Skip to contentSkip to conversation

NET ethernet introduce eth-mac-platform helper

PATCH New Andy Green 1 participant 2 messages Jul 6, 2012

Subsystems (5)
lore
Share & tools
lore

Andy Green

author
#0 lore raw

PATCH 1/2 NET ethernet introduce eth-mac-platform helper

From: Andy Green <[email protected]>

This introduces a small helper in net/ethernet, which registers a network notifier at core_initcall time, and accepts registrations mapping expected asynchronously-probed network device paths (like, "usb1/1-1/1-1.1/1-1.1:1.0") and the MAC that is needed to be assigned to the device when it appears.

This allows platform code to enforce valid, consistent MAC addresses on to devices that have not been probed at boot-time, but due to being wired on the board are always present at the same interface. It has been tested with USB and SDIO probed devices.

Other parts of this series provide an OMAP API that computes a valid locally administered MAC address from CPU ID bits that are unique for each physical SoC, and register those against devices wired to the board.

This solves a longstanding problem in at least Panda case that there are no reserved MACs for either onboard Ethernet nor onboard WLAN module, and without this patch a randomized MAC is assigned to Ethernet and 00:00:00:00:00:00 or 0xdeadbeef is assigned as the WLAN MAC address. The series provides sane, constant locally-administered MAC addresses that have a high probability of differing between boards.

To make use of this safely you also need to make sure that any drivers that may compete for the bus ordinal you are using (eg, mUSB and ehci in Panda case) are loaded in a deterministic order.

At registration it makes a copy of the incoming data, so the data may be __initdata or otherwise transitory. Registration can be called multiple times so registrations from Device Tree and platform may be mixed.

Since it needs to be called quite early in boot and there is no lifecycle for what it does, it could not be modular and is not a driver.

Via suggestions from Arnd Bergmann and Tony Lindgren (and Alan Cox for the network notifier concept).

Cc netdev at vger.kernel.org
Cc linux-kernel at vger.kernel.org
---
 include/net/eth-mac-platform.h  |   40 ++++++++++
 net/Kconfig                     |    5 +
 net/ethernet/Makefile           |    3 +
 net/ethernet/eth-mac-platform.c |  150 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 197 insertions(+), 1 deletion(-)
 create mode 100644 include/net/eth-mac-platform.h
 create mode 100644 net/ethernet/eth-mac-platform.c
include/net/eth-mac-platform.h new file +40 -0
new file mode 100644
index 0000000..752f1de
@@ -0,0 +1,40 @@
+/*
+ * eth-mac-platform.h:  Enforces platform-defined MAC for Async probed devices
+ */
+
+#ifndef __ETH_NET_MAC_PLATFORM_H__
+#define __ETH_NET_MAC_PLATFORM_H__
+
+#include <linux/if_ether.h>
+
+/**
+ * struct eth_mac_platform - associates asynchronously probed device path with
+ *			     MAC address to be assigned to the device when it
+ *			     is created
+ *
+ * @device_path: device path name of network device
+ * @mac: MAC address to assign to network device matching device path
+ * @list: can be left uninitialized when passing from platform
+ */
+
+struct eth_mac_platform {
+	char *device_path;
+	u8 mac[ETH_ALEN];
+	struct list_head list; /* unused in platform data usage */
+};
+
+#ifdef CONFIG_NET
+/**
+ * eth_mac_platform_register_device_macs - add an array of device path to
+ *                                  monitor and MAC to apply when the network
+ *                                  device at the device path appears
+ * @macs: array of struct eth_mac_platform terminated by entry with
+ *	  NULL device_path
+ */
+int eth_mac_platform_register_device_macs(const struct eth_mac_platform *macs);
+#else
+static inline int eth_mac_platform_register_device_macs(
+			     const struct eth_mac_platform *macs) { return 0; }
+#endif /* !CONFIG_NET */
+
+#endif /* __ETH_NET_MAC_PLATFORM_H__ */
net/Kconfig +4 -1
index 245831b..dd8ab96 100644
@@ -335,9 +335,12 @@ source "net/caif/Kconfig"
 source "net/ceph/Kconfig"
 source "net/nfc/Kconfig"
 
-
 endif   # if NET
 
