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