irda: convert to netdev_tx_t
[deliverable/linux.git] / drivers / net / virtio_net.c
index 4d1d47953fc6e4d780c538b5ffd00c901ffc06bf..a6f903f00924835465a3e2a1c9e19d1210c9a478 100644 (file)
@@ -283,10 +283,11 @@ static void try_fill_recv_maxbufs(struct virtnet_info *vi)
        for (;;) {
                struct virtio_net_hdr *hdr;
 
-               skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN);
+               skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN + NET_IP_ALIGN);
                if (unlikely(!skb))
                        break;
 
+               skb_reserve(skb, NET_IP_ALIGN);
                skb_put(skb, MAX_PACKET_LEN);
 
                hdr = skb_vnet_hdr(skb);
@@ -470,7 +471,7 @@ static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb)
        }
 
        if (skb_is_gso(skb)) {
-               hdr->hdr_len = skb_transport_header(skb) - skb->data;
+               hdr->hdr_len = skb_headlen(skb);
                hdr->gso_size = skb_shinfo(skb)->gso_size;
                if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
                        hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
@@ -622,12 +623,9 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
        unsigned int tmp;
        int i;
 
-       if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
-               BUG();  /* Caller should know better */
-               return false;
-       }
-
-       BUG_ON(out + in > VIRTNET_SEND_COMMAND_SG_MAX);
+       /* Caller should know better */
+       BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) ||
+               (out + in > VIRTNET_SEND_COMMAND_SG_MAX));
 
        out++; /* Add header */
        in++; /* Add return status */
@@ -642,8 +640,7 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
                sg_set_buf(&sg[i + 1], sg_virt(s), s->length);
        sg_set_buf(&sg[out + in - 1], &status, sizeof(status));
 
-       if (vi->cvq->vq_ops->add_buf(vi->cvq, sg, out, in, vi) != 0)
-               BUG();
+       BUG_ON(vi->cvq->vq_ops->add_buf(vi->cvq, sg, out, in, vi));
 
        vi->cvq->vq_ops->kick(vi->cvq);
 
@@ -684,6 +681,7 @@ static void virtnet_set_rx_mode(struct net_device *dev)
        u8 promisc, allmulti;
        struct virtio_net_ctrl_mac *mac_data;
        struct dev_addr_list *addr;
+       struct netdev_hw_addr *ha;
        void *buf;
        int i;
 
@@ -711,7 +709,7 @@ static void virtnet_set_rx_mode(struct net_device *dev)
                         allmulti ? "en" : "dis");
 
        /* MAC filter - use one buffer for both lists */
