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