1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*******************************************************************************
3 *
4 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
5 * Copyright(c) 2013 - 2014 Intel Corporation.
6 *
7 * Contact Information:
8 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
9 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
10 *
11 ******************************************************************************/
12
13 #ifndef _VIRTCHNL_H_
14 #define _VIRTCHNL_H_
15
16 /* Description:
17 * This header file describes the VF-PF communication protocol used
18 * by the drivers for all devices starting from our 40G product line
19 *
20 * Admin queue buffer usage:
21 * desc->opcode is always aqc_opc_send_msg_to_pf
22 * flags, retval, datalen, and data addr are all used normally.
23 * The Firmware copies the cookie fields when sending messages between the
24 * PF and VF, but uses all other fields internally. Due to this limitation,
25 * we must send all messages as "indirect", i.e. using an external buffer.
26 *
27 * All the VSI indexes are relative to the VF. Each VF can have maximum of
28 * three VSIs. All the queue indexes are relative to the VSI. Each VF can
29 * have a maximum of sixteen queues for all of its VSIs.
30 *
31 * The PF is required to return a status code in v_retval for all messages
32 * except RESET_VF, which does not require any response. The return value
33 * is of status_code type, defined in the shared type.h.
34 *
35 * In general, VF driver initialization should roughly follow the order of
36 * these opcodes. The VF driver must first validate the API version of the
37 * PF driver, then request a reset, then get resources, then configure
38 * queues and interrupts. After these operations are complete, the VF
39 * driver may start its queues, optionally add MAC and VLAN filters, and
40 * process traffic.
41 */
42
43 /* START GENERIC DEFINES
44 * Need to ensure the following enums and defines hold the same meaning and
45 * value in current and future projects
46 */
47
48 /* Error Codes */
49 enum virtchnl_status_code {
50 VIRTCHNL_STATUS_SUCCESS = 0,
51 VIRTCHNL_STATUS_ERR_PARAM = -5,
52 VIRTCHNL_STATUS_ERR_NO_MEMORY = -18,
53 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38,
54 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39,
55 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40,
56 VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR = -53,
57 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED = -64,
58 };
59
60 /* Backward compatibility */
61 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
62 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
63
64 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT 0x0
65 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1
66 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2
67 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3
68 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4
69 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5
70 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6
71 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT 0x7
72
73 enum virtchnl_link_speed {
74 VIRTCHNL_LINK_SPEED_UNKNOWN = 0,
75 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
76 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
77 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
78 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
79 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
80 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
81 VIRTCHNL_LINK_SPEED_2_5GB = BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
82 VIRTCHNL_LINK_SPEED_5GB = BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
83 };
84
85 /* for hsplit_0 field of Rx HMC context */
86 /* deprecated with AVF 1.0 */
87 enum virtchnl_rx_hsplit {
88 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0,
89 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1,
90 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2,
91 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
92 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8,
93 };
94
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_IWARP = 20, /* advanced opcode */
126 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
127 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
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 /* opcode 34 - 44 are reserved */
140 VIRTCHNL_OP_ADD_RSS_CFG = 45,
141 VIRTCHNL_OP_DEL_RSS_CFG = 46,
142 VIRTCHNL_OP_ADD_FDIR_FILTER = 47,
143 VIRTCHNL_OP_DEL_FDIR_FILTER = 48,
144 VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS = 51,
145 VIRTCHNL_OP_ADD_VLAN_V2 = 52,
146 VIRTCHNL_OP_DEL_VLAN_V2 = 53,
147 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 = 54,
148 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 = 55,
149 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 = 56,
150 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
151 VIRTCHNL_OP_MAX,
152 };
153
154 /* These macros are used to generate compilation errors if a structure/union
155 * is not exactly the correct length. It gives a divide by zero error if the
156 * structure/union is not of the correct size, otherwise it creates an enum
157 * that is never used.
158 */
159 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
160 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
161 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
162 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
163
164 /* Virtual channel message descriptor. This overlays the admin queue
165 * descriptor. All other data is passed in external buffers.
166 */
167
168 struct virtchnl_msg {
169 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
170 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
171 enum virtchnl_status_code v_retval; /* ditto for desc->retval */
172 u32 vfid; /* used by PF when sending to VF */
173 };
174
175 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
176
177 /* Message descriptions and data structures. */
178
179 /* VIRTCHNL_OP_VERSION
180 * VF posts its version number to the PF. PF responds with its version number
181 * in the same format, along with a return code.
182 * Reply from PF has its major/minor versions also in param0 and param1.
183 * If there is a major version mismatch, then the VF cannot operate.
184 * If there is a minor version mismatch, then the VF can operate but should
185 * add a warning to the system log.
186 *
187 * This enum element MUST always be specified as == 1, regardless of other
188 * changes in the API. The PF must always respond to this message without
189 * error regardless of version mismatch.
190 */
191 #define VIRTCHNL_VERSION_MAJOR 1
192 #define VIRTCHNL_VERSION_MINOR 1
193 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
194
195 struct virtchnl_version_info {
196 u32 major;
197 u32 minor;
198 };
199
200 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
201
202 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
203 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
204
205 /* VIRTCHNL_OP_RESET_VF
206 * VF sends this request to PF with no parameters
207 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
208 * until reset completion is indicated. The admin queue must be reinitialized
209 * after this operation.
210 *
211 * When reset is complete, PF must ensure that all queues in all VSIs associated
212 * with the VF are stopped, all queue configurations in the HMC are set to 0,
213 * and all MAC and VLAN filters (except the default MAC address) on all VSIs
214 * are cleared.
215 */
216
217 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
218 * vsi_type should always be 6 for backward compatibility. Add other fields
219 * as needed.
220 */
221 enum virtchnl_vsi_type {
222 VIRTCHNL_VSI_TYPE_INVALID = 0,
223 VIRTCHNL_VSI_SRIOV = 6,
224 };
225
226 /* VIRTCHNL_OP_GET_VF_RESOURCES
227 * Version 1.0 VF sends this request to PF with no parameters
228 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
229 * PF responds with an indirect message containing
230 * virtchnl_vf_resource and one or more
231 * virtchnl_vsi_resource structures.
232 */
233
234 struct virtchnl_vsi_resource {
235 u16 vsi_id;
236 u16 num_queue_pairs;
237 enum virtchnl_vsi_type vsi_type;
238 u16 qset_handle;
239 u8 default_mac_addr[ETH_ALEN];
240 };
241
242 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
243
244 /* VF capability flags
245 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
246 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
247 */
248 #define VIRTCHNL_VF_OFFLOAD_L2 BIT(0)
249 #define VIRTCHNL_VF_OFFLOAD_IWARP BIT(1)
250 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ BIT(3)
251 #define VIRTCHNL_VF_OFFLOAD_RSS_REG BIT(4)
252 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR BIT(5)
253 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES BIT(6)
254 /* used to negotiate communicating link speeds in Mbps */
255 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED BIT(7)
256 #define VIRTCHNL_VF_OFFLOAD_VLAN_V2 BIT(15)
257 #define VIRTCHNL_VF_OFFLOAD_VLAN BIT(16)
258 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING BIT(17)
259 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 BIT(18)
260 #define VIRTCHNL_VF_OFFLOAD_RSS_PF BIT(19)
261 #define VIRTCHNL_VF_OFFLOAD_ENCAP BIT(20)
262 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM BIT(21)
263 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM BIT(22)
264 #define VIRTCHNL_VF_OFFLOAD_ADQ BIT(23)
265 #define VIRTCHNL_VF_OFFLOAD_USO BIT(25)
266 #define VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF BIT(27)
267 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF BIT(28)
268
269 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
270 VIRTCHNL_VF_OFFLOAD_VLAN | \
271 VIRTCHNL_VF_OFFLOAD_RSS_PF)
272
273 struct virtchnl_vf_resource {
274 u16 num_vsis;
275 u16 num_queue_pairs;
276 u16 max_vectors;
277 u16 max_mtu;
278
279 u32 vf_cap_flags;
280 u32 rss_key_size;
281 u32 rss_lut_size;
282
283 struct virtchnl_vsi_resource vsi_res[1];
284 };
285
286 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
287
288 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
289 * VF sends this message to set up parameters for one TX queue.
290 * External data buffer contains one instance of virtchnl_txq_info.
291 * PF configures requested queue and returns a status code.
292 */
293
294 /* Tx queue config info */
295 struct virtchnl_txq_info {
296 u16 vsi_id;
297 u16 queue_id;
298 u16 ring_len; /* number of descriptors, multiple of 8 */
299 u16 headwb_enabled; /* deprecated with AVF 1.0 */
300 u64 dma_ring_addr;
301 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
302 };
303
304 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
305
306 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
307 * VF sends this message to set up parameters for one RX queue.
308 * External data buffer contains one instance of virtchnl_rxq_info.
309 * PF configures requested queue and returns a status code.
310 */
311
312 /* Rx queue config info */
313 struct virtchnl_rxq_info {
314 u16 vsi_id;
315 u16 queue_id;
316 u32 ring_len; /* number of descriptors, multiple of 32 */
317 u16 hdr_size;
318 u16 splithdr_enabled; /* deprecated with AVF 1.0 */
319 u32 databuffer_size;
320 u32 max_pkt_size;
321 u32 pad1;
322 u64 dma_ring_addr;
323 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
324 u32 pad2;
325 };
326
327 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
328
329 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
330 * VF sends this message to set parameters for all active TX and RX queues
331 * associated with the specified VSI.
332 * PF configures queues and returns status.
333 * If the number of queues specified is greater than the number of queues
334 * associated with the VSI, an error is returned and no queues are configured.
335 */
336 struct virtchnl_queue_pair_info {
337 /* NOTE: vsi_id and queue_id should be identical for both queues. */
338 struct virtchnl_txq_info txq;
339 struct virtchnl_rxq_info rxq;
340 };
341
342 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
343
344 struct virtchnl_vsi_queue_config_info {
345 u16 vsi_id;
346 u16 num_queue_pairs;
347 u32 pad;
348 struct virtchnl_queue_pair_info qpair[1];
349 };
350
351 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
352
353 /* VIRTCHNL_OP_REQUEST_QUEUES
354 * VF sends this message to request the PF to allocate additional queues to
355 * this VF. Each VF gets a guaranteed number of queues on init but asking for
356 * additional queues must be negotiated. This is a best effort request as it
357 * is possible the PF does not have enough queues left to support the request.
358 * If the PF cannot support the number requested it will respond with the
359 * maximum number it is able to support. If the request is successful, PF will
360 * then reset the VF to institute required changes.
361 */
362
363 /* VF resource request */
364 struct virtchnl_vf_res_request {
365 u16 num_queue_pairs;
366 };
367
368 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
369 * VF uses this message to map vectors to queues.
370 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
371 * are to be associated with the specified vector.
372 * The "other" causes are always mapped to vector 0.
373 * PF configures interrupt mapping and returns status.
374 */
375 struct virtchnl_vector_map {
376 u16 vsi_id;
377 u16 vector_id;
378 u16 rxq_map;
379 u16 txq_map;
380 u16 rxitr_idx;
381 u16 txitr_idx;
382 };
383
384 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
385
386 struct virtchnl_irq_map_info {
387 u16 num_vectors;
388 struct virtchnl_vector_map vecmap[1];
389 };
390
391 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
392
393 /* VIRTCHNL_OP_ENABLE_QUEUES
394 * VIRTCHNL_OP_DISABLE_QUEUES
395 * VF sends these message to enable or disable TX/RX queue pairs.
396 * The queues fields are bitmaps indicating which queues to act upon.
397 * (Currently, we only support 16 queues per VF, but we make the field
398 * u32 to allow for expansion.)
399 * PF performs requested action and returns status.
400 */
401 struct virtchnl_queue_select {
402 u16 vsi_id;
403 u16 pad;
404 u32 rx_queues;
405 u32 tx_queues;
406 };
407
408 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
409
410 /* VIRTCHNL_OP_ADD_ETH_ADDR
411 * VF sends this message in order to add one or more unicast or multicast
412 * address filters for the specified VSI.
413 * PF adds the filters and returns status.
414 */
415
416 /* VIRTCHNL_OP_DEL_ETH_ADDR
417 * VF sends this message in order to remove one or more unicast or multicast
418 * filters for the specified VSI.
419 * PF removes the filters and returns status.
420 */
421
422 /* VIRTCHNL_ETHER_ADDR_LEGACY
423 * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad
424 * bytes. Moving forward all VF drivers should not set type to
425 * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy
426 * behavior. The control plane function (i.e. PF) can use a best effort method
427 * of tracking the primary/device unicast in this case, but there is no
428 * guarantee and functionality depends on the implementation of the PF.
429 */
430
431 /* VIRTCHNL_ETHER_ADDR_PRIMARY
432 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the
433 * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and
434 * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane
435 * function (i.e. PF) to accurately track and use this MAC address for
436 * displaying on the host and for VM/function reset.
437 */
438
439 /* VIRTCHNL_ETHER_ADDR_EXTRA
440 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra
441 * unicast and/or multicast filters that are being added/deleted via
442 * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively.
443 */
444 struct virtchnl_ether_addr {
445 u8 addr[ETH_ALEN];
446 u8 type;
447 #define VIRTCHNL_ETHER_ADDR_LEGACY 0
448 #define VIRTCHNL_ETHER_ADDR_PRIMARY 1
449 #define VIRTCHNL_ETHER_ADDR_EXTRA 2
450 #define VIRTCHNL_ETHER_ADDR_TYPE_MASK 3 /* first two bits of type are valid */
451 u8 pad;
452 };
453
454 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
455
456 struct virtchnl_ether_addr_list {
457 u16 vsi_id;
458 u16 num_elements;
459 struct virtchnl_ether_addr list[1];
460 };
461
462 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
463
464 /* VIRTCHNL_OP_ADD_VLAN
465 * VF sends this message to add one or more VLAN tag filters for receives.
466 * PF adds the filters and returns status.
467 * If a port VLAN is configured by the PF, this operation will return an
468 * error to the VF.
469 */
470
471 /* VIRTCHNL_OP_DEL_VLAN
472 * VF sends this message to remove one or more VLAN tag filters for receives.
473 * PF removes the filters and returns status.
474 * If a port VLAN is configured by the PF, this operation will return an
475 * error to the VF.
476 */
477
478 struct virtchnl_vlan_filter_list {
479 u16 vsi_id;
480 u16 num_elements;
481 u16 vlan_id[1];
482 };
483
484 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
485
486 /* This enum is used for all of the VIRTCHNL_VF_OFFLOAD_VLAN_V2_CAPS related
487 * structures and opcodes.
488 *
489 * VIRTCHNL_VLAN_UNSUPPORTED - This field is not supported and if a VF driver
490 * populates it the PF should return VIRTCHNL_STATUS_ERR_NOT_SUPPORTED.
491 *
492 * VIRTCHNL_VLAN_ETHERTYPE_8100 - This field supports 0x8100 ethertype.
493 * VIRTCHNL_VLAN_ETHERTYPE_88A8 - This field supports 0x88A8 ethertype.
494 * VIRTCHNL_VLAN_ETHERTYPE_9100 - This field supports 0x9100 ethertype.
495 *
496 * VIRTCHNL_VLAN_ETHERTYPE_AND - Used when multiple ethertypes can be supported
497 * by the PF concurrently. For example, if the PF can support
498 * VIRTCHNL_VLAN_ETHERTYPE_8100 AND VIRTCHNL_VLAN_ETHERTYPE_88A8 filters it
499 * would OR the following bits:
500 *
501 * VIRTHCNL_VLAN_ETHERTYPE_8100 |
502 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
503 * VIRTCHNL_VLAN_ETHERTYPE_AND;
504 *
505 * The VF would interpret this as VLAN filtering can be supported on both 0x8100
506 * and 0x88A8 VLAN ethertypes.
507 *
508 * VIRTCHNL_ETHERTYPE_XOR - Used when only a single ethertype can be supported
509 * by the PF concurrently. For example if the PF can support
510 * VIRTCHNL_VLAN_ETHERTYPE_8100 XOR VIRTCHNL_VLAN_ETHERTYPE_88A8 stripping
511 * offload it would OR the following bits:
512 *
513 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
514 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
515 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
516 *
517 * The VF would interpret this as VLAN stripping can be supported on either
518 * 0x8100 or 0x88a8 VLAN ethertypes. So when requesting VLAN stripping via
519 * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 the specified ethertype will override
520 * the previously set value.
521 *
522 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 - Used to tell the VF to insert and/or
523 * strip the VLAN tag using the L2TAG1 field of the Tx/Rx descriptors.
524 *
525 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to insert hardware
526 * offloaded VLAN tags using the L2TAG2 field of the Tx descriptor.
527 *
528 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to strip hardware
529 * offloaded VLAN tags using the L2TAG2_2 field of the Rx descriptor.
530 *
531 * VIRTCHNL_VLAN_PRIO - This field supports VLAN priority bits. This is used for
532 * VLAN filtering if the underlying PF supports it.
533 *
534 * VIRTCHNL_VLAN_TOGGLE_ALLOWED - This field is used to say whether a
535 * certain VLAN capability can be toggled. For example if the underlying PF/CP
536 * allows the VF to toggle VLAN filtering, stripping, and/or insertion it should
537 * set this bit along with the supported ethertypes.
538 */
539 enum virtchnl_vlan_support {
540 VIRTCHNL_VLAN_UNSUPPORTED = 0,
541 VIRTCHNL_VLAN_ETHERTYPE_8100 = BIT(0),
542 VIRTCHNL_VLAN_ETHERTYPE_88A8 = BIT(1),
543 VIRTCHNL_VLAN_ETHERTYPE_9100 = BIT(2),
544 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 = BIT(8),
545 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 = BIT(9),
546 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 = BIT(10),
547 VIRTCHNL_VLAN_PRIO = BIT(24),
548 VIRTCHNL_VLAN_FILTER_MASK = BIT(28),
549 VIRTCHNL_VLAN_ETHERTYPE_AND = BIT(29),
550 VIRTCHNL_VLAN_ETHERTYPE_XOR = BIT(30),
551 VIRTCHNL_VLAN_TOGGLE = BIT(31),
552 };
553
554 /* This structure is used as part of the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
555 * for filtering, insertion, and stripping capabilities.
556 *
557 * If only outer capabilities are supported (for filtering, insertion, and/or
558 * stripping) then this refers to the outer most or single VLAN from the VF's
559 * perspective.
560 *
561 * If only inner capabilities are supported (for filtering, insertion, and/or
562 * stripping) then this refers to the outer most or single VLAN from the VF's
563 * perspective. Functionally this is the same as if only outer capabilities are
564 * supported. The VF driver is just forced to use the inner fields when
565 * adding/deleting filters and enabling/disabling offloads (if supported).
566 *
567 * If both outer and inner capabilities are supported (for filtering, insertion,
568 * and/or stripping) then outer refers to the outer most or single VLAN and
569 * inner refers to the second VLAN, if it exists, in the packet.
570 *
571 * There is no support for tunneled VLAN offloads, so outer or inner are never
572 * referring to a tunneled packet from the VF's perspective.
573 */
574 struct virtchnl_vlan_supported_caps {
575 u32 outer;
576 u32 inner;
577 };
578
579 /* The PF populates these fields based on the supported VLAN filtering. If a
580 * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
581 * reject any VIRTCHNL_OP_ADD_VLAN_V2 or VIRTCHNL_OP_DEL_VLAN_V2 messages using
582 * the unsupported fields.
583 *
584 * Also, a VF is only allowed to toggle its VLAN filtering setting if the
585 * VIRTCHNL_VLAN_TOGGLE bit is set.
586 *
587 * The ethertype(s) specified in the ethertype_init field are the ethertypes
588 * enabled for VLAN filtering. VLAN filtering in this case refers to the outer
589 * most VLAN from the VF's perspective. If both inner and outer filtering are
590 * allowed then ethertype_init only refers to the outer most VLAN as only
591 * VLAN ethertype supported for inner VLAN filtering is
592 * VIRTCHNL_VLAN_ETHERTYPE_8100. By default, inner VLAN filtering is disabled
593 * when both inner and outer filtering are allowed.
594 *
595 * The max_filters field tells the VF how many VLAN filters it's allowed to have
596 * at any one time. If it exceeds this amount and tries to add another filter,
597 * then the request will be rejected by the PF. To prevent failures, the VF
598 * should keep track of how many VLAN filters it has added and not attempt to
599 * add more than max_filters.
600 */
601 struct virtchnl_vlan_filtering_caps {
602 struct virtchnl_vlan_supported_caps filtering_support;
603 u32 ethertype_init;
604 u16 max_filters;
605 u8 pad[2];
606 };
607
608 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_filtering_caps);
609
610 /* This enum is used for the virtchnl_vlan_offload_caps structure to specify
611 * if the PF supports a different ethertype for stripping and insertion.
612 *
613 * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION - The ethertype(s) specified
614 * for stripping affect the ethertype(s) specified for insertion and visa versa
615 * as well. If the VF tries to configure VLAN stripping via
616 * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 with VIRTCHNL_VLAN_ETHERTYPE_8100 then
617 * that will be the ethertype for both stripping and insertion.
618 *
619 * VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED - The ethertype(s) specified for
620 * stripping do not affect the ethertype(s) specified for insertion and visa
621 * versa.
622 */
623 enum virtchnl_vlan_ethertype_match {
624 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION = 0,
625 VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED = 1,
626 };
627
628 /* The PF populates these fields based on the supported VLAN offloads. If a
629 * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
630 * reject any VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 or
631 * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 messages using the unsupported fields.
632 *
633 * Also, a VF is only allowed to toggle its VLAN offload setting if the
634 * VIRTCHNL_VLAN_TOGGLE_ALLOWED bit is set.
635 *
636 * The VF driver needs to be aware of how the tags are stripped by hardware and
637 * inserted by the VF driver based on the level of offload support. The PF will
638 * populate these fields based on where the VLAN tags are expected to be
639 * offloaded via the VIRTHCNL_VLAN_TAG_LOCATION_* bits. The VF will need to
640 * interpret these fields. See the definition of the
641 * VIRTCHNL_VLAN_TAG_LOCATION_* bits above the virtchnl_vlan_support
642 * enumeration.
643 */
644 struct virtchnl_vlan_offload_caps {
645 struct virtchnl_vlan_supported_caps stripping_support;
646 struct virtchnl_vlan_supported_caps insertion_support;
647 u32 ethertype_init;
648 u8 ethertype_match;
649 u8 pad[3];
650 };
651
652 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_vlan_offload_caps);
653
654 /* VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
655 * VF sends this message to determine its VLAN capabilities.
656 *
657 * PF will mark which capabilities it supports based on hardware support and
658 * current configuration. For example, if a port VLAN is configured the PF will
659 * not allow outer VLAN filtering, stripping, or insertion to be configured so
660 * it will block these features from the VF.
661 *
662 * The VF will need to cross reference its capabilities with the PFs
663 * capabilities in the response message from the PF to determine the VLAN
664 * support.
665 */
666 struct virtchnl_vlan_caps {
667 struct virtchnl_vlan_filtering_caps filtering;
668 struct virtchnl_vlan_offload_caps offloads;
669 };
670
671 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_caps);
672
673 struct virtchnl_vlan {
674 u16 tci; /* tci[15:13] = PCP and tci[11:0] = VID */
675 u16 tci_mask; /* only valid if VIRTCHNL_VLAN_FILTER_MASK set in
676 * filtering caps
677 */
678 u16 tpid; /* 0x8100, 0x88a8, etc. and only type(s) set in
679 * filtering caps. Note that tpid here does not refer to
680 * VIRTCHNL_VLAN_ETHERTYPE_*, but it refers to the
681 * actual 2-byte VLAN TPID
682 */
683 u8 pad[2];
684 };
685
686 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan);
687
688 struct virtchnl_vlan_filter {
689 struct virtchnl_vlan inner;
690 struct virtchnl_vlan outer;
691 u8 pad[16];
692 };
693
694 VIRTCHNL_CHECK_STRUCT_LEN(32, virtchnl_vlan_filter);
695
696 /* VIRTCHNL_OP_ADD_VLAN_V2
697 * VIRTCHNL_OP_DEL_VLAN_V2
698 *
699 * VF sends these messages to add/del one or more VLAN tag filters for Rx
700 * traffic.
701 *
702 * The PF attempts to add the filters and returns status.
703 *
704 * The VF should only ever attempt to add/del virtchnl_vlan_filter(s) using the
705 * supported fields negotiated via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS.
706 */
707 struct virtchnl_vlan_filter_list_v2 {
708 u16 vport_id;
709 u16 num_elements;
710 u8 pad[4];
711 struct virtchnl_vlan_filter filters[1];
712 };
713
714 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_filter_list_v2);
715
716 /* VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
717 * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
718 * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
719 * VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
720 *
721 * VF sends this message to enable or disable VLAN stripping or insertion. It
722 * also needs to specify an ethertype. The VF knows which VLAN ethertypes are
723 * allowed and whether or not it's allowed to enable/disable the specific
724 * offload via the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
725 * parse the virtchnl_vlan_caps.offloads fields to determine which offload
726 * messages are allowed.
727 *
728 * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
729 * following manner the VF will be allowed to enable and/or disable 0x8100 inner
730 * VLAN insertion and/or stripping via the opcodes listed above. Inner in this
731 * case means the outer most or single VLAN from the VF's perspective. This is
732 * because no outer offloads are supported. See the comments above the
733 * virtchnl_vlan_supported_caps structure for more details.
734 *
735 * virtchnl_vlan_caps.offloads.stripping_support.inner =
736 * VIRTCHNL_VLAN_TOGGLE |
737 * VIRTCHNL_VLAN_ETHERTYPE_8100;
738 *
739 * virtchnl_vlan_caps.offloads.insertion_support.inner =
740 * VIRTCHNL_VLAN_TOGGLE |
741 * VIRTCHNL_VLAN_ETHERTYPE_8100;
742 *
743 * In order to enable inner (again note that in this case inner is the outer
744 * most or single VLAN from the VF's perspective) VLAN stripping for 0x8100
745 * VLANs, the VF would populate the virtchnl_vlan_setting structure in the
746 * following manner and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
747 *
748 * virtchnl_vlan_setting.inner_ethertype_setting =
749 * VIRTCHNL_VLAN_ETHERTYPE_8100;
750 *
751 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
752 * initialization.
753 *
754 * The reason that VLAN TPID(s) are not being used for the
755 * outer_ethertype_setting and inner_ethertype_setting fields is because it's
756 * possible a device could support VLAN insertion and/or stripping offload on
757 * multiple ethertypes concurrently, so this method allows a VF to request
758 * multiple ethertypes in one message using the virtchnl_vlan_support
759 * enumeration.
760 *
761 * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
762 * following manner the VF will be allowed to enable 0x8100 and 0x88a8 outer
763 * VLAN insertion and stripping simultaneously. The
764 * virtchnl_vlan_caps.offloads.ethertype_match field will also have to be
765 * populated based on what the PF can support.
766 *
767 * virtchnl_vlan_caps.offloads.stripping_support.outer =
768 * VIRTCHNL_VLAN_TOGGLE |
769 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
770 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
771 * VIRTCHNL_VLAN_ETHERTYPE_AND;
772 *
773 * virtchnl_vlan_caps.offloads.insertion_support.outer =
774 * VIRTCHNL_VLAN_TOGGLE |
775 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
776 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
777 * VIRTCHNL_VLAN_ETHERTYPE_AND;
778 *
779 * In order to enable outer VLAN stripping for 0x8100 and 0x88a8 VLANs, the VF
780 * would populate the virthcnl_vlan_offload_structure in the following manner
781 * and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
782 *
783 * virtchnl_vlan_setting.outer_ethertype_setting =
784 * VIRTHCNL_VLAN_ETHERTYPE_8100 |
785 * VIRTHCNL_VLAN_ETHERTYPE_88A8;
786 *
787 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
788 * initialization.
789 *
790 * There is also the case where a PF and the underlying hardware can support
791 * VLAN offloads on multiple ethertypes, but not concurrently. For example, if
792 * the PF populates the virtchnl_vlan_caps.offloads in the following manner the
793 * VF will be allowed to enable and/or disable 0x8100 XOR 0x88a8 outer VLAN
794 * offloads. The ethertypes must match for stripping and insertion.
795 *
796 * virtchnl_vlan_caps.offloads.stripping_support.outer =
797 * VIRTCHNL_VLAN_TOGGLE |
798 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
799 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
800 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
801 *
802 * virtchnl_vlan_caps.offloads.insertion_support.outer =
803 * VIRTCHNL_VLAN_TOGGLE |
804 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
805 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
806 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
807 *
808 * virtchnl_vlan_caps.offloads.ethertype_match =
809 * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
810 *
811 * In order to enable outer VLAN stripping for 0x88a8 VLANs, the VF would
812 * populate the virtchnl_vlan_setting structure in the following manner and send
813 * the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2. Also, this will change the
814 * ethertype for VLAN insertion if it's enabled. So, for completeness, a
815 * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 with the same ethertype should be sent.
816 *
817 * virtchnl_vlan_setting.outer_ethertype_setting = VIRTHCNL_VLAN_ETHERTYPE_88A8;
818 *
819 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
820 * initialization.
821 */
822 struct virtchnl_vlan_setting {
823 u32 outer_ethertype_setting;
824 u32 inner_ethertype_setting;
825 u16 vport_id;
826 u8 pad[6];
827 };
828
829 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_setting);
830
831 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
832 * VF sends VSI id and flags.
833 * PF returns status code in retval.
834 * Note: we assume that broadcast accept mode is always enabled.
835 */
836 struct virtchnl_promisc_info {
837 u16 vsi_id;
838 u16 flags;
839 };
840
841 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
842
843 #define FLAG_VF_UNICAST_PROMISC 0x00000001
844 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
845
846 /* VIRTCHNL_OP_GET_STATS
847 * VF sends this message to request stats for the selected VSI. VF uses
848 * the virtchnl_queue_select struct to specify the VSI. The queue_id
849 * field is ignored by the PF.
850 *
851 * PF replies with struct eth_stats in an external buffer.
852 */
853
854 /* VIRTCHNL_OP_CONFIG_RSS_KEY
855 * VIRTCHNL_OP_CONFIG_RSS_LUT
856 * VF sends these messages to configure RSS. Only supported if both PF
857 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
858 * configuration negotiation. If this is the case, then the RSS fields in
859 * the VF resource struct are valid.
860 * Both the key and LUT are initialized to 0 by the PF, meaning that
861 * RSS is effectively disabled until set up by the VF.
862 */
863 struct virtchnl_rss_key {
864 u16 vsi_id;
865 u16 key_len;
866 u8 key[1]; /* RSS hash key, packed bytes */
867 };
868
869 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
870
871 struct virtchnl_rss_lut {
872 u16 vsi_id;
873 u16 lut_entries;
874 u8 lut[1]; /* RSS lookup table */
875 };
876
877 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
878
879 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
880 * VIRTCHNL_OP_SET_RSS_HENA
881 * VF sends these messages to get and set the hash filter enable bits for RSS.
882 * By default, the PF sets these to all possible traffic types that the
883 * hardware supports. The VF can query this value if it wants to change the
884 * traffic types that are hashed by the hardware.
885 */
886 struct virtchnl_rss_hena {
887 u64 hena;
888 };
889
890 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
891
892 /* VIRTCHNL_OP_ENABLE_CHANNELS
893 * VIRTCHNL_OP_DISABLE_CHANNELS
894 * VF sends these messages to enable or disable channels based on
895 * the user specified queue count and queue offset for each traffic class.
896 * This struct encompasses all the information that the PF needs from
897 * VF to create a channel.
898 */
899 struct virtchnl_channel_info {
900 u16 count; /* number of queues in a channel */
901 u16 offset; /* queues in a channel start from 'offset' */
902 u32 pad;
903 u64 max_tx_rate;
904 };
905
906 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
907
908 struct virtchnl_tc_info {
909 u32 num_tc;
910 u32 pad;
911 struct virtchnl_channel_info list[1];
912 };
913
914 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
915
916 /* VIRTCHNL_ADD_CLOUD_FILTER
917 * VIRTCHNL_DEL_CLOUD_FILTER
918 * VF sends these messages to add or delete a cloud filter based on the
919 * user specified match and action filters. These structures encompass
920 * all the information that the PF needs from the VF to add/delete a
921 * cloud filter.
922 */
923
924 struct virtchnl_l4_spec {
925 u8 src_mac[ETH_ALEN];
926 u8 dst_mac[ETH_ALEN];
927 __be16 vlan_id;
928 __be16 pad; /* reserved for future use */
929 __be32 src_ip[4];
930 __be32 dst_ip[4];
931 __be16 src_port;
932 __be16 dst_port;
933 };
934
935 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
936
937 union virtchnl_flow_spec {
938 struct virtchnl_l4_spec tcp_spec;
939 u8 buffer[128]; /* reserved for future use */
940 };
941
942 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
943
944 enum virtchnl_action {
945 /* action types */
946 VIRTCHNL_ACTION_DROP = 0,
947 VIRTCHNL_ACTION_TC_REDIRECT,
948 VIRTCHNL_ACTION_PASSTHRU,
949 VIRTCHNL_ACTION_QUEUE,
950 VIRTCHNL_ACTION_Q_REGION,
951 VIRTCHNL_ACTION_MARK,
952 VIRTCHNL_ACTION_COUNT,
953 };
954
955 enum virtchnl_flow_type {
956 /* flow types */
957 VIRTCHNL_TCP_V4_FLOW = 0,
958 VIRTCHNL_TCP_V6_FLOW,
959 };
960
961 struct virtchnl_filter {
962 union virtchnl_flow_spec data;
963 union virtchnl_flow_spec mask;
964 enum virtchnl_flow_type flow_type;
965 enum virtchnl_action action;
966 u32 action_meta;
967 u8 field_flags;
968 u8 pad[3];
969 };
970
971 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
972
973 /* VIRTCHNL_OP_EVENT
974 * PF sends this message to inform the VF driver of events that may affect it.
975 * No direct response is expected from the VF, though it may generate other
976 * messages in response to this one.
977 */
978 enum virtchnl_event_codes {
979 VIRTCHNL_EVENT_UNKNOWN = 0,
980 VIRTCHNL_EVENT_LINK_CHANGE,
981 VIRTCHNL_EVENT_RESET_IMPENDING,
982 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
983 };
984
985 #define PF_EVENT_SEVERITY_INFO 0
986 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
987
988 struct virtchnl_pf_event {
989 enum virtchnl_event_codes event;
990 union {
991 /* If the PF driver does not support the new speed reporting
992 * capabilities then use link_event else use link_event_adv to
993 * get the speed and link information. The ability to understand
994 * new speeds is indicated by setting the capability flag
995 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
996 * in virtchnl_vf_resource struct and can be used to determine
997 * which link event struct to use below.
998 */
999 struct {
1000 enum virtchnl_link_speed link_speed;
1001 bool link_status;
1002 } link_event;
1003 struct {
1004 /* link_speed provided in Mbps */
1005 u32 link_speed;
1006 u8 link_status;
1007 u8 pad[3];
1008 } link_event_adv;
1009 } event_data;
1010
1011 int severity;
1012 };
1013
1014 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
1015
1016 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
1017 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
1018 * The request for this originates from the VF IWARP driver through
1019 * a client interface between VF LAN and VF IWARP driver.
1020 * A vector could have an AEQ and CEQ attached to it although
1021 * there is a single AEQ per VF IWARP instance in which case
1022 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
1023 * There will never be a case where there will be multiple CEQs attached
1024 * to a single vector.
1025 * PF configures interrupt mapping and returns status.
1026 */
1027
1028 struct virtchnl_iwarp_qv_info {
1029 u32 v_idx; /* msix_vector */
1030 u16 ceq_idx;
1031 u16 aeq_idx;
1032 u8 itr_idx;
1033 u8 pad[3];
1034 };
1035
1036 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
1037
1038 struct virtchnl_iwarp_qvlist_info {
1039 u32 num_vectors;
1040 struct virtchnl_iwarp_qv_info qv_info[1];
1041 };
1042
1043 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
1044
1045 /* VF reset states - these are written into the RSTAT register:
1046 * VFGEN_RSTAT on the VF
1047 * When the PF initiates a reset, it writes 0
1048 * When the reset is complete, it writes 1
1049 * When the PF detects that the VF has recovered, it writes 2
1050 * VF checks this register periodically to determine if a reset has occurred,
1051 * then polls it to know when the reset is complete.
1052 * If either the PF or VF reads the register while the hardware
1053 * is in a reset state, it will return DEADBEEF, which, when masked
1054 * will result in 3.
1055 */
1056 enum virtchnl_vfr_states {
1057 VIRTCHNL_VFR_INPROGRESS = 0,
1058 VIRTCHNL_VFR_COMPLETED,
1059 VIRTCHNL_VFR_VFACTIVE,
1060 };
1061
1062 /* Type of RSS algorithm */
1063 enum virtchnl_rss_algorithm {
1064 VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0,
1065 VIRTCHNL_RSS_ALG_R_ASYMMETRIC = 1,
1066 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2,
1067 VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3,
1068 };
1069
1070 #define VIRTCHNL_MAX_NUM_PROTO_HDRS 32
1071 #define PROTO_HDR_SHIFT 5
1072 #define PROTO_HDR_FIELD_START(proto_hdr_type) ((proto_hdr_type) << PROTO_HDR_SHIFT)
1073 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1)
1074
1075 /* VF use these macros to configure each protocol header.
1076 * Specify which protocol headers and protocol header fields base on
1077 * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field.
1078 * @param hdr: a struct of virtchnl_proto_hdr
1079 * @param hdr_type: ETH/IPV4/TCP, etc
1080 * @param field: SRC/DST/TEID/SPI, etc
1081 */
1082 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field) \
1083 ((hdr)->field_selector |= BIT((field) & PROTO_HDR_FIELD_MASK))
1084 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field) \
1085 ((hdr)->field_selector &= ~BIT((field) & PROTO_HDR_FIELD_MASK))
1086 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val) \
1087 ((hdr)->field_selector & BIT((val) & PROTO_HDR_FIELD_MASK))
1088 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr) ((hdr)->field_selector)
1089
1090 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
1091 (VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, \
1092 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
1093 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
1094 (VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, \
1095 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
1096
1097 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type) \
1098 ((hdr)->type = VIRTCHNL_PROTO_HDR_ ## hdr_type)
1099 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \
1100 (((hdr)->type) >> PROTO_HDR_SHIFT)
1101 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \
1102 ((hdr)->type == ((val) >> PROTO_HDR_SHIFT))
1103 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \
1104 (VIRTCHNL_TEST_PROTO_HDR_TYPE((hdr), (val)) && \
1105 VIRTCHNL_TEST_PROTO_HDR_FIELD((hdr), (val)))
1106
1107 /* Protocol header type within a packet segment. A segment consists of one or
1108 * more protocol headers that make up a logical group of protocol headers. Each
1109 * logical group of protocol headers encapsulates or is encapsulated using/by
1110 * tunneling or encapsulation protocols for network virtualization.
1111 */
1112 enum virtchnl_proto_hdr_type {
1113 VIRTCHNL_PROTO_HDR_NONE,
1114 VIRTCHNL_PROTO_HDR_ETH,
1115 VIRTCHNL_PROTO_HDR_S_VLAN,
1116 VIRTCHNL_PROTO_HDR_C_VLAN,
1117 VIRTCHNL_PROTO_HDR_IPV4,
1118 VIRTCHNL_PROTO_HDR_IPV6,
1119 VIRTCHNL_PROTO_HDR_TCP,
1120 VIRTCHNL_PROTO_HDR_UDP,
1121 VIRTCHNL_PROTO_HDR_SCTP,
1122 VIRTCHNL_PROTO_HDR_GTPU_IP,
1123 VIRTCHNL_PROTO_HDR_GTPU_EH,
1124 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
1125 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
1126 VIRTCHNL_PROTO_HDR_PPPOE,
1127 VIRTCHNL_PROTO_HDR_L2TPV3,
1128 VIRTCHNL_PROTO_HDR_ESP,
1129 VIRTCHNL_PROTO_HDR_AH,
1130 VIRTCHNL_PROTO_HDR_PFCP,
1131 };
1132
1133 /* Protocol header field within a protocol header. */
1134 enum virtchnl_proto_hdr_field {
1135 /* ETHER */
1136 VIRTCHNL_PROTO_HDR_ETH_SRC =
1137 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ETH),
1138 VIRTCHNL_PROTO_HDR_ETH_DST,
1139 VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
1140 /* S-VLAN */
1141 VIRTCHNL_PROTO_HDR_S_VLAN_ID =
1142 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_S_VLAN),
1143 /* C-VLAN */
1144 VIRTCHNL_PROTO_HDR_C_VLAN_ID =
1145 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_C_VLAN),
1146 /* IPV4 */
1147 VIRTCHNL_PROTO_HDR_IPV4_SRC =
1148 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4),
1149 VIRTCHNL_PROTO_HDR_IPV4_DST,
1150 VIRTCHNL_PROTO_HDR_IPV4_DSCP,
1151 VIRTCHNL_PROTO_HDR_IPV4_TTL,
1152 VIRTCHNL_PROTO_HDR_IPV4_PROT,
1153 /* IPV6 */
1154 VIRTCHNL_PROTO_HDR_IPV6_SRC =
1155 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6),
1156 VIRTCHNL_PROTO_HDR_IPV6_DST,
1157 VIRTCHNL_PROTO_HDR_IPV6_TC,
1158 VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
1159 VIRTCHNL_PROTO_HDR_IPV6_PROT,
1160 /* TCP */
1161 VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
1162 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_TCP),
1163 VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
1164 /* UDP */
1165 VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
1166 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_UDP),
1167 VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
1168 /* SCTP */
1169 VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
1170 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_SCTP),
1171 VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
1172 /* GTPU_IP */
1173 VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
1174 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_IP),
1175 /* GTPU_EH */
1176 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
1177 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH),
1178 VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
1179 /* PPPOE */
1180 VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
1181 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PPPOE),
1182 /* L2TPV3 */
1183 VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
1184 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV3),
1185 /* ESP */
1186 VIRTCHNL_PROTO_HDR_ESP_SPI =
1187 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ESP),
1188 /* AH */
1189 VIRTCHNL_PROTO_HDR_AH_SPI =
1190 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_AH),
1191 /* PFCP */
1192 VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
1193 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PFCP),
1194 VIRTCHNL_PROTO_HDR_PFCP_SEID,
1195 };
1196
1197 struct virtchnl_proto_hdr {
1198 enum virtchnl_proto_hdr_type type;
1199 u32 field_selector; /* a bit mask to select field for header type */
1200 u8 buffer[64];
1201 /**
1202 * binary buffer in network order for specific header type.
1203 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
1204 * header is expected to be copied into the buffer.
1205 */
1206 };
1207
1208 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr);
1209
1210 struct virtchnl_proto_hdrs {
1211 u8 tunnel_level;
1212 u8 pad[3];
1213 /**
1214 * specify where protocol header start from.
1215 * 0 - from the outer layer
1216 * 1 - from the first inner layer
1217 * 2 - from the second inner layer
1218 * ....
1219 **/
1220 int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */
1221 struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
1222 };
1223
1224 VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs);
1225
1226 struct virtchnl_rss_cfg {
1227 struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */
1228 enum virtchnl_rss_algorithm rss_algorithm; /* RSS algorithm type */
1229 u8 reserved[128]; /* reserve for future */
1230 };
1231
1232 VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg);
1233
1234 /* action configuration for FDIR */
1235 struct virtchnl_filter_action {
1236 enum virtchnl_action type;
1237 union {
1238 /* used for queue and qgroup action */
1239 struct {
1240 u16 index;
1241 u8 region;
1242 } queue;
1243 /* used for count action */
1244 struct {
1245 /* share counter ID with other flow rules */
1246 u8 shared;
1247 u32 id; /* counter ID */
1248 } count;
1249 /* used for mark action */
1250 u32 mark_id;
1251 u8 reserve[32];
1252 } act_conf;
1253 };
1254
1255 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action);
1256
1257 #define VIRTCHNL_MAX_NUM_ACTIONS 8
1258
1259 struct virtchnl_filter_action_set {
1260 /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
1261 int count;
1262 struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
1263 };
1264
1265 VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set);
1266
1267 /* pattern and action for FDIR rule */
1268 struct virtchnl_fdir_rule {
1269 struct virtchnl_proto_hdrs proto_hdrs;
1270 struct virtchnl_filter_action_set action_set;
1271 };
1272
1273 VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule);
1274
1275 /* Status returned to VF after VF requests FDIR commands
1276 * VIRTCHNL_FDIR_SUCCESS
1277 * VF FDIR related request is successfully done by PF
1278 * The request can be OP_ADD/DEL.
1279 *
1280 * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
1281 * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
1282 *
1283 * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
1284 * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
1285 *
1286 * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
1287 * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
1288 *
1289 * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
1290 * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
1291 *
1292 * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
1293 * OP_ADD_FDIR_FILTER request is failed due to parameters validation
1294 * or HW doesn't support.
1295 *
1296 * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
1297 * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
1298 * for programming.
1299 */
1300 enum virtchnl_fdir_prgm_status {
1301 VIRTCHNL_FDIR_SUCCESS = 0,
1302 VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
1303 VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
1304 VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
1305 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
1306 VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
1307 VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
1308 };
1309
1310 /* VIRTCHNL_OP_ADD_FDIR_FILTER
1311 * VF sends this request to PF by filling out vsi_id,
1312 * validate_only and rule_cfg. PF will return flow_id
1313 * if the request is successfully done and return add_status to VF.
1314 */
1315 struct virtchnl_fdir_add {
1316 u16 vsi_id; /* INPUT */
1317 /*
1318 * 1 for validating a fdir rule, 0 for creating a fdir rule.
1319 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
1320 */
1321 u16 validate_only; /* INPUT */
1322 u32 flow_id; /* OUTPUT */
1323 struct virtchnl_fdir_rule rule_cfg; /* INPUT */
1324 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
1325 };
1326
1327 VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add);
1328
1329 /* VIRTCHNL_OP_DEL_FDIR_FILTER
1330 * VF sends this request to PF by filling out vsi_id
1331 * and flow_id. PF will return del_status to VF.
1332 */
1333 struct virtchnl_fdir_del {
1334 u16 vsi_id; /* INPUT */
1335 u16 pad;
1336 u32 flow_id; /* INPUT */
1337 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
1338 };
1339
1340 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del);
1341
1342 /**
1343 * virtchnl_vc_validate_vf_msg
1344 * @ver: Virtchnl version info
1345 * @v_opcode: Opcode for the message
1346 * @msg: pointer to the msg buffer
1347 * @msglen: msg length
1348 *
1349 * validate msg format against struct for each opcode
1350 */
1351 static inline int
virtchnl_vc_validate_vf_msg(struct virtchnl_version_info * ver,u32 v_opcode,u8 * msg,u16 msglen)1352 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
1353 u8 *msg, u16 msglen)
1354 {
1355 bool err_msg_format = false;
1356 int valid_len = 0;
1357
1358 /* Validate message length. */
1359 switch (v_opcode) {
1360 case VIRTCHNL_OP_VERSION:
1361 valid_len = sizeof(struct virtchnl_version_info);
1362 break;
1363 case VIRTCHNL_OP_RESET_VF:
1364 break;
1365 case VIRTCHNL_OP_GET_VF_RESOURCES:
1366 if (VF_IS_V11(ver))
1367 valid_len = sizeof(u32);
1368 break;
1369 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
1370 valid_len = sizeof(struct virtchnl_txq_info);
1371 break;
1372 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
1373 valid_len = sizeof(struct virtchnl_rxq_info);
1374 break;
1375 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1376 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
1377 if (msglen >= valid_len) {
1378 struct virtchnl_vsi_queue_config_info *vqc =
1379 (struct virtchnl_vsi_queue_config_info *)msg;
1380 valid_len += (vqc->num_queue_pairs *
1381 sizeof(struct
1382 virtchnl_queue_pair_info));
1383 if (vqc->num_queue_pairs == 0)
1384 err_msg_format = true;
1385 }
1386 break;
1387 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1388 valid_len = sizeof(struct virtchnl_irq_map_info);
1389 if (msglen >= valid_len) {
1390 struct virtchnl_irq_map_info *vimi =
1391 (struct virtchnl_irq_map_info *)msg;
1392 valid_len += (vimi->num_vectors *
1393 sizeof(struct virtchnl_vector_map));
1394 if (vimi->num_vectors == 0)
1395 err_msg_format = true;
1396 }
1397 break;
1398 case VIRTCHNL_OP_ENABLE_QUEUES:
1399 case VIRTCHNL_OP_DISABLE_QUEUES:
1400 valid_len = sizeof(struct virtchnl_queue_select);
1401 break;
1402 case VIRTCHNL_OP_ADD_ETH_ADDR:
1403 case VIRTCHNL_OP_DEL_ETH_ADDR:
1404 valid_len = sizeof(struct virtchnl_ether_addr_list);
1405 if (msglen >= valid_len) {
1406 struct virtchnl_ether_addr_list *veal =
1407 (struct virtchnl_ether_addr_list *)msg;
1408 valid_len += veal->num_elements *
1409 sizeof(struct virtchnl_ether_addr);
1410 if (veal->num_elements == 0)
1411 err_msg_format = true;
1412 }
1413 break;
1414 case VIRTCHNL_OP_ADD_VLAN:
1415 case VIRTCHNL_OP_DEL_VLAN:
1416 valid_len = sizeof(struct virtchnl_vlan_filter_list);
1417 if (msglen >= valid_len) {
1418 struct virtchnl_vlan_filter_list *vfl =
1419 (struct virtchnl_vlan_filter_list *)msg;
1420 valid_len += vfl->num_elements * sizeof(u16);
1421 if (vfl->num_elements == 0)
1422 err_msg_format = true;
1423 }
1424 break;
1425 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1426 valid_len = sizeof(struct virtchnl_promisc_info);
1427 break;
1428 case VIRTCHNL_OP_GET_STATS:
1429 valid_len = sizeof(struct virtchnl_queue_select);
1430 break;
1431 case VIRTCHNL_OP_IWARP:
1432 /* These messages are opaque to us and will be validated in
1433 * the RDMA client code. We just need to check for nonzero
1434 * length. The firmware will enforce max length restrictions.
1435 */
1436 if (msglen)
1437 valid_len = msglen;
1438 else
1439 err_msg_format = true;
1440 break;
1441 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
1442 break;
1443 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1444 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
1445 if (msglen >= valid_len) {
1446 struct virtchnl_iwarp_qvlist_info *qv =
1447 (struct virtchnl_iwarp_qvlist_info *)msg;
1448 if (qv->num_vectors == 0) {
1449 err_msg_format = true;
1450 break;
1451 }
1452 valid_len += ((qv->num_vectors - 1) *
1453 sizeof(struct virtchnl_iwarp_qv_info));
1454 }
1455 break;
1456 case VIRTCHNL_OP_CONFIG_RSS_KEY:
1457 valid_len = sizeof(struct virtchnl_rss_key);
1458 if (msglen >= valid_len) {
1459 struct virtchnl_rss_key *vrk =
1460 (struct virtchnl_rss_key *)msg;
1461 valid_len += vrk->key_len - 1;
1462 }
1463 break;
1464 case VIRTCHNL_OP_CONFIG_RSS_LUT:
1465 valid_len = sizeof(struct virtchnl_rss_lut);
1466 if (msglen >= valid_len) {
1467 struct virtchnl_rss_lut *vrl =
1468 (struct virtchnl_rss_lut *)msg;
1469 valid_len += vrl->lut_entries - 1;
1470 }
1471 break;
1472 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
1473 break;
1474 case VIRTCHNL_OP_SET_RSS_HENA:
1475 valid_len = sizeof(struct virtchnl_rss_hena);
1476 break;
1477 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1478 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1479 break;
1480 case VIRTCHNL_OP_REQUEST_QUEUES:
1481 valid_len = sizeof(struct virtchnl_vf_res_request);
1482 break;
1483 case VIRTCHNL_OP_ENABLE_CHANNELS:
1484 valid_len = sizeof(struct virtchnl_tc_info);
1485 if (msglen >= valid_len) {
1486 struct virtchnl_tc_info *vti =
1487 (struct virtchnl_tc_info *)msg;
1488 valid_len += (vti->num_tc - 1) *
1489 sizeof(struct virtchnl_channel_info);
1490 if (vti->num_tc == 0)
1491 err_msg_format = true;
1492 }
1493 break;
1494 case VIRTCHNL_OP_DISABLE_CHANNELS:
1495 break;
1496 case VIRTCHNL_OP_ADD_CLOUD_FILTER:
1497 valid_len = sizeof(struct virtchnl_filter);
1498 break;
1499 case VIRTCHNL_OP_DEL_CLOUD_FILTER:
1500 valid_len = sizeof(struct virtchnl_filter);
1501 break;
1502 case VIRTCHNL_OP_ADD_RSS_CFG:
1503 case VIRTCHNL_OP_DEL_RSS_CFG:
1504 valid_len = sizeof(struct virtchnl_rss_cfg);
1505 break;
1506 case VIRTCHNL_OP_ADD_FDIR_FILTER:
1507 valid_len = sizeof(struct virtchnl_fdir_add);
1508 break;
1509 case VIRTCHNL_OP_DEL_FDIR_FILTER:
1510 valid_len = sizeof(struct virtchnl_fdir_del);
1511 break;
1512 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
1513 break;
1514 case VIRTCHNL_OP_ADD_VLAN_V2:
1515 case VIRTCHNL_OP_DEL_VLAN_V2:
1516 valid_len = sizeof(struct virtchnl_vlan_filter_list_v2);
1517 if (msglen >= valid_len) {
1518 struct virtchnl_vlan_filter_list_v2 *vfl =
1519 (struct virtchnl_vlan_filter_list_v2 *)msg;
1520
1521 valid_len += (vfl->num_elements - 1) *
1522 sizeof(struct virtchnl_vlan_filter);
1523
1524 if (vfl->num_elements == 0) {
1525 err_msg_format = true;
1526 break;
1527 }
1528 }
1529 break;
1530 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1531 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1532 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1533 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1534 valid_len = sizeof(struct virtchnl_vlan_setting);
1535 break;
1536 /* These are always errors coming from the VF. */
1537 case VIRTCHNL_OP_EVENT:
1538 case VIRTCHNL_OP_UNKNOWN:
1539 default:
1540 return VIRTCHNL_STATUS_ERR_PARAM;
1541 }
1542 /* few more checks */
1543 if (err_msg_format || valid_len != msglen)
1544 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
1545
1546 return 0;
1547 }
1548 #endif /* _VIRTCHNL_H_ */
1549