debug.c 25 KB

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