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