From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 169BFAFCD for ; Wed, 28 May 2014 09:15:11 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 28 May 2014 00:15:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.98,926,1392192000"; d="scan'208";a="546008092" Received: from shilc102.sh.intel.com ([10.239.39.44]) by fmsmga002.fm.intel.com with ESMTP; 28 May 2014 00:15:21 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shilc102.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s4S7FH19025071; Wed, 28 May 2014 15:15:19 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s4S7FEGF030296; Wed, 28 May 2014 15:15:16 +0800 Received: (from couyang@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s4S7FEtA030292; Wed, 28 May 2014 15:15:14 +0800 From: Ouyang Changchun To: dev@dpdk.org Date: Wed, 28 May 2014 15:15:02 +0800 Message-Id: <1401261302-30140-4-git-send-email-changchun.ouyang@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1401261302-30140-1-git-send-email-changchun.ouyang@intel.com> References: <1401261302-30140-1-git-send-email-changchun.ouyang@intel.com> Subject: [dpdk-dev] [PATCH v2 3/3] testpmd: Add commands to test link up and down of PMD 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: Wed, 28 May 2014 07:15:12 -0000 Please ignore previous patch v1, and just apply this patch v2. This patch adds commands to test the functionality of setting link up and down of PMD in testpmd. Signed-off-by: Ouyang Changchun --- app/test-pmd/cmdline.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.c | 14 +++++++++ app/test-pmd/testpmd.h | 2 ++ 3 files changed, 97 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index b3824f9..29bf5b5 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -3780,6 +3780,85 @@ cmdline_parse_inst_t cmd_start_tx_first = { }, }; +/* *** SET LINK UP *** */ +struct cmd_set_link_up_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t link_up; + cmdline_fixed_string_t port; + uint8_t port_id; +}; + +cmdline_parse_token_string_t cmd_set_link_up_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set"); +cmdline_parse_token_string_t cmd_set_link_up_link_up = + TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up, + "link-up"); +cmdline_parse_token_string_t cmd_set_link_up_port = + TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); +cmdline_parse_token_num_t cmd_set_link_up_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8); + +static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_link_up_result *res = parsed_result; + dev_set_link_up(res->port_id); +} + +cmdline_parse_inst_t cmd_set_link_up = { + .f = cmd_set_link_up_parsed, + .data = NULL, + .help_str = "set link-up port (port id)", + .tokens = { + (void *)&cmd_set_link_up_set, + (void *)&cmd_set_link_up_link_up, + (void *)&cmd_set_link_up_port, + (void *)&cmd_set_link_up_port_id, + NULL, + }, +}; + +/* *** SET LINK DOWN *** */ +struct cmd_set_link_down_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t link_down; + cmdline_fixed_string_t port; + uint8_t port_id; +}; + +cmdline_parse_token_string_t cmd_set_link_down_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set"); +cmdline_parse_token_string_t cmd_set_link_down_link_down = + TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down, + "link-down"); +cmdline_parse_token_string_t cmd_set_link_down_port = + TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); +cmdline_parse_token_num_t cmd_set_link_down_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8); + +static void cmd_set_link_down_parsed( + __attribute__((unused)) void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_link_down_result *res = parsed_result; + dev_set_link_down(res->port_id); +} + +cmdline_parse_inst_t cmd_set_link_down = { + .f = cmd_set_link_down_parsed, + .data = NULL, + .help_str = "set link-down port (port id)", + .tokens = { + (void *)&cmd_set_link_down_set, + (void *)&cmd_set_link_down_link_down, + (void *)&cmd_set_link_down_port, + (void *)&cmd_set_link_down_port_id, + NULL, + }, +}; + /* *** SHOW CFG *** */ struct cmd_showcfg_result { cmdline_fixed_string_t show; @@ -5164,6 +5243,8 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_showcfg, (cmdline_parse_inst_t *)&cmd_start, (cmdline_parse_inst_t *)&cmd_start_tx_first, + (cmdline_parse_inst_t *)&cmd_set_link_up, + (cmdline_parse_inst_t *)&cmd_set_link_down, (cmdline_parse_inst_t *)&cmd_reset, (cmdline_parse_inst_t *)&cmd_set_numbers, (cmdline_parse_inst_t *)&cmd_set_txpkts, diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index bc38305..8f20fda 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1208,6 +1208,20 @@ stop_packet_forwarding(void) test_done = 1; } +void +dev_set_link_up(portid_t pid) +{ + if (rte_eth_dev_set_link_up((uint8_t)pid) < 0) + printf("\nSet link up fail.\n"); +} + +void +dev_set_link_down(portid_t pid) +{ + if (rte_eth_dev_set_link_down((uint8_t)pid) < 0) + printf("\nSet link down fail.\n"); +} + static int all_ports_started(void) { diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 2bdb1a2..88a29e9 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -499,6 +499,8 @@ char *list_pkt_forwarding_modes(void); void set_pkt_forwarding_mode(const char *fwd_mode); void start_packet_forwarding(int with_tx_first); void stop_packet_forwarding(void); +void dev_set_link_up(portid_t pid); +void dev_set_link_down(portid_t pid); void init_port_config(void); int init_port_dcb_config(portid_t pid,struct dcb_config *dcb_conf); int start_port(portid_t pid); -- 1.9.0