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.
22 static void ath9k_hw_set_txq_interrupts(struct ath_hal *ah,
23 struct ath9k_tx_queue_info *qi)
25 struct ath_hal_5416 *ahp = AH5416(ah);
27 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
28 "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
29 ahp->ah_txOkInterruptMask, ahp->ah_txErrInterruptMask,
30 ahp->ah_txDescInterruptMask, ahp->ah_txEolInterruptMask,
31 ahp->ah_txUrnInterruptMask);
33 REG_WRITE(ah, AR_IMR_S0,
34 SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK)
35 | SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC));
36 REG_WRITE(ah, AR_IMR_S1,
37 SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR)
38 | SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL));
39 REG_RMW_FIELD(ah, AR_IMR_S2,
40 AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask);
43 u32 ath9k_hw_gettxbuf(struct ath_hal *ah, u32 q)
45 return REG_READ(ah, AR_QTXDP(q));
48 bool ath9k_hw_puttxbuf(struct ath_hal *ah, u32 q, u32 txdp)
50 REG_WRITE(ah, AR_QTXDP(q), txdp);
55 bool ath9k_hw_txstart(struct ath_hal *ah, u32 q)
57 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q);
59 REG_WRITE(ah, AR_Q_TXE, 1 << q);
64 u32 ath9k_hw_numtxpending(struct ath_hal *ah, u32 q)
68 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
71 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
78 bool ath9k_hw_updatetxtriglevel(struct ath_hal *ah, bool bIncTrigLevel)
80 struct ath_hal_5416 *ahp = AH5416(ah);
81 u32 txcfg, curLevel, newLevel;
84 if (ah->ah_txTrigLevel >= MAX_TX_FIFO_THRESHOLD)
87 omask = ath9k_hw_set_interrupts(ah, ahp->ah_maskReg & ~ATH9K_INT_GLOBAL);
89 txcfg = REG_READ(ah, AR_TXCFG);
90 curLevel = MS(txcfg, AR_FTRIG);
93 if (curLevel < MAX_TX_FIFO_THRESHOLD)
95 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
97 if (newLevel != curLevel)
98 REG_WRITE(ah, AR_TXCFG,
99 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
101 ath9k_hw_set_interrupts(ah, omask);
103 ah->ah_txTrigLevel = newLevel;
105 return newLevel != curLevel;
108 bool ath9k_hw_stoptxdma(struct ath_hal *ah, u32 q)
110 #define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */
111 #define ATH9K_TIME_QUANTUM 100 /* usec */
113 struct ath_hal_5416 *ahp = AH5416(ah);
114 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
115 struct ath9k_tx_queue_info *qi;
117 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
119 if (q >= pCap->total_queues) {
120 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
124 qi = &ahp->ah_txq[q];
125 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
126 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
130 REG_WRITE(ah, AR_Q_TXD, 1 << q);
132 for (wait = wait_time; wait != 0; wait--) {
133 if (ath9k_hw_numtxpending(ah, q) == 0)
135 udelay(ATH9K_TIME_QUANTUM);
138 if (ath9k_hw_numtxpending(ah, q)) {
139 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
140 "%s: Num of pending TX Frames %d on Q %d\n",
141 __func__, ath9k_hw_numtxpending(ah, q), q);
143 for (j = 0; j < 2; j++) {
144 tsfLow = REG_READ(ah, AR_TSF_L32);
145 REG_WRITE(ah, AR_QUIET2,
146 SM(10, AR_QUIET2_QUIET_DUR));
147 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
148 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
149 REG_SET_BIT(ah, AR_TIMER_MODE,
152 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
155 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
156 "TSF have moved while trying to set "
157 "quiet time TSF: 0x%08x\n", tsfLow);
160 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
163 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
166 while (ath9k_hw_numtxpending(ah, q)) {
168 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
169 "Failed to stop Tx DMA in 100 "
170 "msec after killing last frame\n");
173 udelay(ATH9K_TIME_QUANTUM);
176 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
179 REG_WRITE(ah, AR_Q_TXD, 0);
182 #undef ATH9K_TX_STOP_DMA_TIMEOUT
183 #undef ATH9K_TIME_QUANTUM
186 bool ath9k_hw_filltxdesc(struct ath_hal *ah, struct ath_desc *ds,
187 u32 segLen, bool firstSeg,
188 bool lastSeg, const struct ath_desc *ds0)
190 struct ar5416_desc *ads = AR5416DESC(ds);
193 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
194 } else if (lastSeg) {
196 ads->ds_ctl1 = segLen;
197 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
198 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
201 ads->ds_ctl1 = segLen | AR_TxMore;
205 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
206 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
207 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
208 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
209 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
214 void ath9k_hw_cleartxdesc(struct ath_hal *ah, struct ath_desc *ds)
216 struct ar5416_desc *ads = AR5416DESC(ds);
218 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
219 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
220 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
221 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
222 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
225 int ath9k_hw_txprocdesc(struct ath_hal *ah, struct ath_desc *ds)
227 struct ar5416_desc *ads = AR5416DESC(ds);
229 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
232 ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
233 ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
234 ds->ds_txstat.ts_status = 0;
235 ds->ds_txstat.ts_flags = 0;
237 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
238 ds->ds_txstat.ts_status |= ATH9K_TXERR_XRETRY;
239 if (ads->ds_txstatus1 & AR_Filtered)
240 ds->ds_txstat.ts_status |= ATH9K_TXERR_FILT;
241 if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
242 ds->ds_txstat.ts_status |= ATH9K_TXERR_FIFO;
243 ath9k_hw_updatetxtriglevel(ah, true);
245 if (ads->ds_txstatus9 & AR_TxOpExceeded)
246 ds->ds_txstat.ts_status |= ATH9K_TXERR_XTXOP;
247 if (ads->ds_txstatus1 & AR_TxTimerExpired)
248 ds->ds_txstat.ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
250 if (ads->ds_txstatus1 & AR_DescCfgErr)
251 ds->ds_txstat.ts_flags |= ATH9K_TX_DESC_CFG_ERR;
252 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
253 ds->ds_txstat.ts_flags |= ATH9K_TX_DATA_UNDERRUN;
254 ath9k_hw_updatetxtriglevel(ah, true);
256 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
257 ds->ds_txstat.ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
258 ath9k_hw_updatetxtriglevel(ah, true);
260 if (ads->ds_txstatus0 & AR_TxBaStatus) {
261 ds->ds_txstat.ts_flags |= ATH9K_TX_BA;
262 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
263 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
266 ds->ds_txstat.ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
267 switch (ds->ds_txstat.ts_rateindex) {
269 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
272 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
275 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
278 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
282 ds->ds_txstat.ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
283 ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
284 ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
285 ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
286 ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
287 ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
288 ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
289 ds->ds_txstat.evm0 = ads->AR_TxEVM0;
290 ds->ds_txstat.evm1 = ads->AR_TxEVM1;
291 ds->ds_txstat.evm2 = ads->AR_TxEVM2;
292 ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
293 ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
294 ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
295 ds->ds_txstat.ts_antenna = 1;
300 void ath9k_hw_set11n_txdesc(struct ath_hal *ah, struct ath_desc *ds,
301 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
302 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
304 struct ar5416_desc *ads = AR5416DESC(ds);
305 struct ath_hal_5416 *ahp = AH5416(ah);
307 txPower += ahp->ah_txPowerIndexOffset;
311 ads->ds_ctl0 = (pktLen & AR_FrameLen)
312 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
313 | SM(txPower, AR_XmitPower)
314 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
315 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
316 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
317 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
320 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
321 | SM(type, AR_FrameType)
322 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
323 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
324 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
326 ads->ds_ctl6 = SM(keyType, AR_EncrType);
328 if (AR_SREV_9285(ah)) {
336 void ath9k_hw_set11n_ratescenario(struct ath_hal *ah, struct ath_desc *ds,
337 struct ath_desc *lastds,
338 u32 durUpdateEn, u32 rtsctsRate,
340 struct ath9k_11n_rate_series series[],
341 u32 nseries, u32 flags)
343 struct ar5416_desc *ads = AR5416DESC(ds);
344 struct ar5416_desc *last_ads = AR5416DESC(lastds);
348 (void) rtsctsDuration;
350 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
351 ds_ctl0 = ads->ds_ctl0;
353 if (flags & ATH9K_TXDESC_RTSENA) {
354 ds_ctl0 &= ~AR_CTSEnable;
355 ds_ctl0 |= AR_RTSEnable;
357 ds_ctl0 &= ~AR_RTSEnable;
358 ds_ctl0 |= AR_CTSEnable;
361 ads->ds_ctl0 = ds_ctl0;
364 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
367 ads->ds_ctl2 = set11nTries(series, 0)
368 | set11nTries(series, 1)
369 | set11nTries(series, 2)
370 | set11nTries(series, 3)
371 | (durUpdateEn ? AR_DurUpdateEna : 0)
372 | SM(0, AR_BurstDur);
374 ads->ds_ctl3 = set11nRate(series, 0)
375 | set11nRate(series, 1)
376 | set11nRate(series, 2)
377 | set11nRate(series, 3);
379 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
380 | set11nPktDurRTSCTS(series, 1);
382 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
383 | set11nPktDurRTSCTS(series, 3);
385 ads->ds_ctl7 = set11nRateFlags(series, 0)
386 | set11nRateFlags(series, 1)
387 | set11nRateFlags(series, 2)
388 | set11nRateFlags(series, 3)
389 | SM(rtsctsRate, AR_RTSCTSRate);
390 last_ads->ds_ctl2 = ads->ds_ctl2;
391 last_ads->ds_ctl3 = ads->ds_ctl3;
394 void ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds,
397 struct ar5416_desc *ads = AR5416DESC(ds);
399 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
400 ads->ds_ctl6 &= ~AR_AggrLen;
401 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
404 void ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds,
407 struct ar5416_desc *ads = AR5416DESC(ds);
410 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
413 ctl6 &= ~AR_PadDelim;
414 ctl6 |= SM(numDelims, AR_PadDelim);
418 void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds)
420 struct ar5416_desc *ads = AR5416DESC(ds);
422 ads->ds_ctl1 |= AR_IsAggr;
423 ads->ds_ctl1 &= ~AR_MoreAggr;
424 ads->ds_ctl6 &= ~AR_PadDelim;
427 void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds)
429 struct ar5416_desc *ads = AR5416DESC(ds);
431 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
434 void ath9k_hw_set11n_burstduration(struct ath_hal *ah, struct ath_desc *ds,
437 struct ar5416_desc *ads = AR5416DESC(ds);
439 ads->ds_ctl2 &= ~AR_BurstDur;
440 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
443 void ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah, struct ath_desc *ds,
446 struct ar5416_desc *ads = AR5416DESC(ds);
449 ads->ds_ctl0 |= AR_VirtMoreFrag;
451 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
454 void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs)
456 struct ath_hal_5416 *ahp = AH5416(ah);
458 *txqs &= ahp->ah_intrTxqs;
459 ahp->ah_intrTxqs &= ~(*txqs);
462 bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q,
463 const struct ath9k_tx_queue_info *qinfo)
466 struct ath_hal_5416 *ahp = AH5416(ah);
467 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
468 struct ath9k_tx_queue_info *qi;
470 if (q >= pCap->total_queues) {
471 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
475 qi = &ahp->ah_txq[q];
476 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
477 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
481 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %p\n", qi);
483 qi->tqi_ver = qinfo->tqi_ver;
484 qi->tqi_subtype = qinfo->tqi_subtype;
485 qi->tqi_qflags = qinfo->tqi_qflags;
486 qi->tqi_priority = qinfo->tqi_priority;
487 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
488 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
490 qi->tqi_aifs = INIT_AIFS;
491 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
492 cw = min(qinfo->tqi_cwmin, 1024U);
494 while (qi->tqi_cwmin < cw)
495 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
497 qi->tqi_cwmin = qinfo->tqi_cwmin;
498 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
499 cw = min(qinfo->tqi_cwmax, 1024U);
501 while (qi->tqi_cwmax < cw)
502 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
504 qi->tqi_cwmax = INIT_CWMAX;
506 if (qinfo->tqi_shretry != 0)
507 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
509 qi->tqi_shretry = INIT_SH_RETRY;
510 if (qinfo->tqi_lgretry != 0)
511 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
513 qi->tqi_lgretry = INIT_LG_RETRY;
514 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
515 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
516 qi->tqi_burstTime = qinfo->tqi_burstTime;
517 qi->tqi_readyTime = qinfo->tqi_readyTime;
519 switch (qinfo->tqi_subtype) {
521 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
522 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
531 bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q,
532 struct ath9k_tx_queue_info *qinfo)
534 struct ath_hal_5416 *ahp = AH5416(ah);
535 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
536 struct ath9k_tx_queue_info *qi;
538 if (q >= pCap->total_queues) {
539 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
543 qi = &ahp->ah_txq[q];
544 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
545 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
549 qinfo->tqi_qflags = qi->tqi_qflags;
550 qinfo->tqi_ver = qi->tqi_ver;
551 qinfo->tqi_subtype = qi->tqi_subtype;
552 qinfo->tqi_qflags = qi->tqi_qflags;
553 qinfo->tqi_priority = qi->tqi_priority;
554 qinfo->tqi_aifs = qi->tqi_aifs;
555 qinfo->tqi_cwmin = qi->tqi_cwmin;
556 qinfo->tqi_cwmax = qi->tqi_cwmax;
557 qinfo->tqi_shretry = qi->tqi_shretry;
558 qinfo->tqi_lgretry = qi->tqi_lgretry;
559 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
560 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
561 qinfo->tqi_burstTime = qi->tqi_burstTime;
562 qinfo->tqi_readyTime = qi->tqi_readyTime;
567 int ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type,
568 const struct ath9k_tx_queue_info *qinfo)
570 struct ath_hal_5416 *ahp = AH5416(ah);
571 struct ath9k_tx_queue_info *qi;
572 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
576 case ATH9K_TX_QUEUE_BEACON:
577 q = pCap->total_queues - 1;
579 case ATH9K_TX_QUEUE_CAB:
580 q = pCap->total_queues - 2;
582 case ATH9K_TX_QUEUE_PSPOLL:
585 case ATH9K_TX_QUEUE_UAPSD:
586 q = pCap->total_queues - 3;
588 case ATH9K_TX_QUEUE_DATA:
589 for (q = 0; q < pCap->total_queues; q++)
590 if (ahp->ah_txq[q].tqi_type ==
591 ATH9K_TX_QUEUE_INACTIVE)
593 if (q == pCap->total_queues) {
594 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
595 "no available tx queue\n");
600 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "bad tx queue type %u\n", type);
604 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q);
606 qi = &ahp->ah_txq[q];
607 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
608 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
609 "tx queue %u already active\n", q);
612 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
616 TXQ_FLAG_TXOKINT_ENABLE
617 | TXQ_FLAG_TXERRINT_ENABLE
618 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
619 qi->tqi_aifs = INIT_AIFS;
620 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
621 qi->tqi_cwmax = INIT_CWMAX;
622 qi->tqi_shretry = INIT_SH_RETRY;
623 qi->tqi_lgretry = INIT_LG_RETRY;
624 qi->tqi_physCompBuf = 0;
626 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
627 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
633 bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q)
635 struct ath_hal_5416 *ahp = AH5416(ah);
636 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
637 struct ath9k_tx_queue_info *qi;
639 if (q >= pCap->total_queues) {
640 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
643 qi = &ahp->ah_txq[q];
644 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
645 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
649 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "release queue %u\n", q);
651 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
652 ahp->ah_txOkInterruptMask &= ~(1 << q);
653 ahp->ah_txErrInterruptMask &= ~(1 << q);
654 ahp->ah_txDescInterruptMask &= ~(1 << q);
655 ahp->ah_txEolInterruptMask &= ~(1 << q);
656 ahp->ah_txUrnInterruptMask &= ~(1 << q);
657 ath9k_hw_set_txq_interrupts(ah, qi);
662 bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q)
664 struct ath_hal_5416 *ahp = AH5416(ah);
665 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
666 struct ath9k_channel *chan = ah->ah_curchan;
667 struct ath9k_tx_queue_info *qi;
668 u32 cwMin, chanCwMin, value;
670 if (q >= pCap->total_queues) {
671 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
675 qi = &ahp->ah_txq[q];
676 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
677 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
681 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "reset queue %u\n", q);
683 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
684 if (chan && IS_CHAN_B(chan))
685 chanCwMin = INIT_CWMIN_11B;
687 chanCwMin = INIT_CWMIN;
689 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
691 cwMin = qi->tqi_cwmin;
693 REG_WRITE(ah, AR_DLCL_IFS(q),
694 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
695 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
696 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
698 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
699 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
700 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
701 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
703 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
704 REG_WRITE(ah, AR_DMISC(q),
705 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
707 if (qi->tqi_cbrPeriod) {
708 REG_WRITE(ah, AR_QCBRCFG(q),
709 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
710 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
711 REG_WRITE(ah, AR_QMISC(q),
712 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
713 (qi->tqi_cbrOverflowLimit ?
714 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
716 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
717 REG_WRITE(ah, AR_QRDYTIMECFG(q),
718 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
722 REG_WRITE(ah, AR_DCHNTIME(q),
723 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
724 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
726 if (qi->tqi_burstTime
727 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
728 REG_WRITE(ah, AR_QMISC(q),
729 REG_READ(ah, AR_QMISC(q)) |
730 AR_Q_MISC_RDYTIME_EXP_POLICY);
734 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
735 REG_WRITE(ah, AR_DMISC(q),
736 REG_READ(ah, AR_DMISC(q)) |
737 AR_D_MISC_POST_FR_BKOFF_DIS);
739 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
740 REG_WRITE(ah, AR_DMISC(q),
741 REG_READ(ah, AR_DMISC(q)) |
742 AR_D_MISC_FRAG_BKOFF_EN);
744 switch (qi->tqi_type) {
745 case ATH9K_TX_QUEUE_BEACON:
746 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
747 | AR_Q_MISC_FSP_DBA_GATED
748 | AR_Q_MISC_BEACON_USE
749 | AR_Q_MISC_CBR_INCR_DIS1);
751 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
752 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
753 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
754 | AR_D_MISC_BEACON_USE
755 | AR_D_MISC_POST_FR_BKOFF_DIS);
757 case ATH9K_TX_QUEUE_CAB:
758 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
759 | AR_Q_MISC_FSP_DBA_GATED
760 | AR_Q_MISC_CBR_INCR_DIS1
761 | AR_Q_MISC_CBR_INCR_DIS0);
762 value = (qi->tqi_readyTime -
763 (ah->ah_config.sw_beacon_response_time -
764 ah->ah_config.dma_beacon_response_time) -
765 ah->ah_config.additional_swba_backoff) * 1024;
766 REG_WRITE(ah, AR_QRDYTIMECFG(q),
767 value | AR_Q_RDYTIMECFG_EN);
768 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
769 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
770 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
772 case ATH9K_TX_QUEUE_PSPOLL:
773 REG_WRITE(ah, AR_QMISC(q),
774 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
776 case ATH9K_TX_QUEUE_UAPSD:
777 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
778 AR_D_MISC_POST_FR_BKOFF_DIS);
784 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
785 REG_WRITE(ah, AR_DMISC(q),
786 REG_READ(ah, AR_DMISC(q)) |
787 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
788 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
789 AR_D_MISC_POST_FR_BKOFF_DIS);
792 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
793 ahp->ah_txOkInterruptMask |= 1 << q;
795 ahp->ah_txOkInterruptMask &= ~(1 << q);
796 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
797 ahp->ah_txErrInterruptMask |= 1 << q;
799 ahp->ah_txErrInterruptMask &= ~(1 << q);
800 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
801 ahp->ah_txDescInterruptMask |= 1 << q;
803 ahp->ah_txDescInterruptMask &= ~(1 << q);
804 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
805 ahp->ah_txEolInterruptMask |= 1 << q;
807 ahp->ah_txEolInterruptMask &= ~(1 << q);
808 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
809 ahp->ah_txUrnInterruptMask |= 1 << q;
811 ahp->ah_txUrnInterruptMask &= ~(1 << q);
812 ath9k_hw_set_txq_interrupts(ah, qi);
817 int ath9k_hw_rxprocdesc(struct ath_hal *ah, struct ath_desc *ds,
818 u32 pa, struct ath_desc *nds, u64 tsf)
820 struct ar5416_desc ads;
821 struct ar5416_desc *adsp = AR5416DESC(ds);
824 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
827 ads.u.rx = adsp->u.rx;
829 ds->ds_rxstat.rs_status = 0;
830 ds->ds_rxstat.rs_flags = 0;
832 ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
833 ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp;
835 ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
836 ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
837 ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
838 ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
839 ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
840 ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
841 ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
842 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
843 ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
845 ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID;
847 ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
848 ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
850 ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
851 ds->ds_rxstat.rs_moreaggr =
852 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
853 ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
854 ds->ds_rxstat.rs_flags =
855 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
856 ds->ds_rxstat.rs_flags |=
857 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
859 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
860 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
861 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
862 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
863 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
864 ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
866 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
867 if (ads.ds_rxstatus8 & AR_CRCErr)
868 ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
869 else if (ads.ds_rxstatus8 & AR_PHYErr) {
870 ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
871 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
872 ds->ds_rxstat.rs_phyerr = phyerr;
873 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
874 ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
875 else if (ads.ds_rxstatus8 & AR_MichaelErr)
876 ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
882 bool ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds,
885 struct ar5416_desc *ads = AR5416DESC(ds);
886 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
888 ads->ds_ctl1 = size & AR_BufLen;
889 if (flags & ATH9K_RXDESC_INTREQ)
890 ads->ds_ctl1 |= AR_RxIntrReq;
892 ads->ds_rxstatus8 &= ~AR_RxDone;
893 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
894 memset(&(ads->u), 0, sizeof(ads->u));
899 bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set)
904 REG_SET_BIT(ah, AR_DIAG_SW,
905 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
907 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 0)) {
908 REG_CLR_BIT(ah, AR_DIAG_SW,
912 reg = REG_READ(ah, AR_OBS_BUS_1);
913 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
914 "rx failed to go idle in 10 ms RXSM=0x%x\n", reg);
919 REG_CLR_BIT(ah, AR_DIAG_SW,
920 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
926 void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp)
928 REG_WRITE(ah, AR_RXDP, rxdp);
931 void ath9k_hw_rxena(struct ath_hal *ah)
933 REG_WRITE(ah, AR_CR, AR_CR_RXE);
936 void ath9k_hw_startpcureceive(struct ath_hal *ah)
938 ath9k_enable_mib_counters(ah);
942 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
945 void ath9k_hw_stoppcurecv(struct ath_hal *ah)
947 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
949 ath9k_hw_disable_mib_counters(ah);
952 bool ath9k_hw_stopdmarecv(struct ath_hal *ah)
954 REG_WRITE(ah, AR_CR, AR_CR_RXD);
956 if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0)) {
957 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
958 "dma failed to stop in 10ms\n"
959 "AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n",
960 REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));