7a24c0f1b332c2709a5b2968004895026b28e27b
[deb_dpdk.git] / drivers / net / i40e / base / i40e_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 _I40E_VIRTCHNL_H_
35 #define _I40E_VIRTCHNL_H_
36
37 #include "i40e_type.h"
38
39 /* Description:
40  * This header file describes the VF-PF communication protocol used
41  * by the various i40e drivers.
42  *
43  * Admin queue buffer usage:
44  * desc->opcode is always i40e_aqc_opc_send_msg_to_pf
45  * flags, retval, datalen, and data addr are all used normally.
46  * Firmware copies the cookie fields when sending messages between the PF and
47  * VF, but uses all other fields internally. Due to this limitation, we
48  * must send all messages as "indirect", i.e. using an external buffer.
49  *
50  * All the vsi indexes are relative to the VF. Each VF can have maximum of
51  * three VSIs. All the queue indexes are relative to the VSI.  Each VF can
52  * have a maximum of sixteen queues for all of its VSIs.
53  *
54  * The PF is required to return a status code in v_retval for all messages
55  * except RESET_VF, which does not require any response. The return value is of
56  * i40e_status_code type, defined in the i40e_type.h.
57  *
58  * In general, VF driver initialization should roughly follow the order of these
59  * opcodes. The VF driver must first validate the API version of the PF driver,
60  * then request a reset, then get resources, then configure queues and
61  * interrupts. After these operations are complete, the VF driver may start
62  * its queues, optionally add MAC and VLAN filters, and process traffic.
63  */
64
65 /* Opcodes for VF-PF communication. These are placed in the v_opcode field
66  * of the virtchnl_msg structure.
67  */
68 enum i40e_virtchnl_ops {
69 /* The PF sends status change events to VFs using
70  * the I40E_VIRTCHNL_OP_EVENT opcode.
71  * VFs send requests to the PF using the other ops.
72  */
73         I40E_VIRTCHNL_OP_UNKNOWN = 0,
74         I40E_VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */
75         I40E_VIRTCHNL_OP_RESET_VF = 2,
76         I40E_VIRTCHNL_OP_GET_VF_RESOURCES = 3,
77         I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE = 4,
78         I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE = 5,
79         I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6,
80         I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP = 7,
81         I40E_VIRTCHNL_OP_ENABLE_QUEUES = 8,
82         I40E_VIRTCHNL_OP_DISABLE_QUEUES = 9,
83         I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS = 10,
84         I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS = 11,
85         I40E_VIRTCHNL_OP_ADD_VLAN = 12,
86         I40E_VIRTCHNL_OP_DEL_VLAN = 13,
87         I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14,
88         I40E_VIRTCHNL_OP_GET_STATS = 15,
89         I40E_VIRTCHNL_OP_FCOE = 16,
90         I40E_VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */
91 #ifdef I40E_SOL_VF_SUPPORT
92         I40E_VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG = 19,
93 #endif
94         I40E_VIRTCHNL_OP_CONFIG_RSS_KEY = 23,
95         I40E_VIRTCHNL_OP_CONFIG_RSS_LUT = 24,
96         I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25,
97         I40E_VIRTCHNL_OP_SET_RSS_HENA = 26,
98
99 };
100
101 /* Virtual channel message descriptor. This overlays the admin queue
102  * descriptor. All other data is passed in external buffers.
103  */
104
105 struct i40e_virtchnl_msg {
106         u8 pad[8];                       /* AQ flags/opcode/len/retval fields */
107         enum i40e_virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */
108         enum i40e_status_code v_retval;  /* ditto for desc->retval */
109         u32 vfid;                        /* used by PF when sending to VF */
110 };
111
112 /* Message descriptions and data structures.*/
113
114 /* I40E_VIRTCHNL_OP_VERSION
115  * VF posts its version number to the PF. PF responds with its version number
116  * in the same format, along with a return code.
117  * Reply from PF has its major/minor versions also in param0 and param1.
118  * If there is a major version mismatch, then the VF cannot operate.
119  * If there is a minor version mismatch, then the VF can operate but should
120  * add a warning to the system log.
121  *
122  * This enum element MUST always be specified as == 1, regardless of other
123  * changes in the API. The PF must always respond to this message without
124  * error regardless of version mismatch.
125  */
126 #define I40E_VIRTCHNL_VERSION_MAJOR             1
127 #define I40E_VIRTCHNL_VERSION_MINOR             1
128 #define I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS  0
129
130 struct i40e_virtchnl_version_info {
131         u32 major;
132         u32 minor;
133 };
134
135 /* I40E_VIRTCHNL_OP_RESET_VF
136  * VF sends this request to PF with no parameters
137  * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register
138  * until reset completion is indicated. The admin queue must be reinitialized
139  * after this operation.
140  *
141  * When reset is complete, PF must ensure that all queues in all VSIs associated
142  * with the VF are stopped, all queue configurations in the HMC are set to 0,
143  * and all MAC and VLAN filters (except the default MAC address) on all VSIs
144  * are cleared.
145  */
146
147 /* I40E_VIRTCHNL_OP_GET_VF_RESOURCES
148  * Version 1.0 VF sends this request to PF with no parameters
149  * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities
150  * PF responds with an indirect message containing
151  * i40e_virtchnl_vf_resource and one or more
152  * i40e_virtchnl_vsi_resource structures.
153  */
154
155 struct i40e_virtchnl_vsi_resource {
156         u16 vsi_id;
157         u16 num_queue_pairs;
158         enum i40e_vsi_type vsi_type;
159         u16 qset_handle;
160         u8 default_mac_addr[I40E_ETH_LENGTH_OF_ADDRESS];
161 };
162 /* VF offload flags */
163 #define I40E_VIRTCHNL_VF_OFFLOAD_L2             0x00000001
164 #define I40E_VIRTCHNL_VF_OFFLOAD_IWARP          0x00000002
165 #define I40E_VIRTCHNL_VF_OFFLOAD_FCOE           0x00000004
166 #define I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ         0x00000008
167 #define I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG        0x00000010
168 #define I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR      0x00000020
169 #define I40E_VIRTCHNL_VF_OFFLOAD_VLAN           0x00010000
170 #define I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING     0x00020000
171 #define I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2  0x00040000
172 #define I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF         0X00080000
173 #define I40E_VIRTCHNL_VF_OFFLOAD_ENCAP          0X00100000
174 #define I40E_VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM     0X00200000
175 #define I40E_VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM  0X00400000
176
177 #define I40E_VF_BASE_MODE_OFFLOADS (I40E_VIRTCHNL_VF_OFFLOAD_L2 | \
178                                     I40E_VIRTCHNL_VF_OFFLOAD_VLAN | \
179                                     I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF)
180
181 struct i40e_virtchnl_vf_resource {
182         u16 num_vsis;
183         u16 num_queue_pairs;
184         u16 max_vectors;
185         u16 max_mtu;
186
187         u32 vf_offload_flags;
188         u32 rss_key_size;
189         u32 rss_lut_size;
190
191         struct i40e_virtchnl_vsi_resource vsi_res[1];
192 };
193
194 /* I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE
195  * VF sends this message to set up parameters for one TX queue.
196  * External data buffer contains one instance of i40e_virtchnl_txq_info.
197  * PF configures requested queue and returns a status code.
198  */
199
200 /* Tx queue config info */
201 struct i40e_virtchnl_txq_info {
202         u16 vsi_id;
203         u16 queue_id;
204         u16 ring_len;           /* number of descriptors, multiple of 8 */
205         u16 headwb_enabled;
206         u64 dma_ring_addr;
207         u64 dma_headwb_addr;
208 };
209
210 /* I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE
211  * VF sends this message to set up parameters for one RX queue.
212  * External data buffer contains one instance of i40e_virtchnl_rxq_info.
213  * PF configures requested queue and returns a status code.
214  */
215
216 /* Rx queue config info */
217 struct i40e_virtchnl_rxq_info {
218         u16 vsi_id;
219         u16 queue_id;
220         u32 ring_len;           /* number of descriptors, multiple of 32 */
221         u16 hdr_size;
222         u16 splithdr_enabled;
223         u32 databuffer_size;
224         u32 max_pkt_size;
225         u64 dma_ring_addr;
226         enum i40e_hmc_obj_rx_hsplit_0 rx_split_pos;
227 };
228
229 /* I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
230  * VF sends this message to set parameters for all active TX and RX queues
231  * associated with the specified VSI.
232  * PF configures queues and returns status.
233  * If the number of queues specified is greater than the number of queues
234  * associated with the VSI, an error is returned and no queues are configured.
235  */
236 struct i40e_virtchnl_queue_pair_info {
237         /* NOTE: vsi_id and queue_id should be identical for both queues. */
238         struct i40e_virtchnl_txq_info txq;
239         struct i40e_virtchnl_rxq_info rxq;
240 };
241
242 struct i40e_virtchnl_vsi_queue_config_info {
243         u16 vsi_id;
244         u16 num_queue_pairs;
245         struct i40e_virtchnl_queue_pair_info qpair[1];
246 };
247
248 /* I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
249  * VF uses this message to map vectors to queues.
250  * The rxq_map and txq_map fields are bitmaps used to indicate which queues
251  * are to be associated with the specified vector.
252  * The "other" causes are always mapped to vector 0.
253  * PF configures interrupt mapping and returns status.
254  */
255 struct i40e_virtchnl_vector_map {
256         u16 vsi_id;
257         u16 vector_id;
258         u16 rxq_map;
259         u16 txq_map;
260         u16 rxitr_idx;
261         u16 txitr_idx;
262 };
263
264 struct i40e_virtchnl_irq_map_info {
265         u16 num_vectors;
266         struct i40e_virtchnl_vector_map vecmap[1];
267 };
268
269 /* I40E_VIRTCHNL_OP_ENABLE_QUEUES
270  * I40E_VIRTCHNL_OP_DISABLE_QUEUES
271  * VF sends these message to enable or disable TX/RX queue pairs.
272  * The queues fields are bitmaps indicating which queues to act upon.
273  * (Currently, we only support 16 queues per VF, but we make the field
274  * u32 to allow for expansion.)
275  * PF performs requested action and returns status.
276  */
277 struct i40e_virtchnl_queue_select {
278         u16 vsi_id;
279         u16 pad;
280         u32 rx_queues;
281         u32 tx_queues;
282 };
283
284 /* I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
285  * VF sends this message in order to add one or more unicast or multicast
286  * address filters for the specified VSI.
287  * PF adds the filters and returns status.
288  */
289
290 /* I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
291  * VF sends this message in order to remove one or more unicast or multicast
292  * filters for the specified VSI.
293  * PF removes the filters and returns status.
294  */
295
296 struct i40e_virtchnl_ether_addr {
297         u8 addr[I40E_ETH_LENGTH_OF_ADDRESS];
298         u8 pad[2];
299 };
300
301 struct i40e_virtchnl_ether_addr_list {
302         u16 vsi_id;
303         u16 num_elements;
304         struct i40e_virtchnl_ether_addr list[1];
305 };
306
307 #ifdef I40E_SOL_VF_SUPPORT
308 /* I40E_VIRTCHNL_OP_GET_ADDNL_SOL_CONFIG
309  * VF sends this message to get the default MTU and list of additional ethernet
310  * addresses it is allowed to use.
311  * PF responds with an indirect message containing
312  * i40e_virtchnl_addnl_solaris_config with zero or more
313  * i40e_virtchnl_ether_addr structures.
314  *
315  * It is expected that this operation will only ever be needed for Solaris VFs
316  * running under a Solaris PF.
317  */
318 struct i40e_virtchnl_addnl_solaris_config {
319         u16 default_mtu;
320         struct i40e_virtchnl_ether_addr_list al;
321 };
322
323 #endif
324 /* I40E_VIRTCHNL_OP_ADD_VLAN
325  * VF sends this message to add one or more VLAN tag filters for receives.
326  * PF adds the filters and returns status.
327  * If a port VLAN is configured by the PF, this operation will return an
328  * error to the VF.
329  */
330
331 /* I40E_VIRTCHNL_OP_DEL_VLAN
332  * VF sends this message to remove one or more VLAN tag filters for receives.
333  * PF removes the filters and returns status.
334  * If a port VLAN is configured by the PF, this operation will return an
335  * error to the VF.
336  */
337
338 struct i40e_virtchnl_vlan_filter_list {
339         u16 vsi_id;
340         u16 num_elements;
341         u16 vlan_id[1];
342 };
343
344 /* I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
345  * VF sends VSI id and flags.
346  * PF returns status code in retval.
347  * Note: we assume that broadcast accept mode is always enabled.
348  */
349 struct i40e_virtchnl_promisc_info {
350         u16 vsi_id;
351         u16 flags;
352 };
353
354 #define I40E_FLAG_VF_UNICAST_PROMISC    0x00000001
355 #define I40E_FLAG_VF_MULTICAST_PROMISC  0x00000002
356
357 /* I40E_VIRTCHNL_OP_GET_STATS
358  * VF sends this message to request stats for the selected VSI. VF uses
359  * the i40e_virtchnl_queue_select struct to specify the VSI. The queue_id
360  * field is ignored by the PF.
361  *
362  * PF replies with struct i40e_eth_stats in an external buffer.
363  */
364
365 /* I40E_VIRTCHNL_OP_CONFIG_RSS_KEY
366  * I40E_VIRTCHNL_OP_CONFIG_RSS_LUT
367  * VF sends these messages to configure RSS. Only supported if both PF
368  * and VF drivers set the I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
369  * configuration negotiation. If this is the case, then the rss fields in
370  * the vf resource struct are valid.
371  * Both the key and LUT are initialized to 0 by the PF, meaning that
372  * RSS is effectively disabled until set up by the VF.
373  */
374 struct i40e_virtchnl_rss_key {
375         u16 vsi_id;
376         u16 key_len;
377         u8 key[1];         /* RSS hash key, packed bytes */
378 };
379
380 struct i40e_virtchnl_rss_lut {
381         u16 vsi_id;
382         u16 lut_entries;
383         u8 lut[1];        /* RSS lookup table*/
384 };
385
386 /* I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS
387  * I40E_VIRTCHNL_OP_SET_RSS_HENA
388  * VF sends these messages to get and set the hash filter enable bits for RSS.
389  * By default, the PF sets these to all possible traffic types that the
390  * hardware supports. The VF can query this value if it wants to change the
391  * traffic types that are hashed by the hardware.
392  * Traffic types are defined in the i40e_filter_pctype enum in i40e_type.h
393  */
394 struct i40e_virtchnl_rss_hena {
395         u64 hena;
396 };
397
398 /* I40E_VIRTCHNL_OP_EVENT
399  * PF sends this message to inform the VF driver of events that may affect it.
400  * No direct response is expected from the VF, though it may generate other
401  * messages in response to this one.
402  */
403 enum i40e_virtchnl_event_codes {
404         I40E_VIRTCHNL_EVENT_UNKNOWN = 0,
405         I40E_VIRTCHNL_EVENT_LINK_CHANGE,
406         I40E_VIRTCHNL_EVENT_RESET_IMPENDING,
407         I40E_VIRTCHNL_EVENT_PF_DRIVER_CLOSE,
408 };
409 #define I40E_PF_EVENT_SEVERITY_INFO             0
410 #define I40E_PF_EVENT_SEVERITY_ATTENTION        1
411 #define I40E_PF_EVENT_SEVERITY_ACTION_REQUIRED  2
412 #define I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM     255
413
414 struct i40e_virtchnl_pf_event {
415         enum i40e_virtchnl_event_codes event;
416         union {
417                 struct {
418                         enum i40e_aq_link_speed link_speed;
419                         bool link_status;
420                 } link_event;
421         } event_data;
422
423         int severity;
424 };
425
426 /* VF reset states - these are written into the RSTAT register:
427  * I40E_VFGEN_RSTAT1 on the PF
428  * I40E_VFGEN_RSTAT on the VF
429  * When the PF initiates a reset, it writes 0
430  * When the reset is complete, it writes 1
431  * When the PF detects that the VF has recovered, it writes 2
432  * VF checks this register periodically to determine if a reset has occurred,
433  * then polls it to know when the reset is complete.
434  * If either the PF or VF reads the register while the hardware
435  * is in a reset state, it will return DEADBEEF, which, when masked
436  * will result in 3.
437  */
438 enum i40e_vfr_states {
439         I40E_VFR_INPROGRESS = 0,
440         I40E_VFR_COMPLETED,
441         I40E_VFR_VFACTIVE,
442         I40E_VFR_UNKNOWN,
443 };
444
445 #endif /* _I40E_VIRTCHNL_H_ */