diff options
Diffstat (limited to 'drivers/net/virtio_net.c')
-rw-r--r-- | drivers/net/virtio_net.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 5450eac9e263..4452306d5328 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -44,11 +44,15 @@ struct virtnet_info | |||
44 | /* The skb we couldn't send because buffers were full. */ | 44 | /* The skb we couldn't send because buffers were full. */ |
45 | struct sk_buff *last_xmit_skb; | 45 | struct sk_buff *last_xmit_skb; |
46 | 46 | ||
47 | /* If we need to free in a timer, this is it. */ | ||
48 | struct timer_list xmit_free_timer; | ||
49 | |||
47 | /* Number of input buffers, and max we've ever had. */ | 50 | /* Number of input buffers, and max we've ever had. */ |
48 | unsigned int num, max; | 51 | unsigned int num, max; |
49 | 52 | ||
50 | /* For cleaning up after transmission. */ | 53 | /* For cleaning up after transmission. */ |
51 | struct tasklet_struct tasklet; | 54 | struct tasklet_struct tasklet; |
55 | bool free_in_tasklet; | ||
52 | 56 | ||
53 | /* Receive & send queues. */ | 57 | /* Receive & send queues. */ |
54 | struct sk_buff_head recv; | 58 | struct sk_buff_head recv; |
@@ -72,7 +76,7 @@ static void skb_xmit_done(struct virtqueue *svq) | |||
72 | /* Suppress further interrupts. */ | 76 | /* Suppress further interrupts. */ |
73 | svq->vq_ops->disable_cb(svq); | 77 | svq->vq_ops->disable_cb(svq); |
74 | 78 | ||
75 | /* We were waiting for more output buffers. */ | 79 | /* We were probably waiting for more output buffers. */ |
76 | netif_wake_queue(vi->dev); | 80 | netif_wake_queue(vi->dev); |
77 | 81 | ||
78 | /* Make sure we re-xmit last_xmit_skb: if there are no more packets | 82 | /* Make sure we re-xmit last_xmit_skb: if there are no more packets |
@@ -94,9 +98,7 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb, | |||
94 | BUG_ON(len > MAX_PACKET_LEN); | 98 | BUG_ON(len > MAX_PACKET_LEN); |
95 | 99 | ||
96 | skb_trim(skb, len); | 100 | skb_trim(skb, len); |
97 | skb->protocol = eth_type_trans(skb, dev); | 101 | |
98 | pr_debug("Receiving skb proto 0x%04x len %i type %i\n", | ||
99 | ntohs(skb->protocol), skb->len, skb->pkt_type); | ||
100 | dev->stats.rx_bytes += skb->len; | 102 | dev->stats.rx_bytes += skb->len; |
101 | dev->stats.rx_packets++; | 103 | dev->stats.rx_packets++; |
102 | 104 | ||
@@ -106,6 +108,10 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb, | |||
106 | goto frame_err; | 108 | goto frame_err; |
107 | } | 109 | } |
108 | 110 | ||
111 | skb->protocol = eth_type_trans(skb, dev); | ||
112 | pr_debug("Receiving skb proto 0x%04x len %i type %i\n", | ||
113 | ntohs(skb->protocol), skb->len, skb->pkt_type); | ||
114 | |||
109 | if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) { | 115 | if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) { |
110 | pr_debug("GSO!\n"); | 116 | pr_debug("GSO!\n"); |
111 | switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { | 117 | switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { |
@@ -238,9 +244,25 @@ static void free_old_xmit_skbs(struct virtnet_info *vi) | |||
238 | } | 244 | } |
239 | } | 245 | } |
240 | 246 | ||
247 | /* If the virtio transport doesn't always notify us when all in-flight packets | ||
248 | * are consumed, we fall back to using this function on a timer to free them. */ | ||
249 | static void xmit_free(unsigned long data) | ||
250 | { | ||
251 | struct virtnet_info *vi = (void *)data; | ||
252 | |||
253 | netif_tx_lock(vi->dev); | ||
254 | |||
255 | free_old_xmit_skbs(vi); | ||
256 | |||
257 | if (!skb_queue_empty(&vi->send)) | ||
258 | mod_timer(&vi->xmit_free_timer, jiffies + (HZ/10)); | ||
259 | |||
260 | netif_tx_unlock(vi->dev); | ||
261 | } | ||
262 | |||
241 | static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb) | 263 | static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb) |
242 | { | 264 | { |
243 | int num; | 265 | int num, err; |
244 | struct scatterlist sg[2+MAX_SKB_FRAGS]; | 266 | struct scatterlist sg[2+MAX_SKB_FRAGS]; |
245 | struct virtio_net_hdr *hdr; | 267 | struct virtio_net_hdr *hdr; |
246 | const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; | 268 | const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; |
@@ -283,7 +305,11 @@ static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb) | |||
283 | vnet_hdr_to_sg(sg, skb); | 305 | vnet_hdr_to_sg(sg, skb); |
284 | num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1; | 306 | num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1; |
285 | 307 | ||
286 | return vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb); | 308 | err = vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb); |
309 | if (!err && !vi->free_in_tasklet) | ||
310 | mod_timer(&vi->xmit_free_timer, jiffies + (HZ/10)); | ||
311 | |||
312 | return err; | ||
287 | } | 313 | } |
288 | 314 | ||
289 | static void xmit_tasklet(unsigned long data) | 315 | static void xmit_tasklet(unsigned long data) |
@@ -295,6 +321,8 @@ static void xmit_tasklet(unsigned long data) | |||
295 | vi->svq->vq_ops->kick(vi->svq); | 321 | vi->svq->vq_ops->kick(vi->svq); |
296 | vi->last_xmit_skb = NULL; | 322 | vi->last_xmit_skb = NULL; |
297 | } | 323 | } |
324 | if (vi->free_in_tasklet) | ||
325 | free_old_xmit_skbs(vi); | ||
298 | netif_tx_unlock_bh(vi->dev); | 326 | netif_tx_unlock_bh(vi->dev); |
299 | } | 327 | } |
300 | 328 | ||
@@ -435,6 +463,10 @@ static int virtnet_probe(struct virtio_device *vdev) | |||
435 | vi->vdev = vdev; | 463 | vi->vdev = vdev; |
436 | vdev->priv = vi; | 464 | vdev->priv = vi; |
437 | 465 | ||
466 | /* If they give us a callback when all buffers are done, we don't need | ||
467 | * the timer. */ | ||
468 | vi->free_in_tasklet = virtio_has_feature(vdev,VIRTIO_F_NOTIFY_ON_EMPTY); | ||
469 | |||
438 | /* We expect two virtqueues, receive then send. */ | 470 | /* We expect two virtqueues, receive then send. */ |
439 | vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done); | 471 | vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done); |
440 | if (IS_ERR(vi->rvq)) { | 472 | if (IS_ERR(vi->rvq)) { |
@@ -454,6 +486,9 @@ static int virtnet_probe(struct virtio_device *vdev) | |||
454 | 486 | ||
455 | tasklet_init(&vi->tasklet, xmit_tasklet, (unsigned long)vi); | 487 | tasklet_init(&vi->tasklet, xmit_tasklet, (unsigned long)vi); |
456 | 488 | ||
489 | if (!vi->free_in_tasklet) | ||
490 | setup_timer(&vi->xmit_free_timer, xmit_free, (unsigned long)vi); | ||
491 | |||
457 | err = register_netdev(dev); | 492 | err = register_netdev(dev); |
458 | if (err) { | 493 | if (err) { |
459 | pr_debug("virtio_net: registering device failed\n"); | 494 | pr_debug("virtio_net: registering device failed\n"); |
@@ -491,6 +526,9 @@ static void virtnet_remove(struct virtio_device *vdev) | |||
491 | /* Stop all the virtqueues. */ | 526 | /* Stop all the virtqueues. */ |
492 | vdev->config->reset(vdev); | 527 | vdev->config->reset(vdev); |
493 | 528 | ||
529 | if (!vi->free_in_tasklet) | ||
530 | del_timer_sync(&vi->xmit_free_timer); | ||
531 | |||
494 | /* Free our skbs in send and recv queues, if any. */ | 532 | /* Free our skbs in send and recv queues, if any. */ |
495 | while ((skb = __skb_dequeue(&vi->recv)) != NULL) { | 533 | while ((skb = __skb_dequeue(&vi->recv)) != NULL) { |
496 | kfree_skb(skb); | 534 | kfree_skb(skb); |
@@ -514,7 +552,7 @@ static struct virtio_device_id id_table[] = { | |||
514 | static unsigned int features[] = { | 552 | static unsigned int features[] = { |
515 | VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, | 553 | VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, |
516 | VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, | 554 | VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, |
517 | VIRTIO_NET_F_HOST_ECN, | 555 | VIRTIO_NET_F_HOST_ECN, VIRTIO_F_NOTIFY_ON_EMPTY, |
518 | }; | 556 | }; |
519 | 557 | ||
520 | static struct virtio_driver virtio_net = { | 558 | static struct virtio_driver virtio_net = { |