Skip to content

Commit 2dd3560

Browse files
kmaincentkuba-moo
authored andcommitted
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 default_timestamp flag has been introduced in phy_device that is set by the phy driver to know we are using the old API behavior. Reviewed-by: Rahul Rameshbabu <[email protected]> Signed-off-by: Kory Maincent <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e50bfd6 commit 2dd3560

File tree

9 files changed

+43
-8
lines changed

9 files changed

+43
-8
lines changed

drivers/net/phy/bcm-phy-ptp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,9 @@ struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev)
931931
return ERR_CAST(clock);
932932
priv->ptp_clock = clock;
933933

934+
/* Timestamp selected by default to keep legacy API */
935+
phydev->default_timestamp = true;
936+
934937
priv->phydev = phydev;
935938
bcm_ptp_init(priv);
936939

drivers/net/phy/dp83640.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,8 @@ static int dp83640_probe(struct phy_device *phydev)
14471447
for (i = 0; i < MAX_RXTS; i++)
14481448
list_add(&dp83640->rx_pool_data[i].list, &dp83640->rxpool);
14491449

1450+
/* Timestamp selected by default to keep legacy API */
1451+
phydev->default_timestamp = true;
14501452
phydev->mii_ts = &dp83640->mii_ts;
14511453
phydev->priv = dp83640;
14521454

drivers/net/phy/micrel.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3781,6 +3781,9 @@ static void lan8814_ptp_init(struct phy_device *phydev)
37813781
ptp_priv->mii_ts.ts_info = lan8814_ts_info;
37823782

37833783
phydev->mii_ts = &ptp_priv->mii_ts;
3784+
3785+
/* Timestamp selected by default to keep legacy API */
3786+
phydev->default_timestamp = true;
37843787
}
37853788

37863789
static int lan8814_ptp_probe_once(struct phy_device *phydev)
@@ -5279,6 +5282,9 @@ static int lan8841_probe(struct phy_device *phydev)
52795282

52805283
phydev->mii_ts = &ptp_priv->mii_ts;
52815284

5285+
/* Timestamp selected by default to keep legacy API */
5286+
phydev->default_timestamp = true;
5287+
52825288
return 0;
52835289
}
52845290

drivers/net/phy/mscc/mscc_ptp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,9 @@ int vsc8584_ptp_probe(struct phy_device *phydev)
15701570
return PTR_ERR(vsc8531->load_save);
15711571
}
15721572

1573+
/* Timestamp selected by default to keep legacy API */
1574+
phydev->default_timestamp = true;
1575+
15731576
vsc8531->ptp->phydev = phydev;
15741577

15751578
return 0;

drivers/net/phy/nxp-c45-tja11xx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,9 @@ static int nxp_c45_probe(struct phy_device *phydev)
16601660
priv->mii_ts.ts_info = nxp_c45_ts_info;
16611661
phydev->mii_ts = &priv->mii_ts;
16621662
ret = nxp_c45_init_ptp_clock(priv);
1663+
1664+
/* Timestamp selected by default to keep legacy API */
1665+
phydev->default_timestamp = true;
16631666
} else {
16641667
phydev_dbg(phydev, "PTP support not enabled even if the phy supports it");
16651668
}

