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
);
58 * inode->i_private has the @data argument to debugfs_create_file()
61 int i2400m_stats_open(struct inode
*inode
, struct file
*filp
)
63 filp
->private_data
= inode
->i_private
;
68 * We don't allow partial reads of this file, as then the reader would
69 * get weirdly confused data as it is updated.
71 * So or you read it all or nothing; if you try to read with an offset
72 * != 0, we consider you are done reading.
75 ssize_t
i2400m_rx_stats_read(struct file
*filp
, char __user
*buffer
,
76 size_t count
, loff_t
*ppos
)
78 struct i2400m
*i2400m
= filp
->private_data
;
84 if (count
< sizeof(buf
))
86 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
87 snprintf(buf
, sizeof(buf
), "%u %u %u %u %u %u %u\n",
88 i2400m
->rx_pl_num
, i2400m
->rx_pl_min
,
89 i2400m
->rx_pl_max
, i2400m
->rx_num
,
91 i2400m
->rx_size_min
, i2400m
->rx_size_max
);
92 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
93 return simple_read_from_buffer(buffer
, count
, ppos
, buf
, strlen(buf
));
97 /* Any write clears the stats */
99 ssize_t
i2400m_rx_stats_write(struct file
*filp
, const char __user
*buffer
,
100 size_t count
, loff_t
*ppos
)
102 struct i2400m
*i2400m
= filp
->private_data
;
105 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
106 i2400m
->rx_pl_num
= 0;
107 i2400m
->rx_pl_max
= 0;
108 i2400m
->rx_pl_min
= UINT_MAX
;
110 i2400m
->rx_size_acc
= 0;
111 i2400m
->rx_size_min
= UINT_MAX
;
112 i2400m
->rx_size_max
= 0;
113 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
118 const struct file_operations i2400m_rx_stats_fops
= {
119 .owner
= THIS_MODULE
,
120 .open
= i2400m_stats_open
,
121 .read
= i2400m_rx_stats_read
,
122 .write
= i2400m_rx_stats_write
,
123 .llseek
= default_llseek
,
127 /* See i2400m_rx_stats_read() */
129 ssize_t
i2400m_tx_stats_read(struct file
*filp
, char __user
*buffer
,
130 size_t count
, loff_t
*ppos
)
132 struct i2400m
*i2400m
= filp
->private_data
;
138 if (count
< sizeof(buf
))
140 spin_lock_irqsave(&i2400m
->tx_lock
, flags
);
141 snprintf(buf
, sizeof(buf
), "%u %u %u %u %u %u %u\n",
142 i2400m
->tx_pl_num
, i2400m
->tx_pl_min
,
143 i2400m
->tx_pl_max
, i2400m
->tx_num
,
145 i2400m
->tx_size_min
, i2400m
->tx_size_max
);
146 spin_unlock_irqrestore(&i2400m
->tx_lock
, flags
);
147 return simple_read_from_buffer(buffer
, count
, ppos
, buf
, strlen(buf
));
150 /* Any write clears the stats */
152 ssize_t
i2400m_tx_stats_write(struct file
*filp
, const char __user
*buffer
,
153 size_t count
, loff_t
*ppos
)
155 struct i2400m
*i2400m
= filp
->private_data
;
158 spin_lock_irqsave(&i2400m
->tx_lock
, flags
);
159 i2400m
->tx_pl_num
= 0;
160 i2400m
->tx_pl_max
= 0;
161 i2400m
->tx_pl_min
= UINT_MAX
;
163 i2400m
->tx_size_acc
= 0;
164 i2400m
->tx_size_min
= UINT_MAX
;
165 i2400m
->tx_size_max
= 0;
166 spin_unlock_irqrestore(&i2400m
->tx_lock
, flags
);
171 const struct file_operations i2400m_tx_stats_fops
= {
172 .owner
= THIS_MODULE
,
173 .open
= i2400m_stats_open
,
174 .read
= i2400m_tx_stats_read
,
175 .write
= i2400m_tx_stats_write
,
176 .llseek
= default_llseek
,
180 /* Write 1 to ask the device to go into suspend */
182 int debugfs_i2400m_suspend_set(void *data
, u64 val
)
185 struct i2400m
*i2400m
= data
;
186 result
= i2400m_cmd_enter_powersave(i2400m
);
191 DEFINE_SIMPLE_ATTRIBUTE(fops_i2400m_suspend
,
192 NULL
, debugfs_i2400m_suspend_set
,
196 struct dentry
*debugfs_create_i2400m_suspend(
197 const char *name
, struct dentry
*parent
, struct i2400m
*i2400m
)
199 return debugfs_create_file(name
, 0200, parent
, i2400m
,
200 &fops_i2400m_suspend
);
207 * Write 0 to ask the device to soft reset, 1 to cold reset, 2 to bus
208 * reset (as defined by enum i2400m_reset_type).
211 int debugfs_i2400m_reset_set(void *data
, u64 val
)
214 struct i2400m
*i2400m
= data
;
215 enum i2400m_reset_type rt
= val
;
220 result
= i2400m_reset(i2400m
, rt
);
228 DEFINE_SIMPLE_ATTRIBUTE(fops_i2400m_reset
,
229 NULL
, debugfs_i2400m_reset_set
,
233 struct dentry
*debugfs_create_i2400m_reset(
234 const char *name
, struct dentry
*parent
, struct i2400m
*i2400m
)
236 return debugfs_create_file(name
, 0200, parent
, i2400m
,
241 #define __debugfs_register(prefix, name, parent) \
243 result = d_level_register_debugfs(prefix, name, parent); \
249 int i2400m_debugfs_add(struct i2400m
*i2400m
)
252 struct device
*dev
= i2400m_dev(i2400m
);
253 struct dentry
*dentry
= i2400m
->wimax_dev
.debugfs_dentry
;
256 dentry
= debugfs_create_dir("i2400m", dentry
);
257 result
= PTR_ERR(dentry
);
258 if (IS_ERR(dentry
)) {
259 if (result
== -ENODEV
)
260 result
= 0; /* No debugfs support */
263 i2400m
->debugfs_dentry
= dentry
;
264 __debugfs_register("dl_", control
, dentry
);
265 __debugfs_register("dl_", driver
, dentry
);
266 __debugfs_register("dl_", debugfs
, dentry
);
267 __debugfs_register("dl_", fw
, dentry
);
268 __debugfs_register("dl_", netdev
, dentry
);
269 __debugfs_register("dl_", rfkill
, dentry
);
270 __debugfs_register("dl_", rx
, dentry
);
271 __debugfs_register("dl_", tx
, dentry
);
273 fd
= debugfs_create_size_t("tx_in", 0400, dentry
,
275 result
= PTR_ERR(fd
);
276 if (IS_ERR(fd
) && result
!= -ENODEV
) {
277 dev_err(dev
, "Can't create debugfs entry "
278 "tx_in: %d\n", result
);
282 fd
= debugfs_create_size_t("tx_out", 0400, dentry
,
284 result
= PTR_ERR(fd
);
285 if (IS_ERR(fd
) && result
!= -ENODEV
) {
286 dev_err(dev
, "Can't create debugfs entry "
287 "tx_out: %d\n", result
);
291 fd
= debugfs_create_u32("state", 0600, dentry
,
293 result
= PTR_ERR(fd
);
294 if (IS_ERR(fd
) && result
!= -ENODEV
) {
295 dev_err(dev
, "Can't create debugfs entry "
296 "state: %d\n", result
);
301 * Trace received messages from user space
303 * In order to tap the bidirectional message stream in the
304 * 'msg' pipe, user space can read from the 'msg' pipe;
305 * however, due to limitations in libnl, we can't know what
306 * the different applications are sending down to the kernel.
308 * So we have this hack where the driver will echo any message
309 * received on the msg pipe from user space [through a call to
310 * wimax_dev->op_msg_from_user() into
311 * i2400m_op_msg_from_user()] into the 'trace' pipe that this
314 * So then, reading from both the 'trace' and 'msg' pipes in
315 * user space will provide a full dump of the traffic.
317 * Write 1 to activate, 0 to clear.
319 * It is not really very atomic, but it is also not too
322 fd
= debugfs_create_u8("trace_msg_from_user", 0600, dentry
,
323 &i2400m
->trace_msg_from_user
);
324 result
= PTR_ERR(fd
);
325 if (IS_ERR(fd
) && result
!= -ENODEV
) {
326 dev_err(dev
, "Can't create debugfs entry "
327 "trace_msg_from_user: %d\n", result
);
331 fd
= debugfs_create_netdev_queue_stopped("netdev_queue_stopped",
333 result
= PTR_ERR(fd
);
334 if (IS_ERR(fd
) && result
!= -ENODEV
) {
335 dev_err(dev
, "Can't create debugfs entry "
336 "netdev_queue_stopped: %d\n", result
);
340 fd
= debugfs_create_file("rx_stats", 0600, dentry
, i2400m
,
341 &i2400m_rx_stats_fops
);
342 result
= PTR_ERR(fd
);
343 if (IS_ERR(fd
) && result
!= -ENODEV
) {
344 dev_err(dev
, "Can't create debugfs entry "
345 "rx_stats: %d\n", result
);
349 fd
= debugfs_create_file("tx_stats", 0600, dentry
, i2400m
,
350 &i2400m_tx_stats_fops
);
351 result
= PTR_ERR(fd
);
352 if (IS_ERR(fd
) && result
!= -ENODEV
) {
353 dev_err(dev
, "Can't create debugfs entry "
354 "tx_stats: %d\n", result
);
358 fd
= debugfs_create_i2400m_suspend("suspend", dentry
, i2400m
);
359 result
= PTR_ERR(fd
);
360 if (IS_ERR(fd
) && result
!= -ENODEV
) {
361 dev_err(dev
, "Can't create debugfs entry suspend: %d\n",
366 fd
= debugfs_create_i2400m_reset("reset", dentry
, i2400m
);
367 result
= PTR_ERR(fd
);
368 if (IS_ERR(fd
) && result
!= -ENODEV
) {
369 dev_err(dev
, "Can't create debugfs entry reset: %d\n", result
);
378 void i2400m_debugfs_rm(struct i2400m
*i2400m
)
380 debugfs_remove_recursive(i2400m
->debugfs_dentry
);