include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / net / wireless / libertas / debugfs.c
blob1af182778844c04d47e5f070fa853cff0c6c2925
1 #include <linux/dcache.h>
2 #include <linux/debugfs.h>
3 #include <linux/delay.h>
4 #include <linux/hardirq.h>
5 #include <linux/mm.h>
6 #include <linux/string.h>
7 #include <linux/slab.h>
9 #include "decl.h"
10 #include "cmd.h"
11 #include "debugfs.h"
13 static struct dentry *lbs_dir;
14 static char *szStates[] = {
15 "Connected",
16 "Disconnected"
19 #ifdef PROC_DEBUG
20 static void lbs_debug_init(struct lbs_private *priv);
21 #endif
23 static int open_file_generic(struct inode *inode, struct file *file)
25 file->private_data = inode->i_private;
26 return 0;
29 static ssize_t write_file_dummy(struct file *file, const char __user *buf,
30 size_t count, loff_t *ppos)
32 return -EINVAL;
35 static const size_t len = PAGE_SIZE;
37 static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
38 size_t count, loff_t *ppos)
40 struct lbs_private *priv = file->private_data;
41 size_t pos = 0;
42 unsigned long addr = get_zeroed_page(GFP_KERNEL);
43 char *buf = (char *)addr;
44 ssize_t res;
45 if (!buf)
46 return -ENOMEM;
48 pos += snprintf(buf+pos, len-pos, "state = %s\n",
49 szStates[priv->connect_status]);
50 pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
51 (u32) priv->regioncode);
53 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
55 free_page(addr);
56 return res;
59 static ssize_t lbs_sleepparams_write(struct file *file,
60 const char __user *user_buf, size_t count,
61 loff_t *ppos)
63 struct lbs_private *priv = file->private_data;
64 ssize_t buf_size, ret;
65 struct sleep_params sp;
66 int p1, p2, p3, p4, p5, p6;
67 unsigned long addr = get_zeroed_page(GFP_KERNEL);
68 char *buf = (char *)addr;
69 if (!buf)
70 return -ENOMEM;
72 buf_size = min(count, len - 1);
73 if (copy_from_user(buf, user_buf, buf_size)) {
74 ret = -EFAULT;
75 goto out_unlock;
77 ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
78 if (ret != 6) {
79 ret = -EINVAL;
80 goto out_unlock;
82 sp.sp_error = p1;
83 sp.sp_offset = p2;
84 sp.sp_stabletime = p3;
85 sp.sp_calcontrol = p4;
86 sp.sp_extsleepclk = p5;
87 sp.sp_reserved = p6;
89 ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp);
90 if (!ret)
91 ret = count;
92 else if (ret > 0)
93 ret = -EINVAL;
95 out_unlock:
96 free_page(addr);
97 return ret;
100 static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
101 size_t count, loff_t *ppos)
103 struct lbs_private *priv = file->private_data;
104 ssize_t ret;
105 size_t pos = 0;
106 struct sleep_params sp;
107 unsigned long addr = get_zeroed_page(GFP_KERNEL);
108 char *buf = (char *)addr;
109 if (!buf)
110 return -ENOMEM;
112 ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp);
113 if (ret)
114 goto out_unlock;
116 pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error,
117 sp.sp_offset, sp.sp_stabletime,
118 sp.sp_calcontrol, sp.sp_extsleepclk,
119 sp.sp_reserved);
121 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
123 out_unlock:
124 free_page(addr);
125 return ret;
128 static ssize_t lbs_host_sleep_write(struct file *file,
129 const char __user *user_buf, size_t count,
130 loff_t *ppos)
132 struct lbs_private *priv = file->private_data;
133 ssize_t buf_size, ret;
134 int host_sleep;
135 unsigned long addr = get_zeroed_page(GFP_KERNEL);
136 char *buf = (char *)addr;
137 if (!buf)
138 return -ENOMEM;
140 buf_size = min(count, len - 1);
141 if (copy_from_user(buf, user_buf, buf_size)) {
142 ret = -EFAULT;
143 goto out_unlock;
145 ret = sscanf(buf, "%d", &host_sleep);
146 if (ret != 1) {
147 ret = -EINVAL;
148 goto out_unlock;
151 if (host_sleep == 0)
152 ret = lbs_set_host_sleep(priv, 0);
153 else if (host_sleep == 1) {
154 if (priv->wol_criteria == EHS_REMOVE_WAKEUP) {
155 netdev_info(priv->dev,
156 "wake parameters not configured\n");
157 ret = -EINVAL;
158 goto out_unlock;
160 ret = lbs_set_host_sleep(priv, 1);
161 } else {
162 netdev_err(priv->dev, "invalid option\n");
163 ret = -EINVAL;
166 if (!ret)
167 ret = count;
169 out_unlock:
170 free_page(addr);
171 return ret;
174 static ssize_t lbs_host_sleep_read(struct file *file, char __user *userbuf,
175 size_t count, loff_t *ppos)
177 struct lbs_private *priv = file->private_data;
178 ssize_t ret;
179 size_t pos = 0;
180 unsigned long addr = get_zeroed_page(GFP_KERNEL);
181 char *buf = (char *)addr;
182 if (!buf)
183 return -ENOMEM;
185 pos += snprintf(buf, len, "%d\n", priv->is_host_sleep_activated);
187 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
189 free_page(addr);
190 return ret;
194 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
195 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
196 * firmware. Here's an example:
197 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
198 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
199 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
201 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
202 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
203 * defined in mrvlietypes_thresholds
205 * This function searches in this TLV data chunk for a given TLV type
206 * and returns a pointer to the first data byte of the TLV, or to NULL
207 * if the TLV hasn't been found.
209 static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size)
211 struct mrvl_ie_header *tlv_h;
212 uint16_t length;
213 ssize_t pos = 0;
215 while (pos < size) {
216 tlv_h = (struct mrvl_ie_header *) tlv;
217 if (!tlv_h->len)
218 return NULL;
219 if (tlv_h->type == cpu_to_le16(tlv_type))
220 return tlv_h;
221 length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h);
222 pos += length;
223 tlv += length;
225 return NULL;
229 static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask,
230 struct file *file, char __user *userbuf,
231 size_t count, loff_t *ppos)
233 struct cmd_ds_802_11_subscribe_event *subscribed;
234 struct mrvl_ie_thresholds *got;
235 struct lbs_private *priv = file->private_data;
236 ssize_t ret = 0;
237 size_t pos = 0;
238 char *buf;
239 u8 value;
240 u8 freq;
241 int events = 0;
243 buf = (char *)get_zeroed_page(GFP_KERNEL);
244 if (!buf)
245 return -ENOMEM;
247 subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL);
248 if (!subscribed) {
249 ret = -ENOMEM;
250 goto out_page;
253 subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed));
254 subscribed->action = cpu_to_le16(CMD_ACT_GET);
256 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed);
257 if (ret)
258 goto out_cmd;
260 got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
261 if (got) {
262 value = got->value;
263 freq = got->freq;
264 events = le16_to_cpu(subscribed->events);
266 pos += snprintf(buf, len, "%d %d %d\n", value, freq,
267 !!(events & event_mask));
270 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
272 out_cmd:
273 kfree(subscribed);
275 out_page:
276 free_page((unsigned long)buf);
277 return ret;
281 static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask,
282 struct file *file,
283 const char __user *userbuf, size_t count,
284 loff_t *ppos)
286 struct cmd_ds_802_11_subscribe_event *events;
287 struct mrvl_ie_thresholds *tlv;
288 struct lbs_private *priv = file->private_data;
289 ssize_t buf_size;
290 int value, freq, new_mask;
291 uint16_t curr_mask;
292 char *buf;
293 int ret;
295 buf = (char *)get_zeroed_page(GFP_KERNEL);
296 if (!buf)
297 return -ENOMEM;
299 buf_size = min(count, len - 1);
300 if (copy_from_user(buf, userbuf, buf_size)) {
301 ret = -EFAULT;
302 goto out_page;
304 ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
305 if (ret != 3) {
306 ret = -EINVAL;
307 goto out_page;
309 events = kzalloc(sizeof(*events), GFP_KERNEL);
310 if (!events) {
311 ret = -ENOMEM;
312 goto out_page;
315 events->hdr.size = cpu_to_le16(sizeof(*events));
316 events->action = cpu_to_le16(CMD_ACT_GET);
318 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
319 if (ret)
320 goto out_events;
322 curr_mask = le16_to_cpu(events->events);
324 if (new_mask)
325 new_mask = curr_mask | event_mask;
326 else
327 new_mask = curr_mask & ~event_mask;
329 /* Now everything is set and we can send stuff down to the firmware */
331 tlv = (void *)events->tlv;
333 events->action = cpu_to_le16(CMD_ACT_SET);
334 events->events = cpu_to_le16(new_mask);
335 tlv->header.type = cpu_to_le16(tlv_type);
336 tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header));
337 tlv->value = value;
338 if (tlv_type != TLV_TYPE_BCNMISS)
339 tlv->freq = freq;
341 /* The command header, the action, the event mask, and one TLV */
342 events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv));
344 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
346 if (!ret)
347 ret = count;
348 out_events:
349 kfree(events);
350 out_page:
351 free_page((unsigned long)buf);
352 return ret;
356 static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf,
357 size_t count, loff_t *ppos)
359 return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
360 file, userbuf, count, ppos);
364 static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf,
365 size_t count, loff_t *ppos)
367 return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
368 file, userbuf, count, ppos);
372 static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf,
373 size_t count, loff_t *ppos)
375 return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
376 file, userbuf, count, ppos);
380 static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf,
381 size_t count, loff_t *ppos)
383 return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
384 file, userbuf, count, ppos);
388 static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf,
389 size_t count, loff_t *ppos)
391 return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
392 file, userbuf, count, ppos);
396 static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf,
397 size_t count, loff_t *ppos)
399 return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
400 file, userbuf, count, ppos);
404 static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf,
405 size_t count, loff_t *ppos)
407 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
408 file, userbuf, count, ppos);
412 static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf,
413 size_t count, loff_t *ppos)
415 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
416 file, userbuf, count, ppos);
420 static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf,
421 size_t count, loff_t *ppos)
423 return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
424 file, userbuf, count, ppos);
428 static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf,
429 size_t count, loff_t *ppos)
431 return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
432 file, userbuf, count, ppos);
435 static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf,
436 size_t count, loff_t *ppos)
438 return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
439 file, userbuf, count, ppos);
443 static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf,
444 size_t count, loff_t *ppos)
446 return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
447 file, userbuf, count, ppos);
451 static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
452 size_t count, loff_t *ppos)
454 struct lbs_private *priv = file->private_data;
455 ssize_t pos = 0;
456 int ret;
457 unsigned long addr = get_zeroed_page(GFP_KERNEL);
458 char *buf = (char *)addr;
459 u32 val = 0;
461 if (!buf)
462 return -ENOMEM;
464 ret = lbs_get_reg(priv, CMD_MAC_REG_ACCESS, priv->mac_offset, &val);
465 mdelay(10);
466 if (!ret) {
467 pos = snprintf(buf, len, "MAC[0x%x] = 0x%08x\n",
468 priv->mac_offset, val);
469 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
471 free_page(addr);
472 return ret;
475 static ssize_t lbs_rdmac_write(struct file *file,
476 const char __user *userbuf,
477 size_t count, loff_t *ppos)
479 struct lbs_private *priv = file->private_data;
480 ssize_t res, buf_size;
481 unsigned long addr = get_zeroed_page(GFP_KERNEL);
482 char *buf = (char *)addr;
483 if (!buf)
484 return -ENOMEM;
486 buf_size = min(count, len - 1);
487 if (copy_from_user(buf, userbuf, buf_size)) {
488 res = -EFAULT;
489 goto out_unlock;
491 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
492 res = count;
493 out_unlock:
494 free_page(addr);
495 return res;
498 static ssize_t lbs_wrmac_write(struct file *file,
499 const char __user *userbuf,
500 size_t count, loff_t *ppos)
503 struct lbs_private *priv = file->private_data;
504 ssize_t res, buf_size;
505 u32 offset, value;
506 unsigned long addr = get_zeroed_page(GFP_KERNEL);
507 char *buf = (char *)addr;
508 if (!buf)
509 return -ENOMEM;
511 buf_size = min(count, len - 1);
512 if (copy_from_user(buf, userbuf, buf_size)) {
513 res = -EFAULT;
514 goto out_unlock;
516 res = sscanf(buf, "%x %x", &offset, &value);
517 if (res != 2) {
518 res = -EFAULT;
519 goto out_unlock;
522 res = lbs_set_reg(priv, CMD_MAC_REG_ACCESS, offset, value);
523 mdelay(10);
525 if (!res)
526 res = count;
527 out_unlock:
528 free_page(addr);
529 return res;
532 static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
533 size_t count, loff_t *ppos)
535 struct lbs_private *priv = file->private_data;
536 ssize_t pos = 0;
537 int ret;
538 unsigned long addr = get_zeroed_page(GFP_KERNEL);
539 char *buf = (char *)addr;
540 u32 val;
542 if (!buf)
543 return -ENOMEM;
545 ret = lbs_get_reg(priv, CMD_BBP_REG_ACCESS, priv->bbp_offset, &val);
546 mdelay(10);
547 if (!ret) {
548 pos = snprintf(buf, len, "BBP[0x%x] = 0x%08x\n",
549 priv->bbp_offset, val);
550 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
552 free_page(addr);
554 return ret;
557 static ssize_t lbs_rdbbp_write(struct file *file,
558 const char __user *userbuf,
559 size_t count, loff_t *ppos)
561 struct lbs_private *priv = file->private_data;
562 ssize_t res, buf_size;
563 unsigned long addr = get_zeroed_page(GFP_KERNEL);
564 char *buf = (char *)addr;
565 if (!buf)
566 return -ENOMEM;
568 buf_size = min(count, len - 1);
569 if (copy_from_user(buf, userbuf, buf_size)) {
570 res = -EFAULT;
571 goto out_unlock;
573 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
574 res = count;
575 out_unlock:
576 free_page(addr);
577 return res;
580 static ssize_t lbs_wrbbp_write(struct file *file,
581 const char __user *userbuf,
582 size_t count, loff_t *ppos)
585 struct lbs_private *priv = file->private_data;
586 ssize_t res, buf_size;
587 u32 offset, value;
588 unsigned long addr = get_zeroed_page(GFP_KERNEL);
589 char *buf = (char *)addr;
590 if (!buf)
591 return -ENOMEM;
593 buf_size = min(count, len - 1);
594 if (copy_from_user(buf, userbuf, buf_size)) {
595 res = -EFAULT;
596 goto out_unlock;
598 res = sscanf(buf, "%x %x", &offset, &value);
599 if (res != 2) {
600 res = -EFAULT;
601 goto out_unlock;
604 res = lbs_set_reg(priv, CMD_BBP_REG_ACCESS, offset, value);
605 mdelay(10);
607 if (!res)
608 res = count;
609 out_unlock:
610 free_page(addr);
611 return res;
614 static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
615 size_t count, loff_t *ppos)
617 struct lbs_private *priv = file->private_data;
618 ssize_t pos = 0;
619 int ret;
620 unsigned long addr = get_zeroed_page(GFP_KERNEL);
621 char *buf = (char *)addr;
622 u32 val;
624 if (!buf)
625 return -ENOMEM;
627 ret = lbs_get_reg(priv, CMD_RF_REG_ACCESS, priv->rf_offset, &val);
628 mdelay(10);
629 if (!ret) {
630 pos = snprintf(buf, len, "RF[0x%x] = 0x%08x\n",
631 priv->rf_offset, val);
632 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
634 free_page(addr);
636 return ret;
639 static ssize_t lbs_rdrf_write(struct file *file,
640 const char __user *userbuf,
641 size_t count, loff_t *ppos)
643 struct lbs_private *priv = file->private_data;
644 ssize_t res, buf_size;
645 unsigned long addr = get_zeroed_page(GFP_KERNEL);
646 char *buf = (char *)addr;
647 if (!buf)
648 return -ENOMEM;
650 buf_size = min(count, len - 1);
651 if (copy_from_user(buf, userbuf, buf_size)) {
652 res = -EFAULT;
653 goto out_unlock;
655 priv->rf_offset = simple_strtoul(buf, NULL, 16);
656 res = count;
657 out_unlock:
658 free_page(addr);
659 return res;
662 static ssize_t lbs_wrrf_write(struct file *file,
663 const char __user *userbuf,
664 size_t count, loff_t *ppos)
667 struct lbs_private *priv = file->private_data;
668 ssize_t res, buf_size;
669 u32 offset, value;
670 unsigned long addr = get_zeroed_page(GFP_KERNEL);
671 char *buf = (char *)addr;
672 if (!buf)
673 return -ENOMEM;
675 buf_size = min(count, len - 1);
676 if (copy_from_user(buf, userbuf, buf_size)) {
677 res = -EFAULT;
678 goto out_unlock;
680 res = sscanf(buf, "%x %x", &offset, &value);
681 if (res != 2) {
682 res = -EFAULT;
683 goto out_unlock;
686 res = lbs_set_reg(priv, CMD_RF_REG_ACCESS, offset, value);
687 mdelay(10);
689 if (!res)
690 res = count;
691 out_unlock:
692 free_page(addr);
693 return res;
696 #define FOPS(fread, fwrite) { \
697 .owner = THIS_MODULE, \
698 .open = open_file_generic, \
699 .read = (fread), \
700 .write = (fwrite), \
701 .llseek = generic_file_llseek, \
704 struct lbs_debugfs_files {
705 const char *name;
706 int perm;
707 struct file_operations fops;
710 static const struct lbs_debugfs_files debugfs_files[] = {
711 { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
712 { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
713 lbs_sleepparams_write), },
714 { "hostsleep", 0644, FOPS(lbs_host_sleep_read,
715 lbs_host_sleep_write), },
718 static const struct lbs_debugfs_files debugfs_events_files[] = {
719 {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
720 lbs_lowrssi_write), },
721 {"low_snr", 0644, FOPS(lbs_lowsnr_read,
722 lbs_lowsnr_write), },
723 {"failure_count", 0644, FOPS(lbs_failcount_read,
724 lbs_failcount_write), },
725 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
726 lbs_bcnmiss_write), },
727 {"high_rssi", 0644, FOPS(lbs_highrssi_read,
728 lbs_highrssi_write), },
729 {"high_snr", 0644, FOPS(lbs_highsnr_read,
730 lbs_highsnr_write), },
733 static const struct lbs_debugfs_files debugfs_regs_files[] = {
734 {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
735 {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
736 {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
737 {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
738 {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
739 {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
742 void lbs_debugfs_init(void)
744 if (!lbs_dir)
745 lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
748 void lbs_debugfs_remove(void)
750 if (lbs_dir)
751 debugfs_remove(lbs_dir);
754 void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
756 int i;
757 const struct lbs_debugfs_files *files;
758 if (!lbs_dir)
759 goto exit;
761 priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
762 if (!priv->debugfs_dir)
763 goto exit;
765 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
766 files = &debugfs_files[i];
767 priv->debugfs_files[i] = debugfs_create_file(files->name,
768 files->perm,
769 priv->debugfs_dir,
770 priv,
771 &files->fops);
774 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
775 if (!priv->events_dir)
776 goto exit;
778 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
779 files = &debugfs_events_files[i];
780 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
781 files->perm,
782 priv->events_dir,
783 priv,
784 &files->fops);
787 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
788 if (!priv->regs_dir)
789 goto exit;
791 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
792 files = &debugfs_regs_files[i];
793 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
794 files->perm,
795 priv->regs_dir,
796 priv,
797 &files->fops);
800 #ifdef PROC_DEBUG
801 lbs_debug_init(priv);
802 #endif
803 exit:
804 return;
807 void lbs_debugfs_remove_one(struct lbs_private *priv)
809 int i;
811 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
812 debugfs_remove(priv->debugfs_regs_files[i]);
814 debugfs_remove(priv->regs_dir);
816 for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
817 debugfs_remove(priv->debugfs_events_files[i]);
819 debugfs_remove(priv->events_dir);
820 #ifdef PROC_DEBUG
821 debugfs_remove(priv->debugfs_debug);
822 #endif
823 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
824 debugfs_remove(priv->debugfs_files[i]);
825 debugfs_remove(priv->debugfs_dir);
830 /* debug entry */
832 #ifdef PROC_DEBUG
834 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
835 #define item_addr(n) (offsetof(struct lbs_private, n))
838 struct debug_data {
839 char name[32];
840 u32 size;
841 size_t addr;
844 /* To debug any member of struct lbs_private, simply add one line here.
846 static struct debug_data items[] = {
847 {"psmode", item_size(psmode), item_addr(psmode)},
848 {"psstate", item_size(psstate), item_addr(psstate)},
851 static int num_of_items = ARRAY_SIZE(items);
854 * lbs_debugfs_read - proc read function
856 * @file: file to read
857 * @userbuf: pointer to buffer
858 * @count: number of bytes to read
859 * @ppos: read data starting position
861 * returns: amount of data read or negative error code
863 static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
864 size_t count, loff_t *ppos)
866 int val = 0;
867 size_t pos = 0;
868 ssize_t res;
869 char *p;
870 int i;
871 struct debug_data *d;
872 unsigned long addr = get_zeroed_page(GFP_KERNEL);
873 char *buf = (char *)addr;
874 if (!buf)
875 return -ENOMEM;
877 p = buf;
879 d = file->private_data;
881 for (i = 0; i < num_of_items; i++) {
882 if (d[i].size == 1)
883 val = *((u8 *) d[i].addr);
884 else if (d[i].size == 2)
885 val = *((u16 *) d[i].addr);
886 else if (d[i].size == 4)
887 val = *((u32 *) d[i].addr);
888 else if (d[i].size == 8)
889 val = *((u64 *) d[i].addr);
891 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
894 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
896 free_page(addr);
897 return res;
901 * lbs_debugfs_write - proc write function
903 * @f: file pointer
904 * @buf: pointer to data buffer
905 * @cnt: data number to write
906 * @ppos: file position
908 * returns: amount of data written
910 static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
911 size_t cnt, loff_t *ppos)
913 int r, i;
914 char *pdata;
915 char *p;
916 char *p0;
917 char *p1;
918 char *p2;
919 struct debug_data *d = f->private_data;
921 pdata = kmalloc(cnt, GFP_KERNEL);
922 if (pdata == NULL)
923 return 0;
925 if (copy_from_user(pdata, buf, cnt)) {
926 lbs_deb_debugfs("Copy from user failed\n");
927 kfree(pdata);
928 return 0;
931 p0 = pdata;
932 for (i = 0; i < num_of_items; i++) {
933 do {
934 p = strstr(p0, d[i].name);
935 if (p == NULL)
936 break;
937 p1 = strchr(p, '\n');
938 if (p1 == NULL)
939 break;
940 p0 = p1++;
941 p2 = strchr(p, '=');
942 if (!p2)
943 break;
944 p2++;
945 r = simple_strtoul(p2, NULL, 0);
946 if (d[i].size == 1)
947 *((u8 *) d[i].addr) = (u8) r;
948 else if (d[i].size == 2)
949 *((u16 *) d[i].addr) = (u16) r;
950 else if (d[i].size == 4)
951 *((u32 *) d[i].addr) = (u32) r;
952 else if (d[i].size == 8)
953 *((u64 *) d[i].addr) = (u64) r;
954 break;
955 } while (1);
957 kfree(pdata);
959 return (ssize_t)cnt;
962 static const struct file_operations lbs_debug_fops = {
963 .owner = THIS_MODULE,
964 .open = open_file_generic,
965 .write = lbs_debugfs_write,
966 .read = lbs_debugfs_read,
967 .llseek = default_llseek,
971 * lbs_debug_init - create debug proc file
973 * @priv: pointer to &struct lbs_private
975 * returns: N/A
977 static void lbs_debug_init(struct lbs_private *priv)
979 int i;
981 if (!priv->debugfs_dir)
982 return;
984 for (i = 0; i < num_of_items; i++)
985 items[i].addr += (size_t) priv;
987 priv->debugfs_debug = debugfs_create_file("debug", 0644,
988 priv->debugfs_dir, &items[0],
989 &lbs_debug_fops);
991 #endif