Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
From: David MillerDate: Thu, 05 Nov 2015 10:31:26 -0500 (EST) > I'll see if I can cook something up. How does this look? net: Add eth_platform_get_mac_address() helper. A repeating pattern in drivers has become to use OF node information and, if not found, platform specific host information to extract the ethernet address for a given device. Currently this is done with a call to of_get_mac_mac_address() and then some ifdef'd stuff for SPARC. Consolidate this into a portable routine, and provide the arch_get_platform_mac_address() weak function hook for all architectures to implement if they want. Signed-off-by: David S. Miller diff --git a/arch/sparc/kernel/idprom.c b/arch/sparc/kernel/idprom.c index 6bd7501..f95dd11 100644 --- a/arch/sparc/kernel/idprom.c +++ b/arch/sparc/kernel/idprom.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,12 @@ static void __init display_system_type(unsigned char machtype) { } #endif + +unsigned char *arch_get_platform_mac_address(void) +{ + return idprom->id_ethaddr; +} + /* Calculate the IDPROM checksum (xor of the data bytes). */ static unsigned char __init calc_idprom_cksum(struct idprom *idprom) { diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index eb049c6..37ff4a6 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -29,6 +29,9 @@ #include #ifdef __KERNEL__ +struct device; +int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr); +unsigned char *arch_get_platform_get_mac_address(void); u32 eth_get_headlen(void *data, unsigned int max_len); __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev); extern const struct header_ops eth_header_ops; diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 9e63f25..1cb9204f 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -52,6 +52,8 @@ #include #include #include +#include +#include #include #include #include @@ -485,3 +487,33 @@ static int __init eth_offload_init(void) } fs_initcall(eth_offload_init); + +unsigned char * __weak arch_get_platform_mac_address(void) +{ + return NULL; +} + +int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) +{ + const unsigned char *addr; + struct device_node *dp; + + if (dev_is_pci(dev)) + dp = pci_device_to_OF_node(to_pci_dev(dev)); + else + dp = dev->of_node; + + addr = NULL; + if (dp) + addr = of_get_mac_address(dp); + if (!addr) + addr = arch_get_platform_mac_address(); + + if (addr) { + ether_addr_copy(mac_addr, addr); + return 0; + } + + return -ENODEV; +} +EXPORT_SYMBOL(eth_platform_get_mac_address); -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
On (11/05/15 11:29), David Miller wrote: > > The intention is to let your patch go in as-is, then try and update > ixgbe/i40e later in net-next or similar. Sounds good, I can take care of ixgbe/i40e after that happens. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
On (11/05/15 11:05), David Miller wrote: > From: David Miller> Date: Thu, 05 Nov 2015 10:31:26 -0500 (EST) > > > I'll see if I can cook something up. > > How does this look? Looks good to me, Do you want me to respin patch v7 with this? Or update ixgbe/i40e to use this later, after this goes in? --Sowmini -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
From: Sowmini VaradhanDate: Thu, 5 Nov 2015 11:28:31 -0500 > On (11/05/15 11:05), David Miller wrote: >> From: David Miller >> Date: Thu, 05 Nov 2015 10:31:26 -0500 (EST) >> >> > I'll see if I can cook something up. >> >> How does this look? > > Looks good to me, > > Do you want me to respin patch v7 with this? Or update ixgbe/i40e to use > this later, after this goes in? The intention is to let your patch go in as-is, then try and update ixgbe/i40e later in net-next or similar. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
> From: David Miller [mailto:da...@davemloft.net] > Sent: Thursday, November 05, 2015 8:29 AM > > From: Sowmini Varadhan> Date: Thu, 5 Nov 2015 11:28:31 -0500 > > > On (11/05/15 11:05), David Miller wrote: > >> From: David Miller > >> Date: Thu, 05 Nov 2015 10:31:26 -0500 (EST) > >> > >> > I'll see if I can cook something up. > >> > >> How does this look? > > > > Looks good to me, > > > > Do you want me to respin patch v7 with this? Or update ixgbe/i40e to > use > > this later, after this goes in? > > The intention is to let your patch go in as-is, then try and update > ixgbe/i40e later in net-next or similar. That works for us as well - thanks! sln -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
On Thu, Nov 5, 2015 at 6:05 PM, David Millerwrote: > From: David Miller > Date: Thu, 05 Nov 2015 10:31:26 -0500 (EST) > >> I'll see if I can cook something up. > > How does this look? I like it, though couple of style related comments. > > > net: Add eth_platform_get_mac_address() helper. > > A repeating pattern in drivers has become to use OF node information > and, if not found, platform specific host information to extract the > ethernet address for a given device. > > Currently this is done with a call to of_get_mac_mac_address() and > then some ifdef'd stuff for SPARC. > > Consolidate this into a portable routine, and provide the > arch_get_platform_mac_address() weak function hook for all > architectures to implement if they want. > > Signed-off-by: David S. Miller > > diff --git a/arch/sparc/kernel/idprom.c b/arch/sparc/kernel/idprom.c > index 6bd7501..f95dd11 100644 > --- a/arch/sparc/kernel/idprom.c > +++ b/arch/sparc/kernel/idprom.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -60,6 +61,12 @@ static void __init display_system_type(unsigned char > machtype) > { > } > #endif > + > +unsigned char *arch_get_platform_mac_address(void) > +{ > + return idprom->id_ethaddr; > +} > + > /* Calculate the IDPROM checksum (xor of the data bytes). */ > static unsigned char __init calc_idprom_cksum(struct idprom *idprom) > { > diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h > index eb049c6..37ff4a6 100644 > --- a/include/linux/etherdevice.h > +++ b/include/linux/etherdevice.h > @@ -29,6 +29,9 @@ > #include > > #ifdef __KERNEL__ > +struct device; > +int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr); > +unsigned char *arch_get_platform_get_mac_address(void); > u32 eth_get_headlen(void *data, unsigned int max_len); > __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev); > extern const struct header_ops eth_header_ops; > diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c > index 9e63f25..1cb9204f 100644 > --- a/net/ethernet/eth.c > +++ b/net/ethernet/eth.c > @@ -52,6 +52,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > #include > @@ -485,3 +487,33 @@ static int __init eth_offload_init(void) > } > > fs_initcall(eth_offload_init); > + > +unsigned char * __weak arch_get_platform_mac_address(void) > +{ > + return NULL; > +} > + > +int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) > +{ > + const unsigned char *addr; > + struct device_node *dp; > + > + if (dev_is_pci(dev)) > + dp = pci_device_to_OF_node(to_pci_dev(dev)); > + else > + dp = dev->of_node; > + > + addr = NULL; Maybe we can use definition block for this assignment? > + if (dp) > + addr = of_get_mac_address(dp); > + if (!addr) > + addr = arch_get_platform_mac_address(); > + > + if (addr) { What about if (!addr) return -ENODATA; (Yes, ENODATA looks suitable for me) > + ether_addr_copy(mac_addr, addr); > + return 0; > + } > + > + return -ENODEV; > +} > +EXPORT_SYMBOL(eth_platform_get_mac_address); -- With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
On Thu, Nov 5, 2015 at 8:31 PM, David Millerwrote: > From: Andy Shevchenko > Date: Thu, 5 Nov 2015 20:13:21 +0200 > >> What about >> >> if (!addr) >> return -ENODATA; > > I totally disagree. of_get_phy_mode() and other similar attribute > probing mechanisms use -ENODEV. Okay, then just if (!addr) return -ENODEV; -- With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
From: Andy ShevchenkoDate: Thu, 5 Nov 2015 20:13:21 +0200 > What about > > if (!addr) > return -ENODATA; I totally disagree. of_get_phy_mode() and other similar attribute probing mechanisms use -ENODEV. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
From: Sowmini VaradhanDate: Wed, 4 Nov 2015 18:21:00 -0500 > This is the i40e equivalent of commit c762dff24c06 ("ixgbe: Look up MAC > address in Open Firmware or IDPROM"). > > As with that fix, attempt to look up the MAC address in Open Firmware > on systems that support it, and use IDPROM on SPARC if no OF address > is found. > > In the case of the i40e there is an assumption that the default mac > address has already been set up as the primary mac filter on probe, > so if this filter is obtained from the Open Firmware or IDPROM, an > explicit write is needed via i40e_aq_mac_address_write() and > i40e_aq_add_macvlan() invocation. > > Reviewed-by: Martin K. Petersen > Signed-off-by: Sowmini Varadhan Thanks for doing this. Longer term we really need an abstract interface by which architectures can provide a "system" or "firmware" MAC address which applies to a given 'dev'. Because these SPARC ifdef'y things really should propagate to driver after driver after driver. I'll see if I can cook something up. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM
> From: Sowmini Varadhan [mailto:sowmini.varad...@oracle.com] > Sent: Wednesday, November 04, 2015 3:21 PM > > This is the i40e equivalent of commit c762dff24c06 ("ixgbe: Look up MAC > address in Open Firmware or IDPROM"). > > As with that fix, attempt to look up the MAC address in Open Firmware > on systems that support it, and use IDPROM on SPARC if no OF address > is found. > > In the case of the i40e there is an assumption that the default mac > address has already been set up as the primary mac filter on probe, > so if this filter is obtained from the Open Firmware or IDPROM, an > explicit write is needed via i40e_aq_mac_address_write() and > i40e_aq_add_macvlan() invocation. > > Reviewed-by: Martin K. Petersen> Signed-off-by: Sowmini Varadhan > --- > v2, v3: Andy Shevchenko comments > v4: Shannon Nelson review: explicitly set up mac filters before > register_netdev > v5: Shannon Nelson code style comments > v6: Shannon Nelson code style comments > > drivers/net/ethernet/intel/i40e/i40e_main.c | 83 > ++- > 1 files changed, 82 insertions(+), 1 deletions(-) > Acked-by: Shannon Nelson -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html