2 * Copyright (c) 2008-2011 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.
17 #include <linux/dma-mapping.h>
19 #include "ar9003_mac.h"
21 #define BITS_PER_BYTE 8
22 #define OFDM_PLCP_BITS 22
23 #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
29 #define HT_LTF(_ns) (4 * (_ns))
30 #define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */
31 #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */
32 #define TIME_SYMBOLS(t) ((t) >> 2)
33 #define TIME_SYMBOLS_HALFGI(t) (((t) * 5 - 4) / 18)
34 #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
35 #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
38 static u16 bits_per_symbol
[][2] = {
40 { 26, 54 }, /* 0: BPSK */
41 { 52, 108 }, /* 1: QPSK 1/2 */
42 { 78, 162 }, /* 2: QPSK 3/4 */
43 { 104, 216 }, /* 3: 16-QAM 1/2 */
44 { 156, 324 }, /* 4: 16-QAM 3/4 */
45 { 208, 432 }, /* 5: 64-QAM 2/3 */
46 { 234, 486 }, /* 6: 64-QAM 3/4 */
47 { 260, 540 }, /* 7: 64-QAM 5/6 */
50 #define IS_HT_RATE(_rate) ((_rate) & 0x80)
52 static void ath_tx_send_normal(struct ath_softc
*sc
, struct ath_txq
*txq
,
53 struct ath_atx_tid
*tid
, struct sk_buff
*skb
);
54 static void ath_tx_complete(struct ath_softc
*sc
, struct sk_buff
*skb
,
55 int tx_flags
, struct ath_txq
*txq
);
56 static void ath_tx_complete_buf(struct ath_softc
*sc
, struct ath_buf
*bf
,
57 struct ath_txq
*txq
, struct list_head
*bf_q
,
58 struct ath_tx_status
*ts
, int txok
);
59 static void ath_tx_txqaddbuf(struct ath_softc
*sc
, struct ath_txq
*txq
,
60 struct list_head
*head
, bool internal
);
61 static void ath_tx_rc_status(struct ath_softc
*sc
, struct ath_buf
*bf
,
62 struct ath_tx_status
*ts
, int nframes
, int nbad
,
64 static void ath_tx_update_baw(struct ath_softc
*sc
, struct ath_atx_tid
*tid
,
66 static struct ath_buf
*ath_tx_setup_buffer(struct ath_softc
*sc
,
68 struct ath_atx_tid
*tid
,
78 /*********************/
79 /* Aggregation logic */
80 /*********************/
82 void ath_txq_lock(struct ath_softc
*sc
, struct ath_txq
*txq
)
83 __acquires(&txq
->axq_lock
)
85 spin_lock_bh(&txq
->axq_lock
);
88 void ath_txq_unlock(struct ath_softc
*sc
, struct ath_txq
*txq
)
89 __releases(&txq
->axq_lock
)
91 spin_unlock_bh(&txq
->axq_lock
);
94 void ath_txq_unlock_complete(struct ath_softc
*sc
, struct ath_txq
*txq
)
95 __releases(&txq
->axq_lock
)
97 struct sk_buff_head q
;
100 __skb_queue_head_init(&q
);
101 skb_queue_splice_init(&txq
->complete_q
, &q
);
102 spin_unlock_bh(&txq
->axq_lock
);
104 while ((skb
= __skb_dequeue(&q
)))
105 ieee80211_tx_status(sc
->hw
, skb
);
108 static void ath_tx_queue_tid(struct ath_txq
*txq
, struct ath_atx_tid
*tid
)
110 struct ath_atx_ac
*ac
= tid
->ac
;
119 list_add_tail(&tid
->list
, &ac
->tid_q
);
125 list_add_tail(&ac
->list
, &txq
->axq_acq
);
128 static void ath_tx_resume_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
)
130 struct ath_txq
*txq
= tid
->ac
->txq
;
132 WARN_ON(!tid
->paused
);
134 ath_txq_lock(sc
, txq
);
137 if (skb_queue_empty(&tid
->buf_q
))
140 ath_tx_queue_tid(txq
, tid
);
141 ath_txq_schedule(sc
, txq
);
143 ath_txq_unlock_complete(sc
, txq
);
146 static struct ath_frame_info
*get_frame_info(struct sk_buff
*skb
)
148 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
149 BUILD_BUG_ON(sizeof(struct ath_frame_info
) >
150 sizeof(tx_info
->rate_driver_data
));
151 return (struct ath_frame_info
*) &tx_info
->rate_driver_data
[0];
154 static void ath_send_bar(struct ath_atx_tid
*tid
, u16 seqno
)
156 ieee80211_send_bar(tid
->an
->vif
, tid
->an
->sta
->addr
, tid
->tidno
,
157 seqno
<< IEEE80211_SEQ_SEQ_SHIFT
);
160 static void ath_set_rates(struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
163 ieee80211_get_tx_rates(vif
, sta
, bf
->bf_mpdu
, bf
->rates
,
164 ARRAY_SIZE(bf
->rates
));
167 static void ath_tx_clear_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
)
169 tid
->state
&= ~AGGR_ADDBA_COMPLETE
;
170 tid
->state
&= ~AGGR_CLEANUP
;
174 ieee80211_start_tx_ba_cb_irqsafe(tid
->an
->vif
, tid
->an
->sta
->addr
,
176 tid
->stop_cb
= false;
179 static void ath_tx_flush_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
,
182 struct ath_txq
*txq
= tid
->ac
->txq
;
185 struct list_head bf_head
;
186 struct ath_tx_status ts
;
187 struct ath_frame_info
*fi
;
188 bool sendbar
= false;
190 INIT_LIST_HEAD(&bf_head
);
192 memset(&ts
, 0, sizeof(ts
));
194 while ((skb
= __skb_dequeue(&tid
->buf_q
))) {
195 fi
= get_frame_info(skb
);
197 if (!bf
&& !flush_packets
)
198 bf
= ath_tx_setup_buffer(sc
, txq
, tid
, skb
);
201 ieee80211_free_txskb(sc
->hw
, skb
);
205 if (fi
->retries
|| flush_packets
) {
206 list_add_tail(&bf
->list
, &bf_head
);
207 ath_tx_update_baw(sc
, tid
, bf
->bf_state
.seqno
);
208 ath_tx_complete_buf(sc
, bf
, txq
, &bf_head
, &ts
, 0);
211 ath_set_rates(tid
->an
->vif
, tid
->an
->sta
, bf
);
212 ath_tx_send_normal(sc
, txq
, NULL
, skb
);
216 if (tid
->baw_head
== tid
->baw_tail
)
217 ath_tx_clear_tid(sc
, tid
);
219 if (sendbar
&& !flush_packets
) {
220 ath_txq_unlock(sc
, txq
);
221 ath_send_bar(tid
, tid
->seq_start
);
222 ath_txq_lock(sc
, txq
);
226 static void ath_tx_update_baw(struct ath_softc
*sc
, struct ath_atx_tid
*tid
,
231 index
= ATH_BA_INDEX(tid
->seq_start
, seqno
);
232 cindex
= (tid
->baw_head
+ index
) & (ATH_TID_MAX_BUFS
- 1);
234 __clear_bit(cindex
, tid
->tx_buf
);
236 while (tid
->baw_head
!= tid
->baw_tail
&& !test_bit(tid
->baw_head
, tid
->tx_buf
)) {
237 INCR(tid
->seq_start
, IEEE80211_SEQ_MAX
);
238 INCR(tid
->baw_head
, ATH_TID_MAX_BUFS
);
239 if (tid
->bar_index
>= 0)
244 static void ath_tx_addto_baw(struct ath_softc
*sc
, struct ath_atx_tid
*tid
,
249 index
= ATH_BA_INDEX(tid
->seq_start
, seqno
);
250 cindex
= (tid
->baw_head
+ index
) & (ATH_TID_MAX_BUFS
- 1);
251 __set_bit(cindex
, tid
->tx_buf
);
253 if (index
>= ((tid
->baw_tail
- tid
->baw_head
) &
254 (ATH_TID_MAX_BUFS
- 1))) {
255 tid
->baw_tail
= cindex
;
256 INCR(tid
->baw_tail
, ATH_TID_MAX_BUFS
);
261 * TODO: For frame(s) that are in the retry state, we will reuse the
262 * sequence number(s) without setting the retry bit. The
263 * alternative is to give up on these and BAR the receiver's window
266 static void ath_tid_drain(struct ath_softc
*sc
, struct ath_txq
*txq
,
267 struct ath_atx_tid
*tid
)
272 struct list_head bf_head
;
273 struct ath_tx_status ts
;
274 struct ath_frame_info
*fi
;
276 memset(&ts
, 0, sizeof(ts
));
277 INIT_LIST_HEAD(&bf_head
);
279 while ((skb
= __skb_dequeue(&tid
->buf_q
))) {
280 fi
= get_frame_info(skb
);
284 ath_tx_complete(sc
, skb
, ATH_TX_ERROR
, txq
);
288 list_add_tail(&bf
->list
, &bf_head
);
291 ath_tx_update_baw(sc
, tid
, bf
->bf_state
.seqno
);
293 ath_tx_complete_buf(sc
, bf
, txq
, &bf_head
, &ts
, 0);
296 tid
->seq_next
= tid
->seq_start
;
297 tid
->baw_tail
= tid
->baw_head
;
301 static void ath_tx_set_retry(struct ath_softc
*sc
, struct ath_txq
*txq
,
302 struct sk_buff
*skb
, int count
)
304 struct ath_frame_info
*fi
= get_frame_info(skb
);
305 struct ath_buf
*bf
= fi
->bf
;
306 struct ieee80211_hdr
*hdr
;
307 int prev
= fi
->retries
;
309 TX_STAT_INC(txq
->axq_qnum
, a_retries
);
310 fi
->retries
+= count
;
315 hdr
= (struct ieee80211_hdr
*)skb
->data
;
316 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_RETRY
);
317 dma_sync_single_for_device(sc
->dev
, bf
->bf_buf_addr
,
318 sizeof(*hdr
), DMA_TO_DEVICE
);
321 static struct ath_buf
*ath_tx_get_buffer(struct ath_softc
*sc
)
323 struct ath_buf
*bf
= NULL
;
325 spin_lock_bh(&sc
->tx
.txbuflock
);
327 if (unlikely(list_empty(&sc
->tx
.txbuf
))) {
328 spin_unlock_bh(&sc
->tx
.txbuflock
);
332 bf
= list_first_entry(&sc
->tx
.txbuf
, struct ath_buf
, list
);
335 spin_unlock_bh(&sc
->tx
.txbuflock
);
340 static void ath_tx_return_buffer(struct ath_softc
*sc
, struct ath_buf
*bf
)
342 spin_lock_bh(&sc
->tx
.txbuflock
);
343 list_add_tail(&bf
->list
, &sc
->tx
.txbuf
);
344 spin_unlock_bh(&sc
->tx
.txbuflock
);
347 static struct ath_buf
* ath_clone_txbuf(struct ath_softc
*sc
, struct ath_buf
*bf
)
351 tbf
= ath_tx_get_buffer(sc
);
355 ATH_TXBUF_RESET(tbf
);
357 tbf
->bf_mpdu
= bf
->bf_mpdu
;
358 tbf
->bf_buf_addr
= bf
->bf_buf_addr
;
359 memcpy(tbf
->bf_desc
, bf
->bf_desc
, sc
->sc_ah
->caps
.tx_desc_len
);
360 tbf
->bf_state
= bf
->bf_state
;
365 static void ath_tx_count_frames(struct ath_softc
*sc
, struct ath_buf
*bf
,
366 struct ath_tx_status
*ts
, int txok
,
367 int *nframes
, int *nbad
)
369 struct ath_frame_info
*fi
;
371 u32 ba
[WME_BA_BMP_SIZE
>> 5];
378 isaggr
= bf_isaggr(bf
);
380 seq_st
= ts
->ts_seqnum
;
381 memcpy(ba
, &ts
->ba_low
, WME_BA_BMP_SIZE
>> 3);
385 fi
= get_frame_info(bf
->bf_mpdu
);
386 ba_index
= ATH_BA_INDEX(seq_st
, bf
->bf_state
.seqno
);
389 if (!txok
|| (isaggr
&& !ATH_BA_ISSET(ba
, ba_index
)))
397 static void ath_tx_complete_aggr(struct ath_softc
*sc
, struct ath_txq
*txq
,
398 struct ath_buf
*bf
, struct list_head
*bf_q
,
399 struct ath_tx_status
*ts
, int txok
)
401 struct ath_node
*an
= NULL
;
403 struct ieee80211_sta
*sta
;
404 struct ieee80211_hw
*hw
= sc
->hw
;
405 struct ieee80211_hdr
*hdr
;
406 struct ieee80211_tx_info
*tx_info
;
407 struct ath_atx_tid
*tid
= NULL
;
408 struct ath_buf
*bf_next
, *bf_last
= bf
->bf_lastbf
;
409 struct list_head bf_head
;
410 struct sk_buff_head bf_pending
;
411 u16 seq_st
= 0, acked_cnt
= 0, txfail_cnt
= 0, seq_first
;
412 u32 ba
[WME_BA_BMP_SIZE
>> 5];
413 int isaggr
, txfail
, txpending
, sendbar
= 0, needreset
= 0, nbad
= 0;
414 bool rc_update
= true, isba
;
415 struct ieee80211_tx_rate rates
[4];
416 struct ath_frame_info
*fi
;
419 bool flush
= !!(ts
->ts_status
& ATH9K_TX_FLUSH
);
424 hdr
= (struct ieee80211_hdr
*)skb
->data
;
426 tx_info
= IEEE80211_SKB_CB(skb
);
428 memcpy(rates
, bf
->rates
, sizeof(rates
));
430 retries
= ts
->ts_longretry
+ 1;
431 for (i
= 0; i
< ts
->ts_rateindex
; i
++)
432 retries
+= rates
[i
].count
;
436 sta
= ieee80211_find_sta_by_ifaddr(hw
, hdr
->addr1
, hdr
->addr2
);
440 INIT_LIST_HEAD(&bf_head
);
442 bf_next
= bf
->bf_next
;
444 if (!bf
->bf_stale
|| bf_next
!= NULL
)
445 list_move_tail(&bf
->list
, &bf_head
);
447 ath_tx_complete_buf(sc
, bf
, txq
, &bf_head
, ts
, 0);
454 an
= (struct ath_node
*)sta
->drv_priv
;
455 tidno
= ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
456 tid
= ATH_AN_2_TID(an
, tidno
);
457 seq_first
= tid
->seq_start
;
458 isba
= ts
->ts_flags
& ATH9K_TX_BA
;
461 * The hardware occasionally sends a tx status for the wrong TID.
462 * In this case, the BA status cannot be considered valid and all
463 * subframes need to be retransmitted
465 * Only BlockAcks have a TID and therefore normal Acks cannot be
468 if (isba
&& tidno
!= ts
->tid
)
471 isaggr
= bf_isaggr(bf
);
472 memset(ba
, 0, WME_BA_BMP_SIZE
>> 3);
474 if (isaggr
&& txok
) {
475 if (ts
->ts_flags
& ATH9K_TX_BA
) {
476 seq_st
= ts
->ts_seqnum
;
477 memcpy(ba
, &ts
->ba_low
, WME_BA_BMP_SIZE
>> 3);
480 * AR5416 can become deaf/mute when BA
481 * issue happens. Chip needs to be reset.
482 * But AP code may have sychronization issues
483 * when perform internal reset in this routine.
484 * Only enable reset in STA mode for now.
486 if (sc
->sc_ah
->opmode
== NL80211_IFTYPE_STATION
)
491 __skb_queue_head_init(&bf_pending
);
493 ath_tx_count_frames(sc
, bf
, ts
, txok
, &nframes
, &nbad
);
495 u16 seqno
= bf
->bf_state
.seqno
;
497 txfail
= txpending
= sendbar
= 0;
498 bf_next
= bf
->bf_next
;
501 tx_info
= IEEE80211_SKB_CB(skb
);
502 fi
= get_frame_info(skb
);
504 if (ATH_BA_ISSET(ba
, ATH_BA_INDEX(seq_st
, seqno
))) {
505 /* transmit completion, subframe is
506 * acked by block ack */
508 } else if (!isaggr
&& txok
) {
509 /* transmit completion */
511 } else if (tid
->state
& AGGR_CLEANUP
) {
513 * cleanup in progress, just fail
514 * the un-acked sub-frames
519 } else if (fi
->retries
< ATH_MAX_SW_RETRIES
) {
520 if (txok
|| !an
->sleeping
)
521 ath_tx_set_retry(sc
, txq
, bf
->bf_mpdu
,
528 bar_index
= max_t(int, bar_index
,
529 ATH_BA_INDEX(seq_first
, seqno
));
533 * Make sure the last desc is reclaimed if it
534 * not a holding desc.
536 INIT_LIST_HEAD(&bf_head
);
537 if (bf_next
!= NULL
|| !bf_last
->bf_stale
)
538 list_move_tail(&bf
->list
, &bf_head
);
540 if (!txpending
|| (tid
->state
& AGGR_CLEANUP
)) {
542 * complete the acked-ones/xretried ones; update
545 ath_tx_update_baw(sc
, tid
, seqno
);
547 if (rc_update
&& (acked_cnt
== 1 || txfail_cnt
== 1)) {
548 memcpy(tx_info
->control
.rates
, rates
, sizeof(rates
));
549 ath_tx_rc_status(sc
, bf
, ts
, nframes
, nbad
, txok
);
553 ath_tx_complete_buf(sc
, bf
, txq
, &bf_head
, ts
,
556 /* retry the un-acked ones */
557 if (bf
->bf_next
== NULL
&& bf_last
->bf_stale
) {
560 tbf
= ath_clone_txbuf(sc
, bf_last
);
562 * Update tx baw and complete the
563 * frame with failed status if we
567 ath_tx_update_baw(sc
, tid
, seqno
);
569 ath_tx_complete_buf(sc
, bf
, txq
,
571 bar_index
= max_t(int, bar_index
,
572 ATH_BA_INDEX(seq_first
, seqno
));
580 * Put this buffer to the temporary pending
581 * queue to retain ordering
583 __skb_queue_tail(&bf_pending
, skb
);
589 /* prepend un-acked frames to the beginning of the pending frame queue */
590 if (!skb_queue_empty(&bf_pending
)) {
592 ieee80211_sta_set_buffered(sta
, tid
->tidno
, true);
594 skb_queue_splice(&bf_pending
, &tid
->buf_q
);
596 ath_tx_queue_tid(txq
, tid
);
598 if (ts
->ts_status
& (ATH9K_TXERR_FILT
| ATH9K_TXERR_XRETRY
))
599 tid
->ac
->clear_ps_filter
= true;
603 if (bar_index
>= 0) {
604 u16 bar_seq
= ATH_BA_INDEX2SEQ(seq_first
, bar_index
);
606 if (BAW_WITHIN(tid
->seq_start
, tid
->baw_size
, bar_seq
))
607 tid
->bar_index
= ATH_BA_INDEX(tid
->seq_start
, bar_seq
);
609 ath_txq_unlock(sc
, txq
);
610 ath_send_bar(tid
, ATH_BA_INDEX2SEQ(seq_first
, bar_index
+ 1));
611 ath_txq_lock(sc
, txq
);
614 if (tid
->state
& AGGR_CLEANUP
)
615 ath_tx_flush_tid(sc
, tid
, false);
620 ath9k_queue_reset(sc
, RESET_TYPE_TX_ERROR
);
623 static bool bf_is_ampdu_not_probing(struct ath_buf
*bf
)
625 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(bf
->bf_mpdu
);
626 return bf_isampdu(bf
) && !(info
->flags
& IEEE80211_TX_CTL_RATE_CTRL_PROBE
);
629 static void ath_tx_process_buffer(struct ath_softc
*sc
, struct ath_txq
*txq
,
630 struct ath_tx_status
*ts
, struct ath_buf
*bf
,
631 struct list_head
*bf_head
)
635 txok
= !(ts
->ts_status
& ATH9K_TXERR_MASK
);
636 flush
= !!(ts
->ts_status
& ATH9K_TX_FLUSH
);
637 txq
->axq_tx_inprogress
= false;
640 if (bf_is_ampdu_not_probing(bf
))
641 txq
->axq_ampdu_depth
--;
643 if (!bf_isampdu(bf
)) {
645 ath_tx_rc_status(sc
, bf
, ts
, 1, txok
? 0 : 1, txok
);
646 ath_tx_complete_buf(sc
, bf
, txq
, bf_head
, ts
, txok
);
648 ath_tx_complete_aggr(sc
, txq
, bf
, bf_head
, ts
, txok
);
650 if ((sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
) && !flush
)
651 ath_txq_schedule(sc
, txq
);
654 static bool ath_lookup_legacy(struct ath_buf
*bf
)
657 struct ieee80211_tx_info
*tx_info
;
658 struct ieee80211_tx_rate
*rates
;
662 tx_info
= IEEE80211_SKB_CB(skb
);
663 rates
= tx_info
->control
.rates
;
665 for (i
= 0; i
< 4; i
++) {
666 if (!rates
[i
].count
|| rates
[i
].idx
< 0)
669 if (!(rates
[i
].flags
& IEEE80211_TX_RC_MCS
))
676 static u32
ath_lookup_rate(struct ath_softc
*sc
, struct ath_buf
*bf
,
677 struct ath_atx_tid
*tid
)
680 struct ieee80211_tx_info
*tx_info
;
681 struct ieee80211_tx_rate
*rates
;
682 u32 max_4ms_framelen
, frmlen
;
683 u16 aggr_limit
, bt_aggr_limit
, legacy
= 0;
684 int q
= tid
->ac
->txq
->mac80211_qnum
;
688 tx_info
= IEEE80211_SKB_CB(skb
);
689 rates
= tx_info
->control
.rates
;
692 * Find the lowest frame length among the rate series that will have a
693 * 4ms (or TXOP limited) transmit duration.
695 max_4ms_framelen
= ATH_AMPDU_LIMIT_MAX
;
697 for (i
= 0; i
< 4; i
++) {
703 if (!(rates
[i
].flags
& IEEE80211_TX_RC_MCS
)) {
708 if (rates
[i
].flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
713 if (rates
[i
].flags
& IEEE80211_TX_RC_SHORT_GI
)
716 frmlen
= sc
->tx
.max_aggr_framelen
[q
][modeidx
][rates
[i
].idx
];
717 max_4ms_framelen
= min(max_4ms_framelen
, frmlen
);
721 * limit aggregate size by the minimum rate if rate selected is
722 * not a probe rate, if rate selected is a probe rate then
723 * avoid aggregation of this packet.
725 if (tx_info
->flags
& IEEE80211_TX_CTL_RATE_CTRL_PROBE
|| legacy
)
728 aggr_limit
= min(max_4ms_framelen
, (u32
)ATH_AMPDU_LIMIT_MAX
);
731 * Override the default aggregation limit for BTCOEX.
733 bt_aggr_limit
= ath9k_btcoex_aggr_limit(sc
, max_4ms_framelen
);
735 aggr_limit
= bt_aggr_limit
;
738 * h/w can accept aggregates up to 16 bit lengths (65535).
739 * The IE, however can hold up to 65536, which shows up here
740 * as zero. Ignore 65536 since we are constrained by hw.
742 if (tid
->an
->maxampdu
)
743 aggr_limit
= min(aggr_limit
, tid
->an
->maxampdu
);
749 * Returns the number of delimiters to be added to
750 * meet the minimum required mpdudensity.
752 static int ath_compute_num_delims(struct ath_softc
*sc
, struct ath_atx_tid
*tid
,
753 struct ath_buf
*bf
, u16 frmlen
,
756 #define FIRST_DESC_NDELIMS 60
757 u32 nsymbits
, nsymbols
;
760 int width
, streams
, half_gi
, ndelim
, mindelim
;
761 struct ath_frame_info
*fi
= get_frame_info(bf
->bf_mpdu
);
763 /* Select standard number of delimiters based on frame length alone */
764 ndelim
= ATH_AGGR_GET_NDELIM(frmlen
);
767 * If encryption enabled, hardware requires some more padding between
769 * TODO - this could be improved to be dependent on the rate.
770 * The hardware can keep up at lower rates, but not higher rates
772 if ((fi
->keyix
!= ATH9K_TXKEYIX_INVALID
) &&
773 !(sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
))
774 ndelim
+= ATH_AGGR_ENCRYPTDELIM
;
777 * Add delimiter when using RTS/CTS with aggregation
778 * and non enterprise AR9003 card
780 if (first_subfrm
&& !AR_SREV_9580_10_OR_LATER(sc
->sc_ah
) &&
781 (sc
->sc_ah
->ent_mode
& AR_ENT_OTP_MIN_PKT_SIZE_DISABLE
))
782 ndelim
= max(ndelim
, FIRST_DESC_NDELIMS
);
785 * Convert desired mpdu density from microeconds to bytes based
786 * on highest rate in rate series (i.e. first rate) to determine
787 * required minimum length for subframe. Take into account
788 * whether high rate is 20 or 40Mhz and half or full GI.
790 * If there is no mpdu density restriction, no further calculation
794 if (tid
->an
->mpdudensity
== 0)
797 rix
= bf
->rates
[0].idx
;
798 flags
= bf
->rates
[0].flags
;
799 width
= (flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
) ? 1 : 0;
800 half_gi
= (flags
& IEEE80211_TX_RC_SHORT_GI
) ? 1 : 0;
803 nsymbols
= NUM_SYMBOLS_PER_USEC_HALFGI(tid
->an
->mpdudensity
);
805 nsymbols
= NUM_SYMBOLS_PER_USEC(tid
->an
->mpdudensity
);
810 streams
= HT_RC_2_STREAMS(rix
);
811 nsymbits
= bits_per_symbol
[rix
% 8][width
] * streams
;
812 minlen
= (nsymbols
* nsymbits
) / BITS_PER_BYTE
;
814 if (frmlen
< minlen
) {
815 mindelim
= (minlen
- frmlen
) / ATH_AGGR_DELIM_SZ
;
816 ndelim
= max(mindelim
, ndelim
);
822 static enum ATH_AGGR_STATUS
ath_tx_form_aggr(struct ath_softc
*sc
,
824 struct ath_atx_tid
*tid
,
825 struct list_head
*bf_q
,
828 #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
829 struct ath_buf
*bf
, *bf_first
= NULL
, *bf_prev
= NULL
;
830 int rl
= 0, nframes
= 0, ndelim
, prev_al
= 0;
831 u16 aggr_limit
= 0, al
= 0, bpad
= 0,
832 al_delta
, h_baw
= tid
->baw_size
/ 2;
833 enum ATH_AGGR_STATUS status
= ATH_AGGR_DONE
;
834 struct ieee80211_tx_info
*tx_info
;
835 struct ath_frame_info
*fi
;
840 skb
= skb_peek(&tid
->buf_q
);
841 fi
= get_frame_info(skb
);
844 bf
= ath_tx_setup_buffer(sc
, txq
, tid
, skb
);
847 __skb_unlink(skb
, &tid
->buf_q
);
848 ieee80211_free_txskb(sc
->hw
, skb
);
852 bf
->bf_state
.bf_type
= BUF_AMPDU
| BUF_AGGR
;
853 seqno
= bf
->bf_state
.seqno
;
855 /* do not step over block-ack window */
856 if (!BAW_WITHIN(tid
->seq_start
, tid
->baw_size
, seqno
)) {
857 status
= ATH_AGGR_BAW_CLOSED
;
861 if (tid
->bar_index
> ATH_BA_INDEX(tid
->seq_start
, seqno
)) {
862 struct ath_tx_status ts
= {};
863 struct list_head bf_head
;
865 INIT_LIST_HEAD(&bf_head
);
866 list_add(&bf
->list
, &bf_head
);
867 __skb_unlink(skb
, &tid
->buf_q
);
868 ath_tx_update_baw(sc
, tid
, seqno
);
869 ath_tx_complete_buf(sc
, bf
, txq
, &bf_head
, &ts
, 0);
877 ath_set_rates(tid
->an
->vif
, tid
->an
->sta
, bf
);
878 aggr_limit
= ath_lookup_rate(sc
, bf
, tid
);
882 /* do not exceed aggregation limit */
883 al_delta
= ATH_AGGR_DELIM_SZ
+ fi
->framelen
;
886 ((aggr_limit
< (al
+ bpad
+ al_delta
+ prev_al
)) ||
887 ath_lookup_legacy(bf
))) {
888 status
= ATH_AGGR_LIMITED
;
892 tx_info
= IEEE80211_SKB_CB(bf
->bf_mpdu
);
893 if (nframes
&& (tx_info
->flags
& IEEE80211_TX_CTL_RATE_CTRL_PROBE
))
896 /* do not exceed subframe limit */
897 if (nframes
>= min((int)h_baw
, ATH_AMPDU_SUBFRAME_DEFAULT
)) {
898 status
= ATH_AGGR_LIMITED
;
902 /* add padding for previous frame to aggregation length */
903 al
+= bpad
+ al_delta
;
906 * Get the delimiters needed to meet the MPDU
907 * density for this node.
909 ndelim
= ath_compute_num_delims(sc
, tid
, bf_first
, fi
->framelen
,
911 bpad
= PADBYTES(al_delta
) + (ndelim
<< 2);
916 /* link buffers of this frame to the aggregate */
918 ath_tx_addto_baw(sc
, tid
, seqno
);
919 bf
->bf_state
.ndelim
= ndelim
;
921 __skb_unlink(skb
, &tid
->buf_q
);
922 list_add_tail(&bf
->list
, bf_q
);
924 bf_prev
->bf_next
= bf
;
928 } while (!skb_queue_empty(&tid
->buf_q
));
938 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
939 * width - 0 for 20 MHz, 1 for 40 MHz
940 * half_gi - to use 4us v/s 3.6 us for symbol time
942 static u32
ath_pkt_duration(struct ath_softc
*sc
, u8 rix
, int pktlen
,
943 int width
, int half_gi
, bool shortPreamble
)
945 u32 nbits
, nsymbits
, duration
, nsymbols
;
948 /* find number of symbols: PLCP + data */
949 streams
= HT_RC_2_STREAMS(rix
);
950 nbits
= (pktlen
<< 3) + OFDM_PLCP_BITS
;
951 nsymbits
= bits_per_symbol
[rix
% 8][width
] * streams
;
952 nsymbols
= (nbits
+ nsymbits
- 1) / nsymbits
;
955 duration
= SYMBOL_TIME(nsymbols
);
957 duration
= SYMBOL_TIME_HALFGI(nsymbols
);
959 /* addup duration for legacy/ht training and signal fields */
960 duration
+= L_STF
+ L_LTF
+ L_SIG
+ HT_SIG
+ HT_STF
+ HT_LTF(streams
);
965 static int ath_max_framelen(int usec
, int mcs
, bool ht40
, bool sgi
)
967 int streams
= HT_RC_2_STREAMS(mcs
);
971 symbols
= sgi
? TIME_SYMBOLS_HALFGI(usec
) : TIME_SYMBOLS(usec
);
972 bits
= symbols
* bits_per_symbol
[mcs
% 8][ht40
] * streams
;
973 bits
-= OFDM_PLCP_BITS
;
975 bytes
-= L_STF
+ L_LTF
+ L_SIG
+ HT_SIG
+ HT_STF
+ HT_LTF(streams
);
982 void ath_update_max_aggr_framelen(struct ath_softc
*sc
, int queue
, int txop
)
984 u16
*cur_ht20
, *cur_ht20_sgi
, *cur_ht40
, *cur_ht40_sgi
;
987 /* 4ms is the default (and maximum) duration */
988 if (!txop
|| txop
> 4096)
991 cur_ht20
= sc
->tx
.max_aggr_framelen
[queue
][MCS_HT20
];
992 cur_ht20_sgi
= sc
->tx
.max_aggr_framelen
[queue
][MCS_HT20_SGI
];
993 cur_ht40
= sc
->tx
.max_aggr_framelen
[queue
][MCS_HT40
];
994 cur_ht40_sgi
= sc
->tx
.max_aggr_framelen
[queue
][MCS_HT40_SGI
];
995 for (mcs
= 0; mcs
< 32; mcs
++) {
996 cur_ht20
[mcs
] = ath_max_framelen(txop
, mcs
, false, false);
997 cur_ht20_sgi
[mcs
] = ath_max_framelen(txop
, mcs
, false, true);
998 cur_ht40
[mcs
] = ath_max_framelen(txop
, mcs
, true, false);
999 cur_ht40_sgi
[mcs
] = ath_max_framelen(txop
, mcs
, true, true);
1003 static void ath_buf_set_rate(struct ath_softc
*sc
, struct ath_buf
*bf
,
1004 struct ath_tx_info
*info
, int len
)
1006 struct ath_hw
*ah
= sc
->sc_ah
;
1007 struct sk_buff
*skb
;
1008 struct ieee80211_tx_info
*tx_info
;
1009 struct ieee80211_tx_rate
*rates
;
1010 const struct ieee80211_rate
*rate
;
1011 struct ieee80211_hdr
*hdr
;
1012 struct ath_frame_info
*fi
= get_frame_info(bf
->bf_mpdu
);
1017 tx_info
= IEEE80211_SKB_CB(skb
);
1019 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1021 /* set dur_update_en for l-sig computation except for PS-Poll frames */
1022 info
->dur_update
= !ieee80211_is_pspoll(hdr
->frame_control
);
1023 info
->rtscts_rate
= fi
->rtscts_rate
;
1025 for (i
= 0; i
< ARRAY_SIZE(bf
->rates
); i
++) {
1026 bool is_40
, is_sgi
, is_sp
;
1029 if (!rates
[i
].count
|| (rates
[i
].idx
< 0))
1033 info
->rates
[i
].Tries
= rates
[i
].count
;
1035 if (rates
[i
].flags
& IEEE80211_TX_RC_USE_RTS_CTS
) {
1036 info
->rates
[i
].RateFlags
|= ATH9K_RATESERIES_RTS_CTS
;
1037 info
->flags
|= ATH9K_TXDESC_RTSENA
;
1038 } else if (rates
[i
].flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
1039 info
->rates
[i
].RateFlags
|= ATH9K_RATESERIES_RTS_CTS
;
1040 info
->flags
|= ATH9K_TXDESC_CTSENA
;
1043 if (rates
[i
].flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
1044 info
->rates
[i
].RateFlags
|= ATH9K_RATESERIES_2040
;
1045 if (rates
[i
].flags
& IEEE80211_TX_RC_SHORT_GI
)
1046 info
->rates
[i
].RateFlags
|= ATH9K_RATESERIES_HALFGI
;
1048 is_sgi
= !!(rates
[i
].flags
& IEEE80211_TX_RC_SHORT_GI
);
1049 is_40
= !!(rates
[i
].flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
);
1050 is_sp
= !!(rates
[i
].flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
);
1052 if (rates
[i
].flags
& IEEE80211_TX_RC_MCS
) {
1054 info
->rates
[i
].Rate
= rix
| 0x80;
1055 info
->rates
[i
].ChSel
= ath_txchainmask_reduction(sc
,
1056 ah
->txchainmask
, info
->rates
[i
].Rate
);
1057 info
->rates
[i
].PktDuration
= ath_pkt_duration(sc
, rix
, len
,
1058 is_40
, is_sgi
, is_sp
);
1059 if (rix
< 8 && (tx_info
->flags
& IEEE80211_TX_CTL_STBC
))
1060 info
->rates
[i
].RateFlags
|= ATH9K_RATESERIES_STBC
;
1065 rate
= &sc
->sbands
[tx_info
->band
].bitrates
[rates
[i
].idx
];
1066 if ((tx_info
->band
== IEEE80211_BAND_2GHZ
) &&
1067 !(rate
->flags
& IEEE80211_RATE_ERP_G
))
1068 phy
= WLAN_RC_PHY_CCK
;
1070 phy
= WLAN_RC_PHY_OFDM
;
1072 info
->rates
[i
].Rate
= rate
->hw_value
;
1073 if (rate
->hw_value_short
) {
1074 if (rates
[i
].flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
1075 info
->rates
[i
].Rate
|= rate
->hw_value_short
;
1080 if (bf
->bf_state
.bfs_paprd
)
1081 info
->rates
[i
].ChSel
= ah
->txchainmask
;
1083 info
->rates
[i
].ChSel
= ath_txchainmask_reduction(sc
,
1084 ah
->txchainmask
, info
->rates
[i
].Rate
);
1086 info
->rates
[i
].PktDuration
= ath9k_hw_computetxtime(sc
->sc_ah
,
1087 phy
, rate
->bitrate
* 100, len
, rix
, is_sp
);
1090 /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
1091 if (bf_isaggr(bf
) && (len
> sc
->sc_ah
->caps
.rts_aggr_limit
))
1092 info
->flags
&= ~ATH9K_TXDESC_RTSENA
;
1094 /* ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive. */
1095 if (info
->flags
& ATH9K_TXDESC_RTSENA
)
1096 info
->flags
&= ~ATH9K_TXDESC_CTSENA
;
1099 static enum ath9k_pkt_type
get_hw_packet_type(struct sk_buff
*skb
)
1101 struct ieee80211_hdr
*hdr
;
1102 enum ath9k_pkt_type htype
;
1105 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1106 fc
= hdr
->frame_control
;
1108 if (ieee80211_is_beacon(fc
))
1109 htype
= ATH9K_PKT_TYPE_BEACON
;
1110 else if (ieee80211_is_probe_resp(fc
))
1111 htype
= ATH9K_PKT_TYPE_PROBE_RESP
;
1112 else if (ieee80211_is_atim(fc
))
1113 htype
= ATH9K_PKT_TYPE_ATIM
;
1114 else if (ieee80211_is_pspoll(fc
))
1115 htype
= ATH9K_PKT_TYPE_PSPOLL
;
1117 htype
= ATH9K_PKT_TYPE_NORMAL
;
1122 static void ath_tx_fill_desc(struct ath_softc
*sc
, struct ath_buf
*bf
,
1123 struct ath_txq
*txq
, int len
)
1125 struct ath_hw
*ah
= sc
->sc_ah
;
1126 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(bf
->bf_mpdu
);
1127 struct ath_buf
*bf_first
= bf
;
1128 struct ath_tx_info info
;
1129 bool aggr
= !!(bf
->bf_state
.bf_type
& BUF_AGGR
);
1131 memset(&info
, 0, sizeof(info
));
1132 info
.is_first
= true;
1133 info
.is_last
= true;
1134 info
.txpower
= MAX_RATE_POWER
;
1135 info
.qcu
= txq
->axq_qnum
;
1137 info
.flags
= ATH9K_TXDESC_INTREQ
;
1138 if (tx_info
->flags
& IEEE80211_TX_CTL_NO_ACK
)
1139 info
.flags
|= ATH9K_TXDESC_NOACK
;
1140 if (tx_info
->flags
& IEEE80211_TX_CTL_LDPC
)
1141 info
.flags
|= ATH9K_TXDESC_LDPC
;
1143 ath_buf_set_rate(sc
, bf
, &info
, len
);
1145 if (tx_info
->flags
& IEEE80211_TX_CTL_CLEAR_PS_FILT
)
1146 info
.flags
|= ATH9K_TXDESC_CLRDMASK
;
1148 if (bf
->bf_state
.bfs_paprd
)
1149 info
.flags
|= (u32
) bf
->bf_state
.bfs_paprd
<< ATH9K_TXDESC_PAPRD_S
;
1153 struct sk_buff
*skb
= bf
->bf_mpdu
;
1154 struct ath_frame_info
*fi
= get_frame_info(skb
);
1156 info
.type
= get_hw_packet_type(skb
);
1158 info
.link
= bf
->bf_next
->bf_daddr
;
1162 info
.buf_addr
[0] = bf
->bf_buf_addr
;
1163 info
.buf_len
[0] = skb
->len
;
1164 info
.pkt_len
= fi
->framelen
;
1165 info
.keyix
= fi
->keyix
;
1166 info
.keytype
= fi
->keytype
;
1170 info
.aggr
= AGGR_BUF_FIRST
;
1171 else if (!bf
->bf_next
)
1172 info
.aggr
= AGGR_BUF_LAST
;
1174 info
.aggr
= AGGR_BUF_MIDDLE
;
1176 info
.ndelim
= bf
->bf_state
.ndelim
;
1177 info
.aggr_len
= len
;
1180 ath9k_hw_set_txdesc(ah
, bf
->bf_desc
, &info
);
1185 static void ath_tx_sched_aggr(struct ath_softc
*sc
, struct ath_txq
*txq
,
1186 struct ath_atx_tid
*tid
)
1189 enum ATH_AGGR_STATUS status
;
1190 struct ieee80211_tx_info
*tx_info
;
1191 struct list_head bf_q
;
1195 if (skb_queue_empty(&tid
->buf_q
))
1198 INIT_LIST_HEAD(&bf_q
);
1200 status
= ath_tx_form_aggr(sc
, txq
, tid
, &bf_q
, &aggr_len
);
1203 * no frames picked up to be aggregated;
1204 * block-ack window is not open.
1206 if (list_empty(&bf_q
))
1209 bf
= list_first_entry(&bf_q
, struct ath_buf
, list
);
1210 bf
->bf_lastbf
= list_entry(bf_q
.prev
, struct ath_buf
, list
);
1211 tx_info
= IEEE80211_SKB_CB(bf
->bf_mpdu
);
1213 if (tid
->ac
->clear_ps_filter
) {
1214 tid
->ac
->clear_ps_filter
= false;
1215 tx_info
->flags
|= IEEE80211_TX_CTL_CLEAR_PS_FILT
;
1217 tx_info
->flags
&= ~IEEE80211_TX_CTL_CLEAR_PS_FILT
;
1220 /* if only one frame, send as non-aggregate */
1221 if (bf
== bf
->bf_lastbf
) {
1222 aggr_len
= get_frame_info(bf
->bf_mpdu
)->framelen
;
1223 bf
->bf_state
.bf_type
= BUF_AMPDU
;
1225 TX_STAT_INC(txq
->axq_qnum
, a_aggr
);
1228 ath_tx_fill_desc(sc
, bf
, txq
, aggr_len
);
1229 ath_tx_txqaddbuf(sc
, txq
, &bf_q
, false);
1230 } while (txq
->axq_ampdu_depth
< ATH_AGGR_MIN_QDEPTH
&&
1231 status
!= ATH_AGGR_BAW_CLOSED
);
1234 int ath_tx_aggr_start(struct ath_softc
*sc
, struct ieee80211_sta
*sta
,
1237 struct ath_atx_tid
*txtid
;
1238 struct ath_node
*an
;
1241 an
= (struct ath_node
*)sta
->drv_priv
;
1242 txtid
= ATH_AN_2_TID(an
, tid
);
1244 if (txtid
->state
& (AGGR_CLEANUP
| AGGR_ADDBA_COMPLETE
))
1247 /* update ampdu factor/density, they may have changed. This may happen
1248 * in HT IBSS when a beacon with HT-info is received after the station
1249 * has already been added.
1251 if (sta
->ht_cap
.ht_supported
) {
1252 an
->maxampdu
= 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1253 sta
->ht_cap
.ampdu_factor
);
1254 density
= ath9k_parse_mpdudensity(sta
->ht_cap
.ampdu_density
);
1255 an
->mpdudensity
= density
;
1258 txtid
->state
|= AGGR_ADDBA_PROGRESS
;
1259 txtid
->paused
= true;
1260 *ssn
= txtid
->seq_start
= txtid
->seq_next
;
1261 txtid
->bar_index
= -1;
1263 memset(txtid
->tx_buf
, 0, sizeof(txtid
->tx_buf
));
1264 txtid
->baw_head
= txtid
->baw_tail
= 0;
1269 bool ath_tx_aggr_stop(struct ath_softc
*sc
, struct ieee80211_sta
*sta
, u16 tid
,
1272 struct ath_node
*an
= (struct ath_node
*)sta
->drv_priv
;
1273 struct ath_atx_tid
*txtid
= ATH_AN_2_TID(an
, tid
);
1274 struct ath_txq
*txq
= txtid
->ac
->txq
;
1278 txtid
->stop_cb
= false;
1280 if (txtid
->state
& AGGR_CLEANUP
)
1283 if (!(txtid
->state
& AGGR_ADDBA_COMPLETE
)) {
1284 txtid
->state
&= ~AGGR_ADDBA_PROGRESS
;
1288 ath_txq_lock(sc
, txq
);
1289 txtid
->paused
= true;
1292 * If frames are still being transmitted for this TID, they will be
1293 * cleaned up during tx completion. To prevent race conditions, this
1294 * TID can only be reused after all in-progress subframes have been
1297 if (txtid
->baw_head
!= txtid
->baw_tail
) {
1298 txtid
->state
|= AGGR_CLEANUP
;
1300 txtid
->stop_cb
= !flush
;
1302 txtid
->state
&= ~AGGR_ADDBA_COMPLETE
;
1305 ath_tx_flush_tid(sc
, txtid
, flush
);
1306 ath_txq_unlock_complete(sc
, txq
);
1310 void ath_tx_aggr_sleep(struct ieee80211_sta
*sta
, struct ath_softc
*sc
,
1311 struct ath_node
*an
)
1313 struct ath_atx_tid
*tid
;
1314 struct ath_atx_ac
*ac
;
1315 struct ath_txq
*txq
;
1319 for (tidno
= 0, tid
= &an
->tid
[tidno
];
1320 tidno
< IEEE80211_NUM_TIDS
; tidno
++, tid
++) {
1328 ath_txq_lock(sc
, txq
);
1330 buffered
= !skb_queue_empty(&tid
->buf_q
);
1333 list_del(&tid
->list
);
1337 list_del(&ac
->list
);
1340 ath_txq_unlock(sc
, txq
);
1342 ieee80211_sta_set_buffered(sta
, tidno
, buffered
);
1346 void ath_tx_aggr_wakeup(struct ath_softc
*sc
, struct ath_node
*an
)
1348 struct ath_atx_tid
*tid
;
1349 struct ath_atx_ac
*ac
;
1350 struct ath_txq
*txq
;
1353 for (tidno
= 0, tid
= &an
->tid
[tidno
];
1354 tidno
< IEEE80211_NUM_TIDS
; tidno
++, tid
++) {
1359 ath_txq_lock(sc
, txq
);
1360 ac
->clear_ps_filter
= true;
1362 if (!skb_queue_empty(&tid
->buf_q
) && !tid
->paused
) {
1363 ath_tx_queue_tid(txq
, tid
);
1364 ath_txq_schedule(sc
, txq
);
1367 ath_txq_unlock_complete(sc
, txq
);
1371 void ath_tx_aggr_resume(struct ath_softc
*sc
, struct ieee80211_sta
*sta
, u16 tid
)
1373 struct ath_atx_tid
*txtid
;
1374 struct ath_node
*an
;
1376 an
= (struct ath_node
*)sta
->drv_priv
;
1378 txtid
= ATH_AN_2_TID(an
, tid
);
1379 txtid
->baw_size
= IEEE80211_MIN_AMPDU_BUF
<< sta
->ht_cap
.ampdu_factor
;
1380 txtid
->state
|= AGGR_ADDBA_COMPLETE
;
1381 txtid
->state
&= ~AGGR_ADDBA_PROGRESS
;
1382 ath_tx_resume_tid(sc
, txtid
);
1385 /********************/
1386 /* Queue Management */
1387 /********************/
1389 struct ath_txq
*ath_txq_setup(struct ath_softc
*sc
, int qtype
, int subtype
)
1391 struct ath_hw
*ah
= sc
->sc_ah
;
1392 struct ath9k_tx_queue_info qi
;
1393 static const int subtype_txq_to_hwq
[] = {
1394 [IEEE80211_AC_BE
] = ATH_TXQ_AC_BE
,
1395 [IEEE80211_AC_BK
] = ATH_TXQ_AC_BK
,
1396 [IEEE80211_AC_VI
] = ATH_TXQ_AC_VI
,
1397 [IEEE80211_AC_VO
] = ATH_TXQ_AC_VO
,
1401 memset(&qi
, 0, sizeof(qi
));
1402 qi
.tqi_subtype
= subtype_txq_to_hwq
[subtype
];
1403 qi
.tqi_aifs
= ATH9K_TXQ_USEDEFAULT
;
1404 qi
.tqi_cwmin
= ATH9K_TXQ_USEDEFAULT
;
1405 qi
.tqi_cwmax
= ATH9K_TXQ_USEDEFAULT
;
1406 qi
.tqi_physCompBuf
= 0;
1409 * Enable interrupts only for EOL and DESC conditions.
1410 * We mark tx descriptors to receive a DESC interrupt
1411 * when a tx queue gets deep; otherwise waiting for the
1412 * EOL to reap descriptors. Note that this is done to
1413 * reduce interrupt load and this only defers reaping
1414 * descriptors, never transmitting frames. Aside from
1415 * reducing interrupts this also permits more concurrency.
1416 * The only potential downside is if the tx queue backs
1417 * up in which case the top half of the kernel may backup
1418 * due to a lack of tx descriptors.
1420 * The UAPSD queue is an exception, since we take a desc-
1421 * based intr on the EOSP frames.
1423 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) {
1424 qi
.tqi_qflags
= TXQ_FLAG_TXINT_ENABLE
;
1426 if (qtype
== ATH9K_TX_QUEUE_UAPSD
)
1427 qi
.tqi_qflags
= TXQ_FLAG_TXDESCINT_ENABLE
;
1429 qi
.tqi_qflags
= TXQ_FLAG_TXEOLINT_ENABLE
|
1430 TXQ_FLAG_TXDESCINT_ENABLE
;
1432 axq_qnum
= ath9k_hw_setuptxqueue(ah
, qtype
, &qi
);
1433 if (axq_qnum
== -1) {
1435 * NB: don't print a message, this happens
1436 * normally on parts with too few tx queues
1440 if (!ATH_TXQ_SETUP(sc
, axq_qnum
)) {
1441 struct ath_txq
*txq
= &sc
->tx
.txq
[axq_qnum
];
1443 txq
->axq_qnum
= axq_qnum
;
1444 txq
->mac80211_qnum
= -1;
1445 txq
->axq_link
= NULL
;
1446 __skb_queue_head_init(&txq
->complete_q
);
1447 INIT_LIST_HEAD(&txq
->axq_q
);
1448 INIT_LIST_HEAD(&txq
->axq_acq
);
1449 spin_lock_init(&txq
->axq_lock
);
1451 txq
->axq_ampdu_depth
= 0;
1452 txq
->axq_tx_inprogress
= false;
1453 sc
->tx
.txqsetup
|= 1<<axq_qnum
;
1455 txq
->txq_headidx
= txq
->txq_tailidx
= 0;
1456 for (i
= 0; i
< ATH_TXFIFO_DEPTH
; i
++)
1457 INIT_LIST_HEAD(&txq
->txq_fifo
[i
]);
1459 return &sc
->tx
.txq
[axq_qnum
];
1462 int ath_txq_update(struct ath_softc
*sc
, int qnum
,
1463 struct ath9k_tx_queue_info
*qinfo
)
1465 struct ath_hw
*ah
= sc
->sc_ah
;
1467 struct ath9k_tx_queue_info qi
;
1469 BUG_ON(sc
->tx
.txq
[qnum
].axq_qnum
!= qnum
);
1471 ath9k_hw_get_txq_props(ah
, qnum
, &qi
);
1472 qi
.tqi_aifs
= qinfo
->tqi_aifs
;
1473 qi
.tqi_cwmin
= qinfo
->tqi_cwmin
;
1474 qi
.tqi_cwmax
= qinfo
->tqi_cwmax
;
1475 qi
.tqi_burstTime
= qinfo
->tqi_burstTime
;
1476 qi
.tqi_readyTime
= qinfo
->tqi_readyTime
;
1478 if (!ath9k_hw_set_txq_props(ah
, qnum
, &qi
)) {
1479 ath_err(ath9k_hw_common(sc
->sc_ah
),
1480 "Unable to update hardware queue %u!\n", qnum
);
1483 ath9k_hw_resettxqueue(ah
, qnum
);
1489 int ath_cabq_update(struct ath_softc
*sc
)
1491 struct ath9k_tx_queue_info qi
;
1492 struct ath_beacon_config
*cur_conf
= &sc
->cur_beacon_conf
;
1493 int qnum
= sc
->beacon
.cabq
->axq_qnum
;
1495 ath9k_hw_get_txq_props(sc
->sc_ah
, qnum
, &qi
);
1497 * Ensure the readytime % is within the bounds.
1499 if (sc
->config
.cabqReadytime
< ATH9K_READY_TIME_LO_BOUND
)
1500 sc
->config
.cabqReadytime
= ATH9K_READY_TIME_LO_BOUND
;
1501 else if (sc
->config
.cabqReadytime
> ATH9K_READY_TIME_HI_BOUND
)
1502 sc
->config
.cabqReadytime
= ATH9K_READY_TIME_HI_BOUND
;
1504 qi
.tqi_readyTime
= (cur_conf
->beacon_interval
*
1505 sc
->config
.cabqReadytime
) / 100;
1506 ath_txq_update(sc
, qnum
, &qi
);
1511 static void ath_drain_txq_list(struct ath_softc
*sc
, struct ath_txq
*txq
,
1512 struct list_head
*list
)
1514 struct ath_buf
*bf
, *lastbf
;
1515 struct list_head bf_head
;
1516 struct ath_tx_status ts
;
1518 memset(&ts
, 0, sizeof(ts
));
1519 ts
.ts_status
= ATH9K_TX_FLUSH
;
1520 INIT_LIST_HEAD(&bf_head
);
1522 while (!list_empty(list
)) {
1523 bf
= list_first_entry(list
, struct ath_buf
, list
);
1526 list_del(&bf
->list
);
1528 ath_tx_return_buffer(sc
, bf
);
1532 lastbf
= bf
->bf_lastbf
;
1533 list_cut_position(&bf_head
, list
, &lastbf
->list
);
1534 ath_tx_process_buffer(sc
, txq
, &ts
, bf
, &bf_head
);
1539 * Drain a given TX queue (could be Beacon or Data)
1541 * This assumes output has been stopped and
1542 * we do not need to block ath_tx_tasklet.
1544 void ath_draintxq(struct ath_softc
*sc
, struct ath_txq
*txq
)
1546 ath_txq_lock(sc
, txq
);
1548 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) {
1549 int idx
= txq
->txq_tailidx
;
1551 while (!list_empty(&txq
->txq_fifo
[idx
])) {
1552 ath_drain_txq_list(sc
, txq
, &txq
->txq_fifo
[idx
]);
1554 INCR(idx
, ATH_TXFIFO_DEPTH
);
1556 txq
->txq_tailidx
= idx
;
1559 txq
->axq_link
= NULL
;
1560 txq
->axq_tx_inprogress
= false;
1561 ath_drain_txq_list(sc
, txq
, &txq
->axq_q
);
1563 ath_txq_unlock_complete(sc
, txq
);
1566 bool ath_drain_all_txq(struct ath_softc
*sc
)
1568 struct ath_hw
*ah
= sc
->sc_ah
;
1569 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1570 struct ath_txq
*txq
;
1574 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
))
1577 ath9k_hw_abort_tx_dma(ah
);
1579 /* Check if any queue remains active */
1580 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1581 if (!ATH_TXQ_SETUP(sc
, i
))
1584 if (ath9k_hw_numtxpending(ah
, sc
->tx
.txq
[i
].axq_qnum
))
1589 ath_err(common
, "Failed to stop TX DMA, queues=0x%03x!\n", npend
);
1591 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1592 if (!ATH_TXQ_SETUP(sc
, i
))
1596 * The caller will resume queues with ieee80211_wake_queues.
1597 * Mark the queue as not stopped to prevent ath_tx_complete
1598 * from waking the queue too early.
1600 txq
= &sc
->tx
.txq
[i
];
1601 txq
->stopped
= false;
1602 ath_draintxq(sc
, txq
);
1608 void ath_tx_cleanupq(struct ath_softc
*sc
, struct ath_txq
*txq
)
1610 ath9k_hw_releasetxqueue(sc
->sc_ah
, txq
->axq_qnum
);
1611 sc
->tx
.txqsetup
&= ~(1<<txq
->axq_qnum
);
1614 /* For each axq_acq entry, for each tid, try to schedule packets
1615 * for transmit until ampdu_depth has reached min Q depth.
1617 void ath_txq_schedule(struct ath_softc
*sc
, struct ath_txq
*txq
)
1619 struct ath_atx_ac
*ac
, *ac_tmp
, *last_ac
;
1620 struct ath_atx_tid
*tid
, *last_tid
;
1622 if (test_bit(SC_OP_HW_RESET
, &sc
->sc_flags
) ||
1623 list_empty(&txq
->axq_acq
) ||
1624 txq
->axq_ampdu_depth
>= ATH_AGGR_MIN_QDEPTH
)
1627 ac
= list_first_entry(&txq
->axq_acq
, struct ath_atx_ac
, list
);
1628 last_ac
= list_entry(txq
->axq_acq
.prev
, struct ath_atx_ac
, list
);
1630 list_for_each_entry_safe(ac
, ac_tmp
, &txq
->axq_acq
, list
) {
1631 last_tid
= list_entry(ac
->tid_q
.prev
, struct ath_atx_tid
, list
);
1632 list_del(&ac
->list
);
1635 while (!list_empty(&ac
->tid_q
)) {
1636 tid
= list_first_entry(&ac
->tid_q
, struct ath_atx_tid
,
1638 list_del(&tid
->list
);
1644 ath_tx_sched_aggr(sc
, txq
, tid
);
1647 * add tid to round-robin queue if more frames
1648 * are pending for the tid
1650 if (!skb_queue_empty(&tid
->buf_q
))
1651 ath_tx_queue_tid(txq
, tid
);
1653 if (tid
== last_tid
||
1654 txq
->axq_ampdu_depth
>= ATH_AGGR_MIN_QDEPTH
)
1658 if (!list_empty(&ac
->tid_q
) && !ac
->sched
) {
1660 list_add_tail(&ac
->list
, &txq
->axq_acq
);
1663 if (ac
== last_ac
||
1664 txq
->axq_ampdu_depth
>= ATH_AGGR_MIN_QDEPTH
)
1674 * Insert a chain of ath_buf (descriptors) on a txq and
1675 * assume the descriptors are already chained together by caller.
1677 static void ath_tx_txqaddbuf(struct ath_softc
*sc
, struct ath_txq
*txq
,
1678 struct list_head
*head
, bool internal
)
1680 struct ath_hw
*ah
= sc
->sc_ah
;
1681 struct ath_common
*common
= ath9k_hw_common(ah
);
1682 struct ath_buf
*bf
, *bf_last
;
1683 bool puttxbuf
= false;
1687 * Insert the frame on the outbound list and
1688 * pass it on to the hardware.
1691 if (list_empty(head
))
1694 edma
= !!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
);
1695 bf
= list_first_entry(head
, struct ath_buf
, list
);
1696 bf_last
= list_entry(head
->prev
, struct ath_buf
, list
);
1698 ath_dbg(common
, QUEUE
, "qnum: %d, txq depth: %d\n",
1699 txq
->axq_qnum
, txq
->axq_depth
);
1701 if (edma
&& list_empty(&txq
->txq_fifo
[txq
->txq_headidx
])) {
1702 list_splice_tail_init(head
, &txq
->txq_fifo
[txq
->txq_headidx
]);
1703 INCR(txq
->txq_headidx
, ATH_TXFIFO_DEPTH
);
1706 list_splice_tail_init(head
, &txq
->axq_q
);
1708 if (txq
->axq_link
) {
1709 ath9k_hw_set_desc_link(ah
, txq
->axq_link
, bf
->bf_daddr
);
1710 ath_dbg(common
, XMIT
, "link[%u] (%p)=%llx (%p)\n",
1711 txq
->axq_qnum
, txq
->axq_link
,
1712 ito64(bf
->bf_daddr
), bf
->bf_desc
);
1716 txq
->axq_link
= bf_last
->bf_desc
;
1720 TX_STAT_INC(txq
->axq_qnum
, puttxbuf
);
1721 ath9k_hw_puttxbuf(ah
, txq
->axq_qnum
, bf
->bf_daddr
);
1722 ath_dbg(common
, XMIT
, "TXDP[%u] = %llx (%p)\n",
1723 txq
->axq_qnum
, ito64(bf
->bf_daddr
), bf
->bf_desc
);
1727 TX_STAT_INC(txq
->axq_qnum
, txstart
);
1728 ath9k_hw_txstart(ah
, txq
->axq_qnum
);
1733 if (bf_is_ampdu_not_probing(bf
))
1734 txq
->axq_ampdu_depth
++;
1738 static void ath_tx_send_ampdu(struct ath_softc
*sc
, struct ath_atx_tid
*tid
,
1739 struct sk_buff
*skb
, struct ath_tx_control
*txctl
)
1741 struct ath_frame_info
*fi
= get_frame_info(skb
);
1742 struct list_head bf_head
;
1746 * Do not queue to h/w when any of the following conditions is true:
1747 * - there are pending frames in software queue
1748 * - the TID is currently paused for ADDBA/BAR request
1749 * - seqno is not within block-ack window
1750 * - h/w queue depth exceeds low water mark
1752 if (!skb_queue_empty(&tid
->buf_q
) || tid
->paused
||
1753 !BAW_WITHIN(tid
->seq_start
, tid
->baw_size
, tid
->seq_next
) ||
1754 txctl
->txq
->axq_ampdu_depth
>= ATH_AGGR_MIN_QDEPTH
) {
1756 * Add this frame to software queue for scheduling later
1759 TX_STAT_INC(txctl
->txq
->axq_qnum
, a_queued_sw
);
1760 __skb_queue_tail(&tid
->buf_q
, skb
);
1761 if (!txctl
->an
|| !txctl
->an
->sleeping
)
1762 ath_tx_queue_tid(txctl
->txq
, tid
);
1766 bf
= ath_tx_setup_buffer(sc
, txctl
->txq
, tid
, skb
);
1768 ieee80211_free_txskb(sc
->hw
, skb
);
1772 ath_set_rates(tid
->an
->vif
, tid
->an
->sta
, bf
);
1773 bf
->bf_state
.bf_type
= BUF_AMPDU
;
1774 INIT_LIST_HEAD(&bf_head
);
1775 list_add(&bf
->list
, &bf_head
);
1777 /* Add sub-frame to BAW */
1778 ath_tx_addto_baw(sc
, tid
, bf
->bf_state
.seqno
);
1780 /* Queue to h/w without aggregation */
1781 TX_STAT_INC(txctl
->txq
->axq_qnum
, a_queued_hw
);
1783 ath_tx_fill_desc(sc
, bf
, txctl
->txq
, fi
->framelen
);
1784 ath_tx_txqaddbuf(sc
, txctl
->txq
, &bf_head
, false);
1787 static void ath_tx_send_normal(struct ath_softc
*sc
, struct ath_txq
*txq
,
1788 struct ath_atx_tid
*tid
, struct sk_buff
*skb
)
1790 struct ath_frame_info
*fi
= get_frame_info(skb
);
1791 struct list_head bf_head
;
1796 INIT_LIST_HEAD(&bf_head
);
1797 list_add_tail(&bf
->list
, &bf_head
);
1798 bf
->bf_state
.bf_type
= 0;
1802 ath_tx_fill_desc(sc
, bf
, txq
, fi
->framelen
);
1803 ath_tx_txqaddbuf(sc
, txq
, &bf_head
, false);
1804 TX_STAT_INC(txq
->axq_qnum
, queued
);
1807 static void setup_frame_info(struct ieee80211_hw
*hw
,
1808 struct ieee80211_sta
*sta
,
1809 struct sk_buff
*skb
,
1812 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
1813 struct ieee80211_key_conf
*hw_key
= tx_info
->control
.hw_key
;
1814 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1815 const struct ieee80211_rate
*rate
;
1816 struct ath_frame_info
*fi
= get_frame_info(skb
);
1817 struct ath_node
*an
= NULL
;
1818 enum ath9k_key_type keytype
;
1819 bool short_preamble
= false;
1822 * We check if Short Preamble is needed for the CTS rate by
1823 * checking the BSS's global flag.
1824 * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
1826 if (tx_info
->control
.vif
&&
1827 tx_info
->control
.vif
->bss_conf
.use_short_preamble
)
1828 short_preamble
= true;
1830 rate
= ieee80211_get_rts_cts_rate(hw
, tx_info
);
1831 keytype
= ath9k_cmn_get_hw_crypto_keytype(skb
);
1834 an
= (struct ath_node
*) sta
->drv_priv
;
1836 memset(fi
, 0, sizeof(*fi
));
1838 fi
->keyix
= hw_key
->hw_key_idx
;
1839 else if (an
&& ieee80211_is_data(hdr
->frame_control
) && an
->ps_key
> 0)
1840 fi
->keyix
= an
->ps_key
;
1842 fi
->keyix
= ATH9K_TXKEYIX_INVALID
;
1843 fi
->keytype
= keytype
;
1844 fi
->framelen
= framelen
;
1845 fi
->rtscts_rate
= rate
->hw_value
;
1847 fi
->rtscts_rate
|= rate
->hw_value_short
;
1850 u8
ath_txchainmask_reduction(struct ath_softc
*sc
, u8 chainmask
, u32 rate
)
1852 struct ath_hw
*ah
= sc
->sc_ah
;
1853 struct ath9k_channel
*curchan
= ah
->curchan
;
1855 if ((ah
->caps
.hw_caps
& ATH9K_HW_CAP_APM
) &&
1856 (curchan
->channelFlags
& CHANNEL_5GHZ
) &&
1857 (chainmask
== 0x7) && (rate
< 0x90))
1859 else if (AR_SREV_9462(ah
) && ath9k_hw_btcoex_is_enabled(ah
) &&
1867 * Assign a descriptor (and sequence number if necessary,
1868 * and map buffer for DMA. Frees skb on error
1870 static struct ath_buf
*ath_tx_setup_buffer(struct ath_softc
*sc
,
1871 struct ath_txq
*txq
,
1872 struct ath_atx_tid
*tid
,
1873 struct sk_buff
*skb
)
1875 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1876 struct ath_frame_info
*fi
= get_frame_info(skb
);
1877 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1882 bf
= ath_tx_get_buffer(sc
);
1884 ath_dbg(common
, XMIT
, "TX buffers are full\n");
1888 ATH_TXBUF_RESET(bf
);
1891 fragno
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
1892 seqno
= tid
->seq_next
;
1893 hdr
->seq_ctrl
= cpu_to_le16(tid
->seq_next
<< IEEE80211_SEQ_SEQ_SHIFT
);
1896 hdr
->seq_ctrl
|= cpu_to_le16(fragno
);
1898 if (!ieee80211_has_morefrags(hdr
->frame_control
))
1899 INCR(tid
->seq_next
, IEEE80211_SEQ_MAX
);
1901 bf
->bf_state
.seqno
= seqno
;
1906 bf
->bf_buf_addr
= dma_map_single(sc
->dev
, skb
->data
,
1907 skb
->len
, DMA_TO_DEVICE
);
1908 if (unlikely(dma_mapping_error(sc
->dev
, bf
->bf_buf_addr
))) {
1910 bf
->bf_buf_addr
= 0;
1911 ath_err(ath9k_hw_common(sc
->sc_ah
),
1912 "dma_mapping_error() on TX\n");
1913 ath_tx_return_buffer(sc
, bf
);
1922 /* Upon failure caller should free skb */
1923 int ath_tx_start(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1924 struct ath_tx_control
*txctl
)
1926 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1927 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1928 struct ieee80211_sta
*sta
= txctl
->sta
;
1929 struct ieee80211_vif
*vif
= info
->control
.vif
;
1930 struct ath_softc
*sc
= hw
->priv
;
1931 struct ath_txq
*txq
= txctl
->txq
;
1932 struct ath_atx_tid
*tid
= NULL
;
1934 int padpos
, padsize
;
1935 int frmlen
= skb
->len
+ FCS_LEN
;
1939 /* NOTE: sta can be NULL according to net/mac80211.h */
1941 txctl
->an
= (struct ath_node
*)sta
->drv_priv
;
1943 if (info
->control
.hw_key
)
1944 frmlen
+= info
->control
.hw_key
->icv_len
;
1947 * As a temporary workaround, assign seq# here; this will likely need
1948 * to be cleaned up to work better with Beacon transmission and virtual
1951 if (info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
1952 if (info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
)
1953 sc
->tx
.seq_no
+= 0x10;
1954 hdr
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
1955 hdr
->seq_ctrl
|= cpu_to_le16(sc
->tx
.seq_no
);
1958 /* Add the padding after the header if this is not already done */
1959 padpos
= ieee80211_hdrlen(hdr
->frame_control
);
1960 padsize
= padpos
& 3;
1961 if (padsize
&& skb
->len
> padpos
) {
1962 if (skb_headroom(skb
) < padsize
)
1965 skb_push(skb
, padsize
);
1966 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
1967 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1970 if ((vif
&& vif
->type
!= NL80211_IFTYPE_AP
&&
1971 vif
->type
!= NL80211_IFTYPE_AP_VLAN
) ||
1972 !ieee80211_is_data(hdr
->frame_control
))
1973 info
->flags
|= IEEE80211_TX_CTL_CLEAR_PS_FILT
;
1975 setup_frame_info(hw
, sta
, skb
, frmlen
);
1978 * At this point, the vif, hw_key and sta pointers in the tx control
1979 * info are no longer valid (overwritten by the ath_frame_info data.
1982 q
= skb_get_queue_mapping(skb
);
1984 ath_txq_lock(sc
, txq
);
1985 if (txq
== sc
->tx
.txq_map
[q
] &&
1986 ++txq
->pending_frames
> sc
->tx
.txq_max_pending
[q
] &&
1988 ieee80211_stop_queue(sc
->hw
, q
);
1989 txq
->stopped
= true;
1992 if (txctl
->an
&& ieee80211_is_data_qos(hdr
->frame_control
)) {
1993 tidno
= ieee80211_get_qos_ctl(hdr
)[0] &
1994 IEEE80211_QOS_CTL_TID_MASK
;
1995 tid
= ATH_AN_2_TID(txctl
->an
, tidno
);
1997 WARN_ON(tid
->ac
->txq
!= txctl
->txq
);
2000 if ((info
->flags
& IEEE80211_TX_CTL_AMPDU
) && tid
) {
2002 * Try aggregation if it's a unicast data frame
2003 * and the destination is HT capable.
2005 ath_tx_send_ampdu(sc
, tid
, skb
, txctl
);
2009 bf
= ath_tx_setup_buffer(sc
, txctl
->txq
, tid
, skb
);
2012 dev_kfree_skb_any(skb
);
2014 ieee80211_free_txskb(sc
->hw
, skb
);
2018 bf
->bf_state
.bfs_paprd
= txctl
->paprd
;
2021 bf
->bf_state
.bfs_paprd_timestamp
= jiffies
;
2023 ath_set_rates(vif
, sta
, bf
);
2024 ath_tx_send_normal(sc
, txctl
->txq
, tid
, skb
);
2027 ath_txq_unlock(sc
, txq
);
2036 static void ath_tx_complete(struct ath_softc
*sc
, struct sk_buff
*skb
,
2037 int tx_flags
, struct ath_txq
*txq
)
2039 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
2040 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2041 struct ieee80211_hdr
* hdr
= (struct ieee80211_hdr
*)skb
->data
;
2042 int q
, padpos
, padsize
;
2043 unsigned long flags
;
2045 ath_dbg(common
, XMIT
, "TX complete: skb: %p\n", skb
);
2047 if (sc
->sc_ah
->caldata
)
2048 sc
->sc_ah
->caldata
->paprd_packet_sent
= true;
2050 if (!(tx_flags
& ATH_TX_ERROR
))
2051 /* Frame was ACKed */
2052 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
2054 padpos
= ieee80211_hdrlen(hdr
->frame_control
);
2055 padsize
= padpos
& 3;
2056 if (padsize
&& skb
->len
>padpos
+padsize
) {
2058 * Remove MAC header padding before giving the frame back to
2061 memmove(skb
->data
+ padsize
, skb
->data
, padpos
);
2062 skb_pull(skb
, padsize
);
2065 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
2066 if ((sc
->ps_flags
& PS_WAIT_FOR_TX_ACK
) && !txq
->axq_depth
) {
2067 sc
->ps_flags
&= ~PS_WAIT_FOR_TX_ACK
;
2069 "Going back to sleep after having received TX status (0x%lx)\n",
2070 sc
->ps_flags
& (PS_WAIT_FOR_BEACON
|
2072 PS_WAIT_FOR_PSPOLL_DATA
|
2073 PS_WAIT_FOR_TX_ACK
));
2075 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
2077 q
= skb_get_queue_mapping(skb
);
2078 if (txq
== sc
->tx
.txq_map
[q
]) {
2079 if (WARN_ON(--txq
->pending_frames
< 0))
2080 txq
->pending_frames
= 0;
2083 txq
->pending_frames
< sc
->tx
.txq_max_pending
[q
]) {
2084 ieee80211_wake_queue(sc
->hw
, q
);
2085 txq
->stopped
= false;
2089 __skb_queue_tail(&txq
->complete_q
, skb
);
2092 static void ath_tx_complete_buf(struct ath_softc
*sc
, struct ath_buf
*bf
,
2093 struct ath_txq
*txq
, struct list_head
*bf_q
,
2094 struct ath_tx_status
*ts
, int txok
)
2096 struct sk_buff
*skb
= bf
->bf_mpdu
;
2097 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
2098 unsigned long flags
;
2102 tx_flags
|= ATH_TX_ERROR
;
2104 if (ts
->ts_status
& ATH9K_TXERR_FILT
)
2105 tx_info
->flags
|= IEEE80211_TX_STAT_TX_FILTERED
;
2107 dma_unmap_single(sc
->dev
, bf
->bf_buf_addr
, skb
->len
, DMA_TO_DEVICE
);
2108 bf
->bf_buf_addr
= 0;
2110 if (bf
->bf_state
.bfs_paprd
) {
2111 if (time_after(jiffies
,
2112 bf
->bf_state
.bfs_paprd_timestamp
+
2113 msecs_to_jiffies(ATH_PAPRD_TIMEOUT
)))
2114 dev_kfree_skb_any(skb
);
2116 complete(&sc
->paprd_complete
);
2118 ath_debug_stat_tx(sc
, bf
, ts
, txq
, tx_flags
);
2119 ath_tx_complete(sc
, skb
, tx_flags
, txq
);
2121 /* At this point, skb (bf->bf_mpdu) is consumed...make sure we don't
2122 * accidentally reference it later.
2127 * Return the list of ath_buf of this mpdu to free queue
2129 spin_lock_irqsave(&sc
->tx
.txbuflock
, flags
);
2130 list_splice_tail_init(bf_q
, &sc
->tx
.txbuf
);
2131 spin_unlock_irqrestore(&sc
->tx
.txbuflock
, flags
);
2134 static void ath_tx_rc_status(struct ath_softc
*sc
, struct ath_buf
*bf
,
2135 struct ath_tx_status
*ts
, int nframes
, int nbad
,
2138 struct sk_buff
*skb
= bf
->bf_mpdu
;
2139 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2140 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
2141 struct ieee80211_hw
*hw
= sc
->hw
;
2142 struct ath_hw
*ah
= sc
->sc_ah
;
2146 tx_info
->status
.ack_signal
= ts
->ts_rssi
;
2148 tx_rateindex
= ts
->ts_rateindex
;
2149 WARN_ON(tx_rateindex
>= hw
->max_rates
);
2151 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
2152 tx_info
->flags
|= IEEE80211_TX_STAT_AMPDU
;
2154 BUG_ON(nbad
> nframes
);
2156 tx_info
->status
.ampdu_len
= nframes
;
2157 tx_info
->status
.ampdu_ack_len
= nframes
- nbad
;
2159 if ((ts
->ts_status
& ATH9K_TXERR_FILT
) == 0 &&
2160 (tx_info
->flags
& IEEE80211_TX_CTL_NO_ACK
) == 0) {
2162 * If an underrun error is seen assume it as an excessive
2163 * retry only if max frame trigger level has been reached
2164 * (2 KB for single stream, and 4 KB for dual stream).
2165 * Adjust the long retry as if the frame was tried
2166 * hw->max_rate_tries times to affect how rate control updates
2167 * PER for the failed rate.
2168 * In case of congestion on the bus penalizing this type of
2169 * underruns should help hardware actually transmit new frames
2170 * successfully by eventually preferring slower rates.
2171 * This itself should also alleviate congestion on the bus.
2173 if (unlikely(ts
->ts_flags
& (ATH9K_TX_DATA_UNDERRUN
|
2174 ATH9K_TX_DELIM_UNDERRUN
)) &&
2175 ieee80211_is_data(hdr
->frame_control
) &&
2176 ah
->tx_trig_level
>= sc
->sc_ah
->config
.max_txtrig_level
)
2177 tx_info
->status
.rates
[tx_rateindex
].count
=
2181 for (i
= tx_rateindex
+ 1; i
< hw
->max_rates
; i
++) {
2182 tx_info
->status
.rates
[i
].count
= 0;
2183 tx_info
->status
.rates
[i
].idx
= -1;
2186 tx_info
->status
.rates
[tx_rateindex
].count
= ts
->ts_longretry
+ 1;
2189 static void ath_tx_processq(struct ath_softc
*sc
, struct ath_txq
*txq
)
2191 struct ath_hw
*ah
= sc
->sc_ah
;
2192 struct ath_common
*common
= ath9k_hw_common(ah
);
2193 struct ath_buf
*bf
, *lastbf
, *bf_held
= NULL
;
2194 struct list_head bf_head
;
2195 struct ath_desc
*ds
;
2196 struct ath_tx_status ts
;
2199 ath_dbg(common
, QUEUE
, "tx queue %d (%x), link %p\n",
2200 txq
->axq_qnum
, ath9k_hw_gettxbuf(sc
->sc_ah
, txq
->axq_qnum
),
2203 ath_txq_lock(sc
, txq
);
2205 if (test_bit(SC_OP_HW_RESET
, &sc
->sc_flags
))
2208 if (list_empty(&txq
->axq_q
)) {
2209 txq
->axq_link
= NULL
;
2210 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
)
2211 ath_txq_schedule(sc
, txq
);
2214 bf
= list_first_entry(&txq
->axq_q
, struct ath_buf
, list
);
2217 * There is a race condition that a BH gets scheduled
2218 * after sw writes TxE and before hw re-load the last
2219 * descriptor to get the newly chained one.
2220 * Software must keep the last DONE descriptor as a
2221 * holding descriptor - software does so by marking
2222 * it with the STALE flag.
2227 if (list_is_last(&bf_held
->list
, &txq
->axq_q
))
2230 bf
= list_entry(bf_held
->list
.next
, struct ath_buf
,
2234 lastbf
= bf
->bf_lastbf
;
2235 ds
= lastbf
->bf_desc
;
2237 memset(&ts
, 0, sizeof(ts
));
2238 status
= ath9k_hw_txprocdesc(ah
, ds
, &ts
);
2239 if (status
== -EINPROGRESS
)
2242 TX_STAT_INC(txq
->axq_qnum
, txprocdesc
);
2245 * Remove ath_buf's of the same transmit unit from txq,
2246 * however leave the last descriptor back as the holding
2247 * descriptor for hw.
2249 lastbf
->bf_stale
= true;
2250 INIT_LIST_HEAD(&bf_head
);
2251 if (!list_is_singular(&lastbf
->list
))
2252 list_cut_position(&bf_head
,
2253 &txq
->axq_q
, lastbf
->list
.prev
);
2256 list_del(&bf_held
->list
);
2257 ath_tx_return_buffer(sc
, bf_held
);
2260 ath_tx_process_buffer(sc
, txq
, &ts
, bf
, &bf_head
);
2262 ath_txq_unlock_complete(sc
, txq
);
2265 void ath_tx_tasklet(struct ath_softc
*sc
)
2267 struct ath_hw
*ah
= sc
->sc_ah
;
2268 u32 qcumask
= ((1 << ATH9K_NUM_TX_QUEUES
) - 1) & ah
->intr_txqs
;
2271 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
2272 if (ATH_TXQ_SETUP(sc
, i
) && (qcumask
& (1 << i
)))
2273 ath_tx_processq(sc
, &sc
->tx
.txq
[i
]);
2277 void ath_tx_edma_tasklet(struct ath_softc
*sc
)
2279 struct ath_tx_status ts
;
2280 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2281 struct ath_hw
*ah
= sc
->sc_ah
;
2282 struct ath_txq
*txq
;
2283 struct ath_buf
*bf
, *lastbf
;
2284 struct list_head bf_head
;
2285 struct list_head
*fifo_list
;
2289 if (test_bit(SC_OP_HW_RESET
, &sc
->sc_flags
))
2292 status
= ath9k_hw_txprocdesc(ah
, NULL
, (void *)&ts
);
2293 if (status
== -EINPROGRESS
)
2295 if (status
== -EIO
) {
2296 ath_dbg(common
, XMIT
, "Error processing tx status\n");
2300 /* Process beacon completions separately */
2301 if (ts
.qid
== sc
->beacon
.beaconq
) {
2302 sc
->beacon
.tx_processed
= true;
2303 sc
->beacon
.tx_last
= !(ts
.ts_status
& ATH9K_TXERR_MASK
);
2307 txq
= &sc
->tx
.txq
[ts
.qid
];
2309 ath_txq_lock(sc
, txq
);
2311 TX_STAT_INC(txq
->axq_qnum
, txprocdesc
);
2313 fifo_list
= &txq
->txq_fifo
[txq
->txq_tailidx
];
2314 if (list_empty(fifo_list
)) {
2315 ath_txq_unlock(sc
, txq
);
2319 bf
= list_first_entry(fifo_list
, struct ath_buf
, list
);
2321 list_del(&bf
->list
);
2322 ath_tx_return_buffer(sc
, bf
);
2323 bf
= list_first_entry(fifo_list
, struct ath_buf
, list
);
2326 lastbf
= bf
->bf_lastbf
;
2328 INIT_LIST_HEAD(&bf_head
);
2329 if (list_is_last(&lastbf
->list
, fifo_list
)) {
2330 list_splice_tail_init(fifo_list
, &bf_head
);
2331 INCR(txq
->txq_tailidx
, ATH_TXFIFO_DEPTH
);
2333 if (!list_empty(&txq
->axq_q
)) {
2334 struct list_head bf_q
;
2336 INIT_LIST_HEAD(&bf_q
);
2337 txq
->axq_link
= NULL
;
2338 list_splice_tail_init(&txq
->axq_q
, &bf_q
);
2339 ath_tx_txqaddbuf(sc
, txq
, &bf_q
, true);
2342 lastbf
->bf_stale
= true;
2344 list_cut_position(&bf_head
, fifo_list
,
2348 ath_tx_process_buffer(sc
, txq
, &ts
, bf
, &bf_head
);
2349 ath_txq_unlock_complete(sc
, txq
);
2357 static int ath_txstatus_setup(struct ath_softc
*sc
, int size
)
2359 struct ath_descdma
*dd
= &sc
->txsdma
;
2360 u8 txs_len
= sc
->sc_ah
->caps
.txs_len
;
2362 dd
->dd_desc_len
= size
* txs_len
;
2363 dd
->dd_desc
= dmam_alloc_coherent(sc
->dev
, dd
->dd_desc_len
,
2364 &dd
->dd_desc_paddr
, GFP_KERNEL
);
2371 static int ath_tx_edma_init(struct ath_softc
*sc
)
2375 err
= ath_txstatus_setup(sc
, ATH_TXSTATUS_RING_SIZE
);
2377 ath9k_hw_setup_statusring(sc
->sc_ah
, sc
->txsdma
.dd_desc
,
2378 sc
->txsdma
.dd_desc_paddr
,
2379 ATH_TXSTATUS_RING_SIZE
);
2384 int ath_tx_init(struct ath_softc
*sc
, int nbufs
)
2386 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2389 spin_lock_init(&sc
->tx
.txbuflock
);
2391 error
= ath_descdma_setup(sc
, &sc
->tx
.txdma
, &sc
->tx
.txbuf
,
2395 "Failed to allocate tx descriptors: %d\n", error
);
2399 error
= ath_descdma_setup(sc
, &sc
->beacon
.bdma
, &sc
->beacon
.bbuf
,
2400 "beacon", ATH_BCBUF
, 1, 1);
2403 "Failed to allocate beacon descriptors: %d\n", error
);
2407 INIT_DELAYED_WORK(&sc
->tx_complete_work
, ath_tx_complete_poll_work
);
2409 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
2410 error
= ath_tx_edma_init(sc
);
2415 void ath_tx_node_init(struct ath_softc
*sc
, struct ath_node
*an
)
2417 struct ath_atx_tid
*tid
;
2418 struct ath_atx_ac
*ac
;
2421 for (tidno
= 0, tid
= &an
->tid
[tidno
];
2422 tidno
< IEEE80211_NUM_TIDS
;
2426 tid
->seq_start
= tid
->seq_next
= 0;
2427 tid
->baw_size
= WME_MAX_BA
;
2428 tid
->baw_head
= tid
->baw_tail
= 0;
2430 tid
->paused
= false;
2431 tid
->state
&= ~AGGR_CLEANUP
;
2432 __skb_queue_head_init(&tid
->buf_q
);
2433 acno
= TID_TO_WME_AC(tidno
);
2434 tid
->ac
= &an
->ac
[acno
];
2435 tid
->state
&= ~AGGR_ADDBA_COMPLETE
;
2436 tid
->state
&= ~AGGR_ADDBA_PROGRESS
;
2437 tid
->stop_cb
= false;
2440 for (acno
= 0, ac
= &an
->ac
[acno
];
2441 acno
< IEEE80211_NUM_ACS
; acno
++, ac
++) {
2443 ac
->txq
= sc
->tx
.txq_map
[acno
];
2444 INIT_LIST_HEAD(&ac
->tid_q
);
2448 void ath_tx_node_cleanup(struct ath_softc
*sc
, struct ath_node
*an
)
2450 struct ath_atx_ac
*ac
;
2451 struct ath_atx_tid
*tid
;
2452 struct ath_txq
*txq
;
2455 for (tidno
= 0, tid
= &an
->tid
[tidno
];
2456 tidno
< IEEE80211_NUM_TIDS
; tidno
++, tid
++) {
2461 ath_txq_lock(sc
, txq
);
2464 list_del(&tid
->list
);
2469 list_del(&ac
->list
);
2470 tid
->ac
->sched
= false;
2473 ath_tid_drain(sc
, txq
, tid
);
2474 ath_tx_clear_tid(sc
, tid
);
2476 ath_txq_unlock(sc
, txq
);