Skip to contentSkip to conversation

Add SMSC95XX support including MAC address control

PATCH RESEND Superseded Simon Glass 3 participants 16 messages Jun 10, 2011 – Jun 12, 2011

Subsystems (3)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover Add SMSC95XX support including MAC address control

The SMSC95XX is a USB hub with a built-in Ethernet adapter. This adds support for this, using the USB host network framework. The framework is extended to support setting the hardware MAC address via an environment variable, since SMSC95XX chips often have no EEPROM attached, and thus no MAC address. Documentation is added on USB networking, the auto load code is refactored to remove duplication, and the ASIX USB ethernet driver is optimized to reduce the time between successive network operations.

Changes for v2:
- Coding style cleanup
- Changed some comments as suggested
- eth_set_hwaddr -> eth_write_hwaddr
- tided up other users of eth_getenv_enetaddr_by_index()

Changes for v3:
- Drop tfpserverip patch
- Change turbo_mode to #define
- Fix tfpserverip patch bleed

Changes for v4:
- Dropped Tegra2 specific bit
- Added patch in place of tftpserverip patch, to speed up successive network commands on asix
- Fixed a few broken bits in SMSC from my testing

Changes for v5:
- Code style clean-ups in SMSC
- Cleaned up debugging of errors in SMSC driver
- Changed NULL to "eth" in eth_getenv_enetaddr_by_index() API

Changes for v6:
- Adjust documentation file according to Wolfgang's comments
- Set NET_IP_ALIGN to 0 always

Changes for v7:
- Added change logs to each patch as requested by Wolfgang

Simon Glass (5):
Add support for SMSC95XX USB 2.0 10/100MBit Ethernet Adapter Add Ethernet hardware MAC address framework to usbnet Add documentation for USB Host Networking
Put common autoload code into auto_load() function
usbeth: asix: Do a fast init if link already established

 board/davinci/common/misc.c |    2 +-
 doc/README.usb              |  157 ++++++++-
 drivers/net/designware.c    |    2 +-
 drivers/usb/eth/Makefile    |    1 +
 drivers/usb/eth/asix.c      |   36 ++-
 drivers/usb/eth/smsc95xx.c  |  878 +++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/eth/usb_ether.c |   16 +-
 include/net.h               |   25 ++-
 include/usb_ether.h         |   18 +-
 net/bootp.c                 |   75 ++---
 net/eth.c                   |   64 ++--
 11 files changed, 1185 insertions(+), 89 deletions(-)
 create mode 100644 drivers/usb/eth/smsc95xx.c
Signature · 1 line
1.7.3.1
#1 lore raw

PATCH RESEND v7 1/5 Add support for SMSC95XX USB 2.0 10/100MBit Ethernet Adapter

The SMSC95XX is a USB hub with a built-in Ethernet adapter. This adds support for this, using the USB host network framework.

Changes for v2:
- Coding style cleanup
- Changed some comments as suggested

Changes for v3:
- Change turbo_mode to #define

Changes for v4:
- Dropped Tegra2 specific bit
- Fixed a few broken bits in SMSC from my testing

Changes for v5:
- Code style clean-ups in SMSC
- Cleaned up debugging of errors in SMSC driver

Changes for v6:
- Set NET_IP_ALIGN to 0 always

---
 drivers/usb/eth/Makefile    |    1 +
 drivers/usb/eth/smsc95xx.c  |  878 +++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/eth/usb_ether.c |    7 +
 include/usb_ether.h         |   13 +
 4 files changed, 899 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/eth/smsc95xx.c
drivers/usb/eth/Makefile +1 -0
index 6a5f25a..e28793d 100644
@@ -28,6 +28,7 @@ COBJS-$(CONFIG_USB_HOST_ETHER) += usb_ether.o
 ifdef CONFIG_USB_ETHER_ASIX
 COBJS-y += asix.o
 endif
+COBJS-$(CONFIG_USB_ETHER_SMSC95XX) += smsc95xx.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/usb/eth/smsc95xx.c new file +878 -0

878 lines not on this page · raw message

drivers/usb/eth/usb_ether.c +7 -0
index 68a0883..7b55da3 100644
@@ -45,6 +45,13 @@ static const struct usb_eth_prob_dev prob_dev[] = {
 		.get_info = asix_eth_get_info,
 	},
 #endif
+#ifdef CONFIG_USB_ETHER_SMSC95XX
+	{
+		.before_probe = smsc95xx_eth_before_probe,
+		.probe = smsc95xx_eth_probe,
+		.get_info = smsc95xx_eth_get_info,
+	},
+#endif
 	{ },		/* END */
 };
 
