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