>
>> When both mac and phy support ptp timestamp, and the user has not
>> selected a provider(dev->hwprov is NULL), the core uses the mac.
>
>We try to keep policy out of the kernel. It is policy to decide which stamper to
>use, so it should be userspace which decides and sets
>dev->hwprov. This is however a new feature, so we need to ensure it
>does not cause regressions with older code. So that is what this
>phy_is_default_hwtstamp() is about. The Marvell stampers have been around
>a while.
>
>Since yours is a new device, you should be using dev->hwprov. I guess it is a
>reasonably simple patch to ptp4l.
Hi Andrew,
When I tried this on RTL8127A, I found that the provider cannot be selected at all. r8169 has no ndo_hwtstamp_set(), so after dropping default_timestamp the netdev has no active time stamping source, and TSCONFIG_SET fails:
sudo tools/net/ynl/pyynl/cli.py \
--spec Documentation/netlink/specs/ethtool.yaml --do tsconfig-set \
--json '{"header":{"dev-name":"enp2s0"},"hwtstamp-provider":{"index":0,"qualifier":0}}'
There are two places in ethnl_set_tsconfig() that block it:
1. The entry check returns -EOPNOTSUPP before the provider attribute is even parsed, since there is no ndo_hwtstamp_set(), no default PHY and no hwprov yet.
2. Before switching the provider, the current source is disabled with a zero config through dev_set_hwtstamp_phylib(). With no hwprov and no default PHY it goes to the MAC path and returns -EOPNOTSUPP, as there is nothing to disable.
With the change below, the request is only let through when a provider is given.
net/ethtool/tsconfig.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/net/ethtool/tsconfig.c b/net/ethtool/tsconfig.c
index 2db0e7ba8b9f..9c983666a1b0 100644
--- a/net/ethtool/tsconfig.c
+++ b/net/ethtool/tsconfig.c
@@ -300,14 +300,16 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
struct hwtstamp_provider *hwprov = NULL;
struct net_device *dev = req_base->dev;
struct nlattr **tb = info->attrs;
+ bool has_hwts;
int ret;
if (!netif_device_present(dev))
return -ENODEV;
- if (!dev->netdev_ops->ndo_hwtstamp_set &&
- !phy_is_default_hwtstamp(dev->phydev) &&
- !netdev_ops_lock_dereference(dev->hwprov, dev))
+ has_hwts = dev->netdev_ops->ndo_hwtstamp_set ||
+ phy_is_default_hwtstamp(dev->phydev) ||
+ netdev_ops_lock_dereference(dev->hwprov, dev);
+ if (!has_hwts && !tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER])
return -EOPNOTSUPP;
if (tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER]) {
@@ -411,9 +413,12 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
/* Disable current time stamping if we try to enable
* another one
*/
- ret = dev_set_hwtstamp_phylib(dev, &zero_config, info->extack);
- if (ret < 0)
- goto err_free_hwprov;
+ if (has_hwts) {
+ ret = dev_set_hwtstamp_phylib(dev, &zero_config,
+ info->extack);
+ if (ret < 0)
+ goto err_free_hwprov;
+ }
/* Change the selected hwtstamp source */
__hwprov = rcu_replace_pointer(dev->hwprov, hwprov,
Is this the right way to fix it? If so, I will add it as the first patch of v5.
Looking forward to your advice.
Thanks,
Javen
>
> Andrew