Skip to content

stmmac: Refactor Phytium ethernet patches into modular components#9585

Merged
igorpecovnik merged 1 commit intomainfrom
arm64stmmac
Mar 25, 2026
Merged

stmmac: Refactor Phytium ethernet patches into modular components#9585
igorpecovnik merged 1 commit intomainfrom
arm64stmmac

Conversation

@igorpecovnik
Copy link
Copy Markdown
Member

@igorpecovnik igorpecovnik commented Mar 25, 2026

Summary

  • Refactor monolithic Phytium ethernet driver patch into multiple focused patches
  • Improve maintainability by separating concerns into individual patches
  • Add compilation warning fixes

Changes

Split the original net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch into:

  • 1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch - Original Phytium onboard ethernet drivers and ACPI glue
  • 1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch - Adapt to stmmac removal of axi_blen array
  • 1002-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-replace-has_xxxx-with-core_type.patch - Adapt to stmmac replace has_xxxx with core_type
  • 1003-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-pass-struct-device-to-init-exit-methods.patch - Adapt to stmmac pass struct device to init/exit methods
  • 1004-fix-stmmac-compilation-warnings.patch - Fix stmmac compilation warnings

Benefits

  • Better maintainability with smaller, focused patches
  • Easier to review and understand individual changes
  • Easier to enable/disable specific adaptations if needed

Summary by CodeRabbit

  • Bug Fixes

    • Fixed compilation warnings and tightened driver linkage for Phytium Ethernet support.
  • Chores

    • Integrated additional DWMAC drivers and updated platform registration/initialization behavior.
    • Adjusted AXI buffer-length handling to store mask/register values rather than raw entries.
    • Standardized core-type detection for GMAC capability and refined MAC/PHY interface assignment during probe.
    • Changed exported platform API surface to improve clock/resource lookup and platform init/exit argument handling.

@igorpecovnik igorpecovnik requested a review from rpardini as a code owner March 25, 2026 13:00
@github-actions github-actions bot added size/medium PR with more then 50 and less then 250 lines 05 Milestone: Second quarter release labels Mar 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 25, 2026

📝 Walkthrough

Walkthrough

Adds Phytium stmmac build object and driver tweaks, changes PHY/MAC interface assignment logic for ACPI/fwnode paths, converts AXI blen storage to a register-mask form, adjusts exported symbol surface, and makes several functions static to silence warnings.

Changes

Cohort / File(s) Summary
Build / Objects
drivers/net/ethernet/stmicro/stmmac/Makefile
Add dwmac-phytium.o to build and enable dwmac-renesas-gbeth.o via obj-$(CONFIG_...).
Phytium platform driver
drivers/net/ethernet/stmicro/stmmac/dwmac-phytium.c
Replace .remove_new with .remove; call platform exit() with &pdev->dev; make dwmac_phytium_get_resources() static and remove writes to non-existent lpi_irq; minor whitespace edits.
Generic stmmac / ACPI & fwnode handling
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c, drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
Do not copy PHY mode into mac_interface in non-ACPI path; in ACPI path assign phy_interface from firmware; make fw_get_phy_mode() and stmmac_acpi_clock_setup() static; remove lpi_irq assignment when populating resources.
AXI blen handling
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
Read snps,blen into a local u32 axi_blen[AXI_BLEN] and convert to axi->axi_blen_regval via stmmac_axi_blen_to_mask() instead of storing raw array into axi->axi_blen.
Public/exported API & symbols
drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
Remove EXPORT_SYMBOL_GPL(devm_stmmac_probe_config_dt) and its public declaration; add EXPORT_SYMBOL_GPL(stmmac_pltfr_find_clk) and new prototype struct clk *stmmac_pltfr_find_clk(struct plat_stmmacenet_data *plat_dat, const char *name); replacing prior declaration.
Core-type flag update
drivers/net/ethernet/stmicro/stmmac/dwmac-phytium.c, drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
Replace plat->has_gmac = 1 with plat->core_type = DWMAC_CORE_GMAC for GMAC capability indication.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble PHY and MAC with careful paws,
I hop through probes, remove a couple flaws,
AXI lengths become a masked delight,
Static whispers hush warnings out of sight,
A rabbit's patch — neat bytes and joyful claws.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring a monolithic Phytium ethernet driver patch into multiple modular components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch arm64stmmac

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... labels Mar 25, 2026
@igorpecovnik igorpecovnik added the Build Executing build train (permission needed) label Mar 25, 2026
@igorpecovnik igorpecovnik marked this pull request as draft March 25, 2026 13:00
@igorpecovnik igorpecovnik marked this pull request as ready for review March 25, 2026 13:00
@igorpecovnik igorpecovnik reopened this Mar 25, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
patch/kernel/archive/uefi-arm64-6.12/1002-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-replace-has_xxxx-with-core_type.patch (1)

