xref: /dpdk/lib/node/ethdev_ctrl.c (revision 30a1de10)
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_ethdev.h>
6*99a2dd95SBruce Richardson #include <rte_graph.h>
7*99a2dd95SBruce Richardson 
8*99a2dd95SBruce Richardson #include "rte_node_eth_api.h"
9*99a2dd95SBruce Richardson 
10*99a2dd95SBruce Richardson #include "ethdev_rx_priv.h"
11*99a2dd95SBruce Richardson #include "ethdev_tx_priv.h"
12*99a2dd95SBruce Richardson #include "ip4_rewrite_priv.h"
13*99a2dd95SBruce Richardson #include "node_private.h"
14*99a2dd95SBruce Richardson 
15*99a2dd95SBruce Richardson static struct ethdev_ctrl {
16*99a2dd95SBruce Richardson 	uint16_t nb_graphs;
17*99a2dd95SBruce Richardson } ctrl;
18*99a2dd95SBruce Richardson 
19*99a2dd95SBruce Richardson int
rte_node_eth_config(struct rte_node_ethdev_config * conf,uint16_t nb_confs,uint16_t nb_graphs)20*99a2dd95SBruce Richardson rte_node_eth_config(struct rte_node_ethdev_config *conf, uint16_t nb_confs,
21*99a2dd95SBruce Richardson 		    uint16_t nb_graphs)
22*99a2dd95SBruce Richardson {
23*99a2dd95SBruce Richardson 	struct rte_node_register *ip4_rewrite_node;
24*99a2dd95SBruce Richardson 	struct ethdev_tx_node_main *tx_node_data;
25*99a2dd95SBruce Richardson 	uint16_t tx_q_used, rx_q_used, port_id;
26*99a2dd95SBruce Richardson 	struct rte_node_register *tx_node;
27*99a2dd95SBruce Richardson 	char name[RTE_NODE_NAMESIZE];
28*99a2dd95SBruce Richardson 	const char *next_nodes = name;
29*99a2dd95SBruce Richardson 	struct rte_mempool *mp;
30*99a2dd95SBruce Richardson 	int i, j, rc;
31*99a2dd95SBruce Richardson 	uint32_t id;
32*99a2dd95SBruce Richardson 
33*99a2dd95SBruce Richardson 	ip4_rewrite_node = ip4_rewrite_node_get();
34*99a2dd95SBruce Richardson 	tx_node_data = ethdev_tx_node_data_get();
35*99a2dd95SBruce Richardson 	tx_node = ethdev_tx_node_get();
36*99a2dd95SBruce Richardson 	for (i = 0; i < nb_confs; i++) {
37*99a2dd95SBruce Richardson 		port_id = conf[i].port_id;
38*99a2dd95SBruce Richardson 
39*99a2dd95SBruce Richardson 		if (!rte_eth_dev_is_valid_port(port_id))
40*99a2dd95SBruce Richardson 			return -EINVAL;
41*99a2dd95SBruce Richardson 
42*99a2dd95SBruce Richardson 		/* Check for mbuf minimum private size requirement */
43*99a2dd95SBruce Richardson 		for (j = 0; j < conf[i].mp_count; j++) {
44*99a2dd95SBruce Richardson 			mp = conf[i].mp[j];
45*99a2dd95SBruce Richardson 			if (!mp)
46*99a2dd95SBruce Richardson 				continue;
47*99a2dd95SBruce Richardson 			/* Check for minimum private space */
48*99a2dd95SBruce Richardson 			if (rte_pktmbuf_priv_size(mp) < NODE_MBUF_PRIV2_SIZE) {
49*99a2dd95SBruce Richardson 				node_err("ethdev",
50*99a2dd95SBruce Richardson 					 "Minimum mbuf priv size requirement not met by mp %s",
51*99a2dd95SBruce Richardson 					 mp->name);
52*99a2dd95SBruce Richardson 				return -EINVAL;
53*99a2dd95SBruce Richardson 			}
54*99a2dd95SBruce Richardson 		}
55*99a2dd95SBruce Richardson 
56*99a2dd95SBruce Richardson 		rx_q_used = conf[i].num_rx_queues;
57*99a2dd95SBruce Richardson 		tx_q_used = conf[i].num_tx_queues;
58*99a2dd95SBruce Richardson 		/* Check if we have a txq for each worker */
59*99a2dd95SBruce Richardson 		if (tx_q_used < nb_graphs)
60*99a2dd95SBruce Richardson 			return -EINVAL;
61*99a2dd95SBruce Richardson 
62*99a2dd95SBruce Richardson 		/* Create node for each rx port queue pair */
63*99a2dd95SBruce Richardson 		for (j = 0; j < rx_q_used; j++) {
64*99a2dd95SBruce Richardson 			struct ethdev_rx_node_main *rx_node_data;
65*99a2dd95SBruce Richardson 			struct rte_node_register *rx_node;
66*99a2dd95SBruce Richardson 			ethdev_rx_node_elem_t *elem;
67*99a2dd95SBruce Richardson 
68*99a2dd95SBruce Richardson 			rx_node_data = ethdev_rx_get_node_data_get();
69*99a2dd95SBruce Richardson 			rx_node = ethdev_rx_node_get();
70*99a2dd95SBruce Richardson 			snprintf(name, sizeof(name), "%u-%u", port_id, j);
71*99a2dd95SBruce Richardson 			/* Clone a new rx node with same edges as parent */
72*99a2dd95SBruce Richardson 			id = rte_node_clone(rx_node->id, name);
73*99a2dd95SBruce Richardson 			if (id == RTE_NODE_ID_INVALID)
74*99a2dd95SBruce Richardson 				return -EIO;
75*99a2dd95SBruce Richardson 
76*99a2dd95SBruce Richardson 			/* Add it to list of ethdev rx nodes for lookup */
77*99a2dd95SBruce Richardson 			elem = malloc(sizeof(ethdev_rx_node_elem_t));
78*99a2dd95SBruce Richardson 			memset(elem, 0, sizeof(ethdev_rx_node_elem_t));
79*99a2dd95SBruce Richardson 			elem->ctx.port_id = port_id;
80*99a2dd95SBruce Richardson 			elem->ctx.queue_id = j;
81*99a2dd95SBruce Richardson 			elem->nid = id;
82*99a2dd95SBruce Richardson 			elem->next = rx_node_data->head;
83*99a2dd95SBruce Richardson 			rx_node_data->head = elem;
84*99a2dd95SBruce Richardson 
85*99a2dd95SBruce Richardson 			node_dbg("ethdev", "Rx node %s-%s: is at %u",
86*99a2dd95SBruce Richardson 				 rx_node->name, name, id);
87*99a2dd95SBruce Richardson 		}
88*99a2dd95SBruce Richardson 
89*99a2dd95SBruce Richardson 		/* Create a per port tx node from base node */
90*99a2dd95SBruce Richardson 		snprintf(name, sizeof(name), "%u", port_id);
91*99a2dd95SBruce Richardson 		/* Clone a new node with same edges as parent */
92*99a2dd95SBruce Richardson 		id = rte_node_clone(tx_node->id, name);
93*99a2dd95SBruce Richardson 		tx_node_data->nodes[port_id] = id;
94*99a2dd95SBruce Richardson 
95*99a2dd95SBruce Richardson 		node_dbg("ethdev", "Tx node %s-%s: is at %u", tx_node->name,
96*99a2dd95SBruce Richardson 			 name, id);
97*99a2dd95SBruce Richardson 
98*99a2dd95SBruce Richardson 		/* Prepare the actual name of the cloned node */
99*99a2dd95SBruce Richardson 		snprintf(name, sizeof(name), "ethdev_tx-%u", port_id);
100*99a2dd95SBruce Richardson 
101*99a2dd95SBruce Richardson 		/* Add this tx port node as next to ip4_rewrite_node */
102*99a2dd95SBruce Richardson 		rte_node_edge_update(ip4_rewrite_node->id, RTE_EDGE_ID_INVALID,
103*99a2dd95SBruce Richardson 				     &next_nodes, 1);
104*99a2dd95SBruce Richardson 		/* Assuming edge id is the last one alloc'ed */
105*99a2dd95SBruce Richardson 		rc = ip4_rewrite_set_next(
106*99a2dd95SBruce Richardson 			port_id, rte_node_edge_count(ip4_rewrite_node->id) - 1);
107*99a2dd95SBruce Richardson 		if (rc < 0)
108*99a2dd95SBruce Richardson 			return rc;
109*99a2dd95SBruce Richardson 	}
110*99a2dd95SBruce Richardson 
111*99a2dd95SBruce Richardson 	ctrl.nb_graphs = nb_graphs;
112*99a2dd95SBruce Richardson 	return 0;
113*99a2dd95SBruce Richardson }
114