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