ar9002_mac.c 11 KB

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