From patchwork Mon Feb 27 17:21:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Yarlagadda X-Patchwork-Id: 62008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2549156wrd; Mon, 27 Feb 2023 09:33:28 -0800 (PST) X-Google-Smtp-Source: AK7set9y1qaOjge01Gx6Gktx0PMqjH4tIfdhohBIPFHVLh811nQwddz1dv+KrxDsddjaAMKhPCvF X-Received: by 2002:aa7:cd89:0:b0:4af:69e2:529f with SMTP id x9-20020aa7cd89000000b004af69e2529fmr283686edv.27.1677519208572; Mon, 27 Feb 2023 09:33:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1677519208; cv=pass; d=google.com; s=arc-20160816; b=svV/MqQM9Eesmx5bZAEI4BVB4r38/56xDySeJsbPpLagrFlEci0dICNilQ+F+01hWP FY7oNUwg2obncvtCP9JdCnQYV7UagOO6Xi4KK9KbTZLrC8V+ITuKYtLBSL3wKwS8RwmK GIZN0rhV1NGtoTgmhUhhhd2DpYqXQXknmJOUizSpkcebaps0qEgZMCgzJkdLflkgkrFS c2wy+dYisTynZ9fCa4QCVN/pruVLmhJPdFGWDTGBBkmKuN2OQmblUhaELRXMIrXwHTP0 4STtUOUyCtB/1rDL18fus6ew/W4nMKGiENTx0fN/RJ8ip32CQZprpatuTD5gyZVs83kG /fQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4CrWYrnQzjeqIgMM8PaaGIiWahYHga0PSrE4U2JWwo0=; b=DWpdhWgEVlLD/gCNs7Jl9TQexDsNuB1CmjUt6wW1DL0vXw7H8tmjVtgd3iq/vbiWFp UdZ0wHzcWmsX6pL04BCUkzvu9KvatOzUEucvBIXd5qoRfeMC7Hnp4z7ZlWzOcjbM08Jt 1hsiO0V5kFeIU1YnCjXamK4+A5fkzw9lEDBhEIV9QImamlzSodYOap581QmyQNNVgr3M WEvULpPz86XMkzbHmavN0a91O4CAueWs5tMafnwHBzn+NjGCubCIZT5u5Z+1TEHWKxq/ ri8M4SET0fSdjopcaZuk3TDp5z0UcEdoD7jk8RndIOsv9ehQusOVcrl3csZmX0+RYqtm vJRg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=FGc2es3i; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020aa7d890000000b004acbcd255b1si8399470edq.198.2023.02.27.09.33.04; Mon, 27 Feb 2023 09:33:28 -0800 (PST) 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=pass header.i=@Nvidia.com header.s=selector2 header.b=FGc2es3i; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230142AbjB0RWD (ORCPT + 99 others); Mon, 27 Feb 2023 12:22:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230101AbjB0RVw (ORCPT ); Mon, 27 Feb 2023 12:21:52 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2084.outbound.protection.outlook.com [40.107.237.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A22D123C4D; Mon, 27 Feb 2023 09:21:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I/zAZVoT2HEp1omAKMFhPbbMtspq/4ErWlR9wAgIRhdYnDgE5VAyAcjIlPgE0jT04DqGloN+u5Ng2jOxbipTtP3MHu1iqX2Ph1foVUOo471G2wBtA0kpepx0EdUnozfIyQcPMfRMjcTrQ1QGm3N8sUUP3lIajC+i2D0Wk/paMY9bRBKOtbbBgIVxDv0Q6hs2NxKphb6tYrZbhfiD7EUWH3l018NuQVGXmMswItP+6mAxC6Tnr4d1hrRQczZ9/S6AoTI6H2BB4eclmFdPc503sT1RRcAUfT641B+yXH6h1lu5FylQmF9I46C40uV9OmeZzdp7L5ulPOea7jd9bbePow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4CrWYrnQzjeqIgMM8PaaGIiWahYHga0PSrE4U2JWwo0=; b=NEGVTQ+MkCLRr0TWvHJfl1Ds8eqHMzhA/DJRa6cK8vK9+bw3ZdjqyysQ/T8oSVZ/ntp3CrhJ55sed2HVv5oSPNxtcfmV0THc56VhfDs/04wesZWxfDCOXPnaTWhKAmdZ1e533N8d950Y5K02N6VdEOS8LB9DwWOVYPKk2O0or1GWDNARUXH73i1y5wxg/vQd6mAhJj6GJuKYZcu7zYSbONt839g42jBve1qKPKxVaGKuMNQWJDxPdi0KkwLT7/xzZKP6SHE22+2NjDYWhLZIHPQ2KNUcOenXiYnRopxQnf91IuW8nLPnqTeAyRzDCqe3hbAOm0i24JQ2dFV/CFfv0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4CrWYrnQzjeqIgMM8PaaGIiWahYHga0PSrE4U2JWwo0=; b=FGc2es3iU3yBxtF85+x8yiSs4dY1wrqpbTs1Smf9+yKcoQrbZllTkOw2s59yE+fWD9fHRkAc4pFiAOJjatcgw0r9Lo2MbKf89AVowfEcSR9SWQRoHPoXMwKYthu68poCwvzi1BeSVSp4sdqY6UNQLjcN2NdRmegxnm+OC85NCUjLP3FE4DtrLiATPtLli9tA3kUkLNOBXbsqeHArC2cTlzwfZLOPknPKNi0j9OfdBla+n2IhSuZ01D6BQWOM20v2kw76lvugJAIW1Tnhs1w/v/pulYiCSJuO/l1zl3Mo1T0w2Jhj5kmYRoxgEPZgUshQ3M387WPSI5ieFsuUhtUblw== Received: from BLAPR03CA0118.namprd03.prod.outlook.com (2603:10b6:208:32a::33) by IA1PR12MB6138.namprd12.prod.outlook.com (2603:10b6:208:3ea::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.29; Mon, 27 Feb 2023 17:21:46 +0000 Received: from BL02EPF0000C404.namprd05.prod.outlook.com (2603:10b6:208:32a:cafe::da) by BLAPR03CA0118.outlook.office365.com (2603:10b6:208:32a::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.29 via Frontend Transport; Mon, 27 Feb 2023 17:21:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF0000C404.mail.protection.outlook.com (10.167.241.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.12 via Frontend Transport; Mon, 27 Feb 2023 17:21:46 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 27 Feb 2023 09:21:33 -0800 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 27 Feb 2023 09:21:32 -0800 Received: from BUILDSERVER-IO-L4T.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Mon, 27 Feb 2023 09:21:27 -0800 From: Krishna Yarlagadda To: , , , , , , , , , CC: , , , , Krishna Yarlagadda Subject: [Patch V6 2/3] tpm_tis-spi: Support hardware wait polling Date: Mon, 27 Feb 2023 22:51:07 +0530 Message-ID: <20230227172108.8206-3-kyarlagadda@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230227172108.8206-1-kyarlagadda@nvidia.com> References: <20230227172108.8206-1-kyarlagadda@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0000C404:EE_|IA1PR12MB6138:EE_ X-MS-Office365-Filtering-Correlation-Id: e35bed4a-5d6a-4937-b5f5-08db18e71a91 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +0WqTloj6SsLNVAMazZZ0if9/2xc3jvxhZSAj1z//UH4eHeIwPndLG+5hmJD6lJUyxByjVQ4X/CH2Sb7edlDSiJ45FbWMvGsTaCxuXeyz1Sk8A2HqyL0TVqmcF5xHLwqXCNFS2GNKjKIWw4qeD7ZzScH6ASUaL4zdh/SjyLBOj6Wq0F1XEnM/0JJCxFSXM4q6a1TZccT6rGaEGmv4JRG1SAbZhuNcoWUcJ6M18JT3sads6iPu5RHbtmaAy0oO9j3WDG82v1pd7A5HH+NnBmbK4a0Nyxx5wki8kxls93TFQyLOTzSTuQ8y8MOHoUdZvAZmRIQuovzM4ZCCDnDZYbsR2db4wICyuUQWkfvHQFRXRQMdoDfpfaOPg4pdke0lXYPq+pA+rwpVPJhqcgkZtTUji4yGRUPFTIbu6ZowPUYuSyQUwFE9bQ61sxiXZD9K6w1q2MBw6OFAiNTXMiieDpuO4t4tfdgLk1Bdrj4a9x6idHzADOx8WlptL2Xo5jaqGN9gqAhdBzJ+15IUCF2odEZWy9Gx5K0Kl0KkwEkFeenlXnlPJoyL/8g7xN4mGaZMZqwSjb61hAOyhd2AtoXCKpviTyC2Y0AyAsZJgTrPH6LSk3SfrYwlSCqZWimuu2CcorfdC/RqddspMVYNUPlEzGCCnUSNyXoaX/AdX6MnlayXtUtNjEx51Zj7PZpAXeH7uirxX09eIsJs9SBTntUysqDgJVLHBdDftJAedFHqLSyb5MnoFk6oFCUb2Iw6B4N15KAHCTBX2G8p0TmVMSO2ekQcQ== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(396003)(376002)(136003)(39860400002)(346002)(451199018)(40470700004)(36840700001)(46966006)(41300700001)(4326008)(70206006)(70586007)(83380400001)(8676002)(7636003)(36756003)(36860700001)(86362001)(82740400003)(2906002)(921005)(82310400005)(40480700001)(356005)(7416002)(5660300002)(8936002)(40460700003)(47076005)(2616005)(336012)(426003)(478600001)(7696005)(110136005)(107886003)(1076003)(54906003)(316002)(6666004)(186003)(26005)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2023 17:21:46.3295 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e35bed4a-5d6a-4937-b5f5-08db18e71a91 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0000C404.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6138 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no 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?1759006381836769323?= X-GMAIL-MSGID: =?utf-8?q?1759006381836769323?= TPM devices raise wait signal on last addr cycle. This can be detected by software driver by reading MISO line on same clock which requires full duplex support. In case of half duplex controllers wait detection has to be implemented in HW. Support hardware wait state detection by sending entire message and let controller handle flow control. QSPI controller in Tegra234 & Tegra241 implement TPM wait polling. Signed-off-by: Krishna Yarlagadda --- drivers/char/tpm/tpm_tis_spi_main.c | 92 ++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c index a0963a3e92bd..5f66448ee09e 100644 --- a/drivers/char/tpm/tpm_tis_spi_main.c +++ b/drivers/char/tpm/tpm_tis_spi_main.c @@ -71,8 +71,74 @@ static int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy, return 0; } -int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, - u8 *in, const u8 *out) +/* + * Half duplex controller with support for TPM wait state detection like + * Tegra241 need cmd, addr & data sent in single message to manage HW flow + * control. Each phase sent in different transfer for controller to idenity + * phase. + */ +int tpm_tis_spi_hw_flow_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); + struct spi_transfer spi_xfer[3]; + struct spi_message m; + u8 transfer_len; + int ret; + + while (len) { + transfer_len = min_t(u16, len, MAX_SPI_FRAMESIZE); + + spi_message_init(&m); + phy->iobuf[0] = (in ? 0x80 : 0) | (transfer_len - 1); + phy->iobuf[1] = 0xd4; + phy->iobuf[2] = addr >> 8; + phy->iobuf[3] = addr; + + memset(&spi_xfer, 0, sizeof(spi_xfer)); + + spi_xfer[0].tx_buf = phy->iobuf; + spi_xfer[0].len = 1; + spi_message_add_tail(&spi_xfer[0], &m); + + spi_xfer[1].tx_buf = phy->iobuf + 1; + spi_xfer[1].len = 3; + spi_message_add_tail(&spi_xfer[1], &m); + + if (out) { + spi_xfer[2].tx_buf = &phy->iobuf[4]; + spi_xfer[2].rx_buf = NULL; + memcpy(&phy->iobuf[4], out, transfer_len); + out += transfer_len; + } + + if (in) { + spi_xfer[2].tx_buf = NULL; + spi_xfer[2].rx_buf = &phy->iobuf[4]; + } + + spi_xfer[2].len = transfer_len; + spi_message_add_tail(&spi_xfer[2], &m); + + reinit_completion(&phy->ready); + + ret = spi_sync_locked(phy->spi_device, &m); + if (ret < 0) + return ret; + + if (in) { + memcpy(in, &phy->iobuf[4], transfer_len); + in += transfer_len; + } + + len -= transfer_len; + } + + return ret; +} + +int tpm_tis_spi_sw_flow_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; @@ -140,6 +206,28 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len, return ret; } +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); + struct spi_controller *ctlr = phy->spi_device->controller; + + /* + * TPM flow control over SPI requires full duplex support. + * Send entire message to a half duplex controller to handle + * wait polling in controller. + * Set TPM HW flow control flag.. + */ + if (ctlr->flags & SPI_CONTROLLER_HALF_DUPLEX) { + phy->spi_device->mode |= SPI_TPM_HW_FLOW; + return tpm_tis_spi_hw_flow_transfer(data, addr, len, in, + out); + } else { + return tpm_tis_spi_sw_flow_transfer(data, addr, len, in, + out); + } +} + static int tpm_tis_spi_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len, u8 *result, enum tpm_tis_io_mode io_mode) {