From patchwork Tue Jun 13 18:02:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 107504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp741577vqr; Tue, 13 Jun 2023 11:16:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6CkoUu6Qp5sLiEfqYrjdq1ZcFaqtAIl62CVrJNcZOExF7o23wXI+ktZPGUQOoHDkT1odST X-Received: by 2002:a17:902:ecc8:b0:1b3:ee49:8334 with SMTP id a8-20020a170902ecc800b001b3ee498334mr2477487plh.52.1686680205823; Tue, 13 Jun 2023 11:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686680205; cv=none; d=google.com; s=arc-20160816; b=skOA+ND2MVxEzfzv8DB0uywZdSso+/j0HpqdHiQolaytKjEk2zKygoxM5dLBbuFikL DKmibjkIlq/l4/ztWqnXjoMm60XfYBvzhI//d9C6SPyfL+ajY78/Jg6dvQ6REFg0PSy6 AjmUvs7TsnH0SQyIips1IGRNw8TRmYPJjF6Xuighlhf/V2tiJU1q1iPOiAMLf5cOE8Y+ cG1dHoLavBQcgx5rC4sYjGZwZHuHOtj+gOE/I0s342Z/pCLBcsEHknch8IXXZ0WNwev0 OcrIq3pveBVrv8iJ4Gulm7IcO0vxJS5TREneMCR05td72sADLorYiToq9X0azv/BPMl1 LwWw== 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=sMa/CqBM0l9BBbaNj5C7lukGZi69bQbBzT6S831Baps=; b=ifcXnfM+1fL5rju3R+H+zB49g+0OkXd7Kvld5y0B1LmLcecHA4UBvJOTfTNuu5EkAJ jZhIHjkeKGd1y6Uqkit/trLRueMTnHLRkBmvbQoWUu7tcFoSCRnh2eCyCmy5joCPr4QU 8AnKX+grJusnpKsb6oVyugsriYHsYo6RNsyLHXu/rOi3zorV0ZdBAx+3LFwW/lzwI/UW uaHZpTbrQT04DmvC0KJ2ZQFqjoUpbhqJUUnE7ghp8Fwsiuc07JDDhja8hkKh79bB2Vy+ uHBF2hLiH13g1E3HhkHnm/b03Syf/drrGRgLru6QTVllLgTxX3CsaGAdieeNDM9/zhp7 5xIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infineon.com header.s=IFXMAIL header.b=QC6EqAsJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a170902d50500b001b176ba9f0fsi5531140plg.273.2023.06.13.11.16.33; Tue, 13 Jun 2023 11:16:45 -0700 (PDT) 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=fail header.i=@infineon.com header.s=IFXMAIL header.b=QC6EqAsJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=infineon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240211AbjFMSDc (ORCPT + 99 others); Tue, 13 Jun 2023 14:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240112AbjFMSDW (ORCPT ); Tue, 13 Jun 2023 14:03:22 -0400 Received: from smtp14.infineon.com (smtp14.infineon.com [IPv6:2a00:18f0:1e00:4::6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86DD919B3; Tue, 13 Jun 2023 11:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1686679401; x=1718215401; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xEMIE6JZW1YN5TsGLns9bWf/BYLfKZwBzKAFxtl7BSA=; b=QC6EqAsJR7gIIMY5u+gEgJoQeKy3iHMmDCKZwIMYqJ1ooUTxC8Z62Qzr pLqpM11frWfI9E+LVvoWFMYoq0Elcj75LpmnCivM6XAVa0a2H/NGKgR0W xRGJ3ZMFK8Wv9B6s1x/oRWrPeLkkvwjqnP5fnF10+gW/J+ZdNdFU/IKnJ o=; X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="16924802" X-IronPort-AV: E=Sophos;i="6.00,240,1681164000"; d="scan'208";a="16924802" Received: from unknown (HELO MUCSE812.infineon.com) ([172.23.29.38]) by smtp14.infineon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2023 20:03:18 +0200 Received: from KLUSE818.infineon.com (172.28.156.171) by MUCSE812.infineon.com (172.23.29.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Tue, 13 Jun 2023 20:03:16 +0200 Received: from ISCNPC0VBFBX.infineon.com (10.161.6.196) by KLUSE818.infineon.com (172.28.156.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Tue, 13 Jun 2023 20:03:16 +0200 From: Alexander Steffen To: , , CC: Alexander Steffen Subject: [PATCH v3 3/4] tpm_tis: Use responseRetry to recover from data transfer errors Date: Tue, 13 Jun 2023 20:02:58 +0200 Message-ID: <20230613180259.3525-4-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20230613180259.3525-1-Alexander.Steffen@infineon.com> References: <20230613180259.3525-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [10.161.6.196] X-ClientProxiedBy: MUCSE821.infineon.com (172.23.29.47) To KLUSE818.infineon.com (172.28.156.171) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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?1768612383096948233?= X-GMAIL-MSGID: =?utf-8?q?1768612383096948233?= TPM responses may become damaged during transmission, for example due to bit flips on the wire. Instead of aborting when detecting such issues, the responseRetry functionality can be used to make the TPM retransmit its response and receive it again without errors. Signed-off-by: Alexander Steffen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 37 ++++++++++++++++++++++++++------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 5ddaf24518be..a6d1396413a7 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -337,7 +337,7 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) return size; } -static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) +static int tpm_tis_try_recv(struct tpm_chip *chip, u8 *buf, size_t count) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int size = 0; @@ -345,11 +345,6 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) u32 expected; int rc; - if (count < TPM_HEADER_SIZE) { - size = -EIO; - goto out; - } - size = recv_data(chip, buf, TPM_HEADER_SIZE); /* read first 10 bytes, including tag, paramsize, and result */ if (size < TPM_HEADER_SIZE) { @@ -382,7 +377,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) goto out; } status = tpm_tis_status(chip); - if (status & TPM_STS_DATA_AVAIL) { /* retry? */ + if (status & TPM_STS_DATA_AVAIL) { dev_err(&chip->dev, "Error left over data\n"); size = -EIO; goto out; @@ -396,10 +391,36 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) } out: - tpm_tis_ready(chip); return size; } +static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) +{ + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); + unsigned int try; + int rc = 0; + + if (count < TPM_HEADER_SIZE) + return -EIO; + + for (try = 0; try < TPM_RETRY; try++) { + rc = tpm_tis_try_recv(chip, buf, count); + + if (rc == -EIO) + /* Data transfer errors, indicated by EIO, can be + * recovered by rereading the response. + */ + tpm_tis_write8(priv, TPM_STS(priv->locality), + TPM_STS_RESPONSE_RETRY); + else + break; + } + + tpm_tis_ready(chip); + + return rc; +} + /* * If interrupts are used (signaled by an irq set in the vendor structure) * tpm.c can skip polling for the data to be available as the interrupt is diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 610bfadb6acf..3a6b600d22ba 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -34,6 +34,7 @@ enum tis_status { TPM_STS_GO = 0x20, TPM_STS_DATA_AVAIL = 0x10, TPM_STS_DATA_EXPECT = 0x08, + TPM_STS_RESPONSE_RETRY = 0x02, TPM_STS_READ_ZERO = 0x23, /* bits that must be zero on read */ };