From patchwork Sat Oct 1 18:27:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12996646 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 117A8C43217 for ; Sat, 1 Oct 2022 18:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229599AbiJAS1b (ORCPT ); Sat, 1 Oct 2022 14:27:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiJAS12 (ORCPT ); Sat, 1 Oct 2022 14:27:28 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD3A5C9D6 for ; Sat, 1 Oct 2022 11:27:27 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id i3so4654423qkl.3 for ; Sat, 01 Oct 2022 11:27:27 -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=AXCTHbBM3xy5mO2JxnEAE9h4oLwYFoZPkYVZQMX59X8=; b=iE3Zw8AtvHyTSo7yjZ5TTZfVdsni3QUcVgtD3eK1ctc9SR5ugX9C6dXx0/G50K9qsn bX2oWqY2ovdpruGCmz8YPVm4lDzhgoj8oQD1sr+ZTvYcYxCeQ60tIJ9Nw3OnKTiaYU1F M68Iax9PXCrGQYvhpxt2HXFu260lh7AuLWPdE= 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=AXCTHbBM3xy5mO2JxnEAE9h4oLwYFoZPkYVZQMX59X8=; b=POSk8IkCusRrRO8THA+74A2Ga22WgZuVZO4dRLJTiAVNUahcsbwN2Stf/xkemg37TN mfSXotSS46+B/3KpzeqlJgJdWAyRIbyqcEXzyszdHBqT0hGEI/AoI0+4l46gSpIkoOM0 Rrj7coa9xQDgWgDbpB/UBq8hSAFkl4yIj0tF5MV3K3iGjb3EsrjNB52++1X5GVcLUxWH lMX9QGTcr5TrdllDYH6lb5g7CN1fN6FmMr+Lz5AV9WRE/NVc9ZxjigaFBwfZDEvzlpIs JpZnDnwl/VyixQ1FgqILqFyDtY8lVLKxMkX3nkSCvLdbusPiMD76yz8NsT1az+WWTwIi inEg== X-Gm-Message-State: ACrzQf0GI32/5f4GMMAjQ0PFQO9i/9vLpQKKdd+oDcTOA4vuCZwWGqCp IrWu3nTauUgtZ6sawHnHs8/y7Q== X-Google-Smtp-Source: AMsMyM6LPL1pnCl/DUK66Qy1LDXMpiG8RZ9o07C7/W1DKidVlAdRPcHl1aN95ECt0bOnnvibBCPyaA== X-Received: by 2002:a05:620a:4447:b0:6c6:c438:1ced with SMTP id w7-20020a05620a444700b006c6c4381cedmr10215496qkp.658.1664648846871; Sat, 01 Oct 2022 11:27:26 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id h14-20020a05620a400e00b006ce3f1af120sm6652830qko.44.2022.10.01.11.27.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Oct 2022 11:27:26 -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 v2 3/3] bnxt_en: check and resize NVRAM UPDATE entry before flashing Date: Sat, 1 Oct 2022 14:27:11 -0400 Message-Id: <1664648831-7965-4-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1664648831-7965-1-git-send-email-michael.chan@broadcom.com> References: <1664648831-7965-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 092cd4f98a6d..6dc3c3279acf 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);