Skip to content

Commit

Permalink
Merge branch 'r8152-next'
Browse files Browse the repository at this point in the history
Hayes Wang says:

====================
r8152: random MAC address

If the interface has invalid MAC address, it couldn't
be used. In order to let it work normally, give a
random one.

v3:
  Remove
	ether_addr_copy(dev->perm_addr, dev->dev_addr);

v2:
  Use "%pM" format specifier for printing a MAC address.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Sep 5, 2014
2 parents b52b727 + 179bb6d commit e4cf0b7
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions drivers/net/usb/r8152.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,34 +975,6 @@ void write_mii_word(struct net_device *netdev, int phy_id, int reg, int val)
static int
r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags);

static inline void set_ethernet_addr(struct r8152 *tp)
{
struct net_device *dev = tp->netdev;
int ret;
u8 node_id[8] = {0};

if (tp->version == RTL_VER_01)
ret = pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id);
else
ret = pla_ocp_read(tp, PLA_BACKUP, sizeof(node_id), node_id);

if (ret < 0) {
netif_notice(tp, probe, dev, "inet addr fail\n");
} else {
if (tp->version != RTL_VER_01) {
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR,
CRWECR_CONFIG);
pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES,
sizeof(node_id), node_id);
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR,
CRWECR_NORAML);
}

memcpy(dev->dev_addr, node_id, dev->addr_len);
memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
}
}

static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
{
struct r8152 *tp = netdev_priv(netdev);
Expand All @@ -1020,6 +992,37 @@ static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
return 0;
}

static int set_ethernet_addr(struct r8152 *tp)
{
struct net_device *dev = tp->netdev;
struct sockaddr sa;
int ret;

if (tp->version == RTL_VER_01)
ret = pla_ocp_read(tp, PLA_IDR, 8, sa.sa_data);
else
ret = pla_ocp_read(tp, PLA_BACKUP, 8, sa.sa_data);

if (ret < 0) {
netif_err(tp, probe, dev, "Get ether addr fail\n");
} else if (!is_valid_ether_addr(sa.sa_data)) {
netif_err(tp, probe, dev, "Invalid ether addr %pM\n",
sa.sa_data);
eth_hw_addr_random(dev);
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",
sa.sa_data);
} else {
if (tp->version == RTL_VER_01)
ether_addr_copy(dev->dev_addr, sa.sa_data);
else
ret = rtl8152_set_mac_address(dev, &sa);
}

return ret;
}

static void read_bulk_callback(struct urb *urb)
{
struct net_device *netdev;
Expand Down

0 comments on commit e4cf0b7

Please sign in to comment.