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