Skip to contentSkip to conversation

Add support for SMSC95XX USB 2.0 10/100MBit Ethernet Adapter

PATCH Superseded Simon Glass 4 participants 15 messages Apr 14, 2011 – Apr 30, 2011

Subsystems (3)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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.

TEST=usb start; bootp; tftp ...

---
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

---
 drivers/usb/eth/Makefile    |    1 +
 drivers/usb/eth/smsc95xx.c  |  921 +++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/eth/usb_ether.c |    7 +
 include/usb_ether.h         |   13 +
 4 files changed, 942 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 +921 -0

921 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
#1 lore raw

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

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.

TEST=build, test on harmony, with setenv usbethaddr c0:c1:c0:13:0b:b8, bootp, tftp ...

---
 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                   |   65 ++++++++++++++++++++++++++----------------
 5 files changed, 73 insertions(+), 30 deletions(-)
board/davinci/common/misc.c +1 -1
index 2bfdf23..b2b980b 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(NULL, 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..5e0f9e3 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(NULL, 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 95ef8ab..9256a46 100644
@@ -123,7 +123,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 (NULL for "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 */
@@ -136,6 +147,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 (NULL for "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 +40 -25

97 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#2 lore raw

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

Hi,

2011/4/14 Simon Glass <[email protected]>:

Quoted 9 lines

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.

TEST=build, test on harmony, with setenv usbethaddr c0:c1:c0:13:0b:b8, bootp, tftp ...

Quoted 7 lines

---

?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 ? ? ? ? ? ? ? ? ? | ? 65 ++++++++++++++++++++++++++----------------

3 subsystems within 1 single patch (net + usb + davinci-boards). How are we gonna deal with it?
Since the remainder of the series is USB tree related, I would suggest to include it in the u-boot-usb tree, but then I need the Ack of Ben and Sandeep.

Kind regards,

Remy

#3 lore raw

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

Dear Remy Bohmer,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 6 lines
 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 | 65 +++++++++++++++=

Quoted 7 lines

+++++++++++----------------

3 subsystems within 1 single patch (net + usb + davinci-boards). How are we gonna deal with it?
Since the remainder of the series is USB tree related, I would suggest to include it in the u-boot-usb tree, but then I need the Ack of Ben and Sandeep.

I'm standing in for the network custodian as long as we haven't found a better one. I think it will be indeed the best to pull this though your tree. But I just requested some more changes.

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
How many seconds are there in a year? If I tell you there are 3.155 x
10^7, you won't even try to remember it. On the other hand, who could
forget that, to within half a percent, pi seconds is a nanocentury.
                                                - Tom Duff, Bell Labs
#4 lore raw

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

In reply to Simon Glass

Dear Simon Glass,

Quoted 17 lines · In message <[email protected]> you wrote:

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.

TEST=build, test on harmony, with setenv usbethaddr c0:c1:c0:13:0b:b8, bootp, tftp ...

---
 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                   |   65 ++++++++++++++++++++++++++----------------
 5 files changed, 73 insertions(+), 30 deletions(-)

...

Quoted 13 lines
drivers/usb/eth/usb_ether.c +1 -0
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++) {

drivers/usb/eth/usb_ether.c static void probe_valid_drivers(struct usb_device *dev) · line 92

Quoted 4 lines
drivers/usb/eth/usb_ether.c +1 -0
@@ -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;

Index for eth is usb_max_eth_dev.

drivers/usb/eth/usb_ether.c static void probe_valid_drivers(struct usb_device *dev) · line 105

Quoted 6 lines
drivers/usb/eth/usb_ether.c +1 -1
@@ -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);

You change the behaviour here. Please confirmt his is really intentional.

Quoted 5 lines
include/net.h +0 -0
index 95ef8ab..9256a46 100644

include/net.h extern int eth_get_dev_index (void); /* get the device index */ · line 130

Quoted 9 lines
include/net.h +5 -1
@@ -123,7 +123,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 (NULL for "eth")

This is an atitifical decision for the API which is difficult to understand. It just makes the code and understanding it more difficult. Just pass "eth" when you mean it.

include/net.h extern int eth_get_dev_index (void); /* get the device index */ · line 137

Quoted 7 lines
include/net.h +7 -0
+int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
+		   int eth_number)
+{
+	unsigned char env_enetaddr[6];
+	int ret = 0;
+
+	eth_getenv_enetaddr_by_index(base_name, eth_number, env_enetaddr);

Add error handling, or write

	(void)eth_getenv_enetaddr_by_index(...);

to indicate that you intentionally ignore the return value.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Philosophy is a game with objectives and no rules.
Mathematics is a game with rules and no objectives.
#5 lore raw

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

Quoted 11 lines · Wolfgang Denk

Dear Simon Glass,

Quoted 5 lines · In message <[email protected]> you wrote:
(quoted diff) +0 -0
@@ -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;

Index for eth is usb_max_eth_dev.

Quoted 9 lines
Quoted 6 lines
(quoted diff) +0 -0
@@ -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);

You change the behaviour here. ?Please confirmt his is really intentional.

Yes. Since I am using an 'eth' pointer I don't need to index the array again. The behaviour is the same as before.

Quoted 5 lines
Quoted 4 lines
include/net.h +0 -0
@@ -123,7 +123,18 @@ extern int eth_get_dev_index (void); ? ? ? ? ? ? /* get the device index */
Quoted 8 lines

include/net.h extern int eth_get_dev_index (void); /* get the device index */

Quoted 4 lines
include/net.h +4 -0
+/*
+ * Get the hardware address for an ethernet interface .
+ * Args:
+ * ? base_name - base name for device (NULL for "eth")

This is an atitifical decision for the API which is difficult to understand. ?It just makes the code and understanding it more difficult. ?Just pass "eth" when you mean it.

The intention was to avoid everyone having to pass the correct value - potential for error, etc. I could have created a #define, but decided on this.

I have changed it as you request.

Quoted 11 lines

include/net.h extern int eth_get_dev_index (void); ? ? ? ? ? ? /* get the device index */ · line 133

Quoted 8 lines
include/net.h +7 -0
+int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
+ ? ? ? ? ? ? ? ?int eth_number)
+{
+ ? ? unsigned char env_enetaddr[6];
+ ? ? int ret = 0;
+
+ ? ? eth_getenv_enetaddr_by_index(base_name, eth_number, env_enetaddr);

Add error handling, or write

Quoted 3 lines

? ? ? ?(void)eth_getenv_enetaddr_by_index(...);

to indicate that you intentionally ignore the return value.

Done

Quoted 4 lines

Best regards,

Wolfgang Denk

Regards,
Simon

#6 lore raw

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

Dear Simon Glass,

Quoted 15 lines · In message <[email protected]> you wrote:
Quoted 5 lines
Quoted 2 lines

+ eth = &usb_eth[usb_max_eth_dev].eth_dev;

Index for eth is usb_max_eth_dev.

Quoted 9 lines

drivers/usb/eth/usb_ether.c static void probe_valid_drivers(struct usb_device *> dev) · line 105

Quoted 6 lines
drivers/usb/eth/usb_ether.c +1 -1
@@ -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);

You change the behaviour here. Please confirmt his is really intentional.

Quoted 2 lines

Yes. Since I am using an 'eth' pointer I don't need to index the array again. The behaviour is the same as before.

No, it is not. Before, we were accessing entry N-1 here. Now we use entry N. usb_max_eth_dev != usb_max_eth_dev - 1

Quoted 9 lines
Quoted 5 lines

Review static void probe_valid_drivers(struct usb_device *> dev) · line 106

Quoted 1 line
(quoted diff) +1 -0
+ *   base_name - base name for device (NULL for "eth")

This is an atitifical decision for the API which is difficult to understand. It just makes the code and understanding it more difficult. Just pass "eth" when you mean it.

The intention was to avoid everyone having to pass the correct value - potential for error, etc. I could have created a #define, but decided on this.

Ummm... but having everyone to pass the correct value is actually a really good thing to have!

Best regards,

Wolfgang Denk

Signature · 8 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
When a child is taught ... its programmed with simple instructions --
and at some point, if its mind develops properly, it exceeds the  sum
of what it was taught, thinks independently.
	-- Dr. Richard Daystrom, "The Ultimate Computer",
	   stardate 4731.3.
#7 lore raw

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

Quoted 18 lines · Wolfgang Denk

Dear Simon Glass,

Quoted 15 lines · In message <[email protected]> you wrote:
Quoted 14 lines
Quoted 2 lines

+ ? ? ? ? ? ? eth = &usb_eth[usb_max_eth_dev].eth_dev;

Index for eth is usb_max_eth_dev.

Quoted 6 lines
(quoted diff) +0 -0
@@ -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);

