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
;
49 pos
+= snprintf(buf
+pos
, len
-pos
, "state = %s\n",
50 szStates
[priv
->connect_status
]);
51 pos
+= snprintf(buf
+pos
, len
-pos
, "region_code = %02x\n",
52 (u32
) priv
->regioncode
);
54 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
61 static ssize_t
lbs_getscantable(struct file
*file
, char __user
*userbuf
,
62 size_t count
, loff_t
*ppos
)
64 struct lbs_private
*priv
= file
->private_data
;
66 int numscansdone
= 0, res
;
67 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
68 char *buf
= (char *)addr
;
69 DECLARE_SSID_BUF(ssid
);
70 struct bss_descriptor
* iter_bss
;
72 pos
+= snprintf(buf
+pos
, len
-pos
,
73 "# | ch | rssi | bssid | cap | Qual | SSID \n");
75 mutex_lock(&priv
->lock
);
76 list_for_each_entry (iter_bss
, &priv
->network_list
, list
) {
77 u16 ibss
= (iter_bss
->capability
& WLAN_CAPABILITY_IBSS
);
78 u16 privacy
= (iter_bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
79 u16 spectrum_mgmt
= (iter_bss
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
);
81 pos
+= snprintf(buf
+pos
, len
-pos
, "%02u| %03d | %04d | %pM |",
82 numscansdone
, iter_bss
->channel
, iter_bss
->rssi
,
84 pos
+= snprintf(buf
+pos
, len
-pos
, " %04x-", iter_bss
->capability
);
85 pos
+= snprintf(buf
+pos
, len
-pos
, "%c%c%c |",
86 ibss
? 'A' : 'I', privacy
? 'P' : ' ',
87 spectrum_mgmt
? 'S' : ' ');
88 pos
+= snprintf(buf
+pos
, len
-pos
, " %04d |", SCAN_RSSI(iter_bss
->rssi
));
89 pos
+= snprintf(buf
+pos
, len
-pos
, " %s\n",
90 print_ssid(ssid
, iter_bss
->ssid
,
95 mutex_unlock(&priv
->lock
);
97 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
103 static ssize_t
lbs_sleepparams_write(struct file
*file
,
104 const char __user
*user_buf
, size_t count
,
107 struct lbs_private
*priv
= file
->private_data
;
108 ssize_t buf_size
, ret
;
109 struct sleep_params sp
;
110 int p1
, p2
, p3
, p4
, p5
, p6
;
111 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
112 char *buf
= (char *)addr
;
114 buf_size
= min(count
, len
- 1);
115 if (copy_from_user(buf
, user_buf
, buf_size
)) {
119 ret
= sscanf(buf
, "%d %d %d %d %d %d", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
);
126 sp
.sp_stabletime
= p3
;
127 sp
.sp_calcontrol
= p4
;
128 sp
.sp_extsleepclk
= p5
;
131 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_SET
, &sp
);
142 static ssize_t
lbs_sleepparams_read(struct file
*file
, char __user
*userbuf
,
143 size_t count
, loff_t
*ppos
)
145 struct lbs_private
*priv
= file
->private_data
;
148 struct sleep_params sp
;
149 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
150 char *buf
= (char *)addr
;
152 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_GET
, &sp
);
156 pos
+= snprintf(buf
, len
, "%d %d %d %d %d %d\n", sp
.sp_error
,
157 sp
.sp_offset
, sp
.sp_stabletime
,
158 sp
.sp_calcontrol
, sp
.sp_extsleepclk
,
161 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
169 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
170 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
171 * firmware. Here's an example:
172 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
173 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
174 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
176 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
177 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
178 * defined in mrvlietypes_thresholds
180 * This function searches in this TLV data chunk for a given TLV type
181 * and returns a pointer to the first data byte of the TLV, or to NULL
182 * if the TLV hasn't been found.
184 static void *lbs_tlv_find(uint16_t tlv_type
, const uint8_t *tlv
, uint16_t size
)
186 struct mrvlietypesheader
*tlv_h
;
191 tlv_h
= (struct mrvlietypesheader
*) tlv
;
194 if (tlv_h
->type
== cpu_to_le16(tlv_type
))
196 length
= le16_to_cpu(tlv_h
->len
) + sizeof(*tlv_h
);
204 static ssize_t
lbs_threshold_read(uint16_t tlv_type
, uint16_t event_mask
,
205 struct file
*file
, char __user
*userbuf
,
206 size_t count
, loff_t
*ppos
)
208 struct cmd_ds_802_11_subscribe_event
*subscribed
;
209 struct mrvlietypes_thresholds
*got
;
210 struct lbs_private
*priv
= file
->private_data
;
218 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
222 subscribed
= kzalloc(sizeof(*subscribed
), GFP_KERNEL
);
228 subscribed
->hdr
.size
= cpu_to_le16(sizeof(*subscribed
));
229 subscribed
->action
= cpu_to_le16(CMD_ACT_GET
);
231 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, subscribed
);
235 got
= lbs_tlv_find(tlv_type
, subscribed
->tlv
, sizeof(subscribed
->tlv
));
239 events
= le16_to_cpu(subscribed
->events
);
241 pos
+= snprintf(buf
, len
, "%d %d %d\n", value
, freq
,
242 !!(events
& event_mask
));
245 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
251 free_page((unsigned long)buf
);
256 static ssize_t
lbs_threshold_write(uint16_t tlv_type
, uint16_t event_mask
,
258 const char __user
*userbuf
, size_t count
,
261 struct cmd_ds_802_11_subscribe_event
*events
;
262 struct mrvlietypes_thresholds
*tlv
;
263 struct lbs_private
*priv
= file
->private_data
;
265 int value
, freq
, new_mask
;
270 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
274 buf_size
= min(count
, len
- 1);
275 if (copy_from_user(buf
, userbuf
, buf_size
)) {
279 ret
= sscanf(buf
, "%d %d %d", &value
, &freq
, &new_mask
);
284 events
= kzalloc(sizeof(*events
), GFP_KERNEL
);
290 events
->hdr
.size
= cpu_to_le16(sizeof(*events
));
291 events
->action
= cpu_to_le16(CMD_ACT_GET
);
293 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
297 curr_mask
= le16_to_cpu(events
->events
);
300 new_mask
= curr_mask
| event_mask
;
302 new_mask
= curr_mask
& ~event_mask
;
304 /* Now everything is set and we can send stuff down to the firmware */
306 tlv
= (void *)events
->tlv
;
308 events
->action
= cpu_to_le16(CMD_ACT_SET
);
309 events
->events
= cpu_to_le16(new_mask
);
310 tlv
->header
.type
= cpu_to_le16(tlv_type
);
311 tlv
->header
.len
= cpu_to_le16(sizeof(*tlv
) - sizeof(tlv
->header
));
313 if (tlv_type
!= TLV_TYPE_BCNMISS
)
316 /* The command header, the action, the event mask, and one TLV */
317 events
->hdr
.size
= cpu_to_le16(sizeof(events
->hdr
) + 4 + sizeof(*tlv
));
319 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
326 free_page((unsigned long)buf
);
331 static ssize_t
lbs_lowrssi_read(struct file
*file
, char __user
*userbuf
,
332 size_t count
, loff_t
*ppos
)
334 return lbs_threshold_read(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
335 file
, userbuf
, count
, ppos
);
339 static ssize_t
lbs_lowrssi_write(struct file
*file
, const char __user
*userbuf
,
340 size_t count
, loff_t
*ppos
)
342 return lbs_threshold_write(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
343 file
, userbuf
, count
, ppos
);
347 static ssize_t
lbs_lowsnr_read(struct file
*file
, char __user
*userbuf
,
348 size_t count
, loff_t
*ppos
)
350 return lbs_threshold_read(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
351 file
, userbuf
, count
, ppos
);
355 static ssize_t
lbs_lowsnr_write(struct file
*file
, const char __user
*userbuf
,
356 size_t count
, loff_t
*ppos
)
358 return lbs_threshold_write(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
359 file
, userbuf
, count
, ppos
);
363 static ssize_t
lbs_failcount_read(struct file
*file
, char __user
*userbuf
,
364 size_t count
, loff_t
*ppos
)
366 return lbs_threshold_read(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
367 file
, userbuf
, count
, ppos
);
371 static ssize_t
lbs_failcount_write(struct file
*file
, const char __user
*userbuf
,
372 size_t count
, loff_t
*ppos
)
374 return lbs_threshold_write(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
375 file
, userbuf
, count
, ppos
);
379 static ssize_t
lbs_highrssi_read(struct file
*file
, char __user
*userbuf
,
380 size_t count
, loff_t
*ppos
)
382 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
383 file
, userbuf
, count
, ppos
);
387 static ssize_t
lbs_highrssi_write(struct file
*file
, const char __user
*userbuf
,
388 size_t count
, loff_t
*ppos
)
390 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
391 file
, userbuf
, count
, ppos
);
395 static ssize_t
lbs_highsnr_read(struct file
*file
, char __user
*userbuf
,
396 size_t count
, loff_t
*ppos
)
398 return lbs_threshold_read(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
399 file
, userbuf
, count
, ppos
);
403 static ssize_t
lbs_highsnr_write(struct file
*file
, const char __user
*userbuf
,
404 size_t count
, loff_t
*ppos
)
406 return lbs_threshold_write(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
407 file
, userbuf
, count
, ppos
);
410 static ssize_t
lbs_bcnmiss_read(struct file
*file
, char __user
*userbuf
,
411 size_t count
, loff_t
*ppos
)
413 return lbs_threshold_read(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
414 file
, userbuf
, count
, ppos
);
418 static ssize_t
lbs_bcnmiss_write(struct file
*file
, const char __user
*userbuf
,
419 size_t count
, loff_t
*ppos
)
421 return lbs_threshold_write(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
422 file
, userbuf
, count
, ppos
);
427 static ssize_t
lbs_rdmac_read(struct file
*file
, char __user
*userbuf
,
428 size_t count
, loff_t
*ppos
)
430 struct lbs_private
*priv
= file
->private_data
;
431 struct lbs_offset_value offval
;
434 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
435 char *buf
= (char *)addr
;
437 offval
.offset
= priv
->mac_offset
;
440 ret
= lbs_prepare_and_send_command(priv
,
441 CMD_MAC_REG_ACCESS
, 0,
442 CMD_OPTION_WAITFORRSP
, 0, &offval
);
444 pos
+= snprintf(buf
+pos
, len
-pos
, "MAC[0x%x] = 0x%08x\n",
445 priv
->mac_offset
, priv
->offsetvalue
.value
);
447 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
452 static ssize_t
lbs_rdmac_write(struct file
*file
,
453 const char __user
*userbuf
,
454 size_t count
, loff_t
*ppos
)
456 struct lbs_private
*priv
= file
->private_data
;
457 ssize_t res
, buf_size
;
458 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
459 char *buf
= (char *)addr
;
461 buf_size
= min(count
, len
- 1);
462 if (copy_from_user(buf
, userbuf
, buf_size
)) {
466 priv
->mac_offset
= simple_strtoul((char *)buf
, NULL
, 16);
473 static ssize_t
lbs_wrmac_write(struct file
*file
,
474 const char __user
*userbuf
,
475 size_t count
, loff_t
*ppos
)
478 struct lbs_private
*priv
= file
->private_data
;
479 ssize_t res
, buf_size
;
481 struct lbs_offset_value offval
;
482 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
483 char *buf
= (char *)addr
;
485 buf_size
= min(count
, len
- 1);
486 if (copy_from_user(buf
, userbuf
, buf_size
)) {
490 res
= sscanf(buf
, "%x %x", &offset
, &value
);
496 offval
.offset
= offset
;
497 offval
.value
= value
;
498 res
= lbs_prepare_and_send_command(priv
,
499 CMD_MAC_REG_ACCESS
, 1,
500 CMD_OPTION_WAITFORRSP
, 0, &offval
);
509 static ssize_t
lbs_rdbbp_read(struct file
*file
, char __user
*userbuf
,
510 size_t count
, loff_t
*ppos
)
512 struct lbs_private
*priv
= file
->private_data
;
513 struct lbs_offset_value offval
;
516 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
517 char *buf
= (char *)addr
;
519 offval
.offset
= priv
->bbp_offset
;
522 ret
= lbs_prepare_and_send_command(priv
,
523 CMD_BBP_REG_ACCESS
, 0,
524 CMD_OPTION_WAITFORRSP
, 0, &offval
);
526 pos
+= snprintf(buf
+pos
, len
-pos
, "BBP[0x%x] = 0x%08x\n",
527 priv
->bbp_offset
, priv
->offsetvalue
.value
);
529 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
535 static ssize_t
lbs_rdbbp_write(struct file
*file
,
536 const char __user
*userbuf
,
537 size_t count
, loff_t
*ppos
)
539 struct lbs_private
*priv
= file
->private_data
;
540 ssize_t res
, buf_size
;
541 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
542 char *buf
= (char *)addr
;
544 buf_size
= min(count
, len
- 1);
545 if (copy_from_user(buf
, userbuf
, buf_size
)) {
549 priv
->bbp_offset
= simple_strtoul((char *)buf
, NULL
, 16);
556 static ssize_t
lbs_wrbbp_write(struct file
*file
,
557 const char __user
*userbuf
,
558 size_t count
, loff_t
*ppos
)
561 struct lbs_private
*priv
= file
->private_data
;
562 ssize_t res
, buf_size
;
564 struct lbs_offset_value offval
;
565 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
566 char *buf
= (char *)addr
;
568 buf_size
= min(count
, len
- 1);
569 if (copy_from_user(buf
, userbuf
, buf_size
)) {
573 res
= sscanf(buf
, "%x %x", &offset
, &value
);
579 offval
.offset
= offset
;
580 offval
.value
= value
;
581 res
= lbs_prepare_and_send_command(priv
,
582 CMD_BBP_REG_ACCESS
, 1,
583 CMD_OPTION_WAITFORRSP
, 0, &offval
);
592 static ssize_t
lbs_rdrf_read(struct file
*file
, char __user
*userbuf
,
593 size_t count
, loff_t
*ppos
)
595 struct lbs_private
*priv
= file
->private_data
;
596 struct lbs_offset_value offval
;
599 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
600 char *buf
= (char *)addr
;
602 offval
.offset
= priv
->rf_offset
;
605 ret
= lbs_prepare_and_send_command(priv
,
606 CMD_RF_REG_ACCESS
, 0,
607 CMD_OPTION_WAITFORRSP
, 0, &offval
);
609 pos
+= snprintf(buf
+pos
, len
-pos
, "RF[0x%x] = 0x%08x\n",
610 priv
->rf_offset
, priv
->offsetvalue
.value
);
612 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
618 static ssize_t
lbs_rdrf_write(struct file
*file
,
619 const char __user
*userbuf
,
620 size_t count
, loff_t
*ppos
)
622 struct lbs_private
*priv
= file
->private_data
;
623 ssize_t res
, buf_size
;
624 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
625 char *buf
= (char *)addr
;
627 buf_size
= min(count
, len
- 1);
628 if (copy_from_user(buf
, userbuf
, buf_size
)) {
632 priv
->rf_offset
= simple_strtoul((char *)buf
, NULL
, 16);
639 static ssize_t
lbs_wrrf_write(struct file
*file
,
640 const char __user
*userbuf
,
641 size_t count
, loff_t
*ppos
)
644 struct lbs_private
*priv
= file
->private_data
;
645 ssize_t res
, buf_size
;
647 struct lbs_offset_value offval
;
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 res
= sscanf(buf
, "%x %x", &offset
, &value
);
662 offval
.offset
= offset
;
663 offval
.value
= value
;
664 res
= lbs_prepare_and_send_command(priv
,
665 CMD_RF_REG_ACCESS
, 1,
666 CMD_OPTION_WAITFORRSP
, 0, &offval
);
675 #define FOPS(fread, fwrite) { \
676 .owner = THIS_MODULE, \
677 .open = open_file_generic, \
682 struct lbs_debugfs_files
{
685 struct file_operations fops
;
688 static struct lbs_debugfs_files debugfs_files
[] = {
689 { "info", 0444, FOPS(lbs_dev_info
, write_file_dummy
), },
690 { "getscantable", 0444, FOPS(lbs_getscantable
,
691 write_file_dummy
), },
692 { "sleepparams", 0644, FOPS(lbs_sleepparams_read
,
693 lbs_sleepparams_write
), },
696 static struct lbs_debugfs_files debugfs_events_files
[] = {
697 {"low_rssi", 0644, FOPS(lbs_lowrssi_read
,
698 lbs_lowrssi_write
), },
699 {"low_snr", 0644, FOPS(lbs_lowsnr_read
,
700 lbs_lowsnr_write
), },
701 {"failure_count", 0644, FOPS(lbs_failcount_read
,
702 lbs_failcount_write
), },
703 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read
,
704 lbs_bcnmiss_write
), },
705 {"high_rssi", 0644, FOPS(lbs_highrssi_read
,
706 lbs_highrssi_write
), },
707 {"high_snr", 0644, FOPS(lbs_highsnr_read
,
708 lbs_highsnr_write
), },
711 static struct lbs_debugfs_files debugfs_regs_files
[] = {
712 {"rdmac", 0644, FOPS(lbs_rdmac_read
, lbs_rdmac_write
), },
713 {"wrmac", 0600, FOPS(NULL
, lbs_wrmac_write
), },
714 {"rdbbp", 0644, FOPS(lbs_rdbbp_read
, lbs_rdbbp_write
), },
715 {"wrbbp", 0600, FOPS(NULL
, lbs_wrbbp_write
), },
716 {"rdrf", 0644, FOPS(lbs_rdrf_read
, lbs_rdrf_write
), },
717 {"wrrf", 0600, FOPS(NULL
, lbs_wrrf_write
), },
720 void lbs_debugfs_init(void)
723 lbs_dir
= debugfs_create_dir("lbs_wireless", NULL
);
728 void lbs_debugfs_remove(void)
731 debugfs_remove(lbs_dir
);
735 void lbs_debugfs_init_one(struct lbs_private
*priv
, struct net_device
*dev
)
738 struct lbs_debugfs_files
*files
;
742 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, lbs_dir
);
743 if (!priv
->debugfs_dir
)
746 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
747 files
= &debugfs_files
[i
];
748 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
755 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
756 if (!priv
->events_dir
)
759 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
760 files
= &debugfs_events_files
[i
];
761 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
768 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
772 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
773 files
= &debugfs_regs_files
[i
];
774 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
782 lbs_debug_init(priv
);
788 void lbs_debugfs_remove_one(struct lbs_private
*priv
)
792 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
793 debugfs_remove(priv
->debugfs_regs_files
[i
]);
795 debugfs_remove(priv
->regs_dir
);
797 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
798 debugfs_remove(priv
->debugfs_events_files
[i
]);
800 debugfs_remove(priv
->events_dir
);
802 debugfs_remove(priv
->debugfs_debug
);
804 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
805 debugfs_remove(priv
->debugfs_files
[i
]);
806 debugfs_remove(priv
->debugfs_dir
);
815 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
816 #define item_addr(n) (offsetof(struct lbs_private, n))
825 /* To debug any member of struct lbs_private, simply add one line here.
827 static struct debug_data items
[] = {
828 {"psmode", item_size(psmode
), item_addr(psmode
)},
829 {"psstate", item_size(psstate
), item_addr(psstate
)},
832 static int num_of_items
= ARRAY_SIZE(items
);
835 * @brief proc read function
837 * @param page pointer to buffer
838 * @param s read data starting position
841 * @param eof end of file flag
842 * @param data data to output
843 * @return number of output data
845 static ssize_t
lbs_debugfs_read(struct file
*file
, char __user
*userbuf
,
846 size_t count
, loff_t
*ppos
)
853 struct debug_data
*d
;
854 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
855 char *buf
= (char *)addr
;
859 d
= (struct debug_data
*)file
->private_data
;
861 for (i
= 0; i
< num_of_items
; i
++) {
863 val
= *((u8
*) d
[i
].addr
);
864 else if (d
[i
].size
== 2)
865 val
= *((u16
*) d
[i
].addr
);
866 else if (d
[i
].size
== 4)
867 val
= *((u32
*) d
[i
].addr
);
868 else if (d
[i
].size
== 8)
869 val
= *((u64
*) d
[i
].addr
);
871 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
874 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
881 * @brief proc write function
883 * @param f file pointer
884 * @param buf pointer to data buffer
885 * @param cnt data number to write
886 * @param data data to write
887 * @return number of data
889 static ssize_t
lbs_debugfs_write(struct file
*f
, const char __user
*buf
,
890 size_t cnt
, loff_t
*ppos
)
898 struct debug_data
*d
= (struct debug_data
*)f
->private_data
;
900 pdata
= kmalloc(cnt
, GFP_KERNEL
);
904 if (copy_from_user(pdata
, buf
, cnt
)) {
905 lbs_deb_debugfs("Copy from user failed\n");
911 for (i
= 0; i
< num_of_items
; i
++) {
913 p
= strstr(p0
, d
[i
].name
);
916 p1
= strchr(p
, '\n');
924 r
= simple_strtoul(p2
, NULL
, 0);
926 *((u8
*) d
[i
].addr
) = (u8
) r
;
927 else if (d
[i
].size
== 2)
928 *((u16
*) d
[i
].addr
) = (u16
) r
;
929 else if (d
[i
].size
== 4)
930 *((u32
*) d
[i
].addr
) = (u32
) r
;
931 else if (d
[i
].size
== 8)
932 *((u64
*) d
[i
].addr
) = (u64
) r
;
941 static struct file_operations lbs_debug_fops
= {
942 .owner
= THIS_MODULE
,
943 .open
= open_file_generic
,
944 .write
= lbs_debugfs_write
,
945 .read
= lbs_debugfs_read
,
949 * @brief create debug proc file
951 * @param priv pointer struct lbs_private
952 * @param dev pointer net_device
955 static void lbs_debug_init(struct lbs_private
*priv
)
959 if (!priv
->debugfs_dir
)
962 for (i
= 0; i
< num_of_items
; i
++)
963 items
[i
].addr
+= (size_t) priv
;
965 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
966 priv
->debugfs_dir
, &items
[0],