xref: /freebsd/sys/dev/ice/virtchnl.h (revision 681ce946f33e75c590e97c53076e86dff1fe8f4a)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2021, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*$FreeBSD$*/
32 
33 #ifndef _VIRTCHNL_H_
34 #define _VIRTCHNL_H_
35 
36 /* Description:
37  * This header file describes the Virtual Function (VF) - Physical Function
38  * (PF) communication protocol used by the drivers for all devices starting
39  * from our 40G product line
40  *
41  * Admin queue buffer usage:
42  * desc->opcode is always aqc_opc_send_msg_to_pf
43  * flags, retval, datalen, and data addr are all used normally.
44  * The Firmware copies the cookie fields when sending messages between the
45  * PF and VF, but uses all other fields internally. Due to this limitation,
46  * we must send all messages as "indirect", i.e. using an external buffer.
47  *
48  * All the VSI indexes are relative to the VF. Each VF can have maximum of
49  * three VSIs. All the queue indexes are relative to the VSI.  Each VF can
50  * have a maximum of sixteen queues for all of its VSIs.
51  *
52  * The PF is required to return a status code in v_retval for all messages
53  * except RESET_VF, which does not require any response. The returned value
54  * is of virtchnl_status_code type, defined in the shared type.h.
55  *
56  * In general, VF driver initialization should roughly follow the order of
57  * these opcodes. The VF driver must first validate the API version of the
58  * PF driver, then request a reset, then get resources, then configure
59  * queues and interrupts. After these operations are complete, the VF
60  * driver may start its queues, optionally add MAC and VLAN filters, and
61  * process traffic.
62  */
63 
64 /* START GENERIC DEFINES
65  * Need to ensure the following enums and defines hold the same meaning and
66  * value in current and future projects
67  */
68 
69 /* Error Codes */
70 enum virtchnl_status_code {
71 	VIRTCHNL_STATUS_SUCCESS				= 0,
72 	VIRTCHNL_STATUS_ERR_PARAM			= -5,
73 	VIRTCHNL_STATUS_ERR_NO_MEMORY			= -18,
74 	VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH		= -38,
75 	VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR		= -39,
76 	VIRTCHNL_STATUS_ERR_INVALID_VF_ID		= -40,
77 	VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR		= -53,
78 	VIRTCHNL_STATUS_ERR_NOT_SUPPORTED		= -64,
79 };
80 
81 /* Backward compatibility */
82 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
83 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
84 
85 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT		0x0
86 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT		0x1
87 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT	0x2
88 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT		0x3
89 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT		0x4
90 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT		0x5
91 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT		0x6
92 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT		0x7
93 
94 enum virtchnl_link_speed {
95 	VIRTCHNL_LINK_SPEED_UNKNOWN	= 0,
96 	VIRTCHNL_LINK_SPEED_100MB	= BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
97 	VIRTCHNL_LINK_SPEED_1GB		= BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
98 	VIRTCHNL_LINK_SPEED_10GB	= BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
99 	VIRTCHNL_LINK_SPEED_40GB	= BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
100 	VIRTCHNL_LINK_SPEED_20GB	= BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
101 	VIRTCHNL_LINK_SPEED_25GB	= BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
102 	VIRTCHNL_LINK_SPEED_2_5GB	= BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
103 	VIRTCHNL_LINK_SPEED_5GB		= BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
104 };
105 
106 /* for hsplit_0 field of Rx HMC context */
107 /* deprecated with AVF 1.0 */
108 enum virtchnl_rx_hsplit {
109 	VIRTCHNL_RX_HSPLIT_NO_SPLIT      = 0,
110 	VIRTCHNL_RX_HSPLIT_SPLIT_L2      = 1,
111 	VIRTCHNL_RX_HSPLIT_SPLIT_IP      = 2,
112 	VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
113 	VIRTCHNL_RX_HSPLIT_SPLIT_SCTP    = 8,
114 };
115 
116 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS	6
117 /* END GENERIC DEFINES */
118 
119 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
120  * of the virtchnl_msg structure.
121  */
122 enum virtchnl_ops {
123 /* The PF sends status change events to VFs using
124  * the VIRTCHNL_OP_EVENT opcode.
125  * VFs send requests to the PF using the other ops.
126  * Use of "advanced opcode" features must be negotiated as part of capabilities
127  * exchange and are not considered part of base mode feature set.
128  */
129 	VIRTCHNL_OP_UNKNOWN = 0,
130 	VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
131 	VIRTCHNL_OP_RESET_VF = 2,
132 	VIRTCHNL_OP_GET_VF_RESOURCES = 3,
133 	VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
134 	VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
135 	VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
136 	VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
137 	VIRTCHNL_OP_ENABLE_QUEUES = 8,
138 	VIRTCHNL_OP_DISABLE_QUEUES = 9,
139 	VIRTCHNL_OP_ADD_ETH_ADDR = 10,
140 	VIRTCHNL_OP_DEL_ETH_ADDR = 11,
141 	VIRTCHNL_OP_ADD_VLAN = 12,
142 	VIRTCHNL_OP_DEL_VLAN = 13,
143 	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
144 	VIRTCHNL_OP_GET_STATS = 15,
145 	VIRTCHNL_OP_RSVD = 16,
146 	VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
147 	/* opcode 19 is reserved */
148 	/* opcodes 20, 21, and 22 are reserved */
149 	VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
150 	VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
151 	VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
152 	VIRTCHNL_OP_SET_RSS_HENA = 26,
153 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
154 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
155 	VIRTCHNL_OP_REQUEST_QUEUES = 29,
156 	VIRTCHNL_OP_ENABLE_CHANNELS = 30,
157 	VIRTCHNL_OP_DISABLE_CHANNELS = 31,
158 	VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
159 	VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
160 	/* opcode 34 is reserved */
161 	/* opcodes 38, 39, 40, 41, 42 and 43 are reserved */
162 	/* opcode 44 is reserved */
163 	/* opcode 45, 46, 47, 48 and 49 are reserved */
164 	VIRTCHNL_OP_GET_MAX_RSS_QREGION = 50,
165 	VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS = 51,
166 	VIRTCHNL_OP_ADD_VLAN_V2 = 52,
167 	VIRTCHNL_OP_DEL_VLAN_V2 = 53,
168 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 = 54,
169 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 = 55,
170 	VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 = 56,
171 	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
172 	VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 = 58,
173 	VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 = 59,
174 	/* opcodes 60 through 69 are reserved */
175 	VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107,
176 	VIRTCHNL_OP_DISABLE_QUEUES_V2 = 108,
177 	VIRTCHNL_OP_MAP_QUEUE_VECTOR = 111,
178 	VIRTCHNL_OP_MAX,
179 };
180 
181 static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode)
182 {
183 	switch (v_opcode) {
184 	case VIRTCHNL_OP_UNKNOWN:
185 		return "VIRTCHNL_OP_UNKNOWN";
186 	case VIRTCHNL_OP_VERSION:
187 		return "VIRTCHNL_OP_VERSION";
188 	case VIRTCHNL_OP_RESET_VF:
189 		return "VIRTCHNL_OP_RESET_VF";
190 	case VIRTCHNL_OP_GET_VF_RESOURCES:
191 		return "VIRTCHNL_OP_GET_VF_RESOURCES";
192 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
193 		return "VIRTCHNL_OP_CONFIG_TX_QUEUE";
194 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
195 		return "VIRTCHNL_OP_CONFIG_RX_QUEUE";
196 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
197 		return "VIRTCHNL_OP_CONFIG_VSI_QUEUES";
198 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
199 		return "VIRTCHNL_OP_CONFIG_IRQ_MAP";
200 	case VIRTCHNL_OP_ENABLE_QUEUES:
201 		return "VIRTCHNL_OP_ENABLE_QUEUES";
202 	case VIRTCHNL_OP_DISABLE_QUEUES:
203 		return "VIRTCHNL_OP_DISABLE_QUEUES";
204 	case VIRTCHNL_OP_ADD_ETH_ADDR:
205 		return "VIRTCHNL_OP_ADD_ETH_ADDR";
206 	case VIRTCHNL_OP_DEL_ETH_ADDR:
207 		return "VIRTCHNL_OP_DEL_ETH_ADDR";
208 	case VIRTCHNL_OP_ADD_VLAN:
209 		return "VIRTCHNL_OP_ADD_VLAN";
210 	case VIRTCHNL_OP_DEL_VLAN:
211 		return "VIRTCHNL_OP_DEL_VLAN";
212 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
213 		return "VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE";
214 	case VIRTCHNL_OP_GET_STATS:
215 		return "VIRTCHNL_OP_GET_STATS";
216 	case VIRTCHNL_OP_RSVD:
217 		return "VIRTCHNL_OP_RSVD";
218 	case VIRTCHNL_OP_EVENT:
219 		return "VIRTCHNL_OP_EVENT";
220 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
221 		return "VIRTCHNL_OP_CONFIG_RSS_KEY";
222 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
223 		return "VIRTCHNL_OP_CONFIG_RSS_LUT";
224 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
225 		return "VIRTCHNL_OP_GET_RSS_HENA_CAPS";
226 	case VIRTCHNL_OP_SET_RSS_HENA:
227 		return "VIRTCHNL_OP_SET_RSS_HENA";
228 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
229 		return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING";
230 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
231 		return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING";
232 	case VIRTCHNL_OP_REQUEST_QUEUES:
233 		return "VIRTCHNL_OP_REQUEST_QUEUES";
234 	case VIRTCHNL_OP_ENABLE_CHANNELS:
235 		return "VIRTCHNL_OP_ENABLE_CHANNELS";
236 	case VIRTCHNL_OP_DISABLE_CHANNELS:
237 		return "VIRTCHNL_OP_DISABLE_CHANNELS";
238 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
239 		return "VIRTCHNL_OP_ADD_CLOUD_FILTER";
240 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
241 		return "VIRTCHNL_OP_DEL_CLOUD_FILTER";
242 	case VIRTCHNL_OP_GET_MAX_RSS_QREGION:
243 		return "VIRTCHNL_OP_GET_MAX_RSS_QREGION";
244 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
245 		return "VIRTCHNL_OP_ENABLE_QUEUES_V2";
246 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
247 		return "VIRTCHNL_OP_DISABLE_QUEUES_V2";
248 	case VIRTCHNL_OP_MAP_QUEUE_VECTOR:
249 		return "VIRTCHNL_OP_MAP_QUEUE_VECTOR";
250 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
251 		return "VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS";
252 	case VIRTCHNL_OP_ADD_VLAN_V2:
253 		return "VIRTCHNL_OP_ADD_VLAN_V2";
254 	case VIRTCHNL_OP_DEL_VLAN_V2:
255 		return "VIRTCHNL_OP_DEL_VLAN_V2";
256 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
257 		return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2";
258 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
259 		return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2";
260 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
261 		return "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2";
262 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
263 		return "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2";
264 	case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2:
265 		return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2";
266 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
267 		return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2";
268 	case VIRTCHNL_OP_MAX:
269 		return "VIRTCHNL_OP_MAX";
270 	default:
271 		return "Unsupported (update virtchnl.h)";
272 	}
273 }
274 
275 /* These macros are used to generate compilation errors if a structure/union
276  * is not exactly the correct length. It gives a divide by zero error if the
277  * structure/union is not of the correct size, otherwise it creates an enum
278  * that is never used.
279  */
280 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
281 	{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
282 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
283 	{ virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
284 
285 /* Virtual channel message descriptor. This overlays the admin queue
286  * descriptor. All other data is passed in external buffers.
287  */
288 
289 struct virtchnl_msg {
290 	u8 pad[8];			 /* AQ flags/opcode/len/retval fields */
291 
292 	/* avoid confusion with desc->opcode */
293 	enum virtchnl_ops v_opcode;
294 
295 	/* ditto for desc->retval */
296 	enum virtchnl_status_code v_retval;
297 	u32 vfid;			 /* used by PF when sending to VF */
298 };
299 
300 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
301 
302 /* Message descriptions and data structures. */
303 
304 /* VIRTCHNL_OP_VERSION
305  * VF posts its version number to the PF. PF responds with its version number
306  * in the same format, along with a return code.
307  * Reply from PF has its major/minor versions also in param0 and param1.
308  * If there is a major version mismatch, then the VF cannot operate.
309  * If there is a minor version mismatch, then the VF can operate but should
310  * add a warning to the system log.
311  *
312  * This enum element MUST always be specified as == 1, regardless of other
313  * changes in the API. The PF must always respond to this message without
314  * error regardless of version mismatch.
315  */
316 #define VIRTCHNL_VERSION_MAJOR		1
317 #define VIRTCHNL_VERSION_MINOR		1
318 #define VIRTCHNL_VERSION_MAJOR_2	2
319 #define VIRTCHNL_VERSION_MINOR_0	0
320 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS	0
321 
322 struct virtchnl_version_info {
323 	u32 major;
324 	u32 minor;
325 };
326 
327 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
328 
329 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
330 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
331 
332 /* VIRTCHNL_OP_RESET_VF
333  * VF sends this request to PF with no parameters
334  * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
335  * until reset completion is indicated. The admin queue must be reinitialized
336  * after this operation.
337  *
338  * When reset is complete, PF must ensure that all queues in all VSIs associated
339  * with the VF are stopped, all queue configurations in the HMC are set to 0,
340  * and all MAC and VLAN filters (except the default MAC address) on all VSIs
341  * are cleared.
342  */
343 
344 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
345  * vsi_type should always be 6 for backward compatibility. Add other fields
346  * as needed.
347  */
348 enum virtchnl_vsi_type {
349 	VIRTCHNL_VSI_TYPE_INVALID = 0,
350 	VIRTCHNL_VSI_SRIOV = 6,
351 };
352 
353 /* VIRTCHNL_OP_GET_VF_RESOURCES
354  * Version 1.0 VF sends this request to PF with no parameters
355  * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
356  * PF responds with an indirect message containing
357  * virtchnl_vf_resource and one or more
358  * virtchnl_vsi_resource structures.
359  */
360 
361 struct virtchnl_vsi_resource {
362 	u16 vsi_id;
363 	u16 num_queue_pairs;
364 
365 	/* see enum virtchnl_vsi_type */
366 	s32 vsi_type;
367 	u16 qset_handle;
368 	u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
369 };
370 
371 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
372 
373 /* VF capability flags
374  * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
375  * TX/RX Checksum offloading and TSO for non-tunnelled packets.
376  */
377 #define VIRTCHNL_VF_OFFLOAD_L2			0x00000001
378 #define VIRTCHNL_VF_OFFLOAD_IWARP		0x00000002
379 #define VIRTCHNL_VF_OFFLOAD_RSVD		0x00000004
380 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ		0x00000008
381 #define VIRTCHNL_VF_OFFLOAD_RSS_REG		0x00000010
382 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR		0x00000020
383 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES		0x00000040
384 #define VIRTCHNL_VF_OFFLOAD_CRC			0x00000080
385 	/* 0X00000100 is reserved */
386 #define VIRTCHNL_VF_LARGE_NUM_QPAIRS		0x00000200
387 #define VIRTCHNL_VF_OFFLOAD_VLAN_V2		0x00008000
388 #define VIRTCHNL_VF_OFFLOAD_VLAN		0x00010000
389 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING		0x00020000
390 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2	0x00040000
391 #define VIRTCHNL_VF_OFFLOAD_RSS_PF		0X00080000
392 #define VIRTCHNL_VF_OFFLOAD_ENCAP		0X00100000
393 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM		0X00200000
394 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM	0X00400000
395 #define VIRTCHNL_VF_OFFLOAD_ADQ			0X00800000
396 #define VIRTCHNL_VF_OFFLOAD_ADQ_V2		0X01000000
397 #define VIRTCHNL_VF_OFFLOAD_USO			0X02000000
398 	/* 0x04000000 is reserved */
399 	/* 0X08000000 and 0X10000000 are reserved */
400 	/* 0X20000000 is reserved */
401 	/* 0X40000000 is reserved */
402 	/* 0X80000000 is reserved */
403 
404 /* Define below the capability flags that are not offloads */
405 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED		0x00000080
406 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
407 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
408 			       VIRTCHNL_VF_OFFLOAD_RSS_PF)
409 
410 struct virtchnl_vf_resource {
411 	u16 num_vsis;
412 	u16 num_queue_pairs;
413 	u16 max_vectors;
414 	u16 max_mtu;
415 
416 	u32 vf_cap_flags;
417 	u32 rss_key_size;
418 	u32 rss_lut_size;
419 
420 	struct virtchnl_vsi_resource vsi_res[1];
421 };
422 
423 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
424 
425 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
426  * VF sends this message to set up parameters for one TX queue.
427  * External data buffer contains one instance of virtchnl_txq_info.
428  * PF configures requested queue and returns a status code.
429  */
430 
431 /* Tx queue config info */
432 struct virtchnl_txq_info {
433 	u16 vsi_id;
434 	u16 queue_id;
435 	u16 ring_len;		/* number of descriptors, multiple of 8 */
436 	u16 headwb_enabled; /* deprecated with AVF 1.0 */
437 	u64 dma_ring_addr;
438 	u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
439 };
440 
441 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
442 
443 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
444  * VF sends this message to set up parameters for one RX queue.
445  * External data buffer contains one instance of virtchnl_rxq_info.
446  * PF configures requested queue and returns a status code. The
447  * crc_disable flag disables CRC stripping on the VF. Setting
448  * the crc_disable flag to 1 will disable CRC stripping for each
449  * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC
450  * offload must have been set prior to sending this info or the PF
451  * will ignore the request. This flag should be set the same for
452  * all of the queues for a VF.
453  */
454 
455 /* Rx queue config info */
456 struct virtchnl_rxq_info {
457 	u16 vsi_id;
458 	u16 queue_id;
459 	u32 ring_len;		/* number of descriptors, multiple of 32 */
460 	u16 hdr_size;
461 	u16 splithdr_enabled; /* deprecated with AVF 1.0 */
462 	u32 databuffer_size;
463 	u32 max_pkt_size;
464 	u8 crc_disable;
465 	u8 pad1[3];
466 	u64 dma_ring_addr;
467 
468 	/* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
469 	s32 rx_split_pos;
470 	u32 pad2;
471 };
472 
473 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
474 
475 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
476  * VF sends this message to set parameters for active TX and RX queues
477  * associated with the specified VSI.
478  * PF configures queues and returns status.
479  * If the number of queues specified is greater than the number of queues
480  * associated with the VSI, an error is returned and no queues are configured.
481  * NOTE: The VF is not required to configure all queues in a single request.
482  * It may send multiple messages. PF drivers must correctly handle all VF
483  * requests.
484  */
485 struct virtchnl_queue_pair_info {
486 	/* NOTE: vsi_id and queue_id should be identical for both queues. */
487 	struct virtchnl_txq_info txq;
488 	struct virtchnl_rxq_info rxq;
489 };
490 
491 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
492 
493 struct virtchnl_vsi_queue_config_info {
494 	u16 vsi_id;
495 	u16 num_queue_pairs;
496 	u32 pad;
497 	struct virtchnl_queue_pair_info qpair[1];
498 };
499 
500 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
501 
502 /* VIRTCHNL_OP_REQUEST_QUEUES
503  * VF sends this message to request the PF to allocate additional queues to
504  * this VF.  Each VF gets a guaranteed number of queues on init but asking for
505  * additional queues must be negotiated.  This is a best effort request as it
506  * is possible the PF does not have enough queues left to support the request.
507  * If the PF cannot support the number requested it will respond with the
508  * maximum number it is able to support.  If the request is successful, PF will
509  * then reset the VF to institute required changes.
510  */
511 
512 /* VF resource request */
513 struct virtchnl_vf_res_request {
514 	u16 num_queue_pairs;
515 };
516 
517 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
518  * VF uses this message to map vectors to queues.
519  * The rxq_map and txq_map fields are bitmaps used to indicate which queues
520  * are to be associated with the specified vector.
521  * The "other" causes are always mapped to vector 0. The VF may not request
522  * that vector 0 be used for traffic.
523  * PF configures interrupt mapping and returns status.
524  * NOTE: due to hardware requirements, all active queues (both TX and RX)
525  * should be mapped to interrupts, even if the driver intends to operate
526  * only in polling mode. In this case the interrupt may be disabled, but
527  * the ITR timer will still run to trigger writebacks.
528  */
529 struct virtchnl_vector_map {
530 	u16 vsi_id;
531 	u16 vector_id;
532 	u16 rxq_map;
533 	u16 txq_map;
534 	u16 rxitr_idx;
535 	u16 txitr_idx;
536 };
537 
538 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
539 
540 struct virtchnl_irq_map_info {
541 	u16 num_vectors;
542 	struct virtchnl_vector_map vecmap[1];
543 };
544 
545 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
546 
547 /* VIRTCHNL_OP_ENABLE_QUEUES
548  * VIRTCHNL_OP_DISABLE_QUEUES
549  * VF sends these message to enable or disable TX/RX queue pairs.
550  * The queues fields are bitmaps indicating which queues to act upon.
551  * (Currently, we only support 16 queues per VF, but we make the field
552  * u32 to allow for expansion.)
553  * PF performs requested action and returns status.
554  * NOTE: The VF is not required to enable/disable all queues in a single
555  * request. It may send multiple messages.
556  * PF drivers must correctly handle all VF requests.
557  */
558 struct virtchnl_queue_select {
559 	u16 vsi_id;
560 	u16 pad;
561 	u32 rx_queues;
562 	u32 tx_queues;
563 };
564 
565 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
566 
567 /* VIRTCHNL_OP_GET_MAX_RSS_QREGION
568  *
569  * if VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
570  * then this op must be supported.
571  *
572  * VF sends this message in order to query the max RSS queue region
573  * size supported by PF, when VIRTCHNL_VF_LARGE_NUM_QPAIRS is enabled.
574  * This information should be used when configuring the RSS LUT and/or
575  * configuring queue region based filters.
576  *
577  * The maximum RSS queue region is 2^qregion_width. So, a qregion_width
578  * of 6 would inform the VF that the PF supports a maximum RSS queue region
579  * of 64.
580  *
581  * A queue region represents a range of queues that can be used to configure
582  * a RSS LUT. For example, if a VF is given 64 queues, but only a max queue
583  * region size of 16 (i.e. 2^qregion_width = 16) then it will only be able
584  * to configure the RSS LUT with queue indices from 0 to 15. However, other
585  * filters can be used to direct packets to queues >15 via specifying a queue
586  * base/offset and queue region width.
587  */
588 struct virtchnl_max_rss_qregion {
589 	u16 vport_id;
590 	u16 qregion_width;
591 	u8 pad[4];
592 };
593 
594 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_max_rss_qregion);
595 
596 /* VIRTCHNL_OP_ADD_ETH_ADDR
597  * VF sends this message in order to add one or more unicast or multicast
598  * address filters for the specified VSI.
599  * PF adds the filters and returns status.
600  */
601 
602 /* VIRTCHNL_OP_DEL_ETH_ADDR
603  * VF sends this message in order to remove one or more unicast or multicast
604  * filters for the specified VSI.
605  * PF removes the filters and returns status.
606  */
607 
608 /* VIRTCHNL_ETHER_ADDR_LEGACY
609  * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad
610  * bytes. Moving forward all VF drivers should not set type to
611  * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy
612  * behavior. The control plane function (i.e. PF) can use a best effort method
613  * of tracking the primary/device unicast in this case, but there is no
614  * guarantee and functionality depends on the implementation of the PF.
615  */
616 
617 /* VIRTCHNL_ETHER_ADDR_PRIMARY
618  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the
619  * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and
620  * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane
621  * function (i.e. PF) to accurately track and use this MAC address for
622  * displaying on the host and for VM/function reset.
623  */
624 
625 /* VIRTCHNL_ETHER_ADDR_EXTRA
626  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra
627  * unicast and/or multicast filters that are being added/deleted via
628  * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively.
629  */
630 struct virtchnl_ether_addr {
631 	u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
632 	u8 type;
633 #define VIRTCHNL_ETHER_ADDR_LEGACY	0
634 #define VIRTCHNL_ETHER_ADDR_PRIMARY	1
635 #define VIRTCHNL_ETHER_ADDR_EXTRA	2
636 #define VIRTCHNL_ETHER_ADDR_TYPE_MASK	3 /* first two bits of type are valid */
637 	u8 pad;
638 };
639 
640 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
641 
642 struct virtchnl_ether_addr_list {
643 	u16 vsi_id;
644 	u16 num_elements;
645 	struct virtchnl_ether_addr list[1];
646 };
647 
648 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
649 
650 /* VIRTCHNL_OP_ADD_VLAN
651  * VF sends this message to add one or more VLAN tag filters for receives.
652  * PF adds the filters and returns status.
653  * If a port VLAN is configured by the PF, this operation will return an
654  * error to the VF.
655  */
656 
657 /* VIRTCHNL_OP_DEL_VLAN
658  * VF sends this message to remove one or more VLAN tag filters for receives.
659  * PF removes the filters and returns status.
660  * If a port VLAN is configured by the PF, this operation will return an
661  * error to the VF.
662  */
663 
664 struct virtchnl_vlan_filter_list {
665 	u16 vsi_id;
666 	u16 num_elements;
667 	u16 vlan_id[1];
668 };
669 
670 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
671 
672 /* This enum is used for all of the VIRTCHNL_VF_OFFLOAD_VLAN_V2_CAPS related
673  * structures and opcodes.
674  *
675  * VIRTCHNL_VLAN_UNSUPPORTED - This field is not supported and if a VF driver
676  * populates it the PF should return VIRTCHNL_STATUS_ERR_NOT_SUPPORTED.
677  *
678  * VIRTCHNL_VLAN_ETHERTYPE_8100 - This field supports 0x8100 ethertype.
679  * VIRTCHNL_VLAN_ETHERTYPE_88A8 - This field supports 0x88A8 ethertype.
680  * VIRTCHNL_VLAN_ETHERTYPE_9100 - This field supports 0x9100 ethertype.
681  *
682  * VIRTCHNL_VLAN_ETHERTYPE_AND - Used when multiple ethertypes can be supported
683  * by the PF concurrently. For example, if the PF can support
684  * VIRTCHNL_VLAN_ETHERTYPE_8100 AND VIRTCHNL_VLAN_ETHERTYPE_88A8 filters it
685  * would OR the following bits:
686  *
687  *	VIRTHCNL_VLAN_ETHERTYPE_8100 |
688  *	VIRTCHNL_VLAN_ETHERTYPE_88A8 |
689  *	VIRTCHNL_VLAN_ETHERTYPE_AND;
690  *
691  * The VF would interpret this as VLAN filtering can be supported on both 0x8100
692  * and 0x88A8 VLAN ethertypes.
693  *
694  * VIRTCHNL_ETHERTYPE_XOR - Used when only a single ethertype can be supported
695  * by the PF concurrently. For example if the PF can support
696  * VIRTCHNL_VLAN_ETHERTYPE_8100 XOR VIRTCHNL_VLAN_ETHERTYPE_88A8 stripping
697  * offload it would OR the following bits:
698  *
699  *	VIRTCHNL_VLAN_ETHERTYPE_8100 |
700  *	VIRTCHNL_VLAN_ETHERTYPE_88A8 |
701  *	VIRTCHNL_VLAN_ETHERTYPE_XOR;
702  *
703  * The VF would interpret this as VLAN stripping can be supported on either
704  * 0x8100 or 0x88a8 VLAN ethertypes. So when requesting VLAN stripping via
705  * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 the specified ethertype will override
706  * the previously set value.
707  *
708  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 - Used to tell the VF to insert and/or
709  * strip the VLAN tag using the L2TAG1 field of the Tx/Rx descriptors.
710  *
711  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to insert hardware
712  * offloaded VLAN tags using the L2TAG2 field of the Tx descriptor.
713  *
714  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to strip hardware
715  * offloaded VLAN tags using the L2TAG2_2 field of the Rx descriptor.
716  *
717  * VIRTCHNL_VLAN_PRIO - This field supports VLAN priority bits. This is used for
718  * VLAN filtering if the underlying PF supports it.
719  *
720  * VIRTCHNL_VLAN_TOGGLE_ALLOWED - This field is used to say whether a
721  * certain VLAN capability can be toggled. For example if the underlying PF/CP
722  * allows the VF to toggle VLAN filtering, stripping, and/or insertion it should
723  * set this bit along with the supported ethertypes.
724  */
725 enum virtchnl_vlan_support {
726 	VIRTCHNL_VLAN_UNSUPPORTED =		0,
727 	VIRTCHNL_VLAN_ETHERTYPE_8100 =		0x00000001,
728 	VIRTCHNL_VLAN_ETHERTYPE_88A8 =		0x00000002,
729 	VIRTCHNL_VLAN_ETHERTYPE_9100 =		0x00000004,
730 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 =	0x00000100,
731 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 =	0x00000200,
732 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 =	0x00000400,
733 	VIRTCHNL_VLAN_PRIO =			0x01000000,
734 	VIRTCHNL_VLAN_FILTER_MASK =		0x10000000,
735 	VIRTCHNL_VLAN_ETHERTYPE_AND =		0x20000000,
736 	VIRTCHNL_VLAN_ETHERTYPE_XOR =		0x40000000,
737 	VIRTCHNL_VLAN_TOGGLE =			0x80000000
738 };
739 
740 /* This structure is used as part of the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
741  * for filtering, insertion, and stripping capabilities.
742  *
743  * If only outer capabilities are supported (for filtering, insertion, and/or
744  * stripping) then this refers to the outer most or single VLAN from the VF's
745  * perspective.
746  *
747  * If only inner capabilities are supported (for filtering, insertion, and/or
748  * stripping) then this refers to the outer most or single VLAN from the VF's
749  * perspective. Functionally this is the same as if only outer capabilities are
750  * supported. The VF driver is just forced to use the inner fields when
751  * adding/deleting filters and enabling/disabling offloads (if supported).
752  *
753  * If both outer and inner capabilities are supported (for filtering, insertion,
754  * and/or stripping) then outer refers to the outer most or single VLAN and
755  * inner refers to the second VLAN, if it exists, in the packet.
756  *
757  * There is no support for tunneled VLAN offloads, so outer or inner are never
758  * referring to a tunneled packet from the VF's perspective.
759  */
760 struct virtchnl_vlan_supported_caps {
761 	u32 outer;
762 	u32 inner;
763 };
764 
765 /* The PF populates these fields based on the supported VLAN filtering. If a
766  * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
767  * reject any VIRTCHNL_OP_ADD_VLAN_V2 or VIRTCHNL_OP_DEL_VLAN_V2 messages using
768  * the unsupported fields.
769  *
770  * Also, a VF is only allowed to toggle its VLAN filtering setting if the
771  * VIRTCHNL_VLAN_TOGGLE bit is set.
772  *
773  * The ethertype(s) specified in the ethertype_init field are the ethertypes
774  * enabled for VLAN filtering. VLAN filtering in this case refers to the outer
775  * most VLAN from the VF's perspective. If both inner and outer filtering are
776  * allowed then ethertype_init only refers to the outer most VLAN as only
777  * VLAN ethertype supported for inner VLAN filtering is
778  * VIRTCHNL_VLAN_ETHERTYPE_8100. By default, inner VLAN filtering is disabled
779  * when both inner and outer filtering are allowed.
780  *
781  * The max_filters field tells the VF how many VLAN filters it's allowed to have
782  * at any one time. If it exceeds this amount and tries to add another filter,
783  * then the request will be rejected by the PF. To prevent failures, the VF
784  * should keep track of how many VLAN filters it has added and not attempt to
785  * add more than max_filters.
786  */
787 struct virtchnl_vlan_filtering_caps {
788 	struct virtchnl_vlan_supported_caps filtering_support;
789 	u32 ethertype_init;
790 	u16 max_filters;
791 	u8 pad[2];
792 };
793 
794 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_filtering_caps);
795 
796 /* This enum is used for the virtchnl_vlan_offload_caps structure to specify
797  * if the PF supports a different ethertype for stripping and insertion.
798  *
799  * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION - The ethertype(s) specified
800  * for stripping affect the ethertype(s) specified for insertion and visa versa
801  * as well. If the VF tries to configure VLAN stripping via
802  * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 with VIRTCHNL_VLAN_ETHERTYPE_8100 then
803  * that will be the ethertype for both stripping and insertion.
804  *
805  * VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED - The ethertype(s) specified for
806  * stripping do not affect the ethertype(s) specified for insertion and visa
807  * versa.
808  */
809 enum virtchnl_vlan_ethertype_match {
810 	VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION = 0,
811 	VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED = 1,
812 };
813 
814 /* The PF populates these fields based on the supported VLAN offloads. If a
815  * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
816  * reject any VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 or
817  * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 messages using the unsupported fields.
818  *
819  * Also, a VF is only allowed to toggle its VLAN offload setting if the
820  * VIRTCHNL_VLAN_TOGGLE_ALLOWED bit is set.
821  *
822  * The VF driver needs to be aware of how the tags are stripped by hardware and
823  * inserted by the VF driver based on the level of offload support. The PF will
824  * populate these fields based on where the VLAN tags are expected to be
825  * offloaded via the VIRTHCNL_VLAN_TAG_LOCATION_* bits. The VF will need to
826  * interpret these fields. See the definition of the
827  * VIRTCHNL_VLAN_TAG_LOCATION_* bits above the virtchnl_vlan_support
828  * enumeration.
829  */
830 struct virtchnl_vlan_offload_caps {
831 	struct virtchnl_vlan_supported_caps stripping_support;
832 	struct virtchnl_vlan_supported_caps insertion_support;
833 	u32 ethertype_init;
834 	u8 ethertype_match;
835 	u8 pad[3];
836 };
837 
838 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_vlan_offload_caps);
839 
840 /* VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
841  * VF sends this message to determine its VLAN capabilities.
842  *
843  * PF will mark which capabilities it supports based on hardware support and
844  * current configuration. For example, if a port VLAN is configured the PF will
845  * not allow outer VLAN filtering, stripping, or insertion to be configured so
846  * it will block these features from the VF.
847  *
848  * The VF will need to cross reference its capabilities with the PFs
849  * capabilities in the response message from the PF to determine the VLAN
850  * support.
851  */
852 struct virtchnl_vlan_caps {
853 	struct virtchnl_vlan_filtering_caps filtering;
854 	struct virtchnl_vlan_offload_caps offloads;
855 };
856 
857 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_caps);
858 
859 struct virtchnl_vlan {
860 	u16 tci;	/* tci[15:13] = PCP and tci[11:0] = VID */
861 	u16 tci_mask;	/* only valid if VIRTCHNL_VLAN_FILTER_MASK set in
862 			 * filtering caps
863 			 */
864 	u16 tpid;	/* 0x8100, 0x88a8, etc. and only type(s) set in
865 			 * filtering caps. Note that tpid here does not refer to
866 			 * VIRTCHNL_VLAN_ETHERTYPE_*, but it refers to the
867 			 * actual 2-byte VLAN TPID
868 			 */
869 	u8 pad[2];
870 };
871 
872 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan);
873 
874 struct virtchnl_vlan_filter {
875 	struct virtchnl_vlan inner;
876 	struct virtchnl_vlan outer;
877 	u8 pad[16];
878 };
879 
880 VIRTCHNL_CHECK_STRUCT_LEN(32, virtchnl_vlan_filter);
881 
882 /* VIRTCHNL_OP_ADD_VLAN_V2
883  * VIRTCHNL_OP_DEL_VLAN_V2
884  *
885  * VF sends these messages to add/del one or more VLAN tag filters for Rx
886  * traffic.
887  *
888  * The PF attempts to add the filters and returns status.
889  *
890  * The VF should only ever attempt to add/del virtchnl_vlan_filter(s) using the
891  * supported fields negotiated via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS.
892  */
893 struct virtchnl_vlan_filter_list_v2 {
894 	u16 vport_id;
895 	u16 num_elements;
896 	u8 pad[4];
897 	struct virtchnl_vlan_filter filters[1];
898 };
899 
900 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_filter_list_v2);
901 
902 /* VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
903  * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
904  * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
905  * VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
906  *
907  * VF sends this message to enable or disable VLAN stripping or insertion. It
908  * also needs to specify an ethertype. The VF knows which VLAN ethertypes are
909  * allowed and whether or not it's allowed to enable/disable the specific
910  * offload via the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
911  * parse the virtchnl_vlan_caps.offloads fields to determine which offload
912  * messages are allowed.
913  *
914  * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
915  * following manner the VF will be allowed to enable and/or disable 0x8100 inner
916  * VLAN insertion and/or stripping via the opcodes listed above. Inner in this
917  * case means the outer most or single VLAN from the VF's perspective. This is
918  * because no outer offloads are supported. See the comments above the
919  * virtchnl_vlan_supported_caps structure for more details.
920  *
921  * virtchnl_vlan_caps.offloads.stripping_support.inner =
922  *			VIRTCHNL_VLAN_TOGGLE |
923  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
924  *
925  * virtchnl_vlan_caps.offloads.insertion_support.inner =
926  *			VIRTCHNL_VLAN_TOGGLE |
927  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
928  *
929  * In order to enable inner (again note that in this case inner is the outer
930  * most or single VLAN from the VF's perspective) VLAN stripping for 0x8100
931  * VLANs, the VF would populate the virtchnl_vlan_setting structure in the
932  * following manner and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
933  *
934  * virtchnl_vlan_setting.inner_ethertype_setting =
935  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
936  *
937  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
938  * initialization.
939  *
940  * The reason that VLAN TPID(s) are not being used for the
941  * outer_ethertype_setting and inner_ethertype_setting fields is because it's
942  * possible a device could support VLAN insertion and/or stripping offload on
943  * multiple ethertypes concurrently, so this method allows a VF to request
944  * multiple ethertypes in one message using the virtchnl_vlan_support
945  * enumeration.
946  *
947  * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
948  * following manner the VF will be allowed to enable 0x8100 and 0x88a8 outer
949  * VLAN insertion and stripping simultaneously. The
950  * virtchnl_vlan_caps.offloads.ethertype_match field will also have to be
951  * populated based on what the PF can support.
952  *
953  * virtchnl_vlan_caps.offloads.stripping_support.outer =
954  *			VIRTCHNL_VLAN_TOGGLE |
955  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
956  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
957  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
958  *
959  * virtchnl_vlan_caps.offloads.insertion_support.outer =
960  *			VIRTCHNL_VLAN_TOGGLE |
961  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
962  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
963  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
964  *
965  * In order to enable outer VLAN stripping for 0x8100 and 0x88a8 VLANs, the VF
966  * would populate the virthcnl_vlan_offload_structure in the following manner
967  * and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
968  *
969  * virtchnl_vlan_setting.outer_ethertype_setting =
970  *			VIRTHCNL_VLAN_ETHERTYPE_8100 |
971  *			VIRTHCNL_VLAN_ETHERTYPE_88A8;
972  *
973  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
974  * initialization.
975  *
976  * There is also the case where a PF and the underlying hardware can support
977  * VLAN offloads on multiple ethertypes, but not concurrently. For example, if
978  * the PF populates the virtchnl_vlan_caps.offloads in the following manner the
979  * VF will be allowed to enable and/or disable 0x8100 XOR 0x88a8 outer VLAN
980  * offloads. The ethertypes must match for stripping and insertion.
981  *
982  * virtchnl_vlan_caps.offloads.stripping_support.outer =
983  *			VIRTCHNL_VLAN_TOGGLE |
984  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
985  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
986  *			VIRTCHNL_VLAN_ETHERTYPE_XOR;
987  *
988  * virtchnl_vlan_caps.offloads.insertion_support.outer =
989  *			VIRTCHNL_VLAN_TOGGLE |
990  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
991  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
992  *			VIRTCHNL_VLAN_ETHERTYPE_XOR;
993  *
994  * virtchnl_vlan_caps.offloads.ethertype_match =
995  *			VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
996  *
997  * In order to enable outer VLAN stripping for 0x88a8 VLANs, the VF would
998  * populate the virtchnl_vlan_setting structure in the following manner and send
999  * the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2. Also, this will change the
1000  * ethertype for VLAN insertion if it's enabled. So, for completeness, a
1001  * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 with the same ethertype should be sent.
1002  *
1003  * virtchnl_vlan_setting.outer_ethertype_setting = VIRTHCNL_VLAN_ETHERTYPE_88A8;
1004  *
1005  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
1006  * initialization.
1007  *
1008  * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2
1009  * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2
1010  *
1011  * VF sends this message to enable or disable VLAN filtering. It also needs to
1012  * specify an ethertype. The VF knows which VLAN ethertypes are allowed and
1013  * whether or not it's allowed to enable/disable filtering via the
1014  * VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
1015  * parse the virtchnl_vlan_caps.filtering fields to determine which, if any,
1016  * filtering messages are allowed.
1017  *
1018  * For example, if the PF populates the virtchnl_vlan_caps.filtering in the
1019  * following manner the VF will be allowed to enable/disable 0x8100 and 0x88a8
1020  * outer VLAN filtering together. Note, that the VIRTCHNL_VLAN_ETHERTYPE_AND
1021  * means that all filtering ethertypes will to be enabled and disabled together
1022  * regardless of the request from the VF. This means that the underlying
1023  * hardware only supports VLAN filtering for all VLAN the specified ethertypes
1024  * or none of them.
1025  *
1026  * virtchnl_vlan_caps.filtering.filtering_support.outer =
1027  *			VIRTCHNL_VLAN_TOGGLE |
1028  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1029  *			VIRTHCNL_VLAN_ETHERTYPE_88A8 |
1030  *			VIRTCHNL_VLAN_ETHERTYPE_9100 |
1031  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
1032  *
1033  * In order to enable outer VLAN filtering for 0x88a8 and 0x8100 VLANs (0x9100
1034  * VLANs aren't supported by the VF driver), the VF would populate the
1035  * virtchnl_vlan_setting structure in the following manner and send the
1036  * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2. The same message format would be used
1037  * to disable outer VLAN filtering for 0x88a8 and 0x8100 VLANs, but the
1038  * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 opcode is used.
1039  *
1040  * virtchnl_vlan_setting.outer_ethertype_setting =
1041  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1042  *			VIRTCHNL_VLAN_ETHERTYPE_88A8;
1043  *
1044  */
1045 struct virtchnl_vlan_setting {
1046 	u32 outer_ethertype_setting;
1047 	u32 inner_ethertype_setting;
1048 	u16 vport_id;
1049 	u8 pad[6];
1050 };
1051 
1052 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_setting);
1053 
1054 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
1055  * VF sends VSI id and flags.
1056  * PF returns status code in retval.
1057  * Note: we assume that broadcast accept mode is always enabled.
1058  */
1059 struct virtchnl_promisc_info {
1060 	u16 vsi_id;
1061 	u16 flags;
1062 };
1063 
1064 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
1065 
1066 #define FLAG_VF_UNICAST_PROMISC	0x00000001
1067 #define FLAG_VF_MULTICAST_PROMISC	0x00000002
1068 
1069 /* VIRTCHNL_OP_GET_STATS
1070  * VF sends this message to request stats for the selected VSI. VF uses
1071  * the virtchnl_queue_select struct to specify the VSI. The queue_id
1072  * field is ignored by the PF.
1073  *
1074  * PF replies with struct virtchnl_eth_stats in an external buffer.
1075  */
1076 
1077 struct virtchnl_eth_stats {
1078 	u64 rx_bytes;			/* received bytes */
1079 	u64 rx_unicast;			/* received unicast pkts */
1080 	u64 rx_multicast;		/* received multicast pkts */
1081 	u64 rx_broadcast;		/* received broadcast pkts */
1082 	u64 rx_discards;
1083 	u64 rx_unknown_protocol;
1084 	u64 tx_bytes;			/* transmitted bytes */
1085 	u64 tx_unicast;			/* transmitted unicast pkts */
1086 	u64 tx_multicast;		/* transmitted multicast pkts */
1087 	u64 tx_broadcast;		/* transmitted broadcast pkts */
1088 	u64 tx_discards;
1089 	u64 tx_errors;
1090 };
1091 
1092 /* VIRTCHNL_OP_CONFIG_RSS_KEY
1093  * VIRTCHNL_OP_CONFIG_RSS_LUT
1094  * VF sends these messages to configure RSS. Only supported if both PF
1095  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
1096  * configuration negotiation. If this is the case, then the RSS fields in
1097  * the VF resource struct are valid.
1098  * Both the key and LUT are initialized to 0 by the PF, meaning that
1099  * RSS is effectively disabled until set up by the VF.
1100  */
1101 struct virtchnl_rss_key {
1102 	u16 vsi_id;
1103 	u16 key_len;
1104 	u8 key[1];         /* RSS hash key, packed bytes */
1105 };
1106 
1107 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
1108 
1109 struct virtchnl_rss_lut {
1110 	u16 vsi_id;
1111 	u16 lut_entries;
1112 	u8 lut[1];        /* RSS lookup table */
1113 };
1114 
1115 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
1116 
1117 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
1118  * VIRTCHNL_OP_SET_RSS_HENA
1119  * VF sends these messages to get and set the hash filter enable bits for RSS.
1120  * By default, the PF sets these to all possible traffic types that the
1121  * hardware supports. The VF can query this value if it wants to change the
1122  * traffic types that are hashed by the hardware.
1123  */
1124 struct virtchnl_rss_hena {
1125 	u64 hena;
1126 };
1127 
1128 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
1129 
1130 /* This is used by PF driver to enforce how many channels can be supported.
1131  * When ADQ_V2 capability is negotiated, it will allow 16 channels otherwise
1132  * PF driver will allow only max 4 channels
1133  */
1134 #define VIRTCHNL_MAX_ADQ_CHANNELS 4
1135 #define VIRTCHNL_MAX_ADQ_V2_CHANNELS 16
1136 
1137 /* VIRTCHNL_OP_ENABLE_CHANNELS
1138  * VIRTCHNL_OP_DISABLE_CHANNELS
1139  * VF sends these messages to enable or disable channels based on
1140  * the user specified queue count and queue offset for each traffic class.
1141  * This struct encompasses all the information that the PF needs from
1142  * VF to create a channel.
1143  */
1144 struct virtchnl_channel_info {
1145 	u16 count; /* number of queues in a channel */
1146 	u16 offset; /* queues in a channel start from 'offset' */
1147 	u32 pad;
1148 	u64 max_tx_rate;
1149 };
1150 
1151 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
1152 
1153 struct virtchnl_tc_info {
1154 	u32	num_tc;
1155 	u32	pad;
1156 	struct	virtchnl_channel_info list[1];
1157 };
1158 
1159 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
1160 
1161 /* VIRTCHNL_ADD_CLOUD_FILTER
1162  * VIRTCHNL_DEL_CLOUD_FILTER
1163  * VF sends these messages to add or delete a cloud filter based on the
1164  * user specified match and action filters. These structures encompass
1165  * all the information that the PF needs from the VF to add/delete a
1166  * cloud filter.
1167  */
1168 
1169 struct virtchnl_l4_spec {
1170 	u8	src_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
1171 	u8	dst_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
1172 	/* vlan_prio is part of this 16 bit field even from OS perspective
1173 	 * vlan_id:12 is actual vlan_id, then vlanid:bit14..12 is vlan_prio
1174 	 * in future, when decided to offload vlan_prio, pass that information
1175 	 * as part of the "vlan_id" field, Bit14..12
1176 	 */
1177 	__be16	vlan_id;
1178 	__be16	pad; /* reserved for future use */
1179 	__be32	src_ip[4];
1180 	__be32	dst_ip[4];
1181 	__be16	src_port;
1182 	__be16	dst_port;
1183 };
1184 
1185 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
1186 
1187 union virtchnl_flow_spec {
1188 	struct	virtchnl_l4_spec tcp_spec;
1189 	u8	buffer[128]; /* reserved for future use */
1190 };
1191 
1192 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
1193 
1194 enum virtchnl_action {
1195 	/* action types */
1196 	VIRTCHNL_ACTION_DROP = 0,
1197 	VIRTCHNL_ACTION_TC_REDIRECT,
1198 	VIRTCHNL_ACTION_PASSTHRU,
1199 	VIRTCHNL_ACTION_QUEUE,
1200 	VIRTCHNL_ACTION_Q_REGION,
1201 	VIRTCHNL_ACTION_MARK,
1202 	VIRTCHNL_ACTION_COUNT,
1203 };
1204 
1205 enum virtchnl_flow_type {
1206 	/* flow types */
1207 	VIRTCHNL_TCP_V4_FLOW = 0,
1208 	VIRTCHNL_TCP_V6_FLOW,
1209 	VIRTCHNL_UDP_V4_FLOW,
1210 	VIRTCHNL_UDP_V6_FLOW,
1211 };
1212 
1213 struct virtchnl_filter {
1214 	union	virtchnl_flow_spec data;
1215 	union	virtchnl_flow_spec mask;
1216 
1217 	/* see enum virtchnl_flow_type */
1218 	s32 	flow_type;
1219 
1220 	/* see enum virtchnl_action */
1221 	s32	action;
1222 	u32	action_meta;
1223 	u8	field_flags;
1224 };
1225 
1226 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
1227 
1228 /* VIRTCHNL_OP_EVENT
1229  * PF sends this message to inform the VF driver of events that may affect it.
1230  * No direct response is expected from the VF, though it may generate other
1231  * messages in response to this one.
1232  */
1233 enum virtchnl_event_codes {
1234 	VIRTCHNL_EVENT_UNKNOWN = 0,
1235 	VIRTCHNL_EVENT_LINK_CHANGE,
1236 	VIRTCHNL_EVENT_RESET_IMPENDING,
1237 	VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
1238 };
1239 
1240 #define PF_EVENT_SEVERITY_INFO		0
1241 #define PF_EVENT_SEVERITY_ATTENTION	1
1242 #define PF_EVENT_SEVERITY_ACTION_REQUIRED	2
1243 #define PF_EVENT_SEVERITY_CERTAIN_DOOM	255
1244 
1245 struct virtchnl_pf_event {
1246 	/* see enum virtchnl_event_codes */
1247 	s32 event;
1248 	union {
1249 		/* If the PF driver does not support the new speed reporting
1250 		 * capabilities then use link_event else use link_event_adv to
1251 		 * get the speed and link information. The ability to understand
1252 		 * new speeds is indicated by setting the capability flag
1253 		 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
1254 		 * in virtchnl_vf_resource struct and can be used to determine
1255 		 * which link event struct to use below.
1256 		 */
1257 		struct {
1258 			enum virtchnl_link_speed link_speed;
1259 			bool link_status;
1260 			u8 pad[3];
1261 		} link_event;
1262 		struct {
1263 			/* link_speed provided in Mbps */
1264 			u32 link_speed;
1265 			u8 link_status;
1266 			u8 pad[3];
1267 		} link_event_adv;
1268 		struct {
1269 			/* link_speed provided in Mbps */
1270 			u32 link_speed;
1271 			u16 vport_id;
1272 			u8 link_status;
1273 			u8 pad;
1274 		} link_event_adv_vport;
1275 	} event_data;
1276 
1277 	s32 severity;
1278 };
1279 
1280 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
1281 
1282 /* VF reset states - these are written into the RSTAT register:
1283  * VFGEN_RSTAT on the VF
1284  * When the PF initiates a reset, it writes 0
1285  * When the reset is complete, it writes 1
1286  * When the PF detects that the VF has recovered, it writes 2
1287  * VF checks this register periodically to determine if a reset has occurred,
1288  * then polls it to know when the reset is complete.
1289  * If either the PF or VF reads the register while the hardware
1290  * is in a reset state, it will return DEADBEEF, which, when masked
1291  * will result in 3.
1292  */
1293 enum virtchnl_vfr_states {
1294 	VIRTCHNL_VFR_INPROGRESS = 0,
1295 	VIRTCHNL_VFR_COMPLETED,
1296 	VIRTCHNL_VFR_VFACTIVE,
1297 };
1298 
1299 /* TX and RX queue types are valid in legacy as well as split queue models.
1300  * With Split Queue model, 2 additional types are introduced - TX_COMPLETION
1301  * and RX_BUFFER. In split queue model, RX corresponds to the queue where HW
1302  * posts completions.
1303  */
1304 enum virtchnl_queue_type {
1305 	VIRTCHNL_QUEUE_TYPE_TX			= 0,
1306 	VIRTCHNL_QUEUE_TYPE_RX			= 1,
1307 	VIRTCHNL_QUEUE_TYPE_TX_COMPLETION	= 2,
1308 	VIRTCHNL_QUEUE_TYPE_RX_BUFFER		= 3,
1309 	VIRTCHNL_QUEUE_TYPE_CONFIG_TX		= 4,
1310 	VIRTCHNL_QUEUE_TYPE_CONFIG_RX		= 5
1311 };
1312 
1313 /* structure to specify a chunk of contiguous queues */
1314 struct virtchnl_queue_chunk {
1315 	/* see enum virtchnl_queue_type */
1316 	s32 type;
1317 	u16 start_queue_id;
1318 	u16 num_queues;
1319 };
1320 
1321 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_queue_chunk);
1322 
1323 /* structure to specify several chunks of contiguous queues */
1324 struct virtchnl_queue_chunks {
1325 	u16 num_chunks;
1326 	u16 rsvd;
1327 	struct virtchnl_queue_chunk chunks[1];
1328 };
1329 
1330 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_chunks);
1331 
1332 /* VIRTCHNL_OP_ENABLE_QUEUES_V2
1333  * VIRTCHNL_OP_DISABLE_QUEUES_V2
1334  * VIRTCHNL_OP_DEL_QUEUES
1335  *
1336  * If VIRTCHNL version was negotiated in VIRTCHNL_OP_VERSION as 2.0
1337  * then all of these ops are available.
1338  *
1339  * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
1340  * then VIRTCHNL_OP_ENABLE_QUEUES_V2 and VIRTCHNL_OP_DISABLE_QUEUES_V2 are
1341  * available.
1342  *
1343  * PF sends these messages to enable, disable or delete queues specified in
1344  * chunks. PF sends virtchnl_del_ena_dis_queues struct to specify the queues
1345  * to be enabled/disabled/deleted. Also applicable to single queue RX or
1346  * TX. CP performs requested action and returns status.
1347  */
1348 struct virtchnl_del_ena_dis_queues {
1349 	u16 vport_id;
1350 	u16 pad;
1351 	struct virtchnl_queue_chunks chunks;
1352 };
1353 
1354 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_del_ena_dis_queues);
1355 
1356 /* Virtchannel interrupt throttling rate index */
1357 enum virtchnl_itr_idx {
1358 	VIRTCHNL_ITR_IDX_0	= 0,
1359 	VIRTCHNL_ITR_IDX_1	= 1,
1360 	VIRTCHNL_ITR_IDX_NO_ITR	= 3,
1361 };
1362 
1363 /* Queue to vector mapping */
1364 struct virtchnl_queue_vector {
1365 	u16 queue_id;
1366 	u16 vector_id;
1367 	u8 pad[4];
1368 
1369 	/* see enum virtchnl_itr_idx */
1370 	s32 itr_idx;
1371 
1372 	/* see enum virtchnl_queue_type */
1373 	s32 queue_type;
1374 };
1375 
1376 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_queue_vector);
1377 
1378 /* VIRTCHNL_OP_MAP_QUEUE_VECTOR
1379  *
1380  * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
1381  * then only VIRTCHNL_OP_MAP_QUEUE_VECTOR is available.
1382  *
1383  * PF sends this message to map or unmap queues to vectors and ITR index
1384  * registers. External data buffer contains virtchnl_queue_vector_maps structure
1385  * that contains num_qv_maps of virtchnl_queue_vector structures.
1386  * CP maps the requested queue vector maps after validating the queue and vector
1387  * ids and returns a status code.
1388  */
1389 struct virtchnl_queue_vector_maps {
1390 	u16 vport_id;
1391 	u16 num_qv_maps;
1392 	u8 pad[4];
1393 	struct virtchnl_queue_vector qv_maps[1];
1394 };
1395 
1396 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_queue_vector_maps);
1397 
1398 /* Since VF messages are limited by u16 size, precalculate the maximum possible
1399  * values of nested elements in virtchnl structures that virtual channel can
1400  * possibly handle in a single message.
1401  */
1402 enum virtchnl_vector_limits {
1403 	VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX	=
1404 		((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) /
1405 		sizeof(struct virtchnl_queue_pair_info),
1406 
1407 	VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX		=
1408 		((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) /
1409 		sizeof(struct virtchnl_vector_map),
1410 
1411 	VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX	=
1412 		((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) /
1413 		sizeof(struct virtchnl_ether_addr),
1414 
1415 	VIRTCHNL_OP_ADD_DEL_VLAN_MAX		=
1416 		((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) /
1417 		sizeof(u16),
1418 
1419 	VIRTCHNL_OP_ENABLE_CHANNELS_MAX		=
1420 		((u16)(~0) - sizeof(struct virtchnl_tc_info)) /
1421 		sizeof(struct virtchnl_channel_info),
1422 
1423 	VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX	=
1424 		((u16)(~0) - sizeof(struct virtchnl_del_ena_dis_queues)) /
1425 		sizeof(struct virtchnl_queue_chunk),
1426 
1427 	VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX	=
1428 		((u16)(~0) - sizeof(struct virtchnl_queue_vector_maps)) /
1429 		sizeof(struct virtchnl_queue_vector),
1430 
1431 	VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX		=
1432 		((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list_v2)) /
1433 		sizeof(struct virtchnl_vlan_filter),
1434 };
1435 
1436 /**
1437  * virtchnl_vc_validate_vf_msg
1438  * @ver: Virtchnl version info
1439  * @v_opcode: Opcode for the message
1440  * @msg: pointer to the msg buffer
1441  * @msglen: msg length
1442  *
1443  * validate msg format against struct for each opcode
1444  */
1445 static inline int
1446 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
1447 			    u8 *msg, u16 msglen)
1448 {
1449 	bool err_msg_format = false;
1450 	u32 valid_len = 0;
1451 
1452 	/* Validate message length. */
1453 	switch (v_opcode) {
1454 	case VIRTCHNL_OP_VERSION:
1455 		valid_len = sizeof(struct virtchnl_version_info);
1456 		break;
1457 	case VIRTCHNL_OP_RESET_VF:
1458 		break;
1459 	case VIRTCHNL_OP_GET_VF_RESOURCES:
1460 		if (VF_IS_V11(ver))
1461 			valid_len = sizeof(u32);
1462 		break;
1463 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
1464 		valid_len = sizeof(struct virtchnl_txq_info);
1465 		break;
1466 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
1467 		valid_len = sizeof(struct virtchnl_rxq_info);
1468 		break;
1469 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1470 		valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
1471 		if (msglen >= valid_len) {
1472 			struct virtchnl_vsi_queue_config_info *vqc =
1473 			    (struct virtchnl_vsi_queue_config_info *)msg;
1474 
1475 			if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs >
1476 			    VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) {
1477 				err_msg_format = true;
1478 				break;
1479 			}
1480 
1481 			valid_len += (vqc->num_queue_pairs *
1482 				      sizeof(struct
1483 					     virtchnl_queue_pair_info));
1484 		}
1485 		break;
1486 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1487 		valid_len = sizeof(struct virtchnl_irq_map_info);
1488 		if (msglen >= valid_len) {
1489 			struct virtchnl_irq_map_info *vimi =
1490 			    (struct virtchnl_irq_map_info *)msg;
1491 
1492 			if (vimi->num_vectors == 0 || vimi->num_vectors >
1493 			    VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) {
1494 				err_msg_format = true;
1495 				break;
1496 			}
1497 
1498 			valid_len += (vimi->num_vectors *
1499 				      sizeof(struct virtchnl_vector_map));
1500 		}
1501 		break;
1502 	case VIRTCHNL_OP_ENABLE_QUEUES:
1503 	case VIRTCHNL_OP_DISABLE_QUEUES:
1504 		valid_len = sizeof(struct virtchnl_queue_select);
1505 		break;
1506 	case VIRTCHNL_OP_GET_MAX_RSS_QREGION:
1507 		break;
1508 	case VIRTCHNL_OP_ADD_ETH_ADDR:
1509 	case VIRTCHNL_OP_DEL_ETH_ADDR:
1510 		valid_len = sizeof(struct virtchnl_ether_addr_list);
1511 		if (msglen >= valid_len) {
1512 			struct virtchnl_ether_addr_list *veal =
1513 			    (struct virtchnl_ether_addr_list *)msg;
1514 
1515 			if (veal->num_elements == 0 || veal->num_elements >
1516 			    VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) {
1517 				err_msg_format = true;
1518 				break;
1519 			}
1520 
1521 			valid_len += veal->num_elements *
1522 			    sizeof(struct virtchnl_ether_addr);
1523 		}
1524 		break;
1525 	case VIRTCHNL_OP_ADD_VLAN:
1526 	case VIRTCHNL_OP_DEL_VLAN:
1527 		valid_len = sizeof(struct virtchnl_vlan_filter_list);
1528 		if (msglen >= valid_len) {
1529 			struct virtchnl_vlan_filter_list *vfl =
1530 			    (struct virtchnl_vlan_filter_list *)msg;
1531 
1532 			if (vfl->num_elements == 0 || vfl->num_elements >
1533 			    VIRTCHNL_OP_ADD_DEL_VLAN_MAX) {
1534 				err_msg_format = true;
1535 				break;
1536 			}
1537 
1538 			valid_len += vfl->num_elements * sizeof(u16);
1539 		}
1540 		break;
1541 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1542 		valid_len = sizeof(struct virtchnl_promisc_info);
1543 		break;
1544 	case VIRTCHNL_OP_GET_STATS:
1545 		valid_len = sizeof(struct virtchnl_queue_select);
1546 		break;
1547 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
1548 		valid_len = sizeof(struct virtchnl_rss_key);
1549 		if (msglen >= valid_len) {
1550 			struct virtchnl_rss_key *vrk =
1551 				(struct virtchnl_rss_key *)msg;
1552 
1553 			if (vrk->key_len == 0) {
1554 				/* zero length is allowed as input */
1555 				break;
1556 			}
1557 
1558 			valid_len += vrk->key_len - 1;
1559 		}
1560 		break;
1561 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
1562 		valid_len = sizeof(struct virtchnl_rss_lut);
1563 		if (msglen >= valid_len) {
1564 			struct virtchnl_rss_lut *vrl =
1565 				(struct virtchnl_rss_lut *)msg;
1566 
1567 			if (vrl->lut_entries == 0) {
1568 				/* zero entries is allowed as input */
1569 				break;
1570 			}
1571 
1572 			valid_len += vrl->lut_entries - 1;
1573 		}
1574 		break;
1575 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
1576 		break;
1577 	case VIRTCHNL_OP_SET_RSS_HENA:
1578 		valid_len = sizeof(struct virtchnl_rss_hena);
1579 		break;
1580 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1581 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1582 		break;
1583 	case VIRTCHNL_OP_REQUEST_QUEUES:
1584 		valid_len = sizeof(struct virtchnl_vf_res_request);
1585 		break;
1586 	case VIRTCHNL_OP_ENABLE_CHANNELS:
1587 		valid_len = sizeof(struct virtchnl_tc_info);
1588 		if (msglen >= valid_len) {
1589 			struct virtchnl_tc_info *vti =
1590 				(struct virtchnl_tc_info *)msg;
1591 
1592 			if (vti->num_tc == 0 || vti->num_tc >
1593 			    VIRTCHNL_OP_ENABLE_CHANNELS_MAX) {
1594 				err_msg_format = true;
1595 				break;
1596 			}
1597 
1598 			valid_len += (vti->num_tc - 1) *
1599 				     sizeof(struct virtchnl_channel_info);
1600 		}
1601 		break;
1602 	case VIRTCHNL_OP_DISABLE_CHANNELS:
1603 		break;
1604 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
1605 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
1606 		valid_len = sizeof(struct virtchnl_filter);
1607 		break;
1608 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
1609 		break;
1610 	case VIRTCHNL_OP_ADD_VLAN_V2:
1611 	case VIRTCHNL_OP_DEL_VLAN_V2:
1612 		valid_len = sizeof(struct virtchnl_vlan_filter_list_v2);
1613 		if (msglen >= valid_len) {
1614 			struct virtchnl_vlan_filter_list_v2 *vfl =
1615 			    (struct virtchnl_vlan_filter_list_v2 *)msg;
1616 
1617 			if (vfl->num_elements == 0 || vfl->num_elements >
1618 			    VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX) {
1619 				err_msg_format = true;
1620 				break;
1621 			}
1622 
1623 			valid_len += (vfl->num_elements - 1) *
1624 				sizeof(struct virtchnl_vlan_filter);
1625 		}
1626 		break;
1627 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1628 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1629 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1630 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1631 	case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2:
1632 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
1633 		valid_len = sizeof(struct virtchnl_vlan_setting);
1634 		break;
1635 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
1636 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
1637 		valid_len = sizeof(struct virtchnl_del_ena_dis_queues);
1638 		if (msglen >= valid_len) {
1639 			struct virtchnl_del_ena_dis_queues *qs =
1640 				(struct virtchnl_del_ena_dis_queues *)msg;
1641 			if (qs->chunks.num_chunks == 0 ||
1642 			    qs->chunks.num_chunks > VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX) {
1643 				err_msg_format = true;
1644 				break;
1645 			}
1646 			valid_len += (qs->chunks.num_chunks - 1) *
1647 				      sizeof(struct virtchnl_queue_chunk);
1648 		}
1649 		break;
1650 	case VIRTCHNL_OP_MAP_QUEUE_VECTOR:
1651 		valid_len = sizeof(struct virtchnl_queue_vector_maps);
1652 		if (msglen >= valid_len) {
1653 			struct virtchnl_queue_vector_maps *v_qp =
1654 				(struct virtchnl_queue_vector_maps *)msg;
1655 			if (v_qp->num_qv_maps == 0 ||
1656 			    v_qp->num_qv_maps > VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX) {
1657 				err_msg_format = true;
1658 				break;
1659 			}
1660 			valid_len += (v_qp->num_qv_maps - 1) *
1661 				      sizeof(struct virtchnl_queue_vector);
1662 		}
1663 		break;
1664 	/* These are always errors coming from the VF. */
1665 	case VIRTCHNL_OP_EVENT:
1666 	case VIRTCHNL_OP_UNKNOWN:
1667 	default:
1668 		return VIRTCHNL_STATUS_ERR_PARAM;
1669 	}
1670 	/* few more checks */
1671 	if (err_msg_format || valid_len != msglen)
1672 		return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
1673 
1674 	return 0;
1675 }
1676 #endif /* _VIRTCHNL_H_ */
1677