aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
diff options
context:
space:
mode:
authorVaibhav Gupta <vaibhavgupta40@gmail.com>2020-07-02 22:31:42 +0530
committerDavid S. Miller <davem@davemloft.net>2020-07-04 18:02:06 -0700
commit063ad9bcc297c1f4cfd3a35a6a709b3fd52031f3 (patch)
tree36b3ecdf511cf5e5fe1f36e860d321484857f31d /drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
parentnet: dsa: microchip: remove unused private members (diff)
downloadlinux-dev-063ad9bcc297c1f4cfd3a35a6a709b3fd52031f3.tar.xz
linux-dev-063ad9bcc297c1f4cfd3a35a6a709b3fd52031f3.zip
netxen_nic: use generic power management
With legacy PM, drivers themselves were responsible for managing the device's power states and takes care of register states. And they use PCI helper functions to do it. After upgrading to the generic structure, PCI core will take care of required tasks and drivers should do only device-specific operations. In this driver: netxen_nic_resume() calls netxen_nic_attach_func() which then invokes PCI helper functions like pci_enable_device(), pci_set_power_state() and pci_restore_state(). Other function: - netxen_io_slot_reset() also calls netxen_nic_attach_func(). Also, netxen_io_slot_reset() returns specific value based on the return value of netxen_nic_attach_func() as whole. Thus, cannot simply move some piece of code from netxen_nic_attach_func() to it. Hence, define a new function netxen_nic_attach_late_func() to do the tasks which has to be done after PCI helper functions have done their job. Now, netxen_nic_attach_func() invokes netxen_nic_attach_late_func(), thus netxen_io_slot_reset() behaves normally. And, netxen_nic_resume() calls netxen_nic_attach_late_func() to avoid PCI helper functions calls. Compile-tested only. Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c')
-rw-r--r--drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c59
1 files changed, 28 insertions, 31 deletions
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
index 8067ea04d455..f21847739ef1 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
@@ -1695,19 +1695,13 @@ static void netxen_nic_detach_func(struct netxen_adapter *adapter)
clear_bit(__NX_RESETTING, &adapter->state);
}
-static int netxen_nic_attach_func(struct pci_dev *pdev)
+static int netxen_nic_attach_late_func(struct pci_dev *pdev)
{
struct netxen_adapter *adapter = pci_get_drvdata(pdev);
struct net_device *netdev = adapter->netdev;
int err;
- err = pci_enable_device(pdev);
- if (err)
- return err;
-
- pci_set_power_state(pdev, PCI_D0);
pci_set_master(pdev);
- pci_restore_state(pdev);
adapter->ahw.crb_win = -1;
adapter->ahw.ocm_win = -1;
@@ -1741,6 +1735,20 @@ err_out:
return err;
}
+static int netxen_nic_attach_func(struct pci_dev *pdev)
+{
+ int err;
+
+ err = pci_enable_device(pdev);
+ if (err)
+ return err;
+
+ pci_set_power_state(pdev, PCI_D0);
+ pci_restore_state(pdev);
+
+ return netxen_nic_attach_late_func(pdev);
+}
+
static pci_ers_result_t netxen_io_error_detected(struct pci_dev *pdev,
pci_channel_state_t state)
{
@@ -1785,36 +1793,24 @@ static void netxen_nic_shutdown(struct pci_dev *pdev)
pci_disable_device(pdev);
}
-#ifdef CONFIG_PM
-static int
-netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused
+netxen_nic_suspend(struct device *dev_d)
{
- struct netxen_adapter *adapter = pci_get_drvdata(pdev);
- int retval;
+ struct netxen_adapter *adapter = dev_get_drvdata(dev_d);
netxen_nic_detach_func(adapter);
- retval = pci_save_state(pdev);
- if (retval)
- return retval;
-
- if (netxen_nic_wol_supported(adapter)) {
- pci_enable_wake(pdev, PCI_D3cold, 1);
- pci_enable_wake(pdev, PCI_D3hot, 1);
- }
-
- pci_disable_device(pdev);
- pci_set_power_state(pdev, pci_choose_state(pdev, state));
+ if (netxen_nic_wol_supported(adapter))
+ device_wakeup_enable(dev_d);
return 0;
}
-static int
-netxen_nic_resume(struct pci_dev *pdev)
+static int __maybe_unused
+netxen_nic_resume(struct device *dev_d)
{
- return netxen_nic_attach_func(pdev);
+ return netxen_nic_attach_late_func(to_pci_dev(dev_d));
}
-#endif
static int netxen_nic_open(struct net_device *netdev)
{
@@ -3448,15 +3444,16 @@ static const struct pci_error_handlers netxen_err_handler = {
.slot_reset = netxen_io_slot_reset,
};
+static SIMPLE_DEV_PM_OPS(netxen_nic_pm_ops,
+ netxen_nic_suspend,
+ netxen_nic_resume);
+
static struct pci_driver netxen_driver = {
.name = netxen_nic_driver_name,
.id_table = netxen_pci_tbl,
.probe = netxen_nic_probe,
.remove = netxen_nic_remove,
-#ifdef CONFIG_PM
- .suspend = netxen_nic_suspend,
- .resume = netxen_nic_resume,
-#endif
+ .driver.pm = &netxen_nic_pm_ops,
.shutdown = netxen_nic_shutdown,
.err_handler = &netxen_err_handler
};