ar9003_mac.c 18 KB

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