Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004-2011 Atheros Communications Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include "core.h" |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 18 | |
| 19 | #include <linux/circ_buf.h> |
Kalle Valo | 939f1cc | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 20 | #include <linux/fs.h> |
Kalle Valo | 62c83ac | 2011-10-03 13:44:40 +0300 | [diff] [blame] | 21 | #include <linux/vmalloc.h> |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 22 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 23 | #include "debug.h" |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 24 | #include "target.h" |
| 25 | |
| 26 | struct ath6kl_fwlog_slot { |
| 27 | __le32 timestamp; |
| 28 | __le32 length; |
| 29 | |
| 30 | /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */ |
| 31 | u8 payload[0]; |
| 32 | }; |
| 33 | |
| 34 | #define ATH6KL_FWLOG_SIZE 32768 |
| 35 | #define ATH6KL_FWLOG_SLOT_SIZE (sizeof(struct ath6kl_fwlog_slot) + \ |
| 36 | ATH6KL_FWLOG_PAYLOAD_SIZE) |
Kalle Valo | 939f1cc | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 37 | #define ATH6KL_FWLOG_VALID_MASK 0x1ffff |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 38 | |
| 39 | int ath6kl_printk(const char *level, const char *fmt, ...) |
| 40 | { |
| 41 | struct va_format vaf; |
| 42 | va_list args; |
| 43 | int rtn; |
| 44 | |
| 45 | va_start(args, fmt); |
| 46 | |
| 47 | vaf.fmt = fmt; |
| 48 | vaf.va = &args; |
| 49 | |
| 50 | rtn = printk("%sath6kl: %pV", level, &vaf); |
| 51 | |
| 52 | va_end(args); |
| 53 | |
| 54 | return rtn; |
| 55 | } |
| 56 | |
| 57 | #ifdef CONFIG_ATH6KL_DEBUG |
Vasanthakumar Thiagarajan | 91d57de | 2011-09-02 10:40:06 +0300 | [diff] [blame] | 58 | |
| 59 | #define REG_OUTPUT_LEN_PER_LINE 25 |
| 60 | #define REGTYPE_STR_LEN 100 |
| 61 | |
| 62 | struct ath6kl_diag_reg_info { |
| 63 | u32 reg_start; |
| 64 | u32 reg_end; |
| 65 | const char *reg_info; |
| 66 | }; |
| 67 | |
| 68 | static const struct ath6kl_diag_reg_info diag_reg[] = { |
| 69 | { 0x20000, 0x200fc, "General DMA and Rx registers" }, |
| 70 | { 0x28000, 0x28900, "MAC PCU register & keycache" }, |
| 71 | { 0x20800, 0x20a40, "QCU" }, |
| 72 | { 0x21000, 0x212f0, "DCU" }, |
| 73 | { 0x4000, 0x42e4, "RTC" }, |
| 74 | { 0x540000, 0x540000 + (256 * 1024), "RAM" }, |
| 75 | { 0x29800, 0x2B210, "Base Band" }, |
| 76 | { 0x1C000, 0x1C748, "Analog" }, |
| 77 | }; |
| 78 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 79 | void ath6kl_dump_registers(struct ath6kl_device *dev, |
| 80 | struct ath6kl_irq_proc_registers *irq_proc_reg, |
| 81 | struct ath6kl_irq_enable_reg *irq_enable_reg) |
| 82 | { |
| 83 | |
| 84 | ath6kl_dbg(ATH6KL_DBG_ANY, ("<------- Register Table -------->\n")); |
| 85 | |
| 86 | if (irq_proc_reg != NULL) { |
| 87 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 88 | "Host Int status: 0x%x\n", |
| 89 | irq_proc_reg->host_int_status); |
| 90 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 91 | "CPU Int status: 0x%x\n", |
| 92 | irq_proc_reg->cpu_int_status); |
| 93 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 94 | "Error Int status: 0x%x\n", |
| 95 | irq_proc_reg->error_int_status); |
| 96 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 97 | "Counter Int status: 0x%x\n", |
| 98 | irq_proc_reg->counter_int_status); |
| 99 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 100 | "Mbox Frame: 0x%x\n", |
| 101 | irq_proc_reg->mbox_frame); |
| 102 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 103 | "Rx Lookahead Valid: 0x%x\n", |
| 104 | irq_proc_reg->rx_lkahd_valid); |
| 105 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 106 | "Rx Lookahead 0: 0x%x\n", |
| 107 | irq_proc_reg->rx_lkahd[0]); |
| 108 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 109 | "Rx Lookahead 1: 0x%x\n", |
| 110 | irq_proc_reg->rx_lkahd[1]); |
| 111 | |
| 112 | if (dev->ar->mbox_info.gmbox_addr != 0) { |
| 113 | /* |
| 114 | * If the target supports GMBOX hardware, dump some |
| 115 | * additional state. |
| 116 | */ |
| 117 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 118 | "GMBOX Host Int status 2: 0x%x\n", |
| 119 | irq_proc_reg->host_int_status2); |
| 120 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 121 | "GMBOX RX Avail: 0x%x\n", |
| 122 | irq_proc_reg->gmbox_rx_avail); |
| 123 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 124 | "GMBOX lookahead alias 0: 0x%x\n", |
| 125 | irq_proc_reg->rx_gmbox_lkahd_alias[0]); |
| 126 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 127 | "GMBOX lookahead alias 1: 0x%x\n", |
| 128 | irq_proc_reg->rx_gmbox_lkahd_alias[1]); |
| 129 | } |
| 130 | |
| 131 | } |
| 132 | |
| 133 | if (irq_enable_reg != NULL) { |
| 134 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 135 | "Int status Enable: 0x%x\n", |
| 136 | irq_enable_reg->int_status_en); |
| 137 | ath6kl_dbg(ATH6KL_DBG_ANY, "Counter Int status Enable: 0x%x\n", |
| 138 | irq_enable_reg->cntr_int_status_en); |
| 139 | } |
| 140 | ath6kl_dbg(ATH6KL_DBG_ANY, "<------------------------------->\n"); |
| 141 | } |
| 142 | |
| 143 | static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist) |
| 144 | { |
| 145 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 146 | "--- endpoint: %d svc_id: 0x%X ---\n", |
| 147 | ep_dist->endpoint, ep_dist->svc_id); |
| 148 | ath6kl_dbg(ATH6KL_DBG_ANY, " dist_flags : 0x%X\n", |
| 149 | ep_dist->dist_flags); |
| 150 | ath6kl_dbg(ATH6KL_DBG_ANY, " cred_norm : %d\n", |
| 151 | ep_dist->cred_norm); |
| 152 | ath6kl_dbg(ATH6KL_DBG_ANY, " cred_min : %d\n", |
| 153 | ep_dist->cred_min); |
| 154 | ath6kl_dbg(ATH6KL_DBG_ANY, " credits : %d\n", |
| 155 | ep_dist->credits); |
| 156 | ath6kl_dbg(ATH6KL_DBG_ANY, " cred_assngd : %d\n", |
| 157 | ep_dist->cred_assngd); |
| 158 | ath6kl_dbg(ATH6KL_DBG_ANY, " seek_cred : %d\n", |
| 159 | ep_dist->seek_cred); |
| 160 | ath6kl_dbg(ATH6KL_DBG_ANY, " cred_sz : %d\n", |
| 161 | ep_dist->cred_sz); |
| 162 | ath6kl_dbg(ATH6KL_DBG_ANY, " cred_per_msg : %d\n", |
| 163 | ep_dist->cred_per_msg); |
| 164 | ath6kl_dbg(ATH6KL_DBG_ANY, " cred_to_dist : %d\n", |
| 165 | ep_dist->cred_to_dist); |
| 166 | ath6kl_dbg(ATH6KL_DBG_ANY, " txq_depth : %d\n", |
| 167 | get_queue_depth(&((struct htc_endpoint *) |
| 168 | ep_dist->htc_rsvd)->txq)); |
| 169 | ath6kl_dbg(ATH6KL_DBG_ANY, |
| 170 | "----------------------------------\n"); |
| 171 | } |
| 172 | |
| 173 | void dump_cred_dist_stats(struct htc_target *target) |
| 174 | { |
| 175 | struct htc_endpoint_credit_dist *ep_list; |
| 176 | |
| 177 | if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_TRC)) |
| 178 | return; |
| 179 | |
| 180 | list_for_each_entry(ep_list, &target->cred_dist_list, list) |
| 181 | dump_cred_dist(ep_list); |
| 182 | |
Kalle Valo | ebf29c9 | 2011-10-13 15:21:15 +0300 | [diff] [blame] | 183 | ath6kl_dbg(ATH6KL_DBG_HTC, "ctxt:%p dist:%p\n", |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 184 | target->cred_dist_cntxt, NULL); |
Kalle Valo | ebf29c9 | 2011-10-13 15:21:15 +0300 | [diff] [blame] | 185 | ath6kl_dbg(ATH6KL_DBG_HTC, |
| 186 | "credit distribution, total : %d, free : %d\n", |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 187 | target->cred_dist_cntxt->total_avail_credits, |
| 188 | target->cred_dist_cntxt->cur_free_credits); |
| 189 | } |
| 190 | |
Vasanthakumar Thiagarajan | 03f68a9 | 2011-08-26 13:06:32 +0530 | [diff] [blame] | 191 | static int ath6kl_debugfs_open(struct inode *inode, struct file *file) |
| 192 | { |
| 193 | file->private_data = inode->i_private; |
| 194 | return 0; |
| 195 | } |
| 196 | |
Kalle Valo | 9a73083 | 2011-09-27 23:33:28 +0300 | [diff] [blame] | 197 | void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war) |
| 198 | { |
| 199 | switch (war) { |
| 200 | case ATH6KL_WAR_INVALID_RATE: |
| 201 | ar->debug.war_stats.invalid_rate++; |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | static ssize_t read_file_war_stats(struct file *file, char __user *user_buf, |
| 207 | size_t count, loff_t *ppos) |
| 208 | { |
| 209 | struct ath6kl *ar = file->private_data; |
| 210 | char *buf; |
| 211 | unsigned int len = 0, buf_len = 1500; |
| 212 | ssize_t ret_cnt; |
| 213 | |
| 214 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 215 | if (!buf) |
| 216 | return -ENOMEM; |
| 217 | |
| 218 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 219 | len += scnprintf(buf + len, buf_len - len, "%25s\n", |
| 220 | "Workaround stats"); |
| 221 | len += scnprintf(buf + len, buf_len - len, "%25s\n\n", |
| 222 | "================="); |
| 223 | len += scnprintf(buf + len, buf_len - len, "%20s %10u\n", |
| 224 | "Invalid rates", ar->debug.war_stats.invalid_rate); |
| 225 | |
| 226 | if (WARN_ON(len > buf_len)) |
| 227 | len = buf_len; |
| 228 | |
| 229 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 230 | |
| 231 | kfree(buf); |
| 232 | return ret_cnt; |
| 233 | } |
| 234 | |
| 235 | static const struct file_operations fops_war_stats = { |
| 236 | .read = read_file_war_stats, |
| 237 | .open = ath6kl_debugfs_open, |
| 238 | .owner = THIS_MODULE, |
| 239 | .llseek = default_llseek, |
| 240 | }; |
| 241 | |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 242 | static void ath6kl_debug_fwlog_add(struct ath6kl *ar, const void *buf, |
| 243 | size_t buf_len) |
| 244 | { |
| 245 | struct circ_buf *fwlog = &ar->debug.fwlog_buf; |
| 246 | size_t space; |
| 247 | int i; |
| 248 | |
| 249 | /* entries must all be equal size */ |
| 250 | if (WARN_ON(buf_len != ATH6KL_FWLOG_SLOT_SIZE)) |
| 251 | return; |
| 252 | |
| 253 | space = CIRC_SPACE(fwlog->head, fwlog->tail, ATH6KL_FWLOG_SIZE); |
| 254 | if (space < buf_len) |
| 255 | /* discard oldest slot */ |
| 256 | fwlog->tail = (fwlog->tail + ATH6KL_FWLOG_SLOT_SIZE) & |
| 257 | (ATH6KL_FWLOG_SIZE - 1); |
| 258 | |
| 259 | for (i = 0; i < buf_len; i += space) { |
| 260 | space = CIRC_SPACE_TO_END(fwlog->head, fwlog->tail, |
| 261 | ATH6KL_FWLOG_SIZE); |
| 262 | |
| 263 | if ((size_t) space > buf_len - i) |
| 264 | space = buf_len - i; |
| 265 | |
| 266 | memcpy(&fwlog->buf[fwlog->head], buf, space); |
| 267 | fwlog->head = (fwlog->head + space) & (ATH6KL_FWLOG_SIZE - 1); |
| 268 | } |
| 269 | |
| 270 | } |
| 271 | |
| 272 | void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len) |
| 273 | { |
| 274 | struct ath6kl_fwlog_slot *slot = ar->debug.fwlog_tmp; |
| 275 | size_t slot_len; |
| 276 | |
| 277 | if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE)) |
| 278 | return; |
| 279 | |
| 280 | spin_lock_bh(&ar->debug.fwlog_lock); |
| 281 | |
| 282 | slot->timestamp = cpu_to_le32(jiffies); |
| 283 | slot->length = cpu_to_le32(len); |
| 284 | memcpy(slot->payload, buf, len); |
| 285 | |
| 286 | slot_len = sizeof(*slot) + len; |
| 287 | |
| 288 | if (slot_len < ATH6KL_FWLOG_SLOT_SIZE) |
| 289 | memset(slot->payload + len, 0, |
| 290 | ATH6KL_FWLOG_SLOT_SIZE - slot_len); |
| 291 | |
| 292 | ath6kl_debug_fwlog_add(ar, slot, ATH6KL_FWLOG_SLOT_SIZE); |
| 293 | |
| 294 | spin_unlock_bh(&ar->debug.fwlog_lock); |
| 295 | } |
| 296 | |
| 297 | static bool ath6kl_debug_fwlog_empty(struct ath6kl *ar) |
| 298 | { |
| 299 | return CIRC_CNT(ar->debug.fwlog_buf.head, |
| 300 | ar->debug.fwlog_buf.tail, |
| 301 | ATH6KL_FWLOG_SLOT_SIZE) == 0; |
| 302 | } |
| 303 | |
| 304 | static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf, |
| 305 | size_t count, loff_t *ppos) |
| 306 | { |
| 307 | struct ath6kl *ar = file->private_data; |
| 308 | struct circ_buf *fwlog = &ar->debug.fwlog_buf; |
| 309 | size_t len = 0, buf_len = count; |
| 310 | ssize_t ret_cnt; |
| 311 | char *buf; |
| 312 | int ccnt; |
| 313 | |
| 314 | buf = vmalloc(buf_len); |
| 315 | if (!buf) |
| 316 | return -ENOMEM; |
| 317 | |
Kalle Valo | bc07ddb | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 318 | /* read undelivered logs from firmware */ |
| 319 | ath6kl_read_fwlogs(ar); |
| 320 | |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 321 | spin_lock_bh(&ar->debug.fwlog_lock); |
| 322 | |
| 323 | while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) { |
| 324 | ccnt = CIRC_CNT_TO_END(fwlog->head, fwlog->tail, |
| 325 | ATH6KL_FWLOG_SIZE); |
| 326 | |
| 327 | if ((size_t) ccnt > buf_len - len) |
| 328 | ccnt = buf_len - len; |
| 329 | |
| 330 | memcpy(buf + len, &fwlog->buf[fwlog->tail], ccnt); |
| 331 | len += ccnt; |
| 332 | |
| 333 | fwlog->tail = (fwlog->tail + ccnt) & |
| 334 | (ATH6KL_FWLOG_SIZE - 1); |
| 335 | } |
| 336 | |
| 337 | spin_unlock_bh(&ar->debug.fwlog_lock); |
| 338 | |
| 339 | if (WARN_ON(len > buf_len)) |
| 340 | len = buf_len; |
| 341 | |
| 342 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 343 | |
| 344 | vfree(buf); |
| 345 | |
| 346 | return ret_cnt; |
| 347 | } |
| 348 | |
| 349 | static const struct file_operations fops_fwlog = { |
| 350 | .open = ath6kl_debugfs_open, |
| 351 | .read = ath6kl_fwlog_read, |
| 352 | .owner = THIS_MODULE, |
| 353 | .llseek = default_llseek, |
| 354 | }; |
| 355 | |
Kalle Valo | 939f1cc | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 356 | static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf, |
| 357 | size_t count, loff_t *ppos) |
| 358 | { |
| 359 | struct ath6kl *ar = file->private_data; |
| 360 | char buf[16]; |
| 361 | int len; |
| 362 | |
| 363 | len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask); |
| 364 | |
| 365 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 366 | } |
| 367 | |
| 368 | static ssize_t ath6kl_fwlog_mask_write(struct file *file, |
| 369 | const char __user *user_buf, |
| 370 | size_t count, loff_t *ppos) |
| 371 | { |
| 372 | struct ath6kl *ar = file->private_data; |
| 373 | int ret; |
| 374 | |
| 375 | ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask); |
| 376 | if (ret) |
| 377 | return ret; |
| 378 | |
| 379 | ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi, |
| 380 | ATH6KL_FWLOG_VALID_MASK, |
| 381 | ar->debug.fwlog_mask); |
| 382 | if (ret) |
| 383 | return ret; |
| 384 | |
| 385 | return count; |
| 386 | } |
| 387 | |
| 388 | static const struct file_operations fops_fwlog_mask = { |
| 389 | .open = ath6kl_debugfs_open, |
| 390 | .read = ath6kl_fwlog_mask_read, |
| 391 | .write = ath6kl_fwlog_mask_write, |
| 392 | .owner = THIS_MODULE, |
| 393 | .llseek = default_llseek, |
| 394 | }; |
| 395 | |
Vasanthakumar Thiagarajan | 03f68a9 | 2011-08-26 13:06:32 +0530 | [diff] [blame] | 396 | static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf, |
| 397 | size_t count, loff_t *ppos) |
| 398 | { |
| 399 | struct ath6kl *ar = file->private_data; |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 400 | struct ath6kl_vif *vif; |
| 401 | struct target_stats *tgt_stats; |
Vasanthakumar Thiagarajan | 03f68a9 | 2011-08-26 13:06:32 +0530 | [diff] [blame] | 402 | char *buf; |
| 403 | unsigned int len = 0, buf_len = 1500; |
| 404 | int i; |
| 405 | long left; |
| 406 | ssize_t ret_cnt; |
| 407 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 408 | vif = ath6kl_vif_first(ar); |
| 409 | if (!vif) |
| 410 | return -EIO; |
| 411 | |
| 412 | tgt_stats = &vif->target_stats; |
| 413 | |
Vasanthakumar Thiagarajan | 03f68a9 | 2011-08-26 13:06:32 +0530 | [diff] [blame] | 414 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 415 | if (!buf) |
| 416 | return -ENOMEM; |
| 417 | |
| 418 | if (down_interruptible(&ar->sem)) { |
| 419 | kfree(buf); |
| 420 | return -EBUSY; |
| 421 | } |
| 422 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 423 | set_bit(STATS_UPDATE_PEND, &vif->flags); |
Vasanthakumar Thiagarajan | 03f68a9 | 2011-08-26 13:06:32 +0530 | [diff] [blame] | 424 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 425 | if (ath6kl_wmi_get_stats_cmd(ar->wmi, 0)) { |
Vasanthakumar Thiagarajan | 03f68a9 | 2011-08-26 13:06:32 +0530 | [diff] [blame] | 426 | up(&ar->sem); |
| 427 | kfree(buf); |
| 428 | return -EIO; |
| 429 | } |
| 430 | |
| 431 | left = wait_event_interruptible_timeout(ar->event_wq, |
| 432 | !test_bit(STATS_UPDATE_PEND, |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 433 | &vif->flags), WMI_TIMEOUT); |
Vasanthakumar Thiagarajan | 03f68a9 | 2011-08-26 13:06:32 +0530 | [diff] [blame] | 434 | |
| 435 | up(&ar->sem); |
| 436 | |
| 437 | if (left <= 0) { |
| 438 | kfree(buf); |
| 439 | return -ETIMEDOUT; |
| 440 | } |
| 441 | |
| 442 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 443 | len += scnprintf(buf + len, buf_len - len, "%25s\n", |
| 444 | "Target Tx stats"); |
| 445 | len += scnprintf(buf + len, buf_len - len, "%25s\n\n", |
| 446 | "================="); |
| 447 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 448 | "Ucast packets", tgt_stats->tx_ucast_pkt); |
| 449 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 450 | "Bcast packets", tgt_stats->tx_bcast_pkt); |
| 451 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 452 | "Ucast byte", tgt_stats->tx_ucast_byte); |
| 453 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 454 | "Bcast byte", tgt_stats->tx_bcast_byte); |
| 455 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 456 | "Rts success cnt", tgt_stats->tx_rts_success_cnt); |
| 457 | for (i = 0; i < 4; i++) |
| 458 | len += scnprintf(buf + len, buf_len - len, |
| 459 | "%18s %d %10llu\n", "PER on ac", |
| 460 | i, tgt_stats->tx_pkt_per_ac[i]); |
| 461 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 462 | "Error", tgt_stats->tx_err); |
| 463 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 464 | "Fail count", tgt_stats->tx_fail_cnt); |
| 465 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 466 | "Retry count", tgt_stats->tx_retry_cnt); |
| 467 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 468 | "Multi retry cnt", tgt_stats->tx_mult_retry_cnt); |
| 469 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 470 | "Rts fail cnt", tgt_stats->tx_rts_fail_cnt); |
| 471 | len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n", |
| 472 | "TKIP counter measure used", |
| 473 | tgt_stats->tkip_cnter_measures_invoked); |
| 474 | |
| 475 | len += scnprintf(buf + len, buf_len - len, "%25s\n", |
| 476 | "Target Rx stats"); |
| 477 | len += scnprintf(buf + len, buf_len - len, "%25s\n", |
| 478 | "================="); |
| 479 | |
| 480 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 481 | "Ucast packets", tgt_stats->rx_ucast_pkt); |
| 482 | len += scnprintf(buf + len, buf_len - len, "%20s %10d\n", |
| 483 | "Ucast Rate", tgt_stats->rx_ucast_rate); |
| 484 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 485 | "Bcast packets", tgt_stats->rx_bcast_pkt); |
| 486 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 487 | "Ucast byte", tgt_stats->rx_ucast_byte); |
| 488 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 489 | "Bcast byte", tgt_stats->rx_bcast_byte); |
| 490 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 491 | "Fragmented pkt", tgt_stats->rx_frgment_pkt); |
| 492 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 493 | "Error", tgt_stats->rx_err); |
| 494 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 495 | "CRC Err", tgt_stats->rx_crc_err); |
| 496 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 497 | "Key chache miss", tgt_stats->rx_key_cache_miss); |
| 498 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 499 | "Decrypt Err", tgt_stats->rx_decrypt_err); |
| 500 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 501 | "Duplicate frame", tgt_stats->rx_dupl_frame); |
| 502 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 503 | "Tkip Mic failure", tgt_stats->tkip_local_mic_fail); |
| 504 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 505 | "TKIP format err", tgt_stats->tkip_fmt_err); |
| 506 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 507 | "CCMP format Err", tgt_stats->ccmp_fmt_err); |
| 508 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n", |
| 509 | "CCMP Replay Err", tgt_stats->ccmp_replays); |
| 510 | |
| 511 | len += scnprintf(buf + len, buf_len - len, "%25s\n", |
| 512 | "Misc Target stats"); |
| 513 | len += scnprintf(buf + len, buf_len - len, "%25s\n", |
| 514 | "================="); |
| 515 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 516 | "Beacon Miss count", tgt_stats->cs_bmiss_cnt); |
| 517 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 518 | "Num Connects", tgt_stats->cs_connect_cnt); |
| 519 | len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", |
| 520 | "Num disconnects", tgt_stats->cs_discon_cnt); |
| 521 | len += scnprintf(buf + len, buf_len - len, "%20s %10d\n", |
| 522 | "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi); |
| 523 | |
| 524 | if (len > buf_len) |
| 525 | len = buf_len; |
| 526 | |
| 527 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 528 | |
| 529 | kfree(buf); |
| 530 | return ret_cnt; |
| 531 | } |
| 532 | |
| 533 | static const struct file_operations fops_tgt_stats = { |
| 534 | .read = read_file_tgt_stats, |
| 535 | .open = ath6kl_debugfs_open, |
| 536 | .owner = THIS_MODULE, |
| 537 | .llseek = default_llseek, |
| 538 | }; |
| 539 | |
Vasanthakumar Thiagarajan | 78fc485 | 2011-08-26 13:06:33 +0530 | [diff] [blame] | 540 | #define print_credit_info(fmt_str, ep_list_field) \ |
| 541 | (len += scnprintf(buf + len, buf_len - len, fmt_str, \ |
| 542 | ep_list->ep_list_field)) |
| 543 | #define CREDIT_INFO_DISPLAY_STRING_LEN 200 |
| 544 | #define CREDIT_INFO_LEN 128 |
| 545 | |
| 546 | static ssize_t read_file_credit_dist_stats(struct file *file, |
| 547 | char __user *user_buf, |
| 548 | size_t count, loff_t *ppos) |
| 549 | { |
| 550 | struct ath6kl *ar = file->private_data; |
| 551 | struct htc_target *target = ar->htc_target; |
| 552 | struct htc_endpoint_credit_dist *ep_list; |
| 553 | char *buf; |
| 554 | unsigned int buf_len, len = 0; |
| 555 | ssize_t ret_cnt; |
| 556 | |
| 557 | buf_len = CREDIT_INFO_DISPLAY_STRING_LEN + |
| 558 | get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN; |
| 559 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 560 | if (!buf) |
| 561 | return -ENOMEM; |
| 562 | |
| 563 | len += scnprintf(buf + len, buf_len - len, "%25s%5d\n", |
| 564 | "Total Avail Credits: ", |
| 565 | target->cred_dist_cntxt->total_avail_credits); |
| 566 | len += scnprintf(buf + len, buf_len - len, "%25s%5d\n", |
| 567 | "Free credits :", |
| 568 | target->cred_dist_cntxt->cur_free_credits); |
| 569 | |
| 570 | len += scnprintf(buf + len, buf_len - len, |
| 571 | " Epid Flags Cred_norm Cred_min Credits Cred_assngd" |
| 572 | " Seek_cred Cred_sz Cred_per_msg Cred_to_dist" |
| 573 | " qdepth\n"); |
| 574 | |
| 575 | list_for_each_entry(ep_list, &target->cred_dist_list, list) { |
| 576 | print_credit_info(" %2d", endpoint); |
| 577 | print_credit_info("%10x", dist_flags); |
| 578 | print_credit_info("%8d", cred_norm); |
| 579 | print_credit_info("%9d", cred_min); |
| 580 | print_credit_info("%9d", credits); |
| 581 | print_credit_info("%10d", cred_assngd); |
| 582 | print_credit_info("%13d", seek_cred); |
| 583 | print_credit_info("%12d", cred_sz); |
| 584 | print_credit_info("%9d", cred_per_msg); |
| 585 | print_credit_info("%14d", cred_to_dist); |
| 586 | len += scnprintf(buf + len, buf_len - len, "%12d\n", |
| 587 | get_queue_depth(&((struct htc_endpoint *) |
| 588 | ep_list->htc_rsvd)->txq)); |
| 589 | } |
| 590 | |
| 591 | if (len > buf_len) |
| 592 | len = buf_len; |
| 593 | |
| 594 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 595 | kfree(buf); |
| 596 | return ret_cnt; |
| 597 | } |
| 598 | |
| 599 | static const struct file_operations fops_credit_dist_stats = { |
| 600 | .read = read_file_credit_dist_stats, |
| 601 | .open = ath6kl_debugfs_open, |
| 602 | .owner = THIS_MODULE, |
| 603 | .llseek = default_llseek, |
| 604 | }; |
| 605 | |
Jouni Malinen | e809128 | 2011-10-11 17:31:53 +0300 | [diff] [blame] | 606 | static unsigned int print_endpoint_stat(struct htc_target *target, char *buf, |
| 607 | unsigned int buf_len, unsigned int len, |
| 608 | int offset, const char *name) |
| 609 | { |
| 610 | int i; |
| 611 | struct htc_endpoint_stats *ep_st; |
| 612 | u32 *counter; |
| 613 | |
| 614 | len += scnprintf(buf + len, buf_len - len, "%s:", name); |
| 615 | for (i = 0; i < ENDPOINT_MAX; i++) { |
| 616 | ep_st = &target->endpoint[i].ep_st; |
| 617 | counter = ((u32 *) ep_st) + (offset / 4); |
| 618 | len += scnprintf(buf + len, buf_len - len, " %u", *counter); |
| 619 | } |
| 620 | len += scnprintf(buf + len, buf_len - len, "\n"); |
| 621 | |
| 622 | return len; |
| 623 | } |
| 624 | |
| 625 | static ssize_t ath6kl_endpoint_stats_read(struct file *file, |
| 626 | char __user *user_buf, |
| 627 | size_t count, loff_t *ppos) |
| 628 | { |
| 629 | struct ath6kl *ar = file->private_data; |
| 630 | struct htc_target *target = ar->htc_target; |
| 631 | char *buf; |
| 632 | unsigned int buf_len, len = 0; |
| 633 | ssize_t ret_cnt; |
| 634 | |
Jouni Malinen | 1716932 | 2011-10-11 22:08:21 +0300 | [diff] [blame] | 635 | buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) * |
| 636 | (25 + ENDPOINT_MAX * 11); |
| 637 | buf = kmalloc(buf_len, GFP_KERNEL); |
Jouni Malinen | e809128 | 2011-10-11 17:31:53 +0300 | [diff] [blame] | 638 | if (!buf) |
| 639 | return -ENOMEM; |
| 640 | |
| 641 | #define EPSTAT(name) \ |
| 642 | len = print_endpoint_stat(target, buf, buf_len, len, \ |
| 643 | offsetof(struct htc_endpoint_stats, name), \ |
| 644 | #name) |
| 645 | EPSTAT(cred_low_indicate); |
| 646 | EPSTAT(tx_issued); |
| 647 | EPSTAT(tx_pkt_bundled); |
| 648 | EPSTAT(tx_bundles); |
| 649 | EPSTAT(tx_dropped); |
| 650 | EPSTAT(tx_cred_rpt); |
| 651 | EPSTAT(cred_rpt_from_rx); |
Jouni Malinen | 1716932 | 2011-10-11 22:08:21 +0300 | [diff] [blame] | 652 | EPSTAT(cred_rpt_from_other); |
Jouni Malinen | e809128 | 2011-10-11 17:31:53 +0300 | [diff] [blame] | 653 | EPSTAT(cred_rpt_ep0); |
| 654 | EPSTAT(cred_from_rx); |
| 655 | EPSTAT(cred_from_other); |
| 656 | EPSTAT(cred_from_ep0); |
| 657 | EPSTAT(cred_cosumd); |
| 658 | EPSTAT(cred_retnd); |
| 659 | EPSTAT(rx_pkts); |
| 660 | EPSTAT(rx_lkahds); |
| 661 | EPSTAT(rx_bundl); |
| 662 | EPSTAT(rx_bundle_lkahd); |
| 663 | EPSTAT(rx_bundle_from_hdr); |
| 664 | EPSTAT(rx_alloc_thresh_hit); |
| 665 | EPSTAT(rxalloc_thresh_byte); |
| 666 | #undef EPSTAT |
| 667 | |
| 668 | if (len > buf_len) |
| 669 | len = buf_len; |
| 670 | |
| 671 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 672 | kfree(buf); |
| 673 | return ret_cnt; |
| 674 | } |
| 675 | |
| 676 | static ssize_t ath6kl_endpoint_stats_write(struct file *file, |
| 677 | const char __user *user_buf, |
| 678 | size_t count, loff_t *ppos) |
| 679 | { |
| 680 | struct ath6kl *ar = file->private_data; |
| 681 | struct htc_target *target = ar->htc_target; |
| 682 | int ret, i; |
| 683 | u32 val; |
| 684 | struct htc_endpoint_stats *ep_st; |
| 685 | |
| 686 | ret = kstrtou32_from_user(user_buf, count, 0, &val); |
| 687 | if (ret) |
| 688 | return ret; |
| 689 | if (val == 0) { |
| 690 | for (i = 0; i < ENDPOINT_MAX; i++) { |
| 691 | ep_st = &target->endpoint[i].ep_st; |
| 692 | memset(ep_st, 0, sizeof(*ep_st)); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | return count; |
| 697 | } |
| 698 | |
| 699 | static const struct file_operations fops_endpoint_stats = { |
| 700 | .open = ath6kl_debugfs_open, |
| 701 | .read = ath6kl_endpoint_stats_read, |
| 702 | .write = ath6kl_endpoint_stats_write, |
| 703 | .owner = THIS_MODULE, |
| 704 | .llseek = default_llseek, |
| 705 | }; |
| 706 | |
Vasanthakumar Thiagarajan | 91d57de | 2011-09-02 10:40:06 +0300 | [diff] [blame] | 707 | static unsigned long ath6kl_get_num_reg(void) |
| 708 | { |
| 709 | int i; |
| 710 | unsigned long n_reg = 0; |
| 711 | |
| 712 | for (i = 0; i < ARRAY_SIZE(diag_reg); i++) |
| 713 | n_reg = n_reg + |
| 714 | (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1; |
| 715 | |
| 716 | return n_reg; |
| 717 | } |
| 718 | |
| 719 | static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr) |
| 720 | { |
| 721 | int i; |
| 722 | |
| 723 | for (i = 0; i < ARRAY_SIZE(diag_reg); i++) { |
| 724 | if (reg_addr >= diag_reg[i].reg_start && |
| 725 | reg_addr <= diag_reg[i].reg_end) |
| 726 | return true; |
| 727 | } |
| 728 | |
| 729 | return false; |
| 730 | } |
| 731 | |
| 732 | static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf, |
| 733 | size_t count, loff_t *ppos) |
| 734 | { |
| 735 | struct ath6kl *ar = file->private_data; |
| 736 | u8 buf[50]; |
| 737 | unsigned int len = 0; |
| 738 | |
| 739 | if (ar->debug.dbgfs_diag_reg) |
| 740 | len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", |
| 741 | ar->debug.dbgfs_diag_reg); |
| 742 | else |
| 743 | len += scnprintf(buf + len, sizeof(buf) - len, |
| 744 | "All diag registers\n"); |
| 745 | |
| 746 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 747 | } |
| 748 | |
| 749 | static ssize_t ath6kl_regread_write(struct file *file, |
| 750 | const char __user *user_buf, |
| 751 | size_t count, loff_t *ppos) |
| 752 | { |
| 753 | struct ath6kl *ar = file->private_data; |
| 754 | u8 buf[50]; |
| 755 | unsigned int len; |
| 756 | unsigned long reg_addr; |
| 757 | |
| 758 | len = min(count, sizeof(buf) - 1); |
| 759 | if (copy_from_user(buf, user_buf, len)) |
| 760 | return -EFAULT; |
| 761 | |
| 762 | buf[len] = '\0'; |
| 763 | |
| 764 | if (strict_strtoul(buf, 0, ®_addr)) |
| 765 | return -EINVAL; |
| 766 | |
| 767 | if ((reg_addr % 4) != 0) |
| 768 | return -EINVAL; |
| 769 | |
| 770 | if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr)) |
| 771 | return -EINVAL; |
| 772 | |
| 773 | ar->debug.dbgfs_diag_reg = reg_addr; |
| 774 | |
| 775 | return count; |
| 776 | } |
| 777 | |
| 778 | static const struct file_operations fops_diag_reg_read = { |
| 779 | .read = ath6kl_regread_read, |
| 780 | .write = ath6kl_regread_write, |
| 781 | .open = ath6kl_debugfs_open, |
| 782 | .owner = THIS_MODULE, |
| 783 | .llseek = default_llseek, |
| 784 | }; |
| 785 | |
| 786 | static int ath6kl_regdump_open(struct inode *inode, struct file *file) |
| 787 | { |
| 788 | struct ath6kl *ar = inode->i_private; |
| 789 | u8 *buf; |
| 790 | unsigned long int reg_len; |
| 791 | unsigned int len = 0, n_reg; |
| 792 | u32 addr; |
| 793 | __le32 reg_val; |
| 794 | int i, status; |
| 795 | |
| 796 | /* Dump all the registers if no register is specified */ |
| 797 | if (!ar->debug.dbgfs_diag_reg) |
| 798 | n_reg = ath6kl_get_num_reg(); |
| 799 | else |
| 800 | n_reg = 1; |
| 801 | |
| 802 | reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE; |
| 803 | if (n_reg > 1) |
| 804 | reg_len += REGTYPE_STR_LEN; |
| 805 | |
| 806 | buf = vmalloc(reg_len); |
| 807 | if (!buf) |
| 808 | return -ENOMEM; |
| 809 | |
| 810 | if (n_reg == 1) { |
| 811 | addr = ar->debug.dbgfs_diag_reg; |
| 812 | |
| 813 | status = ath6kl_diag_read32(ar, |
| 814 | TARG_VTOP(ar->target_type, addr), |
| 815 | (u32 *)®_val); |
| 816 | if (status) |
| 817 | goto fail_reg_read; |
| 818 | |
| 819 | len += scnprintf(buf + len, reg_len - len, |
| 820 | "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val)); |
| 821 | goto done; |
| 822 | } |
| 823 | |
| 824 | for (i = 0; i < ARRAY_SIZE(diag_reg); i++) { |
| 825 | len += scnprintf(buf + len, reg_len - len, |
| 826 | "%s\n", diag_reg[i].reg_info); |
| 827 | for (addr = diag_reg[i].reg_start; |
| 828 | addr <= diag_reg[i].reg_end; addr += 4) { |
| 829 | status = ath6kl_diag_read32(ar, |
| 830 | TARG_VTOP(ar->target_type, addr), |
| 831 | (u32 *)®_val); |
| 832 | if (status) |
| 833 | goto fail_reg_read; |
| 834 | |
| 835 | len += scnprintf(buf + len, reg_len - len, |
| 836 | "0x%06x 0x%08x\n", |
| 837 | addr, le32_to_cpu(reg_val)); |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | done: |
| 842 | file->private_data = buf; |
| 843 | return 0; |
| 844 | |
| 845 | fail_reg_read: |
| 846 | ath6kl_warn("Unable to read memory:%u\n", addr); |
| 847 | vfree(buf); |
| 848 | return -EIO; |
| 849 | } |
| 850 | |
| 851 | static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf, |
| 852 | size_t count, loff_t *ppos) |
| 853 | { |
| 854 | u8 *buf = file->private_data; |
| 855 | return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); |
| 856 | } |
| 857 | |
| 858 | static int ath6kl_regdump_release(struct inode *inode, struct file *file) |
| 859 | { |
| 860 | vfree(file->private_data); |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | static const struct file_operations fops_reg_dump = { |
| 865 | .open = ath6kl_regdump_open, |
| 866 | .read = ath6kl_regdump_read, |
| 867 | .release = ath6kl_regdump_release, |
| 868 | .owner = THIS_MODULE, |
| 869 | .llseek = default_llseek, |
| 870 | }; |
| 871 | |
Vivek Natarajan | e509044 | 2011-08-31 15:02:19 +0530 | [diff] [blame] | 872 | static ssize_t ath6kl_lrssi_roam_write(struct file *file, |
| 873 | const char __user *user_buf, |
| 874 | size_t count, loff_t *ppos) |
| 875 | { |
| 876 | struct ath6kl *ar = file->private_data; |
| 877 | unsigned long lrssi_roam_threshold; |
| 878 | char buf[32]; |
| 879 | ssize_t len; |
| 880 | |
| 881 | len = min(count, sizeof(buf) - 1); |
| 882 | if (copy_from_user(buf, user_buf, len)) |
| 883 | return -EFAULT; |
| 884 | |
| 885 | buf[len] = '\0'; |
| 886 | if (strict_strtoul(buf, 0, &lrssi_roam_threshold)) |
| 887 | return -EINVAL; |
| 888 | |
| 889 | ar->lrssi_roam_threshold = lrssi_roam_threshold; |
| 890 | |
| 891 | ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold); |
| 892 | |
| 893 | return count; |
| 894 | } |
| 895 | |
| 896 | static ssize_t ath6kl_lrssi_roam_read(struct file *file, |
| 897 | char __user *user_buf, |
| 898 | size_t count, loff_t *ppos) |
| 899 | { |
| 900 | struct ath6kl *ar = file->private_data; |
| 901 | char buf[32]; |
| 902 | unsigned int len; |
| 903 | |
| 904 | len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold); |
| 905 | |
| 906 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 907 | } |
| 908 | |
| 909 | static const struct file_operations fops_lrssi_roam_threshold = { |
| 910 | .read = ath6kl_lrssi_roam_read, |
| 911 | .write = ath6kl_lrssi_roam_write, |
| 912 | .open = ath6kl_debugfs_open, |
| 913 | .owner = THIS_MODULE, |
| 914 | .llseek = default_llseek, |
| 915 | }; |
| 916 | |
Vasanthakumar Thiagarajan | 252c068 | 2011-09-05 11:19:46 +0300 | [diff] [blame] | 917 | static ssize_t ath6kl_regwrite_read(struct file *file, |
| 918 | char __user *user_buf, |
| 919 | size_t count, loff_t *ppos) |
| 920 | { |
| 921 | struct ath6kl *ar = file->private_data; |
| 922 | u8 buf[32]; |
| 923 | unsigned int len = 0; |
| 924 | |
| 925 | len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n", |
| 926 | ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr); |
| 927 | |
| 928 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 929 | } |
| 930 | |
| 931 | static ssize_t ath6kl_regwrite_write(struct file *file, |
| 932 | const char __user *user_buf, |
| 933 | size_t count, loff_t *ppos) |
| 934 | { |
| 935 | struct ath6kl *ar = file->private_data; |
| 936 | char buf[32]; |
| 937 | char *sptr, *token; |
| 938 | unsigned int len = 0; |
| 939 | u32 reg_addr, reg_val; |
| 940 | |
| 941 | len = min(count, sizeof(buf) - 1); |
| 942 | if (copy_from_user(buf, user_buf, len)) |
| 943 | return -EFAULT; |
| 944 | |
| 945 | buf[len] = '\0'; |
| 946 | sptr = buf; |
| 947 | |
| 948 | token = strsep(&sptr, "="); |
| 949 | if (!token) |
| 950 | return -EINVAL; |
| 951 | |
| 952 | if (kstrtou32(token, 0, ®_addr)) |
| 953 | return -EINVAL; |
| 954 | |
| 955 | if (!ath6kl_dbg_is_diag_reg_valid(reg_addr)) |
| 956 | return -EINVAL; |
| 957 | |
| 958 | if (kstrtou32(sptr, 0, ®_val)) |
| 959 | return -EINVAL; |
| 960 | |
| 961 | ar->debug.diag_reg_addr_wr = reg_addr; |
| 962 | ar->debug.diag_reg_val_wr = reg_val; |
| 963 | |
| 964 | if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr, |
| 965 | cpu_to_le32(ar->debug.diag_reg_val_wr))) |
| 966 | return -EIO; |
| 967 | |
| 968 | return count; |
| 969 | } |
| 970 | |
| 971 | static const struct file_operations fops_diag_reg_write = { |
| 972 | .read = ath6kl_regwrite_read, |
| 973 | .write = ath6kl_regwrite_write, |
| 974 | .open = ath6kl_debugfs_open, |
| 975 | .owner = THIS_MODULE, |
| 976 | .llseek = default_llseek, |
| 977 | }; |
| 978 | |
Jouni Malinen | 4b28a80 | 2011-10-11 17:31:54 +0300 | [diff] [blame] | 979 | int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf, |
| 980 | size_t len) |
| 981 | { |
| 982 | const struct wmi_target_roam_tbl *tbl; |
| 983 | u16 num_entries; |
| 984 | |
| 985 | if (len < sizeof(*tbl)) |
| 986 | return -EINVAL; |
| 987 | |
| 988 | tbl = (const struct wmi_target_roam_tbl *) buf; |
| 989 | num_entries = le16_to_cpu(tbl->num_entries); |
| 990 | if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) > |
| 991 | len) |
| 992 | return -EINVAL; |
| 993 | |
| 994 | if (ar->debug.roam_tbl == NULL || |
| 995 | ar->debug.roam_tbl_len < (unsigned int) len) { |
| 996 | kfree(ar->debug.roam_tbl); |
| 997 | ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC); |
| 998 | if (ar->debug.roam_tbl == NULL) |
| 999 | return -ENOMEM; |
| 1000 | } |
| 1001 | |
| 1002 | memcpy(ar->debug.roam_tbl, buf, len); |
| 1003 | ar->debug.roam_tbl_len = len; |
| 1004 | |
| 1005 | if (test_bit(ROAM_TBL_PEND, &ar->flag)) { |
| 1006 | clear_bit(ROAM_TBL_PEND, &ar->flag); |
| 1007 | wake_up(&ar->event_wq); |
| 1008 | } |
| 1009 | |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf, |
| 1014 | size_t count, loff_t *ppos) |
| 1015 | { |
| 1016 | struct ath6kl *ar = file->private_data; |
| 1017 | int ret; |
| 1018 | long left; |
| 1019 | struct wmi_target_roam_tbl *tbl; |
| 1020 | u16 num_entries, i; |
| 1021 | char *buf; |
| 1022 | unsigned int len, buf_len; |
| 1023 | ssize_t ret_cnt; |
| 1024 | |
| 1025 | if (down_interruptible(&ar->sem)) |
| 1026 | return -EBUSY; |
| 1027 | |
| 1028 | set_bit(ROAM_TBL_PEND, &ar->flag); |
| 1029 | |
| 1030 | ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi); |
| 1031 | if (ret) { |
| 1032 | up(&ar->sem); |
| 1033 | return ret; |
| 1034 | } |
| 1035 | |
| 1036 | left = wait_event_interruptible_timeout( |
| 1037 | ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT); |
| 1038 | up(&ar->sem); |
| 1039 | |
| 1040 | if (left <= 0) |
| 1041 | return -ETIMEDOUT; |
| 1042 | |
| 1043 | if (ar->debug.roam_tbl == NULL) |
| 1044 | return -ENOMEM; |
| 1045 | |
| 1046 | tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl; |
| 1047 | num_entries = le16_to_cpu(tbl->num_entries); |
| 1048 | |
| 1049 | buf_len = 100 + num_entries * 100; |
| 1050 | buf = kzalloc(buf_len, GFP_KERNEL); |
| 1051 | if (buf == NULL) |
| 1052 | return -ENOMEM; |
| 1053 | len = 0; |
| 1054 | len += scnprintf(buf + len, buf_len - len, |
| 1055 | "roam_mode=%u\n\n" |
| 1056 | "# roam_util bssid rssi rssidt last_rssi util bias\n", |
| 1057 | le16_to_cpu(tbl->roam_mode)); |
| 1058 | |
| 1059 | for (i = 0; i < num_entries; i++) { |
| 1060 | struct wmi_bss_roam_info *info = &tbl->info[i]; |
| 1061 | len += scnprintf(buf + len, buf_len - len, |
| 1062 | "%d %pM %d %d %d %d %d\n", |
| 1063 | a_sle32_to_cpu(info->roam_util), info->bssid, |
| 1064 | info->rssi, info->rssidt, info->last_rssi, |
| 1065 | info->util, info->bias); |
| 1066 | } |
| 1067 | |
| 1068 | if (len > buf_len) |
| 1069 | len = buf_len; |
| 1070 | |
| 1071 | ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1072 | |
| 1073 | kfree(buf); |
| 1074 | return ret_cnt; |
| 1075 | } |
| 1076 | |
| 1077 | static const struct file_operations fops_roam_table = { |
| 1078 | .read = ath6kl_roam_table_read, |
| 1079 | .open = ath6kl_debugfs_open, |
| 1080 | .owner = THIS_MODULE, |
| 1081 | .llseek = default_llseek, |
| 1082 | }; |
| 1083 | |
Jouni Malinen | 1261875 | 2011-10-11 17:31:55 +0300 | [diff] [blame] | 1084 | static ssize_t ath6kl_force_roam_write(struct file *file, |
| 1085 | const char __user *user_buf, |
| 1086 | size_t count, loff_t *ppos) |
| 1087 | { |
| 1088 | struct ath6kl *ar = file->private_data; |
| 1089 | int ret; |
| 1090 | char buf[20]; |
| 1091 | size_t len; |
| 1092 | u8 bssid[ETH_ALEN]; |
| 1093 | int i; |
| 1094 | int addr[ETH_ALEN]; |
| 1095 | |
| 1096 | len = min(count, sizeof(buf) - 1); |
| 1097 | if (copy_from_user(buf, user_buf, len)) |
| 1098 | return -EFAULT; |
| 1099 | buf[len] = '\0'; |
| 1100 | |
| 1101 | if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 1102 | &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) |
| 1103 | != ETH_ALEN) |
| 1104 | return -EINVAL; |
| 1105 | for (i = 0; i < ETH_ALEN; i++) |
| 1106 | bssid[i] = addr[i]; |
| 1107 | |
| 1108 | ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid); |
| 1109 | if (ret) |
| 1110 | return ret; |
| 1111 | |
| 1112 | return count; |
| 1113 | } |
| 1114 | |
| 1115 | static const struct file_operations fops_force_roam = { |
| 1116 | .write = ath6kl_force_roam_write, |
| 1117 | .open = ath6kl_debugfs_open, |
| 1118 | .owner = THIS_MODULE, |
| 1119 | .llseek = default_llseek, |
| 1120 | }; |
| 1121 | |
| 1122 | static ssize_t ath6kl_roam_mode_write(struct file *file, |
| 1123 | const char __user *user_buf, |
| 1124 | size_t count, loff_t *ppos) |
| 1125 | { |
| 1126 | struct ath6kl *ar = file->private_data; |
| 1127 | int ret; |
| 1128 | char buf[20]; |
| 1129 | size_t len; |
| 1130 | enum wmi_roam_mode mode; |
| 1131 | |
| 1132 | len = min(count, sizeof(buf) - 1); |
| 1133 | if (copy_from_user(buf, user_buf, len)) |
| 1134 | return -EFAULT; |
| 1135 | buf[len] = '\0'; |
| 1136 | if (len > 0 && buf[len - 1] == '\n') |
| 1137 | buf[len - 1] = '\0'; |
| 1138 | |
| 1139 | if (strcasecmp(buf, "default") == 0) |
| 1140 | mode = WMI_DEFAULT_ROAM_MODE; |
| 1141 | else if (strcasecmp(buf, "bssbias") == 0) |
| 1142 | mode = WMI_HOST_BIAS_ROAM_MODE; |
| 1143 | else if (strcasecmp(buf, "lock") == 0) |
| 1144 | mode = WMI_LOCK_BSS_MODE; |
| 1145 | else |
| 1146 | return -EINVAL; |
| 1147 | |
| 1148 | ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode); |
| 1149 | if (ret) |
| 1150 | return ret; |
| 1151 | |
| 1152 | return count; |
| 1153 | } |
| 1154 | |
| 1155 | static const struct file_operations fops_roam_mode = { |
| 1156 | .write = ath6kl_roam_mode_write, |
| 1157 | .open = ath6kl_debugfs_open, |
| 1158 | .owner = THIS_MODULE, |
| 1159 | .llseek = default_llseek, |
| 1160 | }; |
| 1161 | |
Jouni Malinen | ff0b007 | 2011-10-11 17:31:56 +0300 | [diff] [blame] | 1162 | void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive) |
| 1163 | { |
| 1164 | ar->debug.keepalive = keepalive; |
| 1165 | } |
| 1166 | |
| 1167 | static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf, |
| 1168 | size_t count, loff_t *ppos) |
| 1169 | { |
| 1170 | struct ath6kl *ar = file->private_data; |
| 1171 | char buf[16]; |
| 1172 | int len; |
| 1173 | |
| 1174 | len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive); |
| 1175 | |
| 1176 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1177 | } |
| 1178 | |
| 1179 | static ssize_t ath6kl_keepalive_write(struct file *file, |
| 1180 | const char __user *user_buf, |
| 1181 | size_t count, loff_t *ppos) |
| 1182 | { |
| 1183 | struct ath6kl *ar = file->private_data; |
| 1184 | int ret; |
| 1185 | u8 val; |
| 1186 | |
| 1187 | ret = kstrtou8_from_user(user_buf, count, 0, &val); |
| 1188 | if (ret) |
| 1189 | return ret; |
| 1190 | |
| 1191 | ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, val); |
| 1192 | if (ret) |
| 1193 | return ret; |
| 1194 | |
| 1195 | return count; |
| 1196 | } |
| 1197 | |
| 1198 | static const struct file_operations fops_keepalive = { |
| 1199 | .open = ath6kl_debugfs_open, |
| 1200 | .read = ath6kl_keepalive_read, |
| 1201 | .write = ath6kl_keepalive_write, |
| 1202 | .owner = THIS_MODULE, |
| 1203 | .llseek = default_llseek, |
| 1204 | }; |
| 1205 | |
| 1206 | void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout) |
| 1207 | { |
| 1208 | ar->debug.disc_timeout = timeout; |
| 1209 | } |
| 1210 | |
| 1211 | static ssize_t ath6kl_disconnect_timeout_read(struct file *file, |
| 1212 | char __user *user_buf, |
| 1213 | size_t count, loff_t *ppos) |
| 1214 | { |
| 1215 | struct ath6kl *ar = file->private_data; |
| 1216 | char buf[16]; |
| 1217 | int len; |
| 1218 | |
| 1219 | len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout); |
| 1220 | |
| 1221 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 1222 | } |
| 1223 | |
| 1224 | static ssize_t ath6kl_disconnect_timeout_write(struct file *file, |
| 1225 | const char __user *user_buf, |
| 1226 | size_t count, loff_t *ppos) |
| 1227 | { |
| 1228 | struct ath6kl *ar = file->private_data; |
| 1229 | int ret; |
| 1230 | u8 val; |
| 1231 | |
| 1232 | ret = kstrtou8_from_user(user_buf, count, 0, &val); |
| 1233 | if (ret) |
| 1234 | return ret; |
| 1235 | |
| 1236 | ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, val); |
| 1237 | if (ret) |
| 1238 | return ret; |
| 1239 | |
| 1240 | return count; |
| 1241 | } |
| 1242 | |
| 1243 | static const struct file_operations fops_disconnect_timeout = { |
| 1244 | .open = ath6kl_debugfs_open, |
| 1245 | .read = ath6kl_disconnect_timeout_read, |
| 1246 | .write = ath6kl_disconnect_timeout_write, |
| 1247 | .owner = THIS_MODULE, |
| 1248 | .llseek = default_llseek, |
| 1249 | }; |
| 1250 | |
Rishi Panjwani | 8fffd9e | 2011-10-14 17:48:07 -0700 | [diff] [blame] | 1251 | static ssize_t ath6kl_create_qos_write(struct file *file, |
| 1252 | const char __user *user_buf, |
| 1253 | size_t count, loff_t *ppos) |
| 1254 | { |
| 1255 | |
| 1256 | struct ath6kl *ar = file->private_data; |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1257 | struct ath6kl_vif *vif; |
Rishi Panjwani | 8fffd9e | 2011-10-14 17:48:07 -0700 | [diff] [blame] | 1258 | char buf[100]; |
| 1259 | ssize_t len; |
| 1260 | char *sptr, *token; |
| 1261 | struct wmi_create_pstream_cmd pstream; |
| 1262 | u32 val32; |
| 1263 | u16 val16; |
| 1264 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1265 | vif = ath6kl_vif_first(ar); |
| 1266 | if (!vif) |
| 1267 | return -EIO; |
| 1268 | |
Rishi Panjwani | 8fffd9e | 2011-10-14 17:48:07 -0700 | [diff] [blame] | 1269 | len = min(count, sizeof(buf) - 1); |
| 1270 | if (copy_from_user(buf, user_buf, len)) |
| 1271 | return -EFAULT; |
| 1272 | buf[len] = '\0'; |
| 1273 | sptr = buf; |
| 1274 | |
| 1275 | token = strsep(&sptr, " "); |
| 1276 | if (!token) |
| 1277 | return -EINVAL; |
| 1278 | if (kstrtou8(token, 0, &pstream.user_pri)) |
| 1279 | return -EINVAL; |
| 1280 | |
| 1281 | token = strsep(&sptr, " "); |
| 1282 | if (!token) |
| 1283 | return -EINVAL; |
| 1284 | if (kstrtou8(token, 0, &pstream.traffic_direc)) |
| 1285 | return -EINVAL; |
| 1286 | |
| 1287 | token = strsep(&sptr, " "); |
| 1288 | if (!token) |
| 1289 | return -EINVAL; |
| 1290 | if (kstrtou8(token, 0, &pstream.traffic_class)) |
| 1291 | return -EINVAL; |
| 1292 | |
| 1293 | token = strsep(&sptr, " "); |
| 1294 | if (!token) |
| 1295 | return -EINVAL; |
| 1296 | if (kstrtou8(token, 0, &pstream.traffic_type)) |
| 1297 | return -EINVAL; |
| 1298 | |
| 1299 | token = strsep(&sptr, " "); |
| 1300 | if (!token) |
| 1301 | return -EINVAL; |
| 1302 | if (kstrtou8(token, 0, &pstream.voice_psc_cap)) |
| 1303 | return -EINVAL; |
| 1304 | |
| 1305 | token = strsep(&sptr, " "); |
| 1306 | if (!token) |
| 1307 | return -EINVAL; |
| 1308 | if (kstrtou32(token, 0, &val32)) |
| 1309 | return -EINVAL; |
| 1310 | pstream.min_service_int = cpu_to_le32(val32); |
| 1311 | |
| 1312 | token = strsep(&sptr, " "); |
| 1313 | if (!token) |
| 1314 | return -EINVAL; |
| 1315 | if (kstrtou32(token, 0, &val32)) |
| 1316 | return -EINVAL; |
| 1317 | pstream.max_service_int = cpu_to_le32(val32); |
| 1318 | |
| 1319 | token = strsep(&sptr, " "); |
| 1320 | if (!token) |
| 1321 | return -EINVAL; |
| 1322 | if (kstrtou32(token, 0, &val32)) |
| 1323 | return -EINVAL; |
| 1324 | pstream.inactivity_int = cpu_to_le32(val32); |
| 1325 | |
| 1326 | token = strsep(&sptr, " "); |
| 1327 | if (!token) |
| 1328 | return -EINVAL; |
| 1329 | if (kstrtou32(token, 0, &val32)) |
| 1330 | return -EINVAL; |
| 1331 | pstream.suspension_int = cpu_to_le32(val32); |
| 1332 | |
| 1333 | token = strsep(&sptr, " "); |
| 1334 | if (!token) |
| 1335 | return -EINVAL; |
| 1336 | if (kstrtou32(token, 0, &val32)) |
| 1337 | return -EINVAL; |
| 1338 | pstream.service_start_time = cpu_to_le32(val32); |
| 1339 | |
| 1340 | token = strsep(&sptr, " "); |
| 1341 | if (!token) |
| 1342 | return -EINVAL; |
| 1343 | if (kstrtou8(token, 0, &pstream.tsid)) |
| 1344 | return -EINVAL; |
| 1345 | |
| 1346 | token = strsep(&sptr, " "); |
| 1347 | if (!token) |
| 1348 | return -EINVAL; |
| 1349 | if (kstrtou16(token, 0, &val16)) |
| 1350 | return -EINVAL; |
| 1351 | pstream.nominal_msdu = cpu_to_le16(val16); |
| 1352 | |
| 1353 | token = strsep(&sptr, " "); |
| 1354 | if (!token) |
| 1355 | return -EINVAL; |
| 1356 | if (kstrtou16(token, 0, &val16)) |
| 1357 | return -EINVAL; |
| 1358 | pstream.max_msdu = cpu_to_le16(val16); |
| 1359 | |
| 1360 | token = strsep(&sptr, " "); |
| 1361 | if (!token) |
| 1362 | return -EINVAL; |
| 1363 | if (kstrtou32(token, 0, &val32)) |
| 1364 | return -EINVAL; |
| 1365 | pstream.min_data_rate = cpu_to_le32(val32); |
| 1366 | |
| 1367 | token = strsep(&sptr, " "); |
| 1368 | if (!token) |
| 1369 | return -EINVAL; |
| 1370 | if (kstrtou32(token, 0, &val32)) |
| 1371 | return -EINVAL; |
| 1372 | pstream.mean_data_rate = cpu_to_le32(val32); |
| 1373 | |
| 1374 | token = strsep(&sptr, " "); |
| 1375 | if (!token) |
| 1376 | return -EINVAL; |
| 1377 | if (kstrtou32(token, 0, &val32)) |
| 1378 | return -EINVAL; |
| 1379 | pstream.peak_data_rate = cpu_to_le32(val32); |
| 1380 | |
| 1381 | token = strsep(&sptr, " "); |
| 1382 | if (!token) |
| 1383 | return -EINVAL; |
| 1384 | if (kstrtou32(token, 0, &val32)) |
| 1385 | return -EINVAL; |
| 1386 | pstream.max_burst_size = cpu_to_le32(val32); |
| 1387 | |
| 1388 | token = strsep(&sptr, " "); |
| 1389 | if (!token) |
| 1390 | return -EINVAL; |
| 1391 | if (kstrtou32(token, 0, &val32)) |
| 1392 | return -EINVAL; |
| 1393 | pstream.delay_bound = cpu_to_le32(val32); |
| 1394 | |
| 1395 | token = strsep(&sptr, " "); |
| 1396 | if (!token) |
| 1397 | return -EINVAL; |
| 1398 | if (kstrtou32(token, 0, &val32)) |
| 1399 | return -EINVAL; |
| 1400 | pstream.min_phy_rate = cpu_to_le32(val32); |
| 1401 | |
| 1402 | token = strsep(&sptr, " "); |
| 1403 | if (!token) |
| 1404 | return -EINVAL; |
| 1405 | if (kstrtou32(token, 0, &val32)) |
| 1406 | return -EINVAL; |
| 1407 | pstream.sba = cpu_to_le32(val32); |
| 1408 | |
| 1409 | token = strsep(&sptr, " "); |
| 1410 | if (!token) |
| 1411 | return -EINVAL; |
| 1412 | if (kstrtou32(token, 0, &val32)) |
| 1413 | return -EINVAL; |
| 1414 | pstream.medium_time = cpu_to_le32(val32); |
| 1415 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1416 | ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream); |
Rishi Panjwani | 8fffd9e | 2011-10-14 17:48:07 -0700 | [diff] [blame] | 1417 | |
| 1418 | return count; |
| 1419 | } |
| 1420 | |
| 1421 | static const struct file_operations fops_create_qos = { |
| 1422 | .write = ath6kl_create_qos_write, |
| 1423 | .open = ath6kl_debugfs_open, |
| 1424 | .owner = THIS_MODULE, |
| 1425 | .llseek = default_llseek, |
| 1426 | }; |
| 1427 | |
| 1428 | static ssize_t ath6kl_delete_qos_write(struct file *file, |
| 1429 | const char __user *user_buf, |
| 1430 | size_t count, loff_t *ppos) |
| 1431 | { |
| 1432 | |
| 1433 | struct ath6kl *ar = file->private_data; |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1434 | struct ath6kl_vif *vif; |
Rishi Panjwani | 8fffd9e | 2011-10-14 17:48:07 -0700 | [diff] [blame] | 1435 | char buf[100]; |
| 1436 | ssize_t len; |
| 1437 | char *sptr, *token; |
| 1438 | u8 traffic_class; |
| 1439 | u8 tsid; |
| 1440 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1441 | vif = ath6kl_vif_first(ar); |
| 1442 | if (!vif) |
| 1443 | return -EIO; |
| 1444 | |
Rishi Panjwani | 8fffd9e | 2011-10-14 17:48:07 -0700 | [diff] [blame] | 1445 | len = min(count, sizeof(buf) - 1); |
| 1446 | if (copy_from_user(buf, user_buf, len)) |
| 1447 | return -EFAULT; |
| 1448 | buf[len] = '\0'; |
| 1449 | sptr = buf; |
| 1450 | |
| 1451 | token = strsep(&sptr, " "); |
| 1452 | if (!token) |
| 1453 | return -EINVAL; |
| 1454 | if (kstrtou8(token, 0, &traffic_class)) |
| 1455 | return -EINVAL; |
| 1456 | |
| 1457 | token = strsep(&sptr, " "); |
| 1458 | if (!token) |
| 1459 | return -EINVAL; |
| 1460 | if (kstrtou8(token, 0, &tsid)) |
| 1461 | return -EINVAL; |
| 1462 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1463 | ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx, |
| 1464 | traffic_class, tsid); |
Rishi Panjwani | 8fffd9e | 2011-10-14 17:48:07 -0700 | [diff] [blame] | 1465 | |
| 1466 | return count; |
| 1467 | } |
| 1468 | |
| 1469 | static const struct file_operations fops_delete_qos = { |
| 1470 | .write = ath6kl_delete_qos_write, |
| 1471 | .open = ath6kl_debugfs_open, |
| 1472 | .owner = THIS_MODULE, |
| 1473 | .llseek = default_llseek, |
| 1474 | }; |
| 1475 | |
Rishi Panjwani | 116b3a2 | 2011-10-18 17:20:06 -0700 | [diff] [blame] | 1476 | static ssize_t ath6kl_bgscan_int_write(struct file *file, |
| 1477 | const char __user *user_buf, |
| 1478 | size_t count, loff_t *ppos) |
| 1479 | { |
| 1480 | struct ath6kl *ar = file->private_data; |
| 1481 | u16 bgscan_int; |
| 1482 | char buf[32]; |
| 1483 | ssize_t len; |
| 1484 | |
| 1485 | len = min(count, sizeof(buf) - 1); |
| 1486 | if (copy_from_user(buf, user_buf, len)) |
| 1487 | return -EFAULT; |
| 1488 | |
| 1489 | buf[len] = '\0'; |
| 1490 | if (kstrtou16(buf, 0, &bgscan_int)) |
| 1491 | return -EINVAL; |
| 1492 | |
| 1493 | if (bgscan_int == 0) |
| 1494 | bgscan_int = 0xffff; |
| 1495 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1496 | ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3, |
Rishi Panjwani | 116b3a2 | 2011-10-18 17:20:06 -0700 | [diff] [blame] | 1497 | 0, 0, 0); |
| 1498 | |
| 1499 | return count; |
| 1500 | } |
| 1501 | |
| 1502 | static const struct file_operations fops_bgscan_int = { |
| 1503 | .write = ath6kl_bgscan_int_write, |
| 1504 | .open = ath6kl_debugfs_open, |
| 1505 | .owner = THIS_MODULE, |
| 1506 | .llseek = default_llseek, |
| 1507 | }; |
| 1508 | |
Vasanthakumar Thiagarajan | d999ba3 | 2011-08-26 13:06:31 +0530 | [diff] [blame] | 1509 | int ath6kl_debug_init(struct ath6kl *ar) |
| 1510 | { |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 1511 | ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE); |
| 1512 | if (ar->debug.fwlog_buf.buf == NULL) |
| 1513 | return -ENOMEM; |
| 1514 | |
| 1515 | ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL); |
| 1516 | if (ar->debug.fwlog_tmp == NULL) { |
| 1517 | vfree(ar->debug.fwlog_buf.buf); |
| 1518 | return -ENOMEM; |
| 1519 | } |
| 1520 | |
| 1521 | spin_lock_init(&ar->debug.fwlog_lock); |
| 1522 | |
Kalle Valo | 939f1cc | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 1523 | /* |
| 1524 | * Actually we are lying here but don't know how to read the mask |
| 1525 | * value from the firmware. |
| 1526 | */ |
| 1527 | ar->debug.fwlog_mask = 0; |
| 1528 | |
Vasanthakumar Thiagarajan | d999ba3 | 2011-08-26 13:06:31 +0530 | [diff] [blame] | 1529 | ar->debugfs_phy = debugfs_create_dir("ath6kl", |
Vasanthakumar Thiagarajan | be98e3a | 2011-10-25 19:33:57 +0530 | [diff] [blame] | 1530 | ar->wiphy->debugfsdir); |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 1531 | if (!ar->debugfs_phy) { |
| 1532 | vfree(ar->debug.fwlog_buf.buf); |
| 1533 | kfree(ar->debug.fwlog_tmp); |
Vasanthakumar Thiagarajan | d999ba3 | 2011-08-26 13:06:31 +0530 | [diff] [blame] | 1534 | return -ENOMEM; |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 1535 | } |
Vasanthakumar Thiagarajan | d999ba3 | 2011-08-26 13:06:31 +0530 | [diff] [blame] | 1536 | |
Vasanthakumar Thiagarajan | 03f68a9 | 2011-08-26 13:06:32 +0530 | [diff] [blame] | 1537 | debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar, |
| 1538 | &fops_tgt_stats); |
| 1539 | |
Vasanthakumar Thiagarajan | 78fc485 | 2011-08-26 13:06:33 +0530 | [diff] [blame] | 1540 | debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar, |
| 1541 | &fops_credit_dist_stats); |
| 1542 | |
Jouni Malinen | e809128 | 2011-10-11 17:31:53 +0300 | [diff] [blame] | 1543 | debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR, |
| 1544 | ar->debugfs_phy, ar, &fops_endpoint_stats); |
| 1545 | |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 1546 | debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar, |
| 1547 | &fops_fwlog); |
| 1548 | |
Kalle Valo | 939f1cc | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 1549 | debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy, |
| 1550 | ar, &fops_fwlog_mask); |
| 1551 | |
Vasanthakumar Thiagarajan | 91d57de | 2011-09-02 10:40:06 +0300 | [diff] [blame] | 1552 | debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar, |
| 1553 | &fops_diag_reg_read); |
| 1554 | |
| 1555 | debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar, |
| 1556 | &fops_reg_dump); |
| 1557 | |
Vivek Natarajan | e509044 | 2011-08-31 15:02:19 +0530 | [diff] [blame] | 1558 | debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR, |
| 1559 | ar->debugfs_phy, ar, &fops_lrssi_roam_threshold); |
Vasanthakumar Thiagarajan | 252c068 | 2011-09-05 11:19:46 +0300 | [diff] [blame] | 1560 | |
| 1561 | debugfs_create_file("reg_write", S_IRUSR | S_IWUSR, |
| 1562 | ar->debugfs_phy, ar, &fops_diag_reg_write); |
| 1563 | |
Kalle Valo | 9a73083 | 2011-09-27 23:33:28 +0300 | [diff] [blame] | 1564 | debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar, |
| 1565 | &fops_war_stats); |
| 1566 | |
Jouni Malinen | 4b28a80 | 2011-10-11 17:31:54 +0300 | [diff] [blame] | 1567 | debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar, |
| 1568 | &fops_roam_table); |
| 1569 | |
Jouni Malinen | 1261875 | 2011-10-11 17:31:55 +0300 | [diff] [blame] | 1570 | debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar, |
| 1571 | &fops_force_roam); |
| 1572 | |
| 1573 | debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar, |
| 1574 | &fops_roam_mode); |
| 1575 | |
Jouni Malinen | ff0b007 | 2011-10-11 17:31:56 +0300 | [diff] [blame] | 1576 | debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar, |
| 1577 | &fops_keepalive); |
| 1578 | |
| 1579 | debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR, |
| 1580 | ar->debugfs_phy, ar, &fops_disconnect_timeout); |
| 1581 | |
Rishi Panjwani | 8fffd9e | 2011-10-14 17:48:07 -0700 | [diff] [blame] | 1582 | debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar, |
| 1583 | &fops_create_qos); |
| 1584 | |
| 1585 | debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar, |
| 1586 | &fops_delete_qos); |
| 1587 | |
Rishi Panjwani | 116b3a2 | 2011-10-18 17:20:06 -0700 | [diff] [blame] | 1588 | debugfs_create_file("bgscan_interval", S_IWUSR, |
| 1589 | ar->debugfs_phy, ar, &fops_bgscan_int); |
| 1590 | |
Vasanthakumar Thiagarajan | d999ba3 | 2011-08-26 13:06:31 +0530 | [diff] [blame] | 1591 | return 0; |
| 1592 | } |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 1593 | |
| 1594 | void ath6kl_debug_cleanup(struct ath6kl *ar) |
| 1595 | { |
| 1596 | vfree(ar->debug.fwlog_buf.buf); |
| 1597 | kfree(ar->debug.fwlog_tmp); |
Jouni Malinen | 4b28a80 | 2011-10-11 17:31:54 +0300 | [diff] [blame] | 1598 | kfree(ar->debug.roam_tbl); |
Kalle Valo | bdf5396 | 2011-09-02 10:32:04 +0300 | [diff] [blame] | 1599 | } |
| 1600 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1601 | #endif |