Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp373674pxu; Thu, 3 Dec 2020 02:31:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyiBKnF+OPbuL2oON/n4Q7CTqc+jWk5JvEqIgZedigjOVBkhBuwTYi4E8H5PgtThwBwzE8E X-Received: by 2002:a17:906:8151:: with SMTP id z17mr1960170ejw.48.1606991471972; Thu, 03 Dec 2020 02:31:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606991471; cv=none; d=google.com; s=arc-20160816; b=q9IRqgGohPryGqdVK7p9mIq6UHnRNYldjzLCTNVYMrqgTcGc8EDr+SeWyX5OdXIxdB GZu/+03WA7vmlhldSvBxBXaS0d8QWRSmulS6XNxqfLw2Ccg5NPpZpm42R3V/R9nZriP3 16ujzTROpCIMnVYPxnw2J0yf41/aQi3v7ruX/hcNhrYTZbw0sdaTDHlX9CruqXfQIJe9 tuPHCPEW06aYH4tUIy5sK9IVnhmluB8TtaBPhGQAk1gLJij6eXpsOyQIsvtjlO7vbtr2 XKNk7gdL2nEg8mylFvlnXDyQw3tB80EhJPMdZCEq2j5OAbnF76AqMIEhqiYSgo+a8asH 3VWA== 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=UM5Ncnsru3QUoIeEmEMy0y8CAa4MzN7g3OpREe4DLt2NpBuB6bY79onbADMdbRsBFa ZAZDRx8fB4vBn59s7b7mjZz3Vk4Hi0IVfPrz+fwNvaazcQXu0NNl/9kFPZTMAERqr58W fpZe/omik4IBRkRUmK06pT89/T9ZKuZ/0kPzYO9TWw12FcNjazt0V88Wve2IcyfAk3xa /UwcR/GxZKUCGfy8K5BRm7JbMOUuIC19nHIVh7phU4bnvVJZ2goQYmXGkRrtYkGgeuwz rsyoXaGzT82E5Oj3BaEKzNDGFdzM6WLxHfRN/U9hEJPHKxedoTLCfu95ReZJT5rdB4et dtSw== 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 p18si750284eds.125.2020.12.03.02.30.48; Thu, 03 Dec 2020 02:31:11 -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 S2388537AbgLCK1K (ORCPT + 99 others); Thu, 3 Dec 2020 05:27:10 -0500 Received: from mailout01.rmx.de ([94.199.90.91]:36903 "EHLO mailout01.rmx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730157AbgLCK1K (ORCPT ); Thu, 3 Dec 2020 05:27:10 -0500 Received: from kdin02.retarus.com (kdin02.dmz1.retloc [172.19.17.49]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout01.rmx.de (Postfix) with ESMTPS id 4CmsSc1zMyz2SVJw; Thu, 3 Dec 2020 11:26:24 +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 kdin02.retarus.com (Postfix) with ESMTPS id 4CmsRx5GH9z2TSDZ; Thu, 3 Dec 2020 11:25:49 +0100 (CET) Received: from N95HX1G2.wgnetz.xx (192.168.54.174) by mta.arri.de (192.168.100.104) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 3 Dec 2020 11:24:54 +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 v5 6/9] net: ptp: add helper for one-step P2P clocks Date: Thu, 3 Dec 2020 11:21:14 +0100 Message-ID: <20201203102117.8995-7-ceggers@arri.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201203102117.8995-1-ceggers@arri.de> References: <20201203102117.8995-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.174] X-RMX-ID: 20201203-112549-CBxkhgyqMZSR-0@out02.hq 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