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