FD.io VPP  v21.06-3-gbb25fbf28
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 <stdint.h>
19 #include <net/if.h>
20 #include <sys/ioctl.h>
21 #include <sys/uio.h>
22 
23 #include <vlib/vlib.h>
24 #include <vlib/unix/unix.h>
25 #include <vnet/ethernet/ethernet.h>
26 #include <vnet/devices/devices.h>
27 
28 #include <marvell/pp2/pp2.h>
29 
30 uword
33 {
35  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
40  u8 qid = thread_index;
41  mrvl_pp2_outq_t *outq = vec_elt_at_index (ppif->outqs, qid);
42  u32 *buffers = vlib_frame_vector_args (frame);
43  u16 n_desc = frame->n_vectors, n_left = n_desc, n_sent = n_desc, n_done;
44  struct pp2_ppio_desc *d;
45  u16 mask = outq->size - 1;
46 
47  if (PREDICT_FALSE (pp2_ppio_get_num_outq_done (ppif->ppio, ptd->hif, qid,
48  &n_done)))
49  {
50  n_done = 0;
51  vlib_error_count (vm, node->node_index,
52  MRVL_PP2_TX_ERROR_PPIO_GET_NUM_OUTQ_DONE, 1);
53  }
54 
55  if (n_done)
56  {
57  u16 n_free = clib_min (n_done, outq->size - (outq->tail & mask));
58  vlib_buffer_free (vm, outq->buffers + (outq->tail & mask), n_free);
59  if (PREDICT_FALSE (n_free < n_done))
60  vlib_buffer_free (vm, outq->buffers, n_done - n_free);
61  outq->tail += n_done;
62  }
63 
65  d = ptd->descs;
66  while (n_left)
67  {
68  u32 bi0 = buffers[0];
69  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
70  u64 paddr = vlib_buffer_get_pa (vm, b0);
71 
72  pp2_ppio_outq_desc_reset (d);
73  pp2_ppio_outq_desc_set_phys_addr (d, paddr + b0->current_data);
74  pp2_ppio_outq_desc_set_pkt_offset (d, 0);
75  pp2_ppio_outq_desc_set_pkt_len (d, b0->current_length);
76  d++;
77  buffers++;
78  n_left--;
79  }
80 
81  if (pp2_ppio_send (ppif->ppio, ptd->hif, qid, ptd->descs, &n_sent))
82  {
83  n_sent = 0;
84  vlib_error_count (vm, node->node_index, MRVL_PP2_TX_ERROR_PPIO_SEND, 1);
85  }
86 
87  /* free unsent buffers */
88  if (PREDICT_FALSE (n_sent != n_desc))
89  {
91  frame->n_vectors - n_sent);
92  vlib_error_count (vm, node->node_index, MRVL_PP2_TX_ERROR_NO_FREE_SLOTS,
93  frame->n_vectors - n_sent);
94  }
95 
96  /* store buffer index for each enqueued packet into the ring
97  so we can know what to free after packet is sent */
98  if (n_sent)
99  {
100  u16 slot = outq->head & mask;
101  buffers = vlib_frame_vector_args (frame);
102  u16 n_copy = clib_min (outq->size - slot, n_sent);
103 
104  vlib_buffer_copy_indices (outq->buffers + slot, buffers, n_copy);
105  if (PREDICT_FALSE (n_copy < n_sent))
106  clib_memcpy_fast (outq->buffers, buffers + n_copy,
107  (n_sent - n_copy) * sizeof (u32));
108 
109  outq->head += n_sent;
110  }
111 
112  return n_sent;
113 }
114 
115 /*
116  * fd.io coding-style-patch-verification: ON
117  *
118  * Local Variables:
119  * eval: (c-set-style "gnu")
120  * End:
121  */
vlib.h
mrvl_pp2_outq_t::tail
u16 tail
Definition: pp2.h:48
vlib_buffer_free
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:982
mrvl_pp2_outq_t
Definition: pp2.h:42
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
vlib_buffer_copy_indices
vlib_buffer_copy_indices(to, tmp, n_free)
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
pp2.h
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
mrvl_pp2_main
mrvl_pp2_main_t mrvl_pp2_main
Definition: pp2.c:37
vlib_buffer_get_pa
static uword vlib_buffer_get_pa(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:488
vlib_error_count
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
vlib_frame_t
Definition: node.h:372
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
ethernet.h
vlib_buffer_t::current_data
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:119
slot
u8 slot
Definition: pci_types.api:22
vnet_interface_output_runtime_t::dev_instance
u32 dev_instance
Definition: interface_funcs.h:476
mrvl_pp2_per_thread_data_t
Definition: pp2.h:69
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
mrvl_pp2_per_thread_data_t::hif
struct pp2_hif * hif
Definition: pp2.h:72
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
vec_validate_aligned
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:534
mrvl_pp2_interface_tx
uword mrvl_pp2_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: output.c:31
uword
u64 uword
Definition: types.h:112
mrvl_pp2_per_thread_data_t::descs
struct pp2_ppio_desc * descs
Definition: pp2.h:73
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:213
mask
vl_api_pnat_mask_t mask
Definition: pnat.api:45
clib_min
#define clib_min(x, y)
Definition: clib.h:342
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
vlib_buffer_t::current_length
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
u64
unsigned long u64
Definition: types.h:89
mrvl_pp2_main_t::interfaces
mrvl_pp2_if_t * interfaces
Definition: pp2.h:80
n_free
u32 n_free
Definition: interface_output.c:1078
mrvl_pp2_outq_t::size
u16 size
Definition: pp2.h:45
u32
unsigned int u32
Definition: types.h:88
n_left
u32 n_left
Definition: interface_output.c:1078
mrvl_pp2_outq_t::buffers
u32 * buffers
Definition: pp2.h:46
mrvl_pp2_main_t::per_thread_data
mrvl_pp2_per_thread_data_t * per_thread_data
Definition: pp2.h:81
mrvl_pp2_outq_t::head
u16 head
Definition: pp2.h:47
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
unix.h
mrvl_pp2_if_t
Definition: pp2.h:51
devices.h
vlib_node_runtime_t
Definition: node.h:454
mrvl_pp2_main_t
Definition: pp2.h:78
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
vnet_interface_output_runtime_t
Definition: interface_funcs.h:472