* [PATCH] lan743x: allow mac address to come from dt
@ 2020-06-17 22:59 Tim Harvey
2020-06-18 12:44 ` Andrew Lunn
2020-06-19 3:40 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Tim Harvey @ 2020-06-17 22:59 UTC (permalink / raw)
To: Bryan Whitehead, Microchip Linux Driver Support,
David S . Miller, Jakub Kicinski
Cc: netdev, linux-kernel, Tim Harvey
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 <tharvey@gateworks.com>
---
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 <linux/rtnetlink.h>
#include <linux/iopoll.h>
#include <linux/crc16.h>
+#include <linux/of_net.h>
#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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lan743x: allow mac address to come from dt
2020-06-17 22:59 [PATCH] lan743x: allow mac address to come from dt Tim Harvey
@ 2020-06-18 12:44 ` Andrew Lunn
2020-06-19 3:40 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2020-06-18 12:44 UTC (permalink / raw)
To: Tim Harvey
Cc: Bryan Whitehead, Microchip Linux Driver Support,
David S . Miller, Jakub Kicinski, netdev, linux-kernel
On Wed, Jun 17, 2020 at 03:59:10PM -0700, Tim Harvey wrote:
> 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 <tharvey@gateworks.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lan743x: allow mac address to come from dt
2020-06-17 22:59 [PATCH] lan743x: allow mac address to come from dt Tim Harvey
2020-06-18 12:44 ` Andrew Lunn
@ 2020-06-19 3:40 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-06-19 3:40 UTC (permalink / raw)
To: tharvey; +Cc: bryan.whitehead, UNGLinuxDriver, kuba, netdev, linux-kernel
From: Tim Harvey <tharvey@gateworks.com>
Date: Wed, 17 Jun 2020 15:59:10 -0700
> 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 <tharvey@gateworks.com>
Applied to net-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-19 3:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 22:59 [PATCH] lan743x: allow mac address to come from dt Tim Harvey
2020-06-18 12:44 ` Andrew Lunn
2020-06-19 3:40 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).