2
* Copyright 2004, Instant802 Networks, Inc.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation.
9
#include <linux/netdevice.h>
10
#include <linux/skbuff.h>
11
#include <linux/module.h>
12
#include <linux/if_arp.h>
13
#include <linux/types.h>
15
#include <net/pkt_sched.h>
17
#include <net/mac80211.h>
18
#include "ieee80211_i.h"
21
static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
23
return (fc & 0x8C) == 0x88;
28
ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
30
u8 *data = rx->skb->data;
32
unsigned int is_agg_frame = 0;
34
/* does the frame have a qos control field? */
35
if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
36
u8 *qc = data + iwlwifi_ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
38
/* frame has qos control */
39
rx->u.rx.qos_control = le16_to_cpu(*((__le16*)qc));
40
tid = rx->u.rx.qos_control & QOS_CONTROL_TID_MASK;
41
if (rx->u.rx.qos_control &
42
IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
45
if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
46
/* Separate TID for management frames */
47
tid = NUM_RX_DATA_QUEUES - 1;
49
/* no qos control present */
50
tid = 0; /* 802.1d - Best Effort */
52
rx->u.rx.qos_control = 0;
54
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
55
I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
57
I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
59
#endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
62
rx->u.rx.is_agg_frame = is_agg_frame;
63
/* Set skb->priority to 1d tag if highest order bit of TID is not set.
64
* For now, set skb->priority to 0 for other cases. */
65
rx->skb->priority = (tid > 7) ? 0 : tid;
72
ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
75
u8 *data = rx->skb->data;
76
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
78
if (!WLAN_FC_IS_QOS_DATA(fc))
81
/* remove the qos control field, update frame type and meta-data */
82
memmove(data + 2, data, iwlwifi_ieee80211_get_hdrlen(fc) - 2);
83
hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
84
/* change frame type to non QOS */
85
rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
86
hdr->frame_control = cpu_to_le16(fc);
92
#ifdef CONFIG_NET_SCHED
93
/* maximum number of hardware queues we support. */
94
#define TC_80211_MAX_QUEUES 16
96
struct ieee80211_sched_data
98
struct tcf_proto *filter_list;
99
struct Qdisc *queues[TC_80211_MAX_QUEUES];
100
struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
101
unsigned long qdisc_pool;
105
/* given a data frame determine the 802.1p/1d tag to use */
106
static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
112
struct ieee80211_sched_data *q = qdisc_priv(qd);
113
struct tcf_result res = { -1, 0 };
115
/* if there is a user set filter list, call out to that */
116
if (q->filter_list) {
117
tc_classify(skb, q->filter_list, &res);
122
/* skb->priority values from 256->263 are magic values to
123
* directly indicate a specific 802.1d priority.
124
* This is used to allow 802.1d priority to be passed directly in
125
* from VLAN tags, etc. */
126
if (skb->priority >= 256 && skb->priority <= 263)
127
return skb->priority - 256;
129
/* check there is a valid IP header present */
130
offset = iwlwifi_iwlwifi_ieee80211_get_hdrlen_from_skb(skb) + 8 /* LLC + proto */;
131
if (skb->protocol != __constant_htons(ETH_P_IP) ||
132
skb->len < offset + sizeof(*ip))
135
ip = (struct iphdr *) (skb->data + offset);
137
dscp = ip->tos & 0xfc;
144
static inline int wme_downgrade_ac(struct sk_buff *skb)
146
switch (skb->priority) {
149
skb->priority = 5; /* VO -> VI */
153
skb->priority = 3; /* VI -> BE */
157
skb->priority = 2; /* BE -> BK */
165
/* positive return value indicates which queue to use
166
* negative return value indicates to drop the frame */
167
static inline int classify80211(struct sk_buff *skb, struct Qdisc *qd)
169
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
170
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(qd->dev);
171
struct ieee80211_if_sta *ifsta = &sdata->u.sta;
172
struct ieee80211_tx_packet_data *pkt_data =
173
(struct ieee80211_tx_packet_data *) skb->cb;
174
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
175
unsigned short fc = le16_to_cpu(hdr->frame_control);
177
const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
179
/* see if frame is data or non data frame */
180
if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) {
181
/* management frames go on AC_VO queue, but are sent
182
* without QoS control fields */
183
return IEEE80211_TX_QUEUE_DATA0;
186
if (unlikely(pkt_data->mgmt_iface)) {
187
/* Data frames from hostapd (mainly, EAPOL) use AC_VO
188
* and they will include QoS control fields if
189
* the target STA is using WME. */
191
return ieee802_1d_to_ac[skb->priority];
194
/* is this a QoS frame? */
195
qos = fc & IEEE80211_STYPE_QOS_DATA;
198
skb->priority = 0; /* required for correct WPA/11i MIC */
199
return ieee802_1d_to_ac[skb->priority];
202
/* use the data classifier to determine what 802.1d tag the
204
skb->priority = classify_1d(skb, qd);
205
tsid = 8 + skb->priority;
207
/* FIXME: only uplink needs to be checked for Tx */
210
if ((sdata->type == IEEE80211_IF_TYPE_STA) &&
211
(local->wmm_acm & BIT(skb->priority))) {
212
switch (ifsta->ts_data[tsid][dir].status) {
213
case TS_STATUS_ACTIVE:
214
/* if TS Management is enabled, update used_time */
215
ifsta->ts_data[tsid][dir].used_time_usec +=
216
ifsta->MPDUExchangeTime;
218
case TS_STATUS_THROTTLING:
219
/* if admitted time is used up, refuse to send more */
221
printk(KERN_DEBUG "QoS packet throttling\n");
228
/* in case we are a client verify acm is not set for this ac */
229
while ((local->wmm_acm & BIT(skb->priority)) &&
230
!((sdata->type == IEEE80211_IF_TYPE_STA) &&
231
(ifsta->ts_data[skb->priority + EDCA_TSID_MIN][dir].status
232
== TS_STATUS_ACTIVE))) {
233
if (wme_downgrade_ac(skb)) {
234
/* No AC with lower priority has acm=0, drop packet. */
239
/* look up which queue to use for frames with this 1d tag */
240
return ieee802_1d_to_ac[skb->priority];
244
static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
246
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
247
struct ieee80211_sched_data *q = qdisc_priv(qd);
248
struct ieee80211_tx_packet_data *pkt_data =
249
(struct ieee80211_tx_packet_data *) skb->cb;
250
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
251
unsigned short fc = le16_to_cpu(hdr->frame_control);
255
if (pkt_data->requeue) {
256
skb_queue_tail(&q->requeued[pkt_data->queue], skb);
261
queue = classify80211(skb, qd);
263
/* now we know the 1d priority, fill in the QoS header if there is one
265
if (WLAN_FC_IS_QOS_DATA(fc)) {
266
struct sta_info *sta;
267
u8 *p = skb->data + iwlwifi_ieee80211_get_hdrlen(fc) - 2;
268
u8 tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
270
if (local->wifi_wme_noack_test)
271
ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
272
QOS_CONTROL_ACK_POLICY_SHIFT;
273
/* qos header is 2 bytes, second reserved */
278
sta = iwlwifi_sta_info_get(local, hdr->addr1);
280
int ht_queue = sta->tx_queue_id[tid];
281
if ((ht_queue < local->hw.queues) &&
282
test_bit(ht_queue, &q->qdisc_pool)) {
284
pkt_data->ht_queue = 1;
286
printk(KERN_DEBUG "wme:%s ht_queue=%d,queue=%d pool=0x%lX qdisc=%p\n",
287
__func__,ht_queue,queue,q->qdisc_pool,q);
289
iwlwifi_sta_info_put(sta);
295
if (unlikely(queue >= local->hw.queues)) {
297
if (net_ratelimit()) {
298
printk(KERN_DEBUG "%s - queue=%d (hw does not "
300
__func__, queue, local->hw.queues - 1);
303
queue = local->hw.queues - 1;
306
if (unlikely(queue < 0)) {
311
pkt_data->queue = (unsigned int) queue;
312
qdisc = q->queues[queue];
313
err = qdisc->enqueue(skb, qdisc);
314
if (err == NET_XMIT_SUCCESS) {
316
qd->bstats.bytes += skb->len;
317
qd->bstats.packets++;
318
return NET_XMIT_SUCCESS;
326
/* TODO: clean up the cases where master_hard_start_xmit
327
* returns non 0 - it shouldn't ever do that. Once done we
328
* can remove this function */
329
static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
331
struct ieee80211_sched_data *q = qdisc_priv(qd);
332
struct ieee80211_tx_packet_data *pkt_data =
333
(struct ieee80211_tx_packet_data *) skb->cb;
337
/* we recorded which queue to use earlier! */
338
qdisc = q->queues[pkt_data->queue];
340
if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
349
static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
351
struct ieee80211_sched_data *q = qdisc_priv(qd);
352
struct net_device *dev = qd->dev;
353
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
354
struct ieee80211_hw *hw = &local->hw;
359
/* check all the h/w queues in numeric/priority order */
360
for (queue = 0; queue < hw->queues; queue++) {
361
/* see if there is room in this hardware queue */
362
if ((test_bit(IEEE80211_LINK_STATE_XOFF,&local->state[queue])) ||
363
(test_bit(IEEE80211_LINK_STATE_PENDING,&local->state[queue])) ||
364
(!test_bit(queue,&q->qdisc_pool)))
367
/* there is space - try and get a frame */
368
skb = skb_dequeue(&q->requeued[queue]);
374
qdisc = q->queues[queue];
375
skb = qdisc->dequeue(qdisc);
381
/* returning a NULL here when all the h/w queues are full means we
382
* never need to call netif_stop_queue in the driver */
387
static void wme_qdiscop_reset(struct Qdisc* qd)
389
struct ieee80211_sched_data *q = qdisc_priv(qd);
390
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
391
struct ieee80211_hw *hw = &local->hw;
394
/* QUESTION: should we have some hardware flush functionality here? */
396
for (queue = 0; queue < hw->queues; queue++) {
397
skb_queue_purge(&q->requeued[queue]);
398
qdisc_reset(q->queues[queue]);
404
static void wme_qdiscop_destroy(struct Qdisc* qd)
406
struct ieee80211_sched_data *q = qdisc_priv(qd);
407
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
408
struct ieee80211_hw *hw = &local->hw;
411
tcf_destroy_chain(q->filter_list);
412
q->filter_list = NULL;
414
for (queue=0; queue < hw->queues; queue++) {
415
skb_queue_purge(&q->requeued[queue]);
416
qdisc_destroy(q->queues[queue]);
417
q->queues[queue] = &noop_qdisc;
422
/* called whenever parameters are updated on existing qdisc */
423
static int wme_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt)
425
/* struct ieee80211_sched_data *q = qdisc_priv(qd);
427
/* check our options block is the right size */
428
/* copy any options to our local structure */
429
/* Ignore options block for now - always use static mapping
430
struct tc_ieee80211_qopt *qopt = RTA_DATA(opt);
432
if (opt->rta_len < RTA_LENGTH(sizeof(*qopt)))
434
memcpy(q->tag2queue, qopt->tag2queue, sizeof(qopt->tag2queue));
440
/* called during initial creation of qdisc on device */
441
static int wme_qdiscop_init(struct Qdisc *qd, struct rtattr *opt)
443
struct ieee80211_sched_data *q = qdisc_priv(qd);
444
struct net_device *dev = qd->dev;
445
struct ieee80211_local *local;
449
/* check that device is a mac80211 device */
450
if (!dev->ieee80211_ptr ||
451
dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
454
/* check this device is an ieee80211 master type device */
455
if (dev->type != ARPHRD_IEEE80211)
458
/* check that there is no qdisc currently attached to device
459
* this ensures that we will be the root qdisc. (I can't find a better
460
* way to test this explicitly) */
461
if (dev->qdisc_sleeping != &noop_qdisc)
464
if (qd->flags & TCQ_F_INGRESS)
467
local = wdev_priv(dev->ieee80211_ptr);
468
queues = local->hw.queues;
470
/* if options were passed in, set them */
472
err = wme_qdiscop_tune(qd, opt);
475
/* create child queues */
476
for (i = 0; i < queues; i++) {
477
skb_queue_head_init(&q->requeued[i]);
478
q->queues[i] = qdisc_create_dflt(qd->dev, &pfifo_qdisc_ops,
480
if (q->queues[i] == 0) {
481
q->queues[i] = &noop_qdisc;
482
printk(KERN_ERR "%s child qdisc %i creation failed", dev->name, i);
486
for (i = 0; i < 4; i++)
487
set_bit(i,&q->qdisc_pool);
493
static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
495
/* struct ieee80211_sched_data *q = qdisc_priv(qd);
496
unsigned char *p = skb->tail;
497
struct tc_ieee80211_qopt opt;
499
memcpy(&opt.tag2queue, q->tag2queue, TC_80211_MAX_TAG + 1);
500
RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
504
skb_trim(skb, p - skb->data);*/
509
static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
510
struct Qdisc *new, struct Qdisc **old)
512
struct ieee80211_sched_data *q = qdisc_priv(qd);
513
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
514
struct ieee80211_hw *hw = &local->hw;
515
unsigned long queue = arg - 1;
517
if (queue >= hw->queues)
524
*old = q->queues[queue];
525
q->queues[queue] = new;
533
static struct Qdisc *
534
wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
536
struct ieee80211_sched_data *q = qdisc_priv(qd);
537
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
538
struct ieee80211_hw *hw = &local->hw;
539
unsigned long queue = arg - 1;
541
if (queue >= hw->queues)
544
return q->queues[queue];
548
static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
550
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
551
struct ieee80211_hw *hw = &local->hw;
552
unsigned long queue = TC_H_MIN(classid);
554
if (queue - 1 >= hw->queues)
561
static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
564
return wme_classop_get(qd, classid);
568
static void wme_classop_put(struct Qdisc *q, unsigned long cl)
573
static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
574
struct rtattr **tca, unsigned long *arg)
576
unsigned long cl = *arg;
577
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
578
struct ieee80211_hw *hw = &local->hw;
580
if (cl - 1 > hw->queues)
583
/* TODO: put code to program hardware queue parameters here,
584
* to allow programming from tc command line */
590
/* we don't support deleting hardware queues
591
* when we add WMM-SA support - TSPECs may be deleted here */
592
static int wme_classop_delete(struct Qdisc *qd, unsigned long cl)
594
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
595
struct ieee80211_hw *hw = &local->hw;
597
if (cl - 1 > hw->queues)
603
static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
604
struct sk_buff *skb, struct tcmsg *tcm)
606
struct ieee80211_sched_data *q = qdisc_priv(qd);
607
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
608
struct ieee80211_hw *hw = &local->hw;
610
if (cl - 1 > hw->queues)
612
tcm->tcm_handle = TC_H_MIN(cl);
613
tcm->tcm_parent = qd->handle;
614
tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */
619
static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
621
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
622
struct ieee80211_hw *hw = &local->hw;
628
for (queue = 0; queue < hw->queues; queue++) {
629
if (arg->count < arg->skip) {
633
/* we should return classids for our internal queues here
634
* as well as the external ones */
635
if (arg->fn(qd, queue+1, arg) < 0) {
644
static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
647
struct ieee80211_sched_data *q = qdisc_priv(qd);
652
return &q->filter_list;
656
/* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached)
657
* - these are the operations on the classes */
658
static struct Qdisc_class_ops class_ops =
660
.graft = wme_classop_graft,
661
.leaf = wme_classop_leaf,
663
.get = wme_classop_get,
664
.put = wme_classop_put,
665
.change = wme_classop_change,
666
.delete = wme_classop_delete,
667
.walk = wme_classop_walk,
669
.tcf_chain = wme_classop_find_tcf,
670
.bind_tcf = wme_classop_bind,
671
.unbind_tcf = wme_classop_put,
673
.dump = wme_classop_dump_class,
677
/* queueing discipline operations */
678
static struct Qdisc_ops wme_qdisc_ops =
681
.cl_ops = &class_ops,
683
.priv_size = sizeof(struct ieee80211_sched_data),
685
.enqueue = wme_qdiscop_enqueue,
686
.dequeue = wme_qdiscop_dequeue,
687
.requeue = wme_qdiscop_requeue,
688
.drop = NULL, /* drop not needed since we are always the root qdisc */
690
.init = wme_qdiscop_init,
691
.reset = wme_qdiscop_reset,
692
.destroy = wme_qdiscop_destroy,
693
.change = wme_qdiscop_tune,
695
.dump = wme_qdiscop_dump,
699
void ieee80211_install_qdisc(struct net_device *dev)
703
qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops, TC_H_ROOT);
705
printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
709
/* same handle as would be allocated by qdisc_alloc_handle() */
710
qdisc->handle = 0x80010000;
712
qdisc_lock_tree(dev);
713
list_add_tail(&qdisc->list, &dev->qdisc_list);
714
dev->qdisc_sleeping = qdisc;
715
qdisc_unlock_tree(dev);
719
int ieee80211_qdisc_installed(struct net_device *dev)
721
return dev->qdisc_sleeping->ops == &wme_qdisc_ops;
725
int ieee80211_wme_register(void)
727
return register_qdisc(&wme_qdisc_ops);
731
void ieee80211_wme_unregister(void)
733
unregister_qdisc(&wme_qdisc_ops);
735
#endif /* CONFIG_NET_SCHED */
737
int ieee80211_ht_agg_queue_add(struct ieee80211_local *local, struct sta_info *sta, u16 tid)
739
#ifdef CONFIG_NET_SCHED
741
struct ieee80211_sched_data *q = qdisc_priv(local->mdev->qdisc_sleeping);
743
/* prepare the filter and save it for the SW queue
744
* matching the recieved HW queue
745
* (TODO - policy should be replaced for AP)*/
747
/* try to get a Qdisc from a pool */
748
/* FIXME: use test and set command */
749
for (i=7; i < local->hw.queues; i++)
750
if (!test_and_set_bit(i, &q->qdisc_pool)) {
751
sta->tx_queue_id[tid] = i;
753
/* IF there are already pending packets
754
* on this tid first we need to drain them
755
* on the previous queue
756
* since HT is strict in order */
757
#ifdef CONFIG_MAC80211_DEBUG
758
printk(KERN_ERR "mac80211:wme allocated ht agg queue %d"
759
"for tid=%d and sta " MAC_FMT "pool=0x%lX qdisc=%p\n",
760
i,tid,MAC_ARG(sta->addr),q->qdisc_pool,q);
761
#endif /* CONFIG_MAC80211_DEBUG */
765
#endif /* CONFIG_NET_SCHED */
769
int ieee80211_ht_agg_queue_remove(struct ieee80211_local *local, struct sta_info *sta, u16 tid)
771
#ifdef CONFIG_NET_SCHED
773
struct ieee80211_sched_data *q = qdisc_priv(local->mdev->qdisc_sleeping);
775
/* return the qdisc to the pool */
776
i = sta->tx_queue_id[tid];
777
clear_bit(i, &q->qdisc_pool);
778
sta->tx_queue_id[tid] = local->hw.queues;
780
#endif /* CONFIG_NET_SCHED */