+# used by board / dt platform to enforce Ethernet MACs for Async-probed devices
+config ETH_MAC_PLATFORM
+	bool
+
 # Used by archs to tell that they support BPF_JIT
 config HAVE_BPF_JIT
 	bool
net/ethernet/Makefile +3 -0
index 7cef1d8..7362f46 100644
@@ -5,3 +5,6 @@
 obj-y					+= eth.o
 obj-$(subst m,y,$(CONFIG_IPX))		+= pe2.o
 obj-$(subst m,y,$(CONFIG_ATALK))	+= pe2.o
+ifneq ($(CONFIG_NET),)
+obj-$(CONFIG_ETH_MAC_PLATFORM)		+= eth-mac-platform.o
+endif
net/ethernet/eth-mac-platform.c new file +150 -0

150 lines not on this page · raw message

author
#1 lore raw

PATCH 2/2 OMAP4 PANDA register ethernet and wlan for automatic mac allocation

From: Andy Green <[email protected]>

This provides the board-specific device paths needed to get the panda boardfile working with the eth-mac-platform api.

On Pandaboard / ES, neither the onboard Ethernet or onboard WLAN module have onboard arrangements for MAC storage, without this series yielding randomized MAC per-boot and consequent DHCP problems, or in the case of wlan0 a MAC set by a firmware file in the rootfs which unless customized yields a MAC of 00:00:00:00:00:00. No official MAC is reserved for either network device even if you do take the approach to customize the firmware file.

This gets sane, consistent MAC addresses on both devices which should stand a good probability of differing between PandaBoards.

---
 arch/arm/mach-omap2/Kconfig            |    1 +
 arch/arm/mach-omap2/board-omap4panda.c |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
arch/arm/mach-omap2/Kconfig +1 -0
index 83fb31c..61c6a3d 100644
@@ -358,6 +358,7 @@ config MACH_OMAP4_PANDA
 	select OMAP_PACKAGE_CBL
 	select OMAP_PACKAGE_CBS
 	select REGULATOR_FIXED_VOLTAGE if REGULATOR
+	select ETH_MAC_PLATFORM
 
 config MACH_PCM049
 	bool "OMAP4 based phyCORE OMAP4"
arch/arm/mach-omap2/board-omap4panda.c +30 -0
index 982fb26..75d93cc 100644
@@ -32,7 +32,10 @@
 #include <linux/wl12xx.h>
 #include <linux/platform_data/omap-abe-twl6040.h>
 
+#include <net/eth-mac-platform.h>
+
 #include <mach/hardware.h>
+#include <mach/id.h>
 #include <asm/hardware/gic.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -486,16 +489,43 @@ static void omap4_panda_init_rev(void)
 	}
 }
 
+/*
+ * These device paths represent onboard network devices which have
+ * no MAC address set at boot, and need synthetic ones assigning
+ */
+static __initdata struct eth_mac_platform panda_eth_mac_platform[] = {
+
+	{ /* smsc USB <-> Ethernet bridge */
+		.device_path = "usb1/1-1/1-1.1/1-1.1:1.0",
+	},
+	{ /* wlan0 module */
+		.device_path = "wl12xx",
+	},
+	{ /* terminator */
+	}
+};
+
 static void __init omap4_panda_init(void)
 {
 	int package = OMAP_PACKAGE_CBS;
 	int ret;
+	int n;
 
 	if (omap_rev() == OMAP4430_REV_ES1_0)
 		package = OMAP_PACKAGE_CBL;
 	omap4_mux_init(board_mux, NULL, package);
 
 	omap_panda_wlan_data.irq = gpio_to_irq(GPIO_WIFI_IRQ);
+
+	/*
+	 * provide MAC addresses computed from device ID for network
+	 * devices that have no MAC address otherwise on Panda
+	 */
+	for (n = 0; n < ARRAY_SIZE(panda_eth_mac_platform) - 1; n++)
+		omap_die_id_to_ethernet_mac(panda_eth_mac_platform[n].mac, n);
+	if (eth_mac_platform_register_device_macs(panda_eth_mac_platform))
+		pr_err("Unable to register eth_mac_platform devices\n");
+
 	ret = wl12xx_set_platform_data(&omap_panda_wlan_data);
 	if (ret)
 		pr_err("error setting wl12xx data: %d\n", ret);