1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
8 #include <rte_ethdev.h>
9 #include <rte_string_fns.h>
14 static struct link_list link_list;
19 TAILQ_INIT(&link_list);
25 link_find(const char *name)
32 TAILQ_FOREACH(link, &link_list, node)
33 if (strcmp(link->name, name) == 0)
39 static struct rte_eth_conf port_conf_default = {
42 .mq_mode = ETH_MQ_RX_NONE,
43 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
44 .split_hdr_size = 0, /* Header split buffer size */
45 .offloads = DEV_RX_OFFLOAD_CRC_STRIP,
55 .mq_mode = ETH_MQ_TX_NONE,
60 #define RETA_CONF_SIZE (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
63 rss_setup(uint16_t port_id,
65 struct link_params_rss *rss)
67 struct rte_eth_rss_reta_entry64 reta_conf[RETA_CONF_SIZE];
72 memset(reta_conf, 0, sizeof(reta_conf));
74 for (i = 0; i < reta_size; i++)
75 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
77 for (i = 0; i < reta_size; i++) {
78 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
79 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
80 uint32_t rss_qs_pos = i % rss->n_queues;
82 reta_conf[reta_id].reta[reta_pos] =
83 (uint16_t) rss->queue_id[rss_qs_pos];
87 status = rte_eth_dev_rss_reta_update(port_id,
95 link_create(const char *name, struct link_params *params)
97 struct rte_eth_dev_info port_info;
98 struct rte_eth_conf port_conf;
100 struct link_params_rss *rss;
101 struct mempool *mempool;
106 /* Check input params */
107 if ((name == NULL) ||
110 (params->rx.n_queues == 0) ||
111 (params->rx.queue_size == 0) ||
112 (params->tx.n_queues == 0) ||
113 (params->tx.queue_size == 0))
116 port_id = params->port_id;
117 if (params->dev_name) {
118 status = rte_eth_dev_get_port_by_name(params->dev_name,
124 if (!rte_eth_dev_is_valid_port(port_id))
127 rte_eth_dev_info_get(port_id, &port_info);
129 mempool = mempool_find(params->rx.mempool_name);
133 rss = params->rx.rss;
135 if ((port_info.reta_size == 0) ||
136 (port_info.reta_size > ETH_RSS_RETA_SIZE_512))
139 if ((rss->n_queues == 0) ||
140 (rss->n_queues >= LINK_RXQ_RSS_MAX))
143 for (i = 0; i < rss->n_queues; i++)
144 if (rss->queue_id[i] >= port_info.max_rx_queues)
152 memcpy(&port_conf, &port_conf_default, sizeof(port_conf));
154 port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
155 port_conf.rx_adv_conf.rss_conf.rss_hf =
156 ETH_RSS_IPV4 | ETH_RSS_IPV6;
159 cpu_id = (uint32_t) rte_eth_dev_socket_id(port_id);
160 if (cpu_id == (uint32_t) SOCKET_ID_ANY)
163 status = rte_eth_dev_configure(
172 if (params->promiscuous)
173 rte_eth_promiscuous_enable(port_id);
176 for (i = 0; i < params->rx.n_queues; i++) {
177 status = rte_eth_rx_queue_setup(
180 params->rx.queue_size,
190 for (i = 0; i < params->tx.n_queues; i++) {
191 status = rte_eth_tx_queue_setup(
194 params->tx.queue_size,
203 status = rte_eth_dev_start(port_id);
208 status = rss_setup(port_id, port_info.reta_size, rss);
211 rte_eth_dev_stop(port_id);
217 status = rte_eth_dev_set_link_up(port_id);
218 if ((status < 0) && (status != -ENOTSUP)) {
219 rte_eth_dev_stop(port_id);
223 /* Node allocation */
224 link = calloc(1, sizeof(struct link));
226 rte_eth_dev_stop(port_id);
231 strlcpy(link->name, name, sizeof(link->name));
232 link->port_id = port_id;
233 link->n_rxq = params->rx.n_queues;
234 link->n_txq = params->tx.n_queues;
236 /* Node add to list */
237 TAILQ_INSERT_TAIL(&link_list, link, node);
243 link_is_up(const char *name)
245 struct rte_eth_link link_params;
248 /* Check input params */
252 link = link_find(name);
257 rte_eth_link_get(link->port_id, &link_params);
259 return (link_params.link_status == ETH_LINK_DOWN) ? 0 : 1;