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