1 /* Copyright (C) 2004-2005 SBE, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/types.h>
17 #include <linux/module.h>
18 #include <linux/errno.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/proc_fs.h>
22 #include <linux/sched.h>
23 #include <asm/uaccess.h>
24 #include "pmcc4_sysdep.h"
25 #include "sbecom_inline_linux.h"
26 #include "pmcc4_private.h"
30 void sbecom_get_brdinfo (ci_t *, struct sbe_brd_info *, u_int8_t *);
31 extern struct s_hdw_info hdw_info[MAX_BOARDS];
35 /********************************************************************/
37 /********************************************************************/
41 sbecom_proc_brd_cleanup (ci_t * ci)
45 char dir[7 + SBE_IFACETMPL_SIZE + 1];
46 snprintf(dir, sizeof(dir), "driver/%s", ci->devname);
47 remove_proc_entry("info", ci->dir_dev);
48 remove_proc_entry(dir, NULL);
55 sbecom_proc_get_sbe_info (char *buffer, char **start, off_t offset,
56 int length, int *eof, void *priv)
58 ci_t *ci = (ci_t *) priv;
61 struct sbe_brd_info *bip;
63 if (!(bip = OS_kmalloc (sizeof (struct sbe_brd_info))))
69 pr_info(">> sbecom_proc_get_sbe_info: entered, offset %d. length %d.\n",
70 (int) offset, (int) length);
74 hdw_info_t *hi = &hdw_info[ci->brdno];
80 case PROM_FORMAT_TYPE1:
81 bsn = (u_int8_t *) hi->mfg_info.pft1.Serial;
83 case PROM_FORMAT_TYPE2:
84 bsn = (u_int8_t *) hi->mfg_info.pft2.Serial;
88 sbecom_get_brdinfo (ci, bip, bsn);
93 pr_info(">> sbecom_get_brdinfo: returned, first_if %p <%s> last_if %p <%s>\n",
94 (char *) &bip->first_iname, (char *) &bip->first_iname,
95 (char *) &bip->last_iname, (char *) &bip->last_iname);
97 len += sprintf (buffer + len, "Board Type: ");
100 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T3):
101 len += sprintf (buffer + len, "wanPMC-C1T3");
103 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_256T3_E1):
104 len += sprintf (buffer + len, "wanPTMC-256T3 <E1>");
106 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_256T3_T1):
107 len += sprintf (buffer + len, "wanPTMC-256T3 <T1>");
109 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_C24TE1):
110 len += sprintf (buffer + len, "wanPTMC-C24TE1");
113 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C4T1E1):
114 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C4T1E1_L):
115 len += sprintf (buffer + len, "wanPMC-C4T1E1");
117 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C2T1E1):
118 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C2T1E1_L):
119 len += sprintf (buffer + len, "wanPMC-C2T1E1");
121 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T1E1):
122 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T1E1_L):
123 len += sprintf (buffer + len, "wanPMC-C1T1E1");
126 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C4T1E1):
127 len += sprintf (buffer + len, "wanPCI-C4T1E1");
129 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C2T1E1):
130 len += sprintf (buffer + len, "wanPCI-C2T1E1");
132 case SBE_BOARD_ID (PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C1T1E1):
133 len += sprintf (buffer + len, "wanPCI-C1T1E1");
137 len += sprintf (buffer + len, "unknown");
140 len += sprintf (buffer + len, " [%08X]\n", bip->brd_id);
142 len += sprintf (buffer + len, "Board Number: %d\n", bip->brdno);
143 len += sprintf (buffer + len, "Hardware ID: 0x%02X\n", ci->hdw_bid);
144 len += sprintf (buffer + len, "Board SN: %06X\n", bip->brd_sn);
145 len += sprintf (buffer + len, "Board MAC: %02X-%02X-%02X-%02X-%02X-%02X\n",
146 bip->brd_mac_addr[0], bip->brd_mac_addr[1], bip->brd_mac_addr[2],
147 bip->brd_mac_addr[3], bip->brd_mac_addr[4], bip->brd_mac_addr[5]);
148 len += sprintf (buffer + len, "Ports: %d\n", ci->max_port);
149 len += sprintf (buffer + len, "Channels: %d\n", bip->brd_chan_cnt);
151 len += sprintf (buffer + len, "Interface: %s -> %s\n",
152 (char *) &bip->first_iname, (char *) &bip->last_iname);
154 len += sprintf (buffer + len, "Interface: <not available> 1st %p lst %p\n",
155 (char *) &bip->first_iname, (char *) &bip->last_iname);
158 switch (bip->brd_pci_speed)
160 case BINFO_PCI_SPEED_33:
163 case BINFO_PCI_SPEED_66:
167 spd = "<not available>";
170 len += sprintf (buffer + len, "PCI Bus Speed: %s\n", spd);
171 len += sprintf (buffer + len, "Release: %s\n", ci->release);
173 #ifdef SBE_PMCC4_ENABLE
177 extern int max_chans_used;
180 extern int max_rxdesc_used, max_txdesc_used;
182 len += sprintf (buffer + len, "\nmax_mru: %d\n", max_mru);
184 len += sprintf (buffer + len, "\nmax_chans_used: %d\n", max_chans_used);
185 len += sprintf (buffer + len, "max_mtu: %d\n", max_mtu);
187 len += sprintf (buffer + len, "max_rxdesc_used: %d\n", max_rxdesc_used);
188 len += sprintf (buffer + len, "max_txdesc_used: %d\n", max_txdesc_used);
192 OS_kfree (bip); /* cleanup */
195 * How to be a proc read function
196 * ------------------------------
198 * int f(char *buffer, char **start, off_t offset,
199 * int count, int *peof, void *dat)
201 * Assume that the buffer is "count" bytes in size.
203 * If you know you have supplied all the data you
206 * You have three ways to return data:
207 * 0) Leave *start = NULL. (This is the default.)
208 * Put the data of the requested offset at that
209 * offset within the buffer. Return the number (n)
210 * of bytes there are from the beginning of the
211 * buffer up to the last byte of data. If the
212 * number of supplied bytes (= n - offset) is
213 * greater than zero and you didn't signal eof
214 * and the reader is prepared to take more data
215 * you will be called again with the requested
216 * offset advanced by the number of bytes
217 * absorbed. This interface is useful for files
218 * no larger than the buffer.
219 * 1) Set *start = an unsigned long value less than
220 * the buffer address but greater than zero.
221 * Put the data of the requested offset at the
222 * beginning of the buffer. Return the number of
223 * bytes of data placed there. If this number is
224 * greater than zero and you didn't signal eof
225 * and the reader is prepared to take more data
226 * you will be called again with the requested
227 * offset advanced by *start. This interface is
228 * useful when you have a large file consisting
229 * of a series of blocks which you want to count
230 * and return as wholes.
231 * (Hack by Paul.Russell@rustcorp.com.au)
232 * 2) Set *start = an address within the buffer.
233 * Put the data of the requested offset at *start.
234 * Return the number of bytes of data placed there.
235 * If this number is greater than zero and you
236 * didn't signal eof and the reader is prepared to
237 * take more data you will be called again with the
238 * requested offset advanced by the number of bytes
243 /* #4 - intepretation of above = set EOF, return len */
249 * #1 - from net/wireless/atmel.c RLD NOTE -there's something wrong with
250 * this plagarized code which results in this routine being called TWICE.
251 * The second call returns ZERO, resulting in hidden failure, but at
252 * least only a single message set is being displayed.
254 if (len <= offset + length)
256 *start = buffer + offset;
264 #if 0 /* #2 from net/tokenring/olympic.c +
278 *start = buffer + (offset - begin); /* Start of wanted data */
279 len -= (offset - begin); /* Start slop */
281 len = length; /* Ending slop */
286 * char/ftape/lowlevel/ftape-proc.c */
287 len = strlen (buffer);
289 if (offset + length >= len)
296 pr_info(">> proc_fs: returned len = %d., start %p\n", len, start); /* RLD DEBUG */
300 using NONE: returns = 314.314.314.
301 using #1 : returns = 314, 0.
302 using #2 : returns = 314, 0, 0.
303 using #3 : returns = 314, 314.
304 using #4 : returns = 314, 314.
310 /* initialize the /proc subsystem for the specific SBE driver */
313 sbecom_proc_brd_init (ci_t * ci)
315 struct proc_dir_entry *e;
316 char dir[7 + SBE_IFACETMPL_SIZE + 1];
318 /* create a directory in the root procfs */
319 snprintf(dir, sizeof(dir), "driver/%s", ci->devname);
320 ci->dir_dev = proc_mkdir(dir, NULL);
323 pr_err("Unable to create directory /proc/driver/%s\n", ci->devname);
326 e = create_proc_read_entry ("info", S_IFREG | S_IRUGO,
327 ci->dir_dev, sbecom_proc_get_sbe_info, ci);
330 pr_err("Unable to create entry /proc/driver/%s/info\n", ci->devname);
336 sbecom_proc_brd_cleanup (ci);
340 #else /*** ! CONFIG_PROC_FS ***/
342 /* stubbed off dummy routines */
345 sbecom_proc_brd_cleanup (ci_t * ci)
350 sbecom_proc_brd_init (ci_t * ci)
355 #endif /*** CONFIG_PROC_FS ***/
358 /*** End-of-File ***/