From patchwork Mon Jun 14 13:44:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12318967 X-Patchwork-Delegate: kuba@kernel.org 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 22646C4743C for ; Mon, 14 Jun 2021 13:45:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C05961352 for ; Mon, 14 Jun 2021 13:45:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234234AbhFNNrI (ORCPT ); Mon, 14 Jun 2021 09:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234209AbhFNNrF (ORCPT ); Mon, 14 Jun 2021 09:47:05 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F9D0C061574 for ; Mon, 14 Jun 2021 06:45:02 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id l1so16722558ejb.6 for ; Mon, 14 Jun 2021 06:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ooqFNZfnR/s9okR3m5H2rRBaiu37jKflQXhtJLrUE8c=; b=Hf/T/pqVipE4iw/vhI4QH7DtFZJPfcwaa7FWUe5tIyQACIG/NXcNef7JDogRF3Tj8C VfeIBW8OzCB4ZjFhr1yZPzO9PwR3kQowG4ZsowR0j/x04aElIWvN9jhHnWq2fFr1Qd+E hPuxoL8Ht/Hi00X03YLnmYWRvN//Id/OorNQWpYH2UXuAM6ZDhZRNHDNTbzqHDmStZqH V9x0PjSEiKSEV2HCC36H96FKilI1gnkzK8f0HKuzrDOhpR19prHf1zOsMtV5qESmb03Y i5Y4s5Fdua+tbixneiMW/OSs40c+xB8GXlC1CNn9cDs6Ra230JADd0Btiq68rZEZJhi7 zwlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ooqFNZfnR/s9okR3m5H2rRBaiu37jKflQXhtJLrUE8c=; b=Pkp1Pi/nKNgYA+F2uYr+JKLWLvTDBAMY6Z65hzlkVcKCEVRSNGwkcwjB7yuOdYIkmH OZSotq8NnPJWAL/fo53FGU4OV78cj7PcK3e7/dCKEjNfvYE1kTe3hMrsqs1vBW3w5Jzw LeUKhiZiyelSfK0xqL7uocfLFffycqut4cozyV92vE42+zUJ/9NPrvrOr6gSol3U/GMD vw0Z3im4RS5abGHl8pxvfvOHLAAtvK4dxGBhbehYizjuRCQY1SUp+6D3e4MLjQSvRvM2 BjK+rPzLFs4zTTqjvMAVFxVOqBgRL+4XG4LrOMDivDMzztbdA0sArsPaiHAPoEkVLVCH QbSA== X-Gm-Message-State: AOAM532d26ZsxQz4uzO8ZZke4rSvIoHHdf37WEKFxEGL8s+dhMzaiA5J Gvs5N9EnD9eDuW9eim3MXAQ= X-Google-Smtp-Source: ABdhPJyAlZWV0pcyVaqbLF1qmL1+BQGFJE98hcwTEJQhzfUAuRUaVA0qNOeR1piB+tTfovgr8LEmUg== X-Received: by 2002:a17:906:d297:: with SMTP id ay23mr15284438ejb.418.1623678300738; Mon, 14 Jun 2021 06:45:00 -0700 (PDT) Received: from localhost.localdomain ([188.26.224.68]) by smtp.gmail.com with ESMTPSA id q20sm7626891ejb.71.2021.06.14.06.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 06:45:00 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , Radu Pirea , Vladimir Oltean , Richard Cochran , Russell King Subject: [PATCH v3 net-next 1/4] net: phy: nxp-c45-tja11xx: demote the "no PTP support" message to debug Date: Mon, 14 Jun 2021 16:44:38 +0300 Message-Id: <20210614134441.497008-2-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614134441.497008-1-olteanv@gmail.com> References: <20210614134441.497008-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The SJA1110 switch integrates these PHYs, and they do not have support for timestamping. This message becomes quite overwhelming: [ 10.056596] NXP C45 TJA1103 spi1.0-base-t1:01: the phy does not support PTP [ 10.112625] NXP C45 TJA1103 spi1.0-base-t1:02: the phy does not support PTP [ 10.167461] NXP C45 TJA1103 spi1.0-base-t1:03: the phy does not support PTP [ 10.223510] NXP C45 TJA1103 spi1.0-base-t1:04: the phy does not support PTP [ 10.278239] NXP C45 TJA1103 spi1.0-base-t1:05: the phy does not support PTP [ 10.332663] NXP C45 TJA1103 spi1.0-base-t1:06: the phy does not support PTP [ 15.390828] NXP C45 TJA1103 spi1.2-base-t1:01: the phy does not support PTP [ 15.445224] NXP C45 TJA1103 spi1.2-base-t1:02: the phy does not support PTP [ 15.499673] NXP C45 TJA1103 spi1.2-base-t1:03: the phy does not support PTP [ 15.554074] NXP C45 TJA1103 spi1.2-base-t1:04: the phy does not support PTP [ 15.608516] NXP C45 TJA1103 spi1.2-base-t1:05: the phy does not support PTP [ 15.662996] NXP C45 TJA1103 spi1.2-base-t1:06: the phy does not support PTP So reduce its log level to debug. Cc: Richard Cochran Signed-off-by: Vladimir Oltean Reviewed-by: Andrew Lunn Reviewed-by: Russell King (Oracle) --- v2->v3: none v1->v2: none drivers/net/phy/nxp-c45-tja11xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c index 512e4cb5d2c2..902fe1aa7782 100644 --- a/drivers/net/phy/nxp-c45-tja11xx.c +++ b/drivers/net/phy/nxp-c45-tja11xx.c @@ -1090,7 +1090,7 @@ static int nxp_c45_probe(struct phy_device *phydev) VEND1_PORT_ABILITIES); ptp_ability = !!(ptp_ability & PTP_ABILITY); if (!ptp_ability) { - phydev_info(phydev, "the phy does not support PTP"); + phydev_dbg(phydev, "the phy does not support PTP"); goto no_ptp_support; } From patchwork Mon Jun 14 13:44:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12318973 X-Patchwork-Delegate: kuba@kernel.org 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 4E0FEC2B9F4 for ; Mon, 14 Jun 2021 13:46:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19505611CE for ; Mon, 14 Jun 2021 13:46:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234194AbhFNNsU (ORCPT ); Mon, 14 Jun 2021 09:48:20 -0400 Received: from mail-ej1-f44.google.com ([209.85.218.44]:45823 "EHLO mail-ej1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233716AbhFNNsS (ORCPT ); Mon, 14 Jun 2021 09:48:18 -0400 Received: by mail-ej1-f44.google.com with SMTP id k7so16774471ejv.12 for ; Mon, 14 Jun 2021 06:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4Ts50fnE/tCIfiSguG3xBKowkdguDptHLAm3c2fP9Co=; b=nIjW8I6R+5Vay5SzFHKqfjXFUSeVrzWNlHS/Y0DXiyDy6Rsuu2eANLevx7Lv1zC5p+ vbLw2ow0FQx/Y4eFRJnBBSr9onOMV0KpwCLmSDKdKm7XzXLjKxMA2JXxruJLh8MHzDcG nkuQCc0ftnP1lH4nY72mQI3nD4WTnn8ovVQXTCjQpCAdxckILEyYYt4Xurob+eE71QHA rjczoRN7DSL7LEt4I4gqd8W110TSWVYB7hBo8FOVcUSToV2qKS/4YaWS/PHv/anVvU2a 0UCUwlCDUR7YGAWhQWOJBwzqVtOnOvdS4t/LR/FqViYOYoTaX9JNoIts4HCuhNicbhx8 NYGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Ts50fnE/tCIfiSguG3xBKowkdguDptHLAm3c2fP9Co=; b=P4EwO8R1fbslERjY2OfNnUpuqqm5Cbv/vZiX+IZFuEgqaLn0UjJKvqRZ5SY6YPH/L/ xfzXQquksY4LcXC4nwqb3s5tc9jgEUi+zXROKmWRkKnuvBI6BjRr0+jDwvaNnnRx/3Wp 5iwkLEmn2h465G/JUJpNPpJ4PoZDMyDYbsAYNvlV65IrH7w1tmrlq0rzHThZCiowevy6 JyeZqIjo/D1pN7ZfpCW5v+R4Iwg3IVWiUdGWdzoudP7UmAzdPMylBAlzvSWsnUCzscMW BEbATKLjsMoqtx2cfWyKNY0ssFB7NrQm9X7Fw0PauYHwYm6hKu0F12dJ9inD4aZNXPKV CbIA== X-Gm-Message-State: AOAM532QebMwLci6aRrDzjJKxtih/AOp/FEZjhx95SCwSVG+b8KL3ya8 QElqar1AKT5EvHAYPsYxG/Q= X-Google-Smtp-Source: ABdhPJwqGtj5z44vZessRmIoRVaLjZZ7DgBqTrGEnXh8nZq9rFGDJm11Zrc6Hk/Uj6qXMjqg17yQvw== X-Received: by 2002:a17:906:9883:: with SMTP id zc3mr15488410ejb.530.1623678301934; Mon, 14 Jun 2021 06:45:01 -0700 (PDT) Received: from localhost.localdomain ([188.26.224.68]) by smtp.gmail.com with ESMTPSA id q20sm7626891ejb.71.2021.06.14.06.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 06:45:01 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , Radu Pirea , Vladimir Oltean , Russell King , Richard Cochran Subject: [PATCH v3 net-next 2/4] net: phy: nxp-c45-tja11xx: express timestamp wraparound interval in terms of TS_SEC_MASK Date: Mon, 14 Jun 2021 16:44:39 +0300 Message-Id: <20210614134441.497008-3-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614134441.497008-1-olteanv@gmail.com> References: <20210614134441.497008-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Russell King (Oracle) --- v2->v3: Patch is new drivers/net/phy/nxp-c45-tja11xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c index 902fe1aa7782..afdcd6772b1d 100644 --- a/drivers/net/phy/nxp-c45-tja11xx.c +++ b/drivers/net/phy/nxp-c45-tja11xx.c @@ -325,7 +325,7 @@ static void nxp_c45_reconstruct_ts(struct timespec64 *ts, { ts->tv_nsec = hwts->nsec; if ((ts->tv_sec & TS_SEC_MASK) < (hwts->sec & TS_SEC_MASK)) - ts->tv_sec -= BIT(2); + ts->tv_sec -= TS_SEC_MASK + 1; ts->tv_sec &= ~TS_SEC_MASK; ts->tv_sec |= hwts->sec & TS_SEC_MASK; } From patchwork Mon Jun 14 13:44:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12318969 X-Patchwork-Delegate: kuba@kernel.org 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 9FC77C2B9F4 for ; Mon, 14 Jun 2021 13:45:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AF44611EE for ; Mon, 14 Jun 2021 13:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234249AbhFNNrI (ORCPT ); Mon, 14 Jun 2021 09:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234228AbhFNNrH (ORCPT ); Mon, 14 Jun 2021 09:47:07 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 578AEC061574 for ; Mon, 14 Jun 2021 06:45:04 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id g20so16886085ejt.0 for ; Mon, 14 Jun 2021 06:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=klcxm9Fxa3xtqDLM+t/LhJnL0HzSyyWp/UHyUzDlKMw=; b=I9BNYQiqZacDNStrUawl1/9YT6+BmbN98U19u87LBzgvIzMZZXri7YiEqaAjQH8X3s 0vAXxPpvXXeSv/LdHQNjOERP7rLQI64o7UuDtLHxzRLTU0W0JhVrKRrvZ3cw1GCqKvL2 g4jmbxu+L8wbxpzNc/e0YtRuBmvoV6/8EoqD15ckUiHrADdA9CP2mfy6zcAlNZxRZoKj U1ex00nrLoFqG9PknB9TNxzgzaVKyzyG4qZBZKPYtYt7y66CQpNqaresymZP+1h9VxNk DeUjGy0NsTz2/5gLNBjEZujx46eZqlfrCclUA2hywQW+mbdg+EBT//MYoPMPcRRaALWo o5Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=klcxm9Fxa3xtqDLM+t/LhJnL0HzSyyWp/UHyUzDlKMw=; b=Hvhat6tGHc9ysd5Od5Ak9u5JtAA7rhzTYmt7lrVcjsbZDUv7EbVExfQ8Mf6v79fN8s +qvsMxp5M56LWuG8p2Xd2YkSDSWrvVg20pVz9QmVT4DPW4QtGEPatv5p8svqDZSSGFk7 A/u7jwKF+YBeEnt/IpVBJJIQ0IcPeOgNv1SNQjJyq444mNHpcRcpmM+dxwBNUFG0UFpg XtAgo4p1SgJONb7GlbZm+U6PHE8g8XRTz4d7+ikFwtHxQA+X0YIimsvMnnrWBF1LJjKz alFs8IMdf5pWBPmFviPEALTVm5aW78pIAg2w9nSldCfDT2LHzg/1CGDBCF86udaq46Q5 kQQw== X-Gm-Message-State: AOAM5303yqGTd+jWHYlUzyj3Kht4IHNYlWyoScceC9rp6NMvKyvP2gET OS6cFuNaJ3eIcajfpepG+ng= X-Google-Smtp-Source: ABdhPJz5cTem4QZSkMD3r3iAQErJtXcPyTiKVkDb/Bb5U0wwIu00UnLLdBdzU4GNeSqUeqQ0mVr6Cw== X-Received: by 2002:a17:906:4e91:: with SMTP id v17mr15767757eju.119.1623678302985; Mon, 14 Jun 2021 06:45:02 -0700 (PDT) Received: from localhost.localdomain ([188.26.224.68]) by smtp.gmail.com with ESMTPSA id q20sm7626891ejb.71.2021.06.14.06.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 06:45:02 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , Radu Pirea , Vladimir Oltean , Richard Cochran , Russell King Subject: [PATCH v3 net-next 3/4] net: phy: nxp-c45-tja11xx: fix potential RX timestamp wraparound Date: Mon, 14 Jun 2021 16:44:40 +0300 Message-Id: <20210614134441.497008-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614134441.497008-1-olteanv@gmail.com> References: <20210614134441.497008-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The reconstruction procedure for partial timestamps reads the current PTP time and fills in the low 2 bits of the second portion, as well as the nanoseconds portion, from the actual hardware packet timestamp. Critically, the reconstruction procedure works because it assumes that the current PTP time is strictly larger than the hardware timestamp was: it detects a 2-bit wraparound of the 'seconds' portion by checking whether the 'seconds' portion of the partial hardware timestamp is larger than the 'seconds' portion of the current time. That can only happen if the hardware timestamp was captured by the PHY during the last phase of a 'modulo 4 seconds' interval, and the current PTP time was read by the driver during the initial phase of the next 'modulo 4 seconds' interval. The partial RX timestamps are added to priv->rx_queue in nxp_c45_rxtstamp() and they are processed potentially in parallel by the aux worker thread in nxp_c45_do_aux_work(). This means that it is possible for nxp_c45_do_aux_work() to process more than one RX timestamp during the same schedule. There is one premature optimization that will cause issues: for RX timestamping, the driver reads the current time only once, and it uses that to reconstruct all PTP RX timestamps in the queue. For the second and later timestamps, this will be an issue if we are processing two RX timestamps which are to the left and to the right, respectively, of a 4-bit wraparound of the 'seconds' portion of the PTP time, and the current PTP time is also pre-wraparound. 0.000000000 4.000000000 8.000000000 12.000000000 |..................|..................|..................|............> ^ ^ ^ ^ time | | | | | | | process hwts 1 and hwts 2 | | | | | hwts 2 | | | read current PTP time | hwts 1 What will happen in that case is that hwts 2 (post-wraparound) will use a stale current PTP time that is pre-wraparound. But nxp_c45_reconstruct_ts will not detect this condition, because it is not coded up for it, so it will reconstruct hwts 2 with a current time from the previous 4 second interval (i.e. 0.something instead of 4.something). This is solvable by making sure that the full 64-bit current time is always read after the PHY has taken the partial RX timestamp. We do this by reading the current PTP time for every timestamp in the RX queue. Fixes: 514def5dd339 ("phy: nxp-c45-tja11xx: add timestamping support") Cc: Richard Cochran Signed-off-by: Vladimir Oltean Reviewed-by: Russell King (Oracle) --- v2->v3: none v1->v2: none drivers/net/phy/nxp-c45-tja11xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c index afdcd6772b1d..7eac58b78c53 100644 --- a/drivers/net/phy/nxp-c45-tja11xx.c +++ b/drivers/net/phy/nxp-c45-tja11xx.c @@ -427,8 +427,8 @@ static long nxp_c45_do_aux_work(struct ptp_clock_info *ptp) nxp_c45_process_txts(priv, &hwts); } - nxp_c45_ptp_gettimex64(&priv->caps, &ts, NULL); while ((skb = skb_dequeue(&priv->rx_queue)) != NULL) { + nxp_c45_ptp_gettimex64(&priv->caps, &ts, NULL); ts_raw = __be32_to_cpu(NXP_C45_SKB_CB(skb)->header->reserved2); hwts.sec = ts_raw >> 30; hwts.nsec = ts_raw & GENMASK(29, 0); From patchwork Mon Jun 14 13:44:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12318971 X-Patchwork-Delegate: kuba@kernel.org 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 A028FC4743C for ; Mon, 14 Jun 2021 13:45:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A8476102A for ; Mon, 14 Jun 2021 13:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234235AbhFNNrK (ORCPT ); Mon, 14 Jun 2021 09:47:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234236AbhFNNrI (ORCPT ); Mon, 14 Jun 2021 09:47:08 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4232CC061766 for ; Mon, 14 Jun 2021 06:45:05 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id nd37so9058440ejc.3 for ; Mon, 14 Jun 2021 06:45:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pYAlKvmW5lcfzA9vZ07hoaBCM+nPWTi/IELfi/4MJBE=; b=vKEz5hMoyDofoAvSZ+iODlyx2tXmi9dwVO2Y+hYq9OgZmpGzrN4KylEEc12bHdIZvo iqe/+hGaoS3SJ82/o/zSJNFBh+B3Yaik5zFeU4zcQ1V6pvLiTYo4Kx4APqozz5tNA30A +PxAYwJdafXcaDZxYWuFchKh/nYWe+V7/0s0sXHKigpNPu1QcZL71dj9HDXa3cWzP5+E NtiEp/+25D7CW9FqQf6vyu2BBWY00QXzzJ2XS4iCJVjM/L9sAUMQD3h6J2FXOoMzAJaY K8xETdJJXgFNa1WwlHuGgobZ4xkbrIUKyRKsnsgTaioTyCYKtFdHnqdnFn6r/9dlaKhx U1FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pYAlKvmW5lcfzA9vZ07hoaBCM+nPWTi/IELfi/4MJBE=; b=IVHTvMTfGItt20SnFHCMjIFsmY921BU9QbMn1TK4p/TwI6bE6HkGLNovlq4SxMm4LB Xf+TTSWu3AdzFHTOaTsULAJCA1sHxkb8eEfDppvglVtH0KIyW01RLnKF1HTJCr/fLu9x B0YFR9Q9g3hMhUnMlKetoybz7qMntq7rWyzDAFK5EPDmwltlN0PaGsyx0QjSbj8QWfPw 0CpuBkZ/nU2PXV5Y98P21bfBTnjs0K60nfYkGOct29vRyco8M32oEPGZH0lSH9b24bRq vOtoZ849tSiVUj1aUQZNJr9HGLW2foFXGJo2Zy6CgbCRxf4qRnhcQEfNcRh4Ecyb9Dj2 Fn2w== X-Gm-Message-State: AOAM530wDIjbYdeGMhHk3hy/BWAGc9txKLje0A2upm28v9UDOfsduBJG ilX7/rxwvBxVwteOA/S3hjU= X-Google-Smtp-Source: ABdhPJzCVmGGx//8ctED9VVV5C2lBnzVneyBBj5CIoh5tSCr5mRLDD2qmwsjeqsudQQzQBnZTMVIuA== X-Received: by 2002:a17:906:a18b:: with SMTP id s11mr15549942ejy.8.1623678303931; Mon, 14 Jun 2021 06:45:03 -0700 (PDT) Received: from localhost.localdomain ([188.26.224.68]) by smtp.gmail.com with ESMTPSA id q20sm7626891ejb.71.2021.06.14.06.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 06:45:03 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , Radu Pirea , Vladimir Oltean , Russell King Subject: [PATCH v3 net-next 4/4] net: phy: nxp-c45-tja11xx: enable MDIO write access to the master/slave registers Date: Mon, 14 Jun 2021 16:44:41 +0300 Message-Id: <20210614134441.497008-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614134441.497008-1-olteanv@gmail.com> References: <20210614134441.497008-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The SJA1110 switch integrates TJA1103 PHYs, but in SJA1110 switch rev B silicon, there is a bug in that the registers for selecting the 100base-T1 autoneg master/slave roles are not writable. To enable write access to the master/slave registers, these additional PHY writes are necessary during initialization. The issue has been corrected in later SJA1110 silicon versions and is not present in the standalone PHY variants, but applying the workaround unconditionally in the driver should not do any harm. Suggested-by: Radu Pirea (NXP OSS) Signed-off-by: Vladimir Oltean Reviewed-by: Russell King (Oracle) --- v2->v3: none v1->v2: added a comment drivers/net/phy/nxp-c45-tja11xx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/phy/nxp-c45-tja11xx.c b/drivers/net/phy/nxp-c45-tja11xx.c index 7eac58b78c53..91a327f67a42 100644 --- a/drivers/net/phy/nxp-c45-tja11xx.c +++ b/drivers/net/phy/nxp-c45-tja11xx.c @@ -1035,6 +1035,12 @@ static int nxp_c45_config_init(struct phy_device *phydev) return ret; } + /* Bug workaround for SJA1110 rev B: enable write access + * to MDIO_MMD_PMAPMD + */ + phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01F8, 1); + phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x01F9, 2); + phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, VEND1_PHY_CONFIG, PHY_CONFIG_AUTO);