summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2022-09-16 08:32:41 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-09-22 11:31:07 +0200
commit19eabb0a16b5e2435afc4dd16718fef1cc08b6fd (patch)
tree628194f2eeae209d2e2f3dd9f21ac171b974fd4f /net
parent8fcd6851baa3a9f4c1b74bd8cf1ad784e02e6794 (diff)
downloadbarebox-19eabb0a16b5e2435afc4dd16718fef1cc08b6fd.tar.gz
net: Bring up all interfaces when going interactive
So far we only bring up network interfaces when we actually need them. This means we could be idling in the shell for long and once the user decides to do networking he has to wait for the link to be established. We can do better: Before going interactive bring up all known network interfaces which makes the links established when the user needs them. To implement this we have to rework carrier checking a bit, because otherwise barebox would wait for the links to be established before continuing. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net')
-rw-r--r--net/eth.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/net/eth.c b/net/eth.c
index bc641dc8e4..8f6ff7db3a 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -20,8 +20,6 @@
#include <linux/ctype.h>
#include <linux/stat.h>
-static uint64_t last_link_check;
-
LIST_HEAD(netdev_list);
struct eth_ethaddr {
@@ -173,7 +171,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, int force)
+static int eth_carrier_check(struct eth_device *edev, bool may_wait)
{
int ret;
@@ -183,15 +181,17 @@ static int eth_carrier_check(struct eth_device *edev, int force)
if (!edev->phydev)
return 0;
- if (force)
- phy_wait_aneg_done(edev->phydev);
-
- if (force || is_timeout(last_link_check, 5 * SECOND) ||
- !edev->phydev->link) {
+ if (!edev->last_link_check ||
+ is_timeout(edev->last_link_check, 5 * SECOND)) {
ret = phy_update_status(edev->phydev);
if (ret)
return ret;
- last_link_check = get_time_ns();
+ edev->last_link_check = get_time_ns();
+ }
+
+ if (may_wait && !edev->phydev->link) {
+ phy_wait_aneg_done(edev->phydev);
+ edev->last_link_check = get_time_ns();
}
return edev->phydev->link ? 0 : -ENETDOWN;
@@ -237,7 +237,7 @@ int eth_send(struct eth_device *edev, void *packet, int length)
if (slice_acquired(eth_device_slice(edev)))
return eth_queue(edev, packet, length);
- ret = eth_carrier_check(edev, 0);
+ ret = eth_carrier_check(edev, true);
if (ret)
return ret;
@@ -258,7 +258,7 @@ static void eth_do_work(struct eth_device *edev)
int ret;
if (!phy_acquired(edev->phydev)) {
- ret = eth_carrier_check(edev, 0);
+ ret = eth_carrier_check(edev, false);
if (ret)
return;
}
@@ -455,12 +455,12 @@ int eth_open(struct eth_device *edev)
if (edev->active)
return 0;
+ edev->last_link_check = 0;
+
ret = edev->open(edev);
if (!ret)
edev->active = 1;
- eth_carrier_check(edev, 1);
-
return ret;
}
@@ -522,6 +522,14 @@ struct eth_device *of_find_eth_device_by_node(struct device_node *np)
}
EXPORT_SYMBOL(of_find_eth_device_by_node);
+void eth_open_all(void)
+{
+ struct eth_device *edev;
+
+ list_for_each_entry(edev, &netdev_list, list)
+ eth_open(edev);
+}
+
static int of_populate_ethaddr(void)
{
char str[sizeof("xx:xx:xx:xx:xx:xx")];