include/usb_ether.h +13 -0
index 825c275..a7fb26b 100644
@@ -51,6 +51,11 @@ struct ueth_data {
 	unsigned char	irqinterval;	/* Intervall for IRQ Pipe */
 
 	/* private fields for each driver can go here if needed */
+#ifdef CONFIG_USB_ETHER_SMSC95XX
+	size_t rx_urb_size;  /* maximum USB URB size */
+	u32 mac_cr;  /* MAC control register value */
+	int have_hwaddr;  /* 1 if we have a hardware MAC address */
+#endif
 };
 
 /*
@@ -65,4 +70,12 @@ int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
 		      struct eth_device *eth);
 #endif
 
+#ifdef CONFIG_USB_ETHER_SMSC95XX
+void smsc95xx_eth_before_probe(void);
+int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
+			struct ueth_data *ss);
+int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
+			struct eth_device *eth);
+#endif
+
 #endif /* __USB_ETHER_H__ */
Signature · 1 line
1.7.3.1
#2 lore raw

PATCH RESEND v7 1/5 Add support for SMSC95XX USB 2.0 10/100MBit Ethernet Adapter

Hi Simon,

drivers/usb/eth/smsc95xx.c line 875

Quoted 13 lines · Simon Glass
drivers/usb/eth/smsc95xx.c new file +13 -0
+int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
+				struct eth_device *eth)
+{
+	debug("** %s()\n", __func__);
+	if (!eth) {
+		debug("%s: missing parameter.\n", __func__);
+		return 0;
+	}
+	sprintf(eth->name, "%s%d", SMSC95XX_BASE_NAME, curr_eth_dev++);
+	eth->init = smsc95xx_init;
+	eth->send = smsc95xx_send;
+	eth->recv = smsc95xx_recv;
+	eth->halt = smsc95xx_halt;

as Gilles in "Re: [U-Boot] TFTP support for Pandaboard (OMAP4430 Cortex-A9 Dual core)", you need

+ eth->write_hwaddr = smsc95xx_write_hwaddr;

here else setting MAC address using setenv usbethaddr doesn't work

Eric

#3 lore raw

PATCH RESEND v7 1/5 Add support for SMSC95XX USB 2.0 10/100MBit Ethernet Adapter

Quoted 21 lines · Eric B?nard

Hi Simon,

Quoted 4 lines · Simon Glass
(quoted diff) +3 -0
+int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct eth_device *eth)
+{

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ? ? ? debug("** %s()\n", __func__);
+ ? ? ? if (!eth) {
+ ? ? ? ? ? ? ? debug("%s: missing parameter.\n", __func__);
+ ? ? ? ? ? ? ? return 0;
+ ? ? ? }
+ ? ? ? sprintf(eth->name, "%s%d", SMSC95XX_BASE_NAME, curr_eth_dev++);
+ ? ? ? eth->init = smsc95xx_init;
+ ? ? ? eth->send = smsc95xx_send;
+ ? ? ? eth->recv = smsc95xx_recv;
+ ? ? ? eth->halt = smsc95xx_halt;

as Gilles in "Re: [U-Boot] TFTP support for Pandaboard (OMAP4430 Cortex-A9 Dual core)", you need

Quoted 3 lines

+ ? ? ? eth->write_hwaddr = smsc95xx_write_hwaddr;

here else setting MAC address using setenv usbethaddr doesn't work

Hi Eric,

OK thanks have added Gilles' patch and will resend the series on Monday with any comments received. If this can get applied then perhaps we can more easily handle other patches that come up. This driver is by no means perfect but it is a start.

Regards,
Simon

Quoted 3 lines

Eric

#4 lore raw

PATCH RESEND v7 1/5 Add support for SMSC95XX USB 2.0 10/100MBit Ethernet Adapter

Quoted 5 lines · Simon Glass

OK thanks have added Gilles' patch and will resend the series on Monday with any comments received. If this can get applied then perhaps we can more easily handle other patches that come up. This driver is by no means perfect but it is a start.

a very good start as it simply works ;-)

Thanks !
Eric

#5 lore raw

PATCH RESEND v7 2/5 Add Ethernet hardware MAC address framework to usbnet

In reply to Simon Glass

Built-in Ethernet adapters support setting the mac address by means of a ethaddr environment variable for each interface (ethaddr, eth1addr, eth2addr).

This adds similar support to the USB network side, using the names usbethaddr, usbeth1addr, etc. They are kept separate since we don't want a USB device taking the MAC address of a built-in device or vice versa.

Changes for v2:
- eth_set_hwaddr -> eth_write_hwaddr
- tided up other users of eth_getenv_enetaddr_by_index()

Changes for v5:
- Changed NULL to "eth" in eth_getenv_enetaddr_by_index() API

