blob: f7c4bc11053f5f027b8e3b9a95944fe26c2c0284 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 6df6709dc3d00e0bc948d45dfa8d8f18ba379c48 Mon Sep 17 00:00:00 2001
2From: Russell King <rmk+kernel@armlinux.org.uk>
3Date: Tue, 5 Nov 2019 11:56:18 +0000
4Subject: [PATCH 656/660] net: sfp: add support for Clause 45 PHYs
5
6Some SFP+ modules have a Clause 45 PHY onboard, which is accessible via
7the normal I2C address. Detect 10G BASE-T PHYs which may have an
8accessible PHY and probe for it.
9
10Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
11---
12 drivers/net/phy/sfp.c | 44 +++++++++++++++++++++++++++++++++++++++----
13 1 file changed, 40 insertions(+), 4 deletions(-)
14
15--- a/drivers/net/phy/sfp.c
16+++ b/drivers/net/phy/sfp.c
17@@ -1418,12 +1418,12 @@ static void sfp_sm_phy_detach(struct sfp
18 sfp->mod_phy = NULL;
19 }
20
21-static void sfp_sm_probe_phy(struct sfp *sfp)
22+static void sfp_sm_probe_phy(struct sfp *sfp, bool is_c45)
23 {
24 struct phy_device *phy;
25 int err;
26
27- phy = mdiobus_scan(sfp->i2c_mii, SFP_PHY_ADDR);
28+ phy = get_phy_device(sfp->i2c_mii, SFP_PHY_ADDR, is_c45);
29 if (phy == ERR_PTR(-ENODEV)) {
30 dev_info(sfp->dev, "no PHY detected\n");
31 return;
32@@ -1433,6 +1433,13 @@ static void sfp_sm_probe_phy(struct sfp
33 return;
34 }
35
36+ err = phy_device_register(phy);
37+ if (err) {
38+ phy_device_free(phy);
39+ dev_err(sfp->dev, "phy_device_register failed: %d\n", err);
40+ return;
41+ }
42+
43 err = sfp_add_phy(sfp->sfp_bus, phy);
44 if (err) {
45 phy_device_remove(phy);
46@@ -1511,10 +1518,32 @@ static void sfp_sm_fault(struct sfp *sfp
47 }
48 }
49
50+/* Probe a SFP for a PHY device if the module supports copper - the PHY
51+ * normally sits at I2C bus address 0x56, and may either be a clause 22
52+ * or clause 45 PHY.
53+ *
54+ * Clause 22 copper SFP modules normally operate in Cisco SGMII mode with
55+ * negotiation enabled, but some may be in 1000base-X - which is for the
56+ * PHY driver to determine.
57+ *
58+ * Clause 45 copper SFP+ modules (10G) appear to switch their interface
59+ * mode according to the negotiated line speed.
60+ */
61 static void sfp_sm_probe_for_phy(struct sfp *sfp)
62 {
63- if (sfp->id.base.e1000_base_t)
64- sfp_sm_probe_phy(sfp);
65+ switch (sfp->id.base.extended_cc) {
66+ case SFF8024_ECC_10GBASE_T_SFI:
67+ case SFF8024_ECC_10GBASE_T_SR:
68+ case SFF8024_ECC_5GBASE_T:
69+ case SFF8024_ECC_2_5GBASE_T:
70+ sfp_sm_probe_phy(sfp, true);
71+ break;
72+
73+ default:
74+ if (sfp->id.base.e1000_base_t)
75+ sfp_sm_probe_phy(sfp, false);
76+ break;
77+ }
78 }
79
80 static int sfp_module_parse_power(struct sfp *sfp)
81@@ -1574,6 +1603,13 @@ static int sfp_sm_mod_hpower(struct sfp
82 return -EAGAIN;
83 }
84
85+ /* DM7052 reports as a high power module, responds to reads (with
86+ * all bytes 0xff) at 0x51 but does not accept writes. In any case,
87+ * if the bit is already set, we're already in high power mode.
88+ */
89+ if (!!(val & BIT(0)) == enable)
90+ return 0;
91+
92 if (enable)
93 val |= BIT(0);
94 else