Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1310517rbb; Mon, 26 Feb 2024 05:42:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWk7dz5/opL2tOwYbdsFACC/SVr5maqzUn/s0m4cmy8IfzDmrwE+bIVy/+PWbZuavAKakiUemACjTsUXy8qmT3roymhds/nuo/jYuoqKQ== X-Google-Smtp-Source: AGHT+IFrsZTp5fuoGDELjWmI3njt+tQHT2I6e64frXLddzyeI0+GQgu9YaeovjM7gYXqRoq9uwdW X-Received: by 2002:a05:6358:b3c8:b0:17b:583c:c4b7 with SMTP id pb8-20020a056358b3c800b0017b583cc4b7mr10074757rwc.3.1708954965630; Mon, 26 Feb 2024 05:42:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708954965; cv=pass; d=google.com; s=arc-20160816; b=oa2yS26abvhZVk751Lx3AmxfZICJA59D4wfWPLvn8AXvUcwRBgpvCY2cPZkpGtMLCa HtDeP6nh6W3c+H2uIjKWlTjcIUaVVtsFiISnLeHGktiRurGDBj1sTYFWryUa7dC0n+Di cD9LJgKmSZz9L3zkEzn50QNXwWaUJcpmjUac5+JvTZ5jaa6JdKiVlGtjmklAbXI6UGfK iFPgwtNiSsW09Spce94HCqjWCIeiS/DEDaY+4/JX4a/rUanBdFj/+8Relozj9Tv9/W25 eieLqkDeyqgGR73gTzmv+1RpiUW6aZbyzvkLmW6E2Qq+tP0gogb6iD6/YdHpRN/jyxnA 2flQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=oYfxTVQWmBuJF4lBsfx9UPY0Q4bZNXUuXVcIdMJTjIQ=; fh=vtlcgQ30nO0QjQR7y1Wfn7g9c11A+T6SWcSZ6WixcJI=; b=ON5PDBI1aGRGQmgA4sKxuRq+DtD7GtSeaGpm/iSKl9m+n9QLYg9eHx/F6j15S1KTar wp+qR07lcObeFHGYDLhiGLmg0+kU9Jt+9yZHsoLPRfedEcoQPr7/HZTzgzSeDqIJB/2U TsV8btMgT2MDvrh07N3WYFhbUOSPgcuflfhqJ/hPSzVs7pn4IkMNCfCEQzMsIJyBQaVR bw6kQjY0O+yuml10S8lidvwdEeXTbbfd8nt9xXc8+WLW9M1EKyvBxoMv5Hi0vQ13jC+z Z4dfRir56DyRftJsTXwylCdNWxikabXenM9TxKXMcIPv1Y8yTYeeUhZthF6bSTn3mfaD Ph2Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dWkl9a0E; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-81510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t14-20020a63f34e000000b005e3cdc24c26si3774126pgj.467.2024.02.26.05.42.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 05:42:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dWkl9a0E; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-81510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 407262891C3 for ; Mon, 26 Feb 2024 13:42:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C25012C7F0; Mon, 26 Feb 2024 13:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="dWkl9a0E" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBF1712BF1E; Mon, 26 Feb 2024 13:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708954827; cv=none; b=upXK9g14eTHWho4Uj0lTB2bK0ghjw1MEA2oKZnb0s6LJlfqA51xbLcMu9dRXd62ppVqrIyU7c3gRatdKNcq3boCTZG+N+GoyrB0ZmC5oAwVf8MN8P0YyqLT9njvUT2c6fVRjlnYEUnOE6uB53QinVOGyyKBN/1dCvli0kanWfuo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708954827; c=relaxed/simple; bh=kmIAbQWGiqY+Esp6e4HG+4T6WE1cOrUZMnGMSs1qujA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TUGdWNSBRbZgbREJ/YKhQ11t94GSiUKQO7De6KodRUZO/uS0ztvdZwHetI1b5CCA1olcnS0KLCV2UFAnuTFlfBUBr0oHEu+gBXHJtjct0SbfeRjd33b1T0Xpfkf2qyTPMklfW3RpkWoLM4GdAkqDl+mLWw7yrVOBOIetIXO+8YE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=dWkl9a0E; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 0F9D540013; Mon, 26 Feb 2024 13:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708954823; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oYfxTVQWmBuJF4lBsfx9UPY0Q4bZNXUuXVcIdMJTjIQ=; b=dWkl9a0EUbaxd4z5UcEvFMuaCWHCgRuD9eKdy9ZzmXbohVaSgakm9YylmiuK9Gj7znKJ/f g8OxICrmiEO/M37eZrtkHPvTTU90FCXkcoZ3cZuvejcVjf1KK9IPzuO/FtNjqYbjGlMi1L HBzcgnHqtkSlUr8fD8b3pMv0RzkCE4mgegyP8K6Nj4zPVwAhXtZ5MxITCZm1do+mBc7QAI 69VajbqEuCu0BMfJc9wqeQ6ZcB3v6uFHH5LEWASPoDI5jA00JYdxLfEt1cHvMb0yAQn+zd C7RtLfMbHP4yikz8Vy6d4mK68SbD2t+b3KofA5JDOfkzH5FVKTSpFBaZ/Bh/zg== From: Kory Maincent Date: Mon, 26 Feb 2024 14:40:00 +0100 Subject: [PATCH net-next v9 09/13] net: Add the possibility to support a selected hwtstamp in netdevice Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240226-feature_ptp_netnext-v9-9-455611549f21@bootlin.com> References: <20240226-feature_ptp_netnext-v9-0-455611549f21@bootlin.com> In-Reply-To: <20240226-feature_ptp_netnext-v9-0-455611549f21@bootlin.com> To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Radu Pirea , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Willem de Bruijn , Jonathan Corbet , Horatiu Vultur , UNGLinuxDriver@microchip.com, Simon Horman , Vladimir Oltean Cc: Thomas Petazzoni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Maxime Chevallier , Rahul Rameshbabu , Kory Maincent X-Mailer: b4 0.12.4 X-GND-Sasl: kory.maincent@bootlin.com Introduce the description of a hwtstamp provider which is define with a ptp_clock pointer and a qualifier value. Add a hwtstamp provider description within the netdev structure to be able to select the hwtstamp we want too use. By default we use the old API that does not support hwtstamp selectability which mean the hwtstamp ptp_clock pointer is unset. Signed-off-by: Kory Maincent --- Change in v8: - New patch --- drivers/net/phy/phy_device.c | 7 +++++++ include/linux/net_tstamp.h | 6 ++++++ include/linux/netdevice.h | 5 +++++ include/uapi/linux/net_tstamp.h | 11 +++++++++++ net/core/dev_ioctl.c | 39 +++++++++++++++++++++++++++++++++++++-- net/core/timestamping.c | 37 ++++++++++++++++++++++++++++++++----- 6 files changed, 98 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2eefee970851..2532843e3c13 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1936,6 +1937,12 @@ void phy_detach(struct phy_device *phydev) phy_suspend(phydev); if (dev) { + /* Disable timestamp if selected */ + if (ptp_clock_phydev(dev->hwtstamp.ptp) == phydev) { + dev->hwtstamp.ptp = NULL; + dev->hwtstamp.qualifier = HWTSTAMP_PROVIDER_QUALIFIER_PRECISE; + } + phydev->attached_dev->phydev = NULL; phydev->attached_dev = NULL; } diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index 662074b08c94..263dfcf12000 100644 --- a/include/linux/net_tstamp.h +++ b/include/linux/net_tstamp.h @@ -19,6 +19,11 @@ enum hwtstamp_source { HWTSTAMP_SOURCE_PHYLIB, }; +struct hwtstamp_provider { + struct ptp_clock *ptp; + enum hwtstamp_provider_qualifier qualifier; +}; + /** * struct kernel_hwtstamp_config - Kernel copy of struct hwtstamp_config * @@ -43,6 +48,7 @@ struct kernel_hwtstamp_config { struct ifreq *ifr; bool copied_to_user; enum hwtstamp_source source; + enum hwtstamp_provider_qualifier qualifier; }; static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg, diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index b67727c0dc58..43e3050a99af 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -2107,6 +2108,8 @@ enum netdev_reg_state { * @dpll_pin: Pointer to the SyncE source pin of a DPLL subsystem, * where the clock is recovered. * + * @hwtstamp: Tracks which PTP performs hardware packet time stamping. + * * FIXME: cleanup struct net_device such that network protocol info * moves out. */ @@ -2478,6 +2481,8 @@ struct net_device { /** @page_pools: page pools created for this netdevice */ struct hlist_head page_pools; #endif + + struct hwtstamp_provider hwtstamp; }; #define to_net_dev(d) container_of(d, struct net_device, dev) diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h index a2c66b3d7f0f..a9ed48ee8fc7 100644 --- a/include/uapi/linux/net_tstamp.h +++ b/include/uapi/linux/net_tstamp.h @@ -13,6 +13,17 @@ #include #include /* for SO_TIMESTAMPING */ +/* + * Possible type of htstamp provider. Mainly "precise" the default one + * is for IEEE 1588 quality and "approx" is for NICs DMA point. + */ +enum hwtstamp_provider_qualifier { + HWTSTAMP_PROVIDER_QUALIFIER_PRECISE, + HWTSTAMP_PROVIDER_QUALIFIER_APPROX, + + HWTSTAMP_PROVIDER_QUALIFIER_CNT, +}; + /* SO_TIMESTAMPING flags */ enum { SOF_TIMESTAMPING_TX_HARDWARE = (1<<0), diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 3342834597cd..cd093c2aad67 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -270,6 +271,20 @@ static int dev_eth_ioctl(struct net_device *dev, int dev_get_hwtstamp_phylib(struct net_device *dev, struct kernel_hwtstamp_config *cfg) { + cfg->qualifier = dev->hwtstamp.qualifier; + + if (dev->hwtstamp.ptp) { + struct ptp_clock *ptp = dev->hwtstamp.ptp; + + if (ptp_clock_from_phylib(ptp)) + return phy_hwtstamp_get(ptp_clock_phydev(ptp), cfg); + + if (ptp_clock_from_netdev(ptp)) + return dev->netdev_ops->ndo_hwtstamp_get(dev, cfg); + + return -EOPNOTSUPP; + } + if (phy_is_default_hwtstamp(dev->phydev)) return phy_hwtstamp_get(dev->phydev, cfg); @@ -327,11 +342,31 @@ int dev_set_hwtstamp_phylib(struct net_device *dev, struct netlink_ext_ack *extack) { const struct net_device_ops *ops = dev->netdev_ops; - bool phy_ts = phy_is_default_hwtstamp(dev->phydev); struct kernel_hwtstamp_config old_cfg = {}; + struct phy_device *phydev; bool changed = false; + bool phy_ts; int err; + cfg->qualifier = dev->hwtstamp.qualifier; + + if (dev->hwtstamp.ptp) { + struct ptp_clock *ptp = dev->hwtstamp.ptp; + + if (ptp_clock_from_phylib(ptp)) { + phy_ts = true; + phydev = ptp_clock_phydev(ptp); + } else if (ptp_clock_from_netdev(ptp)) { + phy_ts = false; + } else { + return -EOPNOTSUPP; + } + } else { + phy_ts = phy_is_default_hwtstamp(dev->phydev); + if (phy_ts) + phydev = dev->phydev; + } + cfg->source = phy_ts ? HWTSTAMP_SOURCE_PHYLIB : HWTSTAMP_SOURCE_NETDEV; if (phy_ts && (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) { @@ -353,7 +388,7 @@ int dev_set_hwtstamp_phylib(struct net_device *dev, changed = kernel_hwtstamp_config_changed(&old_cfg, cfg); if (phy_ts) { - err = phy_hwtstamp_set(dev->phydev, cfg, extack); + err = phy_hwtstamp_set(phydev, cfg, extack); if (err) { if (changed) ops->ndo_hwtstamp_set(dev, &old_cfg, NULL); diff --git a/net/core/timestamping.c b/net/core/timestamping.c index 3717fb152ecc..a7b256ac3490 100644 --- a/net/core/timestamping.c +++ b/net/core/timestamping.c @@ -9,6 +9,7 @@ #include #include #include +#include static unsigned int classify(const struct sk_buff *skb) { @@ -22,18 +23,31 @@ static unsigned int classify(const struct sk_buff *skb) void skb_clone_tx_timestamp(struct sk_buff *skb) { struct mii_timestamper *mii_ts; + struct phy_device *phydev; struct sk_buff *clone; unsigned int type; - if (!skb->sk || !skb->dev || - !phy_is_default_hwtstamp(skb->dev->phydev)) + if (!skb->sk || !skb->dev) return; + if (skb->dev->hwtstamp.ptp) { + if (!ptp_clock_from_phylib(skb->dev->hwtstamp.ptp)) + return; + + phydev = ptp_clock_phydev(skb->dev->hwtstamp.ptp); + + } else { + if (!phy_is_default_hwtstamp(phydev)) + return; + + phydev = skb->dev->phydev; + } + type = classify(skb); if (type == PTP_CLASS_NONE) return; - mii_ts = skb->dev->phydev->mii_ts; + mii_ts = phydev->mii_ts; if (likely(mii_ts->txtstamp)) { clone = skb_clone_sk(skb); if (!clone) @@ -46,11 +60,24 @@ EXPORT_SYMBOL_GPL(skb_clone_tx_timestamp); bool skb_defer_rx_timestamp(struct sk_buff *skb) { struct mii_timestamper *mii_ts; + struct phy_device *phydev; unsigned int type; - if (!skb->dev || !phy_is_default_hwtstamp(skb->dev->phydev)) + if (!skb->dev) return false; + if (skb->dev->hwtstamp.ptp) { + if (!ptp_clock_from_phylib(skb->dev->hwtstamp.ptp)) + return false; + + phydev = ptp_clock_phydev(skb->dev->hwtstamp.ptp); + } else { + if (!phy_is_default_hwtstamp(phydev)) + return false; + + phydev = skb->dev->phydev; + } + if (skb_headroom(skb) < ETH_HLEN) return false; @@ -63,7 +90,7 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb) if (type == PTP_CLASS_NONE) return false; - mii_ts = skb->dev->phydev->mii_ts; + mii_ts = phydev->mii_ts; if (likely(mii_ts->rxtstamp)) return mii_ts->rxtstamp(mii_ts, skb, type); -- 2.25.1