app/testpmd: move flow control parser
[dpdk.git] / app / test-pmd / cmdline.c
index 8c35825..e1ba338 100644 (file)
@@ -286,6 +286,9 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "    Set hardware insertion of VLAN ID in packets sent"
                        " on a port.\n\n"
 
+                       "tx_vlan set pvid port_id vlan_id (on|off)\n"
+                       "    Set port based TX VLAN insertion.\n\n"
+
                        "tx_vlan reset (port_id)\n"
                        "    Disable hardware insertion of a VLAN header in"
                        " packets sent on a port.\n\n"
@@ -323,7 +326,7 @@ static void cmd_help_long_parsed(void *parsed_result,
 
                        "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
                        " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
-                        " (on|off) (port_id)\n"
+                       " (on|off) autoneg (on|off) (port_id)\n"
                        "    Set the link flow control parameter on a port.\n\n"
 
                        "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
@@ -524,6 +527,8 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "port config all (txfreet|txrst|rxfreet) (value)\n"
                        "    Set free threshold for rx/tx, or set"
                        " tx rs bit threshold.\n\n"
+                       "port config mtu X value\n"
+                       "    Set the MTU of port X to a given value\n\n"
                );
        }
 
@@ -1083,6 +1088,57 @@ cmdline_parse_inst_t cmd_config_max_pkt_len = {
        },
 };
 
