xref: /dpdk/drivers/net/octeontx/octeontx_rxtx.c (revision ffc905f3b856b96c6d8d864dba4052104fae4064)
1aaf4363eSJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
2aaf4363eSJerin Jacob  * Copyright(c) 2017 Cavium, Inc
39e747589SJerin Jacob  */
49e747589SJerin Jacob 
59e747589SJerin Jacob #include <stdint.h>
69e747589SJerin Jacob #include <stdio.h>
79e747589SJerin Jacob #include <stdlib.h>
89e747589SJerin Jacob #include <unistd.h>
99e747589SJerin Jacob 
109e747589SJerin Jacob #include <rte_atomic.h>
119e747589SJerin Jacob #include <rte_common.h>
12*ffc905f3SFerruh Yigit #include <rte_ethdev_driver.h>
139e747589SJerin Jacob #include <rte_ether.h>
149e747589SJerin Jacob #include <rte_log.h>
159e747589SJerin Jacob #include <rte_mbuf.h>
169e747589SJerin Jacob #include <rte_prefetch.h>
179e747589SJerin Jacob 
189e747589SJerin Jacob #include "octeontx_ethdev.h"
199e747589SJerin Jacob #include "octeontx_rxtx.h"
209e747589SJerin Jacob #include "octeontx_logs.h"
219e747589SJerin Jacob 
2220186d43SJerin Jacob 
239e747589SJerin Jacob static __rte_always_inline uint16_t __hot
249e747589SJerin Jacob __octeontx_xmit_pkts(void *lmtline_va, void *ioreg_va, int64_t *fc_status_va,
259e747589SJerin Jacob 			struct rte_mbuf *tx_pkt)
269e747589SJerin Jacob {
279e747589SJerin Jacob 	uint64_t cmd_buf[4];
289e747589SJerin Jacob 	uint16_t gaura_id;
299e747589SJerin Jacob 
309e747589SJerin Jacob 	if (unlikely(*((volatile int64_t *)fc_status_va) < 0))
319e747589SJerin Jacob 		return -ENOSPC;
329e747589SJerin Jacob 
339e747589SJerin Jacob 	/* Get the gaura Id */
349e747589SJerin Jacob 	gaura_id = octeontx_fpa_bufpool_gpool((uintptr_t)tx_pkt->pool->pool_id);
359e747589SJerin Jacob 
369e747589SJerin Jacob 	/* Setup PKO_SEND_HDR_S */
379e747589SJerin Jacob 	cmd_buf[0] = tx_pkt->data_len & 0xffff;
389e747589SJerin Jacob 	cmd_buf[1] = 0x0;
399e747589SJerin Jacob 
409e747589SJerin Jacob 	/* Set don't free bit if reference count > 1 */
419e747589SJerin Jacob 	if (rte_mbuf_refcnt_read(tx_pkt) > 1)
429e747589SJerin Jacob 		cmd_buf[0] |= (1ULL << 58); /* SET DF */
439e747589SJerin Jacob 
449e747589SJerin Jacob 	/* Setup PKO_SEND_GATHER_S */
45bfa9a8a4SThomas Monjalon 	cmd_buf[(1 << 1) | 1] = rte_mbuf_data_iova(tx_pkt);
469e747589SJerin Jacob 	cmd_buf[(1 << 1) | 0] = PKO_SEND_GATHER_SUBDC |
479e747589SJerin Jacob 				PKO_SEND_GATHER_LDTYPE(0x1ull) |
489e747589SJerin Jacob 				PKO_SEND_GATHER_GAUAR((long)gaura_id) |
499e747589SJerin Jacob 				tx_pkt->data_len;
509e747589SJerin Jacob 
519e747589SJerin Jacob 	octeontx_reg_lmtst(lmtline_va, ioreg_va, cmd_buf, PKO_CMD_SZ);
529e747589SJerin Jacob 
539e747589SJerin Jacob 	return 0;
549e747589SJerin Jacob }
559e747589SJerin Jacob 
569e747589SJerin Jacob uint16_t __hot
579e747589SJerin Jacob octeontx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
589e747589SJerin Jacob {
599e747589SJerin Jacob 	int count;
609e747589SJerin Jacob 	struct octeontx_txq *txq = tx_queue;
619e747589SJerin Jacob 	octeontx_dq_t *dq = &txq->dq;
629e747589SJerin Jacob 	int res;
639e747589SJerin Jacob 
649e747589SJerin Jacob 	count = 0;
659e747589SJerin Jacob 
669e747589SJerin Jacob 	while (count < nb_pkts) {
679e747589SJerin Jacob 		res = __octeontx_xmit_pkts(dq->lmtline_va, dq->ioreg_va,
689e747589SJerin Jacob 					   dq->fc_status_va,
699e747589SJerin Jacob 					   tx_pkts[count]);
709e747589SJerin Jacob 		if (res < 0)
719e747589SJerin Jacob 			break;
729e747589SJerin Jacob 
739e747589SJerin Jacob 		count++;
749e747589SJerin Jacob 	}
759e747589SJerin Jacob 
769e747589SJerin Jacob 	return count; /* return number of pkts transmitted */
779e747589SJerin Jacob }
782d2c7918SJerin Jacob 
792d2c7918SJerin Jacob uint16_t __hot
802d2c7918SJerin Jacob octeontx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
812d2c7918SJerin Jacob {
822d2c7918SJerin Jacob 	struct octeontx_rxq *rxq;
832d2c7918SJerin Jacob 	struct rte_event ev;
842d2c7918SJerin Jacob 	size_t count;
852d2c7918SJerin Jacob 	uint16_t valid_event;
862d2c7918SJerin Jacob 
872d2c7918SJerin Jacob 	rxq = rx_queue;
882d2c7918SJerin Jacob 	count = 0;
892d2c7918SJerin Jacob 	while (count < nb_pkts) {
902d2c7918SJerin Jacob 		valid_event = rte_event_dequeue_burst(rxq->evdev,
912d2c7918SJerin Jacob 							rxq->ev_ports, &ev,
922d2c7918SJerin Jacob 							1, 0);
932d2c7918SJerin Jacob 		if (!valid_event)
942d2c7918SJerin Jacob 			break;
95d0d65498SPavan Nikhilesh 		rx_pkts[count++] = ev.mbuf;
962d2c7918SJerin Jacob 	}
972d2c7918SJerin Jacob 
982d2c7918SJerin Jacob 	return count; /* return number of pkts received */
992d2c7918SJerin Jacob }
100