New: mac80211 stack from the wireless-dev tree
[librecmc/librecmc.git] / package / mac80211 / src / mac80211 / wme.c
1 /*
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
21 static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
22 {
23         return (fc & 0x8C) == 0x88;
24 }
25
26
27 ieee80211_txrx_result
28 ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
29 {
30         u8 *data = rx->skb->data;
31         int tid;
32         unsigned int is_agg_frame = 0;
33
34         /* does the frame have a qos control field? */
35         if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
36                 u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
37
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)
43                         is_agg_frame = 1;
44         } else {
45                 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
46                         /* Separate TID for management frames */
47                         tid = NUM_RX_DATA_QUEUES - 1;
48                 } else {
49                         /* no qos control present */
50                         tid = 0; /* 802.1d - Best Effort */
51                 }
52                 rx->u.rx.qos_control = 0;
53         }
54 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
55         I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
56         if (rx->sta) {
57                 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
58         }
59 #endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
60
61         rx->u.rx.queue = tid;
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;
66
67         return TXRX_CONTINUE;
68 }
69
70
71 ieee80211_txrx_result
72 ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
73 {
74         u16 fc = rx->fc;
75         u8 *data = rx->skb->data;
76         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
77
78         if (!WLAN_FC_IS_QOS_DATA(fc))
79                 return TXRX_CONTINUE;
80
81         /* remove the qos control field, update frame type and meta-data */
82         memmove(data + 2, data, 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);
87
88         return TXRX_CONTINUE;
89 }
90
91
92 #ifdef CONFIG_NET_SCHED
93 /* maximum number of hardware queues we support. */
94 #define TC_80211_MAX_QUEUES 8
95
96 struct ieee80211_sched_data
97 {
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 };
102
103
104 /* given a data frame determine the 802.1p/1d tag to use */
105 static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
106 {
107         struct iphdr *ip;
108         int dscp;
109         int offset;
110
111         struct ieee80211_sched_data *q = qdisc_priv(qd);
112         struct tcf_result res = { -1, 0 };
113
114         /* if there is a user set filter list, call out to that */
115         if (q->filter_list) {
116                 tc_classify(skb, q->filter_list, &res);
117                 if (res.class != -1)
118                         return res.class;
119         }
120
121         /* skb->priority values from 256->263 are magic values to
122          * directly indicate a specific 802.1d priority.
123          * This is used to allow 802.1d priority to be passed directly in
124          * from VLAN tags, etc. */
125         if (skb->priority >= 256 && skb->priority <= 263)
126                 return skb->priority - 256;
127
128         /* check there is a valid IP header present */
129         offset = ieee80211_get_hdrlen_from_skb(skb) + 8 /* LLC + proto */;
130         if (skb->protocol != __constant_htons(ETH_P_IP) ||
131             skb->len < offset + sizeof(*ip))
132                 return 0;
133
134         ip = (struct iphdr *) (skb->data + offset);
135
136         dscp = ip->tos & 0xfc;
137         if (dscp & 0x1c)
138                 return 0;
139         return dscp >> 5;
140 }
141
142
143 static inline int wme_downgrade_ac(struct sk_buff *skb)
144 {
145         switch (skb->priority) {
146         case 6:
147         case 7:
148                 skb->priority = 5; /* VO -> VI */
149                 return 0;
150         case 4:
151         case 5:
152                 skb->priority = 3; /* VI -> BE */
153                 return 0;
154         case 0:
155         case 3:
156                 skb->priority = 2; /* BE -> BK */
157                 return 0;
158         default:
159                 return -1;
160         }
161 }
162
163
164 /* positive return value indicates which queue to use
165  * negative return value indicates to drop the frame */
166 static inline int classify80211(struct sk_buff *skb, struct Qdisc *qd)
167 {
168         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
169         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(qd->dev);
170         struct ieee80211_if_sta *ifsta = &sdata->u.sta;
171         struct ieee80211_tx_packet_data *pkt_data =
172                 (struct ieee80211_tx_packet_data *) skb->cb;
173         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
174         unsigned short fc = le16_to_cpu(hdr->frame_control);
175         int qos, tsid, dir;
176         const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
177
178         /* see if frame is data or non data frame */
179         if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) {
180                 /* management frames go on AC_VO queue, but are sent
181                 * without QoS control fields */
182                 return IEEE80211_TX_QUEUE_DATA0;
183         }
184
185         if (unlikely(pkt_data->mgmt_iface)) {
186                 /* Data frames from hostapd (mainly, EAPOL) use AC_VO
187                 * and they will include QoS control fields if
188                 * the target STA is using WME. */
189                 skb->priority = 7;
190                 return ieee802_1d_to_ac[skb->priority];
191         }
192
193         /* is this a QoS frame? */
194         qos = fc & IEEE80211_STYPE_QOS_DATA;
195
196         if (!qos) {
197                 skb->priority = 0; /* required for correct WPA/11i MIC */
198                 return ieee802_1d_to_ac[skb->priority];
199         }
200
201         /* use the data classifier to determine what 802.1d tag the
202          * data frame has */
203         skb->priority = classify_1d(skb, qd);
204         tsid = 8 + skb->priority;
205
206         /* FIXME: only uplink needs to be checked for Tx */
207         dir = STA_TS_UPLINK;
208
209         if ((sdata->type == IEEE80211_IF_TYPE_STA) &&
210             (local->wmm_acm & BIT(skb->priority))) {
211                 switch (ifsta->ts_data[tsid][dir].status) {
212                 case TS_STATUS_ACTIVE:
213                         /* if TS Management is enabled, update used_time */
214                         ifsta->ts_data[tsid][dir].used_time_usec +=
215                                 ifsta->MPDUExchangeTime;
216                         break;
217                 case TS_STATUS_THROTTLING:
218                         /* if admitted time is used up, refuse to send more */
219                         if (net_ratelimit())
220                                 printk(KERN_DEBUG "QoS packet throttling\n");
221                         break;
222                 default:
223                         break;
224                 }
225         }
226
227         /* in case we are a client verify acm is not set for this ac */
228         while ((local->wmm_acm & BIT(skb->priority)) &&
229                !((sdata->type == IEEE80211_IF_TYPE_STA) &&
230                  (ifsta->ts_data[skb->priority + EDCA_TSID_MIN][dir].status
231                         == TS_STATUS_ACTIVE))) {
232                 if (wme_downgrade_ac(skb)) {
233                         /* No AC with lower priority has acm=0, drop packet. */
234                         return -1;
235                 }
236         }
237
238         /* look up which queue to use for frames with this 1d tag */
239         return ieee802_1d_to_ac[skb->priority];
240 }
241
242
243 static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
244 {
245         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
246         struct ieee80211_sched_data *q = qdisc_priv(qd);
247         struct ieee80211_tx_packet_data *pkt_data =
248                 (struct ieee80211_tx_packet_data *) skb->cb;
249         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
250         unsigned short fc = le16_to_cpu(hdr->frame_control);
251         struct Qdisc *qdisc;
252         int err, queue;
253
254         if (pkt_data->requeue) {
255                 skb_queue_tail(&q->requeued[pkt_data->queue], skb);
256                 qd->q.qlen++;
257                 return 0;
258         }
259
260         queue = classify80211(skb, qd);
261
262         /* now we know the 1d priority, fill in the QoS header if there is one
263          */
264         if (WLAN_FC_IS_QOS_DATA(fc)) {
265                 u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2;
266                 u8 qos_hdr = skb->priority & QOS_CONTROL_TAG1D_MASK;
267                 if (local->wifi_wme_noack_test)
268                         qos_hdr |= QOS_CONTROL_ACK_POLICY_NOACK <<
269                                         QOS_CONTROL_ACK_POLICY_SHIFT;
270                 /* qos header is 2 bytes, second reserved */
271                 *p = qos_hdr;
272                 p++;
273                 *p = 0;
274         }
275
276         if (unlikely(queue >= local->hw.queues)) {
277 #if 0
278                 if (net_ratelimit()) {
279                         printk(KERN_DEBUG "%s - queue=%d (hw does not "
280                                "support) -> %d\n",
281                                __func__, queue, local->hw.queues - 1);
282                 }
283 #endif
284                 queue = local->hw.queues - 1;
285         }
286
287         if (unlikely(queue < 0)) {
288                         kfree_skb(skb);
289                         err = NET_XMIT_DROP;
290         } else {
291                 pkt_data->queue = (unsigned int) queue;
292                 qdisc = q->queues[queue];
293                 err = qdisc->enqueue(skb, qdisc);
294                 if (err == NET_XMIT_SUCCESS) {
295                         qd->q.qlen++;
296                         qd->bstats.bytes += skb->len;
297                         qd->bstats.packets++;
298                         return NET_XMIT_SUCCESS;
299                 }
300         }
301         qd->qstats.drops++;
302         return err;
303 }
304
305
306 /* TODO: clean up the cases where master_hard_start_xmit
307  * returns non 0 - it shouldn't ever do that. Once done we
308  * can remove this function */
309 static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
310 {
311         struct ieee80211_sched_data *q = qdisc_priv(qd);
312         struct ieee80211_tx_packet_data *pkt_data =
313                 (struct ieee80211_tx_packet_data *) skb->cb;
314         struct Qdisc *qdisc;
315         int err;
316
317         /* we recorded which queue to use earlier! */
318         qdisc = q->queues[pkt_data->queue];
319
320         if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
321                 qd->q.qlen++;
322                 return 0;
323         }
324         qd->qstats.drops++;
325         return err;
326 }
327
328
329 static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
330 {
331         struct ieee80211_sched_data *q = qdisc_priv(qd);
332         struct net_device *dev = qd->dev;
333         struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
334         struct ieee80211_hw *hw = &local->hw;
335         struct sk_buff *skb;
336         struct Qdisc *qdisc;
337         int queue;
338
339         /* check all the h/w queues in numeric/priority order */
340         for (queue = 0; queue < hw->queues; queue++) {
341                 /* see if there is room in this hardware queue */
342                 if (test_bit(IEEE80211_LINK_STATE_XOFF,
343                              &local->state[queue]) ||
344                     test_bit(IEEE80211_LINK_STATE_PENDING,
345                              &local->state[queue]))
346                         continue;
347
348                 /* there is space - try and get a frame */
349                 skb = skb_dequeue(&q->requeued[queue]);
350                 if (skb) {
351                         qd->q.qlen--;
352                         return skb;
353                 }
354
355                 qdisc = q->queues[queue];
356                 skb = qdisc->dequeue(qdisc);
357                 if (skb) {
358                         qd->q.qlen--;
359                         return skb;
360                 }
361         }
362         /* returning a NULL here when all the h/w queues are full means we
363          * never need to call netif_stop_queue in the driver */
364         return NULL;
365 }
366
367
368 static void wme_qdiscop_reset(struct Qdisc* qd)
369 {
370         struct ieee80211_sched_data *q = qdisc_priv(qd);
371         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
372         struct ieee80211_hw *hw = &local->hw;
373         int queue;
374
375         /* QUESTION: should we have some hardware flush functionality here? */
376
377         for (queue = 0; queue < hw->queues; queue++) {
378                 skb_queue_purge(&q->requeued[queue]);
379                 qdisc_reset(q->queues[queue]);
380         }
381         qd->q.qlen = 0;
382 }
383
384
385 static void wme_qdiscop_destroy(struct Qdisc* qd)
386 {
387         struct ieee80211_sched_data *q = qdisc_priv(qd);
388         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
389         struct ieee80211_hw *hw = &local->hw;
390         int queue;
391
392         tcf_destroy_chain(q->filter_list);
393         q->filter_list = NULL;
394
395         for (queue=0; queue < hw->queues; queue++) {
396                 skb_queue_purge(&q->requeued[queue]);
397                 qdisc_destroy(q->queues[queue]);
398                 q->queues[queue] = &noop_qdisc;
399         }
400 }
401
402
403 /* called whenever parameters are updated on existing qdisc */
404 static int wme_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt)
405 {
406 /*      struct ieee80211_sched_data *q = qdisc_priv(qd);
407 */
408         /* check our options block is the right size */
409         /* copy any options to our local structure */
410 /*      Ignore options block for now - always use static mapping
411         struct tc_ieee80211_qopt *qopt = RTA_DATA(opt);
412
413         if (opt->rta_len < RTA_LENGTH(sizeof(*qopt)))
414                 return -EINVAL;
415         memcpy(q->tag2queue, qopt->tag2queue, sizeof(qopt->tag2queue));
416 */
417         return 0;
418 }
419
420
421 /* called during initial creation of qdisc on device */
422 static int wme_qdiscop_init(struct Qdisc *qd, struct rtattr *opt)
423 {
424         struct ieee80211_sched_data *q = qdisc_priv(qd);
425         struct net_device *dev = qd->dev;
426         struct ieee80211_local *local;
427         int queues;
428         int err = 0, i;
429
430         /* check that device is a mac80211 device */
431         if (!dev->ieee80211_ptr ||
432             dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
433                 return -EINVAL;
434
435         /* check this device is an ieee80211 master type device */
436         if (dev->type != ARPHRD_IEEE80211)
437                 return -EINVAL;
438
439         /* check that there is no qdisc currently attached to device
440          * this ensures that we will be the root qdisc. (I can't find a better
441          * way to test this explicitly) */
442         if (dev->qdisc_sleeping != &noop_qdisc)
443                 return -EINVAL;
444
445         if (qd->flags & TCQ_F_INGRESS)
446                 return -EINVAL;
447
448         local = wdev_priv(dev->ieee80211_ptr);
449         queues = local->hw.queues;
450
451         /* if options were passed in, set them */
452         if (opt) {
453                 err = wme_qdiscop_tune(qd, opt);
454         }
455
456         /* create child queues */
457         for (i = 0; i < queues; i++) {
458                 skb_queue_head_init(&q->requeued[i]);
459                 q->queues[i] = qdisc_create_dflt(qd->dev, &pfifo_qdisc_ops,
460                                                  qd->handle);
461                 if (q->queues[i] == 0) {
462                         q->queues[i] = &noop_qdisc;
463                         printk(KERN_ERR "%s child qdisc %i creation failed", dev->name, i);
464                 }
465         }
466
467         return err;
468 }
469
470 static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
471 {
472 /*      struct ieee80211_sched_data *q = qdisc_priv(qd);
473         unsigned char *p = skb->tail;
474         struct tc_ieee80211_qopt opt;
475
476         memcpy(&opt.tag2queue, q->tag2queue, TC_80211_MAX_TAG + 1);
477         RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
478 */      return skb->len;
479 /*
480 rtattr_failure:
481         skb_trim(skb, p - skb->data);*/
482         return -1;
483 }
484
485
486 static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
487                              struct Qdisc *new, struct Qdisc **old)
488 {
489         struct ieee80211_sched_data *q = qdisc_priv(qd);
490         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
491         struct ieee80211_hw *hw = &local->hw;
492         unsigned long queue = arg - 1;
493
494         if (queue >= hw->queues)
495                 return -EINVAL;
496
497         if (!new)
498                 new = &noop_qdisc;
499
500         sch_tree_lock(qd);
501         *old = q->queues[queue];
502         q->queues[queue] = new;
503         qdisc_reset(*old);
504         sch_tree_unlock(qd);
505
506         return 0;
507 }
508
509
510 static struct Qdisc *
511 wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
512 {
513         struct ieee80211_sched_data *q = qdisc_priv(qd);
514         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
515         struct ieee80211_hw *hw = &local->hw;
516         unsigned long queue = arg - 1;
517
518         if (queue >= hw->queues)
519                 return NULL;
520
521         return q->queues[queue];
522 }
523
524
525 static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
526 {
527         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
528         struct ieee80211_hw *hw = &local->hw;
529         unsigned long queue = TC_H_MIN(classid);
530
531         if (queue - 1 >= hw->queues)
532                 return 0;
533
534         return queue;
535 }
536
537
538 static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
539                                       u32 classid)
540 {
541         return wme_classop_get(qd, classid);
542 }
543
544
545 static void wme_classop_put(struct Qdisc *q, unsigned long cl)
546 {
547 }
548
549
550 static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
551                               struct rtattr **tca, unsigned long *arg)
552 {
553         unsigned long cl = *arg;
554         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
555         struct ieee80211_hw *hw = &local->hw;
556
557         if (cl - 1 > hw->queues)
558                 return -ENOENT;
559
560         /* TODO: put code to program hardware queue parameters here,
561          * to allow programming from tc command line */
562
563         return 0;
564 }
565
566
567 /* we don't support deleting hardware queues
568  * when we add WMM-SA support - TSPECs may be deleted here */
569 static int wme_classop_delete(struct Qdisc *qd, unsigned long cl)
570 {
571         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
572         struct ieee80211_hw *hw = &local->hw;
573
574         if (cl - 1 > hw->queues)
575                 return -ENOENT;
576         return 0;
577 }
578
579
580 static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
581                                   struct sk_buff *skb, struct tcmsg *tcm)
582 {
583         struct ieee80211_sched_data *q = qdisc_priv(qd);
584         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
585         struct ieee80211_hw *hw = &local->hw;
586
587         if (cl - 1 > hw->queues)
588                 return -ENOENT;
589         tcm->tcm_handle = TC_H_MIN(cl);
590         tcm->tcm_parent = qd->handle;
591         tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */
592         return 0;
593 }
594
595
596 static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
597 {
598         struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
599         struct ieee80211_hw *hw = &local->hw;
600         int queue;
601
602         if (arg->stop)
603                 return;
604
605         for (queue = 0; queue < hw->queues; queue++) {
606                 if (arg->count < arg->skip) {
607                         arg->count++;
608                         continue;
609                 }
610                 /* we should return classids for our internal queues here
611                  * as well as the external ones */
612                 if (arg->fn(qd, queue+1, arg) < 0) {
613                         arg->stop = 1;
614                         break;
615                 }
616                 arg->count++;
617         }
618 }
619
620
621 static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
622                                                 unsigned long cl)
623 {
624         struct ieee80211_sched_data *q = qdisc_priv(qd);
625
626         if (cl)
627                 return NULL;
628
629         return &q->filter_list;
630 }
631
632
633 /* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached)
634  * - these are the operations on the classes */
635 static struct Qdisc_class_ops class_ops =
636 {
637         .graft = wme_classop_graft,
638         .leaf = wme_classop_leaf,
639
640         .get = wme_classop_get,
641         .put = wme_classop_put,
642         .change = wme_classop_change,
643         .delete = wme_classop_delete,
644         .walk = wme_classop_walk,
645
646         .tcf_chain = wme_classop_find_tcf,
647         .bind_tcf = wme_classop_bind,
648         .unbind_tcf = wme_classop_put,
649
650         .dump = wme_classop_dump_class,
651 };
652
653
654 /* queueing discipline operations */
655 static struct Qdisc_ops wme_qdisc_ops =
656 {
657         .next = NULL,
658         .cl_ops = &class_ops,
659         .id = "ieee80211",
660         .priv_size = sizeof(struct ieee80211_sched_data),
661
662         .enqueue = wme_qdiscop_enqueue,
663         .dequeue = wme_qdiscop_dequeue,
664         .requeue = wme_qdiscop_requeue,
665         .drop = NULL, /* drop not needed since we are always the root qdisc */
666
667         .init = wme_qdiscop_init,
668         .reset = wme_qdiscop_reset,
669         .destroy = wme_qdiscop_destroy,
670         .change = wme_qdiscop_tune,
671
672         .dump = wme_qdiscop_dump,
673 };
674
675
676 void ieee80211_install_qdisc(struct net_device *dev)
677 {
678         struct Qdisc *qdisc;
679
680         qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops, TC_H_ROOT);
681         if (!qdisc) {
682                 printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
683                 return;
684         }
685
686         /* same handle as would be allocated by qdisc_alloc_handle() */
687         qdisc->handle = 0x80010000;
688
689         qdisc_lock_tree(dev);
690         list_add_tail(&qdisc->list, &dev->qdisc_list);
691         dev->qdisc_sleeping = qdisc;
692         qdisc_unlock_tree(dev);
693 }
694
695
696 int ieee80211_qdisc_installed(struct net_device *dev)
697 {
698         return dev->qdisc_sleeping->ops == &wme_qdisc_ops;
699 }
700
701
702 int ieee80211_wme_register(void)
703 {
704         return register_qdisc(&wme_qdisc_ops);
705 }
706
707
708 void ieee80211_wme_unregister(void)
709 {
710         unregister_qdisc(&wme_qdisc_ops);
711 }
712 #endif /* CONFIG_NET_SCHED */