[dpdk-dev] [PATCH v1 17/26] node: add ethdev Tx node

jerinj at marvell.com jerinj at marvell.com
Wed Mar 18 22:35:42 CET 2020


From: Nithin Dabilpuram <ndabilpuram at marvell.com>

Add rte_node ethdev_tx process function and register it to
graph infra. This node has a specific (port, tx-queue) as context
and it enqueue's all the packets received to that specific queue pair.
When rte_eth_tx_burst() i.e enqueue to queue pair fails, packets
are forwarded to pkt_drop node to be free'd.

Signed-off-by: Nithin Dabilpuram <ndabilpuram at marvell.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula at marvell.com>
Signed-off-by: Kiran Kumar K <kirankumark at marvell.com>
---
 lib/librte_node/Makefile         |  3 +-
 lib/librte_node/ethdev_tx.c      | 86 ++++++++++++++++++++++++++++++++
 lib/librte_node/ethdev_tx_priv.h | 62 +++++++++++++++++++++++
 lib/librte_node/meson.build      |  4 +-
 4 files changed, 152 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_node/ethdev_tx.c
 create mode 100644 lib/librte_node/ethdev_tx_priv.h

diff --git a/lib/librte_node/Makefile b/lib/librte_node/Makefile
index 5a5f589ba..14a293982 100644
--- a/lib/librte_node/Makefile
+++ b/lib/librte_node/Makefile
@@ -9,7 +9,7 @@ LIB = librte_node.a
 
 CFLAGS += -O3 -DALLOW_EXPERIMENTAL_API
 CFLAGS += $(WERROR_FLAGS)
-LDLIBS += -lrte_eal -lrte_graph -lrte_ethdev
+LDLIBS += -lrte_eal -lrte_graph -lrte_mbuf -lrte_ethdev
 
 EXPORT_MAP := rte_node_version.map
 
@@ -17,5 +17,6 @@ EXPORT_MAP := rte_node_version.map
 SRCS-$(CONFIG_RTE_LIBRTE_NODE) += null.c
 SRCS-$(CONFIG_RTE_LIBRTE_NODE) += log.c
 SRCS-$(CONFIG_RTE_LIBRTE_NODE) += ethdev_rx.c
+SRCS-$(CONFIG_RTE_LIBRTE_NODE) += ethdev_tx.c
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_node/ethdev_tx.c b/lib/librte_node/ethdev_tx.c
new file mode 100644
index 000000000..075149089
--- /dev/null
+++ b/lib/librte_node/ethdev_tx.c
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2020 Marvell International Ltd.
+ */
+
+#include <rte_debug.h>
+#include <rte_ethdev.h>
+#include <rte_graph.h>
+#include <rte_graph_worker.h>
+#include <rte_mbuf.h>
+
+#include "ethdev_tx_priv.h"
+
+static struct ethdev_tx_node_main ethdev_tx_main;
+
+static uint16_t
+ethdev_tx_node_process(struct rte_graph *graph, struct rte_node *node,
+		       void **objs, uint16_t nb_objs)
+{
+	ethdev_tx_node_ctx_t *ctx = (ethdev_tx_node_ctx_t *)node->ctx;
+	uint16_t port, queue;
+	uint16_t count;
+
+	/* Get Tx port id */
+	port = ctx->port;
+	queue = ctx->queue;
+
+	count = rte_eth_tx_burst(port, queue, (struct rte_mbuf **)objs,
+				 nb_objs);
+
+	/* Redirect unsent pkts to drop node */
+	if (count != nb_objs) {
+		rte_node_enqueue(graph, node, ETHDEV_TX_NEXT_PKT_DROP,
+				 &objs[count], nb_objs - count);
+	}
+
+	return count;
+}
+
+static int
+ethdev_tx_node_init(const struct rte_graph *graph, struct rte_node *node)
+{
+	ethdev_tx_node_ctx_t *ctx = (ethdev_tx_node_ctx_t *)node->ctx;
+	uint64_t port_id = RTE_MAX_ETHPORTS;
+	int i;
+
+	/* Find our port id */
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+		if (ethdev_tx_main.nodes[i] == node->id) {
+			port_id = i;
+			break;
+		}
+	}
+	RTE_VERIFY(port_id < RTE_MAX_ETHPORTS);
+
+	/* Update port and queue */
+	ctx->port = port_id;
+	ctx->queue = graph->id;
+
+	return 0;
+}
+
+struct ethdev_tx_node_main *
+ethdev_tx_node_data_get(void)
+{
+	return &ethdev_tx_main;
+}
+
+static struct rte_node_register ethdev_tx_node_base = {
+	.process = ethdev_tx_node_process,
+	.name = "ethdev_tx",
+
+	.init = ethdev_tx_node_init,
+
+	.nb_edges = ETHDEV_TX_NEXT_MAX,
+	.next_nodes = {
+		[ETHDEV_TX_NEXT_PKT_DROP] = "pkt_drop",
+	},
+};
+
+struct rte_node_register *
+ethdev_tx_node_get(void)
+{
+	return &ethdev_tx_node_base;
+}
+
+RTE_NODE_REGISTER(ethdev_tx_node_base);
diff --git a/lib/librte_node/ethdev_tx_priv.h b/lib/librte_node/ethdev_tx_priv.h
new file mode 100644
index 000000000..586bff44a
--- /dev/null
+++ b/lib/librte_node/ethdev_tx_priv.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2020 Marvell International Ltd.
+ */
+#ifndef __INCLUDE_ETHDEV_TX_PRIV_H__
+#define __INCLUDE_ETHDEV_TX_PRIV_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ethdev_tx_node_ctx;
+typedef struct ethdev_tx_node_ctx ethdev_tx_node_ctx_t;
+
+enum ethdev_tx_next_nodes {
+	ETHDEV_TX_NEXT_PKT_DROP,
+	ETHDEV_TX_NEXT_MAX,
+};
+
+/**
+ * @internal
+ *
+ * Ethernet Tx node context structure.
+ */
+struct ethdev_tx_node_ctx {
+	uint16_t port;	/**< Port identifier of the Ethernet Tx node. */
+	uint16_t queue; /**< Queue identifier of the Ethernet Tx node. */
+};
+
+/**
+ * @internal
+ *
+ * Ethernet Tx node main structure.
+ */
+struct ethdev_tx_node_main {
+	uint32_t nodes[RTE_MAX_ETHPORTS]; /**< Tx nodes for each ethdev port. */
+};
+
+/**
+ * @internal
+ *
+ * Get the Ethernet Tx node data.
+ *
+ * @return
+ *   Pointer to Ethernet Tx node data.
+ */
+struct ethdev_tx_node_main *ethdev_tx_node_data_get(void);
+
+/**
+ * @internal
+ *
+ * Get the Ethernet Tx node.
+ *
+ * @retrun
+ *   Pointer to the Ethernet Tx node.
+ */
+struct rte_node_register *ethdev_tx_node_get(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INCLUDE_ETHDEV_TX_PRIV_H__ */
diff --git a/lib/librte_node/meson.build b/lib/librte_node/meson.build
index 4adfd6580..c3e35276b 100644
--- a/lib/librte_node/meson.build
+++ b/lib/librte_node/meson.build
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(C) 2020 Marvell International Ltd.
 
-sources = files('null.c', 'log.c', 'ethdev_rx.c')
+sources = files('null.c', 'log.c', 'ethdev_rx.c', 'ethdev_tx.c')
 allow_experimental_apis = true
-deps += ['graph', 'ethdev']
+deps += ['graph', 'mbuf', 'ethdev']
-- 
2.25.1



More information about the dev mailing list