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 "%s: tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
29 __func__, ahp->ah_txOkInterruptMask,
30 ahp->ah_txErrInterruptMask, ahp->ah_txDescInterruptMask,
31 ahp->ah_txEolInterruptMask, 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 void ath9k_hw_dmaRegDump(struct ath_hal *ah)
45 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
46 int qcuOffset = 0, dcuOffset = 0;
47 u32 *qcuBase = &val[0], *dcuBase = &val[4];
50 REG_WRITE(ah, AR_MACMISC,
51 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
52 (AR_MACMISC_MISC_OBS_BUS_1 <<
53 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
55 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "Raw DMA Debug values:\n");
57 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
59 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n");
61 val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32)));
62 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "%d: %08x ", i, val[i]);
65 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n\n");
66 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
67 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
69 for (i = 0; i < ATH9K_NUM_QUEUES;
70 i++, qcuOffset += 4, dcuOffset += 5) {
81 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
82 "%2d %2x %1x %2x %2x\n",
83 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
84 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
85 val[2] & (0x7 << (i * 3)) >> (i * 3),
86 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
89 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n");
90 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
91 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
92 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
93 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
94 "qcu_complete state: %2x dcu_complete state: %2x\n",
95 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
96 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
97 "dcu_arb state: %2x dcu_fp state: %2x\n",
98 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
99 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
100 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
101 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
102 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
103 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
104 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
105 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
106 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
107 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
109 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "pcu observe 0x%x \n",
110 REG_READ(ah, AR_OBS_BUS_1));
111 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
112 "AR_CR 0x%x \n", REG_READ(ah, AR_CR));
115 u32 ath9k_hw_gettxbuf(struct ath_hal *ah, u32 q)
117 return REG_READ(ah, AR_QTXDP(q));
120 bool ath9k_hw_puttxbuf(struct ath_hal *ah, u32 q, u32 txdp)
122 REG_WRITE(ah, AR_QTXDP(q), txdp);
127 bool ath9k_hw_txstart(struct ath_hal *ah, u32 q)
129 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %u\n", __func__, q);
131 REG_WRITE(ah, AR_Q_TXE, 1 << q);
136 u32 ath9k_hw_numtxpending(struct ath_hal *ah, u32 q)
140 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
143 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
150 bool ath9k_hw_updatetxtriglevel(struct ath_hal *ah, bool bIncTrigLevel)
152 struct ath_hal_5416 *ahp = AH5416(ah);
153 u32 txcfg, curLevel, newLevel;
154 enum ath9k_int omask;
156 if (ah->ah_txTrigLevel >= MAX_TX_FIFO_THRESHOLD)
159 omask = ath9k_hw_set_interrupts(ah, ahp->ah_maskReg & ~ATH9K_INT_GLOBAL);
161 txcfg = REG_READ(ah, AR_TXCFG);
162 curLevel = MS(txcfg, AR_FTRIG);
165 if (curLevel < MAX_TX_FIFO_THRESHOLD)
167 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
169 if (newLevel != curLevel)
170 REG_WRITE(ah, AR_TXCFG,
171 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
173 ath9k_hw_set_interrupts(ah, omask);
175 ah->ah_txTrigLevel = newLevel;
177 return newLevel != curLevel;
180 bool ath9k_hw_stoptxdma(struct ath_hal *ah, u32 q)
184 REG_WRITE(ah, AR_Q_TXD, 1 << q);
186 for (wait = 1000; wait != 0; wait--) {
187 if (ath9k_hw_numtxpending(ah, q) == 0)
192 if (ath9k_hw_numtxpending(ah, q)) {
193 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
194 "%s: Num of pending TX Frames %d on Q %d\n",
195 __func__, ath9k_hw_numtxpending(ah, q), q);
197 for (j = 0; j < 2; j++) {
198 tsfLow = REG_READ(ah, AR_TSF_L32);
199 REG_WRITE(ah, AR_QUIET2,
200 SM(10, AR_QUIET2_QUIET_DUR));
201 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
202 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
203 REG_SET_BIT(ah, AR_TIMER_MODE,
206 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
209 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
210 "%s: TSF have moved while trying to set "
211 "quiet time TSF: 0x%08x\n",
215 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
218 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
222 while (ath9k_hw_numtxpending(ah, q)) {
224 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
225 "%s: Failed to stop Tx DMA in 100 "
226 "msec after killing last frame\n",
233 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
236 REG_WRITE(ah, AR_Q_TXD, 0);
241 bool ath9k_hw_filltxdesc(struct ath_hal *ah, struct ath_desc *ds,
242 u32 segLen, bool firstSeg,
243 bool lastSeg, const struct ath_desc *ds0)
245 struct ar5416_desc *ads = AR5416DESC(ds);
248 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
249 } else if (lastSeg) {
251 ads->ds_ctl1 = segLen;
252 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
253 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
256 ads->ds_ctl1 = segLen | AR_TxMore;
260 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
261 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
262 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
263 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
264 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
269 void ath9k_hw_cleartxdesc(struct ath_hal *ah, struct ath_desc *ds)
271 struct ar5416_desc *ads = AR5416DESC(ds);
273 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
274 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
275 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
276 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
277 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
280 int ath9k_hw_txprocdesc(struct ath_hal *ah, struct ath_desc *ds)
282 struct ar5416_desc *ads = AR5416DESC(ds);
284 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
287 ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
288 ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
289 ds->ds_txstat.ts_status = 0;
290 ds->ds_txstat.ts_flags = 0;
292 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
293 ds->ds_txstat.ts_status |= ATH9K_TXERR_XRETRY;
294 if (ads->ds_txstatus1 & AR_Filtered)
295 ds->ds_txstat.ts_status |= ATH9K_TXERR_FILT;
296 if (ads->ds_txstatus1 & AR_FIFOUnderrun) {
297 ds->ds_txstat.ts_status |= ATH9K_TXERR_FIFO;
298 ath9k_hw_updatetxtriglevel(ah, true);
300 if (ads->ds_txstatus9 & AR_TxOpExceeded)
301 ds->ds_txstat.ts_status |= ATH9K_TXERR_XTXOP;
302 if (ads->ds_txstatus1 & AR_TxTimerExpired)
303 ds->ds_txstat.ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
305 if (ads->ds_txstatus1 & AR_DescCfgErr)
306 ds->ds_txstat.ts_flags |= ATH9K_TX_DESC_CFG_ERR;
307 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
308 ds->ds_txstat.ts_flags |= ATH9K_TX_DATA_UNDERRUN;
309 ath9k_hw_updatetxtriglevel(ah, true);
311 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
312 ds->ds_txstat.ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
313 ath9k_hw_updatetxtriglevel(ah, true);
315 if (ads->ds_txstatus0 & AR_TxBaStatus) {
316 ds->ds_txstat.ts_flags |= ATH9K_TX_BA;
317 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
318 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
321 ds->ds_txstat.ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
322 switch (ds->ds_txstat.ts_rateindex) {
324 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
327 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
330 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
333 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
337 ds->ds_txstat.ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
338 ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
339 ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
340 ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
341 ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
342 ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
343 ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
344 ds->ds_txstat.evm0 = ads->AR_TxEVM0;
345 ds->ds_txstat.evm1 = ads->AR_TxEVM1;
346 ds->ds_txstat.evm2 = ads->AR_TxEVM2;
347 ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
348 ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
349 ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
350 ds->ds_txstat.ts_antenna = 1;
355 void ath9k_hw_set11n_txdesc(struct ath_hal *ah, struct ath_desc *ds,
356 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
357 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
359 struct ar5416_desc *ads = AR5416DESC(ds);
360 struct ath_hal_5416 *ahp = AH5416(ah);
362 txPower += ahp->ah_txPowerIndexOffset;
366 ads->ds_ctl0 = (pktLen & AR_FrameLen)
367 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
368 | SM(txPower, AR_XmitPower)
369 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
370 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
371 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
372 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
375 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
376 | SM(type, AR_FrameType)
377 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
378 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
379 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
381 ads->ds_ctl6 = SM(keyType, AR_EncrType);
383 if (AR_SREV_9285(ah)) {
391 void ath9k_hw_set11n_ratescenario(struct ath_hal *ah, struct ath_desc *ds,
392 struct ath_desc *lastds,
393 u32 durUpdateEn, u32 rtsctsRate,
395 struct ath9k_11n_rate_series series[],
396 u32 nseries, u32 flags)
398 struct ar5416_desc *ads = AR5416DESC(ds);
399 struct ar5416_desc *last_ads = AR5416DESC(lastds);
403 (void) rtsctsDuration;
405 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
406 ds_ctl0 = ads->ds_ctl0;
408 if (flags & ATH9K_TXDESC_RTSENA) {
409 ds_ctl0 &= ~AR_CTSEnable;
410 ds_ctl0 |= AR_RTSEnable;
412 ds_ctl0 &= ~AR_RTSEnable;
413 ds_ctl0 |= AR_CTSEnable;
416 ads->ds_ctl0 = ds_ctl0;
419 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
422 ads->ds_ctl2 = set11nTries(series, 0)
423 | set11nTries(series, 1)
424 | set11nTries(series, 2)
425 | set11nTries(series, 3)
426 | (durUpdateEn ? AR_DurUpdateEna : 0)
427 | SM(0, AR_BurstDur);
429 ads->ds_ctl3 = set11nRate(series, 0)
430 | set11nRate(series, 1)
431 | set11nRate(series, 2)
432 | set11nRate(series, 3);
434 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
435 | set11nPktDurRTSCTS(series, 1);
437 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
438 | set11nPktDurRTSCTS(series, 3);
440 ads->ds_ctl7 = set11nRateFlags(series, 0)
441 | set11nRateFlags(series, 1)
442 | set11nRateFlags(series, 2)
443 | set11nRateFlags(series, 3)
444 | SM(rtsctsRate, AR_RTSCTSRate);
445 last_ads->ds_ctl2 = ads->ds_ctl2;
446 last_ads->ds_ctl3 = ads->ds_ctl3;
449 void ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds,
452 struct ar5416_desc *ads = AR5416DESC(ds);
454 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
455 ads->ds_ctl6 &= ~AR_AggrLen;
456 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
459 void ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds,
462 struct ar5416_desc *ads = AR5416DESC(ds);
465 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
468 ctl6 &= ~AR_PadDelim;
469 ctl6 |= SM(numDelims, AR_PadDelim);
473 void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds)
475 struct ar5416_desc *ads = AR5416DESC(ds);
477 ads->ds_ctl1 |= AR_IsAggr;
478 ads->ds_ctl1 &= ~AR_MoreAggr;
479 ads->ds_ctl6 &= ~AR_PadDelim;
482 void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds)
484 struct ar5416_desc *ads = AR5416DESC(ds);
486 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
489 void ath9k_hw_set11n_burstduration(struct ath_hal *ah, struct ath_desc *ds,
492 struct ar5416_desc *ads = AR5416DESC(ds);
494 ads->ds_ctl2 &= ~AR_BurstDur;
495 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
498 void ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah, struct ath_desc *ds,
501 struct ar5416_desc *ads = AR5416DESC(ds);
504 ads->ds_ctl0 |= AR_VirtMoreFrag;
506 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
509 void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs)
511 struct ath_hal_5416 *ahp = AH5416(ah);
513 *txqs &= ahp->ah_intrTxqs;
514 ahp->ah_intrTxqs &= ~(*txqs);
517 bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q,
518 const struct ath9k_tx_queue_info *qinfo)
521 struct ath_hal_5416 *ahp = AH5416(ah);
522 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
523 struct ath9k_tx_queue_info *qi;
525 if (q >= pCap->total_queues) {
526 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
531 qi = &ahp->ah_txq[q];
532 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
533 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue\n",
538 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %p\n", __func__, qi);
540 qi->tqi_ver = qinfo->tqi_ver;
541 qi->tqi_subtype = qinfo->tqi_subtype;
542 qi->tqi_qflags = qinfo->tqi_qflags;
543 qi->tqi_priority = qinfo->tqi_priority;
544 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
545 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
547 qi->tqi_aifs = INIT_AIFS;
548 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
549 cw = min(qinfo->tqi_cwmin, 1024U);
551 while (qi->tqi_cwmin < cw)
552 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
554 qi->tqi_cwmin = qinfo->tqi_cwmin;
555 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
556 cw = min(qinfo->tqi_cwmax, 1024U);
558 while (qi->tqi_cwmax < cw)
559 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
561 qi->tqi_cwmax = INIT_CWMAX;
563 if (qinfo->tqi_shretry != 0)
564 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
566 qi->tqi_shretry = INIT_SH_RETRY;
567 if (qinfo->tqi_lgretry != 0)
568 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
570 qi->tqi_lgretry = INIT_LG_RETRY;
571 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
572 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
573 qi->tqi_burstTime = qinfo->tqi_burstTime;
574 qi->tqi_readyTime = qinfo->tqi_readyTime;
576 switch (qinfo->tqi_subtype) {
578 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
579 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
588 bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q,
589 struct ath9k_tx_queue_info *qinfo)
591 struct ath_hal_5416 *ahp = AH5416(ah);
592 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
593 struct ath9k_tx_queue_info *qi;
595 if (q >= pCap->total_queues) {
596 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
601 qi = &ahp->ah_txq[q];
602 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
603 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue\n",
608 qinfo->tqi_qflags = qi->tqi_qflags;
609 qinfo->tqi_ver = qi->tqi_ver;
610 qinfo->tqi_subtype = qi->tqi_subtype;
611 qinfo->tqi_qflags = qi->tqi_qflags;
612 qinfo->tqi_priority = qi->tqi_priority;
613 qinfo->tqi_aifs = qi->tqi_aifs;
614 qinfo->tqi_cwmin = qi->tqi_cwmin;
615 qinfo->tqi_cwmax = qi->tqi_cwmax;
616 qinfo->tqi_shretry = qi->tqi_shretry;
617 qinfo->tqi_lgretry = qi->tqi_lgretry;
618 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
619 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
620 qinfo->tqi_burstTime = qi->tqi_burstTime;
621 qinfo->tqi_readyTime = qi->tqi_readyTime;
626 int ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type,
627 const struct ath9k_tx_queue_info *qinfo)
629 struct ath_hal_5416 *ahp = AH5416(ah);
630 struct ath9k_tx_queue_info *qi;
631 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
635 case ATH9K_TX_QUEUE_BEACON:
636 q = pCap->total_queues - 1;
638 case ATH9K_TX_QUEUE_CAB:
639 q = pCap->total_queues - 2;
641 case ATH9K_TX_QUEUE_PSPOLL:
644 case ATH9K_TX_QUEUE_UAPSD:
645 q = pCap->total_queues - 3;
647 case ATH9K_TX_QUEUE_DATA:
648 for (q = 0; q < pCap->total_queues; q++)
649 if (ahp->ah_txq[q].tqi_type ==
650 ATH9K_TX_QUEUE_INACTIVE)
652 if (q == pCap->total_queues) {
653 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
654 "%s: no available tx queue\n", __func__);
659 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: bad tx queue type %u\n",
664 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %u\n", __func__, q);
666 qi = &ahp->ah_txq[q];
667 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
668 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
669 "%s: tx queue %u already active\n", __func__, q);
672 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
676 TXQ_FLAG_TXOKINT_ENABLE
677 | TXQ_FLAG_TXERRINT_ENABLE
678 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
679 qi->tqi_aifs = INIT_AIFS;
680 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
681 qi->tqi_cwmax = INIT_CWMAX;
682 qi->tqi_shretry = INIT_SH_RETRY;
683 qi->tqi_lgretry = INIT_LG_RETRY;
684 qi->tqi_physCompBuf = 0;
686 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
687 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
693 bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q)
695 struct ath_hal_5416 *ahp = AH5416(ah);
696 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
697 struct ath9k_tx_queue_info *qi;
699 if (q >= pCap->total_queues) {
700 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
704 qi = &ahp->ah_txq[q];
705 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
706 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue %u\n",
711 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: release queue %u\n",
714 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
715 ahp->ah_txOkInterruptMask &= ~(1 << q);
716 ahp->ah_txErrInterruptMask &= ~(1 << q);
717 ahp->ah_txDescInterruptMask &= ~(1 << q);
718 ahp->ah_txEolInterruptMask &= ~(1 << q);
719 ahp->ah_txUrnInterruptMask &= ~(1 << q);
720 ath9k_hw_set_txq_interrupts(ah, qi);
725 bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q)
727 struct ath_hal_5416 *ahp = AH5416(ah);
728 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
729 struct ath9k_channel *chan = ah->ah_curchan;
730 struct ath9k_tx_queue_info *qi;
731 u32 cwMin, chanCwMin, value;
733 if (q >= pCap->total_queues) {
734 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
739 qi = &ahp->ah_txq[q];
740 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
741 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue %u\n",
746 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: reset queue %u\n", __func__, q);
748 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
749 if (chan && IS_CHAN_B(chan))
750 chanCwMin = INIT_CWMIN_11B;
752 chanCwMin = INIT_CWMIN;
754 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
756 cwMin = qi->tqi_cwmin;
758 REG_WRITE(ah, AR_DLCL_IFS(q),
759 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
760 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
761 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
763 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
764 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
765 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
766 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
768 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
769 REG_WRITE(ah, AR_DMISC(q),
770 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
772 if (qi->tqi_cbrPeriod) {
773 REG_WRITE(ah, AR_QCBRCFG(q),
774 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
775 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
776 REG_WRITE(ah, AR_QMISC(q),
777 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
778 (qi->tqi_cbrOverflowLimit ?
779 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
781 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
782 REG_WRITE(ah, AR_QRDYTIMECFG(q),
783 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
787 REG_WRITE(ah, AR_DCHNTIME(q),
788 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
789 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
791 if (qi->tqi_burstTime
792 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
793 REG_WRITE(ah, AR_QMISC(q),
794 REG_READ(ah, AR_QMISC(q)) |
795 AR_Q_MISC_RDYTIME_EXP_POLICY);
799 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
800 REG_WRITE(ah, AR_DMISC(q),
801 REG_READ(ah, AR_DMISC(q)) |
802 AR_D_MISC_POST_FR_BKOFF_DIS);
804 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
805 REG_WRITE(ah, AR_DMISC(q),
806 REG_READ(ah, AR_DMISC(q)) |
807 AR_D_MISC_FRAG_BKOFF_EN);
809 switch (qi->tqi_type) {
810 case ATH9K_TX_QUEUE_BEACON:
811 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
812 | AR_Q_MISC_FSP_DBA_GATED
813 | AR_Q_MISC_BEACON_USE
814 | AR_Q_MISC_CBR_INCR_DIS1);
816 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
817 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
818 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
819 | AR_D_MISC_BEACON_USE
820 | AR_D_MISC_POST_FR_BKOFF_DIS);
822 case ATH9K_TX_QUEUE_CAB:
823 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
824 | AR_Q_MISC_FSP_DBA_GATED
825 | AR_Q_MISC_CBR_INCR_DIS1
826 | AR_Q_MISC_CBR_INCR_DIS0);
827 value = (qi->tqi_readyTime -
828 (ah->ah_config.sw_beacon_response_time -
829 ah->ah_config.dma_beacon_response_time) -
830 ah->ah_config.additional_swba_backoff) * 1024;
831 REG_WRITE(ah, AR_QRDYTIMECFG(q),
832 value | AR_Q_RDYTIMECFG_EN);
833 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
834 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
835 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
837 case ATH9K_TX_QUEUE_PSPOLL:
838 REG_WRITE(ah, AR_QMISC(q),
839 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
841 case ATH9K_TX_QUEUE_UAPSD:
842 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
843 AR_D_MISC_POST_FR_BKOFF_DIS);
849 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
850 REG_WRITE(ah, AR_DMISC(q),
851 REG_READ(ah, AR_DMISC(q)) |
852 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
853 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
854 AR_D_MISC_POST_FR_BKOFF_DIS);
857 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
858 ahp->ah_txOkInterruptMask |= 1 << q;
860 ahp->ah_txOkInterruptMask &= ~(1 << q);
861 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
862 ahp->ah_txErrInterruptMask |= 1 << q;
864 ahp->ah_txErrInterruptMask &= ~(1 << q);
865 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
866 ahp->ah_txDescInterruptMask |= 1 << q;
868 ahp->ah_txDescInterruptMask &= ~(1 << q);
869 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
870 ahp->ah_txEolInterruptMask |= 1 << q;
872 ahp->ah_txEolInterruptMask &= ~(1 << q);
873 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
874 ahp->ah_txUrnInterruptMask |= 1 << q;
876 ahp->ah_txUrnInterruptMask &= ~(1 << q);
877 ath9k_hw_set_txq_interrupts(ah, qi);
882 int ath9k_hw_rxprocdesc(struct ath_hal *ah, struct ath_desc *ds,
883 u32 pa, struct ath_desc *nds, u64 tsf)
885 struct ar5416_desc ads;
886 struct ar5416_desc *adsp = AR5416DESC(ds);
889 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
892 ads.u.rx = adsp->u.rx;
894 ds->ds_rxstat.rs_status = 0;
895 ds->ds_rxstat.rs_flags = 0;
897 ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
898 ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp;
900 ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
901 ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
902 ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
903 ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
904 ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
905 ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
906 ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
907 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
908 ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
910 ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID;
912 ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
913 ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
915 ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
916 ds->ds_rxstat.rs_moreaggr =
917 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
918 ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
919 ds->ds_rxstat.rs_flags =
920 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
921 ds->ds_rxstat.rs_flags |=
922 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
924 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
925 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
926 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
927 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
928 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
929 ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
931 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
932 if (ads.ds_rxstatus8 & AR_CRCErr)
933 ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
934 else if (ads.ds_rxstatus8 & AR_PHYErr) {
935 ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
936 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
937 ds->ds_rxstat.rs_phyerr = phyerr;
938 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
939 ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
940 else if (ads.ds_rxstatus8 & AR_MichaelErr)
941 ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
947 bool ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds,
950 struct ar5416_desc *ads = AR5416DESC(ds);
951 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
953 ads->ds_ctl1 = size & AR_BufLen;
954 if (flags & ATH9K_RXDESC_INTREQ)
955 ads->ds_ctl1 |= AR_RxIntrReq;
957 ads->ds_rxstatus8 &= ~AR_RxDone;
958 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
959 memset(&(ads->u), 0, sizeof(ads->u));
964 bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set)
969 REG_SET_BIT(ah, AR_DIAG_SW,
970 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
972 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 0)) {
973 REG_CLR_BIT(ah, AR_DIAG_SW,
977 reg = REG_READ(ah, AR_OBS_BUS_1);
978 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
979 "%s: rx failed to go idle in 10 ms RXSM=0x%x\n",
985 REG_CLR_BIT(ah, AR_DIAG_SW,
986 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
992 void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp)
994 REG_WRITE(ah, AR_RXDP, rxdp);
997 void ath9k_hw_rxena(struct ath_hal *ah)
999 REG_WRITE(ah, AR_CR, AR_CR_RXE);
1002 void ath9k_hw_startpcureceive(struct ath_hal *ah)
1004 REG_CLR_BIT(ah, AR_DIAG_SW,
1005 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1007 ath9k_enable_mib_counters(ah);
1009 ath9k_ani_reset(ah);
1012 void ath9k_hw_stoppcurecv(struct ath_hal *ah)
1014 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
1016 ath9k_hw_disable_mib_counters(ah);
1019 bool ath9k_hw_stopdmarecv(struct ath_hal *ah)
1021 REG_WRITE(ah, AR_CR, AR_CR_RXD);
1023 if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0)) {
1024 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
1025 "%s: dma failed to stop in 10ms\n"
1026 "AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n",
1028 REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));