Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3114259pxm; Mon, 28 Feb 2022 12:18:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwB8xzbjhqamev3fe31iN9/DnYBeQH+HCeq8u6wcosUySsxasvRcfOY3fso9OW2rWZgbRmf X-Received: by 2002:a05:6a00:1a8f:b0:4e1:cde3:7bf7 with SMTP id e15-20020a056a001a8f00b004e1cde37bf7mr23755807pfv.52.1646079515193; Mon, 28 Feb 2022 12:18:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079515; cv=none; d=google.com; s=arc-20160816; b=EWGeEtqKKp1rxm+UpE9OW470h4upw+z3nY0LcvgdAy82pI1cX9DB+aNv+vw0PB2Vdg /r8sJkglvwwtAjlpOL0NKLtdV/50W9yLegv4Ln9hj3kM4nnFCYtm2HHt82dSb5bRMSdK fWecyd6vHOJ2zp+IHytYIb+67tp5dpK9eL3ZRf0JnpLGRvguIPWxuFas0n3mJUlbKFC5 ab4V9bcxoO74TCotaapeLCxeenyb4735aPW1LQ0IU9sJkTVOoKV4u9mWGHXmbrxGjh1x aovdbfCjAbRvhgNBol68LgdPaM0m+WbF4XPjeNC+JYC/DjH0bZo2tAiJQfkm+/J+mI9y vZGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vLdwLsRMtHREvKQ0N4ek9e76/fjzmZ9PL5d/802KTIA=; b=DOXY9SzIvzM1mOc1rVy93geoqNCu9UEcZYzsagDRt6+bxKHDu1KDUewxrdX10hdEQc AMvztB+LubNEjln/JD9mZ6JbmMYE45pwGGdAfBcDoAuBNDQN+AqvzPqpKbhpW4VdvWEE DZCd1Mkw+f2KWr5LmftvNmhNnL5CmUtnajZwJMWSyJyZ3H0lhFiCnPYBY88CRRB6xUzM Cvztvh/Znv053+3Iy+ui0G24Q/36pdgjl2MBimEIhHya/zmlGhWdnuKJDkBX61rl7Fup sY4hxM87HGkb2SNVlbU3eF98bNVLAU2pKLxFvTpb50Grzzo4LaihaBpVXHZv0Bj6ZKAu b7eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=02rxw8Ii; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s32-20020a056a0017a000b004e1a7618156si10924244pfg.237.2022.02.28.12.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:18:35 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=02rxw8Ii; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C12FB1B1241; Mon, 28 Feb 2022 11:40:31 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239703AbiB1SCN (ORCPT + 99 others); Mon, 28 Feb 2022 13:02:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238939AbiB1Ryq (ORCPT ); Mon, 28 Feb 2022 12:54:46 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDB88185; Mon, 28 Feb 2022 09:44:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A4364B81085; Mon, 28 Feb 2022 17:44:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFE69C340E7; Mon, 28 Feb 2022 17:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070259; bh=syIQldVdX7I9vkT6zF0HEwnuMxLsFBKjlVxG6GEJKu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=02rxw8IiMEio/YykV64XcFrTGiD5pZg09vAb/KYLfu7rMJX0RhyVIHsiwV6Kc8Hpg HQRVE8At/zhR+1RPhHgJqIz/71JcFY9ClcbQc5dF5J000W/98nMuL8/HqKlLxJh0rp 0BPf8LPKrTGRc89jGeJjqvM+5HRVMmafp1x7hUXc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vikas Gupta , Somnath Kotur , Kalesh AP , Michael Chan , "David S. Miller" Subject: [PATCH 5.16 043/164] bnxt_en: Fix devlink fw_activate Date: Mon, 28 Feb 2022 18:23:25 +0100 Message-Id: <20220228172404.168604422@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172359.567256961@linuxfoundation.org> References: <20220228172359.567256961@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kalesh AP commit 1278d17a1fb860e7eab4bc3ff4b026a87cbf5105 upstream. To install a livepatch, first flash the package to NVM, and then activate the patch through the "HWRM_FW_LIVEPATCH" fw command. To uninstall a patch from NVM, flash the removal package and then activate it through the "HWRM_FW_LIVEPATCH" fw command. The "HWRM_FW_LIVEPATCH" fw command has to consider following scenarios: 1. no patch in NVM and no patch active. Do nothing. 2. patch in NVM, but not active. Activate the patch currently in NVM. 3. patch is not in NVM, but active. Deactivate the patch. 4. patch in NVM and the patch active. Do nothing. Fix the code to handle these scenarios during devlink "fw_activate". To install and activate a live patch: devlink dev flash pci/0000:c1:00.0 file thor_patch.pkg devlink -f dev reload pci/0000:c1:00.0 action fw_activate limit no_reset To remove and deactivate a live patch: devlink dev flash pci/0000:c1:00.0 file thor_patch_rem.pkg devlink -f dev reload pci/0000:c1:00.0 action fw_activate limit no_reset Fixes: 3c4153394e2c ("bnxt_en: implement firmware live patching") Reviewed-by: Vikas Gupta Reviewed-by: Somnath Kotur Signed-off-by: Kalesh AP Signed-off-by: Michael Chan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 39 +++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c @@ -366,6 +366,16 @@ bnxt_dl_livepatch_report_err(struct bnxt } } +/* Live patch status in NVM */ +#define BNXT_LIVEPATCH_NOT_INSTALLED 0 +#define BNXT_LIVEPATCH_INSTALLED FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_INSTALL +#define BNXT_LIVEPATCH_REMOVED FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_ACTIVE +#define BNXT_LIVEPATCH_MASK (FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_INSTALL | \ + FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_ACTIVE) +#define BNXT_LIVEPATCH_ACTIVATED BNXT_LIVEPATCH_MASK + +#define BNXT_LIVEPATCH_STATE(flags) ((flags) & BNXT_LIVEPATCH_MASK) + static int bnxt_dl_livepatch_activate(struct bnxt *bp, struct netlink_ext_ack *extack) { @@ -373,8 +383,9 @@ bnxt_dl_livepatch_activate(struct bnxt * struct hwrm_fw_livepatch_query_input *query_req; struct hwrm_fw_livepatch_output *patch_resp; struct hwrm_fw_livepatch_input *patch_req; + u16 flags, live_patch_state; + bool activated = false; u32 installed = 0; - u16 flags; u8 target; int rc; @@ -393,7 +404,6 @@ bnxt_dl_livepatch_activate(struct bnxt * hwrm_req_drop(bp, query_req); return rc; } - patch_req->opcode = FW_LIVEPATCH_REQ_OPCODE_ACTIVATE; patch_req->loadtype = FW_LIVEPATCH_REQ_LOADTYPE_NVM_INSTALL; patch_resp = hwrm_req_hold(bp, patch_req); @@ -406,12 +416,20 @@ bnxt_dl_livepatch_activate(struct bnxt * } flags = le16_to_cpu(query_resp->status_flags); - if (~flags & FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_INSTALL) + live_patch_state = BNXT_LIVEPATCH_STATE(flags); + + if (live_patch_state == BNXT_LIVEPATCH_NOT_INSTALLED) continue; - if ((flags & FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_ACTIVE) && - !strncmp(query_resp->active_ver, query_resp->install_ver, - sizeof(query_resp->active_ver))) + + if (live_patch_state == BNXT_LIVEPATCH_ACTIVATED) { + activated = true; continue; + } + + if (live_patch_state == BNXT_LIVEPATCH_INSTALLED) + patch_req->opcode = FW_LIVEPATCH_REQ_OPCODE_ACTIVATE; + else if (live_patch_state == BNXT_LIVEPATCH_REMOVED) + patch_req->opcode = FW_LIVEPATCH_REQ_OPCODE_DEACTIVATE; patch_req->fw_target = target; rc = hwrm_req_send(bp, patch_req); @@ -423,8 +441,13 @@ bnxt_dl_livepatch_activate(struct bnxt * } if (!rc && !installed) { - NL_SET_ERR_MSG_MOD(extack, "No live patches found"); - rc = -ENOENT; + if (activated) { + NL_SET_ERR_MSG_MOD(extack, "Live patch already activated"); + rc = -EEXIST; + } else { + NL_SET_ERR_MSG_MOD(extack, "No live patches found"); + rc = -ENOENT; + } } hwrm_req_drop(bp, query_req); hwrm_req_drop(bp, patch_req);