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 * Generic proc file open handler.
145 * This function is called every time a file is accessed for read or write.
148 mwifiex_open_generic(struct inode
*inode
, struct file
*file
)
150 file
->private_data
= inode
->i_private
;
155 * Proc info file read handler.
157 * This function is called when the 'info' file is opened for reading.
158 * It prints the following driver related information -
161 * - Driver extended version
164 * - Media state (connected or disconnected)
166 * - Total number of Tx bytes
167 * - Total number of Rx bytes
168 * - Total number of Tx packets
169 * - Total number of Rx packets
170 * - Total number of dropped Tx packets
171 * - Total number of dropped Rx packets
172 * - Total number of corrupted Tx packets
173 * - Total number of corrupted Rx packets
174 * - Carrier status (on or off)
175 * - Tx queue status (started or stopped)
177 * For STA mode drivers, it also prints the following extra -
183 * - Multicast addresses
186 mwifiex_info_read(struct file
*file
, char __user
*ubuf
,
187 size_t count
, loff_t
*ppos
)
189 struct mwifiex_private
*priv
=
190 (struct mwifiex_private
*) file
->private_data
;
191 struct net_device
*netdev
= priv
->netdev
;
192 struct netdev_hw_addr
*ha
;
193 unsigned long page
= get_zeroed_page(GFP_KERNEL
);
194 char *p
= (char *) page
, fmt
[64];
195 struct mwifiex_bss_info info
;
202 memset(&info
, 0, sizeof(info
));
203 ret
= mwifiex_get_bss_info(priv
, &info
);
207 mwifiex_drv_get_driver_version(priv
->adapter
, fmt
, sizeof(fmt
) - 1);
209 if (!priv
->version_str
[0])
210 mwifiex_get_ver_ext(priv
);
212 p
+= sprintf(p
, "driver_name = " "\"mwifiex\"\n");
213 p
+= sprintf(p
, "driver_version = %s", fmt
);
214 p
+= sprintf(p
, "\nverext = %s", priv
->version_str
);
215 p
+= sprintf(p
, "\ninterface_name=\"%s\"\n", netdev
->name
);
216 p
+= sprintf(p
, "bss_mode=\"%s\"\n", bss_modes
[info
.bss_mode
]);
217 p
+= sprintf(p
, "media_state=\"%s\"\n",
218 (!priv
->media_connected
? "Disconnected" : "Connected"));
219 p
+= sprintf(p
, "mac_address=\"%pM\"\n", netdev
->dev_addr
);
221 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
) {
222 p
+= sprintf(p
, "multicast_count=\"%d\"\n",
223 netdev_mc_count(netdev
));
224 p
+= sprintf(p
, "essid=\"%s\"\n", info
.ssid
.ssid
);
225 p
+= sprintf(p
, "bssid=\"%pM\"\n", info
.bssid
);
226 p
+= sprintf(p
, "channel=\"%d\"\n", (int) info
.bss_chan
);
227 p
+= sprintf(p
, "region_code = \"%02x\"\n", info
.region_code
);
229 netdev_for_each_mc_addr(ha
, netdev
)
230 p
+= sprintf(p
, "multicast_address[%d]=\"%pM\"\n",
234 p
+= sprintf(p
, "num_tx_bytes = %lu\n", priv
->stats
.tx_bytes
);
235 p
+= sprintf(p
, "num_rx_bytes = %lu\n", priv
->stats
.rx_bytes
);
236 p
+= sprintf(p
, "num_tx_pkts = %lu\n", priv
->stats
.tx_packets
);
237 p
+= sprintf(p
, "num_rx_pkts = %lu\n", priv
->stats
.rx_packets
);
238 p
+= sprintf(p
, "num_tx_pkts_dropped = %lu\n", priv
->stats
.tx_dropped
);
239 p
+= sprintf(p
, "num_rx_pkts_dropped = %lu\n", priv
->stats
.rx_dropped
);
240 p
+= sprintf(p
, "num_tx_pkts_err = %lu\n", priv
->stats
.tx_errors
);
241 p
+= sprintf(p
, "num_rx_pkts_err = %lu\n", priv
->stats
.rx_errors
);
242 p
+= sprintf(p
, "carrier %s\n", ((netif_carrier_ok(priv
->netdev
))
244 p
+= sprintf(p
, "tx queue %s\n", ((netif_queue_stopped(priv
->netdev
))
245 ? "stopped" : "started"));
247 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, (char *) page
,
248 (unsigned long) p
- page
);
256 * Proc getlog file read handler.
258 * This function is called when the 'getlog' file is opened for reading
259 * It prints the following log information -
260 * - Number of multicast Tx frames
261 * - Number of failed packets
262 * - Number of Tx retries
263 * - Number of multicast Tx retries
264 * - Number of duplicate frames
265 * - Number of RTS successes
266 * - Number of RTS failures
267 * - Number of ACK failures
268 * - Number of fragmented Rx frames
269 * - Number of multicast Rx frames
270 * - Number of FCS errors
271 * - Number of Tx frames
272 * - WEP ICV error counts
275 mwifiex_getlog_read(struct file
*file
, char __user
*ubuf
,
276 size_t count
, loff_t
*ppos
)
278 struct mwifiex_private
*priv
=
279 (struct mwifiex_private
*) file
->private_data
;
280 unsigned long page
= get_zeroed_page(GFP_KERNEL
);
281 char *p
= (char *) page
;
283 struct mwifiex_ds_get_stats stats
;
288 memset(&stats
, 0, sizeof(stats
));
289 ret
= mwifiex_get_stats_info(priv
, &stats
);
306 "wepicverrcnt-1 %u\n"
307 "wepicverrcnt-2 %u\n"
308 "wepicverrcnt-3 %u\n"
309 "wepicverrcnt-4 %u\n",
310 stats
.mcast_tx_frame
,
319 stats
.mcast_rx_frame
,
322 stats
.wep_icv_error
[0],
323 stats
.wep_icv_error
[1],
324 stats
.wep_icv_error
[2],
325 stats
.wep_icv_error
[3]);
328 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, (char *) page
,
329 (unsigned long) p
- page
);
336 static struct mwifiex_debug_info info
;
339 * Proc debug file read handler.
341 * This function is called when the 'debug' file is opened for reading
342 * It prints the following log information -
344 * - WMM AC VO packets count
345 * - WMM AC VI packets count
346 * - WMM AC BE packets count
347 * - WMM AC BK packets count
348 * - Maximum Tx buffer size
350 * - Current Tx buffer size
353 * - Deep Sleep status
354 * - Device wakeup required status
355 * - Number of wakeup tries
356 * - Host Sleep configured status
357 * - Host Sleep activated status
358 * - Number of Tx timeouts
359 * - Number of command timeouts
360 * - Last timed out command ID
361 * - Last timed out command action
363 * - Last command action
364 * - Last command index
365 * - Last command response ID
366 * - Last command response index
369 * - Number of host to card command failures
370 * - Number of sleep confirm command failures
371 * - Number of host to card data failure
372 * - Number of deauthentication events
373 * - Number of disassociation events
374 * - Number of link lost events
375 * - Number of deauthentication commands
376 * - Number of association success commands
377 * - Number of association failure commands
378 * - Number of commands sent
379 * - Number of data packets sent
380 * - Number of command responses received
381 * - Number of events received
382 * - Tx BA stream table (TID, RA)
383 * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
386 mwifiex_debug_read(struct file
*file
, char __user
*ubuf
,
387 size_t count
, loff_t
*ppos
)
389 struct mwifiex_private
*priv
=
390 (struct mwifiex_private
*) file
->private_data
;
391 struct mwifiex_debug_data
*d
= &items
[0];
392 unsigned long page
= get_zeroed_page(GFP_KERNEL
);
393 char *p
= (char *) page
;
402 ret
= mwifiex_get_debug_info(priv
, &info
);
406 for (i
= 0; i
< num_of_items
; i
++) {
407 p
+= sprintf(p
, "%s=", d
[i
].name
);
409 size
= d
[i
].size
/ d
[i
].num
;
411 if (i
< (num_of_items
- 3))
412 addr
= d
[i
].addr
+ (size_t) &info
;
413 else /* The last 3 items are struct mwifiex_adapter variables */
414 addr
= d
[i
].addr
+ (size_t) priv
->adapter
;
416 for (j
= 0; j
< d
[i
].num
; j
++) {
419 val
= *((u8
*) addr
);
422 val
= *((u16
*) addr
);
425 val
= *((u32
*) addr
);
428 val
= *((long long *) addr
);
435 p
+= sprintf(p
, "%#lx ", val
);
439 p
+= sprintf(p
, "\n");
442 if (info
.tx_tbl_num
) {
443 p
+= sprintf(p
, "Tx BA stream table:\n");
444 for (i
= 0; i
< info
.tx_tbl_num
; i
++)
445 p
+= sprintf(p
, "tid = %d, ra = %pM\n",
446 info
.tx_tbl
[i
].tid
, info
.tx_tbl
[i
].ra
);
449 if (info
.rx_tbl_num
) {
450 p
+= sprintf(p
, "Rx reorder table:\n");
451 for (i
= 0; i
< info
.rx_tbl_num
; i
++) {
452 p
+= sprintf(p
, "tid = %d, ta = %pM, "
454 "win_size = %d, buffer: ",
457 info
.rx_tbl
[i
].start_win
,
458 info
.rx_tbl
[i
].win_size
);
460 for (j
= 0; j
< info
.rx_tbl
[i
].win_size
; j
++)
461 p
+= sprintf(p
, "%c ",
462 info
.rx_tbl
[i
].buffer
[j
] ?
465 p
+= sprintf(p
, "\n");
469 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, (char *) page
,
470 (unsigned long) p
- page
);
477 static u32 saved_reg_type
, saved_reg_offset
, saved_reg_value
;
480 * Proc regrdwr file write handler.
482 * This function is called when the 'regrdwr' file is opened for writing
484 * This function can be used to write to a register.
487 mwifiex_regrdwr_write(struct file
*file
,
488 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
490 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
491 char *buf
= (char *) addr
;
492 size_t buf_size
= min(count
, (size_t) (PAGE_SIZE
- 1));
494 u32 reg_type
= 0, reg_offset
= 0, reg_value
= UINT_MAX
;
500 if (copy_from_user(buf
, ubuf
, buf_size
)) {
505 sscanf(buf
, "%u %x %x", ®_type
, ®_offset
, ®_value
);
507 if (reg_type
== 0 || reg_offset
== 0) {
511 saved_reg_type
= reg_type
;
512 saved_reg_offset
= reg_offset
;
513 saved_reg_value
= reg_value
;
522 * Proc regrdwr file read handler.
524 * This function is called when the 'regrdwr' file is opened for reading
526 * This function can be used to read from a register.
529 mwifiex_regrdwr_read(struct file
*file
, char __user
*ubuf
,
530 size_t count
, loff_t
*ppos
)
532 struct mwifiex_private
*priv
=
533 (struct mwifiex_private
*) file
->private_data
;
534 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
535 char *buf
= (char *) addr
;
536 int pos
= 0, ret
= 0;
542 if (!saved_reg_type
) {
543 /* No command has been given */
544 pos
+= snprintf(buf
, PAGE_SIZE
, "0");
547 /* Set command has been given */
548 if (saved_reg_value
!= UINT_MAX
) {
549 ret
= mwifiex_reg_write(priv
, saved_reg_type
, saved_reg_offset
,
552 pos
+= snprintf(buf
, PAGE_SIZE
, "%u 0x%x 0x%x\n",
553 saved_reg_type
, saved_reg_offset
,
556 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, buf
, pos
);
560 /* Get command has been given */
561 ret
= mwifiex_reg_read(priv
, saved_reg_type
,
562 saved_reg_offset
, ®_value
);
568 pos
+= snprintf(buf
, PAGE_SIZE
, "%u 0x%x 0x%x\n", saved_reg_type
,
569 saved_reg_offset
, reg_value
);
571 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, buf
, pos
);
578 static u32 saved_offset
= -1, saved_bytes
= -1;
581 * Proc rdeeprom file write handler.
583 * This function is called when the 'rdeeprom' file is opened for writing
585 * This function can be used to write to a RDEEPROM location.
588 mwifiex_rdeeprom_write(struct file
*file
,
589 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
591 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
592 char *buf
= (char *) addr
;
593 size_t buf_size
= min(count
, (size_t) (PAGE_SIZE
- 1));
595 int offset
= -1, bytes
= -1;
601 if (copy_from_user(buf
, ubuf
, buf_size
)) {
606 sscanf(buf
, "%d %d", &offset
, &bytes
);
608 if (offset
== -1 || bytes
== -1) {
612 saved_offset
= offset
;
622 * Proc rdeeprom read write handler.
624 * This function is called when the 'rdeeprom' file is opened for reading
626 * This function can be used to read from a RDEEPROM location.
629 mwifiex_rdeeprom_read(struct file
*file
, char __user
*ubuf
,
630 size_t count
, loff_t
*ppos
)
632 struct mwifiex_private
*priv
=
633 (struct mwifiex_private
*) file
->private_data
;
634 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
635 char *buf
= (char *) addr
;
636 int pos
= 0, ret
= 0, i
;
637 u8 value
[MAX_EEPROM_DATA
];
642 if (saved_offset
== -1) {
643 /* No command has been given */
644 pos
+= snprintf(buf
, PAGE_SIZE
, "0");
648 /* Get command has been given */
649 ret
= mwifiex_eeprom_read(priv
, (u16
) saved_offset
,
650 (u16
) saved_bytes
, value
);
656 pos
+= snprintf(buf
, PAGE_SIZE
, "%d %d ", saved_offset
, saved_bytes
);
658 for (i
= 0; i
< saved_bytes
; i
++)
659 pos
+= snprintf(buf
+ strlen(buf
), PAGE_SIZE
, "%d ", value
[i
]);
661 ret
= simple_read_from_buffer(ubuf
, count
, ppos
, buf
, pos
);
669 #define MWIFIEX_DFS_ADD_FILE(name) do { \
670 if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
671 priv, &mwifiex_dfs_##name##_fops)) \
675 #define MWIFIEX_DFS_FILE_OPS(name) \
676 static const struct file_operations mwifiex_dfs_##name##_fops = { \
677 .read = mwifiex_##name##_read, \
678 .write = mwifiex_##name##_write, \
679 .open = mwifiex_open_generic, \
682 #define MWIFIEX_DFS_FILE_READ_OPS(name) \
683 static const struct file_operations mwifiex_dfs_##name##_fops = { \
684 .read = mwifiex_##name##_read, \
685 .open = mwifiex_open_generic, \
688 #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
689 static const struct file_operations mwifiex_dfs_##name##_fops = { \
690 .write = mwifiex_##name##_write, \
691 .open = mwifiex_open_generic, \
695 MWIFIEX_DFS_FILE_READ_OPS(info
);
696 MWIFIEX_DFS_FILE_READ_OPS(debug
);
697 MWIFIEX_DFS_FILE_READ_OPS(getlog
);
698 MWIFIEX_DFS_FILE_OPS(regrdwr
);
699 MWIFIEX_DFS_FILE_OPS(rdeeprom
);
702 * This function creates the debug FS directory structure and the files.
705 mwifiex_dev_debugfs_init(struct mwifiex_private
*priv
)
707 if (!mwifiex_dfs_dir
|| !priv
)
710 priv
->dfs_dev_dir
= debugfs_create_dir(priv
->netdev
->name
,
713 if (!priv
->dfs_dev_dir
)
716 MWIFIEX_DFS_ADD_FILE(info
);
717 MWIFIEX_DFS_ADD_FILE(debug
);
718 MWIFIEX_DFS_ADD_FILE(getlog
);
719 MWIFIEX_DFS_ADD_FILE(regrdwr
);
720 MWIFIEX_DFS_ADD_FILE(rdeeprom
);
724 * This function removes the debug FS directory structure and the files.
727 mwifiex_dev_debugfs_remove(struct mwifiex_private
*priv
)
732 debugfs_remove_recursive(priv
->dfs_dev_dir
);
736 * This function creates the top level proc directory.
739 mwifiex_debugfs_init(void)
741 if (!mwifiex_dfs_dir
)
742 mwifiex_dfs_dir
= debugfs_create_dir("mwifiex", NULL
);
746 * This function removes the top level proc directory.
749 mwifiex_debugfs_remove(void)
752 debugfs_remove(mwifiex_dfs_dir
);