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
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+2−0
@@ -555,6 +555,8 @@ static const struct sfp_upstream_ops sfp_phy_ops = { · 554 unmodified lines
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+2−0
@@ -3254,6 +3254,8 @@ static const struct sfp_upstream_ops m88e1510_sfp_ops = { · 3253 unmodified lines
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+2−0
@@ -503,6 +503,8 @@ static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) · 502 unmodified lines
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+40−0
@@ -1363,6 +1363,46 @@ phy_standalone_show(struct device *dev, struct device_attribute *attr, · 1362 unmodified lines
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+2−0
@@ -1729,6 +1729,8 @@ int phy_suspend(struct phy_device *phydev); · 1728 unmodified lines
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,

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