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