xref: /dpdk/drivers/common/iavf/virtchnl.h (revision 4e2cf9af)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2020 Intel Corporation
3  */
4 
5 #ifndef _VIRTCHNL_H_
6 #define _VIRTCHNL_H_
7 
8 /* Description:
9  * This header file describes the VF-PF communication protocol used
10  * by the drivers for all devices starting from our 40G product line
11  *
12  * Admin queue buffer usage:
13  * desc->opcode is always aqc_opc_send_msg_to_pf
14  * flags, retval, datalen, and data addr are all used normally.
15  * The Firmware copies the cookie fields when sending messages between the
16  * PF and VF, but uses all other fields internally. Due to this limitation,
17  * we must send all messages as "indirect", i.e. using an external buffer.
18  *
19  * All the VSI indexes are relative to the VF. Each VF can have maximum of
20  * three VSIs. All the queue indexes are relative to the VSI.  Each VF can
21  * have a maximum of sixteen queues for all of its VSIs.
22  *
23  * The PF is required to return a status code in v_retval for all messages
24  * except RESET_VF, which does not require any response. The return value
25  * is of status_code type, defined in the shared type.h.
26  *
27  * In general, VF driver initialization should roughly follow the order of
28  * these opcodes. The VF driver must first validate the API version of the
29  * PF driver, then request a reset, then get resources, then configure
30  * queues and interrupts. After these operations are complete, the VF
31  * driver may start its queues, optionally add MAC and VLAN filters, and
32  * process traffic.
33  */
34 
35 /* START GENERIC DEFINES
36  * Need to ensure the following enums and defines hold the same meaning and
37  * value in current and future projects
38  */
39 
40 /* Error Codes */
41 enum virtchnl_status_code {
42 	VIRTCHNL_STATUS_SUCCESS				= 0,
43 	VIRTCHNL_STATUS_ERR_PARAM			= -5,
44 	VIRTCHNL_STATUS_ERR_NO_MEMORY			= -18,
45 	VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH		= -38,
46 	VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR		= -39,
47 	VIRTCHNL_STATUS_ERR_INVALID_VF_ID		= -40,
48 	VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR		= -53,
49 	VIRTCHNL_STATUS_ERR_NOT_SUPPORTED		= -64,
50 };
51 
52 /* Backward compatibility */
53 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
54 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
55 
56 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT		0x0
57 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT		0x1
58 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT	0x2
59 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT		0x3
60 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT		0x4
61 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT		0x5
62 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT		0x6
63 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT		0x7
64 
65 enum virtchnl_link_speed {
66 	VIRTCHNL_LINK_SPEED_UNKNOWN	= 0,
67 	VIRTCHNL_LINK_SPEED_100MB	= BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
68 	VIRTCHNL_LINK_SPEED_1GB		= BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
69 	VIRTCHNL_LINK_SPEED_10GB	= BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
70 	VIRTCHNL_LINK_SPEED_40GB	= BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
71 	VIRTCHNL_LINK_SPEED_20GB	= BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
72 	VIRTCHNL_LINK_SPEED_25GB	= BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
73 	VIRTCHNL_LINK_SPEED_2_5GB	= BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
74 	VIRTCHNL_LINK_SPEED_5GB		= BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
75 };
76 
77 /* for hsplit_0 field of Rx HMC context */
78 /* deprecated with IAVF 1.0 */
79 enum virtchnl_rx_hsplit {
80 	VIRTCHNL_RX_HSPLIT_NO_SPLIT      = 0,
81 	VIRTCHNL_RX_HSPLIT_SPLIT_L2      = 1,
82 	VIRTCHNL_RX_HSPLIT_SPLIT_IP      = 2,
83 	VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
84 	VIRTCHNL_RX_HSPLIT_SPLIT_SCTP    = 8,
85 };
86 
87 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS	6
88 /* END GENERIC DEFINES */
89 
90 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
91  * of the virtchnl_msg structure.
92  */
93 enum virtchnl_ops {
94 /* The PF sends status change events to VFs using
95  * the VIRTCHNL_OP_EVENT opcode.
96  * VFs send requests to the PF using the other ops.
97  * Use of "advanced opcode" features must be negotiated as part of capabilities
98  * exchange and are not considered part of base mode feature set.
99  */
100 	VIRTCHNL_OP_UNKNOWN = 0,
101 	VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
102 	VIRTCHNL_OP_RESET_VF = 2,
103 	VIRTCHNL_OP_GET_VF_RESOURCES = 3,
104 	VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
105 	VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
106 	VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
107 	VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
108 	VIRTCHNL_OP_ENABLE_QUEUES = 8,
109 	VIRTCHNL_OP_DISABLE_QUEUES = 9,
110 	VIRTCHNL_OP_ADD_ETH_ADDR = 10,
111 	VIRTCHNL_OP_DEL_ETH_ADDR = 11,
112 	VIRTCHNL_OP_ADD_VLAN = 12,
113 	VIRTCHNL_OP_DEL_VLAN = 13,
114 	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
115 	VIRTCHNL_OP_GET_STATS = 15,
116 	VIRTCHNL_OP_RSVD = 16,
117 	VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
118 	/* opcode 19 is reserved */
119 	/* opcodes 20, 21, and 22 are reserved */
120 	VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
121 	VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
122 	VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
123 	VIRTCHNL_OP_SET_RSS_HENA = 26,
124 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
125 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
126 	VIRTCHNL_OP_REQUEST_QUEUES = 29,
127 	VIRTCHNL_OP_ENABLE_CHANNELS = 30,
128 	VIRTCHNL_OP_DISABLE_CHANNELS = 31,
129 	VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
130 	VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
131 	/* opcodes 34, 35, 36, 37 and 38 are reserved */
132 	VIRTCHNL_OP_DCF_CMD_DESC = 39,
133 	VIRTCHNL_OP_DCF_CMD_BUFF = 40,
134 	VIRTCHNL_OP_DCF_DISABLE = 41,
135 	VIRTCHNL_OP_DCF_GET_VSI_MAP = 42,
136 	VIRTCHNL_OP_DCF_GET_PKG_INFO = 43,
137 	VIRTCHNL_OP_GET_SUPPORTED_RXDIDS = 44,
138 	VIRTCHNL_OP_ADD_RSS_CFG = 45,
139 	VIRTCHNL_OP_DEL_RSS_CFG = 46,
140 	VIRTCHNL_OP_ADD_FDIR_FILTER = 47,
141 	VIRTCHNL_OP_DEL_FDIR_FILTER = 48,
142 	VIRTCHNL_OP_QUERY_FDIR_FILTER = 49,
143 };
144 
145 /* These macros are used to generate compilation errors if a structure/union
146  * is not exactly the correct length. It gives a divide by zero error if the
147  * structure/union is not of the correct size, otherwise it creates an enum
148  * that is never used.
149  */
150 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
151 	{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
152 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
153 	{ virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
154 
155 /* Virtual channel message descriptor. This overlays the admin queue
156  * descriptor. All other data is passed in external buffers.
157  */
158 
159 struct virtchnl_msg {
160 	u8 pad[8];			 /* AQ flags/opcode/len/retval fields */
161 	enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
162 	enum virtchnl_status_code v_retval;  /* ditto for desc->retval */
163 	u32 vfid;			 /* used by PF when sending to VF */
164 };
165 
166 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
167 
168 /* Message descriptions and data structures. */
169 
170 /* VIRTCHNL_OP_VERSION
171  * VF posts its version number to the PF. PF responds with its version number
172  * in the same format, along with a return code.
173  * Reply from PF has its major/minor versions also in param0 and param1.
174  * If there is a major version mismatch, then the VF cannot operate.
175  * If there is a minor version mismatch, then the VF can operate but should
176  * add a warning to the system log.
177  *
178  * This enum element MUST always be specified as == 1, regardless of other
179  * changes in the API. The PF must always respond to this message without
180  * error regardless of version mismatch.
181  */
182 #define VIRTCHNL_VERSION_MAJOR		1
183 #define VIRTCHNL_VERSION_MINOR		1
184 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS	0
185 
186 struct virtchnl_version_info {
187 	u32 major;
188 	u32 minor;
189 };
190 
191 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
192 
193 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
194 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
195 
196 /* VIRTCHNL_OP_RESET_VF
197  * VF sends this request to PF with no parameters
198  * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
199  * until reset completion is indicated. The admin queue must be reinitialized
200  * after this operation.
201  *
202  * When reset is complete, PF must ensure that all queues in all VSIs associated
203  * with the VF are stopped, all queue configurations in the HMC are set to 0,
204  * and all MAC and VLAN filters (except the default MAC address) on all VSIs
205  * are cleared.
206  */
207 
208 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
209  * vsi_type should always be 6 for backward compatibility. Add other fields
210  * as needed.
211  */
212 enum virtchnl_vsi_type {
213 	VIRTCHNL_VSI_TYPE_INVALID = 0,
214 	VIRTCHNL_VSI_SRIOV = 6,
215 };
216 
217 /* VIRTCHNL_OP_GET_VF_RESOURCES
218  * Version 1.0 VF sends this request to PF with no parameters
219  * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
220  * PF responds with an indirect message containing
221  * virtchnl_vf_resource and one or more
222  * virtchnl_vsi_resource structures.
223  */
224 
225 struct virtchnl_vsi_resource {
226 	u16 vsi_id;
227 	u16 num_queue_pairs;
228 	enum virtchnl_vsi_type vsi_type;
229 	u16 qset_handle;
230 	u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
231 };
232 
233 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
234 
235 /* VF capability flags
236  * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
237  * TX/RX Checksum offloading and TSO for non-tunnelled packets.
238  */
239 #define VIRTCHNL_VF_OFFLOAD_L2			0x00000001
240 #define VIRTCHNL_VF_OFFLOAD_IWARP		0x00000002
241 #define VIRTCHNL_VF_OFFLOAD_RSVD		0x00000004
242 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ		0x00000008
243 #define VIRTCHNL_VF_OFFLOAD_RSS_REG		0x00000010
244 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR		0x00000020
245 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES		0x00000040
246 #define VIRTCHNL_VF_OFFLOAD_CRC			0x00000080
247 #define VIRTCHNL_VF_OFFLOAD_VLAN		0x00010000
248 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING		0x00020000
249 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2	0x00040000
250 #define VIRTCHNL_VF_OFFLOAD_RSS_PF		0X00080000
251 #define VIRTCHNL_VF_OFFLOAD_ENCAP		0X00100000
252 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM		0X00200000
253 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM	0X00400000
254 #define VIRTCHNL_VF_OFFLOAD_ADQ			0X00800000
255 #define VIRTCHNL_VF_OFFLOAD_ADQ_V2		0X01000000
256 #define VIRTCHNL_VF_OFFLOAD_USO			0X02000000
257 #define VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC	0X04000000
258 #define VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF		0X08000000
259 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF		0X10000000
260 	/* 0X20000000 is reserved */
261 #define VIRTCHNL_VF_CAP_DCF			0X40000000
262 	/* 0X80000000 is reserved */
263 
264 /* Define below the capability flags that are not offloads */
265 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED		0x00000080
266 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
267 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
268 			       VIRTCHNL_VF_OFFLOAD_RSS_PF)
269 
270 struct virtchnl_vf_resource {
271 	u16 num_vsis;
272 	u16 num_queue_pairs;
273 	u16 max_vectors;
274 	u16 max_mtu;
275 
276 	u32 vf_cap_flags;
277 	u32 rss_key_size;
278 	u32 rss_lut_size;
279 
280 	struct virtchnl_vsi_resource vsi_res[1];
281 };
282 
283 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
284 
285 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
286  * VF sends this message to set up parameters for one TX queue.
287  * External data buffer contains one instance of virtchnl_txq_info.
288  * PF configures requested queue and returns a status code.
289  */
290 
291 /* Tx queue config info */
292 struct virtchnl_txq_info {
293 	u16 vsi_id;
294 	u16 queue_id;
295 	u16 ring_len;		/* number of descriptors, multiple of 8 */
296 	u16 headwb_enabled; /* deprecated with AVF 1.0 */
297 	u64 dma_ring_addr;
298 	u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
299 };
300 
301 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
302 
303 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
304  * VF sends this message to set up parameters for one RX queue.
305  * External data buffer contains one instance of virtchnl_rxq_info.
306  * PF configures requested queue and returns a status code. The
307  * crc_disable flag disables CRC stripping on the VF. Setting
308  * the crc_disable flag to 1 will disable CRC stripping for each
309  * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC
310  * offload must have been set prior to sending this info or the PF
311  * will ignore the request. This flag should be set the same for
312  * all of the queues for a VF.
313  */
314 
315 /* Rx queue config info */
316 struct virtchnl_rxq_info {
317 	u16 vsi_id;
318 	u16 queue_id;
319 	u32 ring_len;		/* number of descriptors, multiple of 32 */
320 	u16 hdr_size;
321 	u16 splithdr_enabled; /* deprecated with AVF 1.0 */
322 	u32 databuffer_size;
323 	u32 max_pkt_size;
324 	u8 crc_disable;
325 	/* only used when VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC is supported */
326 	u8 rxdid;
327 	u8 pad1[2];
328 	u64 dma_ring_addr;
329 	enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
330 	u32 pad2;
331 };
332 
333 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
334 
335 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
336  * VF sends this message to set parameters for active TX and RX queues
337  * associated with the specified VSI.
338  * PF configures queues and returns status.
339  * If the number of queues specified is greater than the number of queues
340  * associated with the VSI, an error is returned and no queues are configured.
341  * NOTE: The VF is not required to configure all queues in a single request.
342  * It may send multiple messages. PF drivers must correctly handle all VF
343  * requests.
344  */
345 struct virtchnl_queue_pair_info {
346 	/* NOTE: vsi_id and queue_id should be identical for both queues. */
347 	struct virtchnl_txq_info txq;
348 	struct virtchnl_rxq_info rxq;
349 };
350 
351 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
352 
353 struct virtchnl_vsi_queue_config_info {
354 	u16 vsi_id;
355 	u16 num_queue_pairs;
356 	u32 pad;
357 	struct virtchnl_queue_pair_info qpair[1];
358 };
359 
360 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
361 
362 /* VIRTCHNL_OP_REQUEST_QUEUES
363  * VF sends this message to request the PF to allocate additional queues to
364  * this VF.  Each VF gets a guaranteed number of queues on init but asking for
365  * additional queues must be negotiated.  This is a best effort request as it
366  * is possible the PF does not have enough queues left to support the request.
367  * If the PF cannot support the number requested it will respond with the
368  * maximum number it is able to support.  If the request is successful, PF will
369  * then reset the VF to institute required changes.
370  */
371 
372 /* VF resource request */
373 struct virtchnl_vf_res_request {
374 	u16 num_queue_pairs;
375 };
376 
377 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
378  * VF uses this message to map vectors to queues.
379  * The rxq_map and txq_map fields are bitmaps used to indicate which queues
380  * are to be associated with the specified vector.
381  * The "other" causes are always mapped to vector 0. The VF may not request
382  * that vector 0 be used for traffic.
383  * PF configures interrupt mapping and returns status.
384  * NOTE: due to hardware requirements, all active queues (both TX and RX)
385  * should be mapped to interrupts, even if the driver intends to operate
386  * only in polling mode. In this case the interrupt may be disabled, but
387  * the ITR timer will still run to trigger writebacks.
388  */
389 struct virtchnl_vector_map {
390 	u16 vsi_id;
391 	u16 vector_id;
392 	u16 rxq_map;
393 	u16 txq_map;
394 	u16 rxitr_idx;
395 	u16 txitr_idx;
396 };
397 
398 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
399 
400 struct virtchnl_irq_map_info {
401 	u16 num_vectors;
402 	struct virtchnl_vector_map vecmap[1];
403 };
404 
405 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
406 
407 /* VIRTCHNL_OP_ENABLE_QUEUES
408  * VIRTCHNL_OP_DISABLE_QUEUES
409  * VF sends these message to enable or disable TX/RX queue pairs.
410  * The queues fields are bitmaps indicating which queues to act upon.
411  * (Currently, we only support 16 queues per VF, but we make the field
412  * u32 to allow for expansion.)
413  * PF performs requested action and returns status.
414  * NOTE: The VF is not required to enable/disable all queues in a single
415  * request. It may send multiple messages.
416  * PF drivers must correctly handle all VF requests.
417  */
418 struct virtchnl_queue_select {
419 	u16 vsi_id;
420 	u16 pad;
421 	u32 rx_queues;
422 	u32 tx_queues;
423 };
424 
425 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
426 
427 /* VIRTCHNL_OP_ADD_ETH_ADDR
428  * VF sends this message in order to add one or more unicast or multicast
429  * address filters for the specified VSI.
430  * PF adds the filters and returns status.
431  */
432 
433 /* VIRTCHNL_OP_DEL_ETH_ADDR
434  * VF sends this message in order to remove one or more unicast or multicast
435  * filters for the specified VSI.
436  * PF removes the filters and returns status.
437  */
438 
439 /* VIRTCHNL_ETHER_ADDR_LEGACY
440  * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad
441  * bytes. Moving forward all VF drivers should not set type to
442  * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy
443  * behavior. The control plane function (i.e. PF) can use a best effort method
444  * of tracking the primary/device unicast in this case, but there is no
445  * guarantee and functionality depends on the implementation of the PF.
446  */
447 
448 /* VIRTCHNL_ETHER_ADDR_PRIMARY
449  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the
450  * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and
451  * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane
452  * function (i.e. PF) to accurately track and use this MAC address for
453  * displaying on the host and for VM/function reset.
454  */
455 
456 /* VIRTCHNL_ETHER_ADDR_EXTRA
457  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra
458  * unicast and/or multicast filters that are being added/deleted via
459  * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively.
460  */
461 struct virtchnl_ether_addr {
462 	u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
463 	u8 type;
464 #define VIRTCHNL_ETHER_ADDR_LEGACY	0
465 #define VIRTCHNL_ETHER_ADDR_PRIMARY	1
466 #define VIRTCHNL_ETHER_ADDR_EXTRA	2
467 #define VIRTCHNL_ETHER_ADDR_TYPE_MASK	3 /* first two bits of type are valid */
468 	u8 pad;
469 };
470 
471 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
472 
473 struct virtchnl_ether_addr_list {
474 	u16 vsi_id;
475 	u16 num_elements;
476 	struct virtchnl_ether_addr list[1];
477 };
478 
479 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
480 
481 /* VIRTCHNL_OP_ADD_VLAN
482  * VF sends this message to add one or more VLAN tag filters for receives.
483  * PF adds the filters and returns status.
484  * If a port VLAN is configured by the PF, this operation will return an
485  * error to the VF.
486  */
487 
488 /* VIRTCHNL_OP_DEL_VLAN
489  * VF sends this message to remove one or more VLAN tag filters for receives.
490  * PF removes the filters and returns status.
491  * If a port VLAN is configured by the PF, this operation will return an
492  * error to the VF.
493  */
494 
495 struct virtchnl_vlan_filter_list {
496 	u16 vsi_id;
497 	u16 num_elements;
498 	u16 vlan_id[1];
499 };
500 
501 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
502 
503 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
504  * VF sends VSI id and flags.
505  * PF returns status code in retval.
506  * Note: we assume that broadcast accept mode is always enabled.
507  */
508 struct virtchnl_promisc_info {
509 	u16 vsi_id;
510 	u16 flags;
511 };
512 
513 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
514 
515 #define FLAG_VF_UNICAST_PROMISC	0x00000001
516 #define FLAG_VF_MULTICAST_PROMISC	0x00000002
517 
518 /* VIRTCHNL_OP_GET_STATS
519  * VF sends this message to request stats for the selected VSI. VF uses
520  * the virtchnl_queue_select struct to specify the VSI. The queue_id
521  * field is ignored by the PF.
522  *
523  * PF replies with struct virtchnl_eth_stats in an external buffer.
524  */
525 
526 struct virtchnl_eth_stats {
527 	u64 rx_bytes;			/* received bytes */
528 	u64 rx_unicast;			/* received unicast pkts */
529 	u64 rx_multicast;		/* received multicast pkts */
530 	u64 rx_broadcast;		/* received broadcast pkts */
531 	u64 rx_discards;
532 	u64 rx_unknown_protocol;
533 	u64 tx_bytes;			/* transmitted bytes */
534 	u64 tx_unicast;			/* transmitted unicast pkts */
535 	u64 tx_multicast;		/* transmitted multicast pkts */
536 	u64 tx_broadcast;		/* transmitted broadcast pkts */
537 	u64 tx_discards;
538 	u64 tx_errors;
539 };
540 
541 /* VIRTCHNL_OP_CONFIG_RSS_KEY
542  * VIRTCHNL_OP_CONFIG_RSS_LUT
543  * VF sends these messages to configure RSS. Only supported if both PF
544  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
545  * configuration negotiation. If this is the case, then the RSS fields in
546  * the VF resource struct are valid.
547  * Both the key and LUT are initialized to 0 by the PF, meaning that
548  * RSS is effectively disabled until set up by the VF.
549  */
550 struct virtchnl_rss_key {
551 	u16 vsi_id;
552 	u16 key_len;
553 	u8 key[1];         /* RSS hash key, packed bytes */
554 };
555 
556 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
557 
558 struct virtchnl_rss_lut {
559 	u16 vsi_id;
560 	u16 lut_entries;
561 	u8 lut[1];        /* RSS lookup table */
562 };
563 
564 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
565 
566 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
567  * VIRTCHNL_OP_SET_RSS_HENA
568  * VF sends these messages to get and set the hash filter enable bits for RSS.
569  * By default, the PF sets these to all possible traffic types that the
570  * hardware supports. The VF can query this value if it wants to change the
571  * traffic types that are hashed by the hardware.
572  */
573 struct virtchnl_rss_hena {
574 	u64 hena;
575 };
576 
577 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
578 
579 /* Type of RSS algorithm */
580 enum virtchnl_rss_algorithm {
581 	VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC	= 0,
582 	VIRTCHNL_RSS_ALG_XOR_ASYMMETRIC		= 1,
583 	VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC	= 2,
584 	VIRTCHNL_RSS_ALG_XOR_SYMMETRIC		= 3,
585 };
586 
587 /* This is used by PF driver to enforce how many channels can be supported.
588  * When ADQ_V2 capability is negotiated, it will allow 16 channels otherwise
589  * PF driver will allow only max 4 channels
590  */
591 #define VIRTCHNL_MAX_ADQ_CHANNELS 4
592 #define VIRTCHNL_MAX_ADQ_V2_CHANNELS 16
593 
594 /* VIRTCHNL_OP_ENABLE_CHANNELS
595  * VIRTCHNL_OP_DISABLE_CHANNELS
596  * VF sends these messages to enable or disable channels based on
597  * the user specified queue count and queue offset for each traffic class.
598  * This struct encompasses all the information that the PF needs from
599  * VF to create a channel.
600  */
601 struct virtchnl_channel_info {
602 	u16 count; /* number of queues in a channel */
603 	u16 offset; /* queues in a channel start from 'offset' */
604 	u32 pad;
605 	u64 max_tx_rate;
606 };
607 
608 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
609 
610 struct virtchnl_tc_info {
611 	u32	num_tc;
612 	u32	pad;
613 	struct	virtchnl_channel_info list[1];
614 };
615 
616 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
617 
618 /* VIRTCHNL_ADD_CLOUD_FILTER
619  * VIRTCHNL_DEL_CLOUD_FILTER
620  * VF sends these messages to add or delete a cloud filter based on the
621  * user specified match and action filters. These structures encompass
622  * all the information that the PF needs from the VF to add/delete a
623  * cloud filter.
624  */
625 
626 struct virtchnl_l4_spec {
627 	u8	src_mac[ETH_ALEN];
628 	u8	dst_mac[ETH_ALEN];
629 	/* vlan_prio is part of this 16 bit field even from OS perspective
630 	 * vlan_id:12 is actual vlan_id, then vlanid:bit14..12 is vlan_prio
631 	 * in future, when decided to offload vlan_prio, pass that information
632 	 * as part of the "vlan_id" field, Bit14..12
633 	 */
634 	__be16	vlan_id;
635 	__be16	pad; /* reserved for future use */
636 	__be32	src_ip[4];
637 	__be32	dst_ip[4];
638 	__be16	src_port;
639 	__be16	dst_port;
640 };
641 
642 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
643 
644 union virtchnl_flow_spec {
645 	struct	virtchnl_l4_spec tcp_spec;
646 	u8	buffer[128]; /* reserved for future use */
647 };
648 
649 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
650 
651 enum virtchnl_action {
652 	/* action types */
653 	VIRTCHNL_ACTION_DROP = 0,
654 	VIRTCHNL_ACTION_TC_REDIRECT,
655 	VIRTCHNL_ACTION_PASSTHRU,
656 	VIRTCHNL_ACTION_QUEUE,
657 	VIRTCHNL_ACTION_Q_REGION,
658 	VIRTCHNL_ACTION_MARK,
659 	VIRTCHNL_ACTION_COUNT,
660 };
661 
662 enum virtchnl_flow_type {
663 	/* flow types */
664 	VIRTCHNL_TCP_V4_FLOW = 0,
665 	VIRTCHNL_TCP_V6_FLOW,
666 	VIRTCHNL_UDP_V4_FLOW,
667 	VIRTCHNL_UDP_V6_FLOW,
668 };
669 
670 struct virtchnl_filter {
671 	union	virtchnl_flow_spec data;
672 	union	virtchnl_flow_spec mask;
673 	enum	virtchnl_flow_type flow_type;
674 	enum	virtchnl_action action;
675 	u32	action_meta;
676 	u8	field_flags;
677 };
678 
679 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
680 
681 /* VIRTCHNL_OP_DCF_GET_VSI_MAP
682  * VF sends this message to get VSI mapping table.
683  * PF responds with an indirect message containing VF's
684  * HW VSI IDs.
685  * The index of vf_vsi array is the logical VF ID, the
686  * value of vf_vsi array is the VF's HW VSI ID with its
687  * valid configuration.
688  */
689 struct virtchnl_dcf_vsi_map {
690 	u16 pf_vsi;	/* PF's HW VSI ID */
691 	u16 num_vfs;	/* The actual number of VFs allocated */
692 #define VIRTCHNL_DCF_VF_VSI_ID_S	0
693 #define VIRTCHNL_DCF_VF_VSI_ID_M	(0xFFF << VIRTCHNL_DCF_VF_VSI_ID_S)
694 #define VIRTCHNL_DCF_VF_VSI_VALID	BIT(15)
695 	u16 vf_vsi[1];
696 };
697 
698 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_dcf_vsi_map);
699 
700 #define PKG_NAME_SIZE	32
701 #define DSN_SIZE	8
702 
703 struct pkg_version {
704 	u8 major;
705 	u8 minor;
706 	u8 update;
707 	u8 draft;
708 };
709 
710 VIRTCHNL_CHECK_STRUCT_LEN(4, pkg_version);
711 
712 struct virtchnl_pkg_info {
713 	struct pkg_version pkg_ver;
714 	u32 track_id;
715 	char pkg_name[PKG_NAME_SIZE];
716 	u8 dsn[DSN_SIZE];
717 };
718 
719 VIRTCHNL_CHECK_STRUCT_LEN(48, virtchnl_pkg_info);
720 
721 struct virtchnl_supported_rxdids {
722 	u64 supported_rxdids;
723 };
724 
725 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_supported_rxdids);
726 
727 /* VIRTCHNL_OP_EVENT
728  * PF sends this message to inform the VF driver of events that may affect it.
729  * No direct response is expected from the VF, though it may generate other
730  * messages in response to this one.
731  */
732 enum virtchnl_event_codes {
733 	VIRTCHNL_EVENT_UNKNOWN = 0,
734 	VIRTCHNL_EVENT_LINK_CHANGE,
735 	VIRTCHNL_EVENT_RESET_IMPENDING,
736 	VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
737 	VIRTCHNL_EVENT_DCF_VSI_MAP_UPDATE,
738 };
739 
740 #define PF_EVENT_SEVERITY_INFO		0
741 #define PF_EVENT_SEVERITY_ATTENTION	1
742 #define PF_EVENT_SEVERITY_ACTION_REQUIRED	2
743 #define PF_EVENT_SEVERITY_CERTAIN_DOOM	255
744 
745 struct virtchnl_pf_event {
746 	enum virtchnl_event_codes event;
747 	union {
748 		/* If the PF driver does not support the new speed reporting
749 		 * capabilities then use link_event else use link_event_adv to
750 		 * get the speed and link information. The ability to understand
751 		 * new speeds is indicated by setting the capability flag
752 		 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
753 		 * in virtchnl_vf_resource struct and can be used to determine
754 		 * which link event struct to use below.
755 		 */
756 		struct {
757 			enum virtchnl_link_speed link_speed;
758 			u8 link_status;
759 		} link_event;
760 		struct {
761 			/* link_speed provided in Mbps */
762 			u32 link_speed;
763 			u8 link_status;
764 		} link_event_adv;
765 		struct {
766 			u16 vf_id;
767 			u16 vsi_id;
768 		} vf_vsi_map;
769 	} event_data;
770 
771 	int severity;
772 };
773 
774 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
775 
776 
777 /* Since VF messages are limited by u16 size, precalculate the maximum possible
778  * values of nested elements in virtchnl structures that virtual channel can
779  * possibly handle in a single message.
780  */
781 enum virtchnl_vector_limits {
782 	VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX	=
783 		((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) /
784 		sizeof(struct virtchnl_queue_pair_info),
785 
786 	VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX		=
787 		((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) /
788 		sizeof(struct virtchnl_vector_map),
789 
790 	VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX	=
791 		((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) /
792 		sizeof(struct virtchnl_ether_addr),
793 
794 	VIRTCHNL_OP_ADD_DEL_VLAN_MAX		=
795 		((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) /
796 		sizeof(u16),
797 
798 
799 	VIRTCHNL_OP_ENABLE_CHANNELS_MAX		=
800 		((u16)(~0) - sizeof(struct virtchnl_tc_info)) /
801 		sizeof(struct virtchnl_channel_info),
802 };
803 
804 /* VF reset states - these are written into the RSTAT register:
805  * VFGEN_RSTAT on the VF
806  * When the PF initiates a reset, it writes 0
807  * When the reset is complete, it writes 1
808  * When the PF detects that the VF has recovered, it writes 2
809  * VF checks this register periodically to determine if a reset has occurred,
810  * then polls it to know when the reset is complete.
811  * If either the PF or VF reads the register while the hardware
812  * is in a reset state, it will return DEADBEEF, which, when masked
813  * will result in 3.
814  */
815 enum virtchnl_vfr_states {
816 	VIRTCHNL_VFR_INPROGRESS = 0,
817 	VIRTCHNL_VFR_COMPLETED,
818 	VIRTCHNL_VFR_VFACTIVE,
819 };
820 
821 #define VIRTCHNL_MAX_NUM_PROTO_HDRS	32
822 #define PROTO_HDR_SHIFT			5
823 #define PROTO_HDR_FIELD_START(proto_hdr_type) \
824 					(proto_hdr_type << PROTO_HDR_SHIFT)
825 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1)
826 
827 /* VF use these macros to configure each protocol header.
828  * Specify which protocol headers and protocol header fields base on
829  * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field.
830  * @param hdr: a struct of virtchnl_proto_hdr
831  * @param hdr_type: ETH/IPV4/TCP, etc
832  * @param field: SRC/DST/TEID/SPI, etc
833  */
834 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field) \
835 	((hdr)->field_selector |= BIT((field) & PROTO_HDR_FIELD_MASK))
836 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field) \
837 	((hdr)->field_selector &= ~BIT((field) & PROTO_HDR_FIELD_MASK))
838 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val) \
839 	((hdr)->field_selector & BIT((val) & PROTO_HDR_FIELD_MASK))
840 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr)	((hdr)->field_selector)
841 
842 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
843 	(VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, \
844 		VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
845 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
846 	(VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, \
847 		VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
848 
849 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type) \
850 	((hdr)->type = VIRTCHNL_PROTO_HDR_ ## hdr_type)
851 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \
852 	(((hdr)->type) >> PROTO_HDR_SHIFT)
853 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \
854 	((hdr)->type == ((val) >> PROTO_HDR_SHIFT))
855 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \
856 	(VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) && \
857 	 VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val))
858 
859 /* Protocol header type within a packet segment. A segment consists of one or
860  * more protocol headers that make up a logical group of protocol headers. Each
861  * logical group of protocol headers encapsulates or is encapsulated using/by
862  * tunneling or encapsulation protocols for network virtualization.
863  */
864 enum virtchnl_proto_hdr_type {
865 	VIRTCHNL_PROTO_HDR_NONE,
866 	VIRTCHNL_PROTO_HDR_ETH,
867 	VIRTCHNL_PROTO_HDR_S_VLAN,
868 	VIRTCHNL_PROTO_HDR_C_VLAN,
869 	VIRTCHNL_PROTO_HDR_IPV4,
870 	VIRTCHNL_PROTO_HDR_IPV6,
871 	VIRTCHNL_PROTO_HDR_TCP,
872 	VIRTCHNL_PROTO_HDR_UDP,
873 	VIRTCHNL_PROTO_HDR_SCTP,
874 	VIRTCHNL_PROTO_HDR_GTPU_IP,
875 	VIRTCHNL_PROTO_HDR_GTPU_EH,
876 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
877 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
878 	VIRTCHNL_PROTO_HDR_PPPOE,
879 	VIRTCHNL_PROTO_HDR_L2TPV3,
880 	VIRTCHNL_PROTO_HDR_ESP,
881 	VIRTCHNL_PROTO_HDR_AH,
882 	VIRTCHNL_PROTO_HDR_PFCP,
883 	VIRTCHNL_PROTO_HDR_GTPC,
884 };
885 
886 /* Protocol header field within a protocol header. */
887 enum virtchnl_proto_hdr_field {
888 	/* ETHER */
889 	VIRTCHNL_PROTO_HDR_ETH_SRC =
890 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ETH),
891 	VIRTCHNL_PROTO_HDR_ETH_DST,
892 	VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
893 	/* S-VLAN */
894 	VIRTCHNL_PROTO_HDR_S_VLAN_ID =
895 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_S_VLAN),
896 	/* C-VLAN */
897 	VIRTCHNL_PROTO_HDR_C_VLAN_ID =
898 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_C_VLAN),
899 	/* IPV4 */
900 	VIRTCHNL_PROTO_HDR_IPV4_SRC =
901 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4),
902 	VIRTCHNL_PROTO_HDR_IPV4_DST,
903 	VIRTCHNL_PROTO_HDR_IPV4_DSCP,
904 	VIRTCHNL_PROTO_HDR_IPV4_TTL,
905 	VIRTCHNL_PROTO_HDR_IPV4_PROT,
906 	/* IPV6 */
907 	VIRTCHNL_PROTO_HDR_IPV6_SRC =
908 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6),
909 	VIRTCHNL_PROTO_HDR_IPV6_DST,
910 	VIRTCHNL_PROTO_HDR_IPV6_TC,
911 	VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
912 	VIRTCHNL_PROTO_HDR_IPV6_PROT,
913 	/* IPV6 Prefix */
914 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX32_SRC,
915 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX32_DST,
916 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX40_SRC,
917 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX40_DST,
918 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX48_SRC,
919 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX48_DST,
920 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX56_SRC,
921 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX56_DST,
922 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX64_SRC,
923 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX64_DST,
924 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX96_SRC,
925 	VIRTCHNL_PROTO_HDR_IPV6_PREFIX96_DST,
926 	/* TCP */
927 	VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
928 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_TCP),
929 	VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
930 	/* UDP */
931 	VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
932 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_UDP),
933 	VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
934 	/* SCTP */
935 	VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
936 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_SCTP),
937 	VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
938 	/* GTPU_IP */
939 	VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
940 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_IP),
941 	/* GTPU_EH */
942 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
943 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH),
944 	VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
945 	/* PPPOE */
946 	VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
947 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PPPOE),
948 	/* L2TPV3 */
949 	VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
950 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV3),
951 	/* ESP */
952 	VIRTCHNL_PROTO_HDR_ESP_SPI =
953 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ESP),
954 	/* AH */
955 	VIRTCHNL_PROTO_HDR_AH_SPI =
956 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_AH),
957 	/* PFCP */
958 	VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
959 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PFCP),
960 	VIRTCHNL_PROTO_HDR_PFCP_SEID,
961 	/* GTPC */
962 	VIRTCHNL_PROTO_HDR_GTPC_TEID =
963 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPC),
964 };
965 
966 struct virtchnl_proto_hdr {
967 	enum virtchnl_proto_hdr_type type;
968 	u32 field_selector; /* a bit mask to select field for header type */
969 	u8 buffer[64];
970 	/**
971 	 * binary buffer in network order for specific header type.
972 	 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
973 	 * header is expected to be copied into the buffer.
974 	 */
975 };
976 
977 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr);
978 
979 struct virtchnl_proto_hdrs {
980 	u8 tunnel_level;
981 	/**
982 	 * specify where protocol header start from.
983 	 * 0 - from the outer layer
984 	 * 1 - from the first inner layer
985 	 * 2 - from the second inner layer
986 	 * ....
987 	 **/
988 	int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */
989 	struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
990 };
991 
992 VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs);
993 
994 struct virtchnl_rss_cfg {
995 	struct virtchnl_proto_hdrs proto_hdrs;	   /* protocol headers */
996 	enum virtchnl_rss_algorithm rss_algorithm; /* rss algorithm type */
997 	u8 reserved[128];                          /* reserve for future */
998 };
999 
1000 VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg);
1001 
1002 /* action configuration for FDIR */
1003 struct virtchnl_filter_action {
1004 	enum virtchnl_action type;
1005 	union {
1006 		/* used for queue and qgroup action */
1007 		struct {
1008 			u16 index;
1009 			u8 region;
1010 		} queue;
1011 		/* used for count action */
1012 		struct {
1013 			/* share counter ID with other flow rules */
1014 			u8 shared;
1015 			u32 id; /* counter ID */
1016 		} count;
1017 		/* used for mark action */
1018 		u32 mark_id;
1019 		u8 reserve[32];
1020 	} act_conf;
1021 };
1022 
1023 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action);
1024 
1025 #define VIRTCHNL_MAX_NUM_ACTIONS  8
1026 
1027 struct virtchnl_filter_action_set {
1028 	/* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
1029 	int count;
1030 	struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
1031 };
1032 
1033 VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set);
1034 
1035 /* pattern and action for FDIR rule */
1036 struct virtchnl_fdir_rule {
1037 	struct virtchnl_proto_hdrs proto_hdrs;
1038 	struct virtchnl_filter_action_set action_set;
1039 };
1040 
1041 VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule);
1042 
1043 /* query information to retrieve fdir rule counters.
1044  * PF will fill out this structure to reset counter.
1045  */
1046 struct virtchnl_fdir_query_info {
1047 	u32 match_packets_valid:1;
1048 	u32 match_bytes_valid:1;
1049 	u32 reserved:30;  /* Reserved, must be zero. */
1050 	u32 pad;
1051 	u64 matched_packets; /* Number of packets for this rule. */
1052 	u64 matched_bytes;   /* Number of bytes through this rule. */
1053 };
1054 
1055 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_fdir_query_info);
1056 
1057 /* Status returned to VF after VF requests FDIR commands
1058  * VIRTCHNL_FDIR_SUCCESS
1059  * VF FDIR related request is successfully done by PF
1060  * The request can be OP_ADD/DEL/QUERY_FDIR_FILTER.
1061  *
1062  * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
1063  * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
1064  *
1065  * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
1066  * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
1067  *
1068  * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
1069  * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
1070  *
1071  * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
1072  * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
1073  *
1074  * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
1075  * OP_ADD_FDIR_FILTER request is failed due to parameters validation
1076  * or HW doesn't support.
1077  *
1078  * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
1079  * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
1080  * for programming.
1081  *
1082  * VIRTCHNL_FDIR_FAILURE_QUERY_INVALID
1083  * OP_QUERY_FDIR_FILTER request is failed due to parameters validation,
1084  * for example, VF query counter of a rule who has no counter action.
1085  */
1086 enum virtchnl_fdir_prgm_status {
1087 	VIRTCHNL_FDIR_SUCCESS = 0,
1088 	VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
1089 	VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
1090 	VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
1091 	VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
1092 	VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
1093 	VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
1094 	VIRTCHNL_FDIR_FAILURE_QUERY_INVALID,
1095 };
1096 
1097 /* VIRTCHNL_OP_ADD_FDIR_FILTER
1098  * VF sends this request to PF by filling out vsi_id,
1099  * validate_only and rule_cfg. PF will return flow_id
1100  * if the request is successfully done and return add_status to VF.
1101  */
1102 struct virtchnl_fdir_add {
1103 	u16 vsi_id;  /* INPUT */
1104 	/*
1105 	 * 1 for validating a fdir rule, 0 for creating a fdir rule.
1106 	 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
1107 	 */
1108 	u16 validate_only; /* INPUT */
1109 	u32 flow_id;       /* OUTPUT */
1110 	struct virtchnl_fdir_rule rule_cfg; /* INPUT */
1111 	enum virtchnl_fdir_prgm_status status; /* OUTPUT */
1112 };
1113 
1114 VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add);
1115 
1116 /* VIRTCHNL_OP_DEL_FDIR_FILTER
1117  * VF sends this request to PF by filling out vsi_id
1118  * and flow_id. PF will return del_status to VF.
1119  */
1120 struct virtchnl_fdir_del {
1121 	u16 vsi_id;  /* INPUT */
1122 	u16 pad;
1123 	u32 flow_id; /* INPUT */
1124 	enum virtchnl_fdir_prgm_status status; /* OUTPUT */
1125 };
1126 
1127 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del);
1128 
1129 /* VIRTCHNL_OP_QUERY_FDIR_FILTER
1130  * VF sends this request to PF by filling out vsi_id,
1131  * flow_id and reset_counter. PF will return query_info
1132  * and query_status to VF.
1133  */
1134 struct virtchnl_fdir_query {
1135 	u16 vsi_id;   /* INPUT */
1136 	u16 pad1[3];
1137 	u32 flow_id;  /* INPUT */
1138 	u32 reset_counter:1; /* INPUT */
1139 	struct virtchnl_fdir_query_info query_info; /* OUTPUT */
1140 	enum virtchnl_fdir_prgm_status status;  /* OUTPUT */
1141 	u32 pad2;
1142 };
1143 
1144 VIRTCHNL_CHECK_STRUCT_LEN(48, virtchnl_fdir_query);
1145 /**
1146  * virtchnl_vc_validate_vf_msg
1147  * @ver: Virtchnl version info
1148  * @v_opcode: Opcode for the message
1149  * @msg: pointer to the msg buffer
1150  * @msglen: msg length
1151  *
1152  * validate msg format against struct for each opcode
1153  */
1154 static inline int
1155 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
1156 			    u8 *msg, u16 msglen)
1157 {
1158 	bool err_msg_format = false;
1159 	u32 valid_len = 0;
1160 
1161 	/* Validate message length. */
1162 	switch (v_opcode) {
1163 	case VIRTCHNL_OP_VERSION:
1164 		valid_len = sizeof(struct virtchnl_version_info);
1165 		break;
1166 	case VIRTCHNL_OP_RESET_VF:
1167 		break;
1168 	case VIRTCHNL_OP_GET_VF_RESOURCES:
1169 		if (VF_IS_V11(ver))
1170 			valid_len = sizeof(u32);
1171 		break;
1172 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
1173 		valid_len = sizeof(struct virtchnl_txq_info);
1174 		break;
1175 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
1176 		valid_len = sizeof(struct virtchnl_rxq_info);
1177 		break;
1178 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1179 		valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
1180 		if (msglen >= valid_len) {
1181 			struct virtchnl_vsi_queue_config_info *vqc =
1182 			    (struct virtchnl_vsi_queue_config_info *)msg;
1183 
1184 			if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs >
1185 			    VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) {
1186 				err_msg_format = true;
1187 				break;
1188 			}
1189 
1190 			valid_len += (vqc->num_queue_pairs *
1191 				      sizeof(struct
1192 					     virtchnl_queue_pair_info));
1193 		}
1194 		break;
1195 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1196 		valid_len = sizeof(struct virtchnl_irq_map_info);
1197 		if (msglen >= valid_len) {
1198 			struct virtchnl_irq_map_info *vimi =
1199 			    (struct virtchnl_irq_map_info *)msg;
1200 
1201 			if (vimi->num_vectors == 0 || vimi->num_vectors >
1202 			    VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) {
1203 				err_msg_format = true;
1204 				break;
1205 			}
1206 
1207 			valid_len += (vimi->num_vectors *
1208 				      sizeof(struct virtchnl_vector_map));
1209 		}
1210 		break;
1211 	case VIRTCHNL_OP_ENABLE_QUEUES:
1212 	case VIRTCHNL_OP_DISABLE_QUEUES:
1213 		valid_len = sizeof(struct virtchnl_queue_select);
1214 		break;
1215 	case VIRTCHNL_OP_ADD_ETH_ADDR:
1216 	case VIRTCHNL_OP_DEL_ETH_ADDR:
1217 		valid_len = sizeof(struct virtchnl_ether_addr_list);
1218 		if (msglen >= valid_len) {
1219 			struct virtchnl_ether_addr_list *veal =
1220 			    (struct virtchnl_ether_addr_list *)msg;
1221 
1222 			if (veal->num_elements == 0 || veal->num_elements >
1223 			    VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) {
1224 				err_msg_format = true;
1225 				break;
1226 			}
1227 
1228 			valid_len += veal->num_elements *
1229 			    sizeof(struct virtchnl_ether_addr);
1230 		}
1231 		break;
1232 	case VIRTCHNL_OP_ADD_VLAN:
1233 	case VIRTCHNL_OP_DEL_VLAN:
1234 		valid_len = sizeof(struct virtchnl_vlan_filter_list);
1235 		if (msglen >= valid_len) {
1236 			struct virtchnl_vlan_filter_list *vfl =
1237 			    (struct virtchnl_vlan_filter_list *)msg;
1238 
1239 			if (vfl->num_elements == 0 || vfl->num_elements >
1240 			    VIRTCHNL_OP_ADD_DEL_VLAN_MAX) {
1241 				err_msg_format = true;
1242 				break;
1243 			}
1244 
1245 			valid_len += vfl->num_elements * sizeof(u16);
1246 		}
1247 		break;
1248 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1249 		valid_len = sizeof(struct virtchnl_promisc_info);
1250 		break;
1251 	case VIRTCHNL_OP_GET_STATS:
1252 		valid_len = sizeof(struct virtchnl_queue_select);
1253 		break;
1254 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
1255 		valid_len = sizeof(struct virtchnl_rss_key);
1256 		if (msglen >= valid_len) {
1257 			struct virtchnl_rss_key *vrk =
1258 				(struct virtchnl_rss_key *)msg;
1259 
1260 			if (vrk->key_len == 0) {
1261 				/* zero length is allowed as input */
1262 				break;
1263 			}
1264 
1265 			valid_len += vrk->key_len - 1;
1266 		}
1267 		break;
1268 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
1269 		valid_len = sizeof(struct virtchnl_rss_lut);
1270 		if (msglen >= valid_len) {
1271 			struct virtchnl_rss_lut *vrl =
1272 				(struct virtchnl_rss_lut *)msg;
1273 
1274 			if (vrl->lut_entries == 0) {
1275 				/* zero entries is allowed as input */
1276 				break;
1277 			}
1278 
1279 			valid_len += vrl->lut_entries - 1;
1280 		}
1281 		break;
1282 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
1283 		break;
1284 	case VIRTCHNL_OP_SET_RSS_HENA:
1285 		valid_len = sizeof(struct virtchnl_rss_hena);
1286 		break;
1287 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1288 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1289 		break;
1290 	case VIRTCHNL_OP_REQUEST_QUEUES:
1291 		valid_len = sizeof(struct virtchnl_vf_res_request);
1292 		break;
1293 	case VIRTCHNL_OP_ENABLE_CHANNELS:
1294 		valid_len = sizeof(struct virtchnl_tc_info);
1295 		if (msglen >= valid_len) {
1296 			struct virtchnl_tc_info *vti =
1297 				(struct virtchnl_tc_info *)msg;
1298 
1299 			if (vti->num_tc == 0 || vti->num_tc >
1300 			    VIRTCHNL_OP_ENABLE_CHANNELS_MAX) {
1301 				err_msg_format = true;
1302 				break;
1303 			}
1304 
1305 			valid_len += (vti->num_tc - 1) *
1306 				     sizeof(struct virtchnl_channel_info);
1307 		}
1308 		break;
1309 	case VIRTCHNL_OP_DISABLE_CHANNELS:
1310 		break;
1311 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
1312 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
1313 		valid_len = sizeof(struct virtchnl_filter);
1314 		break;
1315 	case VIRTCHNL_OP_DCF_CMD_DESC:
1316 	case VIRTCHNL_OP_DCF_CMD_BUFF:
1317 		/* These two opcodes are specific to handle the AdminQ command,
1318 		 * so the validation needs to be done in PF's context.
1319 		 */
1320 		valid_len = msglen;
1321 		break;
1322 	case VIRTCHNL_OP_DCF_DISABLE:
1323 	case VIRTCHNL_OP_DCF_GET_VSI_MAP:
1324 	case VIRTCHNL_OP_DCF_GET_PKG_INFO:
1325 		break;
1326 	case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
1327 		break;
1328 	case VIRTCHNL_OP_ADD_RSS_CFG:
1329 	case VIRTCHNL_OP_DEL_RSS_CFG:
1330 		valid_len = sizeof(struct virtchnl_rss_cfg);
1331 		break;
1332 	case VIRTCHNL_OP_ADD_FDIR_FILTER:
1333 		valid_len = sizeof(struct virtchnl_fdir_add);
1334 		break;
1335 	case VIRTCHNL_OP_DEL_FDIR_FILTER:
1336 		valid_len = sizeof(struct virtchnl_fdir_del);
1337 		break;
1338 	case VIRTCHNL_OP_QUERY_FDIR_FILTER:
1339 		valid_len = sizeof(struct virtchnl_fdir_query);
1340 		break;
1341 	/* These are always errors coming from the VF. */
1342 	case VIRTCHNL_OP_EVENT:
1343 	case VIRTCHNL_OP_UNKNOWN:
1344 	default:
1345 		return VIRTCHNL_STATUS_ERR_PARAM;
1346 	}
1347 	/* few more checks */
1348 	if (err_msg_format || valid_len != msglen)
1349 		return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
1350 
1351 	return 0;
1352 }
1353 #endif /* _VIRTCHNL_H_ */
1354