* [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups
@ 2026-03-05 10:42 Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables Russell King (Oracle)
` (9 more replies)
0 siblings, 10 replies; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:42 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Hi,
The first four patches clean up the MDC clock divisor selection code,
turning the three different ways we choose a divisor into tabular form,
rather than doing the selection purely in code.
Convert MDIO to use field_prep() which allows a non-constant mask to be
used when preparing fields.
Then use u32 and the associated typed GENMASK for MDIO register field
definitions.
Finally, an extra couple of patches that use appropriate types in
struct mdio_bus_data.
v2:
- add comments about 300MHz to commit message in patch 1
- fix incorrect usage of stmmac_sun8i_csr_to_mdc in patch 3
- fix BIT_u32()->BIT_U32() in patch 8
drivers/net/ethernet/stmicro/stmmac/common.h | 10 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 +--
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 9 +-
.../net/ethernet/stmicro/stmmac/dwmac1000_core.c | 9 +-
.../net/ethernet/stmicro/stmmac/dwmac100_core.c | 9 +-
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 9 +-
.../net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 18 ++--
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 106 ++++++++++++---------
include/linux/stmmac.h | 6 +-
10 files changed, 92 insertions(+), 97 deletions(-)
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH net-next v2 1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
@ 2026-03-05 10:42 ` Russell King (Oracle)
2026-03-05 12:11 ` Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 2/8] net: stmmac: mdio: use same test for MDC clock divisor lookups Russell King (Oracle)
` (8 subsequent siblings)
9 siblings, 1 reply; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:42 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Convert the MDC clock divisor selection to tabular format.
Note that there is a change for 300MHz, but this is not a problem,
as the MDC clock remains within the useable ranges, which are:
STMMAC_CSR_500_800M /324 1.54 - 2.47MHz
STMMAC_CSR_300_500M /204 1.47 - 2.45MHz
STMMAC_CSR_250_300M /124 2.02 - 2.42MHz
STMMAC_CSR_150_250M /102 1.47 - 2.45MHz
STMMAC_CSR_100_150M /62 1.61 - 2.42MHz
STMMAC_CSR_60_100M /42 1.43 - 2.38MHz
STMMAC_CSR_35_60M /26 1.35 - 2.31MHz
STMMAC_CSR_20_35M /16 1.25 - 2.19MHz
Thus, with the change of divisor for exactly 300MHz, MDC temporarily
changes from 2.42MHz to 1.47MHz for the sake of consistency.
The databook does not specify whether the frequency limits for the
CSR divider are inclusive or exclusive.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 98 ++++++++++++-------
1 file changed, 62 insertions(+), 36 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 485a0d790baa..c4123d2260bd 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -473,6 +473,52 @@ void stmmac_pcs_clean(struct net_device *ndev)
priv->hw->xpcs = NULL;
}
+struct stmmac_clk_rate {
+ unsigned long rate;
+ u8 cr;
+};
+
+/* The standard clk_csr_i to GMII_Address CR field mapping. The rate provided
+ * in this table is the exclusive maximum frequency for the divisor. The
+ * comments for each entry give the divisor and the resulting range of MDC
+ * clock frequencies.
+ */
+static const struct stmmac_clk_rate stmmac_std_csr_to_mdc[] = {
+ { CSR_F_35M, STMMAC_CSR_20_35M },
+ { CSR_F_60M, STMMAC_CSR_35_60M },
+ { CSR_F_100M, STMMAC_CSR_60_100M },
+ { CSR_F_150M, STMMAC_CSR_100_150M },
+ { CSR_F_250M, STMMAC_CSR_150_250M },
+ { CSR_F_300M, STMMAC_CSR_250_300M },
+ { CSR_F_500M, STMMAC_CSR_300_500M },
+ { CSR_F_800M, STMMAC_CSR_500_800M },
+ { },
+};
+
+/* The sun8i clk_csr_i to GMII_Address CR field mapping uses rate as the
+ * exclusive minimum frequency for the divisor. Note that the last entry
+ * is valid and also acts as the sentinel.
+ */
+static const struct stmmac_clk_rate stmmac_sun8i_csr_to_mdc[] = {
+ { 160000000, 3 },
+ { 80000000, 2 },
+ { 40000000, 1 },
+ { 0, 0 },
+};
+
+/* The xgmac clk_csr_i to GMII_Address CR field mapping similarly uses rate
+ * as the exclusive minimum frequency for the divisor, and again the last
+ * entry is valid and also the sentinel.
+ */
+static const struct stmmac_clk_rate stmmac_xgmac_csr_to_mdc[] = {
+ { 400000000, 5 },
+ { 350000000, 4 },
+ { 300000000, 3 },
+ { 250000000, 2 },
+ { 150000000, 1 },
+ { 0, 0 },
+};
+
/**
* stmmac_clk_csr_set - dynamically set the MDC clock
* @priv: driver private structure
@@ -490,6 +536,7 @@ static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
{
unsigned long clk_rate;
u32 value = ~0;
+ int i;
clk_rate = clk_get_rate(priv->plat->stmmac_clk);
@@ -500,47 +547,26 @@ static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
* the frequency of clk_csr_i. So we do not change the default
* divider.
*/
- if (clk_rate < CSR_F_35M)
- value = STMMAC_CSR_20_35M;
- else if (clk_rate < CSR_F_60M)
- value = STMMAC_CSR_35_60M;
- else if (clk_rate < CSR_F_100M)
- value = STMMAC_CSR_60_100M;
- else if (clk_rate < CSR_F_150M)
- value = STMMAC_CSR_100_150M;
- else if (clk_rate < CSR_F_250M)
- value = STMMAC_CSR_150_250M;
- else if (clk_rate <= CSR_F_300M)
- value = STMMAC_CSR_250_300M;
- else if (clk_rate < CSR_F_500M)
- value = STMMAC_CSR_300_500M;
- else if (clk_rate < CSR_F_800M)
- value = STMMAC_CSR_500_800M;
+ for (i = 0; stmmac_std_csr_to_mdc[i].rate; i++)
+ if (clk_rate < stmmac_std_csr_to_mdc[i].rate) {
+ value = stmmac_std_csr_to_mdc[i].cr;
+ break;
+ }
if (priv->plat->flags & STMMAC_FLAG_HAS_SUN8I) {
- if (clk_rate > 160000000)
- value = 0x03;
- else if (clk_rate > 80000000)
- value = 0x02;
- else if (clk_rate > 40000000)
- value = 0x01;
- else
- value = 0;
+ /* Note the different test - this is intentional. */
+ for (i = 0; stmmac_sun8i_csr_to_mdc[i].rate; i++)
+ if (clk_rate > stmmac_sun8i_csr_to_mdc[i].rate)
+ break;
+ value = stmmac_sun8i_csr_to_mdc[i].cr;
}
if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
- if (clk_rate > 400000000)
- value = 0x5;
- else if (clk_rate > 350000000)
- value = 0x4;
- else if (clk_rate > 300000000)
- value = 0x3;
- else if (clk_rate > 250000000)
- value = 0x2;
- else if (clk_rate > 150000000)
- value = 0x1;
- else
- value = 0x0;
+ /* Note the different test - this is intentional. */
+ for (i = 0; stmmac_xgmac_csr_to_mdc[i].rate; i++)
+ if (clk_rate > stmmac_xgmac_csr_to_mdc[i].rate)
+ break;
+ value = stmmac_xgmac_csr_to_mdc[i].cr;
}
return value;
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next v2 2/8] net: stmmac: mdio: use same test for MDC clock divisor lookups
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables Russell King (Oracle)
@ 2026-03-05 10:42 ` Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 3/8] net: stmmac: mdio: simplify MDC clock divisor lookup Russell King (Oracle)
` (7 subsequent siblings)
9 siblings, 0 replies; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:42 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Use the same frequency test for all clk_csr value lookups (clock
rate > table rate). This has the side effect that the standard rate
table results in the divider being used for the maximum frequency
for the divider rather than the next higher divider. This still
allows MDC to meet the IEE 802.3 specification, but at a rate closer
to 2.5MHz for these frequencies.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/common.h | 1 +
.../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 27 +++++++++----------
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 42a48f655849..e4ce1167ebab 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -257,6 +257,7 @@ struct stmmac_safety_stats {
(sizeof(struct stmmac_safety_stats) / sizeof(unsigned long))
/* CSR Frequency Access Defines*/
+#define CSR_F_20M 20000000
#define CSR_F_35M 35000000
#define CSR_F_60M 60000000
#define CSR_F_100M 100000000
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index c4123d2260bd..6292911fb54b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -484,15 +484,16 @@ struct stmmac_clk_rate {
* clock frequencies.
*/
static const struct stmmac_clk_rate stmmac_std_csr_to_mdc[] = {
- { CSR_F_35M, STMMAC_CSR_20_35M },
- { CSR_F_60M, STMMAC_CSR_35_60M },
- { CSR_F_100M, STMMAC_CSR_60_100M },
- { CSR_F_150M, STMMAC_CSR_100_150M },
- { CSR_F_250M, STMMAC_CSR_150_250M },
- { CSR_F_300M, STMMAC_CSR_250_300M },
- { CSR_F_500M, STMMAC_CSR_300_500M },
- { CSR_F_800M, STMMAC_CSR_500_800M },
- { },
+ { CSR_F_800M, ~0 },
+ { CSR_F_500M, STMMAC_CSR_500_800M },
+ { CSR_F_300M, STMMAC_CSR_300_500M },
+ { CSR_F_250M, STMMAC_CSR_250_300M },
+ { CSR_F_150M, STMMAC_CSR_150_250M },
+ { CSR_F_100M, STMMAC_CSR_100_150M },
+ { CSR_F_60M, STMMAC_CSR_60_100M },
+ { CSR_F_35M, STMMAC_CSR_35_60M },
+ { CSR_F_20M, STMMAC_CSR_20_35M },
+ { 0, ~0 },
};
/* The sun8i clk_csr_i to GMII_Address CR field mapping uses rate as the
@@ -548,13 +549,12 @@ static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
* divider.
*/
for (i = 0; stmmac_std_csr_to_mdc[i].rate; i++)
- if (clk_rate < stmmac_std_csr_to_mdc[i].rate) {
- value = stmmac_std_csr_to_mdc[i].cr;
+ if (clk_rate > stmmac_std_csr_to_mdc[i].rate)
break;
- }
+ if (stmmac_std_csr_to_mdc[i].cr != (u8)~0)
+ value = stmmac_std_csr_to_mdc[i].cr;
if (priv->plat->flags & STMMAC_FLAG_HAS_SUN8I) {
- /* Note the different test - this is intentional. */
for (i = 0; stmmac_sun8i_csr_to_mdc[i].rate; i++)
if (clk_rate > stmmac_sun8i_csr_to_mdc[i].rate)
break;
@@ -562,7 +562,6 @@ static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
}
if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
- /* Note the different test - this is intentional. */
for (i = 0; stmmac_xgmac_csr_to_mdc[i].rate; i++)
if (clk_rate > stmmac_xgmac_csr_to_mdc[i].rate)
break;
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next v2 3/8] net: stmmac: mdio: simplify MDC clock divisor lookup
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 2/8] net: stmmac: mdio: use same test for MDC clock divisor lookups Russell King (Oracle)
@ 2026-03-05 10:42 ` Russell King (Oracle)
2026-03-06 9:01 ` Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 4/8] net: stmmac: mdio: convert field prep to use field_prep() Russell King (Oracle)
` (6 subsequent siblings)
9 siblings, 1 reply; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:42 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
As each lookup now iterates over each table in the same way, simplfy
the code to select the table, and then walk that table.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 29 +++++++------------
1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 6292911fb54b..c9f0b8b601d2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -535,6 +535,7 @@ static const struct stmmac_clk_rate stmmac_xgmac_csr_to_mdc[] = {
*/
static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
{
+ const struct stmmac_clk_rate *rates;
unsigned long clk_rate;
u32 value = ~0;
int i;
@@ -548,25 +549,17 @@ static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
* the frequency of clk_csr_i. So we do not change the default
* divider.
*/
- for (i = 0; stmmac_std_csr_to_mdc[i].rate; i++)
- if (clk_rate > stmmac_std_csr_to_mdc[i].rate)
- break;
- if (stmmac_std_csr_to_mdc[i].cr != (u8)~0)
- value = stmmac_std_csr_to_mdc[i].cr;
-
- if (priv->plat->flags & STMMAC_FLAG_HAS_SUN8I) {
- for (i = 0; stmmac_sun8i_csr_to_mdc[i].rate; i++)
- if (clk_rate > stmmac_sun8i_csr_to_mdc[i].rate)
- break;
- value = stmmac_sun8i_csr_to_mdc[i].cr;
- }
+ rates = stmmac_std_csr_to_mdc;
+ if (priv->plat->flags & STMMAC_FLAG_HAS_SUN8I)
+ rates = stmmac_sun8i_csr_to_mdc;
+ if (priv->plat->core_type == DWMAC_CORE_XGMAC)
+ rates = stmmac_xgmac_csr_to_mdc;
- if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
- for (i = 0; stmmac_xgmac_csr_to_mdc[i].rate; i++)
- if (clk_rate > stmmac_xgmac_csr_to_mdc[i].rate)
- break;
- value = stmmac_xgmac_csr_to_mdc[i].cr;
- }
+ for (i = 0; rates[i].rate; i++)
+ if (clk_rate > rates[i].rate)
+ break;
+ if (rates[i].cr != (u8)~0)
+ value = rates[i].cr;
return value;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next v2 4/8] net: stmmac: mdio: convert field prep to use field_prep()
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
` (2 preceding siblings ...)
2026-03-05 10:42 ` [PATCH net-next v2 3/8] net: stmmac: mdio: simplify MDC clock divisor lookup Russell King (Oracle)
@ 2026-03-05 10:42 ` Russell King (Oracle)
2026-03-06 13:30 ` Maxime Chevallier
2026-03-05 10:42 ` [PATCH net-next v2 5/8] net: stmmac: use u32 for MDIO register field masks Russell King (Oracle)
` (5 subsequent siblings)
9 siblings, 1 reply; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:42 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Convert the MDIO field preparation to use field_prep(), which removes
the need to store separate mask and shifts. Also convert the clk_csr
value using __ffs() to do the shift as we need to detect overflows
for this.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/common.h | 3 ---
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 3 ---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 3 ---
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 3 ---
drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c | 3 ---
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 3 ---
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 6 ------
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 6 +++---
8 files changed, 3 insertions(+), 27 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index e4ce1167ebab..978f90065681 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -608,11 +608,8 @@ struct mac_link {
struct mii_regs {
unsigned int addr; /* MII Address */
unsigned int data; /* MII Data */
- unsigned int addr_shift; /* MII address shift */
- unsigned int reg_shift; /* MII reg shift */
unsigned int addr_mask; /* MII address mask */
unsigned int reg_mask; /* MII reg mask */
- unsigned int clk_csr_shift;
unsigned int clk_csr_mask;
};
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index 9c51c96223ad..6dfccc969d0e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -367,11 +367,8 @@ static int loongson_dwmac_setup(void *apriv, struct mac_device_info *mac)
mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
mac->mii.addr = GMAC_MII_ADDR;
mac->mii.data = GMAC_MII_DATA;
- mac->mii.addr_shift = 11;
mac->mii.addr_mask = 0x0000F800;
- mac->mii.reg_shift = 6;
mac->mii.reg_mask = 0x000007C0;
- mac->mii.clk_csr_shift = 2;
mac->mii.clk_csr_mask = GENMASK(5, 2);
return 0;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index c01b86fd64da..6b18072112db 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1063,11 +1063,8 @@ static int sun8i_dwmac_setup(void *ppriv, struct mac_device_info *mac)
mac->link.duplex = EMAC_DUPLEX_FULL;
mac->mii.addr = EMAC_MDIO_CMD;
mac->mii.data = EMAC_MDIO_DATA;
- mac->mii.reg_shift = 4;
mac->mii.reg_mask = GENMASK(8, 4);
- mac->mii.addr_shift = 12;
mac->mii.addr_mask = GENMASK(16, 12);
- mac->mii.clk_csr_shift = 20;
mac->mii.clk_csr_mask = GENMASK(22, 20);
mac->unicast_filter_entries = 8;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index af566636fad9..10acca806f4f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -496,11 +496,8 @@ int dwmac1000_setup(struct stmmac_priv *priv)
mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
mac->mii.addr = GMAC_MII_ADDR;
mac->mii.data = GMAC_MII_DATA;
- mac->mii.addr_shift = 11;
mac->mii.addr_mask = 0x0000F800;
- mac->mii.reg_shift = 6;
mac->mii.reg_mask = 0x000007C0;
- mac->mii.clk_csr_shift = 2;
mac->mii.clk_csr_mask = GENMASK(5, 2);
return 0;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
index db4fbe64a38a..911753b9889e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
@@ -184,11 +184,8 @@ int dwmac100_setup(struct stmmac_priv *priv)
mac->link.speed_mask = MAC_CONTROL_PS;
mac->mii.addr = MAC_MII_ADDR;
mac->mii.data = MAC_MII_DATA;
- mac->mii.addr_shift = 11;
mac->mii.addr_mask = 0x0000F800;
- mac->mii.reg_shift = 6;
mac->mii.reg_mask = 0x000007C0;
- mac->mii.clk_csr_shift = 2;
mac->mii.clk_csr_mask = GENMASK(5, 2);
return 0;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 623868afe93d..0e87590c806b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -1030,11 +1030,8 @@ int dwmac4_setup(struct stmmac_priv *priv)
mac->link.speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
mac->mii.addr = GMAC_MDIO_ADDR;
mac->mii.data = GMAC_MDIO_DATA;
- mac->mii.addr_shift = 21;
mac->mii.addr_mask = GENMASK(25, 21);
- mac->mii.reg_shift = 16;
mac->mii.reg_mask = GENMASK(20, 16);
- mac->mii.clk_csr_shift = 8;
mac->mii.clk_csr_mask = GENMASK(11, 8);
mac->num_vlan = stmmac_get_num_vlan(priv->ioaddr);
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 49893b9fb88c..ba98e22f1c12 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -1551,11 +1551,8 @@ int dwxgmac2_setup(struct stmmac_priv *priv)
mac->mii.addr = XGMAC_MDIO_ADDR;
mac->mii.data = XGMAC_MDIO_DATA;
- mac->mii.addr_shift = 16;
mac->mii.addr_mask = GENMASK(20, 16);
- mac->mii.reg_shift = 0;
mac->mii.reg_mask = GENMASK(15, 0);
- mac->mii.clk_csr_shift = 19;
mac->mii.clk_csr_mask = GENMASK(21, 19);
mac->num_vlan = stmmac_get_num_vlan(priv->ioaddr);
@@ -1594,11 +1591,8 @@ int dwxlgmac2_setup(struct stmmac_priv *priv)
mac->mii.addr = XGMAC_MDIO_ADDR;
mac->mii.data = XGMAC_MDIO_DATA;
- mac->mii.addr_shift = 16;
mac->mii.addr_mask = GENMASK(20, 16);
- mac->mii.reg_shift = 0;
mac->mii.reg_mask = GENMASK(15, 0);
- mac->mii.clk_csr_shift = 19;
mac->mii.clk_csr_mask = GENMASK(21, 19);
return 0;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index c9f0b8b601d2..afe98ff5bdcb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -234,8 +234,8 @@ static u32 stmmac_mdio_format_addr(struct stmmac_priv *priv,
{
const struct mii_regs *mii_regs = &priv->hw->mii;
- return ((pa << mii_regs->addr_shift) & mii_regs->addr_mask) |
- ((gr << mii_regs->reg_shift) & mii_regs->reg_mask) |
+ return field_prep(mii_regs->addr_mask, pa) |
+ field_prep(mii_regs->reg_mask, gr) |
priv->gmii_address_bus_config |
MII_ADDR_GBUSY;
}
@@ -577,7 +577,7 @@ static void stmmac_mdio_bus_config(struct stmmac_priv *priv)
else
value = stmmac_clk_csr_set(priv);
- value <<= priv->hw->mii.clk_csr_shift;
+ value <<= __ffs(priv->hw->mii.clk_csr_mask);
if (value & ~priv->hw->mii.clk_csr_mask)
dev_warn(priv->device,
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next v2 5/8] net: stmmac: use u32 for MDIO register field masks
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
` (3 preceding siblings ...)
2026-03-05 10:42 ` [PATCH net-next v2 4/8] net: stmmac: mdio: convert field prep to use field_prep() Russell King (Oracle)
@ 2026-03-05 10:42 ` Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 6/8] net: stmmac: use GENMASK_U32() for mdio bitfields Russell King (Oracle)
` (4 subsequent siblings)
9 siblings, 0 replies; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:42 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
MDIO registers are 32-bit, so use u32 to describe the masks for these
registers. Convert the GENMASK() initialisers to GENMASK_U32() for
type compatibility.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/common.h | 6 +++---
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 6 +++---
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 6 +++---
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 12 ++++++------
7 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 978f90065681..46454e2886ce 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -608,9 +608,9 @@ struct mac_link {
struct mii_regs {
unsigned int addr; /* MII Address */
unsigned int data; /* MII Data */
- unsigned int addr_mask; /* MII address mask */
- unsigned int reg_mask; /* MII reg mask */
- unsigned int clk_csr_mask;
+ u32 addr_mask; /* MII address mask */
+ u32 reg_mask; /* MII reg mask */
+ u32 clk_csr_mask;
};
struct mac_device_info {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index 6dfccc969d0e..a6f8e78856aa 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -369,7 +369,7 @@ static int loongson_dwmac_setup(void *apriv, struct mac_device_info *mac)
mac->mii.data = GMAC_MII_DATA;
mac->mii.addr_mask = 0x0000F800;
mac->mii.reg_mask = 0x000007C0;
- mac->mii.clk_csr_mask = GENMASK(5, 2);
+ mac->mii.clk_csr_mask = GENMASK_U32(5, 2);
return 0;
}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 6b18072112db..3ce03b059277 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1063,9 +1063,9 @@ static int sun8i_dwmac_setup(void *ppriv, struct mac_device_info *mac)
mac->link.duplex = EMAC_DUPLEX_FULL;
mac->mii.addr = EMAC_MDIO_CMD;
mac->mii.data = EMAC_MDIO_DATA;
- mac->mii.reg_mask = GENMASK(8, 4);
- mac->mii.addr_mask = GENMASK(16, 12);
- mac->mii.clk_csr_mask = GENMASK(22, 20);
+ mac->mii.reg_mask = GENMASK_U32(8, 4);
+ mac->mii.addr_mask = GENMASK_U32(16, 12);
+ mac->mii.clk_csr_mask = GENMASK_U32(22, 20);
mac->unicast_filter_entries = 8;
/* Synopsys Id is not available */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index 10acca806f4f..4ea55be04c5c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -498,7 +498,7 @@ int dwmac1000_setup(struct stmmac_priv *priv)
mac->mii.data = GMAC_MII_DATA;
mac->mii.addr_mask = 0x0000F800;
mac->mii.reg_mask = 0x000007C0;
- mac->mii.clk_csr_mask = GENMASK(5, 2);
+ mac->mii.clk_csr_mask = GENMASK_U32(5, 2);
return 0;
}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
index 911753b9889e..7c91ea2775d4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
@@ -186,7 +186,7 @@ int dwmac100_setup(struct stmmac_priv *priv)
mac->mii.data = MAC_MII_DATA;
mac->mii.addr_mask = 0x0000F800;
mac->mii.reg_mask = 0x000007C0;
- mac->mii.clk_csr_mask = GENMASK(5, 2);
+ mac->mii.clk_csr_mask = GENMASK_U32(5, 2);
return 0;
}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 0e87590c806b..602771e19d0f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -1030,9 +1030,9 @@ int dwmac4_setup(struct stmmac_priv *priv)
mac->link.speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
mac->mii.addr = GMAC_MDIO_ADDR;
mac->mii.data = GMAC_MDIO_DATA;
- mac->mii.addr_mask = GENMASK(25, 21);
- mac->mii.reg_mask = GENMASK(20, 16);
- mac->mii.clk_csr_mask = GENMASK(11, 8);
+ mac->mii.addr_mask = GENMASK_U32(25, 21);
+ mac->mii.reg_mask = GENMASK_U32(20, 16);
+ mac->mii.clk_csr_mask = GENMASK_U32(11, 8);
mac->num_vlan = stmmac_get_num_vlan(priv->ioaddr);
return 0;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index ba98e22f1c12..915e7c2ab11f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -1551,9 +1551,9 @@ int dwxgmac2_setup(struct stmmac_priv *priv)
mac->mii.addr = XGMAC_MDIO_ADDR;
mac->mii.data = XGMAC_MDIO_DATA;
- mac->mii.addr_mask = GENMASK(20, 16);
- mac->mii.reg_mask = GENMASK(15, 0);
- mac->mii.clk_csr_mask = GENMASK(21, 19);
+ mac->mii.addr_mask = GENMASK_U32(20, 16);
+ mac->mii.reg_mask = GENMASK_U32(15, 0);
+ mac->mii.clk_csr_mask = GENMASK_U32(21, 19);
mac->num_vlan = stmmac_get_num_vlan(priv->ioaddr);
return 0;
@@ -1591,9 +1591,9 @@ int dwxlgmac2_setup(struct stmmac_priv *priv)
mac->mii.addr = XGMAC_MDIO_ADDR;
mac->mii.data = XGMAC_MDIO_DATA;
- mac->mii.addr_mask = GENMASK(20, 16);
- mac->mii.reg_mask = GENMASK(15, 0);
- mac->mii.clk_csr_mask = GENMASK(21, 19);
+ mac->mii.addr_mask = GENMASK_U32(20, 16);
+ mac->mii.reg_mask = GENMASK_U32(15, 0);
+ mac->mii.clk_csr_mask = GENMASK_U32(21, 19);
return 0;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next v2 6/8] net: stmmac: use GENMASK_U32() for mdio bitfields
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
` (4 preceding siblings ...)
2026-03-05 10:42 ` [PATCH net-next v2 5/8] net: stmmac: use u32 for MDIO register field masks Russell King (Oracle)
@ 2026-03-05 10:42 ` Russell King (Oracle)
2026-03-06 13:30 ` Maxime Chevallier
2026-03-05 10:42 ` [PATCH net-next v2 7/8] net: stmmac: mdio_bus_data->default_an_inband is boolean Russell King (Oracle)
` (3 subsequent siblings)
9 siblings, 1 reply; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:42 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Rather than using hex numbers, use GENMASK() for mdio bitfields.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 4 ++--
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 4 ++--
drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index a6f8e78856aa..b913fe5af488 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -367,8 +367,8 @@ static int loongson_dwmac_setup(void *apriv, struct mac_device_info *mac)
mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
mac->mii.addr = GMAC_MII_ADDR;
mac->mii.data = GMAC_MII_DATA;
- mac->mii.addr_mask = 0x0000F800;
- mac->mii.reg_mask = 0x000007C0;
+ mac->mii.addr_mask = GENMASK_U32(15, 11);
+ mac->mii.reg_mask = GENMASK_U32(10, 6);
mac->mii.clk_csr_mask = GENMASK_U32(5, 2);
return 0;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index 4ea55be04c5c..c7cb30672604 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -496,8 +496,8 @@ int dwmac1000_setup(struct stmmac_priv *priv)
mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
mac->mii.addr = GMAC_MII_ADDR;
mac->mii.data = GMAC_MII_DATA;
- mac->mii.addr_mask = 0x0000F800;
- mac->mii.reg_mask = 0x000007C0;
+ mac->mii.addr_mask = GENMASK_U32(15, 11);
+ mac->mii.reg_mask = GENMASK_U32(10, 6);
mac->mii.clk_csr_mask = GENMASK_U32(5, 2);
return 0;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
index 7c91ea2775d4..6b5cf3a0866a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
@@ -184,8 +184,8 @@ int dwmac100_setup(struct stmmac_priv *priv)
mac->link.speed_mask = MAC_CONTROL_PS;
mac->mii.addr = MAC_MII_ADDR;
mac->mii.data = MAC_MII_DATA;
- mac->mii.addr_mask = 0x0000F800;
- mac->mii.reg_mask = 0x000007C0;
+ mac->mii.addr_mask = GENMASK_U32(15, 11);
+ mac->mii.reg_mask = GENMASK_U32(10, 6);
mac->mii.clk_csr_mask = GENMASK_U32(5, 2);
return 0;
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next v2 7/8] net: stmmac: mdio_bus_data->default_an_inband is boolean
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
` (5 preceding siblings ...)
2026-03-05 10:42 ` [PATCH net-next v2 6/8] net: stmmac: use GENMASK_U32() for mdio bitfields Russell King (Oracle)
@ 2026-03-05 10:42 ` Russell King (Oracle)
2026-03-06 13:31 ` Maxime Chevallier
2026-03-05 10:43 ` [PATCH net-next v2 8/8] net: stmmac: make pcs_mask and phy_mask u32 Russell King (Oracle)
` (2 subsequent siblings)
9 siblings, 1 reply; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:42 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
default_an_inband is declared as an unsigned int, but is set to true/
false and is assigned to phylink_config's member of the same name
which is a bool. Declare this also as a bool for consistency.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
include/linux/stmmac.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 2fc169c7117e..678d03d6d3bd 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -86,10 +86,10 @@ struct stmmac_priv;
struct stmmac_mdio_bus_data {
unsigned int phy_mask;
unsigned int pcs_mask;
- unsigned int default_an_inband;
int *irqs;
int probed_phy_irq;
bool needs_reset;
+ bool default_an_inband;
};
struct stmmac_dma_cfg {
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH net-next v2 8/8] net: stmmac: make pcs_mask and phy_mask u32
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
` (6 preceding siblings ...)
2026-03-05 10:42 ` [PATCH net-next v2 7/8] net: stmmac: mdio_bus_data->default_an_inband is boolean Russell King (Oracle)
@ 2026-03-05 10:43 ` Russell King (Oracle)
2026-03-06 13:32 ` Maxime Chevallier
2026-03-06 13:49 ` [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Maxime Chevallier
2026-03-06 23:50 ` patchwork-bot+netdevbpf
9 siblings, 1 reply; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 10:43 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
The PCS and PHY masks are passed to the mdio bus layer as phy_mask
to prevent bus addresses between 0 and 31 inclusive being scanned,
and this is declared as u32. Also declare these as u32 in stmmac
for type consistency.
Since this is a u32, use BIT_U32() rather than BIT() to generate
values for these fields.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 2 +-
include/linux/stmmac.h | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
index ece2a0c38562..fc13bfb47783 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
@@ -699,7 +699,7 @@ static int intel_mgbe_common_data(struct pci_dev *pdev,
/* Intel mgbe SGMII interface uses pcs-xcps */
if (plat->phy_interface == PHY_INTERFACE_MODE_SGMII ||
plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) {
- plat->mdio_bus_data->pcs_mask = BIT(INTEL_MGBE_XPCS_ADDR);
+ plat->mdio_bus_data->pcs_mask = BIT_U32(INTEL_MGBE_XPCS_ADDR);
plat->mdio_bus_data->default_an_inband = true;
plat->select_pcs = intel_mgbe_select_pcs;
}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index b913fe5af488..ada6c6ef1f5c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -168,7 +168,7 @@ static int loongson_gnet_data(struct pci_dev *pdev,
loongson_default_data(pdev, plat);
plat->phy_interface = PHY_INTERFACE_MODE_GMII;
- plat->mdio_bus_data->phy_mask = ~(u32)BIT(2);
+ plat->mdio_bus_data->phy_mask = ~BIT_U32(2);
plat->fix_mac_speed = loongson_gnet_fix_speed;
return 0;
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 678d03d6d3bd..965ada809fdf 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -84,8 +84,8 @@ struct stmmac_priv;
/* Platfrom data for platform device structure's platform_data field */
struct stmmac_mdio_bus_data {
- unsigned int phy_mask;
- unsigned int pcs_mask;
+ u32 phy_mask;
+ u32 pcs_mask;
int *irqs;
int probed_phy_irq;
bool needs_reset;
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables
2026-03-05 10:42 ` [PATCH net-next v2 1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables Russell King (Oracle)
@ 2026-03-05 12:11 ` Russell King (Oracle)
2026-03-05 15:19 ` Jakub Kicinski
0 siblings, 1 reply; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-05 12:11 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
On Thu, Mar 05, 2026 at 10:42:26AM +0000, Russell King (Oracle) wrote:
> Convert the MDC clock divisor selection to tabular format.
>
> Note that there is a change for 300MHz, but this is not a problem,
> as the MDC clock remains within the useable ranges, which are:
I notice that checkpatch complains about "useable", which it should
not do. "useable" is perfectly correct, especially in British English.
As I'm British, I won't be fixing this checkpatch complaint.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables
2026-03-05 12:11 ` Russell King (Oracle)
@ 2026-03-05 15:19 ` Jakub Kicinski
0 siblings, 0 replies; 18+ messages in thread
From: Jakub Kicinski @ 2026-03-05 15:19 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: Andrew Lunn, Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai,
David S. Miller, Eric Dumazet, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
On Thu, 5 Mar 2026 12:11:06 +0000 Russell King (Oracle) wrote:
> On Thu, Mar 05, 2026 at 10:42:26AM +0000, Russell King (Oracle) wrote:
> > Convert the MDC clock divisor selection to tabular format.
> >
> > Note that there is a change for 300MHz, but this is not a problem,
> > as the MDC clock remains within the useable ranges, which are:
>
> I notice that checkpatch complains about "useable", which it should
> not do. "useable" is perfectly correct, especially in British English.
> As I'm British, I won't be fixing this checkpatch complaint.
Yesterday it reported a warning that someone repeated the word 'very'.
As in "this is very very wrong". checkpatch, eh? gold.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 3/8] net: stmmac: mdio: simplify MDC clock divisor lookup
2026-03-05 10:42 ` [PATCH net-next v2 3/8] net: stmmac: mdio: simplify MDC clock divisor lookup Russell King (Oracle)
@ 2026-03-06 9:01 ` Russell King (Oracle)
0 siblings, 0 replies; 18+ messages in thread
From: Russell King (Oracle) @ 2026-03-06 9:01 UTC (permalink / raw)
To: Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
On Thu, Mar 05, 2026 at 10:42:37AM +0000, Russell King (Oracle) wrote:
> As each lookup now iterates over each table in the same way, simplfy
> the code to select the table, and then walk that table.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> ---
> .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 29 +++++++------------
> 1 file changed, 11 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index 6292911fb54b..c9f0b8b601d2 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -535,6 +535,7 @@ static const struct stmmac_clk_rate stmmac_xgmac_csr_to_mdc[] = {
> */
> static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
> {
> + const struct stmmac_clk_rate *rates;
> unsigned long clk_rate;
> u32 value = ~0;
> int i;
> @@ -548,25 +549,17 @@ static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)
> * the frequency of clk_csr_i. So we do not change the default
> * divider.
> */
> - for (i = 0; stmmac_std_csr_to_mdc[i].rate; i++)
> - if (clk_rate > stmmac_std_csr_to_mdc[i].rate)
> - break;
> - if (stmmac_std_csr_to_mdc[i].cr != (u8)~0)
> - value = stmmac_std_csr_to_mdc[i].cr;
> -
> - if (priv->plat->flags & STMMAC_FLAG_HAS_SUN8I) {
> - for (i = 0; stmmac_sun8i_csr_to_mdc[i].rate; i++)
> - if (clk_rate > stmmac_sun8i_csr_to_mdc[i].rate)
> - break;
> - value = stmmac_sun8i_csr_to_mdc[i].cr;
> - }
> + rates = stmmac_std_csr_to_mdc;
> + if (priv->plat->flags & STMMAC_FLAG_HAS_SUN8I)
> + rates = stmmac_sun8i_csr_to_mdc;
> + if (priv->plat->core_type == DWMAC_CORE_XGMAC)
> + rates = stmmac_xgmac_csr_to_mdc;
>
> - if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
> - for (i = 0; stmmac_xgmac_csr_to_mdc[i].rate; i++)
> - if (clk_rate > stmmac_xgmac_csr_to_mdc[i].rate)
> - break;
> - value = stmmac_xgmac_csr_to_mdc[i].cr;
> - }
> + for (i = 0; rates[i].rate; i++)
> + if (clk_rate > rates[i].rate)
> + break;
> + if (rates[i].cr != (u8)~0)
> + value = rates[i].cr;
Looking at the AI review, it seems to me that the AI review is
incorrect.
With reference to the full original code which can be seen in:
https://patchwork.kernel.org/project/netdevbpf/patch/E1vy69y-0000000Btwd-3oq7@rmk-PC.armlinux.org.uk/
If we look at the original code, then we can see that the intention
is that if clk_rate is smaller than the last real entry for the
sun8i and xgmac cases, the value should end up as zero - and this is
exactly what the new code does. So, the behaviour is preserved, even
though AI thinks it isn't.
AI seems to think that reaching the last entry for sun8i and xgmac
means we have an invalid rate. That is where AI is going wrong -
that is an incorrect "assumption".
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 4/8] net: stmmac: mdio: convert field prep to use field_prep()
2026-03-05 10:42 ` [PATCH net-next v2 4/8] net: stmmac: mdio: convert field prep to use field_prep() Russell King (Oracle)
@ 2026-03-06 13:30 ` Maxime Chevallier
0 siblings, 0 replies; 18+ messages in thread
From: Maxime Chevallier @ 2026-03-06 13:30 UTC (permalink / raw)
To: Russell King (Oracle), Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Hi,
On 05/03/2026 11:42, Russell King (Oracle) wrote:
> Convert the MDIO field preparation to use field_prep(), which removes
> the need to store separate mask and shifts. Also convert the clk_csr
> value using __ffs() to do the shift as we need to detect overflows
> for this.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 6/8] net: stmmac: use GENMASK_U32() for mdio bitfields
2026-03-05 10:42 ` [PATCH net-next v2 6/8] net: stmmac: use GENMASK_U32() for mdio bitfields Russell King (Oracle)
@ 2026-03-06 13:30 ` Maxime Chevallier
0 siblings, 0 replies; 18+ messages in thread
From: Maxime Chevallier @ 2026-03-06 13:30 UTC (permalink / raw)
To: Russell King (Oracle), Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Hi,
On 05/03/2026 11:42, Russell King (Oracle) wrote:
> Rather than using hex numbers, use GENMASK() for mdio bitfields.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 7/8] net: stmmac: mdio_bus_data->default_an_inband is boolean
2026-03-05 10:42 ` [PATCH net-next v2 7/8] net: stmmac: mdio_bus_data->default_an_inband is boolean Russell King (Oracle)
@ 2026-03-06 13:31 ` Maxime Chevallier
0 siblings, 0 replies; 18+ messages in thread
From: Maxime Chevallier @ 2026-03-06 13:31 UTC (permalink / raw)
To: Russell King (Oracle), Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Hi,
On 05/03/2026 11:42, Russell King (Oracle) wrote:
> default_an_inband is declared as an unsigned int, but is set to true/
> false and is assigned to phylink_config's member of the same name
> which is a bool. Declare this also as a bool for consistency.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 8/8] net: stmmac: make pcs_mask and phy_mask u32
2026-03-05 10:43 ` [PATCH net-next v2 8/8] net: stmmac: make pcs_mask and phy_mask u32 Russell King (Oracle)
@ 2026-03-06 13:32 ` Maxime Chevallier
0 siblings, 0 replies; 18+ messages in thread
From: Maxime Chevallier @ 2026-03-06 13:32 UTC (permalink / raw)
To: Russell King (Oracle), Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Hi,
On 05/03/2026 11:43, Russell King (Oracle) wrote:
> The PCS and PHY masks are passed to the mdio bus layer as phy_mask
> to prevent bus addresses between 0 and 31 inclusive being scanned,
> and this is declared as u32. Also declare these as u32 in stmmac
> for type consistency.
>
> Since this is a u32, use BIT_U32() rather than BIT() to generate
> values for these fields.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
` (7 preceding siblings ...)
2026-03-05 10:43 ` [PATCH net-next v2 8/8] net: stmmac: make pcs_mask and phy_mask u32 Russell King (Oracle)
@ 2026-03-06 13:49 ` Maxime Chevallier
2026-03-06 23:50 ` patchwork-bot+netdevbpf
9 siblings, 0 replies; 18+ messages in thread
From: Maxime Chevallier @ 2026-03-06 13:49 UTC (permalink / raw)
To: Russell King (Oracle), Andrew Lunn
Cc: Alexandre Torgue, Andrew Lunn, Chen-Yu Tsai, David S. Miller,
Eric Dumazet, Jakub Kicinski, linux-arm-kernel, linux-stm32,
linux-sunxi, netdev, Paolo Abeni, Samuel Holland
Hi,
On 05/03/2026 11:42, Russell King (Oracle) wrote:
> Hi,
>
> The first four patches clean up the MDC clock divisor selection code,
> turning the three different ways we choose a divisor into tabular form,
> rather than doing the selection purely in code.
>
> Convert MDIO to use field_prep() which allows a non-constant mask to be
> used when preparing fields.
>
> Then use u32 and the associated typed GENMASK for MDIO register field
> definitions.
>
> Finally, an extra couple of patches that use appropriate types in
> struct mdio_bus_data.
>
> v2:
> - add comments about 300MHz to commit message in patch 1
> - fix incorrect usage of stmmac_sun8i_csr_to_mdc in patch 3
> - fix BIT_u32()->BIT_U32() in patch 8
I have tested this series as a whole on 2 platforms using the dwmac mdio
driver (socfpga - KSZ9031 / imx8mp + KSZ9131), no regressions found. I'm
not stressing the 300M case though.
feel free to add my :
Tested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
> drivers/net/ethernet/stmicro/stmmac/common.h | 10 +-
> drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 2 +-
> .../net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 +--
> drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 9 +-
> .../net/ethernet/stmicro/stmmac/dwmac1000_core.c | 9 +-
> .../net/ethernet/stmicro/stmmac/dwmac100_core.c | 9 +-
> drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 9 +-
> .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 18 ++--
> drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 106 ++++++++++++---------
> include/linux/stmmac.h | 6 +-
> 10 files changed, 92 insertions(+), 97 deletions(-)
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
` (8 preceding siblings ...)
2026-03-06 13:49 ` [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Maxime Chevallier
@ 2026-03-06 23:50 ` patchwork-bot+netdevbpf
9 siblings, 0 replies; 18+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-06 23:50 UTC (permalink / raw)
To: Russell King
Cc: andrew, alexandre.torgue, andrew+netdev, wens, davem, edumazet,
kuba, linux-arm-kernel, linux-stm32, linux-sunxi, netdev, pabeni,
samuel
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 5 Mar 2026 10:42:03 +0000 you wrote:
> Hi,
>
> The first four patches clean up the MDC clock divisor selection code,
> turning the three different ways we choose a divisor into tabular form,
> rather than doing the selection purely in code.
>
> Convert MDIO to use field_prep() which allows a non-constant mask to be
> used when preparing fields.
>
> [...]
Here is the summary with links:
- [net-next,v2,1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables
https://git.kernel.org/netdev/net-next/c/4c7e0e081889
- [net-next,v2,2/8] net: stmmac: mdio: use same test for MDC clock divisor lookups
https://git.kernel.org/netdev/net-next/c/b6687ef97603
- [net-next,v2,3/8] net: stmmac: mdio: simplify MDC clock divisor lookup
https://git.kernel.org/netdev/net-next/c/506f78f43c58
- [net-next,v2,4/8] net: stmmac: mdio: convert field prep to use field_prep()
https://git.kernel.org/netdev/net-next/c/58bd0039002b
- [net-next,v2,5/8] net: stmmac: use u32 for MDIO register field masks
https://git.kernel.org/netdev/net-next/c/df388b4d3913
- [net-next,v2,6/8] net: stmmac: use GENMASK_U32() for mdio bitfields
https://git.kernel.org/netdev/net-next/c/a64d927aecf1
- [net-next,v2,7/8] net: stmmac: mdio_bus_data->default_an_inband is boolean
https://git.kernel.org/netdev/net-next/c/3cd963fa915c
- [net-next,v2,8/8] net: stmmac: make pcs_mask and phy_mask u32
https://git.kernel.org/netdev/net-next/c/e4fd855c52ec
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-03-06 23:50 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 10:42 [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 1/8] net: stmmac: mdio: convert MDC clock divisor selection to tables Russell King (Oracle)
2026-03-05 12:11 ` Russell King (Oracle)
2026-03-05 15:19 ` Jakub Kicinski
2026-03-05 10:42 ` [PATCH net-next v2 2/8] net: stmmac: mdio: use same test for MDC clock divisor lookups Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 3/8] net: stmmac: mdio: simplify MDC clock divisor lookup Russell King (Oracle)
2026-03-06 9:01 ` Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 4/8] net: stmmac: mdio: convert field prep to use field_prep() Russell King (Oracle)
2026-03-06 13:30 ` Maxime Chevallier
2026-03-05 10:42 ` [PATCH net-next v2 5/8] net: stmmac: use u32 for MDIO register field masks Russell King (Oracle)
2026-03-05 10:42 ` [PATCH net-next v2 6/8] net: stmmac: use GENMASK_U32() for mdio bitfields Russell King (Oracle)
2026-03-06 13:30 ` Maxime Chevallier
2026-03-05 10:42 ` [PATCH net-next v2 7/8] net: stmmac: mdio_bus_data->default_an_inband is boolean Russell King (Oracle)
2026-03-06 13:31 ` Maxime Chevallier
2026-03-05 10:43 ` [PATCH net-next v2 8/8] net: stmmac: make pcs_mask and phy_mask u32 Russell King (Oracle)
2026-03-06 13:32 ` Maxime Chevallier
2026-03-06 13:49 ` [PATCH net-next v2 0/8] net: stmmac: mdio related cleanups Maxime Chevallier
2026-03-06 23:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox