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