All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: "Saheed O. Bolarinwa" <refactormyself@gmail.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v1 2/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable
Date: Thu, 30 Sep 2021 11:05:16 -0500	[thread overview]
Message-ID: <20210930160516.GA887797@bhelgaas> (raw)
In-Reply-To: <20210929004400.25717-3-refactormyself@gmail.com>

On Wed, Sep 29, 2021 at 02:43:58AM +0200, Saheed O. Bolarinwa wrote:
> From: "Bolarinwa O. Saheed" <refactormyself@gmail.com>
> 
> The clkpm_capable member of the struct pcie_link_state indicates
> if the device is Clock PM capable. This can be calculated when
> it is needed.

... because it comes from Link Capabilities, a read-only register.

> This patch:
>   - removes clkpm_capable from struct pcie_link_state
>   - moves the calculation of clkpm_capable into
>     pcie_is_clkpm_capable()
>   - replaces references to clkpm_capable with a call to
>     pcie_is_clkpm_capable()

No need to say "this patch"; commit logs *always* refer to "this
patch".  Reword in imperative sentence structure, as if giving
commands, e.g.,

  Remove pcie_link_state.clkpm_capable and replace it with
  pcie_is_clkpm_capable(), which computes the value from Link
  Capabilities as needed.

> Signed-off-by: Bolarinwa O. Saheed <refactormyself@gmail.com>
> ---
>  drivers/pci/pcie/aspm.c | 39 ++++++++++++++++++++++-----------------
>  1 file changed, 22 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
> index c23da9a4e2fb..9e65da9a22dd 100644
> --- a/drivers/pci/pcie/aspm.c
> +++ b/drivers/pci/pcie/aspm.c
> @@ -61,7 +61,6 @@ struct pcie_link_state {
>  	u32 aspm_disable:7;		/* Disabled ASPM state */
>  
>  	/* Clock PM state */
> -	u32 clkpm_capable:1;		/* Clock PM capable? */
>  	u32 clkpm_enabled:1;		/* Current Clock PM state */
>  	u32 clkpm_disable:1;		/* Clock PM disabled */
>  
> @@ -146,6 +145,25 @@ static int pcie_get_clkpm_state(struct pci_dev *pdev)
>  	return enabled;
>  }
>  
> +static int pcie_is_clkpm_capable(struct pci_dev *pdev)
> +{
> +	int capable = 1;
> +	u32 reg32;
> +	struct pci_dev *child;
> +	struct pci_bus *linkbus = pdev->subordinate;
> +
> +	/* All functions should have the same cap state, take the worst */
> +	list_for_each_entry(child, &linkbus->devices, bus_list) {
> +		pcie_capability_read_dword(child, PCI_EXP_LNKCAP, &reg32);
> +		if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) {
> +			capable = 0;
> +			break;
> +		}
> +	}
> +
> +	return capable;

  static bool pcie_is_clkpm_capable()
  {
    list_for_each_entry(child, &linkbus->devices, bus_list) {
      pcie_capability_read_dword(child, PCI_EXP_LNKCAP, &cap);
      if (!(cap & PCI_EXP_LNKCAP_CLKPM))
	return false;
    }
    return true;
  }

> +}
> +
>  static int policy_to_clkpm_state(struct pcie_link_state *link)
>  {
>  	switch (aspm_policy) {
> @@ -177,11 +195,12 @@ static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable)
>  
>  static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
>  {
> +	int capable = pcie_is_clkpm_capable(link->pdev);
>  	/*
>  	 * Don't enable Clock PM if the link is not Clock PM capable
>  	 * or Clock PM is disabled
>  	 */
> -	if (!link->clkpm_capable || link->clkpm_disable)
> +	if (!capable || link->clkpm_disable)

I think I'd just call pcie_is_clkpm_capable() directly in the "if"
condition to avoid the local variable, as you did below in
aspm_ctrl_attrs_are_visible().

>  		enable = 0;
>  	/* Need nothing if the specified equals to current state */
>  	if (link->clkpm_enabled == enable)
> @@ -191,21 +210,7 @@ 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;
> -	u32 reg32;
> -	struct pci_dev *child;
> -	struct pci_bus *linkbus = link->pdev->subordinate;
> -
> -	/* All functions should have the same cap and state, take the worst */
> -	list_for_each_entry(child, &linkbus->devices, bus_list) {
> -		pcie_capability_read_dword(child, PCI_EXP_LNKCAP, &reg32);
> -		if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) {
> -			capable = 0;
> -			break;
> -		}
> -	}
>  	link->clkpm_enabled = pcie_get_clkpm_state(link->pdev);
> -	link->clkpm_capable = capable;

This makes good sense to me because PCI_EXP_LNKCAP_CLKPM is read-only
and there's no need to cache the boot-time value because we can always
recompute clkpm_capable if we need it.

>  	link->clkpm_disable = blacklist ? 1 : 0;
>  }
>  
> @@ -1346,7 +1351,7 @@ static umode_t aspm_ctrl_attrs_are_visible(struct kobject *kobj,
>  		return 0;
>  
>  	if (n == 0)
> -		return link->clkpm_capable ? a->mode : 0;
> +		return pcie_is_clkpm_capable(link->pdev) ? a->mode : 0;
>  
>  	return link->aspm_capable & aspm_state_map[n - 1] ? a->mode : 0;
>  }
> -- 
> 2.20.1
> 

  reply	other threads:[~2021-09-30 16:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  0:43 [RFC PATCH v1 0/4] Remove struct pcie_link_state.clkpm_* Saheed O. Bolarinwa
2021-09-29  0:43 ` [RFC PATCH v1 1/4] [PCI/ASPM:] Remove struct pcie_link_state.clkpm_default Saheed O. Bolarinwa
2021-09-30 15:54   ` Bjorn Helgaas
2021-10-11  6:05     ` Saheed Bolarinwa
2021-09-29  0:43 ` [RFC PATCH v1 2/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable Saheed O. Bolarinwa
2021-09-30 16:05   ` Bjorn Helgaas [this message]
2021-09-29  0:43 ` [RFC PATCH v1 3/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled Saheed O. Bolarinwa
2021-09-30 16:28   ` Bjorn Helgaas
2021-09-29  0:44 ` [RFC PATCH v1 4/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_disable Saheed O. Bolarinwa
2021-09-30 20:20   ` Bjorn Helgaas
2021-10-11  6:06     ` Saheed Bolarinwa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210930160516.GA887797@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=refactormyself@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.