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 <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 * Pointer to Ethernet device structure.
76 * Receive queue index.
79 nfb_eth_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
82 * Start traffic on Tx queue.
85 * Pointer to Ethernet device structure.
90 * 0 on success, a negative errno value otherwise.
93 nfb_eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id);
96 * Stop traffic on Tx queue.
99 * Pointer to Ethernet device structure.
104 * 0 on success, a negative errno value otherwise.
107 nfb_eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id);
110 * DPDK callback for TX.
113 * Generic pointer to TX queue structure.
115 * Packets to transmit.
117 * Number of packets in array.
120 * Number of packets successfully transmitted (<= nb_pkts).
122 static __rte_always_inline uint16_t
123 nfb_eth_ndp_tx(void *queue,
124 struct rte_mbuf **bufs,
128 struct rte_mbuf *mbuf;
129 struct ndp_tx_queue *ndp = queue;
131 uint64_t num_bytes = 0;
137 struct ndp_packet packets[nb_pkts];
139 if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
140 RTE_LOG(ERR, PMD, "TX invalid arguments!\n");
144 for (i = 0; i < nb_pkts; i++) {
145 packets[i].data_length = bufs[i]->pkt_len;
146 packets[i].header_length = 0;
149 num_tx = ndp_tx_burst_get(ndp->queue, packets, nb_pkts);
151 if (unlikely(num_tx != nb_pkts))
154 for (i = 0; i < nb_pkts; ++i) {
157 pkt_len = mbuf->pkt_len;
158 mbuf_segs = mbuf->nb_segs;
160 num_bytes += pkt_len;
161 if (mbuf_segs == 1) {
163 * non-scattered packet,
164 * transmit from one mbuf
166 rte_memcpy(packets[i].data,
167 rte_pktmbuf_mtod(mbuf, const void *),
170 /* scattered packet, transmit from more mbufs */
171 struct rte_mbuf *m = mbuf;
173 dst = packets[i].data;
179 dst = ((uint8_t *)(dst)) +
185 rte_pktmbuf_free(mbuf);
188 ndp_tx_burst_flush(ndp->queue);
190 ndp->tx_pkts += num_tx;
191 ndp->err_pkts += nb_pkts - num_tx;
192 ndp->tx_bytes += num_bytes;
196 #endif /* _NFB_TX_H_ */