Skip to contentSkip to conversation

net: ethernet: bgmac: Allow MAC address to be specified in DTB

PATCH Applied Steve Lin 4 participants 4 messages Mar 16, 2017

Subsystems (3)
lore
Share & tools
lore

Steve Lin

author
#0 lore raw

PATCH 1/1 net: ethernet: bgmac: Allow MAC address to be specified in DTB

Allows the BCMA version of the bgmac driver to obtain MAC address from the device tree. If no MAC address is specified there, then the previous behavior (obtaining MAC address from SPROM) is used.

---
 drivers/net/ethernet/broadcom/bgmac-bcma.c | 39 ++++++++++++++++++------------
 1 file changed, 23 insertions(+), 16 deletions(-)
drivers/net/ethernet/broadcom/bgmac-bcma.c +23 -16
index cf15b7e..6322594 100644
@@ -11,6 +11,7 @@
 #include <linux/bcma/bcma.h>
 #include <linux/brcmphy.h>
 #include <linux/etherdevice.h>
+#include <linux/of_net.h>
 #include "bgmac.h"
 
 static inline bool bgmac_is_bcm4707_family(struct bcma_device *core)
@@ -114,7 +115,7 @@ static int bgmac_probe(struct bcma_device *core)
 	struct ssb_sprom *sprom = &core->bus->sprom;
 	struct mii_bus *mii_bus;
 	struct bgmac *bgmac;
-	u8 *mac;
+	const u8 *mac = NULL;
 	int err;
 
 	bgmac = bgmac_alloc(&core->dev);
@@ -127,21 +128,27 @@ static int bgmac_probe(struct bcma_device *core)
 
 	bcma_set_drvdata(core, bgmac);
 
