From patchwork Wed Sep 28 00:58:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12991534 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 11D87C07E9D for ; Wed, 28 Sep 2022 00:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230172AbiI1A7d (ORCPT ); Tue, 27 Sep 2022 20:59:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbiI1A72 (ORCPT ); Tue, 27 Sep 2022 20:59:28 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 818B8160E7B for ; Tue, 27 Sep 2022 17:59:21 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id w9so1439970qvn.11 for ; Tue, 27 Sep 2022 17:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date; bh=/8ANvmu+ien/gHvB0OZs/R0iiX33ilJLPxiQyamxSbs=; b=DkafteW2OMO+4KggWIpIEJUZJAwzFuxRtHoFvtHnE3RrKozv9VzkbX0Y2IfkNY3C37 6gJLyMj2+UXY4tYcGUOenauPXz7Axf18srLFvD9HGuZWIbHaB6B7AyRU/okM0pNfkI2Q nMmcoaAmPJ5VFPQN46HE0KguwT47FRTEPaPa4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date; bh=/8ANvmu+ien/gHvB0OZs/R0iiX33ilJLPxiQyamxSbs=; b=38CSefdXSSu/VLrC+4VaTP0HUMMNY2ucV3vS3sJDzu6ZDGVsGfYiCDrDSLBC6ND9Fs xCKc5PIMjpv1retij47Yj5a+W5iqIzAR5aUN9Bz1GZZBcXjGiQ5VLrtBCWBHGZAs1vGH NOSmoziweTwG4bqbwyL8cKzeNLBlKQtURPB6iDP8SnHjFHJ4RITcvUqjXEaTLjTeo+c7 Fle41iLWpiaHEZkP3gvYN19wRm6lVMc3YKYsUVYacW8dGJhBssp7cXH4eR4N/6Xv5xsF ZEM0SUYC2VvT6obHuhiVY7AQj5rBaPJ668bE66SfQeGJpMAPg/rU9CGOycerzgRbmolp +bfw== X-Gm-Message-State: ACrzQf1awaC3YiQE8NAGC5oZQxfMEKvRFyMIE4aTAwZhIivGThZx8UTC R7zPX1Ju4IVkdxQmGZgZL7xqnH2pd2hVmmaZ X-Google-Smtp-Source: AMsMyM4BKcJHYbRn9D0frGUtGJ3jUDBJ1EmznkH1xP7LOU3U9z3xl0C1duKtZFPLgImsokGVrgLBag== X-Received: by 2002:a05:6214:21e9:b0:4ac:9bfb:e7b1 with SMTP id p9-20020a05621421e900b004ac9bfbe7b1mr24437132qvj.99.1664326760732; Tue, 27 Sep 2022 17:59:20 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id i11-20020a05620a248b00b006cbb8ca04f8sm2078668qkn.40.2022.09.27.17.59.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Sep 2022 17:59:20 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, gospo@broadcom.com, vikas.gupta@broadcom.com Subject: [PATCH net-next 6/6] bnxt_en: check and resize NVRAM UPDATE entry before flashing Date: Tue, 27 Sep 2022 20:58:44 -0400 Message-Id: <1664326724-1415-7-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1664326724-1415-1-git-send-email-michael.chan@broadcom.com> References: <1664326724-1415-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: Vikas Gupta Resize of the UPDATE entry is required if the image to be flashed is larger than the available space. Add this step, otherwise flashing larger firmware images by ethtool or devlink may fail. Reviewed-by: Andy Gospodarek Signed-off-by: Vikas Gupta Signed-off-by: Michael Chan --- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index 2b18af95aacb..2f97f41408e7 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -2514,6 +2514,7 @@ static int bnxt_flash_firmware_from_file(struct net_device *dev, #define MSG_INTERNAL_ERR "PKG install error : Internal error" #define MSG_NO_PKG_UPDATE_AREA_ERR "PKG update area not created in nvram" #define MSG_NO_SPACE_ERR "PKG insufficient update area in nvram" +#define MSG_RESIZE_UPDATE_ERR "Resize UPDATE entry error" #define MSG_ANTI_ROLLBACK_ERR "HWRM_NVM_INSTALL_UPDATE failure due to Anti-rollback detected" #define MSG_GENERIC_FAILURE_ERR "HWRM_NVM_INSTALL_UPDATE failure" @@ -2564,6 +2565,32 @@ static int nvm_update_err_to_stderr(struct net_device *dev, u8 result, #define BNXT_NVM_MORE_FLAG (cpu_to_le16(NVM_MODIFY_REQ_FLAGS_BATCH_MODE)) #define BNXT_NVM_LAST_FLAG (cpu_to_le16(NVM_MODIFY_REQ_FLAGS_BATCH_LAST)) +static int bnxt_resize_update_entry(struct net_device *dev, size_t fw_size, + struct netlink_ext_ack *extack) +{ + u32 item_len; + int rc; + + rc = bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE, + BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, NULL, + &item_len, NULL); + if (rc) { + BNXT_NVM_ERR_MSG(dev, extack, MSG_NO_PKG_UPDATE_AREA_ERR); + return rc; + } + + if (fw_size > item_len) { + rc = bnxt_flash_nvram(dev, BNX_DIR_TYPE_UPDATE, + BNX_DIR_ORDINAL_FIRST, 0, 1, + round_up(fw_size, 4096), NULL, 0); + if (rc) { + BNXT_NVM_ERR_MSG(dev, extack, MSG_RESIZE_UPDATE_ERR); + return rc; + } + } + return 0; +} + int bnxt_flash_package_from_fw_obj(struct net_device *dev, const struct firmware *fw, u32 install_type, struct netlink_ext_ack *extack) { @@ -2580,6 +2607,11 @@ int bnxt_flash_package_from_fw_obj(struct net_device *dev, const struct firmware u16 index; int rc; + /* resize before flashing larger image than available space */ + rc = bnxt_resize_update_entry(dev, fw->size, extack); + if (rc) + return rc; + bnxt_hwrm_fw_set_time(bp); rc = hwrm_req_init(bp, modify, HWRM_NVM_MODIFY);