mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [RFC PATCH 1/2] net: ifup: prefer interfaces where the link is already up
Date: Wed, 25 Jan 2023 10:52:35 +0100	[thread overview]
Message-ID: <20230125095236.2626065-1-a.fatoum@pengutronix.de> (raw)

ifup -a on a platform with a DSA switch can take quite a while, because
barebox will attempt sending a DHCP DISCOVER on every port in sequence
and waiting until timeout. This could use some refactoring to make it
possible to make dhcp() non-blocking, but let's do an easier workaround
for that: Let's prefer ports that already have a link-up, which is the
case if the user has been sitting idly on the shell for a few seconds,
because we enable all interfaces that weren't explicitly disabled then.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/net.h | 1 +
 net/eth.c     | 2 +-
 net/ifup.c    | 8 ++++++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/net.h b/include/net.h
index 0555b0bd6bed..fdd21481dbf5 100644
--- a/include/net.h
+++ b/include/net.h
@@ -110,6 +110,7 @@ int eth_register(struct eth_device* dev);    /* Register network device		*/
 void eth_unregister(struct eth_device* dev); /* Unregister network device	*/
 int eth_set_ethaddr(struct eth_device *edev, const char *ethaddr);
 int eth_open(struct eth_device *edev);
+int eth_carrier_check(struct eth_device *edev, bool may_wait);
 void eth_close(struct eth_device *edev);
 int eth_send(struct eth_device *edev, void *packet, int length);	   /* Send a packet		*/
 int eth_rx(void);			/* Check for received packets	*/
diff --git a/net/eth.c b/net/eth.c
index 6fb64afea024..6c201d7dfc30 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -179,7 +179,7 @@ int eth_complete(struct string_list *sl, char *instr)
 /*
  * Check for link if we haven't done so for longer.
  */
-static int eth_carrier_check(struct eth_device *edev, bool may_wait)
+int eth_carrier_check(struct eth_device *edev, bool may_wait)
 {
 	int ret;
 
diff --git a/net/ifup.c b/net/ifup.c
index e4d5374db3ae..a0167eeb8a82 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -285,6 +285,14 @@ int ifup_all(unsigned flags)
 	    list_empty(&netdev_list))
 		device_detect_all();
 
+	/* Prefer interfaces where the link is already up */
+	for_each_netdev(edev) {
+		if (eth_carrier_check(edev, false))
+			continue;
+
+		ifup_edev(edev, flags);
+	}
+
 	for_each_netdev(edev)
 		ifup_edev(edev, flags);
 
-- 
2.30.2




             reply	other threads:[~2023-01-25  9:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25  9:52 Ahmad Fatoum [this message]
2023-01-25  9:52 ` [RFC PATCH 2/2] net: ifup: have ifup -a stop at the first interface Ahmad Fatoum
2023-01-26  8:36   ` Sascha Hauer
2023-01-26  8:31 ` [RFC PATCH 1/2] net: ifup: prefer interfaces where the link is already up Sascha Hauer

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=20230125095236.2626065-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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