Commit 25766271 authored by Mario Limonciello's avatar Mario Limonciello Committed by David S. Miller

r8152: Refresh MAC address during USBDEVFS_RESET

On some platforms it is possible to dynamically change the policy
of what MAC address is selected from the ASL at runtime.

These tools will reset the USB device and expect the change to be
made immediately.
Signed-off-by: default avatarMario Limonciello <mario.limonciello@dell.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 78fdde30
...@@ -1220,39 +1220,51 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa) ...@@ -1220,39 +1220,51 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
return ret; return ret;
} }
static int set_ethernet_addr(struct r8152 *tp) static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa)
{ {
struct net_device *dev = tp->netdev; struct net_device *dev = tp->netdev;
struct sockaddr sa;
int ret; int ret;
if (tp->version == RTL_VER_01) { if (tp->version == RTL_VER_01) {
ret = pla_ocp_read(tp, PLA_IDR, 8, sa.sa_data); ret = pla_ocp_read(tp, PLA_IDR, 8, sa->sa_data);
} else { } else {
/* if device doesn't support MAC pass through this will /* if device doesn't support MAC pass through this will
* be expected to be non-zero * be expected to be non-zero
*/ */
ret = vendor_mac_passthru_addr_read(tp, &sa); ret = vendor_mac_passthru_addr_read(tp, sa);
if (ret < 0) if (ret < 0)
ret = pla_ocp_read(tp, PLA_BACKUP, 8, sa.sa_data); ret = pla_ocp_read(tp, PLA_BACKUP, 8, sa->sa_data);
} }
if (ret < 0) { if (ret < 0) {
netif_err(tp, probe, dev, "Get ether addr fail\n"); netif_err(tp, probe, dev, "Get ether addr fail\n");
} else if (!is_valid_ether_addr(sa.sa_data)) { } else if (!is_valid_ether_addr(sa->sa_data)) {
netif_err(tp, probe, dev, "Invalid ether addr %pM\n", netif_err(tp, probe, dev, "Invalid ether addr %pM\n",
sa.sa_data); sa->sa_data);
eth_hw_addr_random(dev); eth_hw_addr_random(dev);
ether_addr_copy(sa.sa_data, dev->dev_addr); ether_addr_copy(sa->sa_data, dev->dev_addr);
ret = rtl8152_set_mac_address(dev, &sa);
netif_info(tp, probe, dev, "Random ether addr %pM\n", netif_info(tp, probe, dev, "Random ether addr %pM\n",
sa.sa_data); sa->sa_data);
} else { return 0;
}
return ret;
}
static int set_ethernet_addr(struct r8152 *tp)
{
struct net_device *dev = tp->netdev;
struct sockaddr sa;
int ret;
ret = determine_ethernet_addr(tp, &sa);
if (ret < 0)
return ret;
if (tp->version == RTL_VER_01) if (tp->version == RTL_VER_01)
ether_addr_copy(dev->dev_addr, sa.sa_data); ether_addr_copy(dev->dev_addr, sa.sa_data);
else else
ret = rtl8152_set_mac_address(dev, &sa); ret = rtl8152_set_mac_address(dev, &sa);
}
return ret; return ret;
} }
...@@ -4263,10 +4275,18 @@ static int rtl8152_post_reset(struct usb_interface *intf) ...@@ -4263,10 +4275,18 @@ static int rtl8152_post_reset(struct usb_interface *intf)
{ {
struct r8152 *tp = usb_get_intfdata(intf); struct r8152 *tp = usb_get_intfdata(intf);
struct net_device *netdev; struct net_device *netdev;
struct sockaddr sa;
if (!tp) if (!tp)
return 0; return 0;
/* reset the MAC adddress in case of policy change */
if (determine_ethernet_addr(tp, &sa) >= 0) {
rtnl_lock();
dev_set_mac_address (tp->netdev, &sa, NULL);
rtnl_unlock();
}
netdev = tp->netdev; netdev = tp->netdev;
if (!netif_running(netdev)) if (!netif_running(netdev))
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment