From patchwork Fri Dec 8 18:46:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 10103155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 56E72602A0 for ; Fri, 8 Dec 2017 18:51:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4806828697 for ; Fri, 8 Dec 2017 18:51:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C8D128EEA; Fri, 8 Dec 2017 18:51:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D5EA28EAB for ; Fri, 8 Dec 2017 18:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752707AbdLHSvB (ORCPT ); Fri, 8 Dec 2017 13:51:01 -0500 Received: from smtp2.infineon.com ([217.10.52.18]:19571 "EHLO smtp2.infineon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752338AbdLHSvA (ORCPT ); Fri, 8 Dec 2017 13:51:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1512759060; x=1544295060; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=J4gFIrd3Ovnc927l5lfwpxLPVTmtaO49nMKizBwB354=; b=hG8nQXv+PCUreTmq6HOxcon7lFZ7S78qV2tsU89Y7eO6yWGcfgpWb0Kf jCa0PyoOGRnxjK5LGjCMQw4XLlpSiS7hrPeZHj6JLvAP9bwNbgxgNSM/K dtAsA04Fot7feKIRV1yqLH9eUZ6DzbOLYz5gYq/UZT1E10IU6vY0sbGRg 0=; X-SBRS: None Received: from unknown (HELO mucxv001.muc.infineon.com) ([172.23.11.16]) by smtp2.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 08 Dec 2017 19:50:59 +0100 Received: from MUCSE708.infineon.com (mucse708.infineon.com [172.23.7.82]) by mucxv001.muc.infineon.com (Postfix) with ESMTPS; Fri, 8 Dec 2017 19:50:59 +0100 (CET) Received: from ABGN5CG4522MQD.eu.infineon.com (172.23.8.247) by MUCSE708.infineon.com (172.23.7.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.669.32; Fri, 8 Dec 2017 19:50:58 +0100 From: Alexander Steffen To: , , , CC: Alexander Steffen Subject: [RFC][PATCH 5/9] tpm_tis_core: use XDATA_FIFO for transfers if available Date: Fri, 8 Dec 2017 19:46:54 +0100 Message-ID: <20171208184658.9588-6-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 In-Reply-To: <20171208184658.9588-1-Alexander.Steffen@infineon.com> References: <20171208184658.9588-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [172.23.8.247] X-ClientProxiedBy: MUCSE706.infineon.com (172.23.7.80) To MUCSE708.infineon.com (172.23.7.82) Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The TPM indicates in DataTransferSizeSupport in TPM_INTF_CAPABILITY what the maximum supported transfer size is. Transfers larger than four bytes are only supported for the XDATA_FIFO, not the legacy DATA_FIFO. Therefore, always use the XDATA_FIFO when the TPM indicates support for non-legacy transfer sizes for maximum throughput. Signed-off-by: Alexander Steffen --- drivers/char/tpm/tpm_tis_core.c | 24 ++++++++++++++++++++++-- drivers/char/tpm/tpm_tis_core.h | 4 ++++ drivers/char/tpm/tpm_tis_spi.c | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 1359c52..7240ee4 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -255,7 +255,8 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) } burstcnt = min_t(int, burstcnt, count - size); - rc = tpm_tis_read_bytes(priv, TPM_DATA_FIFO(priv->locality), + rc = tpm_tis_read_bytes(priv, ADD_LOCALITY(priv->fifo_address, + priv->locality), burstcnt, buf + size); if (rc < 0) return rc; @@ -340,7 +341,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) goto out_err; } burstcnt = min_t(int, burstcnt, len - count); - rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), + rc = tpm_tis_write_bytes(priv, ADD_LOCALITY(priv->fifo_address, + priv->locality), burstcnt, buf + count); if (rc < 0) goto out_err; @@ -742,6 +744,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, chip->timeout_c = msecs_to_jiffies(TIS_TIMEOUT_C_MAX); chip->timeout_d = msecs_to_jiffies(TIS_TIMEOUT_D_MAX); priv->phy_ops = phy_ops; + priv->max_transfer_size = 4; dev_set_drvdata(&chip->dev, priv); if (wait_startup(chip, 0) != 0) { @@ -794,6 +797,23 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_dbg(dev, "\tSts Valid Int Support\n"); if (intfcaps & TPM_INTF_DATA_AVAIL_INT) dev_dbg(dev, "\tData Avail Int Support\n"); + switch ((intfcaps >> 9) & 3) { + case 0: + priv->fifo_address = TPM_DATA_FIFO(0); + break; + case 1: + priv->fifo_address = TPM_XDATA_FIFO(0); + priv->max_transfer_size = 8; + break; + case 2: + priv->fifo_address = TPM_XDATA_FIFO(0); + priv->max_transfer_size = 32; + break; + case 3: + priv->fifo_address = TPM_XDATA_FIFO(0); + priv->max_transfer_size = 64; + break; + } rc = tpm2_probe(chip); if (rc) diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 357df13..b7df6ee 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -67,6 +67,7 @@ enum tis_defaults { #define TIS_TIMEOUT_C_MAX max(TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_C) #define TIS_TIMEOUT_D_MAX max(TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_D) +#define ADD_LOCALITY(r, l) ((r) | ((l) << 12)) #define TPM_ACCESS(l) (0x0000 | ((l) << 12)) #define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12)) #define TPM_INT_VECTOR(l) (0x000C | ((l) << 12)) @@ -75,6 +76,7 @@ enum tis_defaults { #define TPM_STS(l) (0x0018 | ((l) << 12)) #define TPM_STS3(l) (0x001b | ((l) << 12)) #define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12)) +#define TPM_XDATA_FIFO(l) (0x0080 | ((l) << 12)) #define TPM_DID_VID(l) (0x0F00 | ((l) << 12)) #define TPM_RID(l) (0x0F04 | ((l) << 12)) @@ -86,6 +88,8 @@ enum tpm_tis_flags { struct tpm_tis_data { u16 manufacturer_id; int locality; + u8 fifo_address; + u8 max_transfer_size; int irq; bool irq_tested; unsigned int flags; diff --git a/drivers/char/tpm/tpm_tis_spi.c b/drivers/char/tpm/tpm_tis_spi.c index 424ff2f..c4f511b 100644 --- a/drivers/char/tpm/tpm_tis_spi.c +++ b/drivers/char/tpm/tpm_tis_spi.c @@ -67,7 +67,7 @@ static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, spi_bus_lock(phy->spi_device->master); while (len) { - transfer_len = min_t(u16, len, MAX_SPI_FRAMESIZE); + transfer_len = min_t(u16, len, data->max_transfer_size); phy->iobuf[0] = (in ? 0x80 : 0) | (transfer_len - 1); phy->iobuf[1] = 0xd4;