19e747589SJerin Jacob /* 29e747589SJerin Jacob * BSD LICENSE 39e747589SJerin Jacob * 49e747589SJerin Jacob * Copyright (C) Cavium, Inc. 2017. All rights reserved. 59e747589SJerin Jacob * 69e747589SJerin Jacob * Redistribution and use in source and binary forms, with or without 79e747589SJerin Jacob * modification, are permitted provided that the following conditions 89e747589SJerin Jacob * are met: 99e747589SJerin Jacob * 109e747589SJerin Jacob * * Redistributions of source code must retain the above copyright 119e747589SJerin Jacob * notice, this list of conditions and the following disclaimer. 129e747589SJerin Jacob * * Redistributions in binary form must reproduce the above copyright 139e747589SJerin Jacob * notice, this list of conditions and the following disclaimer in 149e747589SJerin Jacob * the documentation and/or other materials provided with the 159e747589SJerin Jacob * distribution. 169e747589SJerin Jacob * * Neither the name of Cavium, Inc nor the names of its 179e747589SJerin Jacob * contributors may be used to endorse or promote products derived 189e747589SJerin Jacob * from this software without specific prior written permission. 199e747589SJerin Jacob * 209e747589SJerin Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 219e747589SJerin Jacob * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 229e747589SJerin Jacob * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 239e747589SJerin Jacob * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 249e747589SJerin Jacob * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 259e747589SJerin Jacob * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 269e747589SJerin Jacob * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 279e747589SJerin Jacob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 289e747589SJerin Jacob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 299e747589SJerin Jacob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 309e747589SJerin Jacob * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 319e747589SJerin Jacob */ 329e747589SJerin Jacob 339e747589SJerin Jacob #include <stdint.h> 349e747589SJerin Jacob #include <stdio.h> 359e747589SJerin Jacob #include <stdlib.h> 369e747589SJerin Jacob #include <unistd.h> 379e747589SJerin Jacob 389e747589SJerin Jacob #include <rte_atomic.h> 399e747589SJerin Jacob #include <rte_common.h> 409e747589SJerin Jacob #include <rte_ethdev.h> 419e747589SJerin Jacob #include <rte_ether.h> 429e747589SJerin Jacob #include <rte_log.h> 439e747589SJerin Jacob #include <rte_mbuf.h> 449e747589SJerin Jacob #include <rte_prefetch.h> 459e747589SJerin Jacob 469e747589SJerin Jacob #include "octeontx_ethdev.h" 479e747589SJerin Jacob #include "octeontx_rxtx.h" 489e747589SJerin Jacob #include "octeontx_logs.h" 499e747589SJerin Jacob 509e747589SJerin Jacob static __rte_always_inline uint16_t __hot 519e747589SJerin Jacob __octeontx_xmit_pkts(void *lmtline_va, void *ioreg_va, int64_t *fc_status_va, 529e747589SJerin Jacob struct rte_mbuf *tx_pkt) 539e747589SJerin Jacob { 549e747589SJerin Jacob uint64_t cmd_buf[4]; 559e747589SJerin Jacob uint16_t gaura_id; 569e747589SJerin Jacob 579e747589SJerin Jacob if (unlikely(*((volatile int64_t *)fc_status_va) < 0)) 589e747589SJerin Jacob return -ENOSPC; 599e747589SJerin Jacob 609e747589SJerin Jacob /* Get the gaura Id */ 619e747589SJerin Jacob gaura_id = octeontx_fpa_bufpool_gpool((uintptr_t)tx_pkt->pool->pool_id); 629e747589SJerin Jacob 639e747589SJerin Jacob /* Setup PKO_SEND_HDR_S */ 649e747589SJerin Jacob cmd_buf[0] = tx_pkt->data_len & 0xffff; 659e747589SJerin Jacob cmd_buf[1] = 0x0; 669e747589SJerin Jacob 679e747589SJerin Jacob /* Set don't free bit if reference count > 1 */ 689e747589SJerin Jacob if (rte_mbuf_refcnt_read(tx_pkt) > 1) 699e747589SJerin Jacob cmd_buf[0] |= (1ULL << 58); /* SET DF */ 709e747589SJerin Jacob 719e747589SJerin Jacob /* Setup PKO_SEND_GATHER_S */ 729e747589SJerin Jacob cmd_buf[(1 << 1) | 1] = rte_mbuf_data_dma_addr(tx_pkt); 739e747589SJerin Jacob cmd_buf[(1 << 1) | 0] = PKO_SEND_GATHER_SUBDC | 749e747589SJerin Jacob PKO_SEND_GATHER_LDTYPE(0x1ull) | 759e747589SJerin Jacob PKO_SEND_GATHER_GAUAR((long)gaura_id) | 769e747589SJerin Jacob tx_pkt->data_len; 779e747589SJerin Jacob 789e747589SJerin Jacob octeontx_reg_lmtst(lmtline_va, ioreg_va, cmd_buf, PKO_CMD_SZ); 799e747589SJerin Jacob 809e747589SJerin Jacob return 0; 819e747589SJerin Jacob } 829e747589SJerin Jacob 839e747589SJerin Jacob uint16_t __hot 849e747589SJerin Jacob octeontx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) 859e747589SJerin Jacob { 869e747589SJerin Jacob int count; 879e747589SJerin Jacob struct octeontx_txq *txq = tx_queue; 889e747589SJerin Jacob octeontx_dq_t *dq = &txq->dq; 899e747589SJerin Jacob int res; 909e747589SJerin Jacob 919e747589SJerin Jacob count = 0; 929e747589SJerin Jacob 939e747589SJerin Jacob while (count < nb_pkts) { 949e747589SJerin Jacob res = __octeontx_xmit_pkts(dq->lmtline_va, dq->ioreg_va, 959e747589SJerin Jacob dq->fc_status_va, 969e747589SJerin Jacob tx_pkts[count]); 979e747589SJerin Jacob if (res < 0) 989e747589SJerin Jacob break; 999e747589SJerin Jacob 1009e747589SJerin Jacob count++; 1019e747589SJerin Jacob } 1029e747589SJerin Jacob 1039e747589SJerin Jacob return count; /* return number of pkts transmitted */ 1049e747589SJerin Jacob } 105*2d2c7918SJerin Jacob 106*2d2c7918SJerin Jacob uint16_t __hot 107*2d2c7918SJerin Jacob octeontx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) 108*2d2c7918SJerin Jacob { 109*2d2c7918SJerin Jacob struct rte_mbuf *mbuf; 110*2d2c7918SJerin Jacob struct octeontx_rxq *rxq; 111*2d2c7918SJerin Jacob struct rte_event ev; 112*2d2c7918SJerin Jacob octtx_wqe_t *wqe; 113*2d2c7918SJerin Jacob size_t count; 114*2d2c7918SJerin Jacob uint16_t valid_event; 115*2d2c7918SJerin Jacob 116*2d2c7918SJerin Jacob rxq = rx_queue; 117*2d2c7918SJerin Jacob count = 0; 118*2d2c7918SJerin Jacob while (count < nb_pkts) { 119*2d2c7918SJerin Jacob valid_event = rte_event_dequeue_burst(rxq->evdev, 120*2d2c7918SJerin Jacob rxq->ev_ports, &ev, 121*2d2c7918SJerin Jacob 1, 0); 122*2d2c7918SJerin Jacob if (!valid_event) 123*2d2c7918SJerin Jacob break; 124*2d2c7918SJerin Jacob 125*2d2c7918SJerin Jacob wqe = (octtx_wqe_t *)(uintptr_t)ev.u64; 126*2d2c7918SJerin Jacob rte_prefetch_non_temporal(wqe); 127*2d2c7918SJerin Jacob 128*2d2c7918SJerin Jacob /* Get mbuf from wqe */ 129*2d2c7918SJerin Jacob mbuf = (struct rte_mbuf *)((uintptr_t)wqe - 130*2d2c7918SJerin Jacob OCTTX_PACKET_WQE_SKIP); 131*2d2c7918SJerin Jacob mbuf->data_off = RTE_PTR_DIFF(wqe->s.w3.addr, mbuf->buf_addr); 132*2d2c7918SJerin Jacob mbuf->pkt_len = wqe->s.w1.len; 133*2d2c7918SJerin Jacob mbuf->data_len = mbuf->pkt_len; 134*2d2c7918SJerin Jacob mbuf->nb_segs = 1; 135*2d2c7918SJerin Jacob mbuf->ol_flags = 0; 136*2d2c7918SJerin Jacob mbuf->port = rxq->port_id; 137*2d2c7918SJerin Jacob rte_mbuf_refcnt_set(mbuf, 1); 138*2d2c7918SJerin Jacob rx_pkts[count++] = mbuf; 139*2d2c7918SJerin Jacob } 140*2d2c7918SJerin Jacob 141*2d2c7918SJerin Jacob return count; /* return number of pkts received */ 142*2d2c7918SJerin Jacob } 143