Linux 4.4.145
[linux/fpc-iii.git] / drivers / net / wireless / mwifiex / debugfs.c
blob45d97b64ef84b5871dbecd47f423ad1ecd9a98e9
1 /*
2 * Marvell Wireless LAN device driver: debugfs
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
20 #include <linux/debugfs.h>
22 #include "main.h"
23 #include "11n.h"
26 static struct dentry *mwifiex_dfs_dir;
28 static char *bss_modes[] = {
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",
43 * Proc info file read handler.
45 * This function is called when the 'info' file is opened for reading.
46 * It prints the following driver related information -
47 * - Driver name
48 * - Driver version
49 * - Driver extended version
50 * - Interface name
51 * - BSS mode
52 * - Media state (connected or disconnected)
53 * - MAC address
54 * - Total number of Tx bytes
55 * - Total number of Rx bytes
56 * - Total number of Tx packets
57 * - Total number of Rx packets
58 * - Total number of dropped Tx packets
59 * - Total number of dropped Rx packets
60 * - Total number of corrupted Tx packets
61 * - Total number of corrupted Rx packets
62 * - Carrier status (on or off)
63 * - Tx queue status (started or stopped)
65 * For STA mode drivers, it also prints the following extra -
66 * - ESSID
67 * - BSSID
68 * - Channel
69 * - Region code
70 * - Multicast count
71 * - Multicast addresses
73 static ssize_t
74 mwifiex_info_read(struct file *file, char __user *ubuf,
75 size_t count, loff_t *ppos)
77 struct mwifiex_private *priv =
78 (struct mwifiex_private *) file->private_data;
79 struct net_device *netdev = priv->netdev;
80 struct netdev_hw_addr *ha;
81 struct netdev_queue *txq;
82 unsigned long page = get_zeroed_page(GFP_KERNEL);
83 char *p = (char *) page, fmt[64];
84 struct mwifiex_bss_info info;
85 ssize_t ret;
86 int i = 0;
88 if (!p)
89 return -ENOMEM;
91 memset(&info, 0, sizeof(info));
92 ret = mwifiex_get_bss_info(priv, &info);
93 if (ret)
94 goto free_and_exit;
96 mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
98 if (!priv->version_str[0])
99 mwifiex_get_ver_ext(priv);
101 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
102 p += sprintf(p, "driver_version = %s", fmt);
103 p += sprintf(p, "\nverext = %s", priv->version_str);
104 p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
106 if (info.bss_mode >= ARRAY_SIZE(bss_modes))
107 p += sprintf(p, "bss_mode=\"%d\"\n", info.bss_mode);
108 else
109 p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
111 p += sprintf(p, "media_state=\"%s\"\n",
112 (!priv->media_connected ? "Disconnected" : "Connected"));
113 p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
115 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
116 p += sprintf(p, "multicast_count=\"%d\"\n",
117 netdev_mc_count(netdev));
118 p += sprintf(p, "essid=\"%.*s\"\n", info.ssid.ssid_len,
119 info.ssid.ssid);
120 p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
121 p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
122 p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
124 netdev_for_each_mc_addr(ha, netdev)
125 p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
126 i++, ha->addr);
129 p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
130 p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
131 p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
132 p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
133 p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
134 p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
135 p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
136 p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
137 p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
138 ? "on" : "off"));
139 p += sprintf(p, "tx queue");
140 for (i = 0; i < netdev->num_tx_queues; i++) {
141 txq = netdev_get_tx_queue(netdev, i);
142 p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
143 "stopped" : "started");
145 p += sprintf(p, "\n");
147 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
148 (unsigned long) p - page);
150 free_and_exit:
151 free_page(page);
152 return ret;
156 * Proc device dump read handler.
158 * This function is called when the 'device_dump' file is opened for
159 * reading.
160 * This function dumps driver information and firmware memory segments
161 * (ex. DTCM, ITCM, SQRAM etc.) for
162 * debugging.
164 static ssize_t
165 mwifiex_device_dump_read(struct file *file, char __user *ubuf,
166 size_t count, loff_t *ppos)
168 struct mwifiex_private *priv = file->private_data;
170 if (!priv->adapter->if_ops.device_dump)
171 return -EIO;
173 priv->adapter->if_ops.device_dump(priv->adapter);
175 return 0;
179 * Proc getlog file read handler.
181 * This function is called when the 'getlog' file is opened for reading
182 * It prints the following log information -
183 * - Number of multicast Tx frames
184 * - Number of failed packets
185 * - Number of Tx retries
186 * - Number of multicast Tx retries
187 * - Number of duplicate frames
188 * - Number of RTS successes
189 * - Number of RTS failures
190 * - Number of ACK failures
191 * - Number of fragmented Rx frames
192 * - Number of multicast Rx frames
193 * - Number of FCS errors
194 * - Number of Tx frames
195 * - WEP ICV error counts
196 * - Number of received beacons
197 * - Number of missed beacons
199 static ssize_t
200 mwifiex_getlog_read(struct file *file, char __user *ubuf,
201 size_t count, loff_t *ppos)
203 struct mwifiex_private *priv =
204 (struct mwifiex_private *) file->private_data;
205 unsigned long page = get_zeroed_page(GFP_KERNEL);
206 char *p = (char *) page;
207 ssize_t ret;
208 struct mwifiex_ds_get_stats stats;
210 if (!p)
211 return -ENOMEM;
213 memset(&stats, 0, sizeof(stats));
214 ret = mwifiex_get_stats_info(priv, &stats);
215 if (ret)
216 goto free_and_exit;
218 p += sprintf(p, "\n"
219 "mcasttxframe %u\n"
220 "failed %u\n"
221 "retry %u\n"
222 "multiretry %u\n"
223 "framedup %u\n"
224 "rtssuccess %u\n"
225 "rtsfailure %u\n"
226 "ackfailure %u\n"
227 "rxfrag %u\n"
228 "mcastrxframe %u\n"
229 "fcserror %u\n"
230 "txframe %u\n"
231 "wepicverrcnt-1 %u\n"
232 "wepicverrcnt-2 %u\n"
233 "wepicverrcnt-3 %u\n"
234 "wepicverrcnt-4 %u\n"
235 "bcn_rcv_cnt %u\n"
236 "bcn_miss_cnt %u\n",
237 stats.mcast_tx_frame,
238 stats.failed,
239 stats.retry,
240 stats.multi_retry,
241 stats.frame_dup,
242 stats.rts_success,
243 stats.rts_failure,
244 stats.ack_failure,
245 stats.rx_frag,
246 stats.mcast_rx_frame,
247 stats.fcs_error,
248 stats.tx_frame,
249 stats.wep_icv_error[0],
250 stats.wep_icv_error[1],
251 stats.wep_icv_error[2],
252 stats.wep_icv_error[3],
253 stats.bcn_rcv_cnt,
254 stats.bcn_miss_cnt);
257 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
258 (unsigned long) p - page);
260 free_and_exit:
261 free_page(page);
262 return ret;
265 /* Sysfs histogram file read handler.
267 * This function is called when the 'histogram' file is opened for reading
268 * It prints the following histogram information -
269 * - Number of histogram samples
270 * - Receive packet number of each rx_rate
271 * - Receive packet number of each snr
272 * - Receive packet number of each nosie_flr
273 * - Receive packet number of each signal streath
275 static ssize_t
276 mwifiex_histogram_read(struct file *file, char __user *ubuf,
277 size_t count, loff_t *ppos)
279 struct mwifiex_private *priv =
280 (struct mwifiex_private *)file->private_data;
281 ssize_t ret;
282 struct mwifiex_histogram_data *phist_data;
283 int i, value;
284 unsigned long page = get_zeroed_page(GFP_KERNEL);
285 char *p = (char *)page;
287 if (!p)
288 return -ENOMEM;
290 if (!priv || !priv->hist_data)
291 return -EFAULT;
292 phist_data = priv->hist_data;
294 p += sprintf(p, "\n"
295 "total samples = %d\n",
296 atomic_read(&phist_data->num_samples));
298 p += sprintf(p, "rx rates (in Mbps): 0=1M 1=2M");
299 p += sprintf(p, "2=5.5M 3=11M 4=6M 5=9M 6=12M\n");
300 p += sprintf(p, "7=18M 8=24M 9=36M 10=48M 11=54M");
301 p += sprintf(p, "12-27=MCS0-15(BW20) 28-43=MCS0-15(BW40)\n");
303 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
304 p += sprintf(p, "44-53=MCS0-9(VHT:BW20)");
305 p += sprintf(p, "54-63=MCS0-9(VHT:BW40)");
306 p += sprintf(p, "64-73=MCS0-9(VHT:BW80)\n\n");
307 } else {
308 p += sprintf(p, "\n");
311 for (i = 0; i < MWIFIEX_MAX_RX_RATES; i++) {
312 value = atomic_read(&phist_data->rx_rate[i]);
313 if (value)
314 p += sprintf(p, "rx_rate[%02d] = %d\n", i, value);
317 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
318 for (i = MWIFIEX_MAX_RX_RATES; i < MWIFIEX_MAX_AC_RX_RATES;
319 i++) {
320 value = atomic_read(&phist_data->rx_rate[i]);
321 if (value)
322 p += sprintf(p, "rx_rate[%02d] = %d\n",
323 i, value);
327 for (i = 0; i < MWIFIEX_MAX_SNR; i++) {
328 value = atomic_read(&phist_data->snr[i]);
329 if (value)
330 p += sprintf(p, "snr[%02ddB] = %d\n", i, value);
332 for (i = 0; i < MWIFIEX_MAX_NOISE_FLR; i++) {
333 value = atomic_read(&phist_data->noise_flr[i]);
334 if (value)
335 p += sprintf(p, "noise_flr[-%02ddBm] = %d\n",
336 (int)(i-128), value);
338 for (i = 0; i < MWIFIEX_MAX_SIG_STRENGTH; i++) {
339 value = atomic_read(&phist_data->sig_str[i]);
340 if (value)
341 p += sprintf(p, "sig_strength[-%02ddBm] = %d\n",
342 i, value);
345 ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
346 (unsigned long)p - page);
348 return ret;
351 static ssize_t
352 mwifiex_histogram_write(struct file *file, const char __user *ubuf,
353 size_t count, loff_t *ppos)
355 struct mwifiex_private *priv = (void *)file->private_data;
357 if (priv && priv->hist_data)
358 mwifiex_hist_data_reset(priv);
359 return 0;
362 static struct mwifiex_debug_info info;
365 * Proc debug file read handler.
367 * This function is called when the 'debug' file is opened for reading
368 * It prints the following log information -
369 * - Interrupt count
370 * - WMM AC VO packets count
371 * - WMM AC VI packets count
372 * - WMM AC BE packets count
373 * - WMM AC BK packets count
374 * - Maximum Tx buffer size
375 * - Tx buffer size
376 * - Current Tx buffer size
377 * - Power Save mode
378 * - Power Save state
379 * - Deep Sleep status
380 * - Device wakeup required status
381 * - Number of wakeup tries
382 * - Host Sleep configured status
383 * - Host Sleep activated status
384 * - Number of Tx timeouts
385 * - Number of command timeouts
386 * - Last timed out command ID
387 * - Last timed out command action
388 * - Last command ID
389 * - Last command action
390 * - Last command index
391 * - Last command response ID
392 * - Last command response index
393 * - Last event
394 * - Last event index
395 * - Number of host to card command failures
396 * - Number of sleep confirm command failures
397 * - Number of host to card data failure
398 * - Number of deauthentication events
399 * - Number of disassociation events
400 * - Number of link lost events
401 * - Number of deauthentication commands
402 * - Number of association success commands
403 * - Number of association failure commands
404 * - Number of commands sent
405 * - Number of data packets sent
406 * - Number of command responses received
407 * - Number of events received
408 * - Tx BA stream table (TID, RA)
409 * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
411 static ssize_t
412 mwifiex_debug_read(struct file *file, char __user *ubuf,
413 size_t count, loff_t *ppos)
415 struct mwifiex_private *priv =
416 (struct mwifiex_private *) file->private_data;
417 unsigned long page = get_zeroed_page(GFP_KERNEL);
418 char *p = (char *) page;
419 ssize_t ret;
421 if (!p)
422 return -ENOMEM;
424 ret = mwifiex_get_debug_info(priv, &info);
425 if (ret)
426 goto free_and_exit;
428 p += mwifiex_debug_info_to_buffer(priv, p, &info);
430 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
431 (unsigned long) p - page);
433 free_and_exit:
434 free_page(page);
435 return ret;
438 static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
441 * Proc regrdwr file write handler.
443 * This function is called when the 'regrdwr' file is opened for writing
445 * This function can be used to write to a register.
447 static ssize_t
448 mwifiex_regrdwr_write(struct file *file,
449 const char __user *ubuf, size_t count, loff_t *ppos)
451 unsigned long addr = get_zeroed_page(GFP_KERNEL);
452 char *buf = (char *) addr;
453 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
454 int ret;
455 u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
457 if (!buf)
458 return -ENOMEM;
461 if (copy_from_user(buf, ubuf, buf_size)) {
462 ret = -EFAULT;
463 goto done;
466 sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
468 if (reg_type == 0 || reg_offset == 0) {
469 ret = -EINVAL;
470 goto done;
471 } else {
472 saved_reg_type = reg_type;
473 saved_reg_offset = reg_offset;
474 saved_reg_value = reg_value;
475 ret = count;
477 done:
478 free_page(addr);
479 return ret;
483 * Proc regrdwr file read handler.
485 * This function is called when the 'regrdwr' file is opened for reading
487 * This function can be used to read from a register.
489 static ssize_t
490 mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
491 size_t count, loff_t *ppos)
493 struct mwifiex_private *priv =
494 (struct mwifiex_private *) file->private_data;
495 unsigned long addr = get_zeroed_page(GFP_KERNEL);
496 char *buf = (char *) addr;
497 int pos = 0, ret = 0;
498 u32 reg_value;
500 if (!buf)
501 return -ENOMEM;
503 if (!saved_reg_type) {
504 /* No command has been given */
505 pos += snprintf(buf, PAGE_SIZE, "0");
506 goto done;
508 /* Set command has been given */
509 if (saved_reg_value != UINT_MAX) {
510 ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
511 saved_reg_value);
513 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
514 saved_reg_type, saved_reg_offset,
515 saved_reg_value);
517 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
519 goto done;
521 /* Get command has been given */
522 ret = mwifiex_reg_read(priv, saved_reg_type,
523 saved_reg_offset, &reg_value);
524 if (ret) {
525 ret = -EINVAL;
526 goto done;
529 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
530 saved_reg_offset, reg_value);
532 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
534 done:
535 free_page(addr);
536 return ret;
539 /* Proc debug_mask file read handler.
540 * This function is called when the 'debug_mask' file is opened for reading
541 * This function can be used read driver debugging mask value.
543 static ssize_t
544 mwifiex_debug_mask_read(struct file *file, char __user *ubuf,
545 size_t count, loff_t *ppos)
547 struct mwifiex_private *priv =
548 (struct mwifiex_private *)file->private_data;
549 unsigned long page = get_zeroed_page(GFP_KERNEL);
550 char *buf = (char *)page;
551 size_t ret = 0;
552 int pos = 0;
554 if (!buf)
555 return -ENOMEM;
557 pos += snprintf(buf, PAGE_SIZE, "debug mask=0x%08x\n",
558 priv->adapter->debug_mask);
559 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
561 free_page(page);
562 return ret;
565 /* Proc debug_mask file read handler.
566 * This function is called when the 'debug_mask' file is opened for reading
567 * This function can be used read driver debugging mask value.
569 static ssize_t
570 mwifiex_debug_mask_write(struct file *file, const char __user *ubuf,
571 size_t count, loff_t *ppos)
573 int ret;
574 unsigned long debug_mask;
575 struct mwifiex_private *priv = (void *)file->private_data;
576 unsigned long addr = get_zeroed_page(GFP_KERNEL);
577 char *buf = (void *)addr;
578 size_t buf_size = min(count, (size_t)(PAGE_SIZE - 1));
580 if (!buf)
581 return -ENOMEM;
583 if (copy_from_user(buf, ubuf, buf_size)) {
584 ret = -EFAULT;
585 goto done;
588 if (kstrtoul(buf, 0, &debug_mask)) {
589 ret = -EINVAL;
590 goto done;
593 priv->adapter->debug_mask = debug_mask;
594 ret = count;
595 done:
596 free_page(addr);
597 return ret;
600 /* Proc memrw file write handler.
601 * This function is called when the 'memrw' file is opened for writing
602 * This function can be used to write to a memory location.
604 static ssize_t
605 mwifiex_memrw_write(struct file *file, const char __user *ubuf, size_t count,
606 loff_t *ppos)
608 int ret;
609 char cmd;
610 struct mwifiex_ds_mem_rw mem_rw;
611 u16 cmd_action;
612 struct mwifiex_private *priv = (void *)file->private_data;
613 unsigned long addr = get_zeroed_page(GFP_KERNEL);
614 char *buf = (void *)addr;
615 size_t buf_size = min(count, (size_t)(PAGE_SIZE - 1));
617 if (!buf)
618 return -ENOMEM;
620 if (copy_from_user(buf, ubuf, buf_size)) {
621 ret = -EFAULT;
622 goto done;
625 ret = sscanf(buf, "%c %x %x", &cmd, &mem_rw.addr, &mem_rw.value);
626 if (ret != 3) {
627 ret = -EINVAL;
628 goto done;
631 if ((cmd == 'r') || (cmd == 'R')) {
632 cmd_action = HostCmd_ACT_GEN_GET;
633 mem_rw.value = 0;
634 } else if ((cmd == 'w') || (cmd == 'W')) {
635 cmd_action = HostCmd_ACT_GEN_SET;
636 } else {
637 ret = -EINVAL;
638 goto done;
641 memcpy(&priv->mem_rw, &mem_rw, sizeof(mem_rw));
642 if (mwifiex_send_cmd(priv, HostCmd_CMD_MEM_ACCESS, cmd_action, 0,
643 &mem_rw, true))
644 ret = -1;
645 else
646 ret = count;
648 done:
649 free_page(addr);
650 return ret;
653 /* Proc memrw file read handler.
654 * This function is called when the 'memrw' file is opened for reading
655 * This function can be used to read from a memory location.
657 static ssize_t
658 mwifiex_memrw_read(struct file *file, char __user *ubuf,
659 size_t count, loff_t *ppos)
661 struct mwifiex_private *priv = (void *)file->private_data;
662 unsigned long addr = get_zeroed_page(GFP_KERNEL);
663 char *buf = (char *)addr;
664 int ret, pos = 0;
666 if (!buf)
667 return -ENOMEM;
669 pos += snprintf(buf, PAGE_SIZE, "0x%x 0x%x\n", priv->mem_rw.addr,
670 priv->mem_rw.value);
671 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
673 free_page(addr);
674 return ret;
677 static u32 saved_offset = -1, saved_bytes = -1;
680 * Proc rdeeprom file write handler.
682 * This function is called when the 'rdeeprom' file is opened for writing
684 * This function can be used to write to a RDEEPROM location.
686 static ssize_t
687 mwifiex_rdeeprom_write(struct file *file,
688 const char __user *ubuf, size_t count, loff_t *ppos)
690 unsigned long addr = get_zeroed_page(GFP_KERNEL);
691 char *buf = (char *) addr;
692 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
693 int ret = 0;
694 int offset = -1, bytes = -1;
696 if (!buf)
697 return -ENOMEM;
700 if (copy_from_user(buf, ubuf, buf_size)) {
701 ret = -EFAULT;
702 goto done;
705 sscanf(buf, "%d %d", &offset, &bytes);
707 if (offset == -1 || bytes == -1) {
708 ret = -EINVAL;
709 goto done;
710 } else {
711 saved_offset = offset;
712 saved_bytes = bytes;
713 ret = count;
715 done:
716 free_page(addr);
717 return ret;
721 * Proc rdeeprom read write handler.
723 * This function is called when the 'rdeeprom' file is opened for reading
725 * This function can be used to read from a RDEEPROM location.
727 static ssize_t
728 mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
729 size_t count, loff_t *ppos)
731 struct mwifiex_private *priv =
732 (struct mwifiex_private *) file->private_data;
733 unsigned long addr = get_zeroed_page(GFP_KERNEL);
734 char *buf = (char *) addr;
735 int pos, ret, i;
736 u8 value[MAX_EEPROM_DATA];
738 if (!buf)
739 return -ENOMEM;
741 if (saved_offset == -1) {
742 /* No command has been given */
743 pos = snprintf(buf, PAGE_SIZE, "0");
744 goto done;
747 /* Get command has been given */
748 ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
749 (u16) saved_bytes, value);
750 if (ret) {
751 ret = -EINVAL;
752 goto out_free;
755 pos = snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
757 for (i = 0; i < saved_bytes; i++)
758 pos += scnprintf(buf + pos, PAGE_SIZE - pos, "%d ", value[i]);
760 done:
761 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
762 out_free:
763 free_page(addr);
764 return ret;
767 /* Proc hscfg file write handler
768 * This function can be used to configure the host sleep parameters.
770 static ssize_t
771 mwifiex_hscfg_write(struct file *file, const char __user *ubuf,
772 size_t count, loff_t *ppos)
774 struct mwifiex_private *priv = (void *)file->private_data;
775 unsigned long addr = get_zeroed_page(GFP_KERNEL);
776 char *buf = (char *)addr;
777 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
778 int ret, arg_num;
779 struct mwifiex_ds_hs_cfg hscfg;
780 int conditions = HS_CFG_COND_DEF;
781 u32 gpio = HS_CFG_GPIO_DEF, gap = HS_CFG_GAP_DEF;
783 if (!buf)
784 return -ENOMEM;
786 if (copy_from_user(buf, ubuf, buf_size)) {
787 ret = -EFAULT;
788 goto done;
791 arg_num = sscanf(buf, "%d %x %x", &conditions, &gpio, &gap);
793 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
795 if (arg_num > 3) {
796 mwifiex_dbg(priv->adapter, ERROR,
797 "Too many arguments\n");
798 ret = -EINVAL;
799 goto done;
802 if (arg_num >= 1 && arg_num < 3)
803 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
804 MWIFIEX_SYNC_CMD, &hscfg);
806 if (arg_num) {
807 if (conditions == HS_CFG_CANCEL) {
808 mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
809 ret = count;
810 goto done;
812 hscfg.conditions = conditions;
814 if (arg_num >= 2)
815 hscfg.gpio = gpio;
816 if (arg_num == 3)
817 hscfg.gap = gap;
819 hscfg.is_invoke_hostcmd = false;
820 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
821 MWIFIEX_SYNC_CMD, &hscfg);
823 mwifiex_enable_hs(priv->adapter);
824 priv->adapter->hs_enabling = false;
825 ret = count;
826 done:
827 free_page(addr);
828 return ret;
831 /* Proc hscfg file read handler
832 * This function can be used to read host sleep configuration
833 * parameters from driver.
835 static ssize_t
836 mwifiex_hscfg_read(struct file *file, char __user *ubuf,
837 size_t count, loff_t *ppos)
839 struct mwifiex_private *priv = (void *)file->private_data;
840 unsigned long addr = get_zeroed_page(GFP_KERNEL);
841 char *buf = (char *)addr;
842 int pos, ret;
843 struct mwifiex_ds_hs_cfg hscfg;
845 if (!buf)
846 return -ENOMEM;
848 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
849 MWIFIEX_SYNC_CMD, &hscfg);
851 pos = snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", hscfg.conditions,
852 hscfg.gpio, hscfg.gap);
854 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
856 free_page(addr);
857 return ret;
860 static ssize_t
861 mwifiex_timeshare_coex_read(struct file *file, char __user *ubuf,
862 size_t count, loff_t *ppos)
864 struct mwifiex_private *priv = file->private_data;
865 char buf[3];
866 bool timeshare_coex;
867 int ret;
868 unsigned int len;
870 if (priv->adapter->fw_api_ver != MWIFIEX_FW_V15)
871 return -EOPNOTSUPP;
873 ret = mwifiex_send_cmd(priv, HostCmd_CMD_ROBUST_COEX,
874 HostCmd_ACT_GEN_GET, 0, &timeshare_coex, true);
875 if (ret)
876 return ret;
878 len = sprintf(buf, "%d\n", timeshare_coex);
879 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
882 static ssize_t
883 mwifiex_timeshare_coex_write(struct file *file, const char __user *ubuf,
884 size_t count, loff_t *ppos)
886 bool timeshare_coex;
887 struct mwifiex_private *priv = file->private_data;
888 char kbuf[16];
889 int ret;
891 if (priv->adapter->fw_api_ver != MWIFIEX_FW_V15)
892 return -EOPNOTSUPP;
894 memset(kbuf, 0, sizeof(kbuf));
896 if (copy_from_user(&kbuf, ubuf, min_t(size_t, sizeof(kbuf) - 1, count)))
897 return -EFAULT;
899 if (strtobool(kbuf, &timeshare_coex))
900 return -EINVAL;
902 ret = mwifiex_send_cmd(priv, HostCmd_CMD_ROBUST_COEX,
903 HostCmd_ACT_GEN_SET, 0, &timeshare_coex, true);
904 if (ret)
905 return ret;
906 else
907 return count;
910 #define MWIFIEX_DFS_ADD_FILE(name) do { \
911 if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
912 priv, &mwifiex_dfs_##name##_fops)) \
913 return; \
914 } while (0);
916 #define MWIFIEX_DFS_FILE_OPS(name) \
917 static const struct file_operations mwifiex_dfs_##name##_fops = { \
918 .read = mwifiex_##name##_read, \
919 .write = mwifiex_##name##_write, \
920 .open = simple_open, \
923 #define MWIFIEX_DFS_FILE_READ_OPS(name) \
924 static const struct file_operations mwifiex_dfs_##name##_fops = { \
925 .read = mwifiex_##name##_read, \
926 .open = simple_open, \
929 #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
930 static const struct file_operations mwifiex_dfs_##name##_fops = { \
931 .write = mwifiex_##name##_write, \
932 .open = simple_open, \
936 MWIFIEX_DFS_FILE_READ_OPS(info);
937 MWIFIEX_DFS_FILE_READ_OPS(debug);
938 MWIFIEX_DFS_FILE_READ_OPS(getlog);
939 MWIFIEX_DFS_FILE_READ_OPS(device_dump);
940 MWIFIEX_DFS_FILE_OPS(regrdwr);
941 MWIFIEX_DFS_FILE_OPS(rdeeprom);
942 MWIFIEX_DFS_FILE_OPS(memrw);
943 MWIFIEX_DFS_FILE_OPS(hscfg);
944 MWIFIEX_DFS_FILE_OPS(histogram);
945 MWIFIEX_DFS_FILE_OPS(debug_mask);
946 MWIFIEX_DFS_FILE_OPS(timeshare_coex);
949 * This function creates the debug FS directory structure and the files.
951 void
952 mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
954 if (!mwifiex_dfs_dir || !priv)
955 return;
957 priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
958 mwifiex_dfs_dir);
960 if (!priv->dfs_dev_dir)
961 return;
963 MWIFIEX_DFS_ADD_FILE(info);
964 MWIFIEX_DFS_ADD_FILE(debug);
965 MWIFIEX_DFS_ADD_FILE(getlog);
966 MWIFIEX_DFS_ADD_FILE(regrdwr);
967 MWIFIEX_DFS_ADD_FILE(rdeeprom);
968 MWIFIEX_DFS_ADD_FILE(device_dump);
969 MWIFIEX_DFS_ADD_FILE(memrw);
970 MWIFIEX_DFS_ADD_FILE(hscfg);
971 MWIFIEX_DFS_ADD_FILE(histogram);
972 MWIFIEX_DFS_ADD_FILE(debug_mask);
973 MWIFIEX_DFS_ADD_FILE(timeshare_coex);
977 * This function removes the debug FS directory structure and the files.
979 void
980 mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
982 if (!priv)
983 return;
985 debugfs_remove_recursive(priv->dfs_dev_dir);
989 * This function creates the top level proc directory.
991 void
992 mwifiex_debugfs_init(void)
994 if (!mwifiex_dfs_dir)
995 mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
999 * This function removes the top level proc directory.
1001 void
1002 mwifiex_debugfs_remove(void)
1004 if (mwifiex_dfs_dir)
1005 debugfs_remove(mwifiex_dfs_dir);