Skip to content

Commit 8afb91a

Browse files
oleremkuba-moo
authored andcommitted
net: dsa: microchip: Ensure Stable PME Pin State for Wake-on-LAN
Ensures a stable PME (Power Management Event) pin state by disabling PME on system start and enabling it on shutdown only if WoL (Wake-on-LAN) is configured. This is needed to avoid issues with some PMICs (Power Management ICs). Signed-off-by: Oleksij Rempel <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 77c819c commit 8afb91a

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

drivers/net/dsa/microchip/ksz9477.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,46 @@ int ksz9477_set_wol(struct ksz_device *dev, int port,
197197
return 0;
198198
}
199199

200+
/**
201+
* ksz9477_wol_pre_shutdown - Prepares the switch device for shutdown while
202+
* considering Wake-on-LAN (WoL) settings.
203+
* @dev: The switch device structure.
204+
* @wol_enabled: Pointer to a boolean which will be set to true if WoL is
205+
* enabled on any port.
206+
*
207+
* This function prepares the switch device for a safe shutdown while taking
208+
* into account the Wake-on-LAN (WoL) settings on the user ports. It updates
209+
* the wol_enabled flag accordingly to reflect whether WoL is active on any
210+
* port.
211+
*/
212+
void ksz9477_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled)
213+
{
214+
struct dsa_port *dp;
215+
int ret;
216+
217+
*wol_enabled = false;
218+
219+
if (!dev->wakeup_source)
220+
return;
221+
222+
dsa_switch_for_each_user_port(dp, dev->ds) {
223+
u8 pme_ctrl = 0;
224+
225+
ret = ksz_pread8(dev, dp->index, REG_PORT_PME_CTRL, &pme_ctrl);
226+
if (!ret && pme_ctrl)
227+
*wol_enabled = true;
228+
229+
/* make sure there are no pending wake events which would
230+
* prevent the device from going to sleep/shutdown.
231+
*/
232+
ksz9477_handle_wake_reason(dev, dp->index);
233+
}
234+
235+
/* Now we are save to enable PME pin. */
236+
if (*wol_enabled)
237+
ksz_write8(dev, REG_SW_PME_CTRL, PME_ENABLE);
238+
}
239+
200240
static int ksz9477_wait_vlan_ctrl_ready(struct ksz_device *dev)
201241
{
202242
unsigned int val;
@@ -1277,6 +1317,12 @@ int ksz9477_setup(struct dsa_switch *ds)
12771317
/* enable global MIB counter freeze function */
12781318
ksz_cfg(dev, REG_SW_MAC_CTRL_6, SW_MIB_COUNTER_FREEZE, true);
12791319

1320+
/* Make sure PME (WoL) is not enabled. If requested, it will be
1321+
* enabled by ksz9477_wol_pre_shutdown(). Otherwise, some PMICs do not
1322+
* like PME events changes before shutdown.
1323+
*/
1324+
ksz_write8(dev, REG_SW_PME_CTRL, 0);
1325+
12801326
return 0;
12811327
}
12821328

drivers/net/dsa/microchip/ksz9477.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void ksz9477_get_wol(struct ksz_device *dev, int port,
6262
struct ethtool_wolinfo *wol);
6363
int ksz9477_set_wol(struct ksz_device *dev, int port,
6464
struct ethtool_wolinfo *wol);
65+
void ksz9477_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled);
6566

6667
int ksz9477_port_acl_init(struct ksz_device *dev, int port);
6768
void ksz9477_port_acl_free(struct ksz_device *dev, int port);

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
321321
.phylink_mac_link_up = ksz9477_phylink_mac_link_up,
322322
.get_wol = ksz9477_get_wol,
323323
.set_wol = ksz9477_set_wol,
324+
.wol_pre_shutdown = ksz9477_wol_pre_shutdown,
324325
.config_cpu_port = ksz9477_config_cpu_port,
325326
.tc_cbs_set_cinc = ksz9477_tc_cbs_set_cinc,
326327
.enable_stp_addr = ksz9477_enable_stp_addr,
@@ -3857,7 +3858,12 @@ EXPORT_SYMBOL(ksz_switch_alloc);
38573858
*/
38583859
void ksz_switch_shutdown(struct ksz_device *dev)
38593860
{
3860-
if (dev->dev_ops->reset)
3861+
bool wol_enabled = false;
3862+
3863+
if (dev->dev_ops->wol_pre_shutdown)
3864+
dev->dev_ops->wol_pre_shutdown(dev, &wol_enabled);
3865+
3866+
if (dev->dev_ops->reset && !wol_enabled)
38613867
dev->dev_ops->reset(dev);
38623868

38633869
dsa_switch_shutdown(dev->ds);

drivers/net/dsa/microchip/ksz_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ struct ksz_dev_ops {
378378
struct ethtool_wolinfo *wol);
379379
int (*set_wol)(struct ksz_device *dev, int port,
380380
struct ethtool_wolinfo *wol);
381+
void (*wol_pre_shutdown)(struct ksz_device *dev, bool *wol_enabled);
381382
void (*config_cpu_port)(struct dsa_switch *ds);
382383
int (*enable_stp_addr)(struct ksz_device *dev);
383384
int (*reset)(struct ksz_device *dev);

0 commit comments

Comments
 (0)