From patchwork Tue Mar 21 21:28:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 665721 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 9715DC6FD1D for ; Tue, 21 Mar 2023 21:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbjCUV2q (ORCPT ); Tue, 21 Mar 2023 17:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjCUV2l (ORCPT ); Tue, 21 Mar 2023 17:28:41 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2056.outbound.protection.outlook.com [40.107.223.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45ECB57094; Tue, 21 Mar 2023 14:28:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BjVzW7t/MGED4A9zEw4YVmUH2aMe8WS1GouEnMqTrnXWtChinwQCycDwL1AhwinBJo0nuTVsAntnlMUnfjYUIdj5LZUAplKy2O0qZrb1sn3UCFF53auE309Vi5MhxcwlSJyqZcD9Y+Qpf6ntazKzRHNh/+ZMgGrPWJOFQ007GXAlMh1U6sw5pHN7mWIL+SB2pXc3Y7hWyG0A1ZB03gtwmlBS8nlX48epdtLyR5VUyxh1sgG3/bk4cJIGqRsrYrKr6Zlgvdww6zYNav0/mo3y6pD/3wXDzSGrGOlrJwM78a3zFZoh8180wnrFLj16D97JCaDk4BGIsF9NSmvYik5xYA== 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=zXwRN0ZeOOPLMGJ0WYs12FUsPQdOi58FoZ0rQzD75lM=; b=MacRirhhGUQV63WmaBj7voTsFgffaxDVUoI4hsUYJnvquAKGO/4yoUYVzBiVIW57emzTlv6wDg/Qmza4MhDf/zehvRLNqsAKNMRSZs61QylZ+ydtRom89XMxg9QPZ8dNlHBpyHGF5x1JHxwYGVHCmYZBc6ZQ2XItyhdMmqD4CclLJ8EEZFa+4DvQoBrAe9ZESzjhtvAuXfGhXeaz8M1sn0ltbx5iMXi1lzRALkZVZsXfNaiqYqqabewG5y+VCDAIUGMBYU0Cn1smTgqp79BVQoZDs51sZYycnazcnkqoFwTvEN8Ps51OY/ASf5fLU0j07Hb/qDUoeboaif+FIE1WaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=chromium.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zXwRN0ZeOOPLMGJ0WYs12FUsPQdOi58FoZ0rQzD75lM=; b=DzH8UhSnYCRgexrhcDE6os4Fkz07bpCE202UFeZCHSTq91Zqf1l25GGfjNTxcU7W8tvisLSYwPLjbY5zbRMyTYAbZaNDlV+o63vv34f4av8d1R24A0mLcRWyE4vvVbQvYAZTEDrX4dlnrJqEncE9uc033r3pLYmYTgOiFz8MdOs= Received: from BN9PR03CA0106.namprd03.prod.outlook.com (2603:10b6:408:fd::21) by DS7PR12MB5765.namprd12.prod.outlook.com (2603:10b6:8:74::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 21:28:36 +0000 Received: from BL02EPF00010207.namprd05.prod.outlook.com (2603:10b6:408:fd:cafe::ba) by BN9PR03CA0106.outlook.office365.com (2603:10b6:408:fd::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Tue, 21 Mar 2023 21:28:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF00010207.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.30 via Frontend Transport; Tue, 21 Mar 2023 21:28:36 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 21 Mar 2023 16:28:34 -0500 From: Mario Limonciello To: Mark Hasemeyer , Grzegorz Bernacki , Jarkko Nikula , "Andy Shevchenko" , Mika Westerberg , Jan Dabros CC: Held Felix , Mario Limonciello , Tom Lendacky , , Subject: [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication Date: Tue, 21 Mar 2023 16:28:20 -0500 Message-ID: <20230321212822.5714-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230321212822.5714-1-mario.limonciello@amd.com> References: <20230321212822.5714-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00010207:EE_|DS7PR12MB5765:EE_ X-MS-Office365-Filtering-Correlation-Id: b04b82d6-fd50-4b69-0d9e-08db2a533b1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /vb0GuOP6UXROS1ewQ+Q63kQnIWWHw6GuEqbbhGPEOO41A78g3U/b0L8+Qb6sT8BbyQpFubxT1RPF0wP9KxZ2cN6WifrT6C/yQwXlKvh/eLIvtw8XSGrPP3IcUjhoWWbHx75m10qlZTODD8t43yjVZEvRsjn3eMPb9sjLbjq5RSFnlmYngKtYYpM9bDDTBesbj8KGP0+iMibQ8DQz6sPrKgjd2+9oginkkcVYXD0O0WA5srGgZc1/JEferetJzVIScvwA5rPBQ68gckUWAnhzmxqt2IRwC/QTMu0eUXqpYo8mpDQJ5GPyfzevi6EHVL+TBipCGXV8ngbeDE4s4NC/byfRgA4tUMENvfVwOdnGiFywFlCdLreyk883gQolKVbQZPD5Vjlwy/5rRiX1TDQKR8FWZNXzcJHoOxUMQAaAmZZ+vvni3TNnf8+WmOW3T6beo+GwlUYNJ4LO8/ZlRc68hM6KRS4DS5bW/wIsiTrnAXHH7S4gFtu6zRb/apJa3f+msTIENG29L6UuMbFibEtTe9wMfPITuK/JbPs43+RvpeG+doCsN/2Puyg2bzbYxcm9vIGWBHLmtHvGupxgJrzRYVLJ4ibAkb94RfKAjxhXQrnOnynnm1MHZIkTNkuahkm+vVT20WV4IwTnPi3fSNLZCEb1ytdITGIZooooS6htngl5uPa/GC1wbPJXExgEPARwcBd1/43u9VQ2RZWxCjjdSo72rybCsOBxukNBW6LWsQ= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(396003)(39860400002)(376002)(346002)(136003)(451199018)(36840700001)(40470700004)(46966006)(2616005)(336012)(1076003)(426003)(26005)(47076005)(110136005)(6666004)(4326008)(83380400001)(8676002)(16526019)(54906003)(316002)(478600001)(70206006)(186003)(70586007)(8936002)(5660300002)(82740400003)(44832011)(2906002)(41300700001)(36860700001)(81166007)(356005)(7696005)(40460700003)(82310400005)(86362001)(36756003)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2023 21:28:36.5000 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b04b82d6-fd50-4b69-0d9e-08db2a533b1d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00010207.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5765 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Currently the PSP semaphore communication base address is discovered by using an MSR that is not architecturally guaranteed for future platforms. Also the mailbox that is utilized for communication with the PSP may have other consumers in the kernel, so it's better to make all communication go through a single driver. Acked-by: Tom Lendacky Acked-by: Jarkko Nikula Signed-off-by: Mario Limonciello --- v4->v5: * Pick up tags v3->v4: * Pick up tags v1->v2: * Fix Kconfig to use imply * Use IS_REACHABLE --- drivers/i2c/busses/Kconfig | 2 +- drivers/i2c/busses/i2c-designware-amdpsp.c | 142 ++------------------ drivers/i2c/busses/i2c-designware-core.h | 1 - drivers/i2c/busses/i2c-designware-platdrv.c | 1 - include/linux/psp-platform-access.h | 1 + 5 files changed, 11 insertions(+), 136 deletions(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 25eb4e8fd22f..d53bf716f97d 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -566,9 +566,9 @@ config I2C_DESIGNWARE_PLATFORM config I2C_DESIGNWARE_AMDPSP bool "AMD PSP I2C semaphore support" - depends on X86_MSR depends on ACPI depends on I2C_DESIGNWARE_PLATFORM + imply CRYPTO_DEV_SP_PSP help This driver enables managed host access to the selected I2C bus shared between AMD CPU and AMD PSP. diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index 652e6b64bd5f..105584abcf8f 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -1,11 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include #include -#include +#include #include -#include #include #include @@ -13,23 +10,15 @@ #include "i2c-designware-core.h" #define MSR_AMD_PSP_ADDR 0xc00110a2 -#define PSP_MBOX_OFFSET 0x10570 -#define PSP_CMD_TIMEOUT_US (500 * USEC_PER_MSEC) #define PSP_I2C_RESERVATION_TIME_MS 100 -#define PSP_I2C_REQ_BUS_CMD 0x64 #define PSP_I2C_REQ_RETRY_CNT 400 #define PSP_I2C_REQ_RETRY_DELAY_US (25 * USEC_PER_MSEC) #define PSP_I2C_REQ_STS_OK 0x0 #define PSP_I2C_REQ_STS_BUS_BUSY 0x1 #define PSP_I2C_REQ_STS_INV_PARAM 0x3 -struct psp_req_buffer_hdr { - u32 total_size; - u32 status; -}; - enum psp_i2c_req_type { PSP_I2C_REQ_ACQUIRE, PSP_I2C_REQ_RELEASE, @@ -41,119 +30,12 @@ struct psp_i2c_req { enum psp_i2c_req_type type; }; -struct psp_mbox { - u32 cmd_fields; - u64 i2c_req_addr; -} __packed; - static DEFINE_MUTEX(psp_i2c_access_mutex); static unsigned long psp_i2c_sem_acquired; -static void __iomem *mbox_iomem; static u32 psp_i2c_access_count; static bool psp_i2c_mbox_fail; static struct device *psp_i2c_dev; -/* - * Implementation of PSP-x86 i2c-arbitration mailbox introduced for AMD Cezanne - * family of SoCs. - */ - -static int psp_get_mbox_addr(unsigned long *mbox_addr) -{ - unsigned long long psp_mmio; - - if (rdmsrl_safe(MSR_AMD_PSP_ADDR, &psp_mmio)) - return -EIO; - - *mbox_addr = (unsigned long)(psp_mmio + PSP_MBOX_OFFSET); - - return 0; -} - -static int psp_mbox_probe(void) -{ - unsigned long mbox_addr; - int ret; - - ret = psp_get_mbox_addr(&mbox_addr); - if (ret) - return ret; - - mbox_iomem = ioremap(mbox_addr, sizeof(struct psp_mbox)); - if (!mbox_iomem) - return -ENOMEM; - - return 0; -} - -/* Recovery field should be equal 0 to start sending commands */ -static int psp_check_mbox_recovery(struct psp_mbox __iomem *mbox) -{ - u32 tmp; - - tmp = readl(&mbox->cmd_fields); - - return FIELD_GET(PSP_CMDRESP_RECOVERY, tmp); -} - -static int psp_wait_cmd(struct psp_mbox __iomem *mbox) -{ - u32 tmp, expected; - - /* Expect mbox_cmd to be cleared and the response bit to be set by PSP */ - expected = FIELD_PREP(PSP_CMDRESP_RESP, 1); - - /* - * Check for readiness of PSP mailbox in a tight loop in order to - * process further as soon as command was consumed. - */ - return readl_poll_timeout(&mbox->cmd_fields, tmp, (tmp == expected), - 0, PSP_CMD_TIMEOUT_US); -} - -/* Status equal to 0 means that PSP succeed processing command */ -static u32 psp_check_mbox_sts(struct psp_mbox __iomem *mbox) -{ - u32 cmd_reg; - - cmd_reg = readl(&mbox->cmd_fields); - - return FIELD_GET(PSP_CMDRESP_STS, cmd_reg); -} - -static int psp_send_cmd(struct psp_i2c_req *req) -{ - struct psp_mbox __iomem *mbox = mbox_iomem; - phys_addr_t req_addr; - u32 cmd_reg; - - if (psp_check_mbox_recovery(mbox)) - return -EIO; - - if (psp_wait_cmd(mbox)) - return -EBUSY; - - /* - * Fill mailbox with address of command-response buffer, which will be - * used for sending i2c requests as well as reading status returned by - * PSP. Use physical address of buffer, since PSP will map this region. - */ - req_addr = __psp_pa((void *)req); - writeq(req_addr, &mbox->i2c_req_addr); - - /* Write command register to trigger processing */ - cmd_reg = FIELD_PREP(PSP_CMDRESP_CMD, PSP_I2C_REQ_BUS_CMD); - writel(cmd_reg, &mbox->cmd_fields); - - if (psp_wait_cmd(mbox)) - return -ETIMEDOUT; - - if (psp_check_mbox_sts(mbox)) - return -EIO; - - return 0; -} - /* Helper to verify status returned by PSP */ static int check_i2c_req_sts(struct psp_i2c_req *req) { @@ -182,10 +64,10 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req) * 2. i2c-requests - PSP refuses to grant i2c arbitration to x86 for too * long. * In order to distinguish between these two in error handling code, all - * errors on the first level (returned by psp_send_cmd) are shadowed by + * errors on the first level (returned by psp_send_platform_access_msg) are shadowed by * -EIO. */ - if (psp_send_cmd(req)) + if (psp_send_platform_access_msg(PSP_I2C_REQ_BUS_CMD, (struct psp_request *)req)) return -EIO; return check_i2c_req_sts(req); @@ -202,7 +84,7 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) if (!req) return -ENOMEM; - req->hdr.total_size = sizeof(*req); + req->hdr.payload_size = sizeof(*req); req->type = i2c_req_type; start = jiffies; @@ -381,7 +263,8 @@ static const struct i2c_lock_operations i2c_dw_psp_lock_ops = { int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) { - int ret; + if (!IS_REACHABLE(CRYPTO_DEV_CCP_DD)) + return -ENODEV; if (!dev) return -ENODEV; @@ -393,11 +276,10 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) if (psp_i2c_dev) return -EEXIST; - psp_i2c_dev = dev->dev; + if (psp_check_platform_access_status()) + return -EPROBE_DEFER; - ret = psp_mbox_probe(); - if (ret) - return ret; + psp_i2c_dev = dev->dev; dev_info(psp_i2c_dev, "I2C bus managed by AMD PSP\n"); @@ -411,9 +293,3 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) return 0; } - -/* Unmap area used as a mailbox with PSP */ -void i2c_dw_amdpsp_remove_lock_support(struct dw_i2c_dev *dev) -{ - iounmap(mbox_iomem); -} diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index 050d8c63ad3c..c5d87aae39c6 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -383,7 +383,6 @@ int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev); #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_AMDPSP) int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev); -void i2c_dw_amdpsp_remove_lock_support(struct dw_i2c_dev *dev); #endif int i2c_dw_validate_speed(struct dw_i2c_dev *dev); diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 74182db03a88..89ad88c54754 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -214,7 +214,6 @@ static const struct i2c_dw_semaphore_callbacks i2c_dw_semaphore_cb_table[] = { #ifdef CONFIG_I2C_DESIGNWARE_AMDPSP { .probe = i2c_dw_amdpsp_probe_lock_support, - .remove = i2c_dw_amdpsp_remove_lock_support, }, #endif {} diff --git a/include/linux/psp-platform-access.h b/include/linux/psp-platform-access.h index 89df4549fada..aca3b148af93 100644 --- a/include/linux/psp-platform-access.h +++ b/include/linux/psp-platform-access.h @@ -7,6 +7,7 @@ enum psp_platform_access_msg { PSP_CMD_NONE = 0x0, + PSP_I2C_REQ_BUS_CMD = 0x64, }; struct psp_req_buffer_hdr { From patchwork Tue Mar 21 21:28:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 665976 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 ED056C6FD1D for ; Tue, 21 Mar 2023 21:28:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230214AbjCUV27 (ORCPT ); Tue, 21 Mar 2023 17:28:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbjCUV2s (ORCPT ); Tue, 21 Mar 2023 17:28:48 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2088.outbound.protection.outlook.com [40.107.244.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A49D85709F; Tue, 21 Mar 2023 14:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YhGLBWaJhOw1dTYKOvhdN7ZqLzEZzp1AGuiKOScE5v24kNUfhCkAe4RwOQCqYmobGgZQghMla03wU0Y13Yb0f2/QfN7nM2b8L3IZYpAEHmsxDlQqJyMPp1HvlMFC0ijoF98fy/uyMrIHT2IDunnpbv9mBstzjekP2vfPYQLPghFZNEJHSnXWn4REttAlg06URCp9xCC7KxZXWr8yvRMohXjVDg81TKFYOtattVj0ndoZQX3pUrrFfR5eB/Y5KjWg31mQoMznDIQ5PInYHcG5MAUPtjMjzdByOl4nfIE1yjF+WLqOGyDMRfre/o3nBLDShufhvwLnXAcWhTBlfpqq3A== 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=wlnaQu3lqbf7sRct1xoJ7owBCNv1DSMNWYFfpbHFy3g=; b=QS2QRAoppZvu0EPoqRZcxEl7x7Y88SHRM73m48SVf91/zklMwBsOp/3cWzo31qCaJTUn6k+zN94EcsCMApLyOaOyDE0nQM2PMhBmeyP2/o5YVy7rEetMONGB6Q+GX2fZmLQXiaisgzd6axyziUmAZAK882LP90T1tRIOw5CtFA0YzXSLiuIiZPtzYMgZ8k3D0529RskeVyOrL1VUxsxB1LLKrw0qV51f2GvPZyE+6+8La7Y/n5J/LKElAM12a6cmtTiFuiDu1oAHmC09OTW6iv+v8C6qyRy8mSRwjwdVRxL6+wv80CQJ8mxcRZHEDyT4JBVe0TW2b3llV5oJtKZaBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=chromium.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wlnaQu3lqbf7sRct1xoJ7owBCNv1DSMNWYFfpbHFy3g=; b=pgwy6MCkSBKPcyT8FbclUcqNzyZRYGteErHEx9YWUKIeZYnFuB+YkawjQ9rdT4X7xOrypFzUEquB+gzYO0eTBlXkToBlXKk9KGfXjL3/leXGEDb2cgzkU7Yom6xYJQ6fO6o3P+1KL4SxN7pcx7Ok/7N7vX6dwGpZ82ECTOVVAKM= Received: from BN9PR03CA0105.namprd03.prod.outlook.com (2603:10b6:408:fd::20) by IA1PR12MB6556.namprd12.prod.outlook.com (2603:10b6:208:3a0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 21:28:37 +0000 Received: from BL02EPF00010207.namprd05.prod.outlook.com (2603:10b6:408:fd:cafe::5c) by BN9PR03CA0105.outlook.office365.com (2603:10b6:408:fd::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Tue, 21 Mar 2023 21:28:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF00010207.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.30 via Frontend Transport; Tue, 21 Mar 2023 21:28:37 +0000 Received: from AUS-LX-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 21 Mar 2023 16:28:35 -0500 From: Mario Limonciello To: Mark Hasemeyer , Grzegorz Bernacki , Jarkko Nikula , "Andy Shevchenko" , Mika Westerberg , Jan Dabros CC: Held Felix , Mario Limonciello , , Subject: [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino Date: Tue, 21 Mar 2023 16:28:21 -0500 Message-ID: <20230321212822.5714-4-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230321212822.5714-1-mario.limonciello@amd.com> References: <20230321212822.5714-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00010207:EE_|IA1PR12MB6556:EE_ X-MS-Office365-Filtering-Correlation-Id: d22a103e-bdd6-4bb0-2f20-08db2a533b81 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9pKFf64zGWywrgswKCWwlKOFRq5Wdn7SmBJQfWYfwQZ9/jGwSU0lkCDMWS57vXDfI2b0wIC3sgnvMbjKzIHjn6GgzCOnR6mKBKPMylc1nO8WoQ3BPBipVJpWU2AcHcHSHM8u79t5yIxNm4FwjWoaVT2A58Px7iq8qZTFoE9peYRrkq5JYNMpMq7kMQYBaPpRI8jK6eADJIDKUAH3JnfPxhW8r6HoucrlQApuGTNVEU8tDS6+w04Id/ceyXGmjm9S1s5VGn5hnw8+9YZJn1PP8pnSQkjkGhRgUqNAMPk3QnM5ewq2JkQJV88gDOhWHh8q3AgssEKflShOjHPyivWCgmbax7EOArfc6Ih7rQ2YxDKaQROBPPIinsBrwzvekTFXb9wY3SVFq/pKBNggyRiaqEkDmG4IY+lCCV9FD6X9zIasWsdcHjukn0e/ODjRoUajqhvAX6kUWVN3ReNSiYh1SA5JjIbCnRTn6UFVr6b2hrDYnU2TxbYuUOIMxcDMrqeu9JasMQqWIzaH62tCGedqXuGbkra8XAZo+eYwsTKDa0fm/xb7pHspW8VyrSBTqreljrTgOdkZkasYEhkFkrHGBIa10nsgyC6v9YtSnMEqU3gcZpRnYODk7tGrwWOKwc/3tubX6fIgMX0kbXHfTRMWOQsiFoNLGca66pZ1fzXu0VXmS9FgisPYQooL6s9PjTQ3v7KZCm6LzgIuallx0UxxEo66r0ey996l18tRm0geOgg= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(346002)(376002)(136003)(39860400002)(396003)(451199018)(36840700001)(40470700004)(46966006)(186003)(1076003)(26005)(7696005)(82740400003)(47076005)(966005)(426003)(2616005)(83380400001)(478600001)(316002)(54906003)(16526019)(110136005)(6666004)(336012)(8676002)(4326008)(70586007)(8936002)(70206006)(41300700001)(36860700001)(44832011)(36756003)(5660300002)(40460700003)(2906002)(40480700001)(356005)(81166007)(86362001)(82310400005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2023 21:28:37.1562 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d22a103e-bdd6-4bb0-2f20-08db2a533b81 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00010207.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6556 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Mendocino and later platform don't use the platform feature mailbox for communication for I2C arbitration, they rely upon ringing a doorbell. Detect the platform by the device ID of the root port and choose the appropriate method. Link: https://lore.kernel.org/linux-i2c/20220916131854.687371-3-jsd@semihalf.com/ Signed-off-by: Mario Limonciello --- v4->v5: * Poll for busy * Rename to mendocino * Add explicit dependency on PCI v3->v4: * Adjust to use PCI device ID and function pointers instead v2->v3: * Use CPU ID rather than ACPI ID, this will be pushed to a later patch v1->v2: * New patch --- drivers/i2c/busses/Kconfig | 1 + drivers/i2c/busses/i2c-designware-amdpsp.c | 52 +++++++++++++++++----- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index d53bf716f97d..2aba5ffa8b03 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -568,6 +568,7 @@ config I2C_DESIGNWARE_AMDPSP bool "AMD PSP I2C semaphore support" depends on ACPI depends on I2C_DESIGNWARE_PLATFORM + depends on PCI imply CRYPTO_DEV_SP_PSP help This driver enables managed host access to the selected I2C bus shared diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index 105584abcf8f..87b6cc345d1d 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -36,6 +37,8 @@ static u32 psp_i2c_access_count; static bool psp_i2c_mbox_fail; static struct device *psp_i2c_dev; +static int (*_psp_send_i2c_req)(enum psp_i2c_req_type); + /* Helper to verify status returned by PSP */ static int check_i2c_req_sts(struct psp_i2c_req *req) { @@ -73,34 +76,55 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req) return check_i2c_req_sts(req); } -static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) +static int psp_send_i2c_req_cezanne(enum psp_i2c_req_type i2c_req_type) { struct psp_i2c_req *req; - unsigned long start; int status, ret; /* Allocate command-response buffer */ req = kzalloc(sizeof(*req), GFP_KERNEL); if (!req) return -ENOMEM; - req->hdr.payload_size = sizeof(*req); req->type = i2c_req_type; - - start = jiffies; ret = read_poll_timeout(psp_send_check_i2c_req, status, (status != -EBUSY), PSP_I2C_REQ_RETRY_DELAY_US, PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US, 0, req); - if (ret) { + kfree(req); + + if (ret) dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n", (i2c_req_type == PSP_I2C_REQ_ACQUIRE) ? "release" : "acquire"); - goto cleanup; - } - ret = status; + return ret ? ret : status; +} + +static int psp_send_i2c_req_mendocino(enum psp_i2c_req_type i2c_req_type) +{ + int status, ret; + + ret = read_poll_timeout(psp_ring_platform_doorbell, status, + (status != -EBUSY), + PSP_I2C_REQ_RETRY_DELAY_US, + PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US, + 0, i2c_req_type); + if (ret) + dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n", + (i2c_req_type == PSP_I2C_REQ_ACQUIRE) ? + "release" : "acquire"); + + return ret ? ret : status; +} + +static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) +{ + unsigned long start = jiffies; + int ret; + + ret = _psp_send_i2c_req(i2c_req_type); if (ret) { dev_err(psp_i2c_dev, "PSP communication error\n"); goto cleanup; @@ -115,7 +139,6 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) psp_i2c_mbox_fail = true; } - kfree(req); return ret; } @@ -263,6 +286,8 @@ static const struct i2c_lock_operations i2c_dw_psp_lock_ops = { int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) { + struct pci_dev *rdev; + if (!IS_REACHABLE(CRYPTO_DEV_CCP_DD)) return -ENODEV; @@ -276,6 +301,13 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) if (psp_i2c_dev) return -EEXIST; + /* Cezanne uses platform mailbox, Mendocino and later use doorbell */ + rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); + if (rdev->device == 0x1630) + _psp_send_i2c_req = psp_send_i2c_req_cezanne; + else + _psp_send_i2c_req = psp_send_i2c_req_mendocino; + if (psp_check_platform_access_status()) return -EPROBE_DEFER;