From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by dpdk.org (Postfix) with ESMTP id B0A9FD592 for ; Fri, 3 Mar 2017 16:40:28 +0100 (CET) Received: by mail-wm0-f53.google.com with SMTP id v186so18298533wmd.0 for ; Fri, 03 Mar 2017 07:40:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=C0UNpjNQda7rC34b1Fo/XopyPBLEKs6SVAzLQreUcdo=; b=Q4yMwUWpTMg8+FkOuhdScbFySrqAGKBgaSamU/gl8J/NzaED/ecxDPqgX4IsaNMFge cSWpn5G4AV3owEsON9VI+xJexbKuMJWtdoxV2wI1fJsJwLn8YPlfZUHHUTGRIJEjm3GY vXOC5Wy/xxkl6TXcRT7Z30ya8suOVx7n4h9qr4QzBd/rAcQzs8wa6zQky9yzdZY4vt8e U0M0A4+ao70EsZaU5O8gk4VZdtyiZvKwQLcLrYST8WFdHpv0ZkC+YSVNKMAb9uHVq4Ch m+RjdSXTcz7qmiyzFg9Q95K1arGLRj3SrC9oIHoH8ZRH3Jfqx1cidpGaGNXbpdFPHcoD fxzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=C0UNpjNQda7rC34b1Fo/XopyPBLEKs6SVAzLQreUcdo=; b=rZi1MJo1xRgpK4OjpRRR8MR1OSXlgNvivCktS9uoPhPC+kfgGmhyRd5qpRpnZvwMBc 92dhg/YlYRcOQ2G8XctodZUgTTr2iA1bpXUaBkJ5kjNKrWU1vBo4R3quvAEzd0/pU6Np S4B1S+YiYUUQmcDXE3oHuv16JZA1hBbEhNbnxUHO5qfRfrKD2jKvsTH+wGxR97vXY3z2 fWUmcNwvipWEvm8DVyhQqAFVFoRvmBajGjWDS+TxfDCem4m+Z/1QLgoQML6rLpfMy/VK R3rgBhfDu6u1dztZL0iDE2Q/aL9s4gRWfuEzQR2AbjO6URlOurKl2YXdkp/tdXXCpEAv /Y1Q== X-Gm-Message-State: AMke39lSvfQILrSLjAbk2athyAdtJqHOsH0I7adS71r73moZ5UgBLjfx8GFRDlprb9BmL4cA X-Received: by 10.28.191.194 with SMTP id o63mr3583379wmi.101.1488555627880; Fri, 03 Mar 2017 07:40:27 -0800 (PST) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id k195sm3513175wmd.7.2017.03.03.07.40.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 07:40:27 -0800 (PST) From: Gaetan Rivet To: dev@dpdk.org Date: Fri, 3 Mar 2017 16:40:13 +0100 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 4/4] app/testpmd: use ethdev iterator to list devices X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2017 15:40:28 -0000 This commit replaces redundant code with public ethdev layer calls. Signed-off-by: Gaetan Rivet --- app/test-pmd/cmdline.c | 31 +++++++++++++++---------------- app/test-pmd/cmdline_flow.c | 2 +- app/test-pmd/config.c | 12 ++++++------ app/test-pmd/parameters.c | 4 ++-- app/test-pmd/testpmd.c | 44 +++++++++++--------------------------------- app/test-pmd/testpmd.h | 9 --------- 6 files changed, 35 insertions(+), 67 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 43fc636..871ab19 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -1139,7 +1139,7 @@ cmd_config_speed_all_parsed(void *parsed_result, &link_speed) < 0) return; - FOREACH_PORT(pid, ports) { + RTE_ETH_FOREACH_DEV(pid) { ports[pid].dev_conf.link_speeds = link_speed; } @@ -4641,7 +4641,6 @@ static void cmd_create_bonded_device_parsed(void *parsed_result, nb_ports = rte_eth_dev_count(); reconfig(port_id, res->socket); rte_eth_promiscuous_enable(port_id); - ports[port_id].enabled = 1; } } @@ -5000,7 +4999,7 @@ static void cmd_set_promisc_mode_parsed(void *parsed_result, /* all ports */ if (allports) { - FOREACH_PORT(i, ports) { + RTE_ETH_FOREACH_DEV(i) { if (enable) rte_eth_promiscuous_enable(i); else @@ -5080,7 +5079,7 @@ static void cmd_set_allmulti_mode_parsed(void *parsed_result, /* all ports */ if (allports) { - FOREACH_PORT(i, ports) { + RTE_ETH_FOREACH_DEV(i) { if (enable) rte_eth_allmulticast_enable(i); else @@ -5814,31 +5813,31 @@ static void cmd_showportall_parsed(void *parsed_result, 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); } @@ -10315,7 +10314,7 @@ cmd_config_l2_tunnel_eth_type_all_parsed 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); } } @@ -10431,7 +10430,7 @@ cmd_config_l2_tunnel_en_dis_all_parsed( 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, @@ -12601,7 +12600,7 @@ cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 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; diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index ff98690..b7d2c41 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -2369,7 +2369,7 @@ comp_port(struct context *ctx, const struct token *token, (void)ctx; (void)token; - FOREACH_PORT(p, ports) { + RTE_ETH_FOREACH_DEV(p) { if (buf && i == ent) return snprintf(buf, size, "%u", p); ++i; diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 80491fc..54e38c4 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -174,7 +174,7 @@ nic_stats_display(portid_t port_id) 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; @@ -252,7 +252,7 @@ nic_stats_clear(portid_t port_id) 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; @@ -334,7 +334,7 @@ nic_stats_mapping_display(portid_t port_id) 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; @@ -452,7 +452,7 @@ port_infos_display(portid_t port_id) 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; @@ -725,7 +725,7 @@ port_id_is_invalid(portid_t port_id, enum print_warning warning) 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) @@ -2279,7 +2279,7 @@ set_fwd_ports_mask(uint64_t portmask) 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; diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 28db8cd..67d8bf2 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -394,7 +394,7 @@ parse_portnuma_config(const char *q_arg) 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; @@ -454,7 +454,7 @@ parse_ringnuma_config(const char *q_arg) 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; diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index bfb2f8e..b8ec1fe 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -334,20 +334,6 @@ static void check_all_ports_link_status(uint32_t port_mask); 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. */ static void @@ -547,7 +533,7 @@ init_config(void) socket_num); } - FOREACH_PORT(pid, ports) { + RTE_ETH_FOREACH_DEV(pid) { port = &ports[pid]; rte_eth_dev_info_get(pid, &port->dev_info); @@ -632,7 +618,7 @@ init_fwd_streams(void) 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 " @@ -1253,7 +1239,7 @@ all_ports_started(void) 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) && @@ -1271,7 +1257,7 @@ all_ports_stopped(void) 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)) @@ -1319,7 +1305,7 @@ start_port(portid_t pid) 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; @@ -1476,7 +1462,7 @@ stop_port(portid_t pid) printf("Stopping ports...\n"); - FOREACH_PORT(pi, ports) { + RTE_ETH_FOREACH_DEV(pi) { if (pid != pi && pid != (portid_t)RTE_PORT_ALL) continue; @@ -1519,7 +1505,7 @@ close_port(portid_t pid) printf("Closing ports...\n"); - FOREACH_PORT(pi, ports) { + RTE_ETH_FOREACH_DEV(pi) { if (pid != pi && pid != (portid_t)RTE_PORT_ALL) continue; @@ -1574,7 +1560,6 @@ attach_port(char *identifier) 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) @@ -1608,7 +1593,6 @@ detach_port(uint8_t port_id) 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", @@ -1627,7 +1611,7 @@ pmd_test_exit(void) 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); @@ -1658,7 +1642,7 @@ check_all_ports_link_status(uint32_t port_mask) 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)); @@ -1823,7 +1807,7 @@ init_port_config(void) 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; @@ -2047,8 +2031,6 @@ init_port_dcb_config(portid_t pid, static void init_port(void) { - portid_t pid; - /* Configuration of Ethernet ports. */ ports = rte_zmalloc("testpmd: ports", sizeof(struct rte_port) * RTE_MAX_ETHPORTS, @@ -2058,10 +2040,6 @@ init_port(void) "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 @@ -2136,7 +2114,7 @@ main(int argc, char** argv) 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); #ifdef RTE_LIBRTE_CMDLINE diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 8cf2860..e1e4939 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -163,7 +163,6 @@ struct port_flow { * 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 */ @@ -195,14 +194,6 @@ struct rte_port { 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 -- 2.1.4