at803x fiber/SFP support
Subsystems (3)
cover at803x fiber/SFP support
Add support for 1000Base-X fiber modes to the at803x PHY driver, as well as support for connecting a downstream SFP cage.
Robert Hancock (2):
net: phy: at803x: add fiber support
net: phy: at803x: Support downstream SFP cage
drivers/net/phy/at803x.c | 122 +++++++++++++++++++++++++++++++++++---- 1 file changed, 112 insertions(+), 10 deletions(-)
Signature · 1 line
2.27.0
PATCH 1/2 net: phy: at803x: add fiber support
Previously this driver always forced the copper page to be selected, however for AR8031 in 100Base-FX or 1000Base-X modes, the fiber page needs to be selected. Set the appropriate mode based on the hardware mode_cfg strap selection.
Enable the appropriate interrupt bits to detect fiber-side link up or down events.
Update config_aneg and read_status methods to use the appropriate Clause 37 calls when fiber mode is in use.
--- drivers/net/phy/at803x.c | 69 ++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 10 deletions(-)
drivers/net/phy/at803x.c +59 -10
@@ -48,6 +48,8 @@#define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12)#define AT803X_INTR_ENABLE_LINK_FAIL BIT(11)#define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10) +#define AT803X_INTR_ENABLE_LINK_FAIL_BX BIT(8) +#define AT803X_INTR_ENABLE_LINK_SUCCESS_BX BIT(7)#define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5)#define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1)#define AT803X_INTR_ENABLE_WOL BIT(0)
@@ -81,7 +83,17 @@#define AT803X_DEBUG_DATA 0x1E#define AT803X_MODE_CFG_MASK 0x0F -#define AT803X_MODE_CFG_SGMII 0x01 +#define AT803X_MODE_CFG_BASET_RGMII 0x00 +#define AT803X_MODE_CFG_BASET_SGMII 0x01 +#define AT803X_MODE_CFG_BX1000_RGMII_50 0x02 +#define AT803X_MODE_CFG_BX1000_RGMII_75 0x03 +#define AT803X_MODE_CFG_BX1000_CONV_50 0x04 +#define AT803X_MODE_CFG_BX1000_CONV_75 0x05 +#define AT803X_MODE_CFG_FX100_RGMII_50 0x06 +#define AT803X_MODE_CFG_FX100_CONV_50 0x07 +#define AT803X_MODE_CFG_RGMII_AUTO_MDET 0x0B +#define AT803X_MODE_CFG_FX100_RGMII_75 0x0E +#define AT803X_MODE_CFG_FX100_CONV_75 0x0F#define AT803X_PSSR 0x11/*PHY-Specific Status Register*/ #define AT803X_PSSR_MR_AN_COMPLETE 0x0200
@@ -191,6 +203,8 @@ struct at803x_priv {u16 clk_25m_mask;u8 smarteee_lpi_tw_1g;u8 smarteee_lpi_tw_100m; +bool is_fiber; +bool is_1000basex;struct regulator_dev *vddio_rdev;struct regulator_dev *vddh_rdev;struct regulator *vddio;
@@ -673,12 +687,32 @@ static int at803x_probe(struct phy_device *phydev) }/* Some bootloaders leave the fiber page selected. -* Switch to the copper page, as otherwise we read -* the PHY capabilities from the fiber side. +* Switch to the appropriate page (fiber or copper), as otherwise we +* read the PHY capabilities from the wrong page. */ if (at803x_match_phy_id (phydev,ATH8031_PHY_ID )) { +int mode_cfg; + + ret =phy_read (phydev,AT803X_REG_CHIP_CONFIG ); +if (ret <0 ) + goto err; + mode_cfg = ret &AT803X_MODE_CFG_MASK ; + +switch (mode_cfg) { +case AT803X_MODE_CFG_BX1000_RGMII_50 : +case AT803X_MODE_CFG_BX1000_RGMII_75 : + priv->is_1000basex = true; + fallthrough; +case AT803X_MODE_CFG_FX100_RGMII_50 : +case AT803X_MODE_CFG_FX100_RGMII_75 : + priv->is_fiber = true; +break ; + } +phy_lock_mdio_bus (phydev); - ret =at803x_write_page (phydev,AT803X_PAGE_COPPER ); + ret =at803x_write_page (phydev, + priv->is_fiber ?AT803X_PAGE_FIBER : +AT803X_PAGE_COPPER );phy_unlock_mdio_bus (phydev);if (ret) goto err;
@@ -703,6 +737,7 @@ static void at803x_remove(struct phy_device *phydev)static int at803x_get_features (struct phy_device *phydev) { +struct at803x_priv *priv = phydev->priv;int err; err =genphy_read_abilities (phydev);
@@ -720,12 +755,13 @@ static int at803x_get_features(struct phy_device *phydev)* As a result of that, ESTATUS_1000_XFULL is set * to 1 even when operating in copper TP mode. * -* Remove this mode from the supported link modes, -* as this driver currently only supports copper -* operation. +* Remove this mode from the supported link modes +* when the device is configured for copper operation. */ -linkmode_clear_bit (ETHTOOL_LINK_MODE_1000baseX_Full_BIT, - phydev->supported); +if (!priv->is_1000basex) +linkmode_clear_bit (ETHTOOL_LINK_MODE_1000baseX_Full_BIT, + phydev->supported); +return 0 ; }
@@ -846,6 +882,7 @@ static int at803x_ack_interrupt(struct phy_device *phydev)static int at803x_config_intr (struct phy_device *phydev) { +struct at803x_priv *priv = phydev->priv;int err;int value;
@@ -862,6 +899,10 @@ static int at803x_config_intr(struct phy_device *phydev) value |=AT803X_INTR_ENABLE_DUPLEX_CHANGED ; value |=AT803X_INTR_ENABLE_LINK_FAIL ; value |=AT803X_INTR_ENABLE_LINK_SUCCESS ; +if (priv->is_fiber) { + value |=AT803X_INTR_ENABLE_LINK_FAIL_BX ; + value |=AT803X_INTR_ENABLE_LINK_SUCCESS_BX ; + } err =phy_write (phydev,AT803X_INTR_ENABLE , value); }else {
@@ -929,8 +970,12 @@ static void at803x_link_change_notify(struct phy_device *phydev)static int at803x_read_status (struct phy_device *phydev) { +struct at803x_priv *priv = phydev->priv;int ss, err, old_link = phydev->link; +if (priv->is_1000basex) +return genphy_c37_read_status (phydev); +/* Update the link, but return if there was an error */ err =genphy_update_link (phydev);if (err)
@@ -1029,6 +1074,7 @@ static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl)static int at803x_config_aneg (struct phy_device *phydev) { +struct at803x_priv *priv = phydev->priv;int ret; ret =at803x_config_mdix (phydev, phydev->mdix_ctrl);
@@ -1045,7 +1091,10 @@ static int at803x_config_aneg(struct phy_device *phydev)return ret; } -return genphy_config_aneg (phydev); +if (priv->is_1000basex) +return genphy_c37_config_aneg (phydev); +else +return genphy_config_aneg (phydev); }static int at803x_get_downshift (struct phy_device *phydev,u8 *d)
Signature · 1 line
2.27.0
Russell King (Oracle)
reviewerRe: [PATCH net-next 1/2] net: phy: at803x: add fiber support
Quoted 81 lines · Robert Hancock
Previously this driver always forced the copper page to be selected, however for AR8031 in 100Base-FX or 1000Base-X modes, the fiber page needs to be selected. Set the appropriate mode based on the hardware
mode_cfgstrap selection.Enable the appropriate interrupt bits to detect fiber-side link up or down events.
Update
config_anegandread_statusmethods to use the appropriate Clause 37 calls when fiber mode is in use.Signed-off-by Robert Hancock <[email protected]>--- drivers/net/phy/at803x.c | 69 ++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 10 deletions(-)drivers/net/phy/at803x.c +31
-3@@ -48,6 +48,8 @@#define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12)#define AT803X_INTR_ENABLE_LINK_FAIL BIT(11)#define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10) +#define AT803X_INTR_ENABLE_LINK_FAIL_BX BIT(8) +#define AT803X_INTR_ENABLE_LINK_SUCCESS_BX BIT(7)#define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5)#define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1)#define AT803X_INTR_ENABLE_WOL BIT(0)@@ -81,7 +83,17 @@#define AT803X_DEBUG_DATA 0x1E#define AT803X_MODE_CFG_MASK 0x0F -#define AT803X_MODE_CFG_SGMII 0x01 +#define AT803X_MODE_CFG_BASET_RGMII 0x00 +#define AT803X_MODE_CFG_BASET_SGMII 0x01 +#define AT803X_MODE_CFG_BX1000_RGMII_50 0x02 +#define AT803X_MODE_CFG_BX1000_RGMII_75 0x03 +#define AT803X_MODE_CFG_BX1000_CONV_50 0x04 +#define AT803X_MODE_CFG_BX1000_CONV_75 0x05 +#define AT803X_MODE_CFG_FX100_RGMII_50 0x06 +#define AT803X_MODE_CFG_FX100_CONV_50 0x07 +#define AT803X_MODE_CFG_RGMII_AUTO_MDET 0x0B +#define AT803X_MODE_CFG_FX100_RGMII_75 0x0E +#define AT803X_MODE_CFG_FX100_CONV_75 0x0F#define AT803X_PSSR 0x11/*PHY-Specific Status Register*/ #define AT803X_PSSR_MR_AN_COMPLETE 0x0200@@ -191,6 +203,8 @@ struct at803x_priv {u16 clk_25m_mask;u8 smarteee_lpi_tw_1g;u8 smarteee_lpi_tw_100m; +bool is_fiber; +bool is_1000basex;struct regulator_dev *vddio_rdev;struct regulator_dev *vddh_rdev;struct regulator *vddio;@@ -673,12 +687,32 @@ static int at803x_probe(struct phy_device *phydev) }/* Some bootloaders leave the fiber page selected. -* Switch to the copper page, as otherwise we read -* the PHY capabilities from the fiber side. +* Switch to the appropriate page (fiber or copper), as otherwise we +* read the PHY capabilities from the wrong page. */ if (at803x_match_phy_id (phydev,ATH8031_PHY_ID )) { +int mode_cfg; + + ret =phy_read (phydev,AT803X_REG_CHIP_CONFIG ); +if (ret <0 ) + goto err; + mode_cfg = ret &AT803X_MODE_CFG_MASK ; + +switch (mode_cfg) { +case AT803X_MODE_CFG_BX1000_RGMII_50 : +case AT803X_MODE_CFG_BX1000_RGMII_75 : + priv->is_1000basex = true; + fallthrough; +case AT803X_MODE_CFG_FX100_RGMII_50 : +case AT803X_MODE_CFG_FX100_RGMII_75 :
drivers/net/phy/at803x.c static int at803x_probe(struct phy_device *phydev) · line 716
Quoted 10 lines
drivers/net/phy/at803x.c +7
-1+ priv->is_fiber = true; +break ; + } +phy_lock_mdio_bus (phydev); - ret =at803x_write_page (phydev,AT803X_PAGE_COPPER ); + ret =at803x_write_page (phydev, + priv->is_fiber ?AT803X_PAGE_FIBER : +AT803X_PAGE_COPPER );phy_unlock_mdio_bus (phydev);
Does this configuration have to be restored when the PHY is resumed, or can we assume that this is always retained? Should this be moved to the config_init method?
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
PATCH 2/2 net: phy: at803x: Support downstream SFP cage
In reply to Robert HancockAdd support for downstream SFP cages for AR8031 and AR8033. This is primarily intended for fiber modules or direct-attach cables, however copper modules which work in 1000Base-X mode may also function. Such modules are allowed with a warning.
--- drivers/net/phy/at803x.c | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
drivers/net/phy/at803x.c +53 -0
@@ -19,6 +19,8 @@#include <linux/regulator/of_regulator.h> #include <linux/regulator/driver.h> #include <linux/regulator/consumer.h> +#include <linux/phylink.h> +#include <linux/sfp.h> #include <dt-bindings/net/qca-ar803x.h> #define AT803X_SPECIFIC_FUNCTION_CONTROL 0x10
@@ -552,6 +554,51 @@ static bool at803x_match_phy_id(struct phy_device *phydev, u32 phy_id) == (phy_id & phydev->drv->phy_id_mask); } +static int at803x_sfp_insert (void *upstream,const struct sfp_eeprom_id *id) +{ +struct phy_device *phydev = upstream; +__ETHTOOL_DECLARE_LINK_MODE_MASK (phy_support); +__ETHTOOL_DECLARE_LINK_MODE_MASK (sfp_support); +phy_interface_t iface; + +linkmode_zero (phy_support); + phylink_set(phy_support, 1000baseX_Full); + phylink_set(phy_support, 1000baseT_Full); +phylink_set (phy_support, Autoneg); +phylink_set (phy_support, Pause); +phylink_set (phy_support, Asym_Pause); + +linkmode_zero (sfp_support); +sfp_parse_support (phydev->sfp_bus, id, sfp_support); +/* Some modules support 10G modes as well as others we support. +* Mask out non-supported modes so the correct interface is picked. +*/ +linkmode_and (sfp_support, phy_support, sfp_support); + + iface =sfp_select_interface (phydev->sfp_bus, sfp_support); + +/* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes +* interface for use with SFP modules. +* However, some copper modules detected as having a preferred SGMII +* interface do default to and function in 1000Base-X mode, so just +* print a warning and allow such modules, as they may have some chance +* of working. +*/ +if (iface ==PHY_INTERFACE_MODE_SGMII ) { +dev_warn (&phydev->mdio.dev,"module may not function if 1000Base-X not supported\n" ); + }else if (iface !=PHY_INTERFACE_MODE_1000BASEX ) { +dev_err (&phydev->mdio.dev,"incompatible SFP module inserted\n" ); +return -EINVAL ; + } +return 0 ; +} + +static const struct sfp_upstream_ops at803x_sfp_ops = { + .attach = phy_sfp_attach, + .detach = phy_sfp_detach, + .module_insert = at803x_sfp_insert, +}; +static int at803x_parse_dt (struct phy_device *phydev) {struct device_node *node = phydev->mdio.dev.of_node;
@@ -716,6 +763,12 @@ static int at803x_probe(struct phy_device *phydev)phy_unlock_mdio_bus (phydev);if (ret) goto err; + +if (priv->is_1000basex) { + ret =phy_sfp_probe (phydev, &at803x_sfp_ops); +if (ret <0 ) + goto err; + } }return 0 ;
Signature · 1 line
2.27.0
Russell King (Oracle)
reviewerRe: [PATCH net-next 2/2] net: phy: at803x: Support downstream SFP cage
Quoted 4 lines · Robert Hancock
Add support for downstream SFP cages for AR8031 and AR8033. This is primarily intended for fiber modules or direct-attach cables, however copper modules which work in 1000Base-X mode may also function. Such modules are allowed with a warning.
Possibly that's because they default to 1000Base-X mode for compatibility, but there are some (MikroTik S-RJ01) for example where the PHY definitely is in SGMII mode and will negotiate 10/100Mbit on its media side which won't work with an AR803x.
drivers/net/phy/at803x.c static bool at803x_match_phy_id(struct phy_device *phydev, u32 phy_id) · line 576
Quoted 4 lines
drivers/net/phy/at803x.c +4
-0+/* Some modules support 10G modes as well as others we support. +* Mask out non-supported modes so the correct interface is picked. +*/ +linkmode_and (sfp_support, phy_support, sfp_support);
I think rather than relying on sfp_select_interface() complaining when sfp_support is empty, do an explicit check here (phylink code effectively does this via the phylink_validate() check.)
You'll then either be given SGMII or 1000BASE-X by sfp_select_interface().
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!