Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3597803imm; Mon, 25 Jun 2018 01:02:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI7/yUP26qOcAMQ3tQau+Qn7N4IeeDWNZve+TZGHY5XJnvyHA3SmPcM1E1WodZs2yHS8iMD X-Received: by 2002:a63:b505:: with SMTP id y5-v6mr10043593pge.213.1529913763804; Mon, 25 Jun 2018 01:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529913763; cv=none; d=google.com; s=arc-20160816; b=V9kmjpjfYiHK962PqMTacudK3zi7rRNA7/aNHuOWryCGNtbuArnqDKeCHmG+irXhvQ 89OOSyJR9mnnSJNFdcflw29nAFQBth1VeDe87oaNalOM+iD7WxrP3kFF1R6O/ZL6XM4Y 00J9DfWRL51AoSsiOIQlWGGP9o5zKrKmdDpoNtz8pw7XcLjmwZQSOM1p7pNSKAhBf3vz bwnaya9aEITvtNTF7sDScqMqOGdipJvOdotcRJaOqEP1ZP6cNSoANMGTpL8h1IwzZYN7 c6kOlw+HMiLi8Wy54uY4E1dhPLwymrwner/2H6B5P+AXWvqp1mo0VhStDn4VJrp0M0wA PDQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ssx+PbH2k/OqPzx5Du0dy3nulAsDpj19N5jzElsqDJw=; b=FQduQBHFKPvrMAlGP5FnEmrqXMq4W8SlYFP15Iy4UuDBsLN3aCS/S9Qgl3c5o8I48f jTzFA0k0FF2XNXLlUOuOMUKx5ubx2ltIzNmQQmu/h8GbCJAUzjWOlF3m0sS+2HDkCs3/ zGzKWysL25BqQOvOzBKvn2z2Sqk7UO3hDL4yRrNreDSj2x1BSgEmHpUgqpzZ/YLtdzc7 ur0mytooaMDGDuPKbsXgAVeA2k0mpE4C2oweWqaef8r9e5juLb6JhxWMOKeK2x9mW94p msy11UGRQN/S6OUzQ6haZQ4+PozDa7s0lqy7kintzjncxM62nuWPmlYJ2gJE9+NljbUq Ulnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8-v6si246230pfe.187.2018.06.25.01.02.29; Mon, 25 Jun 2018 01:02:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752939AbeFYIBp (ORCPT + 99 others); Mon, 25 Jun 2018 04:01:45 -0400 Received: from mout.perfora.net ([74.208.4.197]:37051 "EHLO mout.perfora.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752383AbeFYIBn (ORCPT ); Mon, 25 Jun 2018 04:01:43 -0400 Received: from localhost.localdomain.toradex.int ([46.140.72.82]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPA (Nemesis) id 0LlWiH-1g8LsW3Lx1-00bKFT; Mon, 25 Jun 2018 10:01:20 +0200 From: Marcel Ziswiler To: netdev@vger.kernel.org Cc: Oliver Neukum , Marcel Ziswiler , linux-usb@vger.kernel.org, "David S. Miller" , Dean Jenkins , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH] net: usb: asix: allow optionally getting mac address from device tree Date: Mon, 25 Jun 2018 10:01:08 +0200 Message-Id: <20180625080108.32441-1-marcel@ziswiler.com> X-Mailer: git-send-email 2.14.4 X-Provags-ID: V03:K1:mBelHOJuJGy25FR5K74iFAqsUeFxOA6/igAVHPv7IClje9hiKC9 dmzMEFLQlVIElNsMSdSIq6kKindjqwID+pKbGZoc2g7TpbUocvyeYQ+0lZe+XF1lsxm86Eh JhP4IH8z6PqnrBjvL6/aH6QaCQWPirrbh5tCLSObXC5XXHY+uYWaj+zrj5fP7cw2JDL9ypZ x1ai6ZmK4TMt1HnUL5iLg== X-UI-Out-Filterresults: notjunk:1;V01:K0:J6gzLOGem30=:yLXExeUf8MXRyQUYT33e8b mtVa2QVEZrQolDZ4qYdTFV+9C0MfiGm27Kfb5DpghDJVMEaDkcvA6ZvgSG355wf4gCPARUDHp Hbeov0OKikcP+Lh67d7RyaCm7FIjL/9n+pa7fPiC5z1ZFtWXSdX90QQCKOhj9vNFMHZU/bpAj Rskb4N6k+td5UYeLJO/3bDCqlKXQKrX0ujZn4+LyyiJEdmX56pOTxFedUiFNs3q7SZmxEjywd xsdtOTN5PgUQWqZjUxKODoum4DJee1GzOucyGQhCUE7lzxUKFaEQR5N2eMKA/eQTpnXE9pWIi Jy2bWoVJDIkUqlVuuFVswlX4HAfQbcXoUwyxboNDVGkYXwLkYnbjO2z5OZJjDVWLGdi5kQ4xV bwwlU836z2UOYG3re2YrM4Vk5ruMsK1w+8JUGDIU752Dfr7mZsz/Tls/fkMin/Z0s9kM9zb46 kw0d8nPqhbDsOhsyXRb2NEASv+DM5AfnGuY3OI8iWq8I+ZOApm++mRAUNvUzMYsAqPyyMkItH Et2wllfMWONsvVnw6Wh/vA+FZXb/9u+zH3UaM5XbCDwx7tEelwuJNb0HDs02dbiRuEodO0xvT bYFJxfwHLPbRG24VkTRTwxQPbjRxXxP3gmQyvj5+K7N4zbsHE2c6lItFrGWkxLolPrD1Pkavc 1oy0mNniM5cCyHdmeorR/idGv9mRgE9qnG2x0P7gFcpAUb9yWFu8hzfzXOVRlifZzbjA= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marcel Ziswiler 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@7d004000 { 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 --- 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 #include #include +#include #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); -- 2.14.4