1*60495b66SVladimir Oltean /* SPDX-License-Identifier: GPL-2.0-or-later */
2*60495b66SVladimir Oltean /*
3*60495b66SVladimir Oltean * Stubs for the Network PHY library
4*60495b66SVladimir Oltean */
5*60495b66SVladimir Oltean
6*60495b66SVladimir Oltean #include <linux/rtnetlink.h>
7*60495b66SVladimir Oltean
8*60495b66SVladimir Oltean struct kernel_hwtstamp_config;
9*60495b66SVladimir Oltean struct netlink_ext_ack;
10*60495b66SVladimir Oltean struct phy_device;
11*60495b66SVladimir Oltean
12*60495b66SVladimir Oltean #if IS_ENABLED(CONFIG_PHYLIB)
13*60495b66SVladimir Oltean
14*60495b66SVladimir Oltean extern const struct phylib_stubs *phylib_stubs;
15*60495b66SVladimir Oltean
16*60495b66SVladimir Oltean struct phylib_stubs {
17*60495b66SVladimir Oltean int (*hwtstamp_get)(struct phy_device *phydev,
18*60495b66SVladimir Oltean struct kernel_hwtstamp_config *config);
19*60495b66SVladimir Oltean int (*hwtstamp_set)(struct phy_device *phydev,
20*60495b66SVladimir Oltean struct kernel_hwtstamp_config *config,
21*60495b66SVladimir Oltean struct netlink_ext_ack *extack);
22*60495b66SVladimir Oltean };
23*60495b66SVladimir Oltean
phy_hwtstamp_get(struct phy_device * phydev,struct kernel_hwtstamp_config * config)24*60495b66SVladimir Oltean static inline int phy_hwtstamp_get(struct phy_device *phydev,
25*60495b66SVladimir Oltean struct kernel_hwtstamp_config *config)
26*60495b66SVladimir Oltean {
27*60495b66SVladimir Oltean /* phylib_register_stubs() and phylib_unregister_stubs()
28*60495b66SVladimir Oltean * also run under rtnl_lock().
29*60495b66SVladimir Oltean */
30*60495b66SVladimir Oltean ASSERT_RTNL();
31*60495b66SVladimir Oltean
32*60495b66SVladimir Oltean if (!phylib_stubs)
33*60495b66SVladimir Oltean return -EOPNOTSUPP;
34*60495b66SVladimir Oltean
35*60495b66SVladimir Oltean return phylib_stubs->hwtstamp_get(phydev, config);
36*60495b66SVladimir Oltean }
37*60495b66SVladimir Oltean
phy_hwtstamp_set(struct phy_device * phydev,struct kernel_hwtstamp_config * config,struct netlink_ext_ack * extack)38*60495b66SVladimir Oltean static inline int phy_hwtstamp_set(struct phy_device *phydev,
39*60495b66SVladimir Oltean struct kernel_hwtstamp_config *config,
40*60495b66SVladimir Oltean struct netlink_ext_ack *extack)
41*60495b66SVladimir Oltean {
42*60495b66SVladimir Oltean /* phylib_register_stubs() and phylib_unregister_stubs()
43*60495b66SVladimir Oltean * also run under rtnl_lock().
44*60495b66SVladimir Oltean */
45*60495b66SVladimir Oltean ASSERT_RTNL();
46*60495b66SVladimir Oltean
47*60495b66SVladimir Oltean if (!phylib_stubs)
48*60495b66SVladimir Oltean return -EOPNOTSUPP;
49*60495b66SVladimir Oltean
50*60495b66SVladimir Oltean return phylib_stubs->hwtstamp_set(phydev, config, extack);
51*60495b66SVladimir Oltean }
52*60495b66SVladimir Oltean
53*60495b66SVladimir Oltean #else
54*60495b66SVladimir Oltean
phy_hwtstamp_get(struct phy_device * phydev,struct kernel_hwtstamp_config * config)55*60495b66SVladimir Oltean static inline int phy_hwtstamp_get(struct phy_device *phydev,
56*60495b66SVladimir Oltean struct kernel_hwtstamp_config *config)
57*60495b66SVladimir Oltean {
58*60495b66SVladimir Oltean return -EOPNOTSUPP;
59*60495b66SVladimir Oltean }
60*60495b66SVladimir Oltean
phy_hwtstamp_set(struct phy_device * phydev,struct kernel_hwtstamp_config * config,struct netlink_ext_ack * extack)61*60495b66SVladimir Oltean static inline int phy_hwtstamp_set(struct phy_device *phydev,
62*60495b66SVladimir Oltean struct kernel_hwtstamp_config *config,
63*60495b66SVladimir Oltean struct netlink_ext_ack *extack)
64*60495b66SVladimir Oltean {
65*60495b66SVladimir Oltean return -EOPNOTSUPP;
66*60495b66SVladimir Oltean }
67*60495b66SVladimir Oltean
68*60495b66SVladimir Oltean #endif
69