Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2023 Marvell. 3 : : */ 4 : : 5 : : #include <stdlib.h> 6 : : #include <string.h> 7 : : 8 : : #include <cmdline_parse.h> 9 : : #include <cmdline_parse_num.h> 10 : : #include <cmdline_parse_string.h> 11 : : #include <cmdline_socket.h> 12 : : #include <rte_ethdev.h> 13 : : 14 : : #include "ethdev_rx_priv.h" 15 : : #include "module_api.h" 16 : : 17 : : static const char 18 : : cmd_ethdev_rx_help[] = "ethdev_rx map port <ethdev_name> queue <q_num> core <core_id>"; 19 : : 20 : : static struct lcore_params lcore_params_array[ETHDEV_RX_LCORE_PARAMS_MAX]; 21 : : struct rte_node_ethdev_config ethdev_conf[RTE_MAX_ETHPORTS]; 22 : : struct lcore_params *lcore_params = lcore_params_array; 23 : : struct lcore_conf lcore_conf[RTE_MAX_LCORE]; 24 : : uint16_t nb_lcore_params; 25 : : 26 : : static void 27 : : rx_map_configure(uint8_t port_id, uint32_t queue, uint32_t core) 28 : : { 29 : : uint8_t n_rx_queue; 30 : : 31 : 0 : n_rx_queue = lcore_conf[core].n_rx_queue; 32 : 0 : lcore_conf[core].rx_queue_list[n_rx_queue].port_id = port_id; 33 : 0 : lcore_conf[core].rx_queue_list[n_rx_queue].queue_id = queue; 34 : 0 : lcore_conf[core].n_rx_queue++; 35 : : } 36 : : 37 : : uint8_t 38 : 0 : ethdev_rx_num_rx_queues_get(uint16_t port) 39 : : { 40 : : int queue = -1; 41 : : uint16_t i; 42 : : 43 : 0 : for (i = 0; i < nb_lcore_params; ++i) { 44 : 0 : if (lcore_params[i].port_id == port) { 45 : 0 : if (lcore_params[i].queue_id == queue + 1) 46 : : queue = lcore_params[i].queue_id; 47 : : else 48 : 0 : rte_exit(EXIT_FAILURE, 49 : : "Queue ids of the port %d must be" 50 : : " in sequence and must start with 0\n", 51 : : lcore_params[i].port_id); 52 : : } 53 : : } 54 : : 55 : 0 : return (uint8_t)(++queue); 56 : : } 57 : : 58 : : static int 59 : 0 : ethdev_rx_map_add(char *name, uint32_t queue, uint32_t core) 60 : : { 61 : : uint64_t coremask; 62 : : uint16_t port_id; 63 : : int rc; 64 : : 65 : 0 : if (nb_lcore_params >= ETHDEV_RX_LCORE_PARAMS_MAX) 66 : : return -EINVAL; 67 : : 68 : 0 : rc = rte_eth_dev_get_port_by_name(name, &port_id); 69 : 0 : if (rc) 70 : : return -EINVAL; 71 : : 72 : 0 : coremask = graph_coremask_get(); 73 : : 74 : 0 : if (!(coremask & (1 << core))) 75 : : return -EINVAL; 76 : : 77 : 0 : rx_map_configure(port_id, queue, core); 78 : : 79 : 0 : lcore_params_array[nb_lcore_params].port_id = port_id; 80 : 0 : lcore_params_array[nb_lcore_params].queue_id = queue; 81 : 0 : lcore_params_array[nb_lcore_params].lcore_id = core; 82 : 0 : nb_lcore_params++; 83 : 0 : return 0; 84 : : } 85 : : 86 : : void 87 : 0 : cmd_help_ethdev_rx_parsed(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl, 88 : : __rte_unused void *data) 89 : : { 90 : : size_t len; 91 : : 92 : 0 : len = strlen(conn->msg_out); 93 : 0 : conn->msg_out += len; 94 : 0 : snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n", 95 : : "---------------------------- ethdev_rx command help ----------------------------", 96 : : cmd_ethdev_rx_help); 97 : : 98 : 0 : len = strlen(conn->msg_out); 99 : 0 : conn->msg_out_len_max -= len; 100 : 0 : } 101 : : 102 : : void 103 : 0 : cmd_ethdev_rx_map_port_parsed(void *parsed_result, __rte_unused struct cmdline *cl, 104 : : void *data __rte_unused) 105 : : { 106 : : struct cmd_ethdev_rx_map_port_result *res = parsed_result; 107 : : int rc = -EINVAL; 108 : : 109 : 0 : rc = ethdev_rx_map_add(res->dev, res->qid, res->core_id); 110 : 0 : if (rc < 0) { 111 : 0 : cli_exit(); 112 : 0 : printf(MSG_CMD_FAIL, res->ethdev_rx); 113 : 0 : rte_exit(EXIT_FAILURE, "input core is Invalid\n"); 114 : : } 115 : : 116 : 0 : }