Message ID | 20230809185453.40916-9-mario.limonciello@amd.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:9d8d:b0:139:fa0d:b2d with SMTP id d13csp139075rwo; Wed, 9 Aug 2023 13:57:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjfi2Yp0VvPpgEoSpCcD/Jvo6kXtXhLXrwAUb/vhgTNjNb55b5LTJgjlvlkdBEB7O8nWbg X-Received: by 2002:a17:90a:6c41:b0:263:ea6a:1049 with SMTP id x59-20020a17090a6c4100b00263ea6a1049mr412158pjj.2.1691614623226; Wed, 09 Aug 2023 13:57:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691614623; cv=pass; d=google.com; s=arc-20160816; b=eXSP870Yv7RSz/hz8t/3KqwHKTMERub47KqyYecY9L7KICkbOuXSC9qgQ8QZNRgk2D OUCEKwoKRsaeASHQf7hLLYj7MEXxfae6o/TAT+PY7PJpbk4TnN1lnrLtl3/fMD/4VgVW z2bnCP2av9iI1MpXVmtHzyu58y0Jlm+ti6MxYibbRtg/TpX2KYRtrgUk6TLsDYs+ycW2 5hBAPyUxPCda7OUeQb6UA0JSG0aAvwYW38Z4HNW4sF1vGWYGfOUvNo688g00sh3F04vN g2xg7PvlbmzrGiaaZINaUDhdUV4J5+mb4fUin6b1wifGluuCANF94eUaWpRAc3DGURE4 Hivw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U7IljWi8fyJCaKaHKU70C/9A6XxwrDPhSFrCKPfFtKY=; fh=Nh9k8iTb6A6iuv8X6fsJlNl/OveGK+B6OHYtkAnZZ00=; b=P7qkDsxBqIjNCfitc4cxlur8Z7fmVIC39hiRDRtt1FxUol4I+c2jbgYs02IgRHjhan HrOzpxE3Aa13vYThUIQo42c79po+gsLpYh6q2RAxCViHyzicV4qaHDa6idbm1ERy3PEv Q8mojRq/sR1xgRylJSxDmuiTC6oAMae/eUp1s9plu9Frye9AUKDbNx08QUW4yRa/t6lf igeE7twx8zxqc5Y7ocZ6vvdzNH1+L0xHvwiyuID/CRRtba4BtfWH3Q3DJZ5U77wQaW/q ij7Cohfb+G95FQGMOCv64AKPVfhEUxYKxV6RaQgGjrCgsQ1S7Tbz1MuYWM7sj/ITU9/g Ui9Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=46VVImrO; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pi15-20020a17090b1e4f00b00263e5a7d8d7si2362943pjb.1.2023.08.09.13.56.50; Wed, 09 Aug 2023 13:57:03 -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=@amd.com header.s=selector1 header.b=46VVImrO; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231597AbjHITsY (ORCPT <rfc822;craechal@gmail.com> + 99 others); Wed, 9 Aug 2023 15:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234240AbjHITrg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 9 Aug 2023 15:47:36 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2048.outbound.protection.outlook.com [40.107.223.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C269210D; Wed, 9 Aug 2023 12:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SG/V6ZrxslfLLJYzmfaRnLLMUtl082REVAp/7MZ0xTtGj1O5GhNHvi+B6GnpsWBzRolew01VnTm851QaCsLphLLXa88Q8d+k6cnyeUCIkKriDD9NQkOMedz5oxsHJQefqxIKbEaV1D3rmHOW6mr14TMHWA7wlXZadG8JuSuflB413xe1wfttogROMI08LH0Kp5Tk17xJ3Eqwmn/o1ppw6I5ebhmyHfR6hj7QlsQdoajK+b1wsyUIAQ/wRYtmXnunB1v4HKYXhG3JoV2WzZgwrBHtKUDHKa+YFG2b2SiLvOQVPmZc5LmV1zGnFrMqNXa1+BdDCwlBUvbhWLukkdxlgg== 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=U7IljWi8fyJCaKaHKU70C/9A6XxwrDPhSFrCKPfFtKY=; b=WO67AGQfg1g2mZqBe5VhseRg/RkxRMhbfexNJDxxxmoZRHLt2Rkk7zX82q52C9Lyy0qbj6xET1h7jPuYDg7RFGGlzJDJ/ouvhu09KRkInmTsIw3wiRCNlBDFc89TxweZZxO5WCJwk4deLlmYjQSnv2oWvXmYAaRg6fkXdS2mFVsUhAvN7oXR7Qx6NGeHb4NXtIZRvJghW6X7/s/NWDID/AHN4MvFVFdoFx9NR+hI0MAjWeJocBufe71L+wo/nUn19lEsG/KBLSUQJfB2OtVvRONjNjl6DTiNiogRwIx5EjRmXaCmxCqW3Oqi6njXRccuXcpvwcHAFQScQtqQFoM9Ow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.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=U7IljWi8fyJCaKaHKU70C/9A6XxwrDPhSFrCKPfFtKY=; b=46VVImrOUqrOszIcJMllAyK9grmcjgup1j8pV7pSrWk82E89j5ZJHV+a61ps+nvsWwwoYtZ8cr3MiLLVXgYs2GEJY2t0W7t7zeoE8B0tXoavI4mlp/OOVY85cw0NoOzhLPxOnriO5QucVEXVDaS1r7f5kcybkFFDYbWgXLx/Hgg= Received: from MW2PR16CA0057.namprd16.prod.outlook.com (2603:10b6:907:1::34) by DS0PR12MB8342.namprd12.prod.outlook.com (2603:10b6:8:f9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Wed, 9 Aug 2023 19:47:22 +0000 Received: from CO1PEPF000042A9.namprd03.prod.outlook.com (2603:10b6:907:1:cafe::74) by MW2PR16CA0057.outlook.office365.com (2603:10b6:907:1::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.28 via Frontend Transport; Wed, 9 Aug 2023 19:47:22 +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 CO1PEPF000042A9.mail.protection.outlook.com (10.167.243.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6652.19 via Frontend Transport; Wed, 9 Aug 2023 19:47:21 +0000 Received: from SITE-L-T34-2.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.2507.27; Wed, 9 Aug 2023 14:47:19 -0500 From: Mario Limonciello <mario.limonciello@amd.com> To: "Rafael J . Wysocki" <rafael@kernel.org>, Mika Westerberg <mika.westerberg@linux.intel.com>, Bjorn Helgaas <helgaas@kernel.org> CC: <linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>, "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>, <linux-acpi@vger.kernel.org>, Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>, "Iain Lane" <iain@orangesquash.org.uk>, Shyam-sundar S-k <Shyam-sundar.S-k@amd.com>, Mario Limonciello <mario.limonciello@amd.com> Subject: [PATCH v11 8/9] PCI: Split PME state selection into a local static function Date: Wed, 9 Aug 2023 13:54:52 -0500 Message-ID: <20230809185453.40916-9-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230809185453.40916-1-mario.limonciello@amd.com> References: <20230809185453.40916-1-mario.limonciello@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A9:EE_|DS0PR12MB8342:EE_ X-MS-Office365-Filtering-Correlation-Id: da5aeb87-5ed5-4666-71f3-08db991172b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YVkYUY8kmZ/BydUO2qrjjIWDdSxd+kaiCeriLKumzdgWf7wW3mtUkIwyY5L/ipSqzKXzkgv38c6ghclQ8k3XIP79vTIM45LOS1l0Z1Qtr+bA2Vas9txE6pwooMeoG1UDfsplsPWNUa0ZH92gqodXQDHvC+aQplIa3h8G0FE7mqoWAlNEI+O7PaAW1njO13kotlN5VH2rODNZFsR6VPkDXYNIM1AaHO4dljcIfRb5axl0S/zE5195RuVUBZ81TIVNJmTVchUCY9qpQ+k9ZQvnj2tNue62Z8H7pkeJaf4RapLlrHKlDi81Vu+UPZ8zak40x60u1vbBg/ziLZSsxnBpQuEu6aoAKffItN5Fo3+UL33JyoWE52zoT49FayplzuImFx66xW9tSHXJuh6NdJbz+AY/BQ0+tHvGfG4OWfIq4mW3kjcUnVbxqsw1K9gAzV8hiPOnPDaJkDV4LNP5wzD09ydbpJ8kR0fmygf+mbzAl3C7IwdjMedm+cByScMks/omqOhtat5XqjzpfRN0eeqnpcEthT1Nb2wS4eCJqvP9jIt+QWfh467C/Wyl2RcZwmF+NNXi9S/ubfLbtZMdg0JyBTVzsYlFw6VOk+TVl+TQy75aU3PfiORwXjBWLmDtUWsOenKlg4t5+Z1ryElmVAO6xFd3BSJCH0YeyZAV4Qy+79O4/DODSl2KJUCLs1ddbyO1/p++y+0BbSuc9+Dg+1vgGRfpPKj8pOt6/Y3thQNfF3pJsHr9nLsyBimdvbFVkqUKbrlF2ax9Xu3dbZZ35alcCw== 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:(13230028)(4636009)(346002)(136003)(376002)(396003)(39860400002)(451199021)(82310400008)(1800799006)(186006)(46966006)(40470700004)(36840700001)(6666004)(7696005)(40460700003)(86362001)(1076003)(26005)(40480700001)(47076005)(426003)(83380400001)(2616005)(36756003)(36860700001)(16526019)(336012)(81166007)(356005)(82740400003)(44832011)(316002)(41300700001)(8676002)(8936002)(2906002)(4326008)(70586007)(70206006)(478600001)(54906003)(5660300002)(110136005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2023 19:47:21.9310 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da5aeb87-5ed5-4666-71f3-08db991172b0 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: CO1PEPF000042A9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8342 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, URIBL_BLOCKED autolearn=no 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773786494687839802 X-GMAIL-MSGID: 1773786494687839802 |
Series |
Fix wakeup problems on some AMD platforms
|
|
Commit Message
Mario Limonciello
Aug. 9, 2023, 6:54 p.m. UTC
When a device is not power manageable by the platform, and not already
in a low power state pci_target_state() will find the deepest state
that PME is supported and use this to select the wakeup state.
Simplify this logic and split it out to a local function. No intended
functional changes.
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v10->v11:
* New patch split from existing patch in v10
---
drivers/pci/pci.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
Comments
On Wed, Aug 09, 2023 at 01:54:52PM -0500, Mario Limonciello wrote: > When a device is not power manageable by the platform, and not already > in a low power state pci_target_state() will find the deepest state > that PME is supported and use this to select the wakeup state. > > Simplify this logic and split it out to a local function. No intended > functional changes. ... > +static inline pci_power_t pci_get_wake_pme_state(struct pci_dev *dev) > +{ > + pci_power_t state = PCI_D3hot; > + > + while (state && !(dev->pme_support & (1 << state))) > + state--; > + > + return state; Sparse won't be happy about this code (with CF=-D__CHECK_ENDIAN__). Basically it's something like return (__force pci_power_t)fls(dev->pme_support & GENMASK(PCI_D3hot, 0)); (but double check and test the logic). > +} ... Yeah, I see that is the existing code, perhaps amend it first?
On 8/10/2023 11:21 AM, Andy Shevchenko wrote: > On Wed, Aug 09, 2023 at 01:54:52PM -0500, Mario Limonciello wrote: >> When a device is not power manageable by the platform, and not already >> in a low power state pci_target_state() will find the deepest state >> that PME is supported and use this to select the wakeup state. >> >> Simplify this logic and split it out to a local function. No intended >> functional changes. > > ... > >> +static inline pci_power_t pci_get_wake_pme_state(struct pci_dev *dev) >> +{ >> + pci_power_t state = PCI_D3hot; >> + >> + while (state && !(dev->pme_support & (1 << state))) >> + state--; >> + >> + return state; > > Sparse won't be happy about this code (with CF=-D__CHECK_ENDIAN__). > > Basically it's something like > > return (__force pci_power_t)fls(dev->pme_support & GENMASK(PCI_D3hot, 0)); > > (but double check and test the logic). > >> +} > > ... > > Yeah, I see that is the existing code, perhaps amend it first? > Are you sure? I actually double checked the sparse output using this command before I sent it. make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' drivers/pci/pci.o I didn't see anything related to the line numbers for this function.
On Thu, Aug 10, 2023 at 11:29:49AM -0500, Limonciello, Mario wrote: > On 8/10/2023 11:21 AM, Andy Shevchenko wrote: > > On Wed, Aug 09, 2023 at 01:54:52PM -0500, Mario Limonciello wrote: ... > > > +static inline pci_power_t pci_get_wake_pme_state(struct pci_dev *dev) > > > +{ > > > + pci_power_t state = PCI_D3hot; > > > + > > > + while (state && !(dev->pme_support & (1 << state))) > > > + state--; > > > + > > > + return state; > > > > Sparse won't be happy about this code (with CF=-D__CHECK_ENDIAN__). > > > > Basically it's something like > > > > return (__force pci_power_t)fls(dev->pme_support & GENMASK(PCI_D3hot, 0)); > > > > (but double check and test the logic). > > > > > +} > > > > ... > > > > Yeah, I see that is the existing code, perhaps amend it first? > > > > Are you sure? Yes. Just the original code drivers/pci/pci.c:2711:60: warning: restricted pci_power_t degrades to integer drivers/pci/pci.c:2712:30: warning: restricted pci_power_t degrades to integer /* * Find the deepest state from which the device can generate * PME#. */ 2711 ==> while (state && !(dev->pme_support & (1 << state))) 2712 ==> state--; How is yours different? > I actually double checked the sparse output using this > command before I sent it. > > make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' drivers/pci/pci.o > > I didn't see anything related to the line numbers for this function. Just in case... $ gcc --version gcc (Debian 12.3.0-5) 12.3.0 $ sparse --version 0.6.4 (Debian: 0.6.4-3) $ make --version GNU Make 4.3 Built for x86_64-pc-linux-gnu
On 8/11/2023 3:55 AM, Andy Shevchenko wrote: > On Thu, Aug 10, 2023 at 11:29:49AM -0500, Limonciello, Mario wrote: >> On 8/10/2023 11:21 AM, Andy Shevchenko wrote: >>> On Wed, Aug 09, 2023 at 01:54:52PM -0500, Mario Limonciello wrote: > > ... > >>>> +static inline pci_power_t pci_get_wake_pme_state(struct pci_dev *dev) >>>> +{ >>>> + pci_power_t state = PCI_D3hot; >>>> + >>>> + while (state && !(dev->pme_support & (1 << state))) >>>> + state--; >>>> + >>>> + return state; >>> >>> Sparse won't be happy about this code (with CF=-D__CHECK_ENDIAN__). >>> >>> Basically it's something like >>> >>> return (__force pci_power_t)fls(dev->pme_support & GENMASK(PCI_D3hot, 0)); >>> >>> (but double check and test the logic). >>> >>>> +} >>> >>> ... >>> >>> Yeah, I see that is the existing code, perhaps amend it first? >>> >> >> Are you sure? > > Yes. > > Just the original code > > drivers/pci/pci.c:2711:60: warning: restricted pci_power_t degrades to integer > drivers/pci/pci.c:2712:30: warning: restricted pci_power_t degrades to integer > > /* > * Find the deepest state from which the device can generate > * PME#. > */ > 2711 ==> while (state && !(dev->pme_support & (1 << state))) > 2712 ==> state--; > > How is yours different? > >> I actually double checked the sparse output using this >> command before I sent it. >> >> make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' drivers/pci/pci.o >> >> I didn't see anything related to the line numbers for this function. > > Just in case... > > $ gcc --version > gcc (Debian 12.3.0-5) 12.3.0 > > $ sparse --version > 0.6.4 (Debian: 0.6.4-3) > > $ make --version > GNU Make 4.3 > Built for x86_64-pc-linux-gnu > Oh, I see why I wasn't observing it now. Because it's inline code it's processed separately and isn't with the rest of the grouped output from 2416 through 2922. drivers/pci/pci.c:2679:52: sparse: warning: restricted pci_power_t degrades to integer drivers/pci/pci.c:2680:22: sparse: warning: restricted pci_power_t degrades to integer
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 60230da957e0c..693f4ca90452b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2660,6 +2660,20 @@ int pci_wake_from_d3(struct pci_dev *dev, bool enable) } EXPORT_SYMBOL(pci_wake_from_d3); +/* + * Find the deepest state from which the device can generate + * PME#. + */ +static inline pci_power_t pci_get_wake_pme_state(struct pci_dev *dev) +{ + pci_power_t state = PCI_D3hot; + + while (state && !(dev->pme_support & (1 << state))) + state--; + + return state; +} + /** * pci_target_state - find an appropriate low power state for a given PCI dev * @dev: PCI device @@ -2701,21 +2715,8 @@ static pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup) else if (!dev->pm_cap) return PCI_D0; - if (wakeup && dev->pme_support) { - pci_power_t state = PCI_D3hot; - - /* - * Find the deepest state from which the device can generate - * PME#. - */ - while (state && !(dev->pme_support & (1 << state))) - state--; - - if (state) - return state; - else if (dev->pme_support & 1) - return PCI_D0; - } + if (wakeup && dev->pme_support) + return pci_get_wake_pme_state(dev); return PCI_D3hot; }