1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.4 $
6 * Date: $Date: 2003/02/25 14:16:37 $
7 * Purpose: Funktions to display statictic data
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2003 SysKonnect GmbH.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
21 * Author: Mirko Lindner (mlindner@syskonnect.de)
23 * The information in this file is provided "AS IS" without warranty.
25 ******************************************************************************/
26 /******************************************************************************
31 * Revision 1.4 2003/02/25 14:16:37 mlindner
32 * Fix: Copyright statement
34 * Revision 1.3 2002/10/02 12:59:51 mlindner
35 * Add: Support for Yukon
36 * Add: Speed check and setup
37 * Add: Merge source for kernel 2.2.x and 2.4.x
38 * Add: Read sensor names directly from VPD
41 * Revision 1.2.2.7 2002/01/14 12:45:15 mlindner
42 * Fix: Editorial changes
44 * Revision 1.2.2.6 2001/12/06 15:26:07 mlindner
45 * Fix: Return value of proc_read
47 * Revision 1.2.2.5 2001/12/06 09:57:39 mlindner
50 * Revision 1.2.2.4 2001/09/05 12:16:02 mlindner
51 * Add: New ProcFs entries
52 * Fix: Counter Errors (Jumbo == to long errors)
53 * Fix: Kernel error compilation
54 * Fix: too short counters
56 * Revision 1.2.2.3 2001/06/25 07:26:26 mlindner
57 * Add: More error messages
59 * Revision 1.2.2.2 2001/03/15 12:50:13 mlindner
60 * fix: ProcFS owner protection
62 * Revision 1.2.2.1 2001/03/12 16:43:48 mlindner
63 * chg: 2.4 requirements for procfs
65 * Revision 1.1 2001/01/22 14:15:31 mlindner
66 * added ProcFs functionality
67 * Dual Net functionality integrated
71 ******************************************************************************/
77 #include <linux/proc_fs.h>
79 #include "h/skdrv1st.h"
80 #include "h/skdrv2nd.h"
81 #define ZEROPAD 1 /* pad with zero */
82 #define SIGN 2 /* unsigned/signed long */
83 #define PLUS 4 /* show plus */
84 #define SPACE 8 /* space if plus */
85 #define LEFT 16 /* left justified */
86 #define SPECIALX 32 /* 0x */
89 extern SK_AC *pACList;
90 extern struct net_device *SkGeRootDev;
92 extern char * SkNumber(
101 /*****************************************************************************
103 * proc_read - print "summaries" entry
106 * This function fills the proc entry with statistic data about
107 * the ethernet device.
110 * Returns: buffer with statistic data
113 int proc_read(char *buffer,
114 char **buffer_location,
129 struct SK_NET_DEVICE *next;
130 struct SK_NET_DEVICE *SkgeProcDev = SkGeRootDev;
132 SK_PNMI_STRUCT_DATA *pPnmiStruct;
133 SK_PNMI_STAT *pPnmiStat;
134 struct proc_dir_entry *file = (struct proc_dir_entry*) data;
136 while (SkgeProcDev) {
137 pNet = (DEV_NET*) SkgeProcDev->priv;
140 pPnmiStruct = &pAC->PnmiStruct;
141 /* NetIndex in GetStruct is now required, zero is only dummy */
143 for (t=pAC->GIni.GIMacsFound; t > 0; t--) {
144 if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 1)
147 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
148 Size = SK_PNMI_STRUCT_SIZE;
149 SkPnmiGetStruct(pAC, pAC->IoBase,
150 pPnmiStruct, &Size, t-1);
151 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
153 if (strcmp(pAC->dev[t-1]->name, file->name) == 0) {
154 pPnmiStat = &pPnmiStruct->Stat[0];
155 len = sprintf(buffer,
156 "\nDetailed statistic for device %s\n",
157 pAC->dev[t-1]->name);
158 len += sprintf(buffer + len,
159 "=======================================\n");
161 /* Board statistics */
162 len += sprintf(buffer + len,
163 "\nBoard statistics\n\n");
164 len += sprintf(buffer + len,
166 'A' + pAC->Rlmt.Net[t-1].Port[pAC->Rlmt.
167 Net[t-1].PrefPort]->PortNumber);
168 len += sprintf(buffer + len,
169 "Preferred Port %c\n",
170 'A' + pAC->Rlmt.Net[t-1].Port[pAC->Rlmt.
171 Net[t-1].PrefPort]->PortNumber);
173 len += sprintf(buffer + len,
174 "Bus speed (MHz) %d\n",
175 pPnmiStruct->BusSpeed);
177 len += sprintf(buffer + len,
178 "Bus width (Bit) %d\n",
179 pPnmiStruct->BusWidth);
180 len += sprintf(buffer + len,
181 "Hardware revision v%d.%d\n",
182 (pAC->GIni.GIPciHwRev >> 4) & 0x0F,
183 pAC->GIni.GIPciHwRev & 0x0F);
185 /* Print sensor informations */
186 for (i=0; i < pAC->I2c.MaxSens; i ++) {
188 switch (pAC->I2c.SenTable[i].SenType) {
190 strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
191 strcat(sens_msg, " (C)");
192 len += sprintf(buffer + len,
195 pAC->I2c.SenTable[i].SenValue / 10,
196 pAC->I2c.SenTable[i].SenValue % 10);
198 strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
199 strcat(sens_msg, " (F)");
200 len += sprintf(buffer + len,
203 ((((pAC->I2c.SenTable[i].SenValue)
204 *10)*9)/5 + 3200)/100,
205 ((((pAC->I2c.SenTable[i].SenValue)
206 *10)*9)/5 + 3200) % 10);
209 strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
210 strcat(sens_msg, " (V)");
211 len += sprintf(buffer + len,
214 pAC->I2c.SenTable[i].SenValue / 1000,
215 pAC->I2c.SenTable[i].SenValue % 1000);
218 strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
219 strcat(sens_msg, " (rpm)");
220 len += sprintf(buffer + len,
223 pAC->I2c.SenTable[i].SenValue);
230 /*Receive statistics */
231 len += sprintf(buffer + len,
232 "\nReceive statistics\n\n");
234 len += sprintf(buffer + len,
235 "Received bytes %s\n",
236 SkNumber(test_buf, pPnmiStat->StatRxOctetsOkCts,
238 len += sprintf(buffer + len,
239 "Received packets %s\n",
240 SkNumber(test_buf, pPnmiStat->StatRxOkCts,
243 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC &&
244 pAC->HWRevision < 12) {
245 pPnmiStruct->InErrorsCts = pPnmiStruct->InErrorsCts -
246 pPnmiStat->StatRxShortsCts;
247 pPnmiStat->StatRxShortsCts = 0;
250 if (pNet->Mtu > 1500)
251 pPnmiStruct->InErrorsCts = pPnmiStruct->InErrorsCts -
252 pPnmiStat->StatRxTooLongCts;
254 len += sprintf(buffer + len,
255 "Receive errors %s\n",
256 SkNumber(test_buf, pPnmiStruct->InErrorsCts,
258 len += sprintf(buffer + len,
259 "Receive drops %s\n",
260 SkNumber(test_buf, pPnmiStruct->RxNoBufCts,
262 len += sprintf(buffer + len,
263 "Received multicast %s\n",
264 SkNumber(test_buf, pPnmiStat->StatRxMulticastOkCts,
266 len += sprintf(buffer + len,
267 "Receive error types\n");
268 len += sprintf(buffer + len,
270 SkNumber(test_buf, pPnmiStat->StatRxRuntCts,
272 len += sprintf(buffer + len,
273 " buffer overflow %s\n",
274 SkNumber(test_buf, pPnmiStat->StatRxFifoOverflowCts,
276 len += sprintf(buffer + len,
278 SkNumber(test_buf, pPnmiStat->StatRxFcsCts,
280 len += sprintf(buffer + len,
282 SkNumber(test_buf, pPnmiStat->StatRxFramingCts,
284 len += sprintf(buffer + len,
285 " missed frames %s\n",
286 SkNumber(test_buf, pPnmiStat->StatRxMissedCts,
289 if (pNet->Mtu > 1500)
290 pPnmiStat->StatRxTooLongCts = 0;
292 len += sprintf(buffer + len,
294 SkNumber(test_buf, pPnmiStat->StatRxTooLongCts,
296 len += sprintf(buffer + len,
297 " carrier extension %s\n",
298 SkNumber(test_buf, pPnmiStat->StatRxCextCts,
300 len += sprintf(buffer + len,
302 SkNumber(test_buf, pPnmiStat->StatRxShortsCts,
304 len += sprintf(buffer + len,
306 SkNumber(test_buf, pPnmiStat->StatRxSymbolCts,
308 len += sprintf(buffer + len,
309 " LLC MAC size %s\n",
310 SkNumber(test_buf, pPnmiStat->StatRxIRLengthCts,
312 len += sprintf(buffer + len,
313 " carrier event %s\n",
314 SkNumber(test_buf, pPnmiStat->StatRxCarrierCts,
316 len += sprintf(buffer + len,
318 SkNumber(test_buf, pPnmiStat->StatRxJabberCts,
322 /*Transmit statistics */
323 len += sprintf(buffer + len,
324 "\nTransmit statistics\n\n");
326 len += sprintf(buffer + len,
327 "Transmited bytes %s\n",
328 SkNumber(test_buf, pPnmiStat->StatTxOctetsOkCts,
330 len += sprintf(buffer + len,
331 "Transmited packets %s\n",
332 SkNumber(test_buf, pPnmiStat->StatTxOkCts,
334 len += sprintf(buffer + len,
335 "Transmit errors %s\n",
336 SkNumber(test_buf, pPnmiStat->StatTxSingleCollisionCts,
338 len += sprintf(buffer + len,
339 "Transmit dropped %s\n",
340 SkNumber(test_buf, pPnmiStruct->TxNoBufCts,
342 len += sprintf(buffer + len,
343 "Transmit collisions %s\n",
344 SkNumber(test_buf, pPnmiStat->StatTxSingleCollisionCts,
346 len += sprintf(buffer + len,
347 "Transmit errors types\n");
348 len += sprintf(buffer + len,
349 " excessive collision %ld\n",
350 pAC->stats.tx_aborted_errors);
351 len += sprintf(buffer + len,
353 SkNumber(test_buf, pPnmiStat->StatTxCarrierCts,
355 len += sprintf(buffer + len,
356 " fifo underrun %s\n",
357 SkNumber(test_buf, pPnmiStat->StatTxFifoUnderrunCts,
359 len += sprintf(buffer + len,
361 SkNumber(test_buf, pPnmiStat->StatTxCarrierCts,
363 len += sprintf(buffer + len,
365 pAC->stats.tx_window_errors);
376 *buffer_location = buffer + offset;
377 if (buffer_length >= len - offset) {
380 return (min_t(int, buffer_length, len - offset));
384 /*****************************************************************************
386 * SkDoDiv - convert 64bit number
389 * This function "converts" a long long number.
392 * remainder of division
394 static long SkDoDiv (long long Dividend, int Divisor, long long *pErg)
401 Akku = Dividend >> 32;
403 Ergebnis = ((long long) (Akku / Divisor)) << 32;
404 Rest = Akku % Divisor ;
407 Akku |= ((Dividend & 0xFFFF0000) >> 16);
410 Ergebnis += ((long long) (Akku / Divisor)) << 16;
411 Rest = Akku % Divisor ;
414 Akku |= (Dividend & 0xFFFF);
416 Ergebnis += (Akku / Divisor);
417 Rest = Akku % Divisor ;
425 #define do_div(n,base) ({ \
427 __res = ((unsigned long long) n) % (unsigned) base; \
428 n = ((unsigned long long) n) / (unsigned) base; \
434 /*****************************************************************************
436 * SkNumber - Print results
439 * This function converts a long long number into a string.
444 char * SkNumber(char * str, long long num, int base, int size, int precision
447 char c,sign,tmp[66], *strorg = str;
448 const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
452 digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
455 if (base < 2 || base > 36)
457 c = (type & ZEROPAD) ? '0' : ' ';
464 } else if (type & PLUS) {
467 } else if (type & SPACE) {
472 if (type & SPECIALX) {
481 else while (num != 0)
482 tmp[i++] = digits[SkDoDiv(num,base, &num)];
487 if (!(type&(ZEROPAD+LEFT)))
492 if (type & SPECIALX) {
503 while (i < precision--)
515 #endif /* CONFIG_SK98 */