lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu,  1 Jun 2023 09:46:21 +0200
From: Magnus Karlsson <magnus.karlsson@...il.com>
To: magnus.karlsson@...el.com,
	intel-wired-lan@...ts.osuosl.org,
	anthony.l.nguyen@...el.com,
	maciej.fijalkowski@...el.com,
	hao.ma@...el.com
Cc: netdev@...r.kernel.org
Subject: [PATCH iwl-next] ixgbe: allow toggling loopback mode via ndo_set_features callback

From: Hao Ma <hao.ma@...el.com>

Add support for NETIF_F_LOOPBACK. This feature can be set via: $
ethtool -K eth0 loopback <on|off>. This sets the MAC Tx->Rx loopback
used by selftests/bpf/xskxceiver.

Signed-off-by: Hao Ma <hao.ma@...el.com>
---
 .../net/ethernet/intel/ixgbe/ixgbe_common.c   |  4 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 73 +++++++++++++++++++
 drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  1 +
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
index 878dd8dff528..b8998a56ad24 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
@@ -3337,7 +3337,7 @@ s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
 
 	if (link_up_wait_to_complete) {
 		for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
-			if (links_reg & IXGBE_LINKS_UP) {
+			if (links_reg & IXGBE_LINKS_UP || hw->loopback_on) {
 				*link_up = true;
 				break;
 			} else {
@@ -3347,7 +3347,7 @@ s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
 			links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
 		}
 	} else {
-		if (links_reg & IXGBE_LINKS_UP) {
+		if (links_reg & IXGBE_LINKS_UP || hw->loopback_on) {
 			if (crosstalk_fix_active) {
 				/* Check the link state again after a delay
 				 * to filter out spurious link up
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 5d83c887a3fc..70b34b7b5cb0 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -8864,6 +8864,57 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
 	return NETDEV_TX_OK;
 }
 
+static int ixgbe_force_loopback(struct ixgbe_adapter *adapter, bool on)
+{	struct ixgbe_hw *hw = &adapter->hw;
+	u32 reg_data;
+
+	hw->loopback_on = on;
+	/* Setup MAC loopback */
+	reg_data = IXGBE_READ_REG(hw, IXGBE_HLREG0);
+	if (on)
+		reg_data |= IXGBE_HLREG0_LPBK;
+	else
+		reg_data &= ~IXGBE_HLREG0_LPBK;
+	IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_data);
+
+	reg_data = IXGBE_READ_REG(hw, IXGBE_FCTRL);
+	if (on)
+		reg_data |= IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE;
+	else
+		reg_data &= ~(IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE);
+	reg_data &= ~(IXGBE_FCTRL_BAM);
+	IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg_data);
+
+	/* X540 and X550 needs to set the MACC.FLU bit to force link up */
+	switch (adapter->hw.mac.type) {
+	case ixgbe_mac_X540:
+	case ixgbe_mac_X550:
+	case ixgbe_mac_X550EM_x:
+	case ixgbe_mac_x550em_a:
+		reg_data = IXGBE_READ_REG(hw, IXGBE_MACC);
+		if (on)
+			reg_data |= IXGBE_MACC_FLU;
+		else
+			reg_data &= ~IXGBE_MACC_FLU;
+		IXGBE_WRITE_REG(hw, IXGBE_MACC, reg_data);
+		break;
+	default:
+		if (hw->mac.orig_autoc) {
+			if (on)
+				reg_data = hw->mac.orig_autoc | IXGBE_AUTOC_FLU;
+			else
+				reg_data = hw->mac.orig_autoc & ~IXGBE_AUTOC_FLU;
+			IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_data);
+		} else {
+			return 10;
+		}
+	}
+
+	IXGBE_WRITE_FLUSH(hw);
+
+	return 0;
+}
+
 static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
 				      struct net_device *netdev,
 				      struct ixgbe_ring *ring)
@@ -9915,6 +9966,15 @@ static int ixgbe_set_features(struct net_device *netdev,
 	if (changed & NETIF_F_RXALL)
 		need_reset = true;
 
+	if (changed & NETIF_F_LOOPBACK) {
+		if (features & NETIF_F_LOOPBACK) {
+			ixgbe_force_loopback(adapter, true);
+		} else {
+			ixgbe_force_loopback(adapter, false);
+			need_reset = true;
+			}
+	}
+
 	netdev->features = features;
 
 	if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
@@ -10286,6 +10346,17 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
 			/* Wait until ndo_xsk_wakeup completes. */
 			synchronize_rcu();
 		err = ixgbe_setup_tc(dev, adapter->hw_tcs);
+		if (adapter->hw.loopback_on) {
+			u32 reg_data;
+
+			reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0);
+			reg_data |= IXGBE_HLREG0_LPBK;
+			IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data);
+
+			reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_MACC);
+			reg_data |= IXGBE_MACC_FLU;
+			IXGBE_WRITE_REG(&adapter->hw, IXGBE_MACC, reg_data);
+		}
 
 		if (err)
 			return -EINVAL;
@@ -10969,6 +11040,8 @@ static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (hw->mac.type >= ixgbe_mac_82599EB)
 		netdev->features |= NETIF_F_SCTP_CRC | NETIF_F_GSO_UDP_L4;
 
+	netdev->features |= NETIF_F_LOOPBACK;
+
 #ifdef CONFIG_IXGBE_IPSEC
 #define IXGBE_ESP_FEATURES	(NETIF_F_HW_ESP | \
 				 NETIF_F_HW_ESP_TX_CSUM | \
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
index 2b00db92b08f..ca50ccd59b50 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
@@ -3652,6 +3652,7 @@ struct ixgbe_hw {
 	bool				allow_unsupported_sfp;
 	bool				wol_enabled;
 	bool				need_crosstalk_fix;
+	bool				loopback_on;
 };
 
 struct ixgbe_info {

base-commit: 735c9ee9a374769b78c716de3c19a6c9440ede85
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