1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
6 * Copyright (c) 2010, ST-Ericsson
8 #include <linux/debugfs.h>
9 #include <linux/seq_file.h>
10 #include <linux/crc32.h>
17 #include "hif_tx_mib.h"
19 #define CREATE_TRACE_POINTS
22 static const struct trace_print_flags hif_msg_print_map
[] = {
26 static const struct trace_print_flags hif_mib_print_map
[] = {
30 static const struct trace_print_flags wfx_reg_print_map
[] = {
34 static const char *get_symbol(unsigned long val
, const struct trace_print_flags
*symbol_array
)
38 for (i
= 0; symbol_array
[i
].mask
!= -1; i
++) {
39 if (val
== symbol_array
[i
].mask
)
40 return symbol_array
[i
].name
;
46 const char *wfx_get_hif_name(unsigned long id
)
48 return get_symbol(id
, hif_msg_print_map
);
51 const char *wfx_get_mib_name(unsigned long id
)
53 return get_symbol(id
, hif_mib_print_map
);
56 const char *wfx_get_reg_name(unsigned long id
)
58 return get_symbol(id
, wfx_reg_print_map
);
61 static int wfx_counters_show(struct seq_file
*seq
, void *v
)
64 struct wfx_dev
*wdev
= seq
->private;
65 struct wfx_hif_mib_extended_count_table counters
[3];
67 for (i
= 0; i
< ARRAY_SIZE(counters
); i
++) {
68 ret
= wfx_hif_get_counters_table(wdev
, i
, counters
+ i
);
75 seq_printf(seq
, "%-24s %12s %12s %12s\n", "", "global", "iface 0", "iface 1");
77 #define PUT_COUNTER(name) \
78 seq_printf(seq, "%-24s %12d %12d %12d\n", #name, \
79 le32_to_cpu(counters[2].count_##name), \
80 le32_to_cpu(counters[0].count_##name), \
81 le32_to_cpu(counters[1].count_##name))
83 PUT_COUNTER(tx_frames
);
84 PUT_COUNTER(tx_frames_multicast
);
85 PUT_COUNTER(tx_frames_success
);
86 PUT_COUNTER(tx_frames_retried
);
87 PUT_COUNTER(tx_frames_multi_retried
);
88 PUT_COUNTER(tx_frames_failed
);
90 PUT_COUNTER(ack_failed
);
91 PUT_COUNTER(rts_success
);
92 PUT_COUNTER(rts_failed
);
94 PUT_COUNTER(rx_frames
);
95 PUT_COUNTER(rx_frames_multicast
);
96 PUT_COUNTER(rx_frames_success
);
97 PUT_COUNTER(rx_frames_failed
);
98 PUT_COUNTER(drop_plcp
);
99 PUT_COUNTER(drop_fcs
);
100 PUT_COUNTER(drop_no_key
);
101 PUT_COUNTER(drop_decryption
);
102 PUT_COUNTER(drop_tkip_mic
);
103 PUT_COUNTER(drop_bip_mic
);
104 PUT_COUNTER(drop_cmac_icv
);
105 PUT_COUNTER(drop_cmac_replay
);
106 PUT_COUNTER(drop_ccmp_replay
);
107 PUT_COUNTER(drop_duplicate
);
109 PUT_COUNTER(rx_bcn_miss
);
110 PUT_COUNTER(rx_bcn_success
);
111 PUT_COUNTER(rx_bcn_dtim
);
112 PUT_COUNTER(rx_bcn_dtim_aid0_clr
);
113 PUT_COUNTER(rx_bcn_dtim_aid0_set
);
117 for (i
= 0; i
< ARRAY_SIZE(counters
[0].reserved
); i
++)
118 seq_printf(seq
, "reserved[%02d]%12s %12d %12d %12d\n", i
, "",
119 le32_to_cpu(counters
[2].reserved
[i
]),
120 le32_to_cpu(counters
[0].reserved
[i
]),
121 le32_to_cpu(counters
[1].reserved
[i
]));
125 DEFINE_SHOW_ATTRIBUTE(wfx_counters
);
127 static const char * const channel_names
[] = {
132 /* Entries 4 and 5 does not exist */
151 static int wfx_rx_stats_show(struct seq_file
*seq
, void *v
)
153 struct wfx_dev
*wdev
= seq
->private;
154 struct wfx_hif_rx_stats
*st
= &wdev
->rx_stats
;
157 mutex_lock(&wdev
->rx_stats_lock
);
158 seq_printf(seq
, "Timestamp: %dus\n", st
->date
);
159 seq_printf(seq
, "Low power clock: frequency %uHz, external %s\n",
160 le32_to_cpu(st
->pwr_clk_freq
), st
->is_ext_pwr_clk
? "yes" : "no");
161 seq_printf(seq
, "Num. of frames: %d, PER (x10e4): %d, Throughput: %dKbps/s\n",
162 st
->nb_rx_frame
, st
->per_total
, st
->throughput
);
163 seq_puts(seq
, " Num. of PER RSSI SNR CFO\n");
164 seq_puts(seq
, " frames (x10e4) (dBm) (dB) (kHz)\n");
165 for (i
= 0; i
< ARRAY_SIZE(channel_names
); i
++) {
166 if (channel_names
[i
])
167 seq_printf(seq
, "%5s %8d %8d %8d %8d %8d\n",
169 le32_to_cpu(st
->nb_rx_by_rate
[i
]),
170 le16_to_cpu(st
->per
[i
]),
171 (s16
)le16_to_cpu(st
->rssi
[i
]) / 100,
172 (s16
)le16_to_cpu(st
->snr
[i
]) / 100,
173 (s16
)le16_to_cpu(st
->cfo
[i
]));
175 mutex_unlock(&wdev
->rx_stats_lock
);
179 DEFINE_SHOW_ATTRIBUTE(wfx_rx_stats
);
181 static int wfx_tx_power_loop_show(struct seq_file
*seq
, void *v
)
183 struct wfx_dev
*wdev
= seq
->private;
184 struct wfx_hif_tx_power_loop_info
*st
= &wdev
->tx_power_loop_info
;
187 mutex_lock(&wdev
->tx_power_loop_info_lock
);
188 tmp
= le16_to_cpu(st
->tx_gain_dig
);
189 seq_printf(seq
, "Tx gain digital: %d\n", tmp
);
190 tmp
= le16_to_cpu(st
->tx_gain_pa
);
191 seq_printf(seq
, "Tx gain PA: %d\n", tmp
);
192 tmp
= (s16
)le16_to_cpu(st
->target_pout
);
193 seq_printf(seq
, "Target Pout: %d.%02d dBm\n", tmp
/ 4, (tmp
% 4) * 25);
194 tmp
= (s16
)le16_to_cpu(st
->p_estimation
);
195 seq_printf(seq
, "FEM Pout: %d.%02d dBm\n", tmp
/ 4, (tmp
% 4) * 25);
196 tmp
= le16_to_cpu(st
->vpdet
);
197 seq_printf(seq
, "Vpdet: %d mV\n", tmp
);
198 seq_printf(seq
, "Measure index: %d\n", st
->measurement_index
);
199 mutex_unlock(&wdev
->tx_power_loop_info_lock
);
203 DEFINE_SHOW_ATTRIBUTE(wfx_tx_power_loop
);
205 static ssize_t
wfx_send_pds_write(struct file
*file
, const char __user
*user_buf
,
206 size_t count
, loff_t
*ppos
)
208 struct wfx_dev
*wdev
= file
->private_data
;
213 dev_dbg(wdev
->dev
, "PDS data must be written in one transaction");
216 buf
= memdup_user(user_buf
, count
);
219 *ppos
= *ppos
+ count
;
220 ret
= wfx_send_pds(wdev
, buf
, count
);
227 static const struct file_operations wfx_send_pds_fops
= {
229 .write
= wfx_send_pds_write
,
232 struct dbgfs_hif_msg
{
233 struct wfx_dev
*wdev
;
234 struct completion complete
;
239 static ssize_t
wfx_send_hif_msg_write(struct file
*file
, const char __user
*user_buf
,
240 size_t count
, loff_t
*ppos
)
242 struct dbgfs_hif_msg
*context
= file
->private_data
;
243 struct wfx_dev
*wdev
= context
->wdev
;
244 struct wfx_hif_msg
*request
;
246 if (completion_done(&context
->complete
)) {
247 dev_dbg(wdev
->dev
, "read previous result before start a new one\n");
250 if (count
< sizeof(struct wfx_hif_msg
))
253 /* wfx_cmd_send() checks that reply buffer is wide enough, but does not return precise
254 * length read. User have to know how many bytes should be read. Filling reply buffer with a
255 * memory pattern may help user.
257 memset(context
->reply
, 0xFF, sizeof(context
->reply
));
258 request
= memdup_user(user_buf
, count
);
260 return PTR_ERR(request
);
261 if (le16_to_cpu(request
->len
) != count
) {
265 context
->ret
= wfx_cmd_send(wdev
, request
, context
->reply
, sizeof(context
->reply
), false);
268 complete(&context
->complete
);
272 static ssize_t
wfx_send_hif_msg_read(struct file
*file
, char __user
*user_buf
,
273 size_t count
, loff_t
*ppos
)
275 struct dbgfs_hif_msg
*context
= file
->private_data
;
278 if (count
> sizeof(context
->reply
))
280 ret
= wait_for_completion_interruptible(&context
->complete
);
283 if (context
->ret
< 0)
285 /* Be careful, write() is waiting for a full message while read() only returns a payload */
286 if (copy_to_user(user_buf
, context
->reply
, count
))
292 static int wfx_send_hif_msg_open(struct inode
*inode
, struct file
*file
)
294 struct dbgfs_hif_msg
*context
= kzalloc(sizeof(*context
), GFP_KERNEL
);
298 context
->wdev
= inode
->i_private
;
299 init_completion(&context
->complete
);
300 file
->private_data
= context
;
304 static int wfx_send_hif_msg_release(struct inode
*inode
, struct file
*file
)
306 struct dbgfs_hif_msg
*context
= file
->private_data
;
312 static const struct file_operations wfx_send_hif_msg_fops
= {
313 .open
= wfx_send_hif_msg_open
,
314 .release
= wfx_send_hif_msg_release
,
315 .write
= wfx_send_hif_msg_write
,
316 .read
= wfx_send_hif_msg_read
,
319 int wfx_debug_init(struct wfx_dev
*wdev
)
323 d
= debugfs_create_dir("wfx", wdev
->hw
->wiphy
->debugfsdir
);
324 debugfs_create_file("counters", 0444, d
, wdev
, &wfx_counters_fops
);
325 debugfs_create_file("rx_stats", 0444, d
, wdev
, &wfx_rx_stats_fops
);
326 debugfs_create_file("tx_power_loop", 0444, d
, wdev
, &wfx_tx_power_loop_fops
);
327 debugfs_create_file("send_pds", 0200, d
, wdev
, &wfx_send_pds_fops
);
328 debugfs_create_file("send_hif_msg", 0600, d
, wdev
, &wfx_send_hif_msg_fops
);