avf: api fix
[vpp.git] / src / plugins / avf / avf.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef _AVF_H_
19 #define _AVF_H_
20
21 #include <avf/virtchnl.h>
22
23 #include <vlib/log.h>
24
25 #define foreach_avf_device_flags \
26   _(0, INITIALIZED, "initialized") \
27   _(1, ERROR, "error") \
28   _(2, ADMIN_UP, "admin-up") \
29   _(3, IOVA, "iova") \
30   _(4, LINK_UP, "link-up") \
31   _(5, SHARED_TXQ_LOCK, "shared-txq-lock") \
32   _(6, ELOG, "elog")
33
34 enum
35 {
36 #define _(a, b, c) AVF_DEVICE_F_##b = (1 << a),
37   foreach_avf_device_flags
38 #undef _
39 };
40
41 typedef volatile struct
42 {
43   union
44   {
45     struct
46     {
47       u64 mirr:13;
48       u64 rsv1:3;
49       u64 l2tag1:16;
50       u64 filter_status:32;
51       u64 status:19;
52       u64 error:8;
53       u64 rsv2:3;
54       u64 ptype:8;
55       u64 length:26;
56     };
57     u64 qword[4];
58 #ifdef CLIB_HAVE_VEC256
59     u64x4 as_u64x4;
60 #endif
61   };
62 } avf_rx_desc_t;
63
64 STATIC_ASSERT_SIZEOF (avf_rx_desc_t, 32);
65
66 typedef volatile struct
67 {
68   union
69   {
70     u64 qword[2];
71 #ifdef CLIB_HAVE_VEC128
72     u64x2 as_u64x2;
73 #endif
74   };
75 } avf_tx_desc_t;
76
77 STATIC_ASSERT_SIZEOF (avf_tx_desc_t, 16);
78
79 typedef struct
80 {
81   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
82   volatile u32 *qrx_tail;
83   u16 next;
84   u16 size;
85   avf_rx_desc_t *descs;
86   u32 *bufs;
87   u16 n_enqueued;
88 } avf_rxq_t;
89
90 typedef struct
91 {
92   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
93   volatile u32 *qtx_tail;
94   u16 next;
95   u16 size;
96   clib_spinlock_t lock;
97   avf_tx_desc_t *descs;
98   u32 *bufs;
99   u16 n_enqueued;
100 } avf_txq_t;
101
102 typedef struct
103 {
104   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
105   u32 flags;
106   u32 per_interface_next_index;
107
108   u32 dev_instance;
109   u32 sw_if_index;
110   u32 hw_if_index;
111   vlib_pci_dev_handle_t pci_dev_handle;
112   void *bar0;
113
114   /* queues */
115   avf_rxq_t *rxqs;
116   avf_txq_t *txqs;
117
118   /* Admin queues */
119   avf_aq_desc_t *atq;
120   avf_aq_desc_t *arq;
121   void *atq_bufs;
122   void *arq_bufs;
123   u64 atq_bufs_pa;
124   u64 arq_bufs_pa;
125   u16 atq_next_slot;
126   u16 arq_next_slot;
127   virtchnl_pf_event_t *events;
128
129   u16 vsi_id;
130   u32 feature_bitmap;
131   u8 hwaddr[6];
132   u16 num_queue_pairs;
133   u16 max_vectors;
134   u16 max_mtu;
135   u32 rss_key_size;
136   u32 rss_lut_size;
137   virtchnl_link_speed_t link_speed;
138
139   /* stats */
140   virtchnl_eth_stats_t eth_stats;
141
142   /* error */
143   clib_error_t *error;
144 } avf_device_t;
145
146 typedef struct
147 {
148   u32 status;
149   u16 length;
150   u8 ptype;
151   u8 error;
152 } avf_rx_vector_entry_t;
153
154 STATIC_ASSERT_SIZEOF (avf_rx_vector_entry_t, 8);
155
156 #define AVF_RX_VECTOR_SZ VLIB_FRAME_SIZE
157
158 enum
159 {
160   AVF_PROCESS_EVENT_START = 1,
161   AVF_PROCESS_EVENT_STOP = 2,
162   AVF_PROCESS_EVENT_AQ_INT = 3,
163 } avf_process_event_t;
164
165 typedef struct
166 {
167   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
168   avf_rx_vector_entry_t rx_vector[AVF_RX_VECTOR_SZ];
169   u32 *to_free;
170   vlib_buffer_t buffer_template;
171 } avf_per_thread_data_t;
172
173 typedef struct
174 {
175   u8 next_node;
176   i8 buffer_advance;
177   u32 flags;
178 } avf_ptype_t;
179
180 STATIC_ASSERT (VNET_DEVICE_INPUT_N_NEXT_NODES < 256, "too many next nodes");
181
182 typedef struct
183 {
184   u16 msg_id_base;
185
186   avf_device_t *devices;
187   avf_per_thread_data_t *per_thread_data;
188   vlib_physmem_region_index_t physmem_region;
189   int physmem_region_alloc;
190
191   vlib_log_class_t log_class;
192
193   /* 256 element array for ptype based lookup */
194   avf_ptype_t *ptypes;
195 } avf_main_t;
196
197 extern avf_main_t avf_main;
198
199 typedef struct
200 {
201   vlib_pci_addr_t addr;
202   int enable_elog;
203   u16 rxq_size;
204   u16 txq_size;
205   /* return */
206   int rv;
207   u32 sw_if_index;
208   clib_error_t *error;
209 } avf_create_if_args_t;
210
211 void avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args);
212 void avf_delete_if (vlib_main_t * vm, avf_device_t * ad);
213
214 extern vlib_node_registration_t avf_input_node;
215 extern vnet_device_class_t avf_device_class;
216 uword avf_interface_tx (vlib_main_t * vm, vlib_node_runtime_t * node,
217                         vlib_frame_t * frame);
218
219 /* format.c */
220 format_function_t format_avf_device;
221 format_function_t format_avf_device_name;
222 format_function_t format_avf_input_trace;
223
224 static inline u32
225 avf_get_u32 (void *start, int offset)
226 {
227   return *(u32 *) (((u8 *) start) + offset);
228 }
229
230 static inline u64
231 avf_get_u64 (void *start, int offset)
232 {
233   return *(u64 *) (((u8 *) start) + offset);
234 }
235
236 static inline u32
237 avf_get_u32_bits (void *start, int offset, int first, int last)
238 {
239   u32 value = avf_get_u32 (start, offset);
240   if ((last == 0) && (first == 31))
241     return value;
242   value >>= last;
243   value &= (1 << (first - last + 1)) - 1;
244   return value;
245 }
246
247 static inline u64
248 avf_get_u64_bits (void *start, int offset, int first, int last)
249 {
250   u64 value = avf_get_u64 (start, offset);
251   if ((last == 0) && (first == 63))
252     return value;
253   value >>= last;
254   value &= (1 << (first - last + 1)) - 1;
255   return value;
256 }
257
258 static inline void
259 avf_set_u32 (void *start, int offset, u32 value)
260 {
261   (*(u32 *) (((u8 *) start) + offset)) = value;
262 }
263
264 static inline void
265 avf_reg_write (avf_device_t * ad, u32 addr, u32 val)
266 {
267   *(volatile u32 *) ((u8 *) ad->bar0 + addr) = val;
268 }
269
270 static inline u32
271 avf_reg_read (avf_device_t * ad, u32 addr)
272 {
273   return *(volatile u32 *) (ad->bar0 + addr);
274 }
275
276 static inline void
277 avf_reg_flush (avf_device_t * ad)
278 {
279   avf_reg_read (ad, AVFGEN_RSTAT);
280   asm volatile ("":::"memory");
281 }
282
283 typedef struct
284 {
285   u32 next_index;
286   u32 hw_if_index;
287   avf_rx_vector_entry_t rxve;
288 } avf_input_trace_t;
289
290 #endif /* AVF_H */
291
292 /*
293  * fd.io coding-style-patch-verification: ON
294  *
295  * Local Variables:
296  * eval: (c-set-style "gnu")
297  * End:
298  */