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