From 748792d18074b48f8baa8eddd10d1a2a4fdd1c95 Mon Sep 17 00:00:00 2001 From: Chasel Date: Sat, 11 Oct 2025 08:49:36 +0000 Subject: [PATCH 1/3] =?UTF-8?q?[componentss][net][lwip][port]=20=20=20=20?= =?UTF-8?q?=201.=E4=BF=AE=E5=A4=8D=E7=BD=91=E5=8D=A1=E5=9C=A8=E5=9C=A8?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=97=B6phy=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=EF=BC=8C=E5=BD=93=E8=BF=9E=E6=8E=A5=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=94=B9=E5=8F=98=E5=90=8E=E9=87=8D=E6=96=B0=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96phy;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/lwip/port/ethernetif.c | 59 ++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/components/net/lwip/port/ethernetif.c b/components/net/lwip/port/ethernetif.c index 0f32ac85112..37c9d36950a 100644 --- a/components/net/lwip/port/ethernetif.c +++ b/components/net/lwip/port/ethernetif.c @@ -496,11 +496,14 @@ static err_t eth_netif_device_init(struct netif *netif) device = (rt_device_t) ethif; if (rt_device_init(device) != RT_EOK) { - return ERR_IF; + rt_kprintf("eth device initialization failed!\n"); } - 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"); + } } /* copy device flags to netif flags */ @@ -684,11 +687,14 @@ static err_t af_unix_eth_netif_device_init(struct netif *netif) device = (rt_device_t) ethif; if (rt_device_init(device) != RT_EOK) { - return ERR_IF; + rt_kprintf("eth device initialization failed!\n"); } - 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"); + } } /* copy device flags to netif flags */ @@ -850,23 +856,64 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) RT_ASSERT(dev != RT_NULL); + struct eth_device* enetif; + enetif = (struct eth_device*)dev->netif->state; + rt_device_t device = (rt_device_t)(&(enetif->parent)); + + level = rt_spin_lock_irqsave(&(dev->spinlock)); dev->link_changed = 0x01; if (up == RT_TRUE) + { + /* @note Check whether the eth device was successfully initialized, otherwise re-initialize */ + if (!(device->flag & RT_DEVICE_FLAG_ACTIVATED)) + { + if (rt_device_init(device) != RT_EOK) + { + rt_kprintf("eth device initialization failed!\n"); + goto err; + } + if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) + { + rt_kprintf("eth device open failed!\n"); + goto err; + } + } dev->link_status = 0x01; + } else dev->link_status = 0x00; rt_spin_unlock_irqrestore(&(dev->spinlock), level); /* post message to ethernet thread */ return rt_mb_send(ð_rx_thread_mb, (rt_ubase_t)dev); + +err: + rt_spin_unlock_irqrestore(&(dev->spinlock), level); + return -RT_ERROR; } #else /* NOTE: please not use it in interrupt when no RxThread exist */ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) { if (up == RT_TRUE) + { + /* @note Check whether the eth device was successfully initialized, otherwise re-initialize */ + if (!(device->flag & RT_DEVICE_FLAG_ACTIVATED)) + { + if (rt_device_init(device) != RT_EOK) + { + rt_kprintf("eth device initialization failed!\n"); + return -RT_ERROR; + } + if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) + { + rt_kprintf("eth device open failed!\n"); + return -RT_ERROR; + } + } netifapi_netif_set_link_up(dev->netif); + } else netifapi_netif_set_link_down(dev->netif); From 6ba687800707bf3d0e7196502f734ebab2736cfe Mon Sep 17 00:00:00 2001 From: Maihuanyi Date: Sat, 11 Oct 2025 09:15:30 +0000 Subject: [PATCH 2/3] =?UTF-8?q?[componentss][net][lwip][port]=201.?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddevice=E5=8F=98=E9=87=8F=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/lwip/port/ethernetif.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/net/lwip/port/ethernetif.c b/components/net/lwip/port/ethernetif.c index 37c9d36950a..a00eb9eca79 100644 --- a/components/net/lwip/port/ethernetif.c +++ b/components/net/lwip/port/ethernetif.c @@ -860,7 +860,6 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) enetif = (struct eth_device*)dev->netif->state; rt_device_t device = (rt_device_t)(&(enetif->parent)); - level = rt_spin_lock_irqsave(&(dev->spinlock)); dev->link_changed = 0x01; if (up == RT_TRUE) @@ -896,6 +895,10 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) /* NOTE: please not use it in interrupt when no RxThread exist */ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) { + struct eth_device* enetif; + enetif = (struct eth_device*)dev->netif->state; + rt_device_t device = (rt_device_t)(&(enetif->parent)); + if (up == RT_TRUE) { /* @note Check whether the eth device was successfully initialized, otherwise re-initialize */ From cc9db2a022385e60e53ac96d1dbd0fe493adb8fa Mon Sep 17 00:00:00 2001 From: Maihuanyi Date: Sat, 11 Oct 2025 09:19:25 +0000 Subject: [PATCH 3/3] =?UTF-8?q?[componentss][net][lwip][port]=201.?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=A3=B0=E6=98=8E=E5=92=8C=E8=B5=8B=E5=80=BC?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=AE=80=E5=8C=96=E5=B9=B6=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/lwip/port/ethernetif.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/net/lwip/port/ethernetif.c b/components/net/lwip/port/ethernetif.c index a00eb9eca79..b5c6a4b873d 100644 --- a/components/net/lwip/port/ethernetif.c +++ b/components/net/lwip/port/ethernetif.c @@ -856,8 +856,7 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) RT_ASSERT(dev != RT_NULL); - struct eth_device* enetif; - enetif = (struct eth_device*)dev->netif->state; + struct eth_device* enetif = (struct eth_device*)dev->netif->state; rt_device_t device = (rt_device_t)(&(enetif->parent)); level = rt_spin_lock_irqsave(&(dev->spinlock)); @@ -895,8 +894,7 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) /* NOTE: please not use it in interrupt when no RxThread exist */ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) { - struct eth_device* enetif; - enetif = (struct eth_device*)dev->netif->state; + struct eth_device* enetif = (struct eth_device*)dev->netif->state; rt_device_t device = (rt_device_t)(&(enetif->parent)); if (up == RT_TRUE)