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);
347 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
348 ds_ctl0 = ads->ds_ctl0;
350 if (flags & ATH9K_TXDESC_RTSENA) {
351 ds_ctl0 &= ~AR_CTSEnable;
352 ds_ctl0 |= AR_RTSEnable;
354 ds_ctl0 &= ~AR_RTSEnable;
355 ds_ctl0 |= AR_CTSEnable;
358 ads->ds_ctl0 = ds_ctl0;
361 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
364 ads->ds_ctl2 = set11nTries(series, 0)
365 | set11nTries(series, 1)
366 | set11nTries(series, 2)
367 | set11nTries(series, 3)
368 | (durUpdateEn ? AR_DurUpdateEna : 0)
369 | SM(0, AR_BurstDur);
371 ads->ds_ctl3 = set11nRate(series, 0)
372 | set11nRate(series, 1)
373 | set11nRate(series, 2)
374 | set11nRate(series, 3);
376 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
377 | set11nPktDurRTSCTS(series, 1);
379 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
380 | set11nPktDurRTSCTS(series, 3);
382 ads->ds_ctl7 = set11nRateFlags(series, 0)
383 | set11nRateFlags(series, 1)
384 | set11nRateFlags(series, 2)
385 | set11nRateFlags(series, 3)
386 | SM(rtsctsRate, AR_RTSCTSRate);
387 last_ads->ds_ctl2 = ads->ds_ctl2;
388 last_ads->ds_ctl3 = ads->ds_ctl3;
391 void ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds,
394 struct ar5416_desc *ads = AR5416DESC(ds);
396 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
397 ads->ds_ctl6 &= ~AR_AggrLen;
398 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
401 void ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds,
404 struct ar5416_desc *ads = AR5416DESC(ds);
407 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
410 ctl6 &= ~AR_PadDelim;
411 ctl6 |= SM(numDelims, AR_PadDelim);
415 void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds)
417 struct ar5416_desc *ads = AR5416DESC(ds);
419 ads->ds_ctl1 |= AR_IsAggr;
420 ads->ds_ctl1 &= ~AR_MoreAggr;
421 ads->ds_ctl6 &= ~AR_PadDelim;
424 void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds)
426 struct ar5416_desc *ads = AR5416DESC(ds);
428 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
431 void ath9k_hw_set11n_burstduration(struct ath_hal *ah, struct ath_desc *ds,
434 struct ar5416_desc *ads = AR5416DESC(ds);
436 ads->ds_ctl2 &= ~AR_BurstDur;
437 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
440 void ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah, struct ath_desc *ds,
443 struct ar5416_desc *ads = AR5416DESC(ds);
446 ads->ds_ctl0 |= AR_VirtMoreFrag;
448 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
451 void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs)
453 struct ath_hal_5416 *ahp = AH5416(ah);
455 *txqs &= ahp->ah_intrTxqs;
456 ahp->ah_intrTxqs &= ~(*txqs);
459 bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q,
460 const struct ath9k_tx_queue_info *qinfo)
463 struct ath_hal_5416 *ahp = AH5416(ah);
464 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
465 struct ath9k_tx_queue_info *qi;
467 if (q >= pCap->total_queues) {
468 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
472 qi = &ahp->ah_txq[q];
473 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
474 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
478 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %p\n", qi);
480 qi->tqi_ver = qinfo->tqi_ver;
481 qi->tqi_subtype = qinfo->tqi_subtype;
482 qi->tqi_qflags = qinfo->tqi_qflags;
483 qi->tqi_priority = qinfo->tqi_priority;
484 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
485 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
487 qi->tqi_aifs = INIT_AIFS;
488 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
489 cw = min(qinfo->tqi_cwmin, 1024U);
491 while (qi->tqi_cwmin < cw)
492 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
494 qi->tqi_cwmin = qinfo->tqi_cwmin;
495 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
496 cw = min(qinfo->tqi_cwmax, 1024U);
498 while (qi->tqi_cwmax < cw)
499 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
501 qi->tqi_cwmax = INIT_CWMAX;
503 if (qinfo->tqi_shretry != 0)
504 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
506 qi->tqi_shretry = INIT_SH_RETRY;
507 if (qinfo->tqi_lgretry != 0)
508 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
510 qi->tqi_lgretry = INIT_LG_RETRY;
511 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
512 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
513 qi->tqi_burstTime = qinfo->tqi_burstTime;
514 qi->tqi_readyTime = qinfo->tqi_readyTime;
516 switch (qinfo->tqi_subtype) {
518 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
519 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
528 bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q,
529 struct ath9k_tx_queue_info *qinfo)
531 struct ath_hal_5416 *ahp = AH5416(ah);
532 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
533 struct ath9k_tx_queue_info *qi;
535 if (q >= pCap->total_queues) {
536 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
540 qi = &ahp->ah_txq[q];
541 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
542 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n");
546 qinfo->tqi_qflags = qi->tqi_qflags;
547 qinfo->tqi_ver = qi->tqi_ver;
548 qinfo->tqi_subtype = qi->tqi_subtype;
549 qinfo->tqi_qflags = qi->tqi_qflags;
550 qinfo->tqi_priority = qi->tqi_priority;
551 qinfo->tqi_aifs = qi->tqi_aifs;
552 qinfo->tqi_cwmin = qi->tqi_cwmin;
553 qinfo->tqi_cwmax = qi->tqi_cwmax;
554 qinfo->tqi_shretry = qi->tqi_shretry;
555 qinfo->tqi_lgretry = qi->tqi_lgretry;
556 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
557 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
558 qinfo->tqi_burstTime = qi->tqi_burstTime;
559 qinfo->tqi_readyTime = qi->tqi_readyTime;
564 int ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type,
565 const struct ath9k_tx_queue_info *qinfo)
567 struct ath_hal_5416 *ahp = AH5416(ah);
568 struct ath9k_tx_queue_info *qi;
569 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
573 case ATH9K_TX_QUEUE_BEACON:
574 q = pCap->total_queues - 1;
576 case ATH9K_TX_QUEUE_CAB:
577 q = pCap->total_queues - 2;
579 case ATH9K_TX_QUEUE_PSPOLL:
582 case ATH9K_TX_QUEUE_UAPSD:
583 q = pCap->total_queues - 3;
585 case ATH9K_TX_QUEUE_DATA:
586 for (q = 0; q < pCap->total_queues; q++)
587 if (ahp->ah_txq[q].tqi_type ==
588 ATH9K_TX_QUEUE_INACTIVE)
590 if (q == pCap->total_queues) {
591 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
592 "no available tx queue\n");
597 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "bad tx queue type %u\n", type);
601 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q);
603 qi = &ahp->ah_txq[q];
604 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
605 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
606 "tx queue %u already active\n", q);
609 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
613 TXQ_FLAG_TXOKINT_ENABLE
614 | TXQ_FLAG_TXERRINT_ENABLE
615 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
616 qi->tqi_aifs = INIT_AIFS;
617 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
618 qi->tqi_cwmax = INIT_CWMAX;
619 qi->tqi_shretry = INIT_SH_RETRY;
620 qi->tqi_lgretry = INIT_LG_RETRY;
621 qi->tqi_physCompBuf = 0;
623 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
624 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
630 bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q)
632 struct ath_hal_5416 *ahp = AH5416(ah);
633 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
634 struct ath9k_tx_queue_info *qi;
636 if (q >= pCap->total_queues) {
637 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
640 qi = &ahp->ah_txq[q];
641 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
642 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
646 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "release queue %u\n", q);
648 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
649 ahp->ah_txOkInterruptMask &= ~(1 << q);
650 ahp->ah_txErrInterruptMask &= ~(1 << q);
651 ahp->ah_txDescInterruptMask &= ~(1 << q);
652 ahp->ah_txEolInterruptMask &= ~(1 << q);
653 ahp->ah_txUrnInterruptMask &= ~(1 << q);
654 ath9k_hw_set_txq_interrupts(ah, qi);
659 bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q)
661 struct ath_hal_5416 *ahp = AH5416(ah);
662 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
663 struct ath9k_channel *chan = ah->ah_curchan;
664 struct ath9k_tx_queue_info *qi;
665 u32 cwMin, chanCwMin, value;
667 if (q >= pCap->total_queues) {
668 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q);
672 qi = &ahp->ah_txq[q];
673 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
674 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q);
678 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "reset queue %u\n", q);
680 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
681 if (chan && IS_CHAN_B(chan))
682 chanCwMin = INIT_CWMIN_11B;
684 chanCwMin = INIT_CWMIN;
686 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
688 cwMin = qi->tqi_cwmin;
690 REG_WRITE(ah, AR_DLCL_IFS(q),
691 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
692 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
693 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
695 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
696 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
697 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
698 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
700 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
701 REG_WRITE(ah, AR_DMISC(q),
702 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
704 if (qi->tqi_cbrPeriod) {
705 REG_WRITE(ah, AR_QCBRCFG(q),
706 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
707 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
708 REG_WRITE(ah, AR_QMISC(q),
709 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
710 (qi->tqi_cbrOverflowLimit ?
711 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
713 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
714 REG_WRITE(ah, AR_QRDYTIMECFG(q),
715 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
719 REG_WRITE(ah, AR_DCHNTIME(q),
720 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
721 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
723 if (qi->tqi_burstTime
724 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
725 REG_WRITE(ah, AR_QMISC(q),
726 REG_READ(ah, AR_QMISC(q)) |
727 AR_Q_MISC_RDYTIME_EXP_POLICY);
731 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
732 REG_WRITE(ah, AR_DMISC(q),
733 REG_READ(ah, AR_DMISC(q)) |
734 AR_D_MISC_POST_FR_BKOFF_DIS);
736 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
737 REG_WRITE(ah, AR_DMISC(q),
738 REG_READ(ah, AR_DMISC(q)) |
739 AR_D_MISC_FRAG_BKOFF_EN);
741 switch (qi->tqi_type) {
742 case ATH9K_TX_QUEUE_BEACON:
743 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
744 | AR_Q_MISC_FSP_DBA_GATED
745 | AR_Q_MISC_BEACON_USE
746 | AR_Q_MISC_CBR_INCR_DIS1);
748 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
749 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
750 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
751 | AR_D_MISC_BEACON_USE
752 | AR_D_MISC_POST_FR_BKOFF_DIS);
754 case ATH9K_TX_QUEUE_CAB:
755 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
756 | AR_Q_MISC_FSP_DBA_GATED
757 | AR_Q_MISC_CBR_INCR_DIS1
758 | AR_Q_MISC_CBR_INCR_DIS0);
759 value = (qi->tqi_readyTime -
760 (ah->ah_config.sw_beacon_response_time -
761 ah->ah_config.dma_beacon_response_time) -
762 ah->ah_config.additional_swba_backoff) * 1024;
763 REG_WRITE(ah, AR_QRDYTIMECFG(q),
764 value | AR_Q_RDYTIMECFG_EN);
765 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
766 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
767 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
769 case ATH9K_TX_QUEUE_PSPOLL:
770 REG_WRITE(ah, AR_QMISC(q),
771 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
773 case ATH9K_TX_QUEUE_UAPSD:
774 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
775 AR_D_MISC_POST_FR_BKOFF_DIS);
781 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
782 REG_WRITE(ah, AR_DMISC(q),
783 REG_READ(ah, AR_DMISC(q)) |
784 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
785 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
786 AR_D_MISC_POST_FR_BKOFF_DIS);
789 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
790 ahp->ah_txOkInterruptMask |= 1 << q;
792 ahp->ah_txOkInterruptMask &= ~(1 << q);
793 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
794 ahp->ah_txErrInterruptMask |= 1 << q;
796 ahp->ah_txErrInterruptMask &= ~(1 << q);
797 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
798 ahp->ah_txDescInterruptMask |= 1 << q;
800 ahp->ah_txDescInterruptMask &= ~(1 << q);
801 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
802 ahp->ah_txEolInterruptMask |= 1 << q;
804 ahp->ah_txEolInterruptMask &= ~(1 << q);
805 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
806 ahp->ah_txUrnInterruptMask |= 1 << q;
808 ahp->ah_txUrnInterruptMask &= ~(1 << q);
809 ath9k_hw_set_txq_interrupts(ah, qi);
814 int ath9k_hw_rxprocdesc(struct ath_hal *ah, struct ath_desc *ds,
815 u32 pa, struct ath_desc *nds, u64 tsf)
817 struct ar5416_desc ads;
818 struct ar5416_desc *adsp = AR5416DESC(ds);
821 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
824 ads.u.rx = adsp->u.rx;
826 ds->ds_rxstat.rs_status = 0;
827 ds->ds_rxstat.rs_flags = 0;
829 ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
830 ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp;
832 ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
833 ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
834 ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
835 ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
836 ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
837 ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
838 ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
839 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
840 ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
842 ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID;
844 ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
845 ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
847 ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
848 ds->ds_rxstat.rs_moreaggr =
849 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
850 ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
851 ds->ds_rxstat.rs_flags =
852 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
853 ds->ds_rxstat.rs_flags |=
854 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
856 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
857 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
858 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
859 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
860 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
861 ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
863 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
864 if (ads.ds_rxstatus8 & AR_CRCErr)
865 ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
866 else if (ads.ds_rxstatus8 & AR_PHYErr) {
867 ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
868 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
869 ds->ds_rxstat.rs_phyerr = phyerr;
870 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
871 ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
872 else if (ads.ds_rxstatus8 & AR_MichaelErr)
873 ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
879 bool ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds,
882 struct ar5416_desc *ads = AR5416DESC(ds);
883 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
885 ads->ds_ctl1 = size & AR_BufLen;
886 if (flags & ATH9K_RXDESC_INTREQ)
887 ads->ds_ctl1 |= AR_RxIntrReq;
889 ads->ds_rxstatus8 &= ~AR_RxDone;
890 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
891 memset(&(ads->u), 0, sizeof(ads->u));
896 bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set)
901 REG_SET_BIT(ah, AR_DIAG_SW,
902 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
904 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 0)) {
905 REG_CLR_BIT(ah, AR_DIAG_SW,
909 reg = REG_READ(ah, AR_OBS_BUS_1);
910 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
911 "rx failed to go idle in 10 ms RXSM=0x%x\n", reg);
916 REG_CLR_BIT(ah, AR_DIAG_SW,
917 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
923 void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp)
925 REG_WRITE(ah, AR_RXDP, rxdp);
928 void ath9k_hw_rxena(struct ath_hal *ah)
930 REG_WRITE(ah, AR_CR, AR_CR_RXE);
933 void ath9k_hw_startpcureceive(struct ath_hal *ah)
935 ath9k_enable_mib_counters(ah);
939 REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
942 void ath9k_hw_stoppcurecv(struct ath_hal *ah)
944 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
946 ath9k_hw_disable_mib_counters(ah);
949 bool ath9k_hw_stopdmarecv(struct ath_hal *ah)
951 REG_WRITE(ah, AR_CR, AR_CR_RXD);
953 if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0)) {
954 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
955 "dma failed to stop in 10ms\n"
956 "AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n",
957 REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));