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_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_100MB_SHIFT 0x1
57 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2
58 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3
59 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4
60 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5
61 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6
63 enum virtchnl_link_speed {
64 VIRTCHNL_LINK_SPEED_UNKNOWN = 0,
65 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
66 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
67 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
68 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
69 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
70 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
73 /* for hsplit_0 field of Rx HMC context */
74 /* deprecated with AVF 1.0 */
75 enum virtchnl_rx_hsplit {
76 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0,
77 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1,
78 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2,
79 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
80 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8,
83 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS 6
84 /* END GENERIC DEFINES */
86 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
87 * of the virtchnl_msg structure.
90 /* The PF sends status change events to VFs using
91 * the VIRTCHNL_OP_EVENT opcode.
92 * VFs send requests to the PF using the other ops.
93 * Use of "advanced opcode" features must be negotiated as part of capabilities
94 * exchange and are not considered part of base mode feature set.
96 VIRTCHNL_OP_UNKNOWN = 0,
97 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
98 VIRTCHNL_OP_RESET_VF = 2,
99 VIRTCHNL_OP_GET_VF_RESOURCES = 3,
100 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
101 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
102 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
103 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
104 VIRTCHNL_OP_ENABLE_QUEUES = 8,
105 VIRTCHNL_OP_DISABLE_QUEUES = 9,
106 VIRTCHNL_OP_ADD_ETH_ADDR = 10,
107 VIRTCHNL_OP_DEL_ETH_ADDR = 11,
108 VIRTCHNL_OP_ADD_VLAN = 12,
109 VIRTCHNL_OP_DEL_VLAN = 13,
110 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
111 VIRTCHNL_OP_GET_STATS = 15,
112 VIRTCHNL_OP_RSVD = 16,
113 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
114 #ifdef VIRTCHNL_SOL_VF_SUPPORT
115 VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG = 19,
117 #ifdef VIRTCHNL_IWARP
118 VIRTCHNL_OP_IWARP = 20, /* advanced opcode */
119 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
120 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
122 VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
123 VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
124 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
125 VIRTCHNL_OP_SET_RSS_HENA = 26,
126 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
127 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
128 VIRTCHNL_OP_REQUEST_QUEUES = 29,
132 /* These macros are used to generate compilation errors if a structure/union
133 * is not exactly the correct length. It gives a divide by zero error if the
134 * structure is not of the correct size, otherwise it creates an enum that is
137 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
138 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
140 /* Virtual channel message descriptor. This overlays the admin queue
141 * descriptor. All other data is passed in external buffers.
144 struct virtchnl_msg {
145 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
146 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
147 enum virtchnl_status_code v_retval; /* ditto for desc->retval */
148 u32 vfid; /* used by PF when sending to VF */
151 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
153 /* Message descriptions and data structures.*/
155 /* VIRTCHNL_OP_VERSION
156 * VF posts its version number to the PF. PF responds with its version number
157 * in the same format, along with a return code.
158 * Reply from PF has its major/minor versions also in param0 and param1.
159 * If there is a major version mismatch, then the VF cannot operate.
160 * If there is a minor version mismatch, then the VF can operate but should
161 * add a warning to the system log.
163 * This enum element MUST always be specified as == 1, regardless of other
164 * changes in the API. The PF must always respond to this message without
165 * error regardless of version mismatch.
167 #define VIRTCHNL_VERSION_MAJOR 1
168 #define VIRTCHNL_VERSION_MINOR 1
169 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
171 struct virtchnl_version_info {
176 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
178 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
179 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
181 /* VIRTCHNL_OP_RESET_VF
182 * VF sends this request to PF with no parameters
183 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
184 * until reset completion is indicated. The admin queue must be reinitialized
185 * after this operation.
187 * When reset is complete, PF must ensure that all queues in all VSIs associated
188 * with the VF are stopped, all queue configurations in the HMC are set to 0,
189 * and all MAC and VLAN filters (except the default MAC address) on all VSIs
193 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
194 * vsi_type should always be 6 for backward compatibility. Add other fields
197 enum virtchnl_vsi_type {
198 VIRTCHNL_VSI_TYPE_INVALID = 0,
199 VIRTCHNL_VSI_SRIOV = 6,
202 /* VIRTCHNL_OP_GET_VF_RESOURCES
203 * Version 1.0 VF sends this request to PF with no parameters
204 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
205 * PF responds with an indirect message containing
206 * virtchnl_vf_resource and one or more
207 * virtchnl_vsi_resource structures.
210 struct virtchnl_vsi_resource {
213 enum virtchnl_vsi_type vsi_type;
215 u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
218 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
220 /* VF capability flags
221 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
222 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
224 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001
225 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002
226 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004
227 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008
228 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010
229 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020
230 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040
231 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000
232 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000
233 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000
234 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000
235 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000
236 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000
237 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000
239 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
240 VIRTCHNL_VF_OFFLOAD_VLAN | \
241 VIRTCHNL_VF_OFFLOAD_RSS_PF)
243 struct virtchnl_vf_resource {
253 struct virtchnl_vsi_resource vsi_res[1];
256 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
258 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
259 * VF sends this message to set up parameters for one TX queue.
260 * External data buffer contains one instance of virtchnl_txq_info.
261 * PF configures requested queue and returns a status code.
264 /* Tx queue config info */
265 struct virtchnl_txq_info {
268 u16 ring_len; /* number of descriptors, multiple of 8 */
269 u16 headwb_enabled; /* deprecated with AVF 1.0 */
271 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
274 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
276 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
277 * VF sends this message to set up parameters for one RX queue.
278 * External data buffer contains one instance of virtchnl_rxq_info.
279 * PF configures requested queue and returns a status code.
282 /* Rx queue config info */
283 struct virtchnl_rxq_info {
286 u32 ring_len; /* number of descriptors, multiple of 32 */
288 u16 splithdr_enabled; /* deprecated with AVF 1.0 */
293 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
297 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
299 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
300 * VF sends this message to set parameters for all active TX and RX queues
301 * associated with the specified VSI.
302 * PF configures queues and returns status.
303 * If the number of queues specified is greater than the number of queues
304 * associated with the VSI, an error is returned and no queues are configured.
306 struct virtchnl_queue_pair_info {
307 /* NOTE: vsi_id and queue_id should be identical for both queues. */
308 struct virtchnl_txq_info txq;
309 struct virtchnl_rxq_info rxq;
312 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
314 struct virtchnl_vsi_queue_config_info {
318 struct virtchnl_queue_pair_info qpair[1];
321 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
323 /* VIRTCHNL_OP_REQUEST_QUEUES
324 * VF sends this message to request the PF to allocate additional queues to
325 * this VF. Each VF gets a guaranteed number of queues on init but asking for
326 * additional queues must be negotiated. This is a best effort request as it
327 * is possible the PF does not have enough queues left to support the request.
328 * If the PF cannot support the number requested it will respond with the
329 * maximum number it is able to support. If the request is successful, PF will
330 * then reset the VF to institute required changes.
333 /* VF resource request */
334 struct virtchnl_vf_res_request {
338 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
339 * VF uses this message to map vectors to queues.
340 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
341 * are to be associated with the specified vector.
342 * The "other" causes are always mapped to vector 0.
343 * PF configures interrupt mapping and returns status.
345 struct virtchnl_vector_map {
354 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
356 struct virtchnl_irq_map_info {
358 struct virtchnl_vector_map vecmap[1];
361 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
363 /* VIRTCHNL_OP_ENABLE_QUEUES
364 * VIRTCHNL_OP_DISABLE_QUEUES
365 * VF sends these message to enable or disable TX/RX queue pairs.
366 * The queues fields are bitmaps indicating which queues to act upon.
367 * (Currently, we only support 16 queues per VF, but we make the field
368 * u32 to allow for expansion.)
369 * PF performs requested action and returns status.
371 struct virtchnl_queue_select {
378 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
380 /* VIRTCHNL_OP_ADD_ETH_ADDR
381 * VF sends this message in order to add one or more unicast or multicast
382 * address filters for the specified VSI.
383 * PF adds the filters and returns status.
386 /* VIRTCHNL_OP_DEL_ETH_ADDR
387 * VF sends this message in order to remove one or more unicast or multicast
388 * filters for the specified VSI.
389 * PF removes the filters and returns status.
392 struct virtchnl_ether_addr {
393 u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
397 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
399 struct virtchnl_ether_addr_list {
402 struct virtchnl_ether_addr list[1];
405 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
407 #ifdef VIRTCHNL_SOL_VF_SUPPORT
408 /* VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG
409 * VF sends this message to get the default MTU and list of additional ethernet
410 * addresses it is allowed to use.
411 * PF responds with an indirect message containing
412 * virtchnl_addnl_solaris_config with zero or more
413 * virtchnl_ether_addr structures.
415 * It is expected that this operation will only ever be needed for Solaris VFs
416 * running under a Solaris PF.
418 struct virtchnl_addnl_solaris_config {
420 struct virtchnl_ether_addr_list al;
424 /* VIRTCHNL_OP_ADD_VLAN
425 * VF sends this message to add one or more VLAN tag filters for receives.
426 * PF adds the filters and returns status.
427 * If a port VLAN is configured by the PF, this operation will return an
431 /* VIRTCHNL_OP_DEL_VLAN
432 * VF sends this message to remove one or more VLAN tag filters for receives.
433 * PF removes the filters and returns status.
434 * If a port VLAN is configured by the PF, this operation will return an
438 struct virtchnl_vlan_filter_list {
444 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
446 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
447 * VF sends VSI id and flags.
448 * PF returns status code in retval.
449 * Note: we assume that broadcast accept mode is always enabled.
451 struct virtchnl_promisc_info {
456 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
458 #define FLAG_VF_UNICAST_PROMISC 0x00000001
459 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
461 /* VIRTCHNL_OP_GET_STATS
462 * VF sends this message to request stats for the selected VSI. VF uses
463 * the virtchnl_queue_select struct to specify the VSI. The queue_id
464 * field is ignored by the PF.
466 * PF replies with struct eth_stats in an external buffer.
469 /* VIRTCHNL_OP_CONFIG_RSS_KEY
470 * VIRTCHNL_OP_CONFIG_RSS_LUT
471 * VF sends these messages to configure RSS. Only supported if both PF
472 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
473 * configuration negotiation. If this is the case, then the RSS fields in
474 * the VF resource struct are valid.
475 * Both the key and LUT are initialized to 0 by the PF, meaning that
476 * RSS is effectively disabled until set up by the VF.
478 struct virtchnl_rss_key {
481 u8 key[1]; /* RSS hash key, packed bytes */
484 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
486 struct virtchnl_rss_lut {
489 u8 lut[1]; /* RSS lookup table */
492 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
494 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
495 * VIRTCHNL_OP_SET_RSS_HENA
496 * VF sends these messages to get and set the hash filter enable bits for RSS.
497 * By default, the PF sets these to all possible traffic types that the
498 * hardware supports. The VF can query this value if it wants to change the
499 * traffic types that are hashed by the hardware.
501 struct virtchnl_rss_hena {
505 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
508 * PF sends this message to inform the VF driver of events that may affect it.
509 * No direct response is expected from the VF, though it may generate other
510 * messages in response to this one.
512 enum virtchnl_event_codes {
513 VIRTCHNL_EVENT_UNKNOWN = 0,
514 VIRTCHNL_EVENT_LINK_CHANGE,
515 VIRTCHNL_EVENT_RESET_IMPENDING,
516 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
519 #define PF_EVENT_SEVERITY_INFO 0
520 #define PF_EVENT_SEVERITY_ATTENTION 1
521 #define PF_EVENT_SEVERITY_ACTION_REQUIRED 2
522 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
524 struct virtchnl_pf_event {
525 enum virtchnl_event_codes event;
528 enum virtchnl_link_speed link_speed;
536 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
538 #ifdef VIRTCHNL_IWARP
540 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
541 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
542 * The request for this originates from the VF IWARP driver through
543 * a client interface between VF LAN and VF IWARP driver.
544 * A vector could have an AEQ and CEQ attached to it although
545 * there is a single AEQ per VF IWARP instance in which case
546 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
547 * There will never be a case where there will be multiple CEQs attached
548 * to a single vector.
549 * PF configures interrupt mapping and returns status.
552 /* HW does not define a type value for AEQ; only for RX/TX and CEQ.
553 * In order for us to keep the interface simple, SW will define a
554 * unique type value for AEQ.
556 #define QUEUE_TYPE_PE_AEQ 0x80
557 #define QUEUE_INVALID_IDX 0xFFFF
559 struct virtchnl_iwarp_qv_info {
560 u32 v_idx; /* msix_vector */
566 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
568 struct virtchnl_iwarp_qvlist_info {
570 struct virtchnl_iwarp_qv_info qv_info[1];
573 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
577 /* VF reset states - these are written into the RSTAT register:
578 * VFGEN_RSTAT on the VF
579 * When the PF initiates a reset, it writes 0
580 * When the reset is complete, it writes 1
581 * When the PF detects that the VF has recovered, it writes 2
582 * VF checks this register periodically to determine if a reset has occurred,
583 * then polls it to know when the reset is complete.
584 * If either the PF or VF reads the register while the hardware
585 * is in a reset state, it will return DEADBEEF, which, when masked
588 enum virtchnl_vfr_states {
589 VIRTCHNL_VFR_INPROGRESS = 0,
590 VIRTCHNL_VFR_COMPLETED,
591 VIRTCHNL_VFR_VFACTIVE,
595 * virtchnl_vc_validate_vf_msg
596 * @ver: Virtchnl version info
597 * @v_opcode: Opcode for the message
598 * @msg: pointer to the msg buffer
599 * @msglen: msg length
601 * validate msg format against struct for each opcode
604 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
607 bool err_msg_format = false;
610 /* Validate message length. */
612 case VIRTCHNL_OP_VERSION:
613 valid_len = sizeof(struct virtchnl_version_info);
615 case VIRTCHNL_OP_RESET_VF:
617 case VIRTCHNL_OP_GET_VF_RESOURCES:
619 valid_len = sizeof(u32);
621 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
622 valid_len = sizeof(struct virtchnl_txq_info);
624 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
625 valid_len = sizeof(struct virtchnl_rxq_info);
627 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
628 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
629 if (msglen >= valid_len) {
630 struct virtchnl_vsi_queue_config_info *vqc =
631 (struct virtchnl_vsi_queue_config_info *)msg;
632 valid_len += (vqc->num_queue_pairs *
634 virtchnl_queue_pair_info));
635 if (vqc->num_queue_pairs == 0)
636 err_msg_format = true;
639 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
640 valid_len = sizeof(struct virtchnl_irq_map_info);
641 if (msglen >= valid_len) {
642 struct virtchnl_irq_map_info *vimi =
643 (struct virtchnl_irq_map_info *)msg;
644 valid_len += (vimi->num_vectors *
645 sizeof(struct virtchnl_vector_map));
646 if (vimi->num_vectors == 0)
647 err_msg_format = true;
650 case VIRTCHNL_OP_ENABLE_QUEUES:
651 case VIRTCHNL_OP_DISABLE_QUEUES:
652 valid_len = sizeof(struct virtchnl_queue_select);
654 case VIRTCHNL_OP_ADD_ETH_ADDR:
655 case VIRTCHNL_OP_DEL_ETH_ADDR:
656 valid_len = sizeof(struct virtchnl_ether_addr_list);
657 if (msglen >= valid_len) {
658 struct virtchnl_ether_addr_list *veal =
659 (struct virtchnl_ether_addr_list *)msg;
660 valid_len += veal->num_elements *
661 sizeof(struct virtchnl_ether_addr);
662 if (veal->num_elements == 0)
663 err_msg_format = true;
666 case VIRTCHNL_OP_ADD_VLAN:
667 case VIRTCHNL_OP_DEL_VLAN:
668 valid_len = sizeof(struct virtchnl_vlan_filter_list);
669 if (msglen >= valid_len) {
670 struct virtchnl_vlan_filter_list *vfl =
671 (struct virtchnl_vlan_filter_list *)msg;
672 valid_len += vfl->num_elements * sizeof(u16);
673 if (vfl->num_elements == 0)
674 err_msg_format = true;
677 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
678 valid_len = sizeof(struct virtchnl_promisc_info);
680 case VIRTCHNL_OP_GET_STATS:
681 valid_len = sizeof(struct virtchnl_queue_select);
683 #ifdef VIRTCHNL_IWARP
684 case VIRTCHNL_OP_IWARP:
685 /* These messages are opaque to us and will be validated in
686 * the RDMA client code. We just need to check for nonzero
687 * length. The firmware will enforce max length restrictions.
692 err_msg_format = true;
694 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
696 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
697 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
698 if (msglen >= valid_len) {
699 struct virtchnl_iwarp_qvlist_info *qv =
700 (struct virtchnl_iwarp_qvlist_info *)msg;
701 if (qv->num_vectors == 0) {
702 err_msg_format = true;
705 valid_len += ((qv->num_vectors - 1) *
706 sizeof(struct virtchnl_iwarp_qv_info));
710 case VIRTCHNL_OP_CONFIG_RSS_KEY:
711 valid_len = sizeof(struct virtchnl_rss_key);
712 if (msglen >= valid_len) {
713 struct virtchnl_rss_key *vrk =
714 (struct virtchnl_rss_key *)msg;
715 valid_len += vrk->key_len - 1;
718 case VIRTCHNL_OP_CONFIG_RSS_LUT:
719 valid_len = sizeof(struct virtchnl_rss_lut);
720 if (msglen >= valid_len) {
721 struct virtchnl_rss_lut *vrl =
722 (struct virtchnl_rss_lut *)msg;
723 valid_len += vrl->lut_entries - 1;
726 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
728 case VIRTCHNL_OP_SET_RSS_HENA:
729 valid_len = sizeof(struct virtchnl_rss_hena);
731 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
732 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
734 case VIRTCHNL_OP_REQUEST_QUEUES:
735 valid_len = sizeof(struct virtchnl_vf_res_request);
737 /* These are always errors coming from the VF. */
738 case VIRTCHNL_OP_EVENT:
739 case VIRTCHNL_OP_UNKNOWN:
741 return VIRTCHNL_STATUS_ERR_PARAM;
743 /* few more checks */
744 if (err_msg_format || valid_len != msglen)
745 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
749 #endif /* _VIRTCHNL_H_ */