Skip to contentSkip to conversation

at91_emac: Write MAC address automatically

PATCH Superseded Eric Bénard 2 participants 5 messages Jun 15, 2010 – Jun 21, 2010

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

PATCH 2/2 at91_emac: Write MAC address automatically

tested on cpuat91.

---
 drivers/net/at91_emac.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)
drivers/net/at91_emac.c +23 -8
index 1ebcf05..ac5903d 100644
@@ -352,14 +352,6 @@ static int at91emac_init(struct eth_device *netdev, bd_t *bd)
 	writel(1 << AT91_ID_EMAC, &pmc->pcer);
 	writel(readl(&emac->ctl) | AT91_EMAC_CTL_CSR, &emac->ctl);
 
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
-		cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
-		cpu_to_le32(*((u32 *)netdev->enetaddr)));
-	writel(cpu_to_le32(*((u32 *)netdev->enetaddr)), &emac->sa2l);
-	writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))), &emac->sa2h);
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
-		readl(&emac->sa2h), readl(&emac->sa2l));
-
 	/* Init Ethernet buffers */
 	for (i = 0; i < RBF_FRAMEMAX; i++) {
 		dev->rbfdt[i].addr = (unsigned long) NetRxPackets[i];
@@ -460,6 +452,28 @@ static int at91emac_recv(struct eth_device *netdev)
 	return 0;
 }
 
+static int at91emac_write_hwaddr(struct eth_device *netdev)
+{
+	emac_device *dev;
+	at91_emac_t *emac;
+	at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
+
+	if (netdev->enetaddr != 0) {
+		emac = (at91_emac_t *) netdev->iobase;
+		dev = (emac_device *) netdev->priv;
+
+		writel(1 << AT91_ID_EMAC, &pmc->pcer);
+		DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
+			cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
+			cpu_to_le32(*((u32 *)netdev->enetaddr)));
+		writel(cpu_to_le32(*((u32 *)netdev->enetaddr)), &emac->sa2l);
+		writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))), &emac->sa2h);
+		DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
+			readl(&emac->sa2h), readl(&emac->sa2l));
+	}
+	return 0;
+}
+
 int at91emac_register(bd_t *bis, unsigned long iobase)
 {
 	emac_device *emac;
@@ -492,6 +506,7 @@ int at91emac_register(bd_t *bis, unsigned long iobase)
 	dev->halt = at91emac_halt;
 	dev->send = at91emac_send;
 	dev->recv = at91emac_recv;
+	dev->write_hwaddr = at91emac_write_hwaddr;
 
 	eth_register(dev);
 
Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 2/2 at91_emac: Write MAC address automatically

Hi Eric,

Quoted 28 lines · Eric B?nard

tested on cpuat91.

---
  drivers/net/at91_emac.c |   31 +++++++++++++++++++++++--------
  1 files changed, 23 insertions(+), 8 deletions(-)
drivers/net/at91_emac.c +0 -8
index 1ebcf05..ac5903d 100644
@@ -352,14 +352,6 @@ static int at91emac_init(struct eth_device *netdev, bd_t *bd)
  	writel(1<<  AT91_ID_EMAC,&pmc->pcer);
  	writel(readl(&emac->ctl) | AT91_EMAC_CTL_CSR,&emac->ctl);
 
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
-		cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
-		cpu_to_le32(*((u32 *)netdev->enetaddr)));
-	writel(cpu_to_le32(*((u32 *)netdev->enetaddr)),&emac->sa2l);
-	writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),&emac->sa2h);
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
-		readl(&emac->sa2h), readl(&emac->sa2l));
-
  	/* Init Ethernet buffers */
  	for (i = 0; i<  RBF_FRAMEMAX; i++) {
  		dev->rbfdt[i].addr = (unsigned long) NetRxPackets[i];
@@ -460,6 +452,28 @@ static int at91emac_recv(struct eth_device *netdev)
  	return 0;

drivers/net/at91_emac.c static int at91emac_recv(struct eth_device *netdev) · line 462

Quoted 10 lines
drivers/net/at91_emac.c +7 -0
  }
 
