2007-05-06 02:45:53 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2004, Instant802 Networks, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <net/ip.h>
|
|
|
|
#include <net/pkt_sched.h>
|
|
|
|
|
|
|
|
#include <net/mac80211.h>
|
|
|
|
#include "ieee80211_i.h"
|
|
|
|
#include "wme.h"
|
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
/* Default mapping in classifier to work with default
|
2008-05-01 00:51:21 +08:00
|
|
|
* queue setup.
|
|
|
|
*/
|
2008-01-28 20:07:18 +08:00
|
|
|
const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
|
2007-05-06 02:45:53 +08:00
|
|
|
|
2008-01-10 01:12:48 +08:00
|
|
|
static const char llc_ip_hdr[8] = {0xAA, 0xAA, 0x3, 0, 0, 0, 0x08, 0};
|
2007-05-06 02:45:53 +08:00
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
/* Given a data frame determine the 802.1p/1d tag to use. */
|
|
|
|
static unsigned int classify_1d(struct sk_buff *skb)
|
2007-05-06 02:45:53 +08:00
|
|
|
{
|
2008-07-15 18:34:57 +08:00
|
|
|
unsigned int dscp;
|
2007-05-06 02:45:53 +08:00
|
|
|
|
|
|
|
/* skb->priority values from 256->263 are magic values to
|
2008-07-15 18:34:57 +08:00
|
|
|
* directly indicate a specific 802.1d priority. This is used
|
|
|
|
* to allow 802.1d priority to be passed directly in from VLAN
|
|
|
|
* tags, etc.
|
|
|
|
*/
|
2007-05-06 02:45:53 +08:00
|
|
|
if (skb->priority >= 256 && skb->priority <= 263)
|
|
|
|
return skb->priority - 256;
|
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
switch (skb->protocol) {
|
|
|
|
case __constant_htons(ETH_P_IP):
|
|
|
|
dscp = ip_hdr(skb)->tos & 0xfc;
|
|
|
|
break;
|
2007-05-06 02:45:53 +08:00
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2007-05-06 02:45:53 +08:00
|
|
|
|
|
|
|
return dscp >> 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
static int wme_downgrade_ac(struct sk_buff *skb)
|
2007-05-06 02:45:53 +08:00
|
|
|
{
|
|
|
|
switch (skb->priority) {
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
skb->priority = 5; /* VO -> VI */
|
|
|
|
return 0;
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
skb->priority = 3; /* VI -> BE */
|
|
|
|
return 0;
|
|
|
|
case 0:
|
|
|
|
case 3:
|
|
|
|
skb->priority = 2; /* BE -> BK */
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
/* Indicate which queue to use. */
|
|
|
|
static u16 classify80211(struct sk_buff *skb, struct net_device *dev)
|
2007-05-06 02:45:53 +08:00
|
|
|
{
|
2008-07-15 18:34:57 +08:00
|
|
|
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
|
2007-05-06 02:45:53 +08:00
|
|
|
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
|
|
|
|
2008-06-12 05:21:59 +08:00
|
|
|
if (!ieee80211_is_data(hdr->frame_control)) {
|
2007-05-06 02:45:53 +08:00
|
|
|
/* management frames go on AC_VO queue, but are sent
|
|
|
|
* without QoS control fields */
|
2008-05-01 00:51:21 +08:00
|
|
|
return 0;
|
2007-05-06 02:45:53 +08:00
|
|
|
}
|
|
|
|
|
2007-09-28 20:02:09 +08:00
|
|
|
if (0 /* injected */) {
|
|
|
|
/* use AC from radiotap */
|
2007-05-06 02:45:53 +08:00
|
|
|
}
|
|
|
|
|
2008-06-12 05:21:59 +08:00
|
|
|
if (!ieee80211_is_data_qos(hdr->frame_control)) {
|
2007-05-06 02:45:53 +08:00
|
|
|
skb->priority = 0; /* required for correct WPA/11i MIC */
|
|
|
|
return ieee802_1d_to_ac[skb->priority];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use the data classifier to determine what 802.1d tag the
|
2007-08-29 05:01:55 +08:00
|
|
|
* data frame has */
|
2008-07-15 18:34:57 +08:00
|
|
|
skb->priority = classify_1d(skb);
|
2007-05-06 02:45:53 +08:00
|
|
|
|
2007-08-29 05:01:55 +08:00
|
|
|
/* in case we are a client verify acm is not set for this ac */
|
2007-05-06 02:45:53 +08:00
|
|
|
while (unlikely(local->wmm_acm & BIT(skb->priority))) {
|
|
|
|
if (wme_downgrade_ac(skb)) {
|
2008-07-15 18:34:57 +08:00
|
|
|
/* The old code would drop the packet in this
|
|
|
|
* case.
|
|
|
|
*/
|
|
|
|
return 0;
|
2007-05-06 02:45:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look up which queue to use for frames with this 1d tag */
|
|
|
|
return ieee802_1d_to_ac[skb->priority];
|
|
|
|
}
|
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
|
2007-05-06 02:45:53 +08:00
|
|
|
{
|
|
|
|
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
2008-07-15 18:34:57 +08:00
|
|
|
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
|
|
|
|
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
|
2008-01-28 20:07:18 +08:00
|
|
|
struct sta_info *sta;
|
2008-07-15 18:34:57 +08:00
|
|
|
u16 queue;
|
2008-01-28 20:07:18 +08:00
|
|
|
u8 tid;
|
2007-05-06 02:45:53 +08:00
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
queue = classify80211(skb, dev);
|
|
|
|
if (unlikely(queue >= local->hw.queues))
|
|
|
|
queue = local->hw.queues - 1;
|
|
|
|
|
2008-05-15 18:55:29 +08:00
|
|
|
if (info->flags & IEEE80211_TX_CTL_REQUEUE) {
|
2008-02-25 23:27:46 +08:00
|
|
|
rcu_read_lock();
|
2008-01-28 20:07:18 +08:00
|
|
|
sta = sta_info_get(local, hdr->addr1);
|
2008-07-03 02:05:34 +08:00
|
|
|
tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
|
2008-01-28 20:07:18 +08:00
|
|
|
if (sta) {
|
2008-07-15 18:34:57 +08:00
|
|
|
struct ieee80211_hw *hw = &local->hw;
|
2008-01-28 20:07:18 +08:00
|
|
|
int ampdu_queue = sta->tid_to_tx_q[tid];
|
2008-07-15 18:34:57 +08:00
|
|
|
|
|
|
|
if ((ampdu_queue < ieee80211_num_queues(hw)) &&
|
|
|
|
test_bit(ampdu_queue, local->queue_pool)) {
|
2008-01-28 20:07:18 +08:00
|
|
|
queue = ampdu_queue;
|
2008-05-15 18:55:29 +08:00
|
|
|
info->flags |= IEEE80211_TX_CTL_AMPDU;
|
2008-01-28 20:07:18 +08:00
|
|
|
} else {
|
2008-05-15 18:55:29 +08:00
|
|
|
info->flags &= ~IEEE80211_TX_CTL_AMPDU;
|
2008-01-28 20:07:18 +08:00
|
|
|
}
|
|
|
|
}
|
2008-02-25 23:27:46 +08:00
|
|
|
rcu_read_unlock();
|
2007-05-06 02:45:53 +08:00
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
return queue;
|
|
|
|
}
|
2008-05-01 00:51:21 +08:00
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
/* Now we know the 1d priority, fill in the QoS header if
|
|
|
|
* there is one.
|
2007-05-06 02:45:53 +08:00
|
|
|
*/
|
2008-06-12 05:21:59 +08:00
|
|
|
if (ieee80211_is_data_qos(hdr->frame_control)) {
|
|
|
|
u8 *p = ieee80211_get_qos_ctl(hdr);
|
2008-01-28 20:07:18 +08:00
|
|
|
u8 ack_policy = 0;
|
2008-07-03 02:05:34 +08:00
|
|
|
tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
|
2007-05-06 02:45:53 +08:00
|
|
|
if (local->wifi_wme_noack_test)
|
2008-01-28 20:07:18 +08:00
|
|
|
ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
|
2007-05-06 02:45:53 +08:00
|
|
|
QOS_CONTROL_ACK_POLICY_SHIFT;
|
|
|
|
/* qos header is 2 bytes, second reserved */
|
2008-06-12 05:21:59 +08:00
|
|
|
*p++ = ack_policy | tid;
|
2007-05-06 02:45:53 +08:00
|
|
|
*p = 0;
|
2008-01-28 20:07:18 +08:00
|
|
|
|
2008-02-25 23:27:46 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
|
2008-01-28 20:07:18 +08:00
|
|
|
sta = sta_info_get(local, hdr->addr1);
|
|
|
|
if (sta) {
|
|
|
|
int ampdu_queue = sta->tid_to_tx_q[tid];
|
2008-07-15 18:34:57 +08:00
|
|
|
struct ieee80211_hw *hw = &local->hw;
|
|
|
|
|
|
|
|
if ((ampdu_queue < ieee80211_num_queues(hw)) &&
|
|
|
|
test_bit(ampdu_queue, local->queue_pool)) {
|
2008-01-28 20:07:18 +08:00
|
|
|
queue = ampdu_queue;
|
2008-05-15 18:55:29 +08:00
|
|
|
info->flags |= IEEE80211_TX_CTL_AMPDU;
|
2008-01-28 20:07:18 +08:00
|
|
|
} else {
|
2008-05-15 18:55:29 +08:00
|
|
|
info->flags &= ~IEEE80211_TX_CTL_AMPDU;
|
2008-01-28 20:07:18 +08:00
|
|
|
}
|
|
|
|
}
|
2008-02-25 23:27:46 +08:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
2007-05-06 02:45:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
2008-01-28 20:07:18 +08:00
|
|
|
int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
|
2008-07-15 18:34:57 +08:00
|
|
|
struct sta_info *sta, u16 tid)
|
2008-01-28 20:07:18 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-07-29 17:32:07 +08:00
|
|
|
/* XXX: currently broken due to cb/requeue use */
|
|
|
|
return -EPERM;
|
|
|
|
|
2008-01-28 20:07:18 +08:00
|
|
|
/* prepare the filter and save it for the SW queue
|
2008-05-01 00:51:21 +08:00
|
|
|
* matching the received HW queue */
|
|
|
|
|
|
|
|
if (!local->hw.ampdu_queues)
|
|
|
|
return -EPERM;
|
2008-01-28 20:07:18 +08:00
|
|
|
|
|
|
|
/* try to get a Qdisc from the pool */
|
2008-07-15 18:34:57 +08:00
|
|
|
for (i = local->hw.queues; i < ieee80211_num_queues(&local->hw); i++)
|
|
|
|
if (!test_and_set_bit(i, local->queue_pool)) {
|
2008-01-28 20:07:18 +08:00
|
|
|
ieee80211_stop_queue(local_to_hw(local), i);
|
|
|
|
sta->tid_to_tx_q[tid] = i;
|
|
|
|
|
|
|
|
/* IF there are already pending packets
|
|
|
|
* on this tid first we need to drain them
|
|
|
|
* on the previous queue
|
|
|
|
* since HT is strict in order */
|
|
|
|
#ifdef CONFIG_MAC80211_HT_DEBUG
|
2008-07-15 18:34:57 +08:00
|
|
|
if (net_ratelimit()) {
|
|
|
|
DECLARE_MAC_BUF(mac);
|
2008-01-28 20:07:18 +08:00
|
|
|
printk(KERN_DEBUG "allocated aggregation queue"
|
2008-06-13 01:08:19 +08:00
|
|
|
" %d tid %d addr %s pool=0x%lX\n",
|
2008-09-11 06:02:02 +08:00
|
|
|
i, tid, print_mac(mac, sta->sta.addr),
|
2008-07-15 18:34:57 +08:00
|
|
|
local->queue_pool[0]);
|
|
|
|
}
|
2008-01-28 20:07:18 +08:00
|
|
|
#endif /* CONFIG_MAC80211_HT_DEBUG */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-07-17 15:34:19 +08:00
|
|
|
* the caller needs to hold netdev_get_tx_queue(local->mdev, X)->lock
|
2008-01-28 20:07:18 +08:00
|
|
|
*/
|
|
|
|
void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
|
|
|
|
struct sta_info *sta, u16 tid,
|
|
|
|
u8 requeue)
|
|
|
|
{
|
|
|
|
int agg_queue = sta->tid_to_tx_q[tid];
|
2008-07-15 18:34:57 +08:00
|
|
|
struct ieee80211_hw *hw = &local->hw;
|
2008-01-28 20:07:18 +08:00
|
|
|
|
|
|
|
/* return the qdisc to the pool */
|
2008-07-15 18:34:57 +08:00
|
|
|
clear_bit(agg_queue, local->queue_pool);
|
|
|
|
sta->tid_to_tx_q[tid] = ieee80211_num_queues(hw);
|
2008-01-28 20:07:18 +08:00
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
if (requeue) {
|
2008-01-28 20:07:18 +08:00
|
|
|
ieee80211_requeue(local, agg_queue);
|
2008-07-15 18:34:57 +08:00
|
|
|
} else {
|
|
|
|
struct netdev_queue *txq;
|
2008-07-17 15:53:03 +08:00
|
|
|
spinlock_t *root_lock;
|
2008-08-03 14:25:50 +08:00
|
|
|
struct Qdisc *q;
|
2008-07-15 18:34:57 +08:00
|
|
|
|
|
|
|
txq = netdev_get_tx_queue(local->mdev, agg_queue);
|
2008-08-03 14:25:50 +08:00
|
|
|
q = rcu_dereference(txq->qdisc);
|
|
|
|
root_lock = qdisc_lock(q);
|
2008-07-15 18:34:57 +08:00
|
|
|
|
2008-07-17 15:53:03 +08:00
|
|
|
spin_lock_bh(root_lock);
|
2008-08-03 14:25:50 +08:00
|
|
|
qdisc_reset(q);
|
2008-07-17 15:53:03 +08:00
|
|
|
spin_unlock_bh(root_lock);
|
2008-07-15 18:34:57 +08:00
|
|
|
}
|
2008-01-28 20:07:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ieee80211_requeue(struct ieee80211_local *local, int queue)
|
|
|
|
{
|
2008-07-15 18:34:57 +08:00
|
|
|
struct netdev_queue *txq = netdev_get_tx_queue(local->mdev, queue);
|
|
|
|
struct sk_buff_head list;
|
2008-07-17 15:53:03 +08:00
|
|
|
spinlock_t *root_lock;
|
2008-07-15 18:34:57 +08:00
|
|
|
struct Qdisc *qdisc;
|
2008-04-23 18:45:12 +08:00
|
|
|
u32 len;
|
2008-01-28 20:07:18 +08:00
|
|
|
|
2008-07-15 18:34:57 +08:00
|
|
|
rcu_read_lock_bh();
|
|
|
|
|
|
|
|
qdisc = rcu_dereference(txq->qdisc);
|
2008-01-28 20:07:18 +08:00
|
|
|
if (!qdisc || !qdisc->dequeue)
|
2008-07-15 18:34:57 +08:00
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
skb_queue_head_init(&list);
|
2008-01-28 20:07:18 +08:00
|
|
|
|
2008-07-17 15:53:03 +08:00
|
|
|
root_lock = qdisc_root_lock(qdisc);
|
|
|
|
spin_lock(root_lock);
|
2008-01-28 20:07:18 +08:00
|
|
|
for (len = qdisc->q.qlen; len > 0; len--) {
|
2008-07-15 18:34:57 +08:00
|
|
|
struct sk_buff *skb = qdisc->dequeue(qdisc);
|
|
|
|
|
2008-01-28 20:07:18 +08:00
|
|
|
if (skb)
|
2008-07-15 18:34:57 +08:00
|
|
|
__skb_queue_tail(&list, skb);
|
|
|
|
}
|
2008-07-17 15:53:03 +08:00
|
|
|
spin_unlock(root_lock);
|
2008-07-15 18:34:57 +08:00
|
|
|
|
|
|
|
for (len = list.qlen; len > 0; len--) {
|
|
|
|
struct sk_buff *skb = __skb_dequeue(&list);
|
|
|
|
u16 new_queue;
|
|
|
|
|
|
|
|
BUG_ON(!skb);
|
|
|
|
new_queue = ieee80211_select_queue(local->mdev, skb);
|
|
|
|
skb_set_queue_mapping(skb, new_queue);
|
|
|
|
|
|
|
|
txq = netdev_get_tx_queue(local->mdev, new_queue);
|
|
|
|
|
|
|
|
|
|
|
|
qdisc = rcu_dereference(txq->qdisc);
|
2008-07-17 15:53:03 +08:00
|
|
|
root_lock = qdisc_root_lock(qdisc);
|
2008-07-15 18:34:57 +08:00
|
|
|
|
2008-07-17 15:53:03 +08:00
|
|
|
spin_lock(root_lock);
|
2008-07-20 15:08:04 +08:00
|
|
|
qdisc_enqueue_root(skb, qdisc);
|
2008-07-17 15:53:03 +08:00
|
|
|
spin_unlock(root_lock);
|
2008-01-28 20:07:18 +08:00
|
|
|
}
|
2008-07-15 18:34:57 +08:00
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
rcu_read_unlock_bh();
|
2008-01-28 20:07:18 +08:00
|
|
|
}
|