Thread (10 messages) 10 messages, 4 authors, 2026-01-05

Re: [PATCH net-next 3/4] net: phy: realtek: use paged access for MDIO_MMD_VEND2 in C22 mode

From: Daniel Golle <daniel@makrotopia.org>
Date: 2026-01-04 22:02:41
Also in: lkml

On Sun, Jan 04, 2026 at 09:23:00PM +0000, Russell King (Oracle) wrote:
On Sun, Jan 04, 2026 at 01:12:13PM +0000, Daniel Golle wrote:
quoted
+static int rtl822xb_read_mmd(struct phy_device *phydev, int devnum, u16 reg)
+{
+	int oldpage, ret, read_ret;
+	u16 page;
+
+	/* Use Clause-45 bus access in case it is available */
+	if (phydev->is_c45)
+		return __mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr,
+					  devnum, mmdreg);
+
+	/* Use indirect access via MII_MMD_CTRL and MII_MMD_DATA for all
+	 * MMDs except MDIO_MMD_VEND2
+	 */
+	if (devnum != MDIO_MMD_VEND2) {
+		__mdiobus_write(phydev->mdio.bus, phydev->mdio.addr,
+				MII_MMD_CTRL, devnum);
+		__mdiobus_write(phydev->mdio.bus, phydev->mdio.addr,
+				MII_MMD_DATA, mmdreg);
+		__mdiobus_write(phydev->mdio.bus, phydev->mdio.addr,
+				MII_MMD_CTRL, devnum | MII_MMD_CTRL_NOINCR);
+
+		return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
+				       MII_MMD_DATA);
+	}
I think I'd prefer this structure:

	if (devnum != MDIO_MMD_VEND2)
		return mmd_phy_read(phydev->mdio.bus, phydev->mdio.addr,
				    phydev->is_c45, devnum, regad);

	if (phydev->is_c45)
		return __mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr,
					  devnum, mmdreg);
Even this would be possible then:
	if (devnum != MDIO_MMD_VEND2 || phydev->is_c45)
		return mmd_phy_read(phydev->mdio.bus, phydev->mdio.addr,
				    phydev->is_c45, devnum, regad);
rather than open-coding the indirect access, or the reverse order with
mmd_phy_read() called with is_c45 set to false.

Same for the write function.
I also thought it'd be good to do that, but that would require moving
the function prototypes from drivers/net/phy/phylib-internal.h to a
public header which the PHY driver may include, eg. phylib.h. (I suppose
that 'phylib-internal.h' should not be included in PHY drivers).

Needless to say that I also don't fancy open-coding unlocked variants
of phy_{read,write}_paged, but that's on a other story...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help