diff mbox series

[v5,06/20] net: eth-uclass: add function eth_start_udev()

Message ID c012639090f4a45f004768b8e7840e3e81867ca1.1721910373.git.jerome.forissier@linaro.org
State Superseded
Headers show
Series Introduce the lwIP network stack | expand

Commit Message

Jerome Forissier July 25, 2024, 12:57 p.m. UTC
Add a function to start a given etwork device, and update eth_init()
to use it.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 include/net-common.h |  1 +
 net/eth-uclass.c     | 38 +++++++++++++++++++++++++-------------
 2 files changed, 26 insertions(+), 13 deletions(-)

Comments

Tom Rini July 25, 2024, 6:27 p.m. UTC | #1
On Thu, Jul 25, 2024 at 02:57:27PM +0200, Jerome Forissier wrote:

> Add a function to start a given etwork device, and update eth_init()

Typo, "network".

> to use it.
> 
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>

And this is where most of the tiny and acceptable growth comes from in
the legacy network case.

Reviewed-by: Tom Rini <trini@konsulko.com>

But, does the lwIP side end up calling this too then, and so the need to
split this out and not have it be static?
Jerome Forissier July 26, 2024, 8:38 a.m. UTC | #2
On 7/25/24 20:27, Tom Rini wrote:
> On Thu, Jul 25, 2024 at 02:57:27PM +0200, Jerome Forissier wrote:
> 
>> Add a function to start a given etwork device, and update eth_init()
> 
> Typo, "network".

Fixed in v6.
 
>> to use it.
>>
>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> 
> And this is where most of the tiny and acceptable growth comes from in
> the legacy network case.
> 
> Reviewed-by: Tom Rini <trini@konsulko.com>
> 
> But, does the lwIP side end up calling this too then, and so the need to
> split this out and not have it be static?

Yes, eth_start_udev() is called by new_netif() in net/lwip/net-lwip.c.

Thanks,
diff mbox series

Patch

diff --git a/include/net-common.h b/include/net-common.h
index 29342b6eee5..b9b47197e4a 100644
--- a/include/net-common.h
+++ b/include/net-common.h
@@ -148,6 +148,7 @@  int eth_env_set_enetaddr_by_index(const char *base_name, int index,
 int usb_ether_init(void);
 
 int eth_init(void);			/* Initialize the device */
+int eth_start_udev(struct udevice *dev);
 int eth_send(void *packet, int length);	   /* Send a packet */
 #if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
 int eth_receive(void *packet, int length); /* Receive a packet*/
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index e34d7af0229..6dd9b9bb98e 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -284,6 +284,27 @@  static int on_ethaddr(const char *name, const char *value, enum env_op op,
 }
 U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr);
 
+int eth_start_udev(struct udevice *dev)
+{
+	struct eth_device_priv *priv = dev_get_uclass_priv(dev);
+	int ret;
+
+	if (priv->running)
+		return 0;
+
+	if (!device_active(dev))
+		return -EINVAL;
+
+	ret = eth_get_ops(dev)->start(dev);
+	if (ret >= 0) {
+		priv->state = ETH_STATE_ACTIVE;
+		priv->running = true;
+		ret = 0;
+	}
+
+	return ret;
+}
+
 int eth_init(void)
 {
 	struct udevice *current = NULL;
@@ -328,20 +349,11 @@  int eth_init(void)
 		if (current) {
 			debug("Trying %s\n", current->name);
 
-			if (device_active(current)) {
-				ret = eth_get_ops(current)->start(current);
-				if (ret >= 0) {
-					struct eth_device_priv *priv =
-						dev_get_uclass_priv(current);
-
-					priv->state = ETH_STATE_ACTIVE;
-					priv->running = true;
-					ret = 0;
-					goto end;
-				}
-			} else {
+			ret = eth_start_udev(current);
+			if (ret < 0)
 				ret = eth_errno;
-			}
+			else
+				goto end;
 
 			debug("FAIL\n");
 		} else {