You change the behaviour here. ?Please confirmt his is really intentional.

Quoted 5 lines
Quoted 2 lines

Yes. Since I am using an 'eth' pointer I don't need to index the array again. The behaviour is the same as before.

No, it is not. ?Before, we were accessing entry N-1 here. Now we use entry N. ?usb_max_eth_dev != usb_max_eth_dev - 1

Hi Wolfgang,

Hmmm. If you see the usb_max_eth_dev++ below, it is increasing the index variable to keep eth_register() happy. I have kept that behaviour.

So let's say usb_max_eth_dev is 3. The sequence is:

- set eth to point to item 3
- increase usb_max_eth_dev to 4 as required by eth_register()
- call eth_register() with item 3 (i.e. eth pointer hasn't changed)
- call eth_write_hwaddr with item 3

Maybe look at the whole code with my patch applied?

Let me know if I am missing something.

+                       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;
                       }
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

+ * ? base_name - base name for device (NULL for "eth")

This is an atitifical decision for the API which is difficult to understand. ?It just makes the code and understanding it more difficult. ?Just pass "eth" when you mean it.

Quoted 6 lines
Quoted 3 lines

The intention was to avoid everyone having to pass the correct value - potential for error, etc. I could have created a #define, but decided on this.

Ummm... but having everyone to pass the correct value is actually a really good thing to have!

OK fair enough, it is in there now.

Regards,
Simon

#8 lore raw

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

Quoted 37 lines · Simon Glass
Quoted 3 lines · Wolfgang Denk

Dear Simon Glass,

In message <[email protected]> you

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

+ eth = &usb_eth[usb_max_eth_dev].eth_dev;

Index for eth is usb_max_eth_dev.

Review static void probe_valid_drivers(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -100,7 +102,10 @@ static void probe_valid_drivers(struct

usb_device *> dev)

Quoted 1 line
Quoted 1 line
Quoted 1 line

Review static void probe_valid_drivers(struct · line 102

Quoted 1 line
(quoted diff) +0 -0
                       * call since eth_current_> changed (internally

called)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/usb/eth/usb_ether.c static void probe_valid_drivers(struct usb_device *dev)

Quoted 3 lines
drivers/usb/eth/usb_ether.c +0 -1
                       * relies on it
                       */
-                     eth_register(&usb_eth[usb_max_eth_dev -

1].eth_dev);

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

drivers/usb/eth/usb_ether.c static void probe_valid_drivers(struct usb_device *dev) · line 105

Quoted 1 line
drivers/usb/eth/usb_ether.c +1 -0
+                     eth_register(eth);

You change the behaviour here. Please confirmt his is really intentional.

Yes. Since I am using an 'eth' pointer I don't need to index the array again. The behaviour is the same as before.

No, it is not. Before, we were accessing entry N-1 here. Now we use entry N. usb_max_eth_dev != usb_max_eth_dev - 1

Hi Wolfgang,

Hmmm. If you see the usb_max_eth_dev++ below, it is increasing the index variable to keep eth_register() happy. I have kept that behaviour.

So let's say usb_max_eth_dev is 3. The sequence is:

Quoted 10 lines

- set eth to point to item 3
- increase usb_max_eth_dev to 4 as required by eth_register()
- call eth_register() with item 3 (i.e. eth pointer hasn't changed)
- call eth_write_hwaddr with item 3

Maybe look at the whole code with my patch applied?

Let me know if I am missing something.

Hi Wolfgang,

Please can you let me know where we stand with this patch? It is a bit opaque and if you don't mind me reaching a bit further I might be able to clean it up by changing eth_register().

Thanks,
Simon

#9 lore raw

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

In reply to Wolfgang Denk
Quoted 7 lines · On Thursday, April 21, 2011 19:38:06 Wolfgang Denk wrote:
Quoted 6 lines · Simon Glass
Quoted 5 lines
Quoted 1 line

+ * base_name - base name for device (NULL for "eth")

This is an atitifical decision for the API which is difficult to understand. It just makes the code and understanding it more difficult. Just pass "eth" when you mean it.

Quoted 6 lines
Quoted 3 lines

The intention was to avoid everyone having to pass the correct value - potential for error, etc. I could have created a #define, but decided on this.

Ummm... but having everyone to pass the correct value is actually a really good thing to have!

i'm not sure about that. it just means it's easier for people to screw it up, or for duplicated code to propagate via copy & paste. the current API Simon has makes sense to me.
-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/20110430/eaad9e12/attachment.pgp

#10 lore raw

PATCH v4 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.

---
 doc/README.usb |  164 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 163 insertions(+), 1 deletions(-)
doc/README.usb +163 -1
index 9aa4f62..d30e696 100644
@@ -79,4 +79,166 @@ 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.
+
+USB Host Networking is different from 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. 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 a
+first class 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
+setenv autoload y
+bootp
+
+
+(The autoload option makes bootp automatically load the boot file.)
+
+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 */
+
+You will also want to enable the network commands:
+
+#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:
+
+#define CONFIG_BOOTP_SUBNETMASK
+#define CONFIG_BOOTP_GATEWAY
+#define CONFIG_BOOTP_HOSTNAME
+#define CONFIG_BOOTP_BOOTPATH
+
+You should 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.
+
+#define CONFIG_IPADDR           10.0.0.2
+#define CONFIG_SERVERIP         10.0.0.1
+#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' 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>
+
+
+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.
+
+
+Server Setup
+------------
+
+For setting up the server side (dhcpd, tftpd, nfsd) you might find this
+Chromium OS page useful:
+
+http://www.chromium.org/network-based-development
+
+>>>>>>> 232452a... Add documentation for USB Host Networking
Signature · 1 line
1.7.3.1
#11 lore raw

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

In reply to Simon Glass

This is a small clean-up patch.

TEST=Build U-Boot, try bootp and check it auto-loads.

---
 net/bootp.c |   76 +++++++++++++++++++++++++---------------------------------
 1 files changed, 33 insertions(+), 43 deletions(-)
net/bootp.c +33 -43
index 1a71786..a3d0e63 100644
@@ -137,6 +137,36 @@ 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)
+{
+	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)
+		} else 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)
@@ -278,6 +308,7 @@ static void BootpVendorProcess (u8 * ext, int size)
 	if (NetBootFileSize)
 		debug("NetBootFileSize: %d\n", NetBootFileSize);
 }
