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