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