LCOV - code coverage report
Current view: top level - lib/node - ethdev_ctrl.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 71 0.0 %
Date: 2025-05-01 17:49:45 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 36 0.0 %

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

Generated by: LCOV version 1.14