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