add FILE argument to debug functions
[dpdk.git] / app / test-pmd / cmdline.c
index 8c47c01..b3824f9 100644 (file)
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  * 
  *   Copyright(c) 2010-2014 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
@@ -72,6 +73,7 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
+#include <rte_devargs.h>
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
@@ -292,17 +294,9 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "        bit 3 - insert sctp checksum offload if set\n"
                        "    Please check the NIC datasheet for HW limits.\n\n"
 
-#ifdef RTE_LIBRTE_IEEE1588
-                       "set fwd (io|mac|mac_retry|rxonly|txonly|csum|ieee1588)\n"
-                       "    Set IO, MAC, MAC_RETRY, RXONLY, CSUM or TXONLY or ieee1588"
-                       " packet forwarding mode.\n\n"
+                       "set fwd (%s)\n"
+                       "    Set packet forwarding mode.\n\n"
 
-#else
-                       "set fwd (io|mac|mac_retry|rxonly|txonly|csum)\n"
-                       "    Set IO, MAC, MAC_RETRY, RXONLY, CSUM or TXONLY packet"
-                       " forwarding mode.\n\n"
-
-#endif
                        "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
                        "    Add a MAC address on port_id.\n\n"
 
@@ -396,6 +390,7 @@ static void cmd_help_long_parsed(void *parsed_result,
                        " using the lowest port on the NIC.\n\n"
 #endif
 
+                       , list_pkt_forwarding_modes()
                );
        }
 
@@ -2333,6 +2328,46 @@ cmdline_parse_inst_t cmd_set_flush_rx = {
        },
 };
 
+/* *** ENABLE/DISABLE LINK STATUS CHECK *** */
+struct cmd_set_link_check {
+       cmdline_fixed_string_t set;
+       cmdline_fixed_string_t link_check;
+       cmdline_fixed_string_t mode;
+};
+
+static void
+cmd_set_link_check_parsed(void *parsed_result,
+               __attribute__((unused)) struct cmdline *cl,
+               __attribute__((unused)) void *data)
+{
+       struct cmd_set_link_check *res = parsed_result;
+       no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
+}
+
+cmdline_parse_token_string_t cmd_setlinkcheck_set =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
+                       set, "set");
+cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
+                       link_check, "link_check");
+cmdline_parse_token_string_t cmd_setlinkcheck_mode =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
+                       mode, "on#off");
+
+
+cmdline_parse_inst_t cmd_set_link_check = {
+       .f = cmd_set_link_check_parsed,
+       .help_str = "set link_check on|off: enable/disable link status check "
+                   "when starting/stopping a port",
+       .data = NULL,
+       .tokens = {
+               (void *)&cmd_setlinkcheck_set,
+               (void *)&cmd_setlinkcheck_link_check,
+               (void *)&cmd_setlinkcheck_mode,
+               NULL,
+       },
+};
+
 #ifdef RTE_NIC_BYPASS
 /* *** SET NIC BYPASS MODE *** */
 struct cmd_set_bypass_mode_result {
@@ -2686,22 +2721,12 @@ cmdline_parse_token_string_t cmd_setfwd_fwd =
        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
 cmdline_parse_token_string_t cmd_setfwd_mode =
        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
-#ifdef RTE_LIBRTE_IEEE1588
-                                "io#mac#mac_retry#rxonly#txonly#csum#ieee1588");
-#else
-                                "io#mac#mac_retry#rxonly#txonly#csum");
-#endif
+               "" /* defined at init */);
 
 cmdline_parse_inst_t cmd_set_fwd_mode = {
        .f = cmd_set_fwd_mode_parsed,
        .data = NULL,
-#ifdef RTE_LIBRTE_IEEE1588
-       .help_str = "set fwd io|mac|mac_retry|rxonly|txonly|csum|ieee1588 - set IO, MAC,"
-       " MAC_RETRY, RXONLY, TXONLY, CSUM or IEEE1588 packet forwarding mode",
-#else
-       .help_str = "set fwd io|mac|mac_retry|rxonly|txonly|csum - set IO, MAC,"
-       " MAC_RETRY, RXONLY, CSUM or TXONLY packet forwarding mode",
-#endif
+       .help_str = NULL, /* defined at init */
        .tokens = {
                (void *)&cmd_setfwd_set,
                (void *)&cmd_setfwd_fwd,
@@ -2710,6 +2735,28 @@ cmdline_parse_inst_t cmd_set_fwd_mode = {
        },
 };
 
+static void cmd_set_fwd_mode_init(void)
+{
+       char *modes, *c;
+       static char token[128];
+       static char help[256];
+       cmdline_parse_token_string_t *token_struct;
+
+       modes = list_pkt_forwarding_modes();
+       rte_snprintf(help, sizeof help, "set fwd %s - "
+               "set packet forwarding mode", modes);
+       cmd_set_fwd_mode.help_str = help;
+
+       /* string token separator is # */
+       for (c = token; *modes != '\0'; modes++)
+               if (*modes == '|')
+                       *c++ = '#';
+               else
+                       *c++ = *modes;
+       token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
+       token_struct->string_data.str = token;
+}
+
 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
 struct cmd_set_burst_tx_retry_result {
        cmdline_fixed_string_t set;
@@ -3459,7 +3506,7 @@ cmd_link_flow_ctrl_set_parsed(void *parsed_result,
         * 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_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
+                       {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;
@@ -4998,6 +5045,115 @@ cmdline_parse_inst_t cmd_reset_mirror_rule = {
 
 /* ******************************************************************************** */
 
+struct cmd_dump_result {
+       cmdline_fixed_string_t dump;
+};
+
+static void
+dump_struct_sizes(void)
+{
+#define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
+       DUMP_SIZE(struct rte_mbuf);
+       DUMP_SIZE(struct rte_pktmbuf);
+       DUMP_SIZE(struct rte_ctrlmbuf);
+       DUMP_SIZE(struct rte_mempool);
+       DUMP_SIZE(struct rte_ring);
+#undef DUMP_SIZE
+}
+
+static void cmd_dump_parsed(void *parsed_result,
+                           __attribute__((unused)) struct cmdline *cl,
+                           __attribute__((unused)) void *data)
+{
+       struct cmd_dump_result *res = parsed_result;
+
+       if (!strcmp(res->dump, "dump_physmem"))
+               rte_dump_physmem_layout(stdout);
+       else if (!strcmp(res->dump, "dump_memzone"))
+               rte_memzone_dump(stdout);
+       else if (!strcmp(res->dump, "dump_log_history"))
+               rte_log_dump_history(stdout);
+       else if (!strcmp(res->dump, "dump_struct_sizes"))
+               dump_struct_sizes();
+       else if (!strcmp(res->dump, "dump_ring"))
+               rte_ring_list_dump(stdout);
+       else if (!strcmp(res->dump, "dump_mempool"))
+               rte_mempool_list_dump(stdout);
+       else if (!strcmp(res->dump, "dump_devargs"))
+               rte_eal_devargs_dump(stdout);
+}
+
+cmdline_parse_token_string_t cmd_dump_dump =
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
+               "dump_physmem#"
+               "dump_memzone#"
+               "dump_log_history#"
+               "dump_struct_sizes#"
+               "dump_ring#"
+               "dump_mempool#"
+               "dump_devargs");
+
+cmdline_parse_inst_t cmd_dump = {
+       .f = cmd_dump_parsed,  /* function to call */
+       .data = NULL,      /* 2nd arg of func */
+       .help_str = "dump status",
+       .tokens = {        /* token list, NULL terminated */
+               (void *)&cmd_dump_dump,
+               NULL,
+       },
+};
+
+/* ******************************************************************************** */
+
+struct cmd_dump_one_result {
+       cmdline_fixed_string_t dump;
+       cmdline_fixed_string_t name;
+};
+
+static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
+                               __attribute__((unused)) void *data)
+{
+       struct cmd_dump_one_result *res = parsed_result;
+
+       if (!strcmp(res->dump, "dump_ring")) {
+               struct rte_ring *r;
+               r = rte_ring_lookup(res->name);
+               if (r == NULL) {
+                       cmdline_printf(cl, "Cannot find ring\n");
+                       return;
+               }
+               rte_ring_dump(stdout, r);
+       } else if (!strcmp(res->dump, "dump_mempool")) {
+               struct rte_mempool *mp;
+               mp = rte_mempool_lookup(res->name);
+               if (mp == NULL) {
+                       cmdline_printf(cl, "Cannot find mempool\n");
+                       return;
+               }
+               rte_mempool_dump(stdout, mp);
+       }
+}
+
+cmdline_parse_token_string_t cmd_dump_one_dump =
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
+                                "dump_ring#dump_mempool");
+
+cmdline_parse_token_string_t cmd_dump_one_name =
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
+
+cmdline_parse_inst_t cmd_dump_one = {
+       .f = cmd_dump_one_parsed,  /* function to call */
+       .data = NULL,      /* 2nd arg of func */
+       .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
+       .tokens = {        /* token list, NULL terminated */
+               (void *)&cmd_dump_one_dump,
+               (void *)&cmd_dump_one_name,
+               NULL,
+       },
+};
+
+/* ******************************************************************************** */
+
 /* list of instructions */
 cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_help_brief,
@@ -5020,6 +5176,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
        (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
        (cmdline_parse_inst_t *)&cmd_set_flush_rx,
+       (cmdline_parse_inst_t *)&cmd_set_link_check,
 #ifdef RTE_NIC_BYPASS
        (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
        (cmdline_parse_inst_t *)&cmd_set_bypass_event,
@@ -5076,6 +5233,8 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
        (cmdline_parse_inst_t *)&cmd_set_mirror_link,
        (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
+       (cmdline_parse_inst_t *)&cmd_dump,
+       (cmdline_parse_inst_t *)&cmd_dump_one,
        NULL,
 };
 
@@ -5085,6 +5244,9 @@ prompt(void)
 {
        struct cmdline *cl;
 
+       /* initialize non-constant commands */
+       cmd_set_fwd_mode_init();
+
        cl = cmdline_stdin_new(main_ctx, "testpmd> ");
        if (cl == NULL) {
                return;