debug.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. /*
  2. * Copyright (c) 2008-2009 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 <linux/slab.h>
  17. #include <asm/unaligned.h>
  18. #include "ath9k.h"
  19. #define REG_WRITE_D(_ah, _reg, _val) \
  20. ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
  21. #define REG_READ_D(_ah, _reg) \
  22. ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
  23. static struct dentry *ath9k_debugfs_root;
  24. static int ath9k_debugfs_open(struct inode *inode, struct file *file)
  25. {
  26. file->private_data = inode->i_private;
  27. return 0;
  28. }
  29. #ifdef CONFIG_ATH_DEBUG
  30. static ssize_t read_file_debug(struct file *file, char __user *user_buf,
  31. size_t count, loff_t *ppos)
  32. {
  33. struct ath_softc *sc = file->private_data;
  34. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  35. char buf[32];
  36. unsigned int len;
  37. len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask);
  38. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  39. }
  40. static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
  41. size_t count, loff_t *ppos)
  42. {
  43. struct ath_softc *sc = file->private_data;
  44. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  45. unsigned long mask;
  46. char buf[32];
  47. ssize_t len;
  48. len = min(count, sizeof(buf) - 1);
  49. if (copy_from_user(buf, user_buf, len))
  50. return -EINVAL;
  51. buf[len] = '\0';
  52. if (strict_strtoul(buf, 0, &mask))
  53. return -EINVAL;
  54. common->debug_mask = mask;
  55. return count;
  56. }
  57. static const struct file_operations fops_debug = {
  58. .read = read_file_debug,
  59. .write = write_file_debug,
  60. .open = ath9k_debugfs_open,
  61. .owner = THIS_MODULE
  62. };
  63. #endif
  64. #define DMA_BUF_LEN 1024
  65. static ssize_t read_file_dma(struct file *file, char __user *user_buf,
  66. size_t count, loff_t *ppos)
  67. {
  68. struct ath_softc *sc = file->private_data;
  69. struct ath_hw *ah = sc->sc_ah;
  70. char *buf;
  71. int retval;
  72. unsigned int len = 0;
  73. u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
  74. int i, qcuOffset = 0, dcuOffset = 0;
  75. u32 *qcuBase = &val[0], *dcuBase = &val[4];
  76. buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
  77. if (!buf)
  78. return 0;
  79. ath9k_ps_wakeup(sc);
  80. REG_WRITE_D(ah, AR_MACMISC,
  81. ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
  82. (AR_MACMISC_MISC_OBS_BUS_1 <<
  83. AR_MACMISC_MISC_OBS_BUS_MSB_S)));
  84. len += snprintf(buf + len, DMA_BUF_LEN - len,
  85. "Raw DMA Debug values:\n");
  86. for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
  87. if (i % 4 == 0)
  88. len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
  89. val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
  90. len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
  91. i, val[i]);
  92. }
  93. len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
  94. len += snprintf(buf + len, DMA_BUF_LEN - len,
  95. "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
  96. for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
  97. if (i == 8) {
  98. qcuOffset = 0;
  99. qcuBase++;
  100. }
  101. if (i == 6) {
  102. dcuOffset = 0;
  103. dcuBase++;
  104. }
  105. len += snprintf(buf + len, DMA_BUF_LEN - len,
  106. "%2d %2x %1x %2x %2x\n",
  107. i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
  108. (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
  109. val[2] & (0x7 << (i * 3)) >> (i * 3),
  110. (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
  111. }
  112. len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
  113. len += snprintf(buf + len, DMA_BUF_LEN - len,
  114. "qcu_stitch state: %2x qcu_fetch state: %2x\n",
  115. (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
  116. len += snprintf(buf + len, DMA_BUF_LEN - len,
  117. "qcu_complete state: %2x dcu_complete state: %2x\n",
  118. (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
  119. len += snprintf(buf + len, DMA_BUF_LEN - len,
  120. "dcu_arb state: %2x dcu_fp state: %2x\n",
  121. (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
  122. len += snprintf(buf + len, DMA_BUF_LEN - len,
  123. "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
  124. (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
  125. len += snprintf(buf + len, DMA_BUF_LEN - len,
  126. "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
  127. (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
  128. len += snprintf(buf + len, DMA_BUF_LEN - len,
  129. "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
  130. (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
  131. len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x \n",
  132. REG_READ_D(ah, AR_OBS_BUS_1));
  133. len += snprintf(buf + len, DMA_BUF_LEN - len,
  134. "AR_CR: 0x%x \n", REG_READ_D(ah, AR_CR));
  135. ath9k_ps_restore(sc);
  136. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  137. kfree(buf);
  138. return retval;
  139. }
  140. static const struct file_operations fops_dma = {
  141. .read = read_file_dma,
  142. .open = ath9k_debugfs_open,
  143. .owner = THIS_MODULE
  144. };
  145. void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
  146. {
  147. if (status)
  148. sc->debug.stats.istats.total++;
  149. if (status & ATH9K_INT_RX)
  150. sc->debug.stats.istats.rxok++;
  151. if (status & ATH9K_INT_RXEOL)
  152. sc->debug.stats.istats.rxeol++;
  153. if (status & ATH9K_INT_RXORN)
  154. sc->debug.stats.istats.rxorn++;
  155. if (status & ATH9K_INT_TX)
  156. sc->debug.stats.istats.txok++;
  157. if (status & ATH9K_INT_TXURN)
  158. sc->debug.stats.istats.txurn++;
  159. if (status & ATH9K_INT_MIB)
  160. sc->debug.stats.istats.mib++;
  161. if (status & ATH9K_INT_RXPHY)
  162. sc->debug.stats.istats.rxphyerr++;
  163. if (status & ATH9K_INT_RXKCM)
  164. sc->debug.stats.istats.rx_keycache_miss++;
  165. if (status & ATH9K_INT_SWBA)
  166. sc->debug.stats.istats.swba++;
  167. if (status & ATH9K_INT_BMISS)
  168. sc->debug.stats.istats.bmiss++;
  169. if (status & ATH9K_INT_BNR)
  170. sc->debug.stats.istats.bnr++;
  171. if (status & ATH9K_INT_CST)
  172. sc->debug.stats.istats.cst++;
  173. if (status & ATH9K_INT_GTT)
  174. sc->debug.stats.istats.gtt++;
  175. if (status & ATH9K_INT_TIM)
  176. sc->debug.stats.istats.tim++;
  177. if (status & ATH9K_INT_CABEND)
  178. sc->debug.stats.istats.cabend++;
  179. if (status & ATH9K_INT_DTIMSYNC)
  180. sc->debug.stats.istats.dtimsync++;
  181. if (status & ATH9K_INT_DTIM)
  182. sc->debug.stats.istats.dtim++;
  183. }
  184. static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
  185. size_t count, loff_t *ppos)
  186. {
  187. struct ath_softc *sc = file->private_data;
  188. char buf[512];
  189. unsigned int len = 0;
  190. len += snprintf(buf + len, sizeof(buf) - len,
  191. "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
  192. len += snprintf(buf + len, sizeof(buf) - len,
  193. "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
  194. len += snprintf(buf + len, sizeof(buf) - len,
  195. "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
  196. len += snprintf(buf + len, sizeof(buf) - len,
  197. "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
  198. len += snprintf(buf + len, sizeof(buf) - len,
  199. "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
  200. len += snprintf(buf + len, sizeof(buf) - len,
  201. "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
  202. len += snprintf(buf + len, sizeof(buf) - len,
  203. "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
  204. len += snprintf(buf + len, sizeof(buf) - len,
  205. "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
  206. len += snprintf(buf + len, sizeof(buf) - len,
  207. "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
  208. len += snprintf(buf + len, sizeof(buf) - len,
  209. "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
  210. len += snprintf(buf + len, sizeof(buf) - len,
  211. "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
  212. len += snprintf(buf + len, sizeof(buf) - len,
  213. "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
  214. len += snprintf(buf + len, sizeof(buf) - len,
  215. "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
  216. len += snprintf(buf + len, sizeof(buf) - len,
  217. "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
  218. len += snprintf(buf + len, sizeof(buf) - len,
  219. "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
  220. len += snprintf(buf + len, sizeof(buf) - len,
  221. "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
  222. len += snprintf(buf + len, sizeof(buf) - len,
  223. "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
  224. len += snprintf(buf + len, sizeof(buf) - len,
  225. "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
  226. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  227. }
  228. static const struct file_operations fops_interrupt = {
  229. .read = read_file_interrupt,
  230. .open = ath9k_debugfs_open,
  231. .owner = THIS_MODULE
  232. };
  233. void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
  234. {
  235. struct ath_rc_stats *stats;
  236. stats = &sc->debug.stats.rcstats[final_rate];
  237. stats->success++;
  238. }
  239. void ath_debug_stat_retries(struct ath_softc *sc, int rix,
  240. int xretries, int retries, u8 per)
  241. {
  242. struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
  243. stats->xretries += xretries;
  244. stats->retries += retries;
  245. stats->per = per;
  246. }
  247. static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
  248. size_t count, loff_t *ppos)
  249. {
  250. struct ath_softc *sc = file->private_data;
  251. char *buf;
  252. unsigned int len = 0, max;
  253. int i = 0;
  254. ssize_t retval;
  255. if (sc->cur_rate_table == NULL)
  256. return 0;
  257. max = 80 + sc->cur_rate_table->rate_cnt * 1024;
  258. buf = kmalloc(max + 1, GFP_KERNEL);
  259. if (buf == NULL)
  260. return 0;
  261. buf[max] = 0;
  262. len += sprintf(buf, "%6s %6s %6s "
  263. "%10s %10s %10s %10s\n",
  264. "HT", "MCS", "Rate",
  265. "Success", "Retries", "XRetries", "PER");
  266. for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
  267. u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
  268. struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
  269. char mcs[5];
  270. char htmode[5];
  271. int used_mcs = 0, used_htmode = 0;
  272. if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) {
  273. used_mcs = snprintf(mcs, 5, "%d",
  274. sc->cur_rate_table->info[i].ratecode);
  275. if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy))
  276. used_htmode = snprintf(htmode, 5, "HT40");
  277. else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy))
  278. used_htmode = snprintf(htmode, 5, "HT20");
  279. else
  280. used_htmode = snprintf(htmode, 5, "????");
  281. }
  282. mcs[used_mcs] = '\0';
  283. htmode[used_htmode] = '\0';
  284. len += snprintf(buf + len, max - len,
  285. "%6s %6s %3u.%d: "
  286. "%10u %10u %10u %10u\n",
  287. htmode,
  288. mcs,
  289. ratekbps / 1000,
  290. (ratekbps % 1000) / 100,
  291. stats->success,
  292. stats->retries,
  293. stats->xretries,
  294. stats->per);
  295. }
  296. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  297. kfree(buf);
  298. return retval;
  299. }
  300. static const struct file_operations fops_rcstat = {
  301. .read = read_file_rcstat,
  302. .open = ath9k_debugfs_open,
  303. .owner = THIS_MODULE
  304. };
  305. static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
  306. {
  307. switch (state) {
  308. case ATH_WIPHY_INACTIVE:
  309. return "INACTIVE";
  310. case ATH_WIPHY_ACTIVE:
  311. return "ACTIVE";
  312. case ATH_WIPHY_PAUSING:
  313. return "PAUSING";
  314. case ATH_WIPHY_PAUSED:
  315. return "PAUSED";
  316. case ATH_WIPHY_SCAN:
  317. return "SCAN";
  318. }
  319. return "?";
  320. }
  321. static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
  322. size_t count, loff_t *ppos)
  323. {
  324. struct ath_softc *sc = file->private_data;
  325. char buf[512];
  326. unsigned int len = 0;
  327. int i;
  328. u8 addr[ETH_ALEN];
  329. len += snprintf(buf + len, sizeof(buf) - len,
  330. "primary: %s (%s chan=%d ht=%d)\n",
  331. wiphy_name(sc->pri_wiphy->hw->wiphy),
  332. ath_wiphy_state_str(sc->pri_wiphy->state),
  333. sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
  334. for (i = 0; i < sc->num_sec_wiphy; i++) {
  335. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  336. if (aphy == NULL)
  337. continue;
  338. len += snprintf(buf + len, sizeof(buf) - len,
  339. "secondary: %s (%s chan=%d ht=%d)\n",
  340. wiphy_name(aphy->hw->wiphy),
  341. ath_wiphy_state_str(aphy->state),
  342. aphy->chan_idx, aphy->chan_is_ht);
  343. }
  344. put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
  345. put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
  346. len += snprintf(buf + len, sizeof(buf) - len,
  347. "addr: %pM\n", addr);
  348. put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
  349. put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
  350. len += snprintf(buf + len, sizeof(buf) - len,
  351. "addrmask: %pM\n", addr);
  352. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  353. }
  354. static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
  355. {
  356. int i;
  357. if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
  358. return sc->pri_wiphy;
  359. for (i = 0; i < sc->num_sec_wiphy; i++) {
  360. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  361. if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
  362. return aphy;
  363. }
  364. return NULL;
  365. }
  366. static int del_wiphy(struct ath_softc *sc, const char *name)
  367. {
  368. struct ath_wiphy *aphy = get_wiphy(sc, name);
  369. if (!aphy)
  370. return -ENOENT;
  371. return ath9k_wiphy_del(aphy);
  372. }
  373. static int pause_wiphy(struct ath_softc *sc, const char *name)
  374. {
  375. struct ath_wiphy *aphy = get_wiphy(sc, name);
  376. if (!aphy)
  377. return -ENOENT;
  378. return ath9k_wiphy_pause(aphy);
  379. }
  380. static int unpause_wiphy(struct ath_softc *sc, const char *name)
  381. {
  382. struct ath_wiphy *aphy = get_wiphy(sc, name);
  383. if (!aphy)
  384. return -ENOENT;
  385. return ath9k_wiphy_unpause(aphy);
  386. }
  387. static int select_wiphy(struct ath_softc *sc, const char *name)
  388. {
  389. struct ath_wiphy *aphy = get_wiphy(sc, name);
  390. if (!aphy)
  391. return -ENOENT;
  392. return ath9k_wiphy_select(aphy);
  393. }
  394. static int schedule_wiphy(struct ath_softc *sc, const char *msec)
  395. {
  396. ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
  397. return 0;
  398. }
  399. static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
  400. size_t count, loff_t *ppos)
  401. {
  402. struct ath_softc *sc = file->private_data;
  403. char buf[50];
  404. size_t len;
  405. len = min(count, sizeof(buf) - 1);
  406. if (copy_from_user(buf, user_buf, len))
  407. return -EFAULT;
  408. buf[len] = '\0';
  409. if (len > 0 && buf[len - 1] == '\n')
  410. buf[len - 1] = '\0';
  411. if (strncmp(buf, "add", 3) == 0) {
  412. int res = ath9k_wiphy_add(sc);
  413. if (res < 0)
  414. return res;
  415. } else if (strncmp(buf, "del=", 4) == 0) {
  416. int res = del_wiphy(sc, buf + 4);
  417. if (res < 0)
  418. return res;
  419. } else if (strncmp(buf, "pause=", 6) == 0) {
  420. int res = pause_wiphy(sc, buf + 6);
  421. if (res < 0)
  422. return res;
  423. } else if (strncmp(buf, "unpause=", 8) == 0) {
  424. int res = unpause_wiphy(sc, buf + 8);
  425. if (res < 0)
  426. return res;
  427. } else if (strncmp(buf, "select=", 7) == 0) {
  428. int res = select_wiphy(sc, buf + 7);
  429. if (res < 0)
  430. return res;
  431. } else if (strncmp(buf, "schedule=", 9) == 0) {
  432. int res = schedule_wiphy(sc, buf + 9);
  433. if (res < 0)
  434. return res;
  435. } else
  436. return -EOPNOTSUPP;
  437. return count;
  438. }
  439. static const struct file_operations fops_wiphy = {
  440. .read = read_file_wiphy,
  441. .write = write_file_wiphy,
  442. .open = ath9k_debugfs_open,
  443. .owner = THIS_MODULE
  444. };
  445. #define PR(str, elem) \
  446. do { \
  447. len += snprintf(buf + len, size - len, \
  448. "%s%13u%11u%10u%10u\n", str, \
  449. sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
  450. sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
  451. sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
  452. sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
  453. } while(0)
  454. static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
  455. size_t count, loff_t *ppos)
  456. {
  457. struct ath_softc *sc = file->private_data;
  458. char *buf;
  459. unsigned int len = 0, size = 2048;
  460. ssize_t retval = 0;
  461. buf = kzalloc(size, GFP_KERNEL);
  462. if (buf == NULL)
  463. return 0;
  464. len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
  465. PR("MPDUs Queued: ", queued);
  466. PR("MPDUs Completed: ", completed);
  467. PR("Aggregates: ", a_aggr);
  468. PR("AMPDUs Queued: ", a_queued);
  469. PR("AMPDUs Completed:", a_completed);
  470. PR("AMPDUs Retried: ", a_retries);
  471. PR("AMPDUs XRetried: ", a_xretries);
  472. PR("FIFO Underrun: ", fifo_underrun);
  473. PR("TXOP Exceeded: ", xtxop);
  474. PR("TXTIMER Expiry: ", timer_exp);
  475. PR("DESC CFG Error: ", desc_cfg_err);
  476. PR("DATA Underrun: ", data_underrun);
  477. PR("DELIM Underrun: ", delim_underrun);
  478. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  479. kfree(buf);
  480. return retval;
  481. }
  482. void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
  483. struct ath_buf *bf)
  484. {
  485. struct ath_desc *ds = bf->bf_desc;
  486. if (bf_isampdu(bf)) {
  487. if (bf_isxretried(bf))
  488. TX_STAT_INC(txq->axq_qnum, a_xretries);
  489. else
  490. TX_STAT_INC(txq->axq_qnum, a_completed);
  491. } else {
  492. TX_STAT_INC(txq->axq_qnum, completed);
  493. }
  494. if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO)
  495. TX_STAT_INC(txq->axq_qnum, fifo_underrun);
  496. if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP)
  497. TX_STAT_INC(txq->axq_qnum, xtxop);
  498. if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED)
  499. TX_STAT_INC(txq->axq_qnum, timer_exp);
  500. if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR)
  501. TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
  502. if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN)
  503. TX_STAT_INC(txq->axq_qnum, data_underrun);
  504. if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN)
  505. TX_STAT_INC(txq->axq_qnum, delim_underrun);
  506. }
  507. static const struct file_operations fops_xmit = {
  508. .read = read_file_xmit,
  509. .open = ath9k_debugfs_open,
  510. .owner = THIS_MODULE
  511. };
  512. static ssize_t read_file_recv(struct file *file, char __user *user_buf,
  513. size_t count, loff_t *ppos)
  514. {
  515. #define PHY_ERR(s, p) \
  516. len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
  517. sc->debug.stats.rxstats.phy_err_stats[p]);
  518. struct ath_softc *sc = file->private_data;
  519. char *buf;
  520. unsigned int len = 0, size = 1152;
  521. ssize_t retval = 0;
  522. buf = kzalloc(size, GFP_KERNEL);
  523. if (buf == NULL)
  524. return 0;
  525. len += snprintf(buf + len, size - len,
  526. "%18s : %10u\n", "CRC ERR",
  527. sc->debug.stats.rxstats.crc_err);
  528. len += snprintf(buf + len, size - len,
  529. "%18s : %10u\n", "DECRYPT CRC ERR",
  530. sc->debug.stats.rxstats.decrypt_crc_err);
  531. len += snprintf(buf + len, size - len,
  532. "%18s : %10u\n", "PHY ERR",
  533. sc->debug.stats.rxstats.phy_err);
  534. len += snprintf(buf + len, size - len,
  535. "%18s : %10u\n", "MIC ERR",
  536. sc->debug.stats.rxstats.mic_err);
  537. len += snprintf(buf + len, size - len,
  538. "%18s : %10u\n", "PRE-DELIM CRC ERR",
  539. sc->debug.stats.rxstats.pre_delim_crc_err);
  540. len += snprintf(buf + len, size - len,
  541. "%18s : %10u\n", "POST-DELIM CRC ERR",
  542. sc->debug.stats.rxstats.post_delim_crc_err);
  543. len += snprintf(buf + len, size - len,
  544. "%18s : %10u\n", "DECRYPT BUSY ERR",
  545. sc->debug.stats.rxstats.decrypt_busy_err);
  546. PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
  547. PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
  548. PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
  549. PHY_ERR("RATE", ATH9K_PHYERR_RATE);
  550. PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
  551. PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
  552. PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
  553. PHY_ERR("TOR", ATH9K_PHYERR_TOR);
  554. PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
  555. PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
  556. PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
  557. PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
  558. PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
  559. PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
  560. PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
  561. PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
  562. PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
  563. PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
  564. PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
  565. PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
  566. PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
  567. PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
  568. PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
  569. PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
  570. PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
  571. PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
  572. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  573. kfree(buf);
  574. return retval;
  575. #undef PHY_ERR
  576. }
  577. void ath_debug_stat_rx(struct ath_softc *sc, struct ath_buf *bf)
  578. {
  579. #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
  580. #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
  581. struct ath_desc *ds = bf->bf_desc;
  582. u32 phyerr;
  583. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC)
  584. RX_STAT_INC(crc_err);
  585. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT)
  586. RX_STAT_INC(decrypt_crc_err);
  587. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC)
  588. RX_STAT_INC(mic_err);
  589. if (ds->ds_rxstat.rs_status & ATH9K_RX_DELIM_CRC_PRE)
  590. RX_STAT_INC(pre_delim_crc_err);
  591. if (ds->ds_rxstat.rs_status & ATH9K_RX_DELIM_CRC_POST)
  592. RX_STAT_INC(post_delim_crc_err);
  593. if (ds->ds_rxstat.rs_status & ATH9K_RX_DECRYPT_BUSY)
  594. RX_STAT_INC(decrypt_busy_err);
  595. if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY) {
  596. RX_STAT_INC(phy_err);
  597. phyerr = ds->ds_rxstat.rs_phyerr & 0x24;
  598. RX_PHY_ERR_INC(phyerr);
  599. }
  600. #undef RX_STAT_INC
  601. #undef RX_PHY_ERR_INC
  602. }
  603. static const struct file_operations fops_recv = {
  604. .read = read_file_recv,
  605. .open = ath9k_debugfs_open,
  606. .owner = THIS_MODULE
  607. };
  608. int ath9k_init_debug(struct ath_hw *ah)
  609. {
  610. struct ath_common *common = ath9k_hw_common(ah);
  611. struct ath_softc *sc = (struct ath_softc *) common->priv;
  612. if (!ath9k_debugfs_root)
  613. return -ENOENT;
  614. sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
  615. ath9k_debugfs_root);
  616. if (!sc->debug.debugfs_phy)
  617. goto err;
  618. #ifdef CONFIG_ATH_DEBUG
  619. sc->debug.debugfs_debug = debugfs_create_file("debug",
  620. S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
  621. if (!sc->debug.debugfs_debug)
  622. goto err;
  623. #endif
  624. sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
  625. sc->debug.debugfs_phy, sc, &fops_dma);
  626. if (!sc->debug.debugfs_dma)
  627. goto err;
  628. sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
  629. S_IRUSR,
  630. sc->debug.debugfs_phy,
  631. sc, &fops_interrupt);
  632. if (!sc->debug.debugfs_interrupt)
  633. goto err;
  634. sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
  635. S_IRUSR,
  636. sc->debug.debugfs_phy,
  637. sc, &fops_rcstat);
  638. if (!sc->debug.debugfs_rcstat)
  639. goto err;
  640. sc->debug.debugfs_wiphy = debugfs_create_file(
  641. "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
  642. &fops_wiphy);
  643. if (!sc->debug.debugfs_wiphy)
  644. goto err;
  645. sc->debug.debugfs_xmit = debugfs_create_file("xmit",
  646. S_IRUSR,
  647. sc->debug.debugfs_phy,
  648. sc, &fops_xmit);
  649. if (!sc->debug.debugfs_xmit)
  650. goto err;
  651. sc->debug.debugfs_recv = debugfs_create_file("recv",
  652. S_IRUSR,
  653. sc->debug.debugfs_phy,
  654. sc, &fops_recv);
  655. if (!sc->debug.debugfs_recv)
  656. goto err;
  657. return 0;
  658. err:
  659. ath9k_exit_debug(ah);
  660. return -ENOMEM;
  661. }
  662. void ath9k_exit_debug(struct ath_hw *ah)
  663. {
  664. struct ath_common *common = ath9k_hw_common(ah);
  665. struct ath_softc *sc = (struct ath_softc *) common->priv;
  666. debugfs_remove(sc->debug.debugfs_recv);
  667. debugfs_remove(sc->debug.debugfs_xmit);
  668. debugfs_remove(sc->debug.debugfs_wiphy);
  669. debugfs_remove(sc->debug.debugfs_rcstat);
  670. debugfs_remove(sc->debug.debugfs_interrupt);
  671. debugfs_remove(sc->debug.debugfs_dma);
  672. debugfs_remove(sc->debug.debugfs_debug);
  673. debugfs_remove(sc->debug.debugfs_phy);
  674. }
  675. int ath9k_debug_create_root(void)
  676. {
  677. ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  678. if (!ath9k_debugfs_root)
  679. return -ENOENT;
  680. return 0;
  681. }
  682. void ath9k_debug_remove_root(void)
  683. {
  684. debugfs_remove(ath9k_debugfs_root);
  685. ath9k_debugfs_root = NULL;
  686. }