net: phy: provide phylib stubs for hardware timestamping operations
net/core/dev_ioctl.c (built-in code) will want to call phy_mii_ioctl()
for hardware timestamping purposes. This is not directly possible,
because phy_mii_ioctl() is a symbol provided under CONFIG_PHYLIB.
Do something similar to what was done in DSA in commit 5a17818682
("net: dsa: replace NETDEV_PRE_CHANGE_HWTSTAMP notifier with a stub"),
and arrange some indirect calls to phy_mii_ioctl() through a stub
structure containing function pointers, that's provided by phylib as
built-in even when CONFIG_PHYLIB=m, and which phy_init() populates at
runtime (module insertion).
Note: maybe the ownership of the ethtool_phy_ops singleton is backwards,
and the methods exposed by that should be later merged into phylib_stubs.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20230801142824.1772134-12-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
70ef7d87f6
commit
60495b6622
|
@ -7752,6 +7752,7 @@ F: include/linux/mii.h
|
||||||
F: include/linux/of_net.h
|
F: include/linux/of_net.h
|
||||||
F: include/linux/phy.h
|
F: include/linux/phy.h
|
||||||
F: include/linux/phy_fixed.h
|
F: include/linux/phy_fixed.h
|
||||||
|
F: include/linux/phylib_stubs.h
|
||||||
F: include/linux/platform_data/mdio-bcm-unimac.h
|
F: include/linux/platform_data/mdio-bcm-unimac.h
|
||||||
F: include/linux/platform_data/mdio-gpio.h
|
F: include/linux/platform_data/mdio-gpio.h
|
||||||
F: include/trace/events/mdio.h
|
F: include/trace/events/mdio.h
|
||||||
|
|
|
@ -14,6 +14,8 @@ endif
|
||||||
# dedicated loadable module, so we bundle them all together into libphy.ko
|
# dedicated loadable module, so we bundle them all together into libphy.ko
|
||||||
ifdef CONFIG_PHYLIB
|
ifdef CONFIG_PHYLIB
|
||||||
libphy-y += $(mdio-bus-y)
|
libphy-y += $(mdio-bus-y)
|
||||||
|
# the stubs are built-in whenever PHYLIB is built-in or module
|
||||||
|
obj-y += stubs.o
|
||||||
else
|
else
|
||||||
obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o
|
obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -455,6 +455,40 @@ int phy_do_ioctl_running(struct net_device *dev, struct ifreq *ifr, int cmd)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(phy_do_ioctl_running);
|
EXPORT_SYMBOL(phy_do_ioctl_running);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __phy_hwtstamp_get - Get hardware timestamping configuration from PHY
|
||||||
|
*
|
||||||
|
* @phydev: the PHY device structure
|
||||||
|
* @config: structure holding the timestamping configuration
|
||||||
|
*
|
||||||
|
* Query the PHY device for its current hardware timestamping configuration.
|
||||||
|
*/
|
||||||
|
int __phy_hwtstamp_get(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config)
|
||||||
|
{
|
||||||
|
if (!phydev)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
return phy_mii_ioctl(phydev, config->ifr, SIOCGHWTSTAMP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __phy_hwtstamp_set - Modify PHY hardware timestamping configuration
|
||||||
|
*
|
||||||
|
* @phydev: the PHY device structure
|
||||||
|
* @config: structure holding the timestamping configuration
|
||||||
|
* @extack: netlink extended ack structure, for error reporting
|
||||||
|
*/
|
||||||
|
int __phy_hwtstamp_set(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config,
|
||||||
|
struct netlink_ext_ack *extack)
|
||||||
|
{
|
||||||
|
if (!phydev)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
return phy_mii_ioctl(phydev, config->ifr, SIOCSHWTSTAMP);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* phy_queue_state_machine - Trigger the state machine to run soon
|
* phy_queue_state_machine - Trigger the state machine to run soon
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
#include <linux/netdevice.h>
|
#include <linux/netdevice.h>
|
||||||
#include <linux/phy.h>
|
#include <linux/phy.h>
|
||||||
|
#include <linux/phylib_stubs.h>
|
||||||
#include <linux/phy_led_triggers.h>
|
#include <linux/phy_led_triggers.h>
|
||||||
#include <linux/pse-pd/pse.h>
|
#include <linux/pse-pd/pse.h>
|
||||||
#include <linux/property.h>
|
#include <linux/property.h>
|
||||||
|
@ -3448,12 +3449,28 @@ static const struct ethtool_phy_ops phy_ethtool_phy_ops = {
|
||||||
.start_cable_test_tdr = phy_start_cable_test_tdr,
|
.start_cable_test_tdr = phy_start_cable_test_tdr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct phylib_stubs __phylib_stubs = {
|
||||||
|
.hwtstamp_get = __phy_hwtstamp_get,
|
||||||
|
.hwtstamp_set = __phy_hwtstamp_set,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void phylib_register_stubs(void)
|
||||||
|
{
|
||||||
|
phylib_stubs = &__phylib_stubs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void phylib_unregister_stubs(void)
|
||||||
|
{
|
||||||
|
phylib_stubs = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int __init phy_init(void)
|
static int __init phy_init(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rtnl_lock();
|
rtnl_lock();
|
||||||
ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops);
|
ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops);
|
||||||
|
phylib_register_stubs();
|
||||||
rtnl_unlock();
|
rtnl_unlock();
|
||||||
|
|
||||||
rc = mdio_bus_init();
|
rc = mdio_bus_init();
|
||||||
|
@ -3478,6 +3495,7 @@ err_mdio_bus:
|
||||||
mdio_bus_exit();
|
mdio_bus_exit();
|
||||||
err_ethtool_phy_ops:
|
err_ethtool_phy_ops:
|
||||||
rtnl_lock();
|
rtnl_lock();
|
||||||
|
phylib_unregister_stubs();
|
||||||
ethtool_set_ethtool_phy_ops(NULL);
|
ethtool_set_ethtool_phy_ops(NULL);
|
||||||
rtnl_unlock();
|
rtnl_unlock();
|
||||||
|
|
||||||
|
@ -3490,6 +3508,7 @@ static void __exit phy_exit(void)
|
||||||
phy_driver_unregister(&genphy_driver);
|
phy_driver_unregister(&genphy_driver);
|
||||||
mdio_bus_exit();
|
mdio_bus_exit();
|
||||||
rtnl_lock();
|
rtnl_lock();
|
||||||
|
phylib_unregister_stubs();
|
||||||
ethtool_set_ethtool_phy_ops(NULL);
|
ethtool_set_ethtool_phy_ops(NULL);
|
||||||
rtnl_unlock();
|
rtnl_unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/*
|
||||||
|
* Stubs for PHY library functionality called by the core network stack.
|
||||||
|
* These are necessary because CONFIG_PHYLIB can be a module, and built-in
|
||||||
|
* code cannot directly call symbols exported by modules.
|
||||||
|
*/
|
||||||
|
#include <linux/phylib_stubs.h>
|
||||||
|
|
||||||
|
const struct phylib_stubs *phylib_stubs;
|
||||||
|
EXPORT_SYMBOL_GPL(phylib_stubs);
|
|
@ -298,6 +298,7 @@ static inline const char *phy_modes(phy_interface_t interface)
|
||||||
#define MII_BUS_ID_SIZE 61
|
#define MII_BUS_ID_SIZE 61
|
||||||
|
|
||||||
struct device;
|
struct device;
|
||||||
|
struct kernel_hwtstamp_config;
|
||||||
struct phylink;
|
struct phylink;
|
||||||
struct sfp_bus;
|
struct sfp_bus;
|
||||||
struct sfp_upstream_ops;
|
struct sfp_upstream_ops;
|
||||||
|
@ -1955,6 +1956,12 @@ int phy_ethtool_set_plca_cfg(struct phy_device *phydev,
|
||||||
int phy_ethtool_get_plca_status(struct phy_device *phydev,
|
int phy_ethtool_get_plca_status(struct phy_device *phydev,
|
||||||
struct phy_plca_status *plca_st);
|
struct phy_plca_status *plca_st);
|
||||||
|
|
||||||
|
int __phy_hwtstamp_get(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config);
|
||||||
|
int __phy_hwtstamp_set(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config,
|
||||||
|
struct netlink_ext_ack *extack);
|
||||||
|
|
||||||
static inline int phy_package_read(struct phy_device *phydev, u32 regnum)
|
static inline int phy_package_read(struct phy_device *phydev, u32 regnum)
|
||||||
{
|
{
|
||||||
struct phy_package_shared *shared = phydev->shared;
|
struct phy_package_shared *shared = phydev->shared;
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
/*
|
||||||
|
* Stubs for the Network PHY library
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/rtnetlink.h>
|
||||||
|
|
||||||
|
struct kernel_hwtstamp_config;
|
||||||
|
struct netlink_ext_ack;
|
||||||
|
struct phy_device;
|
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_PHYLIB)
|
||||||
|
|
||||||
|
extern const struct phylib_stubs *phylib_stubs;
|
||||||
|
|
||||||
|
struct phylib_stubs {
|
||||||
|
int (*hwtstamp_get)(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config);
|
||||||
|
int (*hwtstamp_set)(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config,
|
||||||
|
struct netlink_ext_ack *extack);
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline int phy_hwtstamp_get(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config)
|
||||||
|
{
|
||||||
|
/* phylib_register_stubs() and phylib_unregister_stubs()
|
||||||
|
* also run under rtnl_lock().
|
||||||
|
*/
|
||||||
|
ASSERT_RTNL();
|
||||||
|
|
||||||
|
if (!phylib_stubs)
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
|
return phylib_stubs->hwtstamp_get(phydev, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int phy_hwtstamp_set(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config,
|
||||||
|
struct netlink_ext_ack *extack)
|
||||||
|
{
|
||||||
|
/* phylib_register_stubs() and phylib_unregister_stubs()
|
||||||
|
* also run under rtnl_lock().
|
||||||
|
*/
|
||||||
|
ASSERT_RTNL();
|
||||||
|
|
||||||
|
if (!phylib_stubs)
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
|
return phylib_stubs->hwtstamp_set(phydev, config, extack);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline int phy_hwtstamp_get(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config)
|
||||||
|
{
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int phy_hwtstamp_set(struct phy_device *phydev,
|
||||||
|
struct kernel_hwtstamp_config *config,
|
||||||
|
struct netlink_ext_ack *extack)
|
||||||
|
{
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue