hn_nvs.c revision 307202
1/*-
2 * Copyright (c) 2009-2012,2016 Microsoft Corp.
3 * Copyright (c) 2010-2012 Citrix Inc.
4 * Copyright (c) 2012 NetApp Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice unmodified, this list of conditions, and the following
12 *    disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c 307202 2016-10-13 08:06:49Z sephe $
29 */
30
31/**
32 * HyperV vmbus network VSC (virtual services client) module
33 *
34 */
35
36
37#include <sys/param.h>
38#include <sys/kernel.h>
39#include <sys/socket.h>
40#include <sys/limits.h>
41#include <sys/lock.h>
42#include <net/if.h>
43#include <net/if_arp.h>
44#include <machine/bus.h>
45#include <machine/atomic.h>
46
47#include <dev/hyperv/include/hyperv.h>
48#include <dev/hyperv/include/vmbus_xact.h>
49#include <dev/hyperv/netvsc/hv_net_vsc.h>
50#include <dev/hyperv/netvsc/hv_rndis_filter.h>
51#include <dev/hyperv/netvsc/if_hnreg.h>
52#include <dev/hyperv/netvsc/if_hnvar.h>
53
54MALLOC_DEFINE(M_NETVSC, "netvsc", "Hyper-V netvsc driver");
55
56/*
57 * Forward declarations
58 */
59static int  hv_nv_init_send_buffer_with_net_vsp(struct hn_softc *sc);
60static int  hv_nv_init_rx_buffer_with_net_vsp(struct hn_softc *);
61static int  hv_nv_destroy_send_buffer(struct hn_softc *sc);
62static int  hv_nv_destroy_rx_buffer(struct hn_softc *sc);
63static int  hv_nv_connect_to_vsp(struct hn_softc *sc, int mtu);
64static void hn_nvs_sent_none(struct hn_send_ctx *sndc,
65    struct hn_softc *, struct vmbus_channel *chan,
66    const void *, int);
67
68struct hn_send_ctx	hn_send_ctx_none =
69    HN_SEND_CTX_INITIALIZER(hn_nvs_sent_none, NULL);
70
71static const uint32_t		hn_nvs_version[] = {
72	HN_NVS_VERSION_5,
73	HN_NVS_VERSION_4,
74	HN_NVS_VERSION_2,
75	HN_NVS_VERSION_1
76};
77
78uint32_t
79hn_chim_alloc(struct hn_softc *sc)
80{
81	int i, bmap_cnt = sc->hn_chim_bmap_cnt;
82	u_long *bmap = sc->hn_chim_bmap;
83	uint32_t ret = HN_NVS_CHIM_IDX_INVALID;
84
85	for (i = 0; i < bmap_cnt; ++i) {
86		int idx;
87
88		idx = ffsl(~bmap[i]);
89		if (idx == 0)
90			continue;
91
92		--idx; /* ffsl is 1-based */
93		KASSERT(i * LONG_BIT + idx < sc->hn_chim_cnt,
94		    ("invalid i %d and idx %d", i, idx));
95
96		if (atomic_testandset_long(&bmap[i], idx))
97			continue;
98
99		ret = i * LONG_BIT + idx;
100		break;
101	}
102	return (ret);
103}
104
105const void *
106hn_nvs_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact,
107    void *req, int reqlen, size_t *resplen0, uint32_t type)
108{
109	struct hn_send_ctx sndc;
110	size_t resplen, min_resplen = *resplen0;
111	const struct hn_nvs_hdr *hdr;
112	int error;
113
114	KASSERT(min_resplen >= sizeof(*hdr),
115	    ("invalid minimum response len %zu", min_resplen));
116
117	/*
118	 * Execute the xact setup by the caller.
119	 */
120	hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact);
121
122	vmbus_xact_activate(xact);
123	error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC,
124	    req, reqlen, &sndc);
125	if (error) {
126		vmbus_xact_deactivate(xact);
127		return (NULL);
128	}
129	hdr = vmbus_xact_wait(xact, &resplen);
130
131	/*
132	 * Check this NVS response message.
133	 */
134	if (resplen < min_resplen) {
135		if_printf(sc->hn_ifp, "invalid NVS resp len %zu\n", resplen);
136		return (NULL);
137	}
138	if (hdr->nvs_type != type) {
139		if_printf(sc->hn_ifp, "unexpected NVS resp 0x%08x, "
140		    "expect 0x%08x\n", hdr->nvs_type, type);
141		return (NULL);
142	}
143	/* All pass! */
144	*resplen0 = resplen;
145	return (hdr);
146}
147
148static __inline int
149hn_nvs_req_send(struct hn_softc *sc, void *req, int reqlen)
150{
151
152	return (hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_NONE,
153	    req, reqlen, &hn_send_ctx_none));
154}
155
156/*
157 * Net VSC initialize receive buffer with net VSP
158 *
159 * Net VSP:  Network virtual services client, also known as the
160 *     Hyper-V extensible switch and the synthetic data path.
161 */
162static int
163hv_nv_init_rx_buffer_with_net_vsp(struct hn_softc *sc)
164{
165	struct vmbus_xact *xact = NULL;
166	struct hn_nvs_rxbuf_conn *conn;
167	const struct hn_nvs_rxbuf_connresp *resp;
168	size_t resp_len;
169	uint32_t status;
170	int error, rxbuf_size;
171
172	/*
173	 * Limit RXBUF size for old NVS.
174	 */
175	if (sc->hn_nvs_ver <= HN_NVS_VERSION_2)
176		rxbuf_size = NETVSC_RECEIVE_BUFFER_SIZE_LEGACY;
177	else
178		rxbuf_size = NETVSC_RECEIVE_BUFFER_SIZE;
179
180	/*
181	 * Connect the RXBUF GPADL to the primary channel.
182	 *
183	 * NOTE:
184	 * Only primary channel has RXBUF connected to it.  Sub-channels
185	 * just share this RXBUF.
186	 */
187	error = vmbus_chan_gpadl_connect(sc->hn_prichan,
188	    sc->hn_rxbuf_dma.hv_paddr, rxbuf_size, &sc->hn_rxbuf_gpadl);
189	if (error) {
190		if_printf(sc->hn_ifp, "rxbuf gpadl connect failed: %d\n",
191		    error);
192		goto cleanup;
193	}
194
195	/*
196	 * Connect RXBUF to NVS.
197	 */
198
199	xact = vmbus_xact_get(sc->hn_xact, sizeof(*conn));
200	if (xact == NULL) {
201		if_printf(sc->hn_ifp, "no xact for nvs rxbuf conn\n");
202		error = ENXIO;
203		goto cleanup;
204	}
205	conn = vmbus_xact_req_data(xact);
206	conn->nvs_type = HN_NVS_TYPE_RXBUF_CONN;
207	conn->nvs_gpadl = sc->hn_rxbuf_gpadl;
208	conn->nvs_sig = HN_NVS_RXBUF_SIG;
209
210	resp_len = sizeof(*resp);
211	resp = hn_nvs_xact_execute(sc, xact, conn, sizeof(*conn), &resp_len,
212	    HN_NVS_TYPE_RXBUF_CONNRESP);
213	if (resp == NULL) {
214		if_printf(sc->hn_ifp, "exec rxbuf conn failed\n");
215		error = EIO;
216		goto cleanup;
217	}
218
219	status = resp->nvs_status;
220	vmbus_xact_put(xact);
221	xact = NULL;
222
223	if (status != HN_NVS_STATUS_OK) {
224		if_printf(sc->hn_ifp, "rxbuf conn failed: %x\n", status);
225		error = EIO;
226		goto cleanup;
227	}
228	sc->hn_flags |= HN_FLAG_RXBUF_CONNECTED;
229
230	return (0);
231
232cleanup:
233	if (xact != NULL)
234		vmbus_xact_put(xact);
235	hv_nv_destroy_rx_buffer(sc);
236	return (error);
237}
238
239/*
240 * Net VSC initialize send buffer with net VSP
241 */
242static int
243hv_nv_init_send_buffer_with_net_vsp(struct hn_softc *sc)
244{
245	struct vmbus_xact *xact = NULL;
246	struct hn_nvs_chim_conn *chim;
247	const struct hn_nvs_chim_connresp *resp;
248	size_t resp_len;
249	uint32_t status, sectsz;
250	int error;
251
252	/*
253	 * Connect chimney sending buffer GPADL to the primary channel.
254	 *
255	 * NOTE:
256	 * Only primary channel has chimney sending buffer connected to it.
257	 * Sub-channels just share this chimney sending buffer.
258	 */
259	error = vmbus_chan_gpadl_connect(sc->hn_prichan,
260  	    sc->hn_chim_dma.hv_paddr, NETVSC_SEND_BUFFER_SIZE,
261	    &sc->hn_chim_gpadl);
262	if (error) {
263		if_printf(sc->hn_ifp, "chimney sending buffer gpadl "
264		    "connect failed: %d\n", error);
265		goto cleanup;
266	}
267
268	/*
269	 * Connect chimney sending buffer to NVS
270	 */
271
272	xact = vmbus_xact_get(sc->hn_xact, sizeof(*chim));
273	if (xact == NULL) {
274		if_printf(sc->hn_ifp, "no xact for nvs chim conn\n");
275		error = ENXIO;
276		goto cleanup;
277	}
278	chim = vmbus_xact_req_data(xact);
279	chim->nvs_type = HN_NVS_TYPE_CHIM_CONN;
280	chim->nvs_gpadl = sc->hn_chim_gpadl;
281	chim->nvs_sig = HN_NVS_CHIM_SIG;
282
283	resp_len = sizeof(*resp);
284	resp = hn_nvs_xact_execute(sc, xact, chim, sizeof(*chim), &resp_len,
285	    HN_NVS_TYPE_CHIM_CONNRESP);
286	if (resp == NULL) {
287		if_printf(sc->hn_ifp, "exec chim conn failed\n");
288		error = EIO;
289		goto cleanup;
290	}
291
292	status = resp->nvs_status;
293	sectsz = resp->nvs_sectsz;
294	vmbus_xact_put(xact);
295	xact = NULL;
296
297	if (status != HN_NVS_STATUS_OK) {
298		if_printf(sc->hn_ifp, "chim conn failed: %x\n", status);
299		error = EIO;
300		goto cleanup;
301	}
302	if (sectsz == 0) {
303		if_printf(sc->hn_ifp, "zero chimney sending buffer "
304		    "section size\n");
305		return 0;
306	}
307
308	sc->hn_chim_szmax = sectsz;
309	sc->hn_chim_cnt = NETVSC_SEND_BUFFER_SIZE / sc->hn_chim_szmax;
310	if (NETVSC_SEND_BUFFER_SIZE % sc->hn_chim_szmax != 0) {
311		if_printf(sc->hn_ifp, "chimney sending sections are "
312		    "not properly aligned\n");
313	}
314	if (sc->hn_chim_cnt % LONG_BIT != 0) {
315		if_printf(sc->hn_ifp, "discard %d chimney sending sections\n",
316		    sc->hn_chim_cnt % LONG_BIT);
317	}
318
319	sc->hn_chim_bmap_cnt = sc->hn_chim_cnt / LONG_BIT;
320	sc->hn_chim_bmap = malloc(sc->hn_chim_bmap_cnt * sizeof(u_long),
321	    M_NETVSC, M_WAITOK | M_ZERO);
322
323	/* Done! */
324	sc->hn_flags |= HN_FLAG_CHIM_CONNECTED;
325	if (bootverbose) {
326		if_printf(sc->hn_ifp, "chimney sending buffer %d/%d\n",
327		    sc->hn_chim_szmax, sc->hn_chim_cnt);
328	}
329	return 0;
330
331cleanup:
332	if (xact != NULL)
333		vmbus_xact_put(xact);
334	hv_nv_destroy_send_buffer(sc);
335	return (error);
336}
337
338/*
339 * Net VSC destroy receive buffer
340 */
341static int
342hv_nv_destroy_rx_buffer(struct hn_softc *sc)
343{
344	int ret = 0;
345
346	if (sc->hn_flags & HN_FLAG_RXBUF_CONNECTED) {
347		struct hn_nvs_rxbuf_disconn disconn;
348
349		/*
350		 * Disconnect RXBUF from NVS.
351		 */
352		memset(&disconn, 0, sizeof(disconn));
353		disconn.nvs_type = HN_NVS_TYPE_RXBUF_DISCONN;
354		disconn.nvs_sig = HN_NVS_RXBUF_SIG;
355
356		/* NOTE: No response. */
357		ret = hn_nvs_req_send(sc, &disconn, sizeof(disconn));
358		if (ret != 0) {
359			if_printf(sc->hn_ifp,
360			    "send rxbuf disconn failed: %d\n", ret);
361			return (ret);
362		}
363		sc->hn_flags &= ~HN_FLAG_RXBUF_CONNECTED;
364	}
365
366	if (sc->hn_rxbuf_gpadl != 0) {
367		/*
368		 * Disconnect RXBUF from primary channel.
369		 */
370		ret = vmbus_chan_gpadl_disconnect(sc->hn_prichan,
371		    sc->hn_rxbuf_gpadl);
372		if (ret != 0) {
373			if_printf(sc->hn_ifp,
374			    "rxbuf disconn failed: %d\n", ret);
375			return (ret);
376		}
377		sc->hn_rxbuf_gpadl = 0;
378	}
379	return (ret);
380}
381
382/*
383 * Net VSC destroy send buffer
384 */
385static int
386hv_nv_destroy_send_buffer(struct hn_softc *sc)
387{
388	int ret = 0;
389
390	if (sc->hn_flags & HN_FLAG_CHIM_CONNECTED) {
391		struct hn_nvs_chim_disconn disconn;
392
393		/*
394		 * Disconnect chimney sending buffer from NVS.
395		 */
396		memset(&disconn, 0, sizeof(disconn));
397		disconn.nvs_type = HN_NVS_TYPE_CHIM_DISCONN;
398		disconn.nvs_sig = HN_NVS_CHIM_SIG;
399
400		/* NOTE: No response. */
401		ret = hn_nvs_req_send(sc, &disconn, sizeof(disconn));
402		if (ret != 0) {
403			if_printf(sc->hn_ifp,
404			    "send chim disconn failed: %d\n", ret);
405			return (ret);
406		}
407		sc->hn_flags &= ~HN_FLAG_CHIM_CONNECTED;
408	}
409
410	if (sc->hn_chim_gpadl != 0) {
411		/*
412		 * Disconnect chimney sending buffer from primary channel.
413		 */
414		ret = vmbus_chan_gpadl_disconnect(sc->hn_prichan,
415		    sc->hn_chim_gpadl);
416		if (ret != 0) {
417			if_printf(sc->hn_ifp,
418			    "chim disconn failed: %d\n", ret);
419			return (ret);
420		}
421		sc->hn_chim_gpadl = 0;
422	}
423
424	if (sc->hn_chim_bmap != NULL) {
425		free(sc->hn_chim_bmap, M_NETVSC);
426		sc->hn_chim_bmap = NULL;
427	}
428
429	return (ret);
430}
431
432static int
433hn_nvs_doinit(struct hn_softc *sc, uint32_t nvs_ver)
434{
435	struct vmbus_xact *xact;
436	struct hn_nvs_init *init;
437	const struct hn_nvs_init_resp *resp;
438	size_t resp_len;
439	uint32_t status;
440
441	xact = vmbus_xact_get(sc->hn_xact, sizeof(*init));
442	if (xact == NULL) {
443		if_printf(sc->hn_ifp, "no xact for nvs init\n");
444		return (ENXIO);
445	}
446	init = vmbus_xact_req_data(xact);
447	init->nvs_type = HN_NVS_TYPE_INIT;
448	init->nvs_ver_min = nvs_ver;
449	init->nvs_ver_max = nvs_ver;
450
451	resp_len = sizeof(*resp);
452	resp = hn_nvs_xact_execute(sc, xact, init, sizeof(*init), &resp_len,
453	    HN_NVS_TYPE_INIT_RESP);
454	if (resp == NULL) {
455		if_printf(sc->hn_ifp, "exec init failed\n");
456		vmbus_xact_put(xact);
457		return (EIO);
458	}
459
460	status = resp->nvs_status;
461	vmbus_xact_put(xact);
462
463	if (status != HN_NVS_STATUS_OK) {
464		if_printf(sc->hn_ifp, "nvs init failed for ver 0x%x\n",
465		    nvs_ver);
466		return (EINVAL);
467	}
468	return (0);
469}
470
471/*
472 * Configure MTU and enable VLAN.
473 */
474static int
475hn_nvs_conf_ndis(struct hn_softc *sc, int mtu)
476{
477	struct hn_nvs_ndis_conf conf;
478	int error;
479
480	memset(&conf, 0, sizeof(conf));
481	conf.nvs_type = HN_NVS_TYPE_NDIS_CONF;
482	conf.nvs_mtu = mtu;
483	conf.nvs_caps = HN_NVS_NDIS_CONF_VLAN;
484
485	/* NOTE: No response. */
486	error = hn_nvs_req_send(sc, &conf, sizeof(conf));
487	if (error)
488		if_printf(sc->hn_ifp, "send nvs ndis conf failed: %d\n", error);
489	return (error);
490}
491
492static int
493hn_nvs_init_ndis(struct hn_softc *sc)
494{
495	struct hn_nvs_ndis_init ndis;
496	int error;
497
498	memset(&ndis, 0, sizeof(ndis));
499	ndis.nvs_type = HN_NVS_TYPE_NDIS_INIT;
500	ndis.nvs_ndis_major = HN_NDIS_VERSION_MAJOR(sc->hn_ndis_ver);
501	ndis.nvs_ndis_minor = HN_NDIS_VERSION_MINOR(sc->hn_ndis_ver);
502
503	/* NOTE: No response. */
504	error = hn_nvs_req_send(sc, &ndis, sizeof(ndis));
505	if (error)
506		if_printf(sc->hn_ifp, "send nvs ndis init failed: %d\n", error);
507	return (error);
508}
509
510static int
511hn_nvs_init(struct hn_softc *sc)
512{
513	int i;
514
515	for (i = 0; i < nitems(hn_nvs_version); ++i) {
516		int error;
517
518		error = hn_nvs_doinit(sc, hn_nvs_version[i]);
519		if (!error) {
520			sc->hn_nvs_ver = hn_nvs_version[i];
521
522			/* Set NDIS version according to NVS version. */
523			sc->hn_ndis_ver = HN_NDIS_VERSION_6_30;
524			if (sc->hn_nvs_ver <= HN_NVS_VERSION_4)
525				sc->hn_ndis_ver = HN_NDIS_VERSION_6_1;
526
527			if (bootverbose) {
528				if_printf(sc->hn_ifp, "NVS version 0x%x, "
529				    "NDIS version %u.%u\n", sc->hn_nvs_ver,
530				    HN_NDIS_VERSION_MAJOR(sc->hn_ndis_ver),
531				    HN_NDIS_VERSION_MINOR(sc->hn_ndis_ver));
532			}
533			return (0);
534		}
535	}
536	if_printf(sc->hn_ifp, "no NVS available\n");
537	return (ENXIO);
538}
539
540static int
541hv_nv_connect_to_vsp(struct hn_softc *sc, int mtu)
542{
543	int ret;
544
545	/*
546	 * Initialize NVS.
547	 */
548	ret = hn_nvs_init(sc);
549	if (ret != 0)
550		return (ret);
551
552	if (sc->hn_nvs_ver >= HN_NVS_VERSION_2) {
553		/*
554		 * Configure NDIS before initializing it.
555		 */
556		ret = hn_nvs_conf_ndis(sc, mtu);
557		if (ret != 0)
558			return (ret);
559	}
560
561	/*
562	 * Initialize NDIS.
563	 */
564	ret = hn_nvs_init_ndis(sc);
565	if (ret != 0)
566		return (ret);
567
568	ret = hv_nv_init_rx_buffer_with_net_vsp(sc);
569	if (ret == 0)
570		ret = hv_nv_init_send_buffer_with_net_vsp(sc);
571	return (ret);
572}
573
574/*
575 * Net VSC disconnect from VSP
576 */
577static void
578hv_nv_disconnect_from_vsp(struct hn_softc *sc)
579{
580	hv_nv_destroy_rx_buffer(sc);
581	hv_nv_destroy_send_buffer(sc);
582}
583
584/*
585 * Net VSC on device add
586 *
587 * Callback when the device belonging to this driver is added
588 */
589int
590hv_nv_on_device_add(struct hn_softc *sc, int mtu)
591{
592
593	/*
594	 * Connect with the NetVsp
595	 */
596	return (hv_nv_connect_to_vsp(sc, mtu));
597}
598
599/*
600 * Net VSC on device remove
601 */
602int
603hv_nv_on_device_remove(struct hn_softc *sc)
604{
605
606	hv_nv_disconnect_from_vsp(sc);
607
608	/* Now, we can close the channel safely */
609
610	vmbus_chan_close(sc->hn_prichan);
611
612	return (0);
613}
614
615void
616hn_nvs_sent_xact(struct hn_send_ctx *sndc,
617    struct hn_softc *sc __unused, struct vmbus_channel *chan __unused,
618    const void *data, int dlen)
619{
620
621	vmbus_xact_wakeup(sndc->hn_cbarg, data, dlen);
622}
623
624static void
625hn_nvs_sent_none(struct hn_send_ctx *sndc __unused,
626    struct hn_softc *sc __unused, struct vmbus_channel *chan __unused,
627    const void *data __unused, int dlen __unused)
628{
629	/* EMPTY */
630}
631
632void
633hn_chim_free(struct hn_softc *sc, uint32_t chim_idx)
634{
635	u_long mask;
636	uint32_t idx;
637
638	idx = chim_idx / LONG_BIT;
639	KASSERT(idx < sc->hn_chim_bmap_cnt,
640	    ("invalid chimney index 0x%x", chim_idx));
641
642	mask = 1UL << (chim_idx % LONG_BIT);
643	KASSERT(sc->hn_chim_bmap[idx] & mask,
644	    ("index bitmap 0x%lx, chimney index %u, "
645	     "bitmap idx %d, bitmask 0x%lx",
646	     sc->hn_chim_bmap[idx], chim_idx, idx, mask));
647
648	atomic_clear_long(&sc->hn_chim_bmap[idx], mask);
649}
650
651/*
652 * Net VSC on send
653 * Sends a packet on the specified Hyper-V device.
654 * Returns 0 on success, non-zero on failure.
655 */
656int
657hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
658    struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt)
659{
660	struct hn_nvs_rndis rndis;
661	int ret;
662
663	rndis.nvs_type = HN_NVS_TYPE_RNDIS;
664	rndis.nvs_rndis_mtype = rndis_mtype;
665	rndis.nvs_chim_idx = sndc->hn_chim_idx;
666	rndis.nvs_chim_sz = sndc->hn_chim_sz;
667
668	if (gpa_cnt) {
669		ret = hn_nvs_send_sglist(chan, gpa, gpa_cnt,
670		    &rndis, sizeof(rndis), sndc);
671	} else {
672		ret = hn_nvs_send(chan, VMBUS_CHANPKT_FLAG_RC,
673		    &rndis, sizeof(rndis), sndc);
674	}
675
676	return (ret);
677}
678