remove extra parentheses in return statement
[dpdk.git] / app / test-pmd / cmdline.c
index 1018379..52e9f5f 100644 (file)
@@ -90,6 +90,8 @@
 
 #include "testpmd.h"
 
+static struct cmdline *testpmd_cl;
+
 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
 
 #ifdef RTE_NIC_BYPASS
@@ -199,7 +201,10 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
                        "    Clear information for port_id, or all.\n\n"
 
-                       "show config (rxtx|cores|fwd)\n"
+                       "show (rxq|txq) info (port_id) (queue_id)\n"
+                       "    Display information for configured RX/TX queue.\n\n"
+
+                       "show config (rxtx|cores|fwd|txpkts)\n"
                        "    Display the given configuration.\n\n"
 
                        "read rxd (port_id) (queue_id) (rxd_id)\n"
@@ -246,7 +251,12 @@ static void cmd_help_long_parsed(void *parsed_result,
 
                        "set txpkts (x[,y]*)\n"
                        "    Set the length of each segment of TXONLY"
-                       " packets.\n\n"
+                       " and optionally CSUM packets.\n\n"
+
+                       "set txsplit (off|on|rand)\n"
+                       "    Set the split policy for the TX packets."
+                       " Right now only applicable for CSUM and TXONLY"
+                       " modes\n\n"
 
                        "set corelist (x[,y]*)\n"
                        "    Set the list of forwarding cores.\n\n"
@@ -629,43 +639,68 @@ static void cmd_help_long_parsed(void *parsed_result,
                        " priority (prio_value) queue (queue_id)\n"
                        "    Add/Del a flex filter.\n\n"
 
-                       "flow_director_filter (port_id) (add|del|update)"
+                       "flow_director_filter (port_id) mode IP (add|del|update)"
                        " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
                        " src (src_ip_address) dst (dst_ip_address)"
                        " vlan (vlan_value) flexbytes (flexbytes_value)"
-                       " (drop|fwd) queue (queue_id) fd_id (fd_id_value)\n"
+                       " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
+                       " fd_id (fd_id_value)\n"
                        "    Add/Del an IP type flow director filter.\n\n"
 
-                       "flow_director_filter (port_id) (add|del|update)"
+                       "flow_director_filter (port_id) mode IP (add|del|update)"
                        " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
                        " src (src_ip_address) (src_port)"
                        " dst (dst_ip_address) (dst_port)"
                        " vlan (vlan_value) flexbytes (flexbytes_value)"
-                       " (drop|fwd) queue (queue_id) fd_id (fd_id_value)\n"
+                       " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
+                       " fd_id (fd_id_value)\n"
                        "    Add/Del an UDP/TCP type flow director filter.\n\n"
 
-                       "flow_director_filter (port_id) (add|del|update)"
+                       "flow_director_filter (port_id) mode IP (add|del|update)"
                        " flow (ipv4-sctp|ipv6-sctp)"
                        " src (src_ip_address) (src_port)"
                        " dst (dst_ip_address) (dst_port)"
                        " tag (verification_tag) vlan (vlan_value)"
                        " flexbytes (flexbytes_value) (drop|fwd)"
-                       " queue (queue_id) fd_id (fd_id_value)\n"
+                       " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
                        "    Add/Del a SCTP type flow director filter.\n\n"
 
-                       "flow_director_filter (port_id) (add|del|update)"
+                       "flow_director_filter (port_id) mode IP (add|del|update)"
                        " flow l2_payload ether (ethertype)"
                        " flexbytes (flexbytes_value) (drop|fwd)"
-                       " queue (queue_id) fd_id (fd_id_value)\n"
+                       " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
                        "    Add/Del a l2 payload type flow director filter.\n\n"
 
+                       "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
+                       " mac (mac_address) vlan (vlan_value)"
+                       " flexbytes (flexbytes_value) (drop|fwd)"
+                       " queue (queue_id) fd_id (fd_id_value)\n"
+                       "    Add/Del a MAC-VLAN flow director filter.\n\n"
+
+                       "flow_director_filter (port_id) mode Tunnel (add|del|update)"
+                       " mac (mac_address) vlan (vlan_value)"
+                       " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
+                       " flexbytes (flexbytes_value) (drop|fwd)"
+                       " queue (queue_id) fd_id (fd_id_value)\n"
+                       "    Add/Del a Tunnel flow director filter.\n\n"
+
                        "flush_flow_director (port_id)\n"
                        "    Flush all flow director entries of a device.\n\n"
 
-                       "flow_director_mask (port_id) vlan (vlan_value)"
+                       "flow_director_mask (port_id) mode IP vlan (vlan_value)"
                        " src_mask (ipv4_src) (ipv6_src) (src_port)"
                        " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
-                       "    Set flow director mask.\n\n"
+                       "    Set flow director IP mask.\n\n"
+
+                       "flow_director_mask (port_id) mode MAC-VLAN"
+                       " vlan (vlan_value) mac (mac_value)\n"
+                       "    Set flow director MAC-VLAN mask.\n\n"
+
+                       "flow_director_mask (port_id) mode Tunnel"
+                       " vlan (vlan_value) mac (mac_value)"
+                       " tunnel-type (tunnel_type_value)"
+                       " tunnel-id (tunnel_id_value)\n"
+                       "    Set flow director Tunnel mask.\n\n"
 
                        "flow_director_flex_mask (port_id)"
                        " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
@@ -2385,11 +2420,11 @@ parse_item_list(char* str, const char* item_name, unsigned int max_items,
                }
                if (c != ',') {
                        printf("character %c is not a decimal digit\n", c);
-                       return (0);
+                       return 0;
                }
                if (! value_ok) {
                        printf("No valid value before comma\n");
-                       return (0);
+                       return 0;
                }
                if (nb_item < max_items) {
                        parsed_items[nb_item] = value;
@@ -2401,11 +2436,11 @@ parse_item_list(char* str, const char* item_name, unsigned int max_items,
        if (nb_item >= max_items) {
                printf("Number of %s = %u > %u (maximum items)\n",
                       item_name, nb_item + 1, max_items);
-               return (0);
+               return 0;
        }
        parsed_items[nb_item++] = value;
        if (! check_unique_values)
-               return (nb_item);
+               return nb_item;
 
        /*
         * Then, check that all values in the list are differents.
@@ -2416,11 +2451,11 @@ parse_item_list(char* str, const char* item_name, unsigned int max_items,
                        if (parsed_items[j] == parsed_items[i]) {
                                printf("duplicated %s %u at index %u and %u\n",
                                       item_name, parsed_items[i], i, j);
-                               return (0);
+                               return 0;
                        }
                }
        }
-       return (nb_item);
+       return nb_item;
 }
 
 struct cmd_set_list_result {
@@ -2619,6 +2654,47 @@ cmdline_parse_inst_t cmd_set_txpkts = {
        },
 };
 
+/* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
+
+struct cmd_set_txsplit_result {
+       cmdline_fixed_string_t cmd_keyword;
+       cmdline_fixed_string_t txsplit;
+       cmdline_fixed_string_t mode;
+};
+
+static void
+cmd_set_txsplit_parsed(void *parsed_result,
+                     __attribute__((unused)) struct cmdline *cl,
+                     __attribute__((unused)) void *data)
+{
+       struct cmd_set_txsplit_result *res;
+
+       res = parsed_result;
+       set_tx_pkt_split(res->mode);
+}
+
+cmdline_parse_token_string_t cmd_set_txsplit_keyword =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
+                                cmd_keyword, "set");
+cmdline_parse_token_string_t cmd_set_txsplit_name =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
+                                txsplit, "txsplit");
+cmdline_parse_token_string_t cmd_set_txsplit_mode =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
+                                mode, NULL);
+
+cmdline_parse_inst_t cmd_set_txsplit = {
+       .f = cmd_set_txsplit_parsed,
+       .data = NULL,
+       .help_str = "set txsplit on|off|rand",
+       .tokens = {
+               (void *)&cmd_set_txsplit_keyword,
+               (void *)&cmd_set_txsplit_name,
+               (void *)&cmd_set_txsplit_mode,
+               NULL,
+       },
+};
+
 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
 struct cmd_rx_vlan_filter_all_result {
        cmdline_fixed_string_t rx_vlan;
@@ -5231,6 +5307,8 @@ static void cmd_showcfg_parsed(void *parsed_result,
                fwd_lcores_config_display();
        else if (!strcmp(res->what, "fwd"))
                fwd_config_display();
+       else if (!strcmp(res->what, "txpkts"))
+               show_tx_pkt_segments();
 }
 
 cmdline_parse_token_string_t cmd_showcfg_show =
@@ -5239,12 +5317,12 @@ cmdline_parse_token_string_t cmd_showcfg_port =
        TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
 cmdline_parse_token_string_t cmd_showcfg_what =
        TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
-                                "rxtx#cores#fwd");
+                                "rxtx#cores#fwd#txpkts");
 
 cmdline_parse_inst_t cmd_showcfg = {
        .f = cmd_showcfg_parsed,
        .data = NULL,
-       .help_str = "show config rxtx|cores|fwd",
+       .help_str = "show config rxtx|cores|fwd|txpkts",
        .tokens = {
                (void *)&cmd_showcfg_show,
                (void *)&cmd_showcfg_port,
@@ -7911,6 +7989,7 @@ struct cmd_flow_director_result {
        uint16_t vlan_value;
        cmdline_fixed_string_t flexbytes;
        cmdline_fixed_string_t flexbytes_value;
+       cmdline_fixed_string_t pf_vf;
        cmdline_fixed_string_t drop;
        cmdline_fixed_string_t queue;
        uint16_t  queue_id;
@@ -7993,14 +8072,14 @@ str2flowtype(char *string)
        return RTE_ETH_FLOW_UNKNOWN;
 }
 
-static uint8_t
+static enum rte_eth_fdir_tunnel_type
 str2fdir_tunneltype(char *string)
 {
        uint8_t i = 0;
 
        static const struct {
                char str[32];
-               uint8_t type;
+               enum rte_eth_fdir_tunnel_type type;
        } tunneltype_str[] = {
                {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
                {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
@@ -8043,6 +8122,8 @@ cmd_flow_director_filter_parsed(void *parsed_result,
        struct cmd_flow_director_result *res = parsed_result;
        struct rte_eth_fdir_filter entry;
        uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
+       char *end;
+       unsigned long vf_id;
        int ret = 0;
 
        ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
@@ -8169,6 +8250,27 @@ cmd_flow_director_filter_parsed(void *parsed_result,
                entry.action.behavior = RTE_ETH_FDIR_REJECT;
        else
                entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
+
+       if (!strcmp(res->pf_vf, "pf"))
+               entry.input.flow_ext.is_vf = 0;
+       else if (!strncmp(res->pf_vf, "vf", 2)) {
+               struct rte_eth_dev_info dev_info;
+
+               memset(&dev_info, 0, sizeof(dev_info));
+               rte_eth_dev_info_get(res->port_id, &dev_info);
+               errno = 0;
+               vf_id = strtoul(res->pf_vf + 2, &end, 10);
+               if (errno != 0 || *end != '\0' || vf_id >= dev_info.max_vfs) {
+                       printf("invalid parameter %s.\n", res->pf_vf);
+                       return;
+               }
+               entry.input.flow_ext.is_vf = 1;
+               entry.input.flow_ext.dst_id = (uint16_t)vf_id;
+       } else {
+               printf("invalid parameter %s.\n", res->pf_vf);
+               return;
+       }
+
        /* set to report FD ID by default */
        entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
        entry.action.rx_queue = res->queue_id;
@@ -8248,6 +8350,9 @@ cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
 cmdline_parse_token_string_t cmd_flow_director_drop =
        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
                                 drop, "drop#fwd");
+cmdline_parse_token_string_t cmd_flow_director_pf_vf =
+       TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
+                             pf_vf, NULL);
 cmdline_parse_token_string_t cmd_flow_director_queue =
        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
                                 queue, "queue");
@@ -8313,6 +8418,7 @@ cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
                (void *)&cmd_flow_director_flexbytes,
                (void *)&cmd_flow_director_flexbytes_value,
                (void *)&cmd_flow_director_drop,
+               (void *)&cmd_flow_director_pf_vf,
                (void *)&cmd_flow_director_queue,
                (void *)&cmd_flow_director_queue_id,
                (void *)&cmd_flow_director_fd_id,
@@ -8344,6 +8450,7 @@ cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
                (void *)&cmd_flow_director_flexbytes,
                (void *)&cmd_flow_director_flexbytes_value,
                (void *)&cmd_flow_director_drop,
+               (void *)&cmd_flow_director_pf_vf,
                (void *)&cmd_flow_director_queue,
                (void *)&cmd_flow_director_queue_id,
                (void *)&cmd_flow_director_fd_id,
@@ -8377,6 +8484,7 @@ cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
                (void *)&cmd_flow_director_flexbytes,
                (void *)&cmd_flow_director_flexbytes_value,
                (void *)&cmd_flow_director_drop,
+               (void *)&cmd_flow_director_pf_vf,
                (void *)&cmd_flow_director_queue,
                (void *)&cmd_flow_director_queue_id,
                (void *)&cmd_flow_director_fd_id,
@@ -8402,6 +8510,7 @@ cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
                (void *)&cmd_flow_director_flexbytes,
                (void *)&cmd_flow_director_flexbytes_value,
                (void *)&cmd_flow_director_drop,
+               (void *)&cmd_flow_director_pf_vf,
                (void *)&cmd_flow_director_queue,
                (void *)&cmd_flow_director_queue_id,
                (void *)&cmd_flow_director_fd_id,
@@ -9541,6 +9650,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_reset,
        (cmdline_parse_inst_t *)&cmd_set_numbers,
        (cmdline_parse_inst_t *)&cmd_set_txpkts,
+       (cmdline_parse_inst_t *)&cmd_set_txsplit,
        (cmdline_parse_inst_t *)&cmd_set_fwd_list,
        (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
        (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
@@ -9670,17 +9780,21 @@ cmdline_parse_ctx_t main_ctx[] = {
 void
 prompt(void)
 {
-       struct cmdline *cl;
-
        /* initialize non-constant commands */
        cmd_set_fwd_mode_init();
 
-       cl = cmdline_stdin_new(main_ctx, "testpmd> ");
-       if (cl == NULL) {
+       testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
+       if (testpmd_cl == NULL)
                return;
-       }
-       cmdline_interact(cl);
-       cmdline_stdin_exit(cl);
+       cmdline_interact(testpmd_cl);
+       cmdline_stdin_exit(testpmd_cl);
+}
+
+void
+prompt_exit(void)
+{
+       if (testpmd_cl != NULL)
+               cmdline_quit(testpmd_cl);
 }
 
 static void