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
8struct kernel_hwtstamp_config;
9struct netlink_ext_ack;
10struct phy_device;
11
12#if IS_ENABLED(CONFIG_PHYLIB)
13
14extern const struct phylib_stubs *phylib_stubs;
15
16struct phylib_stubs {
17	int (*hwtstamp_get)(struct phy_device *phydev,
18			    struct kernel_hwtstamp_config *config);
19	int (*hwtstamp_set)(struct phy_device *phydev,
20			    struct kernel_hwtstamp_config *config,
21			    struct netlink_ext_ack *extack);
22};
23
24static inline int phy_hwtstamp_get(struct phy_device *phydev,
25				   struct kernel_hwtstamp_config *config)
26{
27	/* phylib_register_stubs() and phylib_unregister_stubs()
28	 * also run under rtnl_lock().
29	 */
30	ASSERT_RTNL();
31
32	if (!phylib_stubs)
33		return -EOPNOTSUPP;
34
35	return phylib_stubs->hwtstamp_get(phydev, config);
36}
37
38static inline int phy_hwtstamp_set(struct phy_device *phydev,
39				   struct kernel_hwtstamp_config *config,
40				   struct netlink_ext_ack *extack)
41{
42	/* phylib_register_stubs() and phylib_unregister_stubs()
43	 * also run under rtnl_lock().
44	 */
45	ASSERT_RTNL();
46
47	if (!phylib_stubs)
48		return -EOPNOTSUPP;
49
50	return phylib_stubs->hwtstamp_set(phydev, config, extack);
51}
52
53#else
54
55static inline int phy_hwtstamp_get(struct phy_device *phydev,
56				   struct kernel_hwtstamp_config *config)
57{
58	return -EOPNOTSUPP;
59}
60
61static inline int phy_hwtstamp_set(struct phy_device *phydev,
62				   struct kernel_hwtstamp_config *config,
63				   struct netlink_ext_ack *extack)
64{
65	return -EOPNOTSUPP;
66}
67
68#endif
69