xref: /dpdk/lib/node/ethdev_tx.c (revision daa02b5cddbb8e11b31d41e2bf7bb1ae64dcae2f)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2020 Marvell International Ltd.
3  */
4 
5 #include <rte_debug.h>
6 #include <rte_ethdev.h>
7 #include <rte_graph.h>
8 #include <rte_graph_worker.h>
9 #include <rte_mbuf.h>
10 
11 #include "ethdev_tx_priv.h"
12 
13 static struct ethdev_tx_node_main ethdev_tx_main;
14 
15 static uint16_t
16 ethdev_tx_node_process(struct rte_graph *graph, struct rte_node *node,
17 		       void **objs, uint16_t nb_objs)
18 {
19 	ethdev_tx_node_ctx_t *ctx = (ethdev_tx_node_ctx_t *)node->ctx;
20 	uint16_t port, queue;
21 	uint16_t count;
22 
23 	/* Get Tx port id */
24 	port = ctx->port;
25 	queue = ctx->queue;
26 
27 	count = rte_eth_tx_burst(port, queue, (struct rte_mbuf **)objs,
28 				 nb_objs);
29 
30 	/* Redirect unsent pkts to drop node */
31 	if (count != nb_objs) {
32 		rte_node_enqueue(graph, node, ETHDEV_TX_NEXT_PKT_DROP,
33 				 &objs[count], nb_objs - count);
34 	}
35 
36 	return count;
37 }
38 
39 static int
40 ethdev_tx_node_init(const struct rte_graph *graph, struct rte_node *node)
41 {
42 	ethdev_tx_node_ctx_t *ctx = (ethdev_tx_node_ctx_t *)node->ctx;
43 	uint64_t port_id = RTE_MAX_ETHPORTS;
44 	int i;
45 
46 	/* Find our port id */
47 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
48 		if (ethdev_tx_main.nodes[i] == node->id) {
49 			port_id = i;
50 			break;
51 		}
52 	}
53 	RTE_VERIFY(port_id < RTE_MAX_ETHPORTS);
54 
55 	/* Update port and queue */
56 	ctx->port = port_id;
57 	ctx->queue = graph->id;
58 
59 	return 0;
60 }
61 
62 struct ethdev_tx_node_main *
63 ethdev_tx_node_data_get(void)
64 {
65 	return &ethdev_tx_main;
66 }
67 
68 static struct rte_node_register ethdev_tx_node_base = {
69 	.process = ethdev_tx_node_process,
70 	.name = "ethdev_tx",
71 
72 	.init = ethdev_tx_node_init,
73 
74 	.nb_edges = ETHDEV_TX_NEXT_MAX,
75 	.next_nodes = {
76 		[ETHDEV_TX_NEXT_PKT_DROP] = "pkt_drop",
77 	},
78 };
79 
80 struct rte_node_register *
81 ethdev_tx_node_get(void)
82 {
83 	return &ethdev_tx_node_base;
84 }
85 
86 RTE_NODE_REGISTER(ethdev_tx_node_base);
87