Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp853440ybt; Wed, 17 Jun 2020 16:01:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtHZF+Djcq5rUREJsJ8A3fHWMyIJpw2yUV0tZvACQ6up+DfylCh7THNHXiN2/2RjaAfsyb X-Received: by 2002:aa7:d388:: with SMTP id x8mr1409883edq.380.1592434904513; Wed, 17 Jun 2020 16:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592434904; cv=none; d=google.com; s=arc-20160816; b=RW+pXO5ghnqqeEn5S2DT48ykXuuOVRWn8TL977/BfkyUJw9zBVvXXcZe6hYtNr3TKO PuBjBVrCCV1VBZ+7QDR3VGhHVmFKV5gSV6x3NRU0N8Bv4OhU0CNGccY7JRBLO/OCy6mJ eYy4uU/+Ldh1XvEd4MPm0BUGgBlfQDMKye1wB99meZmBgDiIZVRih7CEAzEuGEztmC0U lzd1diwOvVbU91cqAKD94qNzXPxORQCIHz8VPlJoslQ+IrxOPqEybbS+5Yg8U5R7wf2V cRy3KnqAbvTw/dZEYj2HQOnS1izXQOC8KJGjUrKUAU/vUJl4Zy++NuGMbWM9o+wTfiCp ISdQ== 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; bh=Yf2e9kSxdPIV349rGp+Fp94C3cH1OJBjICIjl3qhnSQ=; b=df7B70QIeN9gXMgoyjwUe0urIYUPMxiaeJiOOy1PFFEXMJRPRbUz/iR3Dcu8fxLbKk +jEVgi5UOlidZsMjU868qaAchrZP7scFLSiKovdbbs1HrVGdTlWW1HsdDhX/IfoXHOW5 yIP/N6OsTvRQdNHD+fpThLRL7Cyl3RkHdkpy5f55k951olzhLID9Sn78IFYtsm3HCn6q esnm/vn7xWZYsuwtomuWD1QOnlS0lqSQi28gE9NOkyfnw2+K9ufo9Mb6P6MNA0/U+2kT SwgAh1rhNzU/uu71IIFs3HswMGQvx5l4bhxwn8QxZqkALytmR+z+5+d+31fxCCWWN/Jt kMoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i21si835005edv.162.2020.06.17.16.01.20; Wed, 17 Jun 2020 16:01:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726952AbgFQW7V (ORCPT + 99 others); Wed, 17 Jun 2020 18:59:21 -0400 Received: from lists.gateworks.com ([108.161.130.12]:43580 "EHLO lists.gateworks.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726763AbgFQW7V (ORCPT ); Wed, 17 Jun 2020 18:59:21 -0400 Received: from 068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by lists.gateworks.com with esmtp (Exim 4.82) (envelope-from ) id 1jlh4l-0006j8-6D; Wed, 17 Jun 2020 23:02:35 +0000 From: Tim Harvey To: Bryan Whitehead , Microchip Linux Driver Support , "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Tim Harvey Subject: [PATCH] lan743x: allow mac address to come from dt Date: Wed, 17 Jun 2020 15:59:10 -0700 Message-Id: <1592434750-8940-1-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a valid mac address is present in dt, use that before using CSR's or a random mac address. Signed-off-by: Tim Harvey --- drivers/net/ethernet/microchip/lan743x_main.c | 41 ++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 7ef22bf..50ad56b 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "lan743x_main.h" #include "lan743x_ethtool.h" @@ -804,26 +805,29 @@ static int lan743x_mac_init(struct lan743x_adapter *adapter) data |= MAC_CR_CNTR_RST_; lan743x_csr_write(adapter, MAC_CR, data); - mac_addr_hi = lan743x_csr_read(adapter, MAC_RX_ADDRH); - mac_addr_lo = lan743x_csr_read(adapter, MAC_RX_ADDRL); - adapter->mac_address[0] = mac_addr_lo & 0xFF; - adapter->mac_address[1] = (mac_addr_lo >> 8) & 0xFF; - adapter->mac_address[2] = (mac_addr_lo >> 16) & 0xFF; - adapter->mac_address[3] = (mac_addr_lo >> 24) & 0xFF; - adapter->mac_address[4] = mac_addr_hi & 0xFF; - adapter->mac_address[5] = (mac_addr_hi >> 8) & 0xFF; + if (!is_valid_ether_addr(adapter->mac_address)) { + mac_addr_hi = lan743x_csr_read(adapter, MAC_RX_ADDRH); + mac_addr_lo = lan743x_csr_read(adapter, MAC_RX_ADDRL); + adapter->mac_address[0] = mac_addr_lo & 0xFF; + adapter->mac_address[1] = (mac_addr_lo >> 8) & 0xFF; + adapter->mac_address[2] = (mac_addr_lo >> 16) & 0xFF; + adapter->mac_address[3] = (mac_addr_lo >> 24) & 0xFF; + adapter->mac_address[4] = mac_addr_hi & 0xFF; + adapter->mac_address[5] = (mac_addr_hi >> 8) & 0xFF; + + if (((mac_addr_hi & 0x0000FFFF) == 0x0000FFFF) && + mac_addr_lo == 0xFFFFFFFF) { + mac_address_valid = false; + } else if (!is_valid_ether_addr(adapter->mac_address)) { + mac_address_valid = false; + } - if (((mac_addr_hi & 0x0000FFFF) == 0x0000FFFF) && - mac_addr_lo == 0xFFFFFFFF) { - mac_address_valid = false; - } else if (!is_valid_ether_addr(adapter->mac_address)) { - mac_address_valid = false; + if (!mac_address_valid) + eth_random_addr(adapter->mac_address); } - - if (!mac_address_valid) - eth_random_addr(adapter->mac_address); lan743x_mac_set_address(adapter, adapter->mac_address); ether_addr_copy(netdev->dev_addr, adapter->mac_address); + return 0; } @@ -2756,6 +2760,7 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev, { struct lan743x_adapter *adapter = NULL; struct net_device *netdev = NULL; + const void *mac_addr; int ret = -ENODEV; netdev = devm_alloc_etherdev(&pdev->dev, @@ -2772,6 +2777,10 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev, NETIF_MSG_IFDOWN | NETIF_MSG_TX_QUEUED; netdev->max_mtu = LAN743X_MAX_FRAME_SIZE; + mac_addr = of_get_mac_address(pdev->dev.of_node); + if (!IS_ERR(mac_addr)) + ether_addr_copy(adapter->mac_address, mac_addr); + ret = lan743x_pci_init(adapter, pdev); if (ret) goto return_error; -- 2.7.4