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