From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by dpdk.org (Postfix) with ESMTP id 1A6035683 for ; Fri, 25 Mar 2016 20:44:37 +0100 (CET) Received: by mail-wm0-f41.google.com with SMTP id u125so27119440wmg.1 for ; Fri, 25 Mar 2016 12:44:37 -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; bh=GgPj07HrllsuDGZZwRGsmtu8fqc4TRnrzjwK1BDkZmE=; b=q6HevxcBi9qLB+Mn7pXwIEtmQg2Mx0odHBD2DT6qHUtyhViY0JqLyuh58uI/mGTIOx brWHcrspy/RIzwwV8CwS8wjDrMgM2SyHPK1p0CTtA3nJ904C53u7sYbHWtyGOqjTJA19 MZCFPIQjqpQU+Z9NKMeCIeBnaY0j+LHjd7AUwAl4tyxxapYNXSCOy/zt6LjhyBgJISy4 lmKJgYaDplW2q/rgipLaU+unQOxJCd1HsANQnhKeomycS1Ni9jKsYLPbbvU+9cQ3d0dc hSAqP8bFv4xc9XGr0qBiGsG4V8UTPJm8twFUIpakMoaO8jwmgvFQwqDOgR5tk8jm0MID WvOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GgPj07HrllsuDGZZwRGsmtu8fqc4TRnrzjwK1BDkZmE=; b=C3g1thwvxor4IMvwV49gVpmKbBiX+GDuKwGnq0Jv42J01tvIZihz/8wFX5ffBZxib/ 9vnyzmWbgtg4mIEUxCSopIJgFbAXWWdsWGyfMPXGQ87uomDapmpp+oUXpxmu5Ipb+YJy JG0GbsWlBJaZ4yegMpKQEkukYigVRHpCNqrPaYDmLuZnF3AuPaU5Y/Qyy+t6vHWnarwO TslHrt3ZHcOw8zNbl+sBtGZagNpFJ2se/YadKvTdKIVt6LxDR1tVmDllWZkSmJJn+Zpy UjCdaUAC+SNmAPopq2mnpifyRKGXd1Gd6zzX5rpbR1e3UkqSJNG5QhfhwnnV1mGyWDXd sBfA== X-Gm-Message-State: AD7BkJJ6mCX/fQam2zRj6FyFopyFpStZ2ptaH1/phxEY1Qzw1kNYPIOjKt1CGySjJqpbGTVt X-Received: by 10.28.9.71 with SMTP id 68mr178149wmj.33.1458935076963; Fri, 25 Mar 2016 12:44:36 -0700 (PDT) Received: from XPS13.localdomain (91.111.75.86.rev.sfr.net. [86.75.111.91]) by smtp.gmail.com with ESMTPSA id u4sm13240660wjz.4.2016.03.25.12.44.34 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 25 Mar 2016 12:44:36 -0700 (PDT) From: Thomas Monjalon To: marcdevel@gmail.com, bruce.richardson@intel.com, declan.doherty@intel.com, konstantin.ananyev@intel.com, wenzhuo.lu@intel.com, helin.zhang@intel.com, jing.d.chen@intel.com, harish.patil@qlogic.com, rahul.lakkireddy@chelsio.com, johndale@cisco.com, vido@cesnet.cz, adrien.mazarguil@6wind.com, alejandro.lucero@netronome.com Cc: dev@dpdk.org Date: Fri, 25 Mar 2016 20:42:25 +0100 Message-Id: <1458934950-23333-4-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1458934950-23333-1-git-send-email-thomas.monjalon@6wind.com> References: <1458238145-7496-1-git-send-email-thomas.monjalon@6wind.com> <1458934950-23333-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-dev] [PATCH v12 3/8] app/testpmd: move speed and duplex parsing in a function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Mar 2016 19:44:37 -0000 From: Marc Sune The code for checking and parsing speed/duplex was duplicated. The new function is also checking the speed/duplex combination. Signed-off-by: Marc Sune --- app/test-pmd/cmdline.c | 99 ++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 93203f4..eb7bbb4 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -988,6 +988,49 @@ struct cmd_config_speed_all { cmdline_fixed_string_t value2; }; +static int +parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint16_t *speed) +{ + + int duplex; + + if (!strcmp(duplexstr, "half")) { + duplex = ETH_LINK_HALF_DUPLEX; + } else if (!strcmp(duplexstr, "full")) { + duplex = ETH_LINK_FULL_DUPLEX; + } else if (!strcmp(duplexstr, "auto")) { + duplex = ETH_LINK_FULL_DUPLEX; + } else { + printf("Unknown duplex parameter\n"); + return -1; + } + + if (!strcmp(speedstr, "10")) { + *speed = ETH_LINK_SPEED_10; + } else if (!strcmp(speedstr, "100")) { + *speed = ETH_LINK_SPEED_100; + } else { + if (duplex != ETH_LINK_FULL_DUPLEX) { + printf("Invalid speed/duplex parameters\n"); + return -1; + } + if (!strcmp(speedstr, "1000")) { + *speed = ETH_LINK_SPEED_1000; + } else if (!strcmp(speedstr, "10000")) { + *speed = ETH_LINK_SPEED_10G; + } else if (!strcmp(speedstr, "40000")) { + *speed = ETH_LINK_SPEED_40G; + } else if (!strcmp(speedstr, "auto")) { + *speed = ETH_LINK_SPEED_AUTONEG; + } else { + printf("Unknown speed parameter\n"); + return -1; + } + } + + return 0; +} + static void cmd_config_speed_all_parsed(void *parsed_result, __attribute__((unused)) struct cmdline *cl, @@ -1003,33 +1046,9 @@ cmd_config_speed_all_parsed(void *parsed_result, return; } - if (!strcmp(res->value1, "10")) - link_speed = ETH_LINK_SPEED_10; - else if (!strcmp(res->value1, "100")) - link_speed = ETH_LINK_SPEED_100; - else if (!strcmp(res->value1, "1000")) - link_speed = ETH_LINK_SPEED_1000; - else if (!strcmp(res->value1, "10000")) - link_speed = ETH_LINK_SPEED_10G; - else if (!strcmp(res->value1, "40000")) - link_speed = ETH_LINK_SPEED_40G; - else if (!strcmp(res->value1, "auto")) - link_speed = ETH_LINK_SPEED_AUTONEG; - else { - printf("Unknown parameter\n"); + if (parse_and_check_speed_duplex(res->value1, res->value2, + &link_speed) < 0) return; - } - - if (!strcmp(res->value2, "half")) - link_duplex = ETH_LINK_HALF_DUPLEX; - else if (!strcmp(res->value2, "full")) - link_duplex = ETH_LINK_FULL_DUPLEX; - else if (!strcmp(res->value2, "auto")) - link_duplex = ETH_LINK_AUTONEG_DUPLEX; - else { - printf("Unknown parameter\n"); - return; - } FOREACH_PORT(pid, ports) { ports[pid].dev_conf.link_speed = link_speed; @@ -1102,33 +1121,9 @@ cmd_config_speed_specific_parsed(void *parsed_result, if (port_id_is_invalid(res->id, ENABLED_WARN)) return; - if (!strcmp(res->value1, "10")) - link_speed = ETH_LINK_SPEED_10; - else if (!strcmp(res->value1, "100")) - link_speed = ETH_LINK_SPEED_100; - else if (!strcmp(res->value1, "1000")) - link_speed = ETH_LINK_SPEED_1000; - else if (!strcmp(res->value1, "10000")) - link_speed = ETH_LINK_SPEED_10000; - else if (!strcmp(res->value1, "40000")) - link_speed = ETH_LINK_SPEED_40G; - else if (!strcmp(res->value1, "auto")) - link_speed = ETH_LINK_SPEED_AUTONEG; - else { - printf("Unknown parameter\n"); - return; - } - - if (!strcmp(res->value2, "half")) - link_duplex = ETH_LINK_HALF_DUPLEX; - else if (!strcmp(res->value2, "full")) - link_duplex = ETH_LINK_FULL_DUPLEX; - else if (!strcmp(res->value2, "auto")) - link_duplex = ETH_LINK_AUTONEG_DUPLEX; - else { - printf("Unknown parameter\n"); + if (parse_and_check_speed_duplex(res->value1, res->value2, + &link_speed) < 0) return; - } ports[res->id].dev_conf.link_speed = link_speed; ports[res->id].dev_conf.link_duplex = link_duplex; -- 2.7.0