]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/wireless/ath/ath6kl/debug.c
ath6kl: Fix endpoint_stats debugfs buffer length calculation
[karo-tx-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_SEND, "ctxt:%p dist:%p\n",
184                    target->cred_dist_cntxt, NULL);
185         ath6kl_dbg(ATH6KL_DBG_TRC, "credit distribution, total : %d, free : %d\n",
186                    target->cred_dist_cntxt->total_avail_credits,
187                    target->cred_dist_cntxt->cur_free_credits);
188 }
189
190 static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
191 {
192         file->private_data = inode->i_private;
193         return 0;
194 }
195
196 void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
197 {
198         switch (war) {
199         case ATH6KL_WAR_INVALID_RATE:
200                 ar->debug.war_stats.invalid_rate++;
201                 break;
202         }
203 }
204
205 static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
206                                    size_t count, loff_t *ppos)
207 {
208         struct ath6kl *ar = file->private_data;
209         char *buf;
210         unsigned int len = 0, buf_len = 1500;
211         ssize_t ret_cnt;
212
213         buf = kzalloc(buf_len, GFP_KERNEL);
214         if (!buf)
215                 return -ENOMEM;
216
217         len += scnprintf(buf + len, buf_len - len, "\n");
218         len += scnprintf(buf + len, buf_len - len, "%25s\n",
219                          "Workaround stats");
220         len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
221                          "=================");
222         len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
223                          "Invalid rates", ar->debug.war_stats.invalid_rate);
224
225         if (WARN_ON(len > buf_len))
226                 len = buf_len;
227
228         ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
229
230         kfree(buf);
231         return ret_cnt;
232 }
233
234 static const struct file_operations fops_war_stats = {
235         .read = read_file_war_stats,
236         .open = ath6kl_debugfs_open,
237         .owner = THIS_MODULE,
238         .llseek = default_llseek,
239 };
240
241 static void ath6kl_debug_fwlog_add(struct ath6kl *ar, const void *buf,
242                                    size_t buf_len)
243 {
244         struct circ_buf *fwlog = &ar->debug.fwlog_buf;
245         size_t space;
246         int i;
247
248         /* entries must all be equal size */
249         if (WARN_ON(buf_len != ATH6KL_FWLOG_SLOT_SIZE))
250                 return;
251
252         space = CIRC_SPACE(fwlog->head, fwlog->tail, ATH6KL_FWLOG_SIZE);
253         if (space < buf_len)
254                 /* discard oldest slot */
255                 fwlog->tail = (fwlog->tail + ATH6KL_FWLOG_SLOT_SIZE) &
256                         (ATH6KL_FWLOG_SIZE - 1);
257
258         for (i = 0; i < buf_len; i += space) {
259                 space = CIRC_SPACE_TO_END(fwlog->head, fwlog->tail,
260                                           ATH6KL_FWLOG_SIZE);
261
262                 if ((size_t) space > buf_len - i)
263                         space = buf_len - i;
264
265                 memcpy(&fwlog->buf[fwlog->head], buf, space);
266                 fwlog->head = (fwlog->head + space) & (ATH6KL_FWLOG_SIZE - 1);
267         }
268
269 }
270
271 void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
272 {
273         struct ath6kl_fwlog_slot *slot = ar->debug.fwlog_tmp;
274         size_t slot_len;
275
276         if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
277                 return;
278
279         spin_lock_bh(&ar->debug.fwlog_lock);
280
281         slot->timestamp = cpu_to_le32(jiffies);
282         slot->length = cpu_to_le32(len);
283         memcpy(slot->payload, buf, len);
284
285         slot_len = sizeof(*slot) + len;
286
287         if (slot_len < ATH6KL_FWLOG_SLOT_SIZE)
288                 memset(slot->payload + len, 0,
289                        ATH6KL_FWLOG_SLOT_SIZE - slot_len);
290
291         ath6kl_debug_fwlog_add(ar, slot, ATH6KL_FWLOG_SLOT_SIZE);
292
293         spin_unlock_bh(&ar->debug.fwlog_lock);
294 }
295
296 static bool ath6kl_debug_fwlog_empty(struct ath6kl *ar)
297 {
298         return CIRC_CNT(ar->debug.fwlog_buf.head,
299                         ar->debug.fwlog_buf.tail,
300                         ATH6KL_FWLOG_SLOT_SIZE) == 0;
301 }
302
303 static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
304                                  size_t count, loff_t *ppos)
305 {
306         struct ath6kl *ar = file->private_data;
307         struct circ_buf *fwlog = &ar->debug.fwlog_buf;
308         size_t len = 0, buf_len = count;
309         ssize_t ret_cnt;
310         char *buf;
311         int ccnt;
312
313         buf = vmalloc(buf_len);
314         if (!buf)
315                 return -ENOMEM;
316
317         /* read undelivered logs from firmware */
318         ath6kl_read_fwlogs(ar);
319
320         spin_lock_bh(&ar->debug.fwlog_lock);
321
322         while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) {
323                 ccnt = CIRC_CNT_TO_END(fwlog->head, fwlog->tail,
324                                        ATH6KL_FWLOG_SIZE);
325
326                 if ((size_t) ccnt > buf_len - len)
327                         ccnt = buf_len - len;
328
329                 memcpy(buf + len, &fwlog->buf[fwlog->tail], ccnt);
330                 len += ccnt;
331
332                 fwlog->tail = (fwlog->tail + ccnt) &
333                         (ATH6KL_FWLOG_SIZE - 1);
334         }
335
336         spin_unlock_bh(&ar->debug.fwlog_lock);
337
338         if (WARN_ON(len > buf_len))
339                 len = buf_len;
340
341         ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
342
343         vfree(buf);
344
345         return ret_cnt;
346 }
347
348 static const struct file_operations fops_fwlog = {
349         .open = ath6kl_debugfs_open,
350         .read = ath6kl_fwlog_read,
351         .owner = THIS_MODULE,
352         .llseek = default_llseek,
353 };
354
355 static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
356                                       size_t count, loff_t *ppos)
357 {
358         struct ath6kl *ar = file->private_data;
359         char buf[16];
360         int len;
361
362         len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
363
364         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
365 }
366
367 static ssize_t ath6kl_fwlog_mask_write(struct file *file,
368                                        const char __user *user_buf,
369                                        size_t count, loff_t *ppos)
370 {
371         struct ath6kl *ar = file->private_data;
372         int ret;
373
374         ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
375         if (ret)
376                 return ret;
377
378         ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
379                                                  ATH6KL_FWLOG_VALID_MASK,
380                                                  ar->debug.fwlog_mask);
381         if (ret)
382                 return ret;
383
384         return count;
385 }
386
387 static const struct file_operations fops_fwlog_mask = {
388         .open = ath6kl_debugfs_open,
389         .read = ath6kl_fwlog_mask_read,
390         .write = ath6kl_fwlog_mask_write,
391         .owner = THIS_MODULE,
392         .llseek = default_llseek,
393 };
394
395 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
396                                    size_t count, loff_t *ppos)
397 {
398         struct ath6kl *ar = file->private_data;
399         struct target_stats *tgt_stats = &ar->target_stats;
400         char *buf;
401         unsigned int len = 0, buf_len = 1500;
402         int i;
403         long left;
404         ssize_t ret_cnt;
405
406         buf = kzalloc(buf_len, GFP_KERNEL);
407         if (!buf)
408                 return -ENOMEM;
409
410         if (down_interruptible(&ar->sem)) {
411                 kfree(buf);
412                 return -EBUSY;
413         }
414
415         set_bit(STATS_UPDATE_PEND, &ar->flag);
416
417         if (ath6kl_wmi_get_stats_cmd(ar->wmi)) {
418                 up(&ar->sem);
419                 kfree(buf);
420                 return -EIO;
421         }
422
423         left = wait_event_interruptible_timeout(ar->event_wq,
424                                                 !test_bit(STATS_UPDATE_PEND,
425                                                 &ar->flag), WMI_TIMEOUT);
426
427         up(&ar->sem);
428
429         if (left <= 0) {
430                 kfree(buf);
431                 return -ETIMEDOUT;
432         }
433
434         len += scnprintf(buf + len, buf_len - len, "\n");
435         len += scnprintf(buf + len, buf_len - len, "%25s\n",
436                          "Target Tx stats");
437         len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
438                          "=================");
439         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
440                          "Ucast packets", tgt_stats->tx_ucast_pkt);
441         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
442                          "Bcast packets", tgt_stats->tx_bcast_pkt);
443         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
444                          "Ucast byte", tgt_stats->tx_ucast_byte);
445         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
446                          "Bcast byte", tgt_stats->tx_bcast_byte);
447         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
448                          "Rts success cnt", tgt_stats->tx_rts_success_cnt);
449         for (i = 0; i < 4; i++)
450                 len += scnprintf(buf + len, buf_len - len,
451                                  "%18s %d %10llu\n", "PER on ac",
452                                  i, tgt_stats->tx_pkt_per_ac[i]);
453         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
454                          "Error", tgt_stats->tx_err);
455         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
456                          "Fail count", tgt_stats->tx_fail_cnt);
457         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
458                          "Retry count", tgt_stats->tx_retry_cnt);
459         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
460                          "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
461         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
462                          "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
463         len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
464                          "TKIP counter measure used",
465                          tgt_stats->tkip_cnter_measures_invoked);
466
467         len += scnprintf(buf + len, buf_len - len, "%25s\n",
468                          "Target Rx stats");
469         len += scnprintf(buf + len, buf_len - len, "%25s\n",
470                          "=================");
471
472         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
473                          "Ucast packets", tgt_stats->rx_ucast_pkt);
474         len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
475                          "Ucast Rate", tgt_stats->rx_ucast_rate);
476         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
477                          "Bcast packets", tgt_stats->rx_bcast_pkt);
478         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
479                          "Ucast byte", tgt_stats->rx_ucast_byte);
480         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
481                          "Bcast byte", tgt_stats->rx_bcast_byte);
482         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
483                          "Fragmented pkt", tgt_stats->rx_frgment_pkt);
484         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
485                          "Error", tgt_stats->rx_err);
486         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
487                          "CRC Err", tgt_stats->rx_crc_err);
488         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
489                          "Key chache miss", tgt_stats->rx_key_cache_miss);
490         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
491                          "Decrypt Err", tgt_stats->rx_decrypt_err);
492         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
493                          "Duplicate frame", tgt_stats->rx_dupl_frame);
494         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
495                          "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
496         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
497                          "TKIP format err", tgt_stats->tkip_fmt_err);
498         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
499                          "CCMP format Err", tgt_stats->ccmp_fmt_err);
500         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
501                          "CCMP Replay Err", tgt_stats->ccmp_replays);
502
503         len += scnprintf(buf + len, buf_len - len, "%25s\n",
504                          "Misc Target stats");
505         len += scnprintf(buf + len, buf_len - len, "%25s\n",
506                          "=================");
507         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
508                          "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
509         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
510                          "Num Connects", tgt_stats->cs_connect_cnt);
511         len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
512                          "Num disconnects", tgt_stats->cs_discon_cnt);
513         len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
514                          "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
515
516         if (len > buf_len)
517                 len = buf_len;
518
519         ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
520
521         kfree(buf);
522         return ret_cnt;
523 }
524
525 static const struct file_operations fops_tgt_stats = {
526         .read = read_file_tgt_stats,
527         .open = ath6kl_debugfs_open,
528         .owner = THIS_MODULE,
529         .llseek = default_llseek,
530 };
531
532 #define print_credit_info(fmt_str, ep_list_field)               \
533         (len += scnprintf(buf + len, buf_len - len, fmt_str,    \
534                          ep_list->ep_list_field))
535 #define CREDIT_INFO_DISPLAY_STRING_LEN  200
536 #define CREDIT_INFO_LEN 128
537
538 static ssize_t read_file_credit_dist_stats(struct file *file,
539                                            char __user *user_buf,
540                                            size_t count, loff_t *ppos)
541 {
542         struct ath6kl *ar = file->private_data;
543         struct htc_target *target = ar->htc_target;
544         struct htc_endpoint_credit_dist *ep_list;
545         char *buf;
546         unsigned int buf_len, len = 0;
547         ssize_t ret_cnt;
548
549         buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
550                   get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
551         buf = kzalloc(buf_len, GFP_KERNEL);
552         if (!buf)
553                 return -ENOMEM;
554
555         len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
556                          "Total Avail Credits: ",
557                          target->cred_dist_cntxt->total_avail_credits);
558         len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
559                          "Free credits :",
560                          target->cred_dist_cntxt->cur_free_credits);
561
562         len += scnprintf(buf + len, buf_len - len,
563                          " Epid  Flags    Cred_norm  Cred_min  Credits  Cred_assngd"
564                          "  Seek_cred  Cred_sz  Cred_per_msg  Cred_to_dist"
565                          "  qdepth\n");
566
567         list_for_each_entry(ep_list, &target->cred_dist_list, list) {
568                 print_credit_info("  %2d", endpoint);
569                 print_credit_info("%10x", dist_flags);
570                 print_credit_info("%8d", cred_norm);
571                 print_credit_info("%9d", cred_min);
572                 print_credit_info("%9d", credits);
573                 print_credit_info("%10d", cred_assngd);
574                 print_credit_info("%13d", seek_cred);
575                 print_credit_info("%12d", cred_sz);
576                 print_credit_info("%9d", cred_per_msg);
577                 print_credit_info("%14d", cred_to_dist);
578                 len += scnprintf(buf + len, buf_len - len, "%12d\n",
579                                  get_queue_depth(&((struct htc_endpoint *)
580                                                  ep_list->htc_rsvd)->txq));
581         }
582
583         if (len > buf_len)
584                 len = buf_len;
585
586         ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
587         kfree(buf);
588         return ret_cnt;
589 }
590
591 static const struct file_operations fops_credit_dist_stats = {
592         .read = read_file_credit_dist_stats,
593         .open = ath6kl_debugfs_open,
594         .owner = THIS_MODULE,
595         .llseek = default_llseek,
596 };
597
598 static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
599                                         unsigned int buf_len, unsigned int len,
600                                         int offset, const char *name)
601 {
602         int i;
603         struct htc_endpoint_stats *ep_st;
604         u32 *counter;
605
606         len += scnprintf(buf + len, buf_len - len, "%s:", name);
607         for (i = 0; i < ENDPOINT_MAX; i++) {
608                 ep_st = &target->endpoint[i].ep_st;
609                 counter = ((u32 *) ep_st) + (offset / 4);
610                 len += scnprintf(buf + len, buf_len - len, " %u", *counter);
611         }
612         len += scnprintf(buf + len, buf_len - len, "\n");
613
614         return len;
615 }
616
617 static ssize_t ath6kl_endpoint_stats_read(struct file *file,
618                                           char __user *user_buf,
619                                           size_t count, loff_t *ppos)
620 {
621         struct ath6kl *ar = file->private_data;
622         struct htc_target *target = ar->htc_target;
623         char *buf;
624         unsigned int buf_len, len = 0;
625         ssize_t ret_cnt;
626
627         buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
628                 (25 + ENDPOINT_MAX * 11);
629         buf = kmalloc(buf_len, GFP_KERNEL);
630         if (!buf)
631                 return -ENOMEM;
632
633 #define EPSTAT(name)                                                    \
634         len = print_endpoint_stat(target, buf, buf_len, len,            \
635                                   offsetof(struct htc_endpoint_stats, name), \
636                                   #name)
637         EPSTAT(cred_low_indicate);
638         EPSTAT(tx_issued);
639         EPSTAT(tx_pkt_bundled);
640         EPSTAT(tx_bundles);
641         EPSTAT(tx_dropped);
642         EPSTAT(tx_cred_rpt);
643         EPSTAT(cred_rpt_from_rx);
644         EPSTAT(cred_rpt_from_other);
645         EPSTAT(cred_rpt_ep0);
646         EPSTAT(cred_from_rx);
647         EPSTAT(cred_from_other);
648         EPSTAT(cred_from_ep0);
649         EPSTAT(cred_cosumd);
650         EPSTAT(cred_retnd);
651         EPSTAT(rx_pkts);
652         EPSTAT(rx_lkahds);
653         EPSTAT(rx_bundl);
654         EPSTAT(rx_bundle_lkahd);
655         EPSTAT(rx_bundle_from_hdr);
656         EPSTAT(rx_alloc_thresh_hit);
657         EPSTAT(rxalloc_thresh_byte);
658 #undef EPSTAT
659
660         if (len > buf_len)
661                 len = buf_len;
662
663         ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
664         kfree(buf);
665         return ret_cnt;
666 }
667
668 static ssize_t ath6kl_endpoint_stats_write(struct file *file,
669                                            const char __user *user_buf,
670                                            size_t count, loff_t *ppos)
671 {
672         struct ath6kl *ar = file->private_data;
673         struct htc_target *target = ar->htc_target;
674         int ret, i;
675         u32 val;
676         struct htc_endpoint_stats *ep_st;
677
678         ret = kstrtou32_from_user(user_buf, count, 0, &val);
679         if (ret)
680                 return ret;
681         if (val == 0) {
682                 for (i = 0; i < ENDPOINT_MAX; i++) {
683                         ep_st = &target->endpoint[i].ep_st;
684                         memset(ep_st, 0, sizeof(*ep_st));
685                 }
686         }
687
688         return count;
689 }
690
691 static const struct file_operations fops_endpoint_stats = {
692         .open = ath6kl_debugfs_open,
693         .read = ath6kl_endpoint_stats_read,
694         .write = ath6kl_endpoint_stats_write,
695         .owner = THIS_MODULE,
696         .llseek = default_llseek,
697 };
698
699 static unsigned long ath6kl_get_num_reg(void)
700 {
701         int i;
702         unsigned long n_reg = 0;
703
704         for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
705                 n_reg = n_reg +
706                      (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
707
708         return n_reg;
709 }
710
711 static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
712 {
713         int i;
714
715         for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
716                 if (reg_addr >= diag_reg[i].reg_start &&
717                     reg_addr <= diag_reg[i].reg_end)
718                         return true;
719         }
720
721         return false;
722 }
723
724 static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
725                                     size_t count, loff_t *ppos)
726 {
727         struct ath6kl *ar = file->private_data;
728         u8 buf[50];
729         unsigned int len = 0;
730
731         if (ar->debug.dbgfs_diag_reg)
732                 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
733                                 ar->debug.dbgfs_diag_reg);
734         else
735                 len += scnprintf(buf + len, sizeof(buf) - len,
736                                  "All diag registers\n");
737
738         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
739 }
740
741 static ssize_t ath6kl_regread_write(struct file *file,
742                                     const char __user *user_buf,
743                                     size_t count, loff_t *ppos)
744 {
745         struct ath6kl *ar = file->private_data;
746         u8 buf[50];
747         unsigned int len;
748         unsigned long reg_addr;
749
750         len = min(count, sizeof(buf) - 1);
751         if (copy_from_user(buf, user_buf, len))
752                 return -EFAULT;
753
754         buf[len] = '\0';
755
756         if (strict_strtoul(buf, 0, &reg_addr))
757                 return -EINVAL;
758
759         if ((reg_addr % 4) != 0)
760                 return -EINVAL;
761
762         if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
763                 return -EINVAL;
764
765         ar->debug.dbgfs_diag_reg = reg_addr;
766
767         return count;
768 }
769
770 static const struct file_operations fops_diag_reg_read = {
771         .read = ath6kl_regread_read,
772         .write = ath6kl_regread_write,
773         .open = ath6kl_debugfs_open,
774         .owner = THIS_MODULE,
775         .llseek = default_llseek,
776 };
777
778 static int ath6kl_regdump_open(struct inode *inode, struct file *file)
779 {
780         struct ath6kl *ar = inode->i_private;
781         u8 *buf;
782         unsigned long int reg_len;
783         unsigned int len = 0, n_reg;
784         u32 addr;
785         __le32 reg_val;
786         int i, status;
787
788         /* Dump all the registers if no register is specified */
789         if (!ar->debug.dbgfs_diag_reg)
790                 n_reg = ath6kl_get_num_reg();
791         else
792                 n_reg = 1;
793
794         reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
795         if (n_reg > 1)
796                 reg_len += REGTYPE_STR_LEN;
797
798         buf = vmalloc(reg_len);
799         if (!buf)
800                 return -ENOMEM;
801
802         if (n_reg == 1) {
803                 addr = ar->debug.dbgfs_diag_reg;
804
805                 status = ath6kl_diag_read32(ar,
806                                 TARG_VTOP(ar->target_type, addr),
807                                 (u32 *)&reg_val);
808                 if (status)
809                         goto fail_reg_read;
810
811                 len += scnprintf(buf + len, reg_len - len,
812                                  "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
813                 goto done;
814         }
815
816         for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
817                 len += scnprintf(buf + len, reg_len - len,
818                                 "%s\n", diag_reg[i].reg_info);
819                 for (addr = diag_reg[i].reg_start;
820                      addr <= diag_reg[i].reg_end; addr += 4) {
821                         status = ath6kl_diag_read32(ar,
822                                         TARG_VTOP(ar->target_type, addr),
823                                         (u32 *)&reg_val);
824                         if (status)
825                                 goto fail_reg_read;
826
827                         len += scnprintf(buf + len, reg_len - len,
828                                         "0x%06x 0x%08x\n",
829                                         addr, le32_to_cpu(reg_val));
830                 }
831         }
832
833 done:
834         file->private_data = buf;
835         return 0;
836
837 fail_reg_read:
838         ath6kl_warn("Unable to read memory:%u\n", addr);
839         vfree(buf);
840         return -EIO;
841 }
842
843 static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
844                                   size_t count, loff_t *ppos)
845 {
846         u8 *buf = file->private_data;
847         return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
848 }
849
850 static int ath6kl_regdump_release(struct inode *inode, struct file *file)
851 {
852         vfree(file->private_data);
853         return 0;
854 }
855
856 static const struct file_operations fops_reg_dump = {
857         .open = ath6kl_regdump_open,
858         .read = ath6kl_regdump_read,
859         .release = ath6kl_regdump_release,
860         .owner = THIS_MODULE,
861         .llseek = default_llseek,
862 };
863
864 static ssize_t ath6kl_lrssi_roam_write(struct file *file,
865                                        const char __user *user_buf,
866                                        size_t count, loff_t *ppos)
867 {
868         struct ath6kl *ar = file->private_data;
869         unsigned long lrssi_roam_threshold;
870         char buf[32];
871         ssize_t len;
872
873         len = min(count, sizeof(buf) - 1);
874         if (copy_from_user(buf, user_buf, len))
875                 return -EFAULT;
876
877         buf[len] = '\0';
878         if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
879                 return -EINVAL;
880
881         ar->lrssi_roam_threshold = lrssi_roam_threshold;
882
883         ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
884
885         return count;
886 }
887
888 static ssize_t ath6kl_lrssi_roam_read(struct file *file,
889                                       char __user *user_buf,
890                                       size_t count, loff_t *ppos)
891 {
892         struct ath6kl *ar = file->private_data;
893         char buf[32];
894         unsigned int len;
895
896         len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
897
898         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
899 }
900
901 static const struct file_operations fops_lrssi_roam_threshold = {
902         .read = ath6kl_lrssi_roam_read,
903         .write = ath6kl_lrssi_roam_write,
904         .open = ath6kl_debugfs_open,
905         .owner = THIS_MODULE,
906         .llseek = default_llseek,
907 };
908
909 static ssize_t ath6kl_regwrite_read(struct file *file,
910                                     char __user *user_buf,
911                                     size_t count, loff_t *ppos)
912 {
913         struct ath6kl *ar = file->private_data;
914         u8 buf[32];
915         unsigned int len = 0;
916
917         len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
918                         ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
919
920         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
921 }
922
923 static ssize_t ath6kl_regwrite_write(struct file *file,
924                                      const char __user *user_buf,
925                                      size_t count, loff_t *ppos)
926 {
927         struct ath6kl *ar = file->private_data;
928         char buf[32];
929         char *sptr, *token;
930         unsigned int len = 0;
931         u32 reg_addr, reg_val;
932
933         len = min(count, sizeof(buf) - 1);
934         if (copy_from_user(buf, user_buf, len))
935                 return -EFAULT;
936
937         buf[len] = '\0';
938         sptr = buf;
939
940         token = strsep(&sptr, "=");
941         if (!token)
942                 return -EINVAL;
943
944         if (kstrtou32(token, 0, &reg_addr))
945                 return -EINVAL;
946
947         if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
948                 return -EINVAL;
949
950         if (kstrtou32(sptr, 0, &reg_val))
951                 return -EINVAL;
952
953         ar->debug.diag_reg_addr_wr = reg_addr;
954         ar->debug.diag_reg_val_wr = reg_val;
955
956         if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
957                                 cpu_to_le32(ar->debug.diag_reg_val_wr)))
958                 return -EIO;
959
960         return count;
961 }
962
963 static const struct file_operations fops_diag_reg_write = {
964         .read = ath6kl_regwrite_read,
965         .write = ath6kl_regwrite_write,
966         .open = ath6kl_debugfs_open,
967         .owner = THIS_MODULE,
968         .llseek = default_llseek,
969 };
970
971 int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
972                                 size_t len)
973 {
974         const struct wmi_target_roam_tbl *tbl;
975         u16 num_entries;
976
977         if (len < sizeof(*tbl))
978                 return -EINVAL;
979
980         tbl = (const struct wmi_target_roam_tbl *) buf;
981         num_entries = le16_to_cpu(tbl->num_entries);
982         if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) >
983             len)
984                 return -EINVAL;
985
986         if (ar->debug.roam_tbl == NULL ||
987             ar->debug.roam_tbl_len < (unsigned int) len) {
988                 kfree(ar->debug.roam_tbl);
989                 ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
990                 if (ar->debug.roam_tbl == NULL)
991                         return -ENOMEM;
992         }
993
994         memcpy(ar->debug.roam_tbl, buf, len);
995         ar->debug.roam_tbl_len = len;
996
997         if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
998                 clear_bit(ROAM_TBL_PEND, &ar->flag);
999                 wake_up(&ar->event_wq);
1000         }
1001
1002         return 0;
1003 }
1004
1005 static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
1006                                       size_t count, loff_t *ppos)
1007 {
1008         struct ath6kl *ar = file->private_data;
1009         int ret;
1010         long left;
1011         struct wmi_target_roam_tbl *tbl;
1012         u16 num_entries, i;
1013         char *buf;
1014         unsigned int len, buf_len;
1015         ssize_t ret_cnt;
1016
1017         if (down_interruptible(&ar->sem))
1018                 return -EBUSY;
1019
1020         set_bit(ROAM_TBL_PEND, &ar->flag);
1021
1022         ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
1023         if (ret) {
1024                 up(&ar->sem);
1025                 return ret;
1026         }
1027
1028         left = wait_event_interruptible_timeout(
1029                 ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
1030         up(&ar->sem);
1031
1032         if (left <= 0)
1033                 return -ETIMEDOUT;
1034
1035         if (ar->debug.roam_tbl == NULL)
1036                 return -ENOMEM;
1037
1038         tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
1039         num_entries = le16_to_cpu(tbl->num_entries);
1040
1041         buf_len = 100 + num_entries * 100;
1042         buf = kzalloc(buf_len, GFP_KERNEL);
1043         if (buf == NULL)
1044                 return -ENOMEM;
1045         len = 0;
1046         len += scnprintf(buf + len, buf_len - len,
1047                          "roam_mode=%u\n\n"
1048                          "# roam_util bssid rssi rssidt last_rssi util bias\n",
1049                          le16_to_cpu(tbl->roam_mode));
1050
1051         for (i = 0; i < num_entries; i++) {
1052                 struct wmi_bss_roam_info *info = &tbl->info[i];
1053                 len += scnprintf(buf + len, buf_len - len,
1054                                  "%d %pM %d %d %d %d %d\n",
1055                                  a_sle32_to_cpu(info->roam_util), info->bssid,
1056                                  info->rssi, info->rssidt, info->last_rssi,
1057                                  info->util, info->bias);
1058         }
1059
1060         if (len > buf_len)
1061                 len = buf_len;
1062
1063         ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1064
1065         kfree(buf);
1066         return ret_cnt;
1067 }
1068
1069 static const struct file_operations fops_roam_table = {
1070         .read = ath6kl_roam_table_read,
1071         .open = ath6kl_debugfs_open,
1072         .owner = THIS_MODULE,
1073         .llseek = default_llseek,
1074 };
1075
1076 static ssize_t ath6kl_force_roam_write(struct file *file,
1077                                        const char __user *user_buf,
1078                                        size_t count, loff_t *ppos)
1079 {
1080         struct ath6kl *ar = file->private_data;
1081         int ret;
1082         char buf[20];
1083         size_t len;
1084         u8 bssid[ETH_ALEN];
1085         int i;
1086         int addr[ETH_ALEN];
1087
1088         len = min(count, sizeof(buf) - 1);
1089         if (copy_from_user(buf, user_buf, len))
1090                 return -EFAULT;
1091         buf[len] = '\0';
1092
1093         if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
1094                    &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5])
1095             != ETH_ALEN)
1096                 return -EINVAL;
1097         for (i = 0; i < ETH_ALEN; i++)
1098                 bssid[i] = addr[i];
1099
1100         ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
1101         if (ret)
1102                 return ret;
1103
1104         return count;
1105 }
1106
1107 static const struct file_operations fops_force_roam = {
1108         .write = ath6kl_force_roam_write,
1109         .open = ath6kl_debugfs_open,
1110         .owner = THIS_MODULE,
1111         .llseek = default_llseek,
1112 };
1113
1114 static ssize_t ath6kl_roam_mode_write(struct file *file,
1115                                       const char __user *user_buf,
1116                                       size_t count, loff_t *ppos)
1117 {
1118         struct ath6kl *ar = file->private_data;
1119         int ret;
1120         char buf[20];
1121         size_t len;
1122         enum wmi_roam_mode mode;
1123
1124         len = min(count, sizeof(buf) - 1);
1125         if (copy_from_user(buf, user_buf, len))
1126                 return -EFAULT;
1127         buf[len] = '\0';
1128         if (len > 0 && buf[len - 1] == '\n')
1129                 buf[len - 1] = '\0';
1130
1131         if (strcasecmp(buf, "default") == 0)
1132                 mode = WMI_DEFAULT_ROAM_MODE;
1133         else if (strcasecmp(buf, "bssbias") == 0)
1134                 mode = WMI_HOST_BIAS_ROAM_MODE;
1135         else if (strcasecmp(buf, "lock") == 0)
1136                 mode = WMI_LOCK_BSS_MODE;
1137         else
1138                 return -EINVAL;
1139
1140         ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
1141         if (ret)
1142                 return ret;
1143
1144         return count;
1145 }
1146
1147 static const struct file_operations fops_roam_mode = {
1148         .write = ath6kl_roam_mode_write,
1149         .open = ath6kl_debugfs_open,
1150         .owner = THIS_MODULE,
1151         .llseek = default_llseek,
1152 };
1153
1154 void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
1155 {
1156         ar->debug.keepalive = keepalive;
1157 }
1158
1159 static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
1160                                      size_t count, loff_t *ppos)
1161 {
1162         struct ath6kl *ar = file->private_data;
1163         char buf[16];
1164         int len;
1165
1166         len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
1167
1168         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1169 }
1170
1171 static ssize_t ath6kl_keepalive_write(struct file *file,
1172                                       const char __user *user_buf,
1173                                       size_t count, loff_t *ppos)
1174 {
1175         struct ath6kl *ar = file->private_data;
1176         int ret;
1177         u8 val;
1178
1179         ret = kstrtou8_from_user(user_buf, count, 0, &val);
1180         if (ret)
1181                 return ret;
1182
1183         ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, val);
1184         if (ret)
1185                 return ret;
1186
1187         return count;
1188 }
1189
1190 static const struct file_operations fops_keepalive = {
1191         .open = ath6kl_debugfs_open,
1192         .read = ath6kl_keepalive_read,
1193         .write = ath6kl_keepalive_write,
1194         .owner = THIS_MODULE,
1195         .llseek = default_llseek,
1196 };
1197
1198 void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
1199 {
1200         ar->debug.disc_timeout = timeout;
1201 }
1202
1203 static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
1204                                               char __user *user_buf,
1205                                               size_t count, loff_t *ppos)
1206 {
1207         struct ath6kl *ar = file->private_data;
1208         char buf[16];
1209         int len;
1210
1211         len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
1212
1213         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1214 }
1215
1216 static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
1217                                                const char __user *user_buf,
1218                                                size_t count, loff_t *ppos)
1219 {
1220         struct ath6kl *ar = file->private_data;
1221         int ret;
1222         u8 val;
1223
1224         ret = kstrtou8_from_user(user_buf, count, 0, &val);
1225         if (ret)
1226                 return ret;
1227
1228         ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, val);
1229         if (ret)
1230                 return ret;
1231
1232         return count;
1233 }
1234
1235 static const struct file_operations fops_disconnect_timeout = {
1236         .open = ath6kl_debugfs_open,
1237         .read = ath6kl_disconnect_timeout_read,
1238         .write = ath6kl_disconnect_timeout_write,
1239         .owner = THIS_MODULE,
1240         .llseek = default_llseek,
1241 };
1242
1243 int ath6kl_debug_init(struct ath6kl *ar)
1244 {
1245         ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE);
1246         if (ar->debug.fwlog_buf.buf == NULL)
1247                 return -ENOMEM;
1248
1249         ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL);
1250         if (ar->debug.fwlog_tmp == NULL) {
1251                 vfree(ar->debug.fwlog_buf.buf);
1252                 return -ENOMEM;
1253         }
1254
1255         spin_lock_init(&ar->debug.fwlog_lock);
1256
1257         /*
1258          * Actually we are lying here but don't know how to read the mask
1259          * value from the firmware.
1260          */
1261         ar->debug.fwlog_mask = 0;
1262
1263         ar->debugfs_phy = debugfs_create_dir("ath6kl",
1264                                              ar->wdev->wiphy->debugfsdir);
1265         if (!ar->debugfs_phy) {
1266                 vfree(ar->debug.fwlog_buf.buf);
1267                 kfree(ar->debug.fwlog_tmp);
1268                 return -ENOMEM;
1269         }
1270
1271         debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
1272                             &fops_tgt_stats);
1273
1274         debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
1275                             &fops_credit_dist_stats);
1276
1277         debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR,
1278                             ar->debugfs_phy, ar, &fops_endpoint_stats);
1279
1280         debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
1281                             &fops_fwlog);
1282
1283         debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
1284                             ar, &fops_fwlog_mask);
1285
1286         debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1287                             &fops_diag_reg_read);
1288
1289         debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
1290                             &fops_reg_dump);
1291
1292         debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
1293                             ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
1294
1295         debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
1296                             ar->debugfs_phy, ar, &fops_diag_reg_write);
1297
1298         debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
1299                             &fops_war_stats);
1300
1301         debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar,
1302                             &fops_roam_table);
1303
1304         debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar,
1305                             &fops_force_roam);
1306
1307         debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar,
1308                             &fops_roam_mode);
1309
1310         debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1311                             &fops_keepalive);
1312
1313         debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR,
1314                             ar->debugfs_phy, ar, &fops_disconnect_timeout);
1315
1316         return 0;
1317 }
1318
1319 void ath6kl_debug_cleanup(struct ath6kl *ar)
1320 {
1321         vfree(ar->debug.fwlog_buf.buf);
1322         kfree(ar->debug.fwlog_tmp);
1323         kfree(ar->debug.roam_tbl);
1324 }
1325
1326 #endif