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