lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1529926008.12558.14.camel@toradex.com>
Date:   Mon, 25 Jun 2018 11:26:49 +0000
From:   Marcel Ziswiler <marcel.ziswiler@...adex.com>
To:     "davem@...emloft.net" <davem@...emloft.net>
CC:     "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "Dean_Jenkins@...tor.com" <Dean_Jenkins@...tor.com>,
        "andreyknvl@...gle.com" <andreyknvl@...gle.com>,
        "oneukum@...e.com" <oneukum@...e.com>,
        "linux-usb@...r.kernel.org" <linux-usb@...r.kernel.org>
Subject: Re: [PATCH] net: usb: asix: allow optionally getting mac address from
 device tree

Hi David

On Mon, 2018-06-25 at 10:01 +0200, Marcel Ziswiler wrote:
> From: Marcel Ziswiler <marcel.ziswiler@...adex.com>
> 
> For Embedded use where e.g. AX88772B chips may be used without
> external
> EEPROMs the boot loader may choose to pass the MAC address to be used
> via device tree. Therefore, allow for optionally getting the MAC
> address from device tree data e.g. as follows (excerpt from a T30
> based
> board, local-mac-address to be filled in by boot loader):
> 
> /* EHCI instance 1: USB2_DP/N -> AX88772B */
> usb@...04000 {
> 	status = "okay";
> 	#address-cells = <1>;
> 	#size-cells = <0>;
> 	asix@1 {
> 		reg = <1>;
> 		local-mac-address = [00 00 00 00 00 00];
> 	};
> };
> 
> Signed-off-by: Marcel Ziswiler <marcel.ziswiler@...adex.com>
> 
> ---
> 
>  drivers/net/usb/asix.h         |  1 +
>  drivers/net/usb/asix_devices.c | 39 ++++++++++++++++++++++++------
> ---------
>  2 files changed, 25 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
> index 9a4171b90947..c8161960cef2 100644
> --- a/drivers/net/usb/asix.h
> +++ b/drivers/net/usb/asix.h
> @@ -37,6 +37,7 @@
>  #include <linux/usb/usbnet.h>
>  #include <linux/slab.h>
>  #include <linux/if_vlan.h>
> +#include <linux/of_net.h>
>  
>  #define DRIVER_VERSION "22-Dec-2011"
>  #define DRIVER_NAME "asix"
> diff --git a/drivers/net/usb/asix_devices.c
> b/drivers/net/usb/asix_devices.c
> index 3d4f7959dabb..a88d65dfc64c 100644
> --- a/drivers/net/usb/asix_devices.c
> +++ b/drivers/net/usb/asix_devices.c
> @@ -690,25 +690,34 @@ static int ax88772_bind(struct usbnet *dev,
> struct usb_interface *intf)
>  	u8 buf[ETH_ALEN], chipcode = 0;
>  	u32 phyid;
>  	struct asix_common_private *priv;
> +	const u8 *mac_addr;
>  
> -	usbnet_get_endpoints(dev,intf);
> +	usbnet_get_endpoints(dev, intf);
>  
> -	/* Get the MAC address */
> -	if (dev->driver_info->data & FLAG_EEPROM_MAC) {
> -		for (i = 0; i < (ETH_ALEN >> 1); i++) {
> -			ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM,
> 0x04 + i,
> -					    0, 2, buf + i * 2, 0);
> -			if (ret < 0)
> -				break;
> -		}
> +	/* Maybe the boot loader passed the MAC address via device
> tree */
> +	mac_addr = of_get_mac_address(dev->udev->dev.of_node);
> +	if (mac_addr) {
> +		memcpy(buf, mac_addr, ETH_ALEN);
>  	} else {
> -		ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
> -				0, 0, ETH_ALEN, buf, 0);
> -	}
> +		/* Try getting the MAC address from EEPROM */
> +		if (dev->driver_info->data & FLAG_EEPROM_MAC) {
> +			for (i = 0; i < (ETH_ALEN >> 1); i++) {
> +				ret = asix_read_cmd(dev,
> AX_CMD_READ_EEPROM,
> +						    0x04 + i, 0, 2,
> buf + i * 2,
> +						    0);
> +				if (ret < 0)
> +					break;
> +			}
> +		} else {
> +			ret = asix_read_cmd(dev,
> AX_CMD_READ_NODE_ID,
> +					    0, 0, ETH_ALEN, buf, 0);
> +		}
>  
> -	if (ret < 0) {
> -		netdev_dbg(dev->net, "Failed to read MAC address:
> %d\n", ret);
> -		return ret;
> +		if (ret < 0) {
> +			netdev_dbg(dev->net, "Failed to read MAC
> address: %d\n",
> +				   ret);
> +			return ret;
> +		}
>  	}
>  
>  	asix_set_netdev_dev_addr(dev, buf);

Now that you mentioned eth_platform_get_mac_address() on my igb attempt I am
wondering whether that would not also be the better approach for ASIX USB net
use. Looks like at least lan78xx already does it that way as well.

What do you think?

Cheers

Marcel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