1 #include <linux/module.h>
2 #include <linux/dcache.h>
3 #include <linux/debugfs.h>
4 #include <linux/delay.h>
6 #include <linux/string.h>
7 #include <net/iw_handler.h>
14 static struct dentry *lbs_dir;
15 static char *szStates[] = {
21 static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev);
24 static int open_file_generic(struct inode *inode, struct file *file)
26 file->private_data = inode->i_private;
30 static ssize_t write_file_dummy(struct file *file, const char __user *buf,
31 size_t count, loff_t *ppos)
36 static const size_t len = PAGE_SIZE;
38 static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
39 size_t count, loff_t *ppos)
41 struct lbs_private *priv = file->private_data;
43 unsigned long addr = get_zeroed_page(GFP_KERNEL);
44 char *buf = (char *)addr;
47 pos += snprintf(buf+pos, len-pos, "state = %s\n",
48 szStates[priv->connect_status]);
49 pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
50 (u32) priv->regioncode);
52 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
59 static ssize_t lbs_getscantable(struct file *file, char __user *userbuf,
60 size_t count, loff_t *ppos)
62 struct lbs_private *priv = file->private_data;
64 int numscansdone = 0, res;
65 unsigned long addr = get_zeroed_page(GFP_KERNEL);
66 char *buf = (char *)addr;
68 struct bss_descriptor * iter_bss;
70 pos += snprintf(buf+pos, len-pos,
71 "# | ch | rssi | bssid | cap | Qual | SSID \n");
73 mutex_lock(&priv->lock);
74 list_for_each_entry (iter_bss, &priv->network_list, list) {
75 u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS);
76 u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY);
77 u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT);
79 pos += snprintf(buf+pos, len-pos,
80 "%02u| %03d | %04ld | %s |",
81 numscansdone, iter_bss->channel, iter_bss->rssi,
82 print_mac(mac, iter_bss->bssid));
83 pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability);
84 pos += snprintf(buf+pos, len-pos, "%c%c%c |",
85 ibss ? 'A' : 'I', privacy ? 'P' : ' ',
86 spectrum_mgmt ? 'S' : ' ');
87 pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi));
88 pos += snprintf(buf+pos, len-pos, " %s\n",
89 escape_essid(iter_bss->ssid, iter_bss->ssid_len));
93 mutex_unlock(&priv->lock);
95 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
101 static ssize_t lbs_sleepparams_write(struct file *file,
102 const char __user *user_buf, size_t count,
105 struct lbs_private *priv = file->private_data;
106 ssize_t buf_size, res;
107 int p1, p2, p3, p4, p5, p6;
108 unsigned long addr = get_zeroed_page(GFP_KERNEL);
109 char *buf = (char *)addr;
111 buf_size = min(count, len - 1);
112 if (copy_from_user(buf, user_buf, buf_size)) {
116 res = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
121 priv->sp.sp_error = p1;
122 priv->sp.sp_offset = p2;
123 priv->sp.sp_stabletime = p3;
124 priv->sp.sp_calcontrol = p4;
125 priv->sp.sp_extsleepclk = p5;
126 priv->sp.sp_reserved = p6;
128 res = lbs_prepare_and_send_command(priv,
129 CMD_802_11_SLEEP_PARAMS,
131 CMD_OPTION_WAITFORRSP, 0, NULL);
143 static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
144 size_t count, loff_t *ppos)
146 struct lbs_private *priv = file->private_data;
149 unsigned long addr = get_zeroed_page(GFP_KERNEL);
150 char *buf = (char *)addr;
152 res = lbs_prepare_and_send_command(priv,
153 CMD_802_11_SLEEP_PARAMS,
155 CMD_OPTION_WAITFORRSP, 0, NULL);
161 pos += snprintf(buf, len, "%d %d %d %d %d %d\n", priv->sp.sp_error,
162 priv->sp.sp_offset, priv->sp.sp_stabletime,
163 priv->sp.sp_calcontrol, priv->sp.sp_extsleepclk,
164 priv->sp.sp_reserved);
166 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
173 static ssize_t lbs_extscan(struct file *file, const char __user *userbuf,
174 size_t count, loff_t *ppos)
176 struct lbs_private *priv = file->private_data;
177 ssize_t res, buf_size;
178 union iwreq_data wrqu;
179 unsigned long addr = get_zeroed_page(GFP_KERNEL);
180 char *buf = (char *)addr;
182 buf_size = min(count, len - 1);
183 if (copy_from_user(buf, userbuf, buf_size)) {
188 lbs_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0);
190 memset(&wrqu, 0, sizeof(union iwreq_data));
191 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
198 static void lbs_parse_bssid(char *buf, size_t count,
199 struct lbs_ioctl_user_scan_cfg *scan_cfg)
202 unsigned int mac[ETH_ALEN];
204 hold = strstr(buf, "bssid=");
208 sscanf(hold, "%02x:%02x:%02x:%02x:%02x:%02x",
209 mac, mac+1, mac+2, mac+3, mac+4, mac+5);
210 memcpy(scan_cfg->bssid, mac, ETH_ALEN);
213 static void lbs_parse_ssid(char *buf, size_t count,
214 struct lbs_ioctl_user_scan_cfg *scan_cfg)
219 hold = strstr(buf, "ssid=");
223 end = strchr(hold, ' ');
225 end = buf + count - 1;
227 size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
228 strncpy(scan_cfg->ssid, hold, size);
233 static int lbs_parse_clear(char *buf, size_t count, const char *tag)
238 hold = strstr(buf, tag);
242 sscanf(hold, "%d", &val);
250 static int lbs_parse_dur(char *buf, size_t count,
251 struct lbs_ioctl_user_scan_cfg *scan_cfg)
256 hold = strstr(buf, "dur=");
260 sscanf(hold, "%d", &val);
265 static void lbs_parse_type(char *buf, size_t count,
266 struct lbs_ioctl_user_scan_cfg *scan_cfg)
271 hold = strstr(buf, "type=");
275 sscanf(hold, "%d", &val);
278 if (val < 1 || val > 3)
281 scan_cfg->bsstype = val;
286 static ssize_t lbs_setuserscan(struct file *file,
287 const char __user *userbuf,
288 size_t count, loff_t *ppos)
290 struct lbs_private *priv = file->private_data;
291 ssize_t res, buf_size;
292 struct lbs_ioctl_user_scan_cfg *scan_cfg;
293 union iwreq_data wrqu;
295 char *buf = (char *)get_zeroed_page(GFP_KERNEL);
300 buf_size = min(count, len - 1);
301 if (copy_from_user(buf, userbuf, buf_size)) {
306 scan_cfg = kzalloc(sizeof(struct lbs_ioctl_user_scan_cfg), GFP_KERNEL);
313 scan_cfg->bsstype = LBS_SCAN_BSS_TYPE_ANY;
315 dur = lbs_parse_dur(buf, count, scan_cfg);
316 lbs_parse_bssid(buf, count, scan_cfg);
317 scan_cfg->clear_bssid = lbs_parse_clear(buf, count, "clear_bssid=");
318 lbs_parse_ssid(buf, count, scan_cfg);
319 scan_cfg->clear_ssid = lbs_parse_clear(buf, count, "clear_ssid=");
320 lbs_parse_type(buf, count, scan_cfg);
322 lbs_scan_networks(priv, scan_cfg, 1);
323 wait_event_interruptible(priv->cmd_pending,
324 priv->surpriseremoved || !priv->last_scanned_channel);
326 if (priv->surpriseremoved)
329 memset(&wrqu, 0x00, sizeof(union iwreq_data));
330 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
335 free_page((unsigned long)buf);
341 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
342 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
343 * firmware. Here's an example:
344 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
345 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
346 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
348 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
349 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
350 * defined in mrvlietypes_thresholds
352 * This function searches in this TLV data chunk for a given TLV type
353 * and returns a pointer to the first data byte of the TLV, or to NULL
354 * if the TLV hasn't been found.
356 static void *lbs_tlv_find(u16 tlv_type, const u8 *tlv, u16 size)
358 __le16 le_type = cpu_to_le16(tlv_type);
360 struct mrvlietypesheader *tlv_h;
363 tlv_h = (struct mrvlietypesheader *) tlv;
364 if (tlv_h->type == le_type)
368 length = le16_to_cpu(tlv_h->len) +
369 sizeof(struct mrvlietypesheader);
378 * This just gets the bitmap of currently subscribed events. Used when
379 * adding an additonal event subscription.
381 static u16 lbs_get_events_bitmap(struct lbs_private *priv)
385 struct cmd_ds_802_11_subscribe_event *events = kzalloc(
386 sizeof(struct cmd_ds_802_11_subscribe_event),
389 res = lbs_prepare_and_send_command(priv,
390 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
391 CMD_OPTION_WAITFORRSP, 0, events);
397 return le16_to_cpu(events->events);
401 static ssize_t lbs_threshold_read(
402 u16 tlv_type, u16 event_mask,
403 struct file *file, char __user *userbuf,
404 size_t count, loff_t *ppos)
406 struct lbs_private *priv = file->private_data;
409 unsigned long addr = get_zeroed_page(GFP_KERNEL);
410 char *buf = (char *)addr;
414 struct cmd_ds_802_11_subscribe_event *events = kzalloc(
415 sizeof(struct cmd_ds_802_11_subscribe_event),
417 struct mrvlietypes_thresholds *got;
419 res = lbs_prepare_and_send_command(priv,
420 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
421 CMD_OPTION_WAITFORRSP, 0, events);
427 got = lbs_tlv_find(tlv_type, events->tlv, sizeof(events->tlv));
435 pos += snprintf(buf, len, "%d %d %d\n", value, freq,
436 !!(le16_to_cpu(events->events) & event_mask));
438 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
445 static ssize_t lbs_threshold_write(
446 u16 tlv_type, u16 event_mask,
448 const char __user *userbuf,
449 size_t count, loff_t *ppos)
451 struct lbs_private *priv = file->private_data;
452 ssize_t res, buf_size;
453 int value, freq, curr_mask, new_mask;
454 unsigned long addr = get_zeroed_page(GFP_KERNEL);
455 char *buf = (char *)addr;
456 struct cmd_ds_802_11_subscribe_event *events;
458 buf_size = min(count, len - 1);
459 if (copy_from_user(buf, userbuf, buf_size)) {
463 res = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
468 curr_mask = lbs_get_events_bitmap(priv);
471 new_mask = curr_mask | event_mask;
473 new_mask = curr_mask & ~event_mask;
475 /* Now everything is set and we can send stuff down to the firmware */
477 sizeof(struct cmd_ds_802_11_subscribe_event),
480 struct mrvlietypes_thresholds *tlv =
481 (struct mrvlietypes_thresholds *) events->tlv;
482 events->action = cpu_to_le16(CMD_ACT_SET);
483 events->events = cpu_to_le16(new_mask);
484 tlv->header.type = cpu_to_le16(tlv_type);
485 tlv->header.len = cpu_to_le16(
486 sizeof(struct mrvlietypes_thresholds) -
487 sizeof(struct mrvlietypesheader));
489 if (tlv_type != TLV_TYPE_BCNMISS)
491 lbs_prepare_and_send_command(priv,
492 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_SET,
493 CMD_OPTION_WAITFORRSP, 0, events);
504 static ssize_t lbs_lowrssi_read(
505 struct file *file, char __user *userbuf,
506 size_t count, loff_t *ppos)
508 return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
509 file, userbuf, count, ppos);
513 static ssize_t lbs_lowrssi_write(
514 struct file *file, const char __user *userbuf,
515 size_t count, loff_t *ppos)
517 return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
518 file, userbuf, count, ppos);
522 static ssize_t lbs_lowsnr_read(
523 struct file *file, char __user *userbuf,
524 size_t count, loff_t *ppos)
526 return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
527 file, userbuf, count, ppos);
531 static ssize_t lbs_lowsnr_write(
532 struct file *file, const char __user *userbuf,
533 size_t count, loff_t *ppos)
535 return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
536 file, userbuf, count, ppos);
540 static ssize_t lbs_failcount_read(
541 struct file *file, char __user *userbuf,
542 size_t count, loff_t *ppos)
544 return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
545 file, userbuf, count, ppos);
549 static ssize_t lbs_failcount_write(
550 struct file *file, const char __user *userbuf,
551 size_t count, loff_t *ppos)
553 return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
554 file, userbuf, count, ppos);
558 static ssize_t lbs_highrssi_read(
559 struct file *file, char __user *userbuf,
560 size_t count, loff_t *ppos)
562 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
563 file, userbuf, count, ppos);
567 static ssize_t lbs_highrssi_write(
568 struct file *file, const char __user *userbuf,
569 size_t count, loff_t *ppos)
571 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
572 file, userbuf, count, ppos);
576 static ssize_t lbs_highsnr_read(
577 struct file *file, char __user *userbuf,
578 size_t count, loff_t *ppos)
580 return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
581 file, userbuf, count, ppos);
585 static ssize_t lbs_highsnr_write(
586 struct file *file, const char __user *userbuf,
587 size_t count, loff_t *ppos)
589 return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
590 file, userbuf, count, ppos);
593 static ssize_t lbs_bcnmiss_read(
594 struct file *file, char __user *userbuf,
595 size_t count, loff_t *ppos)
597 return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
598 file, userbuf, count, ppos);
602 static ssize_t lbs_bcnmiss_write(
603 struct file *file, const char __user *userbuf,
604 size_t count, loff_t *ppos)
606 return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
607 file, userbuf, count, ppos);
617 static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
618 size_t count, loff_t *ppos)
620 struct lbs_private *priv = file->private_data;
621 struct lbs_offset_value offval;
624 unsigned long addr = get_zeroed_page(GFP_KERNEL);
625 char *buf = (char *)addr;
627 offval.offset = priv->mac_offset;
630 ret = lbs_prepare_and_send_command(priv,
631 CMD_MAC_REG_ACCESS, 0,
632 CMD_OPTION_WAITFORRSP, 0, &offval);
634 pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
635 priv->mac_offset, priv->offsetvalue.value);
637 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
642 static ssize_t lbs_rdmac_write(struct file *file,
643 const char __user *userbuf,
644 size_t count, loff_t *ppos)
646 struct lbs_private *priv = file->private_data;
647 ssize_t res, buf_size;
648 unsigned long addr = get_zeroed_page(GFP_KERNEL);
649 char *buf = (char *)addr;
651 buf_size = min(count, len - 1);
652 if (copy_from_user(buf, userbuf, buf_size)) {
656 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
663 static ssize_t lbs_wrmac_write(struct file *file,
664 const char __user *userbuf,
665 size_t count, loff_t *ppos)
668 struct lbs_private *priv = file->private_data;
669 ssize_t res, buf_size;
671 struct lbs_offset_value offval;
672 unsigned long addr = get_zeroed_page(GFP_KERNEL);
673 char *buf = (char *)addr;
675 buf_size = min(count, len - 1);
676 if (copy_from_user(buf, userbuf, buf_size)) {
680 res = sscanf(buf, "%x %x", &offset, &value);
686 offval.offset = offset;
687 offval.value = value;
688 res = lbs_prepare_and_send_command(priv,
689 CMD_MAC_REG_ACCESS, 1,
690 CMD_OPTION_WAITFORRSP, 0, &offval);
699 static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
700 size_t count, loff_t *ppos)
702 struct lbs_private *priv = file->private_data;
703 struct lbs_offset_value offval;
706 unsigned long addr = get_zeroed_page(GFP_KERNEL);
707 char *buf = (char *)addr;
709 offval.offset = priv->bbp_offset;
712 ret = lbs_prepare_and_send_command(priv,
713 CMD_BBP_REG_ACCESS, 0,
714 CMD_OPTION_WAITFORRSP, 0, &offval);
716 pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
717 priv->bbp_offset, priv->offsetvalue.value);
719 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
725 static ssize_t lbs_rdbbp_write(struct file *file,
726 const char __user *userbuf,
727 size_t count, loff_t *ppos)
729 struct lbs_private *priv = file->private_data;
730 ssize_t res, buf_size;
731 unsigned long addr = get_zeroed_page(GFP_KERNEL);
732 char *buf = (char *)addr;
734 buf_size = min(count, len - 1);
735 if (copy_from_user(buf, userbuf, buf_size)) {
739 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
746 static ssize_t lbs_wrbbp_write(struct file *file,
747 const char __user *userbuf,
748 size_t count, loff_t *ppos)
751 struct lbs_private *priv = file->private_data;
752 ssize_t res, buf_size;
754 struct lbs_offset_value offval;
755 unsigned long addr = get_zeroed_page(GFP_KERNEL);
756 char *buf = (char *)addr;
758 buf_size = min(count, len - 1);
759 if (copy_from_user(buf, userbuf, buf_size)) {
763 res = sscanf(buf, "%x %x", &offset, &value);
769 offval.offset = offset;
770 offval.value = value;
771 res = lbs_prepare_and_send_command(priv,
772 CMD_BBP_REG_ACCESS, 1,
773 CMD_OPTION_WAITFORRSP, 0, &offval);
782 static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
783 size_t count, loff_t *ppos)
785 struct lbs_private *priv = file->private_data;
786 struct lbs_offset_value offval;
789 unsigned long addr = get_zeroed_page(GFP_KERNEL);
790 char *buf = (char *)addr;
792 offval.offset = priv->rf_offset;
795 ret = lbs_prepare_and_send_command(priv,
796 CMD_RF_REG_ACCESS, 0,
797 CMD_OPTION_WAITFORRSP, 0, &offval);
799 pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
800 priv->rf_offset, priv->offsetvalue.value);
802 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
808 static ssize_t lbs_rdrf_write(struct file *file,
809 const char __user *userbuf,
810 size_t count, loff_t *ppos)
812 struct lbs_private *priv = file->private_data;
813 ssize_t res, buf_size;
814 unsigned long addr = get_zeroed_page(GFP_KERNEL);
815 char *buf = (char *)addr;
817 buf_size = min(count, len - 1);
818 if (copy_from_user(buf, userbuf, buf_size)) {
822 priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
829 static ssize_t lbs_wrrf_write(struct file *file,
830 const char __user *userbuf,
831 size_t count, loff_t *ppos)
834 struct lbs_private *priv = file->private_data;
835 ssize_t res, buf_size;
837 struct lbs_offset_value offval;
838 unsigned long addr = get_zeroed_page(GFP_KERNEL);
839 char *buf = (char *)addr;
841 buf_size = min(count, len - 1);
842 if (copy_from_user(buf, userbuf, buf_size)) {
846 res = sscanf(buf, "%x %x", &offset, &value);
852 offval.offset = offset;
853 offval.value = value;
854 res = lbs_prepare_and_send_command(priv,
855 CMD_RF_REG_ACCESS, 1,
856 CMD_OPTION_WAITFORRSP, 0, &offval);
865 #define FOPS(fread, fwrite) { \
866 .owner = THIS_MODULE, \
867 .open = open_file_generic, \
872 struct lbs_debugfs_files {
875 struct file_operations fops;
878 static struct lbs_debugfs_files debugfs_files[] = {
879 { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
880 { "getscantable", 0444, FOPS(lbs_getscantable,
881 write_file_dummy), },
882 { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
883 lbs_sleepparams_write), },
884 { "extscan", 0600, FOPS(NULL, lbs_extscan), },
885 { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), },
888 static struct lbs_debugfs_files debugfs_events_files[] = {
889 {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
890 lbs_lowrssi_write), },
891 {"low_snr", 0644, FOPS(lbs_lowsnr_read,
892 lbs_lowsnr_write), },
893 {"failure_count", 0644, FOPS(lbs_failcount_read,
894 lbs_failcount_write), },
895 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
896 lbs_bcnmiss_write), },
897 {"high_rssi", 0644, FOPS(lbs_highrssi_read,
898 lbs_highrssi_write), },
899 {"high_snr", 0644, FOPS(lbs_highsnr_read,
900 lbs_highsnr_write), },
903 static struct lbs_debugfs_files debugfs_regs_files[] = {
904 {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
905 {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
906 {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
907 {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
908 {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
909 {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
912 void lbs_debugfs_init(void)
915 lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
920 void lbs_debugfs_remove(void)
923 debugfs_remove(lbs_dir);
927 void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
930 struct lbs_debugfs_files *files;
934 priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
935 if (!priv->debugfs_dir)
938 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
939 files = &debugfs_files[i];
940 priv->debugfs_files[i] = debugfs_create_file(files->name,
947 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
948 if (!priv->events_dir)
951 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
952 files = &debugfs_events_files[i];
953 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
960 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
964 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
965 files = &debugfs_regs_files[i];
966 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
974 lbs_debug_init(priv, dev);
980 void lbs_debugfs_remove_one(struct lbs_private *priv)
984 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
985 debugfs_remove(priv->debugfs_regs_files[i]);
987 debugfs_remove(priv->regs_dir);
989 for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
990 debugfs_remove(priv->debugfs_events_files[i]);
992 debugfs_remove(priv->events_dir);
994 debugfs_remove(priv->debugfs_debug);
996 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
997 debugfs_remove(priv->debugfs_files[i]);
998 debugfs_remove(priv->debugfs_dir);
1007 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
1008 #define item_addr(n) (offsetof(struct lbs_private, n))
1017 /* To debug any member of struct lbs_private, simply add one line here.
1019 static struct debug_data items[] = {
1020 {"intcounter", item_size(intcounter), item_addr(intcounter)},
1021 {"psmode", item_size(psmode), item_addr(psmode)},
1022 {"psstate", item_size(psstate), item_addr(psstate)},
1025 static int num_of_items = ARRAY_SIZE(items);
1028 * @brief proc read function
1030 * @param page pointer to buffer
1031 * @param s read data starting position
1033 * @param cnt counter
1034 * @param eof end of file flag
1035 * @param data data to output
1036 * @return number of output data
1038 static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
1039 size_t count, loff_t *ppos)
1046 struct debug_data *d;
1047 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1048 char *buf = (char *)addr;
1052 d = (struct debug_data *)file->private_data;
1054 for (i = 0; i < num_of_items; i++) {
1056 val = *((u8 *) d[i].addr);
1057 else if (d[i].size == 2)
1058 val = *((u16 *) d[i].addr);
1059 else if (d[i].size == 4)
1060 val = *((u32 *) d[i].addr);
1061 else if (d[i].size == 8)
1062 val = *((u64 *) d[i].addr);
1064 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
1067 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
1074 * @brief proc write function
1076 * @param f file pointer
1077 * @param buf pointer to data buffer
1078 * @param cnt data number to write
1079 * @param data data to write
1080 * @return number of data
1082 static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
1083 size_t cnt, loff_t *ppos)
1091 struct debug_data *d = (struct debug_data *)f->private_data;
1093 pdata = kmalloc(cnt, GFP_KERNEL);
1097 if (copy_from_user(pdata, buf, cnt)) {
1098 lbs_deb_debugfs("Copy from user failed\n");
1104 for (i = 0; i < num_of_items; i++) {
1106 p = strstr(p0, d[i].name);
1109 p1 = strchr(p, '\n');
1113 p2 = strchr(p, '=');
1117 r = simple_strtoul(p2, NULL, 0);
1119 *((u8 *) d[i].addr) = (u8) r;
1120 else if (d[i].size == 2)
1121 *((u16 *) d[i].addr) = (u16) r;
1122 else if (d[i].size == 4)
1123 *((u32 *) d[i].addr) = (u32) r;
1124 else if (d[i].size == 8)
1125 *((u64 *) d[i].addr) = (u64) r;
1131 return (ssize_t)cnt;
1134 static struct file_operations lbs_debug_fops = {
1135 .owner = THIS_MODULE,
1136 .open = open_file_generic,
1137 .write = lbs_debugfs_write,
1138 .read = lbs_debugfs_read,
1142 * @brief create debug proc file
1144 * @param priv pointer struct lbs_private
1145 * @param dev pointer net_device
1148 static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev)
1152 if (!priv->debugfs_dir)
1155 for (i = 0; i < num_of_items; i++)
1156 items[i].addr += (size_t) priv;
1158 priv->debugfs_debug = debugfs_create_file("debug", 0644,
1159 priv->debugfs_dir, &items[0],