From patchwork Mon Aug 12 22:36:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11090969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D48E813AC for ; Mon, 12 Aug 2019 22:36:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C335927F90 for ; Mon, 12 Aug 2019 22:36:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B70362823E; Mon, 12 Aug 2019 22:36:51 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 1D03B28384 for ; Mon, 12 Aug 2019 22:36:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727284AbfHLWgp (ORCPT ); Mon, 12 Aug 2019 18:36:45 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38929 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727151AbfHLWg1 (ORCPT ); Mon, 12 Aug 2019 18:36:27 -0400 Received: by mail-pg1-f193.google.com with SMTP id u17so50192926pgi.6 for ; Mon, 12 Aug 2019 15:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G1GyJeHxK3pLSUGiO0YqwSLuWrA1RPqBG46rl6iGQ1s=; b=geQsoQ49HygUno2jknhm/5tkiWZxIR99UnMgMqLmz+2kVJ+u+dULTQe2yvZxTIU9XE mYN8oyWmjYVz5J+35rcExedP4HNSIYZORXL933ibyeyrh9j4x94vN7/CD7tKIgylySye GV9xj5Og/JcK1Ve+R7xdxdJnaJCamxQnIY10w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G1GyJeHxK3pLSUGiO0YqwSLuWrA1RPqBG46rl6iGQ1s=; b=pMWrjVx8t0/HTvMumqIV+pofwqilklhfoaue6tUzMLebjHBHCJFD9IMs4NjIXXX+97 KW/kJ+JjDWjpV2lFOAt3tIIAHTbASfSMevuUBf+wDrQBVKo2psAB0blpBe/WFwTGtc+s vN5EQSq0Ng9qCIheIrXCe9q7pWy2ZobFQ7b1KK22xrvb9wuXR/2J+ze4Dj9yvlAHCa1H 1zSZ5SWQiAFRaAMhn9qirjc8MCcvg5wXiNCJOePMHiRWzZCS7tQUDKXnV+DvvGqO0xDV 6Rd7XFUHvhCObzArB0bqNyZ0IwgkIodexR944XZge9iNFffmI5UC+326vSq30Ypa0z8d DlCQ== X-Gm-Message-State: APjAAAXL90QRTpN1gEo47vuXI38QkwrTrnouSyqAhiE2LITt31Vk0Stk YbYqgU0h+ywpNIi6EiJasIIL7w== X-Google-Smtp-Source: APXvYqySaV6YpLXAdPxlUhjGdH9PpCPLsa2Hp/dqfsVZSEg/dLbajPrX4bseW4PkHigNheTRFb11Zg== X-Received: by 2002:a17:90a:8c90:: with SMTP id b16mr1357627pjo.133.1565649386242; Mon, 12 Aug 2019 15:36:26 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id b6sm93911594pgq.26.2019.08.12.15.36.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 15:36:25 -0700 (PDT) From: Stephen Boyd To: Peter Huewe , Jarkko Sakkinen Cc: linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, Andrey Pronin , Duncan Laurie , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , Guenter Roeck , Alexander Steffen Subject: [PATCH v4 2/6] tpm: tpm_tis_spi: Introduce a flow control callback Date: Mon, 12 Aug 2019 15:36:18 -0700 Message-Id: <20190812223622.73297-3-swboyd@chromium.org> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog In-Reply-To: <20190812223622.73297-1-swboyd@chromium.org> References: <20190812223622.73297-1-swboyd@chromium.org> MIME-Version: 1.0 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 Cr50 firmware has a different flow control protocol than the one used by this TPM PTP SPI driver. Introduce a flow control callback so we can override the standard sequence with the custom one that Cr50 uses. Cc: Andrey Pronin Cc: Duncan Laurie Cc: Jason Gunthorpe Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: Guenter Roeck Cc: Alexander Steffen Signed-off-by: Stephen Boyd --- drivers/char/tpm/tpm_tis_spi.c | 55 +++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_spi.c b/drivers/char/tpm/tpm_tis_spi.c index 19513e622053..819602e85b34 100644 --- a/drivers/char/tpm/tpm_tis_spi.c +++ b/drivers/char/tpm/tpm_tis_spi.c @@ -42,6 +42,8 @@ struct tpm_tis_spi_phy { struct tpm_tis_data priv; struct spi_device *spi_device; + int (*flow_control)(struct tpm_tis_spi_phy *phy, + struct spi_transfer *xfer); u8 *iobuf; }; @@ -50,12 +52,39 @@ static inline struct tpm_tis_spi_phy *to_tpm_tis_spi_phy(struct tpm_tis_data *da return container_of(data, struct tpm_tis_spi_phy, priv); } +static int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy, + struct spi_transfer *spi_xfer) +{ + struct spi_message m; + int ret, i; + + if ((phy->iobuf[3] & 0x01) == 0) { + // handle SPI wait states + phy->iobuf[0] = 0; + + for (i = 0; i < TPM_RETRY; i++) { + spi_xfer->len = 1; + spi_message_init(&m); + spi_message_add_tail(spi_xfer, &m); + ret = spi_sync_locked(phy->spi_device, &m); + if (ret < 0) + return ret; + if (phy->iobuf[0] & 0x01) + break; + } + + if (i == TPM_RETRY) + return -ETIMEDOUT; + } + + return 0; +} + static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, u8 *in, const u8 *out) { struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); int ret = 0; - int i; struct spi_message m; struct spi_transfer spi_xfer; u8 transfer_len; @@ -82,26 +111,9 @@ static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, if (ret < 0) goto exit; - if ((phy->iobuf[3] & 0x01) == 0) { - // handle SPI wait states - phy->iobuf[0] = 0; - - for (i = 0; i < TPM_RETRY; i++) { - spi_xfer.len = 1; - spi_message_init(&m); - spi_message_add_tail(&spi_xfer, &m); - ret = spi_sync_locked(phy->spi_device, &m); - if (ret < 0) - goto exit; - if (phy->iobuf[0] & 0x01) - break; - } - - if (i == TPM_RETRY) { - ret = -ETIMEDOUT; - goto exit; - } - } + ret = phy->flow_control(phy, &spi_xfer); + if (ret < 0) + goto exit; spi_xfer.cs_change = 0; spi_xfer.len = transfer_len; @@ -207,6 +219,7 @@ static int tpm_tis_spi_probe(struct spi_device *dev) phy->iobuf = devm_kmalloc(&dev->dev, MAX_SPI_FRAMESIZE, GFP_KERNEL); if (!phy->iobuf) return -ENOMEM; + phy->flow_control = tpm_tis_spi_flow_control; /* If the SPI device has an IRQ then use that */ if (dev->irq > 0)