2 * Copyright (c) 2008 Atheros Communications Inc.
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.
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.
19 static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
20 struct ath9k_tx_queue_info *qi)
22 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
23 "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
24 ah->txok_interrupt_mask, ah->txerr_interrupt_mask,
25 ah->txdesc_interrupt_mask, ah->txeol_interrupt_mask,
26 ah->txurn_interrupt_mask);
28 REG_WRITE(ah, AR_IMR_S0,
29 SM(ah->txok_interrupt_mask, AR_IMR_S0_QCU_TXOK)
30 | SM(ah->txdesc_interrupt_mask, AR_IMR_S0_QCU_TXDESC));
31 REG_WRITE(ah, AR_IMR_S1,
32 SM(ah->txerr_interrupt_mask, AR_IMR_S1_QCU_TXERR)
33 | SM(ah->txeol_interrupt_mask, AR_IMR_S1_QCU_TXEOL));
34 REG_RMW_FIELD(ah, AR_IMR_S2,
35 AR_IMR_S2_QCU_TXURN, ah->txurn_interrupt_mask);
38 u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q)
40 return REG_READ(ah, AR_QTXDP(q));
43 bool ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
45 REG_WRITE(ah, AR_QTXDP(q), txdp);
50 bool ath9k_hw_txstart(struct ath_hw *ah, u32 q)
52 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q);
54 REG_WRITE(ah, AR_Q_TXE, 1 << q);
59 u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q)
63 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
66 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
73 bool ath9k_hw_updatetxtriglevel(struct ath_hw *ah, bool bIncTrigLevel)
75 u32 txcfg, curLevel, newLevel;
78 if (ah->tx_trig_level >= MAX_TX_FIFO_THRESHOLD)
81 omask = ath9k_hw_set_interrupts(ah, ah->mask_reg & ~ATH9K_INT_GLOBAL);
83 txcfg = REG_READ(ah, AR_TXCFG);
84 curLevel = MS(txcfg, AR_FTRIG);
87 if (curLevel < MAX_TX_FIFO_THRESHOLD)
89 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
91 if (newLevel != curLevel)
92 REG_WRITE(ah, AR_TXCFG,
93 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
95 ath9k_hw_set_interrupts(ah, omask);
97 ah->tx_trig_level = newLevel;
99 return newLevel != curLevel;
102 bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
104 #define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
105 #define ATH9K_TIME_QUANTUM 100 /* usec */
107 struct ath9k_hw_capabilities *pCap = &ah->caps;
108 struct ath9k_tx_queue_info *qi;
110 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
112 if (q >= pCap->total_queues) {
113 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
118 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
119 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
123 REG_WRITE(ah, AR_Q_TXD, 1 << q);
125 for (wait = wait_time; wait != 0; wait--) {
126 if (ath9k_hw_numtxpending(ah, q) == 0)
128 udelay(ATH9K_TIME_QUANTUM);
131 if (ath9k_hw_numtxpending(ah, q)) {
132 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
133 "%s: Num of pending TX Frames %d on Q %d\n",
134 __func__, ath9k_hw_numtxpending(ah, q), q);
136 for (j = 0; j < 2; j++) {
137 tsfLow = REG_READ(ah, AR_TSF_L32);
138 REG_WRITE(ah, AR_QUIET2,
139 SM(10, AR_QUIET2_QUIET_DUR));
140 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
141 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
142 REG_SET_BIT(ah, AR_TIMER_MODE,
145 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
148 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
149 "TSF have moved while trying to set "
150 "quiet time TSF: 0x%08x\n", tsfLow);
153 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
156 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
159 while (ath9k_hw_numtxpending(ah, q)) {
161 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
162 "Failed to stop Tx DMA in 100 "
163 "msec after killing last frame\n");
166 udelay(ATH9K_TIME_QUANTUM);
169 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
172 REG_WRITE(ah, AR_Q_TXD, 0);
175 #undef ATH9K_TX_STOP_DMA_TIMEOUT
176 #undef ATH9K_TIME_QUANTUM
179 bool ath9k_hw_filltxdesc(struct ath_hw *ah, struct ath_desc *ds,
180 u32 segLen, bool firstSeg,
181 bool lastSeg, const struct ath_desc *ds0)
183 struct ar5416_desc *ads = AR5416DESC(ds);
186 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
187 } else if (lastSeg) {
189 ads->ds_ctl1 = segLen;
190 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
191 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
194 ads->ds_ctl1 = segLen | AR_TxMore;
198 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
199 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
200 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
201 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
202 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
207 void ath9k_hw_cleartxdesc(struct ath_hw *ah, struct ath_desc *ds)
209 struct ar5416_desc *ads = AR5416DESC(ds);
211 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
212 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
213 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
214 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
215 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
218 int ath9k_hw_txprocdesc(struct ath_hw *ah, struct ath_desc *ds)
220 struct ar5416_desc *ads = AR5416DESC(ds);
222 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
225 ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
226 ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
227 ds->ds_txstat.ts_status = 0;
228 ds->ds_txstat.ts_flags = 0;
230 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
231 ds->ds_txstat.ts_status |= ATH9K_TXERR_XRETRY;
232 if (ads->ds_txstatus1 & AR_Filtered)
233 ds->ds_txstat.ts_status |= ATH9K_TXERR_FILT;
234 if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
235 ds->ds_txstat.ts_status |= ATH9K_TXERR_FIFO;
236 ath9k_hw_updatetxtriglevel(ah, true);
238 if (ads->ds_txstatus9 & AR_TxOpExceeded)
239 ds->ds_txstat.ts_status |= ATH9K_TXERR_XTXOP;
240 if (ads->ds_txstatus1 & AR_TxTimerExpired)
241 ds->ds_txstat.ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
243 if (ads->ds_txstatus1 & AR_DescCfgErr)
244 ds->ds_txstat.ts_flags |= ATH9K_TX_DESC_CFG_ERR;
245 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
246 ds->ds_txstat.ts_flags |= ATH9K_TX_DATA_UNDERRUN;
247 ath9k_hw_updatetxtriglevel(ah, true);
249 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
250 ds->ds_txstat.ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
251 ath9k_hw_updatetxtriglevel(ah, true);
253 if (ads->ds_txstatus0 & AR_TxBaStatus) {
254 ds->ds_txstat.ts_flags |= ATH9K_TX_BA;
255 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
256 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
259 ds->ds_txstat.ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
260 switch (ds->ds_txstat.ts_rateindex) {
262 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
265 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
268 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
271 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
275 ds->ds_txstat.ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
276 ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
277 ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
278 ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
279 ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
280 ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
281 ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
282 ds->ds_txstat.evm0 = ads->AR_TxEVM0;
283 ds->ds_txstat.evm1 = ads->AR_TxEVM1;
284 ds->ds_txstat.evm2 = ads->AR_TxEVM2;
285 ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
286 ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
287 ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
288 ds->ds_txstat.ts_antenna = 1;
293 void ath9k_hw_set11n_txdesc(struct ath_hw *ah, struct ath_desc *ds,
294 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
295 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
297 struct ar5416_desc *ads = AR5416DESC(ds);
299 txPower += ah->txpower_indexoffset;
303 ads->ds_ctl0 = (pktLen & AR_FrameLen)
304 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
305 | SM(txPower, AR_XmitPower)
306 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
307 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
308 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
309 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
312 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
313 | SM(type, AR_FrameType)
314 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
315 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
316 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
318 ads->ds_ctl6 = SM(keyType, AR_EncrType);
320 if (AR_SREV_9285(ah)) {
328 void ath9k_hw_set11n_ratescenario(struct ath_hw *ah, struct ath_desc *ds,
329 struct ath_desc *lastds,
330 u32 durUpdateEn, u32 rtsctsRate,
332 struct ath9k_11n_rate_series series[],
333 u32 nseries, u32 flags)
335 struct ar5416_desc *ads = AR5416DESC(ds);
336 struct ar5416_desc *last_ads = AR5416DESC(lastds);
339 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
340 ds_ctl0 = ads->ds_ctl0;
342 if (flags & ATH9K_TXDESC_RTSENA) {
343 ds_ctl0 &= ~AR_CTSEnable;
344 ds_ctl0 |= AR_RTSEnable;
346 ds_ctl0 &= ~AR_RTSEnable;
347 ds_ctl0 |= AR_CTSEnable;
350 ads->ds_ctl0 = ds_ctl0;
353 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
356 ads->ds_ctl2 = set11nTries(series, 0)
357 | set11nTries(series, 1)
358 | set11nTries(series, 2)
359 | set11nTries(series, 3)
360 | (durUpdateEn ? AR_DurUpdateEna : 0)
361 | SM(0, AR_BurstDur);
363 ads->ds_ctl3 = set11nRate(series, 0)
364 | set11nRate(series, 1)
365 | set11nRate(series, 2)
366 | set11nRate(series, 3);
368 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
369 | set11nPktDurRTSCTS(series, 1);
371 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
372 | set11nPktDurRTSCTS(series, 3);
374 ads->ds_ctl7 = set11nRateFlags(series, 0)
375 | set11nRateFlags(series, 1)
376 | set11nRateFlags(series, 2)
377 | set11nRateFlags(series, 3)
378 | SM(rtsctsRate, AR_RTSCTSRate);
379 last_ads->ds_ctl2 = ads->ds_ctl2;
380 last_ads->ds_ctl3 = ads->ds_ctl3;
383 void ath9k_hw_set11n_aggr_first(struct ath_hw *ah, struct ath_desc *ds,
386 struct ar5416_desc *ads = AR5416DESC(ds);
388 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
389 ads->ds_ctl6 &= ~AR_AggrLen;
390 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
393 void ath9k_hw_set11n_aggr_middle(struct ath_hw *ah, struct ath_desc *ds,
396 struct ar5416_desc *ads = AR5416DESC(ds);
399 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
402 ctl6 &= ~AR_PadDelim;
403 ctl6 |= SM(numDelims, AR_PadDelim);
407 void ath9k_hw_set11n_aggr_last(struct ath_hw *ah, struct ath_desc *ds)
409 struct ar5416_desc *ads = AR5416DESC(ds);
411 ads->ds_ctl1 |= AR_IsAggr;
412 ads->ds_ctl1 &= ~AR_MoreAggr;
413 ads->ds_ctl6 &= ~AR_PadDelim;
416 void ath9k_hw_clr11n_aggr(struct ath_hw *ah, struct ath_desc *ds)
418 struct ar5416_desc *ads = AR5416DESC(ds);
420 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
423 void ath9k_hw_set11n_burstduration(struct ath_hw *ah, struct ath_desc *ds,
426 struct ar5416_desc *ads = AR5416DESC(ds);
428 ads->ds_ctl2 &= ~AR_BurstDur;
429 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
432 void ath9k_hw_set11n_virtualmorefrag(struct ath_hw *ah, struct ath_desc *ds,
435 struct ar5416_desc *ads = AR5416DESC(ds);
438 ads->ds_ctl0 |= AR_VirtMoreFrag;
440 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
443 void ath9k_hw_gettxintrtxqs(struct ath_hw *ah, u32 *txqs)
445 *txqs &= ah->intr_txqs;
446 ah->intr_txqs &= ~(*txqs);
449 bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
450 const struct ath9k_tx_queue_info *qinfo)
453 struct ath9k_hw_capabilities *pCap = &ah->caps;
454 struct ath9k_tx_queue_info *qi;
456 if (q >= pCap->total_queues) {
457 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
462 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
463 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
467 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %p\n", qi);
469 qi->tqi_ver = qinfo->tqi_ver;
470 qi->tqi_subtype = qinfo->tqi_subtype;
471 qi->tqi_qflags = qinfo->tqi_qflags;
472 qi->tqi_priority = qinfo->tqi_priority;
473 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
474 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
476 qi->tqi_aifs = INIT_AIFS;
477 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
478 cw = min(qinfo->tqi_cwmin, 1024U);
480 while (qi->tqi_cwmin < cw)
481 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
483 qi->tqi_cwmin = qinfo->tqi_cwmin;
484 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
485 cw = min(qinfo->tqi_cwmax, 1024U);
487 while (qi->tqi_cwmax < cw)
488 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
490 qi->tqi_cwmax = INIT_CWMAX;
492 if (qinfo->tqi_shretry != 0)
493 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
495 qi->tqi_shretry = INIT_SH_RETRY;
496 if (qinfo->tqi_lgretry != 0)
497 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
499 qi->tqi_lgretry = INIT_LG_RETRY;
500 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
501 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
502 qi->tqi_burstTime = qinfo->tqi_burstTime;
503 qi->tqi_readyTime = qinfo->tqi_readyTime;
505 switch (qinfo->tqi_subtype) {
507 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
508 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
517 bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
518 struct ath9k_tx_queue_info *qinfo)
520 struct ath9k_hw_capabilities *pCap = &ah->caps;
521 struct ath9k_tx_queue_info *qi;
523 if (q >= pCap->total_queues) {
524 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
529 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
530 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
534 qinfo->tqi_qflags = qi->tqi_qflags;
535 qinfo->tqi_ver = qi->tqi_ver;
536 qinfo->tqi_subtype = qi->tqi_subtype;
537 qinfo->tqi_qflags = qi->tqi_qflags;
538 qinfo->tqi_priority = qi->tqi_priority;
539 qinfo->tqi_aifs = qi->tqi_aifs;
540 qinfo->tqi_cwmin = qi->tqi_cwmin;
541 qinfo->tqi_cwmax = qi->tqi_cwmax;
542 qinfo->tqi_shretry = qi->tqi_shretry;
543 qinfo->tqi_lgretry = qi->tqi_lgretry;
544 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
545 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
546 qinfo->tqi_burstTime = qi->tqi_burstTime;
547 qinfo->tqi_readyTime = qi->tqi_readyTime;
552 int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
553 const struct ath9k_tx_queue_info *qinfo)
555 struct ath9k_tx_queue_info *qi;
556 struct ath9k_hw_capabilities *pCap = &ah->caps;
560 case ATH9K_TX_QUEUE_BEACON:
561 q = pCap->total_queues - 1;
563 case ATH9K_TX_QUEUE_CAB:
564 q = pCap->total_queues - 2;
566 case ATH9K_TX_QUEUE_PSPOLL:
569 case ATH9K_TX_QUEUE_UAPSD:
570 q = pCap->total_queues - 3;
572 case ATH9K_TX_QUEUE_DATA:
573 for (q = 0; q < pCap->total_queues; q++)
574 if (ah->txq[q].tqi_type ==
575 ATH9K_TX_QUEUE_INACTIVE)
577 if (q == pCap->total_queues) {
578 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
579 "no available tx queue\n");
584 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "bad tx queue type %u\n", type);
588 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q);
591 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
592 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
593 "tx queue %u already active\n", q);
596 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
600 TXQ_FLAG_TXOKINT_ENABLE
601 | TXQ_FLAG_TXERRINT_ENABLE
602 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
603 qi->tqi_aifs = INIT_AIFS;
604 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
605 qi->tqi_cwmax = INIT_CWMAX;
606 qi->tqi_shretry = INIT_SH_RETRY;
607 qi->tqi_lgretry = INIT_LG_RETRY;
608 qi->tqi_physCompBuf = 0;
610 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
611 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
617 bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
619 struct ath9k_hw_capabilities *pCap = &ah->caps;
620 struct ath9k_tx_queue_info *qi;
622 if (q >= pCap->total_queues) {
623 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
627 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
628 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
632 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "release queue %u\n", q);
634 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
635 ah->txok_interrupt_mask &= ~(1 << q);
636 ah->txerr_interrupt_mask &= ~(1 << q);
637 ah->txdesc_interrupt_mask &= ~(1 << q);
638 ah->txeol_interrupt_mask &= ~(1 << q);
639 ah->txurn_interrupt_mask &= ~(1 << q);
640 ath9k_hw_set_txq_interrupts(ah, qi);
645 bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
647 struct ath9k_hw_capabilities *pCap = &ah->caps;
648 struct ath9k_channel *chan = ah->curchan;
649 struct ath9k_tx_queue_info *qi;
650 u32 cwMin, chanCwMin, value;
652 if (q >= pCap->total_queues) {
653 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
658 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
659 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
663 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "reset queue %u\n", q);
665 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
666 if (chan && IS_CHAN_B(chan))
667 chanCwMin = INIT_CWMIN_11B;
669 chanCwMin = INIT_CWMIN;
671 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
673 cwMin = qi->tqi_cwmin;
675 REG_WRITE(ah, AR_DLCL_IFS(q),
676 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
677 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
678 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
680 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
681 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
682 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
683 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
685 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
686 REG_WRITE(ah, AR_DMISC(q),
687 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
689 if (qi->tqi_cbrPeriod) {
690 REG_WRITE(ah, AR_QCBRCFG(q),
691 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
692 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
693 REG_WRITE(ah, AR_QMISC(q),
694 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
695 (qi->tqi_cbrOverflowLimit ?
696 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
698 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
699 REG_WRITE(ah, AR_QRDYTIMECFG(q),
700 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
704 REG_WRITE(ah, AR_DCHNTIME(q),
705 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
706 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
708 if (qi->tqi_burstTime
709 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
710 REG_WRITE(ah, AR_QMISC(q),
711 REG_READ(ah, AR_QMISC(q)) |
712 AR_Q_MISC_RDYTIME_EXP_POLICY);
716 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
717 REG_WRITE(ah, AR_DMISC(q),
718 REG_READ(ah, AR_DMISC(q)) |
719 AR_D_MISC_POST_FR_BKOFF_DIS);
721 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
722 REG_WRITE(ah, AR_DMISC(q),
723 REG_READ(ah, AR_DMISC(q)) |
724 AR_D_MISC_FRAG_BKOFF_EN);
726 switch (qi->tqi_type) {
727 case ATH9K_TX_QUEUE_BEACON:
728 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
729 | AR_Q_MISC_FSP_DBA_GATED
730 | AR_Q_MISC_BEACON_USE
731 | AR_Q_MISC_CBR_INCR_DIS1);
733 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
734 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
735 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
736 | AR_D_MISC_BEACON_USE
737 | AR_D_MISC_POST_FR_BKOFF_DIS);
739 case ATH9K_TX_QUEUE_CAB:
740 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
741 | AR_Q_MISC_FSP_DBA_GATED
742 | AR_Q_MISC_CBR_INCR_DIS1
743 | AR_Q_MISC_CBR_INCR_DIS0);
744 value = (qi->tqi_readyTime -
745 (ah->config.sw_beacon_response_time -
746 ah->config.dma_beacon_response_time) -
747 ah->config.additional_swba_backoff) * 1024;
748 REG_WRITE(ah, AR_QRDYTIMECFG(q),
749 value | AR_Q_RDYTIMECFG_EN);
750 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
751 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
752 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
754 case ATH9K_TX_QUEUE_PSPOLL:
755 REG_WRITE(ah, AR_QMISC(q),
756 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
758 case ATH9K_TX_QUEUE_UAPSD:
759 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
760 AR_D_MISC_POST_FR_BKOFF_DIS);
766 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
767 REG_WRITE(ah, AR_DMISC(q),
768 REG_READ(ah, AR_DMISC(q)) |
769 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
770 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
771 AR_D_MISC_POST_FR_BKOFF_DIS);
774 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
775 ah->txok_interrupt_mask |= 1 << q;
777 ah->txok_interrupt_mask &= ~(1 << q);
778 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
779 ah->txerr_interrupt_mask |= 1 << q;
781 ah->txerr_interrupt_mask &= ~(1 << q);
782 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
783 ah->txdesc_interrupt_mask |= 1 << q;
785 ah->txdesc_interrupt_mask &= ~(1 << q);
786 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
787 ah->txeol_interrupt_mask |= 1 << q;
789 ah->txeol_interrupt_mask &= ~(1 << q);
790 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
791 ah->txurn_interrupt_mask |= 1 << q;
793 ah->txurn_interrupt_mask &= ~(1 << q);
794 ath9k_hw_set_txq_interrupts(ah, qi);
799 int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
800 u32 pa, struct ath_desc *nds, u64 tsf)
802 struct ar5416_desc ads;
803 struct ar5416_desc *adsp = AR5416DESC(ds);
806 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
809 ads.u.rx = adsp->u.rx;
811 ds->ds_rxstat.rs_status = 0;
812 ds->ds_rxstat.rs_flags = 0;
814 ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
815 ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp;
817 ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
818 ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
819 ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
820 ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
821 ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
822 ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
823 ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
824 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
825 ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
827 ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID;
829 ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
830 ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
832 ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
833 ds->ds_rxstat.rs_moreaggr =
834 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
835 ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
836 ds->ds_rxstat.rs_flags =
837 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
838 ds->ds_rxstat.rs_flags |=
839 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
841 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
842 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
843 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
844 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
845 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
846 ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
848 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
849 if (ads.ds_rxstatus8 & AR_CRCErr)
850 ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
851 else if (ads.ds_rxstatus8 & AR_PHYErr) {
852 ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
853 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
854 ds->ds_rxstat.rs_phyerr = phyerr;
855 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
856 ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
857 else if (ads.ds_rxstatus8 & AR_MichaelErr)
858 ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
864 bool ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
867 struct ar5416_desc *ads = AR5416DESC(ds);
868 struct ath9k_hw_capabilities *pCap = &ah->caps;
870 ads->ds_ctl1 = size & AR_BufLen;
871 if (flags & ATH9K_RXDESC_INTREQ)
872 ads->ds_ctl1 |= AR_RxIntrReq;
874 ads->ds_rxstatus8 &= ~AR_RxDone;
875 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
876 memset(&(ads->u), 0, sizeof(ads->u));
881 bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
886 REG_SET_BIT(ah, AR_DIAG_SW,
887 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
889 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 0)) {
890 REG_CLR_BIT(ah, AR_DIAG_SW,
894 reg = REG_READ(ah, AR_OBS_BUS_1);
895 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
896 "rx failed to go idle in 10 ms RXSM=0x%x\n", reg);
901 REG_CLR_BIT(ah, AR_DIAG_SW,
902 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
908 void ath9k_hw_putrxbuf(struct ath_hw *ah, u32 rxdp)
910 REG_WRITE(ah, AR_RXDP, rxdp);
913 void ath9k_hw_rxena(struct ath_hw *ah)
915 REG_WRITE(ah, AR_CR, AR_CR_RXE);
918 void ath9k_hw_startpcureceive(struct ath_hw *ah)
920 ath9k_enable_mib_counters(ah);
924 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
927 void ath9k_hw_stoppcurecv(struct ath_hw *ah)
929 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
931 ath9k_hw_disable_mib_counters(ah);
934 bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
936 REG_WRITE(ah, AR_CR, AR_CR_RXD);
938 if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0)) {
939 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
940 "dma failed to stop in 10ms\n"
941 "AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n",
942 REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));