2 * Copyright (c) 2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * Implementation of transmit path.
23 #define BITS_PER_BYTE 8
24 #define OFDM_PLCP_BITS 22
25 #define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)
26 #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
32 #define HT_LTF(_ns) (4 * (_ns))
33 #define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */
34 #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */
35 #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
36 #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
38 #define OFDM_SIFS_TIME 16
40 static u_int32_t bits_per_symbol
[][2] = {
42 { 26, 54 }, /* 0: BPSK */
43 { 52, 108 }, /* 1: QPSK 1/2 */
44 { 78, 162 }, /* 2: QPSK 3/4 */
45 { 104, 216 }, /* 3: 16-QAM 1/2 */
46 { 156, 324 }, /* 4: 16-QAM 3/4 */
47 { 208, 432 }, /* 5: 64-QAM 2/3 */
48 { 234, 486 }, /* 6: 64-QAM 3/4 */
49 { 260, 540 }, /* 7: 64-QAM 5/6 */
50 { 52, 108 }, /* 8: BPSK */
51 { 104, 216 }, /* 9: QPSK 1/2 */
52 { 156, 324 }, /* 10: QPSK 3/4 */
53 { 208, 432 }, /* 11: 16-QAM 1/2 */
54 { 312, 648 }, /* 12: 16-QAM 3/4 */
55 { 416, 864 }, /* 13: 64-QAM 2/3 */
56 { 468, 972 }, /* 14: 64-QAM 3/4 */
57 { 520, 1080 }, /* 15: 64-QAM 5/6 */
60 #define IS_HT_RATE(_rate) ((_rate) & 0x80)
63 * Insert a chain of ath_buf (descriptors) on a multicast txq
64 * but do NOT start tx DMA on this queue.
65 * NB: must be called with txq lock held
68 static void ath_tx_mcastqaddbuf(struct ath_softc
*sc
,
70 struct list_head
*head
)
72 struct ath_hal
*ah
= sc
->sc_ah
;
79 * Insert the frame on the outbound list and
80 * pass it on to the hardware.
82 bf
= list_first_entry(head
, struct ath_buf
, list
);
85 * The CAB queue is started from the SWBA handler since
86 * frames only go out on DTIM and to avoid possible races.
88 ath9k_hw_set_interrupts(ah
, 0);
91 * If there is anything in the mcastq, we want to set
92 * the "more data" bit in the last item in the queue to
93 * indicate that there is "more data". It makes sense to add
94 * it here since you are *always* going to have
95 * more data when adding to this queue, no matter where
101 struct ieee80211_hdr
*hdr
;
104 * Add the "more data flag" to the last frame
107 lbf
= list_entry(txq
->axq_q
.prev
, struct ath_buf
, list
);
108 hdr
= (struct ieee80211_hdr
*)
109 ((struct sk_buff
*)(lbf
->bf_mpdu
))->data
;
110 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
114 * Now, concat the frame onto the queue
116 list_splice_tail_init(head
, &txq
->axq_q
);
118 txq
->axq_totalqueued
++;
119 txq
->axq_linkbuf
= list_entry(txq
->axq_q
.prev
, struct ath_buf
, list
);
121 DPRINTF(sc
, ATH_DEBUG_TX_PROC
,
122 "%s: txq depth = %d\n", __func__
, txq
->axq_depth
);
123 if (txq
->axq_link
!= NULL
) {
124 *txq
->axq_link
= cpu_to_le32(bf
->bf_daddr
);
125 DPRINTF(sc
, ATH_DEBUG_XMIT
,
126 "%s: link[%u](%p)=%llx (%p)\n",
128 txq
->axq_qnum
, txq
->axq_link
,
129 ito64(bf
->bf_daddr
), bf
->bf_desc
);
131 txq
->axq_link
= &(bf
->bf_lastbf
->bf_desc
->ds_link
);
132 ath9k_hw_set_interrupts(ah
, sc
->sc_imask
);
136 * Insert a chain of ath_buf (descriptors) on a txq and
137 * assume the descriptors are already chained together by caller.
138 * NB: must be called with txq lock held
141 static void ath_tx_txqaddbuf(struct ath_softc
*sc
,
142 struct ath_txq
*txq
, struct list_head
*head
)
144 struct ath_hal
*ah
= sc
->sc_ah
;
147 * Insert the frame on the outbound list and
148 * pass it on to the hardware.
151 if (list_empty(head
))
154 bf
= list_first_entry(head
, struct ath_buf
, list
);
156 list_splice_tail_init(head
, &txq
->axq_q
);
158 txq
->axq_totalqueued
++;
159 txq
->axq_linkbuf
= list_entry(txq
->axq_q
.prev
, struct ath_buf
, list
);
161 DPRINTF(sc
, ATH_DEBUG_TX_PROC
,
162 "%s: txq depth = %d\n", __func__
, txq
->axq_depth
);
164 if (txq
->axq_link
== NULL
) {
165 ath9k_hw_puttxbuf(ah
, txq
->axq_qnum
, bf
->bf_daddr
);
166 DPRINTF(sc
, ATH_DEBUG_XMIT
,
167 "%s: TXDP[%u] = %llx (%p)\n",
168 __func__
, txq
->axq_qnum
,
169 ito64(bf
->bf_daddr
), bf
->bf_desc
);
171 *txq
->axq_link
= cpu_to_le32(bf
->bf_daddr
);
172 DPRINTF(sc
, ATH_DEBUG_XMIT
, "%s: link[%u] (%p)=%llx (%p)\n",
174 txq
->axq_qnum
, txq
->axq_link
,
175 ito64(bf
->bf_daddr
), bf
->bf_desc
);
177 txq
->axq_link
= &(bf
->bf_lastbf
->bf_desc
->ds_link
);
178 ath9k_hw_txstart(ah
, txq
->axq_qnum
);
181 /* Get transmit rate index using rate in Kbps */
183 static int ath_tx_findindex(const struct hal_rate_table
*rt
, int rate
)
188 for (i
= 0; i
< rt
->rateCount
; i
++) {
189 if (rt
->info
[i
].rateKbps
== rate
) {
198 /* Check if it's okay to send out aggregates */
200 static int ath_aggr_query(struct ath_softc
*sc
,
201 struct ath_node
*an
, u_int8_t tidno
)
203 struct ath_atx_tid
*tid
;
204 tid
= ATH_AN_2_TID(an
, tidno
);
206 if (tid
->addba_exchangecomplete
|| tid
->addba_exchangeinprogress
)
212 static enum hal_pkt_type
get_hal_packet_type(struct ieee80211_hdr
*hdr
)
214 enum hal_pkt_type htype
;
217 fc
= hdr
->frame_control
;
219 /* Calculate Atheros packet type from IEEE80211 packet header */
221 if (ieee80211_is_beacon(fc
))
222 htype
= HAL_PKT_TYPE_BEACON
;
223 else if (ieee80211_is_probe_resp(fc
))
224 htype
= HAL_PKT_TYPE_PROBE_RESP
;
225 else if (ieee80211_is_atim(fc
))
226 htype
= HAL_PKT_TYPE_ATIM
;
227 else if (ieee80211_is_pspoll(fc
))
228 htype
= HAL_PKT_TYPE_PSPOLL
;
230 htype
= HAL_PKT_TYPE_NORMAL
;
235 static void fill_min_rates(struct sk_buff
*skb
, struct ath_tx_control
*txctl
)
237 struct ieee80211_hdr
*hdr
;
238 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
239 struct ath_tx_info_priv
*tx_info_priv
;
242 hdr
= (struct ieee80211_hdr
*)skb
->data
;
243 fc
= hdr
->frame_control
;
244 tx_info_priv
= (struct ath_tx_info_priv
*)tx_info
->driver_data
[0];
246 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
)) {
247 txctl
->use_minrate
= 1;
248 txctl
->min_rate
= tx_info_priv
->min_rate
;
249 } else if (ieee80211_is_data(fc
)) {
250 if (ieee80211_is_nullfunc(fc
) ||
251 (tx_info
->flags
& IEEE80211_TX_CTL_EAPOL_FRAME
)) {
252 txctl
->use_minrate
= 1;
253 txctl
->min_rate
= tx_info_priv
->min_rate
;
255 if (is_multicast_ether_addr(hdr
->addr1
))
256 txctl
->mcast_rate
= tx_info_priv
->min_rate
;
261 /* This function will setup additional txctl information, mostly rate stuff */
262 /* FIXME: seqno, ps */
263 static int ath_tx_prepare(struct ath_softc
*sc
,
265 struct ath_tx_control
*txctl
)
267 struct ieee80211_hw
*hw
= sc
->hw
;
268 struct ieee80211_hdr
*hdr
;
269 struct ath_rc_series
*rcs
;
270 struct ath_txq
*txq
= NULL
;
271 const struct hal_rate_table
*rt
;
272 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
273 struct ath_tx_info_priv
*tx_info_priv
;
275 u_int8_t rix
, antenna
;
279 memset(txctl
, 0, sizeof(struct ath_tx_control
));
282 hdr
= (struct ieee80211_hdr
*)skb
->data
;
283 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
284 fc
= hdr
->frame_control
;
286 rt
= sc
->sc_currates
;
287 KASSERT(rt
!= NULL
, ("no rate table, mode %u", sc
->sc_curmode
));
289 /* Fill misc fields */
291 spin_lock_bh(&sc
->node_lock
);
292 txctl
->an
= ath_node_get(sc
, hdr
->addr1
);
293 /* create a temp node, if the node is not there already */
295 txctl
->an
= ath_node_attach(sc
, hdr
->addr1
, 0);
296 spin_unlock_bh(&sc
->node_lock
);
298 if (ieee80211_is_data_qos(fc
)) {
299 qc
= ieee80211_get_qos_ctl(hdr
);
300 txctl
->tidno
= qc
[0] & 0xf;
304 txctl
->nextfraglen
= 0;
305 txctl
->frmlen
= skb
->len
+ FCS_LEN
- (hdrlen
& 3);
306 txctl
->txpower
= MAX_RATE_POWER
; /* FIXME */
308 /* Fill Key related fields */
310 txctl
->keytype
= HAL_KEY_TYPE_CLEAR
;
311 txctl
->keyix
= HAL_TXKEYIX_INVALID
;
313 if (!(tx_info
->flags
& IEEE80211_TX_CTL_DO_NOT_ENCRYPT
)) {
314 txctl
->keyix
= tx_info
->control
.hw_key
->hw_key_idx
;
315 txctl
->frmlen
+= tx_info
->control
.icv_len
;
317 if (sc
->sc_keytype
== HAL_CIPHER_WEP
)
318 txctl
->keytype
= HAL_KEY_TYPE_WEP
;
319 else if (sc
->sc_keytype
== HAL_CIPHER_TKIP
)
320 txctl
->keytype
= HAL_KEY_TYPE_TKIP
;
321 else if (sc
->sc_keytype
== HAL_CIPHER_AES_CCM
)
322 txctl
->keytype
= HAL_KEY_TYPE_AES
;
325 /* Fill packet type */
327 txctl
->atype
= get_hal_packet_type(hdr
);
331 txctl
->qnum
= ath_get_hal_qnum(skb_get_queue_mapping(skb
), sc
);
332 txq
= &sc
->sc_txq
[txctl
->qnum
];
333 spin_lock_bh(&txq
->axq_lock
);
335 /* Try to avoid running out of descriptors */
336 if (txq
->axq_depth
>= (ATH_TXBUF
- 20)) {
337 DPRINTF(sc
, ATH_DEBUG_FATAL
,
338 "%s: TX queue: %d is full, depth: %d\n",
342 ieee80211_stop_queue(hw
, skb_get_queue_mapping(skb
));
344 spin_unlock_bh(&txq
->axq_lock
);
348 spin_unlock_bh(&txq
->axq_lock
);
352 fill_min_rates(skb
, txctl
);
356 txctl
->flags
= HAL_TXDESC_CLRDMASK
; /* needed for crypto errors */
358 if (tx_info
->flags
& IEEE80211_TX_CTL_NO_ACK
)
359 tx_info
->flags
|= HAL_TXDESC_NOACK
;
360 if (tx_info
->flags
& IEEE80211_TX_CTL_USE_RTS_CTS
)
361 tx_info
->flags
|= HAL_TXDESC_RTSENA
;
364 * Setup for rate calculations.
366 tx_info_priv
= (struct ath_tx_info_priv
*)tx_info
->driver_data
[0];
367 rcs
= tx_info_priv
->rcs
;
369 if (ieee80211_is_data(fc
) && !txctl
->use_minrate
) {
371 /* Enable HT only for DATA frames and not for EAPOL */
372 txctl
->ht
= (hw
->conf
.ht_conf
.ht_supported
&&
373 (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
));
375 if (is_multicast_ether_addr(hdr
->addr1
)) {
376 rcs
[0].rix
= (u_int8_t
)
377 ath_tx_findindex(rt
, txctl
->mcast_rate
);
380 * mcast packets are not re-tried.
384 /* For HT capable stations, we save tidno for later use.
385 * We also override seqno set by upper layer with the one
386 * in tx aggregation state.
388 * First, the fragmentation stat is determined.
389 * If fragmentation is on, the sequence number is
390 * not overridden, since it has been
391 * incremented by the fragmentation routine.
393 if (likely(!(txctl
->flags
& HAL_TXDESC_FRAG_IS_ON
)) &&
394 txctl
->ht
&& sc
->sc_txaggr
) {
395 struct ath_atx_tid
*tid
;
397 tid
= ATH_AN_2_TID(txctl
->an
, txctl
->tidno
);
399 hdr
->seq_ctrl
= cpu_to_le16(tid
->seq_next
<<
400 IEEE80211_SEQ_SEQ_SHIFT
);
401 txctl
->seqno
= tid
->seq_next
;
402 INCR(tid
->seq_next
, IEEE80211_SEQ_MAX
);
405 /* for management and control frames,
406 * or for NULL and EAPOL frames */
408 rcs
[0].rix
= ath_rate_findrateix(sc
, txctl
->min_rate
);
410 rcs
[0].rix
= sc
->sc_minrateix
;
411 rcs
[0].tries
= ATH_MGT_TXMAXTRY
;
416 * Calculate duration. This logically belongs in the 802.11
417 * layer but it lacks sufficient information to calculate it.
419 if ((txctl
->flags
& HAL_TXDESC_NOACK
) == 0 && !ieee80211_is_ctl(fc
)) {
422 * XXX not right with fragmentation.
424 if (sc
->sc_flags
& ATH_PREAMBLE_SHORT
)
425 dur
= rt
->info
[rix
].spAckDuration
;
427 dur
= rt
->info
[rix
].lpAckDuration
;
429 if (le16_to_cpu(hdr
->frame_control
) &
430 IEEE80211_FCTL_MOREFRAGS
) {
431 dur
+= dur
; /* Add additional 'SIFS + ACK' */
434 ** Compute size of next fragment in order to compute
435 ** durations needed to update NAV.
436 ** The last fragment uses the ACK duration only.
437 ** Add time for next fragment.
439 dur
+= ath9k_hw_computetxtime(sc
->sc_ah
, rt
,
441 rix
, sc
->sc_flags
& ATH_PREAMBLE_SHORT
);
444 if (ieee80211_has_morefrags(fc
) ||
445 (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
)) {
447 ** Force hardware to use computed duration for next
448 ** fragment by disabling multi-rate retry, which
449 ** updates duration based on the multi-rate
452 rcs
[1].tries
= rcs
[2].tries
= rcs
[3].tries
= 0;
453 rcs
[1].rix
= rcs
[2].rix
= rcs
[3].rix
= 0;
454 /* reset tries but keep rate index */
455 rcs
[0].tries
= ATH_TXMAXTRY
;
458 hdr
->duration_id
= cpu_to_le16(dur
);
462 * Determine if a tx interrupt should be generated for
463 * this descriptor. We take a tx interrupt to reap
464 * descriptors when the h/w hits an EOL condition or
465 * when the descriptor is specifically marked to generate
466 * an interrupt. We periodically mark descriptors in this
467 * way to insure timely replenishing of the supply needed
468 * for sending frames. Defering interrupts reduces system
469 * load and potentially allows more concurrent work to be
470 * done but if done to aggressively can cause senders to
473 * NB: use >= to deal with sc_txintrperiod changing
474 * dynamically through sysctl.
476 spin_lock_bh(&txq
->axq_lock
);
477 if ((++txq
->axq_intrcnt
>= sc
->sc_txintrperiod
)) {
478 txctl
->flags
|= HAL_TXDESC_INTREQ
;
479 txq
->axq_intrcnt
= 0;
481 spin_unlock_bh(&txq
->axq_lock
);
483 if (is_multicast_ether_addr(hdr
->addr1
)) {
484 antenna
= sc
->sc_mcastantenna
+ 1;
485 sc
->sc_mcastantenna
= (sc
->sc_mcastantenna
+ 1) & 0x1;
487 antenna
= sc
->sc_txantenna
;
489 #ifdef USE_LEGACY_HAL
490 txctl
->antenna
= antenna
;
495 /* To complete a chain of buffers associated a frame */
497 static void ath_tx_complete_buf(struct ath_softc
*sc
,
499 struct list_head
*bf_q
,
500 int txok
, int sendbar
)
502 struct sk_buff
*skb
= bf
->bf_mpdu
;
503 struct ath_xmit_status tx_status
;
507 * Set retry information.
508 * NB: Don't use the information in the descriptor, because the frame
509 * could be software retried.
511 tx_status
.retries
= bf
->bf_retries
;
515 tx_status
.flags
= ATH_TX_BAR
;
518 tx_status
.flags
|= ATH_TX_ERROR
;
520 if (bf
->bf_isxretried
)
521 tx_status
.flags
|= ATH_TX_XRETRY
;
523 /* Unmap this frame */
524 pa
= get_dma_mem_context(bf
, bf_dmacontext
);
525 pci_unmap_single(sc
->pdev
,
529 /* complete this frame */
530 ath_tx_complete(sc
, skb
, &tx_status
, bf
->bf_node
);
533 * Return the list of ath_buf of this mpdu to free queue
535 spin_lock_bh(&sc
->sc_txbuflock
);
536 list_splice_tail_init(bf_q
, &sc
->sc_txbuf
);
537 spin_unlock_bh(&sc
->sc_txbuflock
);
541 * queue up a dest/ac pair for tx scheduling
542 * NB: must be called with txq lock held
545 static void ath_tx_queue_tid(struct ath_txq
*txq
, struct ath_atx_tid
*tid
)
547 struct ath_atx_ac
*ac
= tid
->ac
;
550 * if tid is paused, hold off
556 * add tid to ac atmost once
561 tid
->sched
= AH_TRUE
;
562 list_add_tail(&tid
->list
, &ac
->tid_q
);
565 * add node ac to txq atmost once
571 list_add_tail(&ac
->list
, &txq
->axq_acq
);
576 static void ath_tx_pause_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
)
578 struct ath_txq
*txq
= &sc
->sc_txq
[tid
->ac
->qnum
];
580 spin_lock_bh(&txq
->axq_lock
);
584 spin_unlock_bh(&txq
->axq_lock
);
587 /* resume a tid and schedule aggregate */
589 void ath_tx_resume_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
)
591 struct ath_txq
*txq
= &sc
->sc_txq
[tid
->ac
->qnum
];
593 ASSERT(tid
->paused
> 0);
594 spin_lock_bh(&txq
->axq_lock
);
601 if (list_empty(&tid
->buf_q
))
605 * Add this TID to scheduler and try to send out aggregates
607 ath_tx_queue_tid(txq
, tid
);
608 ath_txq_schedule(sc
, txq
);
610 spin_unlock_bh(&txq
->axq_lock
);
613 /* Compute the number of bad frames */
615 static int ath_tx_num_badfrms(struct ath_softc
*sc
,
616 struct ath_buf
*bf
, int txok
)
618 struct ath_node
*an
= bf
->bf_node
;
619 int isnodegone
= (an
->an_flags
& ATH_NODE_CLEAN
);
620 struct ath_buf
*bf_last
= bf
->bf_lastbf
;
621 struct ath_desc
*ds
= bf_last
->bf_desc
;
622 u_int16_t seq_st
= 0;
623 u_int32_t ba
[WME_BA_BMP_SIZE
>> 5];
628 if (isnodegone
|| ds
->ds_txstat
.ts_flags
== HAL_TX_SW_ABORTED
)
631 isaggr
= bf
->bf_isaggr
;
633 seq_st
= ATH_DS_BA_SEQ(ds
);
634 memcpy(ba
, ATH_DS_BA_BITMAP(ds
), WME_BA_BMP_SIZE
>> 3);
638 ba_index
= ATH_BA_INDEX(seq_st
, bf
->bf_seqno
);
639 if (!txok
|| (isaggr
&& !ATH_BA_ISSET(ba
, ba_index
)))
648 static void ath_tx_set_retry(struct ath_softc
*sc
, struct ath_buf
*bf
)
651 struct ieee80211_hdr
*hdr
;
653 bf
->bf_isretried
= 1;
657 hdr
= (struct ieee80211_hdr
*)skb
->data
;
658 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_RETRY
);
661 /* Update block ack window */
663 static void ath_tx_update_baw(struct ath_softc
*sc
,
664 struct ath_atx_tid
*tid
, int seqno
)
668 index
= ATH_BA_INDEX(tid
->seq_start
, seqno
);
669 cindex
= (tid
->baw_head
+ index
) & (ATH_TID_MAX_BUFS
- 1);
671 tid
->tx_buf
[cindex
] = NULL
;
673 while (tid
->baw_head
!= tid
->baw_tail
&& !tid
->tx_buf
[tid
->baw_head
]) {
674 INCR(tid
->seq_start
, IEEE80211_SEQ_MAX
);
675 INCR(tid
->baw_head
, ATH_TID_MAX_BUFS
);
680 * ath_pkt_dur - compute packet duration (NB: not NAV)
683 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
684 * width - 0 for 20 MHz, 1 for 40 MHz
685 * half_gi - to use 4us v/s 3.6 us for symbol time
688 static u_int32_t
ath_pkt_duration(struct ath_softc
*sc
,
693 enum hal_bool shortPreamble
)
695 const struct hal_rate_table
*rt
= sc
->sc_currates
;
696 u_int32_t nbits
, nsymbits
, duration
, nsymbols
;
700 pktlen
= bf
->bf_isaggr
? bf
->bf_al
: bf
->bf_frmlen
;
701 rc
= rt
->info
[rix
].rateCode
;
704 * for legacy rates, use old function to compute packet duration
707 return ath9k_hw_computetxtime(sc
->sc_ah
,
713 * find number of symbols: PLCP + data
715 nbits
= (pktlen
<< 3) + OFDM_PLCP_BITS
;
716 nsymbits
= bits_per_symbol
[HT_RC_2_MCS(rc
)][width
];
717 nsymbols
= (nbits
+ nsymbits
- 1) / nsymbits
;
720 duration
= SYMBOL_TIME(nsymbols
);
722 duration
= SYMBOL_TIME_HALFGI(nsymbols
);
725 * addup duration for legacy/ht training and signal fields
727 streams
= HT_RC_2_STREAMS(rc
);
728 duration
+= L_STF
+ L_LTF
+ L_SIG
+ HT_SIG
+ HT_STF
+ HT_LTF(streams
);
732 /* Rate module function to set rate related fields in tx descriptor */
734 static void ath_buf_set_rate(struct ath_softc
*sc
, struct ath_buf
*bf
)
736 struct ath_hal
*ah
= sc
->sc_ah
;
737 const struct hal_rate_table
*rt
;
738 struct ath_desc
*ds
= bf
->bf_desc
;
739 struct ath_desc
*lastds
= bf
->bf_lastbf
->bf_desc
;
740 struct hal_11n_rate_series series
[4];
741 int i
, flags
, rtsctsena
= 0, dynamic_mimops
= 0;
742 u_int ctsduration
= 0;
743 u_int8_t rix
= 0, cix
, ctsrate
= 0;
744 u_int32_t aggr_limit_with_rts
= sc
->sc_rtsaggrlimit
;
745 struct ath_node
*an
= (struct ath_node
*) bf
->bf_node
;
748 * get the cix for the lowest valid rix.
750 rt
= sc
->sc_currates
;
752 if (bf
->bf_rcs
[i
].tries
) {
753 rix
= bf
->bf_rcs
[i
].rix
;
757 flags
= (bf
->bf_flags
& (HAL_TXDESC_RTSENA
| HAL_TXDESC_CTSENA
));
758 cix
= rt
->info
[rix
].controlRate
;
761 * If 802.11g protection is enabled, determine whether
762 * to use RTS/CTS or just CTS. Note that this is only
763 * done for OFDM/HT unicast frames.
765 if (sc
->sc_protmode
!= PROT_M_NONE
&&
766 (rt
->info
[rix
].phy
== PHY_OFDM
||
767 rt
->info
[rix
].phy
== PHY_HT
) &&
768 (bf
->bf_flags
& HAL_TXDESC_NOACK
) == 0) {
769 if (sc
->sc_protmode
== PROT_M_RTSCTS
)
770 flags
= HAL_TXDESC_RTSENA
;
771 else if (sc
->sc_protmode
== PROT_M_CTSONLY
)
772 flags
= HAL_TXDESC_CTSENA
;
774 cix
= rt
->info
[sc
->sc_protrix
].controlRate
;
778 /* For 11n, the default behavior is to enable RTS for
779 * hw retried frames. We enable the global flag here and
780 * let rate series flags determine which rates will actually
783 if (sc
->sc_hashtsupport
&& bf
->bf_isdata
) {
784 KASSERT(an
!= NULL
, ("an == null"));
786 * 802.11g protection not needed, use our default behavior
789 flags
= HAL_TXDESC_RTSENA
;
791 * For dynamic MIMO PS, RTS needs to precede the first aggregate
792 * and the second aggregate should have any protection at all.
794 if (an
->an_smmode
== ATH_SM_PWRSAV_DYNAMIC
) {
795 if (!bf
->bf_aggrburst
) {
796 flags
= HAL_TXDESC_RTSENA
;
805 * Set protection if aggregate protection on
807 if (sc
->sc_config
.ath_aggr_prot
&&
808 (!bf
->bf_isaggr
|| (bf
->bf_isaggr
&& bf
->bf_al
< 8192))) {
809 flags
= HAL_TXDESC_RTSENA
;
810 cix
= rt
->info
[sc
->sc_protrix
].controlRate
;
815 * For AR5416 - RTS cannot be followed by a frame larger than 8K.
817 if (bf
->bf_isaggr
&& (bf
->bf_al
> aggr_limit_with_rts
)) {
819 * Ensure that in the case of SM Dynamic power save
820 * while we are bursting the second aggregate the
823 flags
&= ~(HAL_TXDESC_RTSENA
);
827 * CTS transmit rate is derived from the transmit rate
828 * by looking in the h/w rate table. We must also factor
829 * in whether or not a short preamble is to be used.
831 /* NB: cix is set above where RTS/CTS is enabled */
832 KASSERT(cix
!= 0xff, ("cix not setup"));
833 ctsrate
= rt
->info
[cix
].rateCode
|
834 (bf
->bf_shpreamble
? rt
->info
[cix
].shortPreamble
: 0);
837 * Setup HAL rate series
839 memzero(series
, sizeof(struct hal_11n_rate_series
) * 4);
841 for (i
= 0; i
< 4; i
++) {
842 if (!bf
->bf_rcs
[i
].tries
)
845 rix
= bf
->bf_rcs
[i
].rix
;
847 series
[i
].Rate
= rt
->info
[rix
].rateCode
|
848 (bf
->bf_shpreamble
? rt
->info
[rix
].shortPreamble
: 0);
850 series
[i
].Tries
= bf
->bf_rcs
[i
].tries
;
852 series
[i
].RateFlags
= (
853 (bf
->bf_rcs
[i
].flags
& ATH_RC_RTSCTS_FLAG
) ?
854 HAL_RATESERIES_RTS_CTS
: 0) |
855 ((bf
->bf_rcs
[i
].flags
& ATH_RC_CW40_FLAG
) ?
856 HAL_RATESERIES_2040
: 0) |
857 ((bf
->bf_rcs
[i
].flags
& ATH_RC_SGI_FLAG
) ?
858 HAL_RATESERIES_HALFGI
: 0);
860 series
[i
].PktDuration
= ath_pkt_duration(
862 (bf
->bf_rcs
[i
].flags
& ATH_RC_CW40_FLAG
) != 0,
863 (bf
->bf_rcs
[i
].flags
& ATH_RC_SGI_FLAG
),
866 if ((an
->an_smmode
== ATH_SM_PWRSAV_STATIC
) &&
867 (bf
->bf_rcs
[i
].flags
& ATH_RC_DS_FLAG
) == 0) {
869 * When sending to an HT node that has enabled static
870 * SM/MIMO power save, send at single stream rates but
871 * use maximum allowed transmit chains per user,
872 * hardware, regulatory, or country limits for
875 series
[i
].ChSel
= sc
->sc_tx_chainmask
;
879 ath_chainmask_sel_logic(sc
, an
);
881 series
[i
].ChSel
= sc
->sc_tx_chainmask
;
885 series
[i
].RateFlags
|= HAL_RATESERIES_RTS_CTS
;
888 * Set RTS for all rates if node is in dynamic powersave
889 * mode and we are using dual stream rates.
891 if (dynamic_mimops
&& (bf
->bf_rcs
[i
].flags
& ATH_RC_DS_FLAG
))
892 series
[i
].RateFlags
|= HAL_RATESERIES_RTS_CTS
;
896 * For non-HT devices, calculate RTS/CTS duration in software
897 * and disable multi-rate retry.
899 if (flags
&& !sc
->sc_hashtsupport
) {
901 * Compute the transmit duration based on the frame
902 * size and the size of an ACK frame. We call into the
903 * HAL to do the computation since it depends on the
904 * characteristics of the actual PHY being used.
906 * NB: CTS is assumed the same size as an ACK so we can
907 * use the precalculated ACK durations.
909 if (flags
& HAL_TXDESC_RTSENA
) { /* SIFS + CTS */
910 ctsduration
+= bf
->bf_shpreamble
?
911 rt
->info
[cix
].spAckDuration
:
912 rt
->info
[cix
].lpAckDuration
;
915 ctsduration
+= series
[0].PktDuration
;
917 if ((bf
->bf_flags
& HAL_TXDESC_NOACK
) == 0) { /* SIFS + ACK */
918 ctsduration
+= bf
->bf_shpreamble
?
919 rt
->info
[rix
].spAckDuration
:
920 rt
->info
[rix
].lpAckDuration
;
924 * Disable multi-rate retry when using RTS/CTS by clearing
927 memzero(&series
[1], sizeof(struct hal_11n_rate_series
) * 3);
931 * set dur_update_en for l-sig computation except for PS-Poll frames
933 ath9k_hw_set11n_ratescenario(ah
, ds
, lastds
,
938 if (sc
->sc_config
.ath_aggr_prot
&& flags
)
939 ath9k_hw_set11n_burstduration(ah
, ds
, 8192);
943 * Function to send a normal HT (non-AMPDU) frame
944 * NB: must be called with txq lock held
947 static int ath_tx_send_normal(struct ath_softc
*sc
,
949 struct ath_atx_tid
*tid
,
950 struct list_head
*bf_head
)
954 struct ieee80211_tx_info
*tx_info
;
955 struct ath_tx_info_priv
*tx_info_priv
;
957 BUG_ON(list_empty(bf_head
));
959 bf
= list_first_entry(bf_head
, struct ath_buf
, list
);
960 bf
->bf_isampdu
= 0; /* regular HT frame */
962 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
963 tx_info
= IEEE80211_SKB_CB(skb
);
964 tx_info_priv
= (struct ath_tx_info_priv
*)tx_info
->driver_data
[0];
965 memcpy(bf
->bf_rcs
, tx_info_priv
->rcs
, 4 * sizeof(tx_info_priv
->rcs
[0]));
967 /* update starting sequence number for subsequent ADDBA request */
968 INCR(tid
->seq_start
, IEEE80211_SEQ_MAX
);
970 /* Queue to h/w without aggregation */
972 bf
->bf_lastbf
= bf
->bf_lastfrm
; /* one single frame */
973 ath_buf_set_rate(sc
, bf
);
974 ath_tx_txqaddbuf(sc
, txq
, bf_head
);
979 /* flush tid's software queue and send frames as non-ampdu's */
981 static void ath_tx_flush_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
)
983 struct ath_txq
*txq
= &sc
->sc_txq
[tid
->ac
->qnum
];
985 struct list_head bf_head
;
986 INIT_LIST_HEAD(&bf_head
);
988 ASSERT(tid
->paused
> 0);
989 spin_lock_bh(&txq
->axq_lock
);
993 if (tid
->paused
> 0) {
994 spin_unlock_bh(&txq
->axq_lock
);
998 while (!list_empty(&tid
->buf_q
)) {
999 bf
= list_first_entry(&tid
->buf_q
, struct ath_buf
, list
);
1000 ASSERT(!bf
->bf_isretried
);
1001 list_cut_position(&bf_head
, &tid
->buf_q
, &bf
->bf_lastfrm
->list
);
1002 ath_tx_send_normal(sc
, txq
, tid
, &bf_head
);
1005 spin_unlock_bh(&txq
->axq_lock
);
1008 /* Completion routine of an aggregate */
1010 static void ath_tx_complete_aggr_rifs(struct ath_softc
*sc
,
1011 struct ath_txq
*txq
,
1013 struct list_head
*bf_q
,
1016 struct ath_node
*an
= bf
->bf_node
;
1017 struct ath_atx_tid
*tid
= ATH_AN_2_TID(an
, bf
->bf_tidno
);
1018 struct ath_buf
*bf_last
= bf
->bf_lastbf
;
1019 struct ath_desc
*ds
= bf_last
->bf_desc
;
1020 struct ath_buf
*bf_next
, *bf_lastq
= NULL
;
1021 struct list_head bf_head
, bf_pending
;
1022 u_int16_t seq_st
= 0;
1023 u_int32_t ba
[WME_BA_BMP_SIZE
>> 5];
1024 int isaggr
, txfail
, txpending
, sendbar
= 0, needreset
= 0;
1025 int isnodegone
= (an
->an_flags
& ATH_NODE_CLEAN
);
1027 isaggr
= bf
->bf_isaggr
;
1030 if (ATH_DS_TX_BA(ds
)) {
1032 * extract starting sequence and
1035 seq_st
= ATH_DS_BA_SEQ(ds
);
1037 ATH_DS_BA_BITMAP(ds
),
1038 WME_BA_BMP_SIZE
>> 3);
1040 memzero(ba
, WME_BA_BMP_SIZE
>> 3);
1043 * AR5416 can become deaf/mute when BA
1044 * issue happens. Chip needs to be reset.
1045 * But AP code may have sychronization issues
1046 * when perform internal reset in this routine.
1047 * Only enable reset in STA mode for now.
1049 if (sc
->sc_opmode
== HAL_M_STA
)
1053 memzero(ba
, WME_BA_BMP_SIZE
>> 3);
1057 INIT_LIST_HEAD(&bf_pending
);
1058 INIT_LIST_HEAD(&bf_head
);
1061 txfail
= txpending
= 0;
1062 bf_next
= bf
->bf_next
;
1064 if (ATH_BA_ISSET(ba
, ATH_BA_INDEX(seq_st
, bf
->bf_seqno
))) {
1065 /* transmit completion, subframe is
1066 * acked by block ack */
1067 } else if (!isaggr
&& txok
) {
1068 /* transmit completion */
1071 if (!tid
->cleanup_inprogress
&& !isnodegone
&&
1072 ds
->ds_txstat
.ts_flags
!= HAL_TX_SW_ABORTED
) {
1073 if (bf
->bf_retries
< ATH_MAX_SW_RETRIES
) {
1074 ath_tx_set_retry(sc
, bf
);
1077 bf
->bf_isxretried
= 1;
1083 * cleanup in progress, just fail
1084 * the un-acked sub-frames
1090 * Remove ath_buf's of this sub-frame from aggregate queue.
1092 if (bf_next
== NULL
) { /* last subframe in the aggregate */
1093 ASSERT(bf
->bf_lastfrm
== bf_last
);
1096 * The last descriptor of the last sub frame could be
1097 * a holding descriptor for h/w. If that's the case,
1098 * bf->bf_lastfrm won't be in the bf_q.
1099 * Make sure we handle bf_q properly here.
1102 if (!list_empty(bf_q
)) {
1103 bf_lastq
= list_entry(bf_q
->prev
,
1104 struct ath_buf
, list
);
1105 list_cut_position(&bf_head
,
1106 bf_q
, &bf_lastq
->list
);
1109 * XXX: if the last subframe only has one
1110 * descriptor which is also being used as
1111 * a holding descriptor. Then the ath_buf
1112 * is not in the bf_q at all.
1114 INIT_LIST_HEAD(&bf_head
);
1117 ASSERT(!list_empty(bf_q
));
1118 list_cut_position(&bf_head
,
1119 bf_q
, &bf
->bf_lastfrm
->list
);
1124 * complete the acked-ones/xretried ones; update
1127 spin_lock_bh(&txq
->axq_lock
);
1128 ath_tx_update_baw(sc
, tid
, bf
->bf_seqno
);
1129 spin_unlock_bh(&txq
->axq_lock
);
1131 /* complete this sub-frame */
1132 ath_tx_complete_buf(sc
, bf
, &bf_head
, !txfail
, sendbar
);
1135 * retry the un-acked ones
1138 * XXX: if the last descriptor is holding descriptor,
1139 * in order to requeue the frame to software queue, we
1140 * need to allocate a new descriptor and
1141 * copy the content of holding descriptor to it.
1143 if (bf
->bf_next
== NULL
&&
1144 bf_last
->bf_status
& ATH_BUFSTATUS_STALE
) {
1145 struct ath_buf
*tbf
;
1147 /* allocate new descriptor */
1148 spin_lock_bh(&sc
->sc_txbuflock
);
1149 ASSERT(!list_empty((&sc
->sc_txbuf
)));
1150 tbf
= list_first_entry(&sc
->sc_txbuf
,
1151 struct ath_buf
, list
);
1152 list_del(&tbf
->list
);
1153 spin_unlock_bh(&sc
->sc_txbuflock
);
1155 ATH_TXBUF_RESET(tbf
);
1157 /* copy descriptor content */
1158 tbf
->bf_mpdu
= bf_last
->bf_mpdu
;
1159 tbf
->bf_node
= bf_last
->bf_node
;
1160 tbf
->bf_buf_addr
= bf_last
->bf_buf_addr
;
1161 *(tbf
->bf_desc
) = *(bf_last
->bf_desc
);
1163 /* link it to the frame */
1165 bf_lastq
->bf_desc
->ds_link
=
1167 bf
->bf_lastfrm
= tbf
;
1168 ath9k_hw_cleartxdesc(sc
->sc_ah
,
1169 bf
->bf_lastfrm
->bf_desc
);
1171 tbf
->bf_state
= bf_last
->bf_state
;
1172 tbf
->bf_lastfrm
= tbf
;
1173 ath9k_hw_cleartxdesc(sc
->sc_ah
,
1174 tbf
->bf_lastfrm
->bf_desc
);
1176 /* copy the DMA context */
1177 copy_dma_mem_context(
1178 get_dma_mem_context(tbf
,
1180 get_dma_mem_context(bf_last
,
1183 list_add_tail(&tbf
->list
, &bf_head
);
1186 * Clear descriptor status words for
1189 ath9k_hw_cleartxdesc(sc
->sc_ah
,
1190 bf
->bf_lastfrm
->bf_desc
);
1194 * Put this buffer to the temporary pending
1195 * queue to retain ordering
1197 list_splice_tail_init(&bf_head
, &bf_pending
);
1204 * node is already gone. no more assocication
1205 * with the node. the node might have been freed
1206 * any node acces can result in panic.note tid
1207 * is part of the node.
1212 if (tid
->cleanup_inprogress
) {
1213 /* check to see if we're done with cleaning the h/w queue */
1214 spin_lock_bh(&txq
->axq_lock
);
1216 if (tid
->baw_head
== tid
->baw_tail
) {
1217 tid
->addba_exchangecomplete
= 0;
1218 tid
->addba_exchangeattempts
= 0;
1219 spin_unlock_bh(&txq
->axq_lock
);
1221 tid
->cleanup_inprogress
= AH_FALSE
;
1223 /* send buffered frames as singles */
1224 ath_tx_flush_tid(sc
, tid
);
1226 spin_unlock_bh(&txq
->axq_lock
);
1232 * prepend un-acked frames to the beginning of the pending frame queue
1234 if (!list_empty(&bf_pending
)) {
1235 spin_lock_bh(&txq
->axq_lock
);
1236 /* Note: we _prepend_, we _do_not_ at to
1237 * the end of the queue ! */
1238 list_splice(&bf_pending
, &tid
->buf_q
);
1239 ath_tx_queue_tid(txq
, tid
);
1240 spin_unlock_bh(&txq
->axq_lock
);
1244 ath_internal_reset(sc
);
1249 /* Process completed xmit descriptors from the specified queue */
1251 static int ath_tx_processq(struct ath_softc
*sc
, struct ath_txq
*txq
)
1253 struct ath_hal
*ah
= sc
->sc_ah
;
1254 struct ath_buf
*bf
, *lastbf
, *bf_held
= NULL
;
1255 struct list_head bf_head
;
1256 struct ath_desc
*ds
, *tmp_ds
;
1257 struct sk_buff
*skb
;
1258 struct ieee80211_tx_info
*tx_info
;
1259 struct ath_tx_info_priv
*tx_info_priv
;
1261 int nacked
, txok
, nbad
= 0, isrifs
= 0;
1262 enum hal_status status
;
1264 DPRINTF(sc
, ATH_DEBUG_TX_PROC
,
1265 "%s: tx queue %d (%x), link %p\n", __func__
,
1266 txq
->axq_qnum
, ath9k_hw_gettxbuf(sc
->sc_ah
, txq
->axq_qnum
),
1271 spin_lock_bh(&txq
->axq_lock
);
1272 txq
->axq_intrcnt
= 0; /* reset periodic desc intr count */
1273 if (list_empty(&txq
->axq_q
)) {
1274 txq
->axq_link
= NULL
;
1275 txq
->axq_linkbuf
= NULL
;
1276 spin_unlock_bh(&txq
->axq_lock
);
1279 bf
= list_first_entry(&txq
->axq_q
, struct ath_buf
, list
);
1282 * There is a race condition that a BH gets scheduled
1283 * after sw writes TxE and before hw re-load the last
1284 * descriptor to get the newly chained one.
1285 * Software must keep the last DONE descriptor as a
1286 * holding descriptor - software does so by marking
1287 * it with the STALE flag.
1290 if (bf
->bf_status
& ATH_BUFSTATUS_STALE
) {
1292 if (list_is_last(&bf_held
->list
, &txq
->axq_q
)) {
1294 * The holding descriptor is the last
1295 * descriptor in queue. It's safe to remove
1296 * the last holding descriptor in BH context.
1298 spin_unlock_bh(&txq
->axq_lock
);
1301 /* Lets work with the next buffer now */
1302 bf
= list_entry(bf_held
->list
.next
,
1303 struct ath_buf
, list
);
1307 lastbf
= bf
->bf_lastbf
;
1308 ds
= lastbf
->bf_desc
; /* NB: last decriptor */
1310 status
= ath9k_hw_txprocdesc(ah
, ds
);
1311 if (status
== HAL_EINPROGRESS
) {
1312 spin_unlock_bh(&txq
->axq_lock
);
1315 if (bf
->bf_desc
== txq
->axq_lastdsWithCTS
)
1316 txq
->axq_lastdsWithCTS
= NULL
;
1317 if (ds
== txq
->axq_gatingds
)
1318 txq
->axq_gatingds
= NULL
;
1321 * Remove ath_buf's of the same transmit unit from txq,
1322 * however leave the last descriptor back as the holding
1323 * descriptor for hw.
1325 lastbf
->bf_status
|= ATH_BUFSTATUS_STALE
;
1326 INIT_LIST_HEAD(&bf_head
);
1328 if (!list_is_singular(&lastbf
->list
))
1329 list_cut_position(&bf_head
,
1330 &txq
->axq_q
, lastbf
->list
.prev
);
1335 txq
->axq_aggr_depth
--;
1337 txok
= (ds
->ds_txstat
.ts_status
== 0);
1339 spin_unlock_bh(&txq
->axq_lock
);
1342 list_del(&bf_held
->list
);
1343 spin_lock_bh(&sc
->sc_txbuflock
);
1344 list_add_tail(&bf_held
->list
, &sc
->sc_txbuf
);
1345 spin_unlock_bh(&sc
->sc_txbuflock
);
1349 txant
= ds
->ds_txstat
.ts_antenna
;
1350 sc
->sc_ant_tx
[txant
]++;
1352 if (!bf
->bf_isampdu
) {
1354 * This frame is sent out as a single frame.
1355 * Use hardware retry status for this frame.
1357 bf
->bf_retries
= ds
->ds_txstat
.ts_longretry
;
1358 if (ds
->ds_txstat
.ts_status
& HAL_TXERR_XRETRY
)
1359 bf
->bf_isxretried
= 1;
1362 nbad
= ath_tx_num_badfrms(sc
, bf
, txok
);
1365 tx_info
= IEEE80211_SKB_CB(skb
);
1366 tx_info_priv
= (struct ath_tx_info_priv
*)
1367 tx_info
->driver_data
[0];
1368 if (ds
->ds_txstat
.ts_status
& HAL_TXERR_FILT
)
1369 tx_info
->flags
|= IEEE80211_TX_STAT_TX_FILTERED
;
1370 if ((ds
->ds_txstat
.ts_status
& HAL_TXERR_FILT
) == 0 &&
1371 (bf
->bf_flags
& HAL_TXDESC_NOACK
) == 0) {
1372 if (ds
->ds_txstat
.ts_status
== 0)
1375 if (bf
->bf_isdata
) {
1377 tmp_ds
= bf
->bf_rifslast
->bf_desc
;
1380 memcpy(&tx_info_priv
->tx
,
1382 sizeof(tx_info_priv
->tx
));
1383 tx_info_priv
->n_frames
= bf
->bf_nframes
;
1384 tx_info_priv
->n_bad_frames
= nbad
;
1389 * Complete this transmit unit
1392 ath_tx_complete_aggr_rifs(sc
, txq
, bf
, &bf_head
, txok
);
1394 ath_tx_complete_buf(sc
, bf
, &bf_head
, txok
, 0);
1396 /* Wake up mac80211 queue */
1398 spin_lock_bh(&txq
->axq_lock
);
1399 if (txq
->stopped
&& ath_txq_depth(sc
, txq
->axq_qnum
) <=
1402 qnum
= ath_get_mac80211_qnum(txq
->axq_qnum
, sc
);
1404 ieee80211_wake_queue(sc
->hw
, qnum
);
1411 * schedule any pending packets if aggregation is enabled
1414 ath_txq_schedule(sc
, txq
);
1415 spin_unlock_bh(&txq
->axq_lock
);
1420 static void ath_tx_stopdma(struct ath_softc
*sc
, struct ath_txq
*txq
)
1422 struct ath_hal
*ah
= sc
->sc_ah
;
1424 (void) ath9k_hw_stoptxdma(ah
, txq
->axq_qnum
);
1425 DPRINTF(sc
, ATH_DEBUG_XMIT
, "%s: tx queue [%u] %x, link %p\n",
1426 __func__
, txq
->axq_qnum
,
1427 ath9k_hw_gettxbuf(ah
, txq
->axq_qnum
), txq
->axq_link
);
1430 /* Drain only the data queues */
1432 static void ath_drain_txdataq(struct ath_softc
*sc
, enum hal_bool retry_tx
)
1434 struct ath_hal
*ah
= sc
->sc_ah
;
1437 enum hal_ht_macmode ht_macmode
= ath_cwm_macmode(sc
);
1439 /* XXX return value */
1440 if (!sc
->sc_invalid
) {
1441 for (i
= 0; i
< HAL_NUM_TX_QUEUES
; i
++) {
1442 if (ATH_TXQ_SETUP(sc
, i
)) {
1443 ath_tx_stopdma(sc
, &sc
->sc_txq
[i
]);
1445 /* The TxDMA may not really be stopped.
1446 * Double check the hal tx pending count */
1447 npend
+= ath9k_hw_numtxpending(ah
,
1448 sc
->sc_txq
[i
].axq_qnum
);
1454 enum hal_status status
;
1456 /* TxDMA not stopped, reset the hal */
1457 DPRINTF(sc
, ATH_DEBUG_XMIT
,
1458 "%s: Unable to stop TxDMA. Reset HAL!\n", __func__
);
1460 spin_lock_bh(&sc
->sc_resetlock
);
1461 if (!ath9k_hw_reset(ah
, sc
->sc_opmode
,
1462 &sc
->sc_curchan
, ht_macmode
,
1463 sc
->sc_tx_chainmask
, sc
->sc_rx_chainmask
,
1464 sc
->sc_ht_extprotspacing
, AH_TRUE
, &status
)) {
1466 DPRINTF(sc
, ATH_DEBUG_FATAL
,
1467 "%s: unable to reset hardware; hal status %u\n",
1471 spin_unlock_bh(&sc
->sc_resetlock
);
1474 for (i
= 0; i
< HAL_NUM_TX_QUEUES
; i
++) {
1475 if (ATH_TXQ_SETUP(sc
, i
))
1476 ath_tx_draintxq(sc
, &sc
->sc_txq
[i
], retry_tx
);
1480 /* Add a sub-frame to block ack window */
1482 static void ath_tx_addto_baw(struct ath_softc
*sc
,
1483 struct ath_atx_tid
*tid
,
1488 if (bf
->bf_isretried
)
1491 index
= ATH_BA_INDEX(tid
->seq_start
, bf
->bf_seqno
);
1492 cindex
= (tid
->baw_head
+ index
) & (ATH_TID_MAX_BUFS
- 1);
1494 ASSERT(tid
->tx_buf
[cindex
] == NULL
);
1495 tid
->tx_buf
[cindex
] = bf
;
1497 if (index
>= ((tid
->baw_tail
- tid
->baw_head
) &
1498 (ATH_TID_MAX_BUFS
- 1))) {
1499 tid
->baw_tail
= cindex
;
1500 INCR(tid
->baw_tail
, ATH_TID_MAX_BUFS
);
1505 * Function to send an A-MPDU
1506 * NB: must be called with txq lock held
1509 static int ath_tx_send_ampdu(struct ath_softc
*sc
,
1510 struct ath_txq
*txq
,
1511 struct ath_atx_tid
*tid
,
1512 struct list_head
*bf_head
,
1513 struct ath_tx_control
*txctl
)
1516 struct sk_buff
*skb
;
1517 struct ieee80211_tx_info
*tx_info
;
1518 struct ath_tx_info_priv
*tx_info_priv
;
1520 BUG_ON(list_empty(bf_head
));
1522 bf
= list_first_entry(bf_head
, struct ath_buf
, list
);
1524 bf
->bf_seqno
= txctl
->seqno
; /* save seqno and tidno in buffer */
1525 bf
->bf_tidno
= txctl
->tidno
;
1528 * Do not queue to h/w when any of the following conditions is true:
1529 * - there are pending frames in software queue
1530 * - the TID is currently paused for ADDBA/BAR request
1531 * - seqno is not within block-ack window
1532 * - h/w queue depth exceeds low water mark
1534 if (!list_empty(&tid
->buf_q
) || tid
->paused
||
1535 !BAW_WITHIN(tid
->seq_start
, tid
->baw_size
, bf
->bf_seqno
) ||
1536 txq
->axq_depth
>= ATH_AGGR_MIN_QDEPTH
) {
1538 * Add this frame to software queue for scheduling later
1541 list_splice_tail_init(bf_head
, &tid
->buf_q
);
1542 ath_tx_queue_tid(txq
, tid
);
1546 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
1547 tx_info
= IEEE80211_SKB_CB(skb
);
1548 tx_info_priv
= (struct ath_tx_info_priv
*)tx_info
->driver_data
[0];
1549 memcpy(bf
->bf_rcs
, tx_info_priv
->rcs
, 4 * sizeof(tx_info_priv
->rcs
[0]));
1551 /* Add sub-frame to BAW */
1552 ath_tx_addto_baw(sc
, tid
, bf
);
1554 /* Queue to h/w without aggregation */
1556 bf
->bf_lastbf
= bf
->bf_lastfrm
; /* one single frame */
1557 ath_buf_set_rate(sc
, bf
);
1558 ath_tx_txqaddbuf(sc
, txq
, bf_head
);
1564 * returns aggr limit based on lowest of the rates
1567 static u_int32_t
ath_lookup_rate(struct ath_softc
*sc
,
1570 const struct hal_rate_table
*rt
= sc
->sc_currates
;
1571 struct sk_buff
*skb
;
1572 struct ieee80211_tx_info
*tx_info
;
1573 struct ath_tx_info_priv
*tx_info_priv
;
1574 u_int32_t max_4ms_framelen
, frame_length
;
1575 u_int16_t aggr_limit
, legacy
= 0, maxampdu
;
1579 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
1580 tx_info
= IEEE80211_SKB_CB(skb
);
1581 tx_info_priv
= (struct ath_tx_info_priv
*)
1582 tx_info
->driver_data
[0];
1584 tx_info_priv
->rcs
, 4 * sizeof(tx_info_priv
->rcs
[0]));
1587 * Find the lowest frame length among the rate series that will have a
1588 * 4ms transmit duration.
1589 * TODO - TXOP limit needs to be considered.
1591 max_4ms_framelen
= ATH_AMPDU_LIMIT_MAX
;
1593 for (i
= 0; i
< 4; i
++) {
1594 if (bf
->bf_rcs
[i
].tries
) {
1595 frame_length
= bf
->bf_rcs
[i
].max_4ms_framelen
;
1597 if (rt
->info
[bf
->bf_rcs
[i
].rix
].phy
!= PHY_HT
) {
1602 max_4ms_framelen
= min(max_4ms_framelen
, frame_length
);
1607 * limit aggregate size by the minimum rate if rate selected is
1608 * not a probe rate, if rate selected is a probe rate then
1609 * avoid aggregation of this packet.
1611 if (tx_info
->flags
& IEEE80211_TX_CTL_RATE_CTRL_PROBE
|| legacy
)
1614 aggr_limit
= min(max_4ms_framelen
,
1615 (u_int32_t
)ATH_AMPDU_LIMIT_DEFAULT
);
1618 * h/w can accept aggregates upto 16 bit lengths (65535).
1619 * The IE, however can hold upto 65536, which shows up here
1620 * as zero. Ignore 65536 since we are constrained by hw.
1622 maxampdu
= sc
->sc_ht_info
.maxampdu
;
1624 aggr_limit
= min(aggr_limit
, maxampdu
);
1630 * returns the number of delimiters to be added to
1631 * meet the minimum required mpdudensity.
1632 * caller should make sure that the rate is HT rate .
1635 static int ath_compute_num_delims(struct ath_softc
*sc
,
1639 const struct hal_rate_table
*rt
= sc
->sc_currates
;
1640 u_int32_t nsymbits
, nsymbols
, mpdudensity
;
1642 u_int8_t rc
, flags
, rix
;
1643 int width
, half_gi
, ndelim
, mindelim
;
1645 /* Select standard number of delimiters based on frame length alone */
1646 ndelim
= ATH_AGGR_GET_NDELIM(frmlen
);
1649 * If encryption enabled, hardware requires some more padding between
1651 * TODO - this could be improved to be dependent on the rate.
1652 * The hardware can keep up at lower rates, but not higher rates
1654 if (bf
->bf_keytype
!= HAL_KEY_TYPE_CLEAR
)
1655 ndelim
+= ATH_AGGR_ENCRYPTDELIM
;
1658 * Convert desired mpdu density from microeconds to bytes based
1659 * on highest rate in rate series (i.e. first rate) to determine
1660 * required minimum length for subframe. Take into account
1661 * whether high rate is 20 or 40Mhz and half or full GI.
1663 mpdudensity
= sc
->sc_ht_info
.mpdudensity
;
1666 * If there is no mpdu density restriction, no further calculation
1669 if (mpdudensity
== 0)
1672 rix
= bf
->bf_rcs
[0].rix
;
1673 flags
= bf
->bf_rcs
[0].flags
;
1674 rc
= rt
->info
[rix
].rateCode
;
1675 width
= (flags
& ATH_RC_CW40_FLAG
) ? 1 : 0;
1676 half_gi
= (flags
& ATH_RC_SGI_FLAG
) ? 1 : 0;
1679 nsymbols
= NUM_SYMBOLS_PER_USEC_HALFGI(mpdudensity
);
1681 nsymbols
= NUM_SYMBOLS_PER_USEC(mpdudensity
);
1686 nsymbits
= bits_per_symbol
[HT_RC_2_MCS(rc
)][width
];
1687 minlen
= (nsymbols
* nsymbits
) / BITS_PER_BYTE
;
1689 /* Is frame shorter than required minimum length? */
1690 if (frmlen
< minlen
) {
1691 /* Get the minimum number of delimiters required. */
1692 mindelim
= (minlen
- frmlen
) / ATH_AGGR_DELIM_SZ
;
1693 ndelim
= max(mindelim
, ndelim
);
1700 * For aggregation from software buffer queue.
1701 * NB: must be called with txq lock held
1704 static enum ATH_AGGR_STATUS
ath_tx_form_aggr(struct ath_softc
*sc
,
1705 struct ath_atx_tid
*tid
,
1706 struct list_head
*bf_q
,
1707 struct ath_buf
**bf_last
,
1708 struct aggr_rifs_param
*param
,
1711 #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
1712 struct ath_buf
*bf
, *tbf
, *bf_first
, *bf_prev
= NULL
;
1713 struct list_head bf_head
;
1714 int rl
= 0, nframes
= 0, ndelim
;
1715 u_int16_t aggr_limit
= 0, al
= 0, bpad
= 0,
1716 al_delta
, h_baw
= tid
->baw_size
/ 2;
1717 enum ATH_AGGR_STATUS status
= ATH_AGGR_DONE
;
1718 int prev_al
= 0, is_ds_rate
= 0;
1719 INIT_LIST_HEAD(&bf_head
);
1721 BUG_ON(list_empty(&tid
->buf_q
));
1723 bf_first
= list_first_entry(&tid
->buf_q
, struct ath_buf
, list
);
1726 bf
= list_first_entry(&tid
->buf_q
, struct ath_buf
, list
);
1729 * do not step over block-ack window
1731 if (!BAW_WITHIN(tid
->seq_start
, tid
->baw_size
, bf
->bf_seqno
)) {
1732 status
= ATH_AGGR_BAW_CLOSED
;
1737 aggr_limit
= ath_lookup_rate(sc
, bf
);
1740 * Is rate dual stream
1743 (bf
->bf_rcs
[0].flags
& ATH_RC_DS_FLAG
) ? 1 : 0;
1747 * do not exceed aggregation limit
1749 al_delta
= ATH_AGGR_DELIM_SZ
+ bf
->bf_frmlen
;
1751 if (nframes
&& (aggr_limit
<
1752 (al
+ bpad
+ al_delta
+ prev_al
))) {
1753 status
= ATH_AGGR_LIMITED
;
1758 * do not exceed subframe limit
1760 if ((nframes
+ *prev_frames
) >=
1761 min((int)h_baw
, ATH_AMPDU_SUBFRAME_DEFAULT
)) {
1762 status
= ATH_AGGR_LIMITED
;
1767 * add padding for previous frame to aggregation length
1769 al
+= bpad
+ al_delta
;
1772 * Get the delimiters needed to meet the MPDU
1773 * density for this node.
1775 ndelim
= ath_compute_num_delims(sc
, bf_first
, bf
->bf_frmlen
);
1777 bpad
= PADBYTES(al_delta
) + (ndelim
<< 2);
1780 bf
->bf_lastfrm
->bf_desc
->ds_link
= 0;
1783 * this packet is part of an aggregate
1784 * - remove all descriptors belonging to this frame from
1786 * - add it to block ack window
1787 * - set up descriptors for aggregation
1789 list_cut_position(&bf_head
, &tid
->buf_q
, &bf
->bf_lastfrm
->list
);
1790 ath_tx_addto_baw(sc
, tid
, bf
);
1792 list_for_each_entry(tbf
, &bf_head
, list
) {
1793 ath9k_hw_set11n_aggr_middle(sc
->sc_ah
,
1794 tbf
->bf_desc
, ndelim
);
1798 * link buffers of this frame to the aggregate
1800 list_splice_tail_init(&bf_head
, bf_q
);
1804 bf_prev
->bf_next
= bf
;
1805 bf_prev
->bf_lastfrm
->bf_desc
->ds_link
= bf
->bf_daddr
;
1811 * terminate aggregation on a small packet boundary
1813 if (bf
->bf_frmlen
< ATH_AGGR_MINPLEN
) {
1814 status
= ATH_AGGR_SHORTPKT
;
1818 } while (!list_empty(&tid
->buf_q
));
1820 bf_first
->bf_al
= al
;
1821 bf_first
->bf_nframes
= nframes
;
1828 * process pending frames possibly doing a-mpdu aggregation
1829 * NB: must be called with txq lock held
1832 static void ath_tx_sched_aggr(struct ath_softc
*sc
,
1833 struct ath_txq
*txq
, struct ath_atx_tid
*tid
)
1835 struct ath_buf
*bf
, *tbf
, *bf_last
, *bf_lastaggr
= NULL
;
1836 enum ATH_AGGR_STATUS status
;
1837 struct list_head bf_q
;
1838 struct aggr_rifs_param param
= {0, 0, 0, 0, NULL
};
1839 int prev_frames
= 0;
1842 if (list_empty(&tid
->buf_q
))
1845 INIT_LIST_HEAD(&bf_q
);
1847 status
= ath_tx_form_aggr(sc
, tid
, &bf_q
, &bf_lastaggr
, ¶m
,
1851 * no frames picked up to be aggregated; block-ack
1852 * window is not open
1854 if (list_empty(&bf_q
))
1857 bf
= list_first_entry(&bf_q
, struct ath_buf
, list
);
1858 bf_last
= list_entry(bf_q
.prev
, struct ath_buf
, list
);
1859 bf
->bf_lastbf
= bf_last
;
1862 * if only one frame, send as non-aggregate
1864 if (bf
->bf_nframes
== 1) {
1865 ASSERT(bf
->bf_lastfrm
== bf_last
);
1869 * clear aggr bits for every descriptor
1870 * XXX TODO: is there a way to optimize it?
1872 list_for_each_entry(tbf
, &bf_q
, list
) {
1873 ath9k_hw_clr11n_aggr(sc
->sc_ah
, tbf
->bf_desc
);
1876 ath_buf_set_rate(sc
, bf
);
1877 ath_tx_txqaddbuf(sc
, txq
, &bf_q
);
1882 * setup first desc with rate and aggr info
1885 ath_buf_set_rate(sc
, bf
);
1886 ath9k_hw_set11n_aggr_first(sc
->sc_ah
, bf
->bf_desc
, bf
->bf_al
);
1889 * anchor last frame of aggregate correctly
1891 ASSERT(bf_lastaggr
);
1892 ASSERT(bf_lastaggr
->bf_lastfrm
== bf_last
);
1894 ath9k_hw_set11n_aggr_last(sc
->sc_ah
, tbf
->bf_desc
);
1896 /* XXX: We don't enter into this loop, consider removing this */
1897 while (!list_empty(&bf_q
) && !list_is_last(&tbf
->list
, &bf_q
)) {
1898 tbf
= list_entry(tbf
->list
.next
, struct ath_buf
, list
);
1899 ath9k_hw_set11n_aggr_last(sc
->sc_ah
, tbf
->bf_desc
);
1902 txq
->axq_aggr_depth
++;
1905 * Normal aggregate, queue to hardware
1907 ath_tx_txqaddbuf(sc
, txq
, &bf_q
);
1909 } while (txq
->axq_depth
< ATH_AGGR_MIN_QDEPTH
&&
1910 status
!= ATH_AGGR_BAW_CLOSED
);
1913 /* Called with txq lock held */
1915 static void ath_tid_drain(struct ath_softc
*sc
,
1916 struct ath_txq
*txq
,
1917 struct ath_atx_tid
*tid
,
1921 struct list_head bf_head
;
1922 INIT_LIST_HEAD(&bf_head
);
1925 if (list_empty(&tid
->buf_q
))
1927 bf
= list_first_entry(&tid
->buf_q
, struct ath_buf
, list
);
1929 list_cut_position(&bf_head
, &tid
->buf_q
, &bf
->bf_lastfrm
->list
);
1931 /* update baw for software retried frame */
1932 if (bf
->bf_isretried
)
1933 ath_tx_update_baw(sc
, tid
, bf
->bf_seqno
);
1936 * do not indicate packets while holding txq spinlock.
1937 * unlock is intentional here
1939 if (likely(bh_flag
))
1940 spin_unlock_bh(&txq
->axq_lock
);
1942 spin_unlock(&txq
->axq_lock
);
1944 /* complete this sub-frame */
1945 ath_tx_complete_buf(sc
, bf
, &bf_head
, 0, 0);
1947 if (likely(bh_flag
))
1948 spin_lock_bh(&txq
->axq_lock
);
1950 spin_lock(&txq
->axq_lock
);
1954 * TODO: For frame(s) that are in the retry state, we will reuse the
1955 * sequence number(s) without setting the retry bit. The
1956 * alternative is to give up on these and BAR the receiver's window
1959 tid
->seq_next
= tid
->seq_start
;
1960 tid
->baw_tail
= tid
->baw_head
;
1964 * Drain all pending buffers
1965 * NB: must be called with txq lock held
1968 static void ath_txq_drain_pending_buffers(struct ath_softc
*sc
,
1969 struct ath_txq
*txq
,
1972 struct ath_atx_ac
*ac
, *ac_tmp
;
1973 struct ath_atx_tid
*tid
, *tid_tmp
;
1975 list_for_each_entry_safe(ac
, ac_tmp
, &txq
->axq_acq
, list
) {
1976 list_del(&ac
->list
);
1977 ac
->sched
= AH_FALSE
;
1978 list_for_each_entry_safe(tid
, tid_tmp
, &ac
->tid_q
, list
) {
1979 list_del(&tid
->list
);
1980 tid
->sched
= AH_FALSE
;
1981 ath_tid_drain(sc
, txq
, tid
, bh_flag
);
1986 static int ath_tx_start_dma(struct ath_softc
*sc
,
1987 struct sk_buff
*skb
,
1988 struct scatterlist
*sg
,
1990 struct ath_tx_control
*txctl
)
1992 struct ath_node
*an
= txctl
->an
;
1993 struct ath_buf
*bf
= NULL
;
1994 struct list_head bf_head
;
1995 struct ath_desc
*ds
;
1996 struct ath_hal
*ah
= sc
->sc_ah
;
1997 struct ath_txq
*txq
= &sc
->sc_txq
[txctl
->qnum
];
1998 struct ath_tx_info_priv
*tx_info_priv
;
1999 struct ath_rc_series
*rcs
;
2000 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2001 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
2002 __le16 fc
= hdr
->frame_control
;
2004 /* For each sglist entry, allocate an ath_buf for DMA */
2005 INIT_LIST_HEAD(&bf_head
);
2006 spin_lock_bh(&sc
->sc_txbuflock
);
2007 if (unlikely(list_empty(&sc
->sc_txbuf
))) {
2008 spin_unlock_bh(&sc
->sc_txbuflock
);
2012 bf
= list_first_entry(&sc
->sc_txbuf
, struct ath_buf
, list
);
2013 list_del(&bf
->list
);
2014 spin_unlock_bh(&sc
->sc_txbuflock
);
2016 list_add_tail(&bf
->list
, &bf_head
);
2018 /* set up this buffer */
2019 ATH_TXBUF_RESET(bf
);
2020 bf
->bf_frmlen
= txctl
->frmlen
;
2021 bf
->bf_isdata
= ieee80211_is_data(fc
);
2022 bf
->bf_isbar
= ieee80211_is_back_req(fc
);
2023 bf
->bf_ispspoll
= ieee80211_is_pspoll(fc
);
2024 bf
->bf_flags
= txctl
->flags
;
2025 bf
->bf_shpreamble
= sc
->sc_flags
& ATH_PREAMBLE_SHORT
;
2026 bf
->bf_keytype
= txctl
->keytype
;
2027 tx_info_priv
= (struct ath_tx_info_priv
*)tx_info
->driver_data
[0];
2028 rcs
= tx_info_priv
->rcs
;
2029 bf
->bf_rcs
[0] = rcs
[0];
2030 bf
->bf_rcs
[1] = rcs
[1];
2031 bf
->bf_rcs
[2] = rcs
[2];
2032 bf
->bf_rcs
[3] = rcs
[3];
2035 bf
->bf_buf_addr
= sg_dma_address(sg
);
2037 /* setup descriptor */
2040 ds
->ds_data
= bf
->bf_buf_addr
;
2043 * Save the DMA context in the first ath_buf
2045 copy_dma_mem_context(get_dma_mem_context(bf
, bf_dmacontext
),
2046 get_dma_mem_context(txctl
, dmacontext
));
2049 * Formulate first tx descriptor with tx controls.
2051 ath9k_hw_set11n_txdesc(ah
,
2053 bf
->bf_frmlen
, /* frame length */
2054 txctl
->atype
, /* Atheros packet type */
2055 min(txctl
->txpower
, (u_int16_t
)60), /* txpower */
2056 txctl
->keyix
, /* key cache index */
2057 txctl
->keytype
, /* key type */
2058 txctl
->flags
); /* flags */
2059 ath9k_hw_filltxdesc(ah
,
2061 sg_dma_len(sg
), /* segment length */
2062 AH_TRUE
, /* first segment */
2063 (n_sg
== 1) ? AH_TRUE
: AH_FALSE
, /* last segment */
2064 ds
); /* first descriptor */
2067 bf
->bf_lastfrm
= bf
;
2068 bf
->bf_ht
= txctl
->ht
;
2070 spin_lock_bh(&txq
->axq_lock
);
2072 if (txctl
->ht
&& sc
->sc_txaggr
) {
2073 struct ath_atx_tid
*tid
= ATH_AN_2_TID(an
, txctl
->tidno
);
2074 if (ath_aggr_query(sc
, an
, txctl
->tidno
)) {
2076 * Try aggregation if it's a unicast data frame
2077 * and the destination is HT capable.
2079 ath_tx_send_ampdu(sc
, txq
, tid
, &bf_head
, txctl
);
2082 * Send this frame as regular when ADDBA exchange
2083 * is neither complete nor pending.
2085 ath_tx_send_normal(sc
, txq
, tid
, &bf_head
);
2090 ath_buf_set_rate(sc
, bf
);
2092 if (ieee80211_is_back_req(fc
)) {
2093 /* This is required for resuming tid
2094 * during BAR completion */
2095 bf
->bf_tidno
= txctl
->tidno
;
2098 if (is_multicast_ether_addr(hdr
->addr1
)) {
2099 struct ath_vap
*avp
= sc
->sc_vaps
[txctl
->if_id
];
2102 * When servicing one or more stations in power-save
2103 * mode (or) if there is some mcast data waiting on
2104 * mcast queue (to prevent out of order delivery of
2105 * mcast,bcast packets) multicast frames must be
2106 * buffered until after the beacon. We use the private
2107 * mcast queue for that.
2109 /* XXX? more bit in 802.11 frame header */
2110 spin_lock_bh(&avp
->av_mcastq
.axq_lock
);
2111 if (txctl
->ps
|| avp
->av_mcastq
.axq_depth
)
2112 ath_tx_mcastqaddbuf(sc
,
2113 &avp
->av_mcastq
, &bf_head
);
2115 ath_tx_txqaddbuf(sc
, txq
, &bf_head
);
2116 spin_unlock_bh(&avp
->av_mcastq
.axq_lock
);
2118 ath_tx_txqaddbuf(sc
, txq
, &bf_head
);
2120 spin_unlock_bh(&txq
->axq_lock
);
2124 static void xmit_map_sg(struct ath_softc
*sc
,
2125 struct sk_buff
*skb
,
2127 struct ath_tx_control
*txctl
)
2129 struct ath_xmit_status tx_status
;
2130 struct ath_atx_tid
*tid
;
2131 struct scatterlist sg
;
2133 *pa
= pci_map_single(sc
->pdev
, skb
->data
, skb
->len
, PCI_DMA_TODEVICE
);
2135 /* setup S/G list */
2136 memset(&sg
, 0, sizeof(struct scatterlist
));
2137 sg_dma_address(&sg
) = *pa
;
2138 sg_dma_len(&sg
) = skb
->len
;
2140 if (ath_tx_start_dma(sc
, skb
, &sg
, 1, txctl
) != 0) {
2142 * We have to do drop frame here.
2144 pci_unmap_single(sc
->pdev
, *pa
, skb
->len
, PCI_DMA_TODEVICE
);
2146 tx_status
.retries
= 0;
2147 tx_status
.flags
= ATH_TX_ERROR
;
2149 if (txctl
->ht
&& sc
->sc_txaggr
) {
2150 /* Reclaim the seqno. */
2151 tid
= ATH_AN_2_TID((struct ath_node
*)
2152 txctl
->an
, txctl
->tidno
);
2153 DECR(tid
->seq_next
, IEEE80211_SEQ_MAX
);
2155 ath_tx_complete(sc
, skb
, &tx_status
, txctl
->an
);
2159 /* Initialize TX queue and h/w */
2161 int ath_tx_init(struct ath_softc
*sc
, int nbufs
)
2166 spin_lock_init(&sc
->sc_txbuflock
);
2168 /* Setup tx descriptors */
2169 error
= ath_descdma_setup(sc
, &sc
->sc_txdma
, &sc
->sc_txbuf
,
2170 "tx", nbufs
* ATH_FRAG_PER_MSDU
, ATH_TXDESC
);
2172 DPRINTF(sc
, ATH_DEBUG_FATAL
,
2173 "%s: failed to allocate tx descriptors: %d\n",
2178 /* XXX allocate beacon state together with vap */
2179 error
= ath_descdma_setup(sc
, &sc
->sc_bdma
, &sc
->sc_bbuf
,
2180 "beacon", ATH_BCBUF
, 1);
2182 DPRINTF(sc
, ATH_DEBUG_FATAL
,
2183 "%s: failed to allocate "
2184 "beacon descripotrs: %d\n",
2197 /* Reclaim all tx queue resources */
2199 int ath_tx_cleanup(struct ath_softc
*sc
)
2201 /* cleanup beacon descriptors */
2202 if (sc
->sc_bdma
.dd_desc_len
!= 0)
2203 ath_descdma_cleanup(sc
, &sc
->sc_bdma
, &sc
->sc_bbuf
);
2205 /* cleanup tx descriptors */
2206 if (sc
->sc_txdma
.dd_desc_len
!= 0)
2207 ath_descdma_cleanup(sc
, &sc
->sc_txdma
, &sc
->sc_txbuf
);
2212 /* Setup a h/w transmit queue */
2214 struct ath_txq
*ath_txq_setup(struct ath_softc
*sc
, int qtype
, int subtype
)
2216 struct ath_hal
*ah
= sc
->sc_ah
;
2217 struct hal_txq_info qi
;
2220 memzero(&qi
, sizeof(qi
));
2221 qi
.tqi_subtype
= subtype
;
2222 qi
.tqi_aifs
= HAL_TXQ_USEDEFAULT
;
2223 qi
.tqi_cwmin
= HAL_TXQ_USEDEFAULT
;
2224 qi
.tqi_cwmax
= HAL_TXQ_USEDEFAULT
;
2228 * Enable interrupts only for EOL and DESC conditions.
2229 * We mark tx descriptors to receive a DESC interrupt
2230 * when a tx queue gets deep; otherwise waiting for the
2231 * EOL to reap descriptors. Note that this is done to
2232 * reduce interrupt load and this only defers reaping
2233 * descriptors, never transmitting frames. Aside from
2234 * reducing interrupts this also permits more concurrency.
2235 * The only potential downside is if the tx queue backs
2236 * up in which case the top half of the kernel may backup
2237 * due to a lack of tx descriptors.
2239 * The UAPSD queue is an exception, since we take a desc-
2240 * based intr on the EOSP frames.
2242 if (qtype
== HAL_TX_QUEUE_UAPSD
)
2243 qi
.tqi_qflags
= TXQ_FLAG_TXDESCINT_ENABLE
;
2245 qi
.tqi_qflags
= TXQ_FLAG_TXEOLINT_ENABLE
|
2246 TXQ_FLAG_TXDESCINT_ENABLE
;
2247 qnum
= ath9k_hw_setuptxqueue(ah
, qtype
, &qi
);
2250 * NB: don't print a message, this happens
2251 * normally on parts with too few tx queues
2255 if (qnum
>= ARRAY_SIZE(sc
->sc_txq
)) {
2256 DPRINTF(sc
, ATH_DEBUG_FATAL
,
2257 "%s: hal qnum %u out of range, max %u!\n",
2258 __func__
, qnum
, (unsigned int)ARRAY_SIZE(sc
->sc_txq
));
2259 ath9k_hw_releasetxqueue(ah
, qnum
);
2262 if (!ATH_TXQ_SETUP(sc
, qnum
)) {
2263 struct ath_txq
*txq
= &sc
->sc_txq
[qnum
];
2265 txq
->axq_qnum
= qnum
;
2266 txq
->axq_link
= NULL
;
2267 INIT_LIST_HEAD(&txq
->axq_q
);
2268 INIT_LIST_HEAD(&txq
->axq_acq
);
2269 spin_lock_init(&txq
->axq_lock
);
2271 txq
->axq_aggr_depth
= 0;
2272 txq
->axq_totalqueued
= 0;
2273 txq
->axq_intrcnt
= 0;
2274 txq
->axq_linkbuf
= NULL
;
2275 sc
->sc_txqsetup
|= 1<<qnum
;
2277 return &sc
->sc_txq
[qnum
];
2280 /* Reclaim resources for a setup queue */
2282 void ath_tx_cleanupq(struct ath_softc
*sc
, struct ath_txq
*txq
)
2284 ath9k_hw_releasetxqueue(sc
->sc_ah
, txq
->axq_qnum
);
2285 sc
->sc_txqsetup
&= ~(1<<txq
->axq_qnum
);
2289 * Setup a hardware data transmit queue for the specified
2290 * access control. The hal may not support all requested
2291 * queues in which case it will return a reference to a
2292 * previously setup queue. We record the mapping from ac's
2293 * to h/w queues for use by ath_tx_start and also track
2294 * the set of h/w queues being used to optimize work in the
2295 * transmit interrupt handler and related routines.
2298 int ath_tx_setup(struct ath_softc
*sc
, int haltype
)
2300 struct ath_txq
*txq
;
2302 if (haltype
>= ARRAY_SIZE(sc
->sc_haltype2q
)) {
2303 DPRINTF(sc
, ATH_DEBUG_FATAL
,
2304 "%s: HAL AC %u out of range, max %zu!\n",
2305 __func__
, haltype
, ARRAY_SIZE(sc
->sc_haltype2q
));
2308 txq
= ath_txq_setup(sc
, HAL_TX_QUEUE_DATA
, haltype
);
2310 sc
->sc_haltype2q
[haltype
] = txq
->axq_qnum
;
2316 int ath_tx_get_qnum(struct ath_softc
*sc
, int qtype
, int haltype
)
2321 case HAL_TX_QUEUE_DATA
:
2322 if (haltype
>= ARRAY_SIZE(sc
->sc_haltype2q
)) {
2323 DPRINTF(sc
, ATH_DEBUG_FATAL
,
2324 "%s: HAL AC %u out of range, max %zu!\n",
2326 haltype
, ARRAY_SIZE(sc
->sc_haltype2q
));
2329 qnum
= sc
->sc_haltype2q
[haltype
];
2331 case HAL_TX_QUEUE_BEACON
:
2332 qnum
= sc
->sc_bhalq
;
2334 case HAL_TX_QUEUE_CAB
:
2335 qnum
= sc
->sc_cabq
->axq_qnum
;
2343 /* Update parameters for a transmit queue */
2345 int ath_txq_update(struct ath_softc
*sc
, int qnum
, struct hal_txq_info
*qi0
)
2347 struct ath_hal
*ah
= sc
->sc_ah
;
2349 struct hal_txq_info qi
;
2351 if (qnum
== sc
->sc_bhalq
) {
2353 * XXX: for beacon queue, we just save the parameter.
2354 * It will be picked up by ath_beaconq_config when
2357 sc
->sc_beacon_qi
= *qi0
;
2361 ASSERT(sc
->sc_txq
[qnum
].axq_qnum
== qnum
);
2363 ath9k_hw_gettxqueueprops(ah
, qnum
, &qi
);
2364 qi
.tqi_aifs
= qi0
->tqi_aifs
;
2365 qi
.tqi_cwmin
= qi0
->tqi_cwmin
;
2366 qi
.tqi_cwmax
= qi0
->tqi_cwmax
;
2367 qi
.tqi_burstTime
= qi0
->tqi_burstTime
;
2368 qi
.tqi_readyTime
= qi0
->tqi_readyTime
;
2370 if (!ath9k_hw_settxqueueprops(ah
, qnum
, &qi
)) {
2371 DPRINTF(sc
, ATH_DEBUG_FATAL
,
2372 "%s: unable to update hardware queue %u!\n",
2376 ath9k_hw_resettxqueue(ah
, qnum
); /* push to h/w */
2382 int ath_cabq_update(struct ath_softc
*sc
)
2384 struct hal_txq_info qi
;
2385 int qnum
= sc
->sc_cabq
->axq_qnum
;
2386 struct ath_beacon_config conf
;
2388 ath9k_hw_gettxqueueprops(sc
->sc_ah
, qnum
, &qi
);
2390 * Ensure the readytime % is within the bounds.
2392 if (sc
->sc_config
.cabqReadytime
< HAL_READY_TIME_LO_BOUND
)
2393 sc
->sc_config
.cabqReadytime
= HAL_READY_TIME_LO_BOUND
;
2394 else if (sc
->sc_config
.cabqReadytime
> HAL_READY_TIME_HI_BOUND
)
2395 sc
->sc_config
.cabqReadytime
= HAL_READY_TIME_HI_BOUND
;
2397 ath_get_beaconconfig(sc
, ATH_IF_ID_ANY
, &conf
);
2399 (conf
.beacon_interval
* sc
->sc_config
.cabqReadytime
) / 100;
2400 ath_txq_update(sc
, qnum
, &qi
);
2405 int ath_tx_start(struct ath_softc
*sc
, struct sk_buff
*skb
)
2407 struct ath_tx_control txctl
;
2410 error
= ath_tx_prepare(sc
, skb
, &txctl
);
2413 * Start DMA mapping.
2414 * ath_tx_start_dma() will be called either synchronously
2415 * or asynchrounsly once DMA is complete.
2417 xmit_map_sg(sc
, skb
,
2418 get_dma_mem_context(&txctl
, dmacontext
),
2421 ath_node_put(sc
, txctl
.an
, ATH9K_BH_STATUS_CHANGE
);
2423 /* failed packets will be dropped by the caller */
2427 /* Deferred processing of transmit interrupt */
2429 void ath_tx_tasklet(struct ath_softc
*sc
)
2431 u_int64_t tsf
= ath9k_hw_gettsf64(sc
->sc_ah
);
2433 u_int32_t qcumask
= ((1 << HAL_NUM_TX_QUEUES
) - 1);
2435 ath9k_hw_gettxintrtxqs(sc
->sc_ah
, &qcumask
);
2438 * Process each active queue.
2440 for (i
= 0; i
< HAL_NUM_TX_QUEUES
; i
++) {
2441 if (ATH_TXQ_SETUP(sc
, i
) && (qcumask
& (1 << i
)))
2442 nacked
+= ath_tx_processq(sc
, &sc
->sc_txq
[i
]);
2445 sc
->sc_lastrx
= tsf
;
2448 void ath_tx_draintxq(struct ath_softc
*sc
,
2449 struct ath_txq
*txq
, enum hal_bool retry_tx
)
2451 struct ath_buf
*bf
, *lastbf
;
2452 struct list_head bf_head
;
2454 INIT_LIST_HEAD(&bf_head
);
2457 * NB: this assumes output has been stopped and
2458 * we do not need to block ath_tx_tasklet
2461 spin_lock_bh(&txq
->axq_lock
);
2463 if (list_empty(&txq
->axq_q
)) {
2464 txq
->axq_link
= NULL
;
2465 txq
->axq_linkbuf
= NULL
;
2466 spin_unlock_bh(&txq
->axq_lock
);
2470 bf
= list_first_entry(&txq
->axq_q
, struct ath_buf
, list
);
2472 if (bf
->bf_status
& ATH_BUFSTATUS_STALE
) {
2473 list_del(&bf
->list
);
2474 spin_unlock_bh(&txq
->axq_lock
);
2476 spin_lock_bh(&sc
->sc_txbuflock
);
2477 list_add_tail(&bf
->list
, &sc
->sc_txbuf
);
2478 spin_unlock_bh(&sc
->sc_txbuflock
);
2482 lastbf
= bf
->bf_lastbf
;
2484 lastbf
->bf_desc
->ds_txstat
.ts_flags
= HAL_TX_SW_ABORTED
;
2486 /* remove ath_buf's of the same mpdu from txq */
2487 list_cut_position(&bf_head
, &txq
->axq_q
, &lastbf
->list
);
2490 spin_unlock_bh(&txq
->axq_lock
);
2493 ath_tx_complete_aggr_rifs(sc
, txq
, bf
, &bf_head
, 0);
2495 ath_tx_complete_buf(sc
, bf
, &bf_head
, 0, 0);
2498 /* flush any pending frames if aggregation is enabled */
2499 if (sc
->sc_txaggr
) {
2501 spin_lock_bh(&txq
->axq_lock
);
2502 ath_txq_drain_pending_buffers(sc
, txq
,
2503 ATH9K_BH_STATUS_CHANGE
);
2504 spin_unlock_bh(&txq
->axq_lock
);
2509 /* Drain the transmit queues and reclaim resources */
2511 void ath_draintxq(struct ath_softc
*sc
, enum hal_bool retry_tx
)
2513 /* stop beacon queue. The beacon will be freed when
2514 * we go to INIT state */
2515 if (!sc
->sc_invalid
) {
2516 (void) ath9k_hw_stoptxdma(sc
->sc_ah
, sc
->sc_bhalq
);
2517 DPRINTF(sc
, ATH_DEBUG_XMIT
, "%s: beacon queue %x\n", __func__
,
2518 ath9k_hw_gettxbuf(sc
->sc_ah
, sc
->sc_bhalq
));
2521 ath_drain_txdataq(sc
, retry_tx
);
2524 u_int32_t
ath_txq_depth(struct ath_softc
*sc
, int qnum
)
2526 return sc
->sc_txq
[qnum
].axq_depth
;
2529 u_int32_t
ath_txq_aggr_depth(struct ath_softc
*sc
, int qnum
)
2531 return sc
->sc_txq
[qnum
].axq_aggr_depth
;
2534 /* Check if an ADDBA is required. A valid node must be passed. */
2535 enum ATH_AGGR_CHECK
ath_tx_aggr_check(struct ath_softc
*sc
,
2536 struct ath_node
*an
,
2539 struct ath_atx_tid
*txtid
;
2540 DECLARE_MAC_BUF(mac
);
2543 return AGGR_NOT_REQUIRED
;
2545 /* ADDBA exchange must be completed before sending aggregates */
2546 txtid
= ATH_AN_2_TID(an
, tidno
);
2548 if (txtid
->addba_exchangecomplete
)
2549 return AGGR_EXCHANGE_DONE
;
2551 if (txtid
->cleanup_inprogress
)
2552 return AGGR_CLEANUP_PROGRESS
;
2554 if (txtid
->addba_exchangeinprogress
)
2555 return AGGR_EXCHANGE_PROGRESS
;
2557 if (!txtid
->addba_exchangecomplete
) {
2558 if (!txtid
->addba_exchangeinprogress
&&
2559 (txtid
->addba_exchangeattempts
< ADDBA_EXCHANGE_ATTEMPTS
)) {
2560 txtid
->addba_exchangeattempts
++;
2561 return AGGR_REQUIRED
;
2565 return AGGR_NOT_REQUIRED
;
2568 /* Start TX aggregation */
2570 int ath_tx_aggr_start(struct ath_softc
*sc
,
2575 struct ath_atx_tid
*txtid
;
2576 struct ath_node
*an
;
2578 spin_lock_bh(&sc
->node_lock
);
2579 an
= ath_node_find(sc
, (u8
*) addr
);
2580 spin_unlock_bh(&sc
->node_lock
);
2583 DPRINTF(sc
, ATH_DEBUG_AGGR
,
2584 "%s: Node not found to initialize "
2585 "TX aggregation\n", __func__
);
2589 if (sc
->sc_txaggr
) {
2590 txtid
= ATH_AN_2_TID(an
, tid
);
2591 txtid
->addba_exchangeinprogress
= 1;
2592 ath_tx_pause_tid(sc
, txtid
);
2598 /* Stop tx aggregation */
2600 int ath_tx_aggr_stop(struct ath_softc
*sc
,
2604 struct ath_node
*an
;
2606 spin_lock_bh(&sc
->node_lock
);
2607 an
= ath_node_find(sc
, (u8
*) addr
);
2608 spin_unlock_bh(&sc
->node_lock
);
2611 DPRINTF(sc
, ATH_DEBUG_AGGR
,
2612 "%s: TX aggr stop for non-existent node\n", __func__
);
2616 ath_tx_aggr_teardown(sc
, an
, tid
);
2621 * Performs transmit side cleanup when TID changes from aggregated to
2623 * - Pause the TID and mark cleanup in progress
2624 * - Discard all retry frames from the s/w queue.
2627 void ath_tx_aggr_teardown(struct ath_softc
*sc
,
2628 struct ath_node
*an
, u_int8_t tid
)
2630 struct ath_atx_tid
*txtid
= ATH_AN_2_TID(an
, tid
);
2631 struct ath_txq
*txq
= &sc
->sc_txq
[txtid
->ac
->qnum
];
2633 struct list_head bf_head
;
2634 INIT_LIST_HEAD(&bf_head
);
2636 DPRINTF(sc
, ATH_DEBUG_AGGR
, "%s: teardown TX aggregation\n", __func__
);
2638 if (txtid
->cleanup_inprogress
) /* cleanup is in progress */
2641 if (!txtid
->addba_exchangecomplete
) {
2642 txtid
->addba_exchangeattempts
= 0;
2646 /* TID must be paused first */
2647 ath_tx_pause_tid(sc
, txtid
);
2649 /* drop all software retried frames and mark this TID */
2650 spin_lock_bh(&txq
->axq_lock
);
2651 while (!list_empty(&txtid
->buf_q
)) {
2652 bf
= list_first_entry(&txtid
->buf_q
, struct ath_buf
, list
);
2653 if (!bf
->bf_isretried
) {
2655 * NB: it's based on the assumption that
2656 * software retried frame will always stay
2657 * at the head of software queue.
2661 list_cut_position(&bf_head
,
2662 &txtid
->buf_q
, &bf
->bf_lastfrm
->list
);
2663 ath_tx_update_baw(sc
, txtid
, bf
->bf_seqno
);
2665 /* complete this sub-frame */
2666 ath_tx_complete_buf(sc
, bf
, &bf_head
, 0, 0);
2669 if (txtid
->baw_head
!= txtid
->baw_tail
) {
2670 spin_unlock_bh(&txq
->axq_lock
);
2671 txtid
->cleanup_inprogress
= AH_TRUE
;
2673 txtid
->addba_exchangecomplete
= 0;
2674 txtid
->addba_exchangeattempts
= 0;
2675 spin_unlock_bh(&txq
->axq_lock
);
2676 ath_tx_flush_tid(sc
, txtid
);
2681 * Tx scheduling logic
2682 * NB: must be called with txq lock held
2685 void ath_txq_schedule(struct ath_softc
*sc
, struct ath_txq
*txq
)
2687 struct ath_atx_ac
*ac
;
2688 struct ath_atx_tid
*tid
;
2690 /* nothing to schedule */
2691 if (list_empty(&txq
->axq_acq
))
2694 * get the first node/ac pair on the queue
2696 ac
= list_first_entry(&txq
->axq_acq
, struct ath_atx_ac
, list
);
2697 list_del(&ac
->list
);
2698 ac
->sched
= AH_FALSE
;
2701 * process a single tid per destination
2704 /* nothing to schedule */
2705 if (list_empty(&ac
->tid_q
))
2708 tid
= list_first_entry(&ac
->tid_q
, struct ath_atx_tid
, list
);
2709 list_del(&tid
->list
);
2710 tid
->sched
= AH_FALSE
;
2712 if (tid
->paused
) /* check next tid to keep h/w busy */
2715 if (!(tid
->an
->an_smmode
== ATH_SM_PWRSAV_DYNAMIC
) ||
2716 ((txq
->axq_depth
% 2) == 0)) {
2717 ath_tx_sched_aggr(sc
, txq
, tid
);
2721 * add tid to round-robin queue if more frames
2722 * are pending for the tid
2724 if (!list_empty(&tid
->buf_q
))
2725 ath_tx_queue_tid(txq
, tid
);
2727 /* only schedule one TID at a time */
2729 } while (!list_empty(&ac
->tid_q
));
2732 * schedule AC if more TIDs need processing
2734 if (!list_empty(&ac
->tid_q
)) {
2736 * add dest ac to txq if not already added
2738 if (ac
->sched
== AH_FALSE
) {
2739 ac
->sched
= AH_TRUE
;
2740 list_add_tail(&ac
->list
, &txq
->axq_acq
);
2745 /* Initialize per-node transmit state */
2747 void ath_tx_node_init(struct ath_softc
*sc
, struct ath_node
*an
)
2749 if (sc
->sc_txaggr
) {
2750 struct ath_atx_tid
*tid
;
2751 struct ath_atx_ac
*ac
;
2754 sc
->sc_ht_info
.maxampdu
= ATH_AMPDU_LIMIT_DEFAULT
;
2757 * Init per tid tx state
2759 for (tidno
= 0, tid
= &an
->an_aggr
.tx
.tid
[tidno
];
2760 tidno
< WME_NUM_TID
;
2764 tid
->seq_start
= tid
->seq_next
= 0;
2765 tid
->baw_size
= WME_MAX_BA
;
2766 tid
->baw_head
= tid
->baw_tail
= 0;
2767 tid
->sched
= AH_FALSE
;
2768 tid
->paused
= AH_FALSE
;
2769 tid
->cleanup_inprogress
= AH_FALSE
;
2770 INIT_LIST_HEAD(&tid
->buf_q
);
2772 acno
= TID_TO_WME_AC(tidno
);
2773 tid
->ac
= &an
->an_aggr
.tx
.ac
[acno
];
2776 tid
->addba_exchangecomplete
= 0;
2777 tid
->addba_exchangeinprogress
= 0;
2778 tid
->addba_exchangeattempts
= 0;
2782 * Init per ac tx state
2784 for (acno
= 0, ac
= &an
->an_aggr
.tx
.ac
[acno
];
2785 acno
< WME_NUM_AC
; acno
++, ac
++) {
2786 ac
->sched
= AH_FALSE
;
2787 INIT_LIST_HEAD(&ac
->tid_q
);
2791 ac
->qnum
= ath_tx_get_qnum(sc
,
2792 HAL_TX_QUEUE_DATA
, HAL_WME_AC_BE
);
2795 ac
->qnum
= ath_tx_get_qnum(sc
,
2796 HAL_TX_QUEUE_DATA
, HAL_WME_AC_BK
);
2799 ac
->qnum
= ath_tx_get_qnum(sc
,
2800 HAL_TX_QUEUE_DATA
, HAL_WME_AC_VI
);
2803 ac
->qnum
= ath_tx_get_qnum(sc
,
2804 HAL_TX_QUEUE_DATA
, HAL_WME_AC_VO
);
2811 /* Cleanupthe pending buffers for the node. */
2813 void ath_tx_node_cleanup(struct ath_softc
*sc
,
2814 struct ath_node
*an
, bool bh_flag
)
2817 struct ath_atx_ac
*ac
, *ac_tmp
;
2818 struct ath_atx_tid
*tid
, *tid_tmp
;
2819 struct ath_txq
*txq
;
2820 for (i
= 0; i
< HAL_NUM_TX_QUEUES
; i
++) {
2821 if (ATH_TXQ_SETUP(sc
, i
)) {
2822 txq
= &sc
->sc_txq
[i
];
2824 if (likely(bh_flag
))
2825 spin_lock_bh(&txq
->axq_lock
);
2827 spin_lock(&txq
->axq_lock
);
2829 list_for_each_entry_safe(ac
,
2830 ac_tmp
, &txq
->axq_acq
, list
) {
2831 tid
= list_first_entry(&ac
->tid_q
,
2832 struct ath_atx_tid
, list
);
2833 if (tid
&& tid
->an
!= an
)
2835 list_del(&ac
->list
);
2836 ac
->sched
= AH_FALSE
;
2838 list_for_each_entry_safe(tid
,
2839 tid_tmp
, &ac
->tid_q
, list
) {
2840 list_del(&tid
->list
);
2841 tid
->sched
= AH_FALSE
;
2842 ath_tid_drain(sc
, txq
, tid
, bh_flag
);
2843 tid
->addba_exchangecomplete
= 0;
2844 tid
->addba_exchangeattempts
= 0;
2845 tid
->cleanup_inprogress
= AH_FALSE
;
2849 if (likely(bh_flag
))
2850 spin_unlock_bh(&txq
->axq_lock
);
2852 spin_unlock(&txq
->axq_lock
);
2857 /* Cleanup per node transmit state */
2859 void ath_tx_node_free(struct ath_softc
*sc
, struct ath_node
*an
)
2861 if (sc
->sc_txaggr
) {
2862 struct ath_atx_tid
*tid
;
2865 /* Init per tid rx state */
2866 for (tidno
= 0, tid
= &an
->an_aggr
.tx
.tid
[tidno
];
2867 tidno
< WME_NUM_TID
;
2870 for (i
= 0; i
< ATH_TID_MAX_BUFS
; i
++)
2871 ASSERT(tid
->tx_buf
[i
] == NULL
);