debug.c 27 KB

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