debug.c 23 KB

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