debug.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  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 ath_softc *sc = file->private;
  348. struct ath_hw *ah = sc->sc_ah;
  349. u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
  350. int i, qcuOffset = 0, dcuOffset = 0;
  351. u32 *qcuBase = &val[0], *dcuBase = &val[4];
  352. ath9k_ps_wakeup(sc);
  353. REG_WRITE_D(ah, AR_MACMISC,
  354. ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
  355. (AR_MACMISC_MISC_OBS_BUS_1 <<
  356. AR_MACMISC_MISC_OBS_BUS_MSB_S)));
  357. seq_puts(file, "Raw DMA Debug values:\n");
  358. for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
  359. if (i % 4 == 0)
  360. seq_puts(file, "\n");
  361. val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
  362. seq_printf(file, "%d: %08x ", i, val[i]);
  363. }
  364. seq_puts(file, "\n\n");
  365. seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
  366. for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
  367. if (i == 8) {
  368. qcuOffset = 0;
  369. qcuBase++;
  370. }
  371. if (i == 6) {
  372. dcuOffset = 0;
  373. dcuBase++;
  374. }
  375. seq_printf(file, "%2d %2x %1x %2x %2x\n",
  376. i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
  377. (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
  378. (val[2] & (0x7 << (i * 3))) >> (i * 3),
  379. (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
  380. }
  381. seq_puts(file, "\n");
  382. seq_printf(file, "qcu_stitch state: %2x qcu_fetch state: %2x\n",
  383. (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
  384. seq_printf(file, "qcu_complete state: %2x dcu_complete state: %2x\n",
  385. (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
  386. seq_printf(file, "dcu_arb state: %2x dcu_fp state: %2x\n",
  387. (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
  388. seq_printf(file, "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
  389. (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
  390. seq_printf(file, "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
  391. (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
  392. seq_printf(file, "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
  393. (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
  394. seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
  395. seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
  396. ath9k_ps_restore(sc);
  397. return 0;
  398. }
  399. static int open_file_dma(struct inode *inode, struct file *f)
  400. {
  401. return single_open(f, read_file_dma, inode->i_private);
  402. }
  403. static const struct file_operations fops_dma = {
  404. .open = open_file_dma,
  405. .read = seq_read,
  406. .owner = THIS_MODULE,
  407. .llseek = seq_lseek,
  408. .release = single_release,
  409. };
  410. void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
  411. {
  412. if (status)
  413. sc->debug.stats.istats.total++;
  414. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  415. if (status & ATH9K_INT_RXLP)
  416. sc->debug.stats.istats.rxlp++;
  417. if (status & ATH9K_INT_RXHP)
  418. sc->debug.stats.istats.rxhp++;
  419. if (status & ATH9K_INT_BB_WATCHDOG)
  420. sc->debug.stats.istats.bb_watchdog++;
  421. } else {
  422. if (status & ATH9K_INT_RX)
  423. sc->debug.stats.istats.rxok++;
  424. }
  425. if (status & ATH9K_INT_RXEOL)
  426. sc->debug.stats.istats.rxeol++;
  427. if (status & ATH9K_INT_RXORN)
  428. sc->debug.stats.istats.rxorn++;
  429. if (status & ATH9K_INT_TX)
  430. sc->debug.stats.istats.txok++;
  431. if (status & ATH9K_INT_TXURN)
  432. sc->debug.stats.istats.txurn++;
  433. if (status & ATH9K_INT_RXPHY)
  434. sc->debug.stats.istats.rxphyerr++;
  435. if (status & ATH9K_INT_RXKCM)
  436. sc->debug.stats.istats.rx_keycache_miss++;
  437. if (status & ATH9K_INT_SWBA)
  438. sc->debug.stats.istats.swba++;
  439. if (status & ATH9K_INT_BMISS)
  440. sc->debug.stats.istats.bmiss++;
  441. if (status & ATH9K_INT_BNR)
  442. sc->debug.stats.istats.bnr++;
  443. if (status & ATH9K_INT_CST)
  444. sc->debug.stats.istats.cst++;
  445. if (status & ATH9K_INT_GTT)
  446. sc->debug.stats.istats.gtt++;
  447. if (status & ATH9K_INT_TIM)
  448. sc->debug.stats.istats.tim++;
  449. if (status & ATH9K_INT_CABEND)
  450. sc->debug.stats.istats.cabend++;
  451. if (status & ATH9K_INT_DTIMSYNC)
  452. sc->debug.stats.istats.dtimsync++;
  453. if (status & ATH9K_INT_DTIM)
  454. sc->debug.stats.istats.dtim++;
  455. if (status & ATH9K_INT_TSFOOR)
  456. sc->debug.stats.istats.tsfoor++;
  457. if (status & ATH9K_INT_MCI)
  458. sc->debug.stats.istats.mci++;
  459. if (status & ATH9K_INT_GENTIMER)
  460. sc->debug.stats.istats.gen_timer++;
  461. }
  462. static int read_file_interrupt(struct seq_file *file, void *data)
  463. {
  464. struct ath_softc *sc = file->private;
  465. #define PR_IS(a, s) \
  466. do { \
  467. seq_printf(file, "%21s: %10u\n", a, \
  468. sc->debug.stats.istats.s); \
  469. } while (0)
  470. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  471. PR_IS("RXLP", rxlp);
  472. PR_IS("RXHP", rxhp);
  473. PR_IS("WATHDOG", bb_watchdog);
  474. } else {
  475. PR_IS("RX", rxok);
  476. }
  477. PR_IS("RXEOL", rxeol);
  478. PR_IS("RXORN", rxorn);
  479. PR_IS("TX", txok);
  480. PR_IS("TXURN", txurn);
  481. PR_IS("MIB", mib);
  482. PR_IS("RXPHY", rxphyerr);
  483. PR_IS("RXKCM", rx_keycache_miss);
  484. PR_IS("SWBA", swba);
  485. PR_IS("BMISS", bmiss);
  486. PR_IS("BNR", bnr);
  487. PR_IS("CST", cst);
  488. PR_IS("GTT", gtt);
  489. PR_IS("TIM", tim);
  490. PR_IS("CABEND", cabend);
  491. PR_IS("DTIMSYNC", dtimsync);
  492. PR_IS("DTIM", dtim);
  493. PR_IS("TSFOOR", tsfoor);
  494. PR_IS("MCI", mci);
  495. PR_IS("GENTIMER", gen_timer);
  496. PR_IS("TOTAL", total);
  497. seq_puts(file, "SYNC_CAUSE stats:\n");
  498. PR_IS("Sync-All", sync_cause_all);
  499. PR_IS("RTC-IRQ", sync_rtc_irq);
  500. PR_IS("MAC-IRQ", sync_mac_irq);
  501. PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
  502. PR_IS("APB-Timeout", apb_timeout);
  503. PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
  504. PR_IS("HOST1-Fatal", host1_fatal);
  505. PR_IS("HOST1-Perr", host1_perr);
  506. PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
  507. PR_IS("RADM-CPL-EP", radm_cpl_ep);
  508. PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
  509. PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
  510. PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
  511. PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
  512. PR_IS("Local-Bus-Timeout", local_timeout);
  513. PR_IS("PM-Access", pm_access);
  514. PR_IS("MAC-Awake", mac_awake);
  515. PR_IS("MAC-Asleep", mac_asleep);
  516. PR_IS("MAC-Sleep-Access", mac_sleep_access);
  517. return 0;
  518. }
  519. static int open_file_interrupt(struct inode *inode, struct file *f)
  520. {
  521. return single_open(f, read_file_interrupt, inode->i_private);
  522. }
  523. static const struct file_operations fops_interrupt = {
  524. .read = seq_read,
  525. .open = open_file_interrupt,
  526. .owner = THIS_MODULE,
  527. .llseek = seq_lseek,
  528. .release = single_release,
  529. };
  530. static int read_file_xmit(struct seq_file *file, void *data)
  531. {
  532. struct ath_softc *sc = file->private;
  533. seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
  534. PR("MPDUs Queued: ", queued);
  535. PR("MPDUs Completed: ", completed);
  536. PR("MPDUs XRetried: ", xretries);
  537. PR("Aggregates: ", a_aggr);
  538. PR("AMPDUs Queued HW:", a_queued_hw);
  539. PR("AMPDUs Queued SW:", a_queued_sw);
  540. PR("AMPDUs Completed:", a_completed);
  541. PR("AMPDUs Retried: ", a_retries);
  542. PR("AMPDUs XRetried: ", a_xretries);
  543. PR("TXERR Filtered: ", txerr_filtered);
  544. PR("FIFO Underrun: ", fifo_underrun);
  545. PR("TXOP Exceeded: ", xtxop);
  546. PR("TXTIMER Expiry: ", timer_exp);
  547. PR("DESC CFG Error: ", desc_cfg_err);
  548. PR("DATA Underrun: ", data_underrun);
  549. PR("DELIM Underrun: ", delim_underrun);
  550. PR("TX-Pkts-All: ", tx_pkts_all);
  551. PR("TX-Bytes-All: ", tx_bytes_all);
  552. PR("HW-put-tx-buf: ", puttxbuf);
  553. PR("HW-tx-start: ", txstart);
  554. PR("HW-tx-proc-desc: ", txprocdesc);
  555. PR("TX-Failed: ", txfailed);
  556. return 0;
  557. }
  558. static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
  559. struct seq_file *file)
  560. {
  561. ath_txq_lock(sc, txq);
  562. seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
  563. seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
  564. seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
  565. seq_printf(file, "%s: %3d ", "pending", txq->pending_frames);
  566. seq_printf(file, "%s: %d\n", "stopped", txq->stopped);
  567. ath_txq_unlock(sc, txq);
  568. }
  569. static int read_file_queues(struct seq_file *file, void *data)
  570. {
  571. struct ath_softc *sc = file->private;
  572. struct ath_txq *txq;
  573. int i;
  574. static const char *qname[4] = {
  575. "VO", "VI", "BE", "BK"
  576. };
  577. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  578. txq = sc->tx.txq_map[i];
  579. seq_printf(file, "(%s): ", qname[i]);
  580. print_queue(sc, txq, file);
  581. }
  582. seq_puts(file, "(CAB): ");
  583. print_queue(sc, sc->beacon.cabq, file);
  584. return 0;
  585. }
  586. static int read_file_misc(struct seq_file *file, void *data)
  587. {
  588. struct ath_softc *sc = file->private;
  589. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  590. struct ath9k_vif_iter_data iter_data;
  591. struct ath_chanctx *ctx;
  592. unsigned int reg;
  593. u32 rxfilter, i;
  594. seq_printf(file, "BSSID: %pM\n", common->curbssid);
  595. seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
  596. seq_printf(file, "OPMODE: %s\n",
  597. ath_opmode_to_string(sc->sc_ah->opmode));
  598. ath9k_ps_wakeup(sc);
  599. rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
  600. ath9k_ps_restore(sc);
  601. seq_printf(file, "RXFILTER: 0x%x", rxfilter);
  602. if (rxfilter & ATH9K_RX_FILTER_UCAST)
  603. seq_puts(file, " UCAST");
  604. if (rxfilter & ATH9K_RX_FILTER_MCAST)
  605. seq_puts(file, " MCAST");
  606. if (rxfilter & ATH9K_RX_FILTER_BCAST)
  607. seq_puts(file, " BCAST");
  608. if (rxfilter & ATH9K_RX_FILTER_CONTROL)
  609. seq_puts(file, " CONTROL");
  610. if (rxfilter & ATH9K_RX_FILTER_BEACON)
  611. seq_puts(file, " BEACON");
  612. if (rxfilter & ATH9K_RX_FILTER_PROM)
  613. seq_puts(file, " PROM");
  614. if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
  615. seq_puts(file, " PROBEREQ");
  616. if (rxfilter & ATH9K_RX_FILTER_PHYERR)
  617. seq_puts(file, " PHYERR");
  618. if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
  619. seq_puts(file, " MYBEACON");
  620. if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
  621. seq_puts(file, " COMP_BAR");
  622. if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
  623. seq_puts(file, " PSPOLL");
  624. if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
  625. seq_puts(file, " PHYRADAR");
  626. if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
  627. seq_puts(file, " MCAST_BCAST_ALL");
  628. if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
  629. seq_puts(file, " CONTROL_WRAPPER");
  630. seq_puts(file, "\n");
  631. reg = sc->sc_ah->imask;
  632. seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
  633. if (reg & ATH9K_INT_SWBA)
  634. seq_puts(file, " SWBA");
  635. if (reg & ATH9K_INT_BMISS)
  636. seq_puts(file, " BMISS");
  637. if (reg & ATH9K_INT_CST)
  638. seq_puts(file, " CST");
  639. if (reg & ATH9K_INT_RX)
  640. seq_puts(file, " RX");
  641. if (reg & ATH9K_INT_RXHP)
  642. seq_puts(file, " RXHP");
  643. if (reg & ATH9K_INT_RXLP)
  644. seq_puts(file, " RXLP");
  645. if (reg & ATH9K_INT_BB_WATCHDOG)
  646. seq_puts(file, " BB_WATCHDOG");
  647. seq_puts(file, "\n");
  648. i = 0;
  649. ath_for_each_chanctx(sc, ctx) {
  650. if (list_empty(&ctx->vifs))
  651. continue;
  652. ath9k_calculate_iter_data(sc, ctx, &iter_data);
  653. seq_printf(file,
  654. "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i WDS: %i",
  655. i++, (int)(ctx->assigned), iter_data.naps,
  656. iter_data.nstations,
  657. iter_data.nmeshes, iter_data.nwds);
  658. seq_printf(file, " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
  659. iter_data.nadhocs, sc->cur_chan->nvifs,
  660. sc->nbcnvifs);
  661. }
  662. return 0;
  663. }
  664. static int read_file_reset(struct seq_file *file, void *data)
  665. {
  666. struct ath_softc *sc = file->private;
  667. static const char * const reset_cause[__RESET_TYPE_MAX] = {
  668. [RESET_TYPE_BB_HANG] = "Baseband Hang",
  669. [RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
  670. [RESET_TYPE_FATAL_INT] = "Fatal HW Error",
  671. [RESET_TYPE_TX_ERROR] = "TX HW error",
  672. [RESET_TYPE_TX_GTT] = "Transmit timeout",
  673. [RESET_TYPE_TX_HANG] = "TX Path Hang",
  674. [RESET_TYPE_PLL_HANG] = "PLL RX Hang",
  675. [RESET_TYPE_MAC_HANG] = "MAC Hang",
  676. [RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
  677. [RESET_TYPE_MCI] = "MCI Reset",
  678. [RESET_TYPE_CALIBRATION] = "Calibration error",
  679. };
  680. int i;
  681. for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
  682. if (!reset_cause[i])
  683. continue;
  684. seq_printf(file, "%17s: %2d\n", reset_cause[i],
  685. sc->debug.stats.reset[i]);
  686. }
  687. return 0;
  688. }
  689. void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
  690. struct ath_tx_status *ts, struct ath_txq *txq,
  691. unsigned int flags)
  692. {
  693. int qnum = txq->axq_qnum;
  694. TX_STAT_INC(qnum, tx_pkts_all);
  695. sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
  696. if (bf_isampdu(bf)) {
  697. if (flags & ATH_TX_ERROR)
  698. TX_STAT_INC(qnum, a_xretries);
  699. else
  700. TX_STAT_INC(qnum, a_completed);
  701. } else {
  702. if (ts->ts_status & ATH9K_TXERR_XRETRY)
  703. TX_STAT_INC(qnum, xretries);
  704. else
  705. TX_STAT_INC(qnum, completed);
  706. }
  707. if (ts->ts_status & ATH9K_TXERR_FILT)
  708. TX_STAT_INC(qnum, txerr_filtered);
  709. if (ts->ts_status & ATH9K_TXERR_FIFO)
  710. TX_STAT_INC(qnum, fifo_underrun);
  711. if (ts->ts_status & ATH9K_TXERR_XTXOP)
  712. TX_STAT_INC(qnum, xtxop);
  713. if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
  714. TX_STAT_INC(qnum, timer_exp);
  715. if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
  716. TX_STAT_INC(qnum, desc_cfg_err);
  717. if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
  718. TX_STAT_INC(qnum, data_underrun);
  719. if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
  720. TX_STAT_INC(qnum, delim_underrun);
  721. }
  722. static int open_file_xmit(struct inode *inode, struct file *f)
  723. {
  724. return single_open(f, read_file_xmit, inode->i_private);
  725. }
  726. static const struct file_operations fops_xmit = {
  727. .read = seq_read,
  728. .open = open_file_xmit,
  729. .owner = THIS_MODULE,
  730. .llseek = seq_lseek,
  731. .release = single_release,
  732. };
  733. static int open_file_queues(struct inode *inode, struct file *f)
  734. {
  735. return single_open(f, read_file_queues, inode->i_private);
  736. }
  737. static const struct file_operations fops_queues = {
  738. .read = seq_read,
  739. .open = open_file_queues,
  740. .owner = THIS_MODULE,
  741. .llseek = seq_lseek,
  742. .release = single_release,
  743. };
  744. static int open_file_misc(struct inode *inode, struct file *f)
  745. {
  746. return single_open(f, read_file_misc, inode->i_private);
  747. }
  748. static const struct file_operations fops_misc = {
  749. .read = seq_read,
  750. .open = open_file_misc,
  751. .owner = THIS_MODULE,
  752. .llseek = seq_lseek,
  753. .release = single_release,
  754. };
  755. static int open_file_reset(struct inode *inode, struct file *f)
  756. {
  757. return single_open(f, read_file_reset, inode->i_private);
  758. }
  759. static const struct file_operations fops_reset = {
  760. .read = seq_read,
  761. .open = open_file_reset,
  762. .owner = THIS_MODULE,
  763. .llseek = seq_lseek,
  764. .release = single_release,
  765. };
  766. void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
  767. {
  768. ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
  769. }
  770. static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
  771. size_t count, loff_t *ppos)
  772. {
  773. struct ath_softc *sc = file->private_data;
  774. char buf[32];
  775. unsigned int len;
  776. len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
  777. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  778. }
  779. static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
  780. size_t count, loff_t *ppos)
  781. {
  782. struct ath_softc *sc = file->private_data;
  783. unsigned long regidx;
  784. char buf[32];
  785. ssize_t len;
  786. len = min(count, sizeof(buf) - 1);
  787. if (copy_from_user(buf, user_buf, len))
  788. return -EFAULT;
  789. buf[len] = '\0';
  790. if (kstrtoul(buf, 0, &regidx))
  791. return -EINVAL;
  792. sc->debug.regidx = regidx;
  793. return count;
  794. }
  795. static const struct file_operations fops_regidx = {
  796. .read = read_file_regidx,
  797. .write = write_file_regidx,
  798. .open = simple_open,
  799. .owner = THIS_MODULE,
  800. .llseek = default_llseek,
  801. };
  802. static ssize_t read_file_regval(struct file *file, char __user *user_buf,
  803. size_t count, loff_t *ppos)
  804. {
  805. struct ath_softc *sc = file->private_data;
  806. struct ath_hw *ah = sc->sc_ah;
  807. char buf[32];
  808. unsigned int len;
  809. u32 regval;
  810. ath9k_ps_wakeup(sc);
  811. regval = REG_READ_D(ah, sc->debug.regidx);
  812. ath9k_ps_restore(sc);
  813. len = sprintf(buf, "0x%08x\n", regval);
  814. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  815. }
  816. static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
  817. size_t count, loff_t *ppos)
  818. {
  819. struct ath_softc *sc = file->private_data;
  820. struct ath_hw *ah = sc->sc_ah;
  821. unsigned long regval;
  822. char buf[32];
  823. ssize_t len;
  824. len = min(count, sizeof(buf) - 1);
  825. if (copy_from_user(buf, user_buf, len))
  826. return -EFAULT;
  827. buf[len] = '\0';
  828. if (kstrtoul(buf, 0, &regval))
  829. return -EINVAL;
  830. ath9k_ps_wakeup(sc);
  831. REG_WRITE_D(ah, sc->debug.regidx, regval);
  832. ath9k_ps_restore(sc);
  833. return count;
  834. }
  835. static const struct file_operations fops_regval = {
  836. .read = read_file_regval,
  837. .write = write_file_regval,
  838. .open = simple_open,
  839. .owner = THIS_MODULE,
  840. .llseek = default_llseek,
  841. };
  842. #define REGDUMP_LINE_SIZE 20
  843. static int open_file_regdump(struct inode *inode, struct file *file)
  844. {
  845. struct ath_softc *sc = inode->i_private;
  846. unsigned int len = 0;
  847. u8 *buf;
  848. int i;
  849. unsigned long num_regs, regdump_len, max_reg_offset;
  850. max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
  851. num_regs = max_reg_offset / 4 + 1;
  852. regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
  853. buf = vmalloc(regdump_len);
  854. if (!buf)
  855. return -ENOMEM;
  856. ath9k_ps_wakeup(sc);
  857. for (i = 0; i < num_regs; i++)
  858. len += scnprintf(buf + len, regdump_len - len,
  859. "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
  860. ath9k_ps_restore(sc);
  861. file->private_data = buf;
  862. return 0;
  863. }
  864. static const struct file_operations fops_regdump = {
  865. .open = open_file_regdump,
  866. .read = ath9k_debugfs_read_buf,
  867. .release = ath9k_debugfs_release_buf,
  868. .owner = THIS_MODULE,
  869. .llseek = default_llseek,/* read accesses f_pos */
  870. };
  871. static int read_file_dump_nfcal(struct seq_file *file, void *data)
  872. {
  873. struct ath_softc *sc = file->private;
  874. struct ath_hw *ah = sc->sc_ah;
  875. struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
  876. struct ath_common *common = ath9k_hw_common(ah);
  877. struct ieee80211_conf *conf = &common->hw->conf;
  878. u32 i, j;
  879. u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
  880. u8 nread;
  881. seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
  882. seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
  883. for (i = 0; i < NUM_NF_READINGS; i++) {
  884. if (!(chainmask & (1 << i)) ||
  885. ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
  886. continue;
  887. nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
  888. seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
  889. for (j = 0; j < nread; j++)
  890. seq_printf(file, " %d", h[i].nfCalBuffer[j]);
  891. seq_puts(file, "\n");
  892. }
  893. return 0;
  894. }
  895. static int open_file_dump_nfcal(struct inode *inode, struct file *f)
  896. {
  897. return single_open(f, read_file_dump_nfcal, inode->i_private);
  898. }
  899. static const struct file_operations fops_dump_nfcal = {
  900. .read = seq_read,
  901. .open = open_file_dump_nfcal,
  902. .owner = THIS_MODULE,
  903. .llseek = seq_lseek,
  904. .release = single_release,
  905. };
  906. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  907. static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
  908. size_t count, loff_t *ppos)
  909. {
  910. struct ath_softc *sc = file->private_data;
  911. u32 len = 0, size = 1500;
  912. char *buf;
  913. size_t retval;
  914. buf = kzalloc(size, GFP_KERNEL);
  915. if (buf == NULL)
  916. return -ENOMEM;
  917. if (!sc->sc_ah->common.btcoex_enabled) {
  918. len = scnprintf(buf, size, "%s\n",
  919. "BTCOEX is disabled");
  920. goto exit;
  921. }
  922. len = ath9k_dump_btcoex(sc, buf, size);
  923. exit:
  924. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  925. kfree(buf);
  926. return retval;
  927. }
  928. static const struct file_operations fops_btcoex = {
  929. .read = read_file_btcoex,
  930. .open = simple_open,
  931. .owner = THIS_MODULE,
  932. .llseek = default_llseek,
  933. };
  934. #endif
  935. #ifdef CONFIG_ATH9K_DYNACK
  936. static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
  937. size_t count, loff_t *ppos)
  938. {
  939. struct ath_softc *sc = file->private_data;
  940. struct ath_hw *ah = sc->sc_ah;
  941. char buf[32];
  942. unsigned int len;
  943. len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
  944. (ah->dynack.enabled) ? 'A' : 'S');
  945. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  946. }
  947. static const struct file_operations fops_ackto = {
  948. .read = read_file_ackto,
  949. .open = simple_open,
  950. .owner = THIS_MODULE,
  951. .llseek = default_llseek,
  952. };
  953. #endif
  954. static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
  955. size_t count, loff_t *ppos)
  956. {
  957. struct ath_softc *sc = file->private_data;
  958. struct ath_hw *ah = sc->sc_ah;
  959. unsigned int len = 0, size = 32;
  960. ssize_t retval;
  961. char *buf;
  962. buf = kzalloc(size, GFP_KERNEL);
  963. if (!buf)
  964. return -ENOMEM;
  965. len += scnprintf(buf + len, size - len, "%s\n",
  966. ah->tpc_enabled ? "ENABLED" : "DISABLED");
  967. if (len > size)
  968. len = size;
  969. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  970. kfree(buf);
  971. return retval;
  972. }
  973. static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
  974. size_t count, loff_t *ppos)
  975. {
  976. struct ath_softc *sc = file->private_data;
  977. struct ath_hw *ah = sc->sc_ah;
  978. unsigned long val;
  979. char buf[32];
  980. ssize_t len;
  981. bool tpc_enabled;
  982. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  983. /* ar9002 does not support TPC for the moment */
  984. return -EOPNOTSUPP;
  985. }
  986. len = min(count, sizeof(buf) - 1);
  987. if (copy_from_user(buf, user_buf, len))
  988. return -EFAULT;
  989. buf[len] = '\0';
  990. if (kstrtoul(buf, 0, &val))
  991. return -EINVAL;
  992. if (val < 0 || val > 1)
  993. return -EINVAL;
  994. tpc_enabled = !!val;
  995. if (tpc_enabled != ah->tpc_enabled) {
  996. ah->tpc_enabled = tpc_enabled;
  997. ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false);
  998. }
  999. return count;
  1000. }
  1001. static const struct file_operations fops_tpc = {
  1002. .read = read_file_tpc,
  1003. .write = write_file_tpc,
  1004. .open = simple_open,
  1005. .owner = THIS_MODULE,
  1006. .llseek = default_llseek,
  1007. };
  1008. /* Ethtool support for get-stats */
  1009. #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
  1010. static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
  1011. "tx_pkts_nic",
  1012. "tx_bytes_nic",
  1013. "rx_pkts_nic",
  1014. "rx_bytes_nic",
  1015. AMKSTR(d_tx_pkts),
  1016. AMKSTR(d_tx_bytes),
  1017. AMKSTR(d_tx_mpdus_queued),
  1018. AMKSTR(d_tx_mpdus_completed),
  1019. AMKSTR(d_tx_mpdu_xretries),
  1020. AMKSTR(d_tx_aggregates),
  1021. AMKSTR(d_tx_ampdus_queued_hw),
  1022. AMKSTR(d_tx_ampdus_queued_sw),
  1023. AMKSTR(d_tx_ampdus_completed),
  1024. AMKSTR(d_tx_ampdu_retries),
  1025. AMKSTR(d_tx_ampdu_xretries),
  1026. AMKSTR(d_tx_fifo_underrun),
  1027. AMKSTR(d_tx_op_exceeded),
  1028. AMKSTR(d_tx_timer_expiry),
  1029. AMKSTR(d_tx_desc_cfg_err),
  1030. AMKSTR(d_tx_data_underrun),
  1031. AMKSTR(d_tx_delim_underrun),
  1032. "d_rx_crc_err",
  1033. "d_rx_decrypt_crc_err",
  1034. "d_rx_phy_err",
  1035. "d_rx_mic_err",
  1036. "d_rx_pre_delim_crc_err",
  1037. "d_rx_post_delim_crc_err",
  1038. "d_rx_decrypt_busy_err",
  1039. "d_rx_phyerr_radar",
  1040. "d_rx_phyerr_ofdm_timing",
  1041. "d_rx_phyerr_cck_timing",
  1042. };
  1043. #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
  1044. void ath9k_get_et_strings(struct ieee80211_hw *hw,
  1045. struct ieee80211_vif *vif,
  1046. u32 sset, u8 *data)
  1047. {
  1048. if (sset == ETH_SS_STATS)
  1049. memcpy(data, *ath9k_gstrings_stats,
  1050. sizeof(ath9k_gstrings_stats));
  1051. }
  1052. int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
  1053. struct ieee80211_vif *vif, int sset)
  1054. {
  1055. if (sset == ETH_SS_STATS)
  1056. return ATH9K_SSTATS_LEN;
  1057. return 0;
  1058. }
  1059. #define AWDATA(elem) \
  1060. do { \
  1061. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
  1062. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
  1063. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
  1064. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
  1065. } while (0)
  1066. #define AWDATA_RX(elem) \
  1067. do { \
  1068. data[i++] = sc->debug.stats.rxstats.elem; \
  1069. } while (0)
  1070. void ath9k_get_et_stats(struct ieee80211_hw *hw,
  1071. struct ieee80211_vif *vif,
  1072. struct ethtool_stats *stats, u64 *data)
  1073. {
  1074. struct ath_softc *sc = hw->priv;
  1075. int i = 0;
  1076. data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
  1077. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
  1078. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
  1079. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
  1080. data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
  1081. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
  1082. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
  1083. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
  1084. AWDATA_RX(rx_pkts_all);
  1085. AWDATA_RX(rx_bytes_all);
  1086. AWDATA(tx_pkts_all);
  1087. AWDATA(tx_bytes_all);
  1088. AWDATA(queued);
  1089. AWDATA(completed);
  1090. AWDATA(xretries);
  1091. AWDATA(a_aggr);
  1092. AWDATA(a_queued_hw);
  1093. AWDATA(a_queued_sw);
  1094. AWDATA(a_completed);
  1095. AWDATA(a_retries);
  1096. AWDATA(a_xretries);
  1097. AWDATA(fifo_underrun);
  1098. AWDATA(xtxop);
  1099. AWDATA(timer_exp);
  1100. AWDATA(desc_cfg_err);
  1101. AWDATA(data_underrun);
  1102. AWDATA(delim_underrun);
  1103. AWDATA_RX(crc_err);
  1104. AWDATA_RX(decrypt_crc_err);
  1105. AWDATA_RX(phy_err);
  1106. AWDATA_RX(mic_err);
  1107. AWDATA_RX(pre_delim_crc_err);
  1108. AWDATA_RX(post_delim_crc_err);
  1109. AWDATA_RX(decrypt_busy_err);
  1110. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
  1111. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
  1112. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
  1113. WARN_ON(i != ATH9K_SSTATS_LEN);
  1114. }
  1115. void ath9k_deinit_debug(struct ath_softc *sc)
  1116. {
  1117. ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
  1118. }
  1119. int ath9k_init_debug(struct ath_hw *ah)
  1120. {
  1121. struct ath_common *common = ath9k_hw_common(ah);
  1122. struct ath_softc *sc = (struct ath_softc *) common->priv;
  1123. sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
  1124. sc->hw->wiphy->debugfsdir);
  1125. if (!sc->debug.debugfs_phy)
  1126. return -ENOMEM;
  1127. #ifdef CONFIG_ATH_DEBUG
  1128. debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1129. sc, &fops_debug);
  1130. #endif
  1131. ath9k_dfs_init_debug(sc);
  1132. ath9k_tx99_init_debug(sc);
  1133. ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
  1134. debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
  1135. &fops_dma);
  1136. debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
  1137. &fops_interrupt);
  1138. debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
  1139. &fops_xmit);
  1140. debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
  1141. &fops_queues);
  1142. debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1143. &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
  1144. debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1145. &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
  1146. debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1147. &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
  1148. debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1149. &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
  1150. debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
  1151. &fops_misc);
  1152. debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
  1153. &fops_reset);
  1154. ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
  1155. ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
  1156. debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
  1157. &ah->rxchainmask);
  1158. debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
  1159. &ah->txchainmask);
  1160. debugfs_create_file("ani", S_IRUSR | S_IWUSR,
  1161. sc->debug.debugfs_phy, sc, &fops_ani);
  1162. debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1163. &sc->sc_ah->config.enable_paprd);
  1164. debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1165. sc, &fops_regidx);
  1166. debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1167. sc, &fops_regval);
  1168. debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
  1169. sc->debug.debugfs_phy,
  1170. &ah->config.cwm_ignore_extcca);
  1171. debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
  1172. &fops_regdump);
  1173. debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
  1174. &fops_dump_nfcal);
  1175. ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
  1176. ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
  1177. debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
  1178. sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
  1179. debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
  1180. sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
  1181. debugfs_create_file("antenna_diversity", S_IRUSR,
  1182. sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
  1183. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1184. debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
  1185. sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
  1186. debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
  1187. &fops_btcoex);
  1188. #endif
  1189. #ifdef CONFIG_ATH9K_DYNACK
  1190. debugfs_create_file("ack_to", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1191. sc, &fops_ackto);
  1192. #endif
  1193. debugfs_create_file("tpc", S_IRUSR | S_IWUSR,
  1194. sc->debug.debugfs_phy, sc, &fops_tpc);
  1195. return 0;
  1196. }