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