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