From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by dpdk.org (Postfix) with ESMTP id BB4B2590B for ; Thu, 17 Mar 2016 19:10:46 +0100 (CET) Received: by mail-wm0-f50.google.com with SMTP id l68so5498609wml.1 for ; Thu, 17 Mar 2016 11:10:46 -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=lSVs61pCMQ/wFls67TAF1DH7PI6inQ6cSPpGdfTzcFQ=; b=yk6pfiVvblTnvAsL1nJ79vnm5iZ1BFr4wUADDMutrM9r5GHJD9GIg6fmEz6PWS7qdT K7gjtrgvdADBRYfdbU4Xc9WkaYA0By5p4fJ56ZhFVgicN8oruQ9QB8lEd4dnj/wEz88G HtnE6s/eM4h9CXZ8RFqGsMoEs6LvgSBesPe7lMdfkzViKY4he7I9EccuGitJK7K+Saqh yQ4H2Dtoma3IBz0RyEVimqAYbjfZypD1eBlLKOuHENAJi1Zu4ICIj0LV3DgjfekBHe+y XRZn6iJlP9kVJw4Xk5ujMnAV1wEKhnJyamGm2EpVmOynWILYlDN3gav00Sxs2SGgZmcY k9QA== 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=lSVs61pCMQ/wFls67TAF1DH7PI6inQ6cSPpGdfTzcFQ=; b=kyH2IUfcdSeLtgWT3qkxxiZiIp+lSboH82t8PkPWMyIurdLC20N9EXmNE9bIygLayV z7vh39l1+Ip0nnYOkkO3tt5xi4hgcHhYJnufKjYjxPv2XsvcGhLQH/wQ6gEQzQjjq0cA ayKgwxn7g0LJKccM6gc6TVuZRWO/P6KPUdPlTYvSxYHga6rjbsYmhYZOirRDRF4g1tUI KJElBzhv5iaYALQUOZH5pOAhNUtiOUEsXBjzQqeCkEn+RH6bN5eOH9Qfc6sPbYqgdr5I mxQTV+U6mCeXXFtbfE+lzBwmxH6aPAvkVvyzdHQq79DJQ3yeycAbQDzLKCzFnHcr6QUE 0Yzw== X-Gm-Message-State: AD7BkJLhC1upnt5h169iGwbR8PM5WRtITPEhcriJ+51IDxIcRObd6f75QAE7swhKAn/9hwvf X-Received: by 10.194.82.66 with SMTP id g2mr11317781wjy.161.1458238246564; Thu, 17 Mar 2016 11:10:46 -0700 (PDT) Received: from XPS13.localdomain (91.111.75.86.rev.sfr.net. [86.75.111.91]) by smtp.gmail.com with ESMTPSA id u14sm31196179wmu.8.2016.03.17.11.10.44 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 Mar 2016 11:10:46 -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: Thu, 17 Mar 2016 19:09:00 +0100 Message-Id: <1458238145-7496-4-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1458238145-7496-1-git-send-email-thomas.monjalon@6wind.com> References: <1457992546-32230-1-git-send-email-thomas.monjalon@6wind.com> <1458238145-7496-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-dev] [PATCH v11 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: Thu, 17 Mar 2016 18:10:47 -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 9d52b8c..37be5cd 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -983,6 +983,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, @@ -998,33 +1041,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; @@ -1097,33 +1116,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