xref: /freebsd/sys/dev/hyperv/netvsc/hn_nvs.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 /*-
2  * Copyright (c) 2009-2012,2016-2017 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 
29 #ifndef _HN_NVS_H_
30 #define _HN_NVS_H_
31 
32 struct hn_nvs_sendctx;
33 struct vmbus_channel;
34 struct hn_softc;
35 
36 typedef void		(*hn_nvs_sent_t)
37 			(struct hn_nvs_sendctx *, struct hn_softc *,
38 			 struct vmbus_channel *, const void *, int);
39 
40 struct hn_nvs_sendctx {
41 	hn_nvs_sent_t	hn_cb;
42 	void		*hn_cbarg;
43 };
44 
45 #define HN_NVS_SENDCTX_INITIALIZER(cb, cbarg)	\
46 {						\
47 	.hn_cb		= cb,			\
48 	.hn_cbarg	= cbarg			\
49 }
50 
51 static __inline void
52 hn_nvs_sendctx_init(struct hn_nvs_sendctx *sndc, hn_nvs_sent_t cb, void *cbarg)
53 {
54 
55 	sndc->hn_cb = cb;
56 	sndc->hn_cbarg = cbarg;
57 }
58 
59 static __inline int
60 hn_nvs_send(struct vmbus_channel *chan, uint16_t flags,
61     void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc)
62 {
63 
64 	return (vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, flags,
65 	    nvs_msg, nvs_msglen, (uint64_t)(uintptr_t)sndc));
66 }
67 
68 static __inline int
69 hn_nvs_send_sglist(struct vmbus_channel *chan, struct vmbus_gpa sg[], int sglen,
70     void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc)
71 {
72 
73 	return (vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen,
74 	    (uint64_t)(uintptr_t)sndc));
75 }
76 
77 static __inline int
78 hn_nvs_send_rndis_sglist(struct vmbus_channel *chan, uint32_t rndis_mtype,
79     struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt)
80 {
81 	struct hn_nvs_rndis rndis;
82 
83 	rndis.nvs_type = HN_NVS_TYPE_RNDIS;
84 	rndis.nvs_rndis_mtype = rndis_mtype;
85 	rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID;
86 	rndis.nvs_chim_sz = 0;
87 
88 	return (hn_nvs_send_sglist(chan, gpa, gpa_cnt,
89 	    &rndis, sizeof(rndis), sndc));
90 }
91 
92 int		hn_nvs_attach(struct hn_softc *sc, int mtu);
93 void		hn_nvs_detach(struct hn_softc *sc);
94 int		hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch);
95 void		hn_nvs_sent_xact(struct hn_nvs_sendctx *sndc,
96 		    struct hn_softc *sc, struct vmbus_channel *chan,
97 		    const void *data, int dlen);
98 int		hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan,
99 		    struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa,
100 		    int gpa_cnt);
101 void		hn_nvs_set_datapath(struct hn_softc *sc, uint32_t path);
102 
103 extern struct hn_nvs_sendctx	hn_nvs_sendctx_none;
104 
105 #endif  /* !_HN_NVS_H_ */
106