mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: netdev@vger.kernel.org
Cc: Marek Vasut <marex@denx.de>,
	"David S. Miller" <davem@davemloft.net>,
	Andrew Lunn <andrew@lunn.ch>, Eric Dumazet <edumazet@google.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Russell King <linux@armlinux.org.uk>,
	Tristram Ha <tristram.ha@microchip.com>,
	UNGLinuxDriver@microchip.com, Vladimir Oltean <olteanv@gmail.com>,
	Woojung Huh <woojung.huh@microchip.com>,
	linux-kernel@vger.kernel.org
Subject: [net-next,PATCH 1/2] net: dsa: microchip: Add emulated MIIM access to switch LED config registers
Date: Mon, 13 Jan 2025 01:15:35 +0100	[thread overview]
Message-ID: <20250113001543.296510-1-marex@denx.de> (raw)

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@denx.de>
---
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tristram Ha <tristram.ha@microchip.com>
Cc: UNGLinuxDriver@microchip.com
Cc: Vladimir Oltean <olteanv@gmail.com>
Cc: Woojung Huh <woojung.huh@microchip.com>
Cc: linux-kernel@vger.kernel.org
Cc: netdev@vger.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


             reply	other threads:[~2025-01-13  0:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13  0:15 Marek Vasut [this message]
2025-01-13  0:15 ` [net-next,PATCH 2/2] net: phy: micrel: Add KSZ87XX Switch LED control Marek Vasut
2025-01-16  9:58   ` Paolo Abeni
2025-01-16 13:23     ` Andrew Lunn
2025-01-20 14:20       ` Marek Vasut
2025-01-16  9:32 ` [net-next,PATCH 1/2] net: dsa: microchip: Add emulated MIIM access to switch LED config registers Paolo Abeni
2025-01-16 13:06 ` Andrew Lunn
2025-01-20 11:59   ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250113001543.296510-1-marex@denx.de \
    --to=marex@denx.de \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=tristram.ha@microchip.com \
    --cc=woojung.huh@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®