amd-xgbe: Simplify powerdown/powerup paths

The caller parameter in xgbe_powerdown() and xgbe_powerup() was intended
to differentiate between driver and ioctl contexts, but the only
remaining usage is from the driver suspend/resume path.

Simplify this by:
- Removing the unused XGMAC_DRIVER_CONTEXT and XGMAC_IOCTL_CONTEXT
  macros
- Dropping the now-unused caller parameter
- Reordering operations in xgbe_powerdown() to disable NAPI before
  stopping TX/RX, matching the order used in xgbe_stop()

This makes the powerdown/powerup paths easier to follow and keeps the
ordering consistent with the rest of the driver.

Signed-off-by: Raju Rangoju <Raju.Rangoju@amd.com>
Link: https://patch.msgid.link/20260308092851.1510214-2-Raju.Rangoju@amd.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Raju Rangoju 2026-03-08 14:58:50 +05:30 committed by Jakub Kicinski
parent 34bd3c6b0b
commit fe81629217
4 changed files with 32 additions and 43 deletions

View File

@ -1116,69 +1116,62 @@ static int xgbe_phy_reset(struct xgbe_prv_data *pdata)
return pdata->phy_if.phy_reset(pdata);
}
int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
int xgbe_powerdown(struct net_device *netdev)
{
struct xgbe_prv_data *pdata = netdev_priv(netdev);
struct xgbe_hw_if *hw_if = &pdata->hw_if;
DBGPR("-->xgbe_powerdown\n");
if (!netif_running(netdev) ||
(caller == XGMAC_IOCTL_CONTEXT && pdata->power_down)) {
netdev_alert(netdev, "Device is already powered down\n");
DBGPR("<--xgbe_powerdown\n");
if (!netif_running(netdev)) {
netdev_dbg(netdev, "Device is not running, skipping powerdown\n");
return -EINVAL;
}
if (caller == XGMAC_DRIVER_CONTEXT)
netif_device_detach(netdev);
if (pdata->power_down) {
netdev_dbg(netdev, "Device is already powered down\n");
return -EINVAL;
}
netif_device_detach(netdev);
netif_tx_stop_all_queues(netdev);
xgbe_stop_timers(pdata);
flush_workqueue(pdata->dev_workqueue);
xgbe_napi_disable(pdata, 0);
hw_if->powerdown_tx(pdata);
hw_if->powerdown_rx(pdata);
xgbe_napi_disable(pdata, 0);
pdata->power_down = 1;
DBGPR("<--xgbe_powerdown\n");
return 0;
}
int xgbe_powerup(struct net_device *netdev, unsigned int caller)
int xgbe_powerup(struct net_device *netdev)
{
struct xgbe_prv_data *pdata = netdev_priv(netdev);
struct xgbe_hw_if *hw_if = &pdata->hw_if;
DBGPR("-->xgbe_powerup\n");
if (!netif_running(netdev) ||
(caller == XGMAC_IOCTL_CONTEXT && !pdata->power_down)) {
netdev_alert(netdev, "Device is already powered up\n");
DBGPR("<--xgbe_powerup\n");
if (!netif_running(netdev)) {
netdev_dbg(netdev, "Device is not running, skipping powerup\n");
return -EINVAL;
}
pdata->power_down = 0;
xgbe_napi_enable(pdata, 0);
if (!pdata->power_down) {
netdev_dbg(netdev, "Device is already powered up\n");
return -EINVAL;
}
hw_if->powerup_tx(pdata);
hw_if->powerup_rx(pdata);
if (caller == XGMAC_DRIVER_CONTEXT)
netif_device_attach(netdev);
xgbe_napi_enable(pdata, 0);
netif_tx_start_all_queues(netdev);
xgbe_start_timers(pdata);
netif_device_attach(netdev);
DBGPR("<--xgbe_powerup\n");
pdata->power_down = 0;
return 0;
}

View File

@ -360,14 +360,14 @@ static void xgbe_pci_remove(struct pci_dev *pdev)
xgbe_free_pdata(pdata);
}
static int __maybe_unused xgbe_pci_suspend(struct device *dev)
static int xgbe_pci_suspend(struct device *dev)
{
struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
struct net_device *netdev = pdata->netdev;
int ret = 0;
if (netif_running(netdev))
ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT);
ret = xgbe_powerdown(netdev);
pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER;
@ -376,7 +376,7 @@ static int __maybe_unused xgbe_pci_suspend(struct device *dev)
return ret;
}
static int __maybe_unused xgbe_pci_resume(struct device *dev)
static int xgbe_pci_resume(struct device *dev)
{
struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
struct net_device *netdev = pdata->netdev;
@ -388,7 +388,7 @@ static int __maybe_unused xgbe_pci_resume(struct device *dev)
XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
if (netif_running(netdev)) {
ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT);
ret = xgbe_powerup(netdev);
/* Schedule a restart in case the link or phy state changed
* while we were powered down.
@ -461,16 +461,16 @@ static const struct pci_device_id xgbe_pci_table[] = {
};
MODULE_DEVICE_TABLE(pci, xgbe_pci_table);
static SIMPLE_DEV_PM_OPS(xgbe_pci_pm_ops, xgbe_pci_suspend, xgbe_pci_resume);
static DEFINE_SIMPLE_DEV_PM_OPS(xgbe_pci_pm_ops,
xgbe_pci_suspend,
xgbe_pci_resume);
static struct pci_driver xgbe_driver = {
.name = XGBE_DRV_NAME,
.id_table = xgbe_pci_table,
.probe = xgbe_pci_probe,
.remove = xgbe_pci_remove,
.driver = {
.pm = &xgbe_pci_pm_ops,
}
.driver.pm = pm_sleep_ptr(&xgbe_pci_pm_ops),
};
int xgbe_pci_init(void)

View File

@ -384,7 +384,7 @@ static int xgbe_platform_suspend(struct device *dev)
DBGPR("-->xgbe_suspend\n");
if (netif_running(netdev))
ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT);
ret = xgbe_powerdown(netdev);
pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER;
@ -407,7 +407,7 @@ static int xgbe_platform_resume(struct device *dev)
XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
if (netif_running(netdev)) {
ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT);
ret = xgbe_powerup(netdev);
/* Schedule a restart in case the link or phy state changed
* while we were powered down.

View File

@ -146,10 +146,6 @@
#define XGBE_MAX_PPS_OUT 4
#define XGBE_MAX_AUX_SNAP 4
/* Driver PMT macros */
#define XGMAC_DRIVER_CONTEXT 1
#define XGMAC_IOCTL_CONTEXT 2
#define XGMAC_FIFO_MIN_ALLOC 2048
#define XGMAC_FIFO_UNIT 256
#define XGMAC_FIFO_ALIGN(_x) \
@ -1309,8 +1305,8 @@ void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
unsigned int);
void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
void xgbe_get_all_hw_features(struct xgbe_prv_data *);
int xgbe_powerup(struct net_device *, unsigned int);
int xgbe_powerdown(struct net_device *, unsigned int);
int xgbe_powerup(struct net_device *netdev);
int xgbe_powerdown(struct net_device *netdev);
void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
void xgbe_restart_dev(struct xgbe_prv_data *pdata);