+/* *** configure port MTU *** */
+struct cmd_config_mtu_result {
+       cmdline_fixed_string_t port;
+       cmdline_fixed_string_t keyword;
+       cmdline_fixed_string_t mtu;
+       uint8_t port_id;
+       uint16_t value;
+};
+
+static void
+cmd_config_mtu_parsed(void *parsed_result,
+                     __attribute__((unused)) struct cmdline *cl,
+                     __attribute__((unused)) void *data)
+{
+       struct cmd_config_mtu_result *res = parsed_result;
+
+       if (res->value < ETHER_MIN_LEN) {
+               printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
+               return;
+       }
+       port_mtu_set(res->port_id, res->value);
+}
+
+cmdline_parse_token_string_t cmd_config_mtu_port =
+       TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
+                                "port");
+cmdline_parse_token_string_t cmd_config_mtu_keyword =
+       TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
+                                "config");
+cmdline_parse_token_string_t cmd_config_mtu_mtu =
+       TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
+                                "mtu");
+cmdline_parse_token_num_t cmd_config_mtu_port_id =
+       TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
+cmdline_parse_token_num_t cmd_config_mtu_value =
+       TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
+
+cmdline_parse_inst_t cmd_config_mtu = {
+       .f = cmd_config_mtu_parsed,
+       .data = NULL,
+       .help_str = "port config mtu value",
+       .tokens = {
+               (void *)&cmd_config_mtu_port,
+               (void *)&cmd_config_mtu_keyword,
+               (void *)&cmd_config_mtu_mtu,
+               (void *)&cmd_config_mtu_port_id,
+               (void *)&cmd_config_mtu_value,
+               NULL,
+       },
+};
+
 /* *** configure rx mode *** */
 struct cmd_config_rx_mode_flag {
        cmdline_fixed_string_t port;
@@ -1201,9 +1257,9 @@ cmd_config_rss_parsed(void *parsed_result,
        uint8_t i;
 
        if (!strcmp(res->value, "ip"))
-               rss_conf.rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6;
+               rss_conf.rss_hf = ETH_RSS_IP;
        else if (!strcmp(res->value, "udp"))
-               rss_conf.rss_hf = ETH_RSS_IPV4_UDP | ETH_RSS_IPV6_UDP;
+               rss_conf.rss_hf = ETH_RSS_UDP;
        else if (!strcmp(res->value, "none"))
                rss_conf.rss_hf = 0;
        else {
@@ -1311,7 +1367,7 @@ cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
                                 "config");
-cmdline_parse_token_string_t cmd_config_rss_hash_key_port_id =
+cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
        TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
@@ -1370,7 +1426,7 @@ parse_reta_config(const char *str, struct rte_eth_rss_reta *reta_conf)
                if(size >= sizeof(s))
                        return -1;
 
-               rte_snprintf(s, sizeof(s), "%.*s", size, p);
+               snprintf(s, sizeof(s), "%.*s", size, p);
                if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
                        return -1;
                for (i = 0; i < _NUM_FLD; i++) {
@@ -2421,6 +2477,63 @@ cmdline_parse_inst_t cmd_tx_vlan_set = {
        },
 };
 
+/* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
+struct cmd_tx_vlan_set_pvid_result {
+       cmdline_fixed_string_t tx_vlan;
+       cmdline_fixed_string_t set;
+       cmdline_fixed_string_t pvid;
+       uint8_t port_id;
+       uint16_t vlan_id;
+       cmdline_fixed_string_t mode;
+};
+
+static void
+cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
+                           __attribute__((unused)) struct cmdline *cl,
+                           __attribute__((unused)) void *data)
+{
+       struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
+
+       if (strcmp(res->mode, "on") == 0)
+               tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
+       else
+               tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
+}
+
+cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
+       TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
+                                tx_vlan, "tx_vlan");
+cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
+       TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
+                                set, "set");
+cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
+       TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
+                                pvid, "pvid");
+cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
+       TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
+                            port_id, UINT8);
+cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
+       TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
+                             vlan_id, UINT16);
+cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
+       TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
+                                mode, "on#off");
+
+cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
+       .f = cmd_tx_vlan_set_pvid_parsed,
+       .data = NULL,
+       .help_str = "tx_vlan set pvid port_id vlan_id (on|off)",
+       .tokens = {
+               (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
+               (void *)&cmd_tx_vlan_set_pvid_set,
+               (void *)&cmd_tx_vlan_set_pvid_pvid,
+               (void *)&cmd_tx_vlan_set_pvid_port_id,
+               (void *)&cmd_tx_vlan_set_pvid_vlan_id,
+               (void *)&cmd_tx_vlan_set_pvid_mode,
+               NULL,
+       },
+};
+
 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
 struct cmd_tx_vlan_reset_result {
        cmdline_fixed_string_t tx_vlan;
@@ -2962,7 +3075,7 @@ static void cmd_set_fwd_mode_init(void)
        cmdline_parse_token_string_t *token_struct;
 
        modes = list_pkt_forwarding_modes();
-       rte_snprintf(help, sizeof help, "set fwd %s - "
+       snprintf(help, sizeof help, "set fwd %s - "
                "set packet forwarding mode", modes);
        cmd_set_fwd_mode.help_str = help;
 
@@ -3701,6 +3814,8 @@ struct cmd_link_flow_ctrl_set_result {
        cmdline_fixed_string_t tx_lfc_mode;
        cmdline_fixed_string_t mac_ctrl_frame_fwd;
        cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
+       cmdline_fixed_string_t autoneg_str;
+       cmdline_fixed_string_t autoneg;
        uint32_t high_water;
        uint32_t low_water;
        uint16_t pause_time;
@@ -3708,42 +3823,6 @@ struct cmd_link_flow_ctrl_set_result {
        uint8_t  port_id;
 };
 
-static void
-cmd_link_flow_ctrl_set_parsed(void *parsed_result,
-                      __attribute__((unused)) struct cmdline *cl,
-                      __attribute__((unused)) void *data)
-{
-       struct cmd_link_flow_ctrl_set_result *res = parsed_result;
-       struct rte_eth_fc_conf fc_conf;
-       int rx_fc_enable, tx_fc_enable, mac_ctrl_frame_fwd;
-       int ret;
-
-       /*
-        * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
-        * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
-        * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
-        * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
-        */
-       static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
-                       {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
-       };
-
-       rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
-       tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
-       mac_ctrl_frame_fwd = (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) ? 1 : 0;
-
-       fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
-       fc_conf.high_water = res->high_water;
-       fc_conf.low_water  = res->low_water;
-       fc_conf.pause_time = res->pause_time;
-       fc_conf.send_xon   = res->send_xon;
-       fc_conf.mac_ctrl_frame_fwd = (uint8_t)mac_ctrl_frame_fwd;
-
-       ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
-       if (ret != 0)
-               printf("bad flow contrl parameter, return code = %d \n", ret);
-}
-
 cmdline_parse_token_string_t cmd_lfc_set_set =
        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
                                set, "set");
@@ -3780,6 +3859,12 @@ cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
                                mac_ctrl_frame_fwd_mode, "on#off");
+cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
+       TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
+                               autoneg_str, "autoneg");
+cmdline_parse_token_string_t cmd_lfc_set_autoneg =
+       TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
+                               autoneg, "on#off");
 cmdline_parse_token_num_t cmd_lfc_set_portid =
        TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
                                port_id, UINT8);
