aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/net/phy/phy_device.c
diff options
context:
space:
mode:
authorKory Maincent <kory.maincent@bootlin.com>2023-11-14 12:28:41 +0100
committerDavid S. Miller <davem@davemloft.net>2023-11-18 14:52:57 +0000
commit0f7f463d4821a4f52fa5c0a961389e651d50c384 (patch)
tree76d682494226939dac8adba05bf57ae34b827357 /drivers/net/phy/phy_device.c
parentnet: Replace hwtstamp_source by timestamping layer (diff)
downloadwireguard-linux-0f7f463d4821a4f52fa5c0a961389e651d50c384.tar.xz
wireguard-linux-0f7f463d4821a4f52fa5c0a961389e651d50c384.zip
net: Change the API of PHY default timestamp to MAC
Change the API to select MAC default time stamping instead of the PHY. Indeed the PHY is closer to the wire therefore theoretically it has less delay than the MAC timestamping but the reality is different. Due to lower time stamping clock frequency, latency in the MDIO bus and no PHC hardware synchronization between different PHY, the PHY PTP is often less precise than the MAC. The exception is for PHY designed specially for PTP case but these devices are not very widespread. For not breaking the compatibility I introduce a default_timestamp flag in phy_device that is set by the phy driver to know we are using the old API behavior. The phy_set_timestamp function is called at each call of phy_attach_direct. In case of MAC driver using phylink this function is called when the interface is turned up. Then if the interface goes down and up again the last choice of timestamp will be overwritten by the default choice. A solution could be to cache the timestamp status but it can bring other issues. In case of SFP, if we change the module, it doesn't make sense to blindly re-set the timestamp back to PHY, if the new module has a PHY with mediocre timestamping capabilities. Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/phy_device.c')
-rw-r--r--drivers/net/phy/phy_device.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 2ce74593d6e4..8c4794631daa 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1412,6 +1412,26 @@ int phy_sfp_probe(struct phy_device *phydev,
EXPORT_SYMBOL(phy_sfp_probe);
/**
+ * phy_set_timestamp - set the default selected timestamping device
+ * @dev: Pointer to net_device
+ * @phydev: Pointer to phy_device
+ *
+ * This is used to set default timestamping device taking into account
+ * the new API choice, which is selecting the timestamping from MAC by
+ * default if the phydev does not have default_timestamp flag enabled.
+ */
+static void phy_set_timestamp(struct net_device *dev, struct phy_device *phydev)
+{
+ const struct ethtool_ops *ops = dev->ethtool_ops;
+
+ if (!phy_has_tsinfo(phydev))
+ return;
+
+ if (!ops->get_ts_info || phydev->default_timestamp)
+ dev->ts_layer = PHY_TIMESTAMPING;
+}
+
+/**
* phy_attach_direct - attach a network device to a given PHY device pointer
* @dev: network device to attach
* @phydev: Pointer to phy_device to attach
@@ -1484,6 +1504,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
phydev->phy_link_change = phy_link_change;
if (dev) {
+ phy_set_timestamp(dev, phydev);
phydev->attached_dev = dev;
dev->phydev = phydev;
@@ -1812,6 +1833,22 @@ void phy_detach(struct phy_device *phydev)
phy_suspend(phydev);
if (dev) {
+ const struct ethtool_ops *ops = dev->ethtool_ops;
+ struct ethtool_ts_info ts_info = {0};
+
+ if (ops->get_ts_info) {
+ ops->get_ts_info(dev, &ts_info);
+ if ((ts_info.so_timestamping &
+ SOF_TIMESTAMPING_HARDWARE_MASK) ==
+ SOF_TIMESTAMPING_HARDWARE_MASK)
+ dev->ts_layer = MAC_TIMESTAMPING;
+ else if ((ts_info.so_timestamping &
+ SOF_TIMESTAMPING_SOFTWARE_MASK) ==
+ SOF_TIMESTAMPING_SOFTWARE_MASK)
+ dev->ts_layer = SOFTWARE_TIMESTAMPING;
+ } else {
+ dev->ts_layer = NO_TIMESTAMPING;
+ }
phydev->attached_dev->phydev = NULL;
phydev->attached_dev = NULL;
}