From patchwork Fri Oct 21 06:37:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13014305 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 1973DC43219 for ; Fri, 21 Oct 2022 06:38:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbiJUGiP (ORCPT ); Fri, 21 Oct 2022 02:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbiJUGiL (ORCPT ); Fri, 21 Oct 2022 02:38:11 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 892E7237F8A for ; Thu, 20 Oct 2022 23:38:10 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id s3so1072800qtn.12 for ; Thu, 20 Oct 2022 23:38:10 -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:message-id:reply-to; bh=tZCXyj0p7JqIHVZzq2LXyEfTMmb6f88DZKl4zbGeg5A=; b=WTact+8UJWAvjzm79TfE8Cr0iA9i8KiAe1z61jWe7iH5R4ak7RS7y1f/23FSY0bk/g HADisvuba2bxTA7aH7dr5eGxCaA1xlICjGl/eU7VMXTcCDtdBLM+bNngcWHnNIs37Ss/ fBg+twVfKVHB7ybWPMRl5jeg8cdxutAgx0KjQ= 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:message-id:reply-to; bh=tZCXyj0p7JqIHVZzq2LXyEfTMmb6f88DZKl4zbGeg5A=; b=esizhLompcXVGwl+vt/+Dt8+h03+CmqRgR7nXz5VLb2RXrBDHHHvQc6dPFtduCgiLe t1d6J2iSBdHvyDeWQ2ypG0FImxoPocjz5lMlXD0wyTH9Qs8uIMW7RwklNPdY5Ww7hQjx rzpOFzaWH1IKqUAfTRFLpRiqEkeCeEtrJFxxDfU2FWwVGZLqNh/qEXm6m4tIjwCnTyyd 1+pICmuIPkuMwxB2XlWW0cvCfPQjfAc9EEu1RlGmIlH/hxrz0pRlWV4JFN4+6hBQHJRp 50XerYpVNz4p6K63GsGgvpEqYp4mNOJbPTLsPIYnM7ocufGmX8Hfk3vHIil58HC+bbG+ XHUQ== X-Gm-Message-State: ACrzQf0uPx8DuHbAF837ihLEUyzfUiXg5uIoUr6qFE9m9s4dkuEOIqhG Va+0ZijyCCJrrXAPXaISL5rgKA== X-Google-Smtp-Source: AMsMyM6SuyAZLh5KAqimR1DGqbIOlF7Wk5/oscNZmbYHmDF2uo7/7ipj0Ovak3sRhDPgjpmk0PXnmA== X-Received: by 2002:a05:622a:492:b0:39d:789:b915 with SMTP id p18-20020a05622a049200b0039d0789b915mr9460768qtx.561.1666334289948; Thu, 20 Oct 2022 23:38:09 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id t12-20020ac8588c000000b0039cd4d87aacsm7688401qta.15.2022.10.20.23.38.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Oct 2022 23:38:09 -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 v3 3/3] bnxt_en: check and resize NVRAM UPDATE entry before flashing Date: Fri, 21 Oct 2022 02:37:23 -0400 Message-Id: <1666334243-23866-4-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666334243-23866-1-git-send-email-michael.chan@broadcom.com> References: <1666334243-23866-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 44b715c4e19e..cc89e5eabcb9 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);