Skip to contentSkip to conversation

net: phy: micrel: Discern KSZ8051 and KSZ8795 PHYs

PATCH Superseded Marek Vasut 3 participants 8 messages Oct 10, 2019 – Oct 13, 2019

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 net: phy: micrel: Discern KSZ8051 and KSZ8795 PHYs

The KSZ8051 PHY and the KSZ8794/KSZ8795/KSZ8765 switch share exactly the same PHY ID. Since KSZ8051 is higher in the ksphy_driver[] list of PHYs in the micrel PHY driver, it is used even with the KSZ87xx switch. This is wrong, since the KSZ8051 configures registers of the PHY which are not present on the simplified KSZ87xx switch PHYs and misconfigures other registers of the KSZ87xx switch PHYs.

Fortunatelly, it is possible to tell apart the KSZ8051 PHY from the KSZ87xx switch by checking the Basic Status register Bit 0, which is read-only and indicates presence of the Extended Capability Registers. The KSZ8051 PHY has those registers while the KSZ87xx switch does not.

This patch implements simple check for the presence of this bit for both the KSZ8051 PHY and KSZ87xx switch, to let both use the correct PHY driver instance.

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc George McCollister <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Woojung Huh <[email protected]>

---
NOTE: It was also suggested to populate phydev->dev_flags to discern
the PHY from the switch, this does not work for setups where the switch is used as a PHY without a DSA driver. Checking the BMSR Bit 0 for Extended Capability Register works for both DSA and non-DSA usecase.
V2: Move phy_id check into ksz8051_match_phy_device() and
ksz8795_match_phy_device() and drop phy_id{,_mask} from the ksphy_driver[] list to avoid matching on other PHY IDs.

---
 drivers/net/phy/micrel.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
drivers/net/phy/micrel.c +36 -4
index 2fea5541c35a..028a4a177790 100644
@@ -341,6 +341,25 @@ static int ksz8041_config_aneg(struct phy_device *phydev)
 	return genphy_config_aneg(phydev);
 }
 
