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