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