+
 /*
  *	Handle a BOOTP received packet.
  */
@@ -285,7 +316,6 @@ static void
 BootpHandler(uchar * pkt, unsigned dest, 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));
@@ -312,26 +342,7 @@ BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 
 	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
 
@@ -904,34 +915,13 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 		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
#12 lore raw

PATCH v4 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.

TEST=bootp; tftp ... - see that delay is now shorter than before.

---
 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
#13 lore raw

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

In reply to Simon Glass

Dear Simon Glass,

Quoted 6 lines · In message <[email protected]> you wrote:

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

TEST=usb start; bootp; tftp ...

...

drivers/usb/eth/smsc95xx.c line 36

Quoted 6 lines
drivers/usb/eth/smsc95xx.c new file +6 -0
+#define TX_CMD_A_FIRST_SEG_		(0x00002000)
+#define TX_CMD_A_LAST_SEG_		(0x00001000)
+
+/* Rx status word */
+#define RX_STS_FL_			(0x3FFF0000)	/* Frame Length */
+#define RX_STS_ES_			(0x00008000)	/* Error Summary */

...

Please drop the parens around all these constants. Please fix globally.

Quoted 82 lines
drivers/usb/eth/smsc95xx.c new file +82 -0
+/* SCSRs */
+#define ID_REV				(0x00)
+
+#define INT_STS				(0x08)
+
+#define TX_CFG				(0x10)
+#define TX_CFG_ON_			(0x00000004)
+
+#define HW_CFG				(0x14)
+#define HW_CFG_BIR_			(0x00001000)
+#define HW_CFG_RXDOFF_			(0x00000600)
+#define HW_CFG_MEF_			(0x00000020)
+#define HW_CFG_BCE_			(0x00000002)
+#define HW_CFG_LRST_			(0x00000008)
+
+#define PM_CTRL				(0x20)
+#define PM_CTL_PHY_RST_			(0x00000010)
+
+#define AFC_CFG				(0x2C)
+
+/*
+ * Hi watermark = 15.5Kb (~10 mtu pkts)
+ * low watermark = 3k (~2 mtu pkts)
+ * backpressure duration = ~ 350us
+ * Apply FC on any frame.
+ */
+#define AFC_CFG_DEFAULT			(0x00F830A1)
+
+#define E2P_CMD				(0x30)
+#define E2P_CMD_BUSY_			(0x80000000)
+#define E2P_CMD_READ_			(0x00000000)
+#define E2P_CMD_TIMEOUT_		(0x00000400)
+#define E2P_CMD_LOADED_			(0x00000200)
+#define E2P_CMD_ADDR_			(0x000001FF)
+
+#define E2P_DATA			(0x34)
+
+#define BURST_CAP			(0x38)
+
+#define INT_EP_CTL			(0x68)
+#define INT_EP_CTL_PHY_INT_		(0x00008000)
+
+#define BULK_IN_DLY			(0x6C)
+
+/* MAC CSRs */
+#define MAC_CR				(0x100)
+#define MAC_CR_MCPAS_			(0x00080000)
+#define MAC_CR_PRMS_			(0x00040000)
+#define MAC_CR_HPFILT_			(0x00002000)
+#define MAC_CR_TXEN_			(0x00000008)
+#define MAC_CR_RXEN_			(0x00000004)
+
+#define ADDRH				(0x104)
+
+#define ADDRL				(0x108)
+
+#define MII_ADDR			(0x114)
+#define MII_WRITE_			(0x02)
+#define MII_BUSY_			(0x01)
+#define MII_READ_			(0x00) /* ~of MII Write bit */
+
+#define MII_DATA			(0x118)
+
+#define FLOW				(0x11C)
+
+#define VLAN1				(0x120)
+
+#define COE_CR				(0x130)
+#define Tx_COE_EN_			(0x00010000)
+#define Rx_COE_EN_			(0x00000001)
+
+/* Vendor-specific PHY Definitions */
+#define PHY_INT_SRC			(29)
+
+#define PHY_INT_MASK			(30)
+#define PHY_INT_MASK_ANEG_COMP_		((u16)0x0040)
+#define PHY_INT_MASK_LINK_DOWN_		((u16)0x0010)
+#define PHY_INT_MASK_DEFAULT_		(PHY_INT_MASK_ANEG_COMP_ | \
+					 PHY_INT_MASK_LINK_DOWN_)
+
+/* USB Vendor Requests */
+#define USB_VENDOR_REQUEST_WRITE_REGISTER	0xA0

