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