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