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