New upstream version 18.08
[deb_dpdk.git] / drivers / net / netvsc / hn_nvs.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2018 Microsoft Corp.
3  * All rights reserved.
4  */
5
6 /*
7  * The indirection table message is the largest message
8  * received from host, and that is 112 bytes.
9  */
10 #define NVS_RESPSIZE_MAX        256
11
12 /*
13  * NDIS protocol version numbers
14  */
15 #define NDIS_VERSION_6_1                0x00060001
16 #define NDIS_VERSION_6_20               0x00060014
17 #define NDIS_VERSION_6_30               0x0006001e
18 #define NDIS_VERSION_MAJOR(ver) (((ver) & 0xffff0000) >> 16)
19 #define NDIS_VERSION_MINOR(ver) ((ver) & 0xffff)
20
21 /*
22  * NVS versions.
23  */
24 #define NVS_VERSION_1           0x00002
25 #define NVS_VERSION_2           0x30002
26 #define NVS_VERSION_4           0x40000
27 #define NVS_VERSION_5           0x50000
28 #define NVS_VERSION_6           0x60000
29 #define NVS_VERSION_61          0x60001
30
31 #define NVS_RXBUF_SIG           0xcafe
32 #define NVS_CHIM_SIG                    0xface
33
34 #define NVS_CHIM_IDX_INVALID            0xffffffff
35
36 #define NVS_RNDIS_MTYPE_DATA            0
37 #define NVS_RNDIS_MTYPE_CTRL            1
38
39 /*
40  * NVS message transacion status codes.
41  */
42 #define NVS_STATUS_OK           1
43 #define NVS_STATUS_FAILED               2
44
45 /*
46  * NVS request/response message types.
47  */
48 #define NVS_TYPE_INIT           1
49 #define NVS_TYPE_INIT_RESP      2
50
51 #define NVS_TYPE_NDIS_INIT      100
52 #define NVS_TYPE_RXBUF_CONN     101
53 #define NVS_TYPE_RXBUF_CONNRESP 102
54 #define NVS_TYPE_RXBUF_DISCONN  103
55 #define NVS_TYPE_CHIM_CONN      104
56 #define NVS_TYPE_CHIM_CONNRESP  105
57 #define NVS_TYPE_CHIM_DISCONN   106
58 #define NVS_TYPE_RNDIS          107
59 #define NVS_TYPE_RNDIS_ACK      108
60
61 #define NVS_TYPE_NDIS_CONF      125
62 #define NVS_TYPE_VFASSOC_NOTE   128     /* notification */
63 #define NVS_TYPE_SET_DATAPATH   129
64 #define NVS_TYPE_SUBCH_REQ      133
65 #define NVS_TYPE_SUBCH_RESP     133     /* same as SUBCH_REQ */
66 #define NVS_TYPE_TXTBL_NOTE     134     /* notification */
67
68
69 /* NVS message common header */
70 struct hn_nvs_hdr {
71         uint32_t        type;
72 } __rte_packed;
73
74 struct hn_nvs_init {
75         uint32_t        type;   /* NVS_TYPE_INIT */
76         uint32_t        ver_min;
77         uint32_t        ver_max;
78         uint8_t         rsvd[28];
79 } __rte_packed;
80
81 struct hn_nvs_init_resp {
82         uint32_t        type;   /* NVS_TYPE_INIT_RESP */
83         uint32_t        ver;    /* deprecated */
84         uint32_t        rsvd;
85         uint32_t        status; /* NVS_STATUS_ */
86 } __rte_packed;
87
88 /* No response */
89 struct hn_nvs_ndis_conf {
90         uint32_t        type;   /* NVS_TYPE_NDIS_CONF */
91         uint32_t        mtu;
92         uint32_t        rsvd;
93         uint64_t        caps;   /* NVS_NDIS_CONF_ */
94         uint8_t         rsvd1[20];
95 } __rte_packed;
96
97 #define NVS_NDIS_CONF_SRIOV             0x0004
98 #define NVS_NDIS_CONF_VLAN              0x0008
99
100 /* No response */
101 struct hn_nvs_ndis_init {
102         uint32_t        type;   /* NVS_TYPE_NDIS_INIT */
103         uint32_t        ndis_major;     /* NDIS_VERSION_MAJOR_ */
104         uint32_t        ndis_minor;     /* NDIS_VERSION_MINOR_ */
105         uint8_t         rsvd[28];
106 } __rte_packed;
107
108 #define NVS_DATAPATH_SYNTHETIC  0
109 #define NVS_DATAPATH_VF         1
110
111 /* No response */
112 struct hn_nvs_datapath {
113         uint32_t        type;   /* NVS_TYPE_SET_DATAPATH */
114         uint32_t        active_path;/* NVS_DATAPATH_* */
115         uint8_t         rsvd[32];
116 } __rte_packed;
117
118 struct hn_nvs_rxbuf_conn {
119         uint32_t        type;   /* NVS_TYPE_RXBUF_CONN */
120         uint32_t        gpadl;  /* RXBUF vmbus GPADL */
121         uint16_t        sig;    /* NVS_RXBUF_SIG */
122         uint8_t         rsvd[30];
123 } __rte_packed;
124
125 struct hn_nvs_rxbuf_sect {
126         uint32_t        start;
127         uint32_t        slotsz;
128         uint32_t        slotcnt;
129         uint32_t        end;
130 } __rte_packed;
131
132 struct hn_nvs_rxbuf_connresp {
133         uint32_t        type;   /* NVS_TYPE_RXBUF_CONNRESP */
134         uint32_t        status; /* NVS_STATUS_ */
135         uint32_t        nsect;  /* # of elem in nvs_sect */
136         struct hn_nvs_rxbuf_sect nvs_sect[1];
137 } __rte_packed;
138
139 /* No response */
140 struct hn_nvs_rxbuf_disconn {
141         uint32_t        type;   /* NVS_TYPE_RXBUF_DISCONN */
142         uint16_t        sig;    /* NVS_RXBUF_SIG */
143         uint8_t         rsvd[34];
144 } __rte_packed;
145
146 struct hn_nvs_chim_conn {
147         uint32_t        type;   /* NVS_TYPE_CHIM_CONN */
148         uint32_t        gpadl;  /* chimney buf vmbus GPADL */
149         uint16_t        sig;    /* NDIS_NVS_CHIM_SIG */
150         uint8_t         rsvd[30];
151 } __rte_packed;
152
153 struct hn_nvs_chim_connresp {
154         uint32_t        type;   /* NVS_TYPE_CHIM_CONNRESP */
155         uint32_t        status; /* NVS_STATUS_ */
156         uint32_t        sectsz; /* section size */
157 } __rte_packed;
158
159 /* No response */
160 struct hn_nvs_chim_disconn {
161         uint32_t        type;   /* NVS_TYPE_CHIM_DISCONN */
162         uint16_t        sig;    /* NVS_CHIM_SIG */
163         uint8_t         rsvd[34];
164 } __rte_packed;
165
166 #define NVS_SUBCH_OP_ALLOC              1
167
168 struct hn_nvs_subch_req {
169         uint32_t        type;   /* NVS_TYPE_SUBCH_REQ */
170         uint32_t        op;     /* NVS_SUBCH_OP_ */
171         uint32_t        nsubch;
172         uint8_t         rsvd[28];
173 } __rte_packed;
174
175 struct hn_nvs_subch_resp {
176         uint32_t        type;   /* NVS_TYPE_SUBCH_RESP */
177         uint32_t        status; /* NVS_STATUS_ */
178         uint32_t        nsubch;
179         uint8_t         rsvd[28];
180 } __rte_packed;
181
182 struct hn_nvs_rndis {
183         uint32_t        type;   /* NVS_TYPE_RNDIS */
184         uint32_t        rndis_mtype;/* NVS_RNDIS_MTYPE_ */
185         /*
186          * Chimney sending buffer index and size.
187          *
188          * NOTE:
189          * If nvs_chim_idx is set to NVS_CHIM_IDX_INVALID
190          * and nvs_chim_sz is set to 0, then chimney sending
191          * buffer is _not_ used by this RNDIS message.
192          */
193         uint32_t        chim_idx;
194         uint32_t        chim_sz;
195         uint8_t         rsvd[24];
196 } __rte_packed;
197
198 struct hn_nvs_rndis_ack {
199         uint32_t        type;   /* NVS_TYPE_RNDIS_ACK */
200         uint32_t        status; /* NVS_STATUS_ */
201         uint8_t         rsvd[32];
202 } __rte_packed;
203
204
205 int     hn_nvs_attach(struct hn_data *hv, unsigned int mtu);
206 void    hn_nvs_detach(struct hn_data *hv);
207 void    hn_nvs_ack_rxbuf(struct vmbus_channel *chan, uint64_t tid);
208 int     hn_nvs_alloc_subchans(struct hn_data *hv, uint32_t *nsubch);
209 void    hn_nvs_set_datapath(struct hn_data *hv, uint32_t path);
210
211 static inline int
212 hn_nvs_send(struct vmbus_channel *chan, uint16_t flags,
213             void *nvs_msg, int nvs_msglen, uintptr_t sndc,
214             bool *need_sig)
215 {
216         return rte_vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND,
217                                    nvs_msg, nvs_msglen, (uint64_t)sndc,
218                                    flags, need_sig);
219 }
220
221 static inline int
222 hn_nvs_send_sglist(struct vmbus_channel *chan,
223                    struct vmbus_gpa sg[], unsigned int sglen,
224                    void *nvs_msg, int nvs_msglen,
225                    uintptr_t sndc, bool *need_sig)
226 {
227         return rte_vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen,
228                                           (uint64_t)sndc, need_sig);
229 }