xref: /freebsd-11-stable/sys/dev/ixl/virtchnl.h (revision f50bcb8d0bef6414ab58deb08389cfcdcaa8be56)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2019, Intel Corporation
4   All rights reserved.
5 
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are met:
8 
9    1. Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11 
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in the
14       documentation and/or other materials provided with the distribution.
15 
16    3. Neither the name of the Intel Corporation nor the names of its
17       contributors may be used to endorse or promote products derived from
18       this software without specific prior written permission.
19 
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31 
32 ******************************************************************************/
33 /*$FreeBSD$*/
34 
35 
36 #ifndef _VIRTCHNL_H_
37 #define _VIRTCHNL_H_
38 
39 /* Description:
40  * This header file describes the VF-PF communication protocol used
41  * by the drivers for all devices starting from our 40G product line
42  *
43  * Admin queue buffer usage:
44  * desc->opcode is always aqc_opc_send_msg_to_pf
45  * flags, retval, datalen, and data addr are all used normally.
46  * The Firmware copies the cookie fields when sending messages between the
47  * PF and VF, but uses all other fields internally. Due to this limitation,
48  * we must send all messages as "indirect", i.e. using an external buffer.
49  *
50  * All the VSI indexes are relative to the VF. Each VF can have maximum of
51  * three VSIs. All the queue indexes are relative to the VSI.  Each VF can
52  * have a maximum of sixteen queues for all of its VSIs.
53  *
54  * The PF is required to return a status code in v_retval for all messages
55  * except RESET_VF, which does not require any response. The return value
56  * is of status_code type, defined in the shared type.h.
57  *
58  * In general, VF driver initialization should roughly follow the order of
59  * these opcodes. The VF driver must first validate the API version of the
60  * PF driver, then request a reset, then get resources, then configure
61  * queues and interrupts. After these operations are complete, the VF
62  * driver may start its queues, optionally add MAC and VLAN filters, and
63  * process traffic.
64  */
65 
66 /* START GENERIC DEFINES
67  * Need to ensure the following enums and defines hold the same meaning and
68  * value in current and future projects
69  */
70 
71 /* Error Codes */
72 enum virtchnl_status_code {
73 	VIRTCHNL_STATUS_SUCCESS				= 0,
74 	VIRTCHNL_STATUS_ERR_PARAM			= -5,
75 	VIRTCHNL_STATUS_ERR_NO_MEMORY			= -18,
76 	VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH		= -38,
77 	VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR		= -39,
78 	VIRTCHNL_STATUS_ERR_INVALID_VF_ID		= -40,
79 	VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR		= -53,
80 	VIRTCHNL_STATUS_ERR_NOT_SUPPORTED		= -64,
81 };
82 
83 /* Backward compatibility */
84 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
85 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
86 
87 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT		0x0
88 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT		0x1
89 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT	0x2
90 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT		0x3
91 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT		0x4
92 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT		0x5
93 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT		0x6
94 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT		0x7
95 
96 enum virtchnl_link_speed {
97 	VIRTCHNL_LINK_SPEED_UNKNOWN	= 0,
98 	VIRTCHNL_LINK_SPEED_100MB	= BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
99 	VIRTCHNL_LINK_SPEED_1GB		= BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
100 	VIRTCHNL_LINK_SPEED_10GB	= BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
101 	VIRTCHNL_LINK_SPEED_40GB	= BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
102 	VIRTCHNL_LINK_SPEED_20GB	= BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
103 	VIRTCHNL_LINK_SPEED_25GB	= BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
104 	VIRTCHNL_LINK_SPEED_2_5GB	= BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
105 	VIRTCHNL_LINK_SPEED_5GB		= BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
106 };
107 
108 /* for hsplit_0 field of Rx HMC context */
109 /* deprecated with AVF 1.0 */
110 enum virtchnl_rx_hsplit {
111 	VIRTCHNL_RX_HSPLIT_NO_SPLIT      = 0,
112 	VIRTCHNL_RX_HSPLIT_SPLIT_L2      = 1,
113 	VIRTCHNL_RX_HSPLIT_SPLIT_IP      = 2,
114 	VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
115 	VIRTCHNL_RX_HSPLIT_SPLIT_SCTP    = 8,
116 };
117 
118 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS	6
119 /* END GENERIC DEFINES */
120 
121 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
122  * of the virtchnl_msg structure.
123  */
124 enum virtchnl_ops {
125 /* The PF sends status change events to VFs using
126  * the VIRTCHNL_OP_EVENT opcode.
127  * VFs send requests to the PF using the other ops.
128  * Use of "advanced opcode" features must be negotiated as part of capabilities
129  * exchange and are not considered part of base mode feature set.
130  */
131 	VIRTCHNL_OP_UNKNOWN = 0,
132 	VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
133 	VIRTCHNL_OP_RESET_VF = 2,
134 	VIRTCHNL_OP_GET_VF_RESOURCES = 3,
135 	VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
136 	VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
137 	VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
138 	VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
139 	VIRTCHNL_OP_ENABLE_QUEUES = 8,
140 	VIRTCHNL_OP_DISABLE_QUEUES = 9,
141 	VIRTCHNL_OP_ADD_ETH_ADDR = 10,
142 	VIRTCHNL_OP_DEL_ETH_ADDR = 11,
143 	VIRTCHNL_OP_ADD_VLAN = 12,
144 	VIRTCHNL_OP_DEL_VLAN = 13,
145 	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
146 	VIRTCHNL_OP_GET_STATS = 15,
147 	VIRTCHNL_OP_RSVD = 16,
148 	VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
149 	/* opcode 19 is reserved */
150 	VIRTCHNL_OP_IWARP = 20, /* advanced opcode */
151 	VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
152 	VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
153 	VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
154 	VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
155 	VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
156 	VIRTCHNL_OP_SET_RSS_HENA = 26,
157 	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
158 	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
159 	VIRTCHNL_OP_REQUEST_QUEUES = 29,
160 	VIRTCHNL_OP_ENABLE_CHANNELS = 30,
161 	VIRTCHNL_OP_DISABLE_CHANNELS = 31,
162 	VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
163 	VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
164 };
165 
166 /* These macros are used to generate compilation errors if a structure/union
167  * is not exactly the correct length. It gives a divide by zero error if the
168  * structure/union is not of the correct size, otherwise it creates an enum
169  * that is never used.
170  */
171 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
172 	{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
173 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
174 	{ virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
175 
176 /* Virtual channel message descriptor. This overlays the admin queue
177  * descriptor. All other data is passed in external buffers.
178  */
179 
180 struct virtchnl_msg {
181 	u8 pad[8];			 /* AQ flags/opcode/len/retval fields */
182 	enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
183 	enum virtchnl_status_code v_retval;  /* ditto for desc->retval */
184 	u32 vfid;			 /* used by PF when sending to VF */
185 };
186 
187 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
188 
189 /* Message descriptions and data structures. */
190 
191 /* VIRTCHNL_OP_VERSION
192  * VF posts its version number to the PF. PF responds with its version number
193  * in the same format, along with a return code.
194  * Reply from PF has its major/minor versions also in param0 and param1.
195  * If there is a major version mismatch, then the VF cannot operate.
196  * If there is a minor version mismatch, then the VF can operate but should
197  * add a warning to the system log.
198  *
199  * This enum element MUST always be specified as == 1, regardless of other
200  * changes in the API. The PF must always respond to this message without
201  * error regardless of version mismatch.
202  */
203 #define VIRTCHNL_VERSION_MAJOR		1
204 #define VIRTCHNL_VERSION_MINOR		1
205 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS	0
206 
207 struct virtchnl_version_info {
208 	u32 major;
209 	u32 minor;
210 };
211 
212 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
213 
214 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
215 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
216 
217 /* VIRTCHNL_OP_RESET_VF
218  * VF sends this request to PF with no parameters
219  * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
220  * until reset completion is indicated. The admin queue must be reinitialized
221  * after this operation.
222  *
223  * When reset is complete, PF must ensure that all queues in all VSIs associated
224  * with the VF are stopped, all queue configurations in the HMC are set to 0,
225  * and all MAC and VLAN filters (except the default MAC address) on all VSIs
226  * are cleared.
227  */
228 
229 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
230  * vsi_type should always be 6 for backward compatibility. Add other fields
231  * as needed.
232  */
233 enum virtchnl_vsi_type {
234 	VIRTCHNL_VSI_TYPE_INVALID = 0,
235 	VIRTCHNL_VSI_SRIOV = 6,
236 };
237 
238 /* VIRTCHNL_OP_GET_VF_RESOURCES
239  * Version 1.0 VF sends this request to PF with no parameters
240  * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
241  * PF responds with an indirect message containing
242  * virtchnl_vf_resource and one or more
243  * virtchnl_vsi_resource structures.
244  */
245 
246 struct virtchnl_vsi_resource {
247 	u16 vsi_id;
248 	u16 num_queue_pairs;
249 	enum virtchnl_vsi_type vsi_type;
250 	u16 qset_handle;
251 	u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
252 };
253 
254 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
255 
256 /* VF capability flags
257  * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
258  * TX/RX Checksum offloading and TSO for non-tunnelled packets.
259  */
260 #define VIRTCHNL_VF_OFFLOAD_L2			0x00000001
261 #define VIRTCHNL_VF_OFFLOAD_IWARP		0x00000002
262 #define VIRTCHNL_VF_OFFLOAD_RSVD		0x00000004
263 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ		0x00000008
264 #define VIRTCHNL_VF_OFFLOAD_RSS_REG		0x00000010
265 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR		0x00000020
266 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES		0x00000040
267 #define VIRTCHNL_VF_OFFLOAD_CRC			0x00000080
268 #define VIRTCHNL_VF_OFFLOAD_VLAN		0x00010000
269 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING		0x00020000
270 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2	0x00040000
271 #define VIRTCHNL_VF_OFFLOAD_RSS_PF		0X00080000
272 #define VIRTCHNL_VF_OFFLOAD_ENCAP		0X00100000
273 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM		0X00200000
274 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM	0X00400000
275 #define VIRTCHNL_VF_OFFLOAD_ADQ			0X00800000
276 /* Define below the capability flags that are not offloads */
277 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED		0x00000080
278 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
279 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
280 			       VIRTCHNL_VF_OFFLOAD_RSS_PF)
281 
282 struct virtchnl_vf_resource {
283 	u16 num_vsis;
284 	u16 num_queue_pairs;
285 	u16 max_vectors;
286 	u16 max_mtu;
287 
288 	u32 vf_cap_flags;
289 	u32 rss_key_size;
290 	u32 rss_lut_size;
291 
292 	struct virtchnl_vsi_resource vsi_res[1];
293 };
294 
295 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
296 
297 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
298  * VF sends this message to set up parameters for one TX queue.
299  * External data buffer contains one instance of virtchnl_txq_info.
300  * PF configures requested queue and returns a status code.
301  */
302 
303 /* Tx queue config info */
304 struct virtchnl_txq_info {
305 	u16 vsi_id;
306 	u16 queue_id;
307 	u16 ring_len;		/* number of descriptors, multiple of 8 */
308 	u16 headwb_enabled; /* deprecated with AVF 1.0 */
309 	u64 dma_ring_addr;
310 	u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
311 };
312 
313 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
314 
315 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
316  * VF sends this message to set up parameters for one RX queue.
317  * External data buffer contains one instance of virtchnl_rxq_info.
318  * PF configures requested queue and returns a status code. The
319  * crc_disable flag disables CRC stripping on the VF. Setting
320  * the crc_disable flag to 1 will disable CRC stripping for each
321  * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC
322  * offload must have been set prior to sending this info or the PF
323  * will ignore the request. This flag should be set the same for
324  * all of the queues for a VF.
325  */
326 
327 /* Rx queue config info */
328 struct virtchnl_rxq_info {
329 	u16 vsi_id;
330 	u16 queue_id;
331 	u32 ring_len;		/* number of descriptors, multiple of 32 */
332 	u16 hdr_size;
333 	u16 splithdr_enabled; /* deprecated with AVF 1.0 */
334 	u32 databuffer_size;
335 	u32 max_pkt_size;
336 	u8 crc_disable;
337 	u8 pad1[3];
338 	u64 dma_ring_addr;
339 	enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
340 	u32 pad2;
341 };
342 
343 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
344 
345 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
346  * VF sends this message to set parameters for active TX and RX queues
347  * associated with the specified VSI.
348  * PF configures queues and returns status.
349  * If the number of queues specified is greater than the number of queues
350  * associated with the VSI, an error is returned and no queues are configured.
351  * NOTE: The VF is not required to configure all queues in a single request.
352  * It may send multiple messages. PF drivers must correctly handle all VF
353  * requests.
354  */
355 struct virtchnl_queue_pair_info {
356 	/* NOTE: vsi_id and queue_id should be identical for both queues. */
357 	struct virtchnl_txq_info txq;
358 	struct virtchnl_rxq_info rxq;
359 };
360 
361 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
362 
363 struct virtchnl_vsi_queue_config_info {
364 	u16 vsi_id;
365 	u16 num_queue_pairs;
366 	u32 pad;
367 	struct virtchnl_queue_pair_info qpair[1];
368 };
369 
370 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
371 
372 /* VIRTCHNL_OP_REQUEST_QUEUES
373  * VF sends this message to request the PF to allocate additional queues to
374  * this VF.  Each VF gets a guaranteed number of queues on init but asking for
375  * additional queues must be negotiated.  This is a best effort request as it
376  * is possible the PF does not have enough queues left to support the request.
377  * If the PF cannot support the number requested it will respond with the
378  * maximum number it is able to support; otherwise it will respond with the
379  * number requested.
380  */
381 
382 /* VF resource request */
383 struct virtchnl_vf_res_request {
384 	u16 num_queue_pairs;
385 };
386 
387 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
388  * VF uses this message to map vectors to queues.
389  * The rxq_map and txq_map fields are bitmaps used to indicate which queues
390  * are to be associated with the specified vector.
391  * The "other" causes are always mapped to vector 0. The VF may not request
392  * that vector 0 be used for traffic.
393  * PF configures interrupt mapping and returns status.
394  * NOTE: due to hardware requirements, all active queues (both TX and RX)
395  * should be mapped to interrupts, even if the driver intends to operate
396  * only in polling mode. In this case the interrupt may be disabled, but
397  * the ITR timer will still run to trigger writebacks.
398  */
399 struct virtchnl_vector_map {
400 	u16 vsi_id;
401 	u16 vector_id;
402 	u16 rxq_map;
403 	u16 txq_map;
404 	u16 rxitr_idx;
405 	u16 txitr_idx;
406 };
407 
408 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
409 
410 struct virtchnl_irq_map_info {
411 	u16 num_vectors;
412 	struct virtchnl_vector_map vecmap[1];
413 };
414 
415 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
416 
417 /* VIRTCHNL_OP_ENABLE_QUEUES
418  * VIRTCHNL_OP_DISABLE_QUEUES
419  * VF sends these message to enable or disable TX/RX queue pairs.
420  * The queues fields are bitmaps indicating which queues to act upon.
421  * (Currently, we only support 16 queues per VF, but we make the field
422  * u32 to allow for expansion.)
423  * PF performs requested action and returns status.
424  * NOTE: The VF is not required to enable/disable all queues in a single
425  * request. It may send multiple messages.
426  * PF drivers must correctly handle all VF requests.
427  */
428 struct virtchnl_queue_select {
429 	u16 vsi_id;
430 	u16 pad;
431 	u32 rx_queues;
432 	u32 tx_queues;
433 };
434 
435 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
436 
437 /* VIRTCHNL_OP_ADD_ETH_ADDR
438  * VF sends this message in order to add one or more unicast or multicast
439  * address filters for the specified VSI.
440  * PF adds the filters and returns status.
441  */
442 
443 /* VIRTCHNL_OP_DEL_ETH_ADDR
444  * VF sends this message in order to remove one or more unicast or multicast
445  * filters for the specified VSI.
446  * PF removes the filters and returns status.
447  */
448 
449 struct virtchnl_ether_addr {
450 	u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
451 	u8 pad[2];
452 };
453 
454 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
455 
456 struct virtchnl_ether_addr_list {
457 	u16 vsi_id;
458 	u16 num_elements;
459 	struct virtchnl_ether_addr list[1];
460 };
461 
462 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
463 
464 /* VIRTCHNL_OP_ADD_VLAN
465  * VF sends this message to add one or more VLAN tag filters for receives.
466  * PF adds the filters and returns status.
467  * If a port VLAN is configured by the PF, this operation will return an
468  * error to the VF.
469  */
470 
471 /* VIRTCHNL_OP_DEL_VLAN
472  * VF sends this message to remove one or more VLAN tag filters for receives.
473  * PF removes the filters and returns status.
474  * If a port VLAN is configured by the PF, this operation will return an
475  * error to the VF.
476  */
477 
478 struct virtchnl_vlan_filter_list {
479 	u16 vsi_id;
480 	u16 num_elements;
481 	u16 vlan_id[1];
482 };
483 
484 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
485 
486 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
487  * VF sends VSI id and flags.
488  * PF returns status code in retval.
489  * Note: we assume that broadcast accept mode is always enabled.
490  */
491 struct virtchnl_promisc_info {
492 	u16 vsi_id;
493 	u16 flags;
494 };
495 
496 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
497 
498 #define FLAG_VF_UNICAST_PROMISC	0x00000001
499 #define FLAG_VF_MULTICAST_PROMISC	0x00000002
500 
501 /* VIRTCHNL_OP_GET_STATS
502  * VF sends this message to request stats for the selected VSI. VF uses
503  * the virtchnl_queue_select struct to specify the VSI. The queue_id
504  * field is ignored by the PF.
505  *
506  * PF replies with struct virtchnl_eth_stats in an external buffer.
507  */
508 
509 struct virtchnl_eth_stats {
510 	u64 rx_bytes;			/* received bytes */
511 	u64 rx_unicast;			/* received unicast pkts */
512 	u64 rx_multicast;		/* received multicast pkts */
513 	u64 rx_broadcast;		/* received broadcast pkts */
514 	u64 rx_discards;
515 	u64 rx_unknown_protocol;
516 	u64 tx_bytes;			/* transmitted bytes */
517 	u64 tx_unicast;			/* transmitted unicast pkts */
518 	u64 tx_multicast;		/* transmitted multicast pkts */
519 	u64 tx_broadcast;		/* transmitted broadcast pkts */
520 	u64 tx_discards;
521 	u64 tx_errors;
522 };
523 
524 /* VIRTCHNL_OP_CONFIG_RSS_KEY
525  * VIRTCHNL_OP_CONFIG_RSS_LUT
526  * VF sends these messages to configure RSS. Only supported if both PF
527  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
528  * configuration negotiation. If this is the case, then the RSS fields in
529  * the VF resource struct are valid.
530  * Both the key and LUT are initialized to 0 by the PF, meaning that
531  * RSS is effectively disabled until set up by the VF.
532  */
533 struct virtchnl_rss_key {
534 	u16 vsi_id;
535 	u16 key_len;
536 	u8 key[1];         /* RSS hash key, packed bytes */
537 };
538 
539 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
540 
541 struct virtchnl_rss_lut {
542 	u16 vsi_id;
543 	u16 lut_entries;
544 	u8 lut[1];        /* RSS lookup table */
545 };
546 
547 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
548 
549 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
550  * VIRTCHNL_OP_SET_RSS_HENA
551  * VF sends these messages to get and set the hash filter enable bits for RSS.
552  * By default, the PF sets these to all possible traffic types that the
553  * hardware supports. The VF can query this value if it wants to change the
554  * traffic types that are hashed by the hardware.
555  */
556 struct virtchnl_rss_hena {
557 	u64 hena;
558 };
559 
560 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
561 
562 /* VIRTCHNL_OP_ENABLE_CHANNELS
563  * VIRTCHNL_OP_DISABLE_CHANNELS
564  * VF sends these messages to enable or disable channels based on
565  * the user specified queue count and queue offset for each traffic class.
566  * This struct encompasses all the information that the PF needs from
567  * VF to create a channel.
568  */
569 struct virtchnl_channel_info {
570 	u16 count; /* number of queues in a channel */
571 	u16 offset; /* queues in a channel start from 'offset' */
572 	u32 pad;
573 	u64 max_tx_rate;
574 };
575 
576 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
577 
578 struct virtchnl_tc_info {
579 	u32	num_tc;
580 	u32	pad;
581 	struct	virtchnl_channel_info list[1];
582 };
583 
584 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
585 
586 /* VIRTCHNL_ADD_CLOUD_FILTER
587  * VIRTCHNL_DEL_CLOUD_FILTER
588  * VF sends these messages to add or delete a cloud filter based on the
589  * user specified match and action filters. These structures encompass
590  * all the information that the PF needs from the VF to add/delete a
591  * cloud filter.
592  */
593 
594 struct virtchnl_l4_spec {
595 	u8	src_mac[ETH_ALEN];
596 	u8	dst_mac[ETH_ALEN];
597 	__be16	vlan_id;
598 	__be16	pad; /* reserved for future use */
599 	__be32	src_ip[4];
600 	__be32	dst_ip[4];
601 	__be16	src_port;
602 	__be16	dst_port;
603 };
604 
605 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
606 
607 union virtchnl_flow_spec {
608 	struct	virtchnl_l4_spec tcp_spec;
609 	u8	buffer[128]; /* reserved for future use */
610 };
611 
612 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
613 
614 enum virtchnl_action {
615 	/* action types */
616 	VIRTCHNL_ACTION_DROP = 0,
617 	VIRTCHNL_ACTION_TC_REDIRECT,
618 };
619 
620 enum virtchnl_flow_type {
621 	/* flow types */
622 	VIRTCHNL_TCP_V4_FLOW = 0,
623 	VIRTCHNL_TCP_V6_FLOW,
624 };
625 
626 struct virtchnl_filter {
627 	union	virtchnl_flow_spec data;
628 	union	virtchnl_flow_spec mask;
629 	enum	virtchnl_flow_type flow_type;
630 	enum	virtchnl_action action;
631 	u32	action_meta;
632 	u8	field_flags;
633 };
634 
635 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
636 
637 /* VIRTCHNL_OP_EVENT
638  * PF sends this message to inform the VF driver of events that may affect it.
639  * No direct response is expected from the VF, though it may generate other
640  * messages in response to this one.
641  */
642 enum virtchnl_event_codes {
643 	VIRTCHNL_EVENT_UNKNOWN = 0,
644 	VIRTCHNL_EVENT_LINK_CHANGE,
645 	VIRTCHNL_EVENT_RESET_IMPENDING,
646 	VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
647 };
648 
649 #define PF_EVENT_SEVERITY_INFO		0
650 #define PF_EVENT_SEVERITY_ATTENTION	1
651 #define PF_EVENT_SEVERITY_ACTION_REQUIRED	2
652 #define PF_EVENT_SEVERITY_CERTAIN_DOOM	255
653 
654 struct virtchnl_pf_event {
655 	enum virtchnl_event_codes event;
656 	union {
657 		/* If the PF driver does not support the new speed reporting
658 		 * capabilities then use link_event else use link_event_adv to
659 		 * get the speed and link information. The ability to understand
660 		 * new speeds is indicated by setting the capability flag
661 		 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
662 		 * in virtchnl_vf_resource struct and can be used to determine
663 		 * which link event struct to use below.
664 		 */
665 		struct {
666 			enum virtchnl_link_speed link_speed;
667 			u8 link_status;
668 		} link_event;
669 		struct {
670 			/* link_speed provided in Mbps */
671 			u32 link_speed;
672 			u8 link_status;
673 		} link_event_adv;
674 	} event_data;
675 
676 	int severity;
677 };
678 
679 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
680 
681 
682 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
683  * VF uses this message to request PF to map IWARP vectors to IWARP queues.
684  * The request for this originates from the VF IWARP driver through
685  * a client interface between VF LAN and VF IWARP driver.
686  * A vector could have an AEQ and CEQ attached to it although
687  * there is a single AEQ per VF IWARP instance in which case
688  * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
689  * There will never be a case where there will be multiple CEQs attached
690  * to a single vector.
691  * PF configures interrupt mapping and returns status.
692  */
693 struct virtchnl_iwarp_qv_info {
694 	u32 v_idx; /* msix_vector */
695 	u16 ceq_idx;
696 	u16 aeq_idx;
697 	u8 itr_idx;
698 };
699 
700 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
701 
702 struct virtchnl_iwarp_qvlist_info {
703 	u32 num_vectors;
704 	struct virtchnl_iwarp_qv_info qv_info[1];
705 };
706 
707 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
708 
709 
710 /* Since VF messages are limited by u16 size, precalculate the maximum possible
711  * values of nested elements in virtchnl structures that virtual channel can
712  * possibly handle in a single message.
713  */
714 enum virtchnl_vector_limits {
715 	VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX	=
716 		((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) /
717 		sizeof(struct virtchnl_queue_pair_info),
718 
719 	VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX		=
720 		((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) /
721 		sizeof(struct virtchnl_vector_map),
722 
723 	VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX	=
724 		((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) /
725 		sizeof(struct virtchnl_ether_addr),
726 
727 	VIRTCHNL_OP_ADD_DEL_VLAN_MAX		=
728 		((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) /
729 		sizeof(u16),
730 
731 	VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP_MAX	=
732 		((u16)(~0) - sizeof(struct virtchnl_iwarp_qvlist_info)) /
733 		sizeof(struct virtchnl_iwarp_qv_info),
734 
735 	VIRTCHNL_OP_ENABLE_CHANNELS_MAX		=
736 		((u16)(~0) - sizeof(struct virtchnl_tc_info)) /
737 		sizeof(struct virtchnl_channel_info),
738 };
739 
740 /* VF reset states - these are written into the RSTAT register:
741  * VFGEN_RSTAT on the VF
742  * When the PF initiates a reset, it writes 0
743  * When the reset is complete, it writes 1
744  * When the PF detects that the VF has recovered, it writes 2
745  * VF checks this register periodically to determine if a reset has occurred,
746  * then polls it to know when the reset is complete.
747  * If either the PF or VF reads the register while the hardware
748  * is in a reset state, it will return DEADBEEF, which, when masked
749  * will result in 3.
750  */
751 enum virtchnl_vfr_states {
752 	VIRTCHNL_VFR_INPROGRESS = 0,
753 	VIRTCHNL_VFR_COMPLETED,
754 	VIRTCHNL_VFR_VFACTIVE,
755 };
756 
757 /**
758  * virtchnl_vc_validate_vf_msg
759  * @ver: Virtchnl version info
760  * @v_opcode: Opcode for the message
761  * @msg: pointer to the msg buffer
762  * @msglen: msg length
763  *
764  * validate msg format against struct for each opcode
765  */
766 static inline int
virtchnl_vc_validate_vf_msg(struct virtchnl_version_info * ver,u32 v_opcode,u8 * msg,u16 msglen)767 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
768 			    u8 *msg, u16 msglen)
769 {
770 	bool err_msg_format = FALSE;
771 	int valid_len = 0;
772 
773 	/* Validate message length. */
774 	switch (v_opcode) {
775 	case VIRTCHNL_OP_VERSION:
776 		valid_len = sizeof(struct virtchnl_version_info);
777 		break;
778 	case VIRTCHNL_OP_RESET_VF:
779 		break;
780 	case VIRTCHNL_OP_GET_VF_RESOURCES:
781 		if (VF_IS_V11(ver))
782 			valid_len = sizeof(u32);
783 		break;
784 	case VIRTCHNL_OP_CONFIG_TX_QUEUE:
785 		valid_len = sizeof(struct virtchnl_txq_info);
786 		break;
787 	case VIRTCHNL_OP_CONFIG_RX_QUEUE:
788 		valid_len = sizeof(struct virtchnl_rxq_info);
789 		break;
790 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
791 		valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
792 		if (msglen >= valid_len) {
793 			struct virtchnl_vsi_queue_config_info *vqc =
794 			    (struct virtchnl_vsi_queue_config_info *)msg;
795 
796 			if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs >
797 			    VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) {
798 				err_msg_format = TRUE;
799 				break;
800 			}
801 
802 			valid_len += (vqc->num_queue_pairs *
803 				      sizeof(struct
804 					     virtchnl_queue_pair_info));
805 		}
806 		break;
807 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
808 		valid_len = sizeof(struct virtchnl_irq_map_info);
809 		if (msglen >= valid_len) {
810 			struct virtchnl_irq_map_info *vimi =
811 			    (struct virtchnl_irq_map_info *)msg;
812 
813 			if (vimi->num_vectors == 0 || vimi->num_vectors >
814 			    VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) {
815 				err_msg_format = TRUE;
816 				break;
817 			}
818 
819 			valid_len += (vimi->num_vectors *
820 				      sizeof(struct virtchnl_vector_map));
821 		}
822 		break;
823 	case VIRTCHNL_OP_ENABLE_QUEUES:
824 	case VIRTCHNL_OP_DISABLE_QUEUES:
825 		valid_len = sizeof(struct virtchnl_queue_select);
826 		break;
827 	case VIRTCHNL_OP_ADD_ETH_ADDR:
828 	case VIRTCHNL_OP_DEL_ETH_ADDR:
829 		valid_len = sizeof(struct virtchnl_ether_addr_list);
830 		if (msglen >= valid_len) {
831 			struct virtchnl_ether_addr_list *veal =
832 			    (struct virtchnl_ether_addr_list *)msg;
833 
834 			if (veal->num_elements == 0 || veal->num_elements >
835 			    VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) {
836 				err_msg_format = TRUE;
837 				break;
838 			}
839 
840 			valid_len += veal->num_elements *
841 			    sizeof(struct virtchnl_ether_addr);
842 		}
843 		break;
844 	case VIRTCHNL_OP_ADD_VLAN:
845 	case VIRTCHNL_OP_DEL_VLAN:
846 		valid_len = sizeof(struct virtchnl_vlan_filter_list);
847 		if (msglen >= valid_len) {
848 			struct virtchnl_vlan_filter_list *vfl =
849 			    (struct virtchnl_vlan_filter_list *)msg;
850 
851 			if (vfl->num_elements == 0 || vfl->num_elements >
852 			    VIRTCHNL_OP_ADD_DEL_VLAN_MAX) {
853 				err_msg_format = TRUE;
854 				break;
855 			}
856 
857 			valid_len += vfl->num_elements * sizeof(u16);
858 		}
859 		break;
860 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
861 		valid_len = sizeof(struct virtchnl_promisc_info);
862 		break;
863 	case VIRTCHNL_OP_GET_STATS:
864 		valid_len = sizeof(struct virtchnl_queue_select);
865 		break;
866 	case VIRTCHNL_OP_IWARP:
867 		/* These messages are opaque to us and will be validated in
868 		 * the RDMA client code. We just need to check for nonzero
869 		 * length. The firmware will enforce max length restrictions.
870 		 */
871 		if (msglen)
872 			valid_len = msglen;
873 		else
874 			err_msg_format = TRUE;
875 		break;
876 	case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
877 		break;
878 	case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
879 		valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
880 		if (msglen >= valid_len) {
881 			struct virtchnl_iwarp_qvlist_info *qv =
882 				(struct virtchnl_iwarp_qvlist_info *)msg;
883 
884 			if (qv->num_vectors == 0 || qv->num_vectors >
885 			    VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP_MAX) {
886 				err_msg_format = TRUE;
887 				break;
888 			}
889 
890 			valid_len += ((qv->num_vectors - 1) *
891 				sizeof(struct virtchnl_iwarp_qv_info));
892 		}
893 		break;
894 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
895 		valid_len = sizeof(struct virtchnl_rss_key);
896 		if (msglen >= valid_len) {
897 			struct virtchnl_rss_key *vrk =
898 				(struct virtchnl_rss_key *)msg;
899 			valid_len += vrk->key_len - 1;
900 		}
901 		break;
902 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
903 		valid_len = sizeof(struct virtchnl_rss_lut);
904 		if (msglen >= valid_len) {
905 			struct virtchnl_rss_lut *vrl =
906 				(struct virtchnl_rss_lut *)msg;
907 			valid_len += vrl->lut_entries - 1;
908 		}
909 		break;
910 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
911 		break;
912 	case VIRTCHNL_OP_SET_RSS_HENA:
913 		valid_len = sizeof(struct virtchnl_rss_hena);
914 		break;
915 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
916 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
917 		break;
918 	case VIRTCHNL_OP_REQUEST_QUEUES:
919 		valid_len = sizeof(struct virtchnl_vf_res_request);
920 		break;
921 	case VIRTCHNL_OP_ENABLE_CHANNELS:
922 		valid_len = sizeof(struct virtchnl_tc_info);
923 		if (msglen >= valid_len) {
924 			struct virtchnl_tc_info *vti =
925 				(struct virtchnl_tc_info *)msg;
926 
927 			if (vti->num_tc == 0 || vti->num_tc >
928 			    VIRTCHNL_OP_ENABLE_CHANNELS_MAX) {
929 				err_msg_format = TRUE;
930 				break;
931 			}
932 
933 			valid_len += (vti->num_tc - 1) *
934 				     sizeof(struct virtchnl_channel_info);
935 		}
936 		break;
937 	case VIRTCHNL_OP_DISABLE_CHANNELS:
938 		break;
939 	case VIRTCHNL_OP_ADD_CLOUD_FILTER:
940 		/* fall through */
941 	case VIRTCHNL_OP_DEL_CLOUD_FILTER:
942 		valid_len = sizeof(struct virtchnl_filter);
943 		break;
944 	/* These are always errors coming from the VF. */
945 	case VIRTCHNL_OP_EVENT:
946 	case VIRTCHNL_OP_UNKNOWN:
947 	default:
948 		return VIRTCHNL_STATUS_ERR_PARAM;
949 	}
950 	/* few more checks */
951 	if (err_msg_format || valid_len != msglen)
952 		return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
953 
954 	return 0;
955 }
956 #endif /* _VIRTCHNL_H_ */
957