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>
15 static struct dentry
*lbs_dir
;
16 static char *szStates
[] = {
22 static void lbs_debug_init(struct lbs_private
*priv
);
25 static int open_file_generic(struct inode
*inode
, struct file
*file
)
27 file
->private_data
= inode
->i_private
;
31 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
32 size_t count
, loff_t
*ppos
)
37 static const size_t len
= PAGE_SIZE
;
39 static ssize_t
lbs_dev_info(struct file
*file
, char __user
*userbuf
,
40 size_t count
, loff_t
*ppos
)
42 struct lbs_private
*priv
= file
->private_data
;
44 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
45 char *buf
= (char *)addr
;
48 pos
+= snprintf(buf
+pos
, len
-pos
, "state = %s\n",
49 szStates
[priv
->connect_status
]);
50 pos
+= snprintf(buf
+pos
, len
-pos
, "region_code = %02x\n",
51 (u32
) priv
->regioncode
);
53 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
60 static ssize_t
lbs_getscantable(struct file
*file
, char __user
*userbuf
,
61 size_t count
, loff_t
*ppos
)
63 struct lbs_private
*priv
= file
->private_data
;
65 int numscansdone
= 0, res
;
66 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
67 char *buf
= (char *)addr
;
69 struct bss_descriptor
* iter_bss
;
71 pos
+= snprintf(buf
+pos
, len
-pos
,
72 "# | ch | rssi | bssid | cap | Qual | SSID \n");
74 mutex_lock(&priv
->lock
);
75 list_for_each_entry (iter_bss
, &priv
->network_list
, list
) {
76 u16 ibss
= (iter_bss
->capability
& WLAN_CAPABILITY_IBSS
);
77 u16 privacy
= (iter_bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
78 u16 spectrum_mgmt
= (iter_bss
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
);
80 pos
+= snprintf(buf
+pos
, len
-pos
,
81 "%02u| %03d | %04d | %s |",
82 numscansdone
, iter_bss
->channel
, iter_bss
->rssi
,
83 print_mac(mac
, iter_bss
->bssid
));
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 escape_essid(iter_bss
->ssid
, iter_bss
->ssid_len
));
94 mutex_unlock(&priv
->lock
);
96 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
102 static ssize_t
lbs_sleepparams_write(struct file
*file
,
103 const char __user
*user_buf
, size_t count
,
106 struct lbs_private
*priv
= file
->private_data
;
107 ssize_t buf_size
, ret
;
108 struct sleep_params sp
;
109 int p1
, p2
, p3
, p4
, p5
, p6
;
110 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
111 char *buf
= (char *)addr
;
113 buf_size
= min(count
, len
- 1);
114 if (copy_from_user(buf
, user_buf
, buf_size
)) {
118 ret
= sscanf(buf
, "%d %d %d %d %d %d", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
);
125 sp
.sp_stabletime
= p3
;
126 sp
.sp_calcontrol
= p4
;
127 sp
.sp_extsleepclk
= p5
;
130 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_SET
, &sp
);
141 static ssize_t
lbs_sleepparams_read(struct file
*file
, char __user
*userbuf
,
142 size_t count
, loff_t
*ppos
)
144 struct lbs_private
*priv
= file
->private_data
;
147 struct sleep_params sp
;
148 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
149 char *buf
= (char *)addr
;
151 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_GET
, &sp
);
155 pos
+= snprintf(buf
, len
, "%d %d %d %d %d %d\n", sp
.sp_error
,
156 sp
.sp_offset
, sp
.sp_stabletime
,
157 sp
.sp_calcontrol
, sp
.sp_extsleepclk
,
160 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
168 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
169 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
170 * firmware. Here's an example:
171 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
172 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
173 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
175 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
176 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
177 * defined in mrvlietypes_thresholds
179 * This function searches in this TLV data chunk for a given TLV type
180 * and returns a pointer to the first data byte of the TLV, or to NULL
181 * if the TLV hasn't been found.
183 static void *lbs_tlv_find(uint16_t tlv_type
, const uint8_t *tlv
, uint16_t size
)
185 struct mrvlietypesheader
*tlv_h
;
190 tlv_h
= (struct mrvlietypesheader
*) tlv
;
193 if (tlv_h
->type
== cpu_to_le16(tlv_type
))
195 length
= le16_to_cpu(tlv_h
->len
) + sizeof(*tlv_h
);
203 static ssize_t
lbs_threshold_read(uint16_t tlv_type
, uint16_t event_mask
,
204 struct file
*file
, char __user
*userbuf
,
205 size_t count
, loff_t
*ppos
)
207 struct cmd_ds_802_11_subscribe_event
*subscribed
;
208 struct mrvlietypes_thresholds
*got
;
209 struct lbs_private
*priv
= file
->private_data
;
217 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
221 subscribed
= kzalloc(sizeof(*subscribed
), GFP_KERNEL
);
227 subscribed
->hdr
.size
= cpu_to_le16(sizeof(*subscribed
));
228 subscribed
->action
= cpu_to_le16(CMD_ACT_GET
);
230 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, subscribed
);
234 got
= lbs_tlv_find(tlv_type
, subscribed
->tlv
, sizeof(subscribed
->tlv
));
238 events
= le16_to_cpu(subscribed
->events
);
240 pos
+= snprintf(buf
, len
, "%d %d %d\n", value
, freq
,
241 !!(events
& event_mask
));
244 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
250 free_page((unsigned long)buf
);
255 static ssize_t
lbs_threshold_write(uint16_t tlv_type
, uint16_t event_mask
,
257 const char __user
*userbuf
, size_t count
,
260 struct cmd_ds_802_11_subscribe_event
*events
;
261 struct mrvlietypes_thresholds
*tlv
;
262 struct lbs_private
*priv
= file
->private_data
;
264 int value
, freq
, new_mask
;
269 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
273 buf_size
= min(count
, len
- 1);
274 if (copy_from_user(buf
, userbuf
, buf_size
)) {
278 ret
= sscanf(buf
, "%d %d %d", &value
, &freq
, &new_mask
);
283 events
= kzalloc(sizeof(*events
), GFP_KERNEL
);
289 events
->hdr
.size
= cpu_to_le16(sizeof(*events
));
290 events
->action
= cpu_to_le16(CMD_ACT_GET
);
292 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
296 curr_mask
= le16_to_cpu(events
->events
);
299 new_mask
= curr_mask
| event_mask
;
301 new_mask
= curr_mask
& ~event_mask
;
303 /* Now everything is set and we can send stuff down to the firmware */
305 tlv
= (void *)events
->tlv
;
307 events
->action
= cpu_to_le16(CMD_ACT_SET
);
308 events
->events
= cpu_to_le16(new_mask
);
309 tlv
->header
.type
= cpu_to_le16(tlv_type
);
310 tlv
->header
.len
= cpu_to_le16(sizeof(*tlv
) - sizeof(tlv
->header
));
312 if (tlv_type
!= TLV_TYPE_BCNMISS
)
315 /* The command header, the action, the event mask, and one TLV */
316 events
->hdr
.size
= cpu_to_le16(sizeof(events
->hdr
) + 4 + sizeof(*tlv
));
318 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
325 free_page((unsigned long)buf
);
330 static ssize_t
lbs_lowrssi_read(struct file
*file
, char __user
*userbuf
,
331 size_t count
, loff_t
*ppos
)
333 return lbs_threshold_read(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
334 file
, userbuf
, count
, ppos
);
338 static ssize_t
lbs_lowrssi_write(struct file
*file
, const char __user
*userbuf
,
339 size_t count
, loff_t
*ppos
)
341 return lbs_threshold_write(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
342 file
, userbuf
, count
, ppos
);
346 static ssize_t
lbs_lowsnr_read(struct file
*file
, char __user
*userbuf
,
347 size_t count
, loff_t
*ppos
)
349 return lbs_threshold_read(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
350 file
, userbuf
, count
, ppos
);
354 static ssize_t
lbs_lowsnr_write(struct file
*file
, const char __user
*userbuf
,
355 size_t count
, loff_t
*ppos
)
357 return lbs_threshold_write(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
358 file
, userbuf
, count
, ppos
);
362 static ssize_t
lbs_failcount_read(struct file
*file
, char __user
*userbuf
,
363 size_t count
, loff_t
*ppos
)
365 return lbs_threshold_read(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
366 file
, userbuf
, count
, ppos
);
370 static ssize_t
lbs_failcount_write(struct file
*file
, const char __user
*userbuf
,
371 size_t count
, loff_t
*ppos
)
373 return lbs_threshold_write(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
374 file
, userbuf
, count
, ppos
);
378 static ssize_t
lbs_highrssi_read(struct file
*file
, char __user
*userbuf
,
379 size_t count
, loff_t
*ppos
)
381 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
382 file
, userbuf
, count
, ppos
);
386 static ssize_t
lbs_highrssi_write(struct file
*file
, const char __user
*userbuf
,
387 size_t count
, loff_t
*ppos
)
389 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
390 file
, userbuf
, count
, ppos
);
394 static ssize_t
lbs_highsnr_read(struct file
*file
, char __user
*userbuf
,
395 size_t count
, loff_t
*ppos
)
397 return lbs_threshold_read(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
398 file
, userbuf
, count
, ppos
);
402 static ssize_t
lbs_highsnr_write(struct file
*file
, const char __user
*userbuf
,
403 size_t count
, loff_t
*ppos
)
405 return lbs_threshold_write(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
406 file
, userbuf
, count
, ppos
);
409 static ssize_t
lbs_bcnmiss_read(struct file
*file
, char __user
*userbuf
,
410 size_t count
, loff_t
*ppos
)
412 return lbs_threshold_read(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
413 file
, userbuf
, count
, ppos
);
417 static ssize_t
lbs_bcnmiss_write(struct file
*file
, const char __user
*userbuf
,
418 size_t count
, loff_t
*ppos
)
420 return lbs_threshold_write(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
421 file
, userbuf
, count
, ppos
);
426 static ssize_t
lbs_rdmac_read(struct file
*file
, char __user
*userbuf
,
427 size_t count
, loff_t
*ppos
)
429 struct lbs_private
*priv
= file
->private_data
;
430 struct lbs_offset_value offval
;
433 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
434 char *buf
= (char *)addr
;
436 offval
.offset
= priv
->mac_offset
;
439 ret
= lbs_prepare_and_send_command(priv
,
440 CMD_MAC_REG_ACCESS
, 0,
441 CMD_OPTION_WAITFORRSP
, 0, &offval
);
443 pos
+= snprintf(buf
+pos
, len
-pos
, "MAC[0x%x] = 0x%08x\n",
444 priv
->mac_offset
, priv
->offsetvalue
.value
);
446 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
451 static ssize_t
lbs_rdmac_write(struct file
*file
,
452 const char __user
*userbuf
,
453 size_t count
, loff_t
*ppos
)
455 struct lbs_private
*priv
= file
->private_data
;
456 ssize_t res
, buf_size
;
457 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
458 char *buf
= (char *)addr
;
460 buf_size
= min(count
, len
- 1);
461 if (copy_from_user(buf
, userbuf
, buf_size
)) {
465 priv
->mac_offset
= simple_strtoul((char *)buf
, NULL
, 16);
472 static ssize_t
lbs_wrmac_write(struct file
*file
,
473 const char __user
*userbuf
,
474 size_t count
, loff_t
*ppos
)
477 struct lbs_private
*priv
= file
->private_data
;
478 ssize_t res
, buf_size
;
480 struct lbs_offset_value offval
;
481 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
482 char *buf
= (char *)addr
;
484 buf_size
= min(count
, len
- 1);
485 if (copy_from_user(buf
, userbuf
, buf_size
)) {
489 res
= sscanf(buf
, "%x %x", &offset
, &value
);
495 offval
.offset
= offset
;
496 offval
.value
= value
;
497 res
= lbs_prepare_and_send_command(priv
,
498 CMD_MAC_REG_ACCESS
, 1,
499 CMD_OPTION_WAITFORRSP
, 0, &offval
);
508 static ssize_t
lbs_rdbbp_read(struct file
*file
, char __user
*userbuf
,
509 size_t count
, loff_t
*ppos
)
511 struct lbs_private
*priv
= file
->private_data
;
512 struct lbs_offset_value offval
;
515 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
516 char *buf
= (char *)addr
;
518 offval
.offset
= priv
->bbp_offset
;
521 ret
= lbs_prepare_and_send_command(priv
,
522 CMD_BBP_REG_ACCESS
, 0,
523 CMD_OPTION_WAITFORRSP
, 0, &offval
);
525 pos
+= snprintf(buf
+pos
, len
-pos
, "BBP[0x%x] = 0x%08x\n",
526 priv
->bbp_offset
, priv
->offsetvalue
.value
);
528 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
534 static ssize_t
lbs_rdbbp_write(struct file
*file
,
535 const char __user
*userbuf
,
536 size_t count
, loff_t
*ppos
)
538 struct lbs_private
*priv
= file
->private_data
;
539 ssize_t res
, buf_size
;
540 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
541 char *buf
= (char *)addr
;
543 buf_size
= min(count
, len
- 1);
544 if (copy_from_user(buf
, userbuf
, buf_size
)) {
548 priv
->bbp_offset
= simple_strtoul((char *)buf
, NULL
, 16);
555 static ssize_t
lbs_wrbbp_write(struct file
*file
,
556 const char __user
*userbuf
,
557 size_t count
, loff_t
*ppos
)
560 struct lbs_private
*priv
= file
->private_data
;
561 ssize_t res
, buf_size
;
563 struct lbs_offset_value offval
;
564 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
565 char *buf
= (char *)addr
;
567 buf_size
= min(count
, len
- 1);
568 if (copy_from_user(buf
, userbuf
, buf_size
)) {
572 res
= sscanf(buf
, "%x %x", &offset
, &value
);
578 offval
.offset
= offset
;
579 offval
.value
= value
;
580 res
= lbs_prepare_and_send_command(priv
,
581 CMD_BBP_REG_ACCESS
, 1,
582 CMD_OPTION_WAITFORRSP
, 0, &offval
);
591 static ssize_t
lbs_rdrf_read(struct file
*file
, char __user
*userbuf
,
592 size_t count
, loff_t
*ppos
)
594 struct lbs_private
*priv
= file
->private_data
;
595 struct lbs_offset_value offval
;
598 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
599 char *buf
= (char *)addr
;
601 offval
.offset
= priv
->rf_offset
;
604 ret
= lbs_prepare_and_send_command(priv
,
605 CMD_RF_REG_ACCESS
, 0,
606 CMD_OPTION_WAITFORRSP
, 0, &offval
);
608 pos
+= snprintf(buf
+pos
, len
-pos
, "RF[0x%x] = 0x%08x\n",
609 priv
->rf_offset
, priv
->offsetvalue
.value
);
611 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
617 static ssize_t
lbs_rdrf_write(struct file
*file
,
618 const char __user
*userbuf
,
619 size_t count
, loff_t
*ppos
)
621 struct lbs_private
*priv
= file
->private_data
;
622 ssize_t res
, buf_size
;
623 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
624 char *buf
= (char *)addr
;
626 buf_size
= min(count
, len
- 1);
627 if (copy_from_user(buf
, userbuf
, buf_size
)) {
631 priv
->rf_offset
= simple_strtoul((char *)buf
, NULL
, 16);
638 static ssize_t
lbs_wrrf_write(struct file
*file
,
639 const char __user
*userbuf
,
640 size_t count
, loff_t
*ppos
)
643 struct lbs_private
*priv
= file
->private_data
;
644 ssize_t res
, buf_size
;
646 struct lbs_offset_value offval
;
647 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
648 char *buf
= (char *)addr
;
650 buf_size
= min(count
, len
- 1);
651 if (copy_from_user(buf
, userbuf
, buf_size
)) {
655 res
= sscanf(buf
, "%x %x", &offset
, &value
);
661 offval
.offset
= offset
;
662 offval
.value
= value
;
663 res
= lbs_prepare_and_send_command(priv
,
664 CMD_RF_REG_ACCESS
, 1,
665 CMD_OPTION_WAITFORRSP
, 0, &offval
);
674 #define FOPS(fread, fwrite) { \
675 .owner = THIS_MODULE, \
676 .open = open_file_generic, \
681 struct lbs_debugfs_files
{
684 struct file_operations fops
;
687 static struct lbs_debugfs_files debugfs_files
[] = {
688 { "info", 0444, FOPS(lbs_dev_info
, write_file_dummy
), },
689 { "getscantable", 0444, FOPS(lbs_getscantable
,
690 write_file_dummy
), },
691 { "sleepparams", 0644, FOPS(lbs_sleepparams_read
,
692 lbs_sleepparams_write
), },
695 static struct lbs_debugfs_files debugfs_events_files
[] = {
696 {"low_rssi", 0644, FOPS(lbs_lowrssi_read
,
697 lbs_lowrssi_write
), },
698 {"low_snr", 0644, FOPS(lbs_lowsnr_read
,
699 lbs_lowsnr_write
), },
700 {"failure_count", 0644, FOPS(lbs_failcount_read
,
701 lbs_failcount_write
), },
702 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read
,
703 lbs_bcnmiss_write
), },
704 {"high_rssi", 0644, FOPS(lbs_highrssi_read
,
705 lbs_highrssi_write
), },
706 {"high_snr", 0644, FOPS(lbs_highsnr_read
,
707 lbs_highsnr_write
), },
710 static struct lbs_debugfs_files debugfs_regs_files
[] = {
711 {"rdmac", 0644, FOPS(lbs_rdmac_read
, lbs_rdmac_write
), },
712 {"wrmac", 0600, FOPS(NULL
, lbs_wrmac_write
), },
713 {"rdbbp", 0644, FOPS(lbs_rdbbp_read
, lbs_rdbbp_write
), },
714 {"wrbbp", 0600, FOPS(NULL
, lbs_wrbbp_write
), },
715 {"rdrf", 0644, FOPS(lbs_rdrf_read
, lbs_rdrf_write
), },
716 {"wrrf", 0600, FOPS(NULL
, lbs_wrrf_write
), },
719 void lbs_debugfs_init(void)
722 lbs_dir
= debugfs_create_dir("lbs_wireless", NULL
);
727 void lbs_debugfs_remove(void)
730 debugfs_remove(lbs_dir
);
734 void lbs_debugfs_init_one(struct lbs_private
*priv
, struct net_device
*dev
)
737 struct lbs_debugfs_files
*files
;
741 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, lbs_dir
);
742 if (!priv
->debugfs_dir
)
745 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
746 files
= &debugfs_files
[i
];
747 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
754 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
755 if (!priv
->events_dir
)
758 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
759 files
= &debugfs_events_files
[i
];
760 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
767 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
771 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
772 files
= &debugfs_regs_files
[i
];
773 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
781 lbs_debug_init(priv
);
787 void lbs_debugfs_remove_one(struct lbs_private
*priv
)
791 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
792 debugfs_remove(priv
->debugfs_regs_files
[i
]);
794 debugfs_remove(priv
->regs_dir
);
796 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
797 debugfs_remove(priv
->debugfs_events_files
[i
]);
799 debugfs_remove(priv
->events_dir
);
801 debugfs_remove(priv
->debugfs_debug
);
803 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
804 debugfs_remove(priv
->debugfs_files
[i
]);
805 debugfs_remove(priv
->debugfs_dir
);
814 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
815 #define item_addr(n) (offsetof(struct lbs_private, n))
824 /* To debug any member of struct lbs_private, simply add one line here.
826 static struct debug_data items
[] = {
827 {"psmode", item_size(psmode
), item_addr(psmode
)},
828 {"psstate", item_size(psstate
), item_addr(psstate
)},
831 static int num_of_items
= ARRAY_SIZE(items
);
834 * @brief proc read function
836 * @param page pointer to buffer
837 * @param s read data starting position
840 * @param eof end of file flag
841 * @param data data to output
842 * @return number of output data
844 static ssize_t
lbs_debugfs_read(struct file
*file
, char __user
*userbuf
,
845 size_t count
, loff_t
*ppos
)
852 struct debug_data
*d
;
853 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
854 char *buf
= (char *)addr
;
858 d
= (struct debug_data
*)file
->private_data
;
860 for (i
= 0; i
< num_of_items
; i
++) {
862 val
= *((u8
*) d
[i
].addr
);
863 else if (d
[i
].size
== 2)
864 val
= *((u16
*) d
[i
].addr
);
865 else if (d
[i
].size
== 4)
866 val
= *((u32
*) d
[i
].addr
);
867 else if (d
[i
].size
== 8)
868 val
= *((u64
*) d
[i
].addr
);
870 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
873 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
880 * @brief proc write function
882 * @param f file pointer
883 * @param buf pointer to data buffer
884 * @param cnt data number to write
885 * @param data data to write
886 * @return number of data
888 static ssize_t
lbs_debugfs_write(struct file
*f
, const char __user
*buf
,
889 size_t cnt
, loff_t
*ppos
)
897 struct debug_data
*d
= (struct debug_data
*)f
->private_data
;
899 pdata
= kmalloc(cnt
, GFP_KERNEL
);
903 if (copy_from_user(pdata
, buf
, cnt
)) {
904 lbs_deb_debugfs("Copy from user failed\n");
910 for (i
= 0; i
< num_of_items
; i
++) {
912 p
= strstr(p0
, d
[i
].name
);
915 p1
= strchr(p
, '\n');
923 r
= simple_strtoul(p2
, NULL
, 0);
925 *((u8
*) d
[i
].addr
) = (u8
) r
;
926 else if (d
[i
].size
== 2)
927 *((u16
*) d
[i
].addr
) = (u16
) r
;
928 else if (d
[i
].size
== 4)
929 *((u32
*) d
[i
].addr
) = (u32
) r
;
930 else if (d
[i
].size
== 8)
931 *((u64
*) d
[i
].addr
) = (u64
) r
;
940 static struct file_operations lbs_debug_fops
= {
941 .owner
= THIS_MODULE
,
942 .open
= open_file_generic
,
943 .write
= lbs_debugfs_write
,
944 .read
= lbs_debugfs_read
,
948 * @brief create debug proc file
950 * @param priv pointer struct lbs_private
951 * @param dev pointer net_device
954 static void lbs_debug_init(struct lbs_private
*priv
)
958 if (!priv
->debugfs_dir
)
961 for (i
= 0; i
< num_of_items
; i
++)
962 items
[i
].addr
+= (size_t) priv
;
964 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
965 priv
->debugfs_dir
, &items
[0],