Skip to contentSkip to conversation

net: stmmac: dwc-qos-eth: simplify switch() in dwc_eth_dwmac_config_dt()

PATCH In review Russell King (Oracle) 3 participants 3 messages Nov 18, 2025 – Nov 19, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: dwc-qos-eth: simplify switch() in dwc_eth_dwmac_config_dt()

Simplify the the switch() statement in dwc_eth_dwmac_config_dt(). Although this is not speed-critical, simplifying it can make it more readable. This also drastically improves the code emitted by the compiler.

On aarch64, with the original code, the compiler loads registers with every possible value, and then has a tree of test-and-branch statements to work out which register to store. With the simplified code, the compiler can load a register with '4' and shift it appropriately.

This shrinks the text size on aarch64 from 4289 bytes to 4153 bytes, a reduction of 3%.

---
 .../stmicro/stmmac/dwmac-dwc-qos-eth.c        | 26 +++----------------
 1 file changed, 3 insertions(+), 23 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +3 -23
index c7cd6497d42d..e6d5893c5905 100644
@@ -84,29 +84,9 @@ static int dwc_eth_dwmac_config_dt(struct platform_device *pdev,
 	device_property_read_u32(dev, "snps,burst-map", &burst_map);
 
 	/* converts burst-map bitmask to burst array */
-	for (bit_index = 0; bit_index < 7; bit_index++) {
-		if (burst_map & (1 << bit_index)) {
-			switch (bit_index) {
-			case 0:
-			plat_dat->axi->axi_blen[a_index] = 4; break;
-			case 1:
-			plat_dat->axi->axi_blen[a_index] = 8; break;
-			case 2:
-			plat_dat->axi->axi_blen[a_index] = 16; break;
-			case 3:
-			plat_dat->axi->axi_blen[a_index] = 32; break;
-			case 4:
-			plat_dat->axi->axi_blen[a_index] = 64; break;
-			case 5:
-			plat_dat->axi->axi_blen[a_index] = 128; break;
-			case 6:
-			plat_dat->axi->axi_blen[a_index] = 256; break;
-			default:
-			break;
-			}
-			a_index++;
-		}
-	}
+	for (bit_index = 0; bit_index < 7; bit_index++)
+		if (burst_map & (1 << bit_index))
+			plat_dat->axi->axi_blen[a_index++] = 4 << bit_index;
 
 	/* dwc-qos needs GMAC4, AAL, TSO and PMT */
 	plat_dat->core_type = DWMAC_CORE_GMAC4;
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Russell King (Oracle)

Simplify the the switch() statement in dwc_eth_dwmac_config_dt(). Although this is not speed-critical, simplifying it can make it more readable. This also drastically improves the code emitted by the compiler.

On aarch64, with the original code, the compiler loads registers with every possible value, and then has a tree of test-and-branch statements to work out which register to store. With the simplified code, the compiler can load a register with '4' and shift it appropriately.

Quoted 4 lines

This shrinks the text size on aarch64 from 4289 bytes to 4153 bytes, a reduction of 3%.

Maxime

Quoted 41 lines
---
 .../stmicro/stmmac/dwmac-dwc-qos-eth.c        | 26 +++----------------
 1 file changed, 3 insertions(+), 23 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +3 -23
index c7cd6497d42d..e6d5893c5905 100644
@@ -84,29 +84,9 @@ static int dwc_eth_dwmac_config_dt(struct platform_device *pdev,
 	device_property_read_u32(dev, "snps,burst-map", &burst_map);
 
 	/* converts burst-map bitmask to burst array */
-	for (bit_index = 0; bit_index < 7; bit_index++) {
-		if (burst_map & (1 << bit_index)) {
-			switch (bit_index) {
-			case 0:
-			plat_dat->axi->axi_blen[a_index] = 4; break;
-			case 1:
-			plat_dat->axi->axi_blen[a_index] = 8; break;
-			case 2:
-			plat_dat->axi->axi_blen[a_index] = 16; break;
-			case 3:
-			plat_dat->axi->axi_blen[a_index] = 32; break;
-			case 4:
-			plat_dat->axi->axi_blen[a_index] = 64; break;
-			case 5:
-			plat_dat->axi->axi_blen[a_index] = 128; break;
-			case 6:
-			plat_dat->axi->axi_blen[a_index] = 256; break;
-			default:
-			break;
-			}
-			a_index++;
-		}
-	}
+	for (bit_index = 0; bit_index < 7; bit_index++)
+		if (burst_map & (1 << bit_index))
+			plat_dat->axi->axi_blen[a_index++] = 4 << bit_index;
 
 	/* dwc-qos needs GMAC4, AAL, TSO and PMT */
 	plat_dat->core_type = DWMAC_CORE_GMAC4;
#2 lore raw
In reply to Russell King (Oracle)
Quoted 1 line · Russell King (Oracle)

Simplify the the switch() statement in dwc_eth_dwmac_config_dt().

I notice that "the the" stammer has appeared in this patch commit description, which is flagged as a warning in patchwork, so I'll re-send with that fixed.

As I have a number of other patches that depend on this, all centred around the axi_blen stuff, I'll send this patch as part of that series.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!