From patchwork Thu Jul 20 13:58:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 123323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3169743vqt; Thu, 20 Jul 2023 07:45:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlEchIBuhiu2H8HRyMU+a93GyxRBR/im5n1sRANbrtWZRqKKc7pexnWOOQLzk5iasCEtpSES X-Received: by 2002:a17:90a:72c8:b0:261:326d:99e8 with SMTP id l8-20020a17090a72c800b00261326d99e8mr7422132pjk.2.1689864340833; Thu, 20 Jul 2023 07:45:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689864340; cv=pass; d=google.com; s=arc-20160816; b=bUYgOUuEKf7/z7Y/6pyhxQdj8yHYXYvlXlwrwS+gkf954wadGZqb60NrapLpfsIpSD FM9ZFGY0ZGQ6Eo2gRiQyENPaM+wamj75qxsmVdfsNhRUi4VCQwRkWLVbwkMBEPY8b8x1 Ob6qLtR4K0EVlP8lLajAfbSzmDFQ1LJWkDsDFTo5m6u7MwzvSBPTwmoZAo1p+lIHX9nd ySRHyZpu9n2vX0Ueohay2PGUELa0mpCIqbdUwp98Lh5zRWuw6NawL255U5O1r4eepzBx Jx56o2+y50vnfJEsNVCoFcCFFNsiyUpdK0oUjCq0zOxbqBCEAmellCTSruK6CpX/5v6B Y2eA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Vvvbx1BEBpinxsumUX48rt0sTeC+wt2vpJoWkExyF8s=; fh=5sCqXBZldLbRQVwAEJGllRp4L29LJGeGpD2f2le78OE=; b=RzjbhZUTKPqNA4/S3ZUcdlWTZjikzJKyTpJvoM4ubGBychhcvRx5L8Cb+ukGwwshwX toA2zO5V5xIB2DJHceUVOdmxB0oH5t4ug9+wbpOS+w9NwdauhuBHCgaETFVE9wSDQF4i LUWVVuPC7icX2DlpcOy6Rs50wwOfTo3gTlcYxnP7Fmn+j9MjYsZY0e/C763tusgOZO7y 379Ro4OL3MfCU3g+4dNaqMFAczj/ZXYDGa1QzCDHWg+WCqh6Net/RGPWizERjy1chKOI 0q73tmgZMkalYdl7QhcQHgVcUaIKcxuAb7OWqcRb2BuTEkrmny1hMoc45lMiBe/Z8woB Y8uA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=VyWIFSNU; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14-20020a17090acf0e00b00262f798c30csi3646526pju.186.2023.07.20.07.45.27; Thu, 20 Jul 2023 07:45:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=VyWIFSNU; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbjGTN7D (ORCPT + 99 others); Thu, 20 Jul 2023 09:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231759AbjGTN7A (ORCPT ); Thu, 20 Jul 2023 09:59:00 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2064.outbound.protection.outlook.com [40.107.22.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50E511BFC; Thu, 20 Jul 2023 06:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EuOvbtORuQbONwj/CQ5pdmFzwRJXIj/qYOcMuh4hckRGwf/gw9GDMaoydHyYdDN4qOr8ZdfiiAGWn4uAzF/QSpEe+nejPqFxctISStwunaAEa5BHvTouHB3Q+fVgOsAJP8uy8V+uy80DI9voxexeO1boGKaJ2AiN+BdKqFP5BGPXPUoWyA6/MatJOVCrwNFGLEsoSlbUvj1nNMVEmNIckXR99y0C5h8me8whmD62l+DtD6OaG7DY2WeJmUFxq/gApN+dlcefc2R/+Dm5eOyuW/1L72oa2HJOyKXlZ9xVOBsvxJBNfNEMBKjjSHB3IsrKtzj46/fs50vK1gy1IujqmA== 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=Vvvbx1BEBpinxsumUX48rt0sTeC+wt2vpJoWkExyF8s=; b=FsKIwVXt9R2loVF0ctRx7OeNm7fIsFBQUCVQVwwSTdlg/bTdIEwn7PFg6O/KKgdhyS8juLqx5TiezwFLskZjhGsXTbhUUek2ntTfyAbcMGkOjryM9t/CbBtsVYU8118MOPztH4Ntqf2+2SoGKtL2GW062X7C4OH/mp8YGM6eCQ5NhpKLjib8UsEBORkJrks1KeIXLmM/oygnstRfNIxdtQ/kZEZwhKEagakuLGjSBhtwH2pbcuwFG60Oh5rpiOTYpOrVuKf9IP0VxvkOPgpnOPzjLieKs1zrlOPCytGjGXdAI9RXuCc9j5W2sE5HQrzawxjw432T5vPsW81wtyFhAw== 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=Vvvbx1BEBpinxsumUX48rt0sTeC+wt2vpJoWkExyF8s=; b=VyWIFSNUchTMXIR6jVBq9j/HPP2hROpEIufTxMzzbuazefrTEMHbmDh23uSoyskqRA9yeJT6IuRnezhgf7uuUVCzad4ZeKlcisjaGWRlvQ5u1PtD7tEKXddS5vCMYwoZXSDENTrd3O1Kp7zQ7BU4cjlGkIuvWGhgf6P/MoKPSlc= 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 GVXPR04MB9973.eurprd04.prod.outlook.com (2603:10a6:150:112::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Thu, 20 Jul 2023 13:58:58 +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 13:58:58 +0000 From: Frank Li To: frank.li@nxp.com, lpieralisi@kernel.org Cc: Zhiqiang.Hou@nxp.com, bhelgaas@google.com, imx@lists.linux.dev, kernel-janitors@vger.kernel.org, kw@linux.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, mani@kernel.org, markus.elfring@web.de, minghuan.Lian@nxp.com, mingkai.hu@nxp.com, robh@kernel.org, roy.zang@nxp.com, xiaowei.bao@nxp.com Subject: [PATCH v4 2/2] PCI: layerscape: Add the workaround for lost link capabilities during reset. Date: Thu, 20 Jul 2023 09:58:34 -0400 Message-Id: <20230720135834.1977616-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230720135834.1977616-1-Frank.Li@nxp.com> References: <20230720135834.1977616-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR05CA0012.namprd05.prod.outlook.com (2603:10b6:a03:33b::17) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|GVXPR04MB9973:EE_ X-MS-Office365-Filtering-Correlation-Id: 838d610e-1fd4-4576-74ca-08db89297672 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xXA7F94dlh9zBxN5MbPsHXe8419ukd3JNd+YDwFPNxq+N0WnglCC76LefS289LL+ArZoskmoT4LszCRqnM/cVISVIulmYYwhK5DZKK9go/cTN6/0Gicsly6Er8IrPvqeOBqwQtTlFqIwpe0aEMAqSZdIfhIaUveolyv5xWkEsDW0+k3g7Uw0C9ie98XMJOzHGNhMChdEmtoC3LmiEeq9vOWsUA7t1Ze8vcSYgvfpPYlVZn8CeLCSMDGovNJVq/DoTy1TpnZQKGGaYsbGh7hjPNHccSXQT6yOa1cex6WWlX8Khs+MXAueWpDYY1AvfPhF63fVj1uG2nl2NwwVZ3MigKRnB25eaJNo7t4dQqShCh4gQBdOsngTr2vv1uv705cojI8dGuDS1ZD1oDyGHz5A6s+OEC4smgGFDAavG5YvWBV9oDAPRZvx3jxjh1o4HnJ32rHhPNmK+49RUWlYlwi2Mw07WIttQeNh0u7jMX5fudhVDvpNi3Dj2EoW8dQiSKLjwRxh/BiAAAEbtIVwGtedhuDN31okRwp8H/n3ywGoZeuR0fs3QSutO1uE8+Qlsksnu7DhT3KK2CcSHkV/PclWiM4aTlXY20CqeiKWSPQNtk+alb145RRt9CXj2g4UdIgI 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)(136003)(39860400002)(396003)(366004)(346002)(376002)(451199021)(66556008)(478600001)(6666004)(6486002)(52116002)(186003)(36756003)(316002)(6512007)(2616005)(5660300002)(6506007)(2906002)(1076003)(38100700002)(8936002)(66476007)(66946007)(7416002)(4326008)(8676002)(41300700001)(26005)(38350700002)(83380400001)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fHJdL8bMcVOfndCBdGaTAqykQ6csCH9N2TmjCX/ARNUIB+MjdyUFcKY5DsSuWJdgpu7zmo4PLjYjc/S61KwN2+18vk1HPruziDjayKxq0VuqDcyCq9VFeF+9b5gV+KXFUhW7P/iMgsQbKrF/gUuK5YgXEmjKi2AayHhg5bsc901b3a1CQU0vZF5MUHHw441kjEPu/5eChrRdHZQgtjMfH41wiRpWR49X6g+yqPNdHJc7PLA6R3zctD7EI1//bK9sPdmXRA+WdYArpGJrYJANQ2m8EMEaQnkFfYqA0N3A/mm44IE7xNH2z3xEJkg6KWcp8uHdAbXpQrq8txW5kiYmcY1M6iHmT+rwqSn0HQVR9+UU+0J3ZKadQhXLWFbcyHgv8EZncgfJ7T2q3KqOqL8S1Udiql+MEvokn8EvVbD8bYcXrZwPS7VZgVWUopXrG04cZ31d4oeIxvBXxnRAxHECUxqepDO/Tzn8uYoQ1tyj68oqnPD9MR15H508DnF/tnK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sCkvjG8Fp X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 838d610e-1fd4-4576-74ca-08db89297672 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 13:58:57.9125 (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: tTk6OWYVdAhxQv4XFX7CK7fLGb2d8sswtOEKewFDYcSKTc1GfnNhorAhw3Ngant3lcK+FDlMLOkNqqVdYx6fwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9973 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771951190782814562 X-GMAIL-MSGID: 1771951190782814562 From: Xiaowei Bao A workaround for the issue where the PCI Express Endpoint (EP) controller loses the values of the Maximum Link Width and Supported Link Speed from the Link Capabilities Register, which initially configured by the Reset Configuration Word (RCW) during a link-down or hot reset event. Fixes: a805770d8a22 ("PCI: layerscape: Add EP mode support") Acked-by: Manivannan Sadhasivam Signed-off-by: Xiaowei Bao Signed-off-by: Hou Zhiqiang Signed-off-by: Frank Li --- change from v3 to v4 - fix wrong commit a debug code, change pr_err to pr_dbg change from v2 to v3 - fix subject typo capabilities change from v1 to v2: - add comments at restore register - add fixes tag - dw_pcie_writew_dbi to dw_pcie_writel_dbi .../pci/controller/dwc/pci-layerscape-ep.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/pci/controller/dwc/pci-layerscape-ep.c b/drivers/pci/controller/dwc/pci-layerscape-ep.c index e0969ff2ddf7..b1faf41a2fae 100644 --- a/drivers/pci/controller/dwc/pci-layerscape-ep.c +++ b/drivers/pci/controller/dwc/pci-layerscape-ep.c @@ -45,6 +45,7 @@ struct ls_pcie_ep { struct pci_epc_features *ls_epc; const struct ls_pcie_ep_drvdata *drvdata; int irq; + u32 lnkcap; bool big_endian; }; @@ -73,6 +74,7 @@ static irqreturn_t ls_pcie_ep_event_handler(int irq, void *dev_id) struct ls_pcie_ep *pcie = dev_id; struct dw_pcie *pci = pcie->pci; u32 val, cfg; + u8 offset; val = ls_lut_readl(pcie, PEX_PF0_PME_MES_DR); ls_lut_writel(pcie, PEX_PF0_PME_MES_DR, val); @@ -81,6 +83,19 @@ static irqreturn_t ls_pcie_ep_event_handler(int irq, void *dev_id) return IRQ_NONE; if (val & PEX_PF0_PME_MES_DR_LUD) { + + offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + + /* + * The values of the Maximum Link Width and Supported Link + * Speed from the Link Capabilities Register will be lost + * during link down or hot reset. Restore initial value + * that configured by the Reset Configuration Word (RCW). + */ + dw_pcie_dbi_ro_wr_en(pci); + dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, pcie->lnkcap); + dw_pcie_dbi_ro_wr_dis(pci); + cfg = ls_lut_readl(pcie, PEX_PF0_CONFIG); cfg |= PEX_PF0_CFG_READY; ls_lut_writel(pcie, PEX_PF0_CONFIG, cfg); @@ -216,6 +231,7 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev) struct ls_pcie_ep *pcie; struct pci_epc_features *ls_epc; struct resource *dbi_base; + u8 offset; int ret; pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); @@ -252,6 +268,9 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev) platform_set_drvdata(pdev, pcie); + offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + pcie->lnkcap = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCAP); + ret = dw_pcie_ep_init(&pci->ep); if (ret) return ret;