@@ -3789,7 +3874,7 @@ cmdline_parse_inst_t cmd_link_flow_control_set = {
        .data = NULL,
        .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
-port_id",
+autoneg on|off port_id",
        .tokens = {
                (void *)&cmd_lfc_set_set,
                (void *)&cmd_lfc_set_flow_ctrl,
@@ -3803,11 +3888,50 @@ port_id",
                (void *)&cmd_lfc_set_send_xon,
                (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
                (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
+               (void *)&cmd_lfc_set_autoneg_str,
+               (void *)&cmd_lfc_set_autoneg,
                (void *)&cmd_lfc_set_portid,
                NULL,
        },
 };
 
+static void
+cmd_link_flow_ctrl_set_parsed(void *parsed_result,
+                      __attribute__((unused)) struct cmdline *cl,
+                      __attribute__((unused)) void *data)
+{
+       struct cmd_link_flow_ctrl_set_result *res = parsed_result;
+       struct rte_eth_fc_conf fc_conf;
+       int rx_fc_enable, tx_fc_enable, mac_ctrl_frame_fwd;
+       int ret;
+
+       /*
+        * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
+        * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
+        * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
+        * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
+        */
+       static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
+                       {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
+       };
+
+       rx_fc_enable = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
+       tx_fc_enable = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
+       mac_ctrl_frame_fwd = (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) ? 1 : 0;
+
+       fc_conf.mode       = rx_tx_onoff_2_lfc_mode[rx_fc_enable][tx_fc_enable];
+       fc_conf.high_water = res->high_water;
+       fc_conf.low_water  = res->low_water;
+       fc_conf.pause_time = res->pause_time;
+       fc_conf.send_xon   = res->send_xon;
+       fc_conf.mac_ctrl_frame_fwd = (uint8_t)mac_ctrl_frame_fwd;
+       fc_conf.autoneg    = (!strcmp(res->autoneg, "on")) ? 1 : 0;
+
+       ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
+       if (ret != 0)
+               printf("bad flow contrl parameter, return code = %d \n", ret);
+}
+
 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
 struct cmd_priority_flow_ctrl_set_result {
        cmdline_fixed_string_t set;
@@ -5254,7 +5378,7 @@ cmdline_parse_token_string_t cmd_mirror_mask_set =
 cmdline_parse_token_string_t cmd_mirror_mask_port =
        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
                                port, "port");
-cmdline_parse_token_string_t cmd_mirror_mask_portid =
+cmdline_parse_token_num_t cmd_mirror_mask_portid =
        TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
                                port_id, UINT8);
 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
@@ -5364,7 +5488,7 @@ cmdline_parse_token_string_t cmd_mirror_link_set =
 cmdline_parse_token_string_t cmd_mirror_link_port =
        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
                                port, "port");
-cmdline_parse_token_string_t cmd_mirror_link_portid =
+cmdline_parse_token_num_t cmd_mirror_link_portid =
        TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
                                port_id, UINT8);
 cmdline_parse_token_string_t cmd_mirror_link_mirror =
@@ -5450,7 +5574,7 @@ cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
        TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
                                port, "port");
-cmdline_parse_token_string_t cmd_rm_mirror_rule_portid =
+cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
        TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
                                port_id, UINT8);
 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
@@ -5759,7 +5883,7 @@ cmd_set_syn_filter_parsed(void *parsed_result,
                printf("syn filter setting error: (%s)\n", strerror(-ret));
 
 }
-cmdline_parse_token_string_t cmd_syn_filter_portid =
+cmdline_parse_token_num_t cmd_syn_filter_portid =
        TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
                                port_id, UINT8);
 cmdline_parse_token_string_t cmd_syn_filter_priority =
@@ -5877,7 +6001,7 @@ cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
        TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
                                 protocol, "protocol");
-cmdline_parse_token_string_t cmd_2tuple_filter_protocol_value =
+cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
        TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
                                 protocol_value, UINT8);
 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_mask =
@@ -5895,7 +6019,7 @@ cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_mask =
 cmdline_parse_token_string_t cmd_2tuple_filter_flags =
        TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
                                flags, "flags");
-cmdline_parse_token_string_t cmd_2tuple_filter_flags_value =
+cmdline_parse_token_num_t cmd_2tuple_filter_flags_value =
        TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
                                flags_value, UINT8);
 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
@@ -6089,7 +6213,7 @@ cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
        TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
                                protocol, "protocol");
-cmdline_parse_token_string_t cmd_5tuple_filter_protocol_value =
+cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
        TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
                                protocol_value, UINT8);
 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
@@ -6335,7 +6459,7 @@ cmdline_parse_token_num_t cmd_flex_filter_port_id =
 cmdline_parse_token_string_t cmd_flex_filter_len =
        TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
                                len, "len");
-cmdline_parse_token_string_t cmd_flex_filter_len_value =
+cmdline_parse_token_num_t cmd_flex_filter_len_value =
        TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
                                len_value, UINT8);
 cmdline_parse_token_string_t cmd_flex_filter_bytes =
@@ -6465,6 +6589,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
        (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
        (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
+       (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
        (cmdline_parse_inst_t *)&cmd_tx_cksum_set,
        (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
        (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
@@ -6492,6 +6617,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_config_speed_all,
        (cmdline_parse_inst_t *)&cmd_config_speed_specific,
        (cmdline_parse_inst_t *)&cmd_config_rx_tx,
+       (cmdline_parse_inst_t *)&cmd_config_mtu,
        (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
        (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
        (cmdline_parse_inst_t *)&cmd_config_rss,