patch Makefile.am for GLOBAL_LIBDIR as well
[openwrt.git] / package / libertas / src / debugfs.c
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>
8
9 #include "dev.h"
10 #include "decl.h"
11 #include "host.h"
12 #include "debugfs.h"
13
14 static struct dentry *lbs_dir;
15 static char *szStates[] = {
16 "Connected",
17 "Disconnected"
18 };
19
20 #ifdef PROC_DEBUG
21 static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev);
22 #endif
23
24 static int open_file_generic(struct inode *inode, struct file *file)
25 {
26 file->private_data = inode->i_private;
27 return 0;
28 }
29
30 static ssize_t write_file_dummy(struct file *file, const char __user *buf,
31 size_t count, loff_t *ppos)
32 {
33 return -EINVAL;
34 }
35
36 static const size_t len = PAGE_SIZE;
37
38 static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
39 size_t count, loff_t *ppos)
40 {
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;
46
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);
51
52 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
53
54 free_page(addr);
55 return res;
56 }
57
58
59 static ssize_t lbs_getscantable(struct file *file, char __user *userbuf,
60 size_t count, loff_t *ppos)
61 {
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;
69
70 pos += snprintf(buf+pos, len-pos,
71 "# | ch | rssi | bssid | cap | Qual | SSID \n");
72
73 mutex_lock(&priv->lock);
74 list_for_each_entry (iter_bss, &priv->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);
78
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));
90
91 numscansdone++;
92 }
93 mutex_unlock(&priv->lock);
94
95 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
96
97 free_page(addr);
98 return res;
99 }
100
101 static ssize_t lbs_sleepparams_write(struct file *file,
102 const char __user *user_buf, size_t count,
103 loff_t *ppos)
104 {
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;
110
111 buf_size = min(count, len - 1);
112 if (copy_from_user(buf, user_buf, buf_size)) {
113 res = -EFAULT;
114 goto out_unlock;
115 }
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;
120 }
121 priv->sp.sp_error = p1;
122 priv->sp.sp_offset = p2;
123 priv->sp.sp_stabletime = p3;
124 priv->sp.sp_calcontrol = p4;
125 priv->sp.sp_extsleepclk = p5;
126 priv->sp.sp_reserved = p6;
127
128 res = lbs_prepare_and_send_command(priv,
129 CMD_802_11_SLEEP_PARAMS,
130 CMD_ACT_SET,
131 CMD_OPTION_WAITFORRSP, 0, NULL);
132
133 if (!res)
134 res = count;
135 else
136 res = -EINVAL;
137
138 out_unlock:
139 free_page(addr);
140 return res;
141 }
142
143 static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
144 size_t count, loff_t *ppos)
145 {
146 struct lbs_private *priv = file->private_data;
147 ssize_t res;
148 size_t pos = 0;
149 unsigned long addr = get_zeroed_page(GFP_KERNEL);
150 char *buf = (char *)addr;
151
152 res = lbs_prepare_and_send_command(priv,
153 CMD_802_11_SLEEP_PARAMS,
154 CMD_ACT_GET,
155 CMD_OPTION_WAITFORRSP, 0, NULL);
156 if (res) {
157 res = -EFAULT;
158 goto out_unlock;
159 }
160
161 pos += snprintf(buf, len, "%d %d %d %d %d %d\n", priv->sp.sp_error,
162 priv->sp.sp_offset, priv->sp.sp_stabletime,
163 priv->sp.sp_calcontrol, priv->sp.sp_extsleepclk,
164 priv->sp.sp_reserved);
165
166 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
167
168 out_unlock:
169 free_page(addr);
170 return res;
171 }
172
173 static ssize_t lbs_extscan(struct file *file, const char __user *userbuf,
174 size_t count, loff_t *ppos)
175 {
176 struct lbs_private *priv = file->private_data;
177 ssize_t res, buf_size;
178 union iwreq_data wrqu;
179 unsigned long addr = get_zeroed_page(GFP_KERNEL);
180 char *buf = (char *)addr;
181
182 buf_size = min(count, len - 1);
183 if (copy_from_user(buf, userbuf, buf_size)) {
184 res = -EFAULT;
185 goto out_unlock;
186 }
187
188 lbs_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0);
189
190 memset(&wrqu, 0, sizeof(union iwreq_data));
191 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
192
193 out_unlock:
194 free_page(addr);
195 return count;
196 }
197
198 static void lbs_parse_bssid(char *buf, size_t count,
199 struct lbs_ioctl_user_scan_cfg *scan_cfg)
200 {
201 char *hold;
202 unsigned int mac[ETH_ALEN];
203
204 hold = strstr(buf, "bssid=");
205 if (!hold)
206 return;
207 hold += 6;
208 sscanf(hold, MAC_FMT, mac, mac+1, mac+2, mac+3, mac+4, mac+5);
209 memcpy(scan_cfg->bssid, mac, ETH_ALEN);
210 }
211
212 static void lbs_parse_ssid(char *buf, size_t count,
213 struct lbs_ioctl_user_scan_cfg *scan_cfg)
214 {
215 char *hold, *end;
216 ssize_t size;
217
218 hold = strstr(buf, "ssid=");
219 if (!hold)
220 return;
221 hold += 5;
222 end = strchr(hold, ' ');
223 if (!end)
224 end = buf + count - 1;
225
226 size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
227 strncpy(scan_cfg->ssid, hold, size);
228
229 return;
230 }
231
232 static int lbs_parse_clear(char *buf, size_t count, const char *tag)
233 {
234 char *hold;
235 int val;
236
237 hold = strstr(buf, tag);
238 if (!hold)
239 return 0;
240 hold += strlen(tag);
241 sscanf(hold, "%d", &val);
242
243 if (val != 0)
244 val = 1;
245
246 return val;
247 }
248
249 static int lbs_parse_dur(char *buf, size_t count,
250 struct lbs_ioctl_user_scan_cfg *scan_cfg)
251 {
252 char *hold;
253 int val;
254
255 hold = strstr(buf, "dur=");
256 if (!hold)
257 return 0;
258 hold += 4;
259 sscanf(hold, "%d", &val);
260
261 return val;
262 }
263
264 static void lbs_parse_type(char *buf, size_t count,
265 struct lbs_ioctl_user_scan_cfg *scan_cfg)
266 {
267 char *hold;
268 int val;
269
270 hold = strstr(buf, "type=");
271 if (!hold)
272 return;
273 hold += 5;
274 sscanf(hold, "%d", &val);
275
276 /* type=1,2 or 3 */
277 if (val < 1 || val > 3)
278 return;
279
280 scan_cfg->bsstype = val;
281
282 return;
283 }
284
285 static ssize_t lbs_setuserscan(struct file *file,
286 const char __user *userbuf,
287 size_t count, loff_t *ppos)
288 {
289 struct lbs_private *priv = file->private_data;
290 ssize_t res, buf_size;
291 struct lbs_ioctl_user_scan_cfg *scan_cfg;
292 union iwreq_data wrqu;
293 int dur;
294 char *buf = (char *)get_zeroed_page(GFP_KERNEL);
295
296 if (!buf)
297 return -ENOMEM;
298
299 buf_size = min(count, len - 1);
300 if (copy_from_user(buf, userbuf, buf_size)) {
301 res = -EFAULT;
302 goto out_buf;
303 }
304
305 scan_cfg = kzalloc(sizeof(struct lbs_ioctl_user_scan_cfg), GFP_KERNEL);
306 if (!scan_cfg) {
307 res = -ENOMEM;
308 goto out_buf;
309 }
310 res = count;
311
312 scan_cfg->bsstype = LBS_SCAN_BSS_TYPE_ANY;
313
314 dur = lbs_parse_dur(buf, count, scan_cfg);
315 lbs_parse_bssid(buf, count, scan_cfg);
316 scan_cfg->clear_bssid = lbs_parse_clear(buf, count, "clear_bssid=");
317 lbs_parse_ssid(buf, count, scan_cfg);
318 scan_cfg->clear_ssid = lbs_parse_clear(buf, count, "clear_ssid=");
319 lbs_parse_type(buf, count, scan_cfg);
320
321 lbs_scan_networks(priv, scan_cfg, 1);
322 wait_event_interruptible(priv->cmd_pending,
323 priv->surpriseremoved || !priv->last_scanned_channel);
324
325 if (priv->surpriseremoved)
326 goto out_scan_cfg;
327
328 memset(&wrqu, 0x00, sizeof(union iwreq_data));
329 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
330
331 out_scan_cfg:
332 kfree(scan_cfg);
333 out_buf:
334 free_page((unsigned long)buf);
335 return res;
336 }
337
338
339 /*
340 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
341 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
342 * firmware. Here's an example:
343 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
344 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
345 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
346 *
347 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
348 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
349 * defined in mrvlietypes_thresholds
350 *
351 * This function searches in this TLV data chunk for a given TLV type
352 * and returns a pointer to the first data byte of the TLV, or to NULL
353 * if the TLV hasn't been found.
354 */
355 static void *lbs_tlv_find(u16 tlv_type, const u8 *tlv, u16 size)
356 {
357 __le16 le_type = cpu_to_le16(tlv_type);
358 ssize_t pos = 0;
359 struct mrvlietypesheader *tlv_h;
360 while (pos < size) {
361 u16 length;
362 tlv_h = (struct mrvlietypesheader *) tlv;
363 if (tlv_h->type == le_type)
364 return tlv_h;
365 if (tlv_h->len == 0)
366 return NULL;
367 length = le16_to_cpu(tlv_h->len) +
368 sizeof(struct mrvlietypesheader);
369 pos += length;
370 tlv += length;
371 }
372 return NULL;
373 }
374
375
376 /*
377 * This just gets the bitmap of currently subscribed events. Used when
378 * adding an additonal event subscription.
379 */
380 static u16 lbs_get_events_bitmap(struct lbs_private *priv)
381 {
382 ssize_t res;
383
384 struct cmd_ds_802_11_subscribe_event *events = kzalloc(
385 sizeof(struct cmd_ds_802_11_subscribe_event),
386 GFP_KERNEL);
387
388 res = lbs_prepare_and_send_command(priv,
389 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
390 CMD_OPTION_WAITFORRSP, 0, events);
391
392 if (res) {
393 kfree(events);
394 return 0;
395 }
396 return le16_to_cpu(events->events);
397 }
398
399
400 static ssize_t lbs_threshold_read(
401 u16 tlv_type, u16 event_mask,
402 struct file *file, char __user *userbuf,
403 size_t count, loff_t *ppos)
404 {
405 struct lbs_private *priv = file->private_data;
406 ssize_t res = 0;
407 size_t pos = 0;
408 unsigned long addr = get_zeroed_page(GFP_KERNEL);
409 char *buf = (char *)addr;
410 u8 value;
411 u8 freq;
412 int events = 0;
413
414 struct cmd_ds_802_11_subscribe_event *subscribed = kzalloc(
415 sizeof(struct cmd_ds_802_11_subscribe_event),
416 GFP_KERNEL);
417 struct mrvlietypes_thresholds *got;
418
419 res = lbs_prepare_and_send_command(priv,
420 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
421 CMD_OPTION_WAITFORRSP, 0, subscribed);
422 if (res) {
423 kfree(subscribed);
424 return res;
425 }
426
427 got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
428 if (got) {
429 value = got->value;
430 freq = got->freq;
431 events = le16_to_cpu(subscribed->events);
432 }
433 kfree(subscribed);
434
435 if (got)
436 pos += snprintf(buf, len, "%d %d %d\n", value, freq,
437 !!(events & event_mask));
438
439 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
440
441 free_page(addr);
442 return res;
443 }
444
445
446 static ssize_t lbs_threshold_write(
447 u16 tlv_type, u16 event_mask,
448 struct file *file,
449 const char __user *userbuf,
450 size_t count, loff_t *ppos)
451 {
452 struct lbs_private *priv = file->private_data;
453 ssize_t res, buf_size;
454 int value, freq, curr_mask, new_mask;
455 unsigned long addr = get_zeroed_page(GFP_KERNEL);
456 char *buf = (char *)addr;
457 struct cmd_ds_802_11_subscribe_event *events;
458
459 buf_size = min(count, len - 1);
460 if (copy_from_user(buf, userbuf, buf_size)) {
461 res = -EFAULT;
462 goto out_unlock;
463 }
464 res = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
465 if (res != 3) {
466 res = -EFAULT;
467 goto out_unlock;
468 }
469 curr_mask = lbs_get_events_bitmap(priv);
470
471 if (new_mask)
472 new_mask = curr_mask | event_mask;
473 else
474 new_mask = curr_mask & ~event_mask;
475
476 /* Now everything is set and we can send stuff down to the firmware */
477 events = kzalloc(
478 sizeof(struct cmd_ds_802_11_subscribe_event),
479 GFP_KERNEL);
480 if (events) {
481 struct mrvlietypes_thresholds *tlv =
482 (struct mrvlietypes_thresholds *) events->tlv;
483 events->action = cpu_to_le16(CMD_ACT_SET);
484 events->events = cpu_to_le16(new_mask);
485 tlv->header.type = cpu_to_le16(tlv_type);
486 tlv->header.len = cpu_to_le16(
487 sizeof(struct mrvlietypes_thresholds) -
488 sizeof(struct mrvlietypesheader));
489 tlv->value = value;
490 if (tlv_type != TLV_TYPE_BCNMISS)
491 tlv->freq = freq;
492 lbs_prepare_and_send_command(priv,
493 CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_SET,
494 CMD_OPTION_WAITFORRSP, 0, events);
495 kfree(events);
496 }
497
498 res = count;
499 out_unlock:
500 free_page(addr);
501 return res;
502 }
503
504
505 static ssize_t lbs_lowrssi_read(
506 struct file *file, char __user *userbuf,
507 size_t count, loff_t *ppos)
508 {
509 return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
510 file, userbuf, count, ppos);
511 }
512
513
514 static ssize_t lbs_lowrssi_write(
515 struct file *file, const char __user *userbuf,
516 size_t count, loff_t *ppos)
517 {
518 return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
519 file, userbuf, count, ppos);
520 }
521
522
523 static ssize_t lbs_lowsnr_read(
524 struct file *file, char __user *userbuf,
525 size_t count, loff_t *ppos)
526 {
527 return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
528 file, userbuf, count, ppos);
529 }
530
531
532 static ssize_t lbs_lowsnr_write(
533 struct file *file, const char __user *userbuf,
534 size_t count, loff_t *ppos)
535 {
536 return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
537 file, userbuf, count, ppos);
538 }
539
540
541 static ssize_t lbs_failcount_read(
542 struct file *file, char __user *userbuf,
543 size_t count, loff_t *ppos)
544 {
545 return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
546 file, userbuf, count, ppos);
547 }
548
549
550 static ssize_t lbs_failcount_write(
551 struct file *file, const char __user *userbuf,
552 size_t count, loff_t *ppos)
553 {
554 return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
555 file, userbuf, count, ppos);
556 }
557
558
559 static ssize_t lbs_highrssi_read(
560 struct file *file, char __user *userbuf,
561 size_t count, loff_t *ppos)
562 {
563 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
564 file, userbuf, count, ppos);
565 }
566
567
568 static ssize_t lbs_highrssi_write(
569 struct file *file, const char __user *userbuf,
570 size_t count, loff_t *ppos)
571 {
572 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
573 file, userbuf, count, ppos);
574 }
575
576
577 static ssize_t lbs_highsnr_read(
578 struct file *file, char __user *userbuf,
579 size_t count, loff_t *ppos)
580 {
581 return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
582 file, userbuf, count, ppos);
583 }
584
585
586 static ssize_t lbs_highsnr_write(
587 struct file *file, const char __user *userbuf,
588 size_t count, loff_t *ppos)
589 {
590 return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
591 file, userbuf, count, ppos);
592 }
593
594 static ssize_t lbs_bcnmiss_read(
595 struct file *file, char __user *userbuf,
596 size_t count, loff_t *ppos)
597 {
598 return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
599 file, userbuf, count, ppos);
600 }
601
602
603 static ssize_t lbs_bcnmiss_write(
604 struct file *file, const char __user *userbuf,
605 size_t count, loff_t *ppos)
606 {
607 return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
608 file, userbuf, count, ppos);
609 }
610
611
612
613
614
615
616
617
618 static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
619 size_t count, loff_t *ppos)
620 {
621 struct lbs_private *priv = file->private_data;
622 struct lbs_offset_value offval;
623 ssize_t pos = 0;
624 int ret;
625 unsigned long addr = get_zeroed_page(GFP_KERNEL);
626 char *buf = (char *)addr;
627
628 offval.offset = priv->mac_offset;
629 offval.value = 0;
630
631 ret = lbs_prepare_and_send_command(priv,
632 CMD_MAC_REG_ACCESS, 0,
633 CMD_OPTION_WAITFORRSP, 0, &offval);
634 mdelay(10);
635 pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
636 priv->mac_offset, priv->offsetvalue.value);
637
638 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
639 free_page(addr);
640 return ret;
641 }
642
643 static ssize_t lbs_rdmac_write(struct file *file,
644 const char __user *userbuf,
645 size_t count, loff_t *ppos)
646 {
647 struct lbs_private *priv = file->private_data;
648 ssize_t res, buf_size;
649 unsigned long addr = get_zeroed_page(GFP_KERNEL);
650 char *buf = (char *)addr;
651
652 buf_size = min(count, len - 1);
653 if (copy_from_user(buf, userbuf, buf_size)) {
654 res = -EFAULT;
655 goto out_unlock;
656 }
657 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
658 res = count;
659 out_unlock:
660 free_page(addr);
661 return res;
662 }
663
664 static ssize_t lbs_wrmac_write(struct file *file,
665 const char __user *userbuf,
666 size_t count, loff_t *ppos)
667 {
668
669 struct lbs_private *priv = file->private_data;
670 ssize_t res, buf_size;
671 u32 offset, value;
672 struct lbs_offset_value offval;
673 unsigned long addr = get_zeroed_page(GFP_KERNEL);
674 char *buf = (char *)addr;
675
676 buf_size = min(count, len - 1);
677 if (copy_from_user(buf, userbuf, buf_size)) {
678 res = -EFAULT;
679 goto out_unlock;
680 }
681 res = sscanf(buf, "%x %x", &offset, &value);
682 if (res != 2) {
683 res = -EFAULT;
684 goto out_unlock;
685 }
686
687 offval.offset = offset;
688 offval.value = value;
689 res = lbs_prepare_and_send_command(priv,
690 CMD_MAC_REG_ACCESS, 1,
691 CMD_OPTION_WAITFORRSP, 0, &offval);
692 mdelay(10);
693
694 res = count;
695 out_unlock:
696 free_page(addr);
697 return res;
698 }
699
700 static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
701 size_t count, loff_t *ppos)
702 {
703 struct lbs_private *priv = file->private_data;
704 struct lbs_offset_value offval;
705 ssize_t pos = 0;
706 int ret;
707 unsigned long addr = get_zeroed_page(GFP_KERNEL);
708 char *buf = (char *)addr;
709
710 offval.offset = priv->bbp_offset;
711 offval.value = 0;
712
713 ret = lbs_prepare_and_send_command(priv,
714 CMD_BBP_REG_ACCESS, 0,
715 CMD_OPTION_WAITFORRSP, 0, &offval);
716 mdelay(10);
717 pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
718 priv->bbp_offset, priv->offsetvalue.value);
719
720 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
721 free_page(addr);
722
723 return ret;
724 }
725
726 static ssize_t lbs_rdbbp_write(struct file *file,
727 const char __user *userbuf,
728 size_t count, loff_t *ppos)
729 {
730 struct lbs_private *priv = file->private_data;
731 ssize_t res, buf_size;
732 unsigned long addr = get_zeroed_page(GFP_KERNEL);
733 char *buf = (char *)addr;
734
735 buf_size = min(count, len - 1);
736 if (copy_from_user(buf, userbuf, buf_size)) {
737 res = -EFAULT;
738 goto out_unlock;
739 }
740 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
741 res = count;
742 out_unlock:
743 free_page(addr);
744 return res;
745 }
746
747 static ssize_t lbs_wrbbp_write(struct file *file,
748 const char __user *userbuf,
749 size_t count, loff_t *ppos)
750 {
751
752 struct lbs_private *priv = file->private_data;
753 ssize_t res, buf_size;
754 u32 offset, value;
755 struct lbs_offset_value offval;
756 unsigned long addr = get_zeroed_page(GFP_KERNEL);
757 char *buf = (char *)addr;
758
759 buf_size = min(count, len - 1);
760 if (copy_from_user(buf, userbuf, buf_size)) {
761 res = -EFAULT;
762 goto out_unlock;
763 }
764 res = sscanf(buf, "%x %x", &offset, &value);
765 if (res != 2) {
766 res = -EFAULT;
767 goto out_unlock;
768 }
769
770 offval.offset = offset;
771 offval.value = value;
772 res = lbs_prepare_and_send_command(priv,
773 CMD_BBP_REG_ACCESS, 1,
774 CMD_OPTION_WAITFORRSP, 0, &offval);
775 mdelay(10);
776
777 res = count;
778 out_unlock:
779 free_page(addr);
780 return res;
781 }
782
783 static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
784 size_t count, loff_t *ppos)
785 {
786 struct lbs_private *priv = file->private_data;
787 struct lbs_offset_value offval;
788 ssize_t pos = 0;
789 int ret;
790 unsigned long addr = get_zeroed_page(GFP_KERNEL);
791 char *buf = (char *)addr;
792
793 offval.offset = priv->rf_offset;
794 offval.value = 0;
795
796 ret = lbs_prepare_and_send_command(priv,
797 CMD_RF_REG_ACCESS, 0,
798 CMD_OPTION_WAITFORRSP, 0, &offval);
799 mdelay(10);
800 pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
801 priv->rf_offset, priv->offsetvalue.value);
802
803 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
804 free_page(addr);
805
806 return ret;
807 }
808
809 static ssize_t lbs_rdrf_write(struct file *file,
810 const char __user *userbuf,
811 size_t count, loff_t *ppos)
812 {
813 struct lbs_private *priv = file->private_data;
814 ssize_t res, buf_size;
815 unsigned long addr = get_zeroed_page(GFP_KERNEL);
816 char *buf = (char *)addr;
817
818 buf_size = min(count, len - 1);
819 if (copy_from_user(buf, userbuf, buf_size)) {
820 res = -EFAULT;
821 goto out_unlock;
822 }
823 priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
824 res = count;
825 out_unlock:
826 free_page(addr);
827 return res;
828 }
829
830 static ssize_t lbs_wrrf_write(struct file *file,
831 const char __user *userbuf,
832 size_t count, loff_t *ppos)
833 {
834
835 struct lbs_private *priv = file->private_data;
836 ssize_t res, buf_size;
837 u32 offset, value;
838 struct lbs_offset_value offval;
839 unsigned long addr = get_zeroed_page(GFP_KERNEL);
840 char *buf = (char *)addr;
841
842 buf_size = min(count, len - 1);
843 if (copy_from_user(buf, userbuf, buf_size)) {
844 res = -EFAULT;
845 goto out_unlock;
846 }
847 res = sscanf(buf, "%x %x", &offset, &value);
848 if (res != 2) {
849 res = -EFAULT;
850 goto out_unlock;
851 }
852
853 offval.offset = offset;
854 offval.value = value;
855 res = lbs_prepare_and_send_command(priv,
856 CMD_RF_REG_ACCESS, 1,
857 CMD_OPTION_WAITFORRSP, 0, &offval);
858 mdelay(10);
859
860 res = count;
861 out_unlock:
862 free_page(addr);
863 return res;
864 }
865
866 #define FOPS(fread, fwrite) { \
867 .owner = THIS_MODULE, \
868 .open = open_file_generic, \
869 .read = (fread), \
870 .write = (fwrite), \
871 }
872
873 struct lbs_debugfs_files {
874 char *name;
875 int perm;
876 struct file_operations fops;
877 };
878
879 static struct lbs_debugfs_files debugfs_files[] = {
880 { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
881 { "getscantable", 0444, FOPS(lbs_getscantable,
882 write_file_dummy), },
883 { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
884 lbs_sleepparams_write), },
885 { "extscan", 0600, FOPS(NULL, lbs_extscan), },
886 { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), },
887 };
888
889 static struct lbs_debugfs_files debugfs_events_files[] = {
890 {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
891 lbs_lowrssi_write), },
892 {"low_snr", 0644, FOPS(lbs_lowsnr_read,
893 lbs_lowsnr_write), },
894 {"failure_count", 0644, FOPS(lbs_failcount_read,
895 lbs_failcount_write), },
896 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
897 lbs_bcnmiss_write), },
898 {"high_rssi", 0644, FOPS(lbs_highrssi_read,
899 lbs_highrssi_write), },
900 {"high_snr", 0644, FOPS(lbs_highsnr_read,
901 lbs_highsnr_write), },
902 };
903
904 static struct lbs_debugfs_files debugfs_regs_files[] = {
905 {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
906 {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
907 {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
908 {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
909 {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
910 {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
911 };
912
913 void lbs_debugfs_init(void)
914 {
915 if (!lbs_dir)
916 lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
917
918 return;
919 }
920
921 void lbs_debugfs_remove(void)
922 {
923 if (lbs_dir)
924 debugfs_remove(lbs_dir);
925 return;
926 }
927
928 void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
929 {
930 int i;
931 struct lbs_debugfs_files *files;
932 if (!lbs_dir)
933 goto exit;
934
935 priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
936 if (!priv->debugfs_dir)
937 goto exit;
938
939 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
940 files = &debugfs_files[i];
941 priv->debugfs_files[i] = debugfs_create_file(files->name,
942 files->perm,
943 priv->debugfs_dir,
944 priv,
945 &files->fops);
946 }
947
948 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
949 if (!priv->events_dir)
950 goto exit;
951
952 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
953 files = &debugfs_events_files[i];
954 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
955 files->perm,
956 priv->events_dir,
957 priv,
958 &files->fops);
959 }
960
961 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
962 if (!priv->regs_dir)
963 goto exit;
964
965 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
966 files = &debugfs_regs_files[i];
967 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
968 files->perm,
969 priv->regs_dir,
970 priv,
971 &files->fops);
972 }
973
974 #ifdef PROC_DEBUG
975 lbs_debug_init(priv, dev);
976 #endif
977 exit:
978 return;
979 }
980
981 void lbs_debugfs_remove_one(struct lbs_private *priv)
982 {
983 int i;
984
985 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
986 debugfs_remove(priv->debugfs_regs_files[i]);
987
988 debugfs_remove(priv->regs_dir);
989
990 for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
991 debugfs_remove(priv->debugfs_events_files[i]);
992
993 debugfs_remove(priv->events_dir);
994 #ifdef PROC_DEBUG
995 debugfs_remove(priv->debugfs_debug);
996 #endif
997 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
998 debugfs_remove(priv->debugfs_files[i]);
999 debugfs_remove(priv->debugfs_dir);
1000 }
1001
1002
1003
1004 /* debug entry */
1005
1006 #ifdef PROC_DEBUG
1007
1008 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
1009 #define item_addr(n) (offsetof(struct lbs_private, n))
1010
1011
1012 struct debug_data {
1013 char name[32];
1014 u32 size;
1015 size_t addr;
1016 };
1017
1018 /* To debug any member of struct lbs_private, simply add one line here.
1019 */
1020 static struct debug_data items[] = {
1021 {"intcounter", item_size(intcounter), item_addr(intcounter)},
1022 {"psmode", item_size(psmode), item_addr(psmode)},
1023 {"psstate", item_size(psstate), item_addr(psstate)},
1024 };
1025
1026 static int num_of_items = ARRAY_SIZE(items);
1027
1028 /**
1029 * @brief proc read function
1030 *
1031 * @param page pointer to buffer
1032 * @param s read data starting position
1033 * @param off offset
1034 * @param cnt counter
1035 * @param eof end of file flag
1036 * @param data data to output
1037 * @return number of output data
1038 */
1039 static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
1040 size_t count, loff_t *ppos)
1041 {
1042 int val = 0;
1043 size_t pos = 0;
1044 ssize_t res;
1045 char *p;
1046 int i;
1047 struct debug_data *d;
1048 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1049 char *buf = (char *)addr;
1050
1051 p = buf;
1052
1053 d = (struct debug_data *)file->private_data;
1054
1055 for (i = 0; i < num_of_items; i++) {
1056 if (d[i].size == 1)
1057 val = *((u8 *) d[i].addr);
1058 else if (d[i].size == 2)
1059 val = *((u16 *) d[i].addr);
1060 else if (d[i].size == 4)
1061 val = *((u32 *) d[i].addr);
1062 else if (d[i].size == 8)
1063 val = *((u64 *) d[i].addr);
1064
1065 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
1066 }
1067
1068 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
1069
1070 free_page(addr);
1071 return res;
1072 }
1073
1074 /**
1075 * @brief proc write function
1076 *
1077 * @param f file pointer
1078 * @param buf pointer to data buffer
1079 * @param cnt data number to write
1080 * @param data data to write
1081 * @return number of data
1082 */
1083 static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
1084 size_t cnt, loff_t *ppos)
1085 {
1086 int r, i;
1087 char *pdata;
1088 char *p;
1089 char *p0;
1090 char *p1;
1091 char *p2;
1092 struct debug_data *d = (struct debug_data *)f->private_data;
1093
1094 pdata = kmalloc(cnt, GFP_KERNEL);
1095 if (pdata == NULL)
1096 return 0;
1097
1098 if (copy_from_user(pdata, buf, cnt)) {
1099 lbs_deb_debugfs("Copy from user failed\n");
1100 kfree(pdata);
1101 return 0;
1102 }
1103
1104 p0 = pdata;
1105 for (i = 0; i < num_of_items; i++) {
1106 do {
1107 p = strstr(p0, d[i].name);
1108 if (p == NULL)
1109 break;
1110 p1 = strchr(p, '\n');
1111 if (p1 == NULL)
1112 break;
1113 p0 = p1++;
1114 p2 = strchr(p, '=');
1115 if (!p2)
1116 break;
1117 p2++;
1118 r = simple_strtoul(p2, NULL, 0);
1119 if (d[i].size == 1)
1120 *((u8 *) d[i].addr) = (u8) r;
1121 else if (d[i].size == 2)
1122 *((u16 *) d[i].addr) = (u16) r;
1123 else if (d[i].size == 4)
1124 *((u32 *) d[i].addr) = (u32) r;
1125 else if (d[i].size == 8)
1126 *((u64 *) d[i].addr) = (u64) r;
1127 break;
1128 } while (1);
1129 }
1130 kfree(pdata);
1131
1132 return (ssize_t)cnt;
1133 }
1134
1135 static struct file_operations lbs_debug_fops = {
1136 .owner = THIS_MODULE,
1137 .open = open_file_generic,
1138 .write = lbs_debugfs_write,
1139 .read = lbs_debugfs_read,
1140 };
1141
1142 /**
1143 * @brief create debug proc file
1144 *
1145 * @param priv pointer struct lbs_private
1146 * @param dev pointer net_device
1147 * @return N/A
1148 */
1149 static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev)
1150 {
1151 int i;
1152
1153 if (!priv->debugfs_dir)
1154 return;
1155
1156 for (i = 0; i < num_of_items; i++)
1157 items[i].addr += (size_t) priv;
1158
1159 priv->debugfs_debug = debugfs_create_file("debug", 0644,
1160 priv->debugfs_dir, &items[0],
1161 &lbs_debug_fops);
1162 }
1163 #endif
This page took 0.091075 seconds and 5 git commands to generate.