From patchwork Mon Oct 9 15:51:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150176 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961356vqo; Mon, 9 Oct 2023 08:52:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrz2mw6hOwg5RBKZ2d1YFFiYeM+rAqUeI7IOSPMz7kdQAUHtARDfdla1uc/lhU2/M15FZm X-Received: by 2002:a05:6e02:c62:b0:34b:aef9:60d4 with SMTP id f2-20020a056e020c6200b0034baef960d4mr14479760ilj.27.1696866748687; Mon, 09 Oct 2023 08:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866748; cv=none; d=google.com; s=arc-20160816; b=FHX+CUNxLY77zAH2vOEoJ4gCWF4prTM91+PvTT1Ab4KqLeApp2cO2TjjOpp4MGwEQa PbId5cT2JuT5RltEvc77lRJb3wpZ0KOtrfdfjuiGrMzKaz3v1j8/GT8QQjfpCOPCw6ly qu6wJTlHk1zeKQLF7eFy81OBMYoNDUu+34SZ6trMzadgs73d7aCeNoOC12RBvy5VGL1J 6lI57E/EokuaN40gTM6gw1Dg1KLXupepjD96Z8N1Qg3KWNIF8g2cjuPjSAd5/qs8azth imi/soaGXYdNcYQWPmQlCpJ7EUzSVJ0/SS5jhFKjL4dQqLPyM5wNOS6WerVqHrciCFlg m4AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vpY52aoAJ1rGO5AYwVlLY3pMqzhMipg00/2biw96jaA=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=TdWQdkAT8Z/rQ8X0EYQg2DfaT3zILrPx5MjMYDcfgUrYUDj6N0Rg5/7euvUgdQnNUp 18Jb6of+l/Kziqin7Og7YdmDhuXUeNwPj7KjsnjrI2oHBET89lzyxYzD3HRSjJw3V+DN jzDX7/O/gq7Bj31J+bK6q/0fUI1Hx3LSQzE9GtvYF9974YtKT1l+XAMKDIOMC8vkw4v1 AFmSaQWQD7LGohihryLSz2JDMF/tKORx+ahf0YjLZdPpx9bEMH/K0x5ZLRYA6jE2xDYC /DeNeCw/ZzJvgHFye8r3VGVyDKmO+u4onBDQKMIxSed13Uf1E77LNDHmi1npldQq+0Xl mTxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Q8NQgsiq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id w8-20020a63f508000000b00563d791d978si9880727pgh.750.2023.10.09.08.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:52:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Q8NQgsiq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1AC568111390; Mon, 9 Oct 2023 08:52:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377086AbjJIPv4 (ORCPT + 18 others); Mon, 9 Oct 2023 11:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377077AbjJIPvw (ORCPT ); Mon, 9 Oct 2023 11:51:52 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE738E9; Mon, 9 Oct 2023 08:51:49 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 2C27D1C0002; Mon, 9 Oct 2023 15:51:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vpY52aoAJ1rGO5AYwVlLY3pMqzhMipg00/2biw96jaA=; b=Q8NQgsiqpQSAfgkbjfquayNL3gjI7h+THkLcvVxGB6LKFVOyMByAeV9E1DTan4N6lPgTS4 g5/5jAidCYwh8kgkbaffuJ5wxMNbsIYlacAoC1m+SF7WVPwd/VRIGbPgFqIGU5aWECxN4w MGKc7q3CS4nZIY3vHvpqsCrx0k5uZKPiVxn4ntY59nADy9p9OfnYkNBZ8QnA1RBeyhWOZx MB58BtN+zvpjH1w02GuEWD9vOcWXqgqHhfMUKEvBzllXNa027onZtuM0Rmg9uxJxRqbqLE HSciAsx2xJYCW/v4+ehMHlYtcCiVFAtzsH6uWx7UKzz932uACPVaiwEyEAXsCw== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 01/16] net: Convert PHYs hwtstamp callback to use kernel_hwtstamp_config Date: Mon, 9 Oct 2023 17:51:23 +0200 Message-Id: <20231009155138.86458-2-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:52:22 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293748077472068 X-GMAIL-MSGID: 1779293748077472068 From: Kory Maincent The PHYs hwtstamp callback are still getting the timestamp config from ifreq and using copy_from/to_user. Get rid of these functions by using timestamp configuration in parameter. This also allow to move on to kernel_hwtstamp_config and be similar to net devices using the new ndo_hwstamp_get/set. This adds the possibility to manipulate the timestamp configuration from the kernel which was not possible with the copy_from/to_user. Signed-off-by: Kory Maincent Reviewed-by: Florian Fainelli --- drivers/net/phy/bcm-phy-ptp.c | 15 +++++------- drivers/net/phy/dp83640.c | 24 +++++++++---------- drivers/net/phy/micrel.c | 38 ++++++++++++++----------------- drivers/net/phy/mscc/mscc_ptp.c | 18 +++++++-------- drivers/net/phy/nxp-c45-tja11xx.c | 17 ++++++-------- drivers/net/phy/phy.c | 21 +++++++++++++++-- drivers/ptp/ptp_ines.c | 16 ++++++------- include/linux/mii_timestamper.h | 4 +++- include/linux/phy.h | 6 +++-- 9 files changed, 82 insertions(+), 77 deletions(-) diff --git a/drivers/net/phy/bcm-phy-ptp.c b/drivers/net/phy/bcm-phy-ptp.c index ef00d6163061..0beae8f81ffa 100644 --- a/drivers/net/phy/bcm-phy-ptp.c +++ b/drivers/net/phy/bcm-phy-ptp.c @@ -782,16 +782,13 @@ static void bcm_ptp_txtstamp(struct mii_timestamper *mii_ts, } static int bcm_ptp_hwtstamp(struct mii_timestamper *mii_ts, - struct ifreq *ifr) + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { struct bcm_ptp_private *priv = mii2priv(mii_ts); - struct hwtstamp_config cfg; u16 mode, ctrl; - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - switch (cfg.rx_filter) { + switch (cfg->rx_filter) { case HWTSTAMP_FILTER_NONE: priv->hwts_rx = false; break; @@ -804,14 +801,14 @@ static int bcm_ptp_hwtstamp(struct mii_timestamper *mii_ts, case HWTSTAMP_FILTER_PTP_V2_EVENT: case HWTSTAMP_FILTER_PTP_V2_SYNC: case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; priv->hwts_rx = true; break; default: return -ERANGE; } - priv->tx_type = cfg.tx_type; + priv->tx_type = cfg->tx_type; ctrl = priv->hwts_rx ? SLICE_RX_EN : 0; ctrl |= priv->tx_type != HWTSTAMP_TX_OFF ? SLICE_TX_EN : 0; @@ -840,7 +837,7 @@ static int bcm_ptp_hwtstamp(struct mii_timestamper *mii_ts, /* purge existing data */ skb_queue_purge(&priv->tx_queue); - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; + return 0; } static int bcm_ptp_ts_info(struct mii_timestamper *mii_ts, diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c index 2657be7cc049..5c42c47dc564 100644 --- a/drivers/net/phy/dp83640.c +++ b/drivers/net/phy/dp83640.c @@ -1207,22 +1207,20 @@ static irqreturn_t dp83640_handle_interrupt(struct phy_device *phydev) return IRQ_HANDLED; } -static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) +static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { struct dp83640_private *dp83640 = container_of(mii_ts, struct dp83640_private, mii_ts); - struct hwtstamp_config cfg; u16 txcfg0, rxcfg0; - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - if (cfg.tx_type < 0 || cfg.tx_type > HWTSTAMP_TX_ONESTEP_SYNC) + if (cfg->tx_type < 0 || cfg->tx_type > HWTSTAMP_TX_ONESTEP_SYNC) return -ERANGE; - dp83640->hwts_tx_en = cfg.tx_type; + dp83640->hwts_tx_en = cfg->tx_type; - switch (cfg.rx_filter) { + switch (cfg->rx_filter) { case HWTSTAMP_FILTER_NONE: dp83640->hwts_rx_en = 0; dp83640->layer = 0; @@ -1234,7 +1232,7 @@ static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) dp83640->hwts_rx_en = 1; dp83640->layer = PTP_CLASS_L4; dp83640->version = PTP_CLASS_V1; - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; break; case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: @@ -1242,7 +1240,7 @@ static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) dp83640->hwts_rx_en = 1; dp83640->layer = PTP_CLASS_L4; dp83640->version = PTP_CLASS_V2; - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; break; case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: @@ -1250,7 +1248,7 @@ static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) dp83640->hwts_rx_en = 1; dp83640->layer = PTP_CLASS_L2; dp83640->version = PTP_CLASS_V2; - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; break; case HWTSTAMP_FILTER_PTP_V2_EVENT: case HWTSTAMP_FILTER_PTP_V2_SYNC: @@ -1258,7 +1256,7 @@ static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) dp83640->hwts_rx_en = 1; dp83640->layer = PTP_CLASS_L4 | PTP_CLASS_L2; dp83640->version = PTP_CLASS_V2; - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; break; default: return -ERANGE; @@ -1292,7 +1290,7 @@ static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) mutex_unlock(&dp83640->clock->extreg_lock); - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; + return 0; } static void rx_timestamp_work(struct work_struct *work) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 927d3d54658e..43d072b53839 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -2373,24 +2373,22 @@ static void lan8814_flush_fifo(struct phy_device *phydev, bool egress) lanphy_read_page_reg(phydev, 5, PTP_TSU_INT_STS); } -static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) +static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) { struct kszphy_ptp_priv *ptp_priv = container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); struct phy_device *phydev = ptp_priv->phydev; struct lan8814_shared_priv *shared = phydev->shared->priv; struct lan8814_ptp_rx_ts *rx_ts, *tmp; - struct hwtstamp_config config; int txcfg = 0, rxcfg = 0; int pkt_ts_enable; - if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) - return -EFAULT; + ptp_priv->hwts_tx_type = config->tx_type; + ptp_priv->rx_filter = config->rx_filter; - ptp_priv->hwts_tx_type = config.tx_type; - ptp_priv->rx_filter = config.rx_filter; - - switch (config.rx_filter) { + switch (config->rx_filter) { case HWTSTAMP_FILTER_NONE: ptp_priv->layer = 0; ptp_priv->version = 0; @@ -2436,13 +2434,13 @@ static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_MOD, PTP_TX_MOD_TX_PTP_SYNC_TS_INSERT_); - if (config.rx_filter != HWTSTAMP_FILTER_NONE) + if (config->rx_filter != HWTSTAMP_FILTER_NONE) lan8814_config_ts_intr(ptp_priv->phydev, true); else lan8814_config_ts_intr(ptp_priv->phydev, false); mutex_lock(&shared->shared_lock); - if (config.rx_filter != HWTSTAMP_FILTER_NONE) + if (config->rx_filter != HWTSTAMP_FILTER_NONE) shared->ref++; else shared->ref--; @@ -2466,7 +2464,7 @@ static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) lan8814_flush_fifo(ptp_priv->phydev, false); lan8814_flush_fifo(ptp_priv->phydev, true); - return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : 0; + return 0; } static void lan8814_txtstamp(struct mii_timestamper *mii_ts, @@ -3681,21 +3679,19 @@ static void lan8841_ptp_enable_processing(struct kszphy_ptp_priv *ptp_priv, #define LAN8841_PTP_TX_TIMESTAMP_EN 443 #define LAN8841_PTP_TX_MOD 445 -static int lan8841_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) +static int lan8841_hwtstamp(struct mii_timestamper *mii_ts, + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) { struct kszphy_ptp_priv *ptp_priv = container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); struct phy_device *phydev = ptp_priv->phydev; - struct hwtstamp_config config; int txcfg = 0, rxcfg = 0; int pkt_ts_enable; - if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) - return -EFAULT; + ptp_priv->hwts_tx_type = config->tx_type; + ptp_priv->rx_filter = config->rx_filter; - ptp_priv->hwts_tx_type = config.tx_type; - ptp_priv->rx_filter = config.rx_filter; - - switch (config.rx_filter) { + switch (config->rx_filter) { case HWTSTAMP_FILTER_NONE: ptp_priv->layer = 0; ptp_priv->version = 0; @@ -3749,13 +3745,13 @@ static int lan8841_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) /* Now enable/disable the timestamping */ lan8841_ptp_enable_processing(ptp_priv, - config.rx_filter != HWTSTAMP_FILTER_NONE); + config->rx_filter != HWTSTAMP_FILTER_NONE); skb_queue_purge(&ptp_priv->tx_queue); lan8841_ptp_flush_fifo(ptp_priv); - return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : 0; + return 0; } static bool lan8841_rxtstamp(struct mii_timestamper *mii_ts, diff --git a/drivers/net/phy/mscc/mscc_ptp.c b/drivers/net/phy/mscc/mscc_ptp.c index cf728bfd83e2..eb0b032cb613 100644 --- a/drivers/net/phy/mscc/mscc_ptp.c +++ b/drivers/net/phy/mscc/mscc_ptp.c @@ -1045,19 +1045,17 @@ static void vsc85xx_ts_reset_fifo(struct phy_device *phydev) val); } -static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) +static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { struct vsc8531_private *vsc8531 = container_of(mii_ts, struct vsc8531_private, mii_ts); struct phy_device *phydev = vsc8531->ptp->phydev; - struct hwtstamp_config cfg; bool one_step = false; u32 val; - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - switch (cfg.tx_type) { + switch (cfg->tx_type) { case HWTSTAMP_TX_ONESTEP_SYNC: one_step = true; break; @@ -1069,9 +1067,9 @@ static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) return -ERANGE; } - vsc8531->ptp->tx_type = cfg.tx_type; + vsc8531->ptp->tx_type = cfg->tx_type; - switch (cfg.rx_filter) { + switch (cfg->rx_filter) { case HWTSTAMP_FILTER_NONE: break; case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: @@ -1084,7 +1082,7 @@ static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) return -ERANGE; } - vsc8531->ptp->rx_filter = cfg.rx_filter; + vsc8531->ptp->rx_filter = cfg->rx_filter; mutex_lock(&vsc8531->ts_lock); @@ -1132,7 +1130,7 @@ static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) vsc8531->ptp->configured = 1; mutex_unlock(&vsc8531->ts_lock); - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; + return 0; } static int vsc85xx_ts_info(struct mii_timestamper *mii_ts, diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c index 7ab080ff02df..416484ea6eb3 100644 --- a/drivers/net/phy/nxp-c45-tja11xx.c +++ b/drivers/net/phy/nxp-c45-tja11xx.c @@ -1022,24 +1022,21 @@ static bool nxp_c45_rxtstamp(struct mii_timestamper *mii_ts, } static int nxp_c45_hwtstamp(struct mii_timestamper *mii_ts, - struct ifreq *ifreq) + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) { struct nxp_c45_phy *priv = container_of(mii_ts, struct nxp_c45_phy, mii_ts); struct phy_device *phydev = priv->phydev; const struct nxp_c45_phy_data *data; - struct hwtstamp_config cfg; - if (copy_from_user(&cfg, ifreq->ifr_data, sizeof(cfg))) - return -EFAULT; - - if (cfg.tx_type < 0 || cfg.tx_type > HWTSTAMP_TX_ON) + if (cfg->tx_type < 0 || cfg->tx_type > HWTSTAMP_TX_ON) return -ERANGE; data = nxp_c45_get_data(phydev); - priv->hwts_tx = cfg.tx_type; + priv->hwts_tx = cfg->tx_type; - switch (cfg.rx_filter) { + switch (cfg->rx_filter) { case HWTSTAMP_FILTER_NONE: priv->hwts_rx = 0; break; @@ -1047,7 +1044,7 @@ static int nxp_c45_hwtstamp(struct mii_timestamper *mii_ts, case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: priv->hwts_rx = 1; - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; break; default: return -ERANGE; @@ -1074,7 +1071,7 @@ static int nxp_c45_hwtstamp(struct mii_timestamper *mii_ts, nxp_c45_clear_reg_field(phydev, &data->regmap->irq_egr_ts_en); nxp_c45_no_ptp_irq: - return copy_to_user(ifreq->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; + return 0; } static int nxp_c45_ts_info(struct mii_timestamper *mii_ts, diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index a5fa077650e8..d058316666ba 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -325,9 +325,13 @@ EXPORT_SYMBOL(phy_ethtool_ksettings_get); int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) { struct mii_ioctl_data *mii_data = if_mii(ifr); + struct kernel_hwtstamp_config kernel_cfg; + struct netlink_ext_ack extack = {}; u16 val = mii_data->val_in; bool change_autoneg = false; + struct hwtstamp_config cfg; int prtad, devad; + int ret; switch (cmd) { case SIOCGMIIPHY: @@ -411,8 +415,21 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) return 0; case SIOCSHWTSTAMP: - if (phydev->mii_ts && phydev->mii_ts->hwtstamp) - return phydev->mii_ts->hwtstamp(phydev->mii_ts, ifr); + if (phydev->mii_ts && phydev->mii_ts->hwtstamp) { + if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) + return -EFAULT; + + hwtstamp_config_to_kernel(&kernel_cfg, &cfg); + ret = phydev->mii_ts->hwtstamp(phydev->mii_ts, &kernel_cfg, &extack); + if (ret) + return ret; + + hwtstamp_config_from_kernel(&cfg, &kernel_cfg); + if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg))) + return -EFAULT; + + return 0; + } fallthrough; default: diff --git a/drivers/ptp/ptp_ines.c b/drivers/ptp/ptp_ines.c index ed215b458183..1d2940a78455 100644 --- a/drivers/ptp/ptp_ines.c +++ b/drivers/ptp/ptp_ines.c @@ -328,17 +328,15 @@ static u64 ines_find_txts(struct ines_port *port, struct sk_buff *skb) return ns; } -static int ines_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) +static int ines_hwtstamp(struct mii_timestamper *mii_ts, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { struct ines_port *port = container_of(mii_ts, struct ines_port, mii_ts); u32 cm_one_step = 0, port_conf, ts_stat_rx, ts_stat_tx; - struct hwtstamp_config cfg; unsigned long flags; - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - switch (cfg.tx_type) { + switch (cfg->tx_type) { case HWTSTAMP_TX_OFF: ts_stat_tx = 0; break; @@ -353,7 +351,7 @@ static int ines_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) return -ERANGE; } - switch (cfg.rx_filter) { + switch (cfg->rx_filter) { case HWTSTAMP_FILTER_NONE: ts_stat_rx = 0; break; @@ -372,7 +370,7 @@ static int ines_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) case HWTSTAMP_FILTER_PTP_V2_SYNC: case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: ts_stat_rx = TS_ENABLE; - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; break; default: return -ERANGE; @@ -393,7 +391,7 @@ static int ines_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) spin_unlock_irqrestore(&port->lock, flags); - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; + return 0; } static void ines_link_state(struct mii_timestamper *mii_ts, diff --git a/include/linux/mii_timestamper.h b/include/linux/mii_timestamper.h index fa940bbaf8ae..26b04f73f214 100644 --- a/include/linux/mii_timestamper.h +++ b/include/linux/mii_timestamper.h @@ -9,6 +9,7 @@ #include #include #include +#include struct phy_device; @@ -51,7 +52,8 @@ struct mii_timestamper { struct sk_buff *skb, int type); int (*hwtstamp)(struct mii_timestamper *mii_ts, - struct ifreq *ifreq); + struct kernel_hwtstamp_config *kernel_config, + struct netlink_ext_ack *extack); void (*link_state)(struct mii_timestamper *mii_ts, struct phy_device *phydev); diff --git a/include/linux/phy.h b/include/linux/phy.h index 3cc52826f18e..e5f1f41e399c 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1560,9 +1560,11 @@ static inline bool phy_has_txtstamp(struct phy_device *phydev) return phydev && phydev->mii_ts && phydev->mii_ts->txtstamp; } -static inline int phy_hwtstamp(struct phy_device *phydev, struct ifreq *ifr) +static inline int phy_hwtstamp(struct phy_device *phydev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { - return phydev->mii_ts->hwtstamp(phydev->mii_ts, ifr); + return phydev->mii_ts->hwtstamp(phydev->mii_ts, cfg, extack); } static inline bool phy_rxtstamp(struct phy_device *phydev, struct sk_buff *skb, From patchwork Mon Oct 9 15:51:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961286vqo; Mon, 9 Oct 2023 08:52:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEV6ddQWNjZSt38w/eN+Vn4iYmwXj8sDEa5DrYRcp0gYpg+kVJH6csab9SnJRao+UbwgaA+ X-Received: by 2002:a17:90a:b114:b0:25b:c454:a366 with SMTP id z20-20020a17090ab11400b0025bc454a366mr15416083pjq.5.1696866741516; Mon, 09 Oct 2023 08:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866741; cv=none; d=google.com; s=arc-20160816; b=WVQD+g7LRcqMLmiiZY3Czdt1Trf0apj+sO+j4SaZBoC9+TPRfVgjp27yUiMe3bY2lt IGW1qNpMrrSYgR6kSotlACP2EmkKqFF9UEPK2n280t84Gc8FUWt7w7x9UV1vjyy4eZ7x V+dFGV15jhWQJV2uDCTRWr+9aidPoDMaT5nyIxdRD6mpwPZlK8XugSZrC4Wi8PKK50zp dSAwZMYHYkX0I285XqDqEsTjQkrcfbtrfPW2tGs2X7bE8rYRG74HktcuwLQnOHkQIGSj B00Ly93QQZCiaXACCbqVq5SIZijEMqaaHFhTrorT8MeHh9KpZcG2ZSj5I6djhdJVVfFa sDtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d10ol8bgQXRCQ3CN2K11usb0w6nOmBYdHJPNNd1RZzA=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=Sd0MUxooL1ZJvcupJCuKR2pvsI+gHYdCP9anKSHxsGq6QkdPXekbzZM2ocBbtM/77o oxlAgVYU1tzx0i5e8mEvEhoUeNot/xDf0Mlyx/3svF46XQQSIU0QQx+Kxdid9Jd9xd0/ LFUOsr0TDnccZ7IXR8/AOlP9kV9Whn8uMJAtz9NgucbFg1KCdOP7oQPa/U+qiWi7iO6g QE/vMaKv8iAOtCpm0M3bUDob9+ZMvt7fXqjtLMR/Y2wbrU+rnOmBhd9GdoKHKiNRSGmq jWgf6lpyjIuTajeWnmeR30Trw2iSrlauSmz3nQeURoQuA/H8wEIqr2ZQ5mbwyqbIfEIe Y2dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=EBVAcZGQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id bj18-20020a17090b089200b0026961fdd37bsi9837648pjb.97.2023.10.09.08.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=EBVAcZGQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 25805801C1E4; Mon, 9 Oct 2023 08:52:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376524AbjJIPv7 (ORCPT + 18 others); Mon, 9 Oct 2023 11:51:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377083AbjJIPvy (ORCPT ); Mon, 9 Oct 2023 11:51:54 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD9989F; Mon, 9 Oct 2023 08:51:52 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 7EDE01C0013; Mon, 9 Oct 2023 15:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d10ol8bgQXRCQ3CN2K11usb0w6nOmBYdHJPNNd1RZzA=; b=EBVAcZGQOgfR3e24L5o1/MyUk//goW/HWM+hPvBZNWpBxJrgTtvw8dqQf54U1i4BPYp4BA t9ciHAM6nos42a6p9r29lyAz1GqSzzLenWVcLPQRxqQDpTwzaO94vaz6BA82IFYjDUztzc sbyvOKm/7aRL+DbRCIu9dOaNMcy9Y9GZkZDDJN0xEMJh4OR/oSTLonFHf/Kr3pTotx6AvZ Mv4C6jiLy3zJM6tyCknjOEgCykzkmgO8hUto1tyYh/BR1gB2Q3AKYo3xkBjXSItyf61CWw gbjRPYf+drzJRNIlH6QUX7KcJC0Md1AVSB95rTbePn+rENLQUl1J00c1b8jvbA== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 02/16] net: phy: Remove the call to phy_mii_ioctl in phy_hwstamp_get/set Date: Mon, 9 Oct 2023 17:51:24 +0200 Message-Id: <20231009155138.86458-3-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:52:16 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293740597748925 X-GMAIL-MSGID: 1779293740597748925 From: Kory Maincent __phy_hwtstamp_set function were calling the phy_mii_ioctl function which will then use the ifreq pointer to call the hwtstamp callback. Now that ifreq has been removed from the hwstamp callback parameters it seems more logical to not go through the phy_mii_ioctl function and pass directly kernel_hwtstamp_config parameter to the hwtstamp callback. Lets do the same for __phy_hwtstamp_get function and return directly EOPNOTSUPP as SIOCGHWTSTAMP is not supported for now for the PHYs. Signed-off-by: Kory Maincent Reviewed-by: Florian Fainelli --- drivers/net/phy/phy.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index d058316666ba..3376e58e2b88 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -486,7 +486,7 @@ int __phy_hwtstamp_get(struct phy_device *phydev, if (!phydev) return -ENODEV; - return phy_mii_ioctl(phydev, config->ifr, SIOCGHWTSTAMP); + return -EOPNOTSUPP; } /** @@ -503,7 +503,10 @@ int __phy_hwtstamp_set(struct phy_device *phydev, if (!phydev) return -ENODEV; - return phy_mii_ioctl(phydev, config->ifr, SIOCSHWTSTAMP); + if (phydev->mii_ts && phydev->mii_ts->hwtstamp) + return phydev->mii_ts->hwtstamp(phydev->mii_ts, config, extack); + + return -EOPNOTSUPP; } /** From patchwork Mon Oct 9 15:51:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961413vqo; Mon, 9 Oct 2023 08:52:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEt3iVKa6EhXZLTODlzouK8v4IadsKU8kAwj/VH7mnRe/j6wHSaKHBj+VULfv/P0vSpVXZQ X-Received: by 2002:a17:90a:b888:b0:274:8a03:b546 with SMTP id o8-20020a17090ab88800b002748a03b546mr15883685pjr.23.1696866753507; Mon, 09 Oct 2023 08:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866753; cv=none; d=google.com; s=arc-20160816; b=xcdo9ZyM0FU1snGNiJajvs5pSN0a46fAMmxtYBq6YxqXYjDZa+TM6NdrqkBBDsGJzP eQragBOSHoYJSFwxqETsm8pVHV8kRqevx7BMml019aocsSUsMZLS4epB3A6AvYzRFNo4 JPoAYG0AqCB8Nf8HIYHnrgCg7JYUJmFD5616hR7iduNRDmSuHedMyMzxzuPcNrqJOH6T MIOoxVDD5nsUDP7WmIhEZgj26IsISuB0NbJuJayyMKn3xC3+KG4nxkqLSW/z3ddIc429 9a0/e/1TsmaYQwEtXN6CoTAaTgBJb0ybkfwDrlWIsUNPaxAK1DCt3+xP27MD0vfCJVOK MMyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nCGdAto1+QXVw1w1qLCsJMnj81jolLUsBwWTGbRy+0Y=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=xNfG7GzSd8f4Q+G35K4XK3XOSoqnYzrHUK0iMsfqhOUvfhBGPurE8Z62oJult/7L1n uPY1vcyyGP0Wui8v7XxrnTM+8isbZYKugCAA6t9bLWabHurlutT7K03u4gvCacA3ferG 9cfy65rzJXYBbtc8/WkAYMLG9X/SbA/MS0DZkYIIMnjUF91GmaawvvxU60syA8tPS/8D eiKr9x1Ik+5JpbD9rE26K1i96NP0tkfdKp1q3ckn/alnnktoSI4LlxfJnysoZJd4idSo +tXn5E1AfeodpYkS+sruqcHnMeKg/7eJ2EdeWX+nV2H9Ids545QwT3aaJSujoolxaai4 rTRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=momwC1vz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id mm10-20020a17090b358a00b00278ee2b717fsi9619811pjb.85.2023.10.09.08.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=momwC1vz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id A3AEF801C4BF; Mon, 9 Oct 2023 08:52:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377679AbjJIPwD (ORCPT + 18 others); Mon, 9 Oct 2023 11:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377075AbjJIPv7 (ORCPT ); Mon, 9 Oct 2023 11:51:59 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9298EE0; Mon, 9 Oct 2023 08:51:56 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id B157C1C0015; Mon, 9 Oct 2023 15:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nCGdAto1+QXVw1w1qLCsJMnj81jolLUsBwWTGbRy+0Y=; b=momwC1vzc2IU8ca67lLfPkk/qA++etY65cxvjh3z3R/UngLPjgKgKSkYIZ1brHy7Y8XDp+ dEHVGEAh/llfcpGbTx+VdnYfXwnv45AY20bAKciaCxUqoJ+OZMuL9/i5bV9Cl4My42QDm3 Rm45KIHuB+sQ+pelfIgcKT37ErI9ERYo4FdsFhbhtffgQTiJNb1+YN3twFcsv5bhYJ5DH5 oncTiKDNer+TTVsSYsaiCsQ074hCKSuvcY4/+Mp4o+92uFjH0RXMiKj6uiNRxg4Szg+SnL NMyHd6+vObOzuU9FUvmzJRSyXBkcAegX1v6WZbN8GCyQR1aSmhVf9RffmOMfJA== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 03/16] net: ethtool: Refactor identical get_ts_info implementations. Date: Mon, 9 Oct 2023 17:51:25 +0200 Message-Id: <20231009155138.86458-4-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:52:29 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293752647105221 X-GMAIL-MSGID: 1779293752647105221 From: Richard Cochran The vlan, macvlan and the bonding drivers call their "real" device driver in order to report the time stamping capabilities. Provide a core ethtool helper function to avoid copy/paste in the stack. Signed-off-by: Richard Cochran Signed-off-by: Kory Maincent Reviewed-by: Florian Fainelli Reviewed-by: Jay Vosburgh --- Change in v5: - Fixe typo --- drivers/net/bonding/bond_main.c | 27 ++------------------------- drivers/net/macvlan.c | 14 +------------- include/linux/ethtool.h | 8 ++++++++ net/8021q/vlan_dev.c | 15 +-------------- net/ethtool/common.c | 6 ++++++ 5 files changed, 18 insertions(+), 52 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index ed7212e61c54..18af563d20b2 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -5763,29 +5763,12 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev, rcu_read_unlock(); if (real_dev) { - ops = real_dev->ethtool_ops; - phydev = real_dev->phydev; - - if (phy_has_tsinfo(phydev)) { - ret = phy_ts_info(phydev, info); - goto out; - } else if (ops->get_ts_info) { - ret = ops->get_ts_info(real_dev, info); - goto out; - } + ret = ethtool_get_ts_info_by_layer(real_dev, info); } else { /* Check if all slaves support software tx timestamping */ rcu_read_lock(); bond_for_each_slave_rcu(bond, slave, iter) { - ret = -1; - ops = slave->dev->ethtool_ops; - phydev = slave->dev->phydev; - - if (phy_has_tsinfo(phydev)) - ret = phy_ts_info(phydev, &ts_info); - else if (ops->get_ts_info) - ret = ops->get_ts_info(slave->dev, &ts_info); - + ret = ethtool_get_ts_info_by_layer(slave->dev, &ts_info); if (!ret && (ts_info.so_timestamping & SOF_TIMESTAMPING_TX_SOFTWARE)) { sw_tx_support = true; continue; @@ -5797,15 +5780,9 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev, rcu_read_unlock(); } - ret = 0; - info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | - SOF_TIMESTAMPING_SOFTWARE; if (sw_tx_support) info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE; - info->phc_index = -1; - -out: dev_put(real_dev); return ret; } diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 02bd201bc7e5..759406fbaea8 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1086,20 +1086,8 @@ static int macvlan_ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) { struct net_device *real_dev = macvlan_dev_real_dev(dev); - const struct ethtool_ops *ops = real_dev->ethtool_ops; - struct phy_device *phydev = real_dev->phydev; - if (phy_has_tsinfo(phydev)) { - return phy_ts_info(phydev, info); - } else if (ops->get_ts_info) { - return ops->get_ts_info(real_dev, info); - } else { - info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | - SOF_TIMESTAMPING_SOFTWARE; - info->phc_index = -1; - } - - return 0; + return ethtool_get_ts_info_by_layer(real_dev, info); } static netdev_features_t macvlan_fix_features(struct net_device *dev, diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 62b61527bcc4..1159daac776e 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -1043,6 +1043,14 @@ static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add, return -EINVAL; } +/** + * ethtool_get_ts_info_by_layer - Obtains time stamping capabilities from the MAC or PHY layer. + * @dev: pointer to net_device structure + * @info: buffer to hold the result + * Returns zero on success, non-zero otherwise. + */ +int ethtool_get_ts_info_by_layer(struct net_device *dev, struct ethtool_ts_info *info); + /** * ethtool_sprintf - Write formatted string to ethtool string data * @data: Pointer to start of string to update diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 2a7f1b15714a..407b2335f091 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -702,20 +702,7 @@ static int vlan_ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) { const struct vlan_dev_priv *vlan = vlan_dev_priv(dev); - const struct ethtool_ops *ops = vlan->real_dev->ethtool_ops; - struct phy_device *phydev = vlan->real_dev->phydev; - - if (phy_has_tsinfo(phydev)) { - return phy_ts_info(phydev, info); - } else if (ops->get_ts_info) { - return ops->get_ts_info(vlan->real_dev, info); - } else { - info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | - SOF_TIMESTAMPING_SOFTWARE; - info->phc_index = -1; - } - - return 0; + return ethtool_get_ts_info_by_layer(vlan->real_dev, info); } static void vlan_dev_get_stats64(struct net_device *dev, diff --git a/net/ethtool/common.c b/net/ethtool/common.c index f5598c5f50de..e2315e24d695 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -661,6 +661,12 @@ int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index) } EXPORT_SYMBOL(ethtool_get_phc_vclocks); +int ethtool_get_ts_info_by_layer(struct net_device *dev, struct ethtool_ts_info *info) +{ + return __ethtool_get_ts_info(dev, info); +} +EXPORT_SYMBOL(ethtool_get_ts_info_by_layer); + const struct ethtool_phy_ops *ethtool_phy_ops; void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops) From patchwork Mon Oct 9 15:51:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961767vqo; Mon, 9 Oct 2023 08:53:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmYKA5KIEFeoD8n0Td+jltSCdR8YrNR7lE5Z25gn51S638pcZTzdiBFIOB2KhEC2pDItcz X-Received: by 2002:a05:6e02:1786:b0:34f:7779:df7f with SMTP id y6-20020a056e02178600b0034f7779df7fmr22184928ilu.0.1696866790597; Mon, 09 Oct 2023 08:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866790; cv=none; d=google.com; s=arc-20160816; b=CwvfKmyPFPjl67q6gpPo2iH+OqgMbhyxgx8/4wF7zpcLM5EO0ih+9AwQ/vF3jNCNzJ jcia6KLB4okEE5O15dEPv6FkQMdPAeSplLnhUP85cxcKFLwnFEbiK/PiQ3EXs8oCyvrp pGvGMTIMWmfxUJKUv/RFYPbtzqENCEJ1q1g5rgduB1sngZS5fXMjd49OcRiLIJACwmpF RB1NrwuJvNMWl8mPwhB1CaTo0cBDzfoLCadll7wTPnJaluA/AKNEKA2D0uUjcn2c4oPL 3SHg/5vgz2W1SpqyI+HnBmVoZfvl4NTC5AXZowlu7sne2tPDpXcsacPPw1WHFCs4w/cT +EPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XJJJLfXCbUFRk44s1J72eD6nlDzDv8eMO6YkqtQzXLI=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=omZ3vRHMVGottXZX31KoYe6Id9/Nuqn5kezx/DInTZqBaQD/7nmMlhylC76Xxq417h EoQB3JM+MHN6xgl3sLYPZkbnkJ/2HvgvH0bbIbMILnGEuPW/Sk93qp7XSfr6y2t/pTJ5 f/I7zyHZR/Piw6BKTuv1KJtdjukes9qROV28j+p3OOotMfSwc29xZcRJD//35IRECpfT LiOVikRW8w1EfP1Lj3rXuPe1ouKnXKzRySaxMgW+PTf1tbJLP78t8Teoy1Aje29feEEf EkG0x+y/HgWUTr0RwPqp62QMilHI6az2yLdwhAtBkUCuCo9WoXaBMx1xZd4CK2pereD7 72Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=e0dmqWQA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o63-20020a634142000000b0058599cadbacsi9858095pga.258.2023.10.09.08.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=e0dmqWQA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 39A468028FAA; Mon, 9 Oct 2023 08:53:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377077AbjJIPwH (ORCPT + 18 others); Mon, 9 Oct 2023 11:52:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377694AbjJIPwD (ORCPT ); Mon, 9 Oct 2023 11:52:03 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA638CF; Mon, 9 Oct 2023 08:51:59 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 6C9301C0003; Mon, 9 Oct 2023 15:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XJJJLfXCbUFRk44s1J72eD6nlDzDv8eMO6YkqtQzXLI=; b=e0dmqWQAAZkkhPCEn/fBD854fwllIFP9gmgN+eMzKRA8oGUPFkDKM/AEKMckjWBrO3C5no 44Bkz2xKmP/w/p1N0yXZCAFvTGrV8DM5wCwsY5j+z/VshqukKWbAF+z/XlxGLrpkU0gfJB YfmntKeLZDWVna2ojX9OQwHQNvAjV9GiSOKznc6DMiJNQhf697KGL8ygJSx2oLdArLiuXm HFpBEpRQZEeP88OFtv8gwVYVaRhP6WP7GZnHuTnhA/vWMEOVrVGFtcUdn5SyFxh+qavVJ9 fc188nrwDy0991GDUexiFOXf7ac4NUjimFmhExdsJwPZFPQ/Bm2NaaBBnGuMFA== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 04/16] net: macb: Convert to ndo_hwtstamp_get() and ndo_hwtstamp_set() Date: Mon, 9 Oct 2023 17:51:26 +0200 Message-Id: <20231009155138.86458-5-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:04 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293791853813164 X-GMAIL-MSGID: 1779293791853813164 From: Kory Maincent The hardware timestamping through ndo_eth_ioctl() is going away. Convert the macb driver to the new API before that can be removed. Signed-off-by: Kory Maincent Reviewed-by: Florian Fainelli --- drivers/net/ethernet/cadence/macb.h | 15 ++++++--- drivers/net/ethernet/cadence/macb_main.c | 42 +++++++++++++++++++----- drivers/net/ethernet/cadence/macb_ptp.c | 28 ++++++---------- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 78c972bb1d96..aa5700ac9c00 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1165,9 +1165,10 @@ struct macb_ptp_info { int (*get_ts_info)(struct net_device *dev, struct ethtool_ts_info *info); int (*get_hwtst)(struct net_device *netdev, - struct ifreq *ifr); + struct kernel_hwtstamp_config *tstamp_config); int (*set_hwtst)(struct net_device *netdev, - struct ifreq *ifr, int cmd); + struct kernel_hwtstamp_config *tstamp_config, + struct netlink_ext_ack *extack); }; struct macb_pm_data { @@ -1314,7 +1315,7 @@ struct macb { struct ptp_clock *ptp_clock; struct ptp_clock_info ptp_clock_info; struct tsu_incr tsu_incr; - struct hwtstamp_config tstamp_config; + struct kernel_hwtstamp_config tstamp_config; /* RX queue filer rule set*/ struct ethtool_rx_fs_list rx_fs_list; @@ -1363,8 +1364,12 @@ static inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, stru gem_ptp_rxstamp(bp, skb, desc); } -int gem_get_hwtst(struct net_device *dev, struct ifreq *rq); -int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd); + +int gem_get_hwtst(struct net_device *dev, + struct kernel_hwtstamp_config *tstamp_config); +int gem_set_hwtst(struct net_device *dev, + struct kernel_hwtstamp_config *tstamp_config, + struct netlink_ext_ack *extack); #else static inline void gem_ptp_init(struct net_device *ndev) { } static inline void gem_ptp_remove(struct net_device *ndev) { } diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index cebae0f418f2..898debfd4db3 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -3773,18 +3773,38 @@ static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) if (!netif_running(dev)) return -EINVAL; - if (bp->ptp_info) { - switch (cmd) { - case SIOCSHWTSTAMP: - return bp->ptp_info->set_hwtst(dev, rq, cmd); - case SIOCGHWTSTAMP: - return bp->ptp_info->get_hwtst(dev, rq); - } - } - return phylink_mii_ioctl(bp->phylink, rq, cmd); } +static int macb_hwtstamp_get(struct net_device *dev, + struct kernel_hwtstamp_config *cfg) +{ + struct macb *bp = netdev_priv(dev); + + if (!netif_running(dev)) + return -EINVAL; + + if (!bp->ptp_info) + return -EOPNOTSUPP; + + return bp->ptp_info->get_hwtst(dev, cfg); +} + +static int macb_hwtstamp_set(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) +{ + struct macb *bp = netdev_priv(dev); + + if (!netif_running(dev)) + return -EINVAL; + + if (!bp->ptp_info) + return -EOPNOTSUPP; + + return bp->ptp_info->set_hwtst(dev, cfg, extack); +} + static inline void macb_set_txcsum_feature(struct macb *bp, netdev_features_t features) { @@ -3884,6 +3904,8 @@ static const struct net_device_ops macb_netdev_ops = { #endif .ndo_set_features = macb_set_features, .ndo_features_check = macb_features_check, + .ndo_hwtstamp_set = macb_hwtstamp_set, + .ndo_hwtstamp_get = macb_hwtstamp_get, }; /* Configure peripheral capabilities according to device tree @@ -4539,6 +4561,8 @@ static const struct net_device_ops at91ether_netdev_ops = { #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_poll_controller = at91ether_poll_controller, #endif + .ndo_hwtstamp_set = macb_hwtstamp_set, + .ndo_hwtstamp_get = macb_hwtstamp_get, }; static int at91ether_clk_init(struct platform_device *pdev, struct clk **pclk, diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c index 51d26fa190d7..a63bf29c4fa8 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -374,19 +374,16 @@ static int gem_ptp_set_ts_mode(struct macb *bp, return 0; } -int gem_get_hwtst(struct net_device *dev, struct ifreq *rq) +int gem_get_hwtst(struct net_device *dev, + struct kernel_hwtstamp_config *tstamp_config) { - struct hwtstamp_config *tstamp_config; struct macb *bp = netdev_priv(dev); - tstamp_config = &bp->tstamp_config; + *tstamp_config = bp->tstamp_config; if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0) return -EOPNOTSUPP; - if (copy_to_user(rq->ifr_data, tstamp_config, sizeof(*tstamp_config))) - return -EFAULT; - else - return 0; + return 0; } static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable) @@ -401,22 +398,18 @@ static void gem_ptp_set_one_step_sync(struct macb *bp, u8 enable) macb_writel(bp, NCR, reg_val & ~MACB_BIT(OSSMODE)); } -int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd) +int gem_set_hwtst(struct net_device *dev, + struct kernel_hwtstamp_config *tstamp_config, + struct netlink_ext_ack *extack) { enum macb_bd_control tx_bd_control = TSTAMP_DISABLED; enum macb_bd_control rx_bd_control = TSTAMP_DISABLED; - struct hwtstamp_config *tstamp_config; struct macb *bp = netdev_priv(dev); u32 regval; - tstamp_config = &bp->tstamp_config; if ((bp->hw_dma_cap & HW_DMA_CAP_PTP) == 0) return -EOPNOTSUPP; - if (copy_from_user(tstamp_config, ifr->ifr_data, - sizeof(*tstamp_config))) - return -EFAULT; - switch (tstamp_config->tx_type) { case HWTSTAMP_TX_OFF: break; @@ -463,12 +456,11 @@ int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd) return -ERANGE; } + bp->tstamp_config = *tstamp_config; + if (gem_ptp_set_ts_mode(bp, tx_bd_control, rx_bd_control) != 0) return -ERANGE; - if (copy_to_user(ifr->ifr_data, tstamp_config, sizeof(*tstamp_config))) - return -EFAULT; - else - return 0; + return 0; } From patchwork Mon Oct 9 15:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150178 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961452vqo; Mon, 9 Oct 2023 08:52:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/IupHvjMA9Oti9cVwiFKjK6VIta0dNHm715glHFg+YQkOI+Ld1QeFBEUSM4zHor5f8AQD X-Received: by 2002:a17:902:d4cd:b0:1c8:8f5f:b610 with SMTP id o13-20020a170902d4cd00b001c88f5fb610mr9227689plg.13.1696866758219; Mon, 09 Oct 2023 08:52:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866758; cv=none; d=google.com; s=arc-20160816; b=InlpLSf5Fq3yTdjEBqjvzz1rRY60AQoPjQtf4KFHXdWFFrg/OC89obnut/QOlC7zme HQNWjGQGaa2Atr3KkFZGsLsU1sMAvy0l9ASAmS80RuvnJD0OxYg8pjDzgqPfTjkPc7fs wL9vOftaV2vTjoJh9Ce9Nlsh8her4i90Wrkfd3SK0Jl8YLeq00Dmc1bwLa9DuLFqvJZs A6HYfQ5rpsOh0EPpKUa/5rFlYEmwXe0oq42gcrMQe+Rzne0nDKJooEORjXbVzmTy4yMy kB2+vpTjfl4Qkz9TinJfp3zE8XNN70KyZBsucye3rbmIVXZ6Y52UxJCH7m8rAq8Vzo9j zv7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Dwoe6lOlx1E2/77Mocwc9aHtLkZweaYfyFKWpCGQ1gQ=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=hCy93Cdx8KSBhEm4eXowMTlSvRcakzlew87tsTpDmIrwrXrL3eaRtau9mSggEmMrCF /LgimpmSvYy/CZ6lne5bXS5xUAmYf5/uaQBjmxJjISi6MeBy0m9cu4KKplK8VEdbnSrg uorR+fTygyauTL0n30ZO1X2E8Rd8YRYGAWbMOzXzsZP87ulO6MRv0edt5XBJBgL8U4Iw x4QcVdl7HgZxcxVhK58BwbuteCvwfcZGvxo4quLa8gdetBQxArbyCPNQh9QwF6Tjsvnm OwDiJeWivgIP5cb4Gy4UPAUARQdUNxdFzI6RJejyCAKFlzTOoyQQc4DSzhmGoTTRTPo2 CvAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=i+wsxQ6m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l20-20020a170902e2d400b001b9eb5d1ea2si9319055plc.198.2023.10.09.08.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:52:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=i+wsxQ6m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 789678043C1A; Mon, 9 Oct 2023 08:52:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377767AbjJIPwR (ORCPT + 18 others); Mon, 9 Oct 2023 11:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377697AbjJIPwI (ORCPT ); Mon, 9 Oct 2023 11:52:08 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24A88D6; Mon, 9 Oct 2023 08:52:04 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id CFDBC1C0014; Mon, 9 Oct 2023 15:51:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dwoe6lOlx1E2/77Mocwc9aHtLkZweaYfyFKWpCGQ1gQ=; b=i+wsxQ6m1upWCYyo7u+e+YHrmJciyPcLnTSLp3AXxC5O/qfjJvoyHivghNry0Hg5lsJGhn OeMCox2R+6ZYcD/SJe8U7ZUy4fsvchMdbFd2zkq5UDdVVvxEe9h2ZCyRAvEbAeFZDhARq+ 6RZAourwHRPBrrqPuVJeKFIfaaB8nlI0J5QxyT73jQ1ibb+3jlHkBvsqX8gTZxqNA/BsBx Kke6HnWtyeg63AcPh/XEHDYAevc/GQpiVGCh4PfY8n9vty4kdOmS/s6ERI3zPYvURANlw3 VBCOx3+DKO7oGk9GDqhhCr4zkaUYsZaZtcir1+Jzd4E+Bbcv5JL19cy8OHPD8w== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 05/16] net: Make dev_set_hwtstamp_phylib accessible Date: Mon, 9 Oct 2023 17:51:27 +0200 Message-Id: <20231009155138.86458-6-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:52:35 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293757977982208 X-GMAIL-MSGID: 1779293757977982208 From: Kory Maincent Make the dev_set_hwtstamp_phylib function accessible in prevision to use it from ethtool to reset the tstamp current configuration. Signed-off-by: Kory Maincent --- include/linux/netdevice.h | 3 +++ net/core/dev_ioctl.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index e070a4540fba..b9d0411836db 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3922,6 +3922,9 @@ int generic_hwtstamp_get_lower(struct net_device *dev, int generic_hwtstamp_set_lower(struct net_device *dev, struct kernel_hwtstamp_config *kernel_cfg, struct netlink_ext_ack *extack); +int dev_set_hwtstamp_phylib(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack); int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *userdata); unsigned int dev_get_flags(const struct net_device *); int __dev_change_flags(struct net_device *dev, unsigned int flags, diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index b46aedc36939..342a667858ac 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -322,9 +322,9 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) * frames and not forward them), it must set IFF_SEE_ALL_HWTSTAMP_REQUESTS in * dev->priv_flags. */ -static int dev_set_hwtstamp_phylib(struct net_device *dev, - struct kernel_hwtstamp_config *cfg, - struct netlink_ext_ack *extack) +int dev_set_hwtstamp_phylib(struct net_device *dev, + struct kernel_hwtstamp_config *cfg, + struct netlink_ext_ack *extack) { const struct net_device_ops *ops = dev->netdev_ops; bool phy_ts = phy_has_hwtstamp(dev->phydev); From patchwork Mon Oct 9 15:51:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150179 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961455vqo; Mon, 9 Oct 2023 08:52:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYW+U8mbj9hmlNaNtXD44JOtQmMVfWEctQo7TWpXlvuTZHIWiZ0FChAzTmj7QjsmpQAKnW X-Received: by 2002:a17:902:ec85:b0:1c4:749e:e725 with SMTP id x5-20020a170902ec8500b001c4749ee725mr14978628plg.0.1696866758469; Mon, 09 Oct 2023 08:52:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866758; cv=none; d=google.com; s=arc-20160816; b=X8BbfLjcq7Quz6PtP/KhJftRqbY4Fgw7Qa2OgfcI8GYpivj4wiV+bO9PeodzzFQcGq /DGyJXb1RA24eFLcH74G5FWBA0MW7y1eeqVJL7TfEUzuxBz6lo3EdW7AXpFk4ccVPtRh tNYnWQTFZQFqA5z82zYn86ii9IyRNJvQzmEfPWrNjctFxg+CkmoUUOtMMTm2NRp8IMrJ afpip4loYDZw6ug74PhRfx4kPQTW/bGGSP1H5SZkPicMkQIpRmn2I8UAMb8/Xruhdc0m 2hSdrAt1BZ1lA0lCP8kKQJ4t+hT68WEnB9Dm7Gy/rXM1oCsRz9vSnzSuH2YAGh2PEw9c 2itw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a9F7BlsKWH7/jew3pkCvEwzC+iFPlgmNxIBdYB/M5ek=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=t06UBDJXZ2JJh0E+9mdeEGWv7bl7/uOYO4ObbUFXYL4R9L/P2l9AEtX6/YQ28Ngw/w LymMsWHKKZZ0OfkaM7qanXekzMgtzwFgSdtxQ/cOxibU8tbrfDoCqaWPMd91wCGLeWLS 5ap3kfpQcT1d7/IxELrhymlRrsqnTrZ27nw8/vpdGjmdB5cBNFnmW6XaDkM0CB4FOhF3 XkoAdLJoC33NapO5Q6kVFzD+tSPB4lB7qLWRCp2MvZfV+gea3led3snKzHHdOIovnSCJ Rlr0dVCKG2cy3uM8rAVH4qXKeA5b9JZPcF8k3qoJJ/F9PvjMvEc1QaDCrQqHaO26VONv 6SBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=lg9DUJE9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y8-20020a17090322c800b001c45291b6ebsi10404295plg.272.2023.10.09.08.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:52:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=lg9DUJE9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id EEB088043C2A; Mon, 9 Oct 2023 08:52:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377756AbjJIPwW (ORCPT + 18 others); Mon, 9 Oct 2023 11:52:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377716AbjJIPwR (ORCPT ); Mon, 9 Oct 2023 11:52:17 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E0BE125; Mon, 9 Oct 2023 08:52:09 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 813401C0002; Mon, 9 Oct 2023 15:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a9F7BlsKWH7/jew3pkCvEwzC+iFPlgmNxIBdYB/M5ek=; b=lg9DUJE9ubus5wrIC3pe2hFr91vs756EqASADzULyFowPfiMbq2S4435QUiT8hhJqNeKfy 3+hyzRJ8h1ZMKx5twtPj4RgODw/dGd5bOz+FfZnK5O2ON1CdtHsJ4oQIOe6CmFf1/qKPjh 51wxMQ2pAyLaN1yiX/JVuf6cHkE4hINWHe37Sf624PA9+W9rs1ybPIWwMzvlKdWwfLWYdv du3NEm/lRqqAOfPGCOHFhDMvRHybGhQp3sAHFjDAVCpAeCVWRptgFEepJozHpTh44Po2WI iVfkOVoIDLbH9v2MQWQwZLdS50JK56sMnQ6HMEudvfkczYK6z1XcHLZqv64vVQ== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 06/16] net_tstamp: Add TIMESTAMPING SOFTWARE and HARDWARE mask Date: Mon, 9 Oct 2023 17:51:28 +0200 Message-Id: <20231009155138.86458-7-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:52:36 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293758037818073 X-GMAIL-MSGID: 1779293758037818073 From: Kory Maincent Timestamping software or hardware flags are often used as a group, therefore adding these masks will easier future use. I did not use SOF_TIMESTAMPING_SYS_HARDWARE flag as it is deprecated and not use at all. Signed-off-by: Kory Maincent --- include/uapi/linux/net_tstamp.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h index a2c66b3d7f0f..df8091998c8d 100644 --- a/include/uapi/linux/net_tstamp.h +++ b/include/uapi/linux/net_tstamp.h @@ -48,6 +48,14 @@ enum { SOF_TIMESTAMPING_TX_SCHED | \ SOF_TIMESTAMPING_TX_ACK) +#define SOF_TIMESTAMPING_SOFTWARE_MASK (SOF_TIMESTAMPING_RX_SOFTWARE | \ + SOF_TIMESTAMPING_TX_SOFTWARE | \ + SOF_TIMESTAMPING_SOFTWARE) + +#define SOF_TIMESTAMPING_HARDWARE_MASK (SOF_TIMESTAMPING_RX_HARDWARE | \ + SOF_TIMESTAMPING_TX_HARDWARE | \ + SOF_TIMESTAMPING_RAW_HARDWARE) + /** * struct so_timestamping - SO_TIMESTAMPING parameter * From patchwork Mon Oct 9 15:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150180 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961493vqo; Mon, 9 Oct 2023 08:52:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqloa7ASwnnJjYm8yoBezMzomXQq3GYkYmS4lgkI1b0gRi17xFV2fOLC/7tuTxqUYW3ddV X-Received: by 2002:aa7:8889:0:b0:691:1eb:7dda with SMTP id z9-20020aa78889000000b0069101eb7ddamr15150406pfe.7.1696866762418; Mon, 09 Oct 2023 08:52:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866762; cv=none; d=google.com; s=arc-20160816; b=vLqPpJ7sr4WkxyFVbYlqv5pNaQ+4O8PpVfKQvmVmW9dQpLoW9uveNQfy2sYqsmdYYK hQUJ/yMCvDtpIDjTnxrOfJbEDsbSuR8SeTrHYkvttAUf/FU23MGsF7X7WWUouz9So+63 a78UFcegHYpvHQ8oDIXhjff1r2m1X/fdb507K+MvZ9s1GDTrryS8TblwcHWEply11SCO /lekJpmC4XOrqRsdn5qKG4uMO9knd8iK0HaiCdrPGihiKoI2Coi3lX/kKs7CmFigGDf7 IbJZiRzFLEgpNumz1Z5VZlXW4kdmuTE/Xms9VXketnJwifdUnKXI96a0XPI1oW6PE8LF 8pWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S5xrHQYkyyICqKVCkMIBEoNYkfvTukzEtmdi6V8WJdA=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=rvIPWHJl5PkbaHHnSr2gU92uTIoas8cJISa316uDKBfaRESK6aZ/yaplgc0xNXVinb 6oLWqxJOJiMwRdjf/euLjP/4xzoCKU2yAv8uSY2bwPDFZ9n4xwkMRv/0qz+UY84zENY4 BOSm9ylkmJDK95u89PlJvUyzTOalbjJpfJtIOhWAVipiBlPcFshGFdYK3liYyzU8wI5T WJfRMmPyoP34LGkpt3LWZtute5w3/9QWfHv+gw+LjvFNK+dgKu/Wmm02pj8oIBBd4R73 Sx6ws/FAigc+5LnKlfaxH5lZXfGmbgvccTPMqw8JnCFBnfq6ENQA4Ghxct4++mVgLj4C rtUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=p6UHPmrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id v19-20020a056a00149300b00690158064aasi7886392pfu.118.2023.10.09.08.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:52:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=p6UHPmrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 055A38111393; Mon, 9 Oct 2023 08:52:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377876AbjJIPwc (ORCPT + 18 others); Mon, 9 Oct 2023 11:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377751AbjJIPwU (ORCPT ); Mon, 9 Oct 2023 11:52:20 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89DE618F; Mon, 9 Oct 2023 08:52:12 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 370801C0011; Mon, 9 Oct 2023 15:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S5xrHQYkyyICqKVCkMIBEoNYkfvTukzEtmdi6V8WJdA=; b=p6UHPmrUmFDllKWCYfAAHTYuIRZG8gLNy4uqUwjLh/Qlj0D0KGE4nSOGZVCboJ6bVJKrus GE0DkZCgjhWuJJkqYhQbR9n769hO/+QEYo8ABsWBMAG93kQ4xtlaNVv26UpmGZNrHYgtHz s/RSUc6Nf9ppYfTHQI7+sO7gFscZ627BWitZwgLz+c4dT7045m8zFSZNHPRDtP9Dx24IRN 6fghTjrpQofGjT+nzY7kk8bMfK3Ggnz/aOu16bwPsz7lAb5FQ04J8WrM7E9X0W/dwabgjf cDHAbwx1sik7s2cuQvL8Pshq6aWVY6axsH8QJRql3FOf/aDN716Tuxn+XfFEkg== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 07/16] net: phy: micrel: fix ts_info value in case of no phc Date: Mon, 9 Oct 2023 17:51:29 +0200 Message-Id: <20231009155138.86458-8-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:52:39 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293762439494639 X-GMAIL-MSGID: 1779293762439494639 From: Kory Maincent In case of no phc we should not return SOFTWARE TIMESTAMPING flags as we do not know the netdev supports of timestamping. Remove it from the lan8841_ts_info and simply return 0. Signed-off-by: Kory Maincent --- This patch is not tested but it seems consistent to me. --- drivers/net/phy/micrel.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 43d072b53839..4c115e55ffc0 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -3607,12 +3607,8 @@ static int lan8841_ts_info(struct mii_timestamper *mii_ts, info->phc_index = ptp_priv->ptp_clock ? ptp_clock_index(ptp_priv->ptp_clock) : -1; - if (info->phc_index == -1) { - info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE | - SOF_TIMESTAMPING_RX_SOFTWARE | - SOF_TIMESTAMPING_SOFTWARE; + if (info->phc_index == -1) return 0; - } info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE | From patchwork Mon Oct 9 15:51:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961781vqo; Mon, 9 Oct 2023 08:53:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG15rL0W8mG6IjtJCycD2EyolvhZY87PdKCAyoI7VV0dYk9FMEXkWu9MqMnRTnPP6Gs0Txx X-Received: by 2002:a05:6a00:1a92:b0:693:394f:5d99 with SMTP id e18-20020a056a001a9200b00693394f5d99mr20117772pfv.8.1696866791586; Mon, 09 Oct 2023 08:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866791; cv=none; d=google.com; s=arc-20160816; b=ZsuvXYfYuJ2qEr10LSJ2ZkjJVY+l4aX0HKkkZMRNfAJfB6vXbRmkZzTJQcRrFf7tPc 0dB8W2knLyKfTw6qpicZkrZXIbA/TBCFgo866RoEcdHlHVkAZbuwqyGoh4NuJHM8kj4D eb6GnE3XDjCj3EJIqWB7A4xwplTVIrO6mkXZ7C5RrPGNtaSm4zfvxi9YbacNn74A5HmA Km6NSFoYB2LU7YBjDmlMfTFDYfZNONBCBNeV9Mgkx+rojxz3m+N+26hRBXQvdCQqGovC DnXcK9szEWyhaMe7NpWGf83Xptk7z1ziWuK4lWh3qiEPWtlw4LAnxx25//dazPf8ziyG Cm/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TMj927tRAeghDZ/h+pJ+/V78yjedCJcCfZgoXhULyz4=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=Q0D6T4dUz2KslJn1jfVwQnLxTLYrGhbw43zQmnBNIw70vlrvzxb+VCzWQlob7TEjGT tq0asYtaWXbtKqZQjilQV4PTFFkB3D6zixqsn9KD9wHSzWMSpjjGhJ990OD4rvwsXZD1 BMJGkYNe2aGHAUJoJmkvD1uJJGyV+Hd+zeGuYHa3lXyWJUwKlinxur21qLdKwos/GLAU 0hVn9tdY/1l8Q8BZmi/WGe0xr3gxAptxzAx4TspHcgQfym1h+gNEPSej3O9x8if5gknc kqY/K65PzB1EhkReed/ahGI1NUAbXJzzjxTvPEf7l2/PCXZh3yDKm4RZxzSekLM8nqrt 19NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BDUjo4IH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id o16-20020a056a0015d000b0069014511b25si7996701pfu.110.2023.10.09.08.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BDUjo4IH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B5D44801C1DA; Mon, 9 Oct 2023 08:53:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377921AbjJIPwm (ORCPT + 18 others); Mon, 9 Oct 2023 11:52:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377805AbjJIPwZ (ORCPT ); Mon, 9 Oct 2023 11:52:25 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74934DE; Mon, 9 Oct 2023 08:52:16 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id AA4651C000B; Mon, 9 Oct 2023 15:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TMj927tRAeghDZ/h+pJ+/V78yjedCJcCfZgoXhULyz4=; b=BDUjo4IHiXq8jL5QfnRXccx0kY61YfrUVmRbtBib02SxhNLOoHJVX9MsktHMcIvYkKKlGs 3h4WOIZjPC5xJZxfO47lI9ZrGA0KNYiL/6SfROrIpzDu7NZKr83uJX9NzDsGB5tumzbiu3 0md3Y1/0WYbmYnsAot5E2zNkOeh5l4fm4ggh7aqHfDBLREESoRek7ibZ0NEXqF1sOHeMDk zdhNiIdcfpjqjKao7P9vYXINWL9R1FVPRY+Ggp27ea13yrOBlNzd8p6O0XvrlUSQVvvxC6 MO9XXYjPoFfl5Y6u3wNITbusK8wfh77zgbX5OLgVYgjp8qbisn6dPrFlsDfRpw== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 08/16] net: ethtool: Add a command to expose current time stamping layer Date: Mon, 9 Oct 2023 17:51:30 +0200 Message-Id: <20231009155138.86458-9-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:08 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293793139783558 X-GMAIL-MSGID: 1779293793139783558 From: Kory Maincent Time stamping on network packets may happen either in the MAC or in the PHY, but not both. In preparation for making the choice selectable, expose both the current and available layers via ethtool. In accordance with the kernel implementation as it stands, the current layer will always read as "phy" when a PHY time stamping device is present. Future patches will allow changing the current layer administratively. Signed-off-by: Kory Maincent --- Changes in v2: - Move the introduction of selected_timestamping_layer variable in next patch. Changes in v3: - Move on to ethtool instead of syfs Changes in v4: - Move on to netlink ethtool instead of ioctl. I am not familiar with netlink so there might be some code that does not follow the good code practice. Changes in v5: - Rename timestamping layers. - Set a default value of ts_layer in __ethtool_get_ts_info function. - Separate TS_GET and TS_LIST_GET ethtool command in two separate patches. - Update documentation. --- Documentation/networking/ethtool-netlink.rst | 23 ++++++ include/uapi/linux/ethtool_netlink.h | 14 ++++ include/uapi/linux/net_tstamp.h | 14 ++++ net/ethtool/Makefile | 2 +- net/ethtool/common.h | 1 + net/ethtool/netlink.c | 10 +++ net/ethtool/netlink.h | 2 + net/ethtool/ts.c | 78 ++++++++++++++++++++ 8 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 net/ethtool/ts.c diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 2540c70952ff..644b3b764044 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -225,6 +225,7 @@ Userspace to kernel: ``ETHTOOL_MSG_RSS_GET`` get RSS settings ``ETHTOOL_MSG_MM_GET`` get MAC merge layer state ``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters + ``ETHTOOL_MSG_TS_GET`` get current timestamping ===================================== ================================= Kernel to userspace: @@ -268,6 +269,7 @@ Kernel to userspace: ``ETHTOOL_MSG_PSE_GET_REPLY`` PSE parameters ``ETHTOOL_MSG_RSS_GET_REPLY`` RSS settings ``ETHTOOL_MSG_MM_GET_REPLY`` MAC merge layer status + ``ETHTOOL_MSG_TS_GET_REPLY`` current timestamping ======================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device @@ -1994,6 +1996,26 @@ The attributes are propagated to the driver through the following structure: .. kernel-doc:: include/linux/ethtool.h :identifiers: ethtool_mm_cfg +TS_GET +====== + +Gets current timestamping. + +Request contents: + + ================================= ====== ==================== + ``ETHTOOL_A_TS_HEADER`` nested request header + ================================= ====== ==================== + +Kernel response contents: + + ======================= ====== ============================== + ``ETHTOOL_A_TS_HEADER`` nested reply header + ``ETHTOOL_A_TS_LAYER`` u32 current timestamping + ======================= ====== ============================== + +This command get the current timestamp layer. + Request translation =================== @@ -2100,4 +2122,5 @@ are netlink only. n/a ``ETHTOOL_MSG_PLCA_GET_STATUS`` n/a ``ETHTOOL_MSG_MM_GET`` n/a ``ETHTOOL_MSG_MM_SET`` + n/a ``ETHTOOL_MSG_TS_GET`` =================================== ===================================== diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index 73e2c10dc2cc..cb51136328cf 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -57,6 +57,7 @@ enum { ETHTOOL_MSG_PLCA_GET_STATUS, ETHTOOL_MSG_MM_GET, ETHTOOL_MSG_MM_SET, + ETHTOOL_MSG_TS_GET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -109,6 +110,7 @@ enum { ETHTOOL_MSG_PLCA_NTF, ETHTOOL_MSG_MM_GET_REPLY, ETHTOOL_MSG_MM_NTF, + ETHTOOL_MSG_TS_GET_REPLY, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -975,6 +977,18 @@ enum { ETHTOOL_A_MM_MAX = (__ETHTOOL_A_MM_CNT - 1) }; +/* TS LAYER */ + +enum { + ETHTOOL_A_TS_UNSPEC, + ETHTOOL_A_TS_HEADER, /* nest - _A_HEADER_* */ + ETHTOOL_A_TS_LAYER, /* u32 */ + + /* add new constants above here */ + __ETHTOOL_A_TS_CNT, + ETHTOOL_A_TS_MAX = (__ETHTOOL_A_TS_CNT - 1) +}; + /* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_VERSION 1 diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h index df8091998c8d..33ff8e989dbe 100644 --- a/include/uapi/linux/net_tstamp.h +++ b/include/uapi/linux/net_tstamp.h @@ -13,6 +13,20 @@ #include #include /* for SO_TIMESTAMPING */ +/* + * Hardware layer of the TIMESTAMPING provider + * New description layer should have the NETDEV_TIMESTAMPING or + * PHYLIB_TIMESTAMPING bit set to know which API to use for timestamping. + */ +enum { + NO_TIMESTAMPING = 0, + NETDEV_TIMESTAMPING = (1 << 0), + PHYLIB_TIMESTAMPING = (1 << 1), + SOFTWARE_TIMESTAMPING = (1 << 2) | (1 << 0), + + __TIMESTAMPING_COUNT, +}; + /* SO_TIMESTAMPING flags */ enum { SOF_TIMESTAMPING_TX_HARDWARE = (1<<0), diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile index 504f954a1b28..4ea64c080639 100644 --- a/net/ethtool/Makefile +++ b/net/ethtool/Makefile @@ -8,4 +8,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \ - module.o pse-pd.o plca.o mm.o + module.o pse-pd.o plca.o mm.o ts.o diff --git a/net/ethtool/common.h b/net/ethtool/common.h index 28b8aaaf9bcb..a264b635f7d3 100644 --- a/net/ethtool/common.h +++ b/net/ethtool/common.h @@ -35,6 +35,7 @@ extern const char wol_mode_names[][ETH_GSTRING_LEN]; extern const char sof_timestamping_names[][ETH_GSTRING_LEN]; extern const char ts_tx_type_names[][ETH_GSTRING_LEN]; extern const char ts_rx_filter_names[][ETH_GSTRING_LEN]; +extern const char ts_layer_names[][ETH_GSTRING_LEN]; extern const char udp_tunnel_type_names[][ETH_GSTRING_LEN]; int __ethtool_get_link(struct net_device *dev); diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 3bbd5afb7b31..561c0931d055 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -306,6 +306,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_PLCA_GET_STATUS] = ðnl_plca_status_request_ops, [ETHTOOL_MSG_MM_GET] = ðnl_mm_request_ops, [ETHTOOL_MSG_MM_SET] = ðnl_mm_request_ops, + [ETHTOOL_MSG_TS_GET] = ðnl_ts_request_ops, }; static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) @@ -1128,6 +1129,15 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_mm_set_policy, .maxattr = ARRAY_SIZE(ethnl_mm_set_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_TS_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_ts_get_policy, + .maxattr = ARRAY_SIZE(ethnl_ts_get_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 9a333a8d04c1..1e6085198acc 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -395,6 +395,7 @@ extern const struct ethnl_request_ops ethnl_rss_request_ops; extern const struct ethnl_request_ops ethnl_plca_cfg_request_ops; extern const struct ethnl_request_ops ethnl_plca_status_request_ops; extern const struct ethnl_request_ops ethnl_mm_request_ops; +extern const struct ethnl_request_ops ethnl_ts_request_ops; extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1]; extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1]; @@ -441,6 +442,7 @@ extern const struct nla_policy ethnl_plca_set_cfg_policy[ETHTOOL_A_PLCA_MAX + 1] extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADER + 1]; extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1]; extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1]; +extern const struct nla_policy ethnl_ts_get_policy[ETHTOOL_A_TS_HEADER + 1]; int ethnl_set_features(struct sk_buff *skb, struct genl_info *info); int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info); diff --git a/net/ethtool/ts.c b/net/ethtool/ts.c new file mode 100644 index 000000000000..cd33f057ee48 --- /dev/null +++ b/net/ethtool/ts.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include "netlink.h" +#include "common.h" +#include "bitset.h" + +struct ts_req_info { + struct ethnl_req_info base; +}; + +struct ts_reply_data { + struct ethnl_reply_data base; + u32 ts_layer; +}; + +#define TS_REPDATA(__reply_base) \ + container_of(__reply_base, struct ts_reply_data, base) + +/* TS_GET */ +const struct nla_policy ethnl_ts_get_policy[] = { + [ETHTOOL_A_TS_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), +}; + +static int ts_prepare_data(const struct ethnl_req_info *req_base, + struct ethnl_reply_data *reply_base, + const struct genl_info *info) +{ + struct ts_reply_data *data = TS_REPDATA(reply_base); + struct net_device *dev = reply_base->dev; + const struct ethtool_ops *ops = dev->ethtool_ops; + int ret; + + ret = ethnl_ops_begin(dev); + if (ret < 0) + return ret; + + if (phy_has_tsinfo(dev->phydev)) + data->ts_layer = PHYLIB_TIMESTAMPING; + else if (ops->get_ts_info) + data->ts_layer = NETDEV_TIMESTAMPING; + else + data->ts_layer = NO_TIMESTAMPING; + + ethnl_ops_complete(dev); + + return ret; +} + +static int ts_reply_size(const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + return nla_total_size(sizeof(u32)); +} + +static int ts_fill_reply(struct sk_buff *skb, + const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + struct ts_reply_data *data = TS_REPDATA(reply_base); + + return nla_put_u32(skb, ETHTOOL_A_TS_LAYER, data->ts_layer); +} + +const struct ethnl_request_ops ethnl_ts_request_ops = { + .request_cmd = ETHTOOL_MSG_TS_GET, + .reply_cmd = ETHTOOL_MSG_TS_GET_REPLY, + .hdr_attr = ETHTOOL_A_TS_HEADER, + .req_info_size = sizeof(struct ts_req_info), + .reply_data_size = sizeof(struct ts_reply_data), + + .prepare_data = ts_prepare_data, + .reply_size = ts_reply_size, + .fill_reply = ts_fill_reply, +}; From patchwork Mon Oct 9 15:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150181 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961655vqo; Mon, 9 Oct 2023 08:53:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEr4bknu1kxxQTdSzU6qeiUsujl9lv+e0T2QpJ/qMxG0VfwjescTs5XkKmydKRj5Gcf3jQS X-Received: by 2002:a17:90b:4a49:b0:277:3569:2a05 with SMTP id lb9-20020a17090b4a4900b0027735692a05mr13574321pjb.27.1696866781425; Mon, 09 Oct 2023 08:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866781; cv=none; d=google.com; s=arc-20160816; b=e9SndQtxQrCeJaLeCNrNlkO3W3hHv/fMDtXPfssECbXKk/RtZ7jVBWzOwqXUF7/40Q wKC/dYPFRg/I3yCtKjqgq7Tihz9s++wSg8maJfFgpjE7H4bAVDMEg29Na59OvmL2KAmY Zoar6qjAK2WhrP24RsrH53cCFff2AWFpobETsmLZAqP2DGYpqnAmVcTz1ixiGfgRrJQ0 8GVU7VhNlEn4qmF6XdK84WQC4EH61jsdvfjcNUxjc+JNqSGMQ6BKzeQgxLfZ9SLMaGhf pe92yWkya6hx0cIpCncj3wjmmNfWxMYcW0focVuAjWVDAb6pOZqCwPBBpf5hC3KK2GhW sIeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kiv+yxDSpeeBqHfOwRUQw3mS7Lf3CBbyGOYxIaD7WCE=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=CPqTijZauh+uoRhB0WXgcNw05XW4PaVCd9mBpr7gXct0qiy4/n5kuEqGf9yjTtMxTR 7rmnZ3o3VsGAv0lQWiPUmtJhvBNhfd6JWyRxgH7Nvfm7VSGjmG6e2/wflQAB5tArI114 HIRcgUr7FuZJPNUCoea77zaKFz2sytuCgGfgX0XGlbL+WiVd+4HByNu86SLS5WYfG1De By0CtQ1nNNlkVFhPYRmRoPnwxyTEPh2FvldGMpImlhujvVt7RG+Yn2rpqHxkJbsG+Rhj 1ICe56fjsCdZV1P9w/C5h6CxO2+GgVXFSUTguuMhS1WloCrFsh1wYg3fh4mLCDaIX9p5 4IXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=flLpiW9H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id x2-20020a17090a8a8200b00277816efefasi9465733pjn.106.2023.10.09.08.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=flLpiW9H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id BCD0881113A8; Mon, 9 Oct 2023 08:52:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377875AbjJIPwq (ORCPT + 18 others); Mon, 9 Oct 2023 11:52:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377789AbjJIPwb (ORCPT ); Mon, 9 Oct 2023 11:52:31 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B79711F; Mon, 9 Oct 2023 08:52:19 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 4785A1C0012; Mon, 9 Oct 2023 15:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kiv+yxDSpeeBqHfOwRUQw3mS7Lf3CBbyGOYxIaD7WCE=; b=flLpiW9HxWrEEDJ3VIZB37TnzkKrjuWnVmK6tZ2Gb0w6wDpRpRSF3sEndafzvcQuVOmlRC hEKNJdrLeYWBSfbBiXX41cPeNyaN/RAzS6+Ljxv9NKPxXJWJN73kSoDL2chMfqMKVkIZM+ EwbQdtWes55EaDgUxRZyxoFGV7SJqZkn4fPL/FJzNQsL9JCLQsfNuoybXSpHYQLAY265LD 5gFIodeY3uiubSzmSzaeowfU4PWwaLz1i3/ynePtC0brzvAzyu3VN14eg6FzWJC4CrCHoP +4nzddMNDP2+8px2jTy3wbAtjEQ1vUSxrg55QfMms59aH8B1i0PgeJ6gbGLMWg== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 09/16] netlink: specs: Introduce new netlink command to get current timestamp Date: Mon, 9 Oct 2023 17:51:31 +0200 Message-Id: <20231009155138.86458-10-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:52:58 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293782035970216 X-GMAIL-MSGID: 1779293782035970216 From: Kory Maincent Add a new commands allowing to get the current time stamping on a netdevice's link. Example usage : ./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do ts-get \ --json '{"header":{"dev-name":"eth0"}}' {'header': {'dev-index': 3, 'dev-name': 'eth0'}, 'ts-layer': 1} Signed-off-by: Kory Maincent --- Documentation/netlink/specs/ethtool.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 837b565577ca..49ee028e97ca 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -942,6 +942,16 @@ attribute-sets: - name: burst-tmr type: u32 + - + name: ts + attributes: + - + name: header + type: nest + nested-attributes: header + - + name: ts-layer + type: u32 operations: enum-model: directional @@ -1692,3 +1702,17 @@ operations: name: mm-ntf doc: Notification for change in MAC Merge configuration. notify: mm-get + - + name: ts-get + doc: Get current timestamp + + attribute-set: ts + + do: + request: + attributes: + - header + reply: + attributes: &ts + - header + - ts-layer From patchwork Mon Oct 9 15:51:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961744vqo; Mon, 9 Oct 2023 08:53:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEY7c/lg0/MK4sWLqA0A2Kz+vKB8lpS1f3P4f0p+glz/STY2fbcs6hr37cMxe4gIG0ReHu8 X-Received: by 2002:a17:902:dac1:b0:1c7:8783:8dae with SMTP id q1-20020a170902dac100b001c787838daemr14547134plx.17.1696866789288; Mon, 09 Oct 2023 08:53:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866789; cv=none; d=google.com; s=arc-20160816; b=dHVBcq5YICR2pUy7XGP4nlV3lstqxUczFhepQiz4v5L8TFj5zEEid/lM2LSfY6CZfG a/4qa0RIPAb+rob+DXv7JTBIi8bH4Pc5dzw0rFvQERllNoLS1S9oFsSeYUhechYXbG7L seGPg0P+74vjw8ZAFPFZjVxdyuoBmyVaHOiGeXeZ0v5sAehqeoj2BtvMJ8OK5XMHHZh8 V59tv0pr8EZQKg/CnlfuEZxkZvO1mTXWtQ6cNWExuUevgR8ODZkX+xMHrZdWGdiPEfXL DgtBtgac77coLVzHCvzNYk1PIcNb0YQCocDe6h37Uc+N3Q2xJ6pWLeT6PK6RzPWEqyYG Vduw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yV4hKBJdgMmXnstotwMwRXruLGjtxs7rLuaw1mB5g70=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=L/ykRxNTmQMS1WTamrULH7YPj5/3lM96FDoK83WDpusfO8CR9yt3x9NXdUeQgTJ9KV HkETh8XHCBWS5TuOW7tvaJ1Uv8ENKGjK1+Ag9OZQl5ZO/XJusSepAXhTPaXimktk8/7i 4uEgRpfFjN4KyS4Djb+nIpYBbUv91TQo1Wfecaef61fBl8rBinwCGUD7yFo6KuN3rmTH mhRrKSkNka7J9V6wS384LHCAzM13f4OPHZOhAZDPV0f7100GoVT8ZGsd2QVqczTqANJA nD6wlrhfili+hilMAZER/pSU6VPb+RSCV7rC6LskI1HYTr/tcBYbBEwZTHXGOXVNi+pY cAZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=c6W4bb+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id o6-20020a170902d4c600b001bb9375b349si10323697plg.536.2023.10.09.08.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=c6W4bb+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 75522801C1FA; Mon, 9 Oct 2023 08:53:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377709AbjJIPw4 (ORCPT + 18 others); Mon, 9 Oct 2023 11:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377834AbjJIPwj (ORCPT ); Mon, 9 Oct 2023 11:52:39 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 015A7100; Mon, 9 Oct 2023 08:52:23 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id DCE9A1C000A; Mon, 9 Oct 2023 15:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yV4hKBJdgMmXnstotwMwRXruLGjtxs7rLuaw1mB5g70=; b=c6W4bb+kMwa5ErL7BUWKWNTSsPV7LgXkozNDXMQRDJz+bEHViVF1wqyJ4AjJW22M3ZeJtB cpXJ+1oFvPbI9TMHzeEgLJk2YqW9c/7ciLxJQtHQSscghLDT1qdB9AqWWvPW8XSIZRIwbo aiD4xD04hOyrB3gmx6xdoKCyEQjoOn0qoJUY3CfAM82VTOkIRc1Trs49gH0ffOvWfW2wMh CCPMuihcN2a9myPRF1doghK6RBsJNQ/fUtS4bEdzRspPXlt1NEHDAryLQQDSNyOlI5Z1Ly 9jX+MC97xenfXIDfhbwa+8h6F+KCYjJyVFPMj/eIc06iVIQ6D2x6JalCdVzu7w== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 10/16] net: ethtool: Add a command to list available time stamping layers Date: Mon, 9 Oct 2023 17:51:32 +0200 Message-Id: <20231009155138.86458-11-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:06 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293790199801580 X-GMAIL-MSGID: 1779293790199801580 From: Kory Maincent Introduce a new netlink message that lists all available time stamping layers on a given interface. Signed-off-by: Kory Maincent --- Documentation/networking/ethtool-netlink.rst | 23 +++++++ include/uapi/linux/ethtool_netlink.h | 14 ++++ net/ethtool/netlink.c | 10 +++ net/ethtool/netlink.h | 1 + net/ethtool/ts.c | 72 ++++++++++++++++++++ 5 files changed, 120 insertions(+) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 644b3b764044..963a5aacac8d 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -226,6 +226,7 @@ Userspace to kernel: ``ETHTOOL_MSG_MM_GET`` get MAC merge layer state ``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters ``ETHTOOL_MSG_TS_GET`` get current timestamping + ``ETHTOOL_MSG_TS_LIST_GET`` list available timestampings ===================================== ================================= Kernel to userspace: @@ -270,6 +271,7 @@ Kernel to userspace: ``ETHTOOL_MSG_RSS_GET_REPLY`` RSS settings ``ETHTOOL_MSG_MM_GET_REPLY`` MAC merge layer status ``ETHTOOL_MSG_TS_GET_REPLY`` current timestamping + ``ETHTOOL_MSG_TS_LIST_GET_REPLY`` available timestampings ======================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device @@ -2016,6 +2018,26 @@ Kernel response contents: This command get the current timestamp layer. +TS_LIST_GET +========== + +Get the list of available timestampings. + +Request contents: + + ================================= ====== ==================== + ``ETHTOOL_A_TS_HEADER`` nested request header + ================================= ====== ==================== + +Kernel response contents: + + =========================== ====== ============================== + ``ETHTOOL_A_TS_HEADER`` nested reply header + ``ETHTOOL_A_TS_LIST_LAYER`` binary available timestampings + =========================== ====== ============================== + +This command lists all the possible timestamp layer available. + Request translation =================== @@ -2122,5 +2144,6 @@ are netlink only. n/a ``ETHTOOL_MSG_PLCA_GET_STATUS`` n/a ``ETHTOOL_MSG_MM_GET`` n/a ``ETHTOOL_MSG_MM_SET`` + n/a ``ETHTOOL_MSG_TSLIST_GET`` n/a ``ETHTOOL_MSG_TS_GET`` =================================== ===================================== diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index cb51136328cf..62b885d44d06 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -58,6 +58,7 @@ enum { ETHTOOL_MSG_MM_GET, ETHTOOL_MSG_MM_SET, ETHTOOL_MSG_TS_GET, + ETHTOOL_MSG_TS_LIST_GET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -111,6 +112,7 @@ enum { ETHTOOL_MSG_MM_GET_REPLY, ETHTOOL_MSG_MM_NTF, ETHTOOL_MSG_TS_GET_REPLY, + ETHTOOL_MSG_TS_LIST_GET_REPLY, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -989,6 +991,18 @@ enum { ETHTOOL_A_TS_MAX = (__ETHTOOL_A_TS_CNT - 1) }; +/* TS LIST LAYER */ + +enum { + ETHTOOL_A_TS_LIST_UNSPEC, + ETHTOOL_A_TS_LIST_HEADER, /* nest - _A_HEADER_* */ + ETHTOOL_A_TS_LIST_LAYER, /* array, u32 */ + + /* add new constants above here */ + __ETHTOOL_A_TS_LIST_CNT, + ETHTOOL_A_TS_LIST_MAX = (__ETHTOOL_A_TS_LIST_CNT - 1) +}; + /* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_VERSION 1 diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 561c0931d055..842c9db1531f 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -307,6 +307,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_MM_GET] = ðnl_mm_request_ops, [ETHTOOL_MSG_MM_SET] = ðnl_mm_request_ops, [ETHTOOL_MSG_TS_GET] = ðnl_ts_request_ops, + [ETHTOOL_MSG_TS_LIST_GET] = ðnl_ts_list_request_ops, }; static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) @@ -1138,6 +1139,15 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_ts_get_policy, .maxattr = ARRAY_SIZE(ethnl_ts_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_TS_LIST_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_ts_get_policy, + .maxattr = ARRAY_SIZE(ethnl_ts_get_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 1e6085198acc..ea8c312db3af 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -396,6 +396,7 @@ extern const struct ethnl_request_ops ethnl_plca_cfg_request_ops; extern const struct ethnl_request_ops ethnl_plca_status_request_ops; extern const struct ethnl_request_ops ethnl_mm_request_ops; extern const struct ethnl_request_ops ethnl_ts_request_ops; +extern const struct ethnl_request_ops ethnl_ts_list_request_ops; extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1]; extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1]; diff --git a/net/ethtool/ts.c b/net/ethtool/ts.c index cd33f057ee48..d52b9800dc3b 100644 --- a/net/ethtool/ts.c +++ b/net/ethtool/ts.c @@ -76,3 +76,75 @@ const struct ethnl_request_ops ethnl_ts_request_ops = { .reply_size = ts_reply_size, .fill_reply = ts_fill_reply, }; + +/* TS_LIST_GET */ +struct ts_list_reply_data { + struct ethnl_reply_data base; + u32 ts_layer[__TIMESTAMPING_COUNT]; + u8 num_ts; +}; + +#define TS_LIST_REPDATA(__reply_base) \ + container_of(__reply_base, struct ts_list_reply_data, base) + +static int ts_list_prepare_data(const struct ethnl_req_info *req_base, + struct ethnl_reply_data *reply_base, + const struct genl_info *info) +{ + struct ts_list_reply_data *data = TS_LIST_REPDATA(reply_base); + struct net_device *dev = reply_base->dev; + const struct ethtool_ops *ops = dev->ethtool_ops; + struct ethtool_ts_info ts_info = {0}; + int ret, i = 0; + + ret = ethnl_ops_begin(dev); + if (ret < 0) + return ret; + + if (phy_has_tsinfo(dev->phydev)) + data->ts_layer[i++] = PHYLIB_TIMESTAMPING; + if (ops->get_ts_info) { + ops->get_ts_info(dev, &ts_info); + if (ts_info.so_timestamping & + SOF_TIMESTAMPING_HARDWARE_MASK) + data->ts_layer[i++] = NETDEV_TIMESTAMPING; + + if (ts_info.so_timestamping & + SOF_TIMESTAMPING_SOFTWARE_MASK) + data->ts_layer[i++] = SOFTWARE_TIMESTAMPING; + } + + data->num_ts = i; + ethnl_ops_complete(dev); + + return ret; +} + +static int ts_list_reply_size(const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + struct ts_list_reply_data *data = TS_LIST_REPDATA(reply_base); + + return nla_total_size(sizeof(u32)) * data->num_ts; +} + +static int ts_list_fill_reply(struct sk_buff *skb, + const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + struct ts_list_reply_data *data = TS_LIST_REPDATA(reply_base); + + return nla_put(skb, ETHTOOL_A_TS_LIST_LAYER, sizeof(u32) * data->num_ts, data->ts_layer); +} + +const struct ethnl_request_ops ethnl_ts_list_request_ops = { + .request_cmd = ETHTOOL_MSG_TS_LIST_GET, + .reply_cmd = ETHTOOL_MSG_TS_LIST_GET_REPLY, + .hdr_attr = ETHTOOL_A_TS_HEADER, + .req_info_size = sizeof(struct ts_req_info), + .reply_data_size = sizeof(struct ts_list_reply_data), + + .prepare_data = ts_list_prepare_data, + .reply_size = ts_list_reply_size, + .fill_reply = ts_list_fill_reply, +}; From patchwork Mon Oct 9 15:51:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961952vqo; Mon, 9 Oct 2023 08:53:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZcsWPiy8ZodVZMgZvFm0IS5qiPinUxBDMgvCsPbVOgnFSF0rLh88A1YD832vW1zsZSWOU X-Received: by 2002:a05:6358:7245:b0:134:ec9d:ef18 with SMTP id i5-20020a056358724500b00134ec9def18mr19777408rwa.28.1696866807538; Mon, 09 Oct 2023 08:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866807; cv=none; d=google.com; s=arc-20160816; b=EvuSCLz1tvLtrBBtnMLh8z0c/8AoiHNgseDe1ggwlC5bE9WF8PdWkzgjkYIT4Fd/se TS0oOdzfmN/3TqNFkH/AWnQuMOKrwpz/EtUnfFd5bQ2prdugUZiMvJ0HPtdnFZSFdtn4 Lo3tCWTozsgN5uQgkzuZa7Rlrd9T7ntdWNoSquoveP8vRbV5MKARhKA7LiLNGBYq3put kEQAC0xDDNWffGoEldB1wYwOPrtedJhi5rbjaxexR/tVP3frHVmCyEX2Sj4dlB86ppKX lK1zY0b0szDYtUWprgei87pXZVkKQCdVOoQrRNBphewOEL+HpyTi6i6bRnJ1gq0STlo9 L+bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bNVv7aXW4R7kMn/Y3UYMw4xmcy2L8JPMN/pu3cSuY3s=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=myr1rnATeEcpCLxAMVNDsKDPVcXtDQ70dPlw1GrKajQNLY7ohdU3ehCFVa+p15D/9p PxGz5p45YsUSojG2znPr07GciPKcQcwoJeb5V1nsT7jndbvRvS/sgW8dw3MCmyNqXJCg v7v7MK7MgleKwk0j1xsrfvZpMWlXyPkMDTWbMHBC4WaesR/dHJ6s2oPIQ8NmNXzZlC5n MiVSGV4qb2qP4PaIvX2KL9klyu9TxLcTwnQIgYIjxOeGNMqxGepSMhK2ee2JE+2dwzQ/ 543c+pm50OAim+rEpriZHh+7kSucm3sx464dakCCRptGVedb4DqlgP4qwfZNG9Lt/1Jy /CLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=JjlwVlqY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id be3-20020a656e43000000b00582f1f73c80si10122399pgb.466.2023.10.09.08.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=JjlwVlqY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8F8A78028FB1; Mon, 9 Oct 2023 08:53:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377909AbjJIPxB (ORCPT + 18 others); Mon, 9 Oct 2023 11:53:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377790AbjJIPwk (ORCPT ); Mon, 9 Oct 2023 11:52:40 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA40A1A3; Mon, 9 Oct 2023 08:52:27 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id B2ED11C000C; Mon, 9 Oct 2023 15:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bNVv7aXW4R7kMn/Y3UYMw4xmcy2L8JPMN/pu3cSuY3s=; b=JjlwVlqY62tsqrxerlPjaYNBSUO/s2YW9hVsPmrHUS2t5FPVwdtp6Gn2F0bnn002sdbX+m QsrZNFrpxVJneMTAuaO7lL5Wclo2wQCfl123smr01R1PGWxBv1zM/WWTR5lh545hx10/OY d7WFEjOeRgpEAwMaXsDhNKVZrkVAaOVMoouA6z704JeJrpIVL+TTK8eUp9JVYIIPw2jL7F 8ne0Zb87q04AMjAVz2gvGpCjjaWrvyWNIVvkOgy8qnf9xdtashqfR8dabEQHR6G7uGelW6 pxQAyPw3Ql6JPFztGPxQ32ezr+9o8+PF/FyYYk3yc9IwIXyJB021OzEJ9btAgQ== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 11/16] netlink: specs: Introduce new netlink command to list available time stamping layers Date: Mon, 9 Oct 2023 17:51:33 +0200 Message-Id: <20231009155138.86458-12-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:20 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293809518502903 X-GMAIL-MSGID: 1779293809518502903 From: Kory Maincent Add a new commands allowing to list available time stamping layers on a netdevice's link. Example usage : ./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema \ --do ts-list-get \ --json '{"header":{"dev-name":"eth0"}}' {'header': {'dev-index': 3, 'dev-name': 'eth0'}, 'ts-list-layer': b'\x01\x00\x00\x00\x05\x00\x00\x00'} Signed-off-by: Kory Maincent --- Documentation/netlink/specs/ethtool.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 49ee028e97ca..81ed8e5f2f55 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -952,6 +952,16 @@ attribute-sets: - name: ts-layer type: u32 + - + name: ts-list + attributes: + - + name: header + type: nest + nested-attributes: header + - + name: ts-list-layer + type: binary operations: enum-model: directional @@ -1716,3 +1726,17 @@ operations: attributes: &ts - header - ts-layer + - + name: ts-list-get + doc: Get list of timestamp devices available on an interface + + attribute-set: ts-list + + do: + request: + attributes: + - header + reply: + attributes: + - header + - ts-list-layer From patchwork Mon Oct 9 15:51:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150186 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961921vqo; Mon, 9 Oct 2023 08:53:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJ6D6y4sE47SKpK5BdjMy3cKsbIAn4d4+77qc6dGTPx6zq+zr+9d2snMaut8FhSA3lRCJ3 X-Received: by 2002:a9d:6d03:0:b0:6bf:3f4:3edc with SMTP id o3-20020a9d6d03000000b006bf03f43edcmr16081543otp.22.1696866804614; Mon, 09 Oct 2023 08:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866804; cv=none; d=google.com; s=arc-20160816; b=aqBwz8Qqi2hkE3/bD4NBs4qsXcGSe3n005uD01ahrTkjBdCSfrANJnnvHWY4dnUXv3 91DnJCNm5fS0BOhpDJlXeXjhrZHpaftTgtFUtxvaYInrZq+BWJabQEqJG4+k8t1JnTFU ygIkC9jwf9/yh/oRNn/ec7l4i3zlk0hbtSQDV602N2X/Im8GJsgo4AWBe5Ld7iYYXzz0 PFd5kxChSEa6paGGIkM+MS3Jem3yfWT749rUSkGQ6O3z+n9SBjIoCDtuUmw0xMVZmfFJ Q4RIr3HazkgVdD+5Di88F2TN6SbZtkrvFPxp7rzio6IzubaHZBjLQwzriBHZIDDRFRUj 12/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wPtxSHc5kpsl/meOkJ1+JSY5q157KHdOe13rw3OA8+0=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=ExH+U9SuEEVC0Ym9U5+9jf+uFcOx6NuXvVUrN0hOJ2l/GBEb1aQcZv0ZR6BgiFpF4C QSByPG72DGH7bhVg0BLJYMCtMqwD8rHZSBhJvm6+9dY9q42xaxTR49IcpoCT+52wHjaT cfkallKOHtXelGQ1kUlFVh0XUOnEQn9hJ7G5baPilRXwoE6JslibTzh5U1+aTyrkKkcy 9fpEokcx4FzB+ZZvGWZQAHKXpS+Mm9+xFshDUd9zxFk2tcTz4Ta5vN9u9p59Y0g3+3Ke L9rXLvEiAKCXV0hWKya2JAOstw988Qy3vdLClP8v6T/moGdZ0JqbVN9xQIa9+3BvQ07I M1hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=S9mkSIlo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b00563f627f2ecsi9842895pgv.13.2023.10.09.08.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=S9mkSIlo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 7F8C081113A7; Mon, 9 Oct 2023 08:53:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377851AbjJIPxG (ORCPT + 18 others); Mon, 9 Oct 2023 11:53:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377841AbjJIPwm (ORCPT ); Mon, 9 Oct 2023 11:52:42 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39ABD195; Mon, 9 Oct 2023 08:52:32 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 63CAF1C0015; Mon, 9 Oct 2023 15:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wPtxSHc5kpsl/meOkJ1+JSY5q157KHdOe13rw3OA8+0=; b=S9mkSIlotahwxWU9oQA5FxOoPRbeOFzGDpQ38dPwB/Kk4+rqUW7rqapQjM2qXwIYTW4BOO FQszwaQs0qNkOYVscGZqPrf3NUgInpbJZiNNvj+8OykOuSSezkjuBp2Owri6C0bj3iMqO+ AWE194HSvw/YVU6A3Qu8D3Ll1dUiBUC1tZipz0/KVwjyJtGPZobnMXhikePrqH81wlJ9gj hPz8AruBd2izW/0D7IzEB3PfnAx8mKI9sczK84voEqoEv8uMiaxCeULSxFEFCehJhE9ZIs AGxYJF2c7zVn4mLzjrI1p59MHMwpTclEhgqbazwja9/jv7xbt6CT8czXUQb1IA== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 12/16] net: Replace hwtstamp_source by timestamping layer Date: Mon, 9 Oct 2023 17:51:34 +0200 Message-Id: <20231009155138.86458-13-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:21 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293806309957294 X-GMAIL-MSGID: 1779293806309957294 From: Kory Maincent Replace hwtstamp_source which is only used by the kernel_hwtstamp_config structure by the more widely use timestamp_layer structure. This is done to prepare the support of selectable timestamping source. Signed-off-by: Kory Maincent --- drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 6 +++--- include/linux/net_tstamp.h | 11 +++-------- net/core/dev_ioctl.c | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 8e4101628fbd..83c1177469e2 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -470,15 +470,15 @@ static int lan966x_port_hwtstamp_set(struct net_device *dev, struct lan966x_port *port = netdev_priv(dev); int err; - if (cfg->source != HWTSTAMP_SOURCE_NETDEV && - cfg->source != HWTSTAMP_SOURCE_PHYLIB) + if (cfg->source != NETDEV_TIMESTAMPING && + cfg->source != PHYLIB_TIMESTAMPING) return -EOPNOTSUPP; err = lan966x_ptp_setup_traps(port, cfg); if (err) return err; - if (cfg->source == HWTSTAMP_SOURCE_NETDEV) { + if (cfg->source == NETDEV_TIMESTAMPING) { if (!port->lan966x->ptp) return -EOPNOTSUPP; diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h index eb01c37e71e0..2c1af19d5421 100644 --- a/include/linux/net_tstamp.h +++ b/include/linux/net_tstamp.h @@ -5,11 +5,6 @@ #include -enum hwtstamp_source { - HWTSTAMP_SOURCE_NETDEV, - HWTSTAMP_SOURCE_PHYLIB, -}; - /** * struct kernel_hwtstamp_config - Kernel copy of struct hwtstamp_config * @@ -20,8 +15,8 @@ enum hwtstamp_source { * a legacy implementation of a lower driver * @copied_to_user: request was passed to a legacy implementation which already * copied the ioctl request back to user space - * @source: indication whether timestamps should come from the netdev or from - * an attached phylib PHY + * @source: indication whether timestamps should come from software, the netdev + * or from an attached phylib PHY * * Prefer using this structure for in-kernel processing of hardware * timestamping configuration, over the inextensible struct hwtstamp_config @@ -33,7 +28,7 @@ struct kernel_hwtstamp_config { int rx_filter; struct ifreq *ifr; bool copied_to_user; - enum hwtstamp_source source; + u32 source; }; static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg, diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 342a667858ac..45cc1ea9b195 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -332,7 +332,7 @@ int dev_set_hwtstamp_phylib(struct net_device *dev, bool changed = false; int err; - cfg->source = phy_ts ? HWTSTAMP_SOURCE_PHYLIB : HWTSTAMP_SOURCE_NETDEV; + cfg->source = phy_ts ? PHYLIB_TIMESTAMPING : NETDEV_TIMESTAMPING; if (phy_ts && (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) { err = ops->ndo_hwtstamp_get(dev, &old_cfg); From patchwork Mon Oct 9 15:51:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1962161vqo; Mon, 9 Oct 2023 08:53:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeSrQ8Gr1pinKiN8TtfufZ+106cdAcBa9px+XSBiTw9Wc0s0j+UWQsFelg5Khwcrp5cEoL X-Received: by 2002:a17:90a:850b:b0:274:3d7d:e793 with SMTP id l11-20020a17090a850b00b002743d7de793mr12836496pjn.47.1696866831989; Mon, 09 Oct 2023 08:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866831; cv=none; d=google.com; s=arc-20160816; b=YlMLh3mGrlamMQquAyDik51JlWZ+7gZjC5Lnk2Nw0OVRo3CnO3NZap38GNtE56ERRM tMDcVJR/6sVLEyh2IteqeX7/7YcKHCMKFFksqw1obH8p/pKa2+fUjORl7F2IvgYCPqmA H0q7D3ku8M9eK1Ul802ur+UCuYUUvf/e/R2XzR4lxYjDOhRzh6t1pMbrTPK1ApKmbtDN HDstrEzgieqB2UNZDyAIirz/5TDyjukLlhuur66IZT7xj10xlkvYD333BrQclNMgL7V6 6C2pf8fmqWKfwcrgzPDGOC4MNxfYmelAmkiP25ByXDyM8f0cMji33Kk8zaY7LcnRBaRu 4Jcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iQjM6ChqEsCv4tSv5WLWYJR8cO93SncXZdpKtRJANL0=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=FVv1fyTvr2Xte3ricXFf6UUWAnf1zXNxQhc1GJsXFWgRDM0ggaFV4f56QlRK/sf6mo UXXXS4oKwhKTd5rm/KKJXDKfuTN2fuy19i8bgAXFb/MHk8gxUtMC2WNfP1M+KGeIipRu osV5waXNW/ZTToFdcDN6Bzta4AXLKNOcmToaiAALhB+cjFtL8iAsc1ssbGjWkZmvWAto WkdALDWyyqo0zEeMi6c0klOPfPuhv5xARicc9PFI4XabxT+RbqZ+titEkpSYD7axia8s xmroooeK+IkWr9DqLUhWBPu4+RpTdCSC+5ypTnpsxdY0V+qNNHp6jud1N9WdqF0dWbeo T9Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=hq9Z5SYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id e6-20020a17090a4a0600b0027901ee93fbsi11236451pjh.156.2023.10.09.08.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=hq9Z5SYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 432E581113BE; Mon, 9 Oct 2023 08:53:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377934AbjJIPxP (ORCPT + 18 others); Mon, 9 Oct 2023 11:53:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377871AbjJIPwq (ORCPT ); Mon, 9 Oct 2023 11:52:46 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A84D5B; Mon, 9 Oct 2023 08:52:35 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id C1AD31C0008; Mon, 9 Oct 2023 15:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866754; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iQjM6ChqEsCv4tSv5WLWYJR8cO93SncXZdpKtRJANL0=; b=hq9Z5SYqgIU+6U0H+Rc2V7reHCBYxcV+n+KzVYKVJE562HkjyqVAvvPqCnMj1MGWUIhmL7 /XAmFAEQskJ/EPKpb+z16k5pLcpFCQgJiKp7KH/3r3qOqpydiLGh4t/G3yfqm1MgzXW4rX rQ/rXF+A0op8mP2dS9u5/npNjLHAkhnAhEO8zZtzAESPpIIQ0O5IXNanwn3SAC9qcyaKqC uLrE1QjGqqo2Isq/QMCoyEtU8/P+b3chDfiQQWBR0qMZ5IzM4HZNzfJ9GkmuMSu4Id3eLL ykTAZUOlm4UdpA6VpfdAIuS46SSNBhcEnmfDfbx6q1Nh2VeMgGVHs6WXwbhKVg== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 13/16] net: Change the API of PHY default timestamp to MAC Date: Mon, 9 Oct 2023 17:51:35 +0200 Message-Id: <20231009155138.86458-14-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:48 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293835383254756 X-GMAIL-MSGID: 1779293835383254756 From: Kory Maincent Change the API to select MAC default time stamping instead of the PHY. Indeed the PHY is closer to the wire therefore theoretically it have 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 board are not very widespread. For not breaking the compatibility I introduce an allowlist to reference all current PHYs that support time stamping and let them keep the old API behavior. The phy_set_timestamp function is called at each call of phy_attach_direct. In case of MAC driver using phylink this function is called when the interface is turned up. Then if the interface goes down and up again the last choice of timestamp will be overwritten by the default choice. A solution could be to cache the timestamp status but it can bring other issues. In case of SFP, if we change the module, it doesn't make sense to blindly re-set the timestamp back to PHY, if the new module has a PHY with mediocre timestamping capabilities. Signed-off-by: Kory Maincent --- Changes in v5: - Extract the API change in this patch. - Rename whitelist to allowlist. - Set NETDEV_TIMESTAMPING in register_netdevice function. - Add software timestamping case description in ts_info. --- drivers/net/phy/phy_device.c | 68 ++++++++++++++++++++++++++++++++++++ include/linux/netdevice.h | 5 +++ net/core/dev.c | 3 ++ net/core/dev_ioctl.c | 36 +++++++++++-------- net/core/timestamping.c | 9 +++++ net/ethtool/common.c | 16 +++++++-- 6 files changed, 121 insertions(+), 16 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2ce74593d6e4..2d5a6d57acb3 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1411,6 +1411,68 @@ int phy_sfp_probe(struct phy_device *phydev, } EXPORT_SYMBOL(phy_sfp_probe); +/* An allowlist for PHYs selected as default timesetamping. + * Its use is to keep compatibility with old PTP API which is selecting + * these PHYs as default timestamping. + * The new API is selecting the MAC as default timestamping. + */ +const char * const phy_timestamping_allowlist[] = { + "Broadcom BCM5411", + "Broadcom BCM5421", + "Broadcom BCM54210E", + "Broadcom BCM5461", + "Broadcom BCM54612E", + "Broadcom BCM5464", + "Broadcom BCM5481", + "Broadcom BCM54810", + "Broadcom BCM54811", + "Broadcom BCM5482", + "Broadcom BCM50610", + "Broadcom BCM50610M", + "Broadcom BCM57780", + "Broadcom BCM5395", + "Broadcom BCM53125", + "Broadcom BCM53128", + "Broadcom BCM89610", + "NatSemi DP83640", + "Microchip LAN8841 Gigabit PHY", + "Microchip INDY Gigabit Quad PHY", + "Microsemi GE VSC856X SyncE", + "Microsemi GE VSC8575 SyncE", + "Microsemi GE VSC8582 SyncE", + "Microsemi GE VSC8584 SyncE", + "NXP C45 TJA1103", + NULL, +}; + +/** + * phy_set_timestamp - set the default selected timestamping device + * @dev: Pointer to net_device + * @phydev: Pointer to phy_device + * + * This is used to set default timestamping device taking into account + * the new API choice, which is selecting the timestamping from MAC by + * default. + */ +static void phy_set_timestamp(struct net_device *dev, struct phy_device *phydev) +{ + const struct ethtool_ops *ops = dev->ethtool_ops; + int i; + + /* Backward compatibility to old timestamping API */ + for (i = 0; phy_timestamping_allowlist[i]; i++) { + if (!strcmp(phy_timestamping_allowlist[i], + phydev->drv->name)) { + if (phy_has_tsinfo(phydev)) + dev->ts_layer = PHYLIB_TIMESTAMPING; + return; + } + } + + if (phy_has_tsinfo(phydev) && !ops->get_ts_info) + dev->ts_layer = PHYLIB_TIMESTAMPING; +} + /** * phy_attach_direct - attach a network device to a given PHY device pointer * @dev: network device to attach @@ -1484,6 +1546,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, phydev->phy_link_change = phy_link_change; if (dev) { + phy_set_timestamp(dev, phydev); phydev->attached_dev = dev; dev->phydev = phydev; @@ -1794,6 +1857,7 @@ EXPORT_SYMBOL_GPL(devm_phy_package_join); void phy_detach(struct phy_device *phydev) { struct net_device *dev = phydev->attached_dev; + const struct ethtool_ops *ops = dev->ethtool_ops; struct module *ndev_owner = NULL; struct mii_bus *bus; @@ -1812,6 +1876,10 @@ void phy_detach(struct phy_device *phydev) phy_suspend(phydev); if (dev) { + if (ops->get_ts_info) + dev->ts_layer = NETDEV_TIMESTAMPING; + else + dev->ts_layer = NO_TIMESTAMPING; phydev->attached_dev->phydev = NULL; phydev->attached_dev = NULL; } diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index b9d0411836db..4e1d01120511 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -2054,6 +2055,8 @@ enum netdev_ml_priv_type { * * @dpll_pin: Pointer to the SyncE source pin of a DPLL subsystem, * where the clock is recovered. + * @ts_layer: Tracks which network device + * performs packet time stamping. * * FIXME: cleanup struct net_device such that network protocol info * moves out. @@ -2415,6 +2418,8 @@ struct net_device { #if IS_ENABLED(CONFIG_DPLL) struct dpll_pin *dpll_pin; #endif + + u32 ts_layer; }; #define to_net_dev(d) container_of(d, struct net_device, dev) diff --git a/net/core/dev.c b/net/core/dev.c index 606a366cc209..1d4890dee114 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10204,6 +10204,9 @@ int register_netdevice(struct net_device *dev) dev->rtnl_link_state == RTNL_LINK_INITIALIZED) rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U, GFP_KERNEL, 0, NULL); + if (dev->ethtool_ops->get_ts_info) + dev->ts_layer = NETDEV_TIMESTAMPING; + out: return ret; diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 45cc1ea9b195..20009462fa24 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -259,9 +259,7 @@ static int dev_eth_ioctl(struct net_device *dev, * @dev: Network device * @cfg: Timestamping configuration structure * - * Helper for enforcing a common policy that phylib timestamping, if available, - * should take precedence in front of hardware timestamping provided by the - * netdev. + * Helper for calling the selected hardware provider timestamping. * * Note: phy_mii_ioctl() only handles SIOCSHWTSTAMP (not SIOCGHWTSTAMP), and * there only exists a phydev->mii_ts->hwtstamp() method. So this will return @@ -271,10 +269,14 @@ static int dev_eth_ioctl(struct net_device *dev, static int dev_get_hwtstamp_phylib(struct net_device *dev, struct kernel_hwtstamp_config *cfg) { - if (phy_has_hwtstamp(dev->phydev)) + u32 ts_layer = dev->ts_layer; + + if (ts_layer & PHYLIB_TIMESTAMPING) return phy_hwtstamp_get(dev->phydev, cfg); + else if (ts_layer & NETDEV_TIMESTAMPING) + return dev->netdev_ops->ndo_hwtstamp_get(dev, cfg); - return dev->netdev_ops->ndo_hwtstamp_get(dev, cfg); + return -EOPNOTSUPP; } static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) @@ -315,9 +317,8 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) * @cfg: Timestamping configuration structure * @extack: Netlink extended ack message structure, for error reporting * - * Helper for enforcing a common policy that phylib timestamping, if available, - * should take precedence in front of hardware timestamping provided by the - * netdev. If the netdev driver needs to perform specific actions even for PHY + * Helper for calling the selected hardware provider timestamping. + * If the netdev driver needs to perform specific actions even for PHY * timestamping to work properly (a switch port must trap the timestamped * frames and not forward them), it must set IFF_SEE_ALL_HWTSTAMP_REQUESTS in * dev->priv_flags. @@ -327,20 +328,26 @@ 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_has_hwtstamp(dev->phydev); struct kernel_hwtstamp_config old_cfg = {}; + u32 ts_layer = dev->ts_layer; bool changed = false; int err; - cfg->source = phy_ts ? PHYLIB_TIMESTAMPING : NETDEV_TIMESTAMPING; + cfg->source = ts_layer; + + if (!(ts_layer & PHYLIB_TIMESTAMPING) && + !(ts_layer & NETDEV_TIMESTAMPING)) + return -EOPNOTSUPP; - if (phy_ts && (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) { + if ((ts_layer & PHYLIB_TIMESTAMPING) && + (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) { err = ops->ndo_hwtstamp_get(dev, &old_cfg); if (err) return err; } - if (!phy_ts || (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) { + if ((ts_layer & NETDEV_TIMESTAMPING) || + (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) { err = ops->ndo_hwtstamp_set(dev, cfg, extack); if (err) { if (extack->_msg) @@ -349,10 +356,11 @@ int dev_set_hwtstamp_phylib(struct net_device *dev, } } - if (phy_ts && (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) + if ((ts_layer & PHYLIB_TIMESTAMPING) && + (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) changed = kernel_hwtstamp_config_changed(&old_cfg, cfg); - if (phy_ts) { + if (ts_layer & PHYLIB_TIMESTAMPING) { err = phy_hwtstamp_set(dev->phydev, cfg, extack); if (err) { if (changed) diff --git a/net/core/timestamping.c b/net/core/timestamping.c index 04840697fe79..4638b2fb0dbc 100644 --- a/net/core/timestamping.c +++ b/net/core/timestamping.c @@ -21,6 +21,7 @@ static unsigned int classify(const struct sk_buff *skb) void skb_clone_tx_timestamp(struct sk_buff *skb) { + u32 ts_layer = skb->dev->ts_layer; struct mii_timestamper *mii_ts; struct sk_buff *clone; unsigned int type; @@ -28,6 +29,9 @@ void skb_clone_tx_timestamp(struct sk_buff *skb) if (!skb->sk) return; + if (!(ts_layer & PHYLIB_TIMESTAMPING)) + return; + type = classify(skb); if (type == PTP_CLASS_NONE) return; @@ -46,10 +50,15 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb) { struct mii_timestamper *mii_ts; unsigned int type; + u32 ts_layer; if (!skb->dev || !skb->dev->phydev || !skb->dev->phydev->mii_ts) return false; + ts_layer = skb->dev->ts_layer; + if (!(ts_layer & PHYLIB_TIMESTAMPING)) + return false; + if (skb_headroom(skb) < ETH_HLEN) return false; diff --git a/net/ethtool/common.c b/net/ethtool/common.c index e2315e24d695..54a2acc20af0 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -633,13 +633,25 @@ int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) { const struct ethtool_ops *ops = dev->ethtool_ops; struct phy_device *phydev = dev->phydev; + u32 ts_layer = dev->ts_layer; + int ret; memset(info, 0, sizeof(*info)); info->cmd = ETHTOOL_GET_TS_INFO; - if (phy_has_tsinfo(phydev)) + if (ts_layer == SOFTWARE_TIMESTAMPING) { + ret = ops->get_ts_info(dev, info); + if (ret) + return ret; + info->so_timestamping &= ~SOF_TIMESTAMPING_HARDWARE_MASK; + info->phc_index = -1; + return ret; + } + + if (ts_layer & PHYLIB_TIMESTAMPING) return phy_ts_info(phydev, info); - if (ops->get_ts_info) + + if (ts_layer & NETDEV_TIMESTAMPING) return ops->get_ts_info(dev, info); info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | From patchwork Mon Oct 9 15:51:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150185 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1961911vqo; Mon, 9 Oct 2023 08:53:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbOMjlB8WWU95P91w6OgCnm9uwlzEElH6koRLEX3BY62FEKveMVnJHNLYqijlEABefJ/OM X-Received: by 2002:a17:903:1207:b0:1c0:bcbc:d64 with SMTP id l7-20020a170903120700b001c0bcbc0d64mr15821298plh.51.1696866803368; Mon, 09 Oct 2023 08:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866803; cv=none; d=google.com; s=arc-20160816; b=h8loTOQxrG3MfHvxx7BY1uUXBIH6AsFS1HOsh1LjJwQEQ11IPgv9hdMcbqKZhWa731 1nmdWWXRjRvACcPrW9G+g03Uht7JbBlo+X0246rGRc4x5RVFGWvmgHx2xs8Eu2c6iQXr DPYkwU0996MHGLKnNrXDxrXVHaE/+TKVQnaCtlgEpYjPw06xfOX61jfr0RX6Q8rRjC12 Xc/IBtKHtgJ9B/RUP6DIg3DQ6mJk8xXemawzYehNjjijARqvzgtidrEvuex6TO7K5lwk 4mQJb/2jkP++oaIb5e+dh13fCvrrCp5K7LR4Wu1VGDAeulx388jP6/rUxgYabQyDxaw1 hQog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=avXVQPWzRJKUhJQzpKYOLVnENRQVKEA8nP3k0T3jh3I=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=CUGa8erHsz3Aqei6LLsHYlneEbDRAXBlAKTcRyEVGxu+/nv3Wudvpsh4xrGwjZppxd lEe8FViG10JsHjbcG50pdpg4ZtwLuHaUPPvZmyCNC5F2ZwmHd5IGDP61HsFpmqXhfG0M eAunEQpivr/QBQZIxuy48l3mfMW5fODt8Vqy1fLWNde/HDrGGa8ScHazhqJOdJ1F4+H5 uJKVKw8OhjN97TqM25aRoOUn+kVGtVQSVNfrvPSEFAPbI+llFXJ0lbKinHtPrB8dJ7VC cyzcwpv81cmOn1aa779gDNl4tc9AG6cc78o4SFP+Yd5rCjHhk5mhlSNqEslar81d5ocl F4gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=cbA2yog8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g11-20020a1709026b4b00b001c426636990si9380696plt.637.2023.10.09.08.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=cbA2yog8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C116D80212B2; Mon, 9 Oct 2023 08:53:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377896AbjJIPxS (ORCPT + 18 others); Mon, 9 Oct 2023 11:53:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377736AbjJIPwq (ORCPT ); Mon, 9 Oct 2023 11:52:46 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD3B2D66; Mon, 9 Oct 2023 08:52:38 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id B1B211C0007; Mon, 9 Oct 2023 15:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866757; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=avXVQPWzRJKUhJQzpKYOLVnENRQVKEA8nP3k0T3jh3I=; b=cbA2yog8qte67ALWuIDXHSzTxUSM9wkWBe/7C3EHiU+dPm+Bhz4XqsacPYmU7AdP41Weda TS8f9rrY7wZHFp/ScZ9EraBdBX0CUbYoZmC2YTNFLVBwAD6QvFuILsX3N17V6LqLYwcbva w73cnIqSKkuGFLxmwksQQJm1fPAobCbFhy8fzEHh+dTCPymsOpln6j6BOvs9swWtWbrOdP 9YzX8pX/j9SO3RfrFVopT9KogbGWvPEzCk5/Uu7v0ZCoCEl4b8wsYHbazrCCo3xWFYeKie spQjEY65/IJN1r+JIb98mGJQqBBKR1Zlk6r8mWzHMkVFZY7Wvo8yy3jqIbVQcQ== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 14/16] net: ethtool: ts: Update GET_TS to reply the current selected timestamp Date: Mon, 9 Oct 2023 17:51:36 +0200 Message-Id: <20231009155138.86458-15-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293805241852294 X-GMAIL-MSGID: 1779293805241852294 From: Kory Maincent As the default selected timestamp API change we have to change also the timestamp return by ethtool. This patch return now the current selected timestamp. Signed-off-by: Kory Maincent --- net/ethtool/ts.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/net/ethtool/ts.c b/net/ethtool/ts.c index d52b9800dc3b..11041a16de5b 100644 --- a/net/ethtool/ts.c +++ b/net/ethtool/ts.c @@ -31,19 +31,13 @@ static int ts_prepare_data(const struct ethnl_req_info *req_base, { struct ts_reply_data *data = TS_REPDATA(reply_base); struct net_device *dev = reply_base->dev; - const struct ethtool_ops *ops = dev->ethtool_ops; int ret; ret = ethnl_ops_begin(dev); if (ret < 0) return ret; - if (phy_has_tsinfo(dev->phydev)) - data->ts_layer = PHYLIB_TIMESTAMPING; - else if (ops->get_ts_info) - data->ts_layer = NETDEV_TIMESTAMPING; - else - data->ts_layer = NO_TIMESTAMPING; + data->ts_layer = dev->ts_layer; ethnl_ops_complete(dev); From patchwork Mon Oct 9 15:51:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1962101vqo; Mon, 9 Oct 2023 08:53:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwfsWoXb/P8L2AS9GV415a7DeMFGX1CoX+raESGBWelo3Srystc/lIHZNtkIqQKbKIAY1J X-Received: by 2002:a05:6a20:da8b:b0:16c:1340:c621 with SMTP id iy11-20020a056a20da8b00b0016c1340c621mr12160082pzb.31.1696866825258; Mon, 09 Oct 2023 08:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866825; cv=none; d=google.com; s=arc-20160816; b=j8uT4oiTdI2/WsU8aXhd7YJbpsMnokhwrBUivMsmO+17cW0FkL4TCUnVFdO+4a/5Hk UBF6myQCPgCJQqDb7UtlF4BdRi6HjEm724ejXvdbL8gu3EJebzDkJ+jxWWoVGQEiD6OJ C6d25DVQlcB77c1RJB6K1WNWneBgtv/BBwf3rIKVVLzMZ7TZmjqbviNVV0PTlMFAtUCq DWV9hLjq2fJvii/zfJzNwZgTcZDjl6T1dR5Zmevf7dcwVepWSA/K0sHrUwZGFLKSucpL WDZy8XbpuNixk/eUjKtI3z91Xs50rD+a2WmaWjjEXb9GOLUtjvQ8lWpIMhBu56N1mCqf S71g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CgULFTUHlUTSGRTnQAcEagfNudUgdqfksLwVg++GkDw=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=vJVDssYE+W2VmnufU4y1JrE3Pktmyvpr4DjcSY1hf/EwJ3BJ8v4WNtO6rPVD2jJhsV kb7/PURL4r6Pkf7MrX016bw8P3FMe9hF6J+QuzjlVir4s+5GQzPETt4NC2iSY55yvy4b m+XdSxHtsc62XKLCqzHs6cdIWyoFAiGIcvr2yEwWxvEVNIphhCoSQdmaA/HZoBmQbxwz mFUELxZqYSlN5G2k/32lRDkVX4uMalGIqPPlfy8TBvmHSc8u8sHIiF0YcqkvNW2c1uv0 tiAwe3IiMUPZWn78504AT6pgz5oNwxhjblEBPCiqGJ3LYnWAROi5htVCsGpUT701xmwf yVlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="JBjcLgs/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id k4-20020a6555c4000000b00578c914490bsi10180976pgs.494.2023.10.09.08.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:53:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="JBjcLgs/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 9480380C4D50; Mon, 9 Oct 2023 08:53:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377015AbjJIPxX (ORCPT + 18 others); Mon, 9 Oct 2023 11:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377950AbjJIPw5 (ORCPT ); Mon, 9 Oct 2023 11:52:57 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D170D6; Mon, 9 Oct 2023 08:52:41 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id B72A51C0002; Mon, 9 Oct 2023 15:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CgULFTUHlUTSGRTnQAcEagfNudUgdqfksLwVg++GkDw=; b=JBjcLgs/U/sLIEF9UEPx1eGtTQOo6IURWrlVKph8fDu0PibLKiZnlJeCLcG1C7roHxaYgN Y8JgSR0fq21bqCPB++gMRI+G6C9g4B/CPO35UsKA6ZM1BfmpOTyy/ovwluPLkX8Lf/eXNO 8rSNz9K0S7Lkpg+K2oGnIWXIlbWEYUFkjSYzkPLc/RffoG4BuzOm0Ue2ugIWwa+M653QNa 124HIdyHA761NfPE996VIk1Juq2s4ZEOGKa4DRchIkJVAXcrrw6diu+ieoXtosd479PsxH jK2ncr0J0cm65nwENR4rKDnVVJ6bp/yani9Ts+zxU4YxCrUh+7cQIVqs/x0j5g== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 15/16] net ethtool: net: Let the active time stamping layer be selectable Date: Mon, 9 Oct 2023 17:51:37 +0200 Message-Id: <20231009155138.86458-16-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:41 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293828564411645 X-GMAIL-MSGID: 1779293828564411645 From: Kory Maincent Now that the current timestamp is saved in a variable lets add the ETHTOOL_MSG_TS_SET ethtool netlink socket to make it selectable. Signed-off-by: Kory Maincent --- Changes in v2: - Move selected_timestamping_layer introduction in this patch. - Replace strmcmp by sysfs_streq. - Use the PHY timestamp only if available. Changes in v3: - Add a devicetree binding to select the preferred timestamp - Replace the way to select timestamp through ethtool instead of sysfs You can test it with the ethtool source on branch feature_ptp of: https://github.com/kmaincent/ethtool Changes in v4: - Change the API to select MAC default time stamping instead of the PHY. - Add a whitelist to no break the old timestamp PHY default preferences for current PHY. - Replace the ethtool ioctl by netlink. - Add a netdev notifier to allow network device to create trap on PTP packets. Not tested as it need to change the lan966x driver that implement packet traps. I will do after the hwtstamp management change to NDOs. Changes in v5: - Remove the netdev notifier added in v4. - Extract the default timestamp API change in another patch. --- Documentation/networking/ethtool-netlink.rst | 17 +++++ include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/netlink.c | 8 +++ net/ethtool/netlink.h | 1 + net/ethtool/ts.c | 66 ++++++++++++++++++++ 5 files changed, 93 insertions(+) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 963a5aacac8d..eb7f8592986b 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -227,6 +227,7 @@ Userspace to kernel: ``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters ``ETHTOOL_MSG_TS_GET`` get current timestamping ``ETHTOOL_MSG_TS_LIST_GET`` list available timestampings + ``ETHTOOL_MSG_TS_SET`` set current timestamping ===================================== ================================= Kernel to userspace: @@ -2038,6 +2039,21 @@ Kernel response contents: This command lists all the possible timestamp layer available. +TS_SET +====== + +Modify the selected timestamping. + +Request contents: + + ======================= ====== =================== + ``ETHTOOL_A_TS_HEADER`` nested reply header + ``ETHTOOL_A_TS_LAYER`` u32 timestamping + ======================= ====== =================== + +This command set the timestamping with one that should be listed by the +TSLIST_GET command. + Request translation =================== @@ -2146,4 +2162,5 @@ are netlink only. n/a ``ETHTOOL_MSG_MM_SET`` n/a ``ETHTOOL_MSG_TSLIST_GET`` n/a ``ETHTOOL_MSG_TS_GET`` + n/a ``ETHTOOL_MSG_TS_SET`` =================================== ===================================== diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index 62b885d44d06..df6c4fcc62c1 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -59,6 +59,7 @@ enum { ETHTOOL_MSG_MM_SET, ETHTOOL_MSG_TS_GET, ETHTOOL_MSG_TS_LIST_GET, + ETHTOOL_MSG_TS_SET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 842c9db1531f..8322bf71f80d 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -308,6 +308,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_MM_SET] = ðnl_mm_request_ops, [ETHTOOL_MSG_TS_GET] = ðnl_ts_request_ops, [ETHTOOL_MSG_TS_LIST_GET] = ðnl_ts_list_request_ops, + [ETHTOOL_MSG_TS_SET] = ðnl_ts_request_ops, }; static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) @@ -1148,6 +1149,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_ts_get_policy, .maxattr = ARRAY_SIZE(ethnl_ts_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_TS_SET, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_default_set_doit, + .policy = ethnl_ts_set_policy, + .maxattr = ARRAY_SIZE(ethnl_ts_set_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index ea8c312db3af..8fedf234b824 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -444,6 +444,7 @@ extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADE extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1]; extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1]; extern const struct nla_policy ethnl_ts_get_policy[ETHTOOL_A_TS_HEADER + 1]; +extern const struct nla_policy ethnl_ts_set_policy[ETHTOOL_A_TS_MAX + 1]; int ethnl_set_features(struct sk_buff *skb, struct genl_info *info); int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info); diff --git a/net/ethtool/ts.c b/net/ethtool/ts.c index 11041a16de5b..f77297965e03 100644 --- a/net/ethtool/ts.c +++ b/net/ethtool/ts.c @@ -59,6 +59,69 @@ static int ts_fill_reply(struct sk_buff *skb, return nla_put_u32(skb, ETHTOOL_A_TS_LAYER, data->ts_layer); } +/* TS_SET */ +const struct nla_policy ethnl_ts_set_policy[] = { + [ETHTOOL_A_TS_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy), + [ETHTOOL_A_TS_LAYER] = NLA_POLICY_RANGE(NLA_U32, 0, + __TIMESTAMPING_COUNT - 1) +}; + +static int ethnl_set_ts_validate(struct ethnl_req_info *req_info, + struct genl_info *info) +{ + struct nlattr **tb = info->attrs; + const struct net_device_ops *ops = req_info->dev->netdev_ops; + + if (!tb[ETHTOOL_A_TS_LAYER]) + return 0; + + if (!ops->ndo_hwtstamp_set) + return -EOPNOTSUPP; + + return 1; +} + +static int ethnl_set_ts(struct ethnl_req_info *req_info, struct genl_info *info) +{ + struct net_device *dev = req_info->dev; + const struct ethtool_ops *ops = dev->ethtool_ops; + struct kernel_hwtstamp_config config = {0}; + struct nlattr **tb = info->attrs; + bool mod = false; + u32 ts_layer; + int ret; + + ts_layer = dev->ts_layer; + ethnl_update_u32(&ts_layer, tb[ETHTOOL_A_TS_LAYER], &mod); + + if (!mod) + return 0; + + if (ts_layer & NETDEV_TIMESTAMPING && !ops->get_ts_info) { + NL_SET_ERR_MSG_ATTR(info->extack, tb[ETHTOOL_A_TS_LAYER], + "this device cannot support timestamping"); + return -EINVAL; + } + + if (ts_layer & PHYLIB_TIMESTAMPING && !phy_has_tsinfo(dev->phydev)) { + NL_SET_ERR_MSG_ATTR(info->extack, tb[ETHTOOL_A_TS_LAYER], + "this device cannot support timestamping"); + return -EINVAL; + } + + /* Disable time stamping in the current layer. */ + if (netif_device_present(dev) && + dev->ts_layer & (PHYLIB_TIMESTAMPING | NETDEV_TIMESTAMPING)) { + ret = dev_set_hwtstamp_phylib(dev, &config, info->extack); + if (ret < 0) + return ret; + } + + dev->ts_layer = ts_layer; + + return 1; +} + const struct ethnl_request_ops ethnl_ts_request_ops = { .request_cmd = ETHTOOL_MSG_TS_GET, .reply_cmd = ETHTOOL_MSG_TS_GET_REPLY, @@ -69,6 +132,9 @@ const struct ethnl_request_ops ethnl_ts_request_ops = { .prepare_data = ts_prepare_data, .reply_size = ts_reply_size, .fill_reply = ts_fill_reply, + + .set_validate = ethnl_set_ts_validate, + .set = ethnl_set_ts, }; /* TS_LIST_GET */ From patchwork Mon Oct 9 15:51:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 150190 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1962251vqo; Mon, 9 Oct 2023 08:54:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwdntsYYYaYUVf1urGs2ymFCPbPckdPmq1Z4RGz8C978V9M8XnvFJ3kf+U8PGnYDWVUC/b X-Received: by 2002:a17:902:ee42:b0:1bd:e258:a256 with SMTP id 2-20020a170902ee4200b001bde258a256mr15408790plo.32.1696866845276; Mon, 09 Oct 2023 08:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866845; cv=none; d=google.com; s=arc-20160816; b=GufM+D/2/Z7oLZltdAcXkety+smCoII2P2CELgp6QZIPhxZgtP6L3n4EmlDlqd9l1N eARCC0kOw/A+DakcV7DqsSfvTIwRvgYFoEiT7fwkfza7FZ31JAOwKMiQwLD+rvY7u9FB ConL55e9IQ/3LvuT0wGkBCItxnH9NZbaMvu9ulxgcmb7CR4s8OZ0C3NtqcwN6lxnnN29 2eeHhB0n7piItspVs56e9lSBNsWBX8EotnYpgnVt/8pRZW9mTS4uhJeKB8mKHrGTtjOb R/IloovHw5ID4PmWeNIeIGrfNnV/DgnslLDkcQb7PoygZ4Tv13NACqAv6kBHzbPUeVgp QWGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4AMtsZa6zVIHzUbCNgP42uJl6NOiPb2XmqHr6qtSOk8=; fh=G6KN1zqmJBGIhpPSq1AWsD4aWgSLDy1jBh7tZkBaukM=; b=oCrP9FDGo8iBauXD3OyVg+mwLaeKkO0S/hcWsfr8ImYL8/k2lV9L3pPPNt4kcvOL3H L25llmn87LTO5gDXStE9t9D5qvJ1z2/ETUluyPJpng8YeiWaUTHq4bFppbWqNMEfUr4k b55O0D72uUQYA6DgzFC5Qv0o3CGLYUCw1/3Zs/XOOYDOVmIU3vV/89kj6bim84c63KET cRwsmJTqjjDbS438bnPP4EtmAjow/jn4HHP18ijT9/rB7WA2zLQQBfwKjvfgjee1Kjh2 1vsVfIBetd1gzkHl9x1Dd16/JUSSLRQvylWOT5o49F0/HnHJarYgoBt+0f9wxAHGIJyv wJcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=OUAu5uUl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ij7-20020a170902ab4700b001c88fc3c5a6si7452995plb.485.2023.10.09.08.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:54:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=OUAu5uUl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 2E9F880D1590; Mon, 9 Oct 2023 08:53:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377905AbjJIPx1 (ORCPT + 18 others); Mon, 9 Oct 2023 11:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377908AbjJIPxA (ORCPT ); Mon, 9 Oct 2023 11:53:00 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 387DD12A; Mon, 9 Oct 2023 08:52:44 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id DB4AA1C0006; Mon, 9 Oct 2023 15:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696866763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4AMtsZa6zVIHzUbCNgP42uJl6NOiPb2XmqHr6qtSOk8=; b=OUAu5uUl10rdXK/kSRABGinxUBYAX0tqKnedXwm6mighiWm1QSlQlqoTxYxvz4VoRNw+X6 +GC7juiFx+TR0VYScrXq/97Q2dv2Dzl9MF/B81611FPWxuQop/2wQoGEy7cLG4YzjYs78C gvGGfgZ0baXDziXYNRk3AxftqLciQ1kGrZ1zNnCv4avWMHoe76zMvmBxM/LjLNuPabjnM4 3sFM1LUimU7s0KTrX4FS9I52co5M/5DapRRJ6xDLXYp8YCbkxrCl7myWEwnO+X8Z6enWT+ WCooxd5IdXTV/d903kMGVk1Go2Hiqo/puV7fndPWmtKHteGy2i8inv7xPysBCA== From: =?utf-8?q?K=C3=B6ry_Maincent?= To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Thomas Petazzoni , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Horatiu Vultur , UNGLinuxDriver@microchip.com, Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , Richard Cochran , Radu Pirea , Willem de Bruijn , Vladimir Oltean , Michael Walle , Jacob Keller , Maxime Chevallier , Kory Maincent Subject: [PATCH net-next v5 16/16] netlink: specs: Introduce time stamping set command Date: Mon, 9 Oct 2023 17:51:38 +0200 Message-Id: <20231009155138.86458-17-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231009155138.86458-1-kory.maincent@bootlin.com> References: <20231009155138.86458-1-kory.maincent@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: kory.maincent@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:53:59 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779293849364506439 X-GMAIL-MSGID: 1779293849364506439 From: Kory Maincent Add a new commands allowing to set the time stamping. Example usage : ./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema \ --do ts-list-get \ --json '{"header":{"dev-name":"eth0"}}' {'header': {'dev-index': 3, 'dev-name': 'eth0'}, 'ts-list-layer': b'\x02\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00'} ./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do ts-set \ --json '{"header":{"dev-name":"eth0"}, "ts-layer":5}' none ./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do ts-get \ --json '{"header":{"dev-name":"eth0"}}' {'header': {'dev-index': 3, 'dev-name': 'eth0'}, 'ts-layer': 5} Signed-off-by: Kory Maincent --- Documentation/netlink/specs/ethtool.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 81ed8e5f2f55..cfee4bf32128 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -1740,3 +1740,12 @@ operations: attributes: - header - ts-list-layer + - + name: ts-set + doc: Set the timestamp device + + attribute-set: ts + + do: + request: + attributes: *ts