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]
Message-ID: <20250113001543.296510-1-marex@denx.de>
Date: Mon, 13 Jan 2025 01:15:35 +0100
From: Marek Vasut <marex@...x.de>
To: netdev@...r.kernel.org
Cc: Marek Vasut <marex@...x.de>,
	"David S. Miller" <davem@...emloft.net>,
	Andrew Lunn <andrew@...n.ch>,
	Eric Dumazet <edumazet@...gle.com>,
	Heiner Kallweit <hkallweit1@...il.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	Russell King <linux@...linux.org.uk>,
	Tristram Ha <tristram.ha@...rochip.com>,
	UNGLinuxDriver@...rochip.com,
	Vladimir Oltean <olteanv@...il.com>,
	Woojung Huh <woojung.huh@...rochip.com>,
	linux-kernel@...r.kernel.org
Subject: [net-next,PATCH 1/2] net: dsa: microchip: Add emulated MIIM access to switch LED config registers

The KSZ87xx switch DSA driver binds a simplified KSZ8795 switch PHY driver to
each port. The KSZ8795 switch PHY driver is part of drivers/net/phy/micrel.c
and uses generic PHY register accessors to access MIIM registers 0x00..0x05,
0x1d and 0x1f . The MII access is implemented by the KSZ87xx switch DSA driver
and internally done over whichever interface the KSZ87xx switch is connected
to the SoC.

In order to configure LEDs from the KSZ8795 switch PHY driver, it is necessary
to expose the LED control registers to the PHY driver, however, the LED control
registers are not part of the MIIM block, they are in Switch Config Registers
block.

This preparatory patch exposes the LED control bits in those Switch Config
Registers by mapping them at high addresses in the MIIM space, so the PHY
driver can access those registers and surely not collide with the existing
MIIM block registers. The two registers which are exposed are the global
Register 11 (0x0B): Global Control 9 as MIIM block register 0x0b00 and
port specific Register 29/45/61 (0x1D/0x2D/0x3D): Port 1/2/3 Control 10
as MIIM block register 0x0d00 . The access to those registers is further
restricted only to the LED configuration bits to prevent the PHY driver
or userspace tools like 'phytool' from tampering with any other switch
configuration through this interface.

Signed-off-by: Marek Vasut <marex@...x.de>
---
Cc: "David S. Miller" <davem@...emloft.net>
Cc: Andrew Lunn <andrew@...n.ch>
Cc: Eric Dumazet <edumazet@...gle.com>
Cc: Heiner Kallweit <hkallweit1@...il.com>
Cc: Jakub Kicinski <kuba@...nel.org>
Cc: Paolo Abeni <pabeni@...hat.com>
Cc: Russell King <linux@...linux.org.uk>
Cc: Tristram Ha <tristram.ha@...rochip.com>
Cc: UNGLinuxDriver@...rochip.com
Cc: Vladimir Oltean <olteanv@...il.com>
Cc: Woojung Huh <woojung.huh@...rochip.com>
Cc: linux-kernel@...r.kernel.org
Cc: netdev@...r.kernel.org
---
 drivers/net/dsa/microchip/ksz8.c | 47 ++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c
index da7110d675583..9698bf53378af 100644
--- a/drivers/net/dsa/microchip/ksz8.c
+++ b/drivers/net/dsa/microchip/ksz8.c
@@ -1044,6 +1044,22 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 			return ret;
 
 		break;
+	/* Emulated access to Register 11 (0x0B): Global Control 9 */
+	case (REG_SW_CTRL_9 << 8):
+		ret = ksz_read8(dev, REG_SW_CTRL_9, &val1);
+		if (ret)
+			return ret;
+
+		data = val1 & 0x30;	/* LED Mode */
+		break;
+	/* Emulated access to Register 29/45/61 (0x1D/0x2D/0x3D): Port 1/2/3 Control 10 */
+	case (REG_PORT_CTRL_10 << 8):
+		ret = ksz_pread8(dev, p, REG_PORT_CTRL_10, &val1);
+		if (ret)
+			return ret;
+
+		data = val1 & BIT(7);	/* LED Off */
+		break;
 	default:
 		processed = false;
 		break;
@@ -1256,6 +1272,37 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 		if (ret)
 			return ret;
 		break;
+
+	/* Emulated access to Register 11 (0x0B): Global Control 9 */
+	case (REG_SW_CTRL_9 << 8):
+		ret = ksz_read8(dev, REG_SW_CTRL_9, &data);
+		if (ret)
+			return ret;
+
+		/* Only ever allow LED Mode update */
+		data &= ~0x30;
+		data |= val & 0x30;
+
+		ret = ksz_write8(dev, REG_SW_CTRL_9, data);
+		if (ret)
+			return ret;
+		break;
+
+	/* Emulated access to Register 29/45/61 (0x1D/0x2D/0x3D): Port 1/2/3 Control 10 */
+	case (REG_PORT_CTRL_10 << 8):
+		ret = ksz_pread8(dev, p, REG_PORT_CTRL_10, &data);
+		if (ret)
+			return ret;
+
+		/* Only ever allow LED Off update */
+		data &= ~BIT(7);
+		data |= val & BIT(7);
+
+		ret = ksz_pwrite8(dev, p, REG_PORT_CTRL_10, data);
+		if (ret)
+			return ret;
+		break;
+
 	default:
 		break;
 	}
-- 
2.45.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