With legacy PM, drivers themselves were responsible for managing the
device's power states and takes care of register states.
After upgrading to the generic structure, PCI core will take care of
required tasks and drivers should do only device-specific operations.
The driver was calling pci_save/restore_state(), pci_choose_state(),
pci_enable/disable_device() and pci_set_power_state() which is no more
needed.
Compile-tested only.
Signed-off-by: Vaibhav Gupta <[email protected]>
---
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 32 ++++++++------------------
1 file changed, 10 insertions(+), 22 deletions(-)
diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index 55e2321a65bc..45605a520bc8 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -3374,13 +3374,13 @@ enum {
hip08,
};
-static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused hisi_sas_v3_suspend(struct device *dev_d)
{
+ struct pci_dev *pdev = to_pci_dev(dev_d);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
struct hisi_hba *hisi_hba = sha->lldd_ha;
struct device *dev = hisi_hba->dev;
struct Scsi_Host *shost = hisi_hba->shost;
- pci_power_t device_state;
int rc;
if (!pdev->pm_cap) {
@@ -3406,21 +3406,15 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
hisi_sas_init_mem(hisi_hba);
- device_state = pci_choose_state(pdev, state);
- dev_warn(dev, "entering operating state [D%d]\n",
- device_state);
- pci_save_state(pdev);
- pci_disable_device(pdev);
- pci_set_power_state(pdev, device_state);
-
hisi_sas_release_tasks(hisi_hba);
sas_suspend_ha(sha);
return 0;
}
-static int hisi_sas_v3_resume(struct pci_dev *pdev)
+static int __maybe_unused hisi_sas_v3_resume(struct device *dev_d)
{
+ struct pci_dev *pdev = to_pci_dev(dev_d);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
struct hisi_hba *hisi_hba = sha->lldd_ha;
struct Scsi_Host *shost = hisi_hba->shost;
@@ -3430,16 +3424,8 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
dev_warn(dev, "resuming from operating state [D%d]\n",
device_state);
- pci_set_power_state(pdev, PCI_D0);
- pci_enable_wake(pdev, PCI_D0, 0);
- pci_restore_state(pdev);
- rc = pci_enable_device(pdev);
- if (rc) {
- dev_err(dev, "enable device failed during resume (%d)\n", rc);
- return rc;
- }
+ device_wakeup_disable(dev_d);
- pci_set_master(pdev);
scsi_unblock_requests(shost);
clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
@@ -3447,7 +3433,6 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
rc = hw_init_v3_hw(hisi_hba);
if (rc) {
scsi_remove_host(shost);
- pci_disable_device(pdev);
return rc;
}
hisi_hba->hw->phys_init(hisi_hba);
@@ -3468,13 +3453,16 @@ static const struct pci_error_handlers hisi_sas_err_handler = {
.reset_done = hisi_sas_reset_done_v3_hw,
};
+static SIMPLE_DEV_PM_OPS(hisi_sas_v3_pm_ops,
+ hisi_sas_v3_suspend,
+ hisi_sas_v3_resume);
+
static struct pci_driver sas_v3_pci_driver = {
.name = DRV_NAME,
.id_table = sas_v3_pci_table,
.probe = hisi_sas_v3_probe,
.remove = hisi_sas_v3_remove,
- .suspend = hisi_sas_v3_suspend,
- .resume = hisi_sas_v3_resume,
+ .driver.pm = &hisi_sas_v3_pm_ops,
.err_handler = &hisi_sas_err_handler,
};
--
2.27.0
Hi Vaibhav,
?? 2020/7/17 14:34, Vaibhav Gupta д??:
> With legacy PM, drivers themselves were responsible for managing the
> device's power states and takes care of register states.
>
> After upgrading to the generic structure, PCI core will take care of
> required tasks and drivers should do only device-specific operations.
>
> The driver was calling pci_save/restore_state(), pci_choose_state(),
> pci_enable/disable_device() and pci_set_power_state() which is no more
> needed.
>
> Compile-tested only.
>
> Signed-off-by: Vaibhav Gupta <[email protected]>
Reviewed-by: Xiang Chen <[email protected]>
Just a small comment, below.
> ---
> drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 32 ++++++++------------------
> 1 file changed, 10 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> index 55e2321a65bc..45605a520bc8 100644
> --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> @@ -3374,13 +3374,13 @@ enum {
> hip08,
> };
>
> -static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused hisi_sas_v3_suspend(struct device *dev_d)
> {
> + struct pci_dev *pdev = to_pci_dev(dev_d);
> struct sas_ha_struct *sha = pci_get_drvdata(pdev);
> struct hisi_hba *hisi_hba = sha->lldd_ha;
> struct device *dev = hisi_hba->dev;
> struct Scsi_Host *shost = hisi_hba->shost;
> - pci_power_t device_state;
> int rc;
>
> if (!pdev->pm_cap) {
> @@ -3406,21 +3406,15 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
>
> hisi_sas_init_mem(hisi_hba);
>
> - device_state = pci_choose_state(pdev, state);
> - dev_warn(dev, "entering operating state [D%d]\n",
> - device_state);
Please retain above print to keep consistence with the print in function
hisi_sas_v3_resume().
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, device_state);
> -
> hisi_sas_release_tasks(hisi_hba);
>
> sas_suspend_ha(sha);
> return 0;
> }
>
> -static int hisi_sas_v3_resume(struct pci_dev *pdev)
> +static int __maybe_unused hisi_sas_v3_resume(struct device *dev_d)
> {
> + struct pci_dev *pdev = to_pci_dev(dev_d);
> struct sas_ha_struct *sha = pci_get_drvdata(pdev);
> struct hisi_hba *hisi_hba = sha->lldd_ha;
> struct Scsi_Host *shost = hisi_hba->shost;
> @@ -3430,16 +3424,8 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
>
> dev_warn(dev, "resuming from operating state [D%d]\n",
> device_state);
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> - rc = pci_enable_device(pdev);
> - if (rc) {
> - dev_err(dev, "enable device failed during resume (%d)\n", rc);
> - return rc;
> - }
> + device_wakeup_disable(dev_d);
>
> - pci_set_master(pdev);
> scsi_unblock_requests(shost);
> clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
>
> @@ -3447,7 +3433,6 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
> rc = hw_init_v3_hw(hisi_hba);
> if (rc) {
> scsi_remove_host(shost);
> - pci_disable_device(pdev);
> return rc;
> }
> hisi_hba->hw->phys_init(hisi_hba);
> @@ -3468,13 +3453,16 @@ static const struct pci_error_handlers hisi_sas_err_handler = {
> .reset_done = hisi_sas_reset_done_v3_hw,
> };
>
> +static SIMPLE_DEV_PM_OPS(hisi_sas_v3_pm_ops,
> + hisi_sas_v3_suspend,
> + hisi_sas_v3_resume);
> +
> static struct pci_driver sas_v3_pci_driver = {
> .name = DRV_NAME,
> .id_table = sas_v3_pci_table,
> .probe = hisi_sas_v3_probe,
> .remove = hisi_sas_v3_remove,
> - .suspend = hisi_sas_v3_suspend,
> - .resume = hisi_sas_v3_resume,
> + .driver.pm = &hisi_sas_v3_pm_ops,
> .err_handler = &hisi_sas_err_handler,
> };
>
On Mon, Jul 20, 2020 at 02:16:45PM +0800, chenxiang (M) wrote:
> Hi Vaibhav,
>
> 在 2020/7/17 14:34, Vaibhav Gupta 写道:
> > With legacy PM, drivers themselves were responsible for managing the
> > device's power states and takes care of register states.
> >
> > After upgrading to the generic structure, PCI core will take care of
> > required tasks and drivers should do only device-specific operations.
> >
> > The driver was calling pci_save/restore_state(), pci_choose_state(),
> > pci_enable/disable_device() and pci_set_power_state() which is no more
> > needed.
> >
> > Compile-tested only.
> >
> > Signed-off-by: Vaibhav Gupta <[email protected]>
>
> Reviewed-by: Xiang Chen <[email protected]>
> Just a small comment, below.
>
> > ---
> > drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 32 ++++++++------------------
> > 1 file changed, 10 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> > index 55e2321a65bc..45605a520bc8 100644
> > --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> > +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> > @@ -3374,13 +3374,13 @@ enum {
> > hip08,
> > };
> > -static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
> > +static int __maybe_unused hisi_sas_v3_suspend(struct device *dev_d)
> > {
> > + struct pci_dev *pdev = to_pci_dev(dev_d);
> > struct sas_ha_struct *sha = pci_get_drvdata(pdev);
> > struct hisi_hba *hisi_hba = sha->lldd_ha;
> > struct device *dev = hisi_hba->dev;
> > struct Scsi_Host *shost = hisi_hba->shost;
> > - pci_power_t device_state;
> > int rc;
> > if (!pdev->pm_cap) {
> > @@ -3406,21 +3406,15 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
> > hisi_sas_init_mem(hisi_hba);
> > - device_state = pci_choose_state(pdev, state);
> > - dev_warn(dev, "entering operating state [D%d]\n",
> > - device_state);
>
> Please retain above print to keep consistence with the print in function
> hisi_sas_v3_resume().
>
Okay, Thanks for the review :)
This is will be fixed in v2 patch-series along with other changes.
-- Vaibhav Gupta
> > - pci_save_state(pdev);
> > - pci_disable_device(pdev);
> > - pci_set_power_state(pdev, device_state);
> > -
> > hisi_sas_release_tasks(hisi_hba);
> > sas_suspend_ha(sha);
> > return 0;
> > }
> > -static int hisi_sas_v3_resume(struct pci_dev *pdev)
> > +static int __maybe_unused hisi_sas_v3_resume(struct device *dev_d)
> > {
> > + struct pci_dev *pdev = to_pci_dev(dev_d);
> > struct sas_ha_struct *sha = pci_get_drvdata(pdev);
> > struct hisi_hba *hisi_hba = sha->lldd_ha;
> > struct Scsi_Host *shost = hisi_hba->shost;
> > @@ -3430,16 +3424,8 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
> > dev_warn(dev, "resuming from operating state [D%d]\n",
> > device_state);
> > - pci_set_power_state(pdev, PCI_D0);
> > - pci_enable_wake(pdev, PCI_D0, 0);
> > - pci_restore_state(pdev);
> > - rc = pci_enable_device(pdev);
> > - if (rc) {
> > - dev_err(dev, "enable device failed during resume (%d)\n", rc);
> > - return rc;
> > - }
> > + device_wakeup_disable(dev_d);
> > - pci_set_master(pdev);
> > scsi_unblock_requests(shost);
> > clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
> > @@ -3447,7 +3433,6 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
> > rc = hw_init_v3_hw(hisi_hba);
> > if (rc) {
> > scsi_remove_host(shost);
> > - pci_disable_device(pdev);
> > return rc;
> > }
> > hisi_hba->hw->phys_init(hisi_hba);
> > @@ -3468,13 +3453,16 @@ static const struct pci_error_handlers hisi_sas_err_handler = {
> > .reset_done = hisi_sas_reset_done_v3_hw,
> > };
> > +static SIMPLE_DEV_PM_OPS(hisi_sas_v3_pm_ops,
> > + hisi_sas_v3_suspend,
> > + hisi_sas_v3_resume);
> > +
> > static struct pci_driver sas_v3_pci_driver = {
> > .name = DRV_NAME,
> > .id_table = sas_v3_pci_table,
> > .probe = hisi_sas_v3_probe,
> > .remove = hisi_sas_v3_remove,
> > - .suspend = hisi_sas_v3_suspend,
> > - .resume = hisi_sas_v3_resume,
> > + .driver.pm = &hisi_sas_v3_pm_ops,
> > .err_handler = &hisi_sas_err_handler,
> > };
>
>