From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f177.google.com (mail-wr0-f177.google.com [209.85.128.177]) by dpdk.org (Postfix) with ESMTP id 2A6572B94 for ; Fri, 31 Mar 2017 14:04:58 +0200 (CEST) Received: by mail-wr0-f177.google.com with SMTP id k6so97655640wre.2 for ; Fri, 31 Mar 2017 05:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=rCnmqkf2EdmQevKP4soN5tqKzojGzZXX+KnRjOqibh8=; b=qJRVtyBbSheAcCgupDCeDPeWAsQUp2/y5FUMWcVXva6aRNBvdhxzj64nThVq+r19RY hjwXhvh4e8ps5N6Yzign2E8i0HhnBYtLoEhFRibfaXRaZublpgThU7XUFQUKYI532zHR Ek884vOR/xmANpuBZDfS5/aSj5tRRKBrCCwFfQDLJPbWovGab+IuINMjRLCMS0RFT9pD RZP1vK/epfn/RpUjBxV6qOY6FERuRway43C5tLs/cDHZaub2L7cO3nJq0xltYNeiODUQ IFrvfOhI3ZptqrcaIRNGED5WOUkpvviUGB7Jk4IuPZoPaTZhbqNp1gPdZkUTUlf9iT3G U3dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=rCnmqkf2EdmQevKP4soN5tqKzojGzZXX+KnRjOqibh8=; b=kVkhnTZ81N7epEz8Z18eZXDwg2ju5Omtq56rJe1PEE5xk/TtiAkBvfQKEwXWhj4PmN YUA6JYzvm2mo2BLLgNd1f2qVi6Q+unYZIueTc1MWB0dF9cHefS1PG4vUD55Jd6JWo5FX EJs8pU1Hd0P/zvk7en5PKayC/7D3spHkfXl6ivd9MMmRa/g+cfcX469uwRHknF0fsDO/ 2+p9nYcSnDksDS9cegrWdNFqGpm2ArdLQSlHFuG2hbsAAk86+wxtthKuOLtektQDHWde dfKTEx/PWrRs3Jn9cO6nETek0/Gv9a/oNa+D0AgSlR//GieJIIt+NYiIccATOy6ZH2su i7pg== X-Gm-Message-State: AFeK/H3WiBVwADCnUSYIab3I6RsZRDl57ygEc9QgF3dhVObbNaKWkxZkRUh7WJCAJM/IaBq1 X-Received: by 10.223.139.5 with SMTP id n5mr2695653wra.200.1490961898532; Fri, 31 Mar 2017 05:04:58 -0700 (PDT) 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 l41sm6487536wrl.59.2017.03.31.05.04.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 31 Mar 2017 05:04:57 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Thomas Monjalon , Jingjing Wu Date: Fri, 31 Mar 2017 14:04:39 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 3/3] 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, 31 Mar 2017 12:04:59 -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 aac4efb..cf5da4b 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -1160,7 +1160,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; } @@ -4662,7 +4662,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; } } @@ -5021,7 +5020,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 @@ -5101,7 +5100,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 @@ -5835,31 +5834,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); } @@ -10339,7 +10338,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); } } @@ -10455,7 +10454,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, @@ -13114,7 +13113,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 2149df4..4e99f0f 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -2416,7 +2416,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 780ce6b..9d05e01 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) @@ -2281,7 +2281,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 484c19b..b27822b 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; @@ -2036,8 +2020,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, @@ -2047,10 +2029,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 @@ -2125,7 +2103,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 5c18151..011f4b5 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