+static int ksz8051_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8051)
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* KSZ8051 PHY and KSZ8794/KSZ8795/KSZ8765 switch share the same
+	 * exact PHY ID. However, they can be told apart by the extended
+	 * capability registers presence. The KSZ8051 PHY has them while
+	 * the switch does not.
+	 */
+	return ret & BMSR_ERCAP;
+}
+
 static int ksz8081_config_init(struct phy_device *phydev)
 {
 	/* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line
@@ -364,6 +383,21 @@ static int ksz8061_config_init(struct phy_device *phydev)
 	return kszphy_config_init(phydev);
 }
 
+static int ksz8795_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8795)
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* See comment in ksz8051_match_phy_device() for details. */
+	return !(ret & BMSR_ERCAP);
+}
+
 static int ksz9021_load_values_from_of(struct phy_device *phydev,
 				       const struct device_node *of_node,
 				       u16 reg,
@@ -1017,8 +1051,6 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8051,
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8051",
 	/* PHY_BASIC_FEATURES */
 	.driver_data	= &ksz8051_type,
@@ -1029,6 +1061,7 @@ static struct phy_driver ksphy_driver[] = {
 	.get_sset_count = kszphy_get_sset_count,
 	.get_strings	= kszphy_get_strings,
 	.get_stats	= kszphy_get_stats,
+	.match_phy_device = ksz8051_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
@@ -1141,13 +1174,12 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8795,
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8795",
 	/* PHY_BASIC_FEATURES */
 	.config_init	= kszphy_config_init,
 	.config_aneg	= ksz8873mll_config_aneg,
 	.read_status	= ksz8873mll_read_status,
+	.match_phy_device = ksz8795_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
Signature · 1 line
2.23.0
#1 lore raw

PATCH v2 2/2 net: phy: micrel: Update KSZ87xx PHY name

The KSZ8795 PHY ID is in fact used by KSZ8794/KSZ8795/KSZ8765 switches. Update the PHY ID and name to reflect that, as this family of switches is commonly refered to as KSZ87xx

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc George McCollister <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Woojung Huh <[email protected]>

---
V2: Rebase on top of 1/2, no functional change

---
 drivers/net/phy/micrel.c   | 4 ++--
 include/linux/micrel_phy.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/phy/micrel.c +2 -2
index 028a4a177790..2c5b0f81d4f3 100644
@@ -387,7 +387,7 @@ static int ksz8795_match_phy_device(struct phy_device *phydev)
 {
 	int ret;
 
-	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8795)
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ87XX)
 		return 0;
 
 	ret = phy_read(phydev, MII_BMSR);
@@ -1174,7 +1174,7 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.name		= "Micrel KSZ8795",
+	.name		= "Micrel KSZ87XX Switch",
 	/* PHY_BASIC_FEATURES */
 	.config_init	= kszphy_config_init,
 	.config_aneg	= ksz8873mll_config_aneg,
include/linux/micrel_phy.h +1 -1
index ad24554f11f9..75f880c25bb8 100644
@@ -31,7 +31,7 @@
 #define PHY_ID_KSZ886X		0x00221430
 #define PHY_ID_KSZ8863		0x00221435
 
-#define PHY_ID_KSZ8795		0x00221550
+#define PHY_ID_KSZ87XX		0x00221550
 
 #define	PHY_ID_KSZ9477		0x00221631
 
Signature · 1 line
2.23.0
#2 lore raw
In reply to Marek Vasut
Quoted 76 lines · Marek Vasut

The KSZ8051 PHY and the KSZ8794/KSZ8795/KSZ8765 switch share exactly the same PHY ID. Since KSZ8051 is higher in the ksphy_driver[] list of PHYs in the micrel PHY driver, it is used even with the KSZ87xx switch. This is wrong, since the KSZ8051 configures registers of the PHY which are not present on the simplified KSZ87xx switch PHYs and misconfigures other registers of the KSZ87xx switch PHYs.

Fortunatelly, it is possible to tell apart the KSZ8051 PHY from the KSZ87xx switch by checking the Basic Status register Bit 0, which is read-only and indicates presence of the Extended Capability Registers. The KSZ8051 PHY has those registers while the KSZ87xx switch does not.

This patch implements simple check for the presence of this bit for both the KSZ8051 PHY and KSZ87xx switch, to let both use the correct PHY driver instance.

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc George McCollister <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Woojung Huh <[email protected]>

---
NOTE: It was also suggested to populate phydev->dev_flags to discern
the PHY from the switch, this does not work for setups where the switch is used as a PHY without a DSA driver. Checking the BMSR Bit 0 for Extended Capability Register works for both DSA and non-DSA usecase.
V2: Move phy_id check into ksz8051_match_phy_device() and
ksz8795_match_phy_device() and drop phy_id{,_mask} from the ksphy_driver[] list to avoid matching on other PHY IDs.

---
 drivers/net/phy/micrel.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
drivers/net/phy/micrel.c +24 -0
index 2fea5541c35a..028a4a177790 100644
@@ -341,6 +341,25 @@ static int ksz8041_config_aneg(struct phy_device *phydev)
 	return genphy_config_aneg(phydev);
 }
 
+static int ksz8051_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8051)
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* KSZ8051 PHY and KSZ8794/KSZ8795/KSZ8765 switch share the same
+	 * exact PHY ID. However, they can be told apart by the extended
+	 * capability registers presence. The KSZ8051 PHY has them while
+	 * the switch does not.
+	 */
+	return ret & BMSR_ERCAP;
+}
+
 static int ksz8081_config_init(struct phy_device *phydev)
 {
 	/* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line
@@ -364,6 +383,21 @@ static int ksz8061_config_init(struct phy_device *phydev)
 	return kszphy_config_init(phydev);
 }
 
+static int ksz8795_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8795)

drivers/net/phy/micrel.c static int ksz8061_config_init(struct phy_device *phydev) · line 400

Quoted 10 lines
drivers/net/phy/micrel.c +10 -0
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* See comment in ksz8051_match_phy_device() for details. */
+	return !(ret & BMSR_ERCAP);
+}
+

Hi Marek,

given the similarity between ksz8051_match_phy_device() and ksz8795_match_phy_device() I wonder if a common helper is appropriate.

