1*572ff6f6SMatthew Dillon /*
2*572ff6f6SMatthew Dillon  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3*572ff6f6SMatthew Dillon  * Copyright (c) 2002-2004 Atheros Communications, Inc.
4*572ff6f6SMatthew Dillon  *
5*572ff6f6SMatthew Dillon  * Permission to use, copy, modify, and/or distribute this software for any
6*572ff6f6SMatthew Dillon  * purpose with or without fee is hereby granted, provided that the above
7*572ff6f6SMatthew Dillon  * copyright notice and this permission notice appear in all copies.
8*572ff6f6SMatthew Dillon  *
9*572ff6f6SMatthew Dillon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*572ff6f6SMatthew Dillon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*572ff6f6SMatthew Dillon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*572ff6f6SMatthew Dillon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*572ff6f6SMatthew Dillon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*572ff6f6SMatthew Dillon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*572ff6f6SMatthew Dillon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*572ff6f6SMatthew Dillon  *
17*572ff6f6SMatthew Dillon  * $FreeBSD$
18*572ff6f6SMatthew Dillon  */
19*572ff6f6SMatthew Dillon #include "opt_ah.h"
20*572ff6f6SMatthew Dillon 
21*572ff6f6SMatthew Dillon #include "ah.h"
22*572ff6f6SMatthew Dillon #include "ah_internal.h"
23*572ff6f6SMatthew Dillon #include "ah_desc.h"
24*572ff6f6SMatthew Dillon 
25*572ff6f6SMatthew Dillon #include "ar5210/ar5210.h"
26*572ff6f6SMatthew Dillon #include "ar5210/ar5210reg.h"
27*572ff6f6SMatthew Dillon #include "ar5210/ar5210phy.h"
28*572ff6f6SMatthew Dillon #include "ar5210/ar5210desc.h"
29*572ff6f6SMatthew Dillon 
30*572ff6f6SMatthew Dillon /*
31*572ff6f6SMatthew Dillon  * Set the properties of the tx queue with the parameters
32*572ff6f6SMatthew Dillon  * from qInfo.  The queue must previously have been setup
33*572ff6f6SMatthew Dillon  * with a call to ar5210SetupTxQueue.
34*572ff6f6SMatthew Dillon  */
35*572ff6f6SMatthew Dillon HAL_BOOL
ar5210SetTxQueueProps(struct ath_hal * ah,int q,const HAL_TXQ_INFO * qInfo)36*572ff6f6SMatthew Dillon ar5210SetTxQueueProps(struct ath_hal *ah, int q, const HAL_TXQ_INFO *qInfo)
37*572ff6f6SMatthew Dillon {
38*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
39*572ff6f6SMatthew Dillon 
40*572ff6f6SMatthew Dillon 	if (q >= HAL_NUM_TX_QUEUES) {
41*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
42*572ff6f6SMatthew Dillon 		    __func__, q);
43*572ff6f6SMatthew Dillon 		return AH_FALSE;
44*572ff6f6SMatthew Dillon 	}
45*572ff6f6SMatthew Dillon 	return ath_hal_setTxQProps(ah, &ahp->ah_txq[q], qInfo);
46*572ff6f6SMatthew Dillon }
47*572ff6f6SMatthew Dillon 
48*572ff6f6SMatthew Dillon /*
49*572ff6f6SMatthew Dillon  * Return the properties for the specified tx queue.
50*572ff6f6SMatthew Dillon  */
51*572ff6f6SMatthew Dillon HAL_BOOL
ar5210GetTxQueueProps(struct ath_hal * ah,int q,HAL_TXQ_INFO * qInfo)52*572ff6f6SMatthew Dillon ar5210GetTxQueueProps(struct ath_hal *ah, int q, HAL_TXQ_INFO *qInfo)
53*572ff6f6SMatthew Dillon {
54*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
55*572ff6f6SMatthew Dillon 
56*572ff6f6SMatthew Dillon 	if (q >= HAL_NUM_TX_QUEUES) {
57*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
58*572ff6f6SMatthew Dillon 		    __func__, q);
59*572ff6f6SMatthew Dillon 		return AH_FALSE;
60*572ff6f6SMatthew Dillon 	}
61*572ff6f6SMatthew Dillon 	return ath_hal_getTxQProps(ah, qInfo, &ahp->ah_txq[q]);
62*572ff6f6SMatthew Dillon }
63*572ff6f6SMatthew Dillon 
64*572ff6f6SMatthew Dillon /*
65*572ff6f6SMatthew Dillon  * Allocate and initialize a tx DCU/QCU combination.
66*572ff6f6SMatthew Dillon  */
67*572ff6f6SMatthew Dillon int
ar5210SetupTxQueue(struct ath_hal * ah,HAL_TX_QUEUE type,const HAL_TXQ_INFO * qInfo)68*572ff6f6SMatthew Dillon ar5210SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,
69*572ff6f6SMatthew Dillon 	const HAL_TXQ_INFO *qInfo)
70*572ff6f6SMatthew Dillon {
71*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
72*572ff6f6SMatthew Dillon 	HAL_TX_QUEUE_INFO *qi;
73*572ff6f6SMatthew Dillon 	int q;
74*572ff6f6SMatthew Dillon 
75*572ff6f6SMatthew Dillon 	switch (type) {
76*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_BEACON:
77*572ff6f6SMatthew Dillon 		q = 2;
78*572ff6f6SMatthew Dillon 		break;
79*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_CAB:
80*572ff6f6SMatthew Dillon 		q = 1;
81*572ff6f6SMatthew Dillon 		break;
82*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_DATA:
83*572ff6f6SMatthew Dillon 		q = 0;
84*572ff6f6SMatthew Dillon 		break;
85*572ff6f6SMatthew Dillon 	default:
86*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad tx queue type %u\n",
87*572ff6f6SMatthew Dillon 		    __func__, type);
88*572ff6f6SMatthew Dillon 		return -1;
89*572ff6f6SMatthew Dillon 	}
90*572ff6f6SMatthew Dillon 
91*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
92*572ff6f6SMatthew Dillon 
93*572ff6f6SMatthew Dillon 	qi = &ahp->ah_txq[q];
94*572ff6f6SMatthew Dillon 	if (qi->tqi_type != HAL_TX_QUEUE_INACTIVE) {
95*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: tx queue %u already active\n",
96*572ff6f6SMatthew Dillon 		    __func__, q);
97*572ff6f6SMatthew Dillon 		return -1;
98*572ff6f6SMatthew Dillon 	}
99*572ff6f6SMatthew Dillon 	OS_MEMZERO(qi, sizeof(HAL_TX_QUEUE_INFO));
100*572ff6f6SMatthew Dillon 	qi->tqi_type = type;
101*572ff6f6SMatthew Dillon 	if (qInfo == AH_NULL) {
102*572ff6f6SMatthew Dillon 		/* by default enable OK+ERR+DESC+URN interrupts */
103*572ff6f6SMatthew Dillon 		qi->tqi_qflags =
104*572ff6f6SMatthew Dillon 			  HAL_TXQ_TXOKINT_ENABLE
105*572ff6f6SMatthew Dillon 			| HAL_TXQ_TXERRINT_ENABLE
106*572ff6f6SMatthew Dillon 			| HAL_TXQ_TXDESCINT_ENABLE
107*572ff6f6SMatthew Dillon 			| HAL_TXQ_TXURNINT_ENABLE
108*572ff6f6SMatthew Dillon 			;
109*572ff6f6SMatthew Dillon 		qi->tqi_aifs = INIT_AIFS;
110*572ff6f6SMatthew Dillon 		qi->tqi_cwmin = HAL_TXQ_USEDEFAULT;	/* NB: do at reset */
111*572ff6f6SMatthew Dillon 		qi->tqi_shretry = INIT_SH_RETRY;
112*572ff6f6SMatthew Dillon 		qi->tqi_lgretry = INIT_LG_RETRY;
113*572ff6f6SMatthew Dillon 	} else
114*572ff6f6SMatthew Dillon 		(void) ar5210SetTxQueueProps(ah, q, qInfo);
115*572ff6f6SMatthew Dillon 	/* NB: must be followed by ar5210ResetTxQueue */
116*572ff6f6SMatthew Dillon 	return q;
117*572ff6f6SMatthew Dillon }
118*572ff6f6SMatthew Dillon 
119*572ff6f6SMatthew Dillon /*
120*572ff6f6SMatthew Dillon  * Free a tx DCU/QCU combination.
121*572ff6f6SMatthew Dillon  */
122*572ff6f6SMatthew Dillon HAL_BOOL
ar5210ReleaseTxQueue(struct ath_hal * ah,u_int q)123*572ff6f6SMatthew Dillon ar5210ReleaseTxQueue(struct ath_hal *ah, u_int q)
124*572ff6f6SMatthew Dillon {
125*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
126*572ff6f6SMatthew Dillon 	HAL_TX_QUEUE_INFO *qi;
127*572ff6f6SMatthew Dillon 
128*572ff6f6SMatthew Dillon 	if (q >= HAL_NUM_TX_QUEUES) {
129*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
130*572ff6f6SMatthew Dillon 		    __func__, q);
131*572ff6f6SMatthew Dillon 		return AH_FALSE;
132*572ff6f6SMatthew Dillon 	}
133*572ff6f6SMatthew Dillon 	qi = &ahp->ah_txq[q];
134*572ff6f6SMatthew Dillon 	if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
135*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",
136*572ff6f6SMatthew Dillon 		    __func__, q);
137*572ff6f6SMatthew Dillon 		return AH_FALSE;
138*572ff6f6SMatthew Dillon 	}
139*572ff6f6SMatthew Dillon 
140*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: release queue %u\n", __func__, q);
141*572ff6f6SMatthew Dillon 
142*572ff6f6SMatthew Dillon 	qi->tqi_type = HAL_TX_QUEUE_INACTIVE;
143*572ff6f6SMatthew Dillon 	ahp->ah_txOkInterruptMask &= ~(1 << q);
144*572ff6f6SMatthew Dillon 	ahp->ah_txErrInterruptMask &= ~(1 << q);
145*572ff6f6SMatthew Dillon 	ahp->ah_txDescInterruptMask &= ~(1 << q);
146*572ff6f6SMatthew Dillon 	ahp->ah_txEolInterruptMask &= ~(1 << q);
147*572ff6f6SMatthew Dillon 	ahp->ah_txUrnInterruptMask &= ~(1 << q);
148*572ff6f6SMatthew Dillon 
149*572ff6f6SMatthew Dillon 	return AH_TRUE;
150*572ff6f6SMatthew Dillon #undef N
151*572ff6f6SMatthew Dillon }
152*572ff6f6SMatthew Dillon 
153*572ff6f6SMatthew Dillon HAL_BOOL
ar5210ResetTxQueue(struct ath_hal * ah,u_int q)154*572ff6f6SMatthew Dillon ar5210ResetTxQueue(struct ath_hal *ah, u_int q)
155*572ff6f6SMatthew Dillon {
156*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
157*572ff6f6SMatthew Dillon 	const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan;
158*572ff6f6SMatthew Dillon 	HAL_TX_QUEUE_INFO *qi;
159*572ff6f6SMatthew Dillon 	uint32_t cwMin;
160*572ff6f6SMatthew Dillon 
161*572ff6f6SMatthew Dillon 	if (q >= HAL_NUM_TX_QUEUES) {
162*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
163*572ff6f6SMatthew Dillon 		    __func__, q);
164*572ff6f6SMatthew Dillon 		return AH_FALSE;
165*572ff6f6SMatthew Dillon 	}
166*572ff6f6SMatthew Dillon 	qi = &ahp->ah_txq[q];
167*572ff6f6SMatthew Dillon 	if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
168*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",
169*572ff6f6SMatthew Dillon 		    __func__, q);
170*572ff6f6SMatthew Dillon 		return AH_FALSE;
171*572ff6f6SMatthew Dillon 	}
172*572ff6f6SMatthew Dillon 
173*572ff6f6SMatthew Dillon 	/*
174*572ff6f6SMatthew Dillon 	 * Ignore any non-data queue(s).
175*572ff6f6SMatthew Dillon 	 */
176*572ff6f6SMatthew Dillon 	if (qi->tqi_type != HAL_TX_QUEUE_DATA)
177*572ff6f6SMatthew Dillon 		return AH_TRUE;
178*572ff6f6SMatthew Dillon 
179*572ff6f6SMatthew Dillon 	/* Set turbo mode / base mode parameters on or off */
180*572ff6f6SMatthew Dillon 	if (IEEE80211_IS_CHAN_TURBO(chan)) {
181*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_SLOT_TIME, INIT_SLOT_TIME_TURBO);
182*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_TIME_OUT, INIT_ACK_CTS_TIMEOUT_TURBO);
183*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_USEC, INIT_TRANSMIT_LATENCY_TURBO);
184*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_IFS0,
185*572ff6f6SMatthew Dillon 			((INIT_SIFS_TURBO + qi->tqi_aifs * INIT_SLOT_TIME_TURBO)
186*572ff6f6SMatthew Dillon 				<< AR_IFS0_DIFS_S)
187*572ff6f6SMatthew Dillon 			| INIT_SIFS_TURBO);
188*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_IFS1, INIT_PROTO_TIME_CNTRL_TURBO);
189*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY(17),
190*572ff6f6SMatthew Dillon 			(OS_REG_READ(ah, AR_PHY(17)) & ~0x7F) | 0x38);
191*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY_FRCTL,
192*572ff6f6SMatthew Dillon 			AR_PHY_SERVICE_ERR | AR_PHY_TXURN_ERR |
193*572ff6f6SMatthew Dillon 			AR_PHY_ILLLEN_ERR | AR_PHY_ILLRATE_ERR |
194*572ff6f6SMatthew Dillon 			AR_PHY_PARITY_ERR | AR_PHY_TIMING_ERR |
195*572ff6f6SMatthew Dillon 			0x2020 |
196*572ff6f6SMatthew Dillon 			AR_PHY_TURBO_MODE | AR_PHY_TURBO_SHORT);
197*572ff6f6SMatthew Dillon 	} else {
198*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_SLOT_TIME, INIT_SLOT_TIME);
199*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_TIME_OUT, INIT_ACK_CTS_TIMEOUT);
200*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_USEC, INIT_TRANSMIT_LATENCY);
201*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_IFS0,
202*572ff6f6SMatthew Dillon 			((INIT_SIFS + qi->tqi_aifs * INIT_SLOT_TIME)
203*572ff6f6SMatthew Dillon 				<< AR_IFS0_DIFS_S)
204*572ff6f6SMatthew Dillon 			| INIT_SIFS);
205*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_IFS1, INIT_PROTO_TIME_CNTRL);
206*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY(17),
207*572ff6f6SMatthew Dillon 			(OS_REG_READ(ah, AR_PHY(17)) & ~0x7F) | 0x1C);
208*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY_FRCTL,
209*572ff6f6SMatthew Dillon 			AR_PHY_SERVICE_ERR | AR_PHY_TXURN_ERR |
210*572ff6f6SMatthew Dillon 			AR_PHY_ILLLEN_ERR | AR_PHY_ILLRATE_ERR |
211*572ff6f6SMatthew Dillon 			AR_PHY_PARITY_ERR | AR_PHY_TIMING_ERR | 0x1020);
212*572ff6f6SMatthew Dillon 	}
213*572ff6f6SMatthew Dillon 
214*572ff6f6SMatthew Dillon 	if (qi->tqi_cwmin == HAL_TXQ_USEDEFAULT)
215*572ff6f6SMatthew Dillon 		cwMin = INIT_CWMIN;
216*572ff6f6SMatthew Dillon 	else
217*572ff6f6SMatthew Dillon 		cwMin = qi->tqi_cwmin;
218*572ff6f6SMatthew Dillon 
219*572ff6f6SMatthew Dillon 	/* Set cwmin and retry limit values */
220*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_RETRY_LMT,
221*572ff6f6SMatthew Dillon 		  (cwMin << AR_RETRY_LMT_CW_MIN_S)
222*572ff6f6SMatthew Dillon 		 | SM(INIT_SLG_RETRY, AR_RETRY_LMT_SLG_RETRY)
223*572ff6f6SMatthew Dillon 		 | SM(INIT_SSH_RETRY, AR_RETRY_LMT_SSH_RETRY)
224*572ff6f6SMatthew Dillon 		 | SM(qi->tqi_lgretry, AR_RETRY_LMT_LG_RETRY)
225*572ff6f6SMatthew Dillon 		 | SM(qi->tqi_shretry, AR_RETRY_LMT_SH_RETRY)
226*572ff6f6SMatthew Dillon 	);
227*572ff6f6SMatthew Dillon 
228*572ff6f6SMatthew Dillon 	if (qi->tqi_qflags & HAL_TXQ_TXOKINT_ENABLE)
229*572ff6f6SMatthew Dillon 		ahp->ah_txOkInterruptMask |= 1 << q;
230*572ff6f6SMatthew Dillon 	else
231*572ff6f6SMatthew Dillon 		ahp->ah_txOkInterruptMask &= ~(1 << q);
232*572ff6f6SMatthew Dillon 	if (qi->tqi_qflags & HAL_TXQ_TXERRINT_ENABLE)
233*572ff6f6SMatthew Dillon 		ahp->ah_txErrInterruptMask |= 1 << q;
234*572ff6f6SMatthew Dillon 	else
235*572ff6f6SMatthew Dillon 		ahp->ah_txErrInterruptMask &= ~(1 << q);
236*572ff6f6SMatthew Dillon 	if (qi->tqi_qflags & HAL_TXQ_TXDESCINT_ENABLE)
237*572ff6f6SMatthew Dillon 		ahp->ah_txDescInterruptMask |= 1 << q;
238*572ff6f6SMatthew Dillon 	else
239*572ff6f6SMatthew Dillon 		ahp->ah_txDescInterruptMask &= ~(1 << q);
240*572ff6f6SMatthew Dillon 	if (qi->tqi_qflags & HAL_TXQ_TXEOLINT_ENABLE)
241*572ff6f6SMatthew Dillon 		ahp->ah_txEolInterruptMask |= 1 << q;
242*572ff6f6SMatthew Dillon 	else
243*572ff6f6SMatthew Dillon 		ahp->ah_txEolInterruptMask &= ~(1 << q);
244*572ff6f6SMatthew Dillon 	if (qi->tqi_qflags & HAL_TXQ_TXURNINT_ENABLE)
245*572ff6f6SMatthew Dillon 		ahp->ah_txUrnInterruptMask |= 1 << q;
246*572ff6f6SMatthew Dillon 	else
247*572ff6f6SMatthew Dillon 		ahp->ah_txUrnInterruptMask &= ~(1 << q);
248*572ff6f6SMatthew Dillon 
249*572ff6f6SMatthew Dillon 	return AH_TRUE;
250*572ff6f6SMatthew Dillon }
251*572ff6f6SMatthew Dillon 
252*572ff6f6SMatthew Dillon /*
253*572ff6f6SMatthew Dillon  * Get the TXDP for the "main" data queue.  Needs to be extended
254*572ff6f6SMatthew Dillon  * for multiple Q functionality
255*572ff6f6SMatthew Dillon  */
256*572ff6f6SMatthew Dillon uint32_t
ar5210GetTxDP(struct ath_hal * ah,u_int q)257*572ff6f6SMatthew Dillon ar5210GetTxDP(struct ath_hal *ah, u_int q)
258*572ff6f6SMatthew Dillon {
259*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
260*572ff6f6SMatthew Dillon 	HAL_TX_QUEUE_INFO *qi;
261*572ff6f6SMatthew Dillon 
262*572ff6f6SMatthew Dillon 	HALASSERT(q < HAL_NUM_TX_QUEUES);
263*572ff6f6SMatthew Dillon 
264*572ff6f6SMatthew Dillon 	qi = &ahp->ah_txq[q];
265*572ff6f6SMatthew Dillon 	switch (qi->tqi_type) {
266*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_DATA:
267*572ff6f6SMatthew Dillon 		return OS_REG_READ(ah, AR_TXDP0);
268*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_INACTIVE:
269*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: inactive queue %u\n",
270*572ff6f6SMatthew Dillon 		    __func__, q);
271*572ff6f6SMatthew Dillon 		/* fall thru... */
272*572ff6f6SMatthew Dillon 	default:
273*572ff6f6SMatthew Dillon 		break;
274*572ff6f6SMatthew Dillon 	}
275*572ff6f6SMatthew Dillon 	return 0xffffffff;
276*572ff6f6SMatthew Dillon }
277*572ff6f6SMatthew Dillon 
278*572ff6f6SMatthew Dillon /*
279*572ff6f6SMatthew Dillon  * Set the TxDP for the "main" data queue.
280*572ff6f6SMatthew Dillon  */
281*572ff6f6SMatthew Dillon HAL_BOOL
ar5210SetTxDP(struct ath_hal * ah,u_int q,uint32_t txdp)282*572ff6f6SMatthew Dillon ar5210SetTxDP(struct ath_hal *ah, u_int q, uint32_t txdp)
283*572ff6f6SMatthew Dillon {
284*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
285*572ff6f6SMatthew Dillon 	HAL_TX_QUEUE_INFO *qi;
286*572ff6f6SMatthew Dillon 
287*572ff6f6SMatthew Dillon 	HALASSERT(q < HAL_NUM_TX_QUEUES);
288*572ff6f6SMatthew Dillon 
289*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u 0x%x\n",
290*572ff6f6SMatthew Dillon 	    __func__, q, txdp);
291*572ff6f6SMatthew Dillon 	qi = &ahp->ah_txq[q];
292*572ff6f6SMatthew Dillon 	switch (qi->tqi_type) {
293*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_DATA:
294*572ff6f6SMatthew Dillon #ifdef AH_DEBUG
295*572ff6f6SMatthew Dillon 		/*
296*572ff6f6SMatthew Dillon 		 * Make sure that TXE is deasserted before setting the
297*572ff6f6SMatthew Dillon 		 * TXDP.  If TXE is still asserted, setting TXDP will
298*572ff6f6SMatthew Dillon 		 * have no effect.
299*572ff6f6SMatthew Dillon 		 */
300*572ff6f6SMatthew Dillon 		if (OS_REG_READ(ah, AR_CR) & AR_CR_TXE0)
301*572ff6f6SMatthew Dillon 			ath_hal_printf(ah, "%s: TXE asserted; AR_CR=0x%x\n",
302*572ff6f6SMatthew Dillon 				__func__, OS_REG_READ(ah, AR_CR));
303*572ff6f6SMatthew Dillon #endif
304*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_TXDP0, txdp);
305*572ff6f6SMatthew Dillon 		break;
306*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_BEACON:
307*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_CAB:
308*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_TXDP1, txdp);
309*572ff6f6SMatthew Dillon 		break;
310*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_INACTIVE:
311*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",
312*572ff6f6SMatthew Dillon 		    __func__, q);
313*572ff6f6SMatthew Dillon 		/* fall thru... */
314*572ff6f6SMatthew Dillon 	default:
315*572ff6f6SMatthew Dillon 		return AH_FALSE;
316*572ff6f6SMatthew Dillon 	}
317*572ff6f6SMatthew Dillon 	return AH_TRUE;
318*572ff6f6SMatthew Dillon }
319*572ff6f6SMatthew Dillon 
320*572ff6f6SMatthew Dillon /*
321*572ff6f6SMatthew Dillon  * Update Tx FIFO trigger level.
322*572ff6f6SMatthew Dillon  *
323*572ff6f6SMatthew Dillon  * Set bIncTrigLevel to TRUE to increase the trigger level.
324*572ff6f6SMatthew Dillon  * Set bIncTrigLevel to FALSE to decrease the trigger level.
325*572ff6f6SMatthew Dillon  *
326*572ff6f6SMatthew Dillon  * Returns TRUE if the trigger level was updated
327*572ff6f6SMatthew Dillon  */
328*572ff6f6SMatthew Dillon HAL_BOOL
ar5210UpdateTxTrigLevel(struct ath_hal * ah,HAL_BOOL bIncTrigLevel)329*572ff6f6SMatthew Dillon ar5210UpdateTxTrigLevel(struct ath_hal *ah, HAL_BOOL bIncTrigLevel)
330*572ff6f6SMatthew Dillon {
331*572ff6f6SMatthew Dillon 	uint32_t curTrigLevel;
332*572ff6f6SMatthew Dillon 	HAL_INT ints = ar5210GetInterrupts(ah);
333*572ff6f6SMatthew Dillon 
334*572ff6f6SMatthew Dillon 	/*
335*572ff6f6SMatthew Dillon 	 * Disable chip interrupts. This is because halUpdateTxTrigLevel
336*572ff6f6SMatthew Dillon 	 * is called from both ISR and non-ISR contexts.
337*572ff6f6SMatthew Dillon 	 */
338*572ff6f6SMatthew Dillon 	(void) ar5210SetInterrupts(ah, ints &~ HAL_INT_GLOBAL);
339*572ff6f6SMatthew Dillon 	curTrigLevel = OS_REG_READ(ah, AR_TRIG_LEV);
340*572ff6f6SMatthew Dillon 	if (bIncTrigLevel){
341*572ff6f6SMatthew Dillon 		/* increase the trigger level */
342*572ff6f6SMatthew Dillon 		curTrigLevel = curTrigLevel +
343*572ff6f6SMatthew Dillon 			((MAX_TX_FIFO_THRESHOLD - curTrigLevel) / 2);
344*572ff6f6SMatthew Dillon 	} else {
345*572ff6f6SMatthew Dillon 		/* decrease the trigger level if not already at the minimum */
346*572ff6f6SMatthew Dillon 		if (curTrigLevel > MIN_TX_FIFO_THRESHOLD) {
347*572ff6f6SMatthew Dillon 			/* decrease the trigger level */
348*572ff6f6SMatthew Dillon 			curTrigLevel--;
349*572ff6f6SMatthew Dillon 		} else {
350*572ff6f6SMatthew Dillon 			/* no update to the trigger level */
351*572ff6f6SMatthew Dillon 			/* re-enable chip interrupts */
352*572ff6f6SMatthew Dillon 			ar5210SetInterrupts(ah, ints);
353*572ff6f6SMatthew Dillon 			return AH_FALSE;
354*572ff6f6SMatthew Dillon 		}
355*572ff6f6SMatthew Dillon 	}
356*572ff6f6SMatthew Dillon 	/* Update the trigger level */
357*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_TRIG_LEV, curTrigLevel);
358*572ff6f6SMatthew Dillon 	/* re-enable chip interrupts */
359*572ff6f6SMatthew Dillon 	ar5210SetInterrupts(ah, ints);
360*572ff6f6SMatthew Dillon 	return AH_TRUE;
361*572ff6f6SMatthew Dillon }
362*572ff6f6SMatthew Dillon 
363*572ff6f6SMatthew Dillon /*
364*572ff6f6SMatthew Dillon  * Set Transmit Enable bits for the specified queues.
365*572ff6f6SMatthew Dillon  */
366*572ff6f6SMatthew Dillon HAL_BOOL
ar5210StartTxDma(struct ath_hal * ah,u_int q)367*572ff6f6SMatthew Dillon ar5210StartTxDma(struct ath_hal *ah, u_int q)
368*572ff6f6SMatthew Dillon {
369*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
370*572ff6f6SMatthew Dillon 	HAL_TX_QUEUE_INFO *qi;
371*572ff6f6SMatthew Dillon 
372*572ff6f6SMatthew Dillon 	HALASSERT(q < HAL_NUM_TX_QUEUES);
373*572ff6f6SMatthew Dillon 
374*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
375*572ff6f6SMatthew Dillon 	qi = &ahp->ah_txq[q];
376*572ff6f6SMatthew Dillon 	switch (qi->tqi_type) {
377*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_DATA:
378*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_CR, AR_CR_TXE0);
379*572ff6f6SMatthew Dillon 		break;
380*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_CAB:
381*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_CR, AR_CR_TXE1);	/* enable altq xmit */
382*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_BCR,
383*572ff6f6SMatthew Dillon 			AR_BCR_TQ1V | AR_BCR_BDMAE | AR_BCR_TQ1FV);
384*572ff6f6SMatthew Dillon 		break;
385*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_BEACON:
386*572ff6f6SMatthew Dillon 		/* XXX add CR_BCR_BCMD if IBSS mode */
387*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_BCR, AR_BCR_TQ1V | AR_BCR_BDMAE);
388*572ff6f6SMatthew Dillon 		break;
389*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_INACTIVE:
390*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: inactive queue %u\n",
391*572ff6f6SMatthew Dillon 		    __func__, q);
392*572ff6f6SMatthew Dillon 		/* fal thru... */
393*572ff6f6SMatthew Dillon 	default:
394*572ff6f6SMatthew Dillon 		return AH_FALSE;
395*572ff6f6SMatthew Dillon 	}
396*572ff6f6SMatthew Dillon 	return AH_TRUE;
397*572ff6f6SMatthew Dillon }
398*572ff6f6SMatthew Dillon 
399*572ff6f6SMatthew Dillon uint32_t
ar5210NumTxPending(struct ath_hal * ah,u_int q)400*572ff6f6SMatthew Dillon ar5210NumTxPending(struct ath_hal *ah, u_int q)
401*572ff6f6SMatthew Dillon {
402*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
403*572ff6f6SMatthew Dillon 	HAL_TX_QUEUE_INFO *qi;
404*572ff6f6SMatthew Dillon 	uint32_t v;
405*572ff6f6SMatthew Dillon 
406*572ff6f6SMatthew Dillon 	HALASSERT(q < HAL_NUM_TX_QUEUES);
407*572ff6f6SMatthew Dillon 
408*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
409*572ff6f6SMatthew Dillon 	qi = &ahp->ah_txq[q];
410*572ff6f6SMatthew Dillon 	switch (qi->tqi_type) {
411*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_DATA:
412*572ff6f6SMatthew Dillon 		v = OS_REG_READ(ah, AR_CFG);
413*572ff6f6SMatthew Dillon 		return MS(v, AR_CFG_TXCNT);
414*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_INACTIVE:
415*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: inactive queue %u\n",
416*572ff6f6SMatthew Dillon 		    __func__, q);
417*572ff6f6SMatthew Dillon 		/* fall thru... */
418*572ff6f6SMatthew Dillon 	default:
419*572ff6f6SMatthew Dillon 		break;
420*572ff6f6SMatthew Dillon 	}
421*572ff6f6SMatthew Dillon 	return 0;
422*572ff6f6SMatthew Dillon }
423*572ff6f6SMatthew Dillon 
424*572ff6f6SMatthew Dillon /*
425*572ff6f6SMatthew Dillon  * Stop transmit on the specified queue
426*572ff6f6SMatthew Dillon  */
427*572ff6f6SMatthew Dillon HAL_BOOL
ar5210StopTxDma(struct ath_hal * ah,u_int q)428*572ff6f6SMatthew Dillon ar5210StopTxDma(struct ath_hal *ah, u_int q)
429*572ff6f6SMatthew Dillon {
430*572ff6f6SMatthew Dillon 	struct ath_hal_5210 *ahp = AH5210(ah);
431*572ff6f6SMatthew Dillon 	HAL_TX_QUEUE_INFO *qi;
432*572ff6f6SMatthew Dillon 
433*572ff6f6SMatthew Dillon 	HALASSERT(q < HAL_NUM_TX_QUEUES);
434*572ff6f6SMatthew Dillon 
435*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
436*572ff6f6SMatthew Dillon 	qi = &ahp->ah_txq[q];
437*572ff6f6SMatthew Dillon 	switch (qi->tqi_type) {
438*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_DATA: {
439*572ff6f6SMatthew Dillon 		int i;
440*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_CR, AR_CR_TXD0);
441*572ff6f6SMatthew Dillon 		for (i = 0; i < 1000; i++) {
442*572ff6f6SMatthew Dillon 			if ((OS_REG_READ(ah, AR_CFG) & AR_CFG_TXCNT) == 0)
443*572ff6f6SMatthew Dillon 				break;
444*572ff6f6SMatthew Dillon 			OS_DELAY(10);
445*572ff6f6SMatthew Dillon 		}
446*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_CR, 0);
447*572ff6f6SMatthew Dillon 		return (i < 1000);
448*572ff6f6SMatthew Dillon 	}
449*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_BEACON:
450*572ff6f6SMatthew Dillon 		return ath_hal_wait(ah, AR_BSR, AR_BSR_TXQ1F, 0);
451*572ff6f6SMatthew Dillon 	case HAL_TX_QUEUE_INACTIVE:
452*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: inactive queue %u\n",
453*572ff6f6SMatthew Dillon 		    __func__, q);
454*572ff6f6SMatthew Dillon 		/* fall thru... */
455*572ff6f6SMatthew Dillon 	default:
456*572ff6f6SMatthew Dillon 		break;
457*572ff6f6SMatthew Dillon 	}
458*572ff6f6SMatthew Dillon 	return AH_FALSE;
459*572ff6f6SMatthew Dillon }
460*572ff6f6SMatthew Dillon 
461*572ff6f6SMatthew Dillon /*
462*572ff6f6SMatthew Dillon  * Descriptor Access Functions
463*572ff6f6SMatthew Dillon  */
464*572ff6f6SMatthew Dillon 
465*572ff6f6SMatthew Dillon #define	VALID_PKT_TYPES \
466*572ff6f6SMatthew Dillon 	((1<<HAL_PKT_TYPE_NORMAL)|(1<<HAL_PKT_TYPE_ATIM)|\
467*572ff6f6SMatthew Dillon 	 (1<<HAL_PKT_TYPE_PSPOLL)|(1<<HAL_PKT_TYPE_PROBE_RESP)|\
468*572ff6f6SMatthew Dillon 	 (1<<HAL_PKT_TYPE_BEACON))
469*572ff6f6SMatthew Dillon #define	isValidPktType(_t)	((1<<(_t)) & VALID_PKT_TYPES)
470*572ff6f6SMatthew Dillon #define	VALID_TX_RATES \
471*572ff6f6SMatthew Dillon 	((1<<0x0b)|(1<<0x0f)|(1<<0x0a)|(1<<0x0e)|(1<<0x09)|(1<<0x0d)|\
472*572ff6f6SMatthew Dillon 	 (1<<0x08)|(1<<0x0c)|(1<<0x1b)|(1<<0x1a)|(1<<0x1e)|(1<<0x19)|\
473*572ff6f6SMatthew Dillon 	 (1<<0x1d)|(1<<0x18)|(1<<0x1c))
474*572ff6f6SMatthew Dillon #define	isValidTxRate(_r)	((1<<(_r)) & VALID_TX_RATES)
475*572ff6f6SMatthew Dillon 
476*572ff6f6SMatthew Dillon HAL_BOOL
ar5210SetupTxDesc(struct ath_hal * ah,struct ath_desc * ds,u_int pktLen,u_int hdrLen,HAL_PKT_TYPE type,u_int txPower,u_int txRate0,u_int txTries0,u_int keyIx,u_int antMode,u_int flags,u_int rtsctsRate,u_int rtsctsDuration,u_int compicvLen,u_int compivLen,u_int comp)477*572ff6f6SMatthew Dillon ar5210SetupTxDesc(struct ath_hal *ah, struct ath_desc *ds,
478*572ff6f6SMatthew Dillon 	u_int pktLen,
479*572ff6f6SMatthew Dillon 	u_int hdrLen,
480*572ff6f6SMatthew Dillon 	HAL_PKT_TYPE type,
481*572ff6f6SMatthew Dillon 	u_int txPower,
482*572ff6f6SMatthew Dillon 	u_int txRate0, u_int txTries0,
483*572ff6f6SMatthew Dillon 	u_int keyIx,
484*572ff6f6SMatthew Dillon 	u_int antMode,
485*572ff6f6SMatthew Dillon 	u_int flags,
486*572ff6f6SMatthew Dillon 	u_int rtsctsRate,
487*572ff6f6SMatthew Dillon 	u_int rtsctsDuration,
488*572ff6f6SMatthew Dillon         u_int compicvLen,
489*572ff6f6SMatthew Dillon 	u_int compivLen,
490*572ff6f6SMatthew Dillon 	u_int comp)
491*572ff6f6SMatthew Dillon {
492*572ff6f6SMatthew Dillon 	struct ar5210_desc *ads = AR5210DESC(ds);
493*572ff6f6SMatthew Dillon 	uint32_t frtype;
494*572ff6f6SMatthew Dillon 
495*572ff6f6SMatthew Dillon 	(void) txPower;
496*572ff6f6SMatthew Dillon 	(void) rtsctsDuration;
497*572ff6f6SMatthew Dillon 
498*572ff6f6SMatthew Dillon 	HALASSERT(txTries0 != 0);
499*572ff6f6SMatthew Dillon 	HALASSERT(isValidPktType(type));
500*572ff6f6SMatthew Dillon 	HALASSERT(isValidTxRate(txRate0));
501*572ff6f6SMatthew Dillon 
502*572ff6f6SMatthew Dillon 	if (type == HAL_PKT_TYPE_BEACON || type == HAL_PKT_TYPE_PROBE_RESP)
503*572ff6f6SMatthew Dillon 		frtype = AR_Frm_NoDelay;
504*572ff6f6SMatthew Dillon 	else
505*572ff6f6SMatthew Dillon 		frtype = type << 26;
506*572ff6f6SMatthew Dillon 	ads->ds_ctl0 = (pktLen & AR_FrameLen)
507*572ff6f6SMatthew Dillon 		     | (txRate0 << AR_XmitRate_S)
508*572ff6f6SMatthew Dillon 		     | ((hdrLen << AR_HdrLen_S) & AR_HdrLen)
509*572ff6f6SMatthew Dillon 		     | frtype
510*572ff6f6SMatthew Dillon 		     | (flags & HAL_TXDESC_CLRDMASK ? AR_ClearDestMask : 0)
511*572ff6f6SMatthew Dillon 		     | (flags & HAL_TXDESC_INTREQ ? AR_TxInterReq : 0)
512*572ff6f6SMatthew Dillon 		     | (antMode ? AR_AntModeXmit : 0)
513*572ff6f6SMatthew Dillon 		     ;
514*572ff6f6SMatthew Dillon 	if (keyIx != HAL_TXKEYIX_INVALID) {
515*572ff6f6SMatthew Dillon 		ads->ds_ctl1 = (keyIx << AR_EncryptKeyIdx_S) & AR_EncryptKeyIdx;
516*572ff6f6SMatthew Dillon 		ads->ds_ctl0 |= AR_EncryptKeyValid;
517*572ff6f6SMatthew Dillon 	} else
518*572ff6f6SMatthew Dillon 		ads->ds_ctl1 = 0;
519*572ff6f6SMatthew Dillon 	if (flags & HAL_TXDESC_RTSENA) {
520*572ff6f6SMatthew Dillon 		ads->ds_ctl0 |= AR_RTSCTSEnable;
521*572ff6f6SMatthew Dillon 		ads->ds_ctl1 |= (rtsctsDuration << AR_RTSDuration_S)
522*572ff6f6SMatthew Dillon 		    & AR_RTSDuration;
523*572ff6f6SMatthew Dillon 	}
524*572ff6f6SMatthew Dillon 	return AH_TRUE;
525*572ff6f6SMatthew Dillon }
526*572ff6f6SMatthew Dillon 
527*572ff6f6SMatthew Dillon HAL_BOOL
ar5210SetupXTxDesc(struct ath_hal * ah,struct ath_desc * ds,u_int txRate1,u_int txTries1,u_int txRate2,u_int txTries2,u_int txRate3,u_int txTries3)528*572ff6f6SMatthew Dillon ar5210SetupXTxDesc(struct ath_hal *ah, struct ath_desc *ds,
529*572ff6f6SMatthew Dillon 	u_int txRate1, u_int txTries1,
530*572ff6f6SMatthew Dillon 	u_int txRate2, u_int txTries2,
531*572ff6f6SMatthew Dillon 	u_int txRate3, u_int txTries3)
532*572ff6f6SMatthew Dillon {
533*572ff6f6SMatthew Dillon 	(void) ah; (void) ds;
534*572ff6f6SMatthew Dillon 	(void) txRate1; (void) txTries1;
535*572ff6f6SMatthew Dillon 	(void) txRate2; (void) txTries2;
536*572ff6f6SMatthew Dillon 	(void) txRate3; (void) txTries3;
537*572ff6f6SMatthew Dillon 	return AH_FALSE;
538*572ff6f6SMatthew Dillon }
539*572ff6f6SMatthew Dillon 
540*572ff6f6SMatthew Dillon void
ar5210IntrReqTxDesc(struct ath_hal * ah,struct ath_desc * ds)541*572ff6f6SMatthew Dillon ar5210IntrReqTxDesc(struct ath_hal *ah, struct ath_desc *ds)
542*572ff6f6SMatthew Dillon {
543*572ff6f6SMatthew Dillon 	struct ar5210_desc *ads = AR5210DESC(ds);
544*572ff6f6SMatthew Dillon 
545*572ff6f6SMatthew Dillon 	ads->ds_ctl0 |= AR_TxInterReq;
546*572ff6f6SMatthew Dillon }
547*572ff6f6SMatthew Dillon 
548*572ff6f6SMatthew Dillon HAL_BOOL
ar5210FillTxDesc(struct ath_hal * ah,struct ath_desc * ds,HAL_DMA_ADDR * bufAddrList,uint32_t * segLenList,u_int descId,u_int qcuId,HAL_BOOL firstSeg,HAL_BOOL lastSeg,const struct ath_desc * ds0)549*572ff6f6SMatthew Dillon ar5210FillTxDesc(struct ath_hal *ah, struct ath_desc *ds,
550*572ff6f6SMatthew Dillon 	HAL_DMA_ADDR *bufAddrList, uint32_t *segLenList, u_int descId,
551*572ff6f6SMatthew Dillon 	u_int qcuId, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
552*572ff6f6SMatthew Dillon 	const struct ath_desc *ds0)
553*572ff6f6SMatthew Dillon {
554*572ff6f6SMatthew Dillon 	struct ar5210_desc *ads = AR5210DESC(ds);
555*572ff6f6SMatthew Dillon 	uint32_t segLen = segLenList[0];
556*572ff6f6SMatthew Dillon 
557*572ff6f6SMatthew Dillon 	HALASSERT((segLen &~ AR_BufLen) == 0);
558*572ff6f6SMatthew Dillon 
559*572ff6f6SMatthew Dillon 	ds->ds_data = bufAddrList[0];
560*572ff6f6SMatthew Dillon 
561*572ff6f6SMatthew Dillon 	if (firstSeg) {
562*572ff6f6SMatthew Dillon 		/*
563*572ff6f6SMatthew Dillon 		 * First descriptor, don't clobber xmit control data
564*572ff6f6SMatthew Dillon 		 * setup by ar5210SetupTxDesc.
565*572ff6f6SMatthew Dillon 		 */
566*572ff6f6SMatthew Dillon 		ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_More);
567*572ff6f6SMatthew Dillon 	} else if (lastSeg) {		/* !firstSeg && lastSeg */
568*572ff6f6SMatthew Dillon 		/*
569*572ff6f6SMatthew Dillon 		 * Last descriptor in a multi-descriptor frame,
570*572ff6f6SMatthew Dillon 		 * copy the transmit parameters from the first
571*572ff6f6SMatthew Dillon 		 * frame for processing on completion.
572*572ff6f6SMatthew Dillon 		 */
573*572ff6f6SMatthew Dillon 		ads->ds_ctl0 = AR5210DESC_CONST(ds0)->ds_ctl0;
574*572ff6f6SMatthew Dillon 		ads->ds_ctl1 = segLen;
575*572ff6f6SMatthew Dillon 	} else {			/* !firstSeg && !lastSeg */
576*572ff6f6SMatthew Dillon 		/*
577*572ff6f6SMatthew Dillon 		 * Intermediate descriptor in a multi-descriptor frame.
578*572ff6f6SMatthew Dillon 		 */
579*572ff6f6SMatthew Dillon 		ads->ds_ctl0 = 0;
580*572ff6f6SMatthew Dillon 		ads->ds_ctl1 = segLen | AR_More;
581*572ff6f6SMatthew Dillon 	}
582*572ff6f6SMatthew Dillon 	ads->ds_status0 = ads->ds_status1 = 0;
583*572ff6f6SMatthew Dillon 	return AH_TRUE;
584*572ff6f6SMatthew Dillon }
585*572ff6f6SMatthew Dillon 
586*572ff6f6SMatthew Dillon /*
587*572ff6f6SMatthew Dillon  * Processing of HW TX descriptor.
588*572ff6f6SMatthew Dillon  */
589*572ff6f6SMatthew Dillon HAL_STATUS
ar5210ProcTxDesc(struct ath_hal * ah,struct ath_desc * ds,struct ath_tx_status * ts)590*572ff6f6SMatthew Dillon ar5210ProcTxDesc(struct ath_hal *ah,
591*572ff6f6SMatthew Dillon 	struct ath_desc *ds, struct ath_tx_status *ts)
592*572ff6f6SMatthew Dillon {
593*572ff6f6SMatthew Dillon 	struct ar5210_desc *ads = AR5210DESC(ds);
594*572ff6f6SMatthew Dillon 
595*572ff6f6SMatthew Dillon 	if ((ads->ds_status1 & AR_Done) == 0)
596*572ff6f6SMatthew Dillon 		return HAL_EINPROGRESS;
597*572ff6f6SMatthew Dillon 
598*572ff6f6SMatthew Dillon 	/* Update software copies of the HW status */
599*572ff6f6SMatthew Dillon 	ts->ts_seqnum = ads->ds_status1 & AR_SeqNum;
600*572ff6f6SMatthew Dillon 	ts->ts_tstamp = MS(ads->ds_status0, AR_SendTimestamp);
601*572ff6f6SMatthew Dillon 	ts->ts_status = 0;
602*572ff6f6SMatthew Dillon 	if ((ads->ds_status0 & AR_FrmXmitOK) == 0) {
603*572ff6f6SMatthew Dillon 		if (ads->ds_status0 & AR_ExcessiveRetries)
604*572ff6f6SMatthew Dillon 			ts->ts_status |= HAL_TXERR_XRETRY;
605*572ff6f6SMatthew Dillon 		if (ads->ds_status0 & AR_Filtered)
606*572ff6f6SMatthew Dillon 			ts->ts_status |= HAL_TXERR_FILT;
607*572ff6f6SMatthew Dillon 		if (ads->ds_status0  & AR_FIFOUnderrun)
608*572ff6f6SMatthew Dillon 			ts->ts_status |= HAL_TXERR_FIFO;
609*572ff6f6SMatthew Dillon 	}
610*572ff6f6SMatthew Dillon 	ts->ts_rate = MS(ads->ds_ctl0, AR_XmitRate);
611*572ff6f6SMatthew Dillon 	ts->ts_rssi = MS(ads->ds_status1, AR_AckSigStrength);
612*572ff6f6SMatthew Dillon 	ts->ts_shortretry = MS(ads->ds_status0, AR_ShortRetryCnt);
613*572ff6f6SMatthew Dillon 	ts->ts_longretry = MS(ads->ds_status0, AR_LongRetryCnt);
614*572ff6f6SMatthew Dillon 	ts->ts_antenna = 0;		/* NB: don't know */
615*572ff6f6SMatthew Dillon 	ts->ts_finaltsi = 0;
616*572ff6f6SMatthew Dillon 
617*572ff6f6SMatthew Dillon 	return HAL_OK;
618*572ff6f6SMatthew Dillon }
619*572ff6f6SMatthew Dillon 
620*572ff6f6SMatthew Dillon /*
621*572ff6f6SMatthew Dillon  * Determine which tx queues need interrupt servicing.
622*572ff6f6SMatthew Dillon  * STUB.
623*572ff6f6SMatthew Dillon  */
624*572ff6f6SMatthew Dillon void
ar5210GetTxIntrQueue(struct ath_hal * ah,uint32_t * txqs)625*572ff6f6SMatthew Dillon ar5210GetTxIntrQueue(struct ath_hal *ah, uint32_t *txqs)
626*572ff6f6SMatthew Dillon {
627*572ff6f6SMatthew Dillon 	return;
628*572ff6f6SMatthew Dillon }
629*572ff6f6SMatthew Dillon 
630*572ff6f6SMatthew Dillon /*
631*572ff6f6SMatthew Dillon  * Retrieve the rate table from the given TX completion descriptor
632*572ff6f6SMatthew Dillon  */
633*572ff6f6SMatthew Dillon HAL_BOOL
ar5210GetTxCompletionRates(struct ath_hal * ah,const struct ath_desc * ds0,int * rates,int * tries)634*572ff6f6SMatthew Dillon ar5210GetTxCompletionRates(struct ath_hal *ah, const struct ath_desc *ds0, int *rates, int *tries)
635*572ff6f6SMatthew Dillon {
636*572ff6f6SMatthew Dillon 	return AH_FALSE;
637*572ff6f6SMatthew Dillon }
638*572ff6f6SMatthew Dillon 
639*572ff6f6SMatthew Dillon /*
640*572ff6f6SMatthew Dillon  * Set the TX descriptor link pointer
641*572ff6f6SMatthew Dillon  */
642*572ff6f6SMatthew Dillon void
ar5210SetTxDescLink(struct ath_hal * ah,void * ds,uint32_t link)643*572ff6f6SMatthew Dillon ar5210SetTxDescLink(struct ath_hal *ah, void *ds, uint32_t link)
644*572ff6f6SMatthew Dillon {
645*572ff6f6SMatthew Dillon 	struct ar5210_desc *ads = AR5210DESC(ds);
646*572ff6f6SMatthew Dillon 
647*572ff6f6SMatthew Dillon 	ads->ds_link = link;
648*572ff6f6SMatthew Dillon }
649*572ff6f6SMatthew Dillon 
650*572ff6f6SMatthew Dillon /*
651*572ff6f6SMatthew Dillon  * Get the TX descriptor link pointer
652*572ff6f6SMatthew Dillon  */
653*572ff6f6SMatthew Dillon void
ar5210GetTxDescLink(struct ath_hal * ah,void * ds,uint32_t * link)654*572ff6f6SMatthew Dillon ar5210GetTxDescLink(struct ath_hal *ah, void *ds, uint32_t *link)
655*572ff6f6SMatthew Dillon {
656*572ff6f6SMatthew Dillon 	struct ar5210_desc *ads = AR5210DESC(ds);
657*572ff6f6SMatthew Dillon 
658*572ff6f6SMatthew Dillon 	*link = ads->ds_link;
659*572ff6f6SMatthew Dillon }
660*572ff6f6SMatthew Dillon 
661*572ff6f6SMatthew Dillon /*
662*572ff6f6SMatthew Dillon  * Get a pointer to the TX descriptor link pointer
663*572ff6f6SMatthew Dillon  */
664*572ff6f6SMatthew Dillon void
ar5210GetTxDescLinkPtr(struct ath_hal * ah,void * ds,uint32_t ** linkptr)665*572ff6f6SMatthew Dillon ar5210GetTxDescLinkPtr(struct ath_hal *ah, void *ds, uint32_t **linkptr)
666*572ff6f6SMatthew Dillon {
667*572ff6f6SMatthew Dillon 	struct ar5210_desc *ads = AR5210DESC(ds);
668*572ff6f6SMatthew Dillon 
669*572ff6f6SMatthew Dillon 	*linkptr = &ads->ds_link;
670*572ff6f6SMatthew Dillon }
671