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 unsigned long page
= get_zeroed_page(GFP_KERNEL
);
182 char *p
= (char *) page
, fmt
[64];
183 struct mwifiex_bss_info info
;
190 memset(&info
, 0, sizeof(info
));
191 ret
= mwifiex_get_bss_info(priv
, &info
);
195 mwifiex_drv_get_driver_version(priv
->adapter
, fmt
, sizeof(fmt
) - 1);
197 if (!priv
->version_str
[0])
198 mwifiex_get_ver_ext(priv
);
200 p
+= sprintf(p
, "driver_name = " "\"mwifiex\"\n");
201 p
+= sprintf(p
, "driver_version = %s", fmt
);
202 p
+= sprintf(p
, "\nverext = %s", priv
->version_str
);
203 p
+= sprintf(p
, "\ninterface_name=\"%s\"\n", netdev
->name
);
204 p
+= sprintf(p
, "bss_mode=\"%s\"\n", bss_modes
[info
.bss_mode
]);
205 p
+= sprintf(p
, "media_state=\"%s\"\n",
206 (!priv
->media_connected
? "Disconnected" : "Connected"));
207 p
+= sprintf(p
, "mac_address=\"%pM\"\n", netdev
->dev_addr
);
209 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
) {
210 p
+= sprintf(p
, "multicast_count=\"%d\"\n",
211 netdev_mc_count(netdev
));
212 p
+= sprintf(p
, "essid=\"%s\"\n", info
.ssid
.ssid
);
213 p
+= sprintf(p
, "bssid=\"%pM\"\n", info
.bssid
);
214 p
+= sprintf(p
, "channel=\"%d\"\n", (int) info
.bss_chan
);
215 p
+= sprintf(p
, "country_code = \"%s\"\n", info
.country_code
);
217 netdev_for_each_mc_addr(ha
, netdev
)
218 p
+= sprintf(p
, "multicast_address[%d]=\"%pM\"\n",
222 p
+= sprintf(p
, "num_tx_bytes = %lu\n", priv
->stats
.tx_bytes
);
223 p
+= sprintf(p
, "num_rx_bytes = %lu\n", priv
->stats
.rx_bytes
);
224 p
+= sprintf(p
, "num_tx_pkts = %lu\n", priv
->stats
.tx_packets
);
225 p
+= sprintf(p
, "num_rx_pkts = %lu\n", priv
->stats
.rx_packets
);
226 p
+= sprintf(p
, "num_tx_pkts_dropped = %lu\n", priv
->stats
.tx_dropped
);
227 p
+= sprintf(p
, "num_rx_pkts_dropped = %lu\n", priv
->stats
.rx_dropped
);
228 p
+= sprintf(p
, "num_tx_pkts_err = %lu\n", priv
->stats
.tx_errors
);
229 p
+= sprintf(p
, "num_rx_pkts_err = %lu\n", priv
->stats
.rx_errors
);
230 p
+= sprintf(p
, "carrier %s\n", ((netif_carrier_ok(priv
->netdev
))
232 p
+= sprintf(p
, "tx queue %s\n", ((netif_queue_stopped(priv
->netdev
))
233 ? "stopped" : "started"));
235 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, (char *) page
,
236 (unsigned long) p
- page
);
244 * Proc getlog file read handler.
246 * This function is called when the 'getlog' file is opened for reading
247 * It prints the following log information -
248 * - Number of multicast Tx frames
249 * - Number of failed packets
250 * - Number of Tx retries
251 * - Number of multicast Tx retries
252 * - Number of duplicate frames
253 * - Number of RTS successes
254 * - Number of RTS failures
255 * - Number of ACK failures
256 * - Number of fragmented Rx frames
257 * - Number of multicast Rx frames
258 * - Number of FCS errors
259 * - Number of Tx frames
260 * - WEP ICV error counts
263 mwifiex_getlog_read(struct file
*file
, char __user
*ubuf
,
264 size_t count
, loff_t
*ppos
)
266 struct mwifiex_private
*priv
=
267 (struct mwifiex_private
*) file
->private_data
;
268 unsigned long page
= get_zeroed_page(GFP_KERNEL
);
269 char *p
= (char *) page
;
271 struct mwifiex_ds_get_stats stats
;
276 memset(&stats
, 0, sizeof(stats
));
277 ret
= mwifiex_get_stats_info(priv
, &stats
);
294 "wepicverrcnt-1 %u\n"
295 "wepicverrcnt-2 %u\n"
296 "wepicverrcnt-3 %u\n"
297 "wepicverrcnt-4 %u\n",
298 stats
.mcast_tx_frame
,
307 stats
.mcast_rx_frame
,
310 stats
.wep_icv_error
[0],
311 stats
.wep_icv_error
[1],
312 stats
.wep_icv_error
[2],
313 stats
.wep_icv_error
[3]);
316 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, (char *) page
,
317 (unsigned long) p
- page
);
324 static struct mwifiex_debug_info info
;
327 * Proc debug file read handler.
329 * This function is called when the 'debug' file is opened for reading
330 * It prints the following log information -
332 * - WMM AC VO packets count
333 * - WMM AC VI packets count
334 * - WMM AC BE packets count
335 * - WMM AC BK packets count
336 * - Maximum Tx buffer size
338 * - Current Tx buffer size
341 * - Deep Sleep status
342 * - Device wakeup required status
343 * - Number of wakeup tries
344 * - Host Sleep configured status
345 * - Host Sleep activated status
346 * - Number of Tx timeouts
347 * - Number of command timeouts
348 * - Last timed out command ID
349 * - Last timed out command action
351 * - Last command action
352 * - Last command index
353 * - Last command response ID
354 * - Last command response index
357 * - Number of host to card command failures
358 * - Number of sleep confirm command failures
359 * - Number of host to card data failure
360 * - Number of deauthentication events
361 * - Number of disassociation events
362 * - Number of link lost events
363 * - Number of deauthentication commands
364 * - Number of association success commands
365 * - Number of association failure commands
366 * - Number of commands sent
367 * - Number of data packets sent
368 * - Number of command responses received
369 * - Number of events received
370 * - Tx BA stream table (TID, RA)
371 * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
374 mwifiex_debug_read(struct file
*file
, char __user
*ubuf
,
375 size_t count
, loff_t
*ppos
)
377 struct mwifiex_private
*priv
=
378 (struct mwifiex_private
*) file
->private_data
;
379 struct mwifiex_debug_data
*d
= &items
[0];
380 unsigned long page
= get_zeroed_page(GFP_KERNEL
);
381 char *p
= (char *) page
;
390 ret
= mwifiex_get_debug_info(priv
, &info
);
394 for (i
= 0; i
< num_of_items
; i
++) {
395 p
+= sprintf(p
, "%s=", d
[i
].name
);
397 size
= d
[i
].size
/ d
[i
].num
;
399 if (i
< (num_of_items
- 3))
400 addr
= d
[i
].addr
+ (size_t) &info
;
401 else /* The last 3 items are struct mwifiex_adapter variables */
402 addr
= d
[i
].addr
+ (size_t) priv
->adapter
;
404 for (j
= 0; j
< d
[i
].num
; j
++) {
407 val
= *((u8
*) addr
);
410 val
= *((u16
*) addr
);
413 val
= *((u32
*) addr
);
416 val
= *((long long *) addr
);
423 p
+= sprintf(p
, "%#lx ", val
);
427 p
+= sprintf(p
, "\n");
430 if (info
.tx_tbl_num
) {
431 p
+= sprintf(p
, "Tx BA stream table:\n");
432 for (i
= 0; i
< info
.tx_tbl_num
; i
++)
433 p
+= sprintf(p
, "tid = %d, ra = %pM\n",
434 info
.tx_tbl
[i
].tid
, info
.tx_tbl
[i
].ra
);
437 if (info
.rx_tbl_num
) {
438 p
+= sprintf(p
, "Rx reorder table:\n");
439 for (i
= 0; i
< info
.rx_tbl_num
; i
++) {
440 p
+= sprintf(p
, "tid = %d, ta = %pM, "
442 "win_size = %d, buffer: ",
445 info
.rx_tbl
[i
].start_win
,
446 info
.rx_tbl
[i
].win_size
);
448 for (j
= 0; j
< info
.rx_tbl
[i
].win_size
; j
++)
449 p
+= sprintf(p
, "%c ",
450 info
.rx_tbl
[i
].buffer
[j
] ?
453 p
+= sprintf(p
, "\n");
457 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, (char *) page
,
458 (unsigned long) p
- page
);
465 static u32 saved_reg_type
, saved_reg_offset
, saved_reg_value
;
468 * Proc regrdwr file write handler.
470 * This function is called when the 'regrdwr' file is opened for writing
472 * This function can be used to write to a register.
475 mwifiex_regrdwr_write(struct file
*file
,
476 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
478 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
479 char *buf
= (char *) addr
;
480 size_t buf_size
= min(count
, (size_t) (PAGE_SIZE
- 1));
482 u32 reg_type
= 0, reg_offset
= 0, reg_value
= UINT_MAX
;
488 if (copy_from_user(buf
, ubuf
, buf_size
)) {
493 sscanf(buf
, "%u %x %x", ®_type
, ®_offset
, ®_value
);
495 if (reg_type
== 0 || reg_offset
== 0) {
499 saved_reg_type
= reg_type
;
500 saved_reg_offset
= reg_offset
;
501 saved_reg_value
= reg_value
;
510 * Proc regrdwr file read handler.
512 * This function is called when the 'regrdwr' file is opened for reading
514 * This function can be used to read from a register.
517 mwifiex_regrdwr_read(struct file
*file
, char __user
*ubuf
,
518 size_t count
, loff_t
*ppos
)
520 struct mwifiex_private
*priv
=
521 (struct mwifiex_private
*) file
->private_data
;
522 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
523 char *buf
= (char *) addr
;
524 int pos
= 0, ret
= 0;
530 if (!saved_reg_type
) {
531 /* No command has been given */
532 pos
+= snprintf(buf
, PAGE_SIZE
, "0");
535 /* Set command has been given */
536 if (saved_reg_value
!= UINT_MAX
) {
537 ret
= mwifiex_reg_write(priv
, saved_reg_type
, saved_reg_offset
,
540 pos
+= snprintf(buf
, PAGE_SIZE
, "%u 0x%x 0x%x\n",
541 saved_reg_type
, saved_reg_offset
,
544 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, buf
, pos
);
548 /* Get command has been given */
549 ret
= mwifiex_reg_read(priv
, saved_reg_type
,
550 saved_reg_offset
, ®_value
);
556 pos
+= snprintf(buf
, PAGE_SIZE
, "%u 0x%x 0x%x\n", saved_reg_type
,
557 saved_reg_offset
, reg_value
);
559 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, buf
, pos
);
566 static u32 saved_offset
= -1, saved_bytes
= -1;
569 * Proc rdeeprom file write handler.
571 * This function is called when the 'rdeeprom' file is opened for writing
573 * This function can be used to write to a RDEEPROM location.
576 mwifiex_rdeeprom_write(struct file
*file
,
577 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
579 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
580 char *buf
= (char *) addr
;
581 size_t buf_size
= min(count
, (size_t) (PAGE_SIZE
- 1));
583 int offset
= -1, bytes
= -1;
589 if (copy_from_user(buf
, ubuf
, buf_size
)) {
594 sscanf(buf
, "%d %d", &offset
, &bytes
);
596 if (offset
== -1 || bytes
== -1) {
600 saved_offset
= offset
;
610 * Proc rdeeprom read write handler.
612 * This function is called when the 'rdeeprom' file is opened for reading
614 * This function can be used to read from a RDEEPROM location.
617 mwifiex_rdeeprom_read(struct file
*file
, char __user
*ubuf
,
618 size_t count
, loff_t
*ppos
)
620 struct mwifiex_private
*priv
=
621 (struct mwifiex_private
*) file
->private_data
;
622 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
623 char *buf
= (char *) addr
;
624 int pos
= 0, ret
= 0, i
;
625 u8 value
[MAX_EEPROM_DATA
];
630 if (saved_offset
== -1) {
631 /* No command has been given */
632 pos
+= snprintf(buf
, PAGE_SIZE
, "0");
636 /* Get command has been given */
637 ret
= mwifiex_eeprom_read(priv
, (u16
) saved_offset
,
638 (u16
) saved_bytes
, value
);
644 pos
+= snprintf(buf
, PAGE_SIZE
, "%d %d ", saved_offset
, saved_bytes
);
646 for (i
= 0; i
< saved_bytes
; i
++)
647 pos
+= snprintf(buf
+ strlen(buf
), PAGE_SIZE
, "%d ", value
[i
]);
649 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, buf
, pos
);
657 #define MWIFIEX_DFS_ADD_FILE(name) do { \
658 if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
659 priv, &mwifiex_dfs_##name##_fops)) \
663 #define MWIFIEX_DFS_FILE_OPS(name) \
664 static const struct file_operations mwifiex_dfs_##name##_fops = { \
665 .read = mwifiex_##name##_read, \
666 .write = mwifiex_##name##_write, \
667 .open = simple_open, \
670 #define MWIFIEX_DFS_FILE_READ_OPS(name) \
671 static const struct file_operations mwifiex_dfs_##name##_fops = { \
672 .read = mwifiex_##name##_read, \
673 .open = simple_open, \
676 #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
677 static const struct file_operations mwifiex_dfs_##name##_fops = { \
678 .write = mwifiex_##name##_write, \
679 .open = simple_open, \
683 MWIFIEX_DFS_FILE_READ_OPS(info
);
684 MWIFIEX_DFS_FILE_READ_OPS(debug
);
685 MWIFIEX_DFS_FILE_READ_OPS(getlog
);
686 MWIFIEX_DFS_FILE_OPS(regrdwr
);
687 MWIFIEX_DFS_FILE_OPS(rdeeprom
);
690 * This function creates the debug FS directory structure and the files.
693 mwifiex_dev_debugfs_init(struct mwifiex_private
*priv
)
695 if (!mwifiex_dfs_dir
|| !priv
)
698 priv
->dfs_dev_dir
= debugfs_create_dir(priv
->netdev
->name
,
701 if (!priv
->dfs_dev_dir
)
704 MWIFIEX_DFS_ADD_FILE(info
);
705 MWIFIEX_DFS_ADD_FILE(debug
);
706 MWIFIEX_DFS_ADD_FILE(getlog
);
707 MWIFIEX_DFS_ADD_FILE(regrdwr
);
708 MWIFIEX_DFS_ADD_FILE(rdeeprom
);
712 * This function removes the debug FS directory structure and the files.
715 mwifiex_dev_debugfs_remove(struct mwifiex_private
*priv
)
720 debugfs_remove_recursive(priv
->dfs_dev_dir
);
724 * This function creates the top level proc directory.
727 mwifiex_debugfs_init(void)
729 if (!mwifiex_dfs_dir
)
730 mwifiex_dfs_dir
= debugfs_create_dir("mwifiex", NULL
);
734 * This function removes the top level proc directory.
737 mwifiex_debugfs_remove(void)
740 debugfs_remove(mwifiex_dfs_dir
);