include/linux/phy.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ struct macsec_ops;
616616
* handling shall be postponed until PHY has resumed
617617
* @irq_rerun: Flag indicating interrupts occurred while PHY was suspended,
618618
* requiring a rerun of the interrupt handler after resume
619+
* @default_timestamp: Flag indicating whether we are using the phy
620+
* timestamp as the default one
619621
* @interface: enum phy_interface_t value
620622
* @possible_interfaces: bitmap if interface modes that the attached PHY
621623
* will switch between depending on media speed.
@@ -681,6 +683,8 @@ struct phy_device {
681683
unsigned irq_suspended:1;
682684
unsigned irq_rerun:1;
683685

686+
unsigned default_timestamp:1;
687+
684688
int rate_matching;
685689

686690
enum phy_state state;
@@ -1625,6 +1629,21 @@ static inline void phy_txtstamp(struct phy_device *phydev, struct sk_buff *skb,
16251629
phydev->mii_ts->txtstamp(phydev->mii_ts, skb, type);
16261630
}
16271631

1632+
/**
1633+
* phy_is_default_hwtstamp - Is the PHY hwtstamp the default timestamp
1634+
* @phydev: Pointer to phy_device
1635+
*
1636+
* This is used to get default timestamping device taking into account
1637+
* the new API choice, which is selecting the timestamping from MAC by
1638+
* default if the phydev does not have default_timestamp flag enabled.
1639+
*
1640+
* Return: True if phy is the default hw timestamp, false otherwise.
1641+
*/
1642+
static inline bool phy_is_default_hwtstamp(struct phy_device *phydev)
1643+
{
1644+
return phy_has_hwtstamp(phydev) && phydev->default_timestamp;
1645+
}
1646+
16281647
/**
16291648
* phy_is_internal - Convenience function for testing if a PHY is internal
16301649
* @phydev: the phy_device struct

net/core/dev_ioctl.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ static int dev_eth_ioctl(struct net_device *dev,
259259
* @dev: Network device
260260
* @cfg: Timestamping configuration structure
261261
*
262-
* Helper for enforcing a common policy that phylib timestamping, if available,
263-
* should take precedence in front of hardware timestamping provided by the
264-
* netdev.
262+
* Helper for calling the default hardware provider timestamping.
265263
*
266264
* Note: phy_mii_ioctl() only handles SIOCSHWTSTAMP (not SIOCGHWTSTAMP), and
267265
* there only exists a phydev->mii_ts->hwtstamp() method. So this will return
@@ -271,7 +269,7 @@ static int dev_eth_ioctl(struct net_device *dev,
271269
static int dev_get_hwtstamp_phylib(struct net_device *dev,
272270
struct kernel_hwtstamp_config *cfg)
273271
{
274-
if (phy_has_hwtstamp(dev->phydev))
272+
if (phy_is_default_hwtstamp(dev->phydev))
275273
return phy_hwtstamp_get(dev->phydev, cfg);
276274

277275
return dev->netdev_ops->ndo_hwtstamp_get(dev, cfg);
@@ -327,7 +325,7 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,
327325
struct netlink_ext_ack *extack)
328326
{
329327
const struct net_device_ops *ops = dev->netdev_ops;
330-
bool phy_ts = phy_has_hwtstamp(dev->phydev);
328+
bool phy_ts = phy_is_default_hwtstamp(dev->phydev);
331329
struct kernel_hwtstamp_config old_cfg = {};
332330
bool changed = false;
333331
int err;

net/core/timestamping.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
2525
struct sk_buff *clone;
2626
unsigned int type;
2727

28-
if (!skb->sk)
28+
if (!skb->sk || !skb->dev ||
29+
!phy_is_default_hwtstamp(skb->dev->phydev))
2930
return;
3031

3132
type = classify(skb);
@@ -47,7 +48,7 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
4748
struct mii_timestamper *mii_ts;
4849
unsigned int type;
4950

50-
if (!skb->dev || !skb->dev->phydev || !skb->dev->phydev->mii_ts)
51+
if (!skb->dev || !phy_is_default_hwtstamp(skb->dev->phydev))
5152
return false;
5253

5354
if (skb_headroom(skb) < ETH_HLEN)

net/ethtool/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
637637
memset(info, 0, sizeof(*info));
638638
info->cmd = ETHTOOL_GET_TS_INFO;
639639

640-
if (phy_has_tsinfo(phydev))
640+
if (phy_is_default_hwtstamp(phydev) && phy_has_tsinfo(phydev))
641641
return phy_ts_info(phydev, info);
642642
if (ops->get_ts_info)
643643
return ops->get_ts_info(dev, info);

0 commit comments

Comments
 (0)