Re: [PATCH v8 net-next 2/3] netdevsim: Implement basic ptp support
From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Date: 2026-08-12 20:35:25
On 12.08.2026 19:37, Maciek Machnikowski wrote:
Add support for virtual timestamping inside the netdevsim driver. The implementation uses two attached ptp_mock clocks, reads the timestamps of the ones attached either to the netdevsim or its peer and returns timestamps using standard timestamps APIs. This implementation enables running ptp4l on netdevsim adapters and introduces a new ptp selftest. Co-developed-by: Milena Olech <redacted> Signed-off-by: Milena Olech <redacted> Signed-off-by: Maciek Machnikowski <redacted>
[...]
+static int nsim_set_ts_config(struct net_device *netdev,
+ struct kernel_hwtstamp_config *config,
+ struct netlink_ext_ack *extack)
+{
+ struct netdevsim *ns = netdev_priv(netdev);
+ int rx_filter;
+
+ if (!ns->phc)
+ return -EOPNOTSUPP;
+
+ switch (config->tx_type) {
+ case HWTSTAMP_TX_OFF:
+ WRITE_ONCE(ns->tstamp_config.tx_type, HWTSTAMP_TX_OFF);
+ break;
+ case HWTSTAMP_TX_ON:
+ WRITE_ONCE(ns->tstamp_config.tx_type, HWTSTAMP_TX_ON);
+ break;
+ default:
+ return -ERANGE;
+ }
+
+ switch (config->rx_filter) {
+ case HWTSTAMP_FILTER_NONE:
+ rx_filter = HWTSTAMP_FILTER_NONE;
+ break;
+ case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
+ case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
+ case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
+ case HWTSTAMP_FILTER_PTP_V2_EVENT:
+ case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
+ case HWTSTAMP_FILTER_PTP_V2_SYNC:
+ case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
+ case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
+ case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
+ case HWTSTAMP_FILTER_NTP_ALL:
+ case HWTSTAMP_FILTER_ALL:
+ rx_filter = HWTSTAMP_FILTER_ALL;
+ break;
+ default:
+ return -ERANGE;
+ }nit: technically, you can make sashiko silent in this case by simply swapping switch statments order :) Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>