diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2020-03-11 13:41:49 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-03-31 12:35:45 +0200 |
commit | 18cce41473e3c2dbeb50e28daed36411112d72df (patch) | |
tree | c7bbf2c1589a148aa77e69a0d4da1afa154503f7 /net | |
parent | 6a58ec609eec5b28d7ee72fcfd65efb864612234 (diff) | |
download | barebox-18cce41473e3c2dbeb50e28daed36411112d72df.tar.gz barebox-18cce41473e3c2dbeb50e28daed36411112d72df.tar.xz |
net: Open ethernet devices explicitly
Open ethernet devices explicitly rather than implicitly when sending
packets. This allows us to not only enable, but in the next step to
also disable ethernet devices.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net')
-rw-r--r-- | net/dhcp.c | 4 | ||||
-rw-r--r-- | net/eth.c | 55 | ||||
-rw-r--r-- | net/ifup.c | 4 |
3 files changed, 36 insertions, 27 deletions
diff --git a/net/dhcp.c b/net/dhcp.c index 670a6a6422..a27fa89996 100644 --- a/net/dhcp.c +++ b/net/dhcp.c @@ -609,6 +609,10 @@ int dhcp(struct eth_device *edev, const struct dhcp_req_param *param) struct dhcp_result *res; int ret; + ret = eth_open(edev); + if (ret) + return ret; + ret = dhcp_request(edev, param, &res); if (ret) return ret; @@ -211,33 +211,12 @@ static int eth_carrier_check(struct eth_device *edev, int force) return edev->phydev->link ? 0 : -ENETDOWN; } -/* - * Check if we have a current ethernet device and - * eventually open it if we have to. - */ -static int eth_check_open(struct eth_device *edev) -{ - int ret; - - if (edev->active) - return 0; - - ret = edev->open(edev); - if (ret) - return ret; - - edev->active = 1; - - return eth_carrier_check(edev, 1); -} - int eth_send(struct eth_device *edev, void *packet, int length) { int ret; - ret = eth_check_open(edev); - if (ret) - return ret; + if (!edev->active) + return -ENETDOWN; ret = eth_carrier_check(edev, 0); if (ret) @@ -252,10 +231,6 @@ static int __eth_rx(struct eth_device *edev) { int ret; - ret = eth_check_open(edev); - if (ret) - return ret; - ret = eth_carrier_check(edev, 0); if (ret) return ret; @@ -422,6 +397,32 @@ int eth_register(struct eth_device *edev) return 0; } +int eth_open(struct eth_device *edev) +{ + int ret; + + if (edev->active) + return 0; + + ret = edev->open(edev); + if (!ret) + edev->active = 1; + + eth_carrier_check(edev, 1); + + return ret; +} + +void eth_close(struct eth_device *edev) +{ + if (!edev->active) + return; + + edev->halt(edev); + + edev->active = 0; +} + void eth_unregister(struct eth_device *edev) { if (edev->active) diff --git a/net/ifup.c b/net/ifup.c index d550f82530..e5e8ef2346 100644 --- a/net/ifup.c +++ b/net/ifup.c @@ -214,6 +214,10 @@ int ifup_edev(struct eth_device *edev, unsigned flags) if (ret) return ret; + ret = eth_open(edev); + if (ret) + return ret; + if (edev->global_mode == ETH_MODE_DHCP) { if (IS_ENABLED(CONFIG_NET_DHCP)) { ret = dhcp(edev, NULL); |