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