debug.c 25 KB

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