From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 9D8E8960A for ; Fri, 1 Apr 2016 00:12:46 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id p65so94247wmp.1 for ; Thu, 31 Mar 2016 15:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ltd07U/QOq3g14q7UMdkHpNdwIJ6ENvTahBlOpnhz4s=; b=xwZ/8QJ3yV9/nCw1Xc6XG9lD5GbGqMPGKdXMOEkRMPq7uXHP329if/TSdVPK6urIBS giiqOfM3oiM2cj3TEQYWVQb/Dl2LWRl4/R3+IiFwfIfwIqChJaU5pjV+jt+EyJn6Worp P0PKif8y8zqrv7Aa/zcmZJI/sqGpNdE8tnY22cIMi+/+ylMBq7s/PSaI5b/Y6ibSj8Yz tie6tQsN0xQiXumc3PHuXxVdxBZOPXRebzCDbK0e5BMRlO8XoZ3j2SUwavKUfsfHy7Wf ia5Jf+CuXrR1neDm0eUmjlDqJuRbixL3A2iABckz8tnerxUfEzO+6gxSof2CqEHChttO 82Dg== 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=ltd07U/QOq3g14q7UMdkHpNdwIJ6ENvTahBlOpnhz4s=; b=LbecDZShYxnfhV+N9UYmJ5QKidQyJo6Am8CYwN3iGmVoRSwcOK5OTj9NC6MdC/qFfq BYombKSebkRXpA+fYINQYAxzQRzyTCd6yc3IvL0DUoRcx2G+wfnkDnO+7vsW0KLzzpNw 7WF47LmcB2hRSMIClRB2TgXD7UaDS/RicPBmj1vW7MVuAQMHcxlfuwyLQmUqi1Md+9R+ v+nYZ87ohuw2FeE6UX6IoAtwTnsNUNuagxZ5QjIxy5jk7W4r17xRaVlB/hPuKaj6yLbv QI9Yu2+OQVhHTPuQiaBADzLcuPquU8K3I2UCnb9Kj4cQWtXJ9nyygSSr4h9u5xGZ35+t z+NQ== X-Gm-Message-State: AD7BkJJ7JqrLKho6uhfoG/uRb0PEaFviJFEnYyekcUrNz7M7VAxqyEUmt3X03spIPf/ceQ== X-Received: by 10.194.222.234 with SMTP id qp10mr5505878wjc.138.1459462366410; Thu, 31 Mar 2016 15:12:46 -0700 (PDT) Received: from localhost.localdomain (149.red-83-32-179.dynamicip.rima-tde.net. [83.32.179.149]) by smtp.gmail.com with ESMTPSA id m13sm11495604wma.3.2016.03.31.15.12.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Mar 2016 15:12:45 -0700 (PDT) From: Marc Sune To: Thomas Monjalon , "Xu, Qian Q" , "Xing, Beilei" , "dev@dpdk.org" , "Ananyev, Konstantin" , "Lu, Wenzhuo" , "Richardson, Bruce" , "Glynn, Michael J" Cc: Marc Sune Date: Fri, 1 Apr 2016 00:12:26 +0200 Message-Id: <1459462351-1120-4-git-send-email-marcdevel@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1459462351-1120-1-git-send-email-marcdevel@gmail.com> References: <1458955640-22951-1-git-send-email-marcdevel@gmail.com> <1459462351-1120-1-git-send-email-marcdevel@gmail.com> Subject: [dpdk-dev] [PATCH v14 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, 31 Mar 2016 22:12:46 -0000 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.1.4