linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH v1] scsi: smartpqi: use generic power management
@ 2020-07-30  7:02 Vaibhav Gupta
  2020-07-30 11:09 ` [Linux-kernel-mentees] [PATCH v2] " Vaibhav Gupta
  0 siblings, 1 reply; 4+ messages in thread
From: Vaibhav Gupta @ 2020-07-30  7:02 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, Bjorn Helgaas, Vaibhav Gupta,
	Don Brace, James E.J. Bottomley, Martin K. Petersen
  Cc: linux-scsi, Vaibhav Gupta, esc.storagedev, linux-kernel,
	linux-kernel-mentees

Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.

Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/scsi/smartpqi/smartpqi_init.c | 42 ++++++++++++++++++---------
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index cd157f11eb22..dc8567236a23 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -8059,11 +8059,11 @@ static void pqi_process_module_params(void)
 	pqi_process_lockup_action_param();
 }
 
-static __maybe_unused int pqi_suspend(struct pci_dev *pci_dev, pm_message_t state)
+static __maybe_unused int pqi_suspend_late(struct device *dev, pm_message_t state)
 {
 	struct pqi_ctrl_info *ctrl_info;
 
-	ctrl_info = pci_get_drvdata(pci_dev);
+	ctrl_info = dev_get_drvdata(dev);
 
 	pqi_disable_events(ctrl_info);
 	pqi_cancel_update_time_worker(ctrl_info);
@@ -8081,20 +8081,33 @@ static __maybe_unused int pqi_suspend(struct pci_dev *pci_dev, pm_message_t stat
 	if (state.event == PM_EVENT_FREEZE)
 		return 0;
 
-	pci_save_state(pci_dev);
-	pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
-
 	ctrl_info->controller_online = false;
 	ctrl_info->pqi_mode_enabled = false;
 
 	return 0;
 }
 
-static __maybe_unused int pqi_resume(struct pci_dev *pci_dev)
+static __maybe_unused int pqi_suspend(struct device *dev)
+{
+	return pqi_suspend_late(dev, PMSG_SUSPEND);
+}
+
+static __maybe_unused int pqi_hibernate(struct device *dev)
+{
+	return pqi_suspend_late(dev, PMSG_HIBERNATE);
+}
+
+static __maybe_unused int pqi_freeze(struct device *dev)
+{
+	return pqi_suspend_late(dev, PMSG_FREEZE);
+}
+
+static __maybe_unused int pqi_resume(struct device *dev)
 {
 	int rc;
 	struct pqi_ctrl_info *ctrl_info;
 
+	struct pci_dev *pci_dev = to_pci_dev(dev);
 	ctrl_info = pci_get_drvdata(pci_dev);
 
 	if (pci_dev->current_state != PCI_D0) {
@@ -8115,9 +8128,6 @@ static __maybe_unused int pqi_resume(struct pci_dev *pci_dev)
 		return 0;
 	}
 
-	pci_set_power_state(pci_dev, PCI_D0);
-	pci_restore_state(pci_dev);
-
 	return pqi_ctrl_init_resume(ctrl_info);
 }
 
@@ -8480,16 +8490,22 @@ static const struct pci_device_id pqi_pci_id_table[] = {
 
 MODULE_DEVICE_TABLE(pci, pqi_pci_id_table);
 
+static const struct dev_pm_ops pqi_pm_ops = {
+	.suspend = pqi_suspend,
+	.resume = pqi_resume,
+	.freeze = pqi_freeze,
+	.thaw = pqi_resume,
+	.poweroff = pqi_hibernate,
+	.restore = pqi_resume,
+};
+
 static struct pci_driver pqi_pci_driver = {
 	.name = DRIVER_NAME_SHORT,
 	.id_table = pqi_pci_id_table,
 	.probe = pqi_pci_probe,
 	.remove = pqi_pci_remove,
 	.shutdown = pqi_shutdown,
-#if defined(CONFIG_PM)
-	.suspend = pqi_suspend,
-	.resume = pqi_resume,
-#endif
+	.driver.pm = &pqi_pm_ops
 };
 
 static int __init pqi_init(void)
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Linux-kernel-mentees] [PATCH v2] scsi: smartpqi: use generic power management
  2020-07-30  7:02 [Linux-kernel-mentees] [PATCH v1] scsi: smartpqi: use generic power management Vaibhav Gupta
@ 2020-07-30 11:09 ` Vaibhav Gupta
  2020-07-30 11:11   ` Vaibhav Gupta
  2020-08-17  8:10   ` Vaibhav Gupta
  0 siblings, 2 replies; 4+ messages in thread
From: Vaibhav Gupta @ 2020-07-30 11:09 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, Bjorn Helgaas, Vaibhav Gupta,
	Don Brace, James E.J. Bottomley, Martin K. Petersen
  Cc: linux-scsi, Vaibhav Gupta, esc.storagedev, linux-kernel,
	linux-kernel-mentees

Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.

Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/scsi/smartpqi/smartpqi_init.c | 44 +++++++++++++++++++--------
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index cd157f11eb22..7061bd26897a 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -8059,11 +8059,11 @@ static void pqi_process_module_params(void)
 	pqi_process_lockup_action_param();
 }
 
