All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address
@ 2012-10-23 17:15 Paolo Pisati
  2012-10-23 17:15 ` [PATCH 1/6] macaddr kernel bootargs implementation Paolo Pisati
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Paolo Pisati @ 2012-10-23 17:15 UTC (permalink / raw)
  To: netdev; +Cc: Giuseppe Cavallaro, Kristoffer Glembo

In the past drivers grew mechanism to set their own mac address at boot time
via (usually) a module parameter. Unfortunately every single driver had its
own naming/implementation and it soon became clear that a generic
mechanism was needed.

Introduce "macaddr=", a new kernel parameter to set MAC address using
netdevice ops (and hence being hardware independent).

After 0001 is committed, we can garbage collect some custom driver code
that does the same functionality (0002-0006).

I couldn't find the maintainers of ksz884x, sunhme and fec, so pleace cc:
them if you know who they are.

Paolo Pisati (6):
  macaddr kernel bootargs implementation
  stmmac: remove mac address handling as a module parameter
  ksz884x: remove mac address handling as a module parameter
  greth: remove mac address handling as a module parameter
  sunhme: remove mac address handling as a module parameter
  fec: remove mac address handling as a module parameter

 Documentation/kernel-parameters.txt               |    4 +
 drivers/net/ethernet/aeroflex/greth.c             |   36 +++-----
 drivers/net/ethernet/freescale/fec.c              |   27 ++----
 drivers/net/ethernet/micrel/ksz884x.c             |   57 ------------
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |   13 ---
 drivers/net/ethernet/sun/sunhme.c                 |   69 ++++----------
 net/core/dev.c                                    |  101 +++++++++++++++++++++
 7 files changed, 140 insertions(+), 167 deletions(-)

-- 
1.7.9.5

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

* [PATCH 1/6] macaddr kernel bootargs implementation
  2012-10-23 17:15 [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address Paolo Pisati
@ 2012-10-23 17:15 ` Paolo Pisati
  2012-10-23 17:15 ` [PATCH 2/6] stmmac: remove mac address handling as a module parameter Paolo Pisati
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo Pisati @ 2012-10-23 17:15 UTC (permalink / raw)
  To: netdev; +Cc: Giuseppe Cavallaro, Kristoffer Glembo

Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
---
 Documentation/kernel-parameters.txt |    4 ++
 net/core/dev.c                      |  101 +++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 57dfe00..098beb6 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1382,6 +1382,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 	ltpc=		[NET]
 			Format: <io>,<irq>,<dma>
 
+	macaddr=	[HW,NET]
+			Set NIC MAC address to given value.
+			Example: macaddr=eth0,00:11:22:33:44:55
+
 	machvec=	[IA-64] Force the use of a particular machine-vector
 			(machvec) in a generic kernel.
 			Example: machvec=hpzx1_swiotlb
diff --git a/net/core/dev.c b/net/core/dev.c
index abe1147..5b3e125 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -598,6 +598,107 @@ int __init netdev_boot_setup(char *str)
 
 __setup("netdev=", netdev_boot_setup);
 
+struct macaddr_data {
+	char ifname[IFNAMSIZ + 1];
+	struct sockaddr so;
+	struct list_head list;
+};
+
+static LIST_HEAD(macaddr_list);
+
+static int macaddr_device_event(struct notifier_block *unused,
+			     unsigned long event, void *ptr)
+{
+	struct net_device *dev = ptr;
+	struct macaddr_data *ma;
+
+	if (event == NETDEV_REGISTER) {
+		list_for_each_entry(ma, &macaddr_list, list) {
+			if (strcmp(dev->name, ma->ifname) == 0) {
+				dev_set_mac_address(dev, &ma->so);
+				break;
+			}
+		}
+	}
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block macaddr_notifier = {
+	.notifier_call = macaddr_device_event,
+};
+
+static int parse_macaddr(const char *macstr, struct sockaddr *so)
+{
+	int i, h, l;
+
+	for (i = 0; i < 6; i++) {
+		h = hex_to_bin(*macstr);
+		if (h == -1)
+			goto err;
+		macstr++;
+
+		l = hex_to_bin(*macstr);
+		if (l == -1)
+			goto err;
+		macstr++;
+
+		if (i != 5) {
+			if (*macstr != ':')
+				goto err;
+			macstr++;
+		}
+		so->sa_data[i] = (h << 4) + l;
+	}
+	if (is_valid_ether_addr(so->sa_data))
+		return 0;
+err:
+	return -EINVAL;
+}
+
+static int __init if_macaddr(void)
+{
+	char cmdline[] = "macaddr=", *str;
+	int err = -EINVAL, i;
+	struct macaddr_data *ma, *tmp;
+
+	str = boot_command_line;
+	while ((str = strstr(str, cmdline)) != NULL) {
+		ma = kmalloc(sizeof(struct macaddr_data), GFP_KERNEL);
+		if (ma == NULL) {
+			err = -ENOMEM;
+			goto out;
+		}
+
+		/*
+		 * Parse input string, expected format: ethX,00:11:22:33:44:55
+		 */
+		str += sizeof(cmdline) - 1;
+		for (i = 0; i <= IFNAMSIZ; i++, str++) {
+			if (*str == ' ' || *str == '\0')
+				goto out;
+			if (*str == ',')
+				break;
+			ma->ifname[i] = *str;
+		}
+		ma->ifname[++i] = '\0';
+		ma->so.sa_family = ARPHRD_ETHER;
+		if (parse_macaddr(++str, &ma->so))
+			goto out;
+
+		list_add_tail(&ma->list, &macaddr_list);
+	}
+
+	if (!list_empty(&macaddr_list))
+		register_netdevice_notifier(&macaddr_notifier);
+	return 0;
+out:
+	kfree(ma);
+	list_for_each_entry_safe(ma, tmp, &macaddr_list, list)
+		kfree(ma);
+	return err;
+}
+late_initcall(if_macaddr);
+
 /*******************************************************************************
 
 			    Device Interface Subroutines
-- 
1.7.9.5

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

* [PATCH 2/6] stmmac: remove mac address handling as a module parameter
  2012-10-23 17:15 [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address Paolo Pisati
  2012-10-23 17:15 ` [PATCH 1/6] macaddr kernel bootargs implementation Paolo Pisati
@ 2012-10-23 17:15 ` Paolo Pisati
  2012-10-23 17:15 ` [PATCH 3/6] ksz884x: " Paolo Pisati
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo Pisati @ 2012-10-23 17:15 UTC (permalink / raw)
  To: netdev; +Cc: Giuseppe Cavallaro, Kristoffer Glembo

Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |   13 -------------
 1 file changed, 13 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index d4d2bc1..cd8bda7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -93,10 +93,6 @@ static int debug = -1;		/* -1: default, 0: no output, 16:  all */
 module_param(debug, int, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)");
 
-static int phyaddr = -1;
-module_param(phyaddr, int, S_IRUGO);
-MODULE_PARM_DESC(phyaddr, "Physical device address");
-
 #define DMA_TX_SIZE 256
 static int dma_txsize = DMA_TX_SIZE;
 module_param(dma_txsize, int, S_IRUGO | S_IWUSR);
@@ -1925,11 +1921,6 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto out_plat_exit;
 
-	/* Override with kernel parameters if supplied XXX CRS XXX
-	 * this needs to have multiple instances */
-	if ((phyaddr >= 0) && (phyaddr <= 31))
-		priv->plat->phy_addr = phyaddr;
-
 	pr_info("\t%s - (dev. name: %s - id: %d, IRQ #%d\n"
 	       "\tIO base addr: 0x%p)\n", ndev->name, pdev->name,
 	       pdev->id, ndev->irq, addr);