...

Quoted 4 lines
drivers/usb/eth/smsc95xx.c new file +4 -0
+	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
+	if (ret < 0) {
+		debug("Failed to read HW_CFG: %d\n", ret);
+		return ret;

drivers/usb/eth/smsc95xx.c line 535

Quoted 10 lines
drivers/usb/eth/smsc95xx.c new file +10 -0
+	}
+	debug("Read Value from HW_CFG : 0x%08x\n", read_buf);
+
+	read_buf |= HW_CFG_BIR_;
+	ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
+	if (ret < 0) {
+		debug("Failed to write HW_CFG_BIR_ bit in HW_CFG "
+			"register, ret = %d\n", ret);
+		return ret;
+	}

You repeat these sequences of smsc95xx_read_reg() resp. smsc95xx_write_reg() followed by the "if (ret < 0)" part about 20 times.

Please move the respective debug() message for the failure case into the functions, and consider using a loop here instead.

drivers/usb/eth/smsc95xx.c line 577

Quoted 6 lines
drivers/usb/eth/smsc95xx.c new file +6 -0
+	read_buf = DEFAULT_BULK_IN_DELAY;
+	ret = smsc95xx_write_reg(dev, BULK_IN_DLY, read_buf);
+	if (ret < 0) {
+		debug("ret = %d", ret);
+		return ret;
+	}

