virtio_net.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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>
  22. #include <linux/ethtool.h>
  23. #include <linux/module.h>
  24. #include <linux/virtio.h>
  25. #include <linux/virtio_net.h>
  26. #include <linux/scatterlist.h>
  27. static int napi_weight = 128;
  28. module_param(napi_weight, int, 0444);
  29. static int csum = 1, gso = 1;
  30. module_param(csum, bool, 0444);
  31. module_param(gso, bool, 0444);
  32. /* FIXME: MTU in config. */
  33. #define MAX_PACKET_LEN (ETH_HLEN+ETH_DATA_LEN)
  34. struct virtnet_info
  35. {
  36. struct virtio_device *vdev;
  37. struct virtqueue *rvq, *svq;
  38. struct net_device *dev;
  39. struct napi_struct napi;
  40. /* The skb we couldn't send because buffers were full. */
  41. struct sk_buff *last_xmit_skb;
  42. /* If we need to free in a timer, this is it. */
  43. struct timer_list xmit_free_timer;
  44. /* Number of input buffers, and max we've ever had. */
  45. unsigned int num, max;
  46. /* For cleaning up after transmission. */
  47. struct tasklet_struct tasklet;
  48. bool free_in_tasklet;
  49. /* I like... big packets and I cannot lie! */
  50. bool big_packets;
  51. /* Receive & send queues. */
  52. struct sk_buff_head recv;
  53. struct sk_buff_head send;
  54. };
  55. static inline struct virtio_net_hdr *skb_vnet_hdr(struct sk_buff *skb)
  56. {
  57. return (struct virtio_net_hdr *)skb->cb;
  58. }
  59. static inline void vnet_hdr_to_sg(struct scatterlist *sg, struct sk_buff *skb)
  60. {
  61. sg_init_one(sg, skb_vnet_hdr(skb), sizeof(struct virtio_net_hdr));
  62. }
  63. static void skb_xmit_done(struct virtqueue *svq)
  64. {
  65. struct virtnet_info *vi = svq->vdev->priv;
  66. /* Suppress further interrupts. */
  67. svq->vq_ops->disable_cb(svq);
  68. /* We were probably waiting for more output buffers. */
  69. netif_wake_queue(vi->dev);
  70. /* Make sure we re-xmit last_xmit_skb: if there are no more packets
  71. * queued, start_xmit won't be called. */
  72. tasklet_schedule(&vi->tasklet);
  73. }
  74. static void receive_skb(struct net_device *dev, struct sk_buff *skb,
  75. unsigned len)
  76. {
  77. struct virtio_net_hdr *hdr = skb_vnet_hdr(skb);
  78. int err;
  79. if (unlikely(len < sizeof(struct virtio_net_hdr) + ETH_HLEN)) {
  80. pr_debug("%s: short packet %i\n", dev->name, len);
  81. dev->stats.rx_length_errors++;
  82. goto drop;
  83. }
  84. len -= sizeof(struct virtio_net_hdr);
  85. err = pskb_trim(skb, len);
  86. if (err) {
  87. pr_debug("%s: pskb_trim failed %i %d\n", dev->name, len, err);
  88. dev->stats.rx_dropped++;
  89. goto drop;
  90. }
  91. skb->truesize += skb->data_len;
  92. dev->stats.rx_bytes += skb->len;
  93. dev->stats.rx_packets++;
  94. if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
  95. pr_debug("Needs csum!\n");
  96. if (!skb_partial_csum_set(skb,hdr->csum_start,hdr->csum_offset))
  97. goto frame_err;
  98. }
  99. skb->protocol = eth_type_trans(skb, dev);
  100. pr_debug("Receiving skb proto 0x%04x len %i type %i\n",
  101. ntohs(skb->protocol), skb->len, skb->pkt_type);
  102. if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
  103. pr_debug("GSO!\n");
  104. switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
  105. case VIRTIO_NET_HDR_GSO_TCPV4:
  106. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  107. break;
  108. case VIRTIO_NET_HDR_GSO_UDP:
  109. skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
  110. break;
  111. case VIRTIO_NET_HDR_GSO_TCPV6:
  112. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
  113. break;
  114. default:
  115. if (net_ratelimit())
  116. printk(KERN_WARNING "%s: bad gso type %u.\n",
  117. dev->name, hdr->gso_type);
  118. goto frame_err;
  119. }
  120. if (hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN)
  121. skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
  122. skb_shinfo(skb)->gso_size = hdr->gso_size;
  123. if (skb_shinfo(skb)->gso_size == 0) {
  124. if (net_ratelimit())
  125. printk(KERN_WARNING "%s: zero gso size.\n",
  126. dev->name);
  127. goto frame_err;
  128. }
  129. /* Header must be checked, and gso_segs computed. */
  130. skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
  131. skb_shinfo(skb)->gso_segs = 0;
  132. }
  133. netif_receive_skb(skb);
  134. return;
  135. frame_err:
  136. dev->stats.rx_frame_errors++;
  137. drop:
  138. dev_kfree_skb(skb);
  139. }
  140. static void try_fill_recv(struct virtnet_info *vi)
  141. {
  142. struct sk_buff *skb;
  143. struct scatterlist sg[2+MAX_SKB_FRAGS];
  144. int num, err, i;
  145. sg_init_table(sg, 2+MAX_SKB_FRAGS);
  146. for (;;) {
  147. skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN);
  148. if (unlikely(!skb))
  149. break;
  150. skb_put(skb, MAX_PACKET_LEN);
  151. vnet_hdr_to_sg(sg, skb);
  152. if (vi->big_packets) {
  153. for (i = 0; i < MAX_SKB_FRAGS; i++) {
  154. skb_frag_t *f = &skb_shinfo(skb)->frags[i];
  155. f->page = alloc_page(GFP_ATOMIC);
  156. if (!f->page)
  157. break;
  158. f->page_offset = 0;
  159. f->size = PAGE_SIZE;
  160. skb->data_len += PAGE_SIZE;
  161. skb->len += PAGE_SIZE;
  162. skb_shinfo(skb)->nr_frags++;
  163. }
  164. }
  165. num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
  166. skb_queue_head(&vi->recv, skb);
  167. err = vi->rvq->vq_ops->add_buf(vi->rvq, sg, 0, num, skb);
  168. if (err) {
  169. skb_unlink(skb, &vi->recv);
  170. kfree_skb(skb);
  171. break;
  172. }
  173. vi->num++;
  174. }
  175. if (unlikely(vi->num > vi->max))
  176. vi->max = vi->num;
  177. vi->rvq->vq_ops->kick(vi->rvq);
  178. }
  179. static void skb_recv_done(struct virtqueue *rvq)
  180. {
  181. struct virtnet_info *vi = rvq->vdev->priv;
  182. /* Schedule NAPI, Suppress further interrupts if successful. */
  183. if (netif_rx_schedule_prep(vi->dev, &vi->napi)) {
  184. rvq->vq_ops->disable_cb(rvq);
  185. __netif_rx_schedule(vi->dev, &vi->napi);
  186. }
  187. }
  188. static int virtnet_poll(struct napi_struct *napi, int budget)
  189. {
  190. struct virtnet_info *vi = container_of(napi, struct virtnet_info, napi);
  191. struct sk_buff *skb = NULL;
  192. unsigned int len, received = 0;
  193. again:
  194. while (received < budget &&
  195. (skb = vi->rvq->vq_ops->get_buf(vi->rvq, &len)) != NULL) {
  196. __skb_unlink(skb, &vi->recv);
  197. receive_skb(vi->dev, skb, len);
  198. vi->num--;
  199. received++;
  200. }
  201. /* FIXME: If we oom and completely run out of inbufs, we need
  202. * to start a timer trying to fill more. */
  203. if (vi->num < vi->max / 2)
  204. try_fill_recv(vi);
  205. /* Out of packets? */
  206. if (received < budget) {
  207. netif_rx_complete(vi->dev, napi);
  208. if (unlikely(!vi->rvq->vq_ops->enable_cb(vi->rvq))
  209. && napi_schedule_prep(napi)) {
  210. vi->rvq->vq_ops->disable_cb(vi->rvq);
  211. __netif_rx_schedule(vi->dev, napi);
  212. goto again;
  213. }
  214. }
  215. return received;
  216. }
  217. static void free_old_xmit_skbs(struct virtnet_info *vi)
  218. {
  219. struct sk_buff *skb;
  220. unsigned int len;
  221. while ((skb = vi->svq->vq_ops->get_buf(vi->svq, &len)) != NULL) {
  222. pr_debug("Sent skb %p\n", skb);
  223. __skb_unlink(skb, &vi->send);
  224. vi->dev->stats.tx_bytes += skb->len;
  225. vi->dev->stats.tx_packets++;
  226. kfree_skb(skb);
  227. }
  228. }
  229. /* If the virtio transport doesn't always notify us when all in-flight packets
  230. * are consumed, we fall back to using this function on a timer to free them. */
  231. static void xmit_free(unsigned long data)
  232. {
  233. struct virtnet_info *vi = (void *)data;
  234. netif_tx_lock(vi->dev);
  235. free_old_xmit_skbs(vi);
  236. if (!skb_queue_empty(&vi->send))
  237. mod_timer(&vi->xmit_free_timer, jiffies + (HZ/10));
  238. netif_tx_unlock(vi->dev);
  239. }
  240. static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb)
  241. {
  242. int num, err;
  243. struct scatterlist sg[2+MAX_SKB_FRAGS];
  244. struct virtio_net_hdr *hdr;
  245. const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
  246. sg_init_table(sg, 2+MAX_SKB_FRAGS);
  247. pr_debug("%s: xmit %p " MAC_FMT "\n", vi->dev->name, skb,
  248. dest[0], dest[1], dest[2],
  249. dest[3], dest[4], dest[5]);
  250. /* Encode metadata header at front. */
  251. hdr = skb_vnet_hdr(skb);
  252. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  253. hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
  254. hdr->csum_start = skb->csum_start - skb_headroom(skb);
  255. hdr->csum_offset = skb->csum_offset;
  256. } else {
  257. hdr->flags = 0;
  258. hdr->csum_offset = hdr->csum_start = 0;
  259. }
  260. if (skb_is_gso(skb)) {
  261. hdr->hdr_len = skb_transport_header(skb) - skb->data;
  262. hdr->gso_size = skb_shinfo(skb)->gso_size;
  263. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
  264. hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
  265. else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  266. hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
  267. else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
  268. hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
  269. else
  270. BUG();
  271. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN)
  272. hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN;
  273. } else {
  274. hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
  275. hdr->gso_size = hdr->hdr_len = 0;
  276. }
  277. vnet_hdr_to_sg(sg, skb);
  278. num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
  279. err = vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb);
  280. if (!err && !vi->free_in_tasklet)
  281. mod_timer(&vi->xmit_free_timer, jiffies + (HZ/10));
  282. return err;
  283. }
  284. static void xmit_tasklet(unsigned long data)
  285. {
  286. struct virtnet_info *vi = (void *)data;
  287. netif_tx_lock_bh(vi->dev);
  288. if (vi->last_xmit_skb && xmit_skb(vi, vi->last_xmit_skb) == 0) {
  289. vi->svq->vq_ops->kick(vi->svq);
  290. vi->last_xmit_skb = NULL;
  291. }
  292. if (vi->free_in_tasklet)
  293. free_old_xmit_skbs(vi);
  294. netif_tx_unlock_bh(vi->dev);
  295. }
  296. static int start_xmit(struct sk_buff *skb, struct net_device *dev)
  297. {
  298. struct virtnet_info *vi = netdev_priv(dev);
  299. again:
  300. /* Free up any pending old buffers before queueing new ones. */
  301. free_old_xmit_skbs(vi);
  302. /* If we has a buffer left over from last time, send it now. */
  303. if (unlikely(vi->last_xmit_skb) &&
  304. xmit_skb(vi, vi->last_xmit_skb) != 0)
  305. goto stop_queue;
  306. vi->last_xmit_skb = NULL;
  307. /* Put new one in send queue and do transmit */
  308. if (likely(skb)) {
  309. __skb_queue_head(&vi->send, skb);
  310. if (xmit_skb(vi, skb) != 0) {
  311. vi->last_xmit_skb = skb;
  312. skb = NULL;
  313. goto stop_queue;
  314. }
  315. }
  316. done:
  317. vi->svq->vq_ops->kick(vi->svq);
  318. return NETDEV_TX_OK;
  319. stop_queue:
  320. pr_debug("%s: virtio not prepared to send\n", dev->name);
  321. netif_stop_queue(dev);
  322. /* Activate callback for using skbs: if this returns false it
  323. * means some were used in the meantime. */
  324. if (unlikely(!vi->svq->vq_ops->enable_cb(vi->svq))) {
  325. vi->svq->vq_ops->disable_cb(vi->svq);
  326. netif_start_queue(dev);
  327. goto again;
  328. }
  329. if (skb) {
  330. /* Drop this skb: we only queue one. */
  331. vi->dev->stats.tx_dropped++;
  332. kfree_skb(skb);
  333. }
  334. goto done;
  335. }
  336. #ifdef CONFIG_NET_POLL_CONTROLLER
  337. static void virtnet_netpoll(struct net_device *dev)
  338. {
  339. struct virtnet_info *vi = netdev_priv(dev);
  340. napi_schedule(&vi->napi);
  341. }
  342. #endif
  343. static int virtnet_open(struct net_device *dev)
  344. {
  345. struct virtnet_info *vi = netdev_priv(dev);
  346. napi_enable(&vi->napi);
  347. /* If all buffers were filled by other side before we napi_enabled, we
  348. * won't get another interrupt, so process any outstanding packets
  349. * now. virtnet_poll wants re-enable the queue, so we disable here.
  350. * We synchronize against interrupts via NAPI_STATE_SCHED */
  351. if (netif_rx_schedule_prep(dev, &vi->napi)) {
  352. vi->rvq->vq_ops->disable_cb(vi->rvq);
  353. __netif_rx_schedule(dev, &vi->napi);
  354. }
  355. return 0;
  356. }
  357. static int virtnet_close(struct net_device *dev)
  358. {
  359. struct virtnet_info *vi = netdev_priv(dev);
  360. napi_disable(&vi->napi);
  361. return 0;
  362. }
  363. static int virtnet_set_tx_csum(struct net_device *dev, u32 data)
  364. {
  365. struct virtnet_info *vi = netdev_priv(dev);
  366. struct virtio_device *vdev = vi->vdev;
  367. if (data && !virtio_has_feature(vdev, VIRTIO_NET_F_CSUM))
  368. return -ENOSYS;
  369. return ethtool_op_set_tx_hw_csum(dev, data);
  370. }
  371. static struct ethtool_ops virtnet_ethtool_ops = {
  372. .set_tx_csum = virtnet_set_tx_csum,
  373. .set_sg = ethtool_op_set_sg,
  374. };
  375. static int virtnet_probe(struct virtio_device *vdev)
  376. {
  377. int err;
  378. struct net_device *dev;
  379. struct virtnet_info *vi;
  380. /* Allocate ourselves a network device with room for our info */
  381. dev = alloc_etherdev(sizeof(struct virtnet_info));
  382. if (!dev)
  383. return -ENOMEM;
  384. /* Set up network device as normal. */
  385. dev->open = virtnet_open;
  386. dev->stop = virtnet_close;
  387. dev->hard_start_xmit = start_xmit;
  388. dev->features = NETIF_F_HIGHDMA;
  389. #ifdef CONFIG_NET_POLL_CONTROLLER
  390. dev->poll_controller = virtnet_netpoll;
  391. #endif
  392. SET_ETHTOOL_OPS(dev, &virtnet_ethtool_ops);
  393. SET_NETDEV_DEV(dev, &vdev->dev);
  394. /* Do we support "hardware" checksums? */
  395. if (csum && virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) {
  396. /* This opens up the world of extra features. */
  397. dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
  398. if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) {
  399. dev->features |= NETIF_F_TSO | NETIF_F_UFO
  400. | NETIF_F_TSO_ECN | NETIF_F_TSO6;
  401. }
  402. /* Individual feature bits: what can host handle? */
  403. if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO4))
  404. dev->features |= NETIF_F_TSO;
  405. if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO6))
  406. dev->features |= NETIF_F_TSO6;
  407. if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_ECN))
  408. dev->features |= NETIF_F_TSO_ECN;
  409. if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UFO))
  410. dev->features |= NETIF_F_UFO;
  411. }
  412. /* Configuration may specify what MAC to use. Otherwise random. */
  413. if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) {
  414. vdev->config->get(vdev,
  415. offsetof(struct virtio_net_config, mac),
  416. dev->dev_addr, dev->addr_len);
  417. } else
  418. random_ether_addr(dev->dev_addr);
  419. /* Set up our device-specific information */
  420. vi = netdev_priv(dev);
  421. netif_napi_add(dev, &vi->napi, virtnet_poll, napi_weight);
  422. vi->dev = dev;
  423. vi->vdev = vdev;
  424. vdev->priv = vi;
  425. /* If they give us a callback when all buffers are done, we don't need
  426. * the timer. */
  427. vi->free_in_tasklet = virtio_has_feature(vdev,VIRTIO_F_NOTIFY_ON_EMPTY);
  428. /* If we can receive ANY GSO packets, we must allocate large ones. */
  429. if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4)
  430. || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6)
  431. || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN))
  432. vi->big_packets = true;
  433. /* We expect two virtqueues, receive then send. */
  434. vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done);
  435. if (IS_ERR(vi->rvq)) {
  436. err = PTR_ERR(vi->rvq);
  437. goto free;
  438. }
  439. vi->svq = vdev->config->find_vq(vdev, 1, skb_xmit_done);
  440. if (IS_ERR(vi->svq)) {
  441. err = PTR_ERR(vi->svq);
  442. goto free_recv;
  443. }
  444. /* Initialize our empty receive and send queues. */
  445. skb_queue_head_init(&vi->recv);
  446. skb_queue_head_init(&vi->send);
  447. tasklet_init(&vi->tasklet, xmit_tasklet, (unsigned long)vi);
  448. if (!vi->free_in_tasklet)
  449. setup_timer(&vi->xmit_free_timer, xmit_free, (unsigned long)vi);
  450. err = register_netdev(dev);
  451. if (err) {
  452. pr_debug("virtio_net: registering device failed\n");
  453. goto free_send;
  454. }
  455. /* Last of all, set up some receive buffers. */
  456. try_fill_recv(vi);
  457. /* If we didn't even get one input buffer, we're useless. */
  458. if (vi->num == 0) {
  459. err = -ENOMEM;
  460. goto unregister;
  461. }
  462. pr_debug("virtnet: registered device %s\n", dev->name);
  463. return 0;
  464. unregister:
  465. unregister_netdev(dev);
  466. free_send:
  467. vdev->config->del_vq(vi->svq);
  468. free_recv:
  469. vdev->config->del_vq(vi->rvq);
  470. free:
  471. free_netdev(dev);
  472. return err;
  473. }
  474. static void virtnet_remove(struct virtio_device *vdev)
  475. {
  476. struct virtnet_info *vi = vdev->priv;
  477. struct sk_buff *skb;
  478. /* Stop all the virtqueues. */
  479. vdev->config->reset(vdev);
  480. if (!vi->free_in_tasklet)
  481. del_timer_sync(&vi->xmit_free_timer);
  482. /* Free our skbs in send and recv queues, if any. */
  483. while ((skb = __skb_dequeue(&vi->recv)) != NULL) {
  484. kfree_skb(skb);
  485. vi->num--;
  486. }
  487. __skb_queue_purge(&vi->send);
  488. BUG_ON(vi->num != 0);
  489. vdev->config->del_vq(vi->svq);
  490. vdev->config->del_vq(vi->rvq);
  491. unregister_netdev(vi->dev);
  492. free_netdev(vi->dev);
  493. }
  494. static struct virtio_device_id id_table[] = {
  495. { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
  496. { 0 },
  497. };
  498. static unsigned int features[] = {
  499. VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM,
  500. VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC,
  501. VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6,
  502. VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
  503. VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
  504. VIRTIO_F_NOTIFY_ON_EMPTY,
  505. };
  506. static struct virtio_driver virtio_net = {
  507. .feature_table = features,
  508. .feature_table_size = ARRAY_SIZE(features),
  509. .driver.name = KBUILD_MODNAME,
  510. .driver.owner = THIS_MODULE,
  511. .id_table = id_table,
  512. .probe = virtnet_probe,
  513. .remove = __devexit_p(virtnet_remove),
  514. };
  515. static int __init init(void)
  516. {
  517. return register_virtio_driver(&virtio_net);
  518. }
  519. static void __exit fini(void)
  520. {
  521. unregister_virtio_driver(&virtio_net);
  522. }
  523. module_init(init);
  524. module_exit(fini);
  525. MODULE_DEVICE_TABLE(virtio, id_table);
  526. MODULE_DESCRIPTION("Virtio network driver");
  527. MODULE_LICENSE("GPL");