Skip to content

Commit

Permalink
mac80211: add an intermediate software queue implementation
Browse files Browse the repository at this point in the history
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 <nbd@openwrt.org>
[resolved minor context conflict, minor changes, endian annotations]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Felix Fietkau authored and Johannes Berg committed Apr 1, 2015
1 parent cef2fc1 commit ba8c3d6
Show file tree
Hide file tree
Showing 12 changed files with 433 additions and 19 deletions.
83 changes: 83 additions & 0 deletions include/net/mac80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,39 @@
*
*/

/**
* DOC: mac80211 software tx queueing
*
* mac80211 provides an optional intermediate queueing implementation designed
* to allow the driver to keep hardware queues short and provide some fairness
* between different stations/interfaces.
* In this model, the driver pulls data frames from the mac80211 queue instead
* of letting mac80211 push them via drv_tx().
* Other frames (e.g. control or management) are still pushed using drv_tx().
*
* Drivers indicate that they use this model by implementing the .wake_tx_queue
* driver operation.
*
* Intermediate queues (struct ieee80211_txq) are kept per-sta per-tid, with a
* single per-vif queue for multicast data frames.
*
* The driver is expected to initialize its private per-queue data for stations
* and interfaces in the .add_interface and .sta_add ops.
*
* The driver can't access the queue directly. To dequeue a frame, it calls
* ieee80211_tx_dequeue(). Whenever mac80211 adds a new frame to a queue, it
* calls the .wake_tx_queue driver op.
*
* For AP powersave TIM handling, the driver only needs to indicate if it has
* buffered packets in the driver specific data structures by calling
* ieee80211_sta_set_buffered(). For frames buffered in the ieee80211_txq
* struct, mac80211 sets the appropriate TIM PVB bits and calls
* .release_buffered_frames().
* In that callback the driver is therefore expected to release its own
* buffered frames and afterwards also frames from the ieee80211_txq (obtained
* via the usual ieee80211_tx_dequeue).
*/

struct device;

