Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | /* Copyright (C) 2004-2005 SBE, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/types.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <asm/uaccess.h>
#include "pmcc4_sysdep.h"
#include "sbecom_inline_linux.h"
#include "pmcc4_private.h"
#include "sbeproc.h"
/* forwards */
void sbecom_get_brdinfo (ci_t *, struct sbe_brd_info *, u_int8_t *);
extern struct s_hdw_info hdw_info[MAX_BOARDS];
#ifdef CONFIG_PROC_FS
/********************************************************************/
/* procfs stuff */
/********************************************************************/
void
sbecom_proc_brd_cleanup (ci_t * ci)
{
if (ci->dir_dev)
{
char dir[7 + SBE_IFACETMPL_SIZE + 1];
snprintf(dir, sizeof(dir), "driver/%s", ci->devname);
remove_proc_entry("info", ci->dir_dev);
remove_proc_entry(dir, NULL);
ci->dir_dev = NULL;
}
}
static int
sbecom_proc_get_sbe_info (char *buffer, char **start, off_t offset,
int length, int *eof, void *priv)
{
ci_t *ci = (ci_t *) priv;
int len = 0;
char *spd;
struct sbe_brd_info *bip;
if (!(bip = OS_kmalloc (sizeof (struct sbe_brd_info))))
{
return -ENOMEM;
}
#if 0
/** RLD DEBUG **/
pr_info(">> sbecom_proc_get_sbe_info: entered, offset %d. length %d.\n",
(int) offset, (int) length);
#endif
{
hdw_info_t *hi = &hdw_info[ci->brdno];
u_int8_t *bsn = 0;
switch (hi->promfmt)
{
case PROM_FORMAT_TYPE1:
bsn = (u_int8_t *) hi->mfg_info.pft1.Serial;
break;
case PROM_FORMAT_TYPE2:
bsn = (u_int8_t *) hi->mfg_info.pft2.Serial;
break;
}
sbecom_get_brdinfo (ci, bip, bsn);
}
#if 0
/** RLD DEBUG **/
pr_info(">> sbecom_get_brdinfo: returned, first_if %p <%s> last_if %p <%s>\n",
(char *) &bip->first_iname, (char *) &bip->first_iname,
(char *) &bip->last_iname, (char *) &bip->last_iname);
#endif
len += sprintf (buffer + len, "Board Type: ");
switch (bip->brd_id)
{
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T3):
len += sprintf (buffer + len, "wanPMC-C1T3");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_256T3_E1):
len += sprintf (buffer + len, "wanPTMC-256T3 <E1>");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_256T3_T1):
len += sprintf (buffer + len, "wanPTMC-256T3 <T1>");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_C24TE1):
len += sprintf (buffer + len, "wanPTMC-C24TE1");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C4T1E1):
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C4T1E1_L):
len += sprintf (buffer + len, "wanPMC-C4T1E1");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C2T1E1):
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C2T1E1_L):
len += sprintf (buffer + len, "wanPMC-C2T1E1");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T1E1):
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T1E1_L):
len += sprintf (buffer + len, "wanPMC-C1T1E1");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C4T1E1):
len += sprintf (buffer + len, "wanPCI-C4T1E1");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C2T1E1):
len += sprintf (buffer + len, "wanPCI-C2T1E1");
break;
case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C1T1E1):
len += sprintf (buffer + len, "wanPCI-C1T1E1");
break;
default:
len += sprintf (buffer + len, "unknown");
break;
}
len += sprintf (buffer + len, " [%08X]\n", bip->brd_id);
len += sprintf (buffer + len, "Board Number: %d\n", bip->brdno);
len += sprintf (buffer + len, "Hardware ID: 0x%02X\n", ci->hdw_bid);
len += sprintf (buffer + len, "Board SN: %06X\n", bip->brd_sn);
len += sprintf(buffer + len, "Board MAC: %pMF\n",
bip->brd_mac_addr);
len += sprintf (buffer + len, "Ports: %d\n", ci->max_port);
len += sprintf (buffer + len, "Channels: %d\n", bip->brd_chan_cnt);
#if 1
len += sprintf (buffer + len, "Interface: %s -> %s\n",
(char *) &bip->first_iname, (char *) &bip->last_iname);
#else
len += sprintf (buffer + len, "Interface: <not available> 1st %p lst %p\n",
(char *) &bip->first_iname, (char *) &bip->last_iname);
#endif
switch (bip->brd_pci_speed)
{
case BINFO_PCI_SPEED_33:
spd = "33Mhz";
break;
case BINFO_PCI_SPEED_66:
spd = "66Mhz";
break;
default:
spd = "<not available>";
break;
}
len += sprintf (buffer + len, "PCI Bus Speed: %s\n", spd);
len += sprintf (buffer + len, "Release: %s\n", ci->release);
#ifdef SBE_PMCC4_ENABLE
{
extern int cxt1e1_max_mru;
#if 0
extern int max_chans_used;
extern int cxt1e1_max_mtu;
#endif
extern int max_rxdesc_used, max_txdesc_used;
len += sprintf (buffer + len, "\ncxt1e1_max_mru: %d\n", cxt1e1_max_mru);
#if 0
len += sprintf (buffer + len, "\nmax_chans_used: %d\n", max_chans_used);
len += sprintf (buffer + len, "cxt1e1_max_mtu: %d\n", cxt1e1_max_mtu);
#endif
len += sprintf (buffer + len, "max_rxdesc_used: %d\n", max_rxdesc_used);
len += sprintf (buffer + len, "max_txdesc_used: %d\n", max_txdesc_used);
}
#endif
OS_kfree (bip); /* cleanup */
/***
* How to be a proc read function
* ------------------------------
* Prototype:
* int f(char *buffer, char **start, off_t offset,
* int count, int *peof, void *dat)
*
* Assume that the buffer is "count" bytes in size.
*
* If you know you have supplied all the data you
* have, set *peof.
*
* You have three ways to return data:
* 0) Leave *start = NULL. (This is the default.)
* Put the data of the requested offset at that
* offset within the buffer. Return the number (n)
* of bytes there are from the beginning of the
* buffer up to the last byte of data. If the
* number of supplied bytes (= n - offset) is
* greater than zero and you didn't signal eof
* and the reader is prepared to take more data
* you will be called again with the requested
* offset advanced by the number of bytes
* absorbed. This interface is useful for files
* no larger than the buffer.
* 1) Set *start = an unsigned long value less than
* the buffer address but greater than zero.
* Put the data of the requested offset at the
* beginning of the buffer. Return the number of
* bytes of data placed there. If this number is
* greater than zero and you didn't signal eof
* and the reader is prepared to take more data
* you will be called again with the requested
* offset advanced by *start. This interface is
* useful when you have a large file consisting
* of a series of blocks which you want to count
* and return as wholes.
* (Hack by Paul.Russell@rustcorp.com.au)
* 2) Set *start = an address within the buffer.
* Put the data of the requested offset at *start.
* Return the number of bytes of data placed there.
* If this number is greater than zero and you
* didn't signal eof and the reader is prepared to
* take more data you will be called again with the
* requested offset advanced by the number of bytes
* absorbed.
*/
#if 1
/* #4 - interpretation of above = set EOF, return len */
*eof = 1;
#endif
#if 0
/*
* #1 - from net/wireless/atmel.c RLD NOTE -there's something wrong with
* this plagarized code which results in this routine being called TWICE.
* The second call returns ZERO, resulting in hidden failure, but at
* least only a single message set is being displayed.
*/
if (len <= offset + length)
*eof = 1;
*start = buffer + offset;
len -= offset;
if (len > length)
len = length;
if (len < 0)
len = 0;
#endif
#if 0 /* #2 from net/tokenring/olympic.c +
* lanstreamer.c */
{
off_t begin = 0;
int size = 0;
off_t pos = 0;
size = len;
pos = begin + size;
if (pos < offset)
{
len = 0;
begin = pos;
}
*start = buffer + (offset - begin); /* Start of wanted data */
len -= (offset - begin); /* Start slop */
if (len > length)
len = length; /* Ending slop */
}
#endif
#if 0 /* #3 from
* char/ftape/lowlevel/ftape-proc.c */
len = strlen (buffer);
*start = NULL;
if (offset + length >= len)
*eof = 1;
else
*eof = 0;
#endif
#if 0
pr_info(">> proc_fs: returned len = %d., start %p\n", len, start); /* RLD DEBUG */
#endif
/***
using NONE: returns = 314.314.314.
using #1 : returns = 314, 0.
using #2 : returns = 314, 0, 0.
using #3 : returns = 314, 314.
using #4 : returns = 314, 314.
***/
return len;
}
/* initialize the /proc subsystem for the specific SBE driver */
int __init
sbecom_proc_brd_init (ci_t * ci)
{
struct proc_dir_entry *e;
char dir[7 + SBE_IFACETMPL_SIZE + 1];
/* create a directory in the root procfs */
snprintf(dir, sizeof(dir), "driver/%s", ci->devname);
ci->dir_dev = proc_mkdir(dir, NULL);
if (!ci->dir_dev)
{
pr_err("Unable to create directory /proc/driver/%s\n", ci->devname);
goto fail;
}
e = create_proc_read_entry ("info", S_IFREG | S_IRUGO,
ci->dir_dev, sbecom_proc_get_sbe_info, ci);
if (!e)
{
pr_err("Unable to create entry /proc/driver/%s/info\n", ci->devname);
goto fail;
}
return 0;
fail:
sbecom_proc_brd_cleanup (ci);
return 1;
}
#else /*** ! CONFIG_PROC_FS ***/
/* stubbed off dummy routines */
void
sbecom_proc_brd_cleanup (ci_t * ci)
{
}
int __init
sbecom_proc_brd_init (ci_t * ci)
{
return 0;
}
#endif /*** CONFIG_PROC_FS ***/
/*** End-of-File ***/
|