1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2013 - 2015 Intel Corporation
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_ERR_PARAM = -5,
44 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38,
45 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39,
46 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40,
47 VIRTCHNL_STATUS_NOT_SUPPORTED = -64,
50 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1
51 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2
52 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3
53 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4
54 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5
55 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6
57 enum virtchnl_link_speed {
58 VIRTCHNL_LINK_SPEED_UNKNOWN = 0,
59 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
60 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
61 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
62 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
63 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
64 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
67 /* for hsplit_0 field of Rx HMC context */
68 /* deprecated with IAVF 1.0 */
69 enum virtchnl_rx_hsplit {
70 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0,
71 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1,
72 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2,
73 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
74 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8,
77 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS 6
78 /* END GENERIC DEFINES */
80 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
81 * of the virtchnl_msg structure.
84 /* The PF sends status change events to VFs using
85 * the VIRTCHNL_OP_EVENT opcode.
86 * VFs send requests to the PF using the other ops.
87 * Use of "advanced opcode" features must be negotiated as part of capabilities
88 * exchange and are not considered part of base mode feature set.
90 VIRTCHNL_OP_UNKNOWN = 0,
91 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
92 VIRTCHNL_OP_RESET_VF = 2,
93 VIRTCHNL_OP_GET_VF_RESOURCES = 3,
94 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
95 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
96 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
97 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
98 VIRTCHNL_OP_ENABLE_QUEUES = 8,
99 VIRTCHNL_OP_DISABLE_QUEUES = 9,
100 VIRTCHNL_OP_ADD_ETH_ADDR = 10,
101 VIRTCHNL_OP_DEL_ETH_ADDR = 11,
102 VIRTCHNL_OP_ADD_VLAN = 12,
103 VIRTCHNL_OP_DEL_VLAN = 13,
104 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
105 VIRTCHNL_OP_GET_STATS = 15,
106 VIRTCHNL_OP_RSVD = 16,
107 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
108 #ifdef VIRTCHNL_SOL_VF_SUPPORT
109 VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG = 19,
111 #ifdef VIRTCHNL_IWARP
112 VIRTCHNL_OP_IWARP = 20, /* advanced opcode */
113 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
114 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
116 VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
117 VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
118 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
119 VIRTCHNL_OP_SET_RSS_HENA = 26,
120 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
121 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
122 VIRTCHNL_OP_REQUEST_QUEUES = 29,
126 /* This macro is used to generate a compilation error if a structure
127 * is not exactly the correct length. It gives a divide by zero error if the
128 * structure is not of the correct size, otherwise it creates an enum that is
131 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
132 {virtchnl_static_assert_##X = (n) / ((sizeof(struct X) == (n)) ? 1 : 0)}
134 /* Virtual channel message descriptor. This overlays the admin queue
135 * descriptor. All other data is passed in external buffers.
138 struct virtchnl_msg {
139 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
140 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
141 enum virtchnl_status_code v_retval; /* ditto for desc->retval */
142 u32 vfid; /* used by PF when sending to VF */
145 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
147 /* Message descriptions and data structures.*/
149 /* VIRTCHNL_OP_VERSION
150 * VF posts its version number to the PF. PF responds with its version number
151 * in the same format, along with a return code.
152 * Reply from PF has its major/minor versions also in param0 and param1.
153 * If there is a major version mismatch, then the VF cannot operate.
154 * If there is a minor version mismatch, then the VF can operate but should
155 * add a warning to the system log.
157 * This enum element MUST always be specified as == 1, regardless of other
158 * changes in the API. The PF must always respond to this message without
159 * error regardless of version mismatch.
161 #define VIRTCHNL_VERSION_MAJOR 1
162 #define VIRTCHNL_VERSION_MINOR 1
163 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
165 struct virtchnl_version_info {
170 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
172 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
173 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
175 /* VIRTCHNL_OP_RESET_VF
176 * VF sends this request to PF with no parameters
177 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
178 * until reset completion is indicated. The admin queue must be reinitialized
179 * after this operation.
181 * When reset is complete, PF must ensure that all queues in all VSIs associated
182 * with the VF are stopped, all queue configurations in the HMC are set to 0,
183 * and all MAC and VLAN filters (except the default MAC address) on all VSIs
187 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
188 * vsi_type should always be 6 for backward compatibility. Add other fields
191 enum virtchnl_vsi_type {
192 VIRTCHNL_VSI_TYPE_INVALID = 0,
193 VIRTCHNL_VSI_SRIOV = 6,
196 /* VIRTCHNL_OP_GET_VF_RESOURCES
197 * Version 1.0 VF sends this request to PF with no parameters
198 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
199 * PF responds with an indirect message containing
200 * virtchnl_vf_resource and one or more
201 * virtchnl_vsi_resource structures.
204 struct virtchnl_vsi_resource {
207 enum virtchnl_vsi_type vsi_type;
209 u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
212 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
214 /* VF capability flags
215 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
216 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
218 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001
219 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002
220 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004
221 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008
222 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010
223 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020
224 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040
225 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000
226 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000
227 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000
228 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000
229 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000
230 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000
231 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000
232 /* Define below the capability flags that are not offloads */
233 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED 0x00000080
235 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
236 VIRTCHNL_VF_OFFLOAD_VLAN | \
237 VIRTCHNL_VF_OFFLOAD_RSS_PF)
239 struct virtchnl_vf_resource {
249 struct virtchnl_vsi_resource vsi_res[1];
252 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
254 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
255 * VF sends this message to set up parameters for one TX queue.
256 * External data buffer contains one instance of virtchnl_txq_info.
257 * PF configures requested queue and returns a status code.
260 /* Tx queue config info */
261 struct virtchnl_txq_info {
264 u16 ring_len; /* number of descriptors, multiple of 8 */
265 u16 headwb_enabled; /* deprecated with IAVF 1.0 */
267 u64 dma_headwb_addr; /* deprecated with IAVF 1.0 */
270 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
272 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
273 * VF sends this message to set up parameters for one RX queue.
274 * External data buffer contains one instance of virtchnl_rxq_info.
275 * PF configures requested queue and returns a status code.
278 /* Rx queue config info */
279 struct virtchnl_rxq_info {
282 u32 ring_len; /* number of descriptors, multiple of 32 */
284 u16 splithdr_enabled; /* deprecated with IAVF 1.0 */
289 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with IAVF 1.0 */
293 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
295 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
296 * VF sends this message to set parameters for all active TX and RX queues
297 * associated with the specified VSI.
298 * PF configures queues and returns status.
299 * If the number of queues specified is greater than the number of queues
300 * associated with the VSI, an error is returned and no queues are configured.
302 struct virtchnl_queue_pair_info {
303 /* NOTE: vsi_id and queue_id should be identical for both queues. */
304 struct virtchnl_txq_info txq;
305 struct virtchnl_rxq_info rxq;
308 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
310 struct virtchnl_vsi_queue_config_info {
314 struct virtchnl_queue_pair_info qpair[1];
317 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
319 /* VIRTCHNL_OP_REQUEST_QUEUES
320 * VF sends this message to request the PF to allocate additional queues to
321 * this VF. Each VF gets a guaranteed number of queues on init but asking for
322 * additional queues must be negotiated. This is a best effort request as it
323 * is possible the PF does not have enough queues left to support the request.
324 * If the PF cannot support the number requested it will respond with the
325 * maximum number it is able to support. If the request is successful, PF will
326 * then reset the VF to institute required changes.
329 /* VF resource request */
330 struct virtchnl_vf_res_request {
334 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
335 * VF uses this message to map vectors to queues.
336 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
337 * are to be associated with the specified vector.
338 * The "other" causes are always mapped to vector 0.
339 * PF configures interrupt mapping and returns status.
341 struct virtchnl_vector_map {
350 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
352 struct virtchnl_irq_map_info {
354 struct virtchnl_vector_map vecmap[1];
357 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
359 /* VIRTCHNL_OP_ENABLE_QUEUES
360 * VIRTCHNL_OP_DISABLE_QUEUES
361 * VF sends these message to enable or disable TX/RX queue pairs.
362 * The queues fields are bitmaps indicating which queues to act upon.
363 * (Currently, we only support 16 queues per VF, but we make the field
364 * u32 to allow for expansion.)
365 * PF performs requested action and returns status.
367 struct virtchnl_queue_select {
374 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
376 /* VIRTCHNL_OP_ADD_ETH_ADDR
377 * VF sends this message in order to add one or more unicast or multicast
378 * address filters for the specified VSI.
379 * PF adds the filters and returns status.
382 /* VIRTCHNL_OP_DEL_ETH_ADDR
383 * VF sends this message in order to remove one or more unicast or multicast
384 * filters for the specified VSI.
385 * PF removes the filters and returns status.
388 struct virtchnl_ether_addr {
389 u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
393 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
395 struct virtchnl_ether_addr_list {
398 struct virtchnl_ether_addr list[1];
401 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
403 #ifdef VIRTCHNL_SOL_VF_SUPPORT
404 /* VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG
405 * VF sends this message to get the default MTU and list of additional ethernet
406 * addresses it is allowed to use.
407 * PF responds with an indirect message containing
408 * virtchnl_addnl_solaris_config with zero or more
409 * virtchnl_ether_addr structures.
411 * It is expected that this operation will only ever be needed for Solaris VFs
412 * running under a Solaris PF.
414 struct virtchnl_addnl_solaris_config {
416 struct virtchnl_ether_addr_list al;
420 /* VIRTCHNL_OP_ADD_VLAN
421 * VF sends this message to add one or more VLAN tag filters for receives.
422 * PF adds the filters and returns status.
423 * If a port VLAN is configured by the PF, this operation will return an
427 /* VIRTCHNL_OP_DEL_VLAN
428 * VF sends this message to remove one or more VLAN tag filters for receives.
429 * PF removes the filters and returns status.
430 * If a port VLAN is configured by the PF, this operation will return an
434 struct virtchnl_vlan_filter_list {
440 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
442 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
443 * VF sends VSI id and flags.
444 * PF returns status code in retval.
445 * Note: we assume that broadcast accept mode is always enabled.
447 struct virtchnl_promisc_info {
452 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
454 #define FLAG_VF_UNICAST_PROMISC 0x00000001
455 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
457 /* VIRTCHNL_OP_GET_STATS
458 * VF sends this message to request stats for the selected VSI. VF uses
459 * the virtchnl_queue_select struct to specify the VSI. The queue_id
460 * field is ignored by the PF.
462 * PF replies with struct virtchnl_eth_stats in an external buffer.
465 struct virtchnl_eth_stats {
466 u64 rx_bytes; /* received bytes */
467 u64 rx_unicast; /* received unicast pkts */
468 u64 rx_multicast; /* received multicast pkts */
469 u64 rx_broadcast; /* received broadcast pkts */
471 u64 rx_unknown_protocol;
472 u64 tx_bytes; /* transmitted bytes*/
473 u64 tx_unicast; /* transmitted unicast pkts */
474 u64 tx_multicast; /* transmitted multicast pkts */
475 u64 tx_broadcast; /* transmitted broadcast pkts */
480 /* VIRTCHNL_OP_CONFIG_RSS_KEY
481 * VIRTCHNL_OP_CONFIG_RSS_LUT
482 * VF sends these messages to configure RSS. Only supported if both PF
483 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
484 * configuration negotiation. If this is the case, then the RSS fields in
485 * the VF resource struct are valid.
486 * Both the key and LUT are initialized to 0 by the PF, meaning that
487 * RSS is effectively disabled until set up by the VF.
489 struct virtchnl_rss_key {
492 u8 key[1]; /* RSS hash key, packed bytes */
495 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
497 struct virtchnl_rss_lut {
500 u8 lut[1]; /* RSS lookup table */
503 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
505 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
506 * VIRTCHNL_OP_SET_RSS_HENA
507 * VF sends these messages to get and set the hash filter enable bits for RSS.
508 * By default, the PF sets these to all possible traffic types that the
509 * hardware supports. The VF can query this value if it wants to change the
510 * traffic types that are hashed by the hardware.
512 struct virtchnl_rss_hena {
516 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
519 * PF sends this message to inform the VF driver of events that may affect it.
520 * No direct response is expected from the VF, though it may generate other
521 * messages in response to this one.
523 enum virtchnl_event_codes {
524 VIRTCHNL_EVENT_UNKNOWN = 0,
525 VIRTCHNL_EVENT_LINK_CHANGE,
526 VIRTCHNL_EVENT_RESET_IMPENDING,
527 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
530 #define PF_EVENT_SEVERITY_INFO 0
531 #define PF_EVENT_SEVERITY_ATTENTION 1
532 #define PF_EVENT_SEVERITY_ACTION_REQUIRED 2
533 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
535 struct virtchnl_pf_event {
536 enum virtchnl_event_codes event;
538 /* If the PF driver does not support the new speed reporting
539 * capabilities then use link_event else use link_event_adv to
540 * get the speed and link information. The ability to understand
541 * new speeds is indicated by setting the capability flag
542 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
543 * in virtchnl_vf_resource struct and can be used to determine
544 * which link event struct to use below.
547 enum virtchnl_link_speed link_speed;
551 /* link_speed provided in Mbps */
560 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
562 #ifdef VIRTCHNL_IWARP
564 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
565 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
566 * The request for this originates from the VF IWARP driver through
567 * a client interface between VF LAN and VF IWARP driver.
568 * A vector could have an AEQ and CEQ attached to it although
569 * there is a single AEQ per VF IWARP instance in which case
570 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
571 * There will never be a case where there will be multiple CEQs attached
572 * to a single vector.
573 * PF configures interrupt mapping and returns status.
576 /* HW does not define a type value for AEQ; only for RX/TX and CEQ.
577 * In order for us to keep the interface simple, SW will define a
578 * unique type value for AEQ.
580 #define QUEUE_TYPE_PE_AEQ 0x80
581 #define QUEUE_INVALID_IDX 0xFFFF
583 struct virtchnl_iwarp_qv_info {
584 u32 v_idx; /* msix_vector */
590 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
592 struct virtchnl_iwarp_qvlist_info {
594 struct virtchnl_iwarp_qv_info qv_info[1];
597 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
601 /* VF reset states - these are written into the RSTAT register:
602 * VFGEN_RSTAT on the VF
603 * When the PF initiates a reset, it writes 0
604 * When the reset is complete, it writes 1
605 * When the PF detects that the VF has recovered, it writes 2
606 * VF checks this register periodically to determine if a reset has occurred,
607 * then polls it to know when the reset is complete.
608 * If either the PF or VF reads the register while the hardware
609 * is in a reset state, it will return DEADBEEF, which, when masked
612 enum virtchnl_vfr_states {
613 VIRTCHNL_VFR_INPROGRESS = 0,
614 VIRTCHNL_VFR_COMPLETED,
615 VIRTCHNL_VFR_VFACTIVE,
619 * virtchnl_vc_validate_vf_msg
620 * @ver: Virtchnl version info
621 * @v_opcode: Opcode for the message
622 * @msg: pointer to the msg buffer
623 * @msglen: msg length
625 * validate msg format against struct for each opcode
628 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
631 bool err_msg_format = false;
634 /* Validate message length. */
636 case VIRTCHNL_OP_VERSION:
637 valid_len = sizeof(struct virtchnl_version_info);
639 case VIRTCHNL_OP_RESET_VF:
641 case VIRTCHNL_OP_GET_VF_RESOURCES:
643 valid_len = sizeof(u32);
645 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
646 valid_len = sizeof(struct virtchnl_txq_info);
648 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
649 valid_len = sizeof(struct virtchnl_rxq_info);
651 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
652 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
653 if (msglen >= valid_len) {
654 struct virtchnl_vsi_queue_config_info *vqc =
655 (struct virtchnl_vsi_queue_config_info *)msg;
656 valid_len += (vqc->num_queue_pairs *
658 virtchnl_queue_pair_info));
659 if (vqc->num_queue_pairs == 0)
660 err_msg_format = true;
663 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
664 valid_len = sizeof(struct virtchnl_irq_map_info);
665 if (msglen >= valid_len) {
666 struct virtchnl_irq_map_info *vimi =
667 (struct virtchnl_irq_map_info *)msg;
668 valid_len += (vimi->num_vectors *
669 sizeof(struct virtchnl_vector_map));
670 if (vimi->num_vectors == 0)
671 err_msg_format = true;
674 case VIRTCHNL_OP_ENABLE_QUEUES:
675 case VIRTCHNL_OP_DISABLE_QUEUES:
676 valid_len = sizeof(struct virtchnl_queue_select);
678 case VIRTCHNL_OP_ADD_ETH_ADDR:
679 case VIRTCHNL_OP_DEL_ETH_ADDR:
680 valid_len = sizeof(struct virtchnl_ether_addr_list);
681 if (msglen >= valid_len) {
682 struct virtchnl_ether_addr_list *veal =
683 (struct virtchnl_ether_addr_list *)msg;
684 valid_len += veal->num_elements *
685 sizeof(struct virtchnl_ether_addr);
686 if (veal->num_elements == 0)
687 err_msg_format = true;
690 case VIRTCHNL_OP_ADD_VLAN:
691 case VIRTCHNL_OP_DEL_VLAN:
692 valid_len = sizeof(struct virtchnl_vlan_filter_list);
693 if (msglen >= valid_len) {
694 struct virtchnl_vlan_filter_list *vfl =
695 (struct virtchnl_vlan_filter_list *)msg;
696 valid_len += vfl->num_elements * sizeof(u16);
697 if (vfl->num_elements == 0)
698 err_msg_format = true;
701 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
702 valid_len = sizeof(struct virtchnl_promisc_info);
704 case VIRTCHNL_OP_GET_STATS:
705 valid_len = sizeof(struct virtchnl_queue_select);
707 #ifdef VIRTCHNL_IWARP
708 case VIRTCHNL_OP_IWARP:
709 /* These messages are opaque to us and will be validated in
710 * the RDMA client code. We just need to check for nonzero
711 * length. The firmware will enforce max length restrictions.
716 err_msg_format = true;
718 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
720 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
721 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
722 if (msglen >= valid_len) {
723 struct virtchnl_iwarp_qvlist_info *qv =
724 (struct virtchnl_iwarp_qvlist_info *)msg;
725 if (qv->num_vectors == 0) {
726 err_msg_format = true;
729 valid_len += ((qv->num_vectors - 1) *
730 sizeof(struct virtchnl_iwarp_qv_info));
734 case VIRTCHNL_OP_CONFIG_RSS_KEY:
735 valid_len = sizeof(struct virtchnl_rss_key);
736 if (msglen >= valid_len) {
737 struct virtchnl_rss_key *vrk =
738 (struct virtchnl_rss_key *)msg;
739 valid_len += vrk->key_len - 1;
742 case VIRTCHNL_OP_CONFIG_RSS_LUT:
743 valid_len = sizeof(struct virtchnl_rss_lut);
744 if (msglen >= valid_len) {
745 struct virtchnl_rss_lut *vrl =
746 (struct virtchnl_rss_lut *)msg;
747 valid_len += vrl->lut_entries - 1;
750 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
752 case VIRTCHNL_OP_SET_RSS_HENA:
753 valid_len = sizeof(struct virtchnl_rss_hena);
755 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
756 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
758 case VIRTCHNL_OP_REQUEST_QUEUES:
759 valid_len = sizeof(struct virtchnl_vf_res_request);
761 /* These are always errors coming from the VF. */
762 case VIRTCHNL_OP_EVENT:
763 case VIRTCHNL_OP_UNKNOWN:
765 return VIRTCHNL_ERR_PARAM;
767 /* few more checks */
768 if (err_msg_format || valid_len != msglen)
769 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
773 #endif /* _VIRTCHNL_H_ */