developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1 | From 1631a36b9ac022ce6ffb58b039a7e85ad3414ed5 Mon Sep 17 00:00:00 2001 |
| 2 | From: Sam Shih <sam.shih@mediatek.com> |
| 3 | Date: Fri, 2 Jun 2023 13:06:01 +0800 |
| 4 | Subject: [PATCH] |
| 5 | [backport-networking-drivers][999-1709-net-phy-sfp-add-rollball-support.patch] |
| 6 | |
| 7 | --- |
| 8 | drivers/net/phy/marvell.c | 2 +- |
| 9 | drivers/net/phy/marvell10g.c | 168 +++++++++++++-- |
| 10 | drivers/net/phy/mdio-i2c.c | 309 +++++++++++++++++++++++++++- |
| 11 | drivers/net/phy/phylink.c | 74 +++++-- |
| 12 | drivers/net/phy/sfp-bus.c | 102 +--------- |
| 13 | drivers/net/phy/sfp.c | 373 +++++++++++++++++++++++++++++----- |
| 14 | drivers/net/phy/sfp.h | 11 +- |
| 15 | include/linux/mdio/mdio-i2c.h | 10 +- |
| 16 | 8 files changed, 874 insertions(+), 175 deletions(-) |
| 17 | |
| 18 | diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c |
| 19 | index 49801c2eb..f25881745 100644 |
| 20 | --- a/drivers/net/phy/marvell.c |
| 21 | +++ b/drivers/net/phy/marvell.c |
| 22 | @@ -2175,7 +2175,7 @@ static struct phy_driver marvell_drivers[] = { |
| 23 | .phy_id = MARVELL_PHY_ID_88E1111, |
| 24 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 25 | .name = "Marvell 88E1111", |
| 26 | - /* PHY_GBIT_FEATURES */ |
| 27 | + .features = PHY_GBIT_FEATURES, |
| 28 | .probe = marvell_probe, |
| 29 | .config_init = &m88e1111_config_init, |
| 30 | .config_aneg = &marvell_config_aneg, |
| 31 | diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c |
| 32 | index 1e4631761..7d080d52e 100644 |
| 33 | --- a/drivers/net/phy/marvell10g.c |
| 34 | +++ b/drivers/net/phy/marvell10g.c |
| 35 | @@ -32,6 +32,15 @@ |
| 36 | #define MV_PHY_ALASKA_NBT_QUIRK_REV (MARVELL_PHY_ID_88X3310 | 0xa) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 37 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 38 | enum { |
| 39 | + MV_PMA_21X0_PORT_CTRL = 0xc04a, |
| 40 | + MV_PMA_21X0_PORT_CTRL_SWRST = BIT(15), |
| 41 | + MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK = 0x7, |
| 42 | + MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII = 0x0, |
| 43 | + MV_PMA_2180_PORT_CTRL_MACTYPE_DXGMII = 0x1, |
| 44 | + MV_PMA_2180_PORT_CTRL_MACTYPE_QXGMII = 0x2, |
| 45 | + MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER = 0x4, |
| 46 | + MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER_NO_SGMII_AN = 0x5, |
| 47 | + MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH = 0x6, |
| 48 | MV_PMA_BOOT = 0xc050, |
| 49 | MV_PMA_BOOT_FATAL = BIT(0), |
| 50 | |
| 51 | @@ -53,7 +62,18 @@ enum { |
| 52 | |
| 53 | /* Vendor2 MMD registers */ |
| 54 | MV_V2_PORT_CTRL = 0xf001, |
| 55 | - MV_V2_PORT_CTRL_PWRDOWN = 0x0800, |
| 56 | + MV_V2_PORT_CTRL_PWRDOWN = BIT(11), |
| 57 | + MV_V2_33X0_PORT_CTRL_SWRST = BIT(15), |
| 58 | + MV_V2_33X0_PORT_CTRL_MACTYPE_MASK = 0x7, |
| 59 | + MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI = 0x0, |
| 60 | + MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH = 0x1, |
| 61 | + MV_V2_3340_PORT_CTRL_MACTYPE_RXAUI_NO_SGMII_AN = 0x1, |
| 62 | + MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH = 0x2, |
| 63 | + MV_V2_3310_PORT_CTRL_MACTYPE_XAUI = 0x3, |
| 64 | + MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER = 0x4, |
| 65 | + MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN = 0x5, |
| 66 | + MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH = 0x6, |
| 67 | + MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII = 0x7, |
| 68 | MV_V2_TEMP_CTRL = 0xf08a, |
| 69 | MV_V2_TEMP_CTRL_MASK = 0xc000, |
| 70 | MV_V2_TEMP_CTRL_SAMPLE = 0x0000, |
| 71 | @@ -62,11 +82,24 @@ enum { |
| 72 | MV_V2_TEMP_UNKNOWN = 0x9600, /* unknown function */ |
| 73 | }; |
| 74 | |
| 75 | +struct mv3310_chip { |
| 76 | + int (*get_mactype)(struct phy_device *phydev); |
| 77 | + int (*init_interface)(struct phy_device *phydev, int mactype); |
| 78 | +}; |
| 79 | + |
| 80 | struct mv3310_priv { |
| 81 | + bool rate_match; |
| 82 | + phy_interface_t const_interface; |
| 83 | + |
| 84 | struct device *hwmon_dev; |
| 85 | char *hwmon_name; |
| 86 | }; |
| 87 | |
| 88 | +static const struct mv3310_chip *to_mv3310_chip(struct phy_device *phydev) |
| 89 | +{ |
| 90 | + return phydev->drv->driver_data; |
| 91 | +} |
| 92 | + |
| 93 | #ifdef CONFIG_HWMON |
| 94 | static umode_t mv3310_hwmon_is_visible(const void *data, |
| 95 | enum hwmon_sensor_types type, |
| 96 | @@ -155,13 +188,6 @@ static int mv3310_hwmon_config(struct phy_device *phydev, bool enable) |
| 97 | MV_V2_TEMP_CTRL_MASK, val); |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 98 | } |
| 99 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 100 | -static void mv3310_hwmon_disable(void *data) |
| 101 | -{ |
| 102 | - struct phy_device *phydev = data; |
| 103 | - |
| 104 | - mv3310_hwmon_config(phydev, false); |
| 105 | -} |
| 106 | - |
| 107 | static int mv3310_hwmon_probe(struct phy_device *phydev) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 108 | { |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 109 | struct device *dev = &phydev->mdio.dev; |
| 110 | @@ -185,10 +211,6 @@ static int mv3310_hwmon_probe(struct phy_device *phydev) |
| 111 | if (ret) |
| 112 | return ret; |
| 113 | |
| 114 | - ret = devm_add_action_or_reset(dev, mv3310_hwmon_disable, phydev); |
| 115 | - if (ret) |
| 116 | - return ret; |
| 117 | - |
| 118 | priv->hwmon_dev = devm_hwmon_device_register_with_info(dev, |
| 119 | priv->hwmon_name, phydev, |
| 120 | &mv3310_hwmon_chip_info, NULL); |
| 121 | @@ -262,6 +284,11 @@ static int mv3310_probe(struct phy_device *phydev) |
| 122 | return phy_sfp_probe(phydev, &mv3310_sfp_ops); |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 123 | } |
| 124 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 125 | +static void mv3310_remove(struct phy_device *phydev) |
| 126 | +{ |
| 127 | + mv3310_hwmon_config(phydev, false); |
| 128 | +} |
| 129 | + |
| 130 | static int mv3310_suspend(struct phy_device *phydev) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 131 | { |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 132 | return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL, |
| 133 | @@ -297,8 +324,84 @@ static bool mv3310_has_pma_ngbaset_quirk(struct phy_device *phydev) |
| 134 | MV_PHY_ALASKA_NBT_QUIRK_MASK) == MV_PHY_ALASKA_NBT_QUIRK_REV; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 135 | } |
| 136 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 137 | +static int mv2110_get_mactype(struct phy_device *phydev) |
| 138 | +{ |
| 139 | + int mactype; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 140 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 141 | + mactype = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_21X0_PORT_CTRL); |
| 142 | + if (mactype < 0) |
| 143 | + return mactype; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 144 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 145 | + return mactype & MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK; |
| 146 | +} |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 147 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 148 | +static int mv3310_get_mactype(struct phy_device *phydev) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 149 | +{ |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 150 | + int mactype; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 151 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 152 | + mactype = phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL); |
| 153 | + if (mactype < 0) |
| 154 | + return mactype; |
| 155 | + |
| 156 | + return mactype & MV_V2_33X0_PORT_CTRL_MACTYPE_MASK; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 157 | +} |
| 158 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 159 | +static int mv2110_init_interface(struct phy_device *phydev, int mactype) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 160 | +{ |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 161 | + struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 162 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 163 | + priv->rate_match = false; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 164 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 165 | + if (mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH) |
| 166 | + priv->rate_match = true; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 167 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 168 | + if (mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII) |
| 169 | + priv->const_interface = PHY_INTERFACE_MODE_USXGMII; |
| 170 | + else if (mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH) |
| 171 | + priv->const_interface = PHY_INTERFACE_MODE_10GKR; |
| 172 | + else if (mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER || |
| 173 | + mactype == MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER_NO_SGMII_AN) |
| 174 | + priv->const_interface = PHY_INTERFACE_MODE_NA; |
| 175 | + else |
| 176 | + return -EINVAL; |
| 177 | + |
| 178 | + return 0; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 179 | +} |
| 180 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 181 | +static int mv3310_init_interface(struct phy_device *phydev, int mactype) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 182 | +{ |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 183 | + struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 184 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 185 | + priv->rate_match = false; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 186 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 187 | + if (mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH || |
| 188 | + mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH || |
| 189 | + mactype == MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH) |
| 190 | + priv->rate_match = true; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 191 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 192 | + if (mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII) |
| 193 | + priv->const_interface = PHY_INTERFACE_MODE_USXGMII; |
| 194 | + else if (mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH || |
| 195 | + mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN || |
| 196 | + mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER) |
| 197 | + priv->const_interface = PHY_INTERFACE_MODE_10GKR; |
| 198 | + else if (mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH || |
| 199 | + mactype == MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI) |
| 200 | + priv->const_interface = PHY_INTERFACE_MODE_RXAUI; |
| 201 | + else if (mactype == MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH || |
| 202 | + mactype == MV_V2_3310_PORT_CTRL_MACTYPE_XAUI) |
| 203 | + priv->const_interface = PHY_INTERFACE_MODE_XAUI; |
| 204 | + else |
| 205 | + return -EINVAL; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 206 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 207 | + return 0; |
| 208 | +} |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 209 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 210 | static int mv3310_config_init(struct phy_device *phydev) |
| 211 | { |
| 212 | + const struct mv3310_chip *chip = to_mv3310_chip(phydev); |
| 213 | + int err, mactype; |
| 214 | + |
| 215 | /* Check that the PHY interface type is compatible */ |
| 216 | if (phydev->interface != PHY_INTERFACE_MODE_SGMII && |
| 217 | phydev->interface != PHY_INTERFACE_MODE_2500BASEX && |
| 218 | @@ -307,6 +410,16 @@ static int mv3310_config_init(struct phy_device *phydev) |
| 219 | phydev->interface != PHY_INTERFACE_MODE_10GKR) |
| 220 | return -ENODEV; |
| 221 | |
| 222 | + mactype = chip->get_mactype(phydev); |
| 223 | + if (mactype < 0) |
| 224 | + return mactype; |
| 225 | + |
| 226 | + err = chip->init_interface(phydev, mactype); |
| 227 | + if (err) { |
| 228 | + phydev_err(phydev, "MACTYPE configuration invalid\n"); |
| 229 | + return err; |
| 230 | + } |
| 231 | + |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | @@ -384,6 +497,23 @@ static int mv3310_aneg_done(struct phy_device *phydev) |
| 236 | |
| 237 | static void mv3310_update_interface(struct phy_device *phydev) |
| 238 | { |
| 239 | + struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); |
| 240 | + |
| 241 | + if (!phydev->link) |
| 242 | + return; |
| 243 | + |
| 244 | + /* In all of the "* with Rate Matching" modes the PHY interface is fixed |
| 245 | + * at 10Gb. The PHY adapts the rate to actual wire speed with help of |
| 246 | + * internal 16KB buffer. |
| 247 | + * |
| 248 | + * In USXGMII mode the PHY interface mode is also fixed. |
| 249 | + */ |
| 250 | + if (priv->rate_match || |
| 251 | + priv->const_interface == PHY_INTERFACE_MODE_USXGMII) { |
| 252 | + phydev->interface = priv->const_interface; |
| 253 | + return; |
| 254 | + } |
| 255 | + |
| 256 | if ((phydev->interface == PHY_INTERFACE_MODE_SGMII || |
| 257 | phydev->interface == PHY_INTERFACE_MODE_2500BASEX || |
| 258 | phydev->interface == PHY_INTERFACE_MODE_5GBASER || |
| 259 | @@ -503,11 +633,22 @@ static int mv3310_read_status(struct phy_device *phydev) |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | +static const struct mv3310_chip mv3310_type = { |
| 264 | + .get_mactype = mv3310_get_mactype, |
| 265 | + .init_interface = mv3310_init_interface, |
| 266 | +}; |
| 267 | + |
| 268 | +static const struct mv3310_chip mv2111_type = { |
| 269 | + .get_mactype = mv2110_get_mactype, |
| 270 | + .init_interface = mv2110_init_interface, |
| 271 | +}; |
| 272 | + |
| 273 | static struct phy_driver mv3310_drivers[] = { |
| 274 | { |
| 275 | .phy_id = MARVELL_PHY_ID_88X3310, |
| 276 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 277 | .name = "mv88x3310", |
| 278 | + .driver_data = &mv3310_type, |
| 279 | .get_features = mv3310_get_features, |
| 280 | .soft_reset = genphy_no_soft_reset, |
| 281 | .config_init = mv3310_config_init, |
| 282 | @@ -517,11 +658,13 @@ static struct phy_driver mv3310_drivers[] = { |
| 283 | .config_aneg = mv3310_config_aneg, |
| 284 | .aneg_done = mv3310_aneg_done, |
| 285 | .read_status = mv3310_read_status, |
| 286 | + .remove = mv3310_remove, |
| 287 | }, |
| 288 | { |
| 289 | .phy_id = MARVELL_PHY_ID_88E2110, |
| 290 | .phy_id_mask = MARVELL_PHY_ID_MASK, |
| 291 | .name = "mv88x2110", |
| 292 | + .driver_data = &mv2111_type, |
| 293 | .probe = mv3310_probe, |
| 294 | .suspend = mv3310_suspend, |
| 295 | .resume = mv3310_resume, |
| 296 | @@ -530,6 +673,7 @@ static struct phy_driver mv3310_drivers[] = { |
| 297 | .config_aneg = mv3310_config_aneg, |
| 298 | .aneg_done = mv3310_aneg_done, |
| 299 | .read_status = mv3310_read_status, |
| 300 | + .remove = mv3310_remove, |
| 301 | }, |
| 302 | }; |
| 303 | |
| 304 | diff --git a/drivers/net/phy/mdio-i2c.c b/drivers/net/phy/mdio-i2c.c |
| 305 | index 09200a70b..85db63c33 100644 |
| 306 | --- a/drivers/net/phy/mdio-i2c.c |
| 307 | +++ b/drivers/net/phy/mdio-i2c.c |
| 308 | @@ -12,6 +12,7 @@ |
| 309 | #include <linux/i2c.h> |
| 310 | #include <linux/mdio/mdio-i2c.h> |
| 311 | #include <linux/phy.h> |
| 312 | +#include <linux/sfp.h> |
| 313 | |
| 314 | /* |
| 315 | * I2C bus addresses 0x50 and 0x51 are normally an EEPROM, which is |
| 316 | @@ -28,7 +29,7 @@ static unsigned int i2c_mii_phy_addr(int phy_id) |
| 317 | return phy_id + 0x40; |
| 318 | } |
| 319 | |
| 320 | -static int i2c_mii_read(struct mii_bus *bus, int phy_id, int reg) |
| 321 | +static int i2c_mii_read_default(struct mii_bus *bus, int phy_id, int reg) |
| 322 | { |
| 323 | struct i2c_adapter *i2c = bus->priv; |
| 324 | struct i2c_msg msgs[2]; |
| 325 | @@ -62,7 +63,8 @@ static int i2c_mii_read(struct mii_bus *bus, int phy_id, int reg) |
| 326 | return data[0] << 8 | data[1]; |
| 327 | } |
| 328 | |
| 329 | -static int i2c_mii_write(struct mii_bus *bus, int phy_id, int reg, u16 val) |
| 330 | +static int i2c_mii_write_default(struct mii_bus *bus, int phy_id, int reg, |
| 331 | + u16 val) |
| 332 | { |
| 333 | struct i2c_adapter *i2c = bus->priv; |
| 334 | struct i2c_msg msg; |
| 335 | @@ -91,9 +93,288 @@ static int i2c_mii_write(struct mii_bus *bus, int phy_id, int reg, u16 val) |
| 336 | return ret < 0 ? ret : 0; |
| 337 | } |
| 338 | |
| 339 | -struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c) |
| 340 | +/* RollBall SFPs do not access internal PHY via I2C address 0x56, but |
| 341 | + * instead via address 0x51, when SFP page is set to 0x03 and password to |
| 342 | + * 0xffffffff. |
| 343 | + * |
| 344 | + * address size contents description |
| 345 | + * ------- ---- -------- ----------- |
| 346 | + * 0x80 1 CMD 0x01/0x02/0x04 for write/read/done |
| 347 | + * 0x81 1 DEV Clause 45 device |
| 348 | + * 0x82 2 REG Clause 45 register |
| 349 | + * 0x84 2 VAL Register value |
| 350 | + */ |
| 351 | +#define ROLLBALL_PHY_I2C_ADDR 0x51 |
| 352 | + |
| 353 | +#define ROLLBALL_PASSWORD (SFP_VSL + 3) |
| 354 | + |
| 355 | +#define ROLLBALL_CMD_ADDR 0x80 |
| 356 | +#define ROLLBALL_DATA_ADDR 0x81 |
| 357 | + |
| 358 | +#define ROLLBALL_CMD_WRITE 0x01 |
| 359 | +#define ROLLBALL_CMD_READ 0x02 |
| 360 | +#define ROLLBALL_CMD_DONE 0x04 |
| 361 | + |
| 362 | +#define SFP_PAGE_ROLLBALL_MDIO 3 |
| 363 | + |
| 364 | +static int __i2c_transfer_err(struct i2c_adapter *i2c, struct i2c_msg *msgs, |
| 365 | + int num) |
| 366 | +{ |
| 367 | + int ret; |
| 368 | + |
| 369 | + ret = __i2c_transfer(i2c, msgs, num); |
| 370 | + if (ret < 0) |
| 371 | + return ret; |
| 372 | + else if (ret != num) |
| 373 | + return -EIO; |
| 374 | + else |
| 375 | + return 0; |
| 376 | +} |
| 377 | + |
| 378 | +static int __i2c_rollball_get_page(struct i2c_adapter *i2c, int bus_addr, |
| 379 | + u8 *page) |
| 380 | +{ |
| 381 | + struct i2c_msg msgs[2]; |
| 382 | + u8 addr = SFP_PAGE; |
| 383 | + |
| 384 | + msgs[0].addr = bus_addr; |
| 385 | + msgs[0].flags = 0; |
| 386 | + msgs[0].len = 1; |
| 387 | + msgs[0].buf = &addr; |
| 388 | + |
| 389 | + msgs[1].addr = bus_addr; |
| 390 | + msgs[1].flags = I2C_M_RD; |
| 391 | + msgs[1].len = 1; |
| 392 | + msgs[1].buf = page; |
| 393 | + |
| 394 | + return __i2c_transfer_err(i2c, msgs, 2); |
| 395 | +} |
| 396 | + |
| 397 | +static int __i2c_rollball_set_page(struct i2c_adapter *i2c, int bus_addr, |
| 398 | + u8 page) |
| 399 | +{ |
| 400 | + struct i2c_msg msg; |
| 401 | + u8 buf[2]; |
| 402 | + |
| 403 | + buf[0] = SFP_PAGE; |
| 404 | + buf[1] = page; |
| 405 | + |
| 406 | + msg.addr = bus_addr; |
| 407 | + msg.flags = 0; |
| 408 | + msg.len = 2; |
| 409 | + msg.buf = buf; |
| 410 | + |
| 411 | + return __i2c_transfer_err(i2c, &msg, 1); |
| 412 | +} |
| 413 | + |
| 414 | +/* In order to not interfere with other SFP code (which possibly may manipulate |
| 415 | + * SFP_PAGE), for every transfer we do this: |
| 416 | + * 1. lock the bus |
| 417 | + * 2. save content of SFP_PAGE |
| 418 | + * 3. set SFP_PAGE to 3 |
| 419 | + * 4. do the transfer |
| 420 | + * 5. restore original SFP_PAGE |
| 421 | + * 6. unlock the bus |
| 422 | + * Note that one might think that steps 2 to 5 could be theoretically done all |
| 423 | + * in one call to i2c_transfer (by constructing msgs array in such a way), but |
| 424 | + * unfortunately tests show that this does not work :-( Changed SFP_PAGE does |
| 425 | + * not take into account until i2c_transfer() is done. |
| 426 | + */ |
| 427 | +static int i2c_transfer_rollball(struct i2c_adapter *i2c, |
| 428 | + struct i2c_msg *msgs, int num) |
| 429 | +{ |
| 430 | + int ret, main_err = 0; |
| 431 | + u8 saved_page; |
| 432 | + |
| 433 | + i2c_lock_bus(i2c, I2C_LOCK_SEGMENT); |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 434 | + |
| 435 | + /* save original page */ |
| 436 | + ret = __i2c_rollball_get_page(i2c, msgs->addr, &saved_page); |
| 437 | + if (ret) |
| 438 | + goto unlock; |
| 439 | + |
| 440 | + /* change to RollBall MDIO page */ |
| 441 | + ret = __i2c_rollball_set_page(i2c, msgs->addr, SFP_PAGE_ROLLBALL_MDIO); |
| 442 | + if (ret) |
| 443 | + goto unlock; |
| 444 | + |
| 445 | + /* do the transfer; we try to restore original page if this fails */ |
| 446 | + ret = __i2c_transfer_err(i2c, msgs, num); |
| 447 | + if (ret) |
| 448 | + main_err = ret; |
| 449 | + |
| 450 | + /* restore original page */ |
| 451 | + ret = __i2c_rollball_set_page(i2c, msgs->addr, saved_page); |
| 452 | + |
| 453 | +unlock: |
| 454 | + i2c_unlock_bus(i2c, I2C_LOCK_SEGMENT); |
| 455 | + |
| 456 | + return main_err ? : ret; |
| 457 | +} |
| 458 | + |
| 459 | +static int i2c_rollball_mii_poll(struct mii_bus *bus, int bus_addr, u8 *buf, |
| 460 | + size_t len) |
| 461 | +{ |
| 462 | + struct i2c_adapter *i2c = bus->priv; |
| 463 | + struct i2c_msg msgs[2]; |
| 464 | + u8 cmd_addr, tmp, *res; |
| 465 | + int i, ret; |
| 466 | + |
| 467 | + cmd_addr = ROLLBALL_CMD_ADDR; |
| 468 | + |
| 469 | + res = buf ? buf : &tmp; |
| 470 | + len = buf ? len : 1; |
| 471 | + |
| 472 | + msgs[0].addr = bus_addr; |
| 473 | + msgs[0].flags = 0; |
| 474 | + msgs[0].len = 1; |
| 475 | + msgs[0].buf = &cmd_addr; |
| 476 | + |
| 477 | + msgs[1].addr = bus_addr; |
| 478 | + msgs[1].flags = I2C_M_RD; |
| 479 | + msgs[1].len = len; |
| 480 | + msgs[1].buf = res; |
| 481 | + |
| 482 | + /* By experiment it takes up to 70 ms to access a register for these |
| 483 | + * SFPs. Sleep 20ms between iterations and try 10 times. |
| 484 | + */ |
| 485 | + i = 10; |
| 486 | + do { |
| 487 | + msleep(20); |
| 488 | + |
| 489 | + ret = i2c_transfer_rollball(i2c, msgs, ARRAY_SIZE(msgs)); |
| 490 | + if (ret) |
| 491 | + return ret; |
| 492 | + |
| 493 | + if (*res == ROLLBALL_CMD_DONE) |
| 494 | + return 0; |
| 495 | + } while (i-- > 0); |
| 496 | + |
| 497 | + dev_info(&bus->dev, "poll timed out\n"); |
| 498 | + |
| 499 | + return -ETIMEDOUT; |
| 500 | +} |
| 501 | + |
| 502 | +static int i2c_rollball_mii_cmd(struct mii_bus *bus, int bus_addr, u8 cmd, |
| 503 | + u8 *data, size_t len) |
| 504 | +{ |
| 505 | + struct i2c_adapter *i2c = bus->priv; |
| 506 | + struct i2c_msg msgs[2]; |
| 507 | + u8 cmdbuf[2]; |
| 508 | + |
| 509 | + cmdbuf[0] = ROLLBALL_CMD_ADDR; |
| 510 | + cmdbuf[1] = cmd; |
| 511 | + |
| 512 | + msgs[0].addr = bus_addr; |
| 513 | + msgs[0].flags = 0; |
| 514 | + msgs[0].len = len; |
| 515 | + msgs[0].buf = data; |
| 516 | + |
| 517 | + msgs[1].addr = bus_addr; |
| 518 | + msgs[1].flags = 0; |
| 519 | + msgs[1].len = sizeof(cmdbuf); |
| 520 | + msgs[1].buf = cmdbuf; |
| 521 | + |
| 522 | + return i2c_transfer_rollball(i2c, msgs, ARRAY_SIZE(msgs)); |
| 523 | +} |
| 524 | + |
| 525 | +static int i2c_mii_read_rollball(struct mii_bus *bus, int phy_id, int reg) |
| 526 | +{ |
| 527 | + u8 buf[4], res[6]; |
| 528 | + int bus_addr, ret; |
| 529 | + u16 val; |
| 530 | + |
| 531 | + if (!(reg & MII_ADDR_C45)) |
| 532 | + return -EOPNOTSUPP; |
| 533 | + |
| 534 | + bus_addr = i2c_mii_phy_addr(phy_id); |
| 535 | + if (bus_addr != ROLLBALL_PHY_I2C_ADDR) |
| 536 | + return 0xffff; |
| 537 | + |
| 538 | + buf[0] = ROLLBALL_DATA_ADDR; |
| 539 | + buf[1] = (reg >> 16) & 0x1f; |
| 540 | + buf[2] = (reg >> 8) & 0xff; |
| 541 | + buf[3] = reg & 0xff; |
| 542 | + |
| 543 | + ret = i2c_rollball_mii_cmd(bus, bus_addr, ROLLBALL_CMD_READ, buf, |
| 544 | + sizeof(buf)); |
| 545 | + if (ret < 0) |
| 546 | + return ret; |
| 547 | + |
| 548 | + ret = i2c_rollball_mii_poll(bus, bus_addr, res, sizeof(res)); |
| 549 | + if (ret == -ETIMEDOUT) |
| 550 | + return 0xffff; |
| 551 | + else if (ret < 0) |
| 552 | + return ret; |
| 553 | + |
| 554 | + val = res[4] << 8 | res[5]; |
| 555 | + |
| 556 | + return val; |
| 557 | +} |
| 558 | + |
| 559 | +static int i2c_mii_write_rollball(struct mii_bus *bus, int phy_id, int reg, |
| 560 | + u16 val) |
| 561 | +{ |
| 562 | + int bus_addr, ret; |
| 563 | + u8 buf[6]; |
| 564 | + |
| 565 | + if (!(reg & MII_ADDR_C45)) |
| 566 | + return -EOPNOTSUPP; |
| 567 | + |
| 568 | + bus_addr = i2c_mii_phy_addr(phy_id); |
| 569 | + if (bus_addr != ROLLBALL_PHY_I2C_ADDR) |
| 570 | + return 0; |
| 571 | + |
| 572 | + buf[0] = ROLLBALL_DATA_ADDR; |
| 573 | + buf[1] = (reg >> 16) & 0x1f; |
| 574 | + buf[2] = (reg >> 8) & 0xff; |
| 575 | + buf[3] = reg & 0xff; |
| 576 | + buf[4] = val >> 8; |
| 577 | + buf[5] = val & 0xff; |
| 578 | + |
| 579 | + ret = i2c_rollball_mii_cmd(bus, bus_addr, ROLLBALL_CMD_WRITE, buf, |
| 580 | + sizeof(buf)); |
| 581 | + if (ret < 0) |
| 582 | + return ret; |
| 583 | + |
| 584 | + ret = i2c_rollball_mii_poll(bus, bus_addr, NULL, 0); |
| 585 | + if (ret < 0) |
| 586 | + return ret; |
| 587 | + |
| 588 | + return 0; |
| 589 | +} |
| 590 | + |
| 591 | +static int i2c_mii_init_rollball(struct i2c_adapter *i2c) |
| 592 | +{ |
| 593 | + struct i2c_msg msg; |
| 594 | + u8 pw[5]; |
| 595 | + int ret; |
| 596 | + |
| 597 | + pw[0] = ROLLBALL_PASSWORD; |
| 598 | + pw[1] = 0xff; |
| 599 | + pw[2] = 0xff; |
| 600 | + pw[3] = 0xff; |
| 601 | + pw[4] = 0xff; |
| 602 | + |
| 603 | + msg.addr = ROLLBALL_PHY_I2C_ADDR; |
| 604 | + msg.flags = 0; |
| 605 | + msg.len = sizeof(pw); |
| 606 | + msg.buf = pw; |
| 607 | + |
| 608 | + ret = i2c_transfer(i2c, &msg, 1); |
| 609 | + if (ret < 0) |
| 610 | + return ret; |
| 611 | + else if (ret != 1) |
| 612 | + return -EIO; |
| 613 | + else |
| 614 | + return 0; |
| 615 | +} |
| 616 | + |
| 617 | +struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c, |
| 618 | + enum mdio_i2c_proto protocol) |
| 619 | { |
| 620 | struct mii_bus *mii; |
| 621 | + int ret; |
| 622 | |
| 623 | if (!i2c_check_functionality(i2c, I2C_FUNC_I2C)) |
| 624 | return ERR_PTR(-EINVAL); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 625 | @@ -104,10 +385,28 @@ struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 626 | |
| 627 | snprintf(mii->id, MII_BUS_ID_SIZE, "i2c:%s", dev_name(parent)); |
| 628 | mii->parent = parent; |
| 629 | - mii->read = i2c_mii_read; |
| 630 | - mii->write = i2c_mii_write; |
| 631 | mii->priv = i2c; |
| 632 | |
| 633 | + switch (protocol) { |
| 634 | + case MDIO_I2C_ROLLBALL: |
| 635 | + ret = i2c_mii_init_rollball(i2c); |
| 636 | + if (ret < 0) { |
| 637 | + dev_err(parent, |
| 638 | + "Cannot initialize RollBall MDIO I2C protocol: %d\n", |
| 639 | + ret); |
| 640 | + mdiobus_free(mii); |
| 641 | + return ERR_PTR(ret); |
| 642 | + } |
| 643 | + |
| 644 | + mii->read = i2c_mii_read_rollball; |
| 645 | + mii->write = i2c_mii_write_rollball; |
| 646 | + break; |
| 647 | + default: |
| 648 | + mii->read = i2c_mii_read_default; |
| 649 | + mii->write = i2c_mii_write_default; |
| 650 | + break; |
| 651 | + } |
| 652 | + |
| 653 | return mii; |
| 654 | } |
| 655 | EXPORT_SYMBOL_GPL(mdio_i2c_alloc); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 656 | diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c |
| 657 | index f360d9225..67f34ed4c 100644 |
developer | 82eae45 | 2023-02-13 10:04:09 +0800 | [diff] [blame] | 658 | --- a/drivers/net/phy/phylink.c |
| 659 | +++ b/drivers/net/phy/phylink.c |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 660 | @@ -483,62 +483,105 @@ static void phylink_resolve(struct work_struct *w) |
developer | 82eae45 | 2023-02-13 10:04:09 +0800 | [diff] [blame] | 661 | struct phylink *pl = container_of(w, struct phylink, resolve); |
| 662 | struct phylink_link_state link_state; |
| 663 | struct net_device *ndev = pl->netdev; |
| 664 | - int link_changed; |
| 665 | + bool mac_config = false; |
| 666 | + bool retrigger = false; |
| 667 | + bool cur_link_state; |
| 668 | |
| 669 | mutex_lock(&pl->state_mutex); |
| 670 | + if (pl->netdev) |
| 671 | + cur_link_state = netif_carrier_ok(ndev); |
| 672 | + else |
| 673 | + cur_link_state = pl->old_link_state; |
| 674 | + |
| 675 | if (pl->phylink_disable_state) { |
| 676 | pl->mac_link_dropped = false; |
| 677 | link_state.link = false; |
| 678 | } else if (pl->mac_link_dropped) { |
| 679 | link_state.link = false; |
| 680 | + retrigger = true; |
| 681 | } else { |
| 682 | switch (pl->cur_link_an_mode) { |
| 683 | case MLO_AN_PHY: |
| 684 | link_state = pl->phy_state; |
| 685 | phylink_resolve_flow(pl, &link_state); |
| 686 | - phylink_mac_config_up(pl, &link_state); |
| 687 | + mac_config = link_state.link; |
| 688 | break; |
| 689 | |
| 690 | case MLO_AN_FIXED: |
| 691 | phylink_get_fixed_state(pl, &link_state); |
| 692 | - phylink_mac_config_up(pl, &link_state); |
| 693 | + mac_config = link_state.link; |
| 694 | break; |
| 695 | |
| 696 | case MLO_AN_INBAND: |
| 697 | phylink_get_mac_state(pl, &link_state); |
| 698 | |
| 699 | + /* The PCS may have a latching link-fail indicator. |
| 700 | + * If the link was up, bring the link down and |
| 701 | + * re-trigger the resolve. Otherwise, re-read the |
| 702 | + * PCS state to get the current status of the link. |
| 703 | + */ |
| 704 | + if (!link_state.link) { |
| 705 | + if (cur_link_state) |
| 706 | + retrigger = true; |
| 707 | + else |
| 708 | + phylink_get_mac_state(pl, |
| 709 | + &link_state); |
| 710 | + } |
| 711 | + |
| 712 | /* If we have a phy, the "up" state is the union of |
| 713 | - * both the PHY and the MAC */ |
| 714 | + * both the PHY and the MAC |
| 715 | + */ |
| 716 | if (pl->phydev) |
| 717 | link_state.link &= pl->phy_state.link; |
| 718 | |
| 719 | /* Only update if the PHY link is up */ |
| 720 | if (pl->phydev && pl->phy_state.link) { |
| 721 | + /* If the interface has changed, force a |
| 722 | + * link down event if the link isn't already |
| 723 | + * down, and re-resolve. |
| 724 | + */ |
| 725 | + if (link_state.interface != |
| 726 | + pl->phy_state.interface) { |
| 727 | + retrigger = true; |
| 728 | + link_state.link = false; |
| 729 | + } |
| 730 | link_state.interface = pl->phy_state.interface; |
| 731 | |
| 732 | /* If we have a PHY, we need to update with |
| 733 | - * the pause mode bits. */ |
| 734 | - link_state.pause |= pl->phy_state.pause; |
| 735 | - phylink_resolve_flow(pl, &link_state); |
| 736 | - phylink_mac_config(pl, &link_state); |
| 737 | + * the PHY flow control bits. |
| 738 | + */ |
| 739 | + link_state.pause = pl->phy_state.pause; |
| 740 | + mac_config = true; |
| 741 | } |
| 742 | + phylink_resolve_flow(pl, &link_state); |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | - if (pl->netdev) |
| 748 | - link_changed = (link_state.link != netif_carrier_ok(ndev)); |
| 749 | - else |
| 750 | - link_changed = (link_state.link != pl->old_link_state); |
| 751 | + if (mac_config) { |
| 752 | + if (link_state.interface != pl->link_config.interface) { |
| 753 | + /* The interface has changed, force the link down and |
| 754 | + * then reconfigure. |
| 755 | + */ |
| 756 | + if (cur_link_state) { |
| 757 | + phylink_mac_link_down(pl); |
| 758 | + cur_link_state = false; |
| 759 | + } |
| 760 | + phylink_mac_config(pl, &link_state); |
| 761 | + pl->link_config.interface = link_state.interface; |
| 762 | + } else { |
| 763 | + phylink_mac_config(pl, &link_state); |
| 764 | + } |
| 765 | + } |
| 766 | |
| 767 | - if (link_changed) { |
| 768 | + if (link_state.link != cur_link_state) { |
| 769 | pl->old_link_state = link_state.link; |
| 770 | if (!link_state.link) |
| 771 | phylink_mac_link_down(pl); |
| 772 | else |
| 773 | phylink_mac_link_up(pl, link_state); |
| 774 | } |
| 775 | - if (!link_state.link && pl->mac_link_dropped) { |
| 776 | + if (!link_state.link && retrigger) { |
| 777 | pl->mac_link_dropped = false; |
| 778 | queue_work(system_power_efficient_wq, &pl->resolve); |
| 779 | } |
| 780 | @@ -1014,7 +1057,8 @@ void phylink_start(struct phylink *pl) |
| 781 | if (irq <= 0) |
| 782 | mod_timer(&pl->link_poll, jiffies + HZ); |
| 783 | } |
| 784 | - if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->get_fixed_state) |
| 785 | + if ((pl->cfg_link_an_mode == MLO_AN_FIXED && pl->get_fixed_state) || |
| 786 | + (pl->cfg_link_an_mode == MLO_AN_INBAND)) |
| 787 | mod_timer(&pl->link_poll, jiffies + HZ); |
| 788 | if (pl->phydev) |
| 789 | phy_start(pl->phydev); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 790 | diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c |
| 791 | index a2f451c31..4be24406b 100644 |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 792 | --- a/drivers/net/phy/sfp-bus.c |
| 793 | +++ b/drivers/net/phy/sfp-bus.c |
| 794 | @@ -10,12 +10,6 @@ |
| 795 | |
| 796 | #include "sfp.h" |
| 797 | |
| 798 | -struct sfp_quirk { |
| 799 | - const char *vendor; |
| 800 | - const char *part; |
| 801 | - void (*modes)(const struct sfp_eeprom_id *id, unsigned long *modes); |
| 802 | -}; |
| 803 | - |
| 804 | /** |
| 805 | * struct sfp_bus - internal representation of a sfp bus |
| 806 | */ |
| 807 | @@ -38,87 +32,6 @@ struct sfp_bus { |
| 808 | bool started; |
| 809 | }; |
| 810 | |
| 811 | -static void sfp_quirk_2500basex(const struct sfp_eeprom_id *id, |
| 812 | - unsigned long *modes) |
| 813 | -{ |
| 814 | - phylink_set(modes, 2500baseX_Full); |
| 815 | -} |
| 816 | - |
| 817 | -static void sfp_quirk_ubnt_uf_instant(const struct sfp_eeprom_id *id, |
| 818 | - unsigned long *modes) |
| 819 | -{ |
| 820 | - /* Ubiquiti U-Fiber Instant module claims that support all transceiver |
| 821 | - * types including 10G Ethernet which is not truth. So clear all claimed |
| 822 | - * modes and set only one mode which module supports: 1000baseX_Full. |
| 823 | - */ |
| 824 | - phylink_zero(modes); |
| 825 | - phylink_set(modes, 1000baseX_Full); |
| 826 | -} |
| 827 | - |
| 828 | -static const struct sfp_quirk sfp_quirks[] = { |
| 829 | - { |
| 830 | - // Alcatel Lucent G-010S-P can operate at 2500base-X, but |
| 831 | - // incorrectly report 2500MBd NRZ in their EEPROM |
| 832 | - .vendor = "ALCATELLUCENT", |
| 833 | - .part = "G010SP", |
| 834 | - .modes = sfp_quirk_2500basex, |
| 835 | - }, { |
| 836 | - // Alcatel Lucent G-010S-A can operate at 2500base-X, but |
| 837 | - // report 3.2GBd NRZ in their EEPROM |
| 838 | - .vendor = "ALCATELLUCENT", |
| 839 | - .part = "3FE46541AA", |
| 840 | - .modes = sfp_quirk_2500basex, |
| 841 | - }, { |
| 842 | - // Huawei MA5671A can operate at 2500base-X, but report 1.2GBd |
| 843 | - // NRZ in their EEPROM |
| 844 | - .vendor = "HUAWEI", |
| 845 | - .part = "MA5671A", |
| 846 | - .modes = sfp_quirk_2500basex, |
| 847 | - }, { |
| 848 | - .vendor = "UBNT", |
| 849 | - .part = "UF-INSTANT", |
| 850 | - .modes = sfp_quirk_ubnt_uf_instant, |
| 851 | - }, |
| 852 | -}; |
| 853 | - |
| 854 | -static size_t sfp_strlen(const char *str, size_t maxlen) |
| 855 | -{ |
| 856 | - size_t size, i; |
| 857 | - |
| 858 | - /* Trailing characters should be filled with space chars */ |
| 859 | - for (i = 0, size = 0; i < maxlen; i++) |
| 860 | - if (str[i] != ' ') |
| 861 | - size = i + 1; |
| 862 | - |
| 863 | - return size; |
| 864 | -} |
| 865 | - |
| 866 | -static bool sfp_match(const char *qs, const char *str, size_t len) |
| 867 | -{ |
| 868 | - if (!qs) |
| 869 | - return true; |
| 870 | - if (strlen(qs) != len) |
| 871 | - return false; |
| 872 | - return !strncmp(qs, str, len); |
| 873 | -} |
| 874 | - |
| 875 | -static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id) |
| 876 | -{ |
| 877 | - const struct sfp_quirk *q; |
| 878 | - unsigned int i; |
| 879 | - size_t vs, ps; |
| 880 | - |
| 881 | - vs = sfp_strlen(id->base.vendor_name, ARRAY_SIZE(id->base.vendor_name)); |
| 882 | - ps = sfp_strlen(id->base.vendor_pn, ARRAY_SIZE(id->base.vendor_pn)); |
| 883 | - |
| 884 | - for (i = 0, q = sfp_quirks; i < ARRAY_SIZE(sfp_quirks); i++, q++) |
| 885 | - if (sfp_match(q->vendor, id->base.vendor_name, vs) && |
| 886 | - sfp_match(q->part, id->base.vendor_pn, ps)) |
| 887 | - return q; |
| 888 | - |
| 889 | - return NULL; |
| 890 | -} |
| 891 | - |
| 892 | /** |
| 893 | * sfp_parse_port() - Parse the EEPROM base ID, setting the port type |
| 894 | * @bus: a pointer to the &struct sfp_bus structure for the sfp module |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 895 | @@ -236,6 +149,10 @@ void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id, |
| 896 | unsigned int br_min, br_nom, br_max; |
| 897 | __ETHTOOL_DECLARE_LINK_MODE_MASK(modes) = { 0, }; |
| 898 | |
| 899 | + phylink_set(modes, Autoneg); |
| 900 | + phylink_set(modes, Pause); |
| 901 | + phylink_set(modes, Asym_Pause); |
| 902 | + |
| 903 | /* Decode the bitrate information to MBd */ |
| 904 | br_min = br_nom = br_max = 0; |
| 905 | if (id->base.br_nominal) { |
| 906 | @@ -359,14 +276,10 @@ void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id, |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 907 | phylink_set(modes, 1000baseX_Full); |
| 908 | } |
| 909 | |
| 910 | - if (bus->sfp_quirk) |
| 911 | + if (bus->sfp_quirk && bus->sfp_quirk->modes) |
| 912 | bus->sfp_quirk->modes(id, modes); |
| 913 | |
| 914 | bitmap_or(support, support, modes, __ETHTOOL_LINK_MODE_MASK_NBITS); |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 915 | - |
| 916 | - phylink_set(support, Autoneg); |
| 917 | - phylink_set(support, Pause); |
| 918 | - phylink_set(support, Asym_Pause); |
| 919 | } |
| 920 | EXPORT_SYMBOL_GPL(sfp_parse_support); |
| 921 | |
developer | 9002093 | 2023-03-10 18:51:34 +0800 | [diff] [blame] | 922 | @@ -737,12 +650,13 @@ void sfp_link_down(struct sfp_bus *bus) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 923 | } |
| 924 | EXPORT_SYMBOL_GPL(sfp_link_down); |
| 925 | |
| 926 | -int sfp_module_insert(struct sfp_bus *bus, const struct sfp_eeprom_id *id) |
| 927 | +int sfp_module_insert(struct sfp_bus *bus, const struct sfp_eeprom_id *id, |
| 928 | + const struct sfp_quirk *quirk) |
| 929 | { |
| 930 | const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus); |
| 931 | int ret = 0; |
| 932 | |
| 933 | - bus->sfp_quirk = sfp_lookup_quirk(id); |
| 934 | + bus->sfp_quirk = quirk; |
| 935 | |
| 936 | if (ops && ops->module_insert) |
| 937 | ret = ops->module_insert(bus->upstream, id); |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 938 | diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 939 | index f8d1742e0..0fdf5d6d4 100644 |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 940 | --- a/drivers/net/phy/sfp.c |
| 941 | +++ b/drivers/net/phy/sfp.c |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 942 | @@ -165,6 +165,7 @@ static const enum gpiod_flags gpio_flags[] = { |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 943 | * on board (for a copper SFP) time to initialise. |
| 944 | */ |
| 945 | #define T_WAIT msecs_to_jiffies(50) |
| 946 | +#define T_WAIT_ROLLBALL msecs_to_jiffies(25000) |
| 947 | #define T_START_UP msecs_to_jiffies(300) |
| 948 | #define T_START_UP_BAD_GPON msecs_to_jiffies(60000) |
| 949 | |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 950 | @@ -204,8 +205,11 @@ static const enum gpiod_flags gpio_flags[] = { |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 951 | |
| 952 | /* SFP modules appear to always have their PHY configured for bus address |
| 953 | * 0x56 (which with mdio-i2c, translates to a PHY address of 22). |
| 954 | + * RollBall SFPs access phy via SFP Enhanced Digital Diagnostic Interface |
| 955 | + * via address 0x51 (mdio-i2c will use RollBall protocol on this address). |
| 956 | */ |
| 957 | -#define SFP_PHY_ADDR 22 |
| 958 | +#define SFP_PHY_ADDR 22 |
| 959 | +#define SFP_PHY_ADDR_ROLLBALL 17 |
| 960 | |
| 961 | struct sff_data { |
| 962 | unsigned int gpios; |
| 963 | @@ -217,6 +221,7 @@ struct sfp { |
| 964 | struct i2c_adapter *i2c; |
| 965 | struct mii_bus *i2c_mii; |
| 966 | struct sfp_bus *sfp_bus; |
| 967 | + enum mdio_i2c_proto mdio_protocol; |
| 968 | struct phy_device *mod_phy; |
| 969 | const struct sff_data *type; |
| 970 | size_t i2c_block_size; |
| 971 | @@ -233,6 +238,7 @@ struct sfp { |
| 972 | bool need_poll; |
| 973 | |
| 974 | struct mutex st_mutex; /* Protects state */ |
| 975 | + unsigned int state_hw_mask; |
| 976 | unsigned int state_soft_mask; |
| 977 | unsigned int state; |
| 978 | struct delayed_work poll; |
| 979 | @@ -249,6 +255,10 @@ struct sfp { |
| 980 | struct sfp_eeprom_id id; |
| 981 | unsigned int module_power_mW; |
| 982 | unsigned int module_t_start_up; |
| 983 | + unsigned int module_t_wait; |
| 984 | + bool tx_fault_ignore; |
| 985 | + |
| 986 | + const struct sfp_quirk *quirk; |
| 987 | |
| 988 | #if IS_ENABLED(CONFIG_HWMON) |
| 989 | struct sfp_diag diag; |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 990 | @@ -287,6 +297,18 @@ static bool sfp_module_supported(const struct sfp_eeprom_id *id) |
| 991 | !memcmp(id->base.vendor_pn, "UF-INSTANT ", 16)) |
| 992 | return true; |
| 993 | |
| 994 | + /* SFP GPON module SK-LiNK SFP-GE-LX20 SM1310 and SM1550 Instant |
| 995 | + * has in its EEPROM stored phys id UNK instead of SFP. Therefore |
| 996 | + * mark this module explicitly as supported based on vendor name |
| 997 | + * and pn match. |
| 998 | + */ |
| 999 | + if (id->base.phys_id == SFF8024_ID_UNK && |
| 1000 | + id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP && |
| 1001 | + !memcmp(id->base.vendor_name, "SK-LINK ", 16) && |
| 1002 | + (!memcmp(id->base.vendor_pn, "SFP-GE-LX20-SM13", 16) || |
| 1003 | + !memcmp(id->base.vendor_pn, "SFP-GE-LX-SM1550", 16))) |
| 1004 | + return true; |
| 1005 | + |
| 1006 | return false; |
| 1007 | } |
| 1008 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1009 | @@ -303,6 +325,180 @@ static const struct of_device_id sfp_of_match[] = { |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1010 | }; |
| 1011 | MODULE_DEVICE_TABLE(of, sfp_of_match); |
| 1012 | |
| 1013 | +static void sfp_fixup_long_startup(struct sfp *sfp) |
| 1014 | +{ |
| 1015 | + sfp->module_t_start_up = T_START_UP_BAD_GPON; |
| 1016 | +} |
| 1017 | + |
| 1018 | +static void sfp_fixup_ignore_tx_fault(struct sfp *sfp) |
| 1019 | +{ |
| 1020 | + sfp->tx_fault_ignore = true; |
| 1021 | +} |
| 1022 | + |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1023 | +static void sfp_fixup_ruijie_gbic(struct sfp *sfp) |
| 1024 | +{ |
| 1025 | + sfp->mdio_protocol = MDIO_I2C_NONE; |
| 1026 | +} |
| 1027 | + |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1028 | +static void sfp_fixup_halny_gsfp(struct sfp *sfp) |
| 1029 | +{ |
| 1030 | + /* Ignore the TX_FAULT and LOS signals on this module. |
| 1031 | + * these are possibly used for other purposes on this |
| 1032 | + * module, e.g. a serial port. |
| 1033 | + */ |
| 1034 | + sfp->state_hw_mask &= ~(SFP_F_TX_FAULT | SFP_F_LOS); |
| 1035 | +} |
| 1036 | + |
| 1037 | +static void sfp_fixup_rollball(struct sfp *sfp) |
| 1038 | +{ |
| 1039 | + sfp->mdio_protocol = MDIO_I2C_ROLLBALL; |
| 1040 | + sfp->module_t_wait = T_WAIT_ROLLBALL; |
| 1041 | +} |
| 1042 | + |
| 1043 | +static void sfp_fixup_rollball_cc(struct sfp *sfp) |
| 1044 | +{ |
| 1045 | + sfp_fixup_rollball(sfp); |
| 1046 | + |
| 1047 | + /* Some RollBall SFPs may have wrong (zero) extended compliance code |
| 1048 | + * burned in EEPROM. For PHY probing we need the correct one. |
| 1049 | + */ |
| 1050 | + sfp->id.base.extended_cc = SFF8024_ECC_10GBASE_T_SFI; |
| 1051 | +} |
| 1052 | + |
| 1053 | +static void sfp_quirk_2500basex(const struct sfp_eeprom_id *id, |
| 1054 | + unsigned long *modes) |
| 1055 | +{ |
| 1056 | + linkmode_set_bit(ETHTOOL_LINK_MODE_2500baseX_Full_BIT, modes); |
| 1057 | +} |
| 1058 | + |
developer | 82185b7 | 2023-04-10 22:59:38 +0800 | [diff] [blame] | 1059 | +static void sfp_quirk_10000baseSR(const struct sfp_eeprom_id *id, |
| 1060 | + unsigned long *modes) |
| 1061 | +{ |
| 1062 | + linkmode_set_bit(ETHTOOL_LINK_MODE_10000baseSR_Full_BIT, modes); |
| 1063 | +} |
| 1064 | + |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 1065 | +static void sfp_quirk_disable_autoneg(const struct sfp_eeprom_id *id, |
| 1066 | + unsigned long *modes) |
| 1067 | +{ |
| 1068 | + linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, modes); |
| 1069 | +} |
| 1070 | + |
| 1071 | +static void sfp_quirk_oem_2_5g(const struct sfp_eeprom_id *id, |
| 1072 | + unsigned long *modes) |
| 1073 | +{ |
| 1074 | + /* Copper 2.5G SFP */ |
| 1075 | + linkmode_set_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, modes); |
| 1076 | + linkmode_set_bit(ETHTOOL_LINK_MODE_2500baseX_Full_BIT, modes); |
| 1077 | + sfp_quirk_disable_autoneg(id, modes); |
| 1078 | +} |
| 1079 | + |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1080 | +static void sfp_quirk_ubnt_uf_instant(const struct sfp_eeprom_id *id, |
| 1081 | + unsigned long *modes) |
| 1082 | +{ |
| 1083 | + /* Ubiquiti U-Fiber Instant module claims that support all transceiver |
| 1084 | + * types including 10G Ethernet which is not truth. So clear all claimed |
| 1085 | + * modes and set only one mode which module supports: 1000baseX_Full. |
| 1086 | + */ |
| 1087 | + linkmode_zero(modes); |
| 1088 | + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, modes); |
| 1089 | +} |
| 1090 | + |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1091 | +#define SFP_QUIRK(_v, _p, _r, _m, _f) \ |
| 1092 | + { .vendor = _v, .part = _p, .revision = _r, .modes = _m, .fixup = _f, } |
| 1093 | +#define SFP_QUIRK_M(_v, _p, _r, _m) SFP_QUIRK(_v, _p, _r, _m, NULL) |
| 1094 | +#define SFP_QUIRK_F(_v, _p, _r, _f) SFP_QUIRK(_v, _p, _r, NULL, _f) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1095 | + |
| 1096 | +static const struct sfp_quirk sfp_quirks[] = { |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1097 | + // Ruijie MINI-GBIC-GT81 has a RL8211F PHY device, but it cannot |
| 1098 | + // reflect correct BMSR/ADVERTISE from the PHY. |
| 1099 | + SFP_QUIRK_F("RUIJIE", "MINI-GBIC-GT", "81", sfp_fixup_ruijie_gbic), |
| 1100 | + |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1101 | + // Alcatel Lucent G-010S-P can operate at 2500base-X, but incorrectly |
| 1102 | + // report 2500MBd NRZ in their EEPROM |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1103 | + SFP_QUIRK_M("ALCATELLUCENT", "G010SP", '\0', sfp_quirk_2500basex), |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1104 | + |
| 1105 | + // Alcatel Lucent G-010S-A can operate at 2500base-X, but report 3.2GBd |
| 1106 | + // NRZ in their EEPROM |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1107 | + SFP_QUIRK("ALCATELLUCENT", "3FE46541AA", '\0', sfp_quirk_2500basex, |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1108 | + sfp_fixup_long_startup), |
| 1109 | + |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1110 | + SFP_QUIRK_F("HALNy", "HL-GSFP", '\0', sfp_fixup_halny_gsfp), |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1111 | + |
| 1112 | + // Huawei MA5671A can operate at 2500base-X, but report 1.2GBd NRZ in |
| 1113 | + // their EEPROM |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1114 | + SFP_QUIRK("HUAWEI", "MA5671A", '\0', sfp_quirk_2500basex, |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1115 | + sfp_fixup_ignore_tx_fault), |
| 1116 | + |
| 1117 | + // Lantech 8330-262D-E can operate at 2500base-X, but incorrectly report |
| 1118 | + // 2500MBd NRZ in their EEPROM |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1119 | + SFP_QUIRK_M("Lantech", "8330-262D-E", '\0', sfp_quirk_2500basex), |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1120 | + |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 1121 | + // CISCO PLRXPL-VC-S43-CG can operate at 10000baseSR, but not report |
| 1122 | + // in their EEPROM |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1123 | + SFP_QUIRK_M("CISCO-JDSU", "PLRXPL-VC-S43-CG", '\0', sfp_quirk_10000baseSR), |
developer | 82185b7 | 2023-04-10 22:59:38 +0800 | [diff] [blame] | 1124 | + |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1125 | + SFP_QUIRK_M("UBNT", "UF-INSTANT", '\0', sfp_quirk_ubnt_uf_instant), |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1126 | + |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 1127 | + // OEM SFP-2.5G-T can operate at 2500base-T, but not report |
| 1128 | + // in their EEPROM |
| 1129 | + SFP_QUIRK_M("OEM", "SFP-2.5G-T", '\0', sfp_quirk_oem_2_5g), |
| 1130 | + // TP-LINK TL-SM410U can operate at 2500base-T, but not report |
| 1131 | + // in their EEPROM |
| 1132 | + SFP_QUIRK_M("TP-LINK", "TL-SM410U", '\0', sfp_quirk_oem_2_5g), |
| 1133 | + |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1134 | + SFP_QUIRK_F("ETU", "ESP-T5-R", '\0', sfp_fixup_rollball_cc), |
| 1135 | + SFP_QUIRK_F("OEM", "SFP-10G-T", '\0', sfp_fixup_rollball_cc), |
| 1136 | + SFP_QUIRK_F("OEM", "RTSFP-10", '\0', sfp_fixup_rollball_cc), |
| 1137 | + SFP_QUIRK_F("OEM", "RTSFP-10G", '\0', sfp_fixup_rollball_cc), |
| 1138 | + SFP_QUIRK_F("OEM", "TNBYV02-C0X-C3", '\0', sfp_fixup_rollball_cc), |
| 1139 | + SFP_QUIRK_F("Turris", "RTSFP-10", '\0', sfp_fixup_rollball), |
| 1140 | + SFP_QUIRK_F("Turris", "RTSFP-10G", '\0', sfp_fixup_rollball), |
developer | 8912762 | 2023-05-12 17:42:25 +0800 | [diff] [blame] | 1141 | + SFP_QUIRK_F("MIKE", "P60000BBC001-1", '\0', sfp_fixup_rollball), |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1142 | + SFP_QUIRK_F("JESS-LINK", "P60000BBC001-1", '\0', sfp_fixup_rollball), |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1143 | +}; |
| 1144 | + |
| 1145 | +static size_t sfp_strlen(const char *str, size_t maxlen) |
| 1146 | +{ |
| 1147 | + size_t size, i; |
| 1148 | + |
| 1149 | + /* Trailing characters should be filled with space chars, but |
| 1150 | + * some manufacturers can't read SFF-8472 and use NUL. |
| 1151 | + */ |
| 1152 | + for (i = 0, size = 0; i < maxlen; i++) |
| 1153 | + if (str[i] != ' ' && str[i] != '\0') |
| 1154 | + size = i + 1; |
| 1155 | + |
| 1156 | + return size; |
| 1157 | +} |
| 1158 | + |
| 1159 | +static bool sfp_match(const char *qs, const char *str, size_t len) |
| 1160 | +{ |
| 1161 | + if (!qs) |
| 1162 | + return true; |
| 1163 | + if (strlen(qs) != len) |
| 1164 | + return false; |
| 1165 | + return !strncmp(qs, str, len); |
| 1166 | +} |
| 1167 | + |
| 1168 | +static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id) |
| 1169 | +{ |
| 1170 | + const struct sfp_quirk *q; |
| 1171 | + unsigned int i; |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1172 | + size_t vs, ps, rs; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1173 | + |
| 1174 | + vs = sfp_strlen(id->base.vendor_name, ARRAY_SIZE(id->base.vendor_name)); |
| 1175 | + ps = sfp_strlen(id->base.vendor_pn, ARRAY_SIZE(id->base.vendor_pn)); |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1176 | + rs = sfp_strlen(id->base.vendor_rev, ARRAY_SIZE(id->base.vendor_rev)); |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1177 | + |
| 1178 | + for (i = 0, q = sfp_quirks; i < ARRAY_SIZE(sfp_quirks); i++, q++) |
| 1179 | + if (sfp_match(q->vendor, id->base.vendor_name, vs) && |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1180 | + sfp_match(q->part, id->base.vendor_pn, ps) && |
| 1181 | + sfp_match(q->revision, id->base.vendor_rev, rs)) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1182 | + return q; |
| 1183 | + |
| 1184 | + return NULL; |
| 1185 | +} |
| 1186 | + |
| 1187 | static unsigned long poll_jiffies; |
| 1188 | |
| 1189 | static unsigned int sfp_gpio_get_state(struct sfp *sfp) |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1190 | @@ -414,9 +610,6 @@ static int sfp_i2c_write(struct sfp *sfp, bool a2, u8 dev_addr, void *buf, |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1191 | |
| 1192 | static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c) |
| 1193 | { |
| 1194 | - struct mii_bus *i2c_mii; |
| 1195 | - int ret; |
| 1196 | - |
| 1197 | if (!i2c_check_functionality(i2c, I2C_FUNC_I2C)) |
| 1198 | return -EINVAL; |
| 1199 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1200 | @@ -424,7 +617,15 @@ static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1201 | sfp->read = sfp_i2c_read; |
| 1202 | sfp->write = sfp_i2c_write; |
| 1203 | |
| 1204 | - i2c_mii = mdio_i2c_alloc(sfp->dev, i2c); |
| 1205 | + return 0; |
| 1206 | +} |
| 1207 | + |
| 1208 | +static int sfp_i2c_mdiobus_create(struct sfp *sfp) |
| 1209 | +{ |
| 1210 | + struct mii_bus *i2c_mii; |
| 1211 | + int ret; |
| 1212 | + |
| 1213 | + i2c_mii = mdio_i2c_alloc(sfp->dev, sfp->i2c, sfp->mdio_protocol); |
| 1214 | if (IS_ERR(i2c_mii)) |
| 1215 | return PTR_ERR(i2c_mii); |
| 1216 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1217 | @@ -442,6 +643,12 @@ static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
| 1220 | |
| 1221 | +static void sfp_i2c_mdiobus_destroy(struct sfp *sfp) |
| 1222 | +{ |
| 1223 | + mdiobus_unregister(sfp->i2c_mii); |
| 1224 | + sfp->i2c_mii = NULL; |
| 1225 | +} |
| 1226 | + |
| 1227 | /* Interface */ |
| 1228 | static int sfp_read(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len) |
| 1229 | { |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1230 | @@ -487,17 +694,18 @@ static void sfp_soft_set_state(struct sfp *sfp, unsigned int state) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1231 | static void sfp_soft_start_poll(struct sfp *sfp) |
| 1232 | { |
| 1233 | const struct sfp_eeprom_id *id = &sfp->id; |
| 1234 | + unsigned int mask = 0; |
| 1235 | |
| 1236 | sfp->state_soft_mask = 0; |
| 1237 | - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE && |
| 1238 | - !sfp->gpio[GPIO_TX_DISABLE]) |
| 1239 | - sfp->state_soft_mask |= SFP_F_TX_DISABLE; |
| 1240 | - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT && |
| 1241 | - !sfp->gpio[GPIO_TX_FAULT]) |
| 1242 | - sfp->state_soft_mask |= SFP_F_TX_FAULT; |
| 1243 | - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS && |
| 1244 | - !sfp->gpio[GPIO_LOS]) |
| 1245 | - sfp->state_soft_mask |= SFP_F_LOS; |
| 1246 | + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE) |
| 1247 | + mask |= SFP_F_TX_DISABLE; |
| 1248 | + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT) |
| 1249 | + mask |= SFP_F_TX_FAULT; |
| 1250 | + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS) |
| 1251 | + mask |= SFP_F_LOS; |
| 1252 | + |
| 1253 | + // Poll the soft state for hardware pins we want to ignore |
| 1254 | + sfp->state_soft_mask = ~sfp->state_hw_mask & mask; |
| 1255 | |
| 1256 | if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) && |
| 1257 | !sfp->need_poll) |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1258 | @@ -511,10 +719,11 @@ static void sfp_soft_stop_poll(struct sfp *sfp) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1259 | |
| 1260 | static unsigned int sfp_get_state(struct sfp *sfp) |
| 1261 | { |
| 1262 | - unsigned int state = sfp->get_state(sfp); |
| 1263 | + unsigned int soft = sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT); |
| 1264 | + unsigned int state; |
| 1265 | |
| 1266 | - if (state & SFP_F_PRESENT && |
| 1267 | - sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT)) |
| 1268 | + state = sfp->get_state(sfp) & sfp->state_hw_mask; |
| 1269 | + if (state & SFP_F_PRESENT && soft) |
| 1270 | state |= sfp_soft_get_state(sfp); |
| 1271 | |
| 1272 | return state; |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1273 | @@ -1448,12 +1657,12 @@ static void sfp_sm_phy_detach(struct sfp *sfp) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1274 | sfp->mod_phy = NULL; |
| 1275 | } |
| 1276 | |
| 1277 | -static int sfp_sm_probe_phy(struct sfp *sfp, bool is_c45) |
| 1278 | +static int sfp_sm_probe_phy(struct sfp *sfp, int addr, bool is_c45) |
| 1279 | { |
| 1280 | struct phy_device *phy; |
| 1281 | int err; |
| 1282 | |
| 1283 | - phy = get_phy_device(sfp->i2c_mii, SFP_PHY_ADDR, is_c45); |
| 1284 | + phy = get_phy_device(sfp->i2c_mii, addr, is_c45); |
| 1285 | if (phy == ERR_PTR(-ENODEV)) |
| 1286 | return PTR_ERR(phy); |
| 1287 | if (IS_ERR(phy)) { |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1288 | @@ -1548,6 +1757,14 @@ static void sfp_sm_fault(struct sfp *sfp, unsigned int next_state, bool warn) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | +static int sfp_sm_add_mdio_bus(struct sfp *sfp) |
| 1293 | +{ |
| 1294 | + if (sfp->mdio_protocol != MDIO_I2C_NONE) |
| 1295 | + return sfp_i2c_mdiobus_create(sfp); |
| 1296 | + |
| 1297 | + return 0; |
| 1298 | +} |
| 1299 | + |
| 1300 | /* Probe a SFP for a PHY device if the module supports copper - the PHY |
| 1301 | * normally sits at I2C bus address 0x56, and may either be a clause 22 |
| 1302 | * or clause 45 PHY. |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1303 | @@ -1563,36 +1780,52 @@ static int sfp_sm_probe_for_phy(struct sfp *sfp) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1304 | { |
| 1305 | int err = 0; |
| 1306 | |
| 1307 | - switch (sfp->id.base.extended_cc) { |
| 1308 | - case SFF8024_ECC_10GBASE_T_SFI: |
| 1309 | - case SFF8024_ECC_10GBASE_T_SR: |
| 1310 | - case SFF8024_ECC_5GBASE_T: |
| 1311 | - case SFF8024_ECC_2_5GBASE_T: |
| 1312 | - err = sfp_sm_probe_phy(sfp, true); |
| 1313 | + switch (sfp->mdio_protocol) { |
| 1314 | + case MDIO_I2C_NONE: |
| 1315 | break; |
| 1316 | |
| 1317 | - default: |
| 1318 | - if (sfp->id.base.e1000_base_t) |
| 1319 | - err = sfp_sm_probe_phy(sfp, false); |
| 1320 | + case MDIO_I2C_MARVELL_C22: |
| 1321 | + err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, false); |
| 1322 | + break; |
| 1323 | + |
| 1324 | + case MDIO_I2C_C45: |
| 1325 | + err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, true); |
| 1326 | + break; |
| 1327 | + |
| 1328 | + case MDIO_I2C_ROLLBALL: |
| 1329 | + err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR_ROLLBALL, true); |
| 1330 | break; |
| 1331 | } |
| 1332 | + |
| 1333 | return err; |
| 1334 | } |
| 1335 | |
developer | 0d8565e | 2023-05-11 13:34:51 +0800 | [diff] [blame] | 1336 | static int sfp_module_parse_power(struct sfp *sfp) |
| 1337 | { |
| 1338 | u32 power_mW = 1000; |
| 1339 | + bool supports_a2; |
| 1340 | |
| 1341 | - if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_POWER_DECL)) |
| 1342 | + if (sfp->id.ext.sff8472_compliance >= SFP_SFF8472_COMPLIANCE_REV10_2 && |
| 1343 | + sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_POWER_DECL)) |
| 1344 | power_mW = 1500; |
| 1345 | - if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_HIGH_POWER_LEVEL)) |
| 1346 | + /* Added in Rev 11.9, but there is no compliance code for this */ |
| 1347 | + if (sfp->id.ext.sff8472_compliance >= SFP_SFF8472_COMPLIANCE_REV11_4 && |
| 1348 | + sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_HIGH_POWER_LEVEL)) |
| 1349 | power_mW = 2000; |
| 1350 | |
| 1351 | + /* Power level 1 modules (max. 1W) are always supported. */ |
| 1352 | + if (power_mW <= 1000) { |
| 1353 | + sfp->module_power_mW = power_mW; |
| 1354 | + return 0; |
| 1355 | + } |
| 1356 | + |
| 1357 | + supports_a2 = sfp->id.ext.sff8472_compliance != |
| 1358 | + SFP_SFF8472_COMPLIANCE_NONE || |
| 1359 | + sfp->id.ext.diagmon & SFP_DIAGMON_DDM; |
| 1360 | + |
| 1361 | if (power_mW > sfp->max_power_mW) { |
| 1362 | /* Module power specification exceeds the allowed maximum. */ |
| 1363 | - if (sfp->id.ext.sff8472_compliance == |
| 1364 | - SFP_SFF8472_COMPLIANCE_NONE && |
| 1365 | - !(sfp->id.ext.diagmon & SFP_DIAGMON_DDM)) { |
| 1366 | + if (!supports_a2) { |
| 1367 | /* The module appears not to implement bus address |
| 1368 | * 0xa2, so assume that the module powers up in the |
| 1369 | * indicated mode. |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1370 | @@ -1609,13 +1842,21 @@ static int sfp_module_parse_power(struct sfp *sfp) |
developer | 0d8565e | 2023-05-11 13:34:51 +0800 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | + if (!supports_a2) { |
| 1375 | + /* The module power level is below the host maximum and the |
| 1376 | + * module appears not to implement bus address 0xa2, so assume |
| 1377 | + * that the module powers up in the indicated mode. |
| 1378 | + */ |
| 1379 | + return 0; |
| 1380 | + } |
| 1381 | + |
| 1382 | /* If the module requires a higher power mode, but also requires |
| 1383 | * an address change sequence, warn the user that the module may |
| 1384 | * not be functional. |
| 1385 | */ |
| 1386 | - if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE && power_mW > 1000) { |
| 1387 | + if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE) { |
| 1388 | dev_warn(sfp->dev, |
| 1389 | - "Address Change Sequence not supported but module requies %u.%uW, module may not be functional\n", |
| 1390 | + "Address Change Sequence not supported but module requires %u.%uW, module may not be functional\n", |
| 1391 | power_mW / 1000, (power_mW / 100) % 10); |
| 1392 | return 0; |
| 1393 | } |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1394 | @@ -1692,7 +1933,7 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report) |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 1395 | { |
| 1396 | /* SFP module inserted - read I2C data */ |
| 1397 | struct sfp_eeprom_id id; |
| 1398 | - bool cotsworks; |
| 1399 | + bool cotsworks, sklink; |
| 1400 | u8 check; |
| 1401 | int ret; |
| 1402 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1403 | @@ -1747,10 +1988,16 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report) |
developer | 1434070 | 2023-05-30 16:48:14 +0800 | [diff] [blame] | 1404 | */ |
| 1405 | cotsworks = !memcmp(id.base.vendor_name, "COTSWORKS ", 16); |
| 1406 | |
| 1407 | + /* SK-LiNK do not seem to update the checksums when they |
| 1408 | + * do the final programming with the final module part number, |
| 1409 | + * serial number and date code. |
| 1410 | + */ |
| 1411 | + sklink = !memcmp(id.base.vendor_name, "SK-LINK ", 16); |
| 1412 | + |
| 1413 | /* Validate the checksum over the base structure */ |
| 1414 | check = sfp_check(&id.base, sizeof(id.base) - 1); |
| 1415 | if (check != id.base.cc_base) { |
| 1416 | - if (cotsworks) { |
| 1417 | + if (cotsworks || sklink) { |
| 1418 | dev_warn(sfp->dev, |
| 1419 | "EEPROM base structure checksum failure (0x%02x != 0x%02x)\n", |
| 1420 | check, id.base.cc_base); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1421 | @@ -1819,11 +2066,33 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1422 | if (ret < 0) |
| 1423 | return ret; |
| 1424 | |
| 1425 | - if (!memcmp(id.base.vendor_name, "ALCATELLUCENT ", 16) && |
| 1426 | - !memcmp(id.base.vendor_pn, "3FE46541AA ", 16)) |
| 1427 | - sfp->module_t_start_up = T_START_UP_BAD_GPON; |
| 1428 | + /* Initialise state bits to use from hardware */ |
| 1429 | + sfp->state_hw_mask = SFP_F_PRESENT; |
| 1430 | + if (sfp->gpio[GPIO_TX_DISABLE]) |
| 1431 | + sfp->state_hw_mask |= SFP_F_TX_DISABLE; |
| 1432 | + if (sfp->gpio[GPIO_TX_FAULT]) |
| 1433 | + sfp->state_hw_mask |= SFP_F_TX_FAULT; |
| 1434 | + if (sfp->gpio[GPIO_LOS]) |
| 1435 | + sfp->state_hw_mask |= SFP_F_LOS; |
| 1436 | + |
| 1437 | + sfp->module_t_start_up = T_START_UP; |
| 1438 | + sfp->module_t_wait = T_WAIT; |
| 1439 | + |
| 1440 | + sfp->tx_fault_ignore = false; |
| 1441 | + |
| 1442 | + if (sfp->id.base.extended_cc == SFF8024_ECC_10GBASE_T_SFI || |
| 1443 | + sfp->id.base.extended_cc == SFF8024_ECC_10GBASE_T_SR || |
| 1444 | + sfp->id.base.extended_cc == SFF8024_ECC_5GBASE_T || |
| 1445 | + sfp->id.base.extended_cc == SFF8024_ECC_2_5GBASE_T) |
| 1446 | + sfp->mdio_protocol = MDIO_I2C_C45; |
| 1447 | + else if (sfp->id.base.e1000_base_t) |
| 1448 | + sfp->mdio_protocol = MDIO_I2C_MARVELL_C22; |
| 1449 | else |
| 1450 | - sfp->module_t_start_up = T_START_UP; |
| 1451 | + sfp->mdio_protocol = MDIO_I2C_NONE; |
| 1452 | + |
| 1453 | + sfp->quirk = sfp_lookup_quirk(&id); |
| 1454 | + if (sfp->quirk && sfp->quirk->fixup) |
| 1455 | + sfp->quirk->fixup(sfp); |
| 1456 | |
| 1457 | return 0; |
| 1458 | } |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1459 | @@ -1936,7 +2205,8 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1460 | break; |
| 1461 | |
| 1462 | /* Report the module insertion to the upstream device */ |
| 1463 | - err = sfp_module_insert(sfp->sfp_bus, &sfp->id); |
| 1464 | + err = sfp_module_insert(sfp->sfp_bus, &sfp->id, |
| 1465 | + sfp->quirk); |
| 1466 | if (err < 0) { |
| 1467 | sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0); |
| 1468 | break; |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1469 | @@ -1995,6 +2265,8 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1470 | sfp_module_stop(sfp->sfp_bus); |
| 1471 | if (sfp->mod_phy) |
| 1472 | sfp_sm_phy_detach(sfp); |
| 1473 | + if (sfp->i2c_mii) |
| 1474 | + sfp_i2c_mdiobus_destroy(sfp); |
| 1475 | sfp_module_tx_disable(sfp); |
| 1476 | sfp_soft_stop_poll(sfp); |
| 1477 | sfp_sm_next(sfp, SFP_S_DOWN, 0); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1478 | @@ -2018,9 +2290,10 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1479 | |
| 1480 | /* We need to check the TX_FAULT state, which is not defined |
| 1481 | * while TX_DISABLE is asserted. The earliest we want to do |
| 1482 | - * anything (such as probe for a PHY) is 50ms. |
| 1483 | + * anything (such as probe for a PHY) is 50ms (or more on |
| 1484 | + * specific modules). |
| 1485 | */ |
| 1486 | - sfp_sm_next(sfp, SFP_S_WAIT, T_WAIT); |
| 1487 | + sfp_sm_next(sfp, SFP_S_WAIT, sfp->module_t_wait); |
| 1488 | break; |
| 1489 | |
| 1490 | case SFP_S_WAIT: |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1491 | @@ -2034,8 +2307,8 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1492 | * deasserting. |
| 1493 | */ |
| 1494 | timeout = sfp->module_t_start_up; |
| 1495 | - if (timeout > T_WAIT) |
| 1496 | - timeout -= T_WAIT; |
| 1497 | + if (timeout > sfp->module_t_wait) |
| 1498 | + timeout -= sfp->module_t_wait; |
| 1499 | else |
| 1500 | timeout = 1; |
| 1501 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1502 | @@ -2057,6 +2330,12 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1503 | sfp->sm_fault_retries == N_FAULT_INIT); |
| 1504 | } else if (event == SFP_E_TIMEOUT || event == SFP_E_TX_CLEAR) { |
| 1505 | init_done: |
| 1506 | + /* Create mdiobus and start trying for PHY */ |
| 1507 | + ret = sfp_sm_add_mdio_bus(sfp); |
| 1508 | + if (ret < 0) { |
| 1509 | + sfp_sm_next(sfp, SFP_S_FAIL, 0); |
| 1510 | + break; |
| 1511 | + } |
| 1512 | sfp->sm_phy_retries = R_PHY_RETRY; |
| 1513 | goto phy_probe; |
| 1514 | } |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1515 | @@ -2409,6 +2688,8 @@ static int sfp_probe(struct platform_device *pdev) |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1516 | return PTR_ERR(sfp->gpio[i]); |
| 1517 | } |
| 1518 | |
| 1519 | + sfp->state_hw_mask = SFP_F_PRESENT; |
| 1520 | + |
| 1521 | sfp->get_state = sfp_gpio_get_state; |
| 1522 | sfp->set_state = sfp_gpio_set_state; |
| 1523 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1524 | diff --git a/drivers/net/phy/sfp.h b/drivers/net/phy/sfp.h |
| 1525 | index b83f70526..f533e2dd6 100644 |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1526 | --- a/drivers/net/phy/sfp.h |
| 1527 | +++ b/drivers/net/phy/sfp.h |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1528 | @@ -6,6 +6,14 @@ |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1529 | |
| 1530 | struct sfp; |
| 1531 | |
| 1532 | +struct sfp_quirk { |
| 1533 | + const char *vendor; |
| 1534 | + const char *part; |
developer | 6059eb2 | 2023-05-10 21:48:10 +0800 | [diff] [blame] | 1535 | + const char *revision; |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1536 | + void (*modes)(const struct sfp_eeprom_id *id, unsigned long *modes); |
| 1537 | + void (*fixup)(struct sfp *sfp); |
| 1538 | +}; |
| 1539 | + |
| 1540 | struct sfp_socket_ops { |
| 1541 | void (*attach)(struct sfp *sfp); |
| 1542 | void (*detach)(struct sfp *sfp); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1543 | @@ -20,7 +28,8 @@ int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev); |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1544 | void sfp_remove_phy(struct sfp_bus *bus); |
| 1545 | void sfp_link_up(struct sfp_bus *bus); |
| 1546 | void sfp_link_down(struct sfp_bus *bus); |
| 1547 | -int sfp_module_insert(struct sfp_bus *bus, const struct sfp_eeprom_id *id); |
| 1548 | +int sfp_module_insert(struct sfp_bus *bus, const struct sfp_eeprom_id *id, |
| 1549 | + const struct sfp_quirk *quirk); |
| 1550 | void sfp_module_remove(struct sfp_bus *bus); |
| 1551 | int sfp_module_start(struct sfp_bus *bus); |
| 1552 | void sfp_module_stop(struct sfp_bus *bus); |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1553 | diff --git a/include/linux/mdio/mdio-i2c.h b/include/linux/mdio/mdio-i2c.h |
| 1554 | index 751dab281..1c2114068 100644 |
| 1555 | --- a/include/linux/mdio/mdio-i2c.h |
| 1556 | +++ b/include/linux/mdio/mdio-i2c.h |
| 1557 | @@ -11,6 +11,14 @@ struct device; |
| 1558 | struct i2c_adapter; |
| 1559 | struct mii_bus; |
developer | f1e143b | 2023-01-09 16:25:59 +0800 | [diff] [blame] | 1560 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1561 | -struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c); |
| 1562 | +enum mdio_i2c_proto { |
| 1563 | + MDIO_I2C_NONE, |
| 1564 | + MDIO_I2C_MARVELL_C22, |
| 1565 | + MDIO_I2C_C45, |
| 1566 | + MDIO_I2C_ROLLBALL, |
developer | f1e143b | 2023-01-09 16:25:59 +0800 | [diff] [blame] | 1567 | +}; |
| 1568 | + |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1569 | +struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c, |
| 1570 | + enum mdio_i2c_proto protocol); |
developer | c9bd9ae | 2022-12-23 16:54:36 +0800 | [diff] [blame] | 1571 | |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1572 | #endif |
| 1573 | -- |
| 1574 | 2.34.1 |
| 1575 | |