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 int open_file_generic(struct inode *inode, struct file *file)
26
file->private_data = inode->i_private;
30
static ssize_t write_file_dummy(struct file *file, const char __user *buf,
31
size_t count, loff_t *ppos)
36
static const size_t len = PAGE_SIZE;
38
static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
39
size_t count, loff_t *ppos)
41
struct lbs_private *priv = file->private_data;
43
unsigned long addr = get_zeroed_page(GFP_KERNEL);
44
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);
60
static ssize_t lbs_sleepparams_write(struct file *file,
61
const char __user *user_buf, size_t count,
64
struct lbs_private *priv = file->private_data;
65
ssize_t buf_size, ret;
66
struct sleep_params sp;
67
int p1, p2, p3, p4, p5, p6;
68
unsigned long addr = get_zeroed_page(GFP_KERNEL);
69
char *buf = (char *)addr;
73
buf_size = min(count, len - 1);
74
if (copy_from_user(buf, user_buf, buf_size)) {
78
ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
85
sp.sp_stabletime = p3;
86
sp.sp_calcontrol = p4;
87
sp.sp_extsleepclk = p5;
90
ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp);
101
static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
102
size_t count, loff_t *ppos)
104
struct lbs_private *priv = file->private_data;
107
struct sleep_params sp;
108
unsigned long addr = get_zeroed_page(GFP_KERNEL);
109
char *buf = (char *)addr;
113
ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp);
117
pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error,
118
sp.sp_offset, sp.sp_stabletime,
119
sp.sp_calcontrol, sp.sp_extsleepclk,
122
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
129
static ssize_t lbs_host_sleep_write(struct file *file,
130
const char __user *user_buf, size_t count,
133
struct lbs_private *priv = file->private_data;
134
ssize_t buf_size, ret;
136
unsigned long addr = get_zeroed_page(GFP_KERNEL);
137
char *buf = (char *)addr;
141
buf_size = min(count, len - 1);
142
if (copy_from_user(buf, user_buf, buf_size)) {
146
ret = sscanf(buf, "%d", &host_sleep);
153
ret = lbs_set_host_sleep(priv, 0);
154
else if (host_sleep == 1) {
155
if (priv->wol_criteria == EHS_REMOVE_WAKEUP) {
156
netdev_info(priv->dev,
157
"wake parameters not configured\n");
161
ret = lbs_set_host_sleep(priv, 1);
163
netdev_err(priv->dev, "invalid option\n");
175
static ssize_t lbs_host_sleep_read(struct file *file, char __user *userbuf,
176
size_t count, loff_t *ppos)
178
struct lbs_private *priv = file->private_data;
181
unsigned long addr = get_zeroed_page(GFP_KERNEL);
182
char *buf = (char *)addr;
186
pos += snprintf(buf, len, "%d\n", priv->is_host_sleep_activated);
188
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
195
* When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
196
* get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
197
* firmware. Here's an example:
198
* 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
199
* 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
200
* 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
202
* The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
203
* 00 00 are the data bytes of this TLV. For this TLV, their meaning is
204
* defined in mrvlietypes_thresholds
206
* This function searches in this TLV data chunk for a given TLV type
207
* and returns a pointer to the first data byte of the TLV, or to NULL
208
* if the TLV hasn't been found.
210
static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size)
212
struct mrvl_ie_header *tlv_h;
217
tlv_h = (struct mrvl_ie_header *) tlv;
220
if (tlv_h->type == cpu_to_le16(tlv_type))
222
length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h);
230
static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask,
231
struct file *file, char __user *userbuf,
232
size_t count, loff_t *ppos)
234
struct cmd_ds_802_11_subscribe_event *subscribed;
235
struct mrvl_ie_thresholds *got;
236
struct lbs_private *priv = file->private_data;
244
buf = (char *)get_zeroed_page(GFP_KERNEL);
248
subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL);
254
subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed));
255
subscribed->action = cpu_to_le16(CMD_ACT_GET);
257
ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed);
261
got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
265
events = le16_to_cpu(subscribed->events);
267
pos += snprintf(buf, len, "%d %d %d\n", value, freq,
268
!!(events & event_mask));
271
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
277
free_page((unsigned long)buf);
282
static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask,
284
const char __user *userbuf, size_t count,
287
struct cmd_ds_802_11_subscribe_event *events;
288
struct mrvl_ie_thresholds *tlv;
289
struct lbs_private *priv = file->private_data;
291
int value, freq, new_mask;
296
buf = (char *)get_zeroed_page(GFP_KERNEL);
300
buf_size = min(count, len - 1);
301
if (copy_from_user(buf, userbuf, buf_size)) {
305
ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
310
events = kzalloc(sizeof(*events), GFP_KERNEL);
316
events->hdr.size = cpu_to_le16(sizeof(*events));
317
events->action = cpu_to_le16(CMD_ACT_GET);
319
ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
323
curr_mask = le16_to_cpu(events->events);
326
new_mask = curr_mask | event_mask;
328
new_mask = curr_mask & ~event_mask;
330
/* Now everything is set and we can send stuff down to the firmware */
332
tlv = (void *)events->tlv;
334
events->action = cpu_to_le16(CMD_ACT_SET);
335
events->events = cpu_to_le16(new_mask);
336
tlv->header.type = cpu_to_le16(tlv_type);
337
tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header));
339
if (tlv_type != TLV_TYPE_BCNMISS)
342
/* The command header, the action, the event mask, and one TLV */
343
events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv));
345
ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
352
free_page((unsigned long)buf);
357
static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf,
358
size_t count, loff_t *ppos)
360
return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
361
file, userbuf, count, ppos);
365
static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf,
366
size_t count, loff_t *ppos)
368
return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
369
file, userbuf, count, ppos);
373
static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf,
374
size_t count, loff_t *ppos)
376
return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
377
file, userbuf, count, ppos);
381
static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf,
382
size_t count, loff_t *ppos)
384
return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
385
file, userbuf, count, ppos);
389
static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf,
390
size_t count, loff_t *ppos)
392
return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
393
file, userbuf, count, ppos);
397
static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf,
398
size_t count, loff_t *ppos)
400
return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
401
file, userbuf, count, ppos);
405
static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf,
406
size_t count, loff_t *ppos)
408
return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
409
file, userbuf, count, ppos);
413
static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf,
414
size_t count, loff_t *ppos)
416
return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
417
file, userbuf, count, ppos);
421
static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf,
422
size_t count, loff_t *ppos)
424
return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
425
file, userbuf, count, ppos);
429
static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf,
430
size_t count, loff_t *ppos)
432
return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
433
file, userbuf, count, ppos);
436
static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf,
437
size_t count, loff_t *ppos)
439
return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
440
file, userbuf, count, ppos);
444
static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf,
445
size_t count, loff_t *ppos)
447
return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
448
file, userbuf, count, ppos);
452
static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
453
size_t count, loff_t *ppos)
455
struct lbs_private *priv = file->private_data;
458
unsigned long addr = get_zeroed_page(GFP_KERNEL);
459
char *buf = (char *)addr;
465
ret = lbs_get_reg(priv, CMD_MAC_REG_ACCESS, priv->mac_offset, &val);
468
pos = snprintf(buf, len, "MAC[0x%x] = 0x%08x\n",
469
priv->mac_offset, val);
470
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
476
static ssize_t lbs_rdmac_write(struct file *file,
477
const char __user *userbuf,
478
size_t count, loff_t *ppos)
480
struct lbs_private *priv = file->private_data;
481
ssize_t res, buf_size;
482
unsigned long addr = get_zeroed_page(GFP_KERNEL);
483
char *buf = (char *)addr;
487
buf_size = min(count, len - 1);
488
if (copy_from_user(buf, userbuf, buf_size)) {
492
priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
499
static ssize_t lbs_wrmac_write(struct file *file,
500
const char __user *userbuf,
501
size_t count, loff_t *ppos)
504
struct lbs_private *priv = file->private_data;
505
ssize_t res, buf_size;
507
unsigned long addr = get_zeroed_page(GFP_KERNEL);
508
char *buf = (char *)addr;
512
buf_size = min(count, len - 1);
513
if (copy_from_user(buf, userbuf, buf_size)) {
517
res = sscanf(buf, "%x %x", &offset, &value);
523
res = lbs_set_reg(priv, CMD_MAC_REG_ACCESS, offset, value);
533
static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
534
size_t count, loff_t *ppos)
536
struct lbs_private *priv = file->private_data;
539
unsigned long addr = get_zeroed_page(GFP_KERNEL);
540
char *buf = (char *)addr;
546
ret = lbs_get_reg(priv, CMD_BBP_REG_ACCESS, priv->bbp_offset, &val);
549
pos = snprintf(buf, len, "BBP[0x%x] = 0x%08x\n",
550
priv->bbp_offset, val);
551
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
558
static ssize_t lbs_rdbbp_write(struct file *file,
559
const char __user *userbuf,
560
size_t count, loff_t *ppos)
562
struct lbs_private *priv = file->private_data;
563
ssize_t res, buf_size;
564
unsigned long addr = get_zeroed_page(GFP_KERNEL);
565
char *buf = (char *)addr;
569
buf_size = min(count, len - 1);
570
if (copy_from_user(buf, userbuf, buf_size)) {
574
priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
581
static ssize_t lbs_wrbbp_write(struct file *file,
582
const char __user *userbuf,
583
size_t count, loff_t *ppos)
586
struct lbs_private *priv = file->private_data;
587
ssize_t res, buf_size;
589
unsigned long addr = get_zeroed_page(GFP_KERNEL);
590
char *buf = (char *)addr;
594
buf_size = min(count, len - 1);
595
if (copy_from_user(buf, userbuf, buf_size)) {
599
res = sscanf(buf, "%x %x", &offset, &value);
605
res = lbs_set_reg(priv, CMD_BBP_REG_ACCESS, offset, value);
615
static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
616
size_t count, loff_t *ppos)
618
struct lbs_private *priv = file->private_data;
621
unsigned long addr = get_zeroed_page(GFP_KERNEL);
622
char *buf = (char *)addr;
628
ret = lbs_get_reg(priv, CMD_RF_REG_ACCESS, priv->rf_offset, &val);
631
pos = snprintf(buf, len, "RF[0x%x] = 0x%08x\n",
632
priv->rf_offset, val);
633
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
640
static ssize_t lbs_rdrf_write(struct file *file,
641
const char __user *userbuf,
642
size_t count, loff_t *ppos)
644
struct lbs_private *priv = file->private_data;
645
ssize_t res, buf_size;
646
unsigned long addr = get_zeroed_page(GFP_KERNEL);
647
char *buf = (char *)addr;
651
buf_size = min(count, len - 1);
652
if (copy_from_user(buf, userbuf, buf_size)) {
656
priv->rf_offset = simple_strtoul(buf, NULL, 16);
663
static ssize_t lbs_wrrf_write(struct file *file,
664
const char __user *userbuf,
665
size_t count, loff_t *ppos)
668
struct lbs_private *priv = file->private_data;
669
ssize_t res, buf_size;
671
unsigned long addr = get_zeroed_page(GFP_KERNEL);
672
char *buf = (char *)addr;
676
buf_size = min(count, len - 1);
677
if (copy_from_user(buf, userbuf, buf_size)) {
681
res = sscanf(buf, "%x %x", &offset, &value);
687
res = lbs_set_reg(priv, CMD_RF_REG_ACCESS, offset, value);
697
#define FOPS(fread, fwrite) { \
698
.owner = THIS_MODULE, \
699
.open = open_file_generic, \
702
.llseek = generic_file_llseek, \
705
struct lbs_debugfs_files {
708
struct file_operations fops;
711
static const struct lbs_debugfs_files debugfs_files[] = {
712
{ "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
713
{ "sleepparams", 0644, FOPS(lbs_sleepparams_read,
714
lbs_sleepparams_write), },
715
{ "hostsleep", 0644, FOPS(lbs_host_sleep_read,
716
lbs_host_sleep_write), },
719
static const struct lbs_debugfs_files debugfs_events_files[] = {
720
{"low_rssi", 0644, FOPS(lbs_lowrssi_read,
721
lbs_lowrssi_write), },
722
{"low_snr", 0644, FOPS(lbs_lowsnr_read,
723
lbs_lowsnr_write), },
724
{"failure_count", 0644, FOPS(lbs_failcount_read,
725
lbs_failcount_write), },
726
{"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
727
lbs_bcnmiss_write), },
728
{"high_rssi", 0644, FOPS(lbs_highrssi_read,
729
lbs_highrssi_write), },
730
{"high_snr", 0644, FOPS(lbs_highsnr_read,
731
lbs_highsnr_write), },
734
static const struct lbs_debugfs_files debugfs_regs_files[] = {
735
{"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
736
{"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
737
{"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
738
{"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
739
{"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
740
{"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
743
void lbs_debugfs_init(void)
746
lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
749
void lbs_debugfs_remove(void)
752
debugfs_remove(lbs_dir);
755
void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
758
const struct lbs_debugfs_files *files;
762
priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
763
if (!priv->debugfs_dir)
766
for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
767
files = &debugfs_files[i];
768
priv->debugfs_files[i] = debugfs_create_file(files->name,
775
priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
776
if (!priv->events_dir)
779
for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
780
files = &debugfs_events_files[i];
781
priv->debugfs_events_files[i] = debugfs_create_file(files->name,
788
priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
792
for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
793
files = &debugfs_regs_files[i];
794
priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
802
lbs_debug_init(priv);
808
void lbs_debugfs_remove_one(struct lbs_private *priv)
812
for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
813
debugfs_remove(priv->debugfs_regs_files[i]);
815
debugfs_remove(priv->regs_dir);
817
for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
818
debugfs_remove(priv->debugfs_events_files[i]);
820
debugfs_remove(priv->events_dir);
822
debugfs_remove(priv->debugfs_debug);
824
for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
825
debugfs_remove(priv->debugfs_files[i]);
826
debugfs_remove(priv->debugfs_dir);
835
#define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
836
#define item_addr(n) (offsetof(struct lbs_private, n))
845
/* To debug any member of struct lbs_private, simply add one line here.
847
static struct debug_data items[] = {
848
{"psmode", item_size(psmode), item_addr(psmode)},
849
{"psstate", item_size(psstate), item_addr(psstate)},
852
static int num_of_items = ARRAY_SIZE(items);
855
* lbs_debugfs_read - proc read function
857
* @file: file to read
858
* @userbuf: pointer to buffer
859
* @count: number of bytes to read
860
* @ppos: read data starting position
862
* returns: amount of data read or negative error code
864
static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
865
size_t count, loff_t *ppos)
872
struct debug_data *d;
873
unsigned long addr = get_zeroed_page(GFP_KERNEL);
874
char *buf = (char *)addr;
880
d = file->private_data;
882
for (i = 0; i < num_of_items; i++) {
884
val = *((u8 *) d[i].addr);
885
else if (d[i].size == 2)
886
val = *((u16 *) d[i].addr);
887
else if (d[i].size == 4)
888
val = *((u32 *) d[i].addr);
889
else if (d[i].size == 8)
890
val = *((u64 *) d[i].addr);
892
pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
895
res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
902
* lbs_debugfs_write - proc write function
905
* @buf: pointer to data buffer
906
* @cnt: data number to write
907
* @ppos: file position
909
* returns: amount of data written
911
static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
912
size_t cnt, loff_t *ppos)
920
struct debug_data *d = f->private_data;
922
pdata = kmalloc(cnt, GFP_KERNEL);
926
if (copy_from_user(pdata, buf, cnt)) {
927
lbs_deb_debugfs("Copy from user failed\n");
933
for (i = 0; i < num_of_items; i++) {
935
p = strstr(p0, d[i].name);
938
p1 = strchr(p, '\n');
946
r = simple_strtoul(p2, NULL, 0);
948
*((u8 *) d[i].addr) = (u8) r;
949
else if (d[i].size == 2)
950
*((u16 *) d[i].addr) = (u16) r;
951
else if (d[i].size == 4)
952
*((u32 *) d[i].addr) = (u32) r;
953
else if (d[i].size == 8)
954
*((u64 *) d[i].addr) = (u64) r;
963
static const struct file_operations lbs_debug_fops = {
964
.owner = THIS_MODULE,
965
.open = open_file_generic,
966
.write = lbs_debugfs_write,
967
.read = lbs_debugfs_read,
968
.llseek = default_llseek,
972
* lbs_debug_init - create debug proc file
974
* @priv: pointer to &struct lbs_private
978
static void lbs_debug_init(struct lbs_private *priv)
982
if (!priv->debugfs_dir)
985
for (i = 0; i < num_of_items; i++)
986
items[i].addr += (size_t) priv;
988
priv->debugfs_debug = debugfs_create_file("debug", 0644,
989
priv->debugfs_dir, &items[0],