Skip to contentSkip to conversation

net: asix: init ASIX AX88772B MAC from EEPROM

PATCH In review Lucas Stach 4 participants 8 messages Dec 18, 2012 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
#2 lore raw

PATCH 2/2 net: asix: handle packets crossing URB boundaries

In reply to a message not in the archive

ASIX AX88772B started to pack data even more tightly. Packets and the ASIX packet header may now cross URB boundaries. To handle this we have to introduce some state between individual calls to asix_rx_fixup().

---
I've running this patch for some weeks already now and it gets rid of all the commonly seen rx failures with AX88772B.

---
 drivers/net/usb/asix.h         | 10 ++++++
 drivers/net/usb/asix_common.c  | 81 +++++++++++++++++++++++++++++-------------
 drivers/net/usb/asix_devices.c |  8 +++++

3 Dateien geändert, 75 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)

drivers/net/usb/asix.h +10 -0
index e889631..3b4f7a8 100644
@@ -167,6 +167,16 @@ struct asix_data {
 	u8 res;
 };
 
+struct asix_rx_fixup_info {
+	struct sk_buff *ax_skb;
+	u32 header;
+	u16 size;
+	bool split_head;
+};
+struct asix_private {
+	struct asix_rx_fixup_info rx_fixup_info;
+};
+
 int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
 		  u16 size, void *data);
 
drivers/net/usb/asix_common.c +57 -24

101 lines not on this page · raw message

drivers/net/usb/asix_devices.c +8 -0
index 06f7f7cb..2e1f3ec 100644
@@ -495,6 +495,10 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 		dev->rx_urb_size = 2048;
 	}
 
+	dev->driver_priv = kzalloc(sizeof(struct asix_private), GFP_KERNEL);
+	if (!dev->driver_priv)
+		return -ENOMEM;
+
 	return 0;
 }
 
@@ -829,6 +833,10 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
 		dev->rx_urb_size = 2048;
 	}
 
+	dev->driver_priv = kzalloc(sizeof(struct asix_private), GFP_KERNEL);
+	if (!dev->driver_priv)
+			return -ENOMEM;
+
 	return 0;
 }
 
Signature · 6 lines
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#0 lore raw

PATCH 1/2 net: asix: init ASIX AX88772B MAC from EEPROM

The device comes up with a MAC address of all zeros. We need to read the initial device MAC from EEPROM so it can be set properly later.

---
A similar fix was added into U-Boot:
http://patchwork.ozlabs.org/patch/179409/

---
 drivers/net/usb/asix_devices.c | 29 ++++++++++++++++++++++++++---
 include/linux/usb/usbnet.h     |  1 +

2 Dateien geändert, 27 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)

