1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*******************************************************************************
4 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
5 * Copyright(c) 2013 - 2014 Intel Corporation.
8 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
9 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
11 ******************************************************************************/
17 * This header file describes the VF-PF communication protocol used
18 * by the drivers for all devices starting from our 40G product line
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.
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.
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.
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
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
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,
60 /* Backward compatibility */
61 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
62 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
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
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),
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,
95 /* END GENERIC DEFINES */
97 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
98 * of the virtchnl_msg structure.
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.
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,
147 /* These macros are used to generate compilation errors if a structure/union
148 * is not exactly the correct length. It gives a divide by zero error if the
149 * structure/union is not of the correct size, otherwise it creates an enum
150 * that is never used.
152 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
153 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
154 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
155 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
157 /* Virtual channel message descriptor. This overlays the admin queue
158 * descriptor. All other data is passed in external buffers.
161 struct virtchnl_msg {
162 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
163 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
164 enum virtchnl_status_code v_retval; /* ditto for desc->retval */
165 u32 vfid; /* used by PF when sending to VF */
168 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
170 /* Message descriptions and data structures. */
172 /* VIRTCHNL_OP_VERSION
173 * VF posts its version number to the PF. PF responds with its version number
174 * in the same format, along with a return code.
175 * Reply from PF has its major/minor versions also in param0 and param1.
176 * If there is a major version mismatch, then the VF cannot operate.
177 * If there is a minor version mismatch, then the VF can operate but should
178 * add a warning to the system log.
180 * This enum element MUST always be specified as == 1, regardless of other
181 * changes in the API. The PF must always respond to this message without
182 * error regardless of version mismatch.
184 #define VIRTCHNL_VERSION_MAJOR 1
185 #define VIRTCHNL_VERSION_MINOR 1
186 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
188 struct virtchnl_version_info {
193 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
195 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
196 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
198 /* VIRTCHNL_OP_RESET_VF
199 * VF sends this request to PF with no parameters
200 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
201 * until reset completion is indicated. The admin queue must be reinitialized
202 * after this operation.
204 * When reset is complete, PF must ensure that all queues in all VSIs associated
205 * with the VF are stopped, all queue configurations in the HMC are set to 0,
206 * and all MAC and VLAN filters (except the default MAC address) on all VSIs
210 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
211 * vsi_type should always be 6 for backward compatibility. Add other fields
214 enum virtchnl_vsi_type {
215 VIRTCHNL_VSI_TYPE_INVALID = 0,
216 VIRTCHNL_VSI_SRIOV = 6,
219 /* VIRTCHNL_OP_GET_VF_RESOURCES
220 * Version 1.0 VF sends this request to PF with no parameters
221 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
222 * PF responds with an indirect message containing
223 * virtchnl_vf_resource and one or more
224 * virtchnl_vsi_resource structures.
227 struct virtchnl_vsi_resource {
230 enum virtchnl_vsi_type vsi_type;
232 u8 default_mac_addr[ETH_ALEN];
235 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
237 /* VF capability flags
238 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
239 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
241 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001
242 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002
243 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004
244 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008
245 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010
246 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020
247 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040
248 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000
249 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000
250 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000
251 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000
252 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000
253 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000
254 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000
255 #define VIRTCHNL_VF_OFFLOAD_ADQ 0X00800000
256 #define VIRTCHNL_VF_OFFLOAD_USO 0X02000000
257 #define VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF 0X08000000
258 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF 0X10000000
260 /* Define below the capability flags that are not offloads */
261 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED 0x00000080
262 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
263 VIRTCHNL_VF_OFFLOAD_VLAN | \
264 VIRTCHNL_VF_OFFLOAD_RSS_PF)
266 struct virtchnl_vf_resource {
276 struct virtchnl_vsi_resource vsi_res[1];
279 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
281 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
282 * VF sends this message to set up parameters for one TX queue.
283 * External data buffer contains one instance of virtchnl_txq_info.
284 * PF configures requested queue and returns a status code.
287 /* Tx queue config info */
288 struct virtchnl_txq_info {
291 u16 ring_len; /* number of descriptors, multiple of 8 */
292 u16 headwb_enabled; /* deprecated with AVF 1.0 */
294 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
297 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
299 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
300 * VF sends this message to set up parameters for one RX queue.
301 * External data buffer contains one instance of virtchnl_rxq_info.
302 * PF configures requested queue and returns a status code.
305 /* Rx queue config info */
306 struct virtchnl_rxq_info {
309 u32 ring_len; /* number of descriptors, multiple of 32 */
311 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 all 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.
329 struct virtchnl_queue_pair_info {
330 /* NOTE: vsi_id and queue_id should be identical for both queues. */
331 struct virtchnl_txq_info txq;
332 struct virtchnl_rxq_info rxq;
335 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
337 struct virtchnl_vsi_queue_config_info {
341 struct virtchnl_queue_pair_info qpair[1];
344 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
346 /* VIRTCHNL_OP_REQUEST_QUEUES
347 * VF sends this message to request the PF to allocate additional queues to
348 * this VF. Each VF gets a guaranteed number of queues on init but asking for
349 * additional queues must be negotiated. This is a best effort request as it
350 * is possible the PF does not have enough queues left to support the request.
351 * If the PF cannot support the number requested it will respond with the
352 * maximum number it is able to support. If the request is successful, PF will
353 * then reset the VF to institute required changes.
356 /* VF resource request */
357 struct virtchnl_vf_res_request {
361 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
362 * VF uses this message to map vectors to queues.
363 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
364 * are to be associated with the specified vector.
365 * The "other" causes are always mapped to vector 0.
366 * PF configures interrupt mapping and returns status.
368 struct virtchnl_vector_map {
377 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
379 struct virtchnl_irq_map_info {
381 struct virtchnl_vector_map vecmap[1];
384 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
386 /* VIRTCHNL_OP_ENABLE_QUEUES
387 * VIRTCHNL_OP_DISABLE_QUEUES
388 * VF sends these message to enable or disable TX/RX queue pairs.
389 * The queues fields are bitmaps indicating which queues to act upon.
390 * (Currently, we only support 16 queues per VF, but we make the field
391 * u32 to allow for expansion.)
392 * PF performs requested action and returns status.
394 struct virtchnl_queue_select {
401 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
403 /* VIRTCHNL_OP_ADD_ETH_ADDR
404 * VF sends this message in order to add one or more unicast or multicast
405 * address filters for the specified VSI.
406 * PF adds the filters and returns status.
409 /* VIRTCHNL_OP_DEL_ETH_ADDR
410 * VF sends this message in order to remove one or more unicast or multicast
411 * filters for the specified VSI.
412 * PF removes the filters and returns status.
415 struct virtchnl_ether_addr {
420 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
422 struct virtchnl_ether_addr_list {
425 struct virtchnl_ether_addr list[1];
428 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
430 /* VIRTCHNL_OP_ADD_VLAN
431 * VF sends this message to add one or more VLAN tag filters for receives.
432 * PF adds the filters and returns status.
433 * If a port VLAN is configured by the PF, this operation will return an
437 /* VIRTCHNL_OP_DEL_VLAN
438 * VF sends this message to remove one or more VLAN tag filters for receives.
439 * PF removes the filters and returns status.
440 * If a port VLAN is configured by the PF, this operation will return an
444 struct virtchnl_vlan_filter_list {
450 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
452 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
453 * VF sends VSI id and flags.
454 * PF returns status code in retval.
455 * Note: we assume that broadcast accept mode is always enabled.
457 struct virtchnl_promisc_info {
462 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
464 #define FLAG_VF_UNICAST_PROMISC 0x00000001
465 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
467 /* VIRTCHNL_OP_GET_STATS
468 * VF sends this message to request stats for the selected VSI. VF uses
469 * the virtchnl_queue_select struct to specify the VSI. The queue_id
470 * field is ignored by the PF.
472 * PF replies with struct eth_stats in an external buffer.
475 /* VIRTCHNL_OP_CONFIG_RSS_KEY
476 * VIRTCHNL_OP_CONFIG_RSS_LUT
477 * VF sends these messages to configure RSS. Only supported if both PF
478 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
479 * configuration negotiation. If this is the case, then the RSS fields in
480 * the VF resource struct are valid.
481 * Both the key and LUT are initialized to 0 by the PF, meaning that
482 * RSS is effectively disabled until set up by the VF.
484 struct virtchnl_rss_key {
487 u8 key[1]; /* RSS hash key, packed bytes */
490 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
492 struct virtchnl_rss_lut {
495 u8 lut[1]; /* RSS lookup table */
498 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
500 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
501 * VIRTCHNL_OP_SET_RSS_HENA
502 * VF sends these messages to get and set the hash filter enable bits for RSS.
503 * By default, the PF sets these to all possible traffic types that the
504 * hardware supports. The VF can query this value if it wants to change the
505 * traffic types that are hashed by the hardware.
507 struct virtchnl_rss_hena {
511 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
513 /* VIRTCHNL_OP_ENABLE_CHANNELS
514 * VIRTCHNL_OP_DISABLE_CHANNELS
515 * VF sends these messages to enable or disable channels based on
516 * the user specified queue count and queue offset for each traffic class.
517 * This struct encompasses all the information that the PF needs from
518 * VF to create a channel.
520 struct virtchnl_channel_info {
521 u16 count; /* number of queues in a channel */
522 u16 offset; /* queues in a channel start from 'offset' */
527 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
529 struct virtchnl_tc_info {
532 struct virtchnl_channel_info list[1];
535 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
537 /* VIRTCHNL_ADD_CLOUD_FILTER
538 * VIRTCHNL_DEL_CLOUD_FILTER
539 * VF sends these messages to add or delete a cloud filter based on the
540 * user specified match and action filters. These structures encompass
541 * all the information that the PF needs from the VF to add/delete a
545 struct virtchnl_l4_spec {
546 u8 src_mac[ETH_ALEN];
547 u8 dst_mac[ETH_ALEN];
549 __be16 pad; /* reserved for future use */
556 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
558 union virtchnl_flow_spec {
559 struct virtchnl_l4_spec tcp_spec;
560 u8 buffer[128]; /* reserved for future use */
563 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
565 enum virtchnl_action {
567 VIRTCHNL_ACTION_DROP = 0,
568 VIRTCHNL_ACTION_TC_REDIRECT,
569 VIRTCHNL_ACTION_PASSTHRU,
570 VIRTCHNL_ACTION_QUEUE,
571 VIRTCHNL_ACTION_Q_REGION,
572 VIRTCHNL_ACTION_MARK,
573 VIRTCHNL_ACTION_COUNT,
576 enum virtchnl_flow_type {
578 VIRTCHNL_TCP_V4_FLOW = 0,
579 VIRTCHNL_TCP_V6_FLOW,
582 struct virtchnl_filter {
583 union virtchnl_flow_spec data;
584 union virtchnl_flow_spec mask;
585 enum virtchnl_flow_type flow_type;
586 enum virtchnl_action action;
592 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
595 * PF sends this message to inform the VF driver of events that may affect it.
596 * No direct response is expected from the VF, though it may generate other
597 * messages in response to this one.
599 enum virtchnl_event_codes {
600 VIRTCHNL_EVENT_UNKNOWN = 0,
601 VIRTCHNL_EVENT_LINK_CHANGE,
602 VIRTCHNL_EVENT_RESET_IMPENDING,
603 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
606 #define PF_EVENT_SEVERITY_INFO 0
607 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
609 struct virtchnl_pf_event {
610 enum virtchnl_event_codes event;
612 /* If the PF driver does not support the new speed reporting
613 * capabilities then use link_event else use link_event_adv to
614 * get the speed and link information. The ability to understand
615 * new speeds is indicated by setting the capability flag
616 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
617 * in virtchnl_vf_resource struct and can be used to determine
618 * which link event struct to use below.
621 enum virtchnl_link_speed link_speed;
625 /* link_speed provided in Mbps */
635 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
637 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
638 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
639 * The request for this originates from the VF IWARP driver through
640 * a client interface between VF LAN and VF IWARP driver.
641 * A vector could have an AEQ and CEQ attached to it although
642 * there is a single AEQ per VF IWARP instance in which case
643 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
644 * There will never be a case where there will be multiple CEQs attached
645 * to a single vector.
646 * PF configures interrupt mapping and returns status.
649 struct virtchnl_iwarp_qv_info {
650 u32 v_idx; /* msix_vector */
657 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
659 struct virtchnl_iwarp_qvlist_info {
661 struct virtchnl_iwarp_qv_info qv_info[1];
664 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
666 /* VF reset states - these are written into the RSTAT register:
667 * VFGEN_RSTAT on the VF
668 * When the PF initiates a reset, it writes 0
669 * When the reset is complete, it writes 1
670 * When the PF detects that the VF has recovered, it writes 2
671 * VF checks this register periodically to determine if a reset has occurred,
672 * then polls it to know when the reset is complete.
673 * If either the PF or VF reads the register while the hardware
674 * is in a reset state, it will return DEADBEEF, which, when masked
677 enum virtchnl_vfr_states {
678 VIRTCHNL_VFR_INPROGRESS = 0,
679 VIRTCHNL_VFR_COMPLETED,
680 VIRTCHNL_VFR_VFACTIVE,
683 /* Type of RSS algorithm */
684 enum virtchnl_rss_algorithm {
685 VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0,
686 VIRTCHNL_RSS_ALG_R_ASYMMETRIC = 1,
687 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2,
688 VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3,
691 #define VIRTCHNL_MAX_NUM_PROTO_HDRS 32
692 #define PROTO_HDR_SHIFT 5
693 #define PROTO_HDR_FIELD_START(proto_hdr_type) ((proto_hdr_type) << PROTO_HDR_SHIFT)
694 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1)
696 /* VF use these macros to configure each protocol header.
697 * Specify which protocol headers and protocol header fields base on
698 * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field.
699 * @param hdr: a struct of virtchnl_proto_hdr
700 * @param hdr_type: ETH/IPV4/TCP, etc
701 * @param field: SRC/DST/TEID/SPI, etc
703 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field) \
704 ((hdr)->field_selector |= BIT((field) & PROTO_HDR_FIELD_MASK))
705 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field) \
706 ((hdr)->field_selector &= ~BIT((field) & PROTO_HDR_FIELD_MASK))
707 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val) \
708 ((hdr)->field_selector & BIT((val) & PROTO_HDR_FIELD_MASK))
709 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr) ((hdr)->field_selector)
711 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
712 (VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, \
713 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
714 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
715 (VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, \
716 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
718 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type) \
719 ((hdr)->type = VIRTCHNL_PROTO_HDR_ ## hdr_type)
720 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \
721 (((hdr)->type) >> PROTO_HDR_SHIFT)
722 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \
723 ((hdr)->type == ((val) >> PROTO_HDR_SHIFT))
724 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \
725 (VIRTCHNL_TEST_PROTO_HDR_TYPE((hdr), (val)) && \
726 VIRTCHNL_TEST_PROTO_HDR_FIELD((hdr), (val)))
728 /* Protocol header type within a packet segment. A segment consists of one or
729 * more protocol headers that make up a logical group of protocol headers. Each
730 * logical group of protocol headers encapsulates or is encapsulated using/by
731 * tunneling or encapsulation protocols for network virtualization.
733 enum virtchnl_proto_hdr_type {
734 VIRTCHNL_PROTO_HDR_NONE,
735 VIRTCHNL_PROTO_HDR_ETH,
736 VIRTCHNL_PROTO_HDR_S_VLAN,
737 VIRTCHNL_PROTO_HDR_C_VLAN,
738 VIRTCHNL_PROTO_HDR_IPV4,
739 VIRTCHNL_PROTO_HDR_IPV6,
740 VIRTCHNL_PROTO_HDR_TCP,
741 VIRTCHNL_PROTO_HDR_UDP,
742 VIRTCHNL_PROTO_HDR_SCTP,
743 VIRTCHNL_PROTO_HDR_GTPU_IP,
744 VIRTCHNL_PROTO_HDR_GTPU_EH,
745 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
746 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
747 VIRTCHNL_PROTO_HDR_PPPOE,
748 VIRTCHNL_PROTO_HDR_L2TPV3,
749 VIRTCHNL_PROTO_HDR_ESP,
750 VIRTCHNL_PROTO_HDR_AH,
751 VIRTCHNL_PROTO_HDR_PFCP,
754 /* Protocol header field within a protocol header. */
755 enum virtchnl_proto_hdr_field {
757 VIRTCHNL_PROTO_HDR_ETH_SRC =
758 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ETH),
759 VIRTCHNL_PROTO_HDR_ETH_DST,
760 VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
762 VIRTCHNL_PROTO_HDR_S_VLAN_ID =
763 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_S_VLAN),
765 VIRTCHNL_PROTO_HDR_C_VLAN_ID =
766 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_C_VLAN),
768 VIRTCHNL_PROTO_HDR_IPV4_SRC =
769 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4),
770 VIRTCHNL_PROTO_HDR_IPV4_DST,
771 VIRTCHNL_PROTO_HDR_IPV4_DSCP,
772 VIRTCHNL_PROTO_HDR_IPV4_TTL,
773 VIRTCHNL_PROTO_HDR_IPV4_PROT,
775 VIRTCHNL_PROTO_HDR_IPV6_SRC =
776 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6),
777 VIRTCHNL_PROTO_HDR_IPV6_DST,
778 VIRTCHNL_PROTO_HDR_IPV6_TC,
779 VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
780 VIRTCHNL_PROTO_HDR_IPV6_PROT,
782 VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
783 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_TCP),
784 VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
786 VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
787 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_UDP),
788 VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
790 VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
791 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_SCTP),
792 VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
794 VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
795 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_IP),
797 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
798 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH),
799 VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
801 VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
802 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PPPOE),
804 VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
805 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV3),
807 VIRTCHNL_PROTO_HDR_ESP_SPI =
808 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ESP),
810 VIRTCHNL_PROTO_HDR_AH_SPI =
811 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_AH),
813 VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
814 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PFCP),
815 VIRTCHNL_PROTO_HDR_PFCP_SEID,
818 struct virtchnl_proto_hdr {
819 enum virtchnl_proto_hdr_type type;
820 u32 field_selector; /* a bit mask to select field for header type */
823 * binary buffer in network order for specific header type.
824 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
825 * header is expected to be copied into the buffer.
829 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr);
831 struct virtchnl_proto_hdrs {
835 * specify where protocol header start from.
836 * 0 - from the outer layer
837 * 1 - from the first inner layer
838 * 2 - from the second inner layer
841 int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */
842 struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
845 VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs);
847 struct virtchnl_rss_cfg {
848 struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */
849 enum virtchnl_rss_algorithm rss_algorithm; /* RSS algorithm type */
850 u8 reserved[128]; /* reserve for future */
853 VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg);
855 /* action configuration for FDIR */
856 struct virtchnl_filter_action {
857 enum virtchnl_action type;
859 /* used for queue and qgroup action */
864 /* used for count action */
866 /* share counter ID with other flow rules */
868 u32 id; /* counter ID */
870 /* used for mark action */
876 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action);
878 #define VIRTCHNL_MAX_NUM_ACTIONS 8
880 struct virtchnl_filter_action_set {
881 /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
883 struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
886 VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set);
888 /* pattern and action for FDIR rule */
889 struct virtchnl_fdir_rule {
890 struct virtchnl_proto_hdrs proto_hdrs;
891 struct virtchnl_filter_action_set action_set;
894 VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule);
896 /* Status returned to VF after VF requests FDIR commands
897 * VIRTCHNL_FDIR_SUCCESS
898 * VF FDIR related request is successfully done by PF
899 * The request can be OP_ADD/DEL.
901 * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
902 * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
904 * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
905 * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
907 * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
908 * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
910 * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
911 * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
913 * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
914 * OP_ADD_FDIR_FILTER request is failed due to parameters validation
915 * or HW doesn't support.
917 * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
918 * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
921 enum virtchnl_fdir_prgm_status {
922 VIRTCHNL_FDIR_SUCCESS = 0,
923 VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
924 VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
925 VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
926 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
927 VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
928 VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
931 /* VIRTCHNL_OP_ADD_FDIR_FILTER
932 * VF sends this request to PF by filling out vsi_id,
933 * validate_only and rule_cfg. PF will return flow_id
934 * if the request is successfully done and return add_status to VF.
936 struct virtchnl_fdir_add {
937 u16 vsi_id; /* INPUT */
939 * 1 for validating a fdir rule, 0 for creating a fdir rule.
940 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
942 u16 validate_only; /* INPUT */
943 u32 flow_id; /* OUTPUT */
944 struct virtchnl_fdir_rule rule_cfg; /* INPUT */
945 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
948 VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add);
950 /* VIRTCHNL_OP_DEL_FDIR_FILTER
951 * VF sends this request to PF by filling out vsi_id
952 * and flow_id. PF will return del_status to VF.
954 struct virtchnl_fdir_del {
955 u16 vsi_id; /* INPUT */
957 u32 flow_id; /* INPUT */
958 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
961 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del);
964 * virtchnl_vc_validate_vf_msg
965 * @ver: Virtchnl version info
966 * @v_opcode: Opcode for the message
967 * @msg: pointer to the msg buffer
968 * @msglen: msg length
970 * validate msg format against struct for each opcode
973 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
976 bool err_msg_format = false;
979 /* Validate message length. */
981 case VIRTCHNL_OP_VERSION:
982 valid_len = sizeof(struct virtchnl_version_info);
984 case VIRTCHNL_OP_RESET_VF:
986 case VIRTCHNL_OP_GET_VF_RESOURCES:
988 valid_len = sizeof(u32);
990 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
991 valid_len = sizeof(struct virtchnl_txq_info);
993 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
994 valid_len = sizeof(struct virtchnl_rxq_info);
996 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
997 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
998 if (msglen >= valid_len) {
999 struct virtchnl_vsi_queue_config_info *vqc =
1000 (struct virtchnl_vsi_queue_config_info *)msg;
1001 valid_len += (vqc->num_queue_pairs *
1003 virtchnl_queue_pair_info));
1004 if (vqc->num_queue_pairs == 0)
1005 err_msg_format = true;
1008 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1009 valid_len = sizeof(struct virtchnl_irq_map_info);
1010 if (msglen >= valid_len) {
1011 struct virtchnl_irq_map_info *vimi =
1012 (struct virtchnl_irq_map_info *)msg;
1013 valid_len += (vimi->num_vectors *
1014 sizeof(struct virtchnl_vector_map));
1015 if (vimi->num_vectors == 0)
1016 err_msg_format = true;
1019 case VIRTCHNL_OP_ENABLE_QUEUES:
1020 case VIRTCHNL_OP_DISABLE_QUEUES:
1021 valid_len = sizeof(struct virtchnl_queue_select);
1023 case VIRTCHNL_OP_ADD_ETH_ADDR:
1024 case VIRTCHNL_OP_DEL_ETH_ADDR:
1025 valid_len = sizeof(struct virtchnl_ether_addr_list);
1026 if (msglen >= valid_len) {
1027 struct virtchnl_ether_addr_list *veal =
1028 (struct virtchnl_ether_addr_list *)msg;
1029 valid_len += veal->num_elements *
1030 sizeof(struct virtchnl_ether_addr);
1031 if (veal->num_elements == 0)
1032 err_msg_format = true;
1035 case VIRTCHNL_OP_ADD_VLAN:
1036 case VIRTCHNL_OP_DEL_VLAN:
1037 valid_len = sizeof(struct virtchnl_vlan_filter_list);
1038 if (msglen >= valid_len) {
1039 struct virtchnl_vlan_filter_list *vfl =
1040 (struct virtchnl_vlan_filter_list *)msg;
1041 valid_len += vfl->num_elements * sizeof(u16);
1042 if (vfl->num_elements == 0)
1043 err_msg_format = true;
1046 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1047 valid_len = sizeof(struct virtchnl_promisc_info);
1049 case VIRTCHNL_OP_GET_STATS:
1050 valid_len = sizeof(struct virtchnl_queue_select);
1052 case VIRTCHNL_OP_IWARP:
1053 /* These messages are opaque to us and will be validated in
1054 * the RDMA client code. We just need to check for nonzero
1055 * length. The firmware will enforce max length restrictions.
1060 err_msg_format = true;
1062 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
1064 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1065 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
1066 if (msglen >= valid_len) {
1067 struct virtchnl_iwarp_qvlist_info *qv =
1068 (struct virtchnl_iwarp_qvlist_info *)msg;
1069 if (qv->num_vectors == 0) {
1070 err_msg_format = true;
1073 valid_len += ((qv->num_vectors - 1) *
1074 sizeof(struct virtchnl_iwarp_qv_info));
1077 case VIRTCHNL_OP_CONFIG_RSS_KEY:
1078 valid_len = sizeof(struct virtchnl_rss_key);
1079 if (msglen >= valid_len) {
1080 struct virtchnl_rss_key *vrk =
1081 (struct virtchnl_rss_key *)msg;
1082 valid_len += vrk->key_len - 1;
1085 case VIRTCHNL_OP_CONFIG_RSS_LUT:
1086 valid_len = sizeof(struct virtchnl_rss_lut);
1087 if (msglen >= valid_len) {
1088 struct virtchnl_rss_lut *vrl =
1089 (struct virtchnl_rss_lut *)msg;
1090 valid_len += vrl->lut_entries - 1;
1093 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
1095 case VIRTCHNL_OP_SET_RSS_HENA:
1096 valid_len = sizeof(struct virtchnl_rss_hena);
1098 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1099 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1101 case VIRTCHNL_OP_REQUEST_QUEUES:
1102 valid_len = sizeof(struct virtchnl_vf_res_request);
1104 case VIRTCHNL_OP_ENABLE_CHANNELS:
1105 valid_len = sizeof(struct virtchnl_tc_info);
1106 if (msglen >= valid_len) {
1107 struct virtchnl_tc_info *vti =
1108 (struct virtchnl_tc_info *)msg;
1109 valid_len += (vti->num_tc - 1) *
1110 sizeof(struct virtchnl_channel_info);
1111 if (vti->num_tc == 0)
1112 err_msg_format = true;
1115 case VIRTCHNL_OP_DISABLE_CHANNELS:
1117 case VIRTCHNL_OP_ADD_CLOUD_FILTER:
1118 valid_len = sizeof(struct virtchnl_filter);
1120 case VIRTCHNL_OP_DEL_CLOUD_FILTER:
1121 valid_len = sizeof(struct virtchnl_filter);
1123 case VIRTCHNL_OP_ADD_RSS_CFG:
1124 case VIRTCHNL_OP_DEL_RSS_CFG:
1125 valid_len = sizeof(struct virtchnl_rss_cfg);
1127 case VIRTCHNL_OP_ADD_FDIR_FILTER:
1128 valid_len = sizeof(struct virtchnl_fdir_add);
1130 case VIRTCHNL_OP_DEL_FDIR_FILTER:
1131 valid_len = sizeof(struct virtchnl_fdir_del);
1133 /* These are always errors coming from the VF. */
1134 case VIRTCHNL_OP_EVENT:
1135 case VIRTCHNL_OP_UNKNOWN:
1137 return VIRTCHNL_STATUS_ERR_PARAM;
1139 /* few more checks */
1140 if (err_msg_format || valid_len != msglen)
1141 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
1145 #endif /* _VIRTCHNL_H_ */