public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jakub Vaněk" <linuxtardis@gmail.com>
To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: "Andrew Lunn" <andrew@lunn.ch>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	Frank <Frank.Sae@motor-comm.com>,
	"Sai Krishna" <saikrishnag@marvell.com>,
	"Daniel Golle" <daniel@makrotopia.org>,
	"Jakub Vaněk" <linuxtardis@gmail.com>
Subject: [PATCH net-next v2 5/5] net: phy: motorcomm: yt8821: Disable MDIO broadcast
Date: Sun,  1 Mar 2026 00:22:41 +0100	[thread overview]
Message-ID: <20260228232241.1274236-6-linuxtardis@gmail.com> (raw)
In-Reply-To: <20260228232241.1274236-1-linuxtardis@gmail.com>

By default, the YT8821 responds at two MDIO addresses: the address
selected by its strapping pins and the broadcast address 0.
This causes problems if another PHY is legitimately configured
at address 0.

Disable the broadcast address using two mechanisms. The PHY fixup
prevents collisions during initial MDIO bus scanning.
yt8821_config_init() then re-disables the broadcast address if the
PHY goes through a hardware reset (this happens if the PHY has a
reset GPIO on its device tree node, and the interface is brought
down and up).

Link: https://github.com/openwrt/openwrt/pull/21584
Fixes: b671105b88c3 ("net: phy: Add driver for Motorcomm yt8821 2.5G ethernet phy")
Signed-off-by: Jakub Vaněk <linuxtardis@gmail.com>
---
 drivers/net/phy/motorcomm.c         | 29 +++++++++++++++++++++++++
 drivers/net/phy/phy_common_fixups.c | 33 +++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index 4d62f7b36212..e1503fab568a 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -227,6 +227,9 @@
 #define YT8521_LED_100_ON_EN			BIT(5)
 #define YT8521_LED_10_ON_EN			BIT(4)
 
+#define YTPHY_MDIO_ADDRESS_CONTROL_REG		0xA005
+#define YTPHY_MACR_EN_PHY_ADDR_0		BIT(6)
+
 #define YTPHY_MISC_CONFIG_REG			0xA006
 #define YTPHY_MCR_FIBER_SPEED_MASK		BIT(0)
 #define YTPHY_MCR_FIBER_1000BX			(0x1 << 0)
@@ -2764,6 +2767,28 @@ static int yt8821_soft_reset(struct phy_device *phydev)
 					  YT8521_CCR_SW_RST, 0);
 }
 
+/**
+ * yt8821_disable_mdio_address_zero() - disable MDIO broadcast address 0
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * The YT8821 responds on two MDIO addresses by default:
+ *  - the address selected by its strapping pins
+ *  - the broadcast address 0
+ *
+ * Some other PHYs (e.g. the MT7981B internal Gigabit PHY) are hardwired to
+ * respond only at MDIO address 0. If the YT8821 also listens on address 0,
+ * it may incorrectly react to transactions intended for those PHYs.
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8821_disable_mdio_address_zero(struct phy_device *phydev)
+{
+	return ytphy_modify_ext_with_lock(phydev,
+					  YTPHY_MDIO_ADDRESS_CONTROL_REG,
+					  YTPHY_MACR_EN_PHY_ADDR_0,
+					  0);
+}
+
 /**
  * yt8821_config_init() - phy initializatioin
  * @phydev: a pointer to a &struct phy_device
@@ -2799,6 +2824,10 @@ static int yt8821_config_init(struct phy_device *phydev)
 		phydev->rate_matching = RATE_MATCH_PAUSE;
 	}
 
+	ret = yt8821_disable_mdio_address_zero(phydev);
+	if (ret < 0)
+		return ret;
+
 	ret = yt8821_serdes_init(phydev);
 	if (ret < 0)
 		return ret;
diff --git a/drivers/net/phy/phy_common_fixups.c b/drivers/net/phy/phy_common_fixups.c
index fa51c6d7b25f..5a60721b56d6 100644
--- a/drivers/net/phy/phy_common_fixups.c
+++ b/drivers/net/phy/phy_common_fixups.c
@@ -4,6 +4,32 @@
 
 #include "phylib-internal.h"
 
+#define PHY_ID_YT8821				0x4f51ea19
+#define YTPHY_PAGE_SELECT			0x1E
+#define YTPHY_PAGE_DATA				0x1F
+#define YTPHY_MDIO_ADDRESS_CONTROL_REG		0xA005
+#define YTPHY_MACR_EN_PHY_ADDR_0		BIT(6)
+
+/**
+ * yt8821_disable_broadcast - Disable MDIO broadcast on address 0
+ */
+static int yt8821_disable_broadcast(struct phy_device *phydev)
+{
+	int rc = 0;
+
+	phy_lock_mdio_bus(phydev);
+
+	rc = __phy_write(phydev, YTPHY_PAGE_SELECT, YTPHY_MDIO_ADDRESS_CONTROL_REG);
+	if (rc < 0)
+		goto unlock;
+
+	rc = __phy_modify(phydev, YTPHY_PAGE_DATA, YTPHY_MACR_EN_PHY_ADDR_0, 0);
+
+unlock:
+	phy_unlock_mdio_bus(phydev);
+	return rc;
+}
+
 /**
  * phy_register_address_0_fixups - Register fixups for disabling MDIO
  * broadcast address 0
@@ -22,5 +48,12 @@
  */
 int phy_register_address_0_fixups(void)
 {
+	int rc;
+
+	rc = phy_register_fixup_for_uid(PHY_ID_YT8821, 0xFFFFFFFF,
+					yt8821_disable_broadcast);
+	if (rc < 0)
+		return rc;
+
 	return 0;
 }
-- 
2.43.0


  parent reply	other threads:[~2026-02-28 23:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28 23:22 [PATCH net-next v2 0/5] net: phy: Disable MDIO broadcast address on YT8821 Jakub Vaněk
2026-02-28 23:22 ` [PATCH net-next v2 1/5] net: mdiobus: Scan buses in reverse order (31 -> 0) Jakub Vaněk
2026-03-01 15:11   ` Andrew Lunn
2026-03-01 17:03   ` Russell King (Oracle)
2026-03-01 17:24     ` Jakub Vaněk
2026-02-28 23:22 ` [PATCH net-next v2 2/5] of: mdio: Scan PHY address 0 last Jakub Vaněk
2026-02-28 23:22 ` [PATCH net-next v2 3/5] net: phy: Support PHY fixups on Clause 45 PHYs Jakub Vaněk
2026-02-28 23:22 ` [PATCH net-next v2 4/5] net: phy: Add infrastructure for PHY address 0 fixups Jakub Vaněk
2026-02-28 23:22 ` Jakub Vaněk [this message]
2026-03-01  2:43   ` [PATCH net-next v2 5/5] net: phy: motorcomm: yt8821: Disable MDIO broadcast kernel test robot
2026-03-01 16:06 ` [PATCH net-next v2 0/5] net: phy: Disable MDIO broadcast address on YT8821 Andrew Lunn
2026-03-01 17:07   ` Russell King (Oracle)
2026-03-01 17:15   ` Jakub Vaněk

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=20260228232241.1274236-6-linuxtardis@gmail.com \
    --to=linuxtardis@gmail.com \
    --cc=Frank.Sae@motor-comm.com \
    --cc=andrew@lunn.ch \
    --cc=daniel@makrotopia.org \
    --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=pabeni@redhat.com \
    --cc=saikrishnag@marvell.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