Quoted 38 lines
drivers/net/phy/micrel.c +2 -4
 static int ksz9021_load_values_from_of(struct phy_device *phydev,
 				       const struct device_node *of_node,
 				       u16 reg,
@@ -1017,8 +1051,6 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8051,
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8051",
 	/* PHY_BASIC_FEATURES */
 	.driver_data	= &ksz8051_type,
@@ -1029,6 +1061,7 @@ static struct phy_driver ksphy_driver[] = {
 	.get_sset_count = kszphy_get_sset_count,
 	.get_strings	= kszphy_get_strings,
 	.get_stats	= kszphy_get_stats,
+	.match_phy_device = ksz8051_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
@@ -1141,13 +1174,12 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8795,
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8795",
 	/* PHY_BASIC_FEATURES */
 	.config_init	= kszphy_config_init,
 	.config_aneg	= ksz8873mll_config_aneg,
 	.read_status	= ksz8873mll_read_status,
+	.match_phy_device = ksz8795_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
Signature · 1 line
2.23.0
#3 lore raw

On 10/11/19 7:57 AM, Simon Horman wrote:
[...]

Quoted 18 lines
Quoted 5 lines
drivers/net/phy/micrel.c +5 -0
+static int ksz8795_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8795)

drivers/net/phy/micrel.c static int ksz8061_config_init(struct phy_device *phydev) · line 400

Quoted 10 lines
drivers/net/phy/micrel.c +10 -0
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* See comment in ksz8051_match_phy_device() for details. */
+	return !(ret & BMSR_ERCAP);
+}
+

Hi Marek,

Quoted 2 lines

given the similarity between ksz8051_match_phy_device() and ksz8795_match_phy_device() I wonder if a common helper is appropriate.

Then one (or both) of them look like this:

static int ksz8795_match_phy_device(struct phy_device *phydev)

{
        int ret;

        /* See comment in ksz8051_match_phy_device() for details. */
        ret = ksz8051_match_phy_device(phydev);
        if (ret < 0)
                return ret;

        return !ret;
}

It's not that much better.

#4 lore raw
Quoted 37 lines · Marek Vasut

On 10/11/19 7:57 AM, Simon Horman wrote:
[...]

Quoted 18 lines
Quoted 5 lines
drivers/net/phy/micrel.c +5 -0
+static int ksz8795_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8795)

drivers/net/phy/micrel.c static int ksz8061_config_init(struct phy_device *phydev) · line 400

Quoted 10 lines
drivers/net/phy/micrel.c +10 -0
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* See comment in ksz8051_match_phy_device() for details. */
+	return !(ret & BMSR_ERCAP);
+}
+

Hi Marek,

Quoted 2 lines

given the similarity between ksz8051_match_phy_device() and ksz8795_match_phy_device() I wonder if a common helper is appropriate.

Then one (or both) of them look like this:

static int ksz8795_match_phy_device(struct phy_device *phydev)

{
        int ret;

        /* See comment in ksz8051_match_phy_device() for details. */
        ret = ksz8051_match_phy_device(phydev);
        if (ret < 0)
                return ret;

        return !ret;
}
Quoted 1 line

It's not that much better.

Hi Marek,

I think I slightly prefer this but I do see your point and I have no objections to leaving the patch as-is.

maintainer Reviewed-by on v2 1/2
#5 lore raw
In reply to Marek Vasut
Quoted 112 lines · Marek Vasut

The KSZ8051 PHY and the KSZ8794/KSZ8795/KSZ8765 switch share exactly the same PHY ID. Since KSZ8051 is higher in the ksphy_driver[] list of PHYs in the micrel PHY driver, it is used even with the KSZ87xx switch. This is wrong, since the KSZ8051 configures registers of the PHY which are not present on the simplified KSZ87xx switch PHYs and misconfigures other registers of the KSZ87xx switch PHYs.

Fortunatelly, it is possible to tell apart the KSZ8051 PHY from the KSZ87xx switch by checking the Basic Status register Bit 0, which is read-only and indicates presence of the Extended Capability Registers. The KSZ8051 PHY has those registers while the KSZ87xx switch does not.

