2 * Intel Wireless WiMAX Connection 2400m
3 * Debugfs interfaces to manipulate driver and device information
6 * Copyright (C) 2007 Intel Corporation <linux-wimax@intel.com>
7 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <linux/debugfs.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/spinlock.h>
28 #include <linux/device.h>
29 #include <linux/export.h>
33 #define D_SUBMODULE debugfs
34 #include "debug-levels.h"
37 int debugfs_netdev_queue_stopped_get(void *data, u64 *val)
39 struct i2400m *i2400m = data;
40 *val = netif_queue_stopped(i2400m->wimax_dev.net_dev);
43 DEFINE_SIMPLE_ATTRIBUTE(fops_netdev_queue_stopped,
44 debugfs_netdev_queue_stopped_get,
49 struct dentry *debugfs_create_netdev_queue_stopped(
50 const char *name, struct dentry *parent, struct i2400m *i2400m)
52 return debugfs_create_file(name, 0400, parent, i2400m,
53 &fops_netdev_queue_stopped);
57 * We don't allow partial reads of this file, as then the reader would
58 * get weirdly confused data as it is updated.
60 * So or you read it all or nothing; if you try to read with an offset
61 * != 0, we consider you are done reading.
64 ssize_t i2400m_rx_stats_read(struct file *filp, char __user *buffer,
65 size_t count, loff_t *ppos)
67 struct i2400m *i2400m = filp->private_data;
73 if (count < sizeof(buf))
75 spin_lock_irqsave(&i2400m->rx_lock, flags);
76 snprintf(buf, sizeof(buf), "%u %u %u %u %u %u %u\n",
77 i2400m->rx_pl_num, i2400m->rx_pl_min,
78 i2400m->rx_pl_max, i2400m->rx_num,
80 i2400m->rx_size_min, i2400m->rx_size_max);
81 spin_unlock_irqrestore(&i2400m->rx_lock, flags);
82 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
86 /* Any write clears the stats */
88 ssize_t i2400m_rx_stats_write(struct file *filp, const char __user *buffer,
89 size_t count, loff_t *ppos)
91 struct i2400m *i2400m = filp->private_data;
94 spin_lock_irqsave(&i2400m->rx_lock, flags);
95 i2400m->rx_pl_num = 0;
96 i2400m->rx_pl_max = 0;
97 i2400m->rx_pl_min = UINT_MAX;
99 i2400m->rx_size_acc = 0;
100 i2400m->rx_size_min = UINT_MAX;
101 i2400m->rx_size_max = 0;
102 spin_unlock_irqrestore(&i2400m->rx_lock, flags);
107 const struct file_operations i2400m_rx_stats_fops = {
108 .owner = THIS_MODULE,
110 .read = i2400m_rx_stats_read,
111 .write = i2400m_rx_stats_write,
112 .llseek = default_llseek,
116 /* See i2400m_rx_stats_read() */
118 ssize_t i2400m_tx_stats_read(struct file *filp, char __user *buffer,
119 size_t count, loff_t *ppos)
121 struct i2400m *i2400m = filp->private_data;
127 if (count < sizeof(buf))
129 spin_lock_irqsave(&i2400m->tx_lock, flags);
130 snprintf(buf, sizeof(buf), "%u %u %u %u %u %u %u\n",
131 i2400m->tx_pl_num, i2400m->tx_pl_min,
132 i2400m->tx_pl_max, i2400m->tx_num,
134 i2400m->tx_size_min, i2400m->tx_size_max);
135 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
136 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
139 /* Any write clears the stats */
141 ssize_t i2400m_tx_stats_write(struct file *filp, const char __user *buffer,
142 size_t count, loff_t *ppos)
144 struct i2400m *i2400m = filp->private_data;
147 spin_lock_irqsave(&i2400m->tx_lock, flags);
148 i2400m->tx_pl_num = 0;
149 i2400m->tx_pl_max = 0;
150 i2400m->tx_pl_min = UINT_MAX;
152 i2400m->tx_size_acc = 0;
153 i2400m->tx_size_min = UINT_MAX;
154 i2400m->tx_size_max = 0;
155 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
160 const struct file_operations i2400m_tx_stats_fops = {
161 .owner = THIS_MODULE,
163 .read = i2400m_tx_stats_read,
164 .write = i2400m_tx_stats_write,
165 .llseek = default_llseek,
169 /* Write 1 to ask the device to go into suspend */
171 int debugfs_i2400m_suspend_set(void *data, u64 val)
174 struct i2400m *i2400m = data;
175 result = i2400m_cmd_enter_powersave(i2400m);
180 DEFINE_SIMPLE_ATTRIBUTE(fops_i2400m_suspend,
181 NULL, debugfs_i2400m_suspend_set,
185 struct dentry *debugfs_create_i2400m_suspend(
186 const char *name, struct dentry *parent, struct i2400m *i2400m)
188 return debugfs_create_file(name, 0200, parent, i2400m,
189 &fops_i2400m_suspend);
196 * Write 0 to ask the device to soft reset, 1 to cold reset, 2 to bus
197 * reset (as defined by enum i2400m_reset_type).
200 int debugfs_i2400m_reset_set(void *data, u64 val)
203 struct i2400m *i2400m = data;
204 enum i2400m_reset_type rt = val;
209 result = i2400m_reset(i2400m, rt);
217 DEFINE_SIMPLE_ATTRIBUTE(fops_i2400m_reset,
218 NULL, debugfs_i2400m_reset_set,
222 struct dentry *debugfs_create_i2400m_reset(
223 const char *name, struct dentry *parent, struct i2400m *i2400m)
225 return debugfs_create_file(name, 0200, parent, i2400m,
230 #define __debugfs_register(prefix, name, parent) \
232 result = d_level_register_debugfs(prefix, name, parent); \
238 int i2400m_debugfs_add(struct i2400m *i2400m)
241 struct device *dev = i2400m_dev(i2400m);
242 struct dentry *dentry = i2400m->wimax_dev.debugfs_dentry;
245 dentry = debugfs_create_dir("i2400m", dentry);
246 result = PTR_ERR(dentry);
247 if (IS_ERR(dentry)) {
248 if (result == -ENODEV)
249 result = 0; /* No debugfs support */
252 i2400m->debugfs_dentry = dentry;
253 __debugfs_register("dl_", control, dentry);
254 __debugfs_register("dl_", driver, dentry);
255 __debugfs_register("dl_", debugfs, dentry);
256 __debugfs_register("dl_", fw, dentry);
257 __debugfs_register("dl_", netdev, dentry);
258 __debugfs_register("dl_", rfkill, dentry);
259 __debugfs_register("dl_", rx, dentry);
260 __debugfs_register("dl_", tx, dentry);
262 fd = debugfs_create_size_t("tx_in", 0400, dentry,
264 result = PTR_ERR(fd);
265 if (IS_ERR(fd) && result != -ENODEV) {
266 dev_err(dev, "Can't create debugfs entry "
267 "tx_in: %d\n", result);
271 fd = debugfs_create_size_t("tx_out", 0400, dentry,
273 result = PTR_ERR(fd);
274 if (IS_ERR(fd) && result != -ENODEV) {
275 dev_err(dev, "Can't create debugfs entry "
276 "tx_out: %d\n", result);
280 fd = debugfs_create_u32("state", 0600, dentry,
282 result = PTR_ERR(fd);
283 if (IS_ERR(fd) && result != -ENODEV) {
284 dev_err(dev, "Can't create debugfs entry "
285 "state: %d\n", result);
290 * Trace received messages from user space
292 * In order to tap the bidirectional message stream in the
293 * 'msg' pipe, user space can read from the 'msg' pipe;
294 * however, due to limitations in libnl, we can't know what
295 * the different applications are sending down to the kernel.
297 * So we have this hack where the driver will echo any message
298 * received on the msg pipe from user space [through a call to
299 * wimax_dev->op_msg_from_user() into
300 * i2400m_op_msg_from_user()] into the 'trace' pipe that this
303 * So then, reading from both the 'trace' and 'msg' pipes in
304 * user space will provide a full dump of the traffic.
306 * Write 1 to activate, 0 to clear.
308 * It is not really very atomic, but it is also not too
311 fd = debugfs_create_u8("trace_msg_from_user", 0600, dentry,
312 &i2400m->trace_msg_from_user);
313 result = PTR_ERR(fd);
314 if (IS_ERR(fd) && result != -ENODEV) {
315 dev_err(dev, "Can't create debugfs entry "
316 "trace_msg_from_user: %d\n", result);
320 fd = debugfs_create_netdev_queue_stopped("netdev_queue_stopped",
322 result = PTR_ERR(fd);
323 if (IS_ERR(fd) && result != -ENODEV) {
324 dev_err(dev, "Can't create debugfs entry "
325 "netdev_queue_stopped: %d\n", result);
329 fd = debugfs_create_file("rx_stats", 0600, dentry, i2400m,
330 &i2400m_rx_stats_fops);
331 result = PTR_ERR(fd);
332 if (IS_ERR(fd) && result != -ENODEV) {
333 dev_err(dev, "Can't create debugfs entry "
334 "rx_stats: %d\n", result);
338 fd = debugfs_create_file("tx_stats", 0600, dentry, i2400m,
339 &i2400m_tx_stats_fops);
340 result = PTR_ERR(fd);
341 if (IS_ERR(fd) && result != -ENODEV) {
342 dev_err(dev, "Can't create debugfs entry "
343 "tx_stats: %d\n", result);
347 fd = debugfs_create_i2400m_suspend("suspend", dentry, i2400m);
348 result = PTR_ERR(fd);
349 if (IS_ERR(fd) && result != -ENODEV) {
350 dev_err(dev, "Can't create debugfs entry suspend: %d\n",
355 fd = debugfs_create_i2400m_reset("reset", dentry, i2400m);
356 result = PTR_ERR(fd);
357 if (IS_ERR(fd) && result != -ENODEV) {
358 dev_err(dev, "Can't create debugfs entry reset: %d\n", result);
367 void i2400m_debugfs_rm(struct i2400m *i2400m)
369 debugfs_remove_recursive(i2400m->debugfs_dentry);