Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V5

2016-03-01 Thread John Holland

> On 02.03.2016, at 00:55, Jeff Kirsher <jeffrey.t.kirs...@intel.com> wrote:
> 
>> On Tue, 2016-03-01 at 07:56 +0100, John Holland wrote:
>> On Mar 1, 2016, at 03:52, Brown, Aaron F <aaron.f.br...@intel.com>
>> wrote:
>> 
>>> This throws a few checkpatch warnings, but I won't withhold my
>> tested by for these:
>>>  
>>> total: 0 errors, 2 warnings, 0 checks, 21 lines checked
>>>  
>>> Your patch has style problems, please review.
>>>  
>>> NOTE: If any of the errors are false positives, please report
>>>   them to the maintainer, see CHECKPATCH in MAINTAINERS.
>>> u1463:[0]/usr/src/kernels/next-queue>
>> 
>> Thanks for testing...
>> 
>> Do you require me to reformat the patch text? And won't that break
>> the link?
> 
> No, that checkpatch.pl warning on the link you provided is fine,
> although I will clean up your signed-off-by when I go to push it
> upstream. :-)

Thank you very much!


Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V5

2016-02-29 Thread John Holland
On Mar 1, 2016, at 03:52, Brown, Aaron F  wrote:

> This throws a few checkpatch warnings, but I won't withhold my tested by for 
> these:
> 
> total: 0 errors, 2 warnings, 0 checks, 21 lines checked
> 
> Your patch has style problems, please review.
> 
> NOTE: If any of the errors are false positives, please report
>  them to the maintainer, see CHECKPATCH in MAINTAINERS.
> u1463:[0]/usr/src/kernels/next-queue>

Thanks for testing...

Do you require me to reformat the patch text? And won't that break the link?

John


Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V4

2016-02-18 Thread John Holland

> On Feb 18, 2016, at 16:22, David Miller <da...@davemloft.net> wrote:
> 
> From: John Holland <jotih...@gmail.com>
> Date: Thu, 18 Feb 2016 08:53:07 +0100
> 
>> The PCI path in eth_platform_get_mac_address() didn't return a devicetree 
>> node...
> 
> Then fix your platform such that pci_device_to_OF_node() works
> properly instead of adding localized hacks to device drivers.
> 
> Jeff, do not apply this patch.

Please take a look at V5.


Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V5

2016-02-18 Thread John Holland



On 02/18/2016 12:10 PM, John Holland wrote:

Hello,

The Intel i211 LOM PCIe Ethernet controllers' iNVM operates as an OTP
and has no external EEPROM interface [1]. The following allows the
driver to pickup the MAC address from a device tree blob when CONFIG_OF
has been enabled.

+   if (eth_platform_get_mac_address(>dev, hw->mac.addr)) {


For later reference, putting all necessary information in one place.

This requires the dtb for the mac address routing to be properly 
positioned. On an imx6q using U-Boot, that required setting the U-Boot 
environment variable eth1addr and reworking the PCIe tree and allocating 
an alias as such:


1) Set intel,i211 MAC address.

# env set eth1addr 

2) Add an alias to pick up the MAC address from U-Boot and route it to 
the intel,i211 PCIe endpoint for an imx6qdl derivative.


/ {
aliases {
ethernet1 = 
};

};

 {
/* soc pcie bridge 00:00.0 */
pcie@0,0 {
reg = <0x00 0 0 0 0>;
#address-cells = <3>;
#size-cells = <2>;

/* pcie endpoint 01:00.0 */
eth1: intel,i211@pcie0,0 {
reg = <0x01 0 0 0 0>;
};
};
};

John


[Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V5

2016-02-18 Thread John Holland

Hello,

The Intel i211 LOM PCIe Ethernet controllers' iNVM operates as an OTP
and has no external EEPROM interface [1]. The following allows the
driver to pickup the MAC address from a device tree blob when CONFIG_OF
has been enabled.

[1] 
http://www.intel.com/content/www/us/en/embedded/products/networking/i211-ethernet-controller-datasheet.html


Changes V2
- Restrict searching for compatible devices to current pci device.

Changes V3
- Add device tree binding documentation.

Changes V4
- Rebase patch.

Changes V5
- Use eth_platform_get_mac_address() to resolve MAC specified in a dtb.
- Remove now invalid device tree binding documentation specified in V3
  und V4.

Signed-off-by: John Holland<jotih...@gmail.com>
---
 drivers/net/ethernet/intel/igb/igb_main.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c 
b/drivers/net/ethernet/intel/igb/igb_main.c

index a98f418..d3e8228 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 
 #ifdef CONFIG_IGB_DCA
 #include 
 #endif
@@ -2507,9 +2508,11 @@ static int igb_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)

break;
}

-   /* copy the MAC address out of the NVM */
-   if (hw->mac.ops.read_mac_addr(hw))
-   dev_err(>dev, "NVM Read Error\n");
+   if (eth_platform_get_mac_address(>dev, hw->mac.addr)) {
+   /* copy the MAC address out of the NVM */
+   if (hw->mac.ops.read_mac_addr(hw))
+   dev_err(>dev, "NVM Read Error\n");
+   }

memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);



Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V4

2016-02-17 Thread John Holland

> On Feb 18, 2016, at 03:29, David Miller <da...@davemloft.net> wrote:
> 
> From: John Holland <jotih...@gmail.com>
> Date: Thu, 18 Feb 2016 00:49:17 +0100
> 
>> The Intel i211 LOM pcie ethernet controllers' iNVM operates as an OTP
>> and has no externel EEPROM interface [1]. The following allows the
>> driver to pickup the MAC address from a device tree blob when
>> CONFIG_OF
>> has been enabled.
> 
> Please use the generic eth_platform_get_mac_address(), or
> alternatively structure your code like the ixgbe and other cases so
> that SPARC and other OF platforms get this support as well.

Don't know what you mean. The PCI path in eth_platform_get_mac_address() didn't 
return a devicetree node and I can find no instance of of_ use in 
ixgbe.

John


[Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V4

2016-02-17 Thread John Holland

Hello,

The Intel i211 LOM pcie ethernet controllers' iNVM operates as an OTP
and has no externel EEPROM interface [1]. The following allows the
driver to pickup the MAC address from a device tree blob when CONFIG_OF
has been enabled.

[1]http://www.intel.com/content/www/us/en/embedded/products/networking/i211-ethernet-controller-datasheet.html

Changes V2
- Restrict searching for compatible devices to current pci device.

Changes V3
- Add device tree binding documentation.

Changes V4
- Rebase patch.

Signed-off-by: John Holland<jotih...@gmail.com>
---

 Documentation/devicetree/bindings/net/intel,i210.txt | 36 
++
 drivers/net/ethernet/intel/igb/igb_main.c| 31 
+++

 2 files changed, 67 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/intel,i210.txt 
b/Documentation/devicetree/bindings/net/intel,i210.txt

new file mode 100644
index 000..d6ac8d3
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/intel,i210.txt
@@ -0,0 +1,36 @@
+* Intel I210, I211 PCIe bus controller
+
+Required properties:
+- compatible: must be "intel,i210" as described in
+  Documentation/devicetree/bindings/net/phy.txt;
+
+Optional properties:
+- local-mac-address: as described in
+  Documentation/devicetree/bindings/net/ethernet.txt;
+- mac-address: as described in
+  Documentation/devicetree/bindings/net/ethernet.txt;
+
+Child nodes of this PCIe bus controller node are a subset
+of the standard Ethernet PHY device nodes.
+
+Example:
+
+/*
+ * Set a valid MAC address from the u-boot environment variable eth1addr.
+ * The resulting value may be viewed under
+ * /firmware/devicetree/base/soc/pcie@0x0100/i211@bus1/
+ */
+
+#include "imx6q.dtsi";
+
+/ {
+   aliases {
+   ethernet1 = 
+   };
+};
+
+ {
+   eth1: i211@bus1 {
+   compatible = "intel,i210";
+   };
+};
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c 
b/drivers/net/ethernet/intel/igb/igb_main.c

index a98f418..a3203ec 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -57,6 +57,11 @@
 #include "igb.h"
 #include "igb_cdev.h"

+#ifdef CONFIG_OF
+#include 
+#include 
+#endif
+
 #define MAJ 5
 #define MIN 3
 #define BUILD 0
@@ -2299,6 +2304,27 @@ static s32 igb_init_i2c(struct igb_adapter *adapter)
return status;
 }

+#ifdef CONFIG_OF
+/**
+ *  igb_read_mac_addr_dts - Read mac address from the device tree blob
+ *  @dev: pointer to device structure
+ *  @mac_addr: pointer to found mac address
+ **/
+static void igb_read_mac_addr_dts(const struct device *dev, u8 *mac_addr)
+{
+   const u8 *mac;
+   struct device_node *dn;
+
+   dn = of_find_compatible_node(dev->of_node, NULL, "intel,i210");
+   if (dn) {
+   mac = of_get_mac_address(dn);
+   if (mac)
+   ether_addr_copy(mac_addr, mac);
+   }
+}
+#endif
+
+
 /**
  *  igb_probe - Device Initialization Routine
  *  @pdev: PCI device information struct
@@ -2511,6 +2537,11 @@ static int igb_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)

if (hw->mac.ops.read_mac_addr(hw))
dev_err(>dev, "NVM Read Error\n");

+#ifdef CONFIG_OF
+   if (!is_valid_ether_addr(hw->mac.addr))
+   igb_read_mac_addr_dts(>dev, hw->mac.addr);
+#endif
+
memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);

if (!is_valid_ether_addr(netdev->dev_addr)) {


[Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V3

2016-02-16 Thread John Holland

Hello,

The Intel i211 LOM pcie ethernet controllers' iNVM operates as an OTP
and has no externel EEPROM interface [1]. The following allows the
driver to pickup the MAC address from a device tree blob when CONFIG_OF
has been enabled.

[1]http://www.intel.com/content/www/us/en/embedded/products/networking/i211-ethernet-controller-datasheet.html

Changes V2
- Restrict searching for compatible devices to current pci device.

Changes V3
- Add device tree binding documentation.

Signed-off-by: John Holland<jotih...@gmail.com>
---

 Documentation/devicetree/bindings/net/intel,i210.txt | 36 

 drivers/net/ethernet/intel/igb/igb_main.c| 30 
++
 2 files changed, 66 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/intel,i210.txt 
b/Documentation/devicetree/bindings/net/intel,i210.txt
new file mode 100644
index 000..d6ac8d3
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/intel,i210.txt
@@ -0,0 +1,36 @@
+* Intel I210, I211 PCIe bus controller
+
+Required properties:
+- compatible: must be "intel,i210" as described in
+  Documentation/devicetree/bindings/net/phy.txt;
+
+Optional properties:
+- local-mac-address: as described in
+  Documentation/devicetree/bindings/net/ethernet.txt;
+- mac-address: as described in
+  Documentation/devicetree/bindings/net/ethernet.txt;
+
+Child nodes of this PCIe bus controller node are a subset
+of the standard Ethernet PHY device nodes.
+
+Example:
+
+/*
+ * Set a valid MAC address from the u-boot environment variable eth1addr.
+ * The resulting value may be viewed under
+ * /firmware/devicetree/base/soc/pcie@0x0100/i211@bus1/
+ */
+
+#include "imx6q.dtsi";
+
+/ {
+   aliases {
+   ethernet1 = 
+   };
+};
+
+ {
+   eth1: i211@bus1 {
+   compatible = "intel,i210";
+   };
+};
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c 
b/drivers/net/ethernet/intel/igb/igb_main.c
index 31e5f39..f7788fa 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -56,6 +56,11 @@
 #include 
 #include "igb.h"
 
+#ifdef CONFIG_OF

+#include 
+#include 
+#endif
+
 #define MAJ 5
 #define MIN 3
 #define BUILD 0
@@ -2216,6 +2221,26 @@ static s32 igb_init_i2c(struct igb_adapter *adapter)
return status;
 }
 
+#ifdef CONFIG_OF

