1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Cesnet
3 * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
13 #include <rte_ethdev_driver.h>
14 #include <rte_ethdev.h>
15 #include <rte_malloc.h>
18 struct nfb_device *nfb; /* nfb dev structure */
19 struct ndp_queue *queue; /* tx queue */
20 uint16_t tx_queue_id; /* index */
21 volatile uint64_t tx_pkts; /* packets transmitted */
22 volatile uint64_t tx_bytes; /* bytes transmitted */
23 volatile uint64_t err_pkts; /* erroneous packets */
27 * DPDK callback to setup a TX queue for use.
30 * Pointer to Ethernet device structure.
34 * Number of descriptors to configure in queue.
36 * NUMA socket on which memory must be allocated.
38 * Thresholds parameters.
40 * Memory pool for buffer allocations.
43 * 0 on success, a negative errno value otherwise.
46 nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
48 uint16_t nb_tx_desc __rte_unused,
49 unsigned int socket_id,
50 const struct rte_eth_txconf *tx_conf __rte_unused);
53 * Initialize ndp_tx_queue structure
56 * Pointer to nfb device structure.
60 * Pointer to ndp_tx_queue output structure
63 * 0 on success, a negative errno value otherwise.
66 nfb_eth_tx_queue_init(struct nfb_device *nfb,
68 struct ndp_tx_queue *txq);
71 * DPDK callback to release a RX queue.
74 * Generic RX queue pointer.
77 nfb_eth_tx_queue_release(void *q);
80 * Start traffic on Tx queue.
83 * Pointer to Ethernet device structure.
88 * 0 on success, a negative errno value otherwise.
91 nfb_eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id);
94 * Stop traffic on Tx queue.
97 * Pointer to Ethernet device structure.
102 * 0 on success, a negative errno value otherwise.
105 nfb_eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id);
108 * DPDK callback for TX.
111 * Generic pointer to TX queue structure.
113 * Packets to transmit.
115 * Number of packets in array.
118 * Number of packets successfully transmitted (<= nb_pkts).
120 static __rte_always_inline uint16_t
121 nfb_eth_ndp_tx(void *queue,
122 struct rte_mbuf **bufs,
126 struct rte_mbuf *mbuf;
127 struct ndp_tx_queue *ndp = queue;
129 uint64_t num_bytes = 0;
135 struct ndp_packet packets[nb_pkts];
137 if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
138 RTE_LOG(ERR, PMD, "TX invalid arguments!\n");
142 for (i = 0; i < nb_pkts; i++) {
143 packets[i].data_length = bufs[i]->pkt_len;
144 packets[i].header_length = 0;
147 num_tx = ndp_tx_burst_get(ndp->queue, packets, nb_pkts);
149 if (unlikely(num_tx != nb_pkts))
152 for (i = 0; i < nb_pkts; ++i) {
155 pkt_len = mbuf->pkt_len;
156 mbuf_segs = mbuf->nb_segs;
158 num_bytes += pkt_len;
159 if (mbuf_segs == 1) {
161 * non-scattered packet,
162 * transmit from one mbuf
164 rte_memcpy(packets[i].data,
165 rte_pktmbuf_mtod(mbuf, const void *),
168 /* scattered packet, transmit from more mbufs */
169 struct rte_mbuf *m = mbuf;
171 dst = packets[i].data;
177 dst = ((uint8_t *)(dst)) +
183 rte_pktmbuf_free(mbuf);
186 ndp_tx_burst_flush(ndp->queue);
188 ndp->tx_pkts += num_tx;
189 ndp->err_pkts += nb_pkts - num_tx;
190 ndp->tx_bytes += num_bytes;
194 #endif /* _NFB_TX_H_ */