Is it intentional to use the read_buf with a smsc95xx_write_reg() call?

drivers/usb/eth/smsc95xx.c line 607

Quoted 5 lines
drivers/usb/eth/smsc95xx.c new file +5 -0
+	ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
+	if (ret < 0) {
+		debug("Failed to write HW_CFG register, ret=%d\n", ret);
+		return ret;
+	}

Ditto here?

drivers/usb/eth/smsc95xx.c line 643

Quoted 5 lines
drivers/usb/eth/smsc95xx.c new file +5 -0
+	ret = smsc95xx_write_reg(dev, AFC_CFG, read_buf);
+	if (ret < 0) {
+		debug("Failed to write AFC_CFG: %d\n", ret);
+		return ret;
+	}

And here?

drivers/usb/eth/smsc95xx.c line 673

Quoted 5 lines
drivers/usb/eth/smsc95xx.c new file +5 -0
+	ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
+	if (ret < 0) {
+		debug("Failed to read INT_EP_CTL: %d", ret);
+		return ret;
+	}

And here we have &read_buf while everywhere else we have read_buf only?

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"I like your game but we have to change the rules."
#14 lore raw

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

Quoted 9 lines · Wolfgang Denk

Dear Simon Glass,

Review

Quoted 3 lines
(quoted diff) +3 -0
+/* Rx status word */
+#define RX_STS_FL_ ? ? ? ? ? ? ? ? ? (0x3FFF0000) ? ?/* Frame Length */
+#define RX_STS_ES_ ? ? ? ? ? ? ? ? ? (0x00008000) ? ?/* Error Summary */

...

Please drop the parens around all these constants. ?Please fix globally.

Done

Quoted 7 lines
Quoted 6 lines

+ ? ? ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
+ ? ? if (ret < 0) {
+ ? ? ? ? ? ? debug("Failed to write HW_CFG_BIR_ bit in HW_CFG "
+ ? ? ? ? ? ? ? ? ? ? "register, ret = %d\n", ret);
+ ? ? ? ? ? ? return ret;
+ ? ? }

Quoted 6 lines

You repeat these sequences of smsc95xx_read_reg() resp. smsc95xx_write_reg() followed by the "if (ret < 0)" part about 20 times.

Please move the respective debug() message for the failure case into the functions, and consider using a loop here instead.

I have moved the debug messages into the routines. Not sure what you mean by a loop.

Quoted 10 lines
Quoted 7 lines

+ ? ? read_buf = DEFAULT_BULK_IN_DELAY;
+ ? ? ret = smsc95xx_write_reg(dev, BULK_IN_DLY, read_buf);
+ ? ? if (ret < 0) {
+ ? ? ? ? ? ? debug("ret = %d", ret);
+ ? ? ? ? ? ? return ret;
+ ? ? }

Is it intentional to use the read_buf with a smsc95xx_write_reg() call?

It doesn't need to - I have changed it to use the value directly.

Quoted 7 lines
Quoted 5 lines

+ ? ? ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
+ ? ? if (ret < 0) {
+ ? ? ? ? ? ? debug("Failed to write HW_CFG register, ret=%d\n", ret);
+ ? ? ? ? ? ? return ret;
+ ? ? }

Ditto here?

This is updating a register. It reads the value, modifies it and writes it back.

Quoted 8 lines
Quoted 6 lines

+ ? ? ret = smsc95xx_write_reg(dev, AFC_CFG, read_buf);
+ ? ? if (ret < 0) {
+ ? ? ? ? ? ? debug("Failed to write AFC_CFG: %d\n", ret);
+ ? ? ? ? ? ? return ret;
+ ? ? }

And here?

Same as above.

Quoted 9 lines
Quoted 6 lines

+ ? ? ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
+ ? ? if (ret < 0) {
+ ? ? ? ? ? ? debug("Failed to read INT_EP_CTL: %d", ret);
+ ? ? ? ? ? ? return ret;
+ ? ? }

And here we have &read_buf while everywhere else we have read_buf only?

That's because it is reading the value here. The read routine needs an address of a variable to put the value into.

Quoted 6 lines

Best regards,

Wolfgang Denk

Regards,
Simon