netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Justin Lai <justinlai0215@realtek.com>
To: Heiner Kallweit <heiner.kallweit@web.de>,
	"kuba@kernel.org" <kuba@kernel.org>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
	"edumazet@google.com" <edumazet@google.com>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"andrew@lunn.ch" <andrew@lunn.ch>,
	Ping-Ke Shih <pkshih@realtek.com>,
	Larry Chiu <larry.chiu@realtek.com>
Subject: RE: [PATCH net-next v11 09/13] net:ethernet:realtek:rtase: Implement pci_driver suspend and resume function
Date: Tue, 21 Nov 2023 09:30:51 +0000	[thread overview]
Message-ID: <da79c9899e454b80a73ef44d7fdd0135@realtek.com> (raw)
In-Reply-To: <22d15e87-a629-4c4c-a2dc-dcae50822e72@web.de>

> On 15.11.2023 14:34, Justin Lai wrote:
> > 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   | 64 +++++++++++++++++++
> >  1 file changed, 64 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c
> > b/drivers/net/ethernet/realtek/rtase/rtase_main.c
> > index 12607663dd72..b7679b74cc8a 100644
> > --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c
> > +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c
> > @@ -2323,12 +2323,76 @@ 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);
> > +
> 
> IMO this is done by the PCI core already. See other drivers and PCI core code.

Thank you, I will check this part.
> 
> > +     /* restore last modified mac address */
> > +     rtase_rar_set(tp, dev->dev_addr);
> > +
> > +     if (!netif_running(dev))
> > +             goto out;
> > +
> > +     rtase_wait_for_quiescence(dev);
> > +
> > +     rtase_tx_clear(tp);
> > +     rtase_rx_clear(tp);
> > +
> > +     ret = rtase_init_ring(dev);
> > +     if (ret) {
> > +             netdev_err(dev, "unable to init ring\n");
> > +             rtase_free_desc(tp);
> > +             return -ENOMEM;
> > +     }
> > +
> > +     rtase_hw_config(dev);
> > +     /* always link, so start to transmit & receive */
> > +     rtase_hw_start(dev);
> > +
> > +     netif_carrier_on(dev);
> > +     netif_wake_queue(dev);
> > +     netif_device_attach(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,
> 
> Use pm_sleep_ptr and related macros then you don't need the conditional
> compiling.

Thanks for your suggestion, I will modify this driver.
> 
> > +#endif
> >  };
> >
> >  module_pci_driver(rtase_pci_driver);


  reply	other threads:[~2023-11-21  9:31 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-15 13:34 [PATCH net-next v11 00/13] Add Realtek automotive PCIe driver Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 01/13] net:ethernet:realtek:rtase: Add pci table supported in this module Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 02/13] net:ethernet:realtek:rtase: Implement the .ndo_open function Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 03/13] net:ethernet:realtek:rtase: Implement the rtase_down function Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 04/13] net:ethernet:realtek:rtase: Implement the interrupt routine and rtase_poll Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 05/13] net:ethernet:realtek:rtase: Implement hardware configuration function Justin Lai
2023-11-15 15:02   ` Heiner Kallweit
2023-11-21 11:54     ` Justin Lai
2023-11-16 18:06   ` Simon Horman
2023-11-23  3:48     ` Justin Lai
2023-11-18 22:50   ` Jakub Kicinski
2023-11-20 13:22     ` Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 06/13] net:ethernet:realtek:rtase: Implement .ndo_start_xmit function Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 07/13] net:ethernet:realtek:rtase: Implement a function to receive packets Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 08/13] net:ethernet:realtek:rtase: Implement net_device_ops Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 09/13] net:ethernet:realtek:rtase: Implement pci_driver suspend and resume function Justin Lai
2023-11-15 15:02   ` Heiner Kallweit
2023-11-21  9:30     ` Justin Lai [this message]
2023-11-15 13:34 ` [PATCH net-next v11 10/13] net:ethernet:realtek:rtase: Implement ethtool function Justin Lai
2023-11-15 15:02   ` Heiner Kallweit
2023-11-23  3:16     ` Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 11/13] net:ethernet:realtek:rtase: Add a Makefile in the rtase folder Justin Lai
2023-11-15 13:34 ` [PATCH net-next v11 12/13] net:ethernet:realtek: Update the Makefile and Kconfig in the realtek folder Justin Lai
2023-11-15 19:58   ` kernel test robot
2023-11-21 10:00   ` kernel test robot
2023-11-15 13:34 ` [PATCH net-next v11 13/13] MAINTAINERS: Add the rtase ethernet driver entry Justin Lai
2023-11-16 17:57 ` [PATCH net-next v11 00/13] Add Realtek automotive PCIe driver Simon Horman
2023-11-21  9:35   ` Justin Lai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=da79c9899e454b80a73ef44d7fdd0135@realtek.com \
    --to=justinlai0215@realtek.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=heiner.kallweit@web.de \
    --cc=kuba@kernel.org \
    --cc=larry.chiu@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pkshih@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).