diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-10-16 09:26:14 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-12-17 23:50:33 -0500 |
commit | 9ed4cb073438e2154778f0d693d966359afd6549 (patch) | |
tree | d69dcb3b8a8cf9b719a8ee648551debbbf3152b6 /drivers | |
parent | 7bedc7dc7c05e6072dc81da770f70c683c45da10 (diff) |
virtio_net: don't rely on virtqueue_add_buf() returning capacity.
Now we can easily use vq->num_free to determine if there are descriptors
left in the queue, we're about to change virtqueue_add_buf() to return 0
on success. The virtio_net driver is the only one which actually uses
the return value, so change that.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/virtio_net.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 6c094c88424e..7c7f5a94ca4f 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -471,10 +471,11 @@ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp) | |||
471 | err = add_recvbuf_small(vi, gfp); | 471 | err = add_recvbuf_small(vi, gfp); |
472 | 472 | ||
473 | oom = err == -ENOMEM; | 473 | oom = err == -ENOMEM; |
474 | if (err < 0) | 474 | if (err) |
475 | break; | 475 | break; |
476 | ++vi->num; | 476 | ++vi->num; |
477 | } while (err > 0); | 477 | } while (vi->rvq->num_free); |
478 | |||
478 | if (unlikely(vi->num > vi->max)) | 479 | if (unlikely(vi->num > vi->max)) |
479 | vi->max = vi->num; | 480 | vi->max = vi->num; |
480 | virtqueue_kick(vi->rvq); | 481 | virtqueue_kick(vi->rvq); |
@@ -625,27 +626,20 @@ static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb) | |||
625 | static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) | 626 | static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) |
626 | { | 627 | { |
627 | struct virtnet_info *vi = netdev_priv(dev); | 628 | struct virtnet_info *vi = netdev_priv(dev); |
628 | int capacity; | 629 | int err; |
629 | 630 | ||
630 | /* Free up any pending old buffers before queueing new ones. */ | 631 | /* Free up any pending old buffers before queueing new ones. */ |
631 | free_old_xmit_skbs(vi); | 632 | free_old_xmit_skbs(vi); |
632 | 633 | ||
633 | /* Try to transmit */ | 634 | /* Try to transmit */ |
634 | capacity = xmit_skb(vi, skb); | 635 | err = xmit_skb(vi, skb); |
635 | 636 | ||
636 | /* This can happen with OOM and indirect buffers. */ | 637 | /* This should not happen! */ |
637 | if (unlikely(capacity < 0)) { | 638 | if (unlikely(err < 0)) { |
638 | if (likely(capacity == -ENOMEM)) { | 639 | dev->stats.tx_fifo_errors++; |
639 | if (net_ratelimit()) | 640 | if (net_ratelimit()) |
640 | dev_warn(&dev->dev, | 641 | dev_warn(&dev->dev, |
641 | "TX queue failure: out of memory\n"); | 642 | "Unexpected TX queue failure: %d\n", err); |
642 | } else { | ||
643 | dev->stats.tx_fifo_errors++; | ||
644 | if (net_ratelimit()) | ||
645 | dev_warn(&dev->dev, | ||
646 | "Unexpected TX queue failure: %d\n", | ||
647 | capacity); | ||
648 | } | ||
649 | dev->stats.tx_dropped++; | 643 | dev->stats.tx_dropped++; |
650 | kfree_skb(skb); | 644 | kfree_skb(skb); |
651 | return NETDEV_TX_OK; | 645 | return NETDEV_TX_OK; |
@@ -658,13 +652,12 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
658 | 652 | ||
659 | /* Apparently nice girls don't return TX_BUSY; stop the queue | 653 | /* Apparently nice girls don't return TX_BUSY; stop the queue |
660 | * before it gets out of hand. Naturally, this wastes entries. */ | 654 | * before it gets out of hand. Naturally, this wastes entries. */ |
661 | if (capacity < 2+MAX_SKB_FRAGS) { | 655 | if (vi->svq->num_free < 2+MAX_SKB_FRAGS) { |
662 | netif_stop_queue(dev); | 656 | netif_stop_queue(dev); |
663 | if (unlikely(!virtqueue_enable_cb_delayed(vi->svq))) { | 657 | if (unlikely(!virtqueue_enable_cb_delayed(vi->svq))) { |
664 | /* More just got used, free them then recheck. */ | 658 | /* More just got used, free them then recheck. */ |
665 | free_old_xmit_skbs(vi); | 659 | free_old_xmit_skbs(vi); |
666 | capacity = vi->svq->num_free; | 660 | if (vi->svq->num_free >= 2+MAX_SKB_FRAGS) { |
667 | if (capacity >= 2+MAX_SKB_FRAGS) { | ||
668 | netif_start_queue(dev); | 661 | netif_start_queue(dev); |
669 | virtqueue_disable_cb(vi->svq); | 662 | virtqueue_disable_cb(vi->svq); |
670 | } | 663 | } |