Skip to content

Commit 67800d2

Browse files
Csókás, BencePaolo Abeni
authored andcommitted
net: fec: Refactor MAC reset to function
The core is reset both in `fec_restart()` (called on link-up) and `fec_stop()` (going to sleep, driver remove etc.). These two functions had their separate implementations, which was at first only a register write and a `udelay()` (and the accompanying block comment). However, since then we got soft-reset (MAC disable) and Wake-on-LAN support, which meant that these implementations diverged, often causing bugs. For instance, as of now, `fec_stop()` does not check for `FEC_QUIRK_NO_HARD_RESET`, meaning the MII/RMII mode is cleared on eg. a PM power-down event; and `fec_restart()` missed the refactor renaming the "magic" constant `1` to `FEC_ECR_RESET`. To harmonize current implementations, and eliminate this source of potential future bugs, refactor implementation to a common function. Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu> Link: https://patch.msgid.link/20250207121255.161146-2-csokas.bence@prolan.hu Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 907dd32 commit 67800d2

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,29 @@ static void fec_enet_enable_ring(struct net_device *ndev)
10931093
}
10941094
}
10951095

1096+
/* Whack a reset. We should wait for this.
1097+
* For i.MX6SX SOC, enet use AXI bus, we use disable MAC
1098+
* instead of reset MAC itself.
1099+
*/
1100+
static void fec_ctrl_reset(struct fec_enet_private *fep, bool allow_wol)
1101+
{
1102+
u32 val;
1103+
1104+
if (!allow_wol || !(fep->wol_flag & FEC_WOL_FLAG_SLEEP_ON)) {
1105+
if (fep->quirks & FEC_QUIRK_HAS_MULTI_QUEUES ||
1106+
((fep->quirks & FEC_QUIRK_NO_HARD_RESET) && fep->link)) {
1107+
writel(0, fep->hwp + FEC_ECNTRL);
1108+
} else {
1109+
writel(FEC_ECR_RESET, fep->hwp + FEC_ECNTRL);
1110+
udelay(10);
1111+
}
1112+
} else {
1113+
val = readl(fep->hwp + FEC_ECNTRL);
1114+
val |= (FEC_ECR_MAGICEN | FEC_ECR_SLEEP);
1115+
writel(val, fep->hwp + FEC_ECNTRL);
1116+
}
1117+
}
1118+
10961119
/*
10971120
* This function is called to start or restart the FEC during a link
10981121
* change, transmit timeout, or to reconfigure the FEC. The network
@@ -1109,17 +1132,7 @@ fec_restart(struct net_device *ndev)
11091132
if (fep->bufdesc_ex)
11101133
fec_ptp_save_state(fep);
11111134

1112-
/* Whack a reset. We should wait for this.
1113-
* For i.MX6SX SOC, enet use AXI bus, we use disable MAC
1114-
* instead of reset MAC itself.
1115-
*/
1116-
if (fep->quirks & FEC_QUIRK_HAS_MULTI_QUEUES ||
1117-
((fep->quirks & FEC_QUIRK_NO_HARD_RESET) && fep->link)) {
1118-
writel(0, fep->hwp + FEC_ECNTRL);
1119-
} else {
1120-
writel(1, fep->hwp + FEC_ECNTRL);
1121-
udelay(10);
1122-
}
1135+
fec_ctrl_reset(fep, false);
11231136

11241137
/*
11251138
* enet-mac reset will reset mac address registers too,
@@ -1373,22 +1386,7 @@ fec_stop(struct net_device *ndev)
13731386
if (fep->bufdesc_ex)
13741387
fec_ptp_save_state(fep);
13751388

1376-
/* Whack a reset. We should wait for this.
1377-
* For i.MX6SX SOC, enet use AXI bus, we use disable MAC
1378-
* instead of reset MAC itself.
1379-
*/
1380-
if (!(fep->wol_flag & FEC_WOL_FLAG_SLEEP_ON)) {
1381-
if (fep->quirks & FEC_QUIRK_HAS_MULTI_QUEUES) {
1382-
writel(0, fep->hwp + FEC_ECNTRL);
1383-
} else {
1384-
writel(FEC_ECR_RESET, fep->hwp + FEC_ECNTRL);
1385-
udelay(10);
1386-
}
1387-
} else {
1388-
val = readl(fep->hwp + FEC_ECNTRL);
1389-
val |= (FEC_ECR_MAGICEN | FEC_ECR_SLEEP);
1390-
writel(val, fep->hwp + FEC_ECNTRL);
1391-
}
1389+
fec_ctrl_reset(fep, true);
13921390
writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
13931391
writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
13941392

0 commit comments

Comments
 (0)