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