lantiq: setup gphy leds on TPlink TDW8970
[openwrt.git] / package / kernel / mac80211 / patches / 567-ath9k_tid_queue_non_aggr.patch
1 --- a/drivers/net/wireless/ath/ath9k/xmit.c
2 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
3 @@ -672,7 +672,7 @@ static void ath_tx_process_buffer(struct
4         } else
5                 ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok);
6  
7 -       if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) && !flush)
8 +       if (!flush)
9                 ath_txq_schedule(sc, txq);
10  }
11  
12 @@ -848,6 +848,7 @@ static struct ath_buf *
13  ath_tx_get_tid_subframe(struct ath_softc *sc, struct ath_txq *txq,
14                         struct ath_atx_tid *tid, struct sk_buff_head **q)
15  {
16 +       struct ieee80211_tx_info *tx_info;
17         struct ath_frame_info *fi;
18         struct sk_buff *skb;
19         struct ath_buf *bf;
20 @@ -874,6 +875,16 @@ ath_tx_get_tid_subframe(struct ath_softc
21                         continue;
22                 }
23  
24 +               bf->bf_next = NULL;
25 +               bf->bf_lastbf = bf;
26 +
27 +               tx_info = IEEE80211_SKB_CB(skb);
28 +               tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT;
29 +               if (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
30 +                       bf->bf_state.bf_type = 0;
31 +                       return bf;
32 +               }
33 +
34                 bf->bf_state.bf_type = BUF_AMPDU | BUF_AGGR;
35                 seqno = bf->bf_state.seqno;
36  
37 @@ -893,58 +904,45 @@ ath_tx_get_tid_subframe(struct ath_softc
38                         continue;
39                 }
40  
41 -               bf->bf_next = NULL;
42 -               bf->bf_lastbf = bf;
43                 return bf;
44         }
45  
46         return NULL;
47  }
48  
49 -static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
50 -                                            struct ath_txq *txq,
51 -                                            struct ath_atx_tid *tid,
52 -                                            struct list_head *bf_q,
53 -                                            int *aggr_len)
54 +static bool
55 +ath_tx_form_aggr(struct ath_softc *sc, struct ath_txq *txq,
56 +                struct ath_atx_tid *tid, struct list_head *bf_q,
57 +                struct ath_buf *bf_first, struct sk_buff_head *tid_q,
58 +                int *aggr_len)
59  {
60  #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
61 -       struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
62 +       struct ath_buf *bf = bf_first, *bf_prev = NULL;
63         int nframes = 0, ndelim;
64         u16 aggr_limit = 0, al = 0, bpad = 0,
65             al_delta, h_baw = tid->baw_size / 2;
66 -       enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
67         struct ieee80211_tx_info *tx_info;
68         struct ath_frame_info *fi;
69         struct sk_buff *skb;
70 -       struct sk_buff_head *tid_q;
71 +       bool closed = false;
72  
73 -       do {
74 -               bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
75 -               if (!bf) {
76 -                       status = ATH_AGGR_BAW_CLOSED;
77 -                       break;
78 -               }
79 +       bf = bf_first;
80 +       aggr_limit = ath_lookup_rate(sc, bf, tid);
81  
82 +       do {
83                 skb = bf->bf_mpdu;
84                 fi = get_frame_info(skb);
85  
86 -               if (!bf_first) {
87 -                       bf_first = bf;
88 -                       ath_set_rates(tid->an->vif, tid->an->sta, bf);
89 -                       aggr_limit = ath_lookup_rate(sc, bf, tid);
90 -               }
91 -
92                 /* do not exceed aggregation limit */
93                 al_delta = ATH_AGGR_DELIM_SZ + fi->framelen;
94                 if (nframes) {
95                         if (aggr_limit < al + bpad + al_delta ||
96 -                           ath_lookup_legacy(bf) || nframes >= h_baw) {
97 -                               status = ATH_AGGR_LIMITED;
98 +                           ath_lookup_legacy(bf) || nframes >= h_baw)
99                                 break;
100 -                       }
101  
102                         tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
103 -                       if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
104 +                       if ((tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) ||
105 +                           !(tx_info->flags & IEEE80211_TX_CTL_AMPDU))
106                                 break;
107                 }
108  
109 @@ -974,11 +972,26 @@ static enum ATH_AGGR_STATUS ath_tx_form_
110  
111                 bf_prev = bf;
112  
113 +               bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
114 +               if (!bf) {
115 +                       closed = true;
116 +                       break;
117 +               }
118         } while (ath_tid_has_buffered(tid));
119  
120 +       bf = bf_first;
121 +       bf->bf_lastbf = bf_prev;
122 +
123 +       if (bf == bf_prev) {
124 +               al = get_frame_info(bf->bf_mpdu)->framelen;
125 +               bf->bf_state.bf_type = BUF_AMPDU;
126 +       } else {
127 +               TX_STAT_INC(txq->axq_qnum, a_aggr);
128 +       }
129 +
130         *aggr_len = al;
131  
132 -       return status;
133 +       return closed;
134  #undef PADBYTES
135  }
136  
137 @@ -1239,14 +1252,45 @@ static void ath_tx_fill_desc(struct ath_
138         }
139  }
140  
141 +static void
142 +ath_tx_form_burst(struct ath_softc *sc, struct ath_txq *txq,
143 +                 struct ath_atx_tid *tid, struct list_head *bf_q,
144 +                 struct ath_buf *bf_first, struct sk_buff_head *tid_q)
145 +{
146 +       struct ath_buf *bf = bf_first, *bf_prev = NULL;
147 +       struct sk_buff *skb;
148 +       int nframes = 0;
149 +
150 +       do {
151 +               skb = bf->bf_mpdu;
152 +
153 +               nframes++;
154 +               __skb_unlink(skb, tid_q);
155 +               list_add_tail(&bf->list, bf_q);
156 +               if (bf_prev)
157 +                       bf_prev->bf_next = bf;
158 +               bf_prev = bf;
159 +
160 +               if (nframes >= 2)
161 +                       break;
162 +
163 +               bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
164 +               if (!bf)
165 +                       break;
166 +
167 +               ath_set_rates(tid->an->vif, tid->an->sta, bf);
168 +       } while (1);
169 +}
170 +
171  static void ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
172                               struct ath_atx_tid *tid)
173  {
174         struct ath_buf *bf;
175 -       enum ATH_AGGR_STATUS status;
176         struct ieee80211_tx_info *tx_info;
177 +       struct sk_buff_head *tid_q;
178         struct list_head bf_q;
179 -       int aggr_len;
180 +       int aggr_len = 0;
181 +       bool aggr, last = true;
182  
183         do {
184                 if (!ath_tid_has_buffered(tid))
185 @@ -1254,38 +1298,31 @@ static void ath_tx_sched_aggr(struct ath
186  
187                 INIT_LIST_HEAD(&bf_q);
188  
189 -               status = ath_tx_form_aggr(sc, txq, tid, &bf_q, &aggr_len);
190 -
191 -               /*
192 -                * no frames picked up to be aggregated;
193 -                * block-ack window is not open.
194 -                */
195 -               if (list_empty(&bf_q))
196 +               bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
197 +               if (!bf)
198                         break;
199  
200 -               bf = list_first_entry(&bf_q, struct ath_buf, list);
201 -               bf->bf_lastbf = list_entry(bf_q.prev, struct ath_buf, list);
202                 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
203 +               aggr = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
204 +               if ((aggr && txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) ||
205 +                   (!aggr && txq->axq_depth >= ATH_NON_AGGR_MIN_QDEPTH))
206 +                       break;
207 +
208 +               ath_set_rates(tid->an->vif, tid->an->sta, bf);
209 +               if (aggr)
210 +                       last = ath_tx_form_aggr(sc, txq, tid, &bf_q, bf,
211 +                                               tid_q, &aggr_len);
212 +               else
213 +                       ath_tx_form_burst(sc, txq, tid, &bf_q, bf, tid_q);
214  
215                 if (tid->ac->clear_ps_filter) {
216                         tid->ac->clear_ps_filter = false;
217                         tx_info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
218 -               } else {
219 -                       tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT;
220 -               }
221 -
222 -               /* if only one frame, send as non-aggregate */
223 -               if (bf == bf->bf_lastbf) {
224 -                       aggr_len = get_frame_info(bf->bf_mpdu)->framelen;
225 -                       bf->bf_state.bf_type = BUF_AMPDU;
226 -               } else {
227 -                       TX_STAT_INC(txq->axq_qnum, a_aggr);
228                 }
229  
230                 ath_tx_fill_desc(sc, bf, txq, aggr_len);
231                 ath_tx_txqaddbuf(sc, txq, &bf_q, false);
232 -       } while (txq->axq_ampdu_depth < ATH_AGGR_MIN_QDEPTH &&
233 -                status != ATH_AGGR_BAW_CLOSED);
234 +       } while (!last);
235  }
236  
237  int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
238 @@ -1844,58 +1881,6 @@ static void ath_tx_txqaddbuf(struct ath_
239         }
240  }
241  
242 -static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_txq *txq,
243 -                             struct ath_atx_tid *tid, struct sk_buff *skb,
244 -                             struct ath_tx_control *txctl)
245 -{
246 -       struct ath_frame_info *fi = get_frame_info(skb);
247 -       struct list_head bf_head;
248 -       struct ath_buf *bf;
249 -
250 -       /*
251 -        * Do not queue to h/w when any of the following conditions is true:
252 -        * - there are pending frames in software queue
253 -        * - the TID is currently paused for ADDBA/BAR request
254 -        * - seqno is not within block-ack window
255 -        * - h/w queue depth exceeds low water mark
256 -        */
257 -       if ((ath_tid_has_buffered(tid) || tid->paused ||
258 -            !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
259 -            txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) &&
260 -           txq != sc->tx.uapsdq) {
261 -               /*
262 -                * Add this frame to software queue for scheduling later
263 -                * for aggregation.
264 -                */
265 -               TX_STAT_INC(txq->axq_qnum, a_queued_sw);
266 -               __skb_queue_tail(&tid->buf_q, skb);
267 -               if (!txctl->an || !txctl->an->sleeping)
268 -                       ath_tx_queue_tid(txq, tid);
269 -               return;
270 -       }
271 -
272 -       bf = ath_tx_setup_buffer(sc, txq, tid, skb);
273 -       if (!bf) {
274 -               ath_txq_skb_done(sc, txq, skb);
275 -               ieee80211_free_txskb(sc->hw, skb);
276 -               return;
277 -       }
278 -
279 -       ath_set_rates(tid->an->vif, tid->an->sta, bf);
280 -       bf->bf_state.bf_type = BUF_AMPDU;
281 -       INIT_LIST_HEAD(&bf_head);
282 -       list_add(&bf->list, &bf_head);
283 -
284 -       /* Add sub-frame to BAW */
285 -       ath_tx_addto_baw(sc, tid, bf);
286 -
287 -       /* Queue to h/w without aggregation */
288 -       TX_STAT_INC(txq->axq_qnum, a_queued_hw);
289 -       bf->bf_lastbf = bf;
290 -       ath_tx_fill_desc(sc, bf, txq, fi->framelen);
291 -       ath_tx_txqaddbuf(sc, txq, &bf_head, false);
292 -}
293 -
294  static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
295                                struct ath_atx_tid *tid, struct sk_buff *skb)
296  {
297 @@ -2121,20 +2106,25 @@ int ath_tx_start(struct ieee80211_hw *hw
298                 ath_txq_unlock(sc, txq);
299                 txq = sc->tx.uapsdq;
300                 ath_txq_lock(sc, txq);
301 -       }
302 -
303 -       if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
304 +       } else if (txctl->an &&
305 +                  ieee80211_is_data_present(hdr->frame_control)) {
306                 tid = ath_get_skb_tid(sc, txctl->an, skb);
307  
308                 WARN_ON(tid->ac->txq != txctl->txq);
309 -       }
310  
311 -       if ((info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
312 +               if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
313 +                       tid->ac->clear_ps_filter = true;
314 +
315                 /*
316 -                * Try aggregation if it's a unicast data frame
317 -                * and the destination is HT capable.
318 +                * Add this frame to software queue for scheduling later
319 +                * for aggregation.
320                  */
321 -               ath_tx_send_ampdu(sc, txq, tid, skb, txctl);
322 +               TX_STAT_INC(txq->axq_qnum, a_queued_sw);
323 +               __skb_queue_tail(&tid->buf_q, skb);
324 +               if (!txctl->an->sleeping)
325 +                       ath_tx_queue_tid(txq, tid);
326 +
327 +               ath_txq_schedule(sc, txq);
328                 goto out;
329         }
330  
331 @@ -2397,8 +2387,7 @@ static void ath_tx_processq(struct ath_s
332  
333                 if (list_empty(&txq->axq_q)) {
334                         txq->axq_link = NULL;
335 -                       if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
336 -                               ath_txq_schedule(sc, txq);
337 +                       ath_txq_schedule(sc, txq);
338                         break;
339                 }
340                 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
341 @@ -2628,6 +2617,7 @@ void ath_tx_node_init(struct ath_softc *
342         for (acno = 0, ac = &an->ac[acno];
343              acno < IEEE80211_NUM_ACS; acno++, ac++) {
344                 ac->sched    = false;
345 +               ac->clear_ps_filter = true;
346                 ac->txq = sc->tx.txq_map[acno];
347                 INIT_LIST_HEAD(&ac->tid_q);
348         }
349 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
350 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
351 @@ -137,6 +137,8 @@ int ath_descdma_setup(struct ath_softc *
352  #define ATH_AGGR_ENCRYPTDELIM      10
353  /* minimum h/w qdepth to be sustained to maximize aggregation */
354  #define ATH_AGGR_MIN_QDEPTH        2
355 +/* minimum h/w qdepth for non-aggregated traffic */
356 +#define ATH_NON_AGGR_MIN_QDEPTH    8
357  
358  #define IEEE80211_SEQ_SEQ_SHIFT    4
359  #define IEEE80211_SEQ_MAX          4096
360 @@ -173,12 +175,6 @@ int ath_descdma_setup(struct ath_softc *
361  
362  #define ATH_TX_COMPLETE_POLL_INT       1000
363  
364 -enum ATH_AGGR_STATUS {
365 -       ATH_AGGR_DONE,
366 -       ATH_AGGR_BAW_CLOSED,
367 -       ATH_AGGR_LIMITED,
368 -};
369 -
370  #define ATH_TXFIFO_DEPTH 8
371  struct ath_txq {
372         int mac80211_qnum; /* mac80211 queue number, -1 means not mac80211 Q */
373 --- a/drivers/net/wireless/ath/ath9k/main.c
374 +++ b/drivers/net/wireless/ath/ath9k/main.c
375 @@ -1403,9 +1403,6 @@ static void ath9k_sta_notify(struct ieee
376         struct ath_softc *sc = hw->priv;
377         struct ath_node *an = (struct ath_node *) sta->drv_priv;
378  
379 -       if (!sta->ht_cap.ht_supported)
380 -               return;
381 -
382         switch (cmd) {
383         case STA_NOTIFY_SLEEP:
384                 an->sleeping = true;