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>
13 static struct dentry
*lbs_dir
;
14 static char *szStates
[] = {
20 static void lbs_debug_init(struct lbs_private
*priv
);
23 static int open_file_generic(struct inode
*inode
, struct file
*file
)
25 file
->private_data
= inode
->i_private
;
29 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
30 size_t count
, loff_t
*ppos
)
35 static const size_t len
= PAGE_SIZE
;
37 static ssize_t
lbs_dev_info(struct file
*file
, char __user
*userbuf
,
38 size_t count
, loff_t
*ppos
)
40 struct lbs_private
*priv
= file
->private_data
;
42 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
43 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
);
59 static ssize_t
lbs_sleepparams_write(struct file
*file
,
60 const char __user
*user_buf
, size_t count
,
63 struct lbs_private
*priv
= file
->private_data
;
64 ssize_t buf_size
, ret
;
65 struct sleep_params sp
;
66 int p1
, p2
, p3
, p4
, p5
, p6
;
67 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
68 char *buf
= (char *)addr
;
72 buf_size
= min(count
, len
- 1);
73 if (copy_from_user(buf
, user_buf
, buf_size
)) {
77 ret
= sscanf(buf
, "%d %d %d %d %d %d", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
);
84 sp
.sp_stabletime
= p3
;
85 sp
.sp_calcontrol
= p4
;
86 sp
.sp_extsleepclk
= p5
;
89 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_SET
, &sp
);
100 static ssize_t
lbs_sleepparams_read(struct file
*file
, char __user
*userbuf
,
101 size_t count
, loff_t
*ppos
)
103 struct lbs_private
*priv
= file
->private_data
;
106 struct sleep_params sp
;
107 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
108 char *buf
= (char *)addr
;
112 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_GET
, &sp
);
116 pos
+= snprintf(buf
, len
, "%d %d %d %d %d %d\n", sp
.sp_error
,
117 sp
.sp_offset
, sp
.sp_stabletime
,
118 sp
.sp_calcontrol
, sp
.sp_extsleepclk
,
121 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
128 static ssize_t
lbs_host_sleep_write(struct file
*file
,
129 const char __user
*user_buf
, size_t count
,
132 struct lbs_private
*priv
= file
->private_data
;
133 ssize_t buf_size
, ret
;
135 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
136 char *buf
= (char *)addr
;
140 buf_size
= min(count
, len
- 1);
141 if (copy_from_user(buf
, user_buf
, buf_size
)) {
145 ret
= sscanf(buf
, "%d", &host_sleep
);
152 ret
= lbs_set_host_sleep(priv
, 0);
153 else if (host_sleep
== 1) {
154 if (priv
->wol_criteria
== EHS_REMOVE_WAKEUP
) {
155 netdev_info(priv
->dev
,
156 "wake parameters not configured\n");
160 ret
= lbs_set_host_sleep(priv
, 1);
162 netdev_err(priv
->dev
, "invalid option\n");
174 static ssize_t
lbs_host_sleep_read(struct file
*file
, char __user
*userbuf
,
175 size_t count
, loff_t
*ppos
)
177 struct lbs_private
*priv
= file
->private_data
;
180 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
181 char *buf
= (char *)addr
;
185 pos
+= snprintf(buf
, len
, "%d\n", priv
->is_host_sleep_activated
);
187 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
194 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
195 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
196 * firmware. Here's an example:
197 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
198 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
199 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
201 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
202 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
203 * defined in mrvlietypes_thresholds
205 * This function searches in this TLV data chunk for a given TLV type
206 * and returns a pointer to the first data byte of the TLV, or to NULL
207 * if the TLV hasn't been found.
209 static void *lbs_tlv_find(uint16_t tlv_type
, const uint8_t *tlv
, uint16_t size
)
211 struct mrvl_ie_header
*tlv_h
;
216 tlv_h
= (struct mrvl_ie_header
*) tlv
;
219 if (tlv_h
->type
== cpu_to_le16(tlv_type
))
221 length
= le16_to_cpu(tlv_h
->len
) + sizeof(*tlv_h
);
229 static ssize_t
lbs_threshold_read(uint16_t tlv_type
, uint16_t event_mask
,
230 struct file
*file
, char __user
*userbuf
,
231 size_t count
, loff_t
*ppos
)
233 struct cmd_ds_802_11_subscribe_event
*subscribed
;
234 struct mrvl_ie_thresholds
*got
;
235 struct lbs_private
*priv
= file
->private_data
;
243 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
247 subscribed
= kzalloc(sizeof(*subscribed
), GFP_KERNEL
);
253 subscribed
->hdr
.size
= cpu_to_le16(sizeof(*subscribed
));
254 subscribed
->action
= cpu_to_le16(CMD_ACT_GET
);
256 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, subscribed
);
260 got
= lbs_tlv_find(tlv_type
, subscribed
->tlv
, sizeof(subscribed
->tlv
));
264 events
= le16_to_cpu(subscribed
->events
);
266 pos
+= snprintf(buf
, len
, "%d %d %d\n", value
, freq
,
267 !!(events
& event_mask
));
270 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
276 free_page((unsigned long)buf
);
281 static ssize_t
lbs_threshold_write(uint16_t tlv_type
, uint16_t event_mask
,
283 const char __user
*userbuf
, size_t count
,
286 struct cmd_ds_802_11_subscribe_event
*events
;
287 struct mrvl_ie_thresholds
*tlv
;
288 struct lbs_private
*priv
= file
->private_data
;
290 int value
, freq
, new_mask
;
295 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
299 buf_size
= min(count
, len
- 1);
300 if (copy_from_user(buf
, userbuf
, buf_size
)) {
304 ret
= sscanf(buf
, "%d %d %d", &value
, &freq
, &new_mask
);
309 events
= kzalloc(sizeof(*events
), GFP_KERNEL
);
315 events
->hdr
.size
= cpu_to_le16(sizeof(*events
));
316 events
->action
= cpu_to_le16(CMD_ACT_GET
);
318 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
322 curr_mask
= le16_to_cpu(events
->events
);
325 new_mask
= curr_mask
| event_mask
;
327 new_mask
= curr_mask
& ~event_mask
;
329 /* Now everything is set and we can send stuff down to the firmware */
331 tlv
= (void *)events
->tlv
;
333 events
->action
= cpu_to_le16(CMD_ACT_SET
);
334 events
->events
= cpu_to_le16(new_mask
);
335 tlv
->header
.type
= cpu_to_le16(tlv_type
);
336 tlv
->header
.len
= cpu_to_le16(sizeof(*tlv
) - sizeof(tlv
->header
));
338 if (tlv_type
!= TLV_TYPE_BCNMISS
)
341 /* The command header, the action, the event mask, and one TLV */
342 events
->hdr
.size
= cpu_to_le16(sizeof(events
->hdr
) + 4 + sizeof(*tlv
));
344 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
351 free_page((unsigned long)buf
);
356 static ssize_t
lbs_lowrssi_read(struct file
*file
, char __user
*userbuf
,
357 size_t count
, loff_t
*ppos
)
359 return lbs_threshold_read(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
360 file
, userbuf
, count
, ppos
);
364 static ssize_t
lbs_lowrssi_write(struct file
*file
, const char __user
*userbuf
,
365 size_t count
, loff_t
*ppos
)
367 return lbs_threshold_write(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
368 file
, userbuf
, count
, ppos
);
372 static ssize_t
lbs_lowsnr_read(struct file
*file
, char __user
*userbuf
,
373 size_t count
, loff_t
*ppos
)
375 return lbs_threshold_read(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
376 file
, userbuf
, count
, ppos
);
380 static ssize_t
lbs_lowsnr_write(struct file
*file
, const char __user
*userbuf
,
381 size_t count
, loff_t
*ppos
)
383 return lbs_threshold_write(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
384 file
, userbuf
, count
, ppos
);
388 static ssize_t
lbs_failcount_read(struct file
*file
, char __user
*userbuf
,
389 size_t count
, loff_t
*ppos
)
391 return lbs_threshold_read(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
392 file
, userbuf
, count
, ppos
);
396 static ssize_t
lbs_failcount_write(struct file
*file
, const char __user
*userbuf
,
397 size_t count
, loff_t
*ppos
)
399 return lbs_threshold_write(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
400 file
, userbuf
, count
, ppos
);
404 static ssize_t
lbs_highrssi_read(struct file
*file
, char __user
*userbuf
,
405 size_t count
, loff_t
*ppos
)
407 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
408 file
, userbuf
, count
, ppos
);
412 static ssize_t
lbs_highrssi_write(struct file
*file
, const char __user
*userbuf
,
413 size_t count
, loff_t
*ppos
)
415 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
416 file
, userbuf
, count
, ppos
);
420 static ssize_t
lbs_highsnr_read(struct file
*file
, char __user
*userbuf
,
421 size_t count
, loff_t
*ppos
)
423 return lbs_threshold_read(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
424 file
, userbuf
, count
, ppos
);
428 static ssize_t
lbs_highsnr_write(struct file
*file
, const char __user
*userbuf
,
429 size_t count
, loff_t
*ppos
)
431 return lbs_threshold_write(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
432 file
, userbuf
, count
, ppos
);
435 static ssize_t
lbs_bcnmiss_read(struct file
*file
, char __user
*userbuf
,
436 size_t count
, loff_t
*ppos
)
438 return lbs_threshold_read(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
439 file
, userbuf
, count
, ppos
);
443 static ssize_t
lbs_bcnmiss_write(struct file
*file
, const char __user
*userbuf
,
444 size_t count
, loff_t
*ppos
)
446 return lbs_threshold_write(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
447 file
, userbuf
, count
, ppos
);
451 static ssize_t
lbs_rdmac_read(struct file
*file
, char __user
*userbuf
,
452 size_t count
, loff_t
*ppos
)
454 struct lbs_private
*priv
= file
->private_data
;
457 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
458 char *buf
= (char *)addr
;
464 ret
= lbs_get_reg(priv
, CMD_MAC_REG_ACCESS
, priv
->mac_offset
, &val
);
467 pos
= snprintf(buf
, len
, "MAC[0x%x] = 0x%08x\n",
468 priv
->mac_offset
, val
);
469 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
475 static ssize_t
lbs_rdmac_write(struct file
*file
,
476 const char __user
*userbuf
,
477 size_t count
, loff_t
*ppos
)
479 struct lbs_private
*priv
= file
->private_data
;
480 ssize_t res
, buf_size
;
481 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
482 char *buf
= (char *)addr
;
486 buf_size
= min(count
, len
- 1);
487 if (copy_from_user(buf
, userbuf
, buf_size
)) {
491 priv
->mac_offset
= simple_strtoul((char *)buf
, NULL
, 16);
498 static ssize_t
lbs_wrmac_write(struct file
*file
,
499 const char __user
*userbuf
,
500 size_t count
, loff_t
*ppos
)
503 struct lbs_private
*priv
= file
->private_data
;
504 ssize_t res
, buf_size
;
506 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
507 char *buf
= (char *)addr
;
511 buf_size
= min(count
, len
- 1);
512 if (copy_from_user(buf
, userbuf
, buf_size
)) {
516 res
= sscanf(buf
, "%x %x", &offset
, &value
);
522 res
= lbs_set_reg(priv
, CMD_MAC_REG_ACCESS
, offset
, value
);
532 static ssize_t
lbs_rdbbp_read(struct file
*file
, char __user
*userbuf
,
533 size_t count
, loff_t
*ppos
)
535 struct lbs_private
*priv
= file
->private_data
;
538 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
539 char *buf
= (char *)addr
;
545 ret
= lbs_get_reg(priv
, CMD_BBP_REG_ACCESS
, priv
->bbp_offset
, &val
);
548 pos
= snprintf(buf
, len
, "BBP[0x%x] = 0x%08x\n",
549 priv
->bbp_offset
, val
);
550 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
557 static ssize_t
lbs_rdbbp_write(struct file
*file
,
558 const char __user
*userbuf
,
559 size_t count
, loff_t
*ppos
)
561 struct lbs_private
*priv
= file
->private_data
;
562 ssize_t res
, buf_size
;
563 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
564 char *buf
= (char *)addr
;
568 buf_size
= min(count
, len
- 1);
569 if (copy_from_user(buf
, userbuf
, buf_size
)) {
573 priv
->bbp_offset
= simple_strtoul((char *)buf
, NULL
, 16);
580 static ssize_t
lbs_wrbbp_write(struct file
*file
,
581 const char __user
*userbuf
,
582 size_t count
, loff_t
*ppos
)
585 struct lbs_private
*priv
= file
->private_data
;
586 ssize_t res
, buf_size
;
588 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
589 char *buf
= (char *)addr
;
593 buf_size
= min(count
, len
- 1);
594 if (copy_from_user(buf
, userbuf
, buf_size
)) {
598 res
= sscanf(buf
, "%x %x", &offset
, &value
);
604 res
= lbs_set_reg(priv
, CMD_BBP_REG_ACCESS
, offset
, value
);
614 static ssize_t
lbs_rdrf_read(struct file
*file
, char __user
*userbuf
,
615 size_t count
, loff_t
*ppos
)
617 struct lbs_private
*priv
= file
->private_data
;
620 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
621 char *buf
= (char *)addr
;
627 ret
= lbs_get_reg(priv
, CMD_RF_REG_ACCESS
, priv
->rf_offset
, &val
);
630 pos
= snprintf(buf
, len
, "RF[0x%x] = 0x%08x\n",
631 priv
->rf_offset
, val
);
632 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
639 static ssize_t
lbs_rdrf_write(struct file
*file
,
640 const char __user
*userbuf
,
641 size_t count
, loff_t
*ppos
)
643 struct lbs_private
*priv
= file
->private_data
;
644 ssize_t res
, buf_size
;
645 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
646 char *buf
= (char *)addr
;
650 buf_size
= min(count
, len
- 1);
651 if (copy_from_user(buf
, userbuf
, buf_size
)) {
655 priv
->rf_offset
= simple_strtoul(buf
, NULL
, 16);
662 static ssize_t
lbs_wrrf_write(struct file
*file
,
663 const char __user
*userbuf
,
664 size_t count
, loff_t
*ppos
)
667 struct lbs_private
*priv
= file
->private_data
;
668 ssize_t res
, buf_size
;
670 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
671 char *buf
= (char *)addr
;
675 buf_size
= min(count
, len
- 1);
676 if (copy_from_user(buf
, userbuf
, buf_size
)) {
680 res
= sscanf(buf
, "%x %x", &offset
, &value
);
686 res
= lbs_set_reg(priv
, CMD_RF_REG_ACCESS
, offset
, value
);
696 #define FOPS(fread, fwrite) { \
697 .owner = THIS_MODULE, \
698 .open = open_file_generic, \
701 .llseek = generic_file_llseek, \
704 struct lbs_debugfs_files
{
707 struct file_operations fops
;
710 static const struct lbs_debugfs_files debugfs_files
[] = {
711 { "info", 0444, FOPS(lbs_dev_info
, write_file_dummy
), },
712 { "sleepparams", 0644, FOPS(lbs_sleepparams_read
,
713 lbs_sleepparams_write
), },
714 { "hostsleep", 0644, FOPS(lbs_host_sleep_read
,
715 lbs_host_sleep_write
), },
718 static const struct lbs_debugfs_files debugfs_events_files
[] = {
719 {"low_rssi", 0644, FOPS(lbs_lowrssi_read
,
720 lbs_lowrssi_write
), },
721 {"low_snr", 0644, FOPS(lbs_lowsnr_read
,
722 lbs_lowsnr_write
), },
723 {"failure_count", 0644, FOPS(lbs_failcount_read
,
724 lbs_failcount_write
), },
725 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read
,
726 lbs_bcnmiss_write
), },
727 {"high_rssi", 0644, FOPS(lbs_highrssi_read
,
728 lbs_highrssi_write
), },
729 {"high_snr", 0644, FOPS(lbs_highsnr_read
,
730 lbs_highsnr_write
), },
733 static const struct lbs_debugfs_files debugfs_regs_files
[] = {
734 {"rdmac", 0644, FOPS(lbs_rdmac_read
, lbs_rdmac_write
), },
735 {"wrmac", 0600, FOPS(NULL
, lbs_wrmac_write
), },
736 {"rdbbp", 0644, FOPS(lbs_rdbbp_read
, lbs_rdbbp_write
), },
737 {"wrbbp", 0600, FOPS(NULL
, lbs_wrbbp_write
), },
738 {"rdrf", 0644, FOPS(lbs_rdrf_read
, lbs_rdrf_write
), },
739 {"wrrf", 0600, FOPS(NULL
, lbs_wrrf_write
), },
742 void lbs_debugfs_init(void)
745 lbs_dir
= debugfs_create_dir("lbs_wireless", NULL
);
748 void lbs_debugfs_remove(void)
751 debugfs_remove(lbs_dir
);
754 void lbs_debugfs_init_one(struct lbs_private
*priv
, struct net_device
*dev
)
757 const struct lbs_debugfs_files
*files
;
761 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, lbs_dir
);
762 if (!priv
->debugfs_dir
)
765 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
766 files
= &debugfs_files
[i
];
767 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
774 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
775 if (!priv
->events_dir
)
778 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
779 files
= &debugfs_events_files
[i
];
780 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
787 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
791 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
792 files
= &debugfs_regs_files
[i
];
793 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
801 lbs_debug_init(priv
);
807 void lbs_debugfs_remove_one(struct lbs_private
*priv
)
811 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
812 debugfs_remove(priv
->debugfs_regs_files
[i
]);
814 debugfs_remove(priv
->regs_dir
);
816 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
817 debugfs_remove(priv
->debugfs_events_files
[i
]);
819 debugfs_remove(priv
->events_dir
);
821 debugfs_remove(priv
->debugfs_debug
);
823 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
824 debugfs_remove(priv
->debugfs_files
[i
]);
825 debugfs_remove(priv
->debugfs_dir
);
834 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
835 #define item_addr(n) (offsetof(struct lbs_private, n))
844 /* To debug any member of struct lbs_private, simply add one line here.
846 static struct debug_data items
[] = {
847 {"psmode", item_size(psmode
), item_addr(psmode
)},
848 {"psstate", item_size(psstate
), item_addr(psstate
)},
851 static int num_of_items
= ARRAY_SIZE(items
);
854 * lbs_debugfs_read - proc read function
856 * @file: file to read
857 * @userbuf: pointer to buffer
858 * @count: number of bytes to read
859 * @ppos: read data starting position
861 * returns: amount of data read or negative error code
863 static ssize_t
lbs_debugfs_read(struct file
*file
, char __user
*userbuf
,
864 size_t count
, loff_t
*ppos
)
871 struct debug_data
*d
;
872 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
873 char *buf
= (char *)addr
;
879 d
= file
->private_data
;
881 for (i
= 0; i
< num_of_items
; i
++) {
883 val
= *((u8
*) d
[i
].addr
);
884 else if (d
[i
].size
== 2)
885 val
= *((u16
*) d
[i
].addr
);
886 else if (d
[i
].size
== 4)
887 val
= *((u32
*) d
[i
].addr
);
888 else if (d
[i
].size
== 8)
889 val
= *((u64
*) d
[i
].addr
);
891 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
894 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
901 * lbs_debugfs_write - proc write function
904 * @buf: pointer to data buffer
905 * @cnt: data number to write
906 * @ppos: file position
908 * returns: amount of data written
910 static ssize_t
lbs_debugfs_write(struct file
*f
, const char __user
*buf
,
911 size_t cnt
, loff_t
*ppos
)
919 struct debug_data
*d
= f
->private_data
;
921 pdata
= kmalloc(cnt
, GFP_KERNEL
);
925 if (copy_from_user(pdata
, buf
, cnt
)) {
926 lbs_deb_debugfs("Copy from user failed\n");
932 for (i
= 0; i
< num_of_items
; i
++) {
934 p
= strstr(p0
, d
[i
].name
);
937 p1
= strchr(p
, '\n');
945 r
= simple_strtoul(p2
, NULL
, 0);
947 *((u8
*) d
[i
].addr
) = (u8
) r
;
948 else if (d
[i
].size
== 2)
949 *((u16
*) d
[i
].addr
) = (u16
) r
;
950 else if (d
[i
].size
== 4)
951 *((u32
*) d
[i
].addr
) = (u32
) r
;
952 else if (d
[i
].size
== 8)
953 *((u64
*) d
[i
].addr
) = (u64
) r
;
962 static const struct file_operations lbs_debug_fops
= {
963 .owner
= THIS_MODULE
,
964 .open
= open_file_generic
,
965 .write
= lbs_debugfs_write
,
966 .read
= lbs_debugfs_read
,
967 .llseek
= default_llseek
,
971 * lbs_debug_init - create debug proc file
973 * @priv: pointer to &struct lbs_private
977 static void lbs_debug_init(struct lbs_private
*priv
)
981 if (!priv
->debugfs_dir
)
984 for (i
= 0; i
< num_of_items
; i
++)
985 items
[i
].addr
+= (size_t) priv
;
987 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
988 priv
->debugfs_dir
, &items
[0],