1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020
9 * This header file describes the VF-PF communication protocol used
10 * by the drivers for all devices starting from our 40G product line
12 * Admin queue buffer usage:
13 * desc->opcode is always aqc_opc_send_msg_to_pf
14 * flags, retval, datalen, and data addr are all used normally.
15 * The Firmware copies the cookie fields when sending messages between the
16 * PF and VF, but uses all other fields internally. Due to this limitation,
17 * we must send all messages as "indirect", i.e. using an external buffer.
19 * All the VSI indexes are relative to the VF. Each VF can have maximum of
20 * three VSIs. All the queue indexes are relative to the VSI. Each VF can
21 * have a maximum of sixteen queues for all of its VSIs.
23 * The PF is required to return a status code in v_retval for all messages
24 * except RESET_VF, which does not require any response. The return value
25 * is of status_code type, defined in the shared type.h.
27 * In general, VF driver initialization should roughly follow the order of
28 * these opcodes. The VF driver must first validate the API version of the
29 * PF driver, then request a reset, then get resources, then configure
30 * queues and interrupts. After these operations are complete, the VF
31 * driver may start its queues, optionally add MAC and VLAN filters, and
35 /* START GENERIC DEFINES
36 * Need to ensure the following enums and defines hold the same meaning and
37 * value in current and future projects
41 enum virtchnl_status_code {
42 VIRTCHNL_STATUS_SUCCESS = 0,
43 VIRTCHNL_STATUS_ERR_PARAM = -5,
44 VIRTCHNL_STATUS_ERR_NO_MEMORY = -18,
45 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38,
46 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39,
47 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40,
48 VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR = -53,
49 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED = -64,
52 /* Backward compatibility */
53 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
54 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
56 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT 0x0
57 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1
58 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2
59 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3
60 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4
61 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5
62 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6
63 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT 0x7
65 enum virtchnl_link_speed {
66 VIRTCHNL_LINK_SPEED_UNKNOWN = 0,
67 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
68 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
69 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
70 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
71 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
72 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
73 VIRTCHNL_LINK_SPEED_2_5GB = BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
74 VIRTCHNL_LINK_SPEED_5GB = BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
77 /* for hsplit_0 field of Rx HMC context */
78 /* deprecated with IAVF 1.0 */
79 enum virtchnl_rx_hsplit {
80 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0,
81 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1,
82 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2,
83 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
84 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8,
87 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS 6
88 /* END GENERIC DEFINES */
90 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
91 * of the virtchnl_msg structure.
94 /* The PF sends status change events to VFs using
95 * the VIRTCHNL_OP_EVENT opcode.
96 * VFs send requests to the PF using the other ops.
97 * Use of "advanced opcode" features must be negotiated as part of capabilities
98 * exchange and are not considered part of base mode feature set.
100 VIRTCHNL_OP_UNKNOWN = 0,
101 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
102 VIRTCHNL_OP_RESET_VF = 2,
103 VIRTCHNL_OP_GET_VF_RESOURCES = 3,
104 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
105 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
106 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
107 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
108 VIRTCHNL_OP_ENABLE_QUEUES = 8,
109 VIRTCHNL_OP_DISABLE_QUEUES = 9,
110 VIRTCHNL_OP_ADD_ETH_ADDR = 10,
111 VIRTCHNL_OP_DEL_ETH_ADDR = 11,
112 VIRTCHNL_OP_ADD_VLAN = 12,
113 VIRTCHNL_OP_DEL_VLAN = 13,
114 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
115 VIRTCHNL_OP_GET_STATS = 15,
116 VIRTCHNL_OP_RSVD = 16,
117 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
118 /* opcode 19 is reserved */
119 /* opcodes 20, 21, and 22 are reserved */
120 VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
121 VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
122 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
123 VIRTCHNL_OP_SET_RSS_HENA = 26,
124 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
125 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
126 VIRTCHNL_OP_REQUEST_QUEUES = 29,
127 VIRTCHNL_OP_ENABLE_CHANNELS = 30,
128 VIRTCHNL_OP_DISABLE_CHANNELS = 31,
129 VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
130 VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
131 /* opcodes 34, 35, 36, 37 and 38 are reserved */
132 VIRTCHNL_OP_DCF_CMD_DESC = 39,
133 VIRTCHNL_OP_DCF_CMD_BUFF = 40,
134 VIRTCHNL_OP_DCF_DISABLE = 41,
135 VIRTCHNL_OP_DCF_GET_VSI_MAP = 42,
138 /* These macros are used to generate compilation errors if a structure/union
139 * is not exactly the correct length. It gives a divide by zero error if the
140 * structure/union is not of the correct size, otherwise it creates an enum
141 * that is never used.
143 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
144 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
145 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
146 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
148 /* Virtual channel message descriptor. This overlays the admin queue
149 * descriptor. All other data is passed in external buffers.
152 struct virtchnl_msg {
153 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
154 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
155 enum virtchnl_status_code v_retval; /* ditto for desc->retval */
156 u32 vfid; /* used by PF when sending to VF */
159 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
161 /* Message descriptions and data structures. */
163 /* VIRTCHNL_OP_VERSION
164 * VF posts its version number to the PF. PF responds with its version number
165 * in the same format, along with a return code.
166 * Reply from PF has its major/minor versions also in param0 and param1.
167 * If there is a major version mismatch, then the VF cannot operate.
168 * If there is a minor version mismatch, then the VF can operate but should
169 * add a warning to the system log.
171 * This enum element MUST always be specified as == 1, regardless of other
172 * changes in the API. The PF must always respond to this message without
173 * error regardless of version mismatch.
175 #define VIRTCHNL_VERSION_MAJOR 1
176 #define VIRTCHNL_VERSION_MINOR 1
177 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
179 struct virtchnl_version_info {
184 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
186 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
187 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
189 /* VIRTCHNL_OP_RESET_VF
190 * VF sends this request to PF with no parameters
191 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
192 * until reset completion is indicated. The admin queue must be reinitialized
193 * after this operation.
195 * When reset is complete, PF must ensure that all queues in all VSIs associated
196 * with the VF are stopped, all queue configurations in the HMC are set to 0,
197 * and all MAC and VLAN filters (except the default MAC address) on all VSIs
201 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
202 * vsi_type should always be 6 for backward compatibility. Add other fields
205 enum virtchnl_vsi_type {
206 VIRTCHNL_VSI_TYPE_INVALID = 0,
207 VIRTCHNL_VSI_SRIOV = 6,
210 /* VIRTCHNL_OP_GET_VF_RESOURCES
211 * Version 1.0 VF sends this request to PF with no parameters
212 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
213 * PF responds with an indirect message containing
214 * virtchnl_vf_resource and one or more
215 * virtchnl_vsi_resource structures.
218 struct virtchnl_vsi_resource {
221 enum virtchnl_vsi_type vsi_type;
223 u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
226 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
228 /* VF capability flags
229 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
230 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
232 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001
233 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002
234 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004
235 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008
236 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010
237 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020
238 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040
239 #define VIRTCHNL_VF_OFFLOAD_CRC 0x00000080
240 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000
241 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000
242 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000
243 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000
244 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000
245 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000
246 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000
247 #define VIRTCHNL_VF_OFFLOAD_ADQ 0X00800000
248 #define VIRTCHNL_VF_OFFLOAD_ADQ_V2 0X01000000
249 #define VIRTCHNL_VF_OFFLOAD_USO 0X02000000
250 #define VIRTCHNL_VF_CAP_DCF 0X40000000
251 /* 0X80000000 is reserved */
253 /* Define below the capability flags that are not offloads */
254 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED 0x00000080
255 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
256 VIRTCHNL_VF_OFFLOAD_VLAN | \
257 VIRTCHNL_VF_OFFLOAD_RSS_PF)
259 struct virtchnl_vf_resource {
269 struct virtchnl_vsi_resource vsi_res[1];
272 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
274 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
275 * VF sends this message to set up parameters for one TX queue.
276 * External data buffer contains one instance of virtchnl_txq_info.
277 * PF configures requested queue and returns a status code.
280 /* Tx queue config info */
281 struct virtchnl_txq_info {
284 u16 ring_len; /* number of descriptors, multiple of 8 */
285 u16 headwb_enabled; /* deprecated with AVF 1.0 */
287 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
290 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
292 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
293 * VF sends this message to set up parameters for one RX queue.
294 * External data buffer contains one instance of virtchnl_rxq_info.
295 * PF configures requested queue and returns a status code. The
296 * crc_disable flag disables CRC stripping on the VF. Setting
297 * the crc_disable flag to 1 will disable CRC stripping for each
298 * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC
299 * offload must have been set prior to sending this info or the PF
300 * will ignore the request. This flag should be set the same for
301 * all of the queues for a VF.
304 /* Rx queue config info */
305 struct virtchnl_rxq_info {
308 u32 ring_len; /* number of descriptors, multiple of 32 */
310 u16 splithdr_enabled; /* deprecated with AVF 1.0 */
316 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
320 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
322 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
323 * VF sends this message to set parameters for active TX and RX queues
324 * associated with the specified VSI.
325 * PF configures queues and returns status.
326 * If the number of queues specified is greater than the number of queues
327 * associated with the VSI, an error is returned and no queues are configured.
328 * NOTE: The VF is not required to configure all queues in a single request.
329 * It may send multiple messages. PF drivers must correctly handle all VF
332 struct virtchnl_queue_pair_info {
333 /* NOTE: vsi_id and queue_id should be identical for both queues. */
334 struct virtchnl_txq_info txq;
335 struct virtchnl_rxq_info rxq;
338 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
340 struct virtchnl_vsi_queue_config_info {
344 struct virtchnl_queue_pair_info qpair[1];
347 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
349 /* VIRTCHNL_OP_REQUEST_QUEUES
350 * VF sends this message to request the PF to allocate additional queues to
351 * this VF. Each VF gets a guaranteed number of queues on init but asking for
352 * additional queues must be negotiated. This is a best effort request as it
353 * is possible the PF does not have enough queues left to support the request.
354 * If the PF cannot support the number requested it will respond with the
355 * maximum number it is able to support. If the request is successful, PF will
356 * then reset the VF to institute required changes.
359 /* VF resource request */
360 struct virtchnl_vf_res_request {
364 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
365 * VF uses this message to map vectors to queues.
366 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
367 * are to be associated with the specified vector.
368 * The "other" causes are always mapped to vector 0. The VF may not request
369 * that vector 0 be used for traffic.
370 * PF configures interrupt mapping and returns status.
371 * NOTE: due to hardware requirements, all active queues (both TX and RX)
372 * should be mapped to interrupts, even if the driver intends to operate
373 * only in polling mode. In this case the interrupt may be disabled, but
374 * the ITR timer will still run to trigger writebacks.
376 struct virtchnl_vector_map {
385 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
387 struct virtchnl_irq_map_info {
389 struct virtchnl_vector_map vecmap[1];
392 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
394 /* VIRTCHNL_OP_ENABLE_QUEUES
395 * VIRTCHNL_OP_DISABLE_QUEUES
396 * VF sends these message to enable or disable TX/RX queue pairs.
397 * The queues fields are bitmaps indicating which queues to act upon.
398 * (Currently, we only support 16 queues per VF, but we make the field
399 * u32 to allow for expansion.)
400 * PF performs requested action and returns status.
401 * NOTE: The VF is not required to enable/disable all queues in a single
402 * request. It may send multiple messages.
403 * PF drivers must correctly handle all VF requests.
405 struct virtchnl_queue_select {
412 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
414 /* VIRTCHNL_OP_ADD_ETH_ADDR
415 * VF sends this message in order to add one or more unicast or multicast
416 * address filters for the specified VSI.
417 * PF adds the filters and returns status.
420 /* VIRTCHNL_OP_DEL_ETH_ADDR
421 * VF sends this message in order to remove one or more unicast or multicast
422 * filters for the specified VSI.
423 * PF removes the filters and returns status.
426 struct virtchnl_ether_addr {
427 u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
431 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
433 struct virtchnl_ether_addr_list {
436 struct virtchnl_ether_addr list[1];
439 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
441 /* VIRTCHNL_OP_ADD_VLAN
442 * VF sends this message to add one or more VLAN tag filters for receives.
443 * PF adds the filters and returns status.
444 * If a port VLAN is configured by the PF, this operation will return an
448 /* VIRTCHNL_OP_DEL_VLAN
449 * VF sends this message to remove one or more VLAN tag filters for receives.
450 * PF removes the filters and returns status.
451 * If a port VLAN is configured by the PF, this operation will return an
455 struct virtchnl_vlan_filter_list {
461 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
463 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
464 * VF sends VSI id and flags.
465 * PF returns status code in retval.
466 * Note: we assume that broadcast accept mode is always enabled.
468 struct virtchnl_promisc_info {
473 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
475 #define FLAG_VF_UNICAST_PROMISC 0x00000001
476 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
478 /* VIRTCHNL_OP_GET_STATS
479 * VF sends this message to request stats for the selected VSI. VF uses
480 * the virtchnl_queue_select struct to specify the VSI. The queue_id
481 * field is ignored by the PF.
483 * PF replies with struct virtchnl_eth_stats in an external buffer.
486 struct virtchnl_eth_stats {
487 u64 rx_bytes; /* received bytes */
488 u64 rx_unicast; /* received unicast pkts */
489 u64 rx_multicast; /* received multicast pkts */
490 u64 rx_broadcast; /* received broadcast pkts */
492 u64 rx_unknown_protocol;
493 u64 tx_bytes; /* transmitted bytes */
494 u64 tx_unicast; /* transmitted unicast pkts */
495 u64 tx_multicast; /* transmitted multicast pkts */
496 u64 tx_broadcast; /* transmitted broadcast pkts */
501 /* VIRTCHNL_OP_CONFIG_RSS_KEY
502 * VIRTCHNL_OP_CONFIG_RSS_LUT
503 * VF sends these messages to configure RSS. Only supported if both PF
504 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
505 * configuration negotiation. If this is the case, then the RSS fields in
506 * the VF resource struct are valid.
507 * Both the key and LUT are initialized to 0 by the PF, meaning that
508 * RSS is effectively disabled until set up by the VF.
510 struct virtchnl_rss_key {
513 u8 key[1]; /* RSS hash key, packed bytes */
516 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
518 struct virtchnl_rss_lut {
521 u8 lut[1]; /* RSS lookup table */
524 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
526 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
527 * VIRTCHNL_OP_SET_RSS_HENA
528 * VF sends these messages to get and set the hash filter enable bits for RSS.
529 * By default, the PF sets these to all possible traffic types that the
530 * hardware supports. The VF can query this value if it wants to change the
531 * traffic types that are hashed by the hardware.
533 struct virtchnl_rss_hena {
537 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
539 /* This is used by PF driver to enforce how many channels can be supported.
540 * When ADQ_V2 capability is negotiated, it will allow 16 channels otherwise
541 * PF driver will allow only max 4 channels
543 #define VIRTCHNL_MAX_ADQ_CHANNELS 4
544 #define VIRTCHNL_MAX_ADQ_V2_CHANNELS 16
546 /* VIRTCHNL_OP_ENABLE_CHANNELS
547 * VIRTCHNL_OP_DISABLE_CHANNELS
548 * VF sends these messages to enable or disable channels based on
549 * the user specified queue count and queue offset for each traffic class.
550 * This struct encompasses all the information that the PF needs from
551 * VF to create a channel.
553 struct virtchnl_channel_info {
554 u16 count; /* number of queues in a channel */
555 u16 offset; /* queues in a channel start from 'offset' */
560 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
562 struct virtchnl_tc_info {
565 struct virtchnl_channel_info list[1];
568 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
570 /* VIRTCHNL_ADD_CLOUD_FILTER
571 * VIRTCHNL_DEL_CLOUD_FILTER
572 * VF sends these messages to add or delete a cloud filter based on the
573 * user specified match and action filters. These structures encompass
574 * all the information that the PF needs from the VF to add/delete a
578 struct virtchnl_l4_spec {
579 u8 src_mac[ETH_ALEN];
580 u8 dst_mac[ETH_ALEN];
581 /* vlan_prio is part of this 16 bit field even from OS perspective
582 * vlan_id:12 is actual vlan_id, then vlanid:bit14..12 is vlan_prio
583 * in future, when decided to offload vlan_prio, pass that information
584 * as part of the "vlan_id" field, Bit14..12
587 __be16 pad; /* reserved for future use */
594 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
596 union virtchnl_flow_spec {
597 struct virtchnl_l4_spec tcp_spec;
598 u8 buffer[128]; /* reserved for future use */
601 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
603 enum virtchnl_action {
605 VIRTCHNL_ACTION_DROP = 0,
606 VIRTCHNL_ACTION_TC_REDIRECT,
609 enum virtchnl_flow_type {
611 VIRTCHNL_TCP_V4_FLOW = 0,
612 VIRTCHNL_TCP_V6_FLOW,
613 VIRTCHNL_UDP_V4_FLOW,
614 VIRTCHNL_UDP_V6_FLOW,
617 struct virtchnl_filter {
618 union virtchnl_flow_spec data;
619 union virtchnl_flow_spec mask;
620 enum virtchnl_flow_type flow_type;
621 enum virtchnl_action action;
626 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
628 /* VIRTCHNL_OP_DCF_GET_VSI_MAP
629 * VF sends this message to get VSI mapping table.
630 * PF responds with an indirect message containing VF's
632 * The index of vf_vsi array is the logical VF ID, the
633 * value of vf_vsi array is the VF's HW VSI ID with its
634 * valid configuration.
636 struct virtchnl_dcf_vsi_map {
637 u16 pf_vsi; /* PF's HW VSI ID */
638 u16 num_vfs; /* The actual number of VFs allocated */
639 #define VIRTCHNL_DCF_VF_VSI_ID_S 0
640 #define VIRTCHNL_DCF_VF_VSI_ID_M (0xFFF << VIRTCHNL_DCF_VF_VSI_ID_S)
641 #define VIRTCHNL_DCF_VF_VSI_VALID (1 << 15)
645 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_dcf_vsi_map);
648 * PF sends this message to inform the VF driver of events that may affect it.
649 * No direct response is expected from the VF, though it may generate other
650 * messages in response to this one.
652 enum virtchnl_event_codes {
653 VIRTCHNL_EVENT_UNKNOWN = 0,
654 VIRTCHNL_EVENT_LINK_CHANGE,
655 VIRTCHNL_EVENT_RESET_IMPENDING,
656 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
657 VIRTCHNL_EVENT_DCF_VSI_MAP_UPDATE,
660 #define PF_EVENT_SEVERITY_INFO 0
661 #define PF_EVENT_SEVERITY_ATTENTION 1
662 #define PF_EVENT_SEVERITY_ACTION_REQUIRED 2
663 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
665 struct virtchnl_pf_event {
666 enum virtchnl_event_codes event;
668 /* If the PF driver does not support the new speed reporting
669 * capabilities then use link_event else use link_event_adv to
670 * get the speed and link information. The ability to understand
671 * new speeds is indicated by setting the capability flag
672 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
673 * in virtchnl_vf_resource struct and can be used to determine
674 * which link event struct to use below.
677 enum virtchnl_link_speed link_speed;
681 /* link_speed provided in Mbps */
694 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
697 /* Since VF messages are limited by u16 size, precalculate the maximum possible
698 * values of nested elements in virtchnl structures that virtual channel can
699 * possibly handle in a single message.
701 enum virtchnl_vector_limits {
702 VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX =
703 ((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) /
704 sizeof(struct virtchnl_queue_pair_info),
706 VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX =
707 ((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) /
708 sizeof(struct virtchnl_vector_map),
710 VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX =
711 ((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) /
712 sizeof(struct virtchnl_ether_addr),
714 VIRTCHNL_OP_ADD_DEL_VLAN_MAX =
715 ((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) /
719 VIRTCHNL_OP_ENABLE_CHANNELS_MAX =
720 ((u16)(~0) - sizeof(struct virtchnl_tc_info)) /
721 sizeof(struct virtchnl_channel_info),
724 /* VF reset states - these are written into the RSTAT register:
725 * VFGEN_RSTAT on the VF
726 * When the PF initiates a reset, it writes 0
727 * When the reset is complete, it writes 1
728 * When the PF detects that the VF has recovered, it writes 2
729 * VF checks this register periodically to determine if a reset has occurred,
730 * then polls it to know when the reset is complete.
731 * If either the PF or VF reads the register while the hardware
732 * is in a reset state, it will return DEADBEEF, which, when masked
735 enum virtchnl_vfr_states {
736 VIRTCHNL_VFR_INPROGRESS = 0,
737 VIRTCHNL_VFR_COMPLETED,
738 VIRTCHNL_VFR_VFACTIVE,
742 * virtchnl_vc_validate_vf_msg
743 * @ver: Virtchnl version info
744 * @v_opcode: Opcode for the message
745 * @msg: pointer to the msg buffer
746 * @msglen: msg length
748 * validate msg format against struct for each opcode
751 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
754 bool err_msg_format = false;
757 /* Validate message length. */
759 case VIRTCHNL_OP_VERSION:
760 valid_len = sizeof(struct virtchnl_version_info);
762 case VIRTCHNL_OP_RESET_VF:
764 case VIRTCHNL_OP_GET_VF_RESOURCES:
766 valid_len = sizeof(u32);
768 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
769 valid_len = sizeof(struct virtchnl_txq_info);
771 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
772 valid_len = sizeof(struct virtchnl_rxq_info);
774 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
775 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
776 if (msglen >= valid_len) {
777 struct virtchnl_vsi_queue_config_info *vqc =
778 (struct virtchnl_vsi_queue_config_info *)msg;
780 if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs >
781 VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) {
782 err_msg_format = true;
786 valid_len += (vqc->num_queue_pairs *
788 virtchnl_queue_pair_info));
791 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
792 valid_len = sizeof(struct virtchnl_irq_map_info);
793 if (msglen >= valid_len) {
794 struct virtchnl_irq_map_info *vimi =
795 (struct virtchnl_irq_map_info *)msg;
797 if (vimi->num_vectors == 0 || vimi->num_vectors >
798 VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) {
799 err_msg_format = true;
803 valid_len += (vimi->num_vectors *
804 sizeof(struct virtchnl_vector_map));
807 case VIRTCHNL_OP_ENABLE_QUEUES:
808 case VIRTCHNL_OP_DISABLE_QUEUES:
809 valid_len = sizeof(struct virtchnl_queue_select);
811 case VIRTCHNL_OP_ADD_ETH_ADDR:
812 case VIRTCHNL_OP_DEL_ETH_ADDR:
813 valid_len = sizeof(struct virtchnl_ether_addr_list);
814 if (msglen >= valid_len) {
815 struct virtchnl_ether_addr_list *veal =
816 (struct virtchnl_ether_addr_list *)msg;
818 if (veal->num_elements == 0 || veal->num_elements >
819 VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) {
820 err_msg_format = true;
824 valid_len += veal->num_elements *
825 sizeof(struct virtchnl_ether_addr);
828 case VIRTCHNL_OP_ADD_VLAN:
829 case VIRTCHNL_OP_DEL_VLAN:
830 valid_len = sizeof(struct virtchnl_vlan_filter_list);
831 if (msglen >= valid_len) {
832 struct virtchnl_vlan_filter_list *vfl =
833 (struct virtchnl_vlan_filter_list *)msg;
835 if (vfl->num_elements == 0 || vfl->num_elements >
836 VIRTCHNL_OP_ADD_DEL_VLAN_MAX) {
837 err_msg_format = true;
841 valid_len += vfl->num_elements * sizeof(u16);
844 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
845 valid_len = sizeof(struct virtchnl_promisc_info);
847 case VIRTCHNL_OP_GET_STATS:
848 valid_len = sizeof(struct virtchnl_queue_select);
850 case VIRTCHNL_OP_CONFIG_RSS_KEY:
851 valid_len = sizeof(struct virtchnl_rss_key);
852 if (msglen >= valid_len) {
853 struct virtchnl_rss_key *vrk =
854 (struct virtchnl_rss_key *)msg;
856 if (vrk->key_len == 0) {
857 /* zero length is allowed as input */
861 valid_len += vrk->key_len - 1;
864 case VIRTCHNL_OP_CONFIG_RSS_LUT:
865 valid_len = sizeof(struct virtchnl_rss_lut);
866 if (msglen >= valid_len) {
867 struct virtchnl_rss_lut *vrl =
868 (struct virtchnl_rss_lut *)msg;
870 if (vrl->lut_entries == 0) {
871 /* zero entries is allowed as input */
875 valid_len += vrl->lut_entries - 1;
878 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
880 case VIRTCHNL_OP_SET_RSS_HENA:
881 valid_len = sizeof(struct virtchnl_rss_hena);
883 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
884 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
886 case VIRTCHNL_OP_REQUEST_QUEUES:
887 valid_len = sizeof(struct virtchnl_vf_res_request);
889 case VIRTCHNL_OP_ENABLE_CHANNELS:
890 valid_len = sizeof(struct virtchnl_tc_info);
891 if (msglen >= valid_len) {
892 struct virtchnl_tc_info *vti =
893 (struct virtchnl_tc_info *)msg;
895 if (vti->num_tc == 0 || vti->num_tc >
896 VIRTCHNL_OP_ENABLE_CHANNELS_MAX) {
897 err_msg_format = true;
901 valid_len += (vti->num_tc - 1) *
902 sizeof(struct virtchnl_channel_info);
905 case VIRTCHNL_OP_DISABLE_CHANNELS:
907 case VIRTCHNL_OP_ADD_CLOUD_FILTER:
908 case VIRTCHNL_OP_DEL_CLOUD_FILTER:
909 valid_len = sizeof(struct virtchnl_filter);
911 case VIRTCHNL_OP_DCF_CMD_DESC:
912 case VIRTCHNL_OP_DCF_CMD_BUFF:
913 /* These two opcodes are specific to handle the AdminQ command,
914 * so the validation needs to be done in PF's context.
917 case VIRTCHNL_OP_DCF_DISABLE:
918 case VIRTCHNL_OP_DCF_GET_VSI_MAP:
919 /* The two opcodes are required by DCF without message buffer,
920 * so the valid length keeps the default value 0.
923 /* These are always errors coming from the VF. */
924 case VIRTCHNL_OP_EVENT:
925 case VIRTCHNL_OP_UNKNOWN:
927 return VIRTCHNL_STATUS_ERR_PARAM;
929 /* few more checks */
930 if (err_msg_format || valid_len != msglen)
931 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
935 #endif /* _VIRTCHNL_H_ */