blob: f10721da49804305390550210fb3ecc92453758f [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/vmalloc.h>
Johannes Berg12c27152014-11-21 18:58:49 +020021#include <linux/utsname.h>
Kalle Valo5e3dd152013-06-12 20:52:10 +030022
23#include "core.h"
24#include "debug.h"
Kalle Valo7869b4f2014-09-24 14:16:58 +030025#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030026
Kalle Valoa3d135e2013-09-03 11:44:10 +030027/* ms */
28#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
29
Ben Greear384914b2014-08-25 08:37:32 +030030#define ATH10K_FW_CRASH_DUMP_VERSION 1
31
32/**
33 * enum ath10k_fw_crash_dump_type - types of data in the dump file
34 * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format
35 */
36enum ath10k_fw_crash_dump_type {
37 ATH10K_FW_CRASH_DUMP_REGISTERS = 0,
38
39 ATH10K_FW_CRASH_DUMP_MAX,
40};
41
42struct ath10k_tlv_dump_data {
43 /* see ath10k_fw_crash_dump_type above */
44 __le32 type;
45
46 /* in bytes */
47 __le32 tlv_len;
48
49 /* pad to 32-bit boundaries as needed */
50 u8 tlv_data[];
51} __packed;
52
53struct ath10k_dump_file_data {
54 /* dump file information */
55
56 /* "ATH10K-FW-DUMP" */
57 char df_magic[16];
58
59 __le32 len;
60
61 /* file dump version */
62 __le32 version;
63
64 /* some info we can get from ath10k struct that might help */
65
66 u8 uuid[16];
67
68 __le32 chip_id;
69
70 /* 0 for now, in place for later hardware */
71 __le32 bus_type;
72
73 __le32 target_version;
74 __le32 fw_version_major;
75 __le32 fw_version_minor;
76 __le32 fw_version_release;
77 __le32 fw_version_build;
78 __le32 phy_capability;
79 __le32 hw_min_tx_power;
80 __le32 hw_max_tx_power;
81 __le32 ht_cap_info;
82 __le32 vht_cap_info;
83 __le32 num_rf_chains;
84
85 /* firmware version string */
86 char fw_ver[ETHTOOL_FWVERS_LEN];
87
88 /* Kernel related information */
89
90 /* time-of-day stamp */
91 __le64 tv_sec;
92
93 /* time-of-day stamp, nano-seconds */
94 __le64 tv_nsec;
95
96 /* LINUX_VERSION_CODE */
97 __le32 kernel_ver_code;
98
99 /* VERMAGIC_STRING */
100 char kernel_ver[64];
101
102 /* room for growth w/out changing binary format */
103 u8 unused[128];
104
105 /* struct ath10k_tlv_dump_data + more */
106 u8 data[0];
107} __packed;
108
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700109void ath10k_info(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300110{
111 struct va_format vaf = {
112 .fmt = fmt,
113 };
114 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300115
116 va_start(args, fmt);
117 vaf.va = &args;
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700118 dev_info(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300119 trace_ath10k_log_info(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300120 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300121}
122EXPORT_SYMBOL(ath10k_info);
123
Kalle Valo8a0c7972014-08-25 08:37:45 +0300124void ath10k_print_driver_info(struct ath10k *ar)
125{
Kalle Valoa58227e2014-10-13 09:40:59 +0300126 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 +0300127 ar->hw_params.name,
128 ar->target_version,
129 ar->chip_id,
130 ar->hw->wiphy->fw_version,
131 ar->fw_api,
132 ar->htt.target_version_major,
Michal Kazior34b28b62014-09-23 10:22:52 +0200133 ar->htt.target_version_minor,
134 ar->fw_version_major,
135 ar->fw_version_minor,
136 ar->fw_version_release,
Kalle Valoa58227e2014-10-13 09:40:59 +0300137 ar->fw_version_build,
138 ath10k_cal_mode_str(ar->cal_mode));
Kalle Valo43d2a302014-09-10 18:23:30 +0300139 ath10k_info(ar, "debug %d debugfs %d tracing %d dfs %d testmode %d\n",
Kalle Valo8a0c7972014-08-25 08:37:45 +0300140 config_enabled(CONFIG_ATH10K_DEBUG),
141 config_enabled(CONFIG_ATH10K_DEBUGFS),
142 config_enabled(CONFIG_ATH10K_TRACING),
Kalle Valo43d2a302014-09-10 18:23:30 +0300143 config_enabled(CONFIG_ATH10K_DFS_CERTIFIED),
144 config_enabled(CONFIG_NL80211_TESTMODE));
Kalle Valo8a0c7972014-08-25 08:37:45 +0300145}
146EXPORT_SYMBOL(ath10k_print_driver_info);
147
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700148void ath10k_err(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300149{
150 struct va_format vaf = {
151 .fmt = fmt,
152 };
153 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300154
155 va_start(args, fmt);
156 vaf.va = &args;
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700157 dev_err(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300158 trace_ath10k_log_err(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300159 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300160}
161EXPORT_SYMBOL(ath10k_err);
162
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700163void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300164{
165 struct va_format vaf = {
166 .fmt = fmt,
167 };
168 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300169
170 va_start(args, fmt);
171 vaf.va = &args;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200172 dev_warn_ratelimited(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300173 trace_ath10k_log_warn(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300174
175 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300176}
177EXPORT_SYMBOL(ath10k_warn);
178
179#ifdef CONFIG_ATH10K_DEBUGFS
180
181void ath10k_debug_read_service_map(struct ath10k *ar,
Michal Kazior5c01aa3d2014-09-18 15:21:24 +0200182 const void *service_map,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300183 size_t map_size)
184{
185 memcpy(ar->debug.wmi_service_bitmap, service_map, map_size);
186}
187
188static 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;
Michal Kaziorcff990c2014-08-04 09:18:33 +0300194 unsigned int len = 0, buf_len = 4096;
195 const char *name;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300196 ssize_t ret_cnt;
Michal Kaziorcff990c2014-08-04 09:18:33 +0300197 bool enabled;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300198 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
Michal Kaziorc4f8c832014-09-04 10:18:32 +0200209 for (i = 0; i < WMI_SERVICE_MAX; i++) {
Michal Kaziorcff990c2014-08-04 09:18:33 +0300210 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 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300221
222 len += scnprintf(buf + len, buf_len - len,
Michal Kaziorcff990c2014-08-04 09:18:33 +0300223 "%-40s %s\n",
224 name, enabled ? "enabled" : "-");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300225 }
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
235static 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
Michal Kazior53268492014-09-25 12:33:50 +0200242static 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
252static 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
262static 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
271static 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
Michal Kazior60ef4012014-09-25 12:33:48 +0200282void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300283{
Michal Kazior53268492014-09-25 12:33:50 +0200284 struct ath10k_fw_stats stats = {};
285 bool is_start, is_started, is_end;
286 size_t num_peers;
Michal Kaziord15fb522014-09-25 12:33:47 +0200287 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300288
Michal Kazior53268492014-09-25 12:33:50 +0200289 INIT_LIST_HEAD(&stats.pdevs);
290 INIT_LIST_HEAD(&stats.peers);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300291
Michal Kazior53268492014-09-25 12:33:50 +0200292 spin_lock_bh(&ar->data_lock);
293 ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
Michal Kaziord15fb522014-09-25 12:33:47 +0200294 if (ret) {
295 ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
296 goto unlock;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300297 }
298
Michal Kazior53268492014-09-25 12:33:50 +0200299 /* 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
Michal Kazior60ef4012014-09-25 12:33:48 +0200342 complete(&ar->debug.fw_stats_complete);
Michal Kaziord15fb522014-09-25 12:33:47 +0200343
Michal Kazior53268492014-09-25 12:33:50 +0200344free:
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
Michal Kaziord15fb522014-09-25 12:33:47 +0200351unlock:
352 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300353}
354
Michal Kazior53268492014-09-25 12:33:50 +0200355static int ath10k_debug_fw_stats_request(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300356{
Michal Kazior53268492014-09-25 12:33:50 +0200357 unsigned long timeout;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300358 int ret;
359
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200360 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300361
Michal Kazior53268492014-09-25 12:33:50 +0200362 timeout = jiffies + msecs_to_jiffies(1*HZ);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300363
Michal Kazior53268492014-09-25 12:33:50 +0200364 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 }
377
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 }
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200390
391 return 0;
392}
393
394/* FIXME: How to calculate the buffer size sanely? */
395#define ATH10K_FW_STATS_BUF_SIZE (1024*1024)
396
397static 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;
Michal Kazior53268492014-09-25 12:33:50 +0200403 const struct ath10k_fw_stats_pdev *pdev;
404 const struct ath10k_fw_stats_peer *peer;
405 size_t num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300406
Michal Kazior87571bf2013-07-16 09:38:59 +0200407 spin_lock_bh(&ar->data_lock);
Michal Kazior53268492014-09-25 12:33:50 +0200408
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
Kalle Valo5e3dd152013-06-12 20:52:10 +0300418 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",
Michal Kazior53268492014-09-25 12:33:50 +0200425 "Channel noise floor", pdev->ch_noise_floor);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300426 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200427 "Channel TX power", pdev->chan_tx_power);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300428 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200429 "TX frame count", pdev->tx_frame_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300430 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200431 "RX frame count", pdev->rx_frame_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300432 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200433 "RX clear count", pdev->rx_clear_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300434 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200435 "Cycle count", pdev->cycle_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300436 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200437 "PHY error count", pdev->phy_err_count);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200438 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200439 "RTS bad count", pdev->rts_bad);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200440 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200441 "RTS good count", pdev->rts_good);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200442 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200443 "FCS bad count", pdev->fcs_bad);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200444 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200445 "No beacon count", pdev->no_beacons);
Chun-Yeow Yeoh52e346d2014-03-28 14:35:16 +0200446 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200447 "MIB int count", pdev->mib_int_count);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300448
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",
Michal Kazior53268492014-09-25 12:33:50 +0200456 "HTT cookies queued", pdev->comp_queued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300457 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200458 "HTT cookies disp.", pdev->comp_delivered);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300459 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200460 "MSDU queued", pdev->msdu_enqued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300461 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200462 "MPDU queued", pdev->mpdu_enqued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300463 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200464 "MSDUs dropped", pdev->wmm_drop);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300465 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200466 "Local enqued", pdev->local_enqued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300467 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200468 "Local freed", pdev->local_freed);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300469 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200470 "HW queued", pdev->hw_queued);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300471 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200472 "PPDUs reaped", pdev->hw_reaped);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300473 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200474 "Num underruns", pdev->underrun);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300475 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200476 "PPDUs cleaned", pdev->tx_abort);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300477 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200478 "MPDUs requed", pdev->mpdus_requed);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300479 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200480 "Excessive retries", pdev->tx_ko);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300481 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200482 "HW rate", pdev->data_rc);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300483 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200484 "Sched self tiggers", pdev->self_triggers);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300485 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
486 "Dropped due to SW retries",
Michal Kazior53268492014-09-25 12:33:50 +0200487 pdev->sw_retry_failure);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300488 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
489 "Illegal rate phy errors",
Michal Kazior53268492014-09-25 12:33:50 +0200490 pdev->illgl_rate_phy_err);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300491 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200492 "Pdev continous xretry", pdev->pdev_cont_xretry);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300493 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200494 "TX timeout", pdev->pdev_tx_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300495 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200496 "PDEV resets", pdev->pdev_resets);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300497 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200498 "PHY underrun", pdev->phy_underrun);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300499 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200500 "MPDU is more than txop limit", pdev->txop_ovf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300501
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",
Michal Kazior53268492014-09-25 12:33:50 +0200510 pdev->mid_ppdu_route_change);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300511 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200512 "Tot. number of statuses", pdev->status_rcvd);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300513 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200514 "Extra frags on rings 0", pdev->r0_frags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300515 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200516 "Extra frags on rings 1", pdev->r1_frags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300517 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200518 "Extra frags on rings 2", pdev->r2_frags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300519 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200520 "Extra frags on rings 3", pdev->r3_frags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300521 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200522 "MSDUs delivered to HTT", pdev->htt_msdus);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300523 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200524 "MPDUs delivered to HTT", pdev->htt_mpdus);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300525 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200526 "MSDUs delivered to stack", pdev->loc_msdus);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300527 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200528 "MPDUs delivered to stack", pdev->loc_mpdus);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300529 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200530 "Oversized AMSUs", pdev->oversize_amsdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300531 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200532 "PHY errors", pdev->phy_errs);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300533 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200534 "PHY errors drops", pdev->phy_err_drop);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300535 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
Michal Kazior53268492014-09-25 12:33:50 +0200536 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300537
538 len += scnprintf(buf + len, buf_len - len, "\n");
Michal Kazior53268492014-09-25 12:33:50 +0200539 len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
540 "ath10k PEER stats", num_peers);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300541 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
542 "=================");
543
Michal Kazior53268492014-09-25 12:33:50 +0200544 list_for_each_entry(peer, &fw_stats->peers, list) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300545 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
Michal Kazior53268492014-09-25 12:33:50 +0200546 "Peer MAC address", peer->peer_macaddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300547 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200548 "Peer RSSI", peer->peer_rssi);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300549 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200550 "Peer TX rate", peer->peer_tx_rate);
Ben Greear23c3aae2014-03-28 14:35:15 +0200551 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
Michal Kazior53268492014-09-25 12:33:50 +0200552 "Peer RX rate", peer->peer_rx_rate);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300553 len += scnprintf(buf + len, buf_len - len, "\n");
554 }
Michal Kazior53268492014-09-25 12:33:50 +0200555
556unlock:
Michal Kazior87571bf2013-07-16 09:38:59 +0200557 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300558
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200559 if (len >= buf_len)
560 buf[len - 1] = 0;
561 else
562 buf[len] = 0;
563}
Kalle Valo5e3dd152013-06-12 20:52:10 +0300564
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200565static 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;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300570
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200571 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
Michal Kazior53268492014-09-25 12:33:50 +0200584 ret = ath10k_debug_fw_stats_request(ar);
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200585 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;
592
Kalle Valo5e3dd152013-06-12 20:52:10 +0300593 mutex_unlock(&ar->conf_mutex);
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200594 return 0;
595
596err_free:
597 vfree(buf);
598
599err_unlock:
600 mutex_unlock(&ar->conf_mutex);
601 return ret;
602}
603
604static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
605{
606 vfree(file->private_data);
607
608 return 0;
609}
610
611static 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);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300618}
619
620static const struct file_operations fops_fw_stats = {
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200621 .open = ath10k_fw_stats_open,
622 .release = ath10k_fw_stats_release,
Michal Kazior60ef4012014-09-25 12:33:48 +0200623 .read = ath10k_fw_stats_read,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300624 .owner = THIS_MODULE,
625 .llseek = default_llseek,
626};
627
Ben Greearf51dbe72014-09-29 14:41:46 +0300628static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
629 char __user *user_buf,
630 size_t count, loff_t *ppos)
631{
632 struct ath10k *ar = file->private_data;
633 int ret, len, buf_len;
634 char *buf;
635
636 buf_len = 500;
637 buf = kmalloc(buf_len, GFP_KERNEL);
638 if (!buf)
639 return -ENOMEM;
640
641 spin_lock_bh(&ar->data_lock);
642
643 len = 0;
644 len += scnprintf(buf + len, buf_len - len,
645 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
646 len += scnprintf(buf + len, buf_len - len,
647 "fw_warm_reset_counter\t\t%d\n",
648 ar->stats.fw_warm_reset_counter);
649 len += scnprintf(buf + len, buf_len - len,
650 "fw_cold_reset_counter\t\t%d\n",
651 ar->stats.fw_cold_reset_counter);
652
653 spin_unlock_bh(&ar->data_lock);
654
655 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
656
657 kfree(buf);
658
659 return ret;
660}
661
662static const struct file_operations fops_fw_reset_stats = {
663 .open = simple_open,
664 .read = ath10k_debug_fw_reset_stats_read,
665 .owner = THIS_MODULE,
666 .llseek = default_llseek,
667};
668
Ben Greeard5aebc72014-09-10 18:59:28 +0300669/* This is a clean assert crash in firmware. */
670static int ath10k_debug_fw_assert(struct ath10k *ar)
671{
672 struct wmi_vdev_install_key_cmd *cmd;
673 struct sk_buff *skb;
674
675 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
676 if (!skb)
677 return -ENOMEM;
678
679 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
680 memset(cmd, 0, sizeof(*cmd));
681
682 /* big enough number so that firmware asserts */
683 cmd->vdev_id = __cpu_to_le32(0x7ffe);
684
685 return ath10k_wmi_cmd_send(ar, skb,
686 ar->wmi.cmd->vdev_install_key_cmdid);
687}
688
Michal Kazior278c4a82013-07-22 14:08:51 +0200689static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
690 char __user *user_buf,
691 size_t count, loff_t *ppos)
692{
Kalle Valo75cb96d2014-09-14 12:50:44 +0300693 const char buf[] =
694 "To simulate firmware crash write one of the keywords to this file:\n"
695 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
696 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
Michal Kazior605cdba2014-10-28 10:34:37 +0100697 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
698 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
Marek Puzyniak8c656992014-03-21 17:46:56 +0200699
Michal Kazior278c4a82013-07-22 14:08:51 +0200700 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
701}
702
Marek Puzyniak8c656992014-03-21 17:46:56 +0200703/* Simulate firmware crash:
704 * 'soft': Call wmi command causing firmware hang. This firmware hang is
705 * recoverable by warm firmware reset.
706 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
707 * vdev id. This is hard firmware crash because it is recoverable only by cold
708 * firmware reset.
709 */
Michal Kazior278c4a82013-07-22 14:08:51 +0200710static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
711 const char __user *user_buf,
712 size_t count, loff_t *ppos)
713{
714 struct ath10k *ar = file->private_data;
Marek Puzyniak8c656992014-03-21 17:46:56 +0200715 char buf[32];
Michal Kazior278c4a82013-07-22 14:08:51 +0200716 int ret;
717
718 mutex_lock(&ar->conf_mutex);
719
720 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
Marek Puzyniak8c656992014-03-21 17:46:56 +0200721
722 /* make sure that buf is null terminated */
723 buf[sizeof(buf) - 1] = 0;
Michal Kazior278c4a82013-07-22 14:08:51 +0200724
725 if (ar->state != ATH10K_STATE_ON &&
726 ar->state != ATH10K_STATE_RESTARTED) {
727 ret = -ENETDOWN;
728 goto exit;
729 }
730
Marek Puzyniak8c656992014-03-21 17:46:56 +0200731 /* drop the possible '\n' from the end */
732 if (buf[count - 1] == '\n') {
733 buf[count - 1] = 0;
734 count--;
735 }
Michal Kazior278c4a82013-07-22 14:08:51 +0200736
Marek Puzyniak8c656992014-03-21 17:46:56 +0200737 if (!strcmp(buf, "soft")) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200738 ath10k_info(ar, "simulating soft firmware crash\n");
Marek Puzyniak8c656992014-03-21 17:46:56 +0200739 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
740 } else if (!strcmp(buf, "hard")) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200741 ath10k_info(ar, "simulating hard firmware crash\n");
Ben Greear611b3682014-07-25 11:56:40 +0300742 /* 0x7fff is vdev id, and it is always out of range for all
743 * firmware variants in order to force a firmware crash.
744 */
745 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
Kalle Valo5b07e072014-09-14 12:50:06 +0300746 ar->wmi.vdev_param->rts_threshold,
747 0);
Ben Greeard5aebc72014-09-10 18:59:28 +0300748 } else if (!strcmp(buf, "assert")) {
749 ath10k_info(ar, "simulating firmware assert crash\n");
750 ret = ath10k_debug_fw_assert(ar);
Michal Kazior605cdba2014-10-28 10:34:37 +0100751 } else if (!strcmp(buf, "hw-restart")) {
752 ath10k_info(ar, "user requested hw restart\n");
753 queue_work(ar->workqueue, &ar->restart_work);
754 ret = 0;
Marek Puzyniak8c656992014-03-21 17:46:56 +0200755 } else {
756 ret = -EINVAL;
757 goto exit;
758 }
Michal Kazior278c4a82013-07-22 14:08:51 +0200759
Marek Puzyniak8c656992014-03-21 17:46:56 +0200760 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200761 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
Marek Puzyniak8c656992014-03-21 17:46:56 +0200762 goto exit;
763 }
764
765 ret = count;
Michal Kazior278c4a82013-07-22 14:08:51 +0200766
767exit:
768 mutex_unlock(&ar->conf_mutex);
769 return ret;
770}
771
772static const struct file_operations fops_simulate_fw_crash = {
773 .read = ath10k_read_simulate_fw_crash,
774 .write = ath10k_write_simulate_fw_crash,
775 .open = simple_open,
776 .owner = THIS_MODULE,
777 .llseek = default_llseek,
778};
779
Kalle Valo763b8cd2013-09-01 11:22:21 +0300780static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
781 size_t count, loff_t *ppos)
782{
783 struct ath10k *ar = file->private_data;
784 unsigned int len;
785 char buf[50];
786
787 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
788
789 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
790}
791
792static const struct file_operations fops_chip_id = {
793 .read = ath10k_read_chip_id,
794 .open = simple_open,
795 .owner = THIS_MODULE,
796 .llseek = default_llseek,
797};
798
Ben Greear384914b2014-08-25 08:37:32 +0300799struct ath10k_fw_crash_data *
800ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
801{
802 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
803
804 lockdep_assert_held(&ar->data_lock);
805
806 crash_data->crashed_since_read = true;
807 uuid_le_gen(&crash_data->uuid);
808 getnstimeofday(&crash_data->timestamp);
809
810 return crash_data;
811}
812EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
813
814static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
815{
816 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
817 struct ath10k_dump_file_data *dump_data;
818 struct ath10k_tlv_dump_data *dump_tlv;
819 int hdr_len = sizeof(*dump_data);
820 unsigned int len, sofar = 0;
821 unsigned char *buf;
822
823 len = hdr_len;
824 len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
825
826 sofar += hdr_len;
827
828 /* This is going to get big when we start dumping FW RAM and such,
829 * so go ahead and use vmalloc.
830 */
831 buf = vzalloc(len);
832 if (!buf)
833 return NULL;
834
835 spin_lock_bh(&ar->data_lock);
836
837 if (!crash_data->crashed_since_read) {
838 spin_unlock_bh(&ar->data_lock);
839 vfree(buf);
840 return NULL;
841 }
842
843 dump_data = (struct ath10k_dump_file_data *)(buf);
844 strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
845 sizeof(dump_data->df_magic));
846 dump_data->len = cpu_to_le32(len);
847
848 dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
849
850 memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid));
851 dump_data->chip_id = cpu_to_le32(ar->chip_id);
852 dump_data->bus_type = cpu_to_le32(0);
853 dump_data->target_version = cpu_to_le32(ar->target_version);
854 dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
855 dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
856 dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
857 dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
858 dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
859 dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
860 dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
861 dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
862 dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
863 dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
864
865 strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
866 sizeof(dump_data->fw_ver));
867
Johannes Berg12c27152014-11-21 18:58:49 +0200868 dump_data->kernel_ver_code = 0;
869 strlcpy(dump_data->kernel_ver, init_utsname()->release,
Ben Greear384914b2014-08-25 08:37:32 +0300870 sizeof(dump_data->kernel_ver));
871
872 dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
873 dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
874
875 /* Gather crash-dump */
876 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
877 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
878 dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
879 memcpy(dump_tlv->tlv_data, &crash_data->registers,
880 sizeof(crash_data->registers));
881 sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
882
883 ar->debug.fw_crash_data->crashed_since_read = false;
884
885 spin_unlock_bh(&ar->data_lock);
886
887 return dump_data;
888}
889
890static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
891{
892 struct ath10k *ar = inode->i_private;
893 struct ath10k_dump_file_data *dump;
894
895 dump = ath10k_build_dump_file(ar);
896 if (!dump)
897 return -ENODATA;
898
899 file->private_data = dump;
900
901 return 0;
902}
903
904static ssize_t ath10k_fw_crash_dump_read(struct file *file,
905 char __user *user_buf,
906 size_t count, loff_t *ppos)
907{
908 struct ath10k_dump_file_data *dump_file = file->private_data;
909
910 return simple_read_from_buffer(user_buf, count, ppos,
911 dump_file,
912 le32_to_cpu(dump_file->len));
913}
914
915static int ath10k_fw_crash_dump_release(struct inode *inode,
916 struct file *file)
917{
918 vfree(file->private_data);
919
920 return 0;
921}
922
923static const struct file_operations fops_fw_crash_dump = {
924 .open = ath10k_fw_crash_dump_open,
925 .read = ath10k_fw_crash_dump_read,
926 .release = ath10k_fw_crash_dump_release,
927 .owner = THIS_MODULE,
928 .llseek = default_llseek,
929};
930
Kalle Valoa3d135e2013-09-03 11:44:10 +0300931static int ath10k_debug_htt_stats_req(struct ath10k *ar)
932{
933 u64 cookie;
934 int ret;
935
936 lockdep_assert_held(&ar->conf_mutex);
937
938 if (ar->debug.htt_stats_mask == 0)
939 /* htt stats are disabled */
940 return 0;
941
942 if (ar->state != ATH10K_STATE_ON)
943 return 0;
944
945 cookie = get_jiffies_64();
946
947 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
948 cookie);
949 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200950 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
Kalle Valoa3d135e2013-09-03 11:44:10 +0300951 return ret;
952 }
953
954 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
955 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
956
957 return 0;
958}
959
960static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
961{
962 struct ath10k *ar = container_of(work, struct ath10k,
963 debug.htt_stats_dwork.work);
964
965 mutex_lock(&ar->conf_mutex);
966
967 ath10k_debug_htt_stats_req(ar);
968
969 mutex_unlock(&ar->conf_mutex);
970}
971
972static ssize_t ath10k_read_htt_stats_mask(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +0300973 char __user *user_buf,
974 size_t count, loff_t *ppos)
Kalle Valoa3d135e2013-09-03 11:44:10 +0300975{
976 struct ath10k *ar = file->private_data;
977 char buf[32];
978 unsigned int len;
979
980 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
981
982 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
983}
984
985static ssize_t ath10k_write_htt_stats_mask(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +0300986 const char __user *user_buf,
987 size_t count, loff_t *ppos)
Kalle Valoa3d135e2013-09-03 11:44:10 +0300988{
989 struct ath10k *ar = file->private_data;
990 unsigned long mask;
991 int ret;
992
993 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
994 if (ret)
995 return ret;
996
997 /* max 8 bit masks (for now) */
998 if (mask > 0xff)
999 return -E2BIG;
1000
1001 mutex_lock(&ar->conf_mutex);
1002
1003 ar->debug.htt_stats_mask = mask;
1004
1005 ret = ath10k_debug_htt_stats_req(ar);
1006 if (ret)
1007 goto out;
1008
1009 ret = count;
1010
1011out:
1012 mutex_unlock(&ar->conf_mutex);
1013
1014 return ret;
1015}
1016
1017static const struct file_operations fops_htt_stats_mask = {
1018 .read = ath10k_read_htt_stats_mask,
1019 .write = ath10k_write_htt_stats_mask,
1020 .open = simple_open,
1021 .owner = THIS_MODULE,
1022 .llseek = default_llseek,
1023};
1024
Janusz Dziedzicd3856232014-06-02 21:19:46 +03001025static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
1026 char __user *user_buf,
1027 size_t count, loff_t *ppos)
1028{
1029 struct ath10k *ar = file->private_data;
1030 char buf[64];
1031 u8 amsdu = 3, ampdu = 64;
1032 unsigned int len;
1033
1034 mutex_lock(&ar->conf_mutex);
1035
1036 if (ar->debug.htt_max_amsdu)
1037 amsdu = ar->debug.htt_max_amsdu;
1038
1039 if (ar->debug.htt_max_ampdu)
1040 ampdu = ar->debug.htt_max_ampdu;
1041
1042 mutex_unlock(&ar->conf_mutex);
1043
1044 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
1045
1046 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1047}
1048
1049static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
1050 const char __user *user_buf,
1051 size_t count, loff_t *ppos)
1052{
1053 struct ath10k *ar = file->private_data;
1054 int res;
1055 char buf[64];
1056 unsigned int amsdu, ampdu;
1057
1058 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1059
1060 /* make sure that buf is null terminated */
1061 buf[sizeof(buf) - 1] = 0;
1062
1063 res = sscanf(buf, "%u %u", &amsdu, &ampdu);
1064
1065 if (res != 2)
1066 return -EINVAL;
1067
1068 mutex_lock(&ar->conf_mutex);
1069
1070 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1071 if (res)
1072 goto out;
1073
1074 res = count;
1075 ar->debug.htt_max_amsdu = amsdu;
1076 ar->debug.htt_max_ampdu = ampdu;
1077
1078out:
1079 mutex_unlock(&ar->conf_mutex);
1080 return res;
1081}
1082
1083static const struct file_operations fops_htt_max_amsdu_ampdu = {
1084 .read = ath10k_read_htt_max_amsdu_ampdu,
1085 .write = ath10k_write_htt_max_amsdu_ampdu,
1086 .open = simple_open,
1087 .owner = THIS_MODULE,
1088 .llseek = default_llseek,
1089};
1090
Kalle Valof118a3e2014-01-03 12:59:31 +02001091static ssize_t ath10k_read_fw_dbglog(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +03001092 char __user *user_buf,
1093 size_t count, loff_t *ppos)
Kalle Valof118a3e2014-01-03 12:59:31 +02001094{
1095 struct ath10k *ar = file->private_data;
1096 unsigned int len;
1097 char buf[32];
1098
1099 len = scnprintf(buf, sizeof(buf), "0x%08x\n",
1100 ar->debug.fw_dbglog_mask);
1101
1102 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1103}
1104
1105static ssize_t ath10k_write_fw_dbglog(struct file *file,
1106 const char __user *user_buf,
1107 size_t count, loff_t *ppos)
1108{
1109 struct ath10k *ar = file->private_data;
1110 unsigned long mask;
1111 int ret;
1112
1113 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1114 if (ret)
1115 return ret;
1116
1117 mutex_lock(&ar->conf_mutex);
1118
1119 ar->debug.fw_dbglog_mask = mask;
1120
1121 if (ar->state == ATH10K_STATE_ON) {
1122 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask);
1123 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001124 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
Kalle Valof118a3e2014-01-03 12:59:31 +02001125 ret);
1126 goto exit;
1127 }
1128 }
1129
1130 ret = count;
1131
1132exit:
1133 mutex_unlock(&ar->conf_mutex);
1134
1135 return ret;
1136}
1137
Ben Greear6cddcc72014-09-29 14:41:46 +03001138/* TODO: Would be nice to always support ethtool stats, would need to
1139 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1140 * struct available..
1141 */
1142
1143/* This generally cooresponds to the debugfs fw_stats file */
1144static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1145 "tx_pkts_nic",
1146 "tx_bytes_nic",
1147 "rx_pkts_nic",
1148 "rx_bytes_nic",
1149 "d_noise_floor",
1150 "d_cycle_count",
1151 "d_phy_error",
1152 "d_rts_bad",
1153 "d_rts_good",
1154 "d_tx_power", /* in .5 dbM I think */
1155 "d_rx_crc_err", /* fcs_bad */
1156 "d_no_beacon",
1157 "d_tx_mpdus_queued",
1158 "d_tx_msdu_queued",
1159 "d_tx_msdu_dropped",
1160 "d_local_enqued",
1161 "d_local_freed",
1162 "d_tx_ppdu_hw_queued",
1163 "d_tx_ppdu_reaped",
1164 "d_tx_fifo_underrun",
1165 "d_tx_ppdu_abort",
1166 "d_tx_mpdu_requed",
1167 "d_tx_excessive_retries",
1168 "d_tx_hw_rate",
1169 "d_tx_dropped_sw_retries",
1170 "d_tx_illegal_rate",
1171 "d_tx_continuous_xretries",
1172 "d_tx_timeout",
1173 "d_tx_mpdu_txop_limit",
1174 "d_pdev_resets",
1175 "d_rx_mid_ppdu_route_change",
1176 "d_rx_status",
1177 "d_rx_extra_frags_ring0",
1178 "d_rx_extra_frags_ring1",
1179 "d_rx_extra_frags_ring2",
1180 "d_rx_extra_frags_ring3",
1181 "d_rx_msdu_htt",
1182 "d_rx_mpdu_htt",
1183 "d_rx_msdu_stack",
1184 "d_rx_mpdu_stack",
1185 "d_rx_phy_err",
1186 "d_rx_phy_err_drops",
1187 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1188 "d_fw_crash_count",
1189 "d_fw_warm_reset_count",
1190 "d_fw_cold_reset_count",
1191};
1192
1193#define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1194
1195void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1196 struct ieee80211_vif *vif,
1197 u32 sset, u8 *data)
1198{
1199 if (sset == ETH_SS_STATS)
1200 memcpy(data, *ath10k_gstrings_stats,
1201 sizeof(ath10k_gstrings_stats));
1202}
1203
1204int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1205 struct ieee80211_vif *vif, int sset)
1206{
1207 if (sset == ETH_SS_STATS)
1208 return ATH10K_SSTATS_LEN;
1209
1210 return 0;
1211}
1212
1213void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1214 struct ieee80211_vif *vif,
1215 struct ethtool_stats *stats, u64 *data)
1216{
1217 struct ath10k *ar = hw->priv;
1218 static const struct ath10k_fw_stats_pdev zero_stats = {};
1219 const struct ath10k_fw_stats_pdev *pdev_stats;
1220 int i = 0, ret;
1221
1222 mutex_lock(&ar->conf_mutex);
1223
1224 if (ar->state == ATH10K_STATE_ON) {
1225 ret = ath10k_debug_fw_stats_request(ar);
1226 if (ret) {
1227 /* just print a warning and try to use older results */
1228 ath10k_warn(ar,
1229 "failed to get fw stats for ethtool: %d\n",
1230 ret);
1231 }
1232 }
1233
1234 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1235 struct ath10k_fw_stats_pdev,
1236 list);
1237 if (!pdev_stats) {
1238 /* no results available so just return zeroes */
1239 pdev_stats = &zero_stats;
1240 }
1241
1242 spin_lock_bh(&ar->data_lock);
1243
1244 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1245 data[i++] = 0; /* tx bytes */
1246 data[i++] = pdev_stats->htt_mpdus;
1247 data[i++] = 0; /* rx bytes */
1248 data[i++] = pdev_stats->ch_noise_floor;
1249 data[i++] = pdev_stats->cycle_count;
1250 data[i++] = pdev_stats->phy_err_count;
1251 data[i++] = pdev_stats->rts_bad;
1252 data[i++] = pdev_stats->rts_good;
1253 data[i++] = pdev_stats->chan_tx_power;
1254 data[i++] = pdev_stats->fcs_bad;
1255 data[i++] = pdev_stats->no_beacons;
1256 data[i++] = pdev_stats->mpdu_enqued;
1257 data[i++] = pdev_stats->msdu_enqued;
1258 data[i++] = pdev_stats->wmm_drop;
1259 data[i++] = pdev_stats->local_enqued;
1260 data[i++] = pdev_stats->local_freed;
1261 data[i++] = pdev_stats->hw_queued;
1262 data[i++] = pdev_stats->hw_reaped;
1263 data[i++] = pdev_stats->underrun;
1264 data[i++] = pdev_stats->tx_abort;
1265 data[i++] = pdev_stats->mpdus_requed;
1266 data[i++] = pdev_stats->tx_ko;
1267 data[i++] = pdev_stats->data_rc;
1268 data[i++] = pdev_stats->sw_retry_failure;
1269 data[i++] = pdev_stats->illgl_rate_phy_err;
1270 data[i++] = pdev_stats->pdev_cont_xretry;
1271 data[i++] = pdev_stats->pdev_tx_timeout;
1272 data[i++] = pdev_stats->txop_ovf;
1273 data[i++] = pdev_stats->pdev_resets;
1274 data[i++] = pdev_stats->mid_ppdu_route_change;
1275 data[i++] = pdev_stats->status_rcvd;
1276 data[i++] = pdev_stats->r0_frags;
1277 data[i++] = pdev_stats->r1_frags;
1278 data[i++] = pdev_stats->r2_frags;
1279 data[i++] = pdev_stats->r3_frags;
1280 data[i++] = pdev_stats->htt_msdus;
1281 data[i++] = pdev_stats->htt_mpdus;
1282 data[i++] = pdev_stats->loc_msdus;
1283 data[i++] = pdev_stats->loc_mpdus;
1284 data[i++] = pdev_stats->phy_errs;
1285 data[i++] = pdev_stats->phy_err_drop;
1286 data[i++] = pdev_stats->mpdu_errs;
1287 data[i++] = ar->stats.fw_crash_counter;
1288 data[i++] = ar->stats.fw_warm_reset_counter;
1289 data[i++] = ar->stats.fw_cold_reset_counter;
1290
1291 spin_unlock_bh(&ar->data_lock);
1292
1293 mutex_unlock(&ar->conf_mutex);
1294
1295 WARN_ON(i != ATH10K_SSTATS_LEN);
1296}
1297
Kalle Valof118a3e2014-01-03 12:59:31 +02001298static const struct file_operations fops_fw_dbglog = {
1299 .read = ath10k_read_fw_dbglog,
1300 .write = ath10k_write_fw_dbglog,
1301 .open = simple_open,
1302 .owner = THIS_MODULE,
1303 .llseek = default_llseek,
1304};
1305
Kalle Valo7869b4f2014-09-24 14:16:58 +03001306static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1307{
1308 struct ath10k *ar = inode->i_private;
1309 void *buf;
1310 u32 hi_addr;
1311 __le32 addr;
1312 int ret;
1313
1314 mutex_lock(&ar->conf_mutex);
1315
1316 if (ar->state != ATH10K_STATE_ON &&
1317 ar->state != ATH10K_STATE_UTF) {
1318 ret = -ENETDOWN;
1319 goto err;
1320 }
1321
1322 buf = vmalloc(QCA988X_CAL_DATA_LEN);
1323 if (!buf) {
1324 ret = -ENOMEM;
1325 goto err;
1326 }
1327
1328 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1329
1330 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1331 if (ret) {
1332 ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret);
1333 goto err_vfree;
1334 }
1335
1336 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf,
1337 QCA988X_CAL_DATA_LEN);
1338 if (ret) {
1339 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1340 goto err_vfree;
1341 }
1342
1343 file->private_data = buf;
1344
1345 mutex_unlock(&ar->conf_mutex);
1346
1347 return 0;
1348
1349err_vfree:
1350 vfree(buf);
1351
1352err:
1353 mutex_unlock(&ar->conf_mutex);
1354
1355 return ret;
1356}
1357
1358static ssize_t ath10k_debug_cal_data_read(struct file *file,
1359 char __user *user_buf,
1360 size_t count, loff_t *ppos)
1361{
1362 void *buf = file->private_data;
1363
1364 return simple_read_from_buffer(user_buf, count, ppos,
1365 buf, QCA988X_CAL_DATA_LEN);
1366}
1367
1368static int ath10k_debug_cal_data_release(struct inode *inode,
1369 struct file *file)
1370{
1371 vfree(file->private_data);
1372
1373 return 0;
1374}
1375
1376static const struct file_operations fops_cal_data = {
1377 .open = ath10k_debug_cal_data_open,
1378 .read = ath10k_debug_cal_data_read,
1379 .release = ath10k_debug_cal_data_release,
1380 .owner = THIS_MODULE,
1381 .llseek = default_llseek,
1382};
1383
Kalle Valodb66ea02013-09-03 11:44:03 +03001384int ath10k_debug_start(struct ath10k *ar)
1385{
Kalle Valoa3d135e2013-09-03 11:44:10 +03001386 int ret;
1387
Kalle Valo60631c52013-10-08 21:45:25 +03001388 lockdep_assert_held(&ar->conf_mutex);
1389
Kalle Valoa3d135e2013-09-03 11:44:10 +03001390 ret = ath10k_debug_htt_stats_req(ar);
1391 if (ret)
1392 /* continue normally anyway, this isn't serious */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001393 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1394 ret);
Kalle Valoa3d135e2013-09-03 11:44:10 +03001395
Kalle Valof118a3e2014-01-03 12:59:31 +02001396 if (ar->debug.fw_dbglog_mask) {
1397 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask);
1398 if (ret)
1399 /* not serious */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001400 ath10k_warn(ar, "failed to enable dbglog during start: %d",
Kalle Valof118a3e2014-01-03 12:59:31 +02001401 ret);
1402 }
1403
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001404 if (ar->debug.pktlog_filter) {
1405 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1406 ar->debug.pktlog_filter);
1407 if (ret)
1408 /* not serious */
1409 ath10k_warn(ar,
1410 "failed to enable pktlog filter %x: %d\n",
1411 ar->debug.pktlog_filter, ret);
1412 } else {
1413 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1414 if (ret)
1415 /* not serious */
1416 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1417 }
1418
1419 return ret;
Kalle Valodb66ea02013-09-03 11:44:03 +03001420}
1421
1422void ath10k_debug_stop(struct ath10k *ar)
1423{
Kalle Valo60631c52013-10-08 21:45:25 +03001424 lockdep_assert_held(&ar->conf_mutex);
1425
1426 /* Must not use _sync to avoid deadlock, we do that in
1427 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1428 * warning from del_timer(). */
1429 if (ar->debug.htt_stats_mask != 0)
1430 cancel_delayed_work(&ar->debug.htt_stats_dwork);
Janusz Dziedzicd3856232014-06-02 21:19:46 +03001431
1432 ar->debug.htt_max_amsdu = 0;
1433 ar->debug.htt_max_ampdu = 0;
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001434
1435 ath10k_wmi_pdev_pktlog_disable(ar);
Kalle Valodb66ea02013-09-03 11:44:03 +03001436}
1437
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001438static ssize_t ath10k_write_simulate_radar(struct file *file,
1439 const char __user *user_buf,
1440 size_t count, loff_t *ppos)
1441{
1442 struct ath10k *ar = file->private_data;
1443
1444 ieee80211_radar_detected(ar->hw);
1445
1446 return count;
1447}
1448
1449static const struct file_operations fops_simulate_radar = {
1450 .write = ath10k_write_simulate_radar,
1451 .open = simple_open,
1452 .owner = THIS_MODULE,
1453 .llseek = default_llseek,
1454};
1455
1456#define ATH10K_DFS_STAT(s, p) (\
1457 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1458 ar->debug.dfs_stats.p))
1459
1460#define ATH10K_DFS_POOL_STAT(s, p) (\
1461 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1462 ar->debug.dfs_pool_stats.p))
1463
1464static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
1465 size_t count, loff_t *ppos)
1466{
1467 int retval = 0, len = 0;
1468 const int size = 8000;
1469 struct ath10k *ar = file->private_data;
1470 char *buf;
1471
1472 buf = kzalloc(size, GFP_KERNEL);
1473 if (buf == NULL)
1474 return -ENOMEM;
1475
1476 if (!ar->dfs_detector) {
1477 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
1478 goto exit;
1479 }
1480
1481 ar->debug.dfs_pool_stats =
1482 ar->dfs_detector->get_stats(ar->dfs_detector);
1483
1484 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
1485
1486 ATH10K_DFS_STAT("reported phy errors", phy_errors);
1487 ATH10K_DFS_STAT("pulse events reported", pulses_total);
1488 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
1489 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
1490 ATH10K_DFS_STAT("Radars detected", radar_detected);
1491
1492 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
1493 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
1494 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
1495 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
1496 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
1497 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
1498 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
1499 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
1500
1501exit:
1502 if (len > size)
1503 len = size;
1504
1505 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1506 kfree(buf);
1507
1508 return retval;
1509}
1510
1511static const struct file_operations fops_dfs_stats = {
1512 .read = ath10k_read_dfs_stats,
1513 .open = simple_open,
1514 .owner = THIS_MODULE,
1515 .llseek = default_llseek,
1516};
1517
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001518static ssize_t ath10k_write_pktlog_filter(struct file *file,
1519 const char __user *ubuf,
1520 size_t count, loff_t *ppos)
1521{
1522 struct ath10k *ar = file->private_data;
1523 u32 filter;
1524 int ret;
1525
1526 if (kstrtouint_from_user(ubuf, count, 0, &filter))
1527 return -EINVAL;
1528
1529 mutex_lock(&ar->conf_mutex);
1530
1531 if (ar->state != ATH10K_STATE_ON) {
1532 ar->debug.pktlog_filter = filter;
1533 ret = count;
1534 goto out;
1535 }
1536
1537 if (filter && (filter != ar->debug.pktlog_filter)) {
1538 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
1539 if (ret) {
1540 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
1541 ar->debug.pktlog_filter, ret);
1542 goto out;
1543 }
1544 } else {
1545 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1546 if (ret) {
1547 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1548 goto out;
1549 }
1550 }
1551
1552 ar->debug.pktlog_filter = filter;
1553 ret = count;
1554
1555out:
1556 mutex_unlock(&ar->conf_mutex);
1557 return ret;
1558}
1559
1560static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
1561 size_t count, loff_t *ppos)
1562{
1563 char buf[32];
1564 struct ath10k *ar = file->private_data;
1565 int len = 0;
1566
1567 mutex_lock(&ar->conf_mutex);
1568 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
1569 ar->debug.pktlog_filter);
1570 mutex_unlock(&ar->conf_mutex);
1571
1572 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
1573}
1574
1575static const struct file_operations fops_pktlog_filter = {
1576 .read = ath10k_read_pktlog_filter,
1577 .write = ath10k_write_pktlog_filter,
1578 .open = simple_open
1579};
1580
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581int ath10k_debug_create(struct ath10k *ar)
1582{
Ben Greear384914b2014-08-25 08:37:32 +03001583 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
Michal Kaziore13cf7a2014-09-04 09:13:08 +02001584 if (!ar->debug.fw_crash_data)
1585 return -ENOMEM;
Ben Greear384914b2014-08-25 08:37:32 +03001586
Michal Kazior53268492014-09-25 12:33:50 +02001587 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
1588 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
1589
Michal Kaziore13cf7a2014-09-04 09:13:08 +02001590 return 0;
1591}
1592
1593void ath10k_debug_destroy(struct ath10k *ar)
1594{
1595 vfree(ar->debug.fw_crash_data);
1596 ar->debug.fw_crash_data = NULL;
Michal Kazior53268492014-09-25 12:33:50 +02001597
1598 ath10k_debug_fw_stats_reset(ar);
Michal Kaziore13cf7a2014-09-04 09:13:08 +02001599}
1600
1601int ath10k_debug_register(struct ath10k *ar)
1602{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
1604 ar->hw->wiphy->debugfsdir);
Michal Kazioradb43b22014-09-04 12:36:45 +02001605 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
1606 if (IS_ERR(ar->debug.debugfs_phy))
1607 return PTR_ERR(ar->debug.debugfs_phy);
Kalle Valod8bb26b2014-09-14 12:50:33 +03001608
1609 return -ENOMEM;
Michal Kazioradb43b22014-09-04 12:36:45 +02001610 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001611
Kalle Valoa3d135e2013-09-03 11:44:10 +03001612 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
1613 ath10k_debug_htt_stats_dwork);
1614
Michal Kazior60ef4012014-09-25 12:33:48 +02001615 init_completion(&ar->debug.fw_stats_complete);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001616
1617 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
1618 &fops_fw_stats);
1619
Ben Greearf51dbe72014-09-29 14:41:46 +03001620 debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
1621 ar, &fops_fw_reset_stats);
1622
Kalle Valo5e3dd152013-06-12 20:52:10 +03001623 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
1624 &fops_wmi_services);
1625
Michal Kazior278c4a82013-07-22 14:08:51 +02001626 debugfs_create_file("simulate_fw_crash", S_IRUSR, ar->debug.debugfs_phy,
1627 ar, &fops_simulate_fw_crash);
1628
Ben Greear384914b2014-08-25 08:37:32 +03001629 debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy,
1630 ar, &fops_fw_crash_dump);
1631
Kalle Valo763b8cd2013-09-01 11:22:21 +03001632 debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
1633 ar, &fops_chip_id);
1634
Kalle Valoa3d135e2013-09-03 11:44:10 +03001635 debugfs_create_file("htt_stats_mask", S_IRUSR, ar->debug.debugfs_phy,
1636 ar, &fops_htt_stats_mask);
1637
Janusz Dziedzicd3856232014-06-02 21:19:46 +03001638 debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR,
1639 ar->debug.debugfs_phy, ar,
1640 &fops_htt_max_amsdu_ampdu);
1641
Kalle Valof118a3e2014-01-03 12:59:31 +02001642 debugfs_create_file("fw_dbglog", S_IRUSR, ar->debug.debugfs_phy,
1643 ar, &fops_fw_dbglog);
1644
Kalle Valo7869b4f2014-09-24 14:16:58 +03001645 debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
1646 ar, &fops_cal_data);
1647
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001648 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
1649 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
1650 ar->debug.debugfs_phy, ar,
1651 &fops_simulate_radar);
1652
Marek Puzyniak7d9b40b2013-11-20 10:00:28 +02001653 debugfs_create_bool("dfs_block_radar_events", S_IWUSR,
1654 ar->debug.debugfs_phy,
1655 &ar->dfs_block_radar_events);
1656
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001657 debugfs_create_file("dfs_stats", S_IRUSR,
1658 ar->debug.debugfs_phy, ar,
1659 &fops_dfs_stats);
1660 }
1661
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001662 debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
1663 ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
1664
Kalle Valo5e3dd152013-06-12 20:52:10 +03001665 return 0;
1666}
Kalle Valodb66ea02013-09-03 11:44:03 +03001667
Michal Kaziore13cf7a2014-09-04 09:13:08 +02001668void ath10k_debug_unregister(struct ath10k *ar)
Kalle Valo60631c52013-10-08 21:45:25 +03001669{
1670 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
1671}
1672
Kalle Valo5e3dd152013-06-12 20:52:10 +03001673#endif /* CONFIG_ATH10K_DEBUGFS */
1674
1675#ifdef CONFIG_ATH10K_DEBUG
Michal Kazior7aa7a722014-08-25 12:09:38 +02001676void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
1677 const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001678{
1679 struct va_format vaf;
1680 va_list args;
1681
1682 va_start(args, fmt);
1683
1684 vaf.fmt = fmt;
1685 vaf.va = &args;
1686
1687 if (ath10k_debug_mask & mask)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001688 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001689
Michal Kaziord35a6c12014-09-02 11:00:21 +03001690 trace_ath10k_log_dbg(ar, mask, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691
1692 va_end(args);
1693}
1694EXPORT_SYMBOL(ath10k_dbg);
1695
Michal Kazior7aa7a722014-08-25 12:09:38 +02001696void ath10k_dbg_dump(struct ath10k *ar,
1697 enum ath10k_debug_mask mask,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001698 const char *msg, const char *prefix,
1699 const void *buf, size_t len)
1700{
Michal Kazior45724a82014-09-23 10:22:53 +02001701 char linebuf[256];
1702 unsigned int linebuflen;
1703 const void *ptr;
1704
Kalle Valo5e3dd152013-06-12 20:52:10 +03001705 if (ath10k_debug_mask & mask) {
1706 if (msg)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001707 ath10k_dbg(ar, mask, "%s\n", msg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001708
Michal Kazior45724a82014-09-23 10:22:53 +02001709 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
1710 linebuflen = 0;
1711 linebuflen += scnprintf(linebuf + linebuflen,
1712 sizeof(linebuf) - linebuflen,
1713 "%s%08x: ",
1714 (prefix ? prefix : ""),
1715 (unsigned int)(ptr - buf));
1716 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
1717 linebuf + linebuflen,
1718 sizeof(linebuf) - linebuflen, true);
1719 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
1720 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001721 }
1722
1723 /* tracing code doesn't like null strings :/ */
Michal Kaziord35a6c12014-09-02 11:00:21 +03001724 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001725 buf, len);
1726}
1727EXPORT_SYMBOL(ath10k_dbg_dump);
1728
1729#endif /* CONFIG_ATH10K_DEBUG */