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