iavf: add missing cfg_change_validate callback
[vpp.git] / src / plugins / dev_iavf / iavf.h
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright (c) 2023 Cisco Systems, Inc.
3  */
4
5 #ifndef _IIAVF_H_
6 #define _IIAVF_H_
7
8 #include <vppinfra/clib.h>
9 #include <vppinfra/error_bootstrap.h>
10 #include <vppinfra/format.h>
11 #include <vnet/vnet.h>
12 #include <vnet/dev/dev.h>
13 #include <dev_iavf/iavf_desc.h>
14 #include <dev_iavf/virtchnl.h>
15
16 #define IAVF_ITR_INT              250
17 #define IAVF_RX_MAX_DESC_IN_CHAIN 5
18 #define IAVF_MAX_RSS_KEY_SIZE     52
19 #define IAVF_MAX_RSS_LUT_SIZE     64
20 #define IIAVF_AQ_POLL_INTERVAL    0.2
21 #define IIAVF_AQ_BUF_SIZE         4096
22
23 typedef struct iavf_adminq_dma_mem iavf_adminq_dma_mem_t;
24
25 typedef struct
26 {
27   u8 adminq_active : 1;
28   void *bar0;
29
30   /* Admin queues */
31   iavf_adminq_dma_mem_t *aq_mem;
32   u16 atq_next_slot;
33   u16 arq_next_slot;
34   virtchnl_pf_event_t *events;
35 } iavf_device_t;
36
37 typedef struct
38 {
39   u32 flow_id;
40   u16 next_index;
41   i16 buffer_advance;
42 } iavf_flow_lookup_entry_t;
43
44 typedef struct
45 {
46   u8 admin_up : 1;
47   u8 flow_offload : 1;
48   iavf_flow_lookup_entry_t *flow_lookup_entries;
49   u64 intr_mode_per_rxq_bitmap;
50   u32 vf_cap_flags;
51   u16 vsi_id;
52   u16 rss_key_size;
53   u16 rss_lut_size;
54   u16 num_qp;
55   u16 max_vectors;
56   u16 n_rx_vectors;
57 } iavf_port_t;
58
59 typedef struct
60 {
61   u32 *qtx_tail;
62   u32 *buffer_indices;
63   iavf_tx_desc_t *descs;
64   u16 next;
65   u16 n_enqueued;
66   u16 *rs_slots;
67   iavf_tx_desc_t *tmp_descs;
68   u32 *tmp_bufs;
69   u32 *ph_bufs;
70 } iavf_txq_t;
71
72 typedef struct
73 {
74   u32 *qrx_tail;
75   u32 *buffer_indices;
76   iavf_rx_desc_t *descs;
77   u16 next;
78   u16 n_enqueued;
79 } iavf_rxq_t;
80
81 typedef struct
82 {
83   u16 qid;
84   u16 next_index;
85   u32 hw_if_index;
86   u32 flow_id;
87   u64 qw1s[IAVF_RX_MAX_DESC_IN_CHAIN];
88 } iavf_rx_trace_t;
89
90 /* adminq.c */
91 vnet_dev_rv_t iavf_aq_alloc (vlib_main_t *, vnet_dev_t *);
92 void iavf_aq_init (vlib_main_t *, vnet_dev_t *);
93 void iavf_aq_poll_on (vlib_main_t *, vnet_dev_t *);
94 void iavf_aq_poll_off (vlib_main_t *, vnet_dev_t *);
95 void iavf_aq_deinit (vlib_main_t *, vnet_dev_t *);
96 void iavf_aq_free (vlib_main_t *, vnet_dev_t *);
97 vnet_dev_rv_t iavf_aq_atq_enq (vlib_main_t *, vnet_dev_t *, iavf_aq_desc_t *,
98                                const u8 *, u16, f64);
99 int iavf_aq_arq_next_acq (vlib_main_t *, vnet_dev_t *, iavf_aq_desc_t **,
100                           u8 **, f64);
101 void iavf_aq_arq_next_rel (vlib_main_t *, vnet_dev_t *);
102 format_function_t format_virtchnl_op_name;
103 format_function_t format_virtchnl_status;
104
105 /* format.c */
106 format_function_t format_iavf_vf_cap_flags;
107 format_function_t format_iavf_rx_trace;
108 format_function_t format_iavf_port_status;
109
110 /* port.c */
111 vnet_dev_rv_t iavf_port_init (vlib_main_t *, vnet_dev_port_t *);
112 vnet_dev_rv_t iavf_port_start (vlib_main_t *, vnet_dev_port_t *);
113 void iavf_port_stop (vlib_main_t *, vnet_dev_port_t *);
114 vnet_dev_rv_t iavf_port_cfg_change (vlib_main_t *, vnet_dev_port_t *,
115                                     vnet_dev_port_cfg_change_req_t *);
116 vnet_dev_rv_t iavf_port_cfg_change_validate (vlib_main_t *, vnet_dev_port_t *,
117                                              vnet_dev_port_cfg_change_req_t *);
118
119 /* queue.c */
120 vnet_dev_rv_t iavf_rx_queue_alloc (vlib_main_t *, vnet_dev_rx_queue_t *);
121 vnet_dev_rv_t iavf_tx_queue_alloc (vlib_main_t *, vnet_dev_tx_queue_t *);
122 vnet_dev_rv_t iavf_rx_queue_start (vlib_main_t *, vnet_dev_rx_queue_t *);
123 vnet_dev_rv_t iavf_tx_queue_start (vlib_main_t *, vnet_dev_tx_queue_t *);
124 void iavf_rx_queue_stop (vlib_main_t *, vnet_dev_rx_queue_t *);
125 void iavf_tx_queue_stop (vlib_main_t *, vnet_dev_tx_queue_t *);
126 void iavf_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *);
127 void iavf_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *);
128
129 /* counter.c */
130 void iavf_port_poll_stats (vlib_main_t *, vnet_dev_port_t *);
131 void iavf_port_add_counters (vlib_main_t *, vnet_dev_port_t *);
132
133 /* inline funcs */
134
135 static inline u32
136 iavf_get_u32 (void *start, int offset)
137 {
138   return *(u32 *) (((u8 *) start) + offset);
139 }
140
141 static inline void
142 iavf_reg_write (iavf_device_t *ad, u32 addr, u32 val)
143 {
144   __atomic_store_n ((u32 *) ((u8 *) ad->bar0 + addr), val, __ATOMIC_RELEASE);
145 }
146
147 static inline u32
148 iavf_reg_read (iavf_device_t *ad, u32 addr)
149 {
150   return __atomic_load_n ((u32 *) (ad->bar0 + addr), __ATOMIC_RELAXED);
151   ;
152 }
153
154 static inline void
155 iavf_reg_flush (iavf_device_t *ad)
156 {
157   iavf_reg_read (ad, IAVF_VFGEN_RSTAT);
158   asm volatile("" ::: "memory");
159 }
160
161 #define log_debug(dev, f, ...)                                                \
162   vlib_log (VLIB_LOG_LEVEL_DEBUG, iavf_log.class, "%U" f,                     \
163             format_vnet_dev_log, (dev),                                       \
164             clib_string_skip_prefix (__func__, "iavf_"), ##__VA_ARGS__)
165 #define log_info(dev, f, ...)                                                 \
166   vlib_log (VLIB_LOG_LEVEL_INFO, iavf_log.class, "%U: " f,                    \
167             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
168 #define log_notice(dev, f, ...)                                               \
169   vlib_log (VLIB_LOG_LEVEL_NOTICE, iavf_log.class, "%U: " f,                  \
170             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
171 #define log_warn(dev, f, ...)                                                 \
172   vlib_log (VLIB_LOG_LEVEL_WARNING, iavf_log.class, "%U: " f,                 \
173             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
174 #define log_err(dev, f, ...)                                                  \
175   vlib_log (VLIB_LOG_LEVEL_ERR, iavf_log.class, "%U: " f,                     \
176             format_vnet_dev_addr, (dev), ##__VA_ARGS__)
177
178 /* temp */
179 #define IAVF_RX_VECTOR_SZ VLIB_FRAME_SIZE
180
181 typedef struct
182 {
183   u64 qw1s[IAVF_RX_MAX_DESC_IN_CHAIN - 1];
184   u32 buffers[IAVF_RX_MAX_DESC_IN_CHAIN - 1];
185 } iavf_rx_tail_t;
186
187 typedef struct
188 {
189   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
190   vlib_buffer_t *bufs[IAVF_RX_VECTOR_SZ];
191   u16 next[IAVF_RX_VECTOR_SZ];
192   u64 qw1s[IAVF_RX_VECTOR_SZ];
193   u32 flow_ids[IAVF_RX_VECTOR_SZ];
194   iavf_rx_tail_t tails[IAVF_RX_VECTOR_SZ];
195 } iavf_rt_data_t;
196
197 #define foreach_iavf_tx_node_counter                                          \
198   _ (SEG_SZ_EXCEEDED, seg_sz_exceeded, ERROR, "segment size exceeded")        \
199   _ (NO_FREE_SLOTS, no_free_slots, ERROR, "no free tx slots")
200
201 typedef enum
202 {
203 #define _(f, n, s, d) IAVF_TX_NODE_CTR_##f,
204   foreach_iavf_tx_node_counter
205 #undef _
206 } iavf_tx_node_counter_t;
207
208 #define foreach_iavf_rx_node_counter                                          \
209   _ (BUFFER_ALLOC, buffer_alloc, ERROR, "buffer alloc error")
210
211 typedef enum
212 {
213 #define _(f, n, s, d) IAVF_RX_NODE_CTR_##f,
214   foreach_iavf_rx_node_counter
215 #undef _
216 } iavf_rx_node_counter_t;
217
218 #endif /* _IIAVF_H_ */