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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
20 #include <sys/ioctl.h>
23 #include <vlib/vlib.h>
24 #include <vlib/unix/unix.h>
25 #include <vnet/ethernet/ethernet.h>
26 #include <vnet/devices/devices.h>
28 #include <marvell/pp2/pp2.h>
31 mrvl_pp2_interface_tx (vlib_main_t * vm,
32 vlib_node_runtime_t * node, vlib_frame_t * frame)
34 mrvl_pp2_main_t *ppm = &mrvl_pp2_main;
35 vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
36 mrvl_pp2_if_t *ppif = pool_elt_at_index (ppm->interfaces, rd->dev_instance);
37 u32 thread_index = vm->thread_index;
38 mrvl_pp2_per_thread_data_t *ptd =
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;
47 if (PREDICT_FALSE (pp2_ppio_get_num_outq_done (ppif->ppio, ptd->hif, qid,
51 vlib_error_count (vm, node->node_index,
52 MRVL_PP2_TX_ERROR_PPIO_GET_NUM_OUTQ_DONE, 1);
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);
64 vec_validate_aligned (ptd->descs, n_left, CLIB_CACHE_LINE_BYTES);
69 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
70 u64 paddr = vlib_buffer_get_pa (vm, b0);
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);
81 if (pp2_ppio_send (ppif->ppio, ptd->hif, qid, ptd->descs, &n_sent))
84 vlib_error_count (vm, node->node_index, MRVL_PP2_TX_ERROR_PPIO_SEND, 1);
87 /* free unsent buffers */
88 if (PREDICT_FALSE (n_sent != n_desc))
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);
96 /* store buffer index for each enqueued packet into the ring
97 so we can know what to free after packet is sent */
100 u16 slot = outq->head & mask;
101 buffers = vlib_frame_vector_args (frame);
102 u16 n_copy = clib_min (outq->size - slot, n_sent);
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));
109 outq->head += n_sent;
116 * fd.io coding-style-patch-verification: ON
119 * eval: (c-set-style "gnu")