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