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.
19 #define BITS_PER_BYTE 8
20 #define OFDM_PLCP_BITS 22
21 #define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)
22 #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
28 #define HT_LTF(_ns) (4 * (_ns))
29 #define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */
30 #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */
31 #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
32 #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
34 #define OFDM_SIFS_TIME 16
36 static u32 bits_per_symbol
[][2] = {
38 { 26, 54 }, /* 0: BPSK */
39 { 52, 108 }, /* 1: QPSK 1/2 */
40 { 78, 162 }, /* 2: QPSK 3/4 */
41 { 104, 216 }, /* 3: 16-QAM 1/2 */
42 { 156, 324 }, /* 4: 16-QAM 3/4 */
43 { 208, 432 }, /* 5: 64-QAM 2/3 */
44 { 234, 486 }, /* 6: 64-QAM 3/4 */
45 { 260, 540 }, /* 7: 64-QAM 5/6 */
46 { 52, 108 }, /* 8: BPSK */
47 { 104, 216 }, /* 9: QPSK 1/2 */
48 { 156, 324 }, /* 10: QPSK 3/4 */
49 { 208, 432 }, /* 11: 16-QAM 1/2 */
50 { 312, 648 }, /* 12: 16-QAM 3/4 */
51 { 416, 864 }, /* 13: 64-QAM 2/3 */
52 { 468, 972 }, /* 14: 64-QAM 3/4 */
53 { 520, 1080 }, /* 15: 64-QAM 5/6 */
56 #define IS_HT_RATE(_rate) ((_rate) & 0x80)
59 * Insert a chain of ath_buf (descriptors) on a txq and
60 * assume the descriptors are already chained together by caller.
61 * NB: must be called with txq lock held
64 static void ath_tx_txqaddbuf(struct ath_softc
*sc
, struct ath_txq
*txq
,
65 struct list_head
*head
)
67 struct ath_hal
*ah
= sc
->sc_ah
;
71 * Insert the frame on the outbound list and
72 * pass it on to the hardware.
78 bf
= list_first_entry(head
, struct ath_buf
, list
);
80 list_splice_tail_init(head
, &txq
->axq_q
);
82 txq
->axq_totalqueued
++;
83 txq
->axq_linkbuf
= list_entry(txq
->axq_q
.prev
, struct ath_buf
, list
);
85 DPRINTF(sc
, ATH_DBG_QUEUE
,
86 "qnum: %d, txq depth: %d\n", txq
->axq_qnum
, txq
->axq_depth
);
88 if (txq
->axq_link
== NULL
) {
89 ath9k_hw_puttxbuf(ah
, txq
->axq_qnum
, bf
->bf_daddr
);
90 DPRINTF(sc
, ATH_DBG_XMIT
,
91 "TXDP[%u] = %llx (%p)\n",
92 txq
->axq_qnum
, ito64(bf
->bf_daddr
), bf
->bf_desc
);
94 *txq
->axq_link
= bf
->bf_daddr
;
95 DPRINTF(sc
, ATH_DBG_XMIT
, "link[%u] (%p)=%llx (%p)\n",
96 txq
->axq_qnum
, txq
->axq_link
,
97 ito64(bf
->bf_daddr
), bf
->bf_desc
);
99 txq
->axq_link
= &(bf
->bf_lastbf
->bf_desc
->ds_link
);
100 ath9k_hw_txstart(ah
, txq
->axq_qnum
);
103 static void ath_tx_complete(struct ath_softc
*sc
, struct sk_buff
*skb
,
104 struct ath_xmit_status
*tx_status
)
106 struct ieee80211_hw
*hw
= sc
->hw
;
107 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
108 struct ath_tx_info_priv
*tx_info_priv
= ATH_TX_INFO_PRIV(tx_info
);
111 DPRINTF(sc
, ATH_DBG_XMIT
, "TX complete: skb: %p\n", skb
);
113 if (tx_info
->flags
& IEEE80211_TX_CTL_NO_ACK
||
114 tx_info
->flags
& IEEE80211_TX_STAT_TX_FILTERED
) {
116 tx_info
->rate_driver_data
[0] = NULL
;
119 if (tx_status
->flags
& ATH_TX_BAR
) {
120 tx_info
->flags
|= IEEE80211_TX_STAT_AMPDU_NO_BACK
;
121 tx_status
->flags
&= ~ATH_TX_BAR
;
124 if (!(tx_status
->flags
& (ATH_TX_ERROR
| ATH_TX_XRETRY
))) {
125 /* Frame was ACKed */
126 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
129 tx_info
->status
.rates
[0].count
= tx_status
->retries
;
130 if (tx_info
->status
.rates
[0].flags
& IEEE80211_TX_RC_MCS
) {
131 /* Change idx from internal table index to MCS index */
132 int idx
= tx_info
->status
.rates
[0].idx
;
133 struct ath_rate_table
*rate_table
= sc
->cur_rate_table
;
134 if (idx
>= 0 && idx
< rate_table
->rate_cnt
)
135 tx_info
->status
.rates
[0].idx
=
136 rate_table
->info
[idx
].ratecode
& 0x7f;
139 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
140 padsize
= hdrlen
& 3;
141 if (padsize
&& hdrlen
>= 24) {
143 * Remove MAC header padding before giving the frame back to
146 memmove(skb
->data
+ padsize
, skb
->data
, hdrlen
);
147 skb_pull(skb
, padsize
);
150 ieee80211_tx_status(hw
, skb
);
153 /* Check if it's okay to send out aggregates */
155 static int ath_aggr_query(struct ath_softc
*sc
, struct ath_node
*an
, u8 tidno
)
157 struct ath_atx_tid
*tid
;
158 tid
= ATH_AN_2_TID(an
, tidno
);
160 if (tid
->state
& AGGR_ADDBA_COMPLETE
||
161 tid
->state
& AGGR_ADDBA_PROGRESS
)
167 static void ath_get_beaconconfig(struct ath_softc
*sc
, int if_id
,
168 struct ath_beacon_config
*conf
)
170 struct ieee80211_hw
*hw
= sc
->hw
;
172 /* fill in beacon config data */
174 conf
->beacon_interval
= hw
->conf
.beacon_int
;
175 conf
->listen_interval
= 100;
176 conf
->dtim_count
= 1;
177 conf
->bmiss_timeout
= ATH_DEFAULT_BMISS_LIMIT
* conf
->listen_interval
;
180 /* Calculate Atheros packet type from IEEE80211 packet header */
182 static enum ath9k_pkt_type
get_hw_packet_type(struct sk_buff
*skb
)
184 struct ieee80211_hdr
*hdr
;
185 enum ath9k_pkt_type htype
;
188 hdr
= (struct ieee80211_hdr
*)skb
->data
;
189 fc
= hdr
->frame_control
;
191 if (ieee80211_is_beacon(fc
))
192 htype
= ATH9K_PKT_TYPE_BEACON
;
193 else if (ieee80211_is_probe_resp(fc
))
194 htype
= ATH9K_PKT_TYPE_PROBE_RESP
;
195 else if (ieee80211_is_atim(fc
))
196 htype
= ATH9K_PKT_TYPE_ATIM
;
197 else if (ieee80211_is_pspoll(fc
))
198 htype
= ATH9K_PKT_TYPE_PSPOLL
;
200 htype
= ATH9K_PKT_TYPE_NORMAL
;
205 static bool is_pae(struct sk_buff
*skb
)
207 struct ieee80211_hdr
*hdr
;
210 hdr
= (struct ieee80211_hdr
*)skb
->data
;
211 fc
= hdr
->frame_control
;
213 if (ieee80211_is_data(fc
)) {
214 if (ieee80211_is_nullfunc(fc
) ||
215 /* Port Access Entity (IEEE 802.1X) */
216 (skb
->protocol
== cpu_to_be16(ETH_P_PAE
))) {
224 static int get_hw_crypto_keytype(struct sk_buff
*skb
)
226 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
228 if (tx_info
->control
.hw_key
) {
229 if (tx_info
->control
.hw_key
->alg
== ALG_WEP
)
230 return ATH9K_KEY_TYPE_WEP
;
231 else if (tx_info
->control
.hw_key
->alg
== ALG_TKIP
)
232 return ATH9K_KEY_TYPE_TKIP
;
233 else if (tx_info
->control
.hw_key
->alg
== ALG_CCMP
)
234 return ATH9K_KEY_TYPE_AES
;
237 return ATH9K_KEY_TYPE_CLEAR
;
240 /* Called only when tx aggregation is enabled and HT is supported */
242 static void assign_aggr_tid_seqno(struct sk_buff
*skb
,
245 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
246 struct ieee80211_hdr
*hdr
;
248 struct ath_atx_tid
*tid
;
252 if (!tx_info
->control
.sta
)
255 an
= (struct ath_node
*)tx_info
->control
.sta
->drv_priv
;
256 hdr
= (struct ieee80211_hdr
*)skb
->data
;
257 fc
= hdr
->frame_control
;
261 if (ieee80211_is_data_qos(fc
)) {
262 qc
= ieee80211_get_qos_ctl(hdr
);
263 bf
->bf_tidno
= qc
[0] & 0xf;
267 /* For HT capable stations, we save tidno for later use.
268 * We also override seqno set by upper layer with the one
269 * in tx aggregation state.
271 * If fragmentation is on, the sequence number is
272 * not overridden, since it has been
273 * incremented by the fragmentation routine.
275 * FIXME: check if the fragmentation threshold exceeds
278 tid
= ATH_AN_2_TID(an
, bf
->bf_tidno
);
279 hdr
->seq_ctrl
= cpu_to_le16(tid
->seq_next
<<
280 IEEE80211_SEQ_SEQ_SHIFT
);
281 bf
->bf_seqno
= tid
->seq_next
;
282 INCR(tid
->seq_next
, IEEE80211_SEQ_MAX
);
285 static int setup_tx_flags(struct ath_softc
*sc
, struct sk_buff
*skb
,
288 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
291 flags
|= ATH9K_TXDESC_CLRDMASK
; /* needed for crypto errors */
292 flags
|= ATH9K_TXDESC_INTREQ
;
294 if (tx_info
->flags
& IEEE80211_TX_CTL_NO_ACK
)
295 flags
|= ATH9K_TXDESC_NOACK
;
296 if (tx_info
->control
.rates
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
)
297 flags
|= ATH9K_TXDESC_RTSENA
;
302 static struct ath_buf
*ath_tx_get_buffer(struct ath_softc
*sc
)
304 struct ath_buf
*bf
= NULL
;
306 spin_lock_bh(&sc
->tx
.txbuflock
);
308 if (unlikely(list_empty(&sc
->tx
.txbuf
))) {
309 spin_unlock_bh(&sc
->tx
.txbuflock
);
313 bf
= list_first_entry(&sc
->tx
.txbuf
, struct ath_buf
, list
);
316 spin_unlock_bh(&sc
->tx
.txbuflock
);
321 /* To complete a chain of buffers associated a frame */
323 static void ath_tx_complete_buf(struct ath_softc
*sc
,
325 struct list_head
*bf_q
,
326 int txok
, int sendbar
)
328 struct sk_buff
*skb
= bf
->bf_mpdu
;
329 struct ath_xmit_status tx_status
;
333 * Set retry information.
334 * NB: Don't use the information in the descriptor, because the frame
335 * could be software retried.
337 tx_status
.retries
= bf
->bf_retries
;
341 tx_status
.flags
= ATH_TX_BAR
;
344 tx_status
.flags
|= ATH_TX_ERROR
;
346 if (bf_isxretried(bf
))
347 tx_status
.flags
|= ATH_TX_XRETRY
;
350 /* Unmap this frame */
351 pci_unmap_single(sc
->pdev
,
355 /* complete this frame */
356 ath_tx_complete(sc
, skb
, &tx_status
);
359 * Return the list of ath_buf of this mpdu to free queue
361 spin_lock_irqsave(&sc
->tx
.txbuflock
, flags
);
362 list_splice_tail_init(bf_q
, &sc
->tx
.txbuf
);
363 spin_unlock_irqrestore(&sc
->tx
.txbuflock
, flags
);
367 * queue up a dest/ac pair for tx scheduling
368 * NB: must be called with txq lock held
371 static void ath_tx_queue_tid(struct ath_txq
*txq
, struct ath_atx_tid
*tid
)
373 struct ath_atx_ac
*ac
= tid
->ac
;
376 * if tid is paused, hold off
382 * add tid to ac atmost once
388 list_add_tail(&tid
->list
, &ac
->tid_q
);
391 * add node ac to txq atmost once
397 list_add_tail(&ac
->list
, &txq
->axq_acq
);
402 static void ath_tx_pause_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
)
404 struct ath_txq
*txq
= &sc
->tx
.txq
[tid
->ac
->qnum
];
406 spin_lock_bh(&txq
->axq_lock
);
410 spin_unlock_bh(&txq
->axq_lock
);
413 /* resume a tid and schedule aggregate */
415 void ath_tx_resume_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
)
417 struct ath_txq
*txq
= &sc
->tx
.txq
[tid
->ac
->qnum
];
419 ASSERT(tid
->paused
> 0);
420 spin_lock_bh(&txq
->axq_lock
);
427 if (list_empty(&tid
->buf_q
))
431 * Add this TID to scheduler and try to send out aggregates
433 ath_tx_queue_tid(txq
, tid
);
434 ath_txq_schedule(sc
, txq
);
436 spin_unlock_bh(&txq
->axq_lock
);
439 /* Compute the number of bad frames */
441 static int ath_tx_num_badfrms(struct ath_softc
*sc
, struct ath_buf
*bf
,
444 struct ath_buf
*bf_last
= bf
->bf_lastbf
;
445 struct ath_desc
*ds
= bf_last
->bf_desc
;
447 u32 ba
[WME_BA_BMP_SIZE
>> 5];
452 if (ds
->ds_txstat
.ts_flags
== ATH9K_TX_SW_ABORTED
)
455 isaggr
= bf_isaggr(bf
);
457 seq_st
= ATH_DS_BA_SEQ(ds
);
458 memcpy(ba
, ATH_DS_BA_BITMAP(ds
), WME_BA_BMP_SIZE
>> 3);
462 ba_index
= ATH_BA_INDEX(seq_st
, bf
->bf_seqno
);
463 if (!txok
|| (isaggr
&& !ATH_BA_ISSET(ba
, ba_index
)))
472 static void ath_tx_set_retry(struct ath_softc
*sc
, struct ath_buf
*bf
)
475 struct ieee80211_hdr
*hdr
;
477 bf
->bf_state
.bf_type
|= BUF_RETRY
;
481 hdr
= (struct ieee80211_hdr
*)skb
->data
;
482 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_RETRY
);
485 /* Update block ack window */
487 static void ath_tx_update_baw(struct ath_softc
*sc
, struct ath_atx_tid
*tid
,
492 index
= ATH_BA_INDEX(tid
->seq_start
, seqno
);
493 cindex
= (tid
->baw_head
+ index
) & (ATH_TID_MAX_BUFS
- 1);
495 tid
->tx_buf
[cindex
] = NULL
;
497 while (tid
->baw_head
!= tid
->baw_tail
&& !tid
->tx_buf
[tid
->baw_head
]) {
498 INCR(tid
->seq_start
, IEEE80211_SEQ_MAX
);
499 INCR(tid
->baw_head
, ATH_TID_MAX_BUFS
);
504 * ath_pkt_dur - compute packet duration (NB: not NAV)
507 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
508 * width - 0 for 20 MHz, 1 for 40 MHz
509 * half_gi - to use 4us v/s 3.6 us for symbol time
511 static u32
ath_pkt_duration(struct ath_softc
*sc
, u8 rix
, struct ath_buf
*bf
,
512 int width
, int half_gi
, bool shortPreamble
)
514 struct ath_rate_table
*rate_table
= sc
->cur_rate_table
;
515 u32 nbits
, nsymbits
, duration
, nsymbols
;
519 pktlen
= bf_isaggr(bf
) ? bf
->bf_al
: bf
->bf_frmlen
;
520 rc
= rate_table
->info
[rix
].ratecode
;
522 /* for legacy rates, use old function to compute packet duration */
524 return ath9k_hw_computetxtime(sc
->sc_ah
, rate_table
, pktlen
,
527 /* find number of symbols: PLCP + data */
528 nbits
= (pktlen
<< 3) + OFDM_PLCP_BITS
;
529 nsymbits
= bits_per_symbol
[HT_RC_2_MCS(rc
)][width
];
530 nsymbols
= (nbits
+ nsymbits
- 1) / nsymbits
;
533 duration
= SYMBOL_TIME(nsymbols
);
535 duration
= SYMBOL_TIME_HALFGI(nsymbols
);
537 /* addup duration for legacy/ht training and signal fields */
538 streams
= HT_RC_2_STREAMS(rc
);
539 duration
+= L_STF
+ L_LTF
+ L_SIG
+ HT_SIG
+ HT_STF
+ HT_LTF(streams
);
544 /* Rate module function to set rate related fields in tx descriptor */
546 static void ath_buf_set_rate(struct ath_softc
*sc
, struct ath_buf
*bf
)
548 struct ath_hal
*ah
= sc
->sc_ah
;
549 struct ath_rate_table
*rt
;
550 struct ath_desc
*ds
= bf
->bf_desc
;
551 struct ath_desc
*lastds
= bf
->bf_lastbf
->bf_desc
;
552 struct ath9k_11n_rate_series series
[4];
554 struct ieee80211_tx_info
*tx_info
;
555 struct ieee80211_tx_rate
*rates
;
556 struct ieee80211_hdr
*hdr
;
557 int i
, flags
, rtsctsena
= 0;
559 u8 rix
= 0, cix
, ctsrate
= 0;
562 memset(series
, 0, sizeof(struct ath9k_11n_rate_series
) * 4);
564 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
565 hdr
= (struct ieee80211_hdr
*)skb
->data
;
566 fc
= hdr
->frame_control
;
567 tx_info
= IEEE80211_SKB_CB(skb
);
568 rates
= tx_info
->control
.rates
;
570 if (ieee80211_has_morefrags(fc
) ||
571 (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
)) {
572 rates
[1].count
= rates
[2].count
= rates
[3].count
= 0;
573 rates
[1].idx
= rates
[2].idx
= rates
[3].idx
= 0;
574 rates
[0].count
= ATH_TXMAXTRY
;
577 /* get the cix for the lowest valid rix */
578 rt
= sc
->cur_rate_table
;
579 for (i
= 3; i
>= 0; i
--) {
580 if (rates
[i
].count
&& (rates
[i
].idx
>= 0)) {
586 flags
= (bf
->bf_flags
& (ATH9K_TXDESC_RTSENA
| ATH9K_TXDESC_CTSENA
));
587 cix
= rt
->info
[rix
].ctrl_rate
;
590 * If 802.11g protection is enabled, determine whether to use RTS/CTS or
591 * just CTS. Note that this is only done for OFDM/HT unicast frames.
593 if (sc
->sc_protmode
!= PROT_M_NONE
&& !(bf
->bf_flags
& ATH9K_TXDESC_NOACK
)
594 && (rt
->info
[rix
].phy
== WLAN_RC_PHY_OFDM
||
595 WLAN_RC_PHY_HT(rt
->info
[rix
].phy
))) {
596 if (sc
->sc_protmode
== PROT_M_RTSCTS
)
597 flags
= ATH9K_TXDESC_RTSENA
;
598 else if (sc
->sc_protmode
== PROT_M_CTSONLY
)
599 flags
= ATH9K_TXDESC_CTSENA
;
601 cix
= rt
->info
[sc
->sc_protrix
].ctrl_rate
;
605 /* For 11n, the default behavior is to enable RTS for hw retried frames.
606 * We enable the global flag here and let rate series flags determine
607 * which rates will actually use RTS.
609 if ((ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_HT
) && bf_isdata(bf
)) {
610 /* 802.11g protection not needed, use our default behavior */
612 flags
= ATH9K_TXDESC_RTSENA
;
615 /* Set protection if aggregate protection on */
616 if (sc
->sc_config
.ath_aggr_prot
&&
617 (!bf_isaggr(bf
) || (bf_isaggr(bf
) && bf
->bf_al
< 8192))) {
618 flags
= ATH9K_TXDESC_RTSENA
;
619 cix
= rt
->info
[sc
->sc_protrix
].ctrl_rate
;
623 /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
624 if (bf_isaggr(bf
) && (bf
->bf_al
> ah
->ah_caps
.rts_aggr_limit
))
625 flags
&= ~(ATH9K_TXDESC_RTSENA
);
628 * CTS transmit rate is derived from the transmit rate by looking in the
629 * h/w rate table. We must also factor in whether or not a short
630 * preamble is to be used. NB: cix is set above where RTS/CTS is enabled
632 ctsrate
= rt
->info
[cix
].ratecode
|
633 (bf_isshpreamble(bf
) ? rt
->info
[cix
].short_preamble
: 0);
635 for (i
= 0; i
< 4; i
++) {
636 if (!rates
[i
].count
|| (rates
[i
].idx
< 0))
641 series
[i
].Rate
= rt
->info
[rix
].ratecode
|
642 (bf_isshpreamble(bf
) ? rt
->info
[rix
].short_preamble
: 0);
644 series
[i
].Tries
= rates
[i
].count
;
646 series
[i
].RateFlags
= (
647 (rates
[i
].flags
& IEEE80211_TX_RC_USE_RTS_CTS
) ?
648 ATH9K_RATESERIES_RTS_CTS
: 0) |
649 ((rates
[i
].flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
) ?
650 ATH9K_RATESERIES_2040
: 0) |
651 ((rates
[i
].flags
& IEEE80211_TX_RC_SHORT_GI
) ?
652 ATH9K_RATESERIES_HALFGI
: 0);
654 series
[i
].PktDuration
= ath_pkt_duration(sc
, rix
, bf
,
655 (rates
[i
].flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
) != 0,
656 (rates
[i
].flags
& IEEE80211_TX_RC_SHORT_GI
),
657 bf_isshpreamble(bf
));
659 series
[i
].ChSel
= sc
->sc_tx_chainmask
;
662 series
[i
].RateFlags
|= ATH9K_RATESERIES_RTS_CTS
;
665 /* set dur_update_en for l-sig computation except for PS-Poll frames */
666 ath9k_hw_set11n_ratescenario(ah
, ds
, lastds
, !bf_ispspoll(bf
),
667 ctsrate
, ctsduration
,
670 if (sc
->sc_config
.ath_aggr_prot
&& flags
)
671 ath9k_hw_set11n_burstduration(ah
, ds
, 8192);
675 * Function to send a normal HT (non-AMPDU) frame
676 * NB: must be called with txq lock held
678 static int ath_tx_send_normal(struct ath_softc
*sc
,
680 struct ath_atx_tid
*tid
,
681 struct list_head
*bf_head
)
685 BUG_ON(list_empty(bf_head
));
687 bf
= list_first_entry(bf_head
, struct ath_buf
, list
);
688 bf
->bf_state
.bf_type
&= ~BUF_AMPDU
; /* regular HT frame */
690 /* update starting sequence number for subsequent ADDBA request */
691 INCR(tid
->seq_start
, IEEE80211_SEQ_MAX
);
693 /* Queue to h/w without aggregation */
695 bf
->bf_lastbf
= bf
->bf_lastfrm
; /* one single frame */
696 ath_buf_set_rate(sc
, bf
);
697 ath_tx_txqaddbuf(sc
, txq
, bf_head
);
702 /* flush tid's software queue and send frames as non-ampdu's */
704 static void ath_tx_flush_tid(struct ath_softc
*sc
, struct ath_atx_tid
*tid
)
706 struct ath_txq
*txq
= &sc
->tx
.txq
[tid
->ac
->qnum
];
708 struct list_head bf_head
;
709 INIT_LIST_HEAD(&bf_head
);
711 ASSERT(tid
->paused
> 0);
712 spin_lock_bh(&txq
->axq_lock
);
716 if (tid
->paused
> 0) {
717 spin_unlock_bh(&txq
->axq_lock
);
721 while (!list_empty(&tid
->buf_q
)) {
722 bf
= list_first_entry(&tid
->buf_q
, struct ath_buf
, list
);
723 ASSERT(!bf_isretried(bf
));
724 list_cut_position(&bf_head
, &tid
->buf_q
, &bf
->bf_lastfrm
->list
);
725 ath_tx_send_normal(sc
, txq
, tid
, &bf_head
);
728 spin_unlock_bh(&txq
->axq_lock
);
731 /* Completion routine of an aggregate */
733 static void ath_tx_complete_aggr_rifs(struct ath_softc
*sc
,
736 struct list_head
*bf_q
,
739 struct ath_node
*an
= NULL
;
741 struct ieee80211_tx_info
*tx_info
;
742 struct ath_atx_tid
*tid
= NULL
;
743 struct ath_buf
*bf_last
= bf
->bf_lastbf
;
744 struct ath_desc
*ds
= bf_last
->bf_desc
;
745 struct ath_buf
*bf_next
, *bf_lastq
= NULL
;
746 struct list_head bf_head
, bf_pending
;
748 u32 ba
[WME_BA_BMP_SIZE
>> 5];
749 int isaggr
, txfail
, txpending
, sendbar
= 0, needreset
= 0;
751 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
752 tx_info
= IEEE80211_SKB_CB(skb
);
754 if (tx_info
->control
.sta
) {
755 an
= (struct ath_node
*)tx_info
->control
.sta
->drv_priv
;
756 tid
= ATH_AN_2_TID(an
, bf
->bf_tidno
);
759 isaggr
= bf_isaggr(bf
);
762 if (ATH_DS_TX_BA(ds
)) {
764 * extract starting sequence and
767 seq_st
= ATH_DS_BA_SEQ(ds
);
769 ATH_DS_BA_BITMAP(ds
),
770 WME_BA_BMP_SIZE
>> 3);
772 memset(ba
, 0, WME_BA_BMP_SIZE
>> 3);
775 * AR5416 can become deaf/mute when BA
776 * issue happens. Chip needs to be reset.
777 * But AP code may have sychronization issues
778 * when perform internal reset in this routine.
779 * Only enable reset in STA mode for now.
781 if (sc
->sc_ah
->ah_opmode
==
782 NL80211_IFTYPE_STATION
)
786 memset(ba
, 0, WME_BA_BMP_SIZE
>> 3);
790 INIT_LIST_HEAD(&bf_pending
);
791 INIT_LIST_HEAD(&bf_head
);
794 txfail
= txpending
= 0;
795 bf_next
= bf
->bf_next
;
797 if (ATH_BA_ISSET(ba
, ATH_BA_INDEX(seq_st
, bf
->bf_seqno
))) {
798 /* transmit completion, subframe is
799 * acked by block ack */
800 } else if (!isaggr
&& txok
) {
801 /* transmit completion */
804 if (!(tid
->state
& AGGR_CLEANUP
) &&
805 ds
->ds_txstat
.ts_flags
!= ATH9K_TX_SW_ABORTED
) {
806 if (bf
->bf_retries
< ATH_MAX_SW_RETRIES
) {
807 ath_tx_set_retry(sc
, bf
);
810 bf
->bf_state
.bf_type
|= BUF_XRETRY
;
816 * cleanup in progress, just fail
817 * the un-acked sub-frames
823 * Remove ath_buf's of this sub-frame from aggregate queue.
825 if (bf_next
== NULL
) { /* last subframe in the aggregate */
826 ASSERT(bf
->bf_lastfrm
== bf_last
);
829 * The last descriptor of the last sub frame could be
830 * a holding descriptor for h/w. If that's the case,
831 * bf->bf_lastfrm won't be in the bf_q.
832 * Make sure we handle bf_q properly here.
835 if (!list_empty(bf_q
)) {
836 bf_lastq
= list_entry(bf_q
->prev
,
837 struct ath_buf
, list
);
838 list_cut_position(&bf_head
,
839 bf_q
, &bf_lastq
->list
);
842 * XXX: if the last subframe only has one
843 * descriptor which is also being used as
844 * a holding descriptor. Then the ath_buf
845 * is not in the bf_q at all.
847 INIT_LIST_HEAD(&bf_head
);
850 ASSERT(!list_empty(bf_q
));
851 list_cut_position(&bf_head
,
852 bf_q
, &bf
->bf_lastfrm
->list
);
857 * complete the acked-ones/xretried ones; update
860 spin_lock_bh(&txq
->axq_lock
);
861 ath_tx_update_baw(sc
, tid
, bf
->bf_seqno
);
862 spin_unlock_bh(&txq
->axq_lock
);
864 /* complete this sub-frame */
865 ath_tx_complete_buf(sc
, bf
, &bf_head
, !txfail
, sendbar
);
868 * retry the un-acked ones
871 * XXX: if the last descriptor is holding descriptor,
872 * in order to requeue the frame to software queue, we
873 * need to allocate a new descriptor and
874 * copy the content of holding descriptor to it.
876 if (bf
->bf_next
== NULL
&&
877 bf_last
->bf_status
& ATH_BUFSTATUS_STALE
) {
880 /* allocate new descriptor */
881 spin_lock_bh(&sc
->tx
.txbuflock
);
882 ASSERT(!list_empty((&sc
->tx
.txbuf
)));
883 tbf
= list_first_entry(&sc
->tx
.txbuf
,
884 struct ath_buf
, list
);
885 list_del(&tbf
->list
);
886 spin_unlock_bh(&sc
->tx
.txbuflock
);
888 ATH_TXBUF_RESET(tbf
);
890 /* copy descriptor content */
891 tbf
->bf_mpdu
= bf_last
->bf_mpdu
;
892 tbf
->bf_buf_addr
= bf_last
->bf_buf_addr
;
893 *(tbf
->bf_desc
) = *(bf_last
->bf_desc
);
895 /* link it to the frame */
897 bf_lastq
->bf_desc
->ds_link
=
899 bf
->bf_lastfrm
= tbf
;
900 ath9k_hw_cleartxdesc(sc
->sc_ah
,
901 bf
->bf_lastfrm
->bf_desc
);
903 tbf
->bf_state
= bf_last
->bf_state
;
904 tbf
->bf_lastfrm
= tbf
;
905 ath9k_hw_cleartxdesc(sc
->sc_ah
,
906 tbf
->bf_lastfrm
->bf_desc
);
908 /* copy the DMA context */
910 bf_last
->bf_dmacontext
;
912 list_add_tail(&tbf
->list
, &bf_head
);
915 * Clear descriptor status words for
918 ath9k_hw_cleartxdesc(sc
->sc_ah
,
919 bf
->bf_lastfrm
->bf_desc
);
923 * Put this buffer to the temporary pending
924 * queue to retain ordering
926 list_splice_tail_init(&bf_head
, &bf_pending
);
932 if (tid
->state
& AGGR_CLEANUP
) {
933 /* check to see if we're done with cleaning the h/w queue */
934 spin_lock_bh(&txq
->axq_lock
);
936 if (tid
->baw_head
== tid
->baw_tail
) {
937 tid
->state
&= ~AGGR_ADDBA_COMPLETE
;
938 tid
->addba_exchangeattempts
= 0;
939 spin_unlock_bh(&txq
->axq_lock
);
941 tid
->state
&= ~AGGR_CLEANUP
;
943 /* send buffered frames as singles */
944 ath_tx_flush_tid(sc
, tid
);
946 spin_unlock_bh(&txq
->axq_lock
);
952 * prepend un-acked frames to the beginning of the pending frame queue
954 if (!list_empty(&bf_pending
)) {
955 spin_lock_bh(&txq
->axq_lock
);
956 /* Note: we _prepend_, we _do_not_ at to
957 * the end of the queue ! */
958 list_splice(&bf_pending
, &tid
->buf_q
);
959 ath_tx_queue_tid(txq
, tid
);
960 spin_unlock_bh(&txq
->axq_lock
);
964 ath_reset(sc
, false);
969 static void ath_tx_rc_status(struct ath_buf
*bf
, struct ath_desc
*ds
, int nbad
)
971 struct sk_buff
*skb
= (struct sk_buff
*)bf
->bf_mpdu
;
972 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
973 struct ath_tx_info_priv
*tx_info_priv
= ATH_TX_INFO_PRIV(tx_info
);
975 tx_info_priv
->update_rc
= false;
976 if (ds
->ds_txstat
.ts_status
& ATH9K_TXERR_FILT
)
977 tx_info
->flags
|= IEEE80211_TX_STAT_TX_FILTERED
;
979 if ((ds
->ds_txstat
.ts_status
& ATH9K_TXERR_FILT
) == 0 &&
980 (bf
->bf_flags
& ATH9K_TXDESC_NOACK
) == 0) {
982 memcpy(&tx_info_priv
->tx
, &ds
->ds_txstat
,
983 sizeof(tx_info_priv
->tx
));
984 tx_info_priv
->n_frames
= bf
->bf_nframes
;
985 tx_info_priv
->n_bad_frames
= nbad
;
986 tx_info_priv
->update_rc
= true;
991 /* Process completed xmit descriptors from the specified queue */
993 static void ath_tx_processq(struct ath_softc
*sc
, struct ath_txq
*txq
)
995 struct ath_hal
*ah
= sc
->sc_ah
;
996 struct ath_buf
*bf
, *lastbf
, *bf_held
= NULL
;
997 struct list_head bf_head
;
1002 DPRINTF(sc
, ATH_DBG_QUEUE
, "tx queue %d (%x), link %p\n",
1003 txq
->axq_qnum
, ath9k_hw_gettxbuf(sc
->sc_ah
, txq
->axq_qnum
),
1007 spin_lock_bh(&txq
->axq_lock
);
1008 if (list_empty(&txq
->axq_q
)) {
1009 txq
->axq_link
= NULL
;
1010 txq
->axq_linkbuf
= NULL
;
1011 spin_unlock_bh(&txq
->axq_lock
);
1014 bf
= list_first_entry(&txq
->axq_q
, struct ath_buf
, list
);
1017 * There is a race condition that a BH gets scheduled
1018 * after sw writes TxE and before hw re-load the last
1019 * descriptor to get the newly chained one.
1020 * Software must keep the last DONE descriptor as a
1021 * holding descriptor - software does so by marking
1022 * it with the STALE flag.
1025 if (bf
->bf_status
& ATH_BUFSTATUS_STALE
) {
1027 if (list_is_last(&bf_held
->list
, &txq
->axq_q
)) {
1029 * The holding descriptor is the last
1030 * descriptor in queue. It's safe to remove
1031 * the last holding descriptor in BH context.
1033 spin_unlock_bh(&txq
->axq_lock
);
1036 /* Lets work with the next buffer now */
1037 bf
= list_entry(bf_held
->list
.next
,
1038 struct ath_buf
, list
);
1042 lastbf
= bf
->bf_lastbf
;
1043 ds
= lastbf
->bf_desc
; /* NB: last decriptor */
1045 status
= ath9k_hw_txprocdesc(ah
, ds
);
1046 if (status
== -EINPROGRESS
) {
1047 spin_unlock_bh(&txq
->axq_lock
);
1050 if (bf
->bf_desc
== txq
->axq_lastdsWithCTS
)
1051 txq
->axq_lastdsWithCTS
= NULL
;
1052 if (ds
== txq
->axq_gatingds
)
1053 txq
->axq_gatingds
= NULL
;
1056 * Remove ath_buf's of the same transmit unit from txq,
1057 * however leave the last descriptor back as the holding
1058 * descriptor for hw.
1060 lastbf
->bf_status
|= ATH_BUFSTATUS_STALE
;
1061 INIT_LIST_HEAD(&bf_head
);
1063 if (!list_is_singular(&lastbf
->list
))
1064 list_cut_position(&bf_head
,
1065 &txq
->axq_q
, lastbf
->list
.prev
);
1070 txq
->axq_aggr_depth
--;
1072 txok
= (ds
->ds_txstat
.ts_status
== 0);
1074 spin_unlock_bh(&txq
->axq_lock
);
1077 list_del(&bf_held
->list
);
1078 spin_lock_bh(&sc
->tx
.txbuflock
);
1079 list_add_tail(&bf_held
->list
, &sc
->tx
.txbuf
);
1080 spin_unlock_bh(&sc
->tx
.txbuflock
);
1083 if (!bf_isampdu(bf
)) {
1085 * This frame is sent out as a single frame.
1086 * Use hardware retry status for this frame.
1088 bf
->bf_retries
= ds
->ds_txstat
.ts_longretry
;
1089 if (ds
->ds_txstat
.ts_status
& ATH9K_TXERR_XRETRY
)
1090 bf
->bf_state
.bf_type
|= BUF_XRETRY
;
1093 nbad
= ath_tx_num_badfrms(sc
, bf
, txok
);
1096 ath_tx_rc_status(bf
, ds
, nbad
);
1099 * Complete this transmit unit
1102 ath_tx_complete_aggr_rifs(sc
, txq
, bf
, &bf_head
, txok
);
1104 ath_tx_complete_buf(sc
, bf
, &bf_head
, txok
, 0);
1106 /* Wake up mac80211 queue */
1108 spin_lock_bh(&txq
->axq_lock
);
1109 if (txq
->stopped
&& ath_txq_depth(sc
, txq
->axq_qnum
) <=
1112 qnum
= ath_get_mac80211_qnum(txq
->axq_qnum
, sc
);
1114 ieee80211_wake_queue(sc
->hw
, qnum
);
1121 * schedule any pending packets if aggregation is enabled
1123 if (sc
->sc_flags
& SC_OP_TXAGGR
)
1124 ath_txq_schedule(sc
, txq
);
1125 spin_unlock_bh(&txq
->axq_lock
);
1129 static void ath_tx_stopdma(struct ath_softc
*sc
, struct ath_txq
*txq
)
1131 struct ath_hal
*ah
= sc
->sc_ah
;
1133 (void) ath9k_hw_stoptxdma(ah
, txq
->axq_qnum
);
1134 DPRINTF(sc
, ATH_DBG_XMIT
, "tx queue [%u] %x, link %p\n",
1135 txq
->axq_qnum
, ath9k_hw_gettxbuf(ah
, txq
->axq_qnum
),
1139 /* Drain only the data queues */
1141 static void ath_drain_txdataq(struct ath_softc
*sc
, bool retry_tx
)
1143 struct ath_hal
*ah
= sc
->sc_ah
;
1144 int i
, status
, npend
= 0;
1146 if (!(sc
->sc_flags
& SC_OP_INVALID
)) {
1147 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1148 if (ATH_TXQ_SETUP(sc
, i
)) {
1149 ath_tx_stopdma(sc
, &sc
->tx
.txq
[i
]);
1150 /* The TxDMA may not really be stopped.
1151 * Double check the hal tx pending count */
1152 npend
+= ath9k_hw_numtxpending(ah
,
1153 sc
->tx
.txq
[i
].axq_qnum
);
1159 /* TxDMA not stopped, reset the hal */
1160 DPRINTF(sc
, ATH_DBG_XMIT
, "Unable to stop TxDMA. Reset HAL!\n");
1162 spin_lock_bh(&sc
->sc_resetlock
);
1163 if (!ath9k_hw_reset(ah
,
1164 sc
->sc_ah
->ah_curchan
,
1166 sc
->sc_tx_chainmask
, sc
->sc_rx_chainmask
,
1167 sc
->sc_ht_extprotspacing
, true, &status
)) {
1169 DPRINTF(sc
, ATH_DBG_FATAL
,
1170 "Unable to reset hardware; hal status %u\n",
1173 spin_unlock_bh(&sc
->sc_resetlock
);
1176 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1177 if (ATH_TXQ_SETUP(sc
, i
))
1178 ath_tx_draintxq(sc
, &sc
->tx
.txq
[i
], retry_tx
);
1182 /* Add a sub-frame to block ack window */
1184 static void ath_tx_addto_baw(struct ath_softc
*sc
,
1185 struct ath_atx_tid
*tid
,
1190 if (bf_isretried(bf
))
1193 index
= ATH_BA_INDEX(tid
->seq_start
, bf
->bf_seqno
);
1194 cindex
= (tid
->baw_head
+ index
) & (ATH_TID_MAX_BUFS
- 1);
1196 ASSERT(tid
->tx_buf
[cindex
] == NULL
);
1197 tid
->tx_buf
[cindex
] = bf
;
1199 if (index
>= ((tid
->baw_tail
- tid
->baw_head
) &
1200 (ATH_TID_MAX_BUFS
- 1))) {
1201 tid
->baw_tail
= cindex
;
1202 INCR(tid
->baw_tail
, ATH_TID_MAX_BUFS
);
1207 * Function to send an A-MPDU
1208 * NB: must be called with txq lock held
1210 static int ath_tx_send_ampdu(struct ath_softc
*sc
,
1211 struct ath_atx_tid
*tid
,
1212 struct list_head
*bf_head
,
1213 struct ath_tx_control
*txctl
)
1217 BUG_ON(list_empty(bf_head
));
1219 bf
= list_first_entry(bf_head
, struct ath_buf
, list
);
1220 bf
->bf_state
.bf_type
|= BUF_AMPDU
;
1223 * Do not queue to h/w when any of the following conditions is true:
1224 * - there are pending frames in software queue
1225 * - the TID is currently paused for ADDBA/BAR request
1226 * - seqno is not within block-ack window
1227 * - h/w queue depth exceeds low water mark
1229 if (!list_empty(&tid
->buf_q
) || tid
->paused
||
1230 !BAW_WITHIN(tid
->seq_start
, tid
->baw_size
, bf
->bf_seqno
) ||
1231 txctl
->txq
->axq_depth
>= ATH_AGGR_MIN_QDEPTH
) {
1233 * Add this frame to software queue for scheduling later
1236 list_splice_tail_init(bf_head
, &tid
->buf_q
);
1237 ath_tx_queue_tid(txctl
->txq
, tid
);
1241 /* Add sub-frame to BAW */
1242 ath_tx_addto_baw(sc
, tid
, bf
);
1244 /* Queue to h/w without aggregation */
1246 bf
->bf_lastbf
= bf
->bf_lastfrm
; /* one single frame */
1247 ath_buf_set_rate(sc
, bf
);
1248 ath_tx_txqaddbuf(sc
, txctl
->txq
, bf_head
);
1255 * returns aggr limit based on lowest of the rates
1257 static u32
ath_lookup_rate(struct ath_softc
*sc
,
1259 struct ath_atx_tid
*tid
)
1261 struct ath_rate_table
*rate_table
= sc
->cur_rate_table
;
1262 struct sk_buff
*skb
;
1263 struct ieee80211_tx_info
*tx_info
;
1264 struct ieee80211_tx_rate
*rates
;
1265 struct ath_tx_info_priv
*tx_info_priv
;
1266 u32 max_4ms_framelen
, frame_length
;
1267 u16 aggr_limit
, legacy
= 0, maxampdu
;
1270 skb
= (struct sk_buff
*)bf
->bf_mpdu
;
1271 tx_info
= IEEE80211_SKB_CB(skb
);
1272 rates
= tx_info
->control
.rates
;
1274 (struct ath_tx_info_priv
*)tx_info
->rate_driver_data
[0];
1277 * Find the lowest frame length among the rate series that will have a
1278 * 4ms transmit duration.
1279 * TODO - TXOP limit needs to be considered.
1281 max_4ms_framelen
= ATH_AMPDU_LIMIT_MAX
;
1283 for (i
= 0; i
< 4; i
++) {
1284 if (rates
[i
].count
) {
1285 if (!WLAN_RC_PHY_HT(rate_table
->info
[rates
[i
].idx
].phy
)) {
1291 rate_table
->info
[rates
[i
].idx
].max_4ms_framelen
;
1292 max_4ms_framelen
= min(max_4ms_framelen
, frame_length
);
1297 * limit aggregate size by the minimum rate if rate selected is
1298 * not a probe rate, if rate selected is a probe rate then
1299 * avoid aggregation of this packet.
1301 if (tx_info
->flags
& IEEE80211_TX_CTL_RATE_CTRL_PROBE
|| legacy
)
1304 aggr_limit
= min(max_4ms_framelen
,
1305 (u32
)ATH_AMPDU_LIMIT_DEFAULT
);
1308 * h/w can accept aggregates upto 16 bit lengths (65535).
1309 * The IE, however can hold upto 65536, which shows up here
1310 * as zero. Ignore 65536 since we are constrained by hw.
1312 maxampdu
= tid
->an
->maxampdu
;
1314 aggr_limit
= min(aggr_limit
, maxampdu
);
1320 * returns the number of delimiters to be added to
1321 * meet the minimum required mpdudensity.
1322 * caller should make sure that the rate is HT rate .
1324 static int ath_compute_num_delims(struct ath_softc
*sc
,
1325 struct ath_atx_tid
*tid
,
1329 struct ath_rate_table
*rt
= sc
->cur_rate_table
;
1330 struct sk_buff
*skb
= bf
->bf_mpdu
;
1331 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
1332 u32 nsymbits
, nsymbols
, mpdudensity
;
1335 int width
, half_gi
, ndelim
, mindelim
;
1337 /* Select standard number of delimiters based on frame length alone */
1338 ndelim
= ATH_AGGR_GET_NDELIM(frmlen
);
1341 * If encryption enabled, hardware requires some more padding between
1343 * TODO - this could be improved to be dependent on the rate.
1344 * The hardware can keep up at lower rates, but not higher rates
1346 if (bf
->bf_keytype
!= ATH9K_KEY_TYPE_CLEAR
)
1347 ndelim
+= ATH_AGGR_ENCRYPTDELIM
;
1350 * Convert desired mpdu density from microeconds to bytes based
1351 * on highest rate in rate series (i.e. first rate) to determine
1352 * required minimum length for subframe. Take into account
1353 * whether high rate is 20 or 40Mhz and half or full GI.
1355 mpdudensity
= tid
->an
->mpdudensity
;
1358 * If there is no mpdu density restriction, no further calculation
1361 if (mpdudensity
== 0)
1364 rix
= tx_info
->control
.rates
[0].idx
;
1365 flags
= tx_info
->control
.rates
[0].flags
;
1366 rc
= rt
->info
[rix
].ratecode
;
1367 width
= (flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
) ? 1 : 0;
1368 half_gi
= (flags
& IEEE80211_TX_RC_SHORT_GI
) ? 1 : 0;
1371 nsymbols
= NUM_SYMBOLS_PER_USEC_HALFGI(mpdudensity
);
1373 nsymbols
= NUM_SYMBOLS_PER_USEC(mpdudensity
);
1378 nsymbits
= bits_per_symbol
[HT_RC_2_MCS(rc
)][width
];
1379 minlen
= (nsymbols
* nsymbits
) / BITS_PER_BYTE
;
1381 /* Is frame shorter than required minimum length? */
1382 if (frmlen
< minlen
) {
1383 /* Get the minimum number of delimiters required. */
1384 mindelim
= (minlen
- frmlen
) / ATH_AGGR_DELIM_SZ
;
1385 ndelim
= max(mindelim
, ndelim
);
1392 * For aggregation from software buffer queue.
1393 * NB: must be called with txq lock held
1395 static enum ATH_AGGR_STATUS
ath_tx_form_aggr(struct ath_softc
*sc
,
1396 struct ath_atx_tid
*tid
,
1397 struct list_head
*bf_q
,
1398 struct ath_buf
**bf_last
,
1399 struct aggr_rifs_param
*param
,
1402 #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
1403 struct ath_buf
*bf
, *tbf
, *bf_first
, *bf_prev
= NULL
;
1404 struct list_head bf_head
;
1405 int rl
= 0, nframes
= 0, ndelim
;
1406 u16 aggr_limit
= 0, al
= 0, bpad
= 0,
1407 al_delta
, h_baw
= tid
->baw_size
/ 2;
1408 enum ATH_AGGR_STATUS status
= ATH_AGGR_DONE
;
1410 INIT_LIST_HEAD(&bf_head
);
1412 BUG_ON(list_empty(&tid
->buf_q
));
1414 bf_first
= list_first_entry(&tid
->buf_q
, struct ath_buf
, list
);
1417 bf
= list_first_entry(&tid
->buf_q
, struct ath_buf
, list
);
1420 * do not step over block-ack window
1422 if (!BAW_WITHIN(tid
->seq_start
, tid
->baw_size
, bf
->bf_seqno
)) {
1423 status
= ATH_AGGR_BAW_CLOSED
;
1428 aggr_limit
= ath_lookup_rate(sc
, bf
, tid
);
1433 * do not exceed aggregation limit
1435 al_delta
= ATH_AGGR_DELIM_SZ
+ bf
->bf_frmlen
;
1437 if (nframes
&& (aggr_limit
<
1438 (al
+ bpad
+ al_delta
+ prev_al
))) {
1439 status
= ATH_AGGR_LIMITED
;
1444 * do not exceed subframe limit
1446 if ((nframes
+ *prev_frames
) >=
1447 min((int)h_baw
, ATH_AMPDU_SUBFRAME_DEFAULT
)) {
1448 status
= ATH_AGGR_LIMITED
;
1453 * add padding for previous frame to aggregation length
1455 al
+= bpad
+ al_delta
;
1458 * Get the delimiters needed to meet the MPDU
1459 * density for this node.
1461 ndelim
= ath_compute_num_delims(sc
, tid
, bf_first
, bf
->bf_frmlen
);
1463 bpad
= PADBYTES(al_delta
) + (ndelim
<< 2);
1466 bf
->bf_lastfrm
->bf_desc
->ds_link
= 0;
1469 * this packet is part of an aggregate
1470 * - remove all descriptors belonging to this frame from
1472 * - add it to block ack window
1473 * - set up descriptors for aggregation
1475 list_cut_position(&bf_head
, &tid
->buf_q
, &bf
->bf_lastfrm
->list
);
1476 ath_tx_addto_baw(sc
, tid
, bf
);
1478 list_for_each_entry(tbf
, &bf_head
, list
) {
1479 ath9k_hw_set11n_aggr_middle(sc
->sc_ah
,
1480 tbf
->bf_desc
, ndelim
);
1484 * link buffers of this frame to the aggregate
1486 list_splice_tail_init(&bf_head
, bf_q
);
1490 bf_prev
->bf_next
= bf
;
1491 bf_prev
->bf_lastfrm
->bf_desc
->ds_link
= bf
->bf_daddr
;
1497 * terminate aggregation on a small packet boundary
1499 if (bf
->bf_frmlen
< ATH_AGGR_MINPLEN
) {
1500 status
= ATH_AGGR_SHORTPKT
;
1504 } while (!list_empty(&tid
->buf_q
));
1506 bf_first
->bf_al
= al
;
1507 bf_first
->bf_nframes
= nframes
;
1514 * process pending frames possibly doing a-mpdu aggregation
1515 * NB: must be called with txq lock held
1517 static void ath_tx_sched_aggr(struct ath_softc
*sc
,
1518 struct ath_txq
*txq
, struct ath_atx_tid
*tid
)
1520 struct ath_buf
*bf
, *tbf
, *bf_last
, *bf_lastaggr
= NULL
;
1521 enum ATH_AGGR_STATUS status
;
1522 struct list_head bf_q
;
1523 struct aggr_rifs_param param
= {0, 0, 0, 0, NULL
};
1524 int prev_frames
= 0;
1527 if (list_empty(&tid
->buf_q
))
1530 INIT_LIST_HEAD(&bf_q
);
1532 status
= ath_tx_form_aggr(sc
, tid
, &bf_q
, &bf_lastaggr
, ¶m
,
1536 * no frames picked up to be aggregated; block-ack
1537 * window is not open
1539 if (list_empty(&bf_q
))
1542 bf
= list_first_entry(&bf_q
, struct ath_buf
, list
);
1543 bf_last
= list_entry(bf_q
.prev
, struct ath_buf
, list
);
1544 bf
->bf_lastbf
= bf_last
;
1547 * if only one frame, send as non-aggregate
1549 if (bf
->bf_nframes
== 1) {
1550 ASSERT(bf
->bf_lastfrm
== bf_last
);
1552 bf
->bf_state
.bf_type
&= ~BUF_AGGR
;
1554 * clear aggr bits for every descriptor
1555 * XXX TODO: is there a way to optimize it?
1557 list_for_each_entry(tbf
, &bf_q
, list
) {
1558 ath9k_hw_clr11n_aggr(sc
->sc_ah
, tbf
->bf_desc
);
1561 ath_buf_set_rate(sc
, bf
);
1562 ath_tx_txqaddbuf(sc
, txq
, &bf_q
);
1567 * setup first desc with rate and aggr info
1569 bf
->bf_state
.bf_type
|= BUF_AGGR
;
1570 ath_buf_set_rate(sc
, bf
);
1571 ath9k_hw_set11n_aggr_first(sc
->sc_ah
, bf
->bf_desc
, bf
->bf_al
);
1574 * anchor last frame of aggregate correctly
1576 ASSERT(bf_lastaggr
);
1577 ASSERT(bf_lastaggr
->bf_lastfrm
== bf_last
);
1579 ath9k_hw_set11n_aggr_last(sc
->sc_ah
, tbf
->bf_desc
);
1581 /* XXX: We don't enter into this loop, consider removing this */
1582 while (!list_empty(&bf_q
) && !list_is_last(&tbf
->list
, &bf_q
)) {
1583 tbf
= list_entry(tbf
->list
.next
, struct ath_buf
, list
);
1584 ath9k_hw_set11n_aggr_last(sc
->sc_ah
, tbf
->bf_desc
);
1587 txq
->axq_aggr_depth
++;
1590 * Normal aggregate, queue to hardware
1592 ath_tx_txqaddbuf(sc
, txq
, &bf_q
);
1594 } while (txq
->axq_depth
< ATH_AGGR_MIN_QDEPTH
&&
1595 status
!= ATH_AGGR_BAW_CLOSED
);
1598 /* Called with txq lock held */
1600 static void ath_tid_drain(struct ath_softc
*sc
,
1601 struct ath_txq
*txq
,
1602 struct ath_atx_tid
*tid
)
1606 struct list_head bf_head
;
1607 INIT_LIST_HEAD(&bf_head
);
1610 if (list_empty(&tid
->buf_q
))
1612 bf
= list_first_entry(&tid
->buf_q
, struct ath_buf
, list
);
1614 list_cut_position(&bf_head
, &tid
->buf_q
, &bf
->bf_lastfrm
->list
);
1616 /* update baw for software retried frame */
1617 if (bf_isretried(bf
))
1618 ath_tx_update_baw(sc
, tid
, bf
->bf_seqno
);
1621 * do not indicate packets while holding txq spinlock.
1622 * unlock is intentional here
1624 spin_unlock(&txq
->axq_lock
);
1626 /* complete this sub-frame */
1627 ath_tx_complete_buf(sc
, bf
, &bf_head
, 0, 0);
1629 spin_lock(&txq
->axq_lock
);
1633 * TODO: For frame(s) that are in the retry state, we will reuse the
1634 * sequence number(s) without setting the retry bit. The
1635 * alternative is to give up on these and BAR the receiver's window
1638 tid
->seq_next
= tid
->seq_start
;
1639 tid
->baw_tail
= tid
->baw_head
;
1643 * Drain all pending buffers
1644 * NB: must be called with txq lock held
1646 static void ath_txq_drain_pending_buffers(struct ath_softc
*sc
,
1647 struct ath_txq
*txq
)
1649 struct ath_atx_ac
*ac
, *ac_tmp
;
1650 struct ath_atx_tid
*tid
, *tid_tmp
;
1652 list_for_each_entry_safe(ac
, ac_tmp
, &txq
->axq_acq
, list
) {
1653 list_del(&ac
->list
);
1655 list_for_each_entry_safe(tid
, tid_tmp
, &ac
->tid_q
, list
) {
1656 list_del(&tid
->list
);
1658 ath_tid_drain(sc
, txq
, tid
);
1663 static int ath_tx_setup_buffer(struct ath_softc
*sc
, struct ath_buf
*bf
,
1664 struct sk_buff
*skb
,
1665 struct ath_tx_control
*txctl
)
1667 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
1668 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1669 struct ath_tx_info_priv
*tx_info_priv
;
1673 tx_info_priv
= kzalloc(sizeof(*tx_info_priv
), GFP_ATOMIC
);
1674 if (unlikely(!tx_info_priv
))
1676 tx_info
->rate_driver_data
[0] = tx_info_priv
;
1677 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
1678 fc
= hdr
->frame_control
;
1680 ATH_TXBUF_RESET(bf
);
1684 bf
->bf_frmlen
= skb
->len
+ FCS_LEN
- (hdrlen
& 3);
1686 ieee80211_is_data(fc
) ?
1687 (bf
->bf_state
.bf_type
|= BUF_DATA
) :
1688 (bf
->bf_state
.bf_type
&= ~BUF_DATA
);
1689 ieee80211_is_back_req(fc
) ?
1690 (bf
->bf_state
.bf_type
|= BUF_BAR
) :
1691 (bf
->bf_state
.bf_type
&= ~BUF_BAR
);
1692 ieee80211_is_pspoll(fc
) ?
1693 (bf
->bf_state
.bf_type
|= BUF_PSPOLL
) :
1694 (bf
->bf_state
.bf_type
&= ~BUF_PSPOLL
);
1695 (sc
->sc_flags
& SC_OP_PREAMBLE_SHORT
) ?
1696 (bf
->bf_state
.bf_type
|= BUF_SHORT_PREAMBLE
) :
1697 (bf
->bf_state
.bf_type
&= ~BUF_SHORT_PREAMBLE
);
1698 (sc
->hw
->conf
.ht
.enabled
&& !is_pae(skb
) &&
1699 (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)) ?
1700 (bf
->bf_state
.bf_type
|= BUF_HT
) :
1701 (bf
->bf_state
.bf_type
&= ~BUF_HT
);
1703 bf
->bf_flags
= setup_tx_flags(sc
, skb
, txctl
->txq
);
1707 bf
->bf_keytype
= get_hw_crypto_keytype(skb
);
1709 if (bf
->bf_keytype
!= ATH9K_KEY_TYPE_CLEAR
) {
1710 bf
->bf_frmlen
+= tx_info
->control
.hw_key
->icv_len
;
1711 bf
->bf_keyix
= tx_info
->control
.hw_key
->hw_key_idx
;
1713 bf
->bf_keyix
= ATH9K_TXKEYIX_INVALID
;
1716 /* Assign seqno, tidno */
1718 if (ieee80211_is_data_qos(fc
) && (sc
->sc_flags
& SC_OP_TXAGGR
))
1719 assign_aggr_tid_seqno(skb
, bf
);
1724 bf
->bf_dmacontext
= pci_map_single(sc
->pdev
, skb
->data
,
1725 skb
->len
, PCI_DMA_TODEVICE
);
1726 if (unlikely(pci_dma_mapping_error(sc
->pdev
, bf
->bf_dmacontext
))) {
1728 DPRINTF(sc
, ATH_DBG_CONFIG
,
1729 "pci_dma_mapping_error() on TX\n");
1733 bf
->bf_buf_addr
= bf
->bf_dmacontext
;
1737 /* FIXME: tx power */
1738 static void ath_tx_start_dma(struct ath_softc
*sc
, struct ath_buf
*bf
,
1739 struct ath_tx_control
*txctl
)
1741 struct sk_buff
*skb
= (struct sk_buff
*)bf
->bf_mpdu
;
1742 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
1743 struct ath_node
*an
= NULL
;
1744 struct list_head bf_head
;
1745 struct ath_desc
*ds
;
1746 struct ath_atx_tid
*tid
;
1747 struct ath_hal
*ah
= sc
->sc_ah
;
1750 frm_type
= get_hw_packet_type(skb
);
1752 INIT_LIST_HEAD(&bf_head
);
1753 list_add_tail(&bf
->list
, &bf_head
);
1755 /* setup descriptor */
1759 ds
->ds_data
= bf
->bf_buf_addr
;
1761 /* Formulate first tx descriptor with tx controls */
1763 ath9k_hw_set11n_txdesc(ah
, ds
, bf
->bf_frmlen
, frm_type
, MAX_RATE_POWER
,
1764 bf
->bf_keyix
, bf
->bf_keytype
, bf
->bf_flags
);
1766 ath9k_hw_filltxdesc(ah
, ds
,
1767 skb
->len
, /* segment length */
1768 true, /* first segment */
1769 true, /* last segment */
1770 ds
); /* first descriptor */
1772 bf
->bf_lastfrm
= bf
;
1774 spin_lock_bh(&txctl
->txq
->axq_lock
);
1776 if (bf_isht(bf
) && (sc
->sc_flags
& SC_OP_TXAGGR
) &&
1777 tx_info
->control
.sta
) {
1778 an
= (struct ath_node
*)tx_info
->control
.sta
->drv_priv
;
1779 tid
= ATH_AN_2_TID(an
, bf
->bf_tidno
);
1781 if (ath_aggr_query(sc
, an
, bf
->bf_tidno
)) {
1783 * Try aggregation if it's a unicast data frame
1784 * and the destination is HT capable.
1786 ath_tx_send_ampdu(sc
, tid
, &bf_head
, txctl
);
1789 * Send this frame as regular when ADDBA
1790 * exchange is neither complete nor pending.
1792 ath_tx_send_normal(sc
, txctl
->txq
,
1799 ath_buf_set_rate(sc
, bf
);
1800 ath_tx_txqaddbuf(sc
, txctl
->txq
, &bf_head
);
1803 spin_unlock_bh(&txctl
->txq
->axq_lock
);
1806 /* Upon failure caller should free skb */
1807 int ath_tx_start(struct ath_softc
*sc
, struct sk_buff
*skb
,
1808 struct ath_tx_control
*txctl
)
1813 /* Check if a tx buffer is available */
1815 bf
= ath_tx_get_buffer(sc
);
1817 DPRINTF(sc
, ATH_DBG_XMIT
, "TX buffers are full\n");
1821 r
= ath_tx_setup_buffer(sc
, bf
, skb
, txctl
);
1823 struct ath_txq
*txq
= txctl
->txq
;
1825 DPRINTF(sc
, ATH_DBG_FATAL
, "TX mem alloc failure\n");
1827 /* upon ath_tx_processq() this TX queue will be resumed, we
1828 * guarantee this will happen by knowing beforehand that
1829 * we will at least have to run TX completionon one buffer
1831 spin_lock_bh(&txq
->axq_lock
);
1832 if (ath_txq_depth(sc
, txq
->axq_qnum
) > 1) {
1833 ieee80211_stop_queue(sc
->hw
,
1834 skb_get_queue_mapping(skb
));
1837 spin_unlock_bh(&txq
->axq_lock
);
1839 spin_lock_bh(&sc
->tx
.txbuflock
);
1840 list_add_tail(&bf
->list
, &sc
->tx
.txbuf
);
1841 spin_unlock_bh(&sc
->tx
.txbuflock
);
1846 ath_tx_start_dma(sc
, bf
, txctl
);
1851 /* Initialize TX queue and h/w */
1853 int ath_tx_init(struct ath_softc
*sc
, int nbufs
)
1858 spin_lock_init(&sc
->tx
.txbuflock
);
1860 /* Setup tx descriptors */
1861 error
= ath_descdma_setup(sc
, &sc
->tx
.txdma
, &sc
->tx
.txbuf
,
1864 DPRINTF(sc
, ATH_DBG_FATAL
,
1865 "Failed to allocate tx descriptors: %d\n",
1870 /* XXX allocate beacon state together with vap */
1871 error
= ath_descdma_setup(sc
, &sc
->beacon
.bdma
, &sc
->beacon
.bbuf
,
1872 "beacon", ATH_BCBUF
, 1);
1874 DPRINTF(sc
, ATH_DBG_FATAL
,
1875 "Failed to allocate beacon descriptors: %d\n",
1888 /* Reclaim all tx queue resources */
1890 int ath_tx_cleanup(struct ath_softc
*sc
)
1892 /* cleanup beacon descriptors */
1893 if (sc
->beacon
.bdma
.dd_desc_len
!= 0)
1894 ath_descdma_cleanup(sc
, &sc
->beacon
.bdma
, &sc
->beacon
.bbuf
);
1896 /* cleanup tx descriptors */
1897 if (sc
->tx
.txdma
.dd_desc_len
!= 0)
1898 ath_descdma_cleanup(sc
, &sc
->tx
.txdma
, &sc
->tx
.txbuf
);
1903 /* Setup a h/w transmit queue */
1905 struct ath_txq
*ath_txq_setup(struct ath_softc
*sc
, int qtype
, int subtype
)
1907 struct ath_hal
*ah
= sc
->sc_ah
;
1908 struct ath9k_tx_queue_info qi
;
1911 memset(&qi
, 0, sizeof(qi
));
1912 qi
.tqi_subtype
= subtype
;
1913 qi
.tqi_aifs
= ATH9K_TXQ_USEDEFAULT
;
1914 qi
.tqi_cwmin
= ATH9K_TXQ_USEDEFAULT
;
1915 qi
.tqi_cwmax
= ATH9K_TXQ_USEDEFAULT
;
1916 qi
.tqi_physCompBuf
= 0;
1919 * Enable interrupts only for EOL and DESC conditions.
1920 * We mark tx descriptors to receive a DESC interrupt
1921 * when a tx queue gets deep; otherwise waiting for the
1922 * EOL to reap descriptors. Note that this is done to
1923 * reduce interrupt load and this only defers reaping
1924 * descriptors, never transmitting frames. Aside from
1925 * reducing interrupts this also permits more concurrency.
1926 * The only potential downside is if the tx queue backs
1927 * up in which case the top half of the kernel may backup
1928 * due to a lack of tx descriptors.
1930 * The UAPSD queue is an exception, since we take a desc-
1931 * based intr on the EOSP frames.
1933 if (qtype
== ATH9K_TX_QUEUE_UAPSD
)
1934 qi
.tqi_qflags
= TXQ_FLAG_TXDESCINT_ENABLE
;
1936 qi
.tqi_qflags
= TXQ_FLAG_TXEOLINT_ENABLE
|
1937 TXQ_FLAG_TXDESCINT_ENABLE
;
1938 qnum
= ath9k_hw_setuptxqueue(ah
, qtype
, &qi
);
1941 * NB: don't print a message, this happens
1942 * normally on parts with too few tx queues
1946 if (qnum
>= ARRAY_SIZE(sc
->tx
.txq
)) {
1947 DPRINTF(sc
, ATH_DBG_FATAL
,
1948 "qnum %u out of range, max %u!\n",
1949 qnum
, (unsigned int)ARRAY_SIZE(sc
->tx
.txq
));
1950 ath9k_hw_releasetxqueue(ah
, qnum
);
1953 if (!ATH_TXQ_SETUP(sc
, qnum
)) {
1954 struct ath_txq
*txq
= &sc
->tx
.txq
[qnum
];
1956 txq
->axq_qnum
= qnum
;
1957 txq
->axq_link
= NULL
;
1958 INIT_LIST_HEAD(&txq
->axq_q
);
1959 INIT_LIST_HEAD(&txq
->axq_acq
);
1960 spin_lock_init(&txq
->axq_lock
);
1962 txq
->axq_aggr_depth
= 0;
1963 txq
->axq_totalqueued
= 0;
1964 txq
->axq_linkbuf
= NULL
;
1965 sc
->tx
.txqsetup
|= 1<<qnum
;
1967 return &sc
->tx
.txq
[qnum
];
1970 /* Reclaim resources for a setup queue */
1972 void ath_tx_cleanupq(struct ath_softc
*sc
, struct ath_txq
*txq
)
1974 ath9k_hw_releasetxqueue(sc
->sc_ah
, txq
->axq_qnum
);
1975 sc
->tx
.txqsetup
&= ~(1<<txq
->axq_qnum
);
1979 * Setup a hardware data transmit queue for the specified
1980 * access control. The hal may not support all requested
1981 * queues in which case it will return a reference to a
1982 * previously setup queue. We record the mapping from ac's
1983 * to h/w queues for use by ath_tx_start and also track
1984 * the set of h/w queues being used to optimize work in the
1985 * transmit interrupt handler and related routines.
1988 int ath_tx_setup(struct ath_softc
*sc
, int haltype
)
1990 struct ath_txq
*txq
;
1992 if (haltype
>= ARRAY_SIZE(sc
->tx
.hwq_map
)) {
1993 DPRINTF(sc
, ATH_DBG_FATAL
,
1994 "HAL AC %u out of range, max %zu!\n",
1995 haltype
, ARRAY_SIZE(sc
->tx
.hwq_map
));
1998 txq
= ath_txq_setup(sc
, ATH9K_TX_QUEUE_DATA
, haltype
);
2000 sc
->tx
.hwq_map
[haltype
] = txq
->axq_qnum
;
2006 int ath_tx_get_qnum(struct ath_softc
*sc
, int qtype
, int haltype
)
2011 case ATH9K_TX_QUEUE_DATA
:
2012 if (haltype
>= ARRAY_SIZE(sc
->tx
.hwq_map
)) {
2013 DPRINTF(sc
, ATH_DBG_FATAL
,
2014 "HAL AC %u out of range, max %zu!\n",
2015 haltype
, ARRAY_SIZE(sc
->tx
.hwq_map
));
2018 qnum
= sc
->tx
.hwq_map
[haltype
];
2020 case ATH9K_TX_QUEUE_BEACON
:
2021 qnum
= sc
->beacon
.beaconq
;
2023 case ATH9K_TX_QUEUE_CAB
:
2024 qnum
= sc
->beacon
.cabq
->axq_qnum
;
2032 /* Get a transmit queue, if available */
2034 struct ath_txq
*ath_test_get_txq(struct ath_softc
*sc
, struct sk_buff
*skb
)
2036 struct ath_txq
*txq
= NULL
;
2039 qnum
= ath_get_hal_qnum(skb_get_queue_mapping(skb
), sc
);
2040 txq
= &sc
->tx
.txq
[qnum
];
2042 spin_lock_bh(&txq
->axq_lock
);
2044 /* Try to avoid running out of descriptors */
2045 if (txq
->axq_depth
>= (ATH_TXBUF
- 20)) {
2046 DPRINTF(sc
, ATH_DBG_FATAL
,
2047 "TX queue: %d is full, depth: %d\n",
2048 qnum
, txq
->axq_depth
);
2049 ieee80211_stop_queue(sc
->hw
, skb_get_queue_mapping(skb
));
2051 spin_unlock_bh(&txq
->axq_lock
);
2055 spin_unlock_bh(&txq
->axq_lock
);
2060 /* Update parameters for a transmit queue */
2062 int ath_txq_update(struct ath_softc
*sc
, int qnum
,
2063 struct ath9k_tx_queue_info
*qinfo
)
2065 struct ath_hal
*ah
= sc
->sc_ah
;
2067 struct ath9k_tx_queue_info qi
;
2069 if (qnum
== sc
->beacon
.beaconq
) {
2071 * XXX: for beacon queue, we just save the parameter.
2072 * It will be picked up by ath_beaconq_config when
2075 sc
->beacon
.beacon_qi
= *qinfo
;
2079 ASSERT(sc
->tx
.txq
[qnum
].axq_qnum
== qnum
);
2081 ath9k_hw_get_txq_props(ah
, qnum
, &qi
);
2082 qi
.tqi_aifs
= qinfo
->tqi_aifs
;
2083 qi
.tqi_cwmin
= qinfo
->tqi_cwmin
;
2084 qi
.tqi_cwmax
= qinfo
->tqi_cwmax
;
2085 qi
.tqi_burstTime
= qinfo
->tqi_burstTime
;
2086 qi
.tqi_readyTime
= qinfo
->tqi_readyTime
;
2088 if (!ath9k_hw_set_txq_props(ah
, qnum
, &qi
)) {
2089 DPRINTF(sc
, ATH_DBG_FATAL
,
2090 "Unable to update hardware queue %u!\n", qnum
);
2093 ath9k_hw_resettxqueue(ah
, qnum
); /* push to h/w */
2099 int ath_cabq_update(struct ath_softc
*sc
)
2101 struct ath9k_tx_queue_info qi
;
2102 int qnum
= sc
->beacon
.cabq
->axq_qnum
;
2103 struct ath_beacon_config conf
;
2105 ath9k_hw_get_txq_props(sc
->sc_ah
, qnum
, &qi
);
2107 * Ensure the readytime % is within the bounds.
2109 if (sc
->sc_config
.cabqReadytime
< ATH9K_READY_TIME_LO_BOUND
)
2110 sc
->sc_config
.cabqReadytime
= ATH9K_READY_TIME_LO_BOUND
;
2111 else if (sc
->sc_config
.cabqReadytime
> ATH9K_READY_TIME_HI_BOUND
)
2112 sc
->sc_config
.cabqReadytime
= ATH9K_READY_TIME_HI_BOUND
;
2114 ath_get_beaconconfig(sc
, ATH_IF_ID_ANY
, &conf
);
2116 (conf
.beacon_interval
* sc
->sc_config
.cabqReadytime
) / 100;
2117 ath_txq_update(sc
, qnum
, &qi
);
2122 /* Deferred processing of transmit interrupt */
2124 void ath_tx_tasklet(struct ath_softc
*sc
)
2127 u32 qcumask
= ((1 << ATH9K_NUM_TX_QUEUES
) - 1);
2129 ath9k_hw_gettxintrtxqs(sc
->sc_ah
, &qcumask
);
2132 * Process each active queue.
2134 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
2135 if (ATH_TXQ_SETUP(sc
, i
) && (qcumask
& (1 << i
)))
2136 ath_tx_processq(sc
, &sc
->tx
.txq
[i
]);
2140 void ath_tx_draintxq(struct ath_softc
*sc
,
2141 struct ath_txq
*txq
, bool retry_tx
)
2143 struct ath_buf
*bf
, *lastbf
;
2144 struct list_head bf_head
;
2146 INIT_LIST_HEAD(&bf_head
);
2149 * NB: this assumes output has been stopped and
2150 * we do not need to block ath_tx_tasklet
2153 spin_lock_bh(&txq
->axq_lock
);
2155 if (list_empty(&txq
->axq_q
)) {
2156 txq
->axq_link
= NULL
;
2157 txq
->axq_linkbuf
= NULL
;
2158 spin_unlock_bh(&txq
->axq_lock
);
2162 bf
= list_first_entry(&txq
->axq_q
, struct ath_buf
, list
);
2164 if (bf
->bf_status
& ATH_BUFSTATUS_STALE
) {
2165 list_del(&bf
->list
);
2166 spin_unlock_bh(&txq
->axq_lock
);
2168 spin_lock_bh(&sc
->tx
.txbuflock
);
2169 list_add_tail(&bf
->list
, &sc
->tx
.txbuf
);
2170 spin_unlock_bh(&sc
->tx
.txbuflock
);
2174 lastbf
= bf
->bf_lastbf
;
2176 lastbf
->bf_desc
->ds_txstat
.ts_flags
=
2177 ATH9K_TX_SW_ABORTED
;
2179 /* remove ath_buf's of the same mpdu from txq */
2180 list_cut_position(&bf_head
, &txq
->axq_q
, &lastbf
->list
);
2183 spin_unlock_bh(&txq
->axq_lock
);
2186 ath_tx_complete_aggr_rifs(sc
, txq
, bf
, &bf_head
, 0);
2188 ath_tx_complete_buf(sc
, bf
, &bf_head
, 0, 0);
2191 /* flush any pending frames if aggregation is enabled */
2192 if (sc
->sc_flags
& SC_OP_TXAGGR
) {
2194 spin_lock_bh(&txq
->axq_lock
);
2195 ath_txq_drain_pending_buffers(sc
, txq
);
2196 spin_unlock_bh(&txq
->axq_lock
);
2201 /* Drain the transmit queues and reclaim resources */
2203 void ath_draintxq(struct ath_softc
*sc
, bool retry_tx
)
2205 /* stop beacon queue. The beacon will be freed when
2206 * we go to INIT state */
2207 if (!(sc
->sc_flags
& SC_OP_INVALID
)) {
2208 (void) ath9k_hw_stoptxdma(sc
->sc_ah
, sc
->beacon
.beaconq
);
2209 DPRINTF(sc
, ATH_DBG_XMIT
, "beacon queue %x\n",
2210 ath9k_hw_gettxbuf(sc
->sc_ah
, sc
->beacon
.beaconq
));
2213 ath_drain_txdataq(sc
, retry_tx
);
2216 u32
ath_txq_depth(struct ath_softc
*sc
, int qnum
)
2218 return sc
->tx
.txq
[qnum
].axq_depth
;
2221 u32
ath_txq_aggr_depth(struct ath_softc
*sc
, int qnum
)
2223 return sc
->tx
.txq
[qnum
].axq_aggr_depth
;
2226 bool ath_tx_aggr_check(struct ath_softc
*sc
, struct ath_node
*an
, u8 tidno
)
2228 struct ath_atx_tid
*txtid
;
2230 if (!(sc
->sc_flags
& SC_OP_TXAGGR
))
2233 txtid
= ATH_AN_2_TID(an
, tidno
);
2235 if (!(txtid
->state
& AGGR_ADDBA_COMPLETE
)) {
2236 if (!(txtid
->state
& AGGR_ADDBA_PROGRESS
) &&
2237 (txtid
->addba_exchangeattempts
< ADDBA_EXCHANGE_ATTEMPTS
)) {
2238 txtid
->addba_exchangeattempts
++;
2246 /* Start TX aggregation */
2248 int ath_tx_aggr_start(struct ath_softc
*sc
, struct ieee80211_sta
*sta
,
2251 struct ath_atx_tid
*txtid
;
2252 struct ath_node
*an
;
2254 an
= (struct ath_node
*)sta
->drv_priv
;
2256 if (sc
->sc_flags
& SC_OP_TXAGGR
) {
2257 txtid
= ATH_AN_2_TID(an
, tid
);
2258 txtid
->state
|= AGGR_ADDBA_PROGRESS
;
2259 ath_tx_pause_tid(sc
, txtid
);
2265 /* Stop tx aggregation */
2267 int ath_tx_aggr_stop(struct ath_softc
*sc
, struct ieee80211_sta
*sta
, u16 tid
)
2269 struct ath_node
*an
= (struct ath_node
*)sta
->drv_priv
;
2271 ath_tx_aggr_teardown(sc
, an
, tid
);
2275 /* Resume tx aggregation */
2277 void ath_tx_aggr_resume(struct ath_softc
*sc
, struct ieee80211_sta
*sta
, u16 tid
)
2279 struct ath_atx_tid
*txtid
;
2280 struct ath_node
*an
;
2282 an
= (struct ath_node
*)sta
->drv_priv
;
2284 if (sc
->sc_flags
& SC_OP_TXAGGR
) {
2285 txtid
= ATH_AN_2_TID(an
, tid
);
2287 IEEE80211_MIN_AMPDU_BUF
<< sta
->ht_cap
.ampdu_factor
;
2288 txtid
->state
|= AGGR_ADDBA_COMPLETE
;
2289 txtid
->state
&= ~AGGR_ADDBA_PROGRESS
;
2290 ath_tx_resume_tid(sc
, txtid
);
2295 * Performs transmit side cleanup when TID changes from aggregated to
2297 * - Pause the TID and mark cleanup in progress
2298 * - Discard all retry frames from the s/w queue.
2301 void ath_tx_aggr_teardown(struct ath_softc
*sc
, struct ath_node
*an
, u8 tid
)
2303 struct ath_atx_tid
*txtid
= ATH_AN_2_TID(an
, tid
);
2304 struct ath_txq
*txq
= &sc
->tx
.txq
[txtid
->ac
->qnum
];
2306 struct list_head bf_head
;
2307 INIT_LIST_HEAD(&bf_head
);
2309 if (txtid
->state
& AGGR_CLEANUP
) /* cleanup is in progress */
2312 if (!(txtid
->state
& AGGR_ADDBA_COMPLETE
)) {
2313 txtid
->addba_exchangeattempts
= 0;
2317 /* TID must be paused first */
2318 ath_tx_pause_tid(sc
, txtid
);
2320 /* drop all software retried frames and mark this TID */
2321 spin_lock_bh(&txq
->axq_lock
);
2322 while (!list_empty(&txtid
->buf_q
)) {
2323 bf
= list_first_entry(&txtid
->buf_q
, struct ath_buf
, list
);
2324 if (!bf_isretried(bf
)) {
2326 * NB: it's based on the assumption that
2327 * software retried frame will always stay
2328 * at the head of software queue.
2332 list_cut_position(&bf_head
,
2333 &txtid
->buf_q
, &bf
->bf_lastfrm
->list
);
2334 ath_tx_update_baw(sc
, txtid
, bf
->bf_seqno
);
2336 /* complete this sub-frame */
2337 ath_tx_complete_buf(sc
, bf
, &bf_head
, 0, 0);
2340 if (txtid
->baw_head
!= txtid
->baw_tail
) {
2341 spin_unlock_bh(&txq
->axq_lock
);
2342 txtid
->state
|= AGGR_CLEANUP
;
2344 txtid
->state
&= ~AGGR_ADDBA_COMPLETE
;
2345 txtid
->addba_exchangeattempts
= 0;
2346 spin_unlock_bh(&txq
->axq_lock
);
2347 ath_tx_flush_tid(sc
, txtid
);
2352 * Tx scheduling logic
2353 * NB: must be called with txq lock held
2356 void ath_txq_schedule(struct ath_softc
*sc
, struct ath_txq
*txq
)
2358 struct ath_atx_ac
*ac
;
2359 struct ath_atx_tid
*tid
;
2361 /* nothing to schedule */
2362 if (list_empty(&txq
->axq_acq
))
2365 * get the first node/ac pair on the queue
2367 ac
= list_first_entry(&txq
->axq_acq
, struct ath_atx_ac
, list
);
2368 list_del(&ac
->list
);
2372 * process a single tid per destination
2375 /* nothing to schedule */
2376 if (list_empty(&ac
->tid_q
))
2379 tid
= list_first_entry(&ac
->tid_q
, struct ath_atx_tid
, list
);
2380 list_del(&tid
->list
);
2383 if (tid
->paused
) /* check next tid to keep h/w busy */
2386 if ((txq
->axq_depth
% 2) == 0)
2387 ath_tx_sched_aggr(sc
, txq
, tid
);
2390 * add tid to round-robin queue if more frames
2391 * are pending for the tid
2393 if (!list_empty(&tid
->buf_q
))
2394 ath_tx_queue_tid(txq
, tid
);
2396 /* only schedule one TID at a time */
2398 } while (!list_empty(&ac
->tid_q
));
2401 * schedule AC if more TIDs need processing
2403 if (!list_empty(&ac
->tid_q
)) {
2405 * add dest ac to txq if not already added
2409 list_add_tail(&ac
->list
, &txq
->axq_acq
);
2414 /* Initialize per-node transmit state */
2416 void ath_tx_node_init(struct ath_softc
*sc
, struct ath_node
*an
)
2418 struct ath_atx_tid
*tid
;
2419 struct ath_atx_ac
*ac
;
2423 * Init per tid tx state
2425 for (tidno
= 0, tid
= &an
->tid
[tidno
];
2426 tidno
< WME_NUM_TID
;
2430 tid
->seq_start
= tid
->seq_next
= 0;
2431 tid
->baw_size
= WME_MAX_BA
;
2432 tid
->baw_head
= tid
->baw_tail
= 0;
2434 tid
->paused
= false;
2435 tid
->state
&= ~AGGR_CLEANUP
;
2436 INIT_LIST_HEAD(&tid
->buf_q
);
2438 acno
= TID_TO_WME_AC(tidno
);
2439 tid
->ac
= &an
->ac
[acno
];
2442 tid
->state
&= ~AGGR_ADDBA_COMPLETE
;
2443 tid
->state
&= ~AGGR_ADDBA_PROGRESS
;
2444 tid
->addba_exchangeattempts
= 0;
2448 * Init per ac tx state
2450 for (acno
= 0, ac
= &an
->ac
[acno
];
2451 acno
< WME_NUM_AC
; acno
++, ac
++) {
2453 INIT_LIST_HEAD(&ac
->tid_q
);
2457 ac
->qnum
= ath_tx_get_qnum(sc
,
2458 ATH9K_TX_QUEUE_DATA
, ATH9K_WME_AC_BE
);
2461 ac
->qnum
= ath_tx_get_qnum(sc
,
2462 ATH9K_TX_QUEUE_DATA
, ATH9K_WME_AC_BK
);
2465 ac
->qnum
= ath_tx_get_qnum(sc
,
2466 ATH9K_TX_QUEUE_DATA
, ATH9K_WME_AC_VI
);
2469 ac
->qnum
= ath_tx_get_qnum(sc
,
2470 ATH9K_TX_QUEUE_DATA
, ATH9K_WME_AC_VO
);
2476 /* Cleanupthe pending buffers for the node. */
2478 void ath_tx_node_cleanup(struct ath_softc
*sc
, struct ath_node
*an
)
2481 struct ath_atx_ac
*ac
, *ac_tmp
;
2482 struct ath_atx_tid
*tid
, *tid_tmp
;
2483 struct ath_txq
*txq
;
2484 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
2485 if (ATH_TXQ_SETUP(sc
, i
)) {
2486 txq
= &sc
->tx
.txq
[i
];
2488 spin_lock(&txq
->axq_lock
);
2490 list_for_each_entry_safe(ac
,
2491 ac_tmp
, &txq
->axq_acq
, list
) {
2492 tid
= list_first_entry(&ac
->tid_q
,
2493 struct ath_atx_tid
, list
);
2494 if (tid
&& tid
->an
!= an
)
2496 list_del(&ac
->list
);
2499 list_for_each_entry_safe(tid
,
2500 tid_tmp
, &ac
->tid_q
, list
) {
2501 list_del(&tid
->list
);
2503 ath_tid_drain(sc
, txq
, tid
);
2504 tid
->state
&= ~AGGR_ADDBA_COMPLETE
;
2505 tid
->addba_exchangeattempts
= 0;
2506 tid
->state
&= ~AGGR_CLEANUP
;
2510 spin_unlock(&txq
->axq_lock
);
2515 void ath_tx_cabq(struct ath_softc
*sc
, struct sk_buff
*skb
)
2517 int hdrlen
, padsize
;
2518 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2519 struct ath_tx_control txctl
;
2521 memset(&txctl
, 0, sizeof(struct ath_tx_control
));
2524 * As a temporary workaround, assign seq# here; this will likely need
2525 * to be cleaned up to work better with Beacon transmission and virtual
2528 if (info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
2529 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
2530 if (info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
)
2531 sc
->tx
.seq_no
+= 0x10;
2532 hdr
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
2533 hdr
->seq_ctrl
|= cpu_to_le16(sc
->tx
.seq_no
);
2536 /* Add the padding after the header if this is not already done */
2537 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
2539 padsize
= hdrlen
% 4;
2540 if (skb_headroom(skb
) < padsize
) {
2541 DPRINTF(sc
, ATH_DBG_XMIT
, "TX CABQ padding failed\n");
2542 dev_kfree_skb_any(skb
);
2545 skb_push(skb
, padsize
);
2546 memmove(skb
->data
, skb
->data
+ padsize
, hdrlen
);
2549 txctl
.txq
= sc
->beacon
.cabq
;
2551 DPRINTF(sc
, ATH_DBG_XMIT
, "transmitting CABQ packet, skb: %p\n", skb
);
2553 if (ath_tx_start(sc
, skb
, &txctl
) != 0) {
2554 DPRINTF(sc
, ATH_DBG_XMIT
, "CABQ TX failed\n");
2560 dev_kfree_skb_any(skb
);