All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data
@ 2012-08-21 13:23 Lucas Stach
  2012-08-21 13:23 ` [U-Boot] [Patch v3 2/2] net: asix: add support for AX88772B Lucas Stach
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lucas Stach @ 2012-08-21 13:23 UTC (permalink / raw)
  To: u-boot

Avoid clutter in ueth_data. Individual drivers should not mess
with structures belonging to the core like this.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/usb/eth/smsc95xx.c | 48 ++++++++++++++++++++++++++++++++--------------
 include/usb_ether.h        |  8 ++------
 2 Dateien ge?ndert, 36 Zeilen hinzugef?gt(+), 20 Zeilen entfernt(-)

diff --git a/drivers/usb/eth/smsc95xx.c b/drivers/usb/eth/smsc95xx.c
index c62a8c1..4bf2a16 100644
--- a/drivers/usb/eth/smsc95xx.c
+++ b/drivers/usb/eth/smsc95xx.c
@@ -25,6 +25,7 @@
 #include <usb.h>
 #include <linux/mii.h>
 #include "usb_ether.h"
+#include "malloc.h"
 
 /* SMSC LAN95xx based USB 2.0 Ethernet Devices */
 
@@ -146,6 +147,12 @@
 /* local vars */
 static int curr_eth_dev; /* index for name of next device detected */
 
+/* driver private */
+struct smsc95xx_private {
+	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 */
+};
 
 /*
  * Smsc95xx infrastructure commands
@@ -377,6 +384,7 @@ static int smsc95xx_init_mac_address(struct eth_device *eth,
 static int smsc95xx_write_hwaddr(struct eth_device *eth)
 {
 	struct ueth_data *dev = (struct ueth_data *)eth->priv;
+	struct smsc95xx_private *priv = dev->dev_priv;
 	u32 addr_lo = __get_unaligned_le32(&eth->enetaddr[0]);
 	u32 addr_hi = __get_unaligned_le16(&eth->enetaddr[4]);
 	int ret;
@@ -392,7 +400,7 @@ static int smsc95xx_write_hwaddr(struct eth_device *eth)
 		return ret;
 
 	debug("MAC %pM\n", eth->enetaddr);
-	dev->have_hwaddr = 1;
+	priv->have_hwaddr = 1;
 	return 0;
 }
 
@@ -425,19 +433,22 @@ static int smsc95xx_set_csums(struct ueth_data *dev,
 
 static void smsc95xx_set_multicast(struct ueth_data *dev)
 {
+	struct smsc95xx_private *priv = dev->dev_priv;
+
 	/* No multicast in u-boot */
-	dev->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
+	priv->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
 }
 
 /* starts the TX path */
 static void smsc95xx_start_tx_path(struct ueth_data *dev)
 {
+	struct smsc95xx_private *priv = dev->dev_priv;
 	u32 reg_val;
 
 	/* Enable Tx at MAC */
-	dev->mac_cr |= MAC_CR_TXEN_;
+	priv->mac_cr |= MAC_CR_TXEN_;
 
-	smsc95xx_write_reg(dev, MAC_CR, dev->mac_cr);
+	smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
 
 	/* Enable Tx at SCSRs */
 	reg_val = TX_CFG_ON_;
@@ -447,8 +458,10 @@ static void smsc95xx_start_tx_path(struct ueth_data *dev)
 /* Starts the Receive path */
 static void smsc95xx_start_rx_path(struct ueth_data *dev)
 {
-	dev->mac_cr |= MAC_CR_RXEN_;
-	smsc95xx_write_reg(dev, MAC_CR, dev->mac_cr);
+	struct smsc95xx_private *priv = dev->dev_priv;
+
+	priv->mac_cr |= MAC_CR_RXEN_;
+	smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
 }
 
 /*
@@ -462,6 +475,7 @@ static int smsc95xx_init(struct eth_device *eth, bd_t *bd)
 	u32 burst_cap;
 	int timeout;
 	struct ueth_data *dev = (struct ueth_data *)eth->priv;
+	struct smsc95xx_private *priv = (struct smsc95xx_private *)dev->dev_priv;
 #define TIMEOUT_RESOLUTION 50	/* ms */
 	int link_detected;
 
@@ -504,9 +518,9 @@ static int smsc95xx_init(struct eth_device *eth, bd_t *bd)
 		debug("timeout waiting for PHY Reset\n");
 		return -1;
 	}
-	if (!dev->have_hwaddr && smsc95xx_init_mac_address(eth, dev) == 0)
-		dev->have_hwaddr = 1;
-	if (!dev->have_hwaddr) {
+	if (!priv->have_hwaddr && smsc95xx_init_mac_address(eth, dev) == 0)
+		priv->have_hwaddr = 1;
+	if (!priv->have_hwaddr) {
 		puts("Error: SMSC95xx: No MAC address set - set usbethaddr\n");
 		return -1;
 	}
@@ -532,16 +546,16 @@ static int smsc95xx_init(struct eth_device *eth, bd_t *bd)
 #ifdef TURBO_MODE
 	if (dev->pusb_dev->speed == USB_SPEED_HIGH) {
 		burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
-		dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
+		priv->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
 	} else {
 		burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
-		dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
+		priv->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
 	}
 #else
 	burst_cap = 0;
-	dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
+	priv->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
 #endif
-	debug("rx_urb_size=%ld\n", (ulong)dev->rx_urb_size);
+	debug("rx_urb_size=%ld\n", (ulong)priv->rx_urb_size);
 
 	ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
 	if (ret < 0)
@@ -606,7 +620,7 @@ static int smsc95xx_init(struct eth_device *eth, bd_t *bd)
 	if (ret < 0)
 		return ret;
 
-	ret = smsc95xx_read_reg(dev, MAC_CR, &dev->mac_cr);
+	ret = smsc95xx_read_reg(dev, MAC_CR, &priv->mac_cr);
 	if (ret < 0)
 		return ret;
 
@@ -857,6 +871,12 @@ int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
 		return 0;
 	}
 	dev->privptr = (void *)ss;
+
+	/* alloc driver private */
+	ss->dev_priv = calloc(1, sizeof(struct smsc95xx_private));
+	if (!ss->dev_priv)
+		return 0;
+
 	return 1;
 }
 
diff --git a/include/usb_ether.h b/include/usb_ether.h
index a7fb26b..7c7aecb 100644
--- a/include/usb_ether.h
+++ b/include/usb_ether.h
@@ -50,12 +50,8 @@ struct ueth_data {
 	unsigned char	protocol;		/* .............. */
 	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
+	/* driver private */
+	void *dev_priv;
 };
 
 /*
-- 
1.7.11.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [Patch v3 2/2] net: asix: add support for AX88772B
  2012-08-21 13:23 [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data Lucas Stach
@ 2012-08-21 13:23 ` Lucas Stach
  2012-08-21 18:19   ` Mike Frysinger
  2012-08-21 18:16 ` [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data Mike Frysinger
  2012-08-21 20:52 ` Marek Vasut
  2 siblings, 1 reply; 5+ messages in thread
From: Lucas Stach @ 2012-08-21 13:23 UTC (permalink / raw)
  To: u-boot

There are multiple changes needed to make AX88772B work:

1. add vendor and product ID (trivial)

2. We need to read out the MAC address from the EEPROM and write
it into the NodeID register manually.

3. The packet length check has to be adjusted, as all ASIX chips
only use 11 bits to indicate the length. AX88772B uses the other
bits to indicate unrelated things, which cause the check to fail.
This fix is based on a fix for the Linux kernel by Marek Vasut.
Linux upstream commit: bca0beb9363f8487ac902931a50eb00180a2d14a

4. AX88772B provides several bulk endpoints. Only the first
IN/OUT endpoints work in the default configuration. So stop
enumeration after we found them to avoid overwriting the
endpoint config with a non-working one.

This was tested to work on a Colibri T20 board.
Patch is based on u-boot-net/next.

v2:
- split out eeprom mac load into separate function
- add flags to driver to get a clean way to enable workarounds
  or special functions

v3:
- remove useless memsets
- use MAC printing macro
- while touching the asix_dongles array constify it
- provide a write_hwaddr() function for all chipsets that
  support this.
- unify MAC handling in one function

Signed-off-by: Lucas Stach <dev@lynxeye.de>

const
---
 drivers/usb/eth/asix.c | 137 +++++++++++++++++++++++++++++++++++++------------
 1 Datei ge?ndert, 104 Zeilen hinzugef?gt(+), 33 Zeilen entfernt(-)

diff --git a/drivers/usb/eth/asix.c b/drivers/usb/eth/asix.c
index 8fb7fc8..7d9e9a2 100644
--- a/drivers/usb/eth/asix.c
+++ b/drivers/usb/eth/asix.c
@@ -23,6 +23,7 @@
 #include <usb.h>
 #include <linux/mii.h>
 #include "usb_ether.h"
+#include "malloc.h"
 
 
 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
@@ -31,10 +32,12 @@
 #define AX_CMD_READ_MII_REG		0x07
 #define AX_CMD_WRITE_MII_REG		0x08
 #define AX_CMD_SET_HW_MII		0x0a
+#define AX_CMD_READ_EEPROM		0x0b
 #define AX_CMD_READ_RX_CTL		0x0f
 #define AX_CMD_WRITE_RX_CTL		0x10
 #define AX_CMD_WRITE_IPG0		0x12
 #define AX_CMD_READ_NODE_ID		0x13
+#define AX_CMD_WRITE_NODE_ID	0x14
 #define AX_CMD_READ_PHY_ID		0x19
 #define AX_CMD_WRITE_MEDIUM_MODE	0x1b
 #define AX_CMD_WRITE_GPIOS		0x1f
@@ -97,9 +100,21 @@
 #define AX_RX_URB_SIZE 2048
 #define PHY_CONNECT_TIMEOUT 5000
 
+/* asix_flags defines */
+#define FLAG_NONE			0
+#define FLAG_TYPE_AX88172	(1U << 0)
+#define FLAG_TYPE_AX88772	(1U << 1)
+#define FLAG_TYPE_AX88772B	(1U << 2)
+#define FLAG_EEPROM_MAC		(1U << 3) /* initial mac address in eeprom */
+
 /* local vars */
 static int curr_eth_dev; /* index for name of next device detected */
 
+/* driver private */
+struct asix_private {
+	int flags;
+};
+
 /*
  * Asix infrastructure commands
  */
@@ -284,6 +299,21 @@ static int asix_write_gpio(struct ueth_data *dev, u16 value, int sleep)
 	return ret;
 }
 
+static int asix_write_hwaddr(struct eth_device *eth)
+{
+	struct ueth_data *dev = (struct ueth_data *)eth->priv;
+	int ret;
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buf, ETH_ALEN);
+
+	memcpy(buf, eth->enetaddr, ETH_ALEN);
+
+	ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN, buf);
+	if (ret < 0)
+		debug("Failed to set MAC address: %02x\n", ret);
+
+	return ret;
+}
+
 /*
  * mii commands
  */
@@ -310,13 +340,41 @@ static int mii_nway_restart(struct ueth_data *dev)
 	return r;
 }
 
+static int asix_init_mac(struct eth_device *eth)
+{
+	struct ueth_data *dev = (struct ueth_data *)eth->priv;
+	struct asix_private *priv = (struct asix_private *)dev->dev_priv;
+	int i;
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, ee_buf, 2);
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buf, ETH_ALEN);
+
+	if (priv->flags & FLAG_EEPROM_MAC) {
+		for (i = 0; i < (ETH_ALEN >> 1); i++) {
+			if (asix_read_cmd(dev, AX_CMD_READ_EEPROM,
+			                  0x04 + i, 0, 2, ee_buf) < 0) {
+				debug("Failed to read SROM address 04h.\n");
+				return -1;
+			}
+			memcpy((eth->enetaddr + i * 2), ee_buf, 2);
+			asix_write_hwaddr(eth);
+		}
+	} else {
+		if (asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf) < 0) {
+			debug("Failed to read MAC address.\n");
+			return -1;
+		}
+		memcpy(eth->enetaddr, buf, ETH_ALEN);
+	}
+
+	return 0;
+}
+
 /*
  * Asix callbacks
  */
 static int asix_init(struct eth_device *eth, bd_t *bd)
 {
 	int embd_phy;
-	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buf, ETH_ALEN);
 	u16 rx_ctl;
 	struct ueth_data	*dev = (struct ueth_data *)eth->priv;
 	int timeout = 0;
@@ -360,16 +418,8 @@ static int asix_init(struct eth_device *eth, bd_t *bd)
 	debug("RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
 
 	/* Get the MAC address */
-	if (asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
-				0, 0, ETH_ALEN, buf) < 0) {
-		debug("Failed to read MAC address.\n");
-		goto out_err;
-	}
-	memcpy(eth->enetaddr, buf, ETH_ALEN);
-	debug("MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
-		eth->enetaddr[0], eth->enetaddr[1],
-		eth->enetaddr[2], eth->enetaddr[3],
-		eth->enetaddr[4], eth->enetaddr[5]);
+	asix_init_mac(eth);
+	debug("MAC %pM\n", eth->enetaddr);
 
 	dev->phy_id = asix_get_phy_addr(dev);
 	if (dev->phy_id < 0)
@@ -493,13 +543,13 @@ static int asix_recv(struct eth_device *eth)
 		}
 		memcpy(&packet_len, buf_ptr, sizeof(packet_len));
 		le32_to_cpus(&packet_len);
-		if (((packet_len >> 16) ^ 0xffff) != (packet_len & 0xffff)) {
+		if (((~packet_len >> 16) & 0x7ff) != (packet_len & 0x7ff)) {
 			debug("Rx: malformed packet length: %#x (%#x:%#x)\n",
-			      packet_len, (packet_len >> 16) ^ 0xffff,
-			      packet_len & 0xffff);
+			      packet_len, (~packet_len >> 16) & 0x7ff,
+			      packet_len & 0x7ff);
 			return -1;
 		}
-		packet_len = packet_len & 0xffff;
+		packet_len = packet_len & 0x7ff;
 		if (packet_len > actual_len - sizeof(packet_len)) {
 			debug("Rx: too large packet: %d\n", packet_len);
 			return -1;
@@ -534,19 +584,21 @@ void asix_eth_before_probe(void)
 struct asix_dongle {
 	unsigned short vendor;
 	unsigned short product;
+	int flags;
 };
 
-static struct asix_dongle asix_dongles[] = {
-	{ 0x05ac, 0x1402 },	/* Apple USB Ethernet Adapter */
-	{ 0x07d1, 0x3c05 },	/* D-Link DUB-E100 H/W Ver B1 */
-	{ 0x0b95, 0x772a },	/* Cables-to-Go USB Ethernet Adapter */
-	{ 0x0b95, 0x7720 },	/* Trendnet TU2-ET100 V3.0R */
-	{ 0x0b95, 0x1720 },	/* SMC */
-	{ 0x0db0, 0xa877 },	/* MSI - ASIX 88772a */
-	{ 0x13b1, 0x0018 },	/* Linksys 200M v2.1 */
-	{ 0x1557, 0x7720 },	/* 0Q0 cable ethernet */
-	{ 0x2001, 0x3c05 },	/* DLink DUB-E100 H/W Ver B1 Alternate */
-	{ 0x0000, 0x0000 }	/* END - Do not remove */
+static const struct asix_dongle asix_dongles[] = {
+	{ 0x05ac, 0x1402, FLAG_TYPE_AX88772 },	/* Apple USB Ethernet Adapter */
+	{ 0x07d1, 0x3c05, FLAG_TYPE_AX88772 },	/* D-Link DUB-E100 H/W Ver B1 */
+	{ 0x0b95, 0x772a, FLAG_TYPE_AX88772 },	/* Cables-to-Go USB Ethernet Adapter */
+	{ 0x0b95, 0x7720, FLAG_TYPE_AX88772 },	/* Trendnet TU2-ET100 V3.0R */
+	{ 0x0b95, 0x1720, FLAG_TYPE_AX88172 },	/* SMC */
+	{ 0x0db0, 0xa877, FLAG_TYPE_AX88772 },	/* MSI - ASIX 88772a */
+	{ 0x13b1, 0x0018, FLAG_TYPE_AX88172 },	/* Linksys 200M v2.1 */
+	{ 0x1557, 0x7720, FLAG_TYPE_AX88772 },	/* 0Q0 cable ethernet */
+	{ 0x2001, 0x3c05, FLAG_TYPE_AX88772 },	/* DLink DUB-E100 H/W Ver B1 Alternate */
+	{ 0x0b95, 0x772b, FLAG_TYPE_AX88772B | FLAG_EEPROM_MAC }, /* ASIX 88772B */
+	{ 0x0000, 0x0000, FLAG_NONE }	/* END - Do not remove */
 };
 
 /* Probe to see if a new device is actually an asix device */
@@ -555,6 +607,7 @@ int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
 {
 	struct usb_interface *iface;
 	struct usb_interface_descriptor *iface_desc;
+	int ep_in_found = 0, ep_out_found = 0;
 	int i;
 
 	/* let's examine the device now */
@@ -583,6 +636,13 @@ int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
 	ss->subclass = iface_desc->bInterfaceSubClass;
 	ss->protocol = iface_desc->bInterfaceProtocol;
 
+	/* alloc driver private */
+	ss->dev_priv = calloc(1, sizeof(struct asix_private));
+	if (!ss->dev_priv)
+		return 0;
+
+	((struct asix_private *)ss->dev_priv)->flags = asix_dongles[i].flags;
+
 	/*
 	 * We are expecting a minimum of 3 endpoints - in, out (bulk), and
 	 * int. We will ignore any others.
@@ -591,13 +651,19 @@ int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
 		/* is it an BULK endpoint? */
 		if ((iface->ep_desc[i].bmAttributes &
 		     USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
-			if (iface->ep_desc[i].bEndpointAddress & USB_DIR_IN)
-				ss->ep_in = iface->ep_desc[i].bEndpointAddress &
-					USB_ENDPOINT_NUMBER_MASK;
-			else
-				ss->ep_out =
-					iface->ep_desc[i].bEndpointAddress &
-					USB_ENDPOINT_NUMBER_MASK;
+			if (iface->ep_desc[i].bEndpointAddress & USB_DIR_IN) {
+				if (!ep_in_found) {
+					ss->ep_in = iface->ep_desc[i].bEndpointAddress &
+					            USB_ENDPOINT_NUMBER_MASK;
+					ep_in_found = 1;
+				}
+			} else {
+				if (!ep_out_found) {
+					ss->ep_out = iface->ep_desc[i].bEndpointAddress &
+					             USB_ENDPOINT_NUMBER_MASK;
+					ep_out_found = 1;
+				}
+			}
 		}
 
 		/* is it an interrupt endpoint? */
@@ -618,12 +684,15 @@ int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
 		return 0;
 	}
 	dev->privptr = (void *)ss;
+
 	return 1;
 }
 
 int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
 				struct eth_device *eth)
 {
+	struct asix_private *priv = (struct asix_private *)ss->dev_priv;
+
 	if (!eth) {
 		debug("%s: missing parameter.\n", __func__);
 		return 0;
@@ -633,6 +702,8 @@ int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
 	eth->send = asix_send;
 	eth->recv = asix_recv;
 	eth->halt = asix_halt;
+	if (!(priv->flags & FLAG_TYPE_AX88172))
+		eth->write_hwaddr = asix_write_hwaddr;
 	eth->priv = ss;
 
 	return 1;
-- 
1.7.11.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data
  2012-08-21 13:23 [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data Lucas Stach
  2012-08-21 13:23 ` [U-Boot] [Patch v3 2/2] net: asix: add support for AX88772B Lucas Stach
@ 2012-08-21 18:16 ` Mike Frysinger
  2012-08-21 20:52 ` Marek Vasut
  2 siblings, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2012-08-21 18:16 UTC (permalink / raw)
  To: u-boot

On Tuesday 21 August 2012 09:23:12 Lucas Stach wrote:
> Avoid clutter in ueth_data. Individual drivers should not mess
> with structures belonging to the core like this.

nice work
-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/20120821/ee402bea/attachment.pgp>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [Patch v3 2/2] net: asix: add support for AX88772B
  2012-08-21 13:23 ` [U-Boot] [Patch v3 2/2] net: asix: add support for AX88772B Lucas Stach
@ 2012-08-21 18:19   ` Mike Frysinger
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2012-08-21 18:19 UTC (permalink / raw)
  To: u-boot

On Tuesday 21 August 2012 09:23:13 Lucas Stach wrote:
> +	struct ueth_data *dev = (struct ueth_data *)eth->priv;
> +	struct asix_private *priv = (struct asix_private *)dev->dev_priv;

not that it's harmful, but priv is void*, so the casts aren't needed

> +	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, ee_buf, 2);
> +	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buf, ETH_ALEN);