---
 board/davinci/common/misc.c |    2 +-
 drivers/net/designware.c    |    2 +-
 drivers/usb/eth/usb_ether.c |    9 +++++-
 include/net.h               |   25 ++++++++++++++++-
 net/eth.c                   |   64 ++++++++++++++++++++++++++-----------------
 5 files changed, 72 insertions(+), 30 deletions(-)
board/davinci/common/misc.c +1 -1
index 2bfdf23..53d6aa1 100644
@@ -101,7 +101,7 @@ void davinci_sync_env_enetaddr(uint8_t *rom_enetaddr)
 {
 	uint8_t env_enetaddr[6];
 
-	eth_getenv_enetaddr_by_index(0, env_enetaddr);
+	eth_getenv_enetaddr_by_index("eth", 0, env_enetaddr);
 	if (!memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
 		/* There is no MAC address in the environment, so we initialize
 		 * it from the value in the EEPROM. */
drivers/net/designware.c +1 -1
index 3f5eeb7..02ba393 100644
@@ -500,7 +500,7 @@ int designware_initialize(u32 id, ulong base_addr, u32 phy_addr)
 	dev->iobase = (int)base_addr;
 	dev->priv = priv;
 
-	eth_getenv_enetaddr_by_index(id, &dev->enetaddr[0]);
+	eth_getenv_enetaddr_by_index("eth", id, &dev->enetaddr[0]);
 
 	priv->dev = dev;
 	priv->mac_regs_p = (struct eth_mac_regs *)base_addr;
drivers/usb/eth/usb_ether.c +7 -2
index 7b55da3..6565ea5 100644
@@ -80,6 +80,7 @@ int is_eth_dev_on_usb_host(void)
  */
 static void probe_valid_drivers(struct usb_device *dev)
 {
+	struct eth_device *eth;
 	int j;
 
 	for (j = 0; prob_dev[j].probe && prob_dev[j].get_info; j++) {
@@ -88,9 +89,10 @@ static void probe_valid_drivers(struct usb_device *dev)
 		/*
 		 * ok, it is a supported eth device. Get info and fill it in
 		 */
+		eth = &usb_eth[usb_max_eth_dev].eth_dev;
 		if (prob_dev[j].get_info(dev,
 			&usb_eth[usb_max_eth_dev],
-			&usb_eth[usb_max_eth_dev].eth_dev)) {
+			eth)) {
 			/* found proper driver */
 			/* register with networking stack */
 			usb_max_eth_dev++;
@@ -100,7 +102,10 @@ static void probe_valid_drivers(struct usb_device *dev)
 			 * call since eth_current_changed (internally called)
 			 * relies on it
 			 */
-			eth_register(&usb_eth[usb_max_eth_dev - 1].eth_dev);
+			eth_register(eth);
+			if (eth_write_hwaddr(eth, "usbeth",
+					usb_max_eth_dev - 1))
+				puts("Warning: failed to set MAC address\n");
 			break;
 			}
 		}
include/net.h +24 -1
index 018a744..ce54825 100644
@@ -128,7 +128,18 @@ extern int eth_get_dev_index (void);		/* get the device index */
 extern void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
 extern int eth_getenv_enetaddr(char *name, uchar *enetaddr);
 extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr);
-extern int eth_getenv_enetaddr_by_index(int index, uchar *enetaddr);
+
+/*
+ * Get the hardware address for an ethernet interface .
+ * Args:
+ *	base_name - base name for device (normally "eth")
+ *	index - device index number (0 for first)
+ *	enetaddr - returns 6 byte hardware address
+ * Returns:
+ *	Return true if the address is valid.
+ */
+extern int eth_getenv_enetaddr_by_index(const char *base_name, int index,
+					uchar *enetaddr);
 
 extern int usb_eth_initialize(bd_t *bi);
 extern int eth_init(bd_t *bis);			/* Initialize the device */
@@ -141,6 +152,18 @@ extern int eth_rx(void);			/* Check for received packets */
 extern void eth_halt(void);			/* stop SCC */
 extern char *eth_get_name(void);		/* get name of current device */
 
+/*
+ * Set the hardware address for an ethernet interface based on 'eth%daddr'
+ * environment variable (or just 'ethaddr' if eth_number is 0).
+ * Args:
+ *	base_name - base name for device (normally "eth")
+ *	eth_number - value of %d (0 for first device of this type)
+ * Returns:
+ *	0 is success, non-zero is error status from driver.
+ */
+int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
+		     int eth_number);
+
 #ifdef CONFIG_MCAST_TFTP
 int eth_mcast_join( IPaddr_t mcast_addr, u8 join);
 u32 ether_crc (size_t len, unsigned char const *p);
net/eth.c +39 -25

96 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#6 lore raw

PATCH RESEND v7 3/5 Add documentation for USB Host Networking

In reply to Simon Glass

This describes what it is for, devices supported, how to enable for your board in U-Boot, setting up the server, and notes about MAC addresses.

