Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp160693pxu; Tue, 1 Dec 2020 08:19:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwB2yfOZNhfEnuwkhwk6HuQQqmW+VA8egQ4vBSBtiequXIZWRh3Lws6m7ol6eFA704iNwzX X-Received: by 2002:a17:906:7f11:: with SMTP id d17mr3802826ejr.534.1606839552845; Tue, 01 Dec 2020 08:19:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606839552; cv=none; d=google.com; s=arc-20160816; b=UgWmWLv2IqS9rDrJcYnVZqgURL5zBdi+mv+u+oAQ31KlRW4rnvFORYTz/4wEIwSGzV hEylnQSbPF87RHPD5nWlHn8U1yU6u6XKv2dUA2kmjlbF/+3NgfZkX3cTiphaNCNjMuiH 2LLX54FQx77Tv2RedpYpwzKh1o+byPH7Lrfn1rPNqdBLHT1vFl4vS7DPtj3mCosM0LvH yvJh2/Bl4V7wkWlUcrb+3k3Kioc+sc1N0Uwf2O4dJ2YID2pGvns4dhbmx0eAlkCn/SI7 vsWqhUDYY4Cc5hGCJ//BczdGfTqz5HVBcUg0/Dcif9tU10LzCO2WZMYE2tw9BLg0tdi3 P6jQ== 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; bh=853Egs37pc1CbKSus1/J8jjJshN+pt2REOJqR4ASWqA=; b=xl+Giu0U5PsIubv2vlnxJcbhnbz8+YgF8lIW+lHYhM2lgweEikdGwdWvvdhtQQ+TjY llowBBt50yrtz6ePgrpNaXpuRHlVMD0fKBo6TXcLP2c3DtJx5tiGAsTU50f9k7O6Yc3g Oz0XHq3ldcZqRsrUewJvYb3MWTg/a2vZjMe0ex84zPv/e6yUoefSUhIp9PaSOdPYJouO EFfeh65gg2vbJzzB3x17Qo80YWoGrIIxrsWivHQ/rBPHyyhNIm4NCe+Drf9wCkCbqq06 rin45lw4t/zh1ltBeEEMHlQq1zDFB2HI1nOilMHZd6yHAs50ZZcvEP7DnURbgkofLNaP qy3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u4si192430ejr.287.2020.12.01.08.18.49; Tue, 01 Dec 2020 08:19:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392068AbgLAQQo (ORCPT + 99 others); Tue, 1 Dec 2020 11:16:44 -0500 Received: from mailout01.rmx.de ([94.199.90.91]:39434 "EHLO mailout01.rmx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390881AbgLAQQo (ORCPT ); Tue, 1 Dec 2020 11:16:44 -0500 Received: from kdin01.retarus.com (kdin01.dmz1.retloc [172.19.17.48]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout01.rmx.de (Postfix) with ESMTPS id 4ClnJw0TWVz2SVyk; Tue, 1 Dec 2020 17:16:00 +0100 (CET) Received: from mta.arri.de (unknown [217.111.95.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by kdin01.retarus.com (Postfix) with ESMTPS id 4ClnH80qt2z2xGC; Tue, 1 Dec 2020 17:14:28 +0100 (CET) Received: from N95HX1G2.wgnetz.xx (192.168.54.19) by mta.arri.de (192.168.100.104) with Microsoft SMTP Server (TLS) id 14.3.487.0; Tue, 1 Dec 2020 17:09:46 +0100 From: Christian Eggers To: Vladimir Oltean , Jakub Kicinski , Andrew Lunn , Richard Cochran , "Rob Herring" CC: Vivien Didelot , "David S . Miller" , Kurt Kanzenbach , George McCollister , Marek Vasut , Helmut Grohne , Paul Barker , Codrin Ciubotariu , Tristram Ha , Woojung Huh , Microchip Linux Driver Support , Christian Eggers , , , Subject: [PATCH net-next v4 6/9] net: ptp: add helper for one-step P2P clocks Date: Tue, 1 Dec 2020 17:06:08 +0100 Message-ID: <20201201160611.22129-7-ceggers@arri.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201201160611.22129-1-ceggers@arri.de> References: <20201201160611.22129-1-ceggers@arri.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.54.19] X-RMX-ID: 20201201-171436-4ClnH80qt2z2xGC-0@kdin01 X-RMX-SOURCE: 217.111.95.66 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For P2P delay measurement, the ingress time stamp of the PDelay_Req is required for the correction field of the PDelay_Resp. The application echoes back the correction field of the PDelay_Req when sending the PDelay_Resp. Some hardware (like the ZHAW InES PTP time stamping IP core) subtracts the ingress timestamp autonomously from the correction field, so that the hardware only needs to add the egress timestamp on tx. Other hardware (like the Microchip KSZ9563) reports the ingress time stamp via an interrupt and requires that the software provides this time stamp via tail-tag on tx. In order to avoid introducing a further application interface for this, the driver can simply emulate the behavior of the InES device and subtract the ingress time stamp in software from the correction field. On egress, the correction field can either be kept as it is (and the time stamp field in the tail-tag is set to zero) or move the value from the correction field back to the tail-tag. Changing the correction field requires updating the UDP checksum (if UDP is used as transport). Signed-off-by: Christian Eggers --- include/linux/ptp_classify.h | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h index cc0da0b134a4..f19f2f6a9475 100644 --- a/include/linux/ptp_classify.h +++ b/include/linux/ptp_classify.h @@ -10,8 +10,12 @@ #ifndef _PTP_CLASSIFY_H_ #define _PTP_CLASSIFY_H_ +#include #include +#include #include +#include +#include #define PTP_CLASS_NONE 0x00 /* not a PTP event message */ #define PTP_CLASS_V1 0x01 /* protocol version 1 */ @@ -123,6 +127,67 @@ static inline u8 ptp_get_msgtype(const struct ptp_header *hdr, return msgtype; } +/** + * ptp_check_diff8 - Computes new checksum (when altering a 64-bit field) + * @old: old field value + * @new: new field value + * @oldsum: previous checksum + * + * This function can be used to calculate a new checksum when only a single + * field is changed. Similar as ip_vs_check_diff*() in ip_vs.h. + * + * Return: Updated checksum + */ +static inline __wsum ptp_check_diff8(__be64 old, __be64 new, __wsum oldsum) +{ + __be64 diff[2] = { ~old, new }; + + return csum_partial(diff, sizeof(diff), oldsum); +} + +/** + * ptp_header_update_correction - Update PTP header's correction field + * @skb: packet buffer + * @type: type of the packet (see ptp_classify_raw()) + * @hdr: ptp header + * @correction: new correction value + * + * This updates the correction field of a PTP header and updates the UDP + * checksum (if UDP is used as transport). It is needed for hardware capable of + * one-step P2P that does not already modify the correction field of Pdelay_Req + * event messages on ingress. + */ +static inline +void ptp_header_update_correction(struct sk_buff *skb, unsigned int type, + struct ptp_header *hdr, s64 correction) +{ + __be64 correction_old; + struct udphdr *uhdr; + + /* previous correction value is required for checksum update. */ + memcpy(&correction_old, &hdr->correction, sizeof(correction_old)); + + /* write new correction value */ + put_unaligned_be64((u64)correction, &hdr->correction); + + switch (type & PTP_CLASS_PMASK) { + case PTP_CLASS_IPV4: + case PTP_CLASS_IPV6: + /* locate udp header */ + uhdr = (struct udphdr *)((char *)hdr - sizeof(struct udphdr)); + break; + default: + return; + } + + /* update checksum */ + uhdr->check = csum_fold(ptp_check_diff8(correction_old, + hdr->correction, + ~csum_unfold(uhdr->check))); + if (!uhdr->check) + uhdr->check = CSUM_MANGLED_0; +} + void __init ptp_classifier_init(void); #else static inline void ptp_classifier_init(void) @@ -145,5 +210,13 @@ static inline u8 ptp_get_msgtype(const struct ptp_header *hdr, */ return PTP_MSGTYPE_SYNC; } + +static inline +void ptp_onestep_p2p_move_t2_to_correction(struct sk_buff *skb, + unsigned int type, + struct ptp_header *hdr, + ktime_t t2) +{ +} #endif #endif /* _PTP_CLASSIFY_H_ */ -- Christian Eggers Embedded software developer Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918 Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477 Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler