diff mbox series

HID: intel-ish-hid: Replace PCI_DEV_FLAGS_NO_D3 with pci_save_state

Message ID 20200505131730.22118-1-kai.heng.feng@canonical.com (mailing list archive)
State Superseded
Delegated to: Jiri Kosina
Headers show
Series HID: intel-ish-hid: Replace PCI_DEV_FLAGS_NO_D3 with pci_save_state | expand

Commit Message

Kai-Heng Feng May 5, 2020, 1:17 p.m. UTC
PCI_DEV_FLAGS_NO_D3 should not be used outside of PCI core.

Instead, we can use pci_save_state() to hint PCI core that the device
should stay at D0 during suspend.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/hid/intel-ish-hid/ipc/pci-ish.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Srinivas Pandruvada May 8, 2020, 5:45 p.m. UTC | #1
On Tue, 2020-05-05 at 21:17 +0800, Kai-Heng Feng wrote:
> PCI_DEV_FLAGS_NO_D3 should not be used outside of PCI core.
> 
> Instead, we can use pci_save_state() to hint PCI core that the device
> should stay at D0 during suspend.

Your changes are doing more than just changing the flag. Can you
explain more about the other changes?
Also make sure that you test on both platforms which has regular S3 and
S0ix (modern standby system).

Thanks,
Srinivas


> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
>  drivers/hid/intel-ish-hid/ipc/pci-ish.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
> b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
> index f491d8b4e24c..ab588b9c8d09 100644
> --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
> +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
> @@ -106,6 +106,11 @@ static inline bool ish_should_enter_d0i3(struct
> pci_dev *pdev)
>  	return !pm_suspend_via_firmware() || pdev->device ==
> CHV_DEVICE_ID;
>  }
>  
> +static inline bool ish_should_leave_d0i3(struct pci_dev *pdev)
> +{
> +	return !pm_resume_via_firmware() || pdev->device ==
> CHV_DEVICE_ID;
> +}
> +
>  /**
>   * ish_probe() - PCI driver probe callback
>   * @pdev:	pci device
> @@ -215,9 +220,7 @@ static void __maybe_unused
> ish_resume_handler(struct work_struct *work)
>  	struct ishtp_device *dev = pci_get_drvdata(pdev);
>  	int ret;
>  
> -	/* Check the NO_D3 flag to distinguish the resume paths */
> -	if (pdev->dev_flags & PCI_DEV_FLAGS_NO_D3) {
> -		pdev->dev_flags &= ~PCI_DEV_FLAGS_NO_D3;
> +	if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag) {
>  		disable_irq_wake(pdev->irq);
>  
>  		ishtp_send_resume(dev);
> @@ -281,8 +284,10 @@ static int __maybe_unused ish_suspend(struct
> device *device)
>  			 */
>  			ish_disable_dma(dev);
>  		} else {
> -			/* Set the NO_D3 flag, the ISH would enter D0i3
> */
> -			pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
> +			/* Save state so PCI core will keep the device
> at D0,
> +			 * the ISH would enter D0i3
> +			 */
> +			pci_save_state(pdev);
>  
Did you test on some C


>  			enable_irq_wake(pdev->irq);
>  		}
Kai-Heng Feng May 21, 2020, 4:43 a.m. UTC | #2
Hi Srinivas,

> On May 9, 2020, at 01:45, Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> wrote:
> 
> On Tue, 2020-05-05 at 21:17 +0800, Kai-Heng Feng wrote:
>> PCI_DEV_FLAGS_NO_D3 should not be used outside of PCI core.
>> 
>> Instead, we can use pci_save_state() to hint PCI core that the device
>> should stay at D0 during suspend.
> 
> Your changes are doing more than just changing the flag. Can you
> explain more about the other changes?

By using pci_save_state(), in addition to keep itself stay at D0, the parent bridge will also stay at D0.
So it's a better approach to achieve the same thing.

> Also make sure that you test on both platforms which has regular S3 and
> S0ix (modern standby system).

Actually I don't have any physical hardware to test the patch, I found the issue when I search for D3 quirks through the source code.

Can you guys do a quick smoketest for this patch?

Kai-Heng

