Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 105763
b: refs/heads/master
c: 97402b9
h: refs/heads/master
i:
  105761: 9925c8a
  105759: b3c4209
v: v3
  • Loading branch information
Herbert Xu authored and Rusty Russell committed Jul 25, 2008
1 parent 5603241 commit 57067a5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a9ea3fc6f2654a7407864fec983d1671d775b5ee
refs/heads/master: 97402b96f87c6e32f75f1bffdd91a5ee144b679d
44 changes: 39 additions & 5 deletions trunk/drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ struct virtnet_info
struct tasklet_struct tasklet;
bool free_in_tasklet;

/* I like... big packets and I cannot lie! */
bool big_packets;

/* Receive & send queues. */
struct sk_buff_head recv;
struct sk_buff_head send;
Expand Down Expand Up @@ -89,17 +92,22 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
unsigned len)
{
struct virtio_net_hdr *hdr = skb_vnet_hdr(skb);
int err;

if (unlikely(len < sizeof(struct virtio_net_hdr) + ETH_HLEN)) {
pr_debug("%s: short packet %i\n", dev->name, len);
dev->stats.rx_length_errors++;
goto drop;
}
len -= sizeof(struct virtio_net_hdr);
BUG_ON(len > MAX_PACKET_LEN);

skb_trim(skb, len);

err = pskb_trim(skb, len);
if (err) {
pr_debug("%s: pskb_trim failed %i %d\n", dev->name, len, err);
dev->stats.rx_dropped++;
goto drop;
}
skb->truesize += skb->data_len;
dev->stats.rx_bytes += skb->len;
dev->stats.rx_packets++;

Expand Down Expand Up @@ -161,7 +169,7 @@ static void try_fill_recv(struct virtnet_info *vi)
{
struct sk_buff *skb;
struct scatterlist sg[2+MAX_SKB_FRAGS];
int num, err;
int num, err, i;

sg_init_table(sg, 2+MAX_SKB_FRAGS);
for (;;) {
Expand All @@ -171,6 +179,24 @@ static void try_fill_recv(struct virtnet_info *vi)

skb_put(skb, MAX_PACKET_LEN);
vnet_hdr_to_sg(sg, skb);

if (vi->big_packets) {
for (i = 0; i < MAX_SKB_FRAGS; i++) {
skb_frag_t *f = &skb_shinfo(skb)->frags[i];
f->page = alloc_page(GFP_ATOMIC);
if (!f->page)
break;

f->page_offset = 0;
f->size = PAGE_SIZE;

skb->data_len += PAGE_SIZE;
skb->len += PAGE_SIZE;

skb_shinfo(skb)->nr_frags++;
}
}

num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
skb_queue_head(&vi->recv, skb);

Expand Down Expand Up @@ -485,6 +511,12 @@ static int virtnet_probe(struct virtio_device *vdev)
* the timer. */
vi->free_in_tasklet = virtio_has_feature(vdev,VIRTIO_F_NOTIFY_ON_EMPTY);

/* If we can receive ANY GSO packets, we must allocate large ones. */
if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4)
|| virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6)
|| virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN))
vi->big_packets = true;

/* We expect two virtqueues, receive then send. */
vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done);
if (IS_ERR(vi->rvq)) {
Expand Down Expand Up @@ -571,7 +603,9 @@ static unsigned int features[] = {
VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM,
VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC,
VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6,
VIRTIO_NET_F_HOST_ECN, VIRTIO_F_NOTIFY_ON_EMPTY,
VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
VIRTIO_F_NOTIFY_ON_EMPTY,
};

static struct virtio_driver virtio_net = {
Expand Down

0 comments on commit 57067a5

Please sign in to comment.