Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp427161pxb; Thu, 30 Sep 2021 08:58:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdeyxv2Oxm/681RVB9zUkjPHpb6rPCvrfzk44iDykf3D9ZwaVBmrqCLOe8S7LGg4VyTwXc X-Received: by 2002:a17:907:9703:: with SMTP id jg3mr7703590ejc.449.1633017514946; Thu, 30 Sep 2021 08:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633017514; cv=none; d=google.com; s=arc-20160816; b=Raaz1p7P2U8X7fuPO4hIAm7PhjA84eBwM5cV5ndzKxQe/XX1ixkor1bVL39WYk60/y nu2uPPQryL1F7fHxCcBfHYiVzUylziqQKcWF63EcNY6mzUzVAbV00BnavAqrSZZRfmlb 1FEaPld/i3Q/Kq76k3zO0d2pHcA1G5dsLcG5tQHzvyqh3Cg9E79HGh4xYnV5rJrIdb4j l28xGt0uwhmF3eUPvMrxl3xW0bxj9Balu0BLHsBvTiHMupXJVL9o4mJ5+j+v8NKNXCQz isyAB5DtkviIAzZwPQ5eXDDJBe4xFw/xwqu7ywHBTP9tgta7XRXGIf4+BhPaBMUuqJqk KOPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=a6u+fLEItPhZ6+AfH4KlNozn4nI8ff5CSkb4sTv+itA=; b=QL/VlNxu3f7EeBNileBGW72gKTogrl7xAAoYnKCeY0d1ZDH43iC4p54hVmndI4jEAZ zWpwS81zzli2gPdeeAfjkz16/yrmZazqqobOheRwiOpi64+uo54eawfk3bnhQmKBBY4b wn4eqIzAfUT8r8iVUCfCPCR+LcIW+IpRrqhLS7AVK1gbwwvo6o3P0EPFXcbz5J9lGMGv kzc14w/+q+uzbFOdLL/SCvLpw2s6pPP+wyMHdqoVPlzcLcM5mx1Qs4BD5lW73e1FwA8E O+cQFwLuxTUtlCQJhiM80U4wy9lyj9DLRleukxc+ZE/4DyTWkjbcvOoI2Q5Vu5A4EdFW ptsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LQ/9JqDQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si3868183ejc.450.2021.09.30.08.58.10; Thu, 30 Sep 2021 08:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LQ/9JqDQ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346727AbhI3Pzq (ORCPT + 99 others); Thu, 30 Sep 2021 11:55:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:40970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346582AbhI3Pzp (ORCPT ); Thu, 30 Sep 2021 11:55:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3F1F661411; Thu, 30 Sep 2021 15:54:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633017242; bh=4FLgrYfiAV1mkDxGMwPnsUgIYDlrsX1nBmoYjQHKOrs=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=LQ/9JqDQ6td04d9li5F/dooPp/dOE3SlVNgF7u9Si5Kjew50vR+hVWBfsIIzJ+014 N8v+vCGq5AXzoCrCt+vTQHnjT6aXmqePpBODEjc3u2H1yZyKPneMl6p+EB3ZEKnRWC t7KR/gFlY+F11CcGQOEVWeiDpHjkDxX27wH4n4ITAcmyYSd/M0WjR38k7hAfepJB76 iu3JWBvAMASHhgc8rAkbZ2Y9JGoNfsoaS9ng6IJsQGmJMTFzKDeQO5O5nHTC1SRTE+ FeVov8TjM9GUqeg+iWrn8GbDlAo46roW84eAQr+B+Zms1vXcwM1DlF1mHu7jNb+lnM wHHzoZnoflP5Q== Date: Thu, 30 Sep 2021 10:54:00 -0500 From: Bjorn Helgaas To: "Saheed O. Bolarinwa" Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v1 1/4] [PCI/ASPM:] Remove struct pcie_link_state.clkpm_default Message-ID: <20210930155400.GA886716@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210929004400.25717-2-refactormyself@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 29, 2021 at 02:43:57AM +0200, Saheed O. Bolarinwa wrote: > From: "Bolarinwa O. Saheed" > > The clkpm_default member of the struct pcie_link_state stores the > value of the default clkpm state as it is in the BIOS. > > This patch: > - Removes clkpm_default from struct pcie_link_state > - Creates pcie_get_clkpm_state() which return the clkpm state > obtained the BIOS > - Replaces references to clkpm_default with call to > pcie_get_clkpm_state() > > Signed-off-by: Bolarinwa O. Saheed > --- > drivers/pci/pcie/aspm.c | 37 +++++++++++++++++++++++++++---------- > 1 file changed, 27 insertions(+), 10 deletions(-) > > diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c > index 013a47f587ce..c23da9a4e2fb 100644 > --- a/drivers/pci/pcie/aspm.c > +++ b/drivers/pci/pcie/aspm.c > @@ -63,7 +63,6 @@ struct pcie_link_state { > /* Clock PM state */ > u32 clkpm_capable:1; /* Clock PM capable? */ > u32 clkpm_enabled:1; /* Current Clock PM state */ > - u32 clkpm_default:1; /* Default Clock PM state by BIOS */ > u32 clkpm_disable:1; /* Clock PM disabled */ > > /* Exit latencies */ > @@ -123,6 +122,30 @@ static int policy_to_aspm_state(struct pcie_link_state *link) > return 0; > } > > +static int pcie_get_clkpm_state(struct pci_dev *pdev) > +{ > + int enabled = 1; > + u32 reg32; > + u16 reg16; > + struct pci_dev *child; > + struct pci_bus *linkbus = pdev->subordinate; > + > + /* All functions should have the same clkpm state, take the worst */ > + list_for_each_entry(child, &linkbus->devices, bus_list) { > + pcie_capability_read_dword(child, PCI_EXP_LNKCAP, ®32); > + if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) { > + enabled = 0; > + break; > + } > + > + pcie_capability_read_word(child, PCI_EXP_LNKCTL, ®16); > + if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN)) > + enabled = 0; > + } > + > + return enabled; > +} > + > static int policy_to_clkpm_state(struct pcie_link_state *link) > { > switch (aspm_policy) { > @@ -134,7 +157,7 @@ static int policy_to_clkpm_state(struct pcie_link_state *link) > /* Enable Clock PM */ > return 1; > case POLICY_DEFAULT: > - return link->clkpm_default; > + return pcie_get_clkpm_state(link->pdev); > } > return 0; > } > @@ -168,9 +191,8 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable) > > static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) > { > - int capable = 1, enabled = 1; > + int capable = 1; > u32 reg32; > - u16 reg16; > struct pci_dev *child; > struct pci_bus *linkbus = link->pdev->subordinate; > > @@ -179,15 +201,10 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) > pcie_capability_read_dword(child, PCI_EXP_LNKCAP, ®32); > if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) { > capable = 0; > - enabled = 0; > break; > } > - pcie_capability_read_word(child, PCI_EXP_LNKCTL, ®16); > - if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN)) > - enabled = 0; > } > - link->clkpm_enabled = enabled; > - link->clkpm_default = enabled; > + link->clkpm_enabled = pcie_get_clkpm_state(link->pdev); I love the idea of removing clkpm_default, but I need a little more convincing. Before this patch, this code computes clkpm_default from PCI_EXP_LNKCAP_CLKPM and PCI_EXP_LNKCTL_CLKREQ_EN of all the functions of the device. PCI_EXP_LNKCAP_CLKPM is a read-only value, so we can re-read that any time. But PCI_EXP_LNKCTL_CLKREQ_EN is writable, so if we want to know the value that firmware put there, we need to read and save it before we modify it. Why is it safe to remove this init-time read of PCI_EXP_LNKCTL_CLKREQ_EN and instead re-read it any time we need the "default" settings from firmware? > link->clkpm_capable = capable; > link->clkpm_disable = blacklist ? 1 : 0; > } > -- > 2.20.1 >