1 #include <linux/dcache.h>
2 #include <linux/debugfs.h>
3 #include <linux/delay.h>
4 #include <linux/hardirq.h>
6 #include <linux/string.h>
7 #include <linux/slab.h>
8 #include <linux/export.h>
14 static struct dentry
*lbs_dir
;
15 static char *szStates
[] = {
21 static void lbs_debug_init(struct lbs_private
*priv
);
24 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
25 size_t count
, loff_t
*ppos
)
30 static const size_t len
= PAGE_SIZE
;
32 static ssize_t
lbs_dev_info(struct file
*file
, char __user
*userbuf
,
33 size_t count
, loff_t
*ppos
)
35 struct lbs_private
*priv
= file
->private_data
;
37 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
38 char *buf
= (char *)addr
;
43 pos
+= snprintf(buf
+pos
, len
-pos
, "state = %s\n",
44 szStates
[priv
->connect_status
]);
45 pos
+= snprintf(buf
+pos
, len
-pos
, "region_code = %02x\n",
46 (u32
) priv
->regioncode
);
48 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
54 static ssize_t
lbs_sleepparams_write(struct file
*file
,
55 const char __user
*user_buf
, size_t count
,
58 struct lbs_private
*priv
= file
->private_data
;
59 ssize_t buf_size
, ret
;
60 struct sleep_params sp
;
61 int p1
, p2
, p3
, p4
, p5
, p6
;
62 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
63 char *buf
= (char *)addr
;
67 buf_size
= min(count
, len
- 1);
68 if (copy_from_user(buf
, user_buf
, buf_size
)) {
72 ret
= sscanf(buf
, "%d %d %d %d %d %d", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
);
79 sp
.sp_stabletime
= p3
;
80 sp
.sp_calcontrol
= p4
;
81 sp
.sp_extsleepclk
= p5
;
84 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_SET
, &sp
);
95 static ssize_t
lbs_sleepparams_read(struct file
*file
, char __user
*userbuf
,
96 size_t count
, loff_t
*ppos
)
98 struct lbs_private
*priv
= file
->private_data
;
101 struct sleep_params sp
;
102 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
103 char *buf
= (char *)addr
;
107 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_GET
, &sp
);
111 pos
+= snprintf(buf
, len
, "%d %d %d %d %d %d\n", sp
.sp_error
,
112 sp
.sp_offset
, sp
.sp_stabletime
,
113 sp
.sp_calcontrol
, sp
.sp_extsleepclk
,
116 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
123 static ssize_t
lbs_host_sleep_write(struct file
*file
,
124 const char __user
*user_buf
, size_t count
,
127 struct lbs_private
*priv
= file
->private_data
;
128 ssize_t buf_size
, ret
;
130 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
131 char *buf
= (char *)addr
;
135 buf_size
= min(count
, len
- 1);
136 if (copy_from_user(buf
, user_buf
, buf_size
)) {
140 ret
= sscanf(buf
, "%d", &host_sleep
);
147 ret
= lbs_set_host_sleep(priv
, 0);
148 else if (host_sleep
== 1) {
149 if (priv
->wol_criteria
== EHS_REMOVE_WAKEUP
) {
150 netdev_info(priv
->dev
,
151 "wake parameters not configured\n");
155 ret
= lbs_set_host_sleep(priv
, 1);
157 netdev_err(priv
->dev
, "invalid option\n");
169 static ssize_t
lbs_host_sleep_read(struct file
*file
, char __user
*userbuf
,
170 size_t count
, loff_t
*ppos
)
172 struct lbs_private
*priv
= file
->private_data
;
175 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
176 char *buf
= (char *)addr
;
180 pos
+= snprintf(buf
, len
, "%d\n", priv
->is_host_sleep_activated
);
182 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
189 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
190 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
191 * firmware. Here's an example:
192 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
193 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
194 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
196 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
197 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
198 * defined in mrvlietypes_thresholds
200 * This function searches in this TLV data chunk for a given TLV type
201 * and returns a pointer to the first data byte of the TLV, or to NULL
202 * if the TLV hasn't been found.
204 static void *lbs_tlv_find(uint16_t tlv_type
, const uint8_t *tlv
, uint16_t size
)
206 struct mrvl_ie_header
*tlv_h
;
211 tlv_h
= (struct mrvl_ie_header
*) tlv
;
214 if (tlv_h
->type
== cpu_to_le16(tlv_type
))
216 length
= le16_to_cpu(tlv_h
->len
) + sizeof(*tlv_h
);
224 static ssize_t
lbs_threshold_read(uint16_t tlv_type
, uint16_t event_mask
,
225 struct file
*file
, char __user
*userbuf
,
226 size_t count
, loff_t
*ppos
)
228 struct cmd_ds_802_11_subscribe_event
*subscribed
;
229 struct mrvl_ie_thresholds
*got
;
230 struct lbs_private
*priv
= file
->private_data
;
238 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
242 subscribed
= kzalloc(sizeof(*subscribed
), GFP_KERNEL
);
248 subscribed
->hdr
.size
= cpu_to_le16(sizeof(*subscribed
));
249 subscribed
->action
= cpu_to_le16(CMD_ACT_GET
);
251 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, subscribed
);
255 got
= lbs_tlv_find(tlv_type
, subscribed
->tlv
, sizeof(subscribed
->tlv
));
259 events
= le16_to_cpu(subscribed
->events
);
261 pos
+= snprintf(buf
, len
, "%d %d %d\n", value
, freq
,
262 !!(events
& event_mask
));
265 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
271 free_page((unsigned long)buf
);
276 static ssize_t
lbs_threshold_write(uint16_t tlv_type
, uint16_t event_mask
,
278 const char __user
*userbuf
, size_t count
,
281 struct cmd_ds_802_11_subscribe_event
*events
;
282 struct mrvl_ie_thresholds
*tlv
;
283 struct lbs_private
*priv
= file
->private_data
;
285 int value
, freq
, new_mask
;
290 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
294 buf_size
= min(count
, len
- 1);
295 if (copy_from_user(buf
, userbuf
, buf_size
)) {
299 ret
= sscanf(buf
, "%d %d %d", &value
, &freq
, &new_mask
);
304 events
= kzalloc(sizeof(*events
), GFP_KERNEL
);
310 events
->hdr
.size
= cpu_to_le16(sizeof(*events
));
311 events
->action
= cpu_to_le16(CMD_ACT_GET
);
313 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
317 curr_mask
= le16_to_cpu(events
->events
);
320 new_mask
= curr_mask
| event_mask
;
322 new_mask
= curr_mask
& ~event_mask
;
324 /* Now everything is set and we can send stuff down to the firmware */
326 tlv
= (void *)events
->tlv
;
328 events
->action
= cpu_to_le16(CMD_ACT_SET
);
329 events
->events
= cpu_to_le16(new_mask
);
330 tlv
->header
.type
= cpu_to_le16(tlv_type
);
331 tlv
->header
.len
= cpu_to_le16(sizeof(*tlv
) - sizeof(tlv
->header
));
333 if (tlv_type
!= TLV_TYPE_BCNMISS
)
336 /* The command header, the action, the event mask, and one TLV */
337 events
->hdr
.size
= cpu_to_le16(sizeof(events
->hdr
) + 4 + sizeof(*tlv
));
339 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
346 free_page((unsigned long)buf
);
351 static ssize_t
lbs_lowrssi_read(struct file
*file
, char __user
*userbuf
,
352 size_t count
, loff_t
*ppos
)
354 return lbs_threshold_read(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
355 file
, userbuf
, count
, ppos
);
359 static ssize_t
lbs_lowrssi_write(struct file
*file
, const char __user
*userbuf
,
360 size_t count
, loff_t
*ppos
)
362 return lbs_threshold_write(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
363 file
, userbuf
, count
, ppos
);
367 static ssize_t
lbs_lowsnr_read(struct file
*file
, char __user
*userbuf
,
368 size_t count
, loff_t
*ppos
)
370 return lbs_threshold_read(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
371 file
, userbuf
, count
, ppos
);
375 static ssize_t
lbs_lowsnr_write(struct file
*file
, const char __user
*userbuf
,
376 size_t count
, loff_t
*ppos
)
378 return lbs_threshold_write(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
379 file
, userbuf
, count
, ppos
);
383 static ssize_t
lbs_failcount_read(struct file
*file
, char __user
*userbuf
,
384 size_t count
, loff_t
*ppos
)
386 return lbs_threshold_read(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
387 file
, userbuf
, count
, ppos
);
391 static ssize_t
lbs_failcount_write(struct file
*file
, const char __user
*userbuf
,
392 size_t count
, loff_t
*ppos
)
394 return lbs_threshold_write(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
395 file
, userbuf
, count
, ppos
);
399 static ssize_t
lbs_highrssi_read(struct file
*file
, char __user
*userbuf
,
400 size_t count
, loff_t
*ppos
)
402 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
403 file
, userbuf
, count
, ppos
);
407 static ssize_t
lbs_highrssi_write(struct file
*file
, const char __user
*userbuf
,
408 size_t count
, loff_t
*ppos
)
410 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
411 file
, userbuf
, count
, ppos
);
415 static ssize_t
lbs_highsnr_read(struct file
*file
, char __user
*userbuf
,
416 size_t count
, loff_t
*ppos
)
418 return lbs_threshold_read(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
419 file
, userbuf
, count
, ppos
);
423 static ssize_t
lbs_highsnr_write(struct file
*file
, const char __user
*userbuf
,
424 size_t count
, loff_t
*ppos
)
426 return lbs_threshold_write(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
427 file
, userbuf
, count
, ppos
);
430 static ssize_t
lbs_bcnmiss_read(struct file
*file
, char __user
*userbuf
,
431 size_t count
, loff_t
*ppos
)
433 return lbs_threshold_read(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
434 file
, userbuf
, count
, ppos
);
438 static ssize_t
lbs_bcnmiss_write(struct file
*file
, const char __user
*userbuf
,
439 size_t count
, loff_t
*ppos
)
441 return lbs_threshold_write(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
442 file
, userbuf
, count
, ppos
);
446 static ssize_t
lbs_rdmac_read(struct file
*file
, char __user
*userbuf
,
447 size_t count
, loff_t
*ppos
)
449 struct lbs_private
*priv
= file
->private_data
;
452 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
453 char *buf
= (char *)addr
;
459 ret
= lbs_get_reg(priv
, CMD_MAC_REG_ACCESS
, priv
->mac_offset
, &val
);
462 pos
= snprintf(buf
, len
, "MAC[0x%x] = 0x%08x\n",
463 priv
->mac_offset
, val
);
464 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
470 static ssize_t
lbs_rdmac_write(struct file
*file
,
471 const char __user
*userbuf
,
472 size_t count
, loff_t
*ppos
)
474 struct lbs_private
*priv
= file
->private_data
;
475 ssize_t res
, buf_size
;
476 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
477 char *buf
= (char *)addr
;
481 buf_size
= min(count
, len
- 1);
482 if (copy_from_user(buf
, userbuf
, buf_size
)) {
486 priv
->mac_offset
= simple_strtoul(buf
, NULL
, 16);
493 static ssize_t
lbs_wrmac_write(struct file
*file
,
494 const char __user
*userbuf
,
495 size_t count
, loff_t
*ppos
)
498 struct lbs_private
*priv
= file
->private_data
;
499 ssize_t res
, buf_size
;
501 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
502 char *buf
= (char *)addr
;
506 buf_size
= min(count
, len
- 1);
507 if (copy_from_user(buf
, userbuf
, buf_size
)) {
511 res
= sscanf(buf
, "%x %x", &offset
, &value
);
517 res
= lbs_set_reg(priv
, CMD_MAC_REG_ACCESS
, offset
, value
);
527 static ssize_t
lbs_rdbbp_read(struct file
*file
, char __user
*userbuf
,
528 size_t count
, loff_t
*ppos
)
530 struct lbs_private
*priv
= file
->private_data
;
533 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
534 char *buf
= (char *)addr
;
540 ret
= lbs_get_reg(priv
, CMD_BBP_REG_ACCESS
, priv
->bbp_offset
, &val
);
543 pos
= snprintf(buf
, len
, "BBP[0x%x] = 0x%08x\n",
544 priv
->bbp_offset
, val
);
545 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
552 static ssize_t
lbs_rdbbp_write(struct file
*file
,
553 const char __user
*userbuf
,
554 size_t count
, loff_t
*ppos
)
556 struct lbs_private
*priv
= file
->private_data
;
557 ssize_t res
, buf_size
;
558 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
559 char *buf
= (char *)addr
;
563 buf_size
= min(count
, len
- 1);
564 if (copy_from_user(buf
, userbuf
, buf_size
)) {
568 priv
->bbp_offset
= simple_strtoul(buf
, NULL
, 16);
575 static ssize_t
lbs_wrbbp_write(struct file
*file
,
576 const char __user
*userbuf
,
577 size_t count
, loff_t
*ppos
)
580 struct lbs_private
*priv
= file
->private_data
;
581 ssize_t res
, buf_size
;
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 res
= lbs_set_reg(priv
, CMD_BBP_REG_ACCESS
, offset
, value
);
609 static ssize_t
lbs_rdrf_read(struct file
*file
, char __user
*userbuf
,
610 size_t count
, loff_t
*ppos
)
612 struct lbs_private
*priv
= file
->private_data
;
615 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
616 char *buf
= (char *)addr
;
622 ret
= lbs_get_reg(priv
, CMD_RF_REG_ACCESS
, priv
->rf_offset
, &val
);
625 pos
= snprintf(buf
, len
, "RF[0x%x] = 0x%08x\n",
626 priv
->rf_offset
, val
);
627 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
634 static ssize_t
lbs_rdrf_write(struct file
*file
,
635 const char __user
*userbuf
,
636 size_t count
, loff_t
*ppos
)
638 struct lbs_private
*priv
= file
->private_data
;
639 ssize_t res
, buf_size
;
640 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
641 char *buf
= (char *)addr
;
645 buf_size
= min(count
, len
- 1);
646 if (copy_from_user(buf
, userbuf
, buf_size
)) {
650 priv
->rf_offset
= simple_strtoul(buf
, NULL
, 16);
657 static ssize_t
lbs_wrrf_write(struct file
*file
,
658 const char __user
*userbuf
,
659 size_t count
, loff_t
*ppos
)
662 struct lbs_private
*priv
= file
->private_data
;
663 ssize_t res
, buf_size
;
665 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
666 char *buf
= (char *)addr
;
670 buf_size
= min(count
, len
- 1);
671 if (copy_from_user(buf
, userbuf
, buf_size
)) {
675 res
= sscanf(buf
, "%x %x", &offset
, &value
);
681 res
= lbs_set_reg(priv
, CMD_RF_REG_ACCESS
, offset
, value
);
691 #define FOPS(fread, fwrite) { \
692 .owner = THIS_MODULE, \
693 .open = simple_open, \
696 .llseek = generic_file_llseek, \
699 struct lbs_debugfs_files
{
702 struct file_operations fops
;
705 static const struct lbs_debugfs_files debugfs_files
[] = {
706 { "info", 0444, FOPS(lbs_dev_info
, write_file_dummy
), },
707 { "sleepparams", 0644, FOPS(lbs_sleepparams_read
,
708 lbs_sleepparams_write
), },
709 { "hostsleep", 0644, FOPS(lbs_host_sleep_read
,
710 lbs_host_sleep_write
), },
713 static const struct lbs_debugfs_files debugfs_events_files
[] = {
714 {"low_rssi", 0644, FOPS(lbs_lowrssi_read
,
715 lbs_lowrssi_write
), },
716 {"low_snr", 0644, FOPS(lbs_lowsnr_read
,
717 lbs_lowsnr_write
), },
718 {"failure_count", 0644, FOPS(lbs_failcount_read
,
719 lbs_failcount_write
), },
720 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read
,
721 lbs_bcnmiss_write
), },
722 {"high_rssi", 0644, FOPS(lbs_highrssi_read
,
723 lbs_highrssi_write
), },
724 {"high_snr", 0644, FOPS(lbs_highsnr_read
,
725 lbs_highsnr_write
), },
728 static const struct lbs_debugfs_files debugfs_regs_files
[] = {
729 {"rdmac", 0644, FOPS(lbs_rdmac_read
, lbs_rdmac_write
), },
730 {"wrmac", 0600, FOPS(NULL
, lbs_wrmac_write
), },
731 {"rdbbp", 0644, FOPS(lbs_rdbbp_read
, lbs_rdbbp_write
), },
732 {"wrbbp", 0600, FOPS(NULL
, lbs_wrbbp_write
), },
733 {"rdrf", 0644, FOPS(lbs_rdrf_read
, lbs_rdrf_write
), },
734 {"wrrf", 0600, FOPS(NULL
, lbs_wrrf_write
), },
737 void lbs_debugfs_init(void)
740 lbs_dir
= debugfs_create_dir("lbs_wireless", NULL
);
743 void lbs_debugfs_remove(void)
746 debugfs_remove(lbs_dir
);
749 void lbs_debugfs_init_one(struct lbs_private
*priv
, struct net_device
*dev
)
752 const struct lbs_debugfs_files
*files
;
756 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, lbs_dir
);
757 if (!priv
->debugfs_dir
)
760 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
761 files
= &debugfs_files
[i
];
762 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
769 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
770 if (!priv
->events_dir
)
773 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
774 files
= &debugfs_events_files
[i
];
775 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
782 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
786 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
787 files
= &debugfs_regs_files
[i
];
788 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
796 lbs_debug_init(priv
);
802 void lbs_debugfs_remove_one(struct lbs_private
*priv
)
806 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
807 debugfs_remove(priv
->debugfs_regs_files
[i
]);
809 debugfs_remove(priv
->regs_dir
);
811 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
812 debugfs_remove(priv
->debugfs_events_files
[i
]);
814 debugfs_remove(priv
->events_dir
);
816 debugfs_remove(priv
->debugfs_debug
);
818 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
819 debugfs_remove(priv
->debugfs_files
[i
]);
820 debugfs_remove(priv
->debugfs_dir
);
829 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
830 #define item_addr(n) (offsetof(struct lbs_private, n))
839 /* To debug any member of struct lbs_private, simply add one line here.
841 static struct debug_data items
[] = {
842 {"psmode", item_size(psmode
), item_addr(psmode
)},
843 {"psstate", item_size(psstate
), item_addr(psstate
)},
846 static int num_of_items
= ARRAY_SIZE(items
);
849 * lbs_debugfs_read - proc read function
851 * @file: file to read
852 * @userbuf: pointer to buffer
853 * @count: number of bytes to read
854 * @ppos: read data starting position
856 * returns: amount of data read or negative error code
858 static ssize_t
lbs_debugfs_read(struct file
*file
, char __user
*userbuf
,
859 size_t count
, loff_t
*ppos
)
866 struct debug_data
*d
;
867 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
868 char *buf
= (char *)addr
;
874 d
= file
->private_data
;
876 for (i
= 0; i
< num_of_items
; i
++) {
878 val
= *((u8
*) d
[i
].addr
);
879 else if (d
[i
].size
== 2)
880 val
= *((u16
*) d
[i
].addr
);
881 else if (d
[i
].size
== 4)
882 val
= *((u32
*) d
[i
].addr
);
883 else if (d
[i
].size
== 8)
884 val
= *((u64
*) d
[i
].addr
);
886 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
889 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
896 * lbs_debugfs_write - proc write function
899 * @buf: pointer to data buffer
900 * @cnt: data number to write
901 * @ppos: file position
903 * returns: amount of data written
905 static ssize_t
lbs_debugfs_write(struct file
*f
, const char __user
*buf
,
906 size_t cnt
, loff_t
*ppos
)
914 struct debug_data
*d
= f
->private_data
;
919 pdata
= kmalloc(cnt
+ 1, GFP_KERNEL
);
923 if (copy_from_user(pdata
, buf
, cnt
)) {
924 lbs_deb_debugfs("Copy from user failed\n");
931 for (i
= 0; i
< num_of_items
; i
++) {
933 p
= strstr(p0
, d
[i
].name
);
936 p1
= strchr(p
, '\n');
944 r
= simple_strtoul(p2
, NULL
, 0);
946 *((u8
*) d
[i
].addr
) = (u8
) r
;
947 else if (d
[i
].size
== 2)
948 *((u16
*) d
[i
].addr
) = (u16
) r
;
949 else if (d
[i
].size
== 4)
950 *((u32
*) d
[i
].addr
) = (u32
) r
;
951 else if (d
[i
].size
== 8)
952 *((u64
*) d
[i
].addr
) = (u64
) r
;
961 static const struct file_operations lbs_debug_fops
= {
962 .owner
= THIS_MODULE
,
964 .write
= lbs_debugfs_write
,
965 .read
= lbs_debugfs_read
,
966 .llseek
= default_llseek
,
970 * lbs_debug_init - create debug proc file
972 * @priv: pointer to &struct lbs_private
976 static void lbs_debug_init(struct lbs_private
*priv
)
980 if (!priv
->debugfs_dir
)
983 for (i
= 0; i
< num_of_items
; i
++)
984 items
[i
].addr
+= (size_t) priv
;
986 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
987 priv
->debugfs_dir
, &items
[0],