From nobody Fri Oct 10 13:44:19 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E750A14A09C for ; Sat, 14 Jun 2025 00:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749859696; cv=none; b=BkDjRjKKwaTlrmXYRbvWY7y+0lbFzgChzaI/J7vTLPi0XM7ghysStE4JmO3gTnFvvKIaLga9Qh0SdxuMzsjFbCUcpR0LCsrGRL7FgZaRDwljTd0u+qURfnMwlE/15BM0OpfXV8K0++Uk82HICxam2mgzwosp96TIGT5oN53HQ8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749859696; c=relaxed/simple; bh=EQK3/tVjNNDYeAyjzrgQfnPzAGBy80Ah+dNcW93p/UA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sPx4dyHq4WXUFTv3aSFEkKtvZvJFO71Rvu1MPnvMjoj6oGg9VS/HHudrVR+N5VBsXlRDW2TEunOkZ4INA4FWFSpcsnDy96ABOejxc5MWXdIkW+96bgi4gs6JlynPXWMz8FPQwc3Bmo+QGgxzJTvV0C1c2T9YDJYrDzJFREt9xLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--hramamurthy.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iOc+2UEa; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--hramamurthy.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iOc+2UEa" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-74890390d17so1224351b3a.2 for ; Fri, 13 Jun 2025 17:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749859694; x=1750464494; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RPr9VjvadtEs9339VHOUsV2V/j2hqIq22xXAScQhOxY=; b=iOc+2UEalydBG7ZorLuqtUlwxUBmWI8qv5gm6LHlQBoUibA6QGPXZRtl6ilnnPUoJk 5e0zI3AVKbQXG/xeLTroQ2c5cljY8WyYv8hfBemgd/wpaH0aTTpgxfSvwFywIJplaU4x 7/sce3PgjWKhoG6s8qwV+PyaakMlLMM0+vqCtC0tsfYo060DU/5F58v2RTFxfT5BpS5R AuwXoVP2ohqLmcrKT+Cw9uVIY3ulRGO06BP5Ny1NIrQdqE2VEH5eW6joYd57RvMP7zsH 1xTT3fsJhqBwYhhnvnReoYNia9kiCxawCfqfo/ZFaGpJ6xVVXWiszZ7LOh/I+OVmOzWw b1dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749859694; x=1750464494; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RPr9VjvadtEs9339VHOUsV2V/j2hqIq22xXAScQhOxY=; b=s4VcY3DULHbWTg9DLYZYNNc5jK+0+3zfHqrZzujLzkcKGMW4sBvXxQETLWfQK8rVUZ 98cuvsUTwkc/roq5KmIxtPjihlFBzrib+DBThvAfGbP2ALnkLQED3/hSY3RvAJa89PfJ t2HsO3Obd29+qgq0ZiXWBBiZQut7H4w1VE3EDOXVNgLIuhm2Ok6qFjPcrBBmtyNZk+uM /TX83q+ir5DIBMOkPCpcINatYipX1vE1ZW20PuAGX8g817qwujdDos+ViIewdH4DA1LJ gowFr+cJ2PfYrf4Em/VlIOnY3XIJhzPcT9RKAMjv+rHsG3gtK0+XqrzvHQzbkAPh+qCH 4PXg== X-Forwarded-Encrypted: i=1; AJvYcCWe8YjjC9u+/bkVmfXW7cJV6IXlV6EFgqtNWGQVShP6+++DtETGeMM+BYUBVlY6gXw68PVl6nwta5CS8os=@vger.kernel.org X-Gm-Message-State: AOJu0YzrpS/SP7cImwa+x/gPwPWOXRTe2T/lBFbNE/xWy0z/C/YPKoWv mdoEJ4w1XCT19xgCAd6oSYyiIk43x15RKIvrRFlnuR8EtTpVXeSA7ib77wQVQY7C3h2ugkbwTpp oJ1ck5Fs5EQ4iII3YYnHSXQmXJQ== X-Google-Smtp-Source: AGHT+IFetTlh5BYHg8AgVOPUCNwrqc5YM/rhO3Ou3VJ0DriTDP2fyYKqS3lEUw7KiUyXe+48P6WtswONb8fxOViL4w== X-Received: from pfee1.prod.google.com ([2002:a05:6a00:bc81:b0:746:25af:51c4]) (user=hramamurthy job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:244f:b0:746:2591:e531 with SMTP id d2e1a72fcca58-7489cfffc62mr1523220b3a.12.1749859694394; Fri, 13 Jun 2025 17:08:14 -0700 (PDT) Date: Sat, 14 Jun 2025 00:07:53 +0000 In-Reply-To: <20250614000754.164827-1-hramamurthy@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250614000754.164827-1-hramamurthy@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250614000754.164827-8-hramamurthy@google.com> Subject: [PATCH net-next v5 7/8] gve: Implement ndo_hwtstamp_get/set for RX timestamping From: Harshitha Ramamurthy To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jeroendb@google.com, hramamurthy@google.com, andrew+netdev@lunn.ch, willemb@google.com, ziweixiao@google.com, pkaligineedi@google.com, yyd@google.com, joshwash@google.com, shailend@google.com, linux@treblig.org, thostet@google.com, jfraker@google.com, richardcochran@gmail.com, jdamato@fastly.com, vadim.fedorenko@linux.dev, horms@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: John Fraker Implement ndo_hwtstamp_get/set to enable hardware RX timestamping, providing support for SIOC[SG]HWTSTAMP IOCTLs. Included with this support is the small change necessary to read the rx timestamp out of the rx descriptor, now that timestamps start being enabled. The gve clock is only used for hardware timestamps, so started when timestamps are requested and stopped when not needed. This version only supports RX hardware timestamping with the rx filter HWTSTAMP_FILTER_ALL. If the user attempts to configure a more restrictive filter, the filter will be set to HWTSTAMP_FILTER_ALL in the returned structure. Signed-off-by: John Fraker Signed-off-by: Ziwei Xiao Reviewed-by: Willem de Bruijn Signed-off-by: Harshitha Ramamurthy --- Changes in v5: - Utilize ptp_cancel_worker_sync instead of unregistering the PHC every time when rx timestamping is disabled. (Jakub Kicinski) - Add gve_clock_nic_ts_read before the ptp_schedule_worker to do the first refresh. (Jakub Kicinski) Changes in v3: - Update the title and commit message to show it's adding support for ndo functions instead of ioctls (Jakub Kicinski) - Utilize extack for error logging instead of dev_err (Jakub Kicinski) --- drivers/net/ethernet/google/gve/gve.h | 2 + .../net/ethernet/google/gve/gve_desc_dqo.h | 3 +- drivers/net/ethernet/google/gve/gve_main.c | 46 +++++++++++++++++++ drivers/net/ethernet/google/gve/gve_rx_dqo.c | 5 +- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/g= oogle/gve/gve.h index 527e17da60bc..be4b5791c245 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -882,6 +883,7 @@ struct gve_priv { /* True if the device supports reading the nic clock */ bool nic_timestamp_supported; struct gve_ptp *ptp; + struct kernel_hwtstamp_config ts_config; struct gve_nic_ts_report *nic_ts_report; dma_addr_t nic_ts_report_bus; u64 last_sync_nic_counter; /* Clock counter from last NIC TS report */ diff --git a/drivers/net/ethernet/google/gve/gve_desc_dqo.h b/drivers/net/e= thernet/google/gve/gve_desc_dqo.h index f79cd0591110..d17da841b5a0 100644 --- a/drivers/net/ethernet/google/gve/gve_desc_dqo.h +++ b/drivers/net/ethernet/google/gve/gve_desc_dqo.h @@ -247,7 +247,8 @@ struct gve_rx_compl_desc_dqo { }; __le32 hash; __le32 reserved6; - __le64 reserved7; + __le32 reserved7; + __le32 ts; /* timestamp in nanosecs */ } __packed; =20 static_assert(sizeof(struct gve_rx_compl_desc_dqo) =3D=3D 32); diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ether= net/google/gve/gve_main.c index bc2f36962ee8..7fff1409b121 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -727,6 +727,7 @@ static void gve_teardown_device_resources(struct gve_pr= iv *priv) gve_free_counter_array(priv); gve_free_notify_blocks(priv); gve_free_stats_report(priv); + gve_teardown_clock(priv); gve_clear_device_resources_ok(priv); } =20 @@ -2047,6 +2048,46 @@ static int gve_set_features(struct net_device *netde= v, return err; } =20 +static int gve_get_ts_config(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_config) +{ + struct gve_priv *priv =3D netdev_priv(dev); + + *kernel_config =3D priv->ts_config; + return 0; +} + +static int gve_set_ts_config(struct net_device *dev, + struct kernel_hwtstamp_config *kernel_config, + struct netlink_ext_ack *extack) +{ + struct gve_priv *priv =3D netdev_priv(dev); + + if (kernel_config->tx_type !=3D HWTSTAMP_TX_OFF) { + NL_SET_ERR_MSG_MOD(extack, "TX timestamping is not supported"); + return -ERANGE; + } + + if (kernel_config->rx_filter !=3D HWTSTAMP_FILTER_NONE) { + if (!priv->nic_ts_report) { + NL_SET_ERR_MSG_MOD(extack, + "RX timestamping is not supported"); + kernel_config->rx_filter =3D HWTSTAMP_FILTER_NONE; + return -EOPNOTSUPP; + } + + kernel_config->rx_filter =3D HWTSTAMP_FILTER_ALL; + gve_clock_nic_ts_read(priv); + ptp_schedule_worker(priv->ptp->clock, 0); + } else { + ptp_cancel_worker_sync(priv->ptp->clock); + } + + priv->ts_config.rx_filter =3D kernel_config->rx_filter; + + return 0; +} + static const struct net_device_ops gve_netdev_ops =3D { .ndo_start_xmit =3D gve_start_xmit, .ndo_features_check =3D gve_features_check, @@ -2058,6 +2099,8 @@ static const struct net_device_ops gve_netdev_ops =3D= { .ndo_bpf =3D gve_xdp, .ndo_xdp_xmit =3D gve_xdp_xmit, .ndo_xsk_wakeup =3D gve_xsk_wakeup, + .ndo_hwtstamp_get =3D gve_get_ts_config, + .ndo_hwtstamp_set =3D gve_set_ts_config, }; =20 static void gve_handle_status(struct gve_priv *priv, u32 status) @@ -2277,6 +2320,9 @@ static int gve_init_priv(struct gve_priv *priv, bool = skip_describe_device) priv->rx_coalesce_usecs =3D GVE_RX_IRQ_RATELIMIT_US_DQO; } =20 + priv->ts_config.tx_type =3D HWTSTAMP_TX_OFF; + priv->ts_config.rx_filter =3D HWTSTAMP_FILTER_NONE; + setup_device: gve_set_netdev_xdp_features(priv); err =3D gve_setup_device_resources(priv); diff --git a/drivers/net/ethernet/google/gve/gve_rx_dqo.c b/drivers/net/eth= ernet/google/gve/gve_rx_dqo.c index 9aadf8435f8b..0be41a0cdd15 100644 --- a/drivers/net/ethernet/google/gve/gve_rx_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_rx_dqo.c @@ -450,7 +450,7 @@ static void gve_rx_skb_hash(struct sk_buff *skb, * Note that this means if the time delta between packet reception and the= last * clock read is greater than ~2 seconds, this will provide invalid result= s. */ -static void __maybe_unused gve_rx_skb_hwtstamp(struct gve_rx_ring *rx, u32= hwts) +static void gve_rx_skb_hwtstamp(struct gve_rx_ring *rx, u32 hwts) { u64 last_read =3D READ_ONCE(rx->gve->last_sync_nic_counter); struct sk_buff *skb =3D rx->ctx.skb_head; @@ -790,6 +790,9 @@ static int gve_rx_complete_skb(struct gve_rx_ring *rx, = struct napi_struct *napi, if (feat & NETIF_F_RXCSUM) gve_rx_skb_csum(rx->ctx.skb_head, desc, ptype); =20 + if (rx->gve->ts_config.rx_filter =3D=3D HWTSTAMP_FILTER_ALL) + gve_rx_skb_hwtstamp(rx, le32_to_cpu(desc->ts)); + /* RSC packets must set gso_size otherwise the TCP stack will complain * that packets are larger than MTU. */ --=20 2.50.0.rc1.591.g9c95f17f64-goog