diff mbox

[v1] PCI: enable ASPM configuration in PCIE POWERSAVE mode

Message ID 1404198978-26593-1-git-send-email-vidyas@nvidia.com
State Changes Requested
Headers show

Commit Message

Vidya Sagar July 1, 2014, 7:16 a.m. UTC
commit 1a680b7c moved pcie_aspm_powersave_config_link() out of
pci_raw_set_power_state() to pci_set_power_state() which would enable
ASPM. But, with commit db288c9c, which re-introduced the following check
./drivers/pci/pci.c: pci_set_power_state()
+   /* Check if we're already there */
+   if (dev->current_state == state)
+       return 0;
in pci_set_power_state(), call to pcie_aspm_powersave_config_link() is never
made leaving ASPM broken.
Fix it by not returning from when the above condition is true, rather, jump to
ASPM configuration code and exit from there eventually.

Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
---
 drivers/pci/pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Stephen Warren July 1, 2014, 3:04 p.m. UTC | #1
On 07/01/2014 01:16 AM, Vidya Sagar wrote:
> commit 1a680b7c moved pcie_aspm_powersave_config_link() out of
> pci_raw_set_power_state() to pci_set_power_state() which would enable
> ASPM. But, with commit db288c9c, which re-introduced the following check
> ./drivers/pci/pci.c: pci_set_power_state()
> +   /* Check if we're already there */
> +   if (dev->current_state == state)
> +       return 0;
> in pci_set_power_state(), call to pcie_aspm_powersave_config_link() is never
> made leaving ASPM broken.
> Fix it by not returning from when the above condition is true, rather, jump to
> ASPM configuration code and exit from there eventually.

Out of curiosity, was this patch tested by running an umodified mainline
kernel on a Tegra device, or is this simply a port from our downstream
kernel, without any additional upstream testing?
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vidya Sagar July 2, 2014, 4:23 a.m. UTC | #2
> -----Original Message-----
> From: Stephen Warren [mailto:swarren@wwwdotorg.org]
> Sent: Tuesday, July 01, 2014 8:35 PM
> To: Vidya Sagar; bhelgaas@google.com; rjw@sisk.pl;
> nagananda.chumbalkar@hp.com; thierry.reding@gmail.com; Stephen
> Warren; Krishna Thota; linux-pci@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v1] PCI: enable ASPM configuration in PCIE POWERSAVE
> mode
> 
> On 07/01/2014 01:16 AM, Vidya Sagar wrote:
> > commit 1a680b7c moved pcie_aspm_powersave_config_link() out of
> > pci_raw_set_power_state() to pci_set_power_state() which would enable
> > ASPM. But, with commit db288c9c, which re-introduced the following
> > check
> > ./drivers/pci/pci.c: pci_set_power_state()
> > +   /* Check if we're already there */
> > +   if (dev->current_state == state)
> > +       return 0;
> > in pci_set_power_state(), call to pcie_aspm_powersave_config_link() is
> > never made leaving ASPM broken.
> > Fix it by not returning from when the above condition is true, rather,
> > jump to ASPM configuration code and exit from there eventually.
> 
> Out of curiosity, was this patch tested by running an umodified mainline
> kernel on a Tegra device, or is this simply a port from our downstream kernel,
> without any additional upstream testing?

