debug.c 23 KB

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