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