ar5211_xmit.c revision 185406
1/*
2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2006 Atheros Communications, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 *
17 * $Id: ar5211_xmit.c,v 1.6 2008/11/10 04:08:03 sam Exp $
18 */
19#include "opt_ah.h"
20
21#include "ah.h"
22#include "ah_internal.h"
23#include "ah_desc.h"
24
25#include "ar5211/ar5211.h"
26#include "ar5211/ar5211reg.h"
27#include "ar5211/ar5211desc.h"
28
29/*
30 * Update Tx FIFO trigger level.
31 *
32 * Set bIncTrigLevel to TRUE to increase the trigger level.
33 * Set bIncTrigLevel to FALSE to decrease the trigger level.
34 *
35 * Returns TRUE if the trigger level was updated
36 */
37HAL_BOOL
38ar5211UpdateTxTrigLevel(struct ath_hal *ah, HAL_BOOL bIncTrigLevel)
39{
40	uint32_t curTrigLevel, txcfg;
41	HAL_INT ints = ar5211GetInterrupts(ah);
42
43	/*
44	 * Disable chip interrupts. This is because halUpdateTxTrigLevel
45	 * is called from both ISR and non-ISR contexts.
46	 */
47	ar5211SetInterrupts(ah, ints &~ HAL_INT_GLOBAL);
48	txcfg = OS_REG_READ(ah, AR_TXCFG);
49	curTrigLevel = (txcfg & AR_TXCFG_FTRIG_M) >> AR_TXCFG_FTRIG_S;
50	if (bIncTrigLevel){
51		/* increase the trigger level */
52		curTrigLevel = curTrigLevel +
53			((MAX_TX_FIFO_THRESHOLD - curTrigLevel) / 2);
54	} else {
55		/* decrease the trigger level if not already at the minimum */
56		if (curTrigLevel > MIN_TX_FIFO_THRESHOLD) {
57			/* decrease the trigger level */
58			curTrigLevel--;
59		} else {
60			/* no update to the trigger level */
61			/* re-enable chip interrupts */
62			ar5211SetInterrupts(ah, ints);
63			return AH_FALSE;
64		}
65	}
66	/* Update the trigger level */
67	OS_REG_WRITE(ah, AR_TXCFG, (txcfg &~ AR_TXCFG_FTRIG_M) |
68		((curTrigLevel << AR_TXCFG_FTRIG_S) & AR_TXCFG_FTRIG_M));
69	/* re-enable chip interrupts */
70	ar5211SetInterrupts(ah, ints);
71	return AH_TRUE;
72}
73
74/*
75 * Set the properties of the tx queue with the parameters
76 * from qInfo.  The queue must previously have been setup
77 * with a call to ar5211SetupTxQueue.
78 */
79HAL_BOOL
80ar5211SetTxQueueProps(struct ath_hal *ah, int q, const HAL_TXQ_INFO *qInfo)
81{
82	struct ath_hal_5211 *ahp = AH5211(ah);
83
84	if (q >= HAL_NUM_TX_QUEUES) {
85		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
86		    __func__, q);
87		return AH_FALSE;
88	}
89	return ath_hal_setTxQProps(ah, &ahp->ah_txq[q], qInfo);
90}
91
92/*
93 * Return the properties for the specified tx queue.
94 */
95HAL_BOOL
96ar5211GetTxQueueProps(struct ath_hal *ah, int q, HAL_TXQ_INFO *qInfo)
97{
98	struct ath_hal_5211 *ahp = AH5211(ah);
99
100	if (q >= HAL_NUM_TX_QUEUES) {
101		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
102		    __func__, q);
103		return AH_FALSE;
104	}
105	return ath_hal_getTxQProps(ah, qInfo, &ahp->ah_txq[q]);
106}
107
108/*
109 * Allocate and initialize a tx DCU/QCU combination.
110 */
111int
112ar5211SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,
113	const HAL_TXQ_INFO *qInfo)
114{
115	struct ath_hal_5211 *ahp = AH5211(ah);
116	HAL_TX_QUEUE_INFO *qi;
117	int q;
118
119	switch (type) {
120	case HAL_TX_QUEUE_BEACON:
121		q = 9;
122		break;
123	case HAL_TX_QUEUE_CAB:
124		q = 8;
125		break;
126	case HAL_TX_QUEUE_DATA:
127		q = 0;
128		if (ahp->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE)
129			return q;
130		break;
131	default:
132		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad tx queue type %u\n",
133		    __func__, type);
134		return -1;
135	}
136
137	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
138
139	qi = &ahp->ah_txq[q];
140	if (qi->tqi_type != HAL_TX_QUEUE_INACTIVE) {
141		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: tx queue %u already active\n",
142		    __func__, q);
143		return -1;
144	}
145	OS_MEMZERO(qi, sizeof(HAL_TX_QUEUE_INFO));
146	qi->tqi_type = type;
147	if (qInfo == AH_NULL) {
148		/* by default enable OK+ERR+DESC+URN interrupts */
149		qi->tqi_qflags =
150			  HAL_TXQ_TXOKINT_ENABLE
151			| HAL_TXQ_TXERRINT_ENABLE
152			| HAL_TXQ_TXDESCINT_ENABLE
153			| HAL_TXQ_TXURNINT_ENABLE
154			;
155		qi->tqi_aifs = INIT_AIFS;
156		qi->tqi_cwmin = HAL_TXQ_USEDEFAULT;	/* NB: do at reset */
157		qi->tqi_cwmax = INIT_CWMAX;
158		qi->tqi_shretry = INIT_SH_RETRY;
159		qi->tqi_lgretry = INIT_LG_RETRY;
160	} else
161		(void) ar5211SetTxQueueProps(ah, q, qInfo);
162	return q;
163}
164
165/*
166 * Update the h/w interrupt registers to reflect a tx q's configuration.
167 */
168static void
169setTxQInterrupts(struct ath_hal *ah, HAL_TX_QUEUE_INFO *qi)
170{
171	struct ath_hal_5211 *ahp = AH5211(ah);
172
173	HALDEBUG(ah, HAL_DEBUG_TXQUEUE,
174	    "%s: tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n", __func__
175		, ahp->ah_txOkInterruptMask
176		, ahp->ah_txErrInterruptMask
177		, ahp->ah_txDescInterruptMask
178		, ahp->ah_txEolInterruptMask
179		, ahp->ah_txUrnInterruptMask
180	);
181
182	OS_REG_WRITE(ah, AR_IMR_S0,
183		  SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK)
184		| SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC)
185	);
186	OS_REG_WRITE(ah, AR_IMR_S1,
187		  SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR)
188		| SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL)
189	);
190	OS_REG_RMW_FIELD(ah, AR_IMR_S2,
191		AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask);
192}
193
194
195/*
196 * Free a tx DCU/QCU combination.
197 */
198HAL_BOOL
199ar5211ReleaseTxQueue(struct ath_hal *ah, u_int q)
200{
201	struct ath_hal_5211 *ahp = AH5211(ah);
202	HAL_TX_QUEUE_INFO *qi;
203
204	if (q >= HAL_NUM_TX_QUEUES) {
205		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
206		    __func__, q);
207		return AH_FALSE;
208	}
209	qi = &ahp->ah_txq[q];
210	if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
211		HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",
212		    __func__, q);
213		return AH_FALSE;
214	}
215
216	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: release queue %u\n", __func__, q);
217
218	qi->tqi_type = HAL_TX_QUEUE_INACTIVE;
219	ahp->ah_txOkInterruptMask &= ~(1 << q);
220	ahp->ah_txErrInterruptMask &= ~(1 << q);
221	ahp->ah_txDescInterruptMask &= ~(1 << q);
222	ahp->ah_txEolInterruptMask &= ~(1 << q);
223	ahp->ah_txUrnInterruptMask &= ~(1 << q);
224	setTxQInterrupts(ah, qi);
225
226	return AH_TRUE;
227}
228
229/*
230 * Set the retry, aifs, cwmin/max, readyTime regs for specified queue
231 */
232HAL_BOOL
233ar5211ResetTxQueue(struct ath_hal *ah, u_int q)
234{
235	struct ath_hal_5211 *ahp = AH5211(ah);
236	HAL_CHANNEL_INTERNAL *chan = AH_PRIVATE(ah)->ah_curchan;
237	HAL_TX_QUEUE_INFO *qi;
238	uint32_t cwMin, chanCwMin, value;
239
240	if (q >= HAL_NUM_TX_QUEUES) {
241		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid queue num %u\n",
242		    __func__, q);
243		return AH_FALSE;
244	}
245	qi = &ahp->ah_txq[q];
246	if (qi->tqi_type == HAL_TX_QUEUE_INACTIVE) {
247		HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: inactive queue %u\n",
248		    __func__, q);
249		return AH_TRUE;		/* XXX??? */
250	}
251
252	if (qi->tqi_cwmin == HAL_TXQ_USEDEFAULT) {
253		/*
254		 * Select cwmin according to channel type.
255		 * NB: chan can be NULL during attach
256		 */
257		if (chan && IS_CHAN_B(chan))
258			chanCwMin = INIT_CWMIN_11B;
259		else
260			chanCwMin = INIT_CWMIN;
261		/* make sure that the CWmin is of the form (2^n - 1) */
262		for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1)
263			;
264	} else
265		cwMin = qi->tqi_cwmin;
266
267	/* set cwMin/Max and AIFS values */
268	OS_REG_WRITE(ah, AR_DLCL_IFS(q),
269		  SM(cwMin, AR_D_LCL_IFS_CWMIN)
270		| SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX)
271		| SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
272
273	/* Set retry limit values */
274	OS_REG_WRITE(ah, AR_DRETRY_LIMIT(q),
275		   SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH)
276		 | SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG)
277		 | SM(qi->tqi_lgretry, AR_D_RETRY_LIMIT_FR_LG)
278		 | SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH)
279	);
280
281	/* enable early termination on the QCU */
282	OS_REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
283
284	if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_OAHU) {
285		/* Configure DCU to use the global sequence count */
286		OS_REG_WRITE(ah, AR_DMISC(q), AR5311_D_MISC_SEQ_NUM_CONTROL);
287	}
288	/* multiqueue support */
289	if (qi->tqi_cbrPeriod) {
290		OS_REG_WRITE(ah, AR_QCBRCFG(q),
291			  SM(qi->tqi_cbrPeriod,AR_Q_CBRCFG_CBR_INTERVAL)
292			| SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_CBR_OVF_THRESH));
293		OS_REG_WRITE(ah, AR_QMISC(q),
294			OS_REG_READ(ah, AR_QMISC(q)) |
295			AR_Q_MISC_FSP_CBR |
296			(qi->tqi_cbrOverflowLimit ?
297				AR_Q_MISC_CBR_EXP_CNTR_LIMIT : 0));
298	}
299	if (qi->tqi_readyTime) {
300		OS_REG_WRITE(ah, AR_QRDYTIMECFG(q),
301			SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_INT) |
302			AR_Q_RDYTIMECFG_EN);
303	}
304	if (qi->tqi_burstTime) {
305		OS_REG_WRITE(ah, AR_DCHNTIME(q),
306			SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
307			AR_D_CHNTIME_EN);
308		if (qi->tqi_qflags & HAL_TXQ_RDYTIME_EXP_POLICY_ENABLE) {
309			OS_REG_WRITE(ah, AR_QMISC(q),
310			     OS_REG_READ(ah, AR_QMISC(q)) |
311			     AR_Q_MISC_RDYTIME_EXP_POLICY);
312		}
313	}
314
315	if (qi->tqi_qflags & HAL_TXQ_BACKOFF_DISABLE) {
316		OS_REG_WRITE(ah, AR_DMISC(q),
317			OS_REG_READ(ah, AR_DMISC(q)) |
318			AR_D_MISC_POST_FR_BKOFF_DIS);
319	}
320	if (qi->tqi_qflags & HAL_TXQ_FRAG_BURST_BACKOFF_ENABLE) {
321		OS_REG_WRITE(ah, AR_DMISC(q),
322			OS_REG_READ(ah, AR_DMISC(q)) |
323			AR_D_MISC_FRAG_BKOFF_EN);
324	}
325	switch (qi->tqi_type) {
326	case HAL_TX_QUEUE_BEACON:
327		/* Configure QCU for beacons */
328		OS_REG_WRITE(ah, AR_QMISC(q),
329			OS_REG_READ(ah, AR_QMISC(q))
330			| AR_Q_MISC_FSP_DBA_GATED
331			| AR_Q_MISC_BEACON_USE
332			| AR_Q_MISC_CBR_INCR_DIS1);
333		/* Configure DCU for beacons */
334		value = (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL << AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
335			| AR_D_MISC_BEACON_USE | AR_D_MISC_POST_FR_BKOFF_DIS;
336		if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_OAHU)
337			value |= AR5311_D_MISC_SEQ_NUM_CONTROL;
338		OS_REG_WRITE(ah, AR_DMISC(q), value);
339		break;
340	case HAL_TX_QUEUE_CAB:
341		/* Configure QCU for CAB (Crap After Beacon) frames */
342		OS_REG_WRITE(ah, AR_QMISC(q),
343			OS_REG_READ(ah, AR_QMISC(q))
344			| AR_Q_MISC_FSP_DBA_GATED | AR_Q_MISC_CBR_INCR_DIS1
345			| AR_Q_MISC_CBR_INCR_DIS0 | AR_Q_MISC_RDYTIME_EXP_POLICY);
346
347		value = (ahp->ah_beaconInterval
348			- (ath_hal_sw_beacon_response_time - ath_hal_dma_beacon_response_time)
349			- ath_hal_additional_swba_backoff) * 1024;
350		OS_REG_WRITE(ah, AR_QRDYTIMECFG(q), value | AR_Q_RDYTIMECFG_EN);
351
352		/* Configure DCU for CAB */
353		value = (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL << AR_D_MISC_ARB_LOCKOUT_CNTRL_S);
354		if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_OAHU)
355			value |= AR5311_D_MISC_SEQ_NUM_CONTROL;
356		OS_REG_WRITE(ah, AR_QMISC(q), value);
357		break;
358	default:
359		/* NB: silence compiler */
360		break;
361	}
362
363#ifndef AH_DISABLE_WME
364	/*
365	 * Yes, this is a hack and not the right way to do it, but
366	 * it does get the lockout bits and backoff set for the
367	 * high-pri WME queues for testing.  We need to either extend
368	 * the meaning of queueInfo->mode, or create something like
369	 * queueInfo->dcumode.
370	 */
371	if (qi->tqi_intFlags & HAL_TXQ_USE_LOCKOUT_BKOFF_DIS) {
372		OS_REG_WRITE(ah, AR_DMISC(q),
373			 OS_REG_READ(ah, AR_DMISC(q)) |
374			 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
375			    AR_D_MISC_ARB_LOCKOUT_CNTRL)|
376			 AR_D_MISC_POST_FR_BKOFF_DIS);
377	}
378#endif
379
380	/*
381	 * Always update the secondary interrupt mask registers - this
382	 * could be a new queue getting enabled in a running system or
383	 * hw getting re-initialized during a reset!
384	 *
385	 * Since we don't differentiate between tx interrupts corresponding
386	 * to individual queues - secondary tx mask regs are always unmasked;
387	 * tx interrupts are enabled/disabled for all queues collectively
388	 * using the primary mask reg
389	 */
390	if (qi->tqi_qflags & HAL_TXQ_TXOKINT_ENABLE)
391		ahp->ah_txOkInterruptMask |= 1 << q;
392	else
393		ahp->ah_txOkInterruptMask &= ~(1 << q);
394	if (qi->tqi_qflags & HAL_TXQ_TXERRINT_ENABLE)
395		ahp->ah_txErrInterruptMask |= 1 << q;
396	else
397		ahp->ah_txErrInterruptMask &= ~(1 << q);
398	if (qi->tqi_qflags & HAL_TXQ_TXDESCINT_ENABLE)
399		ahp->ah_txDescInterruptMask |= 1 << q;
400	else
401		ahp->ah_txDescInterruptMask &= ~(1 << q);
402	if (qi->tqi_qflags & HAL_TXQ_TXEOLINT_ENABLE)
403		ahp->ah_txEolInterruptMask |= 1 << q;
404	else
405		ahp->ah_txEolInterruptMask &= ~(1 << q);
406	if (qi->tqi_qflags & HAL_TXQ_TXURNINT_ENABLE)
407		ahp->ah_txUrnInterruptMask |= 1 << q;
408	else
409		ahp->ah_txUrnInterruptMask &= ~(1 << q);
410	setTxQInterrupts(ah, qi);
411
412	return AH_TRUE;
413}
414
415/*
416 * Get the TXDP for the specified data queue.
417 */
418uint32_t
419ar5211GetTxDP(struct ath_hal *ah, u_int q)
420{
421	HALASSERT(q < HAL_NUM_TX_QUEUES);
422	return OS_REG_READ(ah, AR_QTXDP(q));
423}
424
425/*
426 * Set the TxDP for the specified tx queue.
427 */
428HAL_BOOL
429ar5211SetTxDP(struct ath_hal *ah, u_int q, uint32_t txdp)
430{
431	HALASSERT(q < HAL_NUM_TX_QUEUES);
432	HALASSERT(AH5211(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
433
434	/*
435	 * Make sure that TXE is deasserted before setting the TXDP.  If TXE
436	 * is still asserted, setting TXDP will have no effect.
437	 */
438	HALASSERT((OS_REG_READ(ah, AR_Q_TXE) & (1 << q)) == 0);
439
440	OS_REG_WRITE(ah, AR_QTXDP(q), txdp);
441
442	return AH_TRUE;
443}
444
445/*
446 * Set Transmit Enable bits for the specified queues.
447 */
448HAL_BOOL
449ar5211StartTxDma(struct ath_hal *ah, u_int q)
450{
451	HALASSERT(q < HAL_NUM_TX_QUEUES);
452	HALASSERT(AH5211(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
453
454	/* Check that queue is not already active */
455	HALASSERT((OS_REG_READ(ah, AR_Q_TXD) & (1<<q)) == 0);
456
457	HALDEBUG(ah, HAL_DEBUG_TXQUEUE, "%s: queue %u\n", __func__, q);
458
459	/* Check to be sure we're not enabling a q that has its TXD bit set. */
460	HALASSERT((OS_REG_READ(ah, AR_Q_TXD) & (1 << q)) == 0);
461
462	OS_REG_WRITE(ah, AR_Q_TXE, 1 << q);
463	return AH_TRUE;
464}
465
466/*
467 * Return the number of frames pending on the specified queue.
468 */
469uint32_t
470ar5211NumTxPending(struct ath_hal *ah, u_int q)
471{
472	uint32_t n;
473
474	HALASSERT(q < HAL_NUM_TX_QUEUES);
475	HALASSERT(AH5211(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
476
477	n = OS_REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT_M;
478	/*
479	 * Pending frame count (PFC) can momentarily go to zero
480	 * while TXE remains asserted.  In other words a PFC of
481	 * zero is not sufficient to say that the queue has stopped.
482	 */
483	if (n == 0 && (OS_REG_READ(ah, AR_Q_TXE) & (1<<q)))
484		n = 1;			/* arbitrarily pick 1 */
485	return n;
486}
487
488/*
489 * Stop transmit on the specified queue
490 */
491HAL_BOOL
492ar5211StopTxDma(struct ath_hal *ah, u_int q)
493{
494	int i;
495
496	HALASSERT(q < HAL_NUM_TX_QUEUES);
497	HALASSERT(AH5211(ah)->ah_txq[q].tqi_type != HAL_TX_QUEUE_INACTIVE);
498
499	OS_REG_WRITE(ah, AR_Q_TXD, 1<<q);
500	for (i = 0; i < 10000; i++) {
501		if (ar5211NumTxPending(ah, q) == 0)
502			break;
503		OS_DELAY(10);
504	}
505	OS_REG_WRITE(ah, AR_Q_TXD, 0);
506
507	return (i < 10000);
508}
509
510/*
511 * Descriptor Access Functions
512 */
513
514#define	VALID_PKT_TYPES \
515	((1<<HAL_PKT_TYPE_NORMAL)|(1<<HAL_PKT_TYPE_ATIM)|\
516	 (1<<HAL_PKT_TYPE_PSPOLL)|(1<<HAL_PKT_TYPE_PROBE_RESP)|\
517	 (1<<HAL_PKT_TYPE_BEACON))
518#define	isValidPktType(_t)	((1<<(_t)) & VALID_PKT_TYPES)
519#define	VALID_TX_RATES \
520	((1<<0x0b)|(1<<0x0f)|(1<<0x0a)|(1<<0x0e)|(1<<0x09)|(1<<0x0d)|\
521	 (1<<0x08)|(1<<0x0c)|(1<<0x1b)|(1<<0x1a)|(1<<0x1e)|(1<<0x19)|\
522	 (1<<0x1d)|(1<<0x18)|(1<<0x1c))
523#define	isValidTxRate(_r)	((1<<(_r)) & VALID_TX_RATES)
524
525HAL_BOOL
526ar5211SetupTxDesc(struct ath_hal *ah, struct ath_desc *ds,
527	u_int pktLen,
528	u_int hdrLen,
529	HAL_PKT_TYPE type,
530	u_int txPower,
531	u_int txRate0, u_int txTries0,
532	u_int keyIx,
533	u_int antMode,
534	u_int flags,
535	u_int rtsctsRate,
536	u_int rtsctsDuration,
537	u_int compicvLen,
538	u_int compivLen,
539	u_int comp)
540{
541	struct ar5211_desc *ads = AR5211DESC(ds);
542
543	(void) hdrLen;
544	(void) txPower;
545	(void) rtsctsRate; (void) rtsctsDuration;
546
547	HALASSERT(txTries0 != 0);
548	HALASSERT(isValidPktType(type));
549	HALASSERT(isValidTxRate(txRate0));
550	/* XXX validate antMode */
551
552	ads->ds_ctl0 = (pktLen & AR_FrameLen)
553		     | (txRate0 << AR_XmitRate_S)
554		     | (antMode << AR_AntModeXmit_S)
555		     | (flags & HAL_TXDESC_CLRDMASK ? AR_ClearDestMask : 0)
556		     | (flags & HAL_TXDESC_INTREQ ? AR_TxInterReq : 0)
557		     | (flags & HAL_TXDESC_RTSENA ? AR_RTSCTSEnable : 0)
558		     | (flags & HAL_TXDESC_VEOL ? AR_VEOL : 0)
559		     ;
560	ads->ds_ctl1 = (type << 26)
561		     | (flags & HAL_TXDESC_NOACK ? AR_NoAck : 0)
562		     ;
563
564	if (keyIx != HAL_TXKEYIX_INVALID) {
565		ads->ds_ctl1 |=
566			(keyIx << AR_EncryptKeyIdx_S) & AR_EncryptKeyIdx;
567		ads->ds_ctl0 |= AR_EncryptKeyValid;
568	}
569	return AH_TRUE;
570#undef RATE
571}
572
573HAL_BOOL
574ar5211SetupXTxDesc(struct ath_hal *ah, struct ath_desc *ds,
575	u_int txRate1, u_int txTries1,
576	u_int txRate2, u_int txTries2,
577	u_int txRate3, u_int txTries3)
578{
579	(void) ah; (void) ds;
580	(void) txRate1; (void) txTries1;
581	(void) txRate2; (void) txTries2;
582	(void) txRate3; (void) txTries3;
583	return AH_FALSE;
584}
585
586void
587ar5211IntrReqTxDesc(struct ath_hal *ah, struct ath_desc *ds)
588{
589	struct ar5211_desc *ads = AR5211DESC(ds);
590
591	ads->ds_ctl0 |= AR_TxInterReq;
592}
593
594HAL_BOOL
595ar5211FillTxDesc(struct ath_hal *ah, struct ath_desc *ds,
596	u_int segLen, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
597	const struct ath_desc *ds0)
598{
599	struct ar5211_desc *ads = AR5211DESC(ds);
600
601	HALASSERT((segLen &~ AR_BufLen) == 0);
602
603	if (firstSeg) {
604		/*
605		 * First descriptor, don't clobber xmit control data
606		 * setup by ar5211SetupTxDesc.
607		 */
608		ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_More);
609	} else if (lastSeg) {		/* !firstSeg && lastSeg */
610		/*
611		 * Last descriptor in a multi-descriptor frame,
612		 * copy the transmit parameters from the first
613		 * frame for processing on completion.
614		 */
615		ads->ds_ctl0 = AR5211DESC_CONST(ds0)->ds_ctl0;
616		ads->ds_ctl1 = segLen;
617	} else {			/* !firstSeg && !lastSeg */
618		/*
619		 * Intermediate descriptor in a multi-descriptor frame.
620		 */
621		ads->ds_ctl0 = 0;
622		ads->ds_ctl1 = segLen | AR_More;
623	}
624	ads->ds_status0 = ads->ds_status1 = 0;
625	return AH_TRUE;
626}
627
628/*
629 * Processing of HW TX descriptor.
630 */
631HAL_STATUS
632ar5211ProcTxDesc(struct ath_hal *ah,
633	struct ath_desc *ds, struct ath_tx_status *ts)
634{
635	struct ar5211_desc *ads = AR5211DESC(ds);
636
637	if ((ads->ds_status1 & AR_Done) == 0)
638		return HAL_EINPROGRESS;
639
640	/* Update software copies of the HW status */
641	ts->ts_seqnum = MS(ads->ds_status1, AR_SeqNum);
642	ts->ts_tstamp = MS(ads->ds_status0, AR_SendTimestamp);
643	ts->ts_status = 0;
644	if ((ads->ds_status0 & AR_FrmXmitOK) == 0) {
645		if (ads->ds_status0 & AR_ExcessiveRetries)
646			ts->ts_status |= HAL_TXERR_XRETRY;
647		if (ads->ds_status0 & AR_Filtered)
648			ts->ts_status |= HAL_TXERR_FILT;
649		if (ads->ds_status0 & AR_FIFOUnderrun)
650			ts->ts_status |= HAL_TXERR_FIFO;
651	}
652	ts->ts_rate = MS(ads->ds_ctl0, AR_XmitRate);
653	ts->ts_rssi = MS(ads->ds_status1, AR_AckSigStrength);
654	ts->ts_shortretry = MS(ads->ds_status0, AR_ShortRetryCnt);
655	ts->ts_longretry = MS(ads->ds_status0, AR_LongRetryCnt);
656	ts->ts_virtcol = MS(ads->ds_status0, AR_VirtCollCnt);
657	ts->ts_antenna = 0;		/* NB: don't know */
658	ts->ts_finaltsi = 0;
659	/*
660	 * NB: the number of retries is one less than it should be.
661	 * Also, 0 retries and 1 retry are both reported as 0 retries.
662	 */
663	if (ts->ts_shortretry > 0)
664		ts->ts_shortretry++;
665	if (ts->ts_longretry > 0)
666		ts->ts_longretry++;
667
668	return HAL_OK;
669}
670
671/*
672 * Determine which tx queues need interrupt servicing.
673 * STUB.
674 */
675void
676ar5211GetTxIntrQueue(struct ath_hal *ah, uint32_t *txqs)
677{
678	return;
679}
680