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;
415 struct cmd_ds_802_11_subscribe_event *subscribed = kzalloc(
416 sizeof(struct cmd_ds_802_11_subscribe_event),
418 struct mrvlietypes_thresholds *got;
420 res = lbs_prepare_and_send_command(priv,
421 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
422 CMD_OPTION_WAITFORRSP, 0, subscribed);
428 got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
432 events = le16_to_cpu(subscribed->events);
437 pos += snprintf(buf, len, "%d %d %d\n", value, freq,
438 !!(events & event_mask));
440 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
447 static ssize_t lbs_threshold_write(
448 u16 tlv_type, u16 event_mask,
450 const char __user *userbuf,
451 size_t count, loff_t *ppos)
453 struct lbs_private *priv = file->private_data;
454 ssize_t res, buf_size;
455 int value, freq, curr_mask, new_mask;
456 unsigned long addr = get_zeroed_page(GFP_KERNEL);
457 char *buf = (char *)addr;
458 struct cmd_ds_802_11_subscribe_event *events;
460 buf_size = min(count, len - 1);
461 if (copy_from_user(buf, userbuf, buf_size)) {
465 res = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
470 curr_mask = lbs_get_events_bitmap(priv);
473 new_mask = curr_mask | event_mask;
475 new_mask = curr_mask & ~event_mask;
477 /* Now everything is set and we can send stuff down to the firmware */
479 sizeof(struct cmd_ds_802_11_subscribe_event),
482 struct mrvlietypes_thresholds *tlv =
483 (struct mrvlietypes_thresholds *) events->tlv;
484 events->action = cpu_to_le16(CMD_ACT_SET);
485 events->events = cpu_to_le16(new_mask);
486 tlv->header.type = cpu_to_le16(tlv_type);
487 tlv->header.len = cpu_to_le16(
488 sizeof(struct mrvlietypes_thresholds) -
489 sizeof(struct mrvlietypesheader));
491 if (tlv_type != TLV_TYPE_BCNMISS)
493 lbs_prepare_and_send_command(priv,
494 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_SET,
495 CMD_OPTION_WAITFORRSP, 0, events);
506 static ssize_t lbs_lowrssi_read(
507 struct file *file, char __user *userbuf,
508 size_t count, loff_t *ppos)
510 return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
511 file, userbuf, count, ppos);
515 static ssize_t lbs_lowrssi_write(
516 struct file *file, const char __user *userbuf,
517 size_t count, loff_t *ppos)
519 return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
520 file, userbuf, count, ppos);
524 static ssize_t lbs_lowsnr_read(
525 struct file *file, char __user *userbuf,
526 size_t count, loff_t *ppos)
528 return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
529 file, userbuf, count, ppos);
533 static ssize_t lbs_lowsnr_write(
534 struct file *file, const char __user *userbuf,
535 size_t count, loff_t *ppos)
537 return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
538 file, userbuf, count, ppos);
542 static ssize_t lbs_failcount_read(
543 struct file *file, char __user *userbuf,
544 size_t count, loff_t *ppos)
546 return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
547 file, userbuf, count, ppos);
551 static ssize_t lbs_failcount_write(
552 struct file *file, const char __user *userbuf,
553 size_t count, loff_t *ppos)
555 return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
556 file, userbuf, count, ppos);
560 static ssize_t lbs_highrssi_read(
561 struct file *file, char __user *userbuf,
562 size_t count, loff_t *ppos)
564 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
565 file, userbuf, count, ppos);
569 static ssize_t lbs_highrssi_write(
570 struct file *file, const char __user *userbuf,
571 size_t count, loff_t *ppos)
573 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
574 file, userbuf, count, ppos);
578 static ssize_t lbs_highsnr_read(
579 struct file *file, char __user *userbuf,
580 size_t count, loff_t *ppos)
582 return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
583 file, userbuf, count, ppos);
587 static ssize_t lbs_highsnr_write(
588 struct file *file, const char __user *userbuf,
589 size_t count, loff_t *ppos)
591 return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
592 file, userbuf, count, ppos);
595 static ssize_t lbs_bcnmiss_read(
596 struct file *file, char __user *userbuf,
597 size_t count, loff_t *ppos)
599 return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
600 file, userbuf, count, ppos);
604 static ssize_t lbs_bcnmiss_write(
605 struct file *file, const char __user *userbuf,
606 size_t count, loff_t *ppos)
608 return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
609 file, userbuf, count, ppos);
619 static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
620 size_t count, loff_t *ppos)
622 struct lbs_private *priv = file->private_data;
623 struct lbs_offset_value offval;
626 unsigned long addr = get_zeroed_page(GFP_KERNEL);
627 char *buf = (char *)addr;
629 offval.offset = priv->mac_offset;
632 ret = lbs_prepare_and_send_command(priv,
633 CMD_MAC_REG_ACCESS, 0,
634 CMD_OPTION_WAITFORRSP, 0, &offval);
636 pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
637 priv->mac_offset, priv->offsetvalue.value);
639 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
644 static ssize_t lbs_rdmac_write(struct file *file,
645 const char __user *userbuf,
646 size_t count, loff_t *ppos)
648 struct lbs_private *priv = file->private_data;
649 ssize_t res, buf_size;
650 unsigned long addr = get_zeroed_page(GFP_KERNEL);
651 char *buf = (char *)addr;
653 buf_size = min(count, len - 1);
654 if (copy_from_user(buf, userbuf, buf_size)) {
658 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
665 static ssize_t lbs_wrmac_write(struct file *file,
666 const char __user *userbuf,
667 size_t count, loff_t *ppos)
670 struct lbs_private *priv = file->private_data;
671 ssize_t res, buf_size;
673 struct lbs_offset_value offval;
674 unsigned long addr = get_zeroed_page(GFP_KERNEL);
675 char *buf = (char *)addr;
677 buf_size = min(count, len - 1);
678 if (copy_from_user(buf, userbuf, buf_size)) {
682 res = sscanf(buf, "%x %x", &offset, &value);
688 offval.offset = offset;
689 offval.value = value;
690 res = lbs_prepare_and_send_command(priv,
691 CMD_MAC_REG_ACCESS, 1,
692 CMD_OPTION_WAITFORRSP, 0, &offval);
701 static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
702 size_t count, loff_t *ppos)
704 struct lbs_private *priv = file->private_data;
705 struct lbs_offset_value offval;
708 unsigned long addr = get_zeroed_page(GFP_KERNEL);
709 char *buf = (char *)addr;
711 offval.offset = priv->bbp_offset;
714 ret = lbs_prepare_and_send_command(priv,
715 CMD_BBP_REG_ACCESS, 0,
716 CMD_OPTION_WAITFORRSP, 0, &offval);
718 pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
719 priv->bbp_offset, priv->offsetvalue.value);
721 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
727 static ssize_t lbs_rdbbp_write(struct file *file,
728 const char __user *userbuf,
729 size_t count, loff_t *ppos)
731 struct lbs_private *priv = file->private_data;
732 ssize_t res, buf_size;
733 unsigned long addr = get_zeroed_page(GFP_KERNEL);
734 char *buf = (char *)addr;
736 buf_size = min(count, len - 1);
737 if (copy_from_user(buf, userbuf, buf_size)) {
741 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
748 static ssize_t lbs_wrbbp_write(struct file *file,
749 const char __user *userbuf,
750 size_t count, loff_t *ppos)
753 struct lbs_private *priv = file->private_data;
754 ssize_t res, buf_size;
756 struct lbs_offset_value offval;
757 unsigned long addr = get_zeroed_page(GFP_KERNEL);
758 char *buf = (char *)addr;
760 buf_size = min(count, len - 1);
761 if (copy_from_user(buf, userbuf, buf_size)) {
765 res = sscanf(buf, "%x %x", &offset, &value);
771 offval.offset = offset;
772 offval.value = value;
773 res = lbs_prepare_and_send_command(priv,
774 CMD_BBP_REG_ACCESS, 1,
775 CMD_OPTION_WAITFORRSP, 0, &offval);
784 static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
785 size_t count, loff_t *ppos)
787 struct lbs_private *priv = file->private_data;
788 struct lbs_offset_value offval;
791 unsigned long addr = get_zeroed_page(GFP_KERNEL);
792 char *buf = (char *)addr;
794 offval.offset = priv->rf_offset;
797 ret = lbs_prepare_and_send_command(priv,
798 CMD_RF_REG_ACCESS, 0,
799 CMD_OPTION_WAITFORRSP, 0, &offval);
801 pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
802 priv->rf_offset, priv->offsetvalue.value);
804 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
810 static ssize_t lbs_rdrf_write(struct file *file,
811 const char __user *userbuf,
812 size_t count, loff_t *ppos)
814 struct lbs_private *priv = file->private_data;
815 ssize_t res, buf_size;
816 unsigned long addr = get_zeroed_page(GFP_KERNEL);
817 char *buf = (char *)addr;
819 buf_size = min(count, len - 1);
820 if (copy_from_user(buf, userbuf, buf_size)) {
824 priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
831 static ssize_t lbs_wrrf_write(struct file *file,
832 const char __user *userbuf,
833 size_t count, loff_t *ppos)
836 struct lbs_private *priv = file->private_data;
837 ssize_t res, buf_size;
839 struct lbs_offset_value offval;
840 unsigned long addr = get_zeroed_page(GFP_KERNEL);
841 char *buf = (char *)addr;
843 buf_size = min(count, len - 1);
844 if (copy_from_user(buf, userbuf, buf_size)) {
848 res = sscanf(buf, "%x %x", &offset, &value);
854 offval.offset = offset;
855 offval.value = value;
856 res = lbs_prepare_and_send_command(priv,
857 CMD_RF_REG_ACCESS, 1,
858 CMD_OPTION_WAITFORRSP, 0, &offval);
867 #define FOPS(fread, fwrite) { \
868 .owner = THIS_MODULE, \
869 .open = open_file_generic, \
874 struct lbs_debugfs_files {
877 struct file_operations fops;
880 static struct lbs_debugfs_files debugfs_files[] = {
881 { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
882 { "getscantable", 0444, FOPS(lbs_getscantable,
883 write_file_dummy), },
884 { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
885 lbs_sleepparams_write), },
886 { "extscan", 0600, FOPS(NULL, lbs_extscan), },
887 { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), },
890 static struct lbs_debugfs_files debugfs_events_files[] = {
891 {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
892 lbs_lowrssi_write), },
893 {"low_snr", 0644, FOPS(lbs_lowsnr_read,
894 lbs_lowsnr_write), },
895 {"failure_count", 0644, FOPS(lbs_failcount_read,
896 lbs_failcount_write), },
897 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
898 lbs_bcnmiss_write), },
899 {"high_rssi", 0644, FOPS(lbs_highrssi_read,
900 lbs_highrssi_write), },
901 {"high_snr", 0644, FOPS(lbs_highsnr_read,
902 lbs_highsnr_write), },
905 static struct lbs_debugfs_files debugfs_regs_files[] = {
906 {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
907 {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
908 {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
909 {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
910 {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
911 {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
914 void lbs_debugfs_init(void)
917 lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
922 void lbs_debugfs_remove(void)
925 debugfs_remove(lbs_dir);
929 void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
932 struct lbs_debugfs_files *files;
936 priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
937 if (!priv->debugfs_dir)
940 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
941 files = &debugfs_files[i];
942 priv->debugfs_files[i] = debugfs_create_file(files->name,
949 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
950 if (!priv->events_dir)
953 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
954 files = &debugfs_events_files[i];
955 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
962 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
966 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
967 files = &debugfs_regs_files[i];
968 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
976 lbs_debug_init(priv, dev);
982 void lbs_debugfs_remove_one(struct lbs_private *priv)
986 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
987 debugfs_remove(priv->debugfs_regs_files[i]);
989 debugfs_remove(priv->regs_dir);
991 for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
992 debugfs_remove(priv->debugfs_events_files[i]);
994 debugfs_remove(priv->events_dir);
996 debugfs_remove(priv->debugfs_debug);
998 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
999 debugfs_remove(priv->debugfs_files[i]);
1000 debugfs_remove(priv->debugfs_dir);
1009 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
1010 #define item_addr(n) (offsetof(struct lbs_private, n))
1019 /* To debug any member of struct lbs_private, simply add one line here.
1021 static struct debug_data items[] = {
1022 {"intcounter", item_size(intcounter), item_addr(intcounter)},
1023 {"psmode", item_size(psmode), item_addr(psmode)},
1024 {"psstate", item_size(psstate), item_addr(psstate)},
1027 static int num_of_items = ARRAY_SIZE(items);
1030 * @brief proc read function
1032 * @param page pointer to buffer
1033 * @param s read data starting position
1035 * @param cnt counter
1036 * @param eof end of file flag
1037 * @param data data to output
1038 * @return number of output data
1040 static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
1041 size_t count, loff_t *ppos)
1048 struct debug_data *d;
1049 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1050 char *buf = (char *)addr;
1054 d = (struct debug_data *)file->private_data;
1056 for (i = 0; i < num_of_items; i++) {
1058 val = *((u8 *) d[i].addr);
1059 else if (d[i].size == 2)
1060 val = *((u16 *) d[i].addr);
1061 else if (d[i].size == 4)
1062 val = *((u32 *) d[i].addr);
1063 else if (d[i].size == 8)
1064 val = *((u64 *) d[i].addr);
1066 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
1069 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
1076 * @brief proc write function
1078 * @param f file pointer
1079 * @param buf pointer to data buffer
1080 * @param cnt data number to write
1081 * @param data data to write
1082 * @return number of data
1084 static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
1085 size_t cnt, loff_t *ppos)
1093 struct debug_data *d = (struct debug_data *)f->private_data;
1095 pdata = kmalloc(cnt, GFP_KERNEL);
1099 if (copy_from_user(pdata, buf, cnt)) {
1100 lbs_deb_debugfs("Copy from user failed\n");
1106 for (i = 0; i < num_of_items; i++) {
1108 p = strstr(p0, d[i].name);
1111 p1 = strchr(p, '\n');
1115 p2 = strchr(p, '=');
1119 r = simple_strtoul(p2, NULL, 0);
1121 *((u8 *) d[i].addr) = (u8) r;
1122 else if (d[i].size == 2)
1123 *((u16 *) d[i].addr) = (u16) r;
1124 else if (d[i].size == 4)
1125 *((u32 *) d[i].addr) = (u32) r;
1126 else if (d[i].size == 8)
1127 *((u64 *) d[i].addr) = (u64) r;
1133 return (ssize_t)cnt;
1136 static struct file_operations lbs_debug_fops = {
1137 .owner = THIS_MODULE,
1138 .open = open_file_generic,
1139 .write = lbs_debugfs_write,
1140 .read = lbs_debugfs_read,
1144 * @brief create debug proc file
1146 * @param priv pointer struct lbs_private
1147 * @param dev pointer net_device
1150 static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev)
1154 if (!priv->debugfs_dir)
1157 for (i = 0; i < num_of_items; i++)
1158 items[i].addr += (size_t) priv;
1160 priv->debugfs_debug = debugfs_create_file("debug", 0644,
1161 priv->debugfs_dir, &items[0],