]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: lwip: move eth_init() out of new_netif()
authorJerome Forissier <jerome.forissier@linaro.org>
Thu, 30 Jan 2025 08:22:20 +0000 (09:22 +0100)
committerTom Rini <trini@konsulko.com>
Wed, 12 Feb 2025 18:36:57 +0000 (12:36 -0600)
Move the initialization of the ethernet devices out of the new_netif()
function. Indeed, new_netif() accepts a struct device argument, which
is expected to be valid and active. The activation and selection of
this device are achieved by eth_init() (on first time the network
stack is used) and eth_set_current(). This is what takes care of the
ethrotate and ethact environment variables. Therefore, move these calls
to a new function: net_lwip_set_current(), and use it whenever a
net-lwip command is run.

This patch hopefully fixes the incorrect net-lwip behavior observed on
boards with multiple ethernet interfaces [1].

Tested on an i.MX8MPlus EVK equipped wih two ethernet ports. The dhcp
command succeeds whether the cable is plugged into the first or second
port.

[1] https://lists.denx.de/pipermail/u-boot/2025-January/576326.html

Reported-by: E Shattow <e@freeshell.de>
Tested-by: E Shattow <e@freeshell.de>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
include/net-lwip.h
net/lwip/dhcp.c
net/lwip/dns.c
net/lwip/net-lwip.c
net/lwip/ping.c
net/lwip/tftp.c
net/lwip/wget.c

index 4d7f9387d1d1ad3207bc5e034a9d0a3d93037c45..64e5c7205602d37c906d43e861675c6807ff6331 100644 (file)
@@ -10,6 +10,7 @@ enum proto_t {
        TFTPGET
 };
 
+void net_lwip_set_current(void);
 struct netif *net_lwip_new_netif(struct udevice *udev);
 struct netif *net_lwip_new_netif_noip(struct udevice *udev);
 void net_lwip_remove_netif(struct netif *netif);
index e7d9147455c21e44782658341650a6694460b90b..3b7e4700c6e4dfa69505db15343ff15ac695e842 100644 (file)
@@ -115,7 +115,7 @@ int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
        int ret;
        struct udevice *dev;
 
-       eth_set_current();
+       net_lwip_set_current();
 
        dev = eth_get_dev();
        if (!dev) {
index 1de63c9998b086797de83008cd52e6610776ee2f..149bdb784dceb8fc314ad847c08cc10d97cb7a6e 100644 (file)
@@ -121,7 +121,7 @@ int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
        if (argc == 3)
                var = argv[2];
 
-       eth_set_current();
+       net_lwip_set_current();
 
        return dns_loop(eth_get_dev(), name, var);
 }
index b863047f5989ba03761bfc61e2a0eb4c3d576ced..cab1dd7d483c4d69d7111444c798ca9f98d8cb88 100644 (file)
@@ -127,6 +127,20 @@ static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip,
        return 0;
 }
 
+/* Initialize the lwIP stack and the ethernet devices and set current device  */
+void net_lwip_set_current(void)
+{
+       static bool init_done;
+
+       if (!init_done) {
+               eth_init_rings();
+               eth_init();
+               lwip_init();
+               init_done = true;
+       }
+       eth_set_current();
+}
+
 static struct netif *new_netif(struct udevice *udev, bool with_ip)
 {
        unsigned char enetaddr[ARP_HLEN];
@@ -134,19 +148,10 @@ static struct netif *new_netif(struct udevice *udev, bool with_ip)
        ip4_addr_t ip, mask, gw;
        struct netif *netif;
        int ret = 0;
-       static bool first_call = true;
 
        if (!udev)
                return NULL;
 
-       if (first_call) {
-               eth_init_rings();
-               /* Pick a valid active device, if any */
-               eth_init();
-               lwip_init();
-               first_call = false;
-       }
-
        if (eth_start_udev(udev) < 0) {
                log_err("Could not start %s\n", udev->name);
                return NULL;
index aa6175307492849bab1450e430065dd4a887e7f3..200a702bbb5e0a68fcd370f8819fa7530f9279c0 100644 (file)
@@ -168,7 +168,7 @@ int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
        if (!ipaddr_aton(argv[1], &addr))
                return CMD_RET_USAGE;
 
-       eth_set_current();
+       net_lwip_set_current();
 
        if (ping_loop(eth_get_dev(), &addr) < 0)
                return CMD_RET_FAILURE;
index fc4aff5f2ba240e9f800be60cf24586750e8301b..123d66b5dba928ea4006ac7e05b03c57f35ff656 100644 (file)
@@ -280,7 +280,7 @@ int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
                goto out;
        }
 
-       eth_set_current();
+       net_lwip_set_current();
 
        if (tftp_loop(eth_get_dev(), laddr, fname, srvip, port) < 0)
                ret = CMD_RET_FAILURE;
index b76f6c0f1d9567a8b8d5c30f50de15258264380c..9aec75f9bedf8f457d3477d081122795a2a6be95 100644 (file)
@@ -354,7 +354,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
 
 int wget_do_request(ulong dst_addr, char *uri)
 {
-       eth_set_current();
+       net_lwip_set_current();
 
        if (!wget_info)
                wget_info = &default_wget_info;