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