I've tested port of this patch on downstream kernel and it works.
I've also tested this on thierry's code base (git://gitorious.org/thierryreding/linux.git) which has
upstream code for T124-Jetson-tk1.
Because of the L0s and L1 exit latencies exhibited by jetson-tk1 on-board Realtek Ethernet controller,
subsystem can't enable ASPM states on the end point,
 but as such I've verified the flow with the help of debug prints and they indicate that the patch is doing its job correctly.

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas July 5, 2014, 6:57 p.m. UTC | #3
[+cc Matthew]

On Tue, Jul 01, 2014 at 12:46:18PM +0530, Vidya Sagar wrote:
> commit 1a680b7c moved pcie_aspm_powersave_config_link() out of
> pci_raw_set_power_state() to pci_set_power_state() which would enable
> ASPM. But, with commit db288c9c, which re-introduced the following check
> ./drivers/pci/pci.c: pci_set_power_state()
> +   /* Check if we're already there */
> +   if (dev->current_state == state)
> +       return 0;
> in pci_set_power_state(), call to pcie_aspm_powersave_config_link() is never
> made leaving ASPM broken.
> Fix it by not returning from when the above condition is true, rather, jump to
> ASPM configuration code and exit from there eventually.

Rafael, Matthew, any comments?  We have vacillated on this before and
the web is already pretty tangled.

Vidya, can you give more details about the bug fixed by this change?
What's the scenario?  Are we resuming and the device is powered up but
ASPM isn't enabled?  Maybe you could collect more details in a
http://bugzilla.kernel.org report?

> Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
> ---
>  drivers/pci/pci.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 1c8592b..ded24c4 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -804,7 +804,7 @@ EXPORT_SYMBOL_GPL(__pci_complete_power_transition);
>   */
>  int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
>  {
> -	int error;
> +	int error = 0;
>  
>  	/* bound the state we're entering */
>  	if (state > PCI_D3cold)
> @@ -821,7 +821,7 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
>  
>  	/* Check if we're already there */
>  	if (dev->current_state == state)
> -		return 0;
> +		goto config_aspm;
>  
>  	__pci_start_power_transition(dev, state);
>  
> @@ -839,6 +839,8 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
>  
>  	if (!__pci_complete_power_transition(dev, state))
>  		error = 0;
> +
> +config_aspm:
>  	/*
>  	 * When aspm_policy is "powersave" this call ensures
>  	 * that ASPM is configured.
> -- 
> 1.8.1.5
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas July 5, 2014, 7:02 p.m. UTC | #4
[+cc Rafael]

On Sat, Jul 05, 2014 at 12:57:36PM -0600, Bjorn Helgaas wrote:
> [+cc Matthew]
> 
> On Tue, Jul 01, 2014 at 12:46:18PM +0530, Vidya Sagar wrote:
> > commit 1a680b7c moved pcie_aspm_powersave_config_link() out of
> > pci_raw_set_power_state() to pci_set_power_state() which would enable
> > ASPM. But, with commit db288c9c, which re-introduced the following check
> > ./drivers/pci/pci.c: pci_set_power_state()
> > +   /* Check if we're already there */
> > +   if (dev->current_state == state)
> > +       return 0;
> > in pci_set_power_state(), call to pcie_aspm_powersave_config_link() is never
> > made leaving ASPM broken.
> > Fix it by not returning from when the above condition is true, rather, jump to
> > ASPM configuration code and exit from there eventually.
> 
> Rafael, Matthew, any comments?  We have vacillated on this before and
> the web is already pretty tangled.
> 
> Vidya, can you give more details about the bug fixed by this change?
> What's the scenario?  Are we resuming and the device is powered up but
> ASPM isn't enabled?  Maybe you could collect more details in a
> http://bugzilla.kernel.org report?
> 
> > Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
> > ---
> >  drivers/pci/pci.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index 1c8592b..ded24c4 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -804,7 +804,7 @@ EXPORT_SYMBOL_GPL(__pci_complete_power_transition);
> >   */
> >  int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
> >  {
> > -	int error;
> > +	int error = 0;
> >  
> >  	/* bound the state we're entering */
> >  	if (state > PCI_D3cold)
> > @@ -821,7 +821,7 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
> >  
> >  	/* Check if we're already there */
> >  	if (dev->current_state == state)
> > -		return 0;
> > +		goto config_aspm;
> >  
> >  	__pci_start_power_transition(dev, state);
> >  
> > @@ -839,6 +839,8 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
> >  
> >  	if (!__pci_complete_power_transition(dev, state))
> >  		error = 0;
> > +
> > +config_aspm:
> >  	/*
> >  	 * When aspm_policy is "powersave" this call ensures
> >  	 * that ASPM is configured.
> > -- 
> > 1.8.1.5
> > 
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Matthew Garrett July 7, 2014, 4:02 p.m. UTC | #5
On Sat, 2014-07-05 at 13:02 -0600, Bjorn Helgaas wrote:
> > Rafael, Matthew, any comments?  We have vacillated on this before and

> > the web is already pretty tangled.

> > 

> > Vidya, can you give more details about the bug fixed by this change?

> > What's the scenario?  Are we resuming and the device is powered up but

> > ASPM isn't enabled?  Maybe you could collect more details in a

> > http://bugzilla.kernel.org report?


I believe that's the case. The proposed change would fix it but isn't
really terribly clean - I think it would be more readable to split this
into multiple functions.

-- 
Matthew Garrett <matthew.garrett@nebula.com>
Vidya Sagar July 7, 2014, 6 p.m. UTC | #6
> -----Original Message-----
> From: Bjorn Helgaas [mailto:bhelgaas@google.com]
> Sent: Sunday, July 06, 2014 12:32 AM
> To: Vidya Sagar
> Cc: nagananda.chumbalkar@hp.com; thierry.reding@gmail.com; Stephen
> Warren; Krishna Thota; linux-pci@vger.kernel.org; linux-
> kernel@vger.kernel.org; Matthew Garrett; Rafael J. Wysocki
> Subject: Re: [PATCH v1] PCI: enable ASPM configuration in PCIE POWERSAVE
> mode
> 
> [+cc Rafael]
> 
> On Sat, Jul 05, 2014 at 12:57:36PM -0600, Bjorn Helgaas wrote:
> > [+cc Matthew]
> >
> > On Tue, Jul 01, 2014 at 12:46:18PM +0530, Vidya Sagar wrote:
> > > commit 1a680b7c moved pcie_aspm_powersave_config_link() out of
> > > pci_raw_set_power_state() to pci_set_power_state() which would
> > > enable ASPM. But, with commit db288c9c, which re-introduced the
> > > following check
> > > ./drivers/pci/pci.c: pci_set_power_state()
> > > +   /* Check if we're already there */
> > > +   if (dev->current_state == state)
> > > +       return 0;
> > > in pci_set_power_state(), call to pcie_aspm_powersave_config_link()
> > > is never made leaving ASPM broken.
> > > Fix it by not returning from when the above condition is true,
> > > rather, jump to ASPM configuration code and exit from there eventually.
> >
> > Rafael, Matthew, any comments?  We have vacillated on this before and
> > the web is already pretty tangled.
> >
> > Vidya, can you give more details about the bug fixed by this change?
> > What's the scenario?  Are we resuming and the device is powered up but
> > ASPM isn't enabled?  Maybe you could collect more details in a
> > http://bugzilla.kernel.org report?

I've raised a bugzilla bug  https://bugzilla.kernel.org/show_bug.cgi?id=79621 for the same.
Scenario here is, when the driver of a particular PCIe device is loaded and when CONFIG_PCIEASPM_POWERSAVE=y, ASPM is expected to get configured by the sub system which is not happening as of today.
The reason for this behavior is the 'if' condition that checks for the device's power state and returns if it is already in D0. Ideally, it shouldn't return from there, rather proceed to configure ASPM.

> >
> > > Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
> > > ---
> > >  drivers/pci/pci.c | 6 ++++--
> > >  1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index
> > > 1c8592b..ded24c4 100644
> > > --- a/drivers/pci/pci.c
> > > +++ b/drivers/pci/pci.c
> > > @@ -804,7 +804,7 @@
> EXPORT_SYMBOL_GPL(__pci_complete_power_transition);
> > >   */
> > >  int pci_set_power_state(struct pci_dev *dev, pci_power_t state)  {
> > > -	int error;
> > > +	int error = 0;
> > >
> > >  	/* bound the state we're entering */
> > >  	if (state > PCI_D3cold)
> > > @@ -821,7 +821,7 @@ int pci_set_power_state(struct pci_dev *dev,
> > > pci_power_t state)
> > >
> > >  	/* Check if we're already there */
> > >  	if (dev->current_state == state)
> > > -		return 0;
> > > +		goto config_aspm;
> > >
> > >  	__pci_start_power_transition(dev, state);
> > >
> > > @@ -839,6 +839,8 @@ int pci_set_power_state(struct pci_dev *dev,
> > > pci_power_t state)
> > >
> > >  	if (!__pci_complete_power_transition(dev, state))
> > >  		error = 0;
> > > +
> > > +config_aspm:
> > >  	/*
> > >  	 * When aspm_policy is "powersave" this call ensures
> > >  	 * that ASPM is configured.
> > > --
> > > 1.8.1.5
> > >
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas July 7, 2014, 9:12 p.m. UTC | #7
On Mon, Jul 7, 2014 at 12:00 PM, Vidya Sagar <vidyas@nvidia.com> wrote:
>> -----Original Message-----
>> From: Bjorn Helgaas [mailto:bhelgaas@google.com]
>> Sent: Sunday, July 06, 2014 12:32 AM
>> To: Vidya Sagar
>> Cc: nagananda.chumbalkar@hp.com; thierry.reding@gmail.com; Stephen
>> Warren; Krishna Thota; linux-pci@vger.kernel.org; linux-
>> kernel@vger.kernel.org; Matthew Garrett; Rafael J. Wysocki
>> Subject: Re: [PATCH v1] PCI: enable ASPM configuration in PCIE POWERSAVE
>> mode
>>
>> [+cc Rafael]
>>
>> On Sat, Jul 05, 2014 at 12:57:36PM -0600, Bjorn Helgaas wrote:
>> > [+cc Matthew]
>> >
>> > On Tue, Jul 01, 2014 at 12:46:18PM +0530, Vidya Sagar wrote:
>> > > commit 1a680b7c moved pcie_aspm_powersave_config_link() out of
>> > > pci_raw_set_power_state() to pci_set_power_state() which would
>> > > enable ASPM. But, with commit db288c9c, which re-introduced the
>> > > following check
>> > > ./drivers/pci/pci.c: pci_set_power_state()
>> > > +   /* Check if we're already there */
>> > > +   if (dev->current_state == state)
>> > > +       return 0;
>> > > in pci_set_power_state(), call to pcie_aspm_powersave_config_link()
>> > > is never made leaving ASPM broken.
>> > > Fix it by not returning from when the above condition is true,
>> > > rather, jump to ASPM configuration code and exit from there eventually.
>> >
>> > Rafael, Matthew, any comments?  We have vacillated on this before and
>> > the web is already pretty tangled.
>> >
>> > Vidya, can you give more details about the bug fixed by this change?
>> > What's the scenario?  Are we resuming and the device is powered up but
>> > ASPM isn't enabled?  Maybe you could collect more details in a
>> > http://bugzilla.kernel.org report?
>
> I've raised a bugzilla bug  https://bugzilla.kernel.org/show_bug.cgi?id=79621 for the same.
> Scenario here is, when the driver of a particular PCIe device is loaded and when CONFIG_PCIEASPM_POWERSAVE=y, ASPM is expected to get configured by the sub system which is not happening as of today.
> The reason for this behavior is the 'if' condition that checks for the device's power state and returns if it is already in D0. Ideally, it shouldn't return from there, rather proceed to configure ASPM.

Thanks, Vidya.  I'm not really looking for analysis of the code flow,
since I can work that out myself.  What I *would* like is a complete
dmesg log and "lspci -vv" output, because I'd like to know what's
special about this particular device.  We boot with devices powered on
(in D0) all the time, and most of the time, ASPM is configured
correctly.  So I want to know what is different about this case.

Bjorn

>> > > Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
>> > > ---
>> > >  drivers/pci/pci.c | 6 ++++--
>> > >  1 file changed, 4 insertions(+), 2 deletions(-)
>> > >
>> > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index
>> > > 1c8592b..ded24c4 100644
>> > > --- a/drivers/pci/pci.c
>> > > +++ b/drivers/pci/pci.c
>> > > @@ -804,7 +804,7 @@
>> EXPORT_SYMBOL_GPL(__pci_complete_power_transition);
>> > >   */
>> > >  int pci_set_power_state(struct pci_dev *dev, pci_power_t state)  {
>> > > - int error;
>> > > + int error = 0;
>> > >
>> > >   /* bound the state we're entering */
>> > >   if (state > PCI_D3cold)
>> > > @@ -821,7 +821,7 @@ int pci_set_power_state(struct pci_dev *dev,
>> > > pci_power_t state)
>> > >
>> > >   /* Check if we're already there */
>> > >   if (dev->current_state == state)
>> > > -         return 0;
>> > > +         goto config_aspm;
>> > >
>> > >   __pci_start_power_transition(dev, state);
>> > >
>> > > @@ -839,6 +839,8 @@ int pci_set_power_state(struct pci_dev *dev,
>> > > pci_power_t state)
>> > >
>> > >   if (!__pci_complete_power_transition(dev, state))
>> > >           error = 0;
>> > > +
>> > > +config_aspm:
>> > >   /*
>> > >    * When aspm_policy is "powersave" this call ensures
>> > >    * that ASPM is configured.
>> > > --
>> > > 1.8.1.5
>> > >
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 1c8592b..ded24c4 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -804,7 +804,7 @@  EXPORT_SYMBOL_GPL(__pci_complete_power_transition);
  */
 int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 {
-	int error;
+	int error = 0;
 
 	/* bound the state we're entering */
 	if (state > PCI_D3cold)
@@ -821,7 +821,7 @@  int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 
 	/* Check if we're already there */
 	if (dev->current_state == state)
-		return 0;
+		goto config_aspm;
 
 	__pci_start_power_transition(dev, state);
 
@@ -839,6 +839,8 @@  int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 
 	if (!__pci_complete_power_transition(dev, state))
 		error = 0;
+
+config_aspm:
 	/*
 	 * When aspm_policy is "powersave" this call ensures
 	 * that ASPM is configured.