-       mac_data = buf = kzalloc(((dev->uc_count + dev->mc_count) * ETH_ALEN) +
+       mac_data = buf = kzalloc(((dev->uc.count + dev->mc_count) * ETH_ALEN) +
                                 (2 * sizeof(mac_data->entries)), GFP_ATOMIC);
        if (!buf) {
                dev_warn(&dev->dev, "No memory for MAC address buffer\n");
@@ -721,16 +719,16 @@ static void virtnet_set_rx_mode(struct net_device *dev)
        sg_init_table(sg, 2);
 
        /* Store the unicast list and count in the front of the buffer */
-       mac_data->entries = dev->uc_count;
-       addr = dev->uc_list;
-       for (i = 0; i < dev->uc_count; i++, addr = addr->next)
-               memcpy(&mac_data->macs[i][0], addr->da_addr, ETH_ALEN);
+       mac_data->entries = dev->uc.count;
+       i = 0;
+       list_for_each_entry(ha, &dev->uc.list, list)
+               memcpy(&mac_data->macs[i++][0], ha->addr, ETH_ALEN);
 
        sg_set_buf(&sg[0], mac_data,
-                  sizeof(mac_data->entries) + (dev->uc_count * ETH_ALEN));
+                  sizeof(mac_data->entries) + (dev->uc.count * ETH_ALEN));
 
        /* multicast list and count fill the end */
-       mac_data = (void *)&mac_data->macs[dev->uc_count][0];
+       mac_data = (void *)&mac_data->macs[dev->uc.count][0];
 
        mac_data->entries = dev->mc_count;
        addr = dev->mc_list;
@@ -776,6 +774,7 @@ static struct ethtool_ops virtnet_ethtool_ops = {
        .set_tx_csum = virtnet_set_tx_csum,
        .set_sg = ethtool_op_set_sg,
        .set_tso = ethtool_op_set_tso,
+       .set_ufo = ethtool_op_set_ufo,
        .get_link = ethtool_op_get_link,
 };
 
@@ -845,6 +844,10 @@ static int virtnet_probe(struct virtio_device *vdev)
        int err;
        struct net_device *dev;
        struct virtnet_info *vi;
+       struct virtqueue *vqs[3];
+       vq_callback_t *callbacks[] = { skb_recv_done, skb_xmit_done, NULL};
+       const char *names[] = { "input", "output", "control" };
+       int nvqs;
 
        /* Allocate ourselves a network device with room for our info */
        dev = alloc_etherdev(sizeof(struct virtnet_info));
@@ -905,25 +908,19 @@ static int virtnet_probe(struct virtio_device *vdev)
        if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
                vi->mergeable_rx_bufs = true;
 
-       /* We expect two virtqueues, receive then send. */
-       vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done);
-       if (IS_ERR(vi->rvq)) {
-               err = PTR_ERR(vi->rvq);
+       /* We expect two virtqueues, receive then send,
+        * and optionally control. */
+       nvqs = virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) ? 3 : 2;
+
+       err = vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names);
+       if (err)
                goto free;
-       }
 
-       vi->svq = vdev->config->find_vq(vdev, 1, skb_xmit_done);
-       if (IS_ERR(vi->svq)) {
-               err = PTR_ERR(vi->svq);
-               goto free_recv;
-       }
+       vi->rvq = vqs[0];
+       vi->svq = vqs[1];
 
        if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
-               vi->cvq = vdev->config->find_vq(vdev, 2, NULL);
-               if (IS_ERR(vi->cvq)) {
-                       err = PTR_ERR(vi->svq);
-                       goto free_send;
-               }
+               vi->cvq = vqs[2];
 
                if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
                        dev->features |= NETIF_F_HW_VLAN_FILTER;
@@ -941,7 +938,7 @@ static int virtnet_probe(struct virtio_device *vdev)
        err = register_netdev(dev);
        if (err) {
                pr_debug("virtio_net: registering device failed\n");
-               goto free_ctrl;
+               goto free_vqs;
        }
 
        /* Last of all, set up some receive buffers. */
@@ -962,13 +959,8 @@ static int virtnet_probe(struct virtio_device *vdev)
 
 unregister:
        unregister_netdev(dev);
-free_ctrl:
-       if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ))
-               vdev->config->del_vq(vi->cvq);
-free_send:
-       vdev->config->del_vq(vi->svq);
-free_recv:
-       vdev->config->del_vq(vi->rvq);
+free_vqs:
+       vdev->config->del_vqs(vdev);
 free:
        free_netdev(dev);
        return err;
@@ -994,12 +986,10 @@ static void virtnet_remove(struct virtio_device *vdev)
 
        BUG_ON(vi->num != 0);
 
-       vdev->config->del_vq(vi->svq);
-       vdev->config->del_vq(vi->rvq);
-       if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ))
-               vdev->config->del_vq(vi->cvq);
        unregister_netdev(vi->dev);
 
+       vdev->config->del_vqs(vi->vdev);
+
        while (vi->pages)
                __free_pages(get_a_page(vi, GFP_KERNEL), 0);
 
@@ -1016,7 +1006,7 @@ static unsigned int features[] = {
        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_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
-       VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
+       VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO,
        VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
        VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
        VIRTIO_F_NOTIFY_ON_EMPTY,
This page took 0.029897 seconds and 5 git commands to generate.