/* NOTE: Called under dev->queue_lock with locally disabled BH. __LINK_STATE_QDISC_RUNNING guarantees only one CPU can enter this region at a time. dev->queue_lock serializes queue accesses for this device AND dev->qdisc pointer itself. netif_tx_lock serializes accesses to device driver. dev->queue_lock and netif_tx_lock are mutually exclusive, if one is grabbed, another must be free. Multiple CPUs may contend for the two locks. Note, that this procedure can be called by a watchdog timer, so that we do not check dev->tbusy flag here. Returns to the caller: 0 - queue is empty. >0 - queue is not empty: tx lock access or queue throttle <0 - Theres room to receive more if !netif_queue_stopped. (It is upon the caller to check for netif_queue_stopped before invoking this routine) */ int qdisc_restart(struct net_device *dev) { struct Qdisc *q = dev->qdisc; unsigned lockless = (dev->features & NETIF_F_LLTX); struct sk_buff *skb = NULL; int ret; ret = try_get_tx_pkt(&skb, dev, q); if (ret >= 0) return ret; /* we have a packet to send */ if (!lockless) { if (!netif_tx_trylock(dev)) return handle_tx_locked(skb,dev,q); } /* all clear .. */ spin_unlock(&dev->queue_lock); /* churn baby churn .. */ ret = dev_hard_start_xmit(skb, dev); if (!lockless) netif_tx_unlock(dev); spin_lock(&dev->queue_lock); /* most likely result, packet went ok */ if (ret == NETDEV_TX_OK) return -1; /* only for lockless drivers .. */ if (ret == NETDEV_TX_LOCKED && lockless) { return handle_tx_locked(skb,dev,q); } if (unlikely (ret != NETDEV_TX_BUSY)) { /* XXX: Do we need a ratelimit? */ printk("BUG %s code %d qlen %d\n",dev->name,ret,q->q.qlen); } return handle_dev_requeue(skb,dev,q); }