xref: /freebsd/sys/dev/hyperv/netvsc/hn_nvs.h (revision 5bdfd3fd36524e05c97cffbc70cf07c894858786)
1e61005feSSepherosa Ziehau /*-
2e61005feSSepherosa Ziehau  * Copyright (c) 2009-2012,2016 Microsoft Corp.
3e61005feSSepherosa Ziehau  * Copyright (c) 2010-2012 Citrix Inc.
4e61005feSSepherosa Ziehau  * Copyright (c) 2012 NetApp Inc.
5e61005feSSepherosa Ziehau  * All rights reserved.
6e61005feSSepherosa Ziehau  *
7e61005feSSepherosa Ziehau  * Redistribution and use in source and binary forms, with or without
8e61005feSSepherosa Ziehau  * modification, are permitted provided that the following conditions
9e61005feSSepherosa Ziehau  * are met:
10e61005feSSepherosa Ziehau  * 1. Redistributions of source code must retain the above copyright
11e61005feSSepherosa Ziehau  *    notice unmodified, this list of conditions, and the following
12e61005feSSepherosa Ziehau  *    disclaimer.
13e61005feSSepherosa Ziehau  * 2. Redistributions in binary form must reproduce the above copyright
14e61005feSSepherosa Ziehau  *    notice, this list of conditions and the following disclaimer in the
15e61005feSSepherosa Ziehau  *    documentation and/or other materials provided with the distribution.
16e61005feSSepherosa Ziehau  *
17e61005feSSepherosa Ziehau  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18e61005feSSepherosa Ziehau  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19e61005feSSepherosa Ziehau  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20e61005feSSepherosa Ziehau  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21e61005feSSepherosa Ziehau  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22e61005feSSepherosa Ziehau  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23e61005feSSepherosa Ziehau  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24e61005feSSepherosa Ziehau  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25e61005feSSepherosa Ziehau  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26e61005feSSepherosa Ziehau  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27e61005feSSepherosa Ziehau  *
28e61005feSSepherosa Ziehau  * $FreeBSD$
29e61005feSSepherosa Ziehau  */
30e61005feSSepherosa Ziehau 
31e61005feSSepherosa Ziehau #ifndef _HN_NVS_H_
32e61005feSSepherosa Ziehau #define _HN_NVS_H_
33e61005feSSepherosa Ziehau 
34e61005feSSepherosa Ziehau struct hn_nvs_sendctx;
35e61005feSSepherosa Ziehau struct vmbus_channel;
36e61005feSSepherosa Ziehau struct hn_softc;
37e61005feSSepherosa Ziehau 
38e61005feSSepherosa Ziehau typedef void		(*hn_nvs_sent_t)
39e61005feSSepherosa Ziehau 			(struct hn_nvs_sendctx *, struct hn_softc *,
40e61005feSSepherosa Ziehau 			 struct vmbus_channel *, const void *, int);
41e61005feSSepherosa Ziehau 
42e61005feSSepherosa Ziehau struct hn_nvs_sendctx {
43e61005feSSepherosa Ziehau 	hn_nvs_sent_t	hn_cb;
44e61005feSSepherosa Ziehau 	void		*hn_cbarg;
45e61005feSSepherosa Ziehau };
46e61005feSSepherosa Ziehau 
47e61005feSSepherosa Ziehau #define HN_NVS_SENDCTX_INITIALIZER(cb, cbarg)	\
48e61005feSSepherosa Ziehau {						\
49e61005feSSepherosa Ziehau 	.hn_cb		= cb,			\
50e61005feSSepherosa Ziehau 	.hn_cbarg	= cbarg			\
51e61005feSSepherosa Ziehau }
52e61005feSSepherosa Ziehau 
53e61005feSSepherosa Ziehau static __inline void
54e61005feSSepherosa Ziehau hn_nvs_sendctx_init(struct hn_nvs_sendctx *sndc, hn_nvs_sent_t cb, void *cbarg)
55e61005feSSepherosa Ziehau {
56e61005feSSepherosa Ziehau 
57e61005feSSepherosa Ziehau 	sndc->hn_cb = cb;
58e61005feSSepherosa Ziehau 	sndc->hn_cbarg = cbarg;
59e61005feSSepherosa Ziehau }
60e61005feSSepherosa Ziehau 
61e61005feSSepherosa Ziehau static __inline int
62e61005feSSepherosa Ziehau hn_nvs_send(struct vmbus_channel *chan, uint16_t flags,
63e61005feSSepherosa Ziehau     void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc)
64e61005feSSepherosa Ziehau {
65e61005feSSepherosa Ziehau 
66e61005feSSepherosa Ziehau 	return (vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, flags,
67e61005feSSepherosa Ziehau 	    nvs_msg, nvs_msglen, (uint64_t)(uintptr_t)sndc));
68e61005feSSepherosa Ziehau }
69e61005feSSepherosa Ziehau 
70e61005feSSepherosa Ziehau static __inline int
71e61005feSSepherosa Ziehau hn_nvs_send_sglist(struct vmbus_channel *chan, struct vmbus_gpa sg[], int sglen,
72e61005feSSepherosa Ziehau     void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc)
73e61005feSSepherosa Ziehau {
74e61005feSSepherosa Ziehau 
75e61005feSSepherosa Ziehau 	return (vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen,
76e61005feSSepherosa Ziehau 	    (uint64_t)(uintptr_t)sndc));
77e61005feSSepherosa Ziehau }
78e61005feSSepherosa Ziehau 
79e61005feSSepherosa Ziehau static __inline int
80e61005feSSepherosa Ziehau hn_nvs_send_rndis_sglist(struct vmbus_channel *chan, uint32_t rndis_mtype,
81e61005feSSepherosa Ziehau     struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt)
82e61005feSSepherosa Ziehau {
83e61005feSSepherosa Ziehau 	struct hn_nvs_rndis rndis;
84e61005feSSepherosa Ziehau 
85e61005feSSepherosa Ziehau 	rndis.nvs_type = HN_NVS_TYPE_RNDIS;
86e61005feSSepherosa Ziehau 	rndis.nvs_rndis_mtype = rndis_mtype;
87e61005feSSepherosa Ziehau 	rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID;
88e61005feSSepherosa Ziehau 	rndis.nvs_chim_sz = 0;
89e61005feSSepherosa Ziehau 
90e61005feSSepherosa Ziehau 	return (hn_nvs_send_sglist(chan, gpa, gpa_cnt,
91e61005feSSepherosa Ziehau 	    &rndis, sizeof(rndis), sndc));
92e61005feSSepherosa Ziehau }
93e61005feSSepherosa Ziehau 
94e61005feSSepherosa Ziehau int		hn_nvs_attach(struct hn_softc *sc, int mtu);
95e61005feSSepherosa Ziehau void		hn_nvs_detach(struct hn_softc *sc);
96e61005feSSepherosa Ziehau int		hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch);
97e61005feSSepherosa Ziehau void		hn_nvs_sent_xact(struct hn_nvs_sendctx *sndc,
98e61005feSSepherosa Ziehau 		    struct hn_softc *sc, struct vmbus_channel *chan,
99e61005feSSepherosa Ziehau 		    const void *data, int dlen);
100e61005feSSepherosa Ziehau int		hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan,
101e61005feSSepherosa Ziehau 		    struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa,
102e61005feSSepherosa Ziehau 		    int gpa_cnt);
103*5bdfd3fdSDexuan Cui void		hn_nvs_set_datapath(struct hn_softc *sc, uint32_t path);
104e61005feSSepherosa Ziehau 
105e61005feSSepherosa Ziehau extern struct hn_nvs_sendctx	hn_nvs_sendctx_none;
106e61005feSSepherosa Ziehau 
107e61005feSSepherosa Ziehau #endif  /* !_HN_NVS_H_ */
108