From: Ivan Bornyakov <i.bornyakov@metrotek.ru>
To: unlisted-recipients:; (no To-header on input)
Cc: Ivan Bornyakov <i.bornyakov@metrotek.ru>,
system@metrotek.ru, andrew@lunn.ch, hkallweit1@gmail.com,
linux@armlinux.org.uk, davem@davemloft.net, kuba@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next v2 1/3] net: phy: marvell-88x2222: check that link is operational
Date: Tue, 13 Apr 2021 23:54:50 +0300 [thread overview]
Message-ID: <2dbac64b0eb7d91962d1f66ac485b8efaa8b0528.1618347034.git.i.bornyakov@metrotek.ru> (raw)
In-Reply-To: <cover.1618347034.git.i.bornyakov@metrotek.ru>
Some SFP modules uses RX_LOS for link indication. In such cases link
will be always up, even without cable connected. RX_LOS changes will
trigger link_up()/link_down() upstream operations. Thus, check that SFP
link is operational before actual read link status.
If there is no SFP cage connected to the tranciever, check only PMD
Recieve Signal Detect register.
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
---
drivers/net/phy/marvell-88x2222.c | 43 +++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/drivers/net/phy/marvell-88x2222.c b/drivers/net/phy/marvell-88x2222.c
index eca8c2f20684..28fe520228a4 100644
--- a/drivers/net/phy/marvell-88x2222.c
+++ b/drivers/net/phy/marvell-88x2222.c
@@ -32,6 +32,10 @@
#define MV_HOST_RST_SW BIT(7)
#define MV_PORT_RST_SW (MV_LINE_RST_SW | MV_HOST_RST_SW)
+/* PMD Receive Signal Detect */
+#define MV_RX_SIGNAL_DETECT 0x000A
+#define MV_RX_SIGNAL_DETECT_GLOBAL BIT(0)
+
/* 1000Base-X/SGMII Control Register */
#define MV_1GBX_CTRL (0x2000 + MII_BMCR)
@@ -51,6 +55,7 @@
struct mv2222_data {
phy_interface_t line_interface;
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
+ bool sfp_link;
};
/* SFI PMA transmit enable */
@@ -139,6 +144,21 @@ static int mv2222_read_status_1g(struct phy_device *phydev)
return link;
}
+static bool mv2222_link_is_operational(struct phy_device *phydev)
+{
+ struct mv2222_data *priv = phydev->priv;
+ int val;
+
+ val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_RX_SIGNAL_DETECT);
+ if (val < 0 || !(val & MV_RX_SIGNAL_DETECT_GLOBAL))
+ return false;
+
+ if (phydev->sfp_bus && !priv->sfp_link)
+ return false;
+
+ return true;
+}
+
static int mv2222_read_status(struct phy_device *phydev)
{
struct mv2222_data *priv = phydev->priv;
@@ -148,6 +168,9 @@ static int mv2222_read_status(struct phy_device *phydev)
phydev->speed = SPEED_UNKNOWN;
phydev->duplex = DUPLEX_UNKNOWN;
+ if (!mv2222_link_is_operational(phydev))
+ return 0;
+
if (priv->line_interface == PHY_INTERFACE_MODE_10GBASER)
link = mv2222_read_status_10g(phydev);
else
@@ -446,9 +469,29 @@ static void mv2222_sfp_remove(void *upstream)
linkmode_zero(priv->supported);
}
+static void mv2222_sfp_link_up(void *upstream)
+{
+ struct phy_device *phydev = upstream;
+ struct mv2222_data *priv;
+
+ priv = phydev->priv;
+ priv->sfp_link = true;
+}
+
+static void mv2222_sfp_link_down(void *upstream)
+{
+ struct phy_device *phydev = upstream;
+ struct mv2222_data *priv;
+
+ priv = phydev->priv;
+ priv->sfp_link = false;
+}
+
static const struct sfp_upstream_ops sfp_phy_ops = {
.module_insert = mv2222_sfp_insert,
.module_remove = mv2222_sfp_remove,
+ .link_up = mv2222_sfp_link_up,
+ .link_down = mv2222_sfp_link_down,
.attach = phy_sfp_attach,
.detach = phy_sfp_detach,
};
--
2.26.3
next prev parent reply other threads:[~2021-04-13 20:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-13 20:54 [PATCH net-next v2 0/3] net: phy: marvell-88x2222: a couple of improvements Ivan Bornyakov
2021-04-13 20:54 ` Ivan Bornyakov [this message]
2021-04-13 20:54 ` [PATCH net-next v2 2/3] net: phy: marvell-88x2222: move read_status after config_aneg Ivan Bornyakov
2021-04-13 20:54 ` [PATCH net-next v2 3/3] net: phy: marvell-88x2222: swap 1G/10G modes on autoneg Ivan Bornyakov
2021-04-14 20:00 ` [PATCH net-next v2 0/3] net: phy: marvell-88x2222: a couple of improvements patchwork-bot+netdevbpf
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=2dbac64b0eb7d91962d1f66ac485b8efaa8b0528.1618347034.git.i.bornyakov@metrotek.ru \
--to=i.bornyakov@metrotek.ru \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=system@metrotek.ru \
/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).