4 * Copyright (C) Cavium, Inc. 2017. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium, Inc nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_atomic.h>
39 #include <rte_common.h>
40 #include <rte_ethdev.h>
41 #include <rte_ether.h>
44 #include <rte_prefetch.h>
46 #include "octeontx_ethdev.h"
47 #include "octeontx_rxtx.h"
48 #include "octeontx_logs.h"
50 static __rte_always_inline uint16_t __hot
51 __octeontx_xmit_pkts(void *lmtline_va, void *ioreg_va, int64_t *fc_status_va,
52 struct rte_mbuf *tx_pkt)
57 if (unlikely(*((volatile int64_t *)fc_status_va) < 0))
60 /* Get the gaura Id */
61 gaura_id = octeontx_fpa_bufpool_gpool((uintptr_t)tx_pkt->pool->pool_id);
63 /* Setup PKO_SEND_HDR_S */
64 cmd_buf[0] = tx_pkt->data_len & 0xffff;
67 /* Set don't free bit if reference count > 1 */
68 if (rte_mbuf_refcnt_read(tx_pkt) > 1)
69 cmd_buf[0] |= (1ULL << 58); /* SET DF */
71 /* Setup PKO_SEND_GATHER_S */
72 cmd_buf[(1 << 1) | 1] = rte_mbuf_data_dma_addr(tx_pkt);
73 cmd_buf[(1 << 1) | 0] = PKO_SEND_GATHER_SUBDC |
74 PKO_SEND_GATHER_LDTYPE(0x1ull) |
75 PKO_SEND_GATHER_GAUAR((long)gaura_id) |
78 octeontx_reg_lmtst(lmtline_va, ioreg_va, cmd_buf, PKO_CMD_SZ);
84 octeontx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
87 struct octeontx_txq *txq = tx_queue;
88 octeontx_dq_t *dq = &txq->dq;
93 while (count < nb_pkts) {
94 res = __octeontx_xmit_pkts(dq->lmtline_va, dq->ioreg_va,
103 return count; /* return number of pkts transmitted */
107 octeontx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
109 struct rte_mbuf *mbuf;
110 struct octeontx_rxq *rxq;
114 uint16_t valid_event;
118 while (count < nb_pkts) {
119 valid_event = rte_event_dequeue_burst(rxq->evdev,
125 wqe = (octtx_wqe_t *)(uintptr_t)ev.u64;
126 rte_prefetch_non_temporal(wqe);
128 /* Get mbuf from wqe */
129 mbuf = (struct rte_mbuf *)((uintptr_t)wqe -
130 OCTTX_PACKET_WQE_SKIP);
131 mbuf->data_off = RTE_PTR_DIFF(wqe->s.w3.addr, mbuf->buf_addr);
132 mbuf->pkt_len = wqe->s.w1.len;
133 mbuf->data_len = mbuf->pkt_len;
136 mbuf->port = rxq->port_id;
137 rte_mbuf_refcnt_set(mbuf, 1);
138 rx_pkts[count++] = mbuf;
141 return count; /* return number of pkts received */