1 /* 2 * BSD LICENSE 3 * 4 * Copyright (C) Cavium, Inc. 2017. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 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 15 * distribution. 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. 19 * 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. 31 */ 32 33 #include <stdint.h> 34 #include <stdio.h> 35 #include <stdlib.h> 36 #include <unistd.h> 37 38 #include <rte_atomic.h> 39 #include <rte_common.h> 40 #include <rte_ethdev.h> 41 #include <rte_ether.h> 42 #include <rte_log.h> 43 #include <rte_mbuf.h> 44 #include <rte_prefetch.h> 45 46 #include "octeontx_ethdev.h" 47 #include "octeontx_rxtx.h" 48 #include "octeontx_logs.h" 49 50 51 static __rte_always_inline uint16_t __hot 52 __octeontx_xmit_pkts(void *lmtline_va, void *ioreg_va, int64_t *fc_status_va, 53 struct rte_mbuf *tx_pkt) 54 { 55 uint64_t cmd_buf[4]; 56 uint16_t gaura_id; 57 58 if (unlikely(*((volatile int64_t *)fc_status_va) < 0)) 59 return -ENOSPC; 60 61 /* Get the gaura Id */ 62 gaura_id = octeontx_fpa_bufpool_gpool((uintptr_t)tx_pkt->pool->pool_id); 63 64 /* Setup PKO_SEND_HDR_S */ 65 cmd_buf[0] = tx_pkt->data_len & 0xffff; 66 cmd_buf[1] = 0x0; 67 68 /* Set don't free bit if reference count > 1 */ 69 if (rte_mbuf_refcnt_read(tx_pkt) > 1) 70 cmd_buf[0] |= (1ULL << 58); /* SET DF */ 71 72 /* Setup PKO_SEND_GATHER_S */ 73 cmd_buf[(1 << 1) | 1] = rte_mbuf_data_iova(tx_pkt); 74 cmd_buf[(1 << 1) | 0] = PKO_SEND_GATHER_SUBDC | 75 PKO_SEND_GATHER_LDTYPE(0x1ull) | 76 PKO_SEND_GATHER_GAUAR((long)gaura_id) | 77 tx_pkt->data_len; 78 79 octeontx_reg_lmtst(lmtline_va, ioreg_va, cmd_buf, PKO_CMD_SZ); 80 81 return 0; 82 } 83 84 uint16_t __hot 85 octeontx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) 86 { 87 int count; 88 struct octeontx_txq *txq = tx_queue; 89 octeontx_dq_t *dq = &txq->dq; 90 int res; 91 92 count = 0; 93 94 while (count < nb_pkts) { 95 res = __octeontx_xmit_pkts(dq->lmtline_va, dq->ioreg_va, 96 dq->fc_status_va, 97 tx_pkts[count]); 98 if (res < 0) 99 break; 100 101 count++; 102 } 103 104 return count; /* return number of pkts transmitted */ 105 } 106 107 uint16_t __hot 108 octeontx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) 109 { 110 struct octeontx_rxq *rxq; 111 struct rte_event ev; 112 size_t count; 113 uint16_t valid_event; 114 115 rxq = rx_queue; 116 count = 0; 117 while (count < nb_pkts) { 118 valid_event = rte_event_dequeue_burst(rxq->evdev, 119 rxq->ev_ports, &ev, 120 1, 0); 121 if (!valid_event) 122 break; 123 rx_pkts[count++] = ev.mbuf; 124 } 125 126 return count; /* return number of pkts received */ 127 } 128