/**
Expand Down Expand Up @@ -1306,6 +1339,7 @@ enum ieee80211_vif_flags {
* monitor interface (if that is requested.)
* @drv_priv: data area for driver use, will always be aligned to
* sizeof(void *).
* @txq: the multicast data TX queue (if driver uses the TXQ abstraction)
*/
struct ieee80211_vif {
enum nl80211_iftype type;
Expand All @@ -1317,6 +1351,8 @@ struct ieee80211_vif {
u8 cab_queue;
u8 hw_queue[IEEE80211_NUM_ACS];

struct ieee80211_txq *txq;

struct ieee80211_chanctx_conf __rcu *chanctx_conf;

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

struct ieee80211_txq *txq[IEEE80211_NUM_TIDS];

/* must be last */
u8 drv_priv[0] __aligned(sizeof(void *));
};
Expand Down Expand Up @@ -1620,6 +1659,27 @@ struct ieee80211_tx_control {
struct ieee80211_sta *sta;
};

/**
* struct ieee80211_txq - Software intermediate tx queue
*
* @vif: &struct ieee80211_vif pointer from the add_interface callback.
* @sta: station table entry, %NULL for per-vif queue
* @tid: the TID for this queue (unused for per-vif queue)
* @ac: the AC for this queue
*
* The driver can obtain packets from this queue by calling
* ieee80211_tx_dequeue().
*/
struct ieee80211_txq {
struct ieee80211_vif *vif;
struct ieee80211_sta *sta;
u8 tid;
u8 ac;

/* must be last */
u8 drv_priv[0] __aligned(sizeof(void *));
};

/**
* enum ieee80211_hw_flags - hardware flags
*
Expand Down Expand Up @@ -1844,6 +1904,8 @@ enum ieee80211_hw_flags {
* within &struct ieee80211_sta.
* @chanctx_data_size: size (in bytes) of the drv_priv data area
* within &struct ieee80211_chanctx_conf.
* @txq_data_size: size (in bytes) of the drv_priv data area
* within @struct ieee80211_txq.
*
* @max_rates: maximum number of alternate rate retry stages the hw
* can handle.
Expand Down Expand Up @@ -1892,6 +1954,9 @@ enum ieee80211_hw_flags {
* @n_cipher_schemes: a size of an array of cipher schemes definitions.
* @cipher_schemes: a pointer to an array of cipher scheme definitions
* supported by HW.
*
* @txq_ac_max_pending: maximum number of frames per AC pending in all txq
* entries for a vif.
*/
struct ieee80211_hw {
struct ieee80211_conf conf;
Expand All @@ -1904,6 +1969,7 @@ struct ieee80211_hw {
int vif_data_size;
int sta_data_size;
int chanctx_data_size;
int txq_data_size;
u16 queues;
u16 max_listen_interval;
s8 max_signal;
Expand All @@ -1920,6 +1986,7 @@ struct ieee80211_hw {
u8 uapsd_max_sp_len;
u8 n_cipher_schemes;
const struct ieee80211_cipher_scheme *cipher_schemes;
int txq_ac_max_pending;
};

/**
Expand Down Expand Up @@ -3082,6 +3149,8 @@ enum ieee80211_reconfig_type {
* response template is provided, together with the location of the
* switch-timing IE within the template. The skb can only be used within
* the function call.
*
* @wake_tx_queue: Called when new packets have been added to the queue.
*/
struct ieee80211_ops {
void (*tx)(struct ieee80211_hw *hw,
Expand Down Expand Up @@ -3313,6 +3382,9 @@ struct ieee80211_ops {
void (*tdls_recv_channel_switch)(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_tdls_ch_sw_params *params);

void (*wake_tx_queue)(struct ieee80211_hw *hw,
struct ieee80211_txq *txq);
};

/**
Expand Down Expand Up @@ -5334,4 +5406,15 @@ void ieee80211_unreserve_tid(struct ieee80211_sta *sta, u8 tid);
*/
size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
const u8 *ids, int n_ids, size_t offset);

/**
* ieee80211_tx_dequeue - dequeue a packet from a software tx queue
*
* @hw: pointer as obtained from ieee80211_alloc_hw()
* @txq: pointer obtained from station or virtual interface
*
* Returns the skb if successful, %NULL if no frame was available.
*/
struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
struct ieee80211_txq *txq);
#endif /* MAC80211_H */
44 changes: 44 additions & 0 deletions net/mac80211/agg-tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,43 @@ ieee80211_wake_queue_agg(struct ieee80211_sub_if_data *sdata, int tid)
__release(agg_queue);
}

static void
ieee80211_agg_stop_txq(struct sta_info *sta, int tid)
{
struct ieee80211_txq *txq = sta->sta.txq[tid];
struct txq_info *txqi;

if (!txq)
return;

txqi = to_txq_info(txq);

/* Lock here to protect against further seqno updates on dequeue */
spin_lock_bh(&txqi->queue.lock);
set_bit(IEEE80211_TXQ_STOP, &txqi->flags);
spin_unlock_bh(&txqi->queue.lock);
}

static void
ieee80211_agg_start_txq(struct sta_info *sta, int tid, bool enable)
{
struct ieee80211_txq *txq = sta->sta.txq[tid];
struct txq_info *txqi;

if (!txq)
return;

txqi = to_txq_info(txq);

if (enable)
set_bit(IEEE80211_TXQ_AMPDU, &txqi->flags);
else
clear_bit(IEEE80211_TXQ_AMPDU, &txqi->flags);

clear_bit(IEEE80211_TXQ_STOP, &txqi->flags);
drv_wake_tx_queue(sta->sdata->local, txqi);
}

/*
* splice packets from the STA's pending to the local pending,
* requires a call to ieee80211_agg_splice_finish later
Expand Down Expand Up @@ -247,6 +284,7 @@ static void ieee80211_remove_tid_tx(struct sta_info *sta, int tid)
ieee80211_assign_tid_tx(sta, tid, NULL);

ieee80211_agg_splice_finish(sta->sdata, tid);
ieee80211_agg_start_txq(sta, tid, false);

kfree_rcu(tid_tx, rcu_head);
}
Expand Down Expand Up @@ -418,6 +456,8 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
*/
clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);

ieee80211_agg_stop_txq(sta, tid);

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

ieee80211_agg_start_txq(sta, tid, false);

kfree_rcu(tid_tx, rcu_head);
return;
}
Expand Down Expand Up @@ -669,6 +711,8 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
ieee80211_agg_splice_finish(sta->sdata, tid);

spin_unlock_bh(&sta->lock);

ieee80211_agg_start_txq(sta, tid, true);
}

