mwifiex: add bcn_rcv_cnt and bcn_miss_cnt in getlog debugfs
[deliverable/linux.git] / drivers / net / wireless / mwifiex / debugfs.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: debugfs
3 *
65da33f5 4 * Copyright (C) 2011-2014, Marvell International Ltd.
5e6e3a92
BZ
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include <linux/debugfs.h>
21
22#include "main.h"
23#include "11n.h"
24
25
26static struct dentry *mwifiex_dfs_dir;
27
28static char *bss_modes[] = {
f873ded2
MG
29 "UNSPECIFIED",
30 "ADHOC",
31 "STATION",
32 "AP",
33 "AP_VLAN",
34 "WDS",
35 "MONITOR",
36 "MESH_POINT",
37 "P2P_CLIENT",
38 "P2P_GO",
39 "P2P_DEVICE",
5e6e3a92
BZ
40};
41
42/* size/addr for mwifiex_debug_info */
43#define item_size(n) (FIELD_SIZEOF(struct mwifiex_debug_info, n))
44#define item_addr(n) (offsetof(struct mwifiex_debug_info, n))
45
46/* size/addr for struct mwifiex_adapter */
47#define adapter_item_size(n) (FIELD_SIZEOF(struct mwifiex_adapter, n))
48#define adapter_item_addr(n) (offsetof(struct mwifiex_adapter, n))
49
50struct mwifiex_debug_data {
51 char name[32]; /* variable/array name */
52 u32 size; /* size of the variable/array */
53 size_t addr; /* address of the variable/array */
54 int num; /* number of variables in an array */
55};
56
57static struct mwifiex_debug_data items[] = {
58 {"int_counter", item_size(int_counter),
59 item_addr(int_counter), 1},
60 {"wmm_ac_vo", item_size(packets_out[WMM_AC_VO]),
61 item_addr(packets_out[WMM_AC_VO]), 1},
62 {"wmm_ac_vi", item_size(packets_out[WMM_AC_VI]),
63 item_addr(packets_out[WMM_AC_VI]), 1},
64 {"wmm_ac_be", item_size(packets_out[WMM_AC_BE]),
65 item_addr(packets_out[WMM_AC_BE]), 1},
66 {"wmm_ac_bk", item_size(packets_out[WMM_AC_BK]),
67 item_addr(packets_out[WMM_AC_BK]), 1},
5e6e3a92
BZ
68 {"tx_buf_size", item_size(tx_buf_size),
69 item_addr(tx_buf_size), 1},
70 {"curr_tx_buf_size", item_size(curr_tx_buf_size),
71 item_addr(curr_tx_buf_size), 1},
72 {"ps_mode", item_size(ps_mode),
73 item_addr(ps_mode), 1},
74 {"ps_state", item_size(ps_state),
75 item_addr(ps_state), 1},
76 {"is_deep_sleep", item_size(is_deep_sleep),
77 item_addr(is_deep_sleep), 1},
78 {"wakeup_dev_req", item_size(pm_wakeup_card_req),
79 item_addr(pm_wakeup_card_req), 1},
80 {"wakeup_tries", item_size(pm_wakeup_fw_try),
81 item_addr(pm_wakeup_fw_try), 1},
82 {"hs_configured", item_size(is_hs_configured),
83 item_addr(is_hs_configured), 1},
84 {"hs_activated", item_size(hs_activated),
85 item_addr(hs_activated), 1},
86 {"num_tx_timeout", item_size(num_tx_timeout),
87 item_addr(num_tx_timeout), 1},
0c9c4a09
AK
88 {"is_cmd_timedout", item_size(is_cmd_timedout),
89 item_addr(is_cmd_timedout), 1},
5e6e3a92
BZ
90 {"timeout_cmd_id", item_size(timeout_cmd_id),
91 item_addr(timeout_cmd_id), 1},
92 {"timeout_cmd_act", item_size(timeout_cmd_act),
93 item_addr(timeout_cmd_act), 1},
94 {"last_cmd_id", item_size(last_cmd_id),
95 item_addr(last_cmd_id), DBG_CMD_NUM},
96 {"last_cmd_act", item_size(last_cmd_act),
97 item_addr(last_cmd_act), DBG_CMD_NUM},
98 {"last_cmd_index", item_size(last_cmd_index),
99 item_addr(last_cmd_index), 1},
100 {"last_cmd_resp_id", item_size(last_cmd_resp_id),
101 item_addr(last_cmd_resp_id), DBG_CMD_NUM},
102 {"last_cmd_resp_index", item_size(last_cmd_resp_index),
103 item_addr(last_cmd_resp_index), 1},
104 {"last_event", item_size(last_event),
105 item_addr(last_event), DBG_CMD_NUM},
106 {"last_event_index", item_size(last_event_index),
107 item_addr(last_event_index), 1},
108 {"num_cmd_h2c_fail", item_size(num_cmd_host_to_card_failure),
109 item_addr(num_cmd_host_to_card_failure), 1},
110 {"num_cmd_sleep_cfm_fail",
111 item_size(num_cmd_sleep_cfm_host_to_card_failure),
112 item_addr(num_cmd_sleep_cfm_host_to_card_failure), 1},
113 {"num_tx_h2c_fail", item_size(num_tx_host_to_card_failure),
114 item_addr(num_tx_host_to_card_failure), 1},
115 {"num_evt_deauth", item_size(num_event_deauth),
116 item_addr(num_event_deauth), 1},
117 {"num_evt_disassoc", item_size(num_event_disassoc),
118 item_addr(num_event_disassoc), 1},
119 {"num_evt_link_lost", item_size(num_event_link_lost),
120 item_addr(num_event_link_lost), 1},
121 {"num_cmd_deauth", item_size(num_cmd_deauth),
122 item_addr(num_cmd_deauth), 1},
123 {"num_cmd_assoc_ok", item_size(num_cmd_assoc_success),
124 item_addr(num_cmd_assoc_success), 1},
125 {"num_cmd_assoc_fail", item_size(num_cmd_assoc_failure),
126 item_addr(num_cmd_assoc_failure), 1},
127 {"cmd_sent", item_size(cmd_sent),
128 item_addr(cmd_sent), 1},
129 {"data_sent", item_size(data_sent),
130 item_addr(data_sent), 1},
131 {"cmd_resp_received", item_size(cmd_resp_received),
132 item_addr(cmd_resp_received), 1},
133 {"event_received", item_size(event_received),
134 item_addr(event_received), 1},
135
136 /* variables defined in struct mwifiex_adapter */
600f5d90
AK
137 {"cmd_pending", adapter_item_size(cmd_pending),
138 adapter_item_addr(cmd_pending), 1},
5e6e3a92
BZ
139 {"tx_pending", adapter_item_size(tx_pending),
140 adapter_item_addr(tx_pending), 1},
141 {"rx_pending", adapter_item_size(rx_pending),
142 adapter_item_addr(rx_pending), 1},
143};
144
145static int num_of_items = ARRAY_SIZE(items);
146
5e6e3a92
BZ
147/*
148 * Proc info file read handler.
149 *
150 * This function is called when the 'info' file is opened for reading.
151 * It prints the following driver related information -
152 * - Driver name
153 * - Driver version
154 * - Driver extended version
155 * - Interface name
156 * - BSS mode
157 * - Media state (connected or disconnected)
158 * - MAC address
159 * - Total number of Tx bytes
160 * - Total number of Rx bytes
161 * - Total number of Tx packets
162 * - Total number of Rx packets
163 * - Total number of dropped Tx packets
164 * - Total number of dropped Rx packets
165 * - Total number of corrupted Tx packets
166 * - Total number of corrupted Rx packets
167 * - Carrier status (on or off)
168 * - Tx queue status (started or stopped)
169 *
170 * For STA mode drivers, it also prints the following extra -
171 * - ESSID
172 * - BSSID
173 * - Channel
174 * - Region code
175 * - Multicast count
176 * - Multicast addresses
177 */
178static ssize_t
179mwifiex_info_read(struct file *file, char __user *ubuf,
180 size_t count, loff_t *ppos)
181{
182 struct mwifiex_private *priv =
183 (struct mwifiex_private *) file->private_data;
184 struct net_device *netdev = priv->netdev;
185 struct netdev_hw_addr *ha;
47411a06 186 struct netdev_queue *txq;
5e6e3a92
BZ
187 unsigned long page = get_zeroed_page(GFP_KERNEL);
188 char *p = (char *) page, fmt[64];
189 struct mwifiex_bss_info info;
270e58e8 190 ssize_t ret;
5e6e3a92
BZ
191 int i = 0;
192
193 if (!p)
194 return -ENOMEM;
195
196 memset(&info, 0, sizeof(info));
197 ret = mwifiex_get_bss_info(priv, &info);
198 if (ret)
199 goto free_and_exit;
200
201 mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
202
203 if (!priv->version_str[0])
204 mwifiex_get_ver_ext(priv);
205
206 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
207 p += sprintf(p, "driver_version = %s", fmt);
208 p += sprintf(p, "\nverext = %s", priv->version_str);
209 p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
f873ded2
MG
210
211 if (info.bss_mode >= ARRAY_SIZE(bss_modes))
212 p += sprintf(p, "bss_mode=\"%d\"\n", info.bss_mode);
213 else
214 p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
215
5e6e3a92
BZ
216 p += sprintf(p, "media_state=\"%s\"\n",
217 (!priv->media_connected ? "Disconnected" : "Connected"));
037b559a 218 p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
5e6e3a92
BZ
219
220 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
221 p += sprintf(p, "multicast_count=\"%d\"\n",
222 netdev_mc_count(netdev));
223 p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid);
037b559a 224 p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
5e6e3a92 225 p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
5e218b7a 226 p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
5e6e3a92
BZ
227
228 netdev_for_each_mc_addr(ha, netdev)
037b559a
AS
229 p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
230 i++, ha->addr);
5e6e3a92
BZ
231 }
232
233 p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
234 p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
235 p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
236 p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
237 p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
238 p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
239 p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
240 p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
241 p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
242 ? "on" : "off"));
47411a06
AP
243 p += sprintf(p, "tx queue");
244 for (i = 0; i < netdev->num_tx_queues; i++) {
245 txq = netdev_get_tx_queue(netdev, i);
246 p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
247 "stopped" : "started");
248 }
249 p += sprintf(p, "\n");
5e6e3a92
BZ
250
251 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
252 (unsigned long) p - page);
253
254free_and_exit:
255 free_page(page);
256 return ret;
257}
258
1c09bf68
AK
259/*
260 * Proc firmware dump read handler.
261 *
262 * This function is called when the 'fw_dump' file is opened for
263 * reading.
264 * This function dumps firmware memory in different files
265 * (ex. DTCM, ITCM, SQRAM etc.) based on the the segments for
266 * debugging.
267 */
268static ssize_t
269mwifiex_fw_dump_read(struct file *file, char __user *ubuf,
270 size_t count, loff_t *ppos)
271{
272 struct mwifiex_private *priv = file->private_data;
273
274 if (!priv->adapter->if_ops.fw_dump)
275 return -EIO;
276
277 priv->adapter->if_ops.fw_dump(priv->adapter);
278
279 return 0;
280}
281
5e6e3a92
BZ
282/*
283 * Proc getlog file read handler.
284 *
285 * This function is called when the 'getlog' file is opened for reading
286 * It prints the following log information -
287 * - Number of multicast Tx frames
288 * - Number of failed packets
289 * - Number of Tx retries
290 * - Number of multicast Tx retries
291 * - Number of duplicate frames
292 * - Number of RTS successes
293 * - Number of RTS failures
294 * - Number of ACK failures
295 * - Number of fragmented Rx frames
296 * - Number of multicast Rx frames
297 * - Number of FCS errors
298 * - Number of Tx frames
299 * - WEP ICV error counts
d35b6392
XH
300 * - Number of received beacons
301 * - Number of missed beacons
5e6e3a92
BZ
302 */
303static ssize_t
304mwifiex_getlog_read(struct file *file, char __user *ubuf,
305 size_t count, loff_t *ppos)
306{
307 struct mwifiex_private *priv =
308 (struct mwifiex_private *) file->private_data;
309 unsigned long page = get_zeroed_page(GFP_KERNEL);
310 char *p = (char *) page;
270e58e8 311 ssize_t ret;
5e6e3a92
BZ
312 struct mwifiex_ds_get_stats stats;
313
314 if (!p)
315 return -ENOMEM;
316
317 memset(&stats, 0, sizeof(stats));
318 ret = mwifiex_get_stats_info(priv, &stats);
319 if (ret)
320 goto free_and_exit;
321
322 p += sprintf(p, "\n"
323 "mcasttxframe %u\n"
324 "failed %u\n"
325 "retry %u\n"
326 "multiretry %u\n"
327 "framedup %u\n"
328 "rtssuccess %u\n"
329 "rtsfailure %u\n"
330 "ackfailure %u\n"
331 "rxfrag %u\n"
332 "mcastrxframe %u\n"
333 "fcserror %u\n"
334 "txframe %u\n"
335 "wepicverrcnt-1 %u\n"
336 "wepicverrcnt-2 %u\n"
337 "wepicverrcnt-3 %u\n"
d35b6392
XH
338 "wepicverrcnt-4 %u\n"
339 "bcn_rcv_cnt %u\n"
340 "bcn_miss_cnt %u\n",
5e6e3a92
BZ
341 stats.mcast_tx_frame,
342 stats.failed,
343 stats.retry,
344 stats.multi_retry,
345 stats.frame_dup,
346 stats.rts_success,
347 stats.rts_failure,
348 stats.ack_failure,
349 stats.rx_frag,
350 stats.mcast_rx_frame,
351 stats.fcs_error,
352 stats.tx_frame,
353 stats.wep_icv_error[0],
354 stats.wep_icv_error[1],
355 stats.wep_icv_error[2],
d35b6392
XH
356 stats.wep_icv_error[3],
357 stats.bcn_rcv_cnt,
358 stats.bcn_miss_cnt);
5e6e3a92
BZ
359
360
361 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
362 (unsigned long) p - page);
363
364free_and_exit:
365 free_page(page);
366 return ret;
367}
368
369static struct mwifiex_debug_info info;
370
371/*
372 * Proc debug file read handler.
373 *
374 * This function is called when the 'debug' file is opened for reading
375 * It prints the following log information -
376 * - Interrupt count
377 * - WMM AC VO packets count
378 * - WMM AC VI packets count
379 * - WMM AC BE packets count
380 * - WMM AC BK packets count
381 * - Maximum Tx buffer size
382 * - Tx buffer size
383 * - Current Tx buffer size
384 * - Power Save mode
385 * - Power Save state
386 * - Deep Sleep status
387 * - Device wakeup required status
388 * - Number of wakeup tries
389 * - Host Sleep configured status
390 * - Host Sleep activated status
391 * - Number of Tx timeouts
392 * - Number of command timeouts
393 * - Last timed out command ID
394 * - Last timed out command action
395 * - Last command ID
396 * - Last command action
397 * - Last command index
398 * - Last command response ID
399 * - Last command response index
400 * - Last event
401 * - Last event index
402 * - Number of host to card command failures
403 * - Number of sleep confirm command failures
404 * - Number of host to card data failure
405 * - Number of deauthentication events
406 * - Number of disassociation events
407 * - Number of link lost events
408 * - Number of deauthentication commands
409 * - Number of association success commands
410 * - Number of association failure commands
411 * - Number of commands sent
412 * - Number of data packets sent
413 * - Number of command responses received
414 * - Number of events received
415 * - Tx BA stream table (TID, RA)
416 * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
417 */
418static ssize_t
419mwifiex_debug_read(struct file *file, char __user *ubuf,
420 size_t count, loff_t *ppos)
421{
422 struct mwifiex_private *priv =
423 (struct mwifiex_private *) file->private_data;
424 struct mwifiex_debug_data *d = &items[0];
425 unsigned long page = get_zeroed_page(GFP_KERNEL);
426 char *p = (char *) page;
270e58e8 427 ssize_t ret;
5e6e3a92
BZ
428 size_t size, addr;
429 long val;
430 int i, j;
431
432 if (!p)
433 return -ENOMEM;
434
435 ret = mwifiex_get_debug_info(priv, &info);
436 if (ret)
437 goto free_and_exit;
438
439 for (i = 0; i < num_of_items; i++) {
440 p += sprintf(p, "%s=", d[i].name);
441
442 size = d[i].size / d[i].num;
443
444 if (i < (num_of_items - 3))
445 addr = d[i].addr + (size_t) &info;
446 else /* The last 3 items are struct mwifiex_adapter variables */
447 addr = d[i].addr + (size_t) priv->adapter;
448
449 for (j = 0; j < d[i].num; j++) {
450 switch (size) {
451 case 1:
452 val = *((u8 *) addr);
453 break;
454 case 2:
455 val = *((u16 *) addr);
456 break;
457 case 4:
458 val = *((u32 *) addr);
459 break;
460 case 8:
461 val = *((long long *) addr);
462 break;
463 default:
464 val = -1;
465 break;
466 }
467
468 p += sprintf(p, "%#lx ", val);
469 addr += size;
470 }
471
472 p += sprintf(p, "\n");
473 }
474
475 if (info.tx_tbl_num) {
476 p += sprintf(p, "Tx BA stream table:\n");
477 for (i = 0; i < info.tx_tbl_num; i++)
037b559a
AS
478 p += sprintf(p, "tid = %d, ra = %pM\n",
479 info.tx_tbl[i].tid, info.tx_tbl[i].ra);
5e6e3a92
BZ
480 }
481
482 if (info.rx_tbl_num) {
483 p += sprintf(p, "Rx reorder table:\n");
484 for (i = 0; i < info.rx_tbl_num; i++) {
037b559a 485 p += sprintf(p, "tid = %d, ta = %pM, "
5e6e3a92
BZ
486 "start_win = %d, "
487 "win_size = %d, buffer: ",
488 info.rx_tbl[i].tid,
037b559a 489 info.rx_tbl[i].ta,
5e6e3a92
BZ
490 info.rx_tbl[i].start_win,
491 info.rx_tbl[i].win_size);
492
493 for (j = 0; j < info.rx_tbl[i].win_size; j++)
494 p += sprintf(p, "%c ",
495 info.rx_tbl[i].buffer[j] ?
496 '1' : '0');
497
498 p += sprintf(p, "\n");
72df6310
XH
499 }
500 }
501
502 if (info.tdls_peer_num) {
503 p += sprintf(p, "TDLS peer table:\n");
504 for (i = 0; i < info.tdls_peer_num; i++) {
505 p += sprintf(p, "peer = %pM",
506 info.tdls_list[i].peer_addr);
507 p += sprintf(p, "\n");
5e6e3a92
BZ
508 }
509 }
510
511 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
512 (unsigned long) p - page);
513
514free_and_exit:
515 free_page(page);
516 return ret;
517}
518
519static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
520
521/*
522 * Proc regrdwr file write handler.
523 *
524 * This function is called when the 'regrdwr' file is opened for writing
525 *
526 * This function can be used to write to a register.
527 */
528static ssize_t
529mwifiex_regrdwr_write(struct file *file,
530 const char __user *ubuf, size_t count, loff_t *ppos)
531{
532 unsigned long addr = get_zeroed_page(GFP_KERNEL);
533 char *buf = (char *) addr;
c8e49556 534 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
270e58e8 535 int ret;
5e6e3a92
BZ
536 u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
537
538 if (!buf)
539 return -ENOMEM;
540
541
542 if (copy_from_user(buf, ubuf, buf_size)) {
543 ret = -EFAULT;
544 goto done;
545 }
546
547 sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
548
549 if (reg_type == 0 || reg_offset == 0) {
550 ret = -EINVAL;
551 goto done;
552 } else {
553 saved_reg_type = reg_type;
554 saved_reg_offset = reg_offset;
555 saved_reg_value = reg_value;
556 ret = count;
557 }
558done:
559 free_page(addr);
560 return ret;
561}
562
563/*
564 * Proc regrdwr file read handler.
565 *
566 * This function is called when the 'regrdwr' file is opened for reading
567 *
568 * This function can be used to read from a register.
569 */
570static ssize_t
571mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
572 size_t count, loff_t *ppos)
573{
574 struct mwifiex_private *priv =
575 (struct mwifiex_private *) file->private_data;
576 unsigned long addr = get_zeroed_page(GFP_KERNEL);
577 char *buf = (char *) addr;
578 int pos = 0, ret = 0;
579 u32 reg_value;
580
581 if (!buf)
582 return -ENOMEM;
583
584 if (!saved_reg_type) {
585 /* No command has been given */
586 pos += snprintf(buf, PAGE_SIZE, "0");
587 goto done;
588 }
589 /* Set command has been given */
590 if (saved_reg_value != UINT_MAX) {
591 ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
592 saved_reg_value);
593
594 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
595 saved_reg_type, saved_reg_offset,
596 saved_reg_value);
597
598 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
599
600 goto done;
601 }
602 /* Get command has been given */
603 ret = mwifiex_reg_read(priv, saved_reg_type,
604 saved_reg_offset, &reg_value);
605 if (ret) {
606 ret = -EINVAL;
607 goto done;
608 }
609
610 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
611 saved_reg_offset, reg_value);
612
613 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
614
615done:
616 free_page(addr);
617 return ret;
618}
619
620static u32 saved_offset = -1, saved_bytes = -1;
621
622/*
623 * Proc rdeeprom file write handler.
624 *
625 * This function is called when the 'rdeeprom' file is opened for writing
626 *
627 * This function can be used to write to a RDEEPROM location.
628 */
629static ssize_t
630mwifiex_rdeeprom_write(struct file *file,
631 const char __user *ubuf, size_t count, loff_t *ppos)
632{
633 unsigned long addr = get_zeroed_page(GFP_KERNEL);
634 char *buf = (char *) addr;
c8e49556 635 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
5e6e3a92
BZ
636 int ret = 0;
637 int offset = -1, bytes = -1;
638
639 if (!buf)
640 return -ENOMEM;
641
642
643 if (copy_from_user(buf, ubuf, buf_size)) {
644 ret = -EFAULT;
645 goto done;
646 }
647
648 sscanf(buf, "%d %d", &offset, &bytes);
649
650 if (offset == -1 || bytes == -1) {
651 ret = -EINVAL;
652 goto done;
653 } else {
654 saved_offset = offset;
655 saved_bytes = bytes;
656 ret = count;
657 }
658done:
659 free_page(addr);
660 return ret;
661}
662
663/*
664 * Proc rdeeprom read write handler.
665 *
666 * This function is called when the 'rdeeprom' file is opened for reading
667 *
668 * This function can be used to read from a RDEEPROM location.
669 */
670static ssize_t
671mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
672 size_t count, loff_t *ppos)
673{
674 struct mwifiex_private *priv =
675 (struct mwifiex_private *) file->private_data;
676 unsigned long addr = get_zeroed_page(GFP_KERNEL);
677 char *buf = (char *) addr;
270e58e8 678 int pos = 0, ret = 0, i;
5e6e3a92
BZ
679 u8 value[MAX_EEPROM_DATA];
680
681 if (!buf)
682 return -ENOMEM;
683
684 if (saved_offset == -1) {
685 /* No command has been given */
686 pos += snprintf(buf, PAGE_SIZE, "0");
687 goto done;
688 }
689
690 /* Get command has been given */
691 ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
692 (u16) saved_bytes, value);
693 if (ret) {
694 ret = -EINVAL;
695 goto done;
696 }
697
698 pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
699
700 for (i = 0; i < saved_bytes; i++)
701 pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
702
703 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
704
705done:
706 free_page(addr);
707 return ret;
708}
709
937a5045
XH
710/* Proc hscfg file write handler
711 * This function can be used to configure the host sleep parameters.
712 */
713static ssize_t
714mwifiex_hscfg_write(struct file *file, const char __user *ubuf,
715 size_t count, loff_t *ppos)
716{
717 struct mwifiex_private *priv = (void *)file->private_data;
718 unsigned long addr = get_zeroed_page(GFP_KERNEL);
719 char *buf = (char *)addr;
720 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
721 int ret, arg_num;
722 struct mwifiex_ds_hs_cfg hscfg;
723 int conditions = HS_CFG_COND_DEF;
724 u32 gpio = HS_CFG_GPIO_DEF, gap = HS_CFG_GAP_DEF;
725
726 if (!buf)
727 return -ENOMEM;
728
729 if (copy_from_user(buf, ubuf, buf_size)) {
730 ret = -EFAULT;
731 goto done;
732 }
733
734 arg_num = sscanf(buf, "%d %x %x", &conditions, &gpio, &gap);
735
736 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
737
738 if (arg_num > 3) {
739 dev_err(priv->adapter->dev, "Too many arguments\n");
740 ret = -EINVAL;
741 goto done;
742 }
743
744 if (arg_num >= 1 && arg_num < 3)
745 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
746 MWIFIEX_SYNC_CMD, &hscfg);
747
748 if (arg_num) {
749 if (conditions == HS_CFG_CANCEL) {
750 mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
751 ret = count;
752 goto done;
753 }
754 hscfg.conditions = conditions;
755 }
756 if (arg_num >= 2)
757 hscfg.gpio = gpio;
758 if (arg_num == 3)
759 hscfg.gap = gap;
760
761 hscfg.is_invoke_hostcmd = false;
762 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
763 MWIFIEX_SYNC_CMD, &hscfg);
764
765 mwifiex_enable_hs(priv->adapter);
766 priv->adapter->hs_enabling = false;
767 ret = count;
768done:
769 free_page(addr);
770 return ret;
771}
772
773/* Proc hscfg file read handler
774 * This function can be used to read host sleep configuration
775 * parameters from driver.
776 */
777static ssize_t
778mwifiex_hscfg_read(struct file *file, char __user *ubuf,
779 size_t count, loff_t *ppos)
780{
781 struct mwifiex_private *priv = (void *)file->private_data;
782 unsigned long addr = get_zeroed_page(GFP_KERNEL);
783 char *buf = (char *)addr;
784 int pos, ret;
785 struct mwifiex_ds_hs_cfg hscfg;
786
787 if (!buf)
788 return -ENOMEM;
789
790 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
791 MWIFIEX_SYNC_CMD, &hscfg);
792
793 pos = snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", hscfg.conditions,
794 hscfg.gpio, hscfg.gap);
795
796 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
797
798 free_page(addr);
799 return ret;
800}
5e6e3a92
BZ
801
802#define MWIFIEX_DFS_ADD_FILE(name) do { \
803 if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
804 priv, &mwifiex_dfs_##name##_fops)) \
805 return; \
806} while (0);
807
808#define MWIFIEX_DFS_FILE_OPS(name) \
809static const struct file_operations mwifiex_dfs_##name##_fops = { \
810 .read = mwifiex_##name##_read, \
811 .write = mwifiex_##name##_write, \
234e3405 812 .open = simple_open, \
5e6e3a92
BZ
813};
814
815#define MWIFIEX_DFS_FILE_READ_OPS(name) \
816static const struct file_operations mwifiex_dfs_##name##_fops = { \
817 .read = mwifiex_##name##_read, \
234e3405 818 .open = simple_open, \
5e6e3a92
BZ
819};
820
821#define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
822static const struct file_operations mwifiex_dfs_##name##_fops = { \
823 .write = mwifiex_##name##_write, \
234e3405 824 .open = simple_open, \
5e6e3a92
BZ
825};
826
827
828MWIFIEX_DFS_FILE_READ_OPS(info);
829MWIFIEX_DFS_FILE_READ_OPS(debug);
830MWIFIEX_DFS_FILE_READ_OPS(getlog);
1c09bf68 831MWIFIEX_DFS_FILE_READ_OPS(fw_dump);
5e6e3a92
BZ
832MWIFIEX_DFS_FILE_OPS(regrdwr);
833MWIFIEX_DFS_FILE_OPS(rdeeprom);
937a5045 834MWIFIEX_DFS_FILE_OPS(hscfg);
5e6e3a92
BZ
835
836/*
837 * This function creates the debug FS directory structure and the files.
838 */
839void
840mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
841{
842 if (!mwifiex_dfs_dir || !priv)
843 return;
844
845 priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
846 mwifiex_dfs_dir);
847
848 if (!priv->dfs_dev_dir)
849 return;
850
851 MWIFIEX_DFS_ADD_FILE(info);
852 MWIFIEX_DFS_ADD_FILE(debug);
853 MWIFIEX_DFS_ADD_FILE(getlog);
854 MWIFIEX_DFS_ADD_FILE(regrdwr);
855 MWIFIEX_DFS_ADD_FILE(rdeeprom);
1c09bf68 856 MWIFIEX_DFS_ADD_FILE(fw_dump);
937a5045 857 MWIFIEX_DFS_ADD_FILE(hscfg);
5e6e3a92
BZ
858}
859
860/*
861 * This function removes the debug FS directory structure and the files.
862 */
863void
864mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
865{
866 if (!priv)
867 return;
868
869 debugfs_remove_recursive(priv->dfs_dev_dir);
5e6e3a92
BZ
870}
871
872/*
873 * This function creates the top level proc directory.
874 */
875void
876mwifiex_debugfs_init(void)
877{
878 if (!mwifiex_dfs_dir)
879 mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
880}
881
882/*
883 * This function removes the top level proc directory.
884 */
885void
886mwifiex_debugfs_remove(void)
887{
888 if (mwifiex_dfs_dir)
889 debugfs_remove(mwifiex_dfs_dir);
890}
This page took 0.59758 seconds and 5 git commands to generate.