| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Stubs for the Network PHY library | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | #include <linux/rtnetlink.h> | 
|---|
| 7 |  | 
|---|
| 8 | struct ethtool_eth_phy_stats; | 
|---|
| 9 | struct ethtool_link_ext_stats; | 
|---|
| 10 | struct ethtool_phy_stats; | 
|---|
| 11 | struct kernel_hwtstamp_config; | 
|---|
| 12 | struct netlink_ext_ack; | 
|---|
| 13 | struct phy_device; | 
|---|
| 14 |  | 
|---|
| 15 | #if IS_ENABLED(CONFIG_PHYLIB) | 
|---|
| 16 |  | 
|---|
| 17 | extern const struct phylib_stubs *phylib_stubs; | 
|---|
| 18 |  | 
|---|
| 19 | struct phylib_stubs { | 
|---|
| 20 | int (*hwtstamp_get)(struct phy_device *phydev, | 
|---|
| 21 | struct kernel_hwtstamp_config *config); | 
|---|
| 22 | int (*hwtstamp_set)(struct phy_device *phydev, | 
|---|
| 23 | struct kernel_hwtstamp_config *config, | 
|---|
| 24 | struct netlink_ext_ack *extack); | 
|---|
| 25 | void (*get_phy_stats)(struct phy_device *phydev, | 
|---|
| 26 | struct ethtool_eth_phy_stats *phy_stats, | 
|---|
| 27 | struct ethtool_phy_stats *phydev_stats); | 
|---|
| 28 | void (*get_link_ext_stats)(struct phy_device *phydev, | 
|---|
| 29 | struct ethtool_link_ext_stats *link_stats); | 
|---|
| 30 | }; | 
|---|
| 31 |  | 
|---|
| 32 | static inline int phy_hwtstamp_get(struct phy_device *phydev, | 
|---|
| 33 | struct kernel_hwtstamp_config *config) | 
|---|
| 34 | { | 
|---|
| 35 | /* phylib_register_stubs() and phylib_unregister_stubs() | 
|---|
| 36 | * also run under rtnl_lock(). | 
|---|
| 37 | */ | 
|---|
| 38 | ASSERT_RTNL(); | 
|---|
| 39 |  | 
|---|
| 40 | if (!phylib_stubs) | 
|---|
| 41 | return -EOPNOTSUPP; | 
|---|
| 42 |  | 
|---|
| 43 | return phylib_stubs->hwtstamp_get(phydev, config); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | static inline int phy_hwtstamp_set(struct phy_device *phydev, | 
|---|
| 47 | struct kernel_hwtstamp_config *config, | 
|---|
| 48 | struct netlink_ext_ack *extack) | 
|---|
| 49 | { | 
|---|
| 50 | /* phylib_register_stubs() and phylib_unregister_stubs() | 
|---|
| 51 | * also run under rtnl_lock(). | 
|---|
| 52 | */ | 
|---|
| 53 | ASSERT_RTNL(); | 
|---|
| 54 |  | 
|---|
| 55 | if (!phylib_stubs) | 
|---|
| 56 | return -EOPNOTSUPP; | 
|---|
| 57 |  | 
|---|
| 58 | return phylib_stubs->hwtstamp_set(phydev, config, extack); | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | static inline void phy_ethtool_get_phy_stats(struct phy_device *phydev, | 
|---|
| 62 | struct ethtool_eth_phy_stats *phy_stats, | 
|---|
| 63 | struct ethtool_phy_stats *phydev_stats) | 
|---|
| 64 | { | 
|---|
| 65 | ASSERT_RTNL(); | 
|---|
| 66 |  | 
|---|
| 67 | if (!phylib_stubs) | 
|---|
| 68 | return; | 
|---|
| 69 |  | 
|---|
| 70 | phylib_stubs->get_phy_stats(phydev, phy_stats, phydev_stats); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | static inline void phy_ethtool_get_link_ext_stats(struct phy_device *phydev, | 
|---|
| 74 | struct ethtool_link_ext_stats *link_stats) | 
|---|
| 75 | { | 
|---|
| 76 | ASSERT_RTNL(); | 
|---|
| 77 |  | 
|---|
| 78 | if (!phylib_stubs) | 
|---|
| 79 | return; | 
|---|
| 80 |  | 
|---|
| 81 | phylib_stubs->get_link_ext_stats(phydev, link_stats); | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | #else | 
|---|
| 85 |  | 
|---|
| 86 | static inline int phy_hwtstamp_get(struct phy_device *phydev, | 
|---|
| 87 | struct kernel_hwtstamp_config *config) | 
|---|
| 88 | { | 
|---|
| 89 | return -EOPNOTSUPP; | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | static inline int phy_hwtstamp_set(struct phy_device *phydev, | 
|---|
| 93 | struct kernel_hwtstamp_config *config, | 
|---|
| 94 | struct netlink_ext_ack *extack) | 
|---|
| 95 | { | 
|---|
| 96 | return -EOPNOTSUPP; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | static inline void phy_ethtool_get_phy_stats(struct phy_device *phydev, | 
|---|
| 100 | struct ethtool_eth_phy_stats *phy_stats, | 
|---|
| 101 | struct ethtool_phy_stats *phydev_stats) | 
|---|
| 102 | { | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | static inline void phy_ethtool_get_link_ext_stats(struct phy_device *phydev, | 
|---|
| 106 | struct ethtool_link_ext_stats *link_stats) | 
|---|
| 107 | { | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | #endif | 
|---|
| 111 |  | 
|---|