Commit 99769d8d authored by Vaibhav Gupta's avatar Vaibhav Gupta Committed by Martin K. Petersen

scsi: 3w-sas: 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-25-vaibhavgupta40@gmail.comSigned-off-by: default avatarVaibhav Gupta <vaibhavgupta40@gmail.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 7ea03ab7
...@@ -1756,11 +1756,10 @@ static void twl_remove(struct pci_dev *pdev) ...@@ -1756,11 +1756,10 @@ static void twl_remove(struct pci_dev *pdev)
twl_device_extension_count--; twl_device_extension_count--;
} /* End twl_remove() */ } /* End twl_remove() */
#ifdef CONFIG_PM
/* This function is called on PCI suspend */ /* This function is called on PCI suspend */
static int twl_suspend(struct pci_dev *pdev, pm_message_t state) static int __maybe_unused twl_suspend(struct device *dev)
{ {
struct Scsi_Host *host = pci_get_drvdata(pdev); struct Scsi_Host *host = dev_get_drvdata(dev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
printk(KERN_WARNING "3w-sas: Suspending host %d.\n", tw_dev->host->host_no); printk(KERN_WARNING "3w-sas: Suspending host %d.\n", tw_dev->host->host_no);
...@@ -1779,31 +1778,18 @@ static int twl_suspend(struct pci_dev *pdev, pm_message_t state) ...@@ -1779,31 +1778,18 @@ static int twl_suspend(struct pci_dev *pdev, pm_message_t state)
/* Clear doorbell interrupt */ /* Clear doorbell interrupt */
TWL_CLEAR_DB_INTERRUPT(tw_dev); TWL_CLEAR_DB_INTERRUPT(tw_dev);
pci_save_state(pdev);
pci_disable_device(pdev);
pci_set_power_state(pdev, pci_choose_state(pdev, state));
return 0; return 0;
} /* End twl_suspend() */ } /* End twl_suspend() */
/* This function is called on PCI resume */ /* This function is called on PCI resume */
static int twl_resume(struct pci_dev *pdev) static int __maybe_unused twl_resume(struct device *dev)
{ {
int retval = 0; int retval = 0;
struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev); struct Scsi_Host *host = pci_get_drvdata(pdev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
printk(KERN_WARNING "3w-sas: Resuming host %d.\n", tw_dev->host->host_no); printk(KERN_WARNING "3w-sas: Resuming host %d.\n", tw_dev->host->host_no);
pci_set_power_state(pdev, PCI_D0);
pci_restore_state(pdev);
retval = pci_enable_device(pdev);
if (retval) {
TW_PRINTK(tw_dev->host, TW_DRIVER, 0x24, "Enable device failed during resume");
return retval;
}
pci_set_master(pdev);
pci_try_set_mwi(pdev); pci_try_set_mwi(pdev);
retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
...@@ -1841,11 +1827,9 @@ static int twl_resume(struct pci_dev *pdev) ...@@ -1841,11 +1827,9 @@ static int twl_resume(struct pci_dev *pdev)
out_disable_device: out_disable_device:
scsi_remove_host(host); scsi_remove_host(host);
pci_disable_device(pdev);
return retval; return retval;
} /* End twl_resume() */ } /* End twl_resume() */
#endif
/* PCI Devices supported by this driver */ /* PCI Devices supported by this driver */
static struct pci_device_id twl_pci_tbl[] = { static struct pci_device_id twl_pci_tbl[] = {
...@@ -1854,16 +1838,15 @@ static struct pci_device_id twl_pci_tbl[] = { ...@@ -1854,16 +1838,15 @@ static struct pci_device_id twl_pci_tbl[] = {
}; };
MODULE_DEVICE_TABLE(pci, twl_pci_tbl); MODULE_DEVICE_TABLE(pci, twl_pci_tbl);
static SIMPLE_DEV_PM_OPS(twl_pm_ops, twl_suspend, twl_resume);
/* pci_driver initializer */ /* pci_driver initializer */
static struct pci_driver twl_driver = { static struct pci_driver twl_driver = {
.name = "3w-sas", .name = "3w-sas",
.id_table = twl_pci_tbl, .id_table = twl_pci_tbl,
.probe = twl_probe, .probe = twl_probe,
.remove = twl_remove, .remove = twl_remove,
#ifdef CONFIG_PM .driver.pm = &twl_pm_ops,
.suspend = twl_suspend,
.resume = twl_resume,
#endif
.shutdown = twl_shutdown .shutdown = twl_shutdown
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment