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