> 
> Thanks,
> Srinivas
> 
> 
>> 
>> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>> ---
>> drivers/hid/intel-ish-hid/ipc/pci-ish.c | 15 ++++++++++-----
>> 1 file changed, 10 insertions(+), 5 deletions(-)
>> 
>> diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
>> b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
>> index f491d8b4e24c..ab588b9c8d09 100644
>> --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
>> +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
>> @@ -106,6 +106,11 @@ static inline bool ish_should_enter_d0i3(struct
>> pci_dev *pdev)
>> 	return !pm_suspend_via_firmware() || pdev->device ==
>> CHV_DEVICE_ID;
>> }
>> 
>> +static inline bool ish_should_leave_d0i3(struct pci_dev *pdev)
>> +{
>> +	return !pm_resume_via_firmware() || pdev->device ==
>> CHV_DEVICE_ID;
>> +}
>> +
>> /**
>>  * ish_probe() - PCI driver probe callback
>>  * @pdev:	pci device
>> @@ -215,9 +220,7 @@ static void __maybe_unused
>> ish_resume_handler(struct work_struct *work)
>> 	struct ishtp_device *dev = pci_get_drvdata(pdev);
>> 	int ret;
>> 
>> -	/* Check the NO_D3 flag to distinguish the resume paths */
>> -	if (pdev->dev_flags & PCI_DEV_FLAGS_NO_D3) {
>> -		pdev->dev_flags &= ~PCI_DEV_FLAGS_NO_D3;
>> +	if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag) {
>> 		disable_irq_wake(pdev->irq);
>> 
>> 		ishtp_send_resume(dev);
>> @@ -281,8 +284,10 @@ static int __maybe_unused ish_suspend(struct
>> device *device)
>> 			 */
>> 			ish_disable_dma(dev);
>> 		} else {
>> -			/* Set the NO_D3 flag, the ISH would enter D0i3
>> */
>> -			pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
>> +			/* Save state so PCI core will keep the device
>> at D0,
>> +			 * the ISH would enter D0i3
>> +			 */
>> +			pci_save_state(pdev);
>> 
> Did you test on some C
> 
> 
>> 			enable_irq_wake(pdev->irq);
>> 		}
Kai-Heng Feng June 12, 2020, 11:43 a.m. UTC | #3
> On May 21, 2020, at 12:43, Kai-Heng Feng <kai.heng.feng@canonical.com> wrote:
> 
> Hi Srinivas,
> 
>> On May 9, 2020, at 01:45, Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> wrote:
>> 
>> On Tue, 2020-05-05 at 21:17 +0800, Kai-Heng Feng wrote:
>>> PCI_DEV_FLAGS_NO_D3 should not be used outside of PCI core.
>>> 
>>> Instead, we can use pci_save_state() to hint PCI core that the device
>>> should stay at D0 during suspend.
>> 
>> Your changes are doing more than just changing the flag. Can you
>> explain more about the other changes?
> 
> By using pci_save_state(), in addition to keep itself stay at D0, the parent bridge will also stay at D0.
> So it's a better approach to achieve the same thing.
> 
>> Also make sure that you test on both platforms which has regular S3 and
>> S0ix (modern standby system).
> 
> Actually I don't have any physical hardware to test the patch, I found the issue when I search for D3 quirks through the source code.
> 
> Can you guys do a quick smoketest for this patch?

Tested this patch on an S2idle system with intel-ish (Latitude 9510) and it works fine.
Please consider merging this patch, thanks!

Kai-Heng

