Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2011 Atheros Communications Inc. |
Kalle Valo | 8b1083d | 2017-12-22 18:31:13 +0200 | [diff] [blame] | 3 | * Copyright (c) 2011-2017 Qualcomm Atheros, Inc. |
Yu Wang | 50e79e2 | 2018-01-30 14:06:08 +0200 | [diff] [blame] | 4 | * Copyright (c) 2018, The Linux Foundation. All rights reserved. |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5 | * |
| 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 Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 21 | #include <linux/vmalloc.h> |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 22 | #include <linux/crc32.h> |
| 23 | #include <linux/firmware.h> |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 24 | |
| 25 | #include "core.h" |
| 26 | #include "debug.h" |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 27 | #include "hif.h" |
Michal Kazior | d7579d1 | 2014-12-03 10:10:54 +0200 | [diff] [blame] | 28 | #include "wmi-ops.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 29 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 30 | /* ms */ |
| 31 | #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000 |
| 32 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 33 | #define ATH10K_DEBUG_CAL_DATA_LEN 12064 |
| 34 | |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 35 | void ath10k_info(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 36 | { |
| 37 | struct va_format vaf = { |
| 38 | .fmt = fmt, |
| 39 | }; |
| 40 | va_list args; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 41 | |
| 42 | va_start(args, fmt); |
| 43 | vaf.va = &args; |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 44 | dev_info(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 45 | trace_ath10k_log_info(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 46 | va_end(args); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 47 | } |
| 48 | EXPORT_SYMBOL(ath10k_info); |
| 49 | |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 50 | void ath10k_debug_print_hwfw_info(struct ath10k *ar) |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 51 | { |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 52 | const struct firmware *firmware; |
Michal Kazior | 84e3df6 | 2015-08-05 06:55:37 +0200 | [diff] [blame] | 53 | char fw_features[128] = {}; |
Michal Kazior | 8866c72 | 2016-03-17 10:52:08 +0100 | [diff] [blame] | 54 | u32 crc = 0; |
Michal Kazior | b27bc5a | 2015-06-15 14:46:40 +0300 | [diff] [blame] | 55 | |
| 56 | ath10k_core_get_fw_features_str(ar, fw_features, sizeof(fw_features)); |
| 57 | |
Kalle Valo | 8605c02 | 2015-11-25 15:38:19 +0200 | [diff] [blame] | 58 | ath10k_info(ar, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x", |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 59 | ar->hw_params.name, |
| 60 | ar->target_version, |
| 61 | ar->chip_id, |
Kalle Valo | 8605c02 | 2015-11-25 15:38:19 +0200 | [diff] [blame] | 62 | ar->id.subsystem_vendor, ar->id.subsystem_device); |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 63 | |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 64 | ath10k_info(ar, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n", |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 65 | 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 Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 70 | |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 71 | firmware = ar->normal_mode_fw.fw_file.firmware; |
| 72 | if (firmware) |
| 73 | crc = crc32_le(0, firmware->data, firmware->size); |
Michal Kazior | 8866c72 | 2016-03-17 10:52:08 +0100 | [diff] [blame] | 74 | |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 75 | ath10k_info(ar, "firmware ver %s api %d features %s crc32 %08x\n", |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 76 | ar->hw->wiphy->fw_version, |
| 77 | ar->fw_api, |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 78 | fw_features, |
Michal Kazior | 8866c72 | 2016-03-17 10:52:08 +0100 | [diff] [blame] | 79 | crc); |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void ath10k_debug_print_board_info(struct ath10k *ar) |
| 83 | { |
| 84 | char boardinfo[100]; |
Yu Wang | 50e79e2 | 2018-01-30 14:06:08 +0200 | [diff] [blame] | 85 | const struct firmware *board; |
| 86 | u32 crc; |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 87 | |
| 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 Wang | 50e79e2 | 2018-01-30 14:06:08 +0200 | [diff] [blame] | 94 | 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 Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 100 | ath10k_info(ar, "board_file api %d bmi_id %s crc32 %08x", |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 101 | ar->bd_api, |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 102 | boardinfo, |
Yu Wang | 50e79e2 | 2018-01-30 14:06:08 +0200 | [diff] [blame] | 103 | crc); |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void ath10k_debug_print_boot_info(struct ath10k *ar) |
| 107 | { |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 108 | ath10k_info(ar, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n", |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 109 | ar->htt.target_version_major, |
Michal Kazior | 34b28b6 | 2014-09-23 10:22:52 +0200 | [diff] [blame] | 110 | ar->htt.target_version_minor, |
Kalle Valo | bf3c13a | 2016-04-20 19:45:33 +0300 | [diff] [blame] | 111 | ar->normal_mode_fw.fw_file.wmi_op_version, |
Kalle Valo | 77561f9 | 2016-04-20 19:45:47 +0300 | [diff] [blame] | 112 | ar->normal_mode_fw.fw_file.htt_op_version, |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 113 | ath10k_cal_mode_str(ar->cal_mode), |
Michal Kazior | b27bc5a | 2015-06-15 14:46:40 +0300 | [diff] [blame] | 114 | ar->max_num_stations, |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 115 | test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags), |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 116 | !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags)); |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 117 | } |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 118 | |
| 119 | void 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 Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 125 | EXPORT_SYMBOL(ath10k_print_driver_info); |
| 126 | |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 127 | void ath10k_err(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 128 | { |
| 129 | struct va_format vaf = { |
| 130 | .fmt = fmt, |
| 131 | }; |
| 132 | va_list args; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 133 | |
| 134 | va_start(args, fmt); |
| 135 | vaf.va = &args; |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 136 | dev_err(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 137 | trace_ath10k_log_err(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 138 | va_end(args); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 139 | } |
| 140 | EXPORT_SYMBOL(ath10k_err); |
| 141 | |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 142 | void ath10k_warn(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 143 | { |
| 144 | struct va_format vaf = { |
| 145 | .fmt = fmt, |
| 146 | }; |
| 147 | va_list args; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 148 | |
| 149 | va_start(args, fmt); |
| 150 | vaf.va = &args; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 151 | dev_warn_ratelimited(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 152 | trace_ath10k_log_warn(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 153 | |
| 154 | va_end(args); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 155 | } |
| 156 | EXPORT_SYMBOL(ath10k_warn); |
| 157 | |
| 158 | #ifdef CONFIG_ATH10K_DEBUGFS |
| 159 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 160 | static 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 chelvam | 75e0dde | 2017-07-03 11:02:36 +0530 | [diff] [blame] | 166 | size_t len = 0, buf_len = 8192; |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 167 | const char *name; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 168 | ssize_t ret_cnt; |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 169 | bool enabled; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 170 | 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 Kazior | acfe7ec | 2014-11-27 10:11:17 +0100 | [diff] [blame] | 178 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | c4f8c83 | 2014-09-04 10:18:32 +0200 | [diff] [blame] | 179 | for (i = 0; i < WMI_SERVICE_MAX; i++) { |
Michal Kazior | acfe7ec | 2014-11-27 10:11:17 +0100 | [diff] [blame] | 180 | enabled = test_bit(i, ar->wmi.svc_map); |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 181 | 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 Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 191 | |
| 192 | len += scnprintf(buf + len, buf_len - len, |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 193 | "%-40s %s\n", |
| 194 | name, enabled ? "enabled" : "-"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 195 | } |
Michal Kazior | acfe7ec | 2014-11-27 10:11:17 +0100 | [diff] [blame] | 196 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 197 | |
| 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 | |
| 206 | static 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 Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 213 | static void ath10k_fw_stats_pdevs_free(struct list_head *head) |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 214 | { |
| 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 Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 223 | static void ath10k_fw_stats_vdevs_free(struct list_head *head) |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 224 | { |
| 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 Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 233 | static void ath10k_fw_stats_peers_free(struct list_head *head) |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 234 | { |
| 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 Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 243 | static 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 Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 253 | static 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 Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 257 | ar->debug.fw_stats.extended = false; |
Mohammed Shafi Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 258 | 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 Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 261 | ath10k_fw_extd_stats_peers_free(&ar->debug.fw_stats.peers_extd); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 262 | spin_unlock_bh(&ar->data_lock); |
| 263 | } |
| 264 | |
Michal Kazior | 60ef401 | 2014-09-25 12:33:48 +0200 | [diff] [blame] | 265 | void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 266 | { |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 267 | struct ath10k_fw_stats stats = {}; |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 268 | bool is_start, is_started, is_end; |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 269 | size_t num_peers; |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 270 | size_t num_vdevs; |
Michal Kazior | d15fb52 | 2014-09-25 12:33:47 +0200 | [diff] [blame] | 271 | int ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 272 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 273 | INIT_LIST_HEAD(&stats.pdevs); |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 274 | INIT_LIST_HEAD(&stats.vdevs); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 275 | INIT_LIST_HEAD(&stats.peers); |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 276 | INIT_LIST_HEAD(&stats.peers_extd); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 277 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 278 | spin_lock_bh(&ar->data_lock); |
| 279 | ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats); |
Michal Kazior | d15fb52 | 2014-09-25 12:33:47 +0200 | [diff] [blame] | 280 | if (ret) { |
| 281 | ath10k_warn(ar, "failed to pull fw stats: %d\n", ret); |
Raja Mani | 5db879a | 2015-07-09 14:19:43 +0530 | [diff] [blame] | 282 | goto free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 283 | } |
| 284 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 285 | /* 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 Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 296 | if (ath10k_peer_stats_enabled(ar)) |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 297 | ath10k_sta_update_rx_duration(ar, &stats); |
Mohammed Shafi Shajakhan | 74135f5 | 2016-02-03 21:07:42 +0530 | [diff] [blame] | 298 | |
Mohammed Shafi Shajakhan | e0b6ce0 | 2016-02-03 21:07:43 +0530 | [diff] [blame] | 299 | if (ar->debug.fw_stats_done) { |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 300 | if (!ath10k_peer_stats_enabled(ar)) |
Mohammed Shafi Shajakhan | e0b6ce0 | 2016-02-03 21:07:43 +0530 | [diff] [blame] | 301 | ath10k_warn(ar, "received unsolicited stats update event\n"); |
| 302 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 303 | goto free; |
| 304 | } |
| 305 | |
Manikanta Pubbisetty | bc6f9ae | 2015-10-16 15:54:52 +0300 | [diff] [blame] | 306 | 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 Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 308 | 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 Shajakhan | d57e7f2 | 2016-01-13 21:16:32 +0530 | [diff] [blame] | 326 | ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers); |
Christian Lamparter | c1e3330 | 2016-12-05 22:52:45 +0100 | [diff] [blame] | 327 | ath10k_fw_extd_stats_peers_free(&ar->debug.fw_stats.peers_extd); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 328 | ath10k_warn(ar, "dropping fw peer stats\n"); |
| 329 | goto free; |
| 330 | } |
| 331 | |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 332 | if (num_vdevs >= BITS_PER_LONG) { |
Mohammed Shafi Shajakhan | d57e7f2 | 2016-01-13 21:16:32 +0530 | [diff] [blame] | 333 | ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs); |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 334 | ath10k_warn(ar, "dropping fw vdev stats\n"); |
| 335 | goto free; |
| 336 | } |
| 337 | |
Christian Lamparter | c1e3330 | 2016-12-05 22:52:45 +0100 | [diff] [blame] | 338 | if (!list_empty(&stats.peers)) |
| 339 | list_splice_tail_init(&stats.peers_extd, |
| 340 | &ar->debug.fw_stats.peers_extd); |
| 341 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 342 | list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers); |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 343 | list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Michal Kazior | 60ef401 | 2014-09-25 12:33:48 +0200 | [diff] [blame] | 346 | complete(&ar->debug.fw_stats_complete); |
Michal Kazior | d15fb52 | 2014-09-25 12:33:47 +0200 | [diff] [blame] | 347 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 348 | free: |
| 349 | /* In some cases lists have been spliced and cleared. Free up |
| 350 | * resources if that is not the case. |
| 351 | */ |
Mohammed Shafi Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 352 | 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 Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 355 | ath10k_fw_extd_stats_peers_free(&stats.peers_extd); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 356 | |
Michal Kazior | d15fb52 | 2014-09-25 12:33:47 +0200 | [diff] [blame] | 357 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 358 | } |
| 359 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 360 | static int ath10k_debug_fw_stats_request(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 361 | { |
Nicholas Mc Guire | 6e8d543 | 2015-03-30 15:39:20 +0300 | [diff] [blame] | 362 | unsigned long timeout, time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 363 | int ret; |
| 364 | |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 365 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 366 | |
Nicholas Mc Guire | 6e8d543 | 2015-03-30 15:39:20 +0300 | [diff] [blame] | 367 | timeout = jiffies + msecs_to_jiffies(1 * HZ); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 368 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 369 | 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 Li | 6274cd4 | 2015-04-01 22:53:21 +0300 | [diff] [blame] | 377 | ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 378 | if (ret) { |
| 379 | ath10k_warn(ar, "could not request stats (%d)\n", ret); |
| 380 | return ret; |
| 381 | } |
| 382 | |
Nicholas Mc Guire | 6e8d543 | 2015-03-30 15:39:20 +0300 | [diff] [blame] | 383 | time_left = |
| 384 | wait_for_completion_timeout(&ar->debug.fw_stats_complete, |
| 385 | 1 * HZ); |
| 386 | if (!time_left) |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 387 | 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 Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 400 | static 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 Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 405 | |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 406 | 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 Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 419 | ret = ath10k_debug_fw_stats_request(ar); |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 420 | if (ret) { |
| 421 | ath10k_warn(ar, "failed to request fw stats: %d\n", ret); |
| 422 | goto err_free; |
| 423 | } |
| 424 | |
Manikanta Pubbisetty | bc6f9ae | 2015-10-16 15:54:52 +0300 | [diff] [blame] | 425 | 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 Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 431 | file->private_data = buf; |
| 432 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 433 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 434 | return 0; |
| 435 | |
| 436 | err_free: |
| 437 | vfree(buf); |
| 438 | |
| 439 | err_unlock: |
| 440 | mutex_unlock(&ar->conf_mutex); |
| 441 | return ret; |
| 442 | } |
| 443 | |
| 444 | static int ath10k_fw_stats_release(struct inode *inode, struct file *file) |
| 445 | { |
| 446 | vfree(file->private_data); |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static 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ński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 455 | size_t len = strlen(buf); |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 456 | |
| 457 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static const struct file_operations fops_fw_stats = { |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 461 | .open = ath10k_fw_stats_open, |
| 462 | .release = ath10k_fw_stats_release, |
Michal Kazior | 60ef401 | 2014-09-25 12:33:48 +0200 | [diff] [blame] | 463 | .read = ath10k_fw_stats_read, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 464 | .owner = THIS_MODULE, |
| 465 | .llseek = default_llseek, |
| 466 | }; |
| 467 | |
Ben Greear | f51dbe7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 468 | static 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ński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 473 | int ret; |
| 474 | size_t len = 0, buf_len = 500; |
Ben Greear | f51dbe7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 475 | char *buf; |
| 476 | |
Ben Greear | f51dbe7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 477 | buf = kmalloc(buf_len, GFP_KERNEL); |
| 478 | if (!buf) |
| 479 | return -ENOMEM; |
| 480 | |
| 481 | spin_lock_bh(&ar->data_lock); |
| 482 | |
Ben Greear | f51dbe7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 483 | 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 | |
| 501 | static 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 Greear | d5aebc7 | 2014-09-10 18:59:28 +0300 | [diff] [blame] | 508 | /* This is a clean assert crash in firmware. */ |
| 509 | static 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 Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 528 | static ssize_t ath10k_read_simulate_fw_crash(struct file *file, |
| 529 | char __user *user_buf, |
| 530 | size_t count, loff_t *ppos) |
| 531 | { |
Kalle Valo | 75cb96d | 2014-09-14 12:50:44 +0300 | [diff] [blame] | 532 | 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 Kazior | 605cdba | 2014-10-28 10:34:37 +0100 | [diff] [blame] | 536 | "`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 Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 538 | |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 539 | return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); |
| 540 | } |
| 541 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 542 | /* 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 Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 549 | static 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 Mera | a16703a | 2017-04-24 16:11:57 +0900 | [diff] [blame] | 554 | char buf[32] = {0}; |
| 555 | ssize_t rc; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 556 | int ret; |
| 557 | |
Michael Mera | a16703a | 2017-04-24 16:11:57 +0900 | [diff] [blame] | 558 | /* filter partial writes and invalid commands */ |
| 559 | if (*ppos != 0 || count >= sizeof(buf) || count == 0) |
| 560 | return -EINVAL; |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 561 | |
Michael Mera | a16703a | 2017-04-24 16:11:57 +0900 | [diff] [blame] | 562 | rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); |
| 563 | if (rc < 0) |
| 564 | return rc; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 565 | |
Mohammed Shafi Shajakhan | f5e3075 | 2016-05-28 11:25:41 +0300 | [diff] [blame] | 566 | /* drop the possible '\n' from the end */ |
Michael Mera | a16703a | 2017-04-24 16:11:57 +0900 | [diff] [blame] | 567 | if (buf[*ppos - 1] == '\n') |
| 568 | buf[*ppos - 1] = '\0'; |
Mohammed Shafi Shajakhan | f5e3075 | 2016-05-28 11:25:41 +0300 | [diff] [blame] | 569 | |
| 570 | mutex_lock(&ar->conf_mutex); |
| 571 | |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 572 | if (ar->state != ATH10K_STATE_ON && |
| 573 | ar->state != ATH10K_STATE_RESTARTED) { |
| 574 | ret = -ENETDOWN; |
| 575 | goto exit; |
| 576 | } |
| 577 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 578 | if (!strcmp(buf, "soft")) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 579 | ath10k_info(ar, "simulating soft firmware crash\n"); |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 580 | ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0); |
| 581 | } else if (!strcmp(buf, "hard")) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 582 | ath10k_info(ar, "simulating hard firmware crash\n"); |
Ben Greear | 611b368 | 2014-07-25 11:56:40 +0300 | [diff] [blame] | 583 | /* 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 Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 587 | ar->wmi.vdev_param->rts_threshold, |
| 588 | 0); |
Ben Greear | d5aebc7 | 2014-09-10 18:59:28 +0300 | [diff] [blame] | 589 | } else if (!strcmp(buf, "assert")) { |
| 590 | ath10k_info(ar, "simulating firmware assert crash\n"); |
| 591 | ret = ath10k_debug_fw_assert(ar); |
Michal Kazior | 605cdba | 2014-10-28 10:34:37 +0100 | [diff] [blame] | 592 | } 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 Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 596 | } else { |
| 597 | ret = -EINVAL; |
| 598 | goto exit; |
| 599 | } |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 600 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 601 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 602 | ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret); |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 603 | goto exit; |
| 604 | } |
| 605 | |
| 606 | ret = count; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 607 | |
| 608 | exit: |
| 609 | mutex_unlock(&ar->conf_mutex); |
| 610 | return ret; |
| 611 | } |
| 612 | |
| 613 | static 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 Valo | 763b8cd | 2013-09-01 11:22:21 +0300 | [diff] [blame] | 621 | static 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ński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 625 | size_t len; |
Kalle Valo | 763b8cd | 2013-09-01 11:22:21 +0300 | [diff] [blame] | 626 | 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 | |
| 633 | static 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 Li | 077a380 | 2014-11-25 12:24:33 +0200 | [diff] [blame] | 640 | static 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ński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 646 | size_t len = 0; |
Yanbo Li | 077a380 | 2014-11-25 12:24:33 +0200 | [diff] [blame] | 647 | 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 | |
| 658 | static 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, ®_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 | |
| 680 | static 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 | |
| 688 | static 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ński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 694 | size_t len; |
Yanbo Li | 077a380 | 2014-11-25 12:24:33 +0200 | [diff] [blame] | 695 | 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 | |
| 713 | exit: |
| 714 | mutex_unlock(&ar->conf_mutex); |
| 715 | |
| 716 | return ret; |
| 717 | } |
| 718 | |
| 719 | static 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, ®_val); |
| 738 | if (ret) |
| 739 | goto exit; |
| 740 | |
| 741 | ath10k_hif_write32(ar, reg_addr, reg_val); |
| 742 | |
| 743 | ret = count; |
| 744 | |
| 745 | exit: |
| 746 | mutex_unlock(&ar->conf_mutex); |
| 747 | |
| 748 | return ret; |
| 749 | } |
| 750 | |
| 751 | static 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 Li | 9f65ad2 | 2014-11-25 12:24:48 +0200 | [diff] [blame] | 759 | static 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 | |
| 804 | exit: |
| 805 | vfree(buf); |
| 806 | mutex_unlock(&ar->conf_mutex); |
| 807 | |
| 808 | return ret; |
| 809 | } |
| 810 | |
| 811 | static 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 | |
| 855 | exit: |
| 856 | vfree(buf); |
| 857 | mutex_unlock(&ar->conf_mutex); |
| 858 | |
| 859 | return ret; |
| 860 | } |
| 861 | |
| 862 | static 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 Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 870 | static 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 Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 889 | ath10k_warn(ar, "failed to send htt stats request: %d\n", ret); |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 890 | 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 | |
| 899 | static 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 | |
| 911 | static ssize_t ath10k_read_htt_stats_mask(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 912 | char __user *user_buf, |
| 913 | size_t count, loff_t *ppos) |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 914 | { |
| 915 | struct ath10k *ar = file->private_data; |
| 916 | char buf[32]; |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 917 | size_t len; |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 918 | |
| 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 | |
| 924 | static ssize_t ath10k_write_htt_stats_mask(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 925 | const char __user *user_buf, |
| 926 | size_t count, loff_t *ppos) |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 927 | { |
| 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 | |
| 950 | out: |
| 951 | mutex_unlock(&ar->conf_mutex); |
| 952 | |
| 953 | return ret; |
| 954 | } |
| 955 | |
| 956 | static 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 Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 964 | static 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 Shajakhan | 81ec3c0 | 2015-11-30 22:29:39 +0530 | [diff] [blame] | 970 | u8 amsdu, ampdu; |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 971 | size_t len; |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 972 | |
| 973 | mutex_lock(&ar->conf_mutex); |
| 974 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 975 | amsdu = ar->htt.max_num_amsdu; |
| 976 | ampdu = ar->htt.max_num_ampdu; |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 977 | 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 | |
| 984 | static 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; |
Venkateswara Naralasetty | 2f177c1 | 2018-04-25 11:36:40 +0300 | [diff] [blame] | 990 | char buf[64] = {0}; |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 991 | unsigned int amsdu, ampdu; |
| 992 | |
Venkateswara Naralasetty | 2f177c1 | 2018-04-25 11:36:40 +0300 | [diff] [blame] | 993 | res = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, |
| 994 | user_buf, count); |
| 995 | if (res <= 0) |
| 996 | return res; |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 997 | |
| 998 | res = sscanf(buf, "%u %u", &amsdu, &du); |
| 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 Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 1010 | ar->htt.max_num_amsdu = amsdu; |
| 1011 | ar->htt.max_num_ampdu = ampdu; |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1012 | |
| 1013 | out: |
| 1014 | mutex_unlock(&ar->conf_mutex); |
| 1015 | return res; |
| 1016 | } |
| 1017 | |
| 1018 | static 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 Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1026 | static ssize_t ath10k_read_fw_dbglog(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1027 | char __user *user_buf, |
| 1028 | size_t count, loff_t *ppos) |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1029 | { |
| 1030 | struct ath10k *ar = file->private_data; |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1031 | size_t len; |
Maharaja Kennadyrajan | afcbc82 | 2016-08-23 15:35:36 +0530 | [diff] [blame] | 1032 | char buf[96]; |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1033 | |
Maharaja Kennadyrajan | afcbc82 | 2016-08-23 15:35:36 +0530 | [diff] [blame] | 1034 | len = scnprintf(buf, sizeof(buf), "0x%16llx %u\n", |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1035 | ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level); |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1036 | |
| 1037 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1038 | } |
| 1039 | |
| 1040 | static 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 Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1045 | int ret; |
Venkateswara Naralasetty | 2f177c1 | 2018-04-25 11:36:40 +0300 | [diff] [blame] | 1046 | char buf[96] = {0}; |
Maharaja Kennadyrajan | afcbc82 | 2016-08-23 15:35:36 +0530 | [diff] [blame] | 1047 | unsigned int log_level; |
| 1048 | u64 mask; |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1049 | |
Venkateswara Naralasetty | 2f177c1 | 2018-04-25 11:36:40 +0300 | [diff] [blame] | 1050 | ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, |
| 1051 | user_buf, count); |
| 1052 | if (ret <= 0) |
| 1053 | return ret; |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1054 | |
Maharaja Kennadyrajan | afcbc82 | 2016-08-23 15:35:36 +0530 | [diff] [blame] | 1055 | ret = sscanf(buf, "%llx %u", &mask, &log_level); |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1056 | |
| 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 Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1063 | |
| 1064 | mutex_lock(&ar->conf_mutex); |
| 1065 | |
| 1066 | ar->debug.fw_dbglog_mask = mask; |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1067 | ar->debug.fw_dbglog_level = log_level; |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1068 | |
| 1069 | if (ar->state == ATH10K_STATE_ON) { |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1070 | ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask, |
| 1071 | ar->debug.fw_dbglog_level); |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1072 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1073 | ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n", |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1074 | ret); |
| 1075 | goto exit; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | ret = count; |
| 1080 | |
| 1081 | exit: |
| 1082 | mutex_unlock(&ar->conf_mutex); |
| 1083 | |
| 1084 | return ret; |
| 1085 | } |
| 1086 | |
Ben Greear | 6cddcc7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 1087 | /* 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 */ |
| 1093 | static 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 | |
| 1144 | void 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 | |
| 1153 | int 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 | |
| 1162 | void 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 Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1247 | static 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 Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1255 | static int ath10k_debug_cal_data_fetch(struct ath10k *ar) |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1256 | { |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1257 | u32 hi_addr; |
| 1258 | __le32 addr; |
| 1259 | int ret; |
| 1260 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1261 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1262 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1263 | if (WARN_ON(ar->hw_params.cal_data_len > ATH10K_DEBUG_CAL_DATA_LEN)) |
| 1264 | return -EINVAL; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1265 | |
| 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 Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1270 | ath10k_warn(ar, "failed to read hi_board_data address: %d\n", |
| 1271 | ret); |
| 1272 | return ret; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1273 | } |
| 1274 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1275 | ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), ar->debug.cal_data, |
Raja Mani | 0b8e3c4 | 2016-03-18 11:44:22 +0200 | [diff] [blame] | 1276 | ar->hw_params.cal_data_len); |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1277 | if (ret) { |
| 1278 | ath10k_warn(ar, "failed to read calibration data: %d\n", ret); |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1279 | return ret; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1280 | } |
| 1281 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1284 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1285 | static 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 Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1297 | mutex_unlock(&ar->conf_mutex); |
| 1298 | |
| 1299 | return 0; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | static ssize_t ath10k_debug_cal_data_read(struct file *file, |
| 1303 | char __user *user_buf, |
| 1304 | size_t count, loff_t *ppos) |
| 1305 | { |
Raja Mani | 0b8e3c4 | 2016-03-18 11:44:22 +0200 | [diff] [blame] | 1306 | struct ath10k *ar = file->private_data; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1307 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1308 | mutex_lock(&ar->conf_mutex); |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1309 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1310 | count = simple_read_from_buffer(user_buf, count, ppos, |
| 1311 | ar->debug.cal_data, |
| 1312 | ar->hw_params.cal_data_len); |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1313 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1314 | mutex_unlock(&ar->conf_mutex); |
| 1315 | |
| 1316 | return count; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1317 | } |
| 1318 | |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 1319 | static 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 | |
| 1347 | exit: |
| 1348 | mutex_unlock(&ar->conf_mutex); |
| 1349 | |
| 1350 | return ret; |
| 1351 | } |
| 1352 | |
| 1353 | static 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ński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1357 | size_t len; |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 1358 | char buf[32]; |
| 1359 | |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1360 | len = scnprintf(buf, sizeof(buf), "%d\n", ar->ani_enabled); |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 1361 | |
| 1362 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1363 | } |
| 1364 | |
| 1365 | static 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 Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1373 | static const struct file_operations fops_cal_data = { |
| 1374 | .open = ath10k_debug_cal_data_open, |
| 1375 | .read = ath10k_debug_cal_data_read, |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1376 | .owner = THIS_MODULE, |
| 1377 | .llseek = default_llseek, |
| 1378 | }; |
| 1379 | |
Peter Oh | a7bd3e9 | 2014-12-02 13:07:14 +0200 | [diff] [blame] | 1380 | static 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ński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1385 | size_t len; |
Peter Oh | a7bd3e9 | 2014-12-02 13:07:14 +0200 | [diff] [blame] | 1386 | char buf[32]; |
| 1387 | |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1388 | len = scnprintf(buf, sizeof(buf), "%d\n", ar->debug.nf_cal_period); |
Peter Oh | a7bd3e9 | 2014-12-02 13:07:14 +0200 | [diff] [blame] | 1389 | |
| 1390 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1391 | } |
| 1392 | |
| 1393 | static 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 | |
| 1432 | exit: |
| 1433 | mutex_unlock(&ar->conf_mutex); |
| 1434 | |
| 1435 | return ret; |
| 1436 | } |
| 1437 | |
| 1438 | static 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 Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1446 | #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024) |
| 1447 | |
| 1448 | static 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 | |
| 1471 | void 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 | |
Maharaja Kennadyrajan | bc64d05 | 2018-03-14 12:14:08 +0200 | [diff] [blame] | 1483 | void |
| 1484 | ath10k_debug_tpc_stats_final_process(struct ath10k *ar, |
| 1485 | struct ath10k_tpc_stats_final *tpc_stats) |
| 1486 | { |
| 1487 | spin_lock_bh(&ar->data_lock); |
| 1488 | |
| 1489 | kfree(ar->debug.tpc_stats_final); |
| 1490 | ar->debug.tpc_stats_final = tpc_stats; |
| 1491 | complete(&ar->debug.tpc_complete); |
| 1492 | |
| 1493 | spin_unlock_bh(&ar->data_lock); |
| 1494 | } |
| 1495 | |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1496 | static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats, |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1497 | unsigned int j, char *buf, size_t *len) |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1498 | { |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1499 | int i; |
| 1500 | size_t buf_len; |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1501 | static const char table_str[][5] = { "CDD", |
| 1502 | "STBC", |
| 1503 | "TXBF" }; |
| 1504 | static const char pream_str[][6] = { "CCK", |
| 1505 | "OFDM", |
| 1506 | "HT20", |
| 1507 | "HT40", |
| 1508 | "VHT20", |
| 1509 | "VHT40", |
| 1510 | "VHT80", |
| 1511 | "HTCUP" }; |
| 1512 | |
| 1513 | buf_len = ATH10K_TPC_CONFIG_BUF_SIZE; |
| 1514 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1515 | "********************************\n"); |
| 1516 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1517 | "******************* %s POWER TABLE ****************\n", |
| 1518 | table_str[j]); |
| 1519 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1520 | "********************************\n"); |
| 1521 | *len += scnprintf(buf + *len, buf_len - *len, |
Tamizh Chelvam | 4b19067 | 2018-04-25 11:36:44 +0300 | [diff] [blame] | 1522 | "No. Preamble Rate_code "); |
| 1523 | |
| 1524 | for (i = 0; i < WMI_TPC_TX_N_CHAIN; i++) |
| 1525 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1526 | "tpc_value%d ", i); |
| 1527 | |
| 1528 | *len += scnprintf(buf + *len, buf_len - *len, "\n"); |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1529 | |
| 1530 | for (i = 0; i < tpc_stats->rate_max; i++) { |
| 1531 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1532 | "%8d %s 0x%2x %s\n", i, |
| 1533 | pream_str[tpc_stats->tpc_table[j].pream_idx[i]], |
| 1534 | tpc_stats->tpc_table[j].rate_code[i], |
| 1535 | tpc_stats->tpc_table[j].tpc_value[i]); |
| 1536 | } |
| 1537 | |
| 1538 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1539 | "***********************************\n"); |
| 1540 | } |
| 1541 | |
| 1542 | static void ath10k_tpc_stats_fill(struct ath10k *ar, |
| 1543 | struct ath10k_tpc_stats *tpc_stats, |
| 1544 | char *buf) |
| 1545 | { |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1546 | int j; |
| 1547 | size_t len, buf_len; |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1548 | |
| 1549 | len = 0; |
| 1550 | buf_len = ATH10K_TPC_CONFIG_BUF_SIZE; |
| 1551 | |
| 1552 | spin_lock_bh(&ar->data_lock); |
| 1553 | |
| 1554 | if (!tpc_stats) { |
| 1555 | ath10k_warn(ar, "failed to get tpc stats\n"); |
| 1556 | goto unlock; |
| 1557 | } |
| 1558 | |
| 1559 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 1560 | len += scnprintf(buf + len, buf_len - len, |
| 1561 | "*************************************\n"); |
| 1562 | len += scnprintf(buf + len, buf_len - len, |
| 1563 | "TPC config for channel %4d mode %d\n", |
| 1564 | tpc_stats->chan_freq, |
| 1565 | tpc_stats->phy_mode); |
| 1566 | len += scnprintf(buf + len, buf_len - len, |
| 1567 | "*************************************\n"); |
| 1568 | len += scnprintf(buf + len, buf_len - len, |
| 1569 | "CTL = 0x%2x Reg. Domain = %2d\n", |
| 1570 | tpc_stats->ctl, |
| 1571 | tpc_stats->reg_domain); |
| 1572 | len += scnprintf(buf + len, buf_len - len, |
| 1573 | "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n", |
| 1574 | tpc_stats->twice_antenna_gain, |
| 1575 | tpc_stats->twice_antenna_reduction); |
| 1576 | len += scnprintf(buf + len, buf_len - len, |
| 1577 | "Power Limit = %2d Reg. Max Power = %2d\n", |
| 1578 | tpc_stats->power_limit, |
| 1579 | tpc_stats->twice_max_rd_power / 2); |
| 1580 | len += scnprintf(buf + len, buf_len - len, |
| 1581 | "Num tx chains = %2d Num supported rates = %2d\n", |
| 1582 | tpc_stats->num_tx_chain, |
| 1583 | tpc_stats->rate_max); |
| 1584 | |
Maharaja Kennadyrajan | e871fb6 | 2017-03-31 17:39:40 +0530 | [diff] [blame] | 1585 | for (j = 0; j < WMI_TPC_FLAG; j++) { |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1586 | switch (j) { |
| 1587 | case WMI_TPC_TABLE_TYPE_CDD: |
| 1588 | if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) { |
| 1589 | len += scnprintf(buf + len, buf_len - len, |
| 1590 | "CDD not supported\n"); |
| 1591 | break; |
| 1592 | } |
| 1593 | |
| 1594 | ath10k_tpc_stats_print(tpc_stats, j, buf, &len); |
| 1595 | break; |
| 1596 | case WMI_TPC_TABLE_TYPE_STBC: |
| 1597 | if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) { |
| 1598 | len += scnprintf(buf + len, buf_len - len, |
| 1599 | "STBC not supported\n"); |
| 1600 | break; |
| 1601 | } |
| 1602 | |
| 1603 | ath10k_tpc_stats_print(tpc_stats, j, buf, &len); |
| 1604 | break; |
| 1605 | case WMI_TPC_TABLE_TYPE_TXBF: |
| 1606 | if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) { |
| 1607 | len += scnprintf(buf + len, buf_len - len, |
| 1608 | "TXBF not supported\n***************************\n"); |
| 1609 | break; |
| 1610 | } |
| 1611 | |
| 1612 | ath10k_tpc_stats_print(tpc_stats, j, buf, &len); |
| 1613 | break; |
| 1614 | default: |
| 1615 | len += scnprintf(buf + len, buf_len - len, |
| 1616 | "Invalid Type\n"); |
| 1617 | break; |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | unlock: |
| 1622 | spin_unlock_bh(&ar->data_lock); |
| 1623 | |
| 1624 | if (len >= buf_len) |
| 1625 | buf[len - 1] = 0; |
| 1626 | else |
| 1627 | buf[len] = 0; |
| 1628 | } |
| 1629 | |
| 1630 | static int ath10k_tpc_stats_open(struct inode *inode, struct file *file) |
| 1631 | { |
| 1632 | struct ath10k *ar = inode->i_private; |
| 1633 | void *buf = NULL; |
| 1634 | int ret; |
| 1635 | |
| 1636 | mutex_lock(&ar->conf_mutex); |
| 1637 | |
| 1638 | if (ar->state != ATH10K_STATE_ON) { |
| 1639 | ret = -ENETDOWN; |
| 1640 | goto err_unlock; |
| 1641 | } |
| 1642 | |
| 1643 | buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE); |
| 1644 | if (!buf) { |
| 1645 | ret = -ENOMEM; |
| 1646 | goto err_unlock; |
| 1647 | } |
| 1648 | |
| 1649 | ret = ath10k_debug_tpc_stats_request(ar); |
| 1650 | if (ret) { |
| 1651 | ath10k_warn(ar, "failed to request tpc config stats: %d\n", |
| 1652 | ret); |
| 1653 | goto err_free; |
| 1654 | } |
| 1655 | |
| 1656 | ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf); |
| 1657 | file->private_data = buf; |
| 1658 | |
| 1659 | mutex_unlock(&ar->conf_mutex); |
| 1660 | return 0; |
| 1661 | |
| 1662 | err_free: |
| 1663 | vfree(buf); |
| 1664 | |
| 1665 | err_unlock: |
| 1666 | mutex_unlock(&ar->conf_mutex); |
| 1667 | return ret; |
| 1668 | } |
| 1669 | |
| 1670 | static int ath10k_tpc_stats_release(struct inode *inode, struct file *file) |
| 1671 | { |
| 1672 | vfree(file->private_data); |
| 1673 | |
| 1674 | return 0; |
| 1675 | } |
| 1676 | |
| 1677 | static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf, |
| 1678 | size_t count, loff_t *ppos) |
| 1679 | { |
| 1680 | const char *buf = file->private_data; |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 1681 | size_t len = strlen(buf); |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1682 | |
| 1683 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1684 | } |
| 1685 | |
| 1686 | static const struct file_operations fops_tpc_stats = { |
| 1687 | .open = ath10k_tpc_stats_open, |
| 1688 | .release = ath10k_tpc_stats_release, |
| 1689 | .read = ath10k_tpc_stats_read, |
| 1690 | .owner = THIS_MODULE, |
| 1691 | .llseek = default_llseek, |
| 1692 | }; |
| 1693 | |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1694 | int ath10k_debug_start(struct ath10k *ar) |
| 1695 | { |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1696 | int ret; |
| 1697 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1698 | lockdep_assert_held(&ar->conf_mutex); |
| 1699 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1700 | ret = ath10k_debug_htt_stats_req(ar); |
| 1701 | if (ret) |
| 1702 | /* continue normally anyway, this isn't serious */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1703 | ath10k_warn(ar, "failed to start htt stats workqueue: %d\n", |
| 1704 | ret); |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1705 | |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1706 | if (ar->debug.fw_dbglog_mask) { |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1707 | ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask, |
| 1708 | ATH10K_DBGLOG_LEVEL_WARN); |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1709 | if (ret) |
| 1710 | /* not serious */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1711 | ath10k_warn(ar, "failed to enable dbglog during start: %d", |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1712 | ret); |
| 1713 | } |
| 1714 | |
Anilkumar Kolli | 7f9befb | 2017-12-05 19:01:24 +0530 | [diff] [blame] | 1715 | if (ar->pktlog_filter) { |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1716 | ret = ath10k_wmi_pdev_pktlog_enable(ar, |
Anilkumar Kolli | 7f9befb | 2017-12-05 19:01:24 +0530 | [diff] [blame] | 1717 | ar->pktlog_filter); |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1718 | if (ret) |
| 1719 | /* not serious */ |
| 1720 | ath10k_warn(ar, |
| 1721 | "failed to enable pktlog filter %x: %d\n", |
Anilkumar Kolli | 7f9befb | 2017-12-05 19:01:24 +0530 | [diff] [blame] | 1722 | ar->pktlog_filter, ret); |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1723 | } else { |
| 1724 | ret = ath10k_wmi_pdev_pktlog_disable(ar); |
| 1725 | if (ret) |
| 1726 | /* not serious */ |
| 1727 | ath10k_warn(ar, "failed to disable pktlog: %d\n", ret); |
| 1728 | } |
| 1729 | |
Surabhi Vishnoi | 5db98ae | 2018-06-13 10:33:35 +0530 | [diff] [blame] | 1730 | if (ar->debug.nf_cal_period && |
| 1731 | !test_bit(ATH10K_FW_FEATURE_NON_BMI, |
| 1732 | ar->normal_mode_fw.fw_file.fw_features)) { |
Peter Oh | a7bd3e9 | 2014-12-02 13:07:14 +0200 | [diff] [blame] | 1733 | ret = ath10k_wmi_pdev_set_param(ar, |
| 1734 | ar->wmi.pdev_param->cal_period, |
| 1735 | ar->debug.nf_cal_period); |
| 1736 | if (ret) |
| 1737 | /* not serious */ |
| 1738 | ath10k_warn(ar, "cal period cfg failed from debug start: %d\n", |
| 1739 | ret); |
| 1740 | } |
| 1741 | |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1742 | return ret; |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | void ath10k_debug_stop(struct ath10k *ar) |
| 1746 | { |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1747 | lockdep_assert_held(&ar->conf_mutex); |
| 1748 | |
Surabhi Vishnoi | 5db98ae | 2018-06-13 10:33:35 +0530 | [diff] [blame] | 1749 | if (!test_bit(ATH10K_FW_FEATURE_NON_BMI, |
| 1750 | ar->normal_mode_fw.fw_file.fw_features)) |
| 1751 | ath10k_debug_cal_data_fetch(ar); |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1752 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1753 | /* Must not use _sync to avoid deadlock, we do that in |
| 1754 | * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 1755 | * warning from del_timer(). |
| 1756 | */ |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1757 | if (ar->debug.htt_stats_mask != 0) |
| 1758 | cancel_delayed_work(&ar->debug.htt_stats_dwork); |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1759 | |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1760 | ath10k_wmi_pdev_pktlog_disable(ar); |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1761 | } |
| 1762 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1763 | static ssize_t ath10k_write_simulate_radar(struct file *file, |
| 1764 | const char __user *user_buf, |
| 1765 | size_t count, loff_t *ppos) |
| 1766 | { |
| 1767 | struct ath10k *ar = file->private_data; |
Mohammed Shafi Shajakhan | ca07baa | 2017-02-22 21:03:11 +0530 | [diff] [blame] | 1768 | struct ath10k_vif *arvif; |
| 1769 | |
| 1770 | /* Just check for for the first vif alone, as all the vifs will be |
| 1771 | * sharing the same channel and if the channel is disabled, all the |
| 1772 | * vifs will share the same 'is_started' state. |
| 1773 | */ |
| 1774 | arvif = list_first_entry(&ar->arvifs, typeof(*arvif), list); |
| 1775 | if (!arvif->is_started) |
| 1776 | return -EINVAL; |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1777 | |
| 1778 | ieee80211_radar_detected(ar->hw); |
| 1779 | |
| 1780 | return count; |
| 1781 | } |
| 1782 | |
| 1783 | static const struct file_operations fops_simulate_radar = { |
| 1784 | .write = ath10k_write_simulate_radar, |
| 1785 | .open = simple_open, |
| 1786 | .owner = THIS_MODULE, |
| 1787 | .llseek = default_llseek, |
| 1788 | }; |
| 1789 | |
| 1790 | #define ATH10K_DFS_STAT(s, p) (\ |
| 1791 | len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \ |
| 1792 | ar->debug.dfs_stats.p)) |
| 1793 | |
| 1794 | #define ATH10K_DFS_POOL_STAT(s, p) (\ |
| 1795 | len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \ |
| 1796 | ar->debug.dfs_pool_stats.p)) |
| 1797 | |
| 1798 | static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf, |
| 1799 | size_t count, loff_t *ppos) |
| 1800 | { |
| 1801 | int retval = 0, len = 0; |
| 1802 | const int size = 8000; |
| 1803 | struct ath10k *ar = file->private_data; |
| 1804 | char *buf; |
| 1805 | |
| 1806 | buf = kzalloc(size, GFP_KERNEL); |
| 1807 | if (buf == NULL) |
| 1808 | return -ENOMEM; |
| 1809 | |
| 1810 | if (!ar->dfs_detector) { |
| 1811 | len += scnprintf(buf + len, size - len, "DFS not enabled\n"); |
| 1812 | goto exit; |
| 1813 | } |
| 1814 | |
| 1815 | ar->debug.dfs_pool_stats = |
| 1816 | ar->dfs_detector->get_stats(ar->dfs_detector); |
| 1817 | |
| 1818 | len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n"); |
| 1819 | |
| 1820 | ATH10K_DFS_STAT("reported phy errors", phy_errors); |
| 1821 | ATH10K_DFS_STAT("pulse events reported", pulses_total); |
| 1822 | ATH10K_DFS_STAT("DFS pulses detected", pulses_detected); |
| 1823 | ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded); |
| 1824 | ATH10K_DFS_STAT("Radars detected", radar_detected); |
| 1825 | |
| 1826 | len += scnprintf(buf + len, size - len, "Global Pool statistics:\n"); |
| 1827 | ATH10K_DFS_POOL_STAT("Pool references", pool_reference); |
| 1828 | ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated); |
| 1829 | ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error); |
| 1830 | ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used); |
| 1831 | ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated); |
| 1832 | ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error); |
| 1833 | ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used); |
| 1834 | |
| 1835 | exit: |
| 1836 | if (len > size) |
| 1837 | len = size; |
| 1838 | |
| 1839 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1840 | kfree(buf); |
| 1841 | |
| 1842 | return retval; |
| 1843 | } |
| 1844 | |
| 1845 | static const struct file_operations fops_dfs_stats = { |
| 1846 | .read = ath10k_read_dfs_stats, |
| 1847 | .open = simple_open, |
| 1848 | .owner = THIS_MODULE, |
| 1849 | .llseek = default_llseek, |
| 1850 | }; |
| 1851 | |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1852 | static ssize_t ath10k_write_pktlog_filter(struct file *file, |
| 1853 | const char __user *ubuf, |
| 1854 | size_t count, loff_t *ppos) |
| 1855 | { |
| 1856 | struct ath10k *ar = file->private_data; |
| 1857 | u32 filter; |
| 1858 | int ret; |
| 1859 | |
| 1860 | if (kstrtouint_from_user(ubuf, count, 0, &filter)) |
| 1861 | return -EINVAL; |
| 1862 | |
| 1863 | mutex_lock(&ar->conf_mutex); |
| 1864 | |
| 1865 | if (ar->state != ATH10K_STATE_ON) { |
Anilkumar Kolli | 7f9befb | 2017-12-05 19:01:24 +0530 | [diff] [blame] | 1866 | ar->pktlog_filter = filter; |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1867 | ret = count; |
| 1868 | goto out; |
| 1869 | } |
| 1870 | |
Anilkumar Kolli | 7f9befb | 2017-12-05 19:01:24 +0530 | [diff] [blame] | 1871 | if (filter == ar->pktlog_filter) { |
Anilkumar Kolli | 9ddc486 | 2016-03-11 11:46:39 +0530 | [diff] [blame] | 1872 | ret = count; |
| 1873 | goto out; |
| 1874 | } |
| 1875 | |
| 1876 | if (filter) { |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1877 | ret = ath10k_wmi_pdev_pktlog_enable(ar, filter); |
| 1878 | if (ret) { |
| 1879 | ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n", |
Anilkumar Kolli | 7f9befb | 2017-12-05 19:01:24 +0530 | [diff] [blame] | 1880 | ar->pktlog_filter, ret); |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1881 | goto out; |
| 1882 | } |
| 1883 | } else { |
| 1884 | ret = ath10k_wmi_pdev_pktlog_disable(ar); |
| 1885 | if (ret) { |
| 1886 | ath10k_warn(ar, "failed to disable pktlog: %d\n", ret); |
| 1887 | goto out; |
| 1888 | } |
| 1889 | } |
| 1890 | |
Anilkumar Kolli | 7f9befb | 2017-12-05 19:01:24 +0530 | [diff] [blame] | 1891 | ar->pktlog_filter = filter; |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1892 | ret = count; |
| 1893 | |
| 1894 | out: |
| 1895 | mutex_unlock(&ar->conf_mutex); |
| 1896 | return ret; |
| 1897 | } |
| 1898 | |
| 1899 | static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf, |
| 1900 | size_t count, loff_t *ppos) |
| 1901 | { |
| 1902 | char buf[32]; |
| 1903 | struct ath10k *ar = file->private_data; |
| 1904 | int len = 0; |
| 1905 | |
| 1906 | mutex_lock(&ar->conf_mutex); |
| 1907 | len = scnprintf(buf, sizeof(buf) - len, "%08x\n", |
Anilkumar Kolli | 7f9befb | 2017-12-05 19:01:24 +0530 | [diff] [blame] | 1908 | ar->pktlog_filter); |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1909 | mutex_unlock(&ar->conf_mutex); |
| 1910 | |
| 1911 | return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 1912 | } |
| 1913 | |
| 1914 | static const struct file_operations fops_pktlog_filter = { |
| 1915 | .read = ath10k_read_pktlog_filter, |
| 1916 | .write = ath10k_write_pktlog_filter, |
| 1917 | .open = simple_open |
| 1918 | }; |
| 1919 | |
Rajkumar Manoharan | 63fb32d | 2015-03-15 20:36:20 +0530 | [diff] [blame] | 1920 | static ssize_t ath10k_write_quiet_period(struct file *file, |
| 1921 | const char __user *ubuf, |
| 1922 | size_t count, loff_t *ppos) |
| 1923 | { |
| 1924 | struct ath10k *ar = file->private_data; |
| 1925 | u32 period; |
| 1926 | |
| 1927 | if (kstrtouint_from_user(ubuf, count, 0, &period)) |
| 1928 | return -EINVAL; |
| 1929 | |
| 1930 | if (period < ATH10K_QUIET_PERIOD_MIN) { |
| 1931 | ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n", |
| 1932 | period); |
| 1933 | return -EINVAL; |
| 1934 | } |
| 1935 | mutex_lock(&ar->conf_mutex); |
| 1936 | ar->thermal.quiet_period = period; |
Rajkumar Manoharan | 8515b5c | 2015-03-15 20:36:22 +0530 | [diff] [blame] | 1937 | ath10k_thermal_set_throttling(ar); |
Rajkumar Manoharan | 63fb32d | 2015-03-15 20:36:20 +0530 | [diff] [blame] | 1938 | mutex_unlock(&ar->conf_mutex); |
| 1939 | |
| 1940 | return count; |
| 1941 | } |
| 1942 | |
| 1943 | static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf, |
| 1944 | size_t count, loff_t *ppos) |
| 1945 | { |
| 1946 | char buf[32]; |
| 1947 | struct ath10k *ar = file->private_data; |
| 1948 | int len = 0; |
| 1949 | |
| 1950 | mutex_lock(&ar->conf_mutex); |
| 1951 | len = scnprintf(buf, sizeof(buf) - len, "%d\n", |
| 1952 | ar->thermal.quiet_period); |
| 1953 | mutex_unlock(&ar->conf_mutex); |
| 1954 | |
| 1955 | return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 1956 | } |
| 1957 | |
| 1958 | static const struct file_operations fops_quiet_period = { |
| 1959 | .read = ath10k_read_quiet_period, |
| 1960 | .write = ath10k_write_quiet_period, |
| 1961 | .open = simple_open |
| 1962 | }; |
| 1963 | |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 1964 | static ssize_t ath10k_write_btcoex(struct file *file, |
| 1965 | const char __user *ubuf, |
| 1966 | size_t count, loff_t *ppos) |
| 1967 | { |
| 1968 | struct ath10k *ar = file->private_data; |
| 1969 | char buf[32]; |
| 1970 | size_t buf_size; |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 1971 | int ret; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 1972 | bool val; |
Rajkumar Manoharan | 3913624 | 2016-05-27 20:15:59 +0530 | [diff] [blame] | 1973 | u32 pdev_param; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 1974 | |
| 1975 | buf_size = min(count, (sizeof(buf) - 1)); |
| 1976 | if (copy_from_user(buf, ubuf, buf_size)) |
| 1977 | return -EFAULT; |
| 1978 | |
| 1979 | buf[buf_size] = '\0'; |
| 1980 | |
| 1981 | if (strtobool(buf, &val) != 0) |
| 1982 | return -EINVAL; |
| 1983 | |
| 1984 | mutex_lock(&ar->conf_mutex); |
| 1985 | |
Mohammed Shafi Shajakhan | c28e6f0 | 2016-02-23 12:58:36 +0530 | [diff] [blame] | 1986 | if (ar->state != ATH10K_STATE_ON && |
| 1987 | ar->state != ATH10K_STATE_RESTARTED) { |
| 1988 | ret = -ENETDOWN; |
| 1989 | goto exit; |
| 1990 | } |
| 1991 | |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 1992 | if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val)) { |
| 1993 | ret = count; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 1994 | goto exit; |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 1995 | } |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 1996 | |
Rajkumar Manoharan | 3913624 | 2016-05-27 20:15:59 +0530 | [diff] [blame] | 1997 | pdev_param = ar->wmi.pdev_param->enable_btcoex; |
| 1998 | if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM, |
| 1999 | ar->running_fw->fw_file.fw_features)) { |
| 2000 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, val); |
| 2001 | if (ret) { |
| 2002 | ath10k_warn(ar, "failed to enable btcoex: %d\n", ret); |
| 2003 | ret = count; |
| 2004 | goto exit; |
| 2005 | } |
| 2006 | } else { |
| 2007 | ath10k_info(ar, "restarting firmware due to btcoex change"); |
| 2008 | queue_work(ar->workqueue, &ar->restart_work); |
| 2009 | } |
| 2010 | |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2011 | if (val) |
| 2012 | set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags); |
| 2013 | else |
| 2014 | clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags); |
| 2015 | |
Mohammed Shafi Shajakhan | c28e6f0 | 2016-02-23 12:58:36 +0530 | [diff] [blame] | 2016 | ret = count; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2017 | |
| 2018 | exit: |
| 2019 | mutex_unlock(&ar->conf_mutex); |
| 2020 | |
Mohammed Shafi Shajakhan | c28e6f0 | 2016-02-23 12:58:36 +0530 | [diff] [blame] | 2021 | return ret; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | static ssize_t ath10k_read_btcoex(struct file *file, char __user *ubuf, |
| 2025 | size_t count, loff_t *ppos) |
| 2026 | { |
| 2027 | char buf[32]; |
| 2028 | struct ath10k *ar = file->private_data; |
| 2029 | int len = 0; |
| 2030 | |
| 2031 | mutex_lock(&ar->conf_mutex); |
| 2032 | len = scnprintf(buf, sizeof(buf) - len, "%d\n", |
| 2033 | test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags)); |
| 2034 | mutex_unlock(&ar->conf_mutex); |
| 2035 | |
| 2036 | return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 2037 | } |
| 2038 | |
| 2039 | static const struct file_operations fops_btcoex = { |
| 2040 | .read = ath10k_read_btcoex, |
| 2041 | .write = ath10k_write_btcoex, |
| 2042 | .open = simple_open |
| 2043 | }; |
| 2044 | |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2045 | static ssize_t ath10k_write_peer_stats(struct file *file, |
| 2046 | const char __user *ubuf, |
| 2047 | size_t count, loff_t *ppos) |
| 2048 | { |
| 2049 | struct ath10k *ar = file->private_data; |
| 2050 | char buf[32]; |
| 2051 | size_t buf_size; |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2052 | int ret; |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2053 | bool val; |
| 2054 | |
| 2055 | buf_size = min(count, (sizeof(buf) - 1)); |
| 2056 | if (copy_from_user(buf, ubuf, buf_size)) |
| 2057 | return -EFAULT; |
| 2058 | |
| 2059 | buf[buf_size] = '\0'; |
| 2060 | |
| 2061 | if (strtobool(buf, &val) != 0) |
| 2062 | return -EINVAL; |
| 2063 | |
| 2064 | mutex_lock(&ar->conf_mutex); |
| 2065 | |
| 2066 | if (ar->state != ATH10K_STATE_ON && |
| 2067 | ar->state != ATH10K_STATE_RESTARTED) { |
| 2068 | ret = -ENETDOWN; |
| 2069 | goto exit; |
| 2070 | } |
| 2071 | |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2072 | if (!(test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags) ^ val)) { |
| 2073 | ret = count; |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2074 | goto exit; |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2075 | } |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2076 | |
| 2077 | if (val) |
| 2078 | set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags); |
| 2079 | else |
| 2080 | clear_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags); |
| 2081 | |
| 2082 | ath10k_info(ar, "restarting firmware due to Peer stats change"); |
| 2083 | |
| 2084 | queue_work(ar->workqueue, &ar->restart_work); |
| 2085 | ret = count; |
| 2086 | |
| 2087 | exit: |
| 2088 | mutex_unlock(&ar->conf_mutex); |
| 2089 | return ret; |
| 2090 | } |
| 2091 | |
| 2092 | static ssize_t ath10k_read_peer_stats(struct file *file, char __user *ubuf, |
| 2093 | size_t count, loff_t *ppos) |
| 2094 | |
| 2095 | { |
| 2096 | char buf[32]; |
| 2097 | struct ath10k *ar = file->private_data; |
| 2098 | int len = 0; |
| 2099 | |
| 2100 | mutex_lock(&ar->conf_mutex); |
| 2101 | len = scnprintf(buf, sizeof(buf) - len, "%d\n", |
| 2102 | test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags)); |
| 2103 | mutex_unlock(&ar->conf_mutex); |
| 2104 | |
| 2105 | return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 2106 | } |
| 2107 | |
| 2108 | static const struct file_operations fops_peer_stats = { |
| 2109 | .read = ath10k_read_peer_stats, |
| 2110 | .write = ath10k_write_peer_stats, |
| 2111 | .open = simple_open |
| 2112 | }; |
| 2113 | |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2114 | static ssize_t ath10k_debug_fw_checksums_read(struct file *file, |
| 2115 | char __user *user_buf, |
| 2116 | size_t count, loff_t *ppos) |
| 2117 | { |
| 2118 | struct ath10k *ar = file->private_data; |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 2119 | size_t len = 0, buf_len = 4096; |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2120 | ssize_t ret_cnt; |
| 2121 | char *buf; |
| 2122 | |
| 2123 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 2124 | if (!buf) |
| 2125 | return -ENOMEM; |
| 2126 | |
| 2127 | mutex_lock(&ar->conf_mutex); |
| 2128 | |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2129 | len += scnprintf(buf + len, buf_len - len, |
| 2130 | "firmware-N.bin\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2131 | crc32_le(0, ar->normal_mode_fw.fw_file.firmware->data, |
| 2132 | ar->normal_mode_fw.fw_file.firmware->size)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2133 | len += scnprintf(buf + len, buf_len - len, |
| 2134 | "athwlan\t\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2135 | crc32_le(0, ar->normal_mode_fw.fw_file.firmware_data, |
| 2136 | ar->normal_mode_fw.fw_file.firmware_len)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2137 | len += scnprintf(buf + len, buf_len - len, |
| 2138 | "otp\t\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2139 | crc32_le(0, ar->normal_mode_fw.fw_file.otp_data, |
| 2140 | ar->normal_mode_fw.fw_file.otp_len)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2141 | len += scnprintf(buf + len, buf_len - len, |
| 2142 | "codeswap\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2143 | crc32_le(0, ar->normal_mode_fw.fw_file.codeswap_data, |
| 2144 | ar->normal_mode_fw.fw_file.codeswap_len)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2145 | len += scnprintf(buf + len, buf_len - len, |
| 2146 | "board-N.bin\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2147 | crc32_le(0, ar->normal_mode_fw.board->data, |
| 2148 | ar->normal_mode_fw.board->size)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2149 | len += scnprintf(buf + len, buf_len - len, |
| 2150 | "board\t\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2151 | crc32_le(0, ar->normal_mode_fw.board_data, |
| 2152 | ar->normal_mode_fw.board_len)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2153 | |
| 2154 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 2155 | |
| 2156 | mutex_unlock(&ar->conf_mutex); |
| 2157 | |
| 2158 | kfree(buf); |
| 2159 | return ret_cnt; |
| 2160 | } |
| 2161 | |
| 2162 | static const struct file_operations fops_fw_checksums = { |
| 2163 | .read = ath10k_debug_fw_checksums_read, |
| 2164 | .open = simple_open, |
| 2165 | .owner = THIS_MODULE, |
| 2166 | .llseek = default_llseek, |
| 2167 | }; |
| 2168 | |
Vasanthakumar Thiagarajan | caee728 | 2018-03-14 12:14:06 +0200 | [diff] [blame] | 2169 | static ssize_t ath10k_sta_tid_stats_mask_read(struct file *file, |
| 2170 | char __user *user_buf, |
| 2171 | size_t count, loff_t *ppos) |
| 2172 | { |
| 2173 | struct ath10k *ar = file->private_data; |
| 2174 | char buf[32]; |
| 2175 | size_t len; |
| 2176 | |
| 2177 | len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->sta_tid_stats_mask); |
| 2178 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 2179 | } |
| 2180 | |
| 2181 | static ssize_t ath10k_sta_tid_stats_mask_write(struct file *file, |
| 2182 | const char __user *user_buf, |
| 2183 | size_t count, loff_t *ppos) |
| 2184 | { |
| 2185 | struct ath10k *ar = file->private_data; |
| 2186 | char buf[32]; |
| 2187 | ssize_t len; |
| 2188 | u32 mask; |
| 2189 | |
| 2190 | len = min(count, sizeof(buf) - 1); |
| 2191 | if (copy_from_user(buf, user_buf, len)) |
| 2192 | return -EFAULT; |
| 2193 | |
| 2194 | buf[len] = '\0'; |
| 2195 | if (kstrtoint(buf, 0, &mask)) |
| 2196 | return -EINVAL; |
| 2197 | |
| 2198 | ar->sta_tid_stats_mask = mask; |
| 2199 | |
| 2200 | return len; |
| 2201 | } |
| 2202 | |
| 2203 | static const struct file_operations fops_sta_tid_stats_mask = { |
| 2204 | .read = ath10k_sta_tid_stats_mask_read, |
| 2205 | .write = ath10k_sta_tid_stats_mask_write, |
| 2206 | .open = simple_open, |
| 2207 | .owner = THIS_MODULE, |
| 2208 | .llseek = default_llseek, |
| 2209 | }; |
| 2210 | |
Maharaja Kennadyrajan | bc64d05 | 2018-03-14 12:14:08 +0200 | [diff] [blame] | 2211 | static int ath10k_debug_tpc_stats_final_request(struct ath10k *ar) |
| 2212 | { |
| 2213 | int ret; |
| 2214 | unsigned long time_left; |
| 2215 | |
| 2216 | lockdep_assert_held(&ar->conf_mutex); |
| 2217 | |
| 2218 | reinit_completion(&ar->debug.tpc_complete); |
| 2219 | |
| 2220 | ret = ath10k_wmi_pdev_get_tpc_table_cmdid(ar, WMI_TPC_CONFIG_PARAM); |
| 2221 | if (ret) { |
| 2222 | ath10k_warn(ar, "failed to request tpc table cmdid: %d\n", ret); |
| 2223 | return ret; |
| 2224 | } |
| 2225 | |
| 2226 | time_left = wait_for_completion_timeout(&ar->debug.tpc_complete, |
| 2227 | 1 * HZ); |
| 2228 | if (time_left == 0) |
| 2229 | return -ETIMEDOUT; |
| 2230 | |
| 2231 | return 0; |
| 2232 | } |
| 2233 | |
| 2234 | static int ath10k_tpc_stats_final_open(struct inode *inode, struct file *file) |
| 2235 | { |
| 2236 | struct ath10k *ar = inode->i_private; |
| 2237 | void *buf; |
| 2238 | int ret; |
| 2239 | |
| 2240 | mutex_lock(&ar->conf_mutex); |
| 2241 | |
| 2242 | if (ar->state != ATH10K_STATE_ON) { |
| 2243 | ret = -ENETDOWN; |
| 2244 | goto err_unlock; |
| 2245 | } |
| 2246 | |
| 2247 | buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE); |
| 2248 | if (!buf) { |
| 2249 | ret = -ENOMEM; |
| 2250 | goto err_unlock; |
| 2251 | } |
| 2252 | |
| 2253 | ret = ath10k_debug_tpc_stats_final_request(ar); |
| 2254 | if (ret) { |
| 2255 | ath10k_warn(ar, "failed to request tpc stats final: %d\n", |
| 2256 | ret); |
| 2257 | goto err_free; |
| 2258 | } |
| 2259 | |
| 2260 | ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf); |
| 2261 | file->private_data = buf; |
| 2262 | |
| 2263 | mutex_unlock(&ar->conf_mutex); |
| 2264 | return 0; |
| 2265 | |
| 2266 | err_free: |
| 2267 | vfree(buf); |
| 2268 | |
| 2269 | err_unlock: |
| 2270 | mutex_unlock(&ar->conf_mutex); |
| 2271 | return ret; |
| 2272 | } |
| 2273 | |
| 2274 | static int ath10k_tpc_stats_final_release(struct inode *inode, |
| 2275 | struct file *file) |
| 2276 | { |
| 2277 | vfree(file->private_data); |
| 2278 | |
| 2279 | return 0; |
| 2280 | } |
| 2281 | |
| 2282 | static ssize_t ath10k_tpc_stats_final_read(struct file *file, |
| 2283 | char __user *user_buf, |
| 2284 | size_t count, loff_t *ppos) |
| 2285 | { |
| 2286 | const char *buf = file->private_data; |
| 2287 | unsigned int len = strlen(buf); |
| 2288 | |
| 2289 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 2290 | } |
| 2291 | |
| 2292 | static const struct file_operations fops_tpc_stats_final = { |
| 2293 | .open = ath10k_tpc_stats_final_open, |
| 2294 | .release = ath10k_tpc_stats_final_release, |
| 2295 | .read = ath10k_tpc_stats_final_read, |
| 2296 | .owner = THIS_MODULE, |
| 2297 | .llseek = default_llseek, |
| 2298 | }; |
| 2299 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2300 | int ath10k_debug_create(struct ath10k *ar) |
| 2301 | { |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 2302 | ar->debug.cal_data = vzalloc(ATH10K_DEBUG_CAL_DATA_LEN); |
| 2303 | if (!ar->debug.cal_data) |
| 2304 | return -ENOMEM; |
| 2305 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2306 | INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs); |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 2307 | INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2308 | INIT_LIST_HEAD(&ar->debug.fw_stats.peers); |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 2309 | INIT_LIST_HEAD(&ar->debug.fw_stats.peers_extd); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2310 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 2311 | return 0; |
| 2312 | } |
| 2313 | |
| 2314 | void ath10k_debug_destroy(struct ath10k *ar) |
| 2315 | { |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 2316 | vfree(ar->debug.cal_data); |
| 2317 | ar->debug.cal_data = NULL; |
| 2318 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2319 | ath10k_debug_fw_stats_reset(ar); |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 2320 | |
| 2321 | kfree(ar->debug.tpc_stats); |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | int ath10k_debug_register(struct ath10k *ar) |
| 2325 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2326 | ar->debug.debugfs_phy = debugfs_create_dir("ath10k", |
| 2327 | ar->hw->wiphy->debugfsdir); |
Michal Kazior | adb43b2 | 2014-09-04 12:36:45 +0200 | [diff] [blame] | 2328 | if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) { |
| 2329 | if (IS_ERR(ar->debug.debugfs_phy)) |
| 2330 | return PTR_ERR(ar->debug.debugfs_phy); |
Kalle Valo | d8bb26b | 2014-09-14 12:50:33 +0300 | [diff] [blame] | 2331 | |
| 2332 | return -ENOMEM; |
Michal Kazior | adb43b2 | 2014-09-04 12:36:45 +0200 | [diff] [blame] | 2333 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2334 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 2335 | INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork, |
| 2336 | ath10k_debug_htt_stats_dwork); |
| 2337 | |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 2338 | init_completion(&ar->debug.tpc_complete); |
Michal Kazior | 60ef401 | 2014-09-25 12:33:48 +0200 | [diff] [blame] | 2339 | init_completion(&ar->debug.fw_stats_complete); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2340 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2341 | debugfs_create_file("fw_stats", 0400, ar->debug.debugfs_phy, ar, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2342 | &fops_fw_stats); |
| 2343 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2344 | debugfs_create_file("fw_reset_stats", 0400, ar->debug.debugfs_phy, ar, |
| 2345 | &fops_fw_reset_stats); |
Ben Greear | f51dbe7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 2346 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2347 | debugfs_create_file("wmi_services", 0400, ar->debug.debugfs_phy, ar, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2348 | &fops_wmi_services); |
| 2349 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2350 | debugfs_create_file("simulate_fw_crash", 0600, ar->debug.debugfs_phy, ar, |
| 2351 | &fops_simulate_fw_crash); |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 2352 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2353 | debugfs_create_file("reg_addr", 0600, ar->debug.debugfs_phy, ar, |
| 2354 | &fops_reg_addr); |
Yanbo Li | 077a380 | 2014-11-25 12:24:33 +0200 | [diff] [blame] | 2355 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2356 | debugfs_create_file("reg_value", 0600, ar->debug.debugfs_phy, ar, |
| 2357 | &fops_reg_value); |
Yanbo Li | 077a380 | 2014-11-25 12:24:33 +0200 | [diff] [blame] | 2358 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2359 | debugfs_create_file("mem_value", 0600, ar->debug.debugfs_phy, ar, |
| 2360 | &fops_mem_value); |
Yanbo Li | 9f65ad2 | 2014-11-25 12:24:48 +0200 | [diff] [blame] | 2361 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2362 | debugfs_create_file("chip_id", 0400, ar->debug.debugfs_phy, ar, |
| 2363 | &fops_chip_id); |
Kalle Valo | 763b8cd | 2013-09-01 11:22:21 +0300 | [diff] [blame] | 2364 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2365 | debugfs_create_file("htt_stats_mask", 0600, ar->debug.debugfs_phy, ar, |
| 2366 | &fops_htt_stats_mask); |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 2367 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2368 | debugfs_create_file("htt_max_amsdu_ampdu", 0600, ar->debug.debugfs_phy, ar, |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 2369 | &fops_htt_max_amsdu_ampdu); |
| 2370 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2371 | debugfs_create_file("fw_dbglog", 0600, ar->debug.debugfs_phy, ar, |
| 2372 | &fops_fw_dbglog); |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 2373 | |
Surabhi Vishnoi | 5db98ae | 2018-06-13 10:33:35 +0530 | [diff] [blame] | 2374 | if (!test_bit(ATH10K_FW_FEATURE_NON_BMI, |
| 2375 | ar->normal_mode_fw.fw_file.fw_features)) { |
| 2376 | debugfs_create_file("cal_data", 0400, ar->debug.debugfs_phy, ar, |
| 2377 | &fops_cal_data); |
| 2378 | |
| 2379 | debugfs_create_file("nf_cal_period", 0600, ar->debug.debugfs_phy, ar, |
| 2380 | &fops_nf_cal_period); |
| 2381 | } |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 2382 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2383 | debugfs_create_file("ani_enable", 0600, ar->debug.debugfs_phy, ar, |
| 2384 | &fops_ani_enable); |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 2385 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 2386 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) { |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2387 | debugfs_create_file("dfs_simulate_radar", 0200, ar->debug.debugfs_phy, |
| 2388 | ar, &fops_simulate_radar); |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2389 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2390 | debugfs_create_bool("dfs_block_radar_events", 0200, |
Marek Puzyniak | 7d9b40b | 2013-11-20 10:00:28 +0200 | [diff] [blame] | 2391 | ar->debug.debugfs_phy, |
| 2392 | &ar->dfs_block_radar_events); |
| 2393 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2394 | debugfs_create_file("dfs_stats", 0400, ar->debug.debugfs_phy, ar, |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2395 | &fops_dfs_stats); |
| 2396 | } |
| 2397 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2398 | debugfs_create_file("pktlog_filter", 0644, ar->debug.debugfs_phy, ar, |
| 2399 | &fops_pktlog_filter); |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 2400 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2401 | debugfs_create_file("quiet_period", 0644, ar->debug.debugfs_phy, ar, |
| 2402 | &fops_quiet_period); |
Rajkumar Manoharan | 63fb32d | 2015-03-15 20:36:20 +0530 | [diff] [blame] | 2403 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2404 | debugfs_create_file("tpc_stats", 0400, ar->debug.debugfs_phy, ar, |
| 2405 | &fops_tpc_stats); |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 2406 | |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2407 | if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map)) |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2408 | debugfs_create_file("btcoex", 0644, ar->debug.debugfs_phy, ar, |
| 2409 | &fops_btcoex); |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2410 | |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2411 | if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map)) |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2412 | debugfs_create_file("peer_stats", 0644, ar->debug.debugfs_phy, ar, |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2413 | &fops_peer_stats); |
| 2414 | |
Marcin Rokicki | 53c8d48 | 2017-02-20 14:40:27 +0100 | [diff] [blame] | 2415 | debugfs_create_file("fw_checksums", 0400, ar->debug.debugfs_phy, ar, |
| 2416 | &fops_fw_checksums); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2417 | |
Vasanthakumar Thiagarajan | caee728 | 2018-03-14 12:14:06 +0200 | [diff] [blame] | 2418 | if (IS_ENABLED(CONFIG_MAC80211_DEBUGFS)) |
| 2419 | debugfs_create_file("sta_tid_stats_mask", 0600, |
| 2420 | ar->debug.debugfs_phy, |
| 2421 | ar, &fops_sta_tid_stats_mask); |
| 2422 | |
Maharaja Kennadyrajan | bc64d05 | 2018-03-14 12:14:08 +0200 | [diff] [blame] | 2423 | if (test_bit(WMI_SERVICE_TPC_STATS_FINAL, ar->wmi.svc_map)) |
| 2424 | debugfs_create_file("tpc_stats_final", 0400, |
| 2425 | ar->debug.debugfs_phy, ar, |
| 2426 | &fops_tpc_stats_final); |
| 2427 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2428 | return 0; |
| 2429 | } |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 2430 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 2431 | void ath10k_debug_unregister(struct ath10k *ar) |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 2432 | { |
| 2433 | cancel_delayed_work_sync(&ar->debug.htt_stats_dwork); |
| 2434 | } |
| 2435 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2436 | #endif /* CONFIG_ATH10K_DEBUGFS */ |
| 2437 | |
| 2438 | #ifdef CONFIG_ATH10K_DEBUG |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2439 | void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask, |
| 2440 | const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2441 | { |
| 2442 | struct va_format vaf; |
| 2443 | va_list args; |
| 2444 | |
| 2445 | va_start(args, fmt); |
| 2446 | |
| 2447 | vaf.fmt = fmt; |
| 2448 | vaf.va = &args; |
| 2449 | |
| 2450 | if (ath10k_debug_mask & mask) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2451 | dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2452 | |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 2453 | trace_ath10k_log_dbg(ar, mask, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2454 | |
| 2455 | va_end(args); |
| 2456 | } |
| 2457 | EXPORT_SYMBOL(ath10k_dbg); |
| 2458 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2459 | void ath10k_dbg_dump(struct ath10k *ar, |
| 2460 | enum ath10k_debug_mask mask, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2461 | const char *msg, const char *prefix, |
| 2462 | const void *buf, size_t len) |
| 2463 | { |
Michal Kazior | 45724a8 | 2014-09-23 10:22:53 +0200 | [diff] [blame] | 2464 | char linebuf[256]; |
Amadeusz Sławiński | 182f1e5 | 2017-02-13 12:38:38 +0200 | [diff] [blame] | 2465 | size_t linebuflen; |
Michal Kazior | 45724a8 | 2014-09-23 10:22:53 +0200 | [diff] [blame] | 2466 | const void *ptr; |
| 2467 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2468 | if (ath10k_debug_mask & mask) { |
| 2469 | if (msg) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2470 | ath10k_dbg(ar, mask, "%s\n", msg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2471 | |
Michal Kazior | 45724a8 | 2014-09-23 10:22:53 +0200 | [diff] [blame] | 2472 | for (ptr = buf; (ptr - buf) < len; ptr += 16) { |
| 2473 | linebuflen = 0; |
| 2474 | linebuflen += scnprintf(linebuf + linebuflen, |
| 2475 | sizeof(linebuf) - linebuflen, |
| 2476 | "%s%08x: ", |
| 2477 | (prefix ? prefix : ""), |
| 2478 | (unsigned int)(ptr - buf)); |
| 2479 | hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1, |
| 2480 | linebuf + linebuflen, |
| 2481 | sizeof(linebuf) - linebuflen, true); |
| 2482 | dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf); |
| 2483 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | /* tracing code doesn't like null strings :/ */ |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 2487 | trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2488 | buf, len); |
| 2489 | } |
| 2490 | EXPORT_SYMBOL(ath10k_dbg_dump); |
| 2491 | |
| 2492 | #endif /* CONFIG_ATH10K_DEBUG */ |