This commit replaces redundant code with public ethdev layer calls.
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
&link_speed) < 0)
return;
- FOREACH_PORT(pid, ports) {
+ RTE_ETH_FOREACH_DEV(pid) {
ports[pid].dev_conf.link_speeds = link_speed;
}
nb_ports = rte_eth_dev_count();
reconfig(port_id, res->socket);
rte_eth_promiscuous_enable(port_id);
- ports[port_id].enabled = 1;
}
}
/* all ports */
if (allports) {
- FOREACH_PORT(i, ports) {
+ RTE_ETH_FOREACH_DEV(i) {
if (enable)
rte_eth_promiscuous_enable(i);
else
/* all ports */
if (allports) {
- FOREACH_PORT(i, ports) {
+ RTE_ETH_FOREACH_DEV(i) {
if (enable)
rte_eth_allmulticast_enable(i);
else
struct cmd_showportall_result *res = parsed_result;
if (!strcmp(res->show, "clear")) {
if (!strcmp(res->what, "stats"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
nic_stats_clear(i);
else if (!strcmp(res->what, "xstats"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
nic_xstats_clear(i);
} else if (!strcmp(res->what, "info"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
port_infos_display(i);
else if (!strcmp(res->what, "stats"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
nic_stats_display(i);
else if (!strcmp(res->what, "xstats"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
nic_xstats_display(i);
else if (!strcmp(res->what, "fdir"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
fdir_get_infos(i);
else if (!strcmp(res->what, "stat_qmap"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
nic_stats_mapping_display(i);
else if (!strcmp(res->what, "dcb_tc"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
port_dcb_info_display(i);
else if (!strcmp(res->what, "cap"))
- FOREACH_PORT(i, ports)
+ RTE_ETH_FOREACH_DEV(i)
port_offload_cap_display(i);
}
entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
entry.ether_type = res->eth_type_val;
- FOREACH_PORT(pid, ports) {
+ RTE_ETH_FOREACH_DEV(pid) {
rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
}
}
else
en = 0;
- FOREACH_PORT(pid, ports) {
+ RTE_ETH_FOREACH_DEV(pid) {
rte_eth_dev_l2_tunnel_offload_set(pid,
&entry,
ETH_L2_TUNNEL_ENABLE_MASK,
if (id == (portid_t)RTE_PORT_ALL) {
portid_t pid;
- FOREACH_PORT(pid, ports) {
+ RTE_ETH_FOREACH_DEV(pid) {
/* check if need_reconfig has been set to 1 */
if (ports[pid].need_reconfig == 0)
ports[pid].need_reconfig = dev;
(void)ctx;
(void)token;
- FOREACH_PORT(p, ports) {
+ RTE_ETH_FOREACH_DEV(p) {
if (buf && i == ent)
return snprintf(buf, size, "%u", p);
++i;
if (port_id_is_invalid(port_id, ENABLED_WARN)) {
printf("Valid port range is [0");
- FOREACH_PORT(pid, ports)
+ RTE_ETH_FOREACH_DEV(pid)
printf(", %d", pid);
printf("]\n");
return;
if (port_id_is_invalid(port_id, ENABLED_WARN)) {
printf("Valid port range is [0");
- FOREACH_PORT(pid, ports)
+ RTE_ETH_FOREACH_DEV(pid)
printf(", %d", pid);
printf("]\n");
return;
if (port_id_is_invalid(port_id, ENABLED_WARN)) {
printf("Valid port range is [0");
- FOREACH_PORT(pid, ports)
+ RTE_ETH_FOREACH_DEV(pid)
printf(", %d", pid);
printf("]\n");
return;
if (port_id_is_invalid(port_id, ENABLED_WARN)) {
printf("Valid port range is [0");
- FOREACH_PORT(pid, ports)
+ RTE_ETH_FOREACH_DEV(pid)
printf(", %d", pid);
printf("]\n");
return;
if (port_id == (portid_t)RTE_PORT_ALL)
return 0;
- if (port_id < RTE_MAX_ETHPORTS && ports[port_id].enabled)
+ if (rte_eth_dev_is_valid_port(port_id))
return 0;
if (warning == ENABLED_WARN)
return;
}
nb_pt = 0;
- for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
+ RTE_ETH_FOREACH_DEV(i) {
if (! ((uint64_t)(1ULL << i) & portmask))
continue;
portlist[nb_pt++] = i;
port_id = (uint8_t)int_fld[FLD_PORT];
if (port_id_is_invalid(port_id, ENABLED_WARN)) {
printf("Valid port range is [0");
- FOREACH_PORT(pid, ports)
+ RTE_ETH_FOREACH_DEV(pid)
printf(", %d", pid);
printf("]\n");
return -1;
port_id = (uint8_t)int_fld[FLD_PORT];
if (port_id_is_invalid(port_id, ENABLED_WARN)) {
printf("Valid port range is [0");
- FOREACH_PORT(pid, ports)
+ RTE_ETH_FOREACH_DEV(pid)
printf(", %d", pid);
printf("]\n");
return -1;
*/
static int all_ports_started(void);
-/*
- * Find next enabled port
- */
-portid_t
-find_next_port(portid_t p, struct rte_port *ports, int size)
-{
- if (ports == NULL)
- rte_exit(-EINVAL, "failed to find a next port id\n");
-
- while ((p < size) && (ports[p].enabled == 0))
- p++;
- return p;
-}
-
/*
* Setup default configuration.
*/
socket_num);
}
- FOREACH_PORT(pid, ports) {
+ RTE_ETH_FOREACH_DEV(pid) {
port = &ports[pid];
rte_eth_dev_info_get(pid, &port->dev_info);
queueid_t q;
/* set socket id according to numa or not */
- FOREACH_PORT(pid, ports) {
+ RTE_ETH_FOREACH_DEV(pid) {
port = &ports[pid];
if (nb_rxq > port->dev_info.max_rx_queues) {
printf("Fail: nb_rxq(%d) is greater than "
portid_t pi;
struct rte_port *port;
- FOREACH_PORT(pi, ports) {
+ RTE_ETH_FOREACH_DEV(pi) {
port = &ports[pi];
/* Check if there is a port which is not started */
if ((port->port_status != RTE_PORT_STARTED) &&
portid_t pi;
struct rte_port *port;
- FOREACH_PORT(pi, ports) {
+ RTE_ETH_FOREACH_DEV(pi) {
port = &ports[pi];
if ((port->port_status != RTE_PORT_STOPPED) &&
(port->slave_flag == 0))
if(dcb_config)
dcb_test = 1;
- FOREACH_PORT(pi, ports) {
+ RTE_ETH_FOREACH_DEV(pi) {
if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
continue;
printf("Stopping ports...\n");
- FOREACH_PORT(pi, ports) {
+ RTE_ETH_FOREACH_DEV(pi) {
if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
continue;
printf("Closing ports...\n");
- FOREACH_PORT(pi, ports) {
+ RTE_ETH_FOREACH_DEV(pi) {
if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
continue;
if (rte_eth_dev_attach(identifier, &pi))
return;
- ports[pi].enabled = 1;
socket_id = (unsigned)rte_eth_dev_socket_id(pi);
/* if socket_id is invalid, set to 0 */
if (check_socket_id(socket_id) < 0)
if (rte_eth_dev_detach(port_id, name))
return;
- ports[port_id].enabled = 0;
nb_ports = rte_eth_dev_count();
printf("Port '%s' is detached. Now total ports is %d\n",
if (ports != NULL) {
no_link_check = 1;
- FOREACH_PORT(pt_id, ports) {
+ RTE_ETH_FOREACH_DEV(pt_id) {
printf("\nShutting down port %d...\n", pt_id);
fflush(stdout);
stop_port(pt_id);
fflush(stdout);
for (count = 0; count <= MAX_CHECK_TIME; count++) {
all_ports_up = 1;
- FOREACH_PORT(portid, ports) {
+ RTE_ETH_FOREACH_DEV(portid) {
if ((port_mask & (1 << portid)) == 0)
continue;
memset(&link, 0, sizeof(link));
portid_t pid;
struct rte_port *port;
- FOREACH_PORT(pid, ports) {
+ RTE_ETH_FOREACH_DEV(pid) {
port = &ports[pid];
port->dev_conf.rxmode = rx_mode;
port->dev_conf.fdir_conf = fdir_conf;
static void
init_port(void)
{
- portid_t pid;
-
/* Configuration of Ethernet ports. */
ports = rte_zmalloc("testpmd: ports",
sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
"rte_zmalloc(%d struct rte_port) failed\n",
RTE_MAX_ETHPORTS);
}
-
- /* enabled allocated ports */
- for (pid = 0; pid < nb_ports; pid++)
- ports[pid].enabled = 1;
}
static void
rte_exit(EXIT_FAILURE, "Start ports failed\n");
/* set all ports to promiscuous mode by default */
- FOREACH_PORT(port_id, ports)
+ RTE_ETH_FOREACH_DEV(port_id)
rte_eth_promiscuous_enable(port_id);
/* Init metrics library */
* The data structure associated with each port.
*/
struct rte_port {
- uint8_t enabled; /**< Port enabled or not */
struct rte_eth_dev_info dev_info; /**< PCI info + driver name */
struct rte_eth_conf dev_conf; /**< Port configuration. */
struct ether_addr eth_addr; /**< Port ethernet address */
struct port_flow *flow_list; /**< Associated flows. */
};
-extern portid_t __rte_unused
-find_next_port(portid_t p, struct rte_port *ports, int size);
-
-#define FOREACH_PORT(p, ports) \
- for (p = find_next_port(0, ports, RTE_MAX_ETHPORTS); \
- p < RTE_MAX_ETHPORTS; \
- p = find_next_port(p + 1, ports, RTE_MAX_ETHPORTS))
-
/**
* The data structure associated with each forwarding logical core.
* The logical cores are internally numbered by a core index from 0 to