Skip to contentSkip to conversation

dm: eth: Test 'ethrotate' before changing current ethernet device

PATCH New Bin Meng 3 participants 8 messages Dec 22, 2015 – Jan 3, 2016 Networking

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/2 dm: eth: Test 'ethrotate' before changing current ethernet device

In eth_current_changed(), the call to eth_get_dev() below has a side effect of rotating ethernet device if uc_priv->current == NULL. This is not what we want when 'ethrotate' variable is 'no'.

---

 net/eth.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
net/eth.c +11 -0
index 6cf3a35..6c490a6 100644
@@ -1039,6 +1039,17 @@ int eth_receive(void *packet, int length)
 static void eth_current_changed(void)
 {
 	char *act = getenv("ethact");
+	char *ethrotate;
+
+	/*
+	 * The call to eth_get_dev() below has a side effect of rotating
+	 * ethernet device if uc_priv->current == NULL. This is not what
+	 * we want when 'ethrotate' variable is 'no'.
+	 */
+	ethrotate = getenv("ethrotate");
+	if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
+		return;
+
 	/* update current ethernet name */
 	if (eth_get_dev()) {
 		if (act == NULL || strcmp(act, eth_get_name()) != 0)
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH 2/2 dm: eth: Stick to 'ethact' when 'ethrotate' is 'no' in eth_init()

When 'ethrotate' variable is set to 'no' and 'ethact' variable is already set to an ethernet device, we should stick to 'ethact'.

---

 net/eth.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
net/eth.c +20 -4
index 6c490a6..18c53bf 100644
@@ -337,14 +337,30 @@ U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr);
 
 int eth_init(void)
 {
-	struct udevice *current;
+	char *ethact = getenv("ethact");
+	char *ethrotate = getenv("ethrotate");
+	struct udevice *current = NULL;
 	struct udevice *old_current;
 	int ret = -ENODEV;
 
-	current = eth_get_dev();
+	/*
+	 * When 'ethrotate' variable is set to 'no' and 'ethact' variable
+	 * is already set to an ethernet device, we should stick to 'ethact'.
+	 */
+	if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0)) {
+		if (ethact) {
+			current = eth_get_dev_by_name(ethact);
+			if (!current)
+				return -EINVAL;
+		}
+	}
+
 	if (!current) {
-		printf("No ethernet found.\n");
-		return -ENODEV;
+		current = eth_get_dev();
+		if (!current) {
+			printf("No ethernet found.\n");
+			return -ENODEV;
+		}
 	}
 
 	old_current = current;
Signature · 1 line
1.8.2.1
#3 lore raw

PATCH 2/2 dm: eth: Stick to 'ethact' when 'ethrotate' is 'no' in eth_init()

Quoted 7 lines · Joe Hershberger
Quoted 4 lines · Bin Meng

When 'ethrotate' variable is set to 'no' and 'ethact' variable is already set to an ethernet device, we should stick to 'ethact'.

Tested on sandbox:

#4 lore raw

PATCH 2/2 dm: eth: Stick to 'ethact' when 'ethrotate' is 'no' in eth_init()

Quoted 5 lines · Simon Glass
Quoted 4 lines · Joe Hershberger
Quoted 3 lines · Bin Meng

When 'ethrotate' variable is set to 'no' and 'ethact' variable is already set to an ethernet device, we should stick to 'ethact'.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Tested on sandbox:

Applied to u-boot-dm/master, thanks!

#6 lore raw

PATCH 1/2 dm: eth: Test 'ethrotate' before changing current ethernet device

Quoted 8 lines · Joe Hershberger
Quoted 5 lines · Bin Meng

In eth_current_changed(), the call to eth_get_dev() below has a side effect of rotating ethernet device if uc_priv->current == NULL. This is not what we want when 'ethrotate' variable is 'no'.

Tested on sandbox:

#7 lore raw

PATCH 1/2 dm: eth: Test 'ethrotate' before changing current ethernet device

Quoted 6 lines · Simon Glass
Quoted 5 lines · Joe Hershberger
Quoted 4 lines · Bin Meng

In eth_current_changed(), the call to eth_get_dev() below has a side effect of rotating ethernet device if uc_priv->current == NULL. This is not what we want when 'ethrotate' variable is 'no'.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Tested on sandbox:

Applied to u-boot-dm/master, thanks!