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