[dpdk-dev] [PATCH 5/5] app/testpmd: enforce offloads caps

Shahaf Shuler shahafs at mellanox.com
Thu Nov 23 13:08:04 CET 2017


In the current design it was possible for offload to be set even though
the device is not supporting it. A warning message was printed instead.

This is a wrong behaviour, as application should set only the offloads
reported by the capabilities of the device.

This patch adds verification for the offloads being set and make sure
the offload configuration passed to the device always match its
capabilities.

Signed-off-by: Shahaf Shuler <shahafs at mellanox.com>
---
 app/test-pmd/cmdline.c | 132 ++++++++++++++++++++++++++++----------------
 app/test-pmd/config.c  |  22 ++++----
 app/test-pmd/testpmd.c |  21 ++++++-
 3 files changed, 115 insertions(+), 60 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 9e3f02ec5..2f099a8e6 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -3639,6 +3639,7 @@ cmd_csum_parsed(void *parsed_result,
 	int hw = 0;
 	uint16_t mask = 0;
 	uint64_t csum_offloads = 0;
+	struct rte_eth_dev_info dev_info;
 
 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
 		printf("invalid port %d\n", res->port_id);
@@ -3649,26 +3650,58 @@ cmd_csum_parsed(void *parsed_result,
 		return;
 	}
 
+	rte_eth_dev_info_get(res->port_id, &dev_info);
 	if (!strcmp(res->mode, "set")) {
 
 		if (!strcmp(res->hwsw, "hw"))
 			hw = 1;
 
 		if (!strcmp(res->proto, "ip")) {
-			mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
-			csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
+			if (dev_info.tx_offload_capa &
+						DEV_TX_OFFLOAD_IPV4_CKSUM) {
+				mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
+				csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
+			} else {
+				printf("IP checksum offload is not supported "
+				       "by port %u\n", res->port_id);
+			}
 		} else if (!strcmp(res->proto, "udp")) {
-			mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
-			csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
+			if (dev_info.tx_offload_capa &
+						DEV_TX_OFFLOAD_UDP_CKSUM) {
+				mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
+				csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
+			} else {
+				printf("UDP checksum offload is not supported "
+				       "by port %u\n", res->port_id);
+			}
 		} else if (!strcmp(res->proto, "tcp")) {
-			mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
-			csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
+			if (dev_info.tx_offload_capa &
+						DEV_TX_OFFLOAD_TCP_CKSUM) {
+				mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
+				csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
+			} else {
+				printf("TCP checksum offload is not supported "
+				       "by port %u\n", res->port_id);
+			}
 		} else if (!strcmp(res->proto, "sctp")) {
-			mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
-			csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
+			if (dev_info.tx_offload_capa &
+						DEV_TX_OFFLOAD_SCTP_CKSUM) {
+				mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
+				csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
+			} else {
+				printf("SCTP checksum offload is not supported "
+				       "by port %u\n", res->port_id);
+			}
 		} else if (!strcmp(res->proto, "outer-ip")) {
-			mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
-			csum_offloads |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
+			if (dev_info.tx_offload_capa &
+					DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
+				mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
+				csum_offloads |=
+						DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
+			} else {
+				printf("Outer IP checksum offload is not "
+				       "supported by port %u\n", res->port_id);
+			}
 		}
 
 		if (hw) {
@@ -3815,6 +3848,14 @@ cmd_tso_set_parsed(void *parsed_result,
 	if (!strcmp(res->mode, "set"))
 		ports[res->port_id].tso_segsz = res->tso_segsz;
 
+	rte_eth_dev_info_get(res->port_id, &dev_info);
+	if ((ports[res->port_id].tso_segsz != 0) &&
+		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
+		printf("Error: TSO is not supported by port %d\n",
+		       res->port_id);
+		return;
+	}
+
 	if (ports[res->port_id].tso_segsz == 0) {
 		ports[res->port_id].dev_conf.txmode.offloads &=
 						~DEV_TX_OFFLOAD_TCP_TSO;
@@ -3826,14 +3867,6 @@ cmd_tso_set_parsed(void *parsed_result,
 			ports[res->port_id].tso_segsz);
 	}
 
-	/* display warnings if configuration is not supported by the NIC */
-	rte_eth_dev_info_get(res->port_id, &dev_info);
-	if ((ports[res->port_id].tso_segsz != 0) &&
-		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
-		printf("Warning: TSO enabled but not "
-			"supported by port %d\n", res->port_id);
-	}
-
 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
 }
 
@@ -3891,24 +3924,25 @@ struct cmd_tunnel_tso_set_result {
 	portid_t port_id;
 };
 
-static void
+static struct rte_eth_dev_info
 check_tunnel_tso_nic_support(portid_t port_id)
 {
 	struct rte_eth_dev_info dev_info;
 
 	rte_eth_dev_info_get(port_id, &dev_info);
 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
-		printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
-		       "supported by port %d\n", port_id);
+		printf("Warning: VXLAN TUNNEL TSO not supported therefore "
+		       "not enabled for port %d\n", port_id);
 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
-		printf("Warning: TSO enabled but GRE TUNNEL TSO not "
-			"supported by port %d\n", port_id);
+		printf("Warning: GRE TUNNEL TSO	not supported therefore "
+		       "not enabled for port %d\n", port_id);
 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
-		printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
-		       "supported by port %d\n", port_id);
+		printf("Warning: IPIP TUNNEL TSO not supported therefore "
+		       "not enabled for port %d\n", port_id);
 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
-		printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
-		       "supported by port %d\n", port_id);
+		printf("Warning: GENEVE TUNNEL TSO not supported therefore "
+		       "not enabled for port %d\n", port_id);
+	return dev_info;
 }
 
 static void
