From patchwork Mon Jan 16 10:08:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 44062 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1115463wrn; Mon, 16 Jan 2023 02:20:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXvSvIHn8zOqia1/Uss46VGa9S4ihL83A0pDM7pRisjl0Cd4SSXXm+5HmP0i8l9cSeqHM09G X-Received: by 2002:a17:90a:bb03:b0:225:a226:9fbb with SMTP id u3-20020a17090abb0300b00225a2269fbbmr88901937pjr.39.1673864428494; Mon, 16 Jan 2023 02:20:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673864428; cv=none; d=google.com; s=arc-20160816; b=XiTZcFTX60spsScEn5s4Gd0cxzW+tqKPAr7RQYC3/MPEHom5TaeWuSfYCde2RnSliY Z156l1/ExrB4Ot2zxA0w/fqASKA084oH4Yonxe1k+B38mEY4KNe1uArs9oHaDhSXK+fC WG7bFTVle3xrxTPJ6G1K/vaeT9hxDmibIAP4ZY84DWTdhfcGJM4lOvTo69qX7U8ZsndZ RjRYBTGbK7KgUbriKNo+D7h9bUgRCXeOdlKoQ+HWv4ptu73vRTrE3fCVRBLONfgnhCFZ em5JO+z4vVociEeEfHVQ9WE9mx2aQs8lCa3y5apN7sIa2va2maFHlQifoZyzuTF12kDN y2HA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aXV8uthLhFKLHFE4WfTOFgW/y06ZjQQsGjbs7wGVQbk=; b=WxDomZn67WAkGD7udzQadb6B/h6Tp+gDN/wHqmTafp32R25y0mEDBY4pyq5NQEbOHa cESMcztzHjfomjATwOA287Q1SEB5Zl8vevierZu3yH27MIvcoL01A5JS55hi9ZVK65iF BUhUMPQ4yZOSEVh6XWc9iK/Pdbu+qiKTearuLc8Xzf1JKyRRRXuR7xvBuWFER+RnQl5c mHth4J4WiBcPwhOJt13Ssx54CCpVVyzCtn9XUbpjUndMkzdnq9L3QErWhfAv0GgImhEd wazsO6o4RWtakwZOFrkQDQhTxzW77GI8U2Idk0ykQ8uYtpeA7EXH2tA8+sNIWW/v4Eiw qoog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MlPxV5Fq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id na7-20020a17090b4c0700b0022990def3ebsi77961pjb.95.2023.01.16.02.20.15; Mon, 16 Jan 2023 02:20:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MlPxV5Fq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229867AbjAPKNW (ORCPT + 99 others); Mon, 16 Jan 2023 05:13:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbjAPKKD (ORCPT ); Mon, 16 Jan 2023 05:10:03 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B39D318B3A; Mon, 16 Jan 2023 02:09:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673863776; x=1705399776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ucEfhHA4CyaQZiOPDmYUXrJQWcd5bqBnChoqQVBwaIg=; b=MlPxV5Fq46b6gCgaK5akqOBiN29sy0e9EVdUK/a59Ze+RFbFPSfujhGn qGuZx1CoTXWdwAvd+RWNrRI2kMnW9Ens00m+qm0pBDWKkRTuQ50a9ehIn Y2pWDfFleJEUVN+hzlSBRu9fWjNofSMrZQY+HN5NaRiylioHvMDC7JhmF oswv9invLf1HoDXnCip8ffa9sKdpNTphk3TprwTemCh0hwo0nSOKO4j5/ xXTPNy7axKdKrQF0cVZnXbWUpGP83ltPdivsQ8fHqdfW4mtb/PqKSVw0B yBRD60AF3yP7EIwwhS1wQTLjJkYDuADwhzUlavHqP4DnV1JaJgNGudZhb Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10591"; a="326489352" X-IronPort-AV: E=Sophos;i="5.97,220,1669104000"; d="scan'208";a="326489352" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2023 02:09:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10591"; a="832785809" X-IronPort-AV: E=Sophos;i="5.97,220,1669104000"; d="scan'208";a="832785809" Received: from xsanroma-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.39.155]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2023 02:09:32 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-fpga@vger.kernel.org, Xu Yilun , Wu Hao , Tom Rix , Moritz Fischer , Lee Jones , Matthew Gerlach , Russ Weight , Tianfei zhang , Mark Brown , Marco Pagani , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v6 08/11] fpga: m10bmc-sec: Create helpers for rsu status/progress checks Date: Mon, 16 Jan 2023 12:08:42 +0200 Message-Id: <20230116100845.6153-9-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230116100845.6153-1-ilpo.jarvinen@linux.intel.com> References: <20230116100845.6153-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755174066604966428?= X-GMAIL-MSGID: =?utf-8?q?1755174066604966428?= RSU_STAT_* and RSU_PROG_* checks are done in more than one place in the sec update code. Move the checks into new helper functions. No function changes intended. Co-developed-by: Tianfei zhang Signed-off-by: Tianfei zhang Co-developed-by: Russ Weight Signed-off-by: Russ Weight Acked-by: Xu Yilun Signed-off-by: Ilpo Järvinen --- drivers/fpga/intel-m10-bmc-sec-update.c | 59 +++++++++++++------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c index 9922027856a4..6e58a463619c 100644 --- a/drivers/fpga/intel-m10-bmc-sec-update.c +++ b/drivers/fpga/intel-m10-bmc-sec-update.c @@ -257,6 +257,28 @@ static void log_error_regs(struct m10bmc_sec *sec, u32 doorbell) dev_err(sec->dev, "RSU auth result: 0x%08x\n", auth_result); } +static bool rsu_status_ok(u32 status) +{ + return (status == RSU_STAT_NORMAL || + status == RSU_STAT_NIOS_OK || + status == RSU_STAT_USER_OK || + status == RSU_STAT_FACTORY_OK); +} + +static bool rsu_progress_done(u32 progress) +{ + return (progress == RSU_PROG_IDLE || + progress == RSU_PROG_RSU_DONE); +} + +static bool rsu_progress_busy(u32 progress) +{ + return (progress == RSU_PROG_AUTHENTICATING || + progress == RSU_PROG_COPYING || + progress == RSU_PROG_UPDATE_CANCEL || + progress == RSU_PROG_PROGRAM_KEY_HASH); +} + static enum fw_upload_err rsu_check_idle(struct m10bmc_sec *sec) { const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; @@ -267,8 +289,7 @@ static enum fw_upload_err rsu_check_idle(struct m10bmc_sec *sec) if (ret) return FW_UPLOAD_ERR_RW_ERROR; - if (rsu_prog(doorbell) != RSU_PROG_IDLE && - rsu_prog(doorbell) != RSU_PROG_RSU_DONE) { + if (!rsu_progress_done(rsu_prog(doorbell))) { log_error_regs(sec, doorbell); return FW_UPLOAD_ERR_BUSY; } @@ -288,7 +309,7 @@ static inline bool rsu_start_done(u32 doorbell) return true; progress = rsu_prog(doorbell); - if (progress != RSU_PROG_IDLE && progress != RSU_PROG_RSU_DONE) + if (!rsu_progress_done(progress)) return true; return false; @@ -397,13 +418,7 @@ static enum fw_upload_err rsu_send_data(struct m10bmc_sec *sec) return FW_UPLOAD_ERR_RW_ERROR; } - switch (rsu_stat(doorbell)) { - case RSU_STAT_NORMAL: - case RSU_STAT_NIOS_OK: - case RSU_STAT_USER_OK: - case RSU_STAT_FACTORY_OK: - break; - default: + if (!rsu_status_ok(rsu_stat(doorbell))) { log_error_regs(sec, doorbell); return FW_UPLOAD_ERR_HW_ERROR; } @@ -418,28 +433,16 @@ static int rsu_check_complete(struct m10bmc_sec *sec, u32 *doorbell) if (m10bmc_sys_read(sec->m10bmc, csr_map->doorbell, doorbell)) return -EIO; - switch (rsu_stat(*doorbell)) { - case RSU_STAT_NORMAL: - case RSU_STAT_NIOS_OK: - case RSU_STAT_USER_OK: - case RSU_STAT_FACTORY_OK: - break; - default: + if (!rsu_status_ok(rsu_stat(*doorbell))) return -EINVAL; - } - switch (rsu_prog(*doorbell)) { - case RSU_PROG_IDLE: - case RSU_PROG_RSU_DONE: + if (rsu_progress_done(rsu_prog(*doorbell))) return 0; - case RSU_PROG_AUTHENTICATING: - case RSU_PROG_COPYING: - case RSU_PROG_UPDATE_CANCEL: - case RSU_PROG_PROGRAM_KEY_HASH: + + if (rsu_progress_busy(rsu_prog(*doorbell))) return -EAGAIN; - default: - return -EINVAL; - } + + return -EINVAL; } static enum fw_upload_err rsu_cancel(struct m10bmc_sec *sec)