Skip to content

Commit 5858147

Browse files
Ivan Bornyakovdavem330
authored andcommitted
net: phy: marvell-88x2222: check that link is operational
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 87b7e5c commit 5858147

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

drivers/net/phy/marvell-88x2222.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#define MV_HOST_RST_SW BIT(7)
3333
#define MV_PORT_RST_SW (MV_LINE_RST_SW | MV_HOST_RST_SW)
3434

35+
/* PMD Receive Signal Detect */
36+
#define MV_RX_SIGNAL_DETECT 0x000A
37+
#define MV_RX_SIGNAL_DETECT_GLOBAL BIT(0)
38+
3539
/* 1000Base-X/SGMII Control Register */
3640
#define MV_1GBX_CTRL (0x2000 + MII_BMCR)
3741

@@ -51,6 +55,7 @@
5155
struct mv2222_data {
5256
phy_interface_t line_interface;
5357
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
58+
bool sfp_link;
5459
};
5560

5661
/* SFI PMA transmit enable */
@@ -139,6 +144,21 @@ static int mv2222_read_status_1g(struct phy_device *phydev)
139144
return link;
140145
}
141146

147+
static bool mv2222_link_is_operational(struct phy_device *phydev)
148+
{
149+
struct mv2222_data *priv = phydev->priv;
150+
int val;
151+
152+
val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_RX_SIGNAL_DETECT);
153+
if (val < 0 || !(val & MV_RX_SIGNAL_DETECT_GLOBAL))
154+
return false;
155+
156+
if (phydev->sfp_bus && !priv->sfp_link)
157+
return false;
158+
159+
return true;
160+
}
161+
142162
static int mv2222_read_status(struct phy_device *phydev)
143163
{
144164
struct mv2222_data *priv = phydev->priv;
@@ -148,6 +168,9 @@ static int mv2222_read_status(struct phy_device *phydev)
148168
phydev->speed = SPEED_UNKNOWN;
149169
phydev->duplex = DUPLEX_UNKNOWN;
150170

171+
if (!mv2222_link_is_operational(phydev))
172+
return 0;
173+
151174
if (priv->line_interface == PHY_INTERFACE_MODE_10GBASER)
152175
link = mv2222_read_status_10g(phydev);
153176
else
@@ -446,9 +469,29 @@ static void mv2222_sfp_remove(void *upstream)
446469
linkmode_zero(priv->supported);
447470
}
448471

472+
static void mv2222_sfp_link_up(void *upstream)
473+
{
474+
struct phy_device *phydev = upstream;
475+
struct mv2222_data *priv;
476+
477+
priv = phydev->priv;
478+
priv->sfp_link = true;
479+
}
480+
481+
static void mv2222_sfp_link_down(void *upstream)
482+
{
483+
struct phy_device *phydev = upstream;
484+
struct mv2222_data *priv;
485+
486+
priv = phydev->priv;
487+
priv->sfp_link = false;
488+
}
489+
449490
static const struct sfp_upstream_ops sfp_phy_ops = {
450491
.module_insert = mv2222_sfp_insert,
451492
.module_remove = mv2222_sfp_remove,
493+
.link_up = mv2222_sfp_link_up,
494+
.link_down = mv2222_sfp_link_down,
452495
.attach = phy_sfp_attach,
453496
.detach = phy_sfp_detach,
454497
};

0 commit comments

Comments
 (0)