kernel parameters: introduce "macaddr" to set mac address
Subsystems (7)
cover kernel parameters: introduce "macaddr" to set mac address
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(-)
Signature · 1 line
1.7.9.5
PATCH 1/6 macaddr kernel bootargs implementation
--- Documentation/kernel-parameters.txt | 4 ++ net/core/dev.c | 101 +++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+)
Documentation/kernel-parameters.txt +4 -0
@@ -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
net/core/dev.c +101 -0
107 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 2/6 stmmac: remove mac address handling as a module parameter
In reply to Paolo Pisati--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -13
@@ -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 256static 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))
Signature · 1 line
1.7.9.5
PATCH 3/6 ksz884x: remove mac address handling as a module parameter
In reply to Paolo Pisati--- drivers/net/ethernet/micrel/ksz884x.c | 57 --------------------------------- 1 file changed, 57 deletions(-)
drivers/net/ethernet/micrel/ksz884x.c +0 -57
@@ -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" );
Signature · 1 line
1.7.9.5
PATCH 4/6 greth: remove mac address handling as a module parameter
In reply to Paolo Pisati--- drivers/net/ethernet/aeroflex/greth.c | 36 +++++++++++---------------------- 1 file changed, 12 insertions(+), 24 deletions(-)
drivers/net/ethernet/aeroflex/greth.c +12 -24
@@ -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" );
Signature · 1 line
1.7.9.5
PATCH 5/6 sunhme: remove mac address handling as a module parameter
In reply to Paolo Pisati--- drivers/net/ethernet/sun/sunhme.c | 69 +++++++++---------------------------- 1 file changed, 16 insertions(+), 53 deletions(-)
drivers/net/ethernet/sun/sunhme.c +16 -53
@@ -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 istruct 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 iif (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 );
Signature · 1 line
1.7.9.5
PATCH 6/6 fec: remove mac address handling as a module parameter
In reply to Paolo Pisati--- drivers/net/ethernet/freescale/fec.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)
drivers/net/ethernet/freescale/fec.c +7 -20
@@ -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; }/* ------------------------------------------------------------------------- */
Signature · 1 line
1.7.9.5
David Miller
maintainerFrom: Paolo Pisati <[email protected]>
Date: Tue, 23 Oct 2012 19:15:27 +0200
Quoted 7 lines
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.
Quoted 8 lines · David Miller
From: Paolo Pisati <[email protected]>
Date: Tue, 23 Oct 2012 19:15:27 +0200Quoted 5 lines
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.
Quoted 7 lines
Quoted 2 lines
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.
Signature · 2 lines
bye, p.