ar9003_mac.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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. mask2 |= ((isr2 & AR_ISR_S2_BB_WATCHDOG) >>
  79. MAP_ISR_S2_BB_WATCHDOG);
  80. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  81. REG_WRITE(ah, AR_ISR_S2, isr2);
  82. isr &= ~AR_ISR_BCNMISC;
  83. }
  84. }
  85. if ((pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED))
  86. isr = REG_READ(ah, AR_ISR_RAC);
  87. if (isr == 0xffffffff) {
  88. *masked = 0;
  89. return false;
  90. }
  91. *masked = isr & ATH9K_INT_COMMON;
  92. if (ah->config.rx_intr_mitigation)
  93. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  94. *masked |= ATH9K_INT_RXLP;
  95. if (ah->config.tx_intr_mitigation)
  96. if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM))
  97. *masked |= ATH9K_INT_TX;
  98. if (isr & (AR_ISR_LP_RXOK | AR_ISR_RXERR))
  99. *masked |= ATH9K_INT_RXLP;
  100. if (isr & AR_ISR_HP_RXOK)
  101. *masked |= ATH9K_INT_RXHP;
  102. if (isr & (AR_ISR_TXOK | AR_ISR_TXERR | AR_ISR_TXEOL)) {
  103. *masked |= ATH9K_INT_TX;
  104. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  105. u32 s0, s1;
  106. s0 = REG_READ(ah, AR_ISR_S0);
  107. REG_WRITE(ah, AR_ISR_S0, s0);
  108. s1 = REG_READ(ah, AR_ISR_S1);
  109. REG_WRITE(ah, AR_ISR_S1, s1);
  110. isr &= ~(AR_ISR_TXOK | AR_ISR_TXERR |
  111. AR_ISR_TXEOL);
  112. }
  113. }
  114. if (isr & AR_ISR_GENTMR) {
  115. u32 s5;
  116. if (pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)
  117. s5 = REG_READ(ah, AR_ISR_S5_S);
  118. else
  119. s5 = REG_READ(ah, AR_ISR_S5);
  120. ah->intr_gen_timer_trigger =
  121. MS(s5, AR_ISR_S5_GENTIMER_TRIG);
  122. ah->intr_gen_timer_thresh =
  123. MS(s5, AR_ISR_S5_GENTIMER_THRESH);
  124. if (ah->intr_gen_timer_trigger)
  125. *masked |= ATH9K_INT_GENTIMER;
  126. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  127. REG_WRITE(ah, AR_ISR_S5, s5);
  128. isr &= ~AR_ISR_GENTMR;
  129. }
  130. }
  131. *masked |= mask2;
  132. if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
  133. REG_WRITE(ah, AR_ISR, isr);
  134. (void) REG_READ(ah, AR_ISR);
  135. }
  136. if (*masked & ATH9K_INT_BB_WATCHDOG)
  137. ar9003_hw_bb_watchdog_read(ah);
  138. }
  139. if (sync_cause) {
  140. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  141. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  142. REG_WRITE(ah, AR_RC, 0);
  143. *masked |= ATH9K_INT_FATAL;
  144. }
  145. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
  146. ath_print(common, ATH_DBG_INTERRUPT,
  147. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  148. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  149. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  150. }
  151. return true;
  152. }
  153. static void ar9003_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen,
  154. bool is_firstseg, bool is_lastseg,
  155. const void *ds0, dma_addr_t buf_addr,
  156. unsigned int qcu)
  157. {
  158. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  159. unsigned int descid = 0;
  160. ads->info = (ATHEROS_VENDOR_ID << AR_DescId_S) |
  161. (1 << AR_TxRxDesc_S) |
  162. (1 << AR_CtrlStat_S) |
  163. (qcu << AR_TxQcuNum_S) | 0x17;
  164. ads->data0 = buf_addr;
  165. ads->data1 = 0;
  166. ads->data2 = 0;
  167. ads->data3 = 0;
  168. ads->ctl3 = (seglen << AR_BufLen_S);
  169. ads->ctl3 &= AR_BufLen;
  170. /* Fill in pointer checksum and descriptor id */
  171. ads->ctl10 = ar9003_calc_ptr_chksum(ads);
  172. ads->ctl10 |= (descid << AR_TxDescId_S);
  173. if (is_firstseg) {
  174. ads->ctl12 |= (is_lastseg ? 0 : AR_TxMore);
  175. } else if (is_lastseg) {
  176. ads->ctl11 = 0;
  177. ads->ctl12 = 0;
  178. ads->ctl13 = AR9003TXC_CONST(ds0)->ctl13;
  179. ads->ctl14 = AR9003TXC_CONST(ds0)->ctl14;
  180. } else {
  181. /* XXX Intermediate descriptor in a multi-descriptor frame.*/
  182. ads->ctl11 = 0;
  183. ads->ctl12 = AR_TxMore;
  184. ads->ctl13 = 0;
  185. ads->ctl14 = 0;
  186. }
  187. }
  188. static int ar9003_hw_proc_txdesc(struct ath_hw *ah, void *ds,
  189. struct ath_tx_status *ts)
  190. {
  191. struct ar9003_txs *ads;
  192. ads = &ah->ts_ring[ah->ts_tail];
  193. if ((ads->status8 & AR_TxDone) == 0)
  194. return -EINPROGRESS;
  195. ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size;
  196. if ((MS(ads->ds_info, AR_DescId) != ATHEROS_VENDOR_ID) ||
  197. (MS(ads->ds_info, AR_TxRxDesc) != 1)) {
  198. ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
  199. "Tx Descriptor error %x\n", ads->ds_info);
  200. memset(ads, 0, sizeof(*ads));
  201. return -EIO;
  202. }
  203. ts->qid = MS(ads->ds_info, AR_TxQcuNum);
  204. ts->desc_id = MS(ads->status1, AR_TxDescId);
  205. ts->ts_seqnum = MS(ads->status8, AR_SeqNum);
  206. ts->ts_tstamp = ads->status4;
  207. ts->ts_status = 0;
  208. ts->ts_flags = 0;
  209. if (ads->status3 & AR_ExcessiveRetries)
  210. ts->ts_status |= ATH9K_TXERR_XRETRY;
  211. if (ads->status3 & AR_Filtered)
  212. ts->ts_status |= ATH9K_TXERR_FILT;
  213. if (ads->status3 & AR_FIFOUnderrun) {
  214. ts->ts_status |= ATH9K_TXERR_FIFO;
  215. ath9k_hw_updatetxtriglevel(ah, true);
  216. }
  217. if (ads->status8 & AR_TxOpExceeded)
  218. ts->ts_status |= ATH9K_TXERR_XTXOP;
  219. if (ads->status3 & AR_TxTimerExpired)
  220. ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  221. if (ads->status3 & AR_DescCfgErr)
  222. ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  223. if (ads->status3 & AR_TxDataUnderrun) {
  224. ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  225. ath9k_hw_updatetxtriglevel(ah, true);
  226. }
  227. if (ads->status3 & AR_TxDelimUnderrun) {
  228. ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  229. ath9k_hw_updatetxtriglevel(ah, true);
  230. }
  231. if (ads->status2 & AR_TxBaStatus) {
  232. ts->ts_flags |= ATH9K_TX_BA;
  233. ts->ba_low = ads->status5;
  234. ts->ba_high = ads->status6;
  235. }
  236. ts->ts_rateindex = MS(ads->status8, AR_FinalTxIdx);
  237. ts->ts_rssi = MS(ads->status7, AR_TxRSSICombined);
  238. ts->ts_rssi_ctl0 = MS(ads->status2, AR_TxRSSIAnt00);
  239. ts->ts_rssi_ctl1 = MS(ads->status2, AR_TxRSSIAnt01);
  240. ts->ts_rssi_ctl2 = MS(ads->status2, AR_TxRSSIAnt02);
  241. ts->ts_rssi_ext0 = MS(ads->status7, AR_TxRSSIAnt10);
  242. ts->ts_rssi_ext1 = MS(ads->status7, AR_TxRSSIAnt11);
  243. ts->ts_rssi_ext2 = MS(ads->status7, AR_TxRSSIAnt12);
  244. ts->ts_shortretry = MS(ads->status3, AR_RTSFailCnt);
  245. ts->ts_longretry = MS(ads->status3, AR_DataFailCnt);
  246. ts->ts_virtcol = MS(ads->status3, AR_VirtRetryCnt);
  247. ts->ts_antenna = 0;
  248. ts->tid = MS(ads->status8, AR_TxTid);
  249. memset(ads, 0, sizeof(*ads));
  250. return 0;
  251. }
  252. static void ar9003_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
  253. u32 pktlen, enum ath9k_pkt_type type, u32 txpower,
  254. u32 keyIx, enum ath9k_key_type keyType, u32 flags)
  255. {
  256. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  257. if (txpower > ah->txpower_limit)
  258. txpower = ah->txpower_limit;
  259. txpower += ah->txpower_indexoffset;
  260. if (txpower > 63)
  261. txpower = 63;
  262. ads->ctl11 = (pktlen & AR_FrameLen)
  263. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  264. | SM(txpower, AR_XmitPower)
  265. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  266. | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
  267. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
  268. | (flags & ATH9K_TXDESC_LOWRXCHAIN ? AR_LowRxChain : 0);
  269. ads->ctl12 =
  270. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  271. | SM(type, AR_FrameType)
  272. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  273. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  274. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  275. ads->ctl17 = SM(keyType, AR_EncrType) |
  276. (flags & ATH9K_TXDESC_LDPC ? AR_LDPC : 0);
  277. ads->ctl18 = 0;
  278. ads->ctl19 = AR_Not_Sounding;
  279. ads->ctl20 = 0;
  280. ads->ctl21 = 0;
  281. ads->ctl22 = 0;
  282. }
  283. static void ar9003_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
  284. void *lastds,
  285. u32 durUpdateEn, u32 rtsctsRate,
  286. u32 rtsctsDuration,
  287. struct ath9k_11n_rate_series series[],
  288. u32 nseries, u32 flags)
  289. {
  290. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  291. struct ar9003_txc *last_ads = (struct ar9003_txc *) lastds;
  292. u_int32_t ctl11;
  293. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  294. ctl11 = ads->ctl11;
  295. if (flags & ATH9K_TXDESC_RTSENA) {
  296. ctl11 &= ~AR_CTSEnable;
  297. ctl11 |= AR_RTSEnable;
  298. } else {
  299. ctl11 &= ~AR_RTSEnable;
  300. ctl11 |= AR_CTSEnable;
  301. }
  302. ads->ctl11 = ctl11;
  303. } else {
  304. ads->ctl11 = (ads->ctl11 & ~(AR_RTSEnable | AR_CTSEnable));
  305. }
  306. ads->ctl13 = 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->ctl14 = set11nRate(series, 0)
  313. | set11nRate(series, 1)
  314. | set11nRate(series, 2)
  315. | set11nRate(series, 3);
  316. ads->ctl15 = set11nPktDurRTSCTS(series, 0)
  317. | set11nPktDurRTSCTS(series, 1);
  318. ads->ctl16 = set11nPktDurRTSCTS(series, 2)
  319. | set11nPktDurRTSCTS(series, 3);
  320. ads->ctl18 = set11nRateFlags(series, 0)
  321. | set11nRateFlags(series, 1)
  322. | set11nRateFlags(series, 2)
  323. | set11nRateFlags(series, 3)
  324. | SM(rtsctsRate, AR_RTSCTSRate);
  325. ads->ctl19 = AR_Not_Sounding;
  326. last_ads->ctl13 = ads->ctl13;
  327. last_ads->ctl14 = ads->ctl14;
  328. }
  329. static void ar9003_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
  330. u32 aggrLen)
  331. {
  332. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  333. ads->ctl12 |= (AR_IsAggr | AR_MoreAggr);
  334. ads->ctl17 &= ~AR_AggrLen;
  335. ads->ctl17 |= SM(aggrLen, AR_AggrLen);
  336. }
  337. static void ar9003_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
  338. u32 numDelims)
  339. {
  340. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  341. unsigned int ctl17;
  342. ads->ctl12 |= (AR_IsAggr | AR_MoreAggr);
  343. /*
  344. * We use a stack variable to manipulate ctl6 to reduce uncached
  345. * read modify, modfiy, write.
  346. */
  347. ctl17 = ads->ctl17;
  348. ctl17 &= ~AR_PadDelim;
  349. ctl17 |= SM(numDelims, AR_PadDelim);
  350. ads->ctl17 = ctl17;
  351. }
  352. static void ar9003_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
  353. {
  354. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  355. ads->ctl12 |= AR_IsAggr;
  356. ads->ctl12 &= ~AR_MoreAggr;
  357. ads->ctl17 &= ~AR_PadDelim;
  358. }
  359. static void ar9003_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
  360. {
  361. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  362. ads->ctl12 &= (~AR_IsAggr & ~AR_MoreAggr);
  363. }
  364. static void ar9003_hw_set11n_burstduration(struct ath_hw *ah, void *ds,
  365. u32 burstDuration)
  366. {
  367. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  368. ads->ctl13 &= ~AR_BurstDur;
  369. ads->ctl13 |= SM(burstDuration, AR_BurstDur);
  370. }
  371. static void ar9003_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
  372. u32 vmf)
  373. {
  374. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  375. if (vmf)
  376. ads->ctl11 |= AR_VirtMoreFrag;
  377. else
  378. ads->ctl11 &= ~AR_VirtMoreFrag;
  379. }
  380. void ar9003_hw_set_paprd_txdesc(struct ath_hw *ah, void *ds, u8 chains)
  381. {
  382. struct ar9003_txc *ads = ds;
  383. ads->ctl12 |= SM(chains, AR_PAPRDChainMask);
  384. }
  385. EXPORT_SYMBOL(ar9003_hw_set_paprd_txdesc);
  386. void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
  387. {
  388. struct ath_hw_ops *ops = ath9k_hw_ops(hw);
  389. ops->rx_enable = ar9003_hw_rx_enable;
  390. ops->set_desc_link = ar9003_hw_set_desc_link;
  391. ops->get_desc_link = ar9003_hw_get_desc_link;
  392. ops->get_isr = ar9003_hw_get_isr;
  393. ops->fill_txdesc = ar9003_hw_fill_txdesc;
  394. ops->proc_txdesc = ar9003_hw_proc_txdesc;
  395. ops->set11n_txdesc = ar9003_hw_set11n_txdesc;
  396. ops->set11n_ratescenario = ar9003_hw_set11n_ratescenario;
  397. ops->set11n_aggr_first = ar9003_hw_set11n_aggr_first;
  398. ops->set11n_aggr_middle = ar9003_hw_set11n_aggr_middle;
  399. ops->set11n_aggr_last = ar9003_hw_set11n_aggr_last;
  400. ops->clr11n_aggr = ar9003_hw_clr11n_aggr;
  401. ops->set11n_burstduration = ar9003_hw_set11n_burstduration;
  402. ops->set11n_virtualmorefrag = ar9003_hw_set11n_virtualmorefrag;
  403. }
  404. void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
  405. {
  406. REG_WRITE(ah, AR_DATABUF_SIZE, buf_size & AR_DATABUF_SIZE_MASK);
  407. }
  408. EXPORT_SYMBOL(ath9k_hw_set_rx_bufsize);
  409. void ath9k_hw_addrxbuf_edma(struct ath_hw *ah, u32 rxdp,
  410. enum ath9k_rx_qtype qtype)
  411. {
  412. if (qtype == ATH9K_RX_QUEUE_HP)
  413. REG_WRITE(ah, AR_HP_RXDP, rxdp);
  414. else
  415. REG_WRITE(ah, AR_LP_RXDP, rxdp);
  416. }
  417. EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma);
  418. int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs,
  419. void *buf_addr)
  420. {
  421. struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr;
  422. unsigned int phyerr;
  423. /* TODO: byte swap on big endian for ar9300_10 */
  424. if ((rxsp->status11 & AR_RxDone) == 0)
  425. return -EINPROGRESS;
  426. if (MS(rxsp->ds_info, AR_DescId) != 0x168c)
  427. return -EINVAL;
  428. if ((rxsp->ds_info & (AR_TxRxDesc | AR_CtrlStat)) != 0)
  429. return -EINPROGRESS;
  430. if (!rxs)
  431. return 0;
  432. rxs->rs_status = 0;
  433. rxs->rs_flags = 0;
  434. rxs->rs_datalen = rxsp->status2 & AR_DataLen;
  435. rxs->rs_tstamp = rxsp->status3;
  436. /* XXX: Keycache */
  437. rxs->rs_rssi = MS(rxsp->status5, AR_RxRSSICombined);
  438. rxs->rs_rssi_ctl0 = MS(rxsp->status1, AR_RxRSSIAnt00);
  439. rxs->rs_rssi_ctl1 = MS(rxsp->status1, AR_RxRSSIAnt01);
  440. rxs->rs_rssi_ctl2 = MS(rxsp->status1, AR_RxRSSIAnt02);
  441. rxs->rs_rssi_ext0 = MS(rxsp->status5, AR_RxRSSIAnt10);
  442. rxs->rs_rssi_ext1 = MS(rxsp->status5, AR_RxRSSIAnt11);
  443. rxs->rs_rssi_ext2 = MS(rxsp->status5, AR_RxRSSIAnt12);
  444. if (rxsp->status11 & AR_RxKeyIdxValid)
  445. rxs->rs_keyix = MS(rxsp->status11, AR_KeyIdx);
  446. else
  447. rxs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  448. rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
  449. rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
  450. rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
  451. rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
  452. rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
  453. rxs->rs_flags = (rxsp->status4 & AR_GI) ? ATH9K_RX_GI : 0;
  454. rxs->rs_flags |= (rxsp->status4 & AR_2040) ? ATH9K_RX_2040 : 0;
  455. rxs->evm0 = rxsp->status6;
  456. rxs->evm1 = rxsp->status7;
  457. rxs->evm2 = rxsp->status8;
  458. rxs->evm3 = rxsp->status9;
  459. rxs->evm4 = (rxsp->status10 & 0xffff);
  460. if (rxsp->status11 & AR_PreDelimCRCErr)
  461. rxs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  462. if (rxsp->status11 & AR_PostDelimCRCErr)
  463. rxs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  464. if (rxsp->status11 & AR_DecryptBusyErr)
  465. rxs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  466. if ((rxsp->status11 & AR_RxFrameOK) == 0) {
  467. /*
  468. * AR_CRCErr will bet set to true if we're on the last
  469. * subframe and the AR_PostDelimCRCErr is caught.
  470. * In a way this also gives us a guarantee that when
  471. * (!(AR_CRCErr) && (AR_PostDelimCRCErr)) we cannot
  472. * possibly be reviewing the last subframe. AR_CRCErr
  473. * is the CRC of the actual data.
  474. */
  475. if (rxsp->status11 & AR_CRCErr) {
  476. rxs->rs_status |= ATH9K_RXERR_CRC;
  477. } else if (rxsp->status11 & AR_PHYErr) {
  478. phyerr = MS(rxsp->status11, AR_PHYErrCode);
  479. /*
  480. * If we reach a point here where AR_PostDelimCRCErr is
  481. * true it implies we're *not* on the last subframe. In
  482. * in that case that we know already that the CRC of
  483. * the frame was OK, and MAC would send an ACK for that
  484. * subframe, even if we did get a phy error of type
  485. * ATH9K_PHYERR_OFDM_RESTART. This is only applicable
  486. * to frame that are prior to the last subframe.
  487. * The AR_PostDelimCRCErr is the CRC for the MPDU
  488. * delimiter, which contains the 4 reserved bits,
  489. * the MPDU length (12 bits), and follows the MPDU
  490. * delimiter for an A-MPDU subframe (0x4E = 'N' ASCII).
  491. */
  492. if ((phyerr == ATH9K_PHYERR_OFDM_RESTART) &&
  493. (rxsp->status11 & AR_PostDelimCRCErr)) {
  494. rxs->rs_phyerr = 0;
  495. } else {
  496. rxs->rs_status |= ATH9K_RXERR_PHY;
  497. rxs->rs_phyerr = phyerr;
  498. }
  499. } else if (rxsp->status11 & AR_DecryptCRCErr) {
  500. rxs->rs_status |= ATH9K_RXERR_DECRYPT;
  501. } else if (rxsp->status11 & AR_MichaelErr) {
  502. rxs->rs_status |= ATH9K_RXERR_MIC;
  503. } else if (rxsp->status11 & AR_KeyMiss)
  504. rxs->rs_status |= ATH9K_RXERR_DECRYPT;
  505. }
  506. return 0;
  507. }
  508. EXPORT_SYMBOL(ath9k_hw_process_rxdesc_edma);
  509. void ath9k_hw_reset_txstatus_ring(struct ath_hw *ah)
  510. {
  511. ah->ts_tail = 0;
  512. memset((void *) ah->ts_ring, 0,
  513. ah->ts_size * sizeof(struct ar9003_txs));
  514. ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
  515. "TS Start 0x%x End 0x%x Virt %p, Size %d\n",
  516. ah->ts_paddr_start, ah->ts_paddr_end,
  517. ah->ts_ring, ah->ts_size);
  518. REG_WRITE(ah, AR_Q_STATUS_RING_START, ah->ts_paddr_start);
  519. REG_WRITE(ah, AR_Q_STATUS_RING_END, ah->ts_paddr_end);
  520. }
  521. void ath9k_hw_setup_statusring(struct ath_hw *ah, void *ts_start,
  522. u32 ts_paddr_start,
  523. u8 size)
  524. {
  525. ah->ts_paddr_start = ts_paddr_start;
  526. ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs));
  527. ah->ts_size = size;
  528. ah->ts_ring = (struct ar9003_txs *) ts_start;
  529. ath9k_hw_reset_txstatus_ring(ah);
  530. }
  531. EXPORT_SYMBOL(ath9k_hw_setup_statusring);