From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id 2CEA7532D for ; Mon, 14 Mar 2016 22:57:23 +0100 (CET) Received: by mail-wm0-f42.google.com with SMTP id l68so1691170wml.1 for ; Mon, 14 Mar 2016 14:57:23 -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=Osg65I2kGUS0twJ3b5QU0H9ZwW3caUUXvwAjTMOqkpGmuUM0JRYlwHiGSRcY53QpeT 3EIR/b+4mbEbK7FUI19m02rtZxxCnFZ14PHCfkDVkm5SMGjaUB3iy7KzkWxM98a9mP9B DlA/l1TKefpvUSfh+fR5YJyVZ1nZy+17PPWJCd2oWpAk1kk507hry+Rr1fJpSFVetoaL V8mSLNvkoLJdmAGxws1aY+L2Acr7TLNsZVAOwcsWZC+ewU08JLTa3bf/ZpAEvnpFD1M+ Qbg2QtQAVR/afUayal2LbEDdmAFZelsz5Zo/R36qR6vJk+aZ27xZXIhEEVXtUX77J763 USrw== 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=WqRszOgqpvUByul3L/zLE0O1Wf6H0WbpFHOarhZASEuQ5UfK9qQd0GIJNgxpFKj0Db uOpo+lywGInl12RwGYJNJkl6yF22cUXjNZv36NFZr4vtw8F5fJUxOg4TfbgVA4Psg1RX 5i0CENr4M+gzftueMKDqdtThthr5g+v3zgym7lzydRoln/MQiuevyy2vxNprTNVvCf0s KLb5+3xZOEHyscNGyLR75DYSubEKExl2dOTDbxfOiyiYenQdg/T0wPDSHa64KQ+mrw5r IIsWpW5BWngAEaBUuMDVZJEJtvRbYHkSKlaKaJ7bw8jsNMGw+roIn9ybZsMHDhNp2DVj BQPQ== X-Gm-Message-State: AD7BkJLZ+SU6jiGBp1azuG+yewec7RkkYlD84X2TcYCHxmYpK8Nql+Lqed22lx8vyvHAPLgj X-Received: by 10.194.185.144 with SMTP id fc16mr26745142wjc.123.1457992643060; Mon, 14 Mar 2016 14:57:23 -0700 (PDT) Received: from XPS13.localdomain (91.111.75.86.rev.sfr.net. [86.75.111.91]) by smtp.gmail.com with ESMTPSA id w133sm17918804wmd.3.2016.03.14.14.57.21 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Mar 2016 14:57:22 -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: Mon, 14 Mar 2016 22:55:41 +0100 Message-Id: <1457992546-32230-4-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1457992546-32230-1-git-send-email-thomas.monjalon@6wind.com> References: <1456793151-1475-1-git-send-email-marcdevel@gmail.com> <1457992546-32230-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-dev] [PATCH v10 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: Mon, 14 Mar 2016 21:57:23 -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