xref: /openbmc/linux/include/linux/avf/virtchnl.h (revision e383353b)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2013-2022, Intel Corporation. */
3 
4 #ifndef _VIRTCHNL_H_
5 #define _VIRTCHNL_H_
6 
7 #include <linux/bitops.h>
8 #include <linux/bits.h>
9 #include <linux/overflow.h>
10 #include <uapi/linux/if_ether.h>
11 
12 /* Description:
13  * This header file describes the Virtual Function (VF) - Physical Function
14  * (PF) communication protocol used by the drivers for all devices starting
15  * from our 40G product line
16  *
17  * Admin queue buffer usage:
18  * desc->opcode is always aqc_opc_send_msg_to_pf
19  * flags, retval, datalen, and data addr are all used normally.
20  * The Firmware copies the cookie fields when sending messages between the
21  * PF and VF, but uses all other fields internally. Due to this limitation,
22  * we must send all messages as "indirect", i.e. using an external buffer.
23  *
24  * All the VSI indexes are relative to the VF. Each VF can have maximum of
25  * three VSIs. All the queue indexes are relative to the VSI.  Each VF can
26  * have a maximum of sixteen queues for all of its VSIs.
27  *
28  * The PF is required to return a status code in v_retval for all messages
29  * except RESET_VF, which does not require any response. The returned value
30  * is of virtchnl_status_code type, defined here.
31  *
32  * In general, VF driver initialization should roughly follow the order of
33  * these opcodes. The VF driver must first validate the API version of the
34  * PF driver, then request a reset, then get resources, then configure
35  * queues and interrupts. After these operations are complete, the VF
36  * driver may start its queues, optionally add MAC and VLAN filters, and
37  * process traffic.
38  */
39 
40 /* START GENERIC DEFINES
41  * Need to ensure the following enums and defines hold the same meaning and
42  * value in current and future projects
43  */
44 
45 /* Error Codes */
46 enum virtchnl_status_code {
47 	VIRTCHNL_STATUS_SUCCESS				= 0,
48 	VIRTCHNL_STATUS_ERR_PARAM			= -5,
49 	VIRTCHNL_STATUS_ERR_NO_MEMORY			= -18,
50 	VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH		= -38,
51 	VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR		= -39,
52 	VIRTCHNL_STATUS_ERR_INVALID_VF_ID		= -40,
53 	VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR		= -53,
54 	VIRTCHNL_STATUS_ERR_NOT_SUPPORTED		= -64,
55 };
56 
57 /* Backward compatibility */
58 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
59 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
60 
61 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT		0x0
62 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT		0x1
63 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT	0x2
64 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT		0x3
65 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT		0x4
66 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT		0x5
67 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT		0x6
68 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT		0x7
69 
70 enum virtchnl_link_speed {
71 	VIRTCHNL_LINK_SPEED_UNKNOWN	= 0,
72 	VIRTCHNL_LINK_SPEED_100MB	= BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
73 	VIRTCHNL_LINK_SPEED_1GB		= BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
74 	VIRTCHNL_LINK_SPEED_10GB	= BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
75 	VIRTCHNL_LINK_SPEED_40GB	= BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
76 	VIRTCHNL_LINK_SPEED_20GB	= BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
77 	VIRTCHNL_LINK_SPEED_25GB	= BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
78 	VIRTCHNL_LINK_SPEED_2_5GB	= BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
79 	VIRTCHNL_LINK_SPEED_5GB		= BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
80 };
81 
82 /* for hsplit_0 field of Rx HMC context */
83 /* deprecated with AVF 1.0 */
84 enum virtchnl_rx_hsplit {
85 	VIRTCHNL_RX_HSPLIT_NO_SPLIT      = 0,
86 	VIRTCHNL_RX_HSPLIT_SPLIT_L2      = 1,
87 	VIRTCHNL_RX_HSPLIT_SPLIT_IP      = 2,
88 	VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
89 	VIRTCHNL_RX_HSPLIT_SPLIT_SCTP    = 8,
90 };
91 
92 /* END GENERIC DEFINES */
93 
94 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
95  * of the virtchnl_msg structure.
96  */
97 enum virtchnl_ops {
98 /* The PF sends status change events to VFs using
99  * the VIRTCHNL_OP_EVENT opcode.
100  * VFs send requests to the PF using the other ops.
101  * Use of "advanced opcode" features must be negotiated as part of capabilities
102  * exchange and are not considered part of base mode feature set.
103  */
104 	VIRTCHNL_OP_UNKNOWN = 0,
105 	VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
106 	VIRTCHNL_OP_RESET_VF = 2,
107 	VIRTCHNL_OP_GET_VF_RESOURCES = 3,
108 	VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
109 	VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
110 	VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
111 	VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
112 	VIRTCHNL_OP_ENABLE_QUEUES = 8,
113 	VIRTCHNL_OP_DISABLE_QUEUES = 9,
114 	VIRTCHNL_OP_ADD_ETH_ADDR = 10,
115 	VIRTCHNL_OP_DEL_ETH_ADDR = 11,
116 	VIRTCHNL_OP_ADD_VLAN = 12,
117 	VIRTCHNL_OP_DEL_VLAN = 13,
118 	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
119 	VIRTCHNL_OP_GET_STATS = 15,
120 	VIRTCHNL_OP_RSVD = 16,
121 	VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
122 	/* opcode 19 is reserved */
123 	VIRTCHNL_OP_IWARP = 20, /* advanced opcode */
124 	VIRTCHNL_OP_RDMA = VIRTCHNL_OP_IWARP,
125 	VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
126 	VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP = VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP,
127 	VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
128 	VIRTCHNL_OP_RELEASE_RDMA_IRQ_MAP = VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP,
129 	VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
130 	VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
131 	VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
132 	VIRTCHNL_OP_SET_RSS_HENA = 26,
133 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
134 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
135 	VIRTCHNL_OP_REQUEST_QUEUES = 29,
136 	VIRTCHNL_OP_ENABLE_CHANNELS = 30,
137 	VIRTCHNL_OP_DISABLE_CHANNELS = 31,
138 	VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
139 	VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
140 	/* opcode 34 - 43 are reserved */
141 	VIRTCHNL_OP_GET_SUPPORTED_RXDIDS = 44,
142 	VIRTCHNL_OP_ADD_RSS_CFG = 45,
143 	VIRTCHNL_OP_DEL_RSS_CFG = 46,
144 	VIRTCHNL_OP_ADD_FDIR_FILTER = 47,
145 	VIRTCHNL_OP_DEL_FDIR_FILTER = 48,
146 	VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS = 51,
147 	VIRTCHNL_OP_ADD_VLAN_V2 = 52,
148 	VIRTCHNL_OP_DEL_VLAN_V2 = 53,
149 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 = 54,
150 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 = 55,
151 	VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 = 56,
152 	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
153 	VIRTCHNL_OP_MAX,
154 };
155 
156 /* These macros are used to generate compilation errors if a structure/union
157  * is not exactly the correct length. It gives a divide by zero error if the
158  * structure/union is not of the correct size, otherwise it creates an enum
159  * that is never used.
160  */
161 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
162 	{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
163 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
164 	{ virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
165 
166 /* Message descriptions and data structures. */
167 
168 /* VIRTCHNL_OP_VERSION
169  * VF posts its version number to the PF. PF responds with its version number
170  * in the same format, along with a return code.
171  * Reply from PF has its major/minor versions also in param0 and param1.
172  * If there is a major version mismatch, then the VF cannot operate.
173  * If there is a minor version mismatch, then the VF can operate but should
174  * add a warning to the system log.
175  *
176  * This enum element MUST always be specified as == 1, regardless of other
177  * changes in the API. The PF must always respond to this message without
178  * error regardless of version mismatch.
179  */
180 #define VIRTCHNL_VERSION_MAJOR		1
181 #define VIRTCHNL_VERSION_MINOR		1
182 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS	0
183 
184 struct virtchnl_version_info {
185 	u32 major;
186 	u32 minor;
187 };
188 
189 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
190 
191 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
192 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
193 
194 /* VIRTCHNL_OP_RESET_VF
195  * VF sends this request to PF with no parameters
196  * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
197  * until reset completion is indicated. The admin queue must be reinitialized
198  * after this operation.
199  *
200  * When reset is complete, PF must ensure that all queues in all VSIs associated
201  * with the VF are stopped, all queue configurations in the HMC are set to 0,
202  * and all MAC and VLAN filters (except the default MAC address) on all VSIs
203  * are cleared.
204  */
205 
206 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
207  * vsi_type should always be 6 for backward compatibility. Add other fields
208  * as needed.
209  */
210 enum virtchnl_vsi_type {
211 	VIRTCHNL_VSI_TYPE_INVALID = 0,
212 	VIRTCHNL_VSI_SRIOV = 6,
213 };
214 
215 /* VIRTCHNL_OP_GET_VF_RESOURCES
216  * Version 1.0 VF sends this request to PF with no parameters
217  * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
218  * PF responds with an indirect message containing
219  * virtchnl_vf_resource and one or more
220  * virtchnl_vsi_resource structures.
221  */
222 
223 struct virtchnl_vsi_resource {
224 	u16 vsi_id;
225 	u16 num_queue_pairs;
226 
227 	/* see enum virtchnl_vsi_type */
228 	s32 vsi_type;
229 	u16 qset_handle;
230 	u8 default_mac_addr[ETH_ALEN];
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			BIT(0)
240 #define VIRTCHNL_VF_OFFLOAD_RDMA		BIT(1)
241 #define VIRTCHNL_VF_CAP_RDMA			VIRTCHNL_VF_OFFLOAD_RDMA
242 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ		BIT(3)
243 #define VIRTCHNL_VF_OFFLOAD_RSS_REG		BIT(4)
244 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR		BIT(5)
245 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES		BIT(6)
246 /* used to negotiate communicating link speeds in Mbps */
247 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED		BIT(7)
248 #define VIRTCHNL_VF_OFFLOAD_VLAN_V2		BIT(15)
249 #define VIRTCHNL_VF_OFFLOAD_VLAN		BIT(16)
250 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING		BIT(17)
251 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2	BIT(18)
252 #define VIRTCHNL_VF_OFFLOAD_RSS_PF		BIT(19)
253 #define VIRTCHNL_VF_OFFLOAD_ENCAP		BIT(20)
254 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM		BIT(21)
255 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM	BIT(22)
256 #define VIRTCHNL_VF_OFFLOAD_ADQ			BIT(23)
257 #define VIRTCHNL_VF_OFFLOAD_USO			BIT(25)
258 #define VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC	BIT(26)
259 #define VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF		BIT(27)
260 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF		BIT(28)
261 
262 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
263 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
264 			       VIRTCHNL_VF_OFFLOAD_RSS_PF)
265 
266 struct virtchnl_vf_resource {
267 	u16 num_vsis;
268 	u16 num_queue_pairs;
269 	u16 max_vectors;
270 	u16 max_mtu;
271 
272 	u32 vf_cap_flags;
273 	u32 rss_key_size;
274 	u32 rss_lut_size;
275 
276 	struct virtchnl_vsi_resource vsi_res[];
277 };
278 
279 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_vf_resource);
280 #define virtchnl_vf_resource_LEGACY_SIZEOF	36
281 
282 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
283  * VF sends this message to set up parameters for one TX queue.
284  * External data buffer contains one instance of virtchnl_txq_info.
285  * PF configures requested queue and returns a status code.
286  */
287 
288 /* Tx queue config info */
289 struct virtchnl_txq_info {
290 	u16 vsi_id;
291 	u16 queue_id;
292 	u16 ring_len;		/* number of descriptors, multiple of 8 */
293 	u16 headwb_enabled; /* deprecated with AVF 1.0 */
294 	u64 dma_ring_addr;
295 	u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
296 };
297 
298 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
299 
300 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
301  * VF sends this message to set up parameters for one RX queue.
302  * External data buffer contains one instance of virtchnl_rxq_info.
303  * PF configures requested queue and returns a status code.
304  */
305 
306 /* Rx queue config info */
307 struct virtchnl_rxq_info {
308 	u16 vsi_id;
309 	u16 queue_id;
310 	u32 ring_len;		/* number of descriptors, multiple of 32 */
311 	u16 hdr_size;
312 	u16 splithdr_enabled; /* deprecated with AVF 1.0 */
313 	u32 databuffer_size;
314 	u32 max_pkt_size;
315 	u8 pad0;
316 	u8 rxdid;
317 	u8 pad1[2];
318 	u64 dma_ring_addr;
319 
320 	/* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
321 	s32 rx_split_pos;
322 	u32 pad2;
323 };
324 
325 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
326 
327 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
328  * VF sends this message to set parameters for all active TX and RX queues
329  * associated with the specified VSI.
330  * PF configures queues and returns status.
331  * If the number of queues specified is greater than the number of queues
332  * associated with the VSI, an error is returned and no queues are configured.
333  * NOTE: The VF is not required to configure all queues in a single request.
334  * It may send multiple messages. PF drivers must correctly handle all VF
335  * requests.
336  */
337 struct virtchnl_queue_pair_info {
338 	/* NOTE: vsi_id and queue_id should be identical for both queues. */
339 	struct virtchnl_txq_info txq;
340 	struct virtchnl_rxq_info rxq;
341 };
342 
343 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
344 
345 struct virtchnl_vsi_queue_config_info {
346 	u16 vsi_id;
347 	u16 num_queue_pairs;
348 	u32 pad;
349 	struct virtchnl_queue_pair_info qpair[];
350 };
351 
352 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vsi_queue_config_info);
353 #define virtchnl_vsi_queue_config_info_LEGACY_SIZEOF	72
354 
355 /* VIRTCHNL_OP_REQUEST_QUEUES
356  * VF sends this message to request the PF to allocate additional queues to
357  * this VF.  Each VF gets a guaranteed number of queues on init but asking for
358  * additional queues must be negotiated.  This is a best effort request as it
359  * is possible the PF does not have enough queues left to support the request.
360  * If the PF cannot support the number requested it will respond with the
361  * maximum number it is able to support.  If the request is successful, PF will
362  * then reset the VF to institute required changes.
363  */
364 
365 /* VF resource request */
366 struct virtchnl_vf_res_request {
367 	u16 num_queue_pairs;
368 };
369 
370 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
371  * VF uses this message to map vectors to queues.
372  * The rxq_map and txq_map fields are bitmaps used to indicate which queues
373  * are to be associated with the specified vector.
374  * The "other" causes are always mapped to vector 0. The VF may not request
375  * that vector 0 be used for traffic.
376  * PF configures interrupt mapping and returns status.
377  * NOTE: due to hardware requirements, all active queues (both TX and RX)
378  * should be mapped to interrupts, even if the driver intends to operate
379  * only in polling mode. In this case the interrupt may be disabled, but
380  * the ITR timer will still run to trigger writebacks.
381  */
382 struct virtchnl_vector_map {
383 	u16 vsi_id;
384 	u16 vector_id;
385 	u16 rxq_map;
386 	u16 txq_map;
387 	u16 rxitr_idx;
388 	u16 txitr_idx;
389 };
390 
391 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
392 
393 struct virtchnl_irq_map_info {
394 	u16 num_vectors;
395 	struct virtchnl_vector_map vecmap[];
396 };
397 
398 VIRTCHNL_CHECK_STRUCT_LEN(2, virtchnl_irq_map_info);
399 #define virtchnl_irq_map_info_LEGACY_SIZEOF	14
400 
401 /* VIRTCHNL_OP_ENABLE_QUEUES
402  * VIRTCHNL_OP_DISABLE_QUEUES
403  * VF sends these message to enable or disable TX/RX queue pairs.
404  * The queues fields are bitmaps indicating which queues to act upon.
405  * (Currently, we only support 16 queues per VF, but we make the field
406  * u32 to allow for expansion.)
407  * PF performs requested action and returns status.
408  * NOTE: The VF is not required to enable/disable all queues in a single
409  * request. It may send multiple messages.
410  * PF drivers must correctly handle all VF requests.
411  */
412 struct virtchnl_queue_select {
413 	u16 vsi_id;
414 	u16 pad;
415 	u32 rx_queues;
416 	u32 tx_queues;
417 };
418 
419 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
420 
421 /* VIRTCHNL_OP_ADD_ETH_ADDR
422  * VF sends this message in order to add one or more unicast or multicast
423  * address filters for the specified VSI.
424  * PF adds the filters and returns status.
425  */
426 
427 /* VIRTCHNL_OP_DEL_ETH_ADDR
428  * VF sends this message in order to remove one or more unicast or multicast
429  * filters for the specified VSI.
430  * PF removes the filters and returns status.
431  */
432 
433 /* VIRTCHNL_ETHER_ADDR_LEGACY
434  * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad
435  * bytes. Moving forward all VF drivers should not set type to
436  * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy
437  * behavior. The control plane function (i.e. PF) can use a best effort method
438  * of tracking the primary/device unicast in this case, but there is no
439  * guarantee and functionality depends on the implementation of the PF.
440  */
441 
442 /* VIRTCHNL_ETHER_ADDR_PRIMARY
443  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the
444  * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and
445  * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane
446  * function (i.e. PF) to accurately track and use this MAC address for
447  * displaying on the host and for VM/function reset.
448  */
449 
450 /* VIRTCHNL_ETHER_ADDR_EXTRA
451  * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra
452  * unicast and/or multicast filters that are being added/deleted via
453  * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively.
454  */
455 struct virtchnl_ether_addr {
456 	u8 addr[ETH_ALEN];
457 	u8 type;
458 #define VIRTCHNL_ETHER_ADDR_LEGACY	0
459 #define VIRTCHNL_ETHER_ADDR_PRIMARY	1
460 #define VIRTCHNL_ETHER_ADDR_EXTRA	2
461 #define VIRTCHNL_ETHER_ADDR_TYPE_MASK	3 /* first two bits of type are valid */
462 	u8 pad;
463 };
464 
465 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
466 
467 struct virtchnl_ether_addr_list {
468 	u16 vsi_id;
469 	u16 num_elements;
470 	struct virtchnl_ether_addr list[];
471 };
472 
473 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_ether_addr_list);
474 #define virtchnl_ether_addr_list_LEGACY_SIZEOF	12
475 
476 /* VIRTCHNL_OP_ADD_VLAN
477  * VF sends this message to add one or more VLAN tag filters for receives.
478  * PF adds the filters and returns status.
479  * If a port VLAN is configured by the PF, this operation will return an
480  * error to the VF.
481  */
482 
483 /* VIRTCHNL_OP_DEL_VLAN
484  * VF sends this message to remove one or more VLAN tag filters for receives.
485  * PF removes the filters and returns status.
486  * If a port VLAN is configured by the PF, this operation will return an
487  * error to the VF.
488  */
489 
490 struct virtchnl_vlan_filter_list {
491 	u16 vsi_id;
492 	u16 num_elements;
493 	u16 vlan_id[];
494 };
495 
496 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_vlan_filter_list);
497 #define virtchnl_vlan_filter_list_LEGACY_SIZEOF	6
498 
499 /* This enum is used for all of the VIRTCHNL_VF_OFFLOAD_VLAN_V2_CAPS related
500  * structures and opcodes.
501  *
502  * VIRTCHNL_VLAN_UNSUPPORTED - This field is not supported and if a VF driver
503  * populates it the PF should return VIRTCHNL_STATUS_ERR_NOT_SUPPORTED.
504  *
505  * VIRTCHNL_VLAN_ETHERTYPE_8100 - This field supports 0x8100 ethertype.
506  * VIRTCHNL_VLAN_ETHERTYPE_88A8 - This field supports 0x88A8 ethertype.
507  * VIRTCHNL_VLAN_ETHERTYPE_9100 - This field supports 0x9100 ethertype.
508  *
509  * VIRTCHNL_VLAN_ETHERTYPE_AND - Used when multiple ethertypes can be supported
510  * by the PF concurrently. For example, if the PF can support
511  * VIRTCHNL_VLAN_ETHERTYPE_8100 AND VIRTCHNL_VLAN_ETHERTYPE_88A8 filters it
512  * would OR the following bits:
513  *
514  *	VIRTHCNL_VLAN_ETHERTYPE_8100 |
515  *	VIRTCHNL_VLAN_ETHERTYPE_88A8 |
516  *	VIRTCHNL_VLAN_ETHERTYPE_AND;
517  *
518  * The VF would interpret this as VLAN filtering can be supported on both 0x8100
519  * and 0x88A8 VLAN ethertypes.
520  *
521  * VIRTCHNL_ETHERTYPE_XOR - Used when only a single ethertype can be supported
522  * by the PF concurrently. For example if the PF can support
523  * VIRTCHNL_VLAN_ETHERTYPE_8100 XOR VIRTCHNL_VLAN_ETHERTYPE_88A8 stripping
524  * offload it would OR the following bits:
525  *
526  *	VIRTCHNL_VLAN_ETHERTYPE_8100 |
527  *	VIRTCHNL_VLAN_ETHERTYPE_88A8 |
528  *	VIRTCHNL_VLAN_ETHERTYPE_XOR;
529  *
530  * The VF would interpret this as VLAN stripping can be supported on either
531  * 0x8100 or 0x88a8 VLAN ethertypes. So when requesting VLAN stripping via
532  * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 the specified ethertype will override
533  * the previously set value.
534  *
535  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 - Used to tell the VF to insert and/or
536  * strip the VLAN tag using the L2TAG1 field of the Tx/Rx descriptors.
537  *
538  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to insert hardware
539  * offloaded VLAN tags using the L2TAG2 field of the Tx descriptor.
540  *
541  * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to strip hardware
542  * offloaded VLAN tags using the L2TAG2_2 field of the Rx descriptor.
543  *
544  * VIRTCHNL_VLAN_PRIO - This field supports VLAN priority bits. This is used for
545  * VLAN filtering if the underlying PF supports it.
546  *
547  * VIRTCHNL_VLAN_TOGGLE_ALLOWED - This field is used to say whether a
548  * certain VLAN capability can be toggled. For example if the underlying PF/CP
549  * allows the VF to toggle VLAN filtering, stripping, and/or insertion it should
550  * set this bit along with the supported ethertypes.
551  */
552 enum virtchnl_vlan_support {
553 	VIRTCHNL_VLAN_UNSUPPORTED =		0,
554 	VIRTCHNL_VLAN_ETHERTYPE_8100 =		BIT(0),
555 	VIRTCHNL_VLAN_ETHERTYPE_88A8 =		BIT(1),
556 	VIRTCHNL_VLAN_ETHERTYPE_9100 =		BIT(2),
557 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 =	BIT(8),
558 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 =	BIT(9),
559 	VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 =	BIT(10),
560 	VIRTCHNL_VLAN_PRIO =			BIT(24),
561 	VIRTCHNL_VLAN_FILTER_MASK =		BIT(28),
562 	VIRTCHNL_VLAN_ETHERTYPE_AND =		BIT(29),
563 	VIRTCHNL_VLAN_ETHERTYPE_XOR =		BIT(30),
564 	VIRTCHNL_VLAN_TOGGLE =			BIT(31),
565 };
566 
567 /* This structure is used as part of the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
568  * for filtering, insertion, and stripping capabilities.
569  *
570  * If only outer capabilities are supported (for filtering, insertion, and/or
571  * stripping) then this refers to the outer most or single VLAN from the VF's
572  * perspective.
573  *
574  * If only inner capabilities are supported (for filtering, insertion, and/or
575  * stripping) then this refers to the outer most or single VLAN from the VF's
576  * perspective. Functionally this is the same as if only outer capabilities are
577  * supported. The VF driver is just forced to use the inner fields when
578  * adding/deleting filters and enabling/disabling offloads (if supported).
579  *
580  * If both outer and inner capabilities are supported (for filtering, insertion,
581  * and/or stripping) then outer refers to the outer most or single VLAN and
582  * inner refers to the second VLAN, if it exists, in the packet.
583  *
584  * There is no support for tunneled VLAN offloads, so outer or inner are never
585  * referring to a tunneled packet from the VF's perspective.
586  */
587 struct virtchnl_vlan_supported_caps {
588 	u32 outer;
589 	u32 inner;
590 };
591 
592 /* The PF populates these fields based on the supported VLAN filtering. If a
593  * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
594  * reject any VIRTCHNL_OP_ADD_VLAN_V2 or VIRTCHNL_OP_DEL_VLAN_V2 messages using
595  * the unsupported fields.
596  *
597  * Also, a VF is only allowed to toggle its VLAN filtering setting if the
598  * VIRTCHNL_VLAN_TOGGLE bit is set.
599  *
600  * The ethertype(s) specified in the ethertype_init field are the ethertypes
601  * enabled for VLAN filtering. VLAN filtering in this case refers to the outer
602  * most VLAN from the VF's perspective. If both inner and outer filtering are
603  * allowed then ethertype_init only refers to the outer most VLAN as only
604  * VLAN ethertype supported for inner VLAN filtering is
605  * VIRTCHNL_VLAN_ETHERTYPE_8100. By default, inner VLAN filtering is disabled
606  * when both inner and outer filtering are allowed.
607  *
608  * The max_filters field tells the VF how many VLAN filters it's allowed to have
609  * at any one time. If it exceeds this amount and tries to add another filter,
610  * then the request will be rejected by the PF. To prevent failures, the VF
611  * should keep track of how many VLAN filters it has added and not attempt to
612  * add more than max_filters.
613  */
614 struct virtchnl_vlan_filtering_caps {
615 	struct virtchnl_vlan_supported_caps filtering_support;
616 	u32 ethertype_init;
617 	u16 max_filters;
618 	u8 pad[2];
619 };
620 
621 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_filtering_caps);
622 
623 /* This enum is used for the virtchnl_vlan_offload_caps structure to specify
624  * if the PF supports a different ethertype for stripping and insertion.
625  *
626  * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION - The ethertype(s) specified
627  * for stripping affect the ethertype(s) specified for insertion and visa versa
628  * as well. If the VF tries to configure VLAN stripping via
629  * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 with VIRTCHNL_VLAN_ETHERTYPE_8100 then
630  * that will be the ethertype for both stripping and insertion.
631  *
632  * VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED - The ethertype(s) specified for
633  * stripping do not affect the ethertype(s) specified for insertion and visa
634  * versa.
635  */
636 enum virtchnl_vlan_ethertype_match {
637 	VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION = 0,
638 	VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED = 1,
639 };
640 
641 /* The PF populates these fields based on the supported VLAN offloads. If a
642  * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
643  * reject any VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 or
644  * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 messages using the unsupported fields.
645  *
646  * Also, a VF is only allowed to toggle its VLAN offload setting if the
647  * VIRTCHNL_VLAN_TOGGLE_ALLOWED bit is set.
648  *
649  * The VF driver needs to be aware of how the tags are stripped by hardware and
650  * inserted by the VF driver based on the level of offload support. The PF will
651  * populate these fields based on where the VLAN tags are expected to be
652  * offloaded via the VIRTHCNL_VLAN_TAG_LOCATION_* bits. The VF will need to
653  * interpret these fields. See the definition of the
654  * VIRTCHNL_VLAN_TAG_LOCATION_* bits above the virtchnl_vlan_support
655  * enumeration.
656  */
657 struct virtchnl_vlan_offload_caps {
658 	struct virtchnl_vlan_supported_caps stripping_support;
659 	struct virtchnl_vlan_supported_caps insertion_support;
660 	u32 ethertype_init;
661 	u8 ethertype_match;
662 	u8 pad[3];
663 };
664 
665 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_vlan_offload_caps);
666 
667 /* VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
668  * VF sends this message to determine its VLAN capabilities.
669  *
670  * PF will mark which capabilities it supports based on hardware support and
671  * current configuration. For example, if a port VLAN is configured the PF will
672  * not allow outer VLAN filtering, stripping, or insertion to be configured so
673  * it will block these features from the VF.
674  *
675  * The VF will need to cross reference its capabilities with the PFs
676  * capabilities in the response message from the PF to determine the VLAN
677  * support.
678  */
679 struct virtchnl_vlan_caps {
680 	struct virtchnl_vlan_filtering_caps filtering;
681 	struct virtchnl_vlan_offload_caps offloads;
682 };
683 
684 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_caps);
685 
686 struct virtchnl_vlan {
687 	u16 tci;	/* tci[15:13] = PCP and tci[11:0] = VID */
688 	u16 tci_mask;	/* only valid if VIRTCHNL_VLAN_FILTER_MASK set in
689 			 * filtering caps
690 			 */
691 	u16 tpid;	/* 0x8100, 0x88a8, etc. and only type(s) set in
692 			 * filtering caps. Note that tpid here does not refer to
693 			 * VIRTCHNL_VLAN_ETHERTYPE_*, but it refers to the
694 			 * actual 2-byte VLAN TPID
695 			 */
696 	u8 pad[2];
697 };
698 
699 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan);
700 
701 struct virtchnl_vlan_filter {
702 	struct virtchnl_vlan inner;
703 	struct virtchnl_vlan outer;
704 	u8 pad[16];
705 };
706 
707 VIRTCHNL_CHECK_STRUCT_LEN(32, virtchnl_vlan_filter);
708 
709 /* VIRTCHNL_OP_ADD_VLAN_V2
710  * VIRTCHNL_OP_DEL_VLAN_V2
711  *
712  * VF sends these messages to add/del one or more VLAN tag filters for Rx
713  * traffic.
714  *
715  * The PF attempts to add the filters and returns status.
716  *
717  * The VF should only ever attempt to add/del virtchnl_vlan_filter(s) using the
718  * supported fields negotiated via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS.
719  */
720 struct virtchnl_vlan_filter_list_v2 {
721 	u16 vport_id;
722 	u16 num_elements;
723 	u8 pad[4];
724 	struct virtchnl_vlan_filter filters[];
725 };
726 
727 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan_filter_list_v2);
728 #define virtchnl_vlan_filter_list_v2_LEGACY_SIZEOF	40
729 
730 /* VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
731  * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
732  * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
733  * VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
734  *
735  * VF sends this message to enable or disable VLAN stripping or insertion. It
736  * also needs to specify an ethertype. The VF knows which VLAN ethertypes are
737  * allowed and whether or not it's allowed to enable/disable the specific
738  * offload via the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
739  * parse the virtchnl_vlan_caps.offloads fields to determine which offload
740  * messages are allowed.
741  *
742  * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
743  * following manner the VF will be allowed to enable and/or disable 0x8100 inner
744  * VLAN insertion and/or stripping via the opcodes listed above. Inner in this
745  * case means the outer most or single VLAN from the VF's perspective. This is
746  * because no outer offloads are supported. See the comments above the
747  * virtchnl_vlan_supported_caps structure for more details.
748  *
749  * virtchnl_vlan_caps.offloads.stripping_support.inner =
750  *			VIRTCHNL_VLAN_TOGGLE |
751  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
752  *
753  * virtchnl_vlan_caps.offloads.insertion_support.inner =
754  *			VIRTCHNL_VLAN_TOGGLE |
755  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
756  *
757  * In order to enable inner (again note that in this case inner is the outer
758  * most or single VLAN from the VF's perspective) VLAN stripping for 0x8100
759  * VLANs, the VF would populate the virtchnl_vlan_setting structure in the
760  * following manner and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
761  *
762  * virtchnl_vlan_setting.inner_ethertype_setting =
763  *			VIRTCHNL_VLAN_ETHERTYPE_8100;
764  *
765  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
766  * initialization.
767  *
768  * The reason that VLAN TPID(s) are not being used for the
769  * outer_ethertype_setting and inner_ethertype_setting fields is because it's
770  * possible a device could support VLAN insertion and/or stripping offload on
771  * multiple ethertypes concurrently, so this method allows a VF to request
772  * multiple ethertypes in one message using the virtchnl_vlan_support
773  * enumeration.
774  *
775  * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
776  * following manner the VF will be allowed to enable 0x8100 and 0x88a8 outer
777  * VLAN insertion and stripping simultaneously. The
778  * virtchnl_vlan_caps.offloads.ethertype_match field will also have to be
779  * populated based on what the PF can support.
780  *
781  * virtchnl_vlan_caps.offloads.stripping_support.outer =
782  *			VIRTCHNL_VLAN_TOGGLE |
783  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
784  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
785  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
786  *
787  * virtchnl_vlan_caps.offloads.insertion_support.outer =
788  *			VIRTCHNL_VLAN_TOGGLE |
789  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
790  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
791  *			VIRTCHNL_VLAN_ETHERTYPE_AND;
792  *
793  * In order to enable outer VLAN stripping for 0x8100 and 0x88a8 VLANs, the VF
794  * would populate the virthcnl_vlan_offload_structure in the following manner
795  * and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
796  *
797  * virtchnl_vlan_setting.outer_ethertype_setting =
798  *			VIRTHCNL_VLAN_ETHERTYPE_8100 |
799  *			VIRTHCNL_VLAN_ETHERTYPE_88A8;
800  *
801  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
802  * initialization.
803  *
804  * There is also the case where a PF and the underlying hardware can support
805  * VLAN offloads on multiple ethertypes, but not concurrently. For example, if
806  * the PF populates the virtchnl_vlan_caps.offloads in the following manner the
807  * VF will be allowed to enable and/or disable 0x8100 XOR 0x88a8 outer VLAN
808  * offloads. The ethertypes must match for stripping and insertion.
809  *
810  * virtchnl_vlan_caps.offloads.stripping_support.outer =
811  *			VIRTCHNL_VLAN_TOGGLE |
812  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
813  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
814  *			VIRTCHNL_VLAN_ETHERTYPE_XOR;
815  *
816  * virtchnl_vlan_caps.offloads.insertion_support.outer =
817  *			VIRTCHNL_VLAN_TOGGLE |
818  *			VIRTCHNL_VLAN_ETHERTYPE_8100 |
819  *			VIRTCHNL_VLAN_ETHERTYPE_88A8 |
820  *			VIRTCHNL_VLAN_ETHERTYPE_XOR;
821  *
822  * virtchnl_vlan_caps.offloads.ethertype_match =
823  *			VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
824  *
825  * In order to enable outer VLAN stripping for 0x88a8 VLANs, the VF would
826  * populate the virtchnl_vlan_setting structure in the following manner and send
827  * the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2. Also, this will change the
828  * ethertype for VLAN insertion if it's enabled. So, for completeness, a
829  * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 with the same ethertype should be sent.
830  *
831  * virtchnl_vlan_setting.outer_ethertype_setting = VIRTHCNL_VLAN_ETHERTYPE_88A8;
832  *
833  * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
834  * initialization.
835  */
836 struct virtchnl_vlan_setting {
837 	u32 outer_ethertype_setting;
838 	u32 inner_ethertype_setting;
839 	u16 vport_id;
840 	u8 pad[6];
841 };
842 
843 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_setting);
844 
845 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
846  * VF sends VSI id and flags.
847  * PF returns status code in retval.
848  * Note: we assume that broadcast accept mode is always enabled.
849  */
850 struct virtchnl_promisc_info {
851 	u16 vsi_id;
852 	u16 flags;
853 };
854 
855 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
856 
857 #define FLAG_VF_UNICAST_PROMISC	0x00000001
858 #define FLAG_VF_MULTICAST_PROMISC	0x00000002
859 
860 /* VIRTCHNL_OP_GET_STATS
861  * VF sends this message to request stats for the selected VSI. VF uses
862  * the virtchnl_queue_select struct to specify the VSI. The queue_id
863  * field is ignored by the PF.
864  *
865  * PF replies with struct eth_stats in an external buffer.
866  */
867 
868 /* VIRTCHNL_OP_CONFIG_RSS_KEY
869  * VIRTCHNL_OP_CONFIG_RSS_LUT
870  * VF sends these messages to configure RSS. Only supported if both PF
871  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
872  * configuration negotiation. If this is the case, then the RSS fields in
873  * the VF resource struct are valid.
874  * Both the key and LUT are initialized to 0 by the PF, meaning that
875  * RSS is effectively disabled until set up by the VF.
876  */
877 struct virtchnl_rss_key {
878 	u16 vsi_id;
879 	u16 key_len;
880 	u8 key[];          /* RSS hash key, packed bytes */
881 };
882 
883 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_rss_key);
884 #define virtchnl_rss_key_LEGACY_SIZEOF	6
885 
886 struct virtchnl_rss_lut {
887 	u16 vsi_id;
888 	u16 lut_entries;
889 	u8 lut[];         /* RSS lookup table */
890 };
891 
892 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_rss_lut);
893 #define virtchnl_rss_lut_LEGACY_SIZEOF	6
894 
895 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
896  * VIRTCHNL_OP_SET_RSS_HENA
897  * VF sends these messages to get and set the hash filter enable bits for RSS.
898  * By default, the PF sets these to all possible traffic types that the
899  * hardware supports. The VF can query this value if it wants to change the
900  * traffic types that are hashed by the hardware.
901  */
902 struct virtchnl_rss_hena {
903 	u64 hena;
904 };
905 
906 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
907 
908 /* VIRTCHNL_OP_ENABLE_CHANNELS
909  * VIRTCHNL_OP_DISABLE_CHANNELS
910  * VF sends these messages to enable or disable channels based on
911  * the user specified queue count and queue offset for each traffic class.
912  * This struct encompasses all the information that the PF needs from
913  * VF to create a channel.
914  */
915 struct virtchnl_channel_info {
916 	u16 count; /* number of queues in a channel */
917 	u16 offset; /* queues in a channel start from 'offset' */
918 	u32 pad;
919 	u64 max_tx_rate;
920 };
921 
922 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
923 
924 struct virtchnl_tc_info {
925 	u32	num_tc;
926 	u32	pad;
927 	struct virtchnl_channel_info list[];
928 };
929 
930 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_tc_info);
931 #define virtchnl_tc_info_LEGACY_SIZEOF	24
932 
933 /* VIRTCHNL_ADD_CLOUD_FILTER
934  * VIRTCHNL_DEL_CLOUD_FILTER
935  * VF sends these messages to add or delete a cloud filter based on the
936  * user specified match and action filters. These structures encompass
937  * all the information that the PF needs from the VF to add/delete a
938  * cloud filter.
939  */
940 
941 struct virtchnl_l4_spec {
942 	u8	src_mac[ETH_ALEN];
943 	u8	dst_mac[ETH_ALEN];
944 	__be16	vlan_id;
945 	__be16	pad; /* reserved for future use */
946 	__be32	src_ip[4];
947 	__be32	dst_ip[4];
948 	__be16	src_port;
949 	__be16	dst_port;
950 };
951 
952 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
953 
954 union virtchnl_flow_spec {
955 	struct	virtchnl_l4_spec tcp_spec;
956 	u8	buffer[128]; /* reserved for future use */
957 };
958 
959 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
960 
961 enum virtchnl_action {
962 	/* action types */
963 	VIRTCHNL_ACTION_DROP = 0,
964 	VIRTCHNL_ACTION_TC_REDIRECT,
965 	VIRTCHNL_ACTION_PASSTHRU,
966 	VIRTCHNL_ACTION_QUEUE,
967 	VIRTCHNL_ACTION_Q_REGION,
968 	VIRTCHNL_ACTION_MARK,
969 	VIRTCHNL_ACTION_COUNT,
970 };
971 
972 enum virtchnl_flow_type {
973 	/* flow types */
974 	VIRTCHNL_TCP_V4_FLOW = 0,
975 	VIRTCHNL_TCP_V6_FLOW,
976 };
977 
978 struct virtchnl_filter {
979 	union	virtchnl_flow_spec data;
980 	union	virtchnl_flow_spec mask;
981 
982 	/* see enum virtchnl_flow_type */
983 	s32	flow_type;
984 
985 	/* see enum virtchnl_action */
986 	s32	action;
987 	u32	action_meta;
988 	u8	field_flags;
989 	u8	pad[3];
990 };
991 
992 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
993 
994 struct virtchnl_supported_rxdids {
995 	u64 supported_rxdids;
996 };
997 
998 /* VIRTCHNL_OP_EVENT
999  * PF sends this message to inform the VF driver of events that may affect it.
1000  * No direct response is expected from the VF, though it may generate other
1001  * messages in response to this one.
1002  */
1003 enum virtchnl_event_codes {
1004 	VIRTCHNL_EVENT_UNKNOWN = 0,
1005 	VIRTCHNL_EVENT_LINK_CHANGE,
1006 	VIRTCHNL_EVENT_RESET_IMPENDING,
1007 	VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
1008 };
1009 
1010 #define PF_EVENT_SEVERITY_INFO		0
1011 #define PF_EVENT_SEVERITY_CERTAIN_DOOM	255
1012 
1013 struct virtchnl_pf_event {
1014 	/* see enum virtchnl_event_codes */
1015 	s32 event;
1016 	union {
1017 		/* If the PF driver does not support the new speed reporting
1018 		 * capabilities then use link_event else use link_event_adv to
1019 		 * get the speed and link information. The ability to understand
1020 		 * new speeds is indicated by setting the capability flag
1021 		 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
1022 		 * in virtchnl_vf_resource struct and can be used to determine
1023 		 * which link event struct to use below.
1024 		 */
1025 		struct {
1026 			enum virtchnl_link_speed link_speed;
1027 			bool link_status;
1028 			u8 pad[3];
1029 		} link_event;
1030 		struct {
1031 			/* link_speed provided in Mbps */
1032 			u32 link_speed;
1033 			u8 link_status;
1034 			u8 pad[3];
1035 		} link_event_adv;
1036 	} event_data;
1037 
1038 	s32 severity;
1039 };
1040 
1041 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
1042 
1043 /* used to specify if a ceq_idx or aeq_idx is invalid */
1044 #define VIRTCHNL_RDMA_INVALID_QUEUE_IDX	0xFFFF
1045 /* VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP
1046  * VF uses this message to request PF to map RDMA vectors to RDMA queues.
1047  * The request for this originates from the VF RDMA driver through
1048  * a client interface between VF LAN and VF RDMA driver.
1049  * A vector could have an AEQ and CEQ attached to it although
1050  * there is a single AEQ per VF RDMA instance in which case
1051  * most vectors will have an VIRTCHNL_RDMA_INVALID_QUEUE_IDX for aeq and valid
1052  * idx for ceqs There will never be a case where there will be multiple CEQs
1053  * attached to a single vector.
1054  * PF configures interrupt mapping and returns status.
1055  */
1056 
1057 struct virtchnl_rdma_qv_info {
1058 	u32 v_idx; /* msix_vector */
1059 	u16 ceq_idx; /* set to VIRTCHNL_RDMA_INVALID_QUEUE_IDX if invalid */
1060 	u16 aeq_idx; /* set to VIRTCHNL_RDMA_INVALID_QUEUE_IDX if invalid */
1061 	u8 itr_idx;
1062 	u8 pad[3];
1063 };
1064 
1065 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_rdma_qv_info);
1066 
1067 struct virtchnl_rdma_qvlist_info {
1068 	u32 num_vectors;
1069 	struct virtchnl_rdma_qv_info qv_info[];
1070 };
1071 
1072 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_rdma_qvlist_info);
1073 #define virtchnl_rdma_qvlist_info_LEGACY_SIZEOF	16
1074 
1075 /* VF reset states - these are written into the RSTAT register:
1076  * VFGEN_RSTAT on the VF
1077  * When the PF initiates a reset, it writes 0
1078  * When the reset is complete, it writes 1
1079  * When the PF detects that the VF has recovered, it writes 2
1080  * VF checks this register periodically to determine if a reset has occurred,
1081  * then polls it to know when the reset is complete.
1082  * If either the PF or VF reads the register while the hardware
1083  * is in a reset state, it will return DEADBEEF, which, when masked
1084  * will result in 3.
1085  */
1086 enum virtchnl_vfr_states {
1087 	VIRTCHNL_VFR_INPROGRESS = 0,
1088 	VIRTCHNL_VFR_COMPLETED,
1089 	VIRTCHNL_VFR_VFACTIVE,
1090 };
1091 
1092 /* Type of RSS algorithm */
1093 enum virtchnl_rss_algorithm {
1094 	VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC	= 0,
1095 	VIRTCHNL_RSS_ALG_R_ASYMMETRIC		= 1,
1096 	VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC	= 2,
1097 	VIRTCHNL_RSS_ALG_XOR_SYMMETRIC		= 3,
1098 };
1099 
1100 #define VIRTCHNL_MAX_NUM_PROTO_HDRS	32
1101 #define PROTO_HDR_SHIFT			5
1102 #define PROTO_HDR_FIELD_START(proto_hdr_type) ((proto_hdr_type) << PROTO_HDR_SHIFT)
1103 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1)
1104 
1105 /* VF use these macros to configure each protocol header.
1106  * Specify which protocol headers and protocol header fields base on
1107  * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field.
1108  * @param hdr: a struct of virtchnl_proto_hdr
1109  * @param hdr_type: ETH/IPV4/TCP, etc
1110  * @param field: SRC/DST/TEID/SPI, etc
1111  */
1112 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field) \
1113 	((hdr)->field_selector |= BIT((field) & PROTO_HDR_FIELD_MASK))
1114 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field) \
1115 	((hdr)->field_selector &= ~BIT((field) & PROTO_HDR_FIELD_MASK))
1116 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val) \
1117 	((hdr)->field_selector & BIT((val) & PROTO_HDR_FIELD_MASK))
1118 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr)	((hdr)->field_selector)
1119 
1120 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
1121 	(VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, \
1122 		VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
1123 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
1124 	(VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, \
1125 		VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
1126 
1127 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type) \
1128 	((hdr)->type = VIRTCHNL_PROTO_HDR_ ## hdr_type)
1129 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \
1130 	(((hdr)->type) >> PROTO_HDR_SHIFT)
1131 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \
1132 	((hdr)->type == ((s32)((val) >> PROTO_HDR_SHIFT)))
1133 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \
1134 	(VIRTCHNL_TEST_PROTO_HDR_TYPE((hdr), (val)) && \
1135 	 VIRTCHNL_TEST_PROTO_HDR_FIELD((hdr), (val)))
1136 
1137 /* Protocol header type within a packet segment. A segment consists of one or
1138  * more protocol headers that make up a logical group of protocol headers. Each
1139  * logical group of protocol headers encapsulates or is encapsulated using/by
1140  * tunneling or encapsulation protocols for network virtualization.
1141  */
1142 enum virtchnl_proto_hdr_type {
1143 	VIRTCHNL_PROTO_HDR_NONE,
1144 	VIRTCHNL_PROTO_HDR_ETH,
1145 	VIRTCHNL_PROTO_HDR_S_VLAN,
1146 	VIRTCHNL_PROTO_HDR_C_VLAN,
1147 	VIRTCHNL_PROTO_HDR_IPV4,
1148 	VIRTCHNL_PROTO_HDR_IPV6,
1149 	VIRTCHNL_PROTO_HDR_TCP,
1150 	VIRTCHNL_PROTO_HDR_UDP,
1151 	VIRTCHNL_PROTO_HDR_SCTP,
1152 	VIRTCHNL_PROTO_HDR_GTPU_IP,
1153 	VIRTCHNL_PROTO_HDR_GTPU_EH,
1154 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
1155 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
1156 	VIRTCHNL_PROTO_HDR_PPPOE,
1157 	VIRTCHNL_PROTO_HDR_L2TPV3,
1158 	VIRTCHNL_PROTO_HDR_ESP,
1159 	VIRTCHNL_PROTO_HDR_AH,
1160 	VIRTCHNL_PROTO_HDR_PFCP,
1161 };
1162 
1163 /* Protocol header field within a protocol header. */
1164 enum virtchnl_proto_hdr_field {
1165 	/* ETHER */
1166 	VIRTCHNL_PROTO_HDR_ETH_SRC =
1167 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ETH),
1168 	VIRTCHNL_PROTO_HDR_ETH_DST,
1169 	VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
1170 	/* S-VLAN */
1171 	VIRTCHNL_PROTO_HDR_S_VLAN_ID =
1172 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_S_VLAN),
1173 	/* C-VLAN */
1174 	VIRTCHNL_PROTO_HDR_C_VLAN_ID =
1175 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_C_VLAN),
1176 	/* IPV4 */
1177 	VIRTCHNL_PROTO_HDR_IPV4_SRC =
1178 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4),
1179 	VIRTCHNL_PROTO_HDR_IPV4_DST,
1180 	VIRTCHNL_PROTO_HDR_IPV4_DSCP,
1181 	VIRTCHNL_PROTO_HDR_IPV4_TTL,
1182 	VIRTCHNL_PROTO_HDR_IPV4_PROT,
1183 	/* IPV6 */
1184 	VIRTCHNL_PROTO_HDR_IPV6_SRC =
1185 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6),
1186 	VIRTCHNL_PROTO_HDR_IPV6_DST,
1187 	VIRTCHNL_PROTO_HDR_IPV6_TC,
1188 	VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
1189 	VIRTCHNL_PROTO_HDR_IPV6_PROT,
1190 	/* TCP */
1191 	VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
1192 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_TCP),
1193 	VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
1194 	/* UDP */
1195 	VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
1196 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_UDP),
1197 	VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
1198 	/* SCTP */
1199 	VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
1200 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_SCTP),
1201 	VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
1202 	/* GTPU_IP */
1203 	VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
1204 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_IP),
1205 	/* GTPU_EH */
1206 	VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
1207 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH),
1208 	VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
1209 	/* PPPOE */
1210 	VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
1211 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PPPOE),
1212 	/* L2TPV3 */
1213 	VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
1214 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV3),
1215 	/* ESP */
1216 	VIRTCHNL_PROTO_HDR_ESP_SPI =
1217 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ESP),
1218 	/* AH */
1219 	VIRTCHNL_PROTO_HDR_AH_SPI =
1220 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_AH),
1221 	/* PFCP */
1222 	VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
1223 		PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PFCP),
1224 	VIRTCHNL_PROTO_HDR_PFCP_SEID,
1225 };
1226 
1227 struct virtchnl_proto_hdr {
1228 	/* see enum virtchnl_proto_hdr_type */
1229 	s32 type;
1230 	u32 field_selector; /* a bit mask to select field for header type */
1231 	u8 buffer[64];
1232 	/**
1233 	 * binary buffer in network order for specific header type.
1234 	 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
1235 	 * header is expected to be copied into the buffer.
1236 	 */
1237 };
1238 
1239 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr);
1240 
1241 struct virtchnl_proto_hdrs {
1242 	u8 tunnel_level;
1243 	u8 pad[3];
1244 	/**
1245 	 * specify where protocol header start from.
1246 	 * 0 - from the outer layer
1247 	 * 1 - from the first inner layer
1248 	 * 2 - from the second inner layer
1249 	 * ....
1250 	 **/
1251 	int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */
1252 	struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
1253 };
1254 
1255 VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs);
1256 
1257 struct virtchnl_rss_cfg {
1258 	struct virtchnl_proto_hdrs proto_hdrs;	   /* protocol headers */
1259 
1260 	/* see enum virtchnl_rss_algorithm; rss algorithm type */
1261 	s32 rss_algorithm;
1262 	u8 reserved[128];                          /* reserve for future */
1263 };
1264 
1265 VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg);
1266 
1267 /* action configuration for FDIR */
1268 struct virtchnl_filter_action {
1269 	/* see enum virtchnl_action type */
1270 	s32 type;
1271 	union {
1272 		/* used for queue and qgroup action */
1273 		struct {
1274 			u16 index;
1275 			u8 region;
1276 		} queue;
1277 		/* used for count action */
1278 		struct {
1279 			/* share counter ID with other flow rules */
1280 			u8 shared;
1281 			u32 id; /* counter ID */
1282 		} count;
1283 		/* used for mark action */
1284 		u32 mark_id;
1285 		u8 reserve[32];
1286 	} act_conf;
1287 };
1288 
1289 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action);
1290 
1291 #define VIRTCHNL_MAX_NUM_ACTIONS  8
1292 
1293 struct virtchnl_filter_action_set {
1294 	/* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
1295 	int count;
1296 	struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
1297 };
1298 
1299 VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set);
1300 
1301 /* pattern and action for FDIR rule */
1302 struct virtchnl_fdir_rule {
1303 	struct virtchnl_proto_hdrs proto_hdrs;
1304 	struct virtchnl_filter_action_set action_set;
1305 };
1306 
1307 VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule);
1308 
1309 /* Status returned to VF after VF requests FDIR commands
1310  * VIRTCHNL_FDIR_SUCCESS
1311  * VF FDIR related request is successfully done by PF
1312  * The request can be OP_ADD/DEL/QUERY_FDIR_FILTER.
1313  *
1314  * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
1315  * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
1316  *
1317  * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
1318  * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
1319  *
1320  * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
1321  * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
1322  *
1323  * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
1324  * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
1325  *
1326  * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
1327  * OP_ADD_FDIR_FILTER request is failed due to parameters validation
1328  * or HW doesn't support.
1329  *
1330  * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
1331  * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
1332  * for programming.
1333  *
1334  * VIRTCHNL_FDIR_FAILURE_QUERY_INVALID
1335  * OP_QUERY_FDIR_FILTER request is failed due to parameters validation,
1336  * for example, VF query counter of a rule who has no counter action.
1337  */
1338 enum virtchnl_fdir_prgm_status {
1339 	VIRTCHNL_FDIR_SUCCESS = 0,
1340 	VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
1341 	VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
1342 	VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
1343 	VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
1344 	VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
1345 	VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
1346 	VIRTCHNL_FDIR_FAILURE_QUERY_INVALID,
1347 };
1348 
1349 /* VIRTCHNL_OP_ADD_FDIR_FILTER
1350  * VF sends this request to PF by filling out vsi_id,
1351  * validate_only and rule_cfg. PF will return flow_id
1352  * if the request is successfully done and return add_status to VF.
1353  */
1354 struct virtchnl_fdir_add {
1355 	u16 vsi_id;  /* INPUT */
1356 	/*
1357 	 * 1 for validating a fdir rule, 0 for creating a fdir rule.
1358 	 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
1359 	 */
1360 	u16 validate_only; /* INPUT */
1361 	u32 flow_id;       /* OUTPUT */
1362 	struct virtchnl_fdir_rule rule_cfg; /* INPUT */
1363 
1364 	/* see enum virtchnl_fdir_prgm_status; OUTPUT */
1365 	s32 status;
1366 };
1367 
1368 VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add);
1369 
1370 /* VIRTCHNL_OP_DEL_FDIR_FILTER
1371  * VF sends this request to PF by filling out vsi_id
1372  * and flow_id. PF will return del_status to VF.
1373  */
1374 struct virtchnl_fdir_del {
1375 	u16 vsi_id;  /* INPUT */
1376 	u16 pad;
1377 	u32 flow_id; /* INPUT */
1378 
1379 	/* see enum virtchnl_fdir_prgm_status; OUTPUT */
1380 	s32 status;
1381 };
1382 
1383 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del);
1384 
1385 #define __vss_byone(p, member, count, old)				      \
1386 	(struct_size(p, member, count) + (old - 1 - struct_size(p, member, 0)))
1387 
1388 #define __vss_byelem(p, member, count, old)				      \
1389 	(struct_size(p, member, count - 1) + (old - struct_size(p, member, 0)))
1390 
1391 #define __vss_full(p, member, count, old)				      \
1392 	(struct_size(p, member, count) + (old - struct_size(p, member, 0)))
1393 
1394 #define __vss(type, func, p, member, count)		\
1395 	struct type: func(p, member, count, type##_LEGACY_SIZEOF)
1396 
1397 #define virtchnl_struct_size(p, m, c)					      \
1398 	_Generic(*p,							      \
1399 		 __vss(virtchnl_vf_resource, __vss_full, p, m, c),	      \
1400 		 __vss(virtchnl_vsi_queue_config_info, __vss_full, p, m, c),  \
1401 		 __vss(virtchnl_irq_map_info, __vss_full, p, m, c),	      \
1402 		 __vss(virtchnl_ether_addr_list, __vss_full, p, m, c),	      \
1403 		 __vss(virtchnl_vlan_filter_list, __vss_full, p, m, c),	      \
1404 		 __vss(virtchnl_vlan_filter_list_v2, __vss_byelem, p, m, c),  \
1405 		 __vss(virtchnl_tc_info, __vss_byelem, p, m, c),	      \
1406 		 __vss(virtchnl_rdma_qvlist_info, __vss_byelem, p, m, c),     \
1407 		 __vss(virtchnl_rss_key, __vss_byone, p, m, c),		      \
1408 		 __vss(virtchnl_rss_lut, __vss_byone, p, m, c))
1409 
1410 /**
1411  * virtchnl_vc_validate_vf_msg
1412  * @ver: Virtchnl version info
1413  * @v_opcode: Opcode for the message
1414  * @msg: pointer to the msg buffer
1415  * @msglen: msg length
1416  *
1417  * validate msg format against struct for each opcode
1418  */
1419 static inline int
virtchnl_vc_validate_vf_msg(struct virtchnl_version_info * ver,u32 v_opcode,u8 * msg,u16 msglen)1420 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
1421 			    u8 *msg, u16 msglen)
1422 {
1423 	bool err_msg_format = false;
1424 	u32 valid_len = 0;
1425 
1426 	/* Validate message length. */
1427 	switch (v_opcode) {
1428 	case VIRTCHNL_OP_VERSION:
1429 		valid_len = sizeof(struct virtchnl_version_info);
1430 		break;
1431 	case VIRTCHNL_OP_RESET_VF:
1432 		break;
1433 	case VIRTCHNL_OP_GET_VF_RESOURCES:
1434 		if (VF_IS_V11(ver))
1435 			valid_len = sizeof(u32);
1436 		break;
1437 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
1438 		valid_len = sizeof(struct virtchnl_txq_info);
1439 		break;
1440 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
1441 		valid_len = sizeof(struct virtchnl_rxq_info);
1442 		break;
1443 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1444 		valid_len = virtchnl_vsi_queue_config_info_LEGACY_SIZEOF;
1445 		if (msglen >= valid_len) {
1446 			struct virtchnl_vsi_queue_config_info *vqc =
1447 			    (struct virtchnl_vsi_queue_config_info *)msg;
1448 			valid_len = virtchnl_struct_size(vqc, qpair,
1449 							 vqc->num_queue_pairs);
1450 			if (vqc->num_queue_pairs == 0)
1451 				err_msg_format = true;
1452 		}
1453 		break;
1454 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1455 		valid_len = virtchnl_irq_map_info_LEGACY_SIZEOF;
1456 		if (msglen >= valid_len) {
1457 			struct virtchnl_irq_map_info *vimi =
1458 			    (struct virtchnl_irq_map_info *)msg;
1459 			valid_len = virtchnl_struct_size(vimi, vecmap,
1460 							 vimi->num_vectors);
1461 			if (vimi->num_vectors == 0)
1462 				err_msg_format = true;
1463 		}
1464 		break;
1465 	case VIRTCHNL_OP_ENABLE_QUEUES:
1466 	case VIRTCHNL_OP_DISABLE_QUEUES:
1467 		valid_len = sizeof(struct virtchnl_queue_select);
1468 		break;
1469 	case VIRTCHNL_OP_ADD_ETH_ADDR:
1470 	case VIRTCHNL_OP_DEL_ETH_ADDR:
1471 		valid_len = virtchnl_ether_addr_list_LEGACY_SIZEOF;
1472 		if (msglen >= valid_len) {
1473 			struct virtchnl_ether_addr_list *veal =
1474 			    (struct virtchnl_ether_addr_list *)msg;
1475 			valid_len = virtchnl_struct_size(veal, list,
1476 							 veal->num_elements);
1477 			if (veal->num_elements == 0)
1478 				err_msg_format = true;
1479 		}
1480 		break;
1481 	case VIRTCHNL_OP_ADD_VLAN:
1482 	case VIRTCHNL_OP_DEL_VLAN:
1483 		valid_len = virtchnl_vlan_filter_list_LEGACY_SIZEOF;
1484 		if (msglen >= valid_len) {
1485 			struct virtchnl_vlan_filter_list *vfl =
1486 			    (struct virtchnl_vlan_filter_list *)msg;
1487 			valid_len = virtchnl_struct_size(vfl, vlan_id,
1488 							 vfl->num_elements);
1489 			if (vfl->num_elements == 0)
1490 				err_msg_format = true;
1491 		}
1492 		break;
1493 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1494 		valid_len = sizeof(struct virtchnl_promisc_info);
1495 		break;
1496 	case VIRTCHNL_OP_GET_STATS:
1497 		valid_len = sizeof(struct virtchnl_queue_select);
1498 		break;
1499 	case VIRTCHNL_OP_RDMA:
1500 		/* These messages are opaque to us and will be validated in
1501 		 * the RDMA client code. We just need to check for nonzero
1502 		 * length. The firmware will enforce max length restrictions.
1503 		 */
1504 		if (msglen)
1505 			valid_len = msglen;
1506 		else
1507 			err_msg_format = true;
1508 		break;
1509 	case VIRTCHNL_OP_RELEASE_RDMA_IRQ_MAP:
1510 		break;
1511 	case VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP:
1512 		valid_len = virtchnl_rdma_qvlist_info_LEGACY_SIZEOF;
1513 		if (msglen >= valid_len) {
1514 			struct virtchnl_rdma_qvlist_info *qv =
1515 				(struct virtchnl_rdma_qvlist_info *)msg;
1516 
1517 			valid_len = virtchnl_struct_size(qv, qv_info,
1518 							 qv->num_vectors);
1519 		}
1520 		break;
1521 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
1522 		valid_len = virtchnl_rss_key_LEGACY_SIZEOF;
1523 		if (msglen >= valid_len) {
1524 			struct virtchnl_rss_key *vrk =
1525 				(struct virtchnl_rss_key *)msg;
1526 			valid_len = virtchnl_struct_size(vrk, key,
1527 							 vrk->key_len);
1528 		}
1529 		break;
1530 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
1531 		valid_len = virtchnl_rss_lut_LEGACY_SIZEOF;
1532 		if (msglen >= valid_len) {
1533 			struct virtchnl_rss_lut *vrl =
1534 				(struct virtchnl_rss_lut *)msg;
1535 			valid_len = virtchnl_struct_size(vrl, lut,
1536 							 vrl->lut_entries);
1537 		}
1538 		break;
1539 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
1540 		break;
1541 	case VIRTCHNL_OP_SET_RSS_HENA:
1542 		valid_len = sizeof(struct virtchnl_rss_hena);
1543 		break;
1544 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1545 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1546 		break;
1547 	case VIRTCHNL_OP_REQUEST_QUEUES:
1548 		valid_len = sizeof(struct virtchnl_vf_res_request);
1549 		break;
1550 	case VIRTCHNL_OP_ENABLE_CHANNELS:
1551 		valid_len = virtchnl_tc_info_LEGACY_SIZEOF;
1552 		if (msglen >= valid_len) {
1553 			struct virtchnl_tc_info *vti =
1554 				(struct virtchnl_tc_info *)msg;
1555 			valid_len = virtchnl_struct_size(vti, list,
1556 							 vti->num_tc);
1557 			if (vti->num_tc == 0)
1558 				err_msg_format = true;
1559 		}
1560 		break;
1561 	case VIRTCHNL_OP_DISABLE_CHANNELS:
1562 		break;
1563 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
1564 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
1565 		valid_len = sizeof(struct virtchnl_filter);
1566 		break;
1567 	case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
1568 		break;
1569 	case VIRTCHNL_OP_ADD_RSS_CFG:
1570 	case VIRTCHNL_OP_DEL_RSS_CFG:
1571 		valid_len = sizeof(struct virtchnl_rss_cfg);
1572 		break;
1573 	case VIRTCHNL_OP_ADD_FDIR_FILTER:
1574 		valid_len = sizeof(struct virtchnl_fdir_add);
1575 		break;
1576 	case VIRTCHNL_OP_DEL_FDIR_FILTER:
1577 		valid_len = sizeof(struct virtchnl_fdir_del);
1578 		break;
1579 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
1580 		break;
1581 	case VIRTCHNL_OP_ADD_VLAN_V2:
1582 	case VIRTCHNL_OP_DEL_VLAN_V2:
1583 		valid_len = virtchnl_vlan_filter_list_v2_LEGACY_SIZEOF;
1584 		if (msglen >= valid_len) {
1585 			struct virtchnl_vlan_filter_list_v2 *vfl =
1586 			    (struct virtchnl_vlan_filter_list_v2 *)msg;
1587 
1588 			valid_len = virtchnl_struct_size(vfl, filters,
1589 							 vfl->num_elements);
1590 
1591 			if (vfl->num_elements == 0) {
1592 				err_msg_format = true;
1593 				break;
1594 			}
1595 		}
1596 		break;
1597 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1598 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1599 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1600 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1601 		valid_len = sizeof(struct virtchnl_vlan_setting);
1602 		break;
1603 	/* These are always errors coming from the VF. */
1604 	case VIRTCHNL_OP_EVENT:
1605 	case VIRTCHNL_OP_UNKNOWN:
1606 	default:
1607 		return VIRTCHNL_STATUS_ERR_PARAM;
1608 	}
1609 	/* few more checks */
1610 	if (err_msg_format || valid_len != msglen)
1611 		return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
1612 
1613 	return 0;
1614 }
1615 #endif /* _VIRTCHNL_H_ */
1616