2019-07-23 15:17:55 +02:00
|
|
|
// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
|
2007-11-17 00:52:17 +01:00
|
|
|
/*
|
|
|
|
* proc.c - procfs support for Protocol family CAN core module
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2007 Volkswagen Group Electronic Research
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of Volkswagen nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, provided that this notice is retained in full, this
|
|
|
|
* software may be distributed under the terms of the GNU General
|
|
|
|
* Public License ("GPL") version 2, in which case the provisions of the
|
|
|
|
* GPL apply INSTEAD OF those given above.
|
|
|
|
*
|
|
|
|
* The provided data structures and external interfaces from this code
|
|
|
|
* are not restricted to be used by modules with a GPL compatible license.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/rcupdate.h>
|
2009-12-25 07:47:47 +01:00
|
|
|
#include <linux/if_arp.h>
|
2018-10-08 09:02:38 +02:00
|
|
|
#include <linux/can/can-ml.h>
|
2007-11-17 00:52:17 +01:00
|
|
|
#include <linux/can/core.h>
|
|
|
|
|
|
|
|
#include "af_can.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* proc filenames for the PF_CAN core
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CAN_PROC_VERSION "version"
|
|
|
|
#define CAN_PROC_STATS "stats"
|
|
|
|
#define CAN_PROC_RESET_STATS "reset_stats"
|
|
|
|
#define CAN_PROC_RCVLIST_ALL "rcvlist_all"
|
|
|
|
#define CAN_PROC_RCVLIST_FIL "rcvlist_fil"
|
|
|
|
#define CAN_PROC_RCVLIST_INV "rcvlist_inv"
|
|
|
|
#define CAN_PROC_RCVLIST_SFF "rcvlist_sff"
|
|
|
|
#define CAN_PROC_RCVLIST_EFF "rcvlist_eff"
|
|
|
|
#define CAN_PROC_RCVLIST_ERR "rcvlist_err"
|
|
|
|
|
|
|
|
static int user_reset;
|
|
|
|
|
|
|
|
static const char rx_list_name[][8] = {
|
|
|
|
[RX_ERR] = "rx_err",
|
|
|
|
[RX_ALL] = "rx_all",
|
|
|
|
[RX_FIL] = "rx_fil",
|
|
|
|
[RX_INV] = "rx_inv",
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* af_can statistics stuff
|
|
|
|
*/
|
|
|
|
|
2017-04-25 08:19:41 +02:00
|
|
|
static void can_init_stats(struct net *net)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
2018-10-08 09:02:29 +02:00
|
|
|
struct can_pkg_stats *pkg_stats = net->can.pkg_stats;
|
|
|
|
struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;
|
2007-11-17 00:52:17 +01:00
|
|
|
/*
|
|
|
|
* This memset function is called from a timer context (when
|
|
|
|
* can_stattimer is active which is the default) OR in a process
|
|
|
|
* context (reading the proc_fs when can_stattimer is disabled).
|
|
|
|
*/
|
2018-10-08 09:02:29 +02:00
|
|
|
memset(pkg_stats, 0, sizeof(struct can_pkg_stats));
|
|
|
|
pkg_stats->jiffies_init = jiffies;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2018-10-08 09:02:29 +02:00
|
|
|
rcv_lists_stats->stats_reset++;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
if (user_reset) {
|
|
|
|
user_reset = 0;
|
2018-10-08 09:02:29 +02:00
|
|
|
rcv_lists_stats->user_reset++;
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
|
|
|
|
unsigned long count)
|
|
|
|
{
|
|
|
|
unsigned long rate;
|
|
|
|
|
|
|
|
if (oldjif == newjif)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* see can_stat_update() - this should NEVER happen! */
|
|
|
|
if (count > (ULONG_MAX / HZ)) {
|
|
|
|
printk(KERN_ERR "can: calc_rate: count exceeded! %ld\n",
|
|
|
|
count);
|
|
|
|
return 99999999;
|
|
|
|
}
|
|
|
|
|
|
|
|
rate = (count * HZ) / (newjif - oldjif);
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
2017-10-17 02:29:06 +02:00
|
|
|
void can_stat_update(struct timer_list *t)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
2018-10-08 09:02:30 +02:00
|
|
|
struct net *net = from_timer(net, t, can.stattimer);
|
2018-10-08 09:02:29 +02:00
|
|
|
struct can_pkg_stats *pkg_stats = net->can.pkg_stats;
|
2007-11-17 00:52:17 +01:00
|
|
|
unsigned long j = jiffies; /* snapshot */
|
|
|
|
|
|
|
|
/* restart counting in timer context on user request */
|
|
|
|
if (user_reset)
|
2017-04-25 08:19:41 +02:00
|
|
|
can_init_stats(net);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* restart counting on jiffies overflow */
|
2018-10-08 09:02:29 +02:00
|
|
|
if (j < pkg_stats->jiffies_init)
|
2017-04-25 08:19:41 +02:00
|
|
|
can_init_stats(net);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* prevent overflow in calc_rate() */
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->rx_frames > (ULONG_MAX / HZ))
|
2017-04-25 08:19:41 +02:00
|
|
|
can_init_stats(net);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* prevent overflow in calc_rate() */
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->tx_frames > (ULONG_MAX / HZ))
|
2017-04-25 08:19:41 +02:00
|
|
|
can_init_stats(net);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* matches overflow - very improbable */
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->matches > (ULONG_MAX / 100))
|
2017-04-25 08:19:41 +02:00
|
|
|
can_init_stats(net);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* calc total values */
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->rx_frames)
|
|
|
|
pkg_stats->total_rx_match_ratio = (pkg_stats->matches * 100) /
|
|
|
|
pkg_stats->rx_frames;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->total_tx_rate = calc_rate(pkg_stats->jiffies_init, j,
|
|
|
|
pkg_stats->tx_frames);
|
|
|
|
pkg_stats->total_rx_rate = calc_rate(pkg_stats->jiffies_init, j,
|
|
|
|
pkg_stats->rx_frames);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* calc current values */
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->rx_frames_delta)
|
|
|
|
pkg_stats->current_rx_match_ratio =
|
|
|
|
(pkg_stats->matches_delta * 100) /
|
|
|
|
pkg_stats->rx_frames_delta;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->current_tx_rate = calc_rate(0, HZ, pkg_stats->tx_frames_delta);
|
|
|
|
pkg_stats->current_rx_rate = calc_rate(0, HZ, pkg_stats->rx_frames_delta);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* check / update maximum values */
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->max_tx_rate < pkg_stats->current_tx_rate)
|
|
|
|
pkg_stats->max_tx_rate = pkg_stats->current_tx_rate;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->max_rx_rate < pkg_stats->current_rx_rate)
|
|
|
|
pkg_stats->max_rx_rate = pkg_stats->current_rx_rate;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->max_rx_match_ratio < pkg_stats->current_rx_match_ratio)
|
|
|
|
pkg_stats->max_rx_match_ratio = pkg_stats->current_rx_match_ratio;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* clear values for 'current rate' calculation */
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->tx_frames_delta = 0;
|
|
|
|
pkg_stats->rx_frames_delta = 0;
|
|
|
|
pkg_stats->matches_delta = 0;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* restart timer (one second) */
|
2018-10-08 09:02:30 +02:00
|
|
|
mod_timer(&net->can.stattimer, round_jiffies(jiffies + HZ));
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* proc read functions
|
|
|
|
*/
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list,
|
|
|
|
struct net_device *dev)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
|
|
|
struct receiver *r;
|
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 02:06:00 +01:00
|
|
|
hlist_for_each_entry_rcu(r, rx_list, list) {
|
2007-11-17 00:52:17 +01:00
|
|
|
char *fmt = (r->can_id & CAN_EFF_FLAG)?
|
2011-05-26 06:57:53 +02:00
|
|
|
" %-5s %08x %08x %pK %pK %8ld %s\n" :
|
|
|
|
" %-5s %03x %08x %pK %pK %8ld %s\n";
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, fmt, DNAME(dev), r->can_id, r->mask,
|
2011-05-26 06:57:53 +02:00
|
|
|
r->func, r->data, r->matches, r->ident);
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
static void can_print_recv_banner(struct seq_file *m)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* can1. 00000000 00000000 00000000
|
|
|
|
* ....... 0 tp20
|
|
|
|
*/
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_puts(m, " device can_id can_mask function"
|
2007-11-17 00:52:17 +01:00
|
|
|
" userdata matches ident\n");
|
|
|
|
}
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
static int can_stats_proc_show(struct seq_file *m, void *v)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
2017-04-25 08:19:41 +02:00
|
|
|
struct net *net = m->private;
|
2018-10-08 09:02:29 +02:00
|
|
|
struct can_pkg_stats *pkg_stats = net->can.pkg_stats;
|
|
|
|
struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;
|
2017-04-25 08:19:41 +02:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_putc(m, '\n');
|
2018-10-08 09:02:29 +02:00
|
|
|
seq_printf(m, " %8ld transmitted frames (TXF)\n", pkg_stats->tx_frames);
|
|
|
|
seq_printf(m, " %8ld received frames (RXF)\n", pkg_stats->rx_frames);
|
|
|
|
seq_printf(m, " %8ld matched frames (RXMF)\n", pkg_stats->matches);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_putc(m, '\n');
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2018-10-08 09:02:30 +02:00
|
|
|
if (net->can.stattimer.function == can_stat_update) {
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld %% total match ratio (RXMR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->total_rx_match_ratio);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld frames/s total tx rate (TXR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->total_tx_rate);
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld frames/s total rx rate (RXR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->total_rx_rate);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_putc(m, '\n');
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld %% current match ratio (CRXMR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->current_rx_match_ratio);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld frames/s current tx rate (CTXR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->current_tx_rate);
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld frames/s current rx rate (CRXR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->current_rx_rate);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_putc(m, '\n');
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld %% max match ratio (MRXMR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->max_rx_match_ratio);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld frames/s max tx rate (MTXR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->max_tx_rate);
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld frames/s max rx rate (MRXR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
pkg_stats->max_rx_rate);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_putc(m, '\n');
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld current receive list entries (CRCV)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
rcv_lists_stats->rcv_entries);
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld maximum receive list entries (MRCV)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
rcv_lists_stats->rcv_entries_max);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2018-10-08 09:02:29 +02:00
|
|
|
if (rcv_lists_stats->stats_reset)
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, "\n %8ld statistic resets (STR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
rcv_lists_stats->stats_reset);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2018-10-08 09:02:29 +02:00
|
|
|
if (rcv_lists_stats->user_reset)
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, " %8ld user statistic resets (USTR)\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
rcv_lists_stats->user_reset);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_putc(m, '\n');
|
|
|
|
return 0;
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
static int can_reset_stats_proc_show(struct seq_file *m, void *v)
|
|
|
|
{
|
2017-04-25 08:19:41 +02:00
|
|
|
struct net *net = m->private;
|
2018-10-08 09:02:29 +02:00
|
|
|
struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;
|
|
|
|
struct can_pkg_stats *pkg_stats = net->can.pkg_stats;
|
2017-04-25 08:19:41 +02:00
|
|
|
|
2007-11-17 00:52:17 +01:00
|
|
|
user_reset = 1;
|
|
|
|
|
2018-10-08 09:02:30 +02:00
|
|
|
if (net->can.stattimer.function == can_stat_update) {
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, "Scheduled statistic reset #%ld.\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
rcv_lists_stats->stats_reset + 1);
|
2007-11-17 00:52:17 +01:00
|
|
|
} else {
|
2018-10-08 09:02:29 +02:00
|
|
|
if (pkg_stats->jiffies_init != jiffies)
|
2017-04-25 08:19:41 +02:00
|
|
|
can_init_stats(net);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, "Performed statistic reset #%ld.\n",
|
2018-10-08 09:02:29 +02:00
|
|
|
rcv_lists_stats->stats_reset);
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
2009-08-28 11:57:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
static int can_version_proc_show(struct seq_file *m, void *v)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, "%s\n", CAN_VERSION_STRING);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-12-25 07:47:47 +01:00
|
|
|
static inline void can_rcvlist_proc_show_one(struct seq_file *m, int idx,
|
|
|
|
struct net_device *dev,
|
2018-10-08 09:02:32 +02:00
|
|
|
struct can_dev_rcv_lists *dev_rcv_lists)
|
2009-12-25 07:47:47 +01:00
|
|
|
{
|
2018-10-08 09:02:32 +02:00
|
|
|
if (!hlist_empty(&dev_rcv_lists->rx[idx])) {
|
2009-12-25 07:47:47 +01:00
|
|
|
can_print_recv_banner(m);
|
2018-10-08 09:02:32 +02:00
|
|
|
can_print_rcvlist(m, &dev_rcv_lists->rx[idx], dev);
|
2009-12-25 07:47:47 +01:00
|
|
|
} else
|
|
|
|
seq_printf(m, " (%s: no entry)\n", DNAME(dev));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
static int can_rcvlist_proc_show(struct seq_file *m, void *v)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
|
|
|
/* double cast to prevent GCC warning */
|
2017-02-21 12:19:47 +01:00
|
|
|
int idx = (int)(long)PDE_DATA(m->file->f_inode);
|
2009-12-25 07:47:47 +01:00
|
|
|
struct net_device *dev;
|
2018-10-08 09:02:32 +02:00
|
|
|
struct can_dev_rcv_lists *dev_rcv_lists;
|
2017-02-21 12:19:47 +01:00
|
|
|
struct net *net = m->private;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_printf(m, "\nreceive list '%s':\n", rx_list_name[idx]);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
2009-12-25 07:47:47 +01:00
|
|
|
/* receive list for 'all' CAN devices (dev == NULL) */
|
2018-10-08 09:02:32 +02:00
|
|
|
dev_rcv_lists = net->can.rx_alldev_list;
|
|
|
|
can_rcvlist_proc_show_one(m, idx, NULL, dev_rcv_lists);
|
2009-12-25 07:47:47 +01:00
|
|
|
|
|
|
|
/* receive list for registered CAN devices */
|
2017-02-21 12:19:47 +01:00
|
|
|
for_each_netdev_rcu(net, dev) {
|
2009-12-25 07:47:47 +01:00
|
|
|
if (dev->type == ARPHRD_CAN && dev->ml_priv)
|
|
|
|
can_rcvlist_proc_show_one(m, idx, dev, dev->ml_priv);
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
2009-12-25 07:47:47 +01:00
|
|
|
|
2007-11-17 00:52:17 +01:00
|
|
|
rcu_read_unlock();
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_putc(m, '\n');
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2014-04-02 20:25:25 +02:00
|
|
|
static inline void can_rcvlist_proc_show_array(struct seq_file *m,
|
|
|
|
struct net_device *dev,
|
|
|
|
struct hlist_head *rcv_array,
|
|
|
|
unsigned int rcv_array_sz)
|
2009-12-25 07:47:47 +01:00
|
|
|
{
|
2014-04-02 20:25:25 +02:00
|
|
|
unsigned int i;
|
2009-12-25 07:47:47 +01:00
|
|
|
int all_empty = 1;
|
|
|
|
|
2012-09-20 03:48:00 +02:00
|
|
|
/* check whether at least one list is non-empty */
|
2014-04-02 20:25:25 +02:00
|
|
|
for (i = 0; i < rcv_array_sz; i++)
|
|
|
|
if (!hlist_empty(&rcv_array[i])) {
|
2009-12-25 07:47:47 +01:00
|
|
|
all_empty = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!all_empty) {
|
|
|
|
can_print_recv_banner(m);
|
2014-04-02 20:25:25 +02:00
|
|
|
for (i = 0; i < rcv_array_sz; i++) {
|
|
|
|
if (!hlist_empty(&rcv_array[i]))
|
|
|
|
can_print_rcvlist(m, &rcv_array[i], dev);
|
2009-12-25 07:47:47 +01:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
seq_printf(m, " (%s: no entry)\n", DNAME(dev));
|
|
|
|
}
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
static int can_rcvlist_sff_proc_show(struct seq_file *m, void *v)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
2009-12-25 07:47:47 +01:00
|
|
|
struct net_device *dev;
|
2018-10-08 09:02:32 +02:00
|
|
|
struct can_dev_rcv_lists *dev_rcv_lists;
|
2017-02-21 12:19:47 +01:00
|
|
|
struct net *net = m->private;
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
/* RX_SFF */
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_puts(m, "\nreceive list 'rx_sff':\n");
|
2007-11-17 00:52:17 +01:00
|
|
|
|
|
|
|
rcu_read_lock();
|
2009-12-25 07:47:47 +01:00
|
|
|
|
|
|
|
/* sff receive list for 'all' CAN devices (dev == NULL) */
|
2018-10-08 09:02:32 +02:00
|
|
|
dev_rcv_lists = net->can.rx_alldev_list;
|
|
|
|
can_rcvlist_proc_show_array(m, NULL, dev_rcv_lists->rx_sff,
|
|
|
|
ARRAY_SIZE(dev_rcv_lists->rx_sff));
|
2009-12-25 07:47:47 +01:00
|
|
|
|
|
|
|
/* sff receive list for registered CAN devices */
|
2017-02-21 12:19:47 +01:00
|
|
|
for_each_netdev_rcu(net, dev) {
|
2014-04-02 20:25:25 +02:00
|
|
|
if (dev->type == ARPHRD_CAN && dev->ml_priv) {
|
2018-10-08 09:02:32 +02:00
|
|
|
dev_rcv_lists = dev->ml_priv;
|
|
|
|
can_rcvlist_proc_show_array(m, dev, dev_rcv_lists->rx_sff,
|
|
|
|
ARRAY_SIZE(dev_rcv_lists->rx_sff));
|
2014-04-02 20:25:25 +02:00
|
|
|
}
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
2009-12-25 07:47:47 +01:00
|
|
|
|
2007-11-17 00:52:17 +01:00
|
|
|
rcu_read_unlock();
|
|
|
|
|
2009-08-28 11:57:21 +02:00
|
|
|
seq_putc(m, '\n');
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2014-04-02 20:25:26 +02:00
|
|
|
static int can_rcvlist_eff_proc_show(struct seq_file *m, void *v)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
2018-10-08 09:02:32 +02:00
|
|
|
struct can_dev_rcv_lists *dev_rcv_lists;
|
2017-02-21 12:19:47 +01:00
|
|
|
struct net *net = m->private;
|
2014-04-02 20:25:26 +02:00
|
|
|
|
|
|
|
/* RX_EFF */
|
|
|
|
seq_puts(m, "\nreceive list 'rx_eff':\n");
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
/* eff receive list for 'all' CAN devices (dev == NULL) */
|
2018-10-08 09:02:32 +02:00
|
|
|
dev_rcv_lists = net->can.rx_alldev_list;
|
|
|
|
can_rcvlist_proc_show_array(m, NULL, dev_rcv_lists->rx_eff,
|
|
|
|
ARRAY_SIZE(dev_rcv_lists->rx_eff));
|
2014-04-02 20:25:26 +02:00
|
|
|
|
|
|
|
/* eff receive list for registered CAN devices */
|
2017-02-21 12:19:47 +01:00
|
|
|
for_each_netdev_rcu(net, dev) {
|
2014-04-02 20:25:26 +02:00
|
|
|
if (dev->type == ARPHRD_CAN && dev->ml_priv) {
|
2018-10-08 09:02:32 +02:00
|
|
|
dev_rcv_lists = dev->ml_priv;
|
|
|
|
can_rcvlist_proc_show_array(m, dev, dev_rcv_lists->rx_eff,
|
|
|
|
ARRAY_SIZE(dev_rcv_lists->rx_eff));
|
2014-04-02 20:25:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
seq_putc(m, '\n');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-17 00:52:17 +01:00
|
|
|
/*
|
|
|
|
* can_init_proc - create main CAN proc directory and procfs entries
|
|
|
|
*/
|
2017-02-21 12:19:47 +01:00
|
|
|
void can_init_proc(struct net *net)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
|
|
|
/* create /proc/net/can directory */
|
2017-02-21 12:19:47 +01:00
|
|
|
net->can.proc_dir = proc_net_mkdir(net, "can", net->proc_net);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (!net->can.proc_dir) {
|
|
|
|
printk(KERN_INFO "can: failed to create /proc/net/can . "
|
|
|
|
"CONFIG_PROC_FS missing?\n");
|
2007-11-17 00:52:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* own procfs entries from the AF_CAN core */
|
2018-04-13 20:38:35 +02:00
|
|
|
net->can.pde_version = proc_create_net_single(CAN_PROC_VERSION, 0644,
|
|
|
|
net->can.proc_dir, can_version_proc_show, NULL);
|
|
|
|
net->can.pde_stats = proc_create_net_single(CAN_PROC_STATS, 0644,
|
|
|
|
net->can.proc_dir, can_stats_proc_show, NULL);
|
|
|
|
net->can.pde_reset_stats = proc_create_net_single(CAN_PROC_RESET_STATS,
|
|
|
|
0644, net->can.proc_dir, can_reset_stats_proc_show,
|
|
|
|
NULL);
|
|
|
|
net->can.pde_rcvlist_err = proc_create_net_single(CAN_PROC_RCVLIST_ERR,
|
|
|
|
0644, net->can.proc_dir, can_rcvlist_proc_show,
|
|
|
|
(void *)RX_ERR);
|
|
|
|
net->can.pde_rcvlist_all = proc_create_net_single(CAN_PROC_RCVLIST_ALL,
|
|
|
|
0644, net->can.proc_dir, can_rcvlist_proc_show,
|
|
|
|
(void *)RX_ALL);
|
|
|
|
net->can.pde_rcvlist_fil = proc_create_net_single(CAN_PROC_RCVLIST_FIL,
|
|
|
|
0644, net->can.proc_dir, can_rcvlist_proc_show,
|
|
|
|
(void *)RX_FIL);
|
|
|
|
net->can.pde_rcvlist_inv = proc_create_net_single(CAN_PROC_RCVLIST_INV,
|
|
|
|
0644, net->can.proc_dir, can_rcvlist_proc_show,
|
|
|
|
(void *)RX_INV);
|
|
|
|
net->can.pde_rcvlist_eff = proc_create_net_single(CAN_PROC_RCVLIST_EFF,
|
|
|
|
0644, net->can.proc_dir, can_rcvlist_eff_proc_show, NULL);
|
|
|
|
net->can.pde_rcvlist_sff = proc_create_net_single(CAN_PROC_RCVLIST_SFF,
|
|
|
|
0644, net->can.proc_dir, can_rcvlist_sff_proc_show, NULL);
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* can_remove_proc - remove procfs entries and main CAN proc directory
|
|
|
|
*/
|
2017-02-21 12:19:47 +01:00
|
|
|
void can_remove_proc(struct net *net)
|
2007-11-17 00:52:17 +01:00
|
|
|
{
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_version)
|
|
|
|
remove_proc_entry(CAN_PROC_VERSION, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_stats)
|
|
|
|
remove_proc_entry(CAN_PROC_STATS, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_reset_stats)
|
|
|
|
remove_proc_entry(CAN_PROC_RESET_STATS, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_rcvlist_err)
|
|
|
|
remove_proc_entry(CAN_PROC_RCVLIST_ERR, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_rcvlist_all)
|
|
|
|
remove_proc_entry(CAN_PROC_RCVLIST_ALL, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_rcvlist_fil)
|
|
|
|
remove_proc_entry(CAN_PROC_RCVLIST_FIL, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_rcvlist_inv)
|
|
|
|
remove_proc_entry(CAN_PROC_RCVLIST_INV, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_rcvlist_eff)
|
|
|
|
remove_proc_entry(CAN_PROC_RCVLIST_EFF, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.pde_rcvlist_sff)
|
|
|
|
remove_proc_entry(CAN_PROC_RCVLIST_SFF, net->can.proc_dir);
|
2007-11-17 00:52:17 +01:00
|
|
|
|
2017-02-21 12:19:47 +01:00
|
|
|
if (net->can.proc_dir)
|
|
|
|
remove_proc_entry("can", net->proc_net);
|
2007-11-17 00:52:17 +01:00
|
|
|
}
|