Changes for v6:
- Adjust documentation file according to Wolfgang's comments

---
 doc/README.usb |  157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 156 insertions(+), 1 deletions(-)
doc/README.usb +156 -1
index 9aa4f62..a8a4058 100644
@@ -79,4 +79,159 @@ CONFIG_USB_UHCI	    defines the lowlevel part.A lowlevel part must be defined
 		    if using CONFIG_CMD_USB
 CONFIG_USB_KEYBOARD enables the USB Keyboard
 CONFIG_USB_STORAGE  enables the USB storage devices
-CONFIG_USB_HOST_ETHER	enables USB ethernet dongle support
+CONFIG_USB_HOST_ETHER	enables USB ethernet adapter support
+
+
+USB Host Networking
+===================
+
+If you have a supported USB Ethernet adapter you can use it in U-Boot
+to obtain an IP address and load a kernel from a network server.
+
+Note: USB Host Networking is not the same as making your board act as a USB
+client. In that case your board is pretending to be an Ethernet adapter
+and will appear as a network interface to an attached computer. In that
+case the connection is via a USB cable with the computer acting as the host.
+
+With USB Host Networking, your board is the USB host. It controls the
+Ethernet adapter to which it is directly connected and the connection to
+the outside world is your adapter's Ethernet cable. Your board becomes an
+independent network device, able to connect and perform network operations
+independently of your computer.
+
+
+Device support
+--------------
+
+Currently supported devices are listed in the drivers according to
+their vendor and product IDs. You can check your device by connecting it
+to a Linux machine and typing 'lsusb'. The drivers are in
+drivers/usb/eth.
+
+For example this lsusb output line shows a device with Vendor ID 0x0x95
+and product ID 0x7720:
+
+Bus 002 Device 010: ID 0b95:7720 ASIX Electronics Corp. AX88772
+
+If you look at drivers/usb/eth/asix.c you will see this line within the
+supported device list, so we know this adapter is supported.
+
+        { 0x0b95, 0x7720 },     /* Trendnet TU2-ET100 V3.0R */
+
+If your adapter is not listed there is a still a chance that it will
+work. Try looking up the manufacturer of the chip inside your adapter.
+or take the adapter apart and look for chip markings. Then add a line
+for your vendor/product ID into the table of the appropriate driver,
+build U-Boot and see if it works. If not then there might be differences
+between the chip in your adapter and the driver. You could try to get a
+datasheet for your device and add support for it to U-Boot. This is not
+particularly difficult - you only need to provide support for four basic
+functions: init, halt, send and recv.
+
+
+Enabling USB Host Networking
+----------------------------
+
+The normal U-Boot commands are used with USB networking, but you must
+start USB first. For example:
+
+usb start
+setenv bootfile /tftpboot/uImage
+bootp
+
+
+To enable USB Host Ethernet in U-Boot, your platform must of course
+support USB with CONFIG_CMD_USB enabled and working. You will need to
+add some config settings to your board header file:
+
+#define CONFIG_USB_HOST_ETHER   /* Enable USB Ethernet adapters */
+#define CONFIG_USB_ETHER_ASIX   /* Asix, or whatever driver(s) you want */
+
+As with built-in networking, you will also want to enable some network
+commands, for example:
+
+#define CONFIG_CMD_NET
+#define CONFIG_NET_MULTI
+#define CONFIG_CMD_PING
+#define CONFIG_CMD_DHCP
+
+and some bootp options, which tell your board to obtain its subnet,
+gateway IP, host name and boot path from the bootp/dhcp server. These
+settings should start you off:
+
+#define CONFIG_BOOTP_SUBNETMASK
+#define CONFIG_BOOTP_GATEWAY
+#define CONFIG_BOOTP_HOSTNAME
+#define CONFIG_BOOTP_BOOTPATH
+
+You can also set the default IP address of your board and the server
+as well as the default file to load when a 'bootp' command is issued.
+All of these can be obtained from the bootp server if not set.
+
+#define CONFIG_IPADDR           10.0.0.2  (replace with your value)
+#define CONFIG_SERVERIP         10.0.0.1  (replace with your value)
+#define CONFIG_BOOTFILE         uImage
+
+
+The 'usb start' command should identify the adapter something like this:
+
+CrOS> usb start
+(Re)start USB...
+USB EHCI 1.00
+scanning bus for devices... 3 USB Device(s) found
+       scanning bus for storage devices... 0 Storage Device(s) found
+       scanning bus for ethernet devices... 1 Ethernet Device(s) found
+CrOS> print ethact
+ethact=asx0
+
+You can see that it found an ethernet device and we can print out the
+device name (asx0 in this case).
+
+Then 'bootp' or 'dhcp' should use it to obtain an IP address from DHCP,
+perhaps something like this:
+
+CrOS> bootp
+Waiting for Ethernet connection... done.
+BOOTP broadcast 1
+BOOTP broadcast 2
+DHCP client bound to address 172.22.73.81
+Using asx0 device
+TFTP from server 172.22.72.144; our IP address is 172.22.73.81
+Filename '/tftpboot/uImage-sjg-seaboard-261347'.
+Load address: 0x40c000
+Loading: #################################################################
+         #################################################################
+         #################################################################
+         ################################################
+done
+Bytes transferred = 3557464 (364858 hex)
+CrOS>
+
+
+Another way of doing this is to issue a tftp command, which will cause the
+bootp to happen automatically.
+
+
+MAC Addresses
+-------------
+
+Most Ethernet dongles have a built-in MAC address which is unique in the
+world. This is important so that devices on the network can be
+distinguised from each other. MAC address conflicts are evil and
+generally result in strange and eratic behaviour.
+
+Some boards have USB Ethernet chips on-board, and these sometimes do not
+have an assigned MAC address. In this case it is up to you to assign
+one which is unique. You should obtain a valid MAC address from a range
+assigned to you before you ship the product.
+
+Built-in Ethernet adapters support setting the MAC address by means of
+an ethaddr environment variable for each interface (ethaddr, eth1addr,
+eth2addr). There is similar support on the USB network side, using the
+names usbethaddr, usbeth1addr, etc. They are kept separate since we
+don't want a USB device taking the MAC address of a built-in device or
+vice versa.
+
+So if your USB Ethernet chip doesn't have a MAC address available then
+you must set usbethaddr to a suitable MAC address. At the time of
+writing this functionality is only supported by the SMSC driver.
Signature · 1 line
1.7.3.1
#7 lore raw

PATCH RESEND v7 4/5 Put common autoload code into auto_load() function

In reply to Simon Glass

This is a small clean-up patch.

---
 net/bootp.c |   75 +++++++++++++++++++++++++---------------------------------
 1 files changed, 32 insertions(+), 43 deletions(-)
net/bootp.c +32 -43
index 4db63cb..4774624 100644
@@ -138,6 +138,35 @@ static int truncate_sz (const char *name, int maxlen, int curlen)
 	return (curlen);
 }
 
+/*
+ * Check if autoload is enabled. If so, use either NFS or TFTP to download
+ * the boot file.
+ */
+static void auto_load(void)
+{
+	const char *s = getenv("autoload");
+
+	if (s != NULL) {
+		if (*s == 'n') {
+			/*
+			 * Just use BOOTP to configure system;
+			 * Do not use TFTP to load the bootfile.
+			 */
+			NetState = NETLOOP_SUCCESS;
+			return;
+		}
+#if defined(CONFIG_CMD_NFS)
+		if (strcmp(s, "NFS") == 0) {
+			/*
+			 * Use NFS to load the bootfile.
+			 */
+			NfsStart();
+			return;
+		}
+#endif
+	TftpStart();
+}
+
 #if !defined(CONFIG_CMD_DHCP)
 
 static void BootpVendorFieldProcess (u8 * ext)
@@ -279,6 +308,7 @@ static void BootpVendorProcess (u8 * ext, int size)
 	if (NetBootFileSize)
 		debug("NetBootFileSize: %d\n", NetBootFileSize);
 }
+
 /*
  *	Handle a BOOTP received packet.
  */
@@ -287,7 +317,6 @@ BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 	     unsigned len)
 {
 	Bootp_t *bp;
-	char	*s;
 
 	debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
 		src, dest, len, sizeof (Bootp_t));
@@ -314,26 +343,7 @@ BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 
 	debug("Got good BOOTP\n");
 
-	if ((s = getenv("autoload")) != NULL) {
-		if (*s == 'n') {
-			/*
-			 * Just use BOOTP to configure system;
-			 * Do not use TFTP to load the bootfile.
-			 */
-			NetState = NETLOOP_SUCCESS;
-			return;
-#if defined(CONFIG_CMD_NFS)
-		} else if (strcmp(s, "NFS") == 0) {
-			/*
-			 * Use NFS to load the bootfile.
-			 */
-			NfsStart();
-			return;
-#endif
-		}
-	}
-
-	TftpStart();
+	auto_load();
 }
 #endif
 
@@ -907,34 +917,13 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 		debug("DHCP State: REQUESTING\n");
 
 		if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
-			char *s;
-
 			if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
 				DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
 			BootpCopyNetParams(bp); /* Store net params from reply */
 			dhcp_state = BOUND;
 			printf ("DHCP client bound to address %pI4\n", &NetOurIP);
 
