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_mbuf_dyn.h>
15 #include <rte_ethdev.h>
17 extern uint64_t nfb_timestamp_rx_dynflag;
18 extern int nfb_timestamp_dynfield_offset;
20 static inline rte_mbuf_timestamp_t *
21 nfb_timestamp_dynfield(struct rte_mbuf *mbuf)
23 return RTE_MBUF_DYNFIELD(mbuf,
24 nfb_timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
28 struct nfb_device *nfb; /* nfb dev structure */
29 struct ndp_queue *queue; /* rx queue */
30 uint16_t rx_queue_id; /* index */
31 uint8_t in_port; /* port */
32 uint8_t flags; /* setup flags */
34 struct rte_mempool *mb_pool; /* memory pool to allocate packets */
35 uint16_t buf_size; /* mbuf size */
37 volatile uint64_t rx_pkts; /* packets read */
38 volatile uint64_t rx_bytes; /* bytes read */
39 volatile uint64_t err_pkts; /* erroneous packets */
43 * Initialize ndp_rx_queue structure
46 * Pointer to nfb device structure.
50 * Device [external] port identifier.
52 * Memory pool for buffer allocations.
54 * Pointer to ndp_rx_queue output structure
56 * 0 on success, a negative errno value otherwise.
59 nfb_eth_rx_queue_init(struct nfb_device *nfb,
62 struct rte_mempool *mb_pool,
63 struct ndp_rx_queue *rxq);
66 * DPDK callback to setup a RX queue for use.
69 * Pointer to Ethernet device structure.
73 * Number of descriptors to configure in queue.
75 * NUMA socket on which memory must be allocated.
77 * Thresholds parameters.
79 * Memory pool for buffer allocations.
82 * 0 on success, a negative errno value otherwise.
85 nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
87 uint16_t nb_rx_desc __rte_unused,
88 unsigned int socket_id,
89 const struct rte_eth_rxconf *rx_conf __rte_unused,
90 struct rte_mempool *mb_pool);
93 * DPDK callback to release a RX queue.
96 * Pointer to Ethernet device structure.
98 * Receive queue index.
101 nfb_eth_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
104 * Start traffic on Rx queue.
107 * Pointer to Ethernet device structure.
111 * 0 on success, a negative errno value otherwise.
114 nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id);
117 * Stop traffic on Rx queue.
120 * Pointer to Ethernet device structure.
125 nfb_eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id);
128 * DPDK callback for RX.
131 * Generic pointer to RX queue structure.
133 * Array to store received packets.
135 * Maximum number of packets in array.
138 * Number of packets successfully received (<= nb_pkts).
140 static __rte_always_inline uint16_t
141 nfb_eth_ndp_rx(void *queue,
142 struct rte_mbuf **bufs,
145 struct ndp_rx_queue *ndp = queue;
146 uint16_t packet_size;
147 uint64_t num_bytes = 0;
151 const uint16_t buf_size = ndp->buf_size;
153 struct rte_mbuf *mbuf;
154 struct ndp_packet packets[nb_pkts];
156 struct rte_mbuf *mbufs[nb_pkts];
158 if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
159 RTE_LOG(ERR, PMD, "RX invalid arguments!\n");
163 /* returns either all or nothing */
164 i = rte_pktmbuf_alloc_bulk(ndp->mb_pool, mbufs, nb_pkts);
165 if (unlikely(i != 0))
168 num_rx = ndp_rx_burst_get(ndp->queue, packets, nb_pkts);
170 if (unlikely(num_rx != nb_pkts)) {
171 for (i = num_rx; i < nb_pkts; i++)
172 rte_pktmbuf_free(mbufs[i]);
179 * Reads the given number of packets from NDP queue given
180 * by queue and copies the packet data into a newly allocated mbuf
183 for (i = 0; i < nb_pkts; ++i) {
186 /* get the space available for data in the mbuf */
187 packet_size = packets[i].data_length;
189 if (likely(packet_size <= buf_size)) {
190 /* NDP packet will fit in one mbuf, go ahead and copy */
191 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
192 packets[i].data, packet_size);
194 mbuf->data_len = (uint16_t)packet_size;
196 mbuf->pkt_len = packet_size;
197 mbuf->port = ndp->in_port;
200 if (nfb_timestamp_dynfield_offset >= 0) {
201 rte_mbuf_timestamp_t timestamp;
205 rte_le_to_cpu_32(*((uint32_t *)
206 (packets[i].header + 4)));
210 rte_le_to_cpu_32(*((uint32_t *)
211 (packets[i].header + 8)));
212 *nfb_timestamp_dynfield(mbuf) = timestamp;
213 mbuf->ol_flags |= nfb_timestamp_rx_dynflag;
216 bufs[num_rx++] = mbuf;
217 num_bytes += packet_size;
220 * NDP packet will not fit in one mbuf,
221 * scattered mode is not enabled, drop packet
223 rte_pktmbuf_free(mbuf);
227 ndp_rx_burst_put(ndp->queue);
229 ndp->rx_pkts += num_rx;
230 ndp->rx_bytes += num_bytes;
234 #endif /* _NFB_RX_H_ */