Skip to content

Commit ba8c3d6

Browse files
Felix Fietkaujmberg-intel
Felix Fietkau
authored andcommitted
mac80211: add an intermediate software queue implementation
This allows drivers to request per-vif and per-sta-tid queues from which they can pull frames. This makes it easier to keep the hardware queues short, and to improve fairness between clients and vifs. The task of scheduling packet transmission is left up to the driver - queueing is controlled by mac80211. Drivers can only dequeue packets by calling ieee80211_tx_dequeue. This makes it possible to add active queue management later without changing drivers using this code. This can also be used as a starting point to implement A-MSDU aggregation in a way that does not add artificially induced latency. Signed-off-by: Felix Fietkau <[email protected]> [resolved minor context conflict, minor changes, endian annotations] Signed-off-by: Johannes Berg <[email protected]>
1 parent cef2fc1 commit ba8c3d6

File tree

12 files changed

+433
-19
lines changed

12 files changed

+433
-19
lines changed

include/net/mac80211.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,39 @@
8484
*
8585
*/
8686

87+
/**
88+
* DOC: mac80211 software tx queueing
89+
*
90+
* mac80211 provides an optional intermediate queueing implementation designed
91+
* to allow the driver to keep hardware queues short and provide some fairness
92+
* between different stations/interfaces.
93+
* In this model, the driver pulls data frames from the mac80211 queue instead
94+
* of letting mac80211 push them via drv_tx().
95+
* Other frames (e.g. control or management) are still pushed using drv_tx().
96+
*
97+
* Drivers indicate that they use this model by implementing the .wake_tx_queue
98+
* driver operation.
99+
*
100+
* Intermediate queues (struct ieee80211_txq) are kept per-sta per-tid, with a
101+
* single per-vif queue for multicast data frames.
102+
*
103+
* The driver is expected to initialize its private per-queue data for stations
104+
* and interfaces in the .add_interface and .sta_add ops.
105+
*
106+
* The driver can't access the queue directly. To dequeue a frame, it calls
107+
* ieee80211_tx_dequeue(). Whenever mac80211 adds a new frame to a queue, it
108+
* calls the .wake_tx_queue driver op.
109+
*
110+
* For AP powersave TIM handling, the driver only needs to indicate if it has
111+
* buffered packets in the driver specific data structures by calling
112+
* ieee80211_sta_set_buffered(). For frames buffered in the ieee80211_txq
113+
* struct, mac80211 sets the appropriate TIM PVB bits and calls
114+
* .release_buffered_frames().
115+
* In that callback the driver is therefore expected to release its own
116+
* buffered frames and afterwards also frames from the ieee80211_txq (obtained
117+
* via the usual ieee80211_tx_dequeue).
118+
*/
119+
87120
struct device;
88121

