1 /******************************************************************************
2
3 Copyright (c) 2013-2018, Intel Corporation
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32 ******************************************************************************/
33 /*$FreeBSD$*/
34
35 #ifndef _VIRTCHNL_H_
36 #define _VIRTCHNL_H_
37
38 /* Description:
39 * This header file describes the VF-PF communication protocol used
40 * by the drivers for all devices starting from our 40G product line
41 *
42 * Admin queue buffer usage:
43 * desc->opcode is always aqc_opc_send_msg_to_pf
44 * flags, retval, datalen, and data addr are all used normally.
45 * The Firmware copies the cookie fields when sending messages between the
46 * PF and VF, but uses all other fields internally. Due to this limitation,
47 * we must send all messages as "indirect", i.e. using an external buffer.
48 *
49 * All the VSI indexes are relative to the VF. Each VF can have maximum of
50 * three VSIs. All the queue indexes are relative to the VSI. Each VF can
51 * have a maximum of sixteen queues for all of its VSIs.
52 *
53 * The PF is required to return a status code in v_retval for all messages
54 * except RESET_VF, which does not require any response. The return value
55 * is of status_code type, defined in the shared type.h.
56 *
57 * In general, VF driver initialization should roughly follow the order of
58 * these opcodes. The VF driver must first validate the API version of the
59 * PF driver, then request a reset, then get resources, then configure
60 * queues and interrupts. After these operations are complete, the VF
61 * driver may start its queues, optionally add MAC and VLAN filters, and
62 * process traffic.
63 */
64
65 /* START GENERIC DEFINES
66 * Need to ensure the following enums and defines hold the same meaning and
67 * value in current and future projects
68 */
69
70 /* Error Codes */
71 enum virtchnl_status_code {
72 VIRTCHNL_STATUS_SUCCESS = 0,
73 VIRTCHNL_ERR_PARAM = -5,
74 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38,
75 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39,
76 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40,
77 VIRTCHNL_STATUS_NOT_SUPPORTED = -64,
78 };
79
80 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT 0x0
81 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1
82 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2
83 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3
84 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4
85 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5
86 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6
87 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT 0x7
88
89 enum virtchnl_link_speed {
90 VIRTCHNL_LINK_SPEED_UNKNOWN = 0,
91 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
92 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
93 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
94 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
95 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
96 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
97 VIRTCHNL_LINK_SPEED_2_5GB = BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
98 VIRTCHNL_LINK_SPEED_5GB = BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
99 };
122 * exchange and are not considered part of base mode feature set.
123 */
124 VIRTCHNL_OP_UNKNOWN = 0,
125 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
126 VIRTCHNL_OP_RESET_VF = 2,
127 VIRTCHNL_OP_GET_VF_RESOURCES = 3,
128 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
129 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
130 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
131 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
132 VIRTCHNL_OP_ENABLE_QUEUES = 8,
133 VIRTCHNL_OP_DISABLE_QUEUES = 9,
134 VIRTCHNL_OP_ADD_ETH_ADDR = 10,
135 VIRTCHNL_OP_DEL_ETH_ADDR = 11,
136 VIRTCHNL_OP_ADD_VLAN = 12,
137 VIRTCHNL_OP_DEL_VLAN = 13,
138 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
139 VIRTCHNL_OP_GET_STATS = 15,
140 VIRTCHNL_OP_RSVD = 16,
141 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
142 VIRTCHNL_OP_IWARP = 20, /* advanced opcode */
143 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
144 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
145 VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
146 VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
147 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
148 VIRTCHNL_OP_SET_RSS_HENA = 26,
149 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
150 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
151 VIRTCHNL_OP_REQUEST_QUEUES = 29,
152
153 };
154
155 /* This macro is used to generate a compilation error if a structure
156 * is not exactly the correct length. It gives a divide by zero error if the
157 * structure is not of the correct size, otherwise it creates an enum that is
158 * never used.
159 */
160 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
161 {virtchnl_static_assert_##X = (n) / ((sizeof(struct X) == (n)) ? 1 : 0)}
162
163 /* Virtual channel message descriptor. This overlays the admin queue
164 * descriptor. All other data is passed in external buffers.
165 */
166
167 struct virtchnl_msg {
168 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
169 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
170 enum virtchnl_status_code v_retval; /* ditto for desc->retval */
171 u32 vfid; /* used by PF when sending to VF */
172 };
173
174 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
175
176 /* Message descriptions and data structures.*/
177
178 /* VIRTCHNL_OP_VERSION
179 * VF posts its version number to the PF. PF responds with its version number
180 * in the same format, along with a return code.
181 * Reply from PF has its major/minor versions also in param0 and param1.
182 * If there is a major version mismatch, then the VF cannot operate.
183 * If there is a minor version mismatch, then the VF can operate but should
184 * add a warning to the system log.
185 *
186 * This enum element MUST always be specified as == 1, regardless of other
187 * changes in the API. The PF must always respond to this message without
188 * error regardless of version mismatch.
189 */
190 #define VIRTCHNL_VERSION_MAJOR 1
191 #define VIRTCHNL_VERSION_MINOR 1
192 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
193
194 struct virtchnl_version_info {
195 u32 major;
196 u32 minor;
197 };
198
199 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
200
201 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
202 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
203
204 /* VIRTCHNL_OP_RESET_VF
205 * VF sends this request to PF with no parameters
206 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
207 * until reset completion is indicated. The admin queue must be reinitialized
208 * after this operation.
209 *
210 * When reset is complete, PF must ensure that all queues in all VSIs associated
211 * with the VF are stopped, all queue configurations in the HMC are set to 0,
216 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
217 * vsi_type should always be 6 for backward compatibility. Add other fields
218 * as needed.
219 */
220 enum virtchnl_vsi_type {
221 VIRTCHNL_VSI_TYPE_INVALID = 0,
222 VIRTCHNL_VSI_SRIOV = 6,
223 };
224
225 /* VIRTCHNL_OP_GET_VF_RESOURCES
226 * Version 1.0 VF sends this request to PF with no parameters
227 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
228 * PF responds with an indirect message containing
229 * virtchnl_vf_resource and one or more
230 * virtchnl_vsi_resource structures.
231 */
232
233 struct virtchnl_vsi_resource {
234 u16 vsi_id;
235 u16 num_queue_pairs;
236 enum virtchnl_vsi_type vsi_type;
237 u16 qset_handle;
238 u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
239 };
240
241 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
242
243 /* VF capability flags
244 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
245 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
246 */
247 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001
248 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002
249 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004
250 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008
251 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010
252 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020
253 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040
254 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000
255 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000
256 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000
257 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000
258 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000
259 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000
260 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000
261
262 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
263 VIRTCHNL_VF_OFFLOAD_VLAN | \
264 VIRTCHNL_VF_OFFLOAD_RSS_PF)
265
266 struct virtchnl_vf_resource {
267 u16 num_vsis;
268 u16 num_queue_pairs;
269 u16 max_vectors;
270 u16 max_mtu;
271
272 u32 vf_cap_flags;
273 u32 rss_key_size;
274 u32 rss_lut_size;
275
276 struct virtchnl_vsi_resource vsi_res[1];
277 };
278
279 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
280
281 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
282 * VF sends this message to set up parameters for one TX queue.
283 * External data buffer contains one instance of virtchnl_txq_info.
284 * PF configures requested queue and returns a status code.
285 */
286
287 /* Tx queue config info */
288 struct virtchnl_txq_info {
289 u16 vsi_id;
290 u16 queue_id;
291 u16 ring_len; /* number of descriptors, multiple of 8 */
292 u16 headwb_enabled; /* deprecated with AVF 1.0 */
293 u64 dma_ring_addr;
294 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
295 };
296
297 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
298
299 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
300 * VF sends this message to set up parameters for one RX queue.
301 * External data buffer contains one instance of virtchnl_rxq_info.
302 * PF configures requested queue and returns a status code.
303 */
304
305 /* Rx queue config info */
306 struct virtchnl_rxq_info {
307 u16 vsi_id;
308 u16 queue_id;
309 u32 ring_len; /* number of descriptors, multiple of 32 */
310 u16 hdr_size;
311 u16 splithdr_enabled; /* deprecated with AVF 1.0 */
312 u32 databuffer_size;
313 u32 max_pkt_size;
314 u32 pad1;
315 u64 dma_ring_addr;
316 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
317 u32 pad2;
318 };
319
320 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
321
322 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
323 * VF sends this message to set parameters for all active TX and RX queues
324 * associated with the specified VSI.
325 * PF configures queues and returns status.
326 * If the number of queues specified is greater than the number of queues
327 * associated with the VSI, an error is returned and no queues are configured.
328 */
329 struct virtchnl_queue_pair_info {
330 /* NOTE: vsi_id and queue_id should be identical for both queues. */
331 struct virtchnl_txq_info txq;
332 struct virtchnl_rxq_info rxq;
333 };
334
335 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
336
337 struct virtchnl_vsi_queue_config_info {
338 u16 vsi_id;
339 u16 num_queue_pairs;
340 u32 pad;
341 struct virtchnl_queue_pair_info qpair[1];
342 };
343
344 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
345
346 /* VIRTCHNL_OP_REQUEST_QUEUES
347 * VF sends this message to request the PF to allocate additional queues to
348 * this VF. Each VF gets a guaranteed number of queues on init but asking for
349 * additional queues must be negotiated. This is a best effort request as it
350 * is possible the PF does not have enough queues left to support the request.
351 * If the PF cannot support the number requested it will respond with the
352 * maximum number it is able to support; otherwise it will respond with the
353 * number requested.
354 */
355
356 /* VF resource request */
357 struct virtchnl_vf_res_request {
358 u16 num_queue_pairs;
359 };
360
361 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
362 * VF uses this message to map vectors to queues.
363 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
364 * are to be associated with the specified vector.
365 * The "other" causes are always mapped to vector 0.
366 * PF configures interrupt mapping and returns status.
367 */
368 struct virtchnl_vector_map {
369 u16 vsi_id;
370 u16 vector_id;
371 u16 rxq_map;
372 u16 txq_map;
373 u16 rxitr_idx;
374 u16 txitr_idx;
375 };
376
377 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
378
379 struct virtchnl_irq_map_info {
380 u16 num_vectors;
381 struct virtchnl_vector_map vecmap[1];
382 };
383
384 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
385
386 /* VIRTCHNL_OP_ENABLE_QUEUES
387 * VIRTCHNL_OP_DISABLE_QUEUES
388 * VF sends these message to enable or disable TX/RX queue pairs.
389 * The queues fields are bitmaps indicating which queues to act upon.
390 * (Currently, we only support 16 queues per VF, but we make the field
391 * u32 to allow for expansion.)
392 * PF performs requested action and returns status.
393 */
394 struct virtchnl_queue_select {
395 u16 vsi_id;
396 u16 pad;
397 u32 rx_queues;
398 u32 tx_queues;
399 };
400
401 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
402
403 /* VIRTCHNL_OP_ADD_ETH_ADDR
404 * VF sends this message in order to add one or more unicast or multicast
405 * address filters for the specified VSI.
406 * PF adds the filters and returns status.
407 */
408
409 /* VIRTCHNL_OP_DEL_ETH_ADDR
410 * VF sends this message in order to remove one or more unicast or multicast
411 * filters for the specified VSI.
412 * PF removes the filters and returns status.
413 */
414
415 struct virtchnl_ether_addr {
416 u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
417 u8 pad[2];
418 };
419
420 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
421
422 struct virtchnl_ether_addr_list {
423 u16 vsi_id;
424 u16 num_elements;
425 struct virtchnl_ether_addr list[1];
426 };
427
428 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
429
430 /* VIRTCHNL_OP_ADD_VLAN
431 * VF sends this message to add one or more VLAN tag filters for receives.
432 * PF adds the filters and returns status.
433 * If a port VLAN is configured by the PF, this operation will return an
434 * error to the VF.
435 */
436
437 /* VIRTCHNL_OP_DEL_VLAN
438 * VF sends this message to remove one or more VLAN tag filters for receives.
439 * PF removes the filters and returns status.
440 * If a port VLAN is configured by the PF, this operation will return an
441 * error to the VF.
442 */
443
444 struct virtchnl_vlan_filter_list {
445 u16 vsi_id;
446 u16 num_elements;
447 u16 vlan_id[1];
448 };
449
450 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
451
452 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
453 * VF sends VSI id and flags.
454 * PF returns status code in retval.
455 * Note: we assume that broadcast accept mode is always enabled.
456 */
457 struct virtchnl_promisc_info {
458 u16 vsi_id;
459 u16 flags;
460 };
461
462 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
463
464 #define FLAG_VF_UNICAST_PROMISC 0x00000001
465 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
466
467 /* VIRTCHNL_OP_GET_STATS
468 * VF sends this message to request stats for the selected VSI. VF uses
469 * the virtchnl_queue_select struct to specify the VSI. The queue_id
470 * field is ignored by the PF.
471 *
472 * PF replies with struct eth_stats in an external buffer.
473 */
474
475 /* VIRTCHNL_OP_CONFIG_RSS_KEY
476 * VIRTCHNL_OP_CONFIG_RSS_LUT
477 * VF sends these messages to configure RSS. Only supported if both PF
478 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
479 * configuration negotiation. If this is the case, then the RSS fields in
480 * the VF resource struct are valid.
481 * Both the key and LUT are initialized to 0 by the PF, meaning that
482 * RSS is effectively disabled until set up by the VF.
483 */
484 struct virtchnl_rss_key {
485 u16 vsi_id;
486 u16 key_len;
487 u8 key[1]; /* RSS hash key, packed bytes */
488 };
489
490 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
491
492 struct virtchnl_rss_lut {
493 u16 vsi_id;
494 u16 lut_entries;
495 u8 lut[1]; /* RSS lookup table */
496 };
497
498 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
499
500 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
501 * VIRTCHNL_OP_SET_RSS_HENA
502 * VF sends these messages to get and set the hash filter enable bits for RSS.
503 * By default, the PF sets these to all possible traffic types that the
504 * hardware supports. The VF can query this value if it wants to change the
505 * traffic types that are hashed by the hardware.
506 */
507 struct virtchnl_rss_hena {
508 u64 hena;
509 };
510
511 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
512
513 /* VIRTCHNL_OP_EVENT
514 * PF sends this message to inform the VF driver of events that may affect it.
515 * No direct response is expected from the VF, though it may generate other
516 * messages in response to this one.
517 */
518 enum virtchnl_event_codes {
519 VIRTCHNL_EVENT_UNKNOWN = 0,
520 VIRTCHNL_EVENT_LINK_CHANGE,
521 VIRTCHNL_EVENT_RESET_IMPENDING,
522 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
523 };
524
525 #define PF_EVENT_SEVERITY_INFO 0
526 #define PF_EVENT_SEVERITY_ATTENTION 1
527 #define PF_EVENT_SEVERITY_ACTION_REQUIRED 2
528 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
529
530 struct virtchnl_pf_event {
531 enum virtchnl_event_codes event;
532 union {
533 struct {
534 enum virtchnl_link_speed link_speed;
535 bool link_status;
536 } link_event;
537 } event_data;
538
539 int severity;
540 };
541
542 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
543
544
545 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
546 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
547 * The request for this originates from the VF IWARP driver through
548 * a client interface between VF LAN and VF IWARP driver.
549 * A vector could have an AEQ and CEQ attached to it although
550 * there is a single AEQ per VF IWARP instance in which case
551 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
552 * There will never be a case where there will be multiple CEQs attached
553 * to a single vector.
554 * PF configures interrupt mapping and returns status.
555 */
556
557 /* HW does not define a type value for AEQ; only for RX/TX and CEQ.
558 * In order for us to keep the interface simple, SW will define a
559 * unique type value for AEQ.
560 */
561 #define QUEUE_TYPE_PE_AEQ 0x80
562 #define QUEUE_INVALID_IDX 0xFFFF
563
564 struct virtchnl_iwarp_qv_info {
565 u32 v_idx; /* msix_vector */
566 u16 ceq_idx;
567 u16 aeq_idx;
568 u8 itr_idx;
569 };
570
571 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
572
573 struct virtchnl_iwarp_qvlist_info {
574 u32 num_vectors;
575 struct virtchnl_iwarp_qv_info qv_info[1];
576 };
577
578 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
579
580
581 /* VF reset states - these are written into the RSTAT register:
582 * VFGEN_RSTAT on the VF
583 * When the PF initiates a reset, it writes 0
584 * When the reset is complete, it writes 1
585 * When the PF detects that the VF has recovered, it writes 2
586 * VF checks this register periodically to determine if a reset has occurred,
587 * then polls it to know when the reset is complete.
588 * If either the PF or VF reads the register while the hardware
589 * is in a reset state, it will return DEADBEEF, which, when masked
590 * will result in 3.
591 */
592 enum virtchnl_vfr_states {
593 VIRTCHNL_VFR_INPROGRESS = 0,
594 VIRTCHNL_VFR_COMPLETED,
595 VIRTCHNL_VFR_VFACTIVE,
596 };
597
598 /**
599 * virtchnl_vc_validate_vf_msg
600 * @ver: Virtchnl version info
601 * @v_opcode: Opcode for the message
602 * @msg: pointer to the msg buffer
603 * @msglen: msg length
604 *
605 * validate msg format against struct for each opcode
606 */
607 static inline int
608 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
609 u8 *msg, u16 msglen)
610 {
611 bool err_msg_format = FALSE;
612 int valid_len = 0;
613
614 /* Validate message length. */
615 switch (v_opcode) {
616 case VIRTCHNL_OP_VERSION:
617 valid_len = sizeof(struct virtchnl_version_info);
618 break;
619 case VIRTCHNL_OP_RESET_VF:
620 break;
621 case VIRTCHNL_OP_GET_VF_RESOURCES:
622 if (VF_IS_V11(ver))
623 valid_len = sizeof(u32);
624 break;
625 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
626 valid_len = sizeof(struct virtchnl_txq_info);
627 break;
628 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
629 valid_len = sizeof(struct virtchnl_rxq_info);
630 break;
631 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
632 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
633 if (msglen >= valid_len) {
634 struct virtchnl_vsi_queue_config_info *vqc =
635 (struct virtchnl_vsi_queue_config_info *)msg;
636 valid_len += (vqc->num_queue_pairs *
637 sizeof(struct
638 virtchnl_queue_pair_info));
639 if (vqc->num_queue_pairs == 0)
640 err_msg_format = TRUE;
641 }
642 break;
643 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
644 valid_len = sizeof(struct virtchnl_irq_map_info);
645 if (msglen >= valid_len) {
646 struct virtchnl_irq_map_info *vimi =
647 (struct virtchnl_irq_map_info *)msg;
648 valid_len += (vimi->num_vectors *
649 sizeof(struct virtchnl_vector_map));
650 if (vimi->num_vectors == 0)
651 err_msg_format = TRUE;
652 }
653 break;
654 case VIRTCHNL_OP_ENABLE_QUEUES:
655 case VIRTCHNL_OP_DISABLE_QUEUES:
656 valid_len = sizeof(struct virtchnl_queue_select);
657 break;
658 case VIRTCHNL_OP_ADD_ETH_ADDR:
659 case VIRTCHNL_OP_DEL_ETH_ADDR:
660 valid_len = sizeof(struct virtchnl_ether_addr_list);
661 if (msglen >= valid_len) {
662 struct virtchnl_ether_addr_list *veal =
663 (struct virtchnl_ether_addr_list *)msg;
664 valid_len += veal->num_elements *
665 sizeof(struct virtchnl_ether_addr);
666 if (veal->num_elements == 0)
667 err_msg_format = TRUE;
668 }
669 break;
670 case VIRTCHNL_OP_ADD_VLAN:
671 case VIRTCHNL_OP_DEL_VLAN:
672 valid_len = sizeof(struct virtchnl_vlan_filter_list);
673 if (msglen >= valid_len) {
674 struct virtchnl_vlan_filter_list *vfl =
675 (struct virtchnl_vlan_filter_list *)msg;
676 valid_len += vfl->num_elements * sizeof(u16);
677 if (vfl->num_elements == 0)
678 err_msg_format = TRUE;
679 }
680 break;
681 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
682 valid_len = sizeof(struct virtchnl_promisc_info);
683 break;
684 case VIRTCHNL_OP_GET_STATS:
685 valid_len = sizeof(struct virtchnl_queue_select);
686 break;
687 case VIRTCHNL_OP_IWARP:
688 /* These messages are opaque to us and will be validated in
689 * the RDMA client code. We just need to check for nonzero
690 * length. The firmware will enforce max length restrictions.
691 */
692 if (msglen)
693 valid_len = msglen;
694 else
695 err_msg_format = TRUE;
696 break;
697 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
698 break;
699 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
700 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
701 if (msglen >= valid_len) {
702 struct virtchnl_iwarp_qvlist_info *qv =
703 (struct virtchnl_iwarp_qvlist_info *)msg;
704 if (qv->num_vectors == 0) {
705 err_msg_format = TRUE;
706 break;
707 }
708 valid_len += ((qv->num_vectors - 1) *
709 sizeof(struct virtchnl_iwarp_qv_info));
710 }
711 break;
712 case VIRTCHNL_OP_CONFIG_RSS_KEY:
713 valid_len = sizeof(struct virtchnl_rss_key);
714 if (msglen >= valid_len) {
715 struct virtchnl_rss_key *vrk =
716 (struct virtchnl_rss_key *)msg;
717 valid_len += vrk->key_len - 1;
718 }
719 break;
720 case VIRTCHNL_OP_CONFIG_RSS_LUT:
721 valid_len = sizeof(struct virtchnl_rss_lut);
722 if (msglen >= valid_len) {
723 struct virtchnl_rss_lut *vrl =
724 (struct virtchnl_rss_lut *)msg;
725 valid_len += vrl->lut_entries - 1;
726 }
727 break;
728 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
729 break;
730 case VIRTCHNL_OP_SET_RSS_HENA:
731 valid_len = sizeof(struct virtchnl_rss_hena);
732 break;
733 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
734 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
735 break;
736 case VIRTCHNL_OP_REQUEST_QUEUES:
737 valid_len = sizeof(struct virtchnl_vf_res_request);
738 break;
739 /* These are always errors coming from the VF. */
740 case VIRTCHNL_OP_EVENT:
741 case VIRTCHNL_OP_UNKNOWN:
742 default:
743 return VIRTCHNL_ERR_PARAM;
744 }
745 /* few more checks */
746 if (err_msg_format || valid_len != msglen)
747 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
748
749 return 0;
750 }
751 #endif /* _VIRTCHNL_H_ */
|
1 /******************************************************************************
2
3 Copyright (c) 2013-2019, Intel Corporation
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32 ******************************************************************************/
33 /*$FreeBSD$*/
34
35
36 #ifndef _VIRTCHNL_H_
37 #define _VIRTCHNL_H_
38
39 /* Description:
40 * This header file describes the Virtual Function (VF) - Physical Function
41 * (PF) communication protocol used by the drivers for all devices starting
42 * from our 40G product line
43 *
44 * Admin queue buffer usage:
45 * desc->opcode is always aqc_opc_send_msg_to_pf
46 * flags, retval, datalen, and data addr are all used normally.
47 * The Firmware copies the cookie fields when sending messages between the
48 * PF and VF, but uses all other fields internally. Due to this limitation,
49 * we must send all messages as "indirect", i.e. using an external buffer.
50 *
51 * All the VSI indexes are relative to the VF. Each VF can have maximum of
52 * three VSIs. All the queue indexes are relative to the VSI. Each VF can
53 * have a maximum of sixteen queues for all of its VSIs.
54 *
55 * The PF is required to return a status code in v_retval for all messages
56 * except RESET_VF, which does not require any response. The returned value
57 * is of virtchnl_status_code type, defined in the shared type.h.
58 *
59 * In general, VF driver initialization should roughly follow the order of
60 * these opcodes. The VF driver must first validate the API version of the
61 * PF driver, then request a reset, then get resources, then configure
62 * queues and interrupts. After these operations are complete, the VF
63 * driver may start its queues, optionally add MAC and VLAN filters, and
64 * process traffic.
65 */
66
67 /* START GENERIC DEFINES
68 * Need to ensure the following enums and defines hold the same meaning and
69 * value in current and future projects
70 */
71
72
73 /* Error Codes */
74 enum virtchnl_status_code {
75 VIRTCHNL_STATUS_SUCCESS = 0,
76 VIRTCHNL_STATUS_ERR_PARAM = -5,
77 VIRTCHNL_STATUS_ERR_NO_MEMORY = -18,
78 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38,
79 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39,
80 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40,
81 VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR = -53,
82 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED = -64,
83 };
84
85 /* Backward compatibility */
86 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
87 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
88
89 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT 0x0
90 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1
91 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2
92 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3
93 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4
94 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5
95 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6
96 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT 0x7
97
98 enum virtchnl_link_speed {
99 VIRTCHNL_LINK_SPEED_UNKNOWN = 0,
100 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
101 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
102 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
103 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
104 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
105 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
106 VIRTCHNL_LINK_SPEED_2_5GB = BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
107 VIRTCHNL_LINK_SPEED_5GB = BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
108 };
131 * exchange and are not considered part of base mode feature set.
132 */
133 VIRTCHNL_OP_UNKNOWN = 0,
134 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
135 VIRTCHNL_OP_RESET_VF = 2,
136 VIRTCHNL_OP_GET_VF_RESOURCES = 3,
137 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
138 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
139 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
140 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
141 VIRTCHNL_OP_ENABLE_QUEUES = 8,
142 VIRTCHNL_OP_DISABLE_QUEUES = 9,
143 VIRTCHNL_OP_ADD_ETH_ADDR = 10,
144 VIRTCHNL_OP_DEL_ETH_ADDR = 11,
145 VIRTCHNL_OP_ADD_VLAN = 12,
146 VIRTCHNL_OP_DEL_VLAN = 13,
147 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
148 VIRTCHNL_OP_GET_STATS = 15,
149 VIRTCHNL_OP_RSVD = 16,
150 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
151 /* opcode 19 is reserved */
152 VIRTCHNL_OP_IWARP = 20, /* advanced opcode */
153 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
154 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
155 VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
156 VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
157 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
158 VIRTCHNL_OP_SET_RSS_HENA = 26,
159 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
160 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
161 VIRTCHNL_OP_REQUEST_QUEUES = 29,
162 VIRTCHNL_OP_ENABLE_CHANNELS = 30,
163 VIRTCHNL_OP_DISABLE_CHANNELS = 31,
164 VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
165 VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
166 /* opcode 34 is reserved */
167 /* opcodes 38, 39, 40, 41, 42 and 43 are reserved */
168 /* opcode 44 is reserved */
169 /* opcode 45, 46, 47, 48 and 49 are reserved */
170 VIRTCHNL_OP_GET_MAX_RSS_QREGION = 50,
171 VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS = 51,
172 VIRTCHNL_OP_ADD_VLAN_V2 = 52,
173 VIRTCHNL_OP_DEL_VLAN_V2 = 53,
174 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 = 54,
175 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 = 55,
176 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 = 56,
177 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
178 VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 = 58,
179 VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 = 59,
180 /* opcodes 60 through 69 are reserved */
181 VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107,
182 VIRTCHNL_OP_DISABLE_QUEUES_V2 = 108,
183 VIRTCHNL_OP_MAP_QUEUE_VECTOR = 111,
184 VIRTCHNL_OP_MAX,
185 };
186
187 static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode)
188 {
189 switch (v_opcode) {
190 case VIRTCHNL_OP_UNKNOWN:
191 return "VIRTCHNL_OP_UNKNOWN";
192 case VIRTCHNL_OP_VERSION:
193 return "VIRTCHNL_OP_VERSION";
194 case VIRTCHNL_OP_RESET_VF:
195 return "VIRTCHNL_OP_RESET_VF";
196 case VIRTCHNL_OP_GET_VF_RESOURCES:
197 return "VIRTCHNL_OP_GET_VF_RESOURCES";
198 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
199 return "VIRTCHNL_OP_CONFIG_TX_QUEUE";
200 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
201 return "VIRTCHNL_OP_CONFIG_RX_QUEUE";
202 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
203 return "VIRTCHNL_OP_CONFIG_VSI_QUEUES";
204 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
205 return "VIRTCHNL_OP_CONFIG_IRQ_MAP";
206 case VIRTCHNL_OP_ENABLE_QUEUES:
207 return "VIRTCHNL_OP_ENABLE_QUEUES";
208 case VIRTCHNL_OP_DISABLE_QUEUES:
209 return "VIRTCHNL_OP_DISABLE_QUEUES";
210 case VIRTCHNL_OP_ADD_ETH_ADDR:
211 return "VIRTCHNL_OP_ADD_ETH_ADDR";
212 case VIRTCHNL_OP_DEL_ETH_ADDR:
213 return "VIRTCHNL_OP_DEL_ETH_ADDR";
214 case VIRTCHNL_OP_ADD_VLAN:
215 return "VIRTCHNL_OP_ADD_VLAN";
216 case VIRTCHNL_OP_DEL_VLAN:
217 return "VIRTCHNL_OP_DEL_VLAN";
218 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
219 return "VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE";
220 case VIRTCHNL_OP_GET_STATS:
221 return "VIRTCHNL_OP_GET_STATS";
222 case VIRTCHNL_OP_RSVD:
223 return "VIRTCHNL_OP_RSVD";
224 case VIRTCHNL_OP_EVENT:
225 return "VIRTCHNL_OP_EVENT";
226 case VIRTCHNL_OP_IWARP:
227 return "VIRTCHNL_OP_IWARP";
228 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
229 return "VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:";
230 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
231 return "VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP";
232 case VIRTCHNL_OP_CONFIG_RSS_KEY:
233 return "VIRTCHNL_OP_CONFIG_RSS_KEY";
234 case VIRTCHNL_OP_CONFIG_RSS_LUT:
235 return "VIRTCHNL_OP_CONFIG_RSS_LUT";
236 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
237 return "VIRTCHNL_OP_GET_RSS_HENA_CAPS";
238 case VIRTCHNL_OP_SET_RSS_HENA:
239 return "VIRTCHNL_OP_SET_RSS_HENA";
240 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
241 return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING";
242 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
243 return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING";
244 case VIRTCHNL_OP_REQUEST_QUEUES:
245 return "VIRTCHNL_OP_REQUEST_QUEUES";
246 case VIRTCHNL_OP_ENABLE_CHANNELS:
247 return "VIRTCHNL_OP_ENABLE_CHANNELS";
248 case VIRTCHNL_OP_DISABLE_CHANNELS:
249 return "VIRTCHNL_OP_DISABLE_CHANNELS";
250 case VIRTCHNL_OP_ADD_CLOUD_FILTER:
251 return "VIRTCHNL_OP_ADD_CLOUD_FILTER";
252 case VIRTCHNL_OP_DEL_CLOUD_FILTER:
253 return "VIRTCHNL_OP_DEL_CLOUD_FILTER";
254 case VIRTCHNL_OP_GET_MAX_RSS_QREGION:
255 return "VIRTCHNL_OP_GET_MAX_RSS_QREGION";
256 case VIRTCHNL_OP_ENABLE_QUEUES_V2:
257 return "VIRTCHNL_OP_ENABLE_QUEUES_V2";
258 case VIRTCHNL_OP_DISABLE_QUEUES_V2:
259 return "VIRTCHNL_OP_DISABLE_QUEUES_V2";
260 case VIRTCHNL_OP_MAP_QUEUE_VECTOR:
261 return "VIRTCHNL_OP_MAP_QUEUE_VECTOR";
262 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
263 return "VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS";
264 case VIRTCHNL_OP_ADD_VLAN_V2:
265 return "VIRTCHNL_OP_ADD_VLAN_V2";
266 case VIRTCHNL_OP_DEL_VLAN_V2:
267 return "VIRTCHNL_OP_DEL_VLAN_V2";
268 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
269 return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2";
270 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
271 return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2";
272 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
273 return "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2";
274 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
275 return "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2";
276 case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2:
277 return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2";
278 case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
279 return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2";
280 case VIRTCHNL_OP_MAX:
281 return "VIRTCHNL_OP_MAX";
282 default:
283 return "Unsupported (update virtchnl.h)";
284 }
285 }
286
287 /* These macros are used to generate compilation errors if a structure/union
288 * is not exactly the correct length. It gives a divide by zero error if the
289 * structure/union is not of the correct size, otherwise it creates an enum
290 * that is never used.
291 */
292 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
293 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
294 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
295 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
296
297 /* Virtual channel message descriptor. This overlays the admin queue
298 * descriptor. All other data is passed in external buffers.
299 */
300
301 struct virtchnl_msg {
302 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
303
304 /* avoid confusion with desc->opcode */
305 enum virtchnl_ops v_opcode;
306
307 /* ditto for desc->retval */
308 enum virtchnl_status_code v_retval;
309 u32 vfid; /* used by PF when sending to VF */
310 };
311
312 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
313
314 /* Message descriptions and data structures. */
315
316 /* VIRTCHNL_OP_VERSION
317 * VF posts its version number to the PF. PF responds with its version number
318 * in the same format, along with a return code.
319 * Reply from PF has its major/minor versions also in param0 and param1.
320 * If there is a major version mismatch, then the VF cannot operate.
321 * If there is a minor version mismatch, then the VF can operate but should
322 * add a warning to the system log.
323 *
324 * This enum element MUST always be specified as == 1, regardless of other
325 * changes in the API. The PF must always respond to this message without
326 * error regardless of version mismatch.
327 */
328 #define VIRTCHNL_VERSION_MAJOR 1
329 #define VIRTCHNL_VERSION_MINOR 1
330 #define VIRTCHNL_VERSION_MAJOR_2 2
331 #define VIRTCHNL_VERSION_MINOR_0 0
332 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
333
334 struct virtchnl_version_info {
335 u32 major;
336 u32 minor;
337 };
338
339 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
340
341 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
342 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
343
344 /* VIRTCHNL_OP_RESET_VF
345 * VF sends this request to PF with no parameters
346 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
347 * until reset completion is indicated. The admin queue must be reinitialized
348 * after this operation.
349 *
350 * When reset is complete, PF must ensure that all queues in all VSIs associated
351 * with the VF are stopped, all queue configurations in the HMC are set to 0,
356 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
357 * vsi_type should always be 6 for backward compatibility. Add other fields
358 * as needed.
359 */
360 enum virtchnl_vsi_type {
361 VIRTCHNL_VSI_TYPE_INVALID = 0,
362 VIRTCHNL_VSI_SRIOV = 6,
363 };
364
365 /* VIRTCHNL_OP_GET_VF_RESOURCES
366 * Version 1.0 VF sends this request to PF with no parameters
367 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
368 * PF responds with an indirect message containing
369 * virtchnl_vf_resource and one or more
370 * virtchnl_vsi_resource structures.
371 */
372
373 struct virtchnl_vsi_resource {
374 u16 vsi_id;
375 u16 num_queue_pairs;
376
377 /* see enum virtchnl_vsi_type */
378 s32 vsi_type;
379 u16 qset_handle;
380 u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
381 };
382
383 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
384
385 /* VF capability flags
386 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
387 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
388 */
389 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001
390 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002
391 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004
392 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008
393 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010
394 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020
395 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040
396 #define VIRTCHNL_VF_OFFLOAD_CRC 0x00000080
397 /* 0X00000100 is reserved */
398 #define VIRTCHNL_VF_LARGE_NUM_QPAIRS 0x00000200
399 #define VIRTCHNL_VF_OFFLOAD_VLAN_V2 0x00008000
400 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000
401 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000
402 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000
403 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000
404 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000
405 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000
406 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000
407 #define VIRTCHNL_VF_OFFLOAD_ADQ 0X00800000
408 #define VIRTCHNL_VF_OFFLOAD_ADQ_V2 0X01000000
409 #define VIRTCHNL_VF_OFFLOAD_USO 0X02000000
410 /* 0x04000000 is reserved */
411 /* 0X08000000 and 0X10000000 are reserved */
412 /* 0X20000000 is reserved */
413 /* 0X40000000 is reserved */
414 /* 0X80000000 is reserved */
415
416 /* Define below the capability flags that are not offloads */
417 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED 0x00000080
418 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
419 VIRTCHNL_VF_OFFLOAD_VLAN | \
420 VIRTCHNL_VF_OFFLOAD_RSS_PF)
421
422 struct virtchnl_vf_resource {
423 u16 num_vsis;
424 u16 num_queue_pairs;
425 u16 max_vectors;
426 u16 max_mtu;
427
428 u32 vf_cap_flags;
429 u32 rss_key_size;
430 u32 rss_lut_size;
431
432 struct virtchnl_vsi_resource vsi_res[1];
433 };
434
435 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
436
437 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
438 * VF sends this message to set up parameters for one TX queue.
439 * External data buffer contains one instance of virtchnl_txq_info.
440 * PF configures requested queue and returns a status code.
441 */
442
443 /* Tx queue config info */
444 struct virtchnl_txq_info {
445 u16 vsi_id;
446 u16 queue_id;
447 u16 ring_len; /* number of descriptors, multiple of 8 */
448 u16 headwb_enabled; /* deprecated with AVF 1.0 */
449 u64 dma_ring_addr;
450 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
451 };
452
453 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
454
455 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
456 * VF sends this message to set up parameters for one RX queue.
457 * External data buffer contains one instance of virtchnl_rxq_info.
458 * PF configures requested queue and returns a status code. The
459 * crc_disable flag disables CRC stripping on the VF. Setting
460 * the crc_disable flag to 1 will disable CRC stripping for each
461 * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC
462 * offload must have been set prior to sending this info or the PF
463 * will ignore the request. This flag should be set the same for
464 * all of the queues for a VF.
465 */
466
467 /* Rx queue config info */
468 struct virtchnl_rxq_info {
469 u16 vsi_id;
470 u16 queue_id;
471 u32 ring_len; /* number of descriptors, multiple of 32 */
472 u16 hdr_size;
473 u16 splithdr_enabled; /* deprecated with AVF 1.0 */
474 u32 databuffer_size;
475 u32 max_pkt_size;
476 u8 crc_disable;
477 u8 pad1[3];
478 u64 dma_ring_addr;
479
480 /* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
481 s32 rx_split_pos;
482 u32 pad2;
483 };
484
485 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
486
487 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
488 * VF sends this message to set parameters for active TX and RX queues
489 * associated with the specified VSI.
490 * PF configures queues and returns status.
491 * If the number of queues specified is greater than the number of queues
492 * associated with the VSI, an error is returned and no queues are configured.
493 * NOTE: The VF is not required to configure all queues in a single request.
494 * It may send multiple messages. PF drivers must correctly handle all VF
495 * requests.
496 */
497 struct virtchnl_queue_pair_info {
498 /* NOTE: vsi_id and queue_id should be identical for both queues. */
499 struct virtchnl_txq_info txq;
500 struct virtchnl_rxq_info rxq;
501 };
502
503 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
504
505 struct virtchnl_vsi_queue_config_info {
506 u16 vsi_id;
507 u16 num_queue_pairs;
508 u32 pad;
509 struct virtchnl_queue_pair_info qpair[1];
510 };
511
512 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
513
514 /* VIRTCHNL_OP_REQUEST_QUEUES
515 * VF sends this message to request the PF to allocate additional queues to
516 * this VF. Each VF gets a guaranteed number of queues on init but asking for
517 * additional queues must be negotiated. This is a best effort request as it
518 * is possible the PF does not have enough queues left to support the request.
519 * If the PF cannot support the number requested it will respond with the
520 * maximum number it is able to support. If the request is successful, PF will
521 * then reset the VF to institute required changes.
522 */
523
524 /* VF resource request */
525 struct virtchnl_vf_res_request {
526 u16 num_queue_pairs;
527 };
528
529 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
530 * VF uses this message to map vectors to queues.
531 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
532 * are to be associated with the specified vector.
533 * The "other" causes are always mapped to vector 0. The VF may not request
534 * that vector 0 be used for traffic.
535 * PF configures interrupt mapping and returns status.
536 * NOTE: due to hardware requirements, all active queues (both TX and RX)
537 * should be mapped to interrupts, even if the driver intends to operate
538 * only in polling mode. In this case the interrupt may be disabled, but
539 * the ITR timer will still run to trigger writebacks.
540 */
541 struct virtchnl_vector_map {
542 u16 vsi_id;
543 u16 vector_id;
544 u16 rxq_map;
545 u16 txq_map;
546 u16 rxitr_idx;
547 u16 txitr_idx;
548 };
549
550 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
551
552 struct virtchnl_irq_map_info {
553 u16 num_vectors;
554 struct virtchnl_vector_map vecmap[1];
555 };
556
557 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
558
559 /* VIRTCHNL_OP_ENABLE_QUEUES
560 * VIRTCHNL_OP_DISABLE_QUEUES
561 * VF sends these message to enable or disable TX/RX queue pairs.
562 * The queues fields are bitmaps indicating which queues to act upon.
563 * (Currently, we only support 16 queues per VF, but we make the field
564 * u32 to allow for expansion.)
565 * PF performs requested action and returns status.
566 * NOTE: The VF is not required to enable/disable all queues in a single
567 * request. It may send multiple messages.
568 * PF drivers must correctly handle all VF requests.
569 */
570 struct virtchnl_queue_select {
571 u16 vsi_id;
572 u16 pad;
573 u32 rx_queues;
574 u32 tx_queues;
575 };
576
577 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
578
579 /* VIRTCHNL_OP_GET_MAX_RSS_QREGION
580 *
581 * if VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
582 * then this op must be supported.
583 *
584 * VF sends this message in order to query the max RSS queue region
585 * size supported by PF, when VIRTCHNL_VF_LARGE_NUM_QPAIRS is enabled.
586 * This information should be used when configuring the RSS LUT and/or
587 * configuring queue region based filters.
588 *
589 * The maximum RSS queue region is 2^qregion_width. So, a qregion_width
590 * of 6 would inform the VF that the PF supports a maximum RSS queue region
591 * of 64.
592 *
593 * A queue region represents a range of queues that can be used to configure
594 * a RSS LUT. For example, if a VF is given 64 queues, but only a max queue
595 * region size of 16 (i.e. 2^qregion_width = 16) then it will only be able
596 * to configure the RSS LUT with queue indices from 0 to 15. However, other
597 * filters can be used to direct packets to queues >15 via specifying a queue
598 * base/offset and queue region width.
599 */
600 struct virtchnl_max_rss_qregion {
601 u16 vport_id;
602 u16 qregion_width;
603 u8 pad[4];
604 };
605
606 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_max_rss_qregion);
607
608 /* VIRTCHNL_OP_ADD_ETH_ADDR
609 * VF sends this message in order to add one or more unicast or multicast
610 * address filters for the specified VSI.
611 * PF adds the filters and returns status.
612 */
613
614 /* VIRTCHNL_OP_DEL_ETH_ADDR
615 * VF sends this message in order to remove one or more unicast or multicast
616 * filters for the specified VSI.
617 * PF removes the filters and returns status.
618 */
619
620 /* VIRTCHNL_ETHER_ADDR_LEGACY
621 * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad
622 * bytes. Moving forward all VF drivers should not set type to
623 * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy
624 * behavior. The control plane function (i.e. PF) can use a best effort method
625 * of tracking the primary/device unicast in this case, but there is no
626 * guarantee and functionality depends on the implementation of the PF.
627 */
628
629 /* VIRTCHNL_ETHER_ADDR_PRIMARY
630 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the
631 * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and
632 * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane
633 * function (i.e. PF) to accurately track and use this MAC address for
634 * displaying on the host and for VM/function reset.
635 */
636
637 /* VIRTCHNL_ETHER_ADDR_EXTRA
638 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra
639 * unicast and/or multicast filters that are being added/deleted via
640 * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively.
641 */
642 struct virtchnl_ether_addr {
643 u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
644 u8 type;
645 #define VIRTCHNL_ETHER_ADDR_LEGACY 0
646 #define VIRTCHNL_ETHER_ADDR_PRIMARY 1
647 #define VIRTCHNL_ETHER_ADDR_EXTRA 2
648 #define VIRTCHNL_ETHER_ADDR_TYPE_MASK 3 /* first two bits of type are valid */
649 u8 pad;
650 };
651
652 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
653
654 struct virtchnl_ether_addr_list {
655 u16 vsi_id;
656 u16 num_elements;
657 struct virtchnl_ether_addr list[1];
658 };
659
660 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
661
662 /* VIRTCHNL_OP_ADD_VLAN
663 * VF sends this message to add one or more VLAN tag filters for receives.
664 * PF adds the filters and returns status.
665 * If a port VLAN is configured by the PF, this operation will return an
666 * error to the VF.
667 */
668
669 /* VIRTCHNL_OP_DEL_VLAN
670 * VF sends this message to remove one or more VLAN tag filters for receives.
671 * PF removes the filters and returns status.
672 * If a port VLAN is configured by the PF, this operation will return an
673 * error to the VF.
674 */
675
676 struct virtchnl_vlan_filter_list {
677 u16 vsi_id;
678 u16 num_elements;
679 u16 vlan_id[1];
680 };
681
682 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
683
684 /* This enum is used for all of the VIRTCHNL_VF_OFFLOAD_VLAN_V2_CAPS related
685 * structures and opcodes.
686 *
687 * VIRTCHNL_VLAN_UNSUPPORTED - This field is not supported and if a VF driver
688 * populates it the PF should return VIRTCHNL_STATUS_ERR_NOT_SUPPORTED.
689 *
690 * VIRTCHNL_VLAN_ETHERTYPE_8100 - This field supports 0x8100 ethertype.
691 * VIRTCHNL_VLAN_ETHERTYPE_88A8 - This field supports 0x88A8 ethertype.
692 * VIRTCHNL_VLAN_ETHERTYPE_9100 - This field supports 0x9100 ethertype.
693 *
694 * VIRTCHNL_VLAN_ETHERTYPE_AND - Used when multiple ethertypes can be supported
695 * by the PF concurrently. For example, if the PF can support
696 * VIRTCHNL_VLAN_ETHERTYPE_8100 AND VIRTCHNL_VLAN_ETHERTYPE_88A8 filters it
697 * would OR the following bits:
698 *
699 * VIRTHCNL_VLAN_ETHERTYPE_8100 |
700 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
701 * VIRTCHNL_VLAN_ETHERTYPE_AND;
702 *
703 * The VF would interpret this as VLAN filtering can be supported on both 0x8100
704 * and 0x88A8 VLAN ethertypes.
705 *
706 * VIRTCHNL_ETHERTYPE_XOR - Used when only a single ethertype can be supported
707 * by the PF concurrently. For example if the PF can support
708 * VIRTCHNL_VLAN_ETHERTYPE_8100 XOR VIRTCHNL_VLAN_ETHERTYPE_88A8 stripping
709 * offload it would OR the following bits:
710 *
711 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
712 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
713 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
714 *
715 * The VF would interpret this as VLAN stripping can be supported on either
716 * 0x8100 or 0x88a8 VLAN ethertypes. So when requesting VLAN stripping via
717 * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 the specified ethertype will override
718 * the previously set value.
719 *
720 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 - Used to tell the VF to insert and/or
721 * strip the VLAN tag using the L2TAG1 field of the Tx/Rx descriptors.
722 *
723 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to insert hardware
724 * offloaded VLAN tags using the L2TAG2 field of the Tx descriptor.
725 *
726 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to strip hardware
727 * offloaded VLAN tags using the L2TAG2_2 field of the Rx descriptor.
728 *
729 * VIRTCHNL_VLAN_PRIO - This field supports VLAN priority bits. This is used for
730 * VLAN filtering if the underlying PF supports it.
731 *
732 * VIRTCHNL_VLAN_TOGGLE_ALLOWED - This field is used to say whether a
733 * certain VLAN capability can be toggled. For example if the underlying PF/CP
734 * allows the VF to toggle VLAN filtering, stripping, and/or insertion it should
735 * set this bit along with the supported ethertypes.
736 */
737 enum virtchnl_vlan_support {
738 VIRTCHNL_VLAN_UNSUPPORTED = 0,
739 VIRTCHNL_VLAN_ETHERTYPE_8100 = 0x00000001,
740 VIRTCHNL_VLAN_ETHERTYPE_88A8 = 0x00000002,
741 VIRTCHNL_VLAN_ETHERTYPE_9100 = 0x00000004,
742 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 = 0x00000100,
743 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 = 0x00000200,
744 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 = 0x00000400,
745 VIRTCHNL_VLAN_PRIO = 0x01000000,
746 VIRTCHNL_VLAN_FILTER_MASK = 0x10000000,
747 VIRTCHNL_VLAN_ETHERTYPE_AND = 0x20000000,
748 VIRTCHNL_VLAN_ETHERTYPE_XOR = 0x40000000,
749 VIRTCHNL_VLAN_TOGGLE = 0x80000000
750 };
751
752 /* This structure is used as part of the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
753 * for filtering, insertion, and stripping capabilities.
754 *
755 * If only outer capabilities are supported (for filtering, insertion, and/or
756 * stripping) then this refers to the outer most or single VLAN from the VF's
757 * perspective.
758 *
759 * If only inner capabilities are supported (for filtering, insertion, and/or
760 * stripping) then this refers to the outer most or single VLAN from the VF's
761 * perspective. Functionally this is the same as if only outer capabilities are
762 * supported. The VF driver is just forced to use the inner fields when
763 * adding/deleting filters and enabling/disabling offloads (if supported).
764 *
765 * If both outer and inner capabilities are supported (for filtering, insertion,
766 * and/or stripping) then outer refers to the outer most or single VLAN and
767 * inner refers to the second VLAN, if it exists, in the packet.
768 *
769 * There is no support for tunneled VLAN offloads, so outer or inner are never
770 * referring to a tunneled packet from the VF's perspective.
771 */
772 struct virtchnl_vlan_supported_caps {
773 u32 outer;
774 u32 inner;
775 };
776
777 /* The PF populates these fields based on the supported VLAN filtering. If a
778 * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
779 * reject any VIRTCHNL_OP_ADD_VLAN_V2 or VIRTCHNL_OP_DEL_VLAN_V2 messages using
780 * the unsupported fields.
781 *
782 * Also, a VF is only allowed to toggle its VLAN filtering setting if the
783 * VIRTCHNL_VLAN_TOGGLE bit is set.
784 *
785 * The ethertype(s) specified in the ethertype_init field are the ethertypes
786 * enabled for VLAN filtering. VLAN filtering in this case refers to the outer
787 * most VLAN from the VF's perspective. If both inner and outer filtering are
788 * allowed then ethertype_init only refers to the outer most VLAN as only
789 * VLAN ethertype supported for inner VLAN filtering is
790 * VIRTCHNL_VLAN_ETHERTYPE_8100. By default, inner VLAN filtering is disabled
791 * when both inner and outer filtering are allowed.
792 *
793 * The max_filters field tells the VF how many VLAN filters it's allowed to have
794 * at any one time. If it exceeds this amount and tries to add another filter,
795 * then the request will be rejected by the PF. To prevent failures, the VF
796 * should keep track of how many VLAN filters it has added and not attempt to
797 * add more than max_filters.
798 */
799 struct virtchnl_vlan_filtering_caps {
800 struct virtchnl_vlan_supported_caps filtering_support;
801 u32 ethertype_init;
802 u16 max_filters;
803 u8 pad[2];
804 };
805
806 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_filtering_caps);
807
808 /* This enum is used for the virtchnl_vlan_offload_caps structure to specify
809 * if the PF supports a different ethertype for stripping and insertion.
810 *
811 * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION - The ethertype(s) specified
812 * for stripping affect the ethertype(s) specified for insertion and visa versa
813 * as well. If the VF tries to configure VLAN stripping via
814 * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 with VIRTCHNL_VLAN_ETHERTYPE_8100 then
815 * that will be the ethertype for both stripping and insertion.
816 *
817 * VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED - The ethertype(s) specified for
818 * stripping do not affect the ethertype(s) specified for insertion and visa
819 * versa.
820 */
821 enum virtchnl_vlan_ethertype_match {
822 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION = 0,
823 VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED = 1,
824 };
825
826 /* The PF populates these fields based on the supported VLAN offloads. If a
827 * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
828 * reject any VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 or
829 * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 messages using the unsupported fields.
830 *
831 * Also, a VF is only allowed to toggle its VLAN offload setting if the
832 * VIRTCHNL_VLAN_TOGGLE_ALLOWED bit is set.
833 *
834 * The VF driver needs to be aware of how the tags are stripped by hardware and
835 * inserted by the VF driver based on the level of offload support. The PF will
836 * populate these fields based on where the VLAN tags are expected to be
837 * offloaded via the VIRTHCNL_VLAN_TAG_LOCATION_* bits. The VF will need to
838 * interpret these fields. See the definition of the
839 * VIRTCHNL_VLAN_TAG_LOCATION_* bits above the virtchnl_vlan_support
840 * enumeration.
841 */
842 struct virtchnl_vlan_offload_caps {
843 struct virtchnl_vlan_supported_caps stripping_support;
844 struct virtchnl_vlan_supported_caps insertion_support;
845 u32 ethertype_init;
846 u8 ethertype_match;
847 u8 pad[3];
848 };
849
850 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_vlan_offload_caps);
851
852 /* VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
853 * VF sends this message to determine its VLAN capabilities.
854 *
855 * PF will mark which capabilities it supports based on hardware support and
856 * current configuration. For example, if a port VLAN is configured the PF will
857 * not allow outer VLAN filtering, stripping, or insertion to be configured so
858 * it will block these features from the VF.
859 *
860 * The VF will need to cross reference its capabilities with the PFs
861 * capabilities in the response message from the PF to determine the VLAN
862 * support.
863 */
864 struct virtchnl_vlan_caps {
865 struct virtchnl_vlan_filtering_caps filtering;
866 struct virtchnl_vlan_offload_caps offloads;
867 };
868
869 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_caps);
870
871 struct virtchnl_vlan {
872 u16 tci; /* tci[15:13] = PCP and tci[11:0] = VID */
873 u16 tci_mask; /* only valid if VIRTCHNL_VLAN_FILTER_MASK set in
874 * filtering caps
875 */
876 u16 tpid; /* 0x8100, 0x88a8, etc. and only type(s) set in
877 * filtering caps. Note that tpid here does not refer to
878 * VIRTCHNL_VLAN_ETHERTYPE_*, but it refers to the
879 * actual 2-byte VLAN TPID
880 */
881 u8 pad[2];
882 };
883
884 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan);
885
886 struct virtchnl_vlan_filter {
887 struct virtchnl_vlan inner;
888 struct virtchnl_vlan outer;
889 u8 pad[16];
890 };
891
892 VIRTCHNL_CHECK_STRUCT_LEN(32, virtchnl_vlan_filter);
893
894 /* VIRTCHNL_OP_ADD_VLAN_V2
895 * VIRTCHNL_OP_DEL_VLAN_V2
896 *
897 * VF sends these messages to add/del one or more VLAN tag filters for Rx
898 * traffic.
899 *
900 * The PF attempts to add the filters and returns status.
901 *
902 * The VF should only ever attempt to add/del virtchnl_vlan_filter(s) using the
903 * supported fields negotiated via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS.
904 */
905 struct virtchnl_vlan_filter_list_v2 {
906 u16 vport_id;
907 u16 num_elements;
908 u8 pad[4];
909 struct virtchnl_vlan_filter filters[1];
910 };
911
912 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_filter_list_v2);
913
914 /* VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
915 * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
916 * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
917 * VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
918 *
919 * VF sends this message to enable or disable VLAN stripping or insertion. It
920 * also needs to specify an ethertype. The VF knows which VLAN ethertypes are
921 * allowed and whether or not it's allowed to enable/disable the specific
922 * offload via the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
923 * parse the virtchnl_vlan_caps.offloads fields to determine which offload
924 * messages are allowed.
925 *
926 * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
927 * following manner the VF will be allowed to enable and/or disable 0x8100 inner
928 * VLAN insertion and/or stripping via the opcodes listed above. Inner in this
929 * case means the outer most or single VLAN from the VF's perspective. This is
930 * because no outer offloads are supported. See the comments above the
931 * virtchnl_vlan_supported_caps structure for more details.
932 *
933 * virtchnl_vlan_caps.offloads.stripping_support.inner =
934 * VIRTCHNL_VLAN_TOGGLE |
935 * VIRTCHNL_VLAN_ETHERTYPE_8100;
936 *
937 * virtchnl_vlan_caps.offloads.insertion_support.inner =
938 * VIRTCHNL_VLAN_TOGGLE |
939 * VIRTCHNL_VLAN_ETHERTYPE_8100;
940 *
941 * In order to enable inner (again note that in this case inner is the outer
942 * most or single VLAN from the VF's perspective) VLAN stripping for 0x8100
943 * VLANs, the VF would populate the virtchnl_vlan_setting structure in the
944 * following manner and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
945 *
946 * virtchnl_vlan_setting.inner_ethertype_setting =
947 * VIRTCHNL_VLAN_ETHERTYPE_8100;
948 *
949 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
950 * initialization.
951 *
952 * The reason that VLAN TPID(s) are not being used for the
953 * outer_ethertype_setting and inner_ethertype_setting fields is because it's
954 * possible a device could support VLAN insertion and/or stripping offload on
955 * multiple ethertypes concurrently, so this method allows a VF to request
956 * multiple ethertypes in one message using the virtchnl_vlan_support
957 * enumeration.
958 *
959 * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
960 * following manner the VF will be allowed to enable 0x8100 and 0x88a8 outer
961 * VLAN insertion and stripping simultaneously. The
962 * virtchnl_vlan_caps.offloads.ethertype_match field will also have to be
963 * populated based on what the PF can support.
964 *
965 * virtchnl_vlan_caps.offloads.stripping_support.outer =
966 * VIRTCHNL_VLAN_TOGGLE |
967 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
968 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
969 * VIRTCHNL_VLAN_ETHERTYPE_AND;
970 *
971 * virtchnl_vlan_caps.offloads.insertion_support.outer =
972 * VIRTCHNL_VLAN_TOGGLE |
973 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
974 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
975 * VIRTCHNL_VLAN_ETHERTYPE_AND;
976 *
977 * In order to enable outer VLAN stripping for 0x8100 and 0x88a8 VLANs, the VF
978 * would populate the virthcnl_vlan_offload_structure in the following manner
979 * and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
980 *
981 * virtchnl_vlan_setting.outer_ethertype_setting =
982 * VIRTHCNL_VLAN_ETHERTYPE_8100 |
983 * VIRTHCNL_VLAN_ETHERTYPE_88A8;
984 *
985 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
986 * initialization.
987 *
988 * There is also the case where a PF and the underlying hardware can support
989 * VLAN offloads on multiple ethertypes, but not concurrently. For example, if
990 * the PF populates the virtchnl_vlan_caps.offloads in the following manner the
991 * VF will be allowed to enable and/or disable 0x8100 XOR 0x88a8 outer VLAN
992 * offloads. The ethertypes must match for stripping and insertion.
993 *
994 * virtchnl_vlan_caps.offloads.stripping_support.outer =
995 * VIRTCHNL_VLAN_TOGGLE |
996 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
997 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
998 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
999 *
1000 * virtchnl_vlan_caps.offloads.insertion_support.outer =
1001 * VIRTCHNL_VLAN_TOGGLE |
1002 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
1003 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
1004 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
1005 *
1006 * virtchnl_vlan_caps.offloads.ethertype_match =
1007 * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
1008 *
1009 * In order to enable outer VLAN stripping for 0x88a8 VLANs, the VF would
1010 * populate the virtchnl_vlan_setting structure in the following manner and send
1011 * the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2. Also, this will change the
1012 * ethertype for VLAN insertion if it's enabled. So, for completeness, a
1013 * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 with the same ethertype should be sent.
1014 *
1015 * virtchnl_vlan_setting.outer_ethertype_setting = VIRTHCNL_VLAN_ETHERTYPE_88A8;
1016 *
1017 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
1018 * initialization.
1019 *
1020 * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2
1021 * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2
1022 *
1023 * VF sends this message to enable or disable VLAN filtering. It also needs to
1024 * specify an ethertype. The VF knows which VLAN ethertypes are allowed and
1025 * whether or not it's allowed to enable/disable filtering via the
1026 * VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
1027 * parse the virtchnl_vlan_caps.filtering fields to determine which, if any,
1028 * filtering messages are allowed.
1029 *
1030 * For example, if the PF populates the virtchnl_vlan_caps.filtering in the
1031 * following manner the VF will be allowed to enable/disable 0x8100 and 0x88a8
1032 * outer VLAN filtering together. Note, that the VIRTCHNL_VLAN_ETHERTYPE_AND
1033 * means that all filtering ethertypes will to be enabled and disabled together
1034 * regardless of the request from the VF. This means that the underlying
1035 * hardware only supports VLAN filtering for all VLAN the specified ethertypes
1036 * or none of them.
1037 *
1038 * virtchnl_vlan_caps.filtering.filtering_support.outer =
1039 * VIRTCHNL_VLAN_TOGGLE |
1040 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
1041 * VIRTHCNL_VLAN_ETHERTYPE_88A8 |
1042 * VIRTCHNL_VLAN_ETHERTYPE_9100 |
1043 * VIRTCHNL_VLAN_ETHERTYPE_AND;
1044 *
1045 * In order to enable outer VLAN filtering for 0x88a8 and 0x8100 VLANs (0x9100
1046 * VLANs aren't supported by the VF driver), the VF would populate the
1047 * virtchnl_vlan_setting structure in the following manner and send the
1048 * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2. The same message format would be used
1049 * to disable outer VLAN filtering for 0x88a8 and 0x8100 VLANs, but the
1050 * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 opcode is used.
1051 *
1052 * virtchnl_vlan_setting.outer_ethertype_setting =
1053 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
1054 * VIRTCHNL_VLAN_ETHERTYPE_88A8;
1055 *
1056 */
1057 struct virtchnl_vlan_setting {
1058 u32 outer_ethertype_setting;
1059 u32 inner_ethertype_setting;
1060 u16 vport_id;
1061 u8 pad[6];
1062 };
1063
1064 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_setting);
1065
1066 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
1067 * VF sends VSI id and flags.
1068 * PF returns status code in retval.
1069 * Note: we assume that broadcast accept mode is always enabled.
1070 */
1071 struct virtchnl_promisc_info {
1072 u16 vsi_id;
1073 u16 flags;
1074 };
1075
1076 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
1077
1078 #define FLAG_VF_UNICAST_PROMISC 0x00000001
1079 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
1080
1081 /* VIRTCHNL_OP_GET_STATS
1082 * VF sends this message to request stats for the selected VSI. VF uses
1083 * the virtchnl_queue_select struct to specify the VSI. The queue_id
1084 * field is ignored by the PF.
1085 *
1086 * PF replies with struct virtchnl_eth_stats in an external buffer.
1087 */
1088
1089 struct virtchnl_eth_stats {
1090 u64 rx_bytes; /* received bytes */
1091 u64 rx_unicast; /* received unicast pkts */
1092 u64 rx_multicast; /* received multicast pkts */
1093 u64 rx_broadcast; /* received broadcast pkts */
1094 u64 rx_discards;
1095 u64 rx_unknown_protocol;
1096 u64 tx_bytes; /* transmitted bytes */
1097 u64 tx_unicast; /* transmitted unicast pkts */
1098 u64 tx_multicast; /* transmitted multicast pkts */
1099 u64 tx_broadcast; /* transmitted broadcast pkts */
1100 u64 tx_discards;
1101 u64 tx_errors;
1102 };
1103
1104 /* VIRTCHNL_OP_CONFIG_RSS_KEY
1105 * VIRTCHNL_OP_CONFIG_RSS_LUT
1106 * VF sends these messages to configure RSS. Only supported if both PF
1107 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
1108 * configuration negotiation. If this is the case, then the RSS fields in
1109 * the VF resource struct are valid.
1110 * Both the key and LUT are initialized to 0 by the PF, meaning that
1111 * RSS is effectively disabled until set up by the VF.
1112 */
1113 struct virtchnl_rss_key {
1114 u16 vsi_id;
1115 u16 key_len;
1116 u8 key[1]; /* RSS hash key, packed bytes */
1117 };
1118
1119 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
1120
1121 struct virtchnl_rss_lut {
1122 u16 vsi_id;
1123 u16 lut_entries;
1124 u8 lut[1]; /* RSS lookup table */
1125 };
1126
1127 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
1128
1129 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
1130 * VIRTCHNL_OP_SET_RSS_HENA
1131 * VF sends these messages to get and set the hash filter enable bits for RSS.
1132 * By default, the PF sets these to all possible traffic types that the
1133 * hardware supports. The VF can query this value if it wants to change the
1134 * traffic types that are hashed by the hardware.
1135 */
1136 struct virtchnl_rss_hena {
1137 u64 hena;
1138 };
1139
1140 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
1141
1142 #if defined(ADV_AVF_SUPPORT) || defined(VIRTCHNL_VER_2_0)
1143 /* Type of RSS algorithm */
1144 enum virtchnl_rss_algorithm {
1145 VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0,
1146 VIRTCHNL_RSS_ALG_R_ASYMMETRIC = 1,
1147 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2,
1148 VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3,
1149 };
1150 #endif /* ADV_AVF_SUPPORT || VIRTCHNL_VER_2_0 */
1151
1152 /* This is used by PF driver to enforce how many channels can be supported.
1153 * When ADQ_V2 capability is negotiated, it will allow 16 channels otherwise
1154 * PF driver will allow only max 4 channels
1155 */
1156 #define VIRTCHNL_MAX_ADQ_CHANNELS 4
1157 #define VIRTCHNL_MAX_ADQ_V2_CHANNELS 16
1158
1159 /* VIRTCHNL_OP_ENABLE_CHANNELS
1160 * VIRTCHNL_OP_DISABLE_CHANNELS
1161 * VF sends these messages to enable or disable channels based on
1162 * the user specified queue count and queue offset for each traffic class.
1163 * This struct encompasses all the information that the PF needs from
1164 * VF to create a channel.
1165 */
1166 struct virtchnl_channel_info {
1167 u16 count; /* number of queues in a channel */
1168 u16 offset; /* queues in a channel start from 'offset' */
1169 u32 pad;
1170 u64 max_tx_rate;
1171 };
1172
1173 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
1174
1175 struct virtchnl_tc_info {
1176 u32 num_tc;
1177 u32 pad;
1178 struct virtchnl_channel_info list[1];
1179 };
1180
1181 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
1182
1183 /* VIRTCHNL_ADD_CLOUD_FILTER
1184 * VIRTCHNL_DEL_CLOUD_FILTER
1185 * VF sends these messages to add or delete a cloud filter based on the
1186 * user specified match and action filters. These structures encompass
1187 * all the information that the PF needs from the VF to add/delete a
1188 * cloud filter.
1189 */
1190
1191 struct virtchnl_l4_spec {
1192 u8 src_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
1193 u8 dst_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS];
1194 /* vlan_prio is part of this 16 bit field even from OS perspective
1195 * vlan_id:12 is actual vlan_id, then vlanid:bit14..12 is vlan_prio
1196 * in future, when decided to offload vlan_prio, pass that information
1197 * as part of the "vlan_id" field, Bit14..12
1198 */
1199 __be16 vlan_id;
1200 __be16 pad; /* reserved for future use */
1201 __be32 src_ip[4];
1202 __be32 dst_ip[4];
1203 __be16 src_port;
1204 __be16 dst_port;
1205 };
1206
1207 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
1208
1209 union virtchnl_flow_spec {
1210 struct virtchnl_l4_spec tcp_spec;
1211 u8 buffer[128]; /* reserved for future use */
1212 };
1213
1214 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
1215
1216 enum virtchnl_action {
1217 /* action types */
1218 VIRTCHNL_ACTION_DROP = 0,
1219 VIRTCHNL_ACTION_TC_REDIRECT,
1220 VIRTCHNL_ACTION_PASSTHRU,
1221 VIRTCHNL_ACTION_QUEUE,
1222 VIRTCHNL_ACTION_Q_REGION,
1223 VIRTCHNL_ACTION_MARK,
1224 VIRTCHNL_ACTION_COUNT,
1225 };
1226
1227 enum virtchnl_flow_type {
1228 /* flow types */
1229 VIRTCHNL_TCP_V4_FLOW = 0,
1230 VIRTCHNL_TCP_V6_FLOW,
1231 VIRTCHNL_UDP_V4_FLOW,
1232 VIRTCHNL_UDP_V6_FLOW,
1233 };
1234
1235 struct virtchnl_filter {
1236 union virtchnl_flow_spec data;
1237 union virtchnl_flow_spec mask;
1238
1239 /* see enum virtchnl_flow_type */
1240 s32 flow_type;
1241
1242 /* see enum virtchnl_action */
1243 s32 action;
1244 u32 action_meta;
1245 u8 field_flags;
1246 };
1247
1248 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
1249
1250
1251
1252 /* VIRTCHNL_OP_EVENT
1253 * PF sends this message to inform the VF driver of events that may affect it.
1254 * No direct response is expected from the VF, though it may generate other
1255 * messages in response to this one.
1256 */
1257 enum virtchnl_event_codes {
1258 VIRTCHNL_EVENT_UNKNOWN = 0,
1259 VIRTCHNL_EVENT_LINK_CHANGE,
1260 VIRTCHNL_EVENT_RESET_IMPENDING,
1261 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
1262 };
1263
1264 #define PF_EVENT_SEVERITY_INFO 0
1265 #define PF_EVENT_SEVERITY_ATTENTION 1
1266 #define PF_EVENT_SEVERITY_ACTION_REQUIRED 2
1267 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
1268
1269 struct virtchnl_pf_event {
1270 /* see enum virtchnl_event_codes */
1271 s32 event;
1272 union {
1273 /* If the PF driver does not support the new speed reporting
1274 * capabilities then use link_event else use link_event_adv to
1275 * get the speed and link information. The ability to understand
1276 * new speeds is indicated by setting the capability flag
1277 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
1278 * in virtchnl_vf_resource struct and can be used to determine
1279 * which link event struct to use below.
1280 */
1281 struct {
1282 enum virtchnl_link_speed link_speed;
1283 bool link_status;
1284 #ifndef __sun
1285 /* In illumos, sizeof (bool) is 4 bytes, not one. */
1286 u8 pad[3];
1287 #endif
1288 } link_event;
1289 struct {
1290 /* link_speed provided in Mbps */
1291 u32 link_speed;
1292 u8 link_status;
1293 u8 pad[3];
1294 } link_event_adv;
1295 struct {
1296 /* link_speed provided in Mbps */
1297 u32 link_speed;
1298 u16 vport_id;
1299 u8 link_status;
1300 u8 pad;
1301 } link_event_adv_vport;
1302 } event_data;
1303
1304 s32 severity;
1305 };
1306
1307 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
1308
1309
1310 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
1311 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
1312 * The request for this originates from the VF IWARP driver through
1313 * a client interface between VF LAN and VF IWARP driver.
1314 * A vector could have an AEQ and CEQ attached to it although
1315 * there is a single AEQ per VF IWARP instance in which case
1316 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
1317 * There will never be a case where there will be multiple CEQs attached
1318 * to a single vector.
1319 * PF configures interrupt mapping and returns status.
1320 */
1321 struct virtchnl_iwarp_qv_info {
1322 u32 v_idx; /* msix_vector */
1323 u16 ceq_idx;
1324 u16 aeq_idx;
1325 u8 itr_idx;
1326 };
1327
1328 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
1329
1330 struct virtchnl_iwarp_qvlist_info {
1331 u32 num_vectors;
1332 struct virtchnl_iwarp_qv_info qv_info[1];
1333 };
1334
1335 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
1336
1337
1338 /* VF reset states - these are written into the RSTAT register:
1339 * VFGEN_RSTAT on the VF
1340 * When the PF initiates a reset, it writes 0
1341 * When the reset is complete, it writes 1
1342 * When the PF detects that the VF has recovered, it writes 2
1343 * VF checks this register periodically to determine if a reset has occurred,
1344 * then polls it to know when the reset is complete.
1345 * If either the PF or VF reads the register while the hardware
1346 * is in a reset state, it will return DEADBEEF, which, when masked
1347 * will result in 3.
1348 */
1349 enum virtchnl_vfr_states {
1350 VIRTCHNL_VFR_INPROGRESS = 0,
1351 VIRTCHNL_VFR_COMPLETED,
1352 VIRTCHNL_VFR_VFACTIVE,
1353 };
1354
1355
1356 /* TX and RX queue types are valid in legacy as well as split queue models.
1357 * With Split Queue model, 2 additional types are introduced - TX_COMPLETION
1358 * and RX_BUFFER. In split queue model, RX corresponds to the queue where HW
1359 * posts completions.
1360 */
1361 enum virtchnl_queue_type {
1362 VIRTCHNL_QUEUE_TYPE_TX = 0,
1363 VIRTCHNL_QUEUE_TYPE_RX = 1,
1364 VIRTCHNL_QUEUE_TYPE_TX_COMPLETION = 2,
1365 VIRTCHNL_QUEUE_TYPE_RX_BUFFER = 3,
1366 VIRTCHNL_QUEUE_TYPE_CONFIG_TX = 4,
1367 VIRTCHNL_QUEUE_TYPE_CONFIG_RX = 5
1368 };
1369
1370
1371 /* structure to specify a chunk of contiguous queues */
1372 struct virtchnl_queue_chunk {
1373 /* see enum virtchnl_queue_type */
1374 s32 type;
1375 u16 start_queue_id;
1376 u16 num_queues;
1377 };
1378
1379 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_queue_chunk);
1380
1381 /* structure to specify several chunks of contiguous queues */
1382 struct virtchnl_queue_chunks {
1383 u16 num_chunks;
1384 u16 rsvd;
1385 struct virtchnl_queue_chunk chunks[1];
1386 };
1387
1388 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_chunks);
1389
1390
1391 /* VIRTCHNL_OP_ENABLE_QUEUES_V2
1392 * VIRTCHNL_OP_DISABLE_QUEUES_V2
1393 * VIRTCHNL_OP_DEL_QUEUES
1394 *
1395 * If VIRTCHNL version was negotiated in VIRTCHNL_OP_VERSION as 2.0
1396 * then all of these ops are available.
1397 *
1398 * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
1399 * then VIRTCHNL_OP_ENABLE_QUEUES_V2 and VIRTCHNL_OP_DISABLE_QUEUES_V2 are
1400 * available.
1401 *
1402 * PF sends these messages to enable, disable or delete queues specified in
1403 * chunks. PF sends virtchnl_del_ena_dis_queues struct to specify the queues
1404 * to be enabled/disabled/deleted. Also applicable to single queue RX or
1405 * TX. CP performs requested action and returns status.
1406 */
1407 struct virtchnl_del_ena_dis_queues {
1408 u16 vport_id;
1409 u16 pad;
1410 struct virtchnl_queue_chunks chunks;
1411 };
1412
1413 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_del_ena_dis_queues);
1414
1415 /* Virtchannel interrupt throttling rate index */
1416 enum virtchnl_itr_idx {
1417 VIRTCHNL_ITR_IDX_0 = 0,
1418 VIRTCHNL_ITR_IDX_1 = 1,
1419 VIRTCHNL_ITR_IDX_NO_ITR = 3,
1420 };
1421
1422 /* Queue to vector mapping */
1423 struct virtchnl_queue_vector {
1424 u16 queue_id;
1425 u16 vector_id;
1426 u8 pad[4];
1427
1428 /* see enum virtchnl_itr_idx */
1429 s32 itr_idx;
1430
1431 /* see enum virtchnl_queue_type */
1432 s32 queue_type;
1433 };
1434
1435 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_queue_vector);
1436
1437 /* VIRTCHNL_OP_MAP_QUEUE_VECTOR
1438 *
1439 * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES
1440 * then only VIRTCHNL_OP_MAP_QUEUE_VECTOR is available.
1441 *
1442 * PF sends this message to map or unmap queues to vectors and ITR index
1443 * registers. External data buffer contains virtchnl_queue_vector_maps structure
1444 * that contains num_qv_maps of virtchnl_queue_vector structures.
1445 * CP maps the requested queue vector maps after validating the queue and vector
1446 * ids and returns a status code.
1447 */
1448 struct virtchnl_queue_vector_maps {
1449 u16 vport_id;
1450 u16 num_qv_maps;
1451 u8 pad[4];
1452 struct virtchnl_queue_vector qv_maps[1];
1453 };
1454
1455 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_queue_vector_maps);
1456
1457
1458
1459 /* Since VF messages are limited by u16 size, precalculate the maximum possible
1460 * values of nested elements in virtchnl structures that virtual channel can
1461 * possibly handle in a single message.
1462 */
1463 enum virtchnl_vector_limits {
1464 VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX =
1465 ((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) /
1466 sizeof(struct virtchnl_queue_pair_info),
1467
1468 VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX =
1469 ((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) /
1470 sizeof(struct virtchnl_vector_map),
1471
1472 VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX =
1473 ((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) /
1474 sizeof(struct virtchnl_ether_addr),
1475
1476 VIRTCHNL_OP_ADD_DEL_VLAN_MAX =
1477 ((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) /
1478 sizeof(u16),
1479
1480 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP_MAX =
1481 ((u16)(~0) - sizeof(struct virtchnl_iwarp_qvlist_info)) /
1482 sizeof(struct virtchnl_iwarp_qv_info),
1483
1484 VIRTCHNL_OP_ENABLE_CHANNELS_MAX =
1485 ((u16)(~0) - sizeof(struct virtchnl_tc_info)) /
1486 sizeof(struct virtchnl_channel_info),
1487
1488 VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX =
1489 ((u16)(~0) - sizeof(struct virtchnl_del_ena_dis_queues)) /
1490 sizeof(struct virtchnl_queue_chunk),
1491
1492 VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX =
1493 ((u16)(~0) - sizeof(struct virtchnl_queue_vector_maps)) /
1494 sizeof(struct virtchnl_queue_vector),
1495
1496 VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX =
1497 ((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list_v2)) /
1498 sizeof(struct virtchnl_vlan_filter),
1499 };
1500
1501 /**
1502 * virtchnl_vc_validate_vf_msg
1503 * @ver: Virtchnl version info
1504 * @v_opcode: Opcode for the message
1505 * @msg: pointer to the msg buffer
1506 * @msglen: msg length
1507 *
1508 * validate msg format against struct for each opcode
1509 */
1510 static inline int
1511 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
1512 u8 *msg, u16 msglen)
1513 {
1514 bool err_msg_format = FALSE;
1515 u32 valid_len = 0;
1516
1517 /* Validate message length. */
1518 switch (v_opcode) {
1519 case VIRTCHNL_OP_VERSION:
1520 valid_len = sizeof(struct virtchnl_version_info);
1521 break;
1522 case VIRTCHNL_OP_RESET_VF:
1523 break;
1524 case VIRTCHNL_OP_GET_VF_RESOURCES:
1525 if (VF_IS_V11(ver))
1526 valid_len = sizeof(u32);
1527 break;
1528 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
1529 valid_len = sizeof(struct virtchnl_txq_info);
1530 break;
1531 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
1532 valid_len = sizeof(struct virtchnl_rxq_info);
1533 break;
1534 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1535 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
1536 if (msglen >= valid_len) {
1537 struct virtchnl_vsi_queue_config_info *vqc =
1538 (struct virtchnl_vsi_queue_config_info *)msg;
1539
1540 if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs >
1541 VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) {
1542 err_msg_format = TRUE;
1543 break;
1544 }
1545
1546 valid_len += (vqc->num_queue_pairs *
1547 sizeof(struct
1548 virtchnl_queue_pair_info));
1549 }
1550 break;
1551 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1552 valid_len = sizeof(struct virtchnl_irq_map_info);
1553 if (msglen >= valid_len) {
1554 struct virtchnl_irq_map_info *vimi =
1555 (struct virtchnl_irq_map_info *)msg;
1556
1557 if (vimi->num_vectors == 0 || vimi->num_vectors >
1558 VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) {
1559 err_msg_format = TRUE;
1560 break;
1561 }
1562
1563 valid_len += (vimi->num_vectors *
1564 sizeof(struct virtchnl_vector_map));
1565 }
1566 break;
1567 case VIRTCHNL_OP_ENABLE_QUEUES:
1568 case VIRTCHNL_OP_DISABLE_QUEUES:
1569 valid_len = sizeof(struct virtchnl_queue_select);
1570 break;
1571 case VIRTCHNL_OP_GET_MAX_RSS_QREGION:
1572 break;
1573 case VIRTCHNL_OP_ADD_ETH_ADDR:
1574 case VIRTCHNL_OP_DEL_ETH_ADDR:
1575 valid_len = sizeof(struct virtchnl_ether_addr_list);
1576 if (msglen >= valid_len) {
1577 struct virtchnl_ether_addr_list *veal =
1578 (struct virtchnl_ether_addr_list *)msg;
1579
1580 if (veal->num_elements == 0 || veal->num_elements >
1581 VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) {
1582 err_msg_format = TRUE;
1583 break;
1584 }
1585
1586 valid_len += veal->num_elements *
1587 sizeof(struct virtchnl_ether_addr);
1588 }
1589 break;
1590 case VIRTCHNL_OP_ADD_VLAN:
1591 case VIRTCHNL_OP_DEL_VLAN:
1592 valid_len = sizeof(struct virtchnl_vlan_filter_list);
1593 if (msglen >= valid_len) {
1594 struct virtchnl_vlan_filter_list *vfl =
1595 (struct virtchnl_vlan_filter_list *)msg;
1596
1597 if (vfl->num_elements == 0 || vfl->num_elements >
1598 VIRTCHNL_OP_ADD_DEL_VLAN_MAX) {
1599 err_msg_format = TRUE;
1600 break;
1601 }
1602
1603 valid_len += vfl->num_elements * sizeof(u16);
1604 }
1605 break;
1606 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1607 valid_len = sizeof(struct virtchnl_promisc_info);
1608 break;
1609 case VIRTCHNL_OP_GET_STATS:
1610 valid_len = sizeof(struct virtchnl_queue_select);
1611 break;
1612 case VIRTCHNL_OP_IWARP:
1613 /* These messages are opaque to us and will be validated in
1614 * the RDMA client code. We just need to check for nonzero
1615 * length. The firmware will enforce max length restrictions.
1616 */
1617 if (msglen)
1618 valid_len = msglen;
1619 else
1620 err_msg_format = TRUE;
1621 break;
1622 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
1623 break;
1624 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1625 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
1626 if (msglen >= valid_len) {
1627 struct virtchnl_iwarp_qvlist_info *qv =
1628 (struct virtchnl_iwarp_qvlist_info *)msg;
1629
1630 if (qv->num_vectors == 0 || qv->num_vectors >
1631 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP_MAX) {
1632 err_msg_format = TRUE;
1633 break;
1634 }
1635
1636 valid_len += ((qv->num_vectors - 1) *
1637 sizeof(struct virtchnl_iwarp_qv_info));
1638 }
1639 break;
1640 case VIRTCHNL_OP_CONFIG_RSS_KEY:
1641 valid_len = sizeof(struct virtchnl_rss_key);
1642 if (msglen >= valid_len) {
1643 struct virtchnl_rss_key *vrk =
1644 (struct virtchnl_rss_key *)msg;
1645
1646 if (vrk->key_len == 0) {
1647 /* zero length is allowed as input */
1648 break;
1649 }
1650
1651 valid_len += vrk->key_len - 1;
1652 }
1653 break;
1654 case VIRTCHNL_OP_CONFIG_RSS_LUT:
1655 valid_len = sizeof(struct virtchnl_rss_lut);
1656 if (msglen >= valid_len) {
1657 struct virtchnl_rss_lut *vrl =
1658 (struct virtchnl_rss_lut *)msg;
1659
1660 if (vrl->lut_entries == 0) {
1661 /* zero entries is allowed as input */
1662 break;
1663 }
1664
1665 valid_len += vrl->lut_entries - 1;
1666 }
1667 break;
1668 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
1669 break;
1670 case VIRTCHNL_OP_SET_RSS_HENA:
1671 valid_len = sizeof(struct virtchnl_rss_hena);
1672 break;
1673 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1674 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1675 break;
1676 case VIRTCHNL_OP_REQUEST_QUEUES:
1677 valid_len = sizeof(struct virtchnl_vf_res_request);
1678 break;
1679 case VIRTCHNL_OP_ENABLE_CHANNELS:
1680 valid_len = sizeof(struct virtchnl_tc_info);
1681 if (msglen >= valid_len) {
1682 struct virtchnl_tc_info *vti =
1683 (struct virtchnl_tc_info *)msg;
1684
1685 if (vti->num_tc == 0 || vti->num_tc >
1686 VIRTCHNL_OP_ENABLE_CHANNELS_MAX) {
1687 err_msg_format = TRUE;
1688 break;
1689 }
1690
1691 valid_len += (vti->num_tc - 1) *
1692 sizeof(struct virtchnl_channel_info);
1693 }
1694 break;
1695 case VIRTCHNL_OP_DISABLE_CHANNELS:
1696 break;
1697 case VIRTCHNL_OP_ADD_CLOUD_FILTER:
1698 case VIRTCHNL_OP_DEL_CLOUD_FILTER:
1699 valid_len = sizeof(struct virtchnl_filter);
1700 break;
1701 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
1702 break;
1703 case VIRTCHNL_OP_ADD_VLAN_V2:
1704 case VIRTCHNL_OP_DEL_VLAN_V2:
1705 valid_len = sizeof(struct virtchnl_vlan_filter_list_v2);
1706 if (msglen >= valid_len) {
1707 struct virtchnl_vlan_filter_list_v2 *vfl =
1708 (struct virtchnl_vlan_filter_list_v2 *)msg;
1709
1710 if (vfl->num_elements == 0 || vfl->num_elements >
1711 VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX) {
1712 err_msg_format = TRUE;
1713 break;
1714 }
1715
1716 valid_len += (vfl->num_elements - 1) *
1717 sizeof(struct virtchnl_vlan_filter);
1718 }
1719 break;
1720 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1721 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1722 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1723 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1724 case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2:
1725 case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
1726 valid_len = sizeof(struct virtchnl_vlan_setting);
1727 break;
1728 case VIRTCHNL_OP_ENABLE_QUEUES_V2:
1729 case VIRTCHNL_OP_DISABLE_QUEUES_V2:
1730 valid_len = sizeof(struct virtchnl_del_ena_dis_queues);
1731 if (msglen >= valid_len) {
1732 struct virtchnl_del_ena_dis_queues *qs =
1733 (struct virtchnl_del_ena_dis_queues *)msg;
1734 if (qs->chunks.num_chunks == 0 ||
1735 qs->chunks.num_chunks > VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX) {
1736 err_msg_format = TRUE;
1737 break;
1738 }
1739 valid_len += (qs->chunks.num_chunks - 1) *
1740 sizeof(struct virtchnl_queue_chunk);
1741 }
1742 break;
1743 case VIRTCHNL_OP_MAP_QUEUE_VECTOR:
1744 valid_len = sizeof(struct virtchnl_queue_vector_maps);
1745 if (msglen >= valid_len) {
1746 struct virtchnl_queue_vector_maps *v_qp =
1747 (struct virtchnl_queue_vector_maps *)msg;
1748 if (v_qp->num_qv_maps == 0 ||
1749 v_qp->num_qv_maps > VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX) {
1750 err_msg_format = TRUE;
1751 break;
1752 }
1753 valid_len += (v_qp->num_qv_maps - 1) *
1754 sizeof(struct virtchnl_queue_vector);
1755 }
1756 break;
1757 /* These are always errors coming from the VF. */
1758 case VIRTCHNL_OP_EVENT:
1759 case VIRTCHNL_OP_UNKNOWN:
1760 default:
1761 return VIRTCHNL_STATUS_ERR_PARAM;
1762 }
1763 /* few more checks */
1764 if (err_msg_format || valid_len != msglen)
1765 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
1766
1767 return 0;
1768 }
1769 #endif /* _VIRTCHNL_H_ */
|