ath9k: fix tx queueing issues after background scans
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 560-ath9k_tx_queueing_rework.patch
1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -133,7 +133,6 @@ int ath_descdma_setup(struct ath_softc *
4 #define ATH_AGGR_ENCRYPTDELIM 10
5 /* minimum h/w qdepth to be sustained to maximize aggregation */
6 #define ATH_AGGR_MIN_QDEPTH 2
7 -#define ATH_AMPDU_SUBFRAME_DEFAULT 32
8
9 #define IEEE80211_SEQ_SEQ_SHIFT 4
10 #define IEEE80211_SEQ_MAX 4096
11 @@ -208,8 +207,9 @@ struct ath_frame_info {
12 int framelen;
13 enum ath9k_key_type keytype;
14 u8 keyix;
15 - u8 retries;
16 u8 rtscts_rate;
17 + u8 retries : 7;
18 + u8 baw_tracked : 1;
19 };
20
21 struct ath_buf_state {
22 @@ -237,6 +237,7 @@ struct ath_buf {
23 struct ath_atx_tid {
24 struct list_head list;
25 struct sk_buff_head buf_q;
26 + struct sk_buff_head retry_q;
27 struct ath_node *an;
28 struct ath_atx_ac *ac;
29 unsigned long tx_buf[BITS_TO_LONGS(ATH_TID_MAX_BUFS)];
30 --- a/drivers/net/wireless/ath/ath9k/debug.c
31 +++ b/drivers/net/wireless/ath/ath9k/debug.c
32 @@ -607,6 +607,28 @@ static ssize_t read_file_xmit(struct fil
33 return retval;
34 }
35
36 +static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
37 + char *buf, ssize_t size)
38 +{
39 + ssize_t len = 0;
40 +
41 + ath_txq_lock(sc, txq);
42 +
43 + len += snprintf(buf + len, size - len, "%s: %d ",
44 + "qnum", txq->axq_qnum);
45 + len += snprintf(buf + len, size - len, "%s: %2d ",
46 + "qdepth", txq->axq_depth);
47 + len += snprintf(buf + len, size - len, "%s: %2d ",
48 + "ampdu-depth", txq->axq_ampdu_depth);
49 + len += snprintf(buf + len, size - len, "%s: %3d ",
50 + "pending", txq->pending_frames);
51 + len += snprintf(buf + len, size - len, "%s: %d\n",
52 + "stopped", txq->stopped);
53 +
54 + ath_txq_unlock(sc, txq);
55 + return len;
56 +}
57 +
58 static ssize_t read_file_queues(struct file *file, char __user *user_buf,
59 size_t count, loff_t *ppos)
60 {
61 @@ -624,24 +646,13 @@ static ssize_t read_file_queues(struct f
62
63 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
64 txq = sc->tx.txq_map[i];
65 - len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
66 -
67 - ath_txq_lock(sc, txq);
68 -
69 - len += snprintf(buf + len, size - len, "%s: %d ",
70 - "qnum", txq->axq_qnum);
71 - len += snprintf(buf + len, size - len, "%s: %2d ",
72 - "qdepth", txq->axq_depth);
73 - len += snprintf(buf + len, size - len, "%s: %2d ",
74 - "ampdu-depth", txq->axq_ampdu_depth);
75 - len += snprintf(buf + len, size - len, "%s: %3d ",
76 - "pending", txq->pending_frames);
77 - len += snprintf(buf + len, size - len, "%s: %d\n",
78 - "stopped", txq->stopped);
79 -
80 - ath_txq_unlock(sc, txq);
81 + len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
82 + len += print_queue(sc, txq, buf + len, size - len);
83 }
84
85 + len += snprintf(buf + len, size - len, "(CAB): ");
86 + len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
87 +
88 if (len > size)
89 len = size;
90
91 --- a/drivers/net/wireless/ath/ath9k/main.c
92 +++ b/drivers/net/wireless/ath/ath9k/main.c
93 @@ -1402,9 +1402,6 @@ static void ath9k_sta_notify(struct ieee
94 struct ath_softc *sc = hw->priv;
95 struct ath_node *an = (struct ath_node *) sta->drv_priv;
96
97 - if (!sta->ht_cap.ht_supported)
98 - return;
99 -
100 switch (cmd) {
101 case STA_NOTIFY_SLEEP:
102 an->sleeping = true;
103 --- a/drivers/net/wireless/ath/ath9k/xmit.c
104 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
105 @@ -168,6 +168,36 @@ static void ath_txq_skb_done(struct ath_
106 }
107 }
108
109 +static struct ath_atx_tid *
110 +ath_get_skb_tid(struct ath_softc *sc, struct ath_node *an, struct sk_buff *skb)
111 +{
112 + struct ieee80211_hdr *hdr;
113 + u8 tidno = 0;
114 +
115 + hdr = (struct ieee80211_hdr *) skb->data;
116 + if (ieee80211_is_data_qos(hdr->frame_control))
117 + tidno = ieee80211_get_qos_ctl(hdr)[0];
118 +
119 + tidno &= IEEE80211_QOS_CTL_TID_MASK;
120 + return ATH_AN_2_TID(an, tidno);
121 +}
122 +
123 +static bool ath_tid_has_buffered(struct ath_atx_tid *tid)
124 +{
125 + return !skb_queue_empty(&tid->buf_q) || !skb_queue_empty(&tid->retry_q);
126 +}
127 +
128 +static struct sk_buff *ath_tid_dequeue(struct ath_atx_tid *tid)
129 +{
130 + struct sk_buff *skb;
131 +
132 + skb = __skb_dequeue(&tid->retry_q);
133 + if (!skb)
134 + skb = __skb_dequeue(&tid->buf_q);
135 +
136 + return skb;
137 +}
138 +
139 static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
140 {
141 struct ath_txq *txq = tid->ac->txq;
142 @@ -182,7 +212,7 @@ static void ath_tx_flush_tid(struct ath_
143
144 memset(&ts, 0, sizeof(ts));
145
146 - while ((skb = __skb_dequeue(&tid->buf_q))) {
147 + while ((skb = ath_tid_dequeue(tid))) {
148 fi = get_frame_info(skb);
149 bf = fi->bf;
150
151 @@ -195,7 +225,7 @@ static void ath_tx_flush_tid(struct ath_
152 }
153 }
154
155 - if (fi->retries) {
156 + if (fi->baw_tracked) {
157 list_add_tail(&bf->list, &bf_head);
158 ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
159 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
160 @@ -232,13 +262,16 @@ static void ath_tx_update_baw(struct ath
161 }
162
163 static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
164 - u16 seqno)
165 + struct ath_buf *bf)
166 {
167 + struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
168 + u16 seqno = bf->bf_state.seqno;
169 int index, cindex;
170
171 index = ATH_BA_INDEX(tid->seq_start, seqno);
172 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
173 __set_bit(cindex, tid->tx_buf);
174 + fi->baw_tracked = 1;
175
176 if (index >= ((tid->baw_tail - tid->baw_head) &
177 (ATH_TID_MAX_BUFS - 1))) {
178 @@ -266,7 +299,7 @@ static void ath_tid_drain(struct ath_sof
179 memset(&ts, 0, sizeof(ts));
180 INIT_LIST_HEAD(&bf_head);
181
182 - while ((skb = __skb_dequeue(&tid->buf_q))) {
183 + while ((skb = ath_tid_dequeue(tid))) {
184 fi = get_frame_info(skb);
185 bf = fi->bf;
186
187 @@ -403,7 +436,6 @@ static void ath_tx_complete_aggr(struct
188 struct ieee80211_tx_rate rates[4];
189 struct ath_frame_info *fi;
190 int nframes;
191 - u8 tidno;
192 bool flush = !!(ts->ts_status & ATH9K_TX_FLUSH);
193 int i, retries;
194 int bar_index = -1;
195 @@ -440,8 +472,7 @@ static void ath_tx_complete_aggr(struct
196 }
197
198 an = (struct ath_node *)sta->drv_priv;
199 - tidno = ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
200 - tid = ATH_AN_2_TID(an, tidno);
201 + tid = ath_get_skb_tid(sc, an, skb);
202 seq_first = tid->seq_start;
203 isba = ts->ts_flags & ATH9K_TX_BA;
204
205 @@ -453,7 +484,7 @@ static void ath_tx_complete_aggr(struct
206 * Only BlockAcks have a TID and therefore normal Acks cannot be
207 * checked
208 */
209 - if (isba && tidno != ts->tid)
210 + if (isba && tid->tidno != ts->tid)
211 txok = false;
212
213 isaggr = bf_isaggr(bf);
214 @@ -489,7 +520,8 @@ static void ath_tx_complete_aggr(struct
215 tx_info = IEEE80211_SKB_CB(skb);
216 fi = get_frame_info(skb);
217
218 - if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
219 + if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno) ||
220 + !tid->active) {
221 /*
222 * Outside of the current BlockAck window,
223 * maybe part of a previous session
224 @@ -583,7 +615,7 @@ static void ath_tx_complete_aggr(struct
225 if (an->sleeping)
226 ieee80211_sta_set_buffered(sta, tid->tidno, true);
227
228 - skb_queue_splice(&bf_pending, &tid->buf_q);
229 + skb_queue_splice_tail(&bf_pending, &tid->retry_q);
230 if (!an->sleeping) {
231 ath_tx_queue_tid(txq, tid);
232
233 @@ -641,7 +673,7 @@ static void ath_tx_process_buffer(struct
234 } else
235 ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok);
236
237 - if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) && !flush)
238 + if (!flush)
239 ath_txq_schedule(sc, txq);
240 }
241
242 @@ -815,15 +847,20 @@ static int ath_compute_num_delims(struct
243
244 static struct ath_buf *
245 ath_tx_get_tid_subframe(struct ath_softc *sc, struct ath_txq *txq,
246 - struct ath_atx_tid *tid)
247 + struct ath_atx_tid *tid, struct sk_buff_head **q)
248 {
249 + struct ieee80211_tx_info *tx_info;
250 struct ath_frame_info *fi;
251 struct sk_buff *skb;
252 struct ath_buf *bf;
253 u16 seqno;
254
255 while (1) {
256 - skb = skb_peek(&tid->buf_q);
257 + *q = &tid->retry_q;
258 + if (skb_queue_empty(*q))
259 + *q = &tid->buf_q;
260 +
261 + skb = skb_peek(*q);
262 if (!skb)
263 break;
264
265 @@ -833,12 +870,22 @@ ath_tx_get_tid_subframe(struct ath_softc
266 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
267
268 if (!bf) {
269 - __skb_unlink(skb, &tid->buf_q);
270 + __skb_unlink(skb, *q);
271 ath_txq_skb_done(sc, txq, skb);
272 ieee80211_free_txskb(sc->hw, skb);
273 continue;
274 }
275
276 + bf->bf_next = NULL;
277 + bf->bf_lastbf = bf;
278 +
279 + tx_info = IEEE80211_SKB_CB(skb);
280 + tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT;
281 + if (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
282 + bf->bf_state.bf_type = 0;
283 + return bf;
284 + }
285 +
286 bf->bf_state.bf_type = BUF_AMPDU | BUF_AGGR;
287 seqno = bf->bf_state.seqno;
288
289 @@ -852,14 +899,12 @@ ath_tx_get_tid_subframe(struct ath_softc
290
291 INIT_LIST_HEAD(&bf_head);
292 list_add(&bf->list, &bf_head);
293 - __skb_unlink(skb, &tid->buf_q);
294 + __skb_unlink(skb, *q);
295 ath_tx_update_baw(sc, tid, seqno);
296 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
297 continue;
298 }
299
300 - bf->bf_next = NULL;
301 - bf->bf_lastbf = bf;
302 return bf;
303 }
304
305 @@ -874,16 +919,17 @@ static enum ATH_AGGR_STATUS ath_tx_form_
306 {
307 #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
308 struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
309 - int rl = 0, nframes = 0, ndelim, prev_al = 0;
310 + int nframes = 0, ndelim;
311 u16 aggr_limit = 0, al = 0, bpad = 0,
312 - al_delta, h_baw = tid->baw_size / 2;
313 + al_delta, h_baw = tid->baw_size / 2;
314 enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
315 struct ieee80211_tx_info *tx_info;
316 struct ath_frame_info *fi;
317 struct sk_buff *skb;
318 + struct sk_buff_head *tid_q;
319
320 do {
321 - bf = ath_tx_get_tid_subframe(sc, txq, tid);
322 + bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
323 if (!bf) {
324 status = ATH_AGGR_BAW_CLOSED;
325 break;
326 @@ -892,33 +938,24 @@ static enum ATH_AGGR_STATUS ath_tx_form_
327 skb = bf->bf_mpdu;
328 fi = get_frame_info(skb);
329
330 - if (!bf_first)
331 + if (!bf_first) {
332 bf_first = bf;
333 -
334 - if (!rl) {
335 ath_set_rates(tid->an->vif, tid->an->sta, bf);
336 aggr_limit = ath_lookup_rate(sc, bf, tid);
337 - rl = 1;
338 }
339
340 /* do not exceed aggregation limit */
341 al_delta = ATH_AGGR_DELIM_SZ + fi->framelen;
342 + if (nframes) {
343 + if (aggr_limit < al + bpad + al_delta ||
344 + ath_lookup_legacy(bf) || nframes >= h_baw) {
345 + status = ATH_AGGR_LIMITED;
346 + break;
347 + }
348
349 - if (nframes &&
350 - ((aggr_limit < (al + bpad + al_delta + prev_al)) ||
351 - ath_lookup_legacy(bf))) {
352 - status = ATH_AGGR_LIMITED;
353 - break;
354 - }
355 -
356 - tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
357 - if (nframes && (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE))
358 - break;
359 -
360 - /* do not exceed subframe limit */
361 - if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
362 - status = ATH_AGGR_LIMITED;
363 - break;
364 + tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
365 + if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
366 + break;
367 }
368
369 /* add padding for previous frame to aggregation length */
370 @@ -936,18 +973,18 @@ static enum ATH_AGGR_STATUS ath_tx_form_
371 bf->bf_next = NULL;
372
373 /* link buffers of this frame to the aggregate */
374 - if (!fi->retries)
375 - ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
376 + if (!fi->baw_tracked)
377 + ath_tx_addto_baw(sc, tid, bf);
378 bf->bf_state.ndelim = ndelim;
379
380 - __skb_unlink(skb, &tid->buf_q);
381 + __skb_unlink(skb, tid_q);
382 list_add_tail(&bf->list, bf_q);
383 if (bf_prev)
384 bf_prev->bf_next = bf;
385
386 bf_prev = bf;
387
388 - } while (!skb_queue_empty(&tid->buf_q));
389 + } while (ath_tid_has_buffered(tid));
390
391 *aggr_len = al;
392
393 @@ -1222,7 +1259,7 @@ static void ath_tx_sched_aggr(struct ath
394 int aggr_len;
395
396 do {
397 - if (skb_queue_empty(&tid->buf_q))
398 + if (!ath_tid_has_buffered(tid))
399 return;
400
401 INIT_LIST_HEAD(&bf_q);
402 @@ -1301,7 +1338,7 @@ void ath_tx_aggr_stop(struct ath_softc *
403
404 ath_txq_lock(sc, txq);
405 txtid->active = false;
406 - txtid->paused = true;
407 + txtid->paused = false;
408 ath_tx_flush_tid(sc, txtid);
409 ath_txq_unlock_complete(sc, txq);
410 }
411 @@ -1326,7 +1363,7 @@ void ath_tx_aggr_sleep(struct ieee80211_
412
413 ath_txq_lock(sc, txq);
414
415 - buffered = !skb_queue_empty(&tid->buf_q);
416 + buffered = ath_tid_has_buffered(tid);
417
418 tid->sched = false;
419 list_del(&tid->list);
420 @@ -1358,7 +1395,7 @@ void ath_tx_aggr_wakeup(struct ath_softc
421 ath_txq_lock(sc, txq);
422 ac->clear_ps_filter = true;
423
424 - if (!skb_queue_empty(&tid->buf_q) && !tid->paused) {
425 + if (!tid->paused && ath_tid_has_buffered(tid)) {
426 ath_tx_queue_tid(txq, tid);
427 ath_txq_schedule(sc, txq);
428 }
429 @@ -1383,7 +1420,7 @@ void ath_tx_aggr_resume(struct ath_softc
430 tid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
431 tid->paused = false;
432
433 - if (!skb_queue_empty(&tid->buf_q)) {
434 + if (ath_tid_has_buffered(tid)) {
435 ath_tx_queue_tid(txq, tid);
436 ath_txq_schedule(sc, txq);
437 }
438 @@ -1403,6 +1440,7 @@ void ath9k_release_buffered_frames(struc
439 struct ieee80211_tx_info *info;
440 struct list_head bf_q;
441 struct ath_buf *bf_tail = NULL, *bf;
442 + struct sk_buff_head *tid_q;
443 int sent = 0;
444 int i;
445
446 @@ -1418,15 +1456,15 @@ void ath9k_release_buffered_frames(struc
447 continue;
448
449 ath_txq_lock(sc, tid->ac->txq);
450 - while (!skb_queue_empty(&tid->buf_q) && nframes > 0) {
451 - bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid);
452 + while (nframes > 0) {
453 + bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid, &tid_q);
454 if (!bf)
455 break;
456
457 - __skb_unlink(bf->bf_mpdu, &tid->buf_q);
458 + __skb_unlink(bf->bf_mpdu, tid_q);
459 list_add_tail(&bf->list, &bf_q);
460 ath_set_rates(tid->an->vif, tid->an->sta, bf);
461 - ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
462 + ath_tx_addto_baw(sc, tid, bf);
463 bf->bf_state.bf_type &= ~BUF_AGGR;
464 if (bf_tail)
465 bf_tail->bf_next = bf;
466 @@ -1436,7 +1474,7 @@ void ath9k_release_buffered_frames(struc
467 sent++;
468 TX_STAT_INC(txq->axq_qnum, a_queued_hw);
469
470 - if (skb_queue_empty(&tid->buf_q))
471 + if (!ath_tid_has_buffered(tid))
472 ieee80211_sta_set_buffered(an->sta, i, false);
473 }
474 ath_txq_unlock_complete(sc, tid->ac->txq);
475 @@ -1722,7 +1760,7 @@ void ath_txq_schedule(struct ath_softc *
476 * add tid to round-robin queue if more frames
477 * are pending for the tid
478 */
479 - if (!skb_queue_empty(&tid->buf_q))
480 + if (ath_tid_has_buffered(tid))
481 ath_tx_queue_tid(txq, tid);
482
483 if (tid == last_tid ||
484 @@ -1831,7 +1869,7 @@ static void ath_tx_send_ampdu(struct ath
485 * - seqno is not within block-ack window
486 * - h/w queue depth exceeds low water mark
487 */
488 - if ((!skb_queue_empty(&tid->buf_q) || tid->paused ||
489 + if ((ath_tid_has_buffered(tid) || tid->paused ||
490 !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
491 txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) &&
492 txq != sc->tx.uapsdq) {
493 @@ -1859,7 +1897,7 @@ static void ath_tx_send_ampdu(struct ath
494 list_add(&bf->list, &bf_head);
495
496 /* Add sub-frame to BAW */
497 - ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
498 + ath_tx_addto_baw(sc, tid, bf);
499
500 /* Queue to h/w without aggregation */
501 TX_STAT_INC(txq->axq_qnum, a_queued_hw);
502 @@ -2066,7 +2104,6 @@ int ath_tx_start(struct ieee80211_hw *hw
503 struct ath_txq *txq = txctl->txq;
504 struct ath_atx_tid *tid = NULL;
505 struct ath_buf *bf;
506 - u8 tidno;
507 int q;
508 int ret;
509
510 @@ -2097,9 +2134,7 @@ int ath_tx_start(struct ieee80211_hw *hw
511 }
512
513 if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
514 - tidno = ieee80211_get_qos_ctl(hdr)[0] &
515 - IEEE80211_QOS_CTL_TID_MASK;
516 - tid = ATH_AN_2_TID(txctl->an, tidno);
517 + tid = ath_get_skb_tid(sc, txctl->an, skb);
518
519 WARN_ON(tid->ac->txq != txctl->txq);
520 }
521 @@ -2372,8 +2407,7 @@ static void ath_tx_processq(struct ath_s
522
523 if (list_empty(&txq->axq_q)) {
524 txq->axq_link = NULL;
525 - if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
526 - ath_txq_schedule(sc, txq);
527 + ath_txq_schedule(sc, txq);
528 break;
529 }
530 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
531 @@ -2595,6 +2629,7 @@ void ath_tx_node_init(struct ath_softc *
532 tid->paused = false;
533 tid->active = false;
534 __skb_queue_head_init(&tid->buf_q);
535 + __skb_queue_head_init(&tid->retry_q);
536 acno = TID_TO_WME_AC(tidno);
537 tid->ac = &an->ac[acno];
538 }
539 @@ -2602,6 +2637,7 @@ void ath_tx_node_init(struct ath_softc *
540 for (acno = 0, ac = &an->ac[acno];
541 acno < IEEE80211_NUM_ACS; acno++, ac++) {
542 ac->sched = false;
543 + ac->clear_ps_filter = true;
544 ac->txq = sc->tx.txq_map[acno];
545 INIT_LIST_HEAD(&ac->tid_q);
546 }