> 
> Kai-Heng
> 
>> 
>> Thanks,
>> Srinivas
>> 
>> 
>>> 
>>> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>>> ---
>>> drivers/hid/intel-ish-hid/ipc/pci-ish.c | 15 ++++++++++-----
>>> 1 file changed, 10 insertions(+), 5 deletions(-)
>>> 
>>> diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
>>> b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
>>> index f491d8b4e24c..ab588b9c8d09 100644
>>> --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
>>> +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
>>> @@ -106,6 +106,11 @@ static inline bool ish_should_enter_d0i3(struct
>>> pci_dev *pdev)
>>> 	return !pm_suspend_via_firmware() || pdev->device ==
>>> CHV_DEVICE_ID;
>>> }
>>> 
>>> +static inline bool ish_should_leave_d0i3(struct pci_dev *pdev)
>>> +{
>>> +	return !pm_resume_via_firmware() || pdev->device ==
>>> CHV_DEVICE_ID;
>>> +}
>>> +
>>> /**
>>> * ish_probe() - PCI driver probe callback
>>> * @pdev:	pci device
>>> @@ -215,9 +220,7 @@ static void __maybe_unused
>>> ish_resume_handler(struct work_struct *work)
>>> 	struct ishtp_device *dev = pci_get_drvdata(pdev);
>>> 	int ret;
>>> 
>>> -	/* Check the NO_D3 flag to distinguish the resume paths */
>>> -	if (pdev->dev_flags & PCI_DEV_FLAGS_NO_D3) {
>>> -		pdev->dev_flags &= ~PCI_DEV_FLAGS_NO_D3;
>>> +	if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag) {
>>> 		disable_irq_wake(pdev->irq);
>>> 
>>> 		ishtp_send_resume(dev);
>>> @@ -281,8 +284,10 @@ static int __maybe_unused ish_suspend(struct
>>> device *device)
>>> 			 */
>>> 			ish_disable_dma(dev);
>>> 		} else {
>>> -			/* Set the NO_D3 flag, the ISH would enter D0i3
>>> */
>>> -			pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
>>> +			/* Save state so PCI core will keep the device
>>> at D0,
>>> +			 * the ISH would enter D0i3
>>> +			 */
>>> +			pci_save_state(pdev);
>>> 
>> Did you test on some C
>> 
>> 
>>> 			enable_irq_wake(pdev->irq);
>>> 		}
>
Jiri Kosina June 19, 2020, 7:43 a.m. UTC | #4
On Fri, 12 Jun 2020, Kai-Heng Feng wrote:

> >>> PCI_DEV_FLAGS_NO_D3 should not be used outside of PCI core.
> >>> 
> >>> Instead, we can use pci_save_state() to hint PCI core that the device
> >>> should stay at D0 during suspend.
> >> 
> >> Your changes are doing more than just changing the flag. Can you
> >> explain more about the other changes?
> > 
> > By using pci_save_state(), in addition to keep itself stay at D0, the parent bridge will also stay at D0.
> > So it's a better approach to achieve the same thing.
> > 
> >> Also make sure that you test on both platforms which has regular S3 and
> >> S0ix (modern standby system).
> > 
> > Actually I don't have any physical hardware to test the patch, I found the issue when I search for D3 quirks through the source code.
> > 
> > Can you guys do a quick smoketest for this patch?
> 
> Tested this patch on an S2idle system with intel-ish (Latitude 9510) and 
> it works fine. Please consider merging this patch, thanks!

Thanks for testing.

Could you please resubmit v2 with the updated changelog (explaining the 
relationship to the parent bridge mode and the related changes your code 
is doing), and resubmit so that I can queue it in hid.git?

Thanks.
diff mbox series

Patch

diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
index f491d8b4e24c..ab588b9c8d09 100644
--- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
+++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
@@ -106,6 +106,11 @@  static inline bool ish_should_enter_d0i3(struct pci_dev *pdev)
 	return !pm_suspend_via_firmware() || pdev->device == CHV_DEVICE_ID;
 }
 
+static inline bool ish_should_leave_d0i3(struct pci_dev *pdev)
+{
+	return !pm_resume_via_firmware() || pdev->device == CHV_DEVICE_ID;
+}
+
 /**
  * ish_probe() - PCI driver probe callback
  * @pdev:	pci device
@@ -215,9 +220,7 @@  static void __maybe_unused ish_resume_handler(struct work_struct *work)
 	struct ishtp_device *dev = pci_get_drvdata(pdev);
 	int ret;
 
-	/* Check the NO_D3 flag to distinguish the resume paths */
-	if (pdev->dev_flags & PCI_DEV_FLAGS_NO_D3) {
-		pdev->dev_flags &= ~PCI_DEV_FLAGS_NO_D3;
+	if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag) {
 		disable_irq_wake(pdev->irq);
 
 		ishtp_send_resume(dev);
@@ -281,8 +284,10 @@  static int __maybe_unused ish_suspend(struct device *device)
 			 */
 			ish_disable_dma(dev);
 		} else {
-			/* Set the NO_D3 flag, the ISH would enter D0i3 */
-			pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
+			/* Save state so PCI core will keep the device at D0,
+			 * the ISH would enter D0i3
+			 */
+			pci_save_state(pdev);
 
 			enable_irq_wake(pdev->irq);
 		}