blob: 8ffff27fe00050d293cd0e38ae7c77ca20004bcb [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * Copyright 2004, Instant802 Networks, Inc.
3 *
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.
7 */
8
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>
14#include <net/ip.h>
15#include <net/pkt_sched.h>
16
17#include <net/mac80211.h>
18#include "ieee80211_i.h"
19#include "wme.h"
20
Jiri Bencf0706e82007-05-05 11:45:53 -070021/* maximum number of hardware queues we support. */
Johannes Berge100bb62008-04-30 18:51:21 +020022#define QD_MAX_QUEUES (IEEE80211_MAX_AMPDU_QUEUES + IEEE80211_MAX_QUEUES)
23/* current number of hardware queues we support. */
24#define QD_NUM(hw) ((hw)->queues + (hw)->ampdu_queues)
Ron Rindjunsky9e723492008-01-28 14:07:18 +020025
Johannes Berge100bb62008-04-30 18:51:21 +020026/*
27 * Default mapping in classifier to work with default
28 * queue setup.
29 */
Ron Rindjunsky9e723492008-01-28 14:07:18 +020030const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
Jiri Bencf0706e82007-05-05 11:45:53 -070031
32struct ieee80211_sched_data
33{
Johannes Berge100bb62008-04-30 18:51:21 +020034 unsigned long qdisc_pool[BITS_TO_LONGS(QD_MAX_QUEUES)];
Jiri Bencf0706e82007-05-05 11:45:53 -070035 struct tcf_proto *filter_list;
Johannes Berge100bb62008-04-30 18:51:21 +020036 struct Qdisc *queues[QD_MAX_QUEUES];
37 struct sk_buff_head requeued[QD_MAX_QUEUES];
Jiri Bencf0706e82007-05-05 11:45:53 -070038};
39
Guy Cohena8bdf292008-01-09 19:12:48 +020040static const char llc_ip_hdr[8] = {0xAA, 0xAA, 0x3, 0, 0, 0, 0x08, 0};
Jiri Bencf0706e82007-05-05 11:45:53 -070041
42/* given a data frame determine the 802.1p/1d tag to use */
43static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
44{
45 struct iphdr *ip;
46 int dscp;
47 int offset;
48
49 struct ieee80211_sched_data *q = qdisc_priv(qd);
50 struct tcf_result res = { -1, 0 };
51
52 /* if there is a user set filter list, call out to that */
53 if (q->filter_list) {
54 tc_classify(skb, q->filter_list, &res);
55 if (res.class != -1)
56 return res.class;
57 }
58
59 /* skb->priority values from 256->263 are magic values to
60 * directly indicate a specific 802.1d priority.
61 * This is used to allow 802.1d priority to be passed directly in
62 * from VLAN tags, etc. */
63 if (skb->priority >= 256 && skb->priority <= 263)
64 return skb->priority - 256;
65
66 /* check there is a valid IP header present */
Guy Cohena8bdf292008-01-09 19:12:48 +020067 offset = ieee80211_get_hdrlen_from_skb(skb);
68 if (skb->len < offset + sizeof(llc_ip_hdr) + sizeof(*ip) ||
69 memcmp(skb->data + offset, llc_ip_hdr, sizeof(llc_ip_hdr)))
Jiri Bencf0706e82007-05-05 11:45:53 -070070 return 0;
71
Guy Cohena8bdf292008-01-09 19:12:48 +020072 ip = (struct iphdr *) (skb->data + offset + sizeof(llc_ip_hdr));
Jiri Bencf0706e82007-05-05 11:45:53 -070073
74 dscp = ip->tos & 0xfc;
75 if (dscp & 0x1c)
76 return 0;
77 return dscp >> 5;
78}
79
80
81static inline int wme_downgrade_ac(struct sk_buff *skb)
82{
83 switch (skb->priority) {
84 case 6:
85 case 7:
86 skb->priority = 5; /* VO -> VI */
87 return 0;
88 case 4:
89 case 5:
90 skb->priority = 3; /* VI -> BE */
91 return 0;
92 case 0:
93 case 3:
94 skb->priority = 2; /* BE -> BK */
95 return 0;
96 default:
97 return -1;
98 }
99}
100
101
102/* positive return value indicates which queue to use
103 * negative return value indicates to drop the frame */
Johannes Berge100bb62008-04-30 18:51:21 +0200104static int classify80211(struct sk_buff *skb, struct Qdisc *qd)
Jiri Bencf0706e82007-05-05 11:45:53 -0700105{
106 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
Jiri Bencf0706e82007-05-05 11:45:53 -0700107 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
108 unsigned short fc = le16_to_cpu(hdr->frame_control);
109 int qos;
Jiri Bencf0706e82007-05-05 11:45:53 -0700110
111 /* see if frame is data or non data frame */
112 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) {
113 /* management frames go on AC_VO queue, but are sent
114 * without QoS control fields */
Johannes Berge100bb62008-04-30 18:51:21 +0200115 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700116 }
117
Johannes Bergf9d540e2007-09-28 14:02:09 +0200118 if (0 /* injected */) {
119 /* use AC from radiotap */
Jiri Bencf0706e82007-05-05 11:45:53 -0700120 }
121
122 /* is this a QoS frame? */
123 qos = fc & IEEE80211_STYPE_QOS_DATA;
124
125 if (!qos) {
126 skb->priority = 0; /* required for correct WPA/11i MIC */
127 return ieee802_1d_to_ac[skb->priority];
128 }
129
130 /* use the data classifier to determine what 802.1d tag the
Johannes Berg3c3b00c2007-08-28 17:01:55 -0400131 * data frame has */
Jiri Bencf0706e82007-05-05 11:45:53 -0700132 skb->priority = classify_1d(skb, qd);
133
Johannes Berg3c3b00c2007-08-28 17:01:55 -0400134 /* in case we are a client verify acm is not set for this ac */
Jiri Bencf0706e82007-05-05 11:45:53 -0700135 while (unlikely(local->wmm_acm & BIT(skb->priority))) {
136 if (wme_downgrade_ac(skb)) {
Johannes Berg3c3b00c2007-08-28 17:01:55 -0400137 /* No AC with lower priority has acm=0, drop packet. */
Jiri Bencf0706e82007-05-05 11:45:53 -0700138 return -1;
139 }
140 }
141
142 /* look up which queue to use for frames with this 1d tag */
143 return ieee802_1d_to_ac[skb->priority];
144}
145
146
147static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
148{
149 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
Johannes Berge100bb62008-04-30 18:51:21 +0200150 struct ieee80211_hw *hw = &local->hw;
Jiri Bencf0706e82007-05-05 11:45:53 -0700151 struct ieee80211_sched_data *q = qdisc_priv(qd);
152 struct ieee80211_tx_packet_data *pkt_data =
153 (struct ieee80211_tx_packet_data *) skb->cb;
154 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
155 unsigned short fc = le16_to_cpu(hdr->frame_control);
156 struct Qdisc *qdisc;
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200157 struct sta_info *sta;
Johannes Berg5c5e1282008-05-03 00:44:09 +0200158 int err, queue;
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200159 u8 tid;
Jiri Bencf0706e82007-05-05 11:45:53 -0700160
Jiri Slabye8bf9642007-08-28 17:01:54 -0400161 if (pkt_data->flags & IEEE80211_TXPD_REQUEUE) {
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200162 queue = pkt_data->queue;
Johannes Bergd0709a62008-02-25 16:27:46 +0100163 rcu_read_lock();
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200164 sta = sta_info_get(local, hdr->addr1);
165 tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
166 if (sta) {
167 int ampdu_queue = sta->tid_to_tx_q[tid];
Johannes Berge100bb62008-04-30 18:51:21 +0200168 if ((ampdu_queue < QD_NUM(hw)) &&
Ron Rindjunskya9af2012008-01-30 12:58:45 +0200169 test_bit(ampdu_queue, q->qdisc_pool)) {
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200170 queue = ampdu_queue;
171 pkt_data->flags |= IEEE80211_TXPD_AMPDU;
172 } else {
173 pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
174 }
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200175 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100176 rcu_read_unlock();
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200177 skb_queue_tail(&q->requeued[queue], skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700178 qd->q.qlen++;
179 return 0;
180 }
181
182 queue = classify80211(skb, qd);
183
Johannes Berge100bb62008-04-30 18:51:21 +0200184 if (unlikely(queue >= local->hw.queues))
185 queue = local->hw.queues - 1;
186
Jiri Bencf0706e82007-05-05 11:45:53 -0700187 /* now we know the 1d priority, fill in the QoS header if there is one
188 */
189 if (WLAN_FC_IS_QOS_DATA(fc)) {
190 u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2;
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200191 u8 ack_policy = 0;
192 tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
Jiri Bencf0706e82007-05-05 11:45:53 -0700193 if (local->wifi_wme_noack_test)
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200194 ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
Jiri Bencf0706e82007-05-05 11:45:53 -0700195 QOS_CONTROL_ACK_POLICY_SHIFT;
196 /* qos header is 2 bytes, second reserved */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200197 *p = ack_policy | tid;
Jiri Bencf0706e82007-05-05 11:45:53 -0700198 p++;
199 *p = 0;
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200200
Johannes Bergd0709a62008-02-25 16:27:46 +0100201 rcu_read_lock();
202
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200203 sta = sta_info_get(local, hdr->addr1);
204 if (sta) {
205 int ampdu_queue = sta->tid_to_tx_q[tid];
Johannes Berge100bb62008-04-30 18:51:21 +0200206 if ((ampdu_queue < QD_NUM(hw)) &&
207 test_bit(ampdu_queue, q->qdisc_pool)) {
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200208 queue = ampdu_queue;
209 pkt_data->flags |= IEEE80211_TXPD_AMPDU;
210 } else {
211 pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
212 }
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200213 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100214
215 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -0700216 }
217
Johannes Berg5c5e1282008-05-03 00:44:09 +0200218 if (unlikely(queue < 0)) {
219 kfree_skb(skb);
220 err = NET_XMIT_DROP;
221 } else {
222 tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
223 pkt_data->queue = (unsigned int) queue;
224 qdisc = q->queues[queue];
225 err = qdisc->enqueue(skb, qdisc);
226 if (err == NET_XMIT_SUCCESS) {
227 qd->q.qlen++;
228 qd->bstats.bytes += skb->len;
229 qd->bstats.packets++;
230 return NET_XMIT_SUCCESS;
231 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700232 }
233 qd->qstats.drops++;
234 return err;
235}
236
237
238/* TODO: clean up the cases where master_hard_start_xmit
239 * returns non 0 - it shouldn't ever do that. Once done we
240 * can remove this function */
241static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
242{
243 struct ieee80211_sched_data *q = qdisc_priv(qd);
244 struct ieee80211_tx_packet_data *pkt_data =
245 (struct ieee80211_tx_packet_data *) skb->cb;
246 struct Qdisc *qdisc;
247 int err;
248
249 /* we recorded which queue to use earlier! */
250 qdisc = q->queues[pkt_data->queue];
251
252 if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
253 qd->q.qlen++;
254 return 0;
255 }
256 qd->qstats.drops++;
257 return err;
258}
259
260
261static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
262{
263 struct ieee80211_sched_data *q = qdisc_priv(qd);
264 struct net_device *dev = qd->dev;
265 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
266 struct ieee80211_hw *hw = &local->hw;
267 struct sk_buff *skb;
268 struct Qdisc *qdisc;
269 int queue;
270
271 /* check all the h/w queues in numeric/priority order */
Johannes Berge100bb62008-04-30 18:51:21 +0200272 for (queue = 0; queue < QD_NUM(hw); queue++) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700273 /* see if there is room in this hardware queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200274 if ((test_bit(IEEE80211_LINK_STATE_XOFF,
275 &local->state[queue])) ||
276 (test_bit(IEEE80211_LINK_STATE_PENDING,
277 &local->state[queue])) ||
Ron Rindjunskya9af2012008-01-30 12:58:45 +0200278 (!test_bit(queue, q->qdisc_pool)))
Jiri Bencf0706e82007-05-05 11:45:53 -0700279 continue;
280
281 /* there is space - try and get a frame */
282 skb = skb_dequeue(&q->requeued[queue]);
283 if (skb) {
284 qd->q.qlen--;
285 return skb;
286 }
287
288 qdisc = q->queues[queue];
289 skb = qdisc->dequeue(qdisc);
290 if (skb) {
291 qd->q.qlen--;
292 return skb;
293 }
294 }
295 /* returning a NULL here when all the h/w queues are full means we
296 * never need to call netif_stop_queue in the driver */
297 return NULL;
298}
299
300
301static void wme_qdiscop_reset(struct Qdisc* qd)
302{
303 struct ieee80211_sched_data *q = qdisc_priv(qd);
304 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
305 struct ieee80211_hw *hw = &local->hw;
306 int queue;
307
308 /* QUESTION: should we have some hardware flush functionality here? */
309
Johannes Berge100bb62008-04-30 18:51:21 +0200310 for (queue = 0; queue < QD_NUM(hw); queue++) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700311 skb_queue_purge(&q->requeued[queue]);
312 qdisc_reset(q->queues[queue]);
313 }
314 qd->q.qlen = 0;
315}
316
317
318static void wme_qdiscop_destroy(struct Qdisc* qd)
319{
320 struct ieee80211_sched_data *q = qdisc_priv(qd);
321 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
322 struct ieee80211_hw *hw = &local->hw;
323 int queue;
324
325 tcf_destroy_chain(q->filter_list);
326 q->filter_list = NULL;
327
Johannes Berge100bb62008-04-30 18:51:21 +0200328 for (queue = 0; queue < QD_NUM(hw); queue++) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700329 skb_queue_purge(&q->requeued[queue]);
330 qdisc_destroy(q->queues[queue]);
331 q->queues[queue] = &noop_qdisc;
332 }
333}
334
335
336/* called whenever parameters are updated on existing qdisc */
Patrick McHardy1e904742008-01-22 22:11:17 -0800337static int wme_qdiscop_tune(struct Qdisc *qd, struct nlattr *opt)
Jiri Bencf0706e82007-05-05 11:45:53 -0700338{
Jiri Bencf0706e82007-05-05 11:45:53 -0700339 return 0;
340}
341
342
343/* called during initial creation of qdisc on device */
Patrick McHardy1e904742008-01-22 22:11:17 -0800344static int wme_qdiscop_init(struct Qdisc *qd, struct nlattr *opt)
Jiri Bencf0706e82007-05-05 11:45:53 -0700345{
346 struct ieee80211_sched_data *q = qdisc_priv(qd);
347 struct net_device *dev = qd->dev;
348 struct ieee80211_local *local;
Johannes Berge100bb62008-04-30 18:51:21 +0200349 struct ieee80211_hw *hw;
Jiri Bencf0706e82007-05-05 11:45:53 -0700350 int err = 0, i;
351
352 /* check that device is a mac80211 device */
353 if (!dev->ieee80211_ptr ||
354 dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
355 return -EINVAL;
356
Johannes Berge100bb62008-04-30 18:51:21 +0200357 local = wdev_priv(dev->ieee80211_ptr);
358 hw = &local->hw;
359
360 /* only allow on master dev */
361 if (dev != local->mdev)
Jiri Bencf0706e82007-05-05 11:45:53 -0700362 return -EINVAL;
363
Johannes Berge100bb62008-04-30 18:51:21 +0200364 /* ensure that we are root qdisc */
365 if (qd->parent != TC_H_ROOT)
Jiri Bencf0706e82007-05-05 11:45:53 -0700366 return -EINVAL;
367
368 if (qd->flags & TCQ_F_INGRESS)
369 return -EINVAL;
370
Jiri Bencf0706e82007-05-05 11:45:53 -0700371 /* if options were passed in, set them */
Johannes Berge100bb62008-04-30 18:51:21 +0200372 if (opt)
Jiri Bencf0706e82007-05-05 11:45:53 -0700373 err = wme_qdiscop_tune(qd, opt);
Jiri Bencf0706e82007-05-05 11:45:53 -0700374
375 /* create child queues */
Johannes Berge100bb62008-04-30 18:51:21 +0200376 for (i = 0; i < QD_NUM(hw); i++) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700377 skb_queue_head_init(&q->requeued[i]);
378 q->queues[i] = qdisc_create_dflt(qd->dev, &pfifo_qdisc_ops,
379 qd->handle);
Johannes Berg136e83d2007-09-10 13:55:08 +0200380 if (!q->queues[i]) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700381 q->queues[i] = &noop_qdisc;
382 printk(KERN_ERR "%s child qdisc %i creation failed", dev->name, i);
383 }
384 }
385
Johannes Berge100bb62008-04-30 18:51:21 +0200386 /* non-aggregation queues: reserve/mark as used */
387 for (i = 0; i < local->hw.queues; i++)
Ron Rindjunskya9af2012008-01-30 12:58:45 +0200388 set_bit(i, q->qdisc_pool);
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200389
Jiri Bencf0706e82007-05-05 11:45:53 -0700390 return err;
391}
392
393static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
394{
Jiri Bencf0706e82007-05-05 11:45:53 -0700395 return -1;
396}
397
398
399static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
400 struct Qdisc *new, struct Qdisc **old)
401{
402 struct ieee80211_sched_data *q = qdisc_priv(qd);
403 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
404 struct ieee80211_hw *hw = &local->hw;
405 unsigned long queue = arg - 1;
406
Johannes Berge100bb62008-04-30 18:51:21 +0200407 if (queue >= QD_NUM(hw))
Jiri Bencf0706e82007-05-05 11:45:53 -0700408 return -EINVAL;
409
410 if (!new)
411 new = &noop_qdisc;
412
413 sch_tree_lock(qd);
414 *old = q->queues[queue];
415 q->queues[queue] = new;
416 qdisc_reset(*old);
417 sch_tree_unlock(qd);
418
419 return 0;
420}
421
422
423static struct Qdisc *
424wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
425{
426 struct ieee80211_sched_data *q = qdisc_priv(qd);
427 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
428 struct ieee80211_hw *hw = &local->hw;
429 unsigned long queue = arg - 1;
430
Johannes Berge100bb62008-04-30 18:51:21 +0200431 if (queue >= QD_NUM(hw))
Jiri Bencf0706e82007-05-05 11:45:53 -0700432 return NULL;
433
434 return q->queues[queue];
435}
436
437
438static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
439{
440 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
441 struct ieee80211_hw *hw = &local->hw;
442 unsigned long queue = TC_H_MIN(classid);
443
Johannes Berge100bb62008-04-30 18:51:21 +0200444 if (queue - 1 >= QD_NUM(hw))
Jiri Bencf0706e82007-05-05 11:45:53 -0700445 return 0;
446
447 return queue;
448}
449
450
451static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
452 u32 classid)
453{
454 return wme_classop_get(qd, classid);
455}
456
457
458static void wme_classop_put(struct Qdisc *q, unsigned long cl)
459{
460}
461
462
463static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
Patrick McHardy1e904742008-01-22 22:11:17 -0800464 struct nlattr **tca, unsigned long *arg)
Jiri Bencf0706e82007-05-05 11:45:53 -0700465{
466 unsigned long cl = *arg;
467 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
468 struct ieee80211_hw *hw = &local->hw;
469
Johannes Berge100bb62008-04-30 18:51:21 +0200470 if (cl - 1 > QD_NUM(hw))
Jiri Bencf0706e82007-05-05 11:45:53 -0700471 return -ENOENT;
472
473 /* TODO: put code to program hardware queue parameters here,
474 * to allow programming from tc command line */
475
476 return 0;
477}
478
479
480/* we don't support deleting hardware queues
481 * when we add WMM-SA support - TSPECs may be deleted here */
482static int wme_classop_delete(struct Qdisc *qd, unsigned long cl)
483{
484 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
485 struct ieee80211_hw *hw = &local->hw;
486
Johannes Berge100bb62008-04-30 18:51:21 +0200487 if (cl - 1 > QD_NUM(hw))
Jiri Bencf0706e82007-05-05 11:45:53 -0700488 return -ENOENT;
489 return 0;
490}
491
492
493static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
494 struct sk_buff *skb, struct tcmsg *tcm)
495{
496 struct ieee80211_sched_data *q = qdisc_priv(qd);
497 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
498 struct ieee80211_hw *hw = &local->hw;
499
Johannes Berge100bb62008-04-30 18:51:21 +0200500 if (cl - 1 > QD_NUM(hw))
Jiri Bencf0706e82007-05-05 11:45:53 -0700501 return -ENOENT;
502 tcm->tcm_handle = TC_H_MIN(cl);
503 tcm->tcm_parent = qd->handle;
504 tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */
505 return 0;
506}
507
508
509static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
510{
511 struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
512 struct ieee80211_hw *hw = &local->hw;
513 int queue;
514
515 if (arg->stop)
516 return;
517
Johannes Berge100bb62008-04-30 18:51:21 +0200518 for (queue = 0; queue < QD_NUM(hw); queue++) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700519 if (arg->count < arg->skip) {
520 arg->count++;
521 continue;
522 }
523 /* we should return classids for our internal queues here
524 * as well as the external ones */
525 if (arg->fn(qd, queue+1, arg) < 0) {
526 arg->stop = 1;
527 break;
528 }
529 arg->count++;
530 }
531}
532
533
534static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
535 unsigned long cl)
536{
537 struct ieee80211_sched_data *q = qdisc_priv(qd);
538
539 if (cl)
540 return NULL;
541
542 return &q->filter_list;
543}
544
545
546/* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached)
547 * - these are the operations on the classes */
Eric Dumazet20fea082007-11-14 01:44:41 -0800548static const struct Qdisc_class_ops class_ops =
Jiri Bencf0706e82007-05-05 11:45:53 -0700549{
550 .graft = wme_classop_graft,
551 .leaf = wme_classop_leaf,
552
553 .get = wme_classop_get,
554 .put = wme_classop_put,
555 .change = wme_classop_change,
556 .delete = wme_classop_delete,
557 .walk = wme_classop_walk,
558
559 .tcf_chain = wme_classop_find_tcf,
560 .bind_tcf = wme_classop_bind,
561 .unbind_tcf = wme_classop_put,
562
563 .dump = wme_classop_dump_class,
564};
565
566
567/* queueing discipline operations */
Eric Dumazet20fea082007-11-14 01:44:41 -0800568static struct Qdisc_ops wme_qdisc_ops __read_mostly =
Jiri Bencf0706e82007-05-05 11:45:53 -0700569{
570 .next = NULL,
571 .cl_ops = &class_ops,
572 .id = "ieee80211",
573 .priv_size = sizeof(struct ieee80211_sched_data),
574
575 .enqueue = wme_qdiscop_enqueue,
576 .dequeue = wme_qdiscop_dequeue,
577 .requeue = wme_qdiscop_requeue,
578 .drop = NULL, /* drop not needed since we are always the root qdisc */
579
580 .init = wme_qdiscop_init,
581 .reset = wme_qdiscop_reset,
582 .destroy = wme_qdiscop_destroy,
583 .change = wme_qdiscop_tune,
584
585 .dump = wme_qdiscop_dump,
586};
587
588
589void ieee80211_install_qdisc(struct net_device *dev)
590{
591 struct Qdisc *qdisc;
592
593 qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops, TC_H_ROOT);
594 if (!qdisc) {
595 printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
596 return;
597 }
598
599 /* same handle as would be allocated by qdisc_alloc_handle() */
600 qdisc->handle = 0x80010000;
601
602 qdisc_lock_tree(dev);
603 list_add_tail(&qdisc->list, &dev->qdisc_list);
604 dev->qdisc_sleeping = qdisc;
605 qdisc_unlock_tree(dev);
606}
607
608
609int ieee80211_qdisc_installed(struct net_device *dev)
610{
611 return dev->qdisc_sleeping->ops == &wme_qdisc_ops;
612}
613
614
615int ieee80211_wme_register(void)
616{
617 return register_qdisc(&wme_qdisc_ops);
618}
619
620
621void ieee80211_wme_unregister(void)
622{
623 unregister_qdisc(&wme_qdisc_ops);
624}
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200625
626int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
627 struct sta_info *sta, u16 tid)
628{
629 int i;
630 struct ieee80211_sched_data *q =
631 qdisc_priv(local->mdev->qdisc_sleeping);
632 DECLARE_MAC_BUF(mac);
633
634 /* prepare the filter and save it for the SW queue
Johannes Berge100bb62008-04-30 18:51:21 +0200635 * matching the received HW queue */
636
637 if (!local->hw.ampdu_queues)
638 return -EPERM;
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200639
640 /* try to get a Qdisc from the pool */
Johannes Berge100bb62008-04-30 18:51:21 +0200641 for (i = local->hw.queues; i < QD_NUM(&local->hw); i++)
Ron Rindjunskya9af2012008-01-30 12:58:45 +0200642 if (!test_and_set_bit(i, q->qdisc_pool)) {
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200643 ieee80211_stop_queue(local_to_hw(local), i);
644 sta->tid_to_tx_q[tid] = i;
645
646 /* IF there are already pending packets
647 * on this tid first we need to drain them
648 * on the previous queue
649 * since HT is strict in order */
650#ifdef CONFIG_MAC80211_HT_DEBUG
651 if (net_ratelimit())
652 printk(KERN_DEBUG "allocated aggregation queue"
Ron Rindjunskya9af2012008-01-30 12:58:45 +0200653 " %d tid %d addr %s pool=0x%lX",
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200654 i, tid, print_mac(mac, sta->addr),
Ron Rindjunskya9af2012008-01-30 12:58:45 +0200655 q->qdisc_pool[0]);
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200656#endif /* CONFIG_MAC80211_HT_DEBUG */
657 return 0;
658 }
659
660 return -EAGAIN;
661}
662
663/**
664 * the caller needs to hold local->mdev->queue_lock
665 */
666void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
667 struct sta_info *sta, u16 tid,
668 u8 requeue)
669{
Johannes Berge100bb62008-04-30 18:51:21 +0200670 struct ieee80211_hw *hw = &local->hw;
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200671 struct ieee80211_sched_data *q =
672 qdisc_priv(local->mdev->qdisc_sleeping);
673 int agg_queue = sta->tid_to_tx_q[tid];
674
675 /* return the qdisc to the pool */
Ron Rindjunskya9af2012008-01-30 12:58:45 +0200676 clear_bit(agg_queue, q->qdisc_pool);
Johannes Berge100bb62008-04-30 18:51:21 +0200677 sta->tid_to_tx_q[tid] = QD_NUM(hw);
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200678
679 if (requeue)
680 ieee80211_requeue(local, agg_queue);
681 else
682 q->queues[agg_queue]->ops->reset(q->queues[agg_queue]);
683}
684
685void ieee80211_requeue(struct ieee80211_local *local, int queue)
686{
687 struct Qdisc *root_qd = local->mdev->qdisc_sleeping;
688 struct ieee80211_sched_data *q = qdisc_priv(root_qd);
689 struct Qdisc *qdisc = q->queues[queue];
690 struct sk_buff *skb = NULL;
Ron Rindjunsky0da926f2008-04-23 13:45:12 +0300691 u32 len;
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200692
693 if (!qdisc || !qdisc->dequeue)
694 return;
695
696 printk(KERN_DEBUG "requeue: qlen = %d\n", qdisc->q.qlen);
697 for (len = qdisc->q.qlen; len > 0; len--) {
698 skb = qdisc->dequeue(qdisc);
699 root_qd->q.qlen--;
700 /* packet will be classified again and */
701 /* skb->packet_data->queue will be overridden if needed */
702 if (skb)
703 wme_qdiscop_enqueue(skb, root_qd);
704 }
705}