From 6a34f91690d0b33b9dbfb63ab1f080fbf2879dc6 Mon Sep 17 00:00:00 2001 From: Wang Xiao W Date: Fri, 5 Feb 2016 12:50:23 +0800 Subject: [PATCH] app/testpmd: fix error message when setting Tx VLAN When using testpmd, sometimes we forget the right order of port_id and vid in "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n" command, and input "tx_vlan set 51 0", we'll get a strange prompt saying "Error, as QinQ has been enabled.". In cmd_tx_vlan_set_parsed function, the first thing we do is checking the port's vlan_offload capability, rather than checking validity of the port_id, therefore if it's an invalid port_id we'll get the above wrong message. We should always make sure that we get a valid port_id before we do other things. It's the similar issue for cmd_tx_vlan_set_qinq_parsed function. Fixes: 92ebda07ee58 ("app/testpmd: add qinq stripping and insertion") Signed-off-by: Wang Xiao W Acked-by: Pablo de Lara --- app/test-pmd/cmdline.c | 18 +++--------------- app/test-pmd/config.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index df99a255d8..81ba2bdb6f 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -2954,12 +2954,6 @@ cmd_tx_vlan_set_parsed(void *parsed_result, __attribute__((unused)) void *data) { struct cmd_tx_vlan_set_result *res = parsed_result; - int vlan_offload = rte_eth_dev_get_vlan_offload(res->port_id); - - if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) { - printf("Error, as QinQ has been enabled.\n"); - return; - } tx_vlan_set(res->port_id, res->vlan_id); } @@ -2970,12 +2964,12 @@ cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan = cmdline_parse_token_string_t cmd_tx_vlan_set_set = TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, set, "set"); -cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = - TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, - vlan_id, UINT16); cmdline_parse_token_num_t cmd_tx_vlan_set_portid = TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, port_id, UINT8); +cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = + TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, + vlan_id, UINT16); cmdline_parse_inst_t cmd_tx_vlan_set = { .f = cmd_tx_vlan_set_parsed, @@ -3006,12 +3000,6 @@ cmd_tx_vlan_set_qinq_parsed(void *parsed_result, __attribute__((unused)) void *data) { struct cmd_tx_vlan_set_qinq_result *res = parsed_result; - int vlan_offload = rte_eth_dev_get_vlan_offload(res->port_id); - - if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) { - printf("Error, as QinQ hasn't been enabled.\n"); - return; - } tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer); } diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 0062484fc5..2970f34157 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1839,10 +1839,18 @@ vlan_tpid_set(portid_t port_id, uint16_t tp_id) void tx_vlan_set(portid_t port_id, uint16_t vlan_id) { + int vlan_offload; if (port_id_is_invalid(port_id, ENABLED_WARN)) return; if (vlan_id_is_invalid(vlan_id)) return; + + vlan_offload = rte_eth_dev_get_vlan_offload(port_id); + if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) { + printf("Error, as QinQ has been enabled.\n"); + return; + } + tx_vlan_reset(port_id); ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN; ports[port_id].tx_vlan_id = vlan_id; @@ -1851,12 +1859,20 @@ tx_vlan_set(portid_t port_id, uint16_t vlan_id) void tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer) { + int vlan_offload; if (port_id_is_invalid(port_id, ENABLED_WARN)) return; if (vlan_id_is_invalid(vlan_id)) return; if (vlan_id_is_invalid(vlan_id_outer)) return; + + vlan_offload = rte_eth_dev_get_vlan_offload(port_id); + if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) { + printf("Error, as QinQ hasn't been enabled.\n"); + return; + } + tx_vlan_reset(port_id); ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ; ports[port_id].tx_vlan_id = vlan_id; -- 2.20.1