1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2018
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 AVF 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
233 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
234 VIRTCHNL_VF_OFFLOAD_VLAN | \
235 VIRTCHNL_VF_OFFLOAD_RSS_PF)
237 struct virtchnl_vf_resource {
247 struct virtchnl_vsi_resource vsi_res[1];
250 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
252 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
253 * VF sends this message to set up parameters for one TX queue.
254 * External data buffer contains one instance of virtchnl_txq_info.
255 * PF configures requested queue and returns a status code.
258 /* Tx queue config info */
259 struct virtchnl_txq_info {
262 u16 ring_len; /* number of descriptors, multiple of 8 */
263 u16 headwb_enabled; /* deprecated with AVF 1.0 */
265 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
268 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
270 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
271 * VF sends this message to set up parameters for one RX queue.
272 * External data buffer contains one instance of virtchnl_rxq_info.
273 * PF configures requested queue and returns a status code.
276 /* Rx queue config info */
277 struct virtchnl_rxq_info {
280 u32 ring_len; /* number of descriptors, multiple of 32 */
282 u16 splithdr_enabled; /* deprecated with AVF 1.0 */
287 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
291 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
293 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
294 * VF sends this message to set parameters for all active TX and RX queues
295 * associated with the specified VSI.
296 * PF configures queues and returns status.
297 * If the number of queues specified is greater than the number of queues
298 * associated with the VSI, an error is returned and no queues are configured.
300 struct virtchnl_queue_pair_info {
301 /* NOTE: vsi_id and queue_id should be identical for both queues. */
302 struct virtchnl_txq_info txq;
303 struct virtchnl_rxq_info rxq;
306 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
308 struct virtchnl_vsi_queue_config_info {
312 struct virtchnl_queue_pair_info qpair[1];
315 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
317 /* VIRTCHNL_OP_REQUEST_QUEUES
318 * VF sends this message to request the PF to allocate additional queues to
319 * this VF. Each VF gets a guaranteed number of queues on init but asking for
320 * additional queues must be negotiated. This is a best effort request as it
321 * is possible the PF does not have enough queues left to support the request.
322 * If the PF cannot support the number requested it will respond with the
323 * maximum number it is able to support. If the request is successful, PF will
324 * then reset the VF to institute required changes.
327 /* VF resource request */
328 struct virtchnl_vf_res_request {
332 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
333 * VF uses this message to map vectors to queues.
334 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
335 * are to be associated with the specified vector.
336 * The "other" causes are always mapped to vector 0.
337 * PF configures interrupt mapping and returns status.
339 struct virtchnl_vector_map {
348 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
350 struct virtchnl_irq_map_info {
352 struct virtchnl_vector_map vecmap[1];
355 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
357 /* VIRTCHNL_OP_ENABLE_QUEUES
358 * VIRTCHNL_OP_DISABLE_QUEUES
359 * VF sends these message to enable or disable TX/RX queue pairs.
360 * The queues fields are bitmaps indicating which queues to act upon.
361 * (Currently, we only support 16 queues per VF, but we make the field
362 * u32 to allow for expansion.)
363 * PF performs requested action and returns status.
365 struct virtchnl_queue_select {
372 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
374 /* VIRTCHNL_OP_ADD_ETH_ADDR
375 * VF sends this message in order to add one or more unicast or multicast
376 * address filters for the specified VSI.
377 * PF adds the filters and returns status.
380 /* VIRTCHNL_OP_DEL_ETH_ADDR
381 * VF sends this message in order to remove one or more unicast or multicast
382 * filters for the specified VSI.
383 * PF removes the filters and returns status.
386 struct virtchnl_ether_addr {
387 u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
391 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
393 struct virtchnl_ether_addr_list {
396 struct virtchnl_ether_addr list[1];
399 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
401 #ifdef VIRTCHNL_SOL_VF_SUPPORT
402 /* VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG
403 * VF sends this message to get the default MTU and list of additional ethernet
404 * addresses it is allowed to use.
405 * PF responds with an indirect message containing
406 * virtchnl_addnl_solaris_config with zero or more
407 * virtchnl_ether_addr structures.
409 * It is expected that this operation will only ever be needed for Solaris VFs
410 * running under a Solaris PF.
412 struct virtchnl_addnl_solaris_config {
414 struct virtchnl_ether_addr_list al;
418 /* VIRTCHNL_OP_ADD_VLAN
419 * VF sends this message to add one or more VLAN tag filters for receives.
420 * PF adds the filters and returns status.
421 * If a port VLAN is configured by the PF, this operation will return an
425 /* VIRTCHNL_OP_DEL_VLAN
426 * VF sends this message to remove one or more VLAN tag filters for receives.
427 * PF removes the filters and returns status.
428 * If a port VLAN is configured by the PF, this operation will return an
432 struct virtchnl_vlan_filter_list {
438 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
440 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
441 * VF sends VSI id and flags.
442 * PF returns status code in retval.
443 * Note: we assume that broadcast accept mode is always enabled.
445 struct virtchnl_promisc_info {
450 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
452 #define FLAG_VF_UNICAST_PROMISC 0x00000001
453 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
455 /* VIRTCHNL_OP_GET_STATS
456 * VF sends this message to request stats for the selected VSI. VF uses
457 * the virtchnl_queue_select struct to specify the VSI. The queue_id
458 * field is ignored by the PF.
460 * PF replies with struct eth_stats in an external buffer.
463 /* VIRTCHNL_OP_CONFIG_RSS_KEY
464 * VIRTCHNL_OP_CONFIG_RSS_LUT
465 * VF sends these messages to configure RSS. Only supported if both PF
466 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
467 * configuration negotiation. If this is the case, then the RSS fields in
468 * the VF resource struct are valid.
469 * Both the key and LUT are initialized to 0 by the PF, meaning that
470 * RSS is effectively disabled until set up by the VF.
472 struct virtchnl_rss_key {
475 u8 key[1]; /* RSS hash key, packed bytes */
478 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
480 struct virtchnl_rss_lut {
483 u8 lut[1]; /* RSS lookup table */
486 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
488 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
489 * VIRTCHNL_OP_SET_RSS_HENA
490 * VF sends these messages to get and set the hash filter enable bits for RSS.
491 * By default, the PF sets these to all possible traffic types that the
492 * hardware supports. The VF can query this value if it wants to change the
493 * traffic types that are hashed by the hardware.
495 struct virtchnl_rss_hena {
499 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
502 * PF sends this message to inform the VF driver of events that may affect it.
503 * No direct response is expected from the VF, though it may generate other
504 * messages in response to this one.
506 enum virtchnl_event_codes {
507 VIRTCHNL_EVENT_UNKNOWN = 0,
508 VIRTCHNL_EVENT_LINK_CHANGE,
509 VIRTCHNL_EVENT_RESET_IMPENDING,
510 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
513 #define PF_EVENT_SEVERITY_INFO 0
514 #define PF_EVENT_SEVERITY_ATTENTION 1
515 #define PF_EVENT_SEVERITY_ACTION_REQUIRED 2
516 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
518 struct virtchnl_pf_event {
519 enum virtchnl_event_codes event;
522 enum virtchnl_link_speed link_speed;
530 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
532 #ifdef VIRTCHNL_IWARP
534 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
535 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
536 * The request for this originates from the VF IWARP driver through
537 * a client interface between VF LAN and VF IWARP driver.
538 * A vector could have an AEQ and CEQ attached to it although
539 * there is a single AEQ per VF IWARP instance in which case
540 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
541 * There will never be a case where there will be multiple CEQs attached
542 * to a single vector.
543 * PF configures interrupt mapping and returns status.
546 /* HW does not define a type value for AEQ; only for RX/TX and CEQ.
547 * In order for us to keep the interface simple, SW will define a
548 * unique type value for AEQ.
550 #define QUEUE_TYPE_PE_AEQ 0x80
551 #define QUEUE_INVALID_IDX 0xFFFF
553 struct virtchnl_iwarp_qv_info {
554 u32 v_idx; /* msix_vector */
560 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
562 struct virtchnl_iwarp_qvlist_info {
564 struct virtchnl_iwarp_qv_info qv_info[1];
567 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
571 /* VF reset states - these are written into the RSTAT register:
572 * VFGEN_RSTAT on the VF
573 * When the PF initiates a reset, it writes 0
574 * When the reset is complete, it writes 1
575 * When the PF detects that the VF has recovered, it writes 2
576 * VF checks this register periodically to determine if a reset has occurred,
577 * then polls it to know when the reset is complete.
578 * If either the PF or VF reads the register while the hardware
579 * is in a reset state, it will return DEADBEEF, which, when masked
582 enum virtchnl_vfr_states {
583 VIRTCHNL_VFR_INPROGRESS = 0,
584 VIRTCHNL_VFR_COMPLETED,
585 VIRTCHNL_VFR_VFACTIVE,
589 * virtchnl_vc_validate_vf_msg
590 * @ver: Virtchnl version info
591 * @v_opcode: Opcode for the message
592 * @msg: pointer to the msg buffer
593 * @msglen: msg length
595 * validate msg format against struct for each opcode
598 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
601 bool err_msg_format = false;
604 /* Validate message length. */
606 case VIRTCHNL_OP_VERSION:
607 valid_len = sizeof(struct virtchnl_version_info);
609 case VIRTCHNL_OP_RESET_VF:
611 case VIRTCHNL_OP_GET_VF_RESOURCES:
613 valid_len = sizeof(u32);
615 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
616 valid_len = sizeof(struct virtchnl_txq_info);
618 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
619 valid_len = sizeof(struct virtchnl_rxq_info);
621 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
622 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
623 if (msglen >= valid_len) {
624 struct virtchnl_vsi_queue_config_info *vqc =
625 (struct virtchnl_vsi_queue_config_info *)msg;
626 valid_len += (vqc->num_queue_pairs *
628 virtchnl_queue_pair_info));
629 if (vqc->num_queue_pairs == 0)
630 err_msg_format = true;
633 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
634 valid_len = sizeof(struct virtchnl_irq_map_info);
635 if (msglen >= valid_len) {
636 struct virtchnl_irq_map_info *vimi =
637 (struct virtchnl_irq_map_info *)msg;
638 valid_len += (vimi->num_vectors *
639 sizeof(struct virtchnl_vector_map));
640 if (vimi->num_vectors == 0)
641 err_msg_format = true;
644 case VIRTCHNL_OP_ENABLE_QUEUES:
645 case VIRTCHNL_OP_DISABLE_QUEUES:
646 valid_len = sizeof(struct virtchnl_queue_select);
648 case VIRTCHNL_OP_ADD_ETH_ADDR:
649 case VIRTCHNL_OP_DEL_ETH_ADDR:
650 valid_len = sizeof(struct virtchnl_ether_addr_list);
651 if (msglen >= valid_len) {
652 struct virtchnl_ether_addr_list *veal =
653 (struct virtchnl_ether_addr_list *)msg;
654 valid_len += veal->num_elements *
655 sizeof(struct virtchnl_ether_addr);
656 if (veal->num_elements == 0)
657 err_msg_format = true;
660 case VIRTCHNL_OP_ADD_VLAN:
661 case VIRTCHNL_OP_DEL_VLAN:
662 valid_len = sizeof(struct virtchnl_vlan_filter_list);
663 if (msglen >= valid_len) {
664 struct virtchnl_vlan_filter_list *vfl =
665 (struct virtchnl_vlan_filter_list *)msg;
666 valid_len += vfl->num_elements * sizeof(u16);
667 if (vfl->num_elements == 0)
668 err_msg_format = true;
671 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
672 valid_len = sizeof(struct virtchnl_promisc_info);
674 case VIRTCHNL_OP_GET_STATS:
675 valid_len = sizeof(struct virtchnl_queue_select);
677 #ifdef VIRTCHNL_IWARP
678 case VIRTCHNL_OP_IWARP:
679 /* These messages are opaque to us and will be validated in
680 * the RDMA client code. We just need to check for nonzero
681 * length. The firmware will enforce max length restrictions.
686 err_msg_format = true;
688 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
690 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
691 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
692 if (msglen >= valid_len) {
693 struct virtchnl_iwarp_qvlist_info *qv =
694 (struct virtchnl_iwarp_qvlist_info *)msg;
695 if (qv->num_vectors == 0) {
696 err_msg_format = true;
699 valid_len += ((qv->num_vectors - 1) *
700 sizeof(struct virtchnl_iwarp_qv_info));
704 case VIRTCHNL_OP_CONFIG_RSS_KEY:
705 valid_len = sizeof(struct virtchnl_rss_key);
706 if (msglen >= valid_len) {
707 struct virtchnl_rss_key *vrk =
708 (struct virtchnl_rss_key *)msg;
709 valid_len += vrk->key_len - 1;
712 case VIRTCHNL_OP_CONFIG_RSS_LUT:
713 valid_len = sizeof(struct virtchnl_rss_lut);
714 if (msglen >= valid_len) {
715 struct virtchnl_rss_lut *vrl =
716 (struct virtchnl_rss_lut *)msg;
717 valid_len += vrl->lut_entries - 1;
720 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
722 case VIRTCHNL_OP_SET_RSS_HENA:
723 valid_len = sizeof(struct virtchnl_rss_hena);
725 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
726 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
728 case VIRTCHNL_OP_REQUEST_QUEUES:
729 valid_len = sizeof(struct virtchnl_vf_res_request);
731 /* These are always errors coming from the VF. */
732 case VIRTCHNL_OP_EVENT:
733 case VIRTCHNL_OP_UNKNOWN:
735 return VIRTCHNL_ERR_PARAM;
737 /* few more checks */
738 if (err_msg_format || valid_len != msglen)
739 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
743 #endif /* _VIRTCHNL_H_ */