app/testpmd: use SPDX tags in 6WIND copyrighted files
[dpdk.git] / app / test-pmd / cmdline.c
index 653dda3..1e06dcd 100644 (file)
@@ -1,35 +1,6 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
- *   Copyright(c) 2014 6WIND S.A.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2016 Intel Corporation.
+ * Copyright(c) 2014 6WIND S.A.
  */
 
 #include <stdarg.h>
@@ -274,6 +245,9 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "set verbose (level)\n"
                        "    Set the debug verbosity level X.\n\n"
 
+                       "set log global|(type) (level)\n"
+                       "    Set the log level.\n\n"
+
                        "set nbport (num)\n"
                        "    Set number of ports.\n\n"
 
@@ -887,6 +861,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"
                );
        }
 
@@ -1529,6 +1512,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")) {
@@ -1536,6 +1521,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")) {
@@ -3042,6 +3029,55 @@ cmdline_parse_inst_t cmd_set_numbers = {
        },
 };
 
+/* *** SET LOG LEVEL CONFIGURATION *** */
+
+struct cmd_set_log_result {
+       cmdline_fixed_string_t set;
+       cmdline_fixed_string_t log;
+       cmdline_fixed_string_t type;
+       uint32_t level;
+};
+
+static void
+cmd_set_log_parsed(void *parsed_result,
+                  __attribute__((unused)) struct cmdline *cl,
+                  __attribute__((unused)) void *data)
+{
+       struct cmd_set_log_result *res;
+       int ret;
+
+       res = parsed_result;
+       if (!strcmp(res->type, "global"))
+               rte_log_set_global_level(res->level);
+       else {
+               ret = rte_log_set_level_regexp(res->type, res->level);
+               if (ret < 0)
+                       printf("Unable to set log level\n");
+       }
+}
+
+cmdline_parse_token_string_t cmd_set_log_set =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
+cmdline_parse_token_string_t cmd_set_log_log =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
+cmdline_parse_token_string_t cmd_set_log_type =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
+cmdline_parse_token_num_t cmd_set_log_level =
+       TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
+
+cmdline_parse_inst_t cmd_set_log = {
+       .f = cmd_set_log_parsed,
+       .data = NULL,
+       .help_str = "set log global|<type> <level>",
+       .tokens = {
+               (void *)&cmd_set_log_set,
+               (void *)&cmd_set_log_log,
+               (void *)&cmd_set_log_type,
+               (void *)&cmd_set_log_level,
+               NULL,
+       },
+};
+
 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
 
 struct cmd_set_txpkts_result {
@@ -3693,40 +3729,40 @@ cmd_csum_parsed(void *parsed_result,
                        hw = 1;
 
                if (!strcmp(res->proto, "ip")) {
-                       if (dev_info.tx_offload_capa &
-                                               DEV_TX_OFFLOAD_IPV4_CKSUM) {
+                       if (hw == 0 || (dev_info.tx_offload_capa &
+                                               DEV_TX_OFFLOAD_IPV4_CKSUM)) {
                                csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
                        } else {
                                printf("IP checksum offload is not supported "
                                       "by port %u\n", res->port_id);
                        }
                } else if (!strcmp(res->proto, "udp")) {
-                       if (dev_info.tx_offload_capa &
-                                               DEV_TX_OFFLOAD_UDP_CKSUM) {
+                       if (hw == 0 || (dev_info.tx_offload_capa &
+                                               DEV_TX_OFFLOAD_UDP_CKSUM)) {
                                csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
                        } else {
                                printf("UDP checksum offload is not supported "
                                       "by port %u\n", res->port_id);
                        }
                } else if (!strcmp(res->proto, "tcp")) {
-                       if (dev_info.tx_offload_capa &
-                                               DEV_TX_OFFLOAD_TCP_CKSUM) {
+                       if (hw == 0 || (dev_info.tx_offload_capa &
+                                               DEV_TX_OFFLOAD_TCP_CKSUM)) {
                                csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
                        } else {
                                printf("TCP checksum offload is not supported "
                                       "by port %u\n", res->port_id);
                        }
                } else if (!strcmp(res->proto, "sctp")) {
-                       if (dev_info.tx_offload_capa &
-                                               DEV_TX_OFFLOAD_SCTP_CKSUM) {
+                       if (hw == 0 || (dev_info.tx_offload_capa &
+                                               DEV_TX_OFFLOAD_SCTP_CKSUM)) {
                                csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
                        } else {
                                printf("SCTP checksum offload is not supported "
                                       "by port %u\n", res->port_id);
                        }
                } else if (!strcmp(res->proto, "outer-ip")) {
-                       if (dev_info.tx_offload_capa &
-                                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
+                       if (hw == 0 || (dev_info.tx_offload_capa &
+                                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
                                csum_offloads |=
                                                DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
                        } else {
@@ -5824,7 +5860,7 @@ cmdline_parse_token_string_t cmd_setpromisc_portall =
                                 "all");
 cmdline_parse_token_num_t cmd_setpromisc_portnum =
        TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
-                             UINT8);
+                             UINT16);
 cmdline_parse_token_string_t cmd_setpromisc_mode =
        TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
                                 "on#off");
@@ -10886,7 +10922,7 @@ cmd_flow_director_flex_mask_parsed(void *parsed_result,
        struct rte_eth_fdir_info fdir_info;
        struct rte_eth_fdir_flex_mask flex_mask;
        struct rte_port *port;
-       uint32_t flow_type_mask;
+       uint64_t flow_type_mask;
        uint16_t i;
        int ret;
 
@@ -10939,7 +10975,7 @@ cmd_flow_director_flex_mask_parsed(void *parsed_result,
                        return;
                }
                for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
-                       if (flow_type_mask & (1 << i)) {
+                       if (flow_type_mask & (1ULL << i)) {
                                flex_mask.flow_type = i;
                                fdir_set_flex_mask(res->port_id, &flex_mask);
                        }
@@ -10948,7 +10984,7 @@ cmd_flow_director_flex_mask_parsed(void *parsed_result,
                return;
        }
        flex_mask.flow_type = str2flowtype(res->flow_type);
-       if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
+       if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
                printf("Flow type %s not supported on port %d\n",
                                res->flow_type, res->port_id);
                return;
@@ -11310,10 +11346,10 @@ cmd_get_hash_global_config_parsed(void *parsed_result,
        }
 
        for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
-               idx = i / UINT32_BIT;
-               offset = i % UINT32_BIT;
+               idx = i / UINT64_BIT;
+               offset = i % UINT64_BIT;
                if (!(info.info.global_conf.valid_bit_mask[idx] &
-                                               (1UL << offset)))
+                                               (1ULL << offset)))
                        continue;
                str = flowtype_to_str(i);
                if (!str)
@@ -11321,7 +11357,7 @@ cmd_get_hash_global_config_parsed(void *parsed_result,
                printf("Symmetric hash is %s globally for flow type %s "
                                                        "by port %d\n",
                        ((info.info.global_conf.sym_hash_enable_mask[idx] &
-                       (1UL << offset)) ? "enabled" : "disabled"), str,
+                       (1ULL << offset)) ? "enabled" : "disabled"), str,
                                                        res->port_id);
        }
 }
@@ -11382,12 +11418,12 @@ cmd_set_hash_global_config_parsed(void *parsed_result,
                        RTE_ETH_HASH_FUNCTION_DEFAULT;
 
        ftype = str2flowtype(res->flow_type);
-       idx = ftype / (CHAR_BIT * sizeof(uint32_t));
-       offset = ftype % (CHAR_BIT * sizeof(uint32_t));
-       info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
+       idx = ftype / UINT64_BIT;
+       offset = ftype % UINT64_BIT;
+       info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
        if (!strcmp(res->enable, "enable"))
                info.info.global_conf.sym_hash_enable_mask[idx] |=
-                                               (1UL << offset);
+                                               (1ULL << offset);
        ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
                                        RTE_ETH_FILTER_SET, &info);
        if (ret < 0)
@@ -14880,6 +14916,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 */
@@ -15782,6 +16049,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (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_log,
        (cmdline_parse_inst_t *)&cmd_set_txpkts,
        (cmdline_parse_inst_t *)&cmd_set_txsplit,
        (cmdline_parse_inst_t *)&cmd_set_fwd_list,
@@ -15970,6 +16238,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,