From patchwork Sun Oct 4 19:22:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 267625 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=-13.5 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 7AA83C4363C for ; Sun, 4 Oct 2020 19:23:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32C98205ED for ; Sun, 4 Oct 2020 19:23:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="SGyzc42J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726574AbgJDTX0 (ORCPT ); Sun, 4 Oct 2020 15:23:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726294AbgJDTXZ (ORCPT ); Sun, 4 Oct 2020 15:23:25 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73661C0613CE for ; Sun, 4 Oct 2020 12:23:25 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id a17so3464798pju.1 for ; Sun, 04 Oct 2020 12:23:25 -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=FpoKpCTbdPLI9UR53Er1KFVnORcdcj7kwAsH/OEY/AA=; b=SGyzc42JvbwWgnBpnveexJaFBbnhFu7rdF7q+4zv3VoZB/i8DWS8A0CaNlBfCoMK3P ve3U2qC2UrwhpJjMLkWw+S45RQrpBtF8Czu0bLLftHaYkT5Y7k/BMfqs5T8zaz8+9sHL Q7F3YZuclmAoPHREfv7H1G6fGIC4NGVKtS4i8= 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=FpoKpCTbdPLI9UR53Er1KFVnORcdcj7kwAsH/OEY/AA=; b=WEbUAFWNVQ88LkKaq6hZ+015+/2NWb5o6WzVGahFjHNCcia2W9lSb968Fat9jIKble LPsvhalmONvL3KYqi15ZbpO6U1SEfQgJx04yetvce7IKzfCZ7iqOJ/ViRiotkf8vBnjB fRGowkgtiYFkLA1QaL+o8Y3okxrwUJmTCWLb6gPxQPR+GHpHEFSQmxdBck0e++jnhqpi bcjH7mYpvqnhp6Cu9QydPnPRIe7cCrB4JRBiPYesMuNmsNCaCto8JC2DF8lRfBIHOQ/K sCHRZHumVy44CBqOf8m7/+AJJwAuHhD2wxaBX3IMJyog0zPhsmyyXLZe3tj1gN9hY4nN ojzw== X-Gm-Message-State: AOAM5325SnrZQANL+6pjJG5F/pDEynL+mnFVwZNa1IZMVTJqNN1x3m4w bEhBO6cWP7Pz+3RjCrUbKv2KYw== X-Google-Smtp-Source: ABdhPJzDSpxsRKV2/n3S/DDcgMccbXCB3wkuIhmm4M7lzwerEcByTPrKp3a6n++2PDFReVvzztUL3A== X-Received: by 2002:a17:90a:7bcf:: with SMTP id d15mr12916988pjl.230.1601839404841; Sun, 04 Oct 2020 12:23:24 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id 138sm9824234pfu.180.2020.10.04.12.23.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Oct 2020 12:23:24 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, gospo@broadcom.com, Edwin Peer Subject: [PATCH net-next 02/11] bnxt_en: refactor bnxt_alloc_fw_health() Date: Sun, 4 Oct 2020 15:22:52 -0400 Message-Id: <1601839381-10446-3-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1601839381-10446-1-git-send-email-michael.chan@broadcom.com> References: <1601839381-10446-1-git-send-email-michael.chan@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Edwin Peer The allocator for the firmware health structure conflates allocation and capability checks, limiting the reusability of the code. This patch separates out the capability check and disablement and improves the warning message to better describe the consequences of an allocation failure. Signed-off-by: Edwin Peer Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 60 ++++++++++++++--------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 38bbd7631fca..cf730ec92a0f 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -7336,6 +7336,36 @@ static int bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(struct bnxt *bp) return rc; } +static int __bnxt_alloc_fw_health(struct bnxt *bp) +{ + if (bp->fw_health) + return 0; + + bp->fw_health = kzalloc(sizeof(*bp->fw_health), GFP_KERNEL); + if (!bp->fw_health) + return -ENOMEM; + + return 0; +} + +static int bnxt_alloc_fw_health(struct bnxt *bp) +{ + int rc; + + if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET) && + !(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)) + return 0; + + rc = __bnxt_alloc_fw_health(bp); + if (rc) { + bp->fw_cap &= ~BNXT_FW_CAP_HOT_RESET; + bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY; + return rc; + } + + return 0; +} + static int bnxt_map_fw_health_regs(struct bnxt *bp) { struct bnxt_fw_health *fw_health = bp->fw_health; @@ -10966,23 +10996,6 @@ static void bnxt_init_dflt_coal(struct bnxt *bp) bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS; } -static void bnxt_alloc_fw_health(struct bnxt *bp) -{ - if (bp->fw_health) - return; - - if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET) && - !(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)) - return; - - bp->fw_health = kzalloc(sizeof(*bp->fw_health), GFP_KERNEL); - if (!bp->fw_health) { - netdev_warn(bp->dev, "Failed to allocate fw_health\n"); - bp->fw_cap &= ~BNXT_FW_CAP_HOT_RESET; - bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY; - } -} - static int bnxt_fw_init_one_p1(struct bnxt *bp) { int rc; @@ -11029,11 +11042,14 @@ static int bnxt_fw_init_one_p2(struct bnxt *bp) netdev_warn(bp->dev, "hwrm query adv flow mgnt failure rc: %d\n", rc); - bnxt_alloc_fw_health(bp); - rc = bnxt_hwrm_error_recovery_qcfg(bp); - if (rc) - netdev_warn(bp->dev, "hwrm query error recovery failure rc: %d\n", - rc); + if (bnxt_alloc_fw_health(bp)) { + netdev_warn(bp->dev, "no memory for firmware error recovery\n"); + } else { + rc = bnxt_hwrm_error_recovery_qcfg(bp); + if (rc) + netdev_warn(bp->dev, "hwrm query error recovery failure rc: %d\n", + rc); + } rc = bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, false); if (rc)