ar9003_mac.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * Copyright (c) 2010 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 "ar9003_mac.h"
  18. static void ar9003_hw_rx_enable(struct ath_hw *hw)
  19. {
  20. REG_WRITE(hw, AR_CR, 0);
  21. }
  22. static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
  23. {
  24. int checksum;
  25. checksum = ads->info + ads->link
  26. + ads->data0 + ads->ctl3
  27. + ads->data1 + ads->ctl5
  28. + ads->data2 + ads->ctl7
  29. + ads->data3 + ads->ctl9;
  30. return ((checksum & 0xffff) + (checksum >> 16)) & AR_TxPtrChkSum;
  31. }
  32. static void ar9003_hw_set_desc_link(void *ds, u32 ds_link)
  33. {
  34. struct ar9003_txc *ads = ds;
  35. ads->link = ds_link;
  36. ads->ctl10 &= ~AR_TxPtrChkSum;
  37. ads->ctl10 |= ar9003_calc_ptr_chksum(ads);
  38. }
  39. static void ar9003_hw_get_desc_link(void *ds, u32 **ds_link)
  40. {
  41. struct ar9003_txc *ads = ds;
  42. *ds_link = &ads->link;
  43. }
  44. static bool ar9003_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
  45. {
  46. u32 isr = 0;
  47. u32 mask2 = 0;
  48. struct ath9k_hw_capabilities *pCap = &ah->caps;
  49. u32 sync_cause = 0;
  50. struct ath_common *common = ath9k_hw_common(ah);
  51. if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
  52. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  53. == AR_RTC_STATUS_ON)
  54. isr = REG_READ(ah, AR_ISR);
  55. }
  56. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & AR_INTR_SYNC_DEFAULT;
  57. *masked = 0;
  58. if (!isr && !sync_cause)
  59. return false;
  60. if (isr) {
  61. if (isr & AR_ISR_BCNMISC) {
  62. u32 isr2;
  63. isr2 = REG_READ(ah, AR_ISR_S2);
  64. mask2 |= ((isr2 & AR_ISR_S2_TIM) >>
  65. MAP_ISR_S2_TIM);
  66. mask2 |= ((isr2 & AR_ISR_S2_DTIM) >>
  67. MAP_ISR_S2_DTIM);
  68. mask2 |= ((isr2 & AR_ISR_S2_DTIMSYNC) >>
  69. MAP_ISR_S2_DTIMSYNC);
  70. mask2 |= ((isr2 & AR_ISR_S2_CABEND) >>
  71. MAP_ISR_S2_CABEND);
  72. mask2 |= ((isr2 & AR_ISR_S2_GTT) <<
  73. MAP_ISR_S2_GTT);
  74. mask2 |= ((isr2 & AR_ISR_S2_CST) <<
  75. MAP_ISR_S2_CST);
  76. mask2 |= ((isr2 & AR_ISR_S2_TSFOOR) >>
  77. MAP_ISR_S2_TSFOOR);
  78. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  79. REG_WRITE(ah, AR_ISR_S2, isr2);
  80. isr &= ~AR_ISR_BCNMISC;
  81. }
  82. }
  83. if ((pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED))
  84. isr = REG_READ(ah, AR_ISR_RAC);
  85. if (isr == 0xffffffff) {
  86. *masked = 0;
  87. return false;
  88. }
  89. *masked = isr & ATH9K_INT_COMMON;
  90. if (ah->config.rx_intr_mitigation)
  91. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  92. *masked |= ATH9K_INT_RXLP;
  93. if (ah->config.tx_intr_mitigation)
  94. if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM))
  95. *masked |= ATH9K_INT_TX;
  96. if (isr & (AR_ISR_LP_RXOK | AR_ISR_RXERR))
  97. *masked |= ATH9K_INT_RXLP;
  98. if (isr & AR_ISR_HP_RXOK)
  99. *masked |= ATH9K_INT_RXHP;
  100. if (isr & (AR_ISR_TXOK | AR_ISR_TXERR | AR_ISR_TXEOL)) {
  101. *masked |= ATH9K_INT_TX;
  102. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  103. u32 s0, s1;
  104. s0 = REG_READ(ah, AR_ISR_S0);
  105. REG_WRITE(ah, AR_ISR_S0, s0);
  106. s1 = REG_READ(ah, AR_ISR_S1);
  107. REG_WRITE(ah, AR_ISR_S1, s1);
  108. isr &= ~(AR_ISR_TXOK | AR_ISR_TXERR |
  109. AR_ISR_TXEOL);
  110. }
  111. }
  112. if (isr & AR_ISR_GENTMR) {
  113. u32 s5;
  114. if (pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)
  115. s5 = REG_READ(ah, AR_ISR_S5_S);
  116. else
  117. s5 = REG_READ(ah, AR_ISR_S5);
  118. ah->intr_gen_timer_trigger =
  119. MS(s5, AR_ISR_S5_GENTIMER_TRIG);
  120. ah->intr_gen_timer_thresh =
  121. MS(s5, AR_ISR_S5_GENTIMER_THRESH);
  122. if (ah->intr_gen_timer_trigger)
  123. *masked |= ATH9K_INT_GENTIMER;
  124. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  125. REG_WRITE(ah, AR_ISR_S5, s5);
  126. isr &= ~AR_ISR_GENTMR;
  127. }
  128. }
  129. *masked |= mask2;
  130. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  131. REG_WRITE(ah, AR_ISR, isr);
  132. (void) REG_READ(ah, AR_ISR);
  133. }
  134. }
  135. if (sync_cause) {
  136. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  137. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  138. REG_WRITE(ah, AR_RC, 0);
  139. *masked |= ATH9K_INT_FATAL;
  140. }
  141. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
  142. ath_print(common, ATH_DBG_INTERRUPT,
  143. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  144. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  145. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  146. }
  147. return true;
  148. }
  149. static void ar9003_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen,
  150. bool is_firstseg, bool is_lastseg,
  151. const void *ds0, dma_addr_t buf_addr,
  152. unsigned int qcu)
  153. {
  154. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  155. unsigned int descid = 0;
  156. ads->info = (ATHEROS_VENDOR_ID << AR_DescId_S) |
  157. (1 << AR_TxRxDesc_S) |
  158. (1 << AR_CtrlStat_S) |
  159. (qcu << AR_TxQcuNum_S) | 0x17;
  160. ads->data0 = buf_addr;
  161. ads->data1 = 0;
  162. ads->data2 = 0;
  163. ads->data3 = 0;
  164. ads->ctl3 = (seglen << AR_BufLen_S);
  165. ads->ctl3 &= AR_BufLen;
  166. /* Fill in pointer checksum and descriptor id */
  167. ads->ctl10 = ar9003_calc_ptr_chksum(ads);
  168. ads->ctl10 |= (descid << AR_TxDescId_S);
  169. if (is_firstseg) {
  170. ads->ctl12 |= (is_lastseg ? 0 : AR_TxMore);
  171. } else if (is_lastseg) {
  172. ads->ctl11 = 0;
  173. ads->ctl12 = 0;
  174. ads->ctl13 = AR9003TXC_CONST(ds0)->ctl13;
  175. ads->ctl14 = AR9003TXC_CONST(ds0)->ctl14;
  176. } else {
  177. /* XXX Intermediate descriptor in a multi-descriptor frame.*/
  178. ads->ctl11 = 0;
  179. ads->ctl12 = AR_TxMore;
  180. ads->ctl13 = 0;
  181. ads->ctl14 = 0;
  182. }
  183. }
  184. static int ar9003_hw_proc_txdesc(struct ath_hw *ah, void *ds,
  185. struct ath_tx_status *ts)
  186. {
  187. struct ar9003_txs *ads;
  188. ads = &ah->ts_ring[ah->ts_tail];
  189. if ((ads->status8 & AR_TxDone) == 0)
  190. return -EINPROGRESS;
  191. ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size;
  192. if ((MS(ads->ds_info, AR_DescId) != ATHEROS_VENDOR_ID) ||
  193. (MS(ads->ds_info, AR_TxRxDesc) != 1)) {
  194. ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
  195. "Tx Descriptor error %x\n", ads->ds_info);
  196. memset(ads, 0, sizeof(*ads));
  197. return -EIO;
  198. }
  199. ts->qid = MS(ads->ds_info, AR_TxQcuNum);
  200. ts->desc_id = MS(ads->status1, AR_TxDescId);
  201. ts->ts_seqnum = MS(ads->status8, AR_SeqNum);
  202. ts->ts_tstamp = ads->status4;
  203. ts->ts_status = 0;
  204. ts->ts_flags = 0;
  205. if (ads->status3 & AR_ExcessiveRetries)
  206. ts->ts_status |= ATH9K_TXERR_XRETRY;
  207. if (ads->status3 & AR_Filtered)
  208. ts->ts_status |= ATH9K_TXERR_FILT;
  209. if (ads->status3 & AR_FIFOUnderrun) {
  210. ts->ts_status |= ATH9K_TXERR_FIFO;
  211. ath9k_hw_updatetxtriglevel(ah, true);
  212. }
  213. if (ads->status8 & AR_TxOpExceeded)
  214. ts->ts_status |= ATH9K_TXERR_XTXOP;
  215. if (ads->status3 & AR_TxTimerExpired)
  216. ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  217. if (ads->status3 & AR_DescCfgErr)
  218. ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  219. if (ads->status3 & AR_TxDataUnderrun) {
  220. ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  221. ath9k_hw_updatetxtriglevel(ah, true);
  222. }
  223. if (ads->status3 & AR_TxDelimUnderrun) {
  224. ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  225. ath9k_hw_updatetxtriglevel(ah, true);
  226. }
  227. if (ads->status2 & AR_TxBaStatus) {
  228. ts->ts_flags |= ATH9K_TX_BA;
  229. ts->ba_low = ads->status5;
  230. ts->ba_high = ads->status6;
  231. }
  232. ts->ts_rateindex = MS(ads->status8, AR_FinalTxIdx);
  233. ts->ts_rssi = MS(ads->status7, AR_TxRSSICombined);
  234. ts->ts_rssi_ctl0 = MS(ads->status2, AR_TxRSSIAnt00);
  235. ts->ts_rssi_ctl1 = MS(ads->status2, AR_TxRSSIAnt01);
  236. ts->ts_rssi_ctl2 = MS(ads->status2, AR_TxRSSIAnt02);
  237. ts->ts_rssi_ext0 = MS(ads->status7, AR_TxRSSIAnt10);
  238. ts->ts_rssi_ext1 = MS(ads->status7, AR_TxRSSIAnt11);
  239. ts->ts_rssi_ext2 = MS(ads->status7, AR_TxRSSIAnt12);
  240. ts->ts_shortretry = MS(ads->status3, AR_RTSFailCnt);
  241. ts->ts_longretry = MS(ads->status3, AR_DataFailCnt);
  242. ts->ts_virtcol = MS(ads->status3, AR_VirtRetryCnt);
  243. ts->ts_antenna = 0;
  244. ts->tid = MS(ads->status8, AR_TxTid);
  245. memset(ads, 0, sizeof(*ads));
  246. return 0;
  247. }
  248. static void ar9003_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
  249. u32 pktlen, enum ath9k_pkt_type type, u32 txpower,
  250. u32 keyIx, enum ath9k_key_type keyType, u32 flags)
  251. {
  252. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  253. if (txpower > ah->txpower_limit)
  254. txpower = ah->txpower_limit;
  255. txpower += ah->txpower_indexoffset;
  256. if (txpower > 63)
  257. txpower = 63;
  258. ads->ctl11 = (pktlen & AR_FrameLen)
  259. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  260. | SM(txpower, AR_XmitPower)
  261. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  262. | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
  263. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
  264. | (flags & ATH9K_TXDESC_LOWRXCHAIN ? AR_LowRxChain : 0);
  265. ads->ctl12 =
  266. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  267. | SM(type, AR_FrameType)
  268. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  269. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  270. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  271. ads->ctl17 = SM(keyType, AR_EncrType) |
  272. (flags & ATH9K_TXDESC_LDPC ? AR_LDPC : 0);
  273. ads->ctl18 = 0;
  274. ads->ctl19 = AR_Not_Sounding;
  275. ads->ctl20 = 0;
  276. ads->ctl21 = 0;
  277. ads->ctl22 = 0;
  278. }
  279. static void ar9003_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
  280. void *lastds,
  281. u32 durUpdateEn, u32 rtsctsRate,
  282. u32 rtsctsDuration,
  283. struct ath9k_11n_rate_series series[],
  284. u32 nseries, u32 flags)
  285. {
  286. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  287. struct ar9003_txc *last_ads = (struct ar9003_txc *) lastds;
  288. u_int32_t ctl11;
  289. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  290. ctl11 = ads->ctl11;
  291. if (flags & ATH9K_TXDESC_RTSENA) {
  292. ctl11 &= ~AR_CTSEnable;
  293. ctl11 |= AR_RTSEnable;
  294. } else {
  295. ctl11 &= ~AR_RTSEnable;
  296. ctl11 |= AR_CTSEnable;
  297. }
  298. ads->ctl11 = ctl11;
  299. } else {
  300. ads->ctl11 = (ads->ctl11 & ~(AR_RTSEnable | AR_CTSEnable));
  301. }
  302. ads->ctl13 = set11nTries(series, 0)
  303. | set11nTries(series, 1)
  304. | set11nTries(series, 2)
  305. | set11nTries(series, 3)
  306. | (durUpdateEn ? AR_DurUpdateEna : 0)
  307. | SM(0, AR_BurstDur);
  308. ads->ctl14 = set11nRate(series, 0)
  309. | set11nRate(series, 1)
  310. | set11nRate(series, 2)
  311. | set11nRate(series, 3);
  312. ads->ctl15 = set11nPktDurRTSCTS(series, 0)
  313. | set11nPktDurRTSCTS(series, 1);
  314. ads->ctl16 = set11nPktDurRTSCTS(series, 2)
  315. | set11nPktDurRTSCTS(series, 3);
  316. ads->ctl18 = set11nRateFlags(series, 0)
  317. | set11nRateFlags(series, 1)
  318. | set11nRateFlags(series, 2)
  319. | set11nRateFlags(series, 3)
  320. | SM(rtsctsRate, AR_RTSCTSRate);
  321. ads->ctl19 = AR_Not_Sounding;
  322. last_ads->ctl13 = ads->ctl13;
  323. last_ads->ctl14 = ads->ctl14;
  324. }
  325. static void ar9003_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
  326. u32 aggrLen)
  327. {
  328. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  329. ads->ctl12 |= (AR_IsAggr | AR_MoreAggr);
  330. ads->ctl17 &= ~AR_AggrLen;
  331. ads->ctl17 |= SM(aggrLen, AR_AggrLen);
  332. }
  333. static void ar9003_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
  334. u32 numDelims)
  335. {
  336. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  337. unsigned int ctl17;
  338. ads->ctl12 |= (AR_IsAggr | AR_MoreAggr);
  339. /*
  340. * We use a stack variable to manipulate ctl6 to reduce uncached
  341. * read modify, modfiy, write.
  342. */
  343. ctl17 = ads->ctl17;
  344. ctl17 &= ~AR_PadDelim;
  345. ctl17 |= SM(numDelims, AR_PadDelim);
  346. ads->ctl17 = ctl17;
  347. }
  348. static void ar9003_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
  349. {
  350. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  351. ads->ctl12 |= AR_IsAggr;
  352. ads->ctl12 &= ~AR_MoreAggr;
  353. ads->ctl17 &= ~AR_PadDelim;
  354. }
  355. static void ar9003_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
  356. {
  357. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  358. ads->ctl12 &= (~AR_IsAggr & ~AR_MoreAggr);
  359. }
  360. static void ar9003_hw_set11n_burstduration(struct ath_hw *ah, void *ds,
  361. u32 burstDuration)
  362. {
  363. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  364. ads->ctl13 &= ~AR_BurstDur;
  365. ads->ctl13 |= SM(burstDuration, AR_BurstDur);
  366. }
  367. static void ar9003_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
  368. u32 vmf)
  369. {
  370. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  371. if (vmf)
  372. ads->ctl11 |= AR_VirtMoreFrag;
  373. else
  374. ads->ctl11 &= ~AR_VirtMoreFrag;
  375. }
  376. void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
  377. {
  378. struct ath_hw_ops *ops = ath9k_hw_ops(hw);
  379. ops->rx_enable = ar9003_hw_rx_enable;
  380. ops->set_desc_link = ar9003_hw_set_desc_link;
  381. ops->get_desc_link = ar9003_hw_get_desc_link;
  382. ops->get_isr = ar9003_hw_get_isr;
  383. ops->fill_txdesc = ar9003_hw_fill_txdesc;
  384. ops->proc_txdesc = ar9003_hw_proc_txdesc;
  385. ops->set11n_txdesc = ar9003_hw_set11n_txdesc;
  386. ops->set11n_ratescenario = ar9003_hw_set11n_ratescenario;
  387. ops->set11n_aggr_first = ar9003_hw_set11n_aggr_first;
  388. ops->set11n_aggr_middle = ar9003_hw_set11n_aggr_middle;
  389. ops->set11n_aggr_last = ar9003_hw_set11n_aggr_last;
  390. ops->clr11n_aggr = ar9003_hw_clr11n_aggr;
  391. ops->set11n_burstduration = ar9003_hw_set11n_burstduration;
  392. ops->set11n_virtualmorefrag = ar9003_hw_set11n_virtualmorefrag;
  393. }
  394. void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
  395. {
  396. REG_WRITE(ah, AR_DATABUF_SIZE, buf_size & AR_DATABUF_SIZE_MASK);
  397. }
  398. EXPORT_SYMBOL(ath9k_hw_set_rx_bufsize);
  399. void ath9k_hw_addrxbuf_edma(struct ath_hw *ah, u32 rxdp,
  400. enum ath9k_rx_qtype qtype)
  401. {
  402. if (qtype == ATH9K_RX_QUEUE_HP)
  403. REG_WRITE(ah, AR_HP_RXDP, rxdp);
  404. else
  405. REG_WRITE(ah, AR_LP_RXDP, rxdp);
  406. }
  407. EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma);
  408. int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs,
  409. void *buf_addr)
  410. {
  411. struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr;
  412. unsigned int phyerr;
  413. /* TODO: byte swap on big endian for ar9300_10 */
  414. if ((rxsp->status11 & AR_RxDone) == 0)
  415. return -EINPROGRESS;
  416. if (MS(rxsp->ds_info, AR_DescId) != 0x168c)
  417. return -EINVAL;
  418. if ((rxsp->ds_info & (AR_TxRxDesc | AR_CtrlStat)) != 0)
  419. return -EINPROGRESS;
  420. if (!rxs)
  421. return 0;
  422. rxs->rs_status = 0;
  423. rxs->rs_flags = 0;
  424. rxs->rs_datalen = rxsp->status2 & AR_DataLen;
  425. rxs->rs_tstamp = rxsp->status3;
  426. /* XXX: Keycache */
  427. rxs->rs_rssi = MS(rxsp->status5, AR_RxRSSICombined);
  428. rxs->rs_rssi_ctl0 = MS(rxsp->status1, AR_RxRSSIAnt00);
  429. rxs->rs_rssi_ctl1 = MS(rxsp->status1, AR_RxRSSIAnt01);
  430. rxs->rs_rssi_ctl2 = MS(rxsp->status1, AR_RxRSSIAnt02);
  431. rxs->rs_rssi_ext0 = MS(rxsp->status5, AR_RxRSSIAnt10);
  432. rxs->rs_rssi_ext1 = MS(rxsp->status5, AR_RxRSSIAnt11);
  433. rxs->rs_rssi_ext2 = MS(rxsp->status5, AR_RxRSSIAnt12);
  434. if (rxsp->status11 & AR_RxKeyIdxValid)
  435. rxs->rs_keyix = MS(rxsp->status11, AR_KeyIdx);
  436. else
  437. rxs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  438. rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
  439. rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
  440. rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
  441. rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
  442. rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
  443. rxs->rs_flags = (rxsp->status4 & AR_GI) ? ATH9K_RX_GI : 0;
  444. rxs->rs_flags |= (rxsp->status4 & AR_2040) ? ATH9K_RX_2040 : 0;
  445. rxs->evm0 = rxsp->status6;
  446. rxs->evm1 = rxsp->status7;
  447. rxs->evm2 = rxsp->status8;
  448. rxs->evm3 = rxsp->status9;
  449. rxs->evm4 = (rxsp->status10 & 0xffff);
  450. if (rxsp->status11 & AR_PreDelimCRCErr)
  451. rxs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  452. if (rxsp->status11 & AR_PostDelimCRCErr)
  453. rxs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  454. if (rxsp->status11 & AR_DecryptBusyErr)
  455. rxs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  456. if ((rxsp->status11 & AR_RxFrameOK) == 0) {
  457. if (rxsp->status11 & AR_CRCErr) {
  458. rxs->rs_status |= ATH9K_RXERR_CRC;
  459. } else if (rxsp->status11 & AR_PHYErr) {
  460. rxs->rs_status |= ATH9K_RXERR_PHY;
  461. phyerr = MS(rxsp->status11, AR_PHYErrCode);
  462. rxs->rs_phyerr = phyerr;
  463. } else if (rxsp->status11 & AR_DecryptCRCErr) {
  464. rxs->rs_status |= ATH9K_RXERR_DECRYPT;
  465. } else if (rxsp->status11 & AR_MichaelErr) {
  466. rxs->rs_status |= ATH9K_RXERR_MIC;
  467. }
  468. }
  469. return 0;
  470. }
  471. EXPORT_SYMBOL(ath9k_hw_process_rxdesc_edma);
  472. void ath9k_hw_reset_txstatus_ring(struct ath_hw *ah)
  473. {
  474. ah->ts_tail = 0;
  475. memset((void *) ah->ts_ring, 0,
  476. ah->ts_size * sizeof(struct ar9003_txs));
  477. ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
  478. "TS Start 0x%x End 0x%x Virt %p, Size %d\n",
  479. ah->ts_paddr_start, ah->ts_paddr_end,
  480. ah->ts_ring, ah->ts_size);
  481. REG_WRITE(ah, AR_Q_STATUS_RING_START, ah->ts_paddr_start);
  482. REG_WRITE(ah, AR_Q_STATUS_RING_END, ah->ts_paddr_end);
  483. }
  484. void ath9k_hw_setup_statusring(struct ath_hw *ah, void *ts_start,
  485. u32 ts_paddr_start,
  486. u8 size)
  487. {
  488. ah->ts_paddr_start = ts_paddr_start;
  489. ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs));
  490. ah->ts_size = size;
  491. ah->ts_ring = (struct ar9003_txs *) ts_start;
  492. ath9k_hw_reset_txstatus_ring(ah);
  493. }
  494. EXPORT_SYMBOL(ath9k_hw_setup_statusring);