From: Robert Hancock <robert.hancock@calian.com>
To: andrew@lunn.ch, hkallweit1@gmail.com
Cc: linux@armlinux.org.uk, davem@davemloft.net, kuba@kernel.org,
netdev@vger.kernel.org,
Robert Hancock <robert.hancock@calian.com>
Subject: [PATCH net-next 2/2] net: phy: at803x: Support downstream SFP cage
Date: Wed, 30 Jun 2021 12:01:46 -0600 [thread overview]
Message-ID: <20210630180146.1121925-3-robert.hancock@calian.com> (raw)
In-Reply-To: <20210630180146.1121925-1-robert.hancock@calian.com>
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.
Signed-off-by: Robert Hancock <robert.hancock@calian.com>
---
drivers/net/phy/at803x.c | 53 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index 65f546eca5f4..b613e26b6b16 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -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;
--
2.27.0
next prev parent reply other threads:[~2021-06-30 18:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-30 18:01 [PATCH net-next 0/2] at803x fiber/SFP support Robert Hancock
2021-06-30 18:01 ` [PATCH net-next 1/2] net: phy: at803x: add fiber support Robert Hancock
2021-07-01 23:05 ` Russell King (Oracle)
2021-06-30 18:01 ` Robert Hancock [this message]
2021-07-01 23:12 ` [PATCH net-next 2/2] net: phy: at803x: Support downstream SFP cage Russell King (Oracle)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210630180146.1121925-3-robert.hancock@calian.com \
--to=robert.hancock@calian.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).