debug.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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. #include "core.h"
  17. #include <linux/circ_buf.h>
  18. #include <linux/fs.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/export.h>
  21. #include "debug.h"
  22. #include "target.h"
  23. struct ath6kl_fwlog_slot {
  24. __le32 timestamp;
  25. __le32 length;
  26. /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
  27. u8 payload[0];
  28. };
  29. #define ATH6KL_FWLOG_SIZE 32768
  30. #define ATH6KL_FWLOG_SLOT_SIZE (sizeof(struct ath6kl_fwlog_slot) + \
  31. ATH6KL_FWLOG_PAYLOAD_SIZE)
  32. #define ATH6KL_FWLOG_VALID_MASK 0x1ffff
  33. int ath6kl_printk(const char *level, const char *fmt, ...)
  34. {
  35. struct va_format vaf;
  36. va_list args;
  37. int rtn;
  38. va_start(args, fmt);
  39. vaf.fmt = fmt;
  40. vaf.va = &args;
  41. rtn = printk("%sath6kl: %pV", level, &vaf);
  42. va_end(args);
  43. return rtn;
  44. }
  45. #ifdef CONFIG_ATH6KL_DEBUG
  46. #define REG_OUTPUT_LEN_PER_LINE 25
  47. #define REGTYPE_STR_LEN 100
  48. struct ath6kl_diag_reg_info {
  49. u32 reg_start;
  50. u32 reg_end;
  51. const char *reg_info;
  52. };
  53. static const struct ath6kl_diag_reg_info diag_reg[] = {
  54. { 0x20000, 0x200fc, "General DMA and Rx registers" },
  55. { 0x28000, 0x28900, "MAC PCU register & keycache" },
  56. { 0x20800, 0x20a40, "QCU" },
  57. { 0x21000, 0x212f0, "DCU" },
  58. { 0x4000, 0x42e4, "RTC" },
  59. { 0x540000, 0x540000 + (256 * 1024), "RAM" },
  60. { 0x29800, 0x2B210, "Base Band" },
  61. { 0x1C000, 0x1C748, "Analog" },
  62. };
  63. void ath6kl_dump_registers(struct ath6kl_device *dev,
  64. struct ath6kl_irq_proc_registers *irq_proc_reg,
  65. struct ath6kl_irq_enable_reg *irq_enable_reg)
  66. {
  67. ath6kl_dbg(ATH6KL_DBG_ANY, ("<------- Register Table -------->\n"));
  68. if (irq_proc_reg != NULL) {
  69. ath6kl_dbg(ATH6KL_DBG_ANY,
  70. "Host Int status: 0x%x\n",
  71. irq_proc_reg->host_int_status);
  72. ath6kl_dbg(ATH6KL_DBG_ANY,
  73. "CPU Int status: 0x%x\n",
  74. irq_proc_reg->cpu_int_status);
  75. ath6kl_dbg(ATH6KL_DBG_ANY,
  76. "Error Int status: 0x%x\n",
  77. irq_proc_reg->error_int_status);
  78. ath6kl_dbg(ATH6KL_DBG_ANY,
  79. "Counter Int status: 0x%x\n",
  80. irq_proc_reg->counter_int_status);
  81. ath6kl_dbg(ATH6KL_DBG_ANY,
  82. "Mbox Frame: 0x%x\n",
  83. irq_proc_reg->mbox_frame);
  84. ath6kl_dbg(ATH6KL_DBG_ANY,
  85. "Rx Lookahead Valid: 0x%x\n",
  86. irq_proc_reg->rx_lkahd_valid);
  87. ath6kl_dbg(ATH6KL_DBG_ANY,
  88. "Rx Lookahead 0: 0x%x\n",
  89. irq_proc_reg->rx_lkahd[0]);
  90. ath6kl_dbg(ATH6KL_DBG_ANY,
  91. "Rx Lookahead 1: 0x%x\n",
  92. irq_proc_reg->rx_lkahd[1]);
  93. if (dev->ar->mbox_info.gmbox_addr != 0) {
  94. /*
  95. * If the target supports GMBOX hardware, dump some
  96. * additional state.
  97. */
  98. ath6kl_dbg(ATH6KL_DBG_ANY,
  99. "GMBOX Host Int status 2: 0x%x\n",
  100. irq_proc_reg->host_int_status2);
  101. ath6kl_dbg(ATH6KL_DBG_ANY,
  102. "GMBOX RX Avail: 0x%x\n",
  103. irq_proc_reg->gmbox_rx_avail);
  104. ath6kl_dbg(ATH6KL_DBG_ANY,
  105. "GMBOX lookahead alias 0: 0x%x\n",
  106. irq_proc_reg->rx_gmbox_lkahd_alias[0]);
  107. ath6kl_dbg(ATH6KL_DBG_ANY,
  108. "GMBOX lookahead alias 1: 0x%x\n",
  109. irq_proc_reg->rx_gmbox_lkahd_alias[1]);
  110. }
  111. }
  112. if (irq_enable_reg != NULL) {
  113. ath6kl_dbg(ATH6KL_DBG_ANY,
  114. "Int status Enable: 0x%x\n",
  115. irq_enable_reg->int_status_en);
  116. ath6kl_dbg(ATH6KL_DBG_ANY, "Counter Int status Enable: 0x%x\n",
  117. irq_enable_reg->cntr_int_status_en);
  118. }
  119. ath6kl_dbg(ATH6KL_DBG_ANY, "<------------------------------->\n");
  120. }
  121. static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
  122. {
  123. ath6kl_dbg(ATH6KL_DBG_ANY,
  124. "--- endpoint: %d svc_id: 0x%X ---\n",
  125. ep_dist->endpoint, ep_dist->svc_id);
  126. ath6kl_dbg(ATH6KL_DBG_ANY, " dist_flags : 0x%X\n",
  127. ep_dist->dist_flags);
  128. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_norm : %d\n",
  129. ep_dist->cred_norm);
  130. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_min : %d\n",
  131. ep_dist->cred_min);
  132. ath6kl_dbg(ATH6KL_DBG_ANY, " credits : %d\n",
  133. ep_dist->credits);
  134. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_assngd : %d\n",
  135. ep_dist->cred_assngd);
  136. ath6kl_dbg(ATH6KL_DBG_ANY, " seek_cred : %d\n",
  137. ep_dist->seek_cred);
  138. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_sz : %d\n",
  139. ep_dist->cred_sz);
  140. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_per_msg : %d\n",
  141. ep_dist->cred_per_msg);
  142. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_to_dist : %d\n",
  143. ep_dist->cred_to_dist);
  144. ath6kl_dbg(ATH6KL_DBG_ANY, " txq_depth : %d\n",
  145. get_queue_depth(&((struct htc_endpoint *)
  146. ep_dist->htc_rsvd)->txq));
  147. ath6kl_dbg(ATH6KL_DBG_ANY,
  148. "----------------------------------\n");
  149. }
  150. void dump_cred_dist_stats(struct htc_target *target)
  151. {
  152. struct htc_endpoint_credit_dist *ep_list;
  153. if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_TRC))
  154. return;
  155. list_for_each_entry(ep_list, &target->cred_dist_list, list)
  156. dump_cred_dist(ep_list);
  157. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:%p dist:%p\n",
  158. target->cred_dist_cntxt, NULL);
  159. ath6kl_dbg(ATH6KL_DBG_TRC, "credit distribution, total : %d, free : %d\n",
  160. target->cred_dist_cntxt->total_avail_credits,
  161. target->cred_dist_cntxt->cur_free_credits);
  162. }
  163. static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
  164. {
  165. file->private_data = inode->i_private;
  166. return 0;
  167. }
  168. void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
  169. {
  170. switch (war) {
  171. case ATH6KL_WAR_INVALID_RATE:
  172. ar->debug.war_stats.invalid_rate++;
  173. break;
  174. }
  175. }
  176. static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
  177. size_t count, loff_t *ppos)
  178. {
  179. struct ath6kl *ar = file->private_data;
  180. char *buf;
  181. unsigned int len = 0, buf_len = 1500;
  182. ssize_t ret_cnt;
  183. buf = kzalloc(buf_len, GFP_KERNEL);
  184. if (!buf)
  185. return -ENOMEM;
  186. len += scnprintf(buf + len, buf_len - len, "\n");
  187. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  188. "Workaround stats");
  189. len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
  190. "=================");
  191. len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
  192. "Invalid rates", ar->debug.war_stats.invalid_rate);
  193. if (WARN_ON(len > buf_len))
  194. len = buf_len;
  195. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  196. kfree(buf);
  197. return ret_cnt;
  198. }
  199. static const struct file_operations fops_war_stats = {
  200. .read = read_file_war_stats,
  201. .open = ath6kl_debugfs_open,
  202. .owner = THIS_MODULE,
  203. .llseek = default_llseek,
  204. };
  205. static void ath6kl_debug_fwlog_add(struct ath6kl *ar, const void *buf,
  206. size_t buf_len)
  207. {
  208. struct circ_buf *fwlog = &ar->debug.fwlog_buf;
  209. size_t space;
  210. int i;
  211. /* entries must all be equal size */
  212. if (WARN_ON(buf_len != ATH6KL_FWLOG_SLOT_SIZE))
  213. return;
  214. space = CIRC_SPACE(fwlog->head, fwlog->tail, ATH6KL_FWLOG_SIZE);
  215. if (space < buf_len)
  216. /* discard oldest slot */
  217. fwlog->tail = (fwlog->tail + ATH6KL_FWLOG_SLOT_SIZE) &
  218. (ATH6KL_FWLOG_SIZE - 1);
  219. for (i = 0; i < buf_len; i += space) {
  220. space = CIRC_SPACE_TO_END(fwlog->head, fwlog->tail,
  221. ATH6KL_FWLOG_SIZE);
  222. if ((size_t) space > buf_len - i)
  223. space = buf_len - i;
  224. memcpy(&fwlog->buf[fwlog->head], buf, space);
  225. fwlog->head = (fwlog->head + space) & (ATH6KL_FWLOG_SIZE - 1);
  226. }
  227. }
  228. void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
  229. {
  230. struct ath6kl_fwlog_slot *slot = ar->debug.fwlog_tmp;
  231. size_t slot_len;
  232. if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
  233. return;
  234. spin_lock_bh(&ar->debug.fwlog_lock);
  235. slot->timestamp = cpu_to_le32(jiffies);
  236. slot->length = cpu_to_le32(len);
  237. memcpy(slot->payload, buf, len);
  238. slot_len = sizeof(*slot) + len;
  239. if (slot_len < ATH6KL_FWLOG_SLOT_SIZE)
  240. memset(slot->payload + len, 0,
  241. ATH6KL_FWLOG_SLOT_SIZE - slot_len);
  242. ath6kl_debug_fwlog_add(ar, slot, ATH6KL_FWLOG_SLOT_SIZE);
  243. spin_unlock_bh(&ar->debug.fwlog_lock);
  244. }
  245. static bool ath6kl_debug_fwlog_empty(struct ath6kl *ar)
  246. {
  247. return CIRC_CNT(ar->debug.fwlog_buf.head,
  248. ar->debug.fwlog_buf.tail,
  249. ATH6KL_FWLOG_SLOT_SIZE) == 0;
  250. }
  251. static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
  252. size_t count, loff_t *ppos)
  253. {
  254. struct ath6kl *ar = file->private_data;
  255. struct circ_buf *fwlog = &ar->debug.fwlog_buf;
  256. size_t len = 0, buf_len = count;
  257. ssize_t ret_cnt;
  258. char *buf;
  259. int ccnt;
  260. buf = vmalloc(buf_len);
  261. if (!buf)
  262. return -ENOMEM;
  263. /* read undelivered logs from firmware */
  264. ath6kl_read_fwlogs(ar);
  265. spin_lock_bh(&ar->debug.fwlog_lock);
  266. while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) {
  267. ccnt = CIRC_CNT_TO_END(fwlog->head, fwlog->tail,
  268. ATH6KL_FWLOG_SIZE);
  269. if ((size_t) ccnt > buf_len - len)
  270. ccnt = buf_len - len;
  271. memcpy(buf + len, &fwlog->buf[fwlog->tail], ccnt);
  272. len += ccnt;
  273. fwlog->tail = (fwlog->tail + ccnt) &
  274. (ATH6KL_FWLOG_SIZE - 1);
  275. }
  276. spin_unlock_bh(&ar->debug.fwlog_lock);
  277. if (WARN_ON(len > buf_len))
  278. len = buf_len;
  279. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  280. vfree(buf);
  281. return ret_cnt;
  282. }
  283. static const struct file_operations fops_fwlog = {
  284. .open = ath6kl_debugfs_open,
  285. .read = ath6kl_fwlog_read,
  286. .owner = THIS_MODULE,
  287. .llseek = default_llseek,
  288. };
  289. static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
  290. size_t count, loff_t *ppos)
  291. {
  292. struct ath6kl *ar = file->private_data;
  293. char buf[16];
  294. int len;
  295. len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
  296. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  297. }
  298. static ssize_t ath6kl_fwlog_mask_write(struct file *file,
  299. const char __user *user_buf,
  300. size_t count, loff_t *ppos)
  301. {
  302. struct ath6kl *ar = file->private_data;
  303. int ret;
  304. ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
  305. if (ret)
  306. return ret;
  307. ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
  308. ATH6KL_FWLOG_VALID_MASK,
  309. ar->debug.fwlog_mask);
  310. if (ret)
  311. return ret;
  312. return count;
  313. }
  314. static const struct file_operations fops_fwlog_mask = {
  315. .open = ath6kl_debugfs_open,
  316. .read = ath6kl_fwlog_mask_read,
  317. .write = ath6kl_fwlog_mask_write,
  318. .owner = THIS_MODULE,
  319. .llseek = default_llseek,
  320. };
  321. static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
  322. size_t count, loff_t *ppos)
  323. {
  324. struct ath6kl *ar = file->private_data;
  325. struct target_stats *tgt_stats = &ar->target_stats;
  326. char *buf;
  327. unsigned int len = 0, buf_len = 1500;
  328. int i;
  329. long left;
  330. ssize_t ret_cnt;
  331. buf = kzalloc(buf_len, GFP_KERNEL);
  332. if (!buf)
  333. return -ENOMEM;
  334. if (down_interruptible(&ar->sem)) {
  335. kfree(buf);
  336. return -EBUSY;
  337. }
  338. set_bit(STATS_UPDATE_PEND, &ar->flag);
  339. if (ath6kl_wmi_get_stats_cmd(ar->wmi)) {
  340. up(&ar->sem);
  341. kfree(buf);
  342. return -EIO;
  343. }
  344. left = wait_event_interruptible_timeout(ar->event_wq,
  345. !test_bit(STATS_UPDATE_PEND,
  346. &ar->flag), WMI_TIMEOUT);
  347. up(&ar->sem);
  348. if (left <= 0) {
  349. kfree(buf);
  350. return -ETIMEDOUT;
  351. }
  352. len += scnprintf(buf + len, buf_len - len, "\n");
  353. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  354. "Target Tx stats");
  355. len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
  356. "=================");
  357. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  358. "Ucast packets", tgt_stats->tx_ucast_pkt);
  359. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  360. "Bcast packets", tgt_stats->tx_bcast_pkt);
  361. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  362. "Ucast byte", tgt_stats->tx_ucast_byte);
  363. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  364. "Bcast byte", tgt_stats->tx_bcast_byte);
  365. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  366. "Rts success cnt", tgt_stats->tx_rts_success_cnt);
  367. for (i = 0; i < 4; i++)
  368. len += scnprintf(buf + len, buf_len - len,
  369. "%18s %d %10llu\n", "PER on ac",
  370. i, tgt_stats->tx_pkt_per_ac[i]);
  371. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  372. "Error", tgt_stats->tx_err);
  373. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  374. "Fail count", tgt_stats->tx_fail_cnt);
  375. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  376. "Retry count", tgt_stats->tx_retry_cnt);
  377. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  378. "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
  379. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  380. "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
  381. len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
  382. "TKIP counter measure used",
  383. tgt_stats->tkip_cnter_measures_invoked);
  384. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  385. "Target Rx stats");
  386. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  387. "=================");
  388. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  389. "Ucast packets", tgt_stats->rx_ucast_pkt);
  390. len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
  391. "Ucast Rate", tgt_stats->rx_ucast_rate);
  392. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  393. "Bcast packets", tgt_stats->rx_bcast_pkt);
  394. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  395. "Ucast byte", tgt_stats->rx_ucast_byte);
  396. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  397. "Bcast byte", tgt_stats->rx_bcast_byte);
  398. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  399. "Fragmented pkt", tgt_stats->rx_frgment_pkt);
  400. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  401. "Error", tgt_stats->rx_err);
  402. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  403. "CRC Err", tgt_stats->rx_crc_err);
  404. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  405. "Key chache miss", tgt_stats->rx_key_cache_miss);
  406. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  407. "Decrypt Err", tgt_stats->rx_decrypt_err);
  408. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  409. "Duplicate frame", tgt_stats->rx_dupl_frame);
  410. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  411. "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
  412. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  413. "TKIP format err", tgt_stats->tkip_fmt_err);
  414. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  415. "CCMP format Err", tgt_stats->ccmp_fmt_err);
  416. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
  417. "CCMP Replay Err", tgt_stats->ccmp_replays);
  418. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  419. "Misc Target stats");
  420. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  421. "=================");
  422. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  423. "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
  424. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  425. "Num Connects", tgt_stats->cs_connect_cnt);
  426. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  427. "Num disconnects", tgt_stats->cs_discon_cnt);
  428. len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
  429. "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
  430. if (len > buf_len)
  431. len = buf_len;
  432. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  433. kfree(buf);
  434. return ret_cnt;
  435. }
  436. static const struct file_operations fops_tgt_stats = {
  437. .read = read_file_tgt_stats,
  438. .open = ath6kl_debugfs_open,
  439. .owner = THIS_MODULE,
  440. .llseek = default_llseek,
  441. };
  442. #define print_credit_info(fmt_str, ep_list_field) \
  443. (len += scnprintf(buf + len, buf_len - len, fmt_str, \
  444. ep_list->ep_list_field))
  445. #define CREDIT_INFO_DISPLAY_STRING_LEN 200
  446. #define CREDIT_INFO_LEN 128
  447. static ssize_t read_file_credit_dist_stats(struct file *file,
  448. char __user *user_buf,
  449. size_t count, loff_t *ppos)
  450. {
  451. struct ath6kl *ar = file->private_data;
  452. struct htc_target *target = ar->htc_target;
  453. struct htc_endpoint_credit_dist *ep_list;
  454. char *buf;
  455. unsigned int buf_len, len = 0;
  456. ssize_t ret_cnt;
  457. buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
  458. get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
  459. buf = kzalloc(buf_len, GFP_KERNEL);
  460. if (!buf)
  461. return -ENOMEM;
  462. len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
  463. "Total Avail Credits: ",
  464. target->cred_dist_cntxt->total_avail_credits);
  465. len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
  466. "Free credits :",
  467. target->cred_dist_cntxt->cur_free_credits);
  468. len += scnprintf(buf + len, buf_len - len,
  469. " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
  470. " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
  471. " qdepth\n");
  472. list_for_each_entry(ep_list, &target->cred_dist_list, list) {
  473. print_credit_info(" %2d", endpoint);
  474. print_credit_info("%10x", dist_flags);
  475. print_credit_info("%8d", cred_norm);
  476. print_credit_info("%9d", cred_min);
  477. print_credit_info("%9d", credits);
  478. print_credit_info("%10d", cred_assngd);
  479. print_credit_info("%13d", seek_cred);
  480. print_credit_info("%12d", cred_sz);
  481. print_credit_info("%9d", cred_per_msg);
  482. print_credit_info("%14d", cred_to_dist);
  483. len += scnprintf(buf + len, buf_len - len, "%12d\n",
  484. get_queue_depth(&((struct htc_endpoint *)
  485. ep_list->htc_rsvd)->txq));
  486. }
  487. if (len > buf_len)
  488. len = buf_len;
  489. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  490. kfree(buf);
  491. return ret_cnt;
  492. }
  493. static const struct file_operations fops_credit_dist_stats = {
  494. .read = read_file_credit_dist_stats,
  495. .open = ath6kl_debugfs_open,
  496. .owner = THIS_MODULE,
  497. .llseek = default_llseek,
  498. };
  499. static unsigned long ath6kl_get_num_reg(void)
  500. {
  501. int i;
  502. unsigned long n_reg = 0;
  503. for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
  504. n_reg = n_reg +
  505. (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
  506. return n_reg;
  507. }
  508. static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
  509. {
  510. int i;
  511. for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
  512. if (reg_addr >= diag_reg[i].reg_start &&
  513. reg_addr <= diag_reg[i].reg_end)
  514. return true;
  515. }
  516. return false;
  517. }
  518. static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
  519. size_t count, loff_t *ppos)
  520. {
  521. struct ath6kl *ar = file->private_data;
  522. u8 buf[50];
  523. unsigned int len = 0;
  524. if (ar->debug.dbgfs_diag_reg)
  525. len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
  526. ar->debug.dbgfs_diag_reg);
  527. else
  528. len += scnprintf(buf + len, sizeof(buf) - len,
  529. "All diag registers\n");
  530. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  531. }
  532. static ssize_t ath6kl_regread_write(struct file *file,
  533. const char __user *user_buf,
  534. size_t count, loff_t *ppos)
  535. {
  536. struct ath6kl *ar = file->private_data;
  537. u8 buf[50];
  538. unsigned int len;
  539. unsigned long reg_addr;
  540. len = min(count, sizeof(buf) - 1);
  541. if (copy_from_user(buf, user_buf, len))
  542. return -EFAULT;
  543. buf[len] = '\0';
  544. if (strict_strtoul(buf, 0, &reg_addr))
  545. return -EINVAL;
  546. if ((reg_addr % 4) != 0)
  547. return -EINVAL;
  548. if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
  549. return -EINVAL;
  550. ar->debug.dbgfs_diag_reg = reg_addr;
  551. return count;
  552. }
  553. static const struct file_operations fops_diag_reg_read = {
  554. .read = ath6kl_regread_read,
  555. .write = ath6kl_regread_write,
  556. .open = ath6kl_debugfs_open,
  557. .owner = THIS_MODULE,
  558. .llseek = default_llseek,
  559. };
  560. static int ath6kl_regdump_open(struct inode *inode, struct file *file)
  561. {
  562. struct ath6kl *ar = inode->i_private;
  563. u8 *buf;
  564. unsigned long int reg_len;
  565. unsigned int len = 0, n_reg;
  566. u32 addr;
  567. __le32 reg_val;
  568. int i, status;
  569. /* Dump all the registers if no register is specified */
  570. if (!ar->debug.dbgfs_diag_reg)
  571. n_reg = ath6kl_get_num_reg();
  572. else
  573. n_reg = 1;
  574. reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
  575. if (n_reg > 1)
  576. reg_len += REGTYPE_STR_LEN;
  577. buf = vmalloc(reg_len);
  578. if (!buf)
  579. return -ENOMEM;
  580. if (n_reg == 1) {
  581. addr = ar->debug.dbgfs_diag_reg;
  582. status = ath6kl_diag_read32(ar,
  583. TARG_VTOP(ar->target_type, addr),
  584. (u32 *)&reg_val);
  585. if (status)
  586. goto fail_reg_read;
  587. len += scnprintf(buf + len, reg_len - len,
  588. "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
  589. goto done;
  590. }
  591. for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
  592. len += scnprintf(buf + len, reg_len - len,
  593. "%s\n", diag_reg[i].reg_info);
  594. for (addr = diag_reg[i].reg_start;
  595. addr <= diag_reg[i].reg_end; addr += 4) {
  596. status = ath6kl_diag_read32(ar,
  597. TARG_VTOP(ar->target_type, addr),
  598. (u32 *)&reg_val);
  599. if (status)
  600. goto fail_reg_read;
  601. len += scnprintf(buf + len, reg_len - len,
  602. "0x%06x 0x%08x\n",
  603. addr, le32_to_cpu(reg_val));
  604. }
  605. }
  606. done:
  607. file->private_data = buf;
  608. return 0;
  609. fail_reg_read:
  610. ath6kl_warn("Unable to read memory:%u\n", addr);
  611. vfree(buf);
  612. return -EIO;
  613. }
  614. static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
  615. size_t count, loff_t *ppos)
  616. {
  617. u8 *buf = file->private_data;
  618. return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  619. }
  620. static int ath6kl_regdump_release(struct inode *inode, struct file *file)
  621. {
  622. vfree(file->private_data);
  623. return 0;
  624. }
  625. static const struct file_operations fops_reg_dump = {
  626. .open = ath6kl_regdump_open,
  627. .read = ath6kl_regdump_read,
  628. .release = ath6kl_regdump_release,
  629. .owner = THIS_MODULE,
  630. .llseek = default_llseek,
  631. };
  632. static ssize_t ath6kl_lrssi_roam_write(struct file *file,
  633. const char __user *user_buf,
  634. size_t count, loff_t *ppos)
  635. {
  636. struct ath6kl *ar = file->private_data;
  637. unsigned long lrssi_roam_threshold;
  638. char buf[32];
  639. ssize_t len;
  640. len = min(count, sizeof(buf) - 1);
  641. if (copy_from_user(buf, user_buf, len))
  642. return -EFAULT;
  643. buf[len] = '\0';
  644. if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
  645. return -EINVAL;
  646. ar->lrssi_roam_threshold = lrssi_roam_threshold;
  647. ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
  648. return count;
  649. }
  650. static ssize_t ath6kl_lrssi_roam_read(struct file *file,
  651. char __user *user_buf,
  652. size_t count, loff_t *ppos)
  653. {
  654. struct ath6kl *ar = file->private_data;
  655. char buf[32];
  656. unsigned int len;
  657. len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
  658. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  659. }
  660. static const struct file_operations fops_lrssi_roam_threshold = {
  661. .read = ath6kl_lrssi_roam_read,
  662. .write = ath6kl_lrssi_roam_write,
  663. .open = ath6kl_debugfs_open,
  664. .owner = THIS_MODULE,
  665. .llseek = default_llseek,
  666. };
  667. static ssize_t ath6kl_regwrite_read(struct file *file,
  668. char __user *user_buf,
  669. size_t count, loff_t *ppos)
  670. {
  671. struct ath6kl *ar = file->private_data;
  672. u8 buf[32];
  673. unsigned int len = 0;
  674. len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
  675. ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
  676. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  677. }
  678. static ssize_t ath6kl_regwrite_write(struct file *file,
  679. const char __user *user_buf,
  680. size_t count, loff_t *ppos)
  681. {
  682. struct ath6kl *ar = file->private_data;
  683. char buf[32];
  684. char *sptr, *token;
  685. unsigned int len = 0;
  686. u32 reg_addr, reg_val;
  687. len = min(count, sizeof(buf) - 1);
  688. if (copy_from_user(buf, user_buf, len))
  689. return -EFAULT;
  690. buf[len] = '\0';
  691. sptr = buf;
  692. token = strsep(&sptr, "=");
  693. if (!token)
  694. return -EINVAL;
  695. if (kstrtou32(token, 0, &reg_addr))
  696. return -EINVAL;
  697. if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
  698. return -EINVAL;
  699. if (kstrtou32(sptr, 0, &reg_val))
  700. return -EINVAL;
  701. ar->debug.diag_reg_addr_wr = reg_addr;
  702. ar->debug.diag_reg_val_wr = reg_val;
  703. if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
  704. cpu_to_le32(ar->debug.diag_reg_val_wr)))
  705. return -EIO;
  706. return count;
  707. }
  708. static const struct file_operations fops_diag_reg_write = {
  709. .read = ath6kl_regwrite_read,
  710. .write = ath6kl_regwrite_write,
  711. .open = ath6kl_debugfs_open,
  712. .owner = THIS_MODULE,
  713. .llseek = default_llseek,
  714. };
  715. int ath6kl_debug_init(struct ath6kl *ar)
  716. {
  717. ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE);
  718. if (ar->debug.fwlog_buf.buf == NULL)
  719. return -ENOMEM;
  720. ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL);
  721. if (ar->debug.fwlog_tmp == NULL) {
  722. vfree(ar->debug.fwlog_buf.buf);
  723. return -ENOMEM;
  724. }
  725. spin_lock_init(&ar->debug.fwlog_lock);
  726. /*
  727. * Actually we are lying here but don't know how to read the mask
  728. * value from the firmware.
  729. */
  730. ar->debug.fwlog_mask = 0;
  731. ar->debugfs_phy = debugfs_create_dir("ath6kl",
  732. ar->wdev->wiphy->debugfsdir);
  733. if (!ar->debugfs_phy) {
  734. vfree(ar->debug.fwlog_buf.buf);
  735. kfree(ar->debug.fwlog_tmp);
  736. return -ENOMEM;
  737. }
  738. debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
  739. &fops_tgt_stats);
  740. debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
  741. &fops_credit_dist_stats);
  742. debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
  743. &fops_fwlog);
  744. debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
  745. ar, &fops_fwlog_mask);
  746. debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
  747. &fops_diag_reg_read);
  748. debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
  749. &fops_reg_dump);
  750. debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
  751. ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
  752. debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
  753. ar->debugfs_phy, ar, &fops_diag_reg_write);
  754. debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
  755. &fops_war_stats);
  756. return 0;
  757. }
  758. void ath6kl_debug_cleanup(struct ath6kl *ar)
  759. {
  760. vfree(ar->debug.fwlog_buf.buf);
  761. kfree(ar->debug.fwlog_tmp);
  762. }
  763. #endif