netvsc_drv.c 32 KB

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