Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * proc.c - procfs support for Protocol family CAN core module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *    notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * 2. Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *    notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *    documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * 3. Neither the name of Volkswagen nor the names of its contributors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *    may be used to endorse or promote products derived from this software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *    without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * Alternatively, provided that this notice is retained in full, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * software may be distributed under the terms of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * Public License ("GPL") version 2, in which case the provisions of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * GPL apply INSTEAD OF those given above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * The provided data structures and external interfaces from this code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * are not restricted to be used by modules with a GPL compatible license.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/can/can-ml.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <linux/can/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include "af_can.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * proc filenames for the PF_CAN core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define CAN_PROC_STATS       "stats"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define CAN_PROC_RESET_STATS "reset_stats"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define CAN_PROC_RCVLIST_ALL "rcvlist_all"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define CAN_PROC_RCVLIST_FIL "rcvlist_fil"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define CAN_PROC_RCVLIST_INV "rcvlist_inv"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define CAN_PROC_RCVLIST_SFF "rcvlist_sff"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define CAN_PROC_RCVLIST_EFF "rcvlist_eff"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define CAN_PROC_RCVLIST_ERR "rcvlist_err"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int user_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static const char rx_list_name[][8] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	[RX_ERR] = "rx_err",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	[RX_ALL] = "rx_all",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	[RX_FIL] = "rx_fil",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	[RX_INV] = "rx_inv",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * af_can statistics stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static void can_init_stats(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct can_pkg_stats *pkg_stats = net->can.pkg_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * This memset function is called from a timer context (when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * can_stattimer is active which is the default) OR in a process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * context (reading the proc_fs when can_stattimer is disabled).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	memset(pkg_stats, 0, sizeof(struct can_pkg_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	pkg_stats->jiffies_init = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	rcv_lists_stats->stats_reset++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (user_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		user_reset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		rcv_lists_stats->user_reset++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			       unsigned long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	unsigned long rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (oldjif == newjif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/* see can_stat_update() - this should NEVER happen! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (count > (ULONG_MAX / HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		printk(KERN_ERR "can: calc_rate: count exceeded! %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		       count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return 99999999;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	rate = (count * HZ) / (newjif - oldjif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) void can_stat_update(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct net *net = from_timer(net, t, can.stattimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct can_pkg_stats *pkg_stats = net->can.pkg_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	unsigned long j = jiffies; /* snapshot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/* restart counting in timer context on user request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (user_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		can_init_stats(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/* restart counting on jiffies overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (j < pkg_stats->jiffies_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		can_init_stats(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	/* prevent overflow in calc_rate() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (pkg_stats->rx_frames > (ULONG_MAX / HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		can_init_stats(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* prevent overflow in calc_rate() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (pkg_stats->tx_frames > (ULONG_MAX / HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		can_init_stats(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/* matches overflow - very improbable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (pkg_stats->matches > (ULONG_MAX / 100))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		can_init_stats(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/* calc total values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (pkg_stats->rx_frames)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		pkg_stats->total_rx_match_ratio = (pkg_stats->matches * 100) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			pkg_stats->rx_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	pkg_stats->total_tx_rate = calc_rate(pkg_stats->jiffies_init, j,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 					    pkg_stats->tx_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	pkg_stats->total_rx_rate = calc_rate(pkg_stats->jiffies_init, j,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 					    pkg_stats->rx_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* calc current values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (pkg_stats->rx_frames_delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		pkg_stats->current_rx_match_ratio =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			(pkg_stats->matches_delta * 100) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			pkg_stats->rx_frames_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	pkg_stats->current_tx_rate = calc_rate(0, HZ, pkg_stats->tx_frames_delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	pkg_stats->current_rx_rate = calc_rate(0, HZ, pkg_stats->rx_frames_delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	/* check / update maximum values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (pkg_stats->max_tx_rate < pkg_stats->current_tx_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		pkg_stats->max_tx_rate = pkg_stats->current_tx_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (pkg_stats->max_rx_rate < pkg_stats->current_rx_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		pkg_stats->max_rx_rate = pkg_stats->current_rx_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (pkg_stats->max_rx_match_ratio < pkg_stats->current_rx_match_ratio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		pkg_stats->max_rx_match_ratio = pkg_stats->current_rx_match_ratio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* clear values for 'current rate' calculation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	pkg_stats->tx_frames_delta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	pkg_stats->rx_frames_delta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	pkg_stats->matches_delta   = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* restart timer (one second) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	mod_timer(&net->can.stattimer, round_jiffies(jiffies + HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * proc read functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			      struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct receiver *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	hlist_for_each_entry_rcu(r, rx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		char *fmt = (r->can_id & CAN_EFF_FLAG)?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			"   %-5s  %08x  %08x  %pK  %pK  %8ld  %s\n" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			"   %-5s     %03x    %08x  %pK  %pK  %8ld  %s\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		seq_printf(m, fmt, DNAME(dev), r->can_id, r->mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				r->func, r->data, r->matches, r->ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void can_print_recv_banner(struct seq_file *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	 *                  can1.  00000000  00000000  00000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 *                 .......          0  tp20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	seq_puts(m, "  device   can_id   can_mask  function"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			"  userdata   matches  ident\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static int can_stats_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct net *net = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct can_pkg_stats *pkg_stats = net->can.pkg_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	seq_printf(m, " %8ld transmitted frames (TXF)\n", pkg_stats->tx_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	seq_printf(m, " %8ld received frames (RXF)\n", pkg_stats->rx_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	seq_printf(m, " %8ld matched frames (RXMF)\n", pkg_stats->matches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (net->can.stattimer.function == can_stat_update) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		seq_printf(m, " %8ld %% total match ratio (RXMR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				pkg_stats->total_rx_match_ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		seq_printf(m, " %8ld frames/s total tx rate (TXR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 				pkg_stats->total_tx_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		seq_printf(m, " %8ld frames/s total rx rate (RXR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				pkg_stats->total_rx_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		seq_printf(m, " %8ld %% current match ratio (CRXMR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				pkg_stats->current_rx_match_ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		seq_printf(m, " %8ld frames/s current tx rate (CTXR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				pkg_stats->current_tx_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		seq_printf(m, " %8ld frames/s current rx rate (CRXR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				pkg_stats->current_rx_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		seq_printf(m, " %8ld %% max match ratio (MRXMR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				pkg_stats->max_rx_match_ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		seq_printf(m, " %8ld frames/s max tx rate (MTXR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				pkg_stats->max_tx_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		seq_printf(m, " %8ld frames/s max rx rate (MRXR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				pkg_stats->max_rx_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	seq_printf(m, " %8ld current receive list entries (CRCV)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			rcv_lists_stats->rcv_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	seq_printf(m, " %8ld maximum receive list entries (MRCV)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			rcv_lists_stats->rcv_entries_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (rcv_lists_stats->stats_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		seq_printf(m, "\n %8ld statistic resets (STR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 				rcv_lists_stats->stats_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (rcv_lists_stats->user_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		seq_printf(m, " %8ld user statistic resets (USTR)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 				rcv_lists_stats->user_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int can_reset_stats_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct net *net = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct can_pkg_stats *pkg_stats = net->can.pkg_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	user_reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (net->can.stattimer.function == can_stat_update) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		seq_printf(m, "Scheduled statistic reset #%ld.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				rcv_lists_stats->stats_reset + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (pkg_stats->jiffies_init != jiffies)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			can_init_stats(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		seq_printf(m, "Performed statistic reset #%ld.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 				rcv_lists_stats->stats_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static inline void can_rcvlist_proc_show_one(struct seq_file *m, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 					     struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 					     struct can_dev_rcv_lists *dev_rcv_lists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (!hlist_empty(&dev_rcv_lists->rx[idx])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		can_print_recv_banner(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		can_print_rcvlist(m, &dev_rcv_lists->rx[idx], dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		seq_printf(m, "  (%s: no entry)\n", DNAME(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static int can_rcvlist_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	/* double cast to prevent GCC warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	int idx = (int)(long)PDE_DATA(m->file->f_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct can_dev_rcv_lists *dev_rcv_lists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	struct net *net = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	seq_printf(m, "\nreceive list '%s':\n", rx_list_name[idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	/* receive list for 'all' CAN devices (dev == NULL) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	dev_rcv_lists = net->can.rx_alldev_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	can_rcvlist_proc_show_one(m, idx, NULL, dev_rcv_lists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	/* receive list for registered CAN devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	for_each_netdev_rcu(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		struct can_ml_priv *can_ml = can_get_ml_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		if (can_ml)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			can_rcvlist_proc_show_one(m, idx, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 						  &can_ml->dev_rcv_lists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static inline void can_rcvlist_proc_show_array(struct seq_file *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 					       struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 					       struct hlist_head *rcv_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 					       unsigned int rcv_array_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	int all_empty = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	/* check whether at least one list is non-empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	for (i = 0; i < rcv_array_sz; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		if (!hlist_empty(&rcv_array[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			all_empty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (!all_empty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		can_print_recv_banner(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		for (i = 0; i < rcv_array_sz; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			if (!hlist_empty(&rcv_array[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				can_print_rcvlist(m, &rcv_array[i], dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		seq_printf(m, "  (%s: no entry)\n", DNAME(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static int can_rcvlist_sff_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	struct can_dev_rcv_lists *dev_rcv_lists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct net *net = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/* RX_SFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	seq_puts(m, "\nreceive list 'rx_sff':\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/* sff receive list for 'all' CAN devices (dev == NULL) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	dev_rcv_lists = net->can.rx_alldev_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	can_rcvlist_proc_show_array(m, NULL, dev_rcv_lists->rx_sff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 				    ARRAY_SIZE(dev_rcv_lists->rx_sff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	/* sff receive list for registered CAN devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	for_each_netdev_rcu(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		struct can_ml_priv *can_ml = can_get_ml_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		if (can_ml) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			dev_rcv_lists = &can_ml->dev_rcv_lists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			can_rcvlist_proc_show_array(m, dev, dev_rcv_lists->rx_sff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 						    ARRAY_SIZE(dev_rcv_lists->rx_sff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static int can_rcvlist_eff_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct can_dev_rcv_lists *dev_rcv_lists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct net *net = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	/* RX_EFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	seq_puts(m, "\nreceive list 'rx_eff':\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	/* eff receive list for 'all' CAN devices (dev == NULL) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	dev_rcv_lists = net->can.rx_alldev_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	can_rcvlist_proc_show_array(m, NULL, dev_rcv_lists->rx_eff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 				    ARRAY_SIZE(dev_rcv_lists->rx_eff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	/* eff receive list for registered CAN devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	for_each_netdev_rcu(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		struct can_ml_priv *can_ml = can_get_ml_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		if (can_ml) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			dev_rcv_lists = &can_ml->dev_rcv_lists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			can_rcvlist_proc_show_array(m, dev, dev_rcv_lists->rx_eff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 						    ARRAY_SIZE(dev_rcv_lists->rx_eff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  * can_init_proc - create main CAN proc directory and procfs entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) void can_init_proc(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	/* create /proc/net/can directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	net->can.proc_dir = proc_net_mkdir(net, "can", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (!net->can.proc_dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		printk(KERN_INFO "can: failed to create /proc/net/can . "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			   "CONFIG_PROC_FS missing?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	/* own procfs entries from the AF_CAN core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	net->can.pde_stats = proc_create_net_single(CAN_PROC_STATS, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			net->can.proc_dir, can_stats_proc_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	net->can.pde_reset_stats = proc_create_net_single(CAN_PROC_RESET_STATS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			0644, net->can.proc_dir, can_reset_stats_proc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	net->can.pde_rcvlist_err = proc_create_net_single(CAN_PROC_RCVLIST_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			0644, net->can.proc_dir, can_rcvlist_proc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			(void *)RX_ERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	net->can.pde_rcvlist_all = proc_create_net_single(CAN_PROC_RCVLIST_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			0644, net->can.proc_dir, can_rcvlist_proc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			(void *)RX_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	net->can.pde_rcvlist_fil = proc_create_net_single(CAN_PROC_RCVLIST_FIL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			0644, net->can.proc_dir, can_rcvlist_proc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			(void *)RX_FIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	net->can.pde_rcvlist_inv = proc_create_net_single(CAN_PROC_RCVLIST_INV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			0644, net->can.proc_dir, can_rcvlist_proc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			(void *)RX_INV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	net->can.pde_rcvlist_eff = proc_create_net_single(CAN_PROC_RCVLIST_EFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 			0644, net->can.proc_dir, can_rcvlist_eff_proc_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	net->can.pde_rcvlist_sff = proc_create_net_single(CAN_PROC_RCVLIST_SFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			0644, net->can.proc_dir, can_rcvlist_sff_proc_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * can_remove_proc - remove procfs entries and main CAN proc directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) void can_remove_proc(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (!net->can.proc_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	if (net->can.pde_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		remove_proc_entry(CAN_PROC_STATS, net->can.proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	if (net->can.pde_reset_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		remove_proc_entry(CAN_PROC_RESET_STATS, net->can.proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	if (net->can.pde_rcvlist_err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		remove_proc_entry(CAN_PROC_RCVLIST_ERR, net->can.proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (net->can.pde_rcvlist_all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		remove_proc_entry(CAN_PROC_RCVLIST_ALL, net->can.proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	if (net->can.pde_rcvlist_fil)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		remove_proc_entry(CAN_PROC_RCVLIST_FIL, net->can.proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if (net->can.pde_rcvlist_inv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		remove_proc_entry(CAN_PROC_RCVLIST_INV, net->can.proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	if (net->can.pde_rcvlist_eff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		remove_proc_entry(CAN_PROC_RCVLIST_EFF, net->can.proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if (net->can.pde_rcvlist_sff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		remove_proc_entry(CAN_PROC_RCVLIST_SFF, net->can.proc_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	remove_proc_entry("can", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }