1 #include <linux/dcache.h>
2 #include <linux/debugfs.h>
3 #include <linux/delay.h>
5 #include <linux/string.h>
6 #include <linux/slab.h>
12 static struct dentry
*lbs_dir
;
13 static char *szStates
[] = {
19 static void lbs_debug_init(struct lbs_private
*priv
);
22 static int open_file_generic(struct inode
*inode
, struct file
*file
)
24 file
->private_data
= inode
->i_private
;
28 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
29 size_t count
, loff_t
*ppos
)
34 static const size_t len
= PAGE_SIZE
;
36 static ssize_t
lbs_dev_info(struct file
*file
, char __user
*userbuf
,
37 size_t count
, loff_t
*ppos
)
39 struct lbs_private
*priv
= file
->private_data
;
41 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
42 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
);
58 static ssize_t
lbs_sleepparams_write(struct file
*file
,
59 const char __user
*user_buf
, size_t count
,
62 struct lbs_private
*priv
= file
->private_data
;
63 ssize_t buf_size
, ret
;
64 struct sleep_params sp
;
65 int p1
, p2
, p3
, p4
, p5
, p6
;
66 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
67 char *buf
= (char *)addr
;
71 buf_size
= min(count
, len
- 1);
72 if (copy_from_user(buf
, user_buf
, buf_size
)) {
76 ret
= sscanf(buf
, "%d %d %d %d %d %d", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
);
83 sp
.sp_stabletime
= p3
;
84 sp
.sp_calcontrol
= p4
;
85 sp
.sp_extsleepclk
= p5
;
88 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_SET
, &sp
);
99 static ssize_t
lbs_sleepparams_read(struct file
*file
, char __user
*userbuf
,
100 size_t count
, loff_t
*ppos
)
102 struct lbs_private
*priv
= file
->private_data
;
105 struct sleep_params sp
;
106 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
107 char *buf
= (char *)addr
;
111 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_GET
, &sp
);
115 pos
+= snprintf(buf
, len
, "%d %d %d %d %d %d\n", sp
.sp_error
,
116 sp
.sp_offset
, sp
.sp_stabletime
,
117 sp
.sp_calcontrol
, sp
.sp_extsleepclk
,
120 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
127 static ssize_t
lbs_host_sleep_write(struct file
*file
,
128 const char __user
*user_buf
, size_t count
,
131 struct lbs_private
*priv
= file
->private_data
;
132 ssize_t buf_size
, ret
;
134 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
135 char *buf
= (char *)addr
;
139 buf_size
= min(count
, len
- 1);
140 if (copy_from_user(buf
, user_buf
, buf_size
)) {
144 ret
= sscanf(buf
, "%d", &host_sleep
);
151 ret
= lbs_set_host_sleep(priv
, 0);
152 else if (host_sleep
== 1) {
153 if (priv
->wol_criteria
== EHS_REMOVE_WAKEUP
) {
154 lbs_pr_info("wake parameters not configured");
158 ret
= lbs_set_host_sleep(priv
, 1);
160 lbs_pr_err("invalid option\n");
172 static ssize_t
lbs_host_sleep_read(struct file
*file
, char __user
*userbuf
,
173 size_t count
, loff_t
*ppos
)
175 struct lbs_private
*priv
= file
->private_data
;
178 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
179 char *buf
= (char *)addr
;
183 pos
+= snprintf(buf
, len
, "%d\n", priv
->is_host_sleep_activated
);
185 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
192 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
193 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
194 * firmware. Here's an example:
195 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
196 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
197 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
199 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
200 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
201 * defined in mrvlietypes_thresholds
203 * This function searches in this TLV data chunk for a given TLV type
204 * and returns a pointer to the first data byte of the TLV, or to NULL
205 * if the TLV hasn't been found.
207 static void *lbs_tlv_find(uint16_t tlv_type
, const uint8_t *tlv
, uint16_t size
)
209 struct mrvl_ie_header
*tlv_h
;
214 tlv_h
= (struct mrvl_ie_header
*) tlv
;
217 if (tlv_h
->type
== cpu_to_le16(tlv_type
))
219 length
= le16_to_cpu(tlv_h
->len
) + sizeof(*tlv_h
);
227 static ssize_t
lbs_threshold_read(uint16_t tlv_type
, uint16_t event_mask
,
228 struct file
*file
, char __user
*userbuf
,
229 size_t count
, loff_t
*ppos
)
231 struct cmd_ds_802_11_subscribe_event
*subscribed
;
232 struct mrvl_ie_thresholds
*got
;
233 struct lbs_private
*priv
= file
->private_data
;
241 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
245 subscribed
= kzalloc(sizeof(*subscribed
), GFP_KERNEL
);
251 subscribed
->hdr
.size
= cpu_to_le16(sizeof(*subscribed
));
252 subscribed
->action
= cpu_to_le16(CMD_ACT_GET
);
254 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, subscribed
);
258 got
= lbs_tlv_find(tlv_type
, subscribed
->tlv
, sizeof(subscribed
->tlv
));
262 events
= le16_to_cpu(subscribed
->events
);
264 pos
+= snprintf(buf
, len
, "%d %d %d\n", value
, freq
,
265 !!(events
& event_mask
));
268 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
274 free_page((unsigned long)buf
);
279 static ssize_t
lbs_threshold_write(uint16_t tlv_type
, uint16_t event_mask
,
281 const char __user
*userbuf
, size_t count
,
284 struct cmd_ds_802_11_subscribe_event
*events
;
285 struct mrvl_ie_thresholds
*tlv
;
286 struct lbs_private
*priv
= file
->private_data
;
288 int value
, freq
, new_mask
;
293 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
297 buf_size
= min(count
, len
- 1);
298 if (copy_from_user(buf
, userbuf
, buf_size
)) {
302 ret
= sscanf(buf
, "%d %d %d", &value
, &freq
, &new_mask
);
307 events
= kzalloc(sizeof(*events
), GFP_KERNEL
);
313 events
->hdr
.size
= cpu_to_le16(sizeof(*events
));
314 events
->action
= cpu_to_le16(CMD_ACT_GET
);
316 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
320 curr_mask
= le16_to_cpu(events
->events
);
323 new_mask
= curr_mask
| event_mask
;
325 new_mask
= curr_mask
& ~event_mask
;
327 /* Now everything is set and we can send stuff down to the firmware */
329 tlv
= (void *)events
->tlv
;
331 events
->action
= cpu_to_le16(CMD_ACT_SET
);
332 events
->events
= cpu_to_le16(new_mask
);
333 tlv
->header
.type
= cpu_to_le16(tlv_type
);
334 tlv
->header
.len
= cpu_to_le16(sizeof(*tlv
) - sizeof(tlv
->header
));
336 if (tlv_type
!= TLV_TYPE_BCNMISS
)
339 /* The command header, the action, the event mask, and one TLV */
340 events
->hdr
.size
= cpu_to_le16(sizeof(events
->hdr
) + 4 + sizeof(*tlv
));
342 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
349 free_page((unsigned long)buf
);
354 static ssize_t
lbs_lowrssi_read(struct file
*file
, char __user
*userbuf
,
355 size_t count
, loff_t
*ppos
)
357 return lbs_threshold_read(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
358 file
, userbuf
, count
, ppos
);
362 static ssize_t
lbs_lowrssi_write(struct file
*file
, const char __user
*userbuf
,
363 size_t count
, loff_t
*ppos
)
365 return lbs_threshold_write(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
366 file
, userbuf
, count
, ppos
);
370 static ssize_t
lbs_lowsnr_read(struct file
*file
, char __user
*userbuf
,
371 size_t count
, loff_t
*ppos
)
373 return lbs_threshold_read(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
374 file
, userbuf
, count
, ppos
);
378 static ssize_t
lbs_lowsnr_write(struct file
*file
, const char __user
*userbuf
,
379 size_t count
, loff_t
*ppos
)
381 return lbs_threshold_write(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
382 file
, userbuf
, count
, ppos
);
386 static ssize_t
lbs_failcount_read(struct file
*file
, char __user
*userbuf
,
387 size_t count
, loff_t
*ppos
)
389 return lbs_threshold_read(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
390 file
, userbuf
, count
, ppos
);
394 static ssize_t
lbs_failcount_write(struct file
*file
, const char __user
*userbuf
,
395 size_t count
, loff_t
*ppos
)
397 return lbs_threshold_write(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
398 file
, userbuf
, count
, ppos
);
402 static ssize_t
lbs_highrssi_read(struct file
*file
, char __user
*userbuf
,
403 size_t count
, loff_t
*ppos
)
405 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
406 file
, userbuf
, count
, ppos
);
410 static ssize_t
lbs_highrssi_write(struct file
*file
, const char __user
*userbuf
,
411 size_t count
, loff_t
*ppos
)
413 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
414 file
, userbuf
, count
, ppos
);
418 static ssize_t
lbs_highsnr_read(struct file
*file
, char __user
*userbuf
,
419 size_t count
, loff_t
*ppos
)
421 return lbs_threshold_read(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
422 file
, userbuf
, count
, ppos
);
426 static ssize_t
lbs_highsnr_write(struct file
*file
, const char __user
*userbuf
,
427 size_t count
, loff_t
*ppos
)
429 return lbs_threshold_write(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
430 file
, userbuf
, count
, ppos
);
433 static ssize_t
lbs_bcnmiss_read(struct file
*file
, char __user
*userbuf
,
434 size_t count
, loff_t
*ppos
)
436 return lbs_threshold_read(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
437 file
, userbuf
, count
, ppos
);
441 static ssize_t
lbs_bcnmiss_write(struct file
*file
, const char __user
*userbuf
,
442 size_t count
, loff_t
*ppos
)
444 return lbs_threshold_write(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
445 file
, userbuf
, count
, ppos
);
449 static ssize_t
lbs_rdmac_read(struct file
*file
, char __user
*userbuf
,
450 size_t count
, loff_t
*ppos
)
452 struct lbs_private
*priv
= file
->private_data
;
455 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
456 char *buf
= (char *)addr
;
462 ret
= lbs_get_reg(priv
, CMD_MAC_REG_ACCESS
, priv
->mac_offset
, &val
);
465 pos
= snprintf(buf
, len
, "MAC[0x%x] = 0x%08x\n",
466 priv
->mac_offset
, val
);
467 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
473 static ssize_t
lbs_rdmac_write(struct file
*file
,
474 const char __user
*userbuf
,
475 size_t count
, loff_t
*ppos
)
477 struct lbs_private
*priv
= file
->private_data
;
478 ssize_t res
, buf_size
;
479 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
480 char *buf
= (char *)addr
;
484 buf_size
= min(count
, len
- 1);
485 if (copy_from_user(buf
, userbuf
, buf_size
)) {
489 priv
->mac_offset
= simple_strtoul((char *)buf
, NULL
, 16);
496 static ssize_t
lbs_wrmac_write(struct file
*file
,
497 const char __user
*userbuf
,
498 size_t count
, loff_t
*ppos
)
501 struct lbs_private
*priv
= file
->private_data
;
502 ssize_t res
, buf_size
;
504 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
505 char *buf
= (char *)addr
;
509 buf_size
= min(count
, len
- 1);
510 if (copy_from_user(buf
, userbuf
, buf_size
)) {
514 res
= sscanf(buf
, "%x %x", &offset
, &value
);
520 res
= lbs_set_reg(priv
, CMD_MAC_REG_ACCESS
, offset
, value
);
530 static ssize_t
lbs_rdbbp_read(struct file
*file
, char __user
*userbuf
,
531 size_t count
, loff_t
*ppos
)
533 struct lbs_private
*priv
= file
->private_data
;
536 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
537 char *buf
= (char *)addr
;
543 ret
= lbs_get_reg(priv
, CMD_BBP_REG_ACCESS
, priv
->bbp_offset
, &val
);
546 pos
= snprintf(buf
, len
, "BBP[0x%x] = 0x%08x\n",
547 priv
->bbp_offset
, val
);
548 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
555 static ssize_t
lbs_rdbbp_write(struct file
*file
,
556 const char __user
*userbuf
,
557 size_t count
, loff_t
*ppos
)
559 struct lbs_private
*priv
= file
->private_data
;
560 ssize_t res
, buf_size
;
561 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
562 char *buf
= (char *)addr
;
566 buf_size
= min(count
, len
- 1);
567 if (copy_from_user(buf
, userbuf
, buf_size
)) {
571 priv
->bbp_offset
= simple_strtoul((char *)buf
, NULL
, 16);
578 static ssize_t
lbs_wrbbp_write(struct file
*file
,
579 const char __user
*userbuf
,
580 size_t count
, loff_t
*ppos
)
583 struct lbs_private
*priv
= file
->private_data
;
584 ssize_t res
, buf_size
;
586 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
587 char *buf
= (char *)addr
;
591 buf_size
= min(count
, len
- 1);
592 if (copy_from_user(buf
, userbuf
, buf_size
)) {
596 res
= sscanf(buf
, "%x %x", &offset
, &value
);
602 res
= lbs_set_reg(priv
, CMD_BBP_REG_ACCESS
, offset
, value
);
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
;
618 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
619 char *buf
= (char *)addr
;
625 ret
= lbs_get_reg(priv
, CMD_RF_REG_ACCESS
, priv
->rf_offset
, &val
);
628 pos
= snprintf(buf
, len
, "RF[0x%x] = 0x%08x\n",
629 priv
->rf_offset
, val
);
630 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
637 static ssize_t
lbs_rdrf_write(struct file
*file
,
638 const char __user
*userbuf
,
639 size_t count
, loff_t
*ppos
)
641 struct lbs_private
*priv
= file
->private_data
;
642 ssize_t res
, buf_size
;
643 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
644 char *buf
= (char *)addr
;
648 buf_size
= min(count
, len
- 1);
649 if (copy_from_user(buf
, userbuf
, buf_size
)) {
653 priv
->rf_offset
= simple_strtoul(buf
, NULL
, 16);
660 static ssize_t
lbs_wrrf_write(struct file
*file
,
661 const char __user
*userbuf
,
662 size_t count
, loff_t
*ppos
)
665 struct lbs_private
*priv
= file
->private_data
;
666 ssize_t res
, buf_size
;
668 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
669 char *buf
= (char *)addr
;
673 buf_size
= min(count
, len
- 1);
674 if (copy_from_user(buf
, userbuf
, buf_size
)) {
678 res
= sscanf(buf
, "%x %x", &offset
, &value
);
684 res
= lbs_set_reg(priv
, CMD_RF_REG_ACCESS
, offset
, value
);
694 #define FOPS(fread, fwrite) { \
695 .owner = THIS_MODULE, \
696 .open = open_file_generic, \
701 struct lbs_debugfs_files
{
704 struct file_operations fops
;
707 static const struct lbs_debugfs_files debugfs_files
[] = {
708 { "info", 0444, FOPS(lbs_dev_info
, write_file_dummy
), },
709 { "sleepparams", 0644, FOPS(lbs_sleepparams_read
,
710 lbs_sleepparams_write
), },
711 { "hostsleep", 0644, FOPS(lbs_host_sleep_read
,
712 lbs_host_sleep_write
), },
715 static const struct lbs_debugfs_files debugfs_events_files
[] = {
716 {"low_rssi", 0644, FOPS(lbs_lowrssi_read
,
717 lbs_lowrssi_write
), },
718 {"low_snr", 0644, FOPS(lbs_lowsnr_read
,
719 lbs_lowsnr_write
), },
720 {"failure_count", 0644, FOPS(lbs_failcount_read
,
721 lbs_failcount_write
), },
722 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read
,
723 lbs_bcnmiss_write
), },
724 {"high_rssi", 0644, FOPS(lbs_highrssi_read
,
725 lbs_highrssi_write
), },
726 {"high_snr", 0644, FOPS(lbs_highsnr_read
,
727 lbs_highsnr_write
), },
730 static const struct lbs_debugfs_files debugfs_regs_files
[] = {
731 {"rdmac", 0644, FOPS(lbs_rdmac_read
, lbs_rdmac_write
), },
732 {"wrmac", 0600, FOPS(NULL
, lbs_wrmac_write
), },
733 {"rdbbp", 0644, FOPS(lbs_rdbbp_read
, lbs_rdbbp_write
), },
734 {"wrbbp", 0600, FOPS(NULL
, lbs_wrbbp_write
), },
735 {"rdrf", 0644, FOPS(lbs_rdrf_read
, lbs_rdrf_write
), },
736 {"wrrf", 0600, FOPS(NULL
, lbs_wrrf_write
), },
739 void lbs_debugfs_init(void)
742 lbs_dir
= debugfs_create_dir("lbs_wireless", NULL
);
745 void lbs_debugfs_remove(void)
748 debugfs_remove(lbs_dir
);
751 void lbs_debugfs_init_one(struct lbs_private
*priv
, struct net_device
*dev
)
754 const struct lbs_debugfs_files
*files
;
758 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, lbs_dir
);
759 if (!priv
->debugfs_dir
)
762 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
763 files
= &debugfs_files
[i
];
764 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
771 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
772 if (!priv
->events_dir
)
775 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
776 files
= &debugfs_events_files
[i
];
777 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
784 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
788 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
789 files
= &debugfs_regs_files
[i
];
790 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
798 lbs_debug_init(priv
);
804 void lbs_debugfs_remove_one(struct lbs_private
*priv
)
808 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
809 debugfs_remove(priv
->debugfs_regs_files
[i
]);
811 debugfs_remove(priv
->regs_dir
);
813 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
814 debugfs_remove(priv
->debugfs_events_files
[i
]);
816 debugfs_remove(priv
->events_dir
);
818 debugfs_remove(priv
->debugfs_debug
);
820 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
821 debugfs_remove(priv
->debugfs_files
[i
]);
822 debugfs_remove(priv
->debugfs_dir
);
831 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
832 #define item_addr(n) (offsetof(struct lbs_private, n))
841 /* To debug any member of struct lbs_private, simply add one line here.
843 static struct debug_data items
[] = {
844 {"psmode", item_size(psmode
), item_addr(psmode
)},
845 {"psstate", item_size(psstate
), item_addr(psstate
)},
848 static int num_of_items
= ARRAY_SIZE(items
);
851 * @brief proc read function
853 * @param page pointer to buffer
854 * @param s read data starting position
857 * @param eof end of file flag
858 * @param data data to output
859 * @return number of output data
861 static ssize_t
lbs_debugfs_read(struct file
*file
, char __user
*userbuf
,
862 size_t count
, loff_t
*ppos
)
869 struct debug_data
*d
;
870 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
871 char *buf
= (char *)addr
;
877 d
= file
->private_data
;
879 for (i
= 0; i
< num_of_items
; i
++) {
881 val
= *((u8
*) d
[i
].addr
);
882 else if (d
[i
].size
== 2)
883 val
= *((u16
*) d
[i
].addr
);
884 else if (d
[i
].size
== 4)
885 val
= *((u32
*) d
[i
].addr
);
886 else if (d
[i
].size
== 8)
887 val
= *((u64
*) d
[i
].addr
);
889 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
892 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
899 * @brief proc write function
901 * @param f file pointer
902 * @param buf pointer to data buffer
903 * @param cnt data number to write
904 * @param data data to write
905 * @return number of data
907 static ssize_t
lbs_debugfs_write(struct file
*f
, const char __user
*buf
,
908 size_t cnt
, loff_t
*ppos
)
916 struct debug_data
*d
= f
->private_data
;
918 pdata
= kmalloc(cnt
, GFP_KERNEL
);
922 if (copy_from_user(pdata
, buf
, cnt
)) {
923 lbs_deb_debugfs("Copy from user failed\n");
929 for (i
= 0; i
< num_of_items
; i
++) {
931 p
= strstr(p0
, d
[i
].name
);
934 p1
= strchr(p
, '\n');
942 r
= simple_strtoul(p2
, NULL
, 0);
944 *((u8
*) d
[i
].addr
) = (u8
) r
;
945 else if (d
[i
].size
== 2)
946 *((u16
*) d
[i
].addr
) = (u16
) r
;
947 else if (d
[i
].size
== 4)
948 *((u32
*) d
[i
].addr
) = (u32
) r
;
949 else if (d
[i
].size
== 8)
950 *((u64
*) d
[i
].addr
) = (u64
) r
;
959 static const struct file_operations lbs_debug_fops
= {
960 .owner
= THIS_MODULE
,
961 .open
= open_file_generic
,
962 .write
= lbs_debugfs_write
,
963 .read
= lbs_debugfs_read
,
967 * @brief create debug proc file
969 * @param priv pointer struct lbs_private
970 * @param dev pointer net_device
973 static void lbs_debug_init(struct lbs_private
*priv
)
977 if (!priv
->debugfs_dir
)
980 for (i
= 0; i
< num_of_items
; i
++)
981 items
[i
].addr
+= (size_t) priv
;
983 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
984 priv
->debugfs_dir
, &items
[0],