app/testpmd: adjust on the fly VLAN configuration
authorShahaf Shuler <shahafs@mellanox.com>
Wed, 10 Jan 2018 09:09:18 +0000 (11:09 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 15 Jan 2018 09:57:21 +0000 (10:57 +0100)
On ethdev there is an API to configure VLAN offloads after the port
was started and without reconfiguration of the port or queues.

In the current design of the application, when the Rx offloads are
changed (through "port config all" CLI command) the port configuration
is overwritten, therefore the configuration made for the VLAN is lost.

This patch is to address the issue by a configuration of each port Rx
offloads separately instead of using the global Rx config. Such
adjustment is required due to the conversion of the application to the
new offloads API.

Signed-off-by: Shahaf Shuler <shahafs@mellanox.com>
Acked-by: Wenzhuo Lu <wenzhuo.lu@intel.com>
app/test-pmd/cmdline.c
app/test-pmd/config.c
app/test-pmd/testpmd.c

index 01a170e..2418f6b 100644 (file)
@@ -1594,34 +1594,38 @@ cmd_config_max_pkt_len_parsed(void *parsed_result,
                                __attribute__((unused)) void *data)
 {
        struct cmd_config_max_pkt_len_result *res = parsed_result;
-       uint64_t rx_offloads = rx_mode.offloads;
+       portid_t pid;
 
        if (!all_ports_stopped()) {
                printf("Please stop all ports first\n");
                return;
        }
 
-       if (!strcmp(res->name, "max-pkt-len")) {
-               if (res->value < ETHER_MIN_LEN) {
-                       printf("max-pkt-len can not be less than %d\n",
-                                                       ETHER_MIN_LEN);
+       RTE_ETH_FOREACH_DEV(pid) {
+               struct rte_port *port = &ports[pid];
+               uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
+
+               if (!strcmp(res->name, "max-pkt-len")) {
+                       if (res->value < ETHER_MIN_LEN) {
+                               printf("max-pkt-len can not be less than %d\n",
+                                               ETHER_MIN_LEN);
+                               return;
+                       }
+                       if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
+                               return;
+
+                       port->dev_conf.rxmode.max_rx_pkt_len = res->value;
+                       if (res->value > ETHER_MAX_LEN)
+                               rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+                       else
+                               rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
+                       port->dev_conf.rxmode.offloads = rx_offloads;
+               } else {
+                       printf("Unknown parameter\n");
                        return;
                }
-               if (res->value == rx_mode.max_rx_pkt_len)
-                       return;
-
-               rx_mode.max_rx_pkt_len = res->value;
-               if (res->value > ETHER_MAX_LEN)
-                       rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-               else
-                       rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-       } else {
-               printf("Unknown parameter\n");
-               return;
        }
 
-       rx_mode.offloads = rx_offloads;
-
        init_port_config();
 
        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
@@ -1723,103 +1727,108 @@ cmd_config_rx_mode_flag_parsed(void *parsed_result,
                                __attribute__((unused)) void *data)
 {
        struct cmd_config_rx_mode_flag *res = parsed_result;
-       uint64_t rx_offloads = rx_mode.offloads;
+       portid_t pid;
 
        if (!all_ports_stopped()) {
                printf("Please stop all ports first\n");
                return;
        }
 
-       if (!strcmp(res->name, "crc-strip")) {
-               if (!strcmp(res->value, "on"))
-                       rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
-               else if (!strcmp(res->value, "off"))
-                       rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
-               else {
-                       printf("Unknown parameter\n");
-                       return;
-               }
-       } else if (!strcmp(res->name, "scatter")) {
-               if (!strcmp(res->value, "on")) {
-                       rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
-               } else if (!strcmp(res->value, "off")) {
-                       rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
+       RTE_ETH_FOREACH_DEV(pid) {
+               struct rte_port *port;
+               uint64_t rx_offloads;
+
+               port = &ports[pid];
+               rx_offloads = port->dev_conf.rxmode.offloads;
+               if (!strcmp(res->name, "crc-strip")) {
+                       if (!strcmp(res->value, "on"))
+                               rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
+                       else if (!strcmp(res->value, "off"))
+                               rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
+                       else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
+               } else if (!strcmp(res->name, "scatter")) {
+                       if (!strcmp(res->value, "on")) {
+                               rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
+                       } else if (!strcmp(res->value, "off")) {
+                               rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
+                       } else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
+               } else if (!strcmp(res->name, "rx-cksum")) {
+                       if (!strcmp(res->value, "on"))
+                               rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
+                       else if (!strcmp(res->value, "off"))
+                               rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
+                       else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
+               } else if (!strcmp(res->name, "rx-timestamp")) {
+                       if (!strcmp(res->value, "on"))
+                               rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
+                       else if (!strcmp(res->value, "off"))
+                               rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
+                       else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
+               } else if (!strcmp(res->name, "hw-vlan")) {
+                       if (!strcmp(res->value, "on")) {
+                               rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
+                                               DEV_RX_OFFLOAD_VLAN_STRIP);
+                       } else if (!strcmp(res->value, "off")) {
+                               rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
+                                               DEV_RX_OFFLOAD_VLAN_STRIP);
+                       } else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
+               } else if (!strcmp(res->name, "hw-vlan-filter")) {
+                       if (!strcmp(res->value, "on"))
+                               rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
+                       else if (!strcmp(res->value, "off"))
+                               rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
+                       else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
+               } else if (!strcmp(res->name, "hw-vlan-strip")) {
+                       if (!strcmp(res->value, "on"))
+                               rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
+                       else if (!strcmp(res->value, "off"))
+                               rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
+                       else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
+               } else if (!strcmp(res->name, "hw-vlan-extend")) {
+                       if (!strcmp(res->value, "on"))
+                               rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
+                       else if (!strcmp(res->value, "off"))
+                               rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
+                       else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
+               } else if (!strcmp(res->name, "drop-en")) {
+                       if (!strcmp(res->value, "on"))
+                               rx_drop_en = 1;
+                       else if (!strcmp(res->value, "off"))
+                               rx_drop_en = 0;
+                       else {
+                               printf("Unknown parameter\n");
+                               return;
+                       }
                } else {
                        printf("Unknown parameter\n");
                        return;
                }
-       } else if (!strcmp(res->name, "rx-cksum")) {
-               if (!strcmp(res->value, "on"))
-                       rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
-               else if (!strcmp(res->value, "off"))
-                       rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
-               else {
-                       printf("Unknown parameter\n");
-                       return;
-               }
-       } else if (!strcmp(res->name, "rx-timestamp")) {
-               if (!strcmp(res->value, "on"))
-                       rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
-               else if (!strcmp(res->value, "off"))
-                       rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
-               else {
-                       printf("Unknown parameter\n");
-                       return;
-               }
-       } else if (!strcmp(res->name, "hw-vlan")) {
-               if (!strcmp(res->value, "on")) {
-                       rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
-                                       DEV_RX_OFFLOAD_VLAN_STRIP);
-               }
-               else if (!strcmp(res->value, "off")) {
-                       rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
-                                       DEV_RX_OFFLOAD_VLAN_STRIP);
-               }
-               else {
-                       printf("Unknown parameter\n");
-                       return;
-               }
-       } else if (!strcmp(res->name, "hw-vlan-filter")) {
-               if (!strcmp(res->value, "on"))
-                       rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
-               else if (!strcmp(res->value, "off"))
-                       rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
-               else {
-                       printf("Unknown parameter\n");
-                       return;
-               }
-       } else if (!strcmp(res->name, "hw-vlan-strip")) {
-               if (!strcmp(res->value, "on"))
-                       rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
-               else if (!strcmp(res->value, "off"))
-                       rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
-               else {
-                       printf("Unknown parameter\n");
-                       return;
-               }
-       } else if (!strcmp(res->name, "hw-vlan-extend")) {
-               if (!strcmp(res->value, "on"))
-                       rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
-               else if (!strcmp(res->value, "off"))
-                       rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
-               else {
-                       printf("Unknown parameter\n");
-                       return;
-               }
-       } else if (!strcmp(res->name, "drop-en")) {
-               if (!strcmp(res->value, "on"))
-                       rx_drop_en = 1;
-               else if (!strcmp(res->value, "off"))
-                       rx_drop_en = 0;
-               else {
-                       printf("Unknown parameter\n");
-                       return;
-               }
-       } else {
-               printf("Unknown parameter\n");
-               return;
+               port->dev_conf.rxmode.offloads = rx_offloads;
        }
-       rx_mode.offloads = rx_offloads;
 
        init_port_config();
 
index 455bea4..20a31d0 100644 (file)
@@ -2675,21 +2675,26 @@ vlan_extend_set(portid_t port_id, int on)
 {
        int diag;
        int vlan_offload;
+       uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
 
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
 
        vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
 
-       if (on)
+       if (on) {
                vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
-       else
+               port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
+       } else {
                vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
+               port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
+       }
 
        diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
        if (diag < 0)
                printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
               "diag=%d\n", port_id, on, diag);
+       ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
 }
 
 void
@@ -2697,21 +2702,26 @@ rx_vlan_strip_set(portid_t port_id, int on)
 {
        int diag;
        int vlan_offload;
+       uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
 
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
 
        vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
 
-       if (on)
+       if (on) {
                vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
-       else
+               port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
+       } else {
                vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
+               port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
+       }
 
        diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
        if (diag < 0)
                printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
               "diag=%d\n", port_id, on, diag);
+       ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
 }
 
 void
@@ -2733,21 +2743,26 @@ rx_vlan_filter_set(portid_t port_id, int on)
 {
        int diag;
        int vlan_offload;
+       uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
 
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
 
        vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
 
-       if (on)
+       if (on) {
                vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
-       else
+               port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
+       } else {
                vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
+               port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
+       }
 
        diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
        if (diag < 0)
                printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
               "diag=%d\n", port_id, on, diag);
+       ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
 }
 
 int
index 12430ac..e73d162 100644 (file)
@@ -575,6 +575,7 @@ init_config(void)
                port = &ports[pid];
                /* Apply default Tx configuration for all ports */
                port->dev_conf.txmode = tx_mode;
+               port->dev_conf.rxmode = rx_mode;
                rte_eth_dev_info_get(pid, &port->dev_info);
 
                if (numa_support) {
@@ -2061,7 +2062,6 @@ init_port_config(void)
 
        RTE_ETH_FOREACH_DEV(pid) {
                port = &ports[pid];
-               port->dev_conf.rxmode = rx_mode;
                port->dev_conf.fdir_conf = fdir_conf;
                if (nb_rxq > 1) {
                        port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;