spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / drivers / net / wimax / i2400m / debugfs.c
blob129ba36bd04d6a52c205aa60c44d042c2003401b
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 <linux/export.h>
30 #include "i2400m.h"
33 #define D_SUBMODULE debugfs
34 #include "debug-levels.h"
36 static
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);
41 return 0;
43 DEFINE_SIMPLE_ATTRIBUTE(fops_netdev_queue_stopped,
44 debugfs_netdev_queue_stopped_get,
45 NULL, "%llu\n");
48 static
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()
60 static
61 int i2400m_stats_open(struct inode *inode, struct file *filp)
63 filp->private_data = inode->i_private;
64 return 0;
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.
74 static
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;
79 char buf[128];
80 unsigned long flags;
82 if (*ppos != 0)
83 return 0;
84 if (count < sizeof(buf))
85 return -ENOSPC;
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,
90 i2400m->rx_size_acc,
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 */
98 static
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;
103 unsigned long flags;
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;
109 i2400m->rx_num = 0;
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);
114 return count;
117 static
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() */
128 static
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;
133 char buf[128];
134 unsigned long flags;
136 if (*ppos != 0)
137 return 0;
138 if (count < sizeof(buf))
139 return -ENOSPC;
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,
144 i2400m->tx_size_acc,
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 */
151 static
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;
156 unsigned long flags;
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;
162 i2400m->tx_num = 0;
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);
167 return count;
170 static
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 */
181 static
182 int debugfs_i2400m_suspend_set(void *data, u64 val)
184 int result;
185 struct i2400m *i2400m = data;
186 result = i2400m_cmd_enter_powersave(i2400m);
187 if (result >= 0)
188 result = 0;
189 return result;
191 DEFINE_SIMPLE_ATTRIBUTE(fops_i2400m_suspend,
192 NULL, debugfs_i2400m_suspend_set,
193 "%llu\n");
195 static
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);
205 * Reset the device
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).
210 static
211 int debugfs_i2400m_reset_set(void *data, u64 val)
213 int result;
214 struct i2400m *i2400m = data;
215 enum i2400m_reset_type rt = val;
216 switch(rt) {
217 case I2400M_RT_WARM:
218 case I2400M_RT_COLD:
219 case I2400M_RT_BUS:
220 result = i2400m_reset(i2400m, rt);
221 if (result >= 0)
222 result = 0;
223 default:
224 result = -EINVAL;
226 return result;
228 DEFINE_SIMPLE_ATTRIBUTE(fops_i2400m_reset,
229 NULL, debugfs_i2400m_reset_set,
230 "%llu\n");
232 static
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,
237 &fops_i2400m_reset);
241 #define __debugfs_register(prefix, name, parent) \
242 do { \
243 result = d_level_register_debugfs(prefix, name, parent); \
244 if (result < 0) \
245 goto error; \
246 } while (0)
249 int i2400m_debugfs_add(struct i2400m *i2400m)
251 int result;
252 struct device *dev = i2400m_dev(i2400m);
253 struct dentry *dentry = i2400m->wimax_dev.debugfs_dentry;
254 struct dentry *fd;
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 */
261 goto error;
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,
274 &i2400m->tx_in);
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);
279 goto error;
282 fd = debugfs_create_size_t("tx_out", 0400, dentry,
283 &i2400m->tx_out);
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);
288 goto error;
291 fd = debugfs_create_u32("state", 0600, dentry,
292 &i2400m->state);
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);
297 goto error;
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
312 * driver creates.
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
320 * critical.
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);
328 goto error;
331 fd = debugfs_create_netdev_queue_stopped("netdev_queue_stopped",
332 dentry, i2400m);
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);
337 goto error;
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);
346 goto error;
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);
355 goto error;
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",
362 result);
363 goto error;
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);
370 goto error;
373 result = 0;
374 error:
375 return result;
378 void i2400m_debugfs_rm(struct i2400m *i2400m)
380 debugfs_remove_recursive(i2400m->debugfs_dentry);