Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp691390pxb; Wed, 11 Nov 2020 13:52:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAarWVZ7dbMWRDVxRCMkTBe63AgYzmJi5I8esfiePdVOWEY1xhS/tk/RTO0ORAliS46ejn X-Received: by 2002:a17:906:6453:: with SMTP id l19mr27082339ejn.366.1605131550654; Wed, 11 Nov 2020 13:52:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605131550; cv=none; d=google.com; s=arc-20160816; b=mpUxzB+ghlPk8yGzpOdDPcMz8s1j3HZ6zO1Df7LAVxIKMj3t5CdshNUqzsrpimj7mT +07oO/i/s4zMW9cHRMHhTBRPaed6xn9vN8ScA9TxWIY1OwX6FilG8yKr5FKhyqVwoul8 y3xGp61qfZ2vvIWfkps3+lna7+OIKn4QoudKbgM6zWI+ei1HPXURyKdYXrYmY64jQOgp 5HJb80SYWlf9AWeJdvipqxUSM0seAdDsxw6JNVPjYHZ/nsR7mMqvuZQWIoWc8G3z1Bnl Yw8CrjtRGKWzQypVTVEA1SdoAsS0DKkUkGK7cz4mLdWR3e5ALarlUypjD+Y1DiNqQrNg wR6w== 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:organization:message-id:date:subject:cc:to :from; bh=aUTdpATExumO7M3S+WEKV4piamFOdM02Cwc/s296Qjs=; b=rKMkHPgmZyY48h+S2pSgEJECfuImJ1z3JH579YzKfkgICRGH9RM9Ajpm7XE1pcv3Ay ZTHigoJ1IfpcH4PCmpKMflL/GK04V+kwx1VeGcMZRGweLX35P74vt4FXL2thVl5Y+laM K62LBkzUhSo/HLfIa5oVF44OEsx5hweR7HUwdrwnkea1jm9ZRNqgzKH0O4EyfpQGyqEk qZhV6h1HzxzqHbKv16j3zdOYTdeG7d/f27ER68vgGmz76bP59TjoApFZIyGastifCc2a 8VvsmShbb4QpNWsW07W4nl6pVQ0FhgmV/gLKV3h9/uiYnaH/lqE4trkuj7gOphd2KRDL tzag== 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 n2si2362057ejr.580.2020.11.11.13.52.05; Wed, 11 Nov 2020 13:52:30 -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 S1726348AbgKKVub (ORCPT + 99 others); Wed, 11 Nov 2020 16:50:31 -0500 Received: from mailout04.rmx.de ([94.199.90.94]:35086 "EHLO mailout04.rmx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726108AbgKKVua (ORCPT ); Wed, 11 Nov 2020 16:50:30 -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 mailout04.rmx.de (Postfix) with ESMTPS id 4CWdh25qXYz3qcH4; Wed, 11 Nov 2020 22:50:26 +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 4CWdgw19V5z2xDM; Wed, 11 Nov 2020 22:50:20 +0100 (CET) Received: from n95hx1g2.localnet (192.168.54.13) by mta.arri.de (192.168.100.104) with Microsoft SMTP Server (TLS) id 14.3.487.0; Wed, 11 Nov 2020 22:49:47 +0100 From: Christian Eggers To: Vladimir Oltean CC: Richard Cochran , Florian Fainelli , Andrew Lunn , Vivien Didelot , Jakub Kicinski , Rob Herring , Helmut Grohne , Paul Barker , Codrin Ciubotariu , George McCollister , Marek Vasut , Tristram Ha , "David S . Miller" , Woojung Huh , "Microchip Linux Driver Support" , , , Subject: Re: [RFC PATCH net-next 7/9] net: dsa: microchip: ksz9477: add hardware time stamping support Date: Wed, 11 Nov 2020 22:49:44 +0100 Message-ID: <5898097.XrYNDCFn2f@n95hx1g2> Organization: Arnold & Richter Cine Technik GmbH & Co. Betriebs KG In-Reply-To: <20201110193245.uwsmrqzio5hco7fb@skbuf> References: <20201019172435.4416-1-ceggers@arri.de> <20201110164045.jqdwvmz5lq4hg54l@skbuf> <20201110193245.uwsmrqzio5hco7fb@skbuf> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Originating-IP: [192.168.54.13] X-RMX-ID: 20201111-225020-4CWdgw19V5z2xDM-0@kdin01 X-RMX-SOURCE: 217.111.95.66 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vladimir, On Tuesday, 10 November 2020, 20:32:45 CET, Vladimir Oltean wrote: > On Tue, Nov 10, 2020 at 06:40:45PM +0200, Vladimir Oltean wrote: > > I am fairly confident that this is how your hardware works, because > > that's also how peer delay wants to be timestamped, it seems. > > So I was confident and also wrong, it appears. My KSZ9477 datasheet > says: > > In the host-to-switch direction, the 4-byte timestamp field is always > present when PTP is enabled, as shown in Figure 4-6. This is true for > all packets sent by the host, including IBA packets. The host uses this > field to insert the receive timestamp from PTP Pdelay_Req messages into > the Pdelay_Resp messages. For all other traffic and PTP message types, > the host should populate the timestamp field with zeros. > > Hm. Does that mean that the switch updates the originTimestamp field of > the Sync frames by itself? IMHO this is the best solution. User space / driver do not know the exact time (would require slow I2C transfer). So inserting the time in hardware seems to be the better solution. Maybe this is what the data sheet meant with "egress timestamp insertion". > Ok... Very interesting that they decided to > introduce a field in the tail tag for a single type of PTP message. > But something is still wrong if you need to special-case the negative > correctionField, it looks like the arithmetic is not done on the correct > number of bits, either by the driver or by the hardware. > Maybe I found the formula which is (should) applied to the correction field for PDelayResp: correction = correction_old + now + residental_delay + tx_latency - tail_tag : current value from the PTP header : Time of the PTP clock when entering the switch : Switching delay : Delay between time stamping unit and wire (configurable via register) : Time stamp in the tail tag The new correction value has been captured with Wireshark. For the measurement I simply halted the internal PTP clock and set it to zero (so it's value is exactly known). In the port's TX time stamp unit I got a non-zero time stamp anyway (between, 10 to 40 ns), so this must be the residential delay. I tested with different values for the correction field and the tail_tag. Negative values are no problem, but the calculation seems no to consider all bits. Measurements: - PTP clock: 0 (frozen) - Residential delay: variable - TX delay: 45 ns (default) - correction = 0xffff ffff ffff.ffff (-1.xxx ns) correction = correction + now + residental_delay + tx_latency - tail_tag = -1 + 0 40 + 45 0 = 84 (0000 0000 0054) wireshark: (0000 0000 0054) --> correct correction = correction + now + residental_delay + tx_latency - tail_tag = -1 + 0 32 + 45 1.000 = -924 (FFFF FFFF FC64) wireshark: (0000 FFFF FC64) --> wrong correction = correction + now + residental_delay + tx_latency - tail_tag = -1 + 0 24 + 45 2.000.000.000 = -1.926.258.108 (FFFF 8D2F A244) wireshark: (0000 7B9A CA44) --> wrong - correction = 0xffff ffff 0000.0000 (-65536.0 ns) correction = correction + now + residental_delay + tx_latency - tail_tag = -65536 0 24 + 45 0 = -65467 (FFFF FFFF 0045) wireshark: (FFFF FFFF 0045) --> correct correction = correction + now + residental_delay + tx_latency - tail_tag = -65536 + 0 32 + 45 1.000 = -66459 (FFFF FFFE FC65) wireshark: (0000 FFFE FC65) --> wrong Please note that the tail tag consist of 2 bits for seconds and 30 bit nanoseconds. So the value of 2.000.000.000 means 1s + 926.258.176 ns. As you are better in 2's complement as me, you can give me some more combinations for testing if you need. But in the end it looks like I should keep T2 in the tail tag. > And zeroing out the correctionField of the Pdelay_Resp on transmission, > to put that value into t_Tail_Tag? How can you squeeze a 48-bit value > into a 32-bit value without truncation? Only the lower bits are used. As long as PDelayResp doesn't take more than 4 seconds, this should be enough. regards Christian