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->adapter->connect_status]);
49 pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
50 (u32) priv->adapter->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->adapter->lock);
74 list_for_each_entry (iter_bss, &priv->adapter->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->adapter->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->adapter->sp.sp_error = p1;
122 priv->adapter->sp.sp_offset = p2;
123 priv->adapter->sp.sp_stabletime = p3;
124 priv->adapter->sp.sp_calcontrol = p4;
125 priv->adapter->sp.sp_extsleepclk = p5;
126 priv->adapter->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;
147 struct lbs_adapter *adapter = priv->adapter;
150 unsigned long addr = get_zeroed_page(GFP_KERNEL);
151 char *buf = (char *)addr;
153 res = lbs_prepare_and_send_command(priv,
154 CMD_802_11_SLEEP_PARAMS,
156 CMD_OPTION_WAITFORRSP, 0, NULL);
162 pos += snprintf(buf, len, "%d %d %d %d %d %d\n", adapter->sp.sp_error,
163 adapter->sp.sp_offset, adapter->sp.sp_stabletime,
164 adapter->sp.sp_calcontrol, adapter->sp.sp_extsleepclk,
165 adapter->sp.sp_reserved);
167 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
174 static ssize_t lbs_extscan(struct file *file, const char __user *userbuf,
175 size_t count, loff_t *ppos)
177 struct lbs_private *priv = file->private_data;
178 ssize_t res, buf_size;
179 union iwreq_data wrqu;
180 unsigned long addr = get_zeroed_page(GFP_KERNEL);
181 char *buf = (char *)addr;
183 buf_size = min(count, len - 1);
184 if (copy_from_user(buf, userbuf, buf_size)) {
189 lbs_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0);
191 memset(&wrqu, 0, sizeof(union iwreq_data));
192 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
199 static void lbs_parse_bssid(char *buf, size_t count,
200 struct lbs_ioctl_user_scan_cfg *scan_cfg)
203 unsigned int mac[ETH_ALEN];
205 hold = strstr(buf, "bssid=");
209 sscanf(hold, "%02x:%02x:%02x:%02x:%02x:%02x",
210 mac, mac+1, mac+2, mac+3, mac+4, mac+5);
211 memcpy(scan_cfg->bssid, mac, ETH_ALEN);
214 static void lbs_parse_ssid(char *buf, size_t count,
215 struct lbs_ioctl_user_scan_cfg *scan_cfg)
220 hold = strstr(buf, "ssid=");
224 end = strchr(hold, ' ');
226 end = buf + count - 1;
228 size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
229 strncpy(scan_cfg->ssid, hold, size);
234 static int lbs_parse_clear(char *buf, size_t count, const char *tag)
239 hold = strstr(buf, tag);
243 sscanf(hold, "%d", &val);
251 static int lbs_parse_dur(char *buf, size_t count,
252 struct lbs_ioctl_user_scan_cfg *scan_cfg)
257 hold = strstr(buf, "dur=");
261 sscanf(hold, "%d", &val);
266 static void lbs_parse_type(char *buf, size_t count,
267 struct lbs_ioctl_user_scan_cfg *scan_cfg)
272 hold = strstr(buf, "type=");
276 sscanf(hold, "%d", &val);
279 if (val < 1 || val > 3)
282 scan_cfg->bsstype = val;
287 static ssize_t lbs_setuserscan(struct file *file,
288 const char __user *userbuf,
289 size_t count, loff_t *ppos)
291 struct lbs_private *priv = file->private_data;
292 ssize_t res, buf_size;
293 struct lbs_ioctl_user_scan_cfg *scan_cfg;
294 union iwreq_data wrqu;
296 char *buf = (char *)get_zeroed_page(GFP_KERNEL);
301 buf_size = min(count, len - 1);
302 if (copy_from_user(buf, userbuf, buf_size)) {
307 scan_cfg = kzalloc(sizeof(struct lbs_ioctl_user_scan_cfg), GFP_KERNEL);
314 scan_cfg->bsstype = LBS_SCAN_BSS_TYPE_ANY;
316 dur = lbs_parse_dur(buf, count, scan_cfg);
317 lbs_parse_bssid(buf, count, scan_cfg);
318 scan_cfg->clear_bssid = lbs_parse_clear(buf, count, "clear_bssid=");
319 lbs_parse_ssid(buf, count, scan_cfg);
320 scan_cfg->clear_ssid = lbs_parse_clear(buf, count, "clear_ssid=");
321 lbs_parse_type(buf, count, scan_cfg);
323 lbs_scan_networks(priv, scan_cfg, 1);
324 wait_event_interruptible(priv->adapter->cmd_pending,
325 priv->adapter->surpriseremoved ||
326 (!priv->adapter->cur_cmd && list_empty(&priv->adapter->cmdpendingq)));
328 if (priv->adapter->surpriseremoved)
331 memset(&wrqu, 0x00, sizeof(union iwreq_data));
332 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
337 free_page((unsigned long)buf);
343 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
344 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
345 * firmware. Here's an example:
346 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
347 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
348 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
350 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
351 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
352 * defined in mrvlietypes_thresholds
354 * This function searches in this TLV data chunk for a given TLV type
355 * and returns a pointer to the first data byte of the TLV, or to NULL
356 * if the TLV hasn't been found.
358 static void *lbs_tlv_find(u16 tlv_type, const u8 *tlv, u16 size)
360 __le16 le_type = cpu_to_le16(tlv_type);
362 struct mrvlietypesheader *tlv_h;
365 tlv_h = (struct mrvlietypesheader *) tlv;
366 if (tlv_h->type == le_type)
370 length = le16_to_cpu(tlv_h->len) +
371 sizeof(struct mrvlietypesheader);
380 * This just gets the bitmap of currently subscribed events. Used when
381 * adding an additonal event subscription.
383 static u16 lbs_get_events_bitmap(struct lbs_private *priv)
387 struct cmd_ds_802_11_subscribe_event *events = kzalloc(
388 sizeof(struct cmd_ds_802_11_subscribe_event),
391 res = lbs_prepare_and_send_command(priv,
392 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
393 CMD_OPTION_WAITFORRSP, 0, events);
399 return le16_to_cpu(events->events);
403 static ssize_t lbs_threshold_read(
404 u16 tlv_type, u16 event_mask,
405 struct file *file, char __user *userbuf,
406 size_t count, loff_t *ppos)
408 struct lbs_private *priv = file->private_data;
411 unsigned long addr = get_zeroed_page(GFP_KERNEL);
412 char *buf = (char *)addr;
416 struct cmd_ds_802_11_subscribe_event *events = kzalloc(
417 sizeof(struct cmd_ds_802_11_subscribe_event),
419 struct mrvlietypes_thresholds *got;
421 res = lbs_prepare_and_send_command(priv,
422 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
423 CMD_OPTION_WAITFORRSP, 0, events);
429 got = lbs_tlv_find(tlv_type, events->tlv, sizeof(events->tlv));
437 pos += snprintf(buf, len, "%d %d %d\n", value, freq,
438 !!(le16_to_cpu(events->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_adapter *adapter = priv->adapter;
624 struct lbs_offset_value offval;
627 unsigned long addr = get_zeroed_page(GFP_KERNEL);
628 char *buf = (char *)addr;
630 offval.offset = priv->mac_offset;
633 ret = lbs_prepare_and_send_command(priv,
634 CMD_MAC_REG_ACCESS, 0,
635 CMD_OPTION_WAITFORRSP, 0, &offval);
637 pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
638 priv->mac_offset, adapter->offsetvalue.value);
640 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
645 static ssize_t lbs_rdmac_write(struct file *file,
646 const char __user *userbuf,
647 size_t count, loff_t *ppos)
649 struct lbs_private *priv = file->private_data;
650 ssize_t res, buf_size;
651 unsigned long addr = get_zeroed_page(GFP_KERNEL);
652 char *buf = (char *)addr;
654 buf_size = min(count, len - 1);
655 if (copy_from_user(buf, userbuf, buf_size)) {
659 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
666 static ssize_t lbs_wrmac_write(struct file *file,
667 const char __user *userbuf,
668 size_t count, loff_t *ppos)
671 struct lbs_private *priv = file->private_data;
672 ssize_t res, buf_size;
674 struct lbs_offset_value offval;
675 unsigned long addr = get_zeroed_page(GFP_KERNEL);
676 char *buf = (char *)addr;
678 buf_size = min(count, len - 1);
679 if (copy_from_user(buf, userbuf, buf_size)) {
683 res = sscanf(buf, "%x %x", &offset, &value);
689 offval.offset = offset;
690 offval.value = value;
691 res = lbs_prepare_and_send_command(priv,
692 CMD_MAC_REG_ACCESS, 1,
693 CMD_OPTION_WAITFORRSP, 0, &offval);
702 static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
703 size_t count, loff_t *ppos)
705 struct lbs_private *priv = file->private_data;
706 struct lbs_adapter *adapter = priv->adapter;
707 struct lbs_offset_value offval;
710 unsigned long addr = get_zeroed_page(GFP_KERNEL);
711 char *buf = (char *)addr;
713 offval.offset = priv->bbp_offset;
716 ret = lbs_prepare_and_send_command(priv,
717 CMD_BBP_REG_ACCESS, 0,
718 CMD_OPTION_WAITFORRSP, 0, &offval);
720 pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
721 priv->bbp_offset, adapter->offsetvalue.value);
723 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
729 static ssize_t lbs_rdbbp_write(struct file *file,
730 const char __user *userbuf,
731 size_t count, loff_t *ppos)
733 struct lbs_private *priv = file->private_data;
734 ssize_t res, buf_size;
735 unsigned long addr = get_zeroed_page(GFP_KERNEL);
736 char *buf = (char *)addr;
738 buf_size = min(count, len - 1);
739 if (copy_from_user(buf, userbuf, buf_size)) {
743 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
750 static ssize_t lbs_wrbbp_write(struct file *file,
751 const char __user *userbuf,
752 size_t count, loff_t *ppos)
755 struct lbs_private *priv = file->private_data;
756 ssize_t res, buf_size;
758 struct lbs_offset_value offval;
759 unsigned long addr = get_zeroed_page(GFP_KERNEL);
760 char *buf = (char *)addr;
762 buf_size = min(count, len - 1);
763 if (copy_from_user(buf, userbuf, buf_size)) {
767 res = sscanf(buf, "%x %x", &offset, &value);
773 offval.offset = offset;
774 offval.value = value;
775 res = lbs_prepare_and_send_command(priv,
776 CMD_BBP_REG_ACCESS, 1,
777 CMD_OPTION_WAITFORRSP, 0, &offval);
786 static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
787 size_t count, loff_t *ppos)
789 struct lbs_private *priv = file->private_data;
790 struct lbs_adapter *adapter = priv->adapter;
791 struct lbs_offset_value offval;
794 unsigned long addr = get_zeroed_page(GFP_KERNEL);
795 char *buf = (char *)addr;
797 offval.offset = priv->rf_offset;
800 ret = lbs_prepare_and_send_command(priv,
801 CMD_RF_REG_ACCESS, 0,
802 CMD_OPTION_WAITFORRSP, 0, &offval);
804 pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
805 priv->rf_offset, adapter->offsetvalue.value);
807 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
813 static ssize_t lbs_rdrf_write(struct file *file,
814 const char __user *userbuf,
815 size_t count, loff_t *ppos)
817 struct lbs_private *priv = file->private_data;
818 ssize_t res, buf_size;
819 unsigned long addr = get_zeroed_page(GFP_KERNEL);
820 char *buf = (char *)addr;
822 buf_size = min(count, len - 1);
823 if (copy_from_user(buf, userbuf, buf_size)) {
827 priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
834 static ssize_t lbs_wrrf_write(struct file *file,
835 const char __user *userbuf,
836 size_t count, loff_t *ppos)
839 struct lbs_private *priv = file->private_data;
840 ssize_t res, buf_size;
842 struct lbs_offset_value offval;
843 unsigned long addr = get_zeroed_page(GFP_KERNEL);
844 char *buf = (char *)addr;
846 buf_size = min(count, len - 1);
847 if (copy_from_user(buf, userbuf, buf_size)) {
851 res = sscanf(buf, "%x %x", &offset, &value);
857 offval.offset = offset;
858 offval.value = value;
859 res = lbs_prepare_and_send_command(priv,
860 CMD_RF_REG_ACCESS, 1,
861 CMD_OPTION_WAITFORRSP, 0, &offval);
870 #define FOPS(fread, fwrite) { \
871 .owner = THIS_MODULE, \
872 .open = open_file_generic, \
877 struct lbs_debugfs_files {
880 struct file_operations fops;
883 static struct lbs_debugfs_files debugfs_files[] = {
884 { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
885 { "getscantable", 0444, FOPS(lbs_getscantable,
886 write_file_dummy), },
887 { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
888 lbs_sleepparams_write), },
889 { "extscan", 0600, FOPS(NULL, lbs_extscan), },
890 { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), },
893 static struct lbs_debugfs_files debugfs_events_files[] = {
894 {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
895 lbs_lowrssi_write), },
896 {"low_snr", 0644, FOPS(lbs_lowsnr_read,
897 lbs_lowsnr_write), },
898 {"failure_count", 0644, FOPS(lbs_failcount_read,
899 lbs_failcount_write), },
900 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
901 lbs_bcnmiss_write), },
902 {"high_rssi", 0644, FOPS(lbs_highrssi_read,
903 lbs_highrssi_write), },
904 {"high_snr", 0644, FOPS(lbs_highsnr_read,
905 lbs_highsnr_write), },
908 static struct lbs_debugfs_files debugfs_regs_files[] = {
909 {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
910 {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
911 {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
912 {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
913 {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
914 {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
917 void lbs_debugfs_init(void)
920 lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
925 void lbs_debugfs_remove(void)
928 debugfs_remove(lbs_dir);
932 void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
935 struct lbs_debugfs_files *files;
939 priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
940 if (!priv->debugfs_dir)
943 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
944 files = &debugfs_files[i];
945 priv->debugfs_files[i] = debugfs_create_file(files->name,
952 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
953 if (!priv->events_dir)
956 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
957 files = &debugfs_events_files[i];
958 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
965 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
969 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
970 files = &debugfs_regs_files[i];
971 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
979 lbs_debug_init(priv, dev);
985 void lbs_debugfs_remove_one(struct lbs_private *priv)
989 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
990 debugfs_remove(priv->debugfs_regs_files[i]);
992 debugfs_remove(priv->regs_dir);
994 for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
995 debugfs_remove(priv->debugfs_events_files[i]);
997 debugfs_remove(priv->events_dir);
999 debugfs_remove(priv->debugfs_debug);
1001 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
1002 debugfs_remove(priv->debugfs_files[i]);
1003 debugfs_remove(priv->debugfs_dir);
1012 #define item_size(n) (FIELD_SIZEOF(struct lbs_adapter, n))
1013 #define item_addr(n) (offsetof(struct lbs_adapter, n))
1022 /* To debug any member of struct lbs_adapter, simply add one line here.
1024 static struct debug_data items[] = {
1025 {"intcounter", item_size(intcounter), item_addr(intcounter)},
1026 {"psmode", item_size(psmode), item_addr(psmode)},
1027 {"psstate", item_size(psstate), item_addr(psstate)},
1030 static int num_of_items = ARRAY_SIZE(items);
1033 * @brief proc read function
1035 * @param page pointer to buffer
1036 * @param s read data starting position
1038 * @param cnt counter
1039 * @param eof end of file flag
1040 * @param data data to output
1041 * @return number of output data
1043 static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
1044 size_t count, loff_t *ppos)
1051 struct debug_data *d;
1052 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1053 char *buf = (char *)addr;
1057 d = (struct debug_data *)file->private_data;
1059 for (i = 0; i < num_of_items; i++) {
1061 val = *((u8 *) d[i].addr);
1062 else if (d[i].size == 2)
1063 val = *((u16 *) d[i].addr);
1064 else if (d[i].size == 4)
1065 val = *((u32 *) d[i].addr);
1066 else if (d[i].size == 8)
1067 val = *((u64 *) d[i].addr);
1069 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
1072 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
1079 * @brief proc write function
1081 * @param f file pointer
1082 * @param buf pointer to data buffer
1083 * @param cnt data number to write
1084 * @param data data to write
1085 * @return number of data
1087 static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
1088 size_t cnt, loff_t *ppos)
1096 struct debug_data *d = (struct debug_data *)f->private_data;
1098 pdata = kmalloc(cnt, GFP_KERNEL);
1102 if (copy_from_user(pdata, buf, cnt)) {
1103 lbs_deb_debugfs("Copy from user failed\n");
1109 for (i = 0; i < num_of_items; i++) {
1111 p = strstr(p0, d[i].name);
1114 p1 = strchr(p, '\n');
1118 p2 = strchr(p, '=');
1122 r = simple_strtoul(p2, NULL, 0);
1124 *((u8 *) d[i].addr) = (u8) r;
1125 else if (d[i].size == 2)
1126 *((u16 *) d[i].addr) = (u16) r;
1127 else if (d[i].size == 4)
1128 *((u32 *) d[i].addr) = (u32) r;
1129 else if (d[i].size == 8)
1130 *((u64 *) d[i].addr) = (u64) r;
1136 return (ssize_t)cnt;
1139 static struct file_operations lbs_debug_fops = {
1140 .owner = THIS_MODULE,
1141 .open = open_file_generic,
1142 .write = lbs_debugfs_write,
1143 .read = lbs_debugfs_read,
1147 * @brief create debug proc file
1149 * @param priv pointer struct lbs_private
1150 * @param dev pointer net_device
1153 static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev)
1157 if (!priv->debugfs_dir)
1160 for (i = 0; i < num_of_items; i++)
1161 items[i].addr += (size_t) priv->adapter;
1163 priv->debugfs_debug = debugfs_create_file("debug", 0644,
1164 priv->debugfs_dir, &items[0],