Commit 31afd6bc authored by Christian Marangi's avatar Christian Marangi Committed by Jakub Kicinski
Browse files

net: phy: pass PHY driver to .match_phy_device OP



Pass PHY driver pointer to .match_phy_device OP in addition to phydev.
Having access to the PHY driver struct might be useful to check the
PHY ID of the driver is being matched for in case the PHY ID scanned in
the phydev is not consistent.

A scenario for this is a PHY that change PHY ID after a firmware is
loaded, in such case, the PHY ID stored in PHY device struct is not
valid anymore and PHY will manually scan the ID in the match_phy_device
function.

Having the PHY driver info is also useful for those PHY driver that
implement multiple simple .match_phy_device OP to match specific MMD PHY
ID. With this extra info if the parsing logic is the same, the matching
function can be generalized by using the phy_id in the PHY driver
instead of hardcoding.

Rust wrapper callback is updated to align to the new match_phy_device
arguments.

Suggested-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: default avatarChristian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Benno Lossin <lossin@kernel.org> # for Rust
Reviewed-by: default avatarFUJITA Tomonori <fujita.tomonori@gmail.com>
Link: https://patch.msgid.link/20250517201353.5137-2-ansuelsmth@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d42d4407
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -185,12 +185,14 @@ static irqreturn_t bcm87xx_handle_interrupt(struct phy_device *phydev)
	return IRQ_HANDLED;
}

static int bcm8706_match_phy_device(struct phy_device *phydev)
static int bcm8706_match_phy_device(struct phy_device *phydev,
				    const struct phy_driver *phydrv)
{
	return phydev->c45_ids.device_ids[4] == PHY_ID_BCM8706;
}

static int bcm8727_match_phy_device(struct phy_device *phydev)
static int bcm8727_match_phy_device(struct phy_device *phydev,
				    const struct phy_driver *phydrv)
{
	return phydev->c45_ids.device_ids[4] == PHY_ID_BCM8727;
}
+4 −2
Original line number Diff line number Diff line
@@ -520,12 +520,14 @@ static int ip101a_g_match_phy_device(struct phy_device *phydev, bool ip101a)
	return ip101a == !ret;
}

static int ip101a_match_phy_device(struct phy_device *phydev)
static int ip101a_match_phy_device(struct phy_device *phydev,
				   const struct phy_driver *phydrv)
{
	return ip101a_g_match_phy_device(phydev, true);
}

static int ip101g_match_phy_device(struct phy_device *phydev)
static int ip101g_match_phy_device(struct phy_device *phydev,
				   const struct phy_driver *phydrv)
{
	return ip101a_g_match_phy_device(phydev, false);
}
+8 −4
Original line number Diff line number Diff line
@@ -1264,7 +1264,8 @@ static int mv3310_get_number_of_ports(struct phy_device *phydev)
	return ret + 1;
}

static int mv3310_match_phy_device(struct phy_device *phydev)
static int mv3310_match_phy_device(struct phy_device *phydev,
				   const struct phy_driver *phydrv)
{
	if ((phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] &
	     MARVELL_PHY_ID_MASK) != MARVELL_PHY_ID_88X3310)
@@ -1273,7 +1274,8 @@ static int mv3310_match_phy_device(struct phy_device *phydev)
	return mv3310_get_number_of_ports(phydev) == 1;
}

static int mv3340_match_phy_device(struct phy_device *phydev)
static int mv3340_match_phy_device(struct phy_device *phydev,
				   const struct phy_driver *phydrv)
{
	if ((phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] &
	     MARVELL_PHY_ID_MASK) != MARVELL_PHY_ID_88X3310)
@@ -1297,12 +1299,14 @@ static int mv211x_match_phy_device(struct phy_device *phydev, bool has_5g)
	return !!(val & MDIO_PCS_SPEED_5G) == has_5g;
}

static int mv2110_match_phy_device(struct phy_device *phydev)
static int mv2110_match_phy_device(struct phy_device *phydev,
				   const struct phy_driver *phydrv)
{
	return mv211x_match_phy_device(phydev, true);
}

static int mv2111_match_phy_device(struct phy_device *phydev)
static int mv2111_match_phy_device(struct phy_device *phydev,
				   const struct phy_driver *phydrv)
{
	return mv211x_match_phy_device(phydev, false);
}
+4 −2
Original line number Diff line number Diff line
@@ -768,7 +768,8 @@ static int ksz8051_ksz8795_match_phy_device(struct phy_device *phydev,
		return !ret;
}

static int ksz8051_match_phy_device(struct phy_device *phydev)
static int ksz8051_match_phy_device(struct phy_device *phydev,
				    const struct phy_driver *phydrv)
{
	return ksz8051_ksz8795_match_phy_device(phydev, true);
}
@@ -888,7 +889,8 @@ static int ksz8061_config_init(struct phy_device *phydev)
	return kszphy_config_init(phydev);
}

static int ksz8795_match_phy_device(struct phy_device *phydev)
static int ksz8795_match_phy_device(struct phy_device *phydev,
				    const struct phy_driver *phydrv)
{
	return ksz8051_ksz8795_match_phy_device(phydev, false);
}
+8 −4
Original line number Diff line number Diff line
@@ -1966,25 +1966,29 @@ static int nxp_c45_macsec_ability(struct phy_device *phydev)
	return macsec_ability;
}

static int tja1103_match_phy_device(struct phy_device *phydev)
static int tja1103_match_phy_device(struct phy_device *phydev,
				    const struct phy_driver *phydrv)
{
	return phy_id_compare(phydev->phy_id, PHY_ID_TJA_1103, PHY_ID_MASK) &&
	       !nxp_c45_macsec_ability(phydev);
}

static int tja1104_match_phy_device(struct phy_device *phydev)
static int tja1104_match_phy_device(struct phy_device *phydev,
				    const struct phy_driver *phydrv)
{
	return phy_id_compare(phydev->phy_id, PHY_ID_TJA_1103, PHY_ID_MASK) &&
	       nxp_c45_macsec_ability(phydev);
}

static int tja1120_match_phy_device(struct phy_device *phydev)
static int tja1120_match_phy_device(struct phy_device *phydev,
				    const struct phy_driver *phydrv)
{
	return phy_id_compare(phydev->phy_id, PHY_ID_TJA_1120, PHY_ID_MASK) &&
	       !nxp_c45_macsec_ability(phydev);
}

static int tja1121_match_phy_device(struct phy_device *phydev)
static int tja1121_match_phy_device(struct phy_device *phydev,
				    const struct phy_driver *phydrv)
{
	return phy_id_compare(phydev->phy_id, PHY_ID_TJA_1120, PHY_ID_MASK) &&
	       nxp_c45_macsec_ability(phydev);
Loading