ar9002_mac.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "hw.h"
  17. #define AR_BufLen 0x00000fff
  18. static void ar9002_hw_rx_enable(struct ath_hw *ah)
  19. {
  20. REG_WRITE(ah, AR_CR, AR_CR_RXE);
  21. }
  22. static void ar9002_hw_set_desc_link(void *ds, u32 ds_link)
  23. {
  24. ((struct ath_desc*) ds)->ds_link = ds_link;
  25. }
  26. static void ar9002_hw_get_desc_link(void *ds, u32 **ds_link)
  27. {
  28. *ds_link = &((struct ath_desc *)ds)->ds_link;
  29. }
  30. static bool ar9002_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
  31. {
  32. u32 isr = 0;
  33. u32 mask2 = 0;
  34. struct ath9k_hw_capabilities *pCap = &ah->caps;
  35. u32 sync_cause = 0;
  36. bool fatal_int = false;
  37. struct ath_common *common = ath9k_hw_common(ah);
  38. if (!AR_SREV_9100(ah)) {
  39. if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
  40. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  41. == AR_RTC_STATUS_ON) {
  42. isr = REG_READ(ah, AR_ISR);
  43. }
  44. }
  45. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
  46. AR_INTR_SYNC_DEFAULT;
  47. *masked = 0;
  48. if (!isr && !sync_cause)
  49. return false;
  50. } else {
  51. *masked = 0;
  52. isr = REG_READ(ah, AR_ISR);
  53. }
  54. if (isr) {
  55. if (isr & AR_ISR_BCNMISC) {
  56. u32 isr2;
  57. isr2 = REG_READ(ah, AR_ISR_S2);
  58. if (isr2 & AR_ISR_S2_TIM)
  59. mask2 |= ATH9K_INT_TIM;
  60. if (isr2 & AR_ISR_S2_DTIM)
  61. mask2 |= ATH9K_INT_DTIM;
  62. if (isr2 & AR_ISR_S2_DTIMSYNC)
  63. mask2 |= ATH9K_INT_DTIMSYNC;
  64. if (isr2 & (AR_ISR_S2_CABEND))
  65. mask2 |= ATH9K_INT_CABEND;
  66. if (isr2 & AR_ISR_S2_GTT)
  67. mask2 |= ATH9K_INT_GTT;
  68. if (isr2 & AR_ISR_S2_CST)
  69. mask2 |= ATH9K_INT_CST;
  70. if (isr2 & AR_ISR_S2_TSFOOR)
  71. mask2 |= ATH9K_INT_TSFOOR;
  72. }
  73. isr = REG_READ(ah, AR_ISR_RAC);
  74. if (isr == 0xffffffff) {
  75. *masked = 0;
  76. return false;
  77. }
  78. *masked = isr & ATH9K_INT_COMMON;
  79. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM |
  80. AR_ISR_RXOK | AR_ISR_RXERR))
  81. *masked |= ATH9K_INT_RX;
  82. if (isr &
  83. (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
  84. AR_ISR_TXEOL)) {
  85. u32 s0_s, s1_s;
  86. *masked |= ATH9K_INT_TX;
  87. s0_s = REG_READ(ah, AR_ISR_S0_S);
  88. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
  89. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
  90. s1_s = REG_READ(ah, AR_ISR_S1_S);
  91. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
  92. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
  93. }
  94. if (isr & AR_ISR_RXORN) {
  95. ath_dbg(common, ATH_DBG_INTERRUPT,
  96. "receive FIFO overrun interrupt\n");
  97. }
  98. *masked |= mask2;
  99. }
  100. if (AR_SREV_9100(ah))
  101. return true;
  102. if (isr & AR_ISR_GENTMR) {
  103. u32 s5_s;
  104. s5_s = REG_READ(ah, AR_ISR_S5_S);
  105. ah->intr_gen_timer_trigger =
  106. MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
  107. ah->intr_gen_timer_thresh =
  108. MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
  109. if (ah->intr_gen_timer_trigger)
  110. *masked |= ATH9K_INT_GENTIMER;
  111. if ((s5_s & AR_ISR_S5_TIM_TIMER) &&
  112. !(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  113. *masked |= ATH9K_INT_TIM_TIMER;
  114. }
  115. if (sync_cause) {
  116. fatal_int =
  117. (sync_cause &
  118. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  119. ? true : false;
  120. if (fatal_int) {
  121. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  122. ath_dbg(common, ATH_DBG_ANY,
  123. "received PCI FATAL interrupt\n");
  124. }
  125. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  126. ath_dbg(common, ATH_DBG_ANY,
  127. "received PCI PERR interrupt\n");
  128. }
  129. *masked |= ATH9K_INT_FATAL;
  130. }
  131. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  132. ath_dbg(common, ATH_DBG_INTERRUPT,
  133. "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
  134. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  135. REG_WRITE(ah, AR_RC, 0);
  136. *masked |= ATH9K_INT_FATAL;
  137. }
  138. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
  139. ath_dbg(common, ATH_DBG_INTERRUPT,
  140. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  141. }
  142. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  143. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  144. }
  145. return true;
  146. }
  147. static void ar9002_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen,
  148. bool is_firstseg, bool is_lastseg,
  149. const void *ds0, dma_addr_t buf_addr,
  150. unsigned int qcu)
  151. {
  152. struct ar5416_desc *ads = AR5416DESC(ds);
  153. ads->ds_data = buf_addr;
  154. if (is_firstseg) {
  155. ads->ds_ctl1 |= seglen | (is_lastseg ? 0 : AR_TxMore);
  156. } else if (is_lastseg) {
  157. ads->ds_ctl0 = 0;
  158. ads->ds_ctl1 = seglen;
  159. ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
  160. ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
  161. } else {
  162. ads->ds_ctl0 = 0;
  163. ads->ds_ctl1 = seglen | AR_TxMore;
  164. ads->ds_ctl2 = 0;
  165. ads->ds_ctl3 = 0;
  166. }
  167. ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
  168. ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
  169. ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
  170. ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
  171. ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
  172. }
  173. static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
  174. struct ath_tx_status *ts)
  175. {
  176. struct ar5416_desc *ads = AR5416DESC(ds);
  177. u32 status;
  178. status = ACCESS_ONCE(ads->ds_txstatus9);
  179. if ((status & AR_TxDone) == 0)
  180. return -EINPROGRESS;
  181. ts->ts_tstamp = ads->AR_SendTimestamp;
  182. ts->ts_status = 0;
  183. ts->ts_flags = 0;
  184. if (status & AR_TxOpExceeded)
  185. ts->ts_status |= ATH9K_TXERR_XTXOP;
  186. ts->tid = MS(status, AR_TxTid);
  187. ts->ts_rateindex = MS(status, AR_FinalTxIdx);
  188. ts->ts_seqnum = MS(status, AR_SeqNum);
  189. status = ACCESS_ONCE(ads->ds_txstatus0);
  190. ts->ts_rssi_ctl0 = MS(status, AR_TxRSSIAnt00);
  191. ts->ts_rssi_ctl1 = MS(status, AR_TxRSSIAnt01);
  192. ts->ts_rssi_ctl2 = MS(status, AR_TxRSSIAnt02);
  193. if (status & AR_TxBaStatus) {
  194. ts->ts_flags |= ATH9K_TX_BA;
  195. ts->ba_low = ads->AR_BaBitmapLow;
  196. ts->ba_high = ads->AR_BaBitmapHigh;
  197. }
  198. status = ACCESS_ONCE(ads->ds_txstatus1);
  199. if (status & AR_FrmXmitOK)
  200. ts->ts_status |= ATH9K_TX_ACKED;
  201. else {
  202. if (status & AR_ExcessiveRetries)
  203. ts->ts_status |= ATH9K_TXERR_XRETRY;
  204. if (status & AR_Filtered)
  205. ts->ts_status |= ATH9K_TXERR_FILT;
  206. if (status & AR_FIFOUnderrun) {
  207. ts->ts_status |= ATH9K_TXERR_FIFO;
  208. ath9k_hw_updatetxtriglevel(ah, true);
  209. }
  210. }
  211. if (status & AR_TxTimerExpired)
  212. ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  213. if (status & AR_DescCfgErr)
  214. ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  215. if (status & AR_TxDataUnderrun) {
  216. ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  217. ath9k_hw_updatetxtriglevel(ah, true);
  218. }
  219. if (status & AR_TxDelimUnderrun) {
  220. ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  221. ath9k_hw_updatetxtriglevel(ah, true);
  222. }
  223. ts->ts_shortretry = MS(status, AR_RTSFailCnt);
  224. ts->ts_longretry = MS(status, AR_DataFailCnt);
  225. ts->ts_virtcol = MS(status, AR_VirtRetryCnt);
  226. status = ACCESS_ONCE(ads->ds_txstatus5);
  227. ts->ts_rssi = MS(status, AR_TxRSSICombined);
  228. ts->ts_rssi_ext0 = MS(status, AR_TxRSSIAnt10);
  229. ts->ts_rssi_ext1 = MS(status, AR_TxRSSIAnt11);
  230. ts->ts_rssi_ext2 = MS(status, AR_TxRSSIAnt12);
  231. ts->evm0 = ads->AR_TxEVM0;
  232. ts->evm1 = ads->AR_TxEVM1;
  233. ts->evm2 = ads->AR_TxEVM2;
  234. return 0;
  235. }
  236. static void ar9002_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
  237. u32 pktLen, enum ath9k_pkt_type type,
  238. u32 txPower, u32 keyIx,
  239. enum ath9k_key_type keyType, u32 flags)
  240. {
  241. struct ar5416_desc *ads = AR5416DESC(ds);
  242. if (txPower > 63)
  243. txPower = 63;
  244. ads->ds_ctl0 = (pktLen & AR_FrameLen)
  245. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  246. | SM(txPower, AR_XmitPower)
  247. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  248. | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
  249. | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
  250. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
  251. ads->ds_ctl1 =
  252. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  253. | SM(type, AR_FrameType)
  254. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  255. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  256. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  257. ads->ds_ctl6 = SM(keyType, AR_EncrType);
  258. if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
  259. ads->ds_ctl8 = 0;
  260. ads->ds_ctl9 = 0;
  261. ads->ds_ctl10 = 0;
  262. ads->ds_ctl11 = 0;
  263. }
  264. }
  265. static void ar9002_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
  266. void *lastds,
  267. u32 durUpdateEn, u32 rtsctsRate,
  268. u32 rtsctsDuration,
  269. struct ath9k_11n_rate_series series[],
  270. u32 nseries, u32 flags)
  271. {
  272. struct ar5416_desc *ads = AR5416DESC(ds);
  273. struct ar5416_desc *last_ads = AR5416DESC(lastds);
  274. u32 ds_ctl0;
  275. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  276. ds_ctl0 = ads->ds_ctl0;
  277. if (flags & ATH9K_TXDESC_RTSENA) {
  278. ds_ctl0 &= ~AR_CTSEnable;
  279. ds_ctl0 |= AR_RTSEnable;
  280. } else {
  281. ds_ctl0 &= ~AR_RTSEnable;
  282. ds_ctl0 |= AR_CTSEnable;
  283. }
  284. ads->ds_ctl0 = ds_ctl0;
  285. } else {
  286. ads->ds_ctl0 =
  287. (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
  288. }
  289. ads->ds_ctl2 = set11nTries(series, 0)
  290. | set11nTries(series, 1)
  291. | set11nTries(series, 2)
  292. | set11nTries(series, 3)
  293. | (durUpdateEn ? AR_DurUpdateEna : 0)
  294. | SM(0, AR_BurstDur);
  295. ads->ds_ctl3 = set11nRate(series, 0)
  296. | set11nRate(series, 1)
  297. | set11nRate(series, 2)
  298. | set11nRate(series, 3);
  299. ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
  300. | set11nPktDurRTSCTS(series, 1);
  301. ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
  302. | set11nPktDurRTSCTS(series, 3);
  303. ads->ds_ctl7 = set11nRateFlags(series, 0)
  304. | set11nRateFlags(series, 1)
  305. | set11nRateFlags(series, 2)
  306. | set11nRateFlags(series, 3)
  307. | SM(rtsctsRate, AR_RTSCTSRate);
  308. last_ads->ds_ctl2 = ads->ds_ctl2;
  309. last_ads->ds_ctl3 = ads->ds_ctl3;
  310. }
  311. static void ar9002_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
  312. u32 aggrLen)
  313. {
  314. struct ar5416_desc *ads = AR5416DESC(ds);
  315. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  316. ads->ds_ctl6 &= ~AR_AggrLen;
  317. ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
  318. }
  319. static void ar9002_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
  320. u32 numDelims)
  321. {
  322. struct ar5416_desc *ads = AR5416DESC(ds);
  323. unsigned int ctl6;
  324. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  325. ctl6 = ads->ds_ctl6;
  326. ctl6 &= ~AR_PadDelim;
  327. ctl6 |= SM(numDelims, AR_PadDelim);
  328. ads->ds_ctl6 = ctl6;
  329. }
  330. static void ar9002_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
  331. {
  332. struct ar5416_desc *ads = AR5416DESC(ds);
  333. ads->ds_ctl1 |= AR_IsAggr;
  334. ads->ds_ctl1 &= ~AR_MoreAggr;
  335. ads->ds_ctl6 &= ~AR_PadDelim;
  336. }
  337. static void ar9002_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
  338. {
  339. struct ar5416_desc *ads = AR5416DESC(ds);
  340. ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
  341. }
  342. static void ar9002_hw_set11n_burstduration(struct ath_hw *ah, void *ds,
  343. u32 burstDuration)
  344. {
  345. struct ar5416_desc *ads = AR5416DESC(ds);
  346. ads->ds_ctl2 &= ~AR_BurstDur;
  347. ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
  348. }
  349. static void ar9002_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
  350. u32 vmf)
  351. {
  352. struct ar5416_desc *ads = AR5416DESC(ds);
  353. if (vmf)
  354. ads->ds_ctl0 |= AR_VirtMoreFrag;
  355. else
  356. ads->ds_ctl0 &= ~AR_VirtMoreFrag;
  357. }
  358. void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
  359. u32 size, u32 flags)
  360. {
  361. struct ar5416_desc *ads = AR5416DESC(ds);
  362. struct ath9k_hw_capabilities *pCap = &ah->caps;
  363. ads->ds_ctl1 = size & AR_BufLen;
  364. if (flags & ATH9K_RXDESC_INTREQ)
  365. ads->ds_ctl1 |= AR_RxIntrReq;
  366. ads->ds_rxstatus8 &= ~AR_RxDone;
  367. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  368. memset(&(ads->u), 0, sizeof(ads->u));
  369. }
  370. EXPORT_SYMBOL(ath9k_hw_setuprxdesc);
  371. void ar9002_hw_attach_mac_ops(struct ath_hw *ah)
  372. {
  373. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  374. ops->rx_enable = ar9002_hw_rx_enable;
  375. ops->set_desc_link = ar9002_hw_set_desc_link;
  376. ops->get_desc_link = ar9002_hw_get_desc_link;
  377. ops->get_isr = ar9002_hw_get_isr;
  378. ops->fill_txdesc = ar9002_hw_fill_txdesc;
  379. ops->proc_txdesc = ar9002_hw_proc_txdesc;
  380. ops->set11n_txdesc = ar9002_hw_set11n_txdesc;
  381. ops->set11n_ratescenario = ar9002_hw_set11n_ratescenario;
  382. ops->set11n_aggr_first = ar9002_hw_set11n_aggr_first;
  383. ops->set11n_aggr_middle = ar9002_hw_set11n_aggr_middle;
  384. ops->set11n_aggr_last = ar9002_hw_set11n_aggr_last;
  385. ops->clr11n_aggr = ar9002_hw_clr11n_aggr;
  386. ops->set11n_burstduration = ar9002_hw_set11n_burstduration;
  387. ops->set11n_virtualmorefrag = ar9002_hw_set11n_virtualmorefrag;
  388. }