diff mbox

[U-Boot,5/6] net: asix: add read_mac function

Message ID 1345630147-14465-6-git-send-email-dev@lynxeye.de
State Superseded
Delegated to: Joe Hershberger
Headers show

Commit Message

Lucas Stach Aug. 22, 2012, 10:09 a.m. UTC
Initial device MAC should be read while getting info about the
device, so it's wrong to only read it in asix_init().

Add a dedicated function to read the initial MAC, which is also
able to handle devices that have their initial MAC stored in
EEPROM. Call this function inasix_eth_get_info().

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/usb/eth/asix.c | 47 +++++++++++++++++++++++++++++++++++------------
 1 Datei geändert, 35 Zeilen hinzugefügt(+), 12 Zeilen entfernt(-)

Comments

Marek Vasut Aug. 22, 2012, 6:26 p.m. UTC | #1
Dear Lucas Stach,

> Initial device MAC should be read while getting info about the
> device, so it's wrong to only read it in asix_init().
> 
> Add a dedicated function to read the initial MAC, which is also
> able to handle devices that have their initial MAC stored in
> EEPROM. Call this function inasix_eth_get_info().
> 
> Signed-off-by: Lucas Stach <dev@lynxeye.de>

Reviewed-by: Marek Vasut <marex@denx.de>
Acked-by: Marek Vasut <marex@denx.de>

> ---
>  drivers/usb/eth/asix.c | 47
> +++++++++++++++++++++++++++++++++++------------ 1 Datei geändert, 35
> Zeilen hinzugefügt(+), 12 Zeilen entfernt(-)
> 
> diff --git a/drivers/usb/eth/asix.c b/drivers/usb/eth/asix.c
> index ce1483e..6ab3e82 100644
> --- a/drivers/usb/eth/asix.c
> +++ b/drivers/usb/eth/asix.c
> @@ -32,6 +32,7 @@
>  #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
> @@ -104,6 +105,8 @@
>  #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 */
> 
> @@ -337,6 +340,33 @@ static int mii_nway_restart(struct ueth_data *dev)
>  	return r;
>  }
> 
> +static int asix_read_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, 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, buf) < 0) {
> +				debug("Failed to read SROM address 04h.\n");
> +				return -1;
> +			}
> +			memcpy((eth->enetaddr + i * 2), buf, 2);
> +		}
> +	} 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;
> +}
> +
>  static int asix_basic_reset(struct ueth_data *dev)
>  {
>  	int embd_phy;
> @@ -391,18 +421,6 @@ static int asix_init(struct eth_device *eth, bd_t *bd)
> 
>  	debug("** %s()\n", __func__);
> 
> -	/* 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]);
> -
>  	dev->phy_id = asix_get_phy_addr(dev);
>  	if (dev->phy_id < 0)
>  		debug("Failed to read phy id\n");
> @@ -682,5 +700,10 @@ int asix_eth_get_info(struct usb_device *dev, struct
> ueth_data *ss, if (asix_basic_reset(ss))
>  		return 0;
> 
> +	/* Get the MAC address */
> +	if (asix_read_mac(eth))
> +		return 0;
> +	debug("MAC %pM\n", eth->enetaddr);
> +
>  	return 1;
>  }

Best regards,
Marek Vasut
Joe Hershberger Aug. 22, 2012, 6:59 p.m. UTC | #2
Hi Lucas,

On Wed, Aug 22, 2012 at 5:09 AM, Lucas Stach <dev@lynxeye.de> wrote:
> Initial device MAC should be read while getting info about the
> device, so it's wrong to only read it in asix_init().
>
> Add a dedicated function to read the initial MAC, which is also
> able to handle devices that have their initial MAC stored in
> EEPROM. Call this function inasix_eth_get_info().
>
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
diff mbox

Patch

diff --git a/drivers/usb/eth/asix.c b/drivers/usb/eth/asix.c
index ce1483e..6ab3e82 100644
--- a/drivers/usb/eth/asix.c
+++ b/drivers/usb/eth/asix.c
@@ -32,6 +32,7 @@ 
 #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
@@ -104,6 +105,8 @@ 
 #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 */
 
@@ -337,6 +340,33 @@  static int mii_nway_restart(struct ueth_data *dev)
 	return r;
 }
 
+static int asix_read_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, 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, buf) < 0) {
+				debug("Failed to read SROM address 04h.\n");
+				return -1;
+			}
+			memcpy((eth->enetaddr + i * 2), buf, 2);
+		}
+	} 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;
+}
+
 static int asix_basic_reset(struct ueth_data *dev)
 {
 	int embd_phy;
@@ -391,18 +421,6 @@  static int asix_init(struct eth_device *eth, bd_t *bd)
 
 	debug("** %s()\n", __func__);
 
-	/* 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]);
-
 	dev->phy_id = asix_get_phy_addr(dev);
 	if (dev->phy_id < 0)
 		debug("Failed to read phy id\n");
@@ -682,5 +700,10 @@  int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
 	if (asix_basic_reset(ss))
 		return 0;
 
+	/* Get the MAC address */
+	if (asix_read_mac(eth))
+		return 0;
+	debug("MAC %pM\n", eth->enetaddr);
+
 	return 1;
 }