virtio_net.c (6eca954e25e8a67e48334e668b9ac7da21fcbc6f) virtio_net.c (f2f2c8b42d5b1858e1680133fcd4bea5c8dcdb2c)
1/* A network driver using virtio.
2 *
3 * Copyright 2007 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

--- 28 unchanged lines hidden (view full) ---

37/* FIXME: MTU in config. */
38#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
39#define GOOD_COPY_LEN 128
40
41#define VIRTNET_SEND_COMMAND_SG_MAX 2
42#define VIRTNET_DRIVER_VERSION "1.0.0"
43
44struct virtnet_stats {
1/* A network driver using virtio.
2 *
3 * Copyright 2007 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

--- 28 unchanged lines hidden (view full) ---

37/* FIXME: MTU in config. */
38#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
39#define GOOD_COPY_LEN 128
40
41#define VIRTNET_SEND_COMMAND_SG_MAX 2
42#define VIRTNET_DRIVER_VERSION "1.0.0"
43
44struct virtnet_stats {
45 struct u64_stats_sync syncp;
45 struct u64_stats_sync tx_syncp;
46 struct u64_stats_sync rx_syncp;
46 u64 tx_bytes;
47 u64 tx_packets;
48
49 u64 rx_bytes;
50 u64 rx_packets;
51};
52
53struct virtnet_info {

--- 241 unchanged lines hidden (view full) ---

295 if (receive_mergeable(vi, skb)) {
296 dev_kfree_skb(skb);
297 return;
298 }
299 }
300
301 hdr = skb_vnet_hdr(skb);
302
47 u64 tx_bytes;
48 u64 tx_packets;
49
50 u64 rx_bytes;
51 u64 rx_packets;
52};
53
54struct virtnet_info {

--- 241 unchanged lines hidden (view full) ---

296 if (receive_mergeable(vi, skb)) {
297 dev_kfree_skb(skb);
298 return;
299 }
300 }
301
302 hdr = skb_vnet_hdr(skb);
303
303 u64_stats_update_begin(&stats->syncp);
304 u64_stats_update_begin(&stats->rx_syncp);
304 stats->rx_bytes += skb->len;
305 stats->rx_packets++;
305 stats->rx_bytes += skb->len;
306 stats->rx_packets++;
306 u64_stats_update_end(&stats->syncp);
307 u64_stats_update_end(&stats->rx_syncp);
307
308 if (hdr->hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
309 pr_debug("Needs csum!\n");
310 if (!skb_partial_csum_set(skb,
311 hdr->hdr.csum_start,
312 hdr->hdr.csum_offset))
313 goto frame_err;
314 } else if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) {

--- 245 unchanged lines hidden (view full) ---

560{
561 struct sk_buff *skb;
562 unsigned int len, tot_sgs = 0;
563 struct virtnet_stats *stats = this_cpu_ptr(vi->stats);
564
565 while ((skb = virtqueue_get_buf(vi->svq, &len)) != NULL) {
566 pr_debug("Sent skb %p\n", skb);
567
308
309 if (hdr->hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
310 pr_debug("Needs csum!\n");
311 if (!skb_partial_csum_set(skb,
312 hdr->hdr.csum_start,
313 hdr->hdr.csum_offset))
314 goto frame_err;
315 } else if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) {

--- 245 unchanged lines hidden (view full) ---

561{
562 struct sk_buff *skb;
563 unsigned int len, tot_sgs = 0;
564 struct virtnet_stats *stats = this_cpu_ptr(vi->stats);
565
566 while ((skb = virtqueue_get_buf(vi->svq, &len)) != NULL) {
567 pr_debug("Sent skb %p\n", skb);
568
568 u64_stats_update_begin(&stats->syncp);
569 u64_stats_update_begin(&stats->tx_syncp);
569 stats->tx_bytes += skb->len;
570 stats->tx_packets++;
570 stats->tx_bytes += skb->len;
571 stats->tx_packets++;
571 u64_stats_update_end(&stats->syncp);
572 u64_stats_update_end(&stats->tx_syncp);
572
573 tot_sgs += skb_vnet_hdr(skb)->num_sg;
574 dev_kfree_skb_any(skb);
575 }
576 return tot_sgs;
577}
578
579static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb)

--- 118 unchanged lines hidden (view full) ---

698 int cpu;
699 unsigned int start;
700
701 for_each_possible_cpu(cpu) {
702 struct virtnet_stats *stats = per_cpu_ptr(vi->stats, cpu);
703 u64 tpackets, tbytes, rpackets, rbytes;
704
705 do {
573
574 tot_sgs += skb_vnet_hdr(skb)->num_sg;
575 dev_kfree_skb_any(skb);
576 }
577 return tot_sgs;
578}
579
580static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb)

--- 118 unchanged lines hidden (view full) ---

699 int cpu;
700 unsigned int start;
701
702 for_each_possible_cpu(cpu) {
703 struct virtnet_stats *stats = per_cpu_ptr(vi->stats, cpu);
704 u64 tpackets, tbytes, rpackets, rbytes;
705
706 do {
706 start = u64_stats_fetch_begin(&stats->syncp);
707 start = u64_stats_fetch_begin(&stats->tx_syncp);
707 tpackets = stats->tx_packets;
708 tbytes = stats->tx_bytes;
708 tpackets = stats->tx_packets;
709 tbytes = stats->tx_bytes;
710 } while (u64_stats_fetch_retry(&stats->tx_syncp, start));
711
712 do {
713 start = u64_stats_fetch_begin(&stats->rx_syncp);
709 rpackets = stats->rx_packets;
710 rbytes = stats->rx_bytes;
714 rpackets = stats->rx_packets;
715 rbytes = stats->rx_bytes;
711 } while (u64_stats_fetch_retry(&stats->syncp, start));
716 } while (u64_stats_fetch_retry(&stats->rx_syncp, start));
712
713 tot->rx_packets += rpackets;
714 tot->tx_packets += tpackets;
715 tot->rx_bytes += rbytes;
716 tot->tx_bytes += tbytes;
717 }
718
719 tot->tx_dropped = dev->stats.tx_dropped;

