ar9002_mac.c 12 KB

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