Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / net / wireless / marvell / mwifiex / debugfs.c
blobdb2872daae97c19a375daff62ae938eb64f5dc64
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 mwifiex_get_ver_ext(priv, 0);
100 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
101 p += sprintf(p, "driver_version = %s", fmt);
102 p += sprintf(p, "\nverext = %s", priv->version_str);
103 p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
105 if (info.bss_mode >= ARRAY_SIZE(bss_modes))
106 p += sprintf(p, "bss_mode=\"%d\"\n", info.bss_mode);
107 else
108 p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
110 p += sprintf(p, "media_state=\"%s\"\n",
111 (!priv->media_connected ? "Disconnected" : "Connected"));
112 p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
114 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
115 p += sprintf(p, "multicast_count=\"%d\"\n",
116 netdev_mc_count(netdev));
117 p += sprintf(p, "essid=\"%.*s\"\n", info.ssid.ssid_len,
118 info.ssid.ssid);
119 p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
120 p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
121 p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
122 p += sprintf(p, "region_code=\"0x%x\"\n",
123 priv->adapter->region_code);
125 netdev_for_each_mc_addr(ha, netdev)
126 p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
127 i++, ha->addr);
130 p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
131 p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
132 p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
133 p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
134 p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
135 p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
136 p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
137 p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
138 p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
139 ? "on" : "off"));
140 p += sprintf(p, "tx queue");
141 for (i = 0; i < netdev->num_tx_queues; i++) {
142 txq = netdev_get_tx_queue(netdev, i);
143 p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
144 "stopped" : "started");
146 p += sprintf(p, "\n");
148 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
149 (unsigned long) p - page);
151 free_and_exit:
152 free_page(page);
153 return ret;
157 * Proc device dump read handler.
159 * This function is called when the 'device_dump' file is opened for
160 * reading.
161 * This function dumps driver information and firmware memory segments
162 * (ex. DTCM, ITCM, SQRAM etc.) for
163 * debugging.
165 static ssize_t
166 mwifiex_device_dump_read(struct file *file, char __user *ubuf,
167 size_t count, loff_t *ppos)
169 struct mwifiex_private *priv = file->private_data;
171 /* For command timeouts, USB firmware will automatically emit
172 * firmware dump events, so we don't implement device_dump().
173 * For user-initiated dumps, we trigger it ourselves.
175 if (priv->adapter->iface_type == MWIFIEX_USB)
176 mwifiex_send_cmd(priv, HostCmd_CMD_FW_DUMP_EVENT,
177 HostCmd_ACT_GEN_SET, 0, NULL, true);
178 else
179 priv->adapter->if_ops.device_dump(priv->adapter);
181 return 0;
185 * Proc getlog file read handler.
187 * This function is called when the 'getlog' file is opened for reading
188 * It prints the following log information -
189 * - Number of multicast Tx frames
190 * - Number of failed packets
191 * - Number of Tx retries
192 * - Number of multicast Tx retries
193 * - Number of duplicate frames
194 * - Number of RTS successes
195 * - Number of RTS failures
196 * - Number of ACK failures
197 * - Number of fragmented Rx frames
198 * - Number of multicast Rx frames
199 * - Number of FCS errors
200 * - Number of Tx frames
201 * - WEP ICV error counts
202 * - Number of received beacons
203 * - Number of missed beacons
205 static ssize_t
206 mwifiex_getlog_read(struct file *file, char __user *ubuf,
207 size_t count, loff_t *ppos)
209 struct mwifiex_private *priv =
210 (struct mwifiex_private *) file->private_data;
211 unsigned long page = get_zeroed_page(GFP_KERNEL);
212 char *p = (char *) page;
213 ssize_t ret;
214 struct mwifiex_ds_get_stats stats;
216 if (!p)
217 return -ENOMEM;
219 memset(&stats, 0, sizeof(stats));
220 ret = mwifiex_get_stats_info(priv, &stats);
221 if (ret)
222 goto free_and_exit;
224 p += sprintf(p, "\n"
225 "mcasttxframe %u\n"
226 "failed %u\n"
227 "retry %u\n"
228 "multiretry %u\n"
229 "framedup %u\n"
230 "rtssuccess %u\n"
231 "rtsfailure %u\n"
232 "ackfailure %u\n"
233 "rxfrag %u\n"
234 "mcastrxframe %u\n"
235 "fcserror %u\n"
236 "txframe %u\n"
237 "wepicverrcnt-1 %u\n"
238 "wepicverrcnt-2 %u\n"
239 "wepicverrcnt-3 %u\n"
240 "wepicverrcnt-4 %u\n"
241 "bcn_rcv_cnt %u\n"
242 "bcn_miss_cnt %u\n",
243 stats.mcast_tx_frame,
244 stats.failed,
245 stats.retry,
246 stats.multi_retry,
247 stats.frame_dup,
248 stats.rts_success,
249 stats.rts_failure,
250 stats.ack_failure,
251 stats.rx_frag,
252 stats.mcast_rx_frame,
253 stats.fcs_error,
254 stats.tx_frame,
255 stats.wep_icv_error[0],
256 stats.wep_icv_error[1],
257 stats.wep_icv_error[2],
258 stats.wep_icv_error[3],
259 stats.bcn_rcv_cnt,
260 stats.bcn_miss_cnt);
263 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
264 (unsigned long) p - page);
266 free_and_exit:
267 free_page(page);
268 return ret;
271 /* Sysfs histogram file read handler.
273 * This function is called when the 'histogram' file is opened for reading
274 * It prints the following histogram information -
275 * - Number of histogram samples
276 * - Receive packet number of each rx_rate
277 * - Receive packet number of each snr
278 * - Receive packet number of each nosie_flr
279 * - Receive packet number of each signal streath
281 static ssize_t
282 mwifiex_histogram_read(struct file *file, char __user *ubuf,
283 size_t count, loff_t *ppos)
285 struct mwifiex_private *priv =
286 (struct mwifiex_private *)file->private_data;
287 ssize_t ret;
288 struct mwifiex_histogram_data *phist_data;
289 int i, value;
290 unsigned long page = get_zeroed_page(GFP_KERNEL);
291 char *p = (char *)page;
293 if (!p)
294 return -ENOMEM;
296 if (!priv || !priv->hist_data)
297 return -EFAULT;
298 phist_data = priv->hist_data;
300 p += sprintf(p, "\n"
301 "total samples = %d\n",
302 atomic_read(&phist_data->num_samples));
304 p += sprintf(p, "rx rates (in Mbps): 0=1M 1=2M");
305 p += sprintf(p, "2=5.5M 3=11M 4=6M 5=9M 6=12M\n");
306 p += sprintf(p, "7=18M 8=24M 9=36M 10=48M 11=54M");
307 p += sprintf(p, "12-27=MCS0-15(BW20) 28-43=MCS0-15(BW40)\n");
309 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
310 p += sprintf(p, "44-53=MCS0-9(VHT:BW20)");
311 p += sprintf(p, "54-63=MCS0-9(VHT:BW40)");
312 p += sprintf(p, "64-73=MCS0-9(VHT:BW80)\n\n");
313 } else {
314 p += sprintf(p, "\n");
317 for (i = 0; i < MWIFIEX_MAX_RX_RATES; i++) {
318 value = atomic_read(&phist_data->rx_rate[i]);
319 if (value)
320 p += sprintf(p, "rx_rate[%02d] = %d\n", i, value);
323 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
324 for (i = MWIFIEX_MAX_RX_RATES; i < MWIFIEX_MAX_AC_RX_RATES;
325 i++) {
326 value = atomic_read(&phist_data->rx_rate[i]);
327 if (value)
328 p += sprintf(p, "rx_rate[%02d] = %d\n",
329 i, value);
333 for (i = 0; i < MWIFIEX_MAX_SNR; i++) {
334 value = atomic_read(&phist_data->snr[i]);
335 if (value)
336 p += sprintf(p, "snr[%02ddB] = %d\n", i, value);
338 for (i = 0; i < MWIFIEX_MAX_NOISE_FLR; i++) {
339 value = atomic_read(&phist_data->noise_flr[i]);
340 if (value)
341 p += sprintf(p, "noise_flr[-%02ddBm] = %d\n",
342 (int)(i-128), value);
344 for (i = 0; i < MWIFIEX_MAX_SIG_STRENGTH; i++) {
345 value = atomic_read(&phist_data->sig_str[i]);
346 if (value)
347 p += sprintf(p, "sig_strength[-%02ddBm] = %d\n",
348 i, value);
351 ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
352 (unsigned long)p - page);
354 return ret;
357 static ssize_t
358 mwifiex_histogram_write(struct file *file, const char __user *ubuf,
359 size_t count, loff_t *ppos)
361 struct mwifiex_private *priv = (void *)file->private_data;
363 if (priv && priv->hist_data)
364 mwifiex_hist_data_reset(priv);
365 return 0;
368 static struct mwifiex_debug_info info;
371 * Proc debug file read handler.
373 * This function is called when the 'debug' file is opened for reading
374 * It prints the following log information -
375 * - Interrupt count
376 * - WMM AC VO packets count
377 * - WMM AC VI packets count
378 * - WMM AC BE packets count
379 * - WMM AC BK packets count
380 * - Maximum Tx buffer size
381 * - Tx buffer size
382 * - Current Tx buffer size
383 * - Power Save mode
384 * - Power Save state
385 * - Deep Sleep status
386 * - Device wakeup required status
387 * - Number of wakeup tries
388 * - Host Sleep configured status
389 * - Host Sleep activated status
390 * - Number of Tx timeouts
391 * - Number of command timeouts
392 * - Last timed out command ID
393 * - Last timed out command action
394 * - Last command ID
395 * - Last command action
396 * - Last command index
397 * - Last command response ID
398 * - Last command response index
399 * - Last event
400 * - Last event index
401 * - Number of host to card command failures
402 * - Number of sleep confirm command failures
403 * - Number of host to card data failure
404 * - Number of deauthentication events
405 * - Number of disassociation events
406 * - Number of link lost events
407 * - Number of deauthentication commands
408 * - Number of association success commands
409 * - Number of association failure commands
410 * - Number of commands sent
411 * - Number of data packets sent
412 * - Number of command responses received
413 * - Number of events received
414 * - Tx BA stream table (TID, RA)
415 * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
417 static ssize_t
418 mwifiex_debug_read(struct file *file, char __user *ubuf,
419 size_t count, loff_t *ppos)
421 struct mwifiex_private *priv =
422 (struct mwifiex_private *) file->private_data;
423 unsigned long page = get_zeroed_page(GFP_KERNEL);
424 char *p = (char *) page;
425 ssize_t ret;
427 if (!p)
428 return -ENOMEM;
430 ret = mwifiex_get_debug_info(priv, &info);
431 if (ret)
432 goto free_and_exit;
434 p += mwifiex_debug_info_to_buffer(priv, p, &info);
436 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
437 (unsigned long) p - page);
439 free_and_exit:
440 free_page(page);
441 return ret;
444 static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
447 * Proc regrdwr file write handler.
449 * This function is called when the 'regrdwr' file is opened for writing
451 * This function can be used to write to a register.
453 static ssize_t
454 mwifiex_regrdwr_write(struct file *file,
455 const char __user *ubuf, size_t count, loff_t *ppos)
457 char *buf;
458 int ret;
459 u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
461 buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
462 if (IS_ERR(buf))
463 return PTR_ERR(buf);
465 sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
467 if (reg_type == 0 || reg_offset == 0) {
468 ret = -EINVAL;
469 goto done;
470 } else {
471 saved_reg_type = reg_type;
472 saved_reg_offset = reg_offset;
473 saved_reg_value = reg_value;
474 ret = count;
476 done:
477 kfree(buf);
478 return ret;
482 * Proc regrdwr file read handler.
484 * This function is called when the 'regrdwr' file is opened for reading
486 * This function can be used to read from a register.
488 static ssize_t
489 mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
490 size_t count, loff_t *ppos)
492 struct mwifiex_private *priv =
493 (struct mwifiex_private *) file->private_data;
494 unsigned long addr = get_zeroed_page(GFP_KERNEL);
495 char *buf = (char *) addr;
496 int pos = 0, ret = 0;
497 u32 reg_value;
499 if (!buf)
500 return -ENOMEM;
502 if (!saved_reg_type) {
503 /* No command has been given */
504 pos += snprintf(buf, PAGE_SIZE, "0");
505 goto done;
507 /* Set command has been given */
508 if (saved_reg_value != UINT_MAX) {
509 ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
510 saved_reg_value);
512 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
513 saved_reg_type, saved_reg_offset,
514 saved_reg_value);
516 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
518 goto done;
520 /* Get command has been given */
521 ret = mwifiex_reg_read(priv, saved_reg_type,
522 saved_reg_offset, &reg_value);
523 if (ret) {
524 ret = -EINVAL;
525 goto done;
528 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
529 saved_reg_offset, reg_value);
531 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
533 done:
534 free_page(addr);
535 return ret;
538 /* Proc debug_mask file read handler.
539 * This function is called when the 'debug_mask' file is opened for reading
540 * This function can be used read driver debugging mask value.
542 static ssize_t
543 mwifiex_debug_mask_read(struct file *file, char __user *ubuf,
544 size_t count, loff_t *ppos)
546 struct mwifiex_private *priv =
547 (struct mwifiex_private *)file->private_data;
548 unsigned long page = get_zeroed_page(GFP_KERNEL);
549 char *buf = (char *)page;
550 size_t ret = 0;
551 int pos = 0;
553 if (!buf)
554 return -ENOMEM;
556 pos += snprintf(buf, PAGE_SIZE, "debug mask=0x%08x\n",
557 priv->adapter->debug_mask);
558 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
560 free_page(page);
561 return ret;
564 /* Proc debug_mask file read handler.
565 * This function is called when the 'debug_mask' file is opened for reading
566 * This function can be used read driver debugging mask value.
568 static ssize_t
569 mwifiex_debug_mask_write(struct file *file, const char __user *ubuf,
570 size_t count, loff_t *ppos)
572 int ret;
573 unsigned long debug_mask;
574 struct mwifiex_private *priv = (void *)file->private_data;
575 char *buf;
577 buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
578 if (IS_ERR(buf))
579 return PTR_ERR(buf);
581 if (kstrtoul(buf, 0, &debug_mask)) {
582 ret = -EINVAL;
583 goto done;
586 priv->adapter->debug_mask = debug_mask;
587 ret = count;
588 done:
589 kfree(buf);
590 return ret;
593 /* debugfs verext file write handler.
594 * This function is called when the 'verext' file is opened for write
596 static ssize_t
597 mwifiex_verext_write(struct file *file, const char __user *ubuf,
598 size_t count, loff_t *ppos)
600 int ret;
601 u32 versionstrsel;
602 struct mwifiex_private *priv = (void *)file->private_data;
603 char buf[16];
605 memset(buf, 0, sizeof(buf));
607 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
608 return -EFAULT;
610 ret = kstrtou32(buf, 10, &versionstrsel);
611 if (ret)
612 return ret;
614 priv->versionstrsel = versionstrsel;
616 return count;
619 /* Proc verext file read handler.
620 * This function is called when the 'verext' file is opened for reading
621 * This function can be used read driver exteneed verion string.
623 static ssize_t
624 mwifiex_verext_read(struct file *file, char __user *ubuf,
625 size_t count, loff_t *ppos)
627 struct mwifiex_private *priv =
628 (struct mwifiex_private *)file->private_data;
629 char buf[256];
630 int ret;
632 mwifiex_get_ver_ext(priv, priv->versionstrsel);
633 ret = snprintf(buf, sizeof(buf), "version string: %s\n",
634 priv->version_str);
636 return simple_read_from_buffer(ubuf, count, ppos, buf, ret);
639 /* Proc memrw file write handler.
640 * This function is called when the 'memrw' file is opened for writing
641 * This function can be used to write to a memory location.
643 static ssize_t
644 mwifiex_memrw_write(struct file *file, const char __user *ubuf, size_t count,
645 loff_t *ppos)
647 int ret;
648 char cmd;
649 struct mwifiex_ds_mem_rw mem_rw;
650 u16 cmd_action;
651 struct mwifiex_private *priv = (void *)file->private_data;
652 char *buf;
654 buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
655 if (IS_ERR(buf))
656 return PTR_ERR(buf);
658 ret = sscanf(buf, "%c %x %x", &cmd, &mem_rw.addr, &mem_rw.value);
659 if (ret != 3) {
660 ret = -EINVAL;
661 goto done;
664 if ((cmd == 'r') || (cmd == 'R')) {
665 cmd_action = HostCmd_ACT_GEN_GET;
666 mem_rw.value = 0;
667 } else if ((cmd == 'w') || (cmd == 'W')) {
668 cmd_action = HostCmd_ACT_GEN_SET;
669 } else {
670 ret = -EINVAL;
671 goto done;
674 memcpy(&priv->mem_rw, &mem_rw, sizeof(mem_rw));
675 if (mwifiex_send_cmd(priv, HostCmd_CMD_MEM_ACCESS, cmd_action, 0,
676 &mem_rw, true))
677 ret = -1;
678 else
679 ret = count;
681 done:
682 kfree(buf);
683 return ret;
686 /* Proc memrw file read handler.
687 * This function is called when the 'memrw' file is opened for reading
688 * This function can be used to read from a memory location.
690 static ssize_t
691 mwifiex_memrw_read(struct file *file, char __user *ubuf,
692 size_t count, loff_t *ppos)
694 struct mwifiex_private *priv = (void *)file->private_data;
695 unsigned long addr = get_zeroed_page(GFP_KERNEL);
696 char *buf = (char *)addr;
697 int ret, pos = 0;
699 if (!buf)
700 return -ENOMEM;
702 pos += snprintf(buf, PAGE_SIZE, "0x%x 0x%x\n", priv->mem_rw.addr,
703 priv->mem_rw.value);
704 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
706 free_page(addr);
707 return ret;
710 static u32 saved_offset = -1, saved_bytes = -1;
713 * Proc rdeeprom file write handler.
715 * This function is called when the 'rdeeprom' file is opened for writing
717 * This function can be used to write to a RDEEPROM location.
719 static ssize_t
720 mwifiex_rdeeprom_write(struct file *file,
721 const char __user *ubuf, size_t count, loff_t *ppos)
723 char *buf;
724 int ret = 0;
725 int offset = -1, bytes = -1;
727 buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
728 if (IS_ERR(buf))
729 return PTR_ERR(buf);
731 sscanf(buf, "%d %d", &offset, &bytes);
733 if (offset == -1 || bytes == -1) {
734 ret = -EINVAL;
735 goto done;
736 } else {
737 saved_offset = offset;
738 saved_bytes = bytes;
739 ret = count;
741 done:
742 kfree(buf);
743 return ret;
747 * Proc rdeeprom read write handler.
749 * This function is called when the 'rdeeprom' file is opened for reading
751 * This function can be used to read from a RDEEPROM location.
753 static ssize_t
754 mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
755 size_t count, loff_t *ppos)
757 struct mwifiex_private *priv =
758 (struct mwifiex_private *) file->private_data;
759 unsigned long addr = get_zeroed_page(GFP_KERNEL);
760 char *buf = (char *) addr;
761 int pos, ret, i;
762 u8 value[MAX_EEPROM_DATA];
764 if (!buf)
765 return -ENOMEM;
767 if (saved_offset == -1) {
768 /* No command has been given */
769 pos = snprintf(buf, PAGE_SIZE, "0");
770 goto done;
773 /* Get command has been given */
774 ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
775 (u16) saved_bytes, value);
776 if (ret) {
777 ret = -EINVAL;
778 goto out_free;
781 pos = snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
783 for (i = 0; i < saved_bytes; i++)
784 pos += scnprintf(buf + pos, PAGE_SIZE - pos, "%d ", value[i]);
786 done:
787 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
788 out_free:
789 free_page(addr);
790 return ret;
793 /* Proc hscfg file write handler
794 * This function can be used to configure the host sleep parameters.
796 static ssize_t
797 mwifiex_hscfg_write(struct file *file, const char __user *ubuf,
798 size_t count, loff_t *ppos)
800 struct mwifiex_private *priv = (void *)file->private_data;
801 char *buf;
802 int ret, arg_num;
803 struct mwifiex_ds_hs_cfg hscfg;
804 int conditions = HS_CFG_COND_DEF;
805 u32 gpio = HS_CFG_GPIO_DEF, gap = HS_CFG_GAP_DEF;
807 buf = memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1)));
808 if (IS_ERR(buf))
809 return PTR_ERR(buf);
811 arg_num = sscanf(buf, "%d %x %x", &conditions, &gpio, &gap);
813 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
815 if (arg_num > 3) {
816 mwifiex_dbg(priv->adapter, ERROR,
817 "Too many arguments\n");
818 ret = -EINVAL;
819 goto done;
822 if (arg_num >= 1 && arg_num < 3)
823 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
824 MWIFIEX_SYNC_CMD, &hscfg);
826 if (arg_num) {
827 if (conditions == HS_CFG_CANCEL) {
828 mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
829 ret = count;
830 goto done;
832 hscfg.conditions = conditions;
834 if (arg_num >= 2)
835 hscfg.gpio = gpio;
836 if (arg_num == 3)
837 hscfg.gap = gap;
839 hscfg.is_invoke_hostcmd = false;
840 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
841 MWIFIEX_SYNC_CMD, &hscfg);
843 mwifiex_enable_hs(priv->adapter);
844 priv->adapter->hs_enabling = false;
845 ret = count;
846 done:
847 kfree(buf);
848 return ret;
851 /* Proc hscfg file read handler
852 * This function can be used to read host sleep configuration
853 * parameters from driver.
855 static ssize_t
856 mwifiex_hscfg_read(struct file *file, char __user *ubuf,
857 size_t count, loff_t *ppos)
859 struct mwifiex_private *priv = (void *)file->private_data;
860 unsigned long addr = get_zeroed_page(GFP_KERNEL);
861 char *buf = (char *)addr;
862 int pos, ret;
863 struct mwifiex_ds_hs_cfg hscfg;
865 if (!buf)
866 return -ENOMEM;
868 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
869 MWIFIEX_SYNC_CMD, &hscfg);
871 pos = snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", hscfg.conditions,
872 hscfg.gpio, hscfg.gap);
874 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
876 free_page(addr);
877 return ret;
880 static ssize_t
881 mwifiex_timeshare_coex_read(struct file *file, char __user *ubuf,
882 size_t count, loff_t *ppos)
884 struct mwifiex_private *priv = file->private_data;
885 char buf[3];
886 bool timeshare_coex;
887 int ret;
888 unsigned int len;
890 if (priv->adapter->fw_api_ver != MWIFIEX_FW_V15)
891 return -EOPNOTSUPP;
893 ret = mwifiex_send_cmd(priv, HostCmd_CMD_ROBUST_COEX,
894 HostCmd_ACT_GEN_GET, 0, &timeshare_coex, true);
895 if (ret)
896 return ret;
898 len = sprintf(buf, "%d\n", timeshare_coex);
899 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
902 static ssize_t
903 mwifiex_timeshare_coex_write(struct file *file, const char __user *ubuf,
904 size_t count, loff_t *ppos)
906 bool timeshare_coex;
907 struct mwifiex_private *priv = file->private_data;
908 char kbuf[16];
909 int ret;
911 if (priv->adapter->fw_api_ver != MWIFIEX_FW_V15)
912 return -EOPNOTSUPP;
914 memset(kbuf, 0, sizeof(kbuf));
916 if (copy_from_user(&kbuf, ubuf, min_t(size_t, sizeof(kbuf) - 1, count)))
917 return -EFAULT;
919 if (strtobool(kbuf, &timeshare_coex))
920 return -EINVAL;
922 ret = mwifiex_send_cmd(priv, HostCmd_CMD_ROBUST_COEX,
923 HostCmd_ACT_GEN_SET, 0, &timeshare_coex, true);
924 if (ret)
925 return ret;
926 else
927 return count;
930 static ssize_t
931 mwifiex_reset_write(struct file *file,
932 const char __user *ubuf, size_t count, loff_t *ppos)
934 struct mwifiex_private *priv = file->private_data;
935 struct mwifiex_adapter *adapter = priv->adapter;
936 bool result;
937 int rc;
939 rc = kstrtobool_from_user(ubuf, count, &result);
940 if (rc)
941 return rc;
943 if (!result)
944 return -EINVAL;
946 if (adapter->if_ops.card_reset) {
947 dev_info(adapter->dev, "Resetting per request\n");
948 adapter->if_ops.card_reset(adapter);
951 return count;
954 #define MWIFIEX_DFS_ADD_FILE(name) do { \
955 if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
956 priv, &mwifiex_dfs_##name##_fops)) \
957 return; \
958 } while (0);
960 #define MWIFIEX_DFS_FILE_OPS(name) \
961 static const struct file_operations mwifiex_dfs_##name##_fops = { \
962 .read = mwifiex_##name##_read, \
963 .write = mwifiex_##name##_write, \
964 .open = simple_open, \
967 #define MWIFIEX_DFS_FILE_READ_OPS(name) \
968 static const struct file_operations mwifiex_dfs_##name##_fops = { \
969 .read = mwifiex_##name##_read, \
970 .open = simple_open, \
973 #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
974 static const struct file_operations mwifiex_dfs_##name##_fops = { \
975 .write = mwifiex_##name##_write, \
976 .open = simple_open, \
980 MWIFIEX_DFS_FILE_READ_OPS(info);
981 MWIFIEX_DFS_FILE_READ_OPS(debug);
982 MWIFIEX_DFS_FILE_READ_OPS(getlog);
983 MWIFIEX_DFS_FILE_READ_OPS(device_dump);
984 MWIFIEX_DFS_FILE_OPS(regrdwr);
985 MWIFIEX_DFS_FILE_OPS(rdeeprom);
986 MWIFIEX_DFS_FILE_OPS(memrw);
987 MWIFIEX_DFS_FILE_OPS(hscfg);
988 MWIFIEX_DFS_FILE_OPS(histogram);
989 MWIFIEX_DFS_FILE_OPS(debug_mask);
990 MWIFIEX_DFS_FILE_OPS(timeshare_coex);
991 MWIFIEX_DFS_FILE_WRITE_OPS(reset);
992 MWIFIEX_DFS_FILE_OPS(verext);
995 * This function creates the debug FS directory structure and the files.
997 void
998 mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
1000 if (!mwifiex_dfs_dir || !priv)
1001 return;
1003 priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
1004 mwifiex_dfs_dir);
1006 if (!priv->dfs_dev_dir)
1007 return;
1009 MWIFIEX_DFS_ADD_FILE(info);
1010 MWIFIEX_DFS_ADD_FILE(debug);
1011 MWIFIEX_DFS_ADD_FILE(getlog);
1012 MWIFIEX_DFS_ADD_FILE(regrdwr);
1013 MWIFIEX_DFS_ADD_FILE(rdeeprom);
1014 MWIFIEX_DFS_ADD_FILE(device_dump);
1015 MWIFIEX_DFS_ADD_FILE(memrw);
1016 MWIFIEX_DFS_ADD_FILE(hscfg);
1017 MWIFIEX_DFS_ADD_FILE(histogram);
1018 MWIFIEX_DFS_ADD_FILE(debug_mask);
1019 MWIFIEX_DFS_ADD_FILE(timeshare_coex);
1020 MWIFIEX_DFS_ADD_FILE(reset);
1021 MWIFIEX_DFS_ADD_FILE(verext);
1025 * This function removes the debug FS directory structure and the files.
1027 void
1028 mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
1030 if (!priv)
1031 return;
1033 debugfs_remove_recursive(priv->dfs_dev_dir);
1037 * This function creates the top level proc directory.
1039 void
1040 mwifiex_debugfs_init(void)
1042 if (!mwifiex_dfs_dir)
1043 mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
1047 * This function removes the top level proc directory.
1049 void
1050 mwifiex_debugfs_remove(void)
1052 debugfs_remove(mwifiex_dfs_dir);