ar9002_mac.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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->ts_antenna = 0;
  250. return 0;
  251. }
  252. static void ar9002_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
  253. u32 pktLen, enum ath9k_pkt_type type,
  254. u32 txPower, u32 keyIx,
  255. enum ath9k_key_type keyType, u32 flags)
  256. {
  257. struct ar5416_desc *ads = AR5416DESC(ds);
  258. txPower += ah->txpower_indexoffset;
  259. if (txPower > 63)
  260. txPower = 63;
  261. ads->ds_ctl0 = (pktLen & AR_FrameLen)
  262. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  263. | SM(txPower, AR_XmitPower)
  264. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  265. | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
  266. | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
  267. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
  268. ads->ds_ctl1 =
  269. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  270. | SM(type, AR_FrameType)
  271. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  272. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  273. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  274. ads->ds_ctl6 = SM(keyType, AR_EncrType);
  275. if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
  276. ads->ds_ctl8 = 0;
  277. ads->ds_ctl9 = 0;
  278. ads->ds_ctl10 = 0;
  279. ads->ds_ctl11 = 0;
  280. }
  281. }
  282. static void ar9002_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
  283. void *lastds,
  284. u32 durUpdateEn, u32 rtsctsRate,
  285. u32 rtsctsDuration,
  286. struct ath9k_11n_rate_series series[],
  287. u32 nseries, u32 flags)
  288. {
  289. struct ar5416_desc *ads = AR5416DESC(ds);
  290. struct ar5416_desc *last_ads = AR5416DESC(lastds);
  291. u32 ds_ctl0;
  292. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  293. ds_ctl0 = ads->ds_ctl0;
  294. if (flags & ATH9K_TXDESC_RTSENA) {
  295. ds_ctl0 &= ~AR_CTSEnable;
  296. ds_ctl0 |= AR_RTSEnable;
  297. } else {
  298. ds_ctl0 &= ~AR_RTSEnable;
  299. ds_ctl0 |= AR_CTSEnable;
  300. }
  301. ads->ds_ctl0 = ds_ctl0;
  302. } else {
  303. ads->ds_ctl0 =
  304. (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
  305. }
  306. ads->ds_ctl2 = set11nTries(series, 0)
  307. | set11nTries(series, 1)
  308. | set11nTries(series, 2)
  309. | set11nTries(series, 3)
  310. | (durUpdateEn ? AR_DurUpdateEna : 0)
  311. | SM(0, AR_BurstDur);
  312. ads->ds_ctl3 = set11nRate(series, 0)
  313. | set11nRate(series, 1)
  314. | set11nRate(series, 2)
  315. | set11nRate(series, 3);
  316. ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
  317. | set11nPktDurRTSCTS(series, 1);
  318. ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
  319. | set11nPktDurRTSCTS(series, 3);
  320. ads->ds_ctl7 = set11nRateFlags(series, 0)
  321. | set11nRateFlags(series, 1)
  322. | set11nRateFlags(series, 2)
  323. | set11nRateFlags(series, 3)
  324. | SM(rtsctsRate, AR_RTSCTSRate);
  325. last_ads->ds_ctl2 = ads->ds_ctl2;
  326. last_ads->ds_ctl3 = ads->ds_ctl3;
  327. }
  328. static void ar9002_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
  329. u32 aggrLen)
  330. {
  331. struct ar5416_desc *ads = AR5416DESC(ds);
  332. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  333. ads->ds_ctl6 &= ~AR_AggrLen;
  334. ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
  335. }
  336. static void ar9002_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
  337. u32 numDelims)
  338. {
  339. struct ar5416_desc *ads = AR5416DESC(ds);
  340. unsigned int ctl6;
  341. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  342. ctl6 = ads->ds_ctl6;
  343. ctl6 &= ~AR_PadDelim;
  344. ctl6 |= SM(numDelims, AR_PadDelim);
  345. ads->ds_ctl6 = ctl6;
  346. }
  347. static void ar9002_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
  348. {
  349. struct ar5416_desc *ads = AR5416DESC(ds);
  350. ads->ds_ctl1 |= AR_IsAggr;
  351. ads->ds_ctl1 &= ~AR_MoreAggr;
  352. ads->ds_ctl6 &= ~AR_PadDelim;
  353. }
  354. static void ar9002_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
  355. {
  356. struct ar5416_desc *ads = AR5416DESC(ds);
  357. ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
  358. }
  359. static void ar9002_hw_set11n_burstduration(struct ath_hw *ah, void *ds,
  360. u32 burstDuration)
  361. {
  362. struct ar5416_desc *ads = AR5416DESC(ds);
  363. ads->ds_ctl2 &= ~AR_BurstDur;
  364. ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
  365. }
  366. static void ar9002_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
  367. u32 vmf)
  368. {
  369. struct ar5416_desc *ads = AR5416DESC(ds);
  370. if (vmf)
  371. ads->ds_ctl0 |= AR_VirtMoreFrag;
  372. else
  373. ads->ds_ctl0 &= ~AR_VirtMoreFrag;
  374. }
  375. void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
  376. u32 size, u32 flags)
  377. {
  378. struct ar5416_desc *ads = AR5416DESC(ds);
  379. struct ath9k_hw_capabilities *pCap = &ah->caps;
  380. ads->ds_ctl1 = size & AR_BufLen;
  381. if (flags & ATH9K_RXDESC_INTREQ)
  382. ads->ds_ctl1 |= AR_RxIntrReq;
  383. ads->ds_rxstatus8 &= ~AR_RxDone;
  384. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  385. memset(&(ads->u), 0, sizeof(ads->u));
  386. }
  387. EXPORT_SYMBOL(ath9k_hw_setuprxdesc);
  388. void ar9002_hw_attach_mac_ops(struct ath_hw *ah)
  389. {
  390. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  391. ops->rx_enable = ar9002_hw_rx_enable;
  392. ops->set_desc_link = ar9002_hw_set_desc_link;
  393. ops->get_desc_link = ar9002_hw_get_desc_link;
  394. ops->get_isr = ar9002_hw_get_isr;
  395. ops->fill_txdesc = ar9002_hw_fill_txdesc;
  396. ops->proc_txdesc = ar9002_hw_proc_txdesc;
  397. ops->set11n_txdesc = ar9002_hw_set11n_txdesc;
  398. ops->set11n_ratescenario = ar9002_hw_set11n_ratescenario;
  399. ops->set11n_aggr_first = ar9002_hw_set11n_aggr_first;
  400. ops->set11n_aggr_middle = ar9002_hw_set11n_aggr_middle;
  401. ops->set11n_aggr_last = ar9002_hw_set11n_aggr_last;
  402. ops->clr11n_aggr = ar9002_hw_clr11n_aggr;
  403. ops->set11n_burstduration = ar9002_hw_set11n_burstduration;
  404. ops->set11n_virtualmorefrag = ar9002_hw_set11n_virtualmorefrag;
  405. }