Skip to content

Commit 034fcc2

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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9c5625f commit 034fcc2

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

drivers/net/phy/at803x.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,8 @@ static const struct sfp_upstream_ops at8031_sfp_ops = {
14521452
.attach = phy_sfp_attach,
14531453
.detach = phy_sfp_detach,
14541454
.module_insert = at8031_sfp_insert,
1455+
.connect_phy = phy_sfp_connect_phy,
1456+
.disconnect_phy = phy_sfp_disconnect_phy,
14551457
};
14561458

14571459
static int at8031_parse_dt(struct phy_device *phydev)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ static const struct sfp_upstream_ops sfp_phy_ops = {
555555
.link_down = mv2222_sfp_link_down,
556556
.attach = phy_sfp_attach,
557557
.detach = phy_sfp_detach,
558+
.connect_phy = phy_sfp_connect_phy,
559+
.disconnect_phy = phy_sfp_disconnect_phy,
558560
};
559561

560562
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
@@ -3254,6 +3254,8 @@ static const struct sfp_upstream_ops m88e1510_sfp_ops = {
32543254
.module_remove = m88e1510_sfp_remove,
32553255
.attach = phy_sfp_attach,
32563256
.detach = phy_sfp_detach,
3257+
.connect_phy = phy_sfp_connect_phy,
3258+
.disconnect_phy = phy_sfp_disconnect_phy,
32573259
};
32583260

32593261
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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,46 @@ phy_standalone_show(struct device *dev, struct device_attribute *attr,
13631363
}
13641364
static DEVICE_ATTR_RO(phy_standalone);
13651365

1366+
/**
1367+
* phy_sfp_connect_phy - Connect the SFP module's PHY to the upstream PHY
1368+
* @upstream: pointer to the upstream phy device
1369+
* @phy: pointer to the SFP module's phy device
1370+
*
1371+
* This helper allows keeping track of PHY devices on the link. It adds the
1372+
* SFP module's phy to the phy namespace of the upstream phy
1373+
*/
1374+
int phy_sfp_connect_phy(void *upstream, struct phy_device *phy)
1375+
{
1376+
struct phy_device *phydev = upstream;
1377+
struct phy_link_topology *topo = phy_get_link_topology(phydev);
1378+
1379+
if (topo)
1380+
return phy_link_topo_add_phy(topo, phy, PHY_UPSTREAM_PHY, phydev);
1381+
1382+
return 0;
1383+
}
1384+
EXPORT_SYMBOL(phy_sfp_connect_phy);
1385+
1386+
/**
1387+
* phy_sfp_disconnect_phy - Disconnect the SFP module's PHY from the upstream PHY
1388+
* @upstream: pointer to the upstream phy device
1389+
* @phy: pointer to the SFP module's phy device
1390+
*
1391+
* This helper allows keeping track of PHY devices on the link. It removes the
1392+
* SFP module's phy to the phy namespace of the upstream phy. As the module phy
1393+
* will be destroyed, re-inserting the same module will add a new phy with a
1394+
* new index.
1395+
*/
1396+
void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy)
1397+
{
1398+
struct phy_device *phydev = upstream;
1399+
struct phy_link_topology *topo = phy_get_link_topology(phydev);
1400+
1401+
if (topo)
1402+
phy_link_topo_del_phy(topo, phy);
1403+
}
1404+
EXPORT_SYMBOL(phy_sfp_disconnect_phy);
1405+
13661406
/**
13671407
* phy_sfp_attach - attach the SFP bus to the PHY upstream network device
13681408
* @upstream: pointer to the phy device

include/linux/phy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,8 @@ int phy_suspend(struct phy_device *phydev);
17291729
int phy_resume(struct phy_device *phydev);
17301730
int __phy_resume(struct phy_device *phydev);
17311731
int phy_loopback(struct phy_device *phydev, bool enable);
1732+
int phy_sfp_connect_phy(void *upstream, struct phy_device *phy);
1733+
void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy);
17321734
void phy_sfp_attach(void *upstream, struct sfp_bus *bus);
17331735
void phy_sfp_detach(void *upstream, struct sfp_bus *bus);
17341736
int phy_sfp_probe(struct phy_device *phydev,

0 commit comments

Comments
 (0)