89122
/**
@@ -1306,6 +1339,7 @@ enum ieee80211_vif_flags {
13061339
* monitor interface (if that is requested.)
13071340
* @drv_priv: data area for driver use, will always be aligned to
13081341
* sizeof(void *).
1342+
* @txq: the multicast data TX queue (if driver uses the TXQ abstraction)
13091343
*/
13101344
struct ieee80211_vif {
13111345
enum nl80211_iftype type;
@@ -1317,6 +1351,8 @@ struct ieee80211_vif {
13171351
u8 cab_queue;
13181352
u8 hw_queue[IEEE80211_NUM_ACS];
13191353

1354+
struct ieee80211_txq *txq;
1355+
13201356
struct ieee80211_chanctx_conf __rcu *chanctx_conf;
13211357

13221358
u32 driver_flags;
@@ -1575,6 +1611,7 @@ struct ieee80211_sta_rates {
15751611
* @tdls_initiator: indicates the STA is an initiator of the TDLS link. Only
15761612
* valid if the STA is a TDLS peer in the first place.
15771613
* @mfp: indicates whether the STA uses management frame protection or not.
1614+
* @txq: per-TID data TX queues (if driver uses the TXQ abstraction)
15781615
*/
15791616
struct ieee80211_sta {
15801617
u32 supp_rates[IEEE80211_NUM_BANDS];
@@ -1593,6 +1630,8 @@ struct ieee80211_sta {
15931630
bool tdls_initiator;
15941631
bool mfp;
15951632

1633+
struct ieee80211_txq *txq[IEEE80211_NUM_TIDS];
1634+
15961635
/* must be last */
15971636
u8 drv_priv[0] __aligned(sizeof(void *));
15981637
};
@@ -1620,6 +1659,27 @@ struct ieee80211_tx_control {
16201659
struct ieee80211_sta *sta;
16211660
};
16221661

1662+
/**
1663+
* struct ieee80211_txq - Software intermediate tx queue
1664+
*
1665+
* @vif: &struct ieee80211_vif pointer from the add_interface callback.
1666+
* @sta: station table entry, %NULL for per-vif queue
1667+
* @tid: the TID for this queue (unused for per-vif queue)
1668+
* @ac: the AC for this queue
1669+
*
1670+
* The driver can obtain packets from this queue by calling
1671+
* ieee80211_tx_dequeue().
1672+
*/
1673+
struct ieee80211_txq {
1674+
struct ieee80211_vif *vif;
1675+
struct ieee80211_sta *sta;
1676+
u8 tid;
1677+
u8 ac;
1678+
1679+
/* must be last */
1680+
u8 drv_priv[0] __aligned(sizeof(void *));
1681+
};
1682+
16231683
/**
16241684
* enum ieee80211_hw_flags - hardware flags
16251685
*
@@ -1844,6 +1904,8 @@ enum ieee80211_hw_flags {
18441904
* within &struct ieee80211_sta.
18451905
* @chanctx_data_size: size (in bytes) of the drv_priv data area
18461906
* within &struct ieee80211_chanctx_conf.
1907+
* @txq_data_size: size (in bytes) of the drv_priv data area
1908+
* within @struct ieee80211_txq.
18471909
*
18481910
* @max_rates: maximum number of alternate rate retry stages the hw
18491911
* can handle.
@@ -1892,6 +1954,9 @@ enum ieee80211_hw_flags {
18921954
* @n_cipher_schemes: a size of an array of cipher schemes definitions.
18931955
* @cipher_schemes: a pointer to an array of cipher scheme definitions
18941956
* supported by HW.
1957+
*
1958+
* @txq_ac_max_pending: maximum number of frames per AC pending in all txq
1959+
* entries for a vif.
18951960
*/
18961961
struct ieee80211_hw {
18971962
struct ieee80211_conf conf;
@@ -1904,6 +1969,7 @@ struct ieee80211_hw {
19041969
int vif_data_size;
19051970
int sta_data_size;
19061971
int chanctx_data_size;
1972+
int txq_data_size;
19071973
u16 queues;
19081974
u16 max_listen_interval;
19091975
s8 max_signal;
@@ -1920,6 +1986,7 @@ struct ieee80211_hw {
19201986
u8 uapsd_max_sp_len;
19211987
u8 n_cipher_schemes;
19221988
const struct ieee80211_cipher_scheme *cipher_schemes;
1989+
int txq_ac_max_pending;
19231990
};
19241991

19251992
/**
@@ -3082,6 +3149,8 @@ enum ieee80211_reconfig_type {
30823149
* response template is provided, together with the location of the
30833150
* switch-timing IE within the template. The skb can only be used within
30843151
* the function call.
3152+
*
3153+
* @wake_tx_queue: Called when new packets have been added to the queue.
30853154
*/
30863155
struct ieee80211_ops {
30873156
void (*tx)(struct ieee80211_hw *hw,
@@ -3313,6 +3382,9 @@ struct ieee80211_ops {
33133382
void (*tdls_recv_channel_switch)(struct ieee80211_hw *hw,
33143383
struct ieee80211_vif *vif,
33153384
struct ieee80211_tdls_ch_sw_params *params);
3385+
3386+
void (*wake_tx_queue)(struct ieee80211_hw *hw,
3387+
struct ieee80211_txq *txq);
33163388
};
33173389

33183390
/**
@@ -5334,4 +5406,15 @@ void ieee80211_unreserve_tid(struct ieee80211_sta *sta, u8 tid);
53345406
*/
53355407
size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
53365408
const u8 *ids, int n_ids, size_t offset);
5409+
5410+
/**
5411+
* ieee80211_tx_dequeue - dequeue a packet from a software tx queue
5412+
*
5413+
* @hw: pointer as obtained from ieee80211_alloc_hw()
5414+
* @txq: pointer obtained from station or virtual interface
5415+
*
5416+
* Returns the skb if successful, %NULL if no frame was available.
5417+
*/
5418+
struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
5419+
struct ieee80211_txq *txq);
53375420
#endif /* MAC80211_H */

net/mac80211/agg-tx.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,43 @@ ieee80211_wake_queue_agg(struct ieee80211_sub_if_data *sdata, int tid)
188188
__release(agg_queue);
189189
}
190190

191+
static void
192+
ieee80211_agg_stop_txq(struct sta_info *sta, int tid)
193+
{
194+
struct ieee80211_txq *txq = sta->sta.txq[tid];
195+
struct txq_info *txqi;
196+
197+
if (!txq)
198+
return;
199+
200+
txqi = to_txq_info(txq);
201+
202+
/* Lock here to protect against further seqno updates on dequeue */
203+
spin_lock_bh(&txqi->queue.lock);
204+
set_bit(IEEE80211_TXQ_STOP, &txqi->flags);
205+
spin_unlock_bh(&txqi->queue.lock);
206+
}
207+
208+
static void
209+
ieee80211_agg_start_txq(struct sta_info *sta, int tid, bool enable)
210+
{
211+
struct ieee80211_txq *txq = sta->sta.txq[tid];
212+
struct txq_info *txqi;
213+
214+
if (!txq)
215+
return;
216+
217+
txqi = to_txq_info(txq);
218+
219+
if (enable)
220+
set_bit(IEEE80211_TXQ_AMPDU, &txqi->flags);
221+
else
222+
clear_bit(IEEE80211_TXQ_AMPDU, &txqi->flags);
223+
224+
clear_bit(IEEE80211_TXQ_STOP, &txqi->flags);
225+
drv_wake_tx_queue(sta->sdata->local, txqi);
226+
}
227+
191228
/*
192229
* splice packets from the STA's pending to the local pending,
193230
* requires a call to ieee80211_agg_splice_finish later
@@ -247,6 +284,7 @@ static void ieee80211_remove_tid_tx(struct sta_info *sta, int tid)
247284
ieee80211_assign_tid_tx(sta, tid, NULL);
248285

249286
ieee80211_agg_splice_finish(sta->sdata, tid);
287+
ieee80211_agg_start_txq(sta, tid, false);
250288

251289
kfree_rcu(tid_tx, rcu_head);
252290
}
@@ -418,6 +456,8 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
418456
*/
419457
clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
420458

459+
ieee80211_agg_stop_txq(sta, tid);
460+
421461
/*
422462
* Make sure no packets are being processed. This ensures that
423463
* we have a valid starting sequence number and that in-flight
@@ -440,6 +480,8 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
440480
ieee80211_agg_splice_finish(sdata, tid);
441481
spin_unlock_bh(&sta->lock);
442482

483+
ieee80211_agg_start_txq(sta, tid, false);
484+
443485
kfree_rcu(tid_tx, rcu_head);
444486
return;
445487
}
@@ -669,6 +711,8 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
669711
ieee80211_agg_splice_finish(sta->sdata, tid);
670712

671713
spin_unlock_bh(&sta->lock);
714+
715+
ieee80211_agg_start_txq(sta, tid, true);
672716
}
673717

674718
void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)

net/mac80211/driver-ops.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,4 +1367,16 @@ drv_tdls_recv_channel_switch(struct ieee80211_local *local,
13671367
trace_drv_return_void(local);
13681368
}
13691369

1370+
static inline void drv_wake_tx_queue(struct ieee80211_local *local,
1371+
struct txq_info *txq)
1372+
{
1373+
struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->txq.vif);
1374+
1375+
if (!check_sdata_in_driver(sdata))
1376+
return;
1377+
1378+
trace_drv_wake_tx_queue(local, sdata, txq);
1379+
local->ops->wake_tx_queue(&local->hw, &txq->txq);
1380+
}
1381+
13701382
#endif /* __MAC80211_DRIVER_OPS */

net/mac80211/ieee80211_i.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,19 @@ struct mac80211_qos_map {
811811
struct rcu_head rcu_head;
812812
};
813813

814+
enum txq_info_flags {
815+
IEEE80211_TXQ_STOP,
816+
IEEE80211_TXQ_AMPDU,
817+
};
818+
819+
struct txq_info {
820+
struct sk_buff_head queue;
821+
unsigned long flags;
822+
823+
/* keep last! */
824+
struct ieee80211_txq txq;
825+
};
826+
814827
struct ieee80211_sub_if_data {
815828
struct list_head list;
816829

@@ -853,6 +866,7 @@ struct ieee80211_sub_if_data {
853866
bool control_port_no_encrypt;
854867
int encrypt_headroom;
855868

869+
atomic_t txqs_len[IEEE80211_NUM_ACS];
856870
struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS];
857871
struct mac80211_qos_map __rcu *qos_map;
858872

@@ -1450,6 +1464,10 @@ static inline struct ieee80211_local *hw_to_local(
14501464
return container_of(hw, struct ieee80211_local, hw);
14511465
}
14521466

1467+
static inline struct txq_info *to_txq_info(struct ieee80211_txq *txq)
1468+
{
1469+
return container_of(txq, struct txq_info, txq);
1470+
}
14531471

14541472
static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
14551473
{
@@ -1906,6 +1924,9 @@ static inline bool ieee80211_can_run_worker(struct ieee80211_local *local)
19061924
return true;
19071925
}
19081926

1927+
void ieee80211_init_tx_queue(struct ieee80211_sub_if_data *sdata,
1928+
struct sta_info *sta,
1929+
struct txq_info *txq, int tid);
19091930
void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
19101931
u16 transaction, u16 auth_alg, u16 status,
19111932
const u8 *extra, size_t extra_len, const u8 *bssid,

net/mac80211/iface.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,13 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
969969
}
970970
spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
971971

972+
if (sdata->vif.txq) {
973+
struct txq_info *txqi = to_txq_info(sdata->vif.txq);
974+
975+
ieee80211_purge_tx_queue(&local->hw, &txqi->queue);
976+
atomic_set(&sdata->txqs_len[txqi->txq.ac], 0);
977+
}
978+
972979
if (local->open_count == 0)
973980
ieee80211_clear_tx_pending(local);
974981

@@ -1654,6 +1661,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
16541661
{
16551662
struct net_device *ndev = NULL;
16561663
struct ieee80211_sub_if_data *sdata = NULL;
1664+
struct txq_info *txqi;
16571665
int ret, i;
16581666
int txqs = 1;
16591667

@@ -1673,10 +1681,18 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
16731681
ieee80211_assign_perm_addr(local, wdev->address, type);
16741682
memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
16751683
} else {
1684+
int size = ALIGN(sizeof(*sdata) + local->hw.vif_data_size,
1685+
sizeof(void *));
1686+
int txq_size = 0;
1687+
1688+
if (local->ops->wake_tx_queue)
1689+
txq_size += sizeof(struct txq_info) +
1690+
local->hw.txq_data_size;
1691+
16761692
if (local->hw.queues >= IEEE80211_NUM_ACS)
16771693
txqs = IEEE80211_NUM_ACS;
16781694

1679-
ndev = alloc_netdev_mqs(sizeof(*sdata) + local->hw.vif_data_size,
1695+
ndev = alloc_netdev_mqs(size + txq_size,
16801696
name, name_assign_type,
16811697
ieee80211_if_setup, txqs, 1);
16821698
if (!ndev)
@@ -1711,6 +1727,11 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
17111727
memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
17121728
memcpy(sdata->name, ndev->name, IFNAMSIZ);
17131729

1730+
if (txq_size) {
1731+
txqi = netdev_priv(ndev) + size;
1732+
ieee80211_init_tx_queue(sdata, NULL, txqi, 0);
1733+
}
1734+
17141735
sdata->dev = ndev;
17151736
}
17161737

net/mac80211/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
10391039

10401040
local->dynamic_ps_forced_timeout = -1;
10411041

1042+
if (!local->hw.txq_ac_max_pending)
1043+
local->hw.txq_ac_max_pending = 64;
1044+
10421045
result = ieee80211_wep_init(local);
10431046
if (result < 0)
10441047
wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",

0 commit comments

Comments
 (0)