From patchwork Tue Jul 12 02:26:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12914472 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F554C433EF for ; Tue, 12 Jul 2022 02:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbiGLC0r (ORCPT ); Mon, 11 Jul 2022 22:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbiGLC0o (ORCPT ); Mon, 11 Jul 2022 22:26:44 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD63C6871E for ; Mon, 11 Jul 2022 19:26:43 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id 145so6324592pga.12 for ; Mon, 11 Jul 2022 19:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dlQahWL1Yw8riOLjDvIwGRp3AwGQ4jHFvVWVNGK7Y0g=; b=cZQY50iZI1nYA0g6CRi2oe4EEhXUYk8PyqLW5/copiwBpKjeQz3ES2h6+/iGIOMK3u kjSIRyi6Cmd2FruUPDzDjgGB9Mr4WYBbfnUBsUFO0N4qTDLLGgwXbFjM4LRP+/qyDVvK y4EjzfDiJkawMfuHwag0AuHCI7FNP3GJXadGg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dlQahWL1Yw8riOLjDvIwGRp3AwGQ4jHFvVWVNGK7Y0g=; b=PgwiabGGMl9RiNRN0D7RIZOixQ7RE2FWJQLJFCPUJ/ePCQ6gpZ1Z8QaxqgONQvFU4Z Kvgh+LYqOD40WyH+gX0fHjCnClR1ZRgQuNroSwDdnp8/DFT1Q890YegvnczAqRxWkN+a b/vAKOE+C3M1gZVIS8EMfHdb85oxGxU+9dA/S1/1d3hawyAVeRtmL0rtzZuOCta+K3tl R1CF2vV6Tdir760kVN2s2IyP7xipB1NB+IC81jhQWeUDERqQIJHTqgLbmq7jSR78T+CQ 29/3RYnph3nzb5VIy/1GA5o3IoEUR1ToBUcr6B0Rz+TyvcUOgpOUmNAvQ4xmxEL0NlQp a2lg== X-Gm-Message-State: AJIora/oop87As0heGt5evD+JGEVIS3/GkT0I974tOmOteeqCZCytfx8 dlBf5En07/p0p2K+Y5vE+oqHJfJdEYJyOQow X-Google-Smtp-Source: AGRyM1ug92V3BWWgLFLV9AsdWvxwtxreC7EYl4mTHPDS2ZW+LAllXSi2D5Yya/84Z/CRHpNm28KINA== X-Received: by 2002:a63:4d26:0:b0:411:83dd:2c3 with SMTP id a38-20020a634d26000000b0041183dd02c3mr17924584pgb.508.1657592802849; Mon, 11 Jul 2022 19:26:42 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id p4-20020a62d004000000b0052878f66f8asm5443049pfg.132.2022.07.11.19.26.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jul 2022 19:26:42 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, gospo@broadcom.com, Pavan Chebbi , Richard Cochran Subject: [PATCH net 5/5] bnxt_en: Fix bnxt_refclk_read() Date: Mon, 11 Jul 2022 22:26:18 -0400 Message-Id: <1657592778-12730-6-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1657592778-12730-1-git-send-email-michael.chan@broadcom.com> References: <1657592778-12730-1-git-send-email-michael.chan@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Pavan Chebbi The upper 32-bit PHC register is not latched when reading the lower 32-bit PHC register. Current code leaves a small window where we may not read correct higher order bits if the lower order bits are just about to wrap around. This patch fixes this by reading higher order bits twice and makes sure that final value is correctly paired with its lower 32 bits. Fixes: 30e96f487f64 ("bnxt_en: Do not read the PTP PHC during chip reset") Cc: Richard Cochran Signed-off-by: Pavan Chebbi Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c index 562f8f68a47d..7f3c0875b6f5 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c @@ -76,14 +76,23 @@ static int bnxt_refclk_read(struct bnxt *bp, struct ptp_system_timestamp *sts, u64 *ns) { struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; + u32 high_before, high_now, low; if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) return -EIO; + high_before = readl(bp->bar0 + ptp->refclk_mapped_regs[1]); ptp_read_system_prets(sts); - *ns = readl(bp->bar0 + ptp->refclk_mapped_regs[0]); + low = readl(bp->bar0 + ptp->refclk_mapped_regs[0]); ptp_read_system_postts(sts); - *ns |= (u64)readl(bp->bar0 + ptp->refclk_mapped_regs[1]) << 32; + high_now = readl(bp->bar0 + ptp->refclk_mapped_regs[1]); + if (high_now != high_before) { + ptp_read_system_prets(sts); + low = readl(bp->bar0 + ptp->refclk_mapped_regs[0]); + ptp_read_system_postts(sts); + } + *ns = ((u64)high_now << 32) | low; + return 0; }