ar9003_mac.c 18 KB

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