1*9e747589SJerin Jacob /* 2*9e747589SJerin Jacob * BSD LICENSE 3*9e747589SJerin Jacob * 4*9e747589SJerin Jacob * Copyright (C) Cavium, Inc. 2017. All rights reserved. 5*9e747589SJerin Jacob * 6*9e747589SJerin Jacob * Redistribution and use in source and binary forms, with or without 7*9e747589SJerin Jacob * modification, are permitted provided that the following conditions 8*9e747589SJerin Jacob * are met: 9*9e747589SJerin Jacob * 10*9e747589SJerin Jacob * * Redistributions of source code must retain the above copyright 11*9e747589SJerin Jacob * notice, this list of conditions and the following disclaimer. 12*9e747589SJerin Jacob * * Redistributions in binary form must reproduce the above copyright 13*9e747589SJerin Jacob * notice, this list of conditions and the following disclaimer in 14*9e747589SJerin Jacob * the documentation and/or other materials provided with the 15*9e747589SJerin Jacob * distribution. 16*9e747589SJerin Jacob * * Neither the name of Cavium, Inc nor the names of its 17*9e747589SJerin Jacob * contributors may be used to endorse or promote products derived 18*9e747589SJerin Jacob * from this software without specific prior written permission. 19*9e747589SJerin Jacob * 20*9e747589SJerin Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21*9e747589SJerin Jacob * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*9e747589SJerin Jacob * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23*9e747589SJerin Jacob * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24*9e747589SJerin Jacob * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25*9e747589SJerin Jacob * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26*9e747589SJerin Jacob * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27*9e747589SJerin Jacob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28*9e747589SJerin Jacob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29*9e747589SJerin Jacob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30*9e747589SJerin Jacob * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31*9e747589SJerin Jacob */ 32*9e747589SJerin Jacob 33*9e747589SJerin Jacob #include <stdint.h> 34*9e747589SJerin Jacob #include <stdio.h> 35*9e747589SJerin Jacob #include <stdlib.h> 36*9e747589SJerin Jacob #include <unistd.h> 37*9e747589SJerin Jacob 38*9e747589SJerin Jacob #include <rte_atomic.h> 39*9e747589SJerin Jacob #include <rte_common.h> 40*9e747589SJerin Jacob #include <rte_ethdev.h> 41*9e747589SJerin Jacob #include <rte_ether.h> 42*9e747589SJerin Jacob #include <rte_log.h> 43*9e747589SJerin Jacob #include <rte_mbuf.h> 44*9e747589SJerin Jacob #include <rte_prefetch.h> 45*9e747589SJerin Jacob 46*9e747589SJerin Jacob #include "octeontx_ethdev.h" 47*9e747589SJerin Jacob #include "octeontx_rxtx.h" 48*9e747589SJerin Jacob #include "octeontx_logs.h" 49*9e747589SJerin Jacob 50*9e747589SJerin Jacob static __rte_always_inline uint16_t __hot 51*9e747589SJerin Jacob __octeontx_xmit_pkts(void *lmtline_va, void *ioreg_va, int64_t *fc_status_va, 52*9e747589SJerin Jacob struct rte_mbuf *tx_pkt) 53*9e747589SJerin Jacob { 54*9e747589SJerin Jacob uint64_t cmd_buf[4]; 55*9e747589SJerin Jacob uint16_t gaura_id; 56*9e747589SJerin Jacob 57*9e747589SJerin Jacob if (unlikely(*((volatile int64_t *)fc_status_va) < 0)) 58*9e747589SJerin Jacob return -ENOSPC; 59*9e747589SJerin Jacob 60*9e747589SJerin Jacob /* Get the gaura Id */ 61*9e747589SJerin Jacob gaura_id = octeontx_fpa_bufpool_gpool((uintptr_t)tx_pkt->pool->pool_id); 62*9e747589SJerin Jacob 63*9e747589SJerin Jacob /* Setup PKO_SEND_HDR_S */ 64*9e747589SJerin Jacob cmd_buf[0] = tx_pkt->data_len & 0xffff; 65*9e747589SJerin Jacob cmd_buf[1] = 0x0; 66*9e747589SJerin Jacob 67*9e747589SJerin Jacob /* Set don't free bit if reference count > 1 */ 68*9e747589SJerin Jacob if (rte_mbuf_refcnt_read(tx_pkt) > 1) 69*9e747589SJerin Jacob cmd_buf[0] |= (1ULL << 58); /* SET DF */ 70*9e747589SJerin Jacob 71*9e747589SJerin Jacob /* Setup PKO_SEND_GATHER_S */ 72*9e747589SJerin Jacob cmd_buf[(1 << 1) | 1] = rte_mbuf_data_dma_addr(tx_pkt); 73*9e747589SJerin Jacob cmd_buf[(1 << 1) | 0] = PKO_SEND_GATHER_SUBDC | 74*9e747589SJerin Jacob PKO_SEND_GATHER_LDTYPE(0x1ull) | 75*9e747589SJerin Jacob PKO_SEND_GATHER_GAUAR((long)gaura_id) | 76*9e747589SJerin Jacob tx_pkt->data_len; 77*9e747589SJerin Jacob 78*9e747589SJerin Jacob octeontx_reg_lmtst(lmtline_va, ioreg_va, cmd_buf, PKO_CMD_SZ); 79*9e747589SJerin Jacob 80*9e747589SJerin Jacob return 0; 81*9e747589SJerin Jacob } 82*9e747589SJerin Jacob 83*9e747589SJerin Jacob uint16_t __hot 84*9e747589SJerin Jacob octeontx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) 85*9e747589SJerin Jacob { 86*9e747589SJerin Jacob int count; 87*9e747589SJerin Jacob struct octeontx_txq *txq = tx_queue; 88*9e747589SJerin Jacob octeontx_dq_t *dq = &txq->dq; 89*9e747589SJerin Jacob int res; 90*9e747589SJerin Jacob 91*9e747589SJerin Jacob count = 0; 92*9e747589SJerin Jacob 93*9e747589SJerin Jacob while (count < nb_pkts) { 94*9e747589SJerin Jacob res = __octeontx_xmit_pkts(dq->lmtline_va, dq->ioreg_va, 95*9e747589SJerin Jacob dq->fc_status_va, 96*9e747589SJerin Jacob tx_pkts[count]); 97*9e747589SJerin Jacob if (res < 0) 98*9e747589SJerin Jacob break; 99*9e747589SJerin Jacob 100*9e747589SJerin Jacob count++; 101*9e747589SJerin Jacob } 102*9e747589SJerin Jacob 103*9e747589SJerin Jacob return count; /* return number of pkts transmitted */ 104*9e747589SJerin Jacob } 105