-			/* Obey the 'autoload' setting */
-			if ((s = getenv("autoload")) != NULL) {
-				if (*s == 'n') {
-					/*
-					 * Just use BOOTP to configure system;
-					 * Do not use TFTP to load the bootfile.
-					 */
-					NetState = NETLOOP_SUCCESS;
-					return;
-#if defined(CONFIG_CMD_NFS)
-				} else if (strcmp(s, "NFS") == 0) {
-					/*
-					 * Use NFS to load the bootfile.
-					 */
-					NfsStart();
-					return;
-#endif
-				}
-			}
-			TftpStart();
+			auto_load();
 			return;
 		}
 		break;
Signature · 1 line
1.7.3.1
#8 lore raw

PATCH RESEND v7 4/5 Put common autoload code into auto_load() function

Hi Simon,

Quoted 33 lines · Simon Glass

This is a small clean-up patch.

---
  net/bootp.c |   75 +++++++++++++++++++++++++---------------------------------
  1 files changed, 32 insertions(+), 43 deletions(-)
net/bootp.c +18 -0
index 4db63cb..4774624 100644
@@ -138,6 +138,35 @@ static int truncate_sz (const char *name, int maxlen, int curlen)
  	return (curlen);
  }
 
+/*
+ * Check if autoload is enabled. If so, use either NFS or TFTP to download
+ * the boot file.
+ */
+static void auto_load(void)
+{
+	const char *s = getenv("autoload");
+
+	if (s != NULL) {
+		if (*s == 'n') {
+			/*
+			 * Just use BOOTP to configure system;
+			 * Do not use TFTP to load the bootfile.
+			 */
+			NetState = NETLOOP_SUCCESS;
+			return;
+		}
+#if defined(CONFIG_CMD_NFS)

net/bootp.c static int truncate_sz (const char *name, int maxlen, int curlen) · line 168

Quoted 10 lines
net/bootp.c +10 -0
+		if (strcmp(s, "NFS") == 0) {
+			/*
+			 * Use NFS to load the bootfile.
+			 */
+			NfsStart();
+			return;
+		}
+#endif
+	TftpStart();
+}

a "}" is missing here

Eric

#9 lore raw

PATCH RESEND v7 4/5 Put common autoload code into auto_load() function

Quoted 53 lines · Eric B?nard

Hi Simon,

Quoted 37 lines · Simon Glass

This is a small clean-up patch.

---
?net/bootp.c | ? 75
+++++++++++++++++++++++++---------------------------------
?1 files changed, 32 insertions(+), 43 deletions(-)

net/bootp.c +2 -0
index 4db63cb..4774624 100644
@@ -138,6 +138,35 @@ static int truncate_sz (const char *name, int maxlen,
 int curlen)
 ? ? ? ?return (curlen);
 ?}
 
+/*
+ * Check if autoload is enabled. If so, use either NFS or TFTP to

download
+ * the boot file.
+ */

net/bootp.c +14 -0
+static void auto_load(void)
+{
+ ? ? ? const char *s = getenv("autoload");
+
+ ? ? ? if (s != NULL) {
+ ? ? ? ? ? ? ? if (*s == 'n') {
+ ? ? ? ? ? ? ? ? ? ? ? /*
+ ? ? ? ? ? ? ? ? ? ? ? ?* Just use BOOTP to configure system;
+ ? ? ? ? ? ? ? ? ? ? ? ?* Do not use TFTP to load the bootfile.
+ ? ? ? ? ? ? ? ? ? ? ? ?*/
+ ? ? ? ? ? ? ? ? ? ? ? NetState = NETLOOP_SUCCESS;
+ ? ? ? ? ? ? ? ? ? ? ? return;
+ ? ? ? ? ? ? ? }
+#if defined(CONFIG_CMD_NFS)

net/bootp.c

Quoted 10 lines
net/bootp.c +10 -0
+ ? ? ? ? ? ? ? if (strcmp(s, "NFS") == 0) {
+ ? ? ? ? ? ? ? ? ? ? ? /*
+ ? ? ? ? ? ? ? ? ? ? ? ?* Use NFS to load the bootfile.
+ ? ? ? ? ? ? ? ? ? ? ? ?*/
+ ? ? ? ? ? ? ? ? ? ? ? NfsStart();
+ ? ? ? ? ? ? ? ? ? ? ? return;
+ ? ? ? ? ? ? ? }
+#endif
+ ? ? ? TftpStart();
+}

a "}" is missing here

Quoted 2 lines

Eric

Thanks Eric, done.

-Simon

#10 lore raw

PATCH RESEND v7 5/5 usbeth: asix: Do a fast init if link already established

In reply to Simon Glass

The Asix driver takes the link down during init() and then brings it back up. This commit changes this so that if a link has already been established successfully we simply check that the link is still good.

This reduces the delay between successive network commands.

---
 drivers/usb/eth/asix.c |   36 +++++++++++++++++++++++-------------
 include/usb_ether.h    |    5 +++--
 2 files changed, 26 insertions(+), 15 deletions(-)
drivers/usb/eth/asix.c +23 -13
index 9b012e4..18e5457 100644
@@ -307,20 +307,12 @@ static int mii_nway_restart(struct ueth_data *dev)
 	return r;
 }
 
