app/testpmd: add vlan offload support
[dpdk.git] / app / test-pmd / cmdline.c
index 28233a6..2c82098 100644 (file)
@@ -30,7 +30,6 @@
  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  * 
- *  version: DPDK.L.1.2.3-3
  */
 
 #include <stdarg.h>
@@ -101,8 +100,8 @@ static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
        cmdline_printf(cl,
                       "Display informations:\n"
                       "---------------------\n"
-                      "- show port info|stats|fdir X|all\n"
-                      "    Diplays information or stats on port X, or all\n"
+                      "- show port info|stats|fdir|stat_qmap X|all\n"
+                      "    Diplays information or stats or stats queue mapping on port X, or all\n"
                       "- clear port stats X|all\n"
                       "    Clear stats for port X, or all\n"
                       "- show config rxtx|cores|fwd\n"
@@ -136,13 +135,16 @@ static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
                       "- set corelist|portlist x[,y]*\n"
                       "    Set the list of forwarding cores / forwarding "
                       "ports\n"
+                      "- vlan set strip|filter|qinq on/off port_id\n"
+                      "    Set the VLAN strip, filter, QinQ(extended) on a port"
                       "- rx_vlan add/rm vlan_id|all port_id\n"
-                      "    Add/remove vlan_id, or all identifiers, to/from "
-                      "the set of VLAN Identifiers\n    filtered by port_id\n"
+                      "    Set the VLAN filter table, add/remove vlan_id, or all "
+                      "identifiers, to/from the set of VLAN Identifiers\n"
+                      "filtered by port_id\n"
+                      "- rx_vlan set tpid value port_id\n"
+                      "    Set Outer VLAN TPID for Packet Filtering on a port \n"
                       "- tx_vlan set vlan_id port_id\n"
-                      "    Enable hardware insertion of a VLAN header with "
-                      "the Tag Identifier vlan_id\n    in packets sent on"
-                      "port_id\n"
+                      "    Set hardware insertion of VLAN ID in packets sent on a port\n"
                       "- tx_vlan reset port_id\n"
                       "    Disable hardware insertion of a VLAN header in "
                       "packets sent on port_id\n"
@@ -176,6 +178,9 @@ static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
                       "    Set bit field value of a port register\n"
                       "- write regbit port_id reg_off bit_x value\n"
                       "    Set bit value of a port register\n"
+                      "- set stat_qmap tx|rx port_id queue_id qmapping\n"
+                      "    Set statistics mapping (qmapping 0..15) for tx|rx queue_id on port_id\n"
+                      "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2 on port 0 to mapping 5\n"
                       "\n");
        cmdline_printf(cl,
                       "Control forwarding:\n"
@@ -562,6 +567,153 @@ cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
        },
 };
 
