-
Couldn't load subscription status.
- Fork 5.3k
[componentss][net][lwip][port] #10793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1.修复网卡在在注册时phy初始化失败,当连接状态改变后重新初始化phy;
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-10-11 17:21 CST)
📝 Review Instructions
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where network interface initialization failures during device registration are now handled by re-attempting PHY initialization when the link status changes.
Key changes:
- Removes error returns from device initialization/open failures, allowing the system to continue operation
- Adds re-initialization logic in
eth_device_linkchange()to retry device initialization when link comes up - Adds debug print statements to help identify initialization failures
| if (up == RT_TRUE) | ||
| { | ||
| /* @note Check whether the eth device was successfully initialized, otherwise re-initialize */ | ||
| if (!(device->flag & RT_DEVICE_FLAG_ACTIVATED)) |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable 'device' is used but not declared in this scope. In the #else block (line 897), the device variable is referenced but not defined, unlike in the #if block where it's properly declared on line 861. / 变量 'device' 在此作用域中被使用但未声明。在 #else 块(第897行)中,device 变量被引用但未定义,不像在 #if 块中在第861行正确声明。
| struct eth_device* enetif; | ||
| enetif = (struct eth_device*)dev->netif->state; | ||
| rt_device_t device = (rt_device_t)(&(enetif->parent)); | ||
|
|
||
|
|
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The variable declarations and assignments can be simplified and made more readable. Consider declaring and initializing variables in a single line where possible, and the extra empty line on 862 is unnecessary. / 变量声明和赋值可以简化并提高可读性。建议在可能的情况下在单行中声明和初始化变量,第862行的额外空行是不必要的。
| struct eth_device* enetif; | |
| enetif = (struct eth_device*)dev->netif->state; | |
| rt_device_t device = (rt_device_t)(&(enetif->parent)); | |
| struct eth_device* enetif = (struct eth_device*)dev->netif->state; | |
| rt_device_t device = (rt_device_t)(&(enetif->parent)); |
| } | ||
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | ||
| else | ||
| { | ||
| return ERR_IF; | ||
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | ||
| { | ||
| rt_kprintf("eth device open failed!\n"); | ||
| } |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the error return (ERR_IF) from device initialization failure changes the function's behavior significantly. The caller will not know that initialization failed, which could lead to undefined behavior when trying to use an uninitialized device. Consider keeping the error return or adding alternative error handling. / 从设备初始化失败中移除错误返回(ERR_IF)显著改变了函数的行为。调用者将不知道初始化失败,这可能在尝试使用未初始化的设备时导致未定义行为。建议保留错误返回或添加替代错误处理。
| return ERR_IF; | ||
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | ||
| { | ||
| rt_kprintf("eth device open failed!\n"); |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the initialization case, removing the error return from device open failure removes important error information from the caller. The function should indicate failure when critical operations like device opening fail. / 与初始化情况类似,从设备打开失败中移除错误返回会从调用者那里移除重要的错误信息。当设备打开等关键操作失败时,函数应该指示失败。
| rt_kprintf("eth device open failed!\n"); | |
| rt_kprintf("eth device open failed!\n"); | |
| return ERR_IF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Maihuanyi 这块不需要错误返回?
|
问一下你说的“如果没有插入网线会超时(没有初始化phy成功)”具体是指什么意思?能否给个说明场景和现象截图 |
|
如果板子在没有插入网线的情况下,注册网卡时会检测网线是否插入,超时后就不会打开eth外设的接口,比如eth的DMA等配置;你可以看看bsp/at32/libraries/rt_drivers/drv_emac.c的emac_speed_config函数;当连接状态改变时网口没有正真初始化的,此时工作时不正常的; |
|
LGTM |
|
返回错误就不往下跑了,lwip 就会初始化不完整
---- Replied Message ----
| From | ***@***.***> |
| Date | 10/13/2025 16:16 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [RT-Thread/rt-thread] [componentss][net][lwip][port] (PR #10793) |
@Rbb666 commented on this pull request.
In components/net/lwip/port/ethernetif.c:
{
- return ERR_IF;
+ if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
+ {
+ rt_kprintf("eth device open failed!\n");
@Maihuanyi 这块不需要错误返回?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
不太理解 “phy初始化失败” 是什么意思?phy 的初始化都是通过 MDC/MDIO 进行初始化的吧,这块如果出现了初始化失败理论上应该由驱动层进行错误处理的。 我认为这个PR应该修复的是给
|
|
另外,PR的标题需要规范下,需要说清楚这个PR解决了什么问题 |
|
我有考虑过返回netifapi_netif_add的错误码的情况,如果返回netifapi_netif_add的错误码,移除网卡设备,显示注册失败?当连接状态改变后后在重新注册一遍;
|
调用顺序是这样的:
|
|
没有提交PR前的eth_device_init_with_flag没有返回eth_device_init的错误码的(没有判断netifapi_netif_add的返回); |
|
目前我知道的驱动层需要更改的有STM32 、at32、wch->riscv的;应该还有其他的文件需要改的; |
这个问题不大,可以
这个问题不大,这个PR可以先添加 其他BSP暂时不改也不影响驱动正常使用的 |
|
if (RT_EOK!= netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input)
)
{
#ifdef RT_USING_NETDEV
netdev_del(netif);
#endif
rt_device_close(&(dev->parent));
rt_device_unregister(&(dev->parent));
rt_free(netif);
}
要删除netdev,不插入网线启动跑起来会崩溃(dma没有开启,调用eth的rx、tx回调就不死机的。
…---- 回复的原邮件 ----
| 发件人 | ***@***.***> |
| 日期 | 2025年10月13日 17:55 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.***>***@***.***> |
| 主题 | Re: [RT-Thread/rt-thread] [componentss][net][lwip][port] (PR #10793) |
Rbb666 left a comment (RT-Thread/rt-thread#10793)
没有提交PR前的eth_device_init_with_flag没有返回eth_device_init的错误码的(没有判断netifapi_netif_add的返回); 原则上eth_device_init ->eth_device_init_with_flag要返回eth_device_init层的错误码,驱动层当连接状态再判读是否注册了网卡,否则重新注册一次; 但涉及的驱动层文件比较多的,需要有人员去跟进;
这个问题不大,可以
没有提交PR前的eth_device_init_with_flag没有返回eth_device_init的错误码的(没有判断netifapi_netif_add的返回); 原则上eth_device_init ->eth_device_init_with_flag要返回eth_device_init层的错误码,驱动层当连接状态再判读是否注册了网卡,否则重新注册一次; 但涉及的驱动层文件比较多的,需要有人员去跟进;
这个问题不大,这个PR可以先添加 netifapi_netif_add 的返回值;
其他BSP暂时不改也不影响驱动正常使用的
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
修改成: return netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);就可以了吧 == |
|
只返回 return netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);就会多出一个没用的网卡,在驱动层注册一次后,ifconfig 会看到两个一样的设备,只是一个在 down ,一个在 up 状态(。・・。)👉
…---- Replied Message ----
| From | ***@***.***> |
| Date | 10/13/2025 21:42 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [RT-Thread/rt-thread] [componentss][net][lwip][port] (PR #10793) |
Rbb666 left a comment (RT-Thread/rt-thread#10793)
if (RT_EOK!= netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input) ) { #ifdef RT_USING_NETDEV netdev_del(netif); #endif rt_device_close(&(dev->parent)); rt_device_unregister(&(dev->parent)); rt_free(netif); } 要删除netdev,不插入网线启动跑起来会崩溃(dma没有开启,调用eth的rx、tx回调就不死机的。
…
---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2025年10月13日 17:55 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [RT-Thread/rt-thread] [componentss][net][lwip][port] (PR #10793) | Rbb666 left a comment (RT-Thread/rt-thread#10793) 没有提交PR前的eth_device_init_with_flag没有返回eth_device_init的错误码的(没有判断netifapi_netif_add的返回); 原则上eth_device_init ->eth_device_init_with_flag要返回eth_device_init层的错误码,驱动层当连接状态再判读是否注册了网卡,否则重新注册一次; 但涉及的驱动层文件比较多的,需要有人员去跟进; 这个问题不大,可以 没有提交PR前的eth_device_init_with_flag没有返回eth_device_init的错误码的(没有判断netifapi_netif_add的返回); 原则上eth_device_init ->eth_device_init_with_flag要返回eth_device_init层的错误码,驱动层当连接状态再判读是否注册了网卡,否则重新注册一次; 但涉及的驱动层文件比较多的,需要有人员去跟进; 这个问题不大,这个PR可以先添加 netifapi_netif_add 的返回值; 其他BSP暂时不改也不影响驱动正常使用的 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
https://github.com/RT-Thread/rt-thread/blob/a3cc23396910c41b83c60127cae8afec78d1dfb5/components/net/lwip/port/ethernetif.c#L632
修改成:
returnnetifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);
就可以了吧 ==
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
|
明天,我先关闭这个 PR,重新提一个吧
…---- Replied Message ----
| From | ***@***.***> |
| Date | 10/13/2025 21:42 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [RT-Thread/rt-thread] [componentss][net][lwip][port] (PR #10793) |
Rbb666 left a comment (RT-Thread/rt-thread#10793)
if (RT_EOK!= netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input) ) { #ifdef RT_USING_NETDEV netdev_del(netif); #endif rt_device_close(&(dev->parent)); rt_device_unregister(&(dev->parent)); rt_free(netif); } 要删除netdev,不插入网线启动跑起来会崩溃(dma没有开启,调用eth的rx、tx回调就不死机的。
…
---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2025年10月13日 17:55 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [RT-Thread/rt-thread] [componentss][net][lwip][port] (PR #10793) | Rbb666 left a comment (RT-Thread/rt-thread#10793) 没有提交PR前的eth_device_init_with_flag没有返回eth_device_init的错误码的(没有判断netifapi_netif_add的返回); 原则上eth_device_init ->eth_device_init_with_flag要返回eth_device_init层的错误码,驱动层当连接状态再判读是否注册了网卡,否则重新注册一次; 但涉及的驱动层文件比较多的,需要有人员去跟进; 这个问题不大,可以 没有提交PR前的eth_device_init_with_flag没有返回eth_device_init的错误码的(没有判断netifapi_netif_add的返回); 原则上eth_device_init ->eth_device_init_with_flag要返回eth_device_init层的错误码,驱动层当连接状态再判读是否注册了网卡,否则重新注册一次; 但涉及的驱动层文件比较多的,需要有人员去跟进; 这个问题不大,这个PR可以先添加 netifapi_netif_add 的返回值; 其他BSP暂时不改也不影响驱动正常使用的 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
https://github.com/RT-Thread/rt-thread/blob/a3cc23396910c41b83c60127cae8afec78d1dfb5/components/net/lwip/port/ethernetif.c#L632
修改成:
returnnetifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);
就可以了吧 ==
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
拉取/合并请求描述:(PR description)
[
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up