scsi: mpt3sas_scsih: Use generic power management

Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Link: https://lore.kernel.org/r/20201102164730.324035-17-vaibhavgupta40@gmail.com
Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Vaibhav Gupta 2020-11-02 22:17:17 +05:30 committed by Martin K. Petersen
parent eaf148359d
commit 17287305a5

View File

@ -12048,20 +12048,18 @@ out_add_shost_fail:
return rv; return rv;
} }
#ifdef CONFIG_PM
/** /**
* scsih_suspend - power management suspend main entry point * scsih_suspend - power management suspend main entry point
* @pdev: PCI device struct * @dev: Device struct
* @state: PM state change to (usually PCI_D3)
* *
* Return: 0 success, anything else error. * Return: 0 success, anything else error.
*/ */
static int static int __maybe_unused
scsih_suspend(struct pci_dev *pdev, pm_message_t state) scsih_suspend(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *shost; struct Scsi_Host *shost;
struct MPT3SAS_ADAPTER *ioc; struct MPT3SAS_ADAPTER *ioc;
pci_power_t device_state;
int rc; int rc;
rc = _scsih_get_shost_and_ioc(pdev, &shost, &ioc); rc = _scsih_get_shost_and_ioc(pdev, &shost, &ioc);
@ -12072,25 +12070,23 @@ scsih_suspend(struct pci_dev *pdev, pm_message_t state)
flush_scheduled_work(); flush_scheduled_work();
scsi_block_requests(shost); scsi_block_requests(shost);
_scsih_nvme_shutdown(ioc); _scsih_nvme_shutdown(ioc);
device_state = pci_choose_state(pdev, state); ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state\n",
ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n", pdev, pci_name(pdev));
pdev, pci_name(pdev), device_state);
pci_save_state(pdev);
mpt3sas_base_free_resources(ioc); mpt3sas_base_free_resources(ioc);
pci_set_power_state(pdev, device_state);
return 0; return 0;
} }
/** /**
* scsih_resume - power management resume main entry point * scsih_resume - power management resume main entry point
* @pdev: PCI device struct * @dev: Device struct
* *
* Return: 0 success, anything else error. * Return: 0 success, anything else error.
*/ */
static int static int __maybe_unused
scsih_resume(struct pci_dev *pdev) scsih_resume(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *shost; struct Scsi_Host *shost;
struct MPT3SAS_ADAPTER *ioc; struct MPT3SAS_ADAPTER *ioc;
pci_power_t device_state = pdev->current_state; pci_power_t device_state = pdev->current_state;
@ -12103,8 +12099,6 @@ scsih_resume(struct pci_dev *pdev)
ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n", ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
pdev, pci_name(pdev), device_state); pdev, pci_name(pdev), device_state);
pci_set_power_state(pdev, PCI_D0);
pci_restore_state(pdev);
ioc->pdev = pdev; ioc->pdev = pdev;
r = mpt3sas_base_map_resources(ioc); r = mpt3sas_base_map_resources(ioc);
if (r) if (r)
@ -12115,7 +12109,6 @@ scsih_resume(struct pci_dev *pdev)
mpt3sas_base_start_watchdog(ioc); mpt3sas_base_start_watchdog(ioc);
return 0; return 0;
} }
#endif /* CONFIG_PM */
/** /**
* scsih_pci_error_detected - Called when a PCI error is detected. * scsih_pci_error_detected - Called when a PCI error is detected.
@ -12417,6 +12410,8 @@ static struct pci_error_handlers _mpt3sas_err_handler = {
.resume = scsih_pci_resume, .resume = scsih_pci_resume,
}; };
static SIMPLE_DEV_PM_OPS(scsih_pm_ops, scsih_suspend, scsih_resume);
static struct pci_driver mpt3sas_driver = { static struct pci_driver mpt3sas_driver = {
.name = MPT3SAS_DRIVER_NAME, .name = MPT3SAS_DRIVER_NAME,
.id_table = mpt3sas_pci_table, .id_table = mpt3sas_pci_table,
@ -12424,10 +12419,7 @@ static struct pci_driver mpt3sas_driver = {
.remove = scsih_remove, .remove = scsih_remove,
.shutdown = scsih_shutdown, .shutdown = scsih_shutdown,
.err_handler = &_mpt3sas_err_handler, .err_handler = &_mpt3sas_err_handler,
#ifdef CONFIG_PM .driver.pm = &scsih_pm_ops,
.suspend = scsih_suspend,
.resume = scsih_resume,
#endif
}; };
/** /**