+/**
+ *  igb_read_mac_addr_dts - Read mac address from the device tree blob
+ *  @dev: pointer to device structure
+ *  @mac_addr: pointer to found mac address
+ **/
+static void igb_read_mac_addr_dts(const struct device *dev, u8 *mac_addr)
+{
+   const u8 *mac;
+   struct device_node *dn;
+
+   dn = of_find_compatible_node(dev->of_node, NULL, "intel,i210");
+   if (dn) {
+   mac = of_get_mac_address(dn);
+   if (mac)
+   ether_addr_copy(mac_addr, mac);
+   }
+}
+#endif
+
 /**
  *  igb_probe - Device Initialization Routine
  *  @pdev: PCI device information struct
@@ -2420,6 +2445,11 @@ static int igb_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
if (hw->mac.ops.read_mac_addr(hw))
dev_err(>dev, "NVM Read Error\n");
 
+#ifdef CONFIG_OF

+   if (!is_valid_ether_addr(hw->mac.addr))
+   igb_read_mac_addr_dts(>dev, hw->mac.addr);
+#endif
+
memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
 
 	if (!is_valid_ether_addr(netdev->dev_addr)) {




Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V2

2016-02-16 Thread John Holland

> On Feb 16, 2016, at 17:58, Andrew Lunn <and...@lunn.ch> wrote:
> 
>> On Sat, Feb 13, 2016 at 11:04:45PM +0100, John Holland wrote:
>> Hello,
>> 
>> The Intel i211 LOM pcie ethernet controllers' iNVM operates as an
>> OTP and has no externel EEPROM interface [1]. The following allows
>> the driver to pickup the MAC address from a device tree blob when
>> CONFIG_OF has been enabled.
>> 
>> [1] 
>> http://www.intel.com/content/www/us/en/embedded/products/networking/i211-ethernet-controller-datasheet.html
>> 
>> Changes V2
>> - Restrict searching for compatible devices to current pci device.
>> 
>> Signed-off-by: John Holland <jotih...@gmail.com>
> 
> Hi John
> 
> Thanks for fixing multiple device support.
> 
> Please could you add documentation in
> Documentation/devicetree/bindings/net. I know these are standard
> properties, but it is somewhat unusual to attach them to a PCI node,
> so having an example would be good.
> 
>   Thanks
>Andrew

Odd that the marvel sky2 allows just that, but supplies no documentation.

I can supply some kind of usage description/example, showing how to use this 
feature to pull in the MAC address from u-boot and route it to the i210. Just 
uncertain as how to name the respective file. igb.txt or i210.txt come to mind. 
Do you prefer one over the other?

John


[Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob V2

2016-02-13 Thread John Holland

Hello,

The Intel i211 LOM pcie ethernet controllers' iNVM operates as an OTP 
and has no externel EEPROM interface [1]. The following allows the 
driver to pickup the MAC address from a device tree blob when CONFIG_OF 
has been enabled.


[1] 
http://www.intel.com/content/www/us/en/embedded/products/networking/i211-ethernet-controller-datasheet.html


Changes V2
- Restrict searching for compatible devices to current pci device.

Signed-off-by: John Holland <jotih...@gmail.com>
---

 drivers/net/ethernet/intel/igb/igb_main.c | 30 
++

 1 file changed, 30 insertions(+)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c 
b/drivers/net/ethernet/intel/igb/igb_main.c

index 31e5f39..f7788fa 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -56,6 +56,11 @@
 #include 
 #include "igb.h"

+#ifdef CONFIG_OF
+#include 
+#include 
+#endif
+
 #define MAJ 5
 #define MIN 3
 #define BUILD 0
@@ -2216,6 +2221,26 @@ static s32 igb_init_i2c(struct igb_adapter *adapter)
return status;
 }

+#ifdef CONFIG_OF
+/**
+ *  igb_read_mac_addr_dts - Read mac address from the device tree blob
+ *  @dev: pointer to device structure
+ *  @mac_addr: pointer to found mac address
+ **/
+static void igb_read_mac_addr_dts(const struct device *dev, u8 *mac_addr)
+{
+   const u8 *mac;
+   struct device_node *dn;
+
+   dn = of_find_compatible_node(dev->of_node, NULL, "intel,i210");
+   if (dn) {
+   mac = of_get_mac_address(dn);
+   if (mac)
+   ether_addr_copy(mac_addr, mac);
+   }
+}
+#endif
+
 /**
  *  igb_probe - Device Initialization Routine
  *  @pdev: PCI device information struct
@@ -2420,6 +2445,11 @@ static int igb_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)

if (hw->mac.ops.read_mac_addr(hw))
dev_err(>dev, "NVM Read Error\n");

+#ifdef CONFIG_OF
+   if (!is_valid_ether_addr(hw->mac.addr))
+   igb_read_mac_addr_dts(>dev, hw->mac.addr);
+#endif
+
memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);

if (!is_valid_ether_addr(netdev->dev_addr)) {



Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob

2016-02-10 Thread John Holland

> On Feb 9, 2016, at 12:02, Jeff Kirsher <jeffrey.t.kirs...@intel.com> wrote:
> 
>> On Fri, 2016-01-29 at 23:11 +0100, John Holland wrote:
>> The Intel i211 LOM pcie ethernet controllers' iNVM operates as an
>> OTP 
>> and has no externel EEPROM interface [1]. The following allows the 
>> driver to pickup the MAC address from a device tree blob when
>> CONFIG_OF 
>> has been enabled.
>> 
>> [1] 
>> http://www.intel.com/content/www/us/en/embedded/products/networking/i
>> 211-ethernet-controller-datasheet.html
>> 
>> Signed-off-by: John Holland <jotih...@gmail.com>
>> ---
>>   drivers/net/ethernet/intel/igb/igb_main.c | 30 
>> ++
>>   1 file changed, 30 insertions(+)
>> 
>> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c 
>> b/drivers/net/ethernet/intel/igb/igb_main.c
>> index 31e5f39..9c92443 100644
>> --- a/drivers/net/ethernet/intel/igb/igb_main.c
>> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
>> @@ -56,6 +56,11 @@
>>   #include 
>>   #include "igb.h"
>> 
>> +#ifdef defined(CONFIG_OF)
>> +#include 
>> +#include 
>> +#endif
>> +
>>   #define MAJ 5
>>   #define MIN 3
>>   #define BUILD 0
>> @@ -2217,6 +,26 @@ static s32 igb_init_i2c(struct igb_adapter
>> *adapter)
>>   }
>> 
>>   /**
>> + *  igb_read_mac_addr_dts - Read mac addres from the device tree
>> blob.
> 
> Address is mis-spelled above

Correct. Will fix this.

> 
>> + *  @hw: pointer to the e1000 hardware structure
>> + **/
>> +#ifdef defined(CONFIG_OF)
> 
> Minor nitpick, you should have the function comment header wrapped in
> the #ifdef as well.

