Patchwork [U-Boot,2/2] USB-CDC: Move MAC addresses setting into usb_eth_init

login
register
mail settings
Submitter Vitaly Kuzmichev
Date Dec. 28, 2010, 1:59 p.m.
Message ID <1293544772-5175-3-git-send-email-vkuzmichev@mvista.com>
Download mbox | patch
Permalink /patch/76844/
State Accepted
Commit 58939fcc5cbda504cee943bca50c3993597710e9
Headers show

Comments

Vitaly Kuzmichev - Dec. 28, 2010, 1:59 p.m.
This allows to change device and host MAC addresses without performing
reset.

Signed-off-by: Vitaly Kuzmichev <vkuzmichev@mvista.com>
---
 drivers/usb/gadget/ether.c |   62 ++++++++++++++++++-------------------------
 1 files changed, 26 insertions(+), 36 deletions(-)
Remy Bohmer - Dec. 28, 2010, 7:56 p.m.
Hi,

2010/12/28 Vitaly Kuzmichev <vkuzmichev@mvista.com>:
> This allows to change device and host MAC addresses without performing
> reset.
>
> Signed-off-by: Vitaly Kuzmichev <vkuzmichev@mvista.com>
> ---
>  drivers/usb/gadget/ether.c |   62 ++++++++++++++++++-------------------------
>  1 files changed, 26 insertions(+), 36 deletions(-)
>

Applied to u-boot-usb.
Thanks.

Remy

Patch

diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 765fbd8..6384869 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -1788,6 +1788,32 @@  static int usb_eth_init(struct eth_device *netdev, bd_t *bd)
 		error("received NULL ptr");
 		goto fail;
 	}
+
+	/* Configure default mac-addresses for the USB ethernet device */
+#ifdef CONFIG_USBNET_DEV_ADDR
+	strlcpy(dev_addr, CONFIG_USBNET_DEV_ADDR, sizeof(dev_addr));
+#endif
+#ifdef CONFIG_USBNET_HOST_ADDR
+	strlcpy(host_addr, CONFIG_USBNET_HOST_ADDR, sizeof(host_addr));
+#endif
+	/* Check if the user overruled the MAC addresses */
+	if (getenv("usbnet_devaddr"))
+		strlcpy(dev_addr, getenv("usbnet_devaddr"),
+			sizeof(dev_addr));
+
+	if (getenv("usbnet_hostaddr"))
+		strlcpy(host_addr, getenv("usbnet_hostaddr"),
+			sizeof(host_addr));
+
+	if (!is_eth_addr_valid(dev_addr)) {
+		error("Need valid 'usbnet_devaddr' to be set");
+		goto fail;
+	}
+	if (!is_eth_addr_valid(host_addr)) {
+		error("Need valid 'usbnet_hostaddr' to be set");
+		goto fail;
+	}
+
 	if (usb_gadget_register_driver(&eth_driver) < 0)
 		goto fail;
 
@@ -1920,7 +1946,6 @@  static struct usb_gadget_driver eth_driver = {
 
 int usb_eth_initialize(bd_t *bi)
 {
-	int status = 0;
 	struct eth_device *netdev = &l_netdev;
 
 	strlcpy(netdev->name, USB_NET_NAME, sizeof(netdev->name));
@@ -1933,41 +1958,6 @@  int usb_eth_initialize(bd_t *bi)
 #ifdef CONFIG_MCAST_TFTP
   #error not supported
 #endif
-	/* Configure default mac-addresses for the USB ethernet device */
-#ifdef CONFIG_USBNET_DEV_ADDR
-	strncpy(dev_addr, CONFIG_USBNET_DEV_ADDR, sizeof(dev_addr));
-#endif
-#ifdef CONFIG_USBNET_HOST_ADDR
-	strncpy(host_addr, CONFIG_USBNET_HOST_ADDR, sizeof(host_addr));
-#endif
-	/* Check if the user overruled the MAC addresses */
-	if (getenv("usbnet_devaddr"))
-		strncpy(dev_addr, getenv("usbnet_devaddr"),
-			sizeof(dev_addr));
-
-	if (getenv("usbnet_hostaddr"))
-		strncpy(host_addr, getenv("usbnet_hostaddr"),
-			sizeof(host_addr));
-
-	/* Make sure both strings are terminated */
-	dev_addr[sizeof(dev_addr)-1] = '\0';
-	host_addr[sizeof(host_addr)-1] = '\0';
-
-	if (!is_eth_addr_valid(dev_addr)) {
-		error("Need valid 'usbnet_devaddr' to be set");
-		status = -1;
-	}
-	if (!is_eth_addr_valid(host_addr)) {
-		error("Need valid 'usbnet_hostaddr' to be set");
-		status = -1;
-	}
-	if (status)
-		goto fail;
-
 	eth_register(netdev);
 	return 0;
-
-fail:
-	error("%s failed. error = %d", __func__, status);
-	return status;
 }