From patchwork Mon Sep 18 13:10:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 141678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3108543vqi; Mon, 18 Sep 2023 20:36:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYEquoWtqPP0QQKDsZJ+RwACCDw+aMRfuwGaqpGqaFtvTh3WcO/Q8G16Jsbms1hMjEx1fd X-Received: by 2002:a9d:768f:0:b0:6bb:1071:ea72 with SMTP id j15-20020a9d768f000000b006bb1071ea72mr10542318otl.36.1695094570771; Mon, 18 Sep 2023 20:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695094570; cv=none; d=google.com; s=arc-20160816; b=e/NdVQdnfZd2eVbGo4tPazrxgYOZW5a9VzZy2ADdCATPUfCLOGDq3JPoqa703qD+3X w8WskKokF5HqZguFeyowME/jJOLMVlLSU4CMsOG5s/6IWU/XUCzG6b2RnnBA400GtGk8 Mo/xCLquhq0OnruVYGiRc4FR07yQzHuy5D5M7uObkd0LSLZMOw+uNVujKBr013oD7WxD fOXVCmRDuWySjDXiZGlykdwUONFRKBJGH7bMGxOE5NLaoudZuNRqNp3m9zdO4OgHRH9Q foGVJ2GA+bzEPNm5D9p+UsKpwugW9SvpSXrmy0IaQmW0b7OmXA43u0QkcoCsIJvTKBMW oq5g== ARC-Message-Signature: i=1; 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=+lpdCK5+VQs9sNEvDPk/c3GmQ6kipvNq7frsPNfmFLM=; fh=+5iD0Q8HSG3sWhOMH+VlKQPx3hsE19cSXpLHbIzVt94=; b=ZRAWQys+3Y1xwPwDhplH6hmaq3h1jH//XkeUEcMXgzaM1urpiiV52vmEx6r2Y6BY0E Aij09jXWOROUBR0h/qgWm9hHFghysBJ4QsHLvrnINODXjh1x0+duc0EO3t0PtCfExuCY ABf/sH20/2mkljVueZQyKS8nMRriZJRPfFrXjXdc+uXmoql3jIU0urDlJXccvUFIjoQ4 7EJOTXT0JI/ElERsrqKXdgFd9YrZdC3MgveoC9aI6N98w3g2NOCgLToW3SEsl6Ige+73 JWvepFrbc534efdPzAdvF0+GFym3wzNoXkNfXQfrKXvQTPkcgyNCkAEwqkdQ6bgxZopy OU7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fQjsiB6v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id e1-20020a636901000000b0056956177395si8800715pgc.512.2023.09.18.20.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 20:36:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fQjsiB6v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id CAD98815CDA8; Mon, 18 Sep 2023 08:47:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbjIRPqc (ORCPT + 25 others); Mon, 18 Sep 2023 11:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbjIRPq1 (ORCPT ); Mon, 18 Sep 2023 11:46:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A0C0CF8; Mon, 18 Sep 2023 08:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695051920; x=1726587920; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uEKrgp0fS4TcV/kqj/T1ibXnz9U6nSS/hcSxBB6l/C0=; b=fQjsiB6vONTRlk5HZosldvkskKXZ2MTyw1KqGM3O3eFuh+jVIf6/8ul4 Rzi241HaWnxbMJgnRQya5Vf5HZBP40Y5/Jj4XJPboRdRKlTbqJ0qr0KOd nCbLZK7sWH5N93txZXAqS2jwkyz0Y8GoxizUBigNMg5QCESzbT+8Rj8Qv 4YBOb63OSFvCwj72KYi0Jj4Vw0D+W+P2od8ZDz/C7ghlZjHdP8TrGwjnD vm6PTGbzxAKuGfkYpabIXNG137gcRf/MI5I7SpYfdHbXbsnn5eCB+evOX q6Dk4OQs5qbi37fN5XaOTMg5h66s6jQeP0qCtpkaAkAWdIuseFiDPqdxX A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="446113406" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="446113406" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 06:12:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="811342150" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="811342150" Received: from nprotaso-mobl1.ccr.corp.intel.com (HELO ijarvine-mobl2.ger.corp.intel.com) ([10.252.49.156]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 06:12:30 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Lukas Wunner , "Rafael J . Wysocki" , Heiner Kallweit , Emmanuel Grumbach , linux-kernel@vger.kernel.org, Bjorn Helgaas Cc: ath10k@lists.infradead.org, ath11k@lists.infradead.org, ath12k@lists.infradead.org, intel-wired-lan@lists.osuosl.org, linux-arm-kernel@lists.infradead.org, linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rdma@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, =?utf-8?q?Ilpo_J?= =?utf-8?q?=C3=A4rvinen?= Subject: [PATCH v2 05/13] PCI/ASPM: Add pci_enable_link_state() Date: Mon, 18 Sep 2023 16:10:55 +0300 Message-Id: <20230918131103.24119-6-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230918131103.24119-1-ilpo.jarvinen@linux.intel.com> References: <20230918131103.24119-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 18 Sep 2023 08:47:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777435484527642098 X-GMAIL-MSGID: 1777435484527642098 pci_disable_link_state() lacks a symmetric pair. Some drivers want to disable ASPM during certain phases of their operation but then re-enable it later on. If pci_disable_link_state() is made for the device, there is currently no way to re-enable the states that were disabled. Add pci_enable_link_state() to remove ASPM states from the state disable mask. Signed-off-by: Ilpo Järvinen --- drivers/pci/pcie/aspm.c | 42 +++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 44 insertions(+) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 91dc95aca90f..f45d18d47c20 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1117,6 +1117,48 @@ int pci_disable_link_state(struct pci_dev *pdev, int state) } EXPORT_SYMBOL(pci_disable_link_state); +/** + * pci_enable_link_state - Re-enable device's link state + * @pdev: PCI device + * @state: ASPM link states to re-enable + * + * Enable device's link state that were previously disable so the link is + * allowed to enter the specific states. Note that if the BIOS didn't grant + * ASPM control to the OS, this does nothing because we can't touch the + * LNKCTL register. + * + * Return: 0 or a negative errno. + */ +int pci_enable_link_state(struct pci_dev *pdev, int state) +{ + struct pcie_link_state *link = pcie_aspm_get_link(pdev); + + if (!link) + return -EINVAL; + /* + * A driver requested that ASPM be enabled on this device, but + * if we don't have permission to manage ASPM (e.g., on ACPI + * systems we have to observe the FADT ACPI_FADT_NO_ASPM bit and + * the _OSC method), we can't honor that request. + */ + if (aspm_disabled) { + pci_warn(pdev, "can't enable ASPM; OS doesn't have ASPM control\n"); + return -EPERM; + } + + mutex_lock(&aspm_lock); + link->aspm_disable &= ~pci_link_state_mask(state); + pcie_config_aspm_link(link, policy_to_aspm_state(link)); + + if (state & PCIE_LINK_STATE_CLKPM) + link->clkpm_disable = 0; + pcie_set_clkpm(link, policy_to_clkpm_state(link)); + mutex_unlock(&aspm_lock); + + return 0; +} +EXPORT_SYMBOL(pci_enable_link_state); + /** * pci_set_default_link_state - Set the default device link state * @pdev: PCI device diff --git a/include/linux/pci.h b/include/linux/pci.h index 3c24ca164104..844d09230264 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1776,11 +1776,13 @@ extern bool pcie_ports_native; int pci_disable_link_state(struct pci_dev *pdev, int state); int pci_disable_link_state_locked(struct pci_dev *pdev, int state); #ifdef CONFIG_PCIEASPM +int pci_enable_link_state(struct pci_dev *pdev, int state); int pci_set_default_link_state(struct pci_dev *pdev, int state); void pcie_no_aspm(void); bool pcie_aspm_support_enabled(void); bool pcie_aspm_enabled(struct pci_dev *pdev); #else +static inline int pci_enable_link_state(struct pci_dev *pdev, int state) { return -EOPNOTSUPP; } static inline int pci_set_default_link_state(struct pci_dev *pdev, int state) { return 0; } static inline void pcie_no_aspm(void) { }