1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * PHY device list allow maintaining a list of 3 * PHY device list allow maintaining a list of PHY devices that are 4 * part of a netdevice's link topology. PHYs c 4 * part of a netdevice's link topology. PHYs can for example be chained, 5 * as is the case when using a PHY that expose 5 * as is the case when using a PHY that exposes an SFP module, on which an 6 * SFP transceiver that embeds a PHY is connec 6 * SFP transceiver that embeds a PHY is connected. 7 * 7 * 8 * This list can then be used by userspace to 8 * This list can then be used by userspace to leverage individual PHY 9 * capabilities. 9 * capabilities. 10 */ 10 */ 11 #ifndef __PHY_LINK_TOPOLOGY_H 11 #ifndef __PHY_LINK_TOPOLOGY_H 12 #define __PHY_LINK_TOPOLOGY_H 12 #define __PHY_LINK_TOPOLOGY_H 13 13 14 #include <linux/ethtool.h> 14 #include <linux/ethtool.h> 15 #include <linux/netdevice.h> 15 #include <linux/netdevice.h> 16 16 17 struct xarray; 17 struct xarray; 18 struct phy_device; 18 struct phy_device; 19 struct sfp_bus; 19 struct sfp_bus; 20 20 21 struct phy_link_topology { 21 struct phy_link_topology { 22 struct xarray phys; 22 struct xarray phys; 23 u32 next_phy_index; 23 u32 next_phy_index; 24 }; 24 }; 25 25 26 struct phy_device_node { 26 struct phy_device_node { 27 enum phy_upstream upstream_type; 27 enum phy_upstream upstream_type; 28 28 29 union { 29 union { 30 struct net_device *netde 30 struct net_device *netdev; 31 struct phy_device *phyde 31 struct phy_device *phydev; 32 } upstream; 32 } upstream; 33 33 34 struct sfp_bus *parent_sfp_bus; 34 struct sfp_bus *parent_sfp_bus; 35 35 36 struct phy_device *phy; 36 struct phy_device *phy; 37 }; 37 }; 38 38 39 #if IS_ENABLED(CONFIG_PHYLIB) 39 #if IS_ENABLED(CONFIG_PHYLIB) 40 int phy_link_topo_add_phy(struct net_device *d 40 int phy_link_topo_add_phy(struct net_device *dev, 41 struct phy_device *p 41 struct phy_device *phy, 42 enum phy_upstream up 42 enum phy_upstream upt, void *upstream); 43 43 44 void phy_link_topo_del_phy(struct net_device * 44 void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy); 45 45 46 static inline struct phy_device * 46 static inline struct phy_device * 47 phy_link_topo_get_phy(struct net_device *dev, 47 phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) 48 { 48 { 49 struct phy_link_topology *topo = dev-> 49 struct phy_link_topology *topo = dev->link_topo; 50 struct phy_device_node *pdn; 50 struct phy_device_node *pdn; 51 51 52 if (!topo) 52 if (!topo) 53 return NULL; 53 return NULL; 54 54 55 pdn = xa_load(&topo->phys, phyindex); 55 pdn = xa_load(&topo->phys, phyindex); 56 if (pdn) 56 if (pdn) 57 return pdn->phy; 57 return pdn->phy; 58 58 59 return NULL; 59 return NULL; 60 } 60 } 61 61 62 #else 62 #else 63 static inline int phy_link_topo_add_phy(struct 63 static inline int phy_link_topo_add_phy(struct net_device *dev, 64 struct 64 struct phy_device *phy, 65 enum p 65 enum phy_upstream upt, void *upstream) 66 { 66 { 67 return 0; 67 return 0; 68 } 68 } 69 69 70 static inline void phy_link_topo_del_phy(struc 70 static inline void phy_link_topo_del_phy(struct net_device *dev, 71 struc 71 struct phy_device *phy) 72 { 72 { 73 } 73 } 74 74 75 static inline struct phy_device * 75 static inline struct phy_device * 76 phy_link_topo_get_phy(struct net_device *dev, 76 phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) 77 { 77 { 78 return NULL; 78 return NULL; 79 } 79 } 80 #endif 80 #endif 81 81 82 #endif /* __PHY_LINK_TOPOLOGY_H */ 82 #endif /* __PHY_LINK_TOPOLOGY_H */ 83 83
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.