From patchwork Tue Jan 10 08:49:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 41363 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2632233wrt; Tue, 10 Jan 2023 00:55:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXsnOMJ3GSUedmsRQMYRCO5HkEbUWN2fpw9QZMcReDK7OdLOV3v3y7EQXzHWQ/E7DpQGea8E X-Received: by 2002:a05:6a20:2d28:b0:b2:5a61:da0e with SMTP id g40-20020a056a202d2800b000b25a61da0emr83207125pzl.62.1673340909901; Tue, 10 Jan 2023 00:55:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673340909; cv=none; d=google.com; s=arc-20160816; b=w5tJnOt1g/Q59ooYjBUxd5EOFplkmUdFYJx9c5+7KGSEU7cNGYc+02W6qhTzsFDQrL cmi6R9i+FuIGfHEcYsRfUA7WiJSyii5fbEe4KxXuctbhSgFaMOeayHkh2ohUtZYYD5IK Ey2arsqCht9dWhOm4iOBkDucDkB/UIuG254+hG/hcHe36gd1aHlwkv47KUmbMYczX+Dn MOm5O4JKQGN2KXLO6wmzttggozuqxvTiGBBrJf5rSZW5+bj1liz1tH0UknWla+vg39tj DKORHeSioy5dATL0Owf4eJXN6qk54TKuRAco+daMH1otdruW7SUyofZZJ5Il71OHCBA+ 0h/g== 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=D1bqUPTml3SpaLIsFpN2YOGe5ccqafk+EQd0o1mxTXQ=; b=u40OSvZLrO3nGFlhM7X6oZwZASB0n0qKL7iMjTxJ5cYvr4bmiFIGjEhZgakWzYe09K E5yzwU06f/2n3WswdW0SjxH3CpeY8TUJ2lKBfNzG6ga5XTPcVnIYKNPh4i69GHIC1Kv7 c2DHQY0HsuYcYeGKr54bAYAz0NA9IDO5/DN0eyqmeGPYng8TKHc5VhjTfF+yoDTQLSKC gaxdAsoI7LENWDyTzC2FVTTqdAld3HPWB3vJNEd9qz/ffBoDyNkHVKOOh+V3mCgeSwq3 rA+9H2lQQBacUduhpxCybXC4G0Pv16vqvqzmbWYUidGl55kOA6MvtKBXe9O813DE5CPx /YcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=OKLKNJF7; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a170902edd000b0017d2c45e8ffsi10837838plk.171.2023.01.10.00.54.57; Tue, 10 Jan 2023 00:55:09 -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=OKLKNJF7; 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 S231597AbjAJIwW (ORCPT + 99 others); Tue, 10 Jan 2023 03:52:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231487AbjAJIvZ (ORCPT ); Tue, 10 Jan 2023 03:51:25 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66CA713D7E; Tue, 10 Jan 2023 00:51:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1673340685; x=1704876685; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h8UF981ICj1wP/5IsxagyjSR7LSgBoaAp+u+2w1cP4o=; b=OKLKNJF7DxFNOr9fI9PunZT4Ory4XGUr4cygS/bbRDHFJdaT2qhsLM/F 3Q5FwpVTjKtNw3lNvVCp4vNtc3hc2wDn2PX3K+fKj8jwNq9fXEgS5E4Sz lNYC78aVsJytn3VAb2YdPz9F6Ah0XW6elATQT0IEWUP4B/gXIxkCnUZnF zKd9yaHuwrXgZItamoWDS9HrQEpsTWpmItWDckMSB/w56+UmtTzFmYolg lv2+ICucitCRkmIBDRQsdXel3cATHtwId1xXcMg5WQG97B+51EuIPlcPO 3oqmX8LYc8KSEghl0x1j3L6Q+ZqQi+bsMYzhFK+usMy9/ERe5K7LSDc5W g==; X-IronPort-AV: E=Sophos;i="5.96,314,1665471600"; d="scan'208";a="196118631" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 10 Jan 2023 01:51:24 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 10 Jan 2023 01:51:23 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Tue, 10 Jan 2023 01:51:16 -0700 From: Arun Ramadoss To: , CC: , , , , , , , , , , , , , Subject: [Patch net-next v8 09/13] net: dsa: microchip: ptp: move pdelay_rsp correction field to tail tag Date: Tue, 10 Jan 2023 14:19:26 +0530 Message-ID: <20230110084930.16049-10-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230110084930.16049-1-arun.ramadoss@microchip.com> References: <20230110084930.16049-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754625118035582337?= X-GMAIL-MSGID: =?utf-8?q?1754625118035582337?= From: Christian Eggers For PDelay_Resp messages we will likely have a negative value in the correction field. The switch hardware cannot correctly update such values (produces an off by one error in the UDP checksum), so it must be moved to the time stamp field in the tail tag. Format of the correction field is 48 bit ns + 16 bit fractional ns. After updating the correction field, clone is no longer required hence it is freed. Signed-off-by: Christian Eggers Co-developed-by: Arun Ramadoss Signed-off-by: Arun Ramadoss --- v6 -> v7 - Reverted the fallthrough keyword - updated pdelay_resp correction without skb clone - removed local variable update_correction in tag_ksz.c v2 -> v3 - used update_correction variable in skb->cb instead of ptp_msg_type v1 -> v2 - added fallthrough keyword in switch case to suppress checkpatch warning RFC v3 -> Patch v1 - Patch is separated from transmission logic patch --- drivers/net/dsa/microchip/ksz_ptp.c | 4 ++++ include/linux/dsa/ksz_common.h | 2 ++ net/dsa/tag_ksz.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index 6edce141cbd7..2a68649943d5 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -267,6 +267,10 @@ void ksz_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb) switch (ptp_msg_type) { case PTP_MSGTYPE_PDELAY_REQ: break; + case PTP_MSGTYPE_PDELAY_RESP: + KSZ_SKB_CB(skb)->ptp_type = type; + KSZ_SKB_CB(skb)->update_correction = true; + return; default: return; diff --git a/include/linux/dsa/ksz_common.h b/include/linux/dsa/ksz_common.h index b91beab5e138..576a99ca698d 100644 --- a/include/linux/dsa/ksz_common.h +++ b/include/linux/dsa/ksz_common.h @@ -36,6 +36,8 @@ struct ksz_tagger_data { struct ksz_skb_cb { struct sk_buff *clone; + unsigned int ptp_type; + bool update_correction; u32 tstamp; }; diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index e14ee26bf6a0..694478fe07d6 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "tag.h" @@ -195,13 +196,39 @@ static void ksz_rcv_timestamp(struct sk_buff *skb, u8 *tag) static void ksz_xmit_timestamp(struct dsa_port *dp, struct sk_buff *skb) { struct ksz_tagger_private *priv; + struct ptp_header *ptp_hdr; + unsigned int ptp_type; + u32 tstamp_raw = 0; + s64 correction; priv = ksz_tagger_private(dp->ds); if (!test_bit(KSZ_HWTS_EN, &priv->state)) return; - put_unaligned_be32(0, skb_put(skb, KSZ_PTP_TAG_LEN)); + if (!KSZ_SKB_CB(skb)->update_correction) + goto output_tag; + + ptp_type = KSZ_SKB_CB(skb)->ptp_type; + + ptp_hdr = ptp_parse_header(skb, ptp_type); + if (!ptp_hdr) + goto output_tag; + + correction = (s64)get_unaligned_be64(&ptp_hdr->correction); + + if (correction < 0) { + struct timespec64 ts; + + ts = ns_to_timespec64(-correction >> 16); + tstamp_raw = ((ts.tv_sec & 3) << 30) | ts.tv_nsec; + + /* Set correction field to 0 and update UDP checksum */ + ptp_header_update_correction(skb, ptp_type, ptp_hdr, 0); + } + +output_tag: + put_unaligned_be32(tstamp_raw, skb_put(skb, KSZ_PTP_TAG_LEN)); } /* Defer transmit if waiting for egress time stamp is required. */