+/* *** VLAN OFFLOAD SET ON A PORT *** */
+struct cmd_vlan_offload_result {
+       cmdline_fixed_string_t vlan;
+       cmdline_fixed_string_t set;
+       cmdline_fixed_string_t what;
+       cmdline_fixed_string_t on;
+       cmdline_fixed_string_t port_id;
+};
+
+static void
+cmd_vlan_offload_parsed(void *parsed_result,
+                         __attribute__((unused)) struct cmdline *cl,
+                         __attribute__((unused)) void *data)
+{
+       int on;
+       struct cmd_vlan_offload_result *res = parsed_result;    
+       char *str;
+       int i, len = 0;
+       portid_t port_id = 0;
+       unsigned int tmp;
+       
+       str = res->port_id;
+       len = strnlen(str, STR_TOKEN_SIZE);
+       i = 0;
+       /* Get port_id first */
+       while(i < len){
+               if(str[i] == ',')
+                       break;
+               
+               i++;
+       }
+       str[i]='\0';
+       tmp = strtoul(str, NULL, 0);
+       /* If port_id greater that what portid_t can represent, return */
+       if(tmp > 255)
+               return;
+       port_id = (portid_t)tmp;
+
+       if (!strcmp(res->on, "on"))
+               on = 1;
+       else
+               on = 0;
+
+       if (!strcmp(res->what, "strip"))
+               rx_vlan_strip_set(port_id,  on);
+       else if(!strcmp(res->what, "stripq")){
+               uint16_t queue_id = 0;
+
+               /* No queue_id, return */
+               if(i + 1 >= len)
+                       return;
+               tmp = strtoul(str + i + 1, NULL, 0);
+               /* If queue_id greater that what 16-bits can represent, return */
+               if(tmp > 0xffff)
+                       return;
+               
+               queue_id = (uint16_t)tmp;
+               rx_vlan_strip_set_on_queue(port_id, queue_id, on);
+       }
+       else if (!strcmp(res->what, "filter"))
+               rx_vlan_filter_set(port_id, on);
+       else
+               vlan_extend_set(port_id, on);
+
+       return;
+}
+
+cmdline_parse_token_string_t cmd_vlan_offload_vlan =
+       TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
+                                vlan, "vlan");
+cmdline_parse_token_string_t cmd_vlan_offload_set =
+       TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
+                                set, "set");
+cmdline_parse_token_string_t cmd_vlan_offload_what =
+       TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
+                                what, "strip#filter#qinq#stripq");
+cmdline_parse_token_string_t cmd_vlan_offload_on =
+       TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
+                             on, "on#off");
+cmdline_parse_token_string_t cmd_vlan_offload_portid =
+       TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
+                             port_id, NULL);
+
+cmdline_parse_inst_t cmd_vlan_offload = {
+       .f = cmd_vlan_offload_parsed,
+       .data = NULL,
+       .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
+       " qinq(extended) for both rx/tx sides ",
+       .tokens = {
+               (void *)&cmd_vlan_offload_vlan,
+               (void *)&cmd_vlan_offload_set,
+               (void *)&cmd_vlan_offload_what,
+               (void *)&cmd_vlan_offload_on,
+               (void *)&cmd_vlan_offload_portid,
+               NULL,
+       },
+};
+
+/* *** VLAN TPID SET ON A PORT *** */
+struct cmd_vlan_tpid_result {
+       cmdline_fixed_string_t vlan;
+       cmdline_fixed_string_t set;
+       cmdline_fixed_string_t what;
+       uint16_t tp_id;
+       uint8_t port_id;
+};
+
+static void
+cmd_vlan_tpid_parsed(void *parsed_result,
+                         __attribute__((unused)) struct cmdline *cl,
+                         __attribute__((unused)) void *data)
+{
+       struct cmd_vlan_tpid_result *res = parsed_result;
+       vlan_tpid_set(res->port_id, res->tp_id);
+       return;
+}
+
+cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
+       TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
+                                vlan, "vlan");
+cmdline_parse_token_string_t cmd_vlan_tpid_set =
+       TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
+                                set, "set");
+cmdline_parse_token_string_t cmd_vlan_tpid_what =
+       TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
+                                what, "tpid");
+cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
+       TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
+                             tp_id, UINT16);
+cmdline_parse_token_num_t cmd_vlan_tpid_portid =
+       TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
+                             port_id, UINT8);
+
+cmdline_parse_inst_t cmd_vlan_tpid = {
+       .f = cmd_vlan_tpid_parsed,
+       .data = NULL,
+       .help_str = "set tpid tp_id port_id, set the Outer VLAN Ether type",
+       .tokens = {
+               (void *)&cmd_vlan_tpid_vlan,
+               (void *)&cmd_vlan_tpid_set,
+               (void *)&cmd_vlan_tpid_what,
+               (void *)&cmd_vlan_tpid_tpid,
+               (void *)&cmd_vlan_tpid_portid,
+               NULL,
+       },
+};
+
 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
 struct cmd_rx_vlan_filter_result {
        cmdline_fixed_string_t rx_vlan;
@@ -578,9 +730,9 @@ cmd_rx_vlan_filter_parsed(void *parsed_result,
        struct cmd_rx_vlan_filter_result *res = parsed_result;
 
        if (!strcmp(res->what, "add"))
-               rx_vlan_filter_set(res->port_id, res->vlan_id, 1);
+               rx_vft_set(res->port_id, res->vlan_id, 1);
        else
-               rx_vlan_filter_set(res->port_id, res->vlan_id, 0);
+               rx_vft_set(res->port_id, res->vlan_id, 0);
 }
 
 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
@@ -624,7 +776,6 @@ cmd_tx_vlan_set_parsed(void *parsed_result,
                       __attribute__((unused)) void *data)
 {
        struct cmd_tx_vlan_set_result *res = parsed_result;
-
        tx_vlan_set(res->port_id, res->vlan_id);
 }
 
@@ -1632,6 +1783,9 @@ static void cmd_showportall_parsed(void *parsed_result,
        else if (!strcmp(res->what, "fdir"))
                for (i = 0; i < nb_ports; i++)
                        fdir_get_infos(i);
+       else if (!strcmp(res->what, "stat_qmap"))
+               for (i = 0; i < nb_ports; i++)
+                       nic_stats_mapping_display(i);
 }
 
 cmdline_parse_token_string_t cmd_showportall_show =
@@ -1641,13 +1795,13 @@ cmdline_parse_token_string_t cmd_showportall_port =
        TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
 cmdline_parse_token_string_t cmd_showportall_what =
        TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
-                                "info#stats#fdir");
+                                "info#stats#fdir#stat_qmap");
 cmdline_parse_token_string_t cmd_showportall_all =
        TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
 cmdline_parse_inst_t cmd_showportall = {
        .f = cmd_showportall_parsed,
        .data = NULL,
-       .help_str = "show|clear port info|stats|fdir all",
+       .help_str = "show|clear port info|stats|fdir|stat_qmap all",
        .tokens = {
                (void *)&cmd_showportall_show,
                (void *)&cmd_showportall_port,
@@ -1679,6 +1833,8 @@ static void cmd_showport_parsed(void *parsed_result,
                nic_stats_display(res->portnum);
        else if (!strcmp(res->what, "fdir"))
                 fdir_get_infos(res->portnum);
+       else if (!strcmp(res->what, "stat_qmap"))
+               nic_stats_mapping_display(res->portnum);
 }
 
 cmdline_parse_token_string_t cmd_showport_show =
@@ -1688,14 +1844,14 @@ cmdline_parse_token_string_t cmd_showport_port =
        TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
 cmdline_parse_token_string_t cmd_showport_what =
        TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
-                                "info#stats#fdir");
+                                "info#stats#fdir#stat_qmap");
 cmdline_parse_token_num_t cmd_showport_portnum =
        TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, INT32);
 
 cmdline_parse_inst_t cmd_showport = {
        .f = cmd_showport_parsed,
        .data = NULL,
-       .help_str = "show|clear port info|stats|fdir X (X = port number)",
+       .help_str = "show|clear port info|stats|fdir|stat_qmap X (X = port number)",
        .tokens = {
                (void *)&cmd_showport_show,
                (void *)&cmd_showport_port,
@@ -2121,6 +2277,63 @@ cmdline_parse_inst_t cmd_mac_addr = {
 };
 
 
+/* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
+struct cmd_set_qmap_result {
+       cmdline_fixed_string_t set;
+       cmdline_fixed_string_t qmap;
+       cmdline_fixed_string_t what;
+       uint8_t port_id;
+       uint16_t queue_id;
+       uint8_t map_value;
+};
+
+static void
+cmd_set_qmap_parsed(void *parsed_result,
+                      __attribute__((unused)) struct cmdline *cl,
+                      __attribute__((unused)) void *data)
+{
+       struct cmd_set_qmap_result *res = parsed_result;
+       int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
+
+       set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
+}
+
+cmdline_parse_token_string_t cmd_setqmap_set =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
+                                set, "set");
+cmdline_parse_token_string_t cmd_setqmap_qmap =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
+                                qmap, "stat_qmap");
+cmdline_parse_token_string_t cmd_setqmap_what =
+       TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
+                                what, "tx#rx");
+cmdline_parse_token_num_t cmd_setqmap_portid =
+       TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
+                             port_id, UINT8);
+cmdline_parse_token_num_t cmd_setqmap_queueid =
+       TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
+                             queue_id, UINT16);
+cmdline_parse_token_num_t cmd_setqmap_mapvalue =
+       TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
+                             map_value, UINT8);
+
+cmdline_parse_inst_t cmd_set_qmap = {
+       .f = cmd_set_qmap_parsed,
+       .data = NULL,
+       .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
+       .tokens = {
+               (void *)&cmd_setqmap_set,
+               (void *)&cmd_setqmap_qmap,
+               (void *)&cmd_setqmap_what,
+               (void *)&cmd_setqmap_portid,
+               (void *)&cmd_setqmap_queueid,
+               (void *)&cmd_setqmap_mapvalue,
+               NULL,
+       },
+};
+
+/* ******************************************************************************** */
+
 /* list of instructions */
 cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_help,
@@ -2140,6 +2353,8 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
        (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
        (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
+       (cmdline_parse_inst_t *)&cmd_vlan_offload,
+       (cmdline_parse_inst_t *)&cmd_vlan_tpid,
        (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
        (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
        (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
@@ -2162,6 +2377,7 @@ cmdline_parse_ctx_t main_ctx[] = {
        (cmdline_parse_inst_t *)&cmd_set_masks_filter,
        (cmdline_parse_inst_t *)&cmd_stop,
        (cmdline_parse_inst_t *)&cmd_mac_addr,
+       (cmdline_parse_inst_t *)&cmd_set_qmap,
        NULL,
 };