U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: E Shattow <e@freeshell.de>
To: Tom Rini <trini@konsulko.com>,
	Jerome Forissier <jerome.forissier@linaro.org>
Cc: u-boot@lists.denx.de,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>,
	Adriano Cordova <adrianox@gmail.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Simon Glass <sjg@chromium.org>
Subject: Re: [PATCH] net: lwip: move eth_init() out of new_netif()
Date: Sun, 2 Feb 2025 17:58:27 -0800	[thread overview]
Message-ID: <0ef33cab-aaad-44fa-ac14-9e0ca1b88963@freeshell.de> (raw)
In-Reply-To: <20250130145026.GY1233568@bill-the-cat>



On 1/30/25 06:50, Tom Rini wrote:
> On Thu, Jan 30, 2025 at 09:22:20AM +0100, Jerome Forissier wrote:
>> 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
>>
>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
>> CC: E Shattow <e@freeshell.de>
> 
> Reported-by: E Shattow <e@freeshell.de>
> 
>> ---
>>  include/net-lwip.h  |  1 +
>>  net/lwip/dhcp.c     |  2 +-
>>  net/lwip/dns.c      |  2 +-
>>  net/lwip/net-lwip.c | 23 ++++++++++++++---------
>>  net/lwip/ping.c     |  2 +-
>>  net/lwip/tftp.c     |  2 +-
>>  net/lwip/wget.c     |  2 +-
>>  7 files changed, 20 insertions(+), 14 deletions(-)
>>
>> diff --git a/include/net-lwip.h b/include/net-lwip.h
>> index 4d7f9387d1d..64e5c720560 100644
>> --- a/include/net-lwip.h
>> +++ b/include/net-lwip.h
>> @@ -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);
>> diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c
>> index e7d9147455c..3b7e4700c6e 100644
>> --- a/net/lwip/dhcp.c
>> +++ b/net/lwip/dhcp.c
>> @@ -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) {
>> diff --git a/net/lwip/dns.c b/net/lwip/dns.c
>> index 1de63c9998b..149bdb784dc 100644
>> --- a/net/lwip/dns.c
>> +++ b/net/lwip/dns.c
>> @@ -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);
>>  }
>> diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c
>> index b863047f598..cab1dd7d483 100644
>> --- a/net/lwip/net-lwip.c
>> +++ b/net/lwip/net-lwip.c
>> @@ -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;
>> diff --git a/net/lwip/ping.c b/net/lwip/ping.c
>> index aa617530749..200a702bbb5 100644
>> --- a/net/lwip/ping.c
>> +++ b/net/lwip/ping.c
>> @@ -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;
>> diff --git a/net/lwip/tftp.c b/net/lwip/tftp.c
>> index fc4aff5f2ba..123d66b5dba 100644
>> --- a/net/lwip/tftp.c
>> +++ b/net/lwip/tftp.c
>> @@ -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;
>> diff --git a/net/lwip/wget.c b/net/lwip/wget.c
>> index b76f6c0f1d9..9aec75f9bed 100644
>> --- a/net/lwip/wget.c
>> +++ b/net/lwip/wget.c
>> @@ -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;
>> -- 
>> 2.43.0
>>
> 

I did write in-thread about the problem since that I tested this patch
successfully. With that and my appreciation for the fix:

Tested-by: E Shattow <e@freeshell.de>

      reply	other threads:[~2025-02-03  1:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-30  8:22 [PATCH] net: lwip: move eth_init() out of new_netif() Jerome Forissier
2025-01-30 14:50 ` Tom Rini
2025-02-03  1:58   ` E Shattow [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0ef33cab-aaad-44fa-ac14-9e0ca1b88963@freeshell.de \
    --to=e@freeshell.de \
    --cc=adrianox@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jerome.forissier@linaro.org \
    --cc=joe.hershberger@ni.com \
    --cc=rfried.dev@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox