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