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.h>
14 #include <rte_malloc.h>
17 struct nfb_device *nfb; /* nfb dev structure */
18 struct ndp_queue *queue; /* tx queue */
19 uint16_t tx_queue_id; /* index */
20 volatile uint64_t tx_pkts; /* packets transmitted */
21 volatile uint64_t tx_bytes; /* bytes transmitted */
22 volatile uint64_t err_pkts; /* erroneous packets */
26 * DPDK callback to setup a TX queue for use.
29 * Pointer to Ethernet device structure.
33 * Number of descriptors to configure in queue.
35 * NUMA socket on which memory must be allocated.
37 * Thresholds parameters.
39 * Memory pool for buffer allocations.
42 * 0 on success, a negative errno value otherwise.
45 nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
47 uint16_t nb_tx_desc __rte_unused,
48 unsigned int socket_id,
49 const struct rte_eth_txconf *tx_conf __rte_unused);
52 * Initialize ndp_tx_queue structure
55 * Pointer to nfb device structure.
59 * Pointer to ndp_tx_queue output structure
62 * 0 on success, a negative errno value otherwise.
65 nfb_eth_tx_queue_init(struct nfb_device *nfb,
67 struct ndp_tx_queue *txq);
70 * DPDK callback to release a RX queue.
73 * Generic RX queue pointer.
76 nfb_eth_tx_queue_release(void *q);
79 * Start traffic on Tx queue.
82 * Pointer to Ethernet device structure.
87 * 0 on success, a negative errno value otherwise.
90 nfb_eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id);
93 * Stop traffic on Tx queue.
96 * Pointer to Ethernet device structure.
101 * 0 on success, a negative errno value otherwise.
104 nfb_eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id);
107 * DPDK callback for TX.
110 * Generic pointer to TX queue structure.
112 * Packets to transmit.
114 * Number of packets in array.
117 * Number of packets successfully transmitted (<= nb_pkts).
119 static __rte_always_inline uint16_t
120 nfb_eth_ndp_tx(void *queue,
121 struct rte_mbuf **bufs,
125 struct rte_mbuf *mbuf;
126 struct ndp_tx_queue *ndp = queue;
128 uint64_t num_bytes = 0;
134 struct ndp_packet packets[nb_pkts];
136 if (unlikely(ndp->queue == NULL || nb_pkts == 0)) {
137 RTE_LOG(ERR, PMD, "TX invalid arguments!\n");
141 for (i = 0; i < nb_pkts; i++) {
142 packets[i].data_length = bufs[i]->pkt_len;
143 packets[i].header_length = 0;
146 num_tx = ndp_tx_burst_get(ndp->queue, packets, nb_pkts);
148 if (unlikely(num_tx != nb_pkts))
151 for (i = 0; i < nb_pkts; ++i) {
154 pkt_len = mbuf->pkt_len;
155 mbuf_segs = mbuf->nb_segs;
157 num_bytes += pkt_len;
158 if (mbuf_segs == 1) {
160 * non-scattered packet,
161 * transmit from one mbuf
163 rte_memcpy(packets[i].data,
164 rte_pktmbuf_mtod(mbuf, const void *),
167 /* scattered packet, transmit from more mbufs */
168 struct rte_mbuf *m = mbuf;
170 dst = packets[i].data;
176 dst = ((uint8_t *)(dst)) +
182 rte_pktmbuf_free(mbuf);
185 ndp_tx_burst_flush(ndp->queue);
187 ndp->tx_pkts += num_tx;
188 ndp->err_pkts += nb_pkts - num_tx;
189 ndp->tx_bytes += num_bytes;
193 #endif /* _NFB_TX_H_ */