History

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.

Maxime Chevallier committed 2 years ago

Commit 034fcc21 parent 9c5625f6 files · +50 −0Browse files

Unified · Split

6 files
  1. drivers/net/phy/at803x.c +2 −0
  2. drivers/net/phy/marvell-88x2222.c +2 −0
  3. drivers/net/phy/marvell.c +2 −0
  4. drivers/net/phy/marvell10g.c +2 −0
  5. drivers/net/phy/phy_device.c +40 −0
  6. include/linux/phy.h +2 −0
drivers/net/phy/at803x.c+2−0
@@ -1452,6 +1452,8 @@ static const struct sfp_upstream_ops at8031_sfp_ops = { · 1451 unmodified lines
1452 .attach = phy_sfp_attach,1452 .attach = phy_sfp_attach,
1453 .detach = phy_sfp_detach,1453 .detach = phy_sfp_detach,
1454 .module_insert = at8031_sfp_insert,1454 .module_insert = at8031_sfp_insert,
1455 .connect_phy = phy_sfp_connect_phy,
1456 .disconnect_phy = phy_sfp_disconnect_phy,
1455};1457};
1456 1458
1457static int at8031_parse_dt(struct phy_device *phydev)1459static int at8031_parse_dt(struct phy_device *phydev)
drivers/net/phy/marvell-88x2222.c+2−0
@@ -555,6 +555,8 @@ static const struct sfp_upstream_ops sfp_phy_ops = { · 554 unmodified lines
555 .link_down = mv2222_sfp_link_down,555 .link_down = mv2222_sfp_link_down,
556 .attach = phy_sfp_attach,556 .attach = phy_sfp_attach,
557 .detach = phy_sfp_detach,557 .detach = phy_sfp_detach,
558 .connect_phy = phy_sfp_connect_phy,
559 .disconnect_phy = phy_sfp_disconnect_phy,
558};560};
559 561
560static int mv2222_probe(struct phy_device *phydev)562static int mv2222_probe(struct phy_device *phydev)
drivers/net/phy/marvell.c+2−0
@@ -3254,6 +3254,8 @@ static const struct sfp_upstream_ops m88e1510_sfp_ops = { · 3253 unmodified lines
3254 .module_remove = m88e1510_sfp_remove,3254 .module_remove = m88e1510_sfp_remove,
3255 .attach = phy_sfp_attach,3255 .attach = phy_sfp_attach,
3256 .detach = phy_sfp_detach,3256 .detach = phy_sfp_detach,
3257 .connect_phy = phy_sfp_connect_phy,
3258 .disconnect_phy = phy_sfp_disconnect_phy,
3257};3259};
3258 3260
3259static int m88e1510_probe(struct phy_device *phydev)3261static int m88e1510_probe(struct phy_device *phydev)
drivers/net/phy/marvell10g.c+2−0
@@ -503,6 +503,8 @@ static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) · 502 unmodified lines
503static const struct sfp_upstream_ops mv3310_sfp_ops = {503static const struct sfp_upstream_ops mv3310_sfp_ops = {
504 .attach = phy_sfp_attach,504 .attach = phy_sfp_attach,
505 .detach = phy_sfp_detach,505 .detach = phy_sfp_detach,
506 .connect_phy = phy_sfp_connect_phy,
507 .disconnect_phy = phy_sfp_disconnect_phy,
506 .module_insert = mv3310_sfp_insert,508 .module_insert = mv3310_sfp_insert,
507};509};
508 510
drivers/net/phy/phy_device.c+40−0
@@ -1363,6 +1363,46 @@ phy_standalone_show(struct device *dev, struct device_attribute *attr, · 1362 unmodified lines
1363}1363}
1364static DEVICE_ATTR_RO(phy_standalone);1364static DEVICE_ATTR_RO(phy_standalone);
1365 1365
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 */
1374int 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}
1384EXPORT_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 */
1396void 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}
1404EXPORT_SYMBOL(phy_sfp_disconnect_phy);
1405
1366/**1406/**
1367 * phy_sfp_attach - attach the SFP bus to the PHY upstream network device1407 * phy_sfp_attach - attach the SFP bus to the PHY upstream network device
1368 * @upstream: pointer to the phy device1408 * @upstream: pointer to the phy device
include/linux/phy.h+2−0
@@ -1729,6 +1729,8 @@ int phy_suspend(struct phy_device *phydev); · 1728 unmodified lines
1729int phy_resume(struct phy_device *phydev);1729int phy_resume(struct phy_device *phydev);
1730int __phy_resume(struct phy_device *phydev);1730int __phy_resume(struct phy_device *phydev);
1731int phy_loopback(struct phy_device *phydev, bool enable);1731int phy_loopback(struct phy_device *phydev, bool enable);
1732int phy_sfp_connect_phy(void *upstream, struct phy_device *phy);
1733void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy);
1732void phy_sfp_attach(void *upstream, struct sfp_bus *bus);1734void phy_sfp_attach(void *upstream, struct sfp_bus *bus);
1733void phy_sfp_detach(void *upstream, struct sfp_bus *bus);1735void phy_sfp_detach(void *upstream, struct sfp_bus *bus);
1734int phy_sfp_probe(struct phy_device *phydev,1736int phy_sfp_probe(struct phy_device *phydev,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t