From patchwork Wed Mar 1 17:33:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Yarlagadda X-Patchwork-Id: 13156267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E333CC6FA9D for ; Wed, 1 Mar 2023 17:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230039AbjCAReX (ORCPT ); Wed, 1 Mar 2023 12:34:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbjCAReW (ORCPT ); Wed, 1 Mar 2023 12:34:22 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2052.outbound.protection.outlook.com [40.107.243.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 547F222782; Wed, 1 Mar 2023 09:34:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CubqDvy7iU6C6gPWlWTjFzns0RqNt+XVpaI7R74JWL4ZGxFdOTgooVjmSLA2hTqqixzZ/Q8mE7VxCfggRDNVTUJJoWnevOa57vJz4rpu8BAzC7Ng/4lZWzepz8Az5X+zVVzpji3t+DPyjTbTjBzrsUJOpM4wFtC2Deqq90fnOaKIJgybVvcDHn+t+gQa/qT1Knx3CSR14EbuKlN61Tlpx/bf+TRKGl1TKQhFIOO2Rm2pFIeg8PvfhmlBGKr7Mn/8t8iWpMqZSLTuLySI4+/eM6kJKEkiBQW75QyZdY6lUHbQkjnp/0m0sFUBuHp3vcVJ63X/BE/eyCM0Qo/gmiY/8w== 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=Mh9Ua9+PFTGOWRtWUmLN86IqbLOmxsmrJzCJu52I840=; b=iQum9Pizew/Xr6B0fSTLyKS00g2Cq7uMuf6ch6vkYIVtGzegnl694fWclnjuVkJ//gm3AwnIVVllJpf21ZyZRZOUtuoFtOpv1kvYletf8htiGkdCtd1kxOMaiJBb5VI2vOptoEi4IxI9fw0wryWFShq2mOCW4B8oHbiGUssgBgdU8KbhnMwCqLMaMshTe6O9m5JP+rcK1ycEESsU9gxvo3SoBRru33oaampvpBbaPu22NXaSy48GAz0Sw0uQckM2LrRp30jG+WZzHVm9hGNEzV+A9ye4G/Yng+30uI+M/uQVNKZGlVT6xhvtWOpJyhBK2muqbEXWPhQgQQ3BT+Rn7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) 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 Received: from BN0PR04CA0155.namprd04.prod.outlook.com (2603:10b6:408:eb::10) by IA1PR12MB6530.namprd12.prod.outlook.com (2603:10b6:208:3a5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18; Wed, 1 Mar 2023 17:34:18 +0000 Received: from BL02EPF00010206.namprd05.prod.outlook.com (2603:10b6:408:eb:cafe::7c) by BN0PR04CA0155.outlook.office365.com (2603:10b6:408:eb::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.17 via Frontend Transport; Wed, 1 Mar 2023 17:34:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BL02EPF00010206.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.12 via Frontend Transport; Wed, 1 Mar 2023 17:34:17 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 1 Mar 2023 09:34:05 -0800 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 1 Mar 2023 09:34:05 -0800 Received: from BUILDSERVER-IO-L4T.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 1 Mar 2023 09:34:01 -0800 From: Krishna Yarlagadda To: , , , , , , , , , CC: , , , , Krishna Yarlagadda Subject: [Patch V7 1/3] spi: Add TPM HW flow flag Date: Wed, 1 Mar 2023 23:03:51 +0530 Message-ID: <20230301173353.28673-2-kyarlagadda@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230301173353.28673-1-kyarlagadda@nvidia.com> References: <20230301173353.28673-1-kyarlagadda@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00010206:EE_|IA1PR12MB6530:EE_ X-MS-Office365-Filtering-Correlation-Id: b62dbcff-3aff-46a2-8018-08db1a7b2f4a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GkhL9DmFTZXdIWP+Orpjd131zb6ME1tqm5dlwjBYDnL+2+ApMjJfGPdwUrDCuGMfqiMrJW9YbjCrSALzL5pDFHazVXY4B1HVkl2m7HQuUtryaT4YxGa8lKnU4A2gwbz7HqQQO9BteE2pUnTevjbsiAjahBkH9hdpcow0Q2pFu+EKUV9mlXxD5cq5fiFP/s8Pk/DQdi7yLlai8Mu2RfwS9ziInPY5xdP9PDdfqxCb1Ac4RIHJJ6sitEcg4+rnm9aLr0p3ILx8zIKWgXQ6+vxBEGvEAiGxa/vCMFfXQ8xu2uYYr+GW6Los7J2HZpngItimNnY5tMfKXCkUyBtkGRNMsUMlFT6eA8Gab2Jt47uQpJQCTvjZjMhSJKApNlG5Xx8ZMRU6SMnQX3UjSpnlXcCCdkXzrdNYhr+eahfe1Jn5HC6AIEudBFmhZ5bG6II//0FAHJsgo0EhZNA94FppZWlChNM3UdL3crvIK9CP52pf1u4/JrSqhWd8H8zYiA0YQ2zq6NqtVdU9aHETt8hlv2izFKJEarFQwYlHEVQLfajG5OTlCDo9YZvDYY6q6L9s2GJwRc5dMib9fx4rLJeH1q97sck0zW8el6HDnqzJVkxsNGx6FK8wUh6X8keKxRaxJbkar4meGrLnfJ3QtT5yCci/BqbuS3xX07RvX8f5KLppwhxfF5efdcjFTIRakU4bCgv6DRqUIIlKQM1jlgH1wypoeMjI/COUjxXdYp5Ji2bWRrkGfkGK2mlS4iPtAnlAvj8HxnLPoVVdUf2rsdwqMSB9HykwqvdOD2TUxis8cZAu03Gb9pPCI38tBVdp+sUVelo9 X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199018)(40470700004)(36840700001)(46966006)(5660300002)(2616005)(40480700001)(7416002)(54906003)(110136005)(7696005)(107886003)(82740400003)(6666004)(7636003)(921005)(356005)(478600001)(966005)(41300700001)(186003)(36756003)(40460700003)(8936002)(316002)(26005)(86362001)(1076003)(4326008)(8676002)(70586007)(36860700001)(70206006)(82310400005)(83380400001)(2906002)(426003)(47076005)(336012)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 17:34:17.7737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b62dbcff-3aff-46a2-8018-08db1a7b2f4a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00010206.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6530 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org TPM specification [1] defines flow control over SPI. Client device can insert a wait state on MISO when address is transmitted by controller on MOSI. Detecting the wait state in software is only possible for full duplex controllers. For controllers that support only half- duplex, the wait state detection needs to be implemented in hardware. Add a flag SPI_TPM_HW_FLOW for TPM device to set when software flow control is not possible and hardware flow control is expected from SPI controller. Reference: [1] https://trustedcomputinggroup.org/resource/pc-client-work-group- pc-client-specific-tpm-interface-specification-tis/ Signed-off-by: Krishna Yarlagadda --- include/linux/spi/spi.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 4fa26b9a3572..b9e49ed42955 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -184,8 +184,18 @@ struct spi_device { u8 chip_select; u8 bits_per_word; bool rt; -#define SPI_NO_TX BIT(31) /* No transmit wire */ -#define SPI_NO_RX BIT(30) /* No receive wire */ +#define SPI_NO_TX BIT(31) /* No transmit wire */ +#define SPI_NO_RX BIT(30) /* No receive wire */ + /* + * TPM specification defines flow control over SPI. Client device + * can insert a wait state on MISO when address is transmitted by + * controller on MOSI. Detecting the wait state in software is only + * possible for full duplex controllers. For controllers that support + * only half-duplex, the wait state detection needs to be implemented + * in hardware. TPM devices would set this flag when hardware flow + * control is expected from SPI controller. + */ +#define SPI_TPM_HW_FLOW BIT(29) /* TPM HW flow control */ /* * All bits defined above should be covered by SPI_MODE_KERNEL_MASK. * The SPI_MODE_KERNEL_MASK has the SPI_MODE_USER_MASK counterpart, @@ -195,7 +205,7 @@ struct spi_device { * These bits must not overlap. A static assert check should make sure of that. * If adding extra bits, make sure to decrease the bit index below as well. */ -#define SPI_MODE_KERNEL_MASK (~(BIT(30) - 1)) +#define SPI_MODE_KERNEL_MASK (~(BIT(29) - 1)) u32 mode; int irq; void *controller_state; From patchwork Wed Mar 1 17:33:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Yarlagadda X-Patchwork-Id: 13156268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E93A6C6FA9D for ; Wed, 1 Mar 2023 17:34:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbjCARee (ORCPT ); Wed, 1 Mar 2023 12:34:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbjCAReb (ORCPT ); Wed, 1 Mar 2023 12:34:31 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11hn2241.outbound.protection.outlook.com [52.100.173.241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0AE248E1B; Wed, 1 Mar 2023 09:34:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CCwH+oiS7y3EPV5XjIPT85XLyoCrdqSeACaOX26NO2ojk5ILPOOsRmv6guZJwobgGiJ2APsaRjPDgWQr5z7Quo8UyFv2sVBRYnlHD1DXoeaKS/gOyTldlEflGEC5QYl5yJwMHOjJ/bfpjpcDV2WMpm4zeho/QQeNHkL5vurdsqCH/MHfQtNvosuw/jh37Mp4vIidS5Vf3iHUVOL418a9bA+H8Gsd5uXtlf3SZ5+zpj7kjTXuIGe/fecajNI/GoKP4xApS2AIFGoDi9jVegXDSjkmDmCZrZpIGk4oBypB9OZvBP4JzXTM1i5cSzZIX/eNTn15l7jcXPKKrixrQ/1MvA== 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=b6nzbWPnxBfKpo/CzW043bxzHouFCEodDPJmySf5H+U=; b=na/cp2pU7hCwkxj9jMSShey0+mAlj82BUYuUq8YSoQ/wGnv2PscLaBJFRg7g/agK5QW5klPeoaWhnnWBnmZQK+kM8dz64aHNu3vgpDNepAQAKpJ2h7XO8uS8HqEaQ50eRqRqAYFRe1g971X8CCk6LMdjPKBelA0FBc1aOfu4dCA9iY6CTazSiR7g8WdtOuSN9V6b9Y/3Sred0zW5E8mFfd3oUIssUOhT4/hlhnZIVA7/79QJ4U0ioJD8TgOrN3vPBsPMyq6+BZbOUIoy38nagw5/xBQcxqXR1hnCZiS3hy2uccceXcXKnAxRgb4wrRyTorE/GqPzmdhNDB4WGiL40A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=b6nzbWPnxBfKpo/CzW043bxzHouFCEodDPJmySf5H+U=; b=VqSVy1ofc7TH/+tjTtjQYSbY2v4dTBV6yoOfM3VwpcpR+q7pw5Bt+PP+nB7Bm4w2W8abwTOJQ9ykYCgPQCNcCfOKRh1kWhEW9UYfMPHMikojqZ0v1BECB72m7jAE+1VU8ADiJqMAoOVThGBz+0iGW6lUdh25Nkl+ff434ki3le7n42VJ2itpRu8R0qYC4gcgLNj/F5pstoMJTnGHvblgic0GyZWLRHYtsNY/lXHRkGgVjrmzmhQZdkKQM/h2XTiafCLka5y0voHcPUJUvlZ/c3qDi1HuU8lPjad0ZL0GnKfysWNXe+3fFpFypZXUVMpnZfK0a0zmToP3XuTnIgRGIw== Received: from BN1PR12CA0020.namprd12.prod.outlook.com (2603:10b6:408:e1::25) by CY8PR12MB7337.namprd12.prod.outlook.com (2603:10b6:930:53::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.27; Wed, 1 Mar 2023 17:34:23 +0000 Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e1:cafe::a1) by BN1PR12CA0020.outlook.office365.com (2603:10b6:408:e1::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30 via Frontend Transport; Wed, 1 Mar 2023 17:34:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.14 via Frontend Transport; Wed, 1 Mar 2023 17:34:23 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 1 Mar 2023 09:34:10 -0800 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 1 Mar 2023 09:34:09 -0800 Received: from BUILDSERVER-IO-L4T.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 1 Mar 2023 09:34:05 -0800 From: Krishna Yarlagadda To: , , , , , , , , , CC: , , , , Krishna Yarlagadda Subject: [Patch V7 2/3] tpm_tis-spi: Add hardware wait polling Date: Wed, 1 Mar 2023 23:03:52 +0530 Message-ID: <20230301173353.28673-3-kyarlagadda@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230301173353.28673-1-kyarlagadda@nvidia.com> References: <20230301173353.28673-1-kyarlagadda@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT048:EE_|CY8PR12MB7337:EE_ X-MS-Office365-Filtering-Correlation-Id: 5507e469-a5a8-4609-55f3-08db1a7b32bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NAXR9Pj1BQtNLFzhOPEk52RLEKAgnns3LOS7xLDvSnQN2pkj4MdxUJeVrGtIXhw23VPgWOFUzohA06WqPePE8yqsb7qy//hotbRSHep5uTM5j+TprbAv1FpEiJ4RAY6gAZY4XkZlq/MoOTrsUgw3K7CrXbxVFOz7bdb0lvVHCT5A+hmoqhRVH3gfF/4kmUCnwMQsdG9JbatfSlTsR3ARE10w1F5krCQyo6MlwoltGgh8MHwdxU3sj4egqrrXm3s0Vcz1HNRBM1CBSYX9nVCLYXmkPGbf0U8IPzalbAyQ+mcxBX/GMrxbTebcPylpGcnXPbF5SgBQ+2mccp24M/wVssCL05G6AFPh6aDCRcrMNS+c78xrhYZNg1gYoV7O0l06IdufcUH32gW4cELRv3pd1+Ve/l4VgGf5XY+xcjmRKXaALbr8dYSyJFbypPLfsf+SFt7KcWXnPLBzPyvKM9PX6p9jXpOtnaBWtlfqF2KF5Z4fkdXbmeYVWnPcfctMbh3pVx0qhoD9UJBzTu3NaGc45CbbtAE3V+W8LNjdpPKyJcP4toBVr0/sg2tc/qnNhIVvnYQaaTHTkE9g1Dxfk3Lbn9O9wgx0HUdr8BU/hvLBAWsy6Mh7jPXG9hO6Jyzw1UDv5UepuqrH4pF5/rrUDbe8o9uaj85+sLgJYbrm7JkLL+9OftaqbXe6dGp+e8qRlGo67/ddfXKd5C3GkjAtgQUjXKVwdDdbG0MfaUXMMzVFDKQpwxLhjdPsz/yUl/GhvF5gnQiwOuxMeQy/sBlC5SV8L6WFpZHJmrIyfrDgbhTJLMPqyRqpfxUNnRNhqffS0yArXjsdteon00usDEC2XdhMxA== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(136003)(39860400002)(346002)(396003)(376002)(451199018)(5400799012)(40470700004)(36840700001)(46966006)(7636003)(8676002)(110136005)(478600001)(8936002)(316002)(336012)(82740400003)(54906003)(7416002)(36756003)(26005)(186003)(7696005)(86362001)(2906002)(40460700003)(82310400005)(921005)(107886003)(40480700001)(356005)(1076003)(6666004)(2616005)(5660300002)(34020700004)(83380400001)(70206006)(4326008)(70586007)(36860700001)(47076005)(41300700001)(426003)(83996005)(2101003)(12100799018);DIR:OUT;SFP:1501; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 17:34:23.5594 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5507e469-a5a8-4609-55f3-08db1a7b32bd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7337 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org TPM devices may insert wait state on last clock cycle of ADDR phase. For SPI controllers that support full-duplex transfers, this can be detected using software by reading the MISO line. For SPI controllers that only support half-duplex transfers, such as the Tegra QSPI, it is not possible to detect the wait signal from software. The QSPI controller in Tegra234 and Tegra241 implement hardware detection of the wait signal which can be enabled in the controller for TPM devices. The current TPM TIS driver only supports software detection of the wait signal. To support SPI controllers that use hardware to detect the wait signal, add the function tpm_tis_spi_hw_flow_transfer() and move the existing code for software based detection into a function called tpm_tis_spi_sw_flow_transfer(). SPI controllers that only support half-duplex transfers will always call tpm_tis_spi_hw_flow_transfer() because they cannot support software based detection. The bit SPI_TPM_HW_FLOW is set to indicate to the SPI controller that hardware detection is required and it is the responsibility of the SPI controller driver to determine if this is supported or not. For hardware flow control, CMD-ADDR-DATA messages are combined into a single message where as for software flow control exiting method of CMD-ADDR in a message and DATA in another is followed. Signed-off-by: Krishna Yarlagadda --- drivers/char/tpm/tpm_tis_spi_main.c | 96 ++++++++++++++++++++++++++++- 1 file changed, 94 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..fc6ee784ff76 100644 --- a/drivers/char/tpm/tpm_tis_spi_main.c +++ b/drivers/char/tpm/tpm_tis_spi_main.c @@ -71,8 +71,76 @@ 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 + * Tegra QSPI need CMD, ADDR & DATA sent in single message to manage HW flow + * control. Each phase sent in different transfer for controller to idenity + * phase. + */ +static 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; +} + +static 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 +208,26 @@ 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) + 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) { @@ -172,6 +260,7 @@ static const struct tpm_tis_phy_ops tpm_spi_phy_ops = { static int tpm_tis_spi_probe(struct spi_device *dev) { struct tpm_tis_spi_phy *phy; + struct spi_controller *ctlr = phy->spi_device->controller; int irq; phy = devm_kzalloc(&dev->dev, sizeof(struct tpm_tis_spi_phy), @@ -181,6 +270,9 @@ static int tpm_tis_spi_probe(struct spi_device *dev) phy->flow_control = tpm_tis_spi_flow_control; + if (ctlr->flags & SPI_CONTROLLER_HALF_DUPLEX) + phy->spi_device->mode |= SPI_TPM_HW_FLOW; + /* If the SPI device has an IRQ then use that */ if (dev->irq > 0) irq = dev->irq; From patchwork Wed Mar 1 17:33:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Yarlagadda X-Patchwork-Id: 13156269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E797C6FA9D for ; Wed, 1 Mar 2023 17:35:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229674AbjCARfI (ORCPT ); Wed, 1 Mar 2023 12:35:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjCARfH (ORCPT ); Wed, 1 Mar 2023 12:35:07 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11hn2218.outbound.protection.outlook.com [52.100.172.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91CCE2594B; Wed, 1 Mar 2023 09:34:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZtdTbMVKx5Q3HJLd0llM2hup9vLYPsHScZVjhWZgVPxRY7aaROglHiNm01l3aq265BEXmoR6lhsyBSXGe26p2pyx+51dBdOXaVmYuBQXocNshszlpIdxgQjrSxvH8f469JX3bHVAMPxbFNgzjCjxkDGSOK4Aq3ytMStM7jFNekU3B6O5ICT6zNml9eWh2zvn0uCyK4nAJcyJ1RKsqGkdmXyo5mCZ8Otff3KhGKMVa7SLjgJ4S8KkQ32yOfWvsHzUSPhYraWmDtg6U3D4WABvc2/DIM6W6vSaHxMDYHxvX9XxfA47P3guS3OVw5U2IJtmGOIAokxGPxzQwvMFRNgKDg== 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=Z6cfpwnnVrUbHlknS5XSwMZgssAwk958FxhAcSDRmG8=; b=DD+IoJK8eHUu/603kDmc8WVbcuIEhIQtvkjFQMyrcIwhcSwPSyEKJHW4Uj74D1FDQp5NjF5MfIB0cr8tMSdqbnYdux6UUVwFnQceQWN59GyCJfChK5fWfQ39pFA5cG5PtGqlSGZ1BOFXsjeNNa/Cm/IK4DOel9qib8mpwQ9ks9r0X/EwblOxl6vMYzu2zSDzWy7BLyrz1usmfIV2tC9JaJADdGO42RDVlrL+ccRTFpmqV6dB7wgjgV9CcgbrDHtNFHzpVZHide1YRYUtqWgM4tNoytcLllHEHvreZ40//0niXBv1tKjH7PvRh8eFyJwi/ghtNjoKhxebo50OXRIDag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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 Received: from BN1PR12CA0027.namprd12.prod.outlook.com (2603:10b6:408:e1::32) by SJ0PR12MB5439.namprd12.prod.outlook.com (2603:10b6:a03:3ae::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18; Wed, 1 Mar 2023 17:34:27 +0000 Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e1:cafe::75) by BN1PR12CA0027.outlook.office365.com (2603:10b6:408:e1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18 via Frontend Transport; Wed, 1 Mar 2023 17:34:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.14 via Frontend Transport; Wed, 1 Mar 2023 17:34:27 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 1 Mar 2023 09:34:15 -0800 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 1 Mar 2023 09:34:14 -0800 Received: from BUILDSERVER-IO-L4T.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 1 Mar 2023 09:34:10 -0800 From: Krishna Yarlagadda To: , , , , , , , , , CC: , , , , Krishna Yarlagadda Subject: [Patch V7 3/3] spi: tegra210-quad: Enable TPM wait polling Date: Wed, 1 Mar 2023 23:03:53 +0530 Message-ID: <20230301173353.28673-4-kyarlagadda@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230301173353.28673-1-kyarlagadda@nvidia.com> References: <20230301173353.28673-1-kyarlagadda@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT048:EE_|SJ0PR12MB5439:EE_ X-MS-Office365-Filtering-Correlation-Id: 6a90ca49-c1d3-4e51-a8f2-08db1a7b34e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3a2fgbN0F47Rs4XTOA+HvHNN2ohx4ZZ6PK15miBMYDr1bZiJR7EZERPLlMyNHxnUa/SzFgVu8zvKtkh/sxOmGTKCCit0rTEvE/bIu2/H5bz0T52YUxu+YZ3MkLWaayXo3mHh37OmkHf6MAtZoTcllMdFACd1499chNKz1ToLiaoDFALFu9Pweflbxa4MSH9cRJ/huzsk/9hiJ9UARENu2mXLuRblxJMv9bGBd904xapDCFWaI8WN5rdvp7JQcN8e3NWZfcQI/ChAJpMGeBWb1C1RmJVfIRj/L5TwL/OsIRCEOpTcy5092tSsNNLBkq8NhUV3VTpH/zRiq2HUZziYGapHLlIng0iYJMTZ50/N24Y/DLumhX6zNt2KtwUWm/FOGHYW8SJASxdOG/QDgzsNT9NW+Fexn5ax0/NiYlYeG8mzzIwXEdWFhtxe7nV3jmgPPOvVBS3IshzPBHQehjHCNq0NZtGslNA9d3cUAXJ6/jgbAL83BB3g6h4SH4LbvaJDjXeNvcyfUvQnfmoRP73k2d0j1JFcjTgF+pMyMeEaESGza3wkZpkmJQsoUoJGx+qujYHcqUDqHoGCSzNHZbXLM59ZYeGCqnLYOQR5SGIO8eypefljq+gsiUYibRGVSamDfcexR9mFIGhD6MtyLaXNiO/bFhySNuE9HUcgLK4GuLnBGi/0vYi09kQXm38Vz7llLSfCwSKuSz84NF6NsXxT76w0ikYTWF7OESLC6m2NXD0R1SVDjCirVE6YIULB//XnLZ0pjJiX9OryHts4qEMOeT4vYR9H7sfj8NL6FQytTxPMoXYaz4lyo/OOb07VYei+driH3GUy2wE9HmFhDAGF5w== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(346002)(136003)(376002)(396003)(451199018)(5400799012)(46966006)(36840700001)(40470700004)(82740400003)(7636003)(36860700001)(316002)(2906002)(34020700004)(40460700003)(7416002)(5660300002)(40480700001)(36756003)(8936002)(86362001)(26005)(4326008)(70206006)(70586007)(186003)(8676002)(1076003)(110136005)(921005)(54906003)(356005)(41300700001)(426003)(336012)(47076005)(82310400005)(478600001)(83380400001)(7696005)(2616005)(6666004)(107886003)(83996005)(2101003)(12100799018);DIR:OUT;SFP:1501; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 17:34:27.1529 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a90ca49-c1d3-4e51-a8f2-08db1a7b34e1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5439 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Trusted Platform Module requires flow control. As defined in TPM interface specification, client would drive MISO line at same cycle as last address bit on MOSI. Tegra234 and Tegra241 QSPI controllers have TPM wait state detection feature which is enabled for TPM client devices reported in SPI device mode bits. Signed-off-by: Krishna Yarlagadda --- drivers/spi/spi-tegra210-quad.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/spi/spi-tegra210-quad.c b/drivers/spi/spi-tegra210-quad.c index 0b9bc3b7f53a..82aec6cb7863 100644 --- a/drivers/spi/spi-tegra210-quad.c +++ b/drivers/spi/spi-tegra210-quad.c @@ -142,6 +142,7 @@ #define QSPI_GLOBAL_CONFIG 0X1a4 #define QSPI_CMB_SEQ_EN BIT(0) +#define QSPI_TPM_WAIT_POLL_EN BIT(1) #define QSPI_CMB_SEQ_ADDR 0x1a8 #define QSPI_ADDRESS_VALUE_SET(X) (((x) & 0xFFFF) << 0) @@ -164,6 +165,7 @@ struct tegra_qspi_soc_data { bool has_dma; bool cmb_xfer_capable; + bool supports_tpm; unsigned int cs_count; }; @@ -1065,6 +1067,12 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi, /* Enable Combined sequence mode */ val = tegra_qspi_readl(tqspi, QSPI_GLOBAL_CONFIG); + if (spi->mode & SPI_TPM_HW_FLOW) { + if (tqspi->soc_data->supports_tpm) + val |= QSPI_TPM_WAIT_POLL_EN; + else + return -EIO; + } val |= QSPI_CMB_SEQ_EN; tegra_qspi_writel(tqspi, val, QSPI_GLOBAL_CONFIG); /* Process individual transfer list */ @@ -1196,6 +1204,8 @@ static int tegra_qspi_non_combined_seq_xfer(struct tegra_qspi *tqspi, /* Disable Combined sequence mode */ val = tegra_qspi_readl(tqspi, QSPI_GLOBAL_CONFIG); val &= ~QSPI_CMB_SEQ_EN; + if (tqspi->soc_data->supports_tpm) + val &= ~QSPI_TPM_WAIT_POLL_EN; tegra_qspi_writel(tqspi, val, QSPI_GLOBAL_CONFIG); list_for_each_entry(transfer, &msg->transfers, transfer_list) { struct spi_transfer *xfer = transfer; @@ -1454,24 +1464,28 @@ static irqreturn_t tegra_qspi_isr_thread(int irq, void *context_data) static struct tegra_qspi_soc_data tegra210_qspi_soc_data = { .has_dma = true, .cmb_xfer_capable = false, + .supports_tpm = false, .cs_count = 1, }; static struct tegra_qspi_soc_data tegra186_qspi_soc_data = { .has_dma = true, .cmb_xfer_capable = true, + .supports_tpm = false, .cs_count = 1, }; static struct tegra_qspi_soc_data tegra234_qspi_soc_data = { .has_dma = false, .cmb_xfer_capable = true, + .supports_tpm = true, .cs_count = 1, }; static struct tegra_qspi_soc_data tegra241_qspi_soc_data = { .has_dma = false, .cmb_xfer_capable = true, + .supports_tpm = true, .cs_count = 4, };