virtio_net.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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.
  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. #include <linux/if_vlan.h>
  28. #include <linux/slab.h>
  29. static int napi_weight = 128;
  30. module_param(napi_weight, int, 0444);
  31. static bool csum = true, gso = true;
  32. module_param(csum, bool, 0444);
  33. module_param(gso, bool, 0444);
  34. /* FIXME: MTU in config. */
  35. #define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
  36. #define GOOD_COPY_LEN 128
  37. #define VIRTNET_SEND_COMMAND_SG_MAX 2
  38. #define VIRTNET_DRIVER_VERSION "1.0.0"
  39. struct virtnet_stats {
  40. struct u64_stats_sync syncp;
  41. u64 tx_bytes;
  42. u64 tx_packets;
  43. u64 rx_bytes;
  44. u64 rx_packets;
  45. };
  46. struct virtnet_info {
  47. struct virtio_device *vdev;
  48. struct virtqueue *rvq, *svq, *cvq;
  49. struct net_device *dev;
  50. struct napi_struct napi;
  51. unsigned int status;
  52. /* Number of input buffers, and max we've ever had. */
  53. unsigned int num, max;
  54. /* I like... big packets and I cannot lie! */
  55. bool big_packets;
  56. /* Host will merge rx buffers for big packets (shake it! shake it!) */
  57. bool mergeable_rx_bufs;
  58. /* Active statistics */
  59. struct virtnet_stats __percpu *stats;
  60. /* Work struct for refilling if we run low on memory. */
  61. struct delayed_work refill;
  62. /* Chain pages by the private ptr. */
  63. struct page *pages;
  64. /* fragments + linear part + virtio header */
  65. struct scatterlist rx_sg[MAX_SKB_FRAGS + 2];
  66. struct scatterlist tx_sg[MAX_SKB_FRAGS + 2];
  67. };
  68. struct skb_vnet_hdr {
  69. union {
  70. struct virtio_net_hdr hdr;
  71. struct virtio_net_hdr_mrg_rxbuf mhdr;
  72. };
  73. unsigned int num_sg;
  74. };
  75. struct padded_vnet_hdr {
  76. struct virtio_net_hdr hdr;
  77. /*
  78. * virtio_net_hdr should be in a separated sg buffer because of a
  79. * QEMU bug, and data sg buffer shares same page with this header sg.
  80. * This padding makes next sg 16 byte aligned after virtio_net_hdr.
  81. */
  82. char padding[6];
  83. };
  84. static inline struct skb_vnet_hdr *skb_vnet_hdr(struct sk_buff *skb)
  85. {
  86. return (struct skb_vnet_hdr *)skb->cb;
  87. }
  88. /*
  89. * private is used to chain pages for big packets, put the whole
  90. * most recent used list in the beginning for reuse
  91. */
  92. static void give_pages(struct virtnet_info *vi, struct page *page)
  93. {
  94. struct page *end;
  95. /* Find end of list, sew whole thing into vi->pages. */
  96. for (end = page; end->private; end = (struct page *)end->private);
  97. end->private = (unsigned long)vi->pages;
  98. vi->pages = page;
  99. }
  100. static struct page *get_a_page(struct virtnet_info *vi, gfp_t gfp_mask)
  101. {
  102. struct page *p = vi->pages;
  103. if (p) {
  104. vi->pages = (struct page *)p->private;
  105. /* clear private here, it is used to chain pages */
  106. p->private = 0;
  107. } else
  108. p = alloc_page(gfp_mask);
  109. return p;
  110. }
  111. static void skb_xmit_done(struct virtqueue *svq)
  112. {
  113. struct virtnet_info *vi = svq->vdev->priv;
  114. /* Suppress further interrupts. */
  115. virtqueue_disable_cb(svq);
  116. /* We were probably waiting for more output buffers. */
  117. netif_wake_queue(vi->dev);
  118. }
  119. static void set_skb_frag(struct sk_buff *skb, struct page *page,
  120. unsigned int offset, unsigned int *len)
  121. {
  122. int size = min((unsigned)PAGE_SIZE - offset, *len);
  123. int i = skb_shinfo(skb)->nr_frags;
  124. __skb_fill_page_desc(skb, i, page, offset, size);
  125. skb->data_len += size;
  126. skb->len += size;
  127. skb->truesize += PAGE_SIZE;
  128. skb_shinfo(skb)->nr_frags++;
  129. *len -= size;
  130. }
  131. /* Called from bottom half context */
  132. static struct sk_buff *page_to_skb(struct virtnet_info *vi,
  133. struct page *page, unsigned int len)
  134. {
  135. struct sk_buff *skb;
  136. struct skb_vnet_hdr *hdr;
  137. unsigned int copy, hdr_len, offset;
  138. char *p;
  139. p = page_address(page);
  140. /* copy small packet so we can reuse these pages for small data */
  141. skb = netdev_alloc_skb_ip_align(vi->dev, GOOD_COPY_LEN);
  142. if (unlikely(!skb))
  143. return NULL;
  144. hdr = skb_vnet_hdr(skb);
  145. if (vi->mergeable_rx_bufs) {
  146. hdr_len = sizeof hdr->mhdr;
  147. offset = hdr_len;
  148. } else {
  149. hdr_len = sizeof hdr->hdr;
  150. offset = sizeof(struct padded_vnet_hdr);
  151. }
  152. memcpy(hdr, p, hdr_len);
  153. len -= hdr_len;
  154. p += offset;
  155. copy = len;
  156. if (copy > skb_tailroom(skb))
  157. copy = skb_tailroom(skb);
  158. memcpy(skb_put(skb, copy), p, copy);
  159. len -= copy;
  160. offset += copy;
  161. /*
  162. * Verify that we can indeed put this data into a skb.
  163. * This is here to handle cases when the device erroneously
  164. * tries to receive more than is possible. This is usually
  165. * the case of a broken device.
  166. */
  167. if (unlikely(len > MAX_SKB_FRAGS * PAGE_SIZE)) {
  168. if (net_ratelimit())
  169. pr_debug("%s: too much data\n", skb->dev->name);
  170. dev_kfree_skb(skb);
  171. return NULL;
  172. }
  173. while (len) {
  174. set_skb_frag(skb, page, offset, &len);
  175. page = (struct page *)page->private;
  176. offset = 0;
  177. }
  178. if (page)
  179. give_pages(vi, page);
  180. return skb;
  181. }
  182. static int receive_mergeable(struct virtnet_info *vi, struct sk_buff *skb)
  183. {
  184. struct skb_vnet_hdr *hdr = skb_vnet_hdr(skb);
  185. struct page *page;
  186. int num_buf, i, len;
  187. num_buf = hdr->mhdr.num_buffers;
  188. while (--num_buf) {
  189. i = skb_shinfo(skb)->nr_frags;
  190. if (i >= MAX_SKB_FRAGS) {
  191. pr_debug("%s: packet too long\n", skb->dev->name);
  192. skb->dev->stats.rx_length_errors++;
  193. return -EINVAL;
  194. }
  195. page = virtqueue_get_buf(vi->rvq, &len);
  196. if (!page) {
  197. pr_debug("%s: rx error: %d buffers missing\n",
  198. skb->dev->name, hdr->mhdr.num_buffers);
  199. skb->dev->stats.rx_length_errors++;
  200. return -EINVAL;
  201. }
  202. if (len > PAGE_SIZE)
  203. len = PAGE_SIZE;
  204. set_skb_frag(skb, page, 0, &len);
  205. --vi->num;
  206. }
  207. return 0;
  208. }
  209. static void receive_buf(struct net_device *dev, void *buf, unsigned int len)
  210. {
  211. struct virtnet_info *vi = netdev_priv(dev);
  212. struct virtnet_stats __percpu *stats = this_cpu_ptr(vi->stats);
  213. struct sk_buff *skb;
  214. struct page *page;
  215. struct skb_vnet_hdr *hdr;
  216. if (unlikely(len < sizeof(struct virtio_net_hdr) + ETH_HLEN)) {
  217. pr_debug("%s: short packet %i\n", dev->name, len);
  218. dev->stats.rx_length_errors++;
  219. if (vi->mergeable_rx_bufs || vi->big_packets)
  220. give_pages(vi, buf);
  221. else
  222. dev_kfree_skb(buf);
  223. return;
  224. }
  225. if (!vi->mergeable_rx_bufs && !vi->big_packets) {
  226. skb = buf;
  227. len -= sizeof(struct virtio_net_hdr);
  228. skb_trim(skb, len);
  229. } else {
  230. page = buf;
  231. skb = page_to_skb(vi, page, len);
  232. if (unlikely(!skb)) {
  233. dev->stats.rx_dropped++;
  234. give_pages(vi, page);
  235. return;
  236. }
  237. if (vi->mergeable_rx_bufs)
  238. if (receive_mergeable(vi, skb)) {
  239. dev_kfree_skb(skb);
  240. return;
  241. }
  242. }
  243. hdr = skb_vnet_hdr(skb);
  244. u64_stats_update_begin(&stats->syncp);
  245. stats->rx_bytes += skb->len;
  246. stats->rx_packets++;
  247. u64_stats_update_end(&stats->syncp);
  248. if (hdr->hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
  249. pr_debug("Needs csum!\n");
  250. if (!skb_partial_csum_set(skb,
  251. hdr->hdr.csum_start,
  252. hdr->hdr.csum_offset))
  253. goto frame_err;
  254. } else if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) {
  255. skb->ip_summed = CHECKSUM_UNNECESSARY;
  256. }
  257. skb->protocol = eth_type_trans(skb, dev);
  258. pr_debug("Receiving skb proto 0x%04x len %i type %i\n",
  259. ntohs(skb->protocol), skb->len, skb->pkt_type);
  260. if (hdr->hdr.gso_type != VIRTIO_NET_HDR_GSO_NONE) {
  261. pr_debug("GSO!\n");
  262. switch (hdr->hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
  263. case VIRTIO_NET_HDR_GSO_TCPV4:
  264. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  265. break;
  266. case VIRTIO_NET_HDR_GSO_UDP:
  267. skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
  268. break;
  269. case VIRTIO_NET_HDR_GSO_TCPV6:
  270. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
  271. break;
  272. default:
  273. if (net_ratelimit())
  274. printk(KERN_WARNING "%s: bad gso type %u.\n",
  275. dev->name, hdr->hdr.gso_type);
  276. goto frame_err;
  277. }
  278. if (hdr->hdr.gso_type & VIRTIO_NET_HDR_GSO_ECN)
  279. skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN;
  280. skb_shinfo(skb)->gso_size = hdr->hdr.gso_size;
  281. if (skb_shinfo(skb)->gso_size == 0) {
  282. if (net_ratelimit())
  283. printk(KERN_WARNING "%s: zero gso size.\n",
  284. dev->name);
  285. goto frame_err;
  286. }
  287. /* Header must be checked, and gso_segs computed. */
  288. skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
  289. skb_shinfo(skb)->gso_segs = 0;
  290. }
  291. netif_receive_skb(skb);
  292. return;
  293. frame_err:
  294. dev->stats.rx_frame_errors++;
  295. dev_kfree_skb(skb);
  296. }
  297. static int add_recvbuf_small(struct virtnet_info *vi, gfp_t gfp)
  298. {
  299. struct sk_buff *skb;
  300. struct skb_vnet_hdr *hdr;
  301. int err;
  302. skb = __netdev_alloc_skb_ip_align(vi->dev, MAX_PACKET_LEN, gfp);
  303. if (unlikely(!skb))
  304. return -ENOMEM;
  305. skb_put(skb, MAX_PACKET_LEN);
  306. hdr = skb_vnet_hdr(skb);
  307. sg_set_buf(vi->rx_sg, &hdr->hdr, sizeof hdr->hdr);
  308. skb_to_sgvec(skb, vi->rx_sg + 1, 0, skb->len);
  309. err = virtqueue_add_buf(vi->rvq, vi->rx_sg, 0, 2, skb, gfp);
  310. if (err < 0)
  311. dev_kfree_skb(skb);
  312. return err;
  313. }
  314. static int add_recvbuf_big(struct virtnet_info *vi, gfp_t gfp)
  315. {
  316. struct page *first, *list = NULL;
  317. char *p;
  318. int i, err, offset;
  319. /* page in vi->rx_sg[MAX_SKB_FRAGS + 1] is list tail */
  320. for (i = MAX_SKB_FRAGS + 1; i > 1; --i) {
  321. first = get_a_page(vi, gfp);
  322. if (!first) {
  323. if (list)
  324. give_pages(vi, list);
  325. return -ENOMEM;
  326. }
  327. sg_set_buf(&vi->rx_sg[i], page_address(first), PAGE_SIZE);
  328. /* chain new page in list head to match sg */
  329. first->private = (unsigned long)list;
  330. list = first;
  331. }
  332. first = get_a_page(vi, gfp);
  333. if (!first) {
  334. give_pages(vi, list);
  335. return -ENOMEM;
  336. }
  337. p = page_address(first);
  338. /* vi->rx_sg[0], vi->rx_sg[1] share the same page */
  339. /* a separated vi->rx_sg[0] for virtio_net_hdr only due to QEMU bug */
  340. sg_set_buf(&vi->rx_sg[0], p, sizeof(struct virtio_net_hdr));
  341. /* vi->rx_sg[1] for data packet, from offset */
  342. offset = sizeof(struct padded_vnet_hdr);
  343. sg_set_buf(&vi->rx_sg[1], p + offset, PAGE_SIZE - offset);
  344. /* chain first in list head */
  345. first->private = (unsigned long)list;
  346. err = virtqueue_add_buf(vi->rvq, vi->rx_sg, 0, MAX_SKB_FRAGS + 2,
  347. first, gfp);
  348. if (err < 0)
  349. give_pages(vi, first);
  350. return err;
  351. }
  352. static int add_recvbuf_mergeable(struct virtnet_info *vi, gfp_t gfp)
  353. {
  354. struct page *page;
  355. int err;
  356. page = get_a_page(vi, gfp);
  357. if (!page)
  358. return -ENOMEM;
  359. sg_init_one(vi->rx_sg, page_address(page), PAGE_SIZE);
  360. err = virtqueue_add_buf(vi->rvq, vi->rx_sg, 0, 1, page, gfp);
  361. if (err < 0)
  362. give_pages(vi, page);
  363. return err;
  364. }
  365. /*
  366. * Returns false if we couldn't fill entirely (OOM).
  367. *
  368. * Normally run in the receive path, but can also be run from ndo_open
  369. * before we're receiving packets, or from refill_work which is
  370. * careful to disable receiving (using napi_disable).
  371. */
  372. static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp)
  373. {
  374. int err;
  375. bool oom;
  376. do {
  377. if (vi->mergeable_rx_bufs)
  378. err = add_recvbuf_mergeable(vi, gfp);
  379. else if (vi->big_packets)
  380. err = add_recvbuf_big(vi, gfp);
  381. else
  382. err = add_recvbuf_small(vi, gfp);
  383. oom = err == -ENOMEM;
  384. if (err < 0)
  385. break;
  386. ++vi->num;
  387. } while (err > 0);
  388. if (unlikely(vi->num > vi->max))
  389. vi->max = vi->num;
  390. virtqueue_kick(vi->rvq);
  391. return !oom;
  392. }
  393. static void skb_recv_done(struct virtqueue *rvq)
  394. {
  395. struct virtnet_info *vi = rvq->vdev->priv;
  396. /* Schedule NAPI, Suppress further interrupts if successful. */
  397. if (napi_schedule_prep(&vi->napi)) {
  398. virtqueue_disable_cb(rvq);
  399. __napi_schedule(&vi->napi);
  400. }
  401. }
  402. static void virtnet_napi_enable(struct virtnet_info *vi)
  403. {
  404. napi_enable(&vi->napi);
  405. /* If all buffers were filled by other side before we napi_enabled, we
  406. * won't get another interrupt, so process any outstanding packets
  407. * now. virtnet_poll wants re-enable the queue, so we disable here.
  408. * We synchronize against interrupts via NAPI_STATE_SCHED */
  409. if (napi_schedule_prep(&vi->napi)) {
  410. virtqueue_disable_cb(vi->rvq);
  411. __napi_schedule(&vi->napi);
  412. }
  413. }
  414. static void refill_work(struct work_struct *work)
  415. {
  416. struct virtnet_info *vi;
  417. bool still_empty;
  418. vi = container_of(work, struct virtnet_info, refill.work);
  419. napi_disable(&vi->napi);
  420. still_empty = !try_fill_recv(vi, GFP_KERNEL);
  421. virtnet_napi_enable(vi);
  422. /* In theory, this can happen: if we don't get any buffers in
  423. * we will *never* try to fill again. */
  424. if (still_empty)
  425. queue_delayed_work(system_nrt_wq, &vi->refill, HZ/2);
  426. }
  427. static int virtnet_poll(struct napi_struct *napi, int budget)
  428. {
  429. struct virtnet_info *vi = container_of(napi, struct virtnet_info, napi);
  430. void *buf;
  431. unsigned int len, received = 0;
  432. again:
  433. while (received < budget &&
  434. (buf = virtqueue_get_buf(vi->rvq, &len)) != NULL) {
  435. receive_buf(vi->dev, buf, len);
  436. --vi->num;
  437. received++;
  438. }
  439. if (vi->num < vi->max / 2) {
  440. if (!try_fill_recv(vi, GFP_ATOMIC))
  441. queue_delayed_work(system_nrt_wq, &vi->refill, 0);
  442. }
  443. /* Out of packets? */
  444. if (received < budget) {
  445. napi_complete(napi);
  446. if (unlikely(!virtqueue_enable_cb(vi->rvq)) &&
  447. napi_schedule_prep(napi)) {
  448. virtqueue_disable_cb(vi->rvq);
  449. __napi_schedule(napi);
  450. goto again;
  451. }
  452. }
  453. return received;
  454. }
  455. static unsigned int free_old_xmit_skbs(struct virtnet_info *vi)
  456. {
  457. struct sk_buff *skb;
  458. unsigned int len, tot_sgs = 0;
  459. struct virtnet_stats __percpu *stats = this_cpu_ptr(vi->stats);
  460. while ((skb = virtqueue_get_buf(vi->svq, &len)) != NULL) {
  461. pr_debug("Sent skb %p\n", skb);
  462. u64_stats_update_begin(&stats->syncp);
  463. stats->tx_bytes += skb->len;
  464. stats->tx_packets++;
  465. u64_stats_update_end(&stats->syncp);
  466. tot_sgs += skb_vnet_hdr(skb)->num_sg;
  467. dev_kfree_skb_any(skb);
  468. }
  469. return tot_sgs;
  470. }
  471. static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb)
  472. {
  473. struct skb_vnet_hdr *hdr = skb_vnet_hdr(skb);
  474. const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
  475. pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest);
  476. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  477. hdr->hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
  478. hdr->hdr.csum_start = skb_checksum_start_offset(skb);
  479. hdr->hdr.csum_offset = skb->csum_offset;
  480. } else {
  481. hdr->hdr.flags = 0;
  482. hdr->hdr.csum_offset = hdr->hdr.csum_start = 0;
  483. }
  484. if (skb_is_gso(skb)) {
  485. hdr->hdr.hdr_len = skb_headlen(skb);
  486. hdr->hdr.gso_size = skb_shinfo(skb)->gso_size;
  487. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
  488. hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
  489. else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  490. hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
  491. else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
  492. hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_UDP;
  493. else
  494. BUG();
  495. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN)
  496. hdr->hdr.gso_type |= VIRTIO_NET_HDR_GSO_ECN;
  497. } else {
  498. hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE;
  499. hdr->hdr.gso_size = hdr->hdr.hdr_len = 0;
  500. }
  501. hdr->mhdr.num_buffers = 0;
  502. /* Encode metadata header at front. */
  503. if (vi->mergeable_rx_bufs)
  504. sg_set_buf(vi->tx_sg, &hdr->mhdr, sizeof hdr->mhdr);
  505. else
  506. sg_set_buf(vi->tx_sg, &hdr->hdr, sizeof hdr->hdr);
  507. hdr->num_sg = skb_to_sgvec(skb, vi->tx_sg + 1, 0, skb->len) + 1;
  508. return virtqueue_add_buf(vi->svq, vi->tx_sg, hdr->num_sg,
  509. 0, skb, GFP_ATOMIC);
  510. }
  511. static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
  512. {
  513. struct virtnet_info *vi = netdev_priv(dev);
  514. int capacity;
  515. /* Free up any pending old buffers before queueing new ones. */
  516. free_old_xmit_skbs(vi);
  517. /* Try to transmit */
  518. capacity = xmit_skb(vi, skb);
  519. /* This can happen with OOM and indirect buffers. */
  520. if (unlikely(capacity < 0)) {
  521. if (net_ratelimit()) {
  522. if (likely(capacity == -ENOMEM)) {
  523. dev_warn(&dev->dev,
  524. "TX queue failure: out of memory\n");
  525. } else {
  526. dev->stats.tx_fifo_errors++;
  527. dev_warn(&dev->dev,
  528. "Unexpected TX queue failure: %d\n",
  529. capacity);
  530. }
  531. }
  532. dev->stats.tx_dropped++;
  533. kfree_skb(skb);
  534. return NETDEV_TX_OK;
  535. }
  536. virtqueue_kick(vi->svq);
  537. /* Don't wait up for transmitted skbs to be freed. */
  538. skb_orphan(skb);
  539. nf_reset(skb);
  540. /* Apparently nice girls don't return TX_BUSY; stop the queue
  541. * before it gets out of hand. Naturally, this wastes entries. */
  542. if (capacity < 2+MAX_SKB_FRAGS) {
  543. netif_stop_queue(dev);
  544. if (unlikely(!virtqueue_enable_cb_delayed(vi->svq))) {
  545. /* More just got used, free them then recheck. */
  546. capacity += free_old_xmit_skbs(vi);
  547. if (capacity >= 2+MAX_SKB_FRAGS) {
  548. netif_start_queue(dev);
  549. virtqueue_disable_cb(vi->svq);
  550. }
  551. }
  552. }
  553. return NETDEV_TX_OK;
  554. }
  555. static int virtnet_set_mac_address(struct net_device *dev, void *p)
  556. {
  557. struct virtnet_info *vi = netdev_priv(dev);
  558. struct virtio_device *vdev = vi->vdev;
  559. int ret;
  560. ret = eth_mac_addr(dev, p);
  561. if (ret)
  562. return ret;
  563. if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC))
  564. vdev->config->set(vdev, offsetof(struct virtio_net_config, mac),
  565. dev->dev_addr, dev->addr_len);
  566. return 0;
  567. }
  568. static struct rtnl_link_stats64 *virtnet_stats(struct net_device *dev,
  569. struct rtnl_link_stats64 *tot)
  570. {
  571. struct virtnet_info *vi = netdev_priv(dev);
  572. int cpu;
  573. unsigned int start;
  574. for_each_possible_cpu(cpu) {
  575. struct virtnet_stats __percpu *stats
  576. = per_cpu_ptr(vi->stats, cpu);
  577. u64 tpackets, tbytes, rpackets, rbytes;
  578. do {
  579. start = u64_stats_fetch_begin(&stats->syncp);
  580. tpackets = stats->tx_packets;
  581. tbytes = stats->tx_bytes;
  582. rpackets = stats->rx_packets;
  583. rbytes = stats->rx_bytes;
  584. } while (u64_stats_fetch_retry(&stats->syncp, start));
  585. tot->rx_packets += rpackets;
  586. tot->tx_packets += tpackets;
  587. tot->rx_bytes += rbytes;
  588. tot->tx_bytes += tbytes;
  589. }
  590. tot->tx_dropped = dev->stats.tx_dropped;
  591. tot->tx_fifo_errors = dev->stats.tx_fifo_errors;
  592. tot->rx_dropped = dev->stats.rx_dropped;
  593. tot->rx_length_errors = dev->stats.rx_length_errors;
  594. tot->rx_frame_errors = dev->stats.rx_frame_errors;
  595. return tot;
  596. }
  597. #ifdef CONFIG_NET_POLL_CONTROLLER
  598. static void virtnet_netpoll(struct net_device *dev)
  599. {
  600. struct virtnet_info *vi = netdev_priv(dev);
  601. napi_schedule(&vi->napi);
  602. }
  603. #endif
  604. static int virtnet_open(struct net_device *dev)
  605. {
  606. struct virtnet_info *vi = netdev_priv(dev);
  607. /* Make sure we have some buffers: if oom use wq. */
  608. if (!try_fill_recv(vi, GFP_KERNEL))
  609. queue_delayed_work(system_nrt_wq, &vi->refill, 0);
  610. virtnet_napi_enable(vi);
  611. return 0;
  612. }
  613. /*
  614. * Send command via the control virtqueue and check status. Commands
  615. * supported by the hypervisor, as indicated by feature bits, should
  616. * never fail unless improperly formated.
  617. */
  618. static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
  619. struct scatterlist *data, int out, int in)
  620. {
  621. struct scatterlist *s, sg[VIRTNET_SEND_COMMAND_SG_MAX + 2];
  622. struct virtio_net_ctrl_hdr ctrl;
  623. virtio_net_ctrl_ack status = ~0;
  624. unsigned int tmp;
  625. int i;
  626. /* Caller should know better */
  627. BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) ||
  628. (out + in > VIRTNET_SEND_COMMAND_SG_MAX));
  629. out++; /* Add header */
  630. in++; /* Add return status */
  631. ctrl.class = class;
  632. ctrl.cmd = cmd;
  633. sg_init_table(sg, out + in);
  634. sg_set_buf(&sg[0], &ctrl, sizeof(ctrl));
  635. for_each_sg(data, s, out + in - 2, i)
  636. sg_set_buf(&sg[i + 1], sg_virt(s), s->length);
  637. sg_set_buf(&sg[out + in - 1], &status, sizeof(status));
  638. BUG_ON(virtqueue_add_buf(vi->cvq, sg, out, in, vi, GFP_ATOMIC) < 0);
  639. virtqueue_kick(vi->cvq);
  640. /*
  641. * Spin for a response, the kick causes an ioport write, trapping
  642. * into the hypervisor, so the request should be handled immediately.
  643. */
  644. while (!virtqueue_get_buf(vi->cvq, &tmp))
  645. cpu_relax();
  646. return status == VIRTIO_NET_OK;
  647. }
  648. static int virtnet_close(struct net_device *dev)
  649. {
  650. struct virtnet_info *vi = netdev_priv(dev);
  651. /* Make sure refill_work doesn't re-enable napi! */
  652. cancel_delayed_work_sync(&vi->refill);
  653. napi_disable(&vi->napi);
  654. return 0;
  655. }
  656. static void virtnet_set_rx_mode(struct net_device *dev)
  657. {
  658. struct virtnet_info *vi = netdev_priv(dev);
  659. struct scatterlist sg[2];
  660. u8 promisc, allmulti;
  661. struct virtio_net_ctrl_mac *mac_data;
  662. struct netdev_hw_addr *ha;
  663. int uc_count;
  664. int mc_count;
  665. void *buf;
  666. int i;
  667. /* We can't dynamicaly set ndo_set_rx_mode, so return gracefully */
  668. if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX))
  669. return;
  670. promisc = ((dev->flags & IFF_PROMISC) != 0);
  671. allmulti = ((dev->flags & IFF_ALLMULTI) != 0);
  672. sg_init_one(sg, &promisc, sizeof(promisc));
  673. if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
  674. VIRTIO_NET_CTRL_RX_PROMISC,
  675. sg, 1, 0))
  676. dev_warn(&dev->dev, "Failed to %sable promisc mode.\n",
  677. promisc ? "en" : "dis");
  678. sg_init_one(sg, &allmulti, sizeof(allmulti));
  679. if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
  680. VIRTIO_NET_CTRL_RX_ALLMULTI,
  681. sg, 1, 0))
  682. dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
  683. allmulti ? "en" : "dis");
  684. uc_count = netdev_uc_count(dev);
  685. mc_count = netdev_mc_count(dev);
  686. /* MAC filter - use one buffer for both lists */
  687. buf = kzalloc(((uc_count + mc_count) * ETH_ALEN) +
  688. (2 * sizeof(mac_data->entries)), GFP_ATOMIC);
  689. mac_data = buf;
  690. if (!buf) {
  691. dev_warn(&dev->dev, "No memory for MAC address buffer\n");
  692. return;
  693. }
  694. sg_init_table(sg, 2);
  695. /* Store the unicast list and count in the front of the buffer */
  696. mac_data->entries = uc_count;
  697. i = 0;
  698. netdev_for_each_uc_addr(ha, dev)
  699. memcpy(&mac_data->macs[i++][0], ha->addr, ETH_ALEN);
  700. sg_set_buf(&sg[0], mac_data,
  701. sizeof(mac_data->entries) + (uc_count * ETH_ALEN));
  702. /* multicast list and count fill the end */
  703. mac_data = (void *)&mac_data->macs[uc_count][0];
  704. mac_data->entries = mc_count;
  705. i = 0;
  706. netdev_for_each_mc_addr(ha, dev)
  707. memcpy(&mac_data->macs[i++][0], ha->addr, ETH_ALEN);
  708. sg_set_buf(&sg[1], mac_data,
  709. sizeof(mac_data->entries) + (mc_count * ETH_ALEN));
  710. if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC,
  711. VIRTIO_NET_CTRL_MAC_TABLE_SET,
  712. sg, 2, 0))
  713. dev_warn(&dev->dev, "Failed to set MAC fitler table.\n");
  714. kfree(buf);
  715. }
  716. static int virtnet_vlan_rx_add_vid(struct net_device *dev, u16 vid)
  717. {
  718. struct virtnet_info *vi = netdev_priv(dev);
  719. struct scatterlist sg;
  720. sg_init_one(&sg, &vid, sizeof(vid));
  721. if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
  722. VIRTIO_NET_CTRL_VLAN_ADD, &sg, 1, 0))
  723. dev_warn(&dev->dev, "Failed to add VLAN ID %d.\n", vid);
  724. return 0;
  725. }
  726. static int virtnet_vlan_rx_kill_vid(struct net_device *dev, u16 vid)
  727. {
  728. struct virtnet_info *vi = netdev_priv(dev);
  729. struct scatterlist sg;
  730. sg_init_one(&sg, &vid, sizeof(vid));
  731. if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
  732. VIRTIO_NET_CTRL_VLAN_DEL, &sg, 1, 0))
  733. dev_warn(&dev->dev, "Failed to kill VLAN ID %d.\n", vid);
  734. return 0;
  735. }
  736. static void virtnet_get_ringparam(struct net_device *dev,
  737. struct ethtool_ringparam *ring)
  738. {
  739. struct virtnet_info *vi = netdev_priv(dev);
  740. ring->rx_max_pending = virtqueue_get_vring_size(vi->rvq);
  741. ring->tx_max_pending = virtqueue_get_vring_size(vi->svq);
  742. ring->rx_pending = ring->rx_max_pending;
  743. ring->tx_pending = ring->tx_max_pending;
  744. }
  745. static void virtnet_get_drvinfo(struct net_device *dev,
  746. struct ethtool_drvinfo *info)
  747. {
  748. struct virtnet_info *vi = netdev_priv(dev);
  749. struct virtio_device *vdev = vi->vdev;
  750. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  751. strlcpy(info->version, VIRTNET_DRIVER_VERSION, sizeof(info->version));
  752. strlcpy(info->bus_info, virtio_bus_name(vdev), sizeof(info->bus_info));
  753. }
  754. static const struct ethtool_ops virtnet_ethtool_ops = {
  755. .get_drvinfo = virtnet_get_drvinfo,
  756. .get_link = ethtool_op_get_link,
  757. .get_ringparam = virtnet_get_ringparam,
  758. };
  759. #define MIN_MTU 68
  760. #define MAX_MTU 65535
  761. static int virtnet_change_mtu(struct net_device *dev, int new_mtu)
  762. {
  763. if (new_mtu < MIN_MTU || new_mtu > MAX_MTU)
  764. return -EINVAL;
  765. dev->mtu = new_mtu;
  766. return 0;
  767. }
  768. static const struct net_device_ops virtnet_netdev = {
  769. .ndo_open = virtnet_open,
  770. .ndo_stop = virtnet_close,
  771. .ndo_start_xmit = start_xmit,
  772. .ndo_validate_addr = eth_validate_addr,
  773. .ndo_set_mac_address = virtnet_set_mac_address,
  774. .ndo_set_rx_mode = virtnet_set_rx_mode,
  775. .ndo_change_mtu = virtnet_change_mtu,
  776. .ndo_get_stats64 = virtnet_stats,
  777. .ndo_vlan_rx_add_vid = virtnet_vlan_rx_add_vid,
  778. .ndo_vlan_rx_kill_vid = virtnet_vlan_rx_kill_vid,
  779. #ifdef CONFIG_NET_POLL_CONTROLLER
  780. .ndo_poll_controller = virtnet_netpoll,
  781. #endif
  782. };
  783. static void virtnet_update_status(struct virtnet_info *vi)
  784. {
  785. u16 v;
  786. if (virtio_config_val(vi->vdev, VIRTIO_NET_F_STATUS,
  787. offsetof(struct virtio_net_config, status),
  788. &v) < 0)
  789. return;
  790. /* Ignore unknown (future) status bits */
  791. v &= VIRTIO_NET_S_LINK_UP;
  792. if (vi->status == v)
  793. return;
  794. vi->status = v;
  795. if (vi->status & VIRTIO_NET_S_LINK_UP) {
  796. netif_carrier_on(vi->dev);
  797. netif_wake_queue(vi->dev);
  798. } else {
  799. netif_carrier_off(vi->dev);
  800. netif_stop_queue(vi->dev);
  801. }
  802. }
  803. static void virtnet_config_changed(struct virtio_device *vdev)
  804. {
  805. struct virtnet_info *vi = vdev->priv;
  806. virtnet_update_status(vi);
  807. }
  808. static int virtnet_probe(struct virtio_device *vdev)
  809. {
  810. int err;
  811. struct net_device *dev;
  812. struct virtnet_info *vi;
  813. struct virtqueue *vqs[3];
  814. vq_callback_t *callbacks[] = { skb_recv_done, skb_xmit_done, NULL};
  815. const char *names[] = { "input", "output", "control" };
  816. int nvqs;
  817. /* Allocate ourselves a network device with room for our info */
  818. dev = alloc_etherdev(sizeof(struct virtnet_info));
  819. if (!dev)
  820. return -ENOMEM;
  821. /* Set up network device as normal. */
  822. dev->priv_flags |= IFF_UNICAST_FLT;
  823. dev->netdev_ops = &virtnet_netdev;
  824. dev->features = NETIF_F_HIGHDMA;
  825. SET_ETHTOOL_OPS(dev, &virtnet_ethtool_ops);
  826. SET_NETDEV_DEV(dev, &vdev->dev);
  827. /* Do we support "hardware" checksums? */
  828. if (virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) {
  829. /* This opens up the world of extra features. */
  830. dev->hw_features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
  831. if (csum)
  832. dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
  833. if (virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) {
  834. dev->hw_features |= NETIF_F_TSO | NETIF_F_UFO
  835. | NETIF_F_TSO_ECN | NETIF_F_TSO6;
  836. }
  837. /* Individual feature bits: what can host handle? */
  838. if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO4))
  839. dev->hw_features |= NETIF_F_TSO;
  840. if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO6))
  841. dev->hw_features |= NETIF_F_TSO6;
  842. if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_ECN))
  843. dev->hw_features |= NETIF_F_TSO_ECN;
  844. if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UFO))
  845. dev->hw_features |= NETIF_F_UFO;
  846. if (gso)
  847. dev->features |= dev->hw_features & (NETIF_F_ALL_TSO|NETIF_F_UFO);
  848. /* (!csum && gso) case will be fixed by register_netdev() */
  849. }
  850. /* Configuration may specify what MAC to use. Otherwise random. */
  851. if (virtio_config_val_len(vdev, VIRTIO_NET_F_MAC,
  852. offsetof(struct virtio_net_config, mac),
  853. dev->dev_addr, dev->addr_len) < 0)
  854. random_ether_addr(dev->dev_addr);
  855. /* Set up our device-specific information */
  856. vi = netdev_priv(dev);
  857. netif_napi_add(dev, &vi->napi, virtnet_poll, napi_weight);
  858. vi->dev = dev;
  859. vi->vdev = vdev;
  860. vdev->priv = vi;
  861. vi->pages = NULL;
  862. vi->stats = alloc_percpu(struct virtnet_stats);
  863. err = -ENOMEM;
  864. if (vi->stats == NULL)
  865. goto free;
  866. INIT_DELAYED_WORK(&vi->refill, refill_work);
  867. sg_init_table(vi->rx_sg, ARRAY_SIZE(vi->rx_sg));
  868. sg_init_table(vi->tx_sg, ARRAY_SIZE(vi->tx_sg));
  869. /* If we can receive ANY GSO packets, we must allocate large ones. */
  870. if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
  871. virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) ||
  872. virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN))
  873. vi->big_packets = true;
  874. if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
  875. vi->mergeable_rx_bufs = true;
  876. /* We expect two virtqueues, receive then send,
  877. * and optionally control. */
  878. nvqs = virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) ? 3 : 2;
  879. err = vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names);
  880. if (err)
  881. goto free_stats;
  882. vi->rvq = vqs[0];
  883. vi->svq = vqs[1];
  884. if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
  885. vi->cvq = vqs[2];
  886. if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
  887. dev->features |= NETIF_F_HW_VLAN_FILTER;
  888. }
  889. err = register_netdev(dev);
  890. if (err) {
  891. pr_debug("virtio_net: registering device failed\n");
  892. goto free_vqs;
  893. }
  894. /* Last of all, set up some receive buffers. */
  895. try_fill_recv(vi, GFP_KERNEL);
  896. /* If we didn't even get one input buffer, we're useless. */
  897. if (vi->num == 0) {
  898. err = -ENOMEM;
  899. goto unregister;
  900. }
  901. /* Assume link up if device can't report link status,
  902. otherwise get link status from config. */
  903. if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) {
  904. netif_carrier_off(dev);
  905. virtnet_update_status(vi);
  906. } else {
  907. vi->status = VIRTIO_NET_S_LINK_UP;
  908. netif_carrier_on(dev);
  909. }
  910. pr_debug("virtnet: registered device %s\n", dev->name);
  911. return 0;
  912. unregister:
  913. unregister_netdev(dev);
  914. free_vqs:
  915. vdev->config->del_vqs(vdev);
  916. free_stats:
  917. free_percpu(vi->stats);
  918. free:
  919. free_netdev(dev);
  920. return err;
  921. }
  922. static void free_unused_bufs(struct virtnet_info *vi)
  923. {
  924. void *buf;
  925. while (1) {
  926. buf = virtqueue_detach_unused_buf(vi->svq);
  927. if (!buf)
  928. break;
  929. dev_kfree_skb(buf);
  930. }
  931. while (1) {
  932. buf = virtqueue_detach_unused_buf(vi->rvq);
  933. if (!buf)
  934. break;
  935. if (vi->mergeable_rx_bufs || vi->big_packets)
  936. give_pages(vi, buf);
  937. else
  938. dev_kfree_skb(buf);
  939. --vi->num;
  940. }
  941. BUG_ON(vi->num != 0);
  942. }
  943. static void __devexit virtnet_remove(struct virtio_device *vdev)
  944. {
  945. struct virtnet_info *vi = vdev->priv;
  946. /* Stop all the virtqueues. */
  947. vdev->config->reset(vdev);
  948. unregister_netdev(vi->dev);
  949. /* Free unused buffers in both send and recv, if any. */
  950. free_unused_bufs(vi);
  951. vdev->config->del_vqs(vi->vdev);
  952. while (vi->pages)
  953. __free_pages(get_a_page(vi, GFP_KERNEL), 0);
  954. free_percpu(vi->stats);
  955. free_netdev(vi->dev);
  956. }
  957. static struct virtio_device_id id_table[] = {
  958. { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
  959. { 0 },
  960. };
  961. static unsigned int features[] = {
  962. VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM,
  963. VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC,
  964. VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6,
  965. VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
  966. VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO,
  967. VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
  968. VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
  969. };
  970. static struct virtio_driver virtio_net_driver = {
  971. .feature_table = features,
  972. .feature_table_size = ARRAY_SIZE(features),
  973. .driver.name = KBUILD_MODNAME,
  974. .driver.owner = THIS_MODULE,
  975. .id_table = id_table,
  976. .probe = virtnet_probe,
  977. .remove = __devexit_p(virtnet_remove),
  978. .config_changed = virtnet_config_changed,
  979. };
  980. static int __init init(void)
  981. {
  982. return register_virtio_driver(&virtio_net_driver);
  983. }
  984. static void __exit fini(void)
  985. {
  986. unregister_virtio_driver(&virtio_net_driver);
  987. }
  988. module_init(init);
  989. module_exit(fini);
  990. MODULE_DEVICE_TABLE(virtio, id_table);
  991. MODULE_DESCRIPTION("Virtio network driver");
  992. MODULE_LICENSE("GPL");