]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - kernel/2.6/net/can/proc.c
Unified the RCSID stuff which is usefull when making an external compilation.
[socketcan-devel.git] / kernel / 2.6 / net / can / proc.c
1 /*
2  * proc.c - procfs support for Protocol family CAN core module
3  *
4  * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, the following disclaimer and
12  *    the referenced file 'COPYING'.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of Volkswagen nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * Alternatively, provided that this notice is retained in full, this
21  * software may be distributed under the terms of the GNU General
22  * Public License ("GPL") version 2 as distributed in the 'COPYING'
23  * file from the main directory of the linux kernel source.
24  *
25  * The provided data structures and external interfaces from this code
26  * are not restricted to be used by modules with a GPL compatible license.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
39  * DAMAGE.
40  *
41  * Send feedback to <socketcan-users@lists.berlios.de>
42  *
43  */
44
45 #include <linux/module.h>
46 #include <linux/proc_fs.h>
47 #include <linux/list.h>
48 #include <linux/rcupdate.h>
49
50 #include <linux/can/core.h>
51 #include "af_can.h"
52
53 #include <linux/can/version.h> /* for RCSID. Removed by mkpatch script */
54 RCSID("$Id$");
55
56 /* proc filenames */
57
58 #define CAN_PROC_VERSION     "version"
59 #define CAN_PROC_STATS       "stats"
60 #define CAN_PROC_RESET_STATS "reset_stats"
61 #define CAN_PROC_RCVLIST_ALL "rcvlist_all"
62 #define CAN_PROC_RCVLIST_FIL "rcvlist_fil"
63 #define CAN_PROC_RCVLIST_INV "rcvlist_inv"
64 #define CAN_PROC_RCVLIST_SFF "rcvlist_sff"
65 #define CAN_PROC_RCVLIST_EFF "rcvlist_eff"
66 #define CAN_PROC_RCVLIST_ERR "rcvlist_err"
67
68 static void can_init_stats(int caller);
69 static void can_stat_update(unsigned long data);
70
71 static struct proc_dir_entry *can_create_proc_readentry(const char *name,
72         mode_t mode, read_proc_t* read_proc, void *data);
73 static void can_remove_proc_readentry(const char *name);
74 static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
75                                unsigned long count);
76
77 static int can_proc_read_version(char *page, char **start, off_t off,
78                                      int count, int *eof, void *data);
79 static int can_proc_read_stats(char *page, char **start, off_t off,
80                                      int count, int *eof, void *data);
81 static int can_proc_read_reset_stats(char *page, char **start, off_t off,
82                                      int count, int *eof, void *data);
83 static int can_proc_read_rcvlist_all(char *page, char **start, off_t off,
84                                      int count, int *eof, void *data);
85 static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off,
86                                      int count, int *eof, void *data);
87 static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off,
88                                      int count, int *eof, void *data);
89 static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
90                                      int count, int *eof, void *data);
91 static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off,
92                                      int count, int *eof, void *data);
93 static int can_proc_read_rcvlist_err(char *page, char **start, off_t off,
94                                      int count, int *eof, void *data);
95
96 static struct proc_dir_entry *can_dir         = NULL;
97 static struct proc_dir_entry *pde_version     = NULL;
98 static struct proc_dir_entry *pde_stats       = NULL;
99 static struct proc_dir_entry *pde_reset_stats = NULL;
100 static struct proc_dir_entry *pde_rcvlist_all = NULL;
101 static struct proc_dir_entry *pde_rcvlist_fil = NULL;
102 static struct proc_dir_entry *pde_rcvlist_inv = NULL;
103 static struct proc_dir_entry *pde_rcvlist_sff = NULL;
104 static struct proc_dir_entry *pde_rcvlist_eff = NULL;
105 static struct proc_dir_entry *pde_rcvlist_err = NULL;
106
107 struct timer_list stattimer; /* timer for statistics update */
108
109 struct s_stats  stats; /* statistics */
110 struct s_pstats pstats;
111
112 extern struct hlist_head rx_dev_list;    /* rx dispatcher structures */
113 extern int stats_timer;                  /* module parameter. default: on */
114
115 /**************************************************/
116 /* procfs init / remove                           */
117 /**************************************************/
118
119 void can_init_proc(void)
120 {
121
122         /* procfs init */
123
124         /* create /proc/can directory */
125         can_dir = proc_mkdir(CAN_PROC_DIR, NULL);
126
127         if (!can_dir) {
128                 printk(KERN_INFO "CAN: failed to create CAN_PROC_DIR. "
129                        "CONFIG_PROC_FS missing?\n");
130                 return;
131         }
132
133         can_dir->owner = THIS_MODULE;
134
135         /* own procfs entries from the AF_CAN core */
136         pde_version     = can_create_proc_readentry(
137                 CAN_PROC_VERSION, 0644, can_proc_read_version, NULL);
138         pde_stats       = can_create_proc_readentry(
139                 CAN_PROC_STATS, 0644, can_proc_read_stats, NULL);
140         pde_reset_stats = can_create_proc_readentry(
141                 CAN_PROC_RESET_STATS, 0644, can_proc_read_reset_stats, NULL);
142         pde_rcvlist_all = can_create_proc_readentry(
143                 CAN_PROC_RCVLIST_ALL, 0644, can_proc_read_rcvlist_all, NULL);
144         pde_rcvlist_fil = can_create_proc_readentry(
145                 CAN_PROC_RCVLIST_FIL, 0644, can_proc_read_rcvlist_fil, NULL);
146         pde_rcvlist_inv = can_create_proc_readentry(
147                 CAN_PROC_RCVLIST_INV, 0644, can_proc_read_rcvlist_inv, NULL);
148         pde_rcvlist_sff = can_create_proc_readentry(
149                 CAN_PROC_RCVLIST_SFF, 0644, can_proc_read_rcvlist_sff, NULL);
150         pde_rcvlist_eff = can_create_proc_readentry(
151                 CAN_PROC_RCVLIST_EFF, 0644, can_proc_read_rcvlist_eff, NULL);
152         pde_rcvlist_err = can_create_proc_readentry(
153                 CAN_PROC_RCVLIST_ERR, 0644, can_proc_read_rcvlist_err, NULL);
154
155         if (stats_timer) {
156                 /* the statistics are updated every second (timer triggered) */
157                 stattimer.function = can_stat_update;
158                 stattimer.data = 0;
159                 /* update every second */
160                 stattimer.expires = jiffies + HZ;
161                 /* start statistics timer */
162                 add_timer(&stattimer);
163         }
164 }
165
166 void can_remove_proc(void)
167 {
168         /* procfs remove */
169         if (pde_version)
170                 can_remove_proc_readentry(CAN_PROC_VERSION);
171
172         if (pde_stats)
173                 can_remove_proc_readentry(CAN_PROC_STATS);
174
175         if (pde_reset_stats)
176                 can_remove_proc_readentry(CAN_PROC_RESET_STATS);
177
178         if (pde_rcvlist_all)
179                 can_remove_proc_readentry(CAN_PROC_RCVLIST_ALL);
180
181         if (pde_rcvlist_fil)
182                 can_remove_proc_readentry(CAN_PROC_RCVLIST_FIL);
183
184         if (pde_rcvlist_inv)
185                 can_remove_proc_readentry(CAN_PROC_RCVLIST_INV);
186
187         if (pde_rcvlist_sff)
188                 can_remove_proc_readentry(CAN_PROC_RCVLIST_SFF);
189
190         if (pde_rcvlist_eff)
191                 can_remove_proc_readentry(CAN_PROC_RCVLIST_EFF);
192
193         if (pde_rcvlist_err)
194                 can_remove_proc_readentry(CAN_PROC_RCVLIST_ERR);
195
196         if (can_dir)
197                 remove_proc_entry(CAN_PROC_DIR, NULL);
198 }
199
200 /**************************************************/
201 /* proc read functions                            */
202 /**************************************************/
203
204 static int can_print_rcvlist(char *page, int len, struct hlist_head *rx_list,
205                              struct net_device *dev)
206 {
207         struct receiver *r;
208         struct hlist_node *n;
209
210         rcu_read_lock();
211         hlist_for_each_entry_rcu(r, n, rx_list, list) {
212                 char *fmt = (r->can_id & CAN_EFF_FLAG)?
213                         "   %-5s  %08X  %08x  %08x  %08x  %8ld  %s\n" :
214                         "   %-5s     %03X    %08x  %08x  %08x  %8ld  %s\n";
215
216                 len += snprintf(page + len, PAGE_SIZE - len, fmt,
217                                 DNAME(dev), r->can_id, r->mask,
218                                 (unsigned int)r->func, (unsigned int)r->data,
219                                 r->matches, r->ident);
220
221                 /* does a typical line fit into the current buffer? */
222
223                 /* 100 Bytes before end of buffer */
224                 if (len > PAGE_SIZE - 100) {
225                         /* mark output cut off */
226                         len += snprintf(page + len, PAGE_SIZE - len,
227                                         "   (..)\n");
228                         break;
229                 }
230         }
231         rcu_read_unlock();
232
233         return len;
234 }
235
236 static int can_print_recv_banner(char *page, int len)
237 {
238         /*
239          *                  can1.  00000000  00000000  00000000
240          *                 .......          0  tp20
241          */
242         len += snprintf(page + len, PAGE_SIZE - len,
243                         "  device   can_id   can_mask  function"
244                         "  userdata   matches  ident\n");
245
246         return len;
247 }
248
249 static int can_proc_read_stats(char *page, char **start, off_t off,
250                                int count, int *eof, void *data)
251 {
252         int len = 0;
253
254         len += snprintf(page + len, PAGE_SIZE - len, "\n");
255         len += snprintf(page + len, PAGE_SIZE - len,
256                         " %8ld transmitted frames (TXF)\n", stats.tx_frames);
257         len += snprintf(page + len, PAGE_SIZE - len,
258                         " %8ld received frames (RXF)\n", stats.rx_frames);
259         len += snprintf(page + len, PAGE_SIZE - len,
260                         " %8ld matched frames (RXMF)\n", stats.matches);
261
262         len += snprintf(page + len, PAGE_SIZE - len, "\n");
263
264         len += snprintf(page + len, PAGE_SIZE - len,
265                         " %8ld %% total match ratio (RXMR)\n",
266                         stats.total_rx_match_ratio);
267
268         len += snprintf(page + len, PAGE_SIZE - len,
269                         " %8ld frames/s total tx rate (TXR)\n",
270                         stats.total_tx_rate);
271         len += snprintf(page + len, PAGE_SIZE - len,
272                         " %8ld frames/s total rx rate (RXR)\n",
273                         stats.total_rx_rate);
274
275         len += snprintf(page + len, PAGE_SIZE - len, "\n");
276
277         len += snprintf(page + len, PAGE_SIZE - len,
278                         " %8ld %% current match ratio (CRXMR)\n",
279                         stats.current_rx_match_ratio);
280
281         len += snprintf(page + len, PAGE_SIZE - len,
282                         " %8ld frames/s current tx rate (CTXR)\n",
283                         stats.current_tx_rate);
284         len += snprintf(page + len, PAGE_SIZE - len,
285                         " %8ld frames/s current rx rate (CRXR)\n",
286                         stats.current_rx_rate);
287
288         len += snprintf(page + len, PAGE_SIZE - len, "\n");
289
290         len += snprintf(page + len, PAGE_SIZE - len,
291                         " %8ld %% max match ratio (MRXMR)\n",
292                         stats.max_rx_match_ratio);
293
294         len += snprintf(page + len, PAGE_SIZE - len,
295                         " %8ld frames/s max tx rate (MTXR)\n",
296                         stats.max_tx_rate);
297         len += snprintf(page + len, PAGE_SIZE - len,
298                         " %8ld frames/s max rx rate (MRXR)\n",
299                         stats.max_rx_rate);
300
301         len += snprintf(page + len, PAGE_SIZE - len, "\n");
302
303         len += snprintf(page + len, PAGE_SIZE - len,
304                         " %8ld current receive list entries (CRCV)\n",
305                         pstats.rcv_entries);
306         len += snprintf(page + len, PAGE_SIZE - len,
307                         " %8ld maximum receive list entries (MRCV)\n",
308                         pstats.rcv_entries_max);
309
310         if (pstats.stats_reset)
311                 len += snprintf(page + len, PAGE_SIZE - len,
312                                 "\n %8ld statistic resets (STR)\n",
313                                 pstats.stats_reset);
314
315         len += snprintf(page + len, PAGE_SIZE - len, "\n");
316
317         *eof = 1;
318         return len;
319 }
320
321 static int can_proc_read_reset_stats(char *page, char **start, off_t off,
322                                      int count, int *eof, void *data)
323 {
324         int len = 0;
325
326         can_init_stats(1);
327
328         len += snprintf(page + len, PAGE_SIZE - len,
329                         "CAN statistic reset #%ld done.\n",
330                         pstats.stats_reset);
331
332         *eof = 1;
333         return len;
334 }
335
336 static int can_proc_read_version(char *page, char **start, off_t off,
337                                  int count, int *eof, void *data)
338 {
339         int len = 0;
340
341         len += snprintf(page + len, PAGE_SIZE - len,
342                         "CAN version %s, ABI version %d",
343                         CAN_VERSION, CAN_ABI_VERSION);
344         *eof = 1;
345         return len;
346 }
347
348 static int can_proc_read_rcvlist_all(char *page, char **start, off_t off,
349                                      int count, int *eof, void *data)
350 {
351         int len = 0;
352         struct dev_rcv_lists *d;
353         struct hlist_node *n;
354
355         /* RX_ALL */
356         len += snprintf(page + len, PAGE_SIZE - len,
357                         "\nreceive list 'rx_all':\n");
358
359         /* find receive list for this device */
360         rcu_read_lock();
361         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
362
363                 if (!hlist_empty(&d->rx_all)) {
364                         len = can_print_recv_banner(page, len);
365                         len = can_print_rcvlist(page, len, &d->rx_all, d->dev);
366                 } else
367                         len += snprintf(page + len, PAGE_SIZE - len,
368                                         "  (%s: no entry)\n", DNAME(d->dev));
369
370                 /* exit on end of buffer? */
371                 if (len > PAGE_SIZE - 100)
372                         break;
373         }
374         rcu_read_unlock();
375
376         len += snprintf(page + len, PAGE_SIZE - len, "\n");
377
378         *eof = 1;
379         return len;
380 }
381
382 static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off,
383                                      int count, int *eof, void *data)
384 {
385         int len = 0;
386         struct dev_rcv_lists *d;
387         struct hlist_node *n;
388
389         /* RX_FIL */
390         len += snprintf(page + len, PAGE_SIZE - len,
391                         "\nreceive list 'rx_fil':\n");
392
393         /* find receive list for this device */
394         rcu_read_lock();
395         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
396
397                 if (!hlist_empty(&d->rx_fil)) {
398                         len = can_print_recv_banner(page, len);
399                         len = can_print_rcvlist(page, len, &d->rx_fil, d->dev);
400                 } else
401                         len += snprintf(page + len, PAGE_SIZE - len,
402                                         "  (%s: no entry)\n", DNAME(d->dev));
403
404                 /* exit on end of buffer? */
405                 if (len > PAGE_SIZE - 100)
406                         break;
407         }
408         rcu_read_unlock();
409
410         len += snprintf(page + len, PAGE_SIZE - len, "\n");
411
412         *eof = 1;
413         return len;
414 }
415
416 static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off,
417                                      int count, int *eof, void *data)
418 {
419         int len = 0;
420         struct dev_rcv_lists *d;
421         struct hlist_node *n;
422
423         /* RX_INV */
424         len += snprintf(page + len, PAGE_SIZE - len,
425                         "\nreceive list 'rx_inv':\n");
426
427         /* find receive list for this device */
428         rcu_read_lock();
429         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
430
431                 if (!hlist_empty(&d->rx_inv)) {
432                         len = can_print_recv_banner(page, len);
433                         len = can_print_rcvlist(page, len, &d->rx_inv, d->dev);
434                 } else
435                         len += snprintf(page + len, PAGE_SIZE - len,
436                                         "  (%s: no entry)\n", DNAME(d->dev));
437
438                 /* exit on end of buffer? */
439                 if (len > PAGE_SIZE - 100)
440                         break;
441         }
442         rcu_read_unlock();
443
444         len += snprintf(page + len, PAGE_SIZE - len, "\n");
445
446         *eof = 1;
447         return len;
448 }
449
450 static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
451                                      int count, int *eof, void *data)
452 {
453         int len = 0;
454         struct dev_rcv_lists *d;
455         struct hlist_node *n;
456
457         /* RX_SFF */
458         len += snprintf(page + len, PAGE_SIZE - len,
459                         "\nreceive list 'rx_sff':\n");
460
461         /* find receive list for this device */
462         rcu_read_lock();
463         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
464                 int i, all_empty = 1;
465                 /* check wether at least one list is non-empty */
466                 for (i = 0; i < 0x800; i++)
467                         if (!hlist_empty(&d->rx_sff[i])) {
468                                 all_empty = 0;
469                                 break;
470                         }
471
472                 if (!all_empty) {
473                         len = can_print_recv_banner(page, len);
474                         for (i = 0; i < 0x800; i++) {
475                                 if (!hlist_empty(&d->rx_sff[i]) &&
476                                     len < PAGE_SIZE - 100)
477                                         len = can_print_rcvlist(page, len,
478                                                                 &d->rx_sff[i],
479                                                                 d->dev);
480                         }
481                 } else
482                         len += snprintf(page + len, PAGE_SIZE - len,
483                                         "  (%s: no entry)\n", DNAME(d->dev));
484
485                 /* exit on end of buffer? */
486                 if (len > PAGE_SIZE - 100)
487                         break;
488         }
489         rcu_read_unlock();
490
491         len += snprintf(page + len, PAGE_SIZE - len, "\n");
492
493         *eof = 1;
494         return len;
495 }
496
497 static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off,
498                                      int count, int *eof, void *data)
499 {
500         int len = 0;
501         struct dev_rcv_lists *d;
502         struct hlist_node *n;
503
504         /* RX_EFF */
505         len += snprintf(page + len, PAGE_SIZE - len,
506                         "\nreceive list 'rx_eff':\n");
507
508         /* find receive list for this device */
509         rcu_read_lock();
510         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
511
512                 if (!hlist_empty(&d->rx_eff)) {
513                         len = can_print_recv_banner(page, len);
514                         len = can_print_rcvlist(page, len, &d->rx_eff, d->dev);
515                 } else
516                         len += snprintf(page + len, PAGE_SIZE - len,
517                                         "  (%s: no entry)\n", DNAME(d->dev));
518
519                 /* exit on end of buffer? */
520                 if (len > PAGE_SIZE - 100)
521                         break;
522         }
523         rcu_read_unlock();
524
525         len += snprintf(page + len, PAGE_SIZE - len, "\n");
526
527         *eof = 1;
528         return len;
529 }
530
531 static int can_proc_read_rcvlist_err(char *page, char **start, off_t off,
532                                      int count, int *eof, void *data)
533 {
534         int len = 0;
535         struct dev_rcv_lists *d;
536         struct hlist_node *n;
537
538         /* RX_ERR */
539         len += snprintf(page + len, PAGE_SIZE - len,
540                         "\nreceive list 'rx_err':\n");
541
542         /* find receive list for this device */
543         rcu_read_lock();
544         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
545
546                 if (!hlist_empty(&d->rx_err)) {
547                         len = can_print_recv_banner(page, len);
548                         len = can_print_rcvlist(page, len, &d->rx_err, d->dev);
549                 } else
550                         len += snprintf(page + len, PAGE_SIZE - len,
551                                         "  (%s: no entry)\n", DNAME(d->dev));
552
553                 /* exit on end of buffer? */
554                 if (len > PAGE_SIZE - 100)
555                         break;
556         }
557         rcu_read_unlock();
558
559         len += snprintf(page + len, PAGE_SIZE - len, "\n");
560
561         *eof = 1;
562         return len;
563 }
564
565 /**************************************************/
566 /* proc utility functions                         */
567 /**************************************************/
568
569 static struct proc_dir_entry *can_create_proc_readentry(const char *name,
570                                                         mode_t mode,
571                                                         read_proc_t* read_proc,
572                                                         void *data)
573 {
574         if (can_dir)
575                 return create_proc_read_entry(name, mode, can_dir, read_proc,
576                                               data);
577         else
578                 return NULL;
579 }
580
581 static void can_remove_proc_readentry(const char *name)
582 {
583         if (can_dir)
584                 remove_proc_entry(name, can_dir);
585 }
586
587 static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
588                                unsigned long count)
589 {
590         unsigned long ret = 0;
591
592         if (oldjif == newjif)
593                 return 0;
594
595         /* see can_rcv() - this should NEVER happen! */
596         if (count > (ULONG_MAX / HZ)) {
597                 printk(KERN_ERR "CAN: calc_rate: count exceeded! %ld\n",
598                        count);
599                 return 99999999;
600         }
601
602         ret = (count * HZ) / (newjif - oldjif);
603
604         return ret;
605 }
606
607 /**************************************************/
608 /* af_can statistics stuff                        */
609 /**************************************************/
610
611 static void can_init_stats(int caller)
612 {
613         memset(&stats, 0, sizeof(stats));
614         stats.jiffies_init  = jiffies;
615         pstats.stats_reset++;
616 }
617
618 static void can_stat_update(unsigned long data)
619 {
620         unsigned long j = jiffies; /* snapshot */
621
622         if (j < stats.jiffies_init) /* jiffies overflow */
623                 can_init_stats(2);
624
625         /* stats.rx_frames is the definitively max. statistic value */
626
627         /* prevent overflow in calc_rate() */
628         if (stats.rx_frames > (ULONG_MAX / HZ))
629                 can_init_stats(3);
630
631         /* matches overflow - very improbable */
632         if (stats.matches > (ULONG_MAX / 100))
633                 can_init_stats(4);
634
635         /* calc total values */
636         if (stats.rx_frames)
637                 stats.total_rx_match_ratio = (stats.matches * 100) / 
638                                                 stats.rx_frames;
639
640         stats.total_tx_rate = calc_rate(stats.jiffies_init, j,
641                                         stats.tx_frames);
642         stats.total_rx_rate = calc_rate(stats.jiffies_init, j,
643                                         stats.rx_frames);
644
645         /* calc current values */
646         if (stats.rx_frames_delta)
647                 stats.current_rx_match_ratio =
648                         (stats.matches_delta * 100) / stats.rx_frames_delta;
649
650         stats.current_tx_rate = calc_rate(0, HZ, stats.tx_frames_delta);
651         stats.current_rx_rate = calc_rate(0, HZ, stats.rx_frames_delta);
652
653         /* check / update maximum values */
654         if (stats.max_tx_rate < stats.current_tx_rate)
655                 stats.max_tx_rate = stats.current_tx_rate;
656
657         if (stats.max_rx_rate < stats.current_rx_rate)
658                 stats.max_rx_rate = stats.current_rx_rate;
659
660         if (stats.max_rx_match_ratio < stats.current_rx_match_ratio)
661                 stats.max_rx_match_ratio = stats.current_rx_match_ratio;
662
663         /* clear values for 'current rate' calculation */
664         stats.tx_frames_delta = 0;
665         stats.rx_frames_delta = 0;
666         stats.matches_delta   = 0;
667
668         /* restart timer */
669         stattimer.expires = jiffies + HZ; /* every second */
670         add_timer(&stattimer);
671 }