--- 332 unchanged lines hidden (view full) ---

1052 struct virtnet_info *vi;
1053
1054 /* Allocate ourselves a network device with room for our info */
1055 dev = alloc_etherdev(sizeof(struct virtnet_info));
1056 if (!dev)
1057 return -ENOMEM;
1058
1059 /* Set up network device as normal. */
717
718 tot->rx_packets += rpackets;
719 tot->tx_packets += tpackets;
720 tot->rx_bytes += rbytes;
721 tot->tx_bytes += tbytes;
722 }
723
724 tot->tx_dropped = dev->stats.tx_dropped;

--- 332 unchanged lines hidden (view full) ---

1057 struct virtnet_info *vi;
1058
1059 /* Allocate ourselves a network device with room for our info */
1060 dev = alloc_etherdev(sizeof(struct virtnet_info));
1061 if (!dev)
1062 return -ENOMEM;
1063
1064 /* Set up network device as normal. */
1060 dev->priv_flags |= IFF_UNICAST_FLT;
1065 dev->priv_flags |= IFF_UNICAST_FLT | IFF_LIVE_ADDR_CHANGE;
1061 dev->netdev_ops = &virtnet_netdev;
1062 dev->features = NETIF_F_HIGHDMA;
1063
1064 SET_ETHTOOL_OPS(dev, &virtnet_ethtool_ops);
1065 SET_NETDEV_DEV(dev, &vdev->dev);
1066
1067 /* Do we support "hardware" checksums? */
1068 if (virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) {

--- 249 unchanged lines hidden ---
1066 dev->netdev_ops = &virtnet_netdev;
1067 dev->features = NETIF_F_HIGHDMA;
1068
1069 SET_ETHTOOL_OPS(dev, &virtnet_ethtool_ops);
1070 SET_NETDEV_DEV(dev, &vdev->dev);
1071
1072 /* Do we support "hardware" checksums? */
1073 if (virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) {

--- 249 unchanged lines hidden ---