-	switch (core->core_unit) {
-	case 0:
-		mac = sprom->et0mac;
-		break;
-	case 1:
-		mac = sprom->et1mac;
-		break;
-	case 2:
-		mac = sprom->et2mac;
-		break;
-	default:
-		dev_err(bgmac->dev, "Unsupported core_unit %d\n",
-			core->core_unit);
-		err = -ENOTSUPP;
-		goto err;
+	if (bgmac->dev->of_node)
+		mac = of_get_mac_address(bgmac->dev->of_node);
+
+	/* If no MAC address assigned via device tree, check SPROM */
+	if (!mac) {
+		switch (core->core_unit) {
+		case 0:
+			mac = sprom->et0mac;
+			break;
+		case 1:
+			mac = sprom->et1mac;
+			break;
+		case 2:
+			mac = sprom->et2mac;
+			break;
+		default:
+			dev_err(bgmac->dev, "Unsupported core_unit %d\n",
+				core->core_unit);
+			err = -ENOTSUPP;
+			goto err;
+		}
 	}
 
 	ether_addr_copy(bgmac->net_dev->dev_addr, mac);
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Steve Lin

Allows the BCMA version of the bgmac driver to obtain MAC address from the device tree. If no MAC address is specified there, then the previous behavior (obtaining MAC address from SPROM) is used.

PS: you might want to specify which tree this applies to by using [PATCH net-next] or [PATCH net] in the subject, see the netdev-FAQ.txt for details:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/netdev-FAQ.txt

Quoted 69 lines
---
 drivers/net/ethernet/broadcom/bgmac-bcma.c | 39 ++++++++++++++++++------------
 1 file changed, 23 insertions(+), 16 deletions(-)
drivers/net/ethernet/broadcom/bgmac-bcma.c +23 -16
index cf15b7e..6322594 100644
@@ -11,6 +11,7 @@
 #include <linux/bcma/bcma.h>
 #include <linux/brcmphy.h>
 #include <linux/etherdevice.h>
+#include <linux/of_net.h>
 #include "bgmac.h"
 
 static inline bool bgmac_is_bcm4707_family(struct bcma_device *core)
@@ -114,7 +115,7 @@ static int bgmac_probe(struct bcma_device *core)
 	struct ssb_sprom *sprom = &core->bus->sprom;
 	struct mii_bus *mii_bus;
 	struct bgmac *bgmac;
-	u8 *mac;
+	const u8 *mac = NULL;
 	int err;
 
 	bgmac = bgmac_alloc(&core->dev);
@@ -127,21 +128,27 @@ static int bgmac_probe(struct bcma_device *core)
 
 	bcma_set_drvdata(core, bgmac);
 
-	switch (core->core_unit) {
-	case 0:
-		mac = sprom->et0mac;
-		break;
-	case 1:
-		mac = sprom->et1mac;
-		break;
-	case 2:
-		mac = sprom->et2mac;
-		break;
-	default:
-		dev_err(bgmac->dev, "Unsupported core_unit %d\n",
-			core->core_unit);
-		err = -ENOTSUPP;
-		goto err;
+	if (bgmac->dev->of_node)
+		mac = of_get_mac_address(bgmac->dev->of_node);
+
+	/* If no MAC address assigned via device tree, check SPROM */
+	if (!mac) {
+		switch (core->core_unit) {
+		case 0:
+			mac = sprom->et0mac;
+			break;
+		case 1:
+			mac = sprom->et1mac;
+			break;
+		case 2:
+			mac = sprom->et2mac;
+			break;
+		default:
+			dev_err(bgmac->dev, "Unsupported core_unit %d\n",
+				core->core_unit);
+			err = -ENOTSUPP;
+			goto err;
+		}
 	}
 
 	ether_addr_copy(bgmac->net_dev->dev_addr, mac);
Signature · 1 line
Florian
Acked-by
#2 lore raw
Quoted 6 lines · Florian Fainelli
Quoted 5 lines · Steve Lin

Allows the BCMA version of the bgmac driver to obtain MAC address from the device tree. If no MAC address is specified there, then the previous behavior (obtaining MAC address from SPROM) is used.

Quoted 8 lines
Quoted 1 line

PS: you might want to specify which tree this applies to by using [PATCH net-next] or [PATCH net] in the subject, see the netdev-FAQ.txt for details:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/netdev-FAQ.txt

I believe he wants this in net-next

Quoted 73 lines
Quoted 59 lines
---
 drivers/net/ethernet/broadcom/bgmac-bcma.c | 39 ++++++++++++++++++------------
 1 file changed, 23 insertions(+), 16 deletions(-)
drivers/net/ethernet/broadcom/bgmac-bcma.c +16 -16
index cf15b7e..6322594 100644
@@ -11,6 +11,7 @@
 #include <linux/bcma/bcma.h>
 #include <linux/brcmphy.h>
 #include <linux/etherdevice.h>
+#include <linux/of_net.h>
 #include "bgmac.h"
 
 static inline bool bgmac_is_bcm4707_family(struct bcma_device *core)
@@ -114,7 +115,7 @@ static int bgmac_probe(struct bcma_device *core)
      struct ssb_sprom *sprom = &core->bus->sprom;
      struct mii_bus *mii_bus;
      struct bgmac *bgmac;
-     u8 *mac;
+     const u8 *mac = NULL;
      int err;
 
      bgmac = bgmac_alloc(&core->dev);
@@ -127,21 +128,27 @@ static int bgmac_probe(struct bcma_device *core)
 
      bcma_set_drvdata(core, bgmac);
 
-     switch (core->core_unit) {
-     case 0:
-             mac = sprom->et0mac;
-             break;
-     case 1:
-             mac = sprom->et1mac;
-             break;
-     case 2:
-             mac = sprom->et2mac;
-             break;
-     default:
-             dev_err(bgmac->dev, "Unsupported core_unit %d\n",
-                     core->core_unit);
-             err = -ENOTSUPP;
-             goto err;
+     if (bgmac->dev->of_node)
+             mac = of_get_mac_address(bgmac->dev->of_node);
+
+     /* If no MAC address assigned via device tree, check SPROM */
+     if (!mac) {
+             switch (core->core_unit) {
+             case 0:
+                     mac = sprom->et0mac;
+                     break;
+             case 1:
+                     mac = sprom->et1mac;
+                     break;
+             case 2:
+                     mac = sprom->et2mac;

drivers/net/ethernet/broadcom/bgmac-bcma.c static int bgmac_probe(struct bcma_device *core) · line 154

Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac-bcma.c +7 -0
+                     break;
+             default:
+                     dev_err(bgmac->dev, "Unsupported core_unit %d\n",
+                             core->core_unit);
+                     err = -ENOTSUPP;
+                     goto err;
+             }
      }
 
      ether_addr_copy(bgmac->net_dev->dev_addr, mac);

--
Florian