1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
8 #include <rte_ethdev.h>
13 static struct link_list link_list;
18 TAILQ_INIT(&link_list);
24 link_find(const char *name)
31 TAILQ_FOREACH(link, &link_list, node)
32 if (strcmp(link->name, name) == 0)
38 static struct rte_eth_conf port_conf_default = {
41 .mq_mode = ETH_MQ_RX_NONE,
43 .header_split = 0, /* Header split */
44 .hw_ip_checksum = 0, /* IP checksum offload */
45 .hw_vlan_filter = 0, /* VLAN filtering */
46 .hw_vlan_strip = 0, /* VLAN strip */
47 .hw_vlan_extend = 0, /* Extended VLAN */
48 .jumbo_frame = 0, /* Jumbo frame support */
49 .hw_strip_crc = 1, /* CRC strip by HW */
50 .enable_scatter = 0, /* Scattered packets RX handler */
52 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
53 .split_hdr_size = 0, /* Header split buffer size */
63 .mq_mode = ETH_MQ_TX_NONE,
68 #define RETA_CONF_SIZE (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
71 rss_setup(uint16_t port_id,
73 struct link_params_rss *rss)
75 struct rte_eth_rss_reta_entry64 reta_conf[RETA_CONF_SIZE];
80 memset(reta_conf, 0, sizeof(reta_conf));
82 for (i = 0; i < reta_size; i++)
83 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
85 for (i = 0; i < reta_size; i++) {
86 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
87 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
88 uint32_t rss_qs_pos = i % rss->n_queues;
90 reta_conf[reta_id].reta[reta_pos] =
91 (uint16_t) rss->queue_id[rss_qs_pos];
95 status = rte_eth_dev_rss_reta_update(port_id,
103 link_create(const char *name, struct link_params *params)
105 struct rte_eth_dev_info port_info;
106 struct rte_eth_conf port_conf;
108 struct link_params_rss *rss;
109 struct mempool *mempool;
114 /* Check input params */
115 if ((name == NULL) ||
118 (params->rx.n_queues == 0) ||
119 (params->rx.queue_size == 0) ||
120 (params->tx.n_queues == 0) ||
121 (params->tx.queue_size == 0))
124 port_id = params->port_id;
125 if (params->dev_name) {
126 status = rte_eth_dev_get_port_by_name(params->dev_name,
132 if (!rte_eth_dev_is_valid_port(port_id))
135 rte_eth_dev_info_get(port_id, &port_info);
137 mempool = mempool_find(params->rx.mempool_name);
141 rss = params->rx.rss;
143 if ((port_info.reta_size == 0) ||
144 (port_info.reta_size > ETH_RSS_RETA_SIZE_512))
147 if ((rss->n_queues == 0) ||
148 (rss->n_queues >= LINK_RXQ_RSS_MAX))
151 for (i = 0; i < rss->n_queues; i++)
152 if (rss->queue_id[i] >= port_info.max_rx_queues)
160 memcpy(&port_conf, &port_conf_default, sizeof(port_conf));
162 port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
163 port_conf.rx_adv_conf.rss_conf.rss_hf =
164 ETH_RSS_IPV4 | ETH_RSS_IPV6;
167 cpu_id = (uint32_t) rte_eth_dev_socket_id(port_id);
168 if (cpu_id == (uint32_t) SOCKET_ID_ANY)
171 status = rte_eth_dev_configure(
180 if (params->promiscuous)
181 rte_eth_promiscuous_enable(port_id);
184 for (i = 0; i < params->rx.n_queues; i++) {
185 status = rte_eth_rx_queue_setup(
188 params->rx.queue_size,
198 for (i = 0; i < params->tx.n_queues; i++) {
199 status = rte_eth_tx_queue_setup(
202 params->tx.queue_size,
211 status = rte_eth_dev_start(port_id);
216 status = rss_setup(port_id, port_info.reta_size, rss);
219 rte_eth_dev_stop(port_id);
225 status = rte_eth_dev_set_link_up(port_id);
226 if ((status < 0) && (status != -ENOTSUP)) {
227 rte_eth_dev_stop(port_id);
231 /* Node allocation */
232 link = calloc(1, sizeof(struct link));
234 rte_eth_dev_stop(port_id);
239 strncpy(link->name, name, sizeof(link->name));
240 link->port_id = port_id;
241 link->n_rxq = params->rx.n_queues;
242 link->n_txq = params->tx.n_queues;
244 /* Node add to list */
245 TAILQ_INSERT_TAIL(&link_list, link, node);
251 link_is_up(const char *name)
253 struct rte_eth_link link_params;
256 /* Check input params */
260 link = link_find(name);
265 rte_eth_link_get(link->port_id, &link_params);
267 return (link_params.link_status == ETH_LINK_DOWN) ? 0 : 1;