blob: a8f5a72ba2591059594dcf590f960d195c85d8eb [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
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>
Ben Greear384914b2014-08-25 08:37:32 +030020#include <linux/version.h>
21#include <linux/vermagic.h>
22#include <linux/vmalloc.h>
Kalle Valo5e3dd152013-06-12 20:52:10 +030023
24#include "core.h"
25#include "debug.h"
Kalle Valo7869b4f2014-09-24 14:16:58 +030026#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030027
Kalle Valoa3d135e2013-09-03 11:44:10 +030028/* ms */
29#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
30
Ben Greear384914b2014-08-25 08:37:32 +030031#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 */
37enum ath10k_fw_crash_dump_type {
38 ATH10K_FW_CRASH_DUMP_REGISTERS = 0,
39
40 ATH10K_FW_CRASH_DUMP_MAX,
41};
42
43struct 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
54struct 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
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700110void ath10k_info(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300111{
112 struct va_format vaf = {
113 .fmt = fmt,
114 };
115 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300116
117 va_start(args, fmt);
118 vaf.va = &args;
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700119 dev_info(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300120 trace_ath10k_log_info(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300121 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300122}
123EXPORT_SYMBOL(ath10k_info);
124
Kalle Valo8a0c7972014-08-25 08:37:45 +0300125void ath10k_print_driver_info(struct ath10k *ar)
126{
Kalle Valoa58227e2014-10-13 09:40:59 +0300127 ath10k_info(ar, "%s (0x%08x, 0x%08x) fw %s api %d htt %d.%d wmi %d.%d.%d.%d cal %s\n",
Kalle Valo8a0c7972014-08-25 08:37:45 +0300128 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,
Michal Kazior34b28b62014-09-23 10:22:52 +0200134 ar->htt.target_version_minor,
135 ar->fw_version_major,
136 ar->fw_version_minor,
137 ar->fw_version_release,
Kalle Valoa58227e2014-10-13 09:40:59 +0300138 ar->fw_version_build,
139 ath10k_cal_mode_str(ar->cal_mode));
Kalle Valo43d2a302014-09-10 18:23:30 +0300140 ath10k_info(ar, "debug %d debugfs %d tracing %d dfs %d testmode %d\n",
Kalle Valo8a0c7972014-08-25 08:37:45 +0300141 config_enabled(CONFIG_ATH10K_DEBUG),
142 config_enabled(CONFIG_ATH10K_DEBUGFS),
143 config_enabled(CONFIG_ATH10K_TRACING),
Kalle Valo43d2a302014-09-10 18:23:30 +0300144 config_enabled(CONFIG_ATH10K_DFS_CERTIFIED),
145 config_enabled(CONFIG_NL80211_TESTMODE));
Kalle Valo8a0c7972014-08-25 08:37:45 +0300146}
147EXPORT_SYMBOL(ath10k_print_driver_info);
148
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700149void ath10k_err(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300150{
151 struct va_format vaf = {
152 .fmt = fmt,
153 };
154 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300155
156 va_start(args, fmt);
157 vaf.va = &args;
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700158 dev_err(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300159 trace_ath10k_log_err(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300160 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300161}
162EXPORT_SYMBOL(ath10k_err);
163
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700164void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300165{
166 struct va_format vaf = {
167 .fmt = fmt,
168 };
169 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300170
171 va_start(args, fmt);
172 vaf.va = &args;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200173 dev_warn_ratelimited(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300174 trace_ath10k_log_warn(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300175
176 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300177}
178EXPORT_SYMBOL(ath10k_warn);
179
180#ifdef CONFIG_ATH10K_DEBUGFS
181
182void ath10k_debug_read_service_map(struct ath10k *ar,
Michal Kazior5c01aa3d2014-09-18 15:21:24 +0200183 const void *service_map,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300184 size_t map_size)
185{
186 memcpy(ar->debug.wmi_service_bitmap, service_map, map_size);
187}
188
189static ssize_t ath10k_read_wmi_services(struct file *file,
190 char __user *user_buf,
191 size_t count, loff_t *ppos)
192{
193 struct ath10k *ar = file->private_data;
194 char *buf;
Michal Kaziorcff990c2014-08-04 09:18:33 +0300195 unsigned int len = 0, buf_len = 4096;
196 const char *name;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300197 ssize_t ret_cnt;
Michal Kaziorcff990c2014-08-04 09:18:33 +0300198 bool enabled;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300199 int i;
200
201 buf = kzalloc(buf_len, GFP_KERNEL);
202 if (!buf)
203 return -ENOMEM;
204
205 mutex_lock(&ar->conf_mutex);
206
207 if (len > buf_len)
208 len = buf_len;
209
Michal Kaziorc4f8c832014-09-04 10:18:32 +0200210 for (i = 0; i < WMI_SERVICE_MAX; i++) {
Michal Kaziorcff990c2014-08-04 09:18:33 +0300211 enabled = test_bit(i, ar->debug.wmi_service_bitmap);
212 name = wmi_service_name(i);
213
214 if (!name) {
215 if (enabled)
216 len += scnprintf(buf + len, buf_len - len,
217 "%-40s %s (bit %d)\n",
218 "unknown", "enabled", i);
219
220 continue;
221 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300222
223 len += scnprintf(buf + len, buf_len - len,
Michal Kaziorcff990c2014-08-04 09:18:33 +0300224 "%-40s %s\n",
225 name, enabled ? "enabled" : "-");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300226 }
227
228 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
229
230 mutex_unlock(&ar->conf_mutex);
231
232 kfree(buf);
233 return ret_cnt;
234}
235
236static const struct file_operations fops_wmi_services = {
237 .read = ath10k_read_wmi_services,
238 .open = simple_open,
239 .owner = THIS_MODULE,
240 .llseek = default_llseek,
241};
242
Michal Kazior53268492014-09-25 12:33:50 +0200243static void ath10k_debug_fw_stats_pdevs_free(struct list_head *head)
244{
245 struct ath10k_fw_stats_pdev *i, *tmp;
246
247 list_for_each_entry_safe(i, tmp, head, list) {
248 list_del(&i->list);
249 kfree(i);
250 }
251}
252
253static void ath10k_debug_fw_stats_peers_free(struct list_head *head)
254{
255 struct ath10k_fw_stats_peer *i, *tmp;
256
257 list_for_each_entry_safe(i, tmp, head, list) {
258 list_del(&i->list);
259 kfree(i);
260 }
261}
262
263static void ath10k_debug_fw_stats_reset(struct ath10k *ar)
264{
265 spin_lock_bh(&ar->data_lock);
266 ar->debug.fw_stats_done = false;
267 ath10k_debug_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
268 ath10k_debug_fw_stats_peers_free(&ar->debug.fw_stats.peers);
269 spin_unlock_bh(&ar->data_lock);
270}
271
272static size_t ath10k_debug_fw_stats_num_peers(struct list_head *head)
273{
274 struct ath10k_fw_stats_peer *i;
275 size_t num = 0;
276
277 list_for_each_entry(i, head, list)
278 ++num;
279
280 return num;
281}
282
Michal Kazior60ef4012014-09-25 12:33:48 +0200283void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300284{
Michal Kazior53268492014-09-25 12:33:50 +0200285 struct ath10k_fw_stats stats = {};
286 bool is_start, is_started, is_end;
287 size_t num_peers;
Michal Kaziord15fb522014-09-25 12:33:47 +0200288 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300289
Michal Kazior53268492014-09-25 12:33:50 +0200290 INIT_LIST_HEAD(&stats.pdevs);
291 INIT_LIST_HEAD(&stats.peers);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300292
Michal Kazior53268492014-09-25 12:33:50 +0200293 spin_lock_bh(&ar->data_lock);
294 ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
Michal Kaziord15fb522014-09-25 12:33:47 +0200295 if (ret) {
296 ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
297 goto unlock;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300298 }
299
Michal Kazior53268492014-09-25 12:33:50 +0200300 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
301 * splits the stats data and delivers it in a ping-pong fashion of
302 * request cmd-update event.
303 *
304 * However there is no explicit end-of-data. Instead start-of-data is
305 * used as an implicit one. This works as follows:
306 * a) discard stat update events until one with pdev stats is
307 * delivered - this skips session started at end of (b)
308 * b) consume stat update events until another one with pdev stats is
309 * delivered which is treated as end-of-data and is itself discarded
310 */
311
312 if (ar->debug.fw_stats_done) {
313 ath10k_warn(ar, "received unsolicited stats update event\n");
314 goto free;
315 }
316
317 num_peers = ath10k_debug_fw_stats_num_peers(&ar->debug.fw_stats.peers);
318 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
319 !list_empty(&stats.pdevs));
320 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
321 !list_empty(&stats.pdevs));
322
323 if (is_start)
324 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
325
326 if (is_end)
327 ar->debug.fw_stats_done = true;
328
329 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
330
331 if (is_started && !is_end) {
332 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
333 /* Although this is unlikely impose a sane limit to
334 * prevent firmware from DoS-ing the host.
335 */
336 ath10k_warn(ar, "dropping fw peer stats\n");
337 goto free;
338 }
339
340 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
341 }
342
Michal Kazior60ef4012014-09-25 12:33:48 +0200343 complete(&ar->debug.fw_stats_complete);
Michal Kaziord15fb522014-09-25 12:33:47 +0200344
Michal Kazior53268492014-09-25 12:33:50 +0200345free:
346 /* In some cases lists have been spliced and cleared. Free up
347 * resources if that is not the case.
348 */
349 ath10k_debug_fw_stats_pdevs_free(&stats.pdevs);
350 ath10k_debug_fw_stats_peers_free(&stats.peers);
351
Michal Kaziord15fb522014-09-25 12:33:47 +0200352unlock:
353 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300354}
355
Michal Kazior53268492014-09-25 12:33:50 +0200356static int ath10k_debug_fw_stats_request(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300357{
Michal Kazior53268492014-09-25 12:33:50 +0200358 unsigned long timeout;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300359 int ret;
360
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200361 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300362
Michal Kazior53268492014-09-25 12:33:50 +0200363 timeout = jiffies + msecs_to_jiffies(1*HZ);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300364
Michal Kazior53268492014-09-25 12:33:50 +0200365 ath10k_debug_fw_stats_reset(ar);
366
367 for (;;) {
368 if (time_after(jiffies, timeout))
369 return -ETIMEDOUT;
370
371 reinit_completion(&ar->debug.fw_stats_complete);
372
373 ret = ath10k_wmi_request_stats(ar, WMI_REQUEST_PEER_STAT);
374 if (ret) {
375 ath10k_warn(ar, "could not request stats (%d)\n", ret);
376 return ret;
377 }
378
379 ret = wait_for_completion_timeout(&ar->debug.fw_stats_complete,
380 1*HZ);
381 if (ret <= 0)
382 return -ETIMEDOUT;
383
384 spin_lock_bh(&ar->data_lock);
385 if (ar->debug.fw_stats_done) {
386 spin_unlock_bh(&ar->data_lock);
387 break;
388 }
389 spin_unlock_bh(&ar->data_lock);
390 }
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200391
392 return 0;
393}
394
395/* FIXME: How to calculate the buffer size sanely? */
396#define ATH10K_FW_STATS_BUF_SIZE (1024*1024)
397
398static void ath10k_fw_stats_fill(struct ath10k *ar,
399 struct ath10k_fw_stats *fw_stats,
400 char *buf)
401{
402 unsigned int len = 0;
403 unsigned int buf_len = ATH10K_FW_STATS_BUF_SIZE;
Michal Kazior53268492014-09-25 12:33:50 +0200404 const struct ath10k_fw_stats_pdev *pdev;
405 const struct ath10k_fw_stats_peer *peer;
406 size_t num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300407
Michal Kazior87571bf2013-07-16 09:38:59 +0200408 spin_lock_bh(&ar->data_lock);
Michal Kazior53268492014-09-25 12:33:50 +0200409
410 pdev = list_first_entry_or_null(&fw_stats->pdevs,
411 struct ath10k_fw_stats_pdev, list);
412 if (!pdev) {
413 ath10k_warn(ar, "failed to get pdev stats\n");
414 goto unlock;
415 }
416
417 num_peers = ath10k_debug_fw_stats_num_peers(&fw_stats->peers);
418
Kalle Valo5e3dd152013-06-12 20:52:10 +0300419 len += scnprintf(buf + len, buf_len - len, "\n");
420 len += scnprintf(buf + len, buf_len - len, "%30s\n",
421 "ath10k PDEV stats");
422 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
423 "=================");
424
425 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200426 "Channel noise floor", pdev->ch_noise_floor);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300427 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200428 "Channel TX power", pdev->chan_tx_power);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300429 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200430 "TX frame count", pdev->tx_frame_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300431 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200432 "RX frame count", pdev->rx_frame_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300433 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200434 "RX clear count", pdev->rx_clear_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300435 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200436 "Cycle count", pdev->cycle_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300437 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200438 "PHY error count", pdev->phy_err_count);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200439 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200440 "RTS bad count", pdev->rts_bad);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200441 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200442 "RTS good count", pdev->rts_good);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200443 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200444 "FCS bad count", pdev->fcs_bad);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200445 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200446 "No beacon count", pdev->no_beacons);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200447 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200448 "MIB int count", pdev->mib_int_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300449
450 len += scnprintf(buf + len, buf_len - len, "\n");
451 len += scnprintf(buf + len, buf_len - len, "%30s\n",
452 "ath10k PDEV TX stats");
453 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
454 "=================");
455
456 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200457 "HTT cookies queued", pdev->comp_queued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300458 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200459 "HTT cookies disp.", pdev->comp_delivered);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300460 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200461 "MSDU queued", pdev->msdu_enqued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300462 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200463 "MPDU queued", pdev->mpdu_enqued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300464 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200465 "MSDUs dropped", pdev->wmm_drop);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300466 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200467 "Local enqued", pdev->local_enqued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300468 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200469 "Local freed", pdev->local_freed);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300470 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200471 "HW queued", pdev->hw_queued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300472 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200473 "PPDUs reaped", pdev->hw_reaped);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300474 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200475 "Num underruns", pdev->underrun);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300476 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200477 "PPDUs cleaned", pdev->tx_abort);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200479 "MPDUs requed", pdev->mpdus_requed);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300480 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200481 "Excessive retries", pdev->tx_ko);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300482 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200483 "HW rate", pdev->data_rc);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300484 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200485 "Sched self tiggers", pdev->self_triggers);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300486 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
487 "Dropped due to SW retries",
Michal Kazior53268492014-09-25 12:33:50 +0200488 pdev->sw_retry_failure);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300489 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
490 "Illegal rate phy errors",
Michal Kazior53268492014-09-25 12:33:50 +0200491 pdev->illgl_rate_phy_err);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300492 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200493 "Pdev continous xretry", pdev->pdev_cont_xretry);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300494 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200495 "TX timeout", pdev->pdev_tx_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300496 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200497 "PDEV resets", pdev->pdev_resets);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300498 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200499 "PHY underrun", pdev->phy_underrun);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300500 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200501 "MPDU is more than txop limit", pdev->txop_ovf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300502
503 len += scnprintf(buf + len, buf_len - len, "\n");
504 len += scnprintf(buf + len, buf_len - len, "%30s\n",
505 "ath10k PDEV RX stats");
506 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
507 "=================");
508
509 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
510 "Mid PPDU route change",
Michal Kazior53268492014-09-25 12:33:50 +0200511 pdev->mid_ppdu_route_change);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300512 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200513 "Tot. number of statuses", pdev->status_rcvd);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300514 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200515 "Extra frags on rings 0", pdev->r0_frags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300516 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200517 "Extra frags on rings 1", pdev->r1_frags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300518 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200519 "Extra frags on rings 2", pdev->r2_frags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300520 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200521 "Extra frags on rings 3", pdev->r3_frags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300522 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200523 "MSDUs delivered to HTT", pdev->htt_msdus);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300524 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200525 "MPDUs delivered to HTT", pdev->htt_mpdus);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300526 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200527 "MSDUs delivered to stack", pdev->loc_msdus);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300528 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200529 "MPDUs delivered to stack", pdev->loc_mpdus);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300530 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200531 "Oversized AMSUs", pdev->oversize_amsdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300532 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200533 "PHY errors", pdev->phy_errs);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300534 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200535 "PHY errors drops", pdev->phy_err_drop);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300536 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200537 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300538
539 len += scnprintf(buf + len, buf_len - len, "\n");
Michal Kazior53268492014-09-25 12:33:50 +0200540 len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
541 "ath10k PEER stats", num_peers);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300542 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
543 "=================");
544
Michal Kazior53268492014-09-25 12:33:50 +0200545 list_for_each_entry(peer, &fw_stats->peers, list) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300546 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
Michal Kazior53268492014-09-25 12:33:50 +0200547 "Peer MAC address", peer->peer_macaddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300548 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200549 "Peer RSSI", peer->peer_rssi);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300550 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200551 "Peer TX rate", peer->peer_tx_rate);
Ben Greear23c3aae2014-03-28 14:35:15 +0200552 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200553 "Peer RX rate", peer->peer_rx_rate);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300554 len += scnprintf(buf + len, buf_len - len, "\n");
555 }
Michal Kazior53268492014-09-25 12:33:50 +0200556
557unlock:
Michal Kazior87571bf2013-07-16 09:38:59 +0200558 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300559
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200560 if (len >= buf_len)
561 buf[len - 1] = 0;
562 else
563 buf[len] = 0;
564}
Kalle Valo5e3dd152013-06-12 20:52:10 +0300565
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200566static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
567{
568 struct ath10k *ar = inode->i_private;
569 void *buf = NULL;
570 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300571
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200572 mutex_lock(&ar->conf_mutex);
573
574 if (ar->state != ATH10K_STATE_ON) {
575 ret = -ENETDOWN;
576 goto err_unlock;
577 }
578
579 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
580 if (!buf) {
581 ret = -ENOMEM;
582 goto err_unlock;
583 }
584
Michal Kazior53268492014-09-25 12:33:50 +0200585 ret = ath10k_debug_fw_stats_request(ar);
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200586 if (ret) {
587 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
588 goto err_free;
589 }
590
591 ath10k_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
592 file->private_data = buf;
593
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594 mutex_unlock(&ar->conf_mutex);
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200595 return 0;
596
597err_free:
598 vfree(buf);
599
600err_unlock:
601 mutex_unlock(&ar->conf_mutex);
602 return ret;
603}
604
605static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
606{
607 vfree(file->private_data);
608
609 return 0;
610}
611
612static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
613 size_t count, loff_t *ppos)
614{
615 const char *buf = file->private_data;
616 unsigned int len = strlen(buf);
617
618 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300619}
620
621static const struct file_operations fops_fw_stats = {
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200622 .open = ath10k_fw_stats_open,
623 .release = ath10k_fw_stats_release,
Michal Kazior60ef4012014-09-25 12:33:48 +0200624 .read = ath10k_fw_stats_read,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300625 .owner = THIS_MODULE,
626 .llseek = default_llseek,
627};
628
Ben Greearf51dbe72014-09-29 14:41:46 +0300629static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
630 char __user *user_buf,
631 size_t count, loff_t *ppos)
632{
633 struct ath10k *ar = file->private_data;
634 int ret, len, buf_len;
635 char *buf;
636
637 buf_len = 500;
638 buf = kmalloc(buf_len, GFP_KERNEL);
639 if (!buf)
640 return -ENOMEM;
641
642 spin_lock_bh(&ar->data_lock);
643
644 len = 0;
645 len += scnprintf(buf + len, buf_len - len,
646 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
647 len += scnprintf(buf + len, buf_len - len,
648 "fw_warm_reset_counter\t\t%d\n",
649 ar->stats.fw_warm_reset_counter);
650 len += scnprintf(buf + len, buf_len - len,
651 "fw_cold_reset_counter\t\t%d\n",
652 ar->stats.fw_cold_reset_counter);
653
654 spin_unlock_bh(&ar->data_lock);
655
656 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
657
658 kfree(buf);
659
660 return ret;
661}
662
663static const struct file_operations fops_fw_reset_stats = {
664 .open = simple_open,
665 .read = ath10k_debug_fw_reset_stats_read,
666 .owner = THIS_MODULE,
667 .llseek = default_llseek,
668};
669
Ben Greeard5aebc72014-09-10 18:59:28 +0300670/* This is a clean assert crash in firmware. */
671static int ath10k_debug_fw_assert(struct ath10k *ar)
672{
673 struct wmi_vdev_install_key_cmd *cmd;
674 struct sk_buff *skb;
675
676 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
677 if (!skb)
678 return -ENOMEM;
679
680 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
681 memset(cmd, 0, sizeof(*cmd));
682
683 /* big enough number so that firmware asserts */
684 cmd->vdev_id = __cpu_to_le32(0x7ffe);
685
686 return ath10k_wmi_cmd_send(ar, skb,
687 ar->wmi.cmd->vdev_install_key_cmdid);
688}
689
Michal Kazior278c4a82013-07-22 14:08:51 +0200690static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
691 char __user *user_buf,
692 size_t count, loff_t *ppos)
693{
Kalle Valo75cb96d2014-09-14 12:50:44 +0300694 const char buf[] =
695 "To simulate firmware crash write one of the keywords to this file:\n"
696 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
697 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
Michal Kazior605cdba2014-10-28 10:34:37 +0100698 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
699 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
Marek Puzyniak8c656992014-03-21 17:46:56 +0200700
Michal Kazior278c4a82013-07-22 14:08:51 +0200701 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
702}
703
Marek Puzyniak8c656992014-03-21 17:46:56 +0200704/* Simulate firmware crash:
705 * 'soft': Call wmi command causing firmware hang. This firmware hang is
706 * recoverable by warm firmware reset.
707 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
708 * vdev id. This is hard firmware crash because it is recoverable only by cold
709 * firmware reset.
710 */
Michal Kazior278c4a82013-07-22 14:08:51 +0200711static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
712 const char __user *user_buf,
713 size_t count, loff_t *ppos)
714{
715 struct ath10k *ar = file->private_data;
Marek Puzyniak8c656992014-03-21 17:46:56 +0200716 char buf[32];
Michal Kazior278c4a82013-07-22 14:08:51 +0200717 int ret;
718
719 mutex_lock(&ar->conf_mutex);
720
721 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
Marek Puzyniak8c656992014-03-21 17:46:56 +0200722
723 /* make sure that buf is null terminated */
724 buf[sizeof(buf) - 1] = 0;
Michal Kazior278c4a82013-07-22 14:08:51 +0200725
726 if (ar->state != ATH10K_STATE_ON &&
727 ar->state != ATH10K_STATE_RESTARTED) {
728 ret = -ENETDOWN;
729 goto exit;
730 }
731
Marek Puzyniak8c656992014-03-21 17:46:56 +0200732 /* drop the possible '\n' from the end */
733 if (buf[count - 1] == '\n') {
734 buf[count - 1] = 0;
735 count--;
736 }
Michal Kazior278c4a82013-07-22 14:08:51 +0200737
Marek Puzyniak8c656992014-03-21 17:46:56 +0200738 if (!strcmp(buf, "soft")) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200739 ath10k_info(ar, "simulating soft firmware crash\n");
Marek Puzyniak8c656992014-03-21 17:46:56 +0200740 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
741 } else if (!strcmp(buf, "hard")) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200742 ath10k_info(ar, "simulating hard firmware crash\n");
Ben Greear611b3682014-07-25 11:56:40 +0300743 /* 0x7fff is vdev id, and it is always out of range for all
744 * firmware variants in order to force a firmware crash.
745 */
746 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
Kalle Valo5b07e072014-09-14 12:50:06 +0300747 ar->wmi.vdev_param->rts_threshold,
748 0);
Ben Greeard5aebc72014-09-10 18:59:28 +0300749 } else if (!strcmp(buf, "assert")) {
750 ath10k_info(ar, "simulating firmware assert crash\n");
751 ret = ath10k_debug_fw_assert(ar);
Michal Kazior605cdba2014-10-28 10:34:37 +0100752 } else if (!strcmp(buf, "hw-restart")) {
753 ath10k_info(ar, "user requested hw restart\n");
754 queue_work(ar->workqueue, &ar->restart_work);
755 ret = 0;
Marek Puzyniak8c656992014-03-21 17:46:56 +0200756 } else {
757 ret = -EINVAL;
758 goto exit;
759 }
Michal Kazior278c4a82013-07-22 14:08:51 +0200760
Marek Puzyniak8c656992014-03-21 17:46:56 +0200761 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200762 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
Marek Puzyniak8c656992014-03-21 17:46:56 +0200763 goto exit;
764 }
765
766 ret = count;
Michal Kazior278c4a82013-07-22 14:08:51 +0200767
768exit:
769 mutex_unlock(&ar->conf_mutex);
770 return ret;
771}
772
773static const struct file_operations fops_simulate_fw_crash = {
774 .read = ath10k_read_simulate_fw_crash,
775 .write = ath10k_write_simulate_fw_crash,
776 .open = simple_open,
777 .owner = THIS_MODULE,
778 .llseek = default_llseek,
779};
780
Kalle Valo763b8cd2013-09-01 11:22:21 +0300781static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
782 size_t count, loff_t *ppos)
783{
784 struct ath10k *ar = file->private_data;
785 unsigned int len;
786 char buf[50];
787
788 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
789
790 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
791}
792
793static const struct file_operations fops_chip_id = {
794 .read = ath10k_read_chip_id,
795 .open = simple_open,
796 .owner = THIS_MODULE,
797 .llseek = default_llseek,
798};
799
Ben Greear384914b2014-08-25 08:37:32 +0300800struct ath10k_fw_crash_data *
801ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
802{
803 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
804
805 lockdep_assert_held(&ar->data_lock);
806
807 crash_data->crashed_since_read = true;
808 uuid_le_gen(&crash_data->uuid);
809 getnstimeofday(&crash_data->timestamp);
810
811 return crash_data;
812}
813EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
814
815static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
816{
817 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
818 struct ath10k_dump_file_data *dump_data;
819 struct ath10k_tlv_dump_data *dump_tlv;
820 int hdr_len = sizeof(*dump_data);
821 unsigned int len, sofar = 0;
822 unsigned char *buf;
823
824 len = hdr_len;
825 len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
826
827 sofar += hdr_len;
828
829 /* This is going to get big when we start dumping FW RAM and such,
830 * so go ahead and use vmalloc.
831 */
832 buf = vzalloc(len);
833 if (!buf)
834 return NULL;
835
836 spin_lock_bh(&ar->data_lock);
837
838 if (!crash_data->crashed_since_read) {
839 spin_unlock_bh(&ar->data_lock);
840 vfree(buf);
841 return NULL;
842 }
843
844 dump_data = (struct ath10k_dump_file_data *)(buf);
845 strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
846 sizeof(dump_data->df_magic));
847 dump_data->len = cpu_to_le32(len);
848
849 dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
850
851 memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid));
852 dump_data->chip_id = cpu_to_le32(ar->chip_id);
853 dump_data->bus_type = cpu_to_le32(0);
854 dump_data->target_version = cpu_to_le32(ar->target_version);
855 dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
856 dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
857 dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
858 dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
859 dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
860 dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
861 dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
862 dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
863 dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
864 dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
865
866 strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
867 sizeof(dump_data->fw_ver));
868
869 dump_data->kernel_ver_code = cpu_to_le32(LINUX_VERSION_CODE);
870 strlcpy(dump_data->kernel_ver, VERMAGIC_STRING,
871 sizeof(dump_data->kernel_ver));
872
873 dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
874 dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
875
876 /* Gather crash-dump */
877 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
878 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
879 dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
880 memcpy(dump_tlv->tlv_data, &crash_data->registers,
881 sizeof(crash_data->registers));
882 sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
883
884 ar->debug.fw_crash_data->crashed_since_read = false;
885
886 spin_unlock_bh(&ar->data_lock);
887
888 return dump_data;
889}
890
891static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
892{
893 struct ath10k *ar = inode->i_private;
894 struct ath10k_dump_file_data *dump;
895
896 dump = ath10k_build_dump_file(ar);
897 if (!dump)
898 return -ENODATA;
899
900 file->private_data = dump;
901
902 return 0;
903}
904
905static ssize_t ath10k_fw_crash_dump_read(struct file *file,
906 char __user *user_buf,
907 size_t count, loff_t *ppos)
908{
909 struct ath10k_dump_file_data *dump_file = file->private_data;
910
911 return simple_read_from_buffer(user_buf, count, ppos,
912 dump_file,
913 le32_to_cpu(dump_file->len));
914}
915
916static int ath10k_fw_crash_dump_release(struct inode *inode,
917 struct file *file)
918{
919 vfree(file->private_data);
920
921 return 0;
922}
923
924static const struct file_operations fops_fw_crash_dump = {
925 .open = ath10k_fw_crash_dump_open,
926 .read = ath10k_fw_crash_dump_read,
927 .release = ath10k_fw_crash_dump_release,
928 .owner = THIS_MODULE,
929 .llseek = default_llseek,
930};
931
Kalle Valoa3d135e2013-09-03 11:44:10 +0300932static int ath10k_debug_htt_stats_req(struct ath10k *ar)
933{
934 u64 cookie;
935 int ret;
936
937 lockdep_assert_held(&ar->conf_mutex);
938
939 if (ar->debug.htt_stats_mask == 0)
940 /* htt stats are disabled */
941 return 0;
942
943 if (ar->state != ATH10K_STATE_ON)
944 return 0;
945
946 cookie = get_jiffies_64();
947
948 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
949 cookie);
950 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200951 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
Kalle Valoa3d135e2013-09-03 11:44:10 +0300952 return ret;
953 }
954
955 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
956 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
957
958 return 0;
959}
960
961static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
962{
963 struct ath10k *ar = container_of(work, struct ath10k,
964 debug.htt_stats_dwork.work);
965
966 mutex_lock(&ar->conf_mutex);
967
968 ath10k_debug_htt_stats_req(ar);
969
970 mutex_unlock(&ar->conf_mutex);
971}
972
973static ssize_t ath10k_read_htt_stats_mask(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +0300974 char __user *user_buf,
975 size_t count, loff_t *ppos)
Kalle Valoa3d135e2013-09-03 11:44:10 +0300976{
977 struct ath10k *ar = file->private_data;
978 char buf[32];
979 unsigned int len;
980
981 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
982
983 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
984}
985
986static ssize_t ath10k_write_htt_stats_mask(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +0300987 const char __user *user_buf,
988 size_t count, loff_t *ppos)
Kalle Valoa3d135e2013-09-03 11:44:10 +0300989{
990 struct ath10k *ar = file->private_data;
991 unsigned long mask;
992 int ret;
993
994 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
995 if (ret)
996 return ret;
997
998 /* max 8 bit masks (for now) */
999 if (mask > 0xff)
1000 return -E2BIG;
1001
1002 mutex_lock(&ar->conf_mutex);
1003
1004 ar->debug.htt_stats_mask = mask;
1005
1006 ret = ath10k_debug_htt_stats_req(ar);
1007 if (ret)
1008 goto out;
1009
1010 ret = count;
1011
1012out:
1013 mutex_unlock(&ar->conf_mutex);
1014
1015 return ret;
1016}
1017
1018static const struct file_operations fops_htt_stats_mask = {
1019 .read = ath10k_read_htt_stats_mask,
1020 .write = ath10k_write_htt_stats_mask,
1021 .open = simple_open,
1022 .owner = THIS_MODULE,
1023 .llseek = default_llseek,
1024};
1025
Janusz Dziedzicd3856232014-06-02 21:19:46 +03001026static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
1027 char __user *user_buf,
1028 size_t count, loff_t *ppos)
1029{
1030 struct ath10k *ar = file->private_data;
1031 char buf[64];
1032 u8 amsdu = 3, ampdu = 64;
1033 unsigned int len;
1034
1035 mutex_lock(&ar->conf_mutex);
1036
1037 if (ar->debug.htt_max_amsdu)
1038 amsdu = ar->debug.htt_max_amsdu;
1039
1040 if (ar->debug.htt_max_ampdu)
1041 ampdu = ar->debug.htt_max_ampdu;
1042
1043 mutex_unlock(&ar->conf_mutex);
1044
1045 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
1046
1047 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1048}
1049
1050static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
1051 const char __user *user_buf,
1052 size_t count, loff_t *ppos)
1053{
1054 struct ath10k *ar = file->private_data;
1055 int res;
1056 char buf[64];
1057 unsigned int amsdu, ampdu;
1058
1059 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1060
1061 /* make sure that buf is null terminated */
1062 buf[sizeof(buf) - 1] = 0;
1063
1064 res = sscanf(buf, "%u %u", &amsdu, &ampdu);
1065
1066 if (res != 2)
1067 return -EINVAL;
1068
1069 mutex_lock(&ar->conf_mutex);
1070
1071 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1072 if (res)
1073 goto out;
1074
1075 res = count;
1076 ar->debug.htt_max_amsdu = amsdu;
1077 ar->debug.htt_max_ampdu = ampdu;
1078
1079out:
1080 mutex_unlock(&ar->conf_mutex);
1081 return res;
1082}
1083
1084static const struct file_operations fops_htt_max_amsdu_ampdu = {
1085 .read = ath10k_read_htt_max_amsdu_ampdu,
1086 .write = ath10k_write_htt_max_amsdu_ampdu,
1087 .open = simple_open,
1088 .owner = THIS_MODULE,
1089 .llseek = default_llseek,
1090};
1091
Kalle Valof118a3e2014-01-03 12:59:31 +02001092static ssize_t ath10k_read_fw_dbglog(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +03001093 char __user *user_buf,
1094 size_t count, loff_t *ppos)
Kalle Valof118a3e2014-01-03 12:59:31 +02001095{
1096 struct ath10k *ar = file->private_data;
1097 unsigned int len;
1098 char buf[32];
1099
1100 len = scnprintf(buf, sizeof(buf), "0x%08x\n",
1101 ar->debug.fw_dbglog_mask);
1102
1103 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1104}
1105
1106static ssize_t ath10k_write_fw_dbglog(struct file *file,
1107 const char __user *user_buf,
1108 size_t count, loff_t *ppos)
1109{
1110 struct ath10k *ar = file->private_data;
1111 unsigned long mask;
1112 int ret;
1113
1114 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1115 if (ret)
1116 return ret;
1117
1118 mutex_lock(&ar->conf_mutex);
1119
1120 ar->debug.fw_dbglog_mask = mask;
1121
1122 if (ar->state == ATH10K_STATE_ON) {
1123 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask);
1124 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001125 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
Kalle Valof118a3e2014-01-03 12:59:31 +02001126 ret);
1127 goto exit;
1128 }
1129 }
1130
1131 ret = count;
1132
1133exit:
1134 mutex_unlock(&ar->conf_mutex);
1135
1136 return ret;
1137}
1138
Ben Greear6cddcc72014-09-29 14:41:46 +03001139/* TODO: Would be nice to always support ethtool stats, would need to
1140 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1141 * struct available..
1142 */
1143
1144/* This generally cooresponds to the debugfs fw_stats file */
1145static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1146 "tx_pkts_nic",
1147 "tx_bytes_nic",
1148 "rx_pkts_nic",
1149 "rx_bytes_nic",
1150 "d_noise_floor",
1151 "d_cycle_count",
1152 "d_phy_error",
1153 "d_rts_bad",
1154 "d_rts_good",
1155 "d_tx_power", /* in .5 dbM I think */
1156 "d_rx_crc_err", /* fcs_bad */
1157 "d_no_beacon",
1158 "d_tx_mpdus_queued",
1159 "d_tx_msdu_queued",
1160 "d_tx_msdu_dropped",
1161 "d_local_enqued",
1162 "d_local_freed",
1163 "d_tx_ppdu_hw_queued",
1164 "d_tx_ppdu_reaped",
1165 "d_tx_fifo_underrun",
1166 "d_tx_ppdu_abort",
1167 "d_tx_mpdu_requed",
1168 "d_tx_excessive_retries",
1169 "d_tx_hw_rate",
1170 "d_tx_dropped_sw_retries",
1171 "d_tx_illegal_rate",
1172 "d_tx_continuous_xretries",
1173 "d_tx_timeout",
1174 "d_tx_mpdu_txop_limit",
1175 "d_pdev_resets",
1176 "d_rx_mid_ppdu_route_change",
1177 "d_rx_status",
1178 "d_rx_extra_frags_ring0",
1179 "d_rx_extra_frags_ring1",
1180 "d_rx_extra_frags_ring2",
1181 "d_rx_extra_frags_ring3",
1182 "d_rx_msdu_htt",
1183 "d_rx_mpdu_htt",
1184 "d_rx_msdu_stack",
1185 "d_rx_mpdu_stack",
1186 "d_rx_phy_err",
1187 "d_rx_phy_err_drops",
1188 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1189 "d_fw_crash_count",
1190 "d_fw_warm_reset_count",
1191 "d_fw_cold_reset_count",
1192};
1193
1194#define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1195
1196void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1197 struct ieee80211_vif *vif,
1198 u32 sset, u8 *data)
1199{
1200 if (sset == ETH_SS_STATS)
1201 memcpy(data, *ath10k_gstrings_stats,
1202 sizeof(ath10k_gstrings_stats));
1203}
1204
1205int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1206 struct ieee80211_vif *vif, int sset)
1207{
1208 if (sset == ETH_SS_STATS)
1209 return ATH10K_SSTATS_LEN;
1210
1211 return 0;
1212}
1213
1214void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1215 struct ieee80211_vif *vif,
1216 struct ethtool_stats *stats, u64 *data)
1217{
1218 struct ath10k *ar = hw->priv;
1219 static const struct ath10k_fw_stats_pdev zero_stats = {};
1220 const struct ath10k_fw_stats_pdev *pdev_stats;
1221 int i = 0, ret;
1222
1223 mutex_lock(&ar->conf_mutex);
1224
1225 if (ar->state == ATH10K_STATE_ON) {
1226 ret = ath10k_debug_fw_stats_request(ar);
1227 if (ret) {
1228 /* just print a warning and try to use older results */
1229 ath10k_warn(ar,
1230 "failed to get fw stats for ethtool: %d\n",
1231 ret);
1232 }
1233 }
1234
1235 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1236 struct ath10k_fw_stats_pdev,
1237 list);
1238 if (!pdev_stats) {
1239 /* no results available so just return zeroes */
1240 pdev_stats = &zero_stats;
1241 }
1242
1243 spin_lock_bh(&ar->data_lock);
1244
1245 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1246 data[i++] = 0; /* tx bytes */
1247 data[i++] = pdev_stats->htt_mpdus;
1248 data[i++] = 0; /* rx bytes */
1249 data[i++] = pdev_stats->ch_noise_floor;
1250 data[i++] = pdev_stats->cycle_count;
1251 data[i++] = pdev_stats->phy_err_count;
1252 data[i++] = pdev_stats->rts_bad;
1253 data[i++] = pdev_stats->rts_good;
1254 data[i++] = pdev_stats->chan_tx_power;
1255 data[i++] = pdev_stats->fcs_bad;
1256 data[i++] = pdev_stats->no_beacons;
1257 data[i++] = pdev_stats->mpdu_enqued;
1258 data[i++] = pdev_stats->msdu_enqued;
1259 data[i++] = pdev_stats->wmm_drop;
1260 data[i++] = pdev_stats->local_enqued;
1261 data[i++] = pdev_stats->local_freed;
1262 data[i++] = pdev_stats->hw_queued;
1263 data[i++] = pdev_stats->hw_reaped;
1264 data[i++] = pdev_stats->underrun;
1265 data[i++] = pdev_stats->tx_abort;
1266 data[i++] = pdev_stats->mpdus_requed;
1267 data[i++] = pdev_stats->tx_ko;
1268 data[i++] = pdev_stats->data_rc;
1269 data[i++] = pdev_stats->sw_retry_failure;
1270 data[i++] = pdev_stats->illgl_rate_phy_err;
1271 data[i++] = pdev_stats->pdev_cont_xretry;
1272 data[i++] = pdev_stats->pdev_tx_timeout;
1273 data[i++] = pdev_stats->txop_ovf;
1274 data[i++] = pdev_stats->pdev_resets;
1275 data[i++] = pdev_stats->mid_ppdu_route_change;
1276 data[i++] = pdev_stats->status_rcvd;
1277 data[i++] = pdev_stats->r0_frags;
1278 data[i++] = pdev_stats->r1_frags;
1279 data[i++] = pdev_stats->r2_frags;
1280 data[i++] = pdev_stats->r3_frags;
1281 data[i++] = pdev_stats->htt_msdus;
1282 data[i++] = pdev_stats->htt_mpdus;
1283 data[i++] = pdev_stats->loc_msdus;
1284 data[i++] = pdev_stats->loc_mpdus;
1285 data[i++] = pdev_stats->phy_errs;
1286 data[i++] = pdev_stats->phy_err_drop;
1287 data[i++] = pdev_stats->mpdu_errs;
1288 data[i++] = ar->stats.fw_crash_counter;
1289 data[i++] = ar->stats.fw_warm_reset_counter;
1290 data[i++] = ar->stats.fw_cold_reset_counter;
1291
1292 spin_unlock_bh(&ar->data_lock);
1293
1294 mutex_unlock(&ar->conf_mutex);
1295
1296 WARN_ON(i != ATH10K_SSTATS_LEN);
1297}
1298
Kalle Valof118a3e2014-01-03 12:59:31 +02001299static const struct file_operations fops_fw_dbglog = {
1300 .read = ath10k_read_fw_dbglog,
1301 .write = ath10k_write_fw_dbglog,
1302 .open = simple_open,
1303 .owner = THIS_MODULE,
1304 .llseek = default_llseek,
1305};
1306
Kalle Valo7869b4f2014-09-24 14:16:58 +03001307static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1308{
1309 struct ath10k *ar = inode->i_private;
1310 void *buf;
1311 u32 hi_addr;
1312 __le32 addr;
1313 int ret;
1314
1315 mutex_lock(&ar->conf_mutex);
1316
1317 if (ar->state != ATH10K_STATE_ON &&
1318 ar->state != ATH10K_STATE_UTF) {
1319 ret = -ENETDOWN;
1320 goto err;
1321 }
1322
1323 buf = vmalloc(QCA988X_CAL_DATA_LEN);
1324 if (!buf) {
1325 ret = -ENOMEM;
1326 goto err;
1327 }
1328
1329 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1330
1331 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1332 if (ret) {
1333 ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret);
1334 goto err_vfree;
1335 }
1336
1337 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf,
1338 QCA988X_CAL_DATA_LEN);
1339 if (ret) {
1340 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1341 goto err_vfree;
1342 }
1343
1344 file->private_data = buf;
1345
1346 mutex_unlock(&ar->conf_mutex);
1347
1348 return 0;
1349
1350err_vfree:
1351 vfree(buf);
1352
1353err:
1354 mutex_unlock(&ar->conf_mutex);
1355
1356 return ret;
1357}
1358
1359static ssize_t ath10k_debug_cal_data_read(struct file *file,
1360 char __user *user_buf,
1361 size_t count, loff_t *ppos)
1362{
1363 void *buf = file->private_data;
1364
1365 return simple_read_from_buffer(user_buf, count, ppos,
1366 buf, QCA988X_CAL_DATA_LEN);
1367}
1368
1369static int ath10k_debug_cal_data_release(struct inode *inode,
1370 struct file *file)
1371{
1372 vfree(file->private_data);
1373
1374 return 0;
1375}
1376
1377static const struct file_operations fops_cal_data = {
1378 .open = ath10k_debug_cal_data_open,
1379 .read = ath10k_debug_cal_data_read,
1380 .release = ath10k_debug_cal_data_release,
1381 .owner = THIS_MODULE,
1382 .llseek = default_llseek,
1383};
1384
Kalle Valodb66ea02013-09-03 11:44:03 +03001385int ath10k_debug_start(struct ath10k *ar)
1386{
Kalle Valoa3d135e2013-09-03 11:44:10 +03001387 int ret;
1388
Kalle Valo60631c52013-10-08 21:45:25 +03001389 lockdep_assert_held(&ar->conf_mutex);
1390
Kalle Valoa3d135e2013-09-03 11:44:10 +03001391 ret = ath10k_debug_htt_stats_req(ar);
1392 if (ret)
1393 /* continue normally anyway, this isn't serious */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001394 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1395 ret);
Kalle Valoa3d135e2013-09-03 11:44:10 +03001396
Kalle Valof118a3e2014-01-03 12:59:31 +02001397 if (ar->debug.fw_dbglog_mask) {
1398 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask);
1399 if (ret)
1400 /* not serious */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001401 ath10k_warn(ar, "failed to enable dbglog during start: %d",
Kalle Valof118a3e2014-01-03 12:59:31 +02001402 ret);
1403 }
1404
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001405 if (ar->debug.pktlog_filter) {
1406 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1407 ar->debug.pktlog_filter);
1408 if (ret)
1409 /* not serious */
1410 ath10k_warn(ar,
1411 "failed to enable pktlog filter %x: %d\n",
1412 ar->debug.pktlog_filter, ret);
1413 } else {
1414 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1415 if (ret)
1416 /* not serious */
1417 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1418 }
1419
1420 return ret;
Kalle Valodb66ea02013-09-03 11:44:03 +03001421}
1422
1423void ath10k_debug_stop(struct ath10k *ar)
1424{
Kalle Valo60631c52013-10-08 21:45:25 +03001425 lockdep_assert_held(&ar->conf_mutex);
1426
1427 /* Must not use _sync to avoid deadlock, we do that in
1428 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1429 * warning from del_timer(). */
1430 if (ar->debug.htt_stats_mask != 0)
1431 cancel_delayed_work(&ar->debug.htt_stats_dwork);
Janusz Dziedzicd3856232014-06-02 21:19:46 +03001432
1433 ar->debug.htt_max_amsdu = 0;
1434 ar->debug.htt_max_ampdu = 0;
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001435
1436 ath10k_wmi_pdev_pktlog_disable(ar);
Kalle Valodb66ea02013-09-03 11:44:03 +03001437}
1438
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001439static ssize_t ath10k_write_simulate_radar(struct file *file,
1440 const char __user *user_buf,
1441 size_t count, loff_t *ppos)
1442{
1443 struct ath10k *ar = file->private_data;
1444
1445 ieee80211_radar_detected(ar->hw);
1446
1447 return count;
1448}
1449
1450static const struct file_operations fops_simulate_radar = {
1451 .write = ath10k_write_simulate_radar,
1452 .open = simple_open,
1453 .owner = THIS_MODULE,
1454 .llseek = default_llseek,
1455};
1456
1457#define ATH10K_DFS_STAT(s, p) (\
1458 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1459 ar->debug.dfs_stats.p))
1460
1461#define ATH10K_DFS_POOL_STAT(s, p) (\
1462 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1463 ar->debug.dfs_pool_stats.p))
1464
1465static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
1466 size_t count, loff_t *ppos)
1467{
1468 int retval = 0, len = 0;
1469 const int size = 8000;
1470 struct ath10k *ar = file->private_data;
1471 char *buf;
1472
1473 buf = kzalloc(size, GFP_KERNEL);
1474 if (buf == NULL)
1475 return -ENOMEM;
1476
1477 if (!ar->dfs_detector) {
1478 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
1479 goto exit;
1480 }
1481
1482 ar->debug.dfs_pool_stats =
1483 ar->dfs_detector->get_stats(ar->dfs_detector);
1484
1485 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
1486
1487 ATH10K_DFS_STAT("reported phy errors", phy_errors);
1488 ATH10K_DFS_STAT("pulse events reported", pulses_total);
1489 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
1490 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
1491 ATH10K_DFS_STAT("Radars detected", radar_detected);
1492
1493 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
1494 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
1495 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
1496 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
1497 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
1498 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
1499 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
1500 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
1501
1502exit:
1503 if (len > size)
1504 len = size;
1505
1506 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1507 kfree(buf);
1508
1509 return retval;
1510}
1511
1512static const struct file_operations fops_dfs_stats = {
1513 .read = ath10k_read_dfs_stats,
1514 .open = simple_open,
1515 .owner = THIS_MODULE,
1516 .llseek = default_llseek,
1517};
1518
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001519static ssize_t ath10k_write_pktlog_filter(struct file *file,
1520 const char __user *ubuf,
1521 size_t count, loff_t *ppos)
1522{
1523 struct ath10k *ar = file->private_data;
1524 u32 filter;
1525 int ret;
1526
1527 if (kstrtouint_from_user(ubuf, count, 0, &filter))
1528 return -EINVAL;
1529
1530 mutex_lock(&ar->conf_mutex);
1531
1532 if (ar->state != ATH10K_STATE_ON) {
1533 ar->debug.pktlog_filter = filter;
1534 ret = count;
1535 goto out;
1536 }
1537
1538 if (filter && (filter != ar->debug.pktlog_filter)) {
1539 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
1540 if (ret) {
1541 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
1542 ar->debug.pktlog_filter, ret);
1543 goto out;
1544 }
1545 } else {
1546 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1547 if (ret) {
1548 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1549 goto out;
1550 }
1551 }
1552
1553 ar->debug.pktlog_filter = filter;
1554 ret = count;
1555
1556out:
1557 mutex_unlock(&ar->conf_mutex);
1558 return ret;
1559}
1560
1561static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
1562 size_t count, loff_t *ppos)
1563{
1564 char buf[32];
1565 struct ath10k *ar = file->private_data;
1566 int len = 0;
1567
1568 mutex_lock(&ar->conf_mutex);
1569 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
1570 ar->debug.pktlog_filter);
1571 mutex_unlock(&ar->conf_mutex);
1572
1573 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
1574}
1575
1576static const struct file_operations fops_pktlog_filter = {
1577 .read = ath10k_read_pktlog_filter,
1578 .write = ath10k_write_pktlog_filter,
1579 .open = simple_open
1580};
1581
Kalle Valo5e3dd152013-06-12 20:52:10 +03001582int ath10k_debug_create(struct ath10k *ar)
1583{
Ben Greear384914b2014-08-25 08:37:32 +03001584 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
Michal Kaziore13cf7a2014-09-04 09:13:08 +02001585 if (!ar->debug.fw_crash_data)
1586 return -ENOMEM;
Ben Greear384914b2014-08-25 08:37:32 +03001587
Michal Kazior53268492014-09-25 12:33:50 +02001588 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
1589 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
1590
Michal Kaziore13cf7a2014-09-04 09:13:08 +02001591 return 0;
1592}
1593
1594void ath10k_debug_destroy(struct ath10k *ar)
1595{
1596 vfree(ar->debug.fw_crash_data);
1597 ar->debug.fw_crash_data = NULL;
Michal Kazior53268492014-09-25 12:33:50 +02001598
1599 ath10k_debug_fw_stats_reset(ar);
Michal Kaziore13cf7a2014-09-04 09:13:08 +02001600}
1601
1602int ath10k_debug_register(struct ath10k *ar)
1603{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001604 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
1605 ar->hw->wiphy->debugfsdir);
Michal Kazioradb43b22014-09-04 12:36:45 +02001606 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
1607 if (IS_ERR(ar->debug.debugfs_phy))
1608 return PTR_ERR(ar->debug.debugfs_phy);
Kalle Valod8bb26b2014-09-14 12:50:33 +03001609
1610 return -ENOMEM;
Michal Kazioradb43b22014-09-04 12:36:45 +02001611 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001612
Kalle Valoa3d135e2013-09-03 11:44:10 +03001613 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
1614 ath10k_debug_htt_stats_dwork);
1615
Michal Kazior60ef4012014-09-25 12:33:48 +02001616 init_completion(&ar->debug.fw_stats_complete);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001617
1618 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
1619 &fops_fw_stats);
1620
Ben Greearf51dbe72014-09-29 14:41:46 +03001621 debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
1622 ar, &fops_fw_reset_stats);
1623
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
1625 &fops_wmi_services);
1626
Michal Kazior278c4a82013-07-22 14:08:51 +02001627 debugfs_create_file("simulate_fw_crash", S_IRUSR, ar->debug.debugfs_phy,
1628 ar, &fops_simulate_fw_crash);
1629
Ben Greear384914b2014-08-25 08:37:32 +03001630 debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy,
1631 ar, &fops_fw_crash_dump);
1632
Kalle Valo763b8cd2013-09-01 11:22:21 +03001633 debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
1634 ar, &fops_chip_id);
1635
Kalle Valoa3d135e2013-09-03 11:44:10 +03001636 debugfs_create_file("htt_stats_mask", S_IRUSR, ar->debug.debugfs_phy,
1637 ar, &fops_htt_stats_mask);
1638
Janusz Dziedzicd3856232014-06-02 21:19:46 +03001639 debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR,
1640 ar->debug.debugfs_phy, ar,
1641 &fops_htt_max_amsdu_ampdu);
1642
Kalle Valof118a3e2014-01-03 12:59:31 +02001643 debugfs_create_file("fw_dbglog", S_IRUSR, ar->debug.debugfs_phy,
1644 ar, &fops_fw_dbglog);
1645
Kalle Valo7869b4f2014-09-24 14:16:58 +03001646 debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
1647 ar, &fops_cal_data);
1648
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001649 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
1650 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
1651 ar->debug.debugfs_phy, ar,
1652 &fops_simulate_radar);
1653
Marek Puzyniak7d9b40b2013-11-20 10:00:28 +02001654 debugfs_create_bool("dfs_block_radar_events", S_IWUSR,
1655 ar->debug.debugfs_phy,
1656 &ar->dfs_block_radar_events);
1657
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001658 debugfs_create_file("dfs_stats", S_IRUSR,
1659 ar->debug.debugfs_phy, ar,
1660 &fops_dfs_stats);
1661 }
1662
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001663 debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
1664 ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
1665
Kalle Valo5e3dd152013-06-12 20:52:10 +03001666 return 0;
1667}
Kalle Valodb66ea02013-09-03 11:44:03 +03001668
Michal Kaziore13cf7a2014-09-04 09:13:08 +02001669void ath10k_debug_unregister(struct ath10k *ar)
Kalle Valo60631c52013-10-08 21:45:25 +03001670{
1671 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
1672}
1673
Kalle Valo5e3dd152013-06-12 20:52:10 +03001674#endif /* CONFIG_ATH10K_DEBUGFS */
1675
1676#ifdef CONFIG_ATH10K_DEBUG
Michal Kazior7aa7a722014-08-25 12:09:38 +02001677void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
1678 const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001679{
1680 struct va_format vaf;
1681 va_list args;
1682
1683 va_start(args, fmt);
1684
1685 vaf.fmt = fmt;
1686 vaf.va = &args;
1687
1688 if (ath10k_debug_mask & mask)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001689 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690
Michal Kaziord35a6c12014-09-02 11:00:21 +03001691 trace_ath10k_log_dbg(ar, mask, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001692
1693 va_end(args);
1694}
1695EXPORT_SYMBOL(ath10k_dbg);
1696
Michal Kazior7aa7a722014-08-25 12:09:38 +02001697void ath10k_dbg_dump(struct ath10k *ar,
1698 enum ath10k_debug_mask mask,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001699 const char *msg, const char *prefix,
1700 const void *buf, size_t len)
1701{
Michal Kazior45724a82014-09-23 10:22:53 +02001702 char linebuf[256];
1703 unsigned int linebuflen;
1704 const void *ptr;
1705
Kalle Valo5e3dd152013-06-12 20:52:10 +03001706 if (ath10k_debug_mask & mask) {
1707 if (msg)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001708 ath10k_dbg(ar, mask, "%s\n", msg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001709
Michal Kazior45724a82014-09-23 10:22:53 +02001710 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
1711 linebuflen = 0;
1712 linebuflen += scnprintf(linebuf + linebuflen,
1713 sizeof(linebuf) - linebuflen,
1714 "%s%08x: ",
1715 (prefix ? prefix : ""),
1716 (unsigned int)(ptr - buf));
1717 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
1718 linebuf + linebuflen,
1719 sizeof(linebuf) - linebuflen, true);
1720 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
1721 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001722 }
1723
1724 /* tracing code doesn't like null strings :/ */
Michal Kaziord35a6c12014-09-02 11:00:21 +03001725 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001726 buf, len);
1727}
1728EXPORT_SYMBOL(ath10k_dbg_dump);
1729
1730#endif /* CONFIG_ATH10K_DEBUG */