FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
output.c
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 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vlib/pci/pci.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/devices/devices.h>
23 
24 #include <avf/avf.h>
25 
26 #define AVF_TXQ_DESC_CMD(x) (1 << (x + 4))
27 #define AVF_TXQ_DESC_CMD_EOP AVF_TXQ_DESC_CMD(0)
28 #define AVF_TXQ_DESC_CMD_RS AVF_TXQ_DESC_CMD(1)
29 #define AVF_TXQ_DESC_CMD_RSV AVF_TXQ_DESC_CMD(2)
30 
33 {
34  return d->qword[1] & 0x0f;
35 }
36 
37 uword
39  vlib_node_runtime_t * node,
40  vlib_frame_t * frame)
41 {
42  avf_main_t *am = &avf_main;
43  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
45  u32 thread_index = vlib_get_thread_index ();
46  u8 qid = thread_index;
47  avf_txq_t *txq = vec_elt_at_index (ad->txqs, qid % ad->num_queue_pairs);
48  avf_tx_desc_t *d0, *d1, *d2, *d3;
49  u32 *buffers = vlib_frame_args (frame);
50  u32 bi0, bi1, bi2, bi3;
51  u16 n_left = frame->n_vectors;
52  vlib_buffer_t *b0, *b1, *b2, *b3;
53  u16 mask = txq->size - 1;
56 
58 
59  /* release cosumed bufs */
60  if (txq->n_bufs)
61  {
62  u16 first, slot, n_free = 0;
63  first = slot = (txq->next - txq->n_bufs) & mask;
64  d0 = txq->descs + slot;
65  while (n_free < txq->n_bufs && avf_tx_desc_get_dtyp (d0) == 0x0F)
66  {
67  n_free++;
68  slot = (slot + 1) & mask;
69  d0 = txq->descs + slot;
70  }
71 
72  if (n_free)
73  {
74  txq->n_bufs -= n_free;;
75  vlib_buffer_free_from_ring (vm, txq->bufs, first, txq->size,
76  n_free);
77  }
78  }
79 
80  while (n_left >= 7)
81  {
82  u16 slot0, slot1, slot2, slot3;
83 
84  vlib_prefetch_buffer_with_index (vm, buffers[4], LOAD);
85  vlib_prefetch_buffer_with_index (vm, buffers[5], LOAD);
86  vlib_prefetch_buffer_with_index (vm, buffers[6], LOAD);
87  vlib_prefetch_buffer_with_index (vm, buffers[7], LOAD);
88 
89  slot0 = txq->next;
90  slot1 = (txq->next + 1) & mask;
91  slot2 = (txq->next + 2) & mask;
92  slot3 = (txq->next + 3) & mask;
93 
94  d0 = txq->descs + slot0;
95  d1 = txq->descs + slot1;
96  d2 = txq->descs + slot2;
97  d3 = txq->descs + slot3;
98 
99  bi0 = buffers[0];
100  bi1 = buffers[1];
101  bi2 = buffers[2];
102  bi3 = buffers[3];
103 
104  txq->bufs[slot0] = bi0;
105  txq->bufs[slot1] = bi1;
106  txq->bufs[slot2] = bi2;
107  txq->bufs[slot3] = bi3;
108  b0 = vlib_get_buffer (vm, bi0);
109  b1 = vlib_get_buffer (vm, bi1);
110  b2 = vlib_get_buffer (vm, bi2);
111  b3 = vlib_get_buffer (vm, bi3);
112 
113 #if 0
114  d->qword[0] = vlib_get_buffer_data_physical_address (vm, bi0) +
115  b0->current_data;
116 #else
117  d0->qword[0] = pointer_to_uword (b0->data) + b0->current_data;
118  d1->qword[0] = pointer_to_uword (b1->data) + b1->current_data;
119  d2->qword[0] = pointer_to_uword (b2->data) + b2->current_data;
120  d3->qword[0] = pointer_to_uword (b3->data) + b3->current_data;
121 
122 #endif
123  d0->qword[1] = ((u64) b0->current_length) << 34 | bits;
124  d1->qword[1] = ((u64) b1->current_length) << 34 | bits;
125  d2->qword[1] = ((u64) b2->current_length) << 34 | bits;
126  d3->qword[1] = ((u64) b3->current_length) << 34 | bits;
127 
128  txq->next = (txq->next + 4) & mask;
129  txq->n_bufs += 4;
130  buffers += 4;
131  n_left -= 4;
132  }
133 
134  while (n_left)
135  {
136  d0 = txq->descs + txq->next;
137  bi0 = buffers[0];
138  txq->bufs[txq->next] = bi0;
139  b0 = vlib_get_buffer (vm, bi0);
140 
141 #if 0
142  d->qword[0] = vlib_get_buffer_data_physical_address (vm, bi0) +
143  b0->current_data;
144 #else
145  d0->qword[0] = pointer_to_uword (b0->data) + b0->current_data;
146 #endif
147  d0->qword[1] = (((u64) b0->current_length) << 34) | bits;
148 
149  txq->next = (txq->next + 1) & mask;
150  txq->n_bufs++;
151  buffers++;
152  n_left--;
153  }
155  *(txq->qtx_tail) = txq->next;
156 
158 
159  return frame->n_vectors - n_left;
160 }
161 
162 #ifndef CLIB_MARCH_VARIANT
163 #if __x86_64__
166 static void __clib_constructor
168 {
169  if (avf_interface_tx_avx512 && clib_cpu_supports_avx512f ())
171  else if (avf_interface_tx_avx2 && clib_cpu_supports_avx2 ())
173 }
174 #endif
175 #endif
176 
177 /*
178  * fd.io coding-style-patch-verification: ON
179  *
180  * Local Variables:
181  * eval: (c-set-style "gnu")
182  * End:
183  */
#define AVF_TXQ_DESC_CMD_RS
Definition: output.c:28
unsigned long u64
Definition: types.h:89
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:98
avf_device_t * devices
Definition: avf.h:161
static u64 vlib_get_buffer_data_physical_address(vlib_main_t *vm, u32 buffer_index)
Definition: buffer_funcs.h:306
volatile u32 * qtx_tail
Definition: avf.h:70
unsigned char u8
Definition: types.h:56
vnet_device_class_t avf_device_class
vlib_node_function_t __clib_weak avf_interface_tx_avx512
Definition: output.c:164
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:104
#define static_always_inline
Definition: clib.h:93
#define vlib_prefetch_buffer_with_index(vm, bi, type)
Prefetch buffer metadata by buffer index The first 64 bytes of buffer contains most header informatio...
Definition: buffer_funcs.h:324
clib_spinlock_t lock
Definition: avf.h:73
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
unsigned int u32
Definition: types.h:88
static void vlib_buffer_free_from_ring(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Free buffers from ring.
Definition: buffer_funcs.h:589
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:108
static void __clib_constructor avf_interface_tx_multiarch_select(void)
Definition: output.c:167
unsigned short u16
Definition: types.h:57
uword( vlib_node_function_t)(struct vlib_main_t *vm, struct vlib_node_runtime_t *node, struct vlib_frame_t *frame)
Definition: node.h:54
#define AVF_TXQ_DESC_CMD_RSV
Definition: output.c:29
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:221
vlib_main_t * vm
Definition: buffer.c:294
avf_tx_desc_t * descs
Definition: avf.h:74
static_always_inline u8 avf_tx_desc_get_dtyp(avf_tx_desc_t *d)
Definition: output.c:32
u32 * bufs
Definition: avf.h:75
Definition: avf.h:67
#define AVF_TXQ_DESC_CMD_EOP
Definition: output.c:27
static void * vlib_frame_args(vlib_frame_t *f)
Get pointer to frame scalar data.
Definition: node_funcs.h:284
static uword pointer_to_uword(const void *p)
Definition: types.h:131
avf_main_t avf_main
Definition: device.c:36
vlib_node_function_t __clib_weak avf_interface_tx_avx2
Definition: output.c:165
u16 next
Definition: avf.h:71
u64 uword
Definition: types.h:112
u64 qword[2]
Definition: avf.h:49
uword CLIB_MULTIARCH_FN() avf_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: output.c:38
u16 size
Definition: avf.h:72
u8 data[0]
Packet data.
Definition: buffer.h:172
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:109
u16 n_bufs
Definition: avf.h:76
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:82
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
#define CLIB_MULTIARCH_FN(fn)
Definition: cpu.h:59