mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Sae <Frank.Sae@motor-comm.com>
To: Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Frank <Frank.Sae@motor-comm.com>,
	netdev@vger.kernel.org
Cc: Masahiro Yamada <masahiroy@kernel.org>,
	Parthiban.Veerasooran@microchip.com,
	linux-kernel@vger.kernel.org,
	"andrew+netdev @ lunn . ch" <andrew+netdev@lunn.ch>,
	lee@trager.us, horms@kernel.org, linux-doc@vger.kernel.org,
	corbet@lwn.net, geert+renesas@glider.be,
	xiaogang.fan@motor-comm.com, fei.zhang@motor-comm.com,
	hua.sun@motor-comm.com
Subject: [PATCH net-next v4 12/14] yt6801: Implement pci_driver suspend and resume
Date: Tue,  8 Apr 2025 17:28:33 +0800	[thread overview]
Message-ID: <20250408092835.3952-13-Frank.Sae@motor-comm.com> (raw)
In-Reply-To: <20250408092835.3952-1-Frank.Sae@motor-comm.com>

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: Frank Sae <Frank.Sae@motor-comm.com>
---
 .../ethernet/motorcomm/yt6801/yt6801_main.c   | 73 +++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/drivers/net/ethernet/motorcomm/yt6801/yt6801_main.c b/drivers/net/ethernet/motorcomm/yt6801/yt6801_main.c
index 6523fe4de..67ff71f80 100644
--- a/drivers/net/ethernet/motorcomm/yt6801/yt6801_main.c
+++ b/drivers/net/ethernet/motorcomm/yt6801/yt6801_main.c
@@ -17,7 +17,11 @@
  *  ********************||******************* **
  */
 
+#include <linux/if_vlan.h>
 #include <linux/module.h>
+#include <linux/phy.h>
+#include <linux/tcp.h>
+
 #include "yt6801_type.h"
 #include "yt6801_desc.h"
 
@@ -1380,6 +1384,21 @@ static void fxgmac_restart_work(struct work_struct *work)
 	fxgmac_restart(container_of(work, struct fxgmac_pdata, restart_work));
 	rtnl_unlock();
 }
