ar9002_mac.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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 (ah->config.rx_intr_mitigation) {
  80. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  81. *masked |= ATH9K_INT_RX;
  82. }
  83. if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
  84. *masked |= ATH9K_INT_RX;
  85. if (isr &
  86. (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
  87. AR_ISR_TXEOL)) {
  88. u32 s0_s, s1_s;
  89. *masked |= ATH9K_INT_TX;
  90. s0_s = REG_READ(ah, AR_ISR_S0_S);
  91. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
  92. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
  93. s1_s = REG_READ(ah, AR_ISR_S1_S);
  94. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
  95. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
  96. }
  97. if (isr & AR_ISR_RXORN) {
  98. ath_print(common, ATH_DBG_INTERRUPT,
  99. "receive FIFO overrun interrupt\n");
  100. }
  101. if (!AR_SREV_9100(ah)) {
  102. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  103. u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
  104. if (isr5 & AR_ISR_S5_TIM_TIMER)
  105. *masked |= ATH9K_INT_TIM_TIMER;
  106. }
  107. }
  108. *masked |= mask2;
  109. }
  110. if (AR_SREV_9100(ah))
  111. return true;
  112. if (isr & AR_ISR_GENTMR) {
  113. u32 s5_s;
  114. s5_s = REG_READ(ah, AR_ISR_S5_S);
  115. if (isr & AR_ISR_GENTMR) {
  116. ah->intr_gen_timer_trigger =
  117. MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
  118. ah->intr_gen_timer_thresh =
  119. MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
  120. if (ah->intr_gen_timer_trigger)
  121. *masked |= ATH9K_INT_GENTIMER;
  122. }
  123. }
  124. if (sync_cause) {
  125. fatal_int =
  126. (sync_cause &
  127. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  128. ? true : false;
  129. if (fatal_int) {
  130. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  131. ath_print(common, ATH_DBG_ANY,
  132. "received PCI FATAL interrupt\n");
  133. }
  134. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  135. ath_print(common, ATH_DBG_ANY,
  136. "received PCI PERR interrupt\n");
  137. }
  138. *masked |= ATH9K_INT_FATAL;
  139. }
  140. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  141. ath_print(common, ATH_DBG_INTERRUPT,
  142. "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
  143. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  144. REG_WRITE(ah, AR_RC, 0);
  145. *masked |= ATH9K_INT_FATAL;
  146. }
  147. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
  148. ath_print(common, ATH_DBG_INTERRUPT,
  149. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  150. }
  151. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  152. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  153. }
  154. return true;
  155. }
  156. static void ar9002_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen,
  157. bool is_firstseg, bool is_lastseg,
  158. const void *ds0, dma_addr_t buf_addr,
  159. unsigned int qcu)
  160. {
  161. struct ar5416_desc *ads = AR5416DESC(ds);
  162. ads->ds_data = buf_addr;
  163. if (is_firstseg) {
  164. ads->ds_ctl1 |= seglen | (is_lastseg ? 0 : AR_TxMore);
  165. } else if (is_lastseg) {
  166. ads->ds_ctl0 = 0;
  167. ads->ds_ctl1 = seglen;
  168. ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
  169. ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
  170. } else {
  171. ads->ds_ctl0 = 0;
  172. ads->ds_ctl1 = seglen | AR_TxMore;
  173. ads->ds_ctl2 = 0;
  174. ads->ds_ctl3 = 0;
  175. }
  176. ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
  177. ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
  178. ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
  179. ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
  180. ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
  181. }
  182. static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
  183. struct ath_tx_status *ts)
  184. {
  185. struct ar5416_desc *ads = AR5416DESC(ds);
  186. if ((ads->ds_txstatus9 & AR_TxDone) == 0)
  187. return -EINPROGRESS;
  188. ts->ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
  189. ts->ts_tstamp = ads->AR_SendTimestamp;
  190. ts->ts_status = 0;
  191. ts->ts_flags = 0;
  192. if (ads->ds_txstatus1 & AR_FrmXmitOK)
  193. ts->ts_status |= ATH9K_TX_ACKED;
  194. if (ads->ds_txstatus1 & AR_ExcessiveRetries)
  195. ts->ts_status |= ATH9K_TXERR_XRETRY;
  196. if (ads->ds_txstatus1 & AR_Filtered)
  197. ts->ts_status |= ATH9K_TXERR_FILT;
  198. if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
  199. ts->ts_status |= ATH9K_TXERR_FIFO;
  200. ath9k_hw_updatetxtriglevel(ah, true);
  201. }
  202. if (ads->ds_txstatus9 & AR_TxOpExceeded)
  203. ts->ts_status |= ATH9K_TXERR_XTXOP;
  204. if (ads->ds_txstatus1 & AR_TxTimerExpired)
  205. ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  206. if (ads->ds_txstatus1 & AR_DescCfgErr)
  207. ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  208. if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
  209. ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  210. ath9k_hw_updatetxtriglevel(ah, true);
  211. }
  212. if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
  213. ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  214. ath9k_hw_updatetxtriglevel(ah, true);
  215. }
  216. if (ads->ds_txstatus0 & AR_TxBaStatus) {
  217. ts->ts_flags |= ATH9K_TX_BA;
  218. ts->ba_low = ads->AR_BaBitmapLow;
  219. ts->ba_high = ads->AR_BaBitmapHigh;
  220. }
  221. ts->ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
  222. switch (ts->ts_rateindex) {
  223. case 0:
  224. ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
  225. break;
  226. case 1:
  227. ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
  228. break;
  229. case 2:
  230. ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
  231. break;
  232. case 3:
  233. ts->ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
  234. break;
  235. }
  236. ts->ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
  237. ts->ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
  238. ts->ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
  239. ts->ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
  240. ts->ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
  241. ts->ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
  242. ts->ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
  243. ts->evm0 = ads->AR_TxEVM0;
  244. ts->evm1 = ads->AR_TxEVM1;
  245. ts->evm2 = ads->AR_TxEVM2;
  246. ts->ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
  247. ts->ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
  248. ts->ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
  249. ts->tid = MS(ads->ds_txstatus9, AR_TxTid);
  250. ts->ts_antenna = 0;
  251. return 0;
  252. }
  253. static void ar9002_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
  254. u32 pktLen, enum ath9k_pkt_type type,
  255. u32 txPower, u32 keyIx,
  256. enum ath9k_key_type keyType, u32 flags)
  257. {
  258. struct ar5416_desc *ads = AR5416DESC(ds);
  259. txPower += ah->txpower_indexoffset;
  260. if (txPower > 63)
  261. txPower = 63;
  262. ads->ds_ctl0 = (pktLen & AR_FrameLen)
  263. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  264. | SM(txPower, AR_XmitPower)
  265. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  266. | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
  267. | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
  268. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
  269. ads->ds_ctl1 =
  270. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  271. | SM(type, AR_FrameType)
  272. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  273. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  274. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  275. ads->ds_ctl6 = SM(keyType, AR_EncrType);
  276. if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
  277. ads->ds_ctl8 = 0;
  278. ads->ds_ctl9 = 0;
  279. ads->ds_ctl10 = 0;
  280. ads->ds_ctl11 = 0;
  281. }
  282. }
  283. static void ar9002_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
  284. void *lastds,
  285. u32 durUpdateEn, u32 rtsctsRate,
  286. u32 rtsctsDuration,
  287. struct ath9k_11n_rate_series series[],
  288. u32 nseries, u32 flags)
  289. {
  290. struct ar5416_desc *ads = AR5416DESC(ds);
  291. struct ar5416_desc *last_ads = AR5416DESC(lastds);
  292. u32 ds_ctl0;
  293. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  294. ds_ctl0 = ads->ds_ctl0;
  295. if (flags & ATH9K_TXDESC_RTSENA) {
  296. ds_ctl0 &= ~AR_CTSEnable;
  297. ds_ctl0 |= AR_RTSEnable;
  298. } else {
  299. ds_ctl0 &= ~AR_RTSEnable;
  300. ds_ctl0 |= AR_CTSEnable;
  301. }
  302. ads->ds_ctl0 = ds_ctl0;
  303. } else {
  304. ads->ds_ctl0 =
  305. (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
  306. }
  307. ads->ds_ctl2 = set11nTries(series, 0)
  308. | set11nTries(series, 1)
  309. | set11nTries(series, 2)
  310. | set11nTries(series, 3)
  311. | (durUpdateEn ? AR_DurUpdateEna : 0)
  312. | SM(0, AR_BurstDur);
  313. ads->ds_ctl3 = set11nRate(series, 0)
  314. | set11nRate(series, 1)
  315. | set11nRate(series, 2)
  316. | set11nRate(series, 3);
  317. ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
  318. | set11nPktDurRTSCTS(series, 1);
  319. ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
  320. | set11nPktDurRTSCTS(series, 3);
  321. ads->ds_ctl7 = set11nRateFlags(series, 0)
  322. | set11nRateFlags(series, 1)
  323. | set11nRateFlags(series, 2)
  324. | set11nRateFlags(series, 3)
  325. | SM(rtsctsRate, AR_RTSCTSRate);
  326. last_ads->ds_ctl2 = ads->ds_ctl2;
  327. last_ads->ds_ctl3 = ads->ds_ctl3;
  328. }
  329. static void ar9002_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
  330. u32 aggrLen)
  331. {
  332. struct ar5416_desc *ads = AR5416DESC(ds);
  333. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  334. ads->ds_ctl6 &= ~AR_AggrLen;
  335. ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
  336. }
  337. static void ar9002_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
  338. u32 numDelims)
  339. {
  340. struct ar5416_desc *ads = AR5416DESC(ds);
  341. unsigned int ctl6;
  342. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  343. ctl6 = ads->ds_ctl6;
  344. ctl6 &= ~AR_PadDelim;
  345. ctl6 |= SM(numDelims, AR_PadDelim);
  346. ads->ds_ctl6 = ctl6;
  347. }
  348. static void ar9002_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
  349. {
  350. struct ar5416_desc *ads = AR5416DESC(ds);
  351. ads->ds_ctl1 |= AR_IsAggr;
  352. ads->ds_ctl1 &= ~AR_MoreAggr;
  353. ads->ds_ctl6 &= ~AR_PadDelim;
  354. }
  355. static void ar9002_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
  356. {
  357. struct ar5416_desc *ads = AR5416DESC(ds);
  358. ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
  359. }
  360. static void ar9002_hw_set11n_burstduration(struct ath_hw *ah, void *ds,
  361. u32 burstDuration)
  362. {
  363. struct ar5416_desc *ads = AR5416DESC(ds);
  364. ads->ds_ctl2 &= ~AR_BurstDur;
  365. ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
  366. }
  367. static void ar9002_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
  368. u32 vmf)
  369. {
  370. struct ar5416_desc *ads = AR5416DESC(ds);
  371. if (vmf)
  372. ads->ds_ctl0 |= AR_VirtMoreFrag;
  373. else
  374. ads->ds_ctl0 &= ~AR_VirtMoreFrag;
  375. }
  376. void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
  377. u32 size, u32 flags)
  378. {
  379. struct ar5416_desc *ads = AR5416DESC(ds);
  380. struct ath9k_hw_capabilities *pCap = &ah->caps;
  381. ads->ds_ctl1 = size & AR_BufLen;
  382. if (flags & ATH9K_RXDESC_INTREQ)
  383. ads->ds_ctl1 |= AR_RxIntrReq;
  384. ads->ds_rxstatus8 &= ~AR_RxDone;
  385. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  386. memset(&(ads->u), 0, sizeof(ads->u));
  387. }
  388. EXPORT_SYMBOL(ath9k_hw_setuprxdesc);
  389. void ar9002_hw_attach_mac_ops(struct ath_hw *ah)
  390. {
  391. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  392. ops->rx_enable = ar9002_hw_rx_enable;
  393. ops->set_desc_link = ar9002_hw_set_desc_link;
  394. ops->get_desc_link = ar9002_hw_get_desc_link;
  395. ops->get_isr = ar9002_hw_get_isr;
  396. ops->fill_txdesc = ar9002_hw_fill_txdesc;
  397. ops->proc_txdesc = ar9002_hw_proc_txdesc;
  398. ops->set11n_txdesc = ar9002_hw_set11n_txdesc;
  399. ops->set11n_ratescenario = ar9002_hw_set11n_ratescenario;
  400. ops->set11n_aggr_first = ar9002_hw_set11n_aggr_first;
  401. ops->set11n_aggr_middle = ar9002_hw_set11n_aggr_middle;
  402. ops->set11n_aggr_last = ar9002_hw_set11n_aggr_last;
  403. ops->clr11n_aggr = ar9002_hw_clr11n_aggr;
  404. ops->set11n_burstduration = ar9002_hw_set11n_burstduration;
  405. ops->set11n_virtualmorefrag = ar9002_hw_set11n_virtualmorefrag;
  406. }