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
rx_map_configure(uint8_t port_id,uint32_t queue,uint32_t core)27 rx_map_configure(uint8_t port_id, uint32_t queue, uint32_t core)
28 {
29 uint8_t n_rx_queue;
30
31 n_rx_queue = lcore_conf[core].n_rx_queue;
32 lcore_conf[core].rx_queue_list[n_rx_queue].port_id = port_id;
33 lcore_conf[core].rx_queue_list[n_rx_queue].queue_id = queue;
34 lcore_conf[core].n_rx_queue++;
35 }
36
37 uint8_t
ethdev_rx_num_rx_queues_get(uint16_t port)38 ethdev_rx_num_rx_queues_get(uint16_t port)
39 {
40 int queue = -1;
41 uint16_t i;
42
43 for (i = 0; i < nb_lcore_params; ++i) {
44 if (lcore_params[i].port_id == port) {
45 if (lcore_params[i].queue_id == queue + 1)
46 queue = lcore_params[i].queue_id;
47 else
48 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 return (uint8_t)(++queue);
56 }
57
58 static int
ethdev_rx_map_add(char * name,uint32_t queue,uint32_t core)59 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 if (nb_lcore_params >= ETHDEV_RX_LCORE_PARAMS_MAX)
66 return -EINVAL;
67
68 rc = rte_eth_dev_get_port_by_name(name, &port_id);
69 if (rc)
70 return -EINVAL;
71
72 coremask = graph_coremask_get();
73
74 if (!(coremask & (1 << core)))
75 return -EINVAL;
76
77 rx_map_configure(port_id, queue, core);
78
79 lcore_params_array[nb_lcore_params].port_id = port_id;
80 lcore_params_array[nb_lcore_params].queue_id = queue;
81 lcore_params_array[nb_lcore_params].lcore_id = core;
82 nb_lcore_params++;
83 return 0;
84 }
85
86 void
cmd_help_ethdev_rx_parsed(__rte_unused void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)87 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 len = strlen(conn->msg_out);
93 conn->msg_out += len;
94 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 len = strlen(conn->msg_out);
99 conn->msg_out_len_max -= len;
100 }
101
102 void
cmd_ethdev_rx_map_port_parsed(void * parsed_result,__rte_unused struct cmdline * cl,void * data __rte_unused)103 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 rc = ethdev_rx_map_add(res->dev, res->qid, res->core_id);
110 if (rc < 0) {
111 cli_exit();
112 printf(MSG_CMD_FAIL, res->ethdev_rx);
113 rte_exit(EXIT_FAILURE, "input core is Invalid\n");
114 }
115
116 }
117