Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3886612pxb; Mon, 1 Feb 2021 07:11:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSi7eQBNxyZHMHMbM+Xb/POjPD6+CuOG5WyEUToEUQAPeFWnVYCw4Jh+1hPl1zfFRs0ong X-Received: by 2002:adf:eccc:: with SMTP id s12mr12422721wro.383.1612192307692; Mon, 01 Feb 2021 07:11:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612192307; cv=none; d=google.com; s=arc-20160816; b=I8IcYBfQsGoUqnXf/ABnuUTF2y0vW9Dx+ZKAZeNkpCVe8I/libJd3RvhxQjnK1NdVI pXwcibwTSB/GvD9ohBXUmv57efnOOn31r2OOxPActV6YhwUD7WMUx0nG4xE1s2h03wSL OESPY6ijJ3mQI6Ry/SMMUBfR2R6BH0A2fi0Nt3V5J8vUv7JaJsd2cN9f473+Ss71ZZD7 t02UP2CMilWnZX52+uZYJzUGXuKpfORGzOBu5CpaN+ytESWR3dXs/ANhwejQ/AvR+vIj etvWYCuVDrhnGglXzSiOnBMVvoN0rnXACONoEs5uYWc9Jds6/q6cAntPXRXzT4SAfjaP YhMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=tyD3Ivv3zM1UlNxoqMzjAvt+uqupEg+1s8S/nR8UPCU=; b=meZrPoWc+O8LROIhyDbO2HXwx+z1NTyHM/fVy39APeEKKcP392gkISZf3dLB0dx6co sfh5lC7foWtVNJhvgETxlbqF41vHJrChYIxhZACaBzSmErnjjFQMz5ahugZPu/ugk/Iq 3V05Kr0bgUQVISOGIca2yI4NMIiAzo+L2qj18zZTT8g9+qNWOAl3iVU5rNMn+IQ+ep7d KPP2YS86UxiSL1exaAzbUY7flFn+x195uVcW2qLSSQ8pflXf4wPNF4bYERY2xYC7mSJ/ CERMBOzINc4rJ8sxQd01hZuzBV5jugO0NsClaeVQzFXwExdRThQdsevyl6C339LbRpOO a/Mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g1si12021537ejf.121.2021.02.01.07.11.18; Mon, 01 Feb 2021 07:11:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231440AbhBAPIn (ORCPT + 99 others); Mon, 1 Feb 2021 10:08:43 -0500 Received: from mga06.intel.com ([134.134.136.31]:33905 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231423AbhBAPI0 (ORCPT ); Mon, 1 Feb 2021 10:08:26 -0500 IronPort-SDR: phvDUMW2mBS2AUWremSqHGyT9chhi8hObLT8FljAjrOnkwPMZp8AO1KQRsDgyov87p25BDSYws VZZVNLQGCvXw== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="242214691" X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="242214691" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 07:02:33 -0800 IronPort-SDR: BGsvKW673ilgXMvy1mKx8OOo8EIcUDcfBRzsnP/z64p7GS1ndIFY4xaxABY4YA28oP4dYVFToD H0p4DaAfmSkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="369891585" Received: from marshy.an.intel.com ([10.122.105.143]) by fmsmga008.fm.intel.com with ESMTP; 01 Feb 2021 07:02:32 -0800 From: richard.gong@linux.intel.com To: mdf@kernel.org, trix@redhat.com, gregkh@linuxfoundation.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Gong Subject: [PATCHv4 6/6] fpga: stratix10-soc: extend driver for bitstream authentication Date: Mon, 1 Feb 2021 09:21:59 -0600 Message-Id: <1612192919-4069-7-git-send-email-richard.gong@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> References: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Richard Gong Extend FPGA manager driver to support FPGA bitstream authentication on Intel SocFPGA platforms. Signed-off-by: Richard Gong --- v4: s/FPGA_MGR_BITSTREM_AUTHENTICATION/FPGA_MGR_BITSTREAM_AUTHENTICATE v3: add handle to retriev the firmware version to keep driver back compatible v2: use flag defined in stratix10-svc driver --- drivers/fpga/stratix10-soc.c | 62 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c index 657a70c..9ab7afd 100644 --- a/drivers/fpga/stratix10-soc.c +++ b/drivers/fpga/stratix10-soc.c @@ -24,6 +24,10 @@ #define S10_BUFFER_TIMEOUT (msecs_to_jiffies(SVC_RECONFIG_BUFFER_TIMEOUT_MS)) #define S10_RECONFIG_TIMEOUT (msecs_to_jiffies(SVC_RECONFIG_REQUEST_TIMEOUT_MS)) +#define INVALID_FIRMWARE_VERSION 0xFFFF +typedef void (*s10_callback)(struct stratix10_svc_client *client, + struct stratix10_svc_cb_data *data); + /* * struct s10_svc_buf * buf: virtual address of buf provided by service layer @@ -40,11 +44,13 @@ struct s10_priv { struct completion status_return_completion; struct s10_svc_buf svc_bufs[NUM_SVC_BUFS]; unsigned long status; + unsigned int fw_version; }; static int s10_svc_send_msg(struct s10_priv *priv, enum stratix10_svc_command_code command, - void *payload, u32 payload_length) + void *payload, u32 payload_length, + s10_callback callback) { struct stratix10_svc_chan *chan = priv->chan; struct device *dev = priv->client.dev; @@ -57,6 +63,7 @@ static int s10_svc_send_msg(struct s10_priv *priv, msg.command = command; msg.payload = payload; msg.payload_length = payload_length; + priv->client.receive_cb = callback; ret = stratix10_svc_send(chan, &msg); dev_dbg(dev, "stratix10_svc_send returned status %d\n", ret); @@ -134,6 +141,29 @@ static void s10_unlock_bufs(struct s10_priv *priv, void *kaddr) } /* + * s10_fw_version_callback - callback for the version of running firmware + * @client: service layer client struct + * @data: message from service layer + */ +static void s10_fw_version_callback(struct stratix10_svc_client *client, + struct stratix10_svc_cb_data *data) +{ + struct s10_priv *priv = client->priv; + unsigned int *version = (unsigned int *)data->kaddr1; + + if (data->status == BIT(SVC_STATUS_OK)) + priv->fw_version = *version; + else if (data->status == BIT(SVC_STATUS_NO_SUPPORT)) + dev_warn(client->dev, + "FW doesn't support bitstream authentication\n"); + else + dev_err(client->dev, "Failed to get FW version %lu\n", + BIT(data->status)); + + complete(&priv->status_return_completion); +} + +/* * s10_receive_callback - callback for service layer to use to provide client * (this driver) messages received through the mailbox. * client: service layer client struct @@ -186,13 +216,22 @@ static int s10_ops_write_init(struct fpga_manager *mgr, if (info->flags & FPGA_MGR_PARTIAL_RECONFIG) { dev_dbg(dev, "Requesting partial reconfiguration.\n"); ctype.flags |= BIT(COMMAND_RECONFIG_FLAG_PARTIAL); + } else if (info->flags & FPGA_MGR_BITSTREAM_AUTHENTICATE) { + if (priv->fw_version == INVALID_FIRMWARE_VERSION) { + dev_err(dev, "FW doesn't support\n"); + return -EINVAL; + } + + dev_dbg(dev, "Requesting bitstream authentication.\n"); + ctype.flags |= BIT(COMMAND_AUTHENTICATE_BITSTREAM); } else { dev_dbg(dev, "Requesting full reconfiguration.\n"); } reinit_completion(&priv->status_return_completion); ret = s10_svc_send_msg(priv, COMMAND_RECONFIG, - &ctype, sizeof(ctype)); + &ctype, sizeof(ctype), + s10_receive_callback); if (ret < 0) goto init_done; @@ -259,7 +298,7 @@ static int s10_send_buf(struct fpga_manager *mgr, const char *buf, size_t count) svc_buf = priv->svc_bufs[i].buf; memcpy(svc_buf, buf, xfer_sz); ret = s10_svc_send_msg(priv, COMMAND_RECONFIG_DATA_SUBMIT, - svc_buf, xfer_sz); + svc_buf, xfer_sz, s10_receive_callback); if (ret < 0) { dev_err(dev, "Error while sending data to service layer (%d)", ret); @@ -303,7 +342,7 @@ static int s10_ops_write(struct fpga_manager *mgr, const char *buf, ret = s10_svc_send_msg( priv, COMMAND_RECONFIG_DATA_CLAIM, - NULL, 0); + NULL, 0, s10_receive_callback); if (ret < 0) break; } @@ -357,7 +396,8 @@ static int s10_ops_write_complete(struct fpga_manager *mgr, do { reinit_completion(&priv->status_return_completion); - ret = s10_svc_send_msg(priv, COMMAND_RECONFIG_STATUS, NULL, 0); + ret = s10_svc_send_msg(priv, COMMAND_RECONFIG_STATUS, + NULL, 0, s10_receive_callback); if (ret < 0) break; @@ -411,8 +451,9 @@ static int s10_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; + priv->fw_version = INVALID_FIRMWARE_VERSION; priv->client.dev = dev; - priv->client.receive_cb = s10_receive_callback; + priv->client.receive_cb = NULL; priv->client.priv = priv; priv->chan = stratix10_svc_request_channel_byname(&priv->client, @@ -440,6 +481,15 @@ static int s10_probe(struct platform_device *pdev) goto probe_err; } + /* get the running firmware version */ + ret = s10_svc_send_msg(priv, COMMAND_FIRMWARE_VERSION, + NULL, 0, s10_fw_version_callback); + if (ret) { + dev_err(dev, "couldn't get firmware version\n"); + fpga_mgr_free(mgr); + goto probe_err; + } + platform_set_drvdata(pdev, mgr); return ret; -- 2.7.4