From 68095474915c95f9271151e2e8eece48bee05200 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 15 Oct 2015 23:10:59 +0800 Subject: [PATCH] [lwIP] Add ETHIF_LINK_AUTOUP/PHYUP flag to ethernet interface --- components/net/lwip-1.4.1/src/arch/sys_arch.c | 7 ++++--- .../net/lwip-1.4.1/src/include/netif/ethernetif.h | 10 +++++++--- components/net/lwip-1.4.1/src/netif/ethernetif.c | 14 ++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/components/net/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip-1.4.1/src/arch/sys_arch.c index d3a69f9ac3..c0aed9d4f0 100644 --- a/components/net/lwip-1.4.1/src/arch/sys_arch.c +++ b/components/net/lwip-1.4.1/src/arch/sys_arch.c @@ -115,9 +115,10 @@ static void tcpip_init_done_callback(void *arg) netif_set_up(ethif->netif); } -#if LWIP_NETIF_LINK_CALLBACK - netif_set_link_up(ethif->netif); -#endif + if (!(ethif->flags & ETHIF_LINK_PHYUP)) + { + netif_set_link_up(ethif->netif); + } /* enter critical */ rt_enter_critical(); diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 2019df7017..bdad32ec20 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -11,6 +11,10 @@ #define ETHERNET_MTU RT_LWIP_ETH_MTU #endif +/* eth flag with auto_linkup or phy_linkup */ +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 + struct eth_device { /* inherit from rt_device */ @@ -20,9 +24,9 @@ struct eth_device struct netif *netif; struct rt_semaphore tx_ack; - rt_uint8_t flags; + rt_uint16_t flags; rt_uint8_t link_changed; - rt_uint16_t link_status; + rt_uint8_t link_status; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); @@ -31,7 +35,7 @@ struct eth_device rt_err_t eth_device_ready(struct eth_device* dev); rt_err_t eth_device_init(struct eth_device * dev, char *name); -rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flag); +rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint16_t flag); rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up); int eth_system_device_init(void); diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 2e0ef2f8bd..f0b2f814dc 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -154,7 +154,7 @@ static err_t eth_netif_device_init(struct netif *netif) } /* copy device flags to netif flags */ - netif->flags = ethif->flags; + netif->flags = (ethif->flags & 0xff); /* set default netif */ if (netif_default == RT_NULL) @@ -173,9 +173,11 @@ static err_t eth_netif_device_init(struct netif *netif) netif_set_up(ethif->netif); } -#ifdef LWIP_NETIF_LINK_CALLBACK - netif_set_link_up(ethif->netif); -#endif + if (!(ethif->flags & ETHIF_LINK_PHYUP)) + { + /* set link_up for this netif */ + netif_set_link_up(ethif->netif); + } return ERR_OK; } @@ -184,7 +186,7 @@ static err_t eth_netif_device_init(struct netif *netif) } /* Keep old drivers compatible in RT-Thread */ -rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flags) +rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint16_t flags) { struct netif* netif; @@ -246,7 +248,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_ rt_err_t eth_device_init(struct eth_device * dev, char *name) { - rt_uint8_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; + rt_uint16_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; #if LWIP_DHCP /* DHCP support */ -- GitLab