Skip to contentSkip to conversation

ixgbe: Look up MAC address in Open Firmware

PATCH In review Martin K. Petersen 7 participants 9 messages Nov 14, 2014 – Nov 17, 2014

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

PATCH 1/1 ixgbe: Look up MAC address in Open Firmware

Attempt to look up the MAC address in Open Firmware on systems that support it. If the "local-mac-address" property is not valid resort to using the IDPROM value.

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +34 -0
index d2df4e3d1032..365924124fab 100644
@@ -50,6 +50,11 @@
 #include <linux/prefetch.h>
 #include <scsi/fc/fc_fcoe.h>
 
+#ifdef CONFIG_OF
+#include <asm/idprom.h>
+#include <asm/prom.h>
+#endif
+
 #include "ixgbe.h"
 #include "ixgbe_common.h"
 #include "ixgbe_dcb_82599.h"
@@ -7959,6 +7964,31 @@ int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
 	return is_wol_supported;
 }
 
+#ifdef CONFIG_OF
+/**
+ * ixgbe_of_mac_addr - Look up MAC address in Open Firmware
+ * @adapter: Pointer to adapter struct
+ */
+static void ixgbe_of_mac_addr(struct ixgbe_adapter *adapter)
+{
+	struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
+	struct ixgbe_hw *hw = &adapter->hw;
+	const unsigned char *addr;
+	int len;
+
+	addr = of_get_property(dp, "local-mac-address", &len);
+	if (addr && len == 6) {
+		e_dev_info("Using OpenPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, addr, 6);
+	}
+
+	if (!is_valid_ether_addr(hw->mac.perm_addr)) {
+		e_dev_info("Using IDPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, idprom->id_ethaddr, 6);
+	}
+}
+#endif
+
 /**
  * ixgbe_probe - Device Initialization Routine
  * @pdev: PCI device information struct
@@ -8223,6 +8253,10 @@ skip_sriov:
 		goto err_sw_init;
 	}
 
+#ifdef CONFIG_OF
+	ixgbe_of_mac_addr(adapter);
+#endif
+
 	memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
 
 	if (!is_valid_ether_addr(netdev->dev_addr)) {
#1 lore raw
Quoted 6 lines · Martin K. Petersen

Attempt to look up the MAC address in Open Firmware on systems that support it. If the "local-mac-address" property is not valid resort to using the IDPROM value.

Thanks Martin, I will add your patch to my queue.

#2 lore raw
In reply to Martin K. Petersen

Hello.

Quoted 10 lines · Martin K. Petersen

Attempt to look up the MAC address in Open Firmware on systems that support it. If the "local-mac-address" property is not valid resort to using the IDPROM value.

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +0 -0
index d2df4e3d1032..365924124fab 100644

[...]

Quoted 33 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +25 -0
@@ -7959,6 +7964,31 @@ int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  	return is_wol_supported;
  }
 
+#ifdef CONFIG_OF
+/**
+ * ixgbe_of_mac_addr - Look up MAC address in Open Firmware
+ * @adapter: Pointer to adapter struct
+ */
+static void ixgbe_of_mac_addr(struct ixgbe_adapter *adapter)
+{
+	struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
+	struct ixgbe_hw *hw = &adapter->hw;
+	const unsigned char *addr;
+	int len;
+
+	addr = of_get_property(dp, "local-mac-address", &len);
+	if (addr && len == 6) {
+		e_dev_info("Using OpenPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, addr, 6);
+	}
+
+	if (!is_valid_ether_addr(hw->mac.perm_addr)) {
+		e_dev_info("Using IDPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, idprom->id_ethaddr, 6);
+	}
+}
+#endif
+
  /**
   * ixgbe_probe - Device Initialization Routine
   * @pdev: PCI device information struct

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c skip_sriov: · line 8258

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
@@ -8223,6 +8253,10 @@ skip_sriov:
  		goto err_sw_init;
  	}
 
+#ifdef CONFIG_OF
+	ixgbe_of_mac_addr(adapter);
+#endif

Eww... why not define the following above instead:

#else
static inline void ixgbe_of_mac_addr(struct ixgbe_adapter *adapter) {} #endif

This is closer to what Documentation/SubmittingPatches suggests.

WBR, Sergei

#3 lore raw
Quoted 5 lines

Review

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Sergei" == Sergei Shtylyov <[email protected]> writes:

(quoted diff) +3 -0
+#ifdef CONFIG_OF
+ ixgbe_of_mac_addr(adapter);
+#endif

Sergei> Eww... why not define the following above instead:

Sergei> #else
Sergei> static inline void ixgbe_of_mac_addr(struct ixgbe_adapter Sergei> *adapter) {}
Sergei> #endif

I don't care much either way. But we might as well do this, then, and shave off an ifdef...

commit 01e25f145972563ee87ebf85b7cb02a4ff8fce3b

Author: Martin K. Petersen <[email protected]>
Date:   Wed Nov 12 20:47:42 2014 -0500

ixgbe: Look up MAC address in Open Firmware

Attempt to look up the MAC address in Open Firmware on systems that support it. If the "local-mac-address" property is not valid resort to using the IDPROM value.

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +32 -0
index d2df4e3d1032..0e45a43172eb 100644
@@ -50,6 +50,11 @@
 #include <linux/prefetch.h>
 #include <scsi/fc/fc_fcoe.h>
 
+#ifdef CONFIG_OF
+#include <asm/idprom.h>
+#include <asm/prom.h>
+#endif
+
 #include "ixgbe.h"
 #include "ixgbe_common.h"
 #include "ixgbe_dcb_82599.h"
@@ -7960,6 +7965,31 @@ int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
 }
 
 /**
+ * ixgbe_of_mac_addr - Look up MAC address in Open Firmware
+ * @adapter: Pointer to adapter struct
+ */
+static void ixgbe_of_mac_addr(struct ixgbe_adapter *adapter)
+{
+#ifdef CONFIG_OF
+	struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
+	struct ixgbe_hw *hw = &adapter->hw;
+	const unsigned char *addr;
+	int len;
+
+	addr = of_get_property(dp, "local-mac-address", &len);
+	if (addr && len == 6) {
+		e_dev_info("Using OpenPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, addr, 6);
+	}
+
+	if (!is_valid_ether_addr(hw->mac.perm_addr)) {
+		e_dev_info("Using IDPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, idprom->id_ethaddr, 6);
+	}
+#endif
+}
+
+/**
  * ixgbe_probe - Device Initialization Routine
  * @pdev: PCI device information struct
  * @ent: entry in ixgbe_pci_tbl
@@ -8223,6 +8253,8 @@ skip_sriov:
 		goto err_sw_init;
 	}
 
+	ixgbe_of_mac_addr(adapter);
+
 	memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
 
 	if (!is_valid_ether_addr(netdev->dev_addr)) {
#4 lore raw
Quoted 11 lines · On Fri, 14 Nov 2014 15:20:09 -0500 "Martin K. Petersen"…

commit 01e25f145972563ee87ebf85b7cb02a4ff8fce3b

Author: Martin K. Petersen <[email protected]>
Date:   Wed Nov 12 20:47:42 2014 -0500

ixgbe: Look up MAC address in Open Firmware

Attempt to look up the MAC address in Open Firmware on systems that support it. If the "local-mac-address" property is not valid resort to using the IDPROM value.

seems fine, but see below...

Quoted 30 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +14 -0
index d2df4e3d1032..0e45a43172eb 100644
@@ -50,6 +50,11 @@
 #include <linux/prefetch.h>
 #include <scsi/fc/fc_fcoe.h>
 
+#ifdef CONFIG_OF
+#include <asm/idprom.h>
+#include <asm/prom.h>
+#endif
+
 #include "ixgbe.h"
 #include "ixgbe_common.h"
 #include "ixgbe_dcb_82599.h"
@@ -7960,6 +7965,31 @@ int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
 }
 
 /**
+ * ixgbe_of_mac_addr - Look up MAC address in Open Firmware
+ * @adapter: Pointer to adapter struct
+ */
+static void ixgbe_of_mac_addr(struct ixgbe_adapter *adapter)
+{
+#ifdef CONFIG_OF
+	struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
+	struct ixgbe_hw *hw = &adapter->hw;
+	const unsigned char *addr;

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, · line 7986

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +10 -0
+	int len;
+
+	addr = of_get_property(dp, "local-mac-address", &len);
+	if (addr && len == 6) {
+		e_dev_info("Using OpenPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, addr, 6);
+	}
+
+	if (!is_valid_ether_addr(hw->mac.perm_addr)) {
+		e_dev_info("Using IDPROM MAC address\n");

There really isn't much point to print this message, just delete this e_dev_info line.

maintainer
#7 lore raw
In reply to Martin K. Petersen

From: "Martin K. Petersen" <[email protected]>
Date: Fri, 14 Nov 2014 14:16:50 -0500

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c line 56

Quoted 4 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +4 -0
+#ifdef CONFIG_OF
+#include <asm/idprom.h>
+#include <asm/prom.h>
+#endif

CONFIG_OF doesn't imply the presence of idprom.

idprom is completely sparc/m68k specific, whereas OF exists on many platforms other than sparc/m68k.

#5 lore raw
In reply to Martin K. Petersen
Quoted 23 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Sergei" == Sergei Shtylyov <[email protected]>

Quoted 3 lines · writes:

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c line 56

Quoted 3 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
+#ifdef CONFIG_OF
+ ixgbe_of_mac_addr(adapter);
+#endif

Sergei> Eww... why not define the following above instead:

Sergei> #else
Sergei> static inline void ixgbe_of_mac_addr(struct ixgbe_adapter Sergei> *adapter) {}
Sergei> #endif

I don't care much either way. But we might as well do this, then, and shave off an ifdef...

commit 01e25f145972563ee87ebf85b7cb02a4ff8fce3b

Author: Martin K. Petersen <[email protected]>
Date:   Wed Nov 12 20:47:42 2014 -0500

ixgbe: Look up MAC address in Open Firmware

Quoted 7 lines

Attempt to look up the MAC address in Open Firmware on systems
that
support it. If the "local-mac-address" property is not valid
resort to
using the IDPROM value.

Was this meant to be a v2 patch??? Yikes!

Based on the feedback from Segei, Dave and Jesse. Dropping this patch from my queue and will wait for a properly formatted v2 of this patch.

Please CC me on any future patches against any changes to drivers/net/ethernet/intel/*

#8 lore raw
In reply to Martin K. Petersen

On 11/14/2014 11:16 AM, Martin K. Petersen wrote:

[snip]

Quoted 7 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +7 -0
+#ifdef CONFIG_OF
+/**
+ * ixgbe_of_mac_addr - Look up MAC address in Open Firmware
+ * @adapter: Pointer to adapter struct
+ */
+static void ixgbe_of_mac_addr(struct ixgbe_adapter *adapter)
+{

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, · line 7983

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +10 -0
+	struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
+	struct ixgbe_hw *hw = &adapter->hw;
+	const unsigned char *addr;
+	int len;
+
+	addr = of_get_property(dp, "local-mac-address", &len);
+	if (addr && len == 6) {
+		e_dev_info("Using OpenPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, addr, 6);
+	}

Cannot you use of_get_mac_address() here which does iterate through all the OF standard ways to specify a MAC address: mac-address, local-mac-address and address? Benefit is that this will work for all DT-enabled platforms.

Quoted 27 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +12 -1
+
+	if (!is_valid_ether_addr(hw->mac.perm_addr)) {
+		e_dev_info("Using IDPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, idprom->id_ethaddr, 6);
+	}
+}
+#endif
+
 /**
  * ixgbe_probe - Device Initialization Routine
  * @pdev: PCI device information struct
@@ -8223,6 +8253,10 @@ skip_sriov:
 		goto err_sw_init;
 	}
 
+#ifdef CONFIG_OF
+	ixgbe_of_mac_addr(adapter);
+#endif
+
 	memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
 
 	if (!is_valid_ether_addr(netdev->dev_addr)) {
--

To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to Martin K. Petersen
Quoted 14 lines · Martin K. Petersen

/**
+ * ixgbe_of_mac_addr - Look up MAC address in Open Firmware
+ * @adapter: Pointer to adapter struct
+ */

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +10 -0
+static void ixgbe_of_mac_addr(struct ixgbe_adapter *adapter)
+{
+#ifdef CONFIG_OF
+	struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
+	struct ixgbe_hw *hw = &adapter->hw;
+	const unsigned char *addr;
+	int len;
+
+	addr = of_get_property(dp, "local-mac-address", &len);
+	if (addr && len == 6) {

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, · line 7990

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +10 -0
+		e_dev_info("Using OpenPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, addr, 6);
+	}
+
+	if (!is_valid_ether_addr(hw->mac.perm_addr)) {
+		e_dev_info("Using IDPROM MAC address\n");
+		memcpy(hw->mac.perm_addr, idprom->id_ethaddr, 6);
+	}
+#endif
+}

I would prefer that the entire function be wrapped by the #if so that a null implementation can include the prototype. That allows the unused parameter to properly be declared as __always_unused as in:

#else
static void ixgbe_of_mac_addr(struct ixgbe_adapter __always_unused *adapter) {}
#endif /* CONFIG_OF */

Otherwise, it will throw warnings when compiled with enhanced warning messages.

Signature · 1 line
Mark Rustad, Networking Division, Intel Corporation