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