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
,
35 const struct trace_print_flags
*symbol_array
)
39 for (i
= 0; symbol_array
[i
].mask
!= -1; i
++) {
40 if (val
== symbol_array
[i
].mask
)
41 return symbol_array
[i
].name
;
47 const char *get_hif_name(unsigned long id
)
49 return get_symbol(id
, hif_msg_print_map
);
52 const char *get_mib_name(unsigned long id
)
54 return get_symbol(id
, hif_mib_print_map
);
57 const char *get_reg_name(unsigned long id
)
59 return get_symbol(id
, wfx_reg_print_map
);
62 static int wfx_counters_show(struct seq_file
*seq
, void *v
)
65 struct wfx_dev
*wdev
= seq
->private;
66 struct hif_mib_extended_count_table counters
[3];
68 for (i
= 0; i
< ARRAY_SIZE(counters
); i
++) {
69 ret
= hif_get_counters_table(wdev
, i
, counters
+ i
);
76 seq_printf(seq
, "%-24s %12s %12s %12s\n",
77 "", "global", "iface 0", "iface 1");
79 #define PUT_COUNTER(name) \
80 seq_printf(seq, "%-24s %12d %12d %12d\n", #name, \
81 le32_to_cpu(counters[2].count_##name), \
82 le32_to_cpu(counters[0].count_##name), \
83 le32_to_cpu(counters[1].count_##name))
85 PUT_COUNTER(tx_packets
);
86 PUT_COUNTER(tx_multicast_frames
);
87 PUT_COUNTER(tx_frames_success
);
88 PUT_COUNTER(tx_frame_failures
);
89 PUT_COUNTER(tx_frames_retried
);
90 PUT_COUNTER(tx_frames_multi_retried
);
92 PUT_COUNTER(rts_success
);
93 PUT_COUNTER(rts_failures
);
94 PUT_COUNTER(ack_failures
);
96 PUT_COUNTER(rx_packets
);
97 PUT_COUNTER(rx_frames_success
);
98 PUT_COUNTER(rx_packet_errors
);
99 PUT_COUNTER(plcp_errors
);
100 PUT_COUNTER(fcs_errors
);
101 PUT_COUNTER(rx_decryption_failures
);
102 PUT_COUNTER(rx_mic_failures
);
103 PUT_COUNTER(rx_no_key_failures
);
104 PUT_COUNTER(rx_frame_duplicates
);
105 PUT_COUNTER(rx_multicast_frames
);
106 PUT_COUNTER(rx_cmacicv_errors
);
107 PUT_COUNTER(rx_cmac_replays
);
108 PUT_COUNTER(rx_mgmt_ccmp_replays
);
110 PUT_COUNTER(rx_beacon
);
111 PUT_COUNTER(miss_beacon
);
115 for (i
= 0; i
< ARRAY_SIZE(counters
[0].reserved
); i
++)
116 seq_printf(seq
, "reserved[%02d]%12s %12d %12d %12d\n", i
, "",
117 le32_to_cpu(counters
[2].reserved
[i
]),
118 le32_to_cpu(counters
[0].reserved
[i
]),
119 le32_to_cpu(counters
[1].reserved
[i
]));
123 DEFINE_SHOW_ATTRIBUTE(wfx_counters
);
125 static const char * const channel_names
[] = {
130 /* Entries 4 and 5 does not exist */
149 static int wfx_rx_stats_show(struct seq_file
*seq
, void *v
)
151 struct wfx_dev
*wdev
= seq
->private;
152 struct hif_rx_stats
*st
= &wdev
->rx_stats
;
155 mutex_lock(&wdev
->rx_stats_lock
);
156 seq_printf(seq
, "Timestamp: %dus\n", st
->date
);
157 seq_printf(seq
, "Low power clock: frequency %uHz, external %s\n",
158 le32_to_cpu(st
->pwr_clk_freq
),
159 st
->is_ext_pwr_clk
? "yes" : "no");
161 "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 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
,
206 const char __user
*user_buf
,
207 size_t count
, loff_t
*ppos
)
209 struct wfx_dev
*wdev
= file
->private_data
;
214 dev_dbg(wdev
->dev
, "PDS data must be written in one transaction");
217 buf
= memdup_user(user_buf
, count
);
220 *ppos
= *ppos
+ count
;
221 ret
= wfx_send_pds(wdev
, buf
, count
);
228 static const struct file_operations wfx_send_pds_fops
= {
230 .write
= wfx_send_pds_write
,
233 struct dbgfs_hif_msg
{
234 struct wfx_dev
*wdev
;
235 struct completion complete
;
240 static ssize_t
wfx_send_hif_msg_write(struct file
*file
,
241 const char __user
*user_buf
,
242 size_t count
, loff_t
*ppos
)
244 struct dbgfs_hif_msg
*context
= file
->private_data
;
245 struct wfx_dev
*wdev
= context
->wdev
;
246 struct hif_msg
*request
;
248 if (completion_done(&context
->complete
)) {
249 dev_dbg(wdev
->dev
, "read previous result before start a new one\n");
252 if (count
< sizeof(struct hif_msg
))
255 // wfx_cmd_send() checks that reply buffer is wide enough, but does not
256 // return precise length read. User have to know how many bytes should
257 // be read. Filling reply buffer with a memory pattern may help user.
258 memset(context
->reply
, 0xFF, sizeof(context
->reply
));
259 request
= memdup_user(user_buf
, count
);
261 return PTR_ERR(request
);
262 if (le16_to_cpu(request
->len
) != count
) {
266 context
->ret
= wfx_cmd_send(wdev
, request
, context
->reply
,
267 sizeof(context
->reply
), false);
270 complete(&context
->complete
);
274 static ssize_t
wfx_send_hif_msg_read(struct file
*file
, char __user
*user_buf
,
275 size_t count
, loff_t
*ppos
)
277 struct dbgfs_hif_msg
*context
= file
->private_data
;
280 if (count
> sizeof(context
->reply
))
282 ret
= wait_for_completion_interruptible(&context
->complete
);
285 if (context
->ret
< 0)
287 // Be careful, write() is waiting for a full message while read()
288 // only returns a payload
289 if (copy_to_user(user_buf
, context
->reply
, count
))
295 static int wfx_send_hif_msg_open(struct inode
*inode
, struct file
*file
)
297 struct dbgfs_hif_msg
*context
= kzalloc(sizeof(*context
), GFP_KERNEL
);
301 context
->wdev
= inode
->i_private
;
302 init_completion(&context
->complete
);
303 file
->private_data
= context
;
307 static int wfx_send_hif_msg_release(struct inode
*inode
, struct file
*file
)
309 struct dbgfs_hif_msg
*context
= file
->private_data
;
315 static const struct file_operations wfx_send_hif_msg_fops
= {
316 .open
= wfx_send_hif_msg_open
,
317 .release
= wfx_send_hif_msg_release
,
318 .write
= wfx_send_hif_msg_write
,
319 .read
= wfx_send_hif_msg_read
,
322 static int wfx_ps_timeout_set(void *data
, u64 val
)
324 struct wfx_dev
*wdev
= (struct wfx_dev
*)data
;
325 struct wfx_vif
*wvif
;
327 wdev
->force_ps_timeout
= val
;
329 while ((wvif
= wvif_iterate(wdev
, wvif
)) != NULL
)
334 static int wfx_ps_timeout_get(void *data
, u64
*val
)
336 struct wfx_dev
*wdev
= (struct wfx_dev
*)data
;
338 *val
= wdev
->force_ps_timeout
;
342 DEFINE_DEBUGFS_ATTRIBUTE(wfx_ps_timeout_fops
, wfx_ps_timeout_get
, wfx_ps_timeout_set
, "%lld\n");
344 int wfx_debug_init(struct wfx_dev
*wdev
)
348 d
= debugfs_create_dir("wfx", wdev
->hw
->wiphy
->debugfsdir
);
349 debugfs_create_file("counters", 0444, d
, wdev
, &wfx_counters_fops
);
350 debugfs_create_file("rx_stats", 0444, d
, wdev
, &wfx_rx_stats_fops
);
351 debugfs_create_file("tx_power_loop", 0444, d
, wdev
,
352 &wfx_tx_power_loop_fops
);
353 debugfs_create_file("send_pds", 0200, d
, wdev
, &wfx_send_pds_fops
);
354 debugfs_create_file("send_hif_msg", 0600, d
, wdev
,
355 &wfx_send_hif_msg_fops
);
356 debugfs_create_file("ps_timeout", 0600, d
, wdev
, &wfx_ps_timeout_fops
);