xref: /f-stack/dpdk/drivers/net/i40e/base/virtchnl.h (revision 2d9fd380)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2020 Intel Corporation
3  */
4 
5 #ifndef _VIRTCHNL_H_
6 #define _VIRTCHNL_H_
7 
8 /* Description:
9  * This header file describes the VF-PF communication protocol used
10  * by the drivers for all devices starting from our 40G product line
11  *
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.
18  *
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.
22  *
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.
26  *
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
32  * process traffic.
33  */
34 
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
38  */
39 
40 /* Error Codes */
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,
50 };
51 
52 /* Backward compatibility */
53 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
54 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
55 
56 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT		0x0
57 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT		0x1
58 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT	0x2
59 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT		0x3
60 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT		0x4
61 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT		0x5
62 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT		0x6
63 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT		0x7
64 
65 enum virtchnl_link_speed {
66 	VIRTCHNL_LINK_SPEED_UNKNOWN	= 0,
67 	VIRTCHNL_LINK_SPEED_100MB	= BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
68 	VIRTCHNL_LINK_SPEED_1GB		= BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
69 	VIRTCHNL_LINK_SPEED_10GB	= BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
70 	VIRTCHNL_LINK_SPEED_40GB	= BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
71 	VIRTCHNL_LINK_SPEED_20GB	= BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
72 	VIRTCHNL_LINK_SPEED_25GB	= BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
73 	VIRTCHNL_LINK_SPEED_2_5GB	= BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
74 	VIRTCHNL_LINK_SPEED_5GB		= BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
75 };
76 
77 /* for hsplit_0 field of Rx HMC context */
78 /* deprecated with AVF 1.0 */
79 enum virtchnl_rx_hsplit {
80 	VIRTCHNL_RX_HSPLIT_NO_SPLIT      = 0,
81 	VIRTCHNL_RX_HSPLIT_SPLIT_L2      = 1,
82 	VIRTCHNL_RX_HSPLIT_SPLIT_IP      = 2,
83 	VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
84 	VIRTCHNL_RX_HSPLIT_SPLIT_SCTP    = 8,
85 };
86 
87 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS	6
88 /* END GENERIC DEFINES */
89 
90 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
91  * of the virtchnl_msg structure.
92  */
93 enum virtchnl_ops {
94 /* The PF sends status change events to VFs using
95  * the VIRTCHNL_OP_EVENT opcode.
96  * VFs send requests to the PF using the other ops.
97  * Use of "advanced opcode" features must be negotiated as part of capabilities
98  * exchange and are not considered part of base mode feature set.
99  */
100 	VIRTCHNL_OP_UNKNOWN = 0,
101 	VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
102 	VIRTCHNL_OP_RESET_VF = 2,
103 	VIRTCHNL_OP_GET_VF_RESOURCES = 3,
104 	VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
105 	VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
106 	VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
107 	VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
108 	VIRTCHNL_OP_ENABLE_QUEUES = 8,
109 	VIRTCHNL_OP_DISABLE_QUEUES = 9,
110 	VIRTCHNL_OP_ADD_ETH_ADDR = 10,
111 	VIRTCHNL_OP_DEL_ETH_ADDR = 11,
112 	VIRTCHNL_OP_ADD_VLAN = 12,
113 	VIRTCHNL_OP_DEL_VLAN = 13,
114 	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
115 	VIRTCHNL_OP_GET_STATS = 15,
116 	VIRTCHNL_OP_RSVD = 16,
117 	VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
118 #ifdef VIRTCHNL_SOL_VF_SUPPORT
119 	VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG = 19,
120 #endif
121 #ifdef VIRTCHNL_IWARP
122 	VIRTCHNL_OP_IWARP = 20, /* advanced opcode */
123 	VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
124 	VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
125 #endif
126 	VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
127 	VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
128 	VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
129 	VIRTCHNL_OP_SET_RSS_HENA = 26,
130 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
131 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
132 	VIRTCHNL_OP_REQUEST_QUEUES = 29,
133 
134 };
135 
136 /* These macros are used to generate compilation errors if a structure/union
137  * is not exactly the correct length. It gives a divide by zero error if the
138  * structure is not of the correct size, otherwise it creates an enum that is
139  * never used.
140  */
141 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
142 	{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
143 
144 /* Virtual channel message descriptor. This overlays the admin queue
145  * descriptor. All other data is passed in external buffers.
146  */
147 
148 struct virtchnl_msg {
149 	u8 pad[8];			 /* AQ flags/opcode/len/retval fields */
150 	enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
151 	enum virtchnl_status_code v_retval;  /* ditto for desc->retval */
152 	u32 vfid;			 /* used by PF when sending to VF */
153 };
154 
155 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
156 
157 /* Message descriptions and data structures.*/
158 
159 /* VIRTCHNL_OP_VERSION
160  * VF posts its version number to the PF. PF responds with its version number
161  * in the same format, along with a return code.
162  * Reply from PF has its major/minor versions also in param0 and param1.
163  * If there is a major version mismatch, then the VF cannot operate.
164  * If there is a minor version mismatch, then the VF can operate but should
165  * add a warning to the system log.
166  *
167  * This enum element MUST always be specified as == 1, regardless of other
168  * changes in the API. The PF must always respond to this message without
169  * error regardless of version mismatch.
170  */
171 #define VIRTCHNL_VERSION_MAJOR		1
172 #define VIRTCHNL_VERSION_MINOR		1
173 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS	0
174 
175 struct virtchnl_version_info {
176 	u32 major;
177 	u32 minor;
178 };
179 
180 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
181 
182 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
183 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
184 
185 /* VIRTCHNL_OP_RESET_VF
186  * VF sends this request to PF with no parameters
187  * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
188  * until reset completion is indicated. The admin queue must be reinitialized
189  * after this operation.
190  *
191  * When reset is complete, PF must ensure that all queues in all VSIs associated
192  * with the VF are stopped, all queue configurations in the HMC are set to 0,
193  * and all MAC and VLAN filters (except the default MAC address) on all VSIs
194  * are cleared.
195  */
196 
197 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
198  * vsi_type should always be 6 for backward compatibility. Add other fields
199  * as needed.
200  */
201 enum virtchnl_vsi_type {
202 	VIRTCHNL_VSI_TYPE_INVALID = 0,
203 	VIRTCHNL_VSI_SRIOV = 6,
204 };
205 
206 /* VIRTCHNL_OP_GET_VF_RESOURCES
207  * Version 1.0 VF sends this request to PF with no parameters
208  * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
209  * PF responds with an indirect message containing
210  * virtchnl_vf_resource and one or more
211  * virtchnl_vsi_resource structures.
212  */
213 
214 struct virtchnl_vsi_resource {
215 	u16 vsi_id;
216 	u16 num_queue_pairs;
217 	enum virtchnl_vsi_type vsi_type;
218 	u16 qset_handle;
219 	u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
220 };
221 
222 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
223 
224 /* VF capability flags
225  * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
226  * TX/RX Checksum offloading and TSO for non-tunnelled packets.
227  */
228 #define VIRTCHNL_VF_OFFLOAD_L2			0x00000001
229 #define VIRTCHNL_VF_OFFLOAD_IWARP		0x00000002
230 #define VIRTCHNL_VF_OFFLOAD_RSVD		0x00000004
231 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ		0x00000008
232 #define VIRTCHNL_VF_OFFLOAD_RSS_REG		0x00000010
233 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR		0x00000020
234 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES		0x00000040
235 #define VIRTCHNL_VF_OFFLOAD_CRC			0x00000080
236 #define VIRTCHNL_VF_OFFLOAD_VLAN		0x00010000
237 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING		0x00020000
238 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2	0x00040000
239 #define VIRTCHNL_VF_OFFLOAD_RSS_PF		0X00080000
240 #define VIRTCHNL_VF_OFFLOAD_ENCAP		0X00100000
241 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM		0X00200000
242 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM	0X00400000
243 /* Define below the capability flags that are not offloads */
244 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED		0x00000080
245 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
246 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
247 			       VIRTCHNL_VF_OFFLOAD_RSS_PF)
248 
249 struct virtchnl_vf_resource {
250 	u16 num_vsis;
251 	u16 num_queue_pairs;
252 	u16 max_vectors;
253 	u16 max_mtu;
254 
255 	u32 vf_cap_flags;
256 	u32 rss_key_size;
257 	u32 rss_lut_size;
258 
259 	struct virtchnl_vsi_resource vsi_res[1];
260 };
261 
262 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
263 
264 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
265  * VF sends this message to set up parameters for one TX queue.
266  * External data buffer contains one instance of virtchnl_txq_info.
267  * PF configures requested queue and returns a status code.
268  */
269 
270 /* Tx queue config info */
271 struct virtchnl_txq_info {
272 	u16 vsi_id;
273 	u16 queue_id;
274 	u16 ring_len;		/* number of descriptors, multiple of 8 */
275 	u16 headwb_enabled; /* deprecated with AVF 1.0 */
276 	u64 dma_ring_addr;
277 	u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
278 };
279 
280 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
281 
282 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
283  * VF sends this message to set up parameters for one RX queue.
284  * External data buffer contains one instance of virtchnl_rxq_info.
285  * PF configures requested queue and returns a status code. The
286  * crc_disable flag disables CRC stripping on the VF. Setting
287  * the crc_disable flag to 1 will disable CRC stripping for each
288  * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC
289  * offload must have been set prior to sending this info or the PF
290  * will ignore the request. This flag should be set the same for
291  * all of the queues for a VF.
292  */
293 
294 /* Rx queue config info */
295 struct virtchnl_rxq_info {
296 	u16 vsi_id;
297 	u16 queue_id;
298 	u32 ring_len;		/* number of descriptors, multiple of 32 */
299 	u16 hdr_size;
300 	u16 splithdr_enabled; /* deprecated with AVF 1.0 */
301 	u32 databuffer_size;
302 	u32 max_pkt_size;
303 	u8 crc_disable;
304 	u8 pad1[3];
305 	u64 dma_ring_addr;
306 	enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
307 	u32 pad2;
308 };
309 
310 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
311 
312 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
313  * VF sends this message to set parameters for all active TX and RX queues
314  * associated with the specified VSI.
315  * PF configures queues and returns status.
316  * If the number of queues specified is greater than the number of queues
317  * associated with the VSI, an error is returned and no queues are configured.
318  */
319 struct virtchnl_queue_pair_info {
320 	/* NOTE: vsi_id and queue_id should be identical for both queues. */
321 	struct virtchnl_txq_info txq;
322 	struct virtchnl_rxq_info rxq;
323 };
324 
325 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
326 
327 struct virtchnl_vsi_queue_config_info {
328 	u16 vsi_id;
329 	u16 num_queue_pairs;
330 	u32 pad;
331 	struct virtchnl_queue_pair_info qpair[1];
332 };
333 
334 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
335 
336 /* VIRTCHNL_OP_REQUEST_QUEUES
337  * VF sends this message to request the PF to allocate additional queues to
338  * this VF.  Each VF gets a guaranteed number of queues on init but asking for
339  * additional queues must be negotiated.  This is a best effort request as it
340  * is possible the PF does not have enough queues left to support the request.
341  * If the PF cannot support the number requested it will respond with the
342  * maximum number it is able to support.  If the request is successful, PF will
343  * then reset the VF to institute required changes.
344  */
345 
346 /* VF resource request */
347 struct virtchnl_vf_res_request {
348 	u16 num_queue_pairs;
349 };
350 
351 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
352  * VF uses this message to map vectors to queues.
353  * The rxq_map and txq_map fields are bitmaps used to indicate which queues
354  * are to be associated with the specified vector.
355  * The "other" causes are always mapped to vector 0.
356  * PF configures interrupt mapping and returns status.
357  */
358 struct virtchnl_vector_map {
359 	u16 vsi_id;
360 	u16 vector_id;
361 	u16 rxq_map;
362 	u16 txq_map;
363 	u16 rxitr_idx;
364 	u16 txitr_idx;
365 };
366 
367 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
368 
369 struct virtchnl_irq_map_info {
370 	u16 num_vectors;
371 	struct virtchnl_vector_map vecmap[1];
372 };
373 
374 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
375 
376 /* VIRTCHNL_OP_ENABLE_QUEUES
377  * VIRTCHNL_OP_DISABLE_QUEUES
378  * VF sends these message to enable or disable TX/RX queue pairs.
379  * The queues fields are bitmaps indicating which queues to act upon.
380  * (Currently, we only support 16 queues per VF, but we make the field
381  * u32 to allow for expansion.)
382  * PF performs requested action and returns status.
383  */
384 struct virtchnl_queue_select {
385 	u16 vsi_id;
386 	u16 pad;
387 	u32 rx_queues;
388 	u32 tx_queues;
389 };
390 
391 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
392 
393 /* VIRTCHNL_OP_ADD_ETH_ADDR
394  * VF sends this message in order to add one or more unicast or multicast
395  * address filters for the specified VSI.
396  * PF adds the filters and returns status.
397  */
398 
399 /* VIRTCHNL_OP_DEL_ETH_ADDR
400  * VF sends this message in order to remove one or more unicast or multicast
401  * filters for the specified VSI.
402  * PF removes the filters and returns status.
403  */
404 
405 struct virtchnl_ether_addr {
406 	u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
407 	u8 pad[2];
408 };
409 
410 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
411 
412 struct virtchnl_ether_addr_list {
413 	u16 vsi_id;
414 	u16 num_elements;
415 	struct virtchnl_ether_addr list[1];
416 };
417 
418 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
419 
420 #ifdef VIRTCHNL_SOL_VF_SUPPORT
421 /* VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG
422  * VF sends this message to get the default MTU and list of additional ethernet
423  * addresses it is allowed to use.
424  * PF responds with an indirect message containing
425  * virtchnl_addnl_solaris_config with zero or more
426  * virtchnl_ether_addr structures.
427  *
428  * It is expected that this operation will only ever be needed for Solaris VFs
429  * running under a Solaris PF.
430  */
431 struct virtchnl_addnl_solaris_config {
432 	u16 default_mtu;
433 	struct virtchnl_ether_addr_list al;
434 };
435 
436 #endif
437 /* VIRTCHNL_OP_ADD_VLAN
438  * VF sends this message to add one or more VLAN tag filters for receives.
439  * PF adds the filters and returns status.
440  * If a port VLAN is configured by the PF, this operation will return an
441  * error to the VF.
442  */
443 
444 /* VIRTCHNL_OP_DEL_VLAN
445  * VF sends this message to remove one or more VLAN tag filters for receives.
446  * PF removes the filters and returns status.
447  * If a port VLAN is configured by the PF, this operation will return an
448  * error to the VF.
449  */
450 
451 struct virtchnl_vlan_filter_list {
452 	u16 vsi_id;
453 	u16 num_elements;
454 	u16 vlan_id[1];
455 };
456 
457 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
458 
459 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
460  * VF sends VSI id and flags.
461  * PF returns status code in retval.
462  * Note: we assume that broadcast accept mode is always enabled.
463  */
464 struct virtchnl_promisc_info {
465 	u16 vsi_id;
466 	u16 flags;
467 };
468 
469 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
470 
471 #define FLAG_VF_UNICAST_PROMISC	0x00000001
472 #define FLAG_VF_MULTICAST_PROMISC	0x00000002
473 
474 /* VIRTCHNL_OP_GET_STATS
475  * VF sends this message to request stats for the selected VSI. VF uses
476  * the virtchnl_queue_select struct to specify the VSI. The queue_id
477  * field is ignored by the PF.
478  *
479  * PF replies with struct eth_stats in an external buffer.
480  */
481 
482 /* VIRTCHNL_OP_CONFIG_RSS_KEY
483  * VIRTCHNL_OP_CONFIG_RSS_LUT
484  * VF sends these messages to configure RSS. Only supported if both PF
485  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
486  * configuration negotiation. If this is the case, then the RSS fields in
487  * the VF resource struct are valid.
488  * Both the key and LUT are initialized to 0 by the PF, meaning that
489  * RSS is effectively disabled until set up by the VF.
490  */
491 struct virtchnl_rss_key {
492 	u16 vsi_id;
493 	u16 key_len;
494 	u8 key[1];         /* RSS hash key, packed bytes */
495 };
496 
497 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
498 
499 struct virtchnl_rss_lut {
500 	u16 vsi_id;
501 	u16 lut_entries;
502 	u8 lut[1];        /* RSS lookup table */
503 };
504 
505 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
506 
507 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
508  * VIRTCHNL_OP_SET_RSS_HENA
509  * VF sends these messages to get and set the hash filter enable bits for RSS.
510  * By default, the PF sets these to all possible traffic types that the
511  * hardware supports. The VF can query this value if it wants to change the
512  * traffic types that are hashed by the hardware.
513  */
514 struct virtchnl_rss_hena {
515 	u64 hena;
516 };
517 
518 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
519 
520 /* VIRTCHNL_OP_EVENT
521  * PF sends this message to inform the VF driver of events that may affect it.
522  * No direct response is expected from the VF, though it may generate other
523  * messages in response to this one.
524  */
525 enum virtchnl_event_codes {
526 	VIRTCHNL_EVENT_UNKNOWN = 0,
527 	VIRTCHNL_EVENT_LINK_CHANGE,
528 	VIRTCHNL_EVENT_RESET_IMPENDING,
529 	VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
530 };
531 
532 #define PF_EVENT_SEVERITY_INFO		0
533 #define PF_EVENT_SEVERITY_ATTENTION	1
534 #define PF_EVENT_SEVERITY_ACTION_REQUIRED	2
535 #define PF_EVENT_SEVERITY_CERTAIN_DOOM	255
536 
537 struct virtchnl_pf_event {
538 	enum virtchnl_event_codes event;
539 	union {
540 		/* If the PF driver does not support the new speed reporting
541 		 * capabilities then use link_event else use link_event_adv to
542 		 * get the speed and link information. The ability to understand
543 		 * new speeds is indicated by setting the capability flag
544 		 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
545 		 * in virtchnl_vf_resource struct and can be used to determine
546 		 * which link event struct to use below.
547 		 */
548 		struct {
549 			enum virtchnl_link_speed link_speed;
550 			bool link_status;
551 		} link_event;
552 		struct {
553 			/* link_speed provided in Mbps */
554 			u32 link_speed;
555 			u8 link_status;
556 		} link_event_adv;
557 	} event_data;
558 
559 	int severity;
560 };
561 
562 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
563 
564 #ifdef VIRTCHNL_IWARP
565 
566 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
567  * VF uses this message to request PF to map IWARP vectors to IWARP queues.
568  * The request for this originates from the VF IWARP driver through
569  * a client interface between VF LAN and VF IWARP driver.
570  * A vector could have an AEQ and CEQ attached to it although
571  * there is a single AEQ per VF IWARP instance in which case
572  * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
573  * There will never be a case where there will be multiple CEQs attached
574  * to a single vector.
575  * PF configures interrupt mapping and returns status.
576  */
577 
578 /* HW does not define a type value for AEQ; only for RX/TX and CEQ.
579  * In order for us to keep the interface simple, SW will define a
580  * unique type value for AEQ.
581  */
582 #define QUEUE_TYPE_PE_AEQ  0x80
583 #define QUEUE_INVALID_IDX  0xFFFF
584 
585 struct virtchnl_iwarp_qv_info {
586 	u32 v_idx; /* msix_vector */
587 	u16 ceq_idx;
588 	u16 aeq_idx;
589 	u8 itr_idx;
590 };
591 
592 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
593 
594 struct virtchnl_iwarp_qvlist_info {
595 	u32 num_vectors;
596 	struct virtchnl_iwarp_qv_info qv_info[1];
597 };
598 
599 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
600 
601 #endif
602 
603 /* VF reset states - these are written into the RSTAT register:
604  * VFGEN_RSTAT on the VF
605  * When the PF initiates a reset, it writes 0
606  * When the reset is complete, it writes 1
607  * When the PF detects that the VF has recovered, it writes 2
608  * VF checks this register periodically to determine if a reset has occurred,
609  * then polls it to know when the reset is complete.
610  * If either the PF or VF reads the register while the hardware
611  * is in a reset state, it will return DEADBEEF, which, when masked
612  * will result in 3.
613  */
614 enum virtchnl_vfr_states {
615 	VIRTCHNL_VFR_INPROGRESS = 0,
616 	VIRTCHNL_VFR_COMPLETED,
617 	VIRTCHNL_VFR_VFACTIVE,
618 };
619 
620 /**
621  * virtchnl_vc_validate_vf_msg
622  * @ver: Virtchnl version info
623  * @v_opcode: Opcode for the message
624  * @msg: pointer to the msg buffer
625  * @msglen: msg length
626  *
627  * validate msg format against struct for each opcode
628  */
629 static inline int
virtchnl_vc_validate_vf_msg(struct virtchnl_version_info * ver,u32 v_opcode,u8 * msg,u16 msglen)630 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
631 			    u8 *msg, u16 msglen)
632 {
633 	bool err_msg_format = false;
634 	int valid_len = 0;
635 
636 	/* Validate message length. */
637 	switch (v_opcode) {
638 	case VIRTCHNL_OP_VERSION:
639 		valid_len = sizeof(struct virtchnl_version_info);
640 		break;
641 	case VIRTCHNL_OP_RESET_VF:
642 		break;
643 	case VIRTCHNL_OP_GET_VF_RESOURCES:
644 		if (VF_IS_V11(ver))
645 			valid_len = sizeof(u32);
646 		break;
647 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
648 		valid_len = sizeof(struct virtchnl_txq_info);
649 		break;
650 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
651 		valid_len = sizeof(struct virtchnl_rxq_info);
652 		break;
653 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
654 		valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
655 		if (msglen >= valid_len) {
656 			struct virtchnl_vsi_queue_config_info *vqc =
657 			    (struct virtchnl_vsi_queue_config_info *)msg;
658 			valid_len += (vqc->num_queue_pairs *
659 				      sizeof(struct
660 					     virtchnl_queue_pair_info));
661 			if (vqc->num_queue_pairs == 0)
662 				err_msg_format = true;
663 		}
664 		break;
665 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
666 		valid_len = sizeof(struct virtchnl_irq_map_info);
667 		if (msglen >= valid_len) {
668 			struct virtchnl_irq_map_info *vimi =
669 			    (struct virtchnl_irq_map_info *)msg;
670 			valid_len += (vimi->num_vectors *
671 				      sizeof(struct virtchnl_vector_map));
672 			if (vimi->num_vectors == 0)
673 				err_msg_format = true;
674 		}
675 		break;
676 	case VIRTCHNL_OP_ENABLE_QUEUES:
677 	case VIRTCHNL_OP_DISABLE_QUEUES:
678 		valid_len = sizeof(struct virtchnl_queue_select);
679 		break;
680 	case VIRTCHNL_OP_ADD_ETH_ADDR:
681 	case VIRTCHNL_OP_DEL_ETH_ADDR:
682 		valid_len = sizeof(struct virtchnl_ether_addr_list);
683 		if (msglen >= valid_len) {
684 			struct virtchnl_ether_addr_list *veal =
685 			    (struct virtchnl_ether_addr_list *)msg;
686 			valid_len += veal->num_elements *
687 			    sizeof(struct virtchnl_ether_addr);
688 			if (veal->num_elements == 0)
689 				err_msg_format = true;
690 		}
691 		break;
692 	case VIRTCHNL_OP_ADD_VLAN:
693 	case VIRTCHNL_OP_DEL_VLAN:
694 		valid_len = sizeof(struct virtchnl_vlan_filter_list);
695 		if (msglen >= valid_len) {
696 			struct virtchnl_vlan_filter_list *vfl =
697 			    (struct virtchnl_vlan_filter_list *)msg;
698 			valid_len += vfl->num_elements * sizeof(u16);
699 			if (vfl->num_elements == 0)
700 				err_msg_format = true;
701 		}
702 		break;
703 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
704 		valid_len = sizeof(struct virtchnl_promisc_info);
705 		break;
706 	case VIRTCHNL_OP_GET_STATS:
707 		valid_len = sizeof(struct virtchnl_queue_select);
708 		break;
709 #ifdef VIRTCHNL_IWARP
710 	case VIRTCHNL_OP_IWARP:
711 		/* These messages are opaque to us and will be validated in
712 		 * the RDMA client code. We just need to check for nonzero
713 		 * length. The firmware will enforce max length restrictions.
714 		 */
715 		if (msglen)
716 			valid_len = msglen;
717 		else
718 			err_msg_format = true;
719 		break;
720 	case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
721 		break;
722 	case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
723 		valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
724 		if (msglen >= valid_len) {
725 			struct virtchnl_iwarp_qvlist_info *qv =
726 				(struct virtchnl_iwarp_qvlist_info *)msg;
727 			if (qv->num_vectors == 0) {
728 				err_msg_format = true;
729 				break;
730 			}
731 			valid_len += ((qv->num_vectors - 1) *
732 				sizeof(struct virtchnl_iwarp_qv_info));
733 		}
734 		break;
735 #endif
736 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
737 		valid_len = sizeof(struct virtchnl_rss_key);
738 		if (msglen >= valid_len) {
739 			struct virtchnl_rss_key *vrk =
740 				(struct virtchnl_rss_key *)msg;
741 			valid_len += vrk->key_len - 1;
742 		}
743 		break;
744 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
745 		valid_len = sizeof(struct virtchnl_rss_lut);
746 		if (msglen >= valid_len) {
747 			struct virtchnl_rss_lut *vrl =
748 				(struct virtchnl_rss_lut *)msg;
749 			valid_len += vrl->lut_entries - 1;
750 		}
751 		break;
752 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
753 		break;
754 	case VIRTCHNL_OP_SET_RSS_HENA:
755 		valid_len = sizeof(struct virtchnl_rss_hena);
756 		break;
757 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
758 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
759 		break;
760 	case VIRTCHNL_OP_REQUEST_QUEUES:
761 		valid_len = sizeof(struct virtchnl_vf_res_request);
762 		break;
763 	/* These are always errors coming from the VF. */
764 	case VIRTCHNL_OP_EVENT:
765 	case VIRTCHNL_OP_UNKNOWN:
766 	default:
767 		return VIRTCHNL_STATUS_ERR_PARAM;
768 	}
769 	/* few more checks */
770 	if (err_msg_format || valid_len != msglen)
771 		return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
772 
773 	return 0;
774 }
775 #endif /* _VIRTCHNL_H_ */
776