Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2011 Atheros Communications Inc. |
| 3 | * Copyright (c) 2011-2013 Qualcomm Atheros, Inc. |
Yu Wang | 0e9b8df | 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> |
Johannes Berg | 12c2715 | 2014-11-21 18:58:49 +0200 | [diff] [blame] | 22 | #include <linux/utsname.h> |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 23 | #include <linux/crc32.h> |
| 24 | #include <linux/firmware.h> |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 25 | |
| 26 | #include "core.h" |
| 27 | #include "debug.h" |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 28 | #include "hif.h" |
Michal Kazior | d7579d1 | 2014-12-03 10:10:54 +0200 | [diff] [blame] | 29 | #include "wmi-ops.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 30 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 31 | /* ms */ |
| 32 | #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000 |
| 33 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 34 | #define ATH10K_DEBUG_CAL_DATA_LEN 12064 |
| 35 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 36 | #define ATH10K_FW_CRASH_DUMP_VERSION 1 |
| 37 | |
| 38 | /** |
| 39 | * enum ath10k_fw_crash_dump_type - types of data in the dump file |
| 40 | * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format |
| 41 | */ |
| 42 | enum ath10k_fw_crash_dump_type { |
| 43 | ATH10K_FW_CRASH_DUMP_REGISTERS = 0, |
| 44 | |
| 45 | ATH10K_FW_CRASH_DUMP_MAX, |
| 46 | }; |
| 47 | |
| 48 | struct ath10k_tlv_dump_data { |
| 49 | /* see ath10k_fw_crash_dump_type above */ |
| 50 | __le32 type; |
| 51 | |
| 52 | /* in bytes */ |
| 53 | __le32 tlv_len; |
| 54 | |
| 55 | /* pad to 32-bit boundaries as needed */ |
| 56 | u8 tlv_data[]; |
| 57 | } __packed; |
| 58 | |
| 59 | struct ath10k_dump_file_data { |
| 60 | /* dump file information */ |
| 61 | |
| 62 | /* "ATH10K-FW-DUMP" */ |
| 63 | char df_magic[16]; |
| 64 | |
| 65 | __le32 len; |
| 66 | |
| 67 | /* file dump version */ |
| 68 | __le32 version; |
| 69 | |
| 70 | /* some info we can get from ath10k struct that might help */ |
| 71 | |
| 72 | u8 uuid[16]; |
| 73 | |
| 74 | __le32 chip_id; |
| 75 | |
| 76 | /* 0 for now, in place for later hardware */ |
| 77 | __le32 bus_type; |
| 78 | |
| 79 | __le32 target_version; |
| 80 | __le32 fw_version_major; |
| 81 | __le32 fw_version_minor; |
| 82 | __le32 fw_version_release; |
| 83 | __le32 fw_version_build; |
| 84 | __le32 phy_capability; |
| 85 | __le32 hw_min_tx_power; |
| 86 | __le32 hw_max_tx_power; |
| 87 | __le32 ht_cap_info; |
| 88 | __le32 vht_cap_info; |
| 89 | __le32 num_rf_chains; |
| 90 | |
| 91 | /* firmware version string */ |
| 92 | char fw_ver[ETHTOOL_FWVERS_LEN]; |
| 93 | |
| 94 | /* Kernel related information */ |
| 95 | |
| 96 | /* time-of-day stamp */ |
| 97 | __le64 tv_sec; |
| 98 | |
| 99 | /* time-of-day stamp, nano-seconds */ |
| 100 | __le64 tv_nsec; |
| 101 | |
| 102 | /* LINUX_VERSION_CODE */ |
| 103 | __le32 kernel_ver_code; |
| 104 | |
| 105 | /* VERMAGIC_STRING */ |
| 106 | char kernel_ver[64]; |
| 107 | |
| 108 | /* room for growth w/out changing binary format */ |
| 109 | u8 unused[128]; |
| 110 | |
| 111 | /* struct ath10k_tlv_dump_data + more */ |
| 112 | u8 data[0]; |
| 113 | } __packed; |
| 114 | |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 115 | void ath10k_info(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 116 | { |
| 117 | struct va_format vaf = { |
| 118 | .fmt = fmt, |
| 119 | }; |
| 120 | va_list args; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 121 | |
| 122 | va_start(args, fmt); |
| 123 | vaf.va = &args; |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 124 | dev_info(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 125 | trace_ath10k_log_info(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 126 | va_end(args); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 127 | } |
| 128 | EXPORT_SYMBOL(ath10k_info); |
| 129 | |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 130 | void ath10k_debug_print_hwfw_info(struct ath10k *ar) |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 131 | { |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 132 | const struct firmware *firmware; |
Michal Kazior | 84e3df6 | 2015-08-05 06:55:37 +0200 | [diff] [blame] | 133 | char fw_features[128] = {}; |
Michal Kazior | 8866c72 | 2016-03-17 10:52:08 +0100 | [diff] [blame] | 134 | u32 crc = 0; |
Michal Kazior | b27bc5a | 2015-06-15 14:46:40 +0300 | [diff] [blame] | 135 | |
| 136 | ath10k_core_get_fw_features_str(ar, fw_features, sizeof(fw_features)); |
| 137 | |
Kalle Valo | 8605c02 | 2015-11-25 15:38:19 +0200 | [diff] [blame] | 138 | 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] | 139 | ar->hw_params.name, |
| 140 | ar->target_version, |
| 141 | ar->chip_id, |
Kalle Valo | 8605c02 | 2015-11-25 15:38:19 +0200 | [diff] [blame] | 142 | ar->id.subsystem_vendor, ar->id.subsystem_device); |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 143 | |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 144 | 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] | 145 | IS_ENABLED(CONFIG_ATH10K_DEBUG), |
| 146 | IS_ENABLED(CONFIG_ATH10K_DEBUGFS), |
| 147 | IS_ENABLED(CONFIG_ATH10K_TRACING), |
| 148 | IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED), |
| 149 | IS_ENABLED(CONFIG_NL80211_TESTMODE)); |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 150 | |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 151 | firmware = ar->normal_mode_fw.fw_file.firmware; |
| 152 | if (firmware) |
| 153 | crc = crc32_le(0, firmware->data, firmware->size); |
Michal Kazior | 8866c72 | 2016-03-17 10:52:08 +0100 | [diff] [blame] | 154 | |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 155 | 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] | 156 | ar->hw->wiphy->fw_version, |
| 157 | ar->fw_api, |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 158 | fw_features, |
Michal Kazior | 8866c72 | 2016-03-17 10:52:08 +0100 | [diff] [blame] | 159 | crc); |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void ath10k_debug_print_board_info(struct ath10k *ar) |
| 163 | { |
| 164 | char boardinfo[100]; |
Yu Wang | 0e9b8df | 2018-01-30 14:06:08 +0200 | [diff] [blame] | 165 | const struct firmware *board; |
| 166 | u32 crc; |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 167 | |
| 168 | if (ar->id.bmi_ids_valid) |
| 169 | scnprintf(boardinfo, sizeof(boardinfo), "%d:%d", |
| 170 | ar->id.bmi_chip_id, ar->id.bmi_board_id); |
| 171 | else |
| 172 | scnprintf(boardinfo, sizeof(boardinfo), "N/A"); |
| 173 | |
Yu Wang | 0e9b8df | 2018-01-30 14:06:08 +0200 | [diff] [blame] | 174 | board = ar->normal_mode_fw.board; |
| 175 | if (!IS_ERR_OR_NULL(board)) |
| 176 | crc = crc32_le(0, board->data, board->size); |
| 177 | else |
| 178 | crc = 0; |
| 179 | |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 180 | ath10k_info(ar, "board_file api %d bmi_id %s crc32 %08x", |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 181 | ar->bd_api, |
Kalle Valo | 3e58044 | 2015-11-25 15:38:34 +0200 | [diff] [blame] | 182 | boardinfo, |
Yu Wang | 0e9b8df | 2018-01-30 14:06:08 +0200 | [diff] [blame] | 183 | crc); |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void ath10k_debug_print_boot_info(struct ath10k *ar) |
| 187 | { |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 188 | 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] | 189 | ar->htt.target_version_major, |
Michal Kazior | 34b28b6 | 2014-09-23 10:22:52 +0200 | [diff] [blame] | 190 | ar->htt.target_version_minor, |
Kalle Valo | bf3c13a | 2016-04-20 19:45:33 +0300 | [diff] [blame] | 191 | ar->normal_mode_fw.fw_file.wmi_op_version, |
Kalle Valo | 77561f9 | 2016-04-20 19:45:47 +0300 | [diff] [blame] | 192 | ar->normal_mode_fw.fw_file.htt_op_version, |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 193 | ath10k_cal_mode_str(ar->cal_mode), |
Michal Kazior | b27bc5a | 2015-06-15 14:46:40 +0300 | [diff] [blame] | 194 | ar->max_num_stations, |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 195 | test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags), |
Kalle Valo | f0de90b | 2015-11-25 15:38:12 +0200 | [diff] [blame] | 196 | !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags)); |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 197 | } |
Kalle Valo | 23f591e | 2015-11-25 15:38:27 +0200 | [diff] [blame] | 198 | |
| 199 | void ath10k_print_driver_info(struct ath10k *ar) |
| 200 | { |
| 201 | ath10k_debug_print_hwfw_info(ar); |
| 202 | ath10k_debug_print_board_info(ar); |
| 203 | ath10k_debug_print_boot_info(ar); |
| 204 | } |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 205 | EXPORT_SYMBOL(ath10k_print_driver_info); |
| 206 | |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 207 | void ath10k_err(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 208 | { |
| 209 | struct va_format vaf = { |
| 210 | .fmt = fmt, |
| 211 | }; |
| 212 | va_list args; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 213 | |
| 214 | va_start(args, fmt); |
| 215 | vaf.va = &args; |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 216 | dev_err(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 217 | trace_ath10k_log_err(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 218 | va_end(args); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 219 | } |
| 220 | EXPORT_SYMBOL(ath10k_err); |
| 221 | |
Joe Perches | babcb3e | 2014-09-22 10:35:34 -0700 | [diff] [blame] | 222 | void ath10k_warn(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 223 | { |
| 224 | struct va_format vaf = { |
| 225 | .fmt = fmt, |
| 226 | }; |
| 227 | va_list args; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 228 | |
| 229 | va_start(args, fmt); |
| 230 | vaf.va = &args; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 231 | dev_warn_ratelimited(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 232 | trace_ath10k_log_warn(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 233 | |
| 234 | va_end(args); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 235 | } |
| 236 | EXPORT_SYMBOL(ath10k_warn); |
| 237 | |
| 238 | #ifdef CONFIG_ATH10K_DEBUGFS |
| 239 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 240 | static ssize_t ath10k_read_wmi_services(struct file *file, |
| 241 | char __user *user_buf, |
| 242 | size_t count, loff_t *ppos) |
| 243 | { |
| 244 | struct ath10k *ar = file->private_data; |
| 245 | char *buf; |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 246 | unsigned int len = 0, buf_len = 4096; |
| 247 | const char *name; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 248 | ssize_t ret_cnt; |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 249 | bool enabled; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 250 | int i; |
| 251 | |
| 252 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 253 | if (!buf) |
| 254 | return -ENOMEM; |
| 255 | |
| 256 | mutex_lock(&ar->conf_mutex); |
| 257 | |
| 258 | if (len > buf_len) |
| 259 | len = buf_len; |
| 260 | |
Michal Kazior | acfe7ec | 2014-11-27 10:11:17 +0100 | [diff] [blame] | 261 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | c4f8c83 | 2014-09-04 10:18:32 +0200 | [diff] [blame] | 262 | for (i = 0; i < WMI_SERVICE_MAX; i++) { |
Michal Kazior | acfe7ec | 2014-11-27 10:11:17 +0100 | [diff] [blame] | 263 | enabled = test_bit(i, ar->wmi.svc_map); |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 264 | name = wmi_service_name(i); |
| 265 | |
| 266 | if (!name) { |
| 267 | if (enabled) |
| 268 | len += scnprintf(buf + len, buf_len - len, |
| 269 | "%-40s %s (bit %d)\n", |
| 270 | "unknown", "enabled", i); |
| 271 | |
| 272 | continue; |
| 273 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 274 | |
| 275 | len += scnprintf(buf + len, buf_len - len, |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 276 | "%-40s %s\n", |
| 277 | name, enabled ? "enabled" : "-"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 278 | } |
Michal Kazior | acfe7ec | 2014-11-27 10:11:17 +0100 | [diff] [blame] | 279 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 280 | |
| 281 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 282 | |
| 283 | mutex_unlock(&ar->conf_mutex); |
| 284 | |
| 285 | kfree(buf); |
| 286 | return ret_cnt; |
| 287 | } |
| 288 | |
| 289 | static const struct file_operations fops_wmi_services = { |
| 290 | .read = ath10k_read_wmi_services, |
| 291 | .open = simple_open, |
| 292 | .owner = THIS_MODULE, |
| 293 | .llseek = default_llseek, |
| 294 | }; |
| 295 | |
Mohammed Shafi Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 296 | static void ath10k_fw_stats_pdevs_free(struct list_head *head) |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 297 | { |
| 298 | struct ath10k_fw_stats_pdev *i, *tmp; |
| 299 | |
| 300 | list_for_each_entry_safe(i, tmp, head, list) { |
| 301 | list_del(&i->list); |
| 302 | kfree(i); |
| 303 | } |
| 304 | } |
| 305 | |
Mohammed Shafi Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 306 | static void ath10k_fw_stats_vdevs_free(struct list_head *head) |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 307 | { |
| 308 | struct ath10k_fw_stats_vdev *i, *tmp; |
| 309 | |
| 310 | list_for_each_entry_safe(i, tmp, head, list) { |
| 311 | list_del(&i->list); |
| 312 | kfree(i); |
| 313 | } |
| 314 | } |
| 315 | |
Mohammed Shafi Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 316 | static void ath10k_fw_stats_peers_free(struct list_head *head) |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 317 | { |
| 318 | struct ath10k_fw_stats_peer *i, *tmp; |
| 319 | |
| 320 | list_for_each_entry_safe(i, tmp, head, list) { |
| 321 | list_del(&i->list); |
| 322 | kfree(i); |
| 323 | } |
| 324 | } |
| 325 | |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 326 | static void ath10k_fw_extd_stats_peers_free(struct list_head *head) |
| 327 | { |
| 328 | struct ath10k_fw_extd_stats_peer *i, *tmp; |
| 329 | |
| 330 | list_for_each_entry_safe(i, tmp, head, list) { |
| 331 | list_del(&i->list); |
| 332 | kfree(i); |
| 333 | } |
| 334 | } |
| 335 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 336 | static void ath10k_debug_fw_stats_reset(struct ath10k *ar) |
| 337 | { |
| 338 | spin_lock_bh(&ar->data_lock); |
| 339 | ar->debug.fw_stats_done = false; |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 340 | ar->debug.fw_stats.extended = false; |
Mohammed Shafi Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 341 | ath10k_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs); |
| 342 | ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs); |
| 343 | ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers); |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 344 | ath10k_fw_extd_stats_peers_free(&ar->debug.fw_stats.peers_extd); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 345 | spin_unlock_bh(&ar->data_lock); |
| 346 | } |
| 347 | |
Michal Kazior | 60ef401 | 2014-09-25 12:33:48 +0200 | [diff] [blame] | 348 | 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] | 349 | { |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 350 | struct ath10k_fw_stats stats = {}; |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 351 | bool is_start, is_started, is_end; |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 352 | size_t num_peers; |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 353 | size_t num_vdevs; |
Michal Kazior | d15fb52 | 2014-09-25 12:33:47 +0200 | [diff] [blame] | 354 | int ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 355 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 356 | INIT_LIST_HEAD(&stats.pdevs); |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 357 | INIT_LIST_HEAD(&stats.vdevs); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 358 | INIT_LIST_HEAD(&stats.peers); |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 359 | INIT_LIST_HEAD(&stats.peers_extd); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 360 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 361 | spin_lock_bh(&ar->data_lock); |
| 362 | ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats); |
Michal Kazior | d15fb52 | 2014-09-25 12:33:47 +0200 | [diff] [blame] | 363 | if (ret) { |
| 364 | ath10k_warn(ar, "failed to pull fw stats: %d\n", ret); |
Raja Mani | 5db879a | 2015-07-09 14:19:43 +0530 | [diff] [blame] | 365 | goto free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 366 | } |
| 367 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 368 | /* Stat data may exceed htc-wmi buffer limit. In such case firmware |
| 369 | * splits the stats data and delivers it in a ping-pong fashion of |
| 370 | * request cmd-update event. |
| 371 | * |
| 372 | * However there is no explicit end-of-data. Instead start-of-data is |
| 373 | * used as an implicit one. This works as follows: |
| 374 | * a) discard stat update events until one with pdev stats is |
| 375 | * delivered - this skips session started at end of (b) |
| 376 | * b) consume stat update events until another one with pdev stats is |
| 377 | * delivered which is treated as end-of-data and is itself discarded |
| 378 | */ |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 379 | if (ath10k_peer_stats_enabled(ar)) |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 380 | ath10k_sta_update_rx_duration(ar, &stats); |
Mohammed Shafi Shajakhan | 74135f5 | 2016-02-03 21:07:42 +0530 | [diff] [blame] | 381 | |
Mohammed Shafi Shajakhan | e0b6ce0 | 2016-02-03 21:07:43 +0530 | [diff] [blame] | 382 | if (ar->debug.fw_stats_done) { |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 383 | if (!ath10k_peer_stats_enabled(ar)) |
Mohammed Shafi Shajakhan | e0b6ce0 | 2016-02-03 21:07:43 +0530 | [diff] [blame] | 384 | ath10k_warn(ar, "received unsolicited stats update event\n"); |
| 385 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 386 | goto free; |
| 387 | } |
| 388 | |
Manikanta Pubbisetty | bc6f9ae | 2015-10-16 15:54:52 +0300 | [diff] [blame] | 389 | num_peers = ath10k_wmi_fw_stats_num_peers(&ar->debug.fw_stats.peers); |
| 390 | 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] | 391 | is_start = (list_empty(&ar->debug.fw_stats.pdevs) && |
| 392 | !list_empty(&stats.pdevs)); |
| 393 | is_end = (!list_empty(&ar->debug.fw_stats.pdevs) && |
| 394 | !list_empty(&stats.pdevs)); |
| 395 | |
| 396 | if (is_start) |
| 397 | list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs); |
| 398 | |
| 399 | if (is_end) |
| 400 | ar->debug.fw_stats_done = true; |
| 401 | |
| 402 | is_started = !list_empty(&ar->debug.fw_stats.pdevs); |
| 403 | |
| 404 | if (is_started && !is_end) { |
| 405 | if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) { |
| 406 | /* Although this is unlikely impose a sane limit to |
| 407 | * prevent firmware from DoS-ing the host. |
| 408 | */ |
Mohammed Shafi Shajakhan | d57e7f2 | 2016-01-13 21:16:32 +0530 | [diff] [blame] | 409 | ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 410 | ath10k_warn(ar, "dropping fw peer stats\n"); |
| 411 | goto free; |
| 412 | } |
| 413 | |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 414 | if (num_vdevs >= BITS_PER_LONG) { |
Mohammed Shafi Shajakhan | d57e7f2 | 2016-01-13 21:16:32 +0530 | [diff] [blame] | 415 | ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs); |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 416 | ath10k_warn(ar, "dropping fw vdev stats\n"); |
| 417 | goto free; |
| 418 | } |
| 419 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 420 | list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers); |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 421 | list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs); |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 422 | list_splice_tail_init(&stats.peers_extd, |
| 423 | &ar->debug.fw_stats.peers_extd); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 424 | } |
| 425 | |
Michal Kazior | 60ef401 | 2014-09-25 12:33:48 +0200 | [diff] [blame] | 426 | complete(&ar->debug.fw_stats_complete); |
Michal Kazior | d15fb52 | 2014-09-25 12:33:47 +0200 | [diff] [blame] | 427 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 428 | free: |
| 429 | /* In some cases lists have been spliced and cleared. Free up |
| 430 | * resources if that is not the case. |
| 431 | */ |
Mohammed Shafi Shajakhan | b4619ea | 2016-01-13 21:16:31 +0530 | [diff] [blame] | 432 | ath10k_fw_stats_pdevs_free(&stats.pdevs); |
| 433 | ath10k_fw_stats_vdevs_free(&stats.vdevs); |
| 434 | ath10k_fw_stats_peers_free(&stats.peers); |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 435 | ath10k_fw_extd_stats_peers_free(&stats.peers_extd); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 436 | |
Michal Kazior | d15fb52 | 2014-09-25 12:33:47 +0200 | [diff] [blame] | 437 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 438 | } |
| 439 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 440 | static int ath10k_debug_fw_stats_request(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 441 | { |
Nicholas Mc Guire | 6e8d543 | 2015-03-30 15:39:20 +0300 | [diff] [blame] | 442 | unsigned long timeout, time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 443 | int ret; |
| 444 | |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 445 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 446 | |
Nicholas Mc Guire | 6e8d543 | 2015-03-30 15:39:20 +0300 | [diff] [blame] | 447 | timeout = jiffies + msecs_to_jiffies(1 * HZ); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 448 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 449 | ath10k_debug_fw_stats_reset(ar); |
| 450 | |
| 451 | for (;;) { |
| 452 | if (time_after(jiffies, timeout)) |
| 453 | return -ETIMEDOUT; |
| 454 | |
| 455 | reinit_completion(&ar->debug.fw_stats_complete); |
| 456 | |
Yanbo Li | 6274cd4 | 2015-04-01 22:53:21 +0300 | [diff] [blame] | 457 | ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 458 | if (ret) { |
| 459 | ath10k_warn(ar, "could not request stats (%d)\n", ret); |
| 460 | return ret; |
| 461 | } |
| 462 | |
Nicholas Mc Guire | 6e8d543 | 2015-03-30 15:39:20 +0300 | [diff] [blame] | 463 | time_left = |
| 464 | wait_for_completion_timeout(&ar->debug.fw_stats_complete, |
| 465 | 1 * HZ); |
| 466 | if (!time_left) |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 467 | return -ETIMEDOUT; |
| 468 | |
| 469 | spin_lock_bh(&ar->data_lock); |
| 470 | if (ar->debug.fw_stats_done) { |
| 471 | spin_unlock_bh(&ar->data_lock); |
| 472 | break; |
| 473 | } |
| 474 | spin_unlock_bh(&ar->data_lock); |
| 475 | } |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 480 | static int ath10k_fw_stats_open(struct inode *inode, struct file *file) |
| 481 | { |
| 482 | struct ath10k *ar = inode->i_private; |
| 483 | void *buf = NULL; |
| 484 | int ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 485 | |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 486 | mutex_lock(&ar->conf_mutex); |
| 487 | |
| 488 | if (ar->state != ATH10K_STATE_ON) { |
| 489 | ret = -ENETDOWN; |
| 490 | goto err_unlock; |
| 491 | } |
| 492 | |
| 493 | buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE); |
| 494 | if (!buf) { |
| 495 | ret = -ENOMEM; |
| 496 | goto err_unlock; |
| 497 | } |
| 498 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 499 | ret = ath10k_debug_fw_stats_request(ar); |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 500 | if (ret) { |
| 501 | ath10k_warn(ar, "failed to request fw stats: %d\n", ret); |
| 502 | goto err_free; |
| 503 | } |
| 504 | |
Manikanta Pubbisetty | bc6f9ae | 2015-10-16 15:54:52 +0300 | [diff] [blame] | 505 | ret = ath10k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, buf); |
| 506 | if (ret) { |
| 507 | ath10k_warn(ar, "failed to fill fw stats: %d\n", ret); |
| 508 | goto err_free; |
| 509 | } |
| 510 | |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 511 | file->private_data = buf; |
| 512 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 513 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 514 | return 0; |
| 515 | |
| 516 | err_free: |
| 517 | vfree(buf); |
| 518 | |
| 519 | err_unlock: |
| 520 | mutex_unlock(&ar->conf_mutex); |
| 521 | return ret; |
| 522 | } |
| 523 | |
| 524 | static int ath10k_fw_stats_release(struct inode *inode, struct file *file) |
| 525 | { |
| 526 | vfree(file->private_data); |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf, |
| 532 | size_t count, loff_t *ppos) |
| 533 | { |
| 534 | const char *buf = file->private_data; |
| 535 | unsigned int len = strlen(buf); |
| 536 | |
| 537 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static const struct file_operations fops_fw_stats = { |
Michal Kazior | fb2e9c0 | 2014-09-25 12:33:49 +0200 | [diff] [blame] | 541 | .open = ath10k_fw_stats_open, |
| 542 | .release = ath10k_fw_stats_release, |
Michal Kazior | 60ef401 | 2014-09-25 12:33:48 +0200 | [diff] [blame] | 543 | .read = ath10k_fw_stats_read, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 544 | .owner = THIS_MODULE, |
| 545 | .llseek = default_llseek, |
| 546 | }; |
| 547 | |
Ben Greear | f51dbe7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 548 | static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file, |
| 549 | char __user *user_buf, |
| 550 | size_t count, loff_t *ppos) |
| 551 | { |
| 552 | struct ath10k *ar = file->private_data; |
| 553 | int ret, len, buf_len; |
| 554 | char *buf; |
| 555 | |
| 556 | buf_len = 500; |
| 557 | buf = kmalloc(buf_len, GFP_KERNEL); |
| 558 | if (!buf) |
| 559 | return -ENOMEM; |
| 560 | |
| 561 | spin_lock_bh(&ar->data_lock); |
| 562 | |
| 563 | len = 0; |
| 564 | len += scnprintf(buf + len, buf_len - len, |
| 565 | "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter); |
| 566 | len += scnprintf(buf + len, buf_len - len, |
| 567 | "fw_warm_reset_counter\t\t%d\n", |
| 568 | ar->stats.fw_warm_reset_counter); |
| 569 | len += scnprintf(buf + len, buf_len - len, |
| 570 | "fw_cold_reset_counter\t\t%d\n", |
| 571 | ar->stats.fw_cold_reset_counter); |
| 572 | |
| 573 | spin_unlock_bh(&ar->data_lock); |
| 574 | |
| 575 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 576 | |
| 577 | kfree(buf); |
| 578 | |
| 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | static const struct file_operations fops_fw_reset_stats = { |
| 583 | .open = simple_open, |
| 584 | .read = ath10k_debug_fw_reset_stats_read, |
| 585 | .owner = THIS_MODULE, |
| 586 | .llseek = default_llseek, |
| 587 | }; |
| 588 | |
Ben Greear | d5aebc7 | 2014-09-10 18:59:28 +0300 | [diff] [blame] | 589 | /* This is a clean assert crash in firmware. */ |
| 590 | static int ath10k_debug_fw_assert(struct ath10k *ar) |
| 591 | { |
| 592 | struct wmi_vdev_install_key_cmd *cmd; |
| 593 | struct sk_buff *skb; |
| 594 | |
| 595 | skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16); |
| 596 | if (!skb) |
| 597 | return -ENOMEM; |
| 598 | |
| 599 | cmd = (struct wmi_vdev_install_key_cmd *)skb->data; |
| 600 | memset(cmd, 0, sizeof(*cmd)); |
| 601 | |
| 602 | /* big enough number so that firmware asserts */ |
| 603 | cmd->vdev_id = __cpu_to_le32(0x7ffe); |
| 604 | |
| 605 | return ath10k_wmi_cmd_send(ar, skb, |
| 606 | ar->wmi.cmd->vdev_install_key_cmdid); |
| 607 | } |
| 608 | |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 609 | static ssize_t ath10k_read_simulate_fw_crash(struct file *file, |
| 610 | char __user *user_buf, |
| 611 | size_t count, loff_t *ppos) |
| 612 | { |
Kalle Valo | 75cb96d | 2014-09-14 12:50:44 +0300 | [diff] [blame] | 613 | const char buf[] = |
| 614 | "To simulate firmware crash write one of the keywords to this file:\n" |
| 615 | "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n" |
| 616 | "`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] | 617 | "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n" |
| 618 | "`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] | 619 | |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 620 | return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); |
| 621 | } |
| 622 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 623 | /* Simulate firmware crash: |
| 624 | * 'soft': Call wmi command causing firmware hang. This firmware hang is |
| 625 | * recoverable by warm firmware reset. |
| 626 | * 'hard': Force firmware crash by setting any vdev parameter for not allowed |
| 627 | * vdev id. This is hard firmware crash because it is recoverable only by cold |
| 628 | * firmware reset. |
| 629 | */ |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 630 | static ssize_t ath10k_write_simulate_fw_crash(struct file *file, |
| 631 | const char __user *user_buf, |
| 632 | size_t count, loff_t *ppos) |
| 633 | { |
| 634 | struct ath10k *ar = file->private_data; |
Michael Mera | 975760b | 2017-04-24 16:11:57 +0900 | [diff] [blame] | 635 | char buf[32] = {0}; |
| 636 | ssize_t rc; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 637 | int ret; |
| 638 | |
Michael Mera | 975760b | 2017-04-24 16:11:57 +0900 | [diff] [blame] | 639 | /* filter partial writes and invalid commands */ |
| 640 | if (*ppos != 0 || count >= sizeof(buf) || count == 0) |
| 641 | return -EINVAL; |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 642 | |
Michael Mera | 975760b | 2017-04-24 16:11:57 +0900 | [diff] [blame] | 643 | rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); |
| 644 | if (rc < 0) |
| 645 | return rc; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 646 | |
Mohammed Shafi Shajakhan | f5e3075 | 2016-05-28 11:25:41 +0300 | [diff] [blame] | 647 | /* drop the possible '\n' from the end */ |
Michael Mera | 975760b | 2017-04-24 16:11:57 +0900 | [diff] [blame] | 648 | if (buf[*ppos - 1] == '\n') |
| 649 | buf[*ppos - 1] = '\0'; |
Mohammed Shafi Shajakhan | f5e3075 | 2016-05-28 11:25:41 +0300 | [diff] [blame] | 650 | |
| 651 | mutex_lock(&ar->conf_mutex); |
| 652 | |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 653 | if (ar->state != ATH10K_STATE_ON && |
| 654 | ar->state != ATH10K_STATE_RESTARTED) { |
| 655 | ret = -ENETDOWN; |
| 656 | goto exit; |
| 657 | } |
| 658 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 659 | if (!strcmp(buf, "soft")) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 660 | ath10k_info(ar, "simulating soft firmware crash\n"); |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 661 | ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0); |
| 662 | } else if (!strcmp(buf, "hard")) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 663 | ath10k_info(ar, "simulating hard firmware crash\n"); |
Ben Greear | 611b368 | 2014-07-25 11:56:40 +0300 | [diff] [blame] | 664 | /* 0x7fff is vdev id, and it is always out of range for all |
| 665 | * firmware variants in order to force a firmware crash. |
| 666 | */ |
| 667 | ret = ath10k_wmi_vdev_set_param(ar, 0x7fff, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 668 | ar->wmi.vdev_param->rts_threshold, |
| 669 | 0); |
Ben Greear | d5aebc7 | 2014-09-10 18:59:28 +0300 | [diff] [blame] | 670 | } else if (!strcmp(buf, "assert")) { |
| 671 | ath10k_info(ar, "simulating firmware assert crash\n"); |
| 672 | ret = ath10k_debug_fw_assert(ar); |
Michal Kazior | 605cdba | 2014-10-28 10:34:37 +0100 | [diff] [blame] | 673 | } else if (!strcmp(buf, "hw-restart")) { |
| 674 | ath10k_info(ar, "user requested hw restart\n"); |
| 675 | queue_work(ar->workqueue, &ar->restart_work); |
| 676 | ret = 0; |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 677 | } else { |
| 678 | ret = -EINVAL; |
| 679 | goto exit; |
| 680 | } |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 681 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 682 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 683 | ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret); |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 684 | goto exit; |
| 685 | } |
| 686 | |
| 687 | ret = count; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 688 | |
| 689 | exit: |
| 690 | mutex_unlock(&ar->conf_mutex); |
| 691 | return ret; |
| 692 | } |
| 693 | |
| 694 | static const struct file_operations fops_simulate_fw_crash = { |
| 695 | .read = ath10k_read_simulate_fw_crash, |
| 696 | .write = ath10k_write_simulate_fw_crash, |
| 697 | .open = simple_open, |
| 698 | .owner = THIS_MODULE, |
| 699 | .llseek = default_llseek, |
| 700 | }; |
| 701 | |
Kalle Valo | 763b8cd | 2013-09-01 11:22:21 +0300 | [diff] [blame] | 702 | static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf, |
| 703 | size_t count, loff_t *ppos) |
| 704 | { |
| 705 | struct ath10k *ar = file->private_data; |
| 706 | unsigned int len; |
| 707 | char buf[50]; |
| 708 | |
| 709 | len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id); |
| 710 | |
| 711 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 712 | } |
| 713 | |
| 714 | static const struct file_operations fops_chip_id = { |
| 715 | .read = ath10k_read_chip_id, |
| 716 | .open = simple_open, |
| 717 | .owner = THIS_MODULE, |
| 718 | .llseek = default_llseek, |
| 719 | }; |
| 720 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 721 | struct ath10k_fw_crash_data * |
| 722 | ath10k_debug_get_new_fw_crash_data(struct ath10k *ar) |
| 723 | { |
| 724 | struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data; |
| 725 | |
| 726 | lockdep_assert_held(&ar->data_lock); |
| 727 | |
| 728 | crash_data->crashed_since_read = true; |
| 729 | uuid_le_gen(&crash_data->uuid); |
| 730 | getnstimeofday(&crash_data->timestamp); |
| 731 | |
| 732 | return crash_data; |
| 733 | } |
| 734 | EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data); |
| 735 | |
| 736 | static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar) |
| 737 | { |
| 738 | struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data; |
| 739 | struct ath10k_dump_file_data *dump_data; |
| 740 | struct ath10k_tlv_dump_data *dump_tlv; |
| 741 | int hdr_len = sizeof(*dump_data); |
| 742 | unsigned int len, sofar = 0; |
| 743 | unsigned char *buf; |
| 744 | |
| 745 | len = hdr_len; |
| 746 | len += sizeof(*dump_tlv) + sizeof(crash_data->registers); |
| 747 | |
| 748 | sofar += hdr_len; |
| 749 | |
| 750 | /* This is going to get big when we start dumping FW RAM and such, |
| 751 | * so go ahead and use vmalloc. |
| 752 | */ |
| 753 | buf = vzalloc(len); |
| 754 | if (!buf) |
| 755 | return NULL; |
| 756 | |
| 757 | spin_lock_bh(&ar->data_lock); |
| 758 | |
| 759 | if (!crash_data->crashed_since_read) { |
| 760 | spin_unlock_bh(&ar->data_lock); |
| 761 | vfree(buf); |
| 762 | return NULL; |
| 763 | } |
| 764 | |
| 765 | dump_data = (struct ath10k_dump_file_data *)(buf); |
| 766 | strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP", |
| 767 | sizeof(dump_data->df_magic)); |
| 768 | dump_data->len = cpu_to_le32(len); |
| 769 | |
| 770 | dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION); |
| 771 | |
| 772 | memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid)); |
| 773 | dump_data->chip_id = cpu_to_le32(ar->chip_id); |
| 774 | dump_data->bus_type = cpu_to_le32(0); |
| 775 | dump_data->target_version = cpu_to_le32(ar->target_version); |
| 776 | dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major); |
| 777 | dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor); |
| 778 | dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release); |
| 779 | dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build); |
| 780 | dump_data->phy_capability = cpu_to_le32(ar->phy_capability); |
| 781 | dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power); |
| 782 | dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power); |
| 783 | dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info); |
| 784 | dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info); |
| 785 | dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains); |
| 786 | |
| 787 | strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version, |
| 788 | sizeof(dump_data->fw_ver)); |
| 789 | |
Johannes Berg | 12c2715 | 2014-11-21 18:58:49 +0200 | [diff] [blame] | 790 | dump_data->kernel_ver_code = 0; |
| 791 | strlcpy(dump_data->kernel_ver, init_utsname()->release, |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 792 | sizeof(dump_data->kernel_ver)); |
| 793 | |
| 794 | dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec); |
| 795 | dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec); |
| 796 | |
| 797 | /* Gather crash-dump */ |
| 798 | dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar); |
| 799 | dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS); |
| 800 | dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers)); |
| 801 | memcpy(dump_tlv->tlv_data, &crash_data->registers, |
| 802 | sizeof(crash_data->registers)); |
| 803 | sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers); |
| 804 | |
| 805 | ar->debug.fw_crash_data->crashed_since_read = false; |
| 806 | |
| 807 | spin_unlock_bh(&ar->data_lock); |
| 808 | |
| 809 | return dump_data; |
| 810 | } |
| 811 | |
| 812 | static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file) |
| 813 | { |
| 814 | struct ath10k *ar = inode->i_private; |
| 815 | struct ath10k_dump_file_data *dump; |
| 816 | |
| 817 | dump = ath10k_build_dump_file(ar); |
| 818 | if (!dump) |
| 819 | return -ENODATA; |
| 820 | |
| 821 | file->private_data = dump; |
| 822 | |
| 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | static ssize_t ath10k_fw_crash_dump_read(struct file *file, |
| 827 | char __user *user_buf, |
| 828 | size_t count, loff_t *ppos) |
| 829 | { |
| 830 | struct ath10k_dump_file_data *dump_file = file->private_data; |
| 831 | |
| 832 | return simple_read_from_buffer(user_buf, count, ppos, |
| 833 | dump_file, |
| 834 | le32_to_cpu(dump_file->len)); |
| 835 | } |
| 836 | |
| 837 | static int ath10k_fw_crash_dump_release(struct inode *inode, |
| 838 | struct file *file) |
| 839 | { |
| 840 | vfree(file->private_data); |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | static const struct file_operations fops_fw_crash_dump = { |
| 846 | .open = ath10k_fw_crash_dump_open, |
| 847 | .read = ath10k_fw_crash_dump_read, |
| 848 | .release = ath10k_fw_crash_dump_release, |
| 849 | .owner = THIS_MODULE, |
| 850 | .llseek = default_llseek, |
| 851 | }; |
| 852 | |
Yanbo Li | 077a380 | 2014-11-25 12:24:33 +0200 | [diff] [blame] | 853 | static ssize_t ath10k_reg_addr_read(struct file *file, |
| 854 | char __user *user_buf, |
| 855 | size_t count, loff_t *ppos) |
| 856 | { |
| 857 | struct ath10k *ar = file->private_data; |
| 858 | u8 buf[32]; |
| 859 | unsigned int len = 0; |
| 860 | u32 reg_addr; |
| 861 | |
| 862 | mutex_lock(&ar->conf_mutex); |
| 863 | reg_addr = ar->debug.reg_addr; |
| 864 | mutex_unlock(&ar->conf_mutex); |
| 865 | |
| 866 | len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr); |
| 867 | |
| 868 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 869 | } |
| 870 | |
| 871 | static ssize_t ath10k_reg_addr_write(struct file *file, |
| 872 | const char __user *user_buf, |
| 873 | size_t count, loff_t *ppos) |
| 874 | { |
| 875 | struct ath10k *ar = file->private_data; |
| 876 | u32 reg_addr; |
| 877 | int ret; |
| 878 | |
| 879 | ret = kstrtou32_from_user(user_buf, count, 0, ®_addr); |
| 880 | if (ret) |
| 881 | return ret; |
| 882 | |
| 883 | if (!IS_ALIGNED(reg_addr, 4)) |
| 884 | return -EFAULT; |
| 885 | |
| 886 | mutex_lock(&ar->conf_mutex); |
| 887 | ar->debug.reg_addr = reg_addr; |
| 888 | mutex_unlock(&ar->conf_mutex); |
| 889 | |
| 890 | return count; |
| 891 | } |
| 892 | |
| 893 | static const struct file_operations fops_reg_addr = { |
| 894 | .read = ath10k_reg_addr_read, |
| 895 | .write = ath10k_reg_addr_write, |
| 896 | .open = simple_open, |
| 897 | .owner = THIS_MODULE, |
| 898 | .llseek = default_llseek, |
| 899 | }; |
| 900 | |
| 901 | static ssize_t ath10k_reg_value_read(struct file *file, |
| 902 | char __user *user_buf, |
| 903 | size_t count, loff_t *ppos) |
| 904 | { |
| 905 | struct ath10k *ar = file->private_data; |
| 906 | u8 buf[48]; |
| 907 | unsigned int len; |
| 908 | u32 reg_addr, reg_val; |
| 909 | int ret; |
| 910 | |
| 911 | mutex_lock(&ar->conf_mutex); |
| 912 | |
| 913 | if (ar->state != ATH10K_STATE_ON && |
| 914 | ar->state != ATH10K_STATE_UTF) { |
| 915 | ret = -ENETDOWN; |
| 916 | goto exit; |
| 917 | } |
| 918 | |
| 919 | reg_addr = ar->debug.reg_addr; |
| 920 | |
| 921 | reg_val = ath10k_hif_read32(ar, reg_addr); |
| 922 | len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val); |
| 923 | |
| 924 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 925 | |
| 926 | exit: |
| 927 | mutex_unlock(&ar->conf_mutex); |
| 928 | |
| 929 | return ret; |
| 930 | } |
| 931 | |
| 932 | static ssize_t ath10k_reg_value_write(struct file *file, |
| 933 | const char __user *user_buf, |
| 934 | size_t count, loff_t *ppos) |
| 935 | { |
| 936 | struct ath10k *ar = file->private_data; |
| 937 | u32 reg_addr, reg_val; |
| 938 | int ret; |
| 939 | |
| 940 | mutex_lock(&ar->conf_mutex); |
| 941 | |
| 942 | if (ar->state != ATH10K_STATE_ON && |
| 943 | ar->state != ATH10K_STATE_UTF) { |
| 944 | ret = -ENETDOWN; |
| 945 | goto exit; |
| 946 | } |
| 947 | |
| 948 | reg_addr = ar->debug.reg_addr; |
| 949 | |
| 950 | ret = kstrtou32_from_user(user_buf, count, 0, ®_val); |
| 951 | if (ret) |
| 952 | goto exit; |
| 953 | |
| 954 | ath10k_hif_write32(ar, reg_addr, reg_val); |
| 955 | |
| 956 | ret = count; |
| 957 | |
| 958 | exit: |
| 959 | mutex_unlock(&ar->conf_mutex); |
| 960 | |
| 961 | return ret; |
| 962 | } |
| 963 | |
| 964 | static const struct file_operations fops_reg_value = { |
| 965 | .read = ath10k_reg_value_read, |
| 966 | .write = ath10k_reg_value_write, |
| 967 | .open = simple_open, |
| 968 | .owner = THIS_MODULE, |
| 969 | .llseek = default_llseek, |
| 970 | }; |
| 971 | |
Yanbo Li | 9f65ad2 | 2014-11-25 12:24:48 +0200 | [diff] [blame] | 972 | static ssize_t ath10k_mem_value_read(struct file *file, |
| 973 | char __user *user_buf, |
| 974 | size_t count, loff_t *ppos) |
| 975 | { |
| 976 | struct ath10k *ar = file->private_data; |
| 977 | u8 *buf; |
| 978 | int ret; |
| 979 | |
| 980 | if (*ppos < 0) |
| 981 | return -EINVAL; |
| 982 | |
| 983 | if (!count) |
| 984 | return 0; |
| 985 | |
| 986 | mutex_lock(&ar->conf_mutex); |
| 987 | |
| 988 | buf = vmalloc(count); |
| 989 | if (!buf) { |
| 990 | ret = -ENOMEM; |
| 991 | goto exit; |
| 992 | } |
| 993 | |
| 994 | if (ar->state != ATH10K_STATE_ON && |
| 995 | ar->state != ATH10K_STATE_UTF) { |
| 996 | ret = -ENETDOWN; |
| 997 | goto exit; |
| 998 | } |
| 999 | |
| 1000 | ret = ath10k_hif_diag_read(ar, *ppos, buf, count); |
| 1001 | if (ret) { |
| 1002 | ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n", |
| 1003 | (u32)(*ppos), ret); |
| 1004 | goto exit; |
| 1005 | } |
| 1006 | |
| 1007 | ret = copy_to_user(user_buf, buf, count); |
| 1008 | if (ret) { |
| 1009 | ret = -EFAULT; |
| 1010 | goto exit; |
| 1011 | } |
| 1012 | |
| 1013 | count -= ret; |
| 1014 | *ppos += count; |
| 1015 | ret = count; |
| 1016 | |
| 1017 | exit: |
| 1018 | vfree(buf); |
| 1019 | mutex_unlock(&ar->conf_mutex); |
| 1020 | |
| 1021 | return ret; |
| 1022 | } |
| 1023 | |
| 1024 | static ssize_t ath10k_mem_value_write(struct file *file, |
| 1025 | const char __user *user_buf, |
| 1026 | size_t count, loff_t *ppos) |
| 1027 | { |
| 1028 | struct ath10k *ar = file->private_data; |
| 1029 | u8 *buf; |
| 1030 | int ret; |
| 1031 | |
| 1032 | if (*ppos < 0) |
| 1033 | return -EINVAL; |
| 1034 | |
| 1035 | if (!count) |
| 1036 | return 0; |
| 1037 | |
| 1038 | mutex_lock(&ar->conf_mutex); |
| 1039 | |
| 1040 | buf = vmalloc(count); |
| 1041 | if (!buf) { |
| 1042 | ret = -ENOMEM; |
| 1043 | goto exit; |
| 1044 | } |
| 1045 | |
| 1046 | if (ar->state != ATH10K_STATE_ON && |
| 1047 | ar->state != ATH10K_STATE_UTF) { |
| 1048 | ret = -ENETDOWN; |
| 1049 | goto exit; |
| 1050 | } |
| 1051 | |
| 1052 | ret = copy_from_user(buf, user_buf, count); |
| 1053 | if (ret) { |
| 1054 | ret = -EFAULT; |
| 1055 | goto exit; |
| 1056 | } |
| 1057 | |
| 1058 | ret = ath10k_hif_diag_write(ar, *ppos, buf, count); |
| 1059 | if (ret) { |
| 1060 | ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n", |
| 1061 | (u32)(*ppos), ret); |
| 1062 | goto exit; |
| 1063 | } |
| 1064 | |
| 1065 | *ppos += count; |
| 1066 | ret = count; |
| 1067 | |
| 1068 | exit: |
| 1069 | vfree(buf); |
| 1070 | mutex_unlock(&ar->conf_mutex); |
| 1071 | |
| 1072 | return ret; |
| 1073 | } |
| 1074 | |
| 1075 | static const struct file_operations fops_mem_value = { |
| 1076 | .read = ath10k_mem_value_read, |
| 1077 | .write = ath10k_mem_value_write, |
| 1078 | .open = simple_open, |
| 1079 | .owner = THIS_MODULE, |
| 1080 | .llseek = default_llseek, |
| 1081 | }; |
| 1082 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1083 | static int ath10k_debug_htt_stats_req(struct ath10k *ar) |
| 1084 | { |
| 1085 | u64 cookie; |
| 1086 | int ret; |
| 1087 | |
| 1088 | lockdep_assert_held(&ar->conf_mutex); |
| 1089 | |
| 1090 | if (ar->debug.htt_stats_mask == 0) |
| 1091 | /* htt stats are disabled */ |
| 1092 | return 0; |
| 1093 | |
| 1094 | if (ar->state != ATH10K_STATE_ON) |
| 1095 | return 0; |
| 1096 | |
| 1097 | cookie = get_jiffies_64(); |
| 1098 | |
| 1099 | ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask, |
| 1100 | cookie); |
| 1101 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1102 | ath10k_warn(ar, "failed to send htt stats request: %d\n", ret); |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1103 | return ret; |
| 1104 | } |
| 1105 | |
| 1106 | queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork, |
| 1107 | msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL)); |
| 1108 | |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
| 1112 | static void ath10k_debug_htt_stats_dwork(struct work_struct *work) |
| 1113 | { |
| 1114 | struct ath10k *ar = container_of(work, struct ath10k, |
| 1115 | debug.htt_stats_dwork.work); |
| 1116 | |
| 1117 | mutex_lock(&ar->conf_mutex); |
| 1118 | |
| 1119 | ath10k_debug_htt_stats_req(ar); |
| 1120 | |
| 1121 | mutex_unlock(&ar->conf_mutex); |
| 1122 | } |
| 1123 | |
| 1124 | static ssize_t ath10k_read_htt_stats_mask(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1125 | char __user *user_buf, |
| 1126 | size_t count, loff_t *ppos) |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1127 | { |
| 1128 | struct ath10k *ar = file->private_data; |
| 1129 | char buf[32]; |
| 1130 | unsigned int len; |
| 1131 | |
| 1132 | len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask); |
| 1133 | |
| 1134 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1135 | } |
| 1136 | |
| 1137 | static ssize_t ath10k_write_htt_stats_mask(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1138 | const char __user *user_buf, |
| 1139 | size_t count, loff_t *ppos) |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1140 | { |
| 1141 | struct ath10k *ar = file->private_data; |
| 1142 | unsigned long mask; |
| 1143 | int ret; |
| 1144 | |
| 1145 | ret = kstrtoul_from_user(user_buf, count, 0, &mask); |
| 1146 | if (ret) |
| 1147 | return ret; |
| 1148 | |
| 1149 | /* max 8 bit masks (for now) */ |
| 1150 | if (mask > 0xff) |
| 1151 | return -E2BIG; |
| 1152 | |
| 1153 | mutex_lock(&ar->conf_mutex); |
| 1154 | |
| 1155 | ar->debug.htt_stats_mask = mask; |
| 1156 | |
| 1157 | ret = ath10k_debug_htt_stats_req(ar); |
| 1158 | if (ret) |
| 1159 | goto out; |
| 1160 | |
| 1161 | ret = count; |
| 1162 | |
| 1163 | out: |
| 1164 | mutex_unlock(&ar->conf_mutex); |
| 1165 | |
| 1166 | return ret; |
| 1167 | } |
| 1168 | |
| 1169 | static const struct file_operations fops_htt_stats_mask = { |
| 1170 | .read = ath10k_read_htt_stats_mask, |
| 1171 | .write = ath10k_write_htt_stats_mask, |
| 1172 | .open = simple_open, |
| 1173 | .owner = THIS_MODULE, |
| 1174 | .llseek = default_llseek, |
| 1175 | }; |
| 1176 | |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1177 | static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file, |
| 1178 | char __user *user_buf, |
| 1179 | size_t count, loff_t *ppos) |
| 1180 | { |
| 1181 | struct ath10k *ar = file->private_data; |
| 1182 | char buf[64]; |
Mohammed Shafi Shajakhan | 81ec3c0 | 2015-11-30 22:29:39 +0530 | [diff] [blame] | 1183 | u8 amsdu, ampdu; |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1184 | unsigned int len; |
| 1185 | |
| 1186 | mutex_lock(&ar->conf_mutex); |
| 1187 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 1188 | amsdu = ar->htt.max_num_amsdu; |
| 1189 | ampdu = ar->htt.max_num_ampdu; |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1190 | mutex_unlock(&ar->conf_mutex); |
| 1191 | |
| 1192 | len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu); |
| 1193 | |
| 1194 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1195 | } |
| 1196 | |
| 1197 | static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file, |
| 1198 | const char __user *user_buf, |
| 1199 | size_t count, loff_t *ppos) |
| 1200 | { |
| 1201 | struct ath10k *ar = file->private_data; |
| 1202 | int res; |
| 1203 | char buf[64]; |
| 1204 | unsigned int amsdu, ampdu; |
| 1205 | |
| 1206 | simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); |
| 1207 | |
| 1208 | /* make sure that buf is null terminated */ |
| 1209 | buf[sizeof(buf) - 1] = 0; |
| 1210 | |
| 1211 | res = sscanf(buf, "%u %u", &amsdu, &du); |
| 1212 | |
| 1213 | if (res != 2) |
| 1214 | return -EINVAL; |
| 1215 | |
| 1216 | mutex_lock(&ar->conf_mutex); |
| 1217 | |
| 1218 | res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu); |
| 1219 | if (res) |
| 1220 | goto out; |
| 1221 | |
| 1222 | res = count; |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 1223 | ar->htt.max_num_amsdu = amsdu; |
| 1224 | ar->htt.max_num_ampdu = ampdu; |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1225 | |
| 1226 | out: |
| 1227 | mutex_unlock(&ar->conf_mutex); |
| 1228 | return res; |
| 1229 | } |
| 1230 | |
| 1231 | static const struct file_operations fops_htt_max_amsdu_ampdu = { |
| 1232 | .read = ath10k_read_htt_max_amsdu_ampdu, |
| 1233 | .write = ath10k_write_htt_max_amsdu_ampdu, |
| 1234 | .open = simple_open, |
| 1235 | .owner = THIS_MODULE, |
| 1236 | .llseek = default_llseek, |
| 1237 | }; |
| 1238 | |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1239 | static ssize_t ath10k_read_fw_dbglog(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1240 | char __user *user_buf, |
| 1241 | size_t count, loff_t *ppos) |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1242 | { |
| 1243 | struct ath10k *ar = file->private_data; |
| 1244 | unsigned int len; |
Maharaja Kennadyrajan | afcbc82 | 2016-08-23 15:35:36 +0530 | [diff] [blame] | 1245 | char buf[96]; |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1246 | |
Maharaja Kennadyrajan | afcbc82 | 2016-08-23 15:35:36 +0530 | [diff] [blame] | 1247 | len = scnprintf(buf, sizeof(buf), "0x%16llx %u\n", |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1248 | ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level); |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1249 | |
| 1250 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1251 | } |
| 1252 | |
| 1253 | static ssize_t ath10k_write_fw_dbglog(struct file *file, |
| 1254 | const char __user *user_buf, |
| 1255 | size_t count, loff_t *ppos) |
| 1256 | { |
| 1257 | struct ath10k *ar = file->private_data; |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1258 | int ret; |
Maharaja Kennadyrajan | afcbc82 | 2016-08-23 15:35:36 +0530 | [diff] [blame] | 1259 | char buf[96]; |
| 1260 | unsigned int log_level; |
| 1261 | u64 mask; |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1262 | |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1263 | simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); |
| 1264 | |
| 1265 | /* make sure that buf is null terminated */ |
| 1266 | buf[sizeof(buf) - 1] = 0; |
| 1267 | |
Maharaja Kennadyrajan | afcbc82 | 2016-08-23 15:35:36 +0530 | [diff] [blame] | 1268 | ret = sscanf(buf, "%llx %u", &mask, &log_level); |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1269 | |
| 1270 | if (!ret) |
| 1271 | return -EINVAL; |
| 1272 | |
| 1273 | if (ret == 1) |
| 1274 | /* default if user did not specify */ |
| 1275 | log_level = ATH10K_DBGLOG_LEVEL_WARN; |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1276 | |
| 1277 | mutex_lock(&ar->conf_mutex); |
| 1278 | |
| 1279 | ar->debug.fw_dbglog_mask = mask; |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1280 | ar->debug.fw_dbglog_level = log_level; |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1281 | |
| 1282 | if (ar->state == ATH10K_STATE_ON) { |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1283 | ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask, |
| 1284 | ar->debug.fw_dbglog_level); |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1285 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1286 | ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n", |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1287 | ret); |
| 1288 | goto exit; |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | ret = count; |
| 1293 | |
| 1294 | exit: |
| 1295 | mutex_unlock(&ar->conf_mutex); |
| 1296 | |
| 1297 | return ret; |
| 1298 | } |
| 1299 | |
Ben Greear | 6cddcc7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 1300 | /* TODO: Would be nice to always support ethtool stats, would need to |
| 1301 | * move the stats storage out of ath10k_debug, or always have ath10k_debug |
| 1302 | * struct available.. |
| 1303 | */ |
| 1304 | |
| 1305 | /* This generally cooresponds to the debugfs fw_stats file */ |
| 1306 | static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = { |
| 1307 | "tx_pkts_nic", |
| 1308 | "tx_bytes_nic", |
| 1309 | "rx_pkts_nic", |
| 1310 | "rx_bytes_nic", |
| 1311 | "d_noise_floor", |
| 1312 | "d_cycle_count", |
| 1313 | "d_phy_error", |
| 1314 | "d_rts_bad", |
| 1315 | "d_rts_good", |
| 1316 | "d_tx_power", /* in .5 dbM I think */ |
| 1317 | "d_rx_crc_err", /* fcs_bad */ |
| 1318 | "d_no_beacon", |
| 1319 | "d_tx_mpdus_queued", |
| 1320 | "d_tx_msdu_queued", |
| 1321 | "d_tx_msdu_dropped", |
| 1322 | "d_local_enqued", |
| 1323 | "d_local_freed", |
| 1324 | "d_tx_ppdu_hw_queued", |
| 1325 | "d_tx_ppdu_reaped", |
| 1326 | "d_tx_fifo_underrun", |
| 1327 | "d_tx_ppdu_abort", |
| 1328 | "d_tx_mpdu_requed", |
| 1329 | "d_tx_excessive_retries", |
| 1330 | "d_tx_hw_rate", |
| 1331 | "d_tx_dropped_sw_retries", |
| 1332 | "d_tx_illegal_rate", |
| 1333 | "d_tx_continuous_xretries", |
| 1334 | "d_tx_timeout", |
| 1335 | "d_tx_mpdu_txop_limit", |
| 1336 | "d_pdev_resets", |
| 1337 | "d_rx_mid_ppdu_route_change", |
| 1338 | "d_rx_status", |
| 1339 | "d_rx_extra_frags_ring0", |
| 1340 | "d_rx_extra_frags_ring1", |
| 1341 | "d_rx_extra_frags_ring2", |
| 1342 | "d_rx_extra_frags_ring3", |
| 1343 | "d_rx_msdu_htt", |
| 1344 | "d_rx_mpdu_htt", |
| 1345 | "d_rx_msdu_stack", |
| 1346 | "d_rx_mpdu_stack", |
| 1347 | "d_rx_phy_err", |
| 1348 | "d_rx_phy_err_drops", |
| 1349 | "d_rx_mpdu_errors", /* FCS, MIC, ENC */ |
| 1350 | "d_fw_crash_count", |
| 1351 | "d_fw_warm_reset_count", |
| 1352 | "d_fw_cold_reset_count", |
| 1353 | }; |
| 1354 | |
| 1355 | #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats) |
| 1356 | |
| 1357 | void ath10k_debug_get_et_strings(struct ieee80211_hw *hw, |
| 1358 | struct ieee80211_vif *vif, |
| 1359 | u32 sset, u8 *data) |
| 1360 | { |
| 1361 | if (sset == ETH_SS_STATS) |
| 1362 | memcpy(data, *ath10k_gstrings_stats, |
| 1363 | sizeof(ath10k_gstrings_stats)); |
| 1364 | } |
| 1365 | |
| 1366 | int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw, |
| 1367 | struct ieee80211_vif *vif, int sset) |
| 1368 | { |
| 1369 | if (sset == ETH_SS_STATS) |
| 1370 | return ATH10K_SSTATS_LEN; |
| 1371 | |
| 1372 | return 0; |
| 1373 | } |
| 1374 | |
| 1375 | void ath10k_debug_get_et_stats(struct ieee80211_hw *hw, |
| 1376 | struct ieee80211_vif *vif, |
| 1377 | struct ethtool_stats *stats, u64 *data) |
| 1378 | { |
| 1379 | struct ath10k *ar = hw->priv; |
| 1380 | static const struct ath10k_fw_stats_pdev zero_stats = {}; |
| 1381 | const struct ath10k_fw_stats_pdev *pdev_stats; |
| 1382 | int i = 0, ret; |
| 1383 | |
| 1384 | mutex_lock(&ar->conf_mutex); |
| 1385 | |
| 1386 | if (ar->state == ATH10K_STATE_ON) { |
| 1387 | ret = ath10k_debug_fw_stats_request(ar); |
| 1388 | if (ret) { |
| 1389 | /* just print a warning and try to use older results */ |
| 1390 | ath10k_warn(ar, |
| 1391 | "failed to get fw stats for ethtool: %d\n", |
| 1392 | ret); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs, |
| 1397 | struct ath10k_fw_stats_pdev, |
| 1398 | list); |
| 1399 | if (!pdev_stats) { |
| 1400 | /* no results available so just return zeroes */ |
| 1401 | pdev_stats = &zero_stats; |
| 1402 | } |
| 1403 | |
| 1404 | spin_lock_bh(&ar->data_lock); |
| 1405 | |
| 1406 | data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */ |
| 1407 | data[i++] = 0; /* tx bytes */ |
| 1408 | data[i++] = pdev_stats->htt_mpdus; |
| 1409 | data[i++] = 0; /* rx bytes */ |
| 1410 | data[i++] = pdev_stats->ch_noise_floor; |
| 1411 | data[i++] = pdev_stats->cycle_count; |
| 1412 | data[i++] = pdev_stats->phy_err_count; |
| 1413 | data[i++] = pdev_stats->rts_bad; |
| 1414 | data[i++] = pdev_stats->rts_good; |
| 1415 | data[i++] = pdev_stats->chan_tx_power; |
| 1416 | data[i++] = pdev_stats->fcs_bad; |
| 1417 | data[i++] = pdev_stats->no_beacons; |
| 1418 | data[i++] = pdev_stats->mpdu_enqued; |
| 1419 | data[i++] = pdev_stats->msdu_enqued; |
| 1420 | data[i++] = pdev_stats->wmm_drop; |
| 1421 | data[i++] = pdev_stats->local_enqued; |
| 1422 | data[i++] = pdev_stats->local_freed; |
| 1423 | data[i++] = pdev_stats->hw_queued; |
| 1424 | data[i++] = pdev_stats->hw_reaped; |
| 1425 | data[i++] = pdev_stats->underrun; |
| 1426 | data[i++] = pdev_stats->tx_abort; |
| 1427 | data[i++] = pdev_stats->mpdus_requed; |
| 1428 | data[i++] = pdev_stats->tx_ko; |
| 1429 | data[i++] = pdev_stats->data_rc; |
| 1430 | data[i++] = pdev_stats->sw_retry_failure; |
| 1431 | data[i++] = pdev_stats->illgl_rate_phy_err; |
| 1432 | data[i++] = pdev_stats->pdev_cont_xretry; |
| 1433 | data[i++] = pdev_stats->pdev_tx_timeout; |
| 1434 | data[i++] = pdev_stats->txop_ovf; |
| 1435 | data[i++] = pdev_stats->pdev_resets; |
| 1436 | data[i++] = pdev_stats->mid_ppdu_route_change; |
| 1437 | data[i++] = pdev_stats->status_rcvd; |
| 1438 | data[i++] = pdev_stats->r0_frags; |
| 1439 | data[i++] = pdev_stats->r1_frags; |
| 1440 | data[i++] = pdev_stats->r2_frags; |
| 1441 | data[i++] = pdev_stats->r3_frags; |
| 1442 | data[i++] = pdev_stats->htt_msdus; |
| 1443 | data[i++] = pdev_stats->htt_mpdus; |
| 1444 | data[i++] = pdev_stats->loc_msdus; |
| 1445 | data[i++] = pdev_stats->loc_mpdus; |
| 1446 | data[i++] = pdev_stats->phy_errs; |
| 1447 | data[i++] = pdev_stats->phy_err_drop; |
| 1448 | data[i++] = pdev_stats->mpdu_errs; |
| 1449 | data[i++] = ar->stats.fw_crash_counter; |
| 1450 | data[i++] = ar->stats.fw_warm_reset_counter; |
| 1451 | data[i++] = ar->stats.fw_cold_reset_counter; |
| 1452 | |
| 1453 | spin_unlock_bh(&ar->data_lock); |
| 1454 | |
| 1455 | mutex_unlock(&ar->conf_mutex); |
| 1456 | |
| 1457 | WARN_ON(i != ATH10K_SSTATS_LEN); |
| 1458 | } |
| 1459 | |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1460 | static const struct file_operations fops_fw_dbglog = { |
| 1461 | .read = ath10k_read_fw_dbglog, |
| 1462 | .write = ath10k_write_fw_dbglog, |
| 1463 | .open = simple_open, |
| 1464 | .owner = THIS_MODULE, |
| 1465 | .llseek = default_llseek, |
| 1466 | }; |
| 1467 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1468 | static int ath10k_debug_cal_data_fetch(struct ath10k *ar) |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1469 | { |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1470 | u32 hi_addr; |
| 1471 | __le32 addr; |
| 1472 | int ret; |
| 1473 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1474 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1475 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1476 | if (WARN_ON(ar->hw_params.cal_data_len > ATH10K_DEBUG_CAL_DATA_LEN)) |
| 1477 | return -EINVAL; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1478 | |
| 1479 | hi_addr = host_interest_item_address(HI_ITEM(hi_board_data)); |
| 1480 | |
| 1481 | ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr)); |
| 1482 | if (ret) { |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1483 | ath10k_warn(ar, "failed to read hi_board_data address: %d\n", |
| 1484 | ret); |
| 1485 | return ret; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1486 | } |
| 1487 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1488 | 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] | 1489 | ar->hw_params.cal_data_len); |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1490 | if (ret) { |
| 1491 | ath10k_warn(ar, "failed to read calibration data: %d\n", ret); |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1492 | return ret; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1493 | } |
| 1494 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1495 | return 0; |
| 1496 | } |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1497 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1498 | static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file) |
| 1499 | { |
| 1500 | struct ath10k *ar = inode->i_private; |
| 1501 | |
| 1502 | mutex_lock(&ar->conf_mutex); |
| 1503 | |
| 1504 | if (ar->state == ATH10K_STATE_ON || |
| 1505 | ar->state == ATH10K_STATE_UTF) { |
| 1506 | ath10k_debug_cal_data_fetch(ar); |
| 1507 | } |
| 1508 | |
| 1509 | file->private_data = ar; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1510 | mutex_unlock(&ar->conf_mutex); |
| 1511 | |
| 1512 | return 0; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | static ssize_t ath10k_debug_cal_data_read(struct file *file, |
| 1516 | char __user *user_buf, |
| 1517 | size_t count, loff_t *ppos) |
| 1518 | { |
Raja Mani | 0b8e3c4 | 2016-03-18 11:44:22 +0200 | [diff] [blame] | 1519 | struct ath10k *ar = file->private_data; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1520 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1521 | mutex_lock(&ar->conf_mutex); |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1522 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1523 | count = simple_read_from_buffer(user_buf, count, ppos, |
| 1524 | ar->debug.cal_data, |
| 1525 | ar->hw_params.cal_data_len); |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1526 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1527 | mutex_unlock(&ar->conf_mutex); |
| 1528 | |
| 1529 | return count; |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1530 | } |
| 1531 | |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 1532 | static ssize_t ath10k_write_ani_enable(struct file *file, |
| 1533 | const char __user *user_buf, |
| 1534 | size_t count, loff_t *ppos) |
| 1535 | { |
| 1536 | struct ath10k *ar = file->private_data; |
| 1537 | int ret; |
| 1538 | u8 enable; |
| 1539 | |
| 1540 | if (kstrtou8_from_user(user_buf, count, 0, &enable)) |
| 1541 | return -EINVAL; |
| 1542 | |
| 1543 | mutex_lock(&ar->conf_mutex); |
| 1544 | |
| 1545 | if (ar->ani_enabled == enable) { |
| 1546 | ret = count; |
| 1547 | goto exit; |
| 1548 | } |
| 1549 | |
| 1550 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable, |
| 1551 | enable); |
| 1552 | if (ret) { |
| 1553 | ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret); |
| 1554 | goto exit; |
| 1555 | } |
| 1556 | ar->ani_enabled = enable; |
| 1557 | |
| 1558 | ret = count; |
| 1559 | |
| 1560 | exit: |
| 1561 | mutex_unlock(&ar->conf_mutex); |
| 1562 | |
| 1563 | return ret; |
| 1564 | } |
| 1565 | |
| 1566 | static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf, |
| 1567 | size_t count, loff_t *ppos) |
| 1568 | { |
| 1569 | struct ath10k *ar = file->private_data; |
| 1570 | int len = 0; |
| 1571 | char buf[32]; |
| 1572 | |
| 1573 | len = scnprintf(buf, sizeof(buf) - len, "%d\n", |
| 1574 | ar->ani_enabled); |
| 1575 | |
| 1576 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1577 | } |
| 1578 | |
| 1579 | static const struct file_operations fops_ani_enable = { |
| 1580 | .read = ath10k_read_ani_enable, |
| 1581 | .write = ath10k_write_ani_enable, |
| 1582 | .open = simple_open, |
| 1583 | .owner = THIS_MODULE, |
| 1584 | .llseek = default_llseek, |
| 1585 | }; |
| 1586 | |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1587 | static const struct file_operations fops_cal_data = { |
| 1588 | .open = ath10k_debug_cal_data_open, |
| 1589 | .read = ath10k_debug_cal_data_read, |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 1590 | .owner = THIS_MODULE, |
| 1591 | .llseek = default_llseek, |
| 1592 | }; |
| 1593 | |
Peter Oh | a7bd3e9 | 2014-12-02 13:07:14 +0200 | [diff] [blame] | 1594 | static ssize_t ath10k_read_nf_cal_period(struct file *file, |
| 1595 | char __user *user_buf, |
| 1596 | size_t count, loff_t *ppos) |
| 1597 | { |
| 1598 | struct ath10k *ar = file->private_data; |
| 1599 | unsigned int len; |
| 1600 | char buf[32]; |
| 1601 | |
| 1602 | len = scnprintf(buf, sizeof(buf), "%d\n", |
| 1603 | ar->debug.nf_cal_period); |
| 1604 | |
| 1605 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1606 | } |
| 1607 | |
| 1608 | static ssize_t ath10k_write_nf_cal_period(struct file *file, |
| 1609 | const char __user *user_buf, |
| 1610 | size_t count, loff_t *ppos) |
| 1611 | { |
| 1612 | struct ath10k *ar = file->private_data; |
| 1613 | unsigned long period; |
| 1614 | int ret; |
| 1615 | |
| 1616 | ret = kstrtoul_from_user(user_buf, count, 0, &period); |
| 1617 | if (ret) |
| 1618 | return ret; |
| 1619 | |
| 1620 | if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX) |
| 1621 | return -EINVAL; |
| 1622 | |
| 1623 | /* there's no way to switch back to the firmware default */ |
| 1624 | if (period == 0) |
| 1625 | return -EINVAL; |
| 1626 | |
| 1627 | mutex_lock(&ar->conf_mutex); |
| 1628 | |
| 1629 | ar->debug.nf_cal_period = period; |
| 1630 | |
| 1631 | if (ar->state != ATH10K_STATE_ON) { |
| 1632 | /* firmware is not running, nothing else to do */ |
| 1633 | ret = count; |
| 1634 | goto exit; |
| 1635 | } |
| 1636 | |
| 1637 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period, |
| 1638 | ar->debug.nf_cal_period); |
| 1639 | if (ret) { |
| 1640 | ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n", |
| 1641 | ret); |
| 1642 | goto exit; |
| 1643 | } |
| 1644 | |
| 1645 | ret = count; |
| 1646 | |
| 1647 | exit: |
| 1648 | mutex_unlock(&ar->conf_mutex); |
| 1649 | |
| 1650 | return ret; |
| 1651 | } |
| 1652 | |
| 1653 | static const struct file_operations fops_nf_cal_period = { |
| 1654 | .read = ath10k_read_nf_cal_period, |
| 1655 | .write = ath10k_write_nf_cal_period, |
| 1656 | .open = simple_open, |
| 1657 | .owner = THIS_MODULE, |
| 1658 | .llseek = default_llseek, |
| 1659 | }; |
| 1660 | |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 1661 | #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024) |
| 1662 | |
| 1663 | static int ath10k_debug_tpc_stats_request(struct ath10k *ar) |
| 1664 | { |
| 1665 | int ret; |
| 1666 | unsigned long time_left; |
| 1667 | |
| 1668 | lockdep_assert_held(&ar->conf_mutex); |
| 1669 | |
| 1670 | reinit_completion(&ar->debug.tpc_complete); |
| 1671 | |
| 1672 | ret = ath10k_wmi_pdev_get_tpc_config(ar, WMI_TPC_CONFIG_PARAM); |
| 1673 | if (ret) { |
| 1674 | ath10k_warn(ar, "failed to request tpc config: %d\n", ret); |
| 1675 | return ret; |
| 1676 | } |
| 1677 | |
| 1678 | time_left = wait_for_completion_timeout(&ar->debug.tpc_complete, |
| 1679 | 1 * HZ); |
| 1680 | if (time_left == 0) |
| 1681 | return -ETIMEDOUT; |
| 1682 | |
| 1683 | return 0; |
| 1684 | } |
| 1685 | |
| 1686 | void ath10k_debug_tpc_stats_process(struct ath10k *ar, |
| 1687 | struct ath10k_tpc_stats *tpc_stats) |
| 1688 | { |
| 1689 | spin_lock_bh(&ar->data_lock); |
| 1690 | |
| 1691 | kfree(ar->debug.tpc_stats); |
| 1692 | ar->debug.tpc_stats = tpc_stats; |
| 1693 | complete(&ar->debug.tpc_complete); |
| 1694 | |
| 1695 | spin_unlock_bh(&ar->data_lock); |
| 1696 | } |
| 1697 | |
| 1698 | static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats, |
| 1699 | unsigned int j, char *buf, unsigned int *len) |
| 1700 | { |
| 1701 | unsigned int i, buf_len; |
| 1702 | static const char table_str[][5] = { "CDD", |
| 1703 | "STBC", |
| 1704 | "TXBF" }; |
| 1705 | static const char pream_str[][6] = { "CCK", |
| 1706 | "OFDM", |
| 1707 | "HT20", |
| 1708 | "HT40", |
| 1709 | "VHT20", |
| 1710 | "VHT40", |
| 1711 | "VHT80", |
| 1712 | "HTCUP" }; |
| 1713 | |
| 1714 | buf_len = ATH10K_TPC_CONFIG_BUF_SIZE; |
| 1715 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1716 | "********************************\n"); |
| 1717 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1718 | "******************* %s POWER TABLE ****************\n", |
| 1719 | table_str[j]); |
| 1720 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1721 | "********************************\n"); |
| 1722 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1723 | "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n"); |
| 1724 | |
| 1725 | for (i = 0; i < tpc_stats->rate_max; i++) { |
| 1726 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1727 | "%8d %s 0x%2x %s\n", i, |
| 1728 | pream_str[tpc_stats->tpc_table[j].pream_idx[i]], |
| 1729 | tpc_stats->tpc_table[j].rate_code[i], |
| 1730 | tpc_stats->tpc_table[j].tpc_value[i]); |
| 1731 | } |
| 1732 | |
| 1733 | *len += scnprintf(buf + *len, buf_len - *len, |
| 1734 | "***********************************\n"); |
| 1735 | } |
| 1736 | |
| 1737 | static void ath10k_tpc_stats_fill(struct ath10k *ar, |
| 1738 | struct ath10k_tpc_stats *tpc_stats, |
| 1739 | char *buf) |
| 1740 | { |
| 1741 | unsigned int len, j, buf_len; |
| 1742 | |
| 1743 | len = 0; |
| 1744 | buf_len = ATH10K_TPC_CONFIG_BUF_SIZE; |
| 1745 | |
| 1746 | spin_lock_bh(&ar->data_lock); |
| 1747 | |
| 1748 | if (!tpc_stats) { |
| 1749 | ath10k_warn(ar, "failed to get tpc stats\n"); |
| 1750 | goto unlock; |
| 1751 | } |
| 1752 | |
| 1753 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 1754 | len += scnprintf(buf + len, buf_len - len, |
| 1755 | "*************************************\n"); |
| 1756 | len += scnprintf(buf + len, buf_len - len, |
| 1757 | "TPC config for channel %4d mode %d\n", |
| 1758 | tpc_stats->chan_freq, |
| 1759 | tpc_stats->phy_mode); |
| 1760 | len += scnprintf(buf + len, buf_len - len, |
| 1761 | "*************************************\n"); |
| 1762 | len += scnprintf(buf + len, buf_len - len, |
| 1763 | "CTL = 0x%2x Reg. Domain = %2d\n", |
| 1764 | tpc_stats->ctl, |
| 1765 | tpc_stats->reg_domain); |
| 1766 | len += scnprintf(buf + len, buf_len - len, |
| 1767 | "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n", |
| 1768 | tpc_stats->twice_antenna_gain, |
| 1769 | tpc_stats->twice_antenna_reduction); |
| 1770 | len += scnprintf(buf + len, buf_len - len, |
| 1771 | "Power Limit = %2d Reg. Max Power = %2d\n", |
| 1772 | tpc_stats->power_limit, |
| 1773 | tpc_stats->twice_max_rd_power / 2); |
| 1774 | len += scnprintf(buf + len, buf_len - len, |
| 1775 | "Num tx chains = %2d Num supported rates = %2d\n", |
| 1776 | tpc_stats->num_tx_chain, |
| 1777 | tpc_stats->rate_max); |
| 1778 | |
| 1779 | for (j = 0; j < tpc_stats->num_tx_chain ; j++) { |
| 1780 | switch (j) { |
| 1781 | case WMI_TPC_TABLE_TYPE_CDD: |
| 1782 | if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) { |
| 1783 | len += scnprintf(buf + len, buf_len - len, |
| 1784 | "CDD not supported\n"); |
| 1785 | break; |
| 1786 | } |
| 1787 | |
| 1788 | ath10k_tpc_stats_print(tpc_stats, j, buf, &len); |
| 1789 | break; |
| 1790 | case WMI_TPC_TABLE_TYPE_STBC: |
| 1791 | if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) { |
| 1792 | len += scnprintf(buf + len, buf_len - len, |
| 1793 | "STBC not supported\n"); |
| 1794 | break; |
| 1795 | } |
| 1796 | |
| 1797 | ath10k_tpc_stats_print(tpc_stats, j, buf, &len); |
| 1798 | break; |
| 1799 | case WMI_TPC_TABLE_TYPE_TXBF: |
| 1800 | if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) { |
| 1801 | len += scnprintf(buf + len, buf_len - len, |
| 1802 | "TXBF not supported\n***************************\n"); |
| 1803 | break; |
| 1804 | } |
| 1805 | |
| 1806 | ath10k_tpc_stats_print(tpc_stats, j, buf, &len); |
| 1807 | break; |
| 1808 | default: |
| 1809 | len += scnprintf(buf + len, buf_len - len, |
| 1810 | "Invalid Type\n"); |
| 1811 | break; |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | unlock: |
| 1816 | spin_unlock_bh(&ar->data_lock); |
| 1817 | |
| 1818 | if (len >= buf_len) |
| 1819 | buf[len - 1] = 0; |
| 1820 | else |
| 1821 | buf[len] = 0; |
| 1822 | } |
| 1823 | |
| 1824 | static int ath10k_tpc_stats_open(struct inode *inode, struct file *file) |
| 1825 | { |
| 1826 | struct ath10k *ar = inode->i_private; |
| 1827 | void *buf = NULL; |
| 1828 | int ret; |
| 1829 | |
| 1830 | mutex_lock(&ar->conf_mutex); |
| 1831 | |
| 1832 | if (ar->state != ATH10K_STATE_ON) { |
| 1833 | ret = -ENETDOWN; |
| 1834 | goto err_unlock; |
| 1835 | } |
| 1836 | |
| 1837 | buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE); |
| 1838 | if (!buf) { |
| 1839 | ret = -ENOMEM; |
| 1840 | goto err_unlock; |
| 1841 | } |
| 1842 | |
| 1843 | ret = ath10k_debug_tpc_stats_request(ar); |
| 1844 | if (ret) { |
| 1845 | ath10k_warn(ar, "failed to request tpc config stats: %d\n", |
| 1846 | ret); |
| 1847 | goto err_free; |
| 1848 | } |
| 1849 | |
| 1850 | ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf); |
| 1851 | file->private_data = buf; |
| 1852 | |
| 1853 | mutex_unlock(&ar->conf_mutex); |
| 1854 | return 0; |
| 1855 | |
| 1856 | err_free: |
| 1857 | vfree(buf); |
| 1858 | |
| 1859 | err_unlock: |
| 1860 | mutex_unlock(&ar->conf_mutex); |
| 1861 | return ret; |
| 1862 | } |
| 1863 | |
| 1864 | static int ath10k_tpc_stats_release(struct inode *inode, struct file *file) |
| 1865 | { |
| 1866 | vfree(file->private_data); |
| 1867 | |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
| 1871 | static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf, |
| 1872 | size_t count, loff_t *ppos) |
| 1873 | { |
| 1874 | const char *buf = file->private_data; |
| 1875 | unsigned int len = strlen(buf); |
| 1876 | |
| 1877 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1878 | } |
| 1879 | |
| 1880 | static const struct file_operations fops_tpc_stats = { |
| 1881 | .open = ath10k_tpc_stats_open, |
| 1882 | .release = ath10k_tpc_stats_release, |
| 1883 | .read = ath10k_tpc_stats_read, |
| 1884 | .owner = THIS_MODULE, |
| 1885 | .llseek = default_llseek, |
| 1886 | }; |
| 1887 | |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1888 | int ath10k_debug_start(struct ath10k *ar) |
| 1889 | { |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1890 | int ret; |
| 1891 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1892 | lockdep_assert_held(&ar->conf_mutex); |
| 1893 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1894 | ret = ath10k_debug_htt_stats_req(ar); |
| 1895 | if (ret) |
| 1896 | /* continue normally anyway, this isn't serious */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1897 | ath10k_warn(ar, "failed to start htt stats workqueue: %d\n", |
| 1898 | ret); |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1899 | |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1900 | if (ar->debug.fw_dbglog_mask) { |
SenthilKumar Jegadeesan | 467210a | 2015-01-29 14:36:52 +0530 | [diff] [blame] | 1901 | ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask, |
| 1902 | ATH10K_DBGLOG_LEVEL_WARN); |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1903 | if (ret) |
| 1904 | /* not serious */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1905 | ath10k_warn(ar, "failed to enable dbglog during start: %d", |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1906 | ret); |
| 1907 | } |
| 1908 | |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1909 | if (ar->debug.pktlog_filter) { |
| 1910 | ret = ath10k_wmi_pdev_pktlog_enable(ar, |
| 1911 | ar->debug.pktlog_filter); |
| 1912 | if (ret) |
| 1913 | /* not serious */ |
| 1914 | ath10k_warn(ar, |
| 1915 | "failed to enable pktlog filter %x: %d\n", |
| 1916 | ar->debug.pktlog_filter, ret); |
| 1917 | } else { |
| 1918 | ret = ath10k_wmi_pdev_pktlog_disable(ar); |
| 1919 | if (ret) |
| 1920 | /* not serious */ |
| 1921 | ath10k_warn(ar, "failed to disable pktlog: %d\n", ret); |
| 1922 | } |
| 1923 | |
Peter Oh | a7bd3e9 | 2014-12-02 13:07:14 +0200 | [diff] [blame] | 1924 | if (ar->debug.nf_cal_period) { |
| 1925 | ret = ath10k_wmi_pdev_set_param(ar, |
| 1926 | ar->wmi.pdev_param->cal_period, |
| 1927 | ar->debug.nf_cal_period); |
| 1928 | if (ret) |
| 1929 | /* not serious */ |
| 1930 | ath10k_warn(ar, "cal period cfg failed from debug start: %d\n", |
| 1931 | ret); |
| 1932 | } |
| 1933 | |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1934 | return ret; |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | void ath10k_debug_stop(struct ath10k *ar) |
| 1938 | { |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1939 | lockdep_assert_held(&ar->conf_mutex); |
| 1940 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 1941 | ath10k_debug_cal_data_fetch(ar); |
| 1942 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1943 | /* Must not use _sync to avoid deadlock, we do that in |
| 1944 | * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid |
| 1945 | * warning from del_timer(). */ |
| 1946 | if (ar->debug.htt_stats_mask != 0) |
| 1947 | cancel_delayed_work(&ar->debug.htt_stats_dwork); |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1948 | |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 1949 | ath10k_wmi_pdev_pktlog_disable(ar); |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1950 | } |
| 1951 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1952 | static ssize_t ath10k_write_simulate_radar(struct file *file, |
| 1953 | const char __user *user_buf, |
| 1954 | size_t count, loff_t *ppos) |
| 1955 | { |
| 1956 | struct ath10k *ar = file->private_data; |
Mohammed Shafi Shajakhan | 6a528eb | 2017-02-22 21:03:11 +0530 | [diff] [blame] | 1957 | struct ath10k_vif *arvif; |
| 1958 | |
| 1959 | /* Just check for for the first vif alone, as all the vifs will be |
| 1960 | * sharing the same channel and if the channel is disabled, all the |
| 1961 | * vifs will share the same 'is_started' state. |
| 1962 | */ |
| 1963 | arvif = list_first_entry(&ar->arvifs, typeof(*arvif), list); |
| 1964 | if (!arvif->is_started) |
| 1965 | return -EINVAL; |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1966 | |
| 1967 | ieee80211_radar_detected(ar->hw); |
| 1968 | |
| 1969 | return count; |
| 1970 | } |
| 1971 | |
| 1972 | static const struct file_operations fops_simulate_radar = { |
| 1973 | .write = ath10k_write_simulate_radar, |
| 1974 | .open = simple_open, |
| 1975 | .owner = THIS_MODULE, |
| 1976 | .llseek = default_llseek, |
| 1977 | }; |
| 1978 | |
| 1979 | #define ATH10K_DFS_STAT(s, p) (\ |
| 1980 | len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \ |
| 1981 | ar->debug.dfs_stats.p)) |
| 1982 | |
| 1983 | #define ATH10K_DFS_POOL_STAT(s, p) (\ |
| 1984 | len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \ |
| 1985 | ar->debug.dfs_pool_stats.p)) |
| 1986 | |
| 1987 | static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf, |
| 1988 | size_t count, loff_t *ppos) |
| 1989 | { |
| 1990 | int retval = 0, len = 0; |
| 1991 | const int size = 8000; |
| 1992 | struct ath10k *ar = file->private_data; |
| 1993 | char *buf; |
| 1994 | |
| 1995 | buf = kzalloc(size, GFP_KERNEL); |
| 1996 | if (buf == NULL) |
| 1997 | return -ENOMEM; |
| 1998 | |
| 1999 | if (!ar->dfs_detector) { |
| 2000 | len += scnprintf(buf + len, size - len, "DFS not enabled\n"); |
| 2001 | goto exit; |
| 2002 | } |
| 2003 | |
| 2004 | ar->debug.dfs_pool_stats = |
| 2005 | ar->dfs_detector->get_stats(ar->dfs_detector); |
| 2006 | |
| 2007 | len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n"); |
| 2008 | |
| 2009 | ATH10K_DFS_STAT("reported phy errors", phy_errors); |
| 2010 | ATH10K_DFS_STAT("pulse events reported", pulses_total); |
| 2011 | ATH10K_DFS_STAT("DFS pulses detected", pulses_detected); |
| 2012 | ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded); |
| 2013 | ATH10K_DFS_STAT("Radars detected", radar_detected); |
| 2014 | |
| 2015 | len += scnprintf(buf + len, size - len, "Global Pool statistics:\n"); |
| 2016 | ATH10K_DFS_POOL_STAT("Pool references", pool_reference); |
| 2017 | ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated); |
| 2018 | ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error); |
| 2019 | ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used); |
| 2020 | ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated); |
| 2021 | ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error); |
| 2022 | ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used); |
| 2023 | |
| 2024 | exit: |
| 2025 | if (len > size) |
| 2026 | len = size; |
| 2027 | |
| 2028 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 2029 | kfree(buf); |
| 2030 | |
| 2031 | return retval; |
| 2032 | } |
| 2033 | |
| 2034 | static const struct file_operations fops_dfs_stats = { |
| 2035 | .read = ath10k_read_dfs_stats, |
| 2036 | .open = simple_open, |
| 2037 | .owner = THIS_MODULE, |
| 2038 | .llseek = default_llseek, |
| 2039 | }; |
| 2040 | |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 2041 | static ssize_t ath10k_write_pktlog_filter(struct file *file, |
| 2042 | const char __user *ubuf, |
| 2043 | size_t count, loff_t *ppos) |
| 2044 | { |
| 2045 | struct ath10k *ar = file->private_data; |
| 2046 | u32 filter; |
| 2047 | int ret; |
| 2048 | |
| 2049 | if (kstrtouint_from_user(ubuf, count, 0, &filter)) |
| 2050 | return -EINVAL; |
| 2051 | |
| 2052 | mutex_lock(&ar->conf_mutex); |
| 2053 | |
| 2054 | if (ar->state != ATH10K_STATE_ON) { |
| 2055 | ar->debug.pktlog_filter = filter; |
| 2056 | ret = count; |
| 2057 | goto out; |
| 2058 | } |
| 2059 | |
Anilkumar Kolli | 9ddc486 | 2016-03-11 11:46:39 +0530 | [diff] [blame] | 2060 | if (filter == ar->debug.pktlog_filter) { |
| 2061 | ret = count; |
| 2062 | goto out; |
| 2063 | } |
| 2064 | |
| 2065 | if (filter) { |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 2066 | ret = ath10k_wmi_pdev_pktlog_enable(ar, filter); |
| 2067 | if (ret) { |
| 2068 | ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n", |
| 2069 | ar->debug.pktlog_filter, ret); |
| 2070 | goto out; |
| 2071 | } |
| 2072 | } else { |
| 2073 | ret = ath10k_wmi_pdev_pktlog_disable(ar); |
| 2074 | if (ret) { |
| 2075 | ath10k_warn(ar, "failed to disable pktlog: %d\n", ret); |
| 2076 | goto out; |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | ar->debug.pktlog_filter = filter; |
| 2081 | ret = count; |
| 2082 | |
| 2083 | out: |
| 2084 | mutex_unlock(&ar->conf_mutex); |
| 2085 | return ret; |
| 2086 | } |
| 2087 | |
| 2088 | static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf, |
| 2089 | size_t count, loff_t *ppos) |
| 2090 | { |
| 2091 | char buf[32]; |
| 2092 | struct ath10k *ar = file->private_data; |
| 2093 | int len = 0; |
| 2094 | |
| 2095 | mutex_lock(&ar->conf_mutex); |
| 2096 | len = scnprintf(buf, sizeof(buf) - len, "%08x\n", |
| 2097 | ar->debug.pktlog_filter); |
| 2098 | mutex_unlock(&ar->conf_mutex); |
| 2099 | |
| 2100 | return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 2101 | } |
| 2102 | |
| 2103 | static const struct file_operations fops_pktlog_filter = { |
| 2104 | .read = ath10k_read_pktlog_filter, |
| 2105 | .write = ath10k_write_pktlog_filter, |
| 2106 | .open = simple_open |
| 2107 | }; |
| 2108 | |
Rajkumar Manoharan | 63fb32d | 2015-03-15 20:36:20 +0530 | [diff] [blame] | 2109 | static ssize_t ath10k_write_quiet_period(struct file *file, |
| 2110 | const char __user *ubuf, |
| 2111 | size_t count, loff_t *ppos) |
| 2112 | { |
| 2113 | struct ath10k *ar = file->private_data; |
| 2114 | u32 period; |
| 2115 | |
| 2116 | if (kstrtouint_from_user(ubuf, count, 0, &period)) |
| 2117 | return -EINVAL; |
| 2118 | |
| 2119 | if (period < ATH10K_QUIET_PERIOD_MIN) { |
| 2120 | ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n", |
| 2121 | period); |
| 2122 | return -EINVAL; |
| 2123 | } |
| 2124 | mutex_lock(&ar->conf_mutex); |
| 2125 | ar->thermal.quiet_period = period; |
Rajkumar Manoharan | 8515b5c | 2015-03-15 20:36:22 +0530 | [diff] [blame] | 2126 | ath10k_thermal_set_throttling(ar); |
Rajkumar Manoharan | 63fb32d | 2015-03-15 20:36:20 +0530 | [diff] [blame] | 2127 | mutex_unlock(&ar->conf_mutex); |
| 2128 | |
| 2129 | return count; |
| 2130 | } |
| 2131 | |
| 2132 | static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf, |
| 2133 | size_t count, loff_t *ppos) |
| 2134 | { |
| 2135 | char buf[32]; |
| 2136 | struct ath10k *ar = file->private_data; |
| 2137 | int len = 0; |
| 2138 | |
| 2139 | mutex_lock(&ar->conf_mutex); |
| 2140 | len = scnprintf(buf, sizeof(buf) - len, "%d\n", |
| 2141 | ar->thermal.quiet_period); |
| 2142 | mutex_unlock(&ar->conf_mutex); |
| 2143 | |
| 2144 | return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 2145 | } |
| 2146 | |
| 2147 | static const struct file_operations fops_quiet_period = { |
| 2148 | .read = ath10k_read_quiet_period, |
| 2149 | .write = ath10k_write_quiet_period, |
| 2150 | .open = simple_open |
| 2151 | }; |
| 2152 | |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2153 | static ssize_t ath10k_write_btcoex(struct file *file, |
| 2154 | const char __user *ubuf, |
| 2155 | size_t count, loff_t *ppos) |
| 2156 | { |
| 2157 | struct ath10k *ar = file->private_data; |
| 2158 | char buf[32]; |
| 2159 | size_t buf_size; |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2160 | int ret; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2161 | bool val; |
Rajkumar Manoharan | 3913624 | 2016-05-27 20:15:59 +0530 | [diff] [blame] | 2162 | u32 pdev_param; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2163 | |
| 2164 | buf_size = min(count, (sizeof(buf) - 1)); |
| 2165 | if (copy_from_user(buf, ubuf, buf_size)) |
| 2166 | return -EFAULT; |
| 2167 | |
| 2168 | buf[buf_size] = '\0'; |
| 2169 | |
| 2170 | if (strtobool(buf, &val) != 0) |
| 2171 | return -EINVAL; |
| 2172 | |
| 2173 | mutex_lock(&ar->conf_mutex); |
| 2174 | |
Mohammed Shafi Shajakhan | c28e6f0 | 2016-02-23 12:58:36 +0530 | [diff] [blame] | 2175 | if (ar->state != ATH10K_STATE_ON && |
| 2176 | ar->state != ATH10K_STATE_RESTARTED) { |
| 2177 | ret = -ENETDOWN; |
| 2178 | goto exit; |
| 2179 | } |
| 2180 | |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2181 | if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val)) { |
| 2182 | ret = count; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2183 | goto exit; |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2184 | } |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2185 | |
Rajkumar Manoharan | 3913624 | 2016-05-27 20:15:59 +0530 | [diff] [blame] | 2186 | pdev_param = ar->wmi.pdev_param->enable_btcoex; |
| 2187 | if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM, |
| 2188 | ar->running_fw->fw_file.fw_features)) { |
| 2189 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, val); |
| 2190 | if (ret) { |
| 2191 | ath10k_warn(ar, "failed to enable btcoex: %d\n", ret); |
| 2192 | ret = count; |
| 2193 | goto exit; |
| 2194 | } |
| 2195 | } else { |
| 2196 | ath10k_info(ar, "restarting firmware due to btcoex change"); |
| 2197 | queue_work(ar->workqueue, &ar->restart_work); |
| 2198 | } |
| 2199 | |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2200 | if (val) |
| 2201 | set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags); |
| 2202 | else |
| 2203 | clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags); |
| 2204 | |
Mohammed Shafi Shajakhan | c28e6f0 | 2016-02-23 12:58:36 +0530 | [diff] [blame] | 2205 | ret = count; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2206 | |
| 2207 | exit: |
| 2208 | mutex_unlock(&ar->conf_mutex); |
| 2209 | |
Mohammed Shafi Shajakhan | c28e6f0 | 2016-02-23 12:58:36 +0530 | [diff] [blame] | 2210 | return ret; |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | static ssize_t ath10k_read_btcoex(struct file *file, char __user *ubuf, |
| 2214 | size_t count, loff_t *ppos) |
| 2215 | { |
| 2216 | char buf[32]; |
| 2217 | struct ath10k *ar = file->private_data; |
| 2218 | int len = 0; |
| 2219 | |
| 2220 | mutex_lock(&ar->conf_mutex); |
| 2221 | len = scnprintf(buf, sizeof(buf) - len, "%d\n", |
| 2222 | test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags)); |
| 2223 | mutex_unlock(&ar->conf_mutex); |
| 2224 | |
| 2225 | return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 2226 | } |
| 2227 | |
| 2228 | static const struct file_operations fops_btcoex = { |
| 2229 | .read = ath10k_read_btcoex, |
| 2230 | .write = ath10k_write_btcoex, |
| 2231 | .open = simple_open |
| 2232 | }; |
| 2233 | |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2234 | static ssize_t ath10k_write_peer_stats(struct file *file, |
| 2235 | const char __user *ubuf, |
| 2236 | size_t count, loff_t *ppos) |
| 2237 | { |
| 2238 | struct ath10k *ar = file->private_data; |
| 2239 | char buf[32]; |
| 2240 | size_t buf_size; |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2241 | int ret; |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2242 | bool val; |
| 2243 | |
| 2244 | buf_size = min(count, (sizeof(buf) - 1)); |
| 2245 | if (copy_from_user(buf, ubuf, buf_size)) |
| 2246 | return -EFAULT; |
| 2247 | |
| 2248 | buf[buf_size] = '\0'; |
| 2249 | |
| 2250 | if (strtobool(buf, &val) != 0) |
| 2251 | return -EINVAL; |
| 2252 | |
| 2253 | mutex_lock(&ar->conf_mutex); |
| 2254 | |
| 2255 | if (ar->state != ATH10K_STATE_ON && |
| 2256 | ar->state != ATH10K_STATE_RESTARTED) { |
| 2257 | ret = -ENETDOWN; |
| 2258 | goto exit; |
| 2259 | } |
| 2260 | |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2261 | if (!(test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags) ^ val)) { |
| 2262 | ret = count; |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2263 | goto exit; |
Mohammed Shafi Shajakhan | 87be054 | 2016-04-05 20:58:26 +0530 | [diff] [blame] | 2264 | } |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2265 | |
| 2266 | if (val) |
| 2267 | set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags); |
| 2268 | else |
| 2269 | clear_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags); |
| 2270 | |
| 2271 | ath10k_info(ar, "restarting firmware due to Peer stats change"); |
| 2272 | |
| 2273 | queue_work(ar->workqueue, &ar->restart_work); |
| 2274 | ret = count; |
| 2275 | |
| 2276 | exit: |
| 2277 | mutex_unlock(&ar->conf_mutex); |
| 2278 | return ret; |
| 2279 | } |
| 2280 | |
| 2281 | static ssize_t ath10k_read_peer_stats(struct file *file, char __user *ubuf, |
| 2282 | size_t count, loff_t *ppos) |
| 2283 | |
| 2284 | { |
| 2285 | char buf[32]; |
| 2286 | struct ath10k *ar = file->private_data; |
| 2287 | int len = 0; |
| 2288 | |
| 2289 | mutex_lock(&ar->conf_mutex); |
| 2290 | len = scnprintf(buf, sizeof(buf) - len, "%d\n", |
| 2291 | test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags)); |
| 2292 | mutex_unlock(&ar->conf_mutex); |
| 2293 | |
| 2294 | return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 2295 | } |
| 2296 | |
| 2297 | static const struct file_operations fops_peer_stats = { |
| 2298 | .read = ath10k_read_peer_stats, |
| 2299 | .write = ath10k_write_peer_stats, |
| 2300 | .open = simple_open |
| 2301 | }; |
| 2302 | |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2303 | static ssize_t ath10k_debug_fw_checksums_read(struct file *file, |
| 2304 | char __user *user_buf, |
| 2305 | size_t count, loff_t *ppos) |
| 2306 | { |
| 2307 | struct ath10k *ar = file->private_data; |
| 2308 | unsigned int len = 0, buf_len = 4096; |
| 2309 | ssize_t ret_cnt; |
| 2310 | char *buf; |
| 2311 | |
| 2312 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 2313 | if (!buf) |
| 2314 | return -ENOMEM; |
| 2315 | |
| 2316 | mutex_lock(&ar->conf_mutex); |
| 2317 | |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2318 | len += scnprintf(buf + len, buf_len - len, |
| 2319 | "firmware-N.bin\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2320 | crc32_le(0, ar->normal_mode_fw.fw_file.firmware->data, |
| 2321 | ar->normal_mode_fw.fw_file.firmware->size)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2322 | len += scnprintf(buf + len, buf_len - len, |
| 2323 | "athwlan\t\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2324 | crc32_le(0, ar->normal_mode_fw.fw_file.firmware_data, |
| 2325 | ar->normal_mode_fw.fw_file.firmware_len)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2326 | len += scnprintf(buf + len, buf_len - len, |
| 2327 | "otp\t\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2328 | crc32_le(0, ar->normal_mode_fw.fw_file.otp_data, |
| 2329 | ar->normal_mode_fw.fw_file.otp_len)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2330 | len += scnprintf(buf + len, buf_len - len, |
| 2331 | "codeswap\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2332 | crc32_le(0, ar->normal_mode_fw.fw_file.codeswap_data, |
| 2333 | ar->normal_mode_fw.fw_file.codeswap_len)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2334 | len += scnprintf(buf + len, buf_len - len, |
| 2335 | "board-N.bin\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2336 | crc32_le(0, ar->normal_mode_fw.board->data, |
| 2337 | ar->normal_mode_fw.board->size)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2338 | len += scnprintf(buf + len, buf_len - len, |
| 2339 | "board\t\t\t%08x\n", |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 2340 | crc32_le(0, ar->normal_mode_fw.board_data, |
| 2341 | ar->normal_mode_fw.board_len)); |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2342 | |
| 2343 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 2344 | |
| 2345 | mutex_unlock(&ar->conf_mutex); |
| 2346 | |
| 2347 | kfree(buf); |
| 2348 | return ret_cnt; |
| 2349 | } |
| 2350 | |
| 2351 | static const struct file_operations fops_fw_checksums = { |
| 2352 | .read = ath10k_debug_fw_checksums_read, |
| 2353 | .open = simple_open, |
| 2354 | .owner = THIS_MODULE, |
| 2355 | .llseek = default_llseek, |
| 2356 | }; |
| 2357 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2358 | int ath10k_debug_create(struct ath10k *ar) |
| 2359 | { |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 2360 | ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data)); |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 2361 | if (!ar->debug.fw_crash_data) |
| 2362 | return -ENOMEM; |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 2363 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 2364 | ar->debug.cal_data = vzalloc(ATH10K_DEBUG_CAL_DATA_LEN); |
| 2365 | if (!ar->debug.cal_data) |
| 2366 | return -ENOMEM; |
| 2367 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2368 | INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs); |
Michal Kazior | 7b6b153 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 2369 | INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2370 | INIT_LIST_HEAD(&ar->debug.fw_stats.peers); |
Mohammed Shafi Shajakhan | 4a49ae9 | 2016-06-30 15:23:47 +0300 | [diff] [blame] | 2371 | INIT_LIST_HEAD(&ar->debug.fw_stats.peers_extd); |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2372 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 2373 | return 0; |
| 2374 | } |
| 2375 | |
| 2376 | void ath10k_debug_destroy(struct ath10k *ar) |
| 2377 | { |
| 2378 | vfree(ar->debug.fw_crash_data); |
| 2379 | ar->debug.fw_crash_data = NULL; |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2380 | |
Marty Faltesek | f67b107d | 2016-10-10 19:00:04 +0300 | [diff] [blame] | 2381 | vfree(ar->debug.cal_data); |
| 2382 | ar->debug.cal_data = NULL; |
| 2383 | |
Michal Kazior | 5326849 | 2014-09-25 12:33:50 +0200 | [diff] [blame] | 2384 | ath10k_debug_fw_stats_reset(ar); |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 2385 | |
| 2386 | kfree(ar->debug.tpc_stats); |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | int ath10k_debug_register(struct ath10k *ar) |
| 2390 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2391 | ar->debug.debugfs_phy = debugfs_create_dir("ath10k", |
| 2392 | ar->hw->wiphy->debugfsdir); |
Michal Kazior | adb43b2 | 2014-09-04 12:36:45 +0200 | [diff] [blame] | 2393 | if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) { |
| 2394 | if (IS_ERR(ar->debug.debugfs_phy)) |
| 2395 | return PTR_ERR(ar->debug.debugfs_phy); |
Kalle Valo | d8bb26b | 2014-09-14 12:50:33 +0300 | [diff] [blame] | 2396 | |
| 2397 | return -ENOMEM; |
Michal Kazior | adb43b2 | 2014-09-04 12:36:45 +0200 | [diff] [blame] | 2398 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2399 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 2400 | INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork, |
| 2401 | ath10k_debug_htt_stats_dwork); |
| 2402 | |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 2403 | init_completion(&ar->debug.tpc_complete); |
Michal Kazior | 60ef401 | 2014-09-25 12:33:48 +0200 | [diff] [blame] | 2404 | init_completion(&ar->debug.fw_stats_complete); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2405 | |
| 2406 | debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar, |
| 2407 | &fops_fw_stats); |
| 2408 | |
Ben Greear | f51dbe7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 2409 | debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy, |
| 2410 | ar, &fops_fw_reset_stats); |
| 2411 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2412 | debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar, |
| 2413 | &fops_wmi_services); |
| 2414 | |
Mohammed Shafi Shajakhan | 8bf1ba1 | 2015-11-24 22:26:37 +0530 | [diff] [blame] | 2415 | debugfs_create_file("simulate_fw_crash", S_IRUSR | S_IWUSR, |
| 2416 | ar->debug.debugfs_phy, ar, &fops_simulate_fw_crash); |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 2417 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 2418 | debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy, |
| 2419 | ar, &fops_fw_crash_dump); |
| 2420 | |
Yanbo Li | 077a380 | 2014-11-25 12:24:33 +0200 | [diff] [blame] | 2421 | debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, |
| 2422 | ar->debug.debugfs_phy, ar, &fops_reg_addr); |
| 2423 | |
| 2424 | debugfs_create_file("reg_value", S_IRUSR | S_IWUSR, |
| 2425 | ar->debug.debugfs_phy, ar, &fops_reg_value); |
| 2426 | |
Yanbo Li | 9f65ad2 | 2014-11-25 12:24:48 +0200 | [diff] [blame] | 2427 | debugfs_create_file("mem_value", S_IRUSR | S_IWUSR, |
| 2428 | ar->debug.debugfs_phy, ar, &fops_mem_value); |
| 2429 | |
Kalle Valo | 763b8cd | 2013-09-01 11:22:21 +0300 | [diff] [blame] | 2430 | debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy, |
| 2431 | ar, &fops_chip_id); |
| 2432 | |
Mohammed Shafi Shajakhan | 8bf1ba1 | 2015-11-24 22:26:37 +0530 | [diff] [blame] | 2433 | debugfs_create_file("htt_stats_mask", S_IRUSR | S_IWUSR, |
| 2434 | ar->debug.debugfs_phy, ar, &fops_htt_stats_mask); |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 2435 | |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 2436 | debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR, |
| 2437 | ar->debug.debugfs_phy, ar, |
| 2438 | &fops_htt_max_amsdu_ampdu); |
| 2439 | |
Mohammed Shafi Shajakhan | 8bf1ba1 | 2015-11-24 22:26:37 +0530 | [diff] [blame] | 2440 | debugfs_create_file("fw_dbglog", S_IRUSR | S_IWUSR, |
| 2441 | ar->debug.debugfs_phy, ar, &fops_fw_dbglog); |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 2442 | |
Kalle Valo | 7869b4f | 2014-09-24 14:16:58 +0300 | [diff] [blame] | 2443 | debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy, |
| 2444 | ar, &fops_cal_data); |
| 2445 | |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 2446 | debugfs_create_file("ani_enable", S_IRUSR | S_IWUSR, |
| 2447 | ar->debug.debugfs_phy, ar, &fops_ani_enable); |
| 2448 | |
Peter Oh | a7bd3e9 | 2014-12-02 13:07:14 +0200 | [diff] [blame] | 2449 | debugfs_create_file("nf_cal_period", S_IRUSR | S_IWUSR, |
| 2450 | ar->debug.debugfs_phy, ar, &fops_nf_cal_period); |
| 2451 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 2452 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) { |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2453 | debugfs_create_file("dfs_simulate_radar", S_IWUSR, |
| 2454 | ar->debug.debugfs_phy, ar, |
| 2455 | &fops_simulate_radar); |
| 2456 | |
Marek Puzyniak | 7d9b40b | 2013-11-20 10:00:28 +0200 | [diff] [blame] | 2457 | debugfs_create_bool("dfs_block_radar_events", S_IWUSR, |
| 2458 | ar->debug.debugfs_phy, |
| 2459 | &ar->dfs_block_radar_events); |
| 2460 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2461 | debugfs_create_file("dfs_stats", S_IRUSR, |
| 2462 | ar->debug.debugfs_phy, ar, |
| 2463 | &fops_dfs_stats); |
| 2464 | } |
| 2465 | |
Rajkumar Manoharan | 9017445 | 2014-10-03 08:02:33 +0300 | [diff] [blame] | 2466 | debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR, |
| 2467 | ar->debug.debugfs_phy, ar, &fops_pktlog_filter); |
| 2468 | |
Rajkumar Manoharan | 63fb32d | 2015-03-15 20:36:20 +0530 | [diff] [blame] | 2469 | debugfs_create_file("quiet_period", S_IRUGO | S_IWUSR, |
| 2470 | ar->debug.debugfs_phy, ar, &fops_quiet_period); |
| 2471 | |
Maharaja Kennadyrajan | 2954266 | 2015-10-05 17:56:38 +0300 | [diff] [blame] | 2472 | debugfs_create_file("tpc_stats", S_IRUSR, |
| 2473 | ar->debug.debugfs_phy, ar, &fops_tpc_stats); |
| 2474 | |
Yanbo Li | 844fa57 | 2015-10-31 11:07:21 +0200 | [diff] [blame] | 2475 | if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map)) |
| 2476 | debugfs_create_file("btcoex", S_IRUGO | S_IWUSR, |
| 2477 | ar->debug.debugfs_phy, ar, &fops_btcoex); |
| 2478 | |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 2479 | if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map)) |
| 2480 | debugfs_create_file("peer_stats", S_IRUGO | S_IWUSR, |
| 2481 | ar->debug.debugfs_phy, ar, |
| 2482 | &fops_peer_stats); |
| 2483 | |
Kalle Valo | 9e100c4 | 2015-11-25 15:38:41 +0200 | [diff] [blame] | 2484 | debugfs_create_file("fw_checksums", S_IRUSR, |
| 2485 | ar->debug.debugfs_phy, ar, &fops_fw_checksums); |
| 2486 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2487 | return 0; |
| 2488 | } |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 2489 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 2490 | void ath10k_debug_unregister(struct ath10k *ar) |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 2491 | { |
| 2492 | cancel_delayed_work_sync(&ar->debug.htt_stats_dwork); |
| 2493 | } |
| 2494 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2495 | #endif /* CONFIG_ATH10K_DEBUGFS */ |
| 2496 | |
| 2497 | #ifdef CONFIG_ATH10K_DEBUG |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2498 | void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask, |
| 2499 | const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2500 | { |
| 2501 | struct va_format vaf; |
| 2502 | va_list args; |
| 2503 | |
| 2504 | va_start(args, fmt); |
| 2505 | |
| 2506 | vaf.fmt = fmt; |
| 2507 | vaf.va = &args; |
| 2508 | |
| 2509 | if (ath10k_debug_mask & mask) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2510 | dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2511 | |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 2512 | trace_ath10k_log_dbg(ar, mask, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2513 | |
| 2514 | va_end(args); |
| 2515 | } |
| 2516 | EXPORT_SYMBOL(ath10k_dbg); |
| 2517 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2518 | void ath10k_dbg_dump(struct ath10k *ar, |
| 2519 | enum ath10k_debug_mask mask, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2520 | const char *msg, const char *prefix, |
| 2521 | const void *buf, size_t len) |
| 2522 | { |
Michal Kazior | 45724a8 | 2014-09-23 10:22:53 +0200 | [diff] [blame] | 2523 | char linebuf[256]; |
| 2524 | unsigned int linebuflen; |
| 2525 | const void *ptr; |
| 2526 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2527 | if (ath10k_debug_mask & mask) { |
| 2528 | if (msg) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2529 | ath10k_dbg(ar, mask, "%s\n", msg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2530 | |
Michal Kazior | 45724a8 | 2014-09-23 10:22:53 +0200 | [diff] [blame] | 2531 | for (ptr = buf; (ptr - buf) < len; ptr += 16) { |
| 2532 | linebuflen = 0; |
| 2533 | linebuflen += scnprintf(linebuf + linebuflen, |
| 2534 | sizeof(linebuf) - linebuflen, |
| 2535 | "%s%08x: ", |
| 2536 | (prefix ? prefix : ""), |
| 2537 | (unsigned int)(ptr - buf)); |
| 2538 | hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1, |
| 2539 | linebuf + linebuflen, |
| 2540 | sizeof(linebuf) - linebuflen, true); |
| 2541 | dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf); |
| 2542 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | /* tracing code doesn't like null strings :/ */ |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 2546 | trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2547 | buf, len); |
| 2548 | } |
| 2549 | EXPORT_SYMBOL(ath10k_dbg_dump); |
| 2550 | |
| 2551 | #endif /* CONFIG_ATH10K_DEBUG */ |