Skip to content

Commit b2db6f4

Browse files
minimaxwelldavem330
authored andcommitted
net: phy: add helpers to handle sfp phy connect/disconnect
There are a few PHY drivers that can handle SFP modules through their sfp_upstream_ops. Introduce Phylib helpers to keep track of connected SFP PHYs in a netdevice's namespace, by adding the SFP PHY to the upstream PHY's netdev's namespace. By doing so, these SFP PHYs can be enumerated and exposed to users, which will be able to use their capabilities. Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4d76f11 commit b2db6f4

File tree

7 files changed

+54
-0
lines changed

7 files changed

+54
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ static const struct sfp_upstream_ops sfp_phy_ops = {
553553
.link_down = mv2222_sfp_link_down,
554554
.attach = phy_sfp_attach,
555555
.detach = phy_sfp_detach,
556+
.connect_phy = phy_sfp_connect_phy,
557+
.disconnect_phy = phy_sfp_disconnect_phy,
556558
};
557559

558560
static int mv2222_probe(struct phy_device *phydev)

drivers/net/phy/marvell.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,8 @@ static const struct sfp_upstream_ops m88e1510_sfp_ops = {
36133613
.module_remove = m88e1510_sfp_remove,
36143614
.attach = phy_sfp_attach,
36153615
.detach = phy_sfp_detach,
3616+
.connect_phy = phy_sfp_connect_phy,
3617+
.disconnect_phy = phy_sfp_disconnect_phy,
36163618
};
36173619

36183620
static int m88e1510_probe(struct phy_device *phydev)

drivers/net/phy/marvell10g.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
503503
static const struct sfp_upstream_ops mv3310_sfp_ops = {
504504
.attach = phy_sfp_attach,
505505
.detach = phy_sfp_detach,
506+
.connect_phy = phy_sfp_connect_phy,
507+
.disconnect_phy = phy_sfp_disconnect_phy,
506508
.module_insert = mv3310_sfp_insert,
507509
};
508510

drivers/net/phy/phy_device.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,48 @@ phy_standalone_show(struct device *dev, struct device_attribute *attr,
13851385
}
13861386
static DEVICE_ATTR_RO(phy_standalone);
13871387

1388+
/**
1389+
* phy_sfp_connect_phy - Connect the SFP module's PHY to the upstream PHY
1390+
* @upstream: pointer to the upstream phy device
1391+
* @phy: pointer to the SFP module's phy device
1392+
*
1393+
* This helper allows keeping track of PHY devices on the link. It adds the
1394+
* SFP module's phy to the phy namespace of the upstream phy
1395+
*
1396+
* Return: 0 on success, otherwise a negative error code.
1397+
*/
1398+
int phy_sfp_connect_phy(void *upstream, struct phy_device *phy)
1399+
{
1400+
struct phy_device *phydev = upstream;
1401+
struct net_device *dev = phydev->attached_dev;
1402+
1403+
if (dev)
1404+
return phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev);
1405+
1406+
return 0;
1407+
}
1408+
EXPORT_SYMBOL(phy_sfp_connect_phy);
1409+
1410+
/**
1411+
* phy_sfp_disconnect_phy - Disconnect the SFP module's PHY from the upstream PHY
1412+
* @upstream: pointer to the upstream phy device
1413+
* @phy: pointer to the SFP module's phy device
1414+
*
1415+
* This helper allows keeping track of PHY devices on the link. It removes the
1416+
* SFP module's phy to the phy namespace of the upstream phy. As the module phy
1417+
* will be destroyed, re-inserting the same module will add a new phy with a
1418+
* new index.
1419+
*/
1420+
void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy)
1421+
{
1422+
struct phy_device *phydev = upstream;
1423+
struct net_device *dev = phydev->attached_dev;
1424+
1425+
if (dev)
1426+
phy_link_topo_del_phy(dev, phy);
1427+
}
1428+
EXPORT_SYMBOL(phy_sfp_disconnect_phy);
1429+
13881430
/**
13891431
* phy_sfp_attach - attach the SFP bus to the PHY upstream network device
13901432
* @upstream: pointer to the phy device

drivers/net/phy/qcom/at803x.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ static const struct sfp_upstream_ops at8031_sfp_ops = {
770770
.attach = phy_sfp_attach,
771771
.detach = phy_sfp_detach,
772772
.module_insert = at8031_sfp_insert,
773+
.connect_phy = phy_sfp_connect_phy,
774+
.disconnect_phy = phy_sfp_disconnect_phy,
773775
};
774776

775777
static int at8031_parse_dt(struct phy_device *phydev)

drivers/net/phy/qcom/qca807x.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ static const struct sfp_upstream_ops qca807x_sfp_ops = {
699699
.detach = phy_sfp_detach,
700700
.module_insert = qca807x_sfp_insert,
701701
.module_remove = qca807x_sfp_remove,
702+
.connect_phy = phy_sfp_connect_phy,
703+
.disconnect_phy = phy_sfp_disconnect_phy,
702704
};
703705

704706
static int qca807x_probe(struct phy_device *phydev)

include/linux/phy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,8 @@ int phy_suspend(struct phy_device *phydev);
17811781
int phy_resume(struct phy_device *phydev);
17821782
int __phy_resume(struct phy_device *phydev);
17831783
int phy_loopback(struct phy_device *phydev, bool enable);
1784+
int phy_sfp_connect_phy(void *upstream, struct phy_device *phy);
1785+
void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy);
17841786
void phy_sfp_attach(void *upstream, struct sfp_bus *bus);
17851787
void phy_sfp_detach(void *upstream, struct sfp_bus *bus);
17861788
int phy_sfp_probe(struct phy_device *phydev,

0 commit comments

Comments
 (0)