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 };
139
140 /* This macro is used to generate a compilation error if a structure
141 * is not exactly the correct length. It gives a divide by zero error if the
142 * structure is not of the correct size, otherwise it creates an enum that is
143 * never used.
144 */
145 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
146 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
147
148 /* Virtual channel message descriptor. This overlays the admin queue
149 * descriptor. All other data is passed in external buffers.
150 */
151
152 struct virtchnl_msg {
153 u8 pad[8]; /* AQ flags/opcode/len/retval fields */
154 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
155 enum virtchnl_status_code v_retval; /* ditto for desc->retval */
156 u32 vfid; /* used by PF when sending to VF */
157 };
158
159 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg);
160
161 /* Message descriptions and data structures.*/
162
163 /* VIRTCHNL_OP_VERSION
164 * VF posts its version number to the PF. PF responds with its version number
165 * in the same format, along with a return code.
166 * Reply from PF has its major/minor versions also in param0 and param1.
167 * If there is a major version mismatch, then the VF cannot operate.
168 * If there is a minor version mismatch, then the VF can operate but should
169 * add a warning to the system log.
170 *
171 * This enum element MUST always be specified as == 1, regardless of other
172 * changes in the API. The PF must always respond to this message without
173 * error regardless of version mismatch.
174 */
175 #define VIRTCHNL_VERSION_MAJOR 1
176 #define VIRTCHNL_VERSION_MINOR 1
177 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0
178
179 struct virtchnl_version_info {
180 u32 major;
181 u32 minor;
182 };
183
184 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info);
185
186 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0))
187 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1))
188
189 /* VIRTCHNL_OP_RESET_VF
190 * VF sends this request to PF with no parameters
191 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
192 * until reset completion is indicated. The admin queue must be reinitialized
193 * after this operation.
194 *
195 * When reset is complete, PF must ensure that all queues in all VSIs associated
196 * with the VF are stopped, all queue configurations in the HMC are set to 0,
197 * and all MAC and VLAN filters (except the default MAC address) on all VSIs
198 * are cleared.
199 */
200
201 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV
202 * vsi_type should always be 6 for backward compatibility. Add other fields
203 * as needed.
204 */
205 enum virtchnl_vsi_type {
206 VIRTCHNL_VSI_TYPE_INVALID = 0,
207 VIRTCHNL_VSI_SRIOV = 6,
208 };
209
210 /* VIRTCHNL_OP_GET_VF_RESOURCES
211 * Version 1.0 VF sends this request to PF with no parameters
212 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
213 * PF responds with an indirect message containing
214 * virtchnl_vf_resource and one or more
215 * virtchnl_vsi_resource structures.
216 */
217
218 struct virtchnl_vsi_resource {
219 u16 vsi_id;
220 u16 num_queue_pairs;
221 enum virtchnl_vsi_type vsi_type;
222 u16 qset_handle;
223 u8 default_mac_addr[ETH_ALEN];
224 };
225
226 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
227
228 /* VF capability flags
229 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including
230 * TX/RX Checksum offloading and TSO for non-tunnelled packets.
231 */
232 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001
233 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002
234 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004
235 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008
236 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010
237 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020
238 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000
239 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000
240 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000
241 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000
242 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000
243 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000
244 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000
245
246 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
247 VIRTCHNL_VF_OFFLOAD_VLAN | \
248 VIRTCHNL_VF_OFFLOAD_RSS_PF)
249
250 struct virtchnl_vf_resource {
251 u16 num_vsis;
252 u16 num_queue_pairs;
253 u16 max_vectors;
254 u16 max_mtu;
255
256 u32 vf_cap_flags;
257 u32 rss_key_size;
258 u32 rss_lut_size;
259
260 struct virtchnl_vsi_resource vsi_res[1];
261 };
262
263 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource);
264
265 /* VIRTCHNL_OP_CONFIG_TX_QUEUE
266 * VF sends this message to set up parameters for one TX queue.
267 * External data buffer contains one instance of virtchnl_txq_info.
268 * PF configures requested queue and returns a status code.
269 */
270
271 /* Tx queue config info */
272 struct virtchnl_txq_info {
273 u16 vsi_id;
274 u16 queue_id;
275 u16 ring_len; /* number of descriptors, multiple of 8 */
276 u16 headwb_enabled; /* deprecated with AVF 1.0 */
277 u64 dma_ring_addr;
278 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */
279 };
280
281 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info);
282
283 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
284 * VF sends this message to set up parameters for one RX queue.
285 * External data buffer contains one instance of virtchnl_rxq_info.
286 * PF configures requested queue and returns a status code.
287 */
288
289 /* Rx queue config info */
290 struct virtchnl_rxq_info {
291 u16 vsi_id;
292 u16 queue_id;
293 u32 ring_len; /* number of descriptors, multiple of 32 */
294 u16 hdr_size;
295 u16 splithdr_enabled; /* deprecated with AVF 1.0 */
296 u32 databuffer_size;
297 u32 max_pkt_size;
298 u32 pad1;
299 u64 dma_ring_addr;
300 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
301 u32 pad2;
302 };
303
304 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info);
305
306 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES
307 * VF sends this message to set parameters for all active TX and RX queues
308 * associated with the specified VSI.
309 * PF configures queues and returns status.
310 * If the number of queues specified is greater than the number of queues
311 * associated with the VSI, an error is returned and no queues are configured.
312 */
313 struct virtchnl_queue_pair_info {
314 /* NOTE: vsi_id and queue_id should be identical for both queues. */
315 struct virtchnl_txq_info txq;
316 struct virtchnl_rxq_info rxq;
317 };
318
319 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info);
320
321 struct virtchnl_vsi_queue_config_info {
322 u16 vsi_id;
323 u16 num_queue_pairs;
324 u32 pad;
325 struct virtchnl_queue_pair_info qpair[1];
326 };
327
328 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info);
329
330 /* VIRTCHNL_OP_CONFIG_IRQ_MAP
331 * VF uses this message to map vectors to queues.
332 * The rxq_map and txq_map fields are bitmaps used to indicate which queues
333 * are to be associated with the specified vector.
334 * The "other" causes are always mapped to vector 0.
335 * PF configures interrupt mapping and returns status.
336 */
337 struct virtchnl_vector_map {
338 u16 vsi_id;
339 u16 vector_id;
340 u16 rxq_map;
341 u16 txq_map;
342 u16 rxitr_idx;
343 u16 txitr_idx;
344 };
345
346 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map);
347
348 struct virtchnl_irq_map_info {
349 u16 num_vectors;
350 struct virtchnl_vector_map vecmap[1];
351 };
352
353 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info);
354
355 /* VIRTCHNL_OP_ENABLE_QUEUES
356 * VIRTCHNL_OP_DISABLE_QUEUES
357 * VF sends these message to enable or disable TX/RX queue pairs.
358 * The queues fields are bitmaps indicating which queues to act upon.
359 * (Currently, we only support 16 queues per VF, but we make the field
360 * u32 to allow for expansion.)
361 * PF performs requested action and returns status.
362 */
363 struct virtchnl_queue_select {
364 u16 vsi_id;
365 u16 pad;
366 u32 rx_queues;
367 u32 tx_queues;
368 };
369
370 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select);
371
372 /* VIRTCHNL_OP_ADD_ETH_ADDR
373 * VF sends this message in order to add one or more unicast or multicast
374 * address filters for the specified VSI.
375 * PF adds the filters and returns status.
376 */
377
378 /* VIRTCHNL_OP_DEL_ETH_ADDR
379 * VF sends this message in order to remove one or more unicast or multicast
380 * filters for the specified VSI.
381 * PF removes the filters and returns status.
382 */
383
384 struct virtchnl_ether_addr {
385 u8 addr[ETH_ALEN];
386 u8 pad[2];
387 };
388
389 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr);
390
391 struct virtchnl_ether_addr_list {
392 u16 vsi_id;
393 u16 num_elements;
394 struct virtchnl_ether_addr list[1];
395 };
396
397 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list);
398
399 /* VIRTCHNL_OP_ADD_VLAN
400 * VF sends this message to add one or more VLAN tag filters for receives.
401 * PF adds the filters and returns status.
402 * If a port VLAN is configured by the PF, this operation will return an
403 * error to the VF.
404 */
405
406 /* VIRTCHNL_OP_DEL_VLAN
407 * VF sends this message to remove one or more VLAN tag filters for receives.
408 * PF removes the filters and returns status.
409 * If a port VLAN is configured by the PF, this operation will return an
410 * error to the VF.
411 */
412
413 struct virtchnl_vlan_filter_list {
414 u16 vsi_id;
415 u16 num_elements;
416 u16 vlan_id[1];
417 };
418
419 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list);
420
421 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
422 * VF sends VSI id and flags.
423 * PF returns status code in retval.
424 * Note: we assume that broadcast accept mode is always enabled.
425 */
426 struct virtchnl_promisc_info {
427 u16 vsi_id;
428 u16 flags;
429 };
430
431 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info);
432
433 #define FLAG_VF_UNICAST_PROMISC 0x00000001
434 #define FLAG_VF_MULTICAST_PROMISC 0x00000002
435
436 /* VIRTCHNL_OP_GET_STATS
437 * VF sends this message to request stats for the selected VSI. VF uses
438 * the virtchnl_queue_select struct to specify the VSI. The queue_id
439 * field is ignored by the PF.
440 *
441 * PF replies with struct eth_stats in an external buffer.
442 */
443
444 /* VIRTCHNL_OP_CONFIG_RSS_KEY
445 * VIRTCHNL_OP_CONFIG_RSS_LUT
446 * VF sends these messages to configure RSS. Only supported if both PF
447 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
448 * configuration negotiation. If this is the case, then the RSS fields in
449 * the VF resource struct are valid.
450 * Both the key and LUT are initialized to 0 by the PF, meaning that
451 * RSS is effectively disabled until set up by the VF.
452 */
453 struct virtchnl_rss_key {
454 u16 vsi_id;
455 u16 key_len;
456 u8 key[1]; /* RSS hash key, packed bytes */
457 };
458
459 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
460
461 struct virtchnl_rss_lut {
462 u16 vsi_id;
463 u16 lut_entries;
464 u8 lut[1]; /* RSS lookup table*/
465 };
466
467 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut);
468
469 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
470 * VIRTCHNL_OP_SET_RSS_HENA
471 * VF sends these messages to get and set the hash filter enable bits for RSS.
472 * By default, the PF sets these to all possible traffic types that the
473 * hardware supports. The VF can query this value if it wants to change the
474 * traffic types that are hashed by the hardware.
475 */
476 struct virtchnl_rss_hena {
477 u64 hena;
478 };
479
480 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena);
481
482 /* VIRTCHNL_OP_EVENT
483 * PF sends this message to inform the VF driver of events that may affect it.
484 * No direct response is expected from the VF, though it may generate other
485 * messages in response to this one.
486 */
487 enum virtchnl_event_codes {
488 VIRTCHNL_EVENT_UNKNOWN = 0,
489 VIRTCHNL_EVENT_LINK_CHANGE,
490 VIRTCHNL_EVENT_RESET_IMPENDING,
491 VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
492 };
493
494 #define PF_EVENT_SEVERITY_INFO 0
495 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
496
497 struct virtchnl_pf_event {
498 enum virtchnl_event_codes event;
499 union {
500 struct {
501 enum virtchnl_link_speed link_speed;
502 bool link_status;
503 } link_event;
504 } event_data;
505
506 int severity;
507 };
508
509 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
510
511 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
512 * VF uses this message to request PF to map IWARP vectors to IWARP queues.
513 * The request for this originates from the VF IWARP driver through
514 * a client interface between VF LAN and VF IWARP driver.
515 * A vector could have an AEQ and CEQ attached to it although
516 * there is a single AEQ per VF IWARP instance in which case
517 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq.
518 * There will never be a case where there will be multiple CEQs attached
519 * to a single vector.
520 * PF configures interrupt mapping and returns status.
521 */
522
523 struct virtchnl_iwarp_qv_info {
524 u32 v_idx; /* msix_vector */
525 u16 ceq_idx;
526 u16 aeq_idx;
527 u8 itr_idx;
528 };
529
530 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info);
531
532 struct virtchnl_iwarp_qvlist_info {
533 u32 num_vectors;
534 struct virtchnl_iwarp_qv_info qv_info[1];
535 };
536
537 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info);
538
539 /* VF reset states - these are written into the RSTAT register:
540 * VFGEN_RSTAT on the VF
541 * When the PF initiates a reset, it writes 0
542 * When the reset is complete, it writes 1
543 * When the PF detects that the VF has recovered, it writes 2
544 * VF checks this register periodically to determine if a reset has occurred,
545 * then polls it to know when the reset is complete.
546 * If either the PF or VF reads the register while the hardware
547 * is in a reset state, it will return DEADBEEF, which, when masked
548 * will result in 3.
549 */
550 enum virtchnl_vfr_states {
551 VIRTCHNL_VFR_INPROGRESS = 0,
552 VIRTCHNL_VFR_COMPLETED,
553 VIRTCHNL_VFR_VFACTIVE,
554 };
555
556 /**
557 * virtchnl_vc_validate_vf_msg
558 * @ver: Virtchnl version info
559 * @v_opcode: Opcode for the message
560 * @msg: pointer to the msg buffer
561 * @msglen: msg length
562 *
563 * validate msg format against struct for each opcode
564 */
565 static inline int
virtchnl_vc_validate_vf_msg(struct virtchnl_version_info * ver,u32 v_opcode,u8 * msg,u16 msglen)566 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
567 u8 *msg, u16 msglen)
568 {
569 bool err_msg_format = false;
570 int valid_len = 0;
571
572 /* Validate message length. */
573 switch (v_opcode) {
574 case VIRTCHNL_OP_VERSION:
575 valid_len = sizeof(struct virtchnl_version_info);
576 break;
577 case VIRTCHNL_OP_RESET_VF:
578 break;
579 case VIRTCHNL_OP_GET_VF_RESOURCES:
580 if (VF_IS_V11(ver))
581 valid_len = sizeof(u32);
582 break;
583 case VIRTCHNL_OP_CONFIG_TX_QUEUE:
584 valid_len = sizeof(struct virtchnl_txq_info);
585 break;
586 case VIRTCHNL_OP_CONFIG_RX_QUEUE:
587 valid_len = sizeof(struct virtchnl_rxq_info);
588 break;
589 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
590 valid_len = sizeof(struct virtchnl_vsi_queue_config_info);
591 if (msglen >= valid_len) {
592 struct virtchnl_vsi_queue_config_info *vqc =
593 (struct virtchnl_vsi_queue_config_info *)msg;
594 valid_len += (vqc->num_queue_pairs *
595 sizeof(struct
596 virtchnl_queue_pair_info));
597 if (vqc->num_queue_pairs == 0)
598 err_msg_format = true;
599 }
600 break;
601 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
602 valid_len = sizeof(struct virtchnl_irq_map_info);
603 if (msglen >= valid_len) {
604 struct virtchnl_irq_map_info *vimi =
605 (struct virtchnl_irq_map_info *)msg;
606 valid_len += (vimi->num_vectors *
607 sizeof(struct virtchnl_vector_map));
608 if (vimi->num_vectors == 0)
609 err_msg_format = true;
610 }
611 break;
612 case VIRTCHNL_OP_ENABLE_QUEUES:
613 case VIRTCHNL_OP_DISABLE_QUEUES:
614 valid_len = sizeof(struct virtchnl_queue_select);
615 break;
616 case VIRTCHNL_OP_ADD_ETH_ADDR:
617 case VIRTCHNL_OP_DEL_ETH_ADDR:
618 valid_len = sizeof(struct virtchnl_ether_addr_list);
619 if (msglen >= valid_len) {
620 struct virtchnl_ether_addr_list *veal =
621 (struct virtchnl_ether_addr_list *)msg;
622 valid_len += veal->num_elements *
623 sizeof(struct virtchnl_ether_addr);
624 if (veal->num_elements == 0)
625 err_msg_format = true;
626 }
627 break;
628 case VIRTCHNL_OP_ADD_VLAN:
629 case VIRTCHNL_OP_DEL_VLAN:
630 valid_len = sizeof(struct virtchnl_vlan_filter_list);
631 if (msglen >= valid_len) {
632 struct virtchnl_vlan_filter_list *vfl =
633 (struct virtchnl_vlan_filter_list *)msg;
634 valid_len += vfl->num_elements * sizeof(u16);
635 if (vfl->num_elements == 0)
636 err_msg_format = true;
637 }
638 break;
639 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
640 valid_len = sizeof(struct virtchnl_promisc_info);
641 break;
642 case VIRTCHNL_OP_GET_STATS:
643 valid_len = sizeof(struct virtchnl_queue_select);
644 break;
645 case VIRTCHNL_OP_IWARP:
646 /* These messages are opaque to us and will be validated in
647 * the RDMA client code. We just need to check for nonzero
648 * length. The firmware will enforce max length restrictions.
649 */
650 if (msglen)
651 valid_len = msglen;
652 else
653 err_msg_format = true;
654 break;
655 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
656 break;
657 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
658 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
659 if (msglen >= valid_len) {
660 struct virtchnl_iwarp_qvlist_info *qv =
661 (struct virtchnl_iwarp_qvlist_info *)msg;
662 if (qv->num_vectors == 0) {
663 err_msg_format = true;
664 break;
665 }
666 valid_len += ((qv->num_vectors - 1) *
667 sizeof(struct virtchnl_iwarp_qv_info));
668 }
669 break;
670 case VIRTCHNL_OP_CONFIG_RSS_KEY:
671 valid_len = sizeof(struct virtchnl_rss_key);
672 if (msglen >= valid_len) {
673 struct virtchnl_rss_key *vrk =
674 (struct virtchnl_rss_key *)msg;
675 valid_len += vrk->key_len - 1;
676 }
677 break;
678 case VIRTCHNL_OP_CONFIG_RSS_LUT:
679 valid_len = sizeof(struct virtchnl_rss_lut);
680 if (msglen >= valid_len) {
681 struct virtchnl_rss_lut *vrl =
682 (struct virtchnl_rss_lut *)msg;
683 valid_len += vrl->lut_entries - 1;
684 }
685 break;
686 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
687 break;
688 case VIRTCHNL_OP_SET_RSS_HENA:
689 valid_len = sizeof(struct virtchnl_rss_hena);
690 break;
691 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
692 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
693 break;
694 /* These are always errors coming from the VF. */
695 case VIRTCHNL_OP_EVENT:
696 case VIRTCHNL_OP_UNKNOWN:
697 default:
698 return VIRTCHNL_ERR_PARAM;
699 }
700 /* few more checks */
701 if ((valid_len != msglen) || (err_msg_format))
702 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
703
704 return 0;
705 }
706 #endif /* _VIRTCHNL_H_ */
707