30-32: Consider using C-style comments for kernel code.

The inline comments use C++ style (//). While valid, kernel coding style typically prefers C-style comments (/* */).

🔧 Suggested change
-+	plat->core_type = DWMAC_CORE_GMAC; // adapt to "net: stmmac: replace has_xxxx with core_type"
++	plat->core_type = DWMAC_CORE_GMAC; /* adapt to: replace has_xxxx with core_type */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@patch/kernel/archive/uefi-arm64-6.12/1002-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-replace-has_xxxx-with-core_type.patch`
around lines 30 - 32, Replace the C++-style inline comment after the assignment
to plat->core_type = DWMAC_CORE_GMAC with a kernel-style C comment; update the
comment that documents the adaptation to use /* ... */ instead of // near the
plat->core_type = DWMAC_CORE_GMAC line so the assignment and the DWMAC_CORE_GMAC
symbol remain unchanged but follow kernel coding style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch`:
- Around line 22-24: The local array axi_blen declared as "u32
axi_blen[AXI_BLEN]" must be zero-initialized so it doesn't contain garbage if
fwnode_property_read_u32_array() fails; update the declaration of axi_blen to
initialize it (e.g., "= { 0 }") and keep calling
fwnode_property_read_u32_array(np, "snps,blen", axi_blen, AXI_BLEN) as before,
then pass the (now-initialized) axi_blen to
stmmac_axi_blen_to_mask(&axi->axi_blen_regval, axi_blen, AXI_BLEN).

---

Nitpick comments:
In
`@patch/kernel/archive/uefi-arm64-6.12/1002-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-replace-has_xxxx-with-core_type.patch`:
- Around line 30-32: Replace the C++-style inline comment after the assignment
to plat->core_type = DWMAC_CORE_GMAC with a kernel-style C comment; update the
comment that documents the adaptation to use /* ... */ instead of // near the
plat->core_type = DWMAC_CORE_GMAC line so the assignment and the DWMAC_CORE_GMAC
symbol remain unchanged but follow kernel coding style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 05420a63-67f5-4eff-9ada-173896ff6d42

📥 Commits

Reviewing files that changed from the base of the PR and between f15f594 and cdafc16.

📒 Files selected for processing (5)
  • patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch
  • patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch
  • patch/kernel/archive/uefi-arm64-6.12/1002-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-replace-has_xxxx-with-core_type.patch
  • patch/kernel/archive/uefi-arm64-6.12/1003-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-pass-struct-device-to-init-exit-methods.patch
  • patch/kernel/archive/uefi-arm64-6.12/1004-fix-stmmac-compilation-warnings.patch

Comment on lines +22 to +24
+ u32 axi_blen[AXI_BLEN]; // adapt to "net: stmmac: remove axi_blen array"
+ fwnode_property_read_u32_array(np, "snps,blen", axi_blen, AXI_BLEN);
+ stmmac_axi_blen_to_mask(&axi->axi_blen_regval, axi_blen, AXI_BLEN);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch

Repository: armbian/build

Length of output: 1310


🏁 Script executed:

# Search for fwnode_property_read_u32_array behavior in kernel docs and code
# Also look for stmmac_axi_blen_to_mask implementation
rg "stmmac_axi_blen_to_mask" --type c -A 5

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Check what happens in other parts of stmmac_platform.c with property reads
rg "fwnode_property_read_u32_array" --type c -B 3 -A 3

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Look for how the original code handled the axi_blen struct member
# before this patch - check git history or similar patterns
rg "axi_blen" --type c -B 2 -A 2 | head -100

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# The kernel source may not be in this repo. Let's search the patch directory
# to see if there are related patches or documentation
fd "stmmac" patch/kernel/archive/uefi-arm64-6.12/

Repository: armbian/build

Length of output: 637


🏁 Script executed:

# Let's look at the context more carefully - check if there's a git repository
# and what the actual state of stmmac files is
git show HEAD:drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c 2>/dev/null | \
  grep -A 10 "stmmac_axi_blen_to_mask\|axi_blen_regval" | head -50

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Search web for stmmac_axi_blen_to_mask function behavior
# First, let's check if we can find kernel source info in the repo
find . -name "*.c" -o -name "*.h" | grep -i stmmac | head -20

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Let's examine the related patch 1000 to understand the original context
cat patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch | head -200

Repository: armbian/build

Length of output: 6862


🏁 Script executed:

# Search for stmmac_axi_blen_to_mask in the patch directory
rg "stmmac_axi_blen_to_mask" patch/

Repository: armbian/build

Length of output: 430


🏁 Script executed:

# Look for the full patch 1000 to see stmmac_axi_blen_to_mask definition
grep -A 20 "stmmac_axi_blen_to_mask" patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Let's get the full stmmac_axi_blen_to_mask implementation from patch 1000
wc -l patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch

Repository: armbian/build

Length of output: 182


🏁 Script executed:

# Get more content from patch 1000, focusing on stmmac_axi_blen_to_mask
grep -B 5 -A 25 "stmmac_axi_blen_to_mask" patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Let's search in patch 1000 for the function definition of stmmac_axi_blen_to_mask
sed -n '/stmmac_axi_blen_to_mask/,/^}/p' patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch | head -50

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Search in patch 1000 more carefully for stmmac_axi_blen_to_mask
cat patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch | grep -n "stmmac_axi_blen_to_mask"

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Get the section around that line
cat patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch | sed -n '200,350p'

Repository: armbian/build

Length of output: 4491


🏁 Script executed:

# Search for where stmmac_axi_blen_to_mask is actually defined - look for "static"
cat patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch | grep -n "axi_blen_to_mask"

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Search more broadly in patch 1000 for axi_blen related code
grep -n "axi_blen" patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch | head -20

Repository: armbian/build

Length of output: 136


🏁 Script executed:

# Let's get the stmmac_platform.c diff section from patch 1000
cat patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch | sed -n '/diff --git a\/drivers\/net\/ethernet\/stmicro\/stmmac\/stmmac_platform.c/,/^diff --git/p' | head -150

Repository: armbian/build

Length of output: 4537


🏁 Script executed:

# Let's see if stmmac_axi_blen_to_mask is a kernel standard function
# by checking web for kernel stmmac documentation
web_search stmmac_axi_blen_to_mask kernel function

Repository: armbian/build

Length of output: 107


🏁 Script executed:

# Let's search in patch 1000 for stmmac_axi_blen_to_mask function definition
# It might be added in the patch's stmmac_platform.c changes
grep -n "stmmac_axi_blen_to_mask" patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Search for it in patch 1001 as well
grep -n "stmmac_axi_blen_to_mask" patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch

Repository: armbian/build

Length of output: 129


🏁 Script executed:

# Look for stmmac related patches to understand the context better
grep -r "axi_blen_regval" patch/kernel/archive/uefi-arm64-6.12/ | head -20

Repository: armbian/build

Length of output: 243


🏁 Script executed:

# Let's search in the kernel doc or other patches for what stmmac_axi_blen_to_mask is
# Check if it's standard kernel function by searching broader context in patch 1000
cat patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch | grep -A 200 "stmmac_axi_setup_acpi" | head -80

Repository: armbian/build

Length of output: 2434


🏁 Script executed:

# Let's find where stmmac_axi_blen_to_mask is defined - search all patches in the directory
grep -r "stmmac_axi_blen_to_mask" patch/kernel/archive/uefi-arm64-6.12/ --include="*.patch"

Repository: armbian/build

Length of output: 243


🏁 Script executed:

# Check if stmmac_axi_blen_to_mask is possibly defined in one of the later patches
for f in patch/kernel/archive/uefi-arm64-6.12/*.patch; do
  echo "=== $f ==="
  grep -c "stmmac_axi_blen_to_mask" "$f" 2>/dev/null || echo "0"
done

Repository: armbian/build

Length of output: 769


🏁 Script executed:

# Let's look at all the changes in patch 1001 more carefully
cat patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch

Repository: armbian/build

Length of output: 1310


🏁 Script executed:

# Let's check if stmmac_axi_blen_to_mask might be defined in kernel headers or docs
# Search for any definition with similar name patterns
grep -r "axi_blen_to_mask\|axi_blen_regval" patch/ --include="*.patch" | head -30

Repository: armbian/build

Length of output: 430


🏁 Script executed:

# Let's understand what kernel version this is targeting
grep -i "subject\|version\|kernel" patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch | head -10

Repository: armbian/build

Length of output: 135


🏁 Script executed:

# Search what axi_blen_regval actually is - check struct definitions
grep -r "axi_blen_regval" patch/kernel/archive/uefi-arm64-6.12/ --include="*.patch" -B 2 -A 2

Repository: armbian/build

Length of output: 873


🏁 Script executed:

# Let's check if this is indeed adapting to upstream kernel changes
# by looking at the commit message context
grep -A 20 "Subject:" patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch

Repository: armbian/build

Length of output: 1125


🏁 Script executed:

# Check what the upstream kernel change was - look for any documentation
# or check if there are similar patches in 6.19
cat patch/kernel/archive/uefi-arm64-6.19/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch 2>/dev/null || echo "Not found in 6.19"

Repository: armbian/build

Length of output: 1310


🏁 Script executed:

# Let's check if stmmac_axi_blen_to_mask might be a newer kernel function
# by examining what kernel versions are involved
ls -la patch/kernel/archive/ | grep uefi-arm64

Repository: armbian/build

Length of output: 384


🏁 Script executed:

# Let's check if there's any definition or documentation of stmmac_axi_blen_to_mask
# by searching in the full patch 1000 for what might be its implementation
wc -l patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch
tail -150 patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch

Repository: armbian/build

Length of output: 5366


🏁 Script executed:

# Let's search for any structure definitions that might have axi_blen_regval
grep -r "struct stmmac_axi" patch/kernel/archive/uefi-arm64-6.12/ --include="*.patch" -A 20 | head -60

Repository: armbian/build

Length of output: 9074


🏁 Script executed:

# Let's look for AXI_BLEN constant definition
grep -r "AXI_BLEN" patch/kernel/archive/uefi-arm64-6.12/ --include="*.patch"

Repository: armbian/build

Length of output: 1014


Local array should be initialized to handle property read failures

The uninitialized u32 axi_blen[AXI_BLEN] array on line 23 receives data from fwnode_property_read_u32_array() whose return value is ignored. If the property read fails, undefined values are passed to stmmac_axi_blen_to_mask(). Initialize the array with = { 0 } to ensure deterministic defaults in hardware configuration:

-	u32 axi_blen[AXI_BLEN]; // adapt to "net: stmmac: remove axi_blen array"
+	u32 axi_blen[AXI_BLEN] = { 0 }; // adapt to "net: stmmac: remove axi_blen array"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
+ u32 axi_blen[AXI_BLEN]; // adapt to "net: stmmac: remove axi_blen array"
+ fwnode_property_read_u32_array(np, "snps,blen", axi_blen, AXI_BLEN);
+ stmmac_axi_blen_to_mask(&axi->axi_blen_regval, axi_blen, AXI_BLEN);
u32 axi_blen[AXI_BLEN] = { 0 }; // adapt to "net: stmmac: remove axi_blen array"
fwnode_property_read_u32_array(np, "snps,blen", axi_blen, AXI_BLEN);
stmmac_axi_blen_to_mask(&axi->axi_blen_regval, axi_blen, AXI_BLEN);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch`
around lines 22 - 24, The local array axi_blen declared as "u32
axi_blen[AXI_BLEN]" must be zero-initialized so it doesn't contain garbage if
fwnode_property_read_u32_array() fails; update the declaration of axi_blen to
initialize it (e.g., "= { 0 }") and keep calling
fwnode_property_read_u32_array(np, "snps,blen", axi_blen, AXI_BLEN) as before,
then pass the (now-initialized) axi_blen to
stmmac_axi_blen_to_mask(&axi->axi_blen_regval, axi_blen, AXI_BLEN).

Split the monolithic Phytium ethernet driver patch into multiple
focused patches for better maintainability:

- 1000: Original Phytium onboard ethernet drivers and ACPI glue
- 1001: Adapt to stmmac removal of axi_blen array
- 1002: Adapt to stmmac replace has_xxxx with core_type
- 1003: Adapt to stmmac pass struct device to init/exit methods
- 1004: Fix stmmac compilation warnings

Signed-off-by: Igor Pecovnik <igor@armbian.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch`:
- Line 520: The code currently assigns the raw return of fw_get_phy_mode(np)
into plat->phy_interface which can store negative errno values; change it to
call fw_get_phy_mode(np) into a temporary int (e.g., mode), check if mode >= 0
and only then assign plat->phy_interface = mode, otherwise leave
plat->phy_interface at its zero-initialized fallback (and optionally log a
warning); this prevents negative values from being used later by __set_bit(mode,
supported_interfaces) and phylink_create() via priv->plat->phy_interface.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5c2df651-4d37-45dc-8a52-3ad12b7ed2ec

📥 Commits

Reviewing files that changed from the base of the PR and between 86fdfd5 and d5e81f2.

📒 Files selected for processing (5)
  • patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch
  • patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch
  • patch/kernel/archive/uefi-arm64-6.12/1002-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-replace-has_xxxx-with-core_type.patch
  • patch/kernel/archive/uefi-arm64-6.12/1003-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-pass-struct-device-to-init-exit-methods.patch
  • patch/kernel/archive/uefi-arm64-6.12/1004-fix-stmmac-compilation-warnings.patch
✅ Files skipped from review due to trivial changes (2)
  • patch/kernel/archive/uefi-arm64-6.12/1003-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-pass-struct-device-to-init-exit-methods.patch
  • patch/kernel/archive/uefi-arm64-6.12/1002-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-replace-has_xxxx-with-core_type.patch
🚧 Files skipped from review as they are similar to previous changes (2)
  • patch/kernel/archive/uefi-arm64-6.12/1001-net-stmicro-stmmac-Phytium-adapt-to-net-stmmac-remove-axi_blen-array.patch
  • patch/kernel/archive/uefi-arm64-6.12/1004-fix-stmmac-compilation-warnings.patch

+ np = dev_fwnode(&(pdev->dev));
+
+ plat->mac_interface = fw_get_phy_mode(np);
+ plat->phy_interface = fw_get_phy_mode(np);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Local patch: helper return paths and assignment =="
rg -n -C2 'fw_get_phy_mode|phy-connection-mode|return -ENODEV|plat->phy_interface = fw_get_phy_mode' \
  patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch

echo
echo "== Upstream v6.12 stmmac_main.c consumers of phy_interface =="
curl -fsSL https://raw.githubusercontent.com/torvalds/linux/v6.12/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | \
  rg -n -C2 'int mode = priv->plat->phy_interface|__set_bit\(mode|phylink_create'

Repository: armbian/build

Length of output: 1393


Don't store raw fw_get_phy_mode() errors in plat->phy_interface.

Line 520 writes the helper's negative errno values straight into plat->phy_interface when ACPI omits or misstates phy-mode. This is unsafe because stmmac later uses priv->plat->phy_interface as a bit index in __set_bit(mode, supported_interfaces) and as the mode parameter to phylink_create(), so a negative value will cause a kernel panic during probe instead of preserving the zero-initialized fallback.

Suggested fix
-	plat->phy_interface = fw_get_phy_mode(np);
+	plat->phy_interface = fw_get_phy_mode(np);
+	if (plat->phy_interface < 0)
+		plat->phy_interface = PHY_INTERFACE_MODE_NA;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
+ plat->phy_interface = fw_get_phy_mode(np);
plat->phy_interface = fw_get_phy_mode(np);
if (plat->phy_interface < 0)
plat->phy_interface = PHY_INTERFACE_MODE_NA;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@patch/kernel/archive/uefi-arm64-6.12/1000-net-stmicro-stmmac-Phytium-onboard-ethernet-drivers-and-ACPI-glue-for-6.x.patch`
at line 520, The code currently assigns the raw return of fw_get_phy_mode(np)
into plat->phy_interface which can store negative errno values; change it to
call fw_get_phy_mode(np) into a temporary int (e.g., mode), check if mode >= 0
and only then assign plat->phy_interface = mode, otherwise leave
plat->phy_interface at its zero-initialized fallback (and optionally log a
warning); this prevents negative values from being used later by __set_bit(mode,
supported_interfaces) and phylink_create() via priv->plat->phy_interface.

@igorpecovnik igorpecovnik merged commit d99502e into main Mar 25, 2026
51 of 52 checks passed
@igorpecovnik igorpecovnik deleted the arm64stmmac branch March 25, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second quarter release Build Executing build train (permission needed) Hardware Hardware related like kernel, U-Boot, ... Needs review Seeking for review Patches Patches related to kernel, U-Boot, ... size/medium PR with more then 50 and less then 250 lines

Development

Successfully merging this pull request may close these issues.

1 participant