ar9003_mac.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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_txc *txc = (struct ar9003_txc *) ds;
  187. struct ar9003_txs *ads;
  188. u32 status;
  189. ads = &ah->ts_ring[ah->ts_tail];
  190. status = ACCESS_ONCE(ads->status8);
  191. if ((status & AR_TxDone) == 0)
  192. return -EINPROGRESS;
  193. ts->qid = MS(ads->ds_info, AR_TxQcuNum);
  194. if (!txc || (MS(txc->info, AR_TxQcuNum) == ts->qid))
  195. ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size;
  196. else
  197. return -ENOENT;
  198. if ((MS(ads->ds_info, AR_DescId) != ATHEROS_VENDOR_ID) ||
  199. (MS(ads->ds_info, AR_TxRxDesc) != 1)) {
  200. ath_dbg(ath9k_hw_common(ah), ATH_DBG_XMIT,
  201. "Tx Descriptor error %x\n", ads->ds_info);
  202. memset(ads, 0, sizeof(*ads));
  203. return -EIO;
  204. }
  205. if (status & AR_TxOpExceeded)
  206. ts->ts_status |= ATH9K_TXERR_XTXOP;
  207. ts->ts_rateindex = MS(status, AR_FinalTxIdx);
  208. ts->ts_seqnum = MS(status, AR_SeqNum);
  209. ts->tid = MS(status, AR_TxTid);
  210. ts->desc_id = MS(ads->status1, AR_TxDescId);
  211. ts->ts_tstamp = ads->status4;
  212. ts->ts_status = 0;
  213. ts->ts_flags = 0;
  214. status = ACCESS_ONCE(ads->status2);
  215. ts->ts_rssi_ctl0 = MS(status, AR_TxRSSIAnt00);
  216. ts->ts_rssi_ctl1 = MS(status, AR_TxRSSIAnt01);
  217. ts->ts_rssi_ctl2 = MS(status, AR_TxRSSIAnt02);
  218. if (status & AR_TxBaStatus) {
  219. ts->ts_flags |= ATH9K_TX_BA;
  220. ts->ba_low = ads->status5;
  221. ts->ba_high = ads->status6;
  222. }
  223. status = ACCESS_ONCE(ads->status3);
  224. if (status & AR_ExcessiveRetries)
  225. ts->ts_status |= ATH9K_TXERR_XRETRY;
  226. if (status & AR_Filtered)
  227. ts->ts_status |= ATH9K_TXERR_FILT;
  228. if (status & AR_FIFOUnderrun) {
  229. ts->ts_status |= ATH9K_TXERR_FIFO;
  230. ath9k_hw_updatetxtriglevel(ah, true);
  231. }
  232. if (status & AR_TxTimerExpired)
  233. ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  234. if (status & AR_DescCfgErr)
  235. ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  236. if (status & AR_TxDataUnderrun) {
  237. ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  238. ath9k_hw_updatetxtriglevel(ah, true);
  239. }
  240. if (status & AR_TxDelimUnderrun) {
  241. ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  242. ath9k_hw_updatetxtriglevel(ah, true);
  243. }
  244. ts->ts_shortretry = MS(status, AR_RTSFailCnt);
  245. ts->ts_longretry = MS(status, AR_DataFailCnt);
  246. ts->ts_virtcol = MS(status, AR_VirtRetryCnt);
  247. status = ACCESS_ONCE(ads->status7);
  248. ts->ts_rssi = MS(status, AR_TxRSSICombined);
  249. ts->ts_rssi_ext0 = MS(status, AR_TxRSSIAnt10);
  250. ts->ts_rssi_ext1 = MS(status, AR_TxRSSIAnt11);
  251. ts->ts_rssi_ext2 = MS(status, AR_TxRSSIAnt12);
  252. memset(ads, 0, sizeof(*ads));
  253. return 0;
  254. }
  255. static void ar9003_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
  256. u32 pktlen, enum ath9k_pkt_type type, u32 txpower,
  257. u32 keyIx, enum ath9k_key_type keyType, u32 flags)
  258. {
  259. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  260. if (txpower > ah->txpower_limit)
  261. txpower = ah->txpower_limit;
  262. if (txpower > 63)
  263. txpower = 63;
  264. ads->ctl11 = (pktlen & AR_FrameLen)
  265. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  266. | SM(txpower, AR_XmitPower)
  267. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  268. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
  269. | (flags & ATH9K_TXDESC_LOWRXCHAIN ? AR_LowRxChain : 0);
  270. ads->ctl12 =
  271. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  272. | SM(type, AR_FrameType)
  273. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  274. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  275. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  276. ads->ctl17 = SM(keyType, AR_EncrType) |
  277. (flags & ATH9K_TXDESC_LDPC ? AR_LDPC : 0);
  278. ads->ctl18 = 0;
  279. ads->ctl19 = AR_Not_Sounding;
  280. ads->ctl20 = 0;
  281. ads->ctl21 = 0;
  282. ads->ctl22 = 0;
  283. }
  284. static void ar9003_hw_set_clrdmask(struct ath_hw *ah, void *ds, bool val)
  285. {
  286. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  287. if (val)
  288. ads->ctl11 |= AR_ClrDestMask;
  289. else
  290. ads->ctl11 &= ~AR_ClrDestMask;
  291. }
  292. static void ar9003_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
  293. void *lastds,
  294. u32 durUpdateEn, u32 rtsctsRate,
  295. u32 rtsctsDuration,
  296. struct ath9k_11n_rate_series series[],
  297. u32 nseries, u32 flags)
  298. {
  299. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  300. struct ar9003_txc *last_ads = (struct ar9003_txc *) lastds;
  301. u_int32_t ctl11;
  302. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  303. ctl11 = ads->ctl11;
  304. if (flags & ATH9K_TXDESC_RTSENA) {
  305. ctl11 &= ~AR_CTSEnable;
  306. ctl11 |= AR_RTSEnable;
  307. } else {
  308. ctl11 &= ~AR_RTSEnable;
  309. ctl11 |= AR_CTSEnable;
  310. }
  311. ads->ctl11 = ctl11;
  312. } else {
  313. ads->ctl11 = (ads->ctl11 & ~(AR_RTSEnable | AR_CTSEnable));
  314. }
  315. ads->ctl13 = set11nTries(series, 0)
  316. | set11nTries(series, 1)
  317. | set11nTries(series, 2)
  318. | set11nTries(series, 3)
  319. | (durUpdateEn ? AR_DurUpdateEna : 0)
  320. | SM(0, AR_BurstDur);
  321. ads->ctl14 = set11nRate(series, 0)
  322. | set11nRate(series, 1)
  323. | set11nRate(series, 2)
  324. | set11nRate(series, 3);
  325. ads->ctl15 = set11nPktDurRTSCTS(series, 0)
  326. | set11nPktDurRTSCTS(series, 1);
  327. ads->ctl16 = set11nPktDurRTSCTS(series, 2)
  328. | set11nPktDurRTSCTS(series, 3);
  329. ads->ctl18 = set11nRateFlags(series, 0)
  330. | set11nRateFlags(series, 1)
  331. | set11nRateFlags(series, 2)
  332. | set11nRateFlags(series, 3)
  333. | SM(rtsctsRate, AR_RTSCTSRate);
  334. ads->ctl19 = AR_Not_Sounding;
  335. last_ads->ctl13 = ads->ctl13;
  336. last_ads->ctl14 = ads->ctl14;
  337. }
  338. static void ar9003_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
  339. u32 aggrLen)
  340. {
  341. #define FIRST_DESC_NDELIMS 60
  342. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  343. ads->ctl12 |= (AR_IsAggr | AR_MoreAggr);
  344. if (ah->ent_mode & AR_ENT_OTP_MPSD) {
  345. u32 ctl17, ndelim;
  346. /*
  347. * Add delimiter when using RTS/CTS with aggregation
  348. * and non enterprise AR9003 card
  349. */
  350. ctl17 = ads->ctl17;
  351. ndelim = MS(ctl17, AR_PadDelim);
  352. if (ndelim < FIRST_DESC_NDELIMS) {
  353. aggrLen += (FIRST_DESC_NDELIMS - ndelim) * 4;
  354. ndelim = FIRST_DESC_NDELIMS;
  355. }
  356. ctl17 &= ~AR_AggrLen;
  357. ctl17 |= SM(aggrLen, AR_AggrLen);
  358. ctl17 &= ~AR_PadDelim;
  359. ctl17 |= SM(ndelim, AR_PadDelim);
  360. ads->ctl17 = ctl17;
  361. } else {
  362. ads->ctl17 &= ~AR_AggrLen;
  363. ads->ctl17 |= SM(aggrLen, AR_AggrLen);
  364. }
  365. }
  366. static void ar9003_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
  367. u32 numDelims)
  368. {
  369. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  370. unsigned int ctl17;
  371. ads->ctl12 |= (AR_IsAggr | AR_MoreAggr);
  372. /*
  373. * We use a stack variable to manipulate ctl6 to reduce uncached
  374. * read modify, modfiy, write.
  375. */
  376. ctl17 = ads->ctl17;
  377. ctl17 &= ~AR_PadDelim;
  378. ctl17 |= SM(numDelims, AR_PadDelim);
  379. ads->ctl17 = ctl17;
  380. }
  381. static void ar9003_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
  382. {
  383. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  384. ads->ctl12 |= AR_IsAggr;
  385. ads->ctl12 &= ~AR_MoreAggr;
  386. ads->ctl17 &= ~AR_PadDelim;
  387. }
  388. static void ar9003_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
  389. {
  390. struct ar9003_txc *ads = (struct ar9003_txc *) ds;
  391. ads->ctl12 &= (~AR_IsAggr & ~AR_MoreAggr);
  392. }
  393. void ar9003_hw_set_paprd_txdesc(struct ath_hw *ah, void *ds, u8 chains)
  394. {
  395. struct ar9003_txc *ads = ds;
  396. ads->ctl12 |= SM(chains, AR_PAPRDChainMask);
  397. }
  398. EXPORT_SYMBOL(ar9003_hw_set_paprd_txdesc);
  399. void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
  400. {
  401. struct ath_hw_ops *ops = ath9k_hw_ops(hw);
  402. ops->rx_enable = ar9003_hw_rx_enable;
  403. ops->set_desc_link = ar9003_hw_set_desc_link;
  404. ops->get_isr = ar9003_hw_get_isr;
  405. ops->fill_txdesc = ar9003_hw_fill_txdesc;
  406. ops->proc_txdesc = ar9003_hw_proc_txdesc;
  407. ops->set11n_txdesc = ar9003_hw_set11n_txdesc;
  408. ops->set11n_ratescenario = ar9003_hw_set11n_ratescenario;
  409. ops->set11n_aggr_first = ar9003_hw_set11n_aggr_first;
  410. ops->set11n_aggr_middle = ar9003_hw_set11n_aggr_middle;
  411. ops->set11n_aggr_last = ar9003_hw_set11n_aggr_last;
  412. ops->clr11n_aggr = ar9003_hw_clr11n_aggr;
  413. ops->set_clrdmask = ar9003_hw_set_clrdmask;
  414. }
  415. void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
  416. {
  417. REG_WRITE(ah, AR_DATABUF_SIZE, buf_size & AR_DATABUF_SIZE_MASK);
  418. }
  419. EXPORT_SYMBOL(ath9k_hw_set_rx_bufsize);
  420. void ath9k_hw_addrxbuf_edma(struct ath_hw *ah, u32 rxdp,
  421. enum ath9k_rx_qtype qtype)
  422. {
  423. if (qtype == ATH9K_RX_QUEUE_HP)
  424. REG_WRITE(ah, AR_HP_RXDP, rxdp);
  425. else
  426. REG_WRITE(ah, AR_LP_RXDP, rxdp);
  427. }
  428. EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma);
  429. int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs,
  430. void *buf_addr)
  431. {
  432. struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr;
  433. unsigned int phyerr;
  434. /* TODO: byte swap on big endian for ar9300_10 */
  435. if ((rxsp->status11 & AR_RxDone) == 0)
  436. return -EINPROGRESS;
  437. if (MS(rxsp->ds_info, AR_DescId) != 0x168c)
  438. return -EINVAL;
  439. if ((rxsp->ds_info & (AR_TxRxDesc | AR_CtrlStat)) != 0)
  440. return -EINPROGRESS;
  441. if (!rxs)
  442. return 0;
  443. rxs->rs_status = 0;
  444. rxs->rs_flags = 0;
  445. rxs->rs_datalen = rxsp->status2 & AR_DataLen;
  446. rxs->rs_tstamp = rxsp->status3;
  447. /* XXX: Keycache */
  448. rxs->rs_rssi = MS(rxsp->status5, AR_RxRSSICombined);
  449. rxs->rs_rssi_ctl0 = MS(rxsp->status1, AR_RxRSSIAnt00);
  450. rxs->rs_rssi_ctl1 = MS(rxsp->status1, AR_RxRSSIAnt01);
  451. rxs->rs_rssi_ctl2 = MS(rxsp->status1, AR_RxRSSIAnt02);
  452. rxs->rs_rssi_ext0 = MS(rxsp->status5, AR_RxRSSIAnt10);
  453. rxs->rs_rssi_ext1 = MS(rxsp->status5, AR_RxRSSIAnt11);
  454. rxs->rs_rssi_ext2 = MS(rxsp->status5, AR_RxRSSIAnt12);
  455. if (rxsp->status11 & AR_RxKeyIdxValid)
  456. rxs->rs_keyix = MS(rxsp->status11, AR_KeyIdx);
  457. else
  458. rxs->rs_keyix = ATH9K_RXKEYIX_INVALID;
  459. rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
  460. rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
  461. rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
  462. rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
  463. rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
  464. rxs->rs_flags = (rxsp->status4 & AR_GI) ? ATH9K_RX_GI : 0;
  465. rxs->rs_flags |= (rxsp->status4 & AR_2040) ? ATH9K_RX_2040 : 0;
  466. rxs->evm0 = rxsp->status6;
  467. rxs->evm1 = rxsp->status7;
  468. rxs->evm2 = rxsp->status8;
  469. rxs->evm3 = rxsp->status9;
  470. rxs->evm4 = (rxsp->status10 & 0xffff);
  471. if (rxsp->status11 & AR_PreDelimCRCErr)
  472. rxs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
  473. if (rxsp->status11 & AR_PostDelimCRCErr)
  474. rxs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
  475. if (rxsp->status11 & AR_DecryptBusyErr)
  476. rxs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
  477. if ((rxsp->status11 & AR_RxFrameOK) == 0) {
  478. /*
  479. * AR_CRCErr will bet set to true if we're on the last
  480. * subframe and the AR_PostDelimCRCErr is caught.
  481. * In a way this also gives us a guarantee that when
  482. * (!(AR_CRCErr) && (AR_PostDelimCRCErr)) we cannot
  483. * possibly be reviewing the last subframe. AR_CRCErr
  484. * is the CRC of the actual data.
  485. */
  486. if (rxsp->status11 & AR_CRCErr)
  487. rxs->rs_status |= ATH9K_RXERR_CRC;
  488. else if (rxsp->status11 & AR_PHYErr) {
  489. phyerr = MS(rxsp->status11, AR_PHYErrCode);
  490. /*
  491. * If we reach a point here where AR_PostDelimCRCErr is
  492. * true it implies we're *not* on the last subframe. In
  493. * in that case that we know already that the CRC of
  494. * the frame was OK, and MAC would send an ACK for that
  495. * subframe, even if we did get a phy error of type
  496. * ATH9K_PHYERR_OFDM_RESTART. This is only applicable
  497. * to frame that are prior to the last subframe.
  498. * The AR_PostDelimCRCErr is the CRC for the MPDU
  499. * delimiter, which contains the 4 reserved bits,
  500. * the MPDU length (12 bits), and follows the MPDU
  501. * delimiter for an A-MPDU subframe (0x4E = 'N' ASCII).
  502. */
  503. if ((phyerr == ATH9K_PHYERR_OFDM_RESTART) &&
  504. (rxsp->status11 & AR_PostDelimCRCErr)) {
  505. rxs->rs_phyerr = 0;
  506. } else {
  507. rxs->rs_status |= ATH9K_RXERR_PHY;
  508. rxs->rs_phyerr = phyerr;
  509. }
  510. } else if (rxsp->status11 & AR_DecryptCRCErr)
  511. rxs->rs_status |= ATH9K_RXERR_DECRYPT;
  512. else if (rxsp->status11 & AR_MichaelErr)
  513. rxs->rs_status |= ATH9K_RXERR_MIC;
  514. else if (rxsp->status11 & AR_KeyMiss)
  515. rxs->rs_status |= ATH9K_RXERR_DECRYPT;
  516. }
  517. return 0;
  518. }
  519. EXPORT_SYMBOL(ath9k_hw_process_rxdesc_edma);
  520. void ath9k_hw_reset_txstatus_ring(struct ath_hw *ah)
  521. {
  522. ah->ts_tail = 0;
  523. memset((void *) ah->ts_ring, 0,
  524. ah->ts_size * sizeof(struct ar9003_txs));
  525. ath_dbg(ath9k_hw_common(ah), ATH_DBG_XMIT,
  526. "TS Start 0x%x End 0x%x Virt %p, Size %d\n",
  527. ah->ts_paddr_start, ah->ts_paddr_end,
  528. ah->ts_ring, ah->ts_size);
  529. REG_WRITE(ah, AR_Q_STATUS_RING_START, ah->ts_paddr_start);
  530. REG_WRITE(ah, AR_Q_STATUS_RING_END, ah->ts_paddr_end);
  531. }
  532. void ath9k_hw_setup_statusring(struct ath_hw *ah, void *ts_start,
  533. u32 ts_paddr_start,
  534. u8 size)
  535. {
  536. ah->ts_paddr_start = ts_paddr_start;
  537. ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs));
  538. ah->ts_size = size;
  539. ah->ts_ring = (struct ar9003_txs *) ts_start;
  540. ath9k_hw_reset_txstatus_ring(ah);
  541. }
  542. EXPORT_SYMBOL(ath9k_hw_setup_statusring);