From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 8D7ED5A6C for ; Sat, 26 Mar 2016 02:28:03 +0100 (CET) Received: by mail-wm0-f67.google.com with SMTP id l68so7244997wml.3 for ; Fri, 25 Mar 2016 18:28:03 -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=YJLY6ivkAolSmVKzvSoD7ngGhIJSIvo71F6/8k2UPkUoKt6fsGbTwmVGe1hFmZ5FWc wRSxrAnJD3dArBKZxYsdNwFt2lrNc9Flz3VWGo1/a6OR/GsiOCgk3sFx3WW/OjnkxKww IPhSMrr4mUtIc8sznbIA01x+4X19tPK6h9BE4VPvdT4kXM+QkCQGAwyNLnlIl+dhcJ3p g+gp3uAY4x4SzAZMsZ89rjnRGCXyZ0W8HFHERICvSgGnFklqosEkP3IPYQCFo5CYuk8u C4hwaPhAgBLmCQTPKvI9eRQg+CA7QLVVYwzQuwjdDbf6pAMddMpZ6vxhKg4VjlihEM8+ Jq7Q== 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=YchtT5n8B5SYoLuwBNLCK0X5GDW4/H7LOhpk4CY5RYqJS1JAOa57kwqZSbTArC5Ufb ppuR1h+Sj2uXxc8LLUcbTJYl2gVrICfL3R6Z74XoG8qS6G7Z2/v9p9CwE0LB3rX8kCBU sVkyEJ3yIaqjPj7ZIP8HkQsg6DTjbMFXzU8jYIlt7r6N02pZ17EVytR//aqxlyN+1CAk 2cDP90Thg6d+MW3U2bMqh+mXaMc8Q+v+I1WZDIkzyFyTX16OVHr02LSC7/+Zzn78p/4K utNY8FaNw1cjPjGAQ47QZm2sXyHPL1SJFB6uudanHM5o4YCUM/O+6ugrp+qiN1XzGRv9 6TBA== X-Gm-Message-State: AD7BkJI4eXRUFQ6ndMAgumhRuGvCauVYaneAa7lxnjgP/aPlDbHPkbuG/1X0ROqVVGG6wg== X-Received: by 10.194.236.170 with SMTP id uv10mr19761475wjc.32.1458955683441; Fri, 25 Mar 2016 18:28:03 -0700 (PDT) Received: from localhost.localdomain (28.red-88-23-79.staticip.rima-tde.net. [88.23.79.28]) by smtp.gmail.com with ESMTPSA id hh8sm14070113wjc.42.2016.03.25.18.28.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Mar 2016 18:28:02 -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: Sat, 26 Mar 2016 02:27:15 +0100 Message-Id: <1458955640-22951-4-git-send-email-marcdevel@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458955640-22951-1-git-send-email-marcdevel@gmail.com> References: <1458934950-23333-1-git-send-email-thomas.monjalon@6wind.com> <1458955640-22951-1-git-send-email-marcdevel@gmail.com> Subject: [dpdk-dev] [PATCH v13 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: Sat, 26 Mar 2016 01:28:03 -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