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

source code of linux/include/linux/avf/virtchnl.h