mwifiex: add prints debug ctrl support
[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
5e6e3a92
BZ
42/*
43 * Proc info file read handler.
44 *
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)
64 *
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
72 */
73static ssize_t
74mwifiex_info_read(struct file *file, char __user *ubuf,
75 size_t count, loff_t *ppos)
76{
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;
47411a06 81 struct netdev_queue *txq;
5e6e3a92
BZ
82 unsigned long page = get_zeroed_page(GFP_KERNEL);
83 char *p = (char *) page, fmt[64];
84 struct mwifiex_bss_info info;
270e58e8 85 ssize_t ret;
5e6e3a92
BZ
86 int i = 0;
87
88 if (!p)
89 return -ENOMEM;
90
91 memset(&info, 0, sizeof(info));
92 ret = mwifiex_get_bss_info(priv, &info);
93 if (ret)
94 goto free_and_exit;
95
96 mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
97
98 if (!priv->version_str[0])
99 mwifiex_get_ver_ext(priv);
100
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);
f873ded2
MG
105
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]);
110
5e6e3a92
BZ
111 p += sprintf(p, "media_state=\"%s\"\n",
112 (!priv->media_connected ? "Disconnected" : "Connected"));
037b559a 113 p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
5e6e3a92
BZ
114
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);
037b559a 119 p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
5e6e3a92 120 p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
5e218b7a 121 p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
5e6e3a92
BZ
122
123 netdev_for_each_mc_addr(ha, netdev)
037b559a
AS
124 p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
125 i++, ha->addr);
5e6e3a92
BZ
126 }
127
128 p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
129 p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
130 p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
131 p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
132 p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
133 p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
134 p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
135 p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
136 p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
137 ? "on" : "off"));
47411a06
AP
138 p += sprintf(p, "tx queue");
139 for (i = 0; i < netdev->num_tx_queues; i++) {
140 txq = netdev_get_tx_queue(netdev, i);
141 p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
142 "stopped" : "started");
143 }
144 p += sprintf(p, "\n");
5e6e3a92
BZ
145
146 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
147 (unsigned long) p - page);
148
149free_and_exit:
150 free_page(page);
151 return ret;
152}
153
1c09bf68
AK
154/*
155 * Proc firmware dump read handler.
156 *
157 * This function is called when the 'fw_dump' file is opened for
158 * reading.
159 * This function dumps firmware memory in different files
160 * (ex. DTCM, ITCM, SQRAM etc.) based on the the segments for
161 * debugging.
162 */
163static ssize_t
164mwifiex_fw_dump_read(struct file *file, char __user *ubuf,
165 size_t count, loff_t *ppos)
166{
167 struct mwifiex_private *priv = file->private_data;
168
169 if (!priv->adapter->if_ops.fw_dump)
170 return -EIO;
171
172 priv->adapter->if_ops.fw_dump(priv->adapter);
173
174 return 0;
175}
176
5e6e3a92
BZ
177/*
178 * Proc getlog file read handler.
179 *
180 * This function is called when the 'getlog' file is opened for reading
181 * It prints the following log information -
182 * - Number of multicast Tx frames
183 * - Number of failed packets
184 * - Number of Tx retries
185 * - Number of multicast Tx retries
186 * - Number of duplicate frames
187 * - Number of RTS successes
188 * - Number of RTS failures
189 * - Number of ACK failures
190 * - Number of fragmented Rx frames
191 * - Number of multicast Rx frames
192 * - Number of FCS errors
193 * - Number of Tx frames
194 * - WEP ICV error counts
d35b6392
XH
195 * - Number of received beacons
196 * - Number of missed beacons
5e6e3a92
BZ
197 */
198static ssize_t
199mwifiex_getlog_read(struct file *file, char __user *ubuf,
200 size_t count, loff_t *ppos)
201{
202 struct mwifiex_private *priv =
203 (struct mwifiex_private *) file->private_data;
204 unsigned long page = get_zeroed_page(GFP_KERNEL);
205 char *p = (char *) page;
270e58e8 206 ssize_t ret;
5e6e3a92
BZ
207 struct mwifiex_ds_get_stats stats;
208
209 if (!p)
210 return -ENOMEM;
211
212 memset(&stats, 0, sizeof(stats));
213 ret = mwifiex_get_stats_info(priv, &stats);
214 if (ret)
215 goto free_and_exit;
216
217 p += sprintf(p, "\n"
218 "mcasttxframe %u\n"
219 "failed %u\n"
220 "retry %u\n"
221 "multiretry %u\n"
222 "framedup %u\n"
223 "rtssuccess %u\n"
224 "rtsfailure %u\n"
225 "ackfailure %u\n"
226 "rxfrag %u\n"
227 "mcastrxframe %u\n"
228 "fcserror %u\n"
229 "txframe %u\n"
230 "wepicverrcnt-1 %u\n"
231 "wepicverrcnt-2 %u\n"
232 "wepicverrcnt-3 %u\n"
d35b6392
XH
233 "wepicverrcnt-4 %u\n"
234 "bcn_rcv_cnt %u\n"
235 "bcn_miss_cnt %u\n",
5e6e3a92
BZ
236 stats.mcast_tx_frame,
237 stats.failed,
238 stats.retry,
239 stats.multi_retry,
240 stats.frame_dup,
241 stats.rts_success,
242 stats.rts_failure,
243 stats.ack_failure,
244 stats.rx_frag,
245 stats.mcast_rx_frame,
246 stats.fcs_error,
247 stats.tx_frame,
248 stats.wep_icv_error[0],
249 stats.wep_icv_error[1],
250 stats.wep_icv_error[2],
d35b6392
XH
251 stats.wep_icv_error[3],
252 stats.bcn_rcv_cnt,
253 stats.bcn_miss_cnt);
5e6e3a92
BZ
254
255
256 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
257 (unsigned long) p - page);
258
259free_and_exit:
260 free_page(page);
261 return ret;
262}
263
cbf6e055
XH
264/* Sysfs histogram file read handler.
265 *
266 * This function is called when the 'histogram' file is opened for reading
267 * It prints the following histogram information -
268 * - Number of histogram samples
269 * - Receive packet number of each rx_rate
270 * - Receive packet number of each snr
271 * - Receive packet number of each nosie_flr
272 * - Receive packet number of each signal streath
273 */
274static ssize_t
275mwifiex_histogram_read(struct file *file, char __user *ubuf,
276 size_t count, loff_t *ppos)
277{
278 struct mwifiex_private *priv =
279 (struct mwifiex_private *)file->private_data;
280 ssize_t ret;
281 struct mwifiex_histogram_data *phist_data;
282 int i, value;
283 unsigned long page = get_zeroed_page(GFP_KERNEL);
284 char *p = (char *)page;
285
286 if (!p)
287 return -ENOMEM;
288
289 if (!priv || !priv->hist_data)
290 return -EFAULT;
291 phist_data = priv->hist_data;
292
293 p += sprintf(p, "\n"
294 "total samples = %d\n",
295 atomic_read(&phist_data->num_samples));
296
297 p += sprintf(p, "rx rates (in Mbps): 0=1M 1=2M");
298 p += sprintf(p, "2=5.5M 3=11M 4=6M 5=9M 6=12M\n");
299 p += sprintf(p, "7=18M 8=24M 9=36M 10=48M 11=54M");
300 p += sprintf(p, "12-27=MCS0-15(BW20) 28-43=MCS0-15(BW40)\n");
301
302 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
303 p += sprintf(p, "44-53=MCS0-9(VHT:BW20)");
304 p += sprintf(p, "54-63=MCS0-9(VHT:BW40)");
305 p += sprintf(p, "64-73=MCS0-9(VHT:BW80)\n\n");
306 } else {
307 p += sprintf(p, "\n");
308 }
309
310 for (i = 0; i < MWIFIEX_MAX_RX_RATES; i++) {
311 value = atomic_read(&phist_data->rx_rate[i]);
312 if (value)
313 p += sprintf(p, "rx_rate[%02d] = %d\n", i, value);
314 }
315
316 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
317 for (i = MWIFIEX_MAX_RX_RATES; i < MWIFIEX_MAX_AC_RX_RATES;
318 i++) {
319 value = atomic_read(&phist_data->rx_rate[i]);
320 if (value)
321 p += sprintf(p, "rx_rate[%02d] = %d\n",
322 i, value);
323 }
324 }
325
326 for (i = 0; i < MWIFIEX_MAX_SNR; i++) {
327 value = atomic_read(&phist_data->snr[i]);
328 if (value)
329 p += sprintf(p, "snr[%02ddB] = %d\n", i, value);
330 }
331 for (i = 0; i < MWIFIEX_MAX_NOISE_FLR; i++) {
332 value = atomic_read(&phist_data->noise_flr[i]);
333 if (value)
334 p += sprintf(p, "noise_flr[-%02ddBm] = %d\n",
335 (int)(i-128), value);
336 }
337 for (i = 0; i < MWIFIEX_MAX_SIG_STRENGTH; i++) {
338 value = atomic_read(&phist_data->sig_str[i]);
339 if (value)
340 p += sprintf(p, "sig_strength[-%02ddBm] = %d\n",
341 i, value);
342 }
343
344 ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
345 (unsigned long)p - page);
346
347 return ret;
348}
349
350static ssize_t
351mwifiex_histogram_write(struct file *file, const char __user *ubuf,
352 size_t count, loff_t *ppos)
353{
354 struct mwifiex_private *priv = (void *)file->private_data;
355
356 if (priv && priv->hist_data)
357 mwifiex_hist_data_reset(priv);
358 return 0;
359}
360
5e6e3a92
BZ
361static struct mwifiex_debug_info info;
362
363/*
364 * Proc debug file read handler.
365 *
366 * This function is called when the 'debug' file is opened for reading
367 * It prints the following log information -
368 * - Interrupt count
369 * - WMM AC VO packets count
370 * - WMM AC VI packets count
371 * - WMM AC BE packets count
372 * - WMM AC BK packets count
373 * - Maximum Tx buffer size
374 * - Tx buffer size
375 * - Current Tx buffer size
376 * - Power Save mode
377 * - Power Save state
378 * - Deep Sleep status
379 * - Device wakeup required status
380 * - Number of wakeup tries
381 * - Host Sleep configured status
382 * - Host Sleep activated status
383 * - Number of Tx timeouts
384 * - Number of command timeouts
385 * - Last timed out command ID
386 * - Last timed out command action
387 * - Last command ID
388 * - Last command action
389 * - Last command index
390 * - Last command response ID
391 * - Last command response index
392 * - Last event
393 * - Last event index
394 * - Number of host to card command failures
395 * - Number of sleep confirm command failures
396 * - Number of host to card data failure
397 * - Number of deauthentication events
398 * - Number of disassociation events
399 * - Number of link lost events
400 * - Number of deauthentication commands
401 * - Number of association success commands
402 * - Number of association failure commands
403 * - Number of commands sent
404 * - Number of data packets sent
405 * - Number of command responses received
406 * - Number of events received
407 * - Tx BA stream table (TID, RA)
408 * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
409 */
410static ssize_t
411mwifiex_debug_read(struct file *file, char __user *ubuf,
412 size_t count, loff_t *ppos)
413{
414 struct mwifiex_private *priv =
415 (struct mwifiex_private *) file->private_data;
5e6e3a92
BZ
416 unsigned long page = get_zeroed_page(GFP_KERNEL);
417 char *p = (char *) page;
270e58e8 418 ssize_t ret;
5e6e3a92
BZ
419
420 if (!p)
421 return -ENOMEM;
422
423 ret = mwifiex_get_debug_info(priv, &info);
424 if (ret)
425 goto free_and_exit;
426
bb5097fe 427 p += mwifiex_debug_info_to_buffer(priv, p, &info);
5e6e3a92
BZ
428
429 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
430 (unsigned long) p - page);
431
432free_and_exit:
433 free_page(page);
434 return ret;
435}
436
437static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
438
439/*
440 * Proc regrdwr file write handler.
441 *
442 * This function is called when the 'regrdwr' file is opened for writing
443 *
444 * This function can be used to write to a register.
445 */
446static ssize_t
447mwifiex_regrdwr_write(struct file *file,
448 const char __user *ubuf, size_t count, loff_t *ppos)
449{
450 unsigned long addr = get_zeroed_page(GFP_KERNEL);
451 char *buf = (char *) addr;
c8e49556 452 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
270e58e8 453 int ret;
5e6e3a92
BZ
454 u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
455
456 if (!buf)
457 return -ENOMEM;
458
459
460 if (copy_from_user(buf, ubuf, buf_size)) {
461 ret = -EFAULT;
462 goto done;
463 }
464
465 sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
466
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;
475 }
476done:
477 free_page(addr);
478 return ret;
479}
480
481/*
482 * Proc regrdwr file read handler.
483 *
484 * This function is called when the 'regrdwr' file is opened for reading
485 *
486 * This function can be used to read from a register.
487 */
488static ssize_t
489mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
490 size_t count, loff_t *ppos)
491{
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;
498
499 if (!buf)
500 return -ENOMEM;
501
502 if (!saved_reg_type) {
503 /* No command has been given */
504 pos += snprintf(buf, PAGE_SIZE, "0");
505 goto done;
506 }
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);
511
512 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
513 saved_reg_type, saved_reg_offset,
514 saved_reg_value);
515
516 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
517
518 goto done;
519 }
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;
526 }
527
528 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
529 saved_reg_offset, reg_value);
530
531 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
532
533done:
534 free_page(addr);
535 return ret;
536}
537
c687a007
ZL
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.
541 */
542static ssize_t
543mwifiex_debug_mask_read(struct file *file, char __user *ubuf,
544 size_t count, loff_t *ppos)
545{
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;
552
553 if (!buf)
554 return -ENOMEM;
555
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);
559
560 free_page(page);
561 return ret;
562}
563
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.
567 */
568static ssize_t
569mwifiex_debug_mask_write(struct file *file, const char __user *ubuf,
570 size_t count, loff_t *ppos)
571{
572 int ret;
573 unsigned long debug_mask;
574 struct mwifiex_private *priv = (void *)file->private_data;
575 unsigned long addr = get_zeroed_page(GFP_KERNEL);
576 char *buf = (void *)addr;
577 size_t buf_size = min(count, (size_t)(PAGE_SIZE - 1));
578
579 if (!buf)
580 return -ENOMEM;
581
582 if (copy_from_user(buf, ubuf, buf_size)) {
583 ret = -EFAULT;
584 goto done;
585 }
586
587 if (kstrtoul(buf, 0, &debug_mask)) {
588 ret = -EINVAL;
589 goto done;
590 }
591
592 priv->adapter->debug_mask = debug_mask;
593 ret = count;
594done:
595 free_page(addr);
596 return ret;
597}
598
c2c6c85f
CL
599/* Proc memrw file write handler.
600 * This function is called when the 'memrw' file is opened for writing
601 * This function can be used to write to a memory location.
602 */
603static ssize_t
604mwifiex_memrw_write(struct file *file, const char __user *ubuf, size_t count,
605 loff_t *ppos)
606{
607 int ret;
608 char cmd;
609 struct mwifiex_ds_mem_rw mem_rw;
610 u16 cmd_action;
611 struct mwifiex_private *priv = (void *)file->private_data;
612 unsigned long addr = get_zeroed_page(GFP_KERNEL);
613 char *buf = (void *)addr;
614 size_t buf_size = min(count, (size_t)(PAGE_SIZE - 1));
615
616 if (!buf)
617 return -ENOMEM;
618
619 if (copy_from_user(buf, ubuf, buf_size)) {
620 ret = -EFAULT;
621 goto done;
622 }
623
624 ret = sscanf(buf, "%c %x %x", &cmd, &mem_rw.addr, &mem_rw.value);
625 if (ret != 3) {
626 ret = -EINVAL;
627 goto done;
628 }
629
630 if ((cmd == 'r') || (cmd == 'R')) {
631 cmd_action = HostCmd_ACT_GEN_GET;
632 mem_rw.value = 0;
633 } else if ((cmd == 'w') || (cmd == 'W')) {
634 cmd_action = HostCmd_ACT_GEN_SET;
635 } else {
636 ret = -EINVAL;
637 goto done;
638 }
639
640 memcpy(&priv->mem_rw, &mem_rw, sizeof(mem_rw));
641 if (mwifiex_send_cmd(priv, HostCmd_CMD_MEM_ACCESS, cmd_action, 0,
642 &mem_rw, true))
643 ret = -1;
644 else
645 ret = count;
646
647done:
648 free_page(addr);
649 return ret;
650}
651
652/* Proc memrw file read handler.
653 * This function is called when the 'memrw' file is opened for reading
654 * This function can be used to read from a memory location.
655 */
656static ssize_t
657mwifiex_memrw_read(struct file *file, char __user *ubuf,
658 size_t count, loff_t *ppos)
659{
660 struct mwifiex_private *priv = (void *)file->private_data;
661 unsigned long addr = get_zeroed_page(GFP_KERNEL);
662 char *buf = (char *)addr;
663 int ret, pos = 0;
664
665 if (!buf)
666 return -ENOMEM;
667
668 pos += snprintf(buf, PAGE_SIZE, "0x%x 0x%x\n", priv->mem_rw.addr,
669 priv->mem_rw.value);
670 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
671
672 free_page(addr);
673 return ret;
674}
675
5e6e3a92
BZ
676static u32 saved_offset = -1, saved_bytes = -1;
677
678/*
679 * Proc rdeeprom file write handler.
680 *
681 * This function is called when the 'rdeeprom' file is opened for writing
682 *
683 * This function can be used to write to a RDEEPROM location.
684 */
685static ssize_t
686mwifiex_rdeeprom_write(struct file *file,
687 const char __user *ubuf, size_t count, loff_t *ppos)
688{
689 unsigned long addr = get_zeroed_page(GFP_KERNEL);
690 char *buf = (char *) addr;
c8e49556 691 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
5e6e3a92
BZ
692 int ret = 0;
693 int offset = -1, bytes = -1;
694
695 if (!buf)
696 return -ENOMEM;
697
698
699 if (copy_from_user(buf, ubuf, buf_size)) {
700 ret = -EFAULT;
701 goto done;
702 }
703
704 sscanf(buf, "%d %d", &offset, &bytes);
705
706 if (offset == -1 || bytes == -1) {
707 ret = -EINVAL;
708 goto done;
709 } else {
710 saved_offset = offset;
711 saved_bytes = bytes;
712 ret = count;
713 }
714done:
715 free_page(addr);
716 return ret;
717}
718
719/*
720 * Proc rdeeprom read write handler.
721 *
722 * This function is called when the 'rdeeprom' file is opened for reading
723 *
724 * This function can be used to read from a RDEEPROM location.
725 */
726static ssize_t
727mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
728 size_t count, loff_t *ppos)
729{
730 struct mwifiex_private *priv =
731 (struct mwifiex_private *) file->private_data;
732 unsigned long addr = get_zeroed_page(GFP_KERNEL);
733 char *buf = (char *) addr;
270e58e8 734 int pos = 0, ret = 0, i;
5e6e3a92
BZ
735 u8 value[MAX_EEPROM_DATA];
736
737 if (!buf)
738 return -ENOMEM;
739
740 if (saved_offset == -1) {
741 /* No command has been given */
742 pos += snprintf(buf, PAGE_SIZE, "0");
743 goto done;
744 }
745
746 /* Get command has been given */
747 ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
748 (u16) saved_bytes, value);
749 if (ret) {
750 ret = -EINVAL;
751 goto done;
752 }
753
754 pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
755
756 for (i = 0; i < saved_bytes; i++)
757 pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
758
759 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
760
761done:
762 free_page(addr);
763 return ret;
764}
765
937a5045
XH
766/* Proc hscfg file write handler
767 * This function can be used to configure the host sleep parameters.
768 */
769static ssize_t
770mwifiex_hscfg_write(struct file *file, const char __user *ubuf,
771 size_t count, loff_t *ppos)
772{
773 struct mwifiex_private *priv = (void *)file->private_data;
774 unsigned long addr = get_zeroed_page(GFP_KERNEL);
775 char *buf = (char *)addr;
776 size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
777 int ret, arg_num;
778 struct mwifiex_ds_hs_cfg hscfg;
779 int conditions = HS_CFG_COND_DEF;
780 u32 gpio = HS_CFG_GPIO_DEF, gap = HS_CFG_GAP_DEF;
781
782 if (!buf)
783 return -ENOMEM;
784
785 if (copy_from_user(buf, ubuf, buf_size)) {
786 ret = -EFAULT;
787 goto done;
788 }
789
790 arg_num = sscanf(buf, "%d %x %x", &conditions, &gpio, &gap);
791
792 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
793
794 if (arg_num > 3) {
795 dev_err(priv->adapter->dev, "Too many arguments\n");
796 ret = -EINVAL;
797 goto done;
798 }
799
800 if (arg_num >= 1 && arg_num < 3)
801 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
802 MWIFIEX_SYNC_CMD, &hscfg);
803
804 if (arg_num) {
805 if (conditions == HS_CFG_CANCEL) {
806 mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
807 ret = count;
808 goto done;
809 }
810 hscfg.conditions = conditions;
811 }
812 if (arg_num >= 2)
813 hscfg.gpio = gpio;
814 if (arg_num == 3)
815 hscfg.gap = gap;
816
817 hscfg.is_invoke_hostcmd = false;
818 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
819 MWIFIEX_SYNC_CMD, &hscfg);
820
821 mwifiex_enable_hs(priv->adapter);
822 priv->adapter->hs_enabling = false;
823 ret = count;
824done:
825 free_page(addr);
826 return ret;
827}
828
829/* Proc hscfg file read handler
830 * This function can be used to read host sleep configuration
831 * parameters from driver.
832 */
833static ssize_t
834mwifiex_hscfg_read(struct file *file, char __user *ubuf,
835 size_t count, loff_t *ppos)
836{
837 struct mwifiex_private *priv = (void *)file->private_data;
838 unsigned long addr = get_zeroed_page(GFP_KERNEL);
839 char *buf = (char *)addr;
840 int pos, ret;
841 struct mwifiex_ds_hs_cfg hscfg;
842
843 if (!buf)
844 return -ENOMEM;
845
846 mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
847 MWIFIEX_SYNC_CMD, &hscfg);
848
849 pos = snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", hscfg.conditions,
850 hscfg.gpio, hscfg.gap);
851
852 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
853
854 free_page(addr);
855 return ret;
856}
5e6e3a92
BZ
857
858#define MWIFIEX_DFS_ADD_FILE(name) do { \
859 if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
860 priv, &mwifiex_dfs_##name##_fops)) \
861 return; \
862} while (0);
863
864#define MWIFIEX_DFS_FILE_OPS(name) \
865static const struct file_operations mwifiex_dfs_##name##_fops = { \
866 .read = mwifiex_##name##_read, \
867 .write = mwifiex_##name##_write, \
234e3405 868 .open = simple_open, \
5e6e3a92
BZ
869};
870
871#define MWIFIEX_DFS_FILE_READ_OPS(name) \
872static const struct file_operations mwifiex_dfs_##name##_fops = { \
873 .read = mwifiex_##name##_read, \
234e3405 874 .open = simple_open, \
5e6e3a92
BZ
875};
876
877#define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
878static const struct file_operations mwifiex_dfs_##name##_fops = { \
879 .write = mwifiex_##name##_write, \
234e3405 880 .open = simple_open, \
5e6e3a92
BZ
881};
882
883
884MWIFIEX_DFS_FILE_READ_OPS(info);
885MWIFIEX_DFS_FILE_READ_OPS(debug);
886MWIFIEX_DFS_FILE_READ_OPS(getlog);
1c09bf68 887MWIFIEX_DFS_FILE_READ_OPS(fw_dump);
5e6e3a92
BZ
888MWIFIEX_DFS_FILE_OPS(regrdwr);
889MWIFIEX_DFS_FILE_OPS(rdeeprom);
c2c6c85f 890MWIFIEX_DFS_FILE_OPS(memrw);
937a5045 891MWIFIEX_DFS_FILE_OPS(hscfg);
cbf6e055 892MWIFIEX_DFS_FILE_OPS(histogram);
c687a007 893MWIFIEX_DFS_FILE_OPS(debug_mask);
5e6e3a92
BZ
894
895/*
896 * This function creates the debug FS directory structure and the files.
897 */
898void
899mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
900{
901 if (!mwifiex_dfs_dir || !priv)
902 return;
903
904 priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
905 mwifiex_dfs_dir);
906
907 if (!priv->dfs_dev_dir)
908 return;
909
910 MWIFIEX_DFS_ADD_FILE(info);
911 MWIFIEX_DFS_ADD_FILE(debug);
912 MWIFIEX_DFS_ADD_FILE(getlog);
913 MWIFIEX_DFS_ADD_FILE(regrdwr);
914 MWIFIEX_DFS_ADD_FILE(rdeeprom);
1c09bf68 915 MWIFIEX_DFS_ADD_FILE(fw_dump);
c2c6c85f 916 MWIFIEX_DFS_ADD_FILE(memrw);
937a5045 917 MWIFIEX_DFS_ADD_FILE(hscfg);
cbf6e055 918 MWIFIEX_DFS_ADD_FILE(histogram);
c687a007 919 MWIFIEX_DFS_ADD_FILE(debug_mask);
5e6e3a92
BZ
920}
921
922/*
923 * This function removes the debug FS directory structure and the files.
924 */
925void
926mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
927{
928 if (!priv)
929 return;
930
931 debugfs_remove_recursive(priv->dfs_dev_dir);
5e6e3a92
BZ
932}
933
934/*
935 * This function creates the top level proc directory.
936 */
937void
938mwifiex_debugfs_init(void)
939{
940 if (!mwifiex_dfs_dir)
941 mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
942}
943
944/*
945 * This function removes the top level proc directory.
946 */
947void
948mwifiex_debugfs_remove(void)
949{
950 if (mwifiex_dfs_dir)
951 debugfs_remove(mwifiex_dfs_dir);
952}
This page took 0.349479 seconds and 5 git commands to generate.