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 {"max_tx_buf_size", item_size(max_tx_buf_size),
62 item_addr(max_tx_buf_size), 1},
63 {"tx_buf_size", item_size(tx_buf_size),
64 item_addr(tx_buf_size), 1},
65 {"curr_tx_buf_size", item_size(curr_tx_buf_size),
66 item_addr(curr_tx_buf_size), 1},
67 {"ps_mode", item_size(ps_mode),
68 item_addr(ps_mode), 1},
69 {"ps_state", item_size(ps_state),
70 item_addr(ps_state), 1},
71 {"is_deep_sleep", item_size(is_deep_sleep),
72 item_addr(is_deep_sleep), 1},
73 {"wakeup_dev_req", item_size(pm_wakeup_card_req),
74 item_addr(pm_wakeup_card_req), 1},
75 {"wakeup_tries", item_size(pm_wakeup_fw_try),
76 item_addr(pm_wakeup_fw_try), 1},
77 {"hs_configured", item_size(is_hs_configured),
78 item_addr(is_hs_configured), 1},
79 {"hs_activated", item_size(hs_activated),
80 item_addr(hs_activated), 1},
81 {"num_tx_timeout", item_size(num_tx_timeout),
82 item_addr(num_tx_timeout), 1},
83 {"num_cmd_timeout", item_size(num_cmd_timeout),
84 item_addr(num_cmd_timeout), 1},
85 {"timeout_cmd_id", item_size(timeout_cmd_id),
86 item_addr(timeout_cmd_id), 1},
87 {"timeout_cmd_act", item_size(timeout_cmd_act),
88 item_addr(timeout_cmd_act), 1},
89 {"last_cmd_id", item_size(last_cmd_id),
90 item_addr(last_cmd_id), DBG_CMD_NUM},
91 {"last_cmd_act", item_size(last_cmd_act),
92 item_addr(last_cmd_act), DBG_CMD_NUM},
93 {"last_cmd_index", item_size(last_cmd_index),
94 item_addr(last_cmd_index), 1},
95 {"last_cmd_resp_id", item_size(last_cmd_resp_id),
96 item_addr(last_cmd_resp_id), DBG_CMD_NUM},
97 {"last_cmd_resp_index", item_size(last_cmd_resp_index),
98 item_addr(last_cmd_resp_index), 1},
99 {"last_event", item_size(last_event),
100 item_addr(last_event), DBG_CMD_NUM},
101 {"last_event_index", item_size(last_event_index),
102 item_addr(last_event_index), 1},
103 {"num_cmd_h2c_fail", item_size(num_cmd_host_to_card_failure),
104 item_addr(num_cmd_host_to_card_failure), 1},
105 {"num_cmd_sleep_cfm_fail",
106 item_size(num_cmd_sleep_cfm_host_to_card_failure),
107 item_addr(num_cmd_sleep_cfm_host_to_card_failure), 1},
108 {"num_tx_h2c_fail", item_size(num_tx_host_to_card_failure),
109 item_addr(num_tx_host_to_card_failure), 1},
110 {"num_evt_deauth", item_size(num_event_deauth),
111 item_addr(num_event_deauth), 1},
112 {"num_evt_disassoc", item_size(num_event_disassoc),
113 item_addr(num_event_disassoc), 1},
114 {"num_evt_link_lost", item_size(num_event_link_lost),
115 item_addr(num_event_link_lost), 1},
116 {"num_cmd_deauth", item_size(num_cmd_deauth),
117 item_addr(num_cmd_deauth), 1},
118 {"num_cmd_assoc_ok", item_size(num_cmd_assoc_success),
119 item_addr(num_cmd_assoc_success), 1},
120 {"num_cmd_assoc_fail", item_size(num_cmd_assoc_failure),
121 item_addr(num_cmd_assoc_failure), 1},
122 {"cmd_sent", item_size(cmd_sent),
123 item_addr(cmd_sent), 1},
124 {"data_sent", item_size(data_sent),
125 item_addr(data_sent), 1},
126 {"cmd_resp_received", item_size(cmd_resp_received),
127 item_addr(cmd_resp_received), 1},
128 {"event_received", item_size(event_received),
129 item_addr(event_received), 1},
131 /* variables defined in struct mwifiex_adapter */
132 {"cmd_pending", adapter_item_size(cmd_pending),
133 adapter_item_addr(cmd_pending), 1},
134 {"tx_pending", adapter_item_size(tx_pending),
135 adapter_item_addr(tx_pending), 1},
136 {"rx_pending", adapter_item_size(rx_pending),
137 adapter_item_addr(rx_pending), 1},
140 static int num_of_items = ARRAY_SIZE(items);
143 * Proc info file read handler.
145 * This function is called when the 'info' file is opened for reading.
146 * It prints the following driver related information -
149 * - Driver extended version
152 * - Media state (connected or disconnected)
154 * - Total number of Tx bytes
155 * - Total number of Rx bytes
156 * - Total number of Tx packets
157 * - Total number of Rx packets
158 * - Total number of dropped Tx packets
159 * - Total number of dropped Rx packets
160 * - Total number of corrupted Tx packets
161 * - Total number of corrupted Rx packets
162 * - Carrier status (on or off)
163 * - Tx queue status (started or stopped)
165 * For STA mode drivers, it also prints the following extra -
171 * - Multicast addresses
174 mwifiex_info_read(struct file *file, char __user *ubuf,
175 size_t count, loff_t *ppos)
177 struct mwifiex_private *priv =
178 (struct mwifiex_private *) file->private_data;
179 struct net_device *netdev = priv->netdev;
180 struct netdev_hw_addr *ha;
181 struct netdev_queue *txq;
182 unsigned long page = get_zeroed_page(GFP_KERNEL);
183 char *p = (char *) page, fmt[64];
184 struct mwifiex_bss_info info;
191 memset(&info, 0, sizeof(info));
192 ret = mwifiex_get_bss_info(priv, &info);
196 mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
198 if (!priv->version_str[0])
199 mwifiex_get_ver_ext(priv);
201 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
202 p += sprintf(p, "driver_version = %s", fmt);
203 p += sprintf(p, "\nverext = %s", priv->version_str);
204 p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
205 p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
206 p += sprintf(p, "media_state=\"%s\"\n",
207 (!priv->media_connected ? "Disconnected" : "Connected"));
208 p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
210 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
211 p += sprintf(p, "multicast_count=\"%d\"\n",
212 netdev_mc_count(netdev));
213 p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid);
214 p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
215 p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
216 p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
218 netdev_for_each_mc_addr(ha, netdev)
219 p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
223 p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
224 p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
225 p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
226 p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
227 p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
228 p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
229 p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
230 p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
231 p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
233 p += sprintf(p, "tx queue");
234 for (i = 0; i < netdev->num_tx_queues; i++) {
235 txq = netdev_get_tx_queue(netdev, i);
236 p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
237 "stopped" : "started");
239 p += sprintf(p, "\n");
241 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
242 (unsigned long) p - page);
250 * Proc getlog file read handler.
252 * This function is called when the 'getlog' file is opened for reading
253 * It prints the following log information -
254 * - Number of multicast Tx frames
255 * - Number of failed packets
256 * - Number of Tx retries
257 * - Number of multicast Tx retries
258 * - Number of duplicate frames
259 * - Number of RTS successes
260 * - Number of RTS failures
261 * - Number of ACK failures
262 * - Number of fragmented Rx frames
263 * - Number of multicast Rx frames
264 * - Number of FCS errors
265 * - Number of Tx frames
266 * - WEP ICV error counts
269 mwifiex_getlog_read(struct file *file, char __user *ubuf,
270 size_t count, loff_t *ppos)
272 struct mwifiex_private *priv =
273 (struct mwifiex_private *) file->private_data;
274 unsigned long page = get_zeroed_page(GFP_KERNEL);
275 char *p = (char *) page;
277 struct mwifiex_ds_get_stats stats;
282 memset(&stats, 0, sizeof(stats));
283 ret = mwifiex_get_stats_info(priv, &stats);
300 "wepicverrcnt-1 %u\n"
301 "wepicverrcnt-2 %u\n"
302 "wepicverrcnt-3 %u\n"
303 "wepicverrcnt-4 %u\n",
304 stats.mcast_tx_frame,
313 stats.mcast_rx_frame,
316 stats.wep_icv_error[0],
317 stats.wep_icv_error[1],
318 stats.wep_icv_error[2],
319 stats.wep_icv_error[3]);
322 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
323 (unsigned long) p - page);
330 static struct mwifiex_debug_info info;
333 * Proc debug file read handler.
335 * This function is called when the 'debug' file is opened for reading
336 * It prints the following log information -
338 * - WMM AC VO packets count
339 * - WMM AC VI packets count
340 * - WMM AC BE packets count
341 * - WMM AC BK packets count
342 * - Maximum Tx buffer size
344 * - Current Tx buffer size
347 * - Deep Sleep status
348 * - Device wakeup required status
349 * - Number of wakeup tries
350 * - Host Sleep configured status
351 * - Host Sleep activated status
352 * - Number of Tx timeouts
353 * - Number of command timeouts
354 * - Last timed out command ID
355 * - Last timed out command action
357 * - Last command action
358 * - Last command index
359 * - Last command response ID
360 * - Last command response index
363 * - Number of host to card command failures
364 * - Number of sleep confirm command failures
365 * - Number of host to card data failure
366 * - Number of deauthentication events
367 * - Number of disassociation events
368 * - Number of link lost events
369 * - Number of deauthentication commands
370 * - Number of association success commands
371 * - Number of association failure commands
372 * - Number of commands sent
373 * - Number of data packets sent
374 * - Number of command responses received
375 * - Number of events received
376 * - Tx BA stream table (TID, RA)
377 * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
380 mwifiex_debug_read(struct file *file, char __user *ubuf,
381 size_t count, loff_t *ppos)
383 struct mwifiex_private *priv =
384 (struct mwifiex_private *) file->private_data;
385 struct mwifiex_debug_data *d = &items[0];
386 unsigned long page = get_zeroed_page(GFP_KERNEL);
387 char *p = (char *) page;
396 ret = mwifiex_get_debug_info(priv, &info);
400 for (i = 0; i < num_of_items; i++) {
401 p += sprintf(p, "%s=", d[i].name);
403 size = d[i].size / d[i].num;
405 if (i < (num_of_items - 3))
406 addr = d[i].addr + (size_t) &info;
407 else /* The last 3 items are struct mwifiex_adapter variables */
408 addr = d[i].addr + (size_t) priv->adapter;
410 for (j = 0; j < d[i].num; j++) {
413 val = *((u8 *) addr);
416 val = *((u16 *) addr);
419 val = *((u32 *) addr);
422 val = *((long long *) addr);
429 p += sprintf(p, "%#lx ", val);
433 p += sprintf(p, "\n");
436 if (info.tx_tbl_num) {
437 p += sprintf(p, "Tx BA stream table:\n");
438 for (i = 0; i < info.tx_tbl_num; i++)
439 p += sprintf(p, "tid = %d, ra = %pM\n",
440 info.tx_tbl[i].tid, info.tx_tbl[i].ra);
443 if (info.rx_tbl_num) {
444 p += sprintf(p, "Rx reorder table:\n");
445 for (i = 0; i < info.rx_tbl_num; i++) {
446 p += sprintf(p, "tid = %d, ta = %pM, "
448 "win_size = %d, buffer: ",
451 info.rx_tbl[i].start_win,
452 info.rx_tbl[i].win_size);
454 for (j = 0; j < info.rx_tbl[i].win_size; j++)
455 p += sprintf(p, "%c ",
456 info.rx_tbl[i].buffer[j] ?
459 p += sprintf(p, "\n");
463 ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
464 (unsigned long) p - page);
471 static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
474 * Proc regrdwr file write handler.
476 * This function is called when the 'regrdwr' file is opened for writing
478 * This function can be used to write to a register.
481 mwifiex_regrdwr_write(struct file *file,
482 const char __user *ubuf, size_t count, loff_t *ppos)
484 unsigned long addr = get_zeroed_page(GFP_KERNEL);
485 char *buf = (char *) addr;
486 size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1));
488 u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
494 if (copy_from_user(buf, ubuf, buf_size)) {
499 sscanf(buf, "%u %x %x", ®_type, ®_offset, ®_value);
501 if (reg_type == 0 || reg_offset == 0) {
505 saved_reg_type = reg_type;
506 saved_reg_offset = reg_offset;
507 saved_reg_value = reg_value;
516 * Proc regrdwr file read handler.
518 * This function is called when the 'regrdwr' file is opened for reading
520 * This function can be used to read from a register.
523 mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
524 size_t count, loff_t *ppos)
526 struct mwifiex_private *priv =
527 (struct mwifiex_private *) file->private_data;
528 unsigned long addr = get_zeroed_page(GFP_KERNEL);
529 char *buf = (char *) addr;
530 int pos = 0, ret = 0;
536 if (!saved_reg_type) {
537 /* No command has been given */
538 pos += snprintf(buf, PAGE_SIZE, "0");
541 /* Set command has been given */
542 if (saved_reg_value != UINT_MAX) {
543 ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
546 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
547 saved_reg_type, saved_reg_offset,
550 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
554 /* Get command has been given */
555 ret = mwifiex_reg_read(priv, saved_reg_type,
556 saved_reg_offset, ®_value);
562 pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
563 saved_reg_offset, reg_value);
565 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
572 static u32 saved_offset = -1, saved_bytes = -1;
575 * Proc rdeeprom file write handler.
577 * This function is called when the 'rdeeprom' file is opened for writing
579 * This function can be used to write to a RDEEPROM location.
582 mwifiex_rdeeprom_write(struct file *file,
583 const char __user *ubuf, size_t count, loff_t *ppos)
585 unsigned long addr = get_zeroed_page(GFP_KERNEL);
586 char *buf = (char *) addr;
587 size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1));
589 int offset = -1, bytes = -1;
595 if (copy_from_user(buf, ubuf, buf_size)) {
600 sscanf(buf, "%d %d", &offset, &bytes);
602 if (offset == -1 || bytes == -1) {
606 saved_offset = offset;
616 * Proc rdeeprom read write handler.
618 * This function is called when the 'rdeeprom' file is opened for reading
620 * This function can be used to read from a RDEEPROM location.
623 mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
624 size_t count, loff_t *ppos)
626 struct mwifiex_private *priv =
627 (struct mwifiex_private *) file->private_data;
628 unsigned long addr = get_zeroed_page(GFP_KERNEL);
629 char *buf = (char *) addr;
630 int pos = 0, ret = 0, i;
631 u8 value[MAX_EEPROM_DATA];
636 if (saved_offset == -1) {
637 /* No command has been given */
638 pos += snprintf(buf, PAGE_SIZE, "0");
642 /* Get command has been given */
643 ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
644 (u16) saved_bytes, value);
650 pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
652 for (i = 0; i < saved_bytes; i++)
653 pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
655 ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
663 #define MWIFIEX_DFS_ADD_FILE(name) do { \
664 if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
665 priv, &mwifiex_dfs_##name##_fops)) \
669 #define MWIFIEX_DFS_FILE_OPS(name) \
670 static const struct file_operations mwifiex_dfs_##name##_fops = { \
671 .read = mwifiex_##name##_read, \
672 .write = mwifiex_##name##_write, \
673 .open = simple_open, \
676 #define MWIFIEX_DFS_FILE_READ_OPS(name) \
677 static const struct file_operations mwifiex_dfs_##name##_fops = { \
678 .read = mwifiex_##name##_read, \
679 .open = simple_open, \
682 #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
683 static const struct file_operations mwifiex_dfs_##name##_fops = { \
684 .write = mwifiex_##name##_write, \
685 .open = simple_open, \
689 MWIFIEX_DFS_FILE_READ_OPS(info);
690 MWIFIEX_DFS_FILE_READ_OPS(debug);
691 MWIFIEX_DFS_FILE_READ_OPS(getlog);
692 MWIFIEX_DFS_FILE_OPS(regrdwr);
693 MWIFIEX_DFS_FILE_OPS(rdeeprom);
696 * This function creates the debug FS directory structure and the files.
699 mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
701 if (!mwifiex_dfs_dir || !priv)
704 priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
707 if (!priv->dfs_dev_dir)
710 MWIFIEX_DFS_ADD_FILE(info);
711 MWIFIEX_DFS_ADD_FILE(debug);
712 MWIFIEX_DFS_ADD_FILE(getlog);
713 MWIFIEX_DFS_ADD_FILE(regrdwr);
714 MWIFIEX_DFS_ADD_FILE(rdeeprom);
718 * This function removes the debug FS directory structure and the files.
721 mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
726 debugfs_remove_recursive(priv->dfs_dev_dir);
730 * This function creates the top level proc directory.
733 mwifiex_debugfs_init(void)
735 if (!mwifiex_dfs_dir)
736 mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
740 * This function removes the top level proc directory.
743 mwifiex_debugfs_remove(void)
746 debugfs_remove(mwifiex_dfs_dir);