From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D0FDC2B9F4 for ; Mon, 14 Jun 2021 14:14:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 496B161206 for ; Mon, 14 Jun 2021 14:14:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233699AbhFNOQP (ORCPT ); Mon, 14 Jun 2021 10:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232745AbhFNOQO (ORCPT ); Mon, 14 Jun 2021 10:16:14 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC1DDC061574 for ; Mon, 14 Jun 2021 07:14:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=B2TZHk381oHEqI2pFW8AwGFr0g6/WiFU6NInsUgaBQc=; b=RLj5BwTkGTo5tdB81YUdfjjf9 1Kw4K6uFQQl494Bkoh64oB/2AYalOVHHheBjaClYU1x7FuaCVNNhNRPHzgthwZSHLZll5W4zGf4pf encDtFAaYYXosPqSIpsAmLZr2ZjfK1V9OEOWY+tQT+MZKRA/C/J0O0BHo6hbPwdhVrnIw8VBIIEM3 aSN3qUgLsITERb3Qza86Ef1F0spB0hk4Snzbvai+WAq+TRexNHvnGzAZkMSwqioGrf15s2+J2RtEP jR1QTf+1HHhvqUpb8uxeZ9w1jlOXD0O2b57peEPiFEZbrHiNi4UwKE7YFi+f/091rpket2D8/xYlh m65xzfsfg==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:45008) by pandora.armlinux.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lsnLr-0004NG-Rk; Mon, 14 Jun 2021 15:14:07 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1lsnLp-0004Bm-Ob; Mon, 14 Jun 2021 15:14:05 +0100 Date: Mon, 14 Jun 2021 15:14:05 +0100 From: "Russell King (Oracle)" To: Vladimir Oltean Cc: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, Florian Fainelli , Andrew Lunn , Heiner Kallweit , Radu Pirea , Vladimir Oltean , Richard Cochran Subject: Re: [PATCH v3 net-next 2/4] net: phy: nxp-c45-tja11xx: express timestamp wraparound interval in terms of TS_SEC_MASK Message-ID: <20210614141405.GV22278@shell.armlinux.org.uk> References: <20210614134441.497008-1-olteanv@gmail.com> <20210614134441.497008-3-olteanv@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210614134441.497008-3-olteanv@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: Russell King (Oracle) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, Jun 14, 2021 at 04:44:39PM +0300, Vladimir Oltean wrote: > From: Vladimir Oltean > > nxp_c45_reconstruct_ts() takes a partial hardware timestamp in @hwts, > with 2 bits of the 'seconds' portion, and a full PTP time in @ts. > > It patches in the lower bits of @hwts into @ts, and to ensure that the > reconstructed timestamp is correct, it checks whether the lower 2 bits > of @hwts are not in fact higher than the lower 2 bits of @ts. This is > not logically possible because, according to the calling convention, @ts > was collected later in time than @hwts, but due to two's complement > arithmetic it can actually happen, because the current PTP time might > have wrapped around between when @hwts was collected and when @ts was, > yielding the lower 2 bits of @ts smaller than those of @hwts. > > To correct for that situation which is expected to happen under normal > conditions, the driver subtracts exactly one wraparound interval from > the reconstructed timestamp, since the upper bits of that need to > correspond to what the upper bits of @hwts were, not to what the upper > bits of @ts were. > > Readers might be confused because the driver denotes the amount of bits > that the partial hardware timestamp has to offer as TS_SEC_MASK > (timestamp mask for seconds). But it subtracts a seemingly unrelated > BIT(2), which is in fact more subtle: if the hardware timestamp provides > 2 bits of partial 'seconds' timestamp, then the wraparound interval is > 2^2 == BIT(2). > > But nonetheless, it is better to express the wraparound interval in > terms of a definition we already have, so replace BIT(2) with > 1 + GENMASK(1, 0) which produces the same result but is clearer. > > Suggested-by: Russell King (Oracle) > Cc: Richard Cochran > Signed-off-by: Vladimir Oltean Thanks! Reviewed-by: Russell King (Oracle) -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!