lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220207174532.362781-2-enguerrand.de-ribaucourt@savoirfairelinux.com>
Date:   Mon,  7 Feb 2022 18:45:34 +0100
From:   Enguerrand de Ribaucourt 
        <enguerrand.de-ribaucourt@...oirfairelinux.com>
To:     netdev@...r.kernel.org
Cc:     andrew@...n.ch, hkallweit1@...il.com, linux@...linux.org.uk,
        Enguerrand de Ribaucourt 
        <enguerrand.de-ribaucourt@...oirfairelinux.com>
Subject: [PATCH v2 1/2] net: phy: micrel: add Microchip KSZ 9897 Switch PHY support

Adding Microchip 9897 Phy included in KSZ9897 Switch.
The KSZ9897 shares the same phy_id as some revisions of the KSZ8081.
match_phy_device functions were added to distinguish them.

Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@...oirfairelinux.com>
---
 drivers/net/phy/micrel.c   | 45 ++++++++++++++++++++++++++++++++++++++
 include/linux/micrel_phy.h |  5 +++++
 2 files changed, 50 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 44a24b99c894..fc5c33194bdc 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -522,6 +522,34 @@ static int ksz8081_read_status(struct phy_device *phydev)
 	return genphy_read_status(phydev);
 }

+static int ksz8081_ksz9897_match_phy_device(struct phy_device *phydev,
+					    const bool ksz_8081)
+{
+	int ret;
+
+	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8081)
+		return 0;
+
+	ret = phy_read(phydev, MICREL_KSZ8081_CTRL2);
+	if (ret < 0)
+		return ret;
+
+	/* KSZ8081A3/KSZ8091R1 PHY and KSZ9897 switch share the same
+	 * exact PHY ID. However, they can be told apart by the default value
+	 * of the LED mode. It is 0 for the PHY, and 1 for the switch.
+	 */
+	ret &= (MICREL_KSZ8081_CTRL2_LED_MODE0 | MICREL_KSZ8081_CTRL2_LED_MODE1);
+	if (!ksz_8081)
+		return ret;
+	else
+		return !ret;
+}
+
+static int ksz8081_match_phy_device(struct phy_device *phydev)
+{
+	return ksz8081_ksz9897_match_phy_device(phydev, true);
+}
+
 static int ksz8061_config_init(struct phy_device *phydev)
 {
 	int ret;
@@ -1561,6 +1589,11 @@ static int ksz886x_cable_test_get_status(struct phy_device *phydev,
 	return ret;
 }

+static int ksz9897_match_phy_device(struct phy_device *phydev)
+{
+	return ksz8081_ksz9897_match_phy_device(phydev, false);
+}
+
 #define LAN_EXT_PAGE_ACCESS_CONTROL			0x16
 #define LAN_EXT_PAGE_ACCESS_ADDRESS_DATA		0x17
 #define LAN_EXT_PAGE_ACCESS_CTRL_EP_FUNC		0x4000
@@ -1734,6 +1767,7 @@ static struct phy_driver ksphy_driver[] = {
 	.config_init	= ksz8081_config_init,
 	.soft_reset	= genphy_soft_reset,
 	.config_aneg	= ksz8081_config_aneg,
+	.match_phy_device = ksz8081_match_phy_device,
 	.read_status	= ksz8081_read_status,
 	.config_intr	= kszphy_config_intr,
 	.handle_interrupt = kszphy_handle_interrupt,
@@ -1869,6 +1903,17 @@ static struct phy_driver ksphy_driver[] = {
 	.config_init	= kszphy_config_init,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
+}, {
+	.phy_id		= PHY_ID_KSZ9897,
+	.phy_id_mask	= 0x00ffffff,
+	.name		= "Microchip KSZ9897",
+	/* PHY_BASIC_FEATURES */
+	.config_init	= kszphy_config_init,
+	.config_aneg	= ksz8873mll_config_aneg,
+	.match_phy_device = ksz9897_match_phy_device,
+	.read_status	= ksz8873mll_read_status,
+	.suspend	= genphy_suspend,
+	.resume		= genphy_resume,
 } };

 module_phy_driver(ksphy_driver);
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index 1f7c33b2f5a3..05b24bf7f75f 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -36,6 +36,7 @@
 #define PHY_ID_KSZ87XX		0x00221550

 #define	PHY_ID_KSZ9477		0x00221631
+#define	PHY_ID_KSZ9897		0x00221561

 /* struct phy_device dev_flags definitions */
 #define MICREL_PHY_50MHZ_CLK	0x00000001
@@ -62,4 +63,8 @@

 #define KSZ886X_CTRL_MDIX_STAT			BIT(4)

+#define MICREL_KSZ8081_CTRL2	0x1F
+#define MICREL_KSZ8081_CTRL2_LED_MODE0	BIT(4)
+#define MICREL_KSZ8081_CTRL2_LED_MODE1	BIT(5)
+
 #endif /* _MICREL_PHY_H */
--
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