From patchwork Tue Nov 19 06:21:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongxing Zhu X-Patchwork-Id: 13879442 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2045.outbound.protection.outlook.com [40.107.22.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC8FB14A0B5 for ; Tue, 19 Nov 2024 06:22:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731997364; cv=fail; b=d6U1xV/2DF15upcXBXbgdfH+igo+GD6IGCr19gIEAOI4wXGOsWZv0ePTWJ6Otw27i3LCVY7x05CC9OW+MGUT3NBpUifYig4lGrdSF6osmkyS4vDW/dzIhcH8EvycDPyUM5UR4HttwxSDvqs2z30IZluZ9dz7WGwgkrp2yuytB7I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731997364; c=relaxed/simple; bh=iyaReOFvWURz/CKD8k3Hyp1sLUcEDvaqs2MCTJoowo0=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=MFEF6KD5OMLmNNm5wWfg0Fn6jPrFdeYO/YRSKuXqJTfuTzQz3ivfBHAX1E/QMuxF5tpLHgXYtzTwnEEkG4N4hxoU1vftYi0j+Sl+TA2k8e4Js0CPyRq1siDUN3QP6OAdIYKJm9ak1+cRQmPsh+4vNC84ZFzjlcg1FmpSSQhsuQQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=jzJwFoAw; arc=fail smtp.client-ip=40.107.22.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="jzJwFoAw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yMppoYetg5UxUN/GLxzPPn+B4rkXiOYm3g56BRNiOLatWNrUw201XZ/5dhzDRGALik081syxLQ4X144kKhadqvKskO6gP5We6dehspzYXKrvTpXc733wTtroWJBaBpV1Dsx8Pi5aBtiZx0U2FJP1ZqUqTfuMCBtebqAUAz44tRTDafaPiKgtbdH04fAHYOHG7liV3ABbbH9eu0Skd0T8MIPeAITujobrqzB3x7vEPWpr971Uos8J+s3l4G7zZIsO9Zjj/W7QVRoKglfAuUPfJUskfBcb5nn/Jo5hLy9uyCnOuhJebvEkSwSj2iPRafDUDISZe7UoYqjW+P0Kwvz06Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=CAjvFpgbJBuv52VTYiDV/mxwXI7ZgeJn2QvxYJ1lA/U=; b=dlZSE2uqXBvzrAySWaHoaXUctwSZPtKH9nalTkPi/6GUYMtIle5u/OlEVCBcu1o1Fv6l3GTGwSV9J2NjjFxua1qK4n0TGAlRiRY7FUD/TCIuBI5hkLscPnAEgFzM6QKfVGAdtmhGgKzKct8JA0o5BqO6zEdWoB6BYwTj+ylf7oanv98KFnvGVoIvuCnP1yo5JDlsFMj2Ya6RTPXiTSj5HCQiDEB2i6jEnqG7ENfrNyNNU4FjjwM5xJy/kQ5UK3B8mc10cIJbZqG/8Td4lYeaYjWo1sBktk5e1/uPAgo7ArC19M6WpqD1PYClsDZssjvGfr/zw4lmW9TINVjvn/3j2A== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CAjvFpgbJBuv52VTYiDV/mxwXI7ZgeJn2QvxYJ1lA/U=; b=jzJwFoAwmrpRdxBQkoa2yZKjDCQDkvo/PrGN2b0gCX4SX/u5Scb4K7d427tME/QD9GZg3FrrGtkdtEMV0odcMUjfaaZbHmYdJnLhcMbqvTUeUOM3J6InrO1ocejX6OpdeIX/tJF1M70PLZ8uDnEnFfUSrlWuVyLLz9xadginEzT7C7SNCqt5d8cLjxC0oaL1d1f9iIsPI4L7ioymQsBM9+ohxfOjPascRSuhO4stP978cAAluB1l/0emvrjBldrcDEmOOfj6LibASJa7qKBEujT0JDLZ7/I+AvcatG4aCciUNyYsVPVfNbc8fiBWQXOm5+KWezlQnxqH+TUQhg7+xA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8676.eurprd04.prod.outlook.com (2603:10a6:20b:42b::10) by PA1PR04MB10746.eurprd04.prod.outlook.com (2603:10a6:102:484::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.23; Tue, 19 Nov 2024 06:22:39 +0000 Received: from AS8PR04MB8676.eurprd04.prod.outlook.com ([fe80::28b2:de72:ad25:5d93]) by AS8PR04MB8676.eurprd04.prod.outlook.com ([fe80::28b2:de72:ad25:5d93%7]) with mapi id 15.20.8158.023; Tue, 19 Nov 2024 06:22:39 +0000 From: Richard Zhu To: jingoohan1@gmail.com, bhelgaas@google.com, lpieralisi@kernel.org, kw@linux.com, manivannan.sadhasivam@linaro.org, robh@kernel.org, frank.li@nxp.com, quic_krichai@quicinc.com Cc: imx@lists.linux.dev, kernel@pengutronix.de, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Richard Zhu Subject: [PATCH v4] PCI: dwc: Clean up some unnecessary codes in dw_pcie_suspend_noirq() Date: Tue, 19 Nov 2024 14:21:21 +0800 Message-Id: <20241119062121.620913-1-hongxing.zhu@nxp.com> X-Mailer: git-send-email 2.37.1 X-ClientProxiedBy: SI2PR04CA0011.apcprd04.prod.outlook.com (2603:1096:4:197::10) To AS8PR04MB8676.eurprd04.prod.outlook.com (2603:10a6:20b:42b::10) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8676:EE_|PA1PR04MB10746:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d396fab-a103-4230-189d-08dd086290f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|7416014|366016|38350700014; X-Microsoft-Antispam-Message-Info: jgZeuxcOFb4vvDEYouloUpfl5ouwGnxYFoE2lOm7evF8i6ztJAQrOhrSOu2i5r/Q0Z5qGqZSl2H0gsqDCHCMtG4/5yBaA2E61vEyNVuJ7lZBu4mJhVjPa16+j1Ipg2R1Z26Uh5iIiXKO+psyF+C+7lVp7IyiXMB6I2iv6ZQvJAd2JMd6V+jt8TQ6Y0WNQ8N22MJG3sR3S7j3dyTPT9LTVnLaN0SYcI+t/4a394ZCXwITt/wftHEBowD6K6QzOg9h16WiK91bua0jG9MPRozHDx2IFfrKDzgQla96pH2O/N+XMC18+p7/RGV00D/Dqj/Ba5Qz9WCiwhQzv3lAO6J2fFor5rZ5D5ujyTbw+rtJdZR9dnTj2zLLKMNWI/F4Jkpzv27CXHmxxUtczsyzWfg3XxdGh3XlVEUJ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E;SFS:(13230040)(52116014)(376014)(1800799024)(7416014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SGjLovBVQTdZdjEW7JiYarlREXjEN/7Att5xwn2bcV7k8YOMcOi2WkhhElws48ugnrDTPHWF8yrpSj82SXbwLaXpj9qXBbSoeGoPGNVdtSKogz6bowoFWeBPUvjegI4P0pCwOyGubUrB8+Mb9UYRsQXEH908QMz26RowlHDmh7CLKuQN3z3uY3PxVygex/1GOrpt6khLdu3tXNXx9+Pct7KPi7givEP7b+PwVfhLWKjk2gJENu9ofYjWDX6jflbJDAfAMYLpJVxDY0qYppbl+ZhM9AKhJCTMakgqdXiGLLy69PcuHaTWbSQTE3MJgCwXy1267XkqjWlVidsTj7EjTthV7gejGZl6lpK+nqNKNcXzU0R4/60Y2JOBken2KEW3HYY6UY/oab+Y8+CGnXxrPJDARv/ZbduJRJ7t+qk/vHyzSIQg6Iai0Jjz6q3JQ6vI2enjC7UKz19Kf4bVPBo7a0dymRSsv5zuPLZjqLQzKz7Jtv1M969ho7CTSqByy1oB4R1juReS+yUe2MNhKdp82eCTtJAKgEpkKwybw1MvY9ZoFfSFCMo1TZu+JsKB7o9pxNuoOzNbrXQKdDFVj4hBAcf+yefS8yIZwbK+OC6qE3yhh9Pujhm2EFCK9fTQXHuYumwiY6b/leT9bMIrRPO9F7rGChDsh4CQv5FRdfq/D+GofLD+nBZinZkwaLOLS2F+XtPN5hHqSQ19s2nk/TAPAHKLBXovrDgK/GbGHvDnMDj3VwL49z9l2wDjPIJWvV7Xciw+Mg/BBq1OaSUwD6nLwG2Hbr6CrI7APoCs+l5it3wJzbMB1BCm/2Or0wM9KsIE5gF3WKzr+neUcVXhQHIcr868upvjPhCpV9U+XfZOvG2jJEblyxvem0PANmj5hO8lDMgSMfpZJp7696kYk+cJLWSw1MBmWE8hU/P3UgsBpTa2iEMkyKfxmEHJXkOHlZbqKzG3ugNvdIGyFLmOT75NMxqb4QdFnU5AmzkMc3UCtpRe/Sg14ZFre607R2K9Yni4ZRuUE1ocPqpqLwylnLIEYOZ2OEf5fAbZxcyxkQmffGOb2CrcgFMPrnG1HUJ3kfhmQeheeDGuM163Nf8KkLHsBkUTvkW2NeR3nnR9TOPQBmPatwMEmdWprwHaC+t/bPSlLCVSc0A0mOUfDgGnHKOnMYjR3kDkdVdN9GimKemsqoe8cJ7kS8yVoD120IG28kyQsENAltAi2Hv6WSoFFgt/MtRHU1xbQ2jFoPfV8hT66kFyOlVGXXvmbFskf400OMd95UVnQiSsZg+JgC+asDqHL5Y6gAk9pldcKqYrjqxZF33STJ4M1pXAi/k+pkuKGA1SUkgkEe3h92ilpZSBjbhIKj3f23+P3i+OU7keVSSEzEcEkt+JbSjBwA+IabbPfd8CQpqc3V5IyWES1Ih1jKNjQyrsYXf15vIHuXBCxQ2AxJtvtbIfcHi7V06ux/oTQQiApT2PGhS6tT3354fUmDwqqpoNKYqF2Zq5BlU1uQ1cv2PSIvUjN9FAp05+MVf7dxlMwfq8e3W5wZYjtt7Mk26IDxWo7kfOXZLktj+vdDrzzg1YW8FFdhTYsHWcBBLcRUCg X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d396fab-a103-4230-189d-08dd086290f0 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8676.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2024 06:22:39.0032 (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: KPfqtvXadNB1gmh5oNPKSPxHahiVkWWjvQdJthMskTsa+bdjhQcEHVm9nZxr3+dvkkwCHlONJ5+/hO27TqxoJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB10746 Before sending PME_TURN_OFF, don't test the LTSSM state. Since it's safe to send PME_TURN_OFF message regardless of whether the link is up or down. So, there would be no need to test the LTSSM state before sending PME_TURN_OFF message. Only print the message when ltssm_stat is not in DETECT and POLL. In the other words, there isn't an error message when no endpoint is connected at all. Signed-off-by: Richard Zhu --- v4 changes: - Keep error return when L2 entry is failed and the endpoint is connected refer to Krishna' comments. Thanks. v3 changes: - Refine the commit message refer to Manivannan's comments. - Regarding Frank's comments, avoid 10ms wait when no link up. v2 changes: - Don't remove L2 poll check. - Add one 1us delay after L2 entry. - No error return when L2 entry is timeout - Don't print message when no link up. --- .../pci/controller/dwc/pcie-designware-host.c | 38 +++++++++++-------- drivers/pci/controller/dwc/pcie-designware.h | 1 + 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 24e89b66b772..d36e01539ce7 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -927,25 +927,31 @@ int dw_pcie_suspend_noirq(struct dw_pcie *pci) if (dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKCTL) & PCI_EXP_LNKCTL_ASPM_L1) return 0; - /* Only send out PME_TURN_OFF when PCIE link is up */ - if (dw_pcie_get_ltssm(pci) > DW_PCIE_LTSSM_DETECT_ACT) { - if (pci->pp.ops->pme_turn_off) - pci->pp.ops->pme_turn_off(&pci->pp); - else - ret = dw_pcie_pme_turn_off(pci); - - if (ret) - return ret; + if (pci->pp.ops->pme_turn_off) + pci->pp.ops->pme_turn_off(&pci->pp); + else + ret = dw_pcie_pme_turn_off(pci); + if (ret) + return ret; - ret = read_poll_timeout(dw_pcie_get_ltssm, val, val == DW_PCIE_LTSSM_L2_IDLE, - PCIE_PME_TO_L2_TIMEOUT_US/10, - PCIE_PME_TO_L2_TIMEOUT_US, false, pci); - if (ret) { - dev_err(pci->dev, "Timeout waiting for L2 entry! LTSSM: 0x%x\n", val); - return ret; - } + ret = read_poll_timeout(dw_pcie_get_ltssm, val, + val == DW_PCIE_LTSSM_L2_IDLE || + val <= DW_PCIE_LTSSM_DETECT_WAIT, + PCIE_PME_TO_L2_TIMEOUT_US/10, + PCIE_PME_TO_L2_TIMEOUT_US, false, pci); + if (ret && (val > DW_PCIE_LTSSM_DETECT_WAIT)) { + /* Only dump message when ltssm_stat isn't in DETECT and POLL */ + dev_err(pci->dev, "Timeout waiting for L2 entry! LTSSM: 0x%x\n", val); + return ret; } + /* + * Refer to r6.0, sec 5.3.3.2.1, software should wait at least + * 100ns after L2/L3 Ready before turning off refclock and + * main power. It's harmless too when no endpoint connected. + */ + udelay(1); + dw_pcie_stop_link(pci); if (pci->pp.ops->deinit) pci->pp.ops->deinit(&pci->pp); diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index 347ab74ac35a..bf036e66717e 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -330,6 +330,7 @@ enum dw_pcie_ltssm { /* Need to align with PCIE_PORT_DEBUG0 bits 0:5 */ DW_PCIE_LTSSM_DETECT_QUIET = 0x0, DW_PCIE_LTSSM_DETECT_ACT = 0x1, + DW_PCIE_LTSSM_DETECT_WAIT = 0x6, DW_PCIE_LTSSM_L0 = 0x11, DW_PCIE_LTSSM_L2_IDLE = 0x15,