This patch implements simple check for the presence of this bit for both the KSZ8051 PHY and KSZ87xx switch, to let both use the correct PHY driver instance.

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc George McCollister <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Woojung Huh <[email protected]>

---
NOTE: It was also suggested to populate phydev->dev_flags to discern
the PHY from the switch, this does not work for setups where the switch is used as a PHY without a DSA driver. Checking the BMSR Bit 0 for Extended Capability Register works for both DSA and non-DSA usecase.
V2: Move phy_id check into ksz8051_match_phy_device() and
ksz8795_match_phy_device() and drop phy_id{,_mask} from the ksphy_driver[] list to avoid matching on other PHY IDs.

---
 drivers/net/phy/micrel.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
drivers/net/phy/micrel.c +35 -3
index 2fea5541c35a..028a4a177790 100644
@@ -341,6 +341,25 @@ static int ksz8041_config_aneg(struct phy_device *phydev)
 	return genphy_config_aneg(phydev);
 }
 
+static int ksz8051_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8051)
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* KSZ8051 PHY and KSZ8794/KSZ8795/KSZ8765 switch share the same
+	 * exact PHY ID. However, they can be told apart by the extended
+	 * capability registers presence. The KSZ8051 PHY has them while
+	 * the switch does not.
+	 */
+	return ret & BMSR_ERCAP;
+}
+
 static int ksz8081_config_init(struct phy_device *phydev)
 {
 	/* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line
@@ -364,6 +383,21 @@ static int ksz8061_config_init(struct phy_device *phydev)
 	return kszphy_config_init(phydev);
 }
 
+static int ksz8795_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8795)
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* See comment in ksz8051_match_phy_device() for details. */
+	return !(ret & BMSR_ERCAP);
+}
+
 static int ksz9021_load_values_from_of(struct phy_device *phydev,
 				       const struct device_node *of_node,
 				       u16 reg,
@@ -1017,8 +1051,6 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8051,
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8051",
 	/* PHY_BASIC_FEATURES */
 	.driver_data	= &ksz8051_type,
@@ -1029,6 +1061,7 @@ static struct phy_driver ksphy_driver[] = {
 	.get_sset_count = kszphy_get_sset_count,
 	.get_strings	= kszphy_get_strings,
 	.get_stats	= kszphy_get_stats,
+	.match_phy_device = ksz8051_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
@@ -1141,13 +1174,12 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8795,

drivers/net/phy/micrel.c static struct phy_driver ksphy_driver[] = { · line 1185

Quoted 10 lines
drivers/net/phy/micrel.c +1 -1
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8795",
 	/* PHY_BASIC_FEATURES */
 	.config_init	= kszphy_config_init,
 	.config_aneg	= ksz8873mll_config_aneg,
 	.read_status	= ksz8873mll_read_status,
+	.match_phy_device = ksz8795_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {

Patch needs to be annotated as "net-next".
See https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt

Apart from that:

maintainer
#6 lore raw
Quoted 118 lines · Heiner Kallweit
Quoted 117 lines · Marek Vasut

The KSZ8051 PHY and the KSZ8794/KSZ8795/KSZ8765 switch share exactly the same PHY ID. Since KSZ8051 is higher in the ksphy_driver[] list of PHYs in the micrel PHY driver, it is used even with the KSZ87xx switch. This is wrong, since the KSZ8051 configures registers of the PHY which are not present on the simplified KSZ87xx switch PHYs and misconfigures other registers of the KSZ87xx switch PHYs.

Fortunatelly, it is possible to tell apart the KSZ8051 PHY from the KSZ87xx switch by checking the Basic Status register Bit 0, which is read-only and indicates presence of the Extended Capability Registers. The KSZ8051 PHY has those registers while the KSZ87xx switch does not.

This patch implements simple check for the presence of this bit for both the KSZ8051 PHY and KSZ87xx switch, to let both use the correct PHY driver instance.

Cc Andrew Lunn <[email protected]>
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc George McCollister <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Tristram Ha <[email protected]>
Cc Woojung Huh <[email protected]>

---
NOTE: It was also suggested to populate phydev->dev_flags to discern
the PHY from the switch, this does not work for setups where the switch is used as a PHY without a DSA driver. Checking the BMSR Bit 0 for Extended Capability Register works for both DSA and non-DSA usecase.
V2: Move phy_id check into ksz8051_match_phy_device() and
ksz8795_match_phy_device() and drop phy_id{,_mask} from the ksphy_driver[] list to avoid matching on other PHY IDs.

---
 drivers/net/phy/micrel.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
drivers/net/phy/micrel.c +35 -4
index 2fea5541c35a..028a4a177790 100644
@@ -341,6 +341,25 @@ static int ksz8041_config_aneg(struct phy_device *phydev)
 	return genphy_config_aneg(phydev);
 }
 
+static int ksz8051_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8051)
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* KSZ8051 PHY and KSZ8794/KSZ8795/KSZ8765 switch share the same
+	 * exact PHY ID. However, they can be told apart by the extended
+	 * capability registers presence. The KSZ8051 PHY has them while
+	 * the switch does not.
+	 */
+	return ret & BMSR_ERCAP;
+}
+
 static int ksz8081_config_init(struct phy_device *phydev)
 {
 	/* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line
@@ -364,6 +383,21 @@ static int ksz8061_config_init(struct phy_device *phydev)
 	return kszphy_config_init(phydev);
 }
 
+static int ksz8795_match_phy_device(struct phy_device *phydev)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8795)
+		return 0;
+
+	ret = phy_read(phydev, MII_BMSR);
+	if (ret < 0)
+		return ret;
+
+	/* See comment in ksz8051_match_phy_device() for details. */
+	return !(ret & BMSR_ERCAP);
+}
+
 static int ksz9021_load_values_from_of(struct phy_device *phydev,
 				       const struct device_node *of_node,
 				       u16 reg,
@@ -1017,8 +1051,6 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8051,
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8051",
 	/* PHY_BASIC_FEATURES */
 	.driver_data	= &ksz8051_type,
@@ -1029,6 +1061,7 @@ static struct phy_driver ksphy_driver[] = {
 	.get_sset_count = kszphy_get_sset_count,
 	.get_strings	= kszphy_get_strings,
 	.get_stats	= kszphy_get_stats,
+	.match_phy_device = ksz8051_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
@@ -1141,13 +1174,12 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8795,
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8795",
 	/* PHY_BASIC_FEATURES */
 	.config_init	= kszphy_config_init,
 	.config_aneg	= ksz8873mll_config_aneg,
 	.read_status	= ksz8873mll_read_status,
Quoted 9 lines

drivers/net/phy/micrel.c static struct phy_driver ksphy_driver[] = { · line 1185

Quoted 5 lines
drivers/net/phy/micrel.c +1 -0
+	.match_phy_device = ksz8795_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {

Patch needs to be annotated as "net-next".
See https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt

Except you consider this a fix, then it would require a Fixes tag and should be annotated "net". The question is:
Do KSZ87xx switches misbehave currently?

Quoted 3 lines

Apart from that:

#7 lore raw

On 10/12/19 11:22 PM, Heiner Kallweit wrote:

[...]

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/phy/micrel.c +0 -2
@@ -1141,13 +1174,12 @@ static struct phy_driver ksphy_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {
-	.phy_id		= PHY_ID_KSZ8795,
-	.phy_id_mask	= MICREL_PHY_ID_MASK,
 	.name		= "Micrel KSZ8795",
 	/* PHY_BASIC_FEATURES */
 	.config_init	= kszphy_config_init,
 	.config_aneg	= ksz8873mll_config_aneg,
 	.read_status	= ksz8873mll_read_status,
Quoted 9 lines

drivers/net/phy/micrel.c static struct phy_driver ksphy_driver[] = { · line 1185

Quoted 5 lines
drivers/net/phy/micrel.c +1 -0
+	.match_phy_device = ksz8795_match_phy_device,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 }, {

Patch needs to be annotated as "net-next".
See https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt

Quoted 3 lines

Except you consider this a fix, then it would require a Fixes tag and should be annotated "net". The question is:
Do KSZ87xx switches misbehave currently?

Well yes they do, otherwise I won't be sending this fix.

Signature · 2 lines
Best regards,
Marek Vasut