xref: /OK3568_Linux_fs/kernel/drivers/net/wimax/i2400m/debugfs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Intel Wireless WiMAX Connection 2400m
4*4882a593Smuzhiyun  * Debugfs interfaces to manipulate driver and device information
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2007 Intel Corporation <linux-wimax@intel.com>
7*4882a593Smuzhiyun  * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/debugfs.h>
11*4882a593Smuzhiyun #include <linux/netdevice.h>
12*4882a593Smuzhiyun #include <linux/etherdevice.h>
13*4882a593Smuzhiyun #include <linux/spinlock.h>
14*4882a593Smuzhiyun #include <linux/device.h>
15*4882a593Smuzhiyun #include <linux/export.h>
16*4882a593Smuzhiyun #include "i2400m.h"
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define D_SUBMODULE debugfs
20*4882a593Smuzhiyun #include "debug-levels.h"
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun static
debugfs_netdev_queue_stopped_get(void * data,u64 * val)23*4882a593Smuzhiyun int debugfs_netdev_queue_stopped_get(void *data, u64 *val)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun 	struct i2400m *i2400m = data;
26*4882a593Smuzhiyun 	*val = netif_queue_stopped(i2400m->wimax_dev.net_dev);
27*4882a593Smuzhiyun 	return 0;
28*4882a593Smuzhiyun }
29*4882a593Smuzhiyun DEFINE_DEBUGFS_ATTRIBUTE(fops_netdev_queue_stopped,
30*4882a593Smuzhiyun 			debugfs_netdev_queue_stopped_get,
31*4882a593Smuzhiyun 			NULL, "%llu\n");
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun  * We don't allow partial reads of this file, as then the reader would
35*4882a593Smuzhiyun  * get weirdly confused data as it is updated.
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * So or you read it all or nothing; if you try to read with an offset
38*4882a593Smuzhiyun  * != 0, we consider you are done reading.
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun static
i2400m_rx_stats_read(struct file * filp,char __user * buffer,size_t count,loff_t * ppos)41*4882a593Smuzhiyun ssize_t i2400m_rx_stats_read(struct file *filp, char __user *buffer,
42*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun 	struct i2400m *i2400m = filp->private_data;
45*4882a593Smuzhiyun 	char buf[128];
46*4882a593Smuzhiyun 	unsigned long flags;
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	if (*ppos != 0)
49*4882a593Smuzhiyun 		return 0;
50*4882a593Smuzhiyun 	if (count < sizeof(buf))
51*4882a593Smuzhiyun 		return -ENOSPC;
52*4882a593Smuzhiyun 	spin_lock_irqsave(&i2400m->rx_lock, flags);
53*4882a593Smuzhiyun 	snprintf(buf, sizeof(buf), "%u %u %u %u %u %u %u\n",
54*4882a593Smuzhiyun 		 i2400m->rx_pl_num, i2400m->rx_pl_min,
55*4882a593Smuzhiyun 		 i2400m->rx_pl_max, i2400m->rx_num,
56*4882a593Smuzhiyun 		 i2400m->rx_size_acc,
57*4882a593Smuzhiyun 		 i2400m->rx_size_min, i2400m->rx_size_max);
58*4882a593Smuzhiyun 	spin_unlock_irqrestore(&i2400m->rx_lock, flags);
59*4882a593Smuzhiyun 	return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* Any write clears the stats */
64*4882a593Smuzhiyun static
i2400m_rx_stats_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)65*4882a593Smuzhiyun ssize_t i2400m_rx_stats_write(struct file *filp, const char __user *buffer,
66*4882a593Smuzhiyun 			      size_t count, loff_t *ppos)
67*4882a593Smuzhiyun {
68*4882a593Smuzhiyun 	struct i2400m *i2400m = filp->private_data;
69*4882a593Smuzhiyun 	unsigned long flags;
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	spin_lock_irqsave(&i2400m->rx_lock, flags);
72*4882a593Smuzhiyun 	i2400m->rx_pl_num = 0;
73*4882a593Smuzhiyun 	i2400m->rx_pl_max = 0;
74*4882a593Smuzhiyun 	i2400m->rx_pl_min = UINT_MAX;
75*4882a593Smuzhiyun 	i2400m->rx_num = 0;
76*4882a593Smuzhiyun 	i2400m->rx_size_acc = 0;
77*4882a593Smuzhiyun 	i2400m->rx_size_min = UINT_MAX;
78*4882a593Smuzhiyun 	i2400m->rx_size_max = 0;
79*4882a593Smuzhiyun 	spin_unlock_irqrestore(&i2400m->rx_lock, flags);
80*4882a593Smuzhiyun 	return count;
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun static
84*4882a593Smuzhiyun const struct file_operations i2400m_rx_stats_fops = {
85*4882a593Smuzhiyun 	.owner =	THIS_MODULE,
86*4882a593Smuzhiyun 	.open =		simple_open,
87*4882a593Smuzhiyun 	.read =		i2400m_rx_stats_read,
88*4882a593Smuzhiyun 	.write =	i2400m_rx_stats_write,
89*4882a593Smuzhiyun 	.llseek =	default_llseek,
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /* See i2400m_rx_stats_read() */
94*4882a593Smuzhiyun static
i2400m_tx_stats_read(struct file * filp,char __user * buffer,size_t count,loff_t * ppos)95*4882a593Smuzhiyun ssize_t i2400m_tx_stats_read(struct file *filp, char __user *buffer,
96*4882a593Smuzhiyun 			     size_t count, loff_t *ppos)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	struct i2400m *i2400m = filp->private_data;
99*4882a593Smuzhiyun 	char buf[128];
100*4882a593Smuzhiyun 	unsigned long flags;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	if (*ppos != 0)
103*4882a593Smuzhiyun 		return 0;
104*4882a593Smuzhiyun 	if (count < sizeof(buf))
105*4882a593Smuzhiyun 		return -ENOSPC;
106*4882a593Smuzhiyun 	spin_lock_irqsave(&i2400m->tx_lock, flags);
107*4882a593Smuzhiyun 	snprintf(buf, sizeof(buf), "%u %u %u %u %u %u %u\n",
108*4882a593Smuzhiyun 		 i2400m->tx_pl_num, i2400m->tx_pl_min,
109*4882a593Smuzhiyun 		 i2400m->tx_pl_max, i2400m->tx_num,
110*4882a593Smuzhiyun 		 i2400m->tx_size_acc,
111*4882a593Smuzhiyun 		 i2400m->tx_size_min, i2400m->tx_size_max);
112*4882a593Smuzhiyun 	spin_unlock_irqrestore(&i2400m->tx_lock, flags);
113*4882a593Smuzhiyun 	return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /* Any write clears the stats */
117*4882a593Smuzhiyun static
i2400m_tx_stats_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)118*4882a593Smuzhiyun ssize_t i2400m_tx_stats_write(struct file *filp, const char __user *buffer,
119*4882a593Smuzhiyun 			      size_t count, loff_t *ppos)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun 	struct i2400m *i2400m = filp->private_data;
122*4882a593Smuzhiyun 	unsigned long flags;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	spin_lock_irqsave(&i2400m->tx_lock, flags);
125*4882a593Smuzhiyun 	i2400m->tx_pl_num = 0;
126*4882a593Smuzhiyun 	i2400m->tx_pl_max = 0;
127*4882a593Smuzhiyun 	i2400m->tx_pl_min = UINT_MAX;
128*4882a593Smuzhiyun 	i2400m->tx_num = 0;
129*4882a593Smuzhiyun 	i2400m->tx_size_acc = 0;
130*4882a593Smuzhiyun 	i2400m->tx_size_min = UINT_MAX;
131*4882a593Smuzhiyun 	i2400m->tx_size_max = 0;
132*4882a593Smuzhiyun 	spin_unlock_irqrestore(&i2400m->tx_lock, flags);
133*4882a593Smuzhiyun 	return count;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun static
137*4882a593Smuzhiyun const struct file_operations i2400m_tx_stats_fops = {
138*4882a593Smuzhiyun 	.owner =	THIS_MODULE,
139*4882a593Smuzhiyun 	.open =		simple_open,
140*4882a593Smuzhiyun 	.read =		i2400m_tx_stats_read,
141*4882a593Smuzhiyun 	.write =	i2400m_tx_stats_write,
142*4882a593Smuzhiyun 	.llseek =	default_llseek,
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun /* Write 1 to ask the device to go into suspend */
147*4882a593Smuzhiyun static
debugfs_i2400m_suspend_set(void * data,u64 val)148*4882a593Smuzhiyun int debugfs_i2400m_suspend_set(void *data, u64 val)
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun 	int result;
151*4882a593Smuzhiyun 	struct i2400m *i2400m = data;
152*4882a593Smuzhiyun 	result = i2400m_cmd_enter_powersave(i2400m);
153*4882a593Smuzhiyun 	if (result >= 0)
154*4882a593Smuzhiyun 		result = 0;
155*4882a593Smuzhiyun 	return result;
156*4882a593Smuzhiyun }
157*4882a593Smuzhiyun DEFINE_DEBUGFS_ATTRIBUTE(fops_i2400m_suspend,
158*4882a593Smuzhiyun 			NULL, debugfs_i2400m_suspend_set,
159*4882a593Smuzhiyun 			"%llu\n");
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun /*
162*4882a593Smuzhiyun  * Reset the device
163*4882a593Smuzhiyun  *
164*4882a593Smuzhiyun  * Write 0 to ask the device to soft reset, 1 to cold reset, 2 to bus
165*4882a593Smuzhiyun  * reset (as defined by enum i2400m_reset_type).
166*4882a593Smuzhiyun  */
167*4882a593Smuzhiyun static
debugfs_i2400m_reset_set(void * data,u64 val)168*4882a593Smuzhiyun int debugfs_i2400m_reset_set(void *data, u64 val)
169*4882a593Smuzhiyun {
170*4882a593Smuzhiyun 	int result;
171*4882a593Smuzhiyun 	struct i2400m *i2400m = data;
172*4882a593Smuzhiyun 	enum i2400m_reset_type rt = val;
173*4882a593Smuzhiyun 	switch(rt) {
174*4882a593Smuzhiyun 	case I2400M_RT_WARM:
175*4882a593Smuzhiyun 	case I2400M_RT_COLD:
176*4882a593Smuzhiyun 	case I2400M_RT_BUS:
177*4882a593Smuzhiyun 		result = i2400m_reset(i2400m, rt);
178*4882a593Smuzhiyun 		if (result >= 0)
179*4882a593Smuzhiyun 			result = 0;
180*4882a593Smuzhiyun 		break;
181*4882a593Smuzhiyun 	default:
182*4882a593Smuzhiyun 		result = -EINVAL;
183*4882a593Smuzhiyun 	}
184*4882a593Smuzhiyun 	return result;
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun DEFINE_DEBUGFS_ATTRIBUTE(fops_i2400m_reset,
187*4882a593Smuzhiyun 			NULL, debugfs_i2400m_reset_set,
188*4882a593Smuzhiyun 			"%llu\n");
189*4882a593Smuzhiyun 
i2400m_debugfs_add(struct i2400m * i2400m)190*4882a593Smuzhiyun void i2400m_debugfs_add(struct i2400m *i2400m)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun 	struct dentry *dentry = i2400m->wimax_dev.debugfs_dentry;
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun 	dentry = debugfs_create_dir("i2400m", dentry);
195*4882a593Smuzhiyun 	i2400m->debugfs_dentry = dentry;
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun 	d_level_register_debugfs("dl_", control, dentry);
198*4882a593Smuzhiyun 	d_level_register_debugfs("dl_", driver, dentry);
199*4882a593Smuzhiyun 	d_level_register_debugfs("dl_", debugfs, dentry);
200*4882a593Smuzhiyun 	d_level_register_debugfs("dl_", fw, dentry);
201*4882a593Smuzhiyun 	d_level_register_debugfs("dl_", netdev, dentry);
202*4882a593Smuzhiyun 	d_level_register_debugfs("dl_", rfkill, dentry);
203*4882a593Smuzhiyun 	d_level_register_debugfs("dl_", rx, dentry);
204*4882a593Smuzhiyun 	d_level_register_debugfs("dl_", tx, dentry);
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 	debugfs_create_size_t("tx_in", 0400, dentry, &i2400m->tx_in);
207*4882a593Smuzhiyun 	debugfs_create_size_t("tx_out", 0400, dentry, &i2400m->tx_out);
208*4882a593Smuzhiyun 	debugfs_create_u32("state", 0600, dentry, &i2400m->state);
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun 	/*
211*4882a593Smuzhiyun 	 * Trace received messages from user space
212*4882a593Smuzhiyun 	 *
213*4882a593Smuzhiyun 	 * In order to tap the bidirectional message stream in the
214*4882a593Smuzhiyun 	 * 'msg' pipe, user space can read from the 'msg' pipe;
215*4882a593Smuzhiyun 	 * however, due to limitations in libnl, we can't know what
216*4882a593Smuzhiyun 	 * the different applications are sending down to the kernel.
217*4882a593Smuzhiyun 	 *
218*4882a593Smuzhiyun 	 * So we have this hack where the driver will echo any message
219*4882a593Smuzhiyun 	 * received on the msg pipe from user space [through a call to
220*4882a593Smuzhiyun 	 * wimax_dev->op_msg_from_user() into
221*4882a593Smuzhiyun 	 * i2400m_op_msg_from_user()] into the 'trace' pipe that this
222*4882a593Smuzhiyun 	 * driver creates.
223*4882a593Smuzhiyun 	 *
224*4882a593Smuzhiyun 	 * So then, reading from both the 'trace' and 'msg' pipes in
225*4882a593Smuzhiyun 	 * user space will provide a full dump of the traffic.
226*4882a593Smuzhiyun 	 *
227*4882a593Smuzhiyun 	 * Write 1 to activate, 0 to clear.
228*4882a593Smuzhiyun 	 *
229*4882a593Smuzhiyun 	 * It is not really very atomic, but it is also not too
230*4882a593Smuzhiyun 	 * critical.
231*4882a593Smuzhiyun 	 */
232*4882a593Smuzhiyun 	debugfs_create_u8("trace_msg_from_user", 0600, dentry,
233*4882a593Smuzhiyun 			  &i2400m->trace_msg_from_user);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	debugfs_create_file("netdev_queue_stopped", 0400, dentry, i2400m,
236*4882a593Smuzhiyun 			    &fops_netdev_queue_stopped);
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun 	debugfs_create_file("rx_stats", 0600, dentry, i2400m,
239*4882a593Smuzhiyun 			    &i2400m_rx_stats_fops);
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 	debugfs_create_file("tx_stats", 0600, dentry, i2400m,
242*4882a593Smuzhiyun 			    &i2400m_tx_stats_fops);
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun 	debugfs_create_file("suspend", 0200, dentry, i2400m,
245*4882a593Smuzhiyun 			    &fops_i2400m_suspend);
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun 	debugfs_create_file("reset", 0200, dentry, i2400m, &fops_i2400m_reset);
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun 
i2400m_debugfs_rm(struct i2400m * i2400m)250*4882a593Smuzhiyun void i2400m_debugfs_rm(struct i2400m *i2400m)
251*4882a593Smuzhiyun {
252*4882a593Smuzhiyun 	debugfs_remove_recursive(i2400m->debugfs_dentry);
253*4882a593Smuzhiyun }
254