* net: usb: ax88179_178a: allow passing MAC via DTB @ 2019-09-30 12:04 Peter Fink 2019-09-30 12:04 ` [PATCH net-next] net: usb: ax88179_178a: allow optionally getting mac address from device tree Peter Fink 0 siblings, 1 reply; 5+ messages in thread From: Peter Fink @ 2019-09-30 12:04 UTC (permalink / raw) To: netdev; +Cc: pfink, davem, linux From: Peter Fink <pfink@christ-es.de> This is a resend of the following patch as net-next was closed before: I adopted the feature to pass the MAC address through device tree from asix_devices.c (introduced in 03fc5d4) to ax88179-based devices. Please have a look if this patch can be accepted. I introduced a new function to avoid code duplication, but I'm not perfectly satisfied with the function name. Suggestions welcome. I'm not totally sure if the use of net->dev_addr and net->perm_addr was correct in the first place or if my understanding is lacking some bits. But I kept the existing behavior as it is working as expected. Patch tested with 4.19, but applies cleanly on net-next. Best regards, Peter -- drivers/net/usb/ax88179_178a.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) -- 2.7.4 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next] net: usb: ax88179_178a: allow optionally getting mac address from device tree 2019-09-30 12:04 net: usb: ax88179_178a: allow passing MAC via DTB Peter Fink @ 2019-09-30 12:04 ` Peter Fink 2019-09-30 13:45 ` Andrew Lunn 2019-10-01 22:20 ` David Miller 0 siblings, 2 replies; 5+ messages in thread From: Peter Fink @ 2019-09-30 12:04 UTC (permalink / raw) To: netdev; +Cc: pfink, davem, linux From: Peter Fink <pfink@christ-es.de> Adopt and integrate the feature to pass the MAC address via device tree from asix_device.c (03fc5d4) also to other ax88179 based asix chips. E.g. the bootloader fills in local-mac-address and the driver will then pick up and use this MAC address. Signed-off-by: Peter Fink <pfink@christ-es.de> --- drivers/net/usb/ax88179_178a.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index daa5448..5a58766 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -1214,6 +1214,29 @@ static int ax88179_led_setting(struct usbnet *dev) return 0; } +static void ax88179_get_mac_addr(struct usbnet *dev) +{ + u8 mac[ETH_ALEN]; + + /* Maybe the boot loader passed the MAC address via device tree */ + if (!eth_platform_get_mac_address(&dev->udev->dev, mac)) { + netif_dbg(dev, ifup, dev->net, + "MAC address read from device tree"); + } else { + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, + ETH_ALEN, mac); + netif_dbg(dev, ifup, dev->net, + "MAC address read from ASIX chip"); + } + + if (is_valid_ether_addr(mac)) { + memcpy(dev->net->dev_addr, mac, ETH_ALEN); + } else { + netdev_info(dev->net, "invalid MAC address, using random\n"); + eth_hw_addr_random(dev->net); + } +} + static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) { u8 buf[5]; @@ -1240,8 +1263,8 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp); msleep(100); - ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, - ETH_ALEN, dev->net->dev_addr); + /* Read MAC address from DTB or asix chip */ + ax88179_get_mac_addr(dev); memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); /* RX bulk configuration */ @@ -1541,8 +1564,8 @@ static int ax88179_reset(struct usbnet *dev) /* Ethernet PHY Auto Detach*/ ax88179_auto_detach(dev, 0); - ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN, - dev->net->dev_addr); + /* Read MAC address from DTB or asix chip */ + ax88179_get_mac_addr(dev); /* RX bulk configuration */ memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); -- 2.7.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: usb: ax88179_178a: allow optionally getting mac address from device tree 2019-09-30 12:04 ` [PATCH net-next] net: usb: ax88179_178a: allow optionally getting mac address from device tree Peter Fink @ 2019-09-30 13:45 ` Andrew Lunn 2019-10-01 22:20 ` David Miller 1 sibling, 0 replies; 5+ messages in thread From: Andrew Lunn @ 2019-09-30 13:45 UTC (permalink / raw) To: Peter Fink; +Cc: netdev, pfink, davem, linux On Mon, Sep 30, 2019 at 02:04:03PM +0200, Peter Fink wrote: > From: Peter Fink <pfink@christ-es.de> > > Adopt and integrate the feature to pass the MAC address via device tree > from asix_device.c (03fc5d4) also to other ax88179 based asix chips. > E.g. the bootloader fills in local-mac-address and the driver will then > pick up and use this MAC address. > > Signed-off-by: Peter Fink <pfink@christ-es.de> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: usb: ax88179_178a: allow optionally getting mac address from device tree 2019-09-30 12:04 ` [PATCH net-next] net: usb: ax88179_178a: allow optionally getting mac address from device tree Peter Fink 2019-09-30 13:45 ` Andrew Lunn @ 2019-10-01 22:20 ` David Miller 1 sibling, 0 replies; 5+ messages in thread From: David Miller @ 2019-10-01 22:20 UTC (permalink / raw) To: pedro; +Cc: netdev, pfink, linux From: Peter Fink <pedro@pixelbox.red> Date: Mon, 30 Sep 2019 14:04:03 +0200 > From: Peter Fink <pfink@christ-es.de> > > Adopt and integrate the feature to pass the MAC address via device tree > from asix_device.c (03fc5d4) also to other ax88179 based asix chips. > E.g. the bootloader fills in local-mac-address and the driver will then > pick up and use this MAC address. > > Signed-off-by: Peter Fink <pfink@christ-es.de> Applied. ^ permalink raw reply [flat|nested] 5+ messages in thread
* net: usb: ax88179_178a: allow passing MAC via DTB @ 2019-09-20 6:58 Peter Fink 0 siblings, 0 replies; 5+ messages in thread From: Peter Fink @ 2019-09-20 6:58 UTC (permalink / raw) To: netdev; +Cc: pfink, davem, linux From: Peter Fink <pfink@christ-es.de> I adopted the feature to pass the MAC address through device tree from asix_devices.c (introduced in 03fc5d4) to ax88179-based devices. Please have a look if this patch can be accepted. I introduced a new function to avoid code duplication, but I'm not perfectly satisfied with the function name. Suggestions welcome. I'm not totally sure if the use of net->dev_addr and net->perm_addr was correct in the first place or if my understanding is lacking some bits. But I kept the existing behavior as it is working as expected. Patch tested with 4.19, but applies cleanly on net-next. Best regards, Peter -- drivers/net/usb/ax88179_178a.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) -- 2.7.4 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-10-01 22:20 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-09-30 12:04 net: usb: ax88179_178a: allow passing MAC via DTB Peter Fink 2019-09-30 12:04 ` [PATCH net-next] net: usb: ax88179_178a: allow optionally getting mac address from device tree Peter Fink 2019-09-30 13:45 ` Andrew Lunn 2019-10-01 22:20 ` David Miller -- strict thread matches above, loose matches on Subject: below -- 2019-09-20 6:58 net: usb: ax88179_178a: allow passing MAC via DTB Peter Fink
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).