libertas: remove user-specified channel list
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / libertas / debugfs.c
blobd3a47cc95475808be4d448ef2a990dd55d7ee17c
1 #include <linux/module.h>
2 #include <linux/dcache.h>
3 #include <linux/debugfs.h>
4 #include <linux/delay.h>
5 #include <linux/mm.h>
6 #include <linux/string.h>
7 #include <net/iw_handler.h>
9 #include "dev.h"
10 #include "decl.h"
11 #include "host.h"
12 #include "debugfs.h"
14 static struct dentry *lbs_dir;
15 static char *szStates[] = {
16 "Connected",
17 "Disconnected"
20 #ifdef PROC_DEBUG
21 static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev);
22 #endif
24 static int open_file_generic(struct inode *inode, struct file *file)
26 file->private_data = inode->i_private;
27 return 0;
30 static ssize_t write_file_dummy(struct file *file, const char __user *buf,
31 size_t count, loff_t *ppos)
33 return -EINVAL;
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;
42 size_t pos = 0;
43 unsigned long addr = get_zeroed_page(GFP_KERNEL);
44 char *buf = (char *)addr;
45 ssize_t res;
47 pos += snprintf(buf+pos, len-pos, "state = %s\n",
48 szStates[priv->adapter->connect_status]);
49 pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
50 (u32) priv->adapter->regioncode);
52 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
54 free_page(addr);
55 return res;
59 static ssize_t lbs_getscantable(struct file *file, char __user *userbuf,
60 size_t count, loff_t *ppos)
62 struct lbs_private *priv = file->private_data;
63 size_t pos = 0;
64 int numscansdone = 0, res;
65 unsigned long addr = get_zeroed_page(GFP_KERNEL);
66 char *buf = (char *)addr;
67 DECLARE_MAC_BUF(mac);
68 struct bss_descriptor * iter_bss;
70 pos += snprintf(buf+pos, len-pos,
71 "# | ch | rssi | bssid | cap | Qual | SSID \n");
73 mutex_lock(&priv->adapter->lock);
74 list_for_each_entry (iter_bss, &priv->adapter->network_list, list) {
75 u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS);
76 u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY);
77 u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT);
79 pos += snprintf(buf+pos, len-pos,
80 "%02u| %03d | %04ld | %s |",
81 numscansdone, iter_bss->channel, iter_bss->rssi,
82 print_mac(mac, iter_bss->bssid));
83 pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability);
84 pos += snprintf(buf+pos, len-pos, "%c%c%c |",
85 ibss ? 'A' : 'I', privacy ? 'P' : ' ',
86 spectrum_mgmt ? 'S' : ' ');
87 pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi));
88 pos += snprintf(buf+pos, len-pos, " %s\n",
89 escape_essid(iter_bss->ssid, iter_bss->ssid_len));
91 numscansdone++;
93 mutex_unlock(&priv->adapter->lock);
95 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
97 free_page(addr);
98 return res;
101 static ssize_t lbs_sleepparams_write(struct file *file,
102 const char __user *user_buf, size_t count,
103 loff_t *ppos)
105 struct lbs_private *priv = file->private_data;
106 ssize_t buf_size, res;
107 int p1, p2, p3, p4, p5, p6;
108 unsigned long addr = get_zeroed_page(GFP_KERNEL);
109 char *buf = (char *)addr;
111 buf_size = min(count, len - 1);
112 if (copy_from_user(buf, user_buf, buf_size)) {
113 res = -EFAULT;
114 goto out_unlock;
116 res = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
117 if (res != 6) {
118 res = -EFAULT;
119 goto out_unlock;
121 priv->adapter->sp.sp_error = p1;
122 priv->adapter->sp.sp_offset = p2;
123 priv->adapter->sp.sp_stabletime = p3;
124 priv->adapter->sp.sp_calcontrol = p4;
125 priv->adapter->sp.sp_extsleepclk = p5;
126 priv->adapter->sp.sp_reserved = p6;
128 res = lbs_prepare_and_send_command(priv,
129 CMD_802_11_SLEEP_PARAMS,
130 CMD_ACT_SET,
131 CMD_OPTION_WAITFORRSP, 0, NULL);
133 if (!res)
134 res = count;
135 else
136 res = -EINVAL;
138 out_unlock:
139 free_page(addr);
140 return res;
143 static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
144 size_t count, loff_t *ppos)
146 struct lbs_private *priv = file->private_data;
147 struct lbs_adapter *adapter = priv->adapter;
148 ssize_t res;
149 size_t pos = 0;
150 unsigned long addr = get_zeroed_page(GFP_KERNEL);
151 char *buf = (char *)addr;
153 res = lbs_prepare_and_send_command(priv,
154 CMD_802_11_SLEEP_PARAMS,
155 CMD_ACT_GET,
156 CMD_OPTION_WAITFORRSP, 0, NULL);
157 if (res) {
158 res = -EFAULT;
159 goto out_unlock;
162 pos += snprintf(buf, len, "%d %d %d %d %d %d\n", adapter->sp.sp_error,
163 adapter->sp.sp_offset, adapter->sp.sp_stabletime,
164 adapter->sp.sp_calcontrol, adapter->sp.sp_extsleepclk,
165 adapter->sp.sp_reserved);
167 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
169 out_unlock:
170 free_page(addr);
171 return res;
174 static ssize_t lbs_extscan(struct file *file, const char __user *userbuf,
175 size_t count, loff_t *ppos)
177 struct lbs_private *priv = file->private_data;
178 ssize_t res, buf_size;
179 union iwreq_data wrqu;
180 unsigned long addr = get_zeroed_page(GFP_KERNEL);
181 char *buf = (char *)addr;
183 buf_size = min(count, len - 1);
184 if (copy_from_user(buf, userbuf, buf_size)) {
185 res = -EFAULT;
186 goto out_unlock;
189 lbs_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0);
191 memset(&wrqu, 0, sizeof(union iwreq_data));
192 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
194 out_unlock:
195 free_page(addr);
196 return count;
199 static void lbs_parse_bssid(char *buf, size_t count,
200 struct lbs_ioctl_user_scan_cfg *scan_cfg)
202 char *hold;
203 unsigned int mac[ETH_ALEN];
205 hold = strstr(buf, "bssid=");
206 if (!hold)
207 return;
208 hold += 6;
209 sscanf(hold, "%02x:%02x:%02x:%02x:%02x:%02x",
210 mac, mac+1, mac+2, mac+3, mac+4, mac+5);
211 memcpy(scan_cfg->bssid, mac, ETH_ALEN);
214 static void lbs_parse_ssid(char *buf, size_t count,
215 struct lbs_ioctl_user_scan_cfg *scan_cfg)
217 char *hold, *end;
218 ssize_t size;
220 hold = strstr(buf, "ssid=");
221 if (!hold)
222 return;
223 hold += 5;
224 end = strchr(hold, ' ');
225 if (!end)
226 end = buf + count - 1;
228 size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
229 strncpy(scan_cfg->ssid, hold, size);
231 return;
234 static int lbs_parse_clear(char *buf, size_t count, const char *tag)
236 char *hold;
237 int val;
239 hold = strstr(buf, tag);
240 if (!hold)
241 return 0;
242 hold += strlen(tag);
243 sscanf(hold, "%d", &val);
245 if (val != 0)
246 val = 1;
248 return val;
251 static int lbs_parse_dur(char *buf, size_t count,
252 struct lbs_ioctl_user_scan_cfg *scan_cfg)
254 char *hold;
255 int val;
257 hold = strstr(buf, "dur=");
258 if (!hold)
259 return 0;
260 hold += 4;
261 sscanf(hold, "%d", &val);
263 return val;
266 static void lbs_parse_type(char *buf, size_t count,
267 struct lbs_ioctl_user_scan_cfg *scan_cfg)
269 char *hold;
270 int val;
272 hold = strstr(buf, "type=");
273 if (!hold)
274 return;
275 hold += 5;
276 sscanf(hold, "%d", &val);
278 /* type=1,2 or 3 */
279 if (val < 1 || val > 3)
280 return;
282 scan_cfg->bsstype = val;
284 return;
287 static ssize_t lbs_setuserscan(struct file *file,
288 const char __user *userbuf,
289 size_t count, loff_t *ppos)
291 struct lbs_private *priv = file->private_data;
292 ssize_t res, buf_size;
293 struct lbs_ioctl_user_scan_cfg *scan_cfg;
294 union iwreq_data wrqu;
295 int dur;
296 unsigned long addr = get_zeroed_page(GFP_KERNEL);
297 char *buf = (char *)addr;
299 scan_cfg = kzalloc(sizeof(struct lbs_ioctl_user_scan_cfg), GFP_KERNEL);
300 if (!scan_cfg)
301 return -ENOMEM;
303 buf_size = min(count, len - 1);
304 if (copy_from_user(buf, userbuf, buf_size)) {
305 res = -EFAULT;
306 goto out_unlock;
309 scan_cfg->bsstype = LBS_SCAN_BSS_TYPE_ANY;
311 dur = lbs_parse_dur(buf, count, scan_cfg);
312 lbs_parse_bssid(buf, count, scan_cfg);
313 scan_cfg->clear_bssid = lbs_parse_clear(buf, count, "clear_bssid=");
314 lbs_parse_ssid(buf, count, scan_cfg);
315 scan_cfg->clear_ssid = lbs_parse_clear(buf, count, "clear_ssid=");
316 lbs_parse_type(buf, count, scan_cfg);
318 lbs_scan_networks(priv, scan_cfg, 1);
319 wait_event_interruptible(priv->adapter->cmd_pending,
320 !priv->adapter->nr_cmd_pending);
322 memset(&wrqu, 0x00, sizeof(union iwreq_data));
323 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
325 out_unlock:
326 free_page(addr);
327 kfree(scan_cfg);
328 return count;
333 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
334 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
335 * firmware. Here's an example:
336 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
337 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
338 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
340 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
341 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
342 * defined in mrvlietypes_thresholds
344 * This function searches in this TLV data chunk for a given TLV type
345 * and returns a pointer to the first data byte of the TLV, or to NULL
346 * if the TLV hasn't been found.
348 static void *lbs_tlv_find(u16 tlv_type, const u8 *tlv, u16 size)
350 __le16 le_type = cpu_to_le16(tlv_type);
351 ssize_t pos = 0;
352 struct mrvlietypesheader *tlv_h;
353 while (pos < size) {
354 u16 length;
355 tlv_h = (struct mrvlietypesheader *) tlv;
356 if (tlv_h->type == le_type)
357 return tlv_h;
358 if (tlv_h->len == 0)
359 return NULL;
360 length = le16_to_cpu(tlv_h->len) +
361 sizeof(struct mrvlietypesheader);
362 pos += length;
363 tlv += length;
365 return NULL;
370 * This just gets the bitmap of currently subscribed events. Used when
371 * adding an additonal event subscription.
373 static u16 lbs_get_events_bitmap(struct lbs_private *priv)
375 ssize_t res;
377 struct cmd_ds_802_11_subscribe_event *events = kzalloc(
378 sizeof(struct cmd_ds_802_11_subscribe_event),
379 GFP_KERNEL);
381 res = lbs_prepare_and_send_command(priv,
382 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
383 CMD_OPTION_WAITFORRSP, 0, events);
385 if (res) {
386 kfree(events);
387 return 0;
389 return le16_to_cpu(events->events);
393 static ssize_t lbs_threshold_read(
394 u16 tlv_type, u16 event_mask,
395 struct file *file, char __user *userbuf,
396 size_t count, loff_t *ppos)
398 struct lbs_private *priv = file->private_data;
399 ssize_t res = 0;
400 size_t pos = 0;
401 unsigned long addr = get_zeroed_page(GFP_KERNEL);
402 char *buf = (char *)addr;
403 u8 value;
404 u8 freq;
406 struct cmd_ds_802_11_subscribe_event *events = kzalloc(
407 sizeof(struct cmd_ds_802_11_subscribe_event),
408 GFP_KERNEL);
409 struct mrvlietypes_thresholds *got;
411 res = lbs_prepare_and_send_command(priv,
412 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
413 CMD_OPTION_WAITFORRSP, 0, events);
414 if (res) {
415 kfree(events);
416 return res;
419 got = lbs_tlv_find(tlv_type, events->tlv, sizeof(events->tlv));
420 if (got) {
421 value = got->value;
422 freq = got->freq;
424 kfree(events);
426 if (got)
427 pos += snprintf(buf, len, "%d %d %d\n", value, freq,
428 !!(le16_to_cpu(events->events) & event_mask));
430 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
432 free_page(addr);
433 return res;
437 static ssize_t lbs_threshold_write(
438 u16 tlv_type, u16 event_mask,
439 struct file *file,
440 const char __user *userbuf,
441 size_t count, loff_t *ppos)
443 struct lbs_private *priv = file->private_data;
444 ssize_t res, buf_size;
445 int value, freq, curr_mask, new_mask;
446 unsigned long addr = get_zeroed_page(GFP_KERNEL);
447 char *buf = (char *)addr;
448 struct cmd_ds_802_11_subscribe_event *events;
450 buf_size = min(count, len - 1);
451 if (copy_from_user(buf, userbuf, buf_size)) {
452 res = -EFAULT;
453 goto out_unlock;
455 res = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
456 if (res != 3) {
457 res = -EFAULT;
458 goto out_unlock;
460 curr_mask = lbs_get_events_bitmap(priv);
462 if (new_mask)
463 new_mask = curr_mask | event_mask;
464 else
465 new_mask = curr_mask & ~event_mask;
467 /* Now everything is set and we can send stuff down to the firmware */
468 events = kzalloc(
469 sizeof(struct cmd_ds_802_11_subscribe_event),
470 GFP_KERNEL);
471 if (events) {
472 struct mrvlietypes_thresholds *tlv =
473 (struct mrvlietypes_thresholds *) events->tlv;
474 events->action = cpu_to_le16(CMD_ACT_SET);
475 events->events = cpu_to_le16(new_mask);
476 tlv->header.type = cpu_to_le16(tlv_type);
477 tlv->header.len = cpu_to_le16(
478 sizeof(struct mrvlietypes_thresholds) -
479 sizeof(struct mrvlietypesheader));
480 tlv->value = value;
481 if (tlv_type != TLV_TYPE_BCNMISS)
482 tlv->freq = freq;
483 lbs_prepare_and_send_command(priv,
484 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_SET,
485 CMD_OPTION_WAITFORRSP, 0, events);
486 kfree(events);
489 res = count;
490 out_unlock:
491 free_page(addr);
492 return res;
496 static ssize_t lbs_lowrssi_read(
497 struct file *file, char __user *userbuf,
498 size_t count, loff_t *ppos)
500 return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
501 file, userbuf, count, ppos);
505 static ssize_t lbs_lowrssi_write(
506 struct file *file, const char __user *userbuf,
507 size_t count, loff_t *ppos)
509 return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
510 file, userbuf, count, ppos);
514 static ssize_t lbs_lowsnr_read(
515 struct file *file, char __user *userbuf,
516 size_t count, loff_t *ppos)
518 return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
519 file, userbuf, count, ppos);
523 static ssize_t lbs_lowsnr_write(
524 struct file *file, const char __user *userbuf,
525 size_t count, loff_t *ppos)
527 return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
528 file, userbuf, count, ppos);
532 static ssize_t lbs_failcount_read(
533 struct file *file, char __user *userbuf,
534 size_t count, loff_t *ppos)
536 return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
537 file, userbuf, count, ppos);
541 static ssize_t lbs_failcount_write(
542 struct file *file, const char __user *userbuf,
543 size_t count, loff_t *ppos)
545 return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
546 file, userbuf, count, ppos);
550 static ssize_t lbs_highrssi_read(
551 struct file *file, char __user *userbuf,
552 size_t count, loff_t *ppos)
554 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
555 file, userbuf, count, ppos);
559 static ssize_t lbs_highrssi_write(
560 struct file *file, const char __user *userbuf,
561 size_t count, loff_t *ppos)
563 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
564 file, userbuf, count, ppos);
568 static ssize_t lbs_highsnr_read(
569 struct file *file, char __user *userbuf,
570 size_t count, loff_t *ppos)
572 return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
573 file, userbuf, count, ppos);
577 static ssize_t lbs_highsnr_write(
578 struct file *file, const char __user *userbuf,
579 size_t count, loff_t *ppos)
581 return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
582 file, userbuf, count, ppos);
585 static ssize_t lbs_bcnmiss_read(
586 struct file *file, char __user *userbuf,
587 size_t count, loff_t *ppos)
589 return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
590 file, userbuf, count, ppos);
594 static ssize_t lbs_bcnmiss_write(
595 struct file *file, const char __user *userbuf,
596 size_t count, loff_t *ppos)
598 return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
599 file, userbuf, count, ppos);
609 static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
610 size_t count, loff_t *ppos)
612 struct lbs_private *priv = file->private_data;
613 struct lbs_adapter *adapter = priv->adapter;
614 struct lbs_offset_value offval;
615 ssize_t pos = 0;
616 int ret;
617 unsigned long addr = get_zeroed_page(GFP_KERNEL);
618 char *buf = (char *)addr;
620 offval.offset = priv->mac_offset;
621 offval.value = 0;
623 ret = lbs_prepare_and_send_command(priv,
624 CMD_MAC_REG_ACCESS, 0,
625 CMD_OPTION_WAITFORRSP, 0, &offval);
626 mdelay(10);
627 pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
628 priv->mac_offset, adapter->offsetvalue.value);
630 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
631 free_page(addr);
632 return ret;
635 static ssize_t lbs_rdmac_write(struct file *file,
636 const char __user *userbuf,
637 size_t count, loff_t *ppos)
639 struct lbs_private *priv = file->private_data;
640 ssize_t res, buf_size;
641 unsigned long addr = get_zeroed_page(GFP_KERNEL);
642 char *buf = (char *)addr;
644 buf_size = min(count, len - 1);
645 if (copy_from_user(buf, userbuf, buf_size)) {
646 res = -EFAULT;
647 goto out_unlock;
649 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
650 res = count;
651 out_unlock:
652 free_page(addr);
653 return res;
656 static ssize_t lbs_wrmac_write(struct file *file,
657 const char __user *userbuf,
658 size_t count, loff_t *ppos)
661 struct lbs_private *priv = file->private_data;
662 ssize_t res, buf_size;
663 u32 offset, value;
664 struct lbs_offset_value offval;
665 unsigned long addr = get_zeroed_page(GFP_KERNEL);
666 char *buf = (char *)addr;
668 buf_size = min(count, len - 1);
669 if (copy_from_user(buf, userbuf, buf_size)) {
670 res = -EFAULT;
671 goto out_unlock;
673 res = sscanf(buf, "%x %x", &offset, &value);
674 if (res != 2) {
675 res = -EFAULT;
676 goto out_unlock;
679 offval.offset = offset;
680 offval.value = value;
681 res = lbs_prepare_and_send_command(priv,
682 CMD_MAC_REG_ACCESS, 1,
683 CMD_OPTION_WAITFORRSP, 0, &offval);
684 mdelay(10);
686 res = count;
687 out_unlock:
688 free_page(addr);
689 return res;
692 static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
693 size_t count, loff_t *ppos)
695 struct lbs_private *priv = file->private_data;
696 struct lbs_adapter *adapter = priv->adapter;
697 struct lbs_offset_value offval;
698 ssize_t pos = 0;
699 int ret;
700 unsigned long addr = get_zeroed_page(GFP_KERNEL);
701 char *buf = (char *)addr;
703 offval.offset = priv->bbp_offset;
704 offval.value = 0;
706 ret = lbs_prepare_and_send_command(priv,
707 CMD_BBP_REG_ACCESS, 0,
708 CMD_OPTION_WAITFORRSP, 0, &offval);
709 mdelay(10);
710 pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
711 priv->bbp_offset, adapter->offsetvalue.value);
713 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
714 free_page(addr);
716 return ret;
719 static ssize_t lbs_rdbbp_write(struct file *file,
720 const char __user *userbuf,
721 size_t count, loff_t *ppos)
723 struct lbs_private *priv = file->private_data;
724 ssize_t res, buf_size;
725 unsigned long addr = get_zeroed_page(GFP_KERNEL);
726 char *buf = (char *)addr;
728 buf_size = min(count, len - 1);
729 if (copy_from_user(buf, userbuf, buf_size)) {
730 res = -EFAULT;
731 goto out_unlock;
733 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
734 res = count;
735 out_unlock:
736 free_page(addr);
737 return res;
740 static ssize_t lbs_wrbbp_write(struct file *file,
741 const char __user *userbuf,
742 size_t count, loff_t *ppos)
745 struct lbs_private *priv = file->private_data;
746 ssize_t res, buf_size;
747 u32 offset, value;
748 struct lbs_offset_value offval;
749 unsigned long addr = get_zeroed_page(GFP_KERNEL);
750 char *buf = (char *)addr;
752 buf_size = min(count, len - 1);
753 if (copy_from_user(buf, userbuf, buf_size)) {
754 res = -EFAULT;
755 goto out_unlock;
757 res = sscanf(buf, "%x %x", &offset, &value);
758 if (res != 2) {
759 res = -EFAULT;
760 goto out_unlock;
763 offval.offset = offset;
764 offval.value = value;
765 res = lbs_prepare_and_send_command(priv,
766 CMD_BBP_REG_ACCESS, 1,
767 CMD_OPTION_WAITFORRSP, 0, &offval);
768 mdelay(10);
770 res = count;
771 out_unlock:
772 free_page(addr);
773 return res;
776 static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
777 size_t count, loff_t *ppos)
779 struct lbs_private *priv = file->private_data;
780 struct lbs_adapter *adapter = priv->adapter;
781 struct lbs_offset_value offval;
782 ssize_t pos = 0;
783 int ret;
784 unsigned long addr = get_zeroed_page(GFP_KERNEL);
785 char *buf = (char *)addr;
787 offval.offset = priv->rf_offset;
788 offval.value = 0;
790 ret = lbs_prepare_and_send_command(priv,
791 CMD_RF_REG_ACCESS, 0,
792 CMD_OPTION_WAITFORRSP, 0, &offval);
793 mdelay(10);
794 pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
795 priv->rf_offset, adapter->offsetvalue.value);
797 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
798 free_page(addr);
800 return ret;
803 static ssize_t lbs_rdrf_write(struct file *file,
804 const char __user *userbuf,
805 size_t count, loff_t *ppos)
807 struct lbs_private *priv = file->private_data;
808 ssize_t res, buf_size;
809 unsigned long addr = get_zeroed_page(GFP_KERNEL);
810 char *buf = (char *)addr;
812 buf_size = min(count, len - 1);
813 if (copy_from_user(buf, userbuf, buf_size)) {
814 res = -EFAULT;
815 goto out_unlock;
817 priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
818 res = count;
819 out_unlock:
820 free_page(addr);
821 return res;
824 static ssize_t lbs_wrrf_write(struct file *file,
825 const char __user *userbuf,
826 size_t count, loff_t *ppos)
829 struct lbs_private *priv = file->private_data;
830 ssize_t res, buf_size;
831 u32 offset, value;
832 struct lbs_offset_value offval;
833 unsigned long addr = get_zeroed_page(GFP_KERNEL);
834 char *buf = (char *)addr;
836 buf_size = min(count, len - 1);
837 if (copy_from_user(buf, userbuf, buf_size)) {
838 res = -EFAULT;
839 goto out_unlock;
841 res = sscanf(buf, "%x %x", &offset, &value);
842 if (res != 2) {
843 res = -EFAULT;
844 goto out_unlock;
847 offval.offset = offset;
848 offval.value = value;
849 res = lbs_prepare_and_send_command(priv,
850 CMD_RF_REG_ACCESS, 1,
851 CMD_OPTION_WAITFORRSP, 0, &offval);
852 mdelay(10);
854 res = count;
855 out_unlock:
856 free_page(addr);
857 return res;
860 #define FOPS(fread, fwrite) { \
861 .owner = THIS_MODULE, \
862 .open = open_file_generic, \
863 .read = (fread), \
864 .write = (fwrite), \
867 struct lbs_debugfs_files {
868 char *name;
869 int perm;
870 struct file_operations fops;
873 static struct lbs_debugfs_files debugfs_files[] = {
874 { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
875 { "getscantable", 0444, FOPS(lbs_getscantable,
876 write_file_dummy), },
877 { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
878 lbs_sleepparams_write), },
879 { "extscan", 0600, FOPS(NULL, lbs_extscan), },
880 { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), },
883 static struct lbs_debugfs_files debugfs_events_files[] = {
884 {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
885 lbs_lowrssi_write), },
886 {"low_snr", 0644, FOPS(lbs_lowsnr_read,
887 lbs_lowsnr_write), },
888 {"failure_count", 0644, FOPS(lbs_failcount_read,
889 lbs_failcount_write), },
890 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
891 lbs_bcnmiss_write), },
892 {"high_rssi", 0644, FOPS(lbs_highrssi_read,
893 lbs_highrssi_write), },
894 {"high_snr", 0644, FOPS(lbs_highsnr_read,
895 lbs_highsnr_write), },
898 static struct lbs_debugfs_files debugfs_regs_files[] = {
899 {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
900 {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
901 {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
902 {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
903 {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
904 {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
907 void lbs_debugfs_init(void)
909 if (!lbs_dir)
910 lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
912 return;
915 void lbs_debugfs_remove(void)
917 if (lbs_dir)
918 debugfs_remove(lbs_dir);
919 return;
922 void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
924 int i;
925 struct lbs_debugfs_files *files;
926 if (!lbs_dir)
927 goto exit;
929 priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
930 if (!priv->debugfs_dir)
931 goto exit;
933 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
934 files = &debugfs_files[i];
935 priv->debugfs_files[i] = debugfs_create_file(files->name,
936 files->perm,
937 priv->debugfs_dir,
938 priv,
939 &files->fops);
942 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
943 if (!priv->events_dir)
944 goto exit;
946 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
947 files = &debugfs_events_files[i];
948 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
949 files->perm,
950 priv->events_dir,
951 priv,
952 &files->fops);
955 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
956 if (!priv->regs_dir)
957 goto exit;
959 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
960 files = &debugfs_regs_files[i];
961 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
962 files->perm,
963 priv->regs_dir,
964 priv,
965 &files->fops);
968 #ifdef PROC_DEBUG
969 lbs_debug_init(priv, dev);
970 #endif
971 exit:
972 return;
975 void lbs_debugfs_remove_one(struct lbs_private *priv)
977 int i;
979 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
980 debugfs_remove(priv->debugfs_regs_files[i]);
982 debugfs_remove(priv->regs_dir);
984 for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
985 debugfs_remove(priv->debugfs_events_files[i]);
987 debugfs_remove(priv->events_dir);
988 #ifdef PROC_DEBUG
989 debugfs_remove(priv->debugfs_debug);
990 #endif
991 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
992 debugfs_remove(priv->debugfs_files[i]);
993 debugfs_remove(priv->debugfs_dir);
998 /* debug entry */
1000 #ifdef PROC_DEBUG
1002 #define item_size(n) (FIELD_SIZEOF(struct lbs_adapter, n))
1003 #define item_addr(n) (offsetof(struct lbs_adapter, n))
1006 struct debug_data {
1007 char name[32];
1008 u32 size;
1009 size_t addr;
1012 /* To debug any member of struct lbs_adapter, simply add one line here.
1014 static struct debug_data items[] = {
1015 {"intcounter", item_size(intcounter), item_addr(intcounter)},
1016 {"psmode", item_size(psmode), item_addr(psmode)},
1017 {"psstate", item_size(psstate), item_addr(psstate)},
1020 static int num_of_items = ARRAY_SIZE(items);
1023 * @brief proc read function
1025 * @param page pointer to buffer
1026 * @param s read data starting position
1027 * @param off offset
1028 * @param cnt counter
1029 * @param eof end of file flag
1030 * @param data data to output
1031 * @return number of output data
1033 static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
1034 size_t count, loff_t *ppos)
1036 int val = 0;
1037 size_t pos = 0;
1038 ssize_t res;
1039 char *p;
1040 int i;
1041 struct debug_data *d;
1042 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1043 char *buf = (char *)addr;
1045 p = buf;
1047 d = (struct debug_data *)file->private_data;
1049 for (i = 0; i < num_of_items; i++) {
1050 if (d[i].size == 1)
1051 val = *((u8 *) d[i].addr);
1052 else if (d[i].size == 2)
1053 val = *((u16 *) d[i].addr);
1054 else if (d[i].size == 4)
1055 val = *((u32 *) d[i].addr);
1056 else if (d[i].size == 8)
1057 val = *((u64 *) d[i].addr);
1059 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
1062 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
1064 free_page(addr);
1065 return res;
1069 * @brief proc write function
1071 * @param f file pointer
1072 * @param buf pointer to data buffer
1073 * @param cnt data number to write
1074 * @param data data to write
1075 * @return number of data
1077 static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
1078 size_t cnt, loff_t *ppos)
1080 int r, i;
1081 char *pdata;
1082 char *p;
1083 char *p0;
1084 char *p1;
1085 char *p2;
1086 struct debug_data *d = (struct debug_data *)f->private_data;
1088 pdata = kmalloc(cnt, GFP_KERNEL);
1089 if (pdata == NULL)
1090 return 0;
1092 if (copy_from_user(pdata, buf, cnt)) {
1093 lbs_deb_debugfs("Copy from user failed\n");
1094 kfree(pdata);
1095 return 0;
1098 p0 = pdata;
1099 for (i = 0; i < num_of_items; i++) {
1100 do {
1101 p = strstr(p0, d[i].name);
1102 if (p == NULL)
1103 break;
1104 p1 = strchr(p, '\n');
1105 if (p1 == NULL)
1106 break;
1107 p0 = p1++;
1108 p2 = strchr(p, '=');
1109 if (!p2)
1110 break;
1111 p2++;
1112 r = simple_strtoul(p2, NULL, 0);
1113 if (d[i].size == 1)
1114 *((u8 *) d[i].addr) = (u8) r;
1115 else if (d[i].size == 2)
1116 *((u16 *) d[i].addr) = (u16) r;
1117 else if (d[i].size == 4)
1118 *((u32 *) d[i].addr) = (u32) r;
1119 else if (d[i].size == 8)
1120 *((u64 *) d[i].addr) = (u64) r;
1121 break;
1122 } while (1);
1124 kfree(pdata);
1126 return (ssize_t)cnt;
1129 static struct file_operations lbs_debug_fops = {
1130 .owner = THIS_MODULE,
1131 .open = open_file_generic,
1132 .write = lbs_debugfs_write,
1133 .read = lbs_debugfs_read,
1137 * @brief create debug proc file
1139 * @param priv pointer struct lbs_private
1140 * @param dev pointer net_device
1141 * @return N/A
1143 static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev)
1145 int i;
1147 if (!priv->debugfs_dir)
1148 return;
1150 for (i = 0; i < num_of_items; i++)
1151 items[i].addr += (size_t) priv->adapter;
1153 priv->debugfs_debug = debugfs_create_file("debug", 0644,
1154 priv->debugfs_dir, &items[0],
1155 &lbs_debug_fops);
1157 #endif