Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*******************************************************************************
3 *
4 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
5 * Copyright(c) 2013 - 2014 Intel Corporation.
6 *
7 * Contact Information:
8 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
9 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
10 *
11 ******************************************************************************/
12
13#ifndef _VIRTCHNL_H_
14#define _VIRTCHNL_H_
15
16/* Description:
17 * This header file describes the VF-PF communication protocol used
18 * by the drivers for all devices starting from our 40G product line
19 *
20 * Admin queue buffer usage:
21 * desc->opcode is always aqc_opc_send_msg_to_pf
22 * flags, retval, datalen, and data addr are all used normally.
23 * The Firmware copies the cookie fields when sending messages between the
24 * PF and VF, but uses all other fields internally. Due to this limitation,
25 * we must send all messages as "indirect", i.e. using an external buffer.
26 *
27 * All the VSI indexes are relative to the VF. Each VF can have maximum of
28 * three VSIs. All the queue indexes are relative to the VSI. Each VF can
29 * have a maximum of sixteen queues for all of its VSIs.
30 *
31 * The PF is required to return a status code in v_retval for all messages
32 * except RESET_VF, which does not require any response. The return value
33 * is of status_code type, defined in the shared type.h.
34 *
35 * In general, VF driver initialization should roughly follow the order of
36 * these opcodes. The VF driver must first validate the API version of the
37 * PF driver, then request a reset, then get resources, then configure
38 * queues and interrupts. After these operations are complete, the VF
39 * driver may start its queues, optionally add MAC and VLAN filters, and
40 * process traffic.
41 */
42
43/* START GENERIC DEFINES
44 * Need to ensure the following enums and defines hold the same meaning and
45 * value in current and future projects
46 */
47
48/* Error Codes */
49enum virtchnl_status_code {
50 VIRTCHNL_STATUS_SUCCESS = 0,
51 VIRTCHNL_STATUS_ERR_PARAM = -5,
52 VIRTCHNL_STATUS_ERR_NO_MEMORY = -18,
53 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38,
54 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39,
55 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40,
56 VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR = -53,
57 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED = -64,
58};
59
60/* Backward compatibility */
61#define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM
62#define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED
63
64#define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT 0x0
65#define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1
66#define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2
67#define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3
68#define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4
69#define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5
70#define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6
71#define VIRTCHNL_LINK_SPEED_5GB_SHIFT 0x7
72
73enum virtchnl_link_speed {
74 VIRTCHNL_LINK_SPEED_UNKNOWN = 0,
75 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT),
76 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT),
77 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT),
78 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT),
79 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT),
80 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT),
81 VIRTCHNL_LINK_SPEED_2_5GB = BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT),
82 VIRTCHNL_LINK_SPEED_5GB = BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT),
83};
84
85/* for hsplit_0 field of Rx HMC context */
86/* deprecated with AVF 1.0 */
87enum virtchnl_rx_hsplit {
88 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0,
89 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1,
90 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2,
91 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4,
92 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8,
93};
94
95/* END GENERIC DEFINES */
96
97/* Opcodes for VF-PF communication. These are placed in the v_opcode field
98 * of the virtchnl_msg structure.
99 */
100enum virtchnl_ops {
101/* The PF sends status change events to VFs using
102 * the VIRTCHNL_OP_EVENT opcode.
103 * VFs send requests to the PF using the other ops.
104 * Use of "advanced opcode" features must be negotiated as part of capabilities
105 * exchange and are not considered part of base mode feature set.
106 */
107 VIRTCHNL_OP_UNKNOWN = 0,
108 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
109 VIRTCHNL_OP_RESET_VF = 2,
110 VIRTCHNL_OP_GET_VF_RESOURCES = 3,
111 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
112 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
113 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
114 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
115 VIRTCHNL_OP_ENABLE_QUEUES = 8,
116 VIRTCHNL_OP_DISABLE_QUEUES = 9,
117 VIRTCHNL_OP_ADD_ETH_ADDR = 10,
118 VIRTCHNL_OP_DEL_ETH_ADDR = 11,
119 VIRTCHNL_OP_ADD_VLAN = 12,
120 VIRTCHNL_OP_DEL_VLAN = 13,
121 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
122 VIRTCHNL_OP_GET_STATS = 15,
123 VIRTCHNL_OP_RSVD = 16,
124 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
125 VIRTCHNL_OP_IWARP = 20, /* advanced opcode */
126 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */
127 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */
128 VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
129 VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
130 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
131 VIRTCHNL_OP_SET_RSS_HENA = 26,
132 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27,
133 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28,
134 VIRTCHNL_OP_REQUEST_QUEUES = 29,
135 VIRTCHNL_OP_ENABLE_CHANNELS = 30,
136 VIRTCHNL_OP_DISABLE_CHANNELS = 31,
137 VIRTCHNL_OP_ADD_CLOUD_FILTER = 32,
138 VIRTCHNL_OP_DEL_CLOUD_FILTER = 33,
139 /* opcode 34 - 43 are reserved */
140 VIRTCHNL_OP_GET_SUPPORTED_RXDIDS = 44,
141 VIRTCHNL_OP_ADD_RSS_CFG = 45,
142 VIRTCHNL_OP_DEL_RSS_CFG = 46,
143 VIRTCHNL_OP_ADD_FDIR_FILTER = 47,
144 VIRTCHNL_OP_DEL_FDIR_FILTER = 48,
145 VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS = 51,
146 VIRTCHNL_OP_ADD_VLAN_V2 = 52,
147 VIRTCHNL_OP_DEL_VLAN_V2 = 53,
148 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 = 54,
149 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 = 55,
150 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 = 56,
151 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
152 VIRTCHNL_OP_MAX,
153};
154
155/* These macros are used to generate compilation errors if a structure/union
156 * is not exactly the correct length. It gives a divide by zero error if the
157 * structure/union is not of the correct size, otherwise it creates an enum
158 * that is 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#define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
163 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
164
165/* Virtual channel message descriptor. This overlays the admin queue
166 * descriptor. All other data is passed in external buffers.
167 */
168
169struct virtchnl_msg {
170 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
171 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
172 enum virtchnl_status_code v_retval; /* ditto for desc->retval */
173 u32 vfid; /* used by PF when sending to VF */
174};
175
176VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
177
178/* Message descriptions and data structures. */
179
180/* VIRTCHNL_OP_VERSION
181 * VF posts its version number to the PF. PF responds with its version number
182 * in the same format, along with a return code.
183 * Reply from PF has its major/minor versions also in param0 and param1.
184 * If there is a major version mismatch, then the VF cannot operate.
185 * If there is a minor version mismatch, then the VF can operate but should
186 * add a warning to the system log.
187 *
188 * This enum element MUST always be specified as == 1, regardless of other
189 * changes in the API. The PF must always respond to this message without
190 * error regardless of version mismatch.
191 */
192#define VIRTCHNL_VERSION_MAJOR 1
193#define VIRTCHNL_VERSION_MINOR 1
194#define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
195
196struct virtchnl_version_info {
197 u32 major;
198 u32 minor;
199};
200
201VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
202
203#define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
204#define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
205
206/* VIRTCHNL_OP_RESET_VF
207 * VF sends this request to PF with no parameters
208 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
209 * until reset completion is indicated. The admin queue must be reinitialized
210 * after this operation.
211 *
212 * When reset is complete, PF must ensure that all queues in all VSIs associated
213 * with the VF are stopped, all queue configurations in the HMC are set to 0,
214 * and all MAC and VLAN filters (except the default MAC address) on all VSIs
215 * are cleared.
216 */
217
218/* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
219 * vsi_type should always be 6 for backward compatibility. Add other fields
220 * as needed.
221 */
222enum virtchnl_vsi_type {
223 VIRTCHNL_VSI_TYPE_INVALID = 0,
224 VIRTCHNL_VSI_SRIOV = 6,
225};
226
227/* VIRTCHNL_OP_GET_VF_RESOURCES
228 * Version 1.0 VF sends this request to PF with no parameters
229 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
230 * PF responds with an indirect message containing
231 * virtchnl_vf_resource and one or more
232 * virtchnl_vsi_resource structures.
233 */
234
235struct virtchnl_vsi_resource {
236 u16 vsi_id;
237 u16 num_queue_pairs;
238 enum virtchnl_vsi_type vsi_type;
239 u16 qset_handle;
240 u8 default_mac_addr[ETH_ALEN];
241};
242
243VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
244
245/* VF capability flags
246 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
247 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
248 */
249#define VIRTCHNL_VF_OFFLOAD_L2 BIT(0)
250#define VIRTCHNL_VF_OFFLOAD_IWARP BIT(1)
251#define VIRTCHNL_VF_OFFLOAD_RSS_AQ BIT(3)
252#define VIRTCHNL_VF_OFFLOAD_RSS_REG BIT(4)
253#define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR BIT(5)
254#define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES BIT(6)
255/* used to negotiate communicating link speeds in Mbps */
256#define VIRTCHNL_VF_CAP_ADV_LINK_SPEED BIT(7)
257#define VIRTCHNL_VF_OFFLOAD_VLAN_V2 BIT(15)
258#define VIRTCHNL_VF_OFFLOAD_VLAN BIT(16)
259#define VIRTCHNL_VF_OFFLOAD_RX_POLLING BIT(17)
260#define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 BIT(18)
261#define VIRTCHNL_VF_OFFLOAD_RSS_PF BIT(19)
262#define VIRTCHNL_VF_OFFLOAD_ENCAP BIT(20)
263#define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM BIT(21)
264#define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM BIT(22)
265#define VIRTCHNL_VF_OFFLOAD_ADQ BIT(23)
266#define VIRTCHNL_VF_OFFLOAD_USO BIT(25)
267#define VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC BIT(26)
268#define VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF BIT(27)
269#define VIRTCHNL_VF_OFFLOAD_FDIR_PF BIT(28)
270
271#define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
272 VIRTCHNL_VF_OFFLOAD_VLAN | \
273 VIRTCHNL_VF_OFFLOAD_RSS_PF)
274
275struct virtchnl_vf_resource {
276 u16 num_vsis;
277 u16 num_queue_pairs;
278 u16 max_vectors;
279 u16 max_mtu;
280
281 u32 vf_cap_flags;
282 u32 rss_key_size;
283 u32 rss_lut_size;
284
285 struct virtchnl_vsi_resource vsi_res[1];
286};
287
288VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
289
290/* VIRTCHNL_OP_CONFIG_TX_QUEUE
291 * VF sends this message to set up parameters for one TX queue.
292 * External data buffer contains one instance of virtchnl_txq_info.
293 * PF configures requested queue and returns a status code.
294 */
295
296/* Tx queue config info */
297struct virtchnl_txq_info {
298 u16 vsi_id;
299 u16 queue_id;
300 u16 ring_len; /* number of descriptors, multiple of 8 */
301 u16 headwb_enabled; /* deprecated with AVF 1.0 */
302 u64 dma_ring_addr;
303 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
304};
305
306VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
307
308/* VIRTCHNL_OP_CONFIG_RX_QUEUE
309 * VF sends this message to set up parameters for one RX queue.
310 * External data buffer contains one instance of virtchnl_rxq_info.
311 * PF configures requested queue and returns a status code.
312 */
313
314/* Rx queue config info */
315struct virtchnl_rxq_info {
316 u16 vsi_id;
317 u16 queue_id;
318 u32 ring_len; /* number of descriptors, multiple of 32 */
319 u16 hdr_size;
320 u16 splithdr_enabled; /* deprecated with AVF 1.0 */
321 u32 databuffer_size;
322 u32 max_pkt_size;
323 u8 pad0;
324 u8 rxdid;
325 u8 pad1[2];
326 u64 dma_ring_addr;
327 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
328 u32 pad2;
329};
330
331VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
332
333/* VIRTCHNL_OP_CONFIG_VSI_QUEUES
334 * VF sends this message to set parameters for all active TX and RX queues
335 * associated with the specified VSI.
336 * PF configures queues and returns status.
337 * If the number of queues specified is greater than the number of queues
338 * associated with the VSI, an error is returned and no queues are configured.
339 */
340struct virtchnl_queue_pair_info {
341 /* NOTE: vsi_id and queue_id should be identical for both queues. */
342 struct virtchnl_txq_info txq;
343 struct virtchnl_rxq_info rxq;
344};
345
346VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
347
348struct virtchnl_vsi_queue_config_info {
349 u16 vsi_id;
350 u16 num_queue_pairs;
351 u32 pad;
352 struct virtchnl_queue_pair_info qpair[1];
353};
354
355VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
356
357/* VIRTCHNL_OP_REQUEST_QUEUES
358 * VF sends this message to request the PF to allocate additional queues to
359 * this VF. Each VF gets a guaranteed number of queues on init but asking for
360 * additional queues must be negotiated. This is a best effort request as it
361 * is possible the PF does not have enough queues left to support the request.
362 * If the PF cannot support the number requested it will respond with the
363 * maximum number it is able to support. If the request is successful, PF will
364 * then reset the VF to institute required changes.
365 */
366
367/* VF resource request */
368struct virtchnl_vf_res_request {
369 u16 num_queue_pairs;
370};
371
372/* VIRTCHNL_OP_CONFIG_IRQ_MAP
373 * VF uses this message to map vectors to queues.
374 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
375 * are to be associated with the specified vector.
376 * The "other" causes are always mapped to vector 0.
377 * PF configures interrupt mapping and returns status.
378 */
379struct virtchnl_vector_map {
380 u16 vsi_id;
381 u16 vector_id;
382 u16 rxq_map;
383 u16 txq_map;
384 u16 rxitr_idx;
385 u16 txitr_idx;
386};
387
388VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
389
390struct virtchnl_irq_map_info {
391 u16 num_vectors;
392 struct virtchnl_vector_map vecmap[1];
393};
394
395VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
396
397/* VIRTCHNL_OP_ENABLE_QUEUES
398 * VIRTCHNL_OP_DISABLE_QUEUES
399 * VF sends these message to enable or disable TX/RX queue pairs.
400 * The queues fields are bitmaps indicating which queues to act upon.
401 * (Currently, we only support 16 queues per VF, but we make the field
402 * u32 to allow for expansion.)
403 * PF performs requested action and returns status.
404 */
405struct virtchnl_queue_select {
406 u16 vsi_id;
407 u16 pad;
408 u32 rx_queues;
409 u32 tx_queues;
410};
411
412VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
413
414/* VIRTCHNL_OP_ADD_ETH_ADDR
415 * VF sends this message in order to add one or more unicast or multicast
416 * address filters for the specified VSI.
417 * PF adds the filters and returns status.
418 */
419
420/* VIRTCHNL_OP_DEL_ETH_ADDR
421 * VF sends this message in order to remove one or more unicast or multicast
422 * filters for the specified VSI.
423 * PF removes the filters and returns status.
424 */
425
426/* VIRTCHNL_ETHER_ADDR_LEGACY
427 * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad
428 * bytes. Moving forward all VF drivers should not set type to
429 * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy
430 * behavior. The control plane function (i.e. PF) can use a best effort method
431 * of tracking the primary/device unicast in this case, but there is no
432 * guarantee and functionality depends on the implementation of the PF.
433 */
434
435/* VIRTCHNL_ETHER_ADDR_PRIMARY
436 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the
437 * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and
438 * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane
439 * function (i.e. PF) to accurately track and use this MAC address for
440 * displaying on the host and for VM/function reset.
441 */
442
443/* VIRTCHNL_ETHER_ADDR_EXTRA
444 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra
445 * unicast and/or multicast filters that are being added/deleted via
446 * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively.
447 */
448struct virtchnl_ether_addr {
449 u8 addr[ETH_ALEN];
450 u8 type;
451#define VIRTCHNL_ETHER_ADDR_LEGACY 0
452#define VIRTCHNL_ETHER_ADDR_PRIMARY 1
453#define VIRTCHNL_ETHER_ADDR_EXTRA 2
454#define VIRTCHNL_ETHER_ADDR_TYPE_MASK 3 /* first two bits of type are valid */
455 u8 pad;
456};
457
458VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
459
460struct virtchnl_ether_addr_list {
461 u16 vsi_id;
462 u16 num_elements;
463 struct virtchnl_ether_addr list[1];
464};
465
466VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
467
468/* VIRTCHNL_OP_ADD_VLAN
469 * VF sends this message to add one or more VLAN tag filters for receives.
470 * PF adds the filters and returns status.
471 * If a port VLAN is configured by the PF, this operation will return an
472 * error to the VF.
473 */
474
475/* VIRTCHNL_OP_DEL_VLAN
476 * VF sends this message to remove one or more VLAN tag filters for receives.
477 * PF removes the filters and returns status.
478 * If a port VLAN is configured by the PF, this operation will return an
479 * error to the VF.
480 */
481
482struct virtchnl_vlan_filter_list {
483 u16 vsi_id;
484 u16 num_elements;
485 u16 vlan_id[1];
486};
487
488VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
489
490/* This enum is used for all of the VIRTCHNL_VF_OFFLOAD_VLAN_V2_CAPS related
491 * structures and opcodes.
492 *
493 * VIRTCHNL_VLAN_UNSUPPORTED - This field is not supported and if a VF driver
494 * populates it the PF should return VIRTCHNL_STATUS_ERR_NOT_SUPPORTED.
495 *
496 * VIRTCHNL_VLAN_ETHERTYPE_8100 - This field supports 0x8100 ethertype.
497 * VIRTCHNL_VLAN_ETHERTYPE_88A8 - This field supports 0x88A8 ethertype.
498 * VIRTCHNL_VLAN_ETHERTYPE_9100 - This field supports 0x9100 ethertype.
499 *
500 * VIRTCHNL_VLAN_ETHERTYPE_AND - Used when multiple ethertypes can be supported
501 * by the PF concurrently. For example, if the PF can support
502 * VIRTCHNL_VLAN_ETHERTYPE_8100 AND VIRTCHNL_VLAN_ETHERTYPE_88A8 filters it
503 * would OR the following bits:
504 *
505 * VIRTHCNL_VLAN_ETHERTYPE_8100 |
506 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
507 * VIRTCHNL_VLAN_ETHERTYPE_AND;
508 *
509 * The VF would interpret this as VLAN filtering can be supported on both 0x8100
510 * and 0x88A8 VLAN ethertypes.
511 *
512 * VIRTCHNL_ETHERTYPE_XOR - Used when only a single ethertype can be supported
513 * by the PF concurrently. For example if the PF can support
514 * VIRTCHNL_VLAN_ETHERTYPE_8100 XOR VIRTCHNL_VLAN_ETHERTYPE_88A8 stripping
515 * offload it would OR the following bits:
516 *
517 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
518 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
519 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
520 *
521 * The VF would interpret this as VLAN stripping can be supported on either
522 * 0x8100 or 0x88a8 VLAN ethertypes. So when requesting VLAN stripping via
523 * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 the specified ethertype will override
524 * the previously set value.
525 *
526 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 - Used to tell the VF to insert and/or
527 * strip the VLAN tag using the L2TAG1 field of the Tx/Rx descriptors.
528 *
529 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to insert hardware
530 * offloaded VLAN tags using the L2TAG2 field of the Tx descriptor.
531 *
532 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to strip hardware
533 * offloaded VLAN tags using the L2TAG2_2 field of the Rx descriptor.
534 *
535 * VIRTCHNL_VLAN_PRIO - This field supports VLAN priority bits. This is used for
536 * VLAN filtering if the underlying PF supports it.
537 *
538 * VIRTCHNL_VLAN_TOGGLE_ALLOWED - This field is used to say whether a
539 * certain VLAN capability can be toggled. For example if the underlying PF/CP
540 * allows the VF to toggle VLAN filtering, stripping, and/or insertion it should
541 * set this bit along with the supported ethertypes.
542 */
543enum virtchnl_vlan_support {
544 VIRTCHNL_VLAN_UNSUPPORTED = 0,
545 VIRTCHNL_VLAN_ETHERTYPE_8100 = BIT(0),
546 VIRTCHNL_VLAN_ETHERTYPE_88A8 = BIT(1),
547 VIRTCHNL_VLAN_ETHERTYPE_9100 = BIT(2),
548 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 = BIT(8),
549 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 = BIT(9),
550 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 = BIT(10),
551 VIRTCHNL_VLAN_PRIO = BIT(24),
552 VIRTCHNL_VLAN_FILTER_MASK = BIT(28),
553 VIRTCHNL_VLAN_ETHERTYPE_AND = BIT(29),
554 VIRTCHNL_VLAN_ETHERTYPE_XOR = BIT(30),
555 VIRTCHNL_VLAN_TOGGLE = BIT(31),
556};
557
558/* This structure is used as part of the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
559 * for filtering, insertion, and stripping capabilities.
560 *
561 * If only outer capabilities are supported (for filtering, insertion, and/or
562 * stripping) then this refers to the outer most or single VLAN from the VF's
563 * perspective.
564 *
565 * If only inner capabilities are supported (for filtering, insertion, and/or
566 * stripping) then this refers to the outer most or single VLAN from the VF's
567 * perspective. Functionally this is the same as if only outer capabilities are
568 * supported. The VF driver is just forced to use the inner fields when
569 * adding/deleting filters and enabling/disabling offloads (if supported).
570 *
571 * If both outer and inner capabilities are supported (for filtering, insertion,
572 * and/or stripping) then outer refers to the outer most or single VLAN and
573 * inner refers to the second VLAN, if it exists, in the packet.
574 *
575 * There is no support for tunneled VLAN offloads, so outer or inner are never
576 * referring to a tunneled packet from the VF's perspective.
577 */
578struct virtchnl_vlan_supported_caps {
579 u32 outer;
580 u32 inner;
581};
582
583/* The PF populates these fields based on the supported VLAN filtering. If a
584 * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
585 * reject any VIRTCHNL_OP_ADD_VLAN_V2 or VIRTCHNL_OP_DEL_VLAN_V2 messages using
586 * the unsupported fields.
587 *
588 * Also, a VF is only allowed to toggle its VLAN filtering setting if the
589 * VIRTCHNL_VLAN_TOGGLE bit is set.
590 *
591 * The ethertype(s) specified in the ethertype_init field are the ethertypes
592 * enabled for VLAN filtering. VLAN filtering in this case refers to the outer
593 * most VLAN from the VF's perspective. If both inner and outer filtering are
594 * allowed then ethertype_init only refers to the outer most VLAN as only
595 * VLAN ethertype supported for inner VLAN filtering is
596 * VIRTCHNL_VLAN_ETHERTYPE_8100. By default, inner VLAN filtering is disabled
597 * when both inner and outer filtering are allowed.
598 *
599 * The max_filters field tells the VF how many VLAN filters it's allowed to have
600 * at any one time. If it exceeds this amount and tries to add another filter,
601 * then the request will be rejected by the PF. To prevent failures, the VF
602 * should keep track of how many VLAN filters it has added and not attempt to
603 * add more than max_filters.
604 */
605struct virtchnl_vlan_filtering_caps {
606 struct virtchnl_vlan_supported_caps filtering_support;
607 u32 ethertype_init;
608 u16 max_filters;
609 u8 pad[2];
610};
611
612VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_filtering_caps);
613
614/* This enum is used for the virtchnl_vlan_offload_caps structure to specify
615 * if the PF supports a different ethertype for stripping and insertion.
616 *
617 * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION - The ethertype(s) specified
618 * for stripping affect the ethertype(s) specified for insertion and visa versa
619 * as well. If the VF tries to configure VLAN stripping via
620 * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 with VIRTCHNL_VLAN_ETHERTYPE_8100 then
621 * that will be the ethertype for both stripping and insertion.
622 *
623 * VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED - The ethertype(s) specified for
624 * stripping do not affect the ethertype(s) specified for insertion and visa
625 * versa.
626 */
627enum virtchnl_vlan_ethertype_match {
628 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION = 0,
629 VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED = 1,
630};
631
632/* The PF populates these fields based on the supported VLAN offloads. If a
633 * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will
634 * reject any VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 or
635 * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 messages using the unsupported fields.
636 *
637 * Also, a VF is only allowed to toggle its VLAN offload setting if the
638 * VIRTCHNL_VLAN_TOGGLE_ALLOWED bit is set.
639 *
640 * The VF driver needs to be aware of how the tags are stripped by hardware and
641 * inserted by the VF driver based on the level of offload support. The PF will
642 * populate these fields based on where the VLAN tags are expected to be
643 * offloaded via the VIRTHCNL_VLAN_TAG_LOCATION_* bits. The VF will need to
644 * interpret these fields. See the definition of the
645 * VIRTCHNL_VLAN_TAG_LOCATION_* bits above the virtchnl_vlan_support
646 * enumeration.
647 */
648struct virtchnl_vlan_offload_caps {
649 struct virtchnl_vlan_supported_caps stripping_support;
650 struct virtchnl_vlan_supported_caps insertion_support;
651 u32 ethertype_init;
652 u8 ethertype_match;
653 u8 pad[3];
654};
655
656VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_vlan_offload_caps);
657
658/* VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
659 * VF sends this message to determine its VLAN capabilities.
660 *
661 * PF will mark which capabilities it supports based on hardware support and
662 * current configuration. For example, if a port VLAN is configured the PF will
663 * not allow outer VLAN filtering, stripping, or insertion to be configured so
664 * it will block these features from the VF.
665 *
666 * The VF will need to cross reference its capabilities with the PFs
667 * capabilities in the response message from the PF to determine the VLAN
668 * support.
669 */
670struct virtchnl_vlan_caps {
671 struct virtchnl_vlan_filtering_caps filtering;
672 struct virtchnl_vlan_offload_caps offloads;
673};
674
675VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_caps);
676
677struct virtchnl_vlan {
678 u16 tci; /* tci[15:13] = PCP and tci[11:0] = VID */
679 u16 tci_mask; /* only valid if VIRTCHNL_VLAN_FILTER_MASK set in
680 * filtering caps
681 */
682 u16 tpid; /* 0x8100, 0x88a8, etc. and only type(s) set in
683 * filtering caps. Note that tpid here does not refer to
684 * VIRTCHNL_VLAN_ETHERTYPE_*, but it refers to the
685 * actual 2-byte VLAN TPID
686 */
687 u8 pad[2];
688};
689
690VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan);
691
692struct virtchnl_vlan_filter {
693 struct virtchnl_vlan inner;
694 struct virtchnl_vlan outer;
695 u8 pad[16];
696};
697
698VIRTCHNL_CHECK_STRUCT_LEN(32, virtchnl_vlan_filter);
699
700/* VIRTCHNL_OP_ADD_VLAN_V2
701 * VIRTCHNL_OP_DEL_VLAN_V2
702 *
703 * VF sends these messages to add/del one or more VLAN tag filters for Rx
704 * traffic.
705 *
706 * The PF attempts to add the filters and returns status.
707 *
708 * The VF should only ever attempt to add/del virtchnl_vlan_filter(s) using the
709 * supported fields negotiated via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS.
710 */
711struct virtchnl_vlan_filter_list_v2 {
712 u16 vport_id;
713 u16 num_elements;
714 u8 pad[4];
715 struct virtchnl_vlan_filter filters[1];
716};
717
718VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_filter_list_v2);
719
720/* VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
721 * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
722 * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
723 * VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
724 *
725 * VF sends this message to enable or disable VLAN stripping or insertion. It
726 * also needs to specify an ethertype. The VF knows which VLAN ethertypes are
727 * allowed and whether or not it's allowed to enable/disable the specific
728 * offload via the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to
729 * parse the virtchnl_vlan_caps.offloads fields to determine which offload
730 * messages are allowed.
731 *
732 * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
733 * following manner the VF will be allowed to enable and/or disable 0x8100 inner
734 * VLAN insertion and/or stripping via the opcodes listed above. Inner in this
735 * case means the outer most or single VLAN from the VF's perspective. This is
736 * because no outer offloads are supported. See the comments above the
737 * virtchnl_vlan_supported_caps structure for more details.
738 *
739 * virtchnl_vlan_caps.offloads.stripping_support.inner =
740 * VIRTCHNL_VLAN_TOGGLE |
741 * VIRTCHNL_VLAN_ETHERTYPE_8100;
742 *
743 * virtchnl_vlan_caps.offloads.insertion_support.inner =
744 * VIRTCHNL_VLAN_TOGGLE |
745 * VIRTCHNL_VLAN_ETHERTYPE_8100;
746 *
747 * In order to enable inner (again note that in this case inner is the outer
748 * most or single VLAN from the VF's perspective) VLAN stripping for 0x8100
749 * VLANs, the VF would populate the virtchnl_vlan_setting structure in the
750 * following manner and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
751 *
752 * virtchnl_vlan_setting.inner_ethertype_setting =
753 * VIRTCHNL_VLAN_ETHERTYPE_8100;
754 *
755 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
756 * initialization.
757 *
758 * The reason that VLAN TPID(s) are not being used for the
759 * outer_ethertype_setting and inner_ethertype_setting fields is because it's
760 * possible a device could support VLAN insertion and/or stripping offload on
761 * multiple ethertypes concurrently, so this method allows a VF to request
762 * multiple ethertypes in one message using the virtchnl_vlan_support
763 * enumeration.
764 *
765 * For example, if the PF populates the virtchnl_vlan_caps.offloads in the
766 * following manner the VF will be allowed to enable 0x8100 and 0x88a8 outer
767 * VLAN insertion and stripping simultaneously. The
768 * virtchnl_vlan_caps.offloads.ethertype_match field will also have to be
769 * populated based on what the PF can support.
770 *
771 * virtchnl_vlan_caps.offloads.stripping_support.outer =
772 * VIRTCHNL_VLAN_TOGGLE |
773 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
774 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
775 * VIRTCHNL_VLAN_ETHERTYPE_AND;
776 *
777 * virtchnl_vlan_caps.offloads.insertion_support.outer =
778 * VIRTCHNL_VLAN_TOGGLE |
779 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
780 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
781 * VIRTCHNL_VLAN_ETHERTYPE_AND;
782 *
783 * In order to enable outer VLAN stripping for 0x8100 and 0x88a8 VLANs, the VF
784 * would populate the virthcnl_vlan_offload_structure in the following manner
785 * and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message.
786 *
787 * virtchnl_vlan_setting.outer_ethertype_setting =
788 * VIRTHCNL_VLAN_ETHERTYPE_8100 |
789 * VIRTHCNL_VLAN_ETHERTYPE_88A8;
790 *
791 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
792 * initialization.
793 *
794 * There is also the case where a PF and the underlying hardware can support
795 * VLAN offloads on multiple ethertypes, but not concurrently. For example, if
796 * the PF populates the virtchnl_vlan_caps.offloads in the following manner the
797 * VF will be allowed to enable and/or disable 0x8100 XOR 0x88a8 outer VLAN
798 * offloads. The ethertypes must match for stripping and insertion.
799 *
800 * virtchnl_vlan_caps.offloads.stripping_support.outer =
801 * VIRTCHNL_VLAN_TOGGLE |
802 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
803 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
804 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
805 *
806 * virtchnl_vlan_caps.offloads.insertion_support.outer =
807 * VIRTCHNL_VLAN_TOGGLE |
808 * VIRTCHNL_VLAN_ETHERTYPE_8100 |
809 * VIRTCHNL_VLAN_ETHERTYPE_88A8 |
810 * VIRTCHNL_VLAN_ETHERTYPE_XOR;
811 *
812 * virtchnl_vlan_caps.offloads.ethertype_match =
813 * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
814 *
815 * In order to enable outer VLAN stripping for 0x88a8 VLANs, the VF would
816 * populate the virtchnl_vlan_setting structure in the following manner and send
817 * the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2. Also, this will change the
818 * ethertype for VLAN insertion if it's enabled. So, for completeness, a
819 * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 with the same ethertype should be sent.
820 *
821 * virtchnl_vlan_setting.outer_ethertype_setting = VIRTHCNL_VLAN_ETHERTYPE_88A8;
822 *
823 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on
824 * initialization.
825 */
826struct virtchnl_vlan_setting {
827 u32 outer_ethertype_setting;
828 u32 inner_ethertype_setting;
829 u16 vport_id;
830 u8 pad[6];
831};
832
833VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_setting);
834
835/* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
836 * VF sends VSI id and flags.
837 * PF returns status code in retval.
838 * Note: we assume that broadcast accept mode is always enabled.
839 */
840struct virtchnl_promisc_info {
841 u16 vsi_id;
842 u16 flags;
843};
844
845VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
846
847#define FLAG_VF_UNICAST_PROMISC 0x00000001
848#define FLAG_VF_MULTICAST_PROMISC 0x00000002
849
850/* VIRTCHNL_OP_GET_STATS
851 * VF sends this message to request stats for the selected VSI. VF uses
852 * the virtchnl_queue_select struct to specify the VSI. The queue_id
853 * field is ignored by the PF.
854 *
855 * PF replies with struct eth_stats in an external buffer.
856 */
857
858/* VIRTCHNL_OP_CONFIG_RSS_KEY
859 * VIRTCHNL_OP_CONFIG_RSS_LUT
860 * VF sends these messages to configure RSS. Only supported if both PF
861 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
862 * configuration negotiation. If this is the case, then the RSS fields in
863 * the VF resource struct are valid.
864 * Both the key and LUT are initialized to 0 by the PF, meaning that
865 * RSS is effectively disabled until set up by the VF.
866 */
867struct virtchnl_rss_key {
868 u16 vsi_id;
869 u16 key_len;
870 u8 key[1]; /* RSS hash key, packed bytes */
871};
872
873VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
874
875struct virtchnl_rss_lut {
876 u16 vsi_id;
877 u16 lut_entries;
878 u8 lut[1]; /* RSS lookup table */
879};
880
881VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
882
883/* VIRTCHNL_OP_GET_RSS_HENA_CAPS
884 * VIRTCHNL_OP_SET_RSS_HENA
885 * VF sends these messages to get and set the hash filter enable bits for RSS.
886 * By default, the PF sets these to all possible traffic types that the
887 * hardware supports. The VF can query this value if it wants to change the
888 * traffic types that are hashed by the hardware.
889 */
890struct virtchnl_rss_hena {
891 u64 hena;
892};
893
894VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
895
896/* VIRTCHNL_OP_ENABLE_CHANNELS
897 * VIRTCHNL_OP_DISABLE_CHANNELS
898 * VF sends these messages to enable or disable channels based on
899 * the user specified queue count and queue offset for each traffic class.
900 * This struct encompasses all the information that the PF needs from
901 * VF to create a channel.
902 */
903struct virtchnl_channel_info {
904 u16 count; /* number of queues in a channel */
905 u16 offset; /* queues in a channel start from 'offset' */
906 u32 pad;
907 u64 max_tx_rate;
908};
909
910VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info);
911
912struct virtchnl_tc_info {
913 u32 num_tc;
914 u32 pad;
915 struct virtchnl_channel_info list[1];
916};
917
918VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info);
919
920/* VIRTCHNL_ADD_CLOUD_FILTER
921 * VIRTCHNL_DEL_CLOUD_FILTER
922 * VF sends these messages to add or delete a cloud filter based on the
923 * user specified match and action filters. These structures encompass
924 * all the information that the PF needs from the VF to add/delete a
925 * cloud filter.
926 */
927
928struct virtchnl_l4_spec {
929 u8 src_mac[ETH_ALEN];
930 u8 dst_mac[ETH_ALEN];
931 __be16 vlan_id;
932 __be16 pad; /* reserved for future use */
933 __be32 src_ip[4];
934 __be32 dst_ip[4];
935 __be16 src_port;
936 __be16 dst_port;
937};
938
939VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec);
940
941union virtchnl_flow_spec {
942 struct virtchnl_l4_spec tcp_spec;
943 u8 buffer[128]; /* reserved for future use */
944};
945
946VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec);
947
948enum virtchnl_action {
949 /* action types */
950 VIRTCHNL_ACTION_DROP = 0,
951 VIRTCHNL_ACTION_TC_REDIRECT,
952 VIRTCHNL_ACTION_PASSTHRU,
953 VIRTCHNL_ACTION_QUEUE,
954 VIRTCHNL_ACTION_Q_REGION,
955 VIRTCHNL_ACTION_MARK,
956 VIRTCHNL_ACTION_COUNT,
957};
958
959enum virtchnl_flow_type {
960 /* flow types */
961 VIRTCHNL_TCP_V4_FLOW = 0,
962 VIRTCHNL_TCP_V6_FLOW,
963};
964
965struct virtchnl_filter {
966 union virtchnl_flow_spec data;
967 union virtchnl_flow_spec mask;
968 enum virtchnl_flow_type flow_type;
969 enum virtchnl_action action;
970 u32 action_meta;
971 u8 field_flags;
972 u8 pad[3];
973};
974
975VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter);
976
977struct virtchnl_supported_rxdids {
978 u64 supported_rxdids;
979};
980
981/* VIRTCHNL_OP_EVENT
982 * PF sends this message to inform the VF driver of events that may affect it.
983 * No direct response is expected from the VF, though it may generate other
984 * messages in response to this one.
985 */
986enum virtchnl_event_codes {
987 VIRTCHNL_EVENT_UNKNOWN = 0,
988 VIRTCHNL_EVENT_LINK_CHANGE,
989 VIRTCHNL_EVENT_RESET_IMPENDING,
990 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
991};
992
993#define PF_EVENT_SEVERITY_INFO 0
994#define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
995
996struct virtchnl_pf_event {
997 enum virtchnl_event_codes event;
998 union {
999 /* If the PF driver does not support the new speed reporting
1000 * capabilities then use link_event else use link_event_adv to
1001 * get the speed and link information. The ability to understand
1002 * new speeds is indicated by setting the capability flag
1003 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter
1004 * in virtchnl_vf_resource struct and can be used to determine
1005 * which link event struct to use below.
1006 */
1007 struct {
1008 enum virtchnl_link_speed link_speed;
1009 bool link_status;
1010 } link_event;
1011 struct {
1012 /* link_speed provided in Mbps */
1013 u32 link_speed;
1014 u8 link_status;
1015 u8 pad[3];
1016 } link_event_adv;
1017 } event_data;
1018
1019 int severity;
1020};
1021
1022VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
1023
1024/* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
1025 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
1026 * The request for this originates from the VF IWARP driver through
1027 * a client interface between VF LAN and VF IWARP driver.
1028 * A vector could have an AEQ and CEQ attached to it although
1029 * there is a single AEQ per VF IWARP instance in which case
1030 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
1031 * There will never be a case where there will be multiple CEQs attached
1032 * to a single vector.
1033 * PF configures interrupt mapping and returns status.
1034 */
1035
1036struct virtchnl_iwarp_qv_info {
1037 u32 v_idx; /* msix_vector */
1038 u16 ceq_idx;
1039 u16 aeq_idx;
1040 u8 itr_idx;
1041 u8 pad[3];
1042};
1043
1044VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
1045
1046struct virtchnl_iwarp_qvlist_info {
1047 u32 num_vectors;
1048 struct virtchnl_iwarp_qv_info qv_info[1];
1049};
1050
1051VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
1052
1053/* VF reset states - these are written into the RSTAT register:
1054 * VFGEN_RSTAT on the VF
1055 * When the PF initiates a reset, it writes 0
1056 * When the reset is complete, it writes 1
1057 * When the PF detects that the VF has recovered, it writes 2
1058 * VF checks this register periodically to determine if a reset has occurred,
1059 * then polls it to know when the reset is complete.
1060 * If either the PF or VF reads the register while the hardware
1061 * is in a reset state, it will return DEADBEEF, which, when masked
1062 * will result in 3.
1063 */
1064enum virtchnl_vfr_states {
1065 VIRTCHNL_VFR_INPROGRESS = 0,
1066 VIRTCHNL_VFR_COMPLETED,
1067 VIRTCHNL_VFR_VFACTIVE,
1068};
1069
1070/* Type of RSS algorithm */
1071enum virtchnl_rss_algorithm {
1072 VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0,
1073 VIRTCHNL_RSS_ALG_R_ASYMMETRIC = 1,
1074 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2,
1075 VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3,
1076};
1077
1078#define VIRTCHNL_MAX_NUM_PROTO_HDRS 32
1079#define PROTO_HDR_SHIFT 5
1080#define PROTO_HDR_FIELD_START(proto_hdr_type) ((proto_hdr_type) << PROTO_HDR_SHIFT)
1081#define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1)
1082
1083/* VF use these macros to configure each protocol header.
1084 * Specify which protocol headers and protocol header fields base on
1085 * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field.
1086 * @param hdr: a struct of virtchnl_proto_hdr
1087 * @param hdr_type: ETH/IPV4/TCP, etc
1088 * @param field: SRC/DST/TEID/SPI, etc
1089 */
1090#define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field) \
1091 ((hdr)->field_selector |= BIT((field) & PROTO_HDR_FIELD_MASK))
1092#define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field) \
1093 ((hdr)->field_selector &= ~BIT((field) & PROTO_HDR_FIELD_MASK))
1094#define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val) \
1095 ((hdr)->field_selector & BIT((val) & PROTO_HDR_FIELD_MASK))
1096#define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr) ((hdr)->field_selector)
1097
1098#define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
1099 (VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, \
1100 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
1101#define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \
1102 (VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, \
1103 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field))
1104
1105#define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type) \
1106 ((hdr)->type = VIRTCHNL_PROTO_HDR_ ## hdr_type)
1107#define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \
1108 (((hdr)->type) >> PROTO_HDR_SHIFT)
1109#define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \
1110 ((hdr)->type == ((val) >> PROTO_HDR_SHIFT))
1111#define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \
1112 (VIRTCHNL_TEST_PROTO_HDR_TYPE((hdr), (val)) && \
1113 VIRTCHNL_TEST_PROTO_HDR_FIELD((hdr), (val)))
1114
1115/* Protocol header type within a packet segment. A segment consists of one or
1116 * more protocol headers that make up a logical group of protocol headers. Each
1117 * logical group of protocol headers encapsulates or is encapsulated using/by
1118 * tunneling or encapsulation protocols for network virtualization.
1119 */
1120enum virtchnl_proto_hdr_type {
1121 VIRTCHNL_PROTO_HDR_NONE,
1122 VIRTCHNL_PROTO_HDR_ETH,
1123 VIRTCHNL_PROTO_HDR_S_VLAN,
1124 VIRTCHNL_PROTO_HDR_C_VLAN,
1125 VIRTCHNL_PROTO_HDR_IPV4,
1126 VIRTCHNL_PROTO_HDR_IPV6,
1127 VIRTCHNL_PROTO_HDR_TCP,
1128 VIRTCHNL_PROTO_HDR_UDP,
1129 VIRTCHNL_PROTO_HDR_SCTP,
1130 VIRTCHNL_PROTO_HDR_GTPU_IP,
1131 VIRTCHNL_PROTO_HDR_GTPU_EH,
1132 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
1133 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
1134 VIRTCHNL_PROTO_HDR_PPPOE,
1135 VIRTCHNL_PROTO_HDR_L2TPV3,
1136 VIRTCHNL_PROTO_HDR_ESP,
1137 VIRTCHNL_PROTO_HDR_AH,
1138 VIRTCHNL_PROTO_HDR_PFCP,
1139};
1140
1141/* Protocol header field within a protocol header. */
1142enum virtchnl_proto_hdr_field {
1143 /* ETHER */
1144 VIRTCHNL_PROTO_HDR_ETH_SRC =
1145 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ETH),
1146 VIRTCHNL_PROTO_HDR_ETH_DST,
1147 VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
1148 /* S-VLAN */
1149 VIRTCHNL_PROTO_HDR_S_VLAN_ID =
1150 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_S_VLAN),
1151 /* C-VLAN */
1152 VIRTCHNL_PROTO_HDR_C_VLAN_ID =
1153 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_C_VLAN),
1154 /* IPV4 */
1155 VIRTCHNL_PROTO_HDR_IPV4_SRC =
1156 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4),
1157 VIRTCHNL_PROTO_HDR_IPV4_DST,
1158 VIRTCHNL_PROTO_HDR_IPV4_DSCP,
1159 VIRTCHNL_PROTO_HDR_IPV4_TTL,
1160 VIRTCHNL_PROTO_HDR_IPV4_PROT,
1161 /* IPV6 */
1162 VIRTCHNL_PROTO_HDR_IPV6_SRC =
1163 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6),
1164 VIRTCHNL_PROTO_HDR_IPV6_DST,
1165 VIRTCHNL_PROTO_HDR_IPV6_TC,
1166 VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
1167 VIRTCHNL_PROTO_HDR_IPV6_PROT,
1168 /* TCP */
1169 VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
1170 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_TCP),
1171 VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
1172 /* UDP */
1173 VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
1174 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_UDP),
1175 VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
1176 /* SCTP */
1177 VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
1178 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_SCTP),
1179 VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
1180 /* GTPU_IP */
1181 VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
1182 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_IP),
1183 /* GTPU_EH */
1184 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
1185 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH),
1186 VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
1187 /* PPPOE */
1188 VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
1189 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PPPOE),
1190 /* L2TPV3 */
1191 VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
1192 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV3),
1193 /* ESP */
1194 VIRTCHNL_PROTO_HDR_ESP_SPI =
1195 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ESP),
1196 /* AH */
1197 VIRTCHNL_PROTO_HDR_AH_SPI =
1198 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_AH),
1199 /* PFCP */
1200 VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
1201 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PFCP),
1202 VIRTCHNL_PROTO_HDR_PFCP_SEID,
1203};
1204
1205struct virtchnl_proto_hdr {
1206 enum virtchnl_proto_hdr_type type;
1207 u32 field_selector; /* a bit mask to select field for header type */
1208 u8 buffer[64];
1209 /**
1210 * binary buffer in network order for specific header type.
1211 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
1212 * header is expected to be copied into the buffer.
1213 */
1214};
1215
1216VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr);
1217
1218struct virtchnl_proto_hdrs {
1219 u8 tunnel_level;
1220 u8 pad[3];
1221 /**
1222 * specify where protocol header start from.
1223 * 0 - from the outer layer
1224 * 1 - from the first inner layer
1225 * 2 - from the second inner layer
1226 * ....
1227 **/
1228 int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */
1229 struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
1230};
1231
1232VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs);
1233
1234struct virtchnl_rss_cfg {
1235 struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */
1236 enum virtchnl_rss_algorithm rss_algorithm; /* RSS algorithm type */
1237 u8 reserved[128]; /* reserve for future */
1238};
1239
1240VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg);
1241
1242/* action configuration for FDIR */
1243struct virtchnl_filter_action {
1244 enum virtchnl_action type;
1245 union {
1246 /* used for queue and qgroup action */
1247 struct {
1248 u16 index;
1249 u8 region;
1250 } queue;
1251 /* used for count action */
1252 struct {
1253 /* share counter ID with other flow rules */
1254 u8 shared;
1255 u32 id; /* counter ID */
1256 } count;
1257 /* used for mark action */
1258 u32 mark_id;
1259 u8 reserve[32];
1260 } act_conf;
1261};
1262
1263VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action);
1264
1265#define VIRTCHNL_MAX_NUM_ACTIONS 8
1266
1267struct virtchnl_filter_action_set {
1268 /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
1269 int count;
1270 struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
1271};
1272
1273VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set);
1274
1275/* pattern and action for FDIR rule */
1276struct virtchnl_fdir_rule {
1277 struct virtchnl_proto_hdrs proto_hdrs;
1278 struct virtchnl_filter_action_set action_set;
1279};
1280
1281VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule);
1282
1283/* Status returned to VF after VF requests FDIR commands
1284 * VIRTCHNL_FDIR_SUCCESS
1285 * VF FDIR related request is successfully done by PF
1286 * The request can be OP_ADD/DEL.
1287 *
1288 * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
1289 * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
1290 *
1291 * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
1292 * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
1293 *
1294 * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
1295 * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
1296 *
1297 * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
1298 * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
1299 *
1300 * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
1301 * OP_ADD_FDIR_FILTER request is failed due to parameters validation
1302 * or HW doesn't support.
1303 *
1304 * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
1305 * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
1306 * for programming.
1307 */
1308enum virtchnl_fdir_prgm_status {
1309 VIRTCHNL_FDIR_SUCCESS = 0,
1310 VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
1311 VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
1312 VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
1313 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
1314 VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
1315 VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
1316};
1317
1318/* VIRTCHNL_OP_ADD_FDIR_FILTER
1319 * VF sends this request to PF by filling out vsi_id,
1320 * validate_only and rule_cfg. PF will return flow_id
1321 * if the request is successfully done and return add_status to VF.
1322 */
1323struct virtchnl_fdir_add {
1324 u16 vsi_id; /* INPUT */
1325 /*
1326 * 1 for validating a fdir rule, 0 for creating a fdir rule.
1327 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
1328 */
1329 u16 validate_only; /* INPUT */
1330 u32 flow_id; /* OUTPUT */
1331 struct virtchnl_fdir_rule rule_cfg; /* INPUT */
1332 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
1333};
1334
1335VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add);
1336
1337/* VIRTCHNL_OP_DEL_FDIR_FILTER
1338 * VF sends this request to PF by filling out vsi_id
1339 * and flow_id. PF will return del_status to VF.
1340 */
1341struct virtchnl_fdir_del {
1342 u16 vsi_id; /* INPUT */
1343 u16 pad;
1344 u32 flow_id; /* INPUT */
1345 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
1346};
1347
1348VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del);
1349
1350/**
1351 * virtchnl_vc_validate_vf_msg
1352 * @ver: Virtchnl version info
1353 * @v_opcode: Opcode for the message
1354 * @msg: pointer to the msg buffer
1355 * @msglen: msg length
1356 *
1357 * validate msg format against struct for each opcode
1358 */
1359static inline int
1360virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
1361 u8 *msg, u16 msglen)
1362{
1363 bool err_msg_format = false;
1364 int valid_len = 0;
1365
1366 /* Validate message length. */
1367 switch (v_opcode) {
1368 case VIRTCHNL_OP_VERSION:
1369 valid_len = sizeof(struct virtchnl_version_info);
1370 break;
1371 case VIRTCHNL_OP_RESET_VF:
1372 break;
1373 case VIRTCHNL_OP_GET_VF_RESOURCES:
1374 if (VF_IS_V11(ver))
1375 valid_len = sizeof(u32);
1376 break;
1377 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
1378 valid_len = sizeof(struct virtchnl_txq_info);
1379 break;
1380 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
1381 valid_len = sizeof(struct virtchnl_rxq_info);
1382 break;
1383 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1384 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
1385 if (msglen >= valid_len) {
1386 struct virtchnl_vsi_queue_config_info *vqc =
1387 (struct virtchnl_vsi_queue_config_info *)msg;
1388 valid_len += (vqc->num_queue_pairs *
1389 sizeof(struct
1390 virtchnl_queue_pair_info));
1391 if (vqc->num_queue_pairs == 0)
1392 err_msg_format = true;
1393 }
1394 break;
1395 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1396 valid_len = sizeof(struct virtchnl_irq_map_info);
1397 if (msglen >= valid_len) {
1398 struct virtchnl_irq_map_info *vimi =
1399 (struct virtchnl_irq_map_info *)msg;
1400 valid_len += (vimi->num_vectors *
1401 sizeof(struct virtchnl_vector_map));
1402 if (vimi->num_vectors == 0)
1403 err_msg_format = true;
1404 }
1405 break;
1406 case VIRTCHNL_OP_ENABLE_QUEUES:
1407 case VIRTCHNL_OP_DISABLE_QUEUES:
1408 valid_len = sizeof(struct virtchnl_queue_select);
1409 break;
1410 case VIRTCHNL_OP_ADD_ETH_ADDR:
1411 case VIRTCHNL_OP_DEL_ETH_ADDR:
1412 valid_len = sizeof(struct virtchnl_ether_addr_list);
1413 if (msglen >= valid_len) {
1414 struct virtchnl_ether_addr_list *veal =
1415 (struct virtchnl_ether_addr_list *)msg;
1416 valid_len += veal->num_elements *
1417 sizeof(struct virtchnl_ether_addr);
1418 if (veal->num_elements == 0)
1419 err_msg_format = true;
1420 }
1421 break;
1422 case VIRTCHNL_OP_ADD_VLAN:
1423 case VIRTCHNL_OP_DEL_VLAN:
1424 valid_len = sizeof(struct virtchnl_vlan_filter_list);
1425 if (msglen >= valid_len) {
1426 struct virtchnl_vlan_filter_list *vfl =
1427 (struct virtchnl_vlan_filter_list *)msg;
1428 valid_len += vfl->num_elements * sizeof(u16);
1429 if (vfl->num_elements == 0)
1430 err_msg_format = true;
1431 }
1432 break;
1433 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1434 valid_len = sizeof(struct virtchnl_promisc_info);
1435 break;
1436 case VIRTCHNL_OP_GET_STATS:
1437 valid_len = sizeof(struct virtchnl_queue_select);
1438 break;
1439 case VIRTCHNL_OP_IWARP:
1440 /* These messages are opaque to us and will be validated in
1441 * the RDMA client code. We just need to check for nonzero
1442 * length. The firmware will enforce max length restrictions.
1443 */
1444 if (msglen)
1445 valid_len = msglen;
1446 else
1447 err_msg_format = true;
1448 break;
1449 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
1450 break;
1451 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1452 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
1453 if (msglen >= valid_len) {
1454 struct virtchnl_iwarp_qvlist_info *qv =
1455 (struct virtchnl_iwarp_qvlist_info *)msg;
1456 if (qv->num_vectors == 0) {
1457 err_msg_format = true;
1458 break;
1459 }
1460 valid_len += ((qv->num_vectors - 1) *
1461 sizeof(struct virtchnl_iwarp_qv_info));
1462 }
1463 break;
1464 case VIRTCHNL_OP_CONFIG_RSS_KEY:
1465 valid_len = sizeof(struct virtchnl_rss_key);
1466 if (msglen >= valid_len) {
1467 struct virtchnl_rss_key *vrk =
1468 (struct virtchnl_rss_key *)msg;
1469 valid_len += vrk->key_len - 1;
1470 }
1471 break;
1472 case VIRTCHNL_OP_CONFIG_RSS_LUT:
1473 valid_len = sizeof(struct virtchnl_rss_lut);
1474 if (msglen >= valid_len) {
1475 struct virtchnl_rss_lut *vrl =
1476 (struct virtchnl_rss_lut *)msg;
1477 valid_len += vrl->lut_entries - 1;
1478 }
1479 break;
1480 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
1481 break;
1482 case VIRTCHNL_OP_SET_RSS_HENA:
1483 valid_len = sizeof(struct virtchnl_rss_hena);
1484 break;
1485 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1486 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1487 break;
1488 case VIRTCHNL_OP_REQUEST_QUEUES:
1489 valid_len = sizeof(struct virtchnl_vf_res_request);
1490 break;
1491 case VIRTCHNL_OP_ENABLE_CHANNELS:
1492 valid_len = sizeof(struct virtchnl_tc_info);
1493 if (msglen >= valid_len) {
1494 struct virtchnl_tc_info *vti =
1495 (struct virtchnl_tc_info *)msg;
1496 valid_len += (vti->num_tc - 1) *
1497 sizeof(struct virtchnl_channel_info);
1498 if (vti->num_tc == 0)
1499 err_msg_format = true;
1500 }
1501 break;
1502 case VIRTCHNL_OP_DISABLE_CHANNELS:
1503 break;
1504 case VIRTCHNL_OP_ADD_CLOUD_FILTER:
1505 valid_len = sizeof(struct virtchnl_filter);
1506 break;
1507 case VIRTCHNL_OP_DEL_CLOUD_FILTER:
1508 valid_len = sizeof(struct virtchnl_filter);
1509 break;
1510 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
1511 break;
1512 case VIRTCHNL_OP_ADD_RSS_CFG:
1513 case VIRTCHNL_OP_DEL_RSS_CFG:
1514 valid_len = sizeof(struct virtchnl_rss_cfg);
1515 break;
1516 case VIRTCHNL_OP_ADD_FDIR_FILTER:
1517 valid_len = sizeof(struct virtchnl_fdir_add);
1518 break;
1519 case VIRTCHNL_OP_DEL_FDIR_FILTER:
1520 valid_len = sizeof(struct virtchnl_fdir_del);
1521 break;
1522 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
1523 break;
1524 case VIRTCHNL_OP_ADD_VLAN_V2:
1525 case VIRTCHNL_OP_DEL_VLAN_V2:
1526 valid_len = sizeof(struct virtchnl_vlan_filter_list_v2);
1527 if (msglen >= valid_len) {
1528 struct virtchnl_vlan_filter_list_v2 *vfl =
1529 (struct virtchnl_vlan_filter_list_v2 *)msg;
1530
1531 valid_len += (vfl->num_elements - 1) *
1532 sizeof(struct virtchnl_vlan_filter);
1533
1534 if (vfl->num_elements == 0) {
1535 err_msg_format = true;
1536 break;
1537 }
1538 }
1539 break;
1540 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1541 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1542 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1543 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1544 valid_len = sizeof(struct virtchnl_vlan_setting);
1545 break;
1546 /* These are always errors coming from the VF. */
1547 case VIRTCHNL_OP_EVENT:
1548 case VIRTCHNL_OP_UNKNOWN:
1549 default:
1550 return VIRTCHNL_STATUS_ERR_PARAM;
1551 }
1552 /* few more checks */
1553 if (err_msg_format || valid_len != msglen)
1554 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
1555
1556 return 0;
1557}
1558#endif /* _VIRTCHNL_H_ */