FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
avf.h
Go to the documentation of this file.
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 AVF_AQ_ENQ_SUSPEND_TIME 50e-6
26 #define AVF_AQ_ENQ_MAX_WAIT_TIME 50e-3
27 
28 #define AVF_RXD_STATUS(x) (1ULL << x)
29 #define AVF_RXD_STATUS_DD AVF_RXD_STATUS(0)
30 #define AVF_RXD_STATUS_EOP AVF_RXD_STATUS(1)
31 #define AVF_RXD_ERROR_SHIFT 19
32 #define AVF_RXD_PTYPE_SHIFT 30
33 #define AVF_RXD_LEN_SHIFT 38
34 #define AVF_RX_MAX_DESC_IN_CHAIN 5
35 
36 #define AVF_RXD_ERROR_IPE (1ULL << (AVF_RXD_ERROR_SHIFT + 3))
37 #define AVF_RXD_ERROR_L4E (1ULL << (AVF_RXD_ERROR_SHIFT + 4))
38 
39 #define AVF_TXD_CMD(x) (1 << (x + 4))
40 #define AVF_TXD_CMD_EOP AVF_TXD_CMD(0)
41 #define AVF_TXD_CMD_RS AVF_TXD_CMD(1)
42 #define AVF_TXD_CMD_RSV AVF_TXD_CMD(2)
43 
44 #define foreach_avf_device_flags \
45  _(0, INITIALIZED, "initialized") \
46  _(1, ERROR, "error") \
47  _(2, ADMIN_UP, "admin-up") \
48  _(3, VA_DMA, "vaddr-dma") \
49  _(4, LINK_UP, "link-up") \
50  _(5, SHARED_TXQ_LOCK, "shared-txq-lock") \
51  _(6, ELOG, "elog")
52 
53 enum
54 {
55 #define _(a, b, c) AVF_DEVICE_F_##b = (1 << a),
57 #undef _
58 };
59 
60 typedef volatile struct
61 {
62  union
63  {
64  struct
65  {
66  u64 mirr:13;
67  u64 rsv1:3;
68  u64 l2tag1:16;
70  u64 status:19;
72  u64 rsv2:3;
74  u64 length:26;
75  };
76  u64 qword[4];
77 #ifdef CLIB_HAVE_VEC256
78  u64x4 as_u64x4;
79 #endif
80  };
82 
84 
85 typedef volatile struct
86 {
87  union
88  {
89  u64 qword[2];
90 #ifdef CLIB_HAVE_VEC128
91  u64x2 as_u64x2;
92 #endif
93  };
95 
97 
98 typedef struct
99 {
100  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
101  volatile u32 *qrx_tail;
109 } avf_rxq_t;
110 
111 typedef struct
112 {
113  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
114  volatile u32 *qtx_tail;
122 } avf_txq_t;
123 
124 typedef struct
125 {
126  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
129 
135  void *bar0;
137 
138  /* queues */
143 
144  /* Admin queues */
147  void *atq_bufs;
148  void *arq_bufs;
154 
157  u8 hwaddr[6];
164 
165  /* stats */
168 
169  /* error */
171 } avf_device_t;
172 
173 #define AVF_RX_VECTOR_SZ VLIB_FRAME_SIZE
174 
175 typedef enum
176 {
181 
182 typedef struct
183 {
186 } avf_rx_tail_t;
187 
188 typedef struct
189 {
190  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
196 
197 typedef struct
198 {
200 
203 
205 } avf_main_t;
206 
207 extern avf_main_t avf_main;
208 
209 typedef struct
210 {
211  vlib_pci_addr_t addr;
217  /* return */
218  int rv;
222 
225 
228 
229 /* format.c */
233 
234 static inline u32
235 avf_get_u32 (void *start, int offset)
236 {
237  return *(u32 *) (((u8 *) start) + offset);
238 }
239 
240 static inline u64
241 avf_get_u64 (void *start, int offset)
242 {
243  return *(u64 *) (((u8 *) start) + offset);
244 }
245 
246 static inline u32
247 avf_get_u32_bits (void *start, int offset, int first, int last)
248 {
249  u32 value = avf_get_u32 (start, offset);
250  if ((last == 0) && (first == 31))
251  return value;
252  value >>= last;
253  value &= (1 << (first - last + 1)) - 1;
254  return value;
255 }
256 
257 static inline u64
258 avf_get_u64_bits (void *start, int offset, int first, int last)
259 {
260  u64 value = avf_get_u64 (start, offset);
261  if ((last == 0) && (first == 63))
262  return value;
263  value >>= last;
264  value &= (1 << (first - last + 1)) - 1;
265  return value;
266 }
267 
268 static inline void
269 avf_set_u32 (void *start, int offset, u32 value)
270 {
271  (*(u32 *) (((u8 *) start) + offset)) = value;
272 }
273 
274 static inline void
276 {
277  *(volatile u32 *) ((u8 *) ad->bar0 + addr) = val;
278 }
279 
280 static inline u32
282 {
283  return *(volatile u32 *) (ad->bar0 + addr);
284 }
285 
286 static inline void
288 {
290  asm volatile ("":::"memory");
291 }
292 
295 {
296  return (d->qword[1] & AVF_RXD_STATUS_EOP) == 0;
297 }
298 
301 {
302  return (d->qword[1] & AVF_RXD_STATUS_DD) == 0;
303 }
304 
305 typedef struct
306 {
311 
312 #define foreach_avf_tx_func_error \
313 _(NO_FREE_SLOTS, "no free tx slots")
314 
315 typedef enum
316 {
317 #define _(f,s) AVF_TX_ERROR_##f,
319 #undef _
322 
323 #endif /* AVF_H */
324 
325 /*
326  * fd.io coding-style-patch-verification: ON
327  *
328  * Local Variables:
329  * eval: (c-set-style "gnu")
330  * End:
331  */
u8 int_mode
Definition: avf.h:107
u32 hw_if_index
Definition: avf.h:132
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
static u64 avf_get_u64_bits(void *start, int offset, int first, int last)
Definition: avf.h:258
clib_error_t * error
Definition: avf.h:170
u64 mirr
Definition: avf.h:66
u64 atq_bufs_pa
Definition: avf.h:149
unsigned long u64
Definition: types.h:89
virtchnl_link_speed_t link_speed
Definition: avf.h:163
static u64 avf_get_u64(void *start, int offset)
Definition: avf.h:241
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
format_function_t format_avf_device
Definition: avf.h:230
vlib_pci_addr_t addr
Definition: avf.h:211
u32 dev_instance
Definition: avf.h:130
virtchnl_link_speed_t
Definition: virtchnl.h:198
u32 next_index
Definition: avf.h:307
#define AVF_RXD_STATUS_DD
Definition: avf.h:29
avf_device_t * devices
Definition: avf.h:201
struct _vnet_device_class vnet_device_class_t
format_function_t format_avf_input_trace
Definition: avf.h:232
vhost_vring_addr_t addr
Definition: vhost_user.h:121
volatile u32 * qtx_tail
Definition: avf.h:114
#define foreach_avf_device_flags
Definition: avf.h:44
unsigned char u8
Definition: types.h:56
vnet_device_class_t avf_device_class
u8 buffer_pool_index
Definition: avf.h:108
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
u32 vlib_log_class_t
Definition: vlib.h:50
u16 * rs_slots
Definition: avf.h:121
#define static_always_inline
Definition: clib.h:99
clib_spinlock_t lock
Definition: avf.h:117
static u32 avf_reg_read(avf_device_t *ad, u32 addr)
Definition: avf.h:281
static u32 avf_get_u32_bits(void *start, int offset, int first, int last)
Definition: avf.h:247
volatile u32 * qrx_tail
Definition: avf.h:101
unsigned int u32
Definition: types.h:88
vlib_pci_dev_handle_t pci_dev_handle
Definition: avf.h:133
void * arq_bufs
Definition: avf.h:148
avf_aq_desc_t * arq
Definition: avf.h:146
epu8_epi32 epu16_epi32 u64x2
Definition: vector_sse42.h:665
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1197
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
u32 hw_if_index
Definition: avf.h:308
u8 * name
Definition: avf.h:136
virtchnl_eth_stats_t last_cleared_eth_stats
Definition: avf.h:167
static u32 avf_get_u32(void *start, int offset)
Definition: avf.h:235
unsigned short u16
Definition: types.h:57
u64 qword[4]
Definition: avf.h:76
#define AVF_RX_VECTOR_SZ
Definition: avf.h:173
static void avf_reg_flush(avf_device_t *ad)
Definition: avf.h:287
u32 vlib_pci_dev_handle_t
Definition: pci.h:97
#define AVF_RXD_STATUS_EOP
Definition: avf.h:30
u16 n_rx_queues
Definition: avf.h:142
u16 atq_next_slot
Definition: avf.h:151
u32 numa_node
Definition: avf.h:134
vlib_main_t * vm
Definition: buffer.c:312
vlib_node_registration_t avf_input_node
(constructor) VLIB_REGISTER_NODE (avf_input_node)
Definition: input.c:462
static_always_inline int avf_rxd_is_not_dd(avf_rx_desc_t *d)
Definition: avf.h:300
u64 length
Definition: avf.h:74
avf_tx_func_error_t
Definition: avf.h:315
Definition: avf.h:98
u64 l2tag1
Definition: avf.h:68
vlib_log_class_t log_class
Definition: avf.h:204
avf_tx_desc_t * descs
Definition: avf.h:118
u64 status
Definition: avf.h:70
u64 rsv1
Definition: avf.h:67
u64 filter_status
Definition: avf.h:69
u16 vsi_id
Definition: avf.h:155
u32 per_interface_next_index
Definition: avf.h:128
u32 feature_bitmap
Definition: avf.h:156
u32 * bufs
Definition: avf.h:119
avf_aq_desc_t * atq
Definition: avf.h:145
u32 flags
Definition: avf.h:127
Definition: avf.h:111
static void avf_set_u32(void *start, int offset, u32 value)
Definition: avf.h:269
u32 * bufs
Definition: avf.h:105
void * bar0
Definition: avf.h:135
vlib_buffer_t buffer_template
Definition: avf.h:194
u16 n_enqueued
Definition: avf.h:120
u16 n_enqueued
Definition: avf.h:106
virtchnl_pf_event_t * events
Definition: avf.h:153
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
Definition: avf.h:275
avf_main_t avf_main
Definition: device.c:37
virtchnl_eth_stats_t eth_stats
Definition: avf.h:166
void * atq_bufs
Definition: avf.h:147
#define AVFGEN_RSTAT
Definition: virtchnl.h:49
u16 msg_id_base
Definition: avf.h:199
u16 num_queue_pairs
Definition: avf.h:158
u16 next
Definition: avf.h:115
struct _vlib_node_registration vlib_node_registration_t
template key/value backing page structure
Definition: bihash_doc.h:44
avf_process_event_t
Definition: avf.h:175
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:1140
u32 rss_lut_size
Definition: avf.h:162
u16 n_tx_queues
Definition: avf.h:141
format_function_t format_avf_device_name
Definition: avf.h:231
VLIB buffer representation.
Definition: buffer.h:102
#define foreach_avf_tx_func_error
Definition: avf.h:312
u16 size
Definition: avf.h:103
u16 arq_next_slot
Definition: avf.h:152
avf_rxq_t * rxqs
Definition: avf.h:139
u64 error
Definition: avf.h:71
struct clib_bihash_value offset
template key/value backing page structure
u64x4
Definition: vector_avx2.h:121
clib_error_t * error
Definition: avf.h:220
avf_per_thread_data_t * per_thread_data
Definition: avf.h:202
u16 size
Definition: avf.h:116
u32 sw_if_index
Definition: avf.h:131
u64 rsv2
Definition: avf.h:72
u64 arq_bufs_pa
Definition: avf.h:150
u64 ptype
Definition: avf.h:73
static_always_inline int avf_rxd_is_not_eop(avf_rx_desc_t *d)
Definition: avf.h:294
STATIC_ASSERT_SIZEOF(avf_rx_desc_t, 32)
#define AVF_RX_MAX_DESC_IN_CHAIN
Definition: avf.h:34
u16 next
Definition: avf.h:102
avf_txq_t * txqs
Definition: avf.h:140
avf_rx_desc_t * descs
Definition: avf.h:104
u16 max_vectors
Definition: avf.h:159
u32 rss_key_size
Definition: avf.h:161
u16 max_mtu
Definition: avf.h:160