]> rtime.felk.cvut.cz Git - linux-imx.git/blob - drivers/net/wireless/mwifiex/debugfs.c
PM / QoS: Add pm_qos and dev_pm_qos to events-power.txt
[linux-imx.git] / drivers / net / wireless / mwifiex / debugfs.c
1 /*
2  * Marvell Wireless LAN device driver: debugfs
3  *
4  * Copyright (C) 2011, Marvell International Ltd.
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
26 static struct dentry *mwifiex_dfs_dir;
27
28 static char *bss_modes[] = {
29         "Unknown",
30         "Ad-hoc",
31         "Managed",
32         "Auto"
33 };
34
35 /* size/addr for mwifiex_debug_info */
36 #define item_size(n)            (FIELD_SIZEOF(struct mwifiex_debug_info, n))
37 #define item_addr(n)            (offsetof(struct mwifiex_debug_info, n))
38
39 /* size/addr for struct mwifiex_adapter */
40 #define adapter_item_size(n)    (FIELD_SIZEOF(struct mwifiex_adapter, n))
41 #define adapter_item_addr(n)    (offsetof(struct mwifiex_adapter, n))
42
43 struct mwifiex_debug_data {
44         char name[32];          /* variable/array name */
45         u32 size;               /* size of the variable/array */
46         size_t addr;            /* address of the variable/array */
47         int num;                /* number of variables in an array */
48 };
49
50 static struct mwifiex_debug_data items[] = {
51         {"int_counter", item_size(int_counter),
52          item_addr(int_counter), 1},
53         {"wmm_ac_vo", item_size(packets_out[WMM_AC_VO]),
54          item_addr(packets_out[WMM_AC_VO]), 1},
55         {"wmm_ac_vi", item_size(packets_out[WMM_AC_VI]),
56          item_addr(packets_out[WMM_AC_VI]), 1},
57         {"wmm_ac_be", item_size(packets_out[WMM_AC_BE]),
58          item_addr(packets_out[WMM_AC_BE]), 1},
59         {"wmm_ac_bk", item_size(packets_out[WMM_AC_BK]),
60          item_addr(packets_out[WMM_AC_BK]), 1},
61         {"tx_buf_size", item_size(tx_buf_size),
62          item_addr(tx_buf_size), 1},
63         {"curr_tx_buf_size", item_size(curr_tx_buf_size),
64          item_addr(curr_tx_buf_size), 1},
65         {"ps_mode", item_size(ps_mode),
66          item_addr(ps_mode), 1},
67         {"ps_state", item_size(ps_state),
68          item_addr(ps_state), 1},
69         {"is_deep_sleep", item_size(is_deep_sleep),
70          item_addr(is_deep_sleep), 1},
71         {"wakeup_dev_req", item_size(pm_wakeup_card_req),
72          item_addr(pm_wakeup_card_req), 1},
73         {"wakeup_tries", item_size(pm_wakeup_fw_try),
74          item_addr(pm_wakeup_fw_try), 1},
75         {"hs_configured", item_size(is_hs_configured),
76          item_addr(is_hs_configured), 1},
77         {"hs_activated", item_size(hs_activated),
78          item_addr(hs_activated), 1},
79         {"num_tx_timeout", item_size(num_tx_timeout),
80          item_addr(num_tx_timeout), 1},
81         {"num_cmd_timeout", item_size(num_cmd_timeout),
82          item_addr(num_cmd_timeout), 1},
83         {"timeout_cmd_id", item_size(timeout_cmd_id),
84          item_addr(timeout_cmd_id), 1},
85         {"timeout_cmd_act", item_size(timeout_cmd_act),
86          item_addr(timeout_cmd_act), 1},
87         {"last_cmd_id", item_size(last_cmd_id),
88          item_addr(last_cmd_id), DBG_CMD_NUM},
89         {"last_cmd_act", item_size(last_cmd_act),
90          item_addr(last_cmd_act), DBG_CMD_NUM},
91         {"last_cmd_index", item_size(last_cmd_index),
92          item_addr(last_cmd_index), 1},
93         {"last_cmd_resp_id", item_size(last_cmd_resp_id),
94          item_addr(last_cmd_resp_id), DBG_CMD_NUM},
95         {"last_cmd_resp_index", item_size(last_cmd_resp_index),
96          item_addr(last_cmd_resp_index), 1},
97         {"last_event", item_size(last_event),
98          item_addr(last_event), DBG_CMD_NUM},
99         {"last_event_index", item_size(last_event_index),
100          item_addr(last_event_index), 1},
101         {"num_cmd_h2c_fail", item_size(num_cmd_host_to_card_failure),
102          item_addr(num_cmd_host_to_card_failure), 1},
103         {"num_cmd_sleep_cfm_fail",
104          item_size(num_cmd_sleep_cfm_host_to_card_failure),
105          item_addr(num_cmd_sleep_cfm_host_to_card_failure), 1},
106         {"num_tx_h2c_fail", item_size(num_tx_host_to_card_failure),
107          item_addr(num_tx_host_to_card_failure), 1},
108         {"num_evt_deauth", item_size(num_event_deauth),
109          item_addr(num_event_deauth), 1},
110         {"num_evt_disassoc", item_size(num_event_disassoc),
111          item_addr(num_event_disassoc), 1},
112         {"num_evt_link_lost", item_size(num_event_link_lost),
113          item_addr(num_event_link_lost), 1},
114         {"num_cmd_deauth", item_size(num_cmd_deauth),
115          item_addr(num_cmd_deauth), 1},
116         {"num_cmd_assoc_ok", item_size(num_cmd_assoc_success),
117          item_addr(num_cmd_assoc_success), 1},
118         {"num_cmd_assoc_fail", item_size(num_cmd_assoc_failure),
119          item_addr(num_cmd_assoc_failure), 1},
120         {"cmd_sent", item_size(cmd_sent),
121          item_addr(cmd_sent), 1},
122         {"data_sent", item_size(data_sent),
123          item_addr(data_sent), 1},
124         {"cmd_resp_received", item_size(cmd_resp_received),
125          item_addr(cmd_resp_received), 1},
126         {"event_received", item_size(event_received),
127          item_addr(event_received), 1},
128
129         /* variables defined in struct mwifiex_adapter */
130         {"cmd_pending", adapter_item_size(cmd_pending),
131          adapter_item_addr(cmd_pending), 1},
132         {"tx_pending", adapter_item_size(tx_pending),
133          adapter_item_addr(tx_pending), 1},
134         {"rx_pending", adapter_item_size(rx_pending),
135          adapter_item_addr(rx_pending), 1},
136 };
137
138 static int num_of_items = ARRAY_SIZE(items);
139
140 /*
141  * Proc info file read handler.
142  *
143  * This function is called when the 'info' file is opened for reading.
144  * It prints the following driver related information -
145  *      - Driver name
146  *      - Driver version
147  *      - Driver extended version
148  *      - Interface name
149  *      - BSS mode
150  *      - Media state (connected or disconnected)
151  *      - MAC address
152  *      - Total number of Tx bytes
153  *      - Total number of Rx bytes
154  *      - Total number of Tx packets
155  *      - Total number of Rx packets
156  *      - Total number of dropped Tx packets
157  *      - Total number of dropped Rx packets
158  *      - Total number of corrupted Tx packets
159  *      - Total number of corrupted Rx packets
160  *      - Carrier status (on or off)
161  *      - Tx queue status (started or stopped)
162  *
163  * For STA mode drivers, it also prints the following extra -
164  *      - ESSID
165  *      - BSSID
166  *      - Channel
167  *      - Region code
168  *      - Multicast count
169  *      - Multicast addresses
170  */
171 static ssize_t
172 mwifiex_info_read(struct file *file, char __user *ubuf,
173                   size_t count, loff_t *ppos)
174 {
175         struct mwifiex_private *priv =
176                 (struct mwifiex_private *) file->private_data;
177         struct net_device *netdev = priv->netdev;
178         struct netdev_hw_addr *ha;
179         struct netdev_queue *txq;
180         unsigned long page = get_zeroed_page(GFP_KERNEL);
181         char *p = (char *) page, fmt[64];
182         struct mwifiex_bss_info info;
183         ssize_t ret;
184         int i = 0;
185
186         if (!p)
187                 return -ENOMEM;
188
189         memset(&info, 0, sizeof(info));
190         ret = mwifiex_get_bss_info(priv, &info);
191         if (ret)
192                 goto free_and_exit;
193
194         mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
195
196         if (!priv->version_str[0])
197                 mwifiex_get_ver_ext(priv);
198
199         p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
200         p += sprintf(p, "driver_version = %s", fmt);
201         p += sprintf(p, "\nverext = %s", priv->version_str);
202         p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
203         p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
204         p += sprintf(p, "media_state=\"%s\"\n",
205                      (!priv->media_connected ? "Disconnected" : "Connected"));
206         p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
207
208         if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
209                 p += sprintf(p, "multicast_count=\"%d\"\n",
210                              netdev_mc_count(netdev));
211                 p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid);
212                 p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
213                 p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
214                 p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
215
216                 netdev_for_each_mc_addr(ha, netdev)
217                         p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
218                                         i++, ha->addr);
219         }
220
221         p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
222         p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
223         p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
224         p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
225         p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
226         p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
227         p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
228         p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
229         p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
230                                          ? "on" : "off"));
231         p += sprintf(p, "tx queue");
232         for (i = 0; i < netdev->num_tx_queues; i++) {
233                 txq = netdev_get_tx_queue(netdev, i);
234                 p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
235                              "stopped" : "started");
236         }
237         p += sprintf(p, "\n");
238
239         ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
240                                       (unsigned long) p - page);
241
242 free_and_exit:
243         free_page(page);
244         return ret;
245 }
246
247 /*
248  * Proc getlog file read handler.
249  *
250  * This function is called when the 'getlog' file is opened for reading
251  * It prints the following log information -
252  *      - Number of multicast Tx frames
253  *      - Number of failed packets
254  *      - Number of Tx retries
255  *      - Number of multicast Tx retries
256  *      - Number of duplicate frames
257  *      - Number of RTS successes
258  *      - Number of RTS failures
259  *      - Number of ACK failures
260  *      - Number of fragmented Rx frames
261  *      - Number of multicast Rx frames
262  *      - Number of FCS errors
263  *      - Number of Tx frames
264  *      - WEP ICV error counts
265  */
266 static ssize_t
267 mwifiex_getlog_read(struct file *file, char __user *ubuf,
268                     size_t count, loff_t *ppos)
269 {
270         struct mwifiex_private *priv =
271                 (struct mwifiex_private *) file->private_data;
272         unsigned long page = get_zeroed_page(GFP_KERNEL);
273         char *p = (char *) page;
274         ssize_t ret;
275         struct mwifiex_ds_get_stats stats;
276
277         if (!p)
278                 return -ENOMEM;
279
280         memset(&stats, 0, sizeof(stats));
281         ret = mwifiex_get_stats_info(priv, &stats);
282         if (ret)
283                 goto free_and_exit;
284
285         p += sprintf(p, "\n"
286                      "mcasttxframe     %u\n"
287                      "failed           %u\n"
288                      "retry            %u\n"
289                      "multiretry       %u\n"
290                      "framedup         %u\n"
291                      "rtssuccess       %u\n"
292                      "rtsfailure       %u\n"
293                      "ackfailure       %u\n"
294                      "rxfrag           %u\n"
295                      "mcastrxframe     %u\n"
296                      "fcserror         %u\n"
297                      "txframe          %u\n"
298                      "wepicverrcnt-1   %u\n"
299                      "wepicverrcnt-2   %u\n"
300                      "wepicverrcnt-3   %u\n"
301                      "wepicverrcnt-4   %u\n",
302                      stats.mcast_tx_frame,
303                      stats.failed,
304                      stats.retry,
305                      stats.multi_retry,
306                      stats.frame_dup,
307                      stats.rts_success,
308                      stats.rts_failure,
309                      stats.ack_failure,
310                      stats.rx_frag,
311                      stats.mcast_rx_frame,
312                      stats.fcs_error,
313                      stats.tx_frame,
314                      stats.wep_icv_error[0],
315                      stats.wep_icv_error[1],
316                      stats.wep_icv_error[2],
317                      stats.wep_icv_error[3]);
318
319
320         ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
321                                       (unsigned long) p - page);
322
323 free_and_exit:
324         free_page(page);
325         return ret;
326 }
327
328 static struct mwifiex_debug_info info;
329
330 /*
331  * Proc debug file read handler.
332  *
333  * This function is called when the 'debug' file is opened for reading
334  * It prints the following log information -
335  *      - Interrupt count
336  *      - WMM AC VO packets count
337  *      - WMM AC VI packets count
338  *      - WMM AC BE packets count
339  *      - WMM AC BK packets count
340  *      - Maximum Tx buffer size
341  *      - Tx buffer size
342  *      - Current Tx buffer size
343  *      - Power Save mode
344  *      - Power Save state
345  *      - Deep Sleep status
346  *      - Device wakeup required status
347  *      - Number of wakeup tries
348  *      - Host Sleep configured status
349  *      - Host Sleep activated status
350  *      - Number of Tx timeouts
351  *      - Number of command timeouts
352  *      - Last timed out command ID
353  *      - Last timed out command action
354  *      - Last command ID
355  *      - Last command action
356  *      - Last command index
357  *      - Last command response ID
358  *      - Last command response index
359  *      - Last event
360  *      - Last event index
361  *      - Number of host to card command failures
362  *      - Number of sleep confirm command failures
363  *      - Number of host to card data failure
364  *      - Number of deauthentication events
365  *      - Number of disassociation events
366  *      - Number of link lost events
367  *      - Number of deauthentication commands
368  *      - Number of association success commands
369  *      - Number of association failure commands
370  *      - Number of commands sent
371  *      - Number of data packets sent
372  *      - Number of command responses received
373  *      - Number of events received
374  *      - Tx BA stream table (TID, RA)
375  *      - Rx reorder table (TID, TA, Start window, Window size, Buffer)
376  */
377 static ssize_t
378 mwifiex_debug_read(struct file *file, char __user *ubuf,
379                    size_t count, loff_t *ppos)
380 {
381         struct mwifiex_private *priv =
382                 (struct mwifiex_private *) file->private_data;
383         struct mwifiex_debug_data *d = &items[0];
384         unsigned long page = get_zeroed_page(GFP_KERNEL);
385         char *p = (char *) page;
386         ssize_t ret;
387         size_t size, addr;
388         long val;
389         int i, j;
390
391         if (!p)
392                 return -ENOMEM;
393
394         ret = mwifiex_get_debug_info(priv, &info);
395         if (ret)
396                 goto free_and_exit;
397
398         for (i = 0; i < num_of_items; i++) {
399                 p += sprintf(p, "%s=", d[i].name);
400
401                 size = d[i].size / d[i].num;
402
403                 if (i < (num_of_items - 3))
404                         addr = d[i].addr + (size_t) &info;
405                 else /* The last 3 items are struct mwifiex_adapter variables */
406                         addr = d[i].addr + (size_t) priv->adapter;
407
408                 for (j = 0; j < d[i].num; j++) {
409                         switch (size) {
410                         case 1:
411                                 val = *((u8 *) addr);
412                                 break;
413                         case 2:
414                                 val = *((u16 *) addr);
415                                 break;
416                         case 4:
417                                 val = *((u32 *) addr);
418                                 break;
419                         case 8:
420                                 val = *((long long *) addr);
421                                 break;
422                         default:
423                                 val = -1;
424                                 break;
425                         }
426
427                         p += sprintf(p, "%#lx ", val);
428                         addr += size;
429                 }
430
431                 p += sprintf(p, "\n");
432         }
433
434         if (info.tx_tbl_num) {
435                 p += sprintf(p, "Tx BA stream table:\n");
436                 for (i = 0; i < info.tx_tbl_num; i++)
437                         p += sprintf(p, "tid = %d, ra = %pM\n",
438                                      info.tx_tbl[i].tid, info.tx_tbl[i].ra);
439         }
440
441         if (info.rx_tbl_num) {
442                 p += sprintf(p, "Rx reorder table:\n");
443                 for (i = 0; i < info.rx_tbl_num; i++) {
444                         p += sprintf(p, "tid = %d, ta = %pM, "
445                                      "start_win = %d, "
446                                      "win_size = %d, buffer: ",
447                                      info.rx_tbl[i].tid,
448                                      info.rx_tbl[i].ta,
449                                      info.rx_tbl[i].start_win,
450                                      info.rx_tbl[i].win_size);
451
452                         for (j = 0; j < info.rx_tbl[i].win_size; j++)
453                                 p += sprintf(p, "%c ",
454                                              info.rx_tbl[i].buffer[j] ?
455                                              '1' : '0');
456
457                         p += sprintf(p, "\n");
458                 }
459         }
460
461         ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
462                                       (unsigned long) p - page);
463
464 free_and_exit:
465         free_page(page);
466         return ret;
467 }
468
469 static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
470
471 /*
472  * Proc regrdwr file write handler.
473  *
474  * This function is called when the 'regrdwr' file is opened for writing
475  *
476  * This function can be used to write to a register.
477  */
478 static ssize_t
479 mwifiex_regrdwr_write(struct file *file,
480                       const char __user *ubuf, size_t count, loff_t *ppos)
481 {
482         unsigned long addr = get_zeroed_page(GFP_KERNEL);
483         char *buf = (char *) addr;
484         size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1));
485         int ret;
486         u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
487
488         if (!buf)
489                 return -ENOMEM;
490
491
492         if (copy_from_user(buf, ubuf, buf_size)) {
493                 ret = -EFAULT;
494                 goto done;
495         }
496
497         sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
498
499         if (reg_type == 0 || reg_offset == 0) {
500                 ret = -EINVAL;
501                 goto done;
502         } else {
503                 saved_reg_type = reg_type;
504                 saved_reg_offset = reg_offset;
505                 saved_reg_value = reg_value;
506                 ret = count;
507         }
508 done:
509         free_page(addr);
510         return ret;
511 }
512
513 /*
514  * Proc regrdwr file read handler.
515  *
516  * This function is called when the 'regrdwr' file is opened for reading
517  *
518  * This function can be used to read from a register.
519  */
520 static ssize_t
521 mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
522                      size_t count, loff_t *ppos)
523 {
524         struct mwifiex_private *priv =
525                 (struct mwifiex_private *) file->private_data;
526         unsigned long addr = get_zeroed_page(GFP_KERNEL);
527         char *buf = (char *) addr;
528         int pos = 0, ret = 0;
529         u32 reg_value;
530
531         if (!buf)
532                 return -ENOMEM;
533
534         if (!saved_reg_type) {
535                 /* No command has been given */
536                 pos += snprintf(buf, PAGE_SIZE, "0");
537                 goto done;
538         }
539         /* Set command has been given */
540         if (saved_reg_value != UINT_MAX) {
541                 ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
542                                         saved_reg_value);
543
544                 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
545                                 saved_reg_type, saved_reg_offset,
546                                 saved_reg_value);
547
548                 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
549
550                 goto done;
551         }
552         /* Get command has been given */
553         ret = mwifiex_reg_read(priv, saved_reg_type,
554                                saved_reg_offset, &reg_value);
555         if (ret) {
556                 ret = -EINVAL;
557                 goto done;
558         }
559
560         pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
561                         saved_reg_offset, reg_value);
562
563         ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
564
565 done:
566         free_page(addr);
567         return ret;
568 }
569
570 static u32 saved_offset = -1, saved_bytes = -1;
571
572 /*
573  * Proc rdeeprom file write handler.
574  *
575  * This function is called when the 'rdeeprom' file is opened for writing
576  *
577  * This function can be used to write to a RDEEPROM location.
578  */
579 static ssize_t
580 mwifiex_rdeeprom_write(struct file *file,
581                        const char __user *ubuf, size_t count, loff_t *ppos)
582 {
583         unsigned long addr = get_zeroed_page(GFP_KERNEL);
584         char *buf = (char *) addr;
585         size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1));
586         int ret = 0;
587         int offset = -1, bytes = -1;
588
589         if (!buf)
590                 return -ENOMEM;
591
592
593         if (copy_from_user(buf, ubuf, buf_size)) {
594                 ret = -EFAULT;
595                 goto done;
596         }
597
598         sscanf(buf, "%d %d", &offset, &bytes);
599
600         if (offset == -1 || bytes == -1) {
601                 ret = -EINVAL;
602                 goto done;
603         } else {
604                 saved_offset = offset;
605                 saved_bytes = bytes;
606                 ret = count;
607         }
608 done:
609         free_page(addr);
610         return ret;
611 }
612
613 /*
614  * Proc rdeeprom read write handler.
615  *
616  * This function is called when the 'rdeeprom' file is opened for reading
617  *
618  * This function can be used to read from a RDEEPROM location.
619  */
620 static ssize_t
621 mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
622                       size_t count, loff_t *ppos)
623 {
624         struct mwifiex_private *priv =
625                 (struct mwifiex_private *) file->private_data;
626         unsigned long addr = get_zeroed_page(GFP_KERNEL);
627         char *buf = (char *) addr;
628         int pos = 0, ret = 0, i;
629         u8 value[MAX_EEPROM_DATA];
630
631         if (!buf)
632                 return -ENOMEM;
633
634         if (saved_offset == -1) {
635                 /* No command has been given */
636                 pos += snprintf(buf, PAGE_SIZE, "0");
637                 goto done;
638         }
639
640         /* Get command has been given */
641         ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
642                                   (u16) saved_bytes, value);
643         if (ret) {
644                 ret = -EINVAL;
645                 goto done;
646         }
647
648         pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
649
650         for (i = 0; i < saved_bytes; i++)
651                 pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
652
653         ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
654
655 done:
656         free_page(addr);
657         return ret;
658 }
659
660
661 #define MWIFIEX_DFS_ADD_FILE(name) do {                                 \
662         if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir,        \
663                         priv, &mwifiex_dfs_##name##_fops))              \
664                 return;                                                 \
665 } while (0);
666
667 #define MWIFIEX_DFS_FILE_OPS(name)                                      \
668 static const struct file_operations mwifiex_dfs_##name##_fops = {       \
669         .read = mwifiex_##name##_read,                                  \
670         .write = mwifiex_##name##_write,                                \
671         .open = simple_open,                                            \
672 };
673
674 #define MWIFIEX_DFS_FILE_READ_OPS(name)                                 \
675 static const struct file_operations mwifiex_dfs_##name##_fops = {       \
676         .read = mwifiex_##name##_read,                                  \
677         .open = simple_open,                                            \
678 };
679
680 #define MWIFIEX_DFS_FILE_WRITE_OPS(name)                                \
681 static const struct file_operations mwifiex_dfs_##name##_fops = {       \
682         .write = mwifiex_##name##_write,                                \
683         .open = simple_open,                                            \
684 };
685
686
687 MWIFIEX_DFS_FILE_READ_OPS(info);
688 MWIFIEX_DFS_FILE_READ_OPS(debug);
689 MWIFIEX_DFS_FILE_READ_OPS(getlog);
690 MWIFIEX_DFS_FILE_OPS(regrdwr);
691 MWIFIEX_DFS_FILE_OPS(rdeeprom);
692
693 /*
694  * This function creates the debug FS directory structure and the files.
695  */
696 void
697 mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
698 {
699         if (!mwifiex_dfs_dir || !priv)
700                 return;
701
702         priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
703                                                mwifiex_dfs_dir);
704
705         if (!priv->dfs_dev_dir)
706                 return;
707
708         MWIFIEX_DFS_ADD_FILE(info);
709         MWIFIEX_DFS_ADD_FILE(debug);
710         MWIFIEX_DFS_ADD_FILE(getlog);
711         MWIFIEX_DFS_ADD_FILE(regrdwr);
712         MWIFIEX_DFS_ADD_FILE(rdeeprom);
713 }
714
715 /*
716  * This function removes the debug FS directory structure and the files.
717  */
718 void
719 mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
720 {
721         if (!priv)
722                 return;
723
724         debugfs_remove_recursive(priv->dfs_dev_dir);
725 }
726
727 /*
728  * This function creates the top level proc directory.
729  */
730 void
731 mwifiex_debugfs_init(void)
732 {
733         if (!mwifiex_dfs_dir)
734                 mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
735 }
736
737 /*
738  * This function removes the top level proc directory.
739  */
740 void
741 mwifiex_debugfs_remove(void)
742 {
743         if (mwifiex_dfs_dir)
744                 debugfs_remove(mwifiex_dfs_dir);
745 }