sch_generic.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. #include <linux/bitops.h>
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/string.h>
  19. #include <linux/errno.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/skbuff.h>
  22. #include <linux/rtnetlink.h>
  23. #include <linux/init.h>
  24. #include <linux/rcupdate.h>
  25. #include <linux/list.h>
  26. #include <net/pkt_sched.h>
  27. /* Main transmission queue. */
  28. /* Modifications to data participating in scheduling must be protected with
  29. * queue->lock spinlock.
  30. *
  31. * The idea is the following:
  32. * - enqueue, dequeue are serialized via top level device
  33. * spinlock queue->lock.
  34. * - ingress filtering is serialized via top level device
  35. * spinlock dev->rx_queue.lock.
  36. * - updates to tree and tree walking are only done under the rtnl mutex.
  37. */
  38. void qdisc_lock_tree(struct net_device *dev)
  39. __acquires(dev->tx_queue.lock)
  40. __acquires(dev->rx_queue.lock)
  41. {
  42. spin_lock_bh(&dev->tx_queue.lock);
  43. spin_lock(&dev->rx_queue.lock);
  44. }
  45. EXPORT_SYMBOL(qdisc_lock_tree);
  46. void qdisc_unlock_tree(struct net_device *dev)
  47. __releases(dev->rx_queue.lock)
  48. __releases(dev->tx_queue.lock)
  49. {
  50. spin_unlock(&dev->rx_queue.lock);
  51. spin_unlock_bh(&dev->tx_queue.lock);
  52. }
  53. EXPORT_SYMBOL(qdisc_unlock_tree);
  54. static inline int qdisc_qlen(struct Qdisc *q)
  55. {
  56. return q->q.qlen;
  57. }
  58. static inline int dev_requeue_skb(struct sk_buff *skb,
  59. struct netdev_queue *dev_queue,
  60. struct Qdisc *q)
  61. {
  62. if (unlikely(skb->next))
  63. dev_queue->gso_skb = skb;
  64. else
  65. q->ops->requeue(skb, q);
  66. netif_schedule_queue(dev_queue);
  67. return 0;
  68. }
  69. static inline struct sk_buff *dev_dequeue_skb(struct net_device *dev,
  70. struct netdev_queue *dev_queue,
  71. struct Qdisc *q)
  72. {
  73. struct sk_buff *skb;
  74. if ((skb = dev_queue->gso_skb))
  75. dev_queue->gso_skb = NULL;
  76. else
  77. skb = q->dequeue(q);
  78. return skb;
  79. }
  80. static inline int handle_dev_cpu_collision(struct sk_buff *skb,
  81. struct net_device *dev,
  82. struct netdev_queue *dev_queue,
  83. struct Qdisc *q)
  84. {
  85. int ret;
  86. if (unlikely(dev->xmit_lock_owner == smp_processor_id())) {
  87. /*
  88. * Same CPU holding the lock. It may be a transient
  89. * configuration error, when hard_start_xmit() recurses. We
  90. * detect it by checking xmit owner and drop the packet when
  91. * deadloop is detected. Return OK to try the next skb.
  92. */
  93. kfree_skb(skb);
  94. if (net_ratelimit())
  95. printk(KERN_WARNING "Dead loop on netdevice %s, "
  96. "fix it urgently!\n", dev->name);
  97. ret = qdisc_qlen(q);
  98. } else {
  99. /*
  100. * Another cpu is holding lock, requeue & delay xmits for
  101. * some time.
  102. */
  103. __get_cpu_var(netdev_rx_stat).cpu_collision++;
  104. ret = dev_requeue_skb(skb, dev_queue, q);
  105. }
  106. return ret;
  107. }
  108. /*
  109. * NOTE: Called under queue->lock with locally disabled BH.
  110. *
  111. * __LINK_STATE_QDISC_RUNNING guarantees only one CPU can process this
  112. * device at a time. queue->lock serializes queue accesses for
  113. * this device AND txq->qdisc pointer itself.
  114. *
  115. * netif_tx_lock serializes accesses to device driver.
  116. *
  117. * queue->lock and netif_tx_lock are mutually exclusive,
  118. * if one is grabbed, another must be free.
  119. *
  120. * Note, that this procedure can be called by a watchdog timer
  121. *
  122. * Returns to the caller:
  123. * 0 - queue is empty or throttled.
  124. * >0 - queue is not empty.
  125. *
  126. */
  127. static inline int qdisc_restart(struct net_device *dev)
  128. {
  129. struct netdev_queue *txq = &dev->tx_queue;
  130. struct Qdisc *q = txq->qdisc;
  131. struct sk_buff *skb;
  132. int ret = NETDEV_TX_BUSY;
  133. /* Dequeue packet */
  134. if (unlikely((skb = dev_dequeue_skb(dev, txq, q)) == NULL))
  135. return 0;
  136. /* And release queue */
  137. spin_unlock(&txq->lock);
  138. HARD_TX_LOCK(dev, smp_processor_id());
  139. if (!netif_subqueue_stopped(dev, skb))
  140. ret = dev_hard_start_xmit(skb, dev);
  141. HARD_TX_UNLOCK(dev);
  142. spin_lock(&txq->lock);
  143. q = txq->qdisc;
  144. switch (ret) {
  145. case NETDEV_TX_OK:
  146. /* Driver sent out skb successfully */
  147. ret = qdisc_qlen(q);
  148. break;
  149. case NETDEV_TX_LOCKED:
  150. /* Driver try lock failed */
  151. ret = handle_dev_cpu_collision(skb, dev, txq, q);
  152. break;
  153. default:
  154. /* Driver returned NETDEV_TX_BUSY - requeue skb */
  155. if (unlikely (ret != NETDEV_TX_BUSY && net_ratelimit()))
  156. printk(KERN_WARNING "BUG %s code %d qlen %d\n",
  157. dev->name, ret, q->q.qlen);
  158. ret = dev_requeue_skb(skb, txq, q);
  159. break;
  160. }
  161. return ret;
  162. }
  163. void __qdisc_run(struct net_device *dev)
  164. {
  165. unsigned long start_time = jiffies;
  166. while (qdisc_restart(dev)) {
  167. if (netif_queue_stopped(dev))
  168. break;
  169. /*
  170. * Postpone processing if
  171. * 1. another process needs the CPU;
  172. * 2. we've been doing it for too long.
  173. */
  174. if (need_resched() || jiffies != start_time) {
  175. netif_schedule_queue(&dev->tx_queue);
  176. break;
  177. }
  178. }
  179. clear_bit(__LINK_STATE_QDISC_RUNNING, &dev->state);
  180. }
  181. static void dev_watchdog(unsigned long arg)
  182. {
  183. struct net_device *dev = (struct net_device *)arg;
  184. struct netdev_queue *txq = &dev->tx_queue;
  185. netif_tx_lock(dev);
  186. if (txq->qdisc != &noop_qdisc) {
  187. if (netif_device_present(dev) &&
  188. netif_running(dev) &&
  189. netif_carrier_ok(dev)) {
  190. if (netif_queue_stopped(dev) &&
  191. time_after(jiffies, dev->trans_start + dev->watchdog_timeo)) {
  192. printk(KERN_INFO "NETDEV WATCHDOG: %s: transmit timed out\n",
  193. dev->name);
  194. dev->tx_timeout(dev);
  195. WARN_ON_ONCE(1);
  196. }
  197. if (!mod_timer(&dev->watchdog_timer, round_jiffies(jiffies + dev->watchdog_timeo)))
  198. dev_hold(dev);
  199. }
  200. }
  201. netif_tx_unlock(dev);
  202. dev_put(dev);
  203. }
  204. void __netdev_watchdog_up(struct net_device *dev)
  205. {
  206. if (dev->tx_timeout) {
  207. if (dev->watchdog_timeo <= 0)
  208. dev->watchdog_timeo = 5*HZ;
  209. if (!mod_timer(&dev->watchdog_timer,
  210. round_jiffies(jiffies + dev->watchdog_timeo)))
  211. dev_hold(dev);
  212. }
  213. }
  214. static void dev_watchdog_up(struct net_device *dev)
  215. {
  216. __netdev_watchdog_up(dev);
  217. }
  218. static void dev_watchdog_down(struct net_device *dev)
  219. {
  220. netif_tx_lock_bh(dev);
  221. if (del_timer(&dev->watchdog_timer))
  222. dev_put(dev);
  223. netif_tx_unlock_bh(dev);
  224. }
  225. /**
  226. * netif_carrier_on - set carrier
  227. * @dev: network device
  228. *
  229. * Device has detected that carrier.
  230. */
  231. void netif_carrier_on(struct net_device *dev)
  232. {
  233. if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
  234. linkwatch_fire_event(dev);
  235. if (netif_running(dev))
  236. __netdev_watchdog_up(dev);
  237. }
  238. }
  239. EXPORT_SYMBOL(netif_carrier_on);
  240. /**
  241. * netif_carrier_off - clear carrier
  242. * @dev: network device
  243. *
  244. * Device has detected loss of carrier.
  245. */
  246. void netif_carrier_off(struct net_device *dev)
  247. {
  248. if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state))
  249. linkwatch_fire_event(dev);
  250. }
  251. EXPORT_SYMBOL(netif_carrier_off);
  252. /* "NOOP" scheduler: the best scheduler, recommended for all interfaces
  253. under all circumstances. It is difficult to invent anything faster or
  254. cheaper.
  255. */
  256. static int noop_enqueue(struct sk_buff *skb, struct Qdisc * qdisc)
  257. {
  258. kfree_skb(skb);
  259. return NET_XMIT_CN;
  260. }
  261. static struct sk_buff *noop_dequeue(struct Qdisc * qdisc)
  262. {
  263. return NULL;
  264. }
  265. static int noop_requeue(struct sk_buff *skb, struct Qdisc* qdisc)
  266. {
  267. if (net_ratelimit())
  268. printk(KERN_DEBUG "%s deferred output. It is buggy.\n",
  269. skb->dev->name);
  270. kfree_skb(skb);
  271. return NET_XMIT_CN;
  272. }
  273. struct Qdisc_ops noop_qdisc_ops __read_mostly = {
  274. .id = "noop",
  275. .priv_size = 0,
  276. .enqueue = noop_enqueue,
  277. .dequeue = noop_dequeue,
  278. .requeue = noop_requeue,
  279. .owner = THIS_MODULE,
  280. };
  281. struct Qdisc noop_qdisc = {
  282. .enqueue = noop_enqueue,
  283. .dequeue = noop_dequeue,
  284. .flags = TCQ_F_BUILTIN,
  285. .ops = &noop_qdisc_ops,
  286. .list = LIST_HEAD_INIT(noop_qdisc.list),
  287. };
  288. EXPORT_SYMBOL(noop_qdisc);
  289. static struct Qdisc_ops noqueue_qdisc_ops __read_mostly = {
  290. .id = "noqueue",
  291. .priv_size = 0,
  292. .enqueue = noop_enqueue,
  293. .dequeue = noop_dequeue,
  294. .requeue = noop_requeue,
  295. .owner = THIS_MODULE,
  296. };
  297. static struct Qdisc noqueue_qdisc = {
  298. .enqueue = NULL,
  299. .dequeue = noop_dequeue,
  300. .flags = TCQ_F_BUILTIN,
  301. .ops = &noqueue_qdisc_ops,
  302. .list = LIST_HEAD_INIT(noqueue_qdisc.list),
  303. };
  304. static const u8 prio2band[TC_PRIO_MAX+1] =
  305. { 1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1 };
  306. /* 3-band FIFO queue: old style, but should be a bit faster than
  307. generic prio+fifo combination.
  308. */
  309. #define PFIFO_FAST_BANDS 3
  310. static inline struct sk_buff_head *prio2list(struct sk_buff *skb,
  311. struct Qdisc *qdisc)
  312. {
  313. struct sk_buff_head *list = qdisc_priv(qdisc);
  314. return list + prio2band[skb->priority & TC_PRIO_MAX];
  315. }
  316. static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc* qdisc)
  317. {
  318. struct sk_buff_head *list = prio2list(skb, qdisc);
  319. if (skb_queue_len(list) < qdisc_dev(qdisc)->tx_queue_len) {
  320. qdisc->q.qlen++;
  321. return __qdisc_enqueue_tail(skb, qdisc, list);
  322. }
  323. return qdisc_drop(skb, qdisc);
  324. }
  325. static struct sk_buff *pfifo_fast_dequeue(struct Qdisc* qdisc)
  326. {
  327. int prio;
  328. struct sk_buff_head *list = qdisc_priv(qdisc);
  329. for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
  330. if (!skb_queue_empty(list + prio)) {
  331. qdisc->q.qlen--;
  332. return __qdisc_dequeue_head(qdisc, list + prio);
  333. }
  334. }
  335. return NULL;
  336. }
  337. static int pfifo_fast_requeue(struct sk_buff *skb, struct Qdisc* qdisc)
  338. {
  339. qdisc->q.qlen++;
  340. return __qdisc_requeue(skb, qdisc, prio2list(skb, qdisc));
  341. }
  342. static void pfifo_fast_reset(struct Qdisc* qdisc)
  343. {
  344. int prio;
  345. struct sk_buff_head *list = qdisc_priv(qdisc);
  346. for (prio = 0; prio < PFIFO_FAST_BANDS; prio++)
  347. __qdisc_reset_queue(qdisc, list + prio);
  348. qdisc->qstats.backlog = 0;
  349. qdisc->q.qlen = 0;
  350. }
  351. static int pfifo_fast_dump(struct Qdisc *qdisc, struct sk_buff *skb)
  352. {
  353. struct tc_prio_qopt opt = { .bands = PFIFO_FAST_BANDS };
  354. memcpy(&opt.priomap, prio2band, TC_PRIO_MAX+1);
  355. NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
  356. return skb->len;
  357. nla_put_failure:
  358. return -1;
  359. }
  360. static int pfifo_fast_init(struct Qdisc *qdisc, struct nlattr *opt)
  361. {
  362. int prio;
  363. struct sk_buff_head *list = qdisc_priv(qdisc);
  364. for (prio = 0; prio < PFIFO_FAST_BANDS; prio++)
  365. skb_queue_head_init(list + prio);
  366. return 0;
  367. }
  368. static struct Qdisc_ops pfifo_fast_ops __read_mostly = {
  369. .id = "pfifo_fast",
  370. .priv_size = PFIFO_FAST_BANDS * sizeof(struct sk_buff_head),
  371. .enqueue = pfifo_fast_enqueue,
  372. .dequeue = pfifo_fast_dequeue,
  373. .requeue = pfifo_fast_requeue,
  374. .init = pfifo_fast_init,
  375. .reset = pfifo_fast_reset,
  376. .dump = pfifo_fast_dump,
  377. .owner = THIS_MODULE,
  378. };
  379. struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
  380. struct Qdisc_ops *ops)
  381. {
  382. void *p;
  383. struct Qdisc *sch;
  384. unsigned int size;
  385. int err = -ENOBUFS;
  386. /* ensure that the Qdisc and the private data are 32-byte aligned */
  387. size = QDISC_ALIGN(sizeof(*sch));
  388. size += ops->priv_size + (QDISC_ALIGNTO - 1);
  389. p = kzalloc(size, GFP_KERNEL);
  390. if (!p)
  391. goto errout;
  392. sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p);
  393. sch->padded = (char *) sch - (char *) p;
  394. INIT_LIST_HEAD(&sch->list);
  395. skb_queue_head_init(&sch->q);
  396. sch->ops = ops;
  397. sch->enqueue = ops->enqueue;
  398. sch->dequeue = ops->dequeue;
  399. sch->dev_queue = dev_queue;
  400. dev_hold(qdisc_dev(sch));
  401. atomic_set(&sch->refcnt, 1);
  402. return sch;
  403. errout:
  404. return ERR_PTR(err);
  405. }
  406. struct Qdisc * qdisc_create_dflt(struct net_device *dev,
  407. struct netdev_queue *dev_queue,
  408. struct Qdisc_ops *ops,
  409. unsigned int parentid)
  410. {
  411. struct Qdisc *sch;
  412. sch = qdisc_alloc(dev_queue, ops);
  413. if (IS_ERR(sch))
  414. goto errout;
  415. sch->parent = parentid;
  416. if (!ops->init || ops->init(sch, NULL) == 0)
  417. return sch;
  418. qdisc_destroy(sch);
  419. errout:
  420. return NULL;
  421. }
  422. EXPORT_SYMBOL(qdisc_create_dflt);
  423. /* Under queue->lock and BH! */
  424. void qdisc_reset(struct Qdisc *qdisc)
  425. {
  426. const struct Qdisc_ops *ops = qdisc->ops;
  427. if (ops->reset)
  428. ops->reset(qdisc);
  429. }
  430. EXPORT_SYMBOL(qdisc_reset);
  431. /* this is the rcu callback function to clean up a qdisc when there
  432. * are no further references to it */
  433. static void __qdisc_destroy(struct rcu_head *head)
  434. {
  435. struct Qdisc *qdisc = container_of(head, struct Qdisc, q_rcu);
  436. kfree((char *) qdisc - qdisc->padded);
  437. }
  438. /* Under queue->lock and BH! */
  439. void qdisc_destroy(struct Qdisc *qdisc)
  440. {
  441. const struct Qdisc_ops *ops = qdisc->ops;
  442. if (qdisc->flags & TCQ_F_BUILTIN ||
  443. !atomic_dec_and_test(&qdisc->refcnt))
  444. return;
  445. list_del(&qdisc->list);
  446. gen_kill_estimator(&qdisc->bstats, &qdisc->rate_est);
  447. if (ops->reset)
  448. ops->reset(qdisc);
  449. if (ops->destroy)
  450. ops->destroy(qdisc);
  451. module_put(ops->owner);
  452. dev_put(qdisc_dev(qdisc));
  453. call_rcu(&qdisc->q_rcu, __qdisc_destroy);
  454. }
  455. EXPORT_SYMBOL(qdisc_destroy);
  456. void dev_activate(struct net_device *dev)
  457. {
  458. struct netdev_queue *txq = &dev->tx_queue;
  459. /* No queueing discipline is attached to device;
  460. create default one i.e. pfifo_fast for devices,
  461. which need queueing and noqueue_qdisc for
  462. virtual interfaces
  463. */
  464. if (txq->qdisc_sleeping == &noop_qdisc) {
  465. struct Qdisc *qdisc;
  466. if (dev->tx_queue_len) {
  467. qdisc = qdisc_create_dflt(dev, txq,
  468. &pfifo_fast_ops,
  469. TC_H_ROOT);
  470. if (qdisc == NULL) {
  471. printk(KERN_INFO "%s: activation failed\n", dev->name);
  472. return;
  473. }
  474. list_add_tail(&qdisc->list, &txq->qdisc_list);
  475. } else {
  476. qdisc = &noqueue_qdisc;
  477. }
  478. txq->qdisc_sleeping = qdisc;
  479. }
  480. if (!netif_carrier_ok(dev))
  481. /* Delay activation until next carrier-on event */
  482. return;
  483. spin_lock_bh(&txq->lock);
  484. rcu_assign_pointer(txq->qdisc, txq->qdisc_sleeping);
  485. if (txq->qdisc != &noqueue_qdisc) {
  486. dev->trans_start = jiffies;
  487. dev_watchdog_up(dev);
  488. }
  489. spin_unlock_bh(&txq->lock);
  490. }
  491. static void dev_deactivate_queue(struct netdev_queue *dev_queue,
  492. struct Qdisc *qdisc_default)
  493. {
  494. struct Qdisc *qdisc;
  495. struct sk_buff *skb;
  496. spin_lock_bh(&dev_queue->lock);
  497. qdisc = dev_queue->qdisc;
  498. if (qdisc) {
  499. dev_queue->qdisc = qdisc_default;
  500. qdisc_reset(qdisc);
  501. }
  502. skb = dev_queue->gso_skb;
  503. dev_queue->gso_skb = NULL;
  504. spin_unlock_bh(&dev_queue->lock);
  505. kfree_skb(skb);
  506. }
  507. void dev_deactivate(struct net_device *dev)
  508. {
  509. int running;
  510. dev_deactivate_queue(&dev->tx_queue, &noop_qdisc);
  511. dev_watchdog_down(dev);
  512. /* Wait for outstanding qdisc-less dev_queue_xmit calls. */
  513. synchronize_rcu();
  514. /* Wait for outstanding qdisc_run calls. */
  515. do {
  516. while (test_bit(__LINK_STATE_QDISC_RUNNING, &dev->state))
  517. yield();
  518. /*
  519. * Double-check inside queue lock to ensure that all effects
  520. * of the queue run are visible when we return.
  521. */
  522. spin_lock_bh(&dev->tx_queue.lock);
  523. running = test_bit(__LINK_STATE_QDISC_RUNNING, &dev->state);
  524. spin_unlock_bh(&dev->tx_queue.lock);
  525. /*
  526. * The running flag should never be set at this point because
  527. * we've already set dev->qdisc to noop_qdisc *inside* the same
  528. * pair of spin locks. That is, if any qdisc_run starts after
  529. * our initial test it should see the noop_qdisc and then
  530. * clear the RUNNING bit before dropping the queue lock. So
  531. * if it is set here then we've found a bug.
  532. */
  533. } while (WARN_ON_ONCE(running));
  534. }
  535. static void dev_init_scheduler_queue(struct net_device *dev,
  536. struct netdev_queue *dev_queue,
  537. struct Qdisc *qdisc)
  538. {
  539. dev_queue->qdisc = qdisc;
  540. dev_queue->qdisc_sleeping = qdisc;
  541. INIT_LIST_HEAD(&dev_queue->qdisc_list);
  542. }
  543. void dev_init_scheduler(struct net_device *dev)
  544. {
  545. qdisc_lock_tree(dev);
  546. dev_init_scheduler_queue(dev, &dev->tx_queue, &noop_qdisc);
  547. dev_init_scheduler_queue(dev, &dev->rx_queue, NULL);
  548. qdisc_unlock_tree(dev);
  549. setup_timer(&dev->watchdog_timer, dev_watchdog, (unsigned long)dev);
  550. }
  551. static void dev_shutdown_scheduler_queue(struct net_device *dev,
  552. struct netdev_queue *dev_queue,
  553. struct Qdisc *qdisc_default)
  554. {
  555. struct Qdisc *qdisc = dev_queue->qdisc_sleeping;
  556. if (qdisc) {
  557. dev_queue->qdisc = qdisc_default;
  558. dev_queue->qdisc_sleeping = qdisc_default;
  559. qdisc_destroy(qdisc);
  560. }
  561. }
  562. void dev_shutdown(struct net_device *dev)
  563. {
  564. qdisc_lock_tree(dev);
  565. dev_shutdown_scheduler_queue(dev, &dev->tx_queue, &noop_qdisc);
  566. dev_shutdown_scheduler_queue(dev, &dev->rx_queue, NULL);
  567. BUG_TRAP(!timer_pending(&dev->watchdog_timer));
  568. qdisc_unlock_tree(dev);
  569. }