+static int at91emac_write_hwaddr(struct eth_device *netdev)
+{
+	emac_device *dev;
+	at91_emac_t *emac;
+	at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
+
+	if (netdev->enetaddr != 0) {
 

This check's not necessary. The caller checks if the MAC address is valid ( a more extensive check than you do here)

Quoted 20 lines
drivers/net/at91_emac.c +15 -0
+		emac = (at91_emac_t *) netdev->iobase;
+		dev = (emac_device *) netdev->priv;
+
+		writel(1<<  AT91_ID_EMAC,&pmc->pcer);
+		DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
+			cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
+			cpu_to_le32(*((u32 *)netdev->enetaddr)));
+		writel(cpu_to_le32(*((u32 *)netdev->enetaddr)),&emac->sa2l);
+		writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),&emac->sa2h);
+		DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
+			readl(&emac->sa2h), readl(&emac->sa2l));
+	}
+	return 0;
+}
+
  int at91emac_register(bd_t *bis, unsigned long iobase)
  {

emac_device *emac;

drivers/net/at91_emac.c int at91emac_register(bd_t *bis, unsigned long iobase) · line 512

Quoted 7 lines
drivers/net/at91_emac.c +1 -0
@@ -492,6 +506,7 @@ int at91emac_register(bd_t *bis, unsigned long iobase)
  	dev->halt = at91emac_halt;
  	dev->send = at91emac_send;
  	dev->recv = at91emac_recv;
+	dev->write_hwaddr = at91emac_write_hwaddr;
 
  	eth_register(dev);
 

regards,
Ben

#2 lore raw

PATCH v2 1/1 at91_emac: Write MAC address automatically

tested on cpuat91.

---
v2 :
don't check if the MAC address is valid

 drivers/net/at91_emac.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
drivers/net/at91_emac.c +20 -8
index cf0a7c0..1213a1a 100644
@@ -360,14 +360,6 @@ static int at91emac_init(struct eth_device *netdev, bd_t *bd)
 	writel(1 << AT91_ID_EMAC, &pmc->pcer);
 	writel(readl(&emac->ctl) | AT91_EMAC_CTL_CSR, &emac->ctl);
 
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
-		cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
-		cpu_to_le32(*((u32 *)netdev->enetaddr)));
-	writel(cpu_to_le32(*((u32 *)netdev->enetaddr)), &emac->sa2l);
-	writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))), &emac->sa2h);
-	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
-		readl(&emac->sa2h), readl(&emac->sa2l));
-
 	/* Init Ethernet buffers */
 	for (i = 0; i < RBF_FRAMEMAX; i++) {
 		dev->rbfdt[i].addr = (unsigned long) NetRxPackets[i];
@@ -468,6 +460,25 @@ static int at91emac_recv(struct eth_device *netdev)
 	return 0;
 }
 
+static int at91emac_write_hwaddr(struct eth_device *netdev)
+{
+	emac_device *dev;
+	at91_emac_t *emac;
+	at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
+	emac = (at91_emac_t *) netdev->iobase;
+	dev = (emac_device *) netdev->priv;
+
+	writel(1 << AT91_ID_EMAC, &pmc->pcer);
+	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
+		cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
+		cpu_to_le32(*((u32 *)netdev->enetaddr)));
+	writel(cpu_to_le32(*((u32 *)netdev->enetaddr)), &emac->sa2l);
+	writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))), &emac->sa2h);
+	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
+		readl(&emac->sa2h), readl(&emac->sa2l));
+	return 0;
+}
+
 int at91emac_register(bd_t *bis, unsigned long iobase)
 {
 	emac_device *emac;
@@ -500,6 +511,7 @@ int at91emac_register(bd_t *bis, unsigned long iobase)
 	dev->halt = at91emac_halt;
 	dev->send = at91emac_send;
 	dev->recv = at91emac_recv;
+	dev->write_hwaddr = at91emac_write_hwaddr;
 
 	eth_register(dev);
 
Signature · 1 line
1.6.3.3
Applied
#3 lore raw

PATCH v2 1/1 at91_emac: Write MAC address automatically

Hi Eric,

Quoted 10 lines · Eric B?nard

tested on cpuat91.

---
v2 :
don't check if the MAC address is valid

  drivers/net/at91_emac.c |   28 ++++++++++++++++++++--------
  1 files changed, 20 insertions(+), 8 deletions(-)

Applied to net/next repo.

regards,
Ben

#4 lore raw

PATCH 2/2 at91_emac: Write MAC address automatically

In reply to Ben Warren

Hi Ben,

Le 21/06/2010 07:59, Ben Warren a ?crit :

Quoted 6 lines · Eric B?nard

drivers/net/at91_emac.c static int at91emac_recv(struct eth_device *netdev) · line 461

Quoted 3 lines
drivers/net/at91_emac.c +2 -0
+
+	if (netdev->enetaddr != 0) {

This check's not necessary. The caller checks if the MAC address is valid ( a more extensive check than you do here)

OK, fixed patch sent, thanks.

Eric