mac80211: remove obsolete patches
[oweals/openwrt.git] / package / kernel / mac80211 / patches / 300-mac80211-add-an-intermediate-software-queue-implemen.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Date: Tue, 18 Nov 2014 23:58:51 +0100
3 Subject: [PATCH] mac80211: add an intermediate software queue implementation
4
5 This allows drivers to request per-vif and per-sta-tid queues from which
6 they can pull frames. This makes it easier to keep the hardware queues
7 short, and to improve fairness between clients and vifs.
8
9 The task of scheduling packet transmission is left up to the driver -
10 queueing is controlled by mac80211. Drivers can only dequeue packets by
11 calling ieee80211_tx_dequeue. This makes it possible to add active queue
12 management later without changing drivers using this code.
13
14 This can also be used as a starting point to implement A-MSDU
15 aggregation in a way that does not add artificially induced latency.
16
17 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
18 ---
19
20 --- a/include/net/mac80211.h
21 +++ b/include/net/mac80211.h
22 @@ -1257,6 +1257,8 @@ struct ieee80211_vif {
23         u8 cab_queue;
24         u8 hw_queue[IEEE80211_NUM_ACS];
25  
26 +       struct ieee80211_txq *txq;
27 +
28         struct ieee80211_chanctx_conf __rcu *chanctx_conf;
29  
30         u32 driver_flags;
31 @@ -1519,6 +1521,8 @@ struct ieee80211_sta {
32         bool tdls_initiator;
33         bool mfp;
34  
35 +       struct ieee80211_txq *txq[IEEE80211_NUM_TIDS];
36 +
37         /* must be last */
38         u8 drv_priv[0] __aligned(sizeof(void *));
39  };
40 @@ -1547,6 +1551,27 @@ struct ieee80211_tx_control {
41  };
42  
43  /**
44 + * struct ieee80211_txq - Software intermediate tx queue
45 + *
46 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
47 + * @sta: station table entry, may be NULL for per-vif queue
48 + * @tid: the TID for this queue (unset for per-vif queue)
49 + * @ac: the AC for this queue
50 + *
51 + * The driver can obtain packets from this queue by calling
52 + * ieee80211_tx_dequeue().
53 + */
54 +struct ieee80211_txq {
55 +       struct ieee80211_vif *vif;
56 +       struct ieee80211_sta *sta;
57 +       u8 tid;
58 +       u8 ac;
59 +
60 +       /* must be last */
61 +       u8 drv_priv[0] __aligned(sizeof(void *));
62 +};
63 +
64 +/**
65   * enum ieee80211_hw_flags - hardware flags
66   *
67   * These flags are used to indicate hardware capabilities to
68 @@ -1770,6 +1795,8 @@ enum ieee80211_hw_flags {
69   *     within &struct ieee80211_sta.
70   * @chanctx_data_size: size (in bytes) of the drv_priv data area
71   *     within &struct ieee80211_chanctx_conf.
72 + * @txq_data_size: size (in bytes) of the drv_priv data area
73 + *     within @struct ieee80211_txq.
74   *
75   * @max_rates: maximum number of alternate rate retry stages the hw
76   *     can handle.
77 @@ -1818,6 +1845,9 @@ enum ieee80211_hw_flags {
78   * @n_cipher_schemes: a size of an array of cipher schemes definitions.
79   * @cipher_schemes: a pointer to an array of cipher scheme definitions
80   *     supported by HW.
81 + *
82 + * @txq_ac_max_pending: maximum number of frames per AC pending in all txq
83 + *     entries for a vif.
84   */
85  struct ieee80211_hw {
86         struct ieee80211_conf conf;
87 @@ -1830,6 +1860,7 @@ struct ieee80211_hw {
88         int vif_data_size;
89         int sta_data_size;
90         int chanctx_data_size;
91 +       int txq_data_size;
92         u16 queues;
93         u16 max_listen_interval;
94         s8 max_signal;
95 @@ -1846,6 +1877,7 @@ struct ieee80211_hw {
96         u8 uapsd_max_sp_len;
97         u8 n_cipher_schemes;
98         const struct ieee80211_cipher_scheme *cipher_schemes;
99 +       int txq_ac_max_pending;
100  };
101  
102  /**
103 @@ -3007,6 +3039,8 @@ enum ieee80211_reconfig_type {
104   *     response template is provided, together with the location of the
105   *     switch-timing IE within the template. The skb can only be used within
106   *     the function call.
107 + *
108 + * @wake_tx_queue: Called when new packets have been added to the queue.
109   */
110  struct ieee80211_ops {
111         void (*tx)(struct ieee80211_hw *hw,
112 @@ -3238,6 +3272,9 @@ struct ieee80211_ops {
113         void (*tdls_recv_channel_switch)(struct ieee80211_hw *hw,
114                                          struct ieee80211_vif *vif,
115                                          struct ieee80211_tdls_ch_sw_params *params);
116 +
117 +       void (*wake_tx_queue)(struct ieee80211_hw *hw,
118 +                             struct ieee80211_txq *txq);
119  };
120  
121  /**
122 @@ -5249,4 +5286,17 @@ void ieee80211_unreserve_tid(struct ieee
123   */
124  size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
125                           const u8 *ids, int n_ids, size_t offset);
126 +
127 +/**
128 + * ieee80211_tx_dequeue - dequeue a packet from a software tx queue
129 + *
130 + * @hw: pointer as obtained from ieee80211_alloc_hw()
131 + * @txq: pointer obtained from .add_tx_queue() call
132 + *
133 + * Returns the sjb if successful, ERR_PTR(-EAGAIN) if no frame was available.
134 + */
135 +struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
136 +                                    struct ieee80211_txq *txq);
137 +
138 +
139  #endif /* MAC80211_H */
140 --- a/net/mac80211/driver-ops.h
141 +++ b/net/mac80211/driver-ops.h
142 @@ -1367,4 +1367,21 @@ drv_tdls_recv_channel_switch(struct ieee
143         trace_drv_return_void(local);
144  }
145  
146 +static inline void drv_wake_tx_queue(struct ieee80211_local *local,
147 +                                    struct txq_info *txq)
148 +{
149 +       struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->txq.vif);
150 +
151 +       if (!check_sdata_in_driver(sdata))
152 +               return;
153 +
154 +       if (txq->txq.sta)
155 +               trace_drv_wake_sta_tx_queue(local, sdata, txq->txq.sta,
156 +                                           txq->txq.tid);
157 +       else
158 +               trace_drv_wake_vif_tx_queue(local, sdata);
159 +
160 +       local->ops->wake_tx_queue(&local->hw, &txq->txq);
161 +}
162 +
163  #endif /* __MAC80211_DRIVER_OPS */
164 --- a/net/mac80211/ieee80211_i.h
165 +++ b/net/mac80211/ieee80211_i.h
166 @@ -809,6 +809,13 @@ struct mac80211_qos_map {
167         struct rcu_head rcu_head;
168  };
169  
170 +struct txq_info {
171 +       struct sk_buff_head queue;
172 +
173 +       /* keep last! */
174 +       struct ieee80211_txq txq;
175 +};
176 +
177  struct ieee80211_sub_if_data {
178         struct list_head list;
179  
180 @@ -853,6 +860,7 @@ struct ieee80211_sub_if_data {
181         bool control_port_no_encrypt;
182         int encrypt_headroom;
183  
184 +       atomic_t txqs_len[IEEE80211_NUM_ACS];
185         struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS];
186         struct mac80211_qos_map __rcu *qos_map;
187  
188 @@ -1905,6 +1913,12 @@ static inline bool ieee80211_can_run_wor
189         return true;
190  }
191  
192 +void ieee80211_init_tx_queue(struct ieee80211_sub_if_data *sdata,
193 +                            struct sta_info *sta,
194 +                            struct txq_info *txq, int tid);
195 +void ieee80211_flush_tx_queue(struct ieee80211_local *local,
196 +                             struct ieee80211_txq *txq);
197 +
198  void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
199                          u16 transaction, u16 auth_alg, u16 status,
200                          const u8 *extra, size_t extra_len, const u8 *bssid,
201 --- a/net/mac80211/iface.c
202 +++ b/net/mac80211/iface.c
203 @@ -969,6 +969,9 @@ static void ieee80211_do_stop(struct iee
204         }
205         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
206  
207 +       if (sdata->vif.txq)
208 +               ieee80211_flush_tx_queue(local, sdata->vif.txq);
209 +
210         if (local->open_count == 0)
211                 ieee80211_clear_tx_pending(local);
212  
213 @@ -1773,6 +1776,15 @@ int ieee80211_if_add(struct ieee80211_lo
214         ieee80211_setup_sdata(sdata, type);
215  
216         if (ndev) {
217 +               struct txq_info *txqi = NULL;
218 +
219 +               if (local->ops->wake_tx_queue) {
220 +                       txqi = kzalloc(sizeof(*txqi) +
221 +                                     local->hw.txq_data_size, GFP_KERNEL);
222 +                       if (txqi)
223 +                               ieee80211_init_tx_queue(sdata, NULL, txqi, 0);
224 +               }
225 +
226                 if (params) {
227                         ndev->ieee80211_ptr->use_4addr = params->use_4addr;
228                         if (type == NL80211_IFTYPE_STATION)
229 @@ -1785,6 +1797,7 @@ int ieee80211_if_add(struct ieee80211_lo
230  
231                 ret = register_netdevice(ndev);
232                 if (ret) {
233 +                       kfree(txqi);
234                         free_netdev(ndev);
235                         return ret;
236                 }
237 @@ -1802,6 +1815,7 @@ int ieee80211_if_add(struct ieee80211_lo
238  
239  void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
240  {
241 +       struct txq_info *txqi;
242         ASSERT_RTNL();
243  
244         mutex_lock(&sdata->local->iflist_mtx);
245 @@ -1810,6 +1824,11 @@ void ieee80211_if_remove(struct ieee8021
246  
247         synchronize_rcu();
248  
249 +       if (sdata->vif.txq) {
250 +               txqi = container_of(sdata->vif.txq, struct txq_info, txq);
251 +               kfree(txqi);
252 +       }
253 +
254         if (sdata->dev) {
255                 unregister_netdevice(sdata->dev);
256         } else {
257 @@ -1833,6 +1852,7 @@ void ieee80211_sdata_stop(struct ieee802
258  void ieee80211_remove_interfaces(struct ieee80211_local *local)
259  {
260         struct ieee80211_sub_if_data *sdata, *tmp;
261 +       struct txq_info *txqi;
262         LIST_HEAD(unreg_list);
263         LIST_HEAD(wdev_list);
264  
265 @@ -1851,6 +1871,12 @@ void ieee80211_remove_interfaces(struct 
266         list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
267                 list_del(&sdata->list);
268  
269 +               if (sdata->vif.txq) {
270 +                       txqi = container_of(sdata->vif.txq, struct txq_info,
271 +                                          txq);
272 +                       kfree(txqi);
273 +               }
274 +
275                 if (sdata->dev)
276                         unregister_netdevice_queue(sdata->dev, &unreg_list);
277                 else
278 --- a/net/mac80211/main.c
279 +++ b/net/mac80211/main.c
280 @@ -1019,6 +1019,9 @@ int ieee80211_register_hw(struct ieee802
281  
282         local->dynamic_ps_forced_timeout = -1;
283  
284 +       if (!local->hw.txq_ac_max_pending)
285 +               local->hw.txq_ac_max_pending = 64;
286 +
287         result = ieee80211_wep_init(local);
288         if (result < 0)
289                 wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
290 --- a/net/mac80211/sta_info.c
291 +++ b/net/mac80211/sta_info.c
292 @@ -118,6 +118,11 @@ static void __cleanup_single_sta(struct 
293                 atomic_dec(&ps->num_sta_ps);
294         }
295  
296 +       if (sta->txq) {
297 +               for (i = 0; i < IEEE80211_NUM_TIDS; i++)
298 +                       ieee80211_flush_tx_queue(local, sta->sta.txq[i]);
299 +       }
300 +
301         for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
302                 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
303                 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
304 @@ -234,6 +239,7 @@ void sta_info_free(struct ieee80211_loca
305  
306         sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
307  
308 +       kfree(sta->txq);
309         kfree(rcu_dereference_raw(sta->sta.rates));
310         kfree(sta);
311  }
312 @@ -285,11 +291,12 @@ struct sta_info *sta_info_alloc(struct i
313                                 const u8 *addr, gfp_t gfp)
314  {
315         struct ieee80211_local *local = sdata->local;
316 +       struct ieee80211_hw *hw = &local->hw;
317         struct sta_info *sta;
318         struct timespec uptime;
319         int i;
320  
321 -       sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
322 +       sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
323         if (!sta)
324                 return NULL;
325  
326 @@ -321,11 +328,23 @@ struct sta_info *sta_info_alloc(struct i
327         for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
328                 ewma_init(&sta->chain_signal_avg[i], 1024, 8);
329  
330 -       if (sta_prepare_rate_control(local, sta, gfp)) {
331 -               kfree(sta);
332 -               return NULL;
333 +       if (local->ops->wake_tx_queue) {
334 +               int size = sizeof(struct txq_info) +
335 +                          ALIGN(hw->txq_data_size, sizeof(void *));
336 +
337 +               sta->txq = kcalloc(IEEE80211_NUM_TIDS, size, gfp);
338 +               if (!sta->txq)
339 +                       goto free;
340 +
341 +               for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
342 +                       struct txq_info *txq = sta->txq + i * size;
343 +                       ieee80211_init_tx_queue(sdata, sta, txq, i);
344 +               }
345         }
346  
347 +       if (sta_prepare_rate_control(local, sta, gfp))
348 +               goto free_txq;
349 +
350         for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
351                 /*
352                  * timer_to_tid must be initialized with identity mapping
353 @@ -346,7 +365,7 @@ struct sta_info *sta_info_alloc(struct i
354         if (sdata->vif.type == NL80211_IFTYPE_AP ||
355             sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
356                 struct ieee80211_supported_band *sband =
357 -                       local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
358 +                       hw->wiphy->bands[ieee80211_get_sdata_band(sdata)];
359                 u8 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
360                                 IEEE80211_HT_CAP_SM_PS_SHIFT;
361                 /*
362 @@ -371,6 +390,12 @@ struct sta_info *sta_info_alloc(struct i
363         sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
364  
365         return sta;
366 +
367 +free_txq:
368 +       kfree(sta->txq);
369 +free:
370 +       kfree(sta);
371 +       return NULL;
372  }
373  
374  static int sta_info_insert_check(struct sta_info *sta)
375 --- a/net/mac80211/sta_info.h
376 +++ b/net/mac80211/sta_info.h
377 @@ -368,6 +368,7 @@ struct sta_info {
378         struct sk_buff_head ps_tx_buf[IEEE80211_NUM_ACS];
379         struct sk_buff_head tx_filtered[IEEE80211_NUM_ACS];
380         unsigned long driver_buffered_tids;
381 +       struct txq_info *txq;
382  
383         /* Updated from RX path only, no locking requirements */
384         unsigned long rx_packets;
385 --- a/net/mac80211/trace.h
386 +++ b/net/mac80211/trace.h
387 @@ -2312,6 +2312,40 @@ TRACE_EVENT(drv_tdls_recv_channel_switch
388         )
389  );
390  
391 +DEFINE_EVENT(local_sdata_evt, drv_wake_vif_tx_queue,
392 +       TP_PROTO(struct ieee80211_local *local,
393 +                struct ieee80211_sub_if_data *sdata),
394 +       TP_ARGS(local, sdata)
395 +);
396 +
397 +TRACE_EVENT(drv_wake_sta_tx_queue,
398 +       TP_PROTO(struct ieee80211_local *local,
399 +                struct ieee80211_sub_if_data *sdata,
400 +                struct ieee80211_sta *sta,
401 +                u8 tid),
402 +
403 +       TP_ARGS(local, sdata, sta, tid),
404 +
405 +       TP_STRUCT__entry(
406 +               LOCAL_ENTRY
407 +               VIF_ENTRY
408 +               STA_ENTRY
409 +               __field(u8, tid)
410 +       ),
411 +
412 +       TP_fast_assign(
413 +               LOCAL_ASSIGN;
414 +               VIF_ASSIGN;
415 +               STA_ASSIGN;
416 +               __entry->tid = tid;
417 +       ),
418 +
419 +       TP_printk(
420 +               LOCAL_PR_FMT  VIF_PR_FMT  STA_PR_FMT " tid: 0x%x",
421 +               LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG, __entry->tid
422 +       )
423 +);
424 +
425  #ifdef CPTCFG_MAC80211_MESSAGE_TRACING
426  #undef TRACE_SYSTEM
427  #define TRACE_SYSTEM mac80211_msg
428 --- a/net/mac80211/tx.c
429 +++ b/net/mac80211/tx.c
430 @@ -1201,13 +1201,76 @@ ieee80211_tx_prepare(struct ieee80211_su
431         return TX_CONTINUE;
432  }
433  
434 +static void ieee80211_drv_tx(struct ieee80211_local *local,
435 +                            struct ieee80211_vif *vif,
436 +                            struct ieee80211_sta *pubsta,
437 +                            struct sk_buff *skb)
438 +{
439 +       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
440 +       struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
441 +       struct ieee80211_tx_control control = {
442 +               .sta = pubsta
443 +       };
444 +       struct ieee80211_txq *txq = NULL;
445 +       struct txq_info *txqi;
446 +       u8 ac;
447 +
448 +       if (ieee80211_is_mgmt(hdr->frame_control) ||
449 +           ieee80211_is_ctl(hdr->frame_control))
450 +               goto tx_normal;
451 +
452 +       if (pubsta) {
453 +               u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
454 +               txq = pubsta->txq[tid];
455 +       } else if (vif) {
456 +               txq = vif->txq;
457 +       }
458 +
459 +       if (!txq)
460 +               goto tx_normal;
461 +
462 +       ac = txq->ac;
463 +       txqi = container_of(txq, struct txq_info, txq);
464 +       atomic_inc(&sdata->txqs_len[ac]);
465 +       if (atomic_read(&sdata->txqs_len[ac]) >= local->hw.txq_ac_max_pending)
466 +               netif_stop_subqueue(sdata->dev, ac);
467 +
468 +       skb_queue_tail(&txqi->queue, skb);
469 +       drv_wake_tx_queue(local, txqi);
470 +
471 +       return;
472 +
473 +tx_normal:
474 +       drv_tx(local, &control, skb);
475 +}
476 +
477 +struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
478 +                                    struct ieee80211_txq *txq)
479 +{
480 +       struct ieee80211_local *local = hw_to_local(hw);
481 +       struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->vif);
482 +       struct txq_info *txqi = container_of(txq, struct txq_info, txq);
483 +       struct sk_buff *skb;
484 +       u8 ac = txq->ac;
485 +
486 +       skb = skb_dequeue(&txqi->queue);
487 +       if (!skb)
488 +               return ERR_PTR(-EAGAIN);
489 +
490 +       atomic_dec(&sdata->txqs_len[ac]);
491 +       if (__netif_subqueue_stopped(sdata->dev, ac))
492 +               ieee80211_propagate_queue_wake(local, sdata->vif.hw_queue[ac]);
493 +
494 +       return skb;
495 +}
496 +EXPORT_SYMBOL(ieee80211_tx_dequeue);
497 +
498  static bool ieee80211_tx_frags(struct ieee80211_local *local,
499                                struct ieee80211_vif *vif,
500                                struct ieee80211_sta *sta,
501                                struct sk_buff_head *skbs,
502                                bool txpending)
503  {
504 -       struct ieee80211_tx_control control;
505         struct sk_buff *skb, *tmp;
506         unsigned long flags;
507  
508 @@ -1265,10 +1328,9 @@ static bool ieee80211_tx_frags(struct ie
509                 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
510  
511                 info->control.vif = vif;
512 -               control.sta = sta;
513  
514                 __skb_unlink(skb, skbs);
515 -               drv_tx(local, &control, skb);
516 +               ieee80211_drv_tx(local, vif, sta, skb);
517         }
518  
519         return true;
520 --- a/net/mac80211/util.c
521 +++ b/net/mac80211/util.c
522 @@ -308,6 +308,11 @@ void ieee80211_propagate_queue_wake(stru
523                 for (ac = 0; ac < n_acs; ac++) {
524                         int ac_queue = sdata->vif.hw_queue[ac];
525  
526 +                       if (local->ops->wake_tx_queue &&
527 +                           (atomic_read(&sdata->txqs_len[ac]) >
528 +                            local->hw.txq_ac_max_pending))
529 +                               continue;
530 +
531                         if (ac_queue == queue ||
532                             (sdata->vif.cab_queue == queue &&
533                              local->queue_stop_reasons[ac_queue] == 0 &&
534 @@ -3307,3 +3312,36 @@ u8 *ieee80211_add_wmm_info_ie(u8 *buf, u
535  
536         return buf;
537  }
538 +
539 +void ieee80211_init_tx_queue(struct ieee80211_sub_if_data *sdata,
540 +                            struct sta_info *sta,
541 +                            struct txq_info *txqi, int tid)
542 +{
543 +       skb_queue_head_init(&txqi->queue);
544 +       txqi->txq.vif = &sdata->vif;
545 +
546 +       if (sta) {
547 +               txqi->txq.sta = &sta->sta;
548 +               sta->sta.txq[tid] = &txqi->txq;
549 +               txqi->txq.ac = ieee802_1d_to_ac[tid & 7];
550 +       } else {
551 +               sdata->vif.txq = &txqi->txq;
552 +               txqi->txq.ac = IEEE80211_AC_BE;
553 +       }
554 +}
555 +
556 +void ieee80211_flush_tx_queue(struct ieee80211_local *local,
557 +                             struct ieee80211_txq *txq)
558 +{
559 +       struct txq_info *txqi = container_of(txq, struct txq_info, txq);
560 +       struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->vif);
561 +       struct sk_buff *skb;
562 +       int n = 0;
563 +
564 +       while ((skb = skb_dequeue(&txqi->queue)) != NULL) {
565 +               n++;
566 +               ieee80211_free_txskb(&local->hw, skb);
567 +       }
568 +
569 +       atomic_sub(n, &sdata->txqs_len[txq->ac]);
570 +}