Linux 2.6.26-rc5
[linux-2.6/openmoko-kernel/knife-kernel.git] / drivers / net / wireless / libertas / debugfs.c
blob0aa0ce3b2c425206262997ef1eacb163cb66c977
1 #include <linux/module.h>
2 #include <linux/dcache.h>
3 #include <linux/debugfs.h>
4 #include <linux/delay.h>
5 #include <linux/mm.h>
6 #include <linux/string.h>
7 #include <net/iw_handler.h>
9 #include "dev.h"
10 #include "decl.h"
11 #include "host.h"
12 #include "debugfs.h"
13 #include "cmd.h"
15 static struct dentry *lbs_dir;
16 static char *szStates[] = {
17 "Connected",
18 "Disconnected"
21 #ifdef PROC_DEBUG
22 static void lbs_debug_init(struct lbs_private *priv);
23 #endif
25 static int open_file_generic(struct inode *inode, struct file *file)
27 file->private_data = inode->i_private;
28 return 0;
31 static ssize_t write_file_dummy(struct file *file, const char __user *buf,
32 size_t count, loff_t *ppos)
34 return -EINVAL;
37 static const size_t len = PAGE_SIZE;
39 static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
40 size_t count, loff_t *ppos)
42 struct lbs_private *priv = file->private_data;
43 size_t pos = 0;
44 unsigned long addr = get_zeroed_page(GFP_KERNEL);
45 char *buf = (char *)addr;
46 ssize_t res;
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;
60 static ssize_t lbs_getscantable(struct file *file, char __user *userbuf,
61 size_t count, loff_t *ppos)
63 struct lbs_private *priv = file->private_data;
64 size_t pos = 0;
65 int numscansdone = 0, res;
66 unsigned long addr = get_zeroed_page(GFP_KERNEL);
67 char *buf = (char *)addr;
68 DECLARE_MAC_BUF(mac);
69 struct bss_descriptor * iter_bss;
71 pos += snprintf(buf+pos, len-pos,
72 "# | ch | rssi | bssid | cap | Qual | SSID \n");
74 mutex_lock(&priv->lock);
75 list_for_each_entry (iter_bss, &priv->network_list, list) {
76 u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS);
77 u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY);
78 u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT);
80 pos += snprintf(buf+pos, len-pos,
81 "%02u| %03d | %04d | %s |",
82 numscansdone, iter_bss->channel, iter_bss->rssi,
83 print_mac(mac, iter_bss->bssid));
84 pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability);
85 pos += snprintf(buf+pos, len-pos, "%c%c%c |",
86 ibss ? 'A' : 'I', privacy ? 'P' : ' ',
87 spectrum_mgmt ? 'S' : ' ');
88 pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi));
89 pos += snprintf(buf+pos, len-pos, " %s\n",
90 escape_essid(iter_bss->ssid, iter_bss->ssid_len));
92 numscansdone++;
94 mutex_unlock(&priv->lock);
96 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
98 free_page(addr);
99 return res;
102 static ssize_t lbs_sleepparams_write(struct file *file,
103 const char __user *user_buf, size_t count,
104 loff_t *ppos)
106 struct lbs_private *priv = file->private_data;
107 ssize_t buf_size, ret;
108 struct sleep_params sp;
109 int p1, p2, p3, p4, p5, p6;
110 unsigned long addr = get_zeroed_page(GFP_KERNEL);
111 char *buf = (char *)addr;
113 buf_size = min(count, len - 1);
114 if (copy_from_user(buf, user_buf, buf_size)) {
115 ret = -EFAULT;
116 goto out_unlock;
118 ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
119 if (ret != 6) {
120 ret = -EINVAL;
121 goto out_unlock;
123 sp.sp_error = p1;
124 sp.sp_offset = p2;
125 sp.sp_stabletime = p3;
126 sp.sp_calcontrol = p4;
127 sp.sp_extsleepclk = p5;
128 sp.sp_reserved = p6;
130 ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp);
131 if (!ret)
132 ret = count;
133 else if (ret > 0)
134 ret = -EINVAL;
136 out_unlock:
137 free_page(addr);
138 return ret;
141 static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
142 size_t count, loff_t *ppos)
144 struct lbs_private *priv = file->private_data;
145 ssize_t ret;
146 size_t pos = 0;
147 struct sleep_params sp;
148 unsigned long addr = get_zeroed_page(GFP_KERNEL);
149 char *buf = (char *)addr;
151 ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp);
152 if (ret)
153 goto out_unlock;
155 pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error,
156 sp.sp_offset, sp.sp_stabletime,
157 sp.sp_calcontrol, sp.sp_extsleepclk,
158 sp.sp_reserved);
160 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
162 out_unlock:
163 free_page(addr);
164 return ret;
168 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
169 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
170 * firmware. Here's an example:
171 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
172 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
173 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
175 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
176 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
177 * defined in mrvlietypes_thresholds
179 * This function searches in this TLV data chunk for a given TLV type
180 * and returns a pointer to the first data byte of the TLV, or to NULL
181 * if the TLV hasn't been found.
183 static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size)
185 struct mrvlietypesheader *tlv_h;
186 uint16_t length;
187 ssize_t pos = 0;
189 while (pos < size) {
190 tlv_h = (struct mrvlietypesheader *) tlv;
191 if (!tlv_h->len)
192 return NULL;
193 if (tlv_h->type == cpu_to_le16(tlv_type))
194 return tlv_h;
195 length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h);
196 pos += length;
197 tlv += length;
199 return NULL;
203 static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask,
204 struct file *file, char __user *userbuf,
205 size_t count, loff_t *ppos)
207 struct cmd_ds_802_11_subscribe_event *subscribed;
208 struct mrvlietypes_thresholds *got;
209 struct lbs_private *priv = file->private_data;
210 ssize_t ret = 0;
211 size_t pos = 0;
212 char *buf;
213 u8 value;
214 u8 freq;
215 int events = 0;
217 buf = (char *)get_zeroed_page(GFP_KERNEL);
218 if (!buf)
219 return -ENOMEM;
221 subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL);
222 if (!subscribed) {
223 ret = -ENOMEM;
224 goto out_page;
227 subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed));
228 subscribed->action = cpu_to_le16(CMD_ACT_GET);
230 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed);
231 if (ret)
232 goto out_cmd;
234 got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
235 if (got) {
236 value = got->value;
237 freq = got->freq;
238 events = le16_to_cpu(subscribed->events);
240 pos += snprintf(buf, len, "%d %d %d\n", value, freq,
241 !!(events & event_mask));
244 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
246 out_cmd:
247 kfree(subscribed);
249 out_page:
250 free_page((unsigned long)buf);
251 return ret;
255 static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask,
256 struct file *file,
257 const char __user *userbuf, size_t count,
258 loff_t *ppos)
260 struct cmd_ds_802_11_subscribe_event *events;
261 struct mrvlietypes_thresholds *tlv;
262 struct lbs_private *priv = file->private_data;
263 ssize_t buf_size;
264 int value, freq, new_mask;
265 uint16_t curr_mask;
266 char *buf;
267 int ret;
269 buf = (char *)get_zeroed_page(GFP_KERNEL);
270 if (!buf)
271 return -ENOMEM;
273 buf_size = min(count, len - 1);
274 if (copy_from_user(buf, userbuf, buf_size)) {
275 ret = -EFAULT;
276 goto out_page;
278 ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
279 if (ret != 3) {
280 ret = -EINVAL;
281 goto out_page;
283 events = kzalloc(sizeof(*events), GFP_KERNEL);
284 if (!events) {
285 ret = -ENOMEM;
286 goto out_page;
289 events->hdr.size = cpu_to_le16(sizeof(*events));
290 events->action = cpu_to_le16(CMD_ACT_GET);
292 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
293 if (ret)
294 goto out_events;
296 curr_mask = le16_to_cpu(events->events);
298 if (new_mask)
299 new_mask = curr_mask | event_mask;
300 else
301 new_mask = curr_mask & ~event_mask;
303 /* Now everything is set and we can send stuff down to the firmware */
305 tlv = (void *)events->tlv;
307 events->action = cpu_to_le16(CMD_ACT_SET);
308 events->events = cpu_to_le16(new_mask);
309 tlv->header.type = cpu_to_le16(tlv_type);
310 tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header));
311 tlv->value = value;
312 if (tlv_type != TLV_TYPE_BCNMISS)
313 tlv->freq = freq;
315 /* The command header, the action, the event mask, and one TLV */
316 events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv));
318 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
320 if (!ret)
321 ret = count;
322 out_events:
323 kfree(events);
324 out_page:
325 free_page((unsigned long)buf);
326 return ret;
330 static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf,
331 size_t count, loff_t *ppos)
333 return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
334 file, userbuf, count, ppos);
338 static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf,
339 size_t count, loff_t *ppos)
341 return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
342 file, userbuf, count, ppos);
346 static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf,
347 size_t count, loff_t *ppos)
349 return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
350 file, userbuf, count, ppos);
354 static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf,
355 size_t count, loff_t *ppos)
357 return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
358 file, userbuf, count, ppos);
362 static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf,
363 size_t count, loff_t *ppos)
365 return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
366 file, userbuf, count, ppos);
370 static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf,
371 size_t count, loff_t *ppos)
373 return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
374 file, userbuf, count, ppos);
378 static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf,
379 size_t count, loff_t *ppos)
381 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
382 file, userbuf, count, ppos);
386 static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf,
387 size_t count, loff_t *ppos)
389 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
390 file, userbuf, count, ppos);
394 static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf,
395 size_t count, loff_t *ppos)
397 return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
398 file, userbuf, count, ppos);
402 static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf,
403 size_t count, loff_t *ppos)
405 return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
406 file, userbuf, count, ppos);
409 static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf,
410 size_t count, loff_t *ppos)
412 return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
413 file, userbuf, count, ppos);
417 static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf,
418 size_t count, loff_t *ppos)
420 return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
421 file, userbuf, count, ppos);
426 static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
427 size_t count, loff_t *ppos)
429 struct lbs_private *priv = file->private_data;
430 struct lbs_offset_value offval;
431 ssize_t pos = 0;
432 int ret;
433 unsigned long addr = get_zeroed_page(GFP_KERNEL);
434 char *buf = (char *)addr;
436 offval.offset = priv->mac_offset;
437 offval.value = 0;
439 ret = lbs_prepare_and_send_command(priv,
440 CMD_MAC_REG_ACCESS, 0,
441 CMD_OPTION_WAITFORRSP, 0, &offval);
442 mdelay(10);
443 pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
444 priv->mac_offset, priv->offsetvalue.value);
446 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
447 free_page(addr);
448 return ret;
451 static ssize_t lbs_rdmac_write(struct file *file,
452 const char __user *userbuf,
453 size_t count, loff_t *ppos)
455 struct lbs_private *priv = file->private_data;
456 ssize_t res, buf_size;
457 unsigned long addr = get_zeroed_page(GFP_KERNEL);
458 char *buf = (char *)addr;
460 buf_size = min(count, len - 1);
461 if (copy_from_user(buf, userbuf, buf_size)) {
462 res = -EFAULT;
463 goto out_unlock;
465 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
466 res = count;
467 out_unlock:
468 free_page(addr);
469 return res;
472 static ssize_t lbs_wrmac_write(struct file *file,
473 const char __user *userbuf,
474 size_t count, loff_t *ppos)
477 struct lbs_private *priv = file->private_data;
478 ssize_t res, buf_size;
479 u32 offset, value;
480 struct lbs_offset_value offval;
481 unsigned long addr = get_zeroed_page(GFP_KERNEL);
482 char *buf = (char *)addr;
484 buf_size = min(count, len - 1);
485 if (copy_from_user(buf, userbuf, buf_size)) {
486 res = -EFAULT;
487 goto out_unlock;
489 res = sscanf(buf, "%x %x", &offset, &value);
490 if (res != 2) {
491 res = -EFAULT;
492 goto out_unlock;
495 offval.offset = offset;
496 offval.value = value;
497 res = lbs_prepare_and_send_command(priv,
498 CMD_MAC_REG_ACCESS, 1,
499 CMD_OPTION_WAITFORRSP, 0, &offval);
500 mdelay(10);
502 res = count;
503 out_unlock:
504 free_page(addr);
505 return res;
508 static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
509 size_t count, loff_t *ppos)
511 struct lbs_private *priv = file->private_data;
512 struct lbs_offset_value offval;
513 ssize_t pos = 0;
514 int ret;
515 unsigned long addr = get_zeroed_page(GFP_KERNEL);
516 char *buf = (char *)addr;
518 offval.offset = priv->bbp_offset;
519 offval.value = 0;
521 ret = lbs_prepare_and_send_command(priv,
522 CMD_BBP_REG_ACCESS, 0,
523 CMD_OPTION_WAITFORRSP, 0, &offval);
524 mdelay(10);
525 pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
526 priv->bbp_offset, priv->offsetvalue.value);
528 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
529 free_page(addr);
531 return ret;
534 static ssize_t lbs_rdbbp_write(struct file *file,
535 const char __user *userbuf,
536 size_t count, loff_t *ppos)
538 struct lbs_private *priv = file->private_data;
539 ssize_t res, buf_size;
540 unsigned long addr = get_zeroed_page(GFP_KERNEL);
541 char *buf = (char *)addr;
543 buf_size = min(count, len - 1);
544 if (copy_from_user(buf, userbuf, buf_size)) {
545 res = -EFAULT;
546 goto out_unlock;
548 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
549 res = count;
550 out_unlock:
551 free_page(addr);
552 return res;
555 static ssize_t lbs_wrbbp_write(struct file *file,
556 const char __user *userbuf,
557 size_t count, loff_t *ppos)
560 struct lbs_private *priv = file->private_data;
561 ssize_t res, buf_size;
562 u32 offset, value;
563 struct lbs_offset_value offval;
564 unsigned long addr = get_zeroed_page(GFP_KERNEL);
565 char *buf = (char *)addr;
567 buf_size = min(count, len - 1);
568 if (copy_from_user(buf, userbuf, buf_size)) {
569 res = -EFAULT;
570 goto out_unlock;
572 res = sscanf(buf, "%x %x", &offset, &value);
573 if (res != 2) {
574 res = -EFAULT;
575 goto out_unlock;
578 offval.offset = offset;
579 offval.value = value;
580 res = lbs_prepare_and_send_command(priv,
581 CMD_BBP_REG_ACCESS, 1,
582 CMD_OPTION_WAITFORRSP, 0, &offval);
583 mdelay(10);
585 res = count;
586 out_unlock:
587 free_page(addr);
588 return res;
591 static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
592 size_t count, loff_t *ppos)
594 struct lbs_private *priv = file->private_data;
595 struct lbs_offset_value offval;
596 ssize_t pos = 0;
597 int ret;
598 unsigned long addr = get_zeroed_page(GFP_KERNEL);
599 char *buf = (char *)addr;
601 offval.offset = priv->rf_offset;
602 offval.value = 0;
604 ret = lbs_prepare_and_send_command(priv,
605 CMD_RF_REG_ACCESS, 0,
606 CMD_OPTION_WAITFORRSP, 0, &offval);
607 mdelay(10);
608 pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
609 priv->rf_offset, priv->offsetvalue.value);
611 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
612 free_page(addr);
614 return ret;
617 static ssize_t lbs_rdrf_write(struct file *file,
618 const char __user *userbuf,
619 size_t count, loff_t *ppos)
621 struct lbs_private *priv = file->private_data;
622 ssize_t res, buf_size;
623 unsigned long addr = get_zeroed_page(GFP_KERNEL);
624 char *buf = (char *)addr;
626 buf_size = min(count, len - 1);
627 if (copy_from_user(buf, userbuf, buf_size)) {
628 res = -EFAULT;
629 goto out_unlock;
631 priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
632 res = count;
633 out_unlock:
634 free_page(addr);
635 return res;
638 static ssize_t lbs_wrrf_write(struct file *file,
639 const char __user *userbuf,
640 size_t count, loff_t *ppos)
643 struct lbs_private *priv = file->private_data;
644 ssize_t res, buf_size;
645 u32 offset, value;
646 struct lbs_offset_value offval;
647 unsigned long addr = get_zeroed_page(GFP_KERNEL);
648 char *buf = (char *)addr;
650 buf_size = min(count, len - 1);
651 if (copy_from_user(buf, userbuf, buf_size)) {
652 res = -EFAULT;
653 goto out_unlock;
655 res = sscanf(buf, "%x %x", &offset, &value);
656 if (res != 2) {
657 res = -EFAULT;
658 goto out_unlock;
661 offval.offset = offset;
662 offval.value = value;
663 res = lbs_prepare_and_send_command(priv,
664 CMD_RF_REG_ACCESS, 1,
665 CMD_OPTION_WAITFORRSP, 0, &offval);
666 mdelay(10);
668 res = count;
669 out_unlock:
670 free_page(addr);
671 return res;
674 #define FOPS(fread, fwrite) { \
675 .owner = THIS_MODULE, \
676 .open = open_file_generic, \
677 .read = (fread), \
678 .write = (fwrite), \
681 struct lbs_debugfs_files {
682 char *name;
683 int perm;
684 struct file_operations fops;
687 static struct lbs_debugfs_files debugfs_files[] = {
688 { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
689 { "getscantable", 0444, FOPS(lbs_getscantable,
690 write_file_dummy), },
691 { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
692 lbs_sleepparams_write), },
695 static struct lbs_debugfs_files debugfs_events_files[] = {
696 {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
697 lbs_lowrssi_write), },
698 {"low_snr", 0644, FOPS(lbs_lowsnr_read,
699 lbs_lowsnr_write), },
700 {"failure_count", 0644, FOPS(lbs_failcount_read,
701 lbs_failcount_write), },
702 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
703 lbs_bcnmiss_write), },
704 {"high_rssi", 0644, FOPS(lbs_highrssi_read,
705 lbs_highrssi_write), },
706 {"high_snr", 0644, FOPS(lbs_highsnr_read,
707 lbs_highsnr_write), },
710 static struct lbs_debugfs_files debugfs_regs_files[] = {
711 {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
712 {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
713 {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
714 {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
715 {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
716 {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
719 void lbs_debugfs_init(void)
721 if (!lbs_dir)
722 lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
724 return;
727 void lbs_debugfs_remove(void)
729 if (lbs_dir)
730 debugfs_remove(lbs_dir);
731 return;
734 void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
736 int i;
737 struct lbs_debugfs_files *files;
738 if (!lbs_dir)
739 goto exit;
741 priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
742 if (!priv->debugfs_dir)
743 goto exit;
745 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
746 files = &debugfs_files[i];
747 priv->debugfs_files[i] = debugfs_create_file(files->name,
748 files->perm,
749 priv->debugfs_dir,
750 priv,
751 &files->fops);
754 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
755 if (!priv->events_dir)
756 goto exit;
758 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
759 files = &debugfs_events_files[i];
760 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
761 files->perm,
762 priv->events_dir,
763 priv,
764 &files->fops);
767 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
768 if (!priv->regs_dir)
769 goto exit;
771 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
772 files = &debugfs_regs_files[i];
773 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
774 files->perm,
775 priv->regs_dir,
776 priv,
777 &files->fops);
780 #ifdef PROC_DEBUG
781 lbs_debug_init(priv);
782 #endif
783 exit:
784 return;
787 void lbs_debugfs_remove_one(struct lbs_private *priv)
789 int i;
791 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
792 debugfs_remove(priv->debugfs_regs_files[i]);
794 debugfs_remove(priv->regs_dir);
796 for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
797 debugfs_remove(priv->debugfs_events_files[i]);
799 debugfs_remove(priv->events_dir);
800 #ifdef PROC_DEBUG
801 debugfs_remove(priv->debugfs_debug);
802 #endif
803 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
804 debugfs_remove(priv->debugfs_files[i]);
805 debugfs_remove(priv->debugfs_dir);
810 /* debug entry */
812 #ifdef PROC_DEBUG
814 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
815 #define item_addr(n) (offsetof(struct lbs_private, n))
818 struct debug_data {
819 char name[32];
820 u32 size;
821 size_t addr;
824 /* To debug any member of struct lbs_private, simply add one line here.
826 static struct debug_data items[] = {
827 {"psmode", item_size(psmode), item_addr(psmode)},
828 {"psstate", item_size(psstate), item_addr(psstate)},
831 static int num_of_items = ARRAY_SIZE(items);
834 * @brief proc read function
836 * @param page pointer to buffer
837 * @param s read data starting position
838 * @param off offset
839 * @param cnt counter
840 * @param eof end of file flag
841 * @param data data to output
842 * @return number of output data
844 static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
845 size_t count, loff_t *ppos)
847 int val = 0;
848 size_t pos = 0;
849 ssize_t res;
850 char *p;
851 int i;
852 struct debug_data *d;
853 unsigned long addr = get_zeroed_page(GFP_KERNEL);
854 char *buf = (char *)addr;
856 p = buf;
858 d = (struct debug_data *)file->private_data;
860 for (i = 0; i < num_of_items; i++) {
861 if (d[i].size == 1)
862 val = *((u8 *) d[i].addr);
863 else if (d[i].size == 2)
864 val = *((u16 *) d[i].addr);
865 else if (d[i].size == 4)
866 val = *((u32 *) d[i].addr);
867 else if (d[i].size == 8)
868 val = *((u64 *) d[i].addr);
870 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
873 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
875 free_page(addr);
876 return res;
880 * @brief proc write function
882 * @param f file pointer
883 * @param buf pointer to data buffer
884 * @param cnt data number to write
885 * @param data data to write
886 * @return number of data
888 static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
889 size_t cnt, loff_t *ppos)
891 int r, i;
892 char *pdata;
893 char *p;
894 char *p0;
895 char *p1;
896 char *p2;
897 struct debug_data *d = (struct debug_data *)f->private_data;
899 pdata = kmalloc(cnt, GFP_KERNEL);
900 if (pdata == NULL)
901 return 0;
903 if (copy_from_user(pdata, buf, cnt)) {
904 lbs_deb_debugfs("Copy from user failed\n");
905 kfree(pdata);
906 return 0;
909 p0 = pdata;
910 for (i = 0; i < num_of_items; i++) {
911 do {
912 p = strstr(p0, d[i].name);
913 if (p == NULL)
914 break;
915 p1 = strchr(p, '\n');
916 if (p1 == NULL)
917 break;
918 p0 = p1++;
919 p2 = strchr(p, '=');
920 if (!p2)
921 break;
922 p2++;
923 r = simple_strtoul(p2, NULL, 0);
924 if (d[i].size == 1)
925 *((u8 *) d[i].addr) = (u8) r;
926 else if (d[i].size == 2)
927 *((u16 *) d[i].addr) = (u16) r;
928 else if (d[i].size == 4)
929 *((u32 *) d[i].addr) = (u32) r;
930 else if (d[i].size == 8)
931 *((u64 *) d[i].addr) = (u64) r;
932 break;
933 } while (1);
935 kfree(pdata);
937 return (ssize_t)cnt;
940 static struct file_operations lbs_debug_fops = {
941 .owner = THIS_MODULE,
942 .open = open_file_generic,
943 .write = lbs_debugfs_write,
944 .read = lbs_debugfs_read,
948 * @brief create debug proc file
950 * @param priv pointer struct lbs_private
951 * @param dev pointer net_device
952 * @return N/A
954 static void lbs_debug_init(struct lbs_private *priv)
956 int i;
958 if (!priv->debugfs_dir)
959 return;
961 for (i = 0; i < num_of_items; i++)
962 items[i].addr += (size_t) priv;
964 priv->debugfs_debug = debugfs_create_file("debug", 0644,
965 priv->debugfs_dir, &items[0],
966 &lbs_debug_fops);
968 #endif