app/testpmd: fix invalid Tx queue number setting
[dpdk.git] / app / test-pmd / cmdline.c
index dc105ab..f7d5bb0 100644 (file)
@@ -89,6 +89,9 @@
 #include <rte_eth_bond.h>
 #include <rte_eth_bond_8023ad.h>
 #endif
+#ifdef RTE_LIBRTE_DPAA_PMD
+#include <rte_pmd_dpaa.h>
+#endif
 #ifdef RTE_LIBRTE_IXGBE_PMD
 #include <rte_pmd_ixgbe.h>
 #endif
@@ -884,6 +887,15 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "port config (port_id) pctype mapping update"
                        " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
                        "    Update a flow type to pctype mapping item on a port\n\n"
+
+                       "port config (port_id) pctype (pctype_id) hash_inset|"
+                       "fdir_inset|fdir_flx_inset get|set|clear field\n"
+                       " (field_idx)\n"
+                       "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
+
+                       "port config (port_id) pctype (pctype_id) hash_inset|"
+                       "fdir_inset|fdir_flx_inset clear all"
+                       "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
                );
        }
 
@@ -999,6 +1011,11 @@ static void cmd_help_long_parsed(void *parsed_result,
                        " queue (queue_id) fd_id (fd_id_value)\n"
                        "    Add/Del a Tunnel flow director filter.\n\n"
 
+                       "flow_director_filter (port_id) mode raw (add|del|update)"
+                       " flow (flow_id) (drop|fwd) queue (queue_id)"
+                       " fd_id (fd_id_value) packet (packet file name)\n"
+                       "    Add/Del a raw type flow director filter.\n\n"
+
                        "flush_flow_director (port_id)\n"
                        "    Flush all flow director entries of a device.\n\n"
 
@@ -1521,6 +1538,8 @@ cmd_config_rx_tx_parsed(void *parsed_result,
                        printf("Warning: Either rx or tx queues should be non zero\n");
                        return;
                }
+               if (check_nb_rxq(res->value) != 0)
+                       return;
                nb_rxq = res->value;
        }
        else if (!strcmp(res->name, "txq")) {
@@ -1528,6 +1547,8 @@ cmd_config_rx_tx_parsed(void *parsed_result,
                        printf("Warning: Either rx or tx queues should be non zero\n");
                        return;
                }
+               if (check_nb_txq(res->value) != 0)
+                       return;
                nb_txq = res->value;
        }
        else if (!strcmp(res->name, "rxd")) {
@@ -9878,6 +9899,8 @@ struct cmd_flow_director_result {
        cmdline_fixed_string_t tunnel_type;
        cmdline_fixed_string_t tunnel_id;
        uint32_t tunnel_id_value;
+       cmdline_fixed_string_t packet;
+       char filepath[];
 };
 
 static inline int
@@ -10027,8 +10050,62 @@ cmd_flow_director_filter_parsed(void *parsed_result,
                        return;
                }
        } else {
-               if (strcmp(res->mode_value, "IP")) {
-                       printf("Please set mode to IP.\n");
+               if (!strcmp(res->mode_value, "raw")) {
+#ifdef RTE_LIBRTE_I40E_PMD
+                       struct rte_pmd_i40e_flow_type_mapping
+                                       mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
+                       struct rte_pmd_i40e_pkt_template_conf conf;
+                       uint16_t flow_type = str2flowtype(res->flow_type);
+                       uint16_t i, port = res->port_id;
+                       uint8_t add;
+
+                       memset(&conf, 0, sizeof(conf));
+
+                       if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
+                               printf("Invalid flow type specified.\n");
+                               return;
+                       }
+                       ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
+                                                                mapping);
+                       if (ret)
+                               return;
+                       if (mapping[flow_type].pctype == 0ULL) {
+                               printf("Invalid flow type specified.\n");
+                               return;
+                       }
+                       for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
+                               if (mapping[flow_type].pctype & (1ULL << i)) {
+                                       conf.input.pctype = i;
+                                       break;
+                               }
+                       }
+
+                       conf.input.packet = open_file(res->filepath,
+                                               &conf.input.length);
+                       if (!conf.input.packet)
+                               return;
+                       if (!strcmp(res->drop, "drop"))
+                               conf.action.behavior =
+                                       RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
+                       else
+                               conf.action.behavior =
+                                       RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
+                       conf.action.report_status =
+                                       RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
+                       conf.action.rx_queue = res->queue_id;
+                       conf.soft_id = res->fd_id_value;
+                       add  = strcmp(res->ops, "del") ? 1 : 0;
+                       ret = rte_pmd_i40e_flow_add_del_packet_template(port,
+                                                                       &conf,
+                                                                       add);
+                       if (ret < 0)
+                               printf("flow director config error: (%s)\n",
+                                      strerror(-ret));
+                       close_file(conf.input.packet);
+#endif
+                       return;
+               } else if (strcmp(res->mode_value, "IP")) {
+                       printf("Please set mode to IP or raw.\n");
                        return;
                }
                entry.input.flow_type = str2flowtype(res->flow_type);
