node: add ethdev control
[dpdk.git] / lib / librte_node / ethdev_ctrl.c
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 "node_private.h"
15
16 static struct ethdev_ctrl {
17         uint16_t nb_graphs;
18 } ctrl;
19
20 int
21 rte_node_eth_config(struct rte_node_ethdev_config *conf, uint16_t nb_confs,
22                     uint16_t nb_graphs)
23 {
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         struct rte_mempool *mp;
29         uint32_t id;
30         int i, j;
31
32         tx_node_data = ethdev_tx_node_data_get();
33         tx_node = ethdev_tx_node_get();
34         for (i = 0; i < nb_confs; i++) {
35                 port_id = conf[i].port_id;
36
37                 if (!rte_eth_dev_is_valid_port(port_id))
38                         return -EINVAL;
39
40                 /* Check for mbuf minimum private size requirement */
41                 for (j = 0; j < conf[i].mp_count; j++) {
42                         mp = conf[i].mp[j];
43                         if (!mp)
44                                 continue;
45                         /* Check for minimum private space */
46                         if (rte_pktmbuf_priv_size(mp) < NODE_MBUF_PRIV2_SIZE) {
47                                 node_err("ethdev",
48                                          "Minimum mbuf priv size requirement not met by mp %s",
49                                          mp->name);
50                                 return -EINVAL;
51                         }
52                 }
53
54                 rx_q_used = conf[i].num_rx_queues;
55                 tx_q_used = conf[i].num_tx_queues;
56                 /* Check if we have a txq for each worker */
57                 if (tx_q_used < nb_graphs)
58                         return -EINVAL;
59
60                 /* Create node for each rx port queue pair */
61                 for (j = 0; j < rx_q_used; j++) {
62                         struct ethdev_rx_node_main *rx_node_data;
63                         struct rte_node_register *rx_node;
64                         ethdev_rx_node_elem_t *elem;
65
66                         rx_node_data = ethdev_rx_get_node_data_get();
67                         rx_node = ethdev_rx_node_get();
68                         snprintf(name, sizeof(name), "%u-%u", port_id, j);
69                         /* Clone a new rx node with same edges as parent */
70                         id = rte_node_clone(rx_node->id, name);
71                         if (id == RTE_NODE_ID_INVALID)
72                                 return -EIO;
73
74                         /* Add it to list of ethdev rx nodes for lookup */
75                         elem = malloc(sizeof(ethdev_rx_node_elem_t));
76                         memset(elem, 0, sizeof(ethdev_rx_node_elem_t));
77                         elem->ctx.port_id = port_id;
78                         elem->ctx.queue_id = j;
79                         elem->nid = id;
80                         elem->next = rx_node_data->head;
81                         rx_node_data->head = elem;
82
83                         node_dbg("ethdev", "Rx node %s-%s: is at %u",
84                                  rx_node->name, name, id);
85                 }
86
87                 /* Create a per port tx node from base node */
88                 snprintf(name, sizeof(name), "%u", port_id);
89                 /* Clone a new node with same edges as parent */
90                 id = rte_node_clone(tx_node->id, name);
91                 tx_node_data->nodes[port_id] = id;
92
93                 node_dbg("ethdev", "Tx node %s-%s: is at %u", tx_node->name,
94                          name, id);
95         }
96
97         ctrl.nb_graphs = nb_graphs;
98         return 0;
99 }