From patchwork Mon May 20 15:59:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1102109 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XE8y+sEO"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 4573WY4djdz9sBK for ; Tue, 21 May 2019 02:00:09 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5A83DC21E70; Mon, 20 May 2019 16:00:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A2D88C21E08; Mon, 20 May 2019 16:00:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EC540C21E08; Mon, 20 May 2019 15:59:59 +0000 (UTC) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by lists.denx.de (Postfix) with ESMTPS id 98E47C21C2F for ; Mon, 20 May 2019 15:59:59 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id y3so13879191wmm.2 for ; Mon, 20 May 2019 08:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hSvNwpMd6Bl+FogowTpAcKp5ob+50MbeXQ4VnoEfyJE=; b=XE8y+sEOhRWoikZRIbnNsumQvnRqMn6RZUGWouObQxY05WFcl/NBsC3wdDjco7Fn6d 1DkaWU/gklpNDTEt+Lj1OKJUw9vea6cqEo9QjUmtI13MogeO8JAj5gFrvI8aYeMuIWLg ptOh/yIWJ7O0RQKZQMcIpZ4tQihb8JBiyi16iCgRgdWb4VY+oM8gBPEU0vSVJGRKuMWq QUS1VYTC8dXZ5OBI1FFjZimsfri7gYhrwYuhdr528LX5o/RT0QBtAvjEmaThkxo3ZP6L E2qhgC2xzgrxIoISzsc4fZelEWv2T6x7eIT5Q3lJ3zUOiblidspSOm08vOsoxqma9m5F ItvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hSvNwpMd6Bl+FogowTpAcKp5ob+50MbeXQ4VnoEfyJE=; b=cXYgrCE2medzjSmNrprSitPj7CqEDE2lOEP+JHHEKdxzCIfJUqdrl/Jpy6pfx54UQV nijEtE2WV7/Az6PiIE5wHorktvW4AV3W+MAogGmvrS9f+1rQdyjiowi6RDpnepcrxpkr heQLvD2iRFuWoSlfOgNH8dON4JWvABkiycK7xrNvMl7bXEF+H+L8JwI8gOX4YdsU87fl GF+oZwsV6vJ5p4IYTlyjma3va23vTH76qoL6O4uSaP8mWWeNdbudsclgyOuFtW39fSmu 6v5VN5cFqum9wY2YHUYMEYA1JbZO8ECH1XUsQEpjFxxjKO0lCCWaRnHRNDN5AU0QizsG LyFw== X-Gm-Message-State: APjAAAUOGGyZp8xUVzYjvPYh4XGNS07Idf89Ff3vW+itREOeicLp67kW neTt8UmA/e9HBiLvE8CtkU4= X-Google-Smtp-Source: APXvYqxzzAIsH4hebhw8DEu9H/C1DPFcOq0ng/OowAnrnS+21Mv+ud8ecedME7Ma5bPH8UV/JVuryg== X-Received: by 2002:a1c:a755:: with SMTP id q82mr12188047wme.82.1558367999104; Mon, 20 May 2019 08:59:59 -0700 (PDT) Received: from localhost (p2E5BEF36.dip0.t-ipconnect.de. [46.91.239.54]) by smtp.gmail.com with ESMTPSA id t18sm31790000wrg.19.2019.05.20.08.59.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 May 2019 08:59:58 -0700 (PDT) From: Thierry Reding To: Simon Glass , Joe Hershberger Date: Mon, 20 May 2019 17:59:56 +0200 Message-Id: <20190520155957.22068-1-thierry.reding@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v4 1/2] net: eth-uclass: Write MAC address to hardware after probe X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Thierry Reding In order for the device to use the proper MAC address, which can have been configured in the environment prior to the device being registered, ensure that the MAC address is written after the device has been probed. For devices that are registered before the network stack is initialized, this is already done during eth_initialize(). If the Ethernet device is on a bus that is not initialized on early boot, such as PCI, the device is not available at the time eth_initialize() is called, so we need the MAC address programming to also happen after probe. Acked-by: Joe Hershberger Signed-off-by: Thierry Reding --- net/eth-uclass.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 2ef20df19203..4225aabf1fa1 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -524,6 +524,8 @@ static int eth_post_probe(struct udevice *dev) #endif } + eth_write_hwaddr(dev); + return 0; } From patchwork Mon May 20 15:59:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1102110 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XJHW8RSi"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 4573Wr192wz9sBb for ; Tue, 21 May 2019 02:00:24 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id BF98DC21ECA; Mon, 20 May 2019 16:00:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1B22BC21EC8; Mon, 20 May 2019 16:00:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 74216C21E08; Mon, 20 May 2019 16:00:01 +0000 (UTC) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by lists.denx.de (Postfix) with ESMTPS id 280E4C21C2F for ; Mon, 20 May 2019 16:00:01 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id q15so13598174wmj.0 for ; Mon, 20 May 2019 09:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JsHWjg/6vidA+TANbKMD14gD7LcnYnwjOUbDnENM5JQ=; b=XJHW8RSiRjZENRK2FaXMdsSHLmWyarzjIkIJ9XtZxIVlf9H+jt+jwKn/0A6pIsMWye HBteQH2VSnPK6FRdr9sAvLrqzL/67FXU4mLbTsePmnhtgwjxJ7RRxeX5sbMlRpKvdoAf M7fyd0oG0YTJYUTamWd2b7EiO6qKyUQUNDASdPgtbGwUio3zoOcKC8O5La6r8M5swNMe gCrZ99NUTN+LOMiWNqWZdIwfzpEGeiS5tl71g+WzKWPErv6+SF5kLSSgK6I/sOgAwB6B 8QnyoPKpV6rm44rC2+sRvUk0TaTCI3ezxdWwx+z64/p/rLpIc7UqIwDwvm4GGA/xL/fz /P6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JsHWjg/6vidA+TANbKMD14gD7LcnYnwjOUbDnENM5JQ=; b=TjIruNBFk4+bPkO1Kva/IhJf/j57ybqIpDvxQlaTFKszlTmcxEkDB4l9qFhDeXVHKV gntVPnFs3tntp7kMfNgGl1LWgySlx5MhVGgJmQO6d2T3NOI4cJbPHYg8wmiC3/72INMu Lqef4X4Rxula8dR0TvsZrPJvgiKYd8B65U6nPMQzsFEBO8Pdg5V2ITX/X4jGR8V0H35b indkKp9esjJhYQH6VdYYEbl2Mm+DTScRA4rd6Ophk0+eALMyvDVMEwBzLpEZxwbCpWDP v0jcbjvrgurI9syGuodPXG2/xikGy/VpmrD3OSpo75DeYocRmWTQrZqvlsz7JNVIBRWc MYXA== X-Gm-Message-State: APjAAAVmc4EdUpUh+pex7MSseUR+dHeDvSlkasifTD1q9pUH78y13nFe uhX3deaNjvOqAG9hFrPSh5I= X-Google-Smtp-Source: APXvYqyrD1eKizStAnK7KjxkzPFIeMnC1zAWvZiN3V5+j+nrAjJvEl2Mg+lBz3g/oaq3eoS/DF71jA== X-Received: by 2002:a7b:c189:: with SMTP id y9mr12996380wmi.116.1558368000666; Mon, 20 May 2019 09:00:00 -0700 (PDT) Received: from localhost (p2E5BEF36.dip0.t-ipconnect.de. [46.91.239.54]) by smtp.gmail.com with ESMTPSA id z74sm444932wmc.2.2019.05.20.08.59.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 May 2019 09:00:00 -0700 (PDT) From: Thierry Reding To: Simon Glass , Joe Hershberger Date: Mon, 20 May 2019 17:59:57 +0200 Message-Id: <20190520155957.22068-2-thierry.reding@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520155957.22068-1-thierry.reding@gmail.com> References: <20190520155957.22068-1-thierry.reding@gmail.com> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v4 2/2] net: eth-uclass: Support device tree MAC addresses X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Thierry Reding Add the standard Ethernet device tree bindings (imported from v5.0 of the Linux kernel) and implement support for reading the MAC address for Ethernet devices in the Ethernet uclass. If the "mac-address" property exists, the MAC address will be parsed from that. If that property does not exist, the "local-mac-address" property will be tried as fallback. MAC addresses from device tree take precedence over the ones stored in a network interface card's ROM. Acked-by: Joe Hershberger Reviewed-by: Grygorii Strashko Signed-off-by: Thierry Reding --- Changes in v4: - do not clear MAC address on failure to avoid overwriting existing MAC - fix build on xtensa (missing CONFIG_OF_CONTROL) Changes in v3: - add additional check to make sure the MAC address read from device tree is a valid MAC address Changes in v2: - use dev_read_u8_array_ptr() --- .../devicetree/bindings/net/ethernet.txt | 66 +++++++++++++++++++ net/eth-uclass.c | 30 ++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/ethernet.txt diff --git a/Documentation/devicetree/bindings/net/ethernet.txt b/Documentation/devicetree/bindings/net/ethernet.txt new file mode 100644 index 000000000000..cfc376bc977a --- /dev/null +++ b/Documentation/devicetree/bindings/net/ethernet.txt @@ -0,0 +1,66 @@ +The following properties are common to the Ethernet controllers: + +NOTE: All 'phy*' properties documented below are Ethernet specific. For the +generic PHY 'phys' property, see +Documentation/devicetree/bindings/phy/phy-bindings.txt. + +- local-mac-address: array of 6 bytes, specifies the MAC address that was + assigned to the network device; +- mac-address: array of 6 bytes, specifies the MAC address that was last used by + the boot program; should be used in cases where the MAC address assigned to + the device by the boot program is different from the "local-mac-address" + property; +- nvmem-cells: phandle, reference to an nvmem node for the MAC address; +- nvmem-cell-names: string, should be "mac-address" if nvmem is to be used; +- max-speed: number, specifies maximum speed in Mbit/s supported by the device; +- max-frame-size: number, maximum transfer unit (IEEE defined MTU), rather than + the maximum frame size (there's contradiction in the Devicetree + Specification). +- phy-mode: string, operation mode of the PHY interface. This is now a de-facto + standard property; supported values are: + * "internal" + * "mii" + * "gmii" + * "sgmii" + * "qsgmii" + * "tbi" + * "rev-mii" + * "rmii" + * "rgmii" (RX and TX delays are added by the MAC when required) + * "rgmii-id" (RGMII with internal RX and TX delays provided by the PHY, the + MAC should not add the RX or TX delays in this case) + * "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC + should not add an RX delay in this case) + * "rgmii-txid" (RGMII with internal TX delay provided by the PHY, the MAC + should not add an TX delay in this case) + * "rtbi" + * "smii" + * "xgmii" + * "trgmii" + * "2000base-x", + * "2500base-x", + * "rxaui" + * "xaui" + * "10gbase-kr" (10GBASE-KR, XFI, SFI) +- phy-connection-type: the same as "phy-mode" property but described in the + Devicetree Specification; +- phy-handle: phandle, specifies a reference to a node representing a PHY + device; this property is described in the Devicetree Specification and so + preferred; +- phy: the same as "phy-handle" property, not recommended for new bindings. +- phy-device: the same as "phy-handle" property, not recommended for new + bindings. +- rx-fifo-depth: the size of the controller's receive fifo in bytes. This + is used for components that can have configurable receive fifo sizes, + and is useful for determining certain configuration settings such as + flow control thresholds. +- tx-fifo-depth: the size of the controller's transmit fifo in bytes. This + is used for components that can have configurable fifo sizes. +- managed: string, specifies the PHY management type. Supported values are: + "auto", "in-band-status". "auto" is the default, it usess MDIO for + management if fixed-link is not specified. + +Child nodes of the Ethernet controller are typically the individual PHY devices +connected via the MDIO bus (sometimes the MDIO bus controller is separate). +They are described in the phy.txt file in this same directory. +For non-MDIO PHY management see fixed-link.txt. diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 4225aabf1fa1..031d55862583 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -455,6 +455,26 @@ static int eth_pre_unbind(struct udevice *dev) return 0; } +static bool eth_dev_get_mac_address(struct udevice *dev, u8 mac[ARP_HLEN]) +{ +#if IS_ENABLED(CONFIG_OF_CONTROL) + const uint8_t *p; + + p = dev_read_u8_array_ptr(dev, "mac-address", ARP_HLEN); + if (!p) + p = dev_read_u8_array_ptr(dev, "local-mac-address", ARP_HLEN); + + if (!p) + return false; + + memcpy(mac, p, ARP_HLEN); + + return true; +#else + return false; +#endif +} + static int eth_post_probe(struct udevice *dev) { struct eth_device_priv *priv = dev->uclass_priv; @@ -489,9 +509,13 @@ static int eth_post_probe(struct udevice *dev) priv->state = ETH_STATE_INIT; - /* Check if the device has a MAC address in ROM */ - if (eth_get_ops(dev)->read_rom_hwaddr) - eth_get_ops(dev)->read_rom_hwaddr(dev); + /* Check if the device has a valid MAC address in device tree */ + if (!eth_dev_get_mac_address(dev, pdata->enetaddr) || + !is_valid_ethaddr(pdata->enetaddr)) { + /* Check if the device has a MAC address in ROM */ + if (eth_get_ops(dev)->read_rom_hwaddr) + eth_get_ops(dev)->read_rom_hwaddr(dev); + } eth_env_get_enetaddr_by_index("eth", dev->seq, env_enetaddr); if (!is_zero_ethaddr(env_enetaddr)) {