[dpdk-dev] [PATCH v3 10/10] app/testpmd: fix on the flight VLAN configuration

Shahaf Shuler shahafs at mellanox.com
Tue Dec 26 10:44:24 CET 2017


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.

Fixes: 6dbb2b336586 ("app/testpmd: convert to new Ethdev Rx offloads API")

Signed-off-by: Shahaf Shuler <shahafs at mellanox.com>
---
 app/test-pmd/cmdline.c | 217 +++++++++++++++++++++++---------------------
 app/test-pmd/config.c  |  27 ++++--
 app/test-pmd/testpmd.c |   2 +-
 3 files changed, 135 insertions(+), 111 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index d1b8dab6e..00a229a41 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -1577,34 +1577,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);
@@ -1706,103 +1710,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();
 
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index d32a4672b..da968cb64 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -2665,21 +2665,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
@@ -2687,21 +2692,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
@@ -2723,21 +2733,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
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 91dcb31c0..c1fb387fb 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -603,6 +603,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) {
@@ -2089,7 +2090,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;
-- 
2.12.0



More information about the dev mailing list