since you don't use both buffers at the same time, just declare one that is big 
enough to work for either code path.  so looks like you could throw away 
ee_buf here.
-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/20120821/90f535e4/attachment.pgp>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data
  2012-08-21 13:23 [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data Lucas Stach
  2012-08-21 13:23 ` [U-Boot] [Patch v3 2/2] net: asix: add support for AX88772B Lucas Stach
  2012-08-21 18:16 ` [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data Mike Frysinger
@ 2012-08-21 20:52 ` Marek Vasut
  2 siblings, 0 replies; 5+ messages in thread
From: Marek Vasut @ 2012-08-21 20:52 UTC (permalink / raw)
  To: u-boot

Dear Lucas Stach,

> Avoid clutter in ueth_data. Individual drivers should not mess
> with structures belonging to the core like this.
> 
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
>  drivers/usb/eth/smsc95xx.c | 48
> ++++++++++++++++++++++++++++++++-------------- include/usb_ether.h       
> |  8 ++------
>  2 Dateien ge?ndert, 36 Zeilen hinzugef?gt(+), 20 Zeilen entfernt(-)

You might want to configure your locale ... otherwise, awesome :)

> diff --git a/drivers/usb/eth/smsc95xx.c b/drivers/usb/eth/smsc95xx.c
> index c62a8c1..4bf2a16 100644
> --- a/drivers/usb/eth/smsc95xx.c
> +++ b/drivers/usb/eth/smsc95xx.c
> @@ -25,6 +25,7 @@
>  #include <usb.h>
>  #include <linux/mii.h>
>  #include "usb_ether.h"
> +#include "malloc.h"
> 
>  /* SMSC LAN95xx based USB 2.0 Ethernet Devices */
> 
> @@ -146,6 +147,12 @@
>  /* local vars */
>  static int curr_eth_dev; /* index for name of next device detected */
> 
> +/* driver private */
> +struct smsc95xx_private {
> +	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 */
> +};
> 
>  /*
>   * Smsc95xx infrastructure commands
> @@ -377,6 +384,7 @@ static int smsc95xx_init_mac_address(struct eth_device
> *eth, static int smsc95xx_write_hwaddr(struct eth_device *eth)
>  {
>  	struct ueth_data *dev = (struct ueth_data *)eth->priv;
> +	struct smsc95xx_private *priv = dev->dev_priv;
>  	u32 addr_lo = __get_unaligned_le32(&eth->enetaddr[0]);
>  	u32 addr_hi = __get_unaligned_le16(&eth->enetaddr[4]);
>  	int ret;
> @@ -392,7 +400,7 @@ static int smsc95xx_write_hwaddr(struct eth_device
> *eth) return ret;
> 
>  	debug("MAC %pM\n", eth->enetaddr);
> -	dev->have_hwaddr = 1;
> +	priv->have_hwaddr = 1;
>  	return 0;
>  }
> 
> @@ -425,19 +433,22 @@ static int smsc95xx_set_csums(struct ueth_data *dev,
> 
>  static void smsc95xx_set_multicast(struct ueth_data *dev)
>  {
> +	struct smsc95xx_private *priv = dev->dev_priv;
> +
>  	/* No multicast in u-boot */
> -	dev->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
> +	priv->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
>  }
> 
>  /* starts the TX path */
>  static void smsc95xx_start_tx_path(struct ueth_data *dev)
>  {
> +	struct smsc95xx_private *priv = dev->dev_priv;
>  	u32 reg_val;
> 
>  	/* Enable Tx at MAC */
> -	dev->mac_cr |= MAC_CR_TXEN_;
> +	priv->mac_cr |= MAC_CR_TXEN_;
> 
> -	smsc95xx_write_reg(dev, MAC_CR, dev->mac_cr);
> +	smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
> 
>  	/* Enable Tx at SCSRs */
>  	reg_val = TX_CFG_ON_;
> @@ -447,8 +458,10 @@ static void smsc95xx_start_tx_path(struct ueth_data
> *dev) /* Starts the Receive path */
>  static void smsc95xx_start_rx_path(struct ueth_data *dev)
>  {
> -	dev->mac_cr |= MAC_CR_RXEN_;
> -	smsc95xx_write_reg(dev, MAC_CR, dev->mac_cr);
> +	struct smsc95xx_private *priv = dev->dev_priv;
> +
> +	priv->mac_cr |= MAC_CR_RXEN_;
> +	smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
>  }
> 
>  /*
> @@ -462,6 +475,7 @@ static int smsc95xx_init(struct eth_device *eth, bd_t
> *bd) u32 burst_cap;
>  	int timeout;
>  	struct ueth_data *dev = (struct ueth_data *)eth->priv;
> +	struct smsc95xx_private *priv = (struct smsc95xx_private *)dev-
>dev_priv;
>  #define TIMEOUT_RESOLUTION 50	/* ms */
>  	int link_detected;
> 
> @@ -504,9 +518,9 @@ static int smsc95xx_init(struct eth_device *eth, bd_t
> *bd) debug("timeout waiting for PHY Reset\n");
>  		return -1;
>  	}
> -	if (!dev->have_hwaddr && smsc95xx_init_mac_address(eth, dev) == 0)
> -		dev->have_hwaddr = 1;
> -	if (!dev->have_hwaddr) {
> +	if (!priv->have_hwaddr && smsc95xx_init_mac_address(eth, dev) == 0)
> +		priv->have_hwaddr = 1;
> +	if (!priv->have_hwaddr) {
>  		puts("Error: SMSC95xx: No MAC address set - set usbethaddr\n");
>  		return -1;
>  	}
> @@ -532,16 +546,16 @@ static int smsc95xx_init(struct eth_device *eth, bd_t
> *bd) #ifdef TURBO_MODE
>  	if (dev->pusb_dev->speed == USB_SPEED_HIGH) {
>  		burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
> -		dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
> +		priv->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
>  	} else {
>  		burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
> -		dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
> +		priv->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
>  	}
>  #else
>  	burst_cap = 0;
> -	dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
> +	priv->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
>  #endif
> -	debug("rx_urb_size=%ld\n", (ulong)dev->rx_urb_size);
> +	debug("rx_urb_size=%ld\n", (ulong)priv->rx_urb_size);
> 
>  	ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
>  	if (ret < 0)
> @@ -606,7 +620,7 @@ static int smsc95xx_init(struct eth_device *eth, bd_t
> *bd) if (ret < 0)
>  		return ret;
> 
> -	ret = smsc95xx_read_reg(dev, MAC_CR, &dev->mac_cr);
> +	ret = smsc95xx_read_reg(dev, MAC_CR, &priv->mac_cr);
>  	if (ret < 0)
>  		return ret;
> 
> @@ -857,6 +871,12 @@ int smsc95xx_eth_probe(struct usb_device *dev,
> unsigned int ifnum, return 0;
>  	}
>  	dev->privptr = (void *)ss;
> +
> +	/* alloc driver private */
> +	ss->dev_priv = calloc(1, sizeof(struct smsc95xx_private));
> +	if (!ss->dev_priv)
> +		return 0;
> +
>  	return 1;
>  }
> 
> diff --git a/include/usb_ether.h b/include/usb_ether.h
> index a7fb26b..7c7aecb 100644
> --- a/include/usb_ether.h
> +++ b/include/usb_ether.h
> @@ -50,12 +50,8 @@ struct ueth_data {
>  	unsigned char	protocol;		/* .............. */
>  	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
> +	/* driver private */
> +	void *dev_priv;
>  };
> 
>  /*

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-08-21 20:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-21 13:23 [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data Lucas Stach
2012-08-21 13:23 ` [U-Boot] [Patch v3 2/2] net: asix: add support for AX88772B Lucas Stach
2012-08-21 18:19   ` Mike Frysinger
2012-08-21 18:16 ` [U-Boot] [Patch v3 1/2] net: introduce transparent driver private in ueth_data Mike Frysinger
2012-08-21 20:52 ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.