ar9003_mac.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * Copyright (c) 2010-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 <linux/export.h>
  17. #include "hw.h"
  18. #include "ar9003_mac.h"
  19. #include "ar9003_mci.h"
  20. static void ar9003_hw_rx_enable(struct ath_hw *hw)
  21. {
  22. REG_WRITE(hw, AR_CR, 0);
  23. }
  24. static void
  25. ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
  26. {
  27. struct ar9003_txc *ads = ds;
  28. int checksum = 0;
  29. u32 val, ctl12, ctl17;
  30. u8 desc_len;
  31. desc_len = ((AR_SREV_9462(ah) || AR_SREV_9565(ah)) ? 0x18 : 0x17);
  32. val = (ATHEROS_VENDOR_ID << AR_DescId_S) |
  33. (1 << AR_TxRxDesc_S) |
  34. (1 << AR_CtrlStat_S) |
  35. (i->qcu << AR_TxQcuNum_S) | desc_len;
  36. checksum += val;
  37. WRITE_ONCE(ads->info, val);
  38. checksum += i->link;
  39. WRITE_ONCE(ads->link, i->link);
  40. checksum += i->buf_addr[0];
  41. WRITE_ONCE(ads->data0, i->buf_addr[0]);
  42. checksum += i->buf_addr[1];
  43. WRITE_ONCE(ads->data1, i->buf_addr[1]);
  44. checksum += i->buf_addr[2];
  45. WRITE_ONCE(ads->data2, i->buf_addr[2]);
  46. checksum += i->buf_addr[3];
  47. WRITE_ONCE(ads->data3, i->buf_addr[3]);
  48. checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
  49. WRITE_ONCE(ads->ctl3, val);
  50. checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
  51. WRITE_ONCE(ads->ctl5, val);
  52. checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
  53. WRITE_ONCE(ads->ctl7, val);
  54. checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
  55. WRITE_ONCE(ads->ctl9, val);
  56. checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
  57. WRITE_ONCE(ads->ctl10, checksum);
  58. if (i->is_first || i->is_last) {
  59. WRITE_ONCE(ads->ctl13, set11nTries(i->rates, 0)
  60. | set11nTries(i->rates, 1)
  61. | set11nTries(i->rates, 2)
  62. | set11nTries(i->rates, 3)
  63. | (i->dur_update ? AR_DurUpdateEna : 0)
  64. | SM(0, AR_BurstDur));
  65. WRITE_ONCE(ads->ctl14, set11nRate(i->rates, 0)
  66. | set11nRate(i->rates, 1)
  67. | set11nRate(i->rates, 2)
  68. | set11nRate(i->rates, 3));
  69. } else {
  70. WRITE_ONCE(ads->ctl13, 0);
  71. WRITE_ONCE(ads->ctl14, 0);
  72. }
  73. ads->ctl20 = 0;
  74. ads->ctl21 = 0;
  75. ads->ctl22 = 0;
  76. ads->ctl23 = 0;
  77. ctl17 = SM(i->keytype, AR_EncrType);
  78. if (!i->is_first) {
  79. WRITE_ONCE(ads->ctl11, 0);
  80. WRITE_ONCE(ads->ctl12, i->is_last ? 0 : AR_TxMore);
  81. WRITE_ONCE(ads->ctl15, 0);
  82. WRITE_ONCE(ads->ctl16, 0);
  83. WRITE_ONCE(ads->ctl17, ctl17);
  84. WRITE_ONCE(ads->ctl18, 0);
  85. WRITE_ONCE(ads->ctl19, 0);
  86. return;
  87. }
  88. WRITE_ONCE(ads->ctl11, (i->pkt_len & AR_FrameLen)
  89. | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  90. | SM(i->txpower[0], AR_XmitPower0)
  91. | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  92. | (i->keyix != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
  93. | (i->flags & ATH9K_TXDESC_LOWRXCHAIN ? AR_LowRxChain : 0)
  94. | (i->flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
  95. | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
  96. (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0)));
  97. ctl12 = (i->keyix != ATH9K_TXKEYIX_INVALID ?
  98. SM(i->keyix, AR_DestIdx) : 0)
  99. | SM(i->type, AR_FrameType)
  100. | (i->flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  101. | (i->flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  102. | (i->flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  103. ctl17 |= (i->flags & ATH9K_TXDESC_LDPC ? AR_LDPC : 0);
  104. switch (i->aggr) {
  105. case AGGR_BUF_FIRST:
  106. ctl17 |= SM(i->aggr_len, AR_AggrLen);
  107. /* fall through */
  108. case AGGR_BUF_MIDDLE:
  109. ctl12 |= AR_IsAggr | AR_MoreAggr;
  110. ctl17 |= SM(i->ndelim, AR_PadDelim);
  111. break;
  112. case AGGR_BUF_LAST:
  113. ctl12 |= AR_IsAggr;
  114. break;
  115. case AGGR_BUF_NONE:
  116. break;
  117. }
  118. val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
  119. ctl12 |= SM(val, AR_PAPRDChainMask);
  120. WRITE_ONCE(ads->ctl12, ctl12);
  121. WRITE_ONCE(ads->ctl17, ctl17);
  122. WRITE_ONCE(ads->ctl15, set11nPktDurRTSCTS(i->rates, 0)
  123. | set11nPktDurRTSCTS(i->rates, 1));
  124. WRITE_ONCE(ads->ctl16, set11nPktDurRTSCTS(i->rates, 2)
  125. | set11nPktDurRTSCTS(i->rates, 3));
  126. WRITE_ONCE(ads->ctl18, set11nRateFlags(i->rates, 0)
  127. | set11nRateFlags(i->rates, 1)
  128. | set11nRateFlags(i->rates, 2)
  129. | set11nRateFlags(i->rates, 3)
  130. | SM(i->rtscts_rate, AR_RTSCTSRate));
  131. WRITE_ONCE(ads->ctl19, AR_Not_Sounding);
  132. WRITE_ONCE(ads->ctl20, SM(i->txpower[1], AR_XmitPower1));
  133. WRITE_ONCE(ads->ctl21, SM(i->txpower[2], AR_XmitPower2));
  134. WRITE_ONCE(ads->ctl22, SM(i->txpower[3], AR_XmitPower3));
  135. }
  136. static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
  137. {
  138. int checksum;
  139. checksum = ads->info + ads->link
  140. + ads->data0 + ads->ctl3
  141. + ads->data1 + ads->ctl5
  142. + ads->data2 + ads->ctl7
  143. + ads->data3 + ads->ctl9;
  144. return ((checksum & 0xffff) + (checksum >> 16)) & AR_TxPtrChkSum;
  145. }
  146. static void ar9003_hw_set_desc_link(void *ds, u32 ds_link)
  147. {
  148. struct ar9003_txc *ads = ds;
  149. ads->link = ds_link;
  150. ads->ctl10 &= ~AR_TxPtrChkSum;
  151. ads->ctl10 |= ar9003_calc_ptr_chksum(ads);
  152. }
  153. static bool ar9003_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked,
  154. u32 *sync_cause_p)
  155. {
  156. u32 isr = 0;
  157. u32 mask2 = 0;
  158. struct ath9k_hw_capabilities *pCap = &ah->caps;
  159. struct ath_common *common = ath9k_hw_common(ah);
  160. u32 sync_cause = 0, async_cause, async_mask = AR_INTR_MAC_IRQ;
  161. bool fatal_int;
  162. if (ath9k_hw_mci_is_enabled(ah))
  163. async_mask |= AR_INTR_ASYNC_MASK_MCI;
  164. async_cause = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  165. if (async_cause & async_mask) {
  166. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  167. == AR_RTC_STATUS_ON)
  168. isr = REG_READ(ah, AR_ISR);
  169. }
  170. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & AR_INTR_SYNC_DEFAULT;
  171. *masked = 0;
  172. if (!isr && !sync_cause && !async_cause)
  173. return false;
  174. if (isr) {
  175. if (isr & AR_ISR_BCNMISC) {
  176. u32 isr2;
  177. isr2 = REG_READ(ah, AR_ISR_S2);
  178. mask2 |= ((isr2 & AR_ISR_S2_TIM) >>
  179. MAP_ISR_S2_TIM);
  180. mask2 |= ((isr2 & AR_ISR_S2_DTIM) >>
  181. MAP_ISR_S2_DTIM);
  182. mask2 |= ((isr2 & AR_ISR_S2_DTIMSYNC) >>
  183. MAP_ISR_S2_DTIMSYNC);
  184. mask2 |= ((isr2 & AR_ISR_S2_CABEND) >>
  185. MAP_ISR_S2_CABEND);
  186. mask2 |= ((isr2 & AR_ISR_S2_GTT) <<
  187. MAP_ISR_S2_GTT);
  188. mask2 |= ((isr2 & AR_ISR_S2_CST) <<
  189. MAP_ISR_S2_CST);
  190. mask2 |= ((isr2 & AR_ISR_S2_TSFOOR) >>
  191. MAP_ISR_S2_TSFOOR);
  192. mask2 |= ((isr2 & AR_ISR_S2_BB_WATCHDOG) >>
  193. MAP_ISR_S2_BB_WATCHDOG);
  194. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  195. REG_WRITE(ah, AR_ISR_S2, isr2);
  196. isr &= ~AR_ISR_BCNMISC;
  197. }
  198. }
  199. if ((pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED))
  200. isr = REG_READ(ah, AR_ISR_RAC);
  201. if (isr == 0xffffffff) {
  202. *masked = 0;
  203. return false;
  204. }
  205. *masked = isr & ATH9K_INT_COMMON;
  206. if (ah->config.rx_intr_mitigation)
  207. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  208. *masked |= ATH9K_INT_RXLP;
  209. if (ah->config.tx_intr_mitigation)
  210. if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM))
  211. *masked |= ATH9K_INT_TX;
  212. if (isr & (AR_ISR_LP_RXOK | AR_ISR_RXERR))
  213. *masked |= ATH9K_INT_RXLP;
  214. if (isr & AR_ISR_HP_RXOK)
  215. *masked |= ATH9K_INT_RXHP;
  216. if (isr & (AR_ISR_TXOK | AR_ISR_TXERR | AR_ISR_TXEOL)) {
  217. *masked |= ATH9K_INT_TX;
  218. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  219. u32 s0, s1;
  220. s0 = REG_READ(ah, AR_ISR_S0);
  221. REG_WRITE(ah, AR_ISR_S0, s0);
  222. s1 = REG_READ(ah, AR_ISR_S1);
  223. REG_WRITE(ah, AR_ISR_S1, s1);
  224. isr &= ~(AR_ISR_TXOK | AR_ISR_TXERR |
  225. AR_ISR_TXEOL);
  226. }
  227. }
  228. if (isr & AR_ISR_GENTMR) {
  229. u32 s5;
  230. if (pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)
  231. s5 = REG_READ(ah, AR_ISR_S5_S);
  232. else
  233. s5 = REG_READ(ah, AR_ISR_S5);
  234. ah->intr_gen_timer_trigger =
  235. MS(s5, AR_ISR_S5_GENTIMER_TRIG);
  236. ah->intr_gen_timer_thresh =
  237. MS(s5, AR_ISR_S5_GENTIMER_THRESH);
  238. if (ah->intr_gen_timer_trigger)
  239. *masked |= ATH9K_INT_GENTIMER;
  240. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  241. REG_WRITE(ah, AR_ISR_S5, s5);
  242. isr &= ~AR_ISR_GENTMR;
  243. }
  244. }
  245. *masked |= mask2;
  246. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  247. REG_WRITE(ah, AR_ISR, isr);
  248. (void) REG_READ(ah, AR_ISR);
  249. }
  250. if (*masked & ATH9K_INT_BB_WATCHDOG)
  251. ar9003_hw_bb_watchdog_read(ah);
  252. }
  253. if (async_cause & AR_INTR_ASYNC_MASK_MCI)
  254. ar9003_mci_get_isr(ah, masked);
  255. if (sync_cause) {
  256. if (sync_cause_p)
  257. *sync_cause_p = sync_cause;
  258. fatal_int =
  259. (sync_cause &
  260. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  261. ? true : false;
  262. if (fatal_int) {
  263. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  264. ath_dbg(common, ANY,
  265. "received PCI FATAL interrupt\n");
  266. }
  267. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  268. ath_dbg(common, ANY,
  269. "received PCI PERR interrupt\n");
  270. }
  271. *masked |= ATH9K_INT_FATAL;
  272. }
  273. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  274. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  275. REG_WRITE(ah, AR_RC, 0);
  276. *masked |= ATH9K_INT_FATAL;
  277. }
  278. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
  279. ath_dbg(common, INTERRUPT,
  280. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  281. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  282. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  283. }
  284. return true;
  285. }
  286. static int ar9003_hw_proc_txdesc(struct ath_hw *ah, void *ds,
  287. struct ath_tx_status *ts)
  288. {
  289. struct ar9003_txs *ads;
  290. u32 status;
  291. ads = &ah->ts_ring[ah->ts_tail];
  292. status = READ_ONCE(ads->status8);
  293. if ((status & AR_TxDone) == 0)
  294. return -EINPROGRESS;
  295. ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size;
  296. if ((MS(ads->ds_info, AR_DescId) != ATHEROS_VENDOR_ID) ||
  297. (MS(ads->ds_info, AR_TxRxDesc) != 1)) {
  298. ath_dbg(ath9k_hw_common(ah), XMIT,
  299. "Tx Descriptor error %x\n", ads->ds_info);
  300. memset(ads, 0, sizeof(*ads));
  301. return -EIO;
  302. }
  303. ts->ts_rateindex = MS(status, AR_FinalTxIdx);
  304. ts->ts_seqnum = MS(status, AR_SeqNum);
  305. ts->tid = MS(status, AR_TxTid);
  306. ts->qid = MS(ads->ds_info, AR_TxQcuNum);
  307. ts->desc_id = MS(ads->status1, AR_TxDescId);
  308. ts->ts_tstamp = ads->status4;
  309. ts->ts_status = 0;
  310. ts->ts_flags = 0;
  311. if (status & AR_TxOpExceeded)
  312. ts->ts_status |= ATH9K_TXERR_XTXOP;
  313. status = READ_ONCE(ads->status2);
  314. ts->ts_rssi_ctl0 = MS(status, AR_TxRSSIAnt00);
  315. ts->ts_rssi_ctl1 = MS(status, AR_TxRSSIAnt01);
  316. ts->ts_rssi_ctl2 = MS(status, AR_TxRSSIAnt02);
  317. if (status & AR_TxBaStatus) {
  318. ts->ts_flags |= ATH9K_TX_BA;
  319. ts->ba_low = ads->status5;
  320. ts->ba_high = ads->status6;
  321. }
  322. status = READ_ONCE(ads->status3);
  323. if (status & AR_ExcessiveRetries)
  324. ts->ts_status |= ATH9K_TXERR_XRETRY;
  325. if (status & AR_Filtered)
  326. ts->ts_status |= ATH9K_TXERR_FILT;
  327. if (status & AR_FIFOUnderrun) {
  328. ts->ts_status |= ATH9K_TXERR_FIFO;
  329. ath9k_hw_updatetxtriglevel(ah, true);
  330. }
  331. if (status & AR_TxTimerExpired)
  332. ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  333. if (status & AR_DescCfgErr)
  334. ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  335. if (status & AR_TxDataUnderrun) {
  336. ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  337. ath9k_hw_updatetxtriglevel(ah, true);
  338. }
  339. if (status & AR_TxDelimUnderrun) {
  340. ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  341. ath9k_hw_updatetxtriglevel(ah, true);
  342. }
  343. ts->ts_shortretry = MS(status, AR_RTSFailCnt);
  344. ts->ts_longretry = MS(status, AR_DataFailCnt);
  345. ts->ts_virtcol = MS(status, AR_VirtRetryCnt);
  346. status = READ_ONCE(ads->status7);
  347. ts->ts_rssi = MS(status, AR_TxRSSICombined);
  348. ts->ts_rssi_ext0 = MS(status, AR_TxRSSIAnt10);
  349. ts->ts_rssi_ext1 = MS(status, AR_TxRSSIAnt11);
  350. ts->ts_rssi_ext2 = MS(status, AR_TxRSSIAnt12);
  351. memset(ads, 0, sizeof(*ads));
  352. return 0;
  353. }
  354. static int ar9003_hw_get_duration(struct ath_hw *ah, const void *ds, int index)
  355. {
  356. const struct ar9003_txc *adc = ds;
  357. switch (index) {
  358. case 0:
  359. return MS(READ_ONCE(adc->ctl15), AR_PacketDur0);
  360. case 1:
  361. return MS(READ_ONCE(adc->ctl15), AR_PacketDur1);
  362. case 2:
  363. return MS(READ_ONCE(adc->ctl16), AR_PacketDur2);
  364. case 3:
  365. return MS(READ_ONCE(adc->ctl16), AR_PacketDur3);
  366. default:
  367. return 0;
  368. }
  369. }
  370. void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
  371. {
  372. struct ath_hw_ops *ops = ath9k_hw_ops(hw);
  373. ops->rx_enable = ar9003_hw_rx_enable;
  374. ops->set_desc_link = ar9003_hw_set_desc_link;
  375. ops->get_isr = ar9003_hw_get_isr;
  376. ops->set_txdesc = ar9003_set_txdesc;
  377. ops->proc_txdesc = ar9003_hw_proc_txdesc;
  378. ops->get_duration = ar9003_hw_get_duration;
  379. }
  380. void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
  381. {
  382. REG_WRITE(ah, AR_DATABUF_SIZE, buf_size & AR_DATABUF_SIZE_MASK);
  383. }
  384. EXPORT_SYMBOL(ath9k_hw_set_rx_bufsize);
  385. void ath9k_hw_addrxbuf_edma(struct ath_hw *ah, u32 rxdp,
  386. enum ath9k_rx_qtype qtype)
  387. {
  388. if (qtype == ATH9K_RX_QUEUE_HP)
  389. REG_WRITE(ah, AR_HP_RXDP, rxdp);
  390. else
  391. REG_WRITE(ah, AR_LP_RXDP, rxdp);
  392. }
  393. EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma);
  394. int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs,
  395. void *buf_addr)
  396. {
  397. struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr;
  398. unsigned int phyerr;
  399. if ((rxsp->status11 & AR_RxDone) == 0)
  400. return -EINPROGRESS;
  401. if (MS(rxsp->ds_info, AR_DescId) != 0x168c)
  402. return -EINVAL;
  403. if ((rxsp->ds_info & (AR_TxRxDesc | AR_CtrlStat)) != 0)
  404. return -EINPROGRESS;
  405. rxs->rs_status = 0;
  406. rxs->rs_flags = 0;
  407. rxs->enc_flags = 0;
  408. rxs->bw = RATE_INFO_BW_20;
  409. rxs->rs_datalen = rxsp->status2 & AR_DataLen;
  410. rxs->rs_tstamp = rxsp->status3;
  411. /* XXX: Keycache */
  412. rxs->rs_rssi = MS(rxsp->status5, AR_RxRSSICombined);
  413. rxs->rs_rssi_ctl[0] = MS(rxsp->status1, AR_RxRSSIAnt00);
  414. rxs->rs_rssi_ctl[1] = MS(rxsp->status1, AR_RxRSSIAnt01);
  415. rxs->rs_rssi_ctl[2] = MS(rxsp->status1, AR_RxRSSIAnt02);
  416. rxs->rs_rssi_ext[0] = MS(rxsp->status5, AR_RxRSSIAnt10);
  417. rxs->rs_rssi_ext[1] = MS(rxsp->status5, AR_RxRSSIAnt11);
  418. rxs->rs_rssi_ext[2] = MS(rxsp->status5, AR_RxRSSIAnt12);
  419. if (rxsp->status11 & AR_RxKeyIdxValid)
  420. rxs->rs_keyix = MS(rxsp->status11, AR_KeyIdx);
  421. else
  422. rxs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  423. rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
  424. rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
  425. rxs->rs_firstaggr = (rxsp->status11 & AR_RxFirstAggr) ? 1 : 0;
  426. rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
  427. rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
  428. rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
  429. rxs->enc_flags |= (rxsp->status4 & AR_GI) ? RX_ENC_FLAG_SHORT_GI : 0;
  430. rxs->bw = (rxsp->status4 & AR_2040) ? RATE_INFO_BW_40 : RATE_INFO_BW_20;
  431. rxs->evm0 = rxsp->status6;
  432. rxs->evm1 = rxsp->status7;
  433. rxs->evm2 = rxsp->status8;
  434. rxs->evm3 = rxsp->status9;
  435. rxs->evm4 = (rxsp->status10 & 0xffff);
  436. if (rxsp->status11 & AR_PreDelimCRCErr)
  437. rxs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  438. if (rxsp->status11 & AR_PostDelimCRCErr)
  439. rxs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  440. if (rxsp->status11 & AR_DecryptBusyErr)
  441. rxs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  442. if ((rxsp->status11 & AR_RxFrameOK) == 0) {
  443. /*
  444. * AR_CRCErr will bet set to true if we're on the last
  445. * subframe and the AR_PostDelimCRCErr is caught.
  446. * In a way this also gives us a guarantee that when
  447. * (!(AR_CRCErr) && (AR_PostDelimCRCErr)) we cannot
  448. * possibly be reviewing the last subframe. AR_CRCErr
  449. * is the CRC of the actual data.
  450. */
  451. if (rxsp->status11 & AR_CRCErr)
  452. rxs->rs_status |= ATH9K_RXERR_CRC;
  453. else if (rxsp->status11 & AR_DecryptCRCErr)
  454. rxs->rs_status |= ATH9K_RXERR_DECRYPT;
  455. else if (rxsp->status11 & AR_MichaelErr)
  456. rxs->rs_status |= ATH9K_RXERR_MIC;
  457. if (rxsp->status11 & AR_PHYErr) {
  458. phyerr = MS(rxsp->status11, AR_PHYErrCode);
  459. /*
  460. * If we reach a point here where AR_PostDelimCRCErr is
  461. * true it implies we're *not* on the last subframe. In
  462. * in that case that we know already that the CRC of
  463. * the frame was OK, and MAC would send an ACK for that
  464. * subframe, even if we did get a phy error of type
  465. * ATH9K_PHYERR_OFDM_RESTART. This is only applicable
  466. * to frame that are prior to the last subframe.
  467. * The AR_PostDelimCRCErr is the CRC for the MPDU
  468. * delimiter, which contains the 4 reserved bits,
  469. * the MPDU length (12 bits), and follows the MPDU
  470. * delimiter for an A-MPDU subframe (0x4E = 'N' ASCII).
  471. */
  472. if ((phyerr == ATH9K_PHYERR_OFDM_RESTART) &&
  473. (rxsp->status11 & AR_PostDelimCRCErr)) {
  474. rxs->rs_phyerr = 0;
  475. } else {
  476. rxs->rs_status |= ATH9K_RXERR_PHY;
  477. rxs->rs_phyerr = phyerr;
  478. }
  479. }
  480. }
  481. if (rxsp->status11 & AR_KeyMiss)
  482. rxs->rs_status |= ATH9K_RXERR_KEYMISS;
  483. return 0;
  484. }
  485. EXPORT_SYMBOL(ath9k_hw_process_rxdesc_edma);
  486. void ath9k_hw_reset_txstatus_ring(struct ath_hw *ah)
  487. {
  488. ah->ts_tail = 0;
  489. memset((void *) ah->ts_ring, 0,
  490. ah->ts_size * sizeof(struct ar9003_txs));
  491. ath_dbg(ath9k_hw_common(ah), XMIT,
  492. "TS Start 0x%x End 0x%x Virt %p, Size %d\n",
  493. ah->ts_paddr_start, ah->ts_paddr_end,
  494. ah->ts_ring, ah->ts_size);
  495. REG_WRITE(ah, AR_Q_STATUS_RING_START, ah->ts_paddr_start);
  496. REG_WRITE(ah, AR_Q_STATUS_RING_END, ah->ts_paddr_end);
  497. }
  498. void ath9k_hw_setup_statusring(struct ath_hw *ah, void *ts_start,
  499. u32 ts_paddr_start,
  500. u16 size)
  501. {
  502. ah->ts_paddr_start = ts_paddr_start;
  503. ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs));
  504. ah->ts_size = size;
  505. ah->ts_ring = (struct ar9003_txs *) ts_start;
  506. ath9k_hw_reset_txstatus_ring(ah);
  507. }
  508. EXPORT_SYMBOL(ath9k_hw_setup_statusring);