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