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)
18 extern uint64_t nfb_timestamp_rx_dynflag;
19 extern int nfb_timestamp_dynfield_offset;
21 static inline rte_mbuf_timestamp_t *
22 nfb_timestamp_dynfield(struct rte_mbuf *mbuf)
24 return RTE_MBUF_DYNFIELD(mbuf,
25 nfb_timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
29 struct nfb_device *nfb; /* nfb dev structure */
30 struct ndp_queue *queue; /* rx queue */
31 uint16_t rx_queue_id; /* index */
32 uint8_t in_port; /* port */
33 uint8_t flags; /* setup flags */
35 struct rte_mempool *mb_pool; /* memory pool to allocate packets */
36 uint16_t buf_size; /* mbuf size */
38 volatile uint64_t rx_pkts; /* packets read */
39 volatile uint64_t rx_bytes; /* bytes read */
40 volatile uint64_t err_pkts; /* erroneous packets */
44 * Initialize ndp_rx_queue structure
47 * Pointer to nfb device structure.
51 * Device [external] port identifier.
53 * Memory pool for buffer allocations.
55 * Pointer to ndp_rx_queue output structure
57 * 0 on success, a negative errno value otherwise.
60 nfb_eth_rx_queue_init(struct nfb_device *nfb,
63 struct rte_mempool *mb_pool,
64 struct ndp_rx_queue *rxq);
67 * DPDK callback to setup a RX queue for use.
70 * Pointer to Ethernet device structure.
74 * Number of descriptors to configure in queue.
76 * NUMA socket on which memory must be allocated.
78 * Thresholds parameters.
80 * Memory pool for buffer allocations.
83 * 0 on success, a negative errno value otherwise.
86 nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
88 uint16_t nb_rx_desc __rte_unused,
89 unsigned int socket_id,
90 const struct rte_eth_rxconf *rx_conf __rte_unused,
91 struct rte_mempool *mb_pool);
94 * DPDK callback to release a RX queue.
97 * Generic RX queue pointer.
100 nfb_eth_rx_queue_release(void *q);
103 * Start traffic on Rx queue.
106 * Pointer to Ethernet device structure.
110 * 0 on success, a negative errno value otherwise.
113 nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id);
116 * Stop traffic on Rx queue.
119 * Pointer to Ethernet device structure.
124 nfb_eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id);
127 * DPDK callback for RX.
130 * Generic pointer to RX queue structure.
132 * Array to store received packets.
134 * Maximum number of packets in array.
137 * Number of packets successfully received (<= nb_pkts).
139 static __rte_always_inline uint16_t
140 nfb_eth_ndp_rx(void *queue,
141 struct rte_mbuf **bufs,
144 struct ndp_rx_queue *ndp = queue;
145 uint8_t timestamping_enabled;
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 timestamping_enabled = ndp->flags & NFB_TIMESTAMP_FLAG;
165 /* returns either all or nothing */
166 i = rte_pktmbuf_alloc_bulk(ndp->mb_pool, mbufs, nb_pkts);
167 if (unlikely(i != 0))
170 num_rx = ndp_rx_burst_get(ndp->queue, packets, nb_pkts);
172 if (unlikely(num_rx != nb_pkts)) {
173 for (i = num_rx; i < nb_pkts; i++)
174 rte_pktmbuf_free(mbufs[i]);
181 * Reads the given number of packets from NDP queue given
182 * by queue and copies the packet data into a newly allocated mbuf
185 for (i = 0; i < nb_pkts; ++i) {
188 /* get the space available for data in the mbuf */
189 packet_size = packets[i].data_length;
191 if (likely(packet_size <= buf_size)) {
192 /* NDP packet will fit in one mbuf, go ahead and copy */
193 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
194 packets[i].data, packet_size);
196 mbuf->data_len = (uint16_t)packet_size;
198 mbuf->pkt_len = packet_size;
199 mbuf->port = ndp->in_port;
202 if (timestamping_enabled) {
203 rte_mbuf_timestamp_t timestamp;
207 rte_le_to_cpu_32(*((uint32_t *)
208 (packets[i].header + 4)));
212 rte_le_to_cpu_32(*((uint32_t *)
213 (packets[i].header + 8)));
214 *nfb_timestamp_dynfield(mbuf) = timestamp;
215 mbuf->ol_flags |= nfb_timestamp_rx_dynflag;
218 bufs[num_rx++] = mbuf;
219 num_bytes += packet_size;
222 * NDP packet will not fit in one mbuf,
223 * scattered mode is not enabled, drop packet
225 rte_pktmbuf_free(mbuf);
229 ndp_rx_burst_put(ndp->queue);
231 ndp->rx_pkts += num_rx;
232 ndp->rx_bytes += num_bytes;
236 #endif /* _NFB_RX_H_ */