forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'phy-listing-link_topology-tracking'
Maxime Chevallier says: ==================== Introduce PHY listing and link_topology tracking This is V11 for the link topology addition, allowing to track all PHYs that are linked to netdevices. This V11 addresses the various netlink-related issues that were raised by Jakub, and fixes some typos in the documentation. As a remainder, here's what the PHY listings would look like : - eth0 has a 88x3310 acting as media converter, and an SFP module with an embedded 88e1111 PHY - eth2 has a 88e1510 PHY PHY for eth0: PHY index: 1 Driver name: mv88x3310 PHY device name: f212a600.mdio-mii:00 Downstream SFP bus name: sfp-eth0 PHY id: 0 Upstream type: MAC PHY for eth0: PHY index: 2 Driver name: Marvell 88E1111 PHY device name: i2c:sfp-eth0:16 PHY id: 21040322 Upstream type: PHY Upstream PHY index: 1 Upstream SFP name: sfp-eth0 PHY for eth2: PHY index: 1 Driver name: Marvell 88E1510 PHY device name: f212a20.mdio-mii:00 PHY id: 21040593 Upstream type: MAC Ethtool patches : https://github.com/minimaxwell/ethtool/tree/link-topo-v6 ==================== Signed-off-by: David S. Miller <[email protected]>
- Loading branch information
Showing
22 changed files
with
385 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* | ||
* Infrastructure to handle all PHY devices connected to a given netdev, | ||
* either directly or indirectly attached. | ||
* | ||
* Copyright (c) 2023 Maxime Chevallier<[email protected]> | ||
*/ | ||
|
||
#include <linux/phy_link_topology.h> | ||
#include <linux/netdevice.h> | ||
#include <linux/phy.h> | ||
#include <linux/rtnetlink.h> | ||
#include <linux/xarray.h> | ||
|
||
struct phy_link_topology *phy_link_topo_create(struct net_device *dev) | ||
{ | ||
struct phy_link_topology *topo; | ||
|
||
topo = kzalloc(sizeof(*topo), GFP_KERNEL); | ||
if (!topo) | ||
return ERR_PTR(-ENOMEM); | ||
|
||
xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1); | ||
topo->next_phy_index = 1; | ||
|
||
return topo; | ||
} | ||
|
||
void phy_link_topo_destroy(struct phy_link_topology *topo) | ||
{ | ||
if (!topo) | ||
return; | ||
|
||
xa_destroy(&topo->phys); | ||
kfree(topo); | ||
} | ||
|
||
int phy_link_topo_add_phy(struct phy_link_topology *topo, | ||
struct phy_device *phy, | ||
enum phy_upstream upt, void *upstream) | ||
{ | ||
struct phy_device_node *pdn; | ||
int ret; | ||
|
||
pdn = kzalloc(sizeof(*pdn), GFP_KERNEL); | ||
if (!pdn) | ||
return -ENOMEM; | ||
|
||
pdn->phy = phy; | ||
switch (upt) { | ||
case PHY_UPSTREAM_MAC: | ||
pdn->upstream.netdev = (struct net_device *)upstream; | ||
if (phy_on_sfp(phy)) | ||
pdn->parent_sfp_bus = pdn->upstream.netdev->sfp_bus; | ||
break; | ||
case PHY_UPSTREAM_PHY: | ||
pdn->upstream.phydev = (struct phy_device *)upstream; | ||
if (phy_on_sfp(phy)) | ||
pdn->parent_sfp_bus = pdn->upstream.phydev->sfp_bus; | ||
break; | ||
default: | ||
ret = -EINVAL; | ||
goto err; | ||
} | ||
pdn->upstream_type = upt; | ||
|
||
/* Attempt to re-use a previously allocated phy_index */ | ||
if (phy->phyindex) { | ||
ret = xa_insert(&topo->phys, phy->phyindex, pdn, GFP_KERNEL); | ||
|
||
/* Errors could be either -ENOMEM or -EBUSY. If the phy has an | ||
* index, and there's another entry at the same index, this is | ||
* unexpected and we still error-out | ||
*/ | ||
if (ret) | ||
goto err; | ||
return 0; | ||
} | ||
|
||
ret = xa_alloc_cyclic(&topo->phys, &phy->phyindex, pdn, xa_limit_32b, | ||
&topo->next_phy_index, GFP_KERNEL); | ||
if (ret) | ||
goto err; | ||
|
||
return 0; | ||
|
||
err: | ||
kfree(pdn); | ||
return ret; | ||
} | ||
EXPORT_SYMBOL_GPL(phy_link_topo_add_phy); | ||
|
||
void phy_link_topo_del_phy(struct phy_link_topology *topo, | ||
struct phy_device *phy) | ||
{ | ||
struct phy_device_node *pdn = xa_erase(&topo->phys, phy->phyindex); | ||
|
||
/* We delete the PHY from the topology, however we don't re-set the | ||
* phy->phyindex field. If the PHY isn't gone, we can re-assign it the | ||
* same index next time it's added back to the topology | ||
*/ | ||
|
||
kfree(pdn); | ||
} | ||
EXPORT_SYMBOL_GPL(phy_link_topo_del_phy); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.