Skip to content

[drivers][ethernet] Add Realtek RTL8125 PCI Ethernet driver - #11944

Open
GuEe-GUI wants to merge 1 commit into
RT-Thread:masterfrom
GuEe-GUI:rtl8125
Open

GuEe-GUI wants to merge 1 commit into
RT-Thread:masterfrom
GuEe-GUI:rtl8125

Conversation

@GuEe-GUI

Copy link
Copy Markdown
Contributor

拉取/合并请求描述:(PR description)

[

  • add native PCI support for RTL8125, RTL8162, and compatible controllers
  • implement descriptor-ring DMA, interrupt-driven RX, TX completion, and link reporting
  • support MAC/PHY OCP access and 10/100/1000/2500M auto-negotiation
  • add Kconfig integration with lwIP software checksum requirement
  • add optional hardware PTP clock support with time adjustment and PPS control

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

- add native PCI support for RTL8125, RTL8162, and compatible controllers
- implement descriptor-ring DMA, interrupt-driven RX, TX completion, and link reporting
- support MAC/PHY OCP access and 10/100/1000/2500M auto-negotiation
- add Kconfig integration with lwIP software checksum requirement
- add optional hardware PTP clock support with time adjustment and PPS control

Signed-off-by: GuEe-GUI <2991707448@qq.com>
@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 rtl8125
    Enter PR branch rtl8125 in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 rtl8125 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the rtl8125 branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/drivers/ethernet/Kconfig
  • components/drivers/ethernet/realtek/Kconfig
  • components/drivers/ethernet/realtek/SConscript
  • components/drivers/ethernet/realtek/r8125.c
  • components/drivers/ethernet/realtek/r8125.h
  • components/drivers/ethernet/realtek/r8125_ptp.c

📊 Current Review Status (Last Updated: 2026-10-30 11:25 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@GuEe-GUI

Copy link
Copy Markdown
Contributor Author

@Rbb666

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

下面 6 处需要修改,涉及构建依赖、PHY 读取、设备卸载和收包处理,请修复后再合入。已检查相关调用流程,并做了部分函数的模拟验证,尚未做 RTL8125 实机测试。

@@ -0,0 +1,22 @@
config RT_ETHERNET_REALTEK
bool "Realtek RTL8125 Ethernet"
depends on RT_USING_PCI

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] 补上 DMA 依赖

这里需要加上 select RT_USING_DMA。目前可以选出 RT_ETHERNET_REALTEK=y、RT_USING_DMA=n 的配置,但驱动无条件调用 rt_dma_alloc_coherent() 和 rt_dma_free_coherent()。DMA 关闭时,rtdevice.h 不包含对应头文件,DMA 源文件也不参与构建,会导致编译或链接失败。RT_USING_PCI 本身没有选中 DMA。

for (int i = 0; i < 1000; ++i)
{
rt_hw_us_delay(10);
if (!(RTL_R32(eth, R8125_PHYAR) & R8125_PHYAR_FLAG))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] MDIO 读取完成条件写反了

PHYAR 读操作应等 R8125_PHYAR_FLAG 置位后再取数据,这里在标志仍为 0 时就退出了。若第一次检查时读取尚未完成,会返回无效数据;调用方可能因此误判 BMCR 的复位位已经清零,继续配置自协商。请修正退出条件,并在超时时返回错误,避免继续使用未完成的读取结果。

if (eth->net_registered)
{
eth_device_linkchange(&eth->parent, RT_FALSE);
eth_device_deinit(&eth->parent);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] 等网络线程处理完通知后再释放设备

eth_device_linkchange() 会把设备指针放入接收线程的邮箱,下一行 eth_device_deinit() 就释放了 netif,外层 remove 随后还会释放 eth。如果接收线程尚未处理这条通知,就会访问已释放的对象。已有的收发请求也需要考虑。请先停止新的收发和通知,等待已投递的请求处理完,再释放 netif、描述符和设备对象。

if (eth->irq_installed)
{
r8125_intr_mask(eth);
rt_hw_interrupt_mask(eth->irq);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] 卸载时需要注销 ISR,不能直接屏蔽共享 INTx

rt_hw_interrupt_mask() 只屏蔽中断线,不会移除之前安装的 ISR。这里使用的是共享 INTx,屏蔽整条线会影响其他设备;后续这条线重新启用时,旧 ISR 还会拿着已经释放的 eth 执行。请关闭本设备的中断源,并调用 rt_hw_interrupt_uninstall() 或对应的 PIC 接口注销回调,确认没有正在执行的回调后再释放对象。


static void r8125_set_rx_filter(struct r8125_eth *eth)
{
rt_uint32_t rx_mode = R8125_RX_ACCEPT_BCAST | R8125_RX_ACCEPT_MY_PHYS;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] 接收过滤器没有开启组播

这里只接受广播和本机单播,没有设置 R8125_RX_ACCEPT_MCAST。即使下面把 MAR 全部置一,组播报文仍然无法通过过滤,IPv6 邻居发现、路由通告和 IPv4 组播都会受影响。当前没有实现组播过滤回调,建议先开启组播接收;如果要按地址过滤,需要接上 lwIP 的相应回调。

_done:
r8125_rx_refill(eth, eth->rx_tail);
eth->rx_tail = R8125_NEXT_RX(eth->rx_tail);
return p;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] 丢弃当前报文后需要继续检查后面的描述符

长度非法或 pbuf_alloc() 失败时,这里回收一个描述符后就返回空指针,前面的错误帧分支也一样。lwIP 接收线程把空指针当作本轮收包结束;如果同一次中断对应的后续描述符已经完成,它们可能一直等到下次中断才被处理。请在丢包后继续遍历,直到找到可交付的报文,或下一个描述符仍归硬件所有时再返回空指针。

@Rbb666 Rbb666 closed this Oct 30, 2026
@Rbb666 Rbb666 reopened this Oct 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants