1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Wireless WiMAX Connection 2400m
4 * Debugfs interfaces to manipulate driver and device information
10 #include <linux/debugfs.h>
11 #include <linux/netdevice.h>
12 #include <linux/etherdevice.h>
13 #include <linux/spinlock.h>
14 #include <linux/device.h>
15 #include <linux/export.h>
19 #define D_SUBMODULE debugfs
20 #include "debug-levels.h"
23 int debugfs_netdev_queue_stopped_get(void *data, u64 *val)
25 struct i2400m *i2400m = data;
26 *val = netif_queue_stopped(i2400m->wimax_dev.net_dev);
29 DEFINE_DEBUGFS_ATTRIBUTE(fops_netdev_queue_stopped,
30 debugfs_netdev_queue_stopped_get,
34 * We don't allow partial reads of this file, as then the reader would
35 * get weirdly confused data as it is updated.
37 * So or you read it all or nothing; if you try to read with an offset
38 * != 0, we consider you are done reading.
41 ssize_t i2400m_rx_stats_read(struct file *filp, char __user *buffer,
42 size_t count, loff_t *ppos)
44 struct i2400m *i2400m = filp->private_data;
50 if (count < sizeof(buf))
52 spin_lock_irqsave(&i2400m->rx_lock, flags);
53 snprintf(buf, sizeof(buf), "%u %u %u %u %u %u %u\n",
54 i2400m->rx_pl_num, i2400m->rx_pl_min,
55 i2400m->rx_pl_max, i2400m->rx_num,
57 i2400m->rx_size_min, i2400m->rx_size_max);
58 spin_unlock_irqrestore(&i2400m->rx_lock, flags);
59 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
63 /* Any write clears the stats */
65 ssize_t i2400m_rx_stats_write(struct file *filp, const char __user *buffer,
66 size_t count, loff_t *ppos)
68 struct i2400m *i2400m = filp->private_data;
71 spin_lock_irqsave(&i2400m->rx_lock, flags);
72 i2400m->rx_pl_num = 0;
73 i2400m->rx_pl_max = 0;
74 i2400m->rx_pl_min = UINT_MAX;
76 i2400m->rx_size_acc = 0;
77 i2400m->rx_size_min = UINT_MAX;
78 i2400m->rx_size_max = 0;
79 spin_unlock_irqrestore(&i2400m->rx_lock, flags);
84 const struct file_operations i2400m_rx_stats_fops = {
87 .read = i2400m_rx_stats_read,
88 .write = i2400m_rx_stats_write,
89 .llseek = default_llseek,
93 /* See i2400m_rx_stats_read() */
95 ssize_t i2400m_tx_stats_read(struct file *filp, char __user *buffer,
96 size_t count, loff_t *ppos)
98 struct i2400m *i2400m = filp->private_data;
104 if (count < sizeof(buf))
106 spin_lock_irqsave(&i2400m->tx_lock, flags);
107 snprintf(buf, sizeof(buf), "%u %u %u %u %u %u %u\n",
108 i2400m->tx_pl_num, i2400m->tx_pl_min,
109 i2400m->tx_pl_max, i2400m->tx_num,
111 i2400m->tx_size_min, i2400m->tx_size_max);
112 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
113 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
116 /* Any write clears the stats */
118 ssize_t i2400m_tx_stats_write(struct file *filp, const char __user *buffer,
119 size_t count, loff_t *ppos)
121 struct i2400m *i2400m = filp->private_data;
124 spin_lock_irqsave(&i2400m->tx_lock, flags);
125 i2400m->tx_pl_num = 0;
126 i2400m->tx_pl_max = 0;
127 i2400m->tx_pl_min = UINT_MAX;
129 i2400m->tx_size_acc = 0;
130 i2400m->tx_size_min = UINT_MAX;
131 i2400m->tx_size_max = 0;
132 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
137 const struct file_operations i2400m_tx_stats_fops = {
138 .owner = THIS_MODULE,
140 .read = i2400m_tx_stats_read,
141 .write = i2400m_tx_stats_write,
142 .llseek = default_llseek,
146 /* Write 1 to ask the device to go into suspend */
148 int debugfs_i2400m_suspend_set(void *data, u64 val)
151 struct i2400m *i2400m = data;
152 result = i2400m_cmd_enter_powersave(i2400m);
157 DEFINE_DEBUGFS_ATTRIBUTE(fops_i2400m_suspend,
158 NULL, debugfs_i2400m_suspend_set,
164 * Write 0 to ask the device to soft reset, 1 to cold reset, 2 to bus
165 * reset (as defined by enum i2400m_reset_type).
168 int debugfs_i2400m_reset_set(void *data, u64 val)
171 struct i2400m *i2400m = data;
172 enum i2400m_reset_type rt = val;
177 result = i2400m_reset(i2400m, rt);
186 DEFINE_DEBUGFS_ATTRIBUTE(fops_i2400m_reset,
187 NULL, debugfs_i2400m_reset_set,
190 void i2400m_debugfs_add(struct i2400m *i2400m)
192 struct dentry *dentry = i2400m->wimax_dev.debugfs_dentry;
194 dentry = debugfs_create_dir("i2400m", dentry);
195 i2400m->debugfs_dentry = dentry;
197 d_level_register_debugfs("dl_", control, dentry);
198 d_level_register_debugfs("dl_", driver, dentry);
199 d_level_register_debugfs("dl_", debugfs, dentry);
200 d_level_register_debugfs("dl_", fw, dentry);
201 d_level_register_debugfs("dl_", netdev, dentry);
202 d_level_register_debugfs("dl_", rfkill, dentry);
203 d_level_register_debugfs("dl_", rx, dentry);
204 d_level_register_debugfs("dl_", tx, dentry);
206 debugfs_create_size_t("tx_in", 0400, dentry, &i2400m->tx_in);
207 debugfs_create_size_t("tx_out", 0400, dentry, &i2400m->tx_out);
208 debugfs_create_u32("state", 0600, dentry, &i2400m->state);
211 * Trace received messages from user space
213 * In order to tap the bidirectional message stream in the
214 * 'msg' pipe, user space can read from the 'msg' pipe;
215 * however, due to limitations in libnl, we can't know what
216 * the different applications are sending down to the kernel.
218 * So we have this hack where the driver will echo any message
219 * received on the msg pipe from user space [through a call to
220 * wimax_dev->op_msg_from_user() into
221 * i2400m_op_msg_from_user()] into the 'trace' pipe that this
224 * So then, reading from both the 'trace' and 'msg' pipes in
225 * user space will provide a full dump of the traffic.
227 * Write 1 to activate, 0 to clear.
229 * It is not really very atomic, but it is also not too
232 debugfs_create_u8("trace_msg_from_user", 0600, dentry,
233 &i2400m->trace_msg_from_user);
235 debugfs_create_file("netdev_queue_stopped", 0400, dentry, i2400m,
236 &fops_netdev_queue_stopped);
238 debugfs_create_file("rx_stats", 0600, dentry, i2400m,
239 &i2400m_rx_stats_fops);
241 debugfs_create_file("tx_stats", 0600, dentry, i2400m,
242 &i2400m_tx_stats_fops);
244 debugfs_create_file("suspend", 0200, dentry, i2400m,
245 &fops_i2400m_suspend);
247 debugfs_create_file("reset", 0200, dentry, i2400m, &fops_i2400m_reset);
250 void i2400m_debugfs_rm(struct i2400m *i2400m)
252 debugfs_remove_recursive(i2400m->debugfs_dentry);