Re: [PATCH net-next v2 2/2] r8152: use eth_hw_addr_random

2014-09-03 Thread Bjørn Mork
Hayes Wang  writes:

> + ether_addr_copy(dev->perm_addr, dev->dev_addr);

This isn't strictly necessary.  register_netdev() will do it for you as
long as you leave the default addr_assign_type (NET_ADDR_PERM).  And you
do.



Bjørn
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH net-next v2 2/2] r8152: use eth_hw_addr_random

2014-09-03 Thread Bjørn Mork
Hayes Wang hayesw...@realtek.com writes:

 + ether_addr_copy(dev-perm_addr, dev-dev_addr);

This isn't strictly necessary.  register_netdev() will do it for you as
long as you leave the default addr_assign_type (NET_ADDR_PERM).  And you
do.



Bjørn
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH net-next v2 2/2] r8152: use eth_hw_addr_random

2014-09-02 Thread Hayes Wang
If the hw doesn't have a valid MAC address, give a random one and
set it to the hw.

Signed-off-by: Hayes Wang 
---
 drivers/net/usb/r8152.c | 35 ---
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index b5ff933..443eb9e 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -992,32 +992,37 @@ static int rtl8152_set_mac_address(struct net_device 
*netdev, void *p)
return 0;
 }
 
-static inline void set_ethernet_addr(struct r8152 *tp)
+static int set_ethernet_addr(struct r8152 *tp)
 {
struct net_device *dev = tp->netdev;
+   struct sockaddr sa;
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);
+   ret = pla_ocp_read(tp, PLA_IDR, 8, sa.sa_data);
else
-   ret = pla_ocp_read(tp, PLA_BACKUP, sizeof(node_id), node_id);
+   ret = pla_ocp_read(tp, PLA_BACKUP, 8, sa.sa_data);
 
if (ret < 0) {
-   netif_notice(tp, probe, dev, "inet addr fail\n");
+   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, );
+   netif_info(tp, probe, dev, "Random ether addr %pM\n",
+  sa.sa_data);
} 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);
-   }
+   if (tp->version == RTL_VER_01)
+   ether_addr_copy(dev->dev_addr, sa.sa_data);
+   else
+   ret = rtl8152_set_mac_address(dev, );
 
-   memcpy(dev->dev_addr, node_id, dev->addr_len);
-   memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
+   ether_addr_copy(dev->perm_addr, dev->dev_addr);
}
+
+   return ret;
 }
 
 static void read_bulk_callback(struct urb *urb)
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH net-next v2 2/2] r8152: use eth_hw_addr_random

2014-09-02 Thread Hayes Wang
If the hw doesn't have a valid MAC address, give a random one and
set it to the hw.

Signed-off-by: Hayes Wang hayesw...@realtek.com
---
 drivers/net/usb/r8152.c | 35 ---
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index b5ff933..443eb9e 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -992,32 +992,37 @@ static int rtl8152_set_mac_address(struct net_device 
*netdev, void *p)
return 0;
 }
 
-static inline void set_ethernet_addr(struct r8152 *tp)
+static int set_ethernet_addr(struct r8152 *tp)
 {
struct net_device *dev = tp-netdev;
+   struct sockaddr sa;
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);
+   ret = pla_ocp_read(tp, PLA_IDR, 8, sa.sa_data);
else
-   ret = pla_ocp_read(tp, PLA_BACKUP, sizeof(node_id), node_id);
+   ret = pla_ocp_read(tp, PLA_BACKUP, 8, sa.sa_data);
 
if (ret  0) {
-   netif_notice(tp, probe, dev, inet addr fail\n);
+   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) {
-   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);
-   }
+   if (tp-version == RTL_VER_01)
+   ether_addr_copy(dev-dev_addr, sa.sa_data);
+   else
+   ret = rtl8152_set_mac_address(dev, sa);
 
-   memcpy(dev-dev_addr, node_id, dev-addr_len);
-   memcpy(dev-perm_addr, dev-dev_addr, dev-addr_len);
+   ether_addr_copy(dev-perm_addr, dev-dev_addr);
}
+
+   return ret;
 }
 
 static void read_bulk_callback(struct urb *urb)
-- 
1.9.3

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/