Commit | Line | Data |
---|---|---|
f078f209 | 1 | /* |
5b68138e | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
f078f209 LR |
3 | * |
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. | |
7 | * | |
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. | |
15 | */ | |
16 | ||
b7f080cf | 17 | #include <linux/dma-mapping.h> |
394cf0a1 | 18 | #include "ath9k.h" |
b622a720 | 19 | #include "ar9003_mac.h" |
f078f209 LR |
20 | |
21 | #define BITS_PER_BYTE 8 | |
22 | #define OFDM_PLCP_BITS 22 | |
f078f209 LR |
23 | #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1) |
24 | #define L_STF 8 | |
25 | #define L_LTF 8 | |
26 | #define L_SIG 4 | |
27 | #define HT_SIG 8 | |
28 | #define HT_STF 4 | |
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 */ | |
aa5955c3 FF |
32 | #define TIME_SYMBOLS(t) ((t) >> 2) |
33 | #define TIME_SYMBOLS_HALFGI(t) (((t) * 5 - 4) / 18) | |
f078f209 LR |
34 | #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2) |
35 | #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18) | |
36 | ||
f078f209 | 37 | |
c6663876 | 38 | static u16 bits_per_symbol[][2] = { |
f078f209 LR |
39 | /* 20MHz 40MHz */ |
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 */ | |
f078f209 LR |
48 | }; |
49 | ||
50 | #define IS_HT_RATE(_rate) ((_rate) & 0x80) | |
51 | ||
82b873af | 52 | static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq, |
44f1d26c FF |
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); | |
e8324357 | 56 | static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf, |
db1a052b | 57 | struct ath_txq *txq, struct list_head *bf_q, |
156369fa | 58 | struct ath_tx_status *ts, int txok); |
102e0572 | 59 | static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq, |
fce041be | 60 | struct list_head *head, bool internal); |
0cdd5c60 FF |
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, | |
3afd21e7 | 63 | int txok); |
90fa539c FF |
64 | static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid, |
65 | int seqno); | |
44f1d26c FF |
66 | static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc, |
67 | struct ath_txq *txq, | |
68 | struct ath_atx_tid *tid, | |
249ee722 | 69 | struct sk_buff *skb); |
c4288390 | 70 | |
545750d3 | 71 | enum { |
0e668cde FF |
72 | MCS_HT20, |
73 | MCS_HT20_SGI, | |
545750d3 FF |
74 | MCS_HT40, |
75 | MCS_HT40_SGI, | |
76 | }; | |
77 | ||
e8324357 S |
78 | /*********************/ |
79 | /* Aggregation logic */ | |
80 | /*********************/ | |
f078f209 | 81 | |
ef1b6cd9 | 82 | void ath_txq_lock(struct ath_softc *sc, struct ath_txq *txq) |
1512a486 | 83 | __acquires(&txq->axq_lock) |
23de5dc9 FF |
84 | { |
85 | spin_lock_bh(&txq->axq_lock); | |
86 | } | |
87 | ||
ef1b6cd9 | 88 | void ath_txq_unlock(struct ath_softc *sc, struct ath_txq *txq) |
1512a486 | 89 | __releases(&txq->axq_lock) |
23de5dc9 FF |
90 | { |
91 | spin_unlock_bh(&txq->axq_lock); | |
92 | } | |
93 | ||
ef1b6cd9 | 94 | void ath_txq_unlock_complete(struct ath_softc *sc, struct ath_txq *txq) |
1512a486 | 95 | __releases(&txq->axq_lock) |
23de5dc9 FF |
96 | { |
97 | struct sk_buff_head q; | |
98 | struct sk_buff *skb; | |
99 | ||
100 | __skb_queue_head_init(&q); | |
101 | skb_queue_splice_init(&txq->complete_q, &q); | |
102 | spin_unlock_bh(&txq->axq_lock); | |
103 | ||
104 | while ((skb = __skb_dequeue(&q))) | |
105 | ieee80211_tx_status(sc->hw, skb); | |
106 | } | |
107 | ||
e8324357 | 108 | static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid) |
ff37e337 | 109 | { |
e8324357 | 110 | struct ath_atx_ac *ac = tid->ac; |
ff37e337 | 111 | |
e8324357 S |
112 | if (tid->paused) |
113 | return; | |
ff37e337 | 114 | |
e8324357 S |
115 | if (tid->sched) |
116 | return; | |
ff37e337 | 117 | |
e8324357 S |
118 | tid->sched = true; |
119 | list_add_tail(&tid->list, &ac->tid_q); | |
528f0c6b | 120 | |
e8324357 S |
121 | if (ac->sched) |
122 | return; | |
f078f209 | 123 | |
e8324357 S |
124 | ac->sched = true; |
125 | list_add_tail(&ac->list, &txq->axq_acq); | |
126 | } | |
f078f209 | 127 | |
e8324357 | 128 | static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid) |
f078f209 | 129 | { |
066dae93 | 130 | struct ath_txq *txq = tid->ac->txq; |
e6a9854b | 131 | |
75401849 | 132 | WARN_ON(!tid->paused); |
f078f209 | 133 | |
23de5dc9 | 134 | ath_txq_lock(sc, txq); |
75401849 | 135 | tid->paused = false; |
f078f209 | 136 | |
56dc6336 | 137 | if (skb_queue_empty(&tid->buf_q)) |
e8324357 | 138 | goto unlock; |
f078f209 | 139 | |
e8324357 S |
140 | ath_tx_queue_tid(txq, tid); |
141 | ath_txq_schedule(sc, txq); | |
142 | unlock: | |
23de5dc9 | 143 | ath_txq_unlock_complete(sc, txq); |
528f0c6b | 144 | } |
f078f209 | 145 | |
2d42efc4 | 146 | static struct ath_frame_info *get_frame_info(struct sk_buff *skb) |
76e45221 FF |
147 | { |
148 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); | |
2d42efc4 FF |
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]; | |
76e45221 FF |
152 | } |
153 | ||
156369fa FF |
154 | static void ath_send_bar(struct ath_atx_tid *tid, u16 seqno) |
155 | { | |
156 | ieee80211_send_bar(tid->an->vif, tid->an->sta->addr, tid->tidno, | |
157 | seqno << IEEE80211_SEQ_SEQ_SHIFT); | |
158 | } | |
159 | ||
79acac07 FF |
160 | static void ath_set_rates(struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
161 | struct ath_buf *bf) | |
162 | { | |
163 | ieee80211_get_tx_rates(vif, sta, bf->bf_mpdu, bf->rates, | |
164 | ARRAY_SIZE(bf->rates)); | |
165 | } | |
166 | ||
16e23428 FF |
167 | static void ath_tx_clear_tid(struct ath_softc *sc, struct ath_atx_tid *tid) |
168 | { | |
169 | tid->state &= ~AGGR_ADDBA_COMPLETE; | |
170 | tid->state &= ~AGGR_CLEANUP; | |
171 | if (!tid->stop_cb) | |
172 | return; | |
173 | ||
174 | ieee80211_start_tx_ba_cb_irqsafe(tid->an->vif, tid->an->sta->addr, | |
175 | tid->tidno); | |
176 | tid->stop_cb = false; | |
177 | } | |
178 | ||
179 | static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid, | |
180 | bool flush_packets) | |
528f0c6b | 181 | { |
066dae93 | 182 | struct ath_txq *txq = tid->ac->txq; |
56dc6336 | 183 | struct sk_buff *skb; |
e8324357 S |
184 | struct ath_buf *bf; |
185 | struct list_head bf_head; | |
90fa539c | 186 | struct ath_tx_status ts; |
2d42efc4 | 187 | struct ath_frame_info *fi; |
156369fa | 188 | bool sendbar = false; |
f078f209 | 189 | |
90fa539c | 190 | INIT_LIST_HEAD(&bf_head); |
e6a9854b | 191 | |
90fa539c | 192 | memset(&ts, 0, sizeof(ts)); |
f078f209 | 193 | |
56dc6336 FF |
194 | while ((skb = __skb_dequeue(&tid->buf_q))) { |
195 | fi = get_frame_info(skb); | |
196 | bf = fi->bf; | |
16e23428 FF |
197 | if (!bf && !flush_packets) |
198 | bf = ath_tx_setup_buffer(sc, txq, tid, skb); | |
56dc6336 | 199 | |
249ee722 | 200 | if (!bf) { |
16e23428 FF |
201 | ieee80211_free_txskb(sc->hw, skb); |
202 | continue; | |
249ee722 FF |
203 | } |
204 | ||
16e23428 | 205 | if (fi->retries || flush_packets) { |
44f1d26c | 206 | list_add_tail(&bf->list, &bf_head); |
6a0ddaef | 207 | ath_tx_update_baw(sc, tid, bf->bf_state.seqno); |
156369fa FF |
208 | ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0); |
209 | sendbar = true; | |
90fa539c | 210 | } else { |
79acac07 | 211 | ath_set_rates(tid->an->vif, tid->an->sta, bf); |
44f1d26c | 212 | ath_tx_send_normal(sc, txq, NULL, skb); |
90fa539c | 213 | } |
528f0c6b | 214 | } |
f078f209 | 215 | |
16e23428 FF |
216 | if (tid->baw_head == tid->baw_tail) |
217 | ath_tx_clear_tid(sc, tid); | |
4eb287a4 | 218 | |
16e23428 | 219 | if (sendbar && !flush_packets) { |
23de5dc9 | 220 | ath_txq_unlock(sc, txq); |
156369fa | 221 | ath_send_bar(tid, tid->seq_start); |
23de5dc9 FF |
222 | ath_txq_lock(sc, txq); |
223 | } | |
528f0c6b | 224 | } |
f078f209 | 225 | |
e8324357 S |
226 | static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid, |
227 | int seqno) | |
528f0c6b | 228 | { |
e8324357 | 229 | int index, cindex; |
f078f209 | 230 | |
e8324357 S |
231 | index = ATH_BA_INDEX(tid->seq_start, seqno); |
232 | cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); | |
f078f209 | 233 | |
81ee13ba | 234 | __clear_bit(cindex, tid->tx_buf); |
528f0c6b | 235 | |
81ee13ba | 236 | while (tid->baw_head != tid->baw_tail && !test_bit(tid->baw_head, tid->tx_buf)) { |
e8324357 S |
237 | INCR(tid->seq_start, IEEE80211_SEQ_MAX); |
238 | INCR(tid->baw_head, ATH_TID_MAX_BUFS); | |
f9437543 FF |
239 | if (tid->bar_index >= 0) |
240 | tid->bar_index--; | |
e8324357 | 241 | } |
528f0c6b | 242 | } |
f078f209 | 243 | |
e8324357 | 244 | static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid, |
2d3bcba0 | 245 | u16 seqno) |
528f0c6b | 246 | { |
e8324357 | 247 | int index, cindex; |
528f0c6b | 248 | |
2d3bcba0 | 249 | index = ATH_BA_INDEX(tid->seq_start, seqno); |
e8324357 | 250 | cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); |
81ee13ba | 251 | __set_bit(cindex, tid->tx_buf); |
f078f209 | 252 | |
e8324357 S |
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); | |
f078f209 | 257 | } |
f078f209 LR |
258 | } |
259 | ||
260 | /* | |
e8324357 S |
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 | |
264 | * forward. | |
f078f209 | 265 | */ |
e8324357 S |
266 | static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq, |
267 | struct ath_atx_tid *tid) | |
f078f209 | 268 | |
f078f209 | 269 | { |
56dc6336 | 270 | struct sk_buff *skb; |
e8324357 S |
271 | struct ath_buf *bf; |
272 | struct list_head bf_head; | |
db1a052b | 273 | struct ath_tx_status ts; |
2d42efc4 | 274 | struct ath_frame_info *fi; |
db1a052b FF |
275 | |
276 | memset(&ts, 0, sizeof(ts)); | |
e8324357 | 277 | INIT_LIST_HEAD(&bf_head); |
f078f209 | 278 | |
56dc6336 FF |
279 | while ((skb = __skb_dequeue(&tid->buf_q))) { |
280 | fi = get_frame_info(skb); | |
281 | bf = fi->bf; | |
f078f209 | 282 | |
44f1d26c | 283 | if (!bf) { |
44f1d26c | 284 | ath_tx_complete(sc, skb, ATH_TX_ERROR, txq); |
44f1d26c FF |
285 | continue; |
286 | } | |
287 | ||
56dc6336 | 288 | list_add_tail(&bf->list, &bf_head); |
f078f209 | 289 | |
2d42efc4 | 290 | if (fi->retries) |
6a0ddaef | 291 | ath_tx_update_baw(sc, tid, bf->bf_state.seqno); |
f078f209 | 292 | |
156369fa | 293 | ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0); |
e8324357 | 294 | } |
f078f209 | 295 | |
e8324357 S |
296 | tid->seq_next = tid->seq_start; |
297 | tid->baw_tail = tid->baw_head; | |
f9437543 | 298 | tid->bar_index = -1; |
f078f209 LR |
299 | } |
300 | ||
fec247c0 | 301 | static void ath_tx_set_retry(struct ath_softc *sc, struct ath_txq *txq, |
da647626 | 302 | struct sk_buff *skb, int count) |
f078f209 | 303 | { |
8b7f8532 | 304 | struct ath_frame_info *fi = get_frame_info(skb); |
f11cc949 | 305 | struct ath_buf *bf = fi->bf; |
e8324357 | 306 | struct ieee80211_hdr *hdr; |
da647626 | 307 | int prev = fi->retries; |
f078f209 | 308 | |
fec247c0 | 309 | TX_STAT_INC(txq->axq_qnum, a_retries); |
da647626 FF |
310 | fi->retries += count; |
311 | ||
312 | if (prev > 0) | |
2d42efc4 | 313 | return; |
f078f209 | 314 | |
e8324357 S |
315 | hdr = (struct ieee80211_hdr *)skb->data; |
316 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY); | |
f11cc949 FF |
317 | dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, |
318 | sizeof(*hdr), DMA_TO_DEVICE); | |
f078f209 LR |
319 | } |
320 | ||
0a8cea84 | 321 | static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc) |
d43f3015 | 322 | { |
0a8cea84 | 323 | struct ath_buf *bf = NULL; |
d43f3015 S |
324 | |
325 | spin_lock_bh(&sc->tx.txbuflock); | |
0a8cea84 FF |
326 | |
327 | if (unlikely(list_empty(&sc->tx.txbuf))) { | |
8a46097a VT |
328 | spin_unlock_bh(&sc->tx.txbuflock); |
329 | return NULL; | |
330 | } | |
0a8cea84 FF |
331 | |
332 | bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list); | |
333 | list_del(&bf->list); | |
334 | ||
d43f3015 S |
335 | spin_unlock_bh(&sc->tx.txbuflock); |
336 | ||
0a8cea84 FF |
337 | return bf; |
338 | } | |
339 | ||
340 | static void ath_tx_return_buffer(struct ath_softc *sc, struct ath_buf *bf) | |
341 | { | |
342 | spin_lock_bh(&sc->tx.txbuflock); | |
343 | list_add_tail(&bf->list, &sc->tx.txbuf); | |
344 | spin_unlock_bh(&sc->tx.txbuflock); | |
345 | } | |
346 | ||
347 | static struct ath_buf* ath_clone_txbuf(struct ath_softc *sc, struct ath_buf *bf) | |
348 | { | |
349 | struct ath_buf *tbf; | |
350 | ||
351 | tbf = ath_tx_get_buffer(sc); | |
352 | if (WARN_ON(!tbf)) | |
353 | return NULL; | |
354 | ||
d43f3015 S |
355 | ATH_TXBUF_RESET(tbf); |
356 | ||
357 | tbf->bf_mpdu = bf->bf_mpdu; | |
358 | tbf->bf_buf_addr = bf->bf_buf_addr; | |
d826c832 | 359 | memcpy(tbf->bf_desc, bf->bf_desc, sc->sc_ah->caps.tx_desc_len); |
d43f3015 | 360 | tbf->bf_state = bf->bf_state; |
d43f3015 S |
361 | |
362 | return tbf; | |
363 | } | |
364 | ||
b572d033 FF |
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) | |
368 | { | |
2d42efc4 | 369 | struct ath_frame_info *fi; |
b572d033 FF |
370 | u16 seq_st = 0; |
371 | u32 ba[WME_BA_BMP_SIZE >> 5]; | |
372 | int ba_index; | |
373 | int isaggr = 0; | |
374 | ||
375 | *nbad = 0; | |
376 | *nframes = 0; | |
377 | ||
b572d033 FF |
378 | isaggr = bf_isaggr(bf); |
379 | if (isaggr) { | |
380 | seq_st = ts->ts_seqnum; | |
381 | memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3); | |
382 | } | |
383 | ||
384 | while (bf) { | |
2d42efc4 | 385 | fi = get_frame_info(bf->bf_mpdu); |
6a0ddaef | 386 | ba_index = ATH_BA_INDEX(seq_st, bf->bf_state.seqno); |
b572d033 FF |
387 | |
388 | (*nframes)++; | |
389 | if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index))) | |
390 | (*nbad)++; | |
391 | ||
392 | bf = bf->bf_next; | |
393 | } | |
394 | } | |
395 | ||
396 | ||
d43f3015 S |
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, | |
1381559b | 399 | struct ath_tx_status *ts, int txok) |
f078f209 | 400 | { |
e8324357 S |
401 | struct ath_node *an = NULL; |
402 | struct sk_buff *skb; | |
1286ec6d | 403 | struct ieee80211_sta *sta; |
0cdd5c60 | 404 | struct ieee80211_hw *hw = sc->hw; |
1286ec6d | 405 | struct ieee80211_hdr *hdr; |
76d5a9e8 | 406 | struct ieee80211_tx_info *tx_info; |
e8324357 | 407 | struct ath_atx_tid *tid = NULL; |
d43f3015 | 408 | struct ath_buf *bf_next, *bf_last = bf->bf_lastbf; |
56dc6336 FF |
409 | struct list_head bf_head; |
410 | struct sk_buff_head bf_pending; | |
156369fa | 411 | u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0, seq_first; |
f078f209 | 412 | u32 ba[WME_BA_BMP_SIZE >> 5]; |
0934af23 | 413 | int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0; |
6fe7cc71 | 414 | bool rc_update = true, isba; |
78c4653a | 415 | struct ieee80211_tx_rate rates[4]; |
2d42efc4 | 416 | struct ath_frame_info *fi; |
ebd02287 | 417 | int nframes; |
5daefbd0 | 418 | u8 tidno; |
daa5c408 | 419 | bool flush = !!(ts->ts_status & ATH9K_TX_FLUSH); |
da647626 | 420 | int i, retries; |
156369fa | 421 | int bar_index = -1; |
f078f209 | 422 | |
a22be22a | 423 | skb = bf->bf_mpdu; |
1286ec6d S |
424 | hdr = (struct ieee80211_hdr *)skb->data; |
425 | ||
76d5a9e8 | 426 | tx_info = IEEE80211_SKB_CB(skb); |
76d5a9e8 | 427 | |
79acac07 | 428 | memcpy(rates, bf->rates, sizeof(rates)); |
78c4653a | 429 | |
da647626 FF |
430 | retries = ts->ts_longretry + 1; |
431 | for (i = 0; i < ts->ts_rateindex; i++) | |
432 | retries += rates[i].count; | |
433 | ||
1286ec6d | 434 | rcu_read_lock(); |
f078f209 | 435 | |
686b9cb9 | 436 | sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2); |
1286ec6d S |
437 | if (!sta) { |
438 | rcu_read_unlock(); | |
73e19463 | 439 | |
31e79a59 FF |
440 | INIT_LIST_HEAD(&bf_head); |
441 | while (bf) { | |
442 | bf_next = bf->bf_next; | |
443 | ||
fce041be | 444 | if (!bf->bf_stale || bf_next != NULL) |
31e79a59 FF |
445 | list_move_tail(&bf->list, &bf_head); |
446 | ||
156369fa | 447 | ath_tx_complete_buf(sc, bf, txq, &bf_head, ts, 0); |
31e79a59 FF |
448 | |
449 | bf = bf_next; | |
450 | } | |
1286ec6d | 451 | return; |
f078f209 LR |
452 | } |
453 | ||
1286ec6d | 454 | an = (struct ath_node *)sta->drv_priv; |
5daefbd0 FF |
455 | tidno = ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK; |
456 | tid = ATH_AN_2_TID(an, tidno); | |
156369fa | 457 | seq_first = tid->seq_start; |
6fe7cc71 | 458 | isba = ts->ts_flags & ATH9K_TX_BA; |
1286ec6d | 459 | |
b11b160d FF |
460 | /* |
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 | |
6fe7cc71 SE |
464 | * |
465 | * Only BlockAcks have a TID and therefore normal Acks cannot be | |
466 | * checked | |
b11b160d | 467 | */ |
6fe7cc71 | 468 | if (isba && tidno != ts->tid) |
b11b160d FF |
469 | txok = false; |
470 | ||
e8324357 | 471 | isaggr = bf_isaggr(bf); |
d43f3015 | 472 | memset(ba, 0, WME_BA_BMP_SIZE >> 3); |
f078f209 | 473 | |
d43f3015 | 474 | if (isaggr && txok) { |
db1a052b FF |
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); | |
e8324357 | 478 | } else { |
d43f3015 S |
479 | /* |
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. | |
485 | */ | |
2660b81a | 486 | if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) |
d43f3015 | 487 | needreset = 1; |
e8324357 | 488 | } |
f078f209 LR |
489 | } |
490 | ||
56dc6336 | 491 | __skb_queue_head_init(&bf_pending); |
f078f209 | 492 | |
b572d033 | 493 | ath_tx_count_frames(sc, bf, ts, txok, &nframes, &nbad); |
e8324357 | 494 | while (bf) { |
6a0ddaef FF |
495 | u16 seqno = bf->bf_state.seqno; |
496 | ||
f0b8220c | 497 | txfail = txpending = sendbar = 0; |
e8324357 | 498 | bf_next = bf->bf_next; |
f078f209 | 499 | |
78c4653a FF |
500 | skb = bf->bf_mpdu; |
501 | tx_info = IEEE80211_SKB_CB(skb); | |
2d42efc4 | 502 | fi = get_frame_info(skb); |
78c4653a | 503 | |
6a0ddaef | 504 | if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) { |
e8324357 S |
505 | /* transmit completion, subframe is |
506 | * acked by block ack */ | |
0934af23 | 507 | acked_cnt++; |
e8324357 S |
508 | } else if (!isaggr && txok) { |
509 | /* transmit completion */ | |
0934af23 | 510 | acked_cnt++; |
1381559b | 511 | } else if (tid->state & AGGR_CLEANUP) { |
b0477013 FF |
512 | /* |
513 | * cleanup in progress, just fail | |
514 | * the un-acked sub-frames | |
515 | */ | |
516 | txfail = 1; | |
517 | } else if (flush) { | |
518 | txpending = 1; | |
519 | } else if (fi->retries < ATH_MAX_SW_RETRIES) { | |
520 | if (txok || !an->sleeping) | |
521 | ath_tx_set_retry(sc, txq, bf->bf_mpdu, | |
522 | retries); | |
523 | ||
524 | txpending = 1; | |
e8324357 | 525 | } else { |
b0477013 FF |
526 | txfail = 1; |
527 | txfail_cnt++; | |
528 | bar_index = max_t(int, bar_index, | |
529 | ATH_BA_INDEX(seq_first, seqno)); | |
e8324357 | 530 | } |
f078f209 | 531 | |
fce041be FF |
532 | /* |
533 | * Make sure the last desc is reclaimed if it | |
534 | * not a holding desc. | |
535 | */ | |
56dc6336 | 536 | INIT_LIST_HEAD(&bf_head); |
99ba6a46 | 537 | if (bf_next != NULL || !bf_last->bf_stale) |
d43f3015 | 538 | list_move_tail(&bf->list, &bf_head); |
f078f209 | 539 | |
90fa539c | 540 | if (!txpending || (tid->state & AGGR_CLEANUP)) { |
e8324357 S |
541 | /* |
542 | * complete the acked-ones/xretried ones; update | |
543 | * block-ack window | |
544 | */ | |
6a0ddaef | 545 | ath_tx_update_baw(sc, tid, seqno); |
f078f209 | 546 | |
8a92e2ee | 547 | if (rc_update && (acked_cnt == 1 || txfail_cnt == 1)) { |
78c4653a | 548 | memcpy(tx_info->control.rates, rates, sizeof(rates)); |
3afd21e7 | 549 | ath_tx_rc_status(sc, bf, ts, nframes, nbad, txok); |
8a92e2ee | 550 | rc_update = false; |
8a92e2ee VT |
551 | } |
552 | ||
db1a052b | 553 | ath_tx_complete_buf(sc, bf, txq, &bf_head, ts, |
156369fa | 554 | !txfail); |
e8324357 | 555 | } else { |
d43f3015 | 556 | /* retry the un-acked ones */ |
99ba6a46 | 557 | if (bf->bf_next == NULL && bf_last->bf_stale) { |
b0477013 FF |
558 | struct ath_buf *tbf; |
559 | ||
560 | tbf = ath_clone_txbuf(sc, bf_last); | |
561 | /* | |
562 | * Update tx baw and complete the | |
563 | * frame with failed status if we | |
564 | * run out of tx buf. | |
565 | */ | |
566 | if (!tbf) { | |
b0477013 | 567 | ath_tx_update_baw(sc, tid, seqno); |
b0477013 FF |
568 | |
569 | ath_tx_complete_buf(sc, bf, txq, | |
570 | &bf_head, ts, 0); | |
571 | bar_index = max_t(int, bar_index, | |
572 | ATH_BA_INDEX(seq_first, seqno)); | |
573 | break; | |
c41d92dc | 574 | } |
b0477013 FF |
575 | |
576 | fi->bf = tbf; | |
e8324357 S |
577 | } |
578 | ||
579 | /* | |
580 | * Put this buffer to the temporary pending | |
581 | * queue to retain ordering | |
582 | */ | |
56dc6336 | 583 | __skb_queue_tail(&bf_pending, skb); |
e8324357 S |
584 | } |
585 | ||
586 | bf = bf_next; | |
f078f209 | 587 | } |
f078f209 | 588 | |
4cee7861 | 589 | /* prepend un-acked frames to the beginning of the pending frame queue */ |
56dc6336 | 590 | if (!skb_queue_empty(&bf_pending)) { |
5519541d | 591 | if (an->sleeping) |
042ec453 | 592 | ieee80211_sta_set_buffered(sta, tid->tidno, true); |
5519541d | 593 | |
56dc6336 | 594 | skb_queue_splice(&bf_pending, &tid->buf_q); |
26a64259 | 595 | if (!an->sleeping) { |
9af73cf7 | 596 | ath_tx_queue_tid(txq, tid); |
26a64259 | 597 | |
adfbda62 | 598 | if (ts->ts_status & (ATH9K_TXERR_FILT | ATH9K_TXERR_XRETRY)) |
26a64259 FF |
599 | tid->ac->clear_ps_filter = true; |
600 | } | |
4cee7861 FF |
601 | } |
602 | ||
23de5dc9 FF |
603 | if (bar_index >= 0) { |
604 | u16 bar_seq = ATH_BA_INDEX2SEQ(seq_first, bar_index); | |
605 | ||
606 | if (BAW_WITHIN(tid->seq_start, tid->baw_size, bar_seq)) | |
607 | tid->bar_index = ATH_BA_INDEX(tid->seq_start, bar_seq); | |
608 | ||
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); | |
612 | } | |
613 | ||
4eb287a4 | 614 | if (tid->state & AGGR_CLEANUP) |
16e23428 | 615 | ath_tx_flush_tid(sc, tid, false); |
90fa539c | 616 | |
1286ec6d S |
617 | rcu_read_unlock(); |
618 | ||
124b979b RM |
619 | if (needreset) |
620 | ath9k_queue_reset(sc, RESET_TYPE_TX_ERROR); | |
e8324357 | 621 | } |
f078f209 | 622 | |
81b51950 FF |
623 | static bool bf_is_ampdu_not_probing(struct ath_buf *bf) |
624 | { | |
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); | |
627 | } | |
628 | ||
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) | |
632 | { | |
0c585dda | 633 | struct ieee80211_tx_info *info; |
81b51950 FF |
634 | bool txok, flush; |
635 | ||
636 | txok = !(ts->ts_status & ATH9K_TXERR_MASK); | |
637 | flush = !!(ts->ts_status & ATH9K_TX_FLUSH); | |
638 | txq->axq_tx_inprogress = false; | |
639 | ||
640 | txq->axq_depth--; | |
641 | if (bf_is_ampdu_not_probing(bf)) | |
642 | txq->axq_ampdu_depth--; | |
643 | ||
644 | if (!bf_isampdu(bf)) { | |
0c585dda FF |
645 | if (!flush) { |
646 | info = IEEE80211_SKB_CB(bf->bf_mpdu); | |
647 | memcpy(info->control.rates, bf->rates, | |
648 | sizeof(info->control.rates)); | |
81b51950 | 649 | ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok); |
0c585dda | 650 | } |
81b51950 FF |
651 | ath_tx_complete_buf(sc, bf, txq, bf_head, ts, txok); |
652 | } else | |
653 | ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok); | |
654 | ||
655 | if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) && !flush) | |
656 | ath_txq_schedule(sc, txq); | |
657 | } | |
658 | ||
1a6e9d0f RM |
659 | static bool ath_lookup_legacy(struct ath_buf *bf) |
660 | { | |
661 | struct sk_buff *skb; | |
662 | struct ieee80211_tx_info *tx_info; | |
663 | struct ieee80211_tx_rate *rates; | |
664 | int i; | |
665 | ||
666 | skb = bf->bf_mpdu; | |
667 | tx_info = IEEE80211_SKB_CB(skb); | |
668 | rates = tx_info->control.rates; | |
669 | ||
059ee09b FF |
670 | for (i = 0; i < 4; i++) { |
671 | if (!rates[i].count || rates[i].idx < 0) | |
672 | break; | |
673 | ||
1a6e9d0f RM |
674 | if (!(rates[i].flags & IEEE80211_TX_RC_MCS)) |
675 | return true; | |
676 | } | |
677 | ||
678 | return false; | |
679 | } | |
680 | ||
e8324357 S |
681 | static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf, |
682 | struct ath_atx_tid *tid) | |
f078f209 | 683 | { |
528f0c6b S |
684 | struct sk_buff *skb; |
685 | struct ieee80211_tx_info *tx_info; | |
a8efee4f | 686 | struct ieee80211_tx_rate *rates; |
d43f3015 | 687 | u32 max_4ms_framelen, frmlen; |
c0ac53fa | 688 | u16 aggr_limit, bt_aggr_limit, legacy = 0; |
aa5955c3 | 689 | int q = tid->ac->txq->mac80211_qnum; |
e8324357 | 690 | int i; |
528f0c6b | 691 | |
a22be22a | 692 | skb = bf->bf_mpdu; |
528f0c6b | 693 | tx_info = IEEE80211_SKB_CB(skb); |
0c585dda | 694 | rates = bf->rates; |
528f0c6b | 695 | |
e8324357 S |
696 | /* |
697 | * Find the lowest frame length among the rate series that will have a | |
aa5955c3 | 698 | * 4ms (or TXOP limited) transmit duration. |
e8324357 S |
699 | */ |
700 | max_4ms_framelen = ATH_AMPDU_LIMIT_MAX; | |
e63835b0 | 701 | |
e8324357 | 702 | for (i = 0; i < 4; i++) { |
b0477013 | 703 | int modeidx; |
e8324357 | 704 | |
b0477013 FF |
705 | if (!rates[i].count) |
706 | continue; | |
545750d3 | 707 | |
b0477013 FF |
708 | if (!(rates[i].flags & IEEE80211_TX_RC_MCS)) { |
709 | legacy = 1; | |
710 | break; | |
f078f209 | 711 | } |
b0477013 FF |
712 | |
713 | if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) | |
714 | modeidx = MCS_HT40; | |
715 | else | |
716 | modeidx = MCS_HT20; | |
717 | ||
718 | if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI) | |
719 | modeidx++; | |
720 | ||
aa5955c3 | 721 | frmlen = sc->tx.max_aggr_framelen[q][modeidx][rates[i].idx]; |
b0477013 | 722 | max_4ms_framelen = min(max_4ms_framelen, frmlen); |
f078f209 | 723 | } |
e63835b0 | 724 | |
f078f209 | 725 | /* |
e8324357 S |
726 | * limit aggregate size by the minimum rate if rate selected is |
727 | * not a probe rate, if rate selected is a probe rate then | |
728 | * avoid aggregation of this packet. | |
f078f209 | 729 | */ |
e8324357 S |
730 | if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy) |
731 | return 0; | |
f078f209 | 732 | |
c0ac53fa SM |
733 | aggr_limit = min(max_4ms_framelen, (u32)ATH_AMPDU_LIMIT_MAX); |
734 | ||
735 | /* | |
736 | * Override the default aggregation limit for BTCOEX. | |
737 | */ | |
738 | bt_aggr_limit = ath9k_btcoex_aggr_limit(sc, max_4ms_framelen); | |
739 | if (bt_aggr_limit) | |
740 | aggr_limit = bt_aggr_limit; | |
f078f209 | 741 | |
e8324357 | 742 | /* |
25985edc LDM |
743 | * h/w can accept aggregates up to 16 bit lengths (65535). |
744 | * The IE, however can hold up to 65536, which shows up here | |
e8324357 | 745 | * as zero. Ignore 65536 since we are constrained by hw. |
f078f209 | 746 | */ |
4ef70841 S |
747 | if (tid->an->maxampdu) |
748 | aggr_limit = min(aggr_limit, tid->an->maxampdu); | |
f078f209 | 749 | |
e8324357 S |
750 | return aggr_limit; |
751 | } | |
f078f209 | 752 | |
e8324357 | 753 | /* |
d43f3015 | 754 | * Returns the number of delimiters to be added to |
e8324357 | 755 | * meet the minimum required mpdudensity. |
e8324357 S |
756 | */ |
757 | static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid, | |
7a12dfdb RM |
758 | struct ath_buf *bf, u16 frmlen, |
759 | bool first_subfrm) | |
e8324357 | 760 | { |
7a12dfdb | 761 | #define FIRST_DESC_NDELIMS 60 |
4ef70841 | 762 | u32 nsymbits, nsymbols; |
e8324357 | 763 | u16 minlen; |
545750d3 | 764 | u8 flags, rix; |
c6663876 | 765 | int width, streams, half_gi, ndelim, mindelim; |
2d42efc4 | 766 | struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu); |
e8324357 S |
767 | |
768 | /* Select standard number of delimiters based on frame length alone */ | |
769 | ndelim = ATH_AGGR_GET_NDELIM(frmlen); | |
f078f209 LR |
770 | |
771 | /* | |
e8324357 S |
772 | * If encryption enabled, hardware requires some more padding between |
773 | * subframes. | |
774 | * TODO - this could be improved to be dependent on the rate. | |
775 | * The hardware can keep up at lower rates, but not higher rates | |
f078f209 | 776 | */ |
4f6760b0 RM |
777 | if ((fi->keyix != ATH9K_TXKEYIX_INVALID) && |
778 | !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)) | |
e8324357 | 779 | ndelim += ATH_AGGR_ENCRYPTDELIM; |
f078f209 | 780 | |
7a12dfdb RM |
781 | /* |
782 | * Add delimiter when using RTS/CTS with aggregation | |
783 | * and non enterprise AR9003 card | |
784 | */ | |
3459731a FF |
785 | if (first_subfrm && !AR_SREV_9580_10_OR_LATER(sc->sc_ah) && |
786 | (sc->sc_ah->ent_mode & AR_ENT_OTP_MIN_PKT_SIZE_DISABLE)) | |
7a12dfdb RM |
787 | ndelim = max(ndelim, FIRST_DESC_NDELIMS); |
788 | ||
e8324357 S |
789 | /* |
790 | * Convert desired mpdu density from microeconds to bytes based | |
791 | * on highest rate in rate series (i.e. first rate) to determine | |
792 | * required minimum length for subframe. Take into account | |
793 | * whether high rate is 20 or 40Mhz and half or full GI. | |
4ef70841 | 794 | * |
e8324357 S |
795 | * If there is no mpdu density restriction, no further calculation |
796 | * is needed. | |
797 | */ | |
4ef70841 S |
798 | |
799 | if (tid->an->mpdudensity == 0) | |
e8324357 | 800 | return ndelim; |
f078f209 | 801 | |
79acac07 FF |
802 | rix = bf->rates[0].idx; |
803 | flags = bf->rates[0].flags; | |
e8324357 S |
804 | width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0; |
805 | half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0; | |
f078f209 | 806 | |
e8324357 | 807 | if (half_gi) |
4ef70841 | 808 | nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(tid->an->mpdudensity); |
e8324357 | 809 | else |
4ef70841 | 810 | nsymbols = NUM_SYMBOLS_PER_USEC(tid->an->mpdudensity); |
f078f209 | 811 | |
e8324357 S |
812 | if (nsymbols == 0) |
813 | nsymbols = 1; | |
f078f209 | 814 | |
c6663876 FF |
815 | streams = HT_RC_2_STREAMS(rix); |
816 | nsymbits = bits_per_symbol[rix % 8][width] * streams; | |
e8324357 | 817 | minlen = (nsymbols * nsymbits) / BITS_PER_BYTE; |
f078f209 | 818 | |
e8324357 | 819 | if (frmlen < minlen) { |
e8324357 S |
820 | mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ; |
821 | ndelim = max(mindelim, ndelim); | |
f078f209 LR |
822 | } |
823 | ||
e8324357 | 824 | return ndelim; |
f078f209 LR |
825 | } |
826 | ||
e8324357 | 827 | static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc, |
fec247c0 | 828 | struct ath_txq *txq, |
d43f3015 | 829 | struct ath_atx_tid *tid, |
269c44bc FF |
830 | struct list_head *bf_q, |
831 | int *aggr_len) | |
f078f209 | 832 | { |
e8324357 | 833 | #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4) |
56dc6336 | 834 | struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL; |
d43f3015 | 835 | int rl = 0, nframes = 0, ndelim, prev_al = 0; |
e8324357 S |
836 | u16 aggr_limit = 0, al = 0, bpad = 0, |
837 | al_delta, h_baw = tid->baw_size / 2; | |
838 | enum ATH_AGGR_STATUS status = ATH_AGGR_DONE; | |
0299a50a | 839 | struct ieee80211_tx_info *tx_info; |
2d42efc4 | 840 | struct ath_frame_info *fi; |
56dc6336 | 841 | struct sk_buff *skb; |
6a0ddaef | 842 | u16 seqno; |
f078f209 | 843 | |
e8324357 | 844 | do { |
56dc6336 FF |
845 | skb = skb_peek(&tid->buf_q); |
846 | fi = get_frame_info(skb); | |
847 | bf = fi->bf; | |
44f1d26c | 848 | if (!fi->bf) |
249ee722 | 849 | bf = ath_tx_setup_buffer(sc, txq, tid, skb); |
56dc6336 | 850 | |
249ee722 FF |
851 | if (!bf) { |
852 | __skb_unlink(skb, &tid->buf_q); | |
853 | ieee80211_free_txskb(sc->hw, skb); | |
44f1d26c | 854 | continue; |
249ee722 | 855 | } |
44f1d26c | 856 | |
399c6489 | 857 | bf->bf_state.bf_type = BUF_AMPDU | BUF_AGGR; |
44f1d26c | 858 | seqno = bf->bf_state.seqno; |
f078f209 | 859 | |
d43f3015 | 860 | /* do not step over block-ack window */ |
6a0ddaef | 861 | if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) { |
e8324357 S |
862 | status = ATH_AGGR_BAW_CLOSED; |
863 | break; | |
864 | } | |
f078f209 | 865 | |
f9437543 FF |
866 | if (tid->bar_index > ATH_BA_INDEX(tid->seq_start, seqno)) { |
867 | struct ath_tx_status ts = {}; | |
868 | struct list_head bf_head; | |
869 | ||
870 | INIT_LIST_HEAD(&bf_head); | |
871 | list_add(&bf->list, &bf_head); | |
872 | __skb_unlink(skb, &tid->buf_q); | |
873 | ath_tx_update_baw(sc, tid, seqno); | |
874 | ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0); | |
875 | continue; | |
876 | } | |
877 | ||
878 | if (!bf_first) | |
879 | bf_first = bf; | |
880 | ||
e8324357 | 881 | if (!rl) { |
79acac07 | 882 | ath_set_rates(tid->an->vif, tid->an->sta, bf); |
e8324357 S |
883 | aggr_limit = ath_lookup_rate(sc, bf, tid); |
884 | rl = 1; | |
885 | } | |
f078f209 | 886 | |
d43f3015 | 887 | /* do not exceed aggregation limit */ |
2d42efc4 | 888 | al_delta = ATH_AGGR_DELIM_SZ + fi->framelen; |
f078f209 | 889 | |
d43f3015 | 890 | if (nframes && |
1a6e9d0f RM |
891 | ((aggr_limit < (al + bpad + al_delta + prev_al)) || |
892 | ath_lookup_legacy(bf))) { | |
e8324357 S |
893 | status = ATH_AGGR_LIMITED; |
894 | break; | |
895 | } | |
f078f209 | 896 | |
0299a50a | 897 | tx_info = IEEE80211_SKB_CB(bf->bf_mpdu); |
bdf2dbfb | 898 | if (nframes && (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)) |
0299a50a FF |
899 | break; |
900 | ||
d43f3015 S |
901 | /* do not exceed subframe limit */ |
902 | if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) { | |
e8324357 S |
903 | status = ATH_AGGR_LIMITED; |
904 | break; | |
905 | } | |
f078f209 | 906 | |
d43f3015 | 907 | /* add padding for previous frame to aggregation length */ |
e8324357 | 908 | al += bpad + al_delta; |
f078f209 | 909 | |
e8324357 S |
910 | /* |
911 | * Get the delimiters needed to meet the MPDU | |
912 | * density for this node. | |
913 | */ | |
7a12dfdb RM |
914 | ndelim = ath_compute_num_delims(sc, tid, bf_first, fi->framelen, |
915 | !nframes); | |
e8324357 | 916 | bpad = PADBYTES(al_delta) + (ndelim << 2); |
f078f209 | 917 | |
7a12dfdb | 918 | nframes++; |
e8324357 | 919 | bf->bf_next = NULL; |
f078f209 | 920 | |
d43f3015 | 921 | /* link buffers of this frame to the aggregate */ |
2d42efc4 | 922 | if (!fi->retries) |
6a0ddaef | 923 | ath_tx_addto_baw(sc, tid, seqno); |
399c6489 | 924 | bf->bf_state.ndelim = ndelim; |
56dc6336 FF |
925 | |
926 | __skb_unlink(skb, &tid->buf_q); | |
927 | list_add_tail(&bf->list, bf_q); | |
399c6489 | 928 | if (bf_prev) |
e8324357 | 929 | bf_prev->bf_next = bf; |
399c6489 | 930 | |
e8324357 | 931 | bf_prev = bf; |
fec247c0 | 932 | |
56dc6336 | 933 | } while (!skb_queue_empty(&tid->buf_q)); |
f078f209 | 934 | |
269c44bc | 935 | *aggr_len = al; |
d43f3015 | 936 | |
e8324357 S |
937 | return status; |
938 | #undef PADBYTES | |
939 | } | |
f078f209 | 940 | |
38dad7ba FF |
941 | /* |
942 | * rix - rate index | |
943 | * pktlen - total bytes (delims + data + fcs + pads + pad delims) | |
944 | * width - 0 for 20 MHz, 1 for 40 MHz | |
945 | * half_gi - to use 4us v/s 3.6 us for symbol time | |
946 | */ | |
947 | static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, int pktlen, | |
948 | int width, int half_gi, bool shortPreamble) | |
949 | { | |
950 | u32 nbits, nsymbits, duration, nsymbols; | |
951 | int streams; | |
952 | ||
953 | /* find number of symbols: PLCP + data */ | |
954 | streams = HT_RC_2_STREAMS(rix); | |
955 | nbits = (pktlen << 3) + OFDM_PLCP_BITS; | |
956 | nsymbits = bits_per_symbol[rix % 8][width] * streams; | |
957 | nsymbols = (nbits + nsymbits - 1) / nsymbits; | |
958 | ||
959 | if (!half_gi) | |
960 | duration = SYMBOL_TIME(nsymbols); | |
961 | else | |
962 | duration = SYMBOL_TIME_HALFGI(nsymbols); | |
963 | ||
964 | /* addup duration for legacy/ht training and signal fields */ | |
965 | duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams); | |
966 | ||
967 | return duration; | |
968 | } | |
969 | ||
aa5955c3 FF |
970 | static int ath_max_framelen(int usec, int mcs, bool ht40, bool sgi) |
971 | { | |
972 | int streams = HT_RC_2_STREAMS(mcs); | |
973 | int symbols, bits; | |
974 | int bytes = 0; | |
975 | ||
976 | symbols = sgi ? TIME_SYMBOLS_HALFGI(usec) : TIME_SYMBOLS(usec); | |
977 | bits = symbols * bits_per_symbol[mcs % 8][ht40] * streams; | |
978 | bits -= OFDM_PLCP_BITS; | |
979 | bytes = bits / 8; | |
980 | bytes -= L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams); | |
981 | if (bytes > 65532) | |
982 | bytes = 65532; | |
983 | ||
984 | return bytes; | |
985 | } | |
986 | ||
987 | void ath_update_max_aggr_framelen(struct ath_softc *sc, int queue, int txop) | |
988 | { | |
989 | u16 *cur_ht20, *cur_ht20_sgi, *cur_ht40, *cur_ht40_sgi; | |
990 | int mcs; | |
991 | ||
992 | /* 4ms is the default (and maximum) duration */ | |
993 | if (!txop || txop > 4096) | |
994 | txop = 4096; | |
995 | ||
996 | cur_ht20 = sc->tx.max_aggr_framelen[queue][MCS_HT20]; | |
997 | cur_ht20_sgi = sc->tx.max_aggr_framelen[queue][MCS_HT20_SGI]; | |
998 | cur_ht40 = sc->tx.max_aggr_framelen[queue][MCS_HT40]; | |
999 | cur_ht40_sgi = sc->tx.max_aggr_framelen[queue][MCS_HT40_SGI]; | |
1000 | for (mcs = 0; mcs < 32; mcs++) { | |
1001 | cur_ht20[mcs] = ath_max_framelen(txop, mcs, false, false); | |
1002 | cur_ht20_sgi[mcs] = ath_max_framelen(txop, mcs, false, true); | |
1003 | cur_ht40[mcs] = ath_max_framelen(txop, mcs, true, false); | |
1004 | cur_ht40_sgi[mcs] = ath_max_framelen(txop, mcs, true, true); | |
1005 | } | |
1006 | } | |
1007 | ||
493cf04f FF |
1008 | static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf, |
1009 | struct ath_tx_info *info, int len) | |
38dad7ba FF |
1010 | { |
1011 | struct ath_hw *ah = sc->sc_ah; | |
38dad7ba FF |
1012 | struct sk_buff *skb; |
1013 | struct ieee80211_tx_info *tx_info; | |
1014 | struct ieee80211_tx_rate *rates; | |
1015 | const struct ieee80211_rate *rate; | |
1016 | struct ieee80211_hdr *hdr; | |
80b08a8d | 1017 | struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu); |
493cf04f FF |
1018 | int i; |
1019 | u8 rix = 0; | |
38dad7ba FF |
1020 | |
1021 | skb = bf->bf_mpdu; | |
1022 | tx_info = IEEE80211_SKB_CB(skb); | |
79acac07 | 1023 | rates = bf->rates; |
38dad7ba | 1024 | hdr = (struct ieee80211_hdr *)skb->data; |
493cf04f FF |
1025 | |
1026 | /* set dur_update_en for l-sig computation except for PS-Poll frames */ | |
1027 | info->dur_update = !ieee80211_is_pspoll(hdr->frame_control); | |
80b08a8d | 1028 | info->rtscts_rate = fi->rtscts_rate; |
38dad7ba | 1029 | |
79acac07 | 1030 | for (i = 0; i < ARRAY_SIZE(bf->rates); i++) { |
38dad7ba FF |
1031 | bool is_40, is_sgi, is_sp; |
1032 | int phy; | |
1033 | ||
1034 | if (!rates[i].count || (rates[i].idx < 0)) | |
1035 | continue; | |
1036 | ||
1037 | rix = rates[i].idx; | |
493cf04f | 1038 | info->rates[i].Tries = rates[i].count; |
38dad7ba FF |
1039 | |
1040 | if (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) { | |
493cf04f FF |
1041 | info->rates[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS; |
1042 | info->flags |= ATH9K_TXDESC_RTSENA; | |
38dad7ba | 1043 | } else if (rates[i].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
493cf04f FF |
1044 | info->rates[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS; |
1045 | info->flags |= ATH9K_TXDESC_CTSENA; | |
38dad7ba FF |
1046 | } |
1047 | ||
1048 | if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) | |
493cf04f | 1049 | info->rates[i].RateFlags |= ATH9K_RATESERIES_2040; |
38dad7ba | 1050 | if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI) |
493cf04f | 1051 | info->rates[i].RateFlags |= ATH9K_RATESERIES_HALFGI; |
38dad7ba FF |
1052 | |
1053 | is_sgi = !!(rates[i].flags & IEEE80211_TX_RC_SHORT_GI); | |
1054 | is_40 = !!(rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH); | |
1055 | is_sp = !!(rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE); | |
1056 | ||
1057 | if (rates[i].flags & IEEE80211_TX_RC_MCS) { | |
1058 | /* MCS rates */ | |
493cf04f FF |
1059 | info->rates[i].Rate = rix | 0x80; |
1060 | info->rates[i].ChSel = ath_txchainmask_reduction(sc, | |
1061 | ah->txchainmask, info->rates[i].Rate); | |
1062 | info->rates[i].PktDuration = ath_pkt_duration(sc, rix, len, | |
38dad7ba FF |
1063 | is_40, is_sgi, is_sp); |
1064 | if (rix < 8 && (tx_info->flags & IEEE80211_TX_CTL_STBC)) | |
493cf04f | 1065 | info->rates[i].RateFlags |= ATH9K_RATESERIES_STBC; |
38dad7ba FF |
1066 | continue; |
1067 | } | |
1068 | ||
1069 | /* legacy rates */ | |
76591bea | 1070 | rate = &sc->sbands[tx_info->band].bitrates[rates[i].idx]; |
38dad7ba FF |
1071 | if ((tx_info->band == IEEE80211_BAND_2GHZ) && |
1072 | !(rate->flags & IEEE80211_RATE_ERP_G)) | |
1073 | phy = WLAN_RC_PHY_CCK; | |
1074 | else | |
1075 | phy = WLAN_RC_PHY_OFDM; | |
1076 | ||
493cf04f | 1077 | info->rates[i].Rate = rate->hw_value; |
38dad7ba FF |
1078 | if (rate->hw_value_short) { |
1079 | if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) | |
493cf04f | 1080 | info->rates[i].Rate |= rate->hw_value_short; |
38dad7ba FF |
1081 | } else { |
1082 | is_sp = false; | |
1083 | } | |
1084 | ||
1085 | if (bf->bf_state.bfs_paprd) | |
493cf04f | 1086 | info->rates[i].ChSel = ah->txchainmask; |
38dad7ba | 1087 | else |
493cf04f FF |
1088 | info->rates[i].ChSel = ath_txchainmask_reduction(sc, |
1089 | ah->txchainmask, info->rates[i].Rate); | |
38dad7ba | 1090 | |
493cf04f | 1091 | info->rates[i].PktDuration = ath9k_hw_computetxtime(sc->sc_ah, |
38dad7ba FF |
1092 | phy, rate->bitrate * 100, len, rix, is_sp); |
1093 | } | |
1094 | ||
1095 | /* For AR5416 - RTS cannot be followed by a frame larger than 8K */ | |
1096 | if (bf_isaggr(bf) && (len > sc->sc_ah->caps.rts_aggr_limit)) | |
493cf04f | 1097 | info->flags &= ~ATH9K_TXDESC_RTSENA; |
38dad7ba FF |
1098 | |
1099 | /* ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive. */ | |
493cf04f FF |
1100 | if (info->flags & ATH9K_TXDESC_RTSENA) |
1101 | info->flags &= ~ATH9K_TXDESC_CTSENA; | |
1102 | } | |
38dad7ba | 1103 | |
493cf04f FF |
1104 | static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb) |
1105 | { | |
1106 | struct ieee80211_hdr *hdr; | |
1107 | enum ath9k_pkt_type htype; | |
1108 | __le16 fc; | |
1109 | ||
1110 | hdr = (struct ieee80211_hdr *)skb->data; | |
1111 | fc = hdr->frame_control; | |
38dad7ba | 1112 | |
493cf04f FF |
1113 | if (ieee80211_is_beacon(fc)) |
1114 | htype = ATH9K_PKT_TYPE_BEACON; | |
1115 | else if (ieee80211_is_probe_resp(fc)) | |
1116 | htype = ATH9K_PKT_TYPE_PROBE_RESP; | |
1117 | else if (ieee80211_is_atim(fc)) | |
1118 | htype = ATH9K_PKT_TYPE_ATIM; | |
1119 | else if (ieee80211_is_pspoll(fc)) | |
1120 | htype = ATH9K_PKT_TYPE_PSPOLL; | |
1121 | else | |
1122 | htype = ATH9K_PKT_TYPE_NORMAL; | |
1123 | ||
1124 | return htype; | |
38dad7ba FF |
1125 | } |
1126 | ||
493cf04f FF |
1127 | static void ath_tx_fill_desc(struct ath_softc *sc, struct ath_buf *bf, |
1128 | struct ath_txq *txq, int len) | |
399c6489 FF |
1129 | { |
1130 | struct ath_hw *ah = sc->sc_ah; | |
1131 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(bf->bf_mpdu); | |
1132 | struct ath_buf *bf_first = bf; | |
493cf04f | 1133 | struct ath_tx_info info; |
399c6489 | 1134 | bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR); |
399c6489 | 1135 | |
493cf04f FF |
1136 | memset(&info, 0, sizeof(info)); |
1137 | info.is_first = true; | |
1138 | info.is_last = true; | |
1139 | info.txpower = MAX_RATE_POWER; | |
1140 | info.qcu = txq->axq_qnum; | |
1141 | ||
1142 | info.flags = ATH9K_TXDESC_INTREQ; | |
1143 | if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) | |
1144 | info.flags |= ATH9K_TXDESC_NOACK; | |
1145 | if (tx_info->flags & IEEE80211_TX_CTL_LDPC) | |
1146 | info.flags |= ATH9K_TXDESC_LDPC; | |
1147 | ||
1148 | ath_buf_set_rate(sc, bf, &info, len); | |
1149 | ||
1150 | if (tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) | |
1151 | info.flags |= ATH9K_TXDESC_CLRDMASK; | |
1152 | ||
1153 | if (bf->bf_state.bfs_paprd) | |
1154 | info.flags |= (u32) bf->bf_state.bfs_paprd << ATH9K_TXDESC_PAPRD_S; | |
399c6489 | 1155 | |
399c6489 FF |
1156 | |
1157 | while (bf) { | |
493cf04f FF |
1158 | struct sk_buff *skb = bf->bf_mpdu; |
1159 | struct ath_frame_info *fi = get_frame_info(skb); | |
1160 | ||
1161 | info.type = get_hw_packet_type(skb); | |
399c6489 | 1162 | if (bf->bf_next) |
493cf04f | 1163 | info.link = bf->bf_next->bf_daddr; |
399c6489 | 1164 | else |
493cf04f FF |
1165 | info.link = 0; |
1166 | ||
42cecc34 JL |
1167 | info.buf_addr[0] = bf->bf_buf_addr; |
1168 | info.buf_len[0] = skb->len; | |
493cf04f FF |
1169 | info.pkt_len = fi->framelen; |
1170 | info.keyix = fi->keyix; | |
1171 | info.keytype = fi->keytype; | |
1172 | ||
1173 | if (aggr) { | |
399c6489 | 1174 | if (bf == bf_first) |
493cf04f FF |
1175 | info.aggr = AGGR_BUF_FIRST; |
1176 | else if (!bf->bf_next) | |
1177 | info.aggr = AGGR_BUF_LAST; | |
1178 | else | |
1179 | info.aggr = AGGR_BUF_MIDDLE; | |
399c6489 | 1180 | |
493cf04f FF |
1181 | info.ndelim = bf->bf_state.ndelim; |
1182 | info.aggr_len = len; | |
399c6489 FF |
1183 | } |
1184 | ||
493cf04f | 1185 | ath9k_hw_set_txdesc(ah, bf->bf_desc, &info); |
399c6489 FF |
1186 | bf = bf->bf_next; |
1187 | } | |
1188 | } | |
1189 | ||
e8324357 S |
1190 | static void ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq, |
1191 | struct ath_atx_tid *tid) | |
1192 | { | |
d43f3015 | 1193 | struct ath_buf *bf; |
e8324357 | 1194 | enum ATH_AGGR_STATUS status; |
399c6489 | 1195 | struct ieee80211_tx_info *tx_info; |
e8324357 | 1196 | struct list_head bf_q; |
269c44bc | 1197 | int aggr_len; |
f078f209 | 1198 | |
e8324357 | 1199 | do { |
56dc6336 | 1200 | if (skb_queue_empty(&tid->buf_q)) |
e8324357 | 1201 | return; |
f078f209 | 1202 | |
e8324357 S |
1203 | INIT_LIST_HEAD(&bf_q); |
1204 | ||
269c44bc | 1205 | status = ath_tx_form_aggr(sc, txq, tid, &bf_q, &aggr_len); |
f078f209 | 1206 | |
f078f209 | 1207 | /* |
d43f3015 S |
1208 | * no frames picked up to be aggregated; |
1209 | * block-ack window is not open. | |
f078f209 | 1210 | */ |
e8324357 S |
1211 | if (list_empty(&bf_q)) |
1212 | break; | |
f078f209 | 1213 | |
e8324357 | 1214 | bf = list_first_entry(&bf_q, struct ath_buf, list); |
d43f3015 | 1215 | bf->bf_lastbf = list_entry(bf_q.prev, struct ath_buf, list); |
399c6489 | 1216 | tx_info = IEEE80211_SKB_CB(bf->bf_mpdu); |
f078f209 | 1217 | |
5519541d FF |
1218 | if (tid->ac->clear_ps_filter) { |
1219 | tid->ac->clear_ps_filter = false; | |
399c6489 FF |
1220 | tx_info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; |
1221 | } else { | |
1222 | tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT; | |
5519541d FF |
1223 | } |
1224 | ||
d43f3015 | 1225 | /* if only one frame, send as non-aggregate */ |
b572d033 | 1226 | if (bf == bf->bf_lastbf) { |
399c6489 FF |
1227 | aggr_len = get_frame_info(bf->bf_mpdu)->framelen; |
1228 | bf->bf_state.bf_type = BUF_AMPDU; | |
1229 | } else { | |
1230 | TX_STAT_INC(txq->axq_qnum, a_aggr); | |
e8324357 | 1231 | } |
f078f209 | 1232 | |
493cf04f | 1233 | ath_tx_fill_desc(sc, bf, txq, aggr_len); |
fce041be | 1234 | ath_tx_txqaddbuf(sc, txq, &bf_q, false); |
4b3ba66a | 1235 | } while (txq->axq_ampdu_depth < ATH_AGGR_MIN_QDEPTH && |
e8324357 S |
1236 | status != ATH_AGGR_BAW_CLOSED); |
1237 | } | |
1238 | ||
231c3a1f FF |
1239 | int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta, |
1240 | u16 tid, u16 *ssn) | |
e8324357 S |
1241 | { |
1242 | struct ath_atx_tid *txtid; | |
1243 | struct ath_node *an; | |
313eb87f | 1244 | u8 density; |
e8324357 S |
1245 | |
1246 | an = (struct ath_node *)sta->drv_priv; | |
f83da965 | 1247 | txtid = ATH_AN_2_TID(an, tid); |
231c3a1f FF |
1248 | |
1249 | if (txtid->state & (AGGR_CLEANUP | AGGR_ADDBA_COMPLETE)) | |
1250 | return -EAGAIN; | |
1251 | ||
313eb87f SE |
1252 | /* update ampdu factor/density, they may have changed. This may happen |
1253 | * in HT IBSS when a beacon with HT-info is received after the station | |
1254 | * has already been added. | |
1255 | */ | |
dd5ee59b | 1256 | if (sta->ht_cap.ht_supported) { |
313eb87f SE |
1257 | an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
1258 | sta->ht_cap.ampdu_factor); | |
1259 | density = ath9k_parse_mpdudensity(sta->ht_cap.ampdu_density); | |
1260 | an->mpdudensity = density; | |
1261 | } | |
1262 | ||
f83da965 | 1263 | txtid->state |= AGGR_ADDBA_PROGRESS; |
75401849 | 1264 | txtid->paused = true; |
49447f2f | 1265 | *ssn = txtid->seq_start = txtid->seq_next; |
f9437543 | 1266 | txtid->bar_index = -1; |
231c3a1f | 1267 | |
2ed72229 FF |
1268 | memset(txtid->tx_buf, 0, sizeof(txtid->tx_buf)); |
1269 | txtid->baw_head = txtid->baw_tail = 0; | |
1270 | ||
231c3a1f | 1271 | return 0; |
e8324357 | 1272 | } |
f078f209 | 1273 | |
16e23428 FF |
1274 | bool ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid, |
1275 | bool flush) | |
e8324357 S |
1276 | { |
1277 | struct ath_node *an = (struct ath_node *)sta->drv_priv; | |
1278 | struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid); | |
066dae93 | 1279 | struct ath_txq *txq = txtid->ac->txq; |
16e23428 FF |
1280 | bool ret = !flush; |
1281 | ||
1282 | if (flush) | |
1283 | txtid->stop_cb = false; | |
f078f209 | 1284 | |
e8324357 | 1285 | if (txtid->state & AGGR_CLEANUP) |
16e23428 | 1286 | return false; |
f078f209 | 1287 | |
e8324357 | 1288 | if (!(txtid->state & AGGR_ADDBA_COMPLETE)) { |
5eae6592 | 1289 | txtid->state &= ~AGGR_ADDBA_PROGRESS; |
16e23428 | 1290 | return ret; |
e8324357 | 1291 | } |
f078f209 | 1292 | |
23de5dc9 | 1293 | ath_txq_lock(sc, txq); |
75401849 | 1294 | txtid->paused = true; |
f078f209 | 1295 | |
90fa539c FF |
1296 | /* |
1297 | * If frames are still being transmitted for this TID, they will be | |
1298 | * cleaned up during tx completion. To prevent race conditions, this | |
1299 | * TID can only be reused after all in-progress subframes have been | |
1300 | * completed. | |
1301 | */ | |
16e23428 | 1302 | if (txtid->baw_head != txtid->baw_tail) { |
e8324357 | 1303 | txtid->state |= AGGR_CLEANUP; |
16e23428 FF |
1304 | ret = false; |
1305 | txtid->stop_cb = !flush; | |
1306 | } else { | |
e8324357 | 1307 | txtid->state &= ~AGGR_ADDBA_COMPLETE; |
16e23428 | 1308 | } |
90fa539c | 1309 | |
16e23428 | 1310 | ath_tx_flush_tid(sc, txtid, flush); |
23de5dc9 | 1311 | ath_txq_unlock_complete(sc, txq); |
16e23428 | 1312 | return ret; |
e8324357 | 1313 | } |
f078f209 | 1314 | |
042ec453 JB |
1315 | void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc, |
1316 | struct ath_node *an) | |
5519541d FF |
1317 | { |
1318 | struct ath_atx_tid *tid; | |
1319 | struct ath_atx_ac *ac; | |
1320 | struct ath_txq *txq; | |
042ec453 | 1321 | bool buffered; |
5519541d FF |
1322 | int tidno; |
1323 | ||
1324 | for (tidno = 0, tid = &an->tid[tidno]; | |
de7b7604 | 1325 | tidno < IEEE80211_NUM_TIDS; tidno++, tid++) { |
5519541d FF |
1326 | |
1327 | if (!tid->sched) | |
1328 | continue; | |
1329 | ||
1330 | ac = tid->ac; | |
1331 | txq = ac->txq; | |
1332 | ||
23de5dc9 | 1333 | ath_txq_lock(sc, txq); |
5519541d | 1334 | |
042ec453 | 1335 | buffered = !skb_queue_empty(&tid->buf_q); |
5519541d FF |
1336 | |
1337 | tid->sched = false; | |
1338 | list_del(&tid->list); | |
1339 | ||
1340 | if (ac->sched) { | |
1341 | ac->sched = false; | |
1342 | list_del(&ac->list); | |
1343 | } | |
1344 | ||
23de5dc9 | 1345 | ath_txq_unlock(sc, txq); |
5519541d | 1346 | |
042ec453 JB |
1347 | ieee80211_sta_set_buffered(sta, tidno, buffered); |
1348 | } | |
5519541d FF |
1349 | } |
1350 | ||
1351 | void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an) | |
1352 | { | |
1353 | struct ath_atx_tid *tid; | |
1354 | struct ath_atx_ac *ac; | |
1355 | struct ath_txq *txq; | |
1356 | int tidno; | |
1357 | ||
1358 | for (tidno = 0, tid = &an->tid[tidno]; | |
de7b7604 | 1359 | tidno < IEEE80211_NUM_TIDS; tidno++, tid++) { |
5519541d FF |
1360 | |
1361 | ac = tid->ac; | |
1362 | txq = ac->txq; | |
1363 | ||
23de5dc9 | 1364 | ath_txq_lock(sc, txq); |
5519541d FF |
1365 | ac->clear_ps_filter = true; |
1366 | ||
56dc6336 | 1367 | if (!skb_queue_empty(&tid->buf_q) && !tid->paused) { |
5519541d FF |
1368 | ath_tx_queue_tid(txq, tid); |
1369 | ath_txq_schedule(sc, txq); | |
1370 | } | |
1371 | ||
23de5dc9 | 1372 | ath_txq_unlock_complete(sc, txq); |
5519541d FF |
1373 | } |
1374 | } | |
1375 | ||
e8324357 S |
1376 | void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid) |
1377 | { | |
1378 | struct ath_atx_tid *txtid; | |
1379 | struct ath_node *an; | |
1380 | ||
1381 | an = (struct ath_node *)sta->drv_priv; | |
1382 | ||
3d4e20f2 SM |
1383 | txtid = ATH_AN_2_TID(an, tid); |
1384 | txtid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor; | |
1385 | txtid->state |= AGGR_ADDBA_COMPLETE; | |
1386 | txtid->state &= ~AGGR_ADDBA_PROGRESS; | |
1387 | ath_tx_resume_tid(sc, txtid); | |
f078f209 LR |
1388 | } |
1389 | ||
e8324357 S |
1390 | /********************/ |
1391 | /* Queue Management */ | |
1392 | /********************/ | |
f078f209 | 1393 | |
e8324357 | 1394 | struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype) |
f078f209 | 1395 | { |
cbe61d8a | 1396 | struct ath_hw *ah = sc->sc_ah; |
e8324357 | 1397 | struct ath9k_tx_queue_info qi; |
066dae93 | 1398 | static const int subtype_txq_to_hwq[] = { |
bea843c7 SM |
1399 | [IEEE80211_AC_BE] = ATH_TXQ_AC_BE, |
1400 | [IEEE80211_AC_BK] = ATH_TXQ_AC_BK, | |
1401 | [IEEE80211_AC_VI] = ATH_TXQ_AC_VI, | |
1402 | [IEEE80211_AC_VO] = ATH_TXQ_AC_VO, | |
066dae93 | 1403 | }; |
60f2d1d5 | 1404 | int axq_qnum, i; |
f078f209 | 1405 | |
e8324357 | 1406 | memset(&qi, 0, sizeof(qi)); |
066dae93 | 1407 | qi.tqi_subtype = subtype_txq_to_hwq[subtype]; |
e8324357 S |
1408 | qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT; |
1409 | qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT; | |
1410 | qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT; | |
1411 | qi.tqi_physCompBuf = 0; | |
f078f209 LR |
1412 | |
1413 | /* | |
e8324357 S |
1414 | * Enable interrupts only for EOL and DESC conditions. |
1415 | * We mark tx descriptors to receive a DESC interrupt | |
1416 | * when a tx queue gets deep; otherwise waiting for the | |
1417 | * EOL to reap descriptors. Note that this is done to | |
1418 | * reduce interrupt load and this only defers reaping | |
1419 | * descriptors, never transmitting frames. Aside from | |
1420 | * reducing interrupts this also permits more concurrency. | |
1421 | * The only potential downside is if the tx queue backs | |
1422 | * up in which case the top half of the kernel may backup | |
1423 | * due to a lack of tx descriptors. | |
1424 | * | |
1425 | * The UAPSD queue is an exception, since we take a desc- | |
1426 | * based intr on the EOSP frames. | |
f078f209 | 1427 | */ |
afe754d6 | 1428 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
ce8fdf6e | 1429 | qi.tqi_qflags = TXQ_FLAG_TXINT_ENABLE; |
afe754d6 VT |
1430 | } else { |
1431 | if (qtype == ATH9K_TX_QUEUE_UAPSD) | |
1432 | qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE; | |
1433 | else | |
1434 | qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE | | |
1435 | TXQ_FLAG_TXDESCINT_ENABLE; | |
1436 | } | |
60f2d1d5 BG |
1437 | axq_qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi); |
1438 | if (axq_qnum == -1) { | |
f078f209 | 1439 | /* |
e8324357 S |
1440 | * NB: don't print a message, this happens |
1441 | * normally on parts with too few tx queues | |
f078f209 | 1442 | */ |
e8324357 | 1443 | return NULL; |
f078f209 | 1444 | } |
60f2d1d5 BG |
1445 | if (!ATH_TXQ_SETUP(sc, axq_qnum)) { |
1446 | struct ath_txq *txq = &sc->tx.txq[axq_qnum]; | |
f078f209 | 1447 | |
60f2d1d5 BG |
1448 | txq->axq_qnum = axq_qnum; |
1449 | txq->mac80211_qnum = -1; | |
e8324357 | 1450 | txq->axq_link = NULL; |
23de5dc9 | 1451 | __skb_queue_head_init(&txq->complete_q); |
e8324357 S |
1452 | INIT_LIST_HEAD(&txq->axq_q); |
1453 | INIT_LIST_HEAD(&txq->axq_acq); | |
1454 | spin_lock_init(&txq->axq_lock); | |
1455 | txq->axq_depth = 0; | |
4b3ba66a | 1456 | txq->axq_ampdu_depth = 0; |
164ace38 | 1457 | txq->axq_tx_inprogress = false; |
60f2d1d5 | 1458 | sc->tx.txqsetup |= 1<<axq_qnum; |
e5003249 VT |
1459 | |
1460 | txq->txq_headidx = txq->txq_tailidx = 0; | |
1461 | for (i = 0; i < ATH_TXFIFO_DEPTH; i++) | |
1462 | INIT_LIST_HEAD(&txq->txq_fifo[i]); | |
e8324357 | 1463 | } |
60f2d1d5 | 1464 | return &sc->tx.txq[axq_qnum]; |
f078f209 LR |
1465 | } |
1466 | ||
e8324357 S |
1467 | int ath_txq_update(struct ath_softc *sc, int qnum, |
1468 | struct ath9k_tx_queue_info *qinfo) | |
1469 | { | |
cbe61d8a | 1470 | struct ath_hw *ah = sc->sc_ah; |
e8324357 S |
1471 | int error = 0; |
1472 | struct ath9k_tx_queue_info qi; | |
1473 | ||
9680e8a3 | 1474 | BUG_ON(sc->tx.txq[qnum].axq_qnum != qnum); |
e8324357 S |
1475 | |
1476 | ath9k_hw_get_txq_props(ah, qnum, &qi); | |
1477 | qi.tqi_aifs = qinfo->tqi_aifs; | |
1478 | qi.tqi_cwmin = qinfo->tqi_cwmin; | |
1479 | qi.tqi_cwmax = qinfo->tqi_cwmax; | |
1480 | qi.tqi_burstTime = qinfo->tqi_burstTime; | |
1481 | qi.tqi_readyTime = qinfo->tqi_readyTime; | |
1482 | ||
1483 | if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) { | |
3800276a JP |
1484 | ath_err(ath9k_hw_common(sc->sc_ah), |
1485 | "Unable to update hardware queue %u!\n", qnum); | |
e8324357 S |
1486 | error = -EIO; |
1487 | } else { | |
1488 | ath9k_hw_resettxqueue(ah, qnum); | |
1489 | } | |
1490 | ||
1491 | return error; | |
1492 | } | |
1493 | ||
1494 | int ath_cabq_update(struct ath_softc *sc) | |
1495 | { | |
1496 | struct ath9k_tx_queue_info qi; | |
9814f6b3 | 1497 | struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf; |
e8324357 | 1498 | int qnum = sc->beacon.cabq->axq_qnum; |
f078f209 | 1499 | |
e8324357 | 1500 | ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi); |
f078f209 | 1501 | /* |
e8324357 | 1502 | * Ensure the readytime % is within the bounds. |
f078f209 | 1503 | */ |
17d7904d S |
1504 | if (sc->config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND) |
1505 | sc->config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND; | |
1506 | else if (sc->config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND) | |
1507 | sc->config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND; | |
f078f209 | 1508 | |
9814f6b3 | 1509 | qi.tqi_readyTime = (cur_conf->beacon_interval * |
fdbf7335 | 1510 | sc->config.cabqReadytime) / 100; |
e8324357 S |
1511 | ath_txq_update(sc, qnum, &qi); |
1512 | ||
1513 | return 0; | |
f078f209 LR |
1514 | } |
1515 | ||
fce041be | 1516 | static void ath_drain_txq_list(struct ath_softc *sc, struct ath_txq *txq, |
1381559b | 1517 | struct list_head *list) |
f078f209 | 1518 | { |
e8324357 S |
1519 | struct ath_buf *bf, *lastbf; |
1520 | struct list_head bf_head; | |
db1a052b FF |
1521 | struct ath_tx_status ts; |
1522 | ||
1523 | memset(&ts, 0, sizeof(ts)); | |
daa5c408 | 1524 | ts.ts_status = ATH9K_TX_FLUSH; |
e8324357 | 1525 | INIT_LIST_HEAD(&bf_head); |
f078f209 | 1526 | |
fce041be FF |
1527 | while (!list_empty(list)) { |
1528 | bf = list_first_entry(list, struct ath_buf, list); | |
f078f209 | 1529 | |
fce041be FF |
1530 | if (bf->bf_stale) { |
1531 | list_del(&bf->list); | |
f078f209 | 1532 | |
fce041be FF |
1533 | ath_tx_return_buffer(sc, bf); |
1534 | continue; | |
e8324357 | 1535 | } |
f078f209 | 1536 | |
e8324357 | 1537 | lastbf = bf->bf_lastbf; |
fce041be | 1538 | list_cut_position(&bf_head, list, &lastbf->list); |
81b51950 | 1539 | ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head); |
f078f209 | 1540 | } |
fce041be | 1541 | } |
f078f209 | 1542 | |
fce041be FF |
1543 | /* |
1544 | * Drain a given TX queue (could be Beacon or Data) | |
1545 | * | |
1546 | * This assumes output has been stopped and | |
1547 | * we do not need to block ath_tx_tasklet. | |
1548 | */ | |
1381559b | 1549 | void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq) |
fce041be | 1550 | { |
23de5dc9 FF |
1551 | ath_txq_lock(sc, txq); |
1552 | ||
e5003249 | 1553 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
fce041be | 1554 | int idx = txq->txq_tailidx; |
e5003249 | 1555 | |
fce041be | 1556 | while (!list_empty(&txq->txq_fifo[idx])) { |
1381559b | 1557 | ath_drain_txq_list(sc, txq, &txq->txq_fifo[idx]); |
fce041be FF |
1558 | |
1559 | INCR(idx, ATH_TXFIFO_DEPTH); | |
e5003249 | 1560 | } |
fce041be | 1561 | txq->txq_tailidx = idx; |
e5003249 | 1562 | } |
e609e2ea | 1563 | |
fce041be FF |
1564 | txq->axq_link = NULL; |
1565 | txq->axq_tx_inprogress = false; | |
1381559b | 1566 | ath_drain_txq_list(sc, txq, &txq->axq_q); |
fce041be | 1567 | |
23de5dc9 | 1568 | ath_txq_unlock_complete(sc, txq); |
f078f209 LR |
1569 | } |
1570 | ||
1381559b | 1571 | bool ath_drain_all_txq(struct ath_softc *sc) |
f078f209 | 1572 | { |
cbe61d8a | 1573 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 1574 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
043a0405 | 1575 | struct ath_txq *txq; |
34d25810 FF |
1576 | int i; |
1577 | u32 npend = 0; | |
043a0405 | 1578 | |
781b14a3 | 1579 | if (test_bit(SC_OP_INVALID, &sc->sc_flags)) |
080e1a25 | 1580 | return true; |
043a0405 | 1581 | |
0d51cccc | 1582 | ath9k_hw_abort_tx_dma(ah); |
043a0405 | 1583 | |
0d51cccc | 1584 | /* Check if any queue remains active */ |
043a0405 | 1585 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
0d51cccc FF |
1586 | if (!ATH_TXQ_SETUP(sc, i)) |
1587 | continue; | |
1588 | ||
34d25810 FF |
1589 | if (ath9k_hw_numtxpending(ah, sc->tx.txq[i].axq_qnum)) |
1590 | npend |= BIT(i); | |
043a0405 S |
1591 | } |
1592 | ||
080e1a25 | 1593 | if (npend) |
34d25810 | 1594 | ath_err(common, "Failed to stop TX DMA, queues=0x%03x!\n", npend); |
043a0405 S |
1595 | |
1596 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { | |
92460412 FF |
1597 | if (!ATH_TXQ_SETUP(sc, i)) |
1598 | continue; | |
1599 | ||
1600 | /* | |
1601 | * The caller will resume queues with ieee80211_wake_queues. | |
1602 | * Mark the queue as not stopped to prevent ath_tx_complete | |
1603 | * from waking the queue too early. | |
1604 | */ | |
1605 | txq = &sc->tx.txq[i]; | |
1606 | txq->stopped = false; | |
1381559b | 1607 | ath_draintxq(sc, txq); |
043a0405 | 1608 | } |
080e1a25 FF |
1609 | |
1610 | return !npend; | |
e8324357 | 1611 | } |
f078f209 | 1612 | |
043a0405 | 1613 | void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq) |
e8324357 | 1614 | { |
043a0405 S |
1615 | ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum); |
1616 | sc->tx.txqsetup &= ~(1<<txq->axq_qnum); | |
e8324357 | 1617 | } |
f078f209 | 1618 | |
7755bad9 BG |
1619 | /* For each axq_acq entry, for each tid, try to schedule packets |
1620 | * for transmit until ampdu_depth has reached min Q depth. | |
1621 | */ | |
e8324357 S |
1622 | void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq) |
1623 | { | |
7755bad9 BG |
1624 | struct ath_atx_ac *ac, *ac_tmp, *last_ac; |
1625 | struct ath_atx_tid *tid, *last_tid; | |
f078f209 | 1626 | |
124b979b RM |
1627 | if (test_bit(SC_OP_HW_RESET, &sc->sc_flags) || |
1628 | list_empty(&txq->axq_acq) || | |
21f28e6f | 1629 | txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) |
e8324357 | 1630 | return; |
f078f209 | 1631 | |
e8324357 | 1632 | ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list); |
7755bad9 | 1633 | last_ac = list_entry(txq->axq_acq.prev, struct ath_atx_ac, list); |
f078f209 | 1634 | |
7755bad9 BG |
1635 | list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) { |
1636 | last_tid = list_entry(ac->tid_q.prev, struct ath_atx_tid, list); | |
1637 | list_del(&ac->list); | |
1638 | ac->sched = false; | |
f078f209 | 1639 | |
7755bad9 BG |
1640 | while (!list_empty(&ac->tid_q)) { |
1641 | tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, | |
1642 | list); | |
1643 | list_del(&tid->list); | |
1644 | tid->sched = false; | |
f078f209 | 1645 | |
7755bad9 BG |
1646 | if (tid->paused) |
1647 | continue; | |
f078f209 | 1648 | |
7755bad9 | 1649 | ath_tx_sched_aggr(sc, txq, tid); |
f078f209 | 1650 | |
7755bad9 BG |
1651 | /* |
1652 | * add tid to round-robin queue if more frames | |
1653 | * are pending for the tid | |
1654 | */ | |
56dc6336 | 1655 | if (!skb_queue_empty(&tid->buf_q)) |
7755bad9 | 1656 | ath_tx_queue_tid(txq, tid); |
f078f209 | 1657 | |
7755bad9 BG |
1658 | if (tid == last_tid || |
1659 | txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) | |
1660 | break; | |
1661 | } | |
f078f209 | 1662 | |
b0477013 FF |
1663 | if (!list_empty(&ac->tid_q) && !ac->sched) { |
1664 | ac->sched = true; | |
1665 | list_add_tail(&ac->list, &txq->axq_acq); | |
f078f209 | 1666 | } |
7755bad9 BG |
1667 | |
1668 | if (ac == last_ac || | |
1669 | txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) | |
1670 | return; | |
e8324357 S |
1671 | } |
1672 | } | |
f078f209 | 1673 | |
e8324357 S |
1674 | /***********/ |
1675 | /* TX, DMA */ | |
1676 | /***********/ | |
1677 | ||
f078f209 | 1678 | /* |
e8324357 S |
1679 | * Insert a chain of ath_buf (descriptors) on a txq and |
1680 | * assume the descriptors are already chained together by caller. | |
f078f209 | 1681 | */ |
e8324357 | 1682 | static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq, |
fce041be | 1683 | struct list_head *head, bool internal) |
f078f209 | 1684 | { |
cbe61d8a | 1685 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 1686 | struct ath_common *common = ath9k_hw_common(ah); |
fce041be FF |
1687 | struct ath_buf *bf, *bf_last; |
1688 | bool puttxbuf = false; | |
1689 | bool edma; | |
f078f209 | 1690 | |
e8324357 S |
1691 | /* |
1692 | * Insert the frame on the outbound list and | |
1693 | * pass it on to the hardware. | |
1694 | */ | |
f078f209 | 1695 | |
e8324357 S |
1696 | if (list_empty(head)) |
1697 | return; | |
f078f209 | 1698 | |
fce041be | 1699 | edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
e8324357 | 1700 | bf = list_first_entry(head, struct ath_buf, list); |
fce041be | 1701 | bf_last = list_entry(head->prev, struct ath_buf, list); |
f078f209 | 1702 | |
d2182b69 JP |
1703 | ath_dbg(common, QUEUE, "qnum: %d, txq depth: %d\n", |
1704 | txq->axq_qnum, txq->axq_depth); | |
f078f209 | 1705 | |
fce041be FF |
1706 | if (edma && list_empty(&txq->txq_fifo[txq->txq_headidx])) { |
1707 | list_splice_tail_init(head, &txq->txq_fifo[txq->txq_headidx]); | |
e5003249 | 1708 | INCR(txq->txq_headidx, ATH_TXFIFO_DEPTH); |
fce041be | 1709 | puttxbuf = true; |
e8324357 | 1710 | } else { |
e5003249 VT |
1711 | list_splice_tail_init(head, &txq->axq_q); |
1712 | ||
fce041be FF |
1713 | if (txq->axq_link) { |
1714 | ath9k_hw_set_desc_link(ah, txq->axq_link, bf->bf_daddr); | |
d2182b69 | 1715 | ath_dbg(common, XMIT, "link[%u] (%p)=%llx (%p)\n", |
226afe68 JP |
1716 | txq->axq_qnum, txq->axq_link, |
1717 | ito64(bf->bf_daddr), bf->bf_desc); | |
fce041be FF |
1718 | } else if (!edma) |
1719 | puttxbuf = true; | |
1720 | ||
1721 | txq->axq_link = bf_last->bf_desc; | |
1722 | } | |
1723 | ||
1724 | if (puttxbuf) { | |
1725 | TX_STAT_INC(txq->axq_qnum, puttxbuf); | |
1726 | ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); | |
d2182b69 | 1727 | ath_dbg(common, XMIT, "TXDP[%u] = %llx (%p)\n", |
fce041be FF |
1728 | txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc); |
1729 | } | |
1730 | ||
1731 | if (!edma) { | |
8d8d3fdc | 1732 | TX_STAT_INC(txq->axq_qnum, txstart); |
e5003249 | 1733 | ath9k_hw_txstart(ah, txq->axq_qnum); |
e8324357 | 1734 | } |
fce041be FF |
1735 | |
1736 | if (!internal) { | |
1737 | txq->axq_depth++; | |
1738 | if (bf_is_ampdu_not_probing(bf)) | |
1739 | txq->axq_ampdu_depth++; | |
1740 | } | |
e8324357 | 1741 | } |
f078f209 | 1742 | |
e8324357 | 1743 | static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid, |
44f1d26c | 1744 | struct sk_buff *skb, struct ath_tx_control *txctl) |
f078f209 | 1745 | { |
44f1d26c | 1746 | struct ath_frame_info *fi = get_frame_info(skb); |
04caf863 | 1747 | struct list_head bf_head; |
44f1d26c | 1748 | struct ath_buf *bf; |
f078f209 | 1749 | |
e8324357 S |
1750 | /* |
1751 | * Do not queue to h/w when any of the following conditions is true: | |
1752 | * - there are pending frames in software queue | |
1753 | * - the TID is currently paused for ADDBA/BAR request | |
1754 | * - seqno is not within block-ack window | |
1755 | * - h/w queue depth exceeds low water mark | |
1756 | */ | |
56dc6336 | 1757 | if (!skb_queue_empty(&tid->buf_q) || tid->paused || |
44f1d26c | 1758 | !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) || |
4b3ba66a | 1759 | txctl->txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) { |
f078f209 | 1760 | /* |
e8324357 S |
1761 | * Add this frame to software queue for scheduling later |
1762 | * for aggregation. | |
f078f209 | 1763 | */ |
bda8adda | 1764 | TX_STAT_INC(txctl->txq->axq_qnum, a_queued_sw); |
44f1d26c | 1765 | __skb_queue_tail(&tid->buf_q, skb); |
9af73cf7 FF |
1766 | if (!txctl->an || !txctl->an->sleeping) |
1767 | ath_tx_queue_tid(txctl->txq, tid); | |
e8324357 S |
1768 | return; |
1769 | } | |
1770 | ||
249ee722 FF |
1771 | bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb); |
1772 | if (!bf) { | |
1773 | ieee80211_free_txskb(sc->hw, skb); | |
44f1d26c | 1774 | return; |
249ee722 | 1775 | } |
44f1d26c | 1776 | |
79acac07 | 1777 | ath_set_rates(tid->an->vif, tid->an->sta, bf); |
399c6489 | 1778 | bf->bf_state.bf_type = BUF_AMPDU; |
04caf863 FF |
1779 | INIT_LIST_HEAD(&bf_head); |
1780 | list_add(&bf->list, &bf_head); | |
1781 | ||
e8324357 | 1782 | /* Add sub-frame to BAW */ |
44f1d26c | 1783 | ath_tx_addto_baw(sc, tid, bf->bf_state.seqno); |
e8324357 S |
1784 | |
1785 | /* Queue to h/w without aggregation */ | |
bda8adda | 1786 | TX_STAT_INC(txctl->txq->axq_qnum, a_queued_hw); |
d43f3015 | 1787 | bf->bf_lastbf = bf; |
493cf04f | 1788 | ath_tx_fill_desc(sc, bf, txctl->txq, fi->framelen); |
fce041be | 1789 | ath_tx_txqaddbuf(sc, txctl->txq, &bf_head, false); |
e8324357 S |
1790 | } |
1791 | ||
82b873af | 1792 | static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq, |
44f1d26c | 1793 | struct ath_atx_tid *tid, struct sk_buff *skb) |
e8324357 | 1794 | { |
44f1d26c FF |
1795 | struct ath_frame_info *fi = get_frame_info(skb); |
1796 | struct list_head bf_head; | |
e8324357 S |
1797 | struct ath_buf *bf; |
1798 | ||
44f1d26c | 1799 | bf = fi->bf; |
44f1d26c FF |
1800 | |
1801 | INIT_LIST_HEAD(&bf_head); | |
1802 | list_add_tail(&bf->list, &bf_head); | |
399c6489 | 1803 | bf->bf_state.bf_type = 0; |
e8324357 | 1804 | |
8c6e3093 | 1805 | bf->bf_next = NULL; |
d43f3015 | 1806 | bf->bf_lastbf = bf; |
493cf04f | 1807 | ath_tx_fill_desc(sc, bf, txq, fi->framelen); |
44f1d26c | 1808 | ath_tx_txqaddbuf(sc, txq, &bf_head, false); |
fec247c0 | 1809 | TX_STAT_INC(txq->axq_qnum, queued); |
e8324357 S |
1810 | } |
1811 | ||
36323f81 TH |
1812 | static void setup_frame_info(struct ieee80211_hw *hw, |
1813 | struct ieee80211_sta *sta, | |
1814 | struct sk_buff *skb, | |
2d42efc4 | 1815 | int framelen) |
e8324357 S |
1816 | { |
1817 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); | |
2d42efc4 | 1818 | struct ieee80211_key_conf *hw_key = tx_info->control.hw_key; |
6a0ddaef | 1819 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
80b08a8d | 1820 | const struct ieee80211_rate *rate; |
2d42efc4 | 1821 | struct ath_frame_info *fi = get_frame_info(skb); |
93ae2dd2 | 1822 | struct ath_node *an = NULL; |
2d42efc4 | 1823 | enum ath9k_key_type keytype; |
80b08a8d FF |
1824 | bool short_preamble = false; |
1825 | ||
1826 | /* | |
1827 | * We check if Short Preamble is needed for the CTS rate by | |
1828 | * checking the BSS's global flag. | |
1829 | * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used. | |
1830 | */ | |
1831 | if (tx_info->control.vif && | |
1832 | tx_info->control.vif->bss_conf.use_short_preamble) | |
1833 | short_preamble = true; | |
e8324357 | 1834 | |
80b08a8d | 1835 | rate = ieee80211_get_rts_cts_rate(hw, tx_info); |
2d42efc4 | 1836 | keytype = ath9k_cmn_get_hw_crypto_keytype(skb); |
e8324357 | 1837 | |
93ae2dd2 FF |
1838 | if (sta) |
1839 | an = (struct ath_node *) sta->drv_priv; | |
1840 | ||
2d42efc4 FF |
1841 | memset(fi, 0, sizeof(*fi)); |
1842 | if (hw_key) | |
1843 | fi->keyix = hw_key->hw_key_idx; | |
93ae2dd2 FF |
1844 | else if (an && ieee80211_is_data(hdr->frame_control) && an->ps_key > 0) |
1845 | fi->keyix = an->ps_key; | |
2d42efc4 FF |
1846 | else |
1847 | fi->keyix = ATH9K_TXKEYIX_INVALID; | |
1848 | fi->keytype = keytype; | |
1849 | fi->framelen = framelen; | |
80b08a8d FF |
1850 | fi->rtscts_rate = rate->hw_value; |
1851 | if (short_preamble) | |
1852 | fi->rtscts_rate |= rate->hw_value_short; | |
e8324357 S |
1853 | } |
1854 | ||
ea066d5a MSS |
1855 | u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate) |
1856 | { | |
1857 | struct ath_hw *ah = sc->sc_ah; | |
1858 | struct ath9k_channel *curchan = ah->curchan; | |
365d2ebc | 1859 | |
d77bf3eb RM |
1860 | if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && |
1861 | (curchan->channelFlags & CHANNEL_5GHZ) && | |
1862 | (chainmask == 0x7) && (rate < 0x90)) | |
ea066d5a | 1863 | return 0x3; |
365d2ebc SM |
1864 | else if (AR_SREV_9462(ah) && ath9k_hw_btcoex_is_enabled(ah) && |
1865 | IS_CCK_RATE(rate)) | |
1866 | return 0x2; | |
ea066d5a MSS |
1867 | else |
1868 | return chainmask; | |
1869 | } | |
1870 | ||
44f1d26c FF |
1871 | /* |
1872 | * Assign a descriptor (and sequence number if necessary, | |
1873 | * and map buffer for DMA. Frees skb on error | |
1874 | */ | |
fa05f87a | 1875 | static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc, |
04caf863 | 1876 | struct ath_txq *txq, |
fa05f87a | 1877 | struct ath_atx_tid *tid, |
249ee722 | 1878 | struct sk_buff *skb) |
f078f209 | 1879 | { |
82b873af | 1880 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
2d42efc4 | 1881 | struct ath_frame_info *fi = get_frame_info(skb); |
fa05f87a | 1882 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
82b873af | 1883 | struct ath_buf *bf; |
fd09c85f | 1884 | int fragno; |
fa05f87a | 1885 | u16 seqno; |
82b873af FF |
1886 | |
1887 | bf = ath_tx_get_buffer(sc); | |
1888 | if (!bf) { | |
d2182b69 | 1889 | ath_dbg(common, XMIT, "TX buffers are full\n"); |
249ee722 | 1890 | return NULL; |
82b873af | 1891 | } |
e022edbd | 1892 | |
528f0c6b | 1893 | ATH_TXBUF_RESET(bf); |
f078f209 | 1894 | |
fa05f87a | 1895 | if (tid) { |
fd09c85f | 1896 | fragno = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG; |
fa05f87a FF |
1897 | seqno = tid->seq_next; |
1898 | hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT); | |
fd09c85f SM |
1899 | |
1900 | if (fragno) | |
1901 | hdr->seq_ctrl |= cpu_to_le16(fragno); | |
1902 | ||
1903 | if (!ieee80211_has_morefrags(hdr->frame_control)) | |
1904 | INCR(tid->seq_next, IEEE80211_SEQ_MAX); | |
1905 | ||
fa05f87a FF |
1906 | bf->bf_state.seqno = seqno; |
1907 | } | |
1908 | ||
f078f209 | 1909 | bf->bf_mpdu = skb; |
f8316df1 | 1910 | |
c1739eb3 BG |
1911 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
1912 | skb->len, DMA_TO_DEVICE); | |
1913 | if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) { | |
f8316df1 | 1914 | bf->bf_mpdu = NULL; |
6cf9e995 | 1915 | bf->bf_buf_addr = 0; |
3800276a JP |
1916 | ath_err(ath9k_hw_common(sc->sc_ah), |
1917 | "dma_mapping_error() on TX\n"); | |
82b873af | 1918 | ath_tx_return_buffer(sc, bf); |
249ee722 | 1919 | return NULL; |
f8316df1 LR |
1920 | } |
1921 | ||
56dc6336 | 1922 | fi->bf = bf; |
04caf863 FF |
1923 | |
1924 | return bf; | |
1925 | } | |
1926 | ||
f8316df1 | 1927 | /* Upon failure caller should free skb */ |
c52f33d0 | 1928 | int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb, |
528f0c6b | 1929 | struct ath_tx_control *txctl) |
f078f209 | 1930 | { |
28d16708 FF |
1931 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
1932 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
36323f81 | 1933 | struct ieee80211_sta *sta = txctl->sta; |
f59a59fe | 1934 | struct ieee80211_vif *vif = info->control.vif; |
9ac58615 | 1935 | struct ath_softc *sc = hw->priv; |
84642d6b | 1936 | struct ath_txq *txq = txctl->txq; |
bdc21457 FF |
1937 | struct ath_atx_tid *tid = NULL; |
1938 | struct ath_buf *bf; | |
4d91f9f3 | 1939 | int padpos, padsize; |
04caf863 | 1940 | int frmlen = skb->len + FCS_LEN; |
bdc21457 | 1941 | u8 tidno; |
28d16708 | 1942 | int q; |
f078f209 | 1943 | |
a9927ba3 BG |
1944 | /* NOTE: sta can be NULL according to net/mac80211.h */ |
1945 | if (sta) | |
1946 | txctl->an = (struct ath_node *)sta->drv_priv; | |
1947 | ||
04caf863 FF |
1948 | if (info->control.hw_key) |
1949 | frmlen += info->control.hw_key->icv_len; | |
1950 | ||
f078f209 | 1951 | /* |
e8324357 S |
1952 | * As a temporary workaround, assign seq# here; this will likely need |
1953 | * to be cleaned up to work better with Beacon transmission and virtual | |
1954 | * BSSes. | |
f078f209 | 1955 | */ |
e8324357 | 1956 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
e8324357 S |
1957 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
1958 | sc->tx.seq_no += 0x10; | |
1959 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); | |
1960 | hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no); | |
f078f209 | 1961 | } |
f078f209 | 1962 | |
42cecc34 | 1963 | /* Add the padding after the header if this is not already done */ |
c60c9929 | 1964 | padpos = ieee80211_hdrlen(hdr->frame_control); |
42cecc34 JL |
1965 | padsize = padpos & 3; |
1966 | if (padsize && skb->len > padpos) { | |
1967 | if (skb_headroom(skb) < padsize) | |
1968 | return -ENOMEM; | |
28d16708 | 1969 | |
42cecc34 JL |
1970 | skb_push(skb, padsize); |
1971 | memmove(skb->data, skb->data + padsize, padpos); | |
6e82bc4a | 1972 | hdr = (struct ieee80211_hdr *) skb->data; |
f078f209 | 1973 | } |
f078f209 | 1974 | |
f59a59fe FF |
1975 | if ((vif && vif->type != NL80211_IFTYPE_AP && |
1976 | vif->type != NL80211_IFTYPE_AP_VLAN) || | |
1977 | !ieee80211_is_data(hdr->frame_control)) | |
1978 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; | |
1979 | ||
36323f81 | 1980 | setup_frame_info(hw, sta, skb, frmlen); |
2d42efc4 FF |
1981 | |
1982 | /* | |
1983 | * At this point, the vif, hw_key and sta pointers in the tx control | |
1984 | * info are no longer valid (overwritten by the ath_frame_info data. | |
1985 | */ | |
1986 | ||
28d16708 | 1987 | q = skb_get_queue_mapping(skb); |
23de5dc9 FF |
1988 | |
1989 | ath_txq_lock(sc, txq); | |
28d16708 | 1990 | if (txq == sc->tx.txq_map[q] && |
7702e788 FF |
1991 | ++txq->pending_frames > sc->tx.txq_max_pending[q] && |
1992 | !txq->stopped) { | |
7545daf4 | 1993 | ieee80211_stop_queue(sc->hw, q); |
3db1cd5c | 1994 | txq->stopped = true; |
f078f209 | 1995 | } |
f078f209 | 1996 | |
bdc21457 FF |
1997 | if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) { |
1998 | tidno = ieee80211_get_qos_ctl(hdr)[0] & | |
1999 | IEEE80211_QOS_CTL_TID_MASK; | |
2000 | tid = ATH_AN_2_TID(txctl->an, tidno); | |
2001 | ||
2002 | WARN_ON(tid->ac->txq != txctl->txq); | |
2003 | } | |
2004 | ||
2005 | if ((info->flags & IEEE80211_TX_CTL_AMPDU) && tid) { | |
2006 | /* | |
2007 | * Try aggregation if it's a unicast data frame | |
2008 | * and the destination is HT capable. | |
2009 | */ | |
2010 | ath_tx_send_ampdu(sc, tid, skb, txctl); | |
2011 | goto out; | |
2012 | } | |
2013 | ||
2014 | bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb); | |
2015 | if (!bf) { | |
2016 | if (txctl->paprd) | |
2017 | dev_kfree_skb_any(skb); | |
2018 | else | |
2019 | ieee80211_free_txskb(sc->hw, skb); | |
2020 | goto out; | |
2021 | } | |
2022 | ||
2023 | bf->bf_state.bfs_paprd = txctl->paprd; | |
2024 | ||
2025 | if (txctl->paprd) | |
2026 | bf->bf_state.bfs_paprd_timestamp = jiffies; | |
2027 | ||
79acac07 | 2028 | ath_set_rates(vif, sta, bf); |
bdc21457 | 2029 | ath_tx_send_normal(sc, txctl->txq, tid, skb); |
3ad29529 | 2030 | |
bdc21457 | 2031 | out: |
23de5dc9 | 2032 | ath_txq_unlock(sc, txq); |
3ad29529 | 2033 | |
44f1d26c | 2034 | return 0; |
f078f209 LR |
2035 | } |
2036 | ||
e8324357 S |
2037 | /*****************/ |
2038 | /* TX Completion */ | |
2039 | /*****************/ | |
528f0c6b | 2040 | |
e8324357 | 2041 | static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb, |
0f9dc298 | 2042 | int tx_flags, struct ath_txq *txq) |
528f0c6b | 2043 | { |
e8324357 | 2044 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
c46917bb | 2045 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
4d91f9f3 | 2046 | struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data; |
97923b14 | 2047 | int q, padpos, padsize; |
07c15a3f | 2048 | unsigned long flags; |
528f0c6b | 2049 | |
d2182b69 | 2050 | ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb); |
528f0c6b | 2051 | |
51dea9be FF |
2052 | if (sc->sc_ah->caldata) |
2053 | sc->sc_ah->caldata->paprd_packet_sent = true; | |
2054 | ||
55797b1a | 2055 | if (!(tx_flags & ATH_TX_ERROR)) |
e8324357 S |
2056 | /* Frame was ACKed */ |
2057 | tx_info->flags |= IEEE80211_TX_STAT_ACK; | |
528f0c6b | 2058 | |
c60c9929 | 2059 | padpos = ieee80211_hdrlen(hdr->frame_control); |
42cecc34 JL |
2060 | padsize = padpos & 3; |
2061 | if (padsize && skb->len>padpos+padsize) { | |
2062 | /* | |
2063 | * Remove MAC header padding before giving the frame back to | |
2064 | * mac80211. | |
2065 | */ | |
2066 | memmove(skb->data + padsize, skb->data, padpos); | |
2067 | skb_pull(skb, padsize); | |
e8324357 | 2068 | } |
528f0c6b | 2069 | |
07c15a3f | 2070 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
c8e8868e | 2071 | if ((sc->ps_flags & PS_WAIT_FOR_TX_ACK) && !txq->axq_depth) { |
1b04b930 | 2072 | sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK; |
d2182b69 | 2073 | ath_dbg(common, PS, |
226afe68 | 2074 | "Going back to sleep after having received TX status (0x%lx)\n", |
1b04b930 S |
2075 | sc->ps_flags & (PS_WAIT_FOR_BEACON | |
2076 | PS_WAIT_FOR_CAB | | |
2077 | PS_WAIT_FOR_PSPOLL_DATA | | |
2078 | PS_WAIT_FOR_TX_ACK)); | |
9a23f9ca | 2079 | } |
07c15a3f | 2080 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
9a23f9ca | 2081 | |
7545daf4 FF |
2082 | q = skb_get_queue_mapping(skb); |
2083 | if (txq == sc->tx.txq_map[q]) { | |
7545daf4 FF |
2084 | if (WARN_ON(--txq->pending_frames < 0)) |
2085 | txq->pending_frames = 0; | |
92460412 | 2086 | |
7702e788 FF |
2087 | if (txq->stopped && |
2088 | txq->pending_frames < sc->tx.txq_max_pending[q]) { | |
7545daf4 | 2089 | ieee80211_wake_queue(sc->hw, q); |
3db1cd5c | 2090 | txq->stopped = false; |
066dae93 | 2091 | } |
97923b14 | 2092 | } |
7545daf4 | 2093 | |
23de5dc9 | 2094 | __skb_queue_tail(&txq->complete_q, skb); |
e8324357 | 2095 | } |
f078f209 | 2096 | |
e8324357 | 2097 | static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf, |
db1a052b | 2098 | struct ath_txq *txq, struct list_head *bf_q, |
156369fa | 2099 | struct ath_tx_status *ts, int txok) |
f078f209 | 2100 | { |
e8324357 | 2101 | struct sk_buff *skb = bf->bf_mpdu; |
3afd21e7 | 2102 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
e8324357 | 2103 | unsigned long flags; |
6b2c4032 | 2104 | int tx_flags = 0; |
f078f209 | 2105 | |
55797b1a | 2106 | if (!txok) |
6b2c4032 | 2107 | tx_flags |= ATH_TX_ERROR; |
f078f209 | 2108 | |
3afd21e7 FF |
2109 | if (ts->ts_status & ATH9K_TXERR_FILT) |
2110 | tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED; | |
2111 | ||
c1739eb3 | 2112 | dma_unmap_single(sc->dev, bf->bf_buf_addr, skb->len, DMA_TO_DEVICE); |
6cf9e995 | 2113 | bf->bf_buf_addr = 0; |
9f42c2b6 FF |
2114 | |
2115 | if (bf->bf_state.bfs_paprd) { | |
9cf04dcc MSS |
2116 | if (time_after(jiffies, |
2117 | bf->bf_state.bfs_paprd_timestamp + | |
2118 | msecs_to_jiffies(ATH_PAPRD_TIMEOUT))) | |
ca369eb4 | 2119 | dev_kfree_skb_any(skb); |
78a18172 | 2120 | else |
ca369eb4 | 2121 | complete(&sc->paprd_complete); |
9f42c2b6 | 2122 | } else { |
55797b1a | 2123 | ath_debug_stat_tx(sc, bf, ts, txq, tx_flags); |
0f9dc298 | 2124 | ath_tx_complete(sc, skb, tx_flags, txq); |
9f42c2b6 | 2125 | } |
6cf9e995 BG |
2126 | /* At this point, skb (bf->bf_mpdu) is consumed...make sure we don't |
2127 | * accidentally reference it later. | |
2128 | */ | |
2129 | bf->bf_mpdu = NULL; | |
e8324357 S |
2130 | |
2131 | /* | |
2132 | * Return the list of ath_buf of this mpdu to free queue | |
2133 | */ | |
2134 | spin_lock_irqsave(&sc->tx.txbuflock, flags); | |
2135 | list_splice_tail_init(bf_q, &sc->tx.txbuf); | |
2136 | spin_unlock_irqrestore(&sc->tx.txbuflock, flags); | |
f078f209 LR |
2137 | } |
2138 | ||
0cdd5c60 FF |
2139 | static void ath_tx_rc_status(struct ath_softc *sc, struct ath_buf *bf, |
2140 | struct ath_tx_status *ts, int nframes, int nbad, | |
3afd21e7 | 2141 | int txok) |
f078f209 | 2142 | { |
a22be22a | 2143 | struct sk_buff *skb = bf->bf_mpdu; |
254ad0ff | 2144 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
e8324357 | 2145 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
0cdd5c60 | 2146 | struct ieee80211_hw *hw = sc->hw; |
f0c255a0 | 2147 | struct ath_hw *ah = sc->sc_ah; |
8a92e2ee | 2148 | u8 i, tx_rateindex; |
f078f209 | 2149 | |
95e4acb7 | 2150 | if (txok) |
db1a052b | 2151 | tx_info->status.ack_signal = ts->ts_rssi; |
95e4acb7 | 2152 | |
db1a052b | 2153 | tx_rateindex = ts->ts_rateindex; |
8a92e2ee VT |
2154 | WARN_ON(tx_rateindex >= hw->max_rates); |
2155 | ||
3afd21e7 | 2156 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) { |
d969847c | 2157 | tx_info->flags |= IEEE80211_TX_STAT_AMPDU; |
f078f209 | 2158 | |
b572d033 | 2159 | BUG_ON(nbad > nframes); |
ebd02287 | 2160 | } |
185d1589 RM |
2161 | tx_info->status.ampdu_len = nframes; |
2162 | tx_info->status.ampdu_ack_len = nframes - nbad; | |
ebd02287 | 2163 | |
db1a052b | 2164 | if ((ts->ts_status & ATH9K_TXERR_FILT) == 0 && |
3afd21e7 | 2165 | (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) == 0) { |
f0c255a0 FF |
2166 | /* |
2167 | * If an underrun error is seen assume it as an excessive | |
2168 | * retry only if max frame trigger level has been reached | |
2169 | * (2 KB for single stream, and 4 KB for dual stream). | |
2170 | * Adjust the long retry as if the frame was tried | |
2171 | * hw->max_rate_tries times to affect how rate control updates | |
2172 | * PER for the failed rate. | |
2173 | * In case of congestion on the bus penalizing this type of | |
2174 | * underruns should help hardware actually transmit new frames | |
2175 | * successfully by eventually preferring slower rates. | |
2176 | * This itself should also alleviate congestion on the bus. | |
2177 | */ | |
3afd21e7 FF |
2178 | if (unlikely(ts->ts_flags & (ATH9K_TX_DATA_UNDERRUN | |
2179 | ATH9K_TX_DELIM_UNDERRUN)) && | |
2180 | ieee80211_is_data(hdr->frame_control) && | |
83860c59 | 2181 | ah->tx_trig_level >= sc->sc_ah->config.max_txtrig_level) |
f0c255a0 FF |
2182 | tx_info->status.rates[tx_rateindex].count = |
2183 | hw->max_rate_tries; | |
f078f209 | 2184 | } |
8a92e2ee | 2185 | |
545750d3 | 2186 | for (i = tx_rateindex + 1; i < hw->max_rates; i++) { |
8a92e2ee | 2187 | tx_info->status.rates[i].count = 0; |
545750d3 FF |
2188 | tx_info->status.rates[i].idx = -1; |
2189 | } | |
8a92e2ee | 2190 | |
78c4653a | 2191 | tx_info->status.rates[tx_rateindex].count = ts->ts_longretry + 1; |
f078f209 LR |
2192 | } |
2193 | ||
e8324357 | 2194 | static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq) |
f078f209 | 2195 | { |
cbe61d8a | 2196 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 2197 | struct ath_common *common = ath9k_hw_common(ah); |
e8324357 | 2198 | struct ath_buf *bf, *lastbf, *bf_held = NULL; |
f078f209 | 2199 | struct list_head bf_head; |
e8324357 | 2200 | struct ath_desc *ds; |
29bffa96 | 2201 | struct ath_tx_status ts; |
e8324357 | 2202 | int status; |
f078f209 | 2203 | |
d2182b69 | 2204 | ath_dbg(common, QUEUE, "tx queue %d (%x), link %p\n", |
226afe68 JP |
2205 | txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum), |
2206 | txq->axq_link); | |
f078f209 | 2207 | |
23de5dc9 | 2208 | ath_txq_lock(sc, txq); |
f078f209 | 2209 | for (;;) { |
124b979b | 2210 | if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) |
236de514 FF |
2211 | break; |
2212 | ||
f078f209 LR |
2213 | if (list_empty(&txq->axq_q)) { |
2214 | txq->axq_link = NULL; | |
3d4e20f2 | 2215 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) |
082f6536 | 2216 | ath_txq_schedule(sc, txq); |
f078f209 LR |
2217 | break; |
2218 | } | |
f078f209 LR |
2219 | bf = list_first_entry(&txq->axq_q, struct ath_buf, list); |
2220 | ||
e8324357 S |
2221 | /* |
2222 | * There is a race condition that a BH gets scheduled | |
2223 | * after sw writes TxE and before hw re-load the last | |
2224 | * descriptor to get the newly chained one. | |
2225 | * Software must keep the last DONE descriptor as a | |
2226 | * holding descriptor - software does so by marking | |
2227 | * it with the STALE flag. | |
2228 | */ | |
2229 | bf_held = NULL; | |
a119cc49 | 2230 | if (bf->bf_stale) { |
e8324357 | 2231 | bf_held = bf; |
fce041be | 2232 | if (list_is_last(&bf_held->list, &txq->axq_q)) |
e8324357 | 2233 | break; |
fce041be FF |
2234 | |
2235 | bf = list_entry(bf_held->list.next, struct ath_buf, | |
2236 | list); | |
f078f209 LR |
2237 | } |
2238 | ||
2239 | lastbf = bf->bf_lastbf; | |
e8324357 | 2240 | ds = lastbf->bf_desc; |
f078f209 | 2241 | |
29bffa96 FF |
2242 | memset(&ts, 0, sizeof(ts)); |
2243 | status = ath9k_hw_txprocdesc(ah, ds, &ts); | |
fce041be | 2244 | if (status == -EINPROGRESS) |
e8324357 | 2245 | break; |
fce041be | 2246 | |
2dac4fb9 | 2247 | TX_STAT_INC(txq->axq_qnum, txprocdesc); |
f078f209 | 2248 | |
e8324357 S |
2249 | /* |
2250 | * Remove ath_buf's of the same transmit unit from txq, | |
2251 | * however leave the last descriptor back as the holding | |
2252 | * descriptor for hw. | |
2253 | */ | |
a119cc49 | 2254 | lastbf->bf_stale = true; |
e8324357 | 2255 | INIT_LIST_HEAD(&bf_head); |
e8324357 S |
2256 | if (!list_is_singular(&lastbf->list)) |
2257 | list_cut_position(&bf_head, | |
2258 | &txq->axq_q, lastbf->list.prev); | |
f078f209 | 2259 | |
fce041be | 2260 | if (bf_held) { |
0a8cea84 | 2261 | list_del(&bf_held->list); |
0a8cea84 | 2262 | ath_tx_return_buffer(sc, bf_held); |
e8324357 | 2263 | } |
f078f209 | 2264 | |
fce041be | 2265 | ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head); |
8469cdef | 2266 | } |
23de5dc9 | 2267 | ath_txq_unlock_complete(sc, txq); |
8469cdef S |
2268 | } |
2269 | ||
e8324357 | 2270 | void ath_tx_tasklet(struct ath_softc *sc) |
f078f209 | 2271 | { |
239c795d FF |
2272 | struct ath_hw *ah = sc->sc_ah; |
2273 | u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1) & ah->intr_txqs; | |
e8324357 | 2274 | int i; |
f078f209 | 2275 | |
e8324357 S |
2276 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
2277 | if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i))) | |
2278 | ath_tx_processq(sc, &sc->tx.txq[i]); | |
f078f209 LR |
2279 | } |
2280 | } | |
2281 | ||
e5003249 VT |
2282 | void ath_tx_edma_tasklet(struct ath_softc *sc) |
2283 | { | |
fce041be | 2284 | struct ath_tx_status ts; |
e5003249 VT |
2285 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
2286 | struct ath_hw *ah = sc->sc_ah; | |
2287 | struct ath_txq *txq; | |
2288 | struct ath_buf *bf, *lastbf; | |
2289 | struct list_head bf_head; | |
99ba6a46 | 2290 | struct list_head *fifo_list; |
e5003249 | 2291 | int status; |
e5003249 VT |
2292 | |
2293 | for (;;) { | |
124b979b | 2294 | if (test_bit(SC_OP_HW_RESET, &sc->sc_flags)) |
236de514 FF |
2295 | break; |
2296 | ||
fce041be | 2297 | status = ath9k_hw_txprocdesc(ah, NULL, (void *)&ts); |
e5003249 VT |
2298 | if (status == -EINPROGRESS) |
2299 | break; | |
2300 | if (status == -EIO) { | |
d2182b69 | 2301 | ath_dbg(common, XMIT, "Error processing tx status\n"); |
e5003249 VT |
2302 | break; |
2303 | } | |
2304 | ||
4e0ad259 FF |
2305 | /* Process beacon completions separately */ |
2306 | if (ts.qid == sc->beacon.beaconq) { | |
2307 | sc->beacon.tx_processed = true; | |
2308 | sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK); | |
e5003249 | 2309 | continue; |
4e0ad259 | 2310 | } |
e5003249 | 2311 | |
fce041be | 2312 | txq = &sc->tx.txq[ts.qid]; |
e5003249 | 2313 | |
23de5dc9 | 2314 | ath_txq_lock(sc, txq); |
fce041be | 2315 | |
78ef731c SM |
2316 | TX_STAT_INC(txq->axq_qnum, txprocdesc); |
2317 | ||
99ba6a46 FF |
2318 | fifo_list = &txq->txq_fifo[txq->txq_tailidx]; |
2319 | if (list_empty(fifo_list)) { | |
23de5dc9 | 2320 | ath_txq_unlock(sc, txq); |
e5003249 VT |
2321 | return; |
2322 | } | |
2323 | ||
99ba6a46 FF |
2324 | bf = list_first_entry(fifo_list, struct ath_buf, list); |
2325 | if (bf->bf_stale) { | |
2326 | list_del(&bf->list); | |
2327 | ath_tx_return_buffer(sc, bf); | |
2328 | bf = list_first_entry(fifo_list, struct ath_buf, list); | |
2329 | } | |
2330 | ||
e5003249 VT |
2331 | lastbf = bf->bf_lastbf; |
2332 | ||
2333 | INIT_LIST_HEAD(&bf_head); | |
99ba6a46 FF |
2334 | if (list_is_last(&lastbf->list, fifo_list)) { |
2335 | list_splice_tail_init(fifo_list, &bf_head); | |
fce041be | 2336 | INCR(txq->txq_tailidx, ATH_TXFIFO_DEPTH); |
e5003249 | 2337 | |
fce041be FF |
2338 | if (!list_empty(&txq->axq_q)) { |
2339 | struct list_head bf_q; | |
60f2d1d5 | 2340 | |
fce041be FF |
2341 | INIT_LIST_HEAD(&bf_q); |
2342 | txq->axq_link = NULL; | |
2343 | list_splice_tail_init(&txq->axq_q, &bf_q); | |
2344 | ath_tx_txqaddbuf(sc, txq, &bf_q, true); | |
2345 | } | |
99ba6a46 FF |
2346 | } else { |
2347 | lastbf->bf_stale = true; | |
2348 | if (bf != lastbf) | |
2349 | list_cut_position(&bf_head, fifo_list, | |
2350 | lastbf->list.prev); | |
fce041be | 2351 | } |
86271e46 | 2352 | |
fce041be | 2353 | ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head); |
23de5dc9 | 2354 | ath_txq_unlock_complete(sc, txq); |
e5003249 VT |
2355 | } |
2356 | } | |
2357 | ||
e8324357 S |
2358 | /*****************/ |
2359 | /* Init, Cleanup */ | |
2360 | /*****************/ | |
f078f209 | 2361 | |
5088c2f1 VT |
2362 | static int ath_txstatus_setup(struct ath_softc *sc, int size) |
2363 | { | |
2364 | struct ath_descdma *dd = &sc->txsdma; | |
2365 | u8 txs_len = sc->sc_ah->caps.txs_len; | |
2366 | ||
2367 | dd->dd_desc_len = size * txs_len; | |
b81950b1 FF |
2368 | dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len, |
2369 | &dd->dd_desc_paddr, GFP_KERNEL); | |
5088c2f1 VT |
2370 | if (!dd->dd_desc) |
2371 | return -ENOMEM; | |
2372 | ||
2373 | return 0; | |
2374 | } | |
2375 | ||
2376 | static int ath_tx_edma_init(struct ath_softc *sc) | |
2377 | { | |
2378 | int err; | |
2379 | ||
2380 | err = ath_txstatus_setup(sc, ATH_TXSTATUS_RING_SIZE); | |
2381 | if (!err) | |
2382 | ath9k_hw_setup_statusring(sc->sc_ah, sc->txsdma.dd_desc, | |
2383 | sc->txsdma.dd_desc_paddr, | |
2384 | ATH_TXSTATUS_RING_SIZE); | |
2385 | ||
2386 | return err; | |
2387 | } | |
2388 | ||
e8324357 | 2389 | int ath_tx_init(struct ath_softc *sc, int nbufs) |
f078f209 | 2390 | { |
c46917bb | 2391 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
e8324357 | 2392 | int error = 0; |
f078f209 | 2393 | |
797fe5cb | 2394 | spin_lock_init(&sc->tx.txbuflock); |
f078f209 | 2395 | |
797fe5cb | 2396 | error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf, |
4adfcded | 2397 | "tx", nbufs, 1, 1); |
797fe5cb | 2398 | if (error != 0) { |
3800276a JP |
2399 | ath_err(common, |
2400 | "Failed to allocate tx descriptors: %d\n", error); | |
b81950b1 | 2401 | return error; |
797fe5cb | 2402 | } |
f078f209 | 2403 | |
797fe5cb | 2404 | error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf, |
5088c2f1 | 2405 | "beacon", ATH_BCBUF, 1, 1); |
797fe5cb | 2406 | if (error != 0) { |
3800276a JP |
2407 | ath_err(common, |
2408 | "Failed to allocate beacon descriptors: %d\n", error); | |
b81950b1 | 2409 | return error; |
797fe5cb | 2410 | } |
f078f209 | 2411 | |
164ace38 SB |
2412 | INIT_DELAYED_WORK(&sc->tx_complete_work, ath_tx_complete_poll_work); |
2413 | ||
b81950b1 | 2414 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
5088c2f1 | 2415 | error = ath_tx_edma_init(sc); |
f078f209 | 2416 | |
e8324357 | 2417 | return error; |
f078f209 LR |
2418 | } |
2419 | ||
f078f209 LR |
2420 | void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an) |
2421 | { | |
c5170163 S |
2422 | struct ath_atx_tid *tid; |
2423 | struct ath_atx_ac *ac; | |
2424 | int tidno, acno; | |
f078f209 | 2425 | |
8ee5afbc | 2426 | for (tidno = 0, tid = &an->tid[tidno]; |
de7b7604 | 2427 | tidno < IEEE80211_NUM_TIDS; |
c5170163 S |
2428 | tidno++, tid++) { |
2429 | tid->an = an; | |
2430 | tid->tidno = tidno; | |
2431 | tid->seq_start = tid->seq_next = 0; | |
2432 | tid->baw_size = WME_MAX_BA; | |
2433 | tid->baw_head = tid->baw_tail = 0; | |
2434 | tid->sched = false; | |
e8324357 | 2435 | tid->paused = false; |
a37c2c79 | 2436 | tid->state &= ~AGGR_CLEANUP; |
56dc6336 | 2437 | __skb_queue_head_init(&tid->buf_q); |
c5170163 | 2438 | acno = TID_TO_WME_AC(tidno); |
8ee5afbc | 2439 | tid->ac = &an->ac[acno]; |
a37c2c79 S |
2440 | tid->state &= ~AGGR_ADDBA_COMPLETE; |
2441 | tid->state &= ~AGGR_ADDBA_PROGRESS; | |
16e23428 | 2442 | tid->stop_cb = false; |
c5170163 | 2443 | } |
f078f209 | 2444 | |
8ee5afbc | 2445 | for (acno = 0, ac = &an->ac[acno]; |
bea843c7 | 2446 | acno < IEEE80211_NUM_ACS; acno++, ac++) { |
c5170163 | 2447 | ac->sched = false; |
066dae93 | 2448 | ac->txq = sc->tx.txq_map[acno]; |
c5170163 | 2449 | INIT_LIST_HEAD(&ac->tid_q); |
f078f209 LR |
2450 | } |
2451 | } | |
2452 | ||
b5aa9bf9 | 2453 | void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an) |
f078f209 | 2454 | { |
2b40994c FF |
2455 | struct ath_atx_ac *ac; |
2456 | struct ath_atx_tid *tid; | |
f078f209 | 2457 | struct ath_txq *txq; |
066dae93 | 2458 | int tidno; |
e8324357 | 2459 | |
2b40994c | 2460 | for (tidno = 0, tid = &an->tid[tidno]; |
de7b7604 | 2461 | tidno < IEEE80211_NUM_TIDS; tidno++, tid++) { |
f078f209 | 2462 | |
2b40994c | 2463 | ac = tid->ac; |
066dae93 | 2464 | txq = ac->txq; |
f078f209 | 2465 | |
23de5dc9 | 2466 | ath_txq_lock(sc, txq); |
2b40994c FF |
2467 | |
2468 | if (tid->sched) { | |
2469 | list_del(&tid->list); | |
2470 | tid->sched = false; | |
2471 | } | |
2472 | ||
2473 | if (ac->sched) { | |
2474 | list_del(&ac->list); | |
2475 | tid->ac->sched = false; | |
f078f209 | 2476 | } |
2b40994c FF |
2477 | |
2478 | ath_tid_drain(sc, txq, tid); | |
16e23428 | 2479 | ath_tx_clear_tid(sc, tid); |
2b40994c | 2480 | |
23de5dc9 | 2481 | ath_txq_unlock(sc, txq); |
f078f209 LR |
2482 | } |
2483 | } |