1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Cesnet
3 * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
14 #include <rte_ethdev.h>
17 struct nfb_device *nfb; /* nfb dev structure */
18 struct ndp_queue *queue; /* rx queue */
19 uint16_t rx_queue_id; /* index */
20 uint8_t in_port; /* port */
22 struct rte_mempool *mb_pool; /* memory pool to allocate packets */
23 uint16_t buf_size; /* mbuf size */
25 volatile uint64_t rx_pkts; /* packets read */
26 volatile uint64_t rx_bytes; /* bytes read */
27 volatile uint64_t err_pkts; /* erroneous packets */
31 * Initialize ndp_rx_queue structure
34 * Pointer to nfb device structure.
38 * Device [external] port identifier.
40 * Memory pool for buffer allocations.
42 * Pointer to ndp_rx_queue output structure
44 * 0 on success, a negative errno value otherwise.
47 nfb_eth_rx_queue_init(struct nfb_device *nfb,
50 struct rte_mempool *mb_pool,
51 struct ndp_rx_queue *rxq);
54 * DPDK callback to setup a RX queue for use.
57 * Pointer to Ethernet device structure.
61 * Number of descriptors to configure in queue.
63 * NUMA socket on which memory must be allocated.
65 * Thresholds parameters.
67 * Memory pool for buffer allocations.
70 * 0 on success, a negative errno value otherwise.
73 nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
75 uint16_t nb_rx_desc __rte_unused,
76 unsigned int socket_id,
77 const struct rte_eth_rxconf *rx_conf __rte_unused,
78 struct rte_mempool *mb_pool);
81 * DPDK callback to release a RX queue.
84 * Generic RX queue pointer.
87 nfb_eth_rx_queue_release(void *q);
90 * Start traffic on Rx queue.
93 * Pointer to Ethernet device structure.
97 * 0 on success, a negative errno value otherwise.
100 nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id);
103 * Stop traffic on Rx queue.
106 * Pointer to Ethernet device structure.
111 nfb_eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id);
114 * DPDK callback for RX.
117 * Generic pointer to RX queue structure.
119 * Array to store received packets.
121 * Maximum number of packets in array.
124 * Number of packets successfully received (<= nb_pkts).
126 static __rte_always_inline uint16_t
127 nfb_eth_ndp_rx(void *queue,
128 struct rte_mbuf **bufs,
131 struct ndp_rx_queue *ndp = queue;
132 uint16_t packet_size;
133 uint64_t num_bytes = 0;
137 const uint16_t buf_size = ndp->buf_size;
139 struct rte_mbuf *mbuf;
140 struct ndp_packet packets[nb_pkts];
142 struct rte_mbuf *mbufs[nb_pkts];
144 if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
145 RTE_LOG(ERR, PMD, "RX invalid arguments!\n");
149 /* returns either all or nothing */
150 i = rte_pktmbuf_alloc_bulk(ndp->mb_pool, mbufs, nb_pkts);
151 if (unlikely(i != 0))
154 num_rx = ndp_rx_burst_get(ndp->queue, packets, nb_pkts);
156 if (unlikely(num_rx != nb_pkts)) {
157 for (i = num_rx; i < nb_pkts; i++)
158 rte_pktmbuf_free(mbufs[i]);
165 * Reads the given number of packets from NDP queue given
166 * by queue and copies the packet data into a newly allocated mbuf
169 for (i = 0; i < nb_pkts; ++i) {
172 /* get the space available for data in the mbuf */
173 packet_size = packets[i].data_length;
175 if (likely(packet_size <= buf_size)) {
176 /* NDP packet will fit in one mbuf, go ahead and copy */
177 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
178 packets[i].data, packet_size);
180 mbuf->data_len = (uint16_t)packet_size;
182 mbuf->pkt_len = packet_size;
183 mbuf->port = ndp->in_port;
184 bufs[num_rx++] = mbuf;
185 num_bytes += packet_size;
188 * NDP packet will not fit in one mbuf,
189 * scattered mode is not enabled, drop packet
191 rte_pktmbuf_free(mbuf);
195 ndp_rx_burst_put(ndp->queue);
197 ndp->rx_pkts += num_rx;
198 ndp->rx_bytes += num_bytes;
202 #endif /* _NFB_RX_H_ */