+
+static int fxgmac_net_powerup(struct fxgmac_pdata *priv)
+{
+	int ret;
+
+	priv->power_state = 0;/* clear all bits as normal now */
+	ret = fxgmac_start(priv);
+	if (ret < 0) {
+		dev_err(priv->dev, "fxgmac start failed:%d.\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 static void fxgmac_config_powerdown(struct fxgmac_pdata *priv)
 {
 	fxgmac_io_wr_bits(priv, MAC_CR, MAC_CR_RE, 1); /* Enable MAC Rx */
@@ -2908,6 +2927,55 @@ static void fxgmac_shutdown(struct pci_dev *pcidev)
 	}
 	rtnl_unlock();
 }
+
+static int fxgmac_suspend(struct device *device)
+{
+	struct fxgmac_pdata *priv = dev_get_drvdata(device);
+	struct net_device *ndev = priv->ndev;
+
+	rtnl_lock();
+	if (priv->dev_state != FXGMAC_DEV_START)
+		goto unlock;
+
+	if (netif_running(ndev))
+		__fxgmac_shutdown(to_pci_dev(device));
+
+	priv->dev_state = FXGMAC_DEV_SUSPEND;
+unlock:
+	rtnl_unlock();
+
+	return 0;
+}
+
+static int fxgmac_resume(struct device *device)
+{
+	struct fxgmac_pdata *priv = dev_get_drvdata(device);
+	struct net_device *ndev = priv->ndev;
+	int ret = 0;
+
+	rtnl_lock();
+	if (priv->dev_state != FXGMAC_DEV_SUSPEND)
+		goto unlock;
+
+	priv->dev_state = FXGMAC_DEV_RESUME;
+	__clear_bit(FXGMAC_POWER_STATE_DOWN, &priv->power_state);
+	rtnl_lock();
+	if (netif_running(ndev)) {
+		ret = fxgmac_net_powerup(priv);
+		if (ret < 0) {
+			netdev_err(priv->ndev, "%s, fxgmac net powerup failed:%d\n",
+				   __func__, ret);
+			goto unlock;
+		}
+	}
+
+	netif_device_attach(ndev);
+unlock:
+	rtnl_unlock();
+
+	return ret;
+}
+
 #define MOTORCOMM_PCI_ID			0x1f0a
 #define YT6801_PCI_DEVICE_ID			0x6801
 
@@ -2918,11 +2986,16 @@ static const struct pci_device_id fxgmac_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, fxgmac_pci_tbl);
 
+static const struct dev_pm_ops fxgmac_pm_ops = {
+	SYSTEM_SLEEP_PM_OPS(fxgmac_suspend, fxgmac_resume)
+};
+
 static struct pci_driver fxgmac_pci_driver = {
 	.name		= FXGMAC_DRV_NAME,
 	.id_table	= fxgmac_pci_tbl,
 	.probe		= fxgmac_probe,
 	.remove		= fxgmac_remove,
+	.driver.pm	= pm_ptr(&fxgmac_pm_ops),
 	.shutdown	= fxgmac_shutdown,
 };
 
-- 
2.34.1


  parent reply	other threads:[~2025-04-08  9:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08  9:28 [PATCH net-next v4 00/14] yt6801: Add Motorcomm yt6801 PCIe driver Frank Sae
2025-04-08  9:28 ` [PATCH net-next v4 01/14] yt6801: Add support for a pci table in this module Frank Sae
2025-04-14  9:19   ` Philipp Stanner
2025-04-08  9:28 ` [PATCH net-next v4 02/14] yt6801: Implement mdio register Frank Sae
2025-04-08  9:28 ` [PATCH net-next v4 03/14] yt6801: Implement pci_driver shutdown Frank Sae
2025-04-08  9:28 ` [PATCH net-next v4 07/14] net:phy:motorcomm: Add PHY_INTERFACE_MODE_INTERNAL to support YT6801 Frank Sae
2025-04-08 13:11   ` Andrew Lunn
2025-04-08  9:28 ` [PATCH net-next v4 08/14] yt6801: Implement the fxgmac_hw_init function Frank Sae
2025-04-08  9:28 ` Frank Sae [this message]
2025-04-08  9:28 ` [PATCH net-next v4 14/14] yt6801: update ethernet documentation and maintainer Frank Sae
2025-04-15  3:13   ` Yanteng Si
2025-04-08 10:14 ` [PATCH net-next v4 04/14] yt6801: Implement the fxgmac_init function Frank Sae
2025-04-08 10:14 ` [PATCH net-next v4 05/14] yt6801: Implement the .ndo_open function Frank Sae
2025-04-08 10:14 ` [PATCH net-next v4 06/14] yt6801: Implement the fxgmac_start function Frank Sae
2025-04-08 10:14 ` [PATCH net-next v4 09/14] yt6801: Implement the poll functions Frank Sae
2025-04-08 10:14 ` [PATCH net-next v4 10/14] yt6801: Implement .ndo_start_xmit function Frank Sae
2025-04-08 10:15 ` [PATCH net-next v4 11/14] yt6801: Implement some net_device_ops function Frank Sae
2025-04-08 10:30 ` [PATCH net-next v4 00/14] yt6801: Add Motorcomm yt6801 PCIe driver Russell King (Oracle)
2025-04-11  9:50   ` Frank Sae
2025-04-11 12:10     ` Russell King (Oracle)
2025-04-13 20:33     ` Andrew Lunn
2025-04-17  6:06       ` Frank Sae
2025-04-17 10:10         ` Russell King (Oracle)
2025-09-09 13:49         ` Shengyu Qu

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=20250408092835.3952-13-Frank.Sae@motor-comm.com \
    --to=frank.sae@motor-comm.com \
    --cc=Parthiban.Veerasooran@microchip.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fei.zhang@motor-comm.com \
    --cc=geert+renesas@glider.be \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=hua.sun@motor-comm.com \
    --cc=kuba@kernel.org \
    --cc=lee@trager.us \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=masahiroy@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=xiaogang.fan@motor-comm.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

all inboxes | Powered by JetHome®