Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2020 Marvell International Ltd.
3 : : */
4 : :
5 : : #include <errno.h>
6 : : #include <stdlib.h>
7 : :
8 : : #include <eal_export.h>
9 : : #include <rte_ethdev.h>
10 : : #include <rte_graph.h>
11 : :
12 : : #include "rte_node_eth_api.h"
13 : :
14 : : #include "ethdev_rx_priv.h"
15 : : #include "ethdev_tx_priv.h"
16 : : #include "ip4_rewrite_priv.h"
17 : : #include "ip6_rewrite_priv.h"
18 : : #include "interface_tx_feature_priv.h"
19 : : #include "node_private.h"
20 : :
21 : : static struct ethdev_ctrl {
22 : : uint16_t nb_graphs;
23 : : } ctrl;
24 : :
25 : : RTE_EXPORT_SYMBOL(rte_node_eth_config)
26 : : int
27 : 0 : rte_node_eth_config(struct rte_node_ethdev_config *conf, uint16_t nb_confs,
28 : : uint16_t nb_graphs)
29 : : {
30 : : struct rte_node_register *if_tx_feature_node;
31 : : struct rte_node_register *ip4_rewrite_node;
32 : : struct rte_node_register *ip6_rewrite_node;
33 : : struct ethdev_tx_node_main *tx_node_data;
34 : : uint16_t tx_q_used, rx_q_used, port_id;
35 : : struct rte_node_register *tx_node;
36 : : char name[RTE_NODE_NAMESIZE];
37 : 0 : const char *next_nodes = name;
38 : : struct rte_mempool *mp;
39 : : int i, j, rc;
40 : : uint32_t id;
41 : :
42 : 0 : if_tx_feature_node = if_tx_feature_node_get();
43 : 0 : ip4_rewrite_node = ip4_rewrite_node_get();
44 : 0 : ip6_rewrite_node = ip6_rewrite_node_get();
45 : 0 : tx_node_data = ethdev_tx_node_data_get();
46 : 0 : tx_node = ethdev_tx_node_get();
47 [ # # ]: 0 : for (i = 0; i < nb_confs; i++) {
48 : 0 : port_id = conf[i].port_id;
49 : :
50 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id))
51 : : return -EINVAL;
52 : :
53 : : /* Check for mbuf minimum private size requirement */
54 [ # # ]: 0 : for (j = 0; j < conf[i].mp_count; j++) {
55 : 0 : mp = conf[i].mp[j];
56 [ # # ]: 0 : if (!mp)
57 : 0 : continue;
58 : : /* Check for minimum private space */
59 [ # # ]: 0 : if (rte_pktmbuf_priv_size(mp) < NODE_MBUF_PRIV2_SIZE) {
60 : 0 : node_err("ethdev",
61 : : "Minimum mbuf priv size requirement not met by mp %s",
62 : : mp->name);
63 : 0 : return -EINVAL;
64 : : }
65 : : }
66 : :
67 : 0 : rx_q_used = conf[i].num_rx_queues;
68 : 0 : tx_q_used = conf[i].num_tx_queues;
69 : : /* Check if we have a txq for each worker */
70 [ # # ]: 0 : if (tx_q_used < nb_graphs)
71 : : return -EINVAL;
72 : :
73 : : /* Create node for each rx port queue pair */
74 [ # # ]: 0 : for (j = 0; j < rx_q_used; j++) {
75 : : struct ethdev_rx_node_main *rx_node_data;
76 : : struct rte_node_register *rx_node;
77 : : ethdev_rx_node_elem_t *elem;
78 : :
79 : 0 : rx_node_data = ethdev_rx_get_node_data_get();
80 : 0 : rx_node = ethdev_rx_node_get();
81 : : snprintf(name, sizeof(name), "%u-%u", port_id, j);
82 : : /* Clone a new rx node with same edges as parent */
83 : 0 : id = rte_node_clone(rx_node->id, name);
84 [ # # ]: 0 : if (id == RTE_NODE_ID_INVALID)
85 : : return -EIO;
86 : :
87 : : /* Add it to list of ethdev rx nodes for lookup */
88 : 0 : elem = malloc(sizeof(ethdev_rx_node_elem_t));
89 [ # # ]: 0 : if (elem == NULL)
90 : : return -ENOMEM;
91 : : memset(elem, 0, sizeof(ethdev_rx_node_elem_t));
92 : 0 : elem->ctx.port_id = port_id;
93 : 0 : elem->ctx.queue_id = j;
94 : 0 : elem->ctx.cls_next = ETHDEV_RX_NEXT_PKT_CLS;
95 : 0 : elem->nid = id;
96 : 0 : elem->next = rx_node_data->head;
97 : 0 : rx_node_data->head = elem;
98 : :
99 : 0 : node_dbg("ethdev", "Rx node %s-%s: is at %u",
100 : : rx_node->name, name, id);
101 : : }
102 : :
103 : : /* Create a per port tx node from base node */
104 : : snprintf(name, sizeof(name), "%u", port_id);
105 : : /* Clone a new node with same edges as parent */
106 : 0 : id = rte_node_clone(tx_node->id, name);
107 : 0 : tx_node_data->nodes[port_id] = id;
108 : :
109 : 0 : node_dbg("ethdev", "Tx node %s-%s: is at %u", tx_node->name,
110 : : name, id);
111 : :
112 : : /* Prepare the actual name of the cloned node */
113 : : snprintf(name, sizeof(name), "ethdev_tx-%u", port_id);
114 : :
115 : : /* Add this tx port node as next to ip4_rewrite_node */
116 : 0 : rte_node_edge_update(ip4_rewrite_node->id, RTE_EDGE_ID_INVALID,
117 : : &next_nodes, 1);
118 : : /* Assuming edge id is the last one alloc'ed */
119 : 0 : rc = ip4_rewrite_set_next(
120 : 0 : port_id, rte_node_edge_count(ip4_rewrite_node->id) - 1);
121 [ # # ]: 0 : if (rc < 0)
122 : 0 : return rc;
123 : :
124 : : /* Add this tx port node as next to ip6_rewrite_node */
125 : 0 : rte_node_edge_update(ip6_rewrite_node->id, RTE_EDGE_ID_INVALID,
126 : : &next_nodes, 1);
127 : : /* Assuming edge id is the last one alloc'ed */
128 : 0 : rc = ip6_rewrite_set_next(
129 : 0 : port_id, rte_node_edge_count(ip6_rewrite_node->id) - 1);
130 [ # # ]: 0 : if (rc < 0)
131 : 0 : return rc;
132 : :
133 : : /* Add this tx port node to if_tx_feature_node */
134 : 0 : rte_node_edge_update(if_tx_feature_node->id, RTE_EDGE_ID_INVALID,
135 : : &next_nodes, 1);
136 : 0 : rc = if_tx_feature_node_set_next(port_id,
137 : 0 : rte_node_edge_count(if_tx_feature_node->id) - 1);
138 : : }
139 : :
140 : 0 : ctrl.nb_graphs = nb_graphs;
141 : 0 : return 0;
142 : : }
143 : :
144 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_node_ethdev_rx_next_update, 24.03)
145 : : int
146 : 0 : rte_node_ethdev_rx_next_update(rte_node_t id, const char *edge_name)
147 : : {
148 : : struct ethdev_rx_node_main *data;
149 : : ethdev_rx_node_elem_t *elem;
150 : : char **next_nodes;
151 : : int rc = -EINVAL;
152 : : uint16_t i = 0;
153 : : uint32_t size;
154 : :
155 [ # # ]: 0 : if (edge_name == NULL)
156 : 0 : goto exit;
157 : :
158 : 0 : size = rte_node_edge_get(id, NULL);
159 : :
160 [ # # ]: 0 : if (size == RTE_NODE_ID_INVALID)
161 : 0 : goto exit;
162 : :
163 : 0 : next_nodes = calloc((size / sizeof(char *)) + 1, sizeof(*next_nodes));
164 [ # # ]: 0 : if (next_nodes == NULL) {
165 : : rc = -ENOMEM;
166 : 0 : goto exit;
167 : : }
168 : :
169 : 0 : size = rte_node_edge_get(id, next_nodes);
170 : :
171 [ # # ]: 0 : while (next_nodes[i] != NULL) {
172 [ # # ]: 0 : if (strcmp(edge_name, next_nodes[i]) == 0) {
173 : 0 : data = ethdev_rx_get_node_data_get();
174 : 0 : elem = data->head;
175 [ # # ]: 0 : while (elem->next != data->head) {
176 [ # # ]: 0 : if (elem->nid == id) {
177 : 0 : elem->ctx.cls_next = i;
178 : : rc = 0;
179 : 0 : goto found;
180 : : }
181 : : elem = elem->next;
182 : : }
183 : : }
184 : 0 : i++;
185 : : }
186 : 0 : found:
187 : 0 : free(next_nodes);
188 : 0 : exit:
189 : 0 : return rc;
190 : : }
|