From patchwork Thu Jul 20 21:09:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13321079 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com 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 6AA00C001DC for ; Thu, 20 Jul 2023 21:09:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230039AbjGTVJo (ORCPT ); Thu, 20 Jul 2023 17:09:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjGTVJn (ORCPT ); Thu, 20 Jul 2023 17:09:43 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2085.outbound.protection.outlook.com [40.107.13.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393991705; Thu, 20 Jul 2023 14:09:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c3K5+0GEiE0+Yz8qNKn6emOx3IseoDO4ksilOvavRXR8pZeBZlTbofVQ6rEaFyy3Dz9j4RIAyxPp7yFOSy0PUJuva/R8tBatvmF2vjo9KeoxgJgzgLWWmfyjQYVyeL1ZtOi/RMR1SYL7TATscS4zqoOZoA90xEHgJvmyRPfUx/SCBAFDMaFbN7ZsGq4gxfTOvu6fKqqcgAUslgRy9/WMGbQ1/lNiKRuuLlp+uuOZhTfGA1y2Qf0pRbk7ntfjyst97QSQsX39h3yimvK2AEApE5Wp7uqmwhCKeRoo3+YMvNLEf7wn+u1gYKtNI6509iON2y2ZL9uXC3Ff/Vx6f27HGQ== 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=/CBxiKMPKjZRwetl/4LDJoYRYcKzNN3zgEQPID7AZDQ=; b=btEVNoPNTOjC8De4riX6yw7/MLBa1KgDx4570prHroTP5gsPRwm+m0Jei3YkWIKWgkdA2Jk+ktZlK4D1dQDFAy5r8R4ZZgHQAJ8xBHhtIQ8wFbRzMeQolHrHrfH6jJtYwe92pQ1DWnH84OTQobWcGBu/Ip3kFyUa2RvntlGY3cHBaE+1LWoortTSKQSFFleI7EWqTcQyhClINdWu2ezGzXj5pb5aO4zz70sIWzf34myBBmKxlanNZIfHESLa99ynEbEoPzRnet4+0Nd4+M/6jCGLtsZpeZGKzEBEGKn/kkvwejPjQKSHRK6UThL1+qYHRHeB483wXJBgEpnE2/esOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/CBxiKMPKjZRwetl/4LDJoYRYcKzNN3zgEQPID7AZDQ=; b=CO1SuthB1AfdfBtiQGV0w6BezMV556VpRvCOBWjA6vKusONncemBtjJ3lj5Aed44iHQhDMNvpAjzX6+FAKWiXKEBtU3HDtaakJjLZMV6889I3pHfm8mfKBZBMW7kz4D/xOCuWz35L3ebw/dJxoW2f0VaQjGzkE9XGu+VeLAhRfE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by VE1PR04MB7392.eurprd04.prod.outlook.com (2603:10a6:800:1b2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.25; Thu, 20 Jul 2023 21:09:39 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::d0d5:3604:98da:20b1]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::d0d5:3604:98da:20b1%7]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 21:09:38 +0000 From: Frank Li To: mani@kernel.org Cc: Frank.li@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, gustavo.pimentel@synopsys.com, helgaas@kernel.org, imx@lists.linux.dev, kw@linux.com, leoyang.li@nxp.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, manivannan.sadhasivam@linaro.org, minghuan.lian@nxp.com, mingkai.hu@nxp.com, robh+dt@kernel.org, roy.zang@nxp.com, shawnguo@kernel.org, zhiqiang.hou@nxp.com Subject: [PATCH v4 1/2] PCI: dwc: Implement general suspend/resume functionality for L2/L3 transitions Date: Thu, 20 Jul 2023 17:09:13 -0400 Message-Id: <20230720210914.2030897-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BY3PR04CA0021.namprd04.prod.outlook.com (2603:10b6:a03:217::26) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|VE1PR04MB7392:EE_ X-MS-Office365-Filtering-Correlation-Id: 8101ac5c-aa0d-42dc-76e2-08db8965a0b6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o/aTvjpR6mNZuycRGEZ3Xl3rbKm42J4fW6dctaDXi2tVzEnQXJ54jh/nWo7u2S/UX/pQUT1dv9xDZRDawWsydWCnSn7YkUeTPdAySJVvfRTbwgJ64CMCxE5UnFZM1eew61f8Cqr50bsyXhlTYzkTmET17117dFgR4twtLtiiGzbx/VoUYyBXuh1zQj2wPoMUgsEDKCaYTZffbKx0/LQilgCJ/3Z0wuPbGHQRONgtyZd8FVnVdAbsffPMl83BjV3bO/i2dNk81O5T9HDjGocxqSvzHJZF2V4kec58WlGwcaeyhsNGj/d1oQSoId69qE+XqEOHXAdIRksqlU3R52WYAOAESteOSj6dRPYygkm5s+ArGR+tkOgcu8aneqj7B4XxNcXiIHYmG3zr5B+l4L6uetqe+iaGd3KV52wcwqIjTgucu52c6o1Z/UGv7wS3YfE+0KX9gcBPa6YDX5ktuQIZ7uLIaPwYBsO55GR3jM060VdaGclwgNiSgJuD4mP01+WD6iIEl7jj2LA6V9LyLTVPKOHGaoeinxb4sqYGhkIX7j6wXjiiya1U7b6RqgGPgaymPdusu9FEBNyPr5CpXuq+nSTRSznfrIT7dnqM4qTzI3UG1pM+xiuJ5na3nBITzkf+ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(86362001)(36756003)(6486002)(66946007)(6666004)(478600001)(66556008)(4326008)(6506007)(52116002)(6916009)(1076003)(66476007)(26005)(2906002)(6512007)(15650500001)(316002)(41300700001)(8936002)(8676002)(5660300002)(7416002)(38350700002)(38100700002)(83380400001)(2616005)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Cmo5xQy2KkIRbxIumN3ZK4tpfq0t8zs/uK0PMjdWIRvh29R4gIpM899o9/dv8T3FNfKpaH75J1pI6I+XhBlP8fbM/4II3y5e39oR3V88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maPcmON6sIUbyaXWa6RFY91/UD0clTHJVxrj0oXMdI4zVvYhBvALqqB+qMosgAHILn/wwL5eiytljt+VZxg7aYU3t90KVBNJxRPX54VpCuajrel/LGViWDo39I68Yqg1F6om24Ua+SU1rKHA/qzT2l3l6s1aWEctXQfmiquV4XmSAHWM9OQmUGRGhr8zEgUUFdiI0y7JrlJROWgb2E2vIImGwZNUIWvqDqFcFGqo6XQ7+MkP/K+vxsUQj13S+ChnZrOHnFIuoSBFnRzPexwKtW7L92y2R5K7OQWpaguvHjseqRPyoKNlKYtWfPtQcwrrZgnC5i8WCacOroaU5+dDQbQ54loRDRHhbT6yYd2aj8JqdJDfro03tPhQIkG1q3oeHuMSV+PCwv3eagzEKulgKL4Q3fbMZdHh9c2ws2GXAZ87t X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8101ac5c-aa0d-42dc-76e2-08db8965a0b6 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 21:09:38.5751 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jwQXi1YQTd658uOoGbkmmIqwTRt7PP9MR54XVQuz/KNHB3/M6hayfKa7whHaCUbWmnyCFePyOFFk43o9PgTB2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7392 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Introduced helper function dw_pcie_get_ltssm to retrieve SMLH_LTSS_STATE. Added API pme_turn_off and exit_from_l2 for managing L2/L3 state transitions. Typical L2 entry workflow: 1. Transmit PME turn off signal to PCI devices and wait for PME_To_Ack. 2. Await link entering L2_IDLE state. 3. Transition Root complex to D3 state. Typical L2 exit workflow: 1. Transition Root complex to D0 state. 2. Issue exit from L2 command. 3. Reinitialize PCI host. 4. Wait for link to become active. Signed-off-by: Frank Li --- Change from v3 to v4: - change according to Manivannan's comments. I hope I have not missed anything. quite long discuss thread Change from v2 to v3: - Basic rewrite whole patch according rob herry suggestion. put common function into dwc, so more soc can share the same logic. .../pci/controller/dwc/pcie-designware-host.c | 95 +++++++++++++++++++ drivers/pci/controller/dwc/pcie-designware.h | 28 ++++++ 2 files changed, 123 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 9952057c8819..a8d8495e4974 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -8,6 +8,7 @@ * Author: Jingoo Han */ +#include #include #include #include @@ -807,3 +808,97 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp) return 0; } EXPORT_SYMBOL_GPL(dw_pcie_setup_rc); + +/* + * This resemble the pci_set_power_state() interfaces, but these are for + * configuring host controllers, which are bridges *to* PCI devices but + * are not PCI devices themselves. + */ +static void dw_pcie_set_dstate(struct dw_pcie *pci, pci_power_t dstate) +{ + u8 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_PM); + u32 val; + + val = dw_pcie_readw_dbi(pci, offset + PCI_PM_CTRL); + val &= ~PCI_PM_CTRL_STATE_MASK; + val |= dstate; + dw_pcie_writew_dbi(pci, offset + PCI_PM_CTRL, val); +} + +int dw_pcie_suspend_noirq(struct dw_pcie *pci) +{ + u8 offset; + u32 val; + int ret; + + offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + /* + * If L1.1\L1.2 enable, devices (such as NVME) want short + * resume latency, controller will not enter L2 + */ + if (dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKCTL) & PCI_EXP_LNKCTL_ASPM_L1) + return 0; + + if (dw_pcie_get_ltssm(pci) <= DW_PCIE_LTSSM_DETECT_ACT) + return 0; + + if (!pci->pp.ops->pme_turn_off) + return -EINVAL; + + pci->pp.ops->pme_turn_off(&pci->pp); + + /* + * PCI Express Base Specification Rev 4.0 + * 5.3.3.2.1 PME Synchronization + * Recommand 1ms to 10ms timeout to check L2 ready + */ + ret = read_poll_timeout(dw_pcie_get_ltssm, val, val == DW_PCIE_LTSSM_L2_IDLE, + 100, 10000, false, pci); + if (ret) { + dev_err(pci->dev, "PCIe link enter L2 timeout! ltssm = 0x%x\n", val); + return ret; + } + + dw_pcie_set_dstate(pci, PCI_D3hot); + + pci->suspended = true; + + return ret; +} +EXPORT_SYMBOL_GPL(dw_pcie_suspend_noirq); + +int dw_pcie_resume_noirq(struct dw_pcie *pci) +{ + int ret; + + if (!pci->suspended) + return 0; + + pci->suspended = false; + + dw_pcie_set_dstate(pci, PCI_D0); + + if (!pci->pp.ops->exit_from_l2) + return -EINVAL; + + pci->pp.ops->exit_from_l2(&pci->pp); + + ret = pci->pp.ops->host_init(&pci->pp); + if (ret) { + dev_err(pci->dev, "Host init failed! ret = 0x%x\n", ret); + return ret; + } + + dw_pcie_setup_rc(&pci->pp); + + ret = dw_pcie_start_link(pci); + if (ret) + return ret; + + ret = dw_pcie_wait_for_link(pci); + if (ret) + return ret; + + return ret; +} +EXPORT_SYMBOL_GPL(dw_pcie_resume_noirq); diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index 79713ce075cc..effb07a506e4 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -288,10 +288,21 @@ enum dw_pcie_core_rst { DW_PCIE_NUM_CORE_RSTS }; +enum dw_pcie_ltssm { + DW_PCIE_LTSSM_UNKNOWN = 0xFFFFFFFF, + /* Need align PCIE_PORT_DEBUG0 bit0:5 */ + DW_PCIE_LTSSM_DETECT_QUIET = 0x0, + DW_PCIE_LTSSM_DETECT_ACT = 0x1, + DW_PCIE_LTSSM_L0 = 0x11, + DW_PCIE_LTSSM_L2_IDLE = 0x15, +}; + struct dw_pcie_host_ops { int (*host_init)(struct dw_pcie_rp *pp); void (*host_deinit)(struct dw_pcie_rp *pp); int (*msi_host_init)(struct dw_pcie_rp *pp); + void (*pme_turn_off)(struct dw_pcie_rp *pp); + void (*exit_from_l2)(struct dw_pcie_rp *pp); }; struct dw_pcie_rp { @@ -364,6 +375,7 @@ struct dw_pcie_ops { void (*write_dbi2)(struct dw_pcie *pcie, void __iomem *base, u32 reg, size_t size, u32 val); int (*link_up)(struct dw_pcie *pcie); + enum dw_pcie_ltssm (*get_ltssm)(struct dw_pcie *pcie); int (*start_link)(struct dw_pcie *pcie); void (*stop_link)(struct dw_pcie *pcie); }; @@ -393,6 +405,7 @@ struct dw_pcie { struct reset_control_bulk_data app_rsts[DW_PCIE_NUM_APP_RSTS]; struct reset_control_bulk_data core_rsts[DW_PCIE_NUM_CORE_RSTS]; struct gpio_desc *pe_rst; + bool suspended; }; #define to_dw_pcie_from_pp(port) container_of((port), struct dw_pcie, pp) @@ -430,6 +443,9 @@ void dw_pcie_iatu_detect(struct dw_pcie *pci); int dw_pcie_edma_detect(struct dw_pcie *pci); void dw_pcie_edma_remove(struct dw_pcie *pci); +int dw_pcie_suspend_noirq(struct dw_pcie *pci); +int dw_pcie_resume_noirq(struct dw_pcie *pci); + static inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val) { dw_pcie_write_dbi(pci, reg, 0x4, val); @@ -501,6 +517,18 @@ static inline void dw_pcie_stop_link(struct dw_pcie *pci) pci->ops->stop_link(pci); } +static inline enum dw_pcie_ltssm dw_pcie_get_ltssm(struct dw_pcie *pci) +{ + u32 val; + + if (pci->ops && pci->ops->get_ltssm) + return pci->ops->get_ltssm(pci); + + val = dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0); + + return (enum dw_pcie_ltssm)FIELD_GET(PORT_LOGIC_LTSSM_STATE_MASK, val); +} + #ifdef CONFIG_PCIE_DW_HOST irqreturn_t dw_handle_msi_irq(struct dw_pcie_rp *pp); int dw_pcie_setup_rc(struct dw_pcie_rp *pp); From patchwork Thu Jul 20 21:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13321080 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com 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 A01F7C001DC for ; Thu, 20 Jul 2023 21:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbjGTVJv (ORCPT ); Thu, 20 Jul 2023 17:09:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230148AbjGTVJt (ORCPT ); Thu, 20 Jul 2023 17:09:49 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2062.outbound.protection.outlook.com [40.107.6.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C34A271D; Thu, 20 Jul 2023 14:09:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=llKwQjRMFM3DJpOnE2iPK84NtVclTPXkQkbrc4KT4Kn8yL/L3BH/51yZPiUQlr2nvpzWhULrFArR1UUNpXTmAHaTiXwInxQDDusj53uZZT/Jx2jAF2A/JkbsOpBbDffxNH1Pvb3JiXR5U9O47FGoHo0pda21H9VWKOSquTLBRtSRUtMW84+kWr2L1N3vw/V/dhOsgZD+rh29ZSz/HtJ+tXEK1ibRb8J3YbfwASFTu1w/X8kd/1DPpIhYC7ynJzdEbru+ILSXt+kvW6PvKOWSihlBjvAYTA+UJ6dorlLCCVMkwZJl8R+M39kIDVcktplJsUKx2z+I1mPdQ08LLeSxIw== 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=uthF2w5R0NQ4CXWx69tOD6VjTW8sR/IU5IXc7JQA7z8=; b=PRdzsVs/ZMfIPgtIq9+wguRO/FCUxUiKXNedS8x4KG9N6rUik5u7Zm7uES/L3TlVTEqcL05gL5za7alaR+q/wGKu48fR3fyBRczCRRY3rpwaH9cXSArgIuj6uOB7GYFn3zw5I0x8TimV361LMxJ3btrfmtU6NOHAgX9d630ym+A64jYD0WgOEu+1xfddx4QlVJuDwcF+/zxlp7GnG6KsqtwLULbz3DyVPQZ+hk2Tne2XRoX3d1ANhyeYlvd3MeafsBUL7QRh6cXHbnVVqqg423nzumC2vQY9DsirwypdoIFEQQVHEWU1FX06vS1JxZFWy9phtL1NUR2OqUJ33Qm2Dg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uthF2w5R0NQ4CXWx69tOD6VjTW8sR/IU5IXc7JQA7z8=; b=WiivIiv18LybhpoXNvnufex2S4Y+lRL6ElhOdiiS/jBlYB3mO5g8WmRrX3mEPwK1CIy6OfDGzsuWHBi7BOMMSLuRCOBeRSsd8I1zJGfVvesr1QP0BPRfcFUgZ6+/UXksUWwIQ1UgKUGzTkeHb8uI+Zrw+NxpclvckO+Ujq5GWiw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 21:09:44 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::d0d5:3604:98da:20b1]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::d0d5:3604:98da:20b1%7]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 21:09:43 +0000 From: Frank Li To: mani@kernel.org Cc: Frank.li@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, gustavo.pimentel@synopsys.com, helgaas@kernel.org, imx@lists.linux.dev, kw@linux.com, leoyang.li@nxp.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, manivannan.sadhasivam@linaro.org, minghuan.lian@nxp.com, mingkai.hu@nxp.com, robh+dt@kernel.org, roy.zang@nxp.com, shawnguo@kernel.org, zhiqiang.hou@nxp.com Subject: [PATCH v4 2/2] PCI: layerscape: Add power management support for ls1028a Date: Thu, 20 Jul 2023 17:09:14 -0400 Message-Id: <20230720210914.2030897-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230720210914.2030897-1-Frank.Li@nxp.com> References: <20230720210914.2030897-1-Frank.Li@nxp.com> X-ClientProxiedBy: BY3PR04CA0021.namprd04.prod.outlook.com (2603:10b6:a03:217::26) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|DU0PR04MB9417:EE_ X-MS-Office365-Filtering-Correlation-Id: 409eb9a5-8597-4232-cdf5-08db8965a3c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2WCeyal0Zqkm0yRNDYOvGwQwJ0tJl09IFuSTXaIXN7IdhtUjOcS3/JILJsZ67QK7p+y4+KtNEFv0Vn4NYBs/6RNk96jwR63Har+KUpBE6nOpd3Tz1DMSFV4kNvK0QQp0tpOJLlXHuSI33+yextc0C7U10PPJ4kIAEwbp2es3uxetjxADv441rplw6ctlGyy3BbPyU5nihljwG/pY4hf0nOtwMrCHJuVABGih0hgNdDlPxDeQlPYft56Vxg1/RNMbRuUJnP5cllr4QTqHrYGdpQHriOnetDQS1VyGVoty7uvPOw5RCmN2jvrtV82tcWqlhgqFicoOPYWcEtX/GgvKADLYBxvtSx6463fH+ZeO8uc7zF1hLjjq/zxKQd4KF92NGT69Y+Aimgpy3ofifHWpKwT+84ql+0aUMPTtm9DtKNh7Ba1zrOkYc1VB3wGEIb6ltILR2JMZY/r7Yk3wqXsZEJYP2twWrol0sBrl++yU50r7hb25Hs81N2LhP8akpr58P5kvAKTyb5SHud4Eya8YZWVF4ZrImrHvAOfhuYmo33oE6aRjV0bbhQ9d2D+jJDDxy2pPNMS5w+6cGBiRjh4cGVc2LG53kMYjnyzGegl/HqZqpyKpCP6UoK1JB/hVF4RM X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(39860400002)(346002)(396003)(136003)(451199021)(66946007)(6512007)(66556008)(6666004)(66476007)(6486002)(2906002)(6916009)(8676002)(7416002)(316002)(8936002)(4326008)(36756003)(38350700002)(5660300002)(6506007)(52116002)(2616005)(38100700002)(186003)(1076003)(26005)(41300700001)(83380400001)(86362001)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-Ant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BWu1/a1bnnkMPZAwSsojnK+B6EnN+Mma16pqbo4EdsXsXV4jxFy9ZwHHc5VFX4owfPyOikeShizg2BUXjiSW28P3poxCkVyFKzA8iwncDLP+kHHTEFp5wJqKwDe3G4LucI1Gmcg8vfWLLKNO1vA8vBDt9LLb7kSzdT5KTp9duIRaQpJz0SPWA2ElJn6/Ef89dlCn8IF3uI2pIb2zK+YlMT47XRObQk86rkGNTS1i8BkQPVI9uNJUdO3aH4Nag47o3vM1NJYJmJpPxLz5WlvXooUbQICjujOYbMjeLXuiSUMXa9r2j6eGCkdc5Tjl+I43N23NW+fDGyua7m38B4R85vBN9D6X/x3XlvxkzN0XlQA0FHzzEX7mNM9kpWa0It5DhQKv20Qek6D4spuMZPJnYZYmWMoKX5vsTZtM+SqLKcTWzpvUtipu4SJpZd2j3gCFmKm5kHtsa8pb2ieyeNtanEp6eatDRLLB5dtOM2jltfoXlaEVrSHqFHcTKpKQHfztJzT1DzvEMK653uk7 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 409eb9a5-8597-4232-cdf5-08db8965a3c6 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 21:09:43.8991 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: i+e7396rNB72wH4lpQhgADofnokoZT1urIqaFSOU3B4VKa6Ce4NlUSOxpfnOpNEZC1FlRQxrOUGymY5w9lP5aQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9417 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Hou Zhiqiang Add PME_Turn_Off/PME_TO_Ack handshake sequence, and finally put the PCIe controller into D3 state after the L2/L3 ready state transition process completion. Signed-off-by: Hou Zhiqiang Signed-off-by: Frank Li --- - Change from v3 to v4 none - change at v3 Basic rewrite whole patch according rob herry suggestion. put common function into dwc, so more soc can share the same logic. drivers/pci/controller/dwc/pci-layerscape.c | 148 ++++++++++++++++++-- 1 file changed, 139 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-layerscape.c b/drivers/pci/controller/dwc/pci-layerscape.c index ed5fb492fe08..32832d74a074 100644 --- a/drivers/pci/controller/dwc/pci-layerscape.c +++ b/drivers/pci/controller/dwc/pci-layerscape.c @@ -8,9 +8,11 @@ * Author: Minghuan Lian */ +#include #include #include #include +#include #include #include #include @@ -27,12 +29,33 @@ #define PCIE_ABSERR 0x8d0 /* Bridge Slave Error Response Register */ #define PCIE_ABSERR_SETTING 0x9401 /* Forward error of non-posted request */ +/* PF Message Command Register */ +#define LS_PCIE_PF_MCR 0x2c +#define PF_MCR_PTOMR BIT(0) +#define PF_MCR_EXL2S BIT(1) + #define PCIE_IATU_NUM 6 +struct ls_pcie; + +struct ls_pcie_drvdata { + const u32 pf_off; + const u32 lut_off; + bool pm_support; +}; + struct ls_pcie { struct dw_pcie *pci; + const struct ls_pcie_drvdata *drvdata; + void __iomem *pf_base; + void __iomem *lut_base; + bool big_endian; + bool ep_presence; + struct regmap *scfg; + int index; }; +#define ls_pcie_pf_readl_addr(addr) ls_pcie_pf_readl(pcie, addr) #define to_ls_pcie(x) dev_get_drvdata((x)->dev) static bool ls_pcie_is_bridge(struct ls_pcie *pcie) @@ -73,6 +96,57 @@ static void ls_pcie_fix_error_response(struct ls_pcie *pcie) iowrite32(PCIE_ABSERR_SETTING, pci->dbi_base + PCIE_ABSERR); } +static u32 ls_pcie_pf_readl(struct ls_pcie *pcie, u32 off) +{ + if (pcie->big_endian) + return ioread32be(pcie->pf_base + off); + + return ioread32(pcie->pf_base + off); +} + +static void ls_pcie_pf_writel(struct ls_pcie *pcie, u32 off, u32 val) +{ + if (pcie->big_endian) + return iowrite32be(val, pcie->pf_base + off); + + return iowrite32(val, pcie->pf_base + off); + +} + +static void ls_pcie_send_turnoff_msg(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct ls_pcie *pcie = to_ls_pcie(pci); + u32 val; + int ret; + + val = ls_pcie_pf_readl(pcie, LS_PCIE_PF_MCR); + val |= PF_MCR_PTOMR; + ls_pcie_pf_writel(pcie, LS_PCIE_PF_MCR, val); + + ret = readx_poll_timeout(ls_pcie_pf_readl_addr, LS_PCIE_PF_MCR, + val, !(val & PF_MCR_PTOMR), 100, 10000); + if (ret) + dev_info(pcie->pci->dev, "poll turn off message timeout\n"); +} + +static void ls_pcie_exit_from_l2(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct ls_pcie *pcie = to_ls_pcie(pci); + u32 val; + int ret; + + val = ls_pcie_pf_readl(pcie, LS_PCIE_PF_MCR); + val |= PF_MCR_EXL2S; + ls_pcie_pf_writel(pcie, LS_PCIE_PF_MCR, val); + + ret = readx_poll_timeout(ls_pcie_pf_readl_addr, LS_PCIE_PF_MCR, + val, !(val & PF_MCR_EXL2S), 100, 10000); + if (ret) + dev_info(pcie->pci->dev, "poll exit L2 state timeout\n"); +} + static int ls_pcie_host_init(struct dw_pcie_rp *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); @@ -91,18 +165,33 @@ static int ls_pcie_host_init(struct dw_pcie_rp *pp) static const struct dw_pcie_host_ops ls_pcie_host_ops = { .host_init = ls_pcie_host_init, + .pme_turn_off = ls_pcie_send_turnoff_msg, + .exit_from_l2 = ls_pcie_exit_from_l2, +}; + +static const struct ls_pcie_drvdata ls1021a_drvdata = { +}; + +static const struct ls_pcie_drvdata ls1043a_drvdata = { + .lut_off = 0x10000, +}; + +static const struct ls_pcie_drvdata layerscape_drvdata = { + .lut_off = 0x80000, + .pf_off = 0xc0000, + .pm_support = true, }; static const struct of_device_id ls_pcie_of_match[] = { - { .compatible = "fsl,ls1012a-pcie", }, - { .compatible = "fsl,ls1021a-pcie", }, - { .compatible = "fsl,ls1028a-pcie", }, - { .compatible = "fsl,ls1043a-pcie", }, - { .compatible = "fsl,ls1046a-pcie", }, - { .compatible = "fsl,ls2080a-pcie", }, - { .compatible = "fsl,ls2085a-pcie", }, - { .compatible = "fsl,ls2088a-pcie", }, - { .compatible = "fsl,ls1088a-pcie", }, + { .compatible = "fsl,ls1012a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls1021a-pcie", .data = &ls1021a_drvdata }, + { .compatible = "fsl,ls1028a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls1043a-pcie", .data = &ls1043a_drvdata }, + { .compatible = "fsl,ls1046a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls2080a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls2085a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls2088a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls1088a-pcie", .data = &layerscape_drvdata }, { }, }; @@ -121,6 +210,8 @@ static int ls_pcie_probe(struct platform_device *pdev) if (!pci) return -ENOMEM; + pcie->drvdata = of_device_get_match_data(dev); + pci->dev = dev; pci->pp.ops = &ls_pcie_host_ops; @@ -131,6 +222,14 @@ static int ls_pcie_probe(struct platform_device *pdev) if (IS_ERR(pci->dbi_base)) return PTR_ERR(pci->dbi_base); + pcie->big_endian = of_property_read_bool(dev->of_node, "big-endian"); + + if (pcie->drvdata->lut_off) + pcie->lut_base = pci->dbi_base + pcie->drvdata->lut_off; + + if (pcie->drvdata->pf_off) + pcie->pf_base = pci->dbi_base + pcie->drvdata->pf_off; + if (!ls_pcie_is_bridge(pcie)) return -ENODEV; @@ -139,12 +238,43 @@ static int ls_pcie_probe(struct platform_device *pdev) return dw_pcie_host_init(&pci->pp); } +#ifdef CONFIG_PM_SLEEP +static int ls_pcie_suspend_noirq(struct device *dev) +{ + struct ls_pcie *pcie = dev_get_drvdata(dev); + struct dw_pcie *pci = pcie->pci; + + if (!pcie->drvdata->pm_support) + return 0; + + return dw_pcie_suspend_noirq(pci); +} + +static int ls_pcie_resume_noirq(struct device *dev) +{ + + struct ls_pcie *pcie = dev_get_drvdata(dev); + struct dw_pcie *pci = pcie->pci; + + if (!pcie->drvdata->pm_support) + return 0; + + return dw_pcie_resume_noirq(pci); +} +#endif /* CONFIG_PM_SLEEP */ + +static const struct dev_pm_ops ls_pcie_pm_ops = { + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(ls_pcie_suspend_noirq, + ls_pcie_resume_noirq) +}; + static struct platform_driver ls_pcie_driver = { .probe = ls_pcie_probe, .driver = { .name = "layerscape-pcie", .of_match_table = ls_pcie_of_match, .suppress_bind_attrs = true, + .pm = &ls_pcie_pm_ops, }, }; builtin_platform_driver(ls_pcie_driver);