From patchwork Mon Nov 16 00:27:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 11906999 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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_HEADER_CTYPE_ONLY,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_TVD_MIME_NO_HEADERS,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 05A40C63699 for ; Mon, 16 Nov 2020 00:28:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AB7522314 for ; Mon, 16 Nov 2020 00:28:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="AYUqGN7x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728262AbgKPA2T (ORCPT ); Sun, 15 Nov 2020 19:28:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726311AbgKPA2S (ORCPT ); Sun, 15 Nov 2020 19:28:18 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47DB3C0613CF for ; Sun, 15 Nov 2020 16:28:18 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id j19so4605883pgg.5 for ; Sun, 15 Nov 2020 16:28:18 -0800 (PST) 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=ay7zhmBkaHC5Ra+dBoVCVWdhN2ITDGmxmdv79eXwAgE=; b=AYUqGN7xNocwgnOwvymhC1iT3Cz1qCr7v9sl/J/fLYaiFdKhCEhyCYAr+B1y1Ki+hW DMCs3dc9/1+Oyazuu640E3p3g0qi2rZvP6xbbaloD9hF87mVAwmhFChnIARCVHjBjr4b 1tPvMZGVPA9EWEUuGR98btJUYk2dPmubuSVXQ= 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; bh=ay7zhmBkaHC5Ra+dBoVCVWdhN2ITDGmxmdv79eXwAgE=; b=KLz0JT9hNT9kmcGvs4dCrCiW9kmN2xaTXoPya0oFVLYJtsUJIWC1lmiFna1oJgXZrr Bwt8a/DXYpqsA9MwODJka3v1PpbHpeY2DHKcSW4IaYqeDIQraGEq5oBJpg4pYXdouG1z IsCCcFwtuC60fxI+ruUA9RFCLlmyPH89WyeL69NZIsnEwMQD0/U4yXOtZZh38FM7R2/w 6qYNyF2rSbZdXzUr+l7RlaFCC3P8paXnfyrMv/VYTMxMU+hI5ZQc8HNusupmJ7Ia9zfY h+Xc4115xg4wTj6AukKoH1wv/IczoqERbuUN//8OKcHfeB90FzfpfMdGIEmfe7z71G6u zsVQ== X-Gm-Message-State: AOAM530hEjldI+530MAiNIxVS+nwajfk2Dox4z1Zkg0pmyGl3eMFUiuc svVJ3j3tfBM2liCqMFuqUD3GWvPoM83Zag== X-Google-Smtp-Source: ABdhPJxRsVJmovsamKluv3durcCbKYX/i1N9dz6LMWfraqLLD/h4MgFRjXr9tlgyK7xizDsx0Juc+Q== X-Received: by 2002:a17:90b:1642:: with SMTP id il2mr12094688pjb.81.1605486497601; Sun, 15 Nov 2020 16:28:17 -0800 (PST) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id i19sm2942563pgk.44.2020.11.15.16.28.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Nov 2020 16:28:17 -0800 (PST) From: Michael Chan To: kuba@kernel.org Cc: netdev@vger.kernel.org, gospo@broadcom.com Subject: [PATCH net 3/4] bnxt_en: Fix counter overflow logic. Date: Sun, 15 Nov 2020 19:27:51 -0500 Message-Id: <1605486472-28156-4-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1605486472-28156-1-git-send-email-michael.chan@broadcom.com> References: <1605486472-28156-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 bnxt_add_one_ctr() adds a hardware counter to a software counter and adjusts for the hardware counter wraparound against the mask. The logic assumes that the hardware counter is always smaller than or equal to the mask. This assumption is mostly correct. But in some cases if the firmware is older and does not provide the accurate mask, the driver can use a mask that is smaller than the actual hardware mask. This can cause some extra carry bits to be added to the software counter, resulting in counters that far exceed the actual value. Fix it by masking the hardware counter with the mask passed into bnxt_add_one_ctr(). Fixes: fea6b3335527 ("bnxt_en: Accumulate all counters.") Reviewed-by: Vasundhara Volam Reviewed-by: Pavan Chebbi Reviewed-by: Edwin Peer Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 448e1ba762ee..7c21aaa8b9af 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -7758,6 +7758,7 @@ static void bnxt_add_one_ctr(u64 hw, u64 *sw, u64 mask) { u64 sw_tmp; + hw &= mask; sw_tmp = (*sw & ~mask) | hw; if (hw < (*sw & mask)) sw_tmp += mask + 1;