From patchwork Tue Jul 5 08:00:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tianfei" X-Patchwork-Id: 12906059 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 F2A2AC433EF for ; Tue, 5 Jul 2022 08:06:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbiGEIEh (ORCPT ); Tue, 5 Jul 2022 04:04:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiGEIEg (ORCPT ); Tue, 5 Jul 2022 04:04:36 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C1D6333 for ; Tue, 5 Jul 2022 01:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657008275; x=1688544275; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sYCLhLPVwk8pA42DL08CmkRgLi2ztKgNK8cqO0fxJiw=; b=IHS97HAp18OH3MH1CMeSmwoZKMWAuQ/6TTQnOuSbp5ns3zka4j5jGOyS PltT8lL+ehyODwZSr9Kd2bqKXplQX0n4KgIpdP1lFNVajsJDshmOzhXJt Vchx3QATQsmfNQbdn/3VXL9UpYKR5n1EIe1s9NoW7VIsZ1np+lFBtBB7A sRyHuRzxkNmMjKgy47Tt9Rf/AIae6M8R3Wt77A+hrX9V9KBN1H34wi8JI +A+FpycC1ZynAsK4YUhzrFAce4N2O7+c/jDGjfkGFytZI3hVueUB6REva EiJaaGlanHw8icGVcUz0QwYJ0jvTJF9FakOXvKZHiW7RrfEXhevpTFVcL w==; X-IronPort-AV: E=McAfee;i="6400,9594,10398"; a="369609012" X-IronPort-AV: E=Sophos;i="5.92,245,1650956400"; d="scan'208";a="369609012" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 01:04:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,245,1650956400"; d="scan'208";a="919613413" Received: from unknown (HELO localhost.localdomain.sh.intel.com) ([10.238.175.107]) by fmsmga005.fm.intel.com with ESMTP; 05 Jul 2022 01:04:33 -0700 From: Tianfei Zhang To: mdf@kernel.org, yilun.xu@intel.com, lee.jones@linaro.org, russell.h.weight@intel.com Cc: hao.wu@intel.com, trix@redhat.com, linux-fpga@vger.kernel.org, Tianfei Zhang Subject: [PATCH v1 1/3] mfd: intel-m10-bmc: add m10bmc_sys_update_bits API Date: Tue, 5 Jul 2022 04:00:56 -0400 Message-Id: <20220705080058.92532-2-tianfei.zhang@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220705080058.92532-1-tianfei.zhang@intel.com> References: <20220705080058.92532-1-tianfei.zhang@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org Adds register access helper functions for M10BMC. m10bmc_raw_update_bits() uses to update m10bmc register bits per addr. m10bmc_sys_update_bits() uses to update m10bmc system register bits per offset. Signed-off-by: Tianfei Zhang --- include/linux/mfd/intel-m10-bmc.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/mfd/intel-m10-bmc.h b/include/linux/mfd/intel-m10-bmc.h index f0044b14136e..8e434886a5a1 100644 --- a/include/linux/mfd/intel-m10-bmc.h +++ b/include/linux/mfd/intel-m10-bmc.h @@ -133,6 +133,8 @@ struct intel_m10bmc { * * m10bmc_raw_read - read m10bmc register per addr * m10bmc_sys_read - read m10bmc system register per offset + * m10bmc_raw_update_bits - update m10bmc register bits per addr + * m10bmc_sys_update_bits - update m10bmc system register bits per offset */ static inline int m10bmc_raw_read(struct intel_m10bmc *m10bmc, unsigned int addr, @@ -148,6 +150,20 @@ m10bmc_raw_read(struct intel_m10bmc *m10bmc, unsigned int addr, return ret; } +static inline int +m10bmc_raw_update_bits(struct intel_m10bmc *m10bmc, unsigned int addr, + unsigned int msk, unsigned int val) +{ + int ret; + + ret = regmap_update_bits(m10bmc->regmap, addr, msk, val); + if (ret) + dev_err(m10bmc->dev, "fail to update reg bits %x: %d\n", + addr, ret); + + return ret; +} + /* * The base of the system registers could be configured by HW developers, and * in HW SPEC, the base is not added to the addresses of the system registers. @@ -158,5 +174,7 @@ m10bmc_raw_read(struct intel_m10bmc *m10bmc, unsigned int addr, */ #define m10bmc_sys_read(m10bmc, offset, val) \ m10bmc_raw_read(m10bmc, M10BMC_SYS_BASE + (offset), val) +#define m10bmc_sys_update_bits(m10bmc, offset, msk, val) \ + m10bmc_raw_update_bits(m10bmc, M10BMC_SYS_BASE + (offset), msk, val) #endif /* __MFD_INTEL_M10_BMC_H */ From patchwork Tue Jul 5 08:00:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tianfei" X-Patchwork-Id: 12906061 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 F0433CCA47C for ; Tue, 5 Jul 2022 08:06:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbiGEIEk (ORCPT ); Tue, 5 Jul 2022 04:04:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiGEIEj (ORCPT ); Tue, 5 Jul 2022 04:04:39 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556056333 for ; Tue, 5 Jul 2022 01:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657008278; x=1688544278; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=229hhrunAiPVA8D+jsEf+MoFO4/vbqwtX+J+v92oXTg=; b=CULmr0P3cn5O57lnZ7xF+l2gu0qA4b9C1cdxOjUDareD1fWgOSNMICG2 HA4DfXoLlZMTxr4z1PnIzk9oaQ+zNXy4/b7e8ZChPQ8d7OuyQRIJ+rBJa gn5CFj+iBEJDnH4WFCKRbIPxQLMTFbNkYZMRQsDwpXwW21vE2Xi1wBrc/ ZrkWnvzh8WZH4XD8IxClok1JWV3DwwGz+UaurBiNqV0kpK/CMRi7RFF6m IKZx9JOl8POduhRWj4ko9R/HZM4evymKQPp8fYFU4otp/p3ixKX9/dtRC OjVPfhvYmVf8K13sPtlZezTvUG+jBGAspIfx9eJJTw8VRNA/kf3mCt0ji A==; X-IronPort-AV: E=McAfee;i="6400,9594,10398"; a="369609029" X-IronPort-AV: E=Sophos;i="5.92,245,1650956400"; d="scan'208";a="369609029" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 01:04:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,245,1650956400"; d="scan'208";a="919613425" Received: from unknown (HELO localhost.localdomain.sh.intel.com) ([10.238.175.107]) by fmsmga005.fm.intel.com with ESMTP; 05 Jul 2022 01:04:36 -0700 From: Tianfei Zhang To: mdf@kernel.org, yilun.xu@intel.com, lee.jones@linaro.org, russell.h.weight@intel.com Cc: hao.wu@intel.com, trix@redhat.com, linux-fpga@vger.kernel.org, Tianfei Zhang Subject: [PATCH v1 2/3] fpga: m10bmc-sec: add sysfs to load bmc images Date: Tue, 5 Jul 2022 04:00:57 -0400 Message-Id: <20220705080058.92532-3-tianfei.zhang@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220705080058.92532-1-tianfei.zhang@intel.com> References: <20220705080058.92532-1-tianfei.zhang@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Russ Weight Add the available_images and image_load sysfs files. The available_images file returns a space separated list of key words that may be written into the image_load file. These keywords describe an FPGA, BMC, or firmware image in FLASH or EEPROM storage that may be loaded. The image_load sysfs file may be written with a key word to trigger a reload of an FPGA, BMC, or firmware image from FLASH or EEPROM. Signed-off-by: Russ Weight Signed-off-by: Tianfei Zhang --- .../sysfs-driver-intel-m10-bmc-sec-update | 21 ++++ drivers/fpga/intel-m10-bmc-sec-update.c | 104 ++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-sec-update b/Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-sec-update index 0a41afe0ab4c..8ded1a59d4db 100644 --- a/Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-sec-update +++ b/Documentation/ABI/testing/sysfs-driver-intel-m10-bmc-sec-update @@ -59,3 +59,24 @@ Contact: Russ Weight Description: Read only. Returns number of times the secure update staging area has been flashed. Format: "%u". + +What: /sys/bus/platform/drivers/intel-m10bmc-sec-update/.../control/available_images +Date: July 2022 +KernelVersion: 5.20 +Contact: Russ Weight +Description: Read-only. This file returns a space separated list of + key words that may be written into the image_load file + described below. These keywords decribe an FPGA, BMC, + or firmware image in FLASH or EEPROM storage that may + be loaded. + +What: /sys/bus/platform/drivers/intel-m10bmc-sec-update/.../control/image_load +Date: July 2022 +KernelVersion: 5.20 +Contact: Russ Weight +Description: Write-only. A key word may be written to this file to + trigger a reload of an FPGA, BMC, or firmware image from + FLASH or EEPROM. Refer to the available_images file for a + list of supported key words for the underlying device. + Writing an unsupported string to this file will result in + EINVAL being returned. diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c index 72c677c910de..640690e6c131 100644 --- a/drivers/fpga/intel-m10-bmc-sec-update.c +++ b/drivers/fpga/intel-m10-bmc-sec-update.c @@ -14,6 +14,8 @@ #include #include +struct image_load; + struct m10bmc_sec { struct device *dev; struct intel_m10bmc *m10bmc; @@ -21,6 +23,12 @@ struct m10bmc_sec { char *fw_name; u32 fw_name_id; bool cancel_request; + struct image_load *image_load; /* terminated with { } member */ +}; + +struct image_load { + const char *name; + int (*load_image)(struct m10bmc_sec *sec); }; static DEFINE_XARRAY_ALLOC(fw_upload_xa); @@ -137,6 +145,54 @@ DEVICE_ATTR_SEC_CSK_RO(pr, PR_PROG_ADDR + CSK_VEC_OFFSET); #define FLASH_COUNT_SIZE 4096 /* count stored as inverted bit vector */ +static ssize_t available_images_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct m10bmc_sec *sec = dev_get_drvdata(dev); + const struct image_load *hndlr; + ssize_t count = 0; + + for (hndlr = sec->image_load; hndlr->name; hndlr++) { + count += scnprintf(buf + count, PAGE_SIZE - count, + "%s ", hndlr->name); + } + + buf[count - 1] = '\n'; + + return count; +} +static DEVICE_ATTR_RO(available_images); + +static ssize_t image_load_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct m10bmc_sec *sec = dev_get_drvdata(dev); + const struct image_load *hndlr; + int ret = -EINVAL; + + for (hndlr = sec->image_load; hndlr->name; hndlr++) { + if (sysfs_streq(buf, hndlr->name)) { + ret = hndlr->load_image(sec); + break; + } + } + + return ret ? : count; +} +static DEVICE_ATTR_WO(image_load); + +static struct attribute *m10bmc_control_attrs[] = { + &dev_attr_available_images.attr, + &dev_attr_image_load.attr, + NULL, +}; + +static struct attribute_group m10bmc_control_attr_group = { + .name = "control", + .attrs = m10bmc_control_attrs, +}; + static ssize_t flash_count_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -195,6 +251,7 @@ static struct attribute_group m10bmc_security_attr_group = { static const struct attribute_group *m10bmc_sec_attr_groups[] = { &m10bmc_security_attr_group, + &m10bmc_control_attr_group, NULL, }; @@ -208,6 +265,52 @@ static void log_error_regs(struct m10bmc_sec *sec, u32 doorbell) dev_err(sec->dev, "RSU auth result: 0x%08x\n", auth_result); } +static int m10bmc_sec_bmc_image_load(struct m10bmc_sec *sec, + unsigned int val) +{ + u32 doorbell; + int ret; + + if (val > 1) { + dev_err(sec->dev, "invalid reload val = %d\n", val); + return -EINVAL; + } + + ret = m10bmc_sys_read(sec->m10bmc, M10BMC_DOORBELL, &doorbell); + if (ret) + return ret; + + if (doorbell & DRBL_REBOOT_DISABLED) + return -EBUSY; + + return m10bmc_sys_update_bits(sec->m10bmc, M10BMC_DOORBELL, + DRBL_CONFIG_SEL | DRBL_REBOOT_REQ, + FIELD_PREP(DRBL_CONFIG_SEL, val) | + DRBL_REBOOT_REQ); +} + +static int m10bmc_sec_bmc_image_load_0(struct m10bmc_sec *sec) +{ + return m10bmc_sec_bmc_image_load(sec, 0); +} + +static int m10bmc_sec_bmc_image_load_1(struct m10bmc_sec *sec) +{ + return m10bmc_sec_bmc_image_load(sec, 1); +} + +static struct image_load m10bmc_image_load_hndlrs[] = { + { + .name = "bmc_factory", + .load_image = m10bmc_sec_bmc_image_load_1, + }, + { + .name = "bmc_user", + .load_image = m10bmc_sec_bmc_image_load_0, + }, + {} +}; + static enum fw_upload_err rsu_check_idle(struct m10bmc_sec *sec) { u32 doorbell; @@ -565,6 +668,7 @@ static int m10bmc_sec_probe(struct platform_device *pdev) sec->dev = &pdev->dev; sec->m10bmc = dev_get_drvdata(pdev->dev.parent); dev_set_drvdata(&pdev->dev, sec); + sec->image_load = m10bmc_image_load_hndlrs; ret = xa_alloc(&fw_upload_xa, &sec->fw_name_id, sec, xa_limit_32b, GFP_KERNEL); From patchwork Tue Jul 5 08:00:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tianfei" X-Patchwork-Id: 12906060 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 D76D2C43334 for ; Tue, 5 Jul 2022 08:06:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbiGEIEl (ORCPT ); Tue, 5 Jul 2022 04:04:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiGEIEl (ORCPT ); Tue, 5 Jul 2022 04:04:41 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 889A713DCB for ; Tue, 5 Jul 2022 01:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657008280; x=1688544280; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5OhNO3QKRYcfdKbQEgyyRfE3Soczzj0MVnPRAls7E4g=; b=UJkD9k+x2G1WJJ4skr+btChpw6suFzXV2+OkZIRgW3gxcMo38branNbb GKyZOlOMvUYnFaAIY16qjChh+88eVmuPNZs+XFFmPJUQ9/L6ZhnBSgXSs Z5tFVKAZH5ET/r2p9/RcYd+am4++c8x6FCyw+xo0t+lV/G4u9wMGkzpWE G8MQVSdrWRi4DOr/42FnSwhghHkqs+VZpmwkHMl+g49mS0IxRSfyFpz+m 0lnmJ5KuTyxt1gCXLSAHGF2aFF6HeBXYe81xzNI2SHIwNSZw9nVGariba D/LlefK7bpTzQmnpr6/VEBj/VNLjMpLxGPrFYzGj76jADNTd+VKIM+IGT w==; X-IronPort-AV: E=McAfee;i="6400,9594,10398"; a="369609036" X-IronPort-AV: E=Sophos;i="5.92,245,1650956400"; d="scan'208";a="369609036" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 01:04:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,245,1650956400"; d="scan'208";a="919613432" Received: from unknown (HELO localhost.localdomain.sh.intel.com) ([10.238.175.107]) by fmsmga005.fm.intel.com with ESMTP; 05 Jul 2022 01:04:38 -0700 From: Tianfei Zhang To: mdf@kernel.org, yilun.xu@intel.com, lee.jones@linaro.org, russell.h.weight@intel.com Cc: hao.wu@intel.com, trix@redhat.com, linux-fpga@vger.kernel.org, Tianfei Zhang Subject: [PATCH v1 3/3] fpga: m10bmc-sec: add m10bmc_sec_retimer_load callback Date: Tue, 5 Jul 2022 04:00:58 -0400 Message-Id: <20220705080058.92532-4-tianfei.zhang@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220705080058.92532-1-tianfei.zhang@intel.com> References: <20220705080058.92532-1-tianfei.zhang@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Russ Weight Create m10bmc_sec_retimer_load() callback function to provide a trigger to update a new retimer (Intel C827 Ethernet transceiver) firmware on Intel PAC N3000 Card. Signed-off-by: Russ Weight Signed-off-by: Tianfei Zhang --- drivers/fpga/intel-m10-bmc-sec-update.c | 146 ++++++++++++++++++++++++ include/linux/mfd/intel-m10-bmc.h | 31 +++++ 2 files changed, 177 insertions(+) diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c index 640690e6c131..707dfd8a1931 100644 --- a/drivers/fpga/intel-m10-bmc-sec-update.c +++ b/drivers/fpga/intel-m10-bmc-sec-update.c @@ -299,6 +299,148 @@ static int m10bmc_sec_bmc_image_load_1(struct m10bmc_sec *sec) return m10bmc_sec_bmc_image_load(sec, 1); } +static int trigger_retimer_eeprom_load(struct m10bmc_sec *sec) +{ + struct intel_m10bmc *m10bmc = sec->m10bmc; + unsigned int val; + int ret; + + ret = m10bmc_sys_update_bits(m10bmc, M10BMC_DOORBELL, + DRBL_PKVL_EEPROM_LOAD_SEC, + DRBL_PKVL_EEPROM_LOAD_SEC); + if (ret) + return ret; + + /* + * If the current NIOS FW supports this retimer update feature, then + * it will clear the same PKVL_EEPROM_LOAD bit in 2 seconds. Otherwise + * the driver needs to clear the PKVL_EEPROM_LOAD bit manually and + * return an error code. + */ + ret = regmap_read_poll_timeout(m10bmc->regmap, + M10BMC_SYS_BASE + M10BMC_DOORBELL, val, + (!(val & DRBL_PKVL_EEPROM_LOAD_SEC)), + M10BMC_PKVL_LOAD_INTERVAL_US, + M10BMC_PKVL_LOAD_TIMEOUT_US); + if (ret == -ETIMEDOUT) { + dev_err(sec->dev, "PKVL_EEPROM_LOAD clear timedout\n"); + m10bmc_sys_update_bits(m10bmc, M10BMC_DOORBELL, + DRBL_PKVL_EEPROM_LOAD_SEC, 0); + ret = -ENODEV; + } else if (ret) { + dev_err(sec->dev, "poll EEPROM_LOAD error %d\n", ret); + } + + return ret; +} + +static int poll_retimer_eeprom_load_done(struct m10bmc_sec *sec) +{ + struct intel_m10bmc *m10bmc = sec->m10bmc; + unsigned int doorbell; + int ret; + + /* + * RSU_STAT_PKVL_REJECT indicates that the current image is + * already programmed. RSU_PROG_PKVL_PROM_DONE that the firmware + * update process has finished, but does not necessarily indicate + * a successful update. + */ + ret = regmap_read_poll_timeout(m10bmc->regmap, + M10BMC_SYS_BASE + M10BMC_DOORBELL, + doorbell, + ((rsu_prog(doorbell) == + RSU_PROG_PKVL_PROM_DONE) || + (rsu_stat(doorbell) == + RSU_STAT_PKVL_REJECT)), + M10BMC_PKVL_PRELOAD_INTERVAL_US, + M10BMC_PKVL_PRELOAD_TIMEOUT_US); + if (ret) { + if (ret == -ETIMEDOUT) + dev_err(sec->dev, + "Doorbell check timedout: 0x%08x\n", doorbell); + else + dev_err(sec->dev, "poll Doorbell error\n"); + return ret; + } + + if (rsu_stat(doorbell) == RSU_STAT_PKVL_REJECT) { + dev_err(sec->dev, "duplicate image rejected\n"); + return -ECANCELED; + } + + return 0; +} + +static int poll_retimer_preload_done(struct m10bmc_sec *sec) +{ + struct intel_m10bmc *m10bmc = sec->m10bmc; + unsigned int val; + int ret; + + /* + * Wait for the updated firmware to be loaded by the PKVL device + * and confirm that the updated firmware is operational + */ + ret = regmap_read_poll_timeout(m10bmc->regmap, + M10BMC_SYS_BASE + M10BMC_PKVL_POLL_CTRL, val, + ((val & M10BMC_PKVL_PRELOAD) == M10BMC_PKVL_PRELOAD), + M10BMC_PKVL_PRELOAD_INTERVAL_US, + M10BMC_PKVL_PRELOAD_TIMEOUT_US); + if (ret) { + dev_err(sec->dev, "poll M10BMC_PKVL_PRELOAD error %d\n", ret); + return ret; + } + + if ((val & M10BMC_PKVL_UPG_STATUS_MASK) != M10BMC_PKVL_UPG_STATUS_GOOD) { + dev_err(sec->dev, "error detected during upgrade\n"); + return -EIO; + } + + return 0; +} + +static int retimer_check_idle(struct m10bmc_sec *sec) +{ + u32 doorbell; + int ret; + + ret = m10bmc_sys_read(sec->m10bmc, M10BMC_DOORBELL, &doorbell); + if (ret) + return -EIO; + + if (rsu_prog(doorbell) != RSU_PROG_IDLE && + rsu_prog(doorbell) != RSU_PROG_RSU_DONE && + rsu_prog(doorbell) != RSU_PROG_PKVL_PROM_DONE) { + log_error_regs(sec, doorbell); + return -EBUSY; + } + + return 0; +} + +static int m10bmc_sec_retimer_eeprom_load(struct m10bmc_sec *sec) +{ + int ret; + + ret = retimer_check_idle(sec); + if (ret) + goto exit; + + ret = trigger_retimer_eeprom_load(sec); + if (ret) + goto exit; + + ret = poll_retimer_eeprom_load_done(sec); + if (ret) + goto exit; + + ret = poll_retimer_preload_done(sec); + +exit: + return ret; +} + static struct image_load m10bmc_image_load_hndlrs[] = { { .name = "bmc_factory", @@ -308,6 +450,10 @@ static struct image_load m10bmc_image_load_hndlrs[] = { .name = "bmc_user", .load_image = m10bmc_sec_bmc_image_load_0, }, + { + .name = "retimer_fw", + .load_image = m10bmc_sec_retimer_eeprom_load, + }, {} }; diff --git a/include/linux/mfd/intel-m10-bmc.h b/include/linux/mfd/intel-m10-bmc.h index 8e434886a5a1..23025e4d2779 100644 --- a/include/linux/mfd/intel-m10-bmc.h +++ b/include/linux/mfd/intel-m10-bmc.h @@ -36,6 +36,37 @@ #define M10BMC_VER_PCB_INFO_MSK GENMASK(31, 24) #define M10BMC_VER_LEGACY_INVALID 0xffffffff +/* Retimer related registers, in system register region */ +#define M10BMC_PKVL_POLL_CTRL 0x80 +#define M10BMC_PKVL_A_PRELOAD BIT(16) +#define M10BMC_PKVL_A_PRELOAD_TO BIT(17) +#define M10BMC_PKVL_A_DATA_TOO_BIG BIT(18) +#define M10BMC_PKVL_A_HDR_CKSUM BIT(20) +#define M10BMC_PKVL_B_PRELOAD BIT(24) +#define M10BMC_PKVL_B_PRELOAD_TO BIT(25) +#define M10BMC_PKVL_B_DATA_TOO_BIG BIT(26) +#define M10BMC_PKVL_B_HDR_CKSUM BIT(28) + +#define M10BMC_PKVL_PRELOAD (M10BMC_PKVL_A_PRELOAD | M10BMC_PKVL_B_PRELOAD) +#define M10BMC_PKVL_PRELOAD_TIMEOUT (M10BMC_PKVL_A_PRELOAD_TO | \ + M10BMC_PKVL_B_PRELOAD_TO) +#define M10BMC_PKVL_DATA_TOO_BIG (M10BMC_PKVL_A_DATA_TOO_BIG | \ + M10BMC_PKVL_B_DATA_TOO_BIG) +#define M10BMC_PKVL_HDR_CHECKSUM (M10BMC_PKVL_A_HDR_CKSUM | \ + M10BMC_PKVL_B_HDR_CKSUM) + +#define M10BMC_PKVL_UPG_STATUS_MASK (M10BMC_PKVL_PRELOAD | M10BMC_PKVL_PRELOAD_TIMEOUT |\ + M10BMC_PKVL_DATA_TOO_BIG | M10BMC_PKVL_HDR_CHECKSUM) +#define M10BMC_PKVL_UPG_STATUS_GOOD (M10BMC_PKVL_PRELOAD | M10BMC_PKVL_HDR_CHECKSUM) + +/* interval 100ms and timeout 2s */ +#define M10BMC_PKVL_LOAD_INTERVAL_US (100 * 1000) +#define M10BMC_PKVL_LOAD_TIMEOUT_US (2 * 1000 * 1000) + +/* interval 100ms and timeout 30s */ +#define M10BMC_PKVL_PRELOAD_INTERVAL_US (100 * 1000) +#define M10BMC_PKVL_PRELOAD_TIMEOUT_US (30 * 1000 * 1000) + /* Secure update doorbell register, in system register region */ #define M10BMC_DOORBELL 0x400