No problem...
I'll do that right too.

> 
>> +static void igb_read_mac_addr_dts(struct e1000_hw *hw)
>> +{
>> +   const u8 *mac;
>> +   struct device_node *dn;
>> +
>> +   dn = of_find_compatible_node(NULL, NULL, "intel,i211");
>> +   if (!dn)
>> +   return;
>> +
>> +   mac = of_get_mac_address(dn);
>> +   if (mac)
>> +   ether_addr_copy(hw->mac.addr, mac);
>> +}
>> +#endif
>> +
>> +/**
>>*  igb_probe - Device Initialization Routine
>>*  @pdev: PCI device information struct
>>*  @ent: entry in igb_pci_tbl
>> @@ -2420,6 +2445,11 @@ static int igb_probe(struct pci_dev *pdev,
>> const 
>> struct pci_device_id *ent)
>>  if (hw->mac.ops.read_mac_addr(hw))
>>  dev_err(>dev, "NVM Read Error\n");
>> 
>> +#ifdef defined(CONFIG_OF)
>> +   if (!is_valid_ether_addr(hw->mac.addr))
>> +   igb_read_mac_addr_dts(hw);
>> +#endif
>> +
>>  memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
>> 
>>  if (!is_valid_ether_addr(netdev->dev_addr)) {
>> ___
>> Intel-wired-lan mailing list
>> intel-wired-...@lists.osuosl.org
>> http://lists.osuosl.org/mailman/listinfo/intel-wired-lan


Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob

2016-02-10 Thread John Holland



Sent from my iPad
On Feb 9, 2016, at 12:54, Andrew Lunn  wrote:

>>> +static void igb_read_mac_addr_dts(struct e1000_hw *hw)
>>> +{
>>> +   const u8 *mac;
>>> +   struct device_node *dn;
>>> +
>>> +   dn = of_find_compatible_node(NULL, NULL, "intel,i211");
> 
> Hi John
> 
> Would this also work for the i210?

The usability scenario of i210 and i211 seem similar enough. Although, I will 
not be able to test the i210, I will use it as the compatible keyword.

> 
> If so, you normally use the compatible string for the first device
> this works with. So maybe this should be changed to intel,i210?
> 
> Thanks
>Andrew


Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob

2016-02-10 Thread John Holland

On Feb 9, 2016, at 12:59, Andrew Lunn  wrote:

>>> +   dn = of_find_compatible_node(NULL, NULL, "intel,i211");
> 
> Humm, NULL, NULL. That means find the first node anywhere in the
> device tree which matches. This is not going to work too well when you
> have multiple i211s.
> 
> There is a way so specify a DT node is attached to a specific PCIe
> bus/slot. I think you should search only there, so solving the
> multiple device issue.
> 

Good point. Will specify the current PCIe node.



Re: [Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob

2016-02-10 Thread John Holland

> On Feb 9, 2016, at 18:42, Shannon Nelson  wrote:
> 
> It seem to me this should be using eth_platform_get_mac_address(), a
> slightly more generic method to do this.  See the i40e driver for an
> example, commit d9a84324e6 I believe.
> 
I believe you are referring to https://patchwork.ozlabs.org/patch/566806. 
Haven't seen this used upstream yet. And, does that not mandate CONFIG_OF?

John


[Intel-wired-lan] [next] igb: allow setting MAC address on i211 using a device tree blob

2016-01-29 Thread John Holland
The Intel i211 LOM pcie ethernet controllers' iNVM operates as an OTP 
and has no externel EEPROM interface [1]. The following allows the 
driver to pickup the MAC address from a device tree blob when CONFIG_OF 
has been enabled.


[1] 
http://www.intel.com/content/www/us/en/embedded/products/networking/i211-ethernet-controller-datasheet.html


Signed-off-by: John Holland <jotih...@gmail.com>
---
 drivers/net/ethernet/intel/igb/igb_main.c | 30 
++

 1 file changed, 30 insertions(+)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c 
b/drivers/net/ethernet/intel/igb/igb_main.c

index 31e5f39..9c92443 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -56,6 +56,11 @@
 #include 
 #include "igb.h"

+#ifdef defined(CONFIG_OF)
+#include 
+#include 
+#endif
+
 #define MAJ 5
 #define MIN 3
 #define BUILD 0
@@ -2217,6 +,26 @@ static s32 igb_init_i2c(struct igb_adapter *adapter)
 }

 /**
+ *  igb_read_mac_addr_dts - Read mac addres from the device tree blob.
+ *  @hw: pointer to the e1000 hardware structure
+ **/
+#ifdef defined(CONFIG_OF)
+static void igb_read_mac_addr_dts(struct e1000_hw *hw)
+{
+   const u8 *mac;
+   struct device_node *dn;
+
+   dn = of_find_compatible_node(NULL, NULL, "intel,i211");
+   if (!dn)
+   return;
+
+   mac = of_get_mac_address(dn);
+   if (mac)
+   ether_addr_copy(hw->mac.addr, mac);
+}
+#endif
+
+/**
  *  igb_probe - Device Initialization Routine
  *  @pdev: PCI device information struct
  *  @ent: entry in igb_pci_tbl
@@ -2420,6 +2445,11 @@ static int igb_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)

if (hw->mac.ops.read_mac_addr(hw))
dev_err(>dev, "NVM Read Error\n");

+#ifdef defined(CONFIG_OF)
+   if (!is_valid_ether_addr(hw->mac.addr))
+   igb_read_mac_addr_dts(hw);
+#endif
+
memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);

if (!is_valid_ether_addr(netdev->dev_addr)) {