Commit 51cb6db0 authored by David S. Miller's avatar David S. Miller

mac80211: Reimplement WME using ->select_queue().

The only behavior change is that we do not drop packets under any
circumstances.  If that is absolutely needed, we could easily add it
back.

With cleanups and help from Johannes Berg.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent eae792b7
......@@ -847,20 +847,12 @@ static inline void SET_IEEE80211_PERM_ADDR(struct ieee80211_hw *hw, u8 *addr)
static inline int ieee80211_num_regular_queues(struct ieee80211_hw *hw)
{
#ifdef CONFIG_MAC80211_QOS
return hw->queues;
#else
return 1;
#endif
}
static inline int ieee80211_num_queues(struct ieee80211_hw *hw)
{
#ifdef CONFIG_MAC80211_QOS
return hw->queues + hw->ampdu_queues;
#else
return 1;
#endif
}
static inline struct ieee80211_rate *
......
......@@ -11,17 +11,6 @@ config MAC80211
This option enables the hardware independent IEEE 802.11
networking stack.
config MAC80211_QOS
def_bool y
depends on MAC80211
depends on NET_SCHED
depends on BROKEN
comment "QoS/HT support disabled"
depends on MAC80211 && !MAC80211_QOS
comment "QoS/HT support needs CONFIG_NET_SCHED"
depends on MAC80211 && !NET_SCHED
menu "Rate control algorithm selection"
depends on MAC80211 != n
......
......@@ -18,10 +18,10 @@ mac80211-y := \
tx.o \
key.o \
util.o \
wme.o \
event.o
mac80211-$(CONFIG_MAC80211_LEDS) += led.o
mac80211-$(CONFIG_MAC80211_QOS) += wme.o
mac80211-$(CONFIG_MAC80211_DEBUGFS) += \
debugfs.o \
debugfs_sta.o \
......
......@@ -25,6 +25,7 @@
#include <linux/etherdevice.h>
#include <net/wireless.h>
#include <net/iw_handler.h>
#include <net/mac80211.h>
#include "key.h"
#include "sta_info.h"
......@@ -537,6 +538,9 @@ enum {
IEEE80211_ADDBA_MSG = 4,
};
/* maximum number of hardware queues we support. */
#define QD_MAX_QUEUES (IEEE80211_MAX_AMPDU_QUEUES + IEEE80211_MAX_QUEUES)
struct ieee80211_local {
/* embed the driver visible part.
* don't cast (use the static inlines below), but we keep
......@@ -545,6 +549,8 @@ struct ieee80211_local {
const struct ieee80211_ops *ops;
unsigned long queue_pool[BITS_TO_LONGS(QD_MAX_QUEUES)];
struct net_device *mdev; /* wmaster# - "master" 802.11 device */
int open_count;
int monitors, cooked_mntrs;
......@@ -740,15 +746,6 @@ struct ieee80211_local {
#endif
};
static inline int ieee80211_is_multiqueue(struct ieee80211_local *local)
{
#ifdef CONFIG_MAC80211_QOS
return netif_is_multiqueue(local->mdev);
#else
return 0;
#endif
}
static inline struct ieee80211_sub_if_data *
IEEE80211_DEV_TO_SUB_IF(struct net_device *dev)
{
......
......@@ -114,7 +114,7 @@ static int ieee80211_master_open(struct net_device *dev)
if (res)
return res;
netif_start_queue(local->mdev);
netif_tx_start_all_queues(local->mdev);
return 0;
}
......@@ -375,7 +375,7 @@ static int ieee80211_open(struct net_device *dev)
queue_work(local->hw.workqueue, &ifsta->work);
}
netif_start_queue(dev);
netif_tx_start_all_queues(dev);
return 0;
err_del_interface:
......@@ -400,7 +400,7 @@ static int ieee80211_stop(struct net_device *dev)
/*
* Stop TX on this interface first.
*/
netif_stop_queue(dev);
netif_tx_stop_all_queues(dev);
/*
* Now delete all active aggregation sessions.
......@@ -554,7 +554,6 @@ static int ieee80211_stop(struct net_device *dev)
int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
{
struct ieee80211_local *local = hw_to_local(hw);
struct netdev_queue *txq;
struct sta_info *sta;
struct ieee80211_sub_if_data *sdata;
u16 start_seq_num = 0;
......@@ -619,11 +618,6 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
(unsigned long)&sta->timer_to_tid[tid];
init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
/* ensure that TX flow won't interrupt us
* until the end of the call to requeue function */
txq = netdev_get_tx_queue(local->mdev, 0);
spin_lock_bh(&txq->lock);
/* create a new queue for this aggregation */
ret = ieee80211_ht_agg_queue_add(local, sta, tid);
......@@ -650,7 +644,7 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
/* No need to requeue the packets in the agg queue, since we
* held the tx lock: no packet could be enqueued to the newly
* allocated queue */
ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
#ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "BA request denied - HW unavailable for"
" tid %d\n", tid);
......@@ -661,7 +655,6 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
/* Will put all the packets in the new SW queue */
ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
spin_unlock_bh(&txq->lock);
spin_unlock_bh(&sta->lock);
/* send an addBA request */
......@@ -687,7 +680,6 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
err_unlock_queue:
kfree(sta->ampdu_mlme.tid_tx[tid]);
sta->ampdu_mlme.tid_tx[tid] = NULL;
spin_unlock_bh(&txq->lock);
ret = -EBUSY;
err_unlock_sta:
spin_unlock_bh(&sta->lock);
......@@ -812,7 +804,6 @@ EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
{
struct ieee80211_local *local = hw_to_local(hw);
struct netdev_queue *txq;
struct sta_info *sta;
u8 *state;
int agg_queue;
......@@ -844,8 +835,9 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
state = &sta->ampdu_mlme.tid_state_tx[tid];
/* NOTE: no need to use sta->lock in this state check, as
* ieee80211_stop_tx_ba_session will let only
* one stop call to pass through per sta/tid */
* ieee80211_stop_tx_ba_session will let only one stop call to
* pass through per sta/tid
*/
if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
#ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
......@@ -860,19 +852,14 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
agg_queue = sta->tid_to_tx_q[tid];
/* avoid ordering issues: we are the only one that can modify
* the content of the qdiscs */
txq = netdev_get_tx_queue(local->mdev, 0);
spin_lock_bh(&txq->lock);
/* remove the queue for this aggregation */
ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
spin_unlock_bh(&txq->lock);
/* we just requeued the all the frames that were in the removed
* queue, and since we might miss a softirq we do netif_schedule_queue.
* ieee80211_wake_queue is not used here as this queue is not
* necessarily stopped */
netif_schedule_queue(txq);
/* We just requeued the all the frames that were in the
* removed queue, and since we might miss a softirq we do
* netif_schedule_queue. ieee80211_wake_queue is not used
* here as this queue is not necessarily stopped
*/
netif_schedule_queue(netdev_get_tx_queue(local->mdev, agg_queue));
spin_lock_bh(&sta->lock);
*state = HT_AGG_STATE_IDLE;
sta->ampdu_mlme.addba_req_num[tid] = 0;
......@@ -1660,17 +1647,12 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
* We use the number of queues for feature tests (QoS, HT) internally
* so restrict them appropriately.
*/
#ifdef CONFIG_MAC80211_QOS
if (hw->queues > IEEE80211_MAX_QUEUES)
hw->queues = IEEE80211_MAX_QUEUES;
if (hw->ampdu_queues > IEEE80211_MAX_AMPDU_QUEUES)
hw->ampdu_queues = IEEE80211_MAX_AMPDU_QUEUES;
if (hw->queues < 4)
hw->ampdu_queues = 0;
#else
hw->queues = 1;
hw->ampdu_queues = 0;
#endif
mdev = alloc_netdev_mq(sizeof(struct wireless_dev),
"wmaster%d", ether_setup,
......@@ -1754,7 +1736,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
goto fail_wep;
}
ieee80211_install_qdisc(local->mdev);
local->mdev->select_queue = ieee80211_select_queue;
/* add one default STA interface */
result = ieee80211_if_add(local, "wlan%d", NULL,
......@@ -1852,23 +1834,11 @@ static int __init ieee80211_init(void)
ret = rc80211_pid_init();
if (ret)
goto out;
ret = ieee80211_wme_register();
if (ret) {
printk(KERN_DEBUG "ieee80211_init: failed to "
"initialize WME (err=%d)\n", ret);
goto out_cleanup_pid;
}
return ret;
ieee80211_debugfs_netdev_init();
return 0;
out_cleanup_pid:
rc80211_pid_exit();
out:
return ret;
}
static void __exit ieee80211_exit(void)
......@@ -1884,7 +1854,6 @@ static void __exit ieee80211_exit(void)
if (mesh_allocated)
ieee80211s_stop();
ieee80211_wme_unregister();
ieee80211_debugfs_netdev_exit();
}
......
......@@ -363,12 +363,7 @@ void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
if (test_bit(queue, local->queues_pending)) {
tasklet_schedule(&local->tx_pending_tasklet);
} else {
if (ieee80211_is_multiqueue(local)) {
netif_wake_subqueue(local->mdev, queue);
} else {
WARN_ON(queue != 0);
netif_wake_queue(local->mdev);
}
netif_wake_subqueue(local->mdev, queue);
}
}
EXPORT_SYMBOL(ieee80211_wake_queue);
......@@ -377,12 +372,7 @@ void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
{
struct ieee80211_local *local = hw_to_local(hw);
if (ieee80211_is_multiqueue(local)) {
netif_stop_subqueue(local->mdev, queue);
} else {
WARN_ON(queue != 0);
netif_stop_queue(local->mdev);
}
netif_stop_subqueue(local->mdev, queue);
}
EXPORT_SYMBOL(ieee80211_stop_queue);
......
......@@ -18,67 +18,42 @@
#include "ieee80211_i.h"
#include "wme.h"
/* maximum number of hardware queues we support. */
#define QD_MAX_QUEUES (IEEE80211_MAX_AMPDU_QUEUES + IEEE80211_MAX_QUEUES)
/* current number of hardware queues we support. */
#define QD_NUM(hw) ((hw)->queues + (hw)->ampdu_queues)
/*
* Default mapping in classifier to work with default
/* Default mapping in classifier to work with default
* queue setup.
*/
const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
struct ieee80211_sched_data
{
unsigned long qdisc_pool[BITS_TO_LONGS(QD_MAX_QUEUES)];
struct tcf_proto *filter_list;
struct Qdisc *queues[QD_MAX_QUEUES];
struct sk_buff_head requeued[QD_MAX_QUEUES];
};
static const char llc_ip_hdr[8] = {0xAA, 0xAA, 0x3, 0, 0, 0, 0x08, 0};
/* given a data frame determine the 802.1p/1d tag to use */
static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
/* Given a data frame determine the 802.1p/1d tag to use. */
static unsigned int classify_1d(struct sk_buff *skb)
{
struct iphdr *ip;
int dscp;
int offset;
struct ieee80211_sched_data *q = qdisc_priv(qd);
struct tcf_result res = { -1, 0 };
/* if there is a user set filter list, call out to that */
if (q->filter_list) {
tc_classify(skb, q->filter_list, &res);
if (res.class != -1)
return res.class;
}
unsigned int dscp;
/* skb->priority values from 256->263 are magic values to
* directly indicate a specific 802.1d priority.
* This is used to allow 802.1d priority to be passed directly in
* from VLAN tags, etc. */
* directly indicate a specific 802.1d priority. This is used
* to allow 802.1d priority to be passed directly in from VLAN
* tags, etc.
*/
if (skb->priority >= 256 && skb->priority <= 263)
return skb->priority - 256;
/* check there is a valid IP header present */
offset = ieee80211_get_hdrlen_from_skb(skb);
if (skb->len < offset + sizeof(llc_ip_hdr) + sizeof(*ip) ||
memcmp(skb->data + offset, llc_ip_hdr, sizeof(llc_ip_hdr)))
return 0;
switch (skb->protocol) {
case __constant_htons(ETH_P_IP):
dscp = ip_hdr(skb)->tos & 0xfc;
break;
ip = (struct iphdr *) (skb->data + offset + sizeof(llc_ip_hdr));
default:
return 0;
}
dscp = ip->tos & 0xfc;
if (dscp & 0x1c)
return 0;
return dscp >> 5;
}
static inline int wme_downgrade_ac(struct sk_buff *skb)
static int wme_downgrade_ac(struct sk_buff *skb)
{
switch (skb->priority) {
case 6:
......@@ -99,11 +74,10 @@ static inline int wme_downgrade_ac(struct sk_buff *skb)
}
/* positive return value indicates which queue to use
* negative return value indicates to drop the frame */
static int classify80211(struct sk_buff *skb, struct Qdisc *qd)
/* Indicate which queue to use. */
static u16 classify80211(struct sk_buff *skb, struct net_device *dev)
{
struct ieee80211_local *local = wdev_priv(qdisc_dev(qd)->ieee80211_ptr);
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
if (!ieee80211_is_data(hdr->frame_control)) {
......@@ -123,13 +97,15 @@ static int classify80211(struct sk_buff *skb, struct Qdisc *qd)
/* use the data classifier to determine what 802.1d tag the
* data frame has */
skb->priority = classify_1d(skb, qd);
skb->priority = classify_1d(skb);
/* in case we are a client verify acm is not set for this ac */
while (unlikely(local->wmm_acm & BIT(skb->priority))) {
if (wme_downgrade_ac(skb)) {
/* No AC with lower priority has acm=0, drop packet. */
return -1;
/* The old code would drop the packet in this
* case.
*/
return 0;
}
}
......@@ -137,28 +113,29 @@ static int classify80211(struct sk_buff *skb, struct Qdisc *qd)
return ieee802_1d_to_ac[skb->priority];
}
static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
{
struct ieee80211_local *local = wdev_priv(qdisc_dev(qd)->ieee80211_ptr);
struct ieee80211_hw *hw = &local->hw;
struct ieee80211_sched_data *q = qdisc_priv(qd);
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
struct Qdisc *qdisc;
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct sta_info *sta;
int err, queue;
u16 queue;
u8 tid;
queue = classify80211(skb, dev);
if (unlikely(queue >= local->hw.queues))
queue = local->hw.queues - 1;
if (info->flags & IEEE80211_TX_CTL_REQUEUE) {
queue = skb_get_queue_mapping(skb);
rcu_read_lock();
sta = sta_info_get(local, hdr->addr1);
tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
if (sta) {
struct ieee80211_hw *hw = &local->hw;
int ampdu_queue = sta->tid_to_tx_q[tid];
if ((ampdu_queue < QD_NUM(hw)) &&
test_bit(ampdu_queue, q->qdisc_pool)) {
if ((ampdu_queue < ieee80211_num_queues(hw)) &&
test_bit(ampdu_queue, local->queue_pool)) {
queue = ampdu_queue;
info->flags |= IEEE80211_TX_CTL_AMPDU;
} else {
......@@ -166,17 +143,12 @@ static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
}
}
rcu_read_unlock();
skb_queue_tail(&q->requeued[queue], skb);
qd->q.qlen++;
return 0;
}
queue = classify80211(skb, qd);
if (unlikely(queue >= local->hw.queues))
queue = local->hw.queues - 1;
return queue;
}
/* now we know the 1d priority, fill in the QoS header if there is one
/* Now we know the 1d priority, fill in the QoS header if
* there is one.
*/
if (ieee80211_is_data_qos(hdr->frame_control)) {
u8 *p = ieee80211_get_qos_ctl(hdr);
......@@ -194,8 +166,10 @@ static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
sta = sta_info_get(local, hdr->addr1);
if (sta) {
int ampdu_queue = sta->tid_to_tx_q[tid];
if ((ampdu_queue < QD_NUM(hw)) &&
test_bit(ampdu_queue, q->qdisc_pool)) {
struct ieee80211_hw *hw = &local->hw;
if ((ampdu_queue < ieee80211_num_queues(hw)) &&
test_bit(ampdu_queue, local->queue_pool)) {
queue = ampdu_queue;
info->flags |= IEEE80211_TX_CTL_AMPDU;
} else {
......@@ -206,421 +180,13 @@ static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
rcu_read_unlock();
}
if (unlikely(queue < 0)) {
kfree_skb(skb);
err = NET_XMIT_DROP;
} else {
skb_set_queue_mapping(skb, queue);
qdisc = q->queues[queue];
err = qdisc->enqueue(skb, qdisc);
if (err == NET_XMIT_SUCCESS) {
qd->q.qlen++;
qd->bstats.bytes += skb->len;
qd->bstats.packets++;
return NET_XMIT_SUCCESS;
}
}
qd->qstats.drops++;
return err;
}
/* TODO: clean up the cases where master_hard_start_xmit
* returns non 0 - it shouldn't ever do that. Once done we
* can remove this function */
static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
{
struct ieee80211_sched_data *q = qdisc_priv(qd);
struct Qdisc *qdisc;
int err;
/* we recorded which queue to use earlier! */
qdisc = q->queues[skb_get_queue_mapping(skb)];
if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
qd->q.qlen++;
return 0;
}
qd->qstats.drops++;
return err;
}
static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
{
struct ieee80211_sched_data *q = qdisc_priv(qd);
struct net_device *dev = qdisc_dev(qd);
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_hw *hw = &local->hw;
struct sk_buff *skb;
struct Qdisc *qdisc;
int queue;
/* check all the h/w queues in numeric/priority order */
for (queue = 0; queue < QD_NUM(hw); queue++) {
/* see if there is room in this hardware queue */
if (__netif_subqueue_stopped(local->mdev, queue) ||
!test_bit(queue, q->qdisc_pool))
continue;
/* there is space - try and get a frame */
skb = skb_dequeue(&q->requeued[queue]);
if (skb) {
qd->q.qlen--;
return skb;
}
qdisc = q->queues[queue];
skb = qdisc->dequeue(qdisc);
if (skb) {
qd->q.qlen--;
return skb;
}
}
/* returning a NULL here when all the h/w queues are full means we
* never need to call netif_stop_queue in the driver */
return NULL;
}
static void wme_qdiscop_reset(struct Qdisc* qd)
{
struct ieee80211_sched_data *q = qdisc_priv(qd);
struct ieee80211_local *local = wdev_priv(qdisc_dev(qd)->ieee80211_ptr);
struct ieee80211_hw *hw = &local->hw;
int queue;
/* QUESTION: should we have some hardware flush functionality here? */
for (queue = 0; queue < QD_NUM(hw); queue++) {
skb_queue_purge(&q->requeued[queue]);
qdisc_reset(q->queues[queue]);
}
qd->q.qlen = 0;
}
static void wme_qdiscop_destroy(struct Qdisc* qd)
{
struct ieee80211_sched_data *q = qdisc_priv(qd);
struct ieee80211_local *local = wdev_priv(qdisc_dev(qd)->ieee80211_ptr);
struct ieee80211_hw *hw = &local->hw;
int queue;
tcf_destroy_chain(&q->filter_list);
for (queue = 0; queue < QD_NUM(hw); queue++) {
skb_queue_purge(&q->requeued[queue]);
qdisc_destroy(q->queues[queue]);
q->queues[queue] = &noop_qdisc;
}
}
/* called whenever parameters are updated on existing qdisc */
static int wme_qdiscop_tune(struct Qdisc *qd, struct nlattr *opt)
{
return 0;
}
/* called during initial creation of qdisc on device */
static int wme_qdiscop_init(struct Qdisc *qd, struct nlattr *opt)
{
struct ieee80211_sched_data *q = qdisc_priv(qd);
struct net_device *dev = qdisc_dev(qd);
struct ieee80211_local *local;
struct ieee80211_hw *hw;
int err = 0, i;
/* check that device is a mac80211 device */
if (!dev->ieee80211_ptr ||
dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
return -EINVAL;
local = wdev_priv(dev->ieee80211_ptr);
hw = &local->hw;
/* only allow on master dev */
if (dev != local->mdev)
return -EINVAL;
/* ensure that we are root qdisc */
if (qd->parent != TC_H_ROOT)
return -EINVAL;
if (qd->flags & TCQ_F_INGRESS)
return -EINVAL;
/* if options were passed in, set them */
if (opt)
err = wme_qdiscop_tune(qd, opt);
/* create child queues */
for (i = 0; i < QD_NUM(hw); i++) {
skb_queue_head_init(&q->requeued[i]);
q->queues[i] = qdisc_create_dflt(qdisc_dev(qd), qd->dev_queue,
&pfifo_qdisc_ops,
qd->handle);
if (!q->queues[i]) {
q->queues[i] = &noop_qdisc;
printk(KERN_ERR "%s child qdisc %i creation failed\n",
dev->name, i);
}
}
/* non-aggregation queues: reserve/mark as used */
for (i = 0; i < local->hw.queues; i++)
set_bit(i, q->qdisc_pool);