Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 1 | /* A simple 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. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | //#define DEBUG |
| 20 | #include <linux/netdevice.h> |
| 21 | #include <linux/etherdevice.h> |
Herbert Xu | a9ea3fc | 2008-04-18 11:21:42 +0800 | [diff] [blame] | 22 | #include <linux/ethtool.h> |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/virtio.h> |
| 25 | #include <linux/virtio_net.h> |
| 26 | #include <linux/scatterlist.h> |
| 27 | |
Dor Laor | 6c0cd7c | 2007-12-16 15:19:43 +0200 | [diff] [blame] | 28 | static int napi_weight = 128; |
| 29 | module_param(napi_weight, int, 0444); |
| 30 | |
Rusty Russell | 34a4857 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 31 | static int csum = 1, gso = 1; |
| 32 | module_param(csum, bool, 0444); |
| 33 | module_param(gso, bool, 0444); |
| 34 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 35 | /* FIXME: MTU in config. */ |
| 36 | #define MAX_PACKET_LEN (ETH_HLEN+ETH_DATA_LEN) |
| 37 | |
| 38 | struct virtnet_info |
| 39 | { |
| 40 | struct virtio_device *vdev; |
| 41 | struct virtqueue *rvq, *svq; |
| 42 | struct net_device *dev; |
| 43 | struct napi_struct napi; |
| 44 | |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 45 | /* The skb we couldn't send because buffers were full. */ |
| 46 | struct sk_buff *last_xmit_skb; |
| 47 | |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 48 | /* If we need to free in a timer, this is it. */ |
Mark McLoughlin | 14c998f | 2008-06-08 20:50:56 +1000 | [diff] [blame] | 49 | struct timer_list xmit_free_timer; |
| 50 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 51 | /* Number of input buffers, and max we've ever had. */ |
| 52 | unsigned int num, max; |
| 53 | |
Rusty Russell | 11a3a15 | 2008-05-26 17:48:13 +1000 | [diff] [blame] | 54 | /* For cleaning up after transmission. */ |
| 55 | struct tasklet_struct tasklet; |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 56 | bool free_in_tasklet; |
Rusty Russell | 11a3a15 | 2008-05-26 17:48:13 +1000 | [diff] [blame] | 57 | |
Herbert Xu | 97402b9 | 2008-04-18 11:24:27 +0800 | [diff] [blame] | 58 | /* I like... big packets and I cannot lie! */ |
| 59 | bool big_packets; |
| 60 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 61 | /* Receive & send queues. */ |
| 62 | struct sk_buff_head recv; |
| 63 | struct sk_buff_head send; |
Rusty Russell | fb6813f | 2008-07-25 12:06:01 -0500 | [diff] [blame] | 64 | |
| 65 | /* Chain pages by the private ptr. */ |
| 66 | struct page *pages; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static inline struct virtio_net_hdr *skb_vnet_hdr(struct sk_buff *skb) |
| 70 | { |
| 71 | return (struct virtio_net_hdr *)skb->cb; |
| 72 | } |
| 73 | |
| 74 | static inline void vnet_hdr_to_sg(struct scatterlist *sg, struct sk_buff *skb) |
| 75 | { |
| 76 | sg_init_one(sg, skb_vnet_hdr(skb), sizeof(struct virtio_net_hdr)); |
| 77 | } |
| 78 | |
Rusty Russell | fb6813f | 2008-07-25 12:06:01 -0500 | [diff] [blame] | 79 | static void give_a_page(struct virtnet_info *vi, struct page *page) |
| 80 | { |
| 81 | page->private = (unsigned long)vi->pages; |
| 82 | vi->pages = page; |
| 83 | } |
| 84 | |
| 85 | static struct page *get_a_page(struct virtnet_info *vi, gfp_t gfp_mask) |
| 86 | { |
| 87 | struct page *p = vi->pages; |
| 88 | |
| 89 | if (p) |
| 90 | vi->pages = (struct page *)p->private; |
| 91 | else |
| 92 | p = alloc_page(gfp_mask); |
| 93 | return p; |
| 94 | } |
| 95 | |
Rusty Russell | 2cb9c6b | 2008-02-04 23:50:07 -0500 | [diff] [blame] | 96 | static void skb_xmit_done(struct virtqueue *svq) |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 97 | { |
Rusty Russell | 2cb9c6b | 2008-02-04 23:50:07 -0500 | [diff] [blame] | 98 | struct virtnet_info *vi = svq->vdev->priv; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 99 | |
Rusty Russell | 2cb9c6b | 2008-02-04 23:50:07 -0500 | [diff] [blame] | 100 | /* Suppress further interrupts. */ |
| 101 | svq->vq_ops->disable_cb(svq); |
Rusty Russell | 11a3a15 | 2008-05-26 17:48:13 +1000 | [diff] [blame] | 102 | |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 103 | /* We were probably waiting for more output buffers. */ |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 104 | netif_wake_queue(vi->dev); |
Rusty Russell | 11a3a15 | 2008-05-26 17:48:13 +1000 | [diff] [blame] | 105 | |
| 106 | /* Make sure we re-xmit last_xmit_skb: if there are no more packets |
| 107 | * queued, start_xmit won't be called. */ |
| 108 | tasklet_schedule(&vi->tasklet); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static void receive_skb(struct net_device *dev, struct sk_buff *skb, |
| 112 | unsigned len) |
| 113 | { |
| 114 | struct virtio_net_hdr *hdr = skb_vnet_hdr(skb); |
Herbert Xu | 97402b9 | 2008-04-18 11:24:27 +0800 | [diff] [blame] | 115 | int err; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 116 | |
| 117 | if (unlikely(len < sizeof(struct virtio_net_hdr) + ETH_HLEN)) { |
| 118 | pr_debug("%s: short packet %i\n", dev->name, len); |
| 119 | dev->stats.rx_length_errors++; |
| 120 | goto drop; |
| 121 | } |
| 122 | len -= sizeof(struct virtio_net_hdr); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 123 | |
Rusty Russell | fb6813f | 2008-07-25 12:06:01 -0500 | [diff] [blame] | 124 | if (len <= MAX_PACKET_LEN) { |
| 125 | unsigned int i; |
| 126 | |
| 127 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) |
Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame^] | 128 | give_a_page(netdev_priv(dev), |
| 129 | skb_shinfo(skb)->frags[i].page); |
Rusty Russell | fb6813f | 2008-07-25 12:06:01 -0500 | [diff] [blame] | 130 | skb->data_len = 0; |
| 131 | skb_shinfo(skb)->nr_frags = 0; |
| 132 | } |
| 133 | |
Herbert Xu | 97402b9 | 2008-04-18 11:24:27 +0800 | [diff] [blame] | 134 | err = pskb_trim(skb, len); |
| 135 | if (err) { |
| 136 | pr_debug("%s: pskb_trim failed %i %d\n", dev->name, len, err); |
| 137 | dev->stats.rx_dropped++; |
| 138 | goto drop; |
| 139 | } |
| 140 | skb->truesize += skb->data_len; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 141 | dev->stats.rx_bytes += skb->len; |
| 142 | dev->stats.rx_packets++; |
| 143 | |
| 144 | if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { |
| 145 | pr_debug("Needs csum!\n"); |
Rusty Russell | f35d9d8 | 2008-02-04 23:49:54 -0500 | [diff] [blame] | 146 | if (!skb_partial_csum_set(skb,hdr->csum_start,hdr->csum_offset)) |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 147 | goto frame_err; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 148 | } |
| 149 | |
Mark McLoughlin | 23cde76 | 2008-06-08 20:49:00 +1000 | [diff] [blame] | 150 | skb->protocol = eth_type_trans(skb, dev); |
| 151 | pr_debug("Receiving skb proto 0x%04x len %i type %i\n", |
| 152 | ntohs(skb->protocol), skb->len, skb->pkt_type); |
| 153 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 154 | if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) { |
| 155 | pr_debug("GSO!\n"); |
Rusty Russell | 34a4857 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 156 | switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 157 | case VIRTIO_NET_HDR_GSO_TCPV4: |
| 158 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
| 159 | break; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 160 | case VIRTIO_NET_HDR_GSO_UDP: |
| 161 | skb_shinfo(skb)->gso_type = SKB_GSO_UDP; |
| 162 | break; |
| 163 | case VIRTIO_NET_HDR_GSO_TCPV6: |
| 164 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; |
| 165 | break; |
| 166 | default: |
| 167 | if (net_ratelimit()) |
| 168 | printk(KERN_WARNING "%s: bad gso type %u.\n", |
| 169 | dev->name, hdr->gso_type); |
| 170 | goto frame_err; |
| 171 | } |
| 172 | |
Rusty Russell | 34a4857 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 173 | if (hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN) |
| 174 | skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN; |
| 175 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 176 | skb_shinfo(skb)->gso_size = hdr->gso_size; |
| 177 | if (skb_shinfo(skb)->gso_size == 0) { |
| 178 | if (net_ratelimit()) |
| 179 | printk(KERN_WARNING "%s: zero gso size.\n", |
| 180 | dev->name); |
| 181 | goto frame_err; |
| 182 | } |
| 183 | |
| 184 | /* Header must be checked, and gso_segs computed. */ |
| 185 | skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY; |
| 186 | skb_shinfo(skb)->gso_segs = 0; |
| 187 | } |
| 188 | |
| 189 | netif_receive_skb(skb); |
| 190 | return; |
| 191 | |
| 192 | frame_err: |
| 193 | dev->stats.rx_frame_errors++; |
| 194 | drop: |
| 195 | dev_kfree_skb(skb); |
| 196 | } |
| 197 | |
| 198 | static void try_fill_recv(struct virtnet_info *vi) |
| 199 | { |
| 200 | struct sk_buff *skb; |
Rusty Russell | 0527168 | 2008-05-02 21:50:45 -0500 | [diff] [blame] | 201 | struct scatterlist sg[2+MAX_SKB_FRAGS]; |
Herbert Xu | 97402b9 | 2008-04-18 11:24:27 +0800 | [diff] [blame] | 202 | int num, err, i; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 203 | |
Rusty Russell | 0527168 | 2008-05-02 21:50:45 -0500 | [diff] [blame] | 204 | sg_init_table(sg, 2+MAX_SKB_FRAGS); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 205 | for (;;) { |
| 206 | skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN); |
| 207 | if (unlikely(!skb)) |
| 208 | break; |
| 209 | |
| 210 | skb_put(skb, MAX_PACKET_LEN); |
| 211 | vnet_hdr_to_sg(sg, skb); |
Herbert Xu | 97402b9 | 2008-04-18 11:24:27 +0800 | [diff] [blame] | 212 | |
| 213 | if (vi->big_packets) { |
| 214 | for (i = 0; i < MAX_SKB_FRAGS; i++) { |
| 215 | skb_frag_t *f = &skb_shinfo(skb)->frags[i]; |
Rusty Russell | fb6813f | 2008-07-25 12:06:01 -0500 | [diff] [blame] | 216 | f->page = get_a_page(vi, GFP_ATOMIC); |
Herbert Xu | 97402b9 | 2008-04-18 11:24:27 +0800 | [diff] [blame] | 217 | if (!f->page) |
| 218 | break; |
| 219 | |
| 220 | f->page_offset = 0; |
| 221 | f->size = PAGE_SIZE; |
| 222 | |
| 223 | skb->data_len += PAGE_SIZE; |
| 224 | skb->len += PAGE_SIZE; |
| 225 | |
| 226 | skb_shinfo(skb)->nr_frags++; |
| 227 | } |
| 228 | } |
| 229 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 230 | num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1; |
| 231 | skb_queue_head(&vi->recv, skb); |
| 232 | |
| 233 | err = vi->rvq->vq_ops->add_buf(vi->rvq, sg, 0, num, skb); |
| 234 | if (err) { |
| 235 | skb_unlink(skb, &vi->recv); |
| 236 | kfree_skb(skb); |
| 237 | break; |
| 238 | } |
| 239 | vi->num++; |
| 240 | } |
| 241 | if (unlikely(vi->num > vi->max)) |
| 242 | vi->max = vi->num; |
| 243 | vi->rvq->vq_ops->kick(vi->rvq); |
| 244 | } |
| 245 | |
Rusty Russell | 18445c4 | 2008-02-04 23:49:57 -0500 | [diff] [blame] | 246 | static void skb_recv_done(struct virtqueue *rvq) |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 247 | { |
| 248 | struct virtnet_info *vi = rvq->vdev->priv; |
Rusty Russell | 18445c4 | 2008-02-04 23:49:57 -0500 | [diff] [blame] | 249 | /* Schedule NAPI, Suppress further interrupts if successful. */ |
| 250 | if (netif_rx_schedule_prep(vi->dev, &vi->napi)) { |
| 251 | rvq->vq_ops->disable_cb(rvq); |
| 252 | __netif_rx_schedule(vi->dev, &vi->napi); |
| 253 | } |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static int virtnet_poll(struct napi_struct *napi, int budget) |
| 257 | { |
| 258 | struct virtnet_info *vi = container_of(napi, struct virtnet_info, napi); |
| 259 | struct sk_buff *skb = NULL; |
| 260 | unsigned int len, received = 0; |
| 261 | |
| 262 | again: |
| 263 | while (received < budget && |
| 264 | (skb = vi->rvq->vq_ops->get_buf(vi->rvq, &len)) != NULL) { |
| 265 | __skb_unlink(skb, &vi->recv); |
| 266 | receive_skb(vi->dev, skb, len); |
| 267 | vi->num--; |
| 268 | received++; |
| 269 | } |
| 270 | |
| 271 | /* FIXME: If we oom and completely run out of inbufs, we need |
| 272 | * to start a timer trying to fill more. */ |
| 273 | if (vi->num < vi->max / 2) |
| 274 | try_fill_recv(vi); |
| 275 | |
Rusty Russell | 8329d98 | 2007-11-19 11:20:43 -0500 | [diff] [blame] | 276 | /* Out of packets? */ |
| 277 | if (received < budget) { |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 278 | netif_rx_complete(vi->dev, napi); |
Rusty Russell | 18445c4 | 2008-02-04 23:49:57 -0500 | [diff] [blame] | 279 | if (unlikely(!vi->rvq->vq_ops->enable_cb(vi->rvq)) |
Christian Borntraeger | 4265f16 | 2008-03-14 14:17:05 +0100 | [diff] [blame] | 280 | && napi_schedule_prep(napi)) { |
| 281 | vi->rvq->vq_ops->disable_cb(vi->rvq); |
| 282 | __netif_rx_schedule(vi->dev, napi); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 283 | goto again; |
Christian Borntraeger | 4265f16 | 2008-03-14 14:17:05 +0100 | [diff] [blame] | 284 | } |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | return received; |
| 288 | } |
| 289 | |
| 290 | static void free_old_xmit_skbs(struct virtnet_info *vi) |
| 291 | { |
| 292 | struct sk_buff *skb; |
| 293 | unsigned int len; |
| 294 | |
| 295 | while ((skb = vi->svq->vq_ops->get_buf(vi->svq, &len)) != NULL) { |
| 296 | pr_debug("Sent skb %p\n", skb); |
| 297 | __skb_unlink(skb, &vi->send); |
Rusty Russell | 655aa31 | 2008-05-02 21:50:43 -0500 | [diff] [blame] | 298 | vi->dev->stats.tx_bytes += skb->len; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 299 | vi->dev->stats.tx_packets++; |
| 300 | kfree_skb(skb); |
| 301 | } |
| 302 | } |
| 303 | |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 304 | /* If the virtio transport doesn't always notify us when all in-flight packets |
| 305 | * are consumed, we fall back to using this function on a timer to free them. */ |
Mark McLoughlin | 14c998f | 2008-06-08 20:50:56 +1000 | [diff] [blame] | 306 | static void xmit_free(unsigned long data) |
| 307 | { |
| 308 | struct virtnet_info *vi = (void *)data; |
| 309 | |
| 310 | netif_tx_lock(vi->dev); |
| 311 | |
| 312 | free_old_xmit_skbs(vi); |
| 313 | |
| 314 | if (!skb_queue_empty(&vi->send)) |
| 315 | mod_timer(&vi->xmit_free_timer, jiffies + (HZ/10)); |
| 316 | |
| 317 | netif_tx_unlock(vi->dev); |
| 318 | } |
| 319 | |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 320 | static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb) |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 321 | { |
Mark McLoughlin | 14c998f | 2008-06-08 20:50:56 +1000 | [diff] [blame] | 322 | int num, err; |
Rusty Russell | 0527168 | 2008-05-02 21:50:45 -0500 | [diff] [blame] | 323 | struct scatterlist sg[2+MAX_SKB_FRAGS]; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 324 | struct virtio_net_hdr *hdr; |
| 325 | const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 326 | |
Rusty Russell | 0527168 | 2008-05-02 21:50:45 -0500 | [diff] [blame] | 327 | sg_init_table(sg, 2+MAX_SKB_FRAGS); |
Rusty Russell | 4d125de | 2007-11-07 16:34:49 +1100 | [diff] [blame] | 328 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 329 | pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 330 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 331 | /* Encode metadata header at front. */ |
| 332 | hdr = skb_vnet_hdr(skb); |
| 333 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 334 | hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; |
| 335 | hdr->csum_start = skb->csum_start - skb_headroom(skb); |
| 336 | hdr->csum_offset = skb->csum_offset; |
| 337 | } else { |
| 338 | hdr->flags = 0; |
| 339 | hdr->csum_offset = hdr->csum_start = 0; |
| 340 | } |
| 341 | |
| 342 | if (skb_is_gso(skb)) { |
Rusty Russell | 50c8ea8 | 2008-02-04 23:50:01 -0500 | [diff] [blame] | 343 | hdr->hdr_len = skb_transport_header(skb) - skb->data; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 344 | hdr->gso_size = skb_shinfo(skb)->gso_size; |
Rusty Russell | 34a4857 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 345 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 346 | hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4; |
| 347 | else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) |
| 348 | hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6; |
| 349 | else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP) |
| 350 | hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP; |
| 351 | else |
| 352 | BUG(); |
Rusty Russell | 34a4857 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 353 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN) |
| 354 | hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 355 | } else { |
| 356 | hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE; |
Rusty Russell | 50c8ea8 | 2008-02-04 23:50:01 -0500 | [diff] [blame] | 357 | hdr->gso_size = hdr->hdr_len = 0; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | vnet_hdr_to_sg(sg, skb); |
| 361 | num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1; |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 362 | |
Mark McLoughlin | 14c998f | 2008-06-08 20:50:56 +1000 | [diff] [blame] | 363 | err = vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb); |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 364 | if (!err && !vi->free_in_tasklet) |
Mark McLoughlin | 14c998f | 2008-06-08 20:50:56 +1000 | [diff] [blame] | 365 | mod_timer(&vi->xmit_free_timer, jiffies + (HZ/10)); |
| 366 | |
| 367 | return err; |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 368 | } |
| 369 | |
Rusty Russell | 11a3a15 | 2008-05-26 17:48:13 +1000 | [diff] [blame] | 370 | static void xmit_tasklet(unsigned long data) |
| 371 | { |
| 372 | struct virtnet_info *vi = (void *)data; |
| 373 | |
| 374 | netif_tx_lock_bh(vi->dev); |
| 375 | if (vi->last_xmit_skb && xmit_skb(vi, vi->last_xmit_skb) == 0) { |
| 376 | vi->svq->vq_ops->kick(vi->svq); |
| 377 | vi->last_xmit_skb = NULL; |
| 378 | } |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 379 | if (vi->free_in_tasklet) |
| 380 | free_old_xmit_skbs(vi); |
Rusty Russell | 11a3a15 | 2008-05-26 17:48:13 +1000 | [diff] [blame] | 381 | netif_tx_unlock_bh(vi->dev); |
| 382 | } |
| 383 | |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 384 | static int start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 385 | { |
| 386 | struct virtnet_info *vi = netdev_priv(dev); |
Rusty Russell | 2cb9c6b | 2008-02-04 23:50:07 -0500 | [diff] [blame] | 387 | |
| 388 | again: |
| 389 | /* Free up any pending old buffers before queueing new ones. */ |
| 390 | free_old_xmit_skbs(vi); |
Rusty Russell | 2cb9c6b | 2008-02-04 23:50:07 -0500 | [diff] [blame] | 391 | |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 392 | /* If we has a buffer left over from last time, send it now. */ |
Mark McLoughlin | 9953ca6 | 2008-05-27 12:06:26 +0100 | [diff] [blame] | 393 | if (unlikely(vi->last_xmit_skb) && |
| 394 | xmit_skb(vi, vi->last_xmit_skb) != 0) |
| 395 | goto stop_queue; |
| 396 | |
| 397 | vi->last_xmit_skb = NULL; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 398 | |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 399 | /* Put new one in send queue and do transmit */ |
Rusty Russell | 7eb2e25 | 2008-05-26 17:42:42 +1000 | [diff] [blame] | 400 | if (likely(skb)) { |
| 401 | __skb_queue_head(&vi->send, skb); |
| 402 | if (xmit_skb(vi, skb) != 0) { |
| 403 | vi->last_xmit_skb = skb; |
| 404 | skb = NULL; |
| 405 | goto stop_queue; |
| 406 | } |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 407 | } |
| 408 | done: |
| 409 | vi->svq->vq_ops->kick(vi->svq); |
| 410 | return NETDEV_TX_OK; |
| 411 | |
| 412 | stop_queue: |
| 413 | pr_debug("%s: virtio not prepared to send\n", dev->name); |
| 414 | netif_stop_queue(dev); |
| 415 | |
| 416 | /* Activate callback for using skbs: if this returns false it |
| 417 | * means some were used in the meantime. */ |
| 418 | if (unlikely(!vi->svq->vq_ops->enable_cb(vi->svq))) { |
| 419 | vi->svq->vq_ops->disable_cb(vi->svq); |
| 420 | netif_start_queue(dev); |
| 421 | goto again; |
| 422 | } |
Mark McLoughlin | 9953ca6 | 2008-05-27 12:06:26 +0100 | [diff] [blame] | 423 | if (skb) { |
| 424 | /* Drop this skb: we only queue one. */ |
| 425 | vi->dev->stats.tx_dropped++; |
| 426 | kfree_skb(skb); |
| 427 | } |
Rusty Russell | 99ffc69 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 428 | goto done; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 429 | } |
| 430 | |
Amit Shah | da74e89 | 2008-02-29 16:24:50 +0530 | [diff] [blame] | 431 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 432 | static void virtnet_netpoll(struct net_device *dev) |
| 433 | { |
| 434 | struct virtnet_info *vi = netdev_priv(dev); |
| 435 | |
| 436 | napi_schedule(&vi->napi); |
| 437 | } |
| 438 | #endif |
| 439 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 440 | static int virtnet_open(struct net_device *dev) |
| 441 | { |
| 442 | struct virtnet_info *vi = netdev_priv(dev); |
| 443 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 444 | napi_enable(&vi->napi); |
Rusty Russell | a48bd8f | 2008-02-04 23:50:07 -0500 | [diff] [blame] | 445 | |
| 446 | /* If all buffers were filled by other side before we napi_enabled, we |
| 447 | * won't get another interrupt, so process any outstanding packets |
Christian Borntraeger | 370076d | 2008-02-06 08:50:11 +0100 | [diff] [blame] | 448 | * now. virtnet_poll wants re-enable the queue, so we disable here. |
| 449 | * We synchronize against interrupts via NAPI_STATE_SCHED */ |
| 450 | if (netif_rx_schedule_prep(dev, &vi->napi)) { |
| 451 | vi->rvq->vq_ops->disable_cb(vi->rvq); |
| 452 | __netif_rx_schedule(dev, &vi->napi); |
| 453 | } |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static int virtnet_close(struct net_device *dev) |
| 458 | { |
| 459 | struct virtnet_info *vi = netdev_priv(dev); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 460 | |
| 461 | napi_disable(&vi->napi); |
| 462 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 463 | return 0; |
| 464 | } |
| 465 | |
Herbert Xu | a9ea3fc | 2008-04-18 11:21:42 +0800 | [diff] [blame] | 466 | static int virtnet_set_tx_csum(struct net_device *dev, u32 data) |
| 467 | { |
| 468 | struct virtnet_info *vi = netdev_priv(dev); |
| 469 | struct virtio_device *vdev = vi->vdev; |
| 470 | |
| 471 | if (data && !virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) |
| 472 | return -ENOSYS; |
| 473 | |
| 474 | return ethtool_op_set_tx_hw_csum(dev, data); |
| 475 | } |
| 476 | |
| 477 | static struct ethtool_ops virtnet_ethtool_ops = { |
| 478 | .set_tx_csum = virtnet_set_tx_csum, |
| 479 | .set_sg = ethtool_op_set_sg, |
| 480 | }; |
| 481 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 482 | static int virtnet_probe(struct virtio_device *vdev) |
| 483 | { |
| 484 | int err; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 485 | struct net_device *dev; |
| 486 | struct virtnet_info *vi; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 487 | |
| 488 | /* Allocate ourselves a network device with room for our info */ |
| 489 | dev = alloc_etherdev(sizeof(struct virtnet_info)); |
| 490 | if (!dev) |
| 491 | return -ENOMEM; |
| 492 | |
| 493 | /* Set up network device as normal. */ |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 494 | dev->open = virtnet_open; |
| 495 | dev->stop = virtnet_close; |
| 496 | dev->hard_start_xmit = start_xmit; |
| 497 | dev->features = NETIF_F_HIGHDMA; |
Amit Shah | da74e89 | 2008-02-29 16:24:50 +0530 | [diff] [blame] | 498 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 499 | dev->poll_controller = virtnet_netpoll; |
| 500 | #endif |
Herbert Xu | a9ea3fc | 2008-04-18 11:21:42 +0800 | [diff] [blame] | 501 | SET_ETHTOOL_OPS(dev, &virtnet_ethtool_ops); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 502 | SET_NETDEV_DEV(dev, &vdev->dev); |
| 503 | |
| 504 | /* Do we support "hardware" checksums? */ |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 505 | if (csum && virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) { |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 506 | /* This opens up the world of extra features. */ |
| 507 | dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST; |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 508 | if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) { |
Rusty Russell | 34a4857 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 509 | dev->features |= NETIF_F_TSO | NETIF_F_UFO |
| 510 | | NETIF_F_TSO_ECN | NETIF_F_TSO6; |
| 511 | } |
Rusty Russell | 5539ae9 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 512 | /* Individual feature bits: what can host handle? */ |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 513 | if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO4)) |
Rusty Russell | 5539ae9 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 514 | dev->features |= NETIF_F_TSO; |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 515 | if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO6)) |
Rusty Russell | 5539ae9 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 516 | dev->features |= NETIF_F_TSO6; |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 517 | if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_ECN)) |
Rusty Russell | 5539ae9 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 518 | dev->features |= NETIF_F_TSO_ECN; |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 519 | if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UFO)) |
Rusty Russell | 5539ae9 | 2008-05-02 21:50:46 -0500 | [diff] [blame] | 520 | dev->features |= NETIF_F_UFO; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /* Configuration may specify what MAC to use. Otherwise random. */ |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 524 | if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) { |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 525 | vdev->config->get(vdev, |
| 526 | offsetof(struct virtio_net_config, mac), |
| 527 | dev->dev_addr, dev->addr_len); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 528 | } else |
| 529 | random_ether_addr(dev->dev_addr); |
| 530 | |
| 531 | /* Set up our device-specific information */ |
| 532 | vi = netdev_priv(dev); |
Dor Laor | 6c0cd7c | 2007-12-16 15:19:43 +0200 | [diff] [blame] | 533 | netif_napi_add(dev, &vi->napi, virtnet_poll, napi_weight); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 534 | vi->dev = dev; |
| 535 | vi->vdev = vdev; |
Christian Borntraeger | d9d5dcc | 2008-02-18 10:02:51 +0100 | [diff] [blame] | 536 | vdev->priv = vi; |
Rusty Russell | fb6813f | 2008-07-25 12:06:01 -0500 | [diff] [blame] | 537 | vi->pages = NULL; |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 538 | |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 539 | /* If they give us a callback when all buffers are done, we don't need |
| 540 | * the timer. */ |
| 541 | vi->free_in_tasklet = virtio_has_feature(vdev,VIRTIO_F_NOTIFY_ON_EMPTY); |
| 542 | |
Herbert Xu | 97402b9 | 2008-04-18 11:24:27 +0800 | [diff] [blame] | 543 | /* If we can receive ANY GSO packets, we must allocate large ones. */ |
| 544 | if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) |
| 545 | || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) |
| 546 | || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN)) |
| 547 | vi->big_packets = true; |
| 548 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 549 | /* We expect two virtqueues, receive then send. */ |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 550 | vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 551 | if (IS_ERR(vi->rvq)) { |
| 552 | err = PTR_ERR(vi->rvq); |
| 553 | goto free; |
| 554 | } |
| 555 | |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 556 | vi->svq = vdev->config->find_vq(vdev, 1, skb_xmit_done); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 557 | if (IS_ERR(vi->svq)) { |
| 558 | err = PTR_ERR(vi->svq); |
| 559 | goto free_recv; |
| 560 | } |
| 561 | |
| 562 | /* Initialize our empty receive and send queues. */ |
| 563 | skb_queue_head_init(&vi->recv); |
| 564 | skb_queue_head_init(&vi->send); |
| 565 | |
Rusty Russell | 11a3a15 | 2008-05-26 17:48:13 +1000 | [diff] [blame] | 566 | tasklet_init(&vi->tasklet, xmit_tasklet, (unsigned long)vi); |
| 567 | |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 568 | if (!vi->free_in_tasklet) |
| 569 | setup_timer(&vi->xmit_free_timer, xmit_free, (unsigned long)vi); |
Mark McLoughlin | 14c998f | 2008-06-08 20:50:56 +1000 | [diff] [blame] | 570 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 571 | err = register_netdev(dev); |
| 572 | if (err) { |
| 573 | pr_debug("virtio_net: registering device failed\n"); |
| 574 | goto free_send; |
| 575 | } |
Rusty Russell | b3369c1 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 576 | |
| 577 | /* Last of all, set up some receive buffers. */ |
| 578 | try_fill_recv(vi); |
| 579 | |
| 580 | /* If we didn't even get one input buffer, we're useless. */ |
| 581 | if (vi->num == 0) { |
| 582 | err = -ENOMEM; |
| 583 | goto unregister; |
| 584 | } |
| 585 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 586 | pr_debug("virtnet: registered device %s\n", dev->name); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 587 | return 0; |
| 588 | |
Rusty Russell | b3369c1 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 589 | unregister: |
| 590 | unregister_netdev(dev); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 591 | free_send: |
| 592 | vdev->config->del_vq(vi->svq); |
| 593 | free_recv: |
| 594 | vdev->config->del_vq(vi->rvq); |
| 595 | free: |
| 596 | free_netdev(dev); |
| 597 | return err; |
| 598 | } |
| 599 | |
| 600 | static void virtnet_remove(struct virtio_device *vdev) |
| 601 | { |
Rusty Russell | 74b2553 | 2007-11-19 11:20:42 -0500 | [diff] [blame] | 602 | struct virtnet_info *vi = vdev->priv; |
Rusty Russell | b3369c1 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 603 | struct sk_buff *skb; |
| 604 | |
Rusty Russell | 6e5aa7e | 2008-02-04 23:50:03 -0500 | [diff] [blame] | 605 | /* Stop all the virtqueues. */ |
| 606 | vdev->config->reset(vdev); |
| 607 | |
Rusty Russell | 363f151 | 2008-06-08 20:51:55 +1000 | [diff] [blame] | 608 | if (!vi->free_in_tasklet) |
| 609 | del_timer_sync(&vi->xmit_free_timer); |
Mark McLoughlin | 14c998f | 2008-06-08 20:50:56 +1000 | [diff] [blame] | 610 | |
Rusty Russell | b3369c1 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 611 | /* Free our skbs in send and recv queues, if any. */ |
Rusty Russell | b3369c1 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 612 | while ((skb = __skb_dequeue(&vi->recv)) != NULL) { |
| 613 | kfree_skb(skb); |
| 614 | vi->num--; |
| 615 | } |
Wang Chen | 288369c | 2008-05-22 18:07:43 +0800 | [diff] [blame] | 616 | __skb_queue_purge(&vi->send); |
Rusty Russell | b3369c1 | 2008-02-04 23:50:02 -0500 | [diff] [blame] | 617 | |
| 618 | BUG_ON(vi->num != 0); |
Rusty Russell | 74b2553 | 2007-11-19 11:20:42 -0500 | [diff] [blame] | 619 | |
| 620 | vdev->config->del_vq(vi->svq); |
| 621 | vdev->config->del_vq(vi->rvq); |
| 622 | unregister_netdev(vi->dev); |
Rusty Russell | fb6813f | 2008-07-25 12:06:01 -0500 | [diff] [blame] | 623 | |
| 624 | while (vi->pages) |
| 625 | __free_pages(get_a_page(vi, GFP_KERNEL), 0); |
| 626 | |
Rusty Russell | 74b2553 | 2007-11-19 11:20:42 -0500 | [diff] [blame] | 627 | free_netdev(vi->dev); |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static struct virtio_device_id id_table[] = { |
| 631 | { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, |
| 632 | { 0 }, |
| 633 | }; |
| 634 | |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 635 | static unsigned int features[] = { |
Mark McLoughlin | 5e4fe5c | 2008-07-08 17:10:42 +1000 | [diff] [blame] | 636 | VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM, |
| 637 | VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 638 | VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, |
Herbert Xu | 97402b9 | 2008-04-18 11:24:27 +0800 | [diff] [blame] | 639 | VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, |
| 640 | VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */ |
| 641 | VIRTIO_F_NOTIFY_ON_EMPTY, |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 642 | }; |
| 643 | |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 644 | static struct virtio_driver virtio_net = { |
Rusty Russell | c45a681 | 2008-05-02 21:50:50 -0500 | [diff] [blame] | 645 | .feature_table = features, |
| 646 | .feature_table_size = ARRAY_SIZE(features), |
Rusty Russell | 296f96f | 2007-10-22 11:03:37 +1000 | [diff] [blame] | 647 | .driver.name = KBUILD_MODNAME, |
| 648 | .driver.owner = THIS_MODULE, |
| 649 | .id_table = id_table, |
| 650 | .probe = virtnet_probe, |
| 651 | .remove = __devexit_p(virtnet_remove), |
| 652 | }; |
| 653 | |
| 654 | static int __init init(void) |
| 655 | { |
| 656 | return register_virtio_driver(&virtio_net); |
| 657 | } |
| 658 | |
| 659 | static void __exit fini(void) |
| 660 | { |
| 661 | unregister_virtio_driver(&virtio_net); |
| 662 | } |
| 663 | module_init(init); |
| 664 | module_exit(fini); |
| 665 | |
| 666 | MODULE_DEVICE_TABLE(virtio, id_table); |
| 667 | MODULE_DESCRIPTION("Virtio network driver"); |
| 668 | MODULE_LICENSE("GPL"); |