@@ -3917,6 +3951,7 @@ cmd_tunnel_tso_set_parsed(void *parsed_result,
 			  __attribute__((unused)) void *data)
 {
 	struct cmd_tunnel_tso_set_result *res = parsed_result;
+	struct rte_eth_dev_info dev_info;
 
 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
 		return;
@@ -3928,6 +3963,7 @@ cmd_tunnel_tso_set_parsed(void *parsed_result,
 	if (!strcmp(res->mode, "set"))
 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
 
+	dev_info = check_tunnel_tso_nic_support(res->port_id);
 	if (ports[res->port_id].tunnel_tso_segsz == 0) {
 		ports[res->port_id].dev_conf.txmode.offloads &=
 			~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
@@ -3936,11 +3972,13 @@ cmd_tunnel_tso_set_parsed(void *parsed_result,
 			  DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
 		printf("TSO for tunneled packets is disabled\n");
 	} else {
+		uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+					 DEV_TX_OFFLOAD_GRE_TNL_TSO |
+					 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
+					 DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
+
 		ports[res->port_id].dev_conf.txmode.offloads |=
-			(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
-			 DEV_TX_OFFLOAD_GRE_TNL_TSO |
-			 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
-			 DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
+			(tso_offloads & dev_info.tx_offload_capa);
 		printf("TSO segment size for tunneled packets is %d\n",
 			ports[res->port_id].tunnel_tso_segsz);
 
@@ -3955,7 +3993,6 @@ cmd_tunnel_tso_set_parsed(void *parsed_result,
 		 * is not necessary for IPv6 tunneled pkts because there's no
 		 * checksum in IP header anymore.
 		 */
-		check_tunnel_tso_nic_support(res->port_id);
 
 		if (!(ports[res->port_id].tx_ol_flags &
 		      TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
@@ -13014,23 +13051,20 @@ cmd_set_macsec_offload_on_parsed(
 		printf("Please stop all ports first\n");
 		return;
 	}
-
-	ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
-	ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_MACSEC_INSERT;
+	rte_eth_dev_info_get(port_id, &dev_info);
+	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
 #ifdef RTE_LIBRTE_IXGBE_PMD
-	ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
+		ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
 #endif
+	}
 	RTE_SET_USED(en);
 	RTE_SET_USED(rp);
 
 	switch (ret) {
 	case 0:
-		rte_eth_dev_info_get(port_id, &dev_info);
-		if ((dev_info.tx_offload_capa &
-		     DEV_TX_OFFLOAD_MACSEC_INSERT) == 0) {
-			printf("Warning: macsec insert enabled but not "
-				"supported by port %d\n", port_id);
-		}
+		ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
+		ports[port_id].dev_conf.txmode.offloads |=
+						DEV_TX_OFFLOAD_MACSEC_INSERT;
 		cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
 		break;
 	case -ENODEV:
@@ -13102,6 +13136,7 @@ cmd_set_macsec_offload_off_parsed(
 {
 	struct cmd_macsec_offload_off_result *res = parsed_result;
 	int ret = -ENOTSUP;
+	struct rte_eth_dev_info dev_info;
 	portid_t port_id = res->port_id;
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN))
@@ -13110,16 +13145,17 @@ cmd_set_macsec_offload_off_parsed(
 		printf("Please stop all ports first\n");
 		return;
 	}
-
-	ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
-	ports[port_id].dev_conf.txmode.offloads &=
-					~DEV_TX_OFFLOAD_MACSEC_INSERT;
+	rte_eth_dev_info_get(port_id, &dev_info);
+	if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
 #ifdef RTE_LIBRTE_IXGBE_PMD
-	ret = rte_pmd_ixgbe_macsec_disable(port_id);
+		ret = rte_pmd_ixgbe_macsec_disable(port_id);
 #endif
-
+	}
 	switch (ret) {
 	case 0:
+		ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
+		ports[port_id].dev_conf.txmode.offloads &=
+						~DEV_TX_OFFLOAD_MACSEC_INSERT;
 		cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
 		break;
 	case -ENODEV:
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 089e9f4cf..a20df307b 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -2790,16 +2790,17 @@ tx_vlan_set(portid_t port_id, uint16_t vlan_id)
 		printf("Error, as QinQ has been enabled.\n");
 		return;
 	}
+	rte_eth_dev_info_get(port_id, &dev_info);
+	if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
+		printf("Error: vlan insert is not supported by port %d\n",
+			port_id);
+		return;
+	}
 
 	tx_vlan_reset(port_id);
 	ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
 	ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
 	ports[port_id].tx_vlan_id = vlan_id;
-	rte_eth_dev_info_get(port_id, &dev_info);
-	if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) {
-		printf("Warning: vlan insert enabled but not "
-		       "supported by port %d\n", port_id);
-	}
 }
 
 void
@@ -2820,17 +2821,18 @@ tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
 		printf("Error, as QinQ hasn't been enabled.\n");
 		return;
 	}
+	rte_eth_dev_info_get(port_id, &dev_info);
+	if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
+		printf("Error: qinq insert not supported by port %d\n",
+			port_id);
+		return;
+	}
 
 	tx_vlan_reset(port_id);
 	ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
 	ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_QINQ_INSERT;
 	ports[port_id].tx_vlan_id = vlan_id;
 	ports[port_id].tx_vlan_id_outer = vlan_id_outer;
-	rte_eth_dev_info_get(port_id, &dev_info);
-	if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) {
-		printf("Warning: qinq insert enabled but not "
-		       "supported by port %d\n", port_id);
-	}
 }
 
 void
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 2550677c3..2b8142162 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -601,10 +601,18 @@ init_config(void)
 
 	RTE_ETH_FOREACH_DEV(pid) {
 		port = &ports[pid];
+		rte_eth_dev_info_get(pid, &port->dev_info);
 		/* Apply default Tx configuration for all ports */
 		port->dev_conf.txmode = tx_mode;
-		rte_eth_dev_info_get(pid, &port->dev_info);
-
+		if ((port->dev_info.tx_offload_capa & tx_mode.offloads) !=
+		     tx_mode.offloads) {
+			printf("Some Tx offloads are not supported "
+			       "by port %d: requested 0x%lx supported 0x%lx\n",
+			       pid, tx_mode.offloads,
+			       port->dev_info.tx_offload_capa);
+			port->dev_conf.txmode.offloads &=
+						port->dev_info.tx_offload_capa;
+		}
 		if (numa_support) {
 			if (port_numa[pid] != NUMA_NO_CONFIG)
 				port_per_socket[port_numa[pid]]++;
@@ -2082,6 +2090,15 @@ init_port_config(void)
 	RTE_ETH_FOREACH_DEV(pid) {
 		port = &ports[pid];
 		port->dev_conf.rxmode = rx_mode;
+		if ((port->dev_info.rx_offload_capa & rx_mode.offloads) !=
+		    rx_mode.offloads) {
+			printf("Some Rx offloads are not supported "
+			       "by port %d: requested 0x%lx supported 0x%lx\n",
+			       pid, rx_mode.offloads,
+			       port->dev_info.rx_offload_capa);
+			port->dev_conf.rxmode.offloads &=
+						port->dev_info.rx_offload_capa;
+		}
 		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