@@ -2165,10 +2156,6 @@ static int __init stmmac_cmdline_opt(char *str)
 		if (!strncmp(opt, "debug:", 6)) {
 			if (strict_strtoul(opt + 6, 0, (unsigned long *)&debug))
 				goto err;
-		} else if (!strncmp(opt, "phyaddr:", 8)) {
-			if (strict_strtoul(opt + 8, 0,
-					   (unsigned long *)&phyaddr))
-				goto err;
 		} else if (!strncmp(opt, "dma_txsize:", 11)) {
 			if (strict_strtoul(opt + 11, 0,
 					   (unsigned long *)&dma_txsize))
-- 
1.7.9.5

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

* [PATCH 3/6] ksz884x: remove mac address handling as a module parameter
  2012-10-23 17:15 [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address Paolo Pisati
  2012-10-23 17:15 ` [PATCH 1/6] macaddr kernel bootargs implementation Paolo Pisati
  2012-10-23 17:15 ` [PATCH 2/6] stmmac: remove mac address handling as a module parameter Paolo Pisati
@ 2012-10-23 17:15 ` Paolo Pisati
  2012-10-23 17:15 ` [PATCH 4/6] greth: " Paolo Pisati
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo Pisati @ 2012-10-23 17:15 UTC (permalink / raw)
  To: netdev; +Cc: Giuseppe Cavallaro, Kristoffer Glembo

Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
---
 drivers/net/ethernet/micrel/ksz884x.c |   57 ---------------------------------
 1 file changed, 57 deletions(-)

diff --git a/drivers/net/ethernet/micrel/ksz884x.c b/drivers/net/ethernet/micrel/ksz884x.c
index 4b9f4bd..c70a1fc 100644
--- a/drivers/net/ethernet/micrel/ksz884x.c
+++ b/drivers/net/ethernet/micrel/ksz884x.c
@@ -6739,9 +6739,6 @@ static void dev_monitor(unsigned long ptr)
 
 static int msg_enable;
 
-static char *macaddr = ":";
-static char *mac1addr = ":";
-
 /*
  * This enables multiple network device mode for KSZ8842, which contains a
  * switch with two physical ports.  Some users like to take control of the
@@ -6852,51 +6849,6 @@ struct platform_info {
 
 static int net_device_present;
 
-static void get_mac_addr(struct dev_info *hw_priv, u8 *macaddr, int port)
-{
-	int i;
-	int j;
-	int got_num;
-	int num;
-
-	i = j = num = got_num = 0;
-	while (j < MAC_ADDR_LEN) {
-		if (macaddr[i]) {
-			int digit;
-
-			got_num = 1;
-			digit = hex_to_bin(macaddr[i]);
-			if (digit >= 0)
-				num = num * 16 + digit;
-			else if (':' == macaddr[i])
-				got_num = 2;
-			else
-				break;
-		} else if (got_num)
-			got_num = 2;
-		else
-			break;
-		if (2 == got_num) {
-			if (MAIN_PORT == port) {
-				hw_priv->hw.override_addr[j++] = (u8) num;
-				hw_priv->hw.override_addr[5] +=
-					hw_priv->hw.id;
-			} else {
-				hw_priv->hw.ksz_switch->other_addr[j++] =
-					(u8) num;
-				hw_priv->hw.ksz_switch->other_addr[5] +=
-					hw_priv->hw.id;
-			}
-			num = got_num = 0;
-		}
-		i++;
-	}
-	if (MAC_ADDR_LEN == j) {
-		if (MAIN_PORT == port)
-			hw_priv->hw.mac_override = 1;
-	}
-}
-
 #define KS884X_DMA_MASK			(~0x0UL)
 
 static void read_other_addr(struct ksz_hw *hw)
@@ -7050,9 +7002,6 @@ static int __devinit pcidev_init(struct pci_dev *pdev,
 	for (i = 0; i < TOTAL_PORT_NUM; i++)
 		init_waitqueue_head(&hw_priv->counter[i].counter);
 
-	if (macaddr[0] != ':')
-		get_mac_addr(hw_priv, macaddr, MAIN_PORT);
-
 	/* Read MAC address and initialize override address if not overrided. */
 	hw_read_addr(hw);
 
@@ -7060,8 +7009,6 @@ static int __devinit pcidev_init(struct pci_dev *pdev,
 	if (hw->dev_count > 1) {
 		memcpy(sw->other_addr, hw->override_addr, MAC_ADDR_LEN);
 		read_other_addr(hw);
-		if (mac1addr[0] != ':')
-			get_mac_addr(hw_priv, mac1addr, OTHER_PORT);
 	}
 
 	hw_setup(hw);
@@ -7276,13 +7223,9 @@ MODULE_LICENSE("GPL");
 module_param_named(message, msg_enable, int, 0);
 MODULE_PARM_DESC(message, "Message verbosity level (0=none, 31=all)");
 
-module_param(macaddr, charp, 0);
-module_param(mac1addr, charp, 0);
 module_param(fast_aging, int, 0);
 module_param(multi_dev, int, 0);
 module_param(stp, int, 0);
-MODULE_PARM_DESC(macaddr, "MAC address");
-MODULE_PARM_DESC(mac1addr, "Second MAC address");
 MODULE_PARM_DESC(fast_aging, "Fast aging");
 MODULE_PARM_DESC(multi_dev, "Multiple device interfaces");
 MODULE_PARM_DESC(stp, "STP support");
-- 
1.7.9.5

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

* [PATCH 4/6] greth: remove mac address handling as a module parameter
  2012-10-23 17:15 [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address Paolo Pisati
                   ` (2 preceding siblings ...)
  2012-10-23 17:15 ` [PATCH 3/6] ksz884x: " Paolo Pisati
@ 2012-10-23 17:15 ` Paolo Pisati
  2012-10-23 17:15 ` [PATCH 5/6] sunhme: " Paolo Pisati
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo Pisati @ 2012-10-23 17:15 UTC (permalink / raw)
  To: netdev; +Cc: Giuseppe Cavallaro, Kristoffer Glembo

Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
---
 drivers/net/ethernet/aeroflex/greth.c |   36 +++++++++++----------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/aeroflex/greth.c b/drivers/net/ethernet/aeroflex/greth.c
index 442fefa..c6c85d6 100644
--- a/drivers/net/ethernet/aeroflex/greth.c
+++ b/drivers/net/ethernet/aeroflex/greth.c
@@ -59,11 +59,6 @@ static int greth_debug = -1;	/* -1 == use GRETH_DEF_MSG_ENABLE as value */
 module_param(greth_debug, int, 0);
 MODULE_PARM_DESC(greth_debug, "GRETH bitmapped debugging message enable value");
 
-/* Accept MAC address of the form macaddr=0x08,0x00,0x20,0x30,0x40,0x50 */
-static int macaddr[6];
-module_param_array(macaddr, int, NULL, 0);
-MODULE_PARM_DESC(macaddr, "GRETH Ethernet MAC address");
-
 static int greth_edcl = 1;
 module_param(greth_edcl, int, 0);
 MODULE_PARM_DESC(greth_edcl, "GRETH EDCL usage indicator. Set to 1 if EDCL is used.");
@@ -1385,8 +1380,11 @@ static int __devinit greth_of_probe(struct platform_device *ofdev)
 
 	int i;
 	int err;
+	int len;
 	int tmp;
 	unsigned long timeout;
+	const unsigned char *addr;
+	int macaddr[6]; /* XXX an initial mac? e.g. 00:11:22:33:44:55? */
 
 	dev = alloc_etherdev(sizeof(struct greth_private));
 
@@ -1495,32 +1493,22 @@ static int __devinit greth_of_probe(struct platform_device *ofdev)
 
 	memset(greth->rx_bd_base, 0, 1024);
 
-	/* Get MAC address from: module param, OF property or ID prom */
-	for (i = 0; i < 6; i++) {
-		if (macaddr[i] != 0)
-			break;
-	}
-	if (i == 6) {
-		const unsigned char *addr;
-		int len;
-		addr = of_get_property(ofdev->dev.of_node, "local-mac-address",
-					&len);
-		if (addr != NULL && len == 6) {
-			for (i = 0; i < 6; i++)
-				macaddr[i] = (unsigned int) addr[i];
-		} else {
+	/* Get MAC address from: OF property or ID prom */
+	addr = of_get_property(ofdev->dev.of_node, "local-mac-address",
+				&len);
+	if (addr != NULL && len == 6) {
+		for (i = 0; i < 6; i++)
+			macaddr[i] = (unsigned int) addr[i];
+	} else {
 #ifdef CONFIG_SPARC
-			for (i = 0; i < 6; i++)
-				macaddr[i] = (unsigned int) idprom->id_ethaddr[i];
+		for (i = 0; i < 6; i++)
+			macaddr[i] = (unsigned int) idprom->id_ethaddr[i];
 #endif
-		}
 	}
 
 	for (i = 0; i < 6; i++)
 		dev->dev_addr[i] = macaddr[i];
 
-	macaddr[5]++;
-
 	if (!is_valid_ether_addr(&dev->dev_addr[0])) {
 		if (netif_msg_probe(greth))
 			dev_err(greth->dev, "no valid ethernet address, aborting.\n");
-- 
1.7.9.5

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

* [PATCH 5/6] sunhme: remove mac address handling as a module parameter
  2012-10-23 17:15 [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address Paolo Pisati
                   ` (3 preceding siblings ...)
  2012-10-23 17:15 ` [PATCH 4/6] greth: " Paolo Pisati
@ 2012-10-23 17:15 ` Paolo Pisati
  2012-10-23 17:15 ` [PATCH 6/6] fec: " Paolo Pisati
  2012-10-23 17:20 ` [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address David Miller
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo Pisati @ 2012-10-23 17:15 UTC (permalink / raw)
  To: netdev; +Cc: Giuseppe Cavallaro, Kristoffer Glembo

Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
---
 drivers/net/ethernet/sun/sunhme.c |   69 +++++++++----------------------------
 1 file changed, 16 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
index cf14ab9..b5e70d5 100644
--- a/drivers/net/ethernet/sun/sunhme.c
+++ b/drivers/net/ethernet/sun/sunhme.c
@@ -9,8 +9,6 @@
  * 2000/11/11 Willy Tarreau <willy AT meta-x.org>
  *   - port to non-sparc architectures. Tested only on x86 and
  *     only currently works with QFE PCI cards.
- *   - ability to specify the MAC address at module load time by passing this
- *     argument : macaddr=0x00,0x10,0x20,0x30,0x40,0x50
  */
 
 #include <linux/module.h>
@@ -74,12 +72,6 @@ MODULE_AUTHOR(DRV_AUTHOR);
 MODULE_DESCRIPTION("Sun HappyMealEthernet(HME) 10/100baseT ethernet driver");
 MODULE_LICENSE("GPL");
 
-static int macaddr[6];
-
-/* accept MAC address of the form macaddr=0x08,0x00,0x20,0x30,0x40,0x50 */
-module_param_array(macaddr, int, NULL, 0);
-MODULE_PARM_DESC(macaddr, "Happy Meal MAC address to set");
-
 #ifdef CONFIG_SBUS
 static struct quattro *qfe_sbus_list;
 #endif
@@ -2631,8 +2623,9 @@ static int __devinit happy_meal_sbus_probe_one(struct platform_device *op, int i
 	struct quattro *qp = NULL;
 	struct happy_meal *hp;
 	struct net_device *dev;
-	int i, qfe_slot = -1;
+	int i, len, qfe_slot = -1;
 	int err = -ENODEV;
+	const unsigned char *addr;
 
 	sbus_dp = op->dev.parent->of_node;
 
@@ -2660,28 +2653,12 @@ static int __devinit happy_meal_sbus_probe_one(struct platform_device *op, int i
 	if (hme_version_printed++ == 0)
 		printk(KERN_INFO "%s", version);
 
-	/* If user did not specify a MAC address specifically, use
-	 * the Quattro local-mac-address property...
-	 */
-	for (i = 0; i < 6; i++) {
-		if (macaddr[i] != 0)
-			break;
-	}
-	if (i < 6) { /* a mac address was given */
-		for (i = 0; i < 6; i++)
-			dev->dev_addr[i] = macaddr[i];
-		macaddr[5]++;
-	} else {
-		const unsigned char *addr;
-		int len;
-
-		addr = of_get_property(dp, "local-mac-address", &len);
 
-		if (qfe_slot != -1 && addr && len == 6)
-			memcpy(dev->dev_addr, addr, 6);
-		else
-			memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
-	}
+	addr = of_get_property(dp, "local-mac-address", &len);
+	if (qfe_slot != -1 && addr && len == 6)
+		memcpy(dev->dev_addr, addr, 6);
+	else
+		memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
 
 	hp = netdev_priv(dev);
 
@@ -2945,9 +2922,10 @@ static int __devinit happy_meal_pci_probe(struct pci_dev *pdev,
 	struct net_device *dev;
 	void __iomem *hpreg_base;
 	unsigned long hpreg_res;
-	int i, qfe_slot = -1;
+	int i, len, qfe_slot = -1;
 	char prom_name[64];
 	int err;
+	const unsigned char *addr;
 
 	/* Now make sure pci_dev cookie is there. */
 #ifdef CONFIG_SPARC
@@ -3018,31 +2996,16 @@ static int __devinit happy_meal_pci_probe(struct pci_dev *pdev,
 		goto err_out_free_res;
 	}
 
-	for (i = 0; i < 6; i++) {
-		if (macaddr[i] != 0)
-			break;
-	}
-	if (i < 6) { /* a mac address was given */
-		for (i = 0; i < 6; i++)
-			dev->dev_addr[i] = macaddr[i];
-		macaddr[5]++;
-	} else {
 #ifdef CONFIG_SPARC
-		const unsigned char *addr;
-		int len;
-
-		if (qfe_slot != -1 &&
-		    (addr = of_get_property(dp, "local-mac-address", &len))
-			!= NULL &&
-		    len == 6) {
-			memcpy(dev->dev_addr, addr, 6);
-		} else {
-			memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
-		}
+	if (qfe_slot != -1 &&
+	    (addr = of_get_property(dp, "local-mac-address", &len)) != NULL &&
+	    len == 6)
+		memcpy(dev->dev_addr, addr, 6);
+	else
+		memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
 #else
-		get_hme_mac_nonsparc(pdev, &dev->dev_addr[0]);
+	get_hme_mac_nonsparc(pdev, &dev->dev_addr[0]);
 #endif
-	}
 
 	/* Layout registers. */
 	hp->gregs      = (hpreg_base + 0x0000UL);
-- 
1.7.9.5

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

* [PATCH 6/6] fec: remove mac address handling as a module parameter
  2012-10-23 17:15 [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address Paolo Pisati
                   ` (4 preceding siblings ...)
  2012-10-23 17:15 ` [PATCH 5/6] sunhme: " Paolo Pisati
@ 2012-10-23 17:15 ` Paolo Pisati
  2012-10-23 17:20 ` [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address David Miller
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo Pisati @ 2012-10-23 17:15 UTC (permalink / raw)
  To: netdev; +Cc: Giuseppe Cavallaro, Kristoffer Glembo

Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
---
 drivers/net/ethernet/freescale/fec.c |   27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.c b/drivers/net/ethernet/freescale/fec.c
index c136230..d5bb97d 100644
--- a/drivers/net/ethernet/freescale/fec.c
+++ b/drivers/net/ethernet/freescale/fec.c
@@ -114,10 +114,6 @@ static const struct of_device_id fec_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, fec_dt_ids);
 
-static unsigned char macaddr[ETH_ALEN];
-module_param_array(macaddr, byte, NULL, 0);
-MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
-
 #if defined(CONFIG_M5272)
 /*
  * Some hardware gets it MAC address out of local flash memory.
@@ -786,21 +782,16 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
 {
 	struct fec_enet_private *fep = netdev_priv(ndev);
 	struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
-	unsigned char *iap, tmpaddr[ETH_ALEN];
+	unsigned char *iap = NULL, tmpaddr[ETH_ALEN];
 
 	/*
 	 * try to get mac address in following order:
-	 *
-	 * 1) module parameter via kernel command line in form
-	 *    fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0
 	 */
-	iap = macaddr;
-
 #ifdef CONFIG_OF
 	/*
-	 * 2) from device tree data
+	 * 1) from device tree data
 	 */
-	if (!is_valid_ether_addr(iap)) {
+	{
 		struct device_node *np = fep->pdev->dev.of_node;
 		if (np) {
 			const char *mac = of_get_mac_address(np);
@@ -811,9 +802,9 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
 #endif
 
 	/*
-	 * 3) from flash or fuse (via platform data)
+	 * 2) from flash or fuse (via platform data)
 	 */
-	if (!is_valid_ether_addr(iap)) {
+	if (iap == NULL || !is_valid_ether_addr(iap)) {
 #ifdef CONFIG_M5272
 		if (FEC_FLASHMAC)
 			iap = (unsigned char *)FEC_FLASHMAC;
@@ -824,9 +815,9 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
 	}
 
 	/*
-	 * 4) FEC mac registers set by bootloader
+	 * 3) FEC mac registers set by bootloader
 	 */
-	if (!is_valid_ether_addr(iap)) {
+	if (iap == NULL || !is_valid_ether_addr(iap)) {
 		*((unsigned long *) &tmpaddr[0]) =
 			be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
 		*((unsigned short *) &tmpaddr[4]) =
@@ -835,10 +826,6 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
 	}
 
 	memcpy(ndev->dev_addr, iap, ETH_ALEN);
-
-	/* Adjust MAC if using macaddr */
-	if (iap == macaddr)
-		 ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->dev_id;
 }
 
 /* ------------------------------------------------------------------------- */
-- 
1.7.9.5

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

* Re: [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address
  2012-10-23 17:15 [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address Paolo Pisati
                   ` (5 preceding siblings ...)
  2012-10-23 17:15 ` [PATCH 6/6] fec: " Paolo Pisati
@ 2012-10-23 17:20 ` David Miller
  2012-10-24  8:07   ` Paolo Pisati
  6 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2012-10-23 17:20 UTC (permalink / raw)
  To: p.pisati; +Cc: netdev, peppe.cavallaro, kristoffer

From: Paolo Pisati <p.pisati@gmail.com>
Date: Tue, 23 Oct 2012 19:15:27 +0200

> In the past drivers grew mechanism to set their own mac address at boot time
> via (usually) a module parameter. Unfortunately every single driver had its
> own naming/implementation and it soon became clear that a generic
> mechanism was needed.
> 
> Introduce "macaddr=", a new kernel parameter to set MAC address using
> netdevice ops (and hence being hardware independent).

Sorry, no, no module parameters.

Run time setting is the only reasonable way to set the MAC address
explicitly.

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

* Re: [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address
  2012-10-23 17:20 ` [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address David Miller
@ 2012-10-24  8:07   ` Paolo Pisati
  0 siblings, 0 replies; 9+ messages in thread
From: Paolo Pisati @ 2012-10-24  8:07 UTC (permalink / raw)
  To: David Miller; +Cc: p.pisati, netdev, peppe.cavallaro, kristoffer

On Tue, Oct 23, 2012 at 01:20:37PM -0400, David Miller wrote:
> From: Paolo Pisati <p.pisati@gmail.com>
> Date: Tue, 23 Oct 2012 19:15:27 +0200
> 
> > In the past drivers grew mechanism to set their own mac address at boot time
> > via (usually) a module parameter. Unfortunately every single driver had its
> > own naming/implementation and it soon became clear that a generic
> > mechanism was needed.
> > 
> > Introduce "macaddr=", a new kernel parameter to set MAC address using
> > netdevice ops (and hence being hardware independent).
> 
> Sorry, no, no module parameters.
> 
> Run time setting is the only reasonable way to set the MAC address
> explicitly.

actually it's a not a module parameter.

and what if you want to change your nic MAC at boot time? e.g. netboot
setup with different configs per different MACs.
-- 
bye,
p.

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

end of thread, other threads:[~2012-10-24  8:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-23 17:15 [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address Paolo Pisati
2012-10-23 17:15 ` [PATCH 1/6] macaddr kernel bootargs implementation Paolo Pisati
2012-10-23 17:15 ` [PATCH 2/6] stmmac: remove mac address handling as a module parameter Paolo Pisati
2012-10-23 17:15 ` [PATCH 3/6] ksz884x: " Paolo Pisati
2012-10-23 17:15 ` [PATCH 4/6] greth: " Paolo Pisati
2012-10-23 17:15 ` [PATCH 5/6] sunhme: " Paolo Pisati
2012-10-23 17:15 ` [PATCH 6/6] fec: " Paolo Pisati
2012-10-23 17:20 ` [PATCH 0/6] kernel parameters: introduce "macaddr" to set mac address David Miller
2012-10-24  8:07   ` Paolo Pisati

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.