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/version.h> |
| 21 | #include <linux/vermagic.h> |
| 22 | #include <linux/vmalloc.h> |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 23 | |
| 24 | #include "core.h" |
| 25 | #include "debug.h" |
| 26 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 27 | /* ms */ |
| 28 | #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000 |
| 29 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 30 | #define ATH10K_FW_CRASH_DUMP_VERSION 1 |
| 31 | |
| 32 | /** |
| 33 | * enum ath10k_fw_crash_dump_type - types of data in the dump file |
| 34 | * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format |
| 35 | */ |
| 36 | enum ath10k_fw_crash_dump_type { |
| 37 | ATH10K_FW_CRASH_DUMP_REGISTERS = 0, |
| 38 | |
| 39 | ATH10K_FW_CRASH_DUMP_MAX, |
| 40 | }; |
| 41 | |
| 42 | struct ath10k_tlv_dump_data { |
| 43 | /* see ath10k_fw_crash_dump_type above */ |
| 44 | __le32 type; |
| 45 | |
| 46 | /* in bytes */ |
| 47 | __le32 tlv_len; |
| 48 | |
| 49 | /* pad to 32-bit boundaries as needed */ |
| 50 | u8 tlv_data[]; |
| 51 | } __packed; |
| 52 | |
| 53 | struct ath10k_dump_file_data { |
| 54 | /* dump file information */ |
| 55 | |
| 56 | /* "ATH10K-FW-DUMP" */ |
| 57 | char df_magic[16]; |
| 58 | |
| 59 | __le32 len; |
| 60 | |
| 61 | /* file dump version */ |
| 62 | __le32 version; |
| 63 | |
| 64 | /* some info we can get from ath10k struct that might help */ |
| 65 | |
| 66 | u8 uuid[16]; |
| 67 | |
| 68 | __le32 chip_id; |
| 69 | |
| 70 | /* 0 for now, in place for later hardware */ |
| 71 | __le32 bus_type; |
| 72 | |
| 73 | __le32 target_version; |
| 74 | __le32 fw_version_major; |
| 75 | __le32 fw_version_minor; |
| 76 | __le32 fw_version_release; |
| 77 | __le32 fw_version_build; |
| 78 | __le32 phy_capability; |
| 79 | __le32 hw_min_tx_power; |
| 80 | __le32 hw_max_tx_power; |
| 81 | __le32 ht_cap_info; |
| 82 | __le32 vht_cap_info; |
| 83 | __le32 num_rf_chains; |
| 84 | |
| 85 | /* firmware version string */ |
| 86 | char fw_ver[ETHTOOL_FWVERS_LEN]; |
| 87 | |
| 88 | /* Kernel related information */ |
| 89 | |
| 90 | /* time-of-day stamp */ |
| 91 | __le64 tv_sec; |
| 92 | |
| 93 | /* time-of-day stamp, nano-seconds */ |
| 94 | __le64 tv_nsec; |
| 95 | |
| 96 | /* LINUX_VERSION_CODE */ |
| 97 | __le32 kernel_ver_code; |
| 98 | |
| 99 | /* VERMAGIC_STRING */ |
| 100 | char kernel_ver[64]; |
| 101 | |
| 102 | /* room for growth w/out changing binary format */ |
| 103 | u8 unused[128]; |
| 104 | |
| 105 | /* struct ath10k_tlv_dump_data + more */ |
| 106 | u8 data[0]; |
| 107 | } __packed; |
| 108 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 109 | int ath10k_info(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 110 | { |
| 111 | struct va_format vaf = { |
| 112 | .fmt = fmt, |
| 113 | }; |
| 114 | va_list args; |
| 115 | int ret; |
| 116 | |
| 117 | va_start(args, fmt); |
| 118 | vaf.va = &args; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 119 | ret = dev_info(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 120 | trace_ath10k_log_info(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 121 | va_end(args); |
| 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | EXPORT_SYMBOL(ath10k_info); |
| 126 | |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 127 | void ath10k_print_driver_info(struct ath10k *ar) |
| 128 | { |
Michal Kazior | 34b28b6 | 2014-09-23 10:22:52 +0200 | [diff] [blame] | 129 | ath10k_info(ar, "%s (0x%08x, 0x%08x) fw %s api %d htt %d.%d wmi %d.%d.%d.%d\n", |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 130 | ar->hw_params.name, |
| 131 | ar->target_version, |
| 132 | ar->chip_id, |
| 133 | ar->hw->wiphy->fw_version, |
| 134 | ar->fw_api, |
| 135 | ar->htt.target_version_major, |
Michal Kazior | 34b28b6 | 2014-09-23 10:22:52 +0200 | [diff] [blame] | 136 | ar->htt.target_version_minor, |
| 137 | ar->fw_version_major, |
| 138 | ar->fw_version_minor, |
| 139 | ar->fw_version_release, |
| 140 | ar->fw_version_build); |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 141 | ath10k_info(ar, "debug %d debugfs %d tracing %d dfs %d testmode %d\n", |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 142 | config_enabled(CONFIG_ATH10K_DEBUG), |
| 143 | config_enabled(CONFIG_ATH10K_DEBUGFS), |
| 144 | config_enabled(CONFIG_ATH10K_TRACING), |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 145 | config_enabled(CONFIG_ATH10K_DFS_CERTIFIED), |
| 146 | config_enabled(CONFIG_NL80211_TESTMODE)); |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 147 | } |
| 148 | EXPORT_SYMBOL(ath10k_print_driver_info); |
| 149 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 150 | int ath10k_err(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 151 | { |
| 152 | struct va_format vaf = { |
| 153 | .fmt = fmt, |
| 154 | }; |
| 155 | va_list args; |
| 156 | int ret; |
| 157 | |
| 158 | va_start(args, fmt); |
| 159 | vaf.va = &args; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 160 | ret = dev_err(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 161 | trace_ath10k_log_err(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 162 | va_end(args); |
| 163 | |
| 164 | return ret; |
| 165 | } |
| 166 | EXPORT_SYMBOL(ath10k_err); |
| 167 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 168 | int ath10k_warn(struct ath10k *ar, const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 169 | { |
| 170 | struct va_format vaf = { |
| 171 | .fmt = fmt, |
| 172 | }; |
| 173 | va_list args; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 174 | |
| 175 | va_start(args, fmt); |
| 176 | vaf.va = &args; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 177 | dev_warn_ratelimited(ar->dev, "%pV", &vaf); |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 178 | trace_ath10k_log_warn(ar, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 179 | |
| 180 | va_end(args); |
| 181 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 182 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 183 | } |
| 184 | EXPORT_SYMBOL(ath10k_warn); |
| 185 | |
| 186 | #ifdef CONFIG_ATH10K_DEBUGFS |
| 187 | |
| 188 | void ath10k_debug_read_service_map(struct ath10k *ar, |
Michal Kazior | 5c01aa3d | 2014-09-18 15:21:24 +0200 | [diff] [blame] | 189 | const void *service_map, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 190 | size_t map_size) |
| 191 | { |
| 192 | memcpy(ar->debug.wmi_service_bitmap, service_map, map_size); |
| 193 | } |
| 194 | |
| 195 | static ssize_t ath10k_read_wmi_services(struct file *file, |
| 196 | char __user *user_buf, |
| 197 | size_t count, loff_t *ppos) |
| 198 | { |
| 199 | struct ath10k *ar = file->private_data; |
| 200 | char *buf; |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 201 | unsigned int len = 0, buf_len = 4096; |
| 202 | const char *name; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 203 | ssize_t ret_cnt; |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 204 | bool enabled; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 205 | int i; |
| 206 | |
| 207 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 208 | if (!buf) |
| 209 | return -ENOMEM; |
| 210 | |
| 211 | mutex_lock(&ar->conf_mutex); |
| 212 | |
| 213 | if (len > buf_len) |
| 214 | len = buf_len; |
| 215 | |
Michal Kazior | c4f8c83 | 2014-09-04 10:18:32 +0200 | [diff] [blame] | 216 | for (i = 0; i < WMI_SERVICE_MAX; i++) { |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 217 | enabled = test_bit(i, ar->debug.wmi_service_bitmap); |
| 218 | name = wmi_service_name(i); |
| 219 | |
| 220 | if (!name) { |
| 221 | if (enabled) |
| 222 | len += scnprintf(buf + len, buf_len - len, |
| 223 | "%-40s %s (bit %d)\n", |
| 224 | "unknown", "enabled", i); |
| 225 | |
| 226 | continue; |
| 227 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 228 | |
| 229 | len += scnprintf(buf + len, buf_len - len, |
Michal Kazior | cff990c | 2014-08-04 09:18:33 +0300 | [diff] [blame] | 230 | "%-40s %s\n", |
| 231 | name, enabled ? "enabled" : "-"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 235 | |
| 236 | mutex_unlock(&ar->conf_mutex); |
| 237 | |
| 238 | kfree(buf); |
| 239 | return ret_cnt; |
| 240 | } |
| 241 | |
| 242 | static const struct file_operations fops_wmi_services = { |
| 243 | .read = ath10k_read_wmi_services, |
| 244 | .open = simple_open, |
| 245 | .owner = THIS_MODULE, |
| 246 | .llseek = default_llseek, |
| 247 | }; |
| 248 | |
| 249 | void ath10k_debug_read_target_stats(struct ath10k *ar, |
| 250 | struct wmi_stats_event *ev) |
| 251 | { |
| 252 | u8 *tmp = ev->data; |
| 253 | struct ath10k_target_stats *stats; |
| 254 | int num_pdev_stats, num_vdev_stats, num_peer_stats; |
Chun-Yeow Yeoh | 52e346d | 2014-03-28 14:35:16 +0200 | [diff] [blame] | 255 | struct wmi_pdev_stats_10x *ps; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 256 | int i; |
| 257 | |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 258 | spin_lock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 259 | |
| 260 | stats = &ar->debug.target_stats; |
| 261 | |
| 262 | num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats); /* 0 or 1 */ |
| 263 | num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats); /* 0 or max vdevs */ |
| 264 | num_peer_stats = __le32_to_cpu(ev->num_peer_stats); /* 0 or max peers */ |
| 265 | |
| 266 | if (num_pdev_stats) { |
Chun-Yeow Yeoh | 52e346d | 2014-03-28 14:35:16 +0200 | [diff] [blame] | 267 | ps = (struct wmi_pdev_stats_10x *)tmp; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 268 | |
| 269 | stats->ch_noise_floor = __le32_to_cpu(ps->chan_nf); |
| 270 | stats->tx_frame_count = __le32_to_cpu(ps->tx_frame_count); |
| 271 | stats->rx_frame_count = __le32_to_cpu(ps->rx_frame_count); |
| 272 | stats->rx_clear_count = __le32_to_cpu(ps->rx_clear_count); |
| 273 | stats->cycle_count = __le32_to_cpu(ps->cycle_count); |
| 274 | stats->phy_err_count = __le32_to_cpu(ps->phy_err_count); |
| 275 | stats->chan_tx_power = __le32_to_cpu(ps->chan_tx_pwr); |
| 276 | |
| 277 | stats->comp_queued = __le32_to_cpu(ps->wal.tx.comp_queued); |
| 278 | stats->comp_delivered = |
| 279 | __le32_to_cpu(ps->wal.tx.comp_delivered); |
| 280 | stats->msdu_enqued = __le32_to_cpu(ps->wal.tx.msdu_enqued); |
| 281 | stats->mpdu_enqued = __le32_to_cpu(ps->wal.tx.mpdu_enqued); |
| 282 | stats->wmm_drop = __le32_to_cpu(ps->wal.tx.wmm_drop); |
| 283 | stats->local_enqued = __le32_to_cpu(ps->wal.tx.local_enqued); |
| 284 | stats->local_freed = __le32_to_cpu(ps->wal.tx.local_freed); |
| 285 | stats->hw_queued = __le32_to_cpu(ps->wal.tx.hw_queued); |
| 286 | stats->hw_reaped = __le32_to_cpu(ps->wal.tx.hw_reaped); |
| 287 | stats->underrun = __le32_to_cpu(ps->wal.tx.underrun); |
| 288 | stats->tx_abort = __le32_to_cpu(ps->wal.tx.tx_abort); |
| 289 | stats->mpdus_requed = __le32_to_cpu(ps->wal.tx.mpdus_requed); |
| 290 | stats->tx_ko = __le32_to_cpu(ps->wal.tx.tx_ko); |
| 291 | stats->data_rc = __le32_to_cpu(ps->wal.tx.data_rc); |
| 292 | stats->self_triggers = __le32_to_cpu(ps->wal.tx.self_triggers); |
| 293 | stats->sw_retry_failure = |
| 294 | __le32_to_cpu(ps->wal.tx.sw_retry_failure); |
| 295 | stats->illgl_rate_phy_err = |
| 296 | __le32_to_cpu(ps->wal.tx.illgl_rate_phy_err); |
| 297 | stats->pdev_cont_xretry = |
| 298 | __le32_to_cpu(ps->wal.tx.pdev_cont_xretry); |
| 299 | stats->pdev_tx_timeout = |
| 300 | __le32_to_cpu(ps->wal.tx.pdev_tx_timeout); |
| 301 | stats->pdev_resets = __le32_to_cpu(ps->wal.tx.pdev_resets); |
| 302 | stats->phy_underrun = __le32_to_cpu(ps->wal.tx.phy_underrun); |
| 303 | stats->txop_ovf = __le32_to_cpu(ps->wal.tx.txop_ovf); |
| 304 | |
| 305 | stats->mid_ppdu_route_change = |
| 306 | __le32_to_cpu(ps->wal.rx.mid_ppdu_route_change); |
| 307 | stats->status_rcvd = __le32_to_cpu(ps->wal.rx.status_rcvd); |
| 308 | stats->r0_frags = __le32_to_cpu(ps->wal.rx.r0_frags); |
| 309 | stats->r1_frags = __le32_to_cpu(ps->wal.rx.r1_frags); |
| 310 | stats->r2_frags = __le32_to_cpu(ps->wal.rx.r2_frags); |
| 311 | stats->r3_frags = __le32_to_cpu(ps->wal.rx.r3_frags); |
| 312 | stats->htt_msdus = __le32_to_cpu(ps->wal.rx.htt_msdus); |
| 313 | stats->htt_mpdus = __le32_to_cpu(ps->wal.rx.htt_mpdus); |
| 314 | stats->loc_msdus = __le32_to_cpu(ps->wal.rx.loc_msdus); |
| 315 | stats->loc_mpdus = __le32_to_cpu(ps->wal.rx.loc_mpdus); |
| 316 | stats->oversize_amsdu = |
| 317 | __le32_to_cpu(ps->wal.rx.oversize_amsdu); |
| 318 | stats->phy_errs = __le32_to_cpu(ps->wal.rx.phy_errs); |
| 319 | stats->phy_err_drop = __le32_to_cpu(ps->wal.rx.phy_err_drop); |
| 320 | stats->mpdu_errs = __le32_to_cpu(ps->wal.rx.mpdu_errs); |
| 321 | |
Chun-Yeow Yeoh | 52e346d | 2014-03-28 14:35:16 +0200 | [diff] [blame] | 322 | if (test_bit(ATH10K_FW_FEATURE_WMI_10X, |
| 323 | ar->fw_features)) { |
| 324 | stats->ack_rx_bad = __le32_to_cpu(ps->ack_rx_bad); |
| 325 | stats->rts_bad = __le32_to_cpu(ps->rts_bad); |
| 326 | stats->rts_good = __le32_to_cpu(ps->rts_good); |
| 327 | stats->fcs_bad = __le32_to_cpu(ps->fcs_bad); |
| 328 | stats->no_beacons = __le32_to_cpu(ps->no_beacons); |
| 329 | stats->mib_int_count = __le32_to_cpu(ps->mib_int_count); |
| 330 | tmp += sizeof(struct wmi_pdev_stats_10x); |
| 331 | } else { |
| 332 | tmp += sizeof(struct wmi_pdev_stats_old); |
| 333 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /* 0 or max vdevs */ |
| 337 | /* Currently firmware does not support VDEV stats */ |
| 338 | if (num_vdev_stats) { |
| 339 | struct wmi_vdev_stats *vdev_stats; |
| 340 | |
| 341 | for (i = 0; i < num_vdev_stats; i++) { |
| 342 | vdev_stats = (struct wmi_vdev_stats *)tmp; |
| 343 | tmp += sizeof(struct wmi_vdev_stats); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | if (num_peer_stats) { |
Ben Greear | 23c3aae | 2014-03-28 14:35:15 +0200 | [diff] [blame] | 348 | struct wmi_peer_stats_10x *peer_stats; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 349 | struct ath10k_peer_stat *s; |
| 350 | |
| 351 | stats->peers = num_peer_stats; |
| 352 | |
| 353 | for (i = 0; i < num_peer_stats; i++) { |
Ben Greear | 23c3aae | 2014-03-28 14:35:15 +0200 | [diff] [blame] | 354 | peer_stats = (struct wmi_peer_stats_10x *)tmp; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 355 | s = &stats->peer_stat[i]; |
| 356 | |
Chun-Yeow Yeoh | cf0fd56 | 2014-03-21 17:46:58 +0200 | [diff] [blame] | 357 | memcpy(s->peer_macaddr, &peer_stats->peer_macaddr.addr, |
| 358 | ETH_ALEN); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 359 | s->peer_rssi = __le32_to_cpu(peer_stats->peer_rssi); |
| 360 | s->peer_tx_rate = |
| 361 | __le32_to_cpu(peer_stats->peer_tx_rate); |
Ben Greear | 23c3aae | 2014-03-28 14:35:15 +0200 | [diff] [blame] | 362 | if (test_bit(ATH10K_FW_FEATURE_WMI_10X, |
| 363 | ar->fw_features)) { |
| 364 | s->peer_rx_rate = |
| 365 | __le32_to_cpu(peer_stats->peer_rx_rate); |
| 366 | tmp += sizeof(struct wmi_peer_stats_10x); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 367 | |
Ben Greear | 23c3aae | 2014-03-28 14:35:15 +0200 | [diff] [blame] | 368 | } else { |
| 369 | tmp += sizeof(struct wmi_peer_stats_old); |
| 370 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 374 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 375 | complete(&ar->debug.event_stats_compl); |
| 376 | } |
| 377 | |
| 378 | static ssize_t ath10k_read_fw_stats(struct file *file, char __user *user_buf, |
| 379 | size_t count, loff_t *ppos) |
| 380 | { |
| 381 | struct ath10k *ar = file->private_data; |
| 382 | struct ath10k_target_stats *fw_stats; |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 383 | char *buf = NULL; |
Ben Greear | 23c3aae | 2014-03-28 14:35:15 +0200 | [diff] [blame] | 384 | unsigned int len = 0, buf_len = 8000; |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 385 | ssize_t ret_cnt = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 386 | long left; |
| 387 | int i; |
| 388 | int ret; |
| 389 | |
| 390 | fw_stats = &ar->debug.target_stats; |
| 391 | |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 392 | mutex_lock(&ar->conf_mutex); |
| 393 | |
| 394 | if (ar->state != ATH10K_STATE_ON) |
| 395 | goto exit; |
| 396 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 397 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 398 | if (!buf) |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 399 | goto exit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 400 | |
| 401 | ret = ath10k_wmi_request_stats(ar, WMI_REQUEST_PEER_STAT); |
| 402 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 403 | ath10k_warn(ar, "could not request stats (%d)\n", ret); |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 404 | goto exit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | left = wait_for_completion_timeout(&ar->debug.event_stats_compl, 1*HZ); |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 408 | if (left <= 0) |
| 409 | goto exit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 410 | |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 411 | spin_lock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 412 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 413 | len += scnprintf(buf + len, buf_len - len, "%30s\n", |
| 414 | "ath10k PDEV stats"); |
| 415 | len += scnprintf(buf + len, buf_len - len, "%30s\n\n", |
| 416 | "================="); |
| 417 | |
| 418 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 419 | "Channel noise floor", fw_stats->ch_noise_floor); |
| 420 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 421 | "Channel TX power", fw_stats->chan_tx_power); |
| 422 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 423 | "TX frame count", fw_stats->tx_frame_count); |
| 424 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 425 | "RX frame count", fw_stats->rx_frame_count); |
| 426 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 427 | "RX clear count", fw_stats->rx_clear_count); |
| 428 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 429 | "Cycle count", fw_stats->cycle_count); |
| 430 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 431 | "PHY error count", fw_stats->phy_err_count); |
Chun-Yeow Yeoh | 52e346d | 2014-03-28 14:35:16 +0200 | [diff] [blame] | 432 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 433 | "RTS bad count", fw_stats->rts_bad); |
| 434 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 435 | "RTS good count", fw_stats->rts_good); |
| 436 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 437 | "FCS bad count", fw_stats->fcs_bad); |
| 438 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 439 | "No beacon count", fw_stats->no_beacons); |
| 440 | len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", |
| 441 | "MIB int count", fw_stats->mib_int_count); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 442 | |
| 443 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 444 | len += scnprintf(buf + len, buf_len - len, "%30s\n", |
| 445 | "ath10k PDEV TX stats"); |
| 446 | len += scnprintf(buf + len, buf_len - len, "%30s\n\n", |
| 447 | "================="); |
| 448 | |
| 449 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 450 | "HTT cookies queued", fw_stats->comp_queued); |
| 451 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 452 | "HTT cookies disp.", fw_stats->comp_delivered); |
| 453 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 454 | "MSDU queued", fw_stats->msdu_enqued); |
| 455 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 456 | "MPDU queued", fw_stats->mpdu_enqued); |
| 457 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 458 | "MSDUs dropped", fw_stats->wmm_drop); |
| 459 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 460 | "Local enqued", fw_stats->local_enqued); |
| 461 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 462 | "Local freed", fw_stats->local_freed); |
| 463 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 464 | "HW queued", fw_stats->hw_queued); |
| 465 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 466 | "PPDUs reaped", fw_stats->hw_reaped); |
| 467 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 468 | "Num underruns", fw_stats->underrun); |
| 469 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 470 | "PPDUs cleaned", fw_stats->tx_abort); |
| 471 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 472 | "MPDUs requed", fw_stats->mpdus_requed); |
| 473 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 474 | "Excessive retries", fw_stats->tx_ko); |
| 475 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 476 | "HW rate", fw_stats->data_rc); |
| 477 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 478 | "Sched self tiggers", fw_stats->self_triggers); |
| 479 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 480 | "Dropped due to SW retries", |
| 481 | fw_stats->sw_retry_failure); |
| 482 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 483 | "Illegal rate phy errors", |
| 484 | fw_stats->illgl_rate_phy_err); |
| 485 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 486 | "Pdev continous xretry", fw_stats->pdev_cont_xretry); |
| 487 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 488 | "TX timeout", fw_stats->pdev_tx_timeout); |
| 489 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 490 | "PDEV resets", fw_stats->pdev_resets); |
| 491 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 492 | "PHY underrun", fw_stats->phy_underrun); |
| 493 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 494 | "MPDU is more than txop limit", fw_stats->txop_ovf); |
| 495 | |
| 496 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 497 | len += scnprintf(buf + len, buf_len - len, "%30s\n", |
| 498 | "ath10k PDEV RX stats"); |
| 499 | len += scnprintf(buf + len, buf_len - len, "%30s\n\n", |
| 500 | "================="); |
| 501 | |
| 502 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 503 | "Mid PPDU route change", |
| 504 | fw_stats->mid_ppdu_route_change); |
| 505 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 506 | "Tot. number of statuses", fw_stats->status_rcvd); |
| 507 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 508 | "Extra frags on rings 0", fw_stats->r0_frags); |
| 509 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 510 | "Extra frags on rings 1", fw_stats->r1_frags); |
| 511 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 512 | "Extra frags on rings 2", fw_stats->r2_frags); |
| 513 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 514 | "Extra frags on rings 3", fw_stats->r3_frags); |
| 515 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 516 | "MSDUs delivered to HTT", fw_stats->htt_msdus); |
| 517 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 518 | "MPDUs delivered to HTT", fw_stats->htt_mpdus); |
| 519 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 520 | "MSDUs delivered to stack", fw_stats->loc_msdus); |
| 521 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 522 | "MPDUs delivered to stack", fw_stats->loc_mpdus); |
| 523 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 524 | "Oversized AMSUs", fw_stats->oversize_amsdu); |
| 525 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 526 | "PHY errors", fw_stats->phy_errs); |
| 527 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 528 | "PHY errors drops", fw_stats->phy_err_drop); |
| 529 | len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", |
| 530 | "MPDU errors (FCS, MIC, ENC)", fw_stats->mpdu_errs); |
| 531 | |
| 532 | len += scnprintf(buf + len, buf_len - len, "\n"); |
Ben Greear | 23c3aae | 2014-03-28 14:35:15 +0200 | [diff] [blame] | 533 | len += scnprintf(buf + len, buf_len - len, "%30s (%d)\n", |
| 534 | "ath10k PEER stats", fw_stats->peers); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 535 | len += scnprintf(buf + len, buf_len - len, "%30s\n\n", |
| 536 | "================="); |
| 537 | |
| 538 | for (i = 0; i < fw_stats->peers; i++) { |
| 539 | len += scnprintf(buf + len, buf_len - len, "%30s %pM\n", |
| 540 | "Peer MAC address", |
| 541 | fw_stats->peer_stat[i].peer_macaddr); |
| 542 | len += scnprintf(buf + len, buf_len - len, "%30s %u\n", |
| 543 | "Peer RSSI", fw_stats->peer_stat[i].peer_rssi); |
| 544 | len += scnprintf(buf + len, buf_len - len, "%30s %u\n", |
| 545 | "Peer TX rate", |
| 546 | fw_stats->peer_stat[i].peer_tx_rate); |
Ben Greear | 23c3aae | 2014-03-28 14:35:15 +0200 | [diff] [blame] | 547 | len += scnprintf(buf + len, buf_len - len, "%30s %u\n", |
| 548 | "Peer RX rate", |
| 549 | fw_stats->peer_stat[i].peer_rx_rate); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 550 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 551 | } |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 552 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 553 | |
| 554 | if (len > buf_len) |
| 555 | len = buf_len; |
| 556 | |
| 557 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 558 | |
Michal Kazior | 87571bf | 2013-07-16 09:38:59 +0200 | [diff] [blame] | 559 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 560 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 561 | kfree(buf); |
| 562 | return ret_cnt; |
| 563 | } |
| 564 | |
| 565 | static const struct file_operations fops_fw_stats = { |
| 566 | .read = ath10k_read_fw_stats, |
| 567 | .open = simple_open, |
| 568 | .owner = THIS_MODULE, |
| 569 | .llseek = default_llseek, |
| 570 | }; |
| 571 | |
Ben Greear | d5aebc7 | 2014-09-10 18:59:28 +0300 | [diff] [blame] | 572 | /* This is a clean assert crash in firmware. */ |
| 573 | static int ath10k_debug_fw_assert(struct ath10k *ar) |
| 574 | { |
| 575 | struct wmi_vdev_install_key_cmd *cmd; |
| 576 | struct sk_buff *skb; |
| 577 | |
| 578 | skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16); |
| 579 | if (!skb) |
| 580 | return -ENOMEM; |
| 581 | |
| 582 | cmd = (struct wmi_vdev_install_key_cmd *)skb->data; |
| 583 | memset(cmd, 0, sizeof(*cmd)); |
| 584 | |
| 585 | /* big enough number so that firmware asserts */ |
| 586 | cmd->vdev_id = __cpu_to_le32(0x7ffe); |
| 587 | |
| 588 | return ath10k_wmi_cmd_send(ar, skb, |
| 589 | ar->wmi.cmd->vdev_install_key_cmdid); |
| 590 | } |
| 591 | |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 592 | static ssize_t ath10k_read_simulate_fw_crash(struct file *file, |
| 593 | char __user *user_buf, |
| 594 | size_t count, loff_t *ppos) |
| 595 | { |
Kalle Valo | 75cb96d | 2014-09-14 12:50:44 +0300 | [diff] [blame] | 596 | const char buf[] = |
| 597 | "To simulate firmware crash write one of the keywords to this file:\n" |
| 598 | "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n" |
| 599 | "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n" |
| 600 | "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"; |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 601 | |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 602 | return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); |
| 603 | } |
| 604 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 605 | /* Simulate firmware crash: |
| 606 | * 'soft': Call wmi command causing firmware hang. This firmware hang is |
| 607 | * recoverable by warm firmware reset. |
| 608 | * 'hard': Force firmware crash by setting any vdev parameter for not allowed |
| 609 | * vdev id. This is hard firmware crash because it is recoverable only by cold |
| 610 | * firmware reset. |
| 611 | */ |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 612 | static ssize_t ath10k_write_simulate_fw_crash(struct file *file, |
| 613 | const char __user *user_buf, |
| 614 | size_t count, loff_t *ppos) |
| 615 | { |
| 616 | struct ath10k *ar = file->private_data; |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 617 | char buf[32]; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 618 | int ret; |
| 619 | |
| 620 | mutex_lock(&ar->conf_mutex); |
| 621 | |
| 622 | simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 623 | |
| 624 | /* make sure that buf is null terminated */ |
| 625 | buf[sizeof(buf) - 1] = 0; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 626 | |
| 627 | if (ar->state != ATH10K_STATE_ON && |
| 628 | ar->state != ATH10K_STATE_RESTARTED) { |
| 629 | ret = -ENETDOWN; |
| 630 | goto exit; |
| 631 | } |
| 632 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 633 | /* drop the possible '\n' from the end */ |
| 634 | if (buf[count - 1] == '\n') { |
| 635 | buf[count - 1] = 0; |
| 636 | count--; |
| 637 | } |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 638 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 639 | if (!strcmp(buf, "soft")) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 640 | ath10k_info(ar, "simulating soft firmware crash\n"); |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 641 | ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0); |
| 642 | } else if (!strcmp(buf, "hard")) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 643 | ath10k_info(ar, "simulating hard firmware crash\n"); |
Ben Greear | 611b368 | 2014-07-25 11:56:40 +0300 | [diff] [blame] | 644 | /* 0x7fff is vdev id, and it is always out of range for all |
| 645 | * firmware variants in order to force a firmware crash. |
| 646 | */ |
| 647 | ret = ath10k_wmi_vdev_set_param(ar, 0x7fff, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 648 | ar->wmi.vdev_param->rts_threshold, |
| 649 | 0); |
Ben Greear | d5aebc7 | 2014-09-10 18:59:28 +0300 | [diff] [blame] | 650 | } else if (!strcmp(buf, "assert")) { |
| 651 | ath10k_info(ar, "simulating firmware assert crash\n"); |
| 652 | ret = ath10k_debug_fw_assert(ar); |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 653 | } else { |
| 654 | ret = -EINVAL; |
| 655 | goto exit; |
| 656 | } |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 657 | |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 658 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 659 | ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret); |
Marek Puzyniak | 8c65699 | 2014-03-21 17:46:56 +0200 | [diff] [blame] | 660 | goto exit; |
| 661 | } |
| 662 | |
| 663 | ret = count; |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 664 | |
| 665 | exit: |
| 666 | mutex_unlock(&ar->conf_mutex); |
| 667 | return ret; |
| 668 | } |
| 669 | |
| 670 | static const struct file_operations fops_simulate_fw_crash = { |
| 671 | .read = ath10k_read_simulate_fw_crash, |
| 672 | .write = ath10k_write_simulate_fw_crash, |
| 673 | .open = simple_open, |
| 674 | .owner = THIS_MODULE, |
| 675 | .llseek = default_llseek, |
| 676 | }; |
| 677 | |
Kalle Valo | 763b8cd | 2013-09-01 11:22:21 +0300 | [diff] [blame] | 678 | static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf, |
| 679 | size_t count, loff_t *ppos) |
| 680 | { |
| 681 | struct ath10k *ar = file->private_data; |
| 682 | unsigned int len; |
| 683 | char buf[50]; |
| 684 | |
| 685 | len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id); |
| 686 | |
| 687 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 688 | } |
| 689 | |
| 690 | static const struct file_operations fops_chip_id = { |
| 691 | .read = ath10k_read_chip_id, |
| 692 | .open = simple_open, |
| 693 | .owner = THIS_MODULE, |
| 694 | .llseek = default_llseek, |
| 695 | }; |
| 696 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 697 | struct ath10k_fw_crash_data * |
| 698 | ath10k_debug_get_new_fw_crash_data(struct ath10k *ar) |
| 699 | { |
| 700 | struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data; |
| 701 | |
| 702 | lockdep_assert_held(&ar->data_lock); |
| 703 | |
| 704 | crash_data->crashed_since_read = true; |
| 705 | uuid_le_gen(&crash_data->uuid); |
| 706 | getnstimeofday(&crash_data->timestamp); |
| 707 | |
| 708 | return crash_data; |
| 709 | } |
| 710 | EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data); |
| 711 | |
| 712 | static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar) |
| 713 | { |
| 714 | struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data; |
| 715 | struct ath10k_dump_file_data *dump_data; |
| 716 | struct ath10k_tlv_dump_data *dump_tlv; |
| 717 | int hdr_len = sizeof(*dump_data); |
| 718 | unsigned int len, sofar = 0; |
| 719 | unsigned char *buf; |
| 720 | |
| 721 | len = hdr_len; |
| 722 | len += sizeof(*dump_tlv) + sizeof(crash_data->registers); |
| 723 | |
| 724 | sofar += hdr_len; |
| 725 | |
| 726 | /* This is going to get big when we start dumping FW RAM and such, |
| 727 | * so go ahead and use vmalloc. |
| 728 | */ |
| 729 | buf = vzalloc(len); |
| 730 | if (!buf) |
| 731 | return NULL; |
| 732 | |
| 733 | spin_lock_bh(&ar->data_lock); |
| 734 | |
| 735 | if (!crash_data->crashed_since_read) { |
| 736 | spin_unlock_bh(&ar->data_lock); |
| 737 | vfree(buf); |
| 738 | return NULL; |
| 739 | } |
| 740 | |
| 741 | dump_data = (struct ath10k_dump_file_data *)(buf); |
| 742 | strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP", |
| 743 | sizeof(dump_data->df_magic)); |
| 744 | dump_data->len = cpu_to_le32(len); |
| 745 | |
| 746 | dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION); |
| 747 | |
| 748 | memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid)); |
| 749 | dump_data->chip_id = cpu_to_le32(ar->chip_id); |
| 750 | dump_data->bus_type = cpu_to_le32(0); |
| 751 | dump_data->target_version = cpu_to_le32(ar->target_version); |
| 752 | dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major); |
| 753 | dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor); |
| 754 | dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release); |
| 755 | dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build); |
| 756 | dump_data->phy_capability = cpu_to_le32(ar->phy_capability); |
| 757 | dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power); |
| 758 | dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power); |
| 759 | dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info); |
| 760 | dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info); |
| 761 | dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains); |
| 762 | |
| 763 | strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version, |
| 764 | sizeof(dump_data->fw_ver)); |
| 765 | |
| 766 | dump_data->kernel_ver_code = cpu_to_le32(LINUX_VERSION_CODE); |
| 767 | strlcpy(dump_data->kernel_ver, VERMAGIC_STRING, |
| 768 | sizeof(dump_data->kernel_ver)); |
| 769 | |
| 770 | dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec); |
| 771 | dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec); |
| 772 | |
| 773 | /* Gather crash-dump */ |
| 774 | dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar); |
| 775 | dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS); |
| 776 | dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers)); |
| 777 | memcpy(dump_tlv->tlv_data, &crash_data->registers, |
| 778 | sizeof(crash_data->registers)); |
| 779 | sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers); |
| 780 | |
| 781 | ar->debug.fw_crash_data->crashed_since_read = false; |
| 782 | |
| 783 | spin_unlock_bh(&ar->data_lock); |
| 784 | |
| 785 | return dump_data; |
| 786 | } |
| 787 | |
| 788 | static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file) |
| 789 | { |
| 790 | struct ath10k *ar = inode->i_private; |
| 791 | struct ath10k_dump_file_data *dump; |
| 792 | |
| 793 | dump = ath10k_build_dump_file(ar); |
| 794 | if (!dump) |
| 795 | return -ENODATA; |
| 796 | |
| 797 | file->private_data = dump; |
| 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static ssize_t ath10k_fw_crash_dump_read(struct file *file, |
| 803 | char __user *user_buf, |
| 804 | size_t count, loff_t *ppos) |
| 805 | { |
| 806 | struct ath10k_dump_file_data *dump_file = file->private_data; |
| 807 | |
| 808 | return simple_read_from_buffer(user_buf, count, ppos, |
| 809 | dump_file, |
| 810 | le32_to_cpu(dump_file->len)); |
| 811 | } |
| 812 | |
| 813 | static int ath10k_fw_crash_dump_release(struct inode *inode, |
| 814 | struct file *file) |
| 815 | { |
| 816 | vfree(file->private_data); |
| 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | static const struct file_operations fops_fw_crash_dump = { |
| 822 | .open = ath10k_fw_crash_dump_open, |
| 823 | .read = ath10k_fw_crash_dump_read, |
| 824 | .release = ath10k_fw_crash_dump_release, |
| 825 | .owner = THIS_MODULE, |
| 826 | .llseek = default_llseek, |
| 827 | }; |
| 828 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 829 | static int ath10k_debug_htt_stats_req(struct ath10k *ar) |
| 830 | { |
| 831 | u64 cookie; |
| 832 | int ret; |
| 833 | |
| 834 | lockdep_assert_held(&ar->conf_mutex); |
| 835 | |
| 836 | if (ar->debug.htt_stats_mask == 0) |
| 837 | /* htt stats are disabled */ |
| 838 | return 0; |
| 839 | |
| 840 | if (ar->state != ATH10K_STATE_ON) |
| 841 | return 0; |
| 842 | |
| 843 | cookie = get_jiffies_64(); |
| 844 | |
| 845 | ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask, |
| 846 | cookie); |
| 847 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 848 | ath10k_warn(ar, "failed to send htt stats request: %d\n", ret); |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 849 | return ret; |
| 850 | } |
| 851 | |
| 852 | queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork, |
| 853 | msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL)); |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
| 858 | static void ath10k_debug_htt_stats_dwork(struct work_struct *work) |
| 859 | { |
| 860 | struct ath10k *ar = container_of(work, struct ath10k, |
| 861 | debug.htt_stats_dwork.work); |
| 862 | |
| 863 | mutex_lock(&ar->conf_mutex); |
| 864 | |
| 865 | ath10k_debug_htt_stats_req(ar); |
| 866 | |
| 867 | mutex_unlock(&ar->conf_mutex); |
| 868 | } |
| 869 | |
| 870 | static ssize_t ath10k_read_htt_stats_mask(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 871 | char __user *user_buf, |
| 872 | size_t count, loff_t *ppos) |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 873 | { |
| 874 | struct ath10k *ar = file->private_data; |
| 875 | char buf[32]; |
| 876 | unsigned int len; |
| 877 | |
| 878 | len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask); |
| 879 | |
| 880 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 881 | } |
| 882 | |
| 883 | static ssize_t ath10k_write_htt_stats_mask(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 884 | const char __user *user_buf, |
| 885 | size_t count, loff_t *ppos) |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 886 | { |
| 887 | struct ath10k *ar = file->private_data; |
| 888 | unsigned long mask; |
| 889 | int ret; |
| 890 | |
| 891 | ret = kstrtoul_from_user(user_buf, count, 0, &mask); |
| 892 | if (ret) |
| 893 | return ret; |
| 894 | |
| 895 | /* max 8 bit masks (for now) */ |
| 896 | if (mask > 0xff) |
| 897 | return -E2BIG; |
| 898 | |
| 899 | mutex_lock(&ar->conf_mutex); |
| 900 | |
| 901 | ar->debug.htt_stats_mask = mask; |
| 902 | |
| 903 | ret = ath10k_debug_htt_stats_req(ar); |
| 904 | if (ret) |
| 905 | goto out; |
| 906 | |
| 907 | ret = count; |
| 908 | |
| 909 | out: |
| 910 | mutex_unlock(&ar->conf_mutex); |
| 911 | |
| 912 | return ret; |
| 913 | } |
| 914 | |
| 915 | static const struct file_operations fops_htt_stats_mask = { |
| 916 | .read = ath10k_read_htt_stats_mask, |
| 917 | .write = ath10k_write_htt_stats_mask, |
| 918 | .open = simple_open, |
| 919 | .owner = THIS_MODULE, |
| 920 | .llseek = default_llseek, |
| 921 | }; |
| 922 | |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 923 | static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file, |
| 924 | char __user *user_buf, |
| 925 | size_t count, loff_t *ppos) |
| 926 | { |
| 927 | struct ath10k *ar = file->private_data; |
| 928 | char buf[64]; |
| 929 | u8 amsdu = 3, ampdu = 64; |
| 930 | unsigned int len; |
| 931 | |
| 932 | mutex_lock(&ar->conf_mutex); |
| 933 | |
| 934 | if (ar->debug.htt_max_amsdu) |
| 935 | amsdu = ar->debug.htt_max_amsdu; |
| 936 | |
| 937 | if (ar->debug.htt_max_ampdu) |
| 938 | ampdu = ar->debug.htt_max_ampdu; |
| 939 | |
| 940 | mutex_unlock(&ar->conf_mutex); |
| 941 | |
| 942 | len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu); |
| 943 | |
| 944 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 945 | } |
| 946 | |
| 947 | static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file, |
| 948 | const char __user *user_buf, |
| 949 | size_t count, loff_t *ppos) |
| 950 | { |
| 951 | struct ath10k *ar = file->private_data; |
| 952 | int res; |
| 953 | char buf[64]; |
| 954 | unsigned int amsdu, ampdu; |
| 955 | |
| 956 | simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); |
| 957 | |
| 958 | /* make sure that buf is null terminated */ |
| 959 | buf[sizeof(buf) - 1] = 0; |
| 960 | |
| 961 | res = sscanf(buf, "%u %u", &amsdu, &du); |
| 962 | |
| 963 | if (res != 2) |
| 964 | return -EINVAL; |
| 965 | |
| 966 | mutex_lock(&ar->conf_mutex); |
| 967 | |
| 968 | res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu); |
| 969 | if (res) |
| 970 | goto out; |
| 971 | |
| 972 | res = count; |
| 973 | ar->debug.htt_max_amsdu = amsdu; |
| 974 | ar->debug.htt_max_ampdu = ampdu; |
| 975 | |
| 976 | out: |
| 977 | mutex_unlock(&ar->conf_mutex); |
| 978 | return res; |
| 979 | } |
| 980 | |
| 981 | static const struct file_operations fops_htt_max_amsdu_ampdu = { |
| 982 | .read = ath10k_read_htt_max_amsdu_ampdu, |
| 983 | .write = ath10k_write_htt_max_amsdu_ampdu, |
| 984 | .open = simple_open, |
| 985 | .owner = THIS_MODULE, |
| 986 | .llseek = default_llseek, |
| 987 | }; |
| 988 | |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 989 | static ssize_t ath10k_read_fw_dbglog(struct file *file, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 990 | char __user *user_buf, |
| 991 | size_t count, loff_t *ppos) |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 992 | { |
| 993 | struct ath10k *ar = file->private_data; |
| 994 | unsigned int len; |
| 995 | char buf[32]; |
| 996 | |
| 997 | len = scnprintf(buf, sizeof(buf), "0x%08x\n", |
| 998 | ar->debug.fw_dbglog_mask); |
| 999 | |
| 1000 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1001 | } |
| 1002 | |
| 1003 | static ssize_t ath10k_write_fw_dbglog(struct file *file, |
| 1004 | const char __user *user_buf, |
| 1005 | size_t count, loff_t *ppos) |
| 1006 | { |
| 1007 | struct ath10k *ar = file->private_data; |
| 1008 | unsigned long mask; |
| 1009 | int ret; |
| 1010 | |
| 1011 | ret = kstrtoul_from_user(user_buf, count, 0, &mask); |
| 1012 | if (ret) |
| 1013 | return ret; |
| 1014 | |
| 1015 | mutex_lock(&ar->conf_mutex); |
| 1016 | |
| 1017 | ar->debug.fw_dbglog_mask = mask; |
| 1018 | |
| 1019 | if (ar->state == ATH10K_STATE_ON) { |
| 1020 | ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask); |
| 1021 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1022 | ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n", |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1023 | ret); |
| 1024 | goto exit; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | ret = count; |
| 1029 | |
| 1030 | exit: |
| 1031 | mutex_unlock(&ar->conf_mutex); |
| 1032 | |
| 1033 | return ret; |
| 1034 | } |
| 1035 | |
| 1036 | static const struct file_operations fops_fw_dbglog = { |
| 1037 | .read = ath10k_read_fw_dbglog, |
| 1038 | .write = ath10k_write_fw_dbglog, |
| 1039 | .open = simple_open, |
| 1040 | .owner = THIS_MODULE, |
| 1041 | .llseek = default_llseek, |
| 1042 | }; |
| 1043 | |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1044 | int ath10k_debug_start(struct ath10k *ar) |
| 1045 | { |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1046 | int ret; |
| 1047 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1048 | lockdep_assert_held(&ar->conf_mutex); |
| 1049 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1050 | ret = ath10k_debug_htt_stats_req(ar); |
| 1051 | if (ret) |
| 1052 | /* continue normally anyway, this isn't serious */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1053 | ath10k_warn(ar, "failed to start htt stats workqueue: %d\n", |
| 1054 | ret); |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1055 | |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1056 | if (ar->debug.fw_dbglog_mask) { |
| 1057 | ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask); |
| 1058 | if (ret) |
| 1059 | /* not serious */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1060 | ath10k_warn(ar, "failed to enable dbglog during start: %d", |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1061 | ret); |
| 1062 | } |
| 1063 | |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1064 | return 0; |
| 1065 | } |
| 1066 | |
| 1067 | void ath10k_debug_stop(struct ath10k *ar) |
| 1068 | { |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1069 | lockdep_assert_held(&ar->conf_mutex); |
| 1070 | |
| 1071 | /* Must not use _sync to avoid deadlock, we do that in |
| 1072 | * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid |
| 1073 | * warning from del_timer(). */ |
| 1074 | if (ar->debug.htt_stats_mask != 0) |
| 1075 | cancel_delayed_work(&ar->debug.htt_stats_dwork); |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1076 | |
| 1077 | ar->debug.htt_max_amsdu = 0; |
| 1078 | ar->debug.htt_max_ampdu = 0; |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1079 | } |
| 1080 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1081 | static ssize_t ath10k_write_simulate_radar(struct file *file, |
| 1082 | const char __user *user_buf, |
| 1083 | size_t count, loff_t *ppos) |
| 1084 | { |
| 1085 | struct ath10k *ar = file->private_data; |
| 1086 | |
| 1087 | ieee80211_radar_detected(ar->hw); |
| 1088 | |
| 1089 | return count; |
| 1090 | } |
| 1091 | |
| 1092 | static const struct file_operations fops_simulate_radar = { |
| 1093 | .write = ath10k_write_simulate_radar, |
| 1094 | .open = simple_open, |
| 1095 | .owner = THIS_MODULE, |
| 1096 | .llseek = default_llseek, |
| 1097 | }; |
| 1098 | |
| 1099 | #define ATH10K_DFS_STAT(s, p) (\ |
| 1100 | len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \ |
| 1101 | ar->debug.dfs_stats.p)) |
| 1102 | |
| 1103 | #define ATH10K_DFS_POOL_STAT(s, p) (\ |
| 1104 | len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \ |
| 1105 | ar->debug.dfs_pool_stats.p)) |
| 1106 | |
| 1107 | static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf, |
| 1108 | size_t count, loff_t *ppos) |
| 1109 | { |
| 1110 | int retval = 0, len = 0; |
| 1111 | const int size = 8000; |
| 1112 | struct ath10k *ar = file->private_data; |
| 1113 | char *buf; |
| 1114 | |
| 1115 | buf = kzalloc(size, GFP_KERNEL); |
| 1116 | if (buf == NULL) |
| 1117 | return -ENOMEM; |
| 1118 | |
| 1119 | if (!ar->dfs_detector) { |
| 1120 | len += scnprintf(buf + len, size - len, "DFS not enabled\n"); |
| 1121 | goto exit; |
| 1122 | } |
| 1123 | |
| 1124 | ar->debug.dfs_pool_stats = |
| 1125 | ar->dfs_detector->get_stats(ar->dfs_detector); |
| 1126 | |
| 1127 | len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n"); |
| 1128 | |
| 1129 | ATH10K_DFS_STAT("reported phy errors", phy_errors); |
| 1130 | ATH10K_DFS_STAT("pulse events reported", pulses_total); |
| 1131 | ATH10K_DFS_STAT("DFS pulses detected", pulses_detected); |
| 1132 | ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded); |
| 1133 | ATH10K_DFS_STAT("Radars detected", radar_detected); |
| 1134 | |
| 1135 | len += scnprintf(buf + len, size - len, "Global Pool statistics:\n"); |
| 1136 | ATH10K_DFS_POOL_STAT("Pool references", pool_reference); |
| 1137 | ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated); |
| 1138 | ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error); |
| 1139 | ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used); |
| 1140 | ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated); |
| 1141 | ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error); |
| 1142 | ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used); |
| 1143 | |
| 1144 | exit: |
| 1145 | if (len > size) |
| 1146 | len = size; |
| 1147 | |
| 1148 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1149 | kfree(buf); |
| 1150 | |
| 1151 | return retval; |
| 1152 | } |
| 1153 | |
| 1154 | static const struct file_operations fops_dfs_stats = { |
| 1155 | .read = ath10k_read_dfs_stats, |
| 1156 | .open = simple_open, |
| 1157 | .owner = THIS_MODULE, |
| 1158 | .llseek = default_llseek, |
| 1159 | }; |
| 1160 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1161 | int ath10k_debug_create(struct ath10k *ar) |
| 1162 | { |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 1163 | ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data)); |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1164 | if (!ar->debug.fw_crash_data) |
| 1165 | return -ENOMEM; |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 1166 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1167 | return 0; |
| 1168 | } |
| 1169 | |
| 1170 | void ath10k_debug_destroy(struct ath10k *ar) |
| 1171 | { |
| 1172 | vfree(ar->debug.fw_crash_data); |
| 1173 | ar->debug.fw_crash_data = NULL; |
| 1174 | } |
| 1175 | |
| 1176 | int ath10k_debug_register(struct ath10k *ar) |
| 1177 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1178 | ar->debug.debugfs_phy = debugfs_create_dir("ath10k", |
| 1179 | ar->hw->wiphy->debugfsdir); |
Michal Kazior | adb43b2 | 2014-09-04 12:36:45 +0200 | [diff] [blame] | 1180 | if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) { |
| 1181 | if (IS_ERR(ar->debug.debugfs_phy)) |
| 1182 | return PTR_ERR(ar->debug.debugfs_phy); |
Kalle Valo | d8bb26b | 2014-09-14 12:50:33 +0300 | [diff] [blame] | 1183 | |
| 1184 | return -ENOMEM; |
Michal Kazior | adb43b2 | 2014-09-04 12:36:45 +0200 | [diff] [blame] | 1185 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1186 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1187 | INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork, |
| 1188 | ath10k_debug_htt_stats_dwork); |
| 1189 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1190 | init_completion(&ar->debug.event_stats_compl); |
| 1191 | |
| 1192 | debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar, |
| 1193 | &fops_fw_stats); |
| 1194 | |
| 1195 | debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar, |
| 1196 | &fops_wmi_services); |
| 1197 | |
Michal Kazior | 278c4a8 | 2013-07-22 14:08:51 +0200 | [diff] [blame] | 1198 | debugfs_create_file("simulate_fw_crash", S_IRUSR, ar->debug.debugfs_phy, |
| 1199 | ar, &fops_simulate_fw_crash); |
| 1200 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 1201 | debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy, |
| 1202 | ar, &fops_fw_crash_dump); |
| 1203 | |
Kalle Valo | 763b8cd | 2013-09-01 11:22:21 +0300 | [diff] [blame] | 1204 | debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy, |
| 1205 | ar, &fops_chip_id); |
| 1206 | |
Kalle Valo | a3d135e | 2013-09-03 11:44:10 +0300 | [diff] [blame] | 1207 | debugfs_create_file("htt_stats_mask", S_IRUSR, ar->debug.debugfs_phy, |
| 1208 | ar, &fops_htt_stats_mask); |
| 1209 | |
Janusz Dziedzic | d385623 | 2014-06-02 21:19:46 +0300 | [diff] [blame] | 1210 | debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR, |
| 1211 | ar->debug.debugfs_phy, ar, |
| 1212 | &fops_htt_max_amsdu_ampdu); |
| 1213 | |
Kalle Valo | f118a3e | 2014-01-03 12:59:31 +0200 | [diff] [blame] | 1214 | debugfs_create_file("fw_dbglog", S_IRUSR, ar->debug.debugfs_phy, |
| 1215 | ar, &fops_fw_dbglog); |
| 1216 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1217 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) { |
| 1218 | debugfs_create_file("dfs_simulate_radar", S_IWUSR, |
| 1219 | ar->debug.debugfs_phy, ar, |
| 1220 | &fops_simulate_radar); |
| 1221 | |
Marek Puzyniak | 7d9b40b | 2013-11-20 10:00:28 +0200 | [diff] [blame] | 1222 | debugfs_create_bool("dfs_block_radar_events", S_IWUSR, |
| 1223 | ar->debug.debugfs_phy, |
| 1224 | &ar->dfs_block_radar_events); |
| 1225 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1226 | debugfs_create_file("dfs_stats", S_IRUSR, |
| 1227 | ar->debug.debugfs_phy, ar, |
| 1228 | &fops_dfs_stats); |
| 1229 | } |
| 1230 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1231 | return 0; |
| 1232 | } |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1233 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1234 | void ath10k_debug_unregister(struct ath10k *ar) |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1235 | { |
| 1236 | cancel_delayed_work_sync(&ar->debug.htt_stats_dwork); |
| 1237 | } |
| 1238 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1239 | #endif /* CONFIG_ATH10K_DEBUGFS */ |
| 1240 | |
| 1241 | #ifdef CONFIG_ATH10K_DEBUG |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1242 | void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask, |
| 1243 | const char *fmt, ...) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1244 | { |
| 1245 | struct va_format vaf; |
| 1246 | va_list args; |
| 1247 | |
| 1248 | va_start(args, fmt); |
| 1249 | |
| 1250 | vaf.fmt = fmt; |
| 1251 | vaf.va = &args; |
| 1252 | |
| 1253 | if (ath10k_debug_mask & mask) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1254 | dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1255 | |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1256 | trace_ath10k_log_dbg(ar, mask, &vaf); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1257 | |
| 1258 | va_end(args); |
| 1259 | } |
| 1260 | EXPORT_SYMBOL(ath10k_dbg); |
| 1261 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1262 | void ath10k_dbg_dump(struct ath10k *ar, |
| 1263 | enum ath10k_debug_mask mask, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1264 | const char *msg, const char *prefix, |
| 1265 | const void *buf, size_t len) |
| 1266 | { |
Michal Kazior | 45724a8 | 2014-09-23 10:22:53 +0200 | [diff] [blame^] | 1267 | char linebuf[256]; |
| 1268 | unsigned int linebuflen; |
| 1269 | const void *ptr; |
| 1270 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1271 | if (ath10k_debug_mask & mask) { |
| 1272 | if (msg) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1273 | ath10k_dbg(ar, mask, "%s\n", msg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1274 | |
Michal Kazior | 45724a8 | 2014-09-23 10:22:53 +0200 | [diff] [blame^] | 1275 | for (ptr = buf; (ptr - buf) < len; ptr += 16) { |
| 1276 | linebuflen = 0; |
| 1277 | linebuflen += scnprintf(linebuf + linebuflen, |
| 1278 | sizeof(linebuf) - linebuflen, |
| 1279 | "%s%08x: ", |
| 1280 | (prefix ? prefix : ""), |
| 1281 | (unsigned int)(ptr - buf)); |
| 1282 | hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1, |
| 1283 | linebuf + linebuflen, |
| 1284 | sizeof(linebuf) - linebuflen, true); |
| 1285 | dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf); |
| 1286 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | /* tracing code doesn't like null strings :/ */ |
Michal Kazior | d35a6c1 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1290 | trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1291 | buf, len); |
| 1292 | } |
| 1293 | EXPORT_SYMBOL(ath10k_dbg_dump); |
| 1294 | |
| 1295 | #endif /* CONFIG_ATH10K_DEBUG */ |