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
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.
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.
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.
17 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
20 --- a/include/net/mac80211.h
21 +++ b/include/net/mac80211.h
27 + * DOC: mac80211 software tx queueing
29 + * mac80211 provides an optional intermediate queueing implementation designed
30 + * to allow the driver to keep hardware queues short and provide some fairness
31 + * between different stations/interfaces.
32 + * In this model, the driver pulls data frames from the mac80211 queue instead
33 + * of letting mac80211 push them via drv_tx().
34 + * Other frames (e.g. control or management) are still pushed using drv_tx().
36 + * Drivers indicate that they use this model by implementing the .wake_tx_queue
39 + * Intermediate queues (struct ieee80211_txq) are kept per-sta per-tid, with a
40 + * single per-vif queue for multicast data frames.
42 + * The driver is expected to initialize its private per-queue data for stations
43 + * and interfaces in the .add_interface and .sta_add ops.
45 + * The driver can't access the queue directly. To dequeue a frame, it calls
46 + * ieee80211_tx_dequeue(). Whenever mac80211 adds a new frame to a queue, it
47 + * calls the .wake_tx_queue driver op.
49 + * For AP powersave TIM handling, the driver only needs to indicate if it has
50 + * buffered packets in the driver specific data structures by calling
51 + * ieee80211_sta_set_buffered(). For frames buffered in the ieee80211_txq
52 + * struct, mac80211 sets the appropriate TIM PVB bits and calls
53 + * .release_buffered_frames().
54 + * In that callback the driver is therefore expected to release its own
55 + * buffered frames and afterwards also frames from the ieee80211_txq (obtained
56 + * via the usual ieee80211_tx_dequeue).
62 @@ -1246,6 +1279,7 @@ enum ieee80211_vif_flags {
63 * monitor interface (if that is requested.)
64 * @drv_priv: data area for driver use, will always be aligned to
66 + * @txq: the multicast data TX queue (if driver uses the TXQ abstraction)
68 struct ieee80211_vif {
69 enum nl80211_iftype type;
70 @@ -1257,6 +1291,8 @@ struct ieee80211_vif {
72 u8 hw_queue[IEEE80211_NUM_ACS];
74 + struct ieee80211_txq *txq;
76 struct ieee80211_chanctx_conf __rcu *chanctx_conf;
79 @@ -1501,6 +1537,7 @@ struct ieee80211_sta_rates {
80 * @tdls_initiator: indicates the STA is an initiator of the TDLS link. Only
81 * valid if the STA is a TDLS peer in the first place.
82 * @mfp: indicates whether the STA uses management frame protection or not.
83 + * @txq: per-TID data TX queues (if driver uses the TXQ abstraction)
85 struct ieee80211_sta {
86 u32 supp_rates[IEEE80211_NUM_BANDS];
87 @@ -1519,6 +1556,8 @@ struct ieee80211_sta {
91 + struct ieee80211_txq *txq[IEEE80211_NUM_TIDS];
94 u8 drv_priv[0] __aligned(sizeof(void *));
96 @@ -1547,6 +1586,27 @@ struct ieee80211_tx_control {
100 + * struct ieee80211_txq - Software intermediate tx queue
102 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
103 + * @sta: station table entry, %NULL for per-vif queue
104 + * @tid: the TID for this queue (unused for per-vif queue)
105 + * @ac: the AC for this queue
107 + * The driver can obtain packets from this queue by calling
108 + * ieee80211_tx_dequeue().
110 +struct ieee80211_txq {
111 + struct ieee80211_vif *vif;
112 + struct ieee80211_sta *sta;
117 + u8 drv_priv[0] __aligned(sizeof(void *));
121 * enum ieee80211_hw_flags - hardware flags
123 * These flags are used to indicate hardware capabilities to
124 @@ -1770,6 +1830,8 @@ enum ieee80211_hw_flags {
125 * within &struct ieee80211_sta.
126 * @chanctx_data_size: size (in bytes) of the drv_priv data area
127 * within &struct ieee80211_chanctx_conf.
128 + * @txq_data_size: size (in bytes) of the drv_priv data area
129 + * within @struct ieee80211_txq.
131 * @max_rates: maximum number of alternate rate retry stages the hw
133 @@ -1818,6 +1880,9 @@ enum ieee80211_hw_flags {
134 * @n_cipher_schemes: a size of an array of cipher schemes definitions.
135 * @cipher_schemes: a pointer to an array of cipher scheme definitions
138 + * @txq_ac_max_pending: maximum number of frames per AC pending in all txq
139 + * entries for a vif.
141 struct ieee80211_hw {
142 struct ieee80211_conf conf;
143 @@ -1830,6 +1895,7 @@ struct ieee80211_hw {
146 int chanctx_data_size;
149 u16 max_listen_interval;
151 @@ -1846,6 +1912,7 @@ struct ieee80211_hw {
154 const struct ieee80211_cipher_scheme *cipher_schemes;
155 + int txq_ac_max_pending;
159 @@ -3007,6 +3074,8 @@ enum ieee80211_reconfig_type {
160 * response template is provided, together with the location of the
161 * switch-timing IE within the template. The skb can only be used within
164 + * @wake_tx_queue: Called when new packets have been added to the queue.
166 struct ieee80211_ops {
167 void (*tx)(struct ieee80211_hw *hw,
168 @@ -3238,6 +3307,9 @@ struct ieee80211_ops {
169 void (*tdls_recv_channel_switch)(struct ieee80211_hw *hw,
170 struct ieee80211_vif *vif,
171 struct ieee80211_tdls_ch_sw_params *params);
173 + void (*wake_tx_queue)(struct ieee80211_hw *hw,
174 + struct ieee80211_txq *txq);
178 @@ -5249,4 +5321,15 @@ void ieee80211_unreserve_tid(struct ieee
180 size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
181 const u8 *ids, int n_ids, size_t offset);
184 + * ieee80211_tx_dequeue - dequeue a packet from a software tx queue
186 + * @hw: pointer as obtained from ieee80211_alloc_hw()
187 + * @txq: pointer obtained from station or virtual interface
189 + * Returns the skb if successful, %NULL if no frame was available.
191 +struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
192 + struct ieee80211_txq *txq);
193 #endif /* MAC80211_H */
194 --- a/net/mac80211/driver-ops.h
195 +++ b/net/mac80211/driver-ops.h
196 @@ -1367,4 +1367,16 @@ drv_tdls_recv_channel_switch(struct ieee
197 trace_drv_return_void(local);
200 +static inline void drv_wake_tx_queue(struct ieee80211_local *local,
201 + struct txq_info *txq)
203 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->txq.vif);
205 + if (!check_sdata_in_driver(sdata))
208 + trace_drv_wake_tx_queue(local, sdata, txq);
209 + local->ops->wake_tx_queue(&local->hw, &txq->txq);
212 #endif /* __MAC80211_DRIVER_OPS */
213 --- a/net/mac80211/ieee80211_i.h
214 +++ b/net/mac80211/ieee80211_i.h
215 @@ -809,6 +809,19 @@ struct mac80211_qos_map {
216 struct rcu_head rcu_head;
219 +enum txq_info_flags {
220 + IEEE80211_TXQ_STOP,
221 + IEEE80211_TXQ_AMPDU,
225 + struct sk_buff_head queue;
226 + unsigned long flags;
229 + struct ieee80211_txq txq;
232 struct ieee80211_sub_if_data {
233 struct list_head list;
235 @@ -853,6 +866,7 @@ struct ieee80211_sub_if_data {
236 bool control_port_no_encrypt;
237 int encrypt_headroom;
239 + atomic_t txqs_len[IEEE80211_NUM_ACS];
240 struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS];
241 struct mac80211_qos_map __rcu *qos_map;
243 @@ -1453,6 +1467,10 @@ static inline struct ieee80211_local *hw
244 return container_of(hw, struct ieee80211_local, hw);
247 +static inline struct txq_info *to_txq_info(struct ieee80211_txq *txq)
249 + return container_of(txq, struct txq_info, txq);
252 static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
254 @@ -1905,6 +1923,9 @@ static inline bool ieee80211_can_run_wor
258 +void ieee80211_init_tx_queue(struct ieee80211_sub_if_data *sdata,
259 + struct sta_info *sta,
260 + struct txq_info *txq, int tid);
261 void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
262 u16 transaction, u16 auth_alg, u16 status,
263 const u8 *extra, size_t extra_len, const u8 *bssid,
264 --- a/net/mac80211/iface.c
265 +++ b/net/mac80211/iface.c
266 @@ -969,6 +969,13 @@ static void ieee80211_do_stop(struct iee
268 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
270 + if (sdata->vif.txq) {
271 + struct txq_info *txqi = to_txq_info(sdata->vif.txq);
273 + ieee80211_purge_tx_queue(&local->hw, &txqi->queue);
274 + atomic_set(&sdata->txqs_len[txqi->txq.ac], 0);
277 if (local->open_count == 0)
278 ieee80211_clear_tx_pending(local);
280 @@ -1674,6 +1681,7 @@ int ieee80211_if_add(struct ieee80211_lo
282 struct net_device *ndev = NULL;
283 struct ieee80211_sub_if_data *sdata = NULL;
284 + struct txq_info *txqi;
288 @@ -1693,10 +1701,18 @@ int ieee80211_if_add(struct ieee80211_lo
289 ieee80211_assign_perm_addr(local, wdev->address, type);
290 memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
292 + int size = ALIGN(sizeof(*sdata) + local->hw.vif_data_size,
296 + if (local->ops->wake_tx_queue)
297 + txq_size += sizeof(struct txq_info) +
298 + local->hw.txq_data_size;
300 if (local->hw.queues >= IEEE80211_NUM_ACS)
301 txqs = IEEE80211_NUM_ACS;
303 - ndev = alloc_netdev_mqs(sizeof(*sdata) + local->hw.vif_data_size,
304 + ndev = alloc_netdev_mqs(size + txq_size,
305 name, NET_NAME_UNKNOWN,
306 ieee80211_if_setup, txqs, 1);
308 @@ -1731,6 +1747,11 @@ int ieee80211_if_add(struct ieee80211_lo
309 memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
310 memcpy(sdata->name, ndev->name, IFNAMSIZ);
313 + txqi = netdev_priv(ndev) + size;
314 + ieee80211_init_tx_queue(sdata, NULL, txqi, 0);
320 --- a/net/mac80211/main.c
321 +++ b/net/mac80211/main.c
322 @@ -1019,6 +1019,9 @@ int ieee80211_register_hw(struct ieee802
324 local->dynamic_ps_forced_timeout = -1;
326 + if (!local->hw.txq_ac_max_pending)
327 + local->hw.txq_ac_max_pending = 64;
329 result = ieee80211_wep_init(local);
331 wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
332 --- a/net/mac80211/sta_info.c
333 +++ b/net/mac80211/sta_info.c
334 @@ -118,6 +118,16 @@ static void __cleanup_single_sta(struct
335 atomic_dec(&ps->num_sta_ps);
338 + if (sta->sta.txq[0]) {
339 + for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
340 + struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
341 + int n = skb_queue_len(&txqi->queue);
343 + ieee80211_purge_tx_queue(&local->hw, &txqi->queue);
344 + atomic_sub(n, &sdata->txqs_len[txqi->txq.ac]);
348 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
349 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
350 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
351 @@ -234,6 +244,8 @@ void sta_info_free(struct ieee80211_loca
353 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
355 + if (sta->sta.txq[0])
356 + kfree(to_txq_info(sta->sta.txq[0]));
357 kfree(rcu_dereference_raw(sta->sta.rates));
360 @@ -285,11 +297,12 @@ struct sta_info *sta_info_alloc(struct i
361 const u8 *addr, gfp_t gfp)
363 struct ieee80211_local *local = sdata->local;
364 + struct ieee80211_hw *hw = &local->hw;
365 struct sta_info *sta;
366 struct timespec uptime;
369 - sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
370 + sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
374 @@ -321,11 +334,25 @@ struct sta_info *sta_info_alloc(struct i
375 for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
376 ewma_init(&sta->chain_signal_avg[i], 1024, 8);
378 - if (sta_prepare_rate_control(local, sta, gfp)) {
381 + if (local->ops->wake_tx_queue) {
383 + int size = sizeof(struct txq_info) +
384 + ALIGN(hw->txq_data_size, sizeof(void *));
386 + txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
390 + for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
391 + struct txq_info *txq = txq_data + i * size;
393 + ieee80211_init_tx_queue(sdata, sta, txq, i);
397 + if (sta_prepare_rate_control(local, sta, gfp))
400 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
402 * timer_to_tid must be initialized with identity mapping
403 @@ -346,7 +373,7 @@ struct sta_info *sta_info_alloc(struct i
404 if (sdata->vif.type == NL80211_IFTYPE_AP ||
405 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
406 struct ieee80211_supported_band *sband =
407 - local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
408 + hw->wiphy->bands[ieee80211_get_sdata_band(sdata)];
409 u8 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
410 IEEE80211_HT_CAP_SM_PS_SHIFT;
412 @@ -371,6 +398,13 @@ struct sta_info *sta_info_alloc(struct i
413 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
418 + if (sta->sta.txq[0])
419 + kfree(to_txq_info(sta->sta.txq[0]));
425 static int sta_info_insert_check(struct sta_info *sta)
426 @@ -640,6 +674,8 @@ static void __sta_info_recalc_tim(struct
429 sta->driver_buffered_tids & tids;
431 + sta->txq_buffered_tids & tids;
435 @@ -1071,7 +1107,7 @@ void ieee80211_sta_ps_deliver_wakeup(str
436 struct ieee80211_sub_if_data *sdata = sta->sdata;
437 struct ieee80211_local *local = sdata->local;
438 struct sk_buff_head pending;
439 - int filtered = 0, buffered = 0, ac;
440 + int filtered = 0, buffered = 0, ac, i;
444 @@ -1090,10 +1126,22 @@ void ieee80211_sta_ps_deliver_wakeup(str
446 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
447 sta->driver_buffered_tids = 0;
448 + sta->txq_buffered_tids = 0;
450 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
451 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
453 + if (sta->sta.txq[0]) {
454 + for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
455 + struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
457 + if (!skb_queue_len(&txqi->queue))
460 + drv_wake_tx_queue(local, txqi);
464 skb_queue_head_init(&pending);
466 /* sync with ieee80211_tx_h_unicast_ps_buf */
467 @@ -1275,8 +1323,10 @@ ieee80211_sta_ps_deliver_response(struct
468 /* if we already have frames from software, then we can't also
469 * release from hardware queues
471 - if (skb_queue_empty(&frames))
472 + if (skb_queue_empty(&frames)) {
473 driver_release_tids |= sta->driver_buffered_tids & tids;
474 + driver_release_tids |= sta->txq_buffered_tids & tids;
477 if (driver_release_tids) {
478 /* If the driver has data on more than one TID then
479 @@ -1447,6 +1497,9 @@ ieee80211_sta_ps_deliver_response(struct
481 sta_info_recalc_tim(sta);
483 + unsigned long tids = sta->txq_buffered_tids & driver_release_tids;
487 * We need to release a frame that is buffered somewhere in the
488 * driver ... it'll have to handle that.
489 @@ -1466,8 +1519,22 @@ ieee80211_sta_ps_deliver_response(struct
490 * that the TID(s) became empty before returning here from the
492 * Either way, however, when the driver tells us that the TID(s)
493 - * became empty we'll do the TIM recalculation.
494 + * became empty or we find that a txq became empty, we'll do the
495 + * TIM recalculation.
498 + if (!sta->sta.txq[0])
501 + for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
502 + struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
504 + if (!(tids & BIT(tid)) || skb_queue_len(&txqi->queue))
507 + sta_info_recalc_tim(sta);
513 --- a/net/mac80211/sta_info.h
514 +++ b/net/mac80211/sta_info.h
515 @@ -274,6 +274,7 @@ struct sta_ampdu_mlme {
516 * entered power saving state, these are also delivered to
517 * the station when it leaves powersave or polls for frames
518 * @driver_buffered_tids: bitmap of TIDs the driver has data buffered on
519 + * @txq_buffered_tids: bitmap of TIDs that mac80211 has txq data buffered on
520 * @rx_packets: Number of MSDUs received from this STA
521 * @rx_bytes: Number of bytes received from this STA
522 * @last_rx: time (in jiffies) when last frame was received from this STA
523 @@ -368,6 +369,7 @@ struct sta_info {
524 struct sk_buff_head ps_tx_buf[IEEE80211_NUM_ACS];
525 struct sk_buff_head tx_filtered[IEEE80211_NUM_ACS];
526 unsigned long driver_buffered_tids;
527 + unsigned long txq_buffered_tids;
529 /* Updated from RX path only, no locking requirements */
530 unsigned long rx_packets;
531 --- a/net/mac80211/trace.h
532 +++ b/net/mac80211/trace.h
533 @@ -2312,6 +2312,37 @@ TRACE_EVENT(drv_tdls_recv_channel_switch
537 +TRACE_EVENT(drv_wake_tx_queue,
538 + TP_PROTO(struct ieee80211_local *local,
539 + struct ieee80211_sub_if_data *sdata,
540 + struct txq_info *txq),
542 + TP_ARGS(local, sdata, txq),
553 + struct ieee80211_sta *sta = txq->txq.sta;
558 + __entry->ac = txq->txq.ac;
559 + __entry->tid = txq->txq.tid;
563 + LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT " ac:%d tid:%d",
564 + LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG, __entry->ac, __entry->tid
568 #ifdef CPTCFG_MAC80211_MESSAGE_TRACING
570 #define TRACE_SYSTEM mac80211_msg
571 --- a/net/mac80211/tx.c
572 +++ b/net/mac80211/tx.c
573 @@ -776,12 +776,22 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
577 +static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid)
579 + u16 *seq = &sta->tid_seq[tid];
580 + __le16 ret = cpu_to_le16(*seq);
582 + /* Increase the sequence number. */
583 + *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
588 static ieee80211_tx_result debug_noinline
589 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
591 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
592 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
597 @@ -832,13 +842,10 @@ ieee80211_tx_h_sequence(struct ieee80211
599 qc = ieee80211_get_qos_ctl(hdr);
600 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
601 - seq = &tx->sta->tid_seq[tid];
602 tx->sta->tx_msdu[tid]++;
604 - hdr->seq_ctrl = cpu_to_le16(*seq);
606 - /* Increase the sequence number. */
607 - *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
608 + if (!tx->sta->sta.txq[0])
609 + hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid);
613 @@ -1067,7 +1074,7 @@ static bool ieee80211_tx_prep_agg(struct
614 * nothing -- this aggregation session is being started
615 * but that might still fail with the driver
618 + } else if (!tx->sta->sta.txq[tid]) {
619 spin_lock(&tx->sta->lock);
621 * Need to re-check now, because we may get here
622 @@ -1201,13 +1208,102 @@ ieee80211_tx_prepare(struct ieee80211_su
626 +static void ieee80211_drv_tx(struct ieee80211_local *local,
627 + struct ieee80211_vif *vif,
628 + struct ieee80211_sta *pubsta,
629 + struct sk_buff *skb)
631 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
632 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
633 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
634 + struct ieee80211_tx_control control = {
637 + struct ieee80211_txq *txq = NULL;
638 + struct txq_info *txqi;
641 + if (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE)
644 + if (!ieee80211_is_data(hdr->frame_control))
648 + u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
650 + txq = pubsta->txq[tid];
659 + txqi = to_txq_info(txq);
660 + atomic_inc(&sdata->txqs_len[ac]);
661 + if (atomic_read(&sdata->txqs_len[ac]) >= local->hw.txq_ac_max_pending)
662 + netif_stop_subqueue(sdata->dev, ac);
664 + skb_queue_tail(&txqi->queue, skb);
665 + drv_wake_tx_queue(local, txqi);
670 + drv_tx(local, &control, skb);
673 +struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
674 + struct ieee80211_txq *txq)
676 + struct ieee80211_local *local = hw_to_local(hw);
677 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->vif);
678 + struct txq_info *txqi = container_of(txq, struct txq_info, txq);
679 + struct ieee80211_hdr *hdr;
680 + struct sk_buff *skb = NULL;
683 + spin_lock_bh(&txqi->queue.lock);
685 + if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags))
688 + skb = __skb_dequeue(&txqi->queue);
692 + atomic_dec(&sdata->txqs_len[ac]);
693 + if (__netif_subqueue_stopped(sdata->dev, ac))
694 + ieee80211_propagate_queue_wake(local, sdata->vif.hw_queue[ac]);
696 + hdr = (struct ieee80211_hdr *)skb->data;
697 + if (txq->sta && ieee80211_is_data_qos(hdr->frame_control)) {
698 + struct sta_info *sta = container_of(txq->sta, struct sta_info,
700 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
702 + hdr->seq_ctrl = ieee80211_tx_next_seq(sta, txq->tid);
703 + if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags))
704 + info->flags |= IEEE80211_TX_CTL_AMPDU;
706 + info->flags &= ~IEEE80211_TX_CTL_AMPDU;
710 + spin_unlock_bh(&txqi->queue.lock);
714 +EXPORT_SYMBOL(ieee80211_tx_dequeue);
716 static bool ieee80211_tx_frags(struct ieee80211_local *local,
717 struct ieee80211_vif *vif,
718 struct ieee80211_sta *sta,
719 struct sk_buff_head *skbs,
722 - struct ieee80211_tx_control control;
723 struct sk_buff *skb, *tmp;
726 @@ -1265,10 +1361,9 @@ static bool ieee80211_tx_frags(struct ie
727 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
729 info->control.vif = vif;
732 __skb_unlink(skb, skbs);
733 - drv_tx(local, &control, skb);
734 + ieee80211_drv_tx(local, vif, sta, skb);
738 --- a/net/mac80211/util.c
739 +++ b/net/mac80211/util.c
740 @@ -308,6 +308,11 @@ void ieee80211_propagate_queue_wake(stru
741 for (ac = 0; ac < n_acs; ac++) {
742 int ac_queue = sdata->vif.hw_queue[ac];
744 + if (local->ops->wake_tx_queue &&
745 + (atomic_read(&sdata->txqs_len[ac]) >
746 + local->hw.txq_ac_max_pending))
749 if (ac_queue == queue ||
750 (sdata->vif.cab_queue == queue &&
751 local->queue_stop_reasons[ac_queue] == 0 &&
752 @@ -3307,3 +3312,20 @@ u8 *ieee80211_add_wmm_info_ie(u8 *buf, u
757 +void ieee80211_init_tx_queue(struct ieee80211_sub_if_data *sdata,
758 + struct sta_info *sta,
759 + struct txq_info *txqi, int tid)
761 + skb_queue_head_init(&txqi->queue);
762 + txqi->txq.vif = &sdata->vif;
765 + txqi->txq.sta = &sta->sta;
766 + sta->sta.txq[tid] = &txqi->txq;
767 + txqi->txq.ac = ieee802_1d_to_ac[tid & 7];
769 + sdata->vif.txq = &txqi->txq;
770 + txqi->txq.ac = IEEE80211_AC_BE;
773 --- a/net/mac80211/rx.c
774 +++ b/net/mac80211/rx.c
775 @@ -1176,6 +1176,7 @@ static void sta_ps_start(struct sta_info
776 struct ieee80211_sub_if_data *sdata = sta->sdata;
777 struct ieee80211_local *local = sdata->local;
781 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
782 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
783 @@ -1189,6 +1190,18 @@ static void sta_ps_start(struct sta_info
784 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
785 ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
786 sta->sta.addr, sta->sta.aid);
788 + if (!sta->sta.txq[0])
791 + for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
792 + struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
794 + if (!skb_queue_len(&txqi->queue))
795 + set_bit(tid, &sta->txq_buffered_tids);
797 + clear_bit(tid, &sta->txq_buffered_tids);
801 static void sta_ps_end(struct sta_info *sta)
802 --- a/net/mac80211/agg-tx.c
803 +++ b/net/mac80211/agg-tx.c
804 @@ -188,6 +188,43 @@ ieee80211_wake_queue_agg(struct ieee8021
805 __release(agg_queue);
809 +ieee80211_agg_stop_txq(struct sta_info *sta, int tid)
811 + struct ieee80211_txq *txq = sta->sta.txq[tid];
812 + struct txq_info *txqi;
817 + txqi = to_txq_info(txq);
819 + /* Lock here to protect against further seqno updates on dequeue */
820 + spin_lock_bh(&txqi->queue.lock);
821 + set_bit(IEEE80211_TXQ_STOP, &txqi->flags);
822 + spin_unlock_bh(&txqi->queue.lock);
826 +ieee80211_agg_start_txq(struct sta_info *sta, int tid, bool enable)
828 + struct ieee80211_txq *txq = sta->sta.txq[tid];
829 + struct txq_info *txqi;
834 + txqi = to_txq_info(txq);
837 + set_bit(IEEE80211_TXQ_AMPDU, &txqi->flags);
839 + clear_bit(IEEE80211_TXQ_AMPDU, &txqi->flags);
841 + clear_bit(IEEE80211_TXQ_STOP, &txqi->flags);
842 + drv_wake_tx_queue(sta->sdata->local, txqi);
846 * splice packets from the STA's pending to the local pending,
847 * requires a call to ieee80211_agg_splice_finish later
848 @@ -247,6 +284,7 @@ static void ieee80211_remove_tid_tx(stru
849 ieee80211_assign_tid_tx(sta, tid, NULL);
851 ieee80211_agg_splice_finish(sta->sdata, tid);
852 + ieee80211_agg_start_txq(sta, tid, false);
854 kfree_rcu(tid_tx, rcu_head);
856 @@ -418,6 +456,8 @@ void ieee80211_tx_ba_session_handle_star
858 clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
860 + ieee80211_agg_stop_txq(sta, tid);
863 * Make sure no packets are being processed. This ensures that
864 * we have a valid starting sequence number and that in-flight
865 @@ -440,6 +480,8 @@ void ieee80211_tx_ba_session_handle_star
866 ieee80211_agg_splice_finish(sdata, tid);
867 spin_unlock_bh(&sta->lock);
869 + ieee80211_agg_start_txq(sta, tid, false);
871 kfree_rcu(tid_tx, rcu_head);
874 @@ -666,6 +708,8 @@ static void ieee80211_agg_tx_operational
875 ieee80211_agg_splice_finish(sta->sdata, tid);
877 spin_unlock_bh(&sta->lock);
879 + ieee80211_agg_start_txq(sta, tid, true);
882 void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)