Skip to contentSkip to conversation

driver: net: ldpaa_eth: Get MAC address from env variable

PATCH New Prabhakar Kushwaha 2 participants 2 messages Aug 10, 2015 – Aug 11, 2015 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver: net: ldpaa_eth: Get MAC address from env variable

Currently ldpaa ethernet driver rely on DPL file to statically configure mac address for the DPNIs. It is not a correct approach.

Add support of reading MAC address for env variable and configure same in DPAA driver.

---
 drivers/net/ldpaa_eth/ldpaa_eth.c | 48 +++++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 14 deletions(-)
drivers/net/ldpaa_eth/ldpaa_eth.c +34 -14
index 4ed1805..1b4094a 100644
@@ -23,6 +23,38 @@ static int init_phy(struct eth_device *dev)
 	return 0;
 }
 
+static int ldpaa_set_mac_from_env(struct eth_device *net_dev)
+{
+	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
+	uint8_t mac_addr[6];
+	char ethaddr[15] = "eth";
+	int err;
+
+	if (priv->dpni_id == 1)
+		strcat(ethaddr, "addr");
+	else
+		sprintf(ethaddr, "eth%daddr", priv->dpni_id - 1);
+
+	err = eth_getenv_enetaddr(ethaddr, mac_addr);
+
+	if (err) {
+		err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
+			      priv->dpni_handle, mac_addr);
+		if (err) {
+			printf("dpni_add_mac_addr() failed\n");
+			return err;
+		}
+
+		memcpy(net_dev->enetaddr, mac_addr, 0x6);
+		err = 0;
+	} else {
+		printf("%s: MAC address is not set\n", ethaddr);
+		err = 1;
+	}
+
+	return err;
+}
+
 static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
 			 const struct dpaa_fd *fd)
 {
@@ -216,7 +248,6 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	struct dpni_queue_attr rx_queue_attr;
-	uint8_t mac_addr[6];
 	int err;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
@@ -236,20 +267,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (err)
 		goto err_bind;
 
-	err = dpni_get_primary_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
-					priv->dpni_handle, mac_addr);
-	if (err) {
-		printf("dpni_get_primary_mac_addr() failed\n");
+	err = ldpaa_set_mac_from_env(net_dev);
+	if (err)
 		return err;
-	}
-
-	memcpy(net_dev->enetaddr, mac_addr, 0x6);
-
-	/* setup the MAC address */
-	if (net_dev->enetaddr[0] & 0x01) {
-		printf("%s: MacAddress is multcast address\n",	__func__);
-		return 1;
-	}
 
 #ifdef CONFIG_PHYLIB
 	/* TODO Check this path */
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 driver: net: ldpaa_eth: Get MAC address from env variable

Hi Prabhakar,

Quoted 22 lines · Prabhakar Kushwaha

Currently ldpaa ethernet driver rely on DPL file to statically configure mac address for the DPNIs. It is not a correct approach.

Add support of reading MAC address for env variable and configure same in DPAA driver.

---
 drivers/net/ldpaa_eth/ldpaa_eth.c | 48 +++++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 14 deletions(-)
drivers/net/ldpaa_eth/ldpaa_eth.c +3 -0
index 4ed1805..1b4094a 100644
@@ -23,6 +23,38 @@ static int init_phy(struct eth_device *dev)
        return 0;
 }
 
+static int ldpaa_set_mac_from_env(struct eth_device *net_dev)
+{
+       struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;

drivers/net/ldpaa_eth/ldpaa_eth.c static int init_phy(struct eth_device *dev) · line 38

Quoted 10 lines
drivers/net/ldpaa_eth/ldpaa_eth.c +10 -0
+       uint8_t mac_addr[6];
+       char ethaddr[15] = "eth";
+       int err;
+
+       if (priv->dpni_id == 1)
+               strcat(ethaddr, "addr");
+       else
+               sprintf(ethaddr, "eth%daddr", priv->dpni_id - 1);
+
+       err = eth_getenv_enetaddr(ethaddr, mac_addr);

Instead of re-implementing this logic, you should just implement a write_hwaddr() ops function for this driver. The network stack will assign the MAC address either from the env, the ROM (as set by the driver in init if available), or random if configured.

Quoted 60 lines
drivers/net/ldpaa_eth/ldpaa_eth.c +20 -15
+       if (err) {
+               err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
+                             priv->dpni_handle, mac_addr);
+               if (err) {
+                       printf("dpni_add_mac_addr() failed\n");
+                       return err;
+               }
+
+               memcpy(net_dev->enetaddr, mac_addr, 0x6);
+               err = 0;
+       } else {
+               printf("%s: MAC address is not set\n", ethaddr);
+               err = 1;
+       }
+
+       return err;
+}
+
 static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
                         const struct dpaa_fd *fd)
 {
@@ -216,7 +248,6 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 {
        struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
        struct dpni_queue_attr rx_queue_attr;
-       uint8_t mac_addr[6];
        int err;
 
        if (net_dev->state == ETH_STATE_ACTIVE)
@@ -236,20 +267,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
        if (err)
                goto err_bind;
 
-       err = dpni_get_primary_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
-                                       priv->dpni_handle, mac_addr);
-       if (err) {
-               printf("dpni_get_primary_mac_addr() failed\n");
+       err = ldpaa_set_mac_from_env(net_dev);
+       if (err)
                return err;
-       }
-
-       memcpy(net_dev->enetaddr, mac_addr, 0x6);
-
-       /* setup the MAC address */
-       if (net_dev->enetaddr[0] & 0x01) {
-               printf("%s: MacAddress is multcast address\n",  __func__);
-               return 1;
-       }
 
 #ifdef CONFIG_PHYLIB
        /* TODO Check this path */
--

1.9.1

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot