public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] igb: allow optionally getting mac address from device tree
@ 2018-06-25  8:00 Marcel Ziswiler
  2018-06-25  8:05 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Marcel Ziswiler @ 2018-06-25  8:00 UTC (permalink / raw)
  To: netdev
  Cc: intel-wired-lan, Jeff Kirsher, Marcel Ziswiler, David S. Miller,
	linux-kernel

From: Marcel Ziswiler <marcel.ziswiler@toradex.com>

For Embedded use where e.g. i210/i211 chips may be used without
external EEPROMs but regardless of whether or not the MAC address is
actually programmed into the iNVM the boot loader may choose to pass
the MAC address to be used via device tree. Therefore, allow for
optionally getting the MAC address from device tree data e.g. as
follows (excerpt from a TK1 based board, local-mac-address to be
filled in by boot loader):

pcie@1003000 {
	...

	/* I210 Gigabit Ethernet Controller */
	pci@2,0 {
		...
		status = "okay";
		pcie@0 {
			reg = <0 0 0 0 0>;
			local-mac-address = [00 00 00 00 00 00];
		};
	};
};

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

---

 drivers/net/ethernet/intel/igb/igb_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index f707709969ac..0abf3698b05c 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -37,6 +37,7 @@
 #include <linux/dca.h>
 #endif
 #include <linux/i2c.h>
+#include <linux/of_net.h>
 #include "igb.h"
 
 #define MAJ 5
@@ -2931,6 +2932,7 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
 	int err, pci_using_dac;
 	u8 part_str[E1000_PBANUM_LENGTH];
+	const void *iap;
 
 	/* Catch broken hardware that put the wrong VF device ID in
 	 * the PCIe SR-IOV capability.
@@ -3122,7 +3124,11 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		break;
 	}
 
-	if (eth_platform_get_mac_address(&pdev->dev, hw->mac.addr)) {
+	/* try to get the MAC address from device tree data */
+	iap = of_get_mac_address(pdev->dev.of_node);
+	if (iap)
+		memcpy(hw->mac.addr, iap, ETH_ALEN);
+	else if (eth_platform_get_mac_address(&pdev->dev, hw->mac.addr)) {
 		/* copy the MAC address out of the NVM */
 		if (hw->mac.ops.read_mac_addr(hw))
 			dev_err(&pdev->dev, "NVM Read Error\n");
-- 
2.14.4


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

* Re: [PATCH] igb: allow optionally getting mac address from device tree
  2018-06-25  8:00 [PATCH] igb: allow optionally getting mac address from device tree Marcel Ziswiler
@ 2018-06-25  8:05 ` David Miller
  2018-06-25 11:25   ` Marcel Ziswiler
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2018-06-25  8:05 UTC (permalink / raw)
  To: marcel
  Cc: netdev, intel-wired-lan, jeffrey.t.kirsher, marcel.ziswiler,
	linux-kernel

From: Marcel Ziswiler <marcel@ziswiler.com>
Date: Mon, 25 Jun 2018 10:00:42 +0200

> @@ -3122,7 +3124,11 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  		break;
>  	}
>  
> -	if (eth_platform_get_mac_address(&pdev->dev, hw->mac.addr)) {
> +	/* try to get the MAC address from device tree data */
> +	iap = of_get_mac_address(pdev->dev.of_node);
> +	if (iap)
> +		memcpy(hw->mac.addr, iap, ETH_ALEN);

This is exactly what eth_platform_get_mac_address() shoule be doing.

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

* Re: [PATCH] igb: allow optionally getting mac address from device tree
  2018-06-25  8:05 ` David Miller
@ 2018-06-25 11:25   ` Marcel Ziswiler
  0 siblings, 0 replies; 3+ messages in thread
From: Marcel Ziswiler @ 2018-06-25 11:25 UTC (permalink / raw)
  To: davem@davemloft.net
  Cc: netdev@vger.kernel.org, jeffrey.t.kirsher@intel.com,
	intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org

Hi David

On Mon, 2018-06-25 at 17:05 +0900, David Miller wrote:
> From: Marcel Ziswiler <marcel@ziswiler.com>
> Date: Mon, 25 Jun 2018 10:00:42 +0200
> 
> > @@ -3122,7 +3124,11 @@ static int igb_probe(struct pci_dev *pdev,
> > const struct pci_device_id *ent)
> >  		break;
> >  	}
> >  
> > -	if (eth_platform_get_mac_address(&pdev->dev, hw-
> > >mac.addr)) {
> > +	/* try to get the MAC address from device tree data */
> > +	iap = of_get_mac_address(pdev->dev.of_node);
> > +	if (iap)
> > +		memcpy(hw->mac.addr, iap, ETH_ALEN);
> 
> This is exactly what eth_platform_get_mac_address() shoule be doing.

Yes, you are absolutely right. That indeed already works just fine given a
proper device tree. Struggling with the device tree part I probably missed
noticing this.

Sorry for the noise and thanks for the tip!

Cheers

Marcel

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

end of thread, other threads:[~2018-06-25 11:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-25  8:00 [PATCH] igb: allow optionally getting mac address from device tree Marcel Ziswiler
2018-06-25  8:05 ` David Miller
2018-06-25 11:25   ` Marcel Ziswiler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox