xref: /freebsd/sys/dev/ice/virtchnl.h (revision 4d846d26)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2022, 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 here.
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 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS	6
70 
71 /* These macros are used to generate compilation errors if a structure/union
72  * is not exactly the correct length. It gives a divide by zero error if the
73  * structure/union is not of the correct size, otherwise it creates an enum
74  * that is never used.
75  */
76 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
77 	{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
78 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
79 	{ virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
80 
81 /* Error Codes
82  * Note that many older versions of various iAVF drivers convert the reported
83  * status code directly into an iavf_status enumeration. For this reason, it
84  * is important that the values of these enumerations line up.
85  */
86 enum virtchnl_status_code {
87 	VIRTCHNL_STATUS_SUCCESS				= 0,
88 	VIRTCHNL_STATUS_ERR_PARAM			= -5,
89 	VIRTCHNL_STATUS_ERR_NO_MEMORY			= -18,
90 	VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH		= -38,
91 	VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR		= -39,
92 	VIRTCHNL_STATUS_ERR_INVALID_VF_ID		= -40,
93 	VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR		= -53,
94 	VIRTCHNL_STATUS_ERR_NOT_SUPPORTED		= -64,
95 };
96 
97 /* Backward compatibility */
98 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
99 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
100 
101 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT		0x0
102 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT		0x1
103 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT	0x2
104 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT		0x3
105 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT		0x4
106 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT		0x5
107 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT		0x6
108 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT		0x7
109 
110 enum virtchnl_link_speed {
111 	VIRTCHNL_LINK_SPEED_UNKNOWN	= 0,
112 	VIRTCHNL_LINK_SPEED_100MB	= BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
113 	VIRTCHNL_LINK_SPEED_1GB		= BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
114 	VIRTCHNL_LINK_SPEED_10GB	= BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
115 	VIRTCHNL_LINK_SPEED_40GB	= BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
116 	VIRTCHNL_LINK_SPEED_20GB	= BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
117 	VIRTCHNL_LINK_SPEED_25GB	= BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
118 	VIRTCHNL_LINK_SPEED_2_5GB	= BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
119 	VIRTCHNL_LINK_SPEED_5GB		= BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
120 };
121 
122 /* for hsplit_0 field of Rx HMC context */
123 /* deprecated with AVF 1.0 */
124 enum virtchnl_rx_hsplit {
125 	VIRTCHNL_RX_HSPLIT_NO_SPLIT      = 0,
126 	VIRTCHNL_RX_HSPLIT_SPLIT_L2      = 1,
127 	VIRTCHNL_RX_HSPLIT_SPLIT_IP      = 2,
128 	VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
129 	VIRTCHNL_RX_HSPLIT_SPLIT_SCTP    = 8,
130 };
131 
132 enum virtchnl_bw_limit_type {
133 	VIRTCHNL_BW_SHAPER = 0,
134 };
135 /* END GENERIC DEFINES */
136 
137 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
138  * of the virtchnl_msg structure.
139  */
140 enum virtchnl_ops {
141 /* The PF sends status change events to VFs using
142  * the VIRTCHNL_OP_EVENT opcode.
143  * VFs send requests to the PF using the other ops.
144  * Use of "advanced opcode" features must be negotiated as part of capabilities
145  * exchange and are not considered part of base mode feature set.
146  *
147  */
148 	VIRTCHNL_OP_UNKNOWN = 0,
149 	VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
150 	VIRTCHNL_OP_RESET_VF = 2,
151 	VIRTCHNL_OP_GET_VF_RESOURCES = 3,
152 	VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
153 	VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
154 	VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
155 	VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
156 	VIRTCHNL_OP_ENABLE_QUEUES = 8,
157 	VIRTCHNL_OP_DISABLE_QUEUES = 9,
158 	VIRTCHNL_OP_ADD_ETH_ADDR = 10,
159 	VIRTCHNL_OP_DEL_ETH_ADDR = 11,
160 	VIRTCHNL_OP_ADD_VLAN = 12,
161 	VIRTCHNL_OP_DEL_VLAN = 13,
162 	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
163 	VIRTCHNL_OP_GET_STATS = 15,
164 	VIRTCHNL_OP_RSVD = 16,
165 	VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
166 	/* opcode 19 is reserved */
167 	/* opcodes 20, 21, and 22 are reserved */
168 	VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
169 	VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
170 	VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
171 	VIRTCHNL_OP_SET_RSS_HENA = 26,
172 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
173 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
174 	VIRTCHNL_OP_REQUEST_QUEUES = 29,
175 	VIRTCHNL_OP_ENABLE_CHANNELS = 30,
176 	VIRTCHNL_OP_DISABLE_CHANNELS = 31,
177 	VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
178 	VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
179 	/* opcode 34 is reserved */
180 	/* opcodes 38, 39, 40, 41, 42 and 43 are reserved */
181 	/* opcode 44 is reserved */
182 	VIRTCHNL_OP_ADD_RSS_CFG = 45,
183 	VIRTCHNL_OP_DEL_RSS_CFG = 46,
184 	VIRTCHNL_OP_ADD_FDIR_FILTER = 47,
185 	VIRTCHNL_OP_DEL_FDIR_FILTER = 48,
186 	VIRTCHNL_OP_GET_MAX_RSS_QREGION = 50,
187 	VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS = 51,
188 	VIRTCHNL_OP_ADD_VLAN_V2 = 52,
189 	VIRTCHNL_OP_DEL_VLAN_V2 = 53,
190 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 = 54,
191 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 = 55,
192 	VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 = 56,
193 	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
194 	VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 = 58,
195 	VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 = 59,
196 	/* opcodes 60 through 65 are reserved */
197 	VIRTCHNL_OP_GET_QOS_CAPS = 66,
198 	VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP = 67,
199 	/* opcode 68 through 70 are reserved */
200 	VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107,
201 	VIRTCHNL_OP_DISABLE_QUEUES_V2 = 108,
202 	VIRTCHNL_OP_MAP_QUEUE_VECTOR = 111,
203 	VIRTCHNL_OP_CONFIG_QUEUE_BW = 112,
204 	VIRTCHNL_OP_CONFIG_QUANTA = 113,
205 	VIRTCHNL_OP_MAX,
206 };
207 
208 static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode)
209 {
210 	switch (v_opcode) {
211 	case VIRTCHNL_OP_UNKNOWN:
212 		return "VIRTCHNL_OP_UNKNOWN";
213 	case VIRTCHNL_OP_VERSION:
214 		return "VIRTCHNL_OP_VERSION";
215 	case VIRTCHNL_OP_RESET_VF:
216 		return "VIRTCHNL_OP_RESET_VF";
217 	case VIRTCHNL_OP_GET_VF_RESOURCES:
218 		return "VIRTCHNL_OP_GET_VF_RESOURCES";
219 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
220 		return "VIRTCHNL_OP_CONFIG_TX_QUEUE";
221 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
222 		return "VIRTCHNL_OP_CONFIG_RX_QUEUE";
223 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
224 		return "VIRTCHNL_OP_CONFIG_VSI_QUEUES";
225 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
226 		return "VIRTCHNL_OP_CONFIG_IRQ_MAP";
227 	case VIRTCHNL_OP_ENABLE_QUEUES:
228 		return "VIRTCHNL_OP_ENABLE_QUEUES";
229 	case VIRTCHNL_OP_DISABLE_QUEUES:
230 		return "VIRTCHNL_OP_DISABLE_QUEUES";
231 	case VIRTCHNL_OP_ADD_ETH_ADDR:
232 		return "VIRTCHNL_OP_ADD_ETH_ADDR";
233 	case VIRTCHNL_OP_DEL_ETH_ADDR:
234 		return "VIRTCHNL_OP_DEL_ETH_ADDR";
235 	case VIRTCHNL_OP_ADD_VLAN:
236 		return "VIRTCHNL_OP_ADD_VLAN";
237 	case VIRTCHNL_OP_DEL_VLAN:
238 		return "VIRTCHNL_OP_DEL_VLAN";
239 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
240 		return "VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE";
241 	case VIRTCHNL_OP_GET_STATS:
242 		return "VIRTCHNL_OP_GET_STATS";
243 	case VIRTCHNL_OP_RSVD:
244 		return "VIRTCHNL_OP_RSVD";
245 	case VIRTCHNL_OP_EVENT:
246 		return "VIRTCHNL_OP_EVENT";
247 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
248 		return "VIRTCHNL_OP_CONFIG_RSS_KEY";
249 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
250 		return "VIRTCHNL_OP_CONFIG_RSS_LUT";
251 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
252 		return "VIRTCHNL_OP_GET_RSS_HENA_CAPS";
253 	case VIRTCHNL_OP_SET_RSS_HENA:
254 		return "VIRTCHNL_OP_SET_RSS_HENA";
255 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
256 		return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING";
257 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
258 		return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING";
259 	case VIRTCHNL_OP_REQUEST_QUEUES:
260 		return "VIRTCHNL_OP_REQUEST_QUEUES";
261 	case VIRTCHNL_OP_ENABLE_CHANNELS:
262 		return "VIRTCHNL_OP_ENABLE_CHANNELS";
263 	case VIRTCHNL_OP_DISABLE_CHANNELS:
264 		return "VIRTCHNL_OP_DISABLE_CHANNELS";
265 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
266 		return "VIRTCHNL_OP_ADD_CLOUD_FILTER";
267 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
268 		return "VIRTCHNL_OP_DEL_CLOUD_FILTER";
269 	case VIRTCHNL_OP_ADD_RSS_CFG:
270 		return "VIRTCHNL_OP_ADD_RSS_CFG";
271 	case VIRTCHNL_OP_DEL_RSS_CFG:
272 		return "VIRTCHNL_OP_DEL_RSS_CFG";
273 	case VIRTCHNL_OP_ADD_FDIR_FILTER:
274 		return "VIRTCHNL_OP_ADD_FDIR_FILTER";
275 	case VIRTCHNL_OP_DEL_FDIR_FILTER:
276 		return "VIRTCHNL_OP_DEL_FDIR_FILTER";
277 	case VIRTCHNL_OP_GET_MAX_RSS_QREGION:
278 		return "VIRTCHNL_OP_GET_MAX_RSS_QREGION";
279 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
280 		return "VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS";
281 	case VIRTCHNL_OP_ADD_VLAN_V2:
282 		return "VIRTCHNL_OP_ADD_VLAN_V2";
283 	case VIRTCHNL_OP_DEL_VLAN_V2:
284 		return "VIRTCHNL_OP_DEL_VLAN_V2";
285 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
286 		return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2";
287 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
288 		return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2";
289 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
290 		return "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2";
291 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
292 		return "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2";
293 	case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2:
294 		return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2";
295 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
296 		return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2";
297 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
298 		return "VIRTCHNL_OP_ENABLE_QUEUES_V2";
299 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
300 		return "VIRTCHNL_OP_DISABLE_QUEUES_V2";
301 	case VIRTCHNL_OP_MAP_QUEUE_VECTOR:
302 		return "VIRTCHNL_OP_MAP_QUEUE_VECTOR";
303 	case VIRTCHNL_OP_MAX:
304 		return "VIRTCHNL_OP_MAX";
305 	default:
306 		return "Unsupported (update virtchnl.h)";
307 	}
308 }
309 
310 static inline const char *virtchnl_stat_str(enum virtchnl_status_code v_status)
311 {
312 	switch (v_status) {
313 	case VIRTCHNL_STATUS_SUCCESS:
314 		return "VIRTCHNL_STATUS_SUCCESS";
315 	case VIRTCHNL_STATUS_ERR_PARAM:
316 		return "VIRTCHNL_STATUS_ERR_PARAM";
317 	case VIRTCHNL_STATUS_ERR_NO_MEMORY:
318 		return "VIRTCHNL_STATUS_ERR_NO_MEMORY";
319 	case VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH:
320 		return "VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH";
321 	case VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR:
322 		return "VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR";
323 	case VIRTCHNL_STATUS_ERR_INVALID_VF_ID:
324 		return "VIRTCHNL_STATUS_ERR_INVALID_VF_ID";
325 	case VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR:
326 		return "VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR";
327 	case VIRTCHNL_STATUS_ERR_NOT_SUPPORTED:
328 		return "VIRTCHNL_STATUS_ERR_NOT_SUPPORTED";
329 	default:
330 		return "Unknown status code (update virtchnl.h)";
331 	}
332 }
333 
334 /* Virtual channel message descriptor. This overlays the admin queue
335  * descriptor. All other data is passed in external buffers.
336  */
337 
338 struct virtchnl_msg {
339 	u8 pad[8];			 /* AQ flags/opcode/len/retval fields */
340 
341 	/* avoid confusion with desc->opcode */
342 	enum virtchnl_ops v_opcode;
343 
344 	/* ditto for desc->retval */
345 	enum virtchnl_status_code v_retval;
346 	u32 vfid;			 /* used by PF when sending to VF */
347 };
348 
349 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
350 
351 /* Message descriptions and data structures. */
352 
353 /* VIRTCHNL_OP_VERSION
354  * VF posts its version number to the PF. PF responds with its version number
355  * in the same format, along with a return code.
356  * Reply from PF has its major/minor versions also in param0 and param1.
357  * If there is a major version mismatch, then the VF cannot operate.
358  * If there is a minor version mismatch, then the VF can operate but should
359  * add a warning to the system log.
360  *
361  * This enum element MUST always be specified as == 1, regardless of other
362  * changes in the API. The PF must always respond to this message without
363  * error regardless of version mismatch.
364  */
365 #define VIRTCHNL_VERSION_MAJOR		1
366 #define VIRTCHNL_VERSION_MINOR		1
367 #define VIRTCHNL_VERSION_MAJOR_2	2
368 #define VIRTCHNL_VERSION_MINOR_0	0
369 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS	0
370 
371 struct virtchnl_version_info {
372 	u32 major;
373 	u32 minor;
374 };
375 
376 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
377 
378 #define VF_IS_V10(_ver) (((_ver)->major == 1) && ((_ver)->minor == 0))
379 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
380 #define VF_IS_V20(_ver) (((_ver)->major == 2) && ((_ver)->minor == 0))
381 
382 /* VIRTCHNL_OP_RESET_VF
383  * VF sends this request to PF with no parameters
384  * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
385  * until reset completion is indicated. The admin queue must be reinitialized
386  * after this operation.
387  *
388  * When reset is complete, PF must ensure that all queues in all VSIs associated
389  * with the VF are stopped, all queue configurations in the HMC are set to 0,
390  * and all MAC and VLAN filters (except the default MAC address) on all VSIs
391  * are cleared.
392  */
393 
394 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
395  * vsi_type should always be 6 for backward compatibility. Add other fields
396  * as needed.
397  */
398 enum virtchnl_vsi_type {
399 	VIRTCHNL_VSI_TYPE_INVALID = 0,
400 	VIRTCHNL_VSI_SRIOV = 6,
401 };
402 
403 /* VIRTCHNL_OP_GET_VF_RESOURCES
404  * Version 1.0 VF sends this request to PF with no parameters
405  * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
406  * PF responds with an indirect message containing
407  * virtchnl_vf_resource and one or more
408  * virtchnl_vsi_resource structures.
409  */
410 
411 struct virtchnl_vsi_resource {
412 	u16 vsi_id;
413 	u16 num_queue_pairs;
414 
415 	/* see enum virtchnl_vsi_type */
416 	s32 vsi_type;
417 	u16 qset_handle;
418 	u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
419 };
420 
421 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
422 
423 /* VF capability flags
424  * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
425  * TX/RX Checksum offloading and TSO for non-tunnelled packets.
426  */
427 #define VIRTCHNL_VF_OFFLOAD_L2			BIT(0)
428 #define VIRTCHNL_VF_OFFLOAD_IWARP		BIT(1)
429 #define VIRTCHNL_VF_CAP_RDMA			VIRTCHNL_VF_OFFLOAD_IWARP
430 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ		BIT(3)
431 #define VIRTCHNL_VF_OFFLOAD_RSS_REG		BIT(4)
432 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR		BIT(5)
433 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES		BIT(6)
434 /* used to negotiate communicating link speeds in Mbps */
435 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED		BIT(7)
436 	/* BIT(8) is reserved */
437 #define VIRTCHNL_VF_LARGE_NUM_QPAIRS		BIT(9)
438 #define VIRTCHNL_VF_OFFLOAD_CRC			BIT(10)
439 #define VIRTCHNL_VF_OFFLOAD_VLAN_V2		BIT(15)
440 #define VIRTCHNL_VF_OFFLOAD_VLAN		BIT(16)
441 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING		BIT(17)
442 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2	BIT(18)
443 #define VIRTCHNL_VF_OFFLOAD_RSS_PF		BIT(19)
444 #define VIRTCHNL_VF_OFFLOAD_ENCAP		BIT(20)
445 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM		BIT(21)
446 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM	BIT(22)
447 #define VIRTCHNL_VF_OFFLOAD_ADQ			BIT(23)
448 #define VIRTCHNL_VF_OFFLOAD_ADQ_V2		BIT(24)
449 #define VIRTCHNL_VF_OFFLOAD_USO			BIT(25)
450 	/* BIT(26) is reserved */
451 #define VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF		BIT(27)
452 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF		BIT(28)
453 #define VIRTCHNL_VF_OFFLOAD_QOS			BIT(29)
454 	/* BIT(30) is reserved */
455 	/* BIT(31) is reserved */
456 
457 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
458 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
459 			       VIRTCHNL_VF_OFFLOAD_RSS_PF)
460 
461 struct virtchnl_vf_resource {
462 	u16 num_vsis;
463 	u16 num_queue_pairs;
464 	u16 max_vectors;
465 	u16 max_mtu;
466 
467 	u32 vf_cap_flags;
468 	u32 rss_key_size;
469 	u32 rss_lut_size;
470 
471 	struct virtchnl_vsi_resource vsi_res[1];
472 };
473 
474 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
475 
476 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
477  * VF sends this message to set up parameters for one TX queue.
478  * External data buffer contains one instance of virtchnl_txq_info.
479  * PF configures requested queue and returns a status code.
480  */
481 
482 /* Tx queue config info */
483 struct virtchnl_txq_info {
484 	u16 vsi_id;
485 	u16 queue_id;
486 	u16 ring_len;		/* number of descriptors, multiple of 8 */
487 	u16 headwb_enabled; /* deprecated with AVF 1.0 */
488 	u64 dma_ring_addr;
489 	u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
490 };
491 
492 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
493 
494 /* RX descriptor IDs (range from 0 to 63) */
495 enum virtchnl_rx_desc_ids {
496 	VIRTCHNL_RXDID_0_16B_BASE		= 0,
497 	VIRTCHNL_RXDID_1_32B_BASE		= 1,
498 	VIRTCHNL_RXDID_2_FLEX_SQ_NIC		= 2,
499 	VIRTCHNL_RXDID_3_FLEX_SQ_SW		= 3,
500 	VIRTCHNL_RXDID_4_FLEX_SQ_NIC_VEB	= 4,
501 	VIRTCHNL_RXDID_5_FLEX_SQ_NIC_ACL	= 5,
502 	VIRTCHNL_RXDID_6_FLEX_SQ_NIC_2		= 6,
503 	VIRTCHNL_RXDID_7_HW_RSVD		= 7,
504 	/* 8 through 15 are reserved */
505 	VIRTCHNL_RXDID_16_COMMS_GENERIC 	= 16,
506 	VIRTCHNL_RXDID_17_COMMS_AUX_VLAN 	= 17,
507 	VIRTCHNL_RXDID_18_COMMS_AUX_IPV4 	= 18,
508 	VIRTCHNL_RXDID_19_COMMS_AUX_IPV6 	= 19,
509 	VIRTCHNL_RXDID_20_COMMS_AUX_FLOW 	= 20,
510 	VIRTCHNL_RXDID_21_COMMS_AUX_TCP 	= 21,
511 	/* 22 through 63 are reserved */
512 };
513 
514 /* RX descriptor ID bitmasks */
515 enum virtchnl_rx_desc_id_bitmasks {
516 	VIRTCHNL_RXDID_0_16B_BASE_M		= BIT(VIRTCHNL_RXDID_0_16B_BASE),
517 	VIRTCHNL_RXDID_1_32B_BASE_M		= BIT(VIRTCHNL_RXDID_1_32B_BASE),
518 	VIRTCHNL_RXDID_2_FLEX_SQ_NIC_M		= BIT(VIRTCHNL_RXDID_2_FLEX_SQ_NIC),
519 	VIRTCHNL_RXDID_3_FLEX_SQ_SW_M		= BIT(VIRTCHNL_RXDID_3_FLEX_SQ_SW),
520 	VIRTCHNL_RXDID_4_FLEX_SQ_NIC_VEB_M	= BIT(VIRTCHNL_RXDID_4_FLEX_SQ_NIC_VEB),
521 	VIRTCHNL_RXDID_5_FLEX_SQ_NIC_ACL_M	= BIT(VIRTCHNL_RXDID_5_FLEX_SQ_NIC_ACL),
522 	VIRTCHNL_RXDID_6_FLEX_SQ_NIC_2_M	= BIT(VIRTCHNL_RXDID_6_FLEX_SQ_NIC_2),
523 	VIRTCHNL_RXDID_7_HW_RSVD_M		= BIT(VIRTCHNL_RXDID_7_HW_RSVD),
524 	/* 9 through 15 are reserved */
525 	VIRTCHNL_RXDID_16_COMMS_GENERIC_M	= BIT(VIRTCHNL_RXDID_16_COMMS_GENERIC),
526 	VIRTCHNL_RXDID_17_COMMS_AUX_VLAN_M	= BIT(VIRTCHNL_RXDID_17_COMMS_AUX_VLAN),
527 	VIRTCHNL_RXDID_18_COMMS_AUX_IPV4_M	= BIT(VIRTCHNL_RXDID_18_COMMS_AUX_IPV4),
528 	VIRTCHNL_RXDID_19_COMMS_AUX_IPV6_M	= BIT(VIRTCHNL_RXDID_19_COMMS_AUX_IPV6),
529 	VIRTCHNL_RXDID_20_COMMS_AUX_FLOW_M	= BIT(VIRTCHNL_RXDID_20_COMMS_AUX_FLOW),
530 	VIRTCHNL_RXDID_21_COMMS_AUX_TCP_M	= BIT(VIRTCHNL_RXDID_21_COMMS_AUX_TCP),
531 	/* 22 through 63 are reserved */
532 };
533 
534 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
535  * VF sends this message to set up parameters for one RX queue.
536  * External data buffer contains one instance of virtchnl_rxq_info.
537  * PF configures requested queue and returns a status code. The
538  * crc_disable flag disables CRC stripping on the VF. Setting
539  * the crc_disable flag to 1 will disable CRC stripping for each
540  * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC
541  * offload must have been set prior to sending this info or the PF
542  * will ignore the request. This flag should be set the same for
543  * all of the queues for a VF.
544  */
545 
546 /* Rx queue config info */
547 struct virtchnl_rxq_info {
548 	u16 vsi_id;
549 	u16 queue_id;
550 	u32 ring_len;		/* number of descriptors, multiple of 32 */
551 	u16 hdr_size;
552 	u16 splithdr_enabled; /* deprecated with AVF 1.0 */
553 	u32 databuffer_size;
554 	u32 max_pkt_size;
555 	u8 crc_disable;
556 	u8 pad1[3];
557 	u64 dma_ring_addr;
558 
559 	/* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
560 	s32 rx_split_pos;
561 	u32 pad2;
562 };
563 
564 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
565 
566 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
567  * VF sends this message to set parameters for active TX and RX queues
568  * associated with the specified VSI.
569  * PF configures queues and returns status.
570  * If the number of queues specified is greater than the number of queues
571  * associated with the VSI, an error is returned and no queues are configured.
572  * NOTE: The VF is not required to configure all queues in a single request.
573  * It may send multiple messages. PF drivers must correctly handle all VF
574  * requests.
575  */
576 struct virtchnl_queue_pair_info {
577 	/* NOTE: vsi_id and queue_id should be identical for both queues. */
578 	struct virtchnl_txq_info txq;
579 	struct virtchnl_rxq_info rxq;
580 };
581 
582 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
583 
584 struct virtchnl_vsi_queue_config_info {
585 	u16 vsi_id;
586 	u16 num_queue_pairs;
587 	u32 pad;
588 	struct virtchnl_queue_pair_info qpair[1];
589 };
590 
591 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
592 
593 /* VIRTCHNL_OP_REQUEST_QUEUES
594  * VF sends this message to request the PF to allocate additional queues to
595  * this VF.  Each VF gets a guaranteed number of queues on init but asking for
596  * additional queues must be negotiated.  This is a best effort request as it
597  * is possible the PF does not have enough queues left to support the request.
598  * If the PF cannot support the number requested it will respond with the
599  * maximum number it is able to support.  If the request is successful, PF will
600  * then reset the VF to institute required changes.
601  */
602 
603 /* VF resource request */
604 struct virtchnl_vf_res_request {
605 	u16 num_queue_pairs;
606 };
607 
608 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
609  * VF uses this message to map vectors to queues.
610  * The rxq_map and txq_map fields are bitmaps used to indicate which queues
611  * are to be associated with the specified vector.
612  * The "other" causes are always mapped to vector 0. The VF may not request
613  * that vector 0 be used for traffic.
614  * PF configures interrupt mapping and returns status.
615  * NOTE: due to hardware requirements, all active queues (both TX and RX)
616  * should be mapped to interrupts, even if the driver intends to operate
617  * only in polling mode. In this case the interrupt may be disabled, but
618  * the ITR timer will still run to trigger writebacks.
619  */
620 struct virtchnl_vector_map {
621 	u16 vsi_id;
622 	u16 vector_id;
623 	u16 rxq_map;
624 	u16 txq_map;
625 	u16 rxitr_idx;
626 	u16 txitr_idx;
627 };
628 
629 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
630 
631 struct virtchnl_irq_map_info {
632 	u16 num_vectors;
633 	struct virtchnl_vector_map vecmap[1];
634 };
635 
636 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
637 
638 /* VIRTCHNL_OP_ENABLE_QUEUES
639  * VIRTCHNL_OP_DISABLE_QUEUES
640  * VF sends these message to enable or disable TX/RX queue pairs.
641  * The queues fields are bitmaps indicating which queues to act upon.
642  * (Currently, we only support 16 queues per VF, but we make the field
643  * u32 to allow for expansion.)
644  * PF performs requested action and returns status.
645  * NOTE: The VF is not required to enable/disable all queues in a single
646  * request. It may send multiple messages.
647  * PF drivers must correctly handle all VF requests.
648  */
649 struct virtchnl_queue_select {
650 	u16 vsi_id;
651 	u16 pad;
652 	u32 rx_queues;
653 	u32 tx_queues;
654 };
655 
656 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
657 
658 /* VIRTCHNL_OP_GET_MAX_RSS_QREGION
659  *
660  * if VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
661  * then this op must be supported.
662  *
663  * VF sends this message in order to query the max RSS queue region
664  * size supported by PF, when VIRTCHNL_VF_LARGE_NUM_QPAIRS is enabled.
665  * This information should be used when configuring the RSS LUT and/or
666  * configuring queue region based filters.
667  *
668  * The maximum RSS queue region is 2^qregion_width. So, a qregion_width
669  * of 6 would inform the VF that the PF supports a maximum RSS queue region
670  * of 64.
671  *
672  * A queue region represents a range of queues that can be used to configure
673  * a RSS LUT. For example, if a VF is given 64 queues, but only a max queue
674  * region size of 16 (i.e. 2^qregion_width = 16) then it will only be able
675  * to configure the RSS LUT with queue indices from 0 to 15. However, other
676  * filters can be used to direct packets to queues >15 via specifying a queue
677  * base/offset and queue region width.
678  */
679 struct virtchnl_max_rss_qregion {
680 	u16 vport_id;
681 	u16 qregion_width;
682 	u8 pad[4];
683 };
684 
685 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_max_rss_qregion);
686 
687 /* VIRTCHNL_OP_ADD_ETH_ADDR
688  * VF sends this message in order to add one or more unicast or multicast
689  * address filters for the specified VSI.
690  * PF adds the filters and returns status.
691  */
692 
693 /* VIRTCHNL_OP_DEL_ETH_ADDR
694  * VF sends this message in order to remove one or more unicast or multicast
695  * filters for the specified VSI.
696  * PF removes the filters and returns status.
697  */
698 
699 /* VIRTCHNL_ETHER_ADDR_LEGACY
700  * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad
701  * bytes. Moving forward all VF drivers should not set type to
702  * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy
703  * behavior. The control plane function (i.e. PF) can use a best effort method
704  * of tracking the primary/device unicast in this case, but there is no
705  * guarantee and functionality depends on the implementation of the PF.
706  */
707 
708 /* VIRTCHNL_ETHER_ADDR_PRIMARY
709  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the
710  * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and
711  * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane
712  * function (i.e. PF) to accurately track and use this MAC address for
713  * displaying on the host and for VM/function reset.
714  */
715 
716 /* VIRTCHNL_ETHER_ADDR_EXTRA
717  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra
718  * unicast and/or multicast filters that are being added/deleted via
719  * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively.
720  */
721 struct virtchnl_ether_addr {
722 	u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
723 	u8 type;
724 #define VIRTCHNL_ETHER_ADDR_LEGACY	0
725 #define VIRTCHNL_ETHER_ADDR_PRIMARY	1
726 #define VIRTCHNL_ETHER_ADDR_EXTRA	2
727 #define VIRTCHNL_ETHER_ADDR_TYPE_MASK	3 /* first two bits of type are valid */
728 	u8 pad;
729 };
730 
731 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
732 
733 struct virtchnl_ether_addr_list {
734 	u16 vsi_id;
735 	u16 num_elements;
736 	struct virtchnl_ether_addr list[1];
737 };
738 
739 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
740 
741 /* VIRTCHNL_OP_ADD_VLAN
742  * VF sends this message to add one or more VLAN tag filters for receives.
743  * PF adds the filters and returns status.
744  * If a port VLAN is configured by the PF, this operation will return an
745  * error to the VF.
746  */
747 
748 /* VIRTCHNL_OP_DEL_VLAN
749  * VF sends this message to remove one or more VLAN tag filters for receives.
750  * PF removes the filters and returns status.
751  * If a port VLAN is configured by the PF, this operation will return an
752  * error to the VF.
753  */
754 
755 struct virtchnl_vlan_filter_list {
756 	u16 vsi_id;
757 	u16 num_elements;
758 	u16 vlan_id[1];
759 };
760 
761 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
762 
763 /* This enum is used for all of the VIRTCHNL_VF_OFFLOAD_VLAN_V2_CAPS related
764  * structures and opcodes.
765  *
766  * VIRTCHNL_VLAN_UNSUPPORTED - This field is not supported and if a VF driver
767  * populates it the PF should return VIRTCHNL_STATUS_ERR_NOT_SUPPORTED.
768  *
769  * VIRTCHNL_VLAN_ETHERTYPE_8100 - This field supports 0x8100 ethertype.
770  * VIRTCHNL_VLAN_ETHERTYPE_88A8 - This field supports 0x88A8 ethertype.
771  * VIRTCHNL_VLAN_ETHERTYPE_9100 - This field supports 0x9100 ethertype.
772  *
773  * VIRTCHNL_VLAN_ETHERTYPE_AND - Used when multiple ethertypes can be supported
774  * by the PF concurrently. For example, if the PF can support
775  * VIRTCHNL_VLAN_ETHERTYPE_8100 AND VIRTCHNL_VLAN_ETHERTYPE_88A8 filters it
776  * would OR the following bits:
777  *
778  *	VIRTHCNL_VLAN_ETHERTYPE_8100 |
779  *	VIRTCHNL_VLAN_ETHERTYPE_88A8 |
780  *	VIRTCHNL_VLAN_ETHERTYPE_AND;
781  *
782  * The VF would interpret this as VLAN filtering can be supported on both 0x8100
783  * and 0x88A8 VLAN ethertypes.
784  *
785  * VIRTCHNL_ETHERTYPE_XOR - Used when only a single ethertype can be supported
786  * by the PF concurrently. For example if the PF can support
787  * VIRTCHNL_VLAN_ETHERTYPE_8100 XOR VIRTCHNL_VLAN_ETHERTYPE_88A8 stripping
788  * offload it would OR the following bits:
789  *
790  *	VIRTCHNL_VLAN_ETHERTYPE_8100 |
791  *	VIRTCHNL_VLAN_ETHERTYPE_88A8 |
792  *	VIRTCHNL_VLAN_ETHERTYPE_XOR;
793  *
794  * The VF would interpret this as VLAN stripping can be supported on either
795  * 0x8100 or 0x88a8 VLAN ethertypes. So when requesting VLAN stripping via
796  * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 the specified ethertype will override
797  * the previously set value.
798  *
799  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 - Used to tell the VF to insert and/or
800  * strip the VLAN tag using the L2TAG1 field of the Tx/Rx descriptors.
801  *
802  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to insert hardware
803  * offloaded VLAN tags using the L2TAG2 field of the Tx descriptor.
804  *
805  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to strip hardware
806  * offloaded VLAN tags using the L2TAG2_2 field of the Rx descriptor.
807  *
808  * VIRTCHNL_VLAN_PRIO - This field supports VLAN priority bits. This is used for
809  * VLAN filtering if the underlying PF supports it.
810  *
811  * VIRTCHNL_VLAN_TOGGLE_ALLOWED - This field is used to say whether a
812  * certain VLAN capability can be toggled. For example if the underlying PF/CP
813  * allows the VF to toggle VLAN filtering, stripping, and/or insertion it should
814  * set this bit along with the supported ethertypes.
815  */
816 enum virtchnl_vlan_support {
817 	VIRTCHNL_VLAN_UNSUPPORTED =		0,
818 	VIRTCHNL_VLAN_ETHERTYPE_8100 =		0x00000001,
819 	VIRTCHNL_VLAN_ETHERTYPE_88A8 =		0x00000002,
820 	VIRTCHNL_VLAN_ETHERTYPE_9100 =		0x00000004,
821 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 =	0x00000100,
822 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 =	0x00000200,
823 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 =	0x00000400,
824 	VIRTCHNL_VLAN_PRIO =			0x01000000,
825 	VIRTCHNL_VLAN_FILTER_MASK =		0x10000000,
826 	VIRTCHNL_VLAN_ETHERTYPE_AND =		0x20000000,
827 	VIRTCHNL_VLAN_ETHERTYPE_XOR =		0x40000000,
828 	VIRTCHNL_VLAN_TOGGLE =			0x80000000
829 };
830 
831 /* This structure is used as part of the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
832  * for filtering, insertion, and stripping capabilities.
833  *
834  * If only outer capabilities are supported (for filtering, insertion, and/or
835  * stripping) then this refers to the outer most or single VLAN from the VF's
836  * perspective.
837  *
838  * If only inner capabilities are supported (for filtering, insertion, and/or
839  * stripping) then this refers to the outer most or single VLAN from the VF's
840  * perspective. Functionally this is the same as if only outer capabilities are
841  * supported. The VF driver is just forced to use the inner fields when
842  * adding/deleting filters and enabling/disabling offloads (if supported).
843  *
844  * If both outer and inner capabilities are supported (for filtering, insertion,
845  * and/or stripping) then outer refers to the outer most or single VLAN and
846  * inner refers to the second VLAN, if it exists, in the packet.
847  *
848  * There is no support for tunneled VLAN offloads, so outer or inner are never
849  * referring to a tunneled packet from the VF's perspective.
850  */
851 struct virtchnl_vlan_supported_caps {
852 	u32 outer;
853 	u32 inner;
854 };
855 
856 /* The PF populates these fields based on the supported VLAN filtering. If a
857  * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
858  * reject any VIRTCHNL_OP_ADD_VLAN_V2 or VIRTCHNL_OP_DEL_VLAN_V2 messages using
859  * the unsupported fields.
860  *
861  * Also, a VF is only allowed to toggle its VLAN filtering setting if the
862  * VIRTCHNL_VLAN_TOGGLE bit is set.
863  *
864  * The ethertype(s) specified in the ethertype_init field are the ethertypes
865  * enabled for VLAN filtering. VLAN filtering in this case refers to the outer
866  * most VLAN from the VF's perspective. If both inner and outer filtering are
867  * allowed then ethertype_init only refers to the outer most VLAN as only
868  * VLAN ethertype supported for inner VLAN filtering is
869  * VIRTCHNL_VLAN_ETHERTYPE_8100. By default, inner VLAN filtering is disabled
870  * when both inner and outer filtering are allowed.
871  *
872  * The max_filters field tells the VF how many VLAN filters it's allowed to have
873  * at any one time. If it exceeds this amount and tries to add another filter,
874  * then the request will be rejected by the PF. To prevent failures, the VF
875  * should keep track of how many VLAN filters it has added and not attempt to
876  * add more than max_filters.
877  */
878 struct virtchnl_vlan_filtering_caps {
879 	struct virtchnl_vlan_supported_caps filtering_support;
880 	u32 ethertype_init;
881 	u16 max_filters;
882 	u8 pad[2];
883 };
884 
885 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_filtering_caps);
886 
887 /* This enum is used for the virtchnl_vlan_offload_caps structure to specify
888  * if the PF supports a different ethertype for stripping and insertion.
889  *
890  * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION - The ethertype(s) specified
891  * for stripping affect the ethertype(s) specified for insertion and visa versa
892  * as well. If the VF tries to configure VLAN stripping via
893  * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 with VIRTCHNL_VLAN_ETHERTYPE_8100 then
894  * that will be the ethertype for both stripping and insertion.
895  *
896  * VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED - The ethertype(s) specified for
897  * stripping do not affect the ethertype(s) specified for insertion and visa
898  * versa.
899  */
900 enum virtchnl_vlan_ethertype_match {
901 	VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION = 0,
902 	VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED = 1,
903 };
904 
905 /* The PF populates these fields based on the supported VLAN offloads. If a
906  * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
907  * reject any VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 or
908  * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 messages using the unsupported fields.
909  *
910  * Also, a VF is only allowed to toggle its VLAN offload setting if the
911  * VIRTCHNL_VLAN_TOGGLE_ALLOWED bit is set.
912  *
913  * The VF driver needs to be aware of how the tags are stripped by hardware and
914  * inserted by the VF driver based on the level of offload support. The PF will
915  * populate these fields based on where the VLAN tags are expected to be
916  * offloaded via the VIRTHCNL_VLAN_TAG_LOCATION_* bits. The VF will need to
917  * interpret these fields. See the definition of the
918  * VIRTCHNL_VLAN_TAG_LOCATION_* bits above the virtchnl_vlan_support
919  * enumeration.
920  */
921 struct virtchnl_vlan_offload_caps {
922 	struct virtchnl_vlan_supported_caps stripping_support;
923 	struct virtchnl_vlan_supported_caps insertion_support;
924 	u32 ethertype_init;
925 	u8 ethertype_match;
926 	u8 pad[3];
927 };
928 
929 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_vlan_offload_caps);
930 
931 /* VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
932  * VF sends this message to determine its VLAN capabilities.
933  *
934  * PF will mark which capabilities it supports based on hardware support and
935  * current configuration. For example, if a port VLAN is configured the PF will
936  * not allow outer VLAN filtering, stripping, or insertion to be configured so
937  * it will block these features from the VF.
938  *
939  * The VF will need to cross reference its capabilities with the PFs
940  * capabilities in the response message from the PF to determine the VLAN
941  * support.
942  */
943 struct virtchnl_vlan_caps {
944 	struct virtchnl_vlan_filtering_caps filtering;
945 	struct virtchnl_vlan_offload_caps offloads;
946 };
947 
948 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_caps);
949 
950 struct virtchnl_vlan {
951 	u16 tci;	/* tci[15:13] = PCP and tci[11:0] = VID */
952 	u16 tci_mask;	/* only valid if VIRTCHNL_VLAN_FILTER_MASK set in
953 			 * filtering caps
954 			 */
955 	u16 tpid;	/* 0x8100, 0x88a8, etc. and only type(s) set in
956 			 * filtering caps. Note that tpid here does not refer to
957 			 * VIRTCHNL_VLAN_ETHERTYPE_*, but it refers to the
958 			 * actual 2-byte VLAN TPID
959 			 */
960 	u8 pad[2];
961 };
962 
963 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan);
964 
965 struct virtchnl_vlan_filter {
966 	struct virtchnl_vlan inner;
967 	struct virtchnl_vlan outer;
968 	u8 pad[16];
969 };
970 
971 VIRTCHNL_CHECK_STRUCT_LEN(32, virtchnl_vlan_filter);
972 
973 /* VIRTCHNL_OP_ADD_VLAN_V2
974  * VIRTCHNL_OP_DEL_VLAN_V2
975  *
976  * VF sends these messages to add/del one or more VLAN tag filters for Rx
977  * traffic.
978  *
979  * The PF attempts to add the filters and returns status.
980  *
981  * The VF should only ever attempt to add/del virtchnl_vlan_filter(s) using the
982  * supported fields negotiated via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS.
983  */
984 struct virtchnl_vlan_filter_list_v2 {
985 	u16 vport_id;
986 	u16 num_elements;
987 	u8 pad[4];
988 	struct virtchnl_vlan_filter filters[1];
989 };
990 
991 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_filter_list_v2);
992 
993 /* VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
994  * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
995  * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
996  * VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
997  *
998  * VF sends this message to enable or disable VLAN stripping or insertion. It
999  * also needs to specify an ethertype. The VF knows which VLAN ethertypes are
1000  * allowed and whether or not it's allowed to enable/disable the specific
1001  * offload via the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
1002  * parse the virtchnl_vlan_caps.offloads fields to determine which offload
1003  * messages are allowed.
1004  *
1005  * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
1006  * following manner the VF will be allowed to enable and/or disable 0x8100 inner
1007  * VLAN insertion and/or stripping via the opcodes listed above. Inner in this
1008  * case means the outer most or single VLAN from the VF's perspective. This is
1009  * because no outer offloads are supported. See the comments above the
1010  * virtchnl_vlan_supported_caps structure for more details.
1011  *
1012  * virtchnl_vlan_caps.offloads.stripping_support.inner =
1013  *			VIRTCHNL_VLAN_TOGGLE |
1014  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
1015  *
1016  * virtchnl_vlan_caps.offloads.insertion_support.inner =
1017  *			VIRTCHNL_VLAN_TOGGLE |
1018  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
1019  *
1020  * In order to enable inner (again note that in this case inner is the outer
1021  * most or single VLAN from the VF's perspective) VLAN stripping for 0x8100
1022  * VLANs, the VF would populate the virtchnl_vlan_setting structure in the
1023  * following manner and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
1024  *
1025  * virtchnl_vlan_setting.inner_ethertype_setting =
1026  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
1027  *
1028  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
1029  * initialization.
1030  *
1031  * The reason that VLAN TPID(s) are not being used for the
1032  * outer_ethertype_setting and inner_ethertype_setting fields is because it's
1033  * possible a device could support VLAN insertion and/or stripping offload on
1034  * multiple ethertypes concurrently, so this method allows a VF to request
1035  * multiple ethertypes in one message using the virtchnl_vlan_support
1036  * enumeration.
1037  *
1038  * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
1039  * following manner the VF will be allowed to enable 0x8100 and 0x88a8 outer
1040  * VLAN insertion and stripping simultaneously. The
1041  * virtchnl_vlan_caps.offloads.ethertype_match field will also have to be
1042  * populated based on what the PF can support.
1043  *
1044  * virtchnl_vlan_caps.offloads.stripping_support.outer =
1045  *			VIRTCHNL_VLAN_TOGGLE |
1046  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1047  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
1048  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
1049  *
1050  * virtchnl_vlan_caps.offloads.insertion_support.outer =
1051  *			VIRTCHNL_VLAN_TOGGLE |
1052  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1053  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
1054  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
1055  *
1056  * In order to enable outer VLAN stripping for 0x8100 and 0x88a8 VLANs, the VF
1057  * would populate the virthcnl_vlan_offload_structure in the following manner
1058  * and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
1059  *
1060  * virtchnl_vlan_setting.outer_ethertype_setting =
1061  *			VIRTHCNL_VLAN_ETHERTYPE_8100 |
1062  *			VIRTHCNL_VLAN_ETHERTYPE_88A8;
1063  *
1064  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
1065  * initialization.
1066  *
1067  * There is also the case where a PF and the underlying hardware can support
1068  * VLAN offloads on multiple ethertypes, but not concurrently. For example, if
1069  * the PF populates the virtchnl_vlan_caps.offloads in the following manner the
1070  * VF will be allowed to enable and/or disable 0x8100 XOR 0x88a8 outer VLAN
1071  * offloads. The ethertypes must match for stripping and insertion.
1072  *
1073  * virtchnl_vlan_caps.offloads.stripping_support.outer =
1074  *			VIRTCHNL_VLAN_TOGGLE |
1075  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1076  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
1077  *			VIRTCHNL_VLAN_ETHERTYPE_XOR;
1078  *
1079  * virtchnl_vlan_caps.offloads.insertion_support.outer =
1080  *			VIRTCHNL_VLAN_TOGGLE |
1081  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1082  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
1083  *			VIRTCHNL_VLAN_ETHERTYPE_XOR;
1084  *
1085  * virtchnl_vlan_caps.offloads.ethertype_match =
1086  *			VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
1087  *
1088  * In order to enable outer VLAN stripping for 0x88a8 VLANs, the VF would
1089  * populate the virtchnl_vlan_setting structure in the following manner and send
1090  * the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2. Also, this will change the
1091  * ethertype for VLAN insertion if it's enabled. So, for completeness, a
1092  * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 with the same ethertype should be sent.
1093  *
1094  * virtchnl_vlan_setting.outer_ethertype_setting = VIRTHCNL_VLAN_ETHERTYPE_88A8;
1095  *
1096  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
1097  * initialization.
1098  *
1099  * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2
1100  * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2
1101  *
1102  * VF sends this message to enable or disable VLAN filtering. It also needs to
1103  * specify an ethertype. The VF knows which VLAN ethertypes are allowed and
1104  * whether or not it's allowed to enable/disable filtering via the
1105  * VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
1106  * parse the virtchnl_vlan_caps.filtering fields to determine which, if any,
1107  * filtering messages are allowed.
1108  *
1109  * For example, if the PF populates the virtchnl_vlan_caps.filtering in the
1110  * following manner the VF will be allowed to enable/disable 0x8100 and 0x88a8
1111  * outer VLAN filtering together. Note, that the VIRTCHNL_VLAN_ETHERTYPE_AND
1112  * means that all filtering ethertypes will to be enabled and disabled together
1113  * regardless of the request from the VF. This means that the underlying
1114  * hardware only supports VLAN filtering for all VLAN the specified ethertypes
1115  * or none of them.
1116  *
1117  * virtchnl_vlan_caps.filtering.filtering_support.outer =
1118  *			VIRTCHNL_VLAN_TOGGLE |
1119  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1120  *			VIRTHCNL_VLAN_ETHERTYPE_88A8 |
1121  *			VIRTCHNL_VLAN_ETHERTYPE_9100 |
1122  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
1123  *
1124  * In order to enable outer VLAN filtering for 0x88a8 and 0x8100 VLANs (0x9100
1125  * VLANs aren't supported by the VF driver), the VF would populate the
1126  * virtchnl_vlan_setting structure in the following manner and send the
1127  * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2. The same message format would be used
1128  * to disable outer VLAN filtering for 0x88a8 and 0x8100 VLANs, but the
1129  * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 opcode is used.
1130  *
1131  * virtchnl_vlan_setting.outer_ethertype_setting =
1132  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
1133  *			VIRTCHNL_VLAN_ETHERTYPE_88A8;
1134  *
1135  */
1136 struct virtchnl_vlan_setting {
1137 	u32 outer_ethertype_setting;
1138 	u32 inner_ethertype_setting;
1139 	u16 vport_id;
1140 	u8 pad[6];
1141 };
1142 
1143 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_setting);
1144 
1145 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
1146  * VF sends VSI id and flags.
1147  * PF returns status code in retval.
1148  * Note: we assume that broadcast accept mode is always enabled.
1149  */
1150 struct virtchnl_promisc_info {
1151 	u16 vsi_id;
1152 	u16 flags;
1153 };
1154 
1155 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
1156 
1157 #define FLAG_VF_UNICAST_PROMISC	0x00000001
1158 #define FLAG_VF_MULTICAST_PROMISC	0x00000002
1159 
1160 /* VIRTCHNL_OP_GET_STATS
1161  * VF sends this message to request stats for the selected VSI. VF uses
1162  * the virtchnl_queue_select struct to specify the VSI. The queue_id
1163  * field is ignored by the PF.
1164  *
1165  * PF replies with struct virtchnl_eth_stats in an external buffer.
1166  */
1167 
1168 struct virtchnl_eth_stats {
1169 	u64 rx_bytes;			/* received bytes */
1170 	u64 rx_unicast;			/* received unicast pkts */
1171 	u64 rx_multicast;		/* received multicast pkts */
1172 	u64 rx_broadcast;		/* received broadcast pkts */
1173 	u64 rx_discards;
1174 	u64 rx_unknown_protocol;
1175 	u64 tx_bytes;			/* transmitted bytes */
1176 	u64 tx_unicast;			/* transmitted unicast pkts */
1177 	u64 tx_multicast;		/* transmitted multicast pkts */
1178 	u64 tx_broadcast;		/* transmitted broadcast pkts */
1179 	u64 tx_discards;
1180 	u64 tx_errors;
1181 };
1182 
1183 /* VIRTCHNL_OP_CONFIG_RSS_KEY
1184  * VIRTCHNL_OP_CONFIG_RSS_LUT
1185  * VF sends these messages to configure RSS. Only supported if both PF
1186  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
1187  * configuration negotiation. If this is the case, then the RSS fields in
1188  * the VF resource struct are valid.
1189  * Both the key and LUT are initialized to 0 by the PF, meaning that
1190  * RSS is effectively disabled until set up by the VF.
1191  */
1192 struct virtchnl_rss_key {
1193 	u16 vsi_id;
1194 	u16 key_len;
1195 	u8 key[1];         /* RSS hash key, packed bytes */
1196 };
1197 
1198 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
1199 
1200 struct virtchnl_rss_lut {
1201 	u16 vsi_id;
1202 	u16 lut_entries;
1203 	u8 lut[1];        /* RSS lookup table */
1204 };
1205 
1206 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
1207 
1208 /* enum virthcnl_hash_filter
1209  *
1210  * Bits defining the hash filters in the hena field of the virtchnl_rss_hena
1211  * structure. Each bit indicates a specific hash filter for RSS.
1212  *
1213  * Note that not all bits are supported on all hardware. The VF should use
1214  * VIRTCHNL_OP_GET_RSS_HENA_CAPS to determine which bits the PF is capable of
1215  * before using VIRTCHNL_OP_SET_RSS_HENA to enable specific filters.
1216  */
1217 enum virtchnl_hash_filter {
1218 	/* Bits 0 through 28 are reserved for future use */
1219 	/* Bit 29, 30, and 32 are not supported on XL710 a X710 */
1220 	VIRTCHNL_HASH_FILTER_UNICAST_IPV4_UDP		= 29,
1221 	VIRTCHNL_HASH_FILTER_MULTICAST_IPV4_UDP		= 30,
1222 	VIRTCHNL_HASH_FILTER_IPV4_UDP			= 31,
1223 	VIRTCHNL_HASH_FILTER_IPV4_TCP_SYN_NO_ACK	= 32,
1224 	VIRTCHNL_HASH_FILTER_IPV4_TCP			= 33,
1225 	VIRTCHNL_HASH_FILTER_IPV4_SCTP			= 34,
1226 	VIRTCHNL_HASH_FILTER_IPV4_OTHER			= 35,
1227 	VIRTCHNL_HASH_FILTER_FRAG_IPV4			= 36,
1228 	/* Bits 37 and 38 are reserved for future use */
1229 	/* Bit 39, 40, and 42 are not supported on XL710 a X710 */
1230 	VIRTCHNL_HASH_FILTER_UNICAST_IPV6_UDP		= 39,
1231 	VIRTCHNL_HASH_FILTER_MULTICAST_IPV6_UDP		= 40,
1232 	VIRTCHNL_HASH_FILTER_IPV6_UDP			= 41,
1233 	VIRTCHNL_HASH_FILTER_IPV6_TCP_SYN_NO_ACK	= 42,
1234 	VIRTCHNL_HASH_FILTER_IPV6_TCP			= 43,
1235 	VIRTCHNL_HASH_FILTER_IPV6_SCTP			= 44,
1236 	VIRTCHNL_HASH_FILTER_IPV6_OTHER			= 45,
1237 	VIRTCHNL_HASH_FILTER_FRAG_IPV6			= 46,
1238 	/* Bit 37 is reserved for future use */
1239 	VIRTCHNL_HASH_FILTER_FCOE_OX			= 48,
1240 	VIRTCHNL_HASH_FILTER_FCOE_RX			= 49,
1241 	VIRTCHNL_HASH_FILTER_FCOE_OTHER			= 50,
1242 	/* Bits 51 through 62 are reserved for future use */
1243 	VIRTCHNL_HASH_FILTER_L2_PAYLOAD			= 63,
1244 };
1245 
1246 #define VIRTCHNL_HASH_FILTER_INVALID	(0)
1247 
1248 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
1249  * VIRTCHNL_OP_SET_RSS_HENA
1250  * VF sends these messages to get and set the hash filter enable bits for RSS.
1251  * By default, the PF sets these to all possible traffic types that the
1252  * hardware supports. The VF can query this value if it wants to change the
1253  * traffic types that are hashed by the hardware.
1254  */
1255 struct virtchnl_rss_hena {
1256 	/* see enum virtchnl_hash_filter */
1257 	u64 hena;
1258 };
1259 
1260 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
1261 
1262 /* Type of RSS algorithm */
1263 enum virtchnl_rss_algorithm {
1264 	VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC	= 0,
1265 	VIRTCHNL_RSS_ALG_R_ASYMMETRIC		= 1,
1266 	VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC	= 2,
1267 	VIRTCHNL_RSS_ALG_XOR_SYMMETRIC		= 3,
1268 };
1269 
1270 /* This is used by PF driver to enforce how many channels can be supported.
1271  * When ADQ_V2 capability is negotiated, it will allow 16 channels otherwise
1272  * PF driver will allow only max 4 channels
1273  */
1274 #define VIRTCHNL_MAX_ADQ_CHANNELS 4
1275 #define VIRTCHNL_MAX_ADQ_V2_CHANNELS 16
1276 
1277 /* VIRTCHNL_OP_ENABLE_CHANNELS
1278  * VIRTCHNL_OP_DISABLE_CHANNELS
1279  * VF sends these messages to enable or disable channels based on
1280  * the user specified queue count and queue offset for each traffic class.
1281  * This struct encompasses all the information that the PF needs from
1282  * VF to create a channel.
1283  */
1284 struct virtchnl_channel_info {
1285 	u16 count; /* number of queues in a channel */
1286 	u16 offset; /* queues in a channel start from 'offset' */
1287 	u32 pad;
1288 	u64 max_tx_rate;
1289 };
1290 
1291 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
1292 
1293 struct virtchnl_tc_info {
1294 	u32	num_tc;
1295 	u32	pad;
1296 	struct	virtchnl_channel_info list[1];
1297 };
1298 
1299 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
1300 
1301 /* VIRTCHNL_ADD_CLOUD_FILTER
1302  * VIRTCHNL_DEL_CLOUD_FILTER
1303  * VF sends these messages to add or delete a cloud filter based on the
1304  * user specified match and action filters. These structures encompass
1305  * all the information that the PF needs from the VF to add/delete a
1306  * cloud filter.
1307  */
1308 
1309 struct virtchnl_l4_spec {
1310 	u8	src_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
1311 	u8	dst_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
1312 	/* vlan_prio is part of this 16 bit field even from OS perspective
1313 	 * vlan_id:12 is actual vlan_id, then vlanid:bit14..12 is vlan_prio
1314 	 * in future, when decided to offload vlan_prio, pass that information
1315 	 * as part of the "vlan_id" field, Bit14..12
1316 	 */
1317 	__be16	vlan_id;
1318 	__be16	pad; /* reserved for future use */
1319 	__be32	src_ip[4];
1320 	__be32	dst_ip[4];
1321 	__be16	src_port;
1322 	__be16	dst_port;
1323 };
1324 
1325 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
1326 
1327 union virtchnl_flow_spec {
1328 	struct	virtchnl_l4_spec tcp_spec;
1329 	u8	buffer[128]; /* reserved for future use */
1330 };
1331 
1332 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
1333 
1334 enum virtchnl_action {
1335 	/* action types */
1336 	VIRTCHNL_ACTION_DROP = 0,
1337 	VIRTCHNL_ACTION_TC_REDIRECT,
1338 	VIRTCHNL_ACTION_PASSTHRU,
1339 	VIRTCHNL_ACTION_QUEUE,
1340 	VIRTCHNL_ACTION_Q_REGION,
1341 	VIRTCHNL_ACTION_MARK,
1342 	VIRTCHNL_ACTION_COUNT,
1343 };
1344 
1345 enum virtchnl_flow_type {
1346 	/* flow types */
1347 	VIRTCHNL_TCP_V4_FLOW = 0,
1348 	VIRTCHNL_TCP_V6_FLOW,
1349 	VIRTCHNL_UDP_V4_FLOW,
1350 	VIRTCHNL_UDP_V6_FLOW,
1351 };
1352 
1353 struct virtchnl_filter {
1354 	union	virtchnl_flow_spec data;
1355 	union	virtchnl_flow_spec mask;
1356 
1357 	/* see enum virtchnl_flow_type */
1358 	s32 	flow_type;
1359 
1360 	/* see enum virtchnl_action */
1361 	s32	action;
1362 	u32	action_meta;
1363 	u8	field_flags;
1364 };
1365 
1366 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
1367 
1368 struct virtchnl_shaper_bw {
1369 	/* Unit is Kbps */
1370 	u32 committed;
1371 	u32 peak;
1372 };
1373 
1374 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_shaper_bw);
1375 
1376 /* VIRTCHNL_OP_EVENT
1377  * PF sends this message to inform the VF driver of events that may affect it.
1378  * No direct response is expected from the VF, though it may generate other
1379  * messages in response to this one.
1380  */
1381 enum virtchnl_event_codes {
1382 	VIRTCHNL_EVENT_UNKNOWN = 0,
1383 	VIRTCHNL_EVENT_LINK_CHANGE,
1384 	VIRTCHNL_EVENT_RESET_IMPENDING,
1385 	VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
1386 };
1387 
1388 #define PF_EVENT_SEVERITY_INFO		0
1389 #define PF_EVENT_SEVERITY_ATTENTION	1
1390 #define PF_EVENT_SEVERITY_ACTION_REQUIRED	2
1391 #define PF_EVENT_SEVERITY_CERTAIN_DOOM	255
1392 
1393 struct virtchnl_pf_event {
1394 	/* see enum virtchnl_event_codes */
1395 	s32 event;
1396 	union {
1397 		/* If the PF driver does not support the new speed reporting
1398 		 * capabilities then use link_event else use link_event_adv to
1399 		 * get the speed and link information. The ability to understand
1400 		 * new speeds is indicated by setting the capability flag
1401 		 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
1402 		 * in virtchnl_vf_resource struct and can be used to determine
1403 		 * which link event struct to use below.
1404 		 */
1405 		struct {
1406 			enum virtchnl_link_speed link_speed;
1407 			bool link_status;
1408 			u8 pad[3];
1409 		} link_event;
1410 		struct {
1411 			/* link_speed provided in Mbps */
1412 			u32 link_speed;
1413 			u8 link_status;
1414 			u8 pad[3];
1415 		} link_event_adv;
1416 	} event_data;
1417 
1418 	s32 severity;
1419 };
1420 
1421 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
1422 
1423 /* VF reset states - these are written into the RSTAT register:
1424  * VFGEN_RSTAT on the VF
1425  * When the PF initiates a reset, it writes 0
1426  * When the reset is complete, it writes 1
1427  * When the PF detects that the VF has recovered, it writes 2
1428  * VF checks this register periodically to determine if a reset has occurred,
1429  * then polls it to know when the reset is complete.
1430  * If either the PF or VF reads the register while the hardware
1431  * is in a reset state, it will return DEADBEEF, which, when masked
1432  * will result in 3.
1433  */
1434 enum virtchnl_vfr_states {
1435 	VIRTCHNL_VFR_INPROGRESS = 0,
1436 	VIRTCHNL_VFR_COMPLETED,
1437 	VIRTCHNL_VFR_VFACTIVE,
1438 };
1439 
1440 #define VIRTCHNL_MAX_NUM_PROTO_HDRS	32
1441 #define VIRTCHNL_MAX_SIZE_RAW_PACKET	1024
1442 #define PROTO_HDR_SHIFT			5
1443 #define PROTO_HDR_FIELD_START(proto_hdr_type) \
1444 					(proto_hdr_type << PROTO_HDR_SHIFT)
1445 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1)
1446 
1447 /* VF use these macros to configure each protocol header.
1448  * Specify which protocol headers and protocol header fields base on
1449  * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field.
1450  * @param hdr: a struct of virtchnl_proto_hdr
1451  * @param hdr_type: ETH/IPV4/TCP, etc
1452  * @param field: SRC/DST/TEID/SPI, etc
1453  */
1454 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field) \
1455 	((hdr)->field_selector |= BIT((field) & PROTO_HDR_FIELD_MASK))
1456 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field) \
1457 	((hdr)->field_selector &= ~BIT((field) & PROTO_HDR_FIELD_MASK))
1458 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val) \
1459 	((hdr)->field_selector & BIT((val) & PROTO_HDR_FIELD_MASK))
1460 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr)	((hdr)->field_selector)
1461 
1462 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
1463 	(VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, \
1464 		VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
1465 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
1466 	(VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, \
1467 		VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
1468 
1469 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type) \
1470 	((hdr)->type = VIRTCHNL_PROTO_HDR_ ## hdr_type)
1471 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \
1472 	(((hdr)->type) >> PROTO_HDR_SHIFT)
1473 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \
1474 	((hdr)->type == ((s32)((val) >> PROTO_HDR_SHIFT)))
1475 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \
1476 	(VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) && \
1477 	 VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val))
1478 
1479 /* Protocol header type within a packet segment. A segment consists of one or
1480  * more protocol headers that make up a logical group of protocol headers. Each
1481  * logical group of protocol headers encapsulates or is encapsulated using/by
1482  * tunneling or encapsulation protocols for network virtualization.
1483  */
1484 enum virtchnl_proto_hdr_type {
1485 	VIRTCHNL_PROTO_HDR_NONE,
1486 	VIRTCHNL_PROTO_HDR_ETH,
1487 	VIRTCHNL_PROTO_HDR_S_VLAN,
1488 	VIRTCHNL_PROTO_HDR_C_VLAN,
1489 	VIRTCHNL_PROTO_HDR_IPV4,
1490 	VIRTCHNL_PROTO_HDR_IPV6,
1491 	VIRTCHNL_PROTO_HDR_TCP,
1492 	VIRTCHNL_PROTO_HDR_UDP,
1493 	VIRTCHNL_PROTO_HDR_SCTP,
1494 	VIRTCHNL_PROTO_HDR_GTPU_IP,
1495 	VIRTCHNL_PROTO_HDR_GTPU_EH,
1496 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
1497 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
1498 	VIRTCHNL_PROTO_HDR_PPPOE,
1499 	VIRTCHNL_PROTO_HDR_L2TPV3,
1500 	VIRTCHNL_PROTO_HDR_ESP,
1501 	VIRTCHNL_PROTO_HDR_AH,
1502 	VIRTCHNL_PROTO_HDR_PFCP,
1503 	VIRTCHNL_PROTO_HDR_GTPC,
1504 	VIRTCHNL_PROTO_HDR_ECPRI,
1505 	VIRTCHNL_PROTO_HDR_L2TPV2,
1506 	VIRTCHNL_PROTO_HDR_PPP,
1507 	/* IPv4 and IPv6 Fragment header types are only associated to
1508 	 * VIRTCHNL_PROTO_HDR_IPV4 and VIRTCHNL_PROTO_HDR_IPV6 respectively,
1509 	 * cannot be used independently.
1510 	 */
1511 	VIRTCHNL_PROTO_HDR_IPV4_FRAG,
1512 	VIRTCHNL_PROTO_HDR_IPV6_EH_FRAG,
1513 	VIRTCHNL_PROTO_HDR_GRE,
1514 };
1515 
1516 /* Protocol header field within a protocol header. */
1517 enum virtchnl_proto_hdr_field {
1518 	/* ETHER */
1519 	VIRTCHNL_PROTO_HDR_ETH_SRC =
1520 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ETH),
1521 	VIRTCHNL_PROTO_HDR_ETH_DST,
1522 	VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
1523 	/* S-VLAN */
1524 	VIRTCHNL_PROTO_HDR_S_VLAN_ID =
1525 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_S_VLAN),
1526 	/* C-VLAN */
1527 	VIRTCHNL_PROTO_HDR_C_VLAN_ID =
1528 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_C_VLAN),
1529 	/* IPV4 */
1530 	VIRTCHNL_PROTO_HDR_IPV4_SRC =
1531 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4),
1532 	VIRTCHNL_PROTO_HDR_IPV4_DST,
1533 	VIRTCHNL_PROTO_HDR_IPV4_DSCP,
1534 	VIRTCHNL_PROTO_HDR_IPV4_TTL,
1535 	VIRTCHNL_PROTO_HDR_IPV4_PROT,
1536 	VIRTCHNL_PROTO_HDR_IPV4_CHKSUM,
1537 	/* IPV6 */
1538 	VIRTCHNL_PROTO_HDR_IPV6_SRC =
1539 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6),
1540 	VIRTCHNL_PROTO_HDR_IPV6_DST,
1541 	VIRTCHNL_PROTO_HDR_IPV6_TC,
1542 	VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
1543 	VIRTCHNL_PROTO_HDR_IPV6_PROT,
1544 	/* IPV6 Prefix */
1545 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX32_SRC,
1546 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX32_DST,
1547 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX40_SRC,
1548 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX40_DST,
1549 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX48_SRC,
1550 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX48_DST,
1551 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX56_SRC,
1552 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX56_DST,
1553 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX64_SRC,
1554 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX64_DST,
1555 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX96_SRC,
1556 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX96_DST,
1557 	/* TCP */
1558 	VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
1559 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_TCP),
1560 	VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
1561 	VIRTCHNL_PROTO_HDR_TCP_CHKSUM,
1562 	/* UDP */
1563 	VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
1564 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_UDP),
1565 	VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
1566 	VIRTCHNL_PROTO_HDR_UDP_CHKSUM,
1567 	/* SCTP */
1568 	VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
1569 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_SCTP),
1570 	VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
1571 	VIRTCHNL_PROTO_HDR_SCTP_CHKSUM,
1572 	/* GTPU_IP */
1573 	VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
1574 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_IP),
1575 	/* GTPU_EH */
1576 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
1577 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH),
1578 	VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
1579 	/* PPPOE */
1580 	VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
1581 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PPPOE),
1582 	/* L2TPV3 */
1583 	VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
1584 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV3),
1585 	/* ESP */
1586 	VIRTCHNL_PROTO_HDR_ESP_SPI =
1587 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ESP),
1588 	/* AH */
1589 	VIRTCHNL_PROTO_HDR_AH_SPI =
1590 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_AH),
1591 	/* PFCP */
1592 	VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
1593 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PFCP),
1594 	VIRTCHNL_PROTO_HDR_PFCP_SEID,
1595 	/* GTPC */
1596 	VIRTCHNL_PROTO_HDR_GTPC_TEID =
1597 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPC),
1598 	/* ECPRI */
1599 	VIRTCHNL_PROTO_HDR_ECPRI_MSG_TYPE =
1600 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ECPRI),
1601 	VIRTCHNL_PROTO_HDR_ECPRI_PC_RTC_ID,
1602 	/* IPv4 Dummy Fragment */
1603 	VIRTCHNL_PROTO_HDR_IPV4_FRAG_PKID =
1604 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4_FRAG),
1605 	/* IPv6 Extension Fragment */
1606 	VIRTCHNL_PROTO_HDR_IPV6_EH_FRAG_PKID =
1607 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6_EH_FRAG),
1608 	/* GTPU_DWN/UP */
1609 	VIRTCHNL_PROTO_HDR_GTPU_DWN_QFI =
1610 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN),
1611 	VIRTCHNL_PROTO_HDR_GTPU_UP_QFI =
1612 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP),
1613 	/* L2TPv2 */
1614 	VIRTCHNL_PROTO_HDR_L2TPV2_SESS_ID =
1615 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV2),
1616 	VIRTCHNL_PROTO_HDR_L2TPV2_LEN_SESS_ID,
1617 };
1618 
1619 struct virtchnl_proto_hdr {
1620 	/* see enum virtchnl_proto_hdr_type */
1621 	s32 type;
1622 	u32 field_selector; /* a bit mask to select field for header type */
1623 	u8 buffer[64];
1624 	/**
1625 	 * binary buffer in network order for specific header type.
1626 	 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
1627 	 * header is expected to be copied into the buffer.
1628 	 */
1629 };
1630 
1631 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr);
1632 
1633 struct virtchnl_proto_hdrs {
1634 	u8 tunnel_level;
1635 	/**
1636 	 * specify where protocol header start from.
1637 	 * must be 0 when sending a raw packet request.
1638 	 * 0 - from the outer layer
1639 	 * 1 - from the first inner layer
1640 	 * 2 - from the second inner layer
1641 	 * ....
1642 	 */
1643 	int count;
1644 	/**
1645 	 * number of proto layers, must < VIRTCHNL_MAX_NUM_PROTO_HDRS
1646 	 * must be 0 for a raw packet request.
1647 	 */
1648 	union {
1649 		struct virtchnl_proto_hdr
1650 			proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
1651 		struct {
1652 			u16 pkt_len;
1653 			u8 spec[VIRTCHNL_MAX_SIZE_RAW_PACKET];
1654 			u8 mask[VIRTCHNL_MAX_SIZE_RAW_PACKET];
1655 		} raw;
1656 	};
1657 };
1658 
1659 VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs);
1660 
1661 struct virtchnl_rss_cfg {
1662 	struct virtchnl_proto_hdrs proto_hdrs;	   /* protocol headers */
1663 
1664 	/* see enum virtchnl_rss_algorithm; rss algorithm type */
1665 	s32 rss_algorithm;
1666 	u8 reserved[128];                          /* reserve for future */
1667 };
1668 
1669 VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg);
1670 
1671 /* action configuration for FDIR */
1672 struct virtchnl_filter_action {
1673 	/* see enum virtchnl_action type */
1674 	s32 type;
1675 	union {
1676 		/* used for queue and qgroup action */
1677 		struct {
1678 			u16 index;
1679 			u8 region;
1680 		} queue;
1681 		/* used for count action */
1682 		struct {
1683 			/* share counter ID with other flow rules */
1684 			u8 shared;
1685 			u32 id; /* counter ID */
1686 		} count;
1687 		/* used for mark action */
1688 		u32 mark_id;
1689 		u8 reserve[32];
1690 	} act_conf;
1691 };
1692 
1693 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action);
1694 
1695 #define VIRTCHNL_MAX_NUM_ACTIONS  8
1696 
1697 struct virtchnl_filter_action_set {
1698 	/* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
1699 	int count;
1700 	struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
1701 };
1702 
1703 VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set);
1704 
1705 /* pattern and action for FDIR rule */
1706 struct virtchnl_fdir_rule {
1707 	struct virtchnl_proto_hdrs proto_hdrs;
1708 	struct virtchnl_filter_action_set action_set;
1709 };
1710 
1711 VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule);
1712 
1713 /* Status returned to VF after VF requests FDIR commands
1714  * VIRTCHNL_FDIR_SUCCESS
1715  * VF FDIR related request is successfully done by PF
1716  * The request can be OP_ADD/DEL/QUERY_FDIR_FILTER.
1717  *
1718  * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
1719  * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
1720  *
1721  * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
1722  * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
1723  *
1724  * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
1725  * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
1726  *
1727  * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
1728  * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
1729  *
1730  * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
1731  * OP_ADD_FDIR_FILTER request is failed due to parameters validation
1732  * or HW doesn't support.
1733  *
1734  * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
1735  * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
1736  * for programming.
1737  *
1738  * VIRTCHNL_FDIR_FAILURE_QUERY_INVALID
1739  * OP_QUERY_FDIR_FILTER request is failed due to parameters validation,
1740  * for example, VF query counter of a rule who has no counter action.
1741  */
1742 enum virtchnl_fdir_prgm_status {
1743 	VIRTCHNL_FDIR_SUCCESS = 0,
1744 	VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
1745 	VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
1746 	VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
1747 	VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
1748 	VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
1749 	VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
1750 	VIRTCHNL_FDIR_FAILURE_QUERY_INVALID,
1751 };
1752 
1753 /* VIRTCHNL_OP_ADD_FDIR_FILTER
1754  * VF sends this request to PF by filling out vsi_id,
1755  * validate_only and rule_cfg. PF will return flow_id
1756  * if the request is successfully done and return add_status to VF.
1757  */
1758 struct virtchnl_fdir_add {
1759 	u16 vsi_id;  /* INPUT */
1760 	/*
1761 	 * 1 for validating a fdir rule, 0 for creating a fdir rule.
1762 	 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
1763 	 */
1764 	u16 validate_only; /* INPUT */
1765 	u32 flow_id;       /* OUTPUT */
1766 	struct virtchnl_fdir_rule rule_cfg; /* INPUT */
1767 
1768 	/* see enum virtchnl_fdir_prgm_status; OUTPUT */
1769 	s32 status;
1770 };
1771 
1772 VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add);
1773 
1774 /* VIRTCHNL_OP_DEL_FDIR_FILTER
1775  * VF sends this request to PF by filling out vsi_id
1776  * and flow_id. PF will return del_status to VF.
1777  */
1778 struct virtchnl_fdir_del {
1779 	u16 vsi_id;  /* INPUT */
1780 	u16 pad;
1781 	u32 flow_id; /* INPUT */
1782 
1783 	/* see enum virtchnl_fdir_prgm_status; OUTPUT */
1784 	s32 status;
1785 };
1786 
1787 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del);
1788 
1789 /* VIRTCHNL_OP_GET_QOS_CAPS
1790  * VF sends this message to get its QoS Caps, such as
1791  * TC number, Arbiter and Bandwidth.
1792  */
1793 struct virtchnl_qos_cap_elem {
1794 	u8 tc_num;
1795 	u8 tc_prio;
1796 #define VIRTCHNL_ABITER_STRICT      0
1797 #define VIRTCHNL_ABITER_ETS         2
1798 	u8 arbiter;
1799 #define VIRTCHNL_STRICT_WEIGHT      1
1800 	u8 weight;
1801 	enum virtchnl_bw_limit_type type;
1802 	union {
1803 		struct virtchnl_shaper_bw shaper;
1804 		u8 pad2[32];
1805 	};
1806 };
1807 
1808 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_qos_cap_elem);
1809 
1810 struct virtchnl_qos_cap_list {
1811 	u16 vsi_id;
1812 	u16 num_elem;
1813 	struct virtchnl_qos_cap_elem cap[1];
1814 };
1815 
1816 VIRTCHNL_CHECK_STRUCT_LEN(44, virtchnl_qos_cap_list);
1817 
1818 /* VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP
1819  * VF sends message virtchnl_queue_tc_mapping to set queue to tc
1820  * mapping for all the Tx and Rx queues with a specified VSI, and
1821  * would get response about bitmap of valid user priorities
1822  * associated with queues.
1823  */
1824 struct virtchnl_queue_tc_mapping {
1825 	u16 vsi_id;
1826 	u16 num_tc;
1827 	u16 num_queue_pairs;
1828 	u8 pad[2];
1829 	union {
1830 		struct {
1831 			u16 start_queue_id;
1832 			u16 queue_count;
1833 		} req;
1834 		struct {
1835 #define VIRTCHNL_USER_PRIO_TYPE_UP	0
1836 #define VIRTCHNL_USER_PRIO_TYPE_DSCP	1
1837 			u16 prio_type;
1838 			u16 valid_prio_bitmap;
1839 		} resp;
1840 	} tc[1];
1841 };
1842 
1843 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_tc_mapping);
1844 
1845 /* VIRTCHNL_OP_CONFIG_QUEUE_BW */
1846 struct virtchnl_queue_bw {
1847 	u16 queue_id;
1848 	u8 tc;
1849 	u8 pad;
1850 	struct virtchnl_shaper_bw shaper;
1851 };
1852 
1853 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_bw);
1854 
1855 struct virtchnl_queues_bw_cfg {
1856 	u16 vsi_id;
1857 	u16 num_queues;
1858 	struct virtchnl_queue_bw cfg[1];
1859 };
1860 
1861 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_queues_bw_cfg);
1862 
1863 /* queue types */
1864 enum virtchnl_queue_type {
1865 	VIRTCHNL_QUEUE_TYPE_TX			= 0,
1866 	VIRTCHNL_QUEUE_TYPE_RX			= 1,
1867 };
1868 
1869 /* structure to specify a chunk of contiguous queues */
1870 struct virtchnl_queue_chunk {
1871 	/* see enum virtchnl_queue_type */
1872 	s32 type;
1873 	u16 start_queue_id;
1874 	u16 num_queues;
1875 };
1876 
1877 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_queue_chunk);
1878 
1879 /* structure to specify several chunks of contiguous queues */
1880 struct virtchnl_queue_chunks {
1881 	u16 num_chunks;
1882 	u16 rsvd;
1883 	struct virtchnl_queue_chunk chunks[1];
1884 };
1885 
1886 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_chunks);
1887 
1888 /* VIRTCHNL_OP_ENABLE_QUEUES_V2
1889  * VIRTCHNL_OP_DISABLE_QUEUES_V2
1890  *
1891  * These opcodes can be used if VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in
1892  * VIRTCHNL_OP_GET_VF_RESOURCES
1893  *
1894  * VF sends virtchnl_ena_dis_queues struct to specify the queues to be
1895  * enabled/disabled in chunks. Also applicable to single queue RX or
1896  * TX. PF performs requested action and returns status.
1897  */
1898 struct virtchnl_del_ena_dis_queues {
1899 	u16 vport_id;
1900 	u16 pad;
1901 	struct virtchnl_queue_chunks chunks;
1902 };
1903 
1904 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_del_ena_dis_queues);
1905 
1906 /* Virtchannel interrupt throttling rate index */
1907 enum virtchnl_itr_idx {
1908 	VIRTCHNL_ITR_IDX_0	= 0,
1909 	VIRTCHNL_ITR_IDX_1	= 1,
1910 	VIRTCHNL_ITR_IDX_NO_ITR	= 3,
1911 };
1912 
1913 /* Queue to vector mapping */
1914 struct virtchnl_queue_vector {
1915 	u16 queue_id;
1916 	u16 vector_id;
1917 	u8 pad[4];
1918 
1919 	/* see enum virtchnl_itr_idx */
1920 	s32 itr_idx;
1921 
1922 	/* see enum virtchnl_queue_type */
1923 	s32 queue_type;
1924 };
1925 
1926 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_queue_vector);
1927 
1928 /* VIRTCHNL_OP_MAP_QUEUE_VECTOR
1929  *
1930  * This opcode can be used only if VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated
1931  * in VIRTCHNL_OP_GET_VF_RESOURCES
1932  *
1933  * VF sends this message to map queues to vectors and ITR index registers.
1934  * External data buffer contains virtchnl_queue_vector_maps structure
1935  * that contains num_qv_maps of virtchnl_queue_vector structures.
1936  * PF maps the requested queue vector maps after validating the queue and vector
1937  * ids and returns a status code.
1938  */
1939 struct virtchnl_queue_vector_maps {
1940 	u16 vport_id;
1941 	u16 num_qv_maps;
1942 	u8 pad[4];
1943 	struct virtchnl_queue_vector qv_maps[1];
1944 };
1945 
1946 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_queue_vector_maps);
1947 
1948 struct virtchnl_quanta_cfg {
1949 	u16 quanta_size;
1950 	struct virtchnl_queue_chunk queue_select;
1951 };
1952 
1953 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_quanta_cfg);
1954 
1955 /* Since VF messages are limited by u16 size, precalculate the maximum possible
1956  * values of nested elements in virtchnl structures that virtual channel can
1957  * possibly handle in a single message.
1958  */
1959 enum virtchnl_vector_limits {
1960 	VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX	=
1961 		((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) /
1962 		sizeof(struct virtchnl_queue_pair_info),
1963 
1964 	VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX		=
1965 		((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) /
1966 		sizeof(struct virtchnl_vector_map),
1967 
1968 	VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX	=
1969 		((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) /
1970 		sizeof(struct virtchnl_ether_addr),
1971 
1972 	VIRTCHNL_OP_ADD_DEL_VLAN_MAX		=
1973 		((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) /
1974 		sizeof(u16),
1975 
1976 	VIRTCHNL_OP_ENABLE_CHANNELS_MAX		=
1977 		((u16)(~0) - sizeof(struct virtchnl_tc_info)) /
1978 		sizeof(struct virtchnl_channel_info),
1979 
1980 	VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX	=
1981 		((u16)(~0) - sizeof(struct virtchnl_del_ena_dis_queues)) /
1982 		sizeof(struct virtchnl_queue_chunk),
1983 
1984 	VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX	=
1985 		((u16)(~0) - sizeof(struct virtchnl_queue_vector_maps)) /
1986 		sizeof(struct virtchnl_queue_vector),
1987 
1988 	VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX		=
1989 		((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list_v2)) /
1990 		sizeof(struct virtchnl_vlan_filter),
1991 };
1992 
1993 /**
1994  * virtchnl_vc_validate_vf_msg
1995  * @ver: Virtchnl version info
1996  * @v_opcode: Opcode for the message
1997  * @msg: pointer to the msg buffer
1998  * @msglen: msg length
1999  *
2000  * validate msg format against struct for each opcode
2001  */
2002 static inline int
2003 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
2004 			    u8 *msg, u16 msglen)
2005 {
2006 	bool err_msg_format = false;
2007 	u32 valid_len = 0;
2008 
2009 	/* Validate message length. */
2010 	switch (v_opcode) {
2011 	case VIRTCHNL_OP_VERSION:
2012 		valid_len = sizeof(struct virtchnl_version_info);
2013 		break;
2014 	case VIRTCHNL_OP_RESET_VF:
2015 		break;
2016 	case VIRTCHNL_OP_GET_VF_RESOURCES:
2017 		if (VF_IS_V11(ver))
2018 			valid_len = sizeof(u32);
2019 		break;
2020 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
2021 		valid_len = sizeof(struct virtchnl_txq_info);
2022 		break;
2023 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
2024 		valid_len = sizeof(struct virtchnl_rxq_info);
2025 		break;
2026 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
2027 		valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
2028 		if (msglen >= valid_len) {
2029 			struct virtchnl_vsi_queue_config_info *vqc =
2030 			    (struct virtchnl_vsi_queue_config_info *)msg;
2031 
2032 			if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs >
2033 			    VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) {
2034 				err_msg_format = true;
2035 				break;
2036 			}
2037 
2038 			valid_len += (vqc->num_queue_pairs *
2039 				      sizeof(struct
2040 					     virtchnl_queue_pair_info));
2041 		}
2042 		break;
2043 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2044 		valid_len = sizeof(struct virtchnl_irq_map_info);
2045 		if (msglen >= valid_len) {
2046 			struct virtchnl_irq_map_info *vimi =
2047 			    (struct virtchnl_irq_map_info *)msg;
2048 
2049 			if (vimi->num_vectors == 0 || vimi->num_vectors >
2050 			    VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) {
2051 				err_msg_format = true;
2052 				break;
2053 			}
2054 
2055 			valid_len += (vimi->num_vectors *
2056 				      sizeof(struct virtchnl_vector_map));
2057 		}
2058 		break;
2059 	case VIRTCHNL_OP_ENABLE_QUEUES:
2060 	case VIRTCHNL_OP_DISABLE_QUEUES:
2061 		valid_len = sizeof(struct virtchnl_queue_select);
2062 		break;
2063 	case VIRTCHNL_OP_GET_MAX_RSS_QREGION:
2064 		break;
2065 	case VIRTCHNL_OP_ADD_ETH_ADDR:
2066 	case VIRTCHNL_OP_DEL_ETH_ADDR:
2067 		valid_len = sizeof(struct virtchnl_ether_addr_list);
2068 		if (msglen >= valid_len) {
2069 			struct virtchnl_ether_addr_list *veal =
2070 			    (struct virtchnl_ether_addr_list *)msg;
2071 
2072 			if (veal->num_elements == 0 || veal->num_elements >
2073 			    VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) {
2074 				err_msg_format = true;
2075 				break;
2076 			}
2077 
2078 			valid_len += veal->num_elements *
2079 			    sizeof(struct virtchnl_ether_addr);
2080 		}
2081 		break;
2082 	case VIRTCHNL_OP_ADD_VLAN:
2083 	case VIRTCHNL_OP_DEL_VLAN:
2084 		valid_len = sizeof(struct virtchnl_vlan_filter_list);
2085 		if (msglen >= valid_len) {
2086 			struct virtchnl_vlan_filter_list *vfl =
2087 			    (struct virtchnl_vlan_filter_list *)msg;
2088 
2089 			if (vfl->num_elements == 0 || vfl->num_elements >
2090 			    VIRTCHNL_OP_ADD_DEL_VLAN_MAX) {
2091 				err_msg_format = true;
2092 				break;
2093 			}
2094 
2095 			valid_len += vfl->num_elements * sizeof(u16);
2096 		}
2097 		break;
2098 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
2099 		valid_len = sizeof(struct virtchnl_promisc_info);
2100 		break;
2101 	case VIRTCHNL_OP_GET_STATS:
2102 		valid_len = sizeof(struct virtchnl_queue_select);
2103 		break;
2104 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
2105 		valid_len = sizeof(struct virtchnl_rss_key);
2106 		if (msglen >= valid_len) {
2107 			struct virtchnl_rss_key *vrk =
2108 				(struct virtchnl_rss_key *)msg;
2109 
2110 			if (vrk->key_len == 0) {
2111 				/* zero length is allowed as input */
2112 				break;
2113 			}
2114 
2115 			valid_len += vrk->key_len - 1;
2116 		}
2117 		break;
2118 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
2119 		valid_len = sizeof(struct virtchnl_rss_lut);
2120 		if (msglen >= valid_len) {
2121 			struct virtchnl_rss_lut *vrl =
2122 				(struct virtchnl_rss_lut *)msg;
2123 
2124 			if (vrl->lut_entries == 0) {
2125 				/* zero entries is allowed as input */
2126 				break;
2127 			}
2128 
2129 			valid_len += vrl->lut_entries - 1;
2130 		}
2131 		break;
2132 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
2133 		break;
2134 	case VIRTCHNL_OP_SET_RSS_HENA:
2135 		valid_len = sizeof(struct virtchnl_rss_hena);
2136 		break;
2137 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2138 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2139 		break;
2140 	case VIRTCHNL_OP_REQUEST_QUEUES:
2141 		valid_len = sizeof(struct virtchnl_vf_res_request);
2142 		break;
2143 	case VIRTCHNL_OP_ENABLE_CHANNELS:
2144 		valid_len = sizeof(struct virtchnl_tc_info);
2145 		if (msglen >= valid_len) {
2146 			struct virtchnl_tc_info *vti =
2147 				(struct virtchnl_tc_info *)msg;
2148 
2149 			if (vti->num_tc == 0 || vti->num_tc >
2150 			    VIRTCHNL_OP_ENABLE_CHANNELS_MAX) {
2151 				err_msg_format = true;
2152 				break;
2153 			}
2154 
2155 			valid_len += (vti->num_tc - 1) *
2156 				     sizeof(struct virtchnl_channel_info);
2157 		}
2158 		break;
2159 	case VIRTCHNL_OP_DISABLE_CHANNELS:
2160 		break;
2161 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
2162 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
2163 		valid_len = sizeof(struct virtchnl_filter);
2164 		break;
2165 	case VIRTCHNL_OP_ADD_RSS_CFG:
2166 	case VIRTCHNL_OP_DEL_RSS_CFG:
2167 		valid_len = sizeof(struct virtchnl_rss_cfg);
2168 		break;
2169 	case VIRTCHNL_OP_ADD_FDIR_FILTER:
2170 		valid_len = sizeof(struct virtchnl_fdir_add);
2171 		break;
2172 	case VIRTCHNL_OP_DEL_FDIR_FILTER:
2173 		valid_len = sizeof(struct virtchnl_fdir_del);
2174 		break;
2175 	case VIRTCHNL_OP_GET_QOS_CAPS:
2176 		break;
2177 	case VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP:
2178 		valid_len = sizeof(struct virtchnl_queue_tc_mapping);
2179 		if (msglen >= valid_len) {
2180 			struct virtchnl_queue_tc_mapping *q_tc =
2181 				(struct virtchnl_queue_tc_mapping *)msg;
2182 			if (q_tc->num_tc == 0) {
2183 				err_msg_format = true;
2184 				break;
2185 			}
2186 			valid_len += (q_tc->num_tc - 1) *
2187 					 sizeof(q_tc->tc[0]);
2188 		}
2189 		break;
2190 	case VIRTCHNL_OP_CONFIG_QUEUE_BW:
2191 		valid_len = sizeof(struct virtchnl_queues_bw_cfg);
2192 		if (msglen >= valid_len) {
2193 			struct virtchnl_queues_bw_cfg *q_bw =
2194 				(struct virtchnl_queues_bw_cfg *)msg;
2195 			if (q_bw->num_queues == 0) {
2196 				err_msg_format = true;
2197 				break;
2198 			}
2199 			valid_len += (q_bw->num_queues - 1) *
2200 					 sizeof(q_bw->cfg[0]);
2201 		}
2202 		break;
2203 	case VIRTCHNL_OP_CONFIG_QUANTA:
2204 		valid_len = sizeof(struct virtchnl_quanta_cfg);
2205 		if (msglen >= valid_len) {
2206 			struct virtchnl_quanta_cfg *q_quanta =
2207 				(struct virtchnl_quanta_cfg *)msg;
2208 			if (q_quanta->quanta_size == 0 ||
2209 			    q_quanta->queue_select.num_queues == 0) {
2210 				err_msg_format = true;
2211 				break;
2212 			}
2213 		}
2214 		break;
2215 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
2216 		break;
2217 	case VIRTCHNL_OP_ADD_VLAN_V2:
2218 	case VIRTCHNL_OP_DEL_VLAN_V2:
2219 		valid_len = sizeof(struct virtchnl_vlan_filter_list_v2);
2220 		if (msglen >= valid_len) {
2221 			struct virtchnl_vlan_filter_list_v2 *vfl =
2222 			    (struct virtchnl_vlan_filter_list_v2 *)msg;
2223 
2224 			if (vfl->num_elements == 0 || vfl->num_elements >
2225 			    VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX) {
2226 				err_msg_format = true;
2227 				break;
2228 			}
2229 
2230 			valid_len += (vfl->num_elements - 1) *
2231 				sizeof(struct virtchnl_vlan_filter);
2232 		}
2233 		break;
2234 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
2235 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
2236 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
2237 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
2238 	case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2:
2239 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
2240 		valid_len = sizeof(struct virtchnl_vlan_setting);
2241 		break;
2242 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
2243 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
2244 		valid_len = sizeof(struct virtchnl_del_ena_dis_queues);
2245 		if (msglen >= valid_len) {
2246 			struct virtchnl_del_ena_dis_queues *qs =
2247 				(struct virtchnl_del_ena_dis_queues *)msg;
2248 			if (qs->chunks.num_chunks == 0 ||
2249 			    qs->chunks.num_chunks > VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX) {
2250 				err_msg_format = true;
2251 				break;
2252 			}
2253 			valid_len += (qs->chunks.num_chunks - 1) *
2254 				      sizeof(struct virtchnl_queue_chunk);
2255 		}
2256 		break;
2257 	case VIRTCHNL_OP_MAP_QUEUE_VECTOR:
2258 		valid_len = sizeof(struct virtchnl_queue_vector_maps);
2259 		if (msglen >= valid_len) {
2260 			struct virtchnl_queue_vector_maps *v_qp =
2261 				(struct virtchnl_queue_vector_maps *)msg;
2262 			if (v_qp->num_qv_maps == 0 ||
2263 			    v_qp->num_qv_maps > VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX) {
2264 				err_msg_format = true;
2265 				break;
2266 			}
2267 			valid_len += (v_qp->num_qv_maps - 1) *
2268 				      sizeof(struct virtchnl_queue_vector);
2269 		}
2270 		break;
2271 	/* These are always errors coming from the VF. */
2272 	case VIRTCHNL_OP_EVENT:
2273 	case VIRTCHNL_OP_UNKNOWN:
2274 	default:
2275 		return VIRTCHNL_STATUS_ERR_PARAM;
2276 	}
2277 	/* few more checks */
2278 	if (err_msg_format || valid_len != msglen)
2279 		return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
2280 
2281 	return 0;
2282 }
2283 #endif /* _VIRTCHNL_H_ */
2284