Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ath9k_ar9002_mac.c 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <ipxe/io.h>
  20. #include "hw.h"
  21. #define AR_BufLen 0x00000fff
  22. static void ar9002_hw_rx_enable(struct ath_hw *ah)
  23. {
  24. REG_WRITE(ah, AR_CR, AR_CR_RXE);
  25. }
  26. static void ar9002_hw_set_desc_link(void *ds, u32 ds_link)
  27. {
  28. ((struct ath_desc*) ds)->ds_link = ds_link;
  29. }
  30. static void ar9002_hw_get_desc_link(void *ds, u32 **ds_link)
  31. {
  32. *ds_link = &((struct ath_desc *)ds)->ds_link;
  33. }
  34. static int ar9002_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
  35. {
  36. u32 isr = 0;
  37. u32 mask2 = 0;
  38. struct ath9k_hw_capabilities *pCap = &ah->caps;
  39. u32 sync_cause = 0;
  40. int fatal_int = 0;
  41. if (!AR_SREV_9100(ah) && (ah->ah_ier & AR_IER_ENABLE)) {
  42. if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
  43. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  44. == AR_RTC_STATUS_ON) {
  45. isr = REG_READ(ah, AR_ISR);
  46. }
  47. }
  48. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
  49. AR_INTR_SYNC_DEFAULT;
  50. *masked = 0;
  51. if (!isr && !sync_cause)
  52. return 0;
  53. } else {
  54. *masked = 0;
  55. isr = REG_READ(ah, AR_ISR);
  56. }
  57. if (isr) {
  58. if (isr & AR_ISR_BCNMISC) {
  59. u32 isr2;
  60. isr2 = REG_READ(ah, AR_ISR_S2);
  61. if (isr2 & AR_ISR_S2_TIM)
  62. mask2 |= ATH9K_INT_TIM;
  63. if (isr2 & AR_ISR_S2_DTIM)
  64. mask2 |= ATH9K_INT_DTIM;
  65. if (isr2 & AR_ISR_S2_DTIMSYNC)
  66. mask2 |= ATH9K_INT_DTIMSYNC;
  67. if (isr2 & (AR_ISR_S2_CABEND))
  68. mask2 |= ATH9K_INT_CABEND;
  69. if (isr2 & AR_ISR_S2_GTT)
  70. mask2 |= ATH9K_INT_GTT;
  71. if (isr2 & AR_ISR_S2_CST)
  72. mask2 |= ATH9K_INT_CST;
  73. if (isr2 & AR_ISR_S2_TSFOOR)
  74. mask2 |= ATH9K_INT_TSFOOR;
  75. }
  76. isr = REG_READ(ah, AR_ISR_RAC);
  77. if (isr == 0xffffffff) {
  78. *masked = 0;
  79. return 0;
  80. }
  81. *masked = isr & ATH9K_INT_COMMON;
  82. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM |
  83. AR_ISR_RXOK | AR_ISR_RXERR))
  84. *masked |= ATH9K_INT_RX;
  85. if (isr &
  86. (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
  87. AR_ISR_TXEOL)) {
  88. u32 s0_s, s1_s;
  89. *masked |= ATH9K_INT_TX;
  90. s0_s = REG_READ(ah, AR_ISR_S0_S);
  91. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
  92. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
  93. s1_s = REG_READ(ah, AR_ISR_S1_S);
  94. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
  95. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
  96. }
  97. if (isr & AR_ISR_RXORN) {
  98. DBG("ath9k: "
  99. "receive FIFO overrun interrupt\n");
  100. }
  101. *masked |= mask2;
  102. }
  103. if (AR_SREV_9100(ah))
  104. return 1;
  105. if (isr & AR_ISR_GENTMR) {
  106. u32 s5_s;
  107. s5_s = REG_READ(ah, AR_ISR_S5_S);
  108. ah->intr_gen_timer_trigger =
  109. MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
  110. ah->intr_gen_timer_thresh =
  111. MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
  112. if (ah->intr_gen_timer_trigger)
  113. *masked |= ATH9K_INT_GENTIMER;
  114. if ((s5_s & AR_ISR_S5_TIM_TIMER) &&
  115. !(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  116. *masked |= ATH9K_INT_TIM_TIMER;
  117. }
  118. if (sync_cause) {
  119. fatal_int =
  120. (sync_cause &
  121. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  122. ? 1 : 0;
  123. if (fatal_int) {
  124. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  125. DBG("ath9k: "
  126. "received PCI FATAL interrupt\n");
  127. }
  128. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  129. DBG("ath9k: "
  130. "received PCI PERR interrupt\n");
  131. }
  132. *masked |= ATH9K_INT_FATAL;
  133. }
  134. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  135. DBG("ath9k: "
  136. "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
  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. DBG("ath9k: "
  143. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  144. }
  145. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  146. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  147. }
  148. return 1;
  149. }
  150. static void ar9002_hw_fill_txdesc(struct ath_hw *ah __unused, void *ds, u32 seglen,
  151. int is_firstseg, int is_lastseg,
  152. const void *ds0, u32 buf_addr,
  153. unsigned int qcu __unused)
  154. {
  155. struct ar5416_desc *ads = AR5416DESC(ds);
  156. ads->ds_data = buf_addr;
  157. if (is_firstseg) {
  158. ads->ds_ctl1 |= seglen | (is_lastseg ? 0 : AR_TxMore);
  159. } else if (is_lastseg) {
  160. ads->ds_ctl0 = 0;
  161. ads->ds_ctl1 = seglen;
  162. ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
  163. ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
  164. } else {
  165. ads->ds_ctl0 = 0;
  166. ads->ds_ctl1 = seglen | AR_TxMore;
  167. ads->ds_ctl2 = 0;
  168. ads->ds_ctl3 = 0;
  169. }
  170. ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
  171. ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
  172. ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
  173. ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
  174. ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
  175. }
  176. static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
  177. struct ath_tx_status *ts)
  178. {
  179. struct ar5416_desc *ads = AR5416DESC(ds);
  180. u32 status;
  181. status = *(volatile typeof(ads->ds_txstatus9) *)&(ads->ds_txstatus9);
  182. if ((status & AR_TxDone) == 0)
  183. return -EINPROGRESS;
  184. ts->ts_tstamp = ads->AR_SendTimestamp;
  185. ts->ts_status = 0;
  186. ts->ts_flags = 0;
  187. if (status & AR_TxOpExceeded)
  188. ts->ts_status |= ATH9K_TXERR_XTXOP;
  189. ts->tid = MS(status, AR_TxTid);
  190. ts->ts_rateindex = MS(status, AR_FinalTxIdx);
  191. ts->ts_seqnum = MS(status, AR_SeqNum);
  192. status = *(volatile typeof(ads->ds_txstatus0) *)&(ads->ds_txstatus0);
  193. ts->ts_rssi_ctl0 = MS(status, AR_TxRSSIAnt00);
  194. ts->ts_rssi_ctl1 = MS(status, AR_TxRSSIAnt01);
  195. ts->ts_rssi_ctl2 = MS(status, AR_TxRSSIAnt02);
  196. if (status & AR_TxBaStatus) {
  197. ts->ts_flags |= ATH9K_TX_BA;
  198. ts->ba_low = ads->AR_BaBitmapLow;
  199. ts->ba_high = ads->AR_BaBitmapHigh;
  200. }
  201. status = *(volatile typeof(ads->ds_txstatus1) *)&(ads->ds_txstatus1);
  202. if (status & AR_FrmXmitOK)
  203. ts->ts_status |= ATH9K_TX_ACKED;
  204. else {
  205. if (status & AR_ExcessiveRetries)
  206. ts->ts_status |= ATH9K_TXERR_XRETRY;
  207. if (status & AR_Filtered)
  208. ts->ts_status |= ATH9K_TXERR_FILT;
  209. if (status & AR_FIFOUnderrun) {
  210. ts->ts_status |= ATH9K_TXERR_FIFO;
  211. ath9k_hw_updatetxtriglevel(ah, 1);
  212. }
  213. }
  214. if (status & AR_TxTimerExpired)
  215. ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
  216. if (status & AR_DescCfgErr)
  217. ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR;
  218. if (status & AR_TxDataUnderrun) {
  219. ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN;
  220. ath9k_hw_updatetxtriglevel(ah, 1);
  221. }
  222. if (status & AR_TxDelimUnderrun) {
  223. ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
  224. ath9k_hw_updatetxtriglevel(ah, 1);
  225. }
  226. ts->ts_shortretry = MS(status, AR_RTSFailCnt);
  227. ts->ts_longretry = MS(status, AR_DataFailCnt);
  228. ts->ts_virtcol = MS(status, AR_VirtRetryCnt);
  229. status = *(volatile typeof(ads->ds_txstatus5) *)&(ads->ds_txstatus5);
  230. ts->ts_rssi = MS(status, AR_TxRSSICombined);
  231. ts->ts_rssi_ext0 = MS(status, AR_TxRSSIAnt10);
  232. ts->ts_rssi_ext1 = MS(status, AR_TxRSSIAnt11);
  233. ts->ts_rssi_ext2 = MS(status, AR_TxRSSIAnt12);
  234. ts->evm0 = ads->AR_TxEVM0;
  235. ts->evm1 = ads->AR_TxEVM1;
  236. ts->evm2 = ads->AR_TxEVM2;
  237. return 0;
  238. }
  239. static void ar9002_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
  240. u32 pktLen, enum ath9k_pkt_type type,
  241. u32 txPower, u32 keyIx,
  242. enum ath9k_key_type keyType, u32 flags)
  243. {
  244. struct ar5416_desc *ads = AR5416DESC(ds);
  245. if (txPower > 63)
  246. txPower = 63;
  247. ads->ds_ctl0 = (pktLen & AR_FrameLen)
  248. | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  249. | SM(txPower, AR_XmitPower)
  250. | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  251. | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
  252. | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
  253. ads->ds_ctl1 =
  254. (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
  255. | SM(type, AR_FrameType)
  256. | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
  257. | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
  258. | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
  259. ads->ds_ctl6 = SM(keyType, AR_EncrType);
  260. if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
  261. ads->ds_ctl8 = 0;
  262. ads->ds_ctl9 = 0;
  263. ads->ds_ctl10 = 0;
  264. ads->ds_ctl11 = 0;
  265. }
  266. }
  267. static void ar9002_hw_set_clrdmask(struct ath_hw *ah __unused, void *ds, int val)
  268. {
  269. struct ar5416_desc *ads = AR5416DESC(ds);
  270. if (val)
  271. ads->ds_ctl0 |= AR_ClrDestMask;
  272. else
  273. ads->ds_ctl0 &= ~AR_ClrDestMask;
  274. }
  275. static void ar9002_hw_set11n_ratescenario(struct ath_hw *ah __unused, void *ds,
  276. void *lastds,
  277. u32 durUpdateEn, u32 rtsctsRate,
  278. u32 rtsctsDuration __unused,
  279. struct ath9k_11n_rate_series series[],
  280. u32 nseries __unused, u32 flags)
  281. {
  282. struct ar5416_desc *ads = AR5416DESC(ds);
  283. struct ar5416_desc *last_ads = AR5416DESC(lastds);
  284. u32 ds_ctl0;
  285. if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
  286. ds_ctl0 = ads->ds_ctl0;
  287. if (flags & ATH9K_TXDESC_RTSENA) {
  288. ds_ctl0 &= ~AR_CTSEnable;
  289. ds_ctl0 |= AR_RTSEnable;
  290. } else {
  291. ds_ctl0 &= ~AR_RTSEnable;
  292. ds_ctl0 |= AR_CTSEnable;
  293. }
  294. ads->ds_ctl0 = ds_ctl0;
  295. } else {
  296. ads->ds_ctl0 =
  297. (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
  298. }
  299. ads->ds_ctl2 = set11nTries(series, 0)
  300. | set11nTries(series, 1)
  301. | set11nTries(series, 2)
  302. | set11nTries(series, 3)
  303. | (durUpdateEn ? AR_DurUpdateEna : 0)
  304. | SM(0, AR_BurstDur);
  305. ads->ds_ctl3 = set11nRate(series, 0)
  306. | set11nRate(series, 1)
  307. | set11nRate(series, 2)
  308. | set11nRate(series, 3);
  309. ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
  310. | set11nPktDurRTSCTS(series, 1);
  311. ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
  312. | set11nPktDurRTSCTS(series, 3);
  313. ads->ds_ctl7 = set11nRateFlags(series, 0)
  314. | set11nRateFlags(series, 1)
  315. | set11nRateFlags(series, 2)
  316. | set11nRateFlags(series, 3)
  317. | SM(rtsctsRate, AR_RTSCTSRate);
  318. last_ads->ds_ctl2 = ads->ds_ctl2;
  319. last_ads->ds_ctl3 = ads->ds_ctl3;
  320. }
  321. static void ar9002_hw_set11n_aggr_first(struct ath_hw *ah __unused, void *ds,
  322. u32 aggrLen)
  323. {
  324. struct ar5416_desc *ads = AR5416DESC(ds);
  325. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  326. ads->ds_ctl6 &= ~AR_AggrLen;
  327. ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
  328. }
  329. static void ar9002_hw_set11n_aggr_middle(struct ath_hw *ah __unused, void *ds,
  330. u32 numDelims)
  331. {
  332. struct ar5416_desc *ads = AR5416DESC(ds);
  333. unsigned int ctl6;
  334. ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
  335. ctl6 = ads->ds_ctl6;
  336. ctl6 &= ~AR_PadDelim;
  337. ctl6 |= SM(numDelims, AR_PadDelim);
  338. ads->ds_ctl6 = ctl6;
  339. }
  340. static void ar9002_hw_set11n_aggr_last(struct ath_hw *ah __unused, void *ds)
  341. {
  342. struct ar5416_desc *ads = AR5416DESC(ds);
  343. ads->ds_ctl1 |= AR_IsAggr;
  344. ads->ds_ctl1 &= ~AR_MoreAggr;
  345. ads->ds_ctl6 &= ~AR_PadDelim;
  346. }
  347. static void ar9002_hw_clr11n_aggr(struct ath_hw *ah __unused, void *ds)
  348. {
  349. struct ar5416_desc *ads = AR5416DESC(ds);
  350. ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
  351. }
  352. void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
  353. u32 size, u32 flags)
  354. {
  355. struct ar5416_desc *ads = AR5416DESC(ds);
  356. struct ath9k_hw_capabilities *pCap = &ah->caps;
  357. ads->ds_ctl1 = size & AR_BufLen;
  358. if (flags & ATH9K_RXDESC_INTREQ)
  359. ads->ds_ctl1 |= AR_RxIntrReq;
  360. ads->ds_rxstatus8 &= ~AR_RxDone;
  361. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  362. memset(&(ads->u), 0, sizeof(ads->u));
  363. }
  364. void ar9002_hw_attach_mac_ops(struct ath_hw *ah)
  365. {
  366. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  367. ops->rx_enable = ar9002_hw_rx_enable;
  368. ops->set_desc_link = ar9002_hw_set_desc_link;
  369. ops->get_desc_link = ar9002_hw_get_desc_link;
  370. ops->get_isr = ar9002_hw_get_isr;
  371. ops->fill_txdesc = ar9002_hw_fill_txdesc;
  372. ops->proc_txdesc = ar9002_hw_proc_txdesc;
  373. ops->set11n_txdesc = ar9002_hw_set11n_txdesc;
  374. ops->set11n_ratescenario = ar9002_hw_set11n_ratescenario;
  375. ops->set11n_aggr_first = ar9002_hw_set11n_aggr_first;
  376. ops->set11n_aggr_middle = ar9002_hw_set11n_aggr_middle;
  377. ops->set11n_aggr_last = ar9002_hw_set11n_aggr_last;
  378. ops->clr11n_aggr = ar9002_hw_clr11n_aggr;
  379. ops->set_clrdmask = ar9002_hw_set_clrdmask;
  380. }