FD.io VPP  v19.01.3-6-g70449b9b9
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
32  vlib_node_runtime_t * node, vlib_frame_t * frame)
33 {
35  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
37  u32 thread_index = vm->thread_index;
39  vec_elt_at_index (ppm->per_thread_data, thread_index);
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  {
90  vlib_buffer_free (vm, vlib_frame_vector_args (frame) + n_sent,
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  clib_memcpy_fast (outq->buffers + slot, buffers, n_copy * sizeof (u32));
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  */
#define clib_min(x, y)
Definition: clib.h:295
u16 head
Definition: pp2.h:46
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:529
u8 runtime_data[0]
Function dependent node-runtime data.
Definition: node.h:545
static uword vlib_buffer_get_pa(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:322
unsigned long u64
Definition: types.h:89
struct pp2_ppio_desc * descs
Definition: pp2.h:72
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
u32 thread_index
Definition: main.h:179
mrvl_pp2_main_t mrvl_pp2_main
Definition: pp2.c:36
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:450
unsigned char u8
Definition: types.h:56
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
#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
u16 size
Definition: pp2.h:44
struct pp2_hif * hif
Definition: pp2.h:71
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:114
unsigned short u16
Definition: types.h:57
#define PREDICT_FALSE(x)
Definition: clib.h:111
u32 node_index
Node index.
Definition: node.h:518
u16 n_vectors
Definition: node.h:420
vlib_main_t * vm
Definition: buffer.c:301
u32 * buffers
Definition: pp2.h:45
u16 tail
Definition: pp2.h:47
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
uword mrvl_pp2_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: output.c:31
mrvl_pp2_if_t * interfaces
Definition: pp2.h:79
mrvl_pp2_per_thread_data_t * per_thread_data
Definition: pp2.h:80
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62