@@ -10200,8 +10277,7 @@ cmdline_parse_token_string_t cmd_flow_director_flow =
                                 flow, "flow");
 cmdline_parse_token_string_t cmd_flow_director_flow_type =
        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
-               flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
-               "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
+               flow_type, NULL);
 cmdline_parse_token_string_t cmd_flow_director_ether =
        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
                                 ether, "ether");
@@ -10293,6 +10369,9 @@ cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
                                 mode_value, "Tunnel");
+cmdline_parse_token_string_t cmd_flow_director_mode_raw =
+       TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
+                                mode_value, "raw");
 cmdline_parse_token_string_t cmd_flow_director_mac =
        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
                                 mac, "mac");
@@ -10311,6 +10390,12 @@ cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
                              tunnel_id_value, UINT32);
+cmdline_parse_token_string_t cmd_flow_director_packet =
+       TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
+                                packet, "packet");
+cmdline_parse_token_string_t cmd_flow_director_filepath =
+       TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
+                                filepath, NULL);
 
 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
        .f = cmd_flow_director_filter_parsed,
@@ -10514,6 +10599,30 @@ cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
        },
 };
 
+cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
+       .f = cmd_flow_director_filter_parsed,
+       .data = NULL,
+       .help_str = "flow_director_filter ... : Add or delete a raw flow "
+               "director entry on NIC",
+       .tokens = {
+               (void *)&cmd_flow_director_filter,
+               (void *)&cmd_flow_director_port_id,
+               (void *)&cmd_flow_director_mode,
+               (void *)&cmd_flow_director_mode_raw,
+               (void *)&cmd_flow_director_ops,
+               (void *)&cmd_flow_director_flow,
+               (void *)&cmd_flow_director_flow_type,
+               (void *)&cmd_flow_director_drop,
+               (void *)&cmd_flow_director_queue,
+               (void *)&cmd_flow_director_queue_id,
+               (void *)&cmd_flow_director_fd_id,
+               (void *)&cmd_flow_director_fd_id_value,
+               (void *)&cmd_flow_director_packet,
+               (void *)&cmd_flow_director_filepath,
+               NULL,
+       },
+};
+
 struct cmd_flush_flow_director_result {
        cmdline_fixed_string_t flush_flow_director;
        portid_t port_id;
@@ -12729,6 +12838,10 @@ cmd_set_tx_loopback_parsed(
        if (ret == -ENOTSUP)
                ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
 #endif
+#ifdef RTE_LIBRTE_DPAA_PMD
+       if (ret == -ENOTSUP)
+               ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
+#endif
 
        switch (ret) {
        case 0:
@@ -14348,7 +14461,7 @@ cmd_ddp_add_parsed(
        }
        file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
 
-       buff = open_ddp_package_file(file_fld[0], &size);
+       buff = open_file(file_fld[0], &size);
        if (!buff) {
                free((void *)filepath);
                return;
@@ -14366,9 +14479,9 @@ cmd_ddp_add_parsed(
        else if (ret < 0)
                printf("Failed to load profile.\n");
        else if (file_num == 2)
-               save_ddp_package_file(file_fld[1], buff, size);
+               save_file(file_fld[1], buff, size);
 
-       close_ddp_package_file(buff);
+       close_file(buff);
        free((void *)filepath);
 }
 
@@ -14423,7 +14536,7 @@ cmd_ddp_del_parsed(
                return;
        }
 
-       buff = open_ddp_package_file(res->filepath, &size);
+       buff = open_file(res->filepath, &size);
        if (!buff)
                return;
 
@@ -14439,7 +14552,7 @@ cmd_ddp_del_parsed(
        else if (ret < 0)
                printf("Failed to delete profile.\n");
 
-       close_ddp_package_file(buff);
+       close_file(buff);
 }
 
 cmdline_parse_inst_t cmd_ddp_del = {
@@ -14499,7 +14612,7 @@ cmd_ddp_info_parsed(
 
 #endif
 
-       pkg = open_ddp_package_file(res->filepath, &pkg_size);
+       pkg = open_file(res->filepath, &pkg_size);
        if (!pkg)
                return;
 
@@ -14676,7 +14789,7 @@ no_print_return:
 #endif
        if (ret == -ENOTSUP)
                printf("Function not supported in PMD driver\n");
-       close_ddp_package_file(pkg);
+       close_file(pkg);
 }
 
 cmdline_parse_inst_t cmd_ddp_get_info = {
@@ -14780,6 +14893,237 @@ cmdline_parse_inst_t cmd_ddp_get_list = {
        },
 };
 
+/* Configure input set */
+struct cmd_cfg_input_set_result {
+       cmdline_fixed_string_t port;
+       cmdline_fixed_string_t cfg;
+       portid_t port_id;
+       cmdline_fixed_string_t pctype;
+       uint8_t pctype_id;
+       cmdline_fixed_string_t inset_type;
+       cmdline_fixed_string_t opt;
+       cmdline_fixed_string_t field;
+       uint8_t field_idx;
+};
+
+static void
+cmd_cfg_input_set_parsed(
+       void *parsed_result,
+       __attribute__((unused)) struct cmdline *cl,
+       __attribute__((unused)) void *data)
+{
+       struct cmd_cfg_input_set_result *res = parsed_result;
+#ifdef RTE_LIBRTE_I40E_PMD
+       enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
+       struct rte_pmd_i40e_inset inset;
+#endif
+       int ret = -ENOTSUP;
+
+       if (res->port_id > nb_ports) {
+               printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
+               return;
+       }
+
+       if (!all_ports_stopped()) {
+               printf("Please stop all ports first\n");
+               return;
+       }
+
+#ifdef RTE_LIBRTE_I40E_PMD
+       if (!strcmp(res->inset_type, "hash_inset"))
+               inset_type = INSET_HASH;
+       else if (!strcmp(res->inset_type, "fdir_inset"))
+               inset_type = INSET_FDIR;
+       else if (!strcmp(res->inset_type, "fdir_flx_inset"))
+               inset_type = INSET_FDIR_FLX;
+       ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
+                                    &inset, inset_type);
+       if (ret) {
+               printf("Failed to get input set.\n");
+               return;
+       }
+
+       if (!strcmp(res->opt, "get")) {
+               ret = rte_pmd_i40e_inset_field_get(inset.inset,
+                                                  res->field_idx);
+               if (ret)
+                       printf("Field index %d is enabled.\n", res->field_idx);
+               else
+                       printf("Field index %d is disabled.\n", res->field_idx);
+               return;
+       } else if (!strcmp(res->opt, "set"))
+               ret = rte_pmd_i40e_inset_field_set(&inset.inset,
+                                                  res->field_idx);
+       else if (!strcmp(res->opt, "clear"))
+               ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
+                                                    res->field_idx);
+       if (ret) {
+               printf("Failed to configure input set field.\n");
+               return;
+       }
+
+       ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
+                                    &inset, inset_type);
+       if (ret) {
+               printf("Failed to set input set.\n");
+               return;
+       }
+#endif
+
+       if (ret == -ENOTSUP)
+               printf("Function not supported\n");
+}
+
+cmdline_parse_token_string_t cmd_cfg_input_set_port =
+       TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
+                                port, "port");
+cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
+       TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
+                                cfg, "config");
+cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
+       TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
+                             port_id, UINT16);
+cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
+       TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
+                                pctype, "pctype");
+cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
+       TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
+                             pctype_id, UINT8);
+cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
+       TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
+                                inset_type,
+                                "hash_inset#fdir_inset#fdir_flx_inset");
+cmdline_parse_token_string_t cmd_cfg_input_set_opt =
+       TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
+                                opt, "get#set#clear");
+cmdline_parse_token_string_t cmd_cfg_input_set_field =
+       TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
+                                field, "field");
+cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
+       TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
+                             field_idx, UINT8);
+
+cmdline_parse_inst_t cmd_cfg_input_set = {
+       .f = cmd_cfg_input_set_parsed,
+       .data = NULL,
+       .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
+                   "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
+       .tokens = {
+               (void *)&cmd_cfg_input_set_port,
+               (void *)&cmd_cfg_input_set_cfg,
+               (void *)&cmd_cfg_input_set_port_id,
+               (void *)&cmd_cfg_input_set_pctype,
+               (void *)&cmd_cfg_input_set_pctype_id,
+               (void *)&cmd_cfg_input_set_inset_type,
+               (void *)&cmd_cfg_input_set_opt,
+               (void *)&cmd_cfg_input_set_field,
+               (void *)&cmd_cfg_input_set_field_idx,
+               NULL,
+       },
+};
+
+/* Clear input set */
+struct cmd_clear_input_set_result {
+       cmdline_fixed_string_t port;
+       cmdline_fixed_string_t cfg;
+       portid_t port_id;
+       cmdline_fixed_string_t pctype;
+       uint8_t pctype_id;
+       cmdline_fixed_string_t inset_type;
+       cmdline_fixed_string_t clear;
+       cmdline_fixed_string_t all;
+};
+
+static void
+cmd_clear_input_set_parsed(
+       void *parsed_result,
+       __attribute__((unused)) struct cmdline *cl,
+       __attribute__((unused)) void *data)
+{
+       struct cmd_clear_input_set_result *res = parsed_result;
+#ifdef RTE_LIBRTE_I40E_PMD
+       enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
+       struct rte_pmd_i40e_inset inset;
+#endif
+       int ret = -ENOTSUP;
+
+       if (res->port_id > nb_ports) {
+               printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
+               return;
+       }
+
+       if (!all_ports_stopped()) {
+               printf("Please stop all ports first\n");
+               return;
+       }
+
+#ifdef RTE_LIBRTE_I40E_PMD
+       if (!strcmp(res->inset_type, "hash_inset"))
+               inset_type = INSET_HASH;
+       else if (!strcmp(res->inset_type, "fdir_inset"))
+               inset_type = INSET_FDIR;
+       else if (!strcmp(res->inset_type, "fdir_flx_inset"))
+               inset_type = INSET_FDIR_FLX;
+
+       memset(&inset, 0, sizeof(inset));
+
+       ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
+                                    &inset, inset_type);
+       if (ret) {
+               printf("Failed to clear input set.\n");
+               return;
+       }
+
+#endif
+
+       if (ret == -ENOTSUP)
+               printf("Function not supported\n");
+}
+
+cmdline_parse_token_string_t cmd_clear_input_set_port =
+       TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
+                                port, "port");
+cmdline_parse_token_string_t cmd_clear_input_set_cfg =
+       TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
+                                cfg, "config");
+cmdline_parse_token_num_t cmd_clear_input_set_port_id =
+       TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
+                             port_id, UINT16);
+cmdline_parse_token_string_t cmd_clear_input_set_pctype =
+       TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
+                                pctype, "pctype");
+cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
+       TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
+                             pctype_id, UINT8);
+cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
+       TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
+                                inset_type,
+                                "hash_inset#fdir_inset#fdir_flx_inset");
+cmdline_parse_token_string_t cmd_clear_input_set_clear =
+       TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
+                                clear, "clear");
+cmdline_parse_token_string_t cmd_clear_input_set_all =
+       TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
+                                all, "all");
+
+cmdline_parse_inst_t cmd_clear_input_set = {
+       .f = cmd_clear_input_set_parsed,
+       .data = NULL,
+       .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
+                   "fdir_inset|fdir_flx_inset clear all",
+       .tokens = {
+               (void *)&cmd_clear_input_set_port,
+               (void *)&cmd_clear_input_set_cfg,
+               (void *)&cmd_clear_input_set_port_id,
+               (void *)&cmd_clear_input_set_pctype,
+               (void *)&cmd_clear_input_set_pctype_id,
+               (void *)&cmd_clear_input_set_inset_type,
+               (void *)&cmd_clear_input_set_clear,
+               (void *)&cmd_clear_input_set_all,
+               NULL,
+       },
+};
+
 /* show vf stats */
 
 /* Common result structure for show vf stats */
@@ -15800,6 +16144,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
        (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
        (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
+       (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
        (cmdline_parse_inst_t *)&cmd_flush_flow_director,
        (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
        (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
@@ -15869,6 +16214,8 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_ddp_del,
        (cmdline_parse_inst_t *)&cmd_ddp_get_list,
        (cmdline_parse_inst_t *)&cmd_ddp_get_info,
+       (cmdline_parse_inst_t *)&cmd_cfg_input_set,
+       (cmdline_parse_inst_t *)&cmd_clear_input_set,
        (cmdline_parse_inst_t *)&cmd_show_vf_stats,
        (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
        (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,