]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/drivers/net/nfb/nfb_rx.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / nfb / nfb_rx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Cesnet
3 * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
4 * All rights reserved.
5 */
6
7 #ifndef _NFB_RX_H_
8 #define _NFB_RX_H_
9
10 #include <nfb/nfb.h>
11 #include <nfb/ndp.h>
12
13 #include <rte_mbuf.h>
14 #include <rte_ethdev.h>
15
16 struct ndp_rx_queue {
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 */
21
22 struct rte_mempool *mb_pool; /* memory pool to allocate packets */
23 uint16_t buf_size; /* mbuf size */
24
25 volatile uint64_t rx_pkts; /* packets read */
26 volatile uint64_t rx_bytes; /* bytes read */
27 volatile uint64_t err_pkts; /* erroneous packets */
28 };
29
30 /**
31 * Initialize ndp_rx_queue structure
32 *
33 * @param nfb
34 * Pointer to nfb device structure.
35 * @param rx_queue_id
36 * RX queue index.
37 * @param port_id
38 * Device [external] port identifier.
39 * @param mb_pool
40 * Memory pool for buffer allocations.
41 * @param[out] rxq
42 * Pointer to ndp_rx_queue output structure
43 * @return
44 * 0 on success, a negative errno value otherwise.
45 */
46 int
47 nfb_eth_rx_queue_init(struct nfb_device *nfb,
48 uint16_t rx_queue_id,
49 uint16_t port_id,
50 struct rte_mempool *mb_pool,
51 struct ndp_rx_queue *rxq);
52
53 /**
54 * DPDK callback to setup a RX queue for use.
55 *
56 * @param dev
57 * Pointer to Ethernet device structure.
58 * @param idx
59 * RX queue index.
60 * @param desc
61 * Number of descriptors to configure in queue.
62 * @param socket
63 * NUMA socket on which memory must be allocated.
64 * @param[in] conf
65 * Thresholds parameters.
66 * @param mb_pool
67 * Memory pool for buffer allocations.
68 *
69 * @return
70 * 0 on success, a negative errno value otherwise.
71 */
72 int
73 nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
74 uint16_t rx_queue_id,
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);
79
80 /**
81 * DPDK callback to release a RX queue.
82 *
83 * @param dpdk_rxq
84 * Generic RX queue pointer.
85 */
86 void
87 nfb_eth_rx_queue_release(void *q);
88
89 /**
90 * Start traffic on Rx queue.
91 *
92 * @param dev
93 * Pointer to Ethernet device structure.
94 * @param txq_id
95 * RX queue index.
96 * @return
97 * 0 on success, a negative errno value otherwise.
98 */
99 int
100 nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id);
101
102 /**
103 * Stop traffic on Rx queue.
104 *
105 * @param dev
106 * Pointer to Ethernet device structure.
107 * @param txq_id
108 * RX queue index.
109 */
110 int
111 nfb_eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id);
112
113 /**
114 * DPDK callback for RX.
115 *
116 * @param dpdk_rxq
117 * Generic pointer to RX queue structure.
118 * @param[out] bufs
119 * Array to store received packets.
120 * @param nb_pkts
121 * Maximum number of packets in array.
122 *
123 * @return
124 * Number of packets successfully received (<= nb_pkts).
125 */
126 static __rte_always_inline uint16_t
127 nfb_eth_ndp_rx(void *queue,
128 struct rte_mbuf **bufs,
129 uint16_t nb_pkts)
130 {
131 struct ndp_rx_queue *ndp = queue;
132 uint16_t packet_size;
133 uint64_t num_bytes = 0;
134 uint16_t num_rx;
135 unsigned int i;
136
137 const uint16_t buf_size = ndp->buf_size;
138
139 struct rte_mbuf *mbuf;
140 struct ndp_packet packets[nb_pkts];
141
142 struct rte_mbuf *mbufs[nb_pkts];
143
144 if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
145 RTE_LOG(ERR, PMD, "RX invalid arguments!\n");
146 return 0;
147 }
148
149 /* returns either all or nothing */
150 i = rte_pktmbuf_alloc_bulk(ndp->mb_pool, mbufs, nb_pkts);
151 if (unlikely(i != 0))
152 return 0;
153
154 num_rx = ndp_rx_burst_get(ndp->queue, packets, nb_pkts);
155
156 if (unlikely(num_rx != nb_pkts)) {
157 for (i = num_rx; i < nb_pkts; i++)
158 rte_pktmbuf_free(mbufs[i]);
159 }
160
161 nb_pkts = num_rx;
162
163 num_rx = 0;
164 /*
165 * Reads the given number of packets from NDP queue given
166 * by queue and copies the packet data into a newly allocated mbuf
167 * to return.
168 */
169 for (i = 0; i < nb_pkts; ++i) {
170 mbuf = mbufs[i];
171
172 /* get the space available for data in the mbuf */
173 packet_size = packets[i].data_length;
174
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);
179
180 mbuf->data_len = (uint16_t)packet_size;
181
182 mbuf->pkt_len = packet_size;
183 mbuf->port = ndp->in_port;
184 bufs[num_rx++] = mbuf;
185 num_bytes += packet_size;
186 } else {
187 /*
188 * NDP packet will not fit in one mbuf,
189 * scattered mode is not enabled, drop packet
190 */
191 rte_pktmbuf_free(mbuf);
192 }
193 }
194
195 ndp_rx_burst_put(ndp->queue);
196
197 ndp->rx_pkts += num_rx;
198 ndp->rx_bytes += num_bytes;
199 return num_rx;
200 }
201
202 #endif /* _NFB_RX_H_ */