blob: 554cd7856cb6e2949cc5eff17aeb76a414204d63 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
Kalle Valo8b1083d2017-12-22 18:31:13 +02003 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
Yu Wang50e79e22018-01-30 14:06:08 +02004 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
Kalle Valo5e3dd152013-06-12 20:52:10 +03005 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <linux/module.h>
20#include <linux/debugfs.h>
Ben Greear384914b2014-08-25 08:37:32 +030021#include <linux/vmalloc.h>
Kalle Valo3e580442015-11-25 15:38:34 +020022#include <linux/crc32.h>
23#include <linux/firmware.h>
Kalle Valo5e3dd152013-06-12 20:52:10 +030024
25#include "core.h"
26#include "debug.h"
Kalle Valo7869b4f2014-09-24 14:16:58 +030027#include "hif.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020028#include "wmi-ops.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030029
Kalle Valoa3d135e2013-09-03 11:44:10 +030030/* ms */
31#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
32
Marty Faltesekf67b107d2016-10-10 19:00:04 +030033#define ATH10K_DEBUG_CAL_DATA_LEN 12064
34
Joe Perchesbabcb3e2014-09-22 10:35:34 -070035void ath10k_info(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +030036{
37 struct va_format vaf = {
38 .fmt = fmt,
39 };
40 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +030041
42 va_start(args, fmt);
43 vaf.va = &args;
Joe Perchesbabcb3e2014-09-22 10:35:34 -070044 dev_info(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +030045 trace_ath10k_log_info(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +030046 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +030047}
48EXPORT_SYMBOL(ath10k_info);
49
Kalle Valo23f591e2015-11-25 15:38:27 +020050void ath10k_debug_print_hwfw_info(struct ath10k *ar)
Kalle Valo8a0c7972014-08-25 08:37:45 +030051{
Kalle Valo7ebf7212016-04-20 19:44:51 +030052 const struct firmware *firmware;
Michal Kazior84e3df62015-08-05 06:55:37 +020053 char fw_features[128] = {};
Michal Kazior8866c722016-03-17 10:52:08 +010054 u32 crc = 0;
Michal Kaziorb27bc5a2015-06-15 14:46:40 +030055
56 ath10k_core_get_fw_features_str(ar, fw_features, sizeof(fw_features));
57
Kalle Valo8605c022015-11-25 15:38:19 +020058 ath10k_info(ar, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x",
Kalle Valo8a0c7972014-08-25 08:37:45 +030059 ar->hw_params.name,
60 ar->target_version,
61 ar->chip_id,
Kalle Valo8605c022015-11-25 15:38:19 +020062 ar->id.subsystem_vendor, ar->id.subsystem_device);
Kalle Valof0de90b2015-11-25 15:38:12 +020063
Kalle Valof0de90b2015-11-25 15:38:12 +020064 ath10k_info(ar, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n",
Masahiro Yamada97f26452016-08-03 13:45:50 -070065 IS_ENABLED(CONFIG_ATH10K_DEBUG),
66 IS_ENABLED(CONFIG_ATH10K_DEBUGFS),
67 IS_ENABLED(CONFIG_ATH10K_TRACING),
68 IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED),
69 IS_ENABLED(CONFIG_NL80211_TESTMODE));
Kalle Valof0de90b2015-11-25 15:38:12 +020070
Kalle Valo7ebf7212016-04-20 19:44:51 +030071 firmware = ar->normal_mode_fw.fw_file.firmware;
72 if (firmware)
73 crc = crc32_le(0, firmware->data, firmware->size);
Michal Kazior8866c722016-03-17 10:52:08 +010074
Kalle Valo3e580442015-11-25 15:38:34 +020075 ath10k_info(ar, "firmware ver %s api %d features %s crc32 %08x\n",
Kalle Valo23f591e2015-11-25 15:38:27 +020076 ar->hw->wiphy->fw_version,
77 ar->fw_api,
Kalle Valo3e580442015-11-25 15:38:34 +020078 fw_features,
Michal Kazior8866c722016-03-17 10:52:08 +010079 crc);
Kalle Valo23f591e2015-11-25 15:38:27 +020080}
81
82void ath10k_debug_print_board_info(struct ath10k *ar)
83{
84 char boardinfo[100];
Yu Wang50e79e22018-01-30 14:06:08 +020085 const struct firmware *board;
86 u32 crc;
Kalle Valo23f591e2015-11-25 15:38:27 +020087
88 if (ar->id.bmi_ids_valid)
89 scnprintf(boardinfo, sizeof(boardinfo), "%d:%d",
90 ar->id.bmi_chip_id, ar->id.bmi_board_id);
91 else
92 scnprintf(boardinfo, sizeof(boardinfo), "N/A");
93
Yu Wang50e79e22018-01-30 14:06:08 +020094 board = ar->normal_mode_fw.board;
95 if (!IS_ERR_OR_NULL(board))
96 crc = crc32_le(0, board->data, board->size);
97 else
98 crc = 0;
99
Kalle Valo3e580442015-11-25 15:38:34 +0200100 ath10k_info(ar, "board_file api %d bmi_id %s crc32 %08x",
Kalle Valo23f591e2015-11-25 15:38:27 +0200101 ar->bd_api,
Kalle Valo3e580442015-11-25 15:38:34 +0200102 boardinfo,
Yu Wang50e79e22018-01-30 14:06:08 +0200103 crc);
Kalle Valo23f591e2015-11-25 15:38:27 +0200104}
105
106void ath10k_debug_print_boot_info(struct ath10k *ar)
107{
Kalle Valof0de90b2015-11-25 15:38:12 +0200108 ath10k_info(ar, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n",
Kalle Valo8a0c7972014-08-25 08:37:45 +0300109 ar->htt.target_version_major,
Michal Kazior34b28b62014-09-23 10:22:52 +0200110 ar->htt.target_version_minor,
Kalle Valobf3c13a2016-04-20 19:45:33 +0300111 ar->normal_mode_fw.fw_file.wmi_op_version,
Kalle Valo77561f92016-04-20 19:45:47 +0300112 ar->normal_mode_fw.fw_file.htt_op_version,
Michal Kaziorcfd10612014-11-25 15:16:05 +0100113 ath10k_cal_mode_str(ar->cal_mode),
Michal Kaziorb27bc5a2015-06-15 14:46:40 +0300114 ar->max_num_stations,
David Liuccec9032015-07-24 20:25:32 +0300115 test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags),
Kalle Valof0de90b2015-11-25 15:38:12 +0200116 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags));
Kalle Valo8a0c7972014-08-25 08:37:45 +0300117}
Kalle Valo23f591e2015-11-25 15:38:27 +0200118
119void ath10k_print_driver_info(struct ath10k *ar)
120{
121 ath10k_debug_print_hwfw_info(ar);
122 ath10k_debug_print_board_info(ar);
123 ath10k_debug_print_boot_info(ar);
124}
Kalle Valo8a0c7972014-08-25 08:37:45 +0300125EXPORT_SYMBOL(ath10k_print_driver_info);
126
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700127void ath10k_err(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300128{
129 struct va_format vaf = {
130 .fmt = fmt,
131 };
132 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300133
134 va_start(args, fmt);
135 vaf.va = &args;
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700136 dev_err(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300137 trace_ath10k_log_err(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300138 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300139}
140EXPORT_SYMBOL(ath10k_err);
141
Joe Perchesbabcb3e2014-09-22 10:35:34 -0700142void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300143{
144 struct va_format vaf = {
145 .fmt = fmt,
146 };
147 va_list args;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300148
149 va_start(args, fmt);
150 vaf.va = &args;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200151 dev_warn_ratelimited(ar->dev, "%pV", &vaf);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300152 trace_ath10k_log_warn(ar, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300153
154 va_end(args);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300155}
156EXPORT_SYMBOL(ath10k_warn);
157
158#ifdef CONFIG_ATH10K_DEBUGFS
159
Kalle Valo5e3dd152013-06-12 20:52:10 +0300160static ssize_t ath10k_read_wmi_services(struct file *file,
161 char __user *user_buf,
162 size_t count, loff_t *ppos)
163{
164 struct ath10k *ar = file->private_data;
165 char *buf;
Tamizh chelvam75e0dde2017-07-03 11:02:36 +0530166 size_t len = 0, buf_len = 8192;
Michal Kaziorcff990c2014-08-04 09:18:33 +0300167 const char *name;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300168 ssize_t ret_cnt;
Michal Kaziorcff990c2014-08-04 09:18:33 +0300169 bool enabled;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300170 int i;
171
172 buf = kzalloc(buf_len, GFP_KERNEL);
173 if (!buf)
174 return -ENOMEM;
175
176 mutex_lock(&ar->conf_mutex);
177
Michal Kazioracfe7ec2014-11-27 10:11:17 +0100178 spin_lock_bh(&ar->data_lock);
Michal Kaziorc4f8c832014-09-04 10:18:32 +0200179 for (i = 0; i < WMI_SERVICE_MAX; i++) {
Michal Kazioracfe7ec2014-11-27 10:11:17 +0100180 enabled = test_bit(i, ar->wmi.svc_map);
Michal Kaziorcff990c2014-08-04 09:18:33 +0300181 name = wmi_service_name(i);
182
183 if (!name) {
184 if (enabled)
185 len += scnprintf(buf + len, buf_len - len,
186 "%-40s %s (bit %d)\n",
187 "unknown", "enabled", i);
188
189 continue;
190 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300191
192 len += scnprintf(buf + len, buf_len - len,
Michal Kaziorcff990c2014-08-04 09:18:33 +0300193 "%-40s %s\n",
194 name, enabled ? "enabled" : "-");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300195 }
Michal Kazioracfe7ec2014-11-27 10:11:17 +0100196 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300197
198 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
199
200 mutex_unlock(&ar->conf_mutex);
201
202 kfree(buf);
203 return ret_cnt;
204}
205
206static const struct file_operations fops_wmi_services = {
207 .read = ath10k_read_wmi_services,
208 .open = simple_open,
209 .owner = THIS_MODULE,
210 .llseek = default_llseek,
211};
212
Mohammed Shafi Shajakhanb4619ea2016-01-13 21:16:31 +0530213static void ath10k_fw_stats_pdevs_free(struct list_head *head)
Michal Kazior53268492014-09-25 12:33:50 +0200214{
215 struct ath10k_fw_stats_pdev *i, *tmp;
216
217 list_for_each_entry_safe(i, tmp, head, list) {
218 list_del(&i->list);
219 kfree(i);
220 }
221}
222
Mohammed Shafi Shajakhanb4619ea2016-01-13 21:16:31 +0530223static void ath10k_fw_stats_vdevs_free(struct list_head *head)
Michal Kazior7b6b1532015-02-15 16:50:40 +0200224{
225 struct ath10k_fw_stats_vdev *i, *tmp;
226
227 list_for_each_entry_safe(i, tmp, head, list) {
228 list_del(&i->list);
229 kfree(i);
230 }
231}
232
Mohammed Shafi Shajakhanb4619ea2016-01-13 21:16:31 +0530233static void ath10k_fw_stats_peers_free(struct list_head *head)
Michal Kazior53268492014-09-25 12:33:50 +0200234{
235 struct ath10k_fw_stats_peer *i, *tmp;
236
237 list_for_each_entry_safe(i, tmp, head, list) {
238 list_del(&i->list);
239 kfree(i);
240 }
241}
242
Mohammed Shafi Shajakhan4a49ae92016-06-30 15:23:47 +0300243static void ath10k_fw_extd_stats_peers_free(struct list_head *head)
244{
245 struct ath10k_fw_extd_stats_peer *i, *tmp;
246
247 list_for_each_entry_safe(i, tmp, head, list) {
248 list_del(&i->list);
249 kfree(i);
250 }
251}
252
Michal Kazior53268492014-09-25 12:33:50 +0200253static void ath10k_debug_fw_stats_reset(struct ath10k *ar)
254{
255 spin_lock_bh(&ar->data_lock);
256 ar->debug.fw_stats_done = false;
Mohammed Shafi Shajakhan4a49ae92016-06-30 15:23:47 +0300257 ar->debug.fw_stats.extended = false;
Mohammed Shafi Shajakhanb4619ea2016-01-13 21:16:31 +0530258 ath10k_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
259 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
260 ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers);
Mohammed Shafi Shajakhan4a49ae92016-06-30 15:23:47 +0300261 ath10k_fw_extd_stats_peers_free(&ar->debug.fw_stats.peers_extd);
Michal Kazior53268492014-09-25 12:33:50 +0200262 spin_unlock_bh(&ar->data_lock);
263}
264
Michal Kazior60ef4012014-09-25 12:33:48 +0200265void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300266{
Michal Kazior53268492014-09-25 12:33:50 +0200267 struct ath10k_fw_stats stats = {};
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +0530268 bool is_start, is_started, is_end;
Michal Kazior53268492014-09-25 12:33:50 +0200269 size_t num_peers;
Michal Kazior7b6b1532015-02-15 16:50:40 +0200270 size_t num_vdevs;
Michal Kaziord15fb522014-09-25 12:33:47 +0200271 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300272
Michal Kazior53268492014-09-25 12:33:50 +0200273 INIT_LIST_HEAD(&stats.pdevs);
Michal Kazior7b6b1532015-02-15 16:50:40 +0200274 INIT_LIST_HEAD(&stats.vdevs);
Michal Kazior53268492014-09-25 12:33:50 +0200275 INIT_LIST_HEAD(&stats.peers);
Mohammed Shafi Shajakhan4a49ae92016-06-30 15:23:47 +0300276 INIT_LIST_HEAD(&stats.peers_extd);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300277
Michal Kazior53268492014-09-25 12:33:50 +0200278 spin_lock_bh(&ar->data_lock);
279 ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
Michal Kaziord15fb522014-09-25 12:33:47 +0200280 if (ret) {
281 ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
Raja Mani5db879a2015-07-09 14:19:43 +0530282 goto free;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300283 }
284
Michal Kazior53268492014-09-25 12:33:50 +0200285 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
286 * splits the stats data and delivers it in a ping-pong fashion of
287 * request cmd-update event.
288 *
289 * However there is no explicit end-of-data. Instead start-of-data is
290 * used as an implicit one. This works as follows:
291 * a) discard stat update events until one with pdev stats is
292 * delivered - this skips session started at end of (b)
293 * b) consume stat update events until another one with pdev stats is
294 * delivered which is treated as end-of-data and is itself discarded
295 */
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +0530296 if (ath10k_peer_stats_enabled(ar))
Mohammed Shafi Shajakhan4a49ae92016-06-30 15:23:47 +0300297 ath10k_sta_update_rx_duration(ar, &stats);
Mohammed Shafi Shajakhan74135f52016-02-03 21:07:42 +0530298
Mohammed Shafi Shajakhane0b6ce02016-02-03 21:07:43 +0530299 if (ar->debug.fw_stats_done) {
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +0530300 if (!ath10k_peer_stats_enabled(ar))
Mohammed Shafi Shajakhane0b6ce02016-02-03 21:07:43 +0530301 ath10k_warn(ar, "received unsolicited stats update event\n");
302
Michal Kazior53268492014-09-25 12:33:50 +0200303 goto free;
304 }
305
Manikanta Pubbisettybc6f9ae2015-10-16 15:54:52 +0300306 num_peers = ath10k_wmi_fw_stats_num_peers(&ar->debug.fw_stats.peers);
307 num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&ar->debug.fw_stats.vdevs);
Michal Kazior53268492014-09-25 12:33:50 +0200308 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
309 !list_empty(&stats.pdevs));
310 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
311 !list_empty(&stats.pdevs));
312
313 if (is_start)
314 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
315
316 if (is_end)
317 ar->debug.fw_stats_done = true;
318
319 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
320
321 if (is_started && !is_end) {
322 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
323 /* Although this is unlikely impose a sane limit to
324 * prevent firmware from DoS-ing the host.
325 */
Mohammed Shafi Shajakhand57e7f22016-01-13 21:16:32 +0530326 ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers);
Christian Lamparterc1e33302016-12-05 22:52:45 +0100327 ath10k_fw_extd_stats_peers_free(&ar->debug.fw_stats.peers_extd);
Michal Kazior53268492014-09-25 12:33:50 +0200328 ath10k_warn(ar, "dropping fw peer stats\n");
329 goto free;
330 }
331
Michal Kazior7b6b1532015-02-15 16:50:40 +0200332 if (num_vdevs >= BITS_PER_LONG) {
Mohammed Shafi Shajakhand57e7f22016-01-13 21:16:32 +0530333 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
Michal Kazior7b6b1532015-02-15 16:50:40 +0200334 ath10k_warn(ar, "dropping fw vdev stats\n");
335 goto free;
336 }
337
Christian Lamparterc1e33302016-12-05 22:52:45 +0100338 if (!list_empty(&stats.peers))
339 list_splice_tail_init(&stats.peers_extd,
340 &ar->debug.fw_stats.peers_extd);
341
Michal Kazior53268492014-09-25 12:33:50 +0200342 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
Michal Kazior7b6b1532015-02-15 16:50:40 +0200343 list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs);
Michal Kazior53268492014-09-25 12:33:50 +0200344 }
345
Michal Kazior60ef4012014-09-25 12:33:48 +0200346 complete(&ar->debug.fw_stats_complete);
Michal Kaziord15fb522014-09-25 12:33:47 +0200347
Michal Kazior53268492014-09-25 12:33:50 +0200348free:
349 /* In some cases lists have been spliced and cleared. Free up
350 * resources if that is not the case.
351 */
Mohammed Shafi Shajakhanb4619ea2016-01-13 21:16:31 +0530352 ath10k_fw_stats_pdevs_free(&stats.pdevs);
353 ath10k_fw_stats_vdevs_free(&stats.vdevs);
354 ath10k_fw_stats_peers_free(&stats.peers);
Mohammed Shafi Shajakhan4a49ae92016-06-30 15:23:47 +0300355 ath10k_fw_extd_stats_peers_free(&stats.peers_extd);
Michal Kazior53268492014-09-25 12:33:50 +0200356
Michal Kaziord15fb522014-09-25 12:33:47 +0200357 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300358}
359
Michal Kazior53268492014-09-25 12:33:50 +0200360static int ath10k_debug_fw_stats_request(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300361{
Nicholas Mc Guire6e8d5432015-03-30 15:39:20 +0300362 unsigned long timeout, time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300363 int ret;
364
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200365 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300366
Nicholas Mc Guire6e8d5432015-03-30 15:39:20 +0300367 timeout = jiffies + msecs_to_jiffies(1 * HZ);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300368
Michal Kazior53268492014-09-25 12:33:50 +0200369 ath10k_debug_fw_stats_reset(ar);
370
371 for (;;) {
372 if (time_after(jiffies, timeout))
373 return -ETIMEDOUT;
374
375 reinit_completion(&ar->debug.fw_stats_complete);
376
Yanbo Li6274cd42015-04-01 22:53:21 +0300377 ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask);
Michal Kazior53268492014-09-25 12:33:50 +0200378 if (ret) {
379 ath10k_warn(ar, "could not request stats (%d)\n", ret);
380 return ret;
381 }
382
Nicholas Mc Guire6e8d5432015-03-30 15:39:20 +0300383 time_left =
384 wait_for_completion_timeout(&ar->debug.fw_stats_complete,
385 1 * HZ);
386 if (!time_left)
Michal Kazior53268492014-09-25 12:33:50 +0200387 return -ETIMEDOUT;
388
389 spin_lock_bh(&ar->data_lock);
390 if (ar->debug.fw_stats_done) {
391 spin_unlock_bh(&ar->data_lock);
392 break;
393 }
394 spin_unlock_bh(&ar->data_lock);
395 }
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200396
397 return 0;
398}
399
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200400static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
401{
402 struct ath10k *ar = inode->i_private;
403 void *buf = NULL;
404 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300405
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200406 mutex_lock(&ar->conf_mutex);
407
408 if (ar->state != ATH10K_STATE_ON) {
409 ret = -ENETDOWN;
410 goto err_unlock;
411 }
412
413 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
414 if (!buf) {
415 ret = -ENOMEM;
416 goto err_unlock;
417 }
418
Michal Kazior53268492014-09-25 12:33:50 +0200419 ret = ath10k_debug_fw_stats_request(ar);
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200420 if (ret) {
421 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
422 goto err_free;
423 }
424
Manikanta Pubbisettybc6f9ae2015-10-16 15:54:52 +0300425 ret = ath10k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
426 if (ret) {
427 ath10k_warn(ar, "failed to fill fw stats: %d\n", ret);
428 goto err_free;
429 }
430
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200431 file->private_data = buf;
432
Kalle Valo5e3dd152013-06-12 20:52:10 +0300433 mutex_unlock(&ar->conf_mutex);
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200434 return 0;
435
436err_free:
437 vfree(buf);
438
439err_unlock:
440 mutex_unlock(&ar->conf_mutex);
441 return ret;
442}
443
444static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
445{
446 vfree(file->private_data);
447
448 return 0;
449}
450
451static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
452 size_t count, loff_t *ppos)
453{
454 const char *buf = file->private_data;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +0200455 size_t len = strlen(buf);
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200456
457 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300458}
459
460static const struct file_operations fops_fw_stats = {
Michal Kaziorfb2e9c02014-09-25 12:33:49 +0200461 .open = ath10k_fw_stats_open,
462 .release = ath10k_fw_stats_release,
Michal Kazior60ef4012014-09-25 12:33:48 +0200463 .read = ath10k_fw_stats_read,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300464 .owner = THIS_MODULE,
465 .llseek = default_llseek,
466};
467
Ben Greearf51dbe72014-09-29 14:41:46 +0300468static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
469 char __user *user_buf,
470 size_t count, loff_t *ppos)
471{
472 struct ath10k *ar = file->private_data;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +0200473 int ret;
474 size_t len = 0, buf_len = 500;
Ben Greearf51dbe72014-09-29 14:41:46 +0300475 char *buf;
476
Ben Greearf51dbe72014-09-29 14:41:46 +0300477 buf = kmalloc(buf_len, GFP_KERNEL);
478 if (!buf)
479 return -ENOMEM;
480
481 spin_lock_bh(&ar->data_lock);
482
Ben Greearf51dbe72014-09-29 14:41:46 +0300483 len += scnprintf(buf + len, buf_len - len,
484 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
485 len += scnprintf(buf + len, buf_len - len,
486 "fw_warm_reset_counter\t\t%d\n",
487 ar->stats.fw_warm_reset_counter);
488 len += scnprintf(buf + len, buf_len - len,
489 "fw_cold_reset_counter\t\t%d\n",
490 ar->stats.fw_cold_reset_counter);
491
492 spin_unlock_bh(&ar->data_lock);
493
494 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
495
496 kfree(buf);
497
498 return ret;
499}
500
501static const struct file_operations fops_fw_reset_stats = {
502 .open = simple_open,
503 .read = ath10k_debug_fw_reset_stats_read,
504 .owner = THIS_MODULE,
505 .llseek = default_llseek,
506};
507
Ben Greeard5aebc72014-09-10 18:59:28 +0300508/* This is a clean assert crash in firmware. */
509static int ath10k_debug_fw_assert(struct ath10k *ar)
510{
511 struct wmi_vdev_install_key_cmd *cmd;
512 struct sk_buff *skb;
513
514 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
515 if (!skb)
516 return -ENOMEM;
517
518 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
519 memset(cmd, 0, sizeof(*cmd));
520
521 /* big enough number so that firmware asserts */
522 cmd->vdev_id = __cpu_to_le32(0x7ffe);
523
524 return ath10k_wmi_cmd_send(ar, skb,
525 ar->wmi.cmd->vdev_install_key_cmdid);
526}
527
Michal Kazior278c4a82013-07-22 14:08:51 +0200528static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
529 char __user *user_buf,
530 size_t count, loff_t *ppos)
531{
Kalle Valo75cb96d2014-09-14 12:50:44 +0300532 const char buf[] =
533 "To simulate firmware crash write one of the keywords to this file:\n"
534 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
535 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
Michal Kazior605cdba2014-10-28 10:34:37 +0100536 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
537 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
Marek Puzyniak8c656992014-03-21 17:46:56 +0200538
Michal Kazior278c4a82013-07-22 14:08:51 +0200539 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
540}
541
Marek Puzyniak8c656992014-03-21 17:46:56 +0200542/* Simulate firmware crash:
543 * 'soft': Call wmi command causing firmware hang. This firmware hang is
544 * recoverable by warm firmware reset.
545 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
546 * vdev id. This is hard firmware crash because it is recoverable only by cold
547 * firmware reset.
548 */
Michal Kazior278c4a82013-07-22 14:08:51 +0200549static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
550 const char __user *user_buf,
551 size_t count, loff_t *ppos)
552{
553 struct ath10k *ar = file->private_data;
Michael Meraa16703a2017-04-24 16:11:57 +0900554 char buf[32] = {0};
555 ssize_t rc;
Michal Kazior278c4a82013-07-22 14:08:51 +0200556 int ret;
557
Michael Meraa16703a2017-04-24 16:11:57 +0900558 /* filter partial writes and invalid commands */
559 if (*ppos != 0 || count >= sizeof(buf) || count == 0)
560 return -EINVAL;
Marek Puzyniak8c656992014-03-21 17:46:56 +0200561
Michael Meraa16703a2017-04-24 16:11:57 +0900562 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
563 if (rc < 0)
564 return rc;
Michal Kazior278c4a82013-07-22 14:08:51 +0200565
Mohammed Shafi Shajakhanf5e30752016-05-28 11:25:41 +0300566 /* drop the possible '\n' from the end */
Michael Meraa16703a2017-04-24 16:11:57 +0900567 if (buf[*ppos - 1] == '\n')
568 buf[*ppos - 1] = '\0';
Mohammed Shafi Shajakhanf5e30752016-05-28 11:25:41 +0300569
570 mutex_lock(&ar->conf_mutex);
571
Michal Kazior278c4a82013-07-22 14:08:51 +0200572 if (ar->state != ATH10K_STATE_ON &&
573 ar->state != ATH10K_STATE_RESTARTED) {
574 ret = -ENETDOWN;
575 goto exit;
576 }
577
Marek Puzyniak8c656992014-03-21 17:46:56 +0200578 if (!strcmp(buf, "soft")) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200579 ath10k_info(ar, "simulating soft firmware crash\n");
Marek Puzyniak8c656992014-03-21 17:46:56 +0200580 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
581 } else if (!strcmp(buf, "hard")) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200582 ath10k_info(ar, "simulating hard firmware crash\n");
Ben Greear611b3682014-07-25 11:56:40 +0300583 /* 0x7fff is vdev id, and it is always out of range for all
584 * firmware variants in order to force a firmware crash.
585 */
586 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
Kalle Valo5b07e072014-09-14 12:50:06 +0300587 ar->wmi.vdev_param->rts_threshold,
588 0);
Ben Greeard5aebc72014-09-10 18:59:28 +0300589 } else if (!strcmp(buf, "assert")) {
590 ath10k_info(ar, "simulating firmware assert crash\n");
591 ret = ath10k_debug_fw_assert(ar);
Michal Kazior605cdba2014-10-28 10:34:37 +0100592 } else if (!strcmp(buf, "hw-restart")) {
593 ath10k_info(ar, "user requested hw restart\n");
594 queue_work(ar->workqueue, &ar->restart_work);
595 ret = 0;
Marek Puzyniak8c656992014-03-21 17:46:56 +0200596 } else {
597 ret = -EINVAL;
598 goto exit;
599 }
Michal Kazior278c4a82013-07-22 14:08:51 +0200600
Marek Puzyniak8c656992014-03-21 17:46:56 +0200601 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200602 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
Marek Puzyniak8c656992014-03-21 17:46:56 +0200603 goto exit;
604 }
605
606 ret = count;
Michal Kazior278c4a82013-07-22 14:08:51 +0200607
608exit:
609 mutex_unlock(&ar->conf_mutex);
610 return ret;
611}
612
613static const struct file_operations fops_simulate_fw_crash = {
614 .read = ath10k_read_simulate_fw_crash,
615 .write = ath10k_write_simulate_fw_crash,
616 .open = simple_open,
617 .owner = THIS_MODULE,
618 .llseek = default_llseek,
619};
620
Kalle Valo763b8cd2013-09-01 11:22:21 +0300621static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
622 size_t count, loff_t *ppos)
623{
624 struct ath10k *ar = file->private_data;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +0200625 size_t len;
Kalle Valo763b8cd2013-09-01 11:22:21 +0300626 char buf[50];
627
628 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
629
630 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
631}
632
633static const struct file_operations fops_chip_id = {
634 .read = ath10k_read_chip_id,
635 .open = simple_open,
636 .owner = THIS_MODULE,
637 .llseek = default_llseek,
638};
639
Yanbo Li077a3802014-11-25 12:24:33 +0200640static ssize_t ath10k_reg_addr_read(struct file *file,
641 char __user *user_buf,
642 size_t count, loff_t *ppos)
643{
644 struct ath10k *ar = file->private_data;
645 u8 buf[32];
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +0200646 size_t len = 0;
Yanbo Li077a3802014-11-25 12:24:33 +0200647 u32 reg_addr;
648
649 mutex_lock(&ar->conf_mutex);
650 reg_addr = ar->debug.reg_addr;
651 mutex_unlock(&ar->conf_mutex);
652
653 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr);
654
655 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
656}
657
658static ssize_t ath10k_reg_addr_write(struct file *file,
659 const char __user *user_buf,
660 size_t count, loff_t *ppos)
661{
662 struct ath10k *ar = file->private_data;
663 u32 reg_addr;
664 int ret;
665
666 ret = kstrtou32_from_user(user_buf, count, 0, &reg_addr);
667 if (ret)
668 return ret;
669
670 if (!IS_ALIGNED(reg_addr, 4))
671 return -EFAULT;
672
673 mutex_lock(&ar->conf_mutex);
674 ar->debug.reg_addr = reg_addr;
675 mutex_unlock(&ar->conf_mutex);
676
677 return count;
678}
679
680static const struct file_operations fops_reg_addr = {
681 .read = ath10k_reg_addr_read,
682 .write = ath10k_reg_addr_write,
683 .open = simple_open,
684 .owner = THIS_MODULE,
685 .llseek = default_llseek,
686};
687
688static ssize_t ath10k_reg_value_read(struct file *file,
689 char __user *user_buf,
690 size_t count, loff_t *ppos)
691{
692 struct ath10k *ar = file->private_data;
693 u8 buf[48];
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +0200694 size_t len;
Yanbo Li077a3802014-11-25 12:24:33 +0200695 u32 reg_addr, reg_val;
696 int ret;
697
698 mutex_lock(&ar->conf_mutex);
699
700 if (ar->state != ATH10K_STATE_ON &&
701 ar->state != ATH10K_STATE_UTF) {
702 ret = -ENETDOWN;
703 goto exit;
704 }
705
706 reg_addr = ar->debug.reg_addr;
707
708 reg_val = ath10k_hif_read32(ar, reg_addr);
709 len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val);
710
711 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
712
713exit:
714 mutex_unlock(&ar->conf_mutex);
715
716 return ret;
717}
718
719static ssize_t ath10k_reg_value_write(struct file *file,
720 const char __user *user_buf,
721 size_t count, loff_t *ppos)
722{
723 struct ath10k *ar = file->private_data;
724 u32 reg_addr, reg_val;
725 int ret;
726
727 mutex_lock(&ar->conf_mutex);
728
729 if (ar->state != ATH10K_STATE_ON &&
730 ar->state != ATH10K_STATE_UTF) {
731 ret = -ENETDOWN;
732 goto exit;
733 }
734
735 reg_addr = ar->debug.reg_addr;
736
737 ret = kstrtou32_from_user(user_buf, count, 0, &reg_val);
738 if (ret)
739 goto exit;
740
741 ath10k_hif_write32(ar, reg_addr, reg_val);
742
743 ret = count;
744
745exit:
746 mutex_unlock(&ar->conf_mutex);
747
748 return ret;
749}
750
751static const struct file_operations fops_reg_value = {
752 .read = ath10k_reg_value_read,
753 .write = ath10k_reg_value_write,
754 .open = simple_open,
755 .owner = THIS_MODULE,
756 .llseek = default_llseek,
757};
758
Yanbo Li9f65ad22014-11-25 12:24:48 +0200759static ssize_t ath10k_mem_value_read(struct file *file,
760 char __user *user_buf,
761 size_t count, loff_t *ppos)
762{
763 struct ath10k *ar = file->private_data;
764 u8 *buf;
765 int ret;
766
767 if (*ppos < 0)
768 return -EINVAL;
769
770 if (!count)
771 return 0;
772
773 mutex_lock(&ar->conf_mutex);
774
775 buf = vmalloc(count);
776 if (!buf) {
777 ret = -ENOMEM;
778 goto exit;
779 }
780
781 if (ar->state != ATH10K_STATE_ON &&
782 ar->state != ATH10K_STATE_UTF) {
783 ret = -ENETDOWN;
784 goto exit;
785 }
786
787 ret = ath10k_hif_diag_read(ar, *ppos, buf, count);
788 if (ret) {
789 ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
790 (u32)(*ppos), ret);
791 goto exit;
792 }
793
794 ret = copy_to_user(user_buf, buf, count);
795 if (ret) {
796 ret = -EFAULT;
797 goto exit;
798 }
799
800 count -= ret;
801 *ppos += count;
802 ret = count;
803
804exit:
805 vfree(buf);
806 mutex_unlock(&ar->conf_mutex);
807
808 return ret;
809}
810
811static ssize_t ath10k_mem_value_write(struct file *file,
812 const char __user *user_buf,
813 size_t count, loff_t *ppos)
814{
815 struct ath10k *ar = file->private_data;
816 u8 *buf;
817 int ret;
818
819 if (*ppos < 0)
820 return -EINVAL;
821
822 if (!count)
823 return 0;
824
825 mutex_lock(&ar->conf_mutex);
826
827 buf = vmalloc(count);
828 if (!buf) {
829 ret = -ENOMEM;
830 goto exit;
831 }
832
833 if (ar->state != ATH10K_STATE_ON &&
834 ar->state != ATH10K_STATE_UTF) {
835 ret = -ENETDOWN;
836 goto exit;
837 }
838
839 ret = copy_from_user(buf, user_buf, count);
840 if (ret) {
841 ret = -EFAULT;
842 goto exit;
843 }
844
845 ret = ath10k_hif_diag_write(ar, *ppos, buf, count);
846 if (ret) {
847 ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
848 (u32)(*ppos), ret);
849 goto exit;
850 }
851
852 *ppos += count;
853 ret = count;
854
855exit:
856 vfree(buf);
857 mutex_unlock(&ar->conf_mutex);
858
859 return ret;
860}
861
862static const struct file_operations fops_mem_value = {
863 .read = ath10k_mem_value_read,
864 .write = ath10k_mem_value_write,
865 .open = simple_open,
866 .owner = THIS_MODULE,
867 .llseek = default_llseek,
868};
869
Kalle Valoa3d135e2013-09-03 11:44:10 +0300870static int ath10k_debug_htt_stats_req(struct ath10k *ar)
871{
872 u64 cookie;
873 int ret;
874
875 lockdep_assert_held(&ar->conf_mutex);
876
877 if (ar->debug.htt_stats_mask == 0)
878 /* htt stats are disabled */
879 return 0;
880
881 if (ar->state != ATH10K_STATE_ON)
882 return 0;
883
884 cookie = get_jiffies_64();
885
886 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
887 cookie);
888 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200889 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
Kalle Valoa3d135e2013-09-03 11:44:10 +0300890 return ret;
891 }
892
893 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
894 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
895
896 return 0;
897}
898
899static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
900{
901 struct ath10k *ar = container_of(work, struct ath10k,
902 debug.htt_stats_dwork.work);
903
904 mutex_lock(&ar->conf_mutex);
905
906 ath10k_debug_htt_stats_req(ar);
907
908 mutex_unlock(&ar->conf_mutex);
909}
910
911static ssize_t ath10k_read_htt_stats_mask(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +0300912 char __user *user_buf,
913 size_t count, loff_t *ppos)
Kalle Valoa3d135e2013-09-03 11:44:10 +0300914{
915 struct ath10k *ar = file->private_data;
916 char buf[32];
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +0200917 size_t len;
Kalle Valoa3d135e2013-09-03 11:44:10 +0300918
919 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
920
921 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
922}
923
924static ssize_t ath10k_write_htt_stats_mask(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +0300925 const char __user *user_buf,
926 size_t count, loff_t *ppos)
Kalle Valoa3d135e2013-09-03 11:44:10 +0300927{
928 struct ath10k *ar = file->private_data;
929 unsigned long mask;
930 int ret;
931
932 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
933 if (ret)
934 return ret;
935
936 /* max 8 bit masks (for now) */
937 if (mask > 0xff)
938 return -E2BIG;
939
940 mutex_lock(&ar->conf_mutex);
941
942 ar->debug.htt_stats_mask = mask;
943
944 ret = ath10k_debug_htt_stats_req(ar);
945 if (ret)
946 goto out;
947
948 ret = count;
949
950out:
951 mutex_unlock(&ar->conf_mutex);
952
953 return ret;
954}
955
956static const struct file_operations fops_htt_stats_mask = {
957 .read = ath10k_read_htt_stats_mask,
958 .write = ath10k_write_htt_stats_mask,
959 .open = simple_open,
960 .owner = THIS_MODULE,
961 .llseek = default_llseek,
962};
963
Janusz Dziedzicd3856232014-06-02 21:19:46 +0300964static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
965 char __user *user_buf,
966 size_t count, loff_t *ppos)
967{
968 struct ath10k *ar = file->private_data;
969 char buf[64];
Mohammed Shafi Shajakhan81ec3c02015-11-30 22:29:39 +0530970 u8 amsdu, ampdu;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +0200971 size_t len;
Janusz Dziedzicd3856232014-06-02 21:19:46 +0300972
973 mutex_lock(&ar->conf_mutex);
974
David Liuccec9032015-07-24 20:25:32 +0300975 amsdu = ar->htt.max_num_amsdu;
976 ampdu = ar->htt.max_num_ampdu;
Janusz Dziedzicd3856232014-06-02 21:19:46 +0300977 mutex_unlock(&ar->conf_mutex);
978
979 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
980
981 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
982}
983
984static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
985 const char __user *user_buf,
986 size_t count, loff_t *ppos)
987{
988 struct ath10k *ar = file->private_data;
989 int res;
990 char buf[64];
991 unsigned int amsdu, ampdu;
992
993 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
994
995 /* make sure that buf is null terminated */
996 buf[sizeof(buf) - 1] = 0;
997
998 res = sscanf(buf, "%u %u", &amsdu, &ampdu);
999
1000 if (res != 2)
1001 return -EINVAL;
1002
1003 mutex_lock(&ar->conf_mutex);
1004
1005 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1006 if (res)
1007 goto out;
1008
1009 res = count;
David Liuccec9032015-07-24 20:25:32 +03001010 ar->htt.max_num_amsdu = amsdu;
1011 ar->htt.max_num_ampdu = ampdu;
Janusz Dziedzicd3856232014-06-02 21:19:46 +03001012
1013out:
1014 mutex_unlock(&ar->conf_mutex);
1015 return res;
1016}
1017
1018static const struct file_operations fops_htt_max_amsdu_ampdu = {
1019 .read = ath10k_read_htt_max_amsdu_ampdu,
1020 .write = ath10k_write_htt_max_amsdu_ampdu,
1021 .open = simple_open,
1022 .owner = THIS_MODULE,
1023 .llseek = default_llseek,
1024};
1025
Kalle Valof118a3e2014-01-03 12:59:31 +02001026static ssize_t ath10k_read_fw_dbglog(struct file *file,
Kalle Valo5b07e072014-09-14 12:50:06 +03001027 char __user *user_buf,
1028 size_t count, loff_t *ppos)
Kalle Valof118a3e2014-01-03 12:59:31 +02001029{
1030 struct ath10k *ar = file->private_data;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001031 size_t len;
Maharaja Kennadyrajanafcbc822016-08-23 15:35:36 +05301032 char buf[96];
Kalle Valof118a3e2014-01-03 12:59:31 +02001033
Maharaja Kennadyrajanafcbc822016-08-23 15:35:36 +05301034 len = scnprintf(buf, sizeof(buf), "0x%16llx %u\n",
SenthilKumar Jegadeesan467210a2015-01-29 14:36:52 +05301035 ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level);
Kalle Valof118a3e2014-01-03 12:59:31 +02001036
1037 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1038}
1039
1040static ssize_t ath10k_write_fw_dbglog(struct file *file,
1041 const char __user *user_buf,
1042 size_t count, loff_t *ppos)
1043{
1044 struct ath10k *ar = file->private_data;
Kalle Valof118a3e2014-01-03 12:59:31 +02001045 int ret;
Maharaja Kennadyrajanafcbc822016-08-23 15:35:36 +05301046 char buf[96];
1047 unsigned int log_level;
1048 u64 mask;
Kalle Valof118a3e2014-01-03 12:59:31 +02001049
SenthilKumar Jegadeesan467210a2015-01-29 14:36:52 +05301050 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1051
1052 /* make sure that buf is null terminated */
1053 buf[sizeof(buf) - 1] = 0;
1054
Maharaja Kennadyrajanafcbc822016-08-23 15:35:36 +05301055 ret = sscanf(buf, "%llx %u", &mask, &log_level);
SenthilKumar Jegadeesan467210a2015-01-29 14:36:52 +05301056
1057 if (!ret)
1058 return -EINVAL;
1059
1060 if (ret == 1)
1061 /* default if user did not specify */
1062 log_level = ATH10K_DBGLOG_LEVEL_WARN;
Kalle Valof118a3e2014-01-03 12:59:31 +02001063
1064 mutex_lock(&ar->conf_mutex);
1065
1066 ar->debug.fw_dbglog_mask = mask;
SenthilKumar Jegadeesan467210a2015-01-29 14:36:52 +05301067 ar->debug.fw_dbglog_level = log_level;
Kalle Valof118a3e2014-01-03 12:59:31 +02001068
1069 if (ar->state == ATH10K_STATE_ON) {
SenthilKumar Jegadeesan467210a2015-01-29 14:36:52 +05301070 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1071 ar->debug.fw_dbglog_level);
Kalle Valof118a3e2014-01-03 12:59:31 +02001072 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001073 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
Kalle Valof118a3e2014-01-03 12:59:31 +02001074 ret);
1075 goto exit;
1076 }
1077 }
1078
1079 ret = count;
1080
1081exit:
1082 mutex_unlock(&ar->conf_mutex);
1083
1084 return ret;
1085}
1086
Ben Greear6cddcc72014-09-29 14:41:46 +03001087/* TODO: Would be nice to always support ethtool stats, would need to
1088 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1089 * struct available..
1090 */
1091
1092/* This generally cooresponds to the debugfs fw_stats file */
1093static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1094 "tx_pkts_nic",
1095 "tx_bytes_nic",
1096 "rx_pkts_nic",
1097 "rx_bytes_nic",
1098 "d_noise_floor",
1099 "d_cycle_count",
1100 "d_phy_error",
1101 "d_rts_bad",
1102 "d_rts_good",
1103 "d_tx_power", /* in .5 dbM I think */
1104 "d_rx_crc_err", /* fcs_bad */
1105 "d_no_beacon",
1106 "d_tx_mpdus_queued",
1107 "d_tx_msdu_queued",
1108 "d_tx_msdu_dropped",
1109 "d_local_enqued",
1110 "d_local_freed",
1111 "d_tx_ppdu_hw_queued",
1112 "d_tx_ppdu_reaped",
1113 "d_tx_fifo_underrun",
1114 "d_tx_ppdu_abort",
1115 "d_tx_mpdu_requed",
1116 "d_tx_excessive_retries",
1117 "d_tx_hw_rate",
1118 "d_tx_dropped_sw_retries",
1119 "d_tx_illegal_rate",
1120 "d_tx_continuous_xretries",
1121 "d_tx_timeout",
1122 "d_tx_mpdu_txop_limit",
1123 "d_pdev_resets",
1124 "d_rx_mid_ppdu_route_change",
1125 "d_rx_status",
1126 "d_rx_extra_frags_ring0",
1127 "d_rx_extra_frags_ring1",
1128 "d_rx_extra_frags_ring2",
1129 "d_rx_extra_frags_ring3",
1130 "d_rx_msdu_htt",
1131 "d_rx_mpdu_htt",
1132 "d_rx_msdu_stack",
1133 "d_rx_mpdu_stack",
1134 "d_rx_phy_err",
1135 "d_rx_phy_err_drops",
1136 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1137 "d_fw_crash_count",
1138 "d_fw_warm_reset_count",
1139 "d_fw_cold_reset_count",
1140};
1141
1142#define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1143
1144void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1145 struct ieee80211_vif *vif,
1146 u32 sset, u8 *data)
1147{
1148 if (sset == ETH_SS_STATS)
1149 memcpy(data, *ath10k_gstrings_stats,
1150 sizeof(ath10k_gstrings_stats));
1151}
1152
1153int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1154 struct ieee80211_vif *vif, int sset)
1155{
1156 if (sset == ETH_SS_STATS)
1157 return ATH10K_SSTATS_LEN;
1158
1159 return 0;
1160}
1161
1162void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1163 struct ieee80211_vif *vif,
1164 struct ethtool_stats *stats, u64 *data)
1165{
1166 struct ath10k *ar = hw->priv;
1167 static const struct ath10k_fw_stats_pdev zero_stats = {};
1168 const struct ath10k_fw_stats_pdev *pdev_stats;
1169 int i = 0, ret;
1170
1171 mutex_lock(&ar->conf_mutex);
1172
1173 if (ar->state == ATH10K_STATE_ON) {
1174 ret = ath10k_debug_fw_stats_request(ar);
1175 if (ret) {
1176 /* just print a warning and try to use older results */
1177 ath10k_warn(ar,
1178 "failed to get fw stats for ethtool: %d\n",
1179 ret);
1180 }
1181 }
1182
1183 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1184 struct ath10k_fw_stats_pdev,
1185 list);
1186 if (!pdev_stats) {
1187 /* no results available so just return zeroes */
1188 pdev_stats = &zero_stats;
1189 }
1190
1191 spin_lock_bh(&ar->data_lock);
1192
1193 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1194 data[i++] = 0; /* tx bytes */
1195 data[i++] = pdev_stats->htt_mpdus;
1196 data[i++] = 0; /* rx bytes */
1197 data[i++] = pdev_stats->ch_noise_floor;
1198 data[i++] = pdev_stats->cycle_count;
1199 data[i++] = pdev_stats->phy_err_count;
1200 data[i++] = pdev_stats->rts_bad;
1201 data[i++] = pdev_stats->rts_good;
1202 data[i++] = pdev_stats->chan_tx_power;
1203 data[i++] = pdev_stats->fcs_bad;
1204 data[i++] = pdev_stats->no_beacons;
1205 data[i++] = pdev_stats->mpdu_enqued;
1206 data[i++] = pdev_stats->msdu_enqued;
1207 data[i++] = pdev_stats->wmm_drop;
1208 data[i++] = pdev_stats->local_enqued;
1209 data[i++] = pdev_stats->local_freed;
1210 data[i++] = pdev_stats->hw_queued;
1211 data[i++] = pdev_stats->hw_reaped;
1212 data[i++] = pdev_stats->underrun;
1213 data[i++] = pdev_stats->tx_abort;
1214 data[i++] = pdev_stats->mpdus_requed;
1215 data[i++] = pdev_stats->tx_ko;
1216 data[i++] = pdev_stats->data_rc;
1217 data[i++] = pdev_stats->sw_retry_failure;
1218 data[i++] = pdev_stats->illgl_rate_phy_err;
1219 data[i++] = pdev_stats->pdev_cont_xretry;
1220 data[i++] = pdev_stats->pdev_tx_timeout;
1221 data[i++] = pdev_stats->txop_ovf;
1222 data[i++] = pdev_stats->pdev_resets;
1223 data[i++] = pdev_stats->mid_ppdu_route_change;
1224 data[i++] = pdev_stats->status_rcvd;
1225 data[i++] = pdev_stats->r0_frags;
1226 data[i++] = pdev_stats->r1_frags;
1227 data[i++] = pdev_stats->r2_frags;
1228 data[i++] = pdev_stats->r3_frags;
1229 data[i++] = pdev_stats->htt_msdus;
1230 data[i++] = pdev_stats->htt_mpdus;
1231 data[i++] = pdev_stats->loc_msdus;
1232 data[i++] = pdev_stats->loc_mpdus;
1233 data[i++] = pdev_stats->phy_errs;
1234 data[i++] = pdev_stats->phy_err_drop;
1235 data[i++] = pdev_stats->mpdu_errs;
1236 data[i++] = ar->stats.fw_crash_counter;
1237 data[i++] = ar->stats.fw_warm_reset_counter;
1238 data[i++] = ar->stats.fw_cold_reset_counter;
1239
1240 spin_unlock_bh(&ar->data_lock);
1241
1242 mutex_unlock(&ar->conf_mutex);
1243
1244 WARN_ON(i != ATH10K_SSTATS_LEN);
1245}
1246
Kalle Valof118a3e2014-01-03 12:59:31 +02001247static const struct file_operations fops_fw_dbglog = {
1248 .read = ath10k_read_fw_dbglog,
1249 .write = ath10k_write_fw_dbglog,
1250 .open = simple_open,
1251 .owner = THIS_MODULE,
1252 .llseek = default_llseek,
1253};
1254
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001255static int ath10k_debug_cal_data_fetch(struct ath10k *ar)
Kalle Valo7869b4f2014-09-24 14:16:58 +03001256{
Kalle Valo7869b4f2014-09-24 14:16:58 +03001257 u32 hi_addr;
1258 __le32 addr;
1259 int ret;
1260
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001261 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo7869b4f2014-09-24 14:16:58 +03001262
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001263 if (WARN_ON(ar->hw_params.cal_data_len > ATH10K_DEBUG_CAL_DATA_LEN))
1264 return -EINVAL;
Kalle Valo7869b4f2014-09-24 14:16:58 +03001265
1266 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1267
1268 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1269 if (ret) {
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001270 ath10k_warn(ar, "failed to read hi_board_data address: %d\n",
1271 ret);
1272 return ret;
Kalle Valo7869b4f2014-09-24 14:16:58 +03001273 }
1274
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001275 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), ar->debug.cal_data,
Raja Mani0b8e3c42016-03-18 11:44:22 +02001276 ar->hw_params.cal_data_len);
Kalle Valo7869b4f2014-09-24 14:16:58 +03001277 if (ret) {
1278 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001279 return ret;
Kalle Valo7869b4f2014-09-24 14:16:58 +03001280 }
1281
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001282 return 0;
1283}
Kalle Valo7869b4f2014-09-24 14:16:58 +03001284
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001285static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1286{
1287 struct ath10k *ar = inode->i_private;
1288
1289 mutex_lock(&ar->conf_mutex);
1290
1291 if (ar->state == ATH10K_STATE_ON ||
1292 ar->state == ATH10K_STATE_UTF) {
1293 ath10k_debug_cal_data_fetch(ar);
1294 }
1295
1296 file->private_data = ar;
Kalle Valo7869b4f2014-09-24 14:16:58 +03001297 mutex_unlock(&ar->conf_mutex);
1298
1299 return 0;
Kalle Valo7869b4f2014-09-24 14:16:58 +03001300}
1301
1302static ssize_t ath10k_debug_cal_data_read(struct file *file,
1303 char __user *user_buf,
1304 size_t count, loff_t *ppos)
1305{
Raja Mani0b8e3c42016-03-18 11:44:22 +02001306 struct ath10k *ar = file->private_data;
Kalle Valo7869b4f2014-09-24 14:16:58 +03001307
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001308 mutex_lock(&ar->conf_mutex);
Kalle Valo7869b4f2014-09-24 14:16:58 +03001309
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001310 count = simple_read_from_buffer(user_buf, count, ppos,
1311 ar->debug.cal_data,
1312 ar->hw_params.cal_data_len);
Kalle Valo7869b4f2014-09-24 14:16:58 +03001313
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001314 mutex_unlock(&ar->conf_mutex);
1315
1316 return count;
Kalle Valo7869b4f2014-09-24 14:16:58 +03001317}
1318
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05301319static ssize_t ath10k_write_ani_enable(struct file *file,
1320 const char __user *user_buf,
1321 size_t count, loff_t *ppos)
1322{
1323 struct ath10k *ar = file->private_data;
1324 int ret;
1325 u8 enable;
1326
1327 if (kstrtou8_from_user(user_buf, count, 0, &enable))
1328 return -EINVAL;
1329
1330 mutex_lock(&ar->conf_mutex);
1331
1332 if (ar->ani_enabled == enable) {
1333 ret = count;
1334 goto exit;
1335 }
1336
1337 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable,
1338 enable);
1339 if (ret) {
1340 ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret);
1341 goto exit;
1342 }
1343 ar->ani_enabled = enable;
1344
1345 ret = count;
1346
1347exit:
1348 mutex_unlock(&ar->conf_mutex);
1349
1350 return ret;
1351}
1352
1353static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf,
1354 size_t count, loff_t *ppos)
1355{
1356 struct ath10k *ar = file->private_data;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001357 size_t len;
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05301358 char buf[32];
1359
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001360 len = scnprintf(buf, sizeof(buf), "%d\n", ar->ani_enabled);
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05301361
1362 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1363}
1364
1365static const struct file_operations fops_ani_enable = {
1366 .read = ath10k_read_ani_enable,
1367 .write = ath10k_write_ani_enable,
1368 .open = simple_open,
1369 .owner = THIS_MODULE,
1370 .llseek = default_llseek,
1371};
1372
Kalle Valo7869b4f2014-09-24 14:16:58 +03001373static const struct file_operations fops_cal_data = {
1374 .open = ath10k_debug_cal_data_open,
1375 .read = ath10k_debug_cal_data_read,
Kalle Valo7869b4f2014-09-24 14:16:58 +03001376 .owner = THIS_MODULE,
1377 .llseek = default_llseek,
1378};
1379
Peter Oha7bd3e92014-12-02 13:07:14 +02001380static ssize_t ath10k_read_nf_cal_period(struct file *file,
1381 char __user *user_buf,
1382 size_t count, loff_t *ppos)
1383{
1384 struct ath10k *ar = file->private_data;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001385 size_t len;
Peter Oha7bd3e92014-12-02 13:07:14 +02001386 char buf[32];
1387
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001388 len = scnprintf(buf, sizeof(buf), "%d\n", ar->debug.nf_cal_period);
Peter Oha7bd3e92014-12-02 13:07:14 +02001389
1390 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1391}
1392
1393static ssize_t ath10k_write_nf_cal_period(struct file *file,
1394 const char __user *user_buf,
1395 size_t count, loff_t *ppos)
1396{
1397 struct ath10k *ar = file->private_data;
1398 unsigned long period;
1399 int ret;
1400
1401 ret = kstrtoul_from_user(user_buf, count, 0, &period);
1402 if (ret)
1403 return ret;
1404
1405 if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX)
1406 return -EINVAL;
1407
1408 /* there's no way to switch back to the firmware default */
1409 if (period == 0)
1410 return -EINVAL;
1411
1412 mutex_lock(&ar->conf_mutex);
1413
1414 ar->debug.nf_cal_period = period;
1415
1416 if (ar->state != ATH10K_STATE_ON) {
1417 /* firmware is not running, nothing else to do */
1418 ret = count;
1419 goto exit;
1420 }
1421
1422 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period,
1423 ar->debug.nf_cal_period);
1424 if (ret) {
1425 ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n",
1426 ret);
1427 goto exit;
1428 }
1429
1430 ret = count;
1431
1432exit:
1433 mutex_unlock(&ar->conf_mutex);
1434
1435 return ret;
1436}
1437
1438static const struct file_operations fops_nf_cal_period = {
1439 .read = ath10k_read_nf_cal_period,
1440 .write = ath10k_write_nf_cal_period,
1441 .open = simple_open,
1442 .owner = THIS_MODULE,
1443 .llseek = default_llseek,
1444};
1445
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03001446#define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1447
1448static int ath10k_debug_tpc_stats_request(struct ath10k *ar)
1449{
1450 int ret;
1451 unsigned long time_left;
1452
1453 lockdep_assert_held(&ar->conf_mutex);
1454
1455 reinit_completion(&ar->debug.tpc_complete);
1456
1457 ret = ath10k_wmi_pdev_get_tpc_config(ar, WMI_TPC_CONFIG_PARAM);
1458 if (ret) {
1459 ath10k_warn(ar, "failed to request tpc config: %d\n", ret);
1460 return ret;
1461 }
1462
1463 time_left = wait_for_completion_timeout(&ar->debug.tpc_complete,
1464 1 * HZ);
1465 if (time_left == 0)
1466 return -ETIMEDOUT;
1467
1468 return 0;
1469}
1470
1471void ath10k_debug_tpc_stats_process(struct ath10k *ar,
1472 struct ath10k_tpc_stats *tpc_stats)
1473{
1474 spin_lock_bh(&ar->data_lock);
1475
1476 kfree(ar->debug.tpc_stats);
1477 ar->debug.tpc_stats = tpc_stats;
1478 complete(&ar->debug.tpc_complete);
1479
1480 spin_unlock_bh(&ar->data_lock);
1481}
1482
1483static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats,
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001484 unsigned int j, char *buf, size_t *len)
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03001485{
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001486 int i;
1487 size_t buf_len;
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03001488 static const char table_str[][5] = { "CDD",
1489 "STBC",
1490 "TXBF" };
1491 static const char pream_str[][6] = { "CCK",
1492 "OFDM",
1493 "HT20",
1494 "HT40",
1495 "VHT20",
1496 "VHT40",
1497 "VHT80",
1498 "HTCUP" };
1499
1500 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1501 *len += scnprintf(buf + *len, buf_len - *len,
1502 "********************************\n");
1503 *len += scnprintf(buf + *len, buf_len - *len,
1504 "******************* %s POWER TABLE ****************\n",
1505 table_str[j]);
1506 *len += scnprintf(buf + *len, buf_len - *len,
1507 "********************************\n");
1508 *len += scnprintf(buf + *len, buf_len - *len,
1509 "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n");
1510
1511 for (i = 0; i < tpc_stats->rate_max; i++) {
1512 *len += scnprintf(buf + *len, buf_len - *len,
1513 "%8d %s 0x%2x %s\n", i,
1514 pream_str[tpc_stats->tpc_table[j].pream_idx[i]],
1515 tpc_stats->tpc_table[j].rate_code[i],
1516 tpc_stats->tpc_table[j].tpc_value[i]);
1517 }
1518
1519 *len += scnprintf(buf + *len, buf_len - *len,
1520 "***********************************\n");
1521}
1522
1523static void ath10k_tpc_stats_fill(struct ath10k *ar,
1524 struct ath10k_tpc_stats *tpc_stats,
1525 char *buf)
1526{
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001527 int j;
1528 size_t len, buf_len;
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03001529
1530 len = 0;
1531 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1532
1533 spin_lock_bh(&ar->data_lock);
1534
1535 if (!tpc_stats) {
1536 ath10k_warn(ar, "failed to get tpc stats\n");
1537 goto unlock;
1538 }
1539
1540 len += scnprintf(buf + len, buf_len - len, "\n");
1541 len += scnprintf(buf + len, buf_len - len,
1542 "*************************************\n");
1543 len += scnprintf(buf + len, buf_len - len,
1544 "TPC config for channel %4d mode %d\n",
1545 tpc_stats->chan_freq,
1546 tpc_stats->phy_mode);
1547 len += scnprintf(buf + len, buf_len - len,
1548 "*************************************\n");
1549 len += scnprintf(buf + len, buf_len - len,
1550 "CTL = 0x%2x Reg. Domain = %2d\n",
1551 tpc_stats->ctl,
1552 tpc_stats->reg_domain);
1553 len += scnprintf(buf + len, buf_len - len,
1554 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1555 tpc_stats->twice_antenna_gain,
1556 tpc_stats->twice_antenna_reduction);
1557 len += scnprintf(buf + len, buf_len - len,
1558 "Power Limit = %2d Reg. Max Power = %2d\n",
1559 tpc_stats->power_limit,
1560 tpc_stats->twice_max_rd_power / 2);
1561 len += scnprintf(buf + len, buf_len - len,
1562 "Num tx chains = %2d Num supported rates = %2d\n",
1563 tpc_stats->num_tx_chain,
1564 tpc_stats->rate_max);
1565
Maharaja Kennadyrajane871fb62017-03-31 17:39:40 +05301566 for (j = 0; j < WMI_TPC_FLAG; j++) {
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03001567 switch (j) {
1568 case WMI_TPC_TABLE_TYPE_CDD:
1569 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1570 len += scnprintf(buf + len, buf_len - len,
1571 "CDD not supported\n");
1572 break;
1573 }
1574
1575 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1576 break;
1577 case WMI_TPC_TABLE_TYPE_STBC:
1578 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1579 len += scnprintf(buf + len, buf_len - len,
1580 "STBC not supported\n");
1581 break;
1582 }
1583
1584 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1585 break;
1586 case WMI_TPC_TABLE_TYPE_TXBF:
1587 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1588 len += scnprintf(buf + len, buf_len - len,
1589 "TXBF not supported\n***************************\n");
1590 break;
1591 }
1592
1593 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1594 break;
1595 default:
1596 len += scnprintf(buf + len, buf_len - len,
1597 "Invalid Type\n");
1598 break;
1599 }
1600 }
1601
1602unlock:
1603 spin_unlock_bh(&ar->data_lock);
1604
1605 if (len >= buf_len)
1606 buf[len - 1] = 0;
1607 else
1608 buf[len] = 0;
1609}
1610
1611static int ath10k_tpc_stats_open(struct inode *inode, struct file *file)
1612{
1613 struct ath10k *ar = inode->i_private;
1614 void *buf = NULL;
1615 int ret;
1616
1617 mutex_lock(&ar->conf_mutex);
1618
1619 if (ar->state != ATH10K_STATE_ON) {
1620 ret = -ENETDOWN;
1621 goto err_unlock;
1622 }
1623
1624 buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE);
1625 if (!buf) {
1626 ret = -ENOMEM;
1627 goto err_unlock;
1628 }
1629
1630 ret = ath10k_debug_tpc_stats_request(ar);
1631 if (ret) {
1632 ath10k_warn(ar, "failed to request tpc config stats: %d\n",
1633 ret);
1634 goto err_free;
1635 }
1636
1637 ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf);
1638 file->private_data = buf;
1639
1640 mutex_unlock(&ar->conf_mutex);
1641 return 0;
1642
1643err_free:
1644 vfree(buf);
1645
1646err_unlock:
1647 mutex_unlock(&ar->conf_mutex);
1648 return ret;
1649}
1650
1651static int ath10k_tpc_stats_release(struct inode *inode, struct file *file)
1652{
1653 vfree(file->private_data);
1654
1655 return 0;
1656}
1657
1658static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf,
1659 size_t count, loff_t *ppos)
1660{
1661 const char *buf = file->private_data;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02001662 size_t len = strlen(buf);
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03001663
1664 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1665}
1666
1667static const struct file_operations fops_tpc_stats = {
1668 .open = ath10k_tpc_stats_open,
1669 .release = ath10k_tpc_stats_release,
1670 .read = ath10k_tpc_stats_read,
1671 .owner = THIS_MODULE,
1672 .llseek = default_llseek,
1673};
1674
Kalle Valodb66ea02013-09-03 11:44:03 +03001675int ath10k_debug_start(struct ath10k *ar)
1676{
Kalle Valoa3d135e2013-09-03 11:44:10 +03001677 int ret;
1678
Kalle Valo60631c52013-10-08 21:45:25 +03001679 lockdep_assert_held(&ar->conf_mutex);
1680
Kalle Valoa3d135e2013-09-03 11:44:10 +03001681 ret = ath10k_debug_htt_stats_req(ar);
1682 if (ret)
1683 /* continue normally anyway, this isn't serious */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001684 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1685 ret);
Kalle Valoa3d135e2013-09-03 11:44:10 +03001686
Kalle Valof118a3e2014-01-03 12:59:31 +02001687 if (ar->debug.fw_dbglog_mask) {
SenthilKumar Jegadeesan467210a2015-01-29 14:36:52 +05301688 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1689 ATH10K_DBGLOG_LEVEL_WARN);
Kalle Valof118a3e2014-01-03 12:59:31 +02001690 if (ret)
1691 /* not serious */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001692 ath10k_warn(ar, "failed to enable dbglog during start: %d",
Kalle Valof118a3e2014-01-03 12:59:31 +02001693 ret);
1694 }
1695
Anilkumar Kolli7f9befb2017-12-05 19:01:24 +05301696 if (ar->pktlog_filter) {
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001697 ret = ath10k_wmi_pdev_pktlog_enable(ar,
Anilkumar Kolli7f9befb2017-12-05 19:01:24 +05301698 ar->pktlog_filter);
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001699 if (ret)
1700 /* not serious */
1701 ath10k_warn(ar,
1702 "failed to enable pktlog filter %x: %d\n",
Anilkumar Kolli7f9befb2017-12-05 19:01:24 +05301703 ar->pktlog_filter, ret);
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001704 } else {
1705 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1706 if (ret)
1707 /* not serious */
1708 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1709 }
1710
Peter Oha7bd3e92014-12-02 13:07:14 +02001711 if (ar->debug.nf_cal_period) {
1712 ret = ath10k_wmi_pdev_set_param(ar,
1713 ar->wmi.pdev_param->cal_period,
1714 ar->debug.nf_cal_period);
1715 if (ret)
1716 /* not serious */
1717 ath10k_warn(ar, "cal period cfg failed from debug start: %d\n",
1718 ret);
1719 }
1720
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001721 return ret;
Kalle Valodb66ea02013-09-03 11:44:03 +03001722}
1723
1724void ath10k_debug_stop(struct ath10k *ar)
1725{
Kalle Valo60631c52013-10-08 21:45:25 +03001726 lockdep_assert_held(&ar->conf_mutex);
1727
Marty Faltesekf67b107d2016-10-10 19:00:04 +03001728 ath10k_debug_cal_data_fetch(ar);
1729
Kalle Valo60631c52013-10-08 21:45:25 +03001730 /* Must not use _sync to avoid deadlock, we do that in
1731 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
Marcin Rokickid6dfe25c2017-02-20 14:39:57 +01001732 * warning from del_timer().
1733 */
Kalle Valo60631c52013-10-08 21:45:25 +03001734 if (ar->debug.htt_stats_mask != 0)
1735 cancel_delayed_work(&ar->debug.htt_stats_dwork);
Janusz Dziedzicd3856232014-06-02 21:19:46 +03001736
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001737 ath10k_wmi_pdev_pktlog_disable(ar);
Kalle Valodb66ea02013-09-03 11:44:03 +03001738}
1739
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001740static ssize_t ath10k_write_simulate_radar(struct file *file,
1741 const char __user *user_buf,
1742 size_t count, loff_t *ppos)
1743{
1744 struct ath10k *ar = file->private_data;
Mohammed Shafi Shajakhanca07baa2017-02-22 21:03:11 +05301745 struct ath10k_vif *arvif;
1746
1747 /* Just check for for the first vif alone, as all the vifs will be
1748 * sharing the same channel and if the channel is disabled, all the
1749 * vifs will share the same 'is_started' state.
1750 */
1751 arvif = list_first_entry(&ar->arvifs, typeof(*arvif), list);
1752 if (!arvif->is_started)
1753 return -EINVAL;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001754
1755 ieee80211_radar_detected(ar->hw);
1756
1757 return count;
1758}
1759
1760static const struct file_operations fops_simulate_radar = {
1761 .write = ath10k_write_simulate_radar,
1762 .open = simple_open,
1763 .owner = THIS_MODULE,
1764 .llseek = default_llseek,
1765};
1766
1767#define ATH10K_DFS_STAT(s, p) (\
1768 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1769 ar->debug.dfs_stats.p))
1770
1771#define ATH10K_DFS_POOL_STAT(s, p) (\
1772 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1773 ar->debug.dfs_pool_stats.p))
1774
1775static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
1776 size_t count, loff_t *ppos)
1777{
1778 int retval = 0, len = 0;
1779 const int size = 8000;
1780 struct ath10k *ar = file->private_data;
1781 char *buf;
1782
1783 buf = kzalloc(size, GFP_KERNEL);
1784 if (buf == NULL)
1785 return -ENOMEM;
1786
1787 if (!ar->dfs_detector) {
1788 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
1789 goto exit;
1790 }
1791
1792 ar->debug.dfs_pool_stats =
1793 ar->dfs_detector->get_stats(ar->dfs_detector);
1794
1795 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
1796
1797 ATH10K_DFS_STAT("reported phy errors", phy_errors);
1798 ATH10K_DFS_STAT("pulse events reported", pulses_total);
1799 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
1800 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
1801 ATH10K_DFS_STAT("Radars detected", radar_detected);
1802
1803 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
1804 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
1805 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
1806 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
1807 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
1808 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
1809 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
1810 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
1811
1812exit:
1813 if (len > size)
1814 len = size;
1815
1816 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1817 kfree(buf);
1818
1819 return retval;
1820}
1821
1822static const struct file_operations fops_dfs_stats = {
1823 .read = ath10k_read_dfs_stats,
1824 .open = simple_open,
1825 .owner = THIS_MODULE,
1826 .llseek = default_llseek,
1827};
1828
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001829static ssize_t ath10k_write_pktlog_filter(struct file *file,
1830 const char __user *ubuf,
1831 size_t count, loff_t *ppos)
1832{
1833 struct ath10k *ar = file->private_data;
1834 u32 filter;
1835 int ret;
1836
1837 if (kstrtouint_from_user(ubuf, count, 0, &filter))
1838 return -EINVAL;
1839
1840 mutex_lock(&ar->conf_mutex);
1841
1842 if (ar->state != ATH10K_STATE_ON) {
Anilkumar Kolli7f9befb2017-12-05 19:01:24 +05301843 ar->pktlog_filter = filter;
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001844 ret = count;
1845 goto out;
1846 }
1847
Anilkumar Kolli7f9befb2017-12-05 19:01:24 +05301848 if (filter == ar->pktlog_filter) {
Anilkumar Kolli9ddc4862016-03-11 11:46:39 +05301849 ret = count;
1850 goto out;
1851 }
1852
1853 if (filter) {
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001854 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
1855 if (ret) {
1856 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
Anilkumar Kolli7f9befb2017-12-05 19:01:24 +05301857 ar->pktlog_filter, ret);
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001858 goto out;
1859 }
1860 } else {
1861 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1862 if (ret) {
1863 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1864 goto out;
1865 }
1866 }
1867
Anilkumar Kolli7f9befb2017-12-05 19:01:24 +05301868 ar->pktlog_filter = filter;
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001869 ret = count;
1870
1871out:
1872 mutex_unlock(&ar->conf_mutex);
1873 return ret;
1874}
1875
1876static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
1877 size_t count, loff_t *ppos)
1878{
1879 char buf[32];
1880 struct ath10k *ar = file->private_data;
1881 int len = 0;
1882
1883 mutex_lock(&ar->conf_mutex);
1884 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
Anilkumar Kolli7f9befb2017-12-05 19:01:24 +05301885 ar->pktlog_filter);
Rajkumar Manoharan90174452014-10-03 08:02:33 +03001886 mutex_unlock(&ar->conf_mutex);
1887
1888 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
1889}
1890
1891static const struct file_operations fops_pktlog_filter = {
1892 .read = ath10k_read_pktlog_filter,
1893 .write = ath10k_write_pktlog_filter,
1894 .open = simple_open
1895};
1896
Rajkumar Manoharan63fb32d2015-03-15 20:36:20 +05301897static ssize_t ath10k_write_quiet_period(struct file *file,
1898 const char __user *ubuf,
1899 size_t count, loff_t *ppos)
1900{
1901 struct ath10k *ar = file->private_data;
1902 u32 period;
1903
1904 if (kstrtouint_from_user(ubuf, count, 0, &period))
1905 return -EINVAL;
1906
1907 if (period < ATH10K_QUIET_PERIOD_MIN) {
1908 ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n",
1909 period);
1910 return -EINVAL;
1911 }
1912 mutex_lock(&ar->conf_mutex);
1913 ar->thermal.quiet_period = period;
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05301914 ath10k_thermal_set_throttling(ar);
Rajkumar Manoharan63fb32d2015-03-15 20:36:20 +05301915 mutex_unlock(&ar->conf_mutex);
1916
1917 return count;
1918}
1919
1920static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf,
1921 size_t count, loff_t *ppos)
1922{
1923 char buf[32];
1924 struct ath10k *ar = file->private_data;
1925 int len = 0;
1926
1927 mutex_lock(&ar->conf_mutex);
1928 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
1929 ar->thermal.quiet_period);
1930 mutex_unlock(&ar->conf_mutex);
1931
1932 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
1933}
1934
1935static const struct file_operations fops_quiet_period = {
1936 .read = ath10k_read_quiet_period,
1937 .write = ath10k_write_quiet_period,
1938 .open = simple_open
1939};
1940
Yanbo Li844fa572015-10-31 11:07:21 +02001941static ssize_t ath10k_write_btcoex(struct file *file,
1942 const char __user *ubuf,
1943 size_t count, loff_t *ppos)
1944{
1945 struct ath10k *ar = file->private_data;
1946 char buf[32];
1947 size_t buf_size;
Mohammed Shafi Shajakhan87be0542016-04-05 20:58:26 +05301948 int ret;
Yanbo Li844fa572015-10-31 11:07:21 +02001949 bool val;
Rajkumar Manoharan39136242016-05-27 20:15:59 +05301950 u32 pdev_param;
Yanbo Li844fa572015-10-31 11:07:21 +02001951
1952 buf_size = min(count, (sizeof(buf) - 1));
1953 if (copy_from_user(buf, ubuf, buf_size))
1954 return -EFAULT;
1955
1956 buf[buf_size] = '\0';
1957
1958 if (strtobool(buf, &val) != 0)
1959 return -EINVAL;
1960
1961 mutex_lock(&ar->conf_mutex);
1962
Mohammed Shafi Shajakhanc28e6f02016-02-23 12:58:36 +05301963 if (ar->state != ATH10K_STATE_ON &&
1964 ar->state != ATH10K_STATE_RESTARTED) {
1965 ret = -ENETDOWN;
1966 goto exit;
1967 }
1968
Mohammed Shafi Shajakhan87be0542016-04-05 20:58:26 +05301969 if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val)) {
1970 ret = count;
Yanbo Li844fa572015-10-31 11:07:21 +02001971 goto exit;
Mohammed Shafi Shajakhan87be0542016-04-05 20:58:26 +05301972 }
Yanbo Li844fa572015-10-31 11:07:21 +02001973
Rajkumar Manoharan39136242016-05-27 20:15:59 +05301974 pdev_param = ar->wmi.pdev_param->enable_btcoex;
1975 if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
1976 ar->running_fw->fw_file.fw_features)) {
1977 ret = ath10k_wmi_pdev_set_param(ar, pdev_param, val);
1978 if (ret) {
1979 ath10k_warn(ar, "failed to enable btcoex: %d\n", ret);
1980 ret = count;
1981 goto exit;
1982 }
1983 } else {
1984 ath10k_info(ar, "restarting firmware due to btcoex change");
1985 queue_work(ar->workqueue, &ar->restart_work);
1986 }
1987
Yanbo Li844fa572015-10-31 11:07:21 +02001988 if (val)
1989 set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
1990 else
1991 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
1992
Mohammed Shafi Shajakhanc28e6f02016-02-23 12:58:36 +05301993 ret = count;
Yanbo Li844fa572015-10-31 11:07:21 +02001994
1995exit:
1996 mutex_unlock(&ar->conf_mutex);
1997
Mohammed Shafi Shajakhanc28e6f02016-02-23 12:58:36 +05301998 return ret;
Yanbo Li844fa572015-10-31 11:07:21 +02001999}
2000
2001static ssize_t ath10k_read_btcoex(struct file *file, char __user *ubuf,
2002 size_t count, loff_t *ppos)
2003{
2004 char buf[32];
2005 struct ath10k *ar = file->private_data;
2006 int len = 0;
2007
2008 mutex_lock(&ar->conf_mutex);
2009 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2010 test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags));
2011 mutex_unlock(&ar->conf_mutex);
2012
2013 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2014}
2015
2016static const struct file_operations fops_btcoex = {
2017 .read = ath10k_read_btcoex,
2018 .write = ath10k_write_btcoex,
2019 .open = simple_open
2020};
2021
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +05302022static ssize_t ath10k_write_peer_stats(struct file *file,
2023 const char __user *ubuf,
2024 size_t count, loff_t *ppos)
2025{
2026 struct ath10k *ar = file->private_data;
2027 char buf[32];
2028 size_t buf_size;
Mohammed Shafi Shajakhan87be0542016-04-05 20:58:26 +05302029 int ret;
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +05302030 bool val;
2031
2032 buf_size = min(count, (sizeof(buf) - 1));
2033 if (copy_from_user(buf, ubuf, buf_size))
2034 return -EFAULT;
2035
2036 buf[buf_size] = '\0';
2037
2038 if (strtobool(buf, &val) != 0)
2039 return -EINVAL;
2040
2041 mutex_lock(&ar->conf_mutex);
2042
2043 if (ar->state != ATH10K_STATE_ON &&
2044 ar->state != ATH10K_STATE_RESTARTED) {
2045 ret = -ENETDOWN;
2046 goto exit;
2047 }
2048
Mohammed Shafi Shajakhan87be0542016-04-05 20:58:26 +05302049 if (!(test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags) ^ val)) {
2050 ret = count;
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +05302051 goto exit;
Mohammed Shafi Shajakhan87be0542016-04-05 20:58:26 +05302052 }
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +05302053
2054 if (val)
2055 set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2056 else
2057 clear_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2058
2059 ath10k_info(ar, "restarting firmware due to Peer stats change");
2060
2061 queue_work(ar->workqueue, &ar->restart_work);
2062 ret = count;
2063
2064exit:
2065 mutex_unlock(&ar->conf_mutex);
2066 return ret;
2067}
2068
2069static ssize_t ath10k_read_peer_stats(struct file *file, char __user *ubuf,
2070 size_t count, loff_t *ppos)
2071
2072{
2073 char buf[32];
2074 struct ath10k *ar = file->private_data;
2075 int len = 0;
2076
2077 mutex_lock(&ar->conf_mutex);
2078 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2079 test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags));
2080 mutex_unlock(&ar->conf_mutex);
2081
2082 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2083}
2084
2085static const struct file_operations fops_peer_stats = {
2086 .read = ath10k_read_peer_stats,
2087 .write = ath10k_write_peer_stats,
2088 .open = simple_open
2089};
2090
Kalle Valo9e100c42015-11-25 15:38:41 +02002091static ssize_t ath10k_debug_fw_checksums_read(struct file *file,
2092 char __user *user_buf,
2093 size_t count, loff_t *ppos)
2094{
2095 struct ath10k *ar = file->private_data;
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02002096 size_t len = 0, buf_len = 4096;
Kalle Valo9e100c42015-11-25 15:38:41 +02002097 ssize_t ret_cnt;
2098 char *buf;
2099
2100 buf = kzalloc(buf_len, GFP_KERNEL);
2101 if (!buf)
2102 return -ENOMEM;
2103
2104 mutex_lock(&ar->conf_mutex);
2105
Kalle Valo9e100c42015-11-25 15:38:41 +02002106 len += scnprintf(buf + len, buf_len - len,
2107 "firmware-N.bin\t\t%08x\n",
Kalle Valo7ebf7212016-04-20 19:44:51 +03002108 crc32_le(0, ar->normal_mode_fw.fw_file.firmware->data,
2109 ar->normal_mode_fw.fw_file.firmware->size));
Kalle Valo9e100c42015-11-25 15:38:41 +02002110 len += scnprintf(buf + len, buf_len - len,
2111 "athwlan\t\t\t%08x\n",
Kalle Valo7ebf7212016-04-20 19:44:51 +03002112 crc32_le(0, ar->normal_mode_fw.fw_file.firmware_data,
2113 ar->normal_mode_fw.fw_file.firmware_len));
Kalle Valo9e100c42015-11-25 15:38:41 +02002114 len += scnprintf(buf + len, buf_len - len,
2115 "otp\t\t\t%08x\n",
Kalle Valo7ebf7212016-04-20 19:44:51 +03002116 crc32_le(0, ar->normal_mode_fw.fw_file.otp_data,
2117 ar->normal_mode_fw.fw_file.otp_len));
Kalle Valo9e100c42015-11-25 15:38:41 +02002118 len += scnprintf(buf + len, buf_len - len,
2119 "codeswap\t\t%08x\n",
Kalle Valo7ebf7212016-04-20 19:44:51 +03002120 crc32_le(0, ar->normal_mode_fw.fw_file.codeswap_data,
2121 ar->normal_mode_fw.fw_file.codeswap_len));
Kalle Valo9e100c42015-11-25 15:38:41 +02002122 len += scnprintf(buf + len, buf_len - len,
2123 "board-N.bin\t\t%08x\n",
Kalle Valo7ebf7212016-04-20 19:44:51 +03002124 crc32_le(0, ar->normal_mode_fw.board->data,
2125 ar->normal_mode_fw.board->size));
Kalle Valo9e100c42015-11-25 15:38:41 +02002126 len += scnprintf(buf + len, buf_len - len,
2127 "board\t\t\t%08x\n",
Kalle Valo7ebf7212016-04-20 19:44:51 +03002128 crc32_le(0, ar->normal_mode_fw.board_data,
2129 ar->normal_mode_fw.board_len));
Kalle Valo9e100c42015-11-25 15:38:41 +02002130
2131 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2132
2133 mutex_unlock(&ar->conf_mutex);
2134
2135 kfree(buf);
2136 return ret_cnt;
2137}
2138
2139static const struct file_operations fops_fw_checksums = {
2140 .read = ath10k_debug_fw_checksums_read,
2141 .open = simple_open,
2142 .owner = THIS_MODULE,
2143 .llseek = default_llseek,
2144};
2145
Kalle Valo5e3dd152013-06-12 20:52:10 +03002146int ath10k_debug_create(struct ath10k *ar)
2147{
Marty Faltesekf67b107d2016-10-10 19:00:04 +03002148 ar->debug.cal_data = vzalloc(ATH10K_DEBUG_CAL_DATA_LEN);
2149 if (!ar->debug.cal_data)
2150 return -ENOMEM;
2151
Michal Kazior53268492014-09-25 12:33:50 +02002152 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
Michal Kazior7b6b1532015-02-15 16:50:40 +02002153 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
Michal Kazior53268492014-09-25 12:33:50 +02002154 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
Mohammed Shafi Shajakhan4a49ae92016-06-30 15:23:47 +03002155 INIT_LIST_HEAD(&ar->debug.fw_stats.peers_extd);
Michal Kazior53268492014-09-25 12:33:50 +02002156
Michal Kaziore13cf7a2014-09-04 09:13:08 +02002157 return 0;
2158}
2159
2160void ath10k_debug_destroy(struct ath10k *ar)
2161{
Marty Faltesekf67b107d2016-10-10 19:00:04 +03002162 vfree(ar->debug.cal_data);
2163 ar->debug.cal_data = NULL;
2164
Michal Kazior53268492014-09-25 12:33:50 +02002165 ath10k_debug_fw_stats_reset(ar);
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03002166
2167 kfree(ar->debug.tpc_stats);
Michal Kaziore13cf7a2014-09-04 09:13:08 +02002168}
2169
2170int ath10k_debug_register(struct ath10k *ar)
2171{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002172 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
2173 ar->hw->wiphy->debugfsdir);
Michal Kazioradb43b22014-09-04 12:36:45 +02002174 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
2175 if (IS_ERR(ar->debug.debugfs_phy))
2176 return PTR_ERR(ar->debug.debugfs_phy);
Kalle Valod8bb26b2014-09-14 12:50:33 +03002177
2178 return -ENOMEM;
Michal Kazioradb43b22014-09-04 12:36:45 +02002179 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180
Kalle Valoa3d135e2013-09-03 11:44:10 +03002181 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
2182 ath10k_debug_htt_stats_dwork);
2183
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03002184 init_completion(&ar->debug.tpc_complete);
Michal Kazior60ef4012014-09-25 12:33:48 +02002185 init_completion(&ar->debug.fw_stats_complete);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002187 debugfs_create_file("fw_stats", 0400, ar->debug.debugfs_phy, ar,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002188 &fops_fw_stats);
2189
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002190 debugfs_create_file("fw_reset_stats", 0400, ar->debug.debugfs_phy, ar,
2191 &fops_fw_reset_stats);
Ben Greearf51dbe72014-09-29 14:41:46 +03002192
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002193 debugfs_create_file("wmi_services", 0400, ar->debug.debugfs_phy, ar,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002194 &fops_wmi_services);
2195
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002196 debugfs_create_file("simulate_fw_crash", 0600, ar->debug.debugfs_phy, ar,
2197 &fops_simulate_fw_crash);
Michal Kazior278c4a82013-07-22 14:08:51 +02002198
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002199 debugfs_create_file("reg_addr", 0600, ar->debug.debugfs_phy, ar,
2200 &fops_reg_addr);
Yanbo Li077a3802014-11-25 12:24:33 +02002201
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002202 debugfs_create_file("reg_value", 0600, ar->debug.debugfs_phy, ar,
2203 &fops_reg_value);
Yanbo Li077a3802014-11-25 12:24:33 +02002204
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002205 debugfs_create_file("mem_value", 0600, ar->debug.debugfs_phy, ar,
2206 &fops_mem_value);
Yanbo Li9f65ad22014-11-25 12:24:48 +02002207
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002208 debugfs_create_file("chip_id", 0400, ar->debug.debugfs_phy, ar,
2209 &fops_chip_id);
Kalle Valo763b8cd2013-09-01 11:22:21 +03002210
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002211 debugfs_create_file("htt_stats_mask", 0600, ar->debug.debugfs_phy, ar,
2212 &fops_htt_stats_mask);
Kalle Valoa3d135e2013-09-03 11:44:10 +03002213
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002214 debugfs_create_file("htt_max_amsdu_ampdu", 0600, ar->debug.debugfs_phy, ar,
Janusz Dziedzicd3856232014-06-02 21:19:46 +03002215 &fops_htt_max_amsdu_ampdu);
2216
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002217 debugfs_create_file("fw_dbglog", 0600, ar->debug.debugfs_phy, ar,
2218 &fops_fw_dbglog);
Kalle Valof118a3e2014-01-03 12:59:31 +02002219
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002220 debugfs_create_file("cal_data", 0400, ar->debug.debugfs_phy, ar,
2221 &fops_cal_data);
Kalle Valo7869b4f2014-09-24 14:16:58 +03002222
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002223 debugfs_create_file("ani_enable", 0600, ar->debug.debugfs_phy, ar,
2224 &fops_ani_enable);
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05302225
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002226 debugfs_create_file("nf_cal_period", 0600, ar->debug.debugfs_phy, ar,
2227 &fops_nf_cal_period);
Peter Oha7bd3e92014-12-02 13:07:14 +02002228
Masahiro Yamada97f26452016-08-03 13:45:50 -07002229 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002230 debugfs_create_file("dfs_simulate_radar", 0200, ar->debug.debugfs_phy,
2231 ar, &fops_simulate_radar);
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002232
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002233 debugfs_create_bool("dfs_block_radar_events", 0200,
Marek Puzyniak7d9b40b2013-11-20 10:00:28 +02002234 ar->debug.debugfs_phy,
2235 &ar->dfs_block_radar_events);
2236
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002237 debugfs_create_file("dfs_stats", 0400, ar->debug.debugfs_phy, ar,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002238 &fops_dfs_stats);
2239 }
2240
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002241 debugfs_create_file("pktlog_filter", 0644, ar->debug.debugfs_phy, ar,
2242 &fops_pktlog_filter);
Rajkumar Manoharan90174452014-10-03 08:02:33 +03002243
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002244 debugfs_create_file("quiet_period", 0644, ar->debug.debugfs_phy, ar,
2245 &fops_quiet_period);
Rajkumar Manoharan63fb32d2015-03-15 20:36:20 +05302246
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002247 debugfs_create_file("tpc_stats", 0400, ar->debug.debugfs_phy, ar,
2248 &fops_tpc_stats);
Maharaja Kennadyrajan29542662015-10-05 17:56:38 +03002249
Yanbo Li844fa572015-10-31 11:07:21 +02002250 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002251 debugfs_create_file("btcoex", 0644, ar->debug.debugfs_phy, ar,
2252 &fops_btcoex);
Yanbo Li844fa572015-10-31 11:07:21 +02002253
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +05302254 if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map))
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002255 debugfs_create_file("peer_stats", 0644, ar->debug.debugfs_phy, ar,
Mohammed Shafi Shajakhancc61a1b2016-03-16 18:13:32 +05302256 &fops_peer_stats);
2257
Marcin Rokicki53c8d482017-02-20 14:40:27 +01002258 debugfs_create_file("fw_checksums", 0400, ar->debug.debugfs_phy, ar,
2259 &fops_fw_checksums);
Kalle Valo9e100c42015-11-25 15:38:41 +02002260
Kalle Valo5e3dd152013-06-12 20:52:10 +03002261 return 0;
2262}
Kalle Valodb66ea02013-09-03 11:44:03 +03002263
Michal Kaziore13cf7a2014-09-04 09:13:08 +02002264void ath10k_debug_unregister(struct ath10k *ar)
Kalle Valo60631c52013-10-08 21:45:25 +03002265{
2266 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
2267}
2268
Kalle Valo5e3dd152013-06-12 20:52:10 +03002269#endif /* CONFIG_ATH10K_DEBUGFS */
2270
2271#ifdef CONFIG_ATH10K_DEBUG
Michal Kazior7aa7a722014-08-25 12:09:38 +02002272void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
2273 const char *fmt, ...)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002274{
2275 struct va_format vaf;
2276 va_list args;
2277
2278 va_start(args, fmt);
2279
2280 vaf.fmt = fmt;
2281 vaf.va = &args;
2282
2283 if (ath10k_debug_mask & mask)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002284 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002285
Michal Kaziord35a6c12014-09-02 11:00:21 +03002286 trace_ath10k_log_dbg(ar, mask, &vaf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002287
2288 va_end(args);
2289}
2290EXPORT_SYMBOL(ath10k_dbg);
2291
Michal Kazior7aa7a722014-08-25 12:09:38 +02002292void ath10k_dbg_dump(struct ath10k *ar,
2293 enum ath10k_debug_mask mask,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002294 const char *msg, const char *prefix,
2295 const void *buf, size_t len)
2296{
Michal Kazior45724a82014-09-23 10:22:53 +02002297 char linebuf[256];
Amadeusz Sławiński182f1e52017-02-13 12:38:38 +02002298 size_t linebuflen;
Michal Kazior45724a82014-09-23 10:22:53 +02002299 const void *ptr;
2300
Kalle Valo5e3dd152013-06-12 20:52:10 +03002301 if (ath10k_debug_mask & mask) {
2302 if (msg)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002303 ath10k_dbg(ar, mask, "%s\n", msg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002304
Michal Kazior45724a82014-09-23 10:22:53 +02002305 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
2306 linebuflen = 0;
2307 linebuflen += scnprintf(linebuf + linebuflen,
2308 sizeof(linebuf) - linebuflen,
2309 "%s%08x: ",
2310 (prefix ? prefix : ""),
2311 (unsigned int)(ptr - buf));
2312 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
2313 linebuf + linebuflen,
2314 sizeof(linebuf) - linebuflen, true);
2315 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
2316 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002317 }
2318
2319 /* tracing code doesn't like null strings :/ */
Michal Kaziord35a6c12014-09-02 11:00:21 +03002320 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002321 buf, len);
2322}
2323EXPORT_SYMBOL(ath10k_dbg_dump);
2324
2325#endif /* CONFIG_ATH10K_DEBUG */