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
netdev_info(priv->dev,
155
"wake parameters not configured\n");
159
ret = lbs_set_host_sleep(priv, 1);
161
netdev_err(priv->dev, "invalid option\n");
173
static ssize_t lbs_host_sleep_read(struct file *file, char __user *userbuf,
174
size_t count, loff_t *ppos)
176
struct lbs_private *priv = file->private_data;
179
unsigned long addr = get_zeroed_page(GFP_KERNEL);
180
char *buf = (char *)addr;
184
pos += snprintf(buf, len, "%d\n", priv->is_host_sleep_activated);
186
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
193
* When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
194
* get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
195
* firmware. Here's an example:
196
* 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
197
* 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
198
* 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200
* The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
201
* 00 00 are the data bytes of this TLV. For this TLV, their meaning is
202
* defined in mrvlietypes_thresholds
204
* This function searches in this TLV data chunk for a given TLV type
205
* and returns a pointer to the first data byte of the TLV, or to NULL
206
* if the TLV hasn't been found.
208
static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size)
210
struct mrvl_ie_header *tlv_h;
215
tlv_h = (struct mrvl_ie_header *) tlv;
218
if (tlv_h->type == cpu_to_le16(tlv_type))
220
length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h);
228
static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask,
229
struct file *file, char __user *userbuf,
230
size_t count, loff_t *ppos)
232
struct cmd_ds_802_11_subscribe_event *subscribed;
233
struct mrvl_ie_thresholds *got;
234
struct lbs_private *priv = file->private_data;
242
buf = (char *)get_zeroed_page(GFP_KERNEL);
246
subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL);
252
subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed));
253
subscribed->action = cpu_to_le16(CMD_ACT_GET);
255
ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed);
259
got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
263
events = le16_to_cpu(subscribed->events);
265
pos += snprintf(buf, len, "%d %d %d\n", value, freq,
266
!!(events & event_mask));
269
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
275
free_page((unsigned long)buf);
280
static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask,
282
const char __user *userbuf, size_t count,
285
struct cmd_ds_802_11_subscribe_event *events;
286
struct mrvl_ie_thresholds *tlv;
287
struct lbs_private *priv = file->private_data;
289
int value, freq, new_mask;
294
buf = (char *)get_zeroed_page(GFP_KERNEL);
298
buf_size = min(count, len - 1);
299
if (copy_from_user(buf, userbuf, buf_size)) {
303
ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
308
events = kzalloc(sizeof(*events), GFP_KERNEL);
314
events->hdr.size = cpu_to_le16(sizeof(*events));
315
events->action = cpu_to_le16(CMD_ACT_GET);
317
ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
321
curr_mask = le16_to_cpu(events->events);
324
new_mask = curr_mask | event_mask;
326
new_mask = curr_mask & ~event_mask;
328
/* Now everything is set and we can send stuff down to the firmware */
330
tlv = (void *)events->tlv;
332
events->action = cpu_to_le16(CMD_ACT_SET);
333
events->events = cpu_to_le16(new_mask);
334
tlv->header.type = cpu_to_le16(tlv_type);
335
tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header));
337
if (tlv_type != TLV_TYPE_BCNMISS)
340
/* The command header, the action, the event mask, and one TLV */
341
events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv));
343
ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
350
free_page((unsigned long)buf);
355
static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf,
356
size_t count, loff_t *ppos)
358
return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
359
file, userbuf, count, ppos);
363
static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf,
364
size_t count, loff_t *ppos)
366
return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
367
file, userbuf, count, ppos);
371
static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf,
372
size_t count, loff_t *ppos)
374
return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
375
file, userbuf, count, ppos);
379
static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf,
380
size_t count, loff_t *ppos)
382
return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
383
file, userbuf, count, ppos);
387
static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf,
388
size_t count, loff_t *ppos)
390
return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
391
file, userbuf, count, ppos);
395
static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf,
396
size_t count, loff_t *ppos)
398
return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
399
file, userbuf, count, ppos);
403
static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf,
404
size_t count, loff_t *ppos)
406
return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
407
file, userbuf, count, ppos);
411
static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf,
412
size_t count, loff_t *ppos)
414
return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
415
file, userbuf, count, ppos);
419
static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf,
420
size_t count, loff_t *ppos)
422
return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
423
file, userbuf, count, ppos);
427
static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf,
428
size_t count, loff_t *ppos)
430
return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
431
file, userbuf, count, ppos);
434
static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf,
435
size_t count, loff_t *ppos)
437
return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
438
file, userbuf, count, ppos);
442
static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf,
443
size_t count, loff_t *ppos)
445
return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
446
file, userbuf, count, ppos);
450
static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
451
size_t count, loff_t *ppos)
453
struct lbs_private *priv = file->private_data;
456
unsigned long addr = get_zeroed_page(GFP_KERNEL);
457
char *buf = (char *)addr;
463
ret = lbs_get_reg(priv, CMD_MAC_REG_ACCESS, priv->mac_offset, &val);
466
pos = snprintf(buf, len, "MAC[0x%x] = 0x%08x\n",
467
priv->mac_offset, val);
468
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
474
static ssize_t lbs_rdmac_write(struct file *file,
475
const char __user *userbuf,
476
size_t count, loff_t *ppos)
478
struct lbs_private *priv = file->private_data;
479
ssize_t res, buf_size;
480
unsigned long addr = get_zeroed_page(GFP_KERNEL);
481
char *buf = (char *)addr;
485
buf_size = min(count, len - 1);
486
if (copy_from_user(buf, userbuf, buf_size)) {
490
priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
497
static ssize_t lbs_wrmac_write(struct file *file,
498
const char __user *userbuf,
499
size_t count, loff_t *ppos)
502
struct lbs_private *priv = file->private_data;
503
ssize_t res, buf_size;
505
unsigned long addr = get_zeroed_page(GFP_KERNEL);
506
char *buf = (char *)addr;
510
buf_size = min(count, len - 1);
511
if (copy_from_user(buf, userbuf, buf_size)) {
515
res = sscanf(buf, "%x %x", &offset, &value);
521
res = lbs_set_reg(priv, CMD_MAC_REG_ACCESS, offset, value);
531
static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
532
size_t count, loff_t *ppos)
534
struct lbs_private *priv = file->private_data;
537
unsigned long addr = get_zeroed_page(GFP_KERNEL);
538
char *buf = (char *)addr;
544
ret = lbs_get_reg(priv, CMD_BBP_REG_ACCESS, priv->bbp_offset, &val);
547
pos = snprintf(buf, len, "BBP[0x%x] = 0x%08x\n",
548
priv->bbp_offset, val);
549
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
556
static ssize_t lbs_rdbbp_write(struct file *file,
557
const char __user *userbuf,
558
size_t count, loff_t *ppos)
560
struct lbs_private *priv = file->private_data;
561
ssize_t res, buf_size;
562
unsigned long addr = get_zeroed_page(GFP_KERNEL);
563
char *buf = (char *)addr;
567
buf_size = min(count, len - 1);
568
if (copy_from_user(buf, userbuf, buf_size)) {
572
priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
579
static ssize_t lbs_wrbbp_write(struct file *file,
580
const char __user *userbuf,
581
size_t count, loff_t *ppos)
584
struct lbs_private *priv = file->private_data;
585
ssize_t res, buf_size;
587
unsigned long addr = get_zeroed_page(GFP_KERNEL);
588
char *buf = (char *)addr;
592
buf_size = min(count, len - 1);
593
if (copy_from_user(buf, userbuf, buf_size)) {
597
res = sscanf(buf, "%x %x", &offset, &value);
603
res = lbs_set_reg(priv, CMD_BBP_REG_ACCESS, offset, value);
613
static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
614
size_t count, loff_t *ppos)
616
struct lbs_private *priv = file->private_data;
619
unsigned long addr = get_zeroed_page(GFP_KERNEL);
620
char *buf = (char *)addr;
626
ret = lbs_get_reg(priv, CMD_RF_REG_ACCESS, priv->rf_offset, &val);
629
pos = snprintf(buf, len, "RF[0x%x] = 0x%08x\n",
630
priv->rf_offset, val);
631
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
638
static ssize_t lbs_rdrf_write(struct file *file,
639
const char __user *userbuf,
640
size_t count, loff_t *ppos)
642
struct lbs_private *priv = file->private_data;
643
ssize_t res, buf_size;
644
unsigned long addr = get_zeroed_page(GFP_KERNEL);
645
char *buf = (char *)addr;
649
buf_size = min(count, len - 1);
650
if (copy_from_user(buf, userbuf, buf_size)) {
654
priv->rf_offset = simple_strtoul(buf, NULL, 16);
661
static ssize_t lbs_wrrf_write(struct file *file,
662
const char __user *userbuf,
663
size_t count, loff_t *ppos)
666
struct lbs_private *priv = file->private_data;
667
ssize_t res, buf_size;
669
unsigned long addr = get_zeroed_page(GFP_KERNEL);
670
char *buf = (char *)addr;
674
buf_size = min(count, len - 1);
675
if (copy_from_user(buf, userbuf, buf_size)) {
679
res = sscanf(buf, "%x %x", &offset, &value);
685
res = lbs_set_reg(priv, CMD_RF_REG_ACCESS, offset, value);
695
#define FOPS(fread, fwrite) { \
696
.owner = THIS_MODULE, \
697
.open = open_file_generic, \
700
.llseek = generic_file_llseek, \
703
struct lbs_debugfs_files {
706
struct file_operations fops;
709
static const struct lbs_debugfs_files debugfs_files[] = {
710
{ "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
711
{ "sleepparams", 0644, FOPS(lbs_sleepparams_read,
712
lbs_sleepparams_write), },
713
{ "hostsleep", 0644, FOPS(lbs_host_sleep_read,
714
lbs_host_sleep_write), },
717
static const struct lbs_debugfs_files debugfs_events_files[] = {
718
{"low_rssi", 0644, FOPS(lbs_lowrssi_read,
719
lbs_lowrssi_write), },
720
{"low_snr", 0644, FOPS(lbs_lowsnr_read,
721
lbs_lowsnr_write), },
722
{"failure_count", 0644, FOPS(lbs_failcount_read,
723
lbs_failcount_write), },
724
{"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
725
lbs_bcnmiss_write), },
726
{"high_rssi", 0644, FOPS(lbs_highrssi_read,
727
lbs_highrssi_write), },
728
{"high_snr", 0644, FOPS(lbs_highsnr_read,
729
lbs_highsnr_write), },
732
static const struct lbs_debugfs_files debugfs_regs_files[] = {
733
{"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
734
{"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
735
{"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
736
{"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
737
{"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
738
{"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
741
void lbs_debugfs_init(void)
744
lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
747
void lbs_debugfs_remove(void)
750
debugfs_remove(lbs_dir);
753
void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
756
const struct lbs_debugfs_files *files;
760
priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
761
if (!priv->debugfs_dir)
764
for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
765
files = &debugfs_files[i];
766
priv->debugfs_files[i] = debugfs_create_file(files->name,
773
priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
774
if (!priv->events_dir)
777
for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
778
files = &debugfs_events_files[i];
779
priv->debugfs_events_files[i] = debugfs_create_file(files->name,
786
priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
790
for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
791
files = &debugfs_regs_files[i];
792
priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
800
lbs_debug_init(priv);
806
void lbs_debugfs_remove_one(struct lbs_private *priv)
810
for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
811
debugfs_remove(priv->debugfs_regs_files[i]);
813
debugfs_remove(priv->regs_dir);
815
for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
816
debugfs_remove(priv->debugfs_events_files[i]);
818
debugfs_remove(priv->events_dir);
820
debugfs_remove(priv->debugfs_debug);
822
for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
823
debugfs_remove(priv->debugfs_files[i]);
824
debugfs_remove(priv->debugfs_dir);
833
#define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
834
#define item_addr(n) (offsetof(struct lbs_private, n))
843
/* To debug any member of struct lbs_private, simply add one line here.
845
static struct debug_data items[] = {
846
{"psmode", item_size(psmode), item_addr(psmode)},
847
{"psstate", item_size(psstate), item_addr(psstate)},
850
static int num_of_items = ARRAY_SIZE(items);
853
* lbs_debugfs_read - proc read function
855
* @file: file to read
856
* @userbuf: pointer to buffer
857
* @count: number of bytes to read
858
* @ppos: read data starting position
860
* returns: amount of data read or negative error code
862
static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
863
size_t count, loff_t *ppos)
870
struct debug_data *d;
871
unsigned long addr = get_zeroed_page(GFP_KERNEL);
872
char *buf = (char *)addr;
878
d = file->private_data;
880
for (i = 0; i < num_of_items; i++) {
882
val = *((u8 *) d[i].addr);
883
else if (d[i].size == 2)
884
val = *((u16 *) d[i].addr);
885
else if (d[i].size == 4)
886
val = *((u32 *) d[i].addr);
887
else if (d[i].size == 8)
888
val = *((u64 *) d[i].addr);
890
pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
893
res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
900
* lbs_debugfs_write - proc write function
903
* @buf: pointer to data buffer
904
* @cnt: data number to write
905
* @ppos: file position
907
* returns: amount of data written
909
static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
910
size_t cnt, loff_t *ppos)
918
struct debug_data *d = f->private_data;
920
pdata = kmalloc(cnt, GFP_KERNEL);
924
if (copy_from_user(pdata, buf, cnt)) {
925
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,
963
.open = open_file_generic,
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],