proc: use seq_puts()/seq_putc() where possible
[linux-2.6/next.git] / drivers / net / wimax / i2400m / debugfs.c
blob9c70b5fa3f51e03b0ea51c84d844df4c22089ad3
1 /*
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
21 * 02110-1301, USA.
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 "i2400m.h"
32 #define D_SUBMODULE debugfs
33 #include "debug-levels.h"
35 static
36 int debugfs_netdev_queue_stopped_get(void *data, u64 *val)
38 struct i2400m *i2400m = data;
39 *val = netif_queue_stopped(i2400m->wimax_dev.net_dev);
40 return 0;
42 DEFINE_SIMPLE_ATTRIBUTE(fops_netdev_queue_stopped,
43 debugfs_netdev_queue_stopped_get,
44 NULL, "%llu\n");
47 static
48 struct dentry *debugfs_create_netdev_queue_stopped(
49 const char *name, struct dentry *parent, struct i2400m *i2400m)
51 return debugfs_create_file(name, 0400, parent, i2400m,
52 &fops_netdev_queue_stopped);
57 * inode->i_private has the @data argument to debugfs_create_file()
59 static
60 int i2400m_stats_open(struct inode *inode, struct file *filp)
62 filp->private_data = inode->i_private;
63 return 0;
67 * We don't allow partial reads of this file, as then the reader would
68 * get weirdly confused data as it is updated.
70 * So or you read it all or nothing; if you try to read with an offset
71 * != 0, we consider you are done reading.
73 static
74 ssize_t i2400m_rx_stats_read(struct file *filp, char __user *buffer,
75 size_t count, loff_t *ppos)
77 struct i2400m *i2400m = filp->private_data;
78 char buf[128];
79 unsigned long flags;
81 if (*ppos != 0)
82 return 0;
83 if (count < sizeof(buf))
84 return -ENOSPC;
85 spin_lock_irqsave(&i2400m->rx_lock, flags);
86 snprintf(buf, sizeof(buf), "%u %u %u %u %u %u %u\n",
87 i2400m->rx_pl_num, i2400m->rx_pl_min,
88 i2400m->rx_pl_max, i2400m->rx_num,
89 i2400m->rx_size_acc,
90 i2400m->rx_size_min, i2400m->rx_size_max);
91 spin_unlock_irqrestore(&i2400m->rx_lock, flags);
92 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
96 /* Any write clears the stats */
97 static
98 ssize_t i2400m_rx_stats_write(struct file *filp, const char __user *buffer,
99 size_t count, loff_t *ppos)
101 struct i2400m *i2400m = filp->private_data;
102 unsigned long flags;
104 spin_lock_irqsave(&i2400m->rx_lock, flags);
105 i2400m->rx_pl_num = 0;
106 i2400m->rx_pl_max = 0;
107 i2400m->rx_pl_min = UINT_MAX;
108 i2400m->rx_num = 0;
109 i2400m->rx_size_acc = 0;
110 i2400m->rx_size_min = UINT_MAX;
111 i2400m->rx_size_max = 0;
112 spin_unlock_irqrestore(&i2400m->rx_lock, flags);
113 return count;
116 static
117 const struct file_operations i2400m_rx_stats_fops = {
118 .owner = THIS_MODULE,
119 .open = i2400m_stats_open,
120 .read = i2400m_rx_stats_read,
121 .write = i2400m_rx_stats_write,
122 .llseek = default_llseek,
126 /* See i2400m_rx_stats_read() */
127 static
128 ssize_t i2400m_tx_stats_read(struct file *filp, char __user *buffer,
129 size_t count, loff_t *ppos)
131 struct i2400m *i2400m = filp->private_data;
132 char buf[128];
133 unsigned long flags;
135 if (*ppos != 0)
136 return 0;
137 if (count < sizeof(buf))
138 return -ENOSPC;
139 spin_lock_irqsave(&i2400m->tx_lock, flags);
140 snprintf(buf, sizeof(buf), "%u %u %u %u %u %u %u\n",
141 i2400m->tx_pl_num, i2400m->tx_pl_min,
142 i2400m->tx_pl_max, i2400m->tx_num,
143 i2400m->tx_size_acc,
144 i2400m->tx_size_min, i2400m->tx_size_max);
145 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
146 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
149 /* Any write clears the stats */
150 static
151 ssize_t i2400m_tx_stats_write(struct file *filp, const char __user *buffer,
152 size_t count, loff_t *ppos)
154 struct i2400m *i2400m = filp->private_data;
155 unsigned long flags;
157 spin_lock_irqsave(&i2400m->tx_lock, flags);
158 i2400m->tx_pl_num = 0;
159 i2400m->tx_pl_max = 0;
160 i2400m->tx_pl_min = UINT_MAX;
161 i2400m->tx_num = 0;
162 i2400m->tx_size_acc = 0;
163 i2400m->tx_size_min = UINT_MAX;
164 i2400m->tx_size_max = 0;
165 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
166 return count;
169 static
170 const struct file_operations i2400m_tx_stats_fops = {
171 .owner = THIS_MODULE,
172 .open = i2400m_stats_open,
173 .read = i2400m_tx_stats_read,
174 .write = i2400m_tx_stats_write,
175 .llseek = default_llseek,
179 /* Write 1 to ask the device to go into suspend */
180 static
181 int debugfs_i2400m_suspend_set(void *data, u64 val)
183 int result;
184 struct i2400m *i2400m = data;
185 result = i2400m_cmd_enter_powersave(i2400m);
186 if (result >= 0)
187 result = 0;
188 return result;
190 DEFINE_SIMPLE_ATTRIBUTE(fops_i2400m_suspend,
191 NULL, debugfs_i2400m_suspend_set,
192 "%llu\n");
194 static
195 struct dentry *debugfs_create_i2400m_suspend(
196 const char *name, struct dentry *parent, struct i2400m *i2400m)
198 return debugfs_create_file(name, 0200, parent, i2400m,
199 &fops_i2400m_suspend);
204 * Reset the device
206 * Write 0 to ask the device to soft reset, 1 to cold reset, 2 to bus
207 * reset (as defined by enum i2400m_reset_type).
209 static
210 int debugfs_i2400m_reset_set(void *data, u64 val)
212 int result;
213 struct i2400m *i2400m = data;
214 enum i2400m_reset_type rt = val;
215 switch(rt) {
216 case I2400M_RT_WARM:
217 case I2400M_RT_COLD:
218 case I2400M_RT_BUS:
219 result = i2400m_reset(i2400m, rt);
220 if (result >= 0)
221 result = 0;
222 default:
223 result = -EINVAL;
225 return result;
227 DEFINE_SIMPLE_ATTRIBUTE(fops_i2400m_reset,
228 NULL, debugfs_i2400m_reset_set,
229 "%llu\n");
231 static
232 struct dentry *debugfs_create_i2400m_reset(
233 const char *name, struct dentry *parent, struct i2400m *i2400m)
235 return debugfs_create_file(name, 0200, parent, i2400m,
236 &fops_i2400m_reset);
240 #define __debugfs_register(prefix, name, parent) \
241 do { \
242 result = d_level_register_debugfs(prefix, name, parent); \
243 if (result < 0) \
244 goto error; \
245 } while (0)
248 int i2400m_debugfs_add(struct i2400m *i2400m)
250 int result;
251 struct device *dev = i2400m_dev(i2400m);
252 struct dentry *dentry = i2400m->wimax_dev.debugfs_dentry;
253 struct dentry *fd;
255 dentry = debugfs_create_dir("i2400m", dentry);
256 result = PTR_ERR(dentry);
257 if (IS_ERR(dentry)) {
258 if (result == -ENODEV)
259 result = 0; /* No debugfs support */
260 goto error;
262 i2400m->debugfs_dentry = dentry;
263 __debugfs_register("dl_", control, dentry);
264 __debugfs_register("dl_", driver, dentry);
265 __debugfs_register("dl_", debugfs, dentry);
266 __debugfs_register("dl_", fw, dentry);
267 __debugfs_register("dl_", netdev, dentry);
268 __debugfs_register("dl_", rfkill, dentry);
269 __debugfs_register("dl_", rx, dentry);
270 __debugfs_register("dl_", tx, dentry);
272 fd = debugfs_create_size_t("tx_in", 0400, dentry,
273 &i2400m->tx_in);
274 result = PTR_ERR(fd);
275 if (IS_ERR(fd) && result != -ENODEV) {
276 dev_err(dev, "Can't create debugfs entry "
277 "tx_in: %d\n", result);
278 goto error;
281 fd = debugfs_create_size_t("tx_out", 0400, dentry,
282 &i2400m->tx_out);
283 result = PTR_ERR(fd);
284 if (IS_ERR(fd) && result != -ENODEV) {
285 dev_err(dev, "Can't create debugfs entry "
286 "tx_out: %d\n", result);
287 goto error;
290 fd = debugfs_create_u32("state", 0600, dentry,
291 &i2400m->state);
292 result = PTR_ERR(fd);
293 if (IS_ERR(fd) && result != -ENODEV) {
294 dev_err(dev, "Can't create debugfs entry "
295 "state: %d\n", result);
296 goto error;
300 * Trace received messages from user space
302 * In order to tap the bidirectional message stream in the
303 * 'msg' pipe, user space can read from the 'msg' pipe;
304 * however, due to limitations in libnl, we can't know what
305 * the different applications are sending down to the kernel.
307 * So we have this hack where the driver will echo any message
308 * received on the msg pipe from user space [through a call to
309 * wimax_dev->op_msg_from_user() into
310 * i2400m_op_msg_from_user()] into the 'trace' pipe that this
311 * driver creates.
313 * So then, reading from both the 'trace' and 'msg' pipes in
314 * user space will provide a full dump of the traffic.
316 * Write 1 to activate, 0 to clear.
318 * It is not really very atomic, but it is also not too
319 * critical.
321 fd = debugfs_create_u8("trace_msg_from_user", 0600, dentry,
322 &i2400m->trace_msg_from_user);
323 result = PTR_ERR(fd);
324 if (IS_ERR(fd) && result != -ENODEV) {
325 dev_err(dev, "Can't create debugfs entry "
326 "trace_msg_from_user: %d\n", result);
327 goto error;
330 fd = debugfs_create_netdev_queue_stopped("netdev_queue_stopped",
331 dentry, i2400m);
332 result = PTR_ERR(fd);
333 if (IS_ERR(fd) && result != -ENODEV) {
334 dev_err(dev, "Can't create debugfs entry "
335 "netdev_queue_stopped: %d\n", result);
336 goto error;
339 fd = debugfs_create_file("rx_stats", 0600, dentry, i2400m,
340 &i2400m_rx_stats_fops);
341 result = PTR_ERR(fd);
342 if (IS_ERR(fd) && result != -ENODEV) {
343 dev_err(dev, "Can't create debugfs entry "
344 "rx_stats: %d\n", result);
345 goto error;
348 fd = debugfs_create_file("tx_stats", 0600, dentry, i2400m,
349 &i2400m_tx_stats_fops);
350 result = PTR_ERR(fd);
351 if (IS_ERR(fd) && result != -ENODEV) {
352 dev_err(dev, "Can't create debugfs entry "
353 "tx_stats: %d\n", result);
354 goto error;
357 fd = debugfs_create_i2400m_suspend("suspend", dentry, i2400m);
358 result = PTR_ERR(fd);
359 if (IS_ERR(fd) && result != -ENODEV) {
360 dev_err(dev, "Can't create debugfs entry suspend: %d\n",
361 result);
362 goto error;
365 fd = debugfs_create_i2400m_reset("reset", dentry, i2400m);
366 result = PTR_ERR(fd);
367 if (IS_ERR(fd) && result != -ENODEV) {
368 dev_err(dev, "Can't create debugfs entry reset: %d\n", result);
369 goto error;
372 result = 0;
373 error:
374 return result;
377 void i2400m_debugfs_rm(struct i2400m *i2400m)
379 debugfs_remove_recursive(i2400m->debugfs_dentry);