aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/virtio_net.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2013-07-24 20:50:23 -0400
committerDavid S. Miller <davem@davemloft.net>2013-07-27 23:06:10 -0400
commite7428e95a06fb516fac1308bd0e176e27c0b9287 (patch)
tree7ccd3f84a565b24ddf7efe5b10325cfd34ad98fc /drivers/net/virtio_net.c
parent10eccb46b521359fa344f63459087df722f0776d (diff)
virtio-net: put virtio net header inline with data
For small packets we can simplify xmit processing by linearizing buffers with the header: most packets seem to have enough head room we can use for this purpose. Since existing hypervisors require that header is the first s/g element, we need a feature bit for this. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/virtio_net.c')
-rw-r--r--drivers/net/virtio_net.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 3d2a90a62649..f21600277583 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -106,6 +106,9 @@ struct virtnet_info {
106 /* Has control virtqueue */ 106 /* Has control virtqueue */
107 bool has_cvq; 107 bool has_cvq;
108 108
109 /* Host can handle any s/g split between our header and packet data */
110 bool any_header_sg;
111
109 /* enable config space updates */ 112 /* enable config space updates */
110 bool config_enable; 113 bool config_enable;
111 114
@@ -669,12 +672,28 @@ static void free_old_xmit_skbs(struct send_queue *sq)
669 672
670static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) 673static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
671{ 674{
672 struct skb_vnet_hdr *hdr = skb_vnet_hdr(skb); 675 struct skb_vnet_hdr *hdr;
673 const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; 676 const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
674 struct virtnet_info *vi = sq->vq->vdev->priv; 677 struct virtnet_info *vi = sq->vq->vdev->priv;
675 unsigned num_sg; 678 unsigned num_sg;
679 unsigned hdr_len;
680 bool can_push;
676 681
677 pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); 682 pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest);
683 if (vi->mergeable_rx_bufs)
684 hdr_len = sizeof hdr->mhdr;
685 else
686 hdr_len = sizeof hdr->hdr;
687
688 can_push = vi->any_header_sg &&
689 !((unsigned long)skb->data & (__alignof__(*hdr) - 1)) &&
690 !skb_header_cloned(skb) && skb_headroom(skb) >= hdr_len;
691 /* Even if we can, don't push here yet as this would skew
692 * csum_start offset below. */
693 if (can_push)
694 hdr = (struct skb_vnet_hdr *)(skb->data - hdr_len);
695 else
696 hdr = skb_vnet_hdr(skb);
678 697
679 if (skb->ip_summed == CHECKSUM_PARTIAL) { 698 if (skb->ip_summed == CHECKSUM_PARTIAL) {
680 hdr->hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; 699 hdr->hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
@@ -703,15 +722,18 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
703 hdr->hdr.gso_size = hdr->hdr.hdr_len = 0; 722 hdr->hdr.gso_size = hdr->hdr.hdr_len = 0;
704 } 723 }
705 724
706 hdr->mhdr.num_buffers = 0;
707
708 /* Encode metadata header at front. */
709 if (vi->mergeable_rx_bufs) 725 if (vi->mergeable_rx_bufs)
710 sg_set_buf(sq->sg, &hdr->mhdr, sizeof hdr->mhdr); 726 hdr->mhdr.num_buffers = 0;
711 else
712 sg_set_buf(sq->sg, &hdr->hdr, sizeof hdr->hdr);
713 727
714 num_sg = skb_to_sgvec(skb, sq->sg + 1, 0, skb->len) + 1; 728 if (can_push) {
729 __skb_push(skb, hdr_len);
730 num_sg = skb_to_sgvec(skb, sq->sg, 0, skb->len);
731 /* Pull header back to avoid skew in tx bytes calculations. */
732 __skb_pull(skb, hdr_len);
733 } else {
734 sg_set_buf(sq->sg, hdr, hdr_len);
735 num_sg = skb_to_sgvec(skb, sq->sg + 1, 0, skb->len) + 1;
736 }
715 return virtqueue_add_outbuf(sq->vq, sq->sg, num_sg, skb, GFP_ATOMIC); 737 return virtqueue_add_outbuf(sq->vq, sq->sg, num_sg, skb, GFP_ATOMIC);
716} 738}
717 739
@@ -1552,6 +1574,9 @@ static int virtnet_probe(struct virtio_device *vdev)
1552 if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) 1574 if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
1553 vi->mergeable_rx_bufs = true; 1575 vi->mergeable_rx_bufs = true;
1554 1576
1577 if (virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT))
1578 vi->any_header_sg = true;
1579
1555 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) 1580 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ))
1556 vi->has_cvq = true; 1581 vi->has_cvq = true;
1557 1582
@@ -1727,6 +1752,7 @@ static unsigned int features[] = {
1727 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, 1752 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
1728 VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ, 1753 VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ,
1729 VIRTIO_NET_F_CTRL_MAC_ADDR, 1754 VIRTIO_NET_F_CTRL_MAC_ADDR,
1755 VIRTIO_F_ANY_LAYOUT,
1730}; 1756};
1731 1757
1732static struct virtio_driver virtio_net_driver = { 1758static struct virtio_driver virtio_net_driver = {