ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / net / sk98lin / skproc.c
1 /******************************************************************************
2  *
3  * Name:        skproc.c
4  * Project:     GEnesis, PCI Gigabit Ethernet Adapter
5  * Version:     $Revision: 1.11 $
6  * Date:        $Date: 2003/12/11 16:03:57 $
7  * Purpose:     Funktions to display statictic data
8  *
9  ******************************************************************************/
10  
11 /******************************************************************************
12  *
13  *      (C)Copyright 1998-2002 SysKonnect GmbH.
14  *      (C)Copyright 2002-2003 Marvell.
15  *
16  *      This program is free software; you can redistribute it and/or modify
17  *      it under the terms of the GNU General Public License as published by
18  *      the Free Software Foundation; either version 2 of the License, or
19  *      (at your option) any later version.
20  *
21  *      Created 22-Nov-2000
22  *      Author: Mirko Lindner (mlindner@syskonnect.de)
23  *
24  *      The information in this file is provided "AS IS" without warranty.
25  *
26  ******************************************************************************/
27 #include <linux/proc_fs.h>
28 #include <linux/seq_file.h>
29
30 #include "h/skdrv1st.h"
31 #include "h/skdrv2nd.h"
32 #include "h/skversion.h"
33
34 extern struct SK_NET_DEVICE *SkGeRootDev;
35 static int sk_proc_print(void *writePtr, char *format, ...);
36 static void sk_gen_browse(void *buffer);
37 int len;
38
39 static int sk_seq_show(struct seq_file *seq, void *v);
40 static int sk_proc_open(struct inode *inode, struct file *file);
41 struct file_operations sk_proc_fops = {
42         .owner          = THIS_MODULE,
43         .open           = sk_proc_open,
44         .read           = seq_read,
45         .llseek         = seq_lseek,
46         .release        = single_release,
47 };
48 struct net_device *currDev = NULL;
49
50 /*****************************************************************************
51  *
52  *      sk_gen_browse -generic  print "summaries" entry 
53  *
54  * Description:
55  *  This function fills the proc entry with statistic data about 
56  *  the ethernet device.
57  *  
58  * Returns: -
59  *      
60  */
61 static void sk_gen_browse(void *buffer)
62 {
63         struct SK_NET_DEVICE    *SkgeProcDev = SkGeRootDev;
64         struct SK_NET_DEVICE    *next;
65         SK_PNMI_STRUCT_DATA     *pPnmiStruct;
66         SK_PNMI_STAT            *pPnmiStat;
67         unsigned long           Flags;  
68         unsigned int            Size;
69         DEV_NET                 *pNet;
70         SK_AC                   *pAC;
71         char                    sens_msg[50];
72         int                     MaxSecurityCount = 0;
73         int                     t;
74         int                     i;
75
76         while (SkgeProcDev) {
77                 MaxSecurityCount++;
78                 if (MaxSecurityCount > 100) {
79                         printk("Max limit for sk_proc_read security counter!\n");
80                         return;
81                 }
82                 pNet = (DEV_NET*) SkgeProcDev->priv;
83                 pAC = pNet->pAC;
84                 next = pAC->Next;
85                 pPnmiStruct = &pAC->PnmiStruct;
86                 /* NetIndex in GetStruct is now required, zero is only dummy */
87
88                 for (t=pAC->GIni.GIMacsFound; t > 0; t--) {
89                         if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 1)
90                                 t--;
91
92                         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
93                         Size = SK_PNMI_STRUCT_SIZE;
94 #ifdef SK_DIAG_SUPPORT
95                         if (pAC->BoardLevel == SK_INIT_DATA) {
96                                 SK_MEMCPY(&(pAC->PnmiStruct), &(pAC->PnmiBackup), sizeof(SK_PNMI_STRUCT_DATA));
97                                 if (pAC->DiagModeActive == DIAG_NOTACTIVE) {
98                                         pAC->Pnmi.DiagAttached = SK_DIAG_IDLE;
99                                 }
100                         } else {
101                                 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, t-1);
102                         }
103 #else
104                         SkPnmiGetStruct(pAC, pAC->IoBase, 
105                                 pPnmiStruct, &Size, t-1);
106 #endif
107                         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
108         
109                         if (strcmp(pAC->dev[t-1]->name, currDev->name) == 0) {
110                                 pPnmiStat = &pPnmiStruct->Stat[0];
111                                 len = sk_proc_print(buffer, 
112                                         "\nDetailed statistic for device %s\n",
113                                         pAC->dev[t-1]->name);
114                                 len += sk_proc_print(buffer,
115                                         "=======================================\n");
116         
117                                 /* Board statistics */
118                                 len += sk_proc_print(buffer, 
119                                         "\nBoard statistics\n\n");
120                                 len += sk_proc_print(buffer,
121                                         "Active Port                    %c\n",
122                                         'A' + pAC->Rlmt.Net[t-1].Port[pAC->Rlmt.
123                                         Net[t-1].PrefPort]->PortNumber);
124                                 len += sk_proc_print(buffer,
125                                         "Preferred Port                 %c\n",
126                                         'A' + pAC->Rlmt.Net[t-1].Port[pAC->Rlmt.
127                                         Net[t-1].PrefPort]->PortNumber);
128
129                                 len += sk_proc_print(buffer,
130                                         "Bus speed (MHz)                %d\n",
131                                         pPnmiStruct->BusSpeed);
132
133                                 len += sk_proc_print(buffer,
134                                         "Bus width (Bit)                %d\n",
135                                         pPnmiStruct->BusWidth);
136                                 len += sk_proc_print(buffer,
137                                         "Driver version                 %s\n",
138                                         VER_STRING);
139                                 len += sk_proc_print(buffer,
140                                         "Hardware revision              v%d.%d\n",
141                                         (pAC->GIni.GIPciHwRev >> 4) & 0x0F,
142                                         pAC->GIni.GIPciHwRev & 0x0F);
143
144                                 /* Print sensor informations */
145                                 for (i=0; i < pAC->I2c.MaxSens; i ++) {
146                                         /* Check type */
147                                         switch (pAC->I2c.SenTable[i].SenType) {
148                                         case 1:
149                                                 strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
150                                                 strcat(sens_msg, " (C)");
151                                                 len += sk_proc_print(buffer,
152                                                         "%-25s      %d.%02d\n",
153                                                         sens_msg,
154                                                         pAC->I2c.SenTable[i].SenValue / 10,
155                                                         pAC->I2c.SenTable[i].SenValue % 10);
156
157                                                 strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
158                                                 strcat(sens_msg, " (F)");
159                                                 len += sk_proc_print(buffer,
160                                                         "%-25s      %d.%02d\n",
161                                                         sens_msg,
162                                                         ((((pAC->I2c.SenTable[i].SenValue)
163                                                         *10)*9)/5 + 3200)/100,
164                                                         ((((pAC->I2c.SenTable[i].SenValue)
165                                                         *10)*9)/5 + 3200) % 10);
166                                                 break;
167                                         case 2:
168                                                 strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
169                                                 strcat(sens_msg, " (V)");
170                                                 len += sk_proc_print(buffer,
171                                                         "%-25s      %d.%03d\n",
172                                                         sens_msg,
173                                                         pAC->I2c.SenTable[i].SenValue / 1000,
174                                                         pAC->I2c.SenTable[i].SenValue % 1000);
175                                                 break;
176                                         case 3:
177                                                 strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
178                                                 strcat(sens_msg, " (rpm)");
179                                                 len += sk_proc_print(buffer,
180                                                         "%-25s      %d\n",
181                                                         sens_msg,
182                                                         pAC->I2c.SenTable[i].SenValue);
183                                                 break;
184                                         default:
185                                                 break;
186                                         }
187                                 }
188                                 
189                                 /*Receive statistics */
190                                 len += sk_proc_print(buffer, 
191                                 "\nReceive statistics\n\n");
192
193                                 len += sk_proc_print(buffer,
194                                         "Received bytes                 %Lu\n",
195                                         (unsigned long long) pPnmiStat->StatRxOctetsOkCts);
196                                 len += sk_proc_print(buffer,
197                                         "Received packets               %Lu\n",
198                                         (unsigned long long) pPnmiStat->StatRxOkCts);
199 #if 0
200                                 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && 
201                                         pAC->HWRevision < 12) {
202                                         pPnmiStruct->InErrorsCts = pPnmiStruct->InErrorsCts - 
203                                                 pPnmiStat->StatRxShortsCts;
204                                         pPnmiStat->StatRxShortsCts = 0;
205                                 }
206 #endif
207                                 if (pNet->Mtu > 1500) 
208                                         pPnmiStruct->InErrorsCts = pPnmiStruct->InErrorsCts -
209                                                 pPnmiStat->StatRxTooLongCts;
210
211                                 len += sk_proc_print(buffer,
212                                         "Receive errors                 %Lu\n",
213                                         (unsigned long long) pPnmiStruct->InErrorsCts);
214                                 len += sk_proc_print(buffer,
215                                         "Receive dropped                %Lu\n",
216                                         (unsigned long long) pPnmiStruct->RxNoBufCts);
217                                 len += sk_proc_print(buffer,
218                                         "Received multicast             %Lu\n",
219                                         (unsigned long long) pPnmiStat->StatRxMulticastOkCts);
220                                 len += sk_proc_print(buffer,
221                                         "Receive error types\n");
222                                 len += sk_proc_print(buffer,
223                                         "   length                      %Lu\n",
224                                         (unsigned long long) pPnmiStat->StatRxRuntCts);
225                                 len += sk_proc_print(buffer,
226                                         "   buffer overflow             %Lu\n",
227                                         (unsigned long long) pPnmiStat->StatRxFifoOverflowCts);
228                                 len += sk_proc_print(buffer,
229                                         "   bad crc                     %Lu\n",
230                                         (unsigned long long) pPnmiStat->StatRxFcsCts);
231                                 len += sk_proc_print(buffer,
232                                         "   framing                     %Lu\n",
233                                         (unsigned long long) pPnmiStat->StatRxFramingCts);
234                                 len += sk_proc_print(buffer,
235                                         "   missed frames               %Lu\n",
236                                         (unsigned long long) pPnmiStat->StatRxMissedCts);
237
238                                 if (pNet->Mtu > 1500)
239                                         pPnmiStat->StatRxTooLongCts = 0;
240
241                                 len += sk_proc_print(buffer,
242                                         "   too long                    %Lu\n",
243                                         (unsigned long long) pPnmiStat->StatRxTooLongCts);                                      
244                                 len += sk_proc_print(buffer,
245                                         "   carrier extension           %Lu\n",
246                                         (unsigned long long) pPnmiStat->StatRxCextCts);                         
247                                 len += sk_proc_print(buffer,
248                                         "   too short                   %Lu\n",
249                                         (unsigned long long) pPnmiStat->StatRxShortsCts);                               
250                                 len += sk_proc_print(buffer,
251                                         "   symbol                      %Lu\n",
252                                         (unsigned long long) pPnmiStat->StatRxSymbolCts);                               
253                                 len += sk_proc_print(buffer,
254                                         "   LLC MAC size                %Lu\n",
255                                         (unsigned long long) pPnmiStat->StatRxIRLengthCts);                             
256                                 len += sk_proc_print(buffer,
257                                         "   carrier event               %Lu\n",
258                                         (unsigned long long) pPnmiStat->StatRxCarrierCts);                              
259                                 len += sk_proc_print(buffer,
260                                         "   jabber                      %Lu\n",
261                                         (unsigned long long) pPnmiStat->StatRxJabberCts);                               
262
263
264                                 /*Transmit statistics */
265                                 len += sk_proc_print(buffer, 
266                                 "\nTransmit statistics\n\n");
267                                 
268                                 len += sk_proc_print(buffer,
269                                         "Transmited bytes               %Lu\n",
270                                         (unsigned long long) pPnmiStat->StatTxOctetsOkCts);
271                                 len += sk_proc_print(buffer,
272                                         "Transmited packets             %Lu\n",
273                                         (unsigned long long) pPnmiStat->StatTxOkCts);
274                                 len += sk_proc_print(buffer,
275                                         "Transmit errors                %Lu\n",
276                                         (unsigned long long) pPnmiStat->StatTxSingleCollisionCts);
277                                 len += sk_proc_print(buffer,
278                                         "Transmit dropped               %Lu\n",
279                                         (unsigned long long) pPnmiStruct->TxNoBufCts);
280                                 len += sk_proc_print(buffer,
281                                         "Transmit collisions            %Lu\n",
282                                         (unsigned long long) pPnmiStat->StatTxSingleCollisionCts);
283                                 len += sk_proc_print(buffer,
284                                         "Transmit error types\n");
285                                 len += sk_proc_print(buffer,
286                                         "   excessive collision         %ld\n",
287                                         pAC->stats.tx_aborted_errors);
288                                 len += sk_proc_print(buffer,
289                                         "   carrier                     %Lu\n",
290                                         (unsigned long long) pPnmiStat->StatTxCarrierCts);
291                                 len += sk_proc_print(buffer,
292                                         "   fifo underrun               %Lu\n",
293                                         (unsigned long long) pPnmiStat->StatTxFifoUnderrunCts);
294                                 len += sk_proc_print(buffer,
295                                         "   heartbeat                   %Lu\n",
296                                         (unsigned long long) pPnmiStat->StatTxCarrierCts);
297                                 len += sk_proc_print(buffer,
298                                         "   window                      %ld\n",
299                                         pAC->stats.tx_window_errors);
300                                 
301                         } /* if (strcmp(pACname, currDeviceName) == 0) */
302                 }
303                 SkgeProcDev = next;
304         }
305 }
306
307 /*****************************************************************************
308  *
309  *      sk_proc_print -generic line print  
310  *
311  * Description:
312  *  This function fills the proc entry with statistic data about 
313  *  the ethernet device.
314  *  
315  * Returns: number of bytes written
316  *      
317  */ 
318 static int sk_proc_print(void *writePtr, char *format, ...)
319 {   
320 #define MAX_LEN_SINGLE_LINE 256
321         char     str[MAX_LEN_SINGLE_LINE];
322         va_list  a_start;
323         int      lenght = 0;
324
325         struct seq_file *seq = (struct seq_file *) writePtr;
326
327         SK_MEMSET(str, 0, MAX_LEN_SINGLE_LINE);
328
329         va_start(a_start, format);
330         vsprintf(str, format, a_start);
331         va_end(a_start);
332
333         lenght = strlen(str);
334
335         seq_printf(seq, str);
336         return lenght;
337 }
338
339 /*****************************************************************************
340  *
341  *      sk_seq_show - show proc information of a particular adapter
342  *
343  * Description:
344  *  This function fills the proc entry with statistic data about 
345  *  the ethernet device. It invokes the generic sk_gen_browse() to
346  *  print out all items one per one.
347  *  
348  * Returns: number of bytes written
349  *      
350  */
351 static int sk_seq_show(struct seq_file *seq, void *v)
352 {
353     void *castedBuffer = (void *) seq;
354     currDev = seq->private;
355     sk_gen_browse(castedBuffer);
356     return 0;
357 }
358
359 /*****************************************************************************
360  *
361  *      sk_proc_open - register the show function when proc is open'ed
362  *  
363  * Description:
364  *  This function is called whenever a sk98lin proc file is queried.
365  *  
366  * Returns: the return value of single_open()
367  *      
368  */
369 static int sk_proc_open(struct inode *inode, struct file *file)
370 {
371     return single_open(file, sk_seq_show, PDE(inode)->data);
372 }
373
374 /*******************************************************************************
375  *
376  * End of file
377  *
378  ******************************************************************************/