2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <adf_os_types.h>
37 #include <adf_os_dma.h>
38 #include <adf_os_timer.h>
39 #include <adf_os_lock.h>
40 #include <adf_os_io.h>
41 #include <adf_os_mem.h>
42 #include <adf_os_util.h>
43 #include <adf_os_stdtypes.h>
44 #include <adf_os_defer.h>
45 #include <adf_os_atomic.h>
48 #include <adf_net_wcmd.h>
52 #ifdef USE_HEADERLEN_RESV
56 #include <ieee80211_var.h>
57 #include "if_athrate.h"
58 #include "if_athvar.h"
61 #define ath_tgt_free_skb adf_nbuf_free
63 #define OFDM_PLCP_BITS 22
64 #define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)
65 #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
71 #define HT_LTF(_ns) (4 * (_ns))
72 #define SYMBOL_TIME(_ns) ((_ns) << 2) // ns * 4 us
73 #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) // ns * 3.6 us
75 static a_uint16_t bits_per_symbol[][2] = {
77 { 26, 54 }, // 0: BPSK
78 { 52, 108 }, // 1: QPSK 1/2
79 { 78, 162 }, // 2: QPSK 3/4
80 { 104, 216 }, // 3: 16-QAM 1/2
81 { 156, 324 }, // 4: 16-QAM 3/4
82 { 208, 432 }, // 5: 64-QAM 2/3
83 { 234, 486 }, // 6: 64-QAM 3/4
84 { 260, 540 }, // 7: 64-QAM 5/6
85 { 52, 108 }, // 8: BPSK
86 { 104, 216 }, // 9: QPSK 1/2
87 { 156, 324 }, // 10: QPSK 3/4
88 { 208, 432 }, // 11: 16-QAM 1/2
89 { 312, 648 }, // 12: 16-QAM 3/4
90 { 416, 864 }, // 13: 64-QAM 2/3
91 { 468, 972 }, // 14: 64-QAM 3/4
92 { 520, 1080 }, // 15: 64-QAM 5/6
95 void owltgt_tx_processq(struct ath_softc_tgt *sc, struct ath_txq *txq,
96 owl_txq_state_t txqstate);
97 static void ath_tgt_txqaddbuf(struct ath_softc_tgt *sc, struct ath_txq *txq,
98 struct ath_tx_buf *bf, struct ath_tx_desc *lastds);
99 void ath_rate_findrate_11n_Hardcoded(struct ath_softc_tgt *sc,
100 struct ath_rc_series series[]);
101 void ath_buf_set_rate_Hardcoded(struct ath_softc_tgt *sc,
102 struct ath_tx_buf *bf) ;
103 static a_int32_t ath_tgt_txbuf_setup(struct ath_softc_tgt *sc,
104 struct ath_tx_buf *bf, ath_data_hdr_t *dh);
105 static void ath_tx_freebuf(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
106 static void ath_tx_uc_comp(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
107 static void ath_update_stats(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
108 void adf_print_buf(adf_nbuf_t buf);
109 static void ath_tgt_tx_enqueue(struct ath_txq *txq, struct ath_atx_tid *tid);
111 void ath_tgt_tx_comp_aggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
112 struct ieee80211_frame *ATH_SKB_2_WH(adf_nbuf_t skb);
114 void ath_tgt_tx_send_normal(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
116 static void ath_tgt_tx_sched_normal(struct ath_softc_tgt *sc, ath_atx_tid_t *tid);
117 static void ath_tgt_tx_sched_aggr(struct ath_softc_tgt *sc, ath_atx_tid_t *tid);
119 extern a_int32_t ath_chainmask_sel_logic(void *);
120 static a_int32_t ath_get_pktlen(struct ath_tx_buf *bf, a_int32_t hdrlen);
121 static void ath_tgt_txq_schedule(struct ath_softc_tgt *sc, struct ath_txq *txq);
123 typedef void (*ath_ft_set_atype_t)(struct ath_softc_tgt *sc, struct ath_buf *bf);
126 ath_tx_set_retry(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
129 ath_bar_tx(struct ath_softc_tgt *sc, ath_atx_tid_t *tid, struct ath_tx_buf *bf);
131 ath_tx_update_baw(ath_atx_tid_t *tid, int seqno);
133 ath_tx_retry_subframe(struct ath_softc_tgt *sc, struct ath_tx_buf *bf,
134 ath_tx_bufhead *bf_q, struct ath_tx_buf **bar);
137 ath_tx_comp_aggr_error(struct ath_softc_tgt *sc, struct ath_tx_buf *bf, ath_atx_tid_t *tid);
139 void ath_tx_addto_baw(ath_atx_tid_t *tid, struct ath_tx_buf *bf);
140 static inline void ath_tx_retry_unaggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
141 static void ath_tx_comp_unaggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
142 static void ath_update_aggr_stats(struct ath_softc_tgt *sc, struct ath_tx_desc *ds,
143 int nframes, int nbad);
144 static inline void ath_aggr_resume_tid(struct ath_softc_tgt *sc, ath_atx_tid_t *tid);
145 static void ath_tx_comp_cleanup(struct ath_softc_tgt *sc, struct ath_tx_buf *bf);
147 int ath_tgt_tx_add_to_aggr(struct ath_softc_tgt *sc,
148 struct ath_buf *bf,int datatype,
149 ath_atx_tid_t *tid, int is_burst);
151 struct ieee80211_frame *ATH_SKB_2_WH(adf_nbuf_t skb)
156 adf_nbuf_peek_header(skb, &anbdata, &anblen);
158 return((struct ieee80211_frame *)anbdata);
161 #undef adf_os_cpu_to_le16
163 static a_uint16_t adf_os_cpu_to_le16(a_uint16_t x)
165 return ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8));
169 ath_aggr_resume_tid(struct ath_softc_tgt *sc, ath_atx_tid_t *tid)
173 txq = TID_TO_ACTXQ(tid->tidno);
176 if (asf_tailq_empty(&tid->buf_q))
179 ath_tgt_tx_enqueue(txq, tid);
180 ath_tgt_txq_schedule(sc, txq);
184 ath_aggr_pause_tid(struct ath_softc_tgt *sc, ath_atx_tid_t *tid)
189 static a_uint32_t ath_pkt_duration(struct ath_softc_tgt *sc,
190 a_uint8_t rix, struct ath_tx_buf *bf,
191 a_int32_t width, a_int32_t half_gi)
193 const HAL_RATE_TABLE *rt = sc->sc_currates;
194 a_uint32_t nbits, nsymbits, duration, nsymbols;
199 pktlen = bf->bf_isaggr ? bf->bf_al : bf->bf_pktlen;
200 rc = rt->info[rix].rateCode;
203 return ath_hal_computetxtime(sc->sc_ah, rt, pktlen, rix,
206 nbits = (pktlen << 3) + OFDM_PLCP_BITS;
207 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
208 nsymbols = (nbits + nsymbits - 1) / nsymbits;
211 duration = SYMBOL_TIME(nsymbols);
213 duration = SYMBOL_TIME_HALFGI(nsymbols);
215 streams = HT_RC_2_STREAMS(rc);
216 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
221 static void ath_dma_map(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
223 adf_nbuf_t skb = bf->bf_skb;
225 skb = adf_nbuf_queue_first(&bf->bf_skbhead);
226 adf_nbuf_map(sc->sc_dev, bf->bf_dmamap, skb, ADF_OS_DMA_TO_DEVICE);
229 static void ath_dma_unmap(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
231 adf_nbuf_t skb = bf->bf_skb;
233 skb = adf_nbuf_queue_first(&bf->bf_skbhead);
234 adf_nbuf_unmap( sc->sc_dev, bf->bf_dmamap, ADF_OS_DMA_TO_DEVICE);
237 static void ath_filltxdesc(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
239 struct ath_tx_desc *ds0, *ds = bf->bf_desc;
243 adf_nbuf_dmamap_info(bf->bf_dmamap, &bf->bf_dmamap_info);
245 for (i = 0; i < bf->bf_dmamap_info.nsegs; i++, ds++) {
247 ds->ds_data = bf->bf_dmamap_info.dma_segs[i].paddr;
249 if (i == (bf->bf_dmamap_info.nsegs - 1)) {
253 ds->ds_link = ATH_BUF_GET_DESC_PHY_ADDR_WITH_IDX(bf, i+1);
255 ath_hal_filltxdesc(sc->sc_ah, ds
256 , bf->bf_dmamap_info.dma_segs[i].len
258 , i == (bf->bf_dmamap_info.nsegs - 1)
263 static void ath_tx_tgt_setds(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
265 struct ath_tx_desc *ds = bf->bf_desc;
267 switch (bf->bf_protmode) {
268 case IEEE80211_PROT_RTSCTS:
269 bf->bf_flags |= HAL_TXDESC_RTSENA;
271 case IEEE80211_PROT_CTSONLY:
272 bf->bf_flags |= HAL_TXDESC_CTSENA;
278 ath_hal_set11n_txdesc(sc->sc_ah, ds
284 , bf->bf_flags | HAL_TXDESC_INTREQ);
286 ath_filltxdesc(sc, bf);
289 static struct ath_tx_buf *ath_buf_toggle(struct ath_softc_tgt *sc,
290 struct ath_tx_buf *bf,
293 struct ath_tx_buf *tmp = NULL;
294 adf_nbuf_t buf = NULL;
296 adf_os_assert(sc->sc_txbuf_held != NULL);
298 tmp = sc->sc_txbuf_held;
301 ath_dma_unmap(sc, bf);
302 adf_nbuf_queue_init(&tmp->bf_skbhead);
303 buf = adf_nbuf_queue_remove(&bf->bf_skbhead);
305 adf_nbuf_queue_add(&tmp->bf_skbhead, buf);
307 adf_os_assert(adf_nbuf_queue_len(&bf->bf_skbhead) == 0);
309 tmp->bf_next = bf->bf_next;
310 tmp->bf_endpt = bf->bf_endpt;
311 tmp->bf_tidno = bf->bf_tidno;
312 tmp->bf_skb = bf->bf_skb;
313 tmp->bf_node = bf->bf_node;
314 tmp->bf_isaggr = bf->bf_isaggr;
315 tmp->bf_flags = bf->bf_flags;
316 tmp->bf_state = bf->bf_state;
317 tmp->bf_retries = bf->bf_retries;
318 tmp->bf_comp = bf->bf_comp;
319 tmp->bf_nframes = bf->bf_nframes;
320 tmp->bf_cookie = bf->bf_cookie;
332 ath_dma_map(sc, tmp);
333 ath_tx_tgt_setds(sc, tmp);
336 sc->sc_txbuf_held = bf;
341 static void ath_tgt_skb_free(struct ath_softc_tgt *sc,
342 adf_nbuf_queue_t *head,
343 HTC_ENDPOINT_ID endpt)
347 while (adf_nbuf_queue_len(head) != 0) {
348 tskb = adf_nbuf_queue_remove(head);
349 ath_free_tx_skb(sc->tgt_htc_handle,endpt,tskb);
353 static void ath_buf_comp(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
355 ath_dma_unmap(sc, bf);
356 ath_tgt_skb_free(sc, &bf->bf_skbhead,bf->bf_endpt);
359 bf = ath_buf_toggle(sc, bf, 0);
361 asf_tailq_insert_tail(&sc->sc_txbuf, bf, bf_list);
365 static void ath_buf_set_rate(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
367 struct ath_hal *ah = sc->sc_ah;
368 const HAL_RATE_TABLE *rt;
369 struct ath_tx_desc *ds = bf->bf_desc;
370 HAL_11N_RATE_SERIES series[4];
372 a_uint8_t rix, cix, rtsctsrate;
373 a_uint32_t ctsduration = 0;
374 a_int32_t prot_mode = AH_FALSE;
376 rt = sc->sc_currates;
377 rix = bf->bf_rcs[0].rix;
378 flags = (bf->bf_flags & (HAL_TXDESC_RTSENA | HAL_TXDESC_CTSENA));
379 cix = rt->info[sc->sc_protrix].controlRate;
381 if (bf->bf_protmode != IEEE80211_PROT_NONE &&
382 (rt->info[rix].phy == IEEE80211_T_OFDM ||
383 rt->info[rix].phy == IEEE80211_T_HT) &&
384 (bf->bf_flags & HAL_TXDESC_NOACK) == 0) {
385 cix = rt->info[sc->sc_protrix].controlRate;
388 if (ath_hal_htsupported(ah) && (!bf->bf_ismcast))
389 flags = HAL_TXDESC_RTSENA;
392 if (bf->bf_rcs[i].tries) {
393 cix = rt->info[bf->bf_rcs[i].rix].controlRate;
400 adf_os_mem_set(series, 0, sizeof(HAL_11N_RATE_SERIES) * 4);
402 for (i = 0; i < 4; i++) {
403 if (!bf->bf_rcs[i].tries)
406 rix = bf->bf_rcs[i].rix;
408 series[i].Rate = rt->info[rix].rateCode |
409 (bf->bf_shpream ? rt->info[rix].shortPreamble : 0);
411 series[i].Tries = bf->bf_rcs[i].tries;
413 series[i].RateFlags = ((bf->bf_rcs[i].flags & ATH_RC_RTSCTS_FLAG) ?
414 HAL_RATESERIES_RTS_CTS : 0 ) |
415 ((bf->bf_rcs[i].flags & ATH_RC_CW40_FLAG) ?
416 HAL_RATESERIES_2040 : 0 ) |
417 ((bf->bf_rcs[i].flags & ATH_RC_HT40_SGI_FLAG) ?
418 HAL_RATESERIES_HALFGI : 0 ) |
419 ((bf->bf_rcs[i].flags & ATH_RC_TX_STBC_FLAG) ?
420 HAL_RATESERIES_STBC: 0);
422 series[i].RateFlags = ((bf->bf_rcs[i].flags & ATH_RC_RTSCTS_FLAG) ?
423 HAL_RATESERIES_RTS_CTS : 0 ) |
424 ((bf->bf_rcs[i].flags & ATH_RC_CW40_FLAG) ?
425 HAL_RATESERIES_2040 : 0 ) |
426 ((bf->bf_rcs[i].flags & ATH_RC_HT40_SGI_FLAG) ?
427 HAL_RATESERIES_HALFGI : 0 );
429 series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
430 (bf->bf_rcs[i].flags & ATH_RC_CW40_FLAG) != 0,
431 (bf->bf_rcs[i].flags & ATH_RC_HT40_SGI_FLAG));
433 series[i].ChSel = sc->sc_ic.ic_tx_chainmask;
436 series[i].RateFlags |= HAL_RATESERIES_RTS_CTS;
438 if (bf->bf_rcs[i].flags & ATH_RC_DS_FLAG)
439 series[i].RateFlags |= HAL_RATESERIES_RTS_CTS;
442 rtsctsrate = rt->info[cix].rateCode |
443 (bf->bf_shpream ? rt->info[cix].shortPreamble : 0);
445 ath_hal_set11n_ratescenario(ah, ds, 1,
446 rtsctsrate, ctsduration,
451 static void ath_tgt_rate_findrate(struct ath_softc_tgt *sc,
452 struct ath_node_target *an,
453 a_int32_t shortPreamble,
459 struct ath_rc_series series[],
462 ath_rate_findrate(sc, an, 1, frameLen, 10, 4, 1,
463 ATH_RC_PROBE_ALLOWED, series, isProbe);
466 static void owl_tgt_tid_init(struct ath_atx_tid *tid)
470 tid->seq_start = tid->seq_next = 0;
471 tid->baw_size = WME_MAX_BA;
472 tid->baw_head = tid->baw_tail = 0;
475 tid->sched = AH_FALSE;
477 asf_tailq_init(&tid->buf_q);
479 for (i = 0; i < ATH_TID_MAX_BUFS; i++) {
480 TX_BUF_BITMAP_CLR(tid->tx_buf_bitmap, i);
484 static void owl_tgt_tid_cleanup(struct ath_softc_tgt *sc,
485 struct ath_atx_tid *tid)
492 tid->flag &= ~TID_CLEANUP_INPROGRES;
494 if (tid->flag & TID_REINITIALIZE) {
495 adf_os_print("TID REINIT DONE for tid %p\n", tid);
496 tid->flag &= ~TID_REINITIALIZE;
497 owl_tgt_tid_init(tid);
499 ath_aggr_resume_tid(sc, tid);
503 void owl_tgt_node_init(struct ath_node_target * an)
505 struct ath_atx_tid *tid;
508 for (tidno = 0, tid = &an->tid[tidno]; tidno < WME_NUM_TID;tidno++, tid++) {
512 if ( tid->flag & TID_CLEANUP_INPROGRES ) {
513 tid->flag |= TID_REINITIALIZE;
514 adf_os_print("tid[%p]->incomp is not 0: %d\n",
517 owl_tgt_tid_init(tid);
522 void ath_tx_status_clear(struct ath_softc_tgt *sc)
526 for (i = 0; i < 2; i++) {
527 sc->tx_status[i].cnt = 0;
531 static WMI_TXSTATUS_EVENT *ath_tx_status_get(struct ath_softc_tgt *sc)
533 WMI_TXSTATUS_EVENT *txs = NULL;
536 for (i = 0; i < 2; i++) {
537 if (sc->tx_status[i].cnt < HTC_MAX_TX_STATUS) {
538 txs = &sc->tx_status[i];
546 void ath_tx_status_update(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
548 struct ath_tx_desc *ds = bf->bf_lastds;
549 WMI_TXSTATUS_EVENT *txs;
551 if (sc->sc_tx_draining)
554 txs = ath_tx_status_get(sc);
558 txs->txstatus[txs->cnt].cookie = bf->bf_cookie;
559 txs->txstatus[txs->cnt].ts_rate = SM(bf->bf_endpt, ATH9K_HTC_TXSTAT_EPID);
561 if (ds->ds_txstat.ts_status & HAL_TXERR_FILT)
562 txs->txstatus[txs->cnt].ts_flags |= ATH9K_HTC_TXSTAT_FILT;
564 if (!(ds->ds_txstat.ts_status & HAL_TXERR_XRETRY) &&
565 !(ds->ds_txstat.ts_status & HAL_TXERR_FIFO) &&
566 !(ds->ds_txstat.ts_status & HAL_TXERR_TIMER_EXPIRED) &&
567 !(ds->ds_txstat.ts_status & HAL_TXERR_FILT))
568 txs->txstatus[txs->cnt].ts_flags |= ATH9K_HTC_TXSTAT_ACK;
570 ath_tx_status_update_rate(sc, bf->bf_rcs, ds->ds_txstat.ts_rate, txs);
575 void ath_tx_status_update_aggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf,
576 struct ath_tx_desc *ds, struct ath_rc_series rcs[],
579 WMI_TXSTATUS_EVENT *txs;
581 if (sc->sc_tx_draining)
584 txs = ath_tx_status_get(sc);
588 txs->txstatus[txs->cnt].cookie = bf->bf_cookie;
589 txs->txstatus[txs->cnt].ts_rate = SM(bf->bf_endpt, ATH9K_HTC_TXSTAT_EPID);
592 txs->txstatus[txs->cnt].ts_flags |= ATH9K_HTC_TXSTAT_ACK;
595 ath_tx_status_update_rate(sc, rcs, ds->ds_txstat.ts_rate, txs);
600 void ath_tx_status_send(struct ath_softc_tgt *sc)
604 if (sc->sc_tx_draining)
607 for (i = 0; i < 2; i++) {
608 if (sc->tx_status[i].cnt) {
609 wmi_event(sc->tgt_wmi_handle, WMI_TXSTATUS_EVENTID,
610 &sc->tx_status[i], sizeof(WMI_TXSTATUS_EVENT));
611 /* FIXME: Handle failures. */
612 sc->tx_status[i].cnt = 0;
617 static void owltgt_tx_process_cabq(struct ath_softc_tgt *sc, struct ath_txq *txq)
619 ath_hal_intrset(sc->sc_ah, sc->sc_imask & ~HAL_INT_SWBA);
620 owltgt_tx_processq(sc, txq, OWL_TXQ_ACTIVE);
621 ath_hal_intrset(sc->sc_ah, sc->sc_imask);
624 void owl_tgt_tx_tasklet(TQUEUE_ARG data)
626 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)data;
630 ath_tx_status_clear(sc);
632 for (i = 0; i < (HAL_NUM_TX_QUEUES - 6); i++) {
633 txq = ATH_TXQ(sc, i);
635 if (ATH_TXQ_SETUP(sc, i)) {
636 if (txq == sc->sc_cabq)
637 owltgt_tx_process_cabq(sc, txq);
639 owltgt_tx_processq(sc, txq, OWL_TXQ_ACTIVE);
643 ath_tx_status_send(sc);
646 void owltgt_tx_processq(struct ath_softc_tgt *sc, struct ath_txq *txq,
647 owl_txq_state_t txqstate)
649 struct ath_tx_buf *bf;
650 struct ath_tx_desc *ds;
654 if (asf_tailq_empty(&txq->axq_q)) {
655 txq->axq_link = NULL;
656 txq->axq_linkbuf = NULL;
660 bf = asf_tailq_first(&txq->axq_q);
663 status = ath_hal_txprocdesc(sc->sc_ah, ds);
665 if (status == HAL_EINPROGRESS) {
666 if (txqstate == OWL_TXQ_ACTIVE)
668 else if (txqstate == OWL_TXQ_STOPPED) {
669 __stats(sc, tx_stopfiltered);
670 ds->ds_txstat.ts_flags = 0;
671 ds->ds_txstat.ts_status = HAL_OK;
673 ds->ds_txstat.ts_flags = HAL_TX_SW_FILTERED;
677 ATH_TXQ_REMOVE_HEAD(txq, bf, bf_list);
678 if ((asf_tailq_empty(&txq->axq_q))) {
679 __stats(sc, tx_qnull);
680 txq->axq_link = NULL;
681 txq->axq_linkbuf = NULL;
687 ath_tx_status_update(sc, bf);
688 ath_buf_comp(sc, bf);
691 if (txqstate == OWL_TXQ_ACTIVE) {
692 ath_tgt_txq_schedule(sc, txq);
697 static struct ieee80211_frame* ATH_SKB2_WH(adf_nbuf_t skb)
702 adf_nbuf_peek_header(skb, &anbdata, &anblen);
703 return((struct ieee80211_frame *)anbdata);
707 ath_tgt_tid_drain(struct ath_softc_tgt *sc, struct ath_atx_tid *tid)
709 struct ath_tx_buf *bf;
711 while (!asf_tailq_empty(&tid->buf_q)) {
712 TAILQ_DEQ(&tid->buf_q, bf, bf_list);
713 ath_tx_freebuf(sc, bf);
716 tid->seq_next = tid->seq_start;
717 tid->baw_tail = tid->baw_head;
720 static void ath_tgt_tx_comp_normal(struct ath_softc_tgt *sc,
721 struct ath_tx_buf *bf)
723 struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
724 ath_atx_tid_t *tid = ATH_AN_2_TID(an, bf->bf_tidno);
726 if (tid->flag & TID_CLEANUP_INPROGRES) {
727 owl_tgt_tid_cleanup(sc, tid);
731 ath_tx_uc_comp(sc, bf);
734 ath_tx_freebuf(sc, bf);
737 static struct ieee80211_node_target * ath_tgt_find_node(struct ath_softc_tgt *sc,
738 a_int32_t node_index)
740 struct ath_node_target *an;
741 struct ieee80211_node_target *ni;
743 if (node_index > TARGET_NODE_MAX)
746 an = &sc->sc_sta[node_index];
750 if (ni->ni_vap == NULL) {
759 static struct ath_tx_buf* ath_tx_buf_alloc(struct ath_softc_tgt *sc)
761 struct ath_tx_buf *bf = NULL;
763 bf = asf_tailq_first(&sc->sc_txbuf);
765 adf_os_mem_set(&bf->bf_state, 0, sizeof(struct ath_buf_state));
766 asf_tailq_remove(&sc->sc_txbuf, bf, bf_list);
774 struct ath_tx_buf* ath_tgt_tx_prepare(struct ath_softc_tgt *sc,
775 adf_nbuf_t skb, ath_data_hdr_t *dh)
777 struct ath_tx_buf *bf;
778 struct ieee80211_node_target *ni;
779 struct ath_atx_tid *tid;
781 ni = ath_tgt_find_node(sc, dh->ni_index);
785 tid = ATH_AN_2_TID(ATH_NODE_TARGET(ni), dh->tidno);
786 if (tid->flag & TID_REINITIALIZE) {
787 adf_os_print("drop frame due to TID reinit\n");
791 bf = ath_tx_buf_alloc(sc);
793 __stats(sc, tx_nobufs);
797 bf->bf_tidno = dh->tidno;
798 bf->bf_txq = TID_TO_ACTXQ(bf->bf_tidno);
799 bf->bf_keytype = dh->keytype;
800 bf->bf_keyix = dh->keyix;
801 bf->bf_protmode = dh->flags & (IEEE80211_PROT_RTSCTS | IEEE80211_PROT_CTSONLY);
804 adf_nbuf_queue_add(&bf->bf_skbhead, skb);
805 skb = adf_nbuf_queue_first(&(bf->bf_skbhead));
807 if (adf_nbuf_queue_len(&(bf->bf_skbhead)) == 0) {
808 __stats(sc, tx_noskbs);
816 ath_tgt_txbuf_setup(sc, bf, dh);
818 ath_tx_tgt_setds(sc, bf);
823 static void ath_tgt_tx_seqno_normal(struct ath_tx_buf *bf)
825 struct ieee80211_node_target *ni = bf->bf_node;
826 struct ath_node_target *an = ATH_NODE_TARGET(ni);
827 struct ieee80211_frame *wh = ATH_SKB_2_WH(bf->bf_skb);
828 struct ath_atx_tid *tid = ATH_AN_2_TID(an, bf->bf_tidno);
830 u_int8_t fragno = (wh->i_seq[0] & 0xf);
832 INCR(ni->ni_txseqmgmt, IEEE80211_SEQ_MAX);
834 bf->bf_seqno = (tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT);
836 *(u_int16_t *)wh->i_seq = adf_os_cpu_to_le16(bf->bf_seqno);
837 wh->i_seq[0] |= fragno;
839 if (!(wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG))
840 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
843 static a_int32_t ath_key_setup(struct ieee80211_node_target *ni,
844 struct ath_tx_buf *bf)
846 struct ieee80211_frame *wh = ATH_SKB_2_WH(bf->bf_skb);
848 if (!(wh->i_fc[1] & IEEE80211_FC1_WEP)) {
849 bf->bf_keytype = HAL_KEY_TYPE_CLEAR;
850 bf->bf_keyix = HAL_TXKEYIX_INVALID;
854 switch (bf->bf_keytype) {
855 case HAL_KEY_TYPE_WEP:
856 bf->bf_pktlen += IEEE80211_WEP_ICVLEN;
858 case HAL_KEY_TYPE_AES:
859 bf->bf_pktlen += IEEE80211_WEP_MICLEN;
861 case HAL_KEY_TYPE_TKIP:
862 bf->bf_pktlen += IEEE80211_WEP_ICVLEN;
868 if (bf->bf_keytype == HAL_KEY_TYPE_AES ||
869 bf->bf_keytype == HAL_KEY_TYPE_TKIP)
870 ieee80211_tgt_crypto_encap(wh, ni, bf->bf_keytype);
875 static void ath_tgt_txq_add_ucast(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
877 struct ath_hal *ah = sc->sc_ah;
880 volatile a_int32_t txe_val;
886 status = ath_hal_txprocdesc(sc->sc_ah, bf->bf_lastds);
888 ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
890 if (txq->axq_link == NULL) {
891 ath_hal_puttxbuf(ah, txq->axq_qnum, ATH_BUF_GET_DESC_PHY_ADDR(bf));
893 *txq->axq_link = ATH_BUF_GET_DESC_PHY_ADDR(bf);
895 txe_val = OS_REG_READ(ah, 0x840);
896 if (!(txe_val & (1<< txq->axq_qnum)))
897 ath_hal_puttxbuf(ah, txq->axq_qnum, ATH_BUF_GET_DESC_PHY_ADDR(bf));
900 txq->axq_link = &bf->bf_lastds->ds_link;
901 ath_hal_txstart(ah, txq->axq_qnum);
904 static a_int32_t ath_tgt_txbuf_setup(struct ath_softc_tgt *sc,
905 struct ath_tx_buf *bf,
909 struct ieee80211_frame *wh = ATH_SKB2_WH(bf->bf_skb);
911 a_uint32_t flags = adf_os_ntohl(dh->flags);
913 ath_tgt_tx_seqno_normal(bf);
915 bf->bf_txq_add = ath_tgt_txq_add_ucast;
916 bf->bf_hdrlen = ieee80211_anyhdrsize(wh);
917 bf->bf_pktlen = ath_get_pktlen(bf, bf->bf_hdrlen);
918 bf->bf_ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
920 if ((retval = ath_key_setup(bf->bf_node, bf)) < 0)
923 if (flags & ATH_SHORT_PREAMBLE)
924 bf->bf_shpream = AH_TRUE;
926 bf->bf_shpream = AH_FALSE;
928 bf->bf_flags = HAL_TXDESC_CLRDMASK;
929 bf->bf_atype = HAL_PKT_TYPE_NORMAL;
935 ath_get_pktlen(struct ath_tx_buf *bf, a_int32_t hdrlen)
937 adf_nbuf_t skb = bf->bf_skb;
940 skb = adf_nbuf_queue_first(&bf->bf_skbhead);
941 pktlen = adf_nbuf_len(skb);
943 pktlen -= (hdrlen & 3);
944 pktlen += IEEE80211_CRC_LEN;
950 ath_tgt_tx_send_normal(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
952 struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
953 struct ath_rc_series rcs[4];
954 struct ath_rc_series mrcs[4];
955 a_int32_t shortPreamble = 0;
956 a_int32_t isProbe = 0;
958 adf_os_mem_set(rcs, 0, sizeof(struct ath_rc_series)*4 );
959 adf_os_mem_set(mrcs, 0, sizeof(struct ath_rc_series)*4 );
961 if (!bf->bf_ismcast) {
962 ath_tgt_rate_findrate(sc, an, shortPreamble,
965 ath_hal_memcpy(bf->bf_rcs, rcs, sizeof(rcs));
967 mrcs[1].tries = mrcs[2].tries = mrcs[3].tries = 0;
968 mrcs[1].rix = mrcs[2].rix = mrcs[3].rix = 0;
972 ath_hal_memcpy(bf->bf_rcs, mrcs, sizeof(mrcs));
975 ath_buf_set_rate(sc, bf);
976 bf->bf_txq_add(sc, bf);
980 ath_tx_freebuf(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
983 struct ath_tx_desc *bfd = NULL;
985 for (bfd = bf->bf_desc, i = 0; i < bf->bf_dmamap_info.nsegs; bfd++, i++) {
986 ath_hal_clr11n_aggr(sc->sc_ah, bfd);
987 ath_hal_set11n_burstduration(sc->sc_ah, bfd, 0);
988 ath_hal_set11n_virtualmorefrag(sc->sc_ah, bfd, 0);
991 ath_dma_unmap(sc, bf);
993 ath_tgt_skb_free(sc, &bf->bf_skbhead,bf->bf_endpt);
999 bf = ath_buf_toggle(sc, bf, 0);
1001 bf->bf_isretried = 0;
1004 asf_tailq_insert_tail(&sc->sc_txbuf, bf, bf_list);
1008 ath_tx_uc_comp(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1010 ath_tx_status_update(sc, bf);
1011 ath_update_stats(sc, bf);
1012 ath_rate_tx_complete(sc, ATH_NODE_TARGET(bf->bf_node),
1013 bf->bf_lastds, bf->bf_rcs, 1, 0);
1017 ath_update_stats(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1019 struct ath_tx_desc *ds = bf->bf_desc;
1022 if (ds->ds_txstat.ts_status == 0) {
1023 if (ds->ds_txstat.ts_rate & HAL_TXSTAT_ALTRATE)
1024 sc->sc_tx_stats.ast_tx_altrate++;
1026 if (ds->ds_txstat.ts_status & HAL_TXERR_XRETRY)
1027 sc->sc_tx_stats.ast_tx_xretries++;
1028 if (ds->ds_txstat.ts_status & HAL_TXERR_FIFO)
1029 sc->sc_tx_stats.ast_tx_fifoerr++;
1030 if (ds->ds_txstat.ts_status & HAL_TXERR_FILT)
1031 sc->sc_tx_stats.ast_tx_filtered++;
1032 if (ds->ds_txstat.ts_status & HAL_TXERR_TIMER_EXPIRED)
1033 sc->sc_tx_stats.ast_tx_timer_exp++;
1035 sr = ds->ds_txstat.ts_shortretry;
1036 lr = ds->ds_txstat.ts_longretry;
1037 sc->sc_tx_stats.ast_tx_shortretry += sr;
1038 sc->sc_tx_stats.ast_tx_longretry += lr;
1042 ath_tgt_send_mgt(struct ath_softc_tgt *sc,adf_nbuf_t hdr_buf, adf_nbuf_t skb,
1043 HTC_ENDPOINT_ID endpt)
1045 struct ieee80211_node_target *ni;
1046 struct ieee80211vap_target *vap;
1047 struct ath_vap_target *avp;
1048 struct ath_hal *ah = sc->sc_ah;
1049 a_uint8_t rix, txrate, ctsrate, cix = 0xff, *data;
1050 a_uint32_t ivlen = 0, icvlen = 0, subtype, flags, ctsduration;
1051 a_int32_t i, iswep, ismcast, hdrlen, pktlen, try0, len;
1052 struct ath_tx_desc *ds=NULL;
1053 struct ath_txq *txq=NULL;
1054 struct ath_tx_buf *bf;
1056 const HAL_RATE_TABLE *rt;
1057 HAL_BOOL shortPreamble;
1058 struct ieee80211_frame *wh;
1059 struct ath_rc_series rcs[4];
1060 HAL_11N_RATE_SERIES series[4];
1065 adf_nbuf_peek_header(skb, &data, &len);
1066 adf_nbuf_pull_head(skb, sizeof(ath_mgt_hdr_t));
1068 adf_nbuf_peek_header(hdr_buf, &data, &len);
1071 adf_os_assert(len >= sizeof(ath_mgt_hdr_t));
1073 mh = (ath_mgt_hdr_t *)data;
1074 adf_nbuf_peek_header(skb, &data, &len);
1075 wh = (struct ieee80211_frame *)data;
1077 adf_os_mem_set(rcs, 0, sizeof(struct ath_rc_series)*4);
1078 adf_os_mem_set(series, 0, sizeof(HAL_11N_RATE_SERIES)*4);
1080 bf = asf_tailq_first(&sc->sc_txbuf);
1084 asf_tailq_remove(&sc->sc_txbuf, bf, bf_list);
1086 ni = ath_tgt_find_node(sc, mh->ni_index);
1090 bf->bf_endpt = endpt;
1091 bf->bf_cookie = mh->cookie;
1092 bf->bf_protmode = mh->flags & (IEEE80211_PROT_RTSCTS | IEEE80211_PROT_CTSONLY);
1093 txq = &sc->sc_txq[1];
1094 iswep = wh->i_fc[1] & IEEE80211_FC1_WEP;
1095 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
1096 hdrlen = ieee80211_anyhdrsize(wh);
1098 keyix = HAL_TXKEYIX_INVALID;
1099 pktlen -= (hdrlen & 3);
1100 pktlen += IEEE80211_CRC_LEN;
1105 adf_nbuf_map(sc->sc_dev, bf->bf_dmamap, skb, ADF_OS_DMA_TO_DEVICE);
1108 adf_nbuf_queue_add(&bf->bf_skbhead, skb);
1111 rt = sc->sc_currates;
1112 adf_os_assert(rt != NULL);
1114 if (mh->flags == ATH_SHORT_PREAMBLE)
1115 shortPreamble = AH_TRUE;
1117 shortPreamble = AH_FALSE;
1119 flags = HAL_TXDESC_CLRDMASK;
1121 switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
1122 case IEEE80211_FC0_TYPE_MGT:
1123 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
1125 if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP)
1126 atype = HAL_PKT_TYPE_PROBE_RESP;
1127 else if (subtype == IEEE80211_FC0_SUBTYPE_ATIM)
1128 atype = HAL_PKT_TYPE_ATIM;
1130 atype = HAL_PKT_TYPE_NORMAL;
1134 atype = HAL_PKT_TYPE_NORMAL;
1138 avp = &sc->sc_vap[mh->vap_index];
1140 rcs[0].rix = ath_get_minrateidx(sc, avp);
1141 rcs[0].tries = ATH_TXMAXTRY;
1144 adf_os_mem_copy(bf->bf_rcs, rcs, sizeof(rcs));
1146 try0 = rcs[0].tries;
1147 txrate = rt->info[rix].rateCode;
1150 txrate |= rt->info[rix].shortPreamble;
1157 flags |= HAL_TXDESC_NOACK;
1159 } else if (pktlen > vap->iv_rtsthreshold) {
1160 flags |= HAL_TXDESC_RTSENA;
1161 cix = rt->info[rix].controlRate;
1164 if ((bf->bf_protmode != IEEE80211_PROT_NONE) &&
1165 rt->info[rix].phy == IEEE80211_T_OFDM &&
1166 (flags & HAL_TXDESC_NOACK) == 0) {
1167 cix = rt->info[sc->sc_protrix].controlRate;
1168 sc->sc_tx_stats.ast_tx_protect++;
1171 *(a_uint16_t *)&wh->i_seq[0] = adf_os_cpu_to_le16(ni->ni_txseqmgmt <<
1172 IEEE80211_SEQ_SEQ_SHIFT);
1173 INCR(ni->ni_txseqmgmt, IEEE80211_SEQ_MAX);
1176 if (flags & (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)) {
1177 adf_os_assert(cix != 0xff);
1178 ctsrate = rt->info[cix].rateCode;
1179 if (shortPreamble) {
1180 ctsrate |= rt->info[cix].shortPreamble;
1181 if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */
1182 ctsduration += rt->info[cix].spAckDuration;
1183 if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */
1184 ctsduration += rt->info[cix].spAckDuration;
1186 if (flags & HAL_TXDESC_RTSENA) /* SIFS + CTS */
1187 ctsduration += rt->info[cix].lpAckDuration;
1188 if ((flags & HAL_TXDESC_NOACK) == 0) /* SIFS + ACK */
1189 ctsduration += rt->info[cix].lpAckDuration;
1191 ctsduration += ath_hal_computetxtime(ah,
1192 rt, pktlen, rix, shortPreamble);
1197 flags |= HAL_TXDESC_INTREQ;
1199 ath_hal_setuptxdesc(ah, ds
1212 , ATH_COMP_PROC_NO_COMP_NO_CCS);
1214 bf->bf_flags = flags;
1217 * Set key type in tx desc while sending the encrypted challenge to AP
1218 * in Auth frame 3 of Shared Authentication, owl needs this.
1220 if (iswep && (keyix != HAL_TXKEYIX_INVALID) &&
1221 (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_AUTH)
1222 ath_hal_fillkeytxdesc(ah, ds, mh->keytype);
1224 ath_filltxdesc(sc, bf);
1226 for (i=0; i<4; i++) {
1227 series[i].Tries = 2;
1228 series[i].Rate = txrate;
1229 series[i].ChSel = sc->sc_ic.ic_tx_chainmask;
1230 series[i].RateFlags = 0;
1232 ath_hal_set11n_ratescenario(ah, ds, 0, ctsrate, ctsduration, series, 4, 0);
1233 ath_tgt_txqaddbuf(sc, txq, bf, bf->bf_lastds);
1237 HTC_ReturnBuffers(sc->tgt_htc_handle, endpt, skb);
1242 ath_tgt_txqaddbuf(struct ath_softc_tgt *sc,
1243 struct ath_txq *txq, struct ath_tx_buf *bf,
1244 struct ath_tx_desc *lastds)
1246 struct ath_hal *ah = sc->sc_ah;
1248 ATH_TXQ_INSERT_TAIL(txq, bf, bf_list);
1250 if (txq->axq_link == NULL) {
1251 ath_hal_puttxbuf(ah, txq->axq_qnum, ATH_BUF_GET_DESC_PHY_ADDR(bf));
1253 *txq->axq_link = ATH_BUF_GET_DESC_PHY_ADDR(bf);
1256 txq->axq_link = &lastds->ds_link;
1257 ath_hal_txstart(ah, txq->axq_qnum);
1260 void ath_tgt_handle_normal(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1263 struct ath_node_target *an;
1265 an = (struct ath_node_target *)bf->bf_node;
1268 tid = &an->tid[bf->bf_tidno];
1271 bf->bf_comp = ath_tgt_tx_comp_normal;
1272 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
1273 ath_tgt_tx_send_normal(sc, bf);
1277 ath_tgt_tx_enqueue(struct ath_txq *txq, struct ath_atx_tid *tid)
1285 tid->sched = AH_TRUE;
1286 asf_tailq_insert_tail(&txq->axq_tidq, tid, tid_qelem);
1290 ath_tgt_txq_schedule(struct ath_softc_tgt *sc, struct ath_txq *txq)
1292 struct ath_atx_tid *tid;
1298 TAILQ_DEQ(&txq->axq_tidq, tid, tid_qelem);
1303 tid->sched = AH_FALSE;
1308 if (!(tid->flag & TID_AGGR_ENABLED))
1309 ath_tgt_tx_sched_normal(sc,tid);
1311 ath_tgt_tx_sched_aggr(sc,tid);
1315 if (!asf_tailq_empty(&tid->buf_q)) {
1316 ath_tgt_tx_enqueue(txq, tid);
1319 } while (!asf_tailq_empty(&txq->axq_tidq) && !bdone);
1323 ath_tgt_handle_aggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1326 struct ath_node_target *an;
1327 struct ath_txq *txq = bf->bf_txq;
1328 a_bool_t queue_frame, within_baw;
1330 an = (struct ath_node_target *)bf->bf_node;
1333 tid = &an->tid[bf->bf_tidno];
1336 bf->bf_comp = ath_tgt_tx_comp_aggr;
1338 within_baw = BAW_WITHIN(tid->seq_start, tid->baw_size,
1339 SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1341 queue_frame = ( (txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) ||
1342 (!asf_tailq_empty(&tid->buf_q)) ||
1343 (tid->paused) || (!within_baw) );
1346 asf_tailq_insert_tail(&tid->buf_q, bf, bf_list);
1347 ath_tgt_tx_enqueue(txq, tid);
1349 ath_tx_addto_baw(tid, bf);
1350 __stats(sc, txaggr_nframes);
1351 ath_tgt_tx_send_normal(sc, bf);
1356 ath_tgt_tx_sched_normal(struct ath_softc_tgt *sc, ath_atx_tid_t *tid)
1358 struct ath_tx_buf *bf;
1359 struct ath_txq *txq =TID_TO_ACTXQ(tid->tidno);;
1362 if (asf_tailq_empty(&tid->buf_q))
1365 bf = asf_tailq_first(&tid->buf_q);
1366 asf_tailq_remove(&tid->buf_q, bf, bf_list);
1367 ath_tgt_tx_send_normal(sc, bf);
1369 } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH);
1373 ath_tgt_tx_sched_aggr(struct ath_softc_tgt *sc, ath_atx_tid_t *tid)
1375 struct ath_tx_buf *bf, *bf_last;
1376 ATH_AGGR_STATUS status;
1377 ath_tx_bufhead bf_q;
1378 struct ath_txq *txq = TID_TO_ACTXQ(tid->tidno);
1379 struct ath_tx_desc *ds = NULL;
1383 if (asf_tailq_empty(&tid->buf_q))
1387 if (asf_tailq_empty(&tid->buf_q))
1390 asf_tailq_init(&bf_q);
1392 status = ath_tgt_tx_form_aggr(sc, tid, &bf_q);
1394 if (asf_tailq_empty(&bf_q))
1397 bf = asf_tailq_first(&bf_q);
1398 bf_last = asf_tailq_last(&bf_q, ath_tx_bufhead_s);
1400 if (bf->bf_nframes == 1) {
1402 if(bf->bf_retries == 0)
1403 __stats(sc, txaggr_single);
1405 bf->bf_lastds = &(bf->bf_descarr[bf->bf_dmamap_info.nsegs -1]);
1406 bf->bf_lastds->ds_link = 0;
1409 for(ds = bf->bf_desc; ds <= bf->bf_lastds; ds++)
1410 ath_hal_clr11n_aggr(sc->sc_ah, ds);
1412 ath_buf_set_rate(sc, bf);
1413 bf->bf_txq_add(sc, bf);
1418 bf_last->bf_next = NULL;
1419 bf_last->bf_lastds->ds_link = 0;
1420 bf_last->bf_ndelim = 0;
1423 ath_buf_set_rate(sc, bf);
1424 ath_hal_set11n_aggr_first(sc->sc_ah, bf->bf_desc, bf->bf_al,
1426 bf->bf_lastds = bf_last->bf_lastds;
1428 for (i = 0; i < bf_last->bf_dmamap_info.nsegs; i++)
1429 ath_hal_set11n_aggr_last(sc->sc_ah, &bf_last->bf_descarr[i]);
1431 if (status == ATH_AGGR_8K_LIMITED) {
1436 bf->bf_txq_add(sc, bf);
1437 } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH &&
1438 status != ATH_TGT_AGGR_BAW_CLOSED);
1441 static u_int32_t ath_lookup_rate(struct ath_softc_tgt *sc,
1442 struct ath_node_target *an,
1443 struct ath_tx_buf *bf)
1446 u_int32_t max4msframelen, frame_length;
1447 u_int16_t aggr_limit, legacy=0;
1448 const HAL_RATE_TABLE *rt = sc->sc_currates;
1449 struct ieee80211_node_target *ieee_node = (struct ieee80211_node_target *)an;
1451 if (bf->bf_ismcast) {
1452 bf->bf_rcs[1].tries = bf->bf_rcs[2].tries = bf->bf_rcs[3].tries = 0;
1453 bf->bf_rcs[0].rix = 0xb;
1454 bf->bf_rcs[0].tries = ATH_TXMAXTRY - 1;
1455 bf->bf_rcs[0].flags = 0;
1457 ath_tgt_rate_findrate(sc, an, AH_TRUE, 0, ATH_TXMAXTRY-1, 4, 1,
1458 ATH_RC_PROBE_ALLOWED, bf->bf_rcs, &prate);
1461 max4msframelen = IEEE80211_AMPDU_LIMIT_MAX;
1463 for (i = 0; i < 4; i++) {
1464 if (bf->bf_rcs[i].tries) {
1465 frame_length = bf->bf_rcs[i].max4msframelen;
1467 if (rt->info[bf->bf_rcs[i].rix].phy != IEEE80211_T_HT) {
1472 max4msframelen = ATH_MIN(max4msframelen, frame_length);
1476 if (prate || legacy)
1479 if (sc->sc_ic.ic_enable_coex)
1480 aggr_limit = ATH_MIN((max4msframelen*3)/8, sc->sc_ic.ic_ampdu_limit);
1482 aggr_limit = ATH_MIN(max4msframelen, sc->sc_ic.ic_ampdu_limit);
1484 if (ieee_node->ni_maxampdu)
1485 aggr_limit = ATH_MIN(aggr_limit, ieee_node->ni_maxampdu);
1490 int ath_tgt_tx_form_aggr(struct ath_softc_tgt *sc, ath_atx_tid_t *tid,
1491 ath_tx_bufhead *bf_q)
1493 struct ath_tx_buf *bf_first ,*bf_prev = NULL;
1494 int nframes = 0, rl = 0;;
1495 struct ath_tx_desc *ds = NULL;
1496 struct ath_tx_buf *bf;
1497 u_int16_t aggr_limit = (64*1024 -1), al = 0, bpad = 0, al_delta;
1498 u_int16_t h_baw = tid->baw_size/2, prev_al = 0, prev_frames = 0;
1500 bf_first = asf_tailq_first(&tid->buf_q);
1503 bf = asf_tailq_first(&tid->buf_q);
1506 if (!BAW_WITHIN(tid->seq_start, tid->baw_size,
1507 SEQNO_FROM_BF_SEQNO(bf->bf_seqno))) {
1509 bf_first->bf_al= al;
1510 bf_first->bf_nframes = nframes;
1511 return ATH_TGT_AGGR_BAW_CLOSED;
1515 aggr_limit = ath_lookup_rate(sc, tid->an, bf);
1519 al_delta = ATH_AGGR_DELIM_SZ + bf->bf_pktlen;
1521 if (nframes && (aggr_limit < (al + bpad + al_delta + prev_al))) {
1522 bf_first->bf_al= al;
1523 bf_first->bf_nframes = nframes;
1524 return ATH_TGT_AGGR_LIMITED;
1528 if ((nframes + prev_frames) >= ATH_MIN((h_baw), 17)) {
1530 if ((nframes + prev_frames) >= ATH_MIN((h_baw), 22)) {
1532 bf_first->bf_al= al;
1533 bf_first->bf_nframes = nframes;
1534 return ATH_TGT_AGGR_LIMITED;
1537 ath_tx_addto_baw(tid, bf);
1538 asf_tailq_remove(&tid->buf_q, bf, bf_list);
1539 asf_tailq_insert_tail(bf_q, bf, bf_list);
1544 adf_os_assert(bf->bf_comp == ath_tgt_tx_comp_aggr);
1546 al += bpad + al_delta;
1547 bf->bf_ndelim = ATH_AGGR_GET_NDELIM(bf->bf_pktlen);
1549 switch (bf->bf_keytype) {
1550 case HAL_KEY_TYPE_AES:
1551 bf->bf_ndelim += ATH_AGGR_ENCRYPTDELIM;
1553 case HAL_KEY_TYPE_WEP:
1554 case HAL_KEY_TYPE_TKIP:
1555 bf->bf_ndelim += 64;
1557 case HAL_KEY_TYPE_WAPI:
1558 bf->bf_ndelim += 12;
1564 bpad = PADBYTES(al_delta) + (bf->bf_ndelim << 2);
1567 bf_prev->bf_next = bf;
1568 bf_prev->bf_lastds->ds_link = ATH_BUF_GET_DESC_PHY_ADDR(bf);
1572 for(ds = bf->bf_desc; ds <= bf->bf_lastds; ds++)
1573 ath_hal_set11n_aggr_middle(sc->sc_ah, ds, bf->bf_ndelim);
1575 } while (!asf_tailq_empty(&tid->buf_q));
1577 bf_first->bf_al= al;
1578 bf_first->bf_nframes = nframes;
1580 return ATH_TGT_AGGR_DONE;
1583 void ath_tx_addto_baw(ath_atx_tid_t *tid, struct ath_tx_buf *bf)
1587 if (bf->bf_isretried) {
1591 index = ATH_BA_INDEX(tid->seq_start, SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1592 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
1594 TX_BUF_BITMAP_SET(tid->tx_buf_bitmap, cindex);
1596 if (index >= ((tid->baw_tail - tid->baw_head) & (ATH_TID_MAX_BUFS - 1))) {
1597 tid->baw_tail = cindex;
1598 INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
1602 void ath_tgt_tx_comp_aggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1604 struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
1605 ath_atx_tid_t *tid = ATH_AN_2_TID(an, bf->bf_tidno);
1606 struct ath_tx_desc lastds;
1607 struct ath_tx_desc *ds = &lastds;
1608 struct ath_rc_series rcs[4];
1613 int nframes = bf->bf_nframes;
1614 struct ath_tx_buf *bf_next;
1615 ath_tx_bufhead bf_q;
1617 struct ath_tx_buf *bar = NULL;
1618 struct ath_txq *txq;
1622 if (tid->flag & TID_CLEANUP_INPROGRES) {
1623 ath_tx_comp_cleanup(sc, bf);
1627 adf_os_mem_copy(ds, bf->bf_lastds, sizeof (struct ath_tx_desc));
1628 adf_os_mem_copy(rcs, bf->bf_rcs, sizeof(rcs));
1630 if (ds->ds_txstat.ts_flags == HAL_TX_SW_FILTERED) {
1635 if (!bf->bf_isaggr) {
1636 ath_tx_comp_unaggr(sc, bf);
1640 __stats(sc, tx_compaggr);
1642 asf_tailq_init(&bf_q);
1644 seq_st = ATH_DS_BA_SEQ(ds);
1645 ba = ATH_DS_BA_BITMAP(ds);
1646 tx_ok = (ATH_DS_TX_STATUS(ds) == HAL_OK);
1648 if (ATH_DS_TX_STATUS(ds) & HAL_TXERR_XRETRY) {
1649 ath_tx_comp_aggr_error(sc, bf, tid);
1653 if (tx_ok && !ATH_DS_TX_BA(ds)) {
1654 __stats(sc, txaggr_babug);
1655 adf_os_print("BA Bug?\n");
1656 ath_tx_comp_aggr_error(sc, bf, tid);
1661 ba_index = ATH_BA_INDEX(seq_st, SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1662 bf_next = bf->bf_next;
1664 if (tx_ok && ATH_BA_ISSET(ba, ba_index)) {
1665 __stats(sc, txaggr_compgood);
1666 ath_tx_update_baw(tid, SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1667 ath_tx_status_update_aggr(sc, bf, ds, rcs, 1);
1668 ath_tx_freebuf(sc, bf);
1670 ath_tx_retry_subframe(sc, bf, &bf_q, &bar);
1676 ath_update_aggr_stats(sc, ds, nframes, nbad);
1677 ath_rate_tx_complete(sc, an, ds, rcs, nframes, nbad);
1680 ath_bar_tx(sc, tid, bar);
1683 if (!asf_tailq_empty(&bf_q)) {
1684 __stats(sc, txaggr_prepends);
1685 TAILQ_INSERTQ_HEAD(&tid->buf_q, &bf_q, bf_list);
1686 ath_tgt_tx_enqueue(txq, tid);
1691 ath_tx_comp_aggr_error(struct ath_softc_tgt *sc, struct ath_tx_buf *bf,
1696 struct ath_tx_desc lastds;
1697 struct ath_tx_desc *ds = &lastds;
1698 struct ath_rc_series rcs[4];
1699 struct ath_tx_buf *bar = NULL;
1700 struct ath_tx_buf *bf_next;
1701 int nframes = bf->bf_nframes;
1702 ath_tx_bufhead bf_q;
1703 struct ath_txq *txq;
1705 asf_tailq_init(&bf_q);
1708 adf_os_mem_copy(ds, bf->bf_lastds, sizeof (struct ath_tx_desc));
1709 adf_os_mem_copy(rcs, bf->bf_rcs, sizeof(rcs));
1712 bf_next = bf->bf_next;
1713 ath_tx_retry_subframe(sc, bf, &bf_q, &bar);
1717 ath_update_aggr_stats(sc, ds, nframes, nframes);
1718 ath_rate_tx_complete(sc, tid->an, ds, rcs, nframes, nframes);
1721 ath_bar_tx(sc, tid, bar);
1724 if (!asf_tailq_empty(&bf_q)) {
1725 __stats(sc, txaggr_prepends);
1726 TAILQ_INSERTQ_HEAD(&tid->buf_q, &bf_q, bf_list);
1727 ath_tgt_tx_enqueue(txq, tid);
1732 ath_tx_comp_cleanup(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1735 struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
1736 ath_atx_tid_t *tid = ATH_AN_2_TID(an, bf->bf_tidno);
1737 struct ath_tx_desc lastds;
1738 struct ath_tx_desc *ds = &lastds;
1739 struct ath_rc_series rcs[4];
1744 int nframes = bf->bf_nframes;
1745 struct ath_tx_buf *bf_next;
1748 adf_os_mem_copy(ds, bf->bf_lastds, sizeof (struct ath_tx_desc));
1749 adf_os_mem_copy(rcs, bf->bf_rcs, sizeof(rcs));
1751 seq_st = ATH_DS_BA_SEQ(ds);
1752 ba = ATH_DS_BA_BITMAP(ds);
1753 tx_ok = (ATH_DS_TX_STATUS(ds) == HAL_OK);
1755 if (!bf->bf_isaggr) {
1756 ath_update_stats(sc, bf);
1758 __stats(sc, tx_compunaggr);
1760 ath_tx_status_update(sc, bf);
1762 ath_tx_freebuf(sc, bf);
1764 if (tid->flag & TID_CLEANUP_INPROGRES) {
1765 owl_tgt_tid_cleanup(sc, tid);
1773 ba_index = ATH_BA_INDEX(seq_st, SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1774 bf_next = bf->bf_next;
1776 ath_tx_status_update_aggr(sc, bf, ds, rcs, 0);
1778 ath_tx_freebuf(sc, bf);
1782 tid->flag &= ~TID_CLEANUP_INPROGRES;
1783 ath_aggr_resume_tid(sc, tid);
1790 ath_update_aggr_stats(sc, ds, nframes, nbad);
1791 ath_rate_tx_complete(sc, an, ds, rcs, nframes, nbad);
1795 ath_tx_retry_subframe(struct ath_softc_tgt *sc, struct ath_tx_buf *bf,
1796 ath_tx_bufhead *bf_q, struct ath_tx_buf **bar)
1799 struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
1800 ath_atx_tid_t *tid = ATH_AN_2_TID(an, bf->bf_tidno);
1801 struct ath_tx_desc *ds = NULL;
1804 __stats(sc, txaggr_compretries);
1806 for(ds = bf->bf_desc, i = 0; i < bf->bf_dmamap_info.nsegs; ds++, i++) {
1807 ath_hal_clr11n_aggr(sc->sc_ah, ds);
1808 ath_hal_set11n_burstduration(sc->sc_ah, ds, 0);
1809 ath_hal_set11n_virtualmorefrag(sc->sc_ah, ds, 0);
1812 if (bf->bf_retries >= OWLMAX_RETRIES) {
1813 __stats(sc, txaggr_xretries);
1814 ath_tx_update_baw(tid, SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1815 ath_tx_status_update_aggr(sc, bf, bf->bf_lastds, NULL, 0);
1820 ath_tx_freebuf(sc, bf);
1825 __stats(sc, txaggr_errlast);
1826 bf = ath_buf_toggle(sc, bf, 1);
1828 bf->bf_lastds = &(bf->bf_descarr[bf->bf_dmamap_info.nsegs - 1]);
1830 ath_tx_set_retry(sc, bf);
1831 asf_tailq_insert_tail(bf_q, bf, bf_list);
1835 ath_update_aggr_stats(struct ath_softc_tgt *sc,
1836 struct ath_tx_desc *ds, int nframes,
1840 u_int8_t status = ATH_DS_TX_STATUS(ds);
1841 u_int8_t txflags = ATH_DS_TX_FLAGS(ds);
1843 __statsn(sc, txaggr_longretries, ds->ds_txstat.ts_longretry);
1844 __statsn(sc, txaggr_shortretries, ds->ds_txstat.ts_shortretry);
1846 if (txflags & HAL_TX_DESC_CFG_ERR)
1847 __stats(sc, txaggr_desc_cfgerr);
1849 if (txflags & HAL_TX_DATA_UNDERRUN)
1850 __stats(sc, txaggr_data_urun);
1852 if (txflags & HAL_TX_DELIM_UNDERRUN)
1853 __stats(sc, txaggr_delim_urun);
1859 if (status & HAL_TXERR_XRETRY)
1860 __stats(sc, txaggr_compxretry);
1862 if (status & HAL_TXERR_FILT)
1863 __stats(sc, txaggr_filtered);
1865 if (status & HAL_TXERR_FIFO)
1866 __stats(sc, txaggr_fifo);
1868 if (status & HAL_TXERR_XTXOP)
1869 __stats(sc, txaggr_xtxop);
1871 if (status & HAL_TXERR_TIMER_EXPIRED)
1872 __stats(sc, txaggr_timer_exp);
1876 ath_tx_comp_unaggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1878 struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
1879 ath_atx_tid_t *tid = ATH_AN_2_TID(an, bf->bf_tidno);
1880 struct ath_tx_desc *ds = bf->bf_lastds;
1882 ath_update_stats(sc, bf);
1883 ath_rate_tx_complete(sc, an, ds, bf->bf_rcs, 1, 0);
1885 if (ATH_DS_TX_STATUS(ds) & HAL_TXERR_XRETRY) {
1886 ath_tx_retry_unaggr(sc, bf);
1889 __stats(sc, tx_compunaggr);
1891 ath_tx_update_baw(tid, SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1892 ath_tx_status_update(sc, bf);
1893 ath_tx_freebuf(sc, bf);
1897 ath_tx_retry_unaggr(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1899 struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
1900 ath_atx_tid_t *tid = ATH_AN_2_TID(an, bf->bf_tidno);
1901 struct ath_txq *txq;
1905 if (bf->bf_retries >= OWLMAX_RETRIES) {
1906 __stats(sc, txunaggr_xretry);
1907 ath_tx_update_baw(tid, SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1908 ath_tx_status_update(sc, bf);
1909 ath_bar_tx(sc, tid, bf);
1913 __stats(sc, txunaggr_compretries);
1914 if (!bf->bf_lastds->ds_link) {
1915 __stats(sc, txunaggr_errlast);
1916 bf = ath_buf_toggle(sc, bf, 1);
1919 ath_tx_set_retry(sc, bf);
1920 asf_tailq_insert_head(&tid->buf_q, bf, bf_list);
1921 ath_tgt_tx_enqueue(txq, tid);
1925 ath_tx_update_baw(ath_atx_tid_t *tid, int seqno)
1930 index = ATH_BA_INDEX(tid->seq_start, seqno);
1931 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
1933 TX_BUF_BITMAP_CLR(tid->tx_buf_bitmap, cindex);
1935 while (tid->baw_head != tid->baw_tail &&
1936 (!TX_BUF_BITMAP_IS_SET(tid->tx_buf_bitmap, tid->baw_head))) {
1937 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
1938 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
1942 static void ath_tx_set_retry(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
1944 struct ieee80211_frame *wh;
1946 __stats(sc, txaggr_retries);
1948 bf->bf_isretried = 1;
1950 wh = ATH_SKB_2_WH(bf->bf_skb);
1951 wh->i_fc[1] |= IEEE80211_FC1_RETRY;
1954 void ath_tgt_tx_cleanup(struct ath_softc_tgt *sc, struct ath_node_target *an,
1955 ath_atx_tid_t *tid, a_uint8_t discard_all)
1957 struct ath_tx_buf *bf;
1958 struct ath_tx_buf *bf_next;
1959 struct ath_txq *txq;
1961 txq = TID_TO_ACTXQ(tid->tidno);
1963 bf = asf_tailq_first(&tid->buf_q);
1966 if (discard_all || bf->bf_isretried) {
1967 bf_next = asf_tailq_next(bf, bf_list);
1968 TAILQ_DEQ(&tid->buf_q, bf, bf_list);
1969 if (bf->bf_isretried)
1970 ath_tx_update_baw(tid, SEQNO_FROM_BF_SEQNO(bf->bf_seqno));
1971 ath_tx_freebuf(sc, bf);
1975 bf->bf_comp = ath_tgt_tx_comp_normal;
1976 bf = asf_tailq_next(bf, bf_list);
1979 ath_aggr_pause_tid(sc, tid);
1981 while (tid->baw_head != tid->baw_tail) {
1982 if (TX_BUF_BITMAP_IS_SET(tid->tx_buf_bitmap, tid->baw_head)) {
1984 tid->flag |= TID_CLEANUP_INPROGRES;
1985 TX_BUF_BITMAP_CLR(tid->tx_buf_bitmap, tid->baw_head);
1987 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
1988 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
1991 if (!(tid->flag & TID_CLEANUP_INPROGRES)) {
1992 ath_aggr_resume_tid(sc, tid);
1996 /******************/
1997 /* BAR Management */
1998 /******************/
2000 static void ath_tgt_delba_send(struct ath_softc_tgt *sc,
2001 struct ieee80211_node_target *ni,
2002 a_uint8_t tidno, a_uint8_t initiator,
2003 a_uint16_t reasoncode)
2005 struct ath_node_target *an = ATH_NODE_TARGET(ni);
2006 ath_atx_tid_t *tid = ATH_AN_2_TID(an, tidno);
2007 struct wmi_data_delba wmi_delba;
2009 tid->flag &= ~TID_AGGR_ENABLED;
2011 ath_tgt_tx_cleanup(sc, an, tid, 1);
2013 wmi_delba.ni_nodeindex = ni->ni_nodeindex;
2014 wmi_delba.tidno = tid->tidno;
2015 wmi_delba.initiator = 1;
2016 wmi_delba.reasoncode = IEEE80211_REASON_UNSPECIFIED;
2018 __stats(sc, txbar_xretry);
2019 wmi_event(sc->tgt_wmi_handle,
2025 static void ath_bar_retry(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
2027 struct ath_node_target *an = ATH_NODE_TARGET(bf->bf_node);
2028 ath_atx_tid_t *tid = ATH_AN_2_TID(an, bf->bf_tidno);
2030 if (bf->bf_retries >= OWLMAX_BAR_RETRIES) {
2031 ath_tgt_delba_send(sc, bf->bf_node, tid->tidno, 1,
2032 IEEE80211_REASON_UNSPECIFIED);
2033 ath_tgt_tid_drain(sc, tid);
2036 ath_buf_comp(sc, bf);
2040 __stats(sc, txbar_compretries);
2042 if (!bf->bf_lastds->ds_link) {
2043 __stats(sc, txbar_errlast);
2044 bf = ath_buf_toggle(sc, bf, 1);
2047 bf->bf_lastds->ds_link = 0;
2049 ath_tx_set_retry(sc, bf);
2050 ath_tgt_txq_add_ucast(sc, bf);
2053 static void ath_bar_tx_comp(struct ath_softc_tgt *sc, struct ath_tx_buf *bf)
2055 struct ath_tx_desc *ds = bf->bf_lastds;
2056 struct ath_node_target *an;
2058 struct ath_txq *txq;
2060 an = (struct ath_node_target *)bf->bf_node;
2061 tid = &an->tid[bf->bf_tidno];
2062 txq = TID_TO_ACTXQ(tid->tidno);
2064 if (ATH_DS_TX_STATUS(ds) & HAL_TXERR_XRETRY) {
2065 ath_bar_retry(sc, bf);
2069 ath_aggr_resume_tid(sc, tid);
2072 ath_buf_comp(sc, bf);
2075 static void ath_bar_tx(struct ath_softc_tgt *sc,
2076 ath_atx_tid_t *tid, struct ath_tx_buf *bf)
2079 struct ieee80211_frame_bar *bar;
2081 struct ath_tx_desc *ds, *ds0;
2082 HAL_11N_RATE_SERIES series[4];
2084 adf_nbuf_queue_t skbhead;
2088 __stats(sc, tx_bars);
2090 adf_os_mem_set(&series, 0, sizeof(series));
2092 ath_aggr_pause_tid(sc, tid);
2094 skb = adf_nbuf_queue_remove(&bf->bf_skbhead);
2095 adf_nbuf_peek_header(skb, &anbdata, &anblen);
2096 adf_nbuf_trim_tail(skb, anblen);
2097 bar = (struct ieee80211_frame_bar *) anbdata;
2101 ath_dma_unmap(sc, bf);
2102 adf_nbuf_queue_add(&bf->bf_skbhead, skb);
2104 bar->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2105 bar->i_fc[0] = IEEE80211_FC0_VERSION_0 |
2106 IEEE80211_FC0_TYPE_CTL |
2107 IEEE80211_FC0_SUBTYPE_BAR;
2108 bar->i_ctl = tid->tidno << IEEE80211_BAR_CTL_TID_S |
2109 IEEE80211_BAR_CTL_COMBA;
2110 bar->i_seq = adf_os_cpu_to_le16(tid->seq_start << IEEE80211_SEQ_SEQ_SHIFT);
2112 bf->bf_seqno = tid->seq_start << IEEE80211_SEQ_SEQ_SHIFT;
2114 adf_nbuf_put_tail(skb, sizeof(struct ieee80211_frame_bar));
2116 bf->bf_comp = ath_bar_tx_comp;
2117 bf->bf_tidno = tid->tidno;
2118 bf->bf_node = &tid->an->ni;
2119 ath_dma_map(sc, bf);
2120 adf_nbuf_dmamap_info(bf->bf_dmamap, &bf->bf_dmamap_info);
2123 ath_hal_setuptxdesc(sc->sc_ah, ds
2124 , adf_nbuf_len(skb) + IEEE80211_CRC_LEN
2126 , HAL_PKT_TYPE_NORMAL
2133 | HAL_TXDESC_CLRDMASK
2135 , ATH_COMP_PROC_NO_COMP_NO_CCS);
2137 skbhead = bf->bf_skbhead;
2141 for (ds0 = ds, i=0; i < bf->bf_dmamap_info.nsegs; ds0++, i++) {
2142 ath_hal_clr11n_aggr(sc->sc_ah, ds0);
2145 ath_filltxdesc(sc, bf);
2147 for (i = 0 ; i < 4; i++) {
2148 series[i].Tries = ATH_TXMAXTRY;
2149 series[i].Rate = min_rate;
2150 series[i].ChSel = sc->sc_ic.ic_tx_chainmask;
2153 ath_hal_set11n_ratescenario(sc->sc_ah, bf->bf_desc, 0, 0, 0, series, 4, 4);
2154 ath_tgt_txq_add_ucast(sc, bf);