You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath9k_mac.c 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <ipxe/io.h>
  20. #include "hw.h"
  21. #include "hw-ops.h"
  22. static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
  23. struct ath9k_tx_queue_info *qi __unused)
  24. {
  25. DBG2("ath9k: "
  26. "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
  27. ah->txok_interrupt_mask, ah->txerr_interrupt_mask,
  28. ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask,
  29. ah->txurn_interrupt_mask);
  30. ENABLE_REGWRITE_BUFFER(ah);
  31. REG_WRITE(ah, AR_IMR_S0,
  32. SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK)
  33. | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC));
  34. REG_WRITE(ah, AR_IMR_S1,
  35. SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR)
  36. | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL));
  37. ah->imrs2_reg &= ~AR_IMR_S2_QCU_TXURN;
  38. ah->imrs2_reg |= (ah->txurn_interrupt_mask & AR_IMR_S2_QCU_TXURN);
  39. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  40. REGWRITE_BUFFER_FLUSH(ah);
  41. }
  42. void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
  43. {
  44. REG_WRITE(ah, AR_QTXDP(q), txdp);
  45. }
  46. void ath9k_hw_txstart(struct ath_hw *ah, u32 q)
  47. {
  48. DBG2("ath9k: "
  49. "Enable TXE on queue: %d\n", q);
  50. REG_WRITE(ah, AR_Q_TXE, 1 << q);
  51. }
  52. u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
  53. {
  54. u32 npend;
  55. npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
  56. if (npend == 0) {
  57. if (REG_READ(ah, AR_Q_TXE) & (1 << q))
  58. npend = 1;
  59. }
  60. return npend;
  61. }
  62. /**
  63. * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level
  64. *
  65. * @ah: atheros hardware struct
  66. * @bIncTrigLevel: whether or not the frame trigger level should be updated
  67. *
  68. * The frame trigger level specifies the minimum number of bytes,
  69. * in units of 64 bytes, that must be DMA'ed into the PCU TX FIFO
  70. * before the PCU will initiate sending the frame on the air. This can
  71. * mean we initiate transmit before a full frame is on the PCU TX FIFO.
  72. * Resets to 0x1 (meaning 64 bytes or a full frame, whichever occurs
  73. * first)
  74. *
  75. * Caution must be taken to ensure to set the frame trigger level based
  76. * on the DMA request size. For example if the DMA request size is set to
  77. * 128 bytes the trigger level cannot exceed 6 * 64 = 384. This is because
  78. * there need to be enough space in the tx FIFO for the requested transfer
  79. * size. Hence the tx FIFO will stop with 512 - 128 = 384 bytes. If we set
  80. * the threshold to a value beyond 6, then the transmit will hang.
  81. *
  82. * Current dual stream devices have a PCU TX FIFO size of 8 KB.
  83. * Current single stream devices have a PCU TX FIFO size of 4 KB, however,
  84. * there is a hardware issue which forces us to use 2 KB instead so the
  85. * frame trigger level must not exceed 2 KB for these chipsets.
  86. */
  87. int ath9k_hw_updatetxtriglevel(struct ath_hw *ah, int bIncTrigLevel)
  88. {
  89. u32 txcfg, curLevel, newLevel;
  90. if (ah->tx_trig_level >= ah->config.max_txtrig_level)
  91. return 0;
  92. ath9k_hw_disable_interrupts(ah);
  93. txcfg = REG_READ(ah, AR_TXCFG);
  94. curLevel = MS(txcfg, AR_FTRIG);
  95. newLevel = curLevel;
  96. if (bIncTrigLevel) {
  97. if (curLevel < ah->config.max_txtrig_level)
  98. newLevel++;
  99. } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
  100. newLevel--;
  101. if (newLevel != curLevel)
  102. REG_WRITE(ah, AR_TXCFG,
  103. (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
  104. ath9k_hw_enable_interrupts(ah);
  105. ah->tx_trig_level = newLevel;
  106. return newLevel != curLevel;
  107. }
  108. void ath9k_hw_abort_tx_dma(struct ath_hw *ah)
  109. {
  110. int i, q;
  111. REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
  112. REG_SET_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
  113. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
  114. REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
  115. for (q = 0; q < AR_NUM_QCU; q++) {
  116. for (i = 0; i < 1000; i++) {
  117. if (i)
  118. udelay(5);
  119. if (!ath9k_hw_numtxpending(ah, q))
  120. break;
  121. }
  122. }
  123. REG_CLR_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
  124. REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
  125. REG_CLR_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
  126. REG_WRITE(ah, AR_Q_TXD, 0);
  127. }
  128. void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
  129. {
  130. *txqs &= ah->intr_txqs;
  131. ah->intr_txqs &= ~(*txqs);
  132. }
  133. int ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
  134. const struct ath9k_tx_queue_info *qinfo)
  135. {
  136. u32 cw;
  137. struct ath9k_tx_queue_info *qi;
  138. qi = &ah->txq[q];
  139. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  140. DBG("ath9k: "
  141. "Set TXQ properties, inactive queue: %d\n", q);
  142. return 0;
  143. }
  144. DBG2("ath9k: Set queue properties for: %d\n", q);
  145. qi->tqi_ver = qinfo->tqi_ver;
  146. qi->tqi_subtype = qinfo->tqi_subtype;
  147. qi->tqi_qflags = qinfo->tqi_qflags;
  148. qi->tqi_priority = qinfo->tqi_priority;
  149. if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
  150. qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
  151. else
  152. qi->tqi_aifs = INIT_AIFS;
  153. if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
  154. cw = min(qinfo->tqi_cwmin, 1024U);
  155. qi->tqi_cwmin = 1;
  156. while (qi->tqi_cwmin < cw)
  157. qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
  158. } else
  159. qi->tqi_cwmin = qinfo->tqi_cwmin;
  160. if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
  161. cw = min(qinfo->tqi_cwmax, 1024U);
  162. qi->tqi_cwmax = 1;
  163. while (qi->tqi_cwmax < cw)
  164. qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
  165. } else
  166. qi->tqi_cwmax = INIT_CWMAX;
  167. if (qinfo->tqi_shretry != 0)
  168. qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
  169. else
  170. qi->tqi_shretry = INIT_SH_RETRY;
  171. if (qinfo->tqi_lgretry != 0)
  172. qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
  173. else
  174. qi->tqi_lgretry = INIT_LG_RETRY;
  175. qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
  176. qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
  177. qi->tqi_burstTime = qinfo->tqi_burstTime;
  178. qi->tqi_readyTime = qinfo->tqi_readyTime;
  179. return 1;
  180. }
  181. int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
  182. const struct ath9k_tx_queue_info *qinfo)
  183. {
  184. struct ath9k_tx_queue_info *qi;
  185. int q;
  186. for (q = 0; q < ATH9K_NUM_TX_QUEUES; q++)
  187. if (ah->txq[q].tqi_type ==
  188. ATH9K_TX_QUEUE_INACTIVE)
  189. break;
  190. if (q == ATH9K_NUM_TX_QUEUES) {
  191. DBG("No available TX queue\n");
  192. return -1;
  193. }
  194. DBG2("ath9K: Setup TX queue: %d\n", q);
  195. qi = &ah->txq[q];
  196. if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
  197. DBG("ath9k: TX queue: %d already active\n", q);
  198. return -1;
  199. }
  200. memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
  201. qi->tqi_type = type;
  202. if (qinfo == NULL) {
  203. qi->tqi_qflags =
  204. TXQ_FLAG_TXOKINT_ENABLE
  205. | TXQ_FLAG_TXERRINT_ENABLE
  206. | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
  207. qi->tqi_aifs = INIT_AIFS;
  208. qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
  209. qi->tqi_cwmax = INIT_CWMAX;
  210. qi->tqi_shretry = INIT_SH_RETRY;
  211. qi->tqi_lgretry = INIT_LG_RETRY;
  212. qi->tqi_physCompBuf = 0;
  213. } else {
  214. qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
  215. (void) ath9k_hw_set_txq_props(ah, q, qinfo);
  216. }
  217. return q;
  218. }
  219. int ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
  220. {
  221. struct ath9k_tx_queue_info *qi;
  222. qi = &ah->txq[q];
  223. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  224. DBG("ath9k: "
  225. "Release TXQ, inactive queue: %d\n", q);
  226. return 0;
  227. }
  228. DBG2("ath9k: Release TX queue: %d\n", q);
  229. qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
  230. ah->txok_interrupt_mask &= ~(1 << q);
  231. ah->txerr_interrupt_mask &= ~(1 << q);
  232. ah->txdesc_interrupt_mask &= ~(1 << q);
  233. ah->txeol_interrupt_mask &= ~(1 << q);
  234. ah->txurn_interrupt_mask &= ~(1 << q);
  235. ath9k_hw_set_txq_interrupts(ah, qi);
  236. return 1;
  237. }
  238. int ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
  239. {
  240. struct ath9k_channel *chan = ah->curchan;
  241. struct ath9k_tx_queue_info *qi;
  242. u32 cwMin, chanCwMin, value __unused;
  243. qi = &ah->txq[q];
  244. if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
  245. DBG("ath9k: "
  246. "Reset TXQ, inactive queue: %d\n", q);
  247. return 1;
  248. }
  249. DBG2("ath9k: Reset TX queue: %d\n", q);
  250. if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
  251. if (chan && IS_CHAN_B(chan))
  252. chanCwMin = INIT_CWMIN_11B;
  253. else
  254. chanCwMin = INIT_CWMIN;
  255. for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
  256. } else
  257. cwMin = qi->tqi_cwmin;
  258. ENABLE_REGWRITE_BUFFER(ah);
  259. REG_WRITE(ah, AR_DLCL_IFS(q),
  260. SM(cwMin, AR_D_LCL_IFS_CWMIN) |
  261. SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
  262. SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
  263. REG_WRITE(ah, AR_DRETRY_LIMIT(q),
  264. SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
  265. SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
  266. SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
  267. REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
  268. if (AR_SREV_9340(ah))
  269. REG_WRITE(ah, AR_DMISC(q),
  270. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x1);
  271. else
  272. REG_WRITE(ah, AR_DMISC(q),
  273. AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
  274. if (qi->tqi_cbrPeriod) {
  275. REG_WRITE(ah, AR_QCBRCFG(q),
  276. SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
  277. SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
  278. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_FSP_CBR |
  279. (qi->tqi_cbrOverflowLimit ?
  280. AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
  281. }
  282. if (qi->tqi_readyTime) {
  283. REG_WRITE(ah, AR_QRDYTIMECFG(q),
  284. SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
  285. AR_Q_RDYTIMECFG_EN);
  286. }
  287. REG_WRITE(ah, AR_DCHNTIME(q),
  288. SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
  289. (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
  290. if (qi->tqi_burstTime
  291. && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE))
  292. REG_SET_BIT(ah, AR_QMISC(q), AR_Q_MISC_RDYTIME_EXP_POLICY);
  293. if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE)
  294. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_POST_FR_BKOFF_DIS);
  295. REGWRITE_BUFFER_FLUSH(ah);
  296. if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  297. REG_SET_BIT(ah, AR_DMISC(q), AR_D_MISC_FRAG_BKOFF_EN);
  298. if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
  299. REG_SET_BIT(ah, AR_DMISC(q),
  300. SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
  301. AR_D_MISC_ARB_LOCKOUT_CNTRL) |
  302. AR_D_MISC_POST_FR_BKOFF_DIS);
  303. }
  304. if (AR_SREV_9300_20_OR_LATER(ah))
  305. REG_WRITE(ah, AR_Q_DESC_CRCCHK, AR_Q_DESC_CRCCHK_EN);
  306. if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
  307. ah->txok_interrupt_mask |= 1 << q;
  308. else
  309. ah->txok_interrupt_mask &= ~(1 << q);
  310. if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
  311. ah->txerr_interrupt_mask |= 1 << q;
  312. else
  313. ah->txerr_interrupt_mask &= ~(1 << q);
  314. if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
  315. ah->txdesc_interrupt_mask |= 1 << q;
  316. else
  317. ah->txdesc_interrupt_mask &= ~(1 << q);
  318. if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
  319. ah->txeol_interrupt_mask |= 1 << q;
  320. else
  321. ah->txeol_interrupt_mask &= ~(1 << q);
  322. if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
  323. ah->txurn_interrupt_mask |= 1 << q;
  324. else
  325. ah->txurn_interrupt_mask &= ~(1 << q);
  326. ath9k_hw_set_txq_interrupts(ah, qi);
  327. return 1;
  328. }
  329. int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
  330. struct ath_rx_status *rs, u64 tsf __unused)
  331. {
  332. struct ar5416_desc ads;
  333. struct ar5416_desc *adsp = AR5416DESC(ds);
  334. u32 phyerr;
  335. if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
  336. return -EINPROGRESS;
  337. ads.u.rx = adsp->u.rx;
  338. rs->rs_status = 0;
  339. rs->rs_flags = 0;
  340. rs->rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
  341. rs->rs_tstamp = ads.AR_RcvTimestamp;
  342. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) {
  343. rs->rs_rssi = ATH9K_RSSI_BAD;
  344. rs->rs_rssi_ctl0 = ATH9K_RSSI_BAD;
  345. rs->rs_rssi_ctl1 = ATH9K_RSSI_BAD;
  346. rs->rs_rssi_ctl2 = ATH9K_RSSI_BAD;
  347. rs->rs_rssi_ext0 = ATH9K_RSSI_BAD;
  348. rs->rs_rssi_ext1 = ATH9K_RSSI_BAD;
  349. rs->rs_rssi_ext2 = ATH9K_RSSI_BAD;
  350. } else {
  351. rs->rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
  352. rs->rs_rssi_ctl0 = MS(ads.ds_rxstatus0,
  353. AR_RxRSSIAnt00);
  354. rs->rs_rssi_ctl1 = MS(ads.ds_rxstatus0,
  355. AR_RxRSSIAnt01);
  356. rs->rs_rssi_ctl2 = MS(ads.ds_rxstatus0,
  357. AR_RxRSSIAnt02);
  358. rs->rs_rssi_ext0 = MS(ads.ds_rxstatus4,
  359. AR_RxRSSIAnt10);
  360. rs->rs_rssi_ext1 = MS(ads.ds_rxstatus4,
  361. AR_RxRSSIAnt11);
  362. rs->rs_rssi_ext2 = MS(ads.ds_rxstatus4,
  363. AR_RxRSSIAnt12);
  364. }
  365. if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
  366. rs->rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
  367. else
  368. rs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  369. rs->rs_rate = RXSTATUS_RATE(ah, (&ads));
  370. rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
  371. rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
  372. rs->rs_moreaggr =
  373. (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
  374. rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
  375. rs->rs_flags =
  376. (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
  377. rs->rs_flags |=
  378. (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
  379. if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
  380. rs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  381. if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
  382. rs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  383. if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
  384. rs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  385. if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
  386. /*
  387. * Treat these errors as mutually exclusive to avoid spurious
  388. * extra error reports from the hardware. If a CRC error is
  389. * reported, then decryption and MIC errors are irrelevant,
  390. * the frame is going to be dropped either way
  391. */
  392. if (ads.ds_rxstatus8 & AR_CRCErr)
  393. rs->rs_status |= ATH9K_RXERR_CRC;
  394. else if (ads.ds_rxstatus8 & AR_PHYErr) {
  395. rs->rs_status |= ATH9K_RXERR_PHY;
  396. phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
  397. rs->rs_phyerr = phyerr;
  398. } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
  399. rs->rs_status |= ATH9K_RXERR_DECRYPT;
  400. else if (ads.ds_rxstatus8 & AR_MichaelErr)
  401. rs->rs_status |= ATH9K_RXERR_MIC;
  402. else if (ads.ds_rxstatus8 & AR_KeyMiss)
  403. rs->rs_status |= ATH9K_RXERR_DECRYPT;
  404. }
  405. return 0;
  406. }
  407. /*
  408. * This can stop or re-enables RX.
  409. *
  410. * If bool is set this will kill any frame which is currently being
  411. * transferred between the MAC and baseband and also prevent any new
  412. * frames from getting started.
  413. */
  414. int ath9k_hw_setrxabort(struct ath_hw *ah, int set)
  415. {
  416. u32 reg;
  417. if (set) {
  418. REG_SET_BIT(ah, AR_DIAG_SW,
  419. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  420. if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE,
  421. 0, AH_WAIT_TIMEOUT)) {
  422. REG_CLR_BIT(ah, AR_DIAG_SW,
  423. (AR_DIAG_RX_DIS |
  424. AR_DIAG_RX_ABORT));
  425. reg = REG_READ(ah, AR_OBS_BUS_1);
  426. DBG("ath9k: "
  427. "RX failed to go idle in 10 ms RXSM=0x%x\n",
  428. reg);
  429. return 0;
  430. }
  431. } else {
  432. REG_CLR_BIT(ah, AR_DIAG_SW,
  433. (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  434. }
  435. return 1;
  436. }
  437. void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
  438. {
  439. REG_WRITE(ah, AR_RXDP, rxdp);
  440. }
  441. void ath9k_hw_startpcureceive(struct ath_hw *ah, int is_scanning)
  442. {
  443. ath9k_ani_reset(ah, is_scanning);
  444. REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  445. }
  446. void ath9k_hw_abortpcurecv(struct ath_hw *ah)
  447. {
  448. REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_ABORT | AR_DIAG_RX_DIS);
  449. }
  450. int ath9k_hw_stopdmarecv(struct ath_hw *ah, int *reset)
  451. {
  452. #define AH_RX_STOP_DMA_TIMEOUT 10000 /* usec */
  453. u32 mac_status, last_mac_status = 0;
  454. int i;
  455. /* Enable access to the DMA observation bus */
  456. REG_WRITE(ah, AR_MACMISC,
  457. ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
  458. (AR_MACMISC_MISC_OBS_BUS_1 <<
  459. AR_MACMISC_MISC_OBS_BUS_MSB_S)));
  460. REG_WRITE(ah, AR_CR, AR_CR_RXD);
  461. /* Wait for rx enable bit to go low */
  462. for (i = AH_RX_STOP_DMA_TIMEOUT / AH_TIME_QUANTUM; i != 0; i--) {
  463. if ((REG_READ(ah, AR_CR) & AR_CR_RXE) == 0)
  464. break;
  465. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  466. mac_status = REG_READ(ah, AR_DMADBG_7) & 0x7f0;
  467. if (mac_status == 0x1c0 && mac_status == last_mac_status) {
  468. *reset = 1;
  469. break;
  470. }
  471. last_mac_status = mac_status;
  472. }
  473. udelay(AH_TIME_QUANTUM);
  474. }
  475. if (i == 0) {
  476. DBG("ath9k: "
  477. "DMA failed to stop in %d ms AR_CR=0x%08x AR_DIAG_SW=0x%08x DMADBG_7=0x%08x\n",
  478. AH_RX_STOP_DMA_TIMEOUT / 1000,
  479. REG_READ(ah, AR_CR),
  480. REG_READ(ah, AR_DIAG_SW),
  481. REG_READ(ah, AR_DMADBG_7));
  482. return 0;
  483. } else {
  484. return 1;
  485. }
  486. #undef AH_RX_STOP_DMA_TIMEOUT
  487. }
  488. int ath9k_hw_intrpend(struct ath_hw *ah)
  489. {
  490. u32 host_isr;
  491. if (AR_SREV_9100(ah) || !(ah->ah_ier & AR_IER_ENABLE))
  492. return 1;
  493. host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  494. if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
  495. return 1;
  496. host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  497. if ((host_isr & AR_INTR_SYNC_DEFAULT)
  498. && (host_isr != AR_INTR_SPURIOUS))
  499. return 1;
  500. return 0;
  501. }
  502. void ath9k_hw_disable_interrupts(struct ath_hw *ah)
  503. {
  504. DBG2("ath9k: disable IER\n");
  505. REG_WRITE(ah, AR_IER, ah->ah_ier);
  506. (void) REG_READ(ah, AR_IER);
  507. if (!AR_SREV_9100(ah)) {
  508. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  509. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  510. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  511. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  512. }
  513. }
  514. void ath9k_hw_enable_interrupts(struct ath_hw *ah)
  515. {
  516. u32 sync_default = AR_INTR_SYNC_DEFAULT;
  517. if (!(ah->imask & ATH9K_INT_GLOBAL))
  518. return;
  519. if (AR_SREV_9340(ah))
  520. sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
  521. DBG2("ath9k: enable IER\n");
  522. REG_WRITE(ah, AR_IER, ah->ah_ier);
  523. if (!AR_SREV_9100(ah)) {
  524. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
  525. AR_INTR_MAC_IRQ);
  526. REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
  527. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
  528. REG_WRITE(ah, AR_INTR_SYNC_MASK, sync_default);
  529. }
  530. DBG2("ath9k: AR_IMR 0x%x IER 0x%x\n",
  531. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  532. }
  533. void ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
  534. {
  535. enum ath9k_int omask = ah->imask;
  536. u32 mask, mask2;
  537. struct ath9k_hw_capabilities *pCap = &ah->caps;
  538. if (!(ints & ATH9K_INT_GLOBAL))
  539. ath9k_hw_disable_interrupts(ah);
  540. DBG2("ath9k: 0x%x => 0x%x\n", omask, ints);
  541. /* TODO: global int Ref count */
  542. mask = ints & ATH9K_INT_COMMON;
  543. mask2 = 0;
  544. if (ints & ATH9K_INT_TX) {
  545. if (ah->config.tx_intr_mitigation)
  546. mask |= AR_IMR_TXMINTR | AR_IMR_TXINTM;
  547. else {
  548. if (ah->txok_interrupt_mask)
  549. mask |= AR_IMR_TXOK;
  550. if (ah->txdesc_interrupt_mask)
  551. mask |= AR_IMR_TXDESC;
  552. }
  553. if (ah->txerr_interrupt_mask)
  554. mask |= AR_IMR_TXERR;
  555. if (ah->txeol_interrupt_mask)
  556. mask |= AR_IMR_TXEOL;
  557. }
  558. if (ints & ATH9K_INT_RX) {
  559. if (AR_SREV_9300_20_OR_LATER(ah)) {
  560. mask |= AR_IMR_RXERR | AR_IMR_RXOK_HP;
  561. if (ah->config.rx_intr_mitigation) {
  562. mask &= ~AR_IMR_RXOK_LP;
  563. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  564. } else {
  565. mask |= AR_IMR_RXOK_LP;
  566. }
  567. } else {
  568. if (ah->config.rx_intr_mitigation)
  569. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  570. else
  571. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  572. }
  573. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  574. mask |= AR_IMR_GENTMR;
  575. }
  576. if (ints & ATH9K_INT_GENTIMER)
  577. mask |= AR_IMR_GENTMR;
  578. if (ints & (ATH9K_INT_BMISC)) {
  579. mask |= AR_IMR_BCNMISC;
  580. if (ints & ATH9K_INT_TIM)
  581. mask2 |= AR_IMR_S2_TIM;
  582. if (ints & ATH9K_INT_DTIM)
  583. mask2 |= AR_IMR_S2_DTIM;
  584. if (ints & ATH9K_INT_DTIMSYNC)
  585. mask2 |= AR_IMR_S2_DTIMSYNC;
  586. if (ints & ATH9K_INT_CABEND)
  587. mask2 |= AR_IMR_S2_CABEND;
  588. if (ints & ATH9K_INT_TSFOOR)
  589. mask2 |= AR_IMR_S2_TSFOOR;
  590. }
  591. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  592. mask |= AR_IMR_BCNMISC;
  593. if (ints & ATH9K_INT_GTT)
  594. mask2 |= AR_IMR_S2_GTT;
  595. if (ints & ATH9K_INT_CST)
  596. mask2 |= AR_IMR_S2_CST;
  597. }
  598. DBG2("ath9k: new IMR 0x%x\n", mask);
  599. REG_WRITE(ah, AR_IMR, mask);
  600. ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
  601. AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
  602. AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
  603. ah->imrs2_reg |= mask2;
  604. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  605. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  606. if (ints & ATH9K_INT_TIM_TIMER)
  607. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  608. else
  609. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  610. }
  611. if (ints & ATH9K_INT_GLOBAL)
  612. ath9k_hw_enable_interrupts(ah);
  613. return;
  614. }