2 * Marvell Wireless LAN device driver: debugfs
4 * Copyright (C) 2011, 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>
26 static struct dentry *mwifiex_dfs_dir;
28 static char *bss_modes[] = {
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))
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))
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 */
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},
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},
138 static int num_of_items = ARRAY_SIZE(items);
141 * Proc info file read handler.
143 * This function is called when the 'info' file is opened for reading.
144 * It prints the following driver related information -
147 * - Driver extended version
150 * - Media state (connected or disconnected)
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)
163 * For STA mode drivers, it also prints the following extra -
169 * - Multicast addresses
172 mwifiex_info_read(struct file *file, char __user *ubuf,
173 size_t count, loff_t *ppos)
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;
189 memset(&info, 0, sizeof(info));
190 ret = mwifiex_get_bss_info(priv, &info);
194 mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
196 if (!priv->version_str[0])
197 mwifiex_get_ver_ext(priv);
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);
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);
216 netdev_for_each_mc_addr(ha, netdev)
217 p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
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))
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");
237 p += sprintf(p, "\n");
239 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
240 (unsigned long) p - page);
248 * Proc getlog file read handler.
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
267 mwifiex_getlog_read(struct file *file, char __user *ubuf,
268 size_t count, loff_t *ppos)
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;
275 struct mwifiex_ds_get_stats stats;
280 memset(&stats, 0, sizeof(stats));
281 ret = mwifiex_get_stats_info(priv, &stats);
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,
311 stats.mcast_rx_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]);
320 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
321 (unsigned long) p - page);
328 static struct mwifiex_debug_info info;
331 * Proc debug file read handler.
333 * This function is called when the 'debug' file is opened for reading
334 * It prints the following log information -
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
342 * - Current Tx buffer size
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
355 * - Last command action
356 * - Last command index
357 * - Last command response ID
358 * - Last command response 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)
378 mwifiex_debug_read(struct file *file, char __user *ubuf,
379 size_t count, loff_t *ppos)
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;
394 ret = mwifiex_get_debug_info(priv, &info);
398 for (i = 0; i < num_of_items; i++) {
399 p += sprintf(p, "%s=", d[i].name);
401 size = d[i].size / d[i].num;
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;
408 for (j = 0; j < d[i].num; j++) {
411 val = *((u8 *) addr);
414 val = *((u16 *) addr);
417 val = *((u32 *) addr);
420 val = *((long long *) addr);
427 p += sprintf(p, "%#lx ", val);
431 p += sprintf(p, "\n");
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);
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, "
446 "win_size = %d, buffer: ",
449 info.rx_tbl[i].start_win,
450 info.rx_tbl[i].win_size);
452 for (j = 0; j < info.rx_tbl[i].win_size; j++)
453 p += sprintf(p, "%c ",
454 info.rx_tbl[i].buffer[j] ?
457 p += sprintf(p, "\n");
461 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
462 (unsigned long) p - page);
469 static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
472 * Proc regrdwr file write handler.
474 * This function is called when the 'regrdwr' file is opened for writing
476 * This function can be used to write to a register.
479 mwifiex_regrdwr_write(struct file *file,
480 const char __user *ubuf, size_t count, loff_t *ppos)
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));
486 u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
492 if (copy_from_user(buf, ubuf, buf_size)) {
497 sscanf(buf, "%u %x %x", ®_type, ®_offset, ®_value);
499 if (reg_type == 0 || reg_offset == 0) {
503 saved_reg_type = reg_type;
504 saved_reg_offset = reg_offset;
505 saved_reg_value = reg_value;
514 * Proc regrdwr file read handler.
516 * This function is called when the 'regrdwr' file is opened for reading
518 * This function can be used to read from a register.
521 mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
522 size_t count, loff_t *ppos)
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;
534 if (!saved_reg_type) {
535 /* No command has been given */
536 pos += snprintf(buf, PAGE_SIZE, "0");
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,
544 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
545 saved_reg_type, saved_reg_offset,
548 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
552 /* Get command has been given */
553 ret = mwifiex_reg_read(priv, saved_reg_type,
554 saved_reg_offset, ®_value);
560 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
561 saved_reg_offset, reg_value);
563 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
570 static u32 saved_offset = -1, saved_bytes = -1;
573 * Proc rdeeprom file write handler.
575 * This function is called when the 'rdeeprom' file is opened for writing
577 * This function can be used to write to a RDEEPROM location.
580 mwifiex_rdeeprom_write(struct file *file,
581 const char __user *ubuf, size_t count, loff_t *ppos)
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));
587 int offset = -1, bytes = -1;
593 if (copy_from_user(buf, ubuf, buf_size)) {
598 sscanf(buf, "%d %d", &offset, &bytes);
600 if (offset == -1 || bytes == -1) {
604 saved_offset = offset;
614 * Proc rdeeprom read write handler.
616 * This function is called when the 'rdeeprom' file is opened for reading
618 * This function can be used to read from a RDEEPROM location.
621 mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
622 size_t count, loff_t *ppos)
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];
634 if (saved_offset == -1) {
635 /* No command has been given */
636 pos += snprintf(buf, PAGE_SIZE, "0");
640 /* Get command has been given */
641 ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
642 (u16) saved_bytes, value);
648 pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
650 for (i = 0; i < saved_bytes; i++)
651 pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
653 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
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)) \
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, \
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, \
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, \
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);
694 * This function creates the debug FS directory structure and the files.
697 mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
699 if (!mwifiex_dfs_dir || !priv)
702 priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
705 if (!priv->dfs_dev_dir)
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);
716 * This function removes the debug FS directory structure and the files.
719 mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
724 debugfs_remove_recursive(priv->dfs_dev_dir);
728 * This function creates the top level proc directory.
731 mwifiex_debugfs_init(void)
733 if (!mwifiex_dfs_dir)
734 mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
738 * This function removes the top level proc directory.
741 mwifiex_debugfs_remove(void)
744 debugfs_remove(mwifiex_dfs_dir);