-/*
- * Asix callbacks
- */
-static int asix_init(struct eth_device *eth, bd_t *bd)
+static int full_init(struct eth_device *eth)
 {
+	struct ueth_data *dev = (struct ueth_data *)eth->priv;
 	int embd_phy;
 	unsigned char buf[ETH_ALEN];
 	u16 rx_ctl;
-	struct ueth_data	*dev = (struct ueth_data *)eth->priv;
-	int timeout = 0;
-#define TIMEOUT_RESOLUTION 50	/* ms */
-	int link_detected;
-
-	debug("** %s()\n", __func__);
 
 	if (asix_write_gpio(dev,
 			AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5) < 0)
@@ -395,6 +387,25 @@ static int asix_init(struct eth_device *eth, bd_t *bd)
 
 	if (asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL) < 0)
 		goto out_err;
+	return 0;
+out_err:
+	return -1;
+}
+
+/*
+ * Asix callbacks
+ */
+static int asix_init(struct eth_device *eth, bd_t *bd)
+{
+	struct ueth_data *dev = (struct ueth_data *)eth->priv;
+	int timeout = 0;
+#define TIMEOUT_RESOLUTION 50	/* ms */
+	int link_detected;
+
+	debug("** %s()\n", __func__);
+
+	if (!dev->has_been_running && full_init(eth))
+		return -1;
 
 	do {
 		link_detected = asix_mdio_read(dev, dev->phy_id, MII_BMSR) &
@@ -411,12 +422,11 @@ static int asix_init(struct eth_device *eth, bd_t *bd)
 			printf("done.\n");
 	} else {
 		printf("unable to connect.\n");
-		goto out_err;
+		return -1;
 	}
 
+	dev->has_been_running = 1;
 	return 0;
-out_err:
-	return -1;
 }
 
 static int asix_send(struct eth_device *eth, volatile void *packet, int length)