void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
Expand Down
12 changes: 12 additions & 0 deletions net/mac80211/driver-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -1367,4 +1367,16 @@ drv_tdls_recv_channel_switch(struct ieee80211_local *local,
trace_drv_return_void(local);
}

static inline void drv_wake_tx_queue(struct ieee80211_local *local,
struct txq_info *txq)
{
struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->txq.vif);

if (!check_sdata_in_driver(sdata))
return;

trace_drv_wake_tx_queue(local, sdata, txq);
local->ops->wake_tx_queue(&local->hw, &txq->txq);
}

#endif /* __MAC80211_DRIVER_OPS */
21 changes: 21 additions & 0 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,19 @@ struct mac80211_qos_map {
struct rcu_head rcu_head;
};

enum txq_info_flags {
IEEE80211_TXQ_STOP,
IEEE80211_TXQ_AMPDU,
};

struct txq_info {
struct sk_buff_head queue;
unsigned long flags;

/* keep last! */
struct ieee80211_txq txq;
};

struct ieee80211_sub_if_data {
struct list_head list;

Expand Down Expand Up @@ -853,6 +866,7 @@ struct ieee80211_sub_if_data {
bool control_port_no_encrypt;
int encrypt_headroom;

atomic_t txqs_len[IEEE80211_NUM_ACS];
struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS];
struct mac80211_qos_map __rcu *qos_map;

Expand Down Expand Up @@ -1450,6 +1464,10 @@ static inline struct ieee80211_local *hw_to_local(
return container_of(hw, struct ieee80211_local, hw);
}

static inline struct txq_info *to_txq_info(struct ieee80211_txq *txq)
{
return container_of(txq, struct txq_info, txq);
}

static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
{
Expand Down Expand Up @@ -1906,6 +1924,9 @@ static inline bool ieee80211_can_run_worker(struct ieee80211_local *local)
return true;
}

void ieee80211_init_tx_queue(struct ieee80211_sub_if_data *sdata,
struct sta_info *sta,
struct txq_info *txq, int tid);
void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
u16 transaction, u16 auth_alg, u16 status,
const u8 *extra, size_t extra_len, const u8 *bssid,
Expand Down
23 changes: 22 additions & 1 deletion net/mac80211/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,13 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
}
spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);

if (sdata->vif.txq) {
struct txq_info *txqi = to_txq_info(sdata->vif.txq);

ieee80211_purge_tx_queue(&local->hw, &txqi->queue);
atomic_set(&sdata->txqs_len[txqi->txq.ac], 0);
}

if (local->open_count == 0)
ieee80211_clear_tx_pending(local);

Expand Down Expand Up @@ -1654,6 +1661,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
{
struct net_device *ndev = NULL;
struct ieee80211_sub_if_data *sdata = NULL;
struct txq_info *txqi;
int ret, i;
int txqs = 1;

Expand All @@ -1673,10 +1681,18 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
ieee80211_assign_perm_addr(local, wdev->address, type);
memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
} else {
int size = ALIGN(sizeof(*sdata) + local->hw.vif_data_size,
sizeof(void *));
int txq_size = 0;

if (local->ops->wake_tx_queue)
txq_size += sizeof(struct txq_info) +
local->hw.txq_data_size;

if (local->hw.queues >= IEEE80211_NUM_ACS)
txqs = IEEE80211_NUM_ACS;

ndev = alloc_netdev_mqs(sizeof(*sdata) + local->hw.vif_data_size,
ndev = alloc_netdev_mqs(size + txq_size,
name, name_assign_type,
ieee80211_if_setup, txqs, 1);
if (!ndev)
Expand Down Expand Up @@ -1711,6 +1727,11 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
memcpy(sdata->name, ndev->name, IFNAMSIZ);

if (txq_size) {
txqi = netdev_priv(ndev) + size;
ieee80211_init_tx_queue(sdata, NULL, txqi, 0);
}

sdata->dev = ndev;
}

Expand Down
3 changes: 3 additions & 0 deletions net/mac80211/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)

local->dynamic_ps_forced_timeout = -1;

if (!local->hw.txq_ac_max_pending)
local->hw.txq_ac_max_pending = 64;

result = ieee80211_wep_init(local);
if (result < 0)
wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
Expand Down
Loading

0 comments on commit ba8c3d6

Please sign in to comment.