debug.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  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 OCB: %i TOTAL: %hi BEACON-VIF: %hi\n",
  642. iter_data.nadhocs, iter_data.nocbs, 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. [RESET_TX_DMA_ERROR] = "Tx DMA stop error",
  664. [RESET_RX_DMA_ERROR] = "Rx DMA stop error",
  665. };
  666. int i;
  667. for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
  668. if (!reset_cause[i])
  669. continue;
  670. seq_printf(file, "%17s: %2d\n", reset_cause[i],
  671. sc->debug.stats.reset[i]);
  672. }
  673. return 0;
  674. }
  675. void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
  676. struct ath_tx_status *ts, struct ath_txq *txq,
  677. unsigned int flags)
  678. {
  679. int qnum = txq->axq_qnum;
  680. TX_STAT_INC(qnum, tx_pkts_all);
  681. sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
  682. if (bf_isampdu(bf)) {
  683. if (flags & ATH_TX_ERROR)
  684. TX_STAT_INC(qnum, a_xretries);
  685. else
  686. TX_STAT_INC(qnum, a_completed);
  687. } else {
  688. if (ts->ts_status & ATH9K_TXERR_XRETRY)
  689. TX_STAT_INC(qnum, xretries);
  690. else
  691. TX_STAT_INC(qnum, completed);
  692. }
  693. if (ts->ts_status & ATH9K_TXERR_FILT)
  694. TX_STAT_INC(qnum, txerr_filtered);
  695. if (ts->ts_status & ATH9K_TXERR_FIFO)
  696. TX_STAT_INC(qnum, fifo_underrun);
  697. if (ts->ts_status & ATH9K_TXERR_XTXOP)
  698. TX_STAT_INC(qnum, xtxop);
  699. if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
  700. TX_STAT_INC(qnum, timer_exp);
  701. if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
  702. TX_STAT_INC(qnum, desc_cfg_err);
  703. if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
  704. TX_STAT_INC(qnum, data_underrun);
  705. if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
  706. TX_STAT_INC(qnum, delim_underrun);
  707. }
  708. void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
  709. {
  710. ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
  711. }
  712. static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
  713. size_t count, loff_t *ppos)
  714. {
  715. struct ath_softc *sc = file->private_data;
  716. char buf[32];
  717. unsigned int len;
  718. len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
  719. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  720. }
  721. static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
  722. size_t count, loff_t *ppos)
  723. {
  724. struct ath_softc *sc = file->private_data;
  725. unsigned long regidx;
  726. char buf[32];
  727. ssize_t len;
  728. len = min(count, sizeof(buf) - 1);
  729. if (copy_from_user(buf, user_buf, len))
  730. return -EFAULT;
  731. buf[len] = '\0';
  732. if (kstrtoul(buf, 0, &regidx))
  733. return -EINVAL;
  734. sc->debug.regidx = regidx;
  735. return count;
  736. }
  737. static const struct file_operations fops_regidx = {
  738. .read = read_file_regidx,
  739. .write = write_file_regidx,
  740. .open = simple_open,
  741. .owner = THIS_MODULE,
  742. .llseek = default_llseek,
  743. };
  744. static ssize_t read_file_regval(struct file *file, char __user *user_buf,
  745. size_t count, loff_t *ppos)
  746. {
  747. struct ath_softc *sc = file->private_data;
  748. struct ath_hw *ah = sc->sc_ah;
  749. char buf[32];
  750. unsigned int len;
  751. u32 regval;
  752. ath9k_ps_wakeup(sc);
  753. regval = REG_READ_D(ah, sc->debug.regidx);
  754. ath9k_ps_restore(sc);
  755. len = sprintf(buf, "0x%08x\n", regval);
  756. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  757. }
  758. static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
  759. size_t count, loff_t *ppos)
  760. {
  761. struct ath_softc *sc = file->private_data;
  762. struct ath_hw *ah = sc->sc_ah;
  763. unsigned long regval;
  764. char buf[32];
  765. ssize_t len;
  766. len = min(count, sizeof(buf) - 1);
  767. if (copy_from_user(buf, user_buf, len))
  768. return -EFAULT;
  769. buf[len] = '\0';
  770. if (kstrtoul(buf, 0, &regval))
  771. return -EINVAL;
  772. ath9k_ps_wakeup(sc);
  773. REG_WRITE_D(ah, sc->debug.regidx, regval);
  774. ath9k_ps_restore(sc);
  775. return count;
  776. }
  777. static const struct file_operations fops_regval = {
  778. .read = read_file_regval,
  779. .write = write_file_regval,
  780. .open = simple_open,
  781. .owner = THIS_MODULE,
  782. .llseek = default_llseek,
  783. };
  784. #define REGDUMP_LINE_SIZE 20
  785. static int open_file_regdump(struct inode *inode, struct file *file)
  786. {
  787. struct ath_softc *sc = inode->i_private;
  788. unsigned int len = 0;
  789. u8 *buf;
  790. int i;
  791. unsigned long num_regs, regdump_len, max_reg_offset;
  792. max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
  793. num_regs = max_reg_offset / 4 + 1;
  794. regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
  795. buf = vmalloc(regdump_len);
  796. if (!buf)
  797. return -ENOMEM;
  798. ath9k_ps_wakeup(sc);
  799. for (i = 0; i < num_regs; i++)
  800. len += scnprintf(buf + len, regdump_len - len,
  801. "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
  802. ath9k_ps_restore(sc);
  803. file->private_data = buf;
  804. return 0;
  805. }
  806. static const struct file_operations fops_regdump = {
  807. .open = open_file_regdump,
  808. .read = ath9k_debugfs_read_buf,
  809. .release = ath9k_debugfs_release_buf,
  810. .owner = THIS_MODULE,
  811. .llseek = default_llseek,/* read accesses f_pos */
  812. };
  813. static int read_file_dump_nfcal(struct seq_file *file, void *data)
  814. {
  815. struct ieee80211_hw *hw = dev_get_drvdata(file->private);
  816. struct ath_softc *sc = hw->priv;
  817. struct ath_hw *ah = sc->sc_ah;
  818. struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
  819. struct ath_common *common = ath9k_hw_common(ah);
  820. struct ieee80211_conf *conf = &common->hw->conf;
  821. u32 i, j;
  822. u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
  823. u8 nread;
  824. seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
  825. seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
  826. for (i = 0; i < NUM_NF_READINGS; i++) {
  827. if (!(chainmask & (1 << i)) ||
  828. ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
  829. continue;
  830. nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
  831. seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
  832. for (j = 0; j < nread; j++)
  833. seq_printf(file, " %d", h[i].nfCalBuffer[j]);
  834. seq_puts(file, "\n");
  835. }
  836. return 0;
  837. }
  838. static int open_file_dump_nfcal(struct inode *inode, struct file *f)
  839. {
  840. return single_open(f, read_file_dump_nfcal, inode->i_private);
  841. }
  842. static const struct file_operations fops_dump_nfcal = {
  843. .read = seq_read,
  844. .open = open_file_dump_nfcal,
  845. .owner = THIS_MODULE,
  846. .llseek = seq_lseek,
  847. .release = single_release,
  848. };
  849. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  850. static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
  851. size_t count, loff_t *ppos)
  852. {
  853. struct ath_softc *sc = file->private_data;
  854. u32 len = 0, size = 1500;
  855. char *buf;
  856. size_t retval;
  857. buf = kzalloc(size, GFP_KERNEL);
  858. if (buf == NULL)
  859. return -ENOMEM;
  860. if (!sc->sc_ah->common.btcoex_enabled) {
  861. len = scnprintf(buf, size, "%s\n",
  862. "BTCOEX is disabled");
  863. goto exit;
  864. }
  865. len = ath9k_dump_btcoex(sc, buf, size);
  866. exit:
  867. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  868. kfree(buf);
  869. return retval;
  870. }
  871. static const struct file_operations fops_btcoex = {
  872. .read = read_file_btcoex,
  873. .open = simple_open,
  874. .owner = THIS_MODULE,
  875. .llseek = default_llseek,
  876. };
  877. #endif
  878. #ifdef CONFIG_ATH9K_DYNACK
  879. static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
  880. size_t count, loff_t *ppos)
  881. {
  882. struct ath_softc *sc = file->private_data;
  883. struct ath_hw *ah = sc->sc_ah;
  884. char buf[32];
  885. unsigned int len;
  886. len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
  887. (ah->dynack.enabled) ? 'A' : 'S');
  888. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  889. }
  890. static const struct file_operations fops_ackto = {
  891. .read = read_file_ackto,
  892. .open = simple_open,
  893. .owner = THIS_MODULE,
  894. .llseek = default_llseek,
  895. };
  896. #endif
  897. #ifdef CONFIG_ATH9K_WOW
  898. static ssize_t read_file_wow(struct file *file, char __user *user_buf,
  899. size_t count, loff_t *ppos)
  900. {
  901. struct ath_softc *sc = file->private_data;
  902. unsigned int len = 0, size = 32;
  903. ssize_t retval;
  904. char *buf;
  905. buf = kzalloc(size, GFP_KERNEL);
  906. if (!buf)
  907. return -ENOMEM;
  908. len += scnprintf(buf + len, size - len, "WOW: %s\n",
  909. sc->force_wow ? "ENABLED" : "DISABLED");
  910. if (len > size)
  911. len = size;
  912. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  913. kfree(buf);
  914. return retval;
  915. }
  916. static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
  917. size_t count, loff_t *ppos)
  918. {
  919. struct ath_softc *sc = file->private_data;
  920. unsigned long val;
  921. char buf[32];
  922. ssize_t len;
  923. len = min(count, sizeof(buf) - 1);
  924. if (copy_from_user(buf, user_buf, len))
  925. return -EFAULT;
  926. buf[len] = '\0';
  927. if (kstrtoul(buf, 0, &val))
  928. return -EINVAL;
  929. if (val != 1)
  930. return -EINVAL;
  931. if (!sc->force_wow) {
  932. sc->force_wow = true;
  933. ath9k_init_wow(sc->hw);
  934. }
  935. return count;
  936. }
  937. static const struct file_operations fops_wow = {
  938. .read = read_file_wow,
  939. .write = write_file_wow,
  940. .open = simple_open,
  941. .owner = THIS_MODULE,
  942. .llseek = default_llseek,
  943. };
  944. #endif
  945. static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
  946. size_t count, loff_t *ppos)
  947. {
  948. struct ath_softc *sc = file->private_data;
  949. struct ath_hw *ah = sc->sc_ah;
  950. unsigned int len = 0, size = 32;
  951. ssize_t retval;
  952. char *buf;
  953. buf = kzalloc(size, GFP_KERNEL);
  954. if (!buf)
  955. return -ENOMEM;
  956. len += scnprintf(buf + len, size - len, "%s\n",
  957. ah->tpc_enabled ? "ENABLED" : "DISABLED");
  958. if (len > size)
  959. len = size;
  960. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  961. kfree(buf);
  962. return retval;
  963. }
  964. static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
  965. size_t count, loff_t *ppos)
  966. {
  967. struct ath_softc *sc = file->private_data;
  968. struct ath_hw *ah = sc->sc_ah;
  969. unsigned long val;
  970. char buf[32];
  971. ssize_t len;
  972. bool tpc_enabled;
  973. len = min(count, sizeof(buf) - 1);
  974. if (copy_from_user(buf, user_buf, len))
  975. return -EFAULT;
  976. buf[len] = '\0';
  977. if (kstrtoul(buf, 0, &val))
  978. return -EINVAL;
  979. if (val < 0 || val > 1)
  980. return -EINVAL;
  981. tpc_enabled = !!val;
  982. if (tpc_enabled != ah->tpc_enabled) {
  983. ah->tpc_enabled = tpc_enabled;
  984. mutex_lock(&sc->mutex);
  985. ath9k_set_txpower(sc, NULL);
  986. mutex_unlock(&sc->mutex);
  987. }
  988. return count;
  989. }
  990. static const struct file_operations fops_tpc = {
  991. .read = read_file_tpc,
  992. .write = write_file_tpc,
  993. .open = simple_open,
  994. .owner = THIS_MODULE,
  995. .llseek = default_llseek,
  996. };
  997. /* Ethtool support for get-stats */
  998. #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
  999. static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
  1000. "tx_pkts_nic",
  1001. "tx_bytes_nic",
  1002. "rx_pkts_nic",
  1003. "rx_bytes_nic",
  1004. AMKSTR(d_tx_pkts),
  1005. AMKSTR(d_tx_bytes),
  1006. AMKSTR(d_tx_mpdus_queued),
  1007. AMKSTR(d_tx_mpdus_completed),
  1008. AMKSTR(d_tx_mpdu_xretries),
  1009. AMKSTR(d_tx_aggregates),
  1010. AMKSTR(d_tx_ampdus_queued_hw),
  1011. AMKSTR(d_tx_ampdus_queued_sw),
  1012. AMKSTR(d_tx_ampdus_completed),
  1013. AMKSTR(d_tx_ampdu_retries),
  1014. AMKSTR(d_tx_ampdu_xretries),
  1015. AMKSTR(d_tx_fifo_underrun),
  1016. AMKSTR(d_tx_op_exceeded),
  1017. AMKSTR(d_tx_timer_expiry),
  1018. AMKSTR(d_tx_desc_cfg_err),
  1019. AMKSTR(d_tx_data_underrun),
  1020. AMKSTR(d_tx_delim_underrun),
  1021. "d_rx_crc_err",
  1022. "d_rx_decrypt_crc_err",
  1023. "d_rx_phy_err",
  1024. "d_rx_mic_err",
  1025. "d_rx_pre_delim_crc_err",
  1026. "d_rx_post_delim_crc_err",
  1027. "d_rx_decrypt_busy_err",
  1028. "d_rx_phyerr_radar",
  1029. "d_rx_phyerr_ofdm_timing",
  1030. "d_rx_phyerr_cck_timing",
  1031. };
  1032. #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
  1033. void ath9k_get_et_strings(struct ieee80211_hw *hw,
  1034. struct ieee80211_vif *vif,
  1035. u32 sset, u8 *data)
  1036. {
  1037. if (sset == ETH_SS_STATS)
  1038. memcpy(data, *ath9k_gstrings_stats,
  1039. sizeof(ath9k_gstrings_stats));
  1040. }
  1041. int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
  1042. struct ieee80211_vif *vif, int sset)
  1043. {
  1044. if (sset == ETH_SS_STATS)
  1045. return ATH9K_SSTATS_LEN;
  1046. return 0;
  1047. }
  1048. #define AWDATA(elem) \
  1049. do { \
  1050. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
  1051. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
  1052. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
  1053. data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
  1054. } while (0)
  1055. #define AWDATA_RX(elem) \
  1056. do { \
  1057. data[i++] = sc->debug.stats.rxstats.elem; \
  1058. } while (0)
  1059. void ath9k_get_et_stats(struct ieee80211_hw *hw,
  1060. struct ieee80211_vif *vif,
  1061. struct ethtool_stats *stats, u64 *data)
  1062. {
  1063. struct ath_softc *sc = hw->priv;
  1064. int i = 0;
  1065. data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
  1066. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
  1067. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
  1068. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
  1069. data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
  1070. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
  1071. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
  1072. sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
  1073. AWDATA_RX(rx_pkts_all);
  1074. AWDATA_RX(rx_bytes_all);
  1075. AWDATA(tx_pkts_all);
  1076. AWDATA(tx_bytes_all);
  1077. AWDATA(queued);
  1078. AWDATA(completed);
  1079. AWDATA(xretries);
  1080. AWDATA(a_aggr);
  1081. AWDATA(a_queued_hw);
  1082. AWDATA(a_queued_sw);
  1083. AWDATA(a_completed);
  1084. AWDATA(a_retries);
  1085. AWDATA(a_xretries);
  1086. AWDATA(fifo_underrun);
  1087. AWDATA(xtxop);
  1088. AWDATA(timer_exp);
  1089. AWDATA(desc_cfg_err);
  1090. AWDATA(data_underrun);
  1091. AWDATA(delim_underrun);
  1092. AWDATA_RX(crc_err);
  1093. AWDATA_RX(decrypt_crc_err);
  1094. AWDATA_RX(phy_err);
  1095. AWDATA_RX(mic_err);
  1096. AWDATA_RX(pre_delim_crc_err);
  1097. AWDATA_RX(post_delim_crc_err);
  1098. AWDATA_RX(decrypt_busy_err);
  1099. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
  1100. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
  1101. AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
  1102. WARN_ON(i != ATH9K_SSTATS_LEN);
  1103. }
  1104. void ath9k_deinit_debug(struct ath_softc *sc)
  1105. {
  1106. ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
  1107. }
  1108. int ath9k_init_debug(struct ath_hw *ah)
  1109. {
  1110. struct ath_common *common = ath9k_hw_common(ah);
  1111. struct ath_softc *sc = (struct ath_softc *) common->priv;
  1112. sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
  1113. sc->hw->wiphy->debugfsdir);
  1114. if (!sc->debug.debugfs_phy)
  1115. return -ENOMEM;
  1116. #ifdef CONFIG_ATH_DEBUG
  1117. debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1118. sc, &fops_debug);
  1119. #endif
  1120. ath9k_dfs_init_debug(sc);
  1121. ath9k_tx99_init_debug(sc);
  1122. ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
  1123. debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
  1124. read_file_dma);
  1125. debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
  1126. read_file_interrupt);
  1127. debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
  1128. read_file_xmit);
  1129. debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
  1130. read_file_queues);
  1131. debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1132. &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
  1133. debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1134. &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
  1135. debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1136. &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
  1137. debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1138. &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
  1139. debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
  1140. read_file_misc);
  1141. debugfs_create_devm_seqfile(sc->dev, "reset", sc->debug.debugfs_phy,
  1142. read_file_reset);
  1143. ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
  1144. ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
  1145. debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
  1146. &ah->rxchainmask);
  1147. debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
  1148. &ah->txchainmask);
  1149. debugfs_create_file("ani", S_IRUSR | S_IWUSR,
  1150. sc->debug.debugfs_phy, sc, &fops_ani);
  1151. debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1152. &sc->sc_ah->config.enable_paprd);
  1153. debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1154. sc, &fops_regidx);
  1155. debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1156. sc, &fops_regval);
  1157. debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
  1158. sc->debug.debugfs_phy,
  1159. &ah->config.cwm_ignore_extcca);
  1160. debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
  1161. &fops_regdump);
  1162. debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
  1163. sc->debug.debugfs_phy,
  1164. read_file_dump_nfcal);
  1165. ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
  1166. ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
  1167. debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
  1168. sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
  1169. debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
  1170. sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
  1171. debugfs_create_file("antenna_diversity", S_IRUSR,
  1172. sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
  1173. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  1174. debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
  1175. sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
  1176. debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
  1177. &fops_btcoex);
  1178. #endif
  1179. #ifdef CONFIG_ATH9K_WOW
  1180. debugfs_create_file("wow", S_IRUSR | S_IWUSR,
  1181. sc->debug.debugfs_phy, sc, &fops_wow);
  1182. #endif
  1183. #ifdef CONFIG_ATH9K_DYNACK
  1184. debugfs_create_file("ack_to", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
  1185. sc, &fops_ackto);
  1186. #endif
  1187. debugfs_create_file("tpc", S_IRUSR | S_IWUSR,
  1188. sc->debug.debugfs_phy, sc, &fops_tpc);
  1189. return 0;
  1190. }