]>
Commit | Line | Data |
---|---|---|
5e3dd157 KV |
1 | /* |
2 | * Copyright (c) 2005-2011 Atheros Communications Inc. | |
3 | * Copyright (c) 2011-2013 Qualcomm Atheros, Inc. | |
4 | * | |
5 | * Permission to use, copy, modify, and/or distribute this software for any | |
6 | * purpose with or without fee is hereby granted, provided that the above | |
7 | * copyright notice and this permission notice appear in all copies. | |
8 | * | |
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
16 | */ | |
17 | ||
18 | #include <linux/module.h> | |
19 | #include <linux/debugfs.h> | |
384914b2 BG |
20 | #include <linux/version.h> |
21 | #include <linux/vermagic.h> | |
22 | #include <linux/vmalloc.h> | |
5e3dd157 KV |
23 | |
24 | #include "core.h" | |
25 | #include "debug.h" | |
26 | ||
a3d135e5 KV |
27 | /* ms */ |
28 | #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000 | |
29 | ||
384914b2 BG |
30 | #define ATH10K_FW_CRASH_DUMP_VERSION 1 |
31 | ||
32 | /** | |
33 | * enum ath10k_fw_crash_dump_type - types of data in the dump file | |
34 | * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format | |
35 | */ | |
36 | enum ath10k_fw_crash_dump_type { | |
37 | ATH10K_FW_CRASH_DUMP_REGISTERS = 0, | |
38 | ||
39 | ATH10K_FW_CRASH_DUMP_MAX, | |
40 | }; | |
41 | ||
42 | struct ath10k_tlv_dump_data { | |
43 | /* see ath10k_fw_crash_dump_type above */ | |
44 | __le32 type; | |
45 | ||
46 | /* in bytes */ | |
47 | __le32 tlv_len; | |
48 | ||
49 | /* pad to 32-bit boundaries as needed */ | |
50 | u8 tlv_data[]; | |
51 | } __packed; | |
52 | ||
53 | struct ath10k_dump_file_data { | |
54 | /* dump file information */ | |
55 | ||
56 | /* "ATH10K-FW-DUMP" */ | |
57 | char df_magic[16]; | |
58 | ||
59 | __le32 len; | |
60 | ||
61 | /* file dump version */ | |
62 | __le32 version; | |
63 | ||
64 | /* some info we can get from ath10k struct that might help */ | |
65 | ||
66 | u8 uuid[16]; | |
67 | ||
68 | __le32 chip_id; | |
69 | ||
70 | /* 0 for now, in place for later hardware */ | |
71 | __le32 bus_type; | |
72 | ||
73 | __le32 target_version; | |
74 | __le32 fw_version_major; | |
75 | __le32 fw_version_minor; | |
76 | __le32 fw_version_release; | |
77 | __le32 fw_version_build; | |
78 | __le32 phy_capability; | |
79 | __le32 hw_min_tx_power; | |
80 | __le32 hw_max_tx_power; | |
81 | __le32 ht_cap_info; | |
82 | __le32 vht_cap_info; | |
83 | __le32 num_rf_chains; | |
84 | ||
85 | /* firmware version string */ | |
86 | char fw_ver[ETHTOOL_FWVERS_LEN]; | |
87 | ||
88 | /* Kernel related information */ | |
89 | ||
90 | /* time-of-day stamp */ | |
91 | __le64 tv_sec; | |
92 | ||
93 | /* time-of-day stamp, nano-seconds */ | |
94 | __le64 tv_nsec; | |
95 | ||
96 | /* LINUX_VERSION_CODE */ | |
97 | __le32 kernel_ver_code; | |
98 | ||
99 | /* VERMAGIC_STRING */ | |
100 | char kernel_ver[64]; | |
101 | ||
102 | /* room for growth w/out changing binary format */ | |
103 | u8 unused[128]; | |
104 | ||
105 | /* struct ath10k_tlv_dump_data + more */ | |
106 | u8 data[0]; | |
107 | } __packed; | |
108 | ||
7aa7a72a | 109 | int ath10k_info(struct ath10k *ar, const char *fmt, ...) |
5e3dd157 KV |
110 | { |
111 | struct va_format vaf = { | |
112 | .fmt = fmt, | |
113 | }; | |
114 | va_list args; | |
115 | int ret; | |
116 | ||
117 | va_start(args, fmt); | |
118 | vaf.va = &args; | |
7aa7a72a | 119 | ret = dev_info(ar->dev, "%pV", &vaf); |
d35a6c18 | 120 | trace_ath10k_log_info(ar, &vaf); |
5e3dd157 KV |
121 | va_end(args); |
122 | ||
123 | return ret; | |
124 | } | |
125 | EXPORT_SYMBOL(ath10k_info); | |
126 | ||
8a0c797e KV |
127 | void ath10k_print_driver_info(struct ath10k *ar) |
128 | { | |
7aa7a72a | 129 | ath10k_info(ar, "%s (0x%08x, 0x%08x) fw %s api %d htt %d.%d\n", |
8a0c797e KV |
130 | ar->hw_params.name, |
131 | ar->target_version, | |
132 | ar->chip_id, | |
133 | ar->hw->wiphy->fw_version, | |
134 | ar->fw_api, | |
135 | ar->htt.target_version_major, | |
136 | ar->htt.target_version_minor); | |
43d2a30f | 137 | ath10k_info(ar, "debug %d debugfs %d tracing %d dfs %d testmode %d\n", |
8a0c797e KV |
138 | config_enabled(CONFIG_ATH10K_DEBUG), |
139 | config_enabled(CONFIG_ATH10K_DEBUGFS), | |
140 | config_enabled(CONFIG_ATH10K_TRACING), | |
43d2a30f KV |
141 | config_enabled(CONFIG_ATH10K_DFS_CERTIFIED), |
142 | config_enabled(CONFIG_NL80211_TESTMODE)); | |
8a0c797e KV |
143 | } |
144 | EXPORT_SYMBOL(ath10k_print_driver_info); | |
145 | ||
7aa7a72a | 146 | int ath10k_err(struct ath10k *ar, const char *fmt, ...) |
5e3dd157 KV |
147 | { |
148 | struct va_format vaf = { | |
149 | .fmt = fmt, | |
150 | }; | |
151 | va_list args; | |
152 | int ret; | |
153 | ||
154 | va_start(args, fmt); | |
155 | vaf.va = &args; | |
7aa7a72a | 156 | ret = dev_err(ar->dev, "%pV", &vaf); |
d35a6c18 | 157 | trace_ath10k_log_err(ar, &vaf); |
5e3dd157 KV |
158 | va_end(args); |
159 | ||
160 | return ret; | |
161 | } | |
162 | EXPORT_SYMBOL(ath10k_err); | |
163 | ||
7aa7a72a | 164 | int ath10k_warn(struct ath10k *ar, const char *fmt, ...) |
5e3dd157 KV |
165 | { |
166 | struct va_format vaf = { | |
167 | .fmt = fmt, | |
168 | }; | |
169 | va_list args; | |
5e3dd157 KV |
170 | |
171 | va_start(args, fmt); | |
172 | vaf.va = &args; | |
7aa7a72a | 173 | dev_warn_ratelimited(ar->dev, "%pV", &vaf); |
d35a6c18 | 174 | trace_ath10k_log_warn(ar, &vaf); |
5e3dd157 KV |
175 | |
176 | va_end(args); | |
177 | ||
7aa7a72a | 178 | return 0; |
5e3dd157 KV |
179 | } |
180 | EXPORT_SYMBOL(ath10k_warn); | |
181 | ||
182 | #ifdef CONFIG_ATH10K_DEBUGFS | |
183 | ||
184 | void ath10k_debug_read_service_map(struct ath10k *ar, | |
185 | void *service_map, | |
186 | size_t map_size) | |
187 | { | |
188 | memcpy(ar->debug.wmi_service_bitmap, service_map, map_size); | |
189 | } | |
190 | ||
191 | static ssize_t ath10k_read_wmi_services(struct file *file, | |
192 | char __user *user_buf, | |
193 | size_t count, loff_t *ppos) | |
194 | { | |
195 | struct ath10k *ar = file->private_data; | |
196 | char *buf; | |
cff990ce MK |
197 | unsigned int len = 0, buf_len = 4096; |
198 | const char *name; | |
5e3dd157 | 199 | ssize_t ret_cnt; |
cff990ce | 200 | bool enabled; |
5e3dd157 KV |
201 | int i; |
202 | ||
203 | buf = kzalloc(buf_len, GFP_KERNEL); | |
204 | if (!buf) | |
205 | return -ENOMEM; | |
206 | ||
207 | mutex_lock(&ar->conf_mutex); | |
208 | ||
209 | if (len > buf_len) | |
210 | len = buf_len; | |
211 | ||
c4f8c836 | 212 | for (i = 0; i < WMI_SERVICE_MAX; i++) { |
cff990ce MK |
213 | enabled = test_bit(i, ar->debug.wmi_service_bitmap); |
214 | name = wmi_service_name(i); | |
215 | ||
216 | if (!name) { | |
217 | if (enabled) | |
218 | len += scnprintf(buf + len, buf_len - len, | |
219 | "%-40s %s (bit %d)\n", | |
220 | "unknown", "enabled", i); | |
221 | ||
222 | continue; | |
223 | } | |
5e3dd157 KV |
224 | |
225 | len += scnprintf(buf + len, buf_len - len, | |
cff990ce MK |
226 | "%-40s %s\n", |
227 | name, enabled ? "enabled" : "-"); | |
5e3dd157 KV |
228 | } |
229 | ||
230 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
231 | ||
232 | mutex_unlock(&ar->conf_mutex); | |
233 | ||
234 | kfree(buf); | |
235 | return ret_cnt; | |
236 | } | |
237 | ||
238 | static const struct file_operations fops_wmi_services = { | |
239 | .read = ath10k_read_wmi_services, | |
240 | .open = simple_open, | |
241 | .owner = THIS_MODULE, | |
242 | .llseek = default_llseek, | |
243 | }; | |
244 | ||
245 | void ath10k_debug_read_target_stats(struct ath10k *ar, | |
246 | struct wmi_stats_event *ev) | |
247 | { | |
248 | u8 *tmp = ev->data; | |
249 | struct ath10k_target_stats *stats; | |
250 | int num_pdev_stats, num_vdev_stats, num_peer_stats; | |
52e346d1 | 251 | struct wmi_pdev_stats_10x *ps; |
5e3dd157 KV |
252 | int i; |
253 | ||
87571bf0 | 254 | spin_lock_bh(&ar->data_lock); |
5e3dd157 KV |
255 | |
256 | stats = &ar->debug.target_stats; | |
257 | ||
258 | num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats); /* 0 or 1 */ | |
259 | num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats); /* 0 or max vdevs */ | |
260 | num_peer_stats = __le32_to_cpu(ev->num_peer_stats); /* 0 or max peers */ | |
261 | ||
262 | if (num_pdev_stats) { | |
52e346d1 | 263 | ps = (struct wmi_pdev_stats_10x *)tmp; |
5e3dd157 KV |
264 | |
265 | stats->ch_noise_floor = __le32_to_cpu(ps->chan_nf); | |
266 | stats->tx_frame_count = __le32_to_cpu(ps->tx_frame_count); | |
267 | stats->rx_frame_count = __le32_to_cpu(ps->rx_frame_count); | |
268 | stats->rx_clear_count = __le32_to_cpu(ps->rx_clear_count); | |
269 | stats->cycle_count = __le32_to_cpu(ps->cycle_count); | |
270 | stats->phy_err_count = __le32_to_cpu(ps->phy_err_count); | |
271 | stats->chan_tx_power = __le32_to_cpu(ps->chan_tx_pwr); | |
272 | ||
273 | stats->comp_queued = __le32_to_cpu(ps->wal.tx.comp_queued); | |
274 | stats->comp_delivered = | |
275 | __le32_to_cpu(ps->wal.tx.comp_delivered); | |
276 | stats->msdu_enqued = __le32_to_cpu(ps->wal.tx.msdu_enqued); | |
277 | stats->mpdu_enqued = __le32_to_cpu(ps->wal.tx.mpdu_enqued); | |
278 | stats->wmm_drop = __le32_to_cpu(ps->wal.tx.wmm_drop); | |
279 | stats->local_enqued = __le32_to_cpu(ps->wal.tx.local_enqued); | |
280 | stats->local_freed = __le32_to_cpu(ps->wal.tx.local_freed); | |
281 | stats->hw_queued = __le32_to_cpu(ps->wal.tx.hw_queued); | |
282 | stats->hw_reaped = __le32_to_cpu(ps->wal.tx.hw_reaped); | |
283 | stats->underrun = __le32_to_cpu(ps->wal.tx.underrun); | |
284 | stats->tx_abort = __le32_to_cpu(ps->wal.tx.tx_abort); | |
285 | stats->mpdus_requed = __le32_to_cpu(ps->wal.tx.mpdus_requed); | |
286 | stats->tx_ko = __le32_to_cpu(ps->wal.tx.tx_ko); | |
287 | stats->data_rc = __le32_to_cpu(ps->wal.tx.data_rc); | |
288 | stats->self_triggers = __le32_to_cpu(ps->wal.tx.self_triggers); | |
289 | stats->sw_retry_failure = | |
290 | __le32_to_cpu(ps->wal.tx.sw_retry_failure); | |
291 | stats->illgl_rate_phy_err = | |
292 | __le32_to_cpu(ps->wal.tx.illgl_rate_phy_err); | |
293 | stats->pdev_cont_xretry = | |
294 | __le32_to_cpu(ps->wal.tx.pdev_cont_xretry); | |
295 | stats->pdev_tx_timeout = | |
296 | __le32_to_cpu(ps->wal.tx.pdev_tx_timeout); | |
297 | stats->pdev_resets = __le32_to_cpu(ps->wal.tx.pdev_resets); | |
298 | stats->phy_underrun = __le32_to_cpu(ps->wal.tx.phy_underrun); | |
299 | stats->txop_ovf = __le32_to_cpu(ps->wal.tx.txop_ovf); | |
300 | ||
301 | stats->mid_ppdu_route_change = | |
302 | __le32_to_cpu(ps->wal.rx.mid_ppdu_route_change); | |
303 | stats->status_rcvd = __le32_to_cpu(ps->wal.rx.status_rcvd); | |
304 | stats->r0_frags = __le32_to_cpu(ps->wal.rx.r0_frags); | |
305 | stats->r1_frags = __le32_to_cpu(ps->wal.rx.r1_frags); | |
306 | stats->r2_frags = __le32_to_cpu(ps->wal.rx.r2_frags); | |
307 | stats->r3_frags = __le32_to_cpu(ps->wal.rx.r3_frags); | |
308 | stats->htt_msdus = __le32_to_cpu(ps->wal.rx.htt_msdus); | |
309 | stats->htt_mpdus = __le32_to_cpu(ps->wal.rx.htt_mpdus); | |
310 | stats->loc_msdus = __le32_to_cpu(ps->wal.rx.loc_msdus); | |
311 | stats->loc_mpdus = __le32_to_cpu(ps->wal.rx.loc_mpdus); | |
312 | stats->oversize_amsdu = | |
313 | __le32_to_cpu(ps->wal.rx.oversize_amsdu); | |
314 | stats->phy_errs = __le32_to_cpu(ps->wal.rx.phy_errs); | |
315 | stats->phy_err_drop = __le32_to_cpu(ps->wal.rx.phy_err_drop); | |
316 | stats->mpdu_errs = __le32_to_cpu(ps->wal.rx.mpdu_errs); | |
317 | ||
52e346d1 CYY |
318 | if (test_bit(ATH10K_FW_FEATURE_WMI_10X, |
319 | ar->fw_features)) { | |
320 | stats->ack_rx_bad = __le32_to_cpu(ps->ack_rx_bad); | |
321 | stats->rts_bad = __le32_to_cpu(ps->rts_bad); | |
322 | stats->rts_good = __le32_to_cpu(ps->rts_good); | |
323 | stats->fcs_bad = __le32_to_cpu(ps->fcs_bad); | |
324 | stats->no_beacons = __le32_to_cpu(ps->no_beacons); | |
325 | stats->mib_int_count = __le32_to_cpu(ps->mib_int_count); | |
326 | tmp += sizeof(struct wmi_pdev_stats_10x); | |
327 | } else { | |
328 | tmp += sizeof(struct wmi_pdev_stats_old); | |
329 | } | |
5e3dd157 KV |
330 | } |
331 | ||
332 | /* 0 or max vdevs */ | |
333 | /* Currently firmware does not support VDEV stats */ | |
334 | if (num_vdev_stats) { | |
335 | struct wmi_vdev_stats *vdev_stats; | |
336 | ||
337 | for (i = 0; i < num_vdev_stats; i++) { | |
338 | vdev_stats = (struct wmi_vdev_stats *)tmp; | |
339 | tmp += sizeof(struct wmi_vdev_stats); | |
340 | } | |
341 | } | |
342 | ||
343 | if (num_peer_stats) { | |
23c3aae4 | 344 | struct wmi_peer_stats_10x *peer_stats; |
5e3dd157 KV |
345 | struct ath10k_peer_stat *s; |
346 | ||
347 | stats->peers = num_peer_stats; | |
348 | ||
349 | for (i = 0; i < num_peer_stats; i++) { | |
23c3aae4 | 350 | peer_stats = (struct wmi_peer_stats_10x *)tmp; |
5e3dd157 KV |
351 | s = &stats->peer_stat[i]; |
352 | ||
cf0fd562 CYY |
353 | memcpy(s->peer_macaddr, &peer_stats->peer_macaddr.addr, |
354 | ETH_ALEN); | |
5e3dd157 KV |
355 | s->peer_rssi = __le32_to_cpu(peer_stats->peer_rssi); |
356 | s->peer_tx_rate = | |
357 | __le32_to_cpu(peer_stats->peer_tx_rate); | |
23c3aae4 BG |
358 | if (test_bit(ATH10K_FW_FEATURE_WMI_10X, |
359 | ar->fw_features)) { | |
360 | s->peer_rx_rate = | |
361 | __le32_to_cpu(peer_stats->peer_rx_rate); | |
362 | tmp += sizeof(struct wmi_peer_stats_10x); | |
363 | ||
364 | } else { | |
365 | tmp += sizeof(struct wmi_peer_stats_old); | |
366 | } | |
5e3dd157 KV |
367 | } |
368 | } | |
369 | ||
87571bf0 | 370 | spin_unlock_bh(&ar->data_lock); |
5e3dd157 KV |
371 | complete(&ar->debug.event_stats_compl); |
372 | } | |
373 | ||
374 | static ssize_t ath10k_read_fw_stats(struct file *file, char __user *user_buf, | |
375 | size_t count, loff_t *ppos) | |
376 | { | |
377 | struct ath10k *ar = file->private_data; | |
378 | struct ath10k_target_stats *fw_stats; | |
87571bf0 | 379 | char *buf = NULL; |
23c3aae4 | 380 | unsigned int len = 0, buf_len = 8000; |
87571bf0 | 381 | ssize_t ret_cnt = 0; |
5e3dd157 KV |
382 | long left; |
383 | int i; | |
384 | int ret; | |
385 | ||
386 | fw_stats = &ar->debug.target_stats; | |
387 | ||
87571bf0 MK |
388 | mutex_lock(&ar->conf_mutex); |
389 | ||
390 | if (ar->state != ATH10K_STATE_ON) | |
391 | goto exit; | |
392 | ||
5e3dd157 KV |
393 | buf = kzalloc(buf_len, GFP_KERNEL); |
394 | if (!buf) | |
87571bf0 | 395 | goto exit; |
5e3dd157 KV |
396 | |
397 | ret = ath10k_wmi_request_stats(ar, WMI_REQUEST_PEER_STAT); | |
398 | if (ret) { | |
7aa7a72a | 399 | ath10k_warn(ar, "could not request stats (%d)\n", ret); |
87571bf0 | 400 | goto exit; |
5e3dd157 KV |
401 | } |
402 | ||
403 | left = wait_for_completion_timeout(&ar->debug.event_stats_compl, 1*HZ); | |
87571bf0 MK |
404 | if (left <= 0) |
405 | goto exit; | |
5e3dd157 | 406 | |
87571bf0 | 407 | spin_lock_bh(&ar->data_lock); |
5e3dd157 KV |
408 | len += scnprintf(buf + len, buf_len - len, "\n"); |
409 | len += scnprintf(buf + len, buf_len - len, "%30s\n", | |
410 | "ath10k PDEV stats"); | |
411 | len += scnprintf(buf + len, buf_len - len, "%30s\n\n", | |
412 | "================="); | |
413 | ||
414 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
415 | "Channel noise floor", fw_stats->ch_noise_floor); | |
416 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
417 | "Channel TX power", fw_stats->chan_tx_power); | |
418 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
419 | "TX frame count", fw_stats->tx_frame_count); | |
420 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
421 | "RX frame count", fw_stats->rx_frame_count); | |
422 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
423 | "RX clear count", fw_stats->rx_clear_count); | |
424 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
425 | "Cycle count", fw_stats->cycle_count); | |
426 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
427 | "PHY error count", fw_stats->phy_err_count); | |
52e346d1 CYY |
428 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
429 | "RTS bad count", fw_stats->rts_bad); | |
430 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
431 | "RTS good count", fw_stats->rts_good); | |
432 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
433 | "FCS bad count", fw_stats->fcs_bad); | |
434 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
435 | "No beacon count", fw_stats->no_beacons); | |
436 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", | |
437 | "MIB int count", fw_stats->mib_int_count); | |
5e3dd157 KV |
438 | |
439 | len += scnprintf(buf + len, buf_len - len, "\n"); | |
440 | len += scnprintf(buf + len, buf_len - len, "%30s\n", | |
441 | "ath10k PDEV TX stats"); | |
442 | len += scnprintf(buf + len, buf_len - len, "%30s\n\n", | |
443 | "================="); | |
444 | ||
445 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
446 | "HTT cookies queued", fw_stats->comp_queued); | |
447 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
448 | "HTT cookies disp.", fw_stats->comp_delivered); | |
449 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
450 | "MSDU queued", fw_stats->msdu_enqued); | |
451 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
452 | "MPDU queued", fw_stats->mpdu_enqued); | |
453 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
454 | "MSDUs dropped", fw_stats->wmm_drop); | |
455 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
456 | "Local enqued", fw_stats->local_enqued); | |
457 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
458 | "Local freed", fw_stats->local_freed); | |
459 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
460 | "HW queued", fw_stats->hw_queued); | |
461 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
462 | "PPDUs reaped", fw_stats->hw_reaped); | |
463 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
464 | "Num underruns", fw_stats->underrun); | |
465 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
466 | "PPDUs cleaned", fw_stats->tx_abort); | |
467 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
468 | "MPDUs requed", fw_stats->mpdus_requed); | |
469 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
470 | "Excessive retries", fw_stats->tx_ko); | |
471 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
472 | "HW rate", fw_stats->data_rc); | |
473 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
474 | "Sched self tiggers", fw_stats->self_triggers); | |
475 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
476 | "Dropped due to SW retries", | |
477 | fw_stats->sw_retry_failure); | |
478 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
479 | "Illegal rate phy errors", | |
480 | fw_stats->illgl_rate_phy_err); | |
481 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
482 | "Pdev continous xretry", fw_stats->pdev_cont_xretry); | |
483 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
484 | "TX timeout", fw_stats->pdev_tx_timeout); | |
485 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
486 | "PDEV resets", fw_stats->pdev_resets); | |
487 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
488 | "PHY underrun", fw_stats->phy_underrun); | |
489 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
490 | "MPDU is more than txop limit", fw_stats->txop_ovf); | |
491 | ||
492 | len += scnprintf(buf + len, buf_len - len, "\n"); | |
493 | len += scnprintf(buf + len, buf_len - len, "%30s\n", | |
494 | "ath10k PDEV RX stats"); | |
495 | len += scnprintf(buf + len, buf_len - len, "%30s\n\n", | |
496 | "================="); | |
497 | ||
498 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
499 | "Mid PPDU route change", | |
500 | fw_stats->mid_ppdu_route_change); | |
501 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
502 | "Tot. number of statuses", fw_stats->status_rcvd); | |
503 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
504 | "Extra frags on rings 0", fw_stats->r0_frags); | |
505 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
506 | "Extra frags on rings 1", fw_stats->r1_frags); | |
507 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
508 | "Extra frags on rings 2", fw_stats->r2_frags); | |
509 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
510 | "Extra frags on rings 3", fw_stats->r3_frags); | |
511 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
512 | "MSDUs delivered to HTT", fw_stats->htt_msdus); | |
513 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
514 | "MPDUs delivered to HTT", fw_stats->htt_mpdus); | |
515 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
516 | "MSDUs delivered to stack", fw_stats->loc_msdus); | |
517 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
518 | "MPDUs delivered to stack", fw_stats->loc_mpdus); | |
519 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
520 | "Oversized AMSUs", fw_stats->oversize_amsdu); | |
521 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
522 | "PHY errors", fw_stats->phy_errs); | |
523 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
524 | "PHY errors drops", fw_stats->phy_err_drop); | |
525 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", | |
526 | "MPDU errors (FCS, MIC, ENC)", fw_stats->mpdu_errs); | |
527 | ||
528 | len += scnprintf(buf + len, buf_len - len, "\n"); | |
23c3aae4 BG |
529 | len += scnprintf(buf + len, buf_len - len, "%30s (%d)\n", |
530 | "ath10k PEER stats", fw_stats->peers); | |
5e3dd157 KV |
531 | len += scnprintf(buf + len, buf_len - len, "%30s\n\n", |
532 | "================="); | |
533 | ||
534 | for (i = 0; i < fw_stats->peers; i++) { | |
535 | len += scnprintf(buf + len, buf_len - len, "%30s %pM\n", | |
536 | "Peer MAC address", | |
537 | fw_stats->peer_stat[i].peer_macaddr); | |
538 | len += scnprintf(buf + len, buf_len - len, "%30s %u\n", | |
539 | "Peer RSSI", fw_stats->peer_stat[i].peer_rssi); | |
540 | len += scnprintf(buf + len, buf_len - len, "%30s %u\n", | |
541 | "Peer TX rate", | |
542 | fw_stats->peer_stat[i].peer_tx_rate); | |
23c3aae4 BG |
543 | len += scnprintf(buf + len, buf_len - len, "%30s %u\n", |
544 | "Peer RX rate", | |
545 | fw_stats->peer_stat[i].peer_rx_rate); | |
5e3dd157 KV |
546 | len += scnprintf(buf + len, buf_len - len, "\n"); |
547 | } | |
87571bf0 | 548 | spin_unlock_bh(&ar->data_lock); |
5e3dd157 KV |
549 | |
550 | if (len > buf_len) | |
551 | len = buf_len; | |
552 | ||
553 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
554 | ||
87571bf0 | 555 | exit: |
5e3dd157 | 556 | mutex_unlock(&ar->conf_mutex); |
5e3dd157 KV |
557 | kfree(buf); |
558 | return ret_cnt; | |
559 | } | |
560 | ||
561 | static const struct file_operations fops_fw_stats = { | |
562 | .read = ath10k_read_fw_stats, | |
563 | .open = simple_open, | |
564 | .owner = THIS_MODULE, | |
565 | .llseek = default_llseek, | |
566 | }; | |
567 | ||
d5aebc77 BG |
568 | /* This is a clean assert crash in firmware. */ |
569 | static int ath10k_debug_fw_assert(struct ath10k *ar) | |
570 | { | |
571 | struct wmi_vdev_install_key_cmd *cmd; | |
572 | struct sk_buff *skb; | |
573 | ||
574 | skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16); | |
575 | if (!skb) | |
576 | return -ENOMEM; | |
577 | ||
578 | cmd = (struct wmi_vdev_install_key_cmd *)skb->data; | |
579 | memset(cmd, 0, sizeof(*cmd)); | |
580 | ||
581 | /* big enough number so that firmware asserts */ | |
582 | cmd->vdev_id = __cpu_to_le32(0x7ffe); | |
583 | ||
584 | return ath10k_wmi_cmd_send(ar, skb, | |
585 | ar->wmi.cmd->vdev_install_key_cmdid); | |
586 | } | |
587 | ||
278c4a85 MK |
588 | static ssize_t ath10k_read_simulate_fw_crash(struct file *file, |
589 | char __user *user_buf, | |
590 | size_t count, loff_t *ppos) | |
591 | { | |
8c656992 MP |
592 | const char buf[] = "To simulate firmware crash write one of the" |
593 | " keywords to this file:\n `soft` - this will send" | |
594 | " WMI_FORCE_FW_HANG_ASSERT to firmware if FW" | |
595 | " supports that command.\n `hard` - this will send" | |
596 | " to firmware command with illegal parameters" | |
d5aebc77 BG |
597 | " causing firmware crash.\n" |
598 | "`assert` - this will send special illegal parameter" | |
599 | " to firmware to cause assert failure" | |
600 | " and crash.\n"; | |
8c656992 | 601 | |
278c4a85 MK |
602 | return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); |
603 | } | |
604 | ||
8c656992 MP |
605 | /* Simulate firmware crash: |
606 | * 'soft': Call wmi command causing firmware hang. This firmware hang is | |
607 | * recoverable by warm firmware reset. | |
608 | * 'hard': Force firmware crash by setting any vdev parameter for not allowed | |
609 | * vdev id. This is hard firmware crash because it is recoverable only by cold | |
610 | * firmware reset. | |
611 | */ | |
278c4a85 MK |
612 | static ssize_t ath10k_write_simulate_fw_crash(struct file *file, |
613 | const char __user *user_buf, | |
614 | size_t count, loff_t *ppos) | |
615 | { | |
616 | struct ath10k *ar = file->private_data; | |
8c656992 | 617 | char buf[32]; |
278c4a85 MK |
618 | int ret; |
619 | ||
620 | mutex_lock(&ar->conf_mutex); | |
621 | ||
622 | simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); | |
8c656992 MP |
623 | |
624 | /* make sure that buf is null terminated */ | |
625 | buf[sizeof(buf) - 1] = 0; | |
278c4a85 MK |
626 | |
627 | if (ar->state != ATH10K_STATE_ON && | |
628 | ar->state != ATH10K_STATE_RESTARTED) { | |
629 | ret = -ENETDOWN; | |
630 | goto exit; | |
631 | } | |
632 | ||
8c656992 MP |
633 | /* drop the possible '\n' from the end */ |
634 | if (buf[count - 1] == '\n') { | |
635 | buf[count - 1] = 0; | |
636 | count--; | |
637 | } | |
638 | ||
639 | if (!strcmp(buf, "soft")) { | |
7aa7a72a | 640 | ath10k_info(ar, "simulating soft firmware crash\n"); |
8c656992 MP |
641 | ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0); |
642 | } else if (!strcmp(buf, "hard")) { | |
7aa7a72a | 643 | ath10k_info(ar, "simulating hard firmware crash\n"); |
611b3682 BG |
644 | /* 0x7fff is vdev id, and it is always out of range for all |
645 | * firmware variants in order to force a firmware crash. | |
646 | */ | |
647 | ret = ath10k_wmi_vdev_set_param(ar, 0x7fff, | |
8c656992 | 648 | ar->wmi.vdev_param->rts_threshold, 0); |
d5aebc77 BG |
649 | } else if (!strcmp(buf, "assert")) { |
650 | ath10k_info(ar, "simulating firmware assert crash\n"); | |
651 | ret = ath10k_debug_fw_assert(ar); | |
8c656992 MP |
652 | } else { |
653 | ret = -EINVAL; | |
654 | goto exit; | |
655 | } | |
278c4a85 | 656 | |
8c656992 | 657 | if (ret) { |
7aa7a72a | 658 | ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret); |
8c656992 MP |
659 | goto exit; |
660 | } | |
278c4a85 | 661 | |
8c656992 | 662 | ret = count; |
278c4a85 MK |
663 | |
664 | exit: | |
665 | mutex_unlock(&ar->conf_mutex); | |
666 | return ret; | |
667 | } | |
668 | ||
669 | static const struct file_operations fops_simulate_fw_crash = { | |
670 | .read = ath10k_read_simulate_fw_crash, | |
671 | .write = ath10k_write_simulate_fw_crash, | |
672 | .open = simple_open, | |
673 | .owner = THIS_MODULE, | |
674 | .llseek = default_llseek, | |
675 | }; | |
676 | ||
763b8cd3 KV |
677 | static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf, |
678 | size_t count, loff_t *ppos) | |
679 | { | |
680 | struct ath10k *ar = file->private_data; | |
681 | unsigned int len; | |
682 | char buf[50]; | |
683 | ||
684 | len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id); | |
685 | ||
686 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
687 | } | |
688 | ||
689 | static const struct file_operations fops_chip_id = { | |
690 | .read = ath10k_read_chip_id, | |
691 | .open = simple_open, | |
692 | .owner = THIS_MODULE, | |
693 | .llseek = default_llseek, | |
694 | }; | |
695 | ||
384914b2 BG |
696 | struct ath10k_fw_crash_data * |
697 | ath10k_debug_get_new_fw_crash_data(struct ath10k *ar) | |
698 | { | |
699 | struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data; | |
700 | ||
701 | lockdep_assert_held(&ar->data_lock); | |
702 | ||
703 | crash_data->crashed_since_read = true; | |
704 | uuid_le_gen(&crash_data->uuid); | |
705 | getnstimeofday(&crash_data->timestamp); | |
706 | ||
707 | return crash_data; | |
708 | } | |
709 | EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data); | |
710 | ||
711 | static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar) | |
712 | { | |
713 | struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data; | |
714 | struct ath10k_dump_file_data *dump_data; | |
715 | struct ath10k_tlv_dump_data *dump_tlv; | |
716 | int hdr_len = sizeof(*dump_data); | |
717 | unsigned int len, sofar = 0; | |
718 | unsigned char *buf; | |
719 | ||
720 | len = hdr_len; | |
721 | len += sizeof(*dump_tlv) + sizeof(crash_data->registers); | |
722 | ||
723 | sofar += hdr_len; | |
724 | ||
725 | /* This is going to get big when we start dumping FW RAM and such, | |
726 | * so go ahead and use vmalloc. | |
727 | */ | |
728 | buf = vzalloc(len); | |
729 | if (!buf) | |
730 | return NULL; | |
731 | ||
732 | spin_lock_bh(&ar->data_lock); | |
733 | ||
734 | if (!crash_data->crashed_since_read) { | |
735 | spin_unlock_bh(&ar->data_lock); | |
736 | vfree(buf); | |
737 | return NULL; | |
738 | } | |
739 | ||
740 | dump_data = (struct ath10k_dump_file_data *)(buf); | |
741 | strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP", | |
742 | sizeof(dump_data->df_magic)); | |
743 | dump_data->len = cpu_to_le32(len); | |
744 | ||
745 | dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION); | |
746 | ||
747 | memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid)); | |
748 | dump_data->chip_id = cpu_to_le32(ar->chip_id); | |
749 | dump_data->bus_type = cpu_to_le32(0); | |
750 | dump_data->target_version = cpu_to_le32(ar->target_version); | |
751 | dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major); | |
752 | dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor); | |
753 | dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release); | |
754 | dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build); | |
755 | dump_data->phy_capability = cpu_to_le32(ar->phy_capability); | |
756 | dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power); | |
757 | dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power); | |
758 | dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info); | |
759 | dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info); | |
760 | dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains); | |
761 | ||
762 | strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version, | |
763 | sizeof(dump_data->fw_ver)); | |
764 | ||
765 | dump_data->kernel_ver_code = cpu_to_le32(LINUX_VERSION_CODE); | |
766 | strlcpy(dump_data->kernel_ver, VERMAGIC_STRING, | |
767 | sizeof(dump_data->kernel_ver)); | |
768 | ||
769 | dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec); | |
770 | dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec); | |
771 | ||
772 | /* Gather crash-dump */ | |
773 | dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar); | |
774 | dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS); | |
775 | dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers)); | |
776 | memcpy(dump_tlv->tlv_data, &crash_data->registers, | |
777 | sizeof(crash_data->registers)); | |
778 | sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers); | |
779 | ||
780 | ar->debug.fw_crash_data->crashed_since_read = false; | |
781 | ||
782 | spin_unlock_bh(&ar->data_lock); | |
783 | ||
784 | return dump_data; | |
785 | } | |
786 | ||
787 | static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file) | |
788 | { | |
789 | struct ath10k *ar = inode->i_private; | |
790 | struct ath10k_dump_file_data *dump; | |
791 | ||
792 | dump = ath10k_build_dump_file(ar); | |
793 | if (!dump) | |
794 | return -ENODATA; | |
795 | ||
796 | file->private_data = dump; | |
797 | ||
798 | return 0; | |
799 | } | |
800 | ||
801 | static ssize_t ath10k_fw_crash_dump_read(struct file *file, | |
802 | char __user *user_buf, | |
803 | size_t count, loff_t *ppos) | |
804 | { | |
805 | struct ath10k_dump_file_data *dump_file = file->private_data; | |
806 | ||
807 | return simple_read_from_buffer(user_buf, count, ppos, | |
808 | dump_file, | |
809 | le32_to_cpu(dump_file->len)); | |
810 | } | |
811 | ||
812 | static int ath10k_fw_crash_dump_release(struct inode *inode, | |
813 | struct file *file) | |
814 | { | |
815 | vfree(file->private_data); | |
816 | ||
817 | return 0; | |
818 | } | |
819 | ||
820 | static const struct file_operations fops_fw_crash_dump = { | |
821 | .open = ath10k_fw_crash_dump_open, | |
822 | .read = ath10k_fw_crash_dump_read, | |
823 | .release = ath10k_fw_crash_dump_release, | |
824 | .owner = THIS_MODULE, | |
825 | .llseek = default_llseek, | |
826 | }; | |
827 | ||
a3d135e5 KV |
828 | static int ath10k_debug_htt_stats_req(struct ath10k *ar) |
829 | { | |
830 | u64 cookie; | |
831 | int ret; | |
832 | ||
833 | lockdep_assert_held(&ar->conf_mutex); | |
834 | ||
835 | if (ar->debug.htt_stats_mask == 0) | |
836 | /* htt stats are disabled */ | |
837 | return 0; | |
838 | ||
839 | if (ar->state != ATH10K_STATE_ON) | |
840 | return 0; | |
841 | ||
842 | cookie = get_jiffies_64(); | |
843 | ||
844 | ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask, | |
845 | cookie); | |
846 | if (ret) { | |
7aa7a72a | 847 | ath10k_warn(ar, "failed to send htt stats request: %d\n", ret); |
a3d135e5 KV |
848 | return ret; |
849 | } | |
850 | ||
851 | queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork, | |
852 | msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL)); | |
853 | ||
854 | return 0; | |
855 | } | |
856 | ||
857 | static void ath10k_debug_htt_stats_dwork(struct work_struct *work) | |
858 | { | |
859 | struct ath10k *ar = container_of(work, struct ath10k, | |
860 | debug.htt_stats_dwork.work); | |
861 | ||
862 | mutex_lock(&ar->conf_mutex); | |
863 | ||
864 | ath10k_debug_htt_stats_req(ar); | |
865 | ||
866 | mutex_unlock(&ar->conf_mutex); | |
867 | } | |
868 | ||
869 | static ssize_t ath10k_read_htt_stats_mask(struct file *file, | |
870 | char __user *user_buf, | |
871 | size_t count, loff_t *ppos) | |
872 | { | |
873 | struct ath10k *ar = file->private_data; | |
874 | char buf[32]; | |
875 | unsigned int len; | |
876 | ||
877 | len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask); | |
878 | ||
879 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
880 | } | |
881 | ||
882 | static ssize_t ath10k_write_htt_stats_mask(struct file *file, | |
883 | const char __user *user_buf, | |
884 | size_t count, loff_t *ppos) | |
885 | { | |
886 | struct ath10k *ar = file->private_data; | |
887 | unsigned long mask; | |
888 | int ret; | |
889 | ||
890 | ret = kstrtoul_from_user(user_buf, count, 0, &mask); | |
891 | if (ret) | |
892 | return ret; | |
893 | ||
894 | /* max 8 bit masks (for now) */ | |
895 | if (mask > 0xff) | |
896 | return -E2BIG; | |
897 | ||
898 | mutex_lock(&ar->conf_mutex); | |
899 | ||
900 | ar->debug.htt_stats_mask = mask; | |
901 | ||
902 | ret = ath10k_debug_htt_stats_req(ar); | |
903 | if (ret) | |
904 | goto out; | |
905 | ||
906 | ret = count; | |
907 | ||
908 | out: | |
909 | mutex_unlock(&ar->conf_mutex); | |
910 | ||
911 | return ret; | |
912 | } | |
913 | ||
914 | static const struct file_operations fops_htt_stats_mask = { | |
915 | .read = ath10k_read_htt_stats_mask, | |
916 | .write = ath10k_write_htt_stats_mask, | |
917 | .open = simple_open, | |
918 | .owner = THIS_MODULE, | |
919 | .llseek = default_llseek, | |
920 | }; | |
921 | ||
d385623a JD |
922 | static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file, |
923 | char __user *user_buf, | |
924 | size_t count, loff_t *ppos) | |
925 | { | |
926 | struct ath10k *ar = file->private_data; | |
927 | char buf[64]; | |
928 | u8 amsdu = 3, ampdu = 64; | |
929 | unsigned int len; | |
930 | ||
931 | mutex_lock(&ar->conf_mutex); | |
932 | ||
933 | if (ar->debug.htt_max_amsdu) | |
934 | amsdu = ar->debug.htt_max_amsdu; | |
935 | ||
936 | if (ar->debug.htt_max_ampdu) | |
937 | ampdu = ar->debug.htt_max_ampdu; | |
938 | ||
939 | mutex_unlock(&ar->conf_mutex); | |
940 | ||
941 | len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu); | |
942 | ||
943 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
944 | } | |
945 | ||
946 | static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file, | |
947 | const char __user *user_buf, | |
948 | size_t count, loff_t *ppos) | |
949 | { | |
950 | struct ath10k *ar = file->private_data; | |
951 | int res; | |
952 | char buf[64]; | |
953 | unsigned int amsdu, ampdu; | |
954 | ||
955 | simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); | |
956 | ||
957 | /* make sure that buf is null terminated */ | |
958 | buf[sizeof(buf) - 1] = 0; | |
959 | ||
960 | res = sscanf(buf, "%u %u", &amsdu, &du); | |
961 | ||
962 | if (res != 2) | |
963 | return -EINVAL; | |
964 | ||
965 | mutex_lock(&ar->conf_mutex); | |
966 | ||
967 | res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu); | |
968 | if (res) | |
969 | goto out; | |
970 | ||
971 | res = count; | |
972 | ar->debug.htt_max_amsdu = amsdu; | |
973 | ar->debug.htt_max_ampdu = ampdu; | |
974 | ||
975 | out: | |
976 | mutex_unlock(&ar->conf_mutex); | |
977 | return res; | |
978 | } | |
979 | ||
980 | static const struct file_operations fops_htt_max_amsdu_ampdu = { | |
981 | .read = ath10k_read_htt_max_amsdu_ampdu, | |
982 | .write = ath10k_write_htt_max_amsdu_ampdu, | |
983 | .open = simple_open, | |
984 | .owner = THIS_MODULE, | |
985 | .llseek = default_llseek, | |
986 | }; | |
987 | ||
f118a3e5 KV |
988 | static ssize_t ath10k_read_fw_dbglog(struct file *file, |
989 | char __user *user_buf, | |
990 | size_t count, loff_t *ppos) | |
991 | { | |
992 | struct ath10k *ar = file->private_data; | |
993 | unsigned int len; | |
994 | char buf[32]; | |
995 | ||
996 | len = scnprintf(buf, sizeof(buf), "0x%08x\n", | |
997 | ar->debug.fw_dbglog_mask); | |
998 | ||
999 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
1000 | } | |
1001 | ||
1002 | static ssize_t ath10k_write_fw_dbglog(struct file *file, | |
1003 | const char __user *user_buf, | |
1004 | size_t count, loff_t *ppos) | |
1005 | { | |
1006 | struct ath10k *ar = file->private_data; | |
1007 | unsigned long mask; | |
1008 | int ret; | |
1009 | ||
1010 | ret = kstrtoul_from_user(user_buf, count, 0, &mask); | |
1011 | if (ret) | |
1012 | return ret; | |
1013 | ||
1014 | mutex_lock(&ar->conf_mutex); | |
1015 | ||
1016 | ar->debug.fw_dbglog_mask = mask; | |
1017 | ||
1018 | if (ar->state == ATH10K_STATE_ON) { | |
1019 | ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask); | |
1020 | if (ret) { | |
7aa7a72a | 1021 | ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n", |
f118a3e5 KV |
1022 | ret); |
1023 | goto exit; | |
1024 | } | |
1025 | } | |
1026 | ||
1027 | ret = count; | |
1028 | ||
1029 | exit: | |
1030 | mutex_unlock(&ar->conf_mutex); | |
1031 | ||
1032 | return ret; | |
1033 | } | |
1034 | ||
1035 | static const struct file_operations fops_fw_dbglog = { | |
1036 | .read = ath10k_read_fw_dbglog, | |
1037 | .write = ath10k_write_fw_dbglog, | |
1038 | .open = simple_open, | |
1039 | .owner = THIS_MODULE, | |
1040 | .llseek = default_llseek, | |
1041 | }; | |
1042 | ||
db66ea04 KV |
1043 | int ath10k_debug_start(struct ath10k *ar) |
1044 | { | |
a3d135e5 KV |
1045 | int ret; |
1046 | ||
60631c5c KV |
1047 | lockdep_assert_held(&ar->conf_mutex); |
1048 | ||
a3d135e5 KV |
1049 | ret = ath10k_debug_htt_stats_req(ar); |
1050 | if (ret) | |
1051 | /* continue normally anyway, this isn't serious */ | |
7aa7a72a MK |
1052 | ath10k_warn(ar, "failed to start htt stats workqueue: %d\n", |
1053 | ret); | |
a3d135e5 | 1054 | |
f118a3e5 KV |
1055 | if (ar->debug.fw_dbglog_mask) { |
1056 | ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask); | |
1057 | if (ret) | |
1058 | /* not serious */ | |
7aa7a72a | 1059 | ath10k_warn(ar, "failed to enable dbglog during start: %d", |
f118a3e5 KV |
1060 | ret); |
1061 | } | |
1062 | ||
db66ea04 KV |
1063 | return 0; |
1064 | } | |
1065 | ||
1066 | void ath10k_debug_stop(struct ath10k *ar) | |
1067 | { | |
60631c5c KV |
1068 | lockdep_assert_held(&ar->conf_mutex); |
1069 | ||
1070 | /* Must not use _sync to avoid deadlock, we do that in | |
1071 | * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid | |
1072 | * warning from del_timer(). */ | |
1073 | if (ar->debug.htt_stats_mask != 0) | |
1074 | cancel_delayed_work(&ar->debug.htt_stats_dwork); | |
d385623a JD |
1075 | |
1076 | ar->debug.htt_max_amsdu = 0; | |
1077 | ar->debug.htt_max_ampdu = 0; | |
db66ea04 KV |
1078 | } |
1079 | ||
9702c686 JD |
1080 | static ssize_t ath10k_write_simulate_radar(struct file *file, |
1081 | const char __user *user_buf, | |
1082 | size_t count, loff_t *ppos) | |
1083 | { | |
1084 | struct ath10k *ar = file->private_data; | |
1085 | ||
1086 | ieee80211_radar_detected(ar->hw); | |
1087 | ||
1088 | return count; | |
1089 | } | |
1090 | ||
1091 | static const struct file_operations fops_simulate_radar = { | |
1092 | .write = ath10k_write_simulate_radar, | |
1093 | .open = simple_open, | |
1094 | .owner = THIS_MODULE, | |
1095 | .llseek = default_llseek, | |
1096 | }; | |
1097 | ||
1098 | #define ATH10K_DFS_STAT(s, p) (\ | |
1099 | len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \ | |
1100 | ar->debug.dfs_stats.p)) | |
1101 | ||
1102 | #define ATH10K_DFS_POOL_STAT(s, p) (\ | |
1103 | len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \ | |
1104 | ar->debug.dfs_pool_stats.p)) | |
1105 | ||
1106 | static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf, | |
1107 | size_t count, loff_t *ppos) | |
1108 | { | |
1109 | int retval = 0, len = 0; | |
1110 | const int size = 8000; | |
1111 | struct ath10k *ar = file->private_data; | |
1112 | char *buf; | |
1113 | ||
1114 | buf = kzalloc(size, GFP_KERNEL); | |
1115 | if (buf == NULL) | |
1116 | return -ENOMEM; | |
1117 | ||
1118 | if (!ar->dfs_detector) { | |
1119 | len += scnprintf(buf + len, size - len, "DFS not enabled\n"); | |
1120 | goto exit; | |
1121 | } | |
1122 | ||
1123 | ar->debug.dfs_pool_stats = | |
1124 | ar->dfs_detector->get_stats(ar->dfs_detector); | |
1125 | ||
1126 | len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n"); | |
1127 | ||
1128 | ATH10K_DFS_STAT("reported phy errors", phy_errors); | |
1129 | ATH10K_DFS_STAT("pulse events reported", pulses_total); | |
1130 | ATH10K_DFS_STAT("DFS pulses detected", pulses_detected); | |
1131 | ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded); | |
1132 | ATH10K_DFS_STAT("Radars detected", radar_detected); | |
1133 | ||
1134 | len += scnprintf(buf + len, size - len, "Global Pool statistics:\n"); | |
1135 | ATH10K_DFS_POOL_STAT("Pool references", pool_reference); | |
1136 | ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated); | |
1137 | ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error); | |
1138 | ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used); | |
1139 | ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated); | |
1140 | ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error); | |
1141 | ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used); | |
1142 | ||
1143 | exit: | |
1144 | if (len > size) | |
1145 | len = size; | |
1146 | ||
1147 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
1148 | kfree(buf); | |
1149 | ||
1150 | return retval; | |
1151 | } | |
1152 | ||
1153 | static const struct file_operations fops_dfs_stats = { | |
1154 | .read = ath10k_read_dfs_stats, | |
1155 | .open = simple_open, | |
1156 | .owner = THIS_MODULE, | |
1157 | .llseek = default_llseek, | |
1158 | }; | |
1159 | ||
5e3dd157 KV |
1160 | int ath10k_debug_create(struct ath10k *ar) |
1161 | { | |
384914b2 | 1162 | ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data)); |
e13cf7a3 MK |
1163 | if (!ar->debug.fw_crash_data) |
1164 | return -ENOMEM; | |
384914b2 | 1165 | |
e13cf7a3 MK |
1166 | return 0; |
1167 | } | |
1168 | ||
1169 | void ath10k_debug_destroy(struct ath10k *ar) | |
1170 | { | |
1171 | vfree(ar->debug.fw_crash_data); | |
1172 | ar->debug.fw_crash_data = NULL; | |
1173 | } | |
1174 | ||
1175 | int ath10k_debug_register(struct ath10k *ar) | |
1176 | { | |
5e3dd157 KV |
1177 | ar->debug.debugfs_phy = debugfs_create_dir("ath10k", |
1178 | ar->hw->wiphy->debugfsdir); | |
adb43b24 MK |
1179 | if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) { |
1180 | if (IS_ERR(ar->debug.debugfs_phy)) | |
1181 | return PTR_ERR(ar->debug.debugfs_phy); | |
1182 | else | |
1183 | return -ENOMEM; | |
1184 | } | |
5e3dd157 | 1185 | |
a3d135e5 KV |
1186 | INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork, |
1187 | ath10k_debug_htt_stats_dwork); | |
1188 | ||
5e3dd157 KV |
1189 | init_completion(&ar->debug.event_stats_compl); |
1190 | ||
1191 | debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar, | |
1192 | &fops_fw_stats); | |
1193 | ||
1194 | debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar, | |
1195 | &fops_wmi_services); | |
1196 | ||
278c4a85 MK |
1197 | debugfs_create_file("simulate_fw_crash", S_IRUSR, ar->debug.debugfs_phy, |
1198 | ar, &fops_simulate_fw_crash); | |
1199 | ||
384914b2 BG |
1200 | debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy, |
1201 | ar, &fops_fw_crash_dump); | |
1202 | ||
763b8cd3 KV |
1203 | debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy, |
1204 | ar, &fops_chip_id); | |
1205 | ||
a3d135e5 KV |
1206 | debugfs_create_file("htt_stats_mask", S_IRUSR, ar->debug.debugfs_phy, |
1207 | ar, &fops_htt_stats_mask); | |
1208 | ||
d385623a JD |
1209 | debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR, |
1210 | ar->debug.debugfs_phy, ar, | |
1211 | &fops_htt_max_amsdu_ampdu); | |
1212 | ||
f118a3e5 KV |
1213 | debugfs_create_file("fw_dbglog", S_IRUSR, ar->debug.debugfs_phy, |
1214 | ar, &fops_fw_dbglog); | |
1215 | ||
9702c686 JD |
1216 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) { |
1217 | debugfs_create_file("dfs_simulate_radar", S_IWUSR, | |
1218 | ar->debug.debugfs_phy, ar, | |
1219 | &fops_simulate_radar); | |
1220 | ||
7d9b40b4 MP |
1221 | debugfs_create_bool("dfs_block_radar_events", S_IWUSR, |
1222 | ar->debug.debugfs_phy, | |
1223 | &ar->dfs_block_radar_events); | |
1224 | ||
9702c686 JD |
1225 | debugfs_create_file("dfs_stats", S_IRUSR, |
1226 | ar->debug.debugfs_phy, ar, | |
1227 | &fops_dfs_stats); | |
1228 | } | |
1229 | ||
5e3dd157 KV |
1230 | return 0; |
1231 | } | |
db66ea04 | 1232 | |
e13cf7a3 | 1233 | void ath10k_debug_unregister(struct ath10k *ar) |
60631c5c KV |
1234 | { |
1235 | cancel_delayed_work_sync(&ar->debug.htt_stats_dwork); | |
1236 | } | |
1237 | ||
5e3dd157 KV |
1238 | #endif /* CONFIG_ATH10K_DEBUGFS */ |
1239 | ||
1240 | #ifdef CONFIG_ATH10K_DEBUG | |
7aa7a72a MK |
1241 | void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask, |
1242 | const char *fmt, ...) | |
5e3dd157 KV |
1243 | { |
1244 | struct va_format vaf; | |
1245 | va_list args; | |
1246 | ||
1247 | va_start(args, fmt); | |
1248 | ||
1249 | vaf.fmt = fmt; | |
1250 | vaf.va = &args; | |
1251 | ||
1252 | if (ath10k_debug_mask & mask) | |
7aa7a72a | 1253 | dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf); |
5e3dd157 | 1254 | |
d35a6c18 | 1255 | trace_ath10k_log_dbg(ar, mask, &vaf); |
5e3dd157 KV |
1256 | |
1257 | va_end(args); | |
1258 | } | |
1259 | EXPORT_SYMBOL(ath10k_dbg); | |
1260 | ||
7aa7a72a MK |
1261 | void ath10k_dbg_dump(struct ath10k *ar, |
1262 | enum ath10k_debug_mask mask, | |
5e3dd157 KV |
1263 | const char *msg, const char *prefix, |
1264 | const void *buf, size_t len) | |
1265 | { | |
1266 | if (ath10k_debug_mask & mask) { | |
1267 | if (msg) | |
7aa7a72a | 1268 | ath10k_dbg(ar, mask, "%s\n", msg); |
5e3dd157 KV |
1269 | |
1270 | print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, buf, len); | |
1271 | } | |
1272 | ||
1273 | /* tracing code doesn't like null strings :/ */ | |
d35a6c18 | 1274 | trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "", |
5e3dd157 KV |
1275 | buf, len); |
1276 | } | |
1277 | EXPORT_SYMBOL(ath10k_dbg_dump); | |
1278 | ||
1279 | #endif /* CONFIG_ATH10K_DEBUG */ |