debug.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 "debug.h"
  18. int ath6kl_printk(const char *level, const char *fmt, ...)
  19. {
  20. struct va_format vaf;
  21. va_list args;
  22. int rtn;
  23. va_start(args, fmt);
  24. vaf.fmt = fmt;
  25. vaf.va = &args;
  26. rtn = printk("%sath6kl: %pV", level, &vaf);
  27. va_end(args);
  28. return rtn;
  29. }
  30. #ifdef CONFIG_ATH6KL_DEBUG
  31. void ath6kl_dump_registers(struct ath6kl_device *dev,
  32. struct ath6kl_irq_proc_registers *irq_proc_reg,
  33. struct ath6kl_irq_enable_reg *irq_enable_reg)
  34. {
  35. ath6kl_dbg(ATH6KL_DBG_ANY, ("<------- Register Table -------->\n"));
  36. if (irq_proc_reg != NULL) {
  37. ath6kl_dbg(ATH6KL_DBG_ANY,
  38. "Host Int status: 0x%x\n",
  39. irq_proc_reg->host_int_status);
  40. ath6kl_dbg(ATH6KL_DBG_ANY,
  41. "CPU Int status: 0x%x\n",
  42. irq_proc_reg->cpu_int_status);
  43. ath6kl_dbg(ATH6KL_DBG_ANY,
  44. "Error Int status: 0x%x\n",
  45. irq_proc_reg->error_int_status);
  46. ath6kl_dbg(ATH6KL_DBG_ANY,
  47. "Counter Int status: 0x%x\n",
  48. irq_proc_reg->counter_int_status);
  49. ath6kl_dbg(ATH6KL_DBG_ANY,
  50. "Mbox Frame: 0x%x\n",
  51. irq_proc_reg->mbox_frame);
  52. ath6kl_dbg(ATH6KL_DBG_ANY,
  53. "Rx Lookahead Valid: 0x%x\n",
  54. irq_proc_reg->rx_lkahd_valid);
  55. ath6kl_dbg(ATH6KL_DBG_ANY,
  56. "Rx Lookahead 0: 0x%x\n",
  57. irq_proc_reg->rx_lkahd[0]);
  58. ath6kl_dbg(ATH6KL_DBG_ANY,
  59. "Rx Lookahead 1: 0x%x\n",
  60. irq_proc_reg->rx_lkahd[1]);
  61. if (dev->ar->mbox_info.gmbox_addr != 0) {
  62. /*
  63. * If the target supports GMBOX hardware, dump some
  64. * additional state.
  65. */
  66. ath6kl_dbg(ATH6KL_DBG_ANY,
  67. "GMBOX Host Int status 2: 0x%x\n",
  68. irq_proc_reg->host_int_status2);
  69. ath6kl_dbg(ATH6KL_DBG_ANY,
  70. "GMBOX RX Avail: 0x%x\n",
  71. irq_proc_reg->gmbox_rx_avail);
  72. ath6kl_dbg(ATH6KL_DBG_ANY,
  73. "GMBOX lookahead alias 0: 0x%x\n",
  74. irq_proc_reg->rx_gmbox_lkahd_alias[0]);
  75. ath6kl_dbg(ATH6KL_DBG_ANY,
  76. "GMBOX lookahead alias 1: 0x%x\n",
  77. irq_proc_reg->rx_gmbox_lkahd_alias[1]);
  78. }
  79. }
  80. if (irq_enable_reg != NULL) {
  81. ath6kl_dbg(ATH6KL_DBG_ANY,
  82. "Int status Enable: 0x%x\n",
  83. irq_enable_reg->int_status_en);
  84. ath6kl_dbg(ATH6KL_DBG_ANY, "Counter Int status Enable: 0x%x\n",
  85. irq_enable_reg->cntr_int_status_en);
  86. }
  87. ath6kl_dbg(ATH6KL_DBG_ANY, "<------------------------------->\n");
  88. }
  89. static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
  90. {
  91. ath6kl_dbg(ATH6KL_DBG_ANY,
  92. "--- endpoint: %d svc_id: 0x%X ---\n",
  93. ep_dist->endpoint, ep_dist->svc_id);
  94. ath6kl_dbg(ATH6KL_DBG_ANY, " dist_flags : 0x%X\n",
  95. ep_dist->dist_flags);
  96. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_norm : %d\n",
  97. ep_dist->cred_norm);
  98. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_min : %d\n",
  99. ep_dist->cred_min);
  100. ath6kl_dbg(ATH6KL_DBG_ANY, " credits : %d\n",
  101. ep_dist->credits);
  102. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_assngd : %d\n",
  103. ep_dist->cred_assngd);
  104. ath6kl_dbg(ATH6KL_DBG_ANY, " seek_cred : %d\n",
  105. ep_dist->seek_cred);
  106. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_sz : %d\n",
  107. ep_dist->cred_sz);
  108. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_per_msg : %d\n",
  109. ep_dist->cred_per_msg);
  110. ath6kl_dbg(ATH6KL_DBG_ANY, " cred_to_dist : %d\n",
  111. ep_dist->cred_to_dist);
  112. ath6kl_dbg(ATH6KL_DBG_ANY, " txq_depth : %d\n",
  113. get_queue_depth(&((struct htc_endpoint *)
  114. ep_dist->htc_rsvd)->txq));
  115. ath6kl_dbg(ATH6KL_DBG_ANY,
  116. "----------------------------------\n");
  117. }
  118. void dump_cred_dist_stats(struct htc_target *target)
  119. {
  120. struct htc_endpoint_credit_dist *ep_list;
  121. if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_TRC))
  122. return;
  123. list_for_each_entry(ep_list, &target->cred_dist_list, list)
  124. dump_cred_dist(ep_list);
  125. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:%p dist:%p\n",
  126. target->cred_dist_cntxt, NULL);
  127. ath6kl_dbg(ATH6KL_DBG_TRC, "credit distribution, total : %d, free : %d\n",
  128. target->cred_dist_cntxt->total_avail_credits,
  129. target->cred_dist_cntxt->cur_free_credits);
  130. }
  131. static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
  132. {
  133. file->private_data = inode->i_private;
  134. return 0;
  135. }
  136. static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
  137. size_t count, loff_t *ppos)
  138. {
  139. struct ath6kl *ar = file->private_data;
  140. struct target_stats *tgt_stats = &ar->target_stats;
  141. char *buf;
  142. unsigned int len = 0, buf_len = 1500;
  143. int i;
  144. long left;
  145. ssize_t ret_cnt;
  146. buf = kzalloc(buf_len, GFP_KERNEL);
  147. if (!buf)
  148. return -ENOMEM;
  149. if (down_interruptible(&ar->sem)) {
  150. kfree(buf);
  151. return -EBUSY;
  152. }
  153. set_bit(STATS_UPDATE_PEND, &ar->flag);
  154. if (ath6kl_wmi_get_stats_cmd(ar->wmi)) {
  155. up(&ar->sem);
  156. kfree(buf);
  157. return -EIO;
  158. }
  159. left = wait_event_interruptible_timeout(ar->event_wq,
  160. !test_bit(STATS_UPDATE_PEND,
  161. &ar->flag), WMI_TIMEOUT);
  162. up(&ar->sem);
  163. if (left <= 0) {
  164. kfree(buf);
  165. return -ETIMEDOUT;
  166. }
  167. len += scnprintf(buf + len, buf_len - len, "\n");
  168. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  169. "Target Tx stats");
  170. len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
  171. "=================");
  172. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  173. "Ucast packets", tgt_stats->tx_ucast_pkt);
  174. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  175. "Bcast packets", tgt_stats->tx_bcast_pkt);
  176. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  177. "Ucast byte", tgt_stats->tx_ucast_byte);
  178. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  179. "Bcast byte", tgt_stats->tx_bcast_byte);
  180. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  181. "Rts success cnt", tgt_stats->tx_rts_success_cnt);
  182. for (i = 0; i < 4; i++)
  183. len += scnprintf(buf + len, buf_len - len,
  184. "%18s %d %10llu\n", "PER on ac",
  185. i, tgt_stats->tx_pkt_per_ac[i]);
  186. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  187. "Error", tgt_stats->tx_err);
  188. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  189. "Fail count", tgt_stats->tx_fail_cnt);
  190. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  191. "Retry count", tgt_stats->tx_retry_cnt);
  192. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  193. "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
  194. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  195. "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
  196. len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
  197. "TKIP counter measure used",
  198. tgt_stats->tkip_cnter_measures_invoked);
  199. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  200. "Target Rx stats");
  201. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  202. "=================");
  203. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  204. "Ucast packets", tgt_stats->rx_ucast_pkt);
  205. len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
  206. "Ucast Rate", tgt_stats->rx_ucast_rate);
  207. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  208. "Bcast packets", tgt_stats->rx_bcast_pkt);
  209. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  210. "Ucast byte", tgt_stats->rx_ucast_byte);
  211. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  212. "Bcast byte", tgt_stats->rx_bcast_byte);
  213. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  214. "Fragmented pkt", tgt_stats->rx_frgment_pkt);
  215. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  216. "Error", tgt_stats->rx_err);
  217. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  218. "CRC Err", tgt_stats->rx_crc_err);
  219. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  220. "Key chache miss", tgt_stats->rx_key_cache_miss);
  221. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  222. "Decrypt Err", tgt_stats->rx_decrypt_err);
  223. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  224. "Duplicate frame", tgt_stats->rx_dupl_frame);
  225. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  226. "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
  227. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  228. "TKIP format err", tgt_stats->tkip_fmt_err);
  229. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  230. "CCMP format Err", tgt_stats->ccmp_fmt_err);
  231. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
  232. "CCMP Replay Err", tgt_stats->ccmp_replays);
  233. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  234. "Misc Target stats");
  235. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  236. "=================");
  237. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  238. "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
  239. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  240. "Num Connects", tgt_stats->cs_connect_cnt);
  241. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  242. "Num disconnects", tgt_stats->cs_discon_cnt);
  243. len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
  244. "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
  245. if (len > buf_len)
  246. len = buf_len;
  247. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  248. kfree(buf);
  249. return ret_cnt;
  250. }
  251. static const struct file_operations fops_tgt_stats = {
  252. .read = read_file_tgt_stats,
  253. .open = ath6kl_debugfs_open,
  254. .owner = THIS_MODULE,
  255. .llseek = default_llseek,
  256. };
  257. int ath6kl_debug_init(struct ath6kl *ar)
  258. {
  259. ar->debugfs_phy = debugfs_create_dir("ath6kl",
  260. ar->wdev->wiphy->debugfsdir);
  261. if (!ar->debugfs_phy)
  262. return -ENOMEM;
  263. debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
  264. &fops_tgt_stats);
  265. return 0;
  266. }
  267. #endif