debug.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/slab.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/export.h>
  19. #include <asm/unaligned.h>
  20. #include "ath9k.h"
  21. #define REG_WRITE_D(_ah, _reg, _val) \
  22. ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
  23. #define REG_READ_D(_ah, _reg) \
  24. ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
  25. void ath9k_debug_sync_cause(struct ath_softc *sc, u32 sync_cause)
  26. {
  27. if (sync_cause)
  28. sc->debug.stats.istats.sync_cause_all++;
  29. if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
  30. sc->debug.stats.istats.sync_rtc_irq++;
  31. if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
  32. sc->debug.stats.istats.sync_mac_irq++;
  33. if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
  34. sc->debug.stats.istats.eeprom_illegal_access++;
  35. if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
  36. sc->debug.stats.istats.apb_timeout++;
  37. if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
  38. sc->debug.stats.istats.pci_mode_conflict++;
  39. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
  40. sc->debug.stats.istats.host1_fatal++;
  41. if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
  42. sc->debug.stats.istats.host1_perr++;
  43. if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
  44. sc->debug.stats.istats.trcv_fifo_perr++;
  45. if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
  46. sc->debug.stats.istats.radm_cpl_ep++;
  47. if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
  48. sc->debug.stats.istats.radm_cpl_dllp_abort++;
  49. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
  50. sc->debug.stats.istats.radm_cpl_tlp_abort++;
  51. if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
  52. sc->debug.stats.istats.radm_cpl_ecrc_err++;
  53. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
  54. sc->debug.stats.istats.radm_cpl_timeout++;
  55. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
  56. sc->debug.stats.istats.local_timeout++;
  57. if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
  58. sc->debug.stats.istats.pm_access++;
  59. if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
  60. sc->debug.stats.istats.mac_awake++;
  61. if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
  62. sc->debug.stats.istats.mac_asleep++;
  63. if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
  64. sc->debug.stats.istats.mac_sleep_access++;
  65. }
  66. static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
  67. size_t count, loff_t *ppos)
  68. {
  69. u8 *buf = file->private_data;
  70. return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  71. }
  72. static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
  73. {
  74. vfree(file->private_data);
  75. return 0;
  76. }
  77. #ifdef CONFIG_ATH_DEBUG
  78. static ssize_t read_file_debug(struct file *file, char __user *user_buf,
  79. size_t count, loff_t *ppos)
  80. {
  81. struct ath_softc *sc = file->private_data;
  82. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  83. char buf[32];
  84. unsigned int len;
  85. len = sprintf(buf, "0x%08x\n", common->debug_mask);
  86. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  87. }
  88. static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
  89. size_t count, loff_t *ppos)
  90. {
  91. struct ath_softc *sc = file->private_data;
  92. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  93. unsigned long mask;
  94. char buf[32];
  95. ssize_t len;
  96. len = min(count, sizeof(buf) - 1);
  97. if (copy_from_user(buf, user_buf, len))
  98. return -EFAULT;
  99. buf[len] = '\0';
  100. if (kstrtoul(buf, 0, &mask))
  101. return -EINVAL;
  102. common->debug_mask = mask;
  103. return count;
  104. }
  105. static const struct file_operations fops_debug = {
  106. .read = read_file_debug,
  107. .write = write_file_debug,
  108. .open = simple_open,
  109. .owner = THIS_MODULE,
  110. .llseek = default_llseek,
  111. };
  112. #endif
  113. #define DMA_BUF_LEN 1024
  114. static ssize_t read_file_ani(struct file *file, char __user *user_buf,
  115. size_t count, loff_t *ppos)
  116. {
  117. struct ath_softc *sc = file->private_data;
  118. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  119. struct ath_hw *ah = sc->sc_ah;
  120. unsigned int len = 0;
  121. const unsigned int size = 1024;
  122. ssize_t retval = 0;
  123. char *buf;
  124. int i;
  125. struct {
  126. const char *name;
  127. unsigned int val;
  128. } ani_info[] = {
  129. { "ANI RESET", ah->stats.ast_ani_reset },
  130. { "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
  131. { "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
  132. { "SPUR UP", ah->stats.ast_ani_spurup },
  133. { "SPUR DOWN", ah->stats.ast_ani_spurup },
  134. { "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
  135. { "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
  136. { "MRC-CCK ON", ah->stats.ast_ani_ccklow },
  137. { "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
  138. { "FIR-STEP UP", ah->stats.ast_ani_stepup },
  139. { "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
  140. { "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
  141. { "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
  142. { "CCK ERRORS", ah->stats.ast_ani_cckerrs },
  143. };
  144. buf = kzalloc(size, GFP_KERNEL);
  145. if (buf == NULL)
  146. return -ENOMEM;
  147. len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
  148. common->disable_ani ? "DISABLED" : "ENABLED");
  149. if (common->disable_ani)
  150. goto exit;
  151. for (i = 0; i < ARRAY_SIZE(ani_info); i++)
  152. len += scnprintf(buf + len, size - len, "%15s: %u\n",
  153. ani_info[i].name, ani_info[i].val);
  154. exit:
  155. if (len > size)
  156. len = size;
  157. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  158. kfree(buf);
  159. return retval;
  160. }
  161. static ssize_t write_file_ani(struct file *file,
  162. const char __user *user_buf,
  163. size_t count, loff_t *ppos)
  164. {
  165. struct ath_softc *sc = file->private_data;
  166. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  167. unsigned long ani;
  168. char buf[32];
  169. ssize_t len;
  170. len = min(count, sizeof(buf) - 1);
  171. if (copy_from_user(buf, user_buf, len))
  172. return -EFAULT;
  173. buf[len] = '\0';
  174. if (kstrtoul(buf, 0, &ani))
  175. return -EINVAL;
  176. if (ani > 1)
  177. return -EINVAL;
  178. common->disable_ani = !ani;
  179. if (common->disable_ani) {
  180. clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
  181. ath_stop_ani(sc);
  182. } else {
  183. ath_check_ani(sc);
  184. }
  185. return count;
  186. }
  187. static const struct file_operations fops_ani = {
  188. .read = read_file_ani,
  189. .write = write_file_ani,
  190. .open = simple_open,
  191. .owner = THIS_MODULE,
  192. .llseek = default_llseek,
  193. };
  194. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  195. static ssize_t read_file_bt_ant_diversity(struct file *file,
  196. char __user *user_buf,
  197. size_t count, loff_t *ppos)
  198. {
  199. struct ath_softc *sc = file->private_data;
  200. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  201. char buf[32];
  202. unsigned int len;
  203. len = sprintf(buf, "%d\n", common->bt_ant_diversity);
  204. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  205. }
  206. static ssize_t write_file_bt_ant_diversity(struct file *file,
  207. const char __user *user_buf,
  208. size_t count, loff_t *ppos)
  209. {
  210. struct ath_softc *sc = file->private_data;
  211. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  212. struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
  213. unsigned long bt_ant_diversity;
  214. char buf[32];
  215. ssize_t len;
  216. len = min(count, sizeof(buf) - 1);
  217. if (copy_from_user(buf, user_buf, len))
  218. return -EFAULT;
  219. if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
  220. goto exit;
  221. buf[len] = '\0';
  222. if (kstrtoul(buf, 0, &bt_ant_diversity))
  223. return -EINVAL;
  224. common->bt_ant_diversity = !!bt_ant_diversity;
  225. ath9k_ps_wakeup(sc);
  226. ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
  227. ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
  228. common->bt_ant_diversity);
  229. ath9k_ps_restore(sc);
  230. exit:
  231. return count;
  232. }
  233. static const struct file_operations fops_bt_ant_diversity = {
  234. .read = read_file_bt_ant_diversity,
  235. .write = write_file_bt_ant_diversity,
  236. .open = simple_open,
  237. .owner = THIS_MODULE,
  238. .llseek = default_llseek,
  239. };
  240. #endif
  241. void ath9k_debug_stat_ant(struct ath_softc *sc,
  242. struct ath_hw_antcomb_conf *div_ant_conf,
  243. int main_rssi_avg, int alt_rssi_avg)
  244. {
  245. struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
  246. struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
  247. as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
  248. as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
  249. as_main->rssi_avg = main_rssi_avg;
  250. as_alt->rssi_avg = alt_rssi_avg;
  251. }
  252. static ssize_t read_file_antenna_diversity(struct file *file,
  253. char __user *user_buf,
  254. size_t count, loff_t *ppos)
  255. {
  256. struct ath_softc *sc = file->private_data;
  257. struct ath_hw *ah = sc->sc_ah;
  258. struct ath9k_hw_capabilities *pCap = &ah->caps;
  259. struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
  260. struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
  261. struct ath_hw_antcomb_conf div_ant_conf;
  262. unsigned int len = 0;
  263. const unsigned int size = 1024;
  264. ssize_t retval = 0;
  265. char *buf;
  266. static const char *lna_conf_str[4] = {
  267. "LNA1_MINUS_LNA2", "LNA2", "LNA1", "LNA1_PLUS_LNA2"
  268. };
  269. buf = kzalloc(size, GFP_KERNEL);
  270. if (buf == NULL)
  271. return -ENOMEM;
  272. if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
  273. len += scnprintf(buf + len, size - len, "%s\n",
  274. "Antenna Diversity Combining is disabled");
  275. goto exit;
  276. }
  277. ath9k_ps_wakeup(sc);
  278. ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
  279. len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
  280. lna_conf_str[div_ant_conf.main_lna_conf]);
  281. len += scnprintf(buf + len, size - len, "Current ALT config : %s\n",
  282. lna_conf_str[div_ant_conf.alt_lna_conf]);
  283. len += scnprintf(buf + len, size - len, "Average MAIN RSSI : %d\n",
  284. as_main->rssi_avg);
  285. len += scnprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n",
  286. as_alt->rssi_avg);
  287. ath9k_ps_restore(sc);
  288. len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
  289. len += scnprintf(buf + len, size - len, "-------------------\n");
  290. len += scnprintf(buf + len, size - len, "%30s%15s\n",
  291. "MAIN", "ALT");
  292. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  293. "TOTAL COUNT",
  294. as_main->recv_cnt,
  295. as_alt->recv_cnt);
  296. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  297. "LNA1",
  298. as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
  299. as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
  300. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  301. "LNA2",
  302. as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
  303. as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
  304. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  305. "LNA1 + LNA2",
  306. as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
  307. as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
  308. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  309. "LNA1 - LNA2",
  310. as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
  311. as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
  312. len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
  313. len += scnprintf(buf + len, size - len, "--------------------\n");
  314. len += scnprintf(buf + len, size - len, "%30s%15s\n",
  315. "MAIN", "ALT");
  316. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  317. "LNA1",
  318. as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
  319. as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
  320. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  321. "LNA2",
  322. as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
  323. as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
  324. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  325. "LNA1 + LNA2",
  326. as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
  327. as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
  328. len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
  329. "LNA1 - LNA2",
  330. as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
  331. as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
  332. exit:
  333. if (len > size)
  334. len = size;
  335. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  336. kfree(buf);
  337. return retval;
  338. }
  339. static const struct file_operations fops_antenna_diversity = {
  340. .read = read_file_antenna_diversity,
  341. .open = simple_open,
  342. .owner = THIS_MODULE,
  343. .llseek = default_llseek,
  344. };
  345. static int read_file_dma(struct seq_file *file, void *data)
  346. {
  347. struct ieee80211_hw *hw = dev_get_drvdata(file->private);
  348. struct ath_softc *sc = hw->priv;
  349. struct ath_hw *ah = sc->sc_ah;
  350. u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
  351. int i, qcuOffset = 0, dcuOffset = 0;
  352. u32 *qcuBase = &val[0], *dcuBase = &val[4];
  353. ath9k_ps_wakeup(sc);
  354. REG_WRITE_D(ah, AR_MACMISC,
  355. ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
  356. (AR_MACMISC_MISC_OBS_BUS_1 <<
  357. AR_MACMISC_MISC_OBS_BUS_MSB_S)));
  358. seq_puts(file, "Raw DMA Debug values:\n");
  359. for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
  360. if (i % 4 == 0)
  361. seq_puts(file, "\n");
  362. val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
  363. seq_printf(file, "%d: %08x ", i, val[i]);
  364. }
  365. seq_puts(file, "\n\n");
  366. seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
  367. for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
  368. if (i == 8) {
  369. qcuOffset = 0;
  370. qcuBase++;
  371. }
  372. if (i == 6) {
  373. dcuOffset = 0;
  374. dcuBase++;
  375. }
  376. seq_printf(file, "%2d %2x %1x %2x %2x\n",
  377. i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
  378. (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
  379. (val[2] & (0x7 << (i * 3))) >> (i * 3),
  380. (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
  381. }
  382. seq_puts(file, "\n");
  383. seq_printf(file, "qcu_stitch state: %2x qcu_fetch state: %2x\n",
  384. (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
  385. seq_printf(file, "qcu_complete state: %2x dcu_complete state: %2x\n",
  386. (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
  387. seq_printf(file, "dcu_arb state: %2x dcu_fp state: %2x\n",
  388. (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
  389. seq_printf(file, "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
  390. (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
  391. seq_printf(file, "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
  392. (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
  393. seq_printf(file, "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
  394. (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
  395. seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
  396. seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
  397. ath9k_ps_restore(sc);
  398. return 0;
  399. }
  400. void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
  401. {
  402. if (status)
  403. sc->debug.stats.istats.total++;
  404. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  405. if (status & ATH9K_INT_RXLP)
  406. sc->debug.stats.istats.rxlp++;
  407. if (status & ATH9K_INT_RXHP)
  408. sc->debug.stats.istats.rxhp++;
  409. if (status & ATH9K_INT_BB_WATCHDOG)
  410. sc->debug.stats.istats.bb_watchdog++;
  411. } else {
  412. if (status & ATH9K_INT_RX)
  413. sc->debug.stats.istats.rxok++;
  414. }
  415. if (status & ATH9K_INT_RXEOL)
  416. sc->debug.stats.istats.rxeol++;
  417. if (status & ATH9K_INT_RXORN)
  418. sc->debug.stats.istats.rxorn++;
  419. if (status & ATH9K_INT_TX)
  420. sc->debug.stats.istats.txok++;
  421. if (status & ATH9K_INT_TXURN)
  422. sc->debug.stats.istats.txurn++;
  423. if (status & ATH9K_INT_RXPHY)
  424. sc->debug.stats.istats.rxphyerr++;
  425. if (status & ATH9K_INT_RXKCM)
  426. sc->debug.stats.istats.rx_keycache_miss++;
  427. if (status & ATH9K_INT_SWBA)
  428. sc->debug.stats.istats.swba++;
  429. if (status & ATH9K_INT_BMISS)
  430. sc->debug.stats.istats.bmiss++;
  431. if (status & ATH9K_INT_BNR)
  432. sc->debug.stats.istats.bnr++;
  433. if (status & ATH9K_INT_CST)
  434. sc->debug.stats.istats.cst++;
  435. if (status & ATH9K_INT_GTT)
  436. sc->debug.stats.istats.gtt++;
  437. if (status & ATH9K_INT_TIM)
  438. sc->debug.stats.istats.tim++;
  439. if (status & ATH9K_INT_CABEND)
  440. sc->debug.stats.istats.cabend++;
  441. if (status & ATH9K_INT_DTIMSYNC)
  442. sc->debug.stats.istats.dtimsync++;
  443. if (status & ATH9K_INT_DTIM)
  444. sc->debug.stats.istats.dtim++;
  445. if (status & ATH9K_INT_TSFOOR)
  446. sc->debug.stats.istats.tsfoor++;
  447. if (status & ATH9K_INT_MCI)
  448. sc->debug.stats.istats.mci++;
  449. if (status & ATH9K_INT_GENTIMER)
  450. sc->debug.stats.istats.gen_timer++;
  451. }
  452. static int read_file_interrupt(struct seq_file *file, void *data)
  453. {
  454. struct ieee80211_hw *hw = dev_get_drvdata(file->private);
  455. struct ath_softc *sc = hw->priv;
  456. #define PR_IS(a, s) \
  457. do { \
  458. seq_printf(file, "%21s: %10u\n", a, \
  459. sc->debug.stats.istats.s); \
  460. } while (0)
  461. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  462. PR_IS("RXLP", rxlp);
  463. PR_IS("RXHP", rxhp);
  464. PR_IS("WATHDOG", bb_watchdog);
  465. } else {
  466. PR_IS("RX", rxok);
  467. }
  468. PR_IS("RXEOL", rxeol);
  469. PR_IS("RXORN", rxorn);
  470. PR_IS("TX", txok);
  471. PR_IS("TXURN", txurn);
  472. PR_IS("MIB", mib);
  473. PR_IS("RXPHY", rxphyerr);
  474. PR_IS("RXKCM", rx_keycache_miss);
  475. PR_IS("SWBA", swba);
  476. PR_IS("BMISS", bmiss);
  477. PR_IS("BNR", bnr);
  478. PR_IS("CST", cst);
  479. PR_IS("GTT", gtt);
  480. PR_IS("TIM", tim);
  481. PR_IS("CABEND", cabend);
  482. PR_IS("DTIMSYNC", dtimsync);
  483. PR_IS("DTIM", dtim);
  484. PR_IS("TSFOOR", tsfoor);
  485. PR_IS("MCI", mci);
  486. PR_IS("GENTIMER", gen_timer);
  487. PR_IS("TOTAL", total);
  488. seq_puts(file, "SYNC_CAUSE stats:\n");
  489. PR_IS("Sync-All", sync_cause_all);
  490. PR_IS("RTC-IRQ", sync_rtc_irq);
  491. PR_IS("MAC-IRQ", sync_mac_irq);
  492. PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
  493. PR_IS("APB-Timeout", apb_timeout);
  494. PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
  495. PR_IS("HOST1-Fatal", host1_fatal);
  496. PR_IS("HOST1-Perr", host1_perr);
  497. PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
  498. PR_IS("RADM-CPL-EP", radm_cpl_ep);
  499. PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
  500. PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
  501. PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
  502. PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
  503. PR_IS("Local-Bus-Timeout", local_timeout);
  504. PR_IS("PM-Access", pm_access);
  505. PR_IS("MAC-Awake", mac_awake);
  506. PR_IS("MAC-Asleep", mac_asleep);
  507. PR_IS("MAC-Sleep-Access", mac_sleep_access);
  508. return 0;
  509. }
  510. static int read_file_xmit(struct seq_file *file, void *data)
  511. {
  512. struct ieee80211_hw *hw = dev_get_drvdata(file->private);
  513. struct ath_softc *sc = hw->priv;
  514. seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
  515. PR("MPDUs Queued: ", queued);
  516. PR("MPDUs Completed: ", completed);
  517. PR("MPDUs XRetried: ", xretries);
  518. PR("Aggregates: ", a_aggr);
  519. PR("AMPDUs Queued HW:", a_queued_hw);
  520. PR("AMPDUs Queued SW:", a_queued_sw);
  521. PR("AMPDUs Completed:", a_completed);
  522. PR("AMPDUs Retried: ", a_retries);
  523. PR("AMPDUs XRetried: ", a_xretries);
  524. PR("TXERR Filtered: ", txerr_filtered);
  525. PR("FIFO Underrun: ", fifo_underrun);
  526. PR("TXOP Exceeded: ", xtxop);
  527. PR("TXTIMER Expiry: ", timer_exp);
  528. PR("DESC CFG Error: ", desc_cfg_err);
  529. PR("DATA Underrun: ", data_underrun);
  530. PR("DELIM Underrun: ", delim_underrun);
  531. PR("TX-Pkts-All: ", tx_pkts_all);
  532. PR("TX-Bytes-All: ", tx_bytes_all);
  533. PR("HW-put-tx-buf: ", puttxbuf);
  534. PR("HW-tx-start: ", txstart);
  535. PR("HW-tx-proc-desc: ", txprocdesc);
  536. PR("TX-Failed: ", txfailed);
  537. return 0;
  538. }
  539. static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
  540. struct seq_file *file)
  541. {
  542. ath_txq_lock(sc, txq);
  543. seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
  544. seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
  545. seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
  546. seq_printf(file, "%s: %3d ", "pending", txq->pending_frames);
  547. seq_printf(file, "%s: %d\n", "stopped", txq->stopped);
  548. ath_txq_unlock(sc, txq);
  549. }
  550. static int read_file_queues(struct seq_file *file, void *data)
  551. {
  552. struct ieee80211_hw *hw = dev_get_drvdata(file->private);
  553. struct ath_softc *sc = hw->priv;
  554. struct ath_txq *txq;
  555. int i;
  556. static const char *qname[4] = {
  557. "VO", "VI", "BE", "BK"
  558. };
  559. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  560. txq = sc->tx.txq_map[i];
  561. seq_printf(file, "(%s): ", qname[i]);
  562. print_queue(sc, txq, file);
  563. }
  564. seq_puts(file, "(CAB): ");
  565. print_queue(sc, sc->beacon.cabq, file);
  566. return 0;
  567. }
  568. static int read_file_misc(struct seq_file *file, void *data)
  569. {
  570. struct ieee80211_hw *hw = dev_get_drvdata(file->private);
  571. struct ath_softc *sc = hw->priv;
  572. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  573. struct ath9k_vif_iter_data iter_data;
  574. struct ath_chanctx *ctx;
  575. unsigned int reg;
  576. u32 rxfilter, i;
  577. seq_printf(file, "BSSID: %pM\n", common->curbssid);
  578. seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
  579. seq_printf(file, "OPMODE: %s\n",
  580. ath_opmode_to_string(sc->sc_ah->opmode));
  581. ath9k_ps_wakeup(sc);
  582. rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
  583. ath9k_ps_restore(sc);
  584. seq_printf(file, "RXFILTER: 0x%x", rxfilter);
  585. if (rxfilter & ATH9K_RX_FILTER_UCAST)
  586. seq_puts(file, " UCAST");
  587. if (rxfilter & ATH9K_RX_FILTER_MCAST)
  588. seq_puts(file, " MCAST");
  589. if (rxfilter & ATH9K_RX_FILTER_BCAST)
  590. seq_puts(file, " BCAST");
  591. if (rxfilter & ATH9K_RX_FILTER_CONTROL)
  592. seq_puts(file, " CONTROL");
  593. if (rxfilter & ATH9K_RX_FILTER_BEACON)
  594. seq_puts(file, " BEACON");
  595. if (rxfilter & ATH9K_RX_FILTER_PROM)
  596. seq_puts(file, " PROM");
  597. if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
  598. seq_puts(file, " PROBEREQ");
  599. if (rxfilter & ATH9K_RX_FILTER_PHYERR)
  600. seq_puts(file, " PHYERR");
  601. if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
  602. seq_puts(file, " MYBEACON");
  603. if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
  604. seq_puts(file, " COMP_BAR");
  605. if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
  606. seq_puts(file, " PSPOLL");
  607. if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
  608. seq_puts(file, " PHYRADAR");
  609. if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
  610. seq_puts(file, " MCAST_BCAST_ALL");
  611. if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
  612. seq_puts(file, " CONTROL_WRAPPER");
  613. seq_puts(file, "\n");
  614. reg = sc->sc_ah->imask;
  615. seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
  616. if (reg & ATH9K_INT_SWBA)
  617. seq_puts(file, " SWBA");
  618. if (reg & ATH9K_INT_BMISS)
  619. seq_puts(file, " BMISS");
  620. if (reg & ATH9K_INT_CST)
  621. seq_puts(file, " CST");
  622. if (reg & ATH9K_INT_RX)
  623. seq_puts(file, " RX");
  624. if (reg & ATH9K_INT_RXHP)
  625. seq_puts(file, " RXHP");
  626. if (reg & ATH9K_INT_RXLP)
  627. seq_puts(file, " RXLP");
  628. if (reg & ATH9K_INT_BB_WATCHDOG)
  629. seq_puts(file, " BB_WATCHDOG");
  630. seq_puts(file, "\n");
  631. i = 0;
  632. ath_for_each_chanctx(sc, ctx) {
  633. if (list_empty(&ctx->vifs))
  634. continue;
  635. ath9k_calculate_iter_data(sc, ctx, &iter_data);
  636. seq_printf(file,
  637. "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i WDS: %i",
  638. i++, (int)(ctx->assigned), iter_data.naps,
  639. iter_data.nstations,
  640. iter_data.nmeshes, iter_data.nwds);
  641. seq_printf(file, " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
  642. iter_data.nadhocs, sc->cur_chan->nvifs,
  643. sc->nbcnvifs);
  644. }
  645. return 0;
  646. }
  647. static int read_file_reset(struct seq_file *file, void *data)
  648. {
  649. struct ieee80211_hw *hw = dev_get_drvdata(file->private);
  650. struct ath_softc *sc = hw->priv;
  651. static const char * const reset_cause[__RESET_TYPE_MAX] = {
  652. [RESET_TYPE_BB_HANG] = "Baseband Hang",
  653. [RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
  654. [RESET_TYPE_FATAL_INT] = "Fatal HW Error",
  655. [RESET_TYPE_TX_ERROR] = "TX HW error",
  656. [RESET_TYPE_TX_GTT] = "Transmit timeout",
  657. [RESET_TYPE_TX_HANG] = "TX Path Hang",
  658. [RESET_TYPE_PLL_HANG] = "PLL RX Hang",
  659. [RESET_TYPE_MAC_HANG] = "MAC Hang",
  660. [RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
  661. [RESET_TYPE_MCI] = "MCI Reset",
  662. [RESET_TYPE_CALIBRATION] = "Calibration error",
  663. };
  664. int i;
  665. for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
  666. if (!reset_cause[i])
  667. continue;
  668. seq_printf(file, "%17s: %2d\n", reset_cause[i],
  669. sc->debug.stats.reset[i]);
  670. }
  671. return 0;
  672. }
  673. void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
  674. struct ath_tx_status *ts, struct ath_txq *txq,
  675. unsigned int flags)
  676. {
  677. int qnum = txq->axq_qnum;
  678. TX_STAT_INC(qnum, tx_pkts_all);
  679. sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
  680. if (bf_isampdu(bf)) {
  681. if (flags & ATH_TX_ERROR)
  682. TX_STAT_INC(qnum, a_xretries);
  683. else
  684. TX_STAT_INC(qnum, a_completed);
  685. } else {
  686. if (ts->ts_status & ATH9K_TXERR_XRETRY)
  687. TX_STAT_INC(qnum, xretries);
  688. else
  689. TX_STAT_INC(qnum, completed);
  690. }
  691. if (ts->ts_status & ATH9K_TXERR_FILT)
  692. TX_STAT_INC(qnum, txerr_filtered);
  693. if (ts->ts_status & ATH9K_TXERR_FIFO)
  694. TX_STAT_INC(qnum, fifo_underrun);
  695. if (ts->ts_status & ATH9K_TXERR_XTXOP)
  696. TX_STAT_INC(qnum, xtxop);
  697. if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
  698. TX_STAT_INC(qnum, timer_exp);
  699. if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
  700. TX_STAT_INC(qnum, desc_cfg_err);
  701. if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
  702. TX_STAT_INC(qnum, data_underrun);
  703. if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
  704. TX_STAT_INC(qnum, delim_underrun);
  705. }
  706. void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
  707. {
  708. ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
  709. }
  710. static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
  711. size_t count, loff_t *ppos)
  712. {
  713. struct ath_softc *sc = file->private_data;
  714. char buf[32];
  715. unsigned int len;
  716. len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
  717. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  718. }
  719. static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
  720. size_t count, loff_t *ppos)
  721. {
  722. struct ath_softc *sc = file->private_data;
  723. unsigned long regidx;
  724. char buf[32];
  725. ssize_t len;
  726. len = min(count, sizeof(buf) - 1);
  727. if (copy_from_user(buf, user_buf, len))
  728. return -EFAULT;
  729. buf[len] = '\0';
  730. if (kstrtoul(buf, 0, &regidx))
  731. return -EINVAL;
  732. sc->debug.regidx = regidx;
  733. return count;
  734. }
  735. static const struct file_operations fops_regidx = {
  736. .read = read_file_regidx,
  737. .write = write_file_regidx,
  738. .open = simple_open,
  739. .owner = THIS_MODULE,
  740. .llseek = default_llseek,
  741. };
  742. static ssize_t read_file_regval(struct file *file, char __user *user_buf,
  743. size_t count, loff_t *ppos)
  744. {
  745. struct ath_softc *sc = file->private_data;
  746. struct ath_hw *ah = sc->sc_ah;
  747. char buf[32];
  748. unsigned int len;
  749. u32 regval;
  750. ath9k_ps_wakeup(sc);
  751. regval = REG_READ_D(ah, sc->debug.regidx);
  752. ath9k_ps_restore(sc);
  753. len = sprintf(buf, "0x%08x\n", regval);
  754. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  755. }
  756. static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
  757. size_t count, loff_t *ppos)
  758. {
  759. struct ath_softc *sc = file->private_data;
  760. struct ath_hw *ah = sc->sc_ah;
  761. unsigned long regval;
  762. char buf[32];
  763. ssize_t len;
  764. len = min(count, sizeof(buf) - 1);
  765. if (copy_from_user(buf, user_buf, len))
  766. return -EFAULT;
  767. buf[len] = '\0';
  768. if (kstrtoul(buf, 0, &regval))
  769. return -EINVAL;
  770. ath9k_ps_wakeup(sc);
  771. REG_WRITE_D(ah, sc->debug.regidx, regval);
  772. ath9k_ps_restore(sc);
  773. return count;
  774. }
  775. static const struct file_operations fops_regval = {
  776. .read = read_file_regval,
  777. .write = write_file_regval,
  778. .open = simple_open,
  779. .owner = THIS_MODULE,
  780. .llseek = default_llseek,
  781. };
  782. #define REGDUMP_LINE_SIZE 20
  783. static int open_file_regdump(struct inode *inode, struct file *file)
  784. {
  785. struct ath_softc *sc = inode->i_private;
  786. unsigned int len = 0;
  787. u8 *buf;
  788. int i;
  789. unsigned long num_regs, regdump_len, max_reg_offset;
  790. max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
  791. num_regs = max_reg_offset / 4 + 1;
  792. regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
  793. buf = vmalloc(regdump_len);
  794. if (!buf)
  795. return -ENOMEM;
  796. ath9k_ps_wakeup(sc);
  797. for (i = 0; i < num_regs; i++)
  798. len += scnprintf(buf + len, regdump_len - len,
  799. "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
  800. ath9k_ps_restore(sc);
  801. file->private_data = buf;
  802. return 0;
  803. }
  804. static const struct file_operations fops_regdump = {
  805. .open = open_file_regdump,
  806. .read = ath9k_debugfs_read_buf,
  807. .release = ath9k_debugfs_release_buf,
  808. .owner = THIS_MODULE,
  809. .llseek = default_llseek,/* read accesses f_pos */
  810. };
  811. static int read_file_dump_nfcal(struct seq_file *file, void *data)
  812. {
  813. struct ieee80211_hw *hw = dev_get_drvdata(file->private);
  814. struct ath_softc *sc = hw->priv;
  815. struct ath_hw *ah = sc->sc_ah;
  816. struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
  817. struct ath_common *common = ath9k_hw_common(ah);
  818. struct ieee80211_conf *conf = &common->hw->conf;
  819. u32 i, j;
  820. u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
  821. u8 nread;
  822. seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
  823. seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
  824. for (i = 0; i < NUM_NF_READINGS; i++) {
  825. if (!(chainmask & (1 << i)) ||
  826. ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
  827. continue;
  828. nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
  829. seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
  830. for (j = 0; j < nread; j++)
  831. seq_printf(file, " %d", h[i].nfCalBuffer[j]);
  832. seq_puts(file, "\n");
  833. }
  834. return 0;
  835. }
  836. static int open_file_dump_nfcal(struct inode *inode, struct file *f)
  837. {
  838. return single_open(f, read_file_dump_nfcal, inode->i_private);
  839. }
  840. static const struct file_operations fops_dump_nfcal = {
  841. .read = seq_read,
  842. .open = open_file_dump_nfcal,
  843. .owner = THIS_MODULE,
  844. .llseek = seq_lseek,
  845. .release = single_release,
  846. };
  847. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  848. static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
  849. size_t count, loff_t *ppos)
  850. {
  851. struct ath_softc *sc = file->private_data;
  852. u32 len = 0, size = 1500;
  853. char *buf;
  854. size_t retval;
  855. buf = kzalloc(size, GFP_KERNEL);
  856. if (buf == NULL)
  857. return -ENOMEM;
  858. if (!sc->sc_ah->common.btcoex_enabled) {
  859. len = scnprintf(buf, size, "%s\n",
  860. "BTCOEX is disabled");
  861. goto exit;
  862. }
  863. len = ath9k_dump_btcoex(sc, buf, size);
  864. exit:
  865. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  866. kfree(buf);
  867. return retval;
  868. }
  869. static const struct file_operations fops_btcoex = {
  870. .read = read_file_btcoex,
  871. .open = simple_open,
  872. .owner = THIS_MODULE,
  873. .llseek = default_llseek,
  874. };
  875. #endif
  876. #ifdef CONFIG_ATH9K_DYNACK
  877. static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
  878. size_t count, loff_t *ppos)
  879. {
  880. struct ath_softc *sc = file->private_data;
  881. struct ath_hw *ah = sc->sc_ah;
  882. char buf[32];
  883. unsigned int len;
  884. len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
  885. (ah->dynack.enabled) ? 'A' : 'S');
  886. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  887. }
  888. static const struct file_operations fops_ackto = {
  889. .read = read_file_ackto,
  890. .open = simple_open,
  891. .owner = THIS_MODULE,
  892. .llseek = default_llseek,
  893. };
  894. #endif
  895. #ifdef CONFIG_ATH9K_WOW
  896. static ssize_t read_file_wow(struct file *file, char __user *user_buf,
  897. size_t count, loff_t *ppos)
  898. {
  899. struct ath_softc *sc = file->private_data;
  900. unsigned int len = 0, size = 32;
  901. ssize_t retval;
  902. char *buf;
  903. buf = kzalloc(size, GFP_KERNEL);
  904. if (!buf)
  905. return -ENOMEM;
  906. len += scnprintf(buf + len, size - len, "WOW: %s\n",
  907. sc->force_wow ? "ENABLED" : "DISABLED");
  908. if (len > size)
  909. len = size;
  910. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  911. kfree(buf);
  912. return retval;
  913. }
  914. static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
  915. size_t count, loff_t *ppos)
  916. {
  917. struct ath_softc *sc = file->private_data;
  918. unsigned long val;
  919. char buf[32];
  920. ssize_t len;
  921. len = min(count, sizeof(buf) - 1);
  922. if (copy_from_user(buf, user_buf, len))
  923. return -EFAULT;
  924. buf[len] = '\0';
  925. if (kstrtoul(buf, 0, &val))
  926. return -EINVAL;
  927. if (val != 1)
  928. return -EINVAL;
  929. if (!sc->force_wow) {
  930. sc->force_wow = true;
  931. ath9k_init_wow(sc->hw);
  932. }
  933. return count;
  934. }
  935. static const struct file_operations fops_wow = {
  936. .read = read_file_wow,
  937. .write = write_file_wow,
  938. .open = simple_open,
  939. .owner = THIS_MODULE,
  940. .llseek = default_llseek,
  941. };
  942. #endif
  943. static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
  944. size_t count, loff_t *ppos)
  945. {
  946. struct ath_softc *sc = file->private_data;
  947. struct ath_hw *ah = sc->sc_ah;
  948. unsigned int len = 0, size = 32;
  949. ssize_t retval;
  950. char *buf;
  951. buf = kzalloc(size, GFP_KERNEL);
  952. if (!buf)
  953. return -ENOMEM;
  954. len += scnprintf(buf + len, size - len, "%s\n",
  955. ah->tpc_enabled ? "ENABLED" : "DISABLED");
  956. if (len > size)
  957. len = size;
  958. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  959. kfree(buf);
  960. return retval;
  961. }
  962. static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
  963. size_t count, loff_t *ppos)
  964. {
  965. struct ath_softc *sc = file->private_data;
  966. struct ath_hw *ah = sc->sc_ah;
  967. unsigned long val;
  968. char buf[32];
  969. ssize_t len;
  970. bool tpc_enabled;
  971. len = min(count, sizeof(buf) - 1);
  972. if (copy_from_user(buf, user_buf, len))
  973. return -EFAULT;
  974. buf[len] = '\0';
  975. if (kstrtoul(buf, 0, &val))
  976. return -EINVAL;
  977. if (val < 0 || val > 1)
  978. return -EINVAL;
  979. tpc_enabled = !!val;
  980. if (tpc_enabled != ah->tpc_enabled) {
  981. ah->tpc_enabled = tpc_enabled;
  982. mutex_lock(&sc->mutex);
  983. ath9k_set_txpower(sc, NULL);
  984. mutex_unlock(&sc->mutex);
  985. }
  986. return count;
  987. }
  988. static const struct file_operations fops_tpc = {
  989. .read = read_file_tpc,
  990. .write = write_file_tpc,
  991. .open = simple_open,
  992. .owner = THIS_MODULE,
  993. .llseek = default_llseek,
  994. };
  995. /* Ethtool support for get-stats */
  996. #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
  997. static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
  998. "tx_pkts_nic",
  999. "tx_bytes_nic",
  1000. "rx_pkts_nic",
  1001. "rx_bytes_nic",
  1002. AMKSTR(d_tx_pkts),
  1003. AMKSTR(d_tx_bytes),
  1004. AMKSTR(d_tx_mpdus_queued),
  1005. AMKSTR(d_tx_mpdus_completed),
  1006. AMKSTR(d_tx_mpdu_xretries),
  1007. AMKSTR(d_tx_aggregates),
  1008. AMKSTR(d_tx_ampdus_queued_hw),
  1009. AMKSTR(d_tx_ampdus_queued_sw),
  1010. AMKSTR(d_tx_ampdus_completed),
  1011. AMKSTR(d_tx_ampdu_retries),
  1012. AMKSTR(d_tx_ampdu_xretries),
  1013. AMKSTR(d_tx_fifo_underrun),
  1014. AMKSTR(d_tx_op_exceeded),
  1015. AMKSTR(d_tx_timer_expiry),
  1016. AMKSTR(d_tx_desc_cfg_err),
  1017. AMKSTR(d_tx_data_underrun),
  1018. AMKSTR(d_tx_delim_underrun),
  1019. "d_rx_crc_err",
  1020. "d_rx_decrypt_crc_err",
  1021. "d_rx_phy_err",
  1022. "d_rx_mic_err",
  1023. "d_rx_pre_delim_crc_err",
  1024. "d_rx_post_delim_crc_err",
  1025. "d_rx_decrypt_busy_err",
  1026. "d_rx_phyerr_radar",
  1027. "d_rx_phyerr_ofdm_timing",
  1028. "d_rx_phyerr_cck_timing",
  1029. };
  1030. #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
  1031. void ath9k_get_et_strings(struct ieee80211_hw *hw,
  1032. struct ieee80211_vif *vif,
  1033. u32 sset, u8 *data)
  1034. {
  1035. if (sset == ETH_SS_STATS)
  1036. memcpy(data, *ath9k_gstrings_stats,
  1037. sizeof(ath9k_gstrings_stats));
  1038. }
  1039. int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
  1040. struct ieee80211_vif *vif, int sset)
  1041. {
  1042. if (sset == ETH_SS_STATS)
  1043. return ATH9K_SSTATS_LEN;
  1044. return 0;
  1045. }
  1046. #define AWDATA(elem) \
  1047. do { \
  1048. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
  1049. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
  1050. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
  1051. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
  1052. } while (0)
  1053. #define AWDATA_RX(elem) \
  1054. do { \
  1055. data[i++] = sc->debug.stats.rxstats.elem; \
  1056. } while (0)
  1057. void ath9k_get_et_stats(struct ieee80211_hw *hw,
  1058. struct ieee80211_vif *vif,
  1059. struct ethtool_stats *stats, u64 *data)
  1060. {
  1061. struct ath_softc *sc = hw->priv;
  1062. int i = 0;
  1063. data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
  1064. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
  1065. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
  1066. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
  1067. data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
  1068. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
  1069. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
  1070. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
  1071. AWDATA_RX(rx_pkts_all);
  1072. AWDATA_RX(rx_bytes_all);
  1073. AWDATA(tx_pkts_all);
  1074. AWDATA(tx_bytes_all);
  1075. AWDATA(queued);
  1076. AWDATA(completed);
  1077. AWDATA(xretries);
  1078. AWDATA(a_aggr);
  1079. AWDATA(a_queued_hw);
  1080. AWDATA(a_queued_sw);
  1081. AWDATA(a_completed);
  1082. AWDATA(a_retries);
  1083. AWDATA(a_xretries);
  1084. AWDATA(fifo_underrun);
  1085. AWDATA(xtxop);
  1086. AWDATA(timer_exp);
  1087. AWDATA(desc_cfg_err);
  1088. AWDATA(data_underrun);
  1089. AWDATA(delim_underrun);
  1090. AWDATA_RX(crc_err);
  1091. AWDATA_RX(decrypt_crc_err);
  1092. AWDATA_RX(phy_err);
  1093. AWDATA_RX(mic_err);
  1094. AWDATA_RX(pre_delim_crc_err);
  1095. AWDATA_RX(post_delim_crc_err);
  1096. AWDATA_RX(decrypt_busy_err);
  1097. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
  1098. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
  1099. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
  1100. WARN_ON(i != ATH9K_SSTATS_LEN);
  1101. }
  1102. void ath9k_deinit_debug(struct ath_softc *sc)
  1103. {
  1104. ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
  1105. }
  1106. int ath9k_init_debug(struct ath_hw *ah)
  1107. {
  1108. struct ath_common *common = ath9k_hw_common(ah);
  1109. struct ath_softc *sc = (struct ath_softc *) common->priv;
  1110. sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
  1111. sc->hw->wiphy->debugfsdir);
  1112. if (!sc->debug.debugfs_phy)
  1113. return -ENOMEM;
  1114. #ifdef CONFIG_ATH_DEBUG
  1115. debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1116. sc, &fops_debug);
  1117. #endif
  1118. ath9k_dfs_init_debug(sc);
  1119. ath9k_tx99_init_debug(sc);
  1120. ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
  1121. debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
  1122. read_file_dma);
  1123. debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
  1124. read_file_interrupt);
  1125. debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
  1126. read_file_xmit);
  1127. debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
  1128. read_file_queues);
  1129. debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1130. &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
  1131. debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1132. &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
  1133. debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1134. &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
  1135. debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1136. &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
  1137. debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
  1138. read_file_misc);
  1139. debugfs_create_devm_seqfile(sc->dev, "reset", sc->debug.debugfs_phy,
  1140. read_file_reset);
  1141. ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
  1142. ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
  1143. debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
  1144. &ah->rxchainmask);
  1145. debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
  1146. &ah->txchainmask);
  1147. debugfs_create_file("ani", S_IRUSR | S_IWUSR,
  1148. sc->debug.debugfs_phy, sc, &fops_ani);
  1149. debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1150. &sc->sc_ah->config.enable_paprd);
  1151. debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1152. sc, &fops_regidx);
  1153. debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1154. sc, &fops_regval);
  1155. debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
  1156. sc->debug.debugfs_phy,
  1157. &ah->config.cwm_ignore_extcca);
  1158. debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
  1159. &fops_regdump);
  1160. debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
  1161. sc->debug.debugfs_phy,
  1162. read_file_dump_nfcal);
  1163. ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
  1164. ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
  1165. debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
  1166. sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
  1167. debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
  1168. sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
  1169. debugfs_create_file("antenna_diversity", S_IRUSR,
  1170. sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
  1171. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1172. debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
  1173. sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
  1174. debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
  1175. &fops_btcoex);
  1176. #endif
  1177. #ifdef CONFIG_ATH9K_WOW
  1178. debugfs_create_file("wow", S_IRUSR | S_IWUSR,
  1179. sc->debug.debugfs_phy, sc, &fops_wow);
  1180. #endif
  1181. #ifdef CONFIG_ATH9K_DYNACK
  1182. debugfs_create_file("ack_to", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1183. sc, &fops_ackto);
  1184. #endif
  1185. debugfs_create_file("tpc", S_IRUSR | S_IWUSR,
  1186. sc->debug.debugfs_phy, sc, &fops_tpc);
  1187. return 0;
  1188. }