netvsc_drv.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /*
  2. * Copyright (c) 2009, Microsoft Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * Authors:
  17. * Haiyang Zhang <haiyangz@microsoft.com>
  18. * Hank Janssen <hjanssen@microsoft.com>
  19. */
  20. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/init.h>
  22. #include <linux/atomic.h>
  23. #include <linux/module.h>
  24. #include <linux/highmem.h>
  25. #include <linux/device.h>
  26. #include <linux/io.h>
  27. #include <linux/delay.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/inetdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/if_vlan.h>
  33. #include <linux/in.h>
  34. #include <linux/slab.h>
  35. #include <net/arp.h>
  36. #include <net/route.h>
  37. #include <net/sock.h>
  38. #include <net/pkt_sched.h>
  39. #include "hyperv_net.h"
  40. #define RING_SIZE_MIN 64
  41. #define LINKCHANGE_INT (2 * HZ)
  42. #define NETVSC_HW_FEATURES (NETIF_F_RXCSUM | \
  43. NETIF_F_SG | \
  44. NETIF_F_TSO | \
  45. NETIF_F_TSO6 | \
  46. NETIF_F_HW_CSUM)
  47. static int ring_size = 128;
  48. module_param(ring_size, int, S_IRUGO);
  49. MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
  50. static int max_num_vrss_chns = 8;
  51. static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
  52. NETIF_MSG_LINK | NETIF_MSG_IFUP |
  53. NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR |
  54. NETIF_MSG_TX_ERR;
  55. static int debug = -1;
  56. module_param(debug, int, S_IRUGO);
  57. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  58. static void do_set_multicast(struct work_struct *w)
  59. {
  60. struct net_device_context *ndevctx =
  61. container_of(w, struct net_device_context, work);
  62. struct netvsc_device *nvdev;
  63. struct rndis_device *rdev;
  64. nvdev = hv_get_drvdata(ndevctx->device_ctx);
  65. if (nvdev == NULL || nvdev->ndev == NULL)
  66. return;
  67. rdev = nvdev->extension;
  68. if (rdev == NULL)
  69. return;
  70. if (nvdev->ndev->flags & IFF_PROMISC)
  71. rndis_filter_set_packet_filter(rdev,
  72. NDIS_PACKET_TYPE_PROMISCUOUS);
  73. else
  74. rndis_filter_set_packet_filter(rdev,
  75. NDIS_PACKET_TYPE_BROADCAST |
  76. NDIS_PACKET_TYPE_ALL_MULTICAST |
  77. NDIS_PACKET_TYPE_DIRECTED);
  78. }
  79. static void netvsc_set_multicast_list(struct net_device *net)
  80. {
  81. struct net_device_context *net_device_ctx = netdev_priv(net);
  82. schedule_work(&net_device_ctx->work);
  83. }
  84. static int netvsc_open(struct net_device *net)
  85. {
  86. struct net_device_context *net_device_ctx = netdev_priv(net);
  87. struct hv_device *device_obj = net_device_ctx->device_ctx;
  88. struct netvsc_device *nvdev;
  89. struct rndis_device *rdev;
  90. int ret = 0;
  91. netif_carrier_off(net);
  92. /* Open up the device */
  93. ret = rndis_filter_open(device_obj);
  94. if (ret != 0) {
  95. netdev_err(net, "unable to open device (ret %d).\n", ret);
  96. return ret;
  97. }
  98. netif_tx_wake_all_queues(net);
  99. nvdev = hv_get_drvdata(device_obj);
  100. rdev = nvdev->extension;
  101. if (!rdev->link_state)
  102. netif_carrier_on(net);
  103. return ret;
  104. }
  105. static int netvsc_close(struct net_device *net)
  106. {
  107. struct net_device_context *net_device_ctx = netdev_priv(net);
  108. struct hv_device *device_obj = net_device_ctx->device_ctx;
  109. struct netvsc_device *nvdev = hv_get_drvdata(device_obj);
  110. int ret;
  111. u32 aread, awrite, i, msec = 10, retry = 0, retry_max = 20;
  112. struct vmbus_channel *chn;
  113. netif_tx_disable(net);
  114. /* Make sure netvsc_set_multicast_list doesn't re-enable filter! */
  115. cancel_work_sync(&net_device_ctx->work);
  116. ret = rndis_filter_close(device_obj);
  117. if (ret != 0) {
  118. netdev_err(net, "unable to close device (ret %d).\n", ret);
  119. return ret;
  120. }
  121. /* Ensure pending bytes in ring are read */
  122. while (true) {
  123. aread = 0;
  124. for (i = 0; i < nvdev->num_chn; i++) {
  125. chn = nvdev->chn_table[i];
  126. if (!chn)
  127. continue;
  128. hv_get_ringbuffer_availbytes(&chn->inbound, &aread,
  129. &awrite);
  130. if (aread)
  131. break;
  132. hv_get_ringbuffer_availbytes(&chn->outbound, &aread,
  133. &awrite);
  134. if (aread)
  135. break;
  136. }
  137. retry++;
  138. if (retry > retry_max || aread == 0)
  139. break;
  140. msleep(msec);
  141. if (msec < 1000)
  142. msec *= 2;
  143. }
  144. if (aread) {
  145. netdev_err(net, "Ring buffer not empty after closing rndis\n");
  146. ret = -ETIMEDOUT;
  147. }
  148. return ret;
  149. }
  150. static void *init_ppi_data(struct rndis_message *msg, u32 ppi_size,
  151. int pkt_type)
  152. {
  153. struct rndis_packet *rndis_pkt;
  154. struct rndis_per_packet_info *ppi;
  155. rndis_pkt = &msg->msg.pkt;
  156. rndis_pkt->data_offset += ppi_size;
  157. ppi = (struct rndis_per_packet_info *)((void *)rndis_pkt +
  158. rndis_pkt->per_pkt_info_offset + rndis_pkt->per_pkt_info_len);
  159. ppi->size = ppi_size;
  160. ppi->type = pkt_type;
  161. ppi->ppi_offset = sizeof(struct rndis_per_packet_info);
  162. rndis_pkt->per_pkt_info_len += ppi_size;
  163. return ppi;
  164. }
  165. static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
  166. void *accel_priv, select_queue_fallback_t fallback)
  167. {
  168. struct net_device_context *net_device_ctx = netdev_priv(ndev);
  169. struct hv_device *hdev = net_device_ctx->device_ctx;
  170. struct netvsc_device *nvsc_dev = hv_get_drvdata(hdev);
  171. u32 hash;
  172. u16 q_idx = 0;
  173. if (nvsc_dev == NULL || ndev->real_num_tx_queues <= 1)
  174. return 0;
  175. hash = skb_get_hash(skb);
  176. q_idx = nvsc_dev->send_table[hash % VRSS_SEND_TAB_SIZE] %
  177. ndev->real_num_tx_queues;
  178. if (!nvsc_dev->chn_table[q_idx])
  179. q_idx = 0;
  180. return q_idx;
  181. }
  182. static u32 fill_pg_buf(struct page *page, u32 offset, u32 len,
  183. struct hv_page_buffer *pb)
  184. {
  185. int j = 0;
  186. /* Deal with compund pages by ignoring unused part
  187. * of the page.
  188. */
  189. page += (offset >> PAGE_SHIFT);
  190. offset &= ~PAGE_MASK;
  191. while (len > 0) {
  192. unsigned long bytes;
  193. bytes = PAGE_SIZE - offset;
  194. if (bytes > len)
  195. bytes = len;
  196. pb[j].pfn = page_to_pfn(page);
  197. pb[j].offset = offset;
  198. pb[j].len = bytes;
  199. offset += bytes;
  200. len -= bytes;
  201. if (offset == PAGE_SIZE && len) {
  202. page++;
  203. offset = 0;
  204. j++;
  205. }
  206. }
  207. return j + 1;
  208. }
  209. static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb,
  210. struct hv_netvsc_packet *packet,
  211. struct hv_page_buffer **page_buf)
  212. {
  213. struct hv_page_buffer *pb = *page_buf;
  214. u32 slots_used = 0;
  215. char *data = skb->data;
  216. int frags = skb_shinfo(skb)->nr_frags;
  217. int i;
  218. /* The packet is laid out thus:
  219. * 1. hdr: RNDIS header and PPI
  220. * 2. skb linear data
  221. * 3. skb fragment data
  222. */
  223. if (hdr != NULL)
  224. slots_used += fill_pg_buf(virt_to_page(hdr),
  225. offset_in_page(hdr),
  226. len, &pb[slots_used]);
  227. packet->rmsg_size = len;
  228. packet->rmsg_pgcnt = slots_used;
  229. slots_used += fill_pg_buf(virt_to_page(data),
  230. offset_in_page(data),
  231. skb_headlen(skb), &pb[slots_used]);
  232. for (i = 0; i < frags; i++) {
  233. skb_frag_t *frag = skb_shinfo(skb)->frags + i;
  234. slots_used += fill_pg_buf(skb_frag_page(frag),
  235. frag->page_offset,
  236. skb_frag_size(frag), &pb[slots_used]);
  237. }
  238. return slots_used;
  239. }
  240. static int count_skb_frag_slots(struct sk_buff *skb)
  241. {
  242. int i, frags = skb_shinfo(skb)->nr_frags;
  243. int pages = 0;
  244. for (i = 0; i < frags; i++) {
  245. skb_frag_t *frag = skb_shinfo(skb)->frags + i;
  246. unsigned long size = skb_frag_size(frag);
  247. unsigned long offset = frag->page_offset;
  248. /* Skip unused frames from start of page */
  249. offset &= ~PAGE_MASK;
  250. pages += PFN_UP(offset + size);
  251. }
  252. return pages;
  253. }
  254. static int netvsc_get_slots(struct sk_buff *skb)
  255. {
  256. char *data = skb->data;
  257. unsigned int offset = offset_in_page(data);
  258. unsigned int len = skb_headlen(skb);
  259. int slots;
  260. int frag_slots;
  261. slots = DIV_ROUND_UP(offset + len, PAGE_SIZE);
  262. frag_slots = count_skb_frag_slots(skb);
  263. return slots + frag_slots;
  264. }
  265. static u32 get_net_transport_info(struct sk_buff *skb, u32 *trans_off)
  266. {
  267. u32 ret_val = TRANSPORT_INFO_NOT_IP;
  268. if ((eth_hdr(skb)->h_proto != htons(ETH_P_IP)) &&
  269. (eth_hdr(skb)->h_proto != htons(ETH_P_IPV6))) {
  270. goto not_ip;
  271. }
  272. *trans_off = skb_transport_offset(skb);
  273. if ((eth_hdr(skb)->h_proto == htons(ETH_P_IP))) {
  274. struct iphdr *iphdr = ip_hdr(skb);
  275. if (iphdr->protocol == IPPROTO_TCP)
  276. ret_val = TRANSPORT_INFO_IPV4_TCP;
  277. else if (iphdr->protocol == IPPROTO_UDP)
  278. ret_val = TRANSPORT_INFO_IPV4_UDP;
  279. } else {
  280. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  281. ret_val = TRANSPORT_INFO_IPV6_TCP;
  282. else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
  283. ret_val = TRANSPORT_INFO_IPV6_UDP;
  284. }
  285. not_ip:
  286. return ret_val;
  287. }
  288. static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
  289. {
  290. struct net_device_context *net_device_ctx = netdev_priv(net);
  291. struct hv_netvsc_packet *packet = NULL;
  292. int ret;
  293. unsigned int num_data_pgs;
  294. struct rndis_message *rndis_msg;
  295. struct rndis_packet *rndis_pkt;
  296. u32 rndis_msg_size;
  297. bool isvlan;
  298. bool linear = false;
  299. struct rndis_per_packet_info *ppi;
  300. struct ndis_tcp_ip_checksum_info *csum_info;
  301. struct ndis_tcp_lso_info *lso_info;
  302. int hdr_offset;
  303. u32 net_trans_info;
  304. u32 hash;
  305. u32 skb_length;
  306. struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT];
  307. struct hv_page_buffer *pb = page_buf;
  308. struct netvsc_stats *tx_stats = this_cpu_ptr(net_device_ctx->tx_stats);
  309. /* We will atmost need two pages to describe the rndis
  310. * header. We can only transmit MAX_PAGE_BUFFER_COUNT number
  311. * of pages in a single packet. If skb is scattered around
  312. * more pages we try linearizing it.
  313. */
  314. check_size:
  315. skb_length = skb->len;
  316. num_data_pgs = netvsc_get_slots(skb) + 2;
  317. if (num_data_pgs > MAX_PAGE_BUFFER_COUNT && linear) {
  318. net_alert_ratelimited("packet too big: %u pages (%u bytes)\n",
  319. num_data_pgs, skb->len);
  320. ret = -EFAULT;
  321. goto drop;
  322. } else if (num_data_pgs > MAX_PAGE_BUFFER_COUNT) {
  323. if (skb_linearize(skb)) {
  324. net_alert_ratelimited("failed to linearize skb\n");
  325. ret = -ENOMEM;
  326. goto drop;
  327. }
  328. linear = true;
  329. goto check_size;
  330. }
  331. /*
  332. * Place the rndis header in the skb head room and
  333. * the skb->cb will be used for hv_netvsc_packet
  334. * structure.
  335. */
  336. ret = skb_cow_head(skb, RNDIS_AND_PPI_SIZE);
  337. if (ret) {
  338. netdev_err(net, "unable to alloc hv_netvsc_packet\n");
  339. ret = -ENOMEM;
  340. goto drop;
  341. }
  342. /* Use the skb control buffer for building up the packet */
  343. BUILD_BUG_ON(sizeof(struct hv_netvsc_packet) >
  344. FIELD_SIZEOF(struct sk_buff, cb));
  345. packet = (struct hv_netvsc_packet *)skb->cb;
  346. packet->q_idx = skb_get_queue_mapping(skb);
  347. packet->total_data_buflen = skb->len;
  348. rndis_msg = (struct rndis_message *)skb->head;
  349. memset(rndis_msg, 0, RNDIS_AND_PPI_SIZE);
  350. isvlan = skb->vlan_tci & VLAN_TAG_PRESENT;
  351. /* Add the rndis header */
  352. rndis_msg->ndis_msg_type = RNDIS_MSG_PACKET;
  353. rndis_msg->msg_len = packet->total_data_buflen;
  354. rndis_pkt = &rndis_msg->msg.pkt;
  355. rndis_pkt->data_offset = sizeof(struct rndis_packet);
  356. rndis_pkt->data_len = packet->total_data_buflen;
  357. rndis_pkt->per_pkt_info_offset = sizeof(struct rndis_packet);
  358. rndis_msg_size = RNDIS_MESSAGE_SIZE(struct rndis_packet);
  359. hash = skb_get_hash_raw(skb);
  360. if (hash != 0 && net->real_num_tx_queues > 1) {
  361. rndis_msg_size += NDIS_HASH_PPI_SIZE;
  362. ppi = init_ppi_data(rndis_msg, NDIS_HASH_PPI_SIZE,
  363. NBL_HASH_VALUE);
  364. *(u32 *)((void *)ppi + ppi->ppi_offset) = hash;
  365. }
  366. if (isvlan) {
  367. struct ndis_pkt_8021q_info *vlan;
  368. rndis_msg_size += NDIS_VLAN_PPI_SIZE;
  369. ppi = init_ppi_data(rndis_msg, NDIS_VLAN_PPI_SIZE,
  370. IEEE_8021Q_INFO);
  371. vlan = (struct ndis_pkt_8021q_info *)((void *)ppi +
  372. ppi->ppi_offset);
  373. vlan->vlanid = skb->vlan_tci & VLAN_VID_MASK;
  374. vlan->pri = (skb->vlan_tci & VLAN_PRIO_MASK) >>
  375. VLAN_PRIO_SHIFT;
  376. }
  377. net_trans_info = get_net_transport_info(skb, &hdr_offset);
  378. if (net_trans_info == TRANSPORT_INFO_NOT_IP)
  379. goto do_send;
  380. /*
  381. * Setup the sendside checksum offload only if this is not a
  382. * GSO packet.
  383. */
  384. if (skb_is_gso(skb))
  385. goto do_lso;
  386. if ((skb->ip_summed == CHECKSUM_NONE) ||
  387. (skb->ip_summed == CHECKSUM_UNNECESSARY))
  388. goto do_send;
  389. rndis_msg_size += NDIS_CSUM_PPI_SIZE;
  390. ppi = init_ppi_data(rndis_msg, NDIS_CSUM_PPI_SIZE,
  391. TCPIP_CHKSUM_PKTINFO);
  392. csum_info = (struct ndis_tcp_ip_checksum_info *)((void *)ppi +
  393. ppi->ppi_offset);
  394. if (net_trans_info & (INFO_IPV4 << 16))
  395. csum_info->transmit.is_ipv4 = 1;
  396. else
  397. csum_info->transmit.is_ipv6 = 1;
  398. if (net_trans_info & INFO_TCP) {
  399. csum_info->transmit.tcp_checksum = 1;
  400. csum_info->transmit.tcp_header_offset = hdr_offset;
  401. } else if (net_trans_info & INFO_UDP) {
  402. /* UDP checksum offload is not supported on ws2008r2.
  403. * Furthermore, on ws2012 and ws2012r2, there are some
  404. * issues with udp checksum offload from Linux guests.
  405. * (these are host issues).
  406. * For now compute the checksum here.
  407. */
  408. struct udphdr *uh;
  409. u16 udp_len;
  410. ret = skb_cow_head(skb, 0);
  411. if (ret)
  412. goto drop;
  413. uh = udp_hdr(skb);
  414. udp_len = ntohs(uh->len);
  415. uh->check = 0;
  416. uh->check = csum_tcpudp_magic(ip_hdr(skb)->saddr,
  417. ip_hdr(skb)->daddr,
  418. udp_len, IPPROTO_UDP,
  419. csum_partial(uh, udp_len, 0));
  420. if (uh->check == 0)
  421. uh->check = CSUM_MANGLED_0;
  422. csum_info->transmit.udp_checksum = 0;
  423. }
  424. goto do_send;
  425. do_lso:
  426. rndis_msg_size += NDIS_LSO_PPI_SIZE;
  427. ppi = init_ppi_data(rndis_msg, NDIS_LSO_PPI_SIZE,
  428. TCP_LARGESEND_PKTINFO);
  429. lso_info = (struct ndis_tcp_lso_info *)((void *)ppi +
  430. ppi->ppi_offset);
  431. lso_info->lso_v2_transmit.type = NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE;
  432. if (net_trans_info & (INFO_IPV4 << 16)) {
  433. lso_info->lso_v2_transmit.ip_version =
  434. NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4;
  435. ip_hdr(skb)->tot_len = 0;
  436. ip_hdr(skb)->check = 0;
  437. tcp_hdr(skb)->check =
  438. ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  439. ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  440. } else {
  441. lso_info->lso_v2_transmit.ip_version =
  442. NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6;
  443. ipv6_hdr(skb)->payload_len = 0;
  444. tcp_hdr(skb)->check =
  445. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  446. &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  447. }
  448. lso_info->lso_v2_transmit.tcp_header_offset = hdr_offset;
  449. lso_info->lso_v2_transmit.mss = skb_shinfo(skb)->gso_size;
  450. do_send:
  451. /* Start filling in the page buffers with the rndis hdr */
  452. rndis_msg->msg_len += rndis_msg_size;
  453. packet->total_data_buflen = rndis_msg->msg_len;
  454. packet->page_buf_cnt = init_page_array(rndis_msg, rndis_msg_size,
  455. skb, packet, &pb);
  456. /* timestamp packet in software */
  457. skb_tx_timestamp(skb);
  458. ret = netvsc_send(net_device_ctx->device_ctx, packet,
  459. rndis_msg, &pb, skb);
  460. drop:
  461. if (ret == 0) {
  462. u64_stats_update_begin(&tx_stats->syncp);
  463. tx_stats->packets++;
  464. tx_stats->bytes += skb_length;
  465. u64_stats_update_end(&tx_stats->syncp);
  466. } else {
  467. if (ret != -EAGAIN) {
  468. dev_kfree_skb_any(skb);
  469. net->stats.tx_dropped++;
  470. }
  471. }
  472. return (ret == -EAGAIN) ? NETDEV_TX_BUSY : NETDEV_TX_OK;
  473. }
  474. /*
  475. * netvsc_linkstatus_callback - Link up/down notification
  476. */
  477. void netvsc_linkstatus_callback(struct hv_device *device_obj,
  478. struct rndis_message *resp)
  479. {
  480. struct rndis_indicate_status *indicate = &resp->msg.indicate_status;
  481. struct net_device *net;
  482. struct net_device_context *ndev_ctx;
  483. struct netvsc_device *net_device;
  484. struct netvsc_reconfig *event;
  485. unsigned long flags;
  486. /* Handle link change statuses only */
  487. if (indicate->status != RNDIS_STATUS_NETWORK_CHANGE &&
  488. indicate->status != RNDIS_STATUS_MEDIA_CONNECT &&
  489. indicate->status != RNDIS_STATUS_MEDIA_DISCONNECT)
  490. return;
  491. net_device = hv_get_drvdata(device_obj);
  492. net = net_device->ndev;
  493. if (!net || net->reg_state != NETREG_REGISTERED)
  494. return;
  495. ndev_ctx = netdev_priv(net);
  496. event = kzalloc(sizeof(*event), GFP_ATOMIC);
  497. if (!event)
  498. return;
  499. event->event = indicate->status;
  500. spin_lock_irqsave(&ndev_ctx->lock, flags);
  501. list_add_tail(&event->list, &ndev_ctx->reconfig_events);
  502. spin_unlock_irqrestore(&ndev_ctx->lock, flags);
  503. schedule_delayed_work(&ndev_ctx->dwork, 0);
  504. }
  505. /*
  506. * netvsc_recv_callback - Callback when we receive a packet from the
  507. * "wire" on the specified device.
  508. */
  509. int netvsc_recv_callback(struct hv_device *device_obj,
  510. struct hv_netvsc_packet *packet,
  511. void **data,
  512. struct ndis_tcp_ip_checksum_info *csum_info,
  513. struct vmbus_channel *channel,
  514. u16 vlan_tci)
  515. {
  516. struct net_device *net;
  517. struct net_device_context *net_device_ctx;
  518. struct sk_buff *skb;
  519. struct netvsc_stats *rx_stats;
  520. net = ((struct netvsc_device *)hv_get_drvdata(device_obj))->ndev;
  521. if (!net || net->reg_state != NETREG_REGISTERED) {
  522. return NVSP_STAT_FAIL;
  523. }
  524. net_device_ctx = netdev_priv(net);
  525. rx_stats = this_cpu_ptr(net_device_ctx->rx_stats);
  526. /* Allocate a skb - TODO direct I/O to pages? */
  527. skb = netdev_alloc_skb_ip_align(net, packet->total_data_buflen);
  528. if (unlikely(!skb)) {
  529. ++net->stats.rx_dropped;
  530. return NVSP_STAT_FAIL;
  531. }
  532. /*
  533. * Copy to skb. This copy is needed here since the memory pointed by
  534. * hv_netvsc_packet cannot be deallocated
  535. */
  536. memcpy(skb_put(skb, packet->total_data_buflen), *data,
  537. packet->total_data_buflen);
  538. skb->protocol = eth_type_trans(skb, net);
  539. if (csum_info) {
  540. /* We only look at the IP checksum here.
  541. * Should we be dropping the packet if checksum
  542. * failed? How do we deal with other checksums - TCP/UDP?
  543. */
  544. if (csum_info->receive.ip_checksum_succeeded)
  545. skb->ip_summed = CHECKSUM_UNNECESSARY;
  546. else
  547. skb->ip_summed = CHECKSUM_NONE;
  548. }
  549. if (vlan_tci & VLAN_TAG_PRESENT)
  550. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
  551. vlan_tci);
  552. skb_record_rx_queue(skb, channel->
  553. offermsg.offer.sub_channel_index);
  554. u64_stats_update_begin(&rx_stats->syncp);
  555. rx_stats->packets++;
  556. rx_stats->bytes += packet->total_data_buflen;
  557. u64_stats_update_end(&rx_stats->syncp);
  558. /*
  559. * Pass the skb back up. Network stack will deallocate the skb when it
  560. * is done.
  561. * TODO - use NAPI?
  562. */
  563. netif_rx(skb);
  564. return 0;
  565. }
  566. static void netvsc_get_drvinfo(struct net_device *net,
  567. struct ethtool_drvinfo *info)
  568. {
  569. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  570. strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
  571. }
  572. static void netvsc_get_channels(struct net_device *net,
  573. struct ethtool_channels *channel)
  574. {
  575. struct net_device_context *net_device_ctx = netdev_priv(net);
  576. struct hv_device *dev = net_device_ctx->device_ctx;
  577. struct netvsc_device *nvdev = hv_get_drvdata(dev);
  578. if (nvdev) {
  579. channel->max_combined = nvdev->max_chn;
  580. channel->combined_count = nvdev->num_chn;
  581. }
  582. }
  583. static int netvsc_set_channels(struct net_device *net,
  584. struct ethtool_channels *channels)
  585. {
  586. struct net_device_context *net_device_ctx = netdev_priv(net);
  587. struct hv_device *dev = net_device_ctx->device_ctx;
  588. struct netvsc_device *nvdev = hv_get_drvdata(dev);
  589. struct netvsc_device_info device_info;
  590. u32 num_chn;
  591. u32 max_chn;
  592. int ret = 0;
  593. bool recovering = false;
  594. if (!nvdev || nvdev->destroy)
  595. return -ENODEV;
  596. num_chn = nvdev->num_chn;
  597. max_chn = min_t(u32, nvdev->max_chn, num_online_cpus());
  598. if (nvdev->nvsp_version < NVSP_PROTOCOL_VERSION_5) {
  599. pr_info("vRSS unsupported before NVSP Version 5\n");
  600. return -EINVAL;
  601. }
  602. /* We do not support rx, tx, or other */
  603. if (!channels ||
  604. channels->rx_count ||
  605. channels->tx_count ||
  606. channels->other_count ||
  607. (channels->combined_count < 1))
  608. return -EINVAL;
  609. if (channels->combined_count > max_chn) {
  610. pr_info("combined channels too high, using %d\n", max_chn);
  611. channels->combined_count = max_chn;
  612. }
  613. ret = netvsc_close(net);
  614. if (ret)
  615. goto out;
  616. do_set:
  617. nvdev->start_remove = true;
  618. rndis_filter_device_remove(dev);
  619. nvdev->num_chn = channels->combined_count;
  620. net_device_ctx->device_ctx = dev;
  621. hv_set_drvdata(dev, net);
  622. memset(&device_info, 0, sizeof(device_info));
  623. device_info.num_chn = nvdev->num_chn; /* passed to RNDIS */
  624. device_info.ring_size = ring_size;
  625. device_info.max_num_vrss_chns = max_num_vrss_chns;
  626. ret = rndis_filter_device_add(dev, &device_info);
  627. if (ret) {
  628. if (recovering) {
  629. netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
  630. return ret;
  631. }
  632. goto recover;
  633. }
  634. nvdev = hv_get_drvdata(dev);
  635. ret = netif_set_real_num_tx_queues(net, nvdev->num_chn);
  636. if (ret) {
  637. if (recovering) {
  638. netdev_err(net, "could not set tx queue count (ret %d)\n", ret);
  639. return ret;
  640. }
  641. goto recover;
  642. }
  643. ret = netif_set_real_num_rx_queues(net, nvdev->num_chn);
  644. if (ret) {
  645. if (recovering) {
  646. netdev_err(net, "could not set rx queue count (ret %d)\n", ret);
  647. return ret;
  648. }
  649. goto recover;
  650. }
  651. out:
  652. netvsc_open(net);
  653. return ret;
  654. recover:
  655. /* If the above failed, we attempt to recover through the same
  656. * process but with the original number of channels.
  657. */
  658. netdev_err(net, "could not set channels, recovering\n");
  659. recovering = true;
  660. channels->combined_count = num_chn;
  661. goto do_set;
  662. }
  663. static bool netvsc_validate_ethtool_ss_cmd(const struct ethtool_cmd *cmd)
  664. {
  665. struct ethtool_cmd diff1 = *cmd;
  666. struct ethtool_cmd diff2 = {};
  667. ethtool_cmd_speed_set(&diff1, 0);
  668. diff1.duplex = 0;
  669. /* advertising and cmd are usually set */
  670. diff1.advertising = 0;
  671. diff1.cmd = 0;
  672. /* We set port to PORT_OTHER */
  673. diff2.port = PORT_OTHER;
  674. return !memcmp(&diff1, &diff2, sizeof(diff1));
  675. }
  676. static void netvsc_init_settings(struct net_device *dev)
  677. {
  678. struct net_device_context *ndc = netdev_priv(dev);
  679. ndc->speed = SPEED_UNKNOWN;
  680. ndc->duplex = DUPLEX_UNKNOWN;
  681. }
  682. static int netvsc_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  683. {
  684. struct net_device_context *ndc = netdev_priv(dev);
  685. ethtool_cmd_speed_set(cmd, ndc->speed);
  686. cmd->duplex = ndc->duplex;
  687. cmd->port = PORT_OTHER;
  688. return 0;
  689. }
  690. static int netvsc_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  691. {
  692. struct net_device_context *ndc = netdev_priv(dev);
  693. u32 speed;
  694. speed = ethtool_cmd_speed(cmd);
  695. if (!ethtool_validate_speed(speed) ||
  696. !ethtool_validate_duplex(cmd->duplex) ||
  697. !netvsc_validate_ethtool_ss_cmd(cmd))
  698. return -EINVAL;
  699. ndc->speed = speed;
  700. ndc->duplex = cmd->duplex;
  701. return 0;
  702. }
  703. static int netvsc_change_mtu(struct net_device *ndev, int mtu)
  704. {
  705. struct net_device_context *ndevctx = netdev_priv(ndev);
  706. struct hv_device *hdev = ndevctx->device_ctx;
  707. struct netvsc_device *nvdev = hv_get_drvdata(hdev);
  708. struct netvsc_device_info device_info;
  709. int limit = ETH_DATA_LEN;
  710. u32 num_chn;
  711. int ret = 0;
  712. if (nvdev == NULL || nvdev->destroy)
  713. return -ENODEV;
  714. if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)
  715. limit = NETVSC_MTU - ETH_HLEN;
  716. if (mtu < NETVSC_MTU_MIN || mtu > limit)
  717. return -EINVAL;
  718. ret = netvsc_close(ndev);
  719. if (ret)
  720. goto out;
  721. num_chn = nvdev->num_chn;
  722. nvdev->start_remove = true;
  723. rndis_filter_device_remove(hdev);
  724. ndev->mtu = mtu;
  725. ndevctx->device_ctx = hdev;
  726. hv_set_drvdata(hdev, ndev);
  727. memset(&device_info, 0, sizeof(device_info));
  728. device_info.ring_size = ring_size;
  729. device_info.num_chn = num_chn;
  730. device_info.max_num_vrss_chns = max_num_vrss_chns;
  731. rndis_filter_device_add(hdev, &device_info);
  732. out:
  733. netvsc_open(ndev);
  734. return ret;
  735. }
  736. static struct rtnl_link_stats64 *netvsc_get_stats64(struct net_device *net,
  737. struct rtnl_link_stats64 *t)
  738. {
  739. struct net_device_context *ndev_ctx = netdev_priv(net);
  740. int cpu;
  741. for_each_possible_cpu(cpu) {
  742. struct netvsc_stats *tx_stats = per_cpu_ptr(ndev_ctx->tx_stats,
  743. cpu);
  744. struct netvsc_stats *rx_stats = per_cpu_ptr(ndev_ctx->rx_stats,
  745. cpu);
  746. u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
  747. unsigned int start;
  748. do {
  749. start = u64_stats_fetch_begin_irq(&tx_stats->syncp);
  750. tx_packets = tx_stats->packets;
  751. tx_bytes = tx_stats->bytes;
  752. } while (u64_stats_fetch_retry_irq(&tx_stats->syncp, start));
  753. do {
  754. start = u64_stats_fetch_begin_irq(&rx_stats->syncp);
  755. rx_packets = rx_stats->packets;
  756. rx_bytes = rx_stats->bytes;
  757. } while (u64_stats_fetch_retry_irq(&rx_stats->syncp, start));
  758. t->tx_bytes += tx_bytes;
  759. t->tx_packets += tx_packets;
  760. t->rx_bytes += rx_bytes;
  761. t->rx_packets += rx_packets;
  762. }
  763. t->tx_dropped = net->stats.tx_dropped;
  764. t->tx_errors = net->stats.tx_dropped;
  765. t->rx_dropped = net->stats.rx_dropped;
  766. t->rx_errors = net->stats.rx_errors;
  767. return t;
  768. }
  769. static int netvsc_set_mac_addr(struct net_device *ndev, void *p)
  770. {
  771. struct net_device_context *ndevctx = netdev_priv(ndev);
  772. struct hv_device *hdev = ndevctx->device_ctx;
  773. struct sockaddr *addr = p;
  774. char save_adr[ETH_ALEN];
  775. unsigned char save_aatype;
  776. int err;
  777. memcpy(save_adr, ndev->dev_addr, ETH_ALEN);
  778. save_aatype = ndev->addr_assign_type;
  779. err = eth_mac_addr(ndev, p);
  780. if (err != 0)
  781. return err;
  782. err = rndis_filter_set_device_mac(hdev, addr->sa_data);
  783. if (err != 0) {
  784. /* roll back to saved MAC */
  785. memcpy(ndev->dev_addr, save_adr, ETH_ALEN);
  786. ndev->addr_assign_type = save_aatype;
  787. }
  788. return err;
  789. }
  790. #ifdef CONFIG_NET_POLL_CONTROLLER
  791. static void netvsc_poll_controller(struct net_device *net)
  792. {
  793. /* As netvsc_start_xmit() works synchronous we don't have to
  794. * trigger anything here.
  795. */
  796. }
  797. #endif
  798. static const struct ethtool_ops ethtool_ops = {
  799. .get_drvinfo = netvsc_get_drvinfo,
  800. .get_link = ethtool_op_get_link,
  801. .get_channels = netvsc_get_channels,
  802. .set_channels = netvsc_set_channels,
  803. .get_ts_info = ethtool_op_get_ts_info,
  804. .get_settings = netvsc_get_settings,
  805. .set_settings = netvsc_set_settings,
  806. };
  807. static const struct net_device_ops device_ops = {
  808. .ndo_open = netvsc_open,
  809. .ndo_stop = netvsc_close,
  810. .ndo_start_xmit = netvsc_start_xmit,
  811. .ndo_set_rx_mode = netvsc_set_multicast_list,
  812. .ndo_change_mtu = netvsc_change_mtu,
  813. .ndo_validate_addr = eth_validate_addr,
  814. .ndo_set_mac_address = netvsc_set_mac_addr,
  815. .ndo_select_queue = netvsc_select_queue,
  816. .ndo_get_stats64 = netvsc_get_stats64,
  817. #ifdef CONFIG_NET_POLL_CONTROLLER
  818. .ndo_poll_controller = netvsc_poll_controller,
  819. #endif
  820. };
  821. /*
  822. * Handle link status changes. For RNDIS_STATUS_NETWORK_CHANGE emulate link
  823. * down/up sequence. In case of RNDIS_STATUS_MEDIA_CONNECT when carrier is
  824. * present send GARP packet to network peers with netif_notify_peers().
  825. */
  826. static void netvsc_link_change(struct work_struct *w)
  827. {
  828. struct net_device_context *ndev_ctx;
  829. struct net_device *net;
  830. struct netvsc_device *net_device;
  831. struct rndis_device *rdev;
  832. struct netvsc_reconfig *event = NULL;
  833. bool notify = false, reschedule = false;
  834. unsigned long flags, next_reconfig, delay;
  835. ndev_ctx = container_of(w, struct net_device_context, dwork.work);
  836. net_device = hv_get_drvdata(ndev_ctx->device_ctx);
  837. rdev = net_device->extension;
  838. net = net_device->ndev;
  839. next_reconfig = ndev_ctx->last_reconfig + LINKCHANGE_INT;
  840. if (time_is_after_jiffies(next_reconfig)) {
  841. /* link_watch only sends one notification with current state
  842. * per second, avoid doing reconfig more frequently. Handle
  843. * wrap around.
  844. */
  845. delay = next_reconfig - jiffies;
  846. delay = delay < LINKCHANGE_INT ? delay : LINKCHANGE_INT;
  847. schedule_delayed_work(&ndev_ctx->dwork, delay);
  848. return;
  849. }
  850. ndev_ctx->last_reconfig = jiffies;
  851. spin_lock_irqsave(&ndev_ctx->lock, flags);
  852. if (!list_empty(&ndev_ctx->reconfig_events)) {
  853. event = list_first_entry(&ndev_ctx->reconfig_events,
  854. struct netvsc_reconfig, list);
  855. list_del(&event->list);
  856. reschedule = !list_empty(&ndev_ctx->reconfig_events);
  857. }
  858. spin_unlock_irqrestore(&ndev_ctx->lock, flags);
  859. if (!event)
  860. return;
  861. rtnl_lock();
  862. switch (event->event) {
  863. /* Only the following events are possible due to the check in
  864. * netvsc_linkstatus_callback()
  865. */
  866. case RNDIS_STATUS_MEDIA_CONNECT:
  867. if (rdev->link_state) {
  868. rdev->link_state = false;
  869. netif_carrier_on(net);
  870. netif_tx_wake_all_queues(net);
  871. } else {
  872. notify = true;
  873. }
  874. kfree(event);
  875. break;
  876. case RNDIS_STATUS_MEDIA_DISCONNECT:
  877. if (!rdev->link_state) {
  878. rdev->link_state = true;
  879. netif_carrier_off(net);
  880. netif_tx_stop_all_queues(net);
  881. }
  882. kfree(event);
  883. break;
  884. case RNDIS_STATUS_NETWORK_CHANGE:
  885. /* Only makes sense if carrier is present */
  886. if (!rdev->link_state) {
  887. rdev->link_state = true;
  888. netif_carrier_off(net);
  889. netif_tx_stop_all_queues(net);
  890. event->event = RNDIS_STATUS_MEDIA_CONNECT;
  891. spin_lock_irqsave(&ndev_ctx->lock, flags);
  892. list_add_tail(&event->list, &ndev_ctx->reconfig_events);
  893. spin_unlock_irqrestore(&ndev_ctx->lock, flags);
  894. reschedule = true;
  895. }
  896. break;
  897. }
  898. rtnl_unlock();
  899. if (notify)
  900. netdev_notify_peers(net);
  901. /* link_watch only sends one notification with current state per
  902. * second, handle next reconfig event in 2 seconds.
  903. */
  904. if (reschedule)
  905. schedule_delayed_work(&ndev_ctx->dwork, LINKCHANGE_INT);
  906. }
  907. static void netvsc_free_netdev(struct net_device *netdev)
  908. {
  909. struct net_device_context *net_device_ctx = netdev_priv(netdev);
  910. free_percpu(net_device_ctx->tx_stats);
  911. free_percpu(net_device_ctx->rx_stats);
  912. free_netdev(netdev);
  913. }
  914. static int netvsc_probe(struct hv_device *dev,
  915. const struct hv_vmbus_device_id *dev_id)
  916. {
  917. struct net_device *net = NULL;
  918. struct net_device_context *net_device_ctx;
  919. struct netvsc_device_info device_info;
  920. struct netvsc_device *nvdev;
  921. int ret;
  922. net = alloc_etherdev_mq(sizeof(struct net_device_context),
  923. num_online_cpus());
  924. if (!net)
  925. return -ENOMEM;
  926. netif_carrier_off(net);
  927. net_device_ctx = netdev_priv(net);
  928. net_device_ctx->device_ctx = dev;
  929. net_device_ctx->msg_enable = netif_msg_init(debug, default_msg);
  930. if (netif_msg_probe(net_device_ctx))
  931. netdev_dbg(net, "netvsc msg_enable: %d\n",
  932. net_device_ctx->msg_enable);
  933. net_device_ctx->tx_stats = netdev_alloc_pcpu_stats(struct netvsc_stats);
  934. if (!net_device_ctx->tx_stats) {
  935. free_netdev(net);
  936. return -ENOMEM;
  937. }
  938. net_device_ctx->rx_stats = netdev_alloc_pcpu_stats(struct netvsc_stats);
  939. if (!net_device_ctx->rx_stats) {
  940. free_percpu(net_device_ctx->tx_stats);
  941. free_netdev(net);
  942. return -ENOMEM;
  943. }
  944. hv_set_drvdata(dev, net);
  945. INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change);
  946. INIT_WORK(&net_device_ctx->work, do_set_multicast);
  947. spin_lock_init(&net_device_ctx->lock);
  948. INIT_LIST_HEAD(&net_device_ctx->reconfig_events);
  949. net->netdev_ops = &device_ops;
  950. net->hw_features = NETVSC_HW_FEATURES;
  951. net->features = NETVSC_HW_FEATURES | NETIF_F_HW_VLAN_CTAG_TX;
  952. net->ethtool_ops = &ethtool_ops;
  953. SET_NETDEV_DEV(net, &dev->device);
  954. /* We always need headroom for rndis header */
  955. net->needed_headroom = RNDIS_AND_PPI_SIZE;
  956. /* Notify the netvsc driver of the new device */
  957. memset(&device_info, 0, sizeof(device_info));
  958. device_info.ring_size = ring_size;
  959. device_info.max_num_vrss_chns = max_num_vrss_chns;
  960. ret = rndis_filter_device_add(dev, &device_info);
  961. if (ret != 0) {
  962. netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
  963. netvsc_free_netdev(net);
  964. hv_set_drvdata(dev, NULL);
  965. return ret;
  966. }
  967. memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
  968. nvdev = hv_get_drvdata(dev);
  969. netif_set_real_num_tx_queues(net, nvdev->num_chn);
  970. netif_set_real_num_rx_queues(net, nvdev->num_chn);
  971. netvsc_init_settings(net);
  972. ret = register_netdev(net);
  973. if (ret != 0) {
  974. pr_err("Unable to register netdev.\n");
  975. rndis_filter_device_remove(dev);
  976. netvsc_free_netdev(net);
  977. }
  978. return ret;
  979. }
  980. static int netvsc_remove(struct hv_device *dev)
  981. {
  982. struct net_device *net;
  983. struct net_device_context *ndev_ctx;
  984. struct netvsc_device *net_device;
  985. net_device = hv_get_drvdata(dev);
  986. net = net_device->ndev;
  987. if (net == NULL) {
  988. dev_err(&dev->device, "No net device to remove\n");
  989. return 0;
  990. }
  991. net_device->start_remove = true;
  992. ndev_ctx = netdev_priv(net);
  993. cancel_delayed_work_sync(&ndev_ctx->dwork);
  994. cancel_work_sync(&ndev_ctx->work);
  995. /* Stop outbound asap */
  996. netif_tx_disable(net);
  997. unregister_netdev(net);
  998. /*
  999. * Call to the vsc driver to let it know that the device is being
  1000. * removed
  1001. */
  1002. rndis_filter_device_remove(dev);
  1003. netvsc_free_netdev(net);
  1004. return 0;
  1005. }
  1006. static const struct hv_vmbus_device_id id_table[] = {
  1007. /* Network guid */
  1008. { HV_NIC_GUID, },
  1009. { },
  1010. };
  1011. MODULE_DEVICE_TABLE(vmbus, id_table);
  1012. /* The one and only one */
  1013. static struct hv_driver netvsc_drv = {
  1014. .name = KBUILD_MODNAME,
  1015. .id_table = id_table,
  1016. .probe = netvsc_probe,
  1017. .remove = netvsc_remove,
  1018. };
  1019. static void __exit netvsc_drv_exit(void)
  1020. {
  1021. vmbus_driver_unregister(&netvsc_drv);
  1022. }
  1023. static int __init netvsc_drv_init(void)
  1024. {
  1025. if (ring_size < RING_SIZE_MIN) {
  1026. ring_size = RING_SIZE_MIN;
  1027. pr_info("Increased ring_size to %d (min allowed)\n",
  1028. ring_size);
  1029. }
  1030. return vmbus_driver_register(&netvsc_drv);
  1031. }
  1032. MODULE_LICENSE("GPL");
  1033. MODULE_DESCRIPTION("Microsoft Hyper-V network driver");
  1034. module_init(netvsc_drv_init);
  1035. module_exit(netvsc_drv_exit);