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>
16 #define NFB_TIMESTAMP_FLAG (1 << 0)
19 struct nfb_device *nfb; /* nfb dev structure */
20 struct ndp_queue *queue; /* rx queue */
21 uint16_t rx_queue_id; /* index */
22 uint8_t in_port; /* port */
23 uint8_t flags; /* setup flags */
25 struct rte_mempool *mb_pool; /* memory pool to allocate packets */
26 uint16_t buf_size; /* mbuf size */
28 volatile uint64_t rx_pkts; /* packets read */
29 volatile uint64_t rx_bytes; /* bytes read */
30 volatile uint64_t err_pkts; /* erroneous packets */
34 * Initialize ndp_rx_queue structure
37 * Pointer to nfb device structure.
41 * Device [external] port identifier.
43 * Memory pool for buffer allocations.
45 * Pointer to ndp_rx_queue output structure
47 * 0 on success, a negative errno value otherwise.
50 nfb_eth_rx_queue_init(struct nfb_device *nfb,
53 struct rte_mempool *mb_pool,
54 struct ndp_rx_queue *rxq);
57 * DPDK callback to setup a RX queue for use.
60 * Pointer to Ethernet device structure.
64 * Number of descriptors to configure in queue.
66 * NUMA socket on which memory must be allocated.
68 * Thresholds parameters.
70 * Memory pool for buffer allocations.
73 * 0 on success, a negative errno value otherwise.
76 nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
78 uint16_t nb_rx_desc __rte_unused,
79 unsigned int socket_id,
80 const struct rte_eth_rxconf *rx_conf __rte_unused,
81 struct rte_mempool *mb_pool);
84 * DPDK callback to release a RX queue.
87 * Generic RX queue pointer.
90 nfb_eth_rx_queue_release(void *q);
93 * Start traffic on Rx queue.
96 * Pointer to Ethernet device structure.
100 * 0 on success, a negative errno value otherwise.
103 nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id);
106 * Stop traffic on Rx queue.
109 * Pointer to Ethernet device structure.
114 nfb_eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id);
117 * DPDK callback for RX.
120 * Generic pointer to RX queue structure.
122 * Array to store received packets.
124 * Maximum number of packets in array.
127 * Number of packets successfully received (<= nb_pkts).
129 static __rte_always_inline uint16_t
130 nfb_eth_ndp_rx(void *queue,
131 struct rte_mbuf **bufs,
134 struct ndp_rx_queue *ndp = queue;
135 uint8_t timestamping_enabled;
136 uint16_t packet_size;
137 uint64_t num_bytes = 0;
141 const uint16_t buf_size = ndp->buf_size;
143 struct rte_mbuf *mbuf;
144 struct ndp_packet packets[nb_pkts];
146 struct rte_mbuf *mbufs[nb_pkts];
148 if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
149 RTE_LOG(ERR, PMD, "RX invalid arguments!\n");
153 timestamping_enabled = ndp->flags & NFB_TIMESTAMP_FLAG;
155 /* returns either all or nothing */
156 i = rte_pktmbuf_alloc_bulk(ndp->mb_pool, mbufs, nb_pkts);
157 if (unlikely(i != 0))
160 num_rx = ndp_rx_burst_get(ndp->queue, packets, nb_pkts);
162 if (unlikely(num_rx != nb_pkts)) {
163 for (i = num_rx; i < nb_pkts; i++)
164 rte_pktmbuf_free(mbufs[i]);
171 * Reads the given number of packets from NDP queue given
172 * by queue and copies the packet data into a newly allocated mbuf
175 for (i = 0; i < nb_pkts; ++i) {
178 /* get the space available for data in the mbuf */
179 packet_size = packets[i].data_length;
181 if (likely(packet_size <= buf_size)) {
182 /* NDP packet will fit in one mbuf, go ahead and copy */
183 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
184 packets[i].data, packet_size);
186 mbuf->data_len = (uint16_t)packet_size;
188 mbuf->pkt_len = packet_size;
189 mbuf->port = ndp->in_port;
192 if (timestamping_enabled) {
195 rte_le_to_cpu_32(*((uint32_t *)
196 (packets[i].header + 4)));
197 mbuf->timestamp <<= 32;
200 rte_le_to_cpu_32(*((uint32_t *)
201 (packets[i].header + 8)));
202 mbuf->ol_flags |= PKT_RX_TIMESTAMP;
205 bufs[num_rx++] = mbuf;
206 num_bytes += packet_size;
209 * NDP packet will not fit in one mbuf,
210 * scattered mode is not enabled, drop packet
212 rte_pktmbuf_free(mbuf);
216 ndp_rx_burst_put(ndp->queue);
218 ndp->rx_pkts += num_rx;
219 ndp->rx_bytes += num_bytes;
223 #endif /* _NFB_RX_H_ */