drivers/net/usb/asix_devices.c +26 -3
index 7a6e758..06f7f7cb 100644
@@ -422,14 +422,25 @@ static const struct net_device_ops ax88772_netdev_ops = {
 
 static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 {
-	int ret, embd_phy;
+	int ret, embd_phy, i;
 	u8 buf[ETH_ALEN];
 	u32 phyid;
 
 	usbnet_get_endpoints(dev,intf);
 
 	/* Get the MAC address */
-	ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
+	if (dev->driver_info->flags & FLAG_EEPROM_MAC) {
+		for (i = 0; i < (ETH_ALEN >> 1); i++) {
+			ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x04 + i,
+					0, 2, buf + i * 2);
+			if (ret < 0)
+				break;
+		}
+	} else {
+		ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
+				0, 0, ETH_ALEN, buf);
+	}
+
 	if (ret < 0) {
 		netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
 		return ret;
@@ -872,6 +883,18 @@ static const struct driver_info ax88772_info = {
 	.tx_fixup = asix_tx_fixup,
 };
 
+static const struct driver_info ax88772b_info = {
+	.description = "ASIX AX88772B USB 2.0 Ethernet",
+	.bind = ax88772_bind,
+	.status = asix_status,
+	.link_reset = ax88772_link_reset,
+	.reset = ax88772_reset,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
+	         FLAG_MULTI_PACKET | FLAG_EEPROM_MAC,
+	.rx_fixup = asix_rx_fixup,
+	.tx_fixup = asix_tx_fixup,
+};
+
 static const struct driver_info ax88178_info = {
 	.description = "ASIX AX88178 USB 2.0 Ethernet",
 	.bind = ax88178_bind,
@@ -953,7 +976,7 @@ static const struct usb_device_id	products [] = {
 }, {
 	// ASIX AX88772B 10/100
 	USB_DEVICE (0x0b95, 0x772b),
-	.driver_info = (unsigned long) &ax88772_info,
+	.driver_info = (unsigned long) &ax88772b_info,
 }, {
 	// ASIX AX88772 10/100
 	USB_DEVICE (0x0b95, 0x7720),
include/linux/usb/usbnet.h +1 -0
index 9bbeabf..8e9516f 100644
@@ -106,6 +106,7 @@ struct driver_info {
  */
 #define FLAG_MULTI_PACKET	0x2000
 #define FLAG_RX_ASSEMBLE	0x4000	/* rx packets may span >1 frames */
+#define FLAG_EEPROM_MAC		0x8000	/* initialize device MAC from eeprom */
 
 	/* init device ... can sleep, or cause probe() failure */
 	int	(*bind)(struct usbnet *, struct usb_interface *);
Signature · 1 line
1.7.11.7
#4 lore raw

include/linux/usb/usbnet.h struct driver_info { · line 109

Quoted 9 lines · On Tuesday 18 December 2012 13:10:25 Lucas Stach wrote:
include/linux/usb/usbnet.h +1 -0
index 9bbeabf..8e9516f 100644
@@ -106,6 +106,7 @@ struct driver_info {
  */
 #define FLAG_MULTI_PACKET      0x2000
 #define FLAG_RX_ASSEMBLE       0x4000  /* rx packets may span >1 frames */
+#define FLAG_EEPROM_MAC                0x8000  /* initialize device MAC from eeprom */

Hi,

this looks sensible, but
why are you adding a flag unused in usbnet to usbnet.h?

Regards
Oliver

#5 lore raw

Am Dienstag, den 18.12.2012, 14:11 +0100 schrieb Oliver Neukum:

Quoted 13 lines · On Tuesday 18 December 2012 13:10:25 Lucas Stach wrote:

include/linux/usb/usbnet.h struct driver_info { · line 109

Quoted 9 lines
include/linux/usb/usbnet.h +1 -0
index 9bbeabf..8e9516f 100644
@@ -106,6 +106,7 @@ struct driver_info {
  */
 #define FLAG_MULTI_PACKET      0x2000
 #define FLAG_RX_ASSEMBLE       0x4000  /* rx packets may span >1 frames */
+#define FLAG_EEPROM_MAC                0x8000  /* initialize device MAC from eeprom */

Hi,

Quoted 2 lines

this looks sensible, but
why are you adding a flag unused in usbnet to usbnet.h?

Right, this might not be the right place to add this. Could you point me to a more appropriate place? The data member of usbnet might be a good place to stuff this into, but why is this a plain long and not some kind of pointer? It is used for a different purpose on other ASIX chips already.

Regards,
Lucas

#6 lore raw
Quoted 14 lines · On Tuesday 18 December 2012 14:24:32 Lucas Stach wrote:

Am Dienstag, den 18.12.2012, 14:11 +0100 schrieb Oliver Neukum:

Quoted 13 lines · On Tuesday 18 December 2012 13:10:25 Lucas Stach wrote:

include/linux/usb/usbnet.h struct driver_info { · line 109

Quoted 9 lines
include/linux/usb/usbnet.h +1 -0
index 9bbeabf..8e9516f 100644
@@ -106,6 +106,7 @@ struct driver_info {
  */
 #define FLAG_MULTI_PACKET      0x2000
 #define FLAG_RX_ASSEMBLE       0x4000  /* rx packets may span >1 frames */
+#define FLAG_EEPROM_MAC                0x8000  /* initialize device MAC from eeprom */

Hi,

Quoted 5 lines
Quoted 2 lines

this looks sensible, but
why are you adding a flag unused in usbnet to usbnet.h?

Right, this might not be the right place to add this. Could you point me to a more appropriate place? The data member of usbnet might be a good

driver_priv is intended for such stuff

Quoted 3 lines

place to stuff this into, but why is this a plain long and not some kind of pointer? It is used for a different purpose on other ASIX chips already.

But there is another pointer.

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

Am Dienstag, den 18.12.2012, 14:33 +0100 schrieb Oliver Neukum:

Quoted 15 lines · On Tuesday 18 December 2012 14:24:32 Lucas Stach wrote:
Quoted 14 lines

Am Dienstag, den 18.12.2012, 14:11 +0100 schrieb Oliver Neukum:

Quoted 13 lines · On Tuesday 18 December 2012 13:10:25 Lucas Stach wrote:

include/linux/usb/usbnet.h struct driver_info { · line 109

Quoted 9 lines
include/linux/usb/usbnet.h +1 -0
index 9bbeabf..8e9516f 100644
@@ -106,6 +106,7 @@ struct driver_info {
  */
 #define FLAG_MULTI_PACKET      0x2000
 #define FLAG_RX_ASSEMBLE       0x4000  /* rx packets may span >1 frames */
+#define FLAG_EEPROM_MAC                0x8000  /* initialize device MAC from eeprom */

Hi,

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

this looks sensible, but
why are you adding a flag unused in usbnet to usbnet.h?

Right, this might not be the right place to add this. Could you point me to a more appropriate place? The data member of usbnet might be a good

driver_priv is intended for such stuff

I'm not talking about the usbnet struct, but the driver_info struct. I need a way to pass this flag from the static driver info to the bind function. I don't even have a usbnet device at this point, where I could hang on driver_priv data.

Regards,
Lucas

#3 lore raw

Re: [PATCH 2/2] net: asix: handle packets crossing URB boundaries

In reply to Lucas Stach

drivers/net/usb/asix_devices.c static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) · line 502

Quoted 11 lines · On Tuesday 18 December 2012 13:10:26 Lucas Stach wrote:
drivers/net/usb/asix_devices.c +4 -0
@@ -495,6 +495,10 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
                dev->rx_urb_size = 2048;
        }
 
+       dev->driver_priv = kzalloc(sizeof(struct asix_private), GFP_KERNEL);
+       if (!dev->driver_priv)
+               return -ENOMEM;
+
        return 0;

Where is this freed?

Regards
Oliver

#8 lore raw
In reply to Lucas Stach
Quoted 22 lines · On Tuesday 18 December 2012 14:38:32 Lucas Stach wrote:

Am Dienstag, den 18.12.2012, 14:33 +0100 schrieb Oliver Neukum:

Quoted 21 lines · On Tuesday 18 December 2012 14:24:32 Lucas Stach wrote:
Quoted 19 lines

Am Dienstag, den 18.12.2012, 14:11 +0100 schrieb Oliver Neukum:

Quoted 13 lines · On Tuesday 18 December 2012 13:10:25 Lucas Stach wrote:

include/linux/usb/usbnet.h struct driver_info { · line 109

Quoted 9 lines
include/linux/usb/usbnet.h +1 -0
index 9bbeabf..8e9516f 100644
@@ -106,6 +106,7 @@ struct driver_info {
  */
 #define FLAG_MULTI_PACKET      0x2000
 #define FLAG_RX_ASSEMBLE       0x4000  /* rx packets may span >1 frames */
+#define FLAG_EEPROM_MAC                0x8000  /* initialize device MAC from eeprom */

Hi,

Quoted 2 lines

this looks sensible, but
why are you adding a flag unused in usbnet to usbnet.h?

Right, this might not be the right place to add this. Could you point me to a more appropriate place? The data member of usbnet might be a good

Quoted 6 lines
Quoted 2 lines

driver_priv is intended for such stuff

I'm not talking about the usbnet struct, but the driver_info struct. I need a way to pass this flag from the static driver info to the bind function. I don't even have a usbnet device at this point, where I could hang on driver_priv data.

True, sorry I misread the patch. You could split up ax88772_bind() implicitly encoding the flag. That would be reasonably clean. If you really don't want to do that, please add another private field. But we cannot pollute the flags.

Regards
Oliver