diff mbox series

[net,v4,2/3] net: wangxun: match VLAN CTAG and STAG features

Message ID 20240514072330.14340-3-jiawenwu@trustnetic.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Wangxun fixes | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 925 this patch: 925
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 936 this patch: 936
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 936 this patch: 936
netdev/checkpatch warning WARNING: line length of 85 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 28 this patch: 28
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-17--00-00 (tests: 1034)

Commit Message

Jiawen Wu May 14, 2024, 7:23 a.m. UTC
Hardware requires VLAN CTAG and STAG configuration always matches. And
whether VLAN CTAG or STAG changes, the configuration needs to be changed
as well.

Fixes: 6670f1ece2c8 ("net: txgbe: Add netdev features support")
Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
Reviewed-by: Sai Krishna <saikrishnag@marvell.com>
Reviewed-by: Simon Horman <horms@kernel.org>
---
 drivers/net/ethernet/wangxun/libwx/wx_lib.c   | 61 +++++++++++++++++++
 drivers/net/ethernet/wangxun/libwx/wx_lib.h   |  2 +
 drivers/net/ethernet/wangxun/ngbe/ngbe_main.c |  1 +
 .../net/ethernet/wangxun/txgbe/txgbe_main.c   |  1 +
 4 files changed, 65 insertions(+)

Comments

Jakub Kicinski May 17, 2024, 2:45 a.m. UTC | #1
On Tue, 14 May 2024 15:23:29 +0800 Jiawen Wu wrote:
> +#define NETIF_VLAN_STRIPPING_FEATURES	(NETIF_F_HW_VLAN_CTAG_RX | \
> +					 NETIF_F_HW_VLAN_STAG_RX)


> +	if (changed & NETIF_VLAN_STRIPPING_FEATURES) {
> +		if (features & NETIF_F_HW_VLAN_CTAG_RX &&
> +		    features & NETIF_F_HW_VLAN_STAG_RX) {
> +			features |= NETIF_VLAN_STRIPPING_FEATURES;

this is a noop, right? It's like checking:

	if (value & 1)
		value |= 1; 

features already have both bits set ORing them in doesn't change much.
Or am I misreading?

All I would have expected was:

	if (features & NETIF_VLAN_STRIPPING_FEATURES != NETIF_VLAN_STRIPPING_FEATURES) {
		/* your "else" clause which resets both */
	}

> +		} else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
> +			 !(features & NETIF_F_HW_VLAN_STAG_RX)) {
> +			features &= ~NETIF_VLAN_STRIPPING_FEATURES;
> +		} else {
> +			features &= ~NETIF_VLAN_STRIPPING_FEATURES;
> +			features |= netdev->features & NETIF_VLAN_STRIPPING_FEATURES;
> +			wx_err(wx, "802.1Q and 802.1ad VLAN stripping must be either both on or both off.");
> +		}
> +	}
Jiawen Wu May 17, 2024, 3:03 a.m. UTC | #2
On Fri, May 17, 2024 10:46 AM, Jakub Kicinski wrote:
> On Tue, 14 May 2024 15:23:29 +0800 Jiawen Wu wrote:
> > +#define NETIF_VLAN_STRIPPING_FEATURES	(NETIF_F_HW_VLAN_CTAG_RX | \
> > +					 NETIF_F_HW_VLAN_STAG_RX)
> 
> 
> > +	if (changed & NETIF_VLAN_STRIPPING_FEATURES) {
> > +		if (features & NETIF_F_HW_VLAN_CTAG_RX &&
> > +		    features & NETIF_F_HW_VLAN_STAG_RX) {
> > +			features |= NETIF_VLAN_STRIPPING_FEATURES;
> 
> this is a noop, right? It's like checking:
> 
> 	if (value & 1)
> 		value |= 1;
> 
> features already have both bits set ORing them in doesn't change much.
> Or am I misreading?
> 
> All I would have expected was:
> 
> 	if (features & NETIF_VLAN_STRIPPING_FEATURES != NETIF_VLAN_STRIPPING_FEATURES) {
> 		/* your "else" clause which resets both */
> 	}
> 
> > +		} else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
> > +			 !(features & NETIF_F_HW_VLAN_STAG_RX)) {
> > +			features &= ~NETIF_VLAN_STRIPPING_FEATURES;
> > +		} else {
> > +			features &= ~NETIF_VLAN_STRIPPING_FEATURES;
> > +			features |= netdev->features & NETIF_VLAN_STRIPPING_FEATURES;
> > +			wx_err(wx, "802.1Q and 802.1ad VLAN stripping must be either both on or both off.");
> > +		}
> > +	}

Right. Looks like I just need to keep the "else" part and remove others.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
index 667a5675998c..28599e03cf4e 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
@@ -2701,6 +2701,67 @@  int wx_set_features(struct net_device *netdev, netdev_features_t features)
 }
 EXPORT_SYMBOL(wx_set_features);
 
