1bdcd8170SKalle Valo /* 2bdcd8170SKalle Valo * Copyright (c) 2004-2011 Atheros Communications Inc. 3bdcd8170SKalle Valo * 4bdcd8170SKalle Valo * Permission to use, copy, modify, and/or distribute this software for any 5bdcd8170SKalle Valo * purpose with or without fee is hereby granted, provided that the above 6bdcd8170SKalle Valo * copyright notice and this permission notice appear in all copies. 7bdcd8170SKalle Valo * 8bdcd8170SKalle Valo * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9bdcd8170SKalle Valo * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10bdcd8170SKalle Valo * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11bdcd8170SKalle Valo * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12bdcd8170SKalle Valo * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13bdcd8170SKalle Valo * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14bdcd8170SKalle Valo * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15bdcd8170SKalle Valo */ 16bdcd8170SKalle Valo 17bdcd8170SKalle Valo #include "core.h" 18bdf5396bSKalle Valo 19bdf5396bSKalle Valo #include <linux/circ_buf.h> 20939f1cceSKalle Valo #include <linux/fs.h> 2162c83ac4SKalle Valo #include <linux/vmalloc.h> 22bdf5396bSKalle Valo 23bdcd8170SKalle Valo #include "debug.h" 24bdf5396bSKalle Valo #include "target.h" 25bdf5396bSKalle Valo 26bdf5396bSKalle Valo struct ath6kl_fwlog_slot { 27bdf5396bSKalle Valo __le32 timestamp; 28bdf5396bSKalle Valo __le32 length; 29bdf5396bSKalle Valo 30bdf5396bSKalle Valo /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */ 31bdf5396bSKalle Valo u8 payload[0]; 32bdf5396bSKalle Valo }; 33bdf5396bSKalle Valo 34bdf5396bSKalle Valo #define ATH6KL_FWLOG_SIZE 32768 35bdf5396bSKalle Valo #define ATH6KL_FWLOG_SLOT_SIZE (sizeof(struct ath6kl_fwlog_slot) + \ 36bdf5396bSKalle Valo ATH6KL_FWLOG_PAYLOAD_SIZE) 37939f1cceSKalle Valo #define ATH6KL_FWLOG_VALID_MASK 0x1ffff 38bdcd8170SKalle Valo 39bdcd8170SKalle Valo int ath6kl_printk(const char *level, const char *fmt, ...) 40bdcd8170SKalle Valo { 41bdcd8170SKalle Valo struct va_format vaf; 42bdcd8170SKalle Valo va_list args; 43bdcd8170SKalle Valo int rtn; 44bdcd8170SKalle Valo 45bdcd8170SKalle Valo va_start(args, fmt); 46bdcd8170SKalle Valo 47bdcd8170SKalle Valo vaf.fmt = fmt; 48bdcd8170SKalle Valo vaf.va = &args; 49bdcd8170SKalle Valo 50bdcd8170SKalle Valo rtn = printk("%sath6kl: %pV", level, &vaf); 51bdcd8170SKalle Valo 52bdcd8170SKalle Valo va_end(args); 53bdcd8170SKalle Valo 54bdcd8170SKalle Valo return rtn; 55bdcd8170SKalle Valo } 56bdcd8170SKalle Valo 57bdcd8170SKalle Valo #ifdef CONFIG_ATH6KL_DEBUG 5891d57de5SVasanthakumar Thiagarajan 5991d57de5SVasanthakumar Thiagarajan #define REG_OUTPUT_LEN_PER_LINE 25 6091d57de5SVasanthakumar Thiagarajan #define REGTYPE_STR_LEN 100 6191d57de5SVasanthakumar Thiagarajan 6291d57de5SVasanthakumar Thiagarajan struct ath6kl_diag_reg_info { 6391d57de5SVasanthakumar Thiagarajan u32 reg_start; 6491d57de5SVasanthakumar Thiagarajan u32 reg_end; 6591d57de5SVasanthakumar Thiagarajan const char *reg_info; 6691d57de5SVasanthakumar Thiagarajan }; 6791d57de5SVasanthakumar Thiagarajan 6891d57de5SVasanthakumar Thiagarajan static const struct ath6kl_diag_reg_info diag_reg[] = { 6991d57de5SVasanthakumar Thiagarajan { 0x20000, 0x200fc, "General DMA and Rx registers" }, 7091d57de5SVasanthakumar Thiagarajan { 0x28000, 0x28900, "MAC PCU register & keycache" }, 7191d57de5SVasanthakumar Thiagarajan { 0x20800, 0x20a40, "QCU" }, 7291d57de5SVasanthakumar Thiagarajan { 0x21000, 0x212f0, "DCU" }, 7391d57de5SVasanthakumar Thiagarajan { 0x4000, 0x42e4, "RTC" }, 7491d57de5SVasanthakumar Thiagarajan { 0x540000, 0x540000 + (256 * 1024), "RAM" }, 7591d57de5SVasanthakumar Thiagarajan { 0x29800, 0x2B210, "Base Band" }, 7691d57de5SVasanthakumar Thiagarajan { 0x1C000, 0x1C748, "Analog" }, 7791d57de5SVasanthakumar Thiagarajan }; 7891d57de5SVasanthakumar Thiagarajan 79bdcd8170SKalle Valo void ath6kl_dump_registers(struct ath6kl_device *dev, 80bdcd8170SKalle Valo struct ath6kl_irq_proc_registers *irq_proc_reg, 81bdcd8170SKalle Valo struct ath6kl_irq_enable_reg *irq_enable_reg) 82bdcd8170SKalle Valo { 83bdcd8170SKalle Valo 84bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, ("<------- Register Table -------->\n")); 85bdcd8170SKalle Valo 86bdcd8170SKalle Valo if (irq_proc_reg != NULL) { 87bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 88bdcd8170SKalle Valo "Host Int status: 0x%x\n", 89bdcd8170SKalle Valo irq_proc_reg->host_int_status); 90bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 91bdcd8170SKalle Valo "CPU Int status: 0x%x\n", 92bdcd8170SKalle Valo irq_proc_reg->cpu_int_status); 93bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 94bdcd8170SKalle Valo "Error Int status: 0x%x\n", 95bdcd8170SKalle Valo irq_proc_reg->error_int_status); 96bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 97bdcd8170SKalle Valo "Counter Int status: 0x%x\n", 98bdcd8170SKalle Valo irq_proc_reg->counter_int_status); 99bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 100bdcd8170SKalle Valo "Mbox Frame: 0x%x\n", 101bdcd8170SKalle Valo irq_proc_reg->mbox_frame); 102bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 103bdcd8170SKalle Valo "Rx Lookahead Valid: 0x%x\n", 104bdcd8170SKalle Valo irq_proc_reg->rx_lkahd_valid); 105bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 106bdcd8170SKalle Valo "Rx Lookahead 0: 0x%x\n", 107bdcd8170SKalle Valo irq_proc_reg->rx_lkahd[0]); 108bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 109bdcd8170SKalle Valo "Rx Lookahead 1: 0x%x\n", 110bdcd8170SKalle Valo irq_proc_reg->rx_lkahd[1]); 111bdcd8170SKalle Valo 112bdcd8170SKalle Valo if (dev->ar->mbox_info.gmbox_addr != 0) { 113bdcd8170SKalle Valo /* 114bdcd8170SKalle Valo * If the target supports GMBOX hardware, dump some 115bdcd8170SKalle Valo * additional state. 116bdcd8170SKalle Valo */ 117bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 118bdcd8170SKalle Valo "GMBOX Host Int status 2: 0x%x\n", 119bdcd8170SKalle Valo irq_proc_reg->host_int_status2); 120bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 121bdcd8170SKalle Valo "GMBOX RX Avail: 0x%x\n", 122bdcd8170SKalle Valo irq_proc_reg->gmbox_rx_avail); 123bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 124bdcd8170SKalle Valo "GMBOX lookahead alias 0: 0x%x\n", 125bdcd8170SKalle Valo irq_proc_reg->rx_gmbox_lkahd_alias[0]); 126bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 127bdcd8170SKalle Valo "GMBOX lookahead alias 1: 0x%x\n", 128bdcd8170SKalle Valo irq_proc_reg->rx_gmbox_lkahd_alias[1]); 129bdcd8170SKalle Valo } 130bdcd8170SKalle Valo 131bdcd8170SKalle Valo } 132bdcd8170SKalle Valo 133bdcd8170SKalle Valo if (irq_enable_reg != NULL) { 134bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 135bdcd8170SKalle Valo "Int status Enable: 0x%x\n", 136bdcd8170SKalle Valo irq_enable_reg->int_status_en); 137bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, "Counter Int status Enable: 0x%x\n", 138bdcd8170SKalle Valo irq_enable_reg->cntr_int_status_en); 139bdcd8170SKalle Valo } 140bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, "<------------------------------->\n"); 141bdcd8170SKalle Valo } 142bdcd8170SKalle Valo 143bdcd8170SKalle Valo static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist) 144bdcd8170SKalle Valo { 145bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 146bdcd8170SKalle Valo "--- endpoint: %d svc_id: 0x%X ---\n", 147bdcd8170SKalle Valo ep_dist->endpoint, ep_dist->svc_id); 148bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " dist_flags : 0x%X\n", 149bdcd8170SKalle Valo ep_dist->dist_flags); 150bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " cred_norm : %d\n", 151bdcd8170SKalle Valo ep_dist->cred_norm); 152bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " cred_min : %d\n", 153bdcd8170SKalle Valo ep_dist->cred_min); 154bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " credits : %d\n", 155bdcd8170SKalle Valo ep_dist->credits); 156bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " cred_assngd : %d\n", 157bdcd8170SKalle Valo ep_dist->cred_assngd); 158bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " seek_cred : %d\n", 159bdcd8170SKalle Valo ep_dist->seek_cred); 160bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " cred_sz : %d\n", 161bdcd8170SKalle Valo ep_dist->cred_sz); 162bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " cred_per_msg : %d\n", 163bdcd8170SKalle Valo ep_dist->cred_per_msg); 164bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " cred_to_dist : %d\n", 165bdcd8170SKalle Valo ep_dist->cred_to_dist); 166bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, " txq_depth : %d\n", 167*e8c39790SKalle Valo get_queue_depth(&ep_dist->htc_ep->txq)); 168bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_ANY, 169bdcd8170SKalle Valo "----------------------------------\n"); 170bdcd8170SKalle Valo } 171bdcd8170SKalle Valo 172bdcd8170SKalle Valo void dump_cred_dist_stats(struct htc_target *target) 173bdcd8170SKalle Valo { 174bdcd8170SKalle Valo struct htc_endpoint_credit_dist *ep_list; 175bdcd8170SKalle Valo 176bdcd8170SKalle Valo if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_TRC)) 177bdcd8170SKalle Valo return; 178bdcd8170SKalle Valo 179bdcd8170SKalle Valo list_for_each_entry(ep_list, &target->cred_dist_list, list) 180bdcd8170SKalle Valo dump_cred_dist(ep_list); 181bdcd8170SKalle Valo 182ebf29c95SKalle Valo ath6kl_dbg(ATH6KL_DBG_HTC, "ctxt:%p dist:%p\n", 183bdcd8170SKalle Valo target->cred_dist_cntxt, NULL); 184ebf29c95SKalle Valo ath6kl_dbg(ATH6KL_DBG_HTC, 185ebf29c95SKalle Valo "credit distribution, total : %d, free : %d\n", 186bdcd8170SKalle Valo target->cred_dist_cntxt->total_avail_credits, 187bdcd8170SKalle Valo target->cred_dist_cntxt->cur_free_credits); 188bdcd8170SKalle Valo } 189bdcd8170SKalle Valo 19003f68a95SVasanthakumar Thiagarajan static int ath6kl_debugfs_open(struct inode *inode, struct file *file) 19103f68a95SVasanthakumar Thiagarajan { 19203f68a95SVasanthakumar Thiagarajan file->private_data = inode->i_private; 19303f68a95SVasanthakumar Thiagarajan return 0; 19403f68a95SVasanthakumar Thiagarajan } 19503f68a95SVasanthakumar Thiagarajan 1969a730834SKalle Valo void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war) 1979a730834SKalle Valo { 1989a730834SKalle Valo switch (war) { 1999a730834SKalle Valo case ATH6KL_WAR_INVALID_RATE: 2009a730834SKalle Valo ar->debug.war_stats.invalid_rate++; 2019a730834SKalle Valo break; 2029a730834SKalle Valo } 2039a730834SKalle Valo } 2049a730834SKalle Valo 2059a730834SKalle Valo static ssize_t read_file_war_stats(struct file *file, char __user *user_buf, 2069a730834SKalle Valo size_t count, loff_t *ppos) 2079a730834SKalle Valo { 2089a730834SKalle Valo struct ath6kl *ar = file->private_data; 2099a730834SKalle Valo char *buf; 2109a730834SKalle Valo unsigned int len = 0, buf_len = 1500; 2119a730834SKalle Valo ssize_t ret_cnt; 2129a730834SKalle Valo 2139a730834SKalle Valo buf = kzalloc(buf_len, GFP_KERNEL); 2149a730834SKalle Valo if (!buf) 2159a730834SKalle Valo return -ENOMEM; 2169a730834SKalle Valo 2179a730834SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n"); 2189a730834SKalle Valo len += scnprintf(buf + len, buf_len - len, "%25s\n", 2199a730834SKalle Valo "Workaround stats"); 2209a730834SKalle Valo len += scnprintf(buf + len, buf_len - len, "%25s\n\n", 2219a730834SKalle Valo "================="); 2229a730834SKalle Valo len += scnprintf(buf + len, buf_len - len, "%20s %10u\n", 2239a730834SKalle Valo "Invalid rates", ar->debug.war_stats.invalid_rate); 2249a730834SKalle Valo 2259a730834SKalle Valo if (WARN_ON(len > buf_len)) 2269a730834SKalle Valo len = buf_len; 2279a730834SKalle Valo 2289a730834SKalle Valo ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); 2299a730834SKalle Valo 2309a730834SKalle Valo kfree(buf); 2319a730834SKalle Valo return ret_cnt; 2329a730834SKalle Valo } 2339a730834SKalle Valo 2349a730834SKalle Valo static const struct file_operations fops_war_stats = { 2359a730834SKalle Valo .read = read_file_war_stats, 2369a730834SKalle Valo .open = ath6kl_debugfs_open, 2379a730834SKalle Valo .owner = THIS_MODULE, 2389a730834SKalle Valo .llseek = default_llseek, 2399a730834SKalle Valo }; 2409a730834SKalle Valo 241bdf5396bSKalle Valo static void ath6kl_debug_fwlog_add(struct ath6kl *ar, const void *buf, 242bdf5396bSKalle Valo size_t buf_len) 243bdf5396bSKalle Valo { 244bdf5396bSKalle Valo struct circ_buf *fwlog = &ar->debug.fwlog_buf; 245bdf5396bSKalle Valo size_t space; 246bdf5396bSKalle Valo int i; 247bdf5396bSKalle Valo 248bdf5396bSKalle Valo /* entries must all be equal size */ 249bdf5396bSKalle Valo if (WARN_ON(buf_len != ATH6KL_FWLOG_SLOT_SIZE)) 250bdf5396bSKalle Valo return; 251bdf5396bSKalle Valo 252bdf5396bSKalle Valo space = CIRC_SPACE(fwlog->head, fwlog->tail, ATH6KL_FWLOG_SIZE); 253bdf5396bSKalle Valo if (space < buf_len) 254bdf5396bSKalle Valo /* discard oldest slot */ 255bdf5396bSKalle Valo fwlog->tail = (fwlog->tail + ATH6KL_FWLOG_SLOT_SIZE) & 256bdf5396bSKalle Valo (ATH6KL_FWLOG_SIZE - 1); 257bdf5396bSKalle Valo 258bdf5396bSKalle Valo for (i = 0; i < buf_len; i += space) { 259bdf5396bSKalle Valo space = CIRC_SPACE_TO_END(fwlog->head, fwlog->tail, 260bdf5396bSKalle Valo ATH6KL_FWLOG_SIZE); 261bdf5396bSKalle Valo 262bdf5396bSKalle Valo if ((size_t) space > buf_len - i) 263bdf5396bSKalle Valo space = buf_len - i; 264bdf5396bSKalle Valo 265bdf5396bSKalle Valo memcpy(&fwlog->buf[fwlog->head], buf, space); 266bdf5396bSKalle Valo fwlog->head = (fwlog->head + space) & (ATH6KL_FWLOG_SIZE - 1); 267bdf5396bSKalle Valo } 268bdf5396bSKalle Valo 269bdf5396bSKalle Valo } 270bdf5396bSKalle Valo 271bdf5396bSKalle Valo void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len) 272bdf5396bSKalle Valo { 273bdf5396bSKalle Valo struct ath6kl_fwlog_slot *slot = ar->debug.fwlog_tmp; 274bdf5396bSKalle Valo size_t slot_len; 275bdf5396bSKalle Valo 276bdf5396bSKalle Valo if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE)) 277bdf5396bSKalle Valo return; 278bdf5396bSKalle Valo 279bdf5396bSKalle Valo spin_lock_bh(&ar->debug.fwlog_lock); 280bdf5396bSKalle Valo 281bdf5396bSKalle Valo slot->timestamp = cpu_to_le32(jiffies); 282bdf5396bSKalle Valo slot->length = cpu_to_le32(len); 283bdf5396bSKalle Valo memcpy(slot->payload, buf, len); 284bdf5396bSKalle Valo 285bdf5396bSKalle Valo slot_len = sizeof(*slot) + len; 286bdf5396bSKalle Valo 287bdf5396bSKalle Valo if (slot_len < ATH6KL_FWLOG_SLOT_SIZE) 288bdf5396bSKalle Valo memset(slot->payload + len, 0, 289bdf5396bSKalle Valo ATH6KL_FWLOG_SLOT_SIZE - slot_len); 290bdf5396bSKalle Valo 291bdf5396bSKalle Valo ath6kl_debug_fwlog_add(ar, slot, ATH6KL_FWLOG_SLOT_SIZE); 292bdf5396bSKalle Valo 293bdf5396bSKalle Valo spin_unlock_bh(&ar->debug.fwlog_lock); 294bdf5396bSKalle Valo } 295bdf5396bSKalle Valo 296bdf5396bSKalle Valo static bool ath6kl_debug_fwlog_empty(struct ath6kl *ar) 297bdf5396bSKalle Valo { 298bdf5396bSKalle Valo return CIRC_CNT(ar->debug.fwlog_buf.head, 299bdf5396bSKalle Valo ar->debug.fwlog_buf.tail, 300bdf5396bSKalle Valo ATH6KL_FWLOG_SLOT_SIZE) == 0; 301bdf5396bSKalle Valo } 302bdf5396bSKalle Valo 303bdf5396bSKalle Valo static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf, 304bdf5396bSKalle Valo size_t count, loff_t *ppos) 305bdf5396bSKalle Valo { 306bdf5396bSKalle Valo struct ath6kl *ar = file->private_data; 307bdf5396bSKalle Valo struct circ_buf *fwlog = &ar->debug.fwlog_buf; 308bdf5396bSKalle Valo size_t len = 0, buf_len = count; 309bdf5396bSKalle Valo ssize_t ret_cnt; 310bdf5396bSKalle Valo char *buf; 311bdf5396bSKalle Valo int ccnt; 312bdf5396bSKalle Valo 313bdf5396bSKalle Valo buf = vmalloc(buf_len); 314bdf5396bSKalle Valo if (!buf) 315bdf5396bSKalle Valo return -ENOMEM; 316bdf5396bSKalle Valo 317bc07ddb2SKalle Valo /* read undelivered logs from firmware */ 318bc07ddb2SKalle Valo ath6kl_read_fwlogs(ar); 319bc07ddb2SKalle Valo 320bdf5396bSKalle Valo spin_lock_bh(&ar->debug.fwlog_lock); 321bdf5396bSKalle Valo 322bdf5396bSKalle Valo while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) { 323bdf5396bSKalle Valo ccnt = CIRC_CNT_TO_END(fwlog->head, fwlog->tail, 324bdf5396bSKalle Valo ATH6KL_FWLOG_SIZE); 325bdf5396bSKalle Valo 326bdf5396bSKalle Valo if ((size_t) ccnt > buf_len - len) 327bdf5396bSKalle Valo ccnt = buf_len - len; 328bdf5396bSKalle Valo 329bdf5396bSKalle Valo memcpy(buf + len, &fwlog->buf[fwlog->tail], ccnt); 330bdf5396bSKalle Valo len += ccnt; 331bdf5396bSKalle Valo 332bdf5396bSKalle Valo fwlog->tail = (fwlog->tail + ccnt) & 333bdf5396bSKalle Valo (ATH6KL_FWLOG_SIZE - 1); 334bdf5396bSKalle Valo } 335bdf5396bSKalle Valo 336bdf5396bSKalle Valo spin_unlock_bh(&ar->debug.fwlog_lock); 337bdf5396bSKalle Valo 338bdf5396bSKalle Valo if (WARN_ON(len > buf_len)) 339bdf5396bSKalle Valo len = buf_len; 340bdf5396bSKalle Valo 341bdf5396bSKalle Valo ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); 342bdf5396bSKalle Valo 343bdf5396bSKalle Valo vfree(buf); 344bdf5396bSKalle Valo 345bdf5396bSKalle Valo return ret_cnt; 346bdf5396bSKalle Valo } 347bdf5396bSKalle Valo 348bdf5396bSKalle Valo static const struct file_operations fops_fwlog = { 349bdf5396bSKalle Valo .open = ath6kl_debugfs_open, 350bdf5396bSKalle Valo .read = ath6kl_fwlog_read, 351bdf5396bSKalle Valo .owner = THIS_MODULE, 352bdf5396bSKalle Valo .llseek = default_llseek, 353bdf5396bSKalle Valo }; 354bdf5396bSKalle Valo 355939f1cceSKalle Valo static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf, 356939f1cceSKalle Valo size_t count, loff_t *ppos) 357939f1cceSKalle Valo { 358939f1cceSKalle Valo struct ath6kl *ar = file->private_data; 359939f1cceSKalle Valo char buf[16]; 360939f1cceSKalle Valo int len; 361939f1cceSKalle Valo 362939f1cceSKalle Valo len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask); 363939f1cceSKalle Valo 364939f1cceSKalle Valo return simple_read_from_buffer(user_buf, count, ppos, buf, len); 365939f1cceSKalle Valo } 366939f1cceSKalle Valo 367939f1cceSKalle Valo static ssize_t ath6kl_fwlog_mask_write(struct file *file, 368939f1cceSKalle Valo const char __user *user_buf, 369939f1cceSKalle Valo size_t count, loff_t *ppos) 370939f1cceSKalle Valo { 371939f1cceSKalle Valo struct ath6kl *ar = file->private_data; 372939f1cceSKalle Valo int ret; 373939f1cceSKalle Valo 374939f1cceSKalle Valo ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask); 375939f1cceSKalle Valo if (ret) 376939f1cceSKalle Valo return ret; 377939f1cceSKalle Valo 378939f1cceSKalle Valo ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi, 379939f1cceSKalle Valo ATH6KL_FWLOG_VALID_MASK, 380939f1cceSKalle Valo ar->debug.fwlog_mask); 381939f1cceSKalle Valo if (ret) 382939f1cceSKalle Valo return ret; 383939f1cceSKalle Valo 384939f1cceSKalle Valo return count; 385939f1cceSKalle Valo } 386939f1cceSKalle Valo 387939f1cceSKalle Valo static const struct file_operations fops_fwlog_mask = { 388939f1cceSKalle Valo .open = ath6kl_debugfs_open, 389939f1cceSKalle Valo .read = ath6kl_fwlog_mask_read, 390939f1cceSKalle Valo .write = ath6kl_fwlog_mask_write, 391939f1cceSKalle Valo .owner = THIS_MODULE, 392939f1cceSKalle Valo .llseek = default_llseek, 393939f1cceSKalle Valo }; 394939f1cceSKalle Valo 39503f68a95SVasanthakumar Thiagarajan static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf, 39603f68a95SVasanthakumar Thiagarajan size_t count, loff_t *ppos) 39703f68a95SVasanthakumar Thiagarajan { 39803f68a95SVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data; 399990bd915SVasanthakumar Thiagarajan struct ath6kl_vif *vif; 400990bd915SVasanthakumar Thiagarajan struct target_stats *tgt_stats; 40103f68a95SVasanthakumar Thiagarajan char *buf; 40203f68a95SVasanthakumar Thiagarajan unsigned int len = 0, buf_len = 1500; 40303f68a95SVasanthakumar Thiagarajan int i; 40403f68a95SVasanthakumar Thiagarajan long left; 40503f68a95SVasanthakumar Thiagarajan ssize_t ret_cnt; 40603f68a95SVasanthakumar Thiagarajan 407990bd915SVasanthakumar Thiagarajan vif = ath6kl_vif_first(ar); 408990bd915SVasanthakumar Thiagarajan if (!vif) 409990bd915SVasanthakumar Thiagarajan return -EIO; 410990bd915SVasanthakumar Thiagarajan 411990bd915SVasanthakumar Thiagarajan tgt_stats = &vif->target_stats; 412990bd915SVasanthakumar Thiagarajan 41303f68a95SVasanthakumar Thiagarajan buf = kzalloc(buf_len, GFP_KERNEL); 41403f68a95SVasanthakumar Thiagarajan if (!buf) 41503f68a95SVasanthakumar Thiagarajan return -ENOMEM; 41603f68a95SVasanthakumar Thiagarajan 41703f68a95SVasanthakumar Thiagarajan if (down_interruptible(&ar->sem)) { 41803f68a95SVasanthakumar Thiagarajan kfree(buf); 41903f68a95SVasanthakumar Thiagarajan return -EBUSY; 42003f68a95SVasanthakumar Thiagarajan } 42103f68a95SVasanthakumar Thiagarajan 422b95907a7SVasanthakumar Thiagarajan set_bit(STATS_UPDATE_PEND, &vif->flags); 42303f68a95SVasanthakumar Thiagarajan 424334234b5SVasanthakumar Thiagarajan if (ath6kl_wmi_get_stats_cmd(ar->wmi, 0)) { 42503f68a95SVasanthakumar Thiagarajan up(&ar->sem); 42603f68a95SVasanthakumar Thiagarajan kfree(buf); 42703f68a95SVasanthakumar Thiagarajan return -EIO; 42803f68a95SVasanthakumar Thiagarajan } 42903f68a95SVasanthakumar Thiagarajan 43003f68a95SVasanthakumar Thiagarajan left = wait_event_interruptible_timeout(ar->event_wq, 43103f68a95SVasanthakumar Thiagarajan !test_bit(STATS_UPDATE_PEND, 432b95907a7SVasanthakumar Thiagarajan &vif->flags), WMI_TIMEOUT); 43303f68a95SVasanthakumar Thiagarajan 43403f68a95SVasanthakumar Thiagarajan up(&ar->sem); 43503f68a95SVasanthakumar Thiagarajan 43603f68a95SVasanthakumar Thiagarajan if (left <= 0) { 43703f68a95SVasanthakumar Thiagarajan kfree(buf); 43803f68a95SVasanthakumar Thiagarajan return -ETIMEDOUT; 43903f68a95SVasanthakumar Thiagarajan } 44003f68a95SVasanthakumar Thiagarajan 44103f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "\n"); 44203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n", 44303f68a95SVasanthakumar Thiagarajan "Target Tx stats"); 44403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n\n", 44503f68a95SVasanthakumar Thiagarajan "================="); 44603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 44703f68a95SVasanthakumar Thiagarajan "Ucast packets", tgt_stats->tx_ucast_pkt); 44803f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 44903f68a95SVasanthakumar Thiagarajan "Bcast packets", tgt_stats->tx_bcast_pkt); 45003f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 45103f68a95SVasanthakumar Thiagarajan "Ucast byte", tgt_stats->tx_ucast_byte); 45203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 45303f68a95SVasanthakumar Thiagarajan "Bcast byte", tgt_stats->tx_bcast_byte); 45403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 45503f68a95SVasanthakumar Thiagarajan "Rts success cnt", tgt_stats->tx_rts_success_cnt); 45603f68a95SVasanthakumar Thiagarajan for (i = 0; i < 4; i++) 45703f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, 45803f68a95SVasanthakumar Thiagarajan "%18s %d %10llu\n", "PER on ac", 45903f68a95SVasanthakumar Thiagarajan i, tgt_stats->tx_pkt_per_ac[i]); 46003f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 46103f68a95SVasanthakumar Thiagarajan "Error", tgt_stats->tx_err); 46203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 46303f68a95SVasanthakumar Thiagarajan "Fail count", tgt_stats->tx_fail_cnt); 46403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 46503f68a95SVasanthakumar Thiagarajan "Retry count", tgt_stats->tx_retry_cnt); 46603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 46703f68a95SVasanthakumar Thiagarajan "Multi retry cnt", tgt_stats->tx_mult_retry_cnt); 46803f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 46903f68a95SVasanthakumar Thiagarajan "Rts fail cnt", tgt_stats->tx_rts_fail_cnt); 47003f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n", 47103f68a95SVasanthakumar Thiagarajan "TKIP counter measure used", 47203f68a95SVasanthakumar Thiagarajan tgt_stats->tkip_cnter_measures_invoked); 47303f68a95SVasanthakumar Thiagarajan 47403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n", 47503f68a95SVasanthakumar Thiagarajan "Target Rx stats"); 47603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n", 47703f68a95SVasanthakumar Thiagarajan "================="); 47803f68a95SVasanthakumar Thiagarajan 47903f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 48003f68a95SVasanthakumar Thiagarajan "Ucast packets", tgt_stats->rx_ucast_pkt); 48103f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10d\n", 48203f68a95SVasanthakumar Thiagarajan "Ucast Rate", tgt_stats->rx_ucast_rate); 48303f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 48403f68a95SVasanthakumar Thiagarajan "Bcast packets", tgt_stats->rx_bcast_pkt); 48503f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 48603f68a95SVasanthakumar Thiagarajan "Ucast byte", tgt_stats->rx_ucast_byte); 48703f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 48803f68a95SVasanthakumar Thiagarajan "Bcast byte", tgt_stats->rx_bcast_byte); 48903f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 49003f68a95SVasanthakumar Thiagarajan "Fragmented pkt", tgt_stats->rx_frgment_pkt); 49103f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 49203f68a95SVasanthakumar Thiagarajan "Error", tgt_stats->rx_err); 49303f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 49403f68a95SVasanthakumar Thiagarajan "CRC Err", tgt_stats->rx_crc_err); 49503f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 49603f68a95SVasanthakumar Thiagarajan "Key chache miss", tgt_stats->rx_key_cache_miss); 49703f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 49803f68a95SVasanthakumar Thiagarajan "Decrypt Err", tgt_stats->rx_decrypt_err); 49903f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 50003f68a95SVasanthakumar Thiagarajan "Duplicate frame", tgt_stats->rx_dupl_frame); 50103f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 50203f68a95SVasanthakumar Thiagarajan "Tkip Mic failure", tgt_stats->tkip_local_mic_fail); 50303f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 50403f68a95SVasanthakumar Thiagarajan "TKIP format err", tgt_stats->tkip_fmt_err); 50503f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 50603f68a95SVasanthakumar Thiagarajan "CCMP format Err", tgt_stats->ccmp_fmt_err); 50703f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n", 50803f68a95SVasanthakumar Thiagarajan "CCMP Replay Err", tgt_stats->ccmp_replays); 50903f68a95SVasanthakumar Thiagarajan 51003f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n", 51103f68a95SVasanthakumar Thiagarajan "Misc Target stats"); 51203f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s\n", 51303f68a95SVasanthakumar Thiagarajan "================="); 51403f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 51503f68a95SVasanthakumar Thiagarajan "Beacon Miss count", tgt_stats->cs_bmiss_cnt); 51603f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 51703f68a95SVasanthakumar Thiagarajan "Num Connects", tgt_stats->cs_connect_cnt); 51803f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n", 51903f68a95SVasanthakumar Thiagarajan "Num disconnects", tgt_stats->cs_discon_cnt); 52003f68a95SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%20s %10d\n", 52103f68a95SVasanthakumar Thiagarajan "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi); 52203f68a95SVasanthakumar Thiagarajan 52303f68a95SVasanthakumar Thiagarajan if (len > buf_len) 52403f68a95SVasanthakumar Thiagarajan len = buf_len; 52503f68a95SVasanthakumar Thiagarajan 52603f68a95SVasanthakumar Thiagarajan ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); 52703f68a95SVasanthakumar Thiagarajan 52803f68a95SVasanthakumar Thiagarajan kfree(buf); 52903f68a95SVasanthakumar Thiagarajan return ret_cnt; 53003f68a95SVasanthakumar Thiagarajan } 53103f68a95SVasanthakumar Thiagarajan 53203f68a95SVasanthakumar Thiagarajan static const struct file_operations fops_tgt_stats = { 53303f68a95SVasanthakumar Thiagarajan .read = read_file_tgt_stats, 53403f68a95SVasanthakumar Thiagarajan .open = ath6kl_debugfs_open, 53503f68a95SVasanthakumar Thiagarajan .owner = THIS_MODULE, 53603f68a95SVasanthakumar Thiagarajan .llseek = default_llseek, 53703f68a95SVasanthakumar Thiagarajan }; 53803f68a95SVasanthakumar Thiagarajan 53978fc4856SVasanthakumar Thiagarajan #define print_credit_info(fmt_str, ep_list_field) \ 54078fc4856SVasanthakumar Thiagarajan (len += scnprintf(buf + len, buf_len - len, fmt_str, \ 54178fc4856SVasanthakumar Thiagarajan ep_list->ep_list_field)) 54278fc4856SVasanthakumar Thiagarajan #define CREDIT_INFO_DISPLAY_STRING_LEN 200 54378fc4856SVasanthakumar Thiagarajan #define CREDIT_INFO_LEN 128 54478fc4856SVasanthakumar Thiagarajan 54578fc4856SVasanthakumar Thiagarajan static ssize_t read_file_credit_dist_stats(struct file *file, 54678fc4856SVasanthakumar Thiagarajan char __user *user_buf, 54778fc4856SVasanthakumar Thiagarajan size_t count, loff_t *ppos) 54878fc4856SVasanthakumar Thiagarajan { 54978fc4856SVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data; 55078fc4856SVasanthakumar Thiagarajan struct htc_target *target = ar->htc_target; 55178fc4856SVasanthakumar Thiagarajan struct htc_endpoint_credit_dist *ep_list; 55278fc4856SVasanthakumar Thiagarajan char *buf; 55378fc4856SVasanthakumar Thiagarajan unsigned int buf_len, len = 0; 55478fc4856SVasanthakumar Thiagarajan ssize_t ret_cnt; 55578fc4856SVasanthakumar Thiagarajan 55678fc4856SVasanthakumar Thiagarajan buf_len = CREDIT_INFO_DISPLAY_STRING_LEN + 55778fc4856SVasanthakumar Thiagarajan get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN; 55878fc4856SVasanthakumar Thiagarajan buf = kzalloc(buf_len, GFP_KERNEL); 55978fc4856SVasanthakumar Thiagarajan if (!buf) 56078fc4856SVasanthakumar Thiagarajan return -ENOMEM; 56178fc4856SVasanthakumar Thiagarajan 56278fc4856SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s%5d\n", 56378fc4856SVasanthakumar Thiagarajan "Total Avail Credits: ", 56478fc4856SVasanthakumar Thiagarajan target->cred_dist_cntxt->total_avail_credits); 56578fc4856SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%25s%5d\n", 56678fc4856SVasanthakumar Thiagarajan "Free credits :", 56778fc4856SVasanthakumar Thiagarajan target->cred_dist_cntxt->cur_free_credits); 56878fc4856SVasanthakumar Thiagarajan 56978fc4856SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, 57078fc4856SVasanthakumar Thiagarajan " Epid Flags Cred_norm Cred_min Credits Cred_assngd" 57178fc4856SVasanthakumar Thiagarajan " Seek_cred Cred_sz Cred_per_msg Cred_to_dist" 57278fc4856SVasanthakumar Thiagarajan " qdepth\n"); 57378fc4856SVasanthakumar Thiagarajan 57478fc4856SVasanthakumar Thiagarajan list_for_each_entry(ep_list, &target->cred_dist_list, list) { 57578fc4856SVasanthakumar Thiagarajan print_credit_info(" %2d", endpoint); 57678fc4856SVasanthakumar Thiagarajan print_credit_info("%10x", dist_flags); 57778fc4856SVasanthakumar Thiagarajan print_credit_info("%8d", cred_norm); 57878fc4856SVasanthakumar Thiagarajan print_credit_info("%9d", cred_min); 57978fc4856SVasanthakumar Thiagarajan print_credit_info("%9d", credits); 58078fc4856SVasanthakumar Thiagarajan print_credit_info("%10d", cred_assngd); 58178fc4856SVasanthakumar Thiagarajan print_credit_info("%13d", seek_cred); 58278fc4856SVasanthakumar Thiagarajan print_credit_info("%12d", cred_sz); 58378fc4856SVasanthakumar Thiagarajan print_credit_info("%9d", cred_per_msg); 58478fc4856SVasanthakumar Thiagarajan print_credit_info("%14d", cred_to_dist); 58578fc4856SVasanthakumar Thiagarajan len += scnprintf(buf + len, buf_len - len, "%12d\n", 586*e8c39790SKalle Valo get_queue_depth(&ep_list->htc_ep->txq)); 58778fc4856SVasanthakumar Thiagarajan } 58878fc4856SVasanthakumar Thiagarajan 58978fc4856SVasanthakumar Thiagarajan if (len > buf_len) 59078fc4856SVasanthakumar Thiagarajan len = buf_len; 59178fc4856SVasanthakumar Thiagarajan 59278fc4856SVasanthakumar Thiagarajan ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); 59378fc4856SVasanthakumar Thiagarajan kfree(buf); 59478fc4856SVasanthakumar Thiagarajan return ret_cnt; 59578fc4856SVasanthakumar Thiagarajan } 59678fc4856SVasanthakumar Thiagarajan 59778fc4856SVasanthakumar Thiagarajan static const struct file_operations fops_credit_dist_stats = { 59878fc4856SVasanthakumar Thiagarajan .read = read_file_credit_dist_stats, 59978fc4856SVasanthakumar Thiagarajan .open = ath6kl_debugfs_open, 60078fc4856SVasanthakumar Thiagarajan .owner = THIS_MODULE, 60178fc4856SVasanthakumar Thiagarajan .llseek = default_llseek, 60278fc4856SVasanthakumar Thiagarajan }; 60378fc4856SVasanthakumar Thiagarajan 604e8091281SJouni Malinen static unsigned int print_endpoint_stat(struct htc_target *target, char *buf, 605e8091281SJouni Malinen unsigned int buf_len, unsigned int len, 606e8091281SJouni Malinen int offset, const char *name) 607e8091281SJouni Malinen { 608e8091281SJouni Malinen int i; 609e8091281SJouni Malinen struct htc_endpoint_stats *ep_st; 610e8091281SJouni Malinen u32 *counter; 611e8091281SJouni Malinen 612e8091281SJouni Malinen len += scnprintf(buf + len, buf_len - len, "%s:", name); 613e8091281SJouni Malinen for (i = 0; i < ENDPOINT_MAX; i++) { 614e8091281SJouni Malinen ep_st = &target->endpoint[i].ep_st; 615e8091281SJouni Malinen counter = ((u32 *) ep_st) + (offset / 4); 616e8091281SJouni Malinen len += scnprintf(buf + len, buf_len - len, " %u", *counter); 617e8091281SJouni Malinen } 618e8091281SJouni Malinen len += scnprintf(buf + len, buf_len - len, "\n"); 619e8091281SJouni Malinen 620e8091281SJouni Malinen return len; 621e8091281SJouni Malinen } 622e8091281SJouni Malinen 623e8091281SJouni Malinen static ssize_t ath6kl_endpoint_stats_read(struct file *file, 624e8091281SJouni Malinen char __user *user_buf, 625e8091281SJouni Malinen size_t count, loff_t *ppos) 626e8091281SJouni Malinen { 627e8091281SJouni Malinen struct ath6kl *ar = file->private_data; 628e8091281SJouni Malinen struct htc_target *target = ar->htc_target; 629e8091281SJouni Malinen char *buf; 630e8091281SJouni Malinen unsigned int buf_len, len = 0; 631e8091281SJouni Malinen ssize_t ret_cnt; 632e8091281SJouni Malinen 63317169329SJouni Malinen buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) * 63417169329SJouni Malinen (25 + ENDPOINT_MAX * 11); 63517169329SJouni Malinen buf = kmalloc(buf_len, GFP_KERNEL); 636e8091281SJouni Malinen if (!buf) 637e8091281SJouni Malinen return -ENOMEM; 638e8091281SJouni Malinen 639e8091281SJouni Malinen #define EPSTAT(name) \ 640e8091281SJouni Malinen len = print_endpoint_stat(target, buf, buf_len, len, \ 641e8091281SJouni Malinen offsetof(struct htc_endpoint_stats, name), \ 642e8091281SJouni Malinen #name) 643e8091281SJouni Malinen EPSTAT(cred_low_indicate); 644e8091281SJouni Malinen EPSTAT(tx_issued); 645e8091281SJouni Malinen EPSTAT(tx_pkt_bundled); 646e8091281SJouni Malinen EPSTAT(tx_bundles); 647e8091281SJouni Malinen EPSTAT(tx_dropped); 648e8091281SJouni Malinen EPSTAT(tx_cred_rpt); 649e8091281SJouni Malinen EPSTAT(cred_rpt_from_rx); 65017169329SJouni Malinen EPSTAT(cred_rpt_from_other); 651e8091281SJouni Malinen EPSTAT(cred_rpt_ep0); 652e8091281SJouni Malinen EPSTAT(cred_from_rx); 653e8091281SJouni Malinen EPSTAT(cred_from_other); 654e8091281SJouni Malinen EPSTAT(cred_from_ep0); 655e8091281SJouni Malinen EPSTAT(cred_cosumd); 656e8091281SJouni Malinen EPSTAT(cred_retnd); 657e8091281SJouni Malinen EPSTAT(rx_pkts); 658e8091281SJouni Malinen EPSTAT(rx_lkahds); 659e8091281SJouni Malinen EPSTAT(rx_bundl); 660e8091281SJouni Malinen EPSTAT(rx_bundle_lkahd); 661e8091281SJouni Malinen EPSTAT(rx_bundle_from_hdr); 662e8091281SJouni Malinen EPSTAT(rx_alloc_thresh_hit); 663e8091281SJouni Malinen EPSTAT(rxalloc_thresh_byte); 664e8091281SJouni Malinen #undef EPSTAT 665e8091281SJouni Malinen 666e8091281SJouni Malinen if (len > buf_len) 667e8091281SJouni Malinen len = buf_len; 668e8091281SJouni Malinen 669e8091281SJouni Malinen ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); 670e8091281SJouni Malinen kfree(buf); 671e8091281SJouni Malinen return ret_cnt; 672e8091281SJouni Malinen } 673e8091281SJouni Malinen 674e8091281SJouni Malinen static ssize_t ath6kl_endpoint_stats_write(struct file *file, 675e8091281SJouni Malinen const char __user *user_buf, 676e8091281SJouni Malinen size_t count, loff_t *ppos) 677e8091281SJouni Malinen { 678e8091281SJouni Malinen struct ath6kl *ar = file->private_data; 679e8091281SJouni Malinen struct htc_target *target = ar->htc_target; 680e8091281SJouni Malinen int ret, i; 681e8091281SJouni Malinen u32 val; 682e8091281SJouni Malinen struct htc_endpoint_stats *ep_st; 683e8091281SJouni Malinen 684e8091281SJouni Malinen ret = kstrtou32_from_user(user_buf, count, 0, &val); 685e8091281SJouni Malinen if (ret) 686e8091281SJouni Malinen return ret; 687e8091281SJouni Malinen if (val == 0) { 688e8091281SJouni Malinen for (i = 0; i < ENDPOINT_MAX; i++) { 689e8091281SJouni Malinen ep_st = &target->endpoint[i].ep_st; 690e8091281SJouni Malinen memset(ep_st, 0, sizeof(*ep_st)); 691e8091281SJouni Malinen } 692e8091281SJouni Malinen } 693e8091281SJouni Malinen 694e8091281SJouni Malinen return count; 695e8091281SJouni Malinen } 696e8091281SJouni Malinen 697e8091281SJouni Malinen static const struct file_operations fops_endpoint_stats = { 698e8091281SJouni Malinen .open = ath6kl_debugfs_open, 699e8091281SJouni Malinen .read = ath6kl_endpoint_stats_read, 700e8091281SJouni Malinen .write = ath6kl_endpoint_stats_write, 701e8091281SJouni Malinen .owner = THIS_MODULE, 702e8091281SJouni Malinen .llseek = default_llseek, 703e8091281SJouni Malinen }; 704e8091281SJouni Malinen 70591d57de5SVasanthakumar Thiagarajan static unsigned long ath6kl_get_num_reg(void) 70691d57de5SVasanthakumar Thiagarajan { 70791d57de5SVasanthakumar Thiagarajan int i; 70891d57de5SVasanthakumar Thiagarajan unsigned long n_reg = 0; 70991d57de5SVasanthakumar Thiagarajan 71091d57de5SVasanthakumar Thiagarajan for (i = 0; i < ARRAY_SIZE(diag_reg); i++) 71191d57de5SVasanthakumar Thiagarajan n_reg = n_reg + 71291d57de5SVasanthakumar Thiagarajan (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1; 71391d57de5SVasanthakumar Thiagarajan 71491d57de5SVasanthakumar Thiagarajan return n_reg; 71591d57de5SVasanthakumar Thiagarajan } 71691d57de5SVasanthakumar Thiagarajan 71791d57de5SVasanthakumar Thiagarajan static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr) 71891d57de5SVasanthakumar Thiagarajan { 71991d57de5SVasanthakumar Thiagarajan int i; 72091d57de5SVasanthakumar Thiagarajan 72191d57de5SVasanthakumar Thiagarajan for (i = 0; i < ARRAY_SIZE(diag_reg); i++) { 72291d57de5SVasanthakumar Thiagarajan if (reg_addr >= diag_reg[i].reg_start && 72391d57de5SVasanthakumar Thiagarajan reg_addr <= diag_reg[i].reg_end) 72491d57de5SVasanthakumar Thiagarajan return true; 72591d57de5SVasanthakumar Thiagarajan } 72691d57de5SVasanthakumar Thiagarajan 72791d57de5SVasanthakumar Thiagarajan return false; 72891d57de5SVasanthakumar Thiagarajan } 72991d57de5SVasanthakumar Thiagarajan 73091d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf, 73191d57de5SVasanthakumar Thiagarajan size_t count, loff_t *ppos) 73291d57de5SVasanthakumar Thiagarajan { 73391d57de5SVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data; 73491d57de5SVasanthakumar Thiagarajan u8 buf[50]; 73591d57de5SVasanthakumar Thiagarajan unsigned int len = 0; 73691d57de5SVasanthakumar Thiagarajan 73791d57de5SVasanthakumar Thiagarajan if (ar->debug.dbgfs_diag_reg) 73891d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", 73991d57de5SVasanthakumar Thiagarajan ar->debug.dbgfs_diag_reg); 74091d57de5SVasanthakumar Thiagarajan else 74191d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, sizeof(buf) - len, 74291d57de5SVasanthakumar Thiagarajan "All diag registers\n"); 74391d57de5SVasanthakumar Thiagarajan 74491d57de5SVasanthakumar Thiagarajan return simple_read_from_buffer(user_buf, count, ppos, buf, len); 74591d57de5SVasanthakumar Thiagarajan } 74691d57de5SVasanthakumar Thiagarajan 74791d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regread_write(struct file *file, 74891d57de5SVasanthakumar Thiagarajan const char __user *user_buf, 74991d57de5SVasanthakumar Thiagarajan size_t count, loff_t *ppos) 75091d57de5SVasanthakumar Thiagarajan { 75191d57de5SVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data; 75291d57de5SVasanthakumar Thiagarajan u8 buf[50]; 75391d57de5SVasanthakumar Thiagarajan unsigned int len; 75491d57de5SVasanthakumar Thiagarajan unsigned long reg_addr; 75591d57de5SVasanthakumar Thiagarajan 75691d57de5SVasanthakumar Thiagarajan len = min(count, sizeof(buf) - 1); 75791d57de5SVasanthakumar Thiagarajan if (copy_from_user(buf, user_buf, len)) 75891d57de5SVasanthakumar Thiagarajan return -EFAULT; 75991d57de5SVasanthakumar Thiagarajan 76091d57de5SVasanthakumar Thiagarajan buf[len] = '\0'; 76191d57de5SVasanthakumar Thiagarajan 76291d57de5SVasanthakumar Thiagarajan if (strict_strtoul(buf, 0, ®_addr)) 76391d57de5SVasanthakumar Thiagarajan return -EINVAL; 76491d57de5SVasanthakumar Thiagarajan 76591d57de5SVasanthakumar Thiagarajan if ((reg_addr % 4) != 0) 76691d57de5SVasanthakumar Thiagarajan return -EINVAL; 76791d57de5SVasanthakumar Thiagarajan 76891d57de5SVasanthakumar Thiagarajan if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr)) 76991d57de5SVasanthakumar Thiagarajan return -EINVAL; 77091d57de5SVasanthakumar Thiagarajan 77191d57de5SVasanthakumar Thiagarajan ar->debug.dbgfs_diag_reg = reg_addr; 77291d57de5SVasanthakumar Thiagarajan 77391d57de5SVasanthakumar Thiagarajan return count; 77491d57de5SVasanthakumar Thiagarajan } 77591d57de5SVasanthakumar Thiagarajan 77691d57de5SVasanthakumar Thiagarajan static const struct file_operations fops_diag_reg_read = { 77791d57de5SVasanthakumar Thiagarajan .read = ath6kl_regread_read, 77891d57de5SVasanthakumar Thiagarajan .write = ath6kl_regread_write, 77991d57de5SVasanthakumar Thiagarajan .open = ath6kl_debugfs_open, 78091d57de5SVasanthakumar Thiagarajan .owner = THIS_MODULE, 78191d57de5SVasanthakumar Thiagarajan .llseek = default_llseek, 78291d57de5SVasanthakumar Thiagarajan }; 78391d57de5SVasanthakumar Thiagarajan 78491d57de5SVasanthakumar Thiagarajan static int ath6kl_regdump_open(struct inode *inode, struct file *file) 78591d57de5SVasanthakumar Thiagarajan { 78691d57de5SVasanthakumar Thiagarajan struct ath6kl *ar = inode->i_private; 78791d57de5SVasanthakumar Thiagarajan u8 *buf; 78891d57de5SVasanthakumar Thiagarajan unsigned long int reg_len; 78991d57de5SVasanthakumar Thiagarajan unsigned int len = 0, n_reg; 79091d57de5SVasanthakumar Thiagarajan u32 addr; 79191d57de5SVasanthakumar Thiagarajan __le32 reg_val; 79291d57de5SVasanthakumar Thiagarajan int i, status; 79391d57de5SVasanthakumar Thiagarajan 79491d57de5SVasanthakumar Thiagarajan /* Dump all the registers if no register is specified */ 79591d57de5SVasanthakumar Thiagarajan if (!ar->debug.dbgfs_diag_reg) 79691d57de5SVasanthakumar Thiagarajan n_reg = ath6kl_get_num_reg(); 79791d57de5SVasanthakumar Thiagarajan else 79891d57de5SVasanthakumar Thiagarajan n_reg = 1; 79991d57de5SVasanthakumar Thiagarajan 80091d57de5SVasanthakumar Thiagarajan reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE; 80191d57de5SVasanthakumar Thiagarajan if (n_reg > 1) 80291d57de5SVasanthakumar Thiagarajan reg_len += REGTYPE_STR_LEN; 80391d57de5SVasanthakumar Thiagarajan 80491d57de5SVasanthakumar Thiagarajan buf = vmalloc(reg_len); 80591d57de5SVasanthakumar Thiagarajan if (!buf) 80691d57de5SVasanthakumar Thiagarajan return -ENOMEM; 80791d57de5SVasanthakumar Thiagarajan 80891d57de5SVasanthakumar Thiagarajan if (n_reg == 1) { 80991d57de5SVasanthakumar Thiagarajan addr = ar->debug.dbgfs_diag_reg; 81091d57de5SVasanthakumar Thiagarajan 81191d57de5SVasanthakumar Thiagarajan status = ath6kl_diag_read32(ar, 81291d57de5SVasanthakumar Thiagarajan TARG_VTOP(ar->target_type, addr), 81391d57de5SVasanthakumar Thiagarajan (u32 *)®_val); 81491d57de5SVasanthakumar Thiagarajan if (status) 81591d57de5SVasanthakumar Thiagarajan goto fail_reg_read; 81691d57de5SVasanthakumar Thiagarajan 81791d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, reg_len - len, 81891d57de5SVasanthakumar Thiagarajan "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val)); 81991d57de5SVasanthakumar Thiagarajan goto done; 82091d57de5SVasanthakumar Thiagarajan } 82191d57de5SVasanthakumar Thiagarajan 82291d57de5SVasanthakumar Thiagarajan for (i = 0; i < ARRAY_SIZE(diag_reg); i++) { 82391d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, reg_len - len, 82491d57de5SVasanthakumar Thiagarajan "%s\n", diag_reg[i].reg_info); 82591d57de5SVasanthakumar Thiagarajan for (addr = diag_reg[i].reg_start; 82691d57de5SVasanthakumar Thiagarajan addr <= diag_reg[i].reg_end; addr += 4) { 82791d57de5SVasanthakumar Thiagarajan status = ath6kl_diag_read32(ar, 82891d57de5SVasanthakumar Thiagarajan TARG_VTOP(ar->target_type, addr), 82991d57de5SVasanthakumar Thiagarajan (u32 *)®_val); 83091d57de5SVasanthakumar Thiagarajan if (status) 83191d57de5SVasanthakumar Thiagarajan goto fail_reg_read; 83291d57de5SVasanthakumar Thiagarajan 83391d57de5SVasanthakumar Thiagarajan len += scnprintf(buf + len, reg_len - len, 83491d57de5SVasanthakumar Thiagarajan "0x%06x 0x%08x\n", 83591d57de5SVasanthakumar Thiagarajan addr, le32_to_cpu(reg_val)); 83691d57de5SVasanthakumar Thiagarajan } 83791d57de5SVasanthakumar Thiagarajan } 83891d57de5SVasanthakumar Thiagarajan 83991d57de5SVasanthakumar Thiagarajan done: 84091d57de5SVasanthakumar Thiagarajan file->private_data = buf; 84191d57de5SVasanthakumar Thiagarajan return 0; 84291d57de5SVasanthakumar Thiagarajan 84391d57de5SVasanthakumar Thiagarajan fail_reg_read: 84491d57de5SVasanthakumar Thiagarajan ath6kl_warn("Unable to read memory:%u\n", addr); 84591d57de5SVasanthakumar Thiagarajan vfree(buf); 84691d57de5SVasanthakumar Thiagarajan return -EIO; 84791d57de5SVasanthakumar Thiagarajan } 84891d57de5SVasanthakumar Thiagarajan 84991d57de5SVasanthakumar Thiagarajan static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf, 85091d57de5SVasanthakumar Thiagarajan size_t count, loff_t *ppos) 85191d57de5SVasanthakumar Thiagarajan { 85291d57de5SVasanthakumar Thiagarajan u8 *buf = file->private_data; 85391d57de5SVasanthakumar Thiagarajan return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); 85491d57de5SVasanthakumar Thiagarajan } 85591d57de5SVasanthakumar Thiagarajan 85691d57de5SVasanthakumar Thiagarajan static int ath6kl_regdump_release(struct inode *inode, struct file *file) 85791d57de5SVasanthakumar Thiagarajan { 85891d57de5SVasanthakumar Thiagarajan vfree(file->private_data); 85991d57de5SVasanthakumar Thiagarajan return 0; 86091d57de5SVasanthakumar Thiagarajan } 86191d57de5SVasanthakumar Thiagarajan 86291d57de5SVasanthakumar Thiagarajan static const struct file_operations fops_reg_dump = { 86391d57de5SVasanthakumar Thiagarajan .open = ath6kl_regdump_open, 86491d57de5SVasanthakumar Thiagarajan .read = ath6kl_regdump_read, 86591d57de5SVasanthakumar Thiagarajan .release = ath6kl_regdump_release, 86691d57de5SVasanthakumar Thiagarajan .owner = THIS_MODULE, 86791d57de5SVasanthakumar Thiagarajan .llseek = default_llseek, 86891d57de5SVasanthakumar Thiagarajan }; 86991d57de5SVasanthakumar Thiagarajan 870e5090444SVivek Natarajan static ssize_t ath6kl_lrssi_roam_write(struct file *file, 871e5090444SVivek Natarajan const char __user *user_buf, 872e5090444SVivek Natarajan size_t count, loff_t *ppos) 873e5090444SVivek Natarajan { 874e5090444SVivek Natarajan struct ath6kl *ar = file->private_data; 875e5090444SVivek Natarajan unsigned long lrssi_roam_threshold; 876e5090444SVivek Natarajan char buf[32]; 877e5090444SVivek Natarajan ssize_t len; 878e5090444SVivek Natarajan 879e5090444SVivek Natarajan len = min(count, sizeof(buf) - 1); 880e5090444SVivek Natarajan if (copy_from_user(buf, user_buf, len)) 881e5090444SVivek Natarajan return -EFAULT; 882e5090444SVivek Natarajan 883e5090444SVivek Natarajan buf[len] = '\0'; 884e5090444SVivek Natarajan if (strict_strtoul(buf, 0, &lrssi_roam_threshold)) 885e5090444SVivek Natarajan return -EINVAL; 886e5090444SVivek Natarajan 887e5090444SVivek Natarajan ar->lrssi_roam_threshold = lrssi_roam_threshold; 888e5090444SVivek Natarajan 889e5090444SVivek Natarajan ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold); 890e5090444SVivek Natarajan 891e5090444SVivek Natarajan return count; 892e5090444SVivek Natarajan } 893e5090444SVivek Natarajan 894e5090444SVivek Natarajan static ssize_t ath6kl_lrssi_roam_read(struct file *file, 895e5090444SVivek Natarajan char __user *user_buf, 896e5090444SVivek Natarajan size_t count, loff_t *ppos) 897e5090444SVivek Natarajan { 898e5090444SVivek Natarajan struct ath6kl *ar = file->private_data; 899e5090444SVivek Natarajan char buf[32]; 900e5090444SVivek Natarajan unsigned int len; 901e5090444SVivek Natarajan 902e5090444SVivek Natarajan len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold); 903e5090444SVivek Natarajan 904e5090444SVivek Natarajan return simple_read_from_buffer(user_buf, count, ppos, buf, len); 905e5090444SVivek Natarajan } 906e5090444SVivek Natarajan 907e5090444SVivek Natarajan static const struct file_operations fops_lrssi_roam_threshold = { 908e5090444SVivek Natarajan .read = ath6kl_lrssi_roam_read, 909e5090444SVivek Natarajan .write = ath6kl_lrssi_roam_write, 910e5090444SVivek Natarajan .open = ath6kl_debugfs_open, 911e5090444SVivek Natarajan .owner = THIS_MODULE, 912e5090444SVivek Natarajan .llseek = default_llseek, 913e5090444SVivek Natarajan }; 914e5090444SVivek Natarajan 915252c068bSVasanthakumar Thiagarajan static ssize_t ath6kl_regwrite_read(struct file *file, 916252c068bSVasanthakumar Thiagarajan char __user *user_buf, 917252c068bSVasanthakumar Thiagarajan size_t count, loff_t *ppos) 918252c068bSVasanthakumar Thiagarajan { 919252c068bSVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data; 920252c068bSVasanthakumar Thiagarajan u8 buf[32]; 921252c068bSVasanthakumar Thiagarajan unsigned int len = 0; 922252c068bSVasanthakumar Thiagarajan 923252c068bSVasanthakumar Thiagarajan len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n", 924252c068bSVasanthakumar Thiagarajan ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr); 925252c068bSVasanthakumar Thiagarajan 926252c068bSVasanthakumar Thiagarajan return simple_read_from_buffer(user_buf, count, ppos, buf, len); 927252c068bSVasanthakumar Thiagarajan } 928252c068bSVasanthakumar Thiagarajan 929252c068bSVasanthakumar Thiagarajan static ssize_t ath6kl_regwrite_write(struct file *file, 930252c068bSVasanthakumar Thiagarajan const char __user *user_buf, 931252c068bSVasanthakumar Thiagarajan size_t count, loff_t *ppos) 932252c068bSVasanthakumar Thiagarajan { 933252c068bSVasanthakumar Thiagarajan struct ath6kl *ar = file->private_data; 934252c068bSVasanthakumar Thiagarajan char buf[32]; 935252c068bSVasanthakumar Thiagarajan char *sptr, *token; 936252c068bSVasanthakumar Thiagarajan unsigned int len = 0; 937252c068bSVasanthakumar Thiagarajan u32 reg_addr, reg_val; 938252c068bSVasanthakumar Thiagarajan 939252c068bSVasanthakumar Thiagarajan len = min(count, sizeof(buf) - 1); 940252c068bSVasanthakumar Thiagarajan if (copy_from_user(buf, user_buf, len)) 941252c068bSVasanthakumar Thiagarajan return -EFAULT; 942252c068bSVasanthakumar Thiagarajan 943252c068bSVasanthakumar Thiagarajan buf[len] = '\0'; 944252c068bSVasanthakumar Thiagarajan sptr = buf; 945252c068bSVasanthakumar Thiagarajan 946252c068bSVasanthakumar Thiagarajan token = strsep(&sptr, "="); 947252c068bSVasanthakumar Thiagarajan if (!token) 948252c068bSVasanthakumar Thiagarajan return -EINVAL; 949252c068bSVasanthakumar Thiagarajan 950252c068bSVasanthakumar Thiagarajan if (kstrtou32(token, 0, ®_addr)) 951252c068bSVasanthakumar Thiagarajan return -EINVAL; 952252c068bSVasanthakumar Thiagarajan 953252c068bSVasanthakumar Thiagarajan if (!ath6kl_dbg_is_diag_reg_valid(reg_addr)) 954252c068bSVasanthakumar Thiagarajan return -EINVAL; 955252c068bSVasanthakumar Thiagarajan 956252c068bSVasanthakumar Thiagarajan if (kstrtou32(sptr, 0, ®_val)) 957252c068bSVasanthakumar Thiagarajan return -EINVAL; 958252c068bSVasanthakumar Thiagarajan 959252c068bSVasanthakumar Thiagarajan ar->debug.diag_reg_addr_wr = reg_addr; 960252c068bSVasanthakumar Thiagarajan ar->debug.diag_reg_val_wr = reg_val; 961252c068bSVasanthakumar Thiagarajan 962252c068bSVasanthakumar Thiagarajan if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr, 963252c068bSVasanthakumar Thiagarajan cpu_to_le32(ar->debug.diag_reg_val_wr))) 964252c068bSVasanthakumar Thiagarajan return -EIO; 965252c068bSVasanthakumar Thiagarajan 966252c068bSVasanthakumar Thiagarajan return count; 967252c068bSVasanthakumar Thiagarajan } 968252c068bSVasanthakumar Thiagarajan 969252c068bSVasanthakumar Thiagarajan static const struct file_operations fops_diag_reg_write = { 970252c068bSVasanthakumar Thiagarajan .read = ath6kl_regwrite_read, 971252c068bSVasanthakumar Thiagarajan .write = ath6kl_regwrite_write, 972252c068bSVasanthakumar Thiagarajan .open = ath6kl_debugfs_open, 973252c068bSVasanthakumar Thiagarajan .owner = THIS_MODULE, 974252c068bSVasanthakumar Thiagarajan .llseek = default_llseek, 975252c068bSVasanthakumar Thiagarajan }; 976252c068bSVasanthakumar Thiagarajan 9774b28a80dSJouni Malinen int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf, 9784b28a80dSJouni Malinen size_t len) 9794b28a80dSJouni Malinen { 9804b28a80dSJouni Malinen const struct wmi_target_roam_tbl *tbl; 9814b28a80dSJouni Malinen u16 num_entries; 9824b28a80dSJouni Malinen 9834b28a80dSJouni Malinen if (len < sizeof(*tbl)) 9844b28a80dSJouni Malinen return -EINVAL; 9854b28a80dSJouni Malinen 9864b28a80dSJouni Malinen tbl = (const struct wmi_target_roam_tbl *) buf; 9874b28a80dSJouni Malinen num_entries = le16_to_cpu(tbl->num_entries); 9884b28a80dSJouni Malinen if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) > 9894b28a80dSJouni Malinen len) 9904b28a80dSJouni Malinen return -EINVAL; 9914b28a80dSJouni Malinen 9924b28a80dSJouni Malinen if (ar->debug.roam_tbl == NULL || 9934b28a80dSJouni Malinen ar->debug.roam_tbl_len < (unsigned int) len) { 9944b28a80dSJouni Malinen kfree(ar->debug.roam_tbl); 9954b28a80dSJouni Malinen ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC); 9964b28a80dSJouni Malinen if (ar->debug.roam_tbl == NULL) 9974b28a80dSJouni Malinen return -ENOMEM; 9984b28a80dSJouni Malinen } 9994b28a80dSJouni Malinen 10004b28a80dSJouni Malinen memcpy(ar->debug.roam_tbl, buf, len); 10014b28a80dSJouni Malinen ar->debug.roam_tbl_len = len; 10024b28a80dSJouni Malinen 10034b28a80dSJouni Malinen if (test_bit(ROAM_TBL_PEND, &ar->flag)) { 10044b28a80dSJouni Malinen clear_bit(ROAM_TBL_PEND, &ar->flag); 10054b28a80dSJouni Malinen wake_up(&ar->event_wq); 10064b28a80dSJouni Malinen } 10074b28a80dSJouni Malinen 10084b28a80dSJouni Malinen return 0; 10094b28a80dSJouni Malinen } 10104b28a80dSJouni Malinen 10114b28a80dSJouni Malinen static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf, 10124b28a80dSJouni Malinen size_t count, loff_t *ppos) 10134b28a80dSJouni Malinen { 10144b28a80dSJouni Malinen struct ath6kl *ar = file->private_data; 10154b28a80dSJouni Malinen int ret; 10164b28a80dSJouni Malinen long left; 10174b28a80dSJouni Malinen struct wmi_target_roam_tbl *tbl; 10184b28a80dSJouni Malinen u16 num_entries, i; 10194b28a80dSJouni Malinen char *buf; 10204b28a80dSJouni Malinen unsigned int len, buf_len; 10214b28a80dSJouni Malinen ssize_t ret_cnt; 10224b28a80dSJouni Malinen 10234b28a80dSJouni Malinen if (down_interruptible(&ar->sem)) 10244b28a80dSJouni Malinen return -EBUSY; 10254b28a80dSJouni Malinen 10264b28a80dSJouni Malinen set_bit(ROAM_TBL_PEND, &ar->flag); 10274b28a80dSJouni Malinen 10284b28a80dSJouni Malinen ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi); 10294b28a80dSJouni Malinen if (ret) { 10304b28a80dSJouni Malinen up(&ar->sem); 10314b28a80dSJouni Malinen return ret; 10324b28a80dSJouni Malinen } 10334b28a80dSJouni Malinen 10344b28a80dSJouni Malinen left = wait_event_interruptible_timeout( 10354b28a80dSJouni Malinen ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT); 10364b28a80dSJouni Malinen up(&ar->sem); 10374b28a80dSJouni Malinen 10384b28a80dSJouni Malinen if (left <= 0) 10394b28a80dSJouni Malinen return -ETIMEDOUT; 10404b28a80dSJouni Malinen 10414b28a80dSJouni Malinen if (ar->debug.roam_tbl == NULL) 10424b28a80dSJouni Malinen return -ENOMEM; 10434b28a80dSJouni Malinen 10444b28a80dSJouni Malinen tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl; 10454b28a80dSJouni Malinen num_entries = le16_to_cpu(tbl->num_entries); 10464b28a80dSJouni Malinen 10474b28a80dSJouni Malinen buf_len = 100 + num_entries * 100; 10484b28a80dSJouni Malinen buf = kzalloc(buf_len, GFP_KERNEL); 10494b28a80dSJouni Malinen if (buf == NULL) 10504b28a80dSJouni Malinen return -ENOMEM; 10514b28a80dSJouni Malinen len = 0; 10524b28a80dSJouni Malinen len += scnprintf(buf + len, buf_len - len, 10534b28a80dSJouni Malinen "roam_mode=%u\n\n" 10544b28a80dSJouni Malinen "# roam_util bssid rssi rssidt last_rssi util bias\n", 10554b28a80dSJouni Malinen le16_to_cpu(tbl->roam_mode)); 10564b28a80dSJouni Malinen 10574b28a80dSJouni Malinen for (i = 0; i < num_entries; i++) { 10584b28a80dSJouni Malinen struct wmi_bss_roam_info *info = &tbl->info[i]; 10594b28a80dSJouni Malinen len += scnprintf(buf + len, buf_len - len, 10604b28a80dSJouni Malinen "%d %pM %d %d %d %d %d\n", 10614b28a80dSJouni Malinen a_sle32_to_cpu(info->roam_util), info->bssid, 10624b28a80dSJouni Malinen info->rssi, info->rssidt, info->last_rssi, 10634b28a80dSJouni Malinen info->util, info->bias); 10644b28a80dSJouni Malinen } 10654b28a80dSJouni Malinen 10664b28a80dSJouni Malinen if (len > buf_len) 10674b28a80dSJouni Malinen len = buf_len; 10684b28a80dSJouni Malinen 10694b28a80dSJouni Malinen ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len); 10704b28a80dSJouni Malinen 10714b28a80dSJouni Malinen kfree(buf); 10724b28a80dSJouni Malinen return ret_cnt; 10734b28a80dSJouni Malinen } 10744b28a80dSJouni Malinen 10754b28a80dSJouni Malinen static const struct file_operations fops_roam_table = { 10764b28a80dSJouni Malinen .read = ath6kl_roam_table_read, 10774b28a80dSJouni Malinen .open = ath6kl_debugfs_open, 10784b28a80dSJouni Malinen .owner = THIS_MODULE, 10794b28a80dSJouni Malinen .llseek = default_llseek, 10804b28a80dSJouni Malinen }; 10814b28a80dSJouni Malinen 10821261875fSJouni Malinen static ssize_t ath6kl_force_roam_write(struct file *file, 10831261875fSJouni Malinen const char __user *user_buf, 10841261875fSJouni Malinen size_t count, loff_t *ppos) 10851261875fSJouni Malinen { 10861261875fSJouni Malinen struct ath6kl *ar = file->private_data; 10871261875fSJouni Malinen int ret; 10881261875fSJouni Malinen char buf[20]; 10891261875fSJouni Malinen size_t len; 10901261875fSJouni Malinen u8 bssid[ETH_ALEN]; 10911261875fSJouni Malinen int i; 10921261875fSJouni Malinen int addr[ETH_ALEN]; 10931261875fSJouni Malinen 10941261875fSJouni Malinen len = min(count, sizeof(buf) - 1); 10951261875fSJouni Malinen if (copy_from_user(buf, user_buf, len)) 10961261875fSJouni Malinen return -EFAULT; 10971261875fSJouni Malinen buf[len] = '\0'; 10981261875fSJouni Malinen 10991261875fSJouni Malinen if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", 11001261875fSJouni Malinen &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) 11011261875fSJouni Malinen != ETH_ALEN) 11021261875fSJouni Malinen return -EINVAL; 11031261875fSJouni Malinen for (i = 0; i < ETH_ALEN; i++) 11041261875fSJouni Malinen bssid[i] = addr[i]; 11051261875fSJouni Malinen 11061261875fSJouni Malinen ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid); 11071261875fSJouni Malinen if (ret) 11081261875fSJouni Malinen return ret; 11091261875fSJouni Malinen 11101261875fSJouni Malinen return count; 11111261875fSJouni Malinen } 11121261875fSJouni Malinen 11131261875fSJouni Malinen static const struct file_operations fops_force_roam = { 11141261875fSJouni Malinen .write = ath6kl_force_roam_write, 11151261875fSJouni Malinen .open = ath6kl_debugfs_open, 11161261875fSJouni Malinen .owner = THIS_MODULE, 11171261875fSJouni Malinen .llseek = default_llseek, 11181261875fSJouni Malinen }; 11191261875fSJouni Malinen 11201261875fSJouni Malinen static ssize_t ath6kl_roam_mode_write(struct file *file, 11211261875fSJouni Malinen const char __user *user_buf, 11221261875fSJouni Malinen size_t count, loff_t *ppos) 11231261875fSJouni Malinen { 11241261875fSJouni Malinen struct ath6kl *ar = file->private_data; 11251261875fSJouni Malinen int ret; 11261261875fSJouni Malinen char buf[20]; 11271261875fSJouni Malinen size_t len; 11281261875fSJouni Malinen enum wmi_roam_mode mode; 11291261875fSJouni Malinen 11301261875fSJouni Malinen len = min(count, sizeof(buf) - 1); 11311261875fSJouni Malinen if (copy_from_user(buf, user_buf, len)) 11321261875fSJouni Malinen return -EFAULT; 11331261875fSJouni Malinen buf[len] = '\0'; 11341261875fSJouni Malinen if (len > 0 && buf[len - 1] == '\n') 11351261875fSJouni Malinen buf[len - 1] = '\0'; 11361261875fSJouni Malinen 11371261875fSJouni Malinen if (strcasecmp(buf, "default") == 0) 11381261875fSJouni Malinen mode = WMI_DEFAULT_ROAM_MODE; 11391261875fSJouni Malinen else if (strcasecmp(buf, "bssbias") == 0) 11401261875fSJouni Malinen mode = WMI_HOST_BIAS_ROAM_MODE; 11411261875fSJouni Malinen else if (strcasecmp(buf, "lock") == 0) 11421261875fSJouni Malinen mode = WMI_LOCK_BSS_MODE; 11431261875fSJouni Malinen else 11441261875fSJouni Malinen return -EINVAL; 11451261875fSJouni Malinen 11461261875fSJouni Malinen ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode); 11471261875fSJouni Malinen if (ret) 11481261875fSJouni Malinen return ret; 11491261875fSJouni Malinen 11501261875fSJouni Malinen return count; 11511261875fSJouni Malinen } 11521261875fSJouni Malinen 11531261875fSJouni Malinen static const struct file_operations fops_roam_mode = { 11541261875fSJouni Malinen .write = ath6kl_roam_mode_write, 11551261875fSJouni Malinen .open = ath6kl_debugfs_open, 11561261875fSJouni Malinen .owner = THIS_MODULE, 11571261875fSJouni Malinen .llseek = default_llseek, 11581261875fSJouni Malinen }; 11591261875fSJouni Malinen 1160ff0b0075SJouni Malinen void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive) 1161ff0b0075SJouni Malinen { 1162ff0b0075SJouni Malinen ar->debug.keepalive = keepalive; 1163ff0b0075SJouni Malinen } 1164ff0b0075SJouni Malinen 1165ff0b0075SJouni Malinen static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf, 1166ff0b0075SJouni Malinen size_t count, loff_t *ppos) 1167ff0b0075SJouni Malinen { 1168ff0b0075SJouni Malinen struct ath6kl *ar = file->private_data; 1169ff0b0075SJouni Malinen char buf[16]; 1170ff0b0075SJouni Malinen int len; 1171ff0b0075SJouni Malinen 1172ff0b0075SJouni Malinen len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive); 1173ff0b0075SJouni Malinen 1174ff0b0075SJouni Malinen return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1175ff0b0075SJouni Malinen } 1176ff0b0075SJouni Malinen 1177ff0b0075SJouni Malinen static ssize_t ath6kl_keepalive_write(struct file *file, 1178ff0b0075SJouni Malinen const char __user *user_buf, 1179ff0b0075SJouni Malinen size_t count, loff_t *ppos) 1180ff0b0075SJouni Malinen { 1181ff0b0075SJouni Malinen struct ath6kl *ar = file->private_data; 1182ff0b0075SJouni Malinen int ret; 1183ff0b0075SJouni Malinen u8 val; 1184ff0b0075SJouni Malinen 1185ff0b0075SJouni Malinen ret = kstrtou8_from_user(user_buf, count, 0, &val); 1186ff0b0075SJouni Malinen if (ret) 1187ff0b0075SJouni Malinen return ret; 1188ff0b0075SJouni Malinen 11890ce59445SVasanthakumar Thiagarajan ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, 0, val); 1190ff0b0075SJouni Malinen if (ret) 1191ff0b0075SJouni Malinen return ret; 1192ff0b0075SJouni Malinen 1193ff0b0075SJouni Malinen return count; 1194ff0b0075SJouni Malinen } 1195ff0b0075SJouni Malinen 1196ff0b0075SJouni Malinen static const struct file_operations fops_keepalive = { 1197ff0b0075SJouni Malinen .open = ath6kl_debugfs_open, 1198ff0b0075SJouni Malinen .read = ath6kl_keepalive_read, 1199ff0b0075SJouni Malinen .write = ath6kl_keepalive_write, 1200ff0b0075SJouni Malinen .owner = THIS_MODULE, 1201ff0b0075SJouni Malinen .llseek = default_llseek, 1202ff0b0075SJouni Malinen }; 1203ff0b0075SJouni Malinen 1204ff0b0075SJouni Malinen void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout) 1205ff0b0075SJouni Malinen { 1206ff0b0075SJouni Malinen ar->debug.disc_timeout = timeout; 1207ff0b0075SJouni Malinen } 1208ff0b0075SJouni Malinen 1209ff0b0075SJouni Malinen static ssize_t ath6kl_disconnect_timeout_read(struct file *file, 1210ff0b0075SJouni Malinen char __user *user_buf, 1211ff0b0075SJouni Malinen size_t count, loff_t *ppos) 1212ff0b0075SJouni Malinen { 1213ff0b0075SJouni Malinen struct ath6kl *ar = file->private_data; 1214ff0b0075SJouni Malinen char buf[16]; 1215ff0b0075SJouni Malinen int len; 1216ff0b0075SJouni Malinen 1217ff0b0075SJouni Malinen len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout); 1218ff0b0075SJouni Malinen 1219ff0b0075SJouni Malinen return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1220ff0b0075SJouni Malinen } 1221ff0b0075SJouni Malinen 1222ff0b0075SJouni Malinen static ssize_t ath6kl_disconnect_timeout_write(struct file *file, 1223ff0b0075SJouni Malinen const char __user *user_buf, 1224ff0b0075SJouni Malinen size_t count, loff_t *ppos) 1225ff0b0075SJouni Malinen { 1226ff0b0075SJouni Malinen struct ath6kl *ar = file->private_data; 1227ff0b0075SJouni Malinen int ret; 1228ff0b0075SJouni Malinen u8 val; 1229ff0b0075SJouni Malinen 1230ff0b0075SJouni Malinen ret = kstrtou8_from_user(user_buf, count, 0, &val); 1231ff0b0075SJouni Malinen if (ret) 1232ff0b0075SJouni Malinen return ret; 1233ff0b0075SJouni Malinen 12340ce59445SVasanthakumar Thiagarajan ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, 0, val); 1235ff0b0075SJouni Malinen if (ret) 1236ff0b0075SJouni Malinen return ret; 1237ff0b0075SJouni Malinen 1238ff0b0075SJouni Malinen return count; 1239ff0b0075SJouni Malinen } 1240ff0b0075SJouni Malinen 1241ff0b0075SJouni Malinen static const struct file_operations fops_disconnect_timeout = { 1242ff0b0075SJouni Malinen .open = ath6kl_debugfs_open, 1243ff0b0075SJouni Malinen .read = ath6kl_disconnect_timeout_read, 1244ff0b0075SJouni Malinen .write = ath6kl_disconnect_timeout_write, 1245ff0b0075SJouni Malinen .owner = THIS_MODULE, 1246ff0b0075SJouni Malinen .llseek = default_llseek, 1247ff0b0075SJouni Malinen }; 1248ff0b0075SJouni Malinen 12498fffd9e5SRishi Panjwani static ssize_t ath6kl_create_qos_write(struct file *file, 12508fffd9e5SRishi Panjwani const char __user *user_buf, 12518fffd9e5SRishi Panjwani size_t count, loff_t *ppos) 12528fffd9e5SRishi Panjwani { 12538fffd9e5SRishi Panjwani 12548fffd9e5SRishi Panjwani struct ath6kl *ar = file->private_data; 1255990bd915SVasanthakumar Thiagarajan struct ath6kl_vif *vif; 12568fffd9e5SRishi Panjwani char buf[100]; 12578fffd9e5SRishi Panjwani ssize_t len; 12588fffd9e5SRishi Panjwani char *sptr, *token; 12598fffd9e5SRishi Panjwani struct wmi_create_pstream_cmd pstream; 12608fffd9e5SRishi Panjwani u32 val32; 12618fffd9e5SRishi Panjwani u16 val16; 12628fffd9e5SRishi Panjwani 1263990bd915SVasanthakumar Thiagarajan vif = ath6kl_vif_first(ar); 1264990bd915SVasanthakumar Thiagarajan if (!vif) 1265990bd915SVasanthakumar Thiagarajan return -EIO; 1266990bd915SVasanthakumar Thiagarajan 12678fffd9e5SRishi Panjwani len = min(count, sizeof(buf) - 1); 12688fffd9e5SRishi Panjwani if (copy_from_user(buf, user_buf, len)) 12698fffd9e5SRishi Panjwani return -EFAULT; 12708fffd9e5SRishi Panjwani buf[len] = '\0'; 12718fffd9e5SRishi Panjwani sptr = buf; 12728fffd9e5SRishi Panjwani 12738fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 12748fffd9e5SRishi Panjwani if (!token) 12758fffd9e5SRishi Panjwani return -EINVAL; 12768fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.user_pri)) 12778fffd9e5SRishi Panjwani return -EINVAL; 12788fffd9e5SRishi Panjwani 12798fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 12808fffd9e5SRishi Panjwani if (!token) 12818fffd9e5SRishi Panjwani return -EINVAL; 12828fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.traffic_direc)) 12838fffd9e5SRishi Panjwani return -EINVAL; 12848fffd9e5SRishi Panjwani 12858fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 12868fffd9e5SRishi Panjwani if (!token) 12878fffd9e5SRishi Panjwani return -EINVAL; 12888fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.traffic_class)) 12898fffd9e5SRishi Panjwani return -EINVAL; 12908fffd9e5SRishi Panjwani 12918fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 12928fffd9e5SRishi Panjwani if (!token) 12938fffd9e5SRishi Panjwani return -EINVAL; 12948fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.traffic_type)) 12958fffd9e5SRishi Panjwani return -EINVAL; 12968fffd9e5SRishi Panjwani 12978fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 12988fffd9e5SRishi Panjwani if (!token) 12998fffd9e5SRishi Panjwani return -EINVAL; 13008fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.voice_psc_cap)) 13018fffd9e5SRishi Panjwani return -EINVAL; 13028fffd9e5SRishi Panjwani 13038fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13048fffd9e5SRishi Panjwani if (!token) 13058fffd9e5SRishi Panjwani return -EINVAL; 13068fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13078fffd9e5SRishi Panjwani return -EINVAL; 13088fffd9e5SRishi Panjwani pstream.min_service_int = cpu_to_le32(val32); 13098fffd9e5SRishi Panjwani 13108fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13118fffd9e5SRishi Panjwani if (!token) 13128fffd9e5SRishi Panjwani return -EINVAL; 13138fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13148fffd9e5SRishi Panjwani return -EINVAL; 13158fffd9e5SRishi Panjwani pstream.max_service_int = cpu_to_le32(val32); 13168fffd9e5SRishi Panjwani 13178fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13188fffd9e5SRishi Panjwani if (!token) 13198fffd9e5SRishi Panjwani return -EINVAL; 13208fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13218fffd9e5SRishi Panjwani return -EINVAL; 13228fffd9e5SRishi Panjwani pstream.inactivity_int = cpu_to_le32(val32); 13238fffd9e5SRishi Panjwani 13248fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13258fffd9e5SRishi Panjwani if (!token) 13268fffd9e5SRishi Panjwani return -EINVAL; 13278fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13288fffd9e5SRishi Panjwani return -EINVAL; 13298fffd9e5SRishi Panjwani pstream.suspension_int = cpu_to_le32(val32); 13308fffd9e5SRishi Panjwani 13318fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13328fffd9e5SRishi Panjwani if (!token) 13338fffd9e5SRishi Panjwani return -EINVAL; 13348fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13358fffd9e5SRishi Panjwani return -EINVAL; 13368fffd9e5SRishi Panjwani pstream.service_start_time = cpu_to_le32(val32); 13378fffd9e5SRishi Panjwani 13388fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13398fffd9e5SRishi Panjwani if (!token) 13408fffd9e5SRishi Panjwani return -EINVAL; 13418fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &pstream.tsid)) 13428fffd9e5SRishi Panjwani return -EINVAL; 13438fffd9e5SRishi Panjwani 13448fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13458fffd9e5SRishi Panjwani if (!token) 13468fffd9e5SRishi Panjwani return -EINVAL; 13478fffd9e5SRishi Panjwani if (kstrtou16(token, 0, &val16)) 13488fffd9e5SRishi Panjwani return -EINVAL; 13498fffd9e5SRishi Panjwani pstream.nominal_msdu = cpu_to_le16(val16); 13508fffd9e5SRishi Panjwani 13518fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13528fffd9e5SRishi Panjwani if (!token) 13538fffd9e5SRishi Panjwani return -EINVAL; 13548fffd9e5SRishi Panjwani if (kstrtou16(token, 0, &val16)) 13558fffd9e5SRishi Panjwani return -EINVAL; 13568fffd9e5SRishi Panjwani pstream.max_msdu = cpu_to_le16(val16); 13578fffd9e5SRishi Panjwani 13588fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13598fffd9e5SRishi Panjwani if (!token) 13608fffd9e5SRishi Panjwani return -EINVAL; 13618fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13628fffd9e5SRishi Panjwani return -EINVAL; 13638fffd9e5SRishi Panjwani pstream.min_data_rate = cpu_to_le32(val32); 13648fffd9e5SRishi Panjwani 13658fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13668fffd9e5SRishi Panjwani if (!token) 13678fffd9e5SRishi Panjwani return -EINVAL; 13688fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13698fffd9e5SRishi Panjwani return -EINVAL; 13708fffd9e5SRishi Panjwani pstream.mean_data_rate = cpu_to_le32(val32); 13718fffd9e5SRishi Panjwani 13728fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13738fffd9e5SRishi Panjwani if (!token) 13748fffd9e5SRishi Panjwani return -EINVAL; 13758fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13768fffd9e5SRishi Panjwani return -EINVAL; 13778fffd9e5SRishi Panjwani pstream.peak_data_rate = cpu_to_le32(val32); 13788fffd9e5SRishi Panjwani 13798fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13808fffd9e5SRishi Panjwani if (!token) 13818fffd9e5SRishi Panjwani return -EINVAL; 13828fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13838fffd9e5SRishi Panjwani return -EINVAL; 13848fffd9e5SRishi Panjwani pstream.max_burst_size = cpu_to_le32(val32); 13858fffd9e5SRishi Panjwani 13868fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13878fffd9e5SRishi Panjwani if (!token) 13888fffd9e5SRishi Panjwani return -EINVAL; 13898fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13908fffd9e5SRishi Panjwani return -EINVAL; 13918fffd9e5SRishi Panjwani pstream.delay_bound = cpu_to_le32(val32); 13928fffd9e5SRishi Panjwani 13938fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 13948fffd9e5SRishi Panjwani if (!token) 13958fffd9e5SRishi Panjwani return -EINVAL; 13968fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 13978fffd9e5SRishi Panjwani return -EINVAL; 13988fffd9e5SRishi Panjwani pstream.min_phy_rate = cpu_to_le32(val32); 13998fffd9e5SRishi Panjwani 14008fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 14018fffd9e5SRishi Panjwani if (!token) 14028fffd9e5SRishi Panjwani return -EINVAL; 14038fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 14048fffd9e5SRishi Panjwani return -EINVAL; 14058fffd9e5SRishi Panjwani pstream.sba = cpu_to_le32(val32); 14068fffd9e5SRishi Panjwani 14078fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 14088fffd9e5SRishi Panjwani if (!token) 14098fffd9e5SRishi Panjwani return -EINVAL; 14108fffd9e5SRishi Panjwani if (kstrtou32(token, 0, &val32)) 14118fffd9e5SRishi Panjwani return -EINVAL; 14128fffd9e5SRishi Panjwani pstream.medium_time = cpu_to_le32(val32); 14138fffd9e5SRishi Panjwani 1414240d2799SVasanthakumar Thiagarajan ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream); 14158fffd9e5SRishi Panjwani 14168fffd9e5SRishi Panjwani return count; 14178fffd9e5SRishi Panjwani } 14188fffd9e5SRishi Panjwani 14198fffd9e5SRishi Panjwani static const struct file_operations fops_create_qos = { 14208fffd9e5SRishi Panjwani .write = ath6kl_create_qos_write, 14218fffd9e5SRishi Panjwani .open = ath6kl_debugfs_open, 14228fffd9e5SRishi Panjwani .owner = THIS_MODULE, 14238fffd9e5SRishi Panjwani .llseek = default_llseek, 14248fffd9e5SRishi Panjwani }; 14258fffd9e5SRishi Panjwani 14268fffd9e5SRishi Panjwani static ssize_t ath6kl_delete_qos_write(struct file *file, 14278fffd9e5SRishi Panjwani const char __user *user_buf, 14288fffd9e5SRishi Panjwani size_t count, loff_t *ppos) 14298fffd9e5SRishi Panjwani { 14308fffd9e5SRishi Panjwani 14318fffd9e5SRishi Panjwani struct ath6kl *ar = file->private_data; 1432990bd915SVasanthakumar Thiagarajan struct ath6kl_vif *vif; 14338fffd9e5SRishi Panjwani char buf[100]; 14348fffd9e5SRishi Panjwani ssize_t len; 14358fffd9e5SRishi Panjwani char *sptr, *token; 14368fffd9e5SRishi Panjwani u8 traffic_class; 14378fffd9e5SRishi Panjwani u8 tsid; 14388fffd9e5SRishi Panjwani 1439990bd915SVasanthakumar Thiagarajan vif = ath6kl_vif_first(ar); 1440990bd915SVasanthakumar Thiagarajan if (!vif) 1441990bd915SVasanthakumar Thiagarajan return -EIO; 1442990bd915SVasanthakumar Thiagarajan 14438fffd9e5SRishi Panjwani len = min(count, sizeof(buf) - 1); 14448fffd9e5SRishi Panjwani if (copy_from_user(buf, user_buf, len)) 14458fffd9e5SRishi Panjwani return -EFAULT; 14468fffd9e5SRishi Panjwani buf[len] = '\0'; 14478fffd9e5SRishi Panjwani sptr = buf; 14488fffd9e5SRishi Panjwani 14498fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 14508fffd9e5SRishi Panjwani if (!token) 14518fffd9e5SRishi Panjwani return -EINVAL; 14528fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &traffic_class)) 14538fffd9e5SRishi Panjwani return -EINVAL; 14548fffd9e5SRishi Panjwani 14558fffd9e5SRishi Panjwani token = strsep(&sptr, " "); 14568fffd9e5SRishi Panjwani if (!token) 14578fffd9e5SRishi Panjwani return -EINVAL; 14588fffd9e5SRishi Panjwani if (kstrtou8(token, 0, &tsid)) 14598fffd9e5SRishi Panjwani return -EINVAL; 14608fffd9e5SRishi Panjwani 1461240d2799SVasanthakumar Thiagarajan ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx, 1462240d2799SVasanthakumar Thiagarajan traffic_class, tsid); 14638fffd9e5SRishi Panjwani 14648fffd9e5SRishi Panjwani return count; 14658fffd9e5SRishi Panjwani } 14668fffd9e5SRishi Panjwani 14678fffd9e5SRishi Panjwani static const struct file_operations fops_delete_qos = { 14688fffd9e5SRishi Panjwani .write = ath6kl_delete_qos_write, 14698fffd9e5SRishi Panjwani .open = ath6kl_debugfs_open, 14708fffd9e5SRishi Panjwani .owner = THIS_MODULE, 14718fffd9e5SRishi Panjwani .llseek = default_llseek, 14728fffd9e5SRishi Panjwani }; 14738fffd9e5SRishi Panjwani 1474116b3a2eSRishi Panjwani static ssize_t ath6kl_bgscan_int_write(struct file *file, 1475116b3a2eSRishi Panjwani const char __user *user_buf, 1476116b3a2eSRishi Panjwani size_t count, loff_t *ppos) 1477116b3a2eSRishi Panjwani { 1478116b3a2eSRishi Panjwani struct ath6kl *ar = file->private_data; 1479116b3a2eSRishi Panjwani u16 bgscan_int; 1480116b3a2eSRishi Panjwani char buf[32]; 1481116b3a2eSRishi Panjwani ssize_t len; 1482116b3a2eSRishi Panjwani 1483116b3a2eSRishi Panjwani len = min(count, sizeof(buf) - 1); 1484116b3a2eSRishi Panjwani if (copy_from_user(buf, user_buf, len)) 1485116b3a2eSRishi Panjwani return -EFAULT; 1486116b3a2eSRishi Panjwani 1487116b3a2eSRishi Panjwani buf[len] = '\0'; 1488116b3a2eSRishi Panjwani if (kstrtou16(buf, 0, &bgscan_int)) 1489116b3a2eSRishi Panjwani return -EINVAL; 1490116b3a2eSRishi Panjwani 1491116b3a2eSRishi Panjwani if (bgscan_int == 0) 1492116b3a2eSRishi Panjwani bgscan_int = 0xffff; 1493116b3a2eSRishi Panjwani 1494334234b5SVasanthakumar Thiagarajan ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3, 1495116b3a2eSRishi Panjwani 0, 0, 0); 1496116b3a2eSRishi Panjwani 1497116b3a2eSRishi Panjwani return count; 1498116b3a2eSRishi Panjwani } 1499116b3a2eSRishi Panjwani 1500116b3a2eSRishi Panjwani static const struct file_operations fops_bgscan_int = { 1501116b3a2eSRishi Panjwani .write = ath6kl_bgscan_int_write, 1502116b3a2eSRishi Panjwani .open = ath6kl_debugfs_open, 1503116b3a2eSRishi Panjwani .owner = THIS_MODULE, 1504116b3a2eSRishi Panjwani .llseek = default_llseek, 1505116b3a2eSRishi Panjwani }; 1506116b3a2eSRishi Panjwani 1507d999ba3eSVasanthakumar Thiagarajan int ath6kl_debug_init(struct ath6kl *ar) 1508d999ba3eSVasanthakumar Thiagarajan { 1509bdf5396bSKalle Valo ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE); 1510bdf5396bSKalle Valo if (ar->debug.fwlog_buf.buf == NULL) 1511bdf5396bSKalle Valo return -ENOMEM; 1512bdf5396bSKalle Valo 1513bdf5396bSKalle Valo ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL); 1514bdf5396bSKalle Valo if (ar->debug.fwlog_tmp == NULL) { 1515bdf5396bSKalle Valo vfree(ar->debug.fwlog_buf.buf); 1516bdf5396bSKalle Valo return -ENOMEM; 1517bdf5396bSKalle Valo } 1518bdf5396bSKalle Valo 1519bdf5396bSKalle Valo spin_lock_init(&ar->debug.fwlog_lock); 1520bdf5396bSKalle Valo 1521939f1cceSKalle Valo /* 1522939f1cceSKalle Valo * Actually we are lying here but don't know how to read the mask 1523939f1cceSKalle Valo * value from the firmware. 1524939f1cceSKalle Valo */ 1525939f1cceSKalle Valo ar->debug.fwlog_mask = 0; 1526939f1cceSKalle Valo 1527d999ba3eSVasanthakumar Thiagarajan ar->debugfs_phy = debugfs_create_dir("ath6kl", 1528be98e3a4SVasanthakumar Thiagarajan ar->wiphy->debugfsdir); 1529bdf5396bSKalle Valo if (!ar->debugfs_phy) { 1530bdf5396bSKalle Valo vfree(ar->debug.fwlog_buf.buf); 1531bdf5396bSKalle Valo kfree(ar->debug.fwlog_tmp); 1532d999ba3eSVasanthakumar Thiagarajan return -ENOMEM; 1533bdf5396bSKalle Valo } 1534d999ba3eSVasanthakumar Thiagarajan 153503f68a95SVasanthakumar Thiagarajan debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar, 153603f68a95SVasanthakumar Thiagarajan &fops_tgt_stats); 153703f68a95SVasanthakumar Thiagarajan 153878fc4856SVasanthakumar Thiagarajan debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar, 153978fc4856SVasanthakumar Thiagarajan &fops_credit_dist_stats); 154078fc4856SVasanthakumar Thiagarajan 1541e8091281SJouni Malinen debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR, 1542e8091281SJouni Malinen ar->debugfs_phy, ar, &fops_endpoint_stats); 1543e8091281SJouni Malinen 1544bdf5396bSKalle Valo debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar, 1545bdf5396bSKalle Valo &fops_fwlog); 1546bdf5396bSKalle Valo 1547939f1cceSKalle Valo debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy, 1548939f1cceSKalle Valo ar, &fops_fwlog_mask); 1549939f1cceSKalle Valo 155091d57de5SVasanthakumar Thiagarajan debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar, 155191d57de5SVasanthakumar Thiagarajan &fops_diag_reg_read); 155291d57de5SVasanthakumar Thiagarajan 155391d57de5SVasanthakumar Thiagarajan debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar, 155491d57de5SVasanthakumar Thiagarajan &fops_reg_dump); 155591d57de5SVasanthakumar Thiagarajan 1556e5090444SVivek Natarajan debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR, 1557e5090444SVivek Natarajan ar->debugfs_phy, ar, &fops_lrssi_roam_threshold); 1558252c068bSVasanthakumar Thiagarajan 1559252c068bSVasanthakumar Thiagarajan debugfs_create_file("reg_write", S_IRUSR | S_IWUSR, 1560252c068bSVasanthakumar Thiagarajan ar->debugfs_phy, ar, &fops_diag_reg_write); 1561252c068bSVasanthakumar Thiagarajan 15629a730834SKalle Valo debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar, 15639a730834SKalle Valo &fops_war_stats); 15649a730834SKalle Valo 15654b28a80dSJouni Malinen debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar, 15664b28a80dSJouni Malinen &fops_roam_table); 15674b28a80dSJouni Malinen 15681261875fSJouni Malinen debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar, 15691261875fSJouni Malinen &fops_force_roam); 15701261875fSJouni Malinen 15711261875fSJouni Malinen debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar, 15721261875fSJouni Malinen &fops_roam_mode); 15731261875fSJouni Malinen 1574ff0b0075SJouni Malinen debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar, 1575ff0b0075SJouni Malinen &fops_keepalive); 1576ff0b0075SJouni Malinen 1577ff0b0075SJouni Malinen debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR, 1578ff0b0075SJouni Malinen ar->debugfs_phy, ar, &fops_disconnect_timeout); 1579ff0b0075SJouni Malinen 15808fffd9e5SRishi Panjwani debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar, 15818fffd9e5SRishi Panjwani &fops_create_qos); 15828fffd9e5SRishi Panjwani 15838fffd9e5SRishi Panjwani debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar, 15848fffd9e5SRishi Panjwani &fops_delete_qos); 15858fffd9e5SRishi Panjwani 1586116b3a2eSRishi Panjwani debugfs_create_file("bgscan_interval", S_IWUSR, 1587116b3a2eSRishi Panjwani ar->debugfs_phy, ar, &fops_bgscan_int); 1588116b3a2eSRishi Panjwani 1589d999ba3eSVasanthakumar Thiagarajan return 0; 1590d999ba3eSVasanthakumar Thiagarajan } 1591bdf5396bSKalle Valo 1592bdf5396bSKalle Valo void ath6kl_debug_cleanup(struct ath6kl *ar) 1593bdf5396bSKalle Valo { 1594bdf5396bSKalle Valo vfree(ar->debug.fwlog_buf.buf); 1595bdf5396bSKalle Valo kfree(ar->debug.fwlog_tmp); 15964b28a80dSJouni Malinen kfree(ar->debug.roam_tbl); 1597bdf5396bSKalle Valo } 1598bdf5396bSKalle Valo 1599bdcd8170SKalle Valo #endif 1600