-static __maybe_unused int pqi_suspend(struct pci_dev *pci_dev, pm_message_t state)
+static int pqi_suspend_late(struct device *dev, pm_message_t state)
 {
 	struct pqi_ctrl_info *ctrl_info;
 
-	ctrl_info = pci_get_drvdata(pci_dev);
+	ctrl_info = dev_get_drvdata(dev);
 
 	pqi_disable_events(ctrl_info);
 	pqi_cancel_update_time_worker(ctrl_info);
@@ -8081,20 +8081,33 @@ static __maybe_unused int pqi_suspend(struct pci_dev *pci_dev, pm_message_t stat
 	if (state.event == PM_EVENT_FREEZE)
 		return 0;
 
-	pci_save_state(pci_dev);
-	pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
-
 	ctrl_info->controller_online = false;
 	ctrl_info->pqi_mode_enabled = false;
 
 	return 0;
 }
 
-static __maybe_unused int pqi_resume(struct pci_dev *pci_dev)
+static __maybe_unused int pqi_suspend(struct device *dev)
+{
+	return pqi_suspend_late(dev, PMSG_SUSPEND);
+}
+
+static __maybe_unused int pqi_hibernate(struct device *dev)
+{
+	return pqi_suspend_late(dev, PMSG_HIBERNATE);
+}
+
+static __maybe_unused int pqi_freeze(struct device *dev)
+{
+	return pqi_suspend_late(dev, PMSG_FREEZE);
+}
+
+static __maybe_unused int pqi_resume(struct device *dev)
 {
 	int rc;
 	struct pqi_ctrl_info *ctrl_info;
 
+	struct pci_dev *pci_dev = to_pci_dev(dev);
 	ctrl_info = pci_get_drvdata(pci_dev);
 
 	if (pci_dev->current_state != PCI_D0) {
@@ -8115,9 +8128,6 @@ static __maybe_unused int pqi_resume(struct pci_dev *pci_dev)
 		return 0;
 	}
 
-	pci_set_power_state(pci_dev, PCI_D0);
-	pci_restore_state(pci_dev);
-
 	return pqi_ctrl_init_resume(ctrl_info);
 }
 
@@ -8480,16 +8490,24 @@ static const struct pci_device_id pqi_pci_id_table[] = {
 
 MODULE_DEVICE_TABLE(pci, pqi_pci_id_table);
 
+static const struct dev_pm_ops pqi_pm_ops = {
+#ifdef CONFIG_PM_SLEEP
+	.suspend = pqi_suspend,
+	.resume = pqi_resume,
+	.freeze = pqi_freeze,
+	.thaw = pqi_resume,
+	.poweroff = pqi_hibernate,
+	.restore = pqi_resume,
+#endif
+};
+
 static struct pci_driver pqi_pci_driver = {
 	.name = DRIVER_NAME_SHORT,
 	.id_table = pqi_pci_id_table,
 	.probe = pqi_pci_probe,
 	.remove = pqi_pci_remove,
 	.shutdown = pqi_shutdown,
-#if defined(CONFIG_PM)
-	.suspend = pqi_suspend,
-	.resume = pqi_resume,
-#endif
+	.driver.pm = &pqi_pm_ops
 };
 
 static int __init pqi_init(void)
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v2] scsi: smartpqi: use generic power management
  2020-07-30 11:09 ` [Linux-kernel-mentees] [PATCH v2] " Vaibhav Gupta
@ 2020-07-30 11:11   ` Vaibhav Gupta
  2020-08-17  8:10   ` Vaibhav Gupta
  1 sibling, 0 replies; 4+ messages in thread
From: Vaibhav Gupta @ 2020-07-30 11:11 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, Bjorn Helgaas, Vaibhav Gupta,
	Don Brace, James E.J. Bottomley, Martin K. Petersen
  Cc: linux-kernel-mentees, esc.storagedev, linux-kernel, linux-scsi

This patch is compile tested only.

Thanks
Vaibhav Gupta
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v2] scsi: smartpqi: use generic power management
  2020-07-30 11:09 ` [Linux-kernel-mentees] [PATCH v2] " Vaibhav Gupta
  2020-07-30 11:11   ` Vaibhav Gupta
@ 2020-08-17  8:10   ` Vaibhav Gupta
  1 sibling, 0 replies; 4+ messages in thread
From: Vaibhav Gupta @ 2020-08-17  8:10 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, Bjorn Helgaas, Vaibhav Gupta,
	Don Brace, James E.J. Bottomley, Martin K. Petersen
  Cc: linux-kernel-mentees, esc.storagedev, linux-kernel, linux-scsi

On Thu, Jul 30, 2020 at 04:39:30PM +0530, Vaibhav Gupta wrote:
> Drivers using legacy power management .suspen()/.resume() callbacks
> have to manage PCI states and device's PM states themselves. They also
> need to take care of standard configuration registers.
> 
> Switch to generic power management framework using a single
> "struct dev_pm_ops" variable to take the unnecessary load from the driver.
> This also avoids the need for the driver to directly call most of the PCI
> helper functions and device power state control functions, as through
> the generic framework PCI Core takes care of the necessary operations,
> and drivers are required to do only device-specific jobs.
> 
> Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
> ---
>  drivers/scsi/smartpqi/smartpqi_init.c | 44 +++++++++++++++++++--------
>  1 file changed, 31 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
> index cd157f11eb22..7061bd26897a 100644
> --- a/drivers/scsi/smartpqi/smartpqi_init.c
> +++ b/drivers/scsi/smartpqi/smartpqi_init.c
> @@ -8059,11 +8059,11 @@ static void pqi_process_module_params(void)
>  	pqi_process_lockup_action_param();
>  }
>  
> -static __maybe_unused int pqi_suspend(struct pci_dev *pci_dev, pm_message_t state)
> +static int pqi_suspend_late(struct device *dev, pm_message_t state)
>  {
>  	struct pqi_ctrl_info *ctrl_info;
>  
> -	ctrl_info = pci_get_drvdata(pci_dev);
> +	ctrl_info = dev_get_drvdata(dev);
>  
>  	pqi_disable_events(ctrl_info);
>  	pqi_cancel_update_time_worker(ctrl_info);
> @@ -8081,20 +8081,33 @@ static __maybe_unused int pqi_suspend(struct pci_dev *pci_dev, pm_message_t stat
>  	if (state.event == PM_EVENT_FREEZE)
>  		return 0;
>  
> -	pci_save_state(pci_dev);
> -	pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
> -
>  	ctrl_info->controller_online = false;
>  	ctrl_info->pqi_mode_enabled = false;
>  
>  	return 0;
>  }
>  
> -static __maybe_unused int pqi_resume(struct pci_dev *pci_dev)
> +static __maybe_unused int pqi_suspend(struct device *dev)
> +{
> +	return pqi_suspend_late(dev, PMSG_SUSPEND);
> +}
> +
> +static __maybe_unused int pqi_hibernate(struct device *dev)
> +{
> +	return pqi_suspend_late(dev, PMSG_HIBERNATE);
> +}
> +
> +static __maybe_unused int pqi_freeze(struct device *dev)
> +{
> +	return pqi_suspend_late(dev, PMSG_FREEZE);
> +}
> +
> +static __maybe_unused int pqi_resume(struct device *dev)
>  {
>  	int rc;
>  	struct pqi_ctrl_info *ctrl_info;
>  
> +	struct pci_dev *pci_dev = to_pci_dev(dev);
>  	ctrl_info = pci_get_drvdata(pci_dev);
>  
>  	if (pci_dev->current_state != PCI_D0) {
> @@ -8115,9 +8128,6 @@ static __maybe_unused int pqi_resume(struct pci_dev *pci_dev)
>  		return 0;
>  	}
>  
> -	pci_set_power_state(pci_dev, PCI_D0);
> -	pci_restore_state(pci_dev);
> -
>  	return pqi_ctrl_init_resume(ctrl_info);
>  }
>  
> @@ -8480,16 +8490,24 @@ static const struct pci_device_id pqi_pci_id_table[] = {
>  
>  MODULE_DEVICE_TABLE(pci, pqi_pci_id_table);
>  
> +static const struct dev_pm_ops pqi_pm_ops = {
> +#ifdef CONFIG_PM_SLEEP
> +	.suspend = pqi_suspend,
> +	.resume = pqi_resume,
> +	.freeze = pqi_freeze,
> +	.thaw = pqi_resume,
> +	.poweroff = pqi_hibernate,
> +	.restore = pqi_resume,
> +#endif
> +};
> +
>  static struct pci_driver pqi_pci_driver = {
>  	.name = DRIVER_NAME_SHORT,
>  	.id_table = pqi_pci_id_table,
>  	.probe = pqi_pci_probe,
>  	.remove = pqi_pci_remove,
>  	.shutdown = pqi_shutdown,
> -#if defined(CONFIG_PM)
> -	.suspend = pqi_suspend,
> -	.resume = pqi_resume,
> -#endif
> +	.driver.pm = &pqi_pm_ops
>  };
>  
>  static int __init pqi_init(void)
> -- 
> 2.27.0
> 
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-17  8:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-30  7:02 [Linux-kernel-mentees] [PATCH v1] scsi: smartpqi: use generic power management Vaibhav Gupta
2020-07-30 11:09 ` [Linux-kernel-mentees] [PATCH v2] " Vaibhav Gupta
2020-07-30 11:11   ` Vaibhav Gupta
2020-08-17  8:10   ` Vaibhav Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).