Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10240115rwl; Sun, 1 Jan 2023 21:50:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXs5uYSvntr8AwJX0BkkQZ7xuhZ9fvJ53XgpyQ250WlKn7nBhaw2yorVxXSeH/oJ40JV34iG X-Received: by 2002:a17:907:970a:b0:7c0:fd1a:79ee with SMTP id jg10-20020a170907970a00b007c0fd1a79eemr52633215ejc.63.1672638634751; Sun, 01 Jan 2023 21:50:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672638634; cv=none; d=google.com; s=arc-20160816; b=UStwlpsbTpOjxD6vnXgL1aczL4mrmEDTJ55kSYDboIMd+J/f34MZR3GAqKVKmPZMcy c9cfNTFq7xK/4Z2qwxDw8LSn4njpn/Q9ub1JZkLvJ4m/um9FRb1et5p3w/NVaZ2BsiKY WWci8ImOuhjvUYX7Yz0x/TUHss4O7aFdgzuU/0VKJYXvgO32dZPjqlRRrnQwRa9sKCHk xGw7G/Nl+btqnkpQsVa7pouXm3m2unSW5Sa7PWV429X0d2I8izDpEDNN8jBSuVroOSFE mijG39eL28LSq1C6ZELrhxcRPkbgoOFc6iMpT66I8cbLML2Hv9l449mOTBRVk+Ggramc P+3A== 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=j+VZDxcCoa15F1S74qhW/t38i5bJ5I2HbMWkh4JpNJo=; b=xPjVI83x1/L34GR26mOE/Xr1kCGQKbKarrSfoEsoon6aveF35l4c/skgpjh3NxF2eb 8HeAxmrU339DlvIVsSzBxqdNpyhQPzMs8GZmQ+EpPPa7mrx0FPkIU3goKGdei+K1Q4Zd 21bh+jvIRSeXQd1jIXMWXjv3jwzzrpTL+kWDOS8IsTww07z/r3rsTGSXydKlV1G5PK52 DW5Zi7gScOPIS1UR7NG5mqiYBpMlKVVvXa8vul/0wV5g/bPrL9PW/qpUBoX0q4ptka6H MAJBkfVVgVzCW2KecjyKGAmjW6KegFxPmpzR7NUokXBQM9ADRxLA3G/9TOIFC6i5HrNN aKUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=zJfAkLJj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv15-20020a17090760cf00b007ade22f401bsi24723952ejc.759.2023.01.01.21.50.20; Sun, 01 Jan 2023 21:50:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=zJfAkLJj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230289AbjABFKw (ORCPT + 59 others); Mon, 2 Jan 2023 00:10:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbjABFJ6 (ORCPT ); Mon, 2 Jan 2023 00:09:58 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D18FF2614; Sun, 1 Jan 2023 21:08:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1672636098; x=1704172098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BsHOrPq13mxXcu/hutFr3b8J7KhpwyigNExjZ/OZMjk=; b=zJfAkLJjIwToha6GBOLOaRUJniXxQLjnl6ejjvoshB/otSTohV/tf9y0 yoqkE/Kr4ux1i96rkNf+N/V/RlnUjqIkLyp+gic18AEiXU/hS1F6opLCB HsLgKFDmP1kY/7fHuWhjVfy8XHSb3/S+KTRwSBDT3VYPsUT/1OKWaJpbc 8ppMJ5AbrmJAfQLJc4z6mhKURT+jP4pEzw3+JG9/SwEAwNcAHjmpt4+jn NZDc47iTztpwRyPvzy4y9sA93C08NioNdDxvZ1ssBIIljiyrWj7oN3Dw8 fMa9INTzfHRWvpuv410wLeshJVYJD2fnU0m8goE+m20PnOuK1B6yv2+i5 Q==; X-IronPort-AV: E=Sophos;i="5.96,293,1665471600"; d="scan'208";a="130397803" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 01 Jan 2023 22:08:11 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Sun, 1 Jan 2023 22:08:10 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Sun, 1 Jan 2023 22:08:04 -0700 From: Arun Ramadoss To: , CC: , , , , , , , , , , , , , , Subject: [Patch net-next v6 12/13] net: dsa: microchip: ptp: lan937x: add 2 step timestamping Date: Mon, 2 Jan 2023 10:34:58 +0530 Message-ID: <20230102050459.31023-13-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230102050459.31023-1-arun.ramadoss@microchip.com> References: <20230102050459.31023-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,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 LAN937x series of switches support 2 step timestamping mechanism. There are timestamp correction calculation performed in ksz_rcv_timestamp and ksz_xmit_timestamp which are applicable only for p2p1step. To check whether the 2 step is enabled or not in tag_ksz.c introduced the helper function in taggger_data to query it from ksz_ptp.c. Based on whether 2 step is enabled or not, timestamp calculation are performed. Signed-off-by: Arun Ramadoss --- v3 -> v4 - P2P_1step bit is set which is required for P2P. It is missed during patch v3 regression. v2 -> v3 - Reverted setting PTP_1Step bit as we are setting 802_1AS bit v1 -> v2 - declard is_ptp_twostep as macro NULL for ptp disabled case - Moved the patch in series to have continuity for lan937x updates 9/11 to 12/13 - enable PTP_1STEP bit based on tx timestamping Patch v1 - Patch is new. --- drivers/net/dsa/microchip/ksz_ptp.c | 37 ++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 2d52a3d4771e..c2d156002ee5 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -283,6 +283,9 @@ int ksz_get_ts_info(struct dsa_switch *ds, int port, struct ethtool_ts_info *ts) ts->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ONESTEP_P2P); + if (is_lan937x(dev)) + ts->tx_types |= BIT(HWTSTAMP_TX_ON); + ts->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | @@ -310,6 +313,8 @@ static int ksz_set_hwtstamp_config(struct ksz_device *dev, struct ksz_port *prt, struct hwtstamp_config *config) { + int ret; + if (config->flags) return -EINVAL; @@ -325,6 +330,25 @@ static int ksz_set_hwtstamp_config(struct ksz_device *dev, prt->ptpmsg_irq[KSZ_XDREQ_MSG].ts_en = 1; prt->ptpmsg_irq[KSZ_PDRES_MSG].ts_en = 0; prt->hwts_tx_en = true; + + ret = ksz_rmw16(dev, REG_PTP_MSG_CONF1, PTP_1STEP, PTP_1STEP); + if (ret) + return ret; + + break; + case HWTSTAMP_TX_ON: + if (!is_lan937x(dev)) + return -ERANGE; + + prt->ptpmsg_irq[KSZ_SYNC_MSG].ts_en = 1; + prt->ptpmsg_irq[KSZ_XDREQ_MSG].ts_en = 1; + prt->ptpmsg_irq[KSZ_PDRES_MSG].ts_en = 1; + prt->hwts_tx_en = true; + + ret = ksz_rmw16(dev, REG_PTP_MSG_CONF1, PTP_1STEP, 0); + if (ret) + return ret; + break; default: return -ERANGE; @@ -412,14 +436,20 @@ bool ksz_port_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb, struct skb_shared_hwtstamps *hwtstamps = skb_hwtstamps(skb); struct ksz_device *dev = ds->priv; struct ptp_header *ptp_hdr; + struct ksz_port *prt; u8 ptp_msg_type; ktime_t tstamp; s64 correction; + prt = &dev->ports[port]; + tstamp = KSZ_SKB_CB(skb)->tstamp; memset(hwtstamps, 0, sizeof(*hwtstamps)); hwtstamps->hwtstamp = ksz_tstamp_reconstruct(dev, tstamp); + if (prt->tstamp_config.tx_type != HWTSTAMP_TX_ONESTEP_P2P) + goto out; + ptp_hdr = ptp_parse_header(skb, type); if (!ptp_hdr) goto out; @@ -468,6 +498,10 @@ void ksz_port_txtstamp(struct dsa_switch *ds, int port, ptp_msg_type = ptp_get_msgtype(hdr, type); switch (ptp_msg_type) { + case PTP_MSGTYPE_SYNC: + if (prt->tstamp_config.tx_type == HWTSTAMP_TX_ONESTEP_P2P) + return; + fallthrough; case PTP_MSGTYPE_PDELAY_REQ: fallthrough; case PTP_MSGTYPE_PDELAY_RESP: @@ -484,7 +518,8 @@ void ksz_port_txtstamp(struct dsa_switch *ds, int port, /* caching the value to be used in tag_ksz.c */ KSZ_SKB_CB(skb)->clone = clone; KSZ_SKB_CB(clone)->ptp_type = type; - if (ptp_msg_type == PTP_MSGTYPE_PDELAY_RESP) + if (ptp_msg_type == PTP_MSGTYPE_PDELAY_RESP && + prt->tstamp_config.tx_type == HWTSTAMP_TX_ONESTEP_P2P) KSZ_SKB_CB(clone)->update_correction = true; } -- 2.36.1