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 5020186d43SJerin Jacob 519e747589SJerin Jacob static __rte_always_inline uint16_t __hot 529e747589SJerin Jacob __octeontx_xmit_pkts(void *lmtline_va, void *ioreg_va, int64_t *fc_status_va, 539e747589SJerin Jacob struct rte_mbuf *tx_pkt) 549e747589SJerin Jacob { 559e747589SJerin Jacob uint64_t cmd_buf[4]; 569e747589SJerin Jacob uint16_t gaura_id; 579e747589SJerin Jacob 589e747589SJerin Jacob if (unlikely(*((volatile int64_t *)fc_status_va) < 0)) 599e747589SJerin Jacob return -ENOSPC; 609e747589SJerin Jacob 619e747589SJerin Jacob /* Get the gaura Id */ 629e747589SJerin Jacob gaura_id = octeontx_fpa_bufpool_gpool((uintptr_t)tx_pkt->pool->pool_id); 639e747589SJerin Jacob 649e747589SJerin Jacob /* Setup PKO_SEND_HDR_S */ 659e747589SJerin Jacob cmd_buf[0] = tx_pkt->data_len & 0xffff; 669e747589SJerin Jacob cmd_buf[1] = 0x0; 679e747589SJerin Jacob 689e747589SJerin Jacob /* Set don't free bit if reference count > 1 */ 699e747589SJerin Jacob if (rte_mbuf_refcnt_read(tx_pkt) > 1) 709e747589SJerin Jacob cmd_buf[0] |= (1ULL << 58); /* SET DF */ 719e747589SJerin Jacob 729e747589SJerin Jacob /* Setup PKO_SEND_GATHER_S */ 73*bfa9a8a4SThomas Monjalon cmd_buf[(1 << 1) | 1] = rte_mbuf_data_iova(tx_pkt); 749e747589SJerin Jacob cmd_buf[(1 << 1) | 0] = PKO_SEND_GATHER_SUBDC | 759e747589SJerin Jacob PKO_SEND_GATHER_LDTYPE(0x1ull) | 769e747589SJerin Jacob PKO_SEND_GATHER_GAUAR((long)gaura_id) | 779e747589SJerin Jacob tx_pkt->data_len; 789e747589SJerin Jacob 799e747589SJerin Jacob octeontx_reg_lmtst(lmtline_va, ioreg_va, cmd_buf, PKO_CMD_SZ); 809e747589SJerin Jacob 819e747589SJerin Jacob return 0; 829e747589SJerin Jacob } 839e747589SJerin Jacob 849e747589SJerin Jacob uint16_t __hot 859e747589SJerin Jacob octeontx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) 869e747589SJerin Jacob { 879e747589SJerin Jacob int count; 889e747589SJerin Jacob struct octeontx_txq *txq = tx_queue; 899e747589SJerin Jacob octeontx_dq_t *dq = &txq->dq; 909e747589SJerin Jacob int res; 919e747589SJerin Jacob 929e747589SJerin Jacob count = 0; 939e747589SJerin Jacob 949e747589SJerin Jacob while (count < nb_pkts) { 959e747589SJerin Jacob res = __octeontx_xmit_pkts(dq->lmtline_va, dq->ioreg_va, 969e747589SJerin Jacob dq->fc_status_va, 979e747589SJerin Jacob tx_pkts[count]); 989e747589SJerin Jacob if (res < 0) 999e747589SJerin Jacob break; 1009e747589SJerin Jacob 1019e747589SJerin Jacob count++; 1029e747589SJerin Jacob } 1039e747589SJerin Jacob 1049e747589SJerin Jacob return count; /* return number of pkts transmitted */ 1059e747589SJerin Jacob } 1062d2c7918SJerin Jacob 1072d2c7918SJerin Jacob uint16_t __hot 1082d2c7918SJerin Jacob octeontx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) 1092d2c7918SJerin Jacob { 1102d2c7918SJerin Jacob struct octeontx_rxq *rxq; 1112d2c7918SJerin Jacob struct rte_event ev; 1122d2c7918SJerin Jacob size_t count; 1132d2c7918SJerin Jacob uint16_t valid_event; 1142d2c7918SJerin Jacob 1152d2c7918SJerin Jacob rxq = rx_queue; 1162d2c7918SJerin Jacob count = 0; 1172d2c7918SJerin Jacob while (count < nb_pkts) { 1182d2c7918SJerin Jacob valid_event = rte_event_dequeue_burst(rxq->evdev, 1192d2c7918SJerin Jacob rxq->ev_ports, &ev, 1202d2c7918SJerin Jacob 1, 0); 1212d2c7918SJerin Jacob if (!valid_event) 1222d2c7918SJerin Jacob break; 123d0d65498SPavan Nikhilesh rx_pkts[count++] = ev.mbuf; 1242d2c7918SJerin Jacob } 1252d2c7918SJerin Jacob 1262d2c7918SJerin Jacob return count; /* return number of pkts received */ 1272d2c7918SJerin Jacob } 128