Message ID | 20231102154505.940783-10-justinlai0215@realtek.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Add Realtek automotive PCIe driver | expand |
> +static int rtase_resume(struct pci_dev *pdev) > +{ > + struct net_device *dev = pci_get_drvdata(pdev); > + struct rtase_private *tp = netdev_priv(dev); > + int ret; > + > + pci_set_power_state(pdev, PCI_D0); > + pci_restore_state(pdev); > + pci_enable_wake(pdev, PCI_D0, 0); > + > + /* restore last modified mac address */ > + rtase_rar_set(tp, dev->dev_addr); > + > + if (!netif_running(dev)) > + goto out; > + > + rtase_wait_for_quiescence(dev); > + netif_device_attach(dev); > + > + rtase_tx_clear(tp); > + rtase_rx_clear(tp); > + > + ret = rtase_init_ring(dev); > + if (ret) > + netdev_alert(dev, "unable to init ring\n"); If you fail to init the ring, is it safe to keep going? Andrew
> -----Original Message----- > From: Andrew Lunn <andrew@lunn.ch> > Sent: Sunday, November 5, 2023 3:52 AM > To: Justin Lai <justinlai0215@realtek.com> > Cc: kuba@kernel.org; davem@davemloft.net; edumazet@google.com; > pabeni@redhat.com; linux-kernel@vger.kernel.org; netdev@vger.kernel.org; > Ping-Ke Shih <pkshih@realtek.com>; Larry Chiu <larry.chiu@realtek.com> > Subject: Re: [PATCH net-next v10 09/13] net:ethernet:realtek:rtase: Implement > pci_driver suspend and resume function > > > External mail. > > > > > +static int rtase_resume(struct pci_dev *pdev) { > > + struct net_device *dev = pci_get_drvdata(pdev); > > + struct rtase_private *tp = netdev_priv(dev); > > + int ret; > > + > > + pci_set_power_state(pdev, PCI_D0); > > + pci_restore_state(pdev); > > + pci_enable_wake(pdev, PCI_D0, 0); > > + > > + /* restore last modified mac address */ > > + rtase_rar_set(tp, dev->dev_addr); > > + > > + if (!netif_running(dev)) > > + goto out; > > + > > + rtase_wait_for_quiescence(dev); > > + netif_device_attach(dev); > > + > > + rtase_tx_clear(tp); > > + rtase_rx_clear(tp); > > + > > + ret = rtase_init_ring(dev); > > + if (ret) > > + netdev_alert(dev, "unable to init ring\n"); > > If you fail to init the ring, is it safe to keep going? > > Andrew Thanks for your reply, I will add error handling of rtase_init_ring()
diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c index feae944bc5c0..829f6df163e9 100644 --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c @@ -2325,12 +2325,73 @@ static void rtase_shutdown(struct pci_dev *pdev) rtase_reset_interrupt(pdev, tp); } +#ifdef CONFIG_PM +static int rtase_suspend(struct pci_dev *pdev, pm_message_t state) +{ + struct net_device *dev = pci_get_drvdata(pdev); + + if (!netif_running(dev)) + goto out; + + netif_stop_queue(dev); + netif_carrier_off(dev); + netif_device_detach(dev); + rtase_hw_reset(dev); + +out: + pci_save_state(pdev); + + return 0; +} + +static int rtase_resume(struct pci_dev *pdev) +{ + struct net_device *dev = pci_get_drvdata(pdev); + struct rtase_private *tp = netdev_priv(dev); + int ret; + + pci_set_power_state(pdev, PCI_D0); + pci_restore_state(pdev); + pci_enable_wake(pdev, PCI_D0, 0); + + /* restore last modified mac address */ + rtase_rar_set(tp, dev->dev_addr); + + if (!netif_running(dev)) + goto out; + + rtase_wait_for_quiescence(dev); + netif_device_attach(dev); + + rtase_tx_clear(tp); + rtase_rx_clear(tp); + + ret = rtase_init_ring(dev); + if (ret) + netdev_alert(dev, "unable to init ring\n"); + + rtase_hw_config(dev); + /* always link, so start to transmit & receive */ + rtase_hw_start(dev); + + netif_carrier_on(dev); + netif_wake_queue(dev); + +out: + return 0; +} +#endif /* CONFIG_PM */ + static struct pci_driver rtase_pci_driver = { .name = KBUILD_MODNAME, .id_table = rtase_pci_tbl, .probe = rtase_init_one, .remove = rtase_remove_one, .shutdown = rtase_shutdown, +#ifdef CONFIG_PM + .suspend = rtase_suspend, + .resume = rtase_resume, +#endif }; module_pci_driver(rtase_pci_driver);
Implement the pci_driver suspend function to enable the device to sleep, and implement the resume function to enable the device to resume operation. Signed-off-by: Justin Lai <justinlai0215@realtek.com> --- .../net/ethernet/realtek/rtase/rtase_main.c | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+)