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>
8 #include <net/lib80211.h>
16 static struct dentry
*lbs_dir
;
17 static char *szStates
[] = {
23 static void lbs_debug_init(struct lbs_private
*priv
);
26 static int open_file_generic(struct inode
*inode
, struct file
*file
)
28 file
->private_data
= inode
->i_private
;
32 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
33 size_t count
, loff_t
*ppos
)
38 static const size_t len
= PAGE_SIZE
;
40 static ssize_t
lbs_dev_info(struct file
*file
, char __user
*userbuf
,
41 size_t count
, loff_t
*ppos
)
43 struct lbs_private
*priv
= file
->private_data
;
45 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
46 char *buf
= (char *)addr
;
51 pos
+= snprintf(buf
+pos
, len
-pos
, "state = %s\n",
52 szStates
[priv
->connect_status
]);
53 pos
+= snprintf(buf
+pos
, len
-pos
, "region_code = %02x\n",
54 (u32
) priv
->regioncode
);
56 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
63 static ssize_t
lbs_getscantable(struct file
*file
, char __user
*userbuf
,
64 size_t count
, loff_t
*ppos
)
66 struct lbs_private
*priv
= file
->private_data
;
68 int numscansdone
= 0, res
;
69 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
70 char *buf
= (char *)addr
;
71 DECLARE_SSID_BUF(ssid
);
72 struct bss_descriptor
* iter_bss
;
76 pos
+= snprintf(buf
+pos
, len
-pos
,
77 "# | ch | rssi | bssid | cap | Qual | SSID \n");
79 mutex_lock(&priv
->lock
);
80 list_for_each_entry (iter_bss
, &priv
->network_list
, list
) {
81 u16 ibss
= (iter_bss
->capability
& WLAN_CAPABILITY_IBSS
);
82 u16 privacy
= (iter_bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
83 u16 spectrum_mgmt
= (iter_bss
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
);
85 pos
+= snprintf(buf
+pos
, len
-pos
, "%02u| %03d | %04d | %pM |",
86 numscansdone
, iter_bss
->channel
, iter_bss
->rssi
,
88 pos
+= snprintf(buf
+pos
, len
-pos
, " %04x-", iter_bss
->capability
);
89 pos
+= snprintf(buf
+pos
, len
-pos
, "%c%c%c |",
90 ibss
? 'A' : 'I', privacy
? 'P' : ' ',
91 spectrum_mgmt
? 'S' : ' ');
92 pos
+= snprintf(buf
+pos
, len
-pos
, " %04d |", SCAN_RSSI(iter_bss
->rssi
));
93 pos
+= snprintf(buf
+pos
, len
-pos
, " %s\n",
94 print_ssid(ssid
, iter_bss
->ssid
,
99 mutex_unlock(&priv
->lock
);
101 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
107 static ssize_t
lbs_sleepparams_write(struct file
*file
,
108 const char __user
*user_buf
, size_t count
,
111 struct lbs_private
*priv
= file
->private_data
;
112 ssize_t buf_size
, ret
;
113 struct sleep_params sp
;
114 int p1
, p2
, p3
, p4
, p5
, p6
;
115 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
116 char *buf
= (char *)addr
;
120 buf_size
= min(count
, len
- 1);
121 if (copy_from_user(buf
, user_buf
, buf_size
)) {
125 ret
= sscanf(buf
, "%d %d %d %d %d %d", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
);
132 sp
.sp_stabletime
= p3
;
133 sp
.sp_calcontrol
= p4
;
134 sp
.sp_extsleepclk
= p5
;
137 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_SET
, &sp
);
148 static ssize_t
lbs_sleepparams_read(struct file
*file
, char __user
*userbuf
,
149 size_t count
, loff_t
*ppos
)
151 struct lbs_private
*priv
= file
->private_data
;
154 struct sleep_params sp
;
155 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
156 char *buf
= (char *)addr
;
160 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_GET
, &sp
);
164 pos
+= snprintf(buf
, len
, "%d %d %d %d %d %d\n", sp
.sp_error
,
165 sp
.sp_offset
, sp
.sp_stabletime
,
166 sp
.sp_calcontrol
, sp
.sp_extsleepclk
,
169 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
177 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
178 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
179 * firmware. Here's an example:
180 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
181 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
182 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
184 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
185 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
186 * defined in mrvlietypes_thresholds
188 * This function searches in this TLV data chunk for a given TLV type
189 * and returns a pointer to the first data byte of the TLV, or to NULL
190 * if the TLV hasn't been found.
192 static void *lbs_tlv_find(uint16_t tlv_type
, const uint8_t *tlv
, uint16_t size
)
194 struct mrvl_ie_header
*tlv_h
;
199 tlv_h
= (struct mrvl_ie_header
*) tlv
;
202 if (tlv_h
->type
== cpu_to_le16(tlv_type
))
204 length
= le16_to_cpu(tlv_h
->len
) + sizeof(*tlv_h
);
212 static ssize_t
lbs_threshold_read(uint16_t tlv_type
, uint16_t event_mask
,
213 struct file
*file
, char __user
*userbuf
,
214 size_t count
, loff_t
*ppos
)
216 struct cmd_ds_802_11_subscribe_event
*subscribed
;
217 struct mrvl_ie_thresholds
*got
;
218 struct lbs_private
*priv
= file
->private_data
;
226 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
230 subscribed
= kzalloc(sizeof(*subscribed
), GFP_KERNEL
);
236 subscribed
->hdr
.size
= cpu_to_le16(sizeof(*subscribed
));
237 subscribed
->action
= cpu_to_le16(CMD_ACT_GET
);
239 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, subscribed
);
243 got
= lbs_tlv_find(tlv_type
, subscribed
->tlv
, sizeof(subscribed
->tlv
));
247 events
= le16_to_cpu(subscribed
->events
);
249 pos
+= snprintf(buf
, len
, "%d %d %d\n", value
, freq
,
250 !!(events
& event_mask
));
253 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
259 free_page((unsigned long)buf
);
264 static ssize_t
lbs_threshold_write(uint16_t tlv_type
, uint16_t event_mask
,
266 const char __user
*userbuf
, size_t count
,
269 struct cmd_ds_802_11_subscribe_event
*events
;
270 struct mrvl_ie_thresholds
*tlv
;
271 struct lbs_private
*priv
= file
->private_data
;
273 int value
, freq
, new_mask
;
278 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
282 buf_size
= min(count
, len
- 1);
283 if (copy_from_user(buf
, userbuf
, buf_size
)) {
287 ret
= sscanf(buf
, "%d %d %d", &value
, &freq
, &new_mask
);
292 events
= kzalloc(sizeof(*events
), GFP_KERNEL
);
298 events
->hdr
.size
= cpu_to_le16(sizeof(*events
));
299 events
->action
= cpu_to_le16(CMD_ACT_GET
);
301 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
305 curr_mask
= le16_to_cpu(events
->events
);
308 new_mask
= curr_mask
| event_mask
;
310 new_mask
= curr_mask
& ~event_mask
;
312 /* Now everything is set and we can send stuff down to the firmware */
314 tlv
= (void *)events
->tlv
;
316 events
->action
= cpu_to_le16(CMD_ACT_SET
);
317 events
->events
= cpu_to_le16(new_mask
);
318 tlv
->header
.type
= cpu_to_le16(tlv_type
);
319 tlv
->header
.len
= cpu_to_le16(sizeof(*tlv
) - sizeof(tlv
->header
));
321 if (tlv_type
!= TLV_TYPE_BCNMISS
)
324 /* The command header, the action, the event mask, and one TLV */
325 events
->hdr
.size
= cpu_to_le16(sizeof(events
->hdr
) + 4 + sizeof(*tlv
));
327 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
334 free_page((unsigned long)buf
);
339 static ssize_t
lbs_lowrssi_read(struct file
*file
, char __user
*userbuf
,
340 size_t count
, loff_t
*ppos
)
342 return lbs_threshold_read(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
343 file
, userbuf
, count
, ppos
);
347 static ssize_t
lbs_lowrssi_write(struct file
*file
, const char __user
*userbuf
,
348 size_t count
, loff_t
*ppos
)
350 return lbs_threshold_write(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
351 file
, userbuf
, count
, ppos
);
355 static ssize_t
lbs_lowsnr_read(struct file
*file
, char __user
*userbuf
,
356 size_t count
, loff_t
*ppos
)
358 return lbs_threshold_read(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
359 file
, userbuf
, count
, ppos
);
363 static ssize_t
lbs_lowsnr_write(struct file
*file
, const char __user
*userbuf
,
364 size_t count
, loff_t
*ppos
)
366 return lbs_threshold_write(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
367 file
, userbuf
, count
, ppos
);
371 static ssize_t
lbs_failcount_read(struct file
*file
, char __user
*userbuf
,
372 size_t count
, loff_t
*ppos
)
374 return lbs_threshold_read(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
375 file
, userbuf
, count
, ppos
);
379 static ssize_t
lbs_failcount_write(struct file
*file
, const char __user
*userbuf
,
380 size_t count
, loff_t
*ppos
)
382 return lbs_threshold_write(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
383 file
, userbuf
, count
, ppos
);
387 static ssize_t
lbs_highrssi_read(struct file
*file
, char __user
*userbuf
,
388 size_t count
, loff_t
*ppos
)
390 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
391 file
, userbuf
, count
, ppos
);
395 static ssize_t
lbs_highrssi_write(struct file
*file
, const char __user
*userbuf
,
396 size_t count
, loff_t
*ppos
)
398 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
399 file
, userbuf
, count
, ppos
);
403 static ssize_t
lbs_highsnr_read(struct file
*file
, char __user
*userbuf
,
404 size_t count
, loff_t
*ppos
)
406 return lbs_threshold_read(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
407 file
, userbuf
, count
, ppos
);
411 static ssize_t
lbs_highsnr_write(struct file
*file
, const char __user
*userbuf
,
412 size_t count
, loff_t
*ppos
)
414 return lbs_threshold_write(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
415 file
, userbuf
, count
, ppos
);
418 static ssize_t
lbs_bcnmiss_read(struct file
*file
, char __user
*userbuf
,
419 size_t count
, loff_t
*ppos
)
421 return lbs_threshold_read(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
422 file
, userbuf
, count
, ppos
);
426 static ssize_t
lbs_bcnmiss_write(struct file
*file
, const char __user
*userbuf
,
427 size_t count
, loff_t
*ppos
)
429 return lbs_threshold_write(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
430 file
, userbuf
, count
, ppos
);
435 static ssize_t
lbs_rdmac_read(struct file
*file
, char __user
*userbuf
,
436 size_t count
, loff_t
*ppos
)
438 struct lbs_private
*priv
= file
->private_data
;
439 struct lbs_offset_value offval
;
442 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
443 char *buf
= (char *)addr
;
447 offval
.offset
= priv
->mac_offset
;
450 ret
= lbs_prepare_and_send_command(priv
,
451 CMD_MAC_REG_ACCESS
, 0,
452 CMD_OPTION_WAITFORRSP
, 0, &offval
);
454 pos
+= snprintf(buf
+pos
, len
-pos
, "MAC[0x%x] = 0x%08x\n",
455 priv
->mac_offset
, priv
->offsetvalue
.value
);
457 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
462 static ssize_t
lbs_rdmac_write(struct file
*file
,
463 const char __user
*userbuf
,
464 size_t count
, loff_t
*ppos
)
466 struct lbs_private
*priv
= file
->private_data
;
467 ssize_t res
, buf_size
;
468 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
469 char *buf
= (char *)addr
;
473 buf_size
= min(count
, len
- 1);
474 if (copy_from_user(buf
, userbuf
, buf_size
)) {
478 priv
->mac_offset
= simple_strtoul((char *)buf
, NULL
, 16);
485 static ssize_t
lbs_wrmac_write(struct file
*file
,
486 const char __user
*userbuf
,
487 size_t count
, loff_t
*ppos
)
490 struct lbs_private
*priv
= file
->private_data
;
491 ssize_t res
, buf_size
;
493 struct lbs_offset_value offval
;
494 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
495 char *buf
= (char *)addr
;
499 buf_size
= min(count
, len
- 1);
500 if (copy_from_user(buf
, userbuf
, buf_size
)) {
504 res
= sscanf(buf
, "%x %x", &offset
, &value
);
510 offval
.offset
= offset
;
511 offval
.value
= value
;
512 res
= lbs_prepare_and_send_command(priv
,
513 CMD_MAC_REG_ACCESS
, 1,
514 CMD_OPTION_WAITFORRSP
, 0, &offval
);
523 static ssize_t
lbs_rdbbp_read(struct file
*file
, char __user
*userbuf
,
524 size_t count
, loff_t
*ppos
)
526 struct lbs_private
*priv
= file
->private_data
;
527 struct lbs_offset_value offval
;
530 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
531 char *buf
= (char *)addr
;
535 offval
.offset
= priv
->bbp_offset
;
538 ret
= lbs_prepare_and_send_command(priv
,
539 CMD_BBP_REG_ACCESS
, 0,
540 CMD_OPTION_WAITFORRSP
, 0, &offval
);
542 pos
+= snprintf(buf
+pos
, len
-pos
, "BBP[0x%x] = 0x%08x\n",
543 priv
->bbp_offset
, priv
->offsetvalue
.value
);
545 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
551 static ssize_t
lbs_rdbbp_write(struct file
*file
,
552 const char __user
*userbuf
,
553 size_t count
, loff_t
*ppos
)
555 struct lbs_private
*priv
= file
->private_data
;
556 ssize_t res
, buf_size
;
557 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
558 char *buf
= (char *)addr
;
562 buf_size
= min(count
, len
- 1);
563 if (copy_from_user(buf
, userbuf
, buf_size
)) {
567 priv
->bbp_offset
= simple_strtoul((char *)buf
, NULL
, 16);
574 static ssize_t
lbs_wrbbp_write(struct file
*file
,
575 const char __user
*userbuf
,
576 size_t count
, loff_t
*ppos
)
579 struct lbs_private
*priv
= file
->private_data
;
580 ssize_t res
, buf_size
;
582 struct lbs_offset_value offval
;
583 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
584 char *buf
= (char *)addr
;
588 buf_size
= min(count
, len
- 1);
589 if (copy_from_user(buf
, userbuf
, buf_size
)) {
593 res
= sscanf(buf
, "%x %x", &offset
, &value
);
599 offval
.offset
= offset
;
600 offval
.value
= value
;
601 res
= lbs_prepare_and_send_command(priv
,
602 CMD_BBP_REG_ACCESS
, 1,
603 CMD_OPTION_WAITFORRSP
, 0, &offval
);
612 static ssize_t
lbs_rdrf_read(struct file
*file
, char __user
*userbuf
,
613 size_t count
, loff_t
*ppos
)
615 struct lbs_private
*priv
= file
->private_data
;
616 struct lbs_offset_value offval
;
619 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
620 char *buf
= (char *)addr
;
624 offval
.offset
= priv
->rf_offset
;
627 ret
= lbs_prepare_and_send_command(priv
,
628 CMD_RF_REG_ACCESS
, 0,
629 CMD_OPTION_WAITFORRSP
, 0, &offval
);
631 pos
+= snprintf(buf
+pos
, len
-pos
, "RF[0x%x] = 0x%08x\n",
632 priv
->rf_offset
, priv
->offsetvalue
.value
);
634 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
640 static ssize_t
lbs_rdrf_write(struct file
*file
,
641 const char __user
*userbuf
,
642 size_t count
, loff_t
*ppos
)
644 struct lbs_private
*priv
= file
->private_data
;
645 ssize_t res
, buf_size
;
646 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
647 char *buf
= (char *)addr
;
651 buf_size
= min(count
, len
- 1);
652 if (copy_from_user(buf
, userbuf
, buf_size
)) {
656 priv
->rf_offset
= simple_strtoul(buf
, NULL
, 16);
663 static ssize_t
lbs_wrrf_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
;
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_RF_REG_ACCESS
, 1,
692 CMD_OPTION_WAITFORRSP
, 0, &offval
);
701 #define FOPS(fread, fwrite) { \
702 .owner = THIS_MODULE, \
703 .open = open_file_generic, \
708 struct lbs_debugfs_files
{
711 struct file_operations fops
;
714 static const struct lbs_debugfs_files debugfs_files
[] = {
715 { "info", 0444, FOPS(lbs_dev_info
, write_file_dummy
), },
716 { "getscantable", 0444, FOPS(lbs_getscantable
,
717 write_file_dummy
), },
718 { "sleepparams", 0644, FOPS(lbs_sleepparams_read
,
719 lbs_sleepparams_write
), },
722 static const struct lbs_debugfs_files debugfs_events_files
[] = {
723 {"low_rssi", 0644, FOPS(lbs_lowrssi_read
,
724 lbs_lowrssi_write
), },
725 {"low_snr", 0644, FOPS(lbs_lowsnr_read
,
726 lbs_lowsnr_write
), },
727 {"failure_count", 0644, FOPS(lbs_failcount_read
,
728 lbs_failcount_write
), },
729 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read
,
730 lbs_bcnmiss_write
), },
731 {"high_rssi", 0644, FOPS(lbs_highrssi_read
,
732 lbs_highrssi_write
), },
733 {"high_snr", 0644, FOPS(lbs_highsnr_read
,
734 lbs_highsnr_write
), },
737 static const struct lbs_debugfs_files debugfs_regs_files
[] = {
738 {"rdmac", 0644, FOPS(lbs_rdmac_read
, lbs_rdmac_write
), },
739 {"wrmac", 0600, FOPS(NULL
, lbs_wrmac_write
), },
740 {"rdbbp", 0644, FOPS(lbs_rdbbp_read
, lbs_rdbbp_write
), },
741 {"wrbbp", 0600, FOPS(NULL
, lbs_wrbbp_write
), },
742 {"rdrf", 0644, FOPS(lbs_rdrf_read
, lbs_rdrf_write
), },
743 {"wrrf", 0600, FOPS(NULL
, lbs_wrrf_write
), },
746 void lbs_debugfs_init(void)
749 lbs_dir
= debugfs_create_dir("lbs_wireless", NULL
);
754 void lbs_debugfs_remove(void)
757 debugfs_remove(lbs_dir
);
761 void lbs_debugfs_init_one(struct lbs_private
*priv
, struct net_device
*dev
)
764 const struct lbs_debugfs_files
*files
;
768 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, lbs_dir
);
769 if (!priv
->debugfs_dir
)
772 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
773 files
= &debugfs_files
[i
];
774 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
781 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
782 if (!priv
->events_dir
)
785 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
786 files
= &debugfs_events_files
[i
];
787 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
794 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
798 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
799 files
= &debugfs_regs_files
[i
];
800 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
808 lbs_debug_init(priv
);
814 void lbs_debugfs_remove_one(struct lbs_private
*priv
)
818 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
819 debugfs_remove(priv
->debugfs_regs_files
[i
]);
821 debugfs_remove(priv
->regs_dir
);
823 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
824 debugfs_remove(priv
->debugfs_events_files
[i
]);
826 debugfs_remove(priv
->events_dir
);
828 debugfs_remove(priv
->debugfs_debug
);
830 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
831 debugfs_remove(priv
->debugfs_files
[i
]);
832 debugfs_remove(priv
->debugfs_dir
);
841 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
842 #define item_addr(n) (offsetof(struct lbs_private, n))
851 /* To debug any member of struct lbs_private, simply add one line here.
853 static struct debug_data items
[] = {
854 {"psmode", item_size(psmode
), item_addr(psmode
)},
855 {"psstate", item_size(psstate
), item_addr(psstate
)},
858 static int num_of_items
= ARRAY_SIZE(items
);
861 * @brief proc read function
863 * @param page pointer to buffer
864 * @param s read data starting position
867 * @param eof end of file flag
868 * @param data data to output
869 * @return number of output data
871 static ssize_t
lbs_debugfs_read(struct file
*file
, char __user
*userbuf
,
872 size_t count
, loff_t
*ppos
)
879 struct debug_data
*d
;
880 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
881 char *buf
= (char *)addr
;
887 d
= (struct debug_data
*)file
->private_data
;
889 for (i
= 0; i
< num_of_items
; i
++) {
891 val
= *((u8
*) d
[i
].addr
);
892 else if (d
[i
].size
== 2)
893 val
= *((u16
*) d
[i
].addr
);
894 else if (d
[i
].size
== 4)
895 val
= *((u32
*) d
[i
].addr
);
896 else if (d
[i
].size
== 8)
897 val
= *((u64
*) d
[i
].addr
);
899 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
902 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
909 * @brief proc write function
911 * @param f file pointer
912 * @param buf pointer to data buffer
913 * @param cnt data number to write
914 * @param data data to write
915 * @return number of data
917 static ssize_t
lbs_debugfs_write(struct file
*f
, const char __user
*buf
,
918 size_t cnt
, loff_t
*ppos
)
926 struct debug_data
*d
= (struct debug_data
*)f
->private_data
;
928 pdata
= kmalloc(cnt
, GFP_KERNEL
);
932 if (copy_from_user(pdata
, buf
, cnt
)) {
933 lbs_deb_debugfs("Copy from user failed\n");
939 for (i
= 0; i
< num_of_items
; i
++) {
941 p
= strstr(p0
, d
[i
].name
);
944 p1
= strchr(p
, '\n');
952 r
= simple_strtoul(p2
, NULL
, 0);
954 *((u8
*) d
[i
].addr
) = (u8
) r
;
955 else if (d
[i
].size
== 2)
956 *((u16
*) d
[i
].addr
) = (u16
) r
;
957 else if (d
[i
].size
== 4)
958 *((u32
*) d
[i
].addr
) = (u32
) r
;
959 else if (d
[i
].size
== 8)
960 *((u64
*) d
[i
].addr
) = (u64
) r
;
969 static const struct file_operations lbs_debug_fops
= {
970 .owner
= THIS_MODULE
,
971 .open
= open_file_generic
,
972 .write
= lbs_debugfs_write
,
973 .read
= lbs_debugfs_read
,
977 * @brief create debug proc file
979 * @param priv pointer struct lbs_private
980 * @param dev pointer net_device
983 static void lbs_debug_init(struct lbs_private
*priv
)
987 if (!priv
->debugfs_dir
)
990 for (i
= 0; i
< num_of_items
; i
++)
991 items
[i
].addr
+= (size_t) priv
;
993 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
994 priv
->debugfs_dir
, &items
[0],