]> bbs.cooldavid.org Git - net-next-2.6.git/blob - net/sched/sch_generic.c
netdev: Allocate multiple queues for TX.
[net-next-2.6.git] / net / sched / sch_generic.c
1 /*
2  * net/sched/sch_generic.c      Generic packet scheduler routines.
3  *
4  *              This program is free software; you can redistribute it and/or
5  *              modify it under the terms of the GNU General Public License
6  *              as published by the Free Software Foundation; either version
7  *              2 of the License, or (at your option) any later version.
8  *
9  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10  *              Jamal Hadi Salim, <hadi@cyberus.ca> 990601
11  *              - Ingress support
12  */
13
14 #include <linux/bitops.h>
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/string.h>
20 #include <linux/errno.h>
21 #include <linux/netdevice.h>
22 #include <linux/skbuff.h>
23 #include <linux/rtnetlink.h>
24 #include <linux/init.h>
25 #include <linux/rcupdate.h>
26 #include <linux/list.h>
27 #include <net/pkt_sched.h>
28
29 /* Main transmission queue. */
30
31 /* Modifications to data participating in scheduling must be protected with
32  * queue->lock spinlock.
33  *
34  * The idea is the following:
35  * - enqueue, dequeue are serialized via top level device
36  *   spinlock queue->lock.
37  * - ingress filtering is serialized via top level device
38  *   spinlock dev->rx_queue.lock.
39  * - updates to tree and tree walking are only done under the rtnl mutex.
40  */
41
42 void qdisc_lock_tree(struct net_device *dev)
43         __acquires(dev->rx_queue.lock)
44 {
45         unsigned int i;
46
47         local_bh_disable();
48         for (i = 0; i < dev->num_tx_queues; i++) {
49                 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
50                 spin_lock(&txq->lock);
51         }
52         spin_lock(&dev->rx_queue.lock);
53 }
54 EXPORT_SYMBOL(qdisc_lock_tree);
55
56 void qdisc_unlock_tree(struct net_device *dev)
57         __releases(dev->rx_queue.lock)
58 {
59         unsigned int i;
60
61         spin_unlock(&dev->rx_queue.lock);
62         for (i = 0; i < dev->num_tx_queues; i++) {
63                 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
64                 spin_unlock(&txq->lock);
65         }
66         local_bh_enable();
67 }
68 EXPORT_SYMBOL(qdisc_unlock_tree);
69
70 static inline int qdisc_qlen(struct Qdisc *q)
71 {
72         return q->q.qlen;
73 }
74
75 static inline int dev_requeue_skb(struct sk_buff *skb,
76                                   struct netdev_queue *dev_queue,
77                                   struct Qdisc *q)
78 {
79         if (unlikely(skb->next))
80                 dev_queue->gso_skb = skb;
81         else
82                 q->ops->requeue(skb, q);
83
84         netif_schedule_queue(dev_queue);
85         return 0;
86 }
87
88 static inline struct sk_buff *dequeue_skb(struct netdev_queue *dev_queue,
89                                           struct Qdisc *q)
90 {
91         struct sk_buff *skb;
92
93         if ((skb = dev_queue->gso_skb))
94                 dev_queue->gso_skb = NULL;
95         else
96                 skb = q->dequeue(q);
97
98         return skb;
99 }
100
101 static inline int handle_dev_cpu_collision(struct sk_buff *skb,
102                                            struct netdev_queue *dev_queue,
103                                            struct Qdisc *q)
104 {
105         int ret;
106
107         if (unlikely(dev_queue->xmit_lock_owner == smp_processor_id())) {
108                 /*
109                  * Same CPU holding the lock. It may be a transient
110                  * configuration error, when hard_start_xmit() recurses. We
111                  * detect it by checking xmit owner and drop the packet when
112                  * deadloop is detected. Return OK to try the next skb.
113                  */
114                 kfree_skb(skb);
115                 if (net_ratelimit())
116                         printk(KERN_WARNING "Dead loop on netdevice %s, "
117                                "fix it urgently!\n", dev_queue->dev->name);
118                 ret = qdisc_qlen(q);
119         } else {
120                 /*
121                  * Another cpu is holding lock, requeue & delay xmits for
122                  * some time.
123                  */
124                 __get_cpu_var(netdev_rx_stat).cpu_collision++;
125                 ret = dev_requeue_skb(skb, dev_queue, q);
126         }
127
128         return ret;
129 }
130
131 /*
132  * NOTE: Called under queue->lock with locally disabled BH.
133  *
134  * __QUEUE_STATE_QDISC_RUNNING guarantees only one CPU can process
135  * this queue at a time. queue->lock serializes queue accesses for
136  * this queue AND txq->qdisc pointer itself.
137  *
138  *  netif_tx_lock serializes accesses to device driver.
139  *
140  *  queue->lock and netif_tx_lock are mutually exclusive,
141  *  if one is grabbed, another must be free.
142  *
143  * Note, that this procedure can be called by a watchdog timer
144  *
145  * Returns to the caller:
146  *                              0  - queue is empty or throttled.
147  *                              >0 - queue is not empty.
148  *
149  */
150 static inline int qdisc_restart(struct netdev_queue *txq)
151 {
152         struct Qdisc *q = txq->qdisc;
153         int ret = NETDEV_TX_BUSY;
154         struct net_device *dev;
155         struct sk_buff *skb;
156
157         /* Dequeue packet */
158         if (unlikely((skb = dequeue_skb(txq, q)) == NULL))
159                 return 0;
160
161
162         /* And release queue */
163         spin_unlock(&txq->lock);
164
165         dev = txq->dev;
166
167         HARD_TX_LOCK(dev, txq, smp_processor_id());
168         if (!netif_subqueue_stopped(dev, skb))
169                 ret = dev_hard_start_xmit(skb, dev);
170         HARD_TX_UNLOCK(dev, txq);
171
172         spin_lock(&txq->lock);
173         q = txq->qdisc;
174
175         switch (ret) {
176         case NETDEV_TX_OK:
177                 /* Driver sent out skb successfully */
178                 ret = qdisc_qlen(q);
179                 break;
180
181         case NETDEV_TX_LOCKED:
182                 /* Driver try lock failed */
183                 ret = handle_dev_cpu_collision(skb, txq, q);
184                 break;
185
186         default:
187                 /* Driver returned NETDEV_TX_BUSY - requeue skb */
188                 if (unlikely (ret != NETDEV_TX_BUSY && net_ratelimit()))
189                         printk(KERN_WARNING "BUG %s code %d qlen %d\n",
190                                dev->name, ret, q->q.qlen);
191
192                 ret = dev_requeue_skb(skb, txq, q);
193                 break;
194         }
195
196         return ret;
197 }
198
199 void __qdisc_run(struct netdev_queue *txq)
200 {
201         struct net_device *dev = txq->dev;
202         unsigned long start_time = jiffies;
203
204         while (qdisc_restart(txq)) {
205                 if (netif_queue_stopped(dev))
206                         break;
207
208                 /*
209                  * Postpone processing if
210                  * 1. another process needs the CPU;
211                  * 2. we've been doing it for too long.
212                  */
213                 if (need_resched() || jiffies != start_time) {
214                         netif_schedule_queue(txq);
215                         break;
216                 }
217         }
218
219         clear_bit(__QUEUE_STATE_QDISC_RUNNING, &txq->state);
220 }
221
222 static void dev_watchdog(unsigned long arg)
223 {
224         struct net_device *dev = (struct net_device *)arg;
225
226         netif_tx_lock(dev);
227         if (!qdisc_tx_is_noop(dev)) {
228                 if (netif_device_present(dev) &&
229                     netif_running(dev) &&
230                     netif_carrier_ok(dev)) {
231                         int some_queue_stopped = 0;
232                         unsigned int i;
233
234                         for (i = 0; i < dev->num_tx_queues; i++) {
235                                 struct netdev_queue *txq;
236
237                                 txq = netdev_get_tx_queue(dev, i);
238                                 if (netif_tx_queue_stopped(txq)) {
239                                         some_queue_stopped = 1;
240                                         break;
241                                 }
242                         }
243
244                         if (some_queue_stopped &&
245                             time_after(jiffies, (dev->trans_start +
246                                                  dev->watchdog_timeo))) {
247                                 printk(KERN_INFO "NETDEV WATCHDOG: %s: "
248                                        "transmit timed out\n",
249                                        dev->name);
250                                 dev->tx_timeout(dev);
251                                 WARN_ON_ONCE(1);
252                         }
253                         if (!mod_timer(&dev->watchdog_timer,
254                                        round_jiffies(jiffies +
255                                                      dev->watchdog_timeo)))
256                                 dev_hold(dev);
257                 }
258         }
259         netif_tx_unlock(dev);
260
261         dev_put(dev);
262 }
263
264 void __netdev_watchdog_up(struct net_device *dev)
265 {
266         if (dev->tx_timeout) {
267                 if (dev->watchdog_timeo <= 0)
268                         dev->watchdog_timeo = 5*HZ;
269                 if (!mod_timer(&dev->watchdog_timer,
270                                round_jiffies(jiffies + dev->watchdog_timeo)))
271                         dev_hold(dev);
272         }
273 }
274
275 static void dev_watchdog_up(struct net_device *dev)
276 {
277         __netdev_watchdog_up(dev);
278 }
279
280 static void dev_watchdog_down(struct net_device *dev)
281 {
282         netif_tx_lock_bh(dev);
283         if (del_timer(&dev->watchdog_timer))
284                 dev_put(dev);
285         netif_tx_unlock_bh(dev);
286 }
287
288 /**
289  *      netif_carrier_on - set carrier
290  *      @dev: network device
291  *
292  * Device has detected that carrier.
293  */
294 void netif_carrier_on(struct net_device *dev)
295 {
296         if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
297                 linkwatch_fire_event(dev);
298                 if (netif_running(dev))
299                         __netdev_watchdog_up(dev);
300         }
301 }
302 EXPORT_SYMBOL(netif_carrier_on);
303
304 /**
305  *      netif_carrier_off - clear carrier
306  *      @dev: network device
307  *
308  * Device has detected loss of carrier.
309  */
310 void netif_carrier_off(struct net_device *dev)
311 {
312         if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state))
313                 linkwatch_fire_event(dev);
314 }
315 EXPORT_SYMBOL(netif_carrier_off);
316
317 /* "NOOP" scheduler: the best scheduler, recommended for all interfaces
318    under all circumstances. It is difficult to invent anything faster or
319    cheaper.
320  */
321
322 static int noop_enqueue(struct sk_buff *skb, struct Qdisc * qdisc)
323 {
324         kfree_skb(skb);
325         return NET_XMIT_CN;
326 }
327
328 static struct sk_buff *noop_dequeue(struct Qdisc * qdisc)
329 {
330         return NULL;
331 }
332
333 static int noop_requeue(struct sk_buff *skb, struct Qdisc* qdisc)
334 {
335         if (net_ratelimit())
336                 printk(KERN_DEBUG "%s deferred output. It is buggy.\n",
337                        skb->dev->name);
338         kfree_skb(skb);
339         return NET_XMIT_CN;
340 }
341
342 struct Qdisc_ops noop_qdisc_ops __read_mostly = {
343         .id             =       "noop",
344         .priv_size      =       0,
345         .enqueue        =       noop_enqueue,
346         .dequeue        =       noop_dequeue,
347         .requeue        =       noop_requeue,
348         .owner          =       THIS_MODULE,
349 };
350
351 struct Qdisc noop_qdisc = {
352         .enqueue        =       noop_enqueue,
353         .dequeue        =       noop_dequeue,
354         .flags          =       TCQ_F_BUILTIN,
355         .ops            =       &noop_qdisc_ops,
356         .list           =       LIST_HEAD_INIT(noop_qdisc.list),
357 };
358 EXPORT_SYMBOL(noop_qdisc);
359
360 static struct Qdisc_ops noqueue_qdisc_ops __read_mostly = {
361         .id             =       "noqueue",
362         .priv_size      =       0,
363         .enqueue        =       noop_enqueue,
364         .dequeue        =       noop_dequeue,
365         .requeue        =       noop_requeue,
366         .owner          =       THIS_MODULE,
367 };
368
369 static struct Qdisc noqueue_qdisc = {
370         .enqueue        =       NULL,
371         .dequeue        =       noop_dequeue,
372         .flags          =       TCQ_F_BUILTIN,
373         .ops            =       &noqueue_qdisc_ops,
374         .list           =       LIST_HEAD_INIT(noqueue_qdisc.list),
375 };
376
377
378 static const u8 prio2band[TC_PRIO_MAX+1] =
379         { 1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1 };
380
381 /* 3-band FIFO queue: old style, but should be a bit faster than
382    generic prio+fifo combination.
383  */
384
385 #define PFIFO_FAST_BANDS 3
386
387 static inline struct sk_buff_head *prio2list(struct sk_buff *skb,
388                                              struct Qdisc *qdisc)
389 {
390         struct sk_buff_head *list = qdisc_priv(qdisc);
391         return list + prio2band[skb->priority & TC_PRIO_MAX];
392 }
393
394 static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc* qdisc)
395 {
396         struct sk_buff_head *list = prio2list(skb, qdisc);
397
398         if (skb_queue_len(list) < qdisc_dev(qdisc)->tx_queue_len) {
399                 qdisc->q.qlen++;
400                 return __qdisc_enqueue_tail(skb, qdisc, list);
401         }
402
403         return qdisc_drop(skb, qdisc);
404 }
405
406 static struct sk_buff *pfifo_fast_dequeue(struct Qdisc* qdisc)
407 {
408         int prio;
409         struct sk_buff_head *list = qdisc_priv(qdisc);
410
411         for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
412                 if (!skb_queue_empty(list + prio)) {
413                         qdisc->q.qlen--;
414                         return __qdisc_dequeue_head(qdisc, list + prio);
415                 }
416         }
417
418         return NULL;
419 }
420
421 static int pfifo_fast_requeue(struct sk_buff *skb, struct Qdisc* qdisc)
422 {
423         qdisc->q.qlen++;
424         return __qdisc_requeue(skb, qdisc, prio2list(skb, qdisc));
425 }
426
427 static void pfifo_fast_reset(struct Qdisc* qdisc)
428 {
429         int prio;
430         struct sk_buff_head *list = qdisc_priv(qdisc);
431
432         for (prio = 0; prio < PFIFO_FAST_BANDS; prio++)
433                 __qdisc_reset_queue(qdisc, list + prio);
434
435         qdisc->qstats.backlog = 0;
436         qdisc->q.qlen = 0;
437 }
438
439 static int pfifo_fast_dump(struct Qdisc *qdisc, struct sk_buff *skb)
440 {
441         struct tc_prio_qopt opt = { .bands = PFIFO_FAST_BANDS };
442
443         memcpy(&opt.priomap, prio2band, TC_PRIO_MAX+1);
444         NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
445         return skb->len;
446
447 nla_put_failure:
448         return -1;
449 }
450
451 static int pfifo_fast_init(struct Qdisc *qdisc, struct nlattr *opt)
452 {
453         int prio;
454         struct sk_buff_head *list = qdisc_priv(qdisc);
455
456         for (prio = 0; prio < PFIFO_FAST_BANDS; prio++)
457                 skb_queue_head_init(list + prio);
458
459         return 0;
460 }
461
462 static struct Qdisc_ops pfifo_fast_ops __read_mostly = {
463         .id             =       "pfifo_fast",
464         .priv_size      =       PFIFO_FAST_BANDS * sizeof(struct sk_buff_head),
465         .enqueue        =       pfifo_fast_enqueue,
466         .dequeue        =       pfifo_fast_dequeue,
467         .requeue        =       pfifo_fast_requeue,
468         .init           =       pfifo_fast_init,
469         .reset          =       pfifo_fast_reset,
470         .dump           =       pfifo_fast_dump,
471         .owner          =       THIS_MODULE,
472 };
473
474 struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
475                           struct Qdisc_ops *ops)
476 {
477         void *p;
478         struct Qdisc *sch;
479         unsigned int size;
480         int err = -ENOBUFS;
481
482         /* ensure that the Qdisc and the private data are 32-byte aligned */
483         size = QDISC_ALIGN(sizeof(*sch));
484         size += ops->priv_size + (QDISC_ALIGNTO - 1);
485
486         p = kzalloc(size, GFP_KERNEL);
487         if (!p)
488                 goto errout;
489         sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p);
490         sch->padded = (char *) sch - (char *) p;
491
492         INIT_LIST_HEAD(&sch->list);
493         skb_queue_head_init(&sch->q);
494         sch->ops = ops;
495         sch->enqueue = ops->enqueue;
496         sch->dequeue = ops->dequeue;
497         sch->dev_queue = dev_queue;
498         dev_hold(qdisc_dev(sch));
499         atomic_set(&sch->refcnt, 1);
500
501         return sch;
502 errout:
503         return ERR_PTR(err);
504 }
505
506 struct Qdisc * qdisc_create_dflt(struct net_device *dev,
507                                  struct netdev_queue *dev_queue,
508                                  struct Qdisc_ops *ops,
509                                  unsigned int parentid)
510 {
511         struct Qdisc *sch;
512
513         sch = qdisc_alloc(dev_queue, ops);
514         if (IS_ERR(sch))
515                 goto errout;
516         sch->parent = parentid;
517
518         if (!ops->init || ops->init(sch, NULL) == 0)
519                 return sch;
520
521         qdisc_destroy(sch);
522 errout:
523         return NULL;
524 }
525 EXPORT_SYMBOL(qdisc_create_dflt);
526
527 /* Under queue->lock and BH! */
528
529 void qdisc_reset(struct Qdisc *qdisc)
530 {
531         const struct Qdisc_ops *ops = qdisc->ops;
532
533         if (ops->reset)
534                 ops->reset(qdisc);
535 }
536 EXPORT_SYMBOL(qdisc_reset);
537
538 /* this is the rcu callback function to clean up a qdisc when there
539  * are no further references to it */
540
541 static void __qdisc_destroy(struct rcu_head *head)
542 {
543         struct Qdisc *qdisc = container_of(head, struct Qdisc, q_rcu);
544         kfree((char *) qdisc - qdisc->padded);
545 }
546
547 /* Under queue->lock and BH! */
548
549 void qdisc_destroy(struct Qdisc *qdisc)
550 {
551         const struct Qdisc_ops  *ops = qdisc->ops;
552
553         if (qdisc->flags & TCQ_F_BUILTIN ||
554             !atomic_dec_and_test(&qdisc->refcnt))
555                 return;
556
557         list_del(&qdisc->list);
558         gen_kill_estimator(&qdisc->bstats, &qdisc->rate_est);
559         if (ops->reset)
560                 ops->reset(qdisc);
561         if (ops->destroy)
562                 ops->destroy(qdisc);
563
564         module_put(ops->owner);
565         dev_put(qdisc_dev(qdisc));
566         call_rcu(&qdisc->q_rcu, __qdisc_destroy);
567 }
568 EXPORT_SYMBOL(qdisc_destroy);
569
570 static bool dev_all_qdisc_sleeping_noop(struct net_device *dev)
571 {
572         unsigned int i;
573
574         for (i = 0; i < dev->num_tx_queues; i++) {
575                 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
576
577                 if (txq->qdisc_sleeping != &noop_qdisc)
578                         return false;
579         }
580         return true;
581 }
582
583 static void attach_one_default_qdisc(struct net_device *dev,
584                                      struct netdev_queue *dev_queue,
585                                      void *_unused)
586 {
587         struct Qdisc *qdisc;
588
589         if (dev->tx_queue_len) {
590                 qdisc = qdisc_create_dflt(dev, dev_queue,
591                                           &pfifo_fast_ops, TC_H_ROOT);
592                 if (!qdisc) {
593                         printk(KERN_INFO "%s: activation failed\n", dev->name);
594                         return;
595                 }
596                 list_add_tail(&qdisc->list, &dev_queue->qdisc_list);
597         } else {
598                 qdisc =  &noqueue_qdisc;
599         }
600         dev_queue->qdisc_sleeping = qdisc;
601 }
602
603 static void transition_one_qdisc(struct net_device *dev,
604                                  struct netdev_queue *dev_queue,
605                                  void *_need_watchdog)
606 {
607         int *need_watchdog_p = _need_watchdog;
608
609         spin_lock_bh(&dev_queue->lock);
610         rcu_assign_pointer(dev_queue->qdisc, dev_queue->qdisc_sleeping);
611         if (dev_queue->qdisc != &noqueue_qdisc)
612                 *need_watchdog_p = 1;
613         spin_unlock_bh(&dev_queue->lock);
614 }
615
616 void dev_activate(struct net_device *dev)
617 {
618         int need_watchdog;
619
620         /* No queueing discipline is attached to device;
621            create default one i.e. pfifo_fast for devices,
622            which need queueing and noqueue_qdisc for
623            virtual interfaces
624          */
625
626         if (dev_all_qdisc_sleeping_noop(dev))
627                 netdev_for_each_tx_queue(dev, attach_one_default_qdisc, NULL);
628
629         if (!netif_carrier_ok(dev))
630                 /* Delay activation until next carrier-on event */
631                 return;
632
633         need_watchdog = 0;
634         netdev_for_each_tx_queue(dev, transition_one_qdisc, &need_watchdog);
635
636         if (need_watchdog) {
637                 dev->trans_start = jiffies;
638                 dev_watchdog_up(dev);
639         }
640 }
641
642 static void dev_deactivate_queue(struct net_device *dev,
643                                  struct netdev_queue *dev_queue,
644                                  void *_qdisc_default)
645 {
646         struct Qdisc *qdisc_default = _qdisc_default;
647         struct Qdisc *qdisc;
648         struct sk_buff *skb;
649
650         spin_lock_bh(&dev_queue->lock);
651
652         qdisc = dev_queue->qdisc;
653         if (qdisc) {
654                 dev_queue->qdisc = qdisc_default;
655                 qdisc_reset(qdisc);
656         }
657         skb = dev_queue->gso_skb;
658         dev_queue->gso_skb = NULL;
659
660         spin_unlock_bh(&dev_queue->lock);
661
662         kfree_skb(skb);
663 }
664
665 static bool some_qdisc_is_running(struct net_device *dev, int lock)
666 {
667         unsigned int i;
668
669         for (i = 0; i < dev->num_tx_queues; i++) {
670                 struct netdev_queue *dev_queue;
671                 int val;
672
673                 dev_queue = netdev_get_tx_queue(dev, i);
674
675                 if (lock)
676                         spin_lock_bh(&dev_queue->lock);
677
678                 val = test_bit(__QUEUE_STATE_QDISC_RUNNING, &dev_queue->state);
679
680                 if (lock)
681                         spin_unlock_bh(&dev_queue->lock);
682
683                 if (val)
684                         return true;
685         }
686         return false;
687 }
688
689 void dev_deactivate(struct net_device *dev)
690 {
691         bool running;
692
693         netdev_for_each_tx_queue(dev, dev_deactivate_queue, &noop_qdisc);
694
695         dev_watchdog_down(dev);
696
697         /* Wait for outstanding qdisc-less dev_queue_xmit calls. */
698         synchronize_rcu();
699
700         /* Wait for outstanding qdisc_run calls. */
701         do {
702                 while (some_qdisc_is_running(dev, 0))
703                         yield();
704
705                 /*
706                  * Double-check inside queue lock to ensure that all effects
707                  * of the queue run are visible when we return.
708                  */
709                 running = some_qdisc_is_running(dev, 1);
710
711                 /*
712                  * The running flag should never be set at this point because
713                  * we've already set dev->qdisc to noop_qdisc *inside* the same
714                  * pair of spin locks.  That is, if any qdisc_run starts after
715                  * our initial test it should see the noop_qdisc and then
716                  * clear the RUNNING bit before dropping the queue lock.  So
717                  * if it is set here then we've found a bug.
718                  */
719         } while (WARN_ON_ONCE(running));
720 }
721
722 static void dev_init_scheduler_queue(struct net_device *dev,
723                                      struct netdev_queue *dev_queue,
724                                      void *_qdisc)
725 {
726         struct Qdisc *qdisc = _qdisc;
727
728         dev_queue->qdisc = qdisc;
729         dev_queue->qdisc_sleeping = qdisc;
730         INIT_LIST_HEAD(&dev_queue->qdisc_list);
731 }
732
733 void dev_init_scheduler(struct net_device *dev)
734 {
735         qdisc_lock_tree(dev);
736         netdev_for_each_tx_queue(dev, dev_init_scheduler_queue, &noop_qdisc);
737         dev_init_scheduler_queue(dev, &dev->rx_queue, NULL);
738         qdisc_unlock_tree(dev);
739
740         setup_timer(&dev->watchdog_timer, dev_watchdog, (unsigned long)dev);
741 }
742
743 static void shutdown_scheduler_queue(struct net_device *dev,
744                                      struct netdev_queue *dev_queue,
745                                      void *_qdisc_default)
746 {
747         struct Qdisc *qdisc = dev_queue->qdisc_sleeping;
748         struct Qdisc *qdisc_default = _qdisc_default;
749
750         if (qdisc) {
751                 dev_queue->qdisc = qdisc_default;
752                 dev_queue->qdisc_sleeping = qdisc_default;
753
754                 qdisc_destroy(qdisc);
755         }
756 }
757
758 void dev_shutdown(struct net_device *dev)
759 {
760         qdisc_lock_tree(dev);
761         netdev_for_each_tx_queue(dev, shutdown_scheduler_queue, &noop_qdisc);
762         shutdown_scheduler_queue(dev, &dev->rx_queue, NULL);
763         BUG_TRAP(!timer_pending(&dev->watchdog_timer));
764         qdisc_unlock_tree(dev);
765 }