]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - kernel/2.6/net/can/proc.c
Changes after test integration into kernel 2.6.21 :
[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 /*
57  * proc filenames for the PF_CAN core
58  */
59
60 #define CAN_PROC_VERSION     "version"
61 #define CAN_PROC_STATS       "stats"
62 #define CAN_PROC_RESET_STATS "reset_stats"
63 #define CAN_PROC_RCVLIST_ALL "rcvlist_all"
64 #define CAN_PROC_RCVLIST_FIL "rcvlist_fil"
65 #define CAN_PROC_RCVLIST_INV "rcvlist_inv"
66 #define CAN_PROC_RCVLIST_SFF "rcvlist_sff"
67 #define CAN_PROC_RCVLIST_EFF "rcvlist_eff"
68 #define CAN_PROC_RCVLIST_ERR "rcvlist_err"
69
70 static void can_init_stats(int caller);
71 static void can_stat_update(unsigned long data);
72
73 static struct proc_dir_entry *can_create_proc_readentry(const char *name,
74         mode_t mode, read_proc_t* read_proc, void *data);
75 static void can_remove_proc_readentry(const char *name);
76 static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
77                                unsigned long count);
78
79 static int can_proc_read_version(char *page, char **start, off_t off,
80                                      int count, int *eof, void *data);
81 static int can_proc_read_stats(char *page, char **start, off_t off,
82                                      int count, int *eof, void *data);
83 static int can_proc_read_reset_stats(char *page, char **start, off_t off,
84                                      int count, int *eof, void *data);
85 static int can_proc_read_rcvlist_all(char *page, char **start, off_t off,
86                                      int count, int *eof, void *data);
87 static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off,
88                                      int count, int *eof, void *data);
89 static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off,
90                                      int count, int *eof, void *data);
91 static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
92                                      int count, int *eof, void *data);
93 static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off,
94                                      int count, int *eof, void *data);
95 static int can_proc_read_rcvlist_err(char *page, char **start, off_t off,
96                                      int count, int *eof, void *data);
97
98 static struct proc_dir_entry *can_dir         = NULL;
99 static struct proc_dir_entry *pde_version     = NULL;
100 static struct proc_dir_entry *pde_stats       = NULL;
101 static struct proc_dir_entry *pde_reset_stats = NULL;
102 static struct proc_dir_entry *pde_rcvlist_all = NULL;
103 static struct proc_dir_entry *pde_rcvlist_fil = NULL;
104 static struct proc_dir_entry *pde_rcvlist_inv = NULL;
105 static struct proc_dir_entry *pde_rcvlist_sff = NULL;
106 static struct proc_dir_entry *pde_rcvlist_eff = NULL;
107 static struct proc_dir_entry *pde_rcvlist_err = NULL;
108
109 struct timer_list stattimer; /* timer for statistics update */
110
111 struct s_stats  stats; /* statistics */
112 struct s_pstats pstats;
113
114 extern struct hlist_head rx_dev_list;    /* rx dispatcher structures */
115 extern int stats_timer;                  /* module parameter. default: on */
116
117 /*
118  * can_init_proc - create main CAN proc directory and procfs entries
119  */
120 void can_init_proc(void)
121 {
122         /* create /proc/net/can directory */
123         can_dir = proc_mkdir(CAN_PROC_DIR, NULL);
124
125         if (!can_dir) {
126                 printk(KERN_INFO "can: failed to create /proc/%s . "
127                        "CONFIG_PROC_FS missing?\n", CAN_PROC_DIR);
128                 return;
129         }
130
131         can_dir->owner = THIS_MODULE;
132
133         /* own procfs entries from the AF_CAN core */
134         pde_version     = can_create_proc_readentry(
135                 CAN_PROC_VERSION, 0644, can_proc_read_version, NULL);
136         pde_stats       = can_create_proc_readentry(
137                 CAN_PROC_STATS, 0644, can_proc_read_stats, NULL);
138         pde_reset_stats = can_create_proc_readentry(
139                 CAN_PROC_RESET_STATS, 0644, can_proc_read_reset_stats, NULL);
140         pde_rcvlist_all = can_create_proc_readentry(
141                 CAN_PROC_RCVLIST_ALL, 0644, can_proc_read_rcvlist_all, NULL);
142         pde_rcvlist_fil = can_create_proc_readentry(
143                 CAN_PROC_RCVLIST_FIL, 0644, can_proc_read_rcvlist_fil, NULL);
144         pde_rcvlist_inv = can_create_proc_readentry(
145                 CAN_PROC_RCVLIST_INV, 0644, can_proc_read_rcvlist_inv, NULL);
146         pde_rcvlist_sff = can_create_proc_readentry(
147                 CAN_PROC_RCVLIST_SFF, 0644, can_proc_read_rcvlist_sff, NULL);
148         pde_rcvlist_eff = can_create_proc_readentry(
149                 CAN_PROC_RCVLIST_EFF, 0644, can_proc_read_rcvlist_eff, NULL);
150         pde_rcvlist_err = can_create_proc_readentry(
151                 CAN_PROC_RCVLIST_ERR, 0644, can_proc_read_rcvlist_err, NULL);
152
153         if (stats_timer) {
154                 /* the statistics are updated every second (timer triggered) */
155                 stattimer.function = can_stat_update;
156                 stattimer.data = 0;
157                 /* update every second */
158                 stattimer.expires = jiffies + HZ;
159                 /* start statistics timer */
160                 add_timer(&stattimer);
161         }
162 }
163
164 /*
165  * can_remove_proc - remove procfs entries and main CAN proc directory
166  */
167 void can_remove_proc(void)
168 {
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, "%s\n",
342                         CAN_VERSION_STRING);
343         *eof = 1;
344         return len;
345 }
346
347 static int can_proc_read_rcvlist_all(char *page, char **start, off_t off,
348                                      int count, int *eof, void *data)
349 {
350         int len = 0;
351         struct dev_rcv_lists *d;
352         struct hlist_node *n;
353
354         /* RX_ALL */
355         len += snprintf(page + len, PAGE_SIZE - len,
356                         "\nreceive list 'rx_all':\n");
357
358         /* find receive list for this device */
359         rcu_read_lock();
360         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
361
362                 if (!hlist_empty(&d->rx_all)) {
363                         len = can_print_recv_banner(page, len);
364                         len = can_print_rcvlist(page, len, &d->rx_all, d->dev);
365                 } else
366                         len += snprintf(page + len, PAGE_SIZE - len,
367                                         "  (%s: no entry)\n", DNAME(d->dev));
368
369                 /* exit on end of buffer? */
370                 if (len > PAGE_SIZE - 100)
371                         break;
372         }
373         rcu_read_unlock();
374
375         len += snprintf(page + len, PAGE_SIZE - len, "\n");
376
377         *eof = 1;
378         return len;
379 }
380
381 static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off,
382                                      int count, int *eof, void *data)
383 {
384         int len = 0;
385         struct dev_rcv_lists *d;
386         struct hlist_node *n;
387
388         /* RX_FIL */
389         len += snprintf(page + len, PAGE_SIZE - len,
390                         "\nreceive list 'rx_fil':\n");
391
392         /* find receive list for this device */
393         rcu_read_lock();
394         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
395
396                 if (!hlist_empty(&d->rx_fil)) {
397                         len = can_print_recv_banner(page, len);
398                         len = can_print_rcvlist(page, len, &d->rx_fil, d->dev);
399                 } else
400                         len += snprintf(page + len, PAGE_SIZE - len,
401                                         "  (%s: no entry)\n", DNAME(d->dev));
402
403                 /* exit on end of buffer? */
404                 if (len > PAGE_SIZE - 100)
405                         break;
406         }
407         rcu_read_unlock();
408
409         len += snprintf(page + len, PAGE_SIZE - len, "\n");
410
411         *eof = 1;
412         return len;
413 }
414
415 static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off,
416                                      int count, int *eof, void *data)
417 {
418         int len = 0;
419         struct dev_rcv_lists *d;
420         struct hlist_node *n;
421
422         /* RX_INV */
423         len += snprintf(page + len, PAGE_SIZE - len,
424                         "\nreceive list 'rx_inv':\n");
425
426         /* find receive list for this device */
427         rcu_read_lock();
428         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
429
430                 if (!hlist_empty(&d->rx_inv)) {
431                         len = can_print_recv_banner(page, len);
432                         len = can_print_rcvlist(page, len, &d->rx_inv, d->dev);
433                 } else
434                         len += snprintf(page + len, PAGE_SIZE - len,
435                                         "  (%s: no entry)\n", DNAME(d->dev));
436
437                 /* exit on end of buffer? */
438                 if (len > PAGE_SIZE - 100)
439                         break;
440         }
441         rcu_read_unlock();
442
443         len += snprintf(page + len, PAGE_SIZE - len, "\n");
444
445         *eof = 1;
446         return len;
447 }
448
449 static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
450                                      int count, int *eof, void *data)
451 {
452         int len = 0;
453         struct dev_rcv_lists *d;
454         struct hlist_node *n;
455
456         /* RX_SFF */
457         len += snprintf(page + len, PAGE_SIZE - len,
458                         "\nreceive list 'rx_sff':\n");
459
460         /* find receive list for this device */
461         rcu_read_lock();
462         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
463                 int i, all_empty = 1;
464                 /* check wether at least one list is non-empty */
465                 for (i = 0; i < 0x800; i++)
466                         if (!hlist_empty(&d->rx_sff[i])) {
467                                 all_empty = 0;
468                                 break;
469                         }
470
471                 if (!all_empty) {
472                         len = can_print_recv_banner(page, len);
473                         for (i = 0; i < 0x800; i++) {
474                                 if (!hlist_empty(&d->rx_sff[i]) &&
475                                     len < PAGE_SIZE - 100)
476                                         len = can_print_rcvlist(page, len,
477                                                                 &d->rx_sff[i],
478                                                                 d->dev);
479                         }
480                 } else
481                         len += snprintf(page + len, PAGE_SIZE - len,
482                                         "  (%s: no entry)\n", DNAME(d->dev));
483
484                 /* exit on end of buffer? */
485                 if (len > PAGE_SIZE - 100)
486                         break;
487         }
488         rcu_read_unlock();
489
490         len += snprintf(page + len, PAGE_SIZE - len, "\n");
491
492         *eof = 1;
493         return len;
494 }
495
496 static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off,
497                                      int count, int *eof, void *data)
498 {
499         int len = 0;
500         struct dev_rcv_lists *d;
501         struct hlist_node *n;
502
503         /* RX_EFF */
504         len += snprintf(page + len, PAGE_SIZE - len,
505                         "\nreceive list 'rx_eff':\n");
506
507         /* find receive list for this device */
508         rcu_read_lock();
509         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
510
511                 if (!hlist_empty(&d->rx_eff)) {
512                         len = can_print_recv_banner(page, len);
513                         len = can_print_rcvlist(page, len, &d->rx_eff, d->dev);
514                 } else
515                         len += snprintf(page + len, PAGE_SIZE - len,
516                                         "  (%s: no entry)\n", DNAME(d->dev));
517
518                 /* exit on end of buffer? */
519                 if (len > PAGE_SIZE - 100)
520                         break;
521         }
522         rcu_read_unlock();
523
524         len += snprintf(page + len, PAGE_SIZE - len, "\n");
525
526         *eof = 1;
527         return len;
528 }
529
530 static int can_proc_read_rcvlist_err(char *page, char **start, off_t off,
531                                      int count, int *eof, void *data)
532 {
533         int len = 0;
534         struct dev_rcv_lists *d;
535         struct hlist_node *n;
536
537         /* RX_ERR */
538         len += snprintf(page + len, PAGE_SIZE - len,
539                         "\nreceive list 'rx_err':\n");
540
541         /* find receive list for this device */
542         rcu_read_lock();
543         hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
544
545                 if (!hlist_empty(&d->rx_err)) {
546                         len = can_print_recv_banner(page, len);
547                         len = can_print_rcvlist(page, len, &d->rx_err, d->dev);
548                 } else
549                         len += snprintf(page + len, PAGE_SIZE - len,
550                                         "  (%s: no entry)\n", DNAME(d->dev));
551
552                 /* exit on end of buffer? */
553                 if (len > PAGE_SIZE - 100)
554                         break;
555         }
556         rcu_read_unlock();
557
558         len += snprintf(page + len, PAGE_SIZE - len, "\n");
559
560         *eof = 1;
561         return len;
562 }
563
564 /*
565  * proc utility functions
566  */
567
568 static struct proc_dir_entry *can_create_proc_readentry(const char *name,
569                                                         mode_t mode,
570                                                         read_proc_t* read_proc,
571                                                         void *data)
572 {
573         if (can_dir)
574                 return create_proc_read_entry(name, mode, can_dir, read_proc,
575                                               data);
576         else
577                 return NULL;
578 }
579
580 static void can_remove_proc_readentry(const char *name)
581 {
582         if (can_dir)
583                 remove_proc_entry(name, can_dir);
584 }
585
586 static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
587                                unsigned long count)
588 {
589         unsigned long ret = 0;
590
591         if (oldjif == newjif)
592                 return 0;
593
594         /* see can_rcv() - this should NEVER happen! */
595         if (count > (ULONG_MAX / HZ)) {
596                 printk(KERN_ERR "can: calc_rate: count exceeded! %ld\n",
597                        count);
598                 return 99999999;
599         }
600
601         ret = (count * HZ) / (newjif - oldjif);
602
603         return ret;
604 }
605
606 /* 
607  * af_can statistics stuff
608  */
609
610 static void can_init_stats(int caller)
611 {
612         memset(&stats, 0, sizeof(stats));
613         stats.jiffies_init  = jiffies;
614         pstats.stats_reset++;
615 }
616
617 static void can_stat_update(unsigned long data)
618 {
619         unsigned long j = jiffies; /* snapshot */
620
621         if (j < stats.jiffies_init) /* jiffies overflow */
622                 can_init_stats(2);
623
624         /* stats.rx_frames is the definitively max. statistic value */
625
626         /* prevent overflow in calc_rate() */
627         if (stats.rx_frames > (ULONG_MAX / HZ))
628                 can_init_stats(3);
629
630         /* matches overflow - very improbable */
631         if (stats.matches > (ULONG_MAX / 100))
632                 can_init_stats(4);
633
634         /* calc total values */
635         if (stats.rx_frames)
636                 stats.total_rx_match_ratio = (stats.matches * 100) / 
637                                                 stats.rx_frames;
638
639         stats.total_tx_rate = calc_rate(stats.jiffies_init, j,
640                                         stats.tx_frames);
641         stats.total_rx_rate = calc_rate(stats.jiffies_init, j,
642                                         stats.rx_frames);
643
644         /* calc current values */
645         if (stats.rx_frames_delta)
646                 stats.current_rx_match_ratio =
647                         (stats.matches_delta * 100) / stats.rx_frames_delta;
648
649         stats.current_tx_rate = calc_rate(0, HZ, stats.tx_frames_delta);
650         stats.current_rx_rate = calc_rate(0, HZ, stats.rx_frames_delta);
651
652         /* check / update maximum values */
653         if (stats.max_tx_rate < stats.current_tx_rate)
654                 stats.max_tx_rate = stats.current_tx_rate;
655
656         if (stats.max_rx_rate < stats.current_rx_rate)
657                 stats.max_rx_rate = stats.current_rx_rate;
658
659         if (stats.max_rx_match_ratio < stats.current_rx_match_ratio)
660                 stats.max_rx_match_ratio = stats.current_rx_match_ratio;
661
662         /* clear values for 'current rate' calculation */
663         stats.tx_frames_delta = 0;
664         stats.rx_frames_delta = 0;
665         stats.matches_delta   = 0;
666
667         /* restart timer */
668         stattimer.expires = jiffies + HZ; /* every second */
669         add_timer(&stattimer);
670 }