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