include/usb_ether.h +3 -2
index a7fb26b..73b085d 100644
@@ -37,8 +37,9 @@
 
 struct ueth_data {
 	/* eth info */
-	struct eth_device eth_dev;		/* used with eth_register */
-	int phy_id;						/* mii phy id */
+	struct eth_device eth_dev;	/* used with eth_register */
+	int phy_id;			/* mii phy id */
+	int has_been_running;		/* 1 if we have had a link up */
 
 	/* usb info */
 	struct usb_device *pusb_dev;	/* this usb_device */
Signature · 1 line
1.7.3.1
#11 lore raw

PATCH RESEND v7 5/5 usbeth: asix: Do a fast init if link already established

Quoted 5 lines · On Friday, June 10, 2011 11:04:11 Simon Glass wrote:

The Asix driver takes the link down during init() and then brings it back up. This commit changes this so that if a link has already been established successfully we simply check that the link is still good.

This reduces the delay between successive network commands.

i'm not sure about this. i think this is a general issue to all net devices and should be resolved there rather than making diff net drivers behave differently based on how the maintainer felt like going.

i also vaguely recall there being discussions on this topic recently. -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110610/99ce6ab4/attachment.pgp

#12 lore raw

PATCH RESEND v7 5/5 usbeth: asix: Do a fast init if link already established

Quoted 5 lines · Mike Frysinger
Quoted 4 lines · On Friday, June 10, 2011 11:04:11 Simon Glass wrote:

The Asix driver takes the link down during init() and then brings it back up. This commit changes this so that if a link has already been established successfully we simply check that the link is still good.

Quoted 9 lines
Quoted 1 line

This reduces the delay between successive network commands.

i'm not sure about this. ?i think this is a general issue to all net devices and should be resolved there rather than making diff net drivers behave differently based on how the maintainer felt like going.

i also vaguely recall there being discussions on this topic recently. -mike

Hi Mike,

OK perhaps my understanding is incorrect.

I saw discussion about the SMSC driver and whether half should do something there. I changed it to stop packet reception.

In my view it is correct for it to stop packet reception but keep the link up. Bringing the link down and up takes a few seconds, which adds delay between bootp and tftp. We don't want that.

Regards,
Simon

#13 lore raw

PATCH RESEND v7 5/5 usbeth: asix: Do a fast init if link already established

Quoted 14 lines · On Friday, June 10, 2011 18:22:06 Simon Glass wrote:
Quoted 5 lines · Mike Frysinger
Quoted 4 lines · On Friday, June 10, 2011 11:04:11 Simon Glass wrote:

The Asix driver takes the link down during init() and then brings it back up. This commit changes this so that if a link has already been established successfully we simply check that the link is still good.

Quoted 7 lines
Quoted 1 line

This reduces the delay between successive network commands.

i'm not sure about this. i think this is a general issue to all net devices and should be resolved there rather than making diff net drivers behave differently based on how the maintainer felt like going.

i also vaguely recall there being discussions on this topic recently.

Quoted 8 lines

OK perhaps my understanding is incorrect.

I saw discussion about the SMSC driver and whether half should do something there. I changed it to stop packet reception.

In my view it is correct for it to stop packet reception but keep the link up. Bringing the link down and up takes a few seconds, which adds delay between bootp and tftp. We don't want that.

yes, but i'm saying that this needs to be decided at a higher level and then documented rather than changing diff drivers to behave differently. i'm not against making changes here to make things operate more smoothly, but i am against undocumented fragmentation, especially when the networking layer in u- boot is already a confusing mine field for people.

the current behavior is for the device to be completely taken down at halt() and completely brought up at init() time. you're proposing something else, so let's do it as a proper proposal and not a single driver change.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110611/b3e018ac/attachment.pgp

#14 lore raw

PATCH RESEND v7 5/5 usbeth: asix: Do a fast init if link already established

Quoted 30 lines · Mike Frysinger
Quoted 14 lines · On Friday, June 10, 2011 18:22:06 Simon Glass wrote:
Quoted 5 lines · Mike Frysinger
Quoted 4 lines · On Friday, June 10, 2011 11:04:11 Simon Glass wrote:

The Asix driver takes the link down during init() and then brings it back up. This commit changes this so that if a link has already been established successfully we simply check that the link is still good.

Quoted 7 lines
Quoted 1 line

This reduces the delay between successive network commands.

i'm not sure about this. ?i think this is a general issue to all net devices and should be resolved there rather than making diff net drivers behave differently based on how the maintainer felt like going.

i also vaguely recall there being discussions on this topic recently.

Quoted 8 lines

OK perhaps my understanding is incorrect.

I saw discussion about the SMSC driver and whether half should do something there. I changed it to stop packet reception.

In my view it is correct for it to stop packet reception but keep the link up. Bringing the link down and up takes a few seconds, which adds delay between bootp and tftp. We don't want that.

yes, but i'm saying that this needs to be decided at a higher level and then documented rather than changing diff drivers to behave differently. ?i'm not against making changes here to make things operate more smoothly, but i am against undocumented fragmentation, especially when the networking layer in u- boot is already a confusing mine field for people.

Quoted 5 lines

the current behavior is for the device to be completely taken down at halt() and completely brought up at init() time. ?you're proposing something else, so let's do it as a proper proposal and not a single driver change. -mike

Hi Mike,

Yes I do understand. The Atmel macb driver sees that a link is already up, doesn't force a renegotiate and just turns off packet transfer in the halt() method. That was the behavior I was modelling.

It might be reasonable to declare that halt may keep the link up if it wants to, and that there is then no way to bring the link down.

Or perhaps we could add two new methods:

- start = bring up the link if not already up, and get ready for transmission
- stop = stop transmission/reception but don't bring down the link

These could be skipped if not defined for each driver:

- start can simply be skipped, on the assumption that init has set up the link
- stop, if missing, then U-Boot must call halt() instead, then init next time around

There may be some desire for an explicit command to change the state of an interface, like 'eth stop n' or 'eth halt n'.

If this suits I am happy to create a patch for it, or something along these lines, so long as it doesn't turn into a timer-scale epic.

Note that USB is a little different here. WIth a directly-attached ethernet, power is generally applied by the hardware on boot, and the PHY will often pick up a link before U-Boot comes to call the Ethernet init() routine. This works well and I don't want to change it.

For USB unfortunately everything is off until power is applied to the adapter via the normal USB approach, complete with 500ms delays, etc. We can't get around this, but certainly don't want to be removing and reapplying power to the adapter between each network operation. It takes ages. I even consider it desirable to provide an option to pre-init any USB ethernet adapters found, while scanning the rest of the USB bus.

Anyway I will drop this patch from the series and carry it locally for now. I await your comments.

Regards,
Simon

#15 lore raw

v7 cover Add SMSC95XX support including MAC address control

In reply to Simon Glass

Hi Simon,

Quoted 5 lines · Simon Glass

Simon Glass (5):
Add support for SMSC95XX USB 2.0 10/100MBit Ethernet Adapter Add Ethernet hardware MAC address framework to usbnet Add documentation for USB Host Networking
Put common autoload code into auto_load() function

for the 4 first patches, with the 2 comments I sent concerning patches 1 and 4 :

Thanks,
Eric