+#define NETIF_VLAN_STRIPPING_FEATURES	(NETIF_F_HW_VLAN_CTAG_RX | \
+					 NETIF_F_HW_VLAN_STAG_RX)
+
+#define NETIF_VLAN_INSERTION_FEATURES	(NETIF_F_HW_VLAN_CTAG_TX | \
+					 NETIF_F_HW_VLAN_STAG_TX)
+
+#define NETIF_VLAN_FILTERING_FEATURES	(NETIF_F_HW_VLAN_CTAG_FILTER | \
+					 NETIF_F_HW_VLAN_STAG_FILTER)
+
+netdev_features_t wx_fix_features(struct net_device *netdev,
+				  netdev_features_t features)
+{
+	netdev_features_t changed = netdev->features ^ features;
+	struct wx *wx = netdev_priv(netdev);
+
+	if (changed & NETIF_VLAN_STRIPPING_FEATURES) {
+		if (features & NETIF_F_HW_VLAN_CTAG_RX &&
+		    features & NETIF_F_HW_VLAN_STAG_RX) {
+			features |= NETIF_VLAN_STRIPPING_FEATURES;
+		} else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
+			 !(features & NETIF_F_HW_VLAN_STAG_RX)) {
+			features &= ~NETIF_VLAN_STRIPPING_FEATURES;
+		} else {
+			features &= ~NETIF_VLAN_STRIPPING_FEATURES;
+			features |= netdev->features & NETIF_VLAN_STRIPPING_FEATURES;
+			wx_err(wx, "802.1Q and 802.1ad VLAN stripping must be either both on or both off.");
+		}
+	}
+
+	if (changed & NETIF_VLAN_INSERTION_FEATURES) {
+		if (features & NETIF_F_HW_VLAN_CTAG_TX &&
+		    features & NETIF_F_HW_VLAN_STAG_TX) {
+			features |= NETIF_VLAN_INSERTION_FEATURES;
+		} else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
+			 !(features & NETIF_F_HW_VLAN_STAG_TX)) {
+			features &= ~NETIF_VLAN_INSERTION_FEATURES;
+		} else {
+			features &= ~NETIF_VLAN_INSERTION_FEATURES;
+			features |= netdev->features & NETIF_VLAN_INSERTION_FEATURES;
+			wx_err(wx, "802.1Q and 802.1ad VLAN insertion must be either both on or both off.");
+		}
+	}
+
+	if (changed & NETIF_VLAN_FILTERING_FEATURES) {
+		if (features & NETIF_F_HW_VLAN_CTAG_FILTER &&
+		    features & NETIF_F_HW_VLAN_STAG_FILTER) {
+			features |= NETIF_VLAN_FILTERING_FEATURES;
+		} else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
+			 !(features & NETIF_F_HW_VLAN_STAG_FILTER)) {
+			features &= ~NETIF_VLAN_FILTERING_FEATURES;
+		} else {
+			features &= ~NETIF_VLAN_FILTERING_FEATURES;
+			features |= netdev->features & NETIF_VLAN_FILTERING_FEATURES;
+			wx_err(wx, "802.1Q and 802.1ad VLAN filtering must be either both on or both off.");
+		}
+	}
+
+	return features;
+}
+EXPORT_SYMBOL(wx_fix_features);
+
 void wx_set_ring(struct wx *wx, u32 new_tx_count,
 		 u32 new_rx_count, struct wx_ring *temp_ring)
 {
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.h b/drivers/net/ethernet/wangxun/libwx/wx_lib.h
index ec909e876720..c41b29ea812f 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_lib.h
+++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.h
@@ -30,6 +30,8 @@  int wx_setup_resources(struct wx *wx);
 void wx_get_stats64(struct net_device *netdev,
 		    struct rtnl_link_stats64 *stats);
 int wx_set_features(struct net_device *netdev, netdev_features_t features);
+netdev_features_t wx_fix_features(struct net_device *netdev,
+				  netdev_features_t features);
 void wx_set_ring(struct wx *wx, u32 new_tx_count,
 		 u32 new_rx_count, struct wx_ring *temp_ring);
 
diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
index fdd6b4f70b7a..e894e01d030d 100644
--- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
+++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
@@ -499,6 +499,7 @@  static const struct net_device_ops ngbe_netdev_ops = {
 	.ndo_start_xmit         = wx_xmit_frame,
 	.ndo_set_rx_mode        = wx_set_rx_mode,
 	.ndo_set_features       = wx_set_features,
+	.ndo_fix_features       = wx_fix_features,
 	.ndo_validate_addr      = eth_validate_addr,
 	.ndo_set_mac_address    = wx_set_mac,
 	.ndo_get_stats64        = wx_get_stats64,
diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
index bd4624d14ca0..b3c0058b045d 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
@@ -428,6 +428,7 @@  static const struct net_device_ops txgbe_netdev_ops = {
 	.ndo_start_xmit         = wx_xmit_frame,
 	.ndo_set_rx_mode        = wx_set_rx_mode,
 	.ndo_set_features       = wx_set_features,
+	.ndo_fix_features       = wx_fix_features,
 	.ndo_validate_addr      = eth_validate_addr,
 	.ndo_set_mac_address    = wx_set_mac,
 	.ndo_get_stats64        = wx_get_stats64,