xref: /dpdk/drivers/net/octeontx/octeontx_rxtx.c (revision b733c60f68f12e064359b27e630305c541a3fbdf)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4 
5 #include <stdint.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 
10 #include <rte_atomic.h>
11 #include <rte_common.h>
12 #include <rte_ethdev_driver.h>
13 #include <rte_ether.h>
14 #include <rte_log.h>
15 #include <rte_mbuf.h>
16 #include <rte_prefetch.h>
17 
18 #include "octeontx_ethdev.h"
19 #include "octeontx_rxtx.h"
20 #include "octeontx_logs.h"
21 
22 
23 static __rte_always_inline uint16_t __hot
24 __octeontx_xmit_pkts(void *lmtline_va, void *ioreg_va, int64_t *fc_status_va,
25 			struct rte_mbuf *tx_pkt)
26 {
27 	uint64_t cmd_buf[4];
28 	uint16_t gaura_id;
29 
30 	if (unlikely(*((volatile int64_t *)fc_status_va) < 0))
31 		return -ENOSPC;
32 
33 	/* Get the gaura Id */
34 	gaura_id = octeontx_fpa_bufpool_gaura((uintptr_t)tx_pkt->pool->pool_id);
35 
36 	/* Setup PKO_SEND_HDR_S */
37 	cmd_buf[0] = tx_pkt->data_len & 0xffff;
38 	cmd_buf[1] = 0x0;
39 
40 	/* Set don't free bit if reference count > 1 */
41 	if (rte_mbuf_refcnt_read(tx_pkt) > 1)
42 		cmd_buf[0] |= (1ULL << 58); /* SET DF */
43 
44 	/* Setup PKO_SEND_GATHER_S */
45 	cmd_buf[(1 << 1) | 1] = rte_mbuf_data_iova(tx_pkt);
46 	cmd_buf[(1 << 1) | 0] = PKO_SEND_GATHER_SUBDC |
47 				PKO_SEND_GATHER_LDTYPE(0x1ull) |
48 				PKO_SEND_GATHER_GAUAR((long)gaura_id) |
49 				tx_pkt->data_len;
50 
51 	octeontx_reg_lmtst(lmtline_va, ioreg_va, cmd_buf, PKO_CMD_SZ);
52 
53 	return 0;
54 }
55 
56 uint16_t __hot
57 octeontx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
58 {
59 	int count;
60 	struct octeontx_txq *txq = tx_queue;
61 	octeontx_dq_t *dq = &txq->dq;
62 	int res;
63 
64 	count = 0;
65 
66 	rte_cio_wmb();
67 	while (count < nb_pkts) {
68 		res = __octeontx_xmit_pkts(dq->lmtline_va, dq->ioreg_va,
69 					   dq->fc_status_va,
70 					   tx_pkts[count]);
71 		if (res < 0)
72 			break;
73 
74 		count++;
75 	}
76 
77 	return count; /* return number of pkts transmitted */
78 }
79 
80 uint16_t __hot
81 octeontx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
82 {
83 	struct octeontx_rxq *rxq;
84 	struct rte_event ev;
85 	size_t count;
86 	uint16_t valid_event;
87 
88 	rxq = rx_queue;
89 	count = 0;
90 	while (count < nb_pkts) {
91 		valid_event = rte_event_dequeue_burst(rxq->evdev,
92 							rxq->ev_ports, &ev,
93 							1, 0);
94 		if (!valid_event)
95 			break;
96 		rx_pkts[count++] = ev.mbuf;
97 	}
98 
99 	return count; /* return number of pkts received */
100 }
101