netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] r8152: random MAC address
@ 2014-09-02  9:55 Hayes Wang
  2014-09-02  9:55 ` [PATCH net-next 1/2] r8152: change the location of rtl8152_set_mac_address Hayes Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Hayes Wang @ 2014-09-02  9:55 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb

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

Hayes Wang (2):
  r8152: change the location of rtl8152_set_mac_address
  r8152: use eth_hw_addr_random

 drivers/net/usb/r8152.c | 65 ++++++++++++++++++++++++++++---------------------
 1 file changed, 37 insertions(+), 28 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net-next 1/2] r8152: change the location of rtl8152_set_mac_address
  2014-09-02  9:55 [PATCH net-next 0/2] r8152: random MAC address Hayes Wang
@ 2014-09-02  9:55 ` Hayes Wang
  2014-09-02  9:55 ` [PATCH net-next 2/2] r8152: use eth_hw_addr_random Hayes Wang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Hayes Wang @ 2014-09-02  9:55 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb

Exchange the location of rtl8152_set_mac_address() and
set_ethernet_addr(). Then, the set_ethernet_addr() could
set the MAC address by calling rtl8152_set_mac_address()
later.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 80b0179..b5ff933 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -975,6 +975,23 @@ 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 int rtl8152_set_mac_address(struct net_device *netdev, void *p)
+{
+	struct r8152 *tp = netdev_priv(netdev);
+	struct sockaddr *addr = p;
+
+	if (!is_valid_ether_addr(addr->sa_data))
+		return -EADDRNOTAVAIL;
+
+	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
+	pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data);
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
+
+	return 0;
+}
+
 static inline void set_ethernet_addr(struct r8152 *tp)
 {
 	struct net_device *dev = tp->netdev;
@@ -1003,23 +1020,6 @@ static inline void set_ethernet_addr(struct r8152 *tp)
 	}
 }
 
-static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
-{
-	struct r8152 *tp = netdev_priv(netdev);
-	struct sockaddr *addr = p;
-
-	if (!is_valid_ether_addr(addr->sa_data))
-		return -EADDRNOTAVAIL;
-
-	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
-
-	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
-	pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data);
-	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
-
-	return 0;
-}
-
 static void read_bulk_callback(struct urb *urb)
 {
 	struct net_device *netdev;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next 2/2] r8152: use eth_hw_addr_random
  2014-09-02  9:55 [PATCH net-next 0/2] r8152: random MAC address Hayes Wang
  2014-09-02  9:55 ` [PATCH net-next 1/2] r8152: change the location of rtl8152_set_mac_address Hayes Wang
@ 2014-09-02  9:55 ` Hayes Wang
  2014-09-02 12:53   ` Sergei Shtylyov
  2014-09-03  2:59 ` [PATCH net-next v2 0/2] r8152: random MAC address Hayes Wang
       [not found] ` <1394712342-15778-32-Taiwan-albertk@realtek.com>
  3 siblings, 1 reply; 9+ messages in thread
From: Hayes Wang @ 2014-09-02  9:55 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb

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 <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index b5ff933..2bc1b8d 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -992,32 +992,41 @@ 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 %02x:%02x:%02x:%02x:%02x:%02x\n",
+			  sa.sa_data[0], sa.sa_data[1], sa.sa_data[2],
+			  sa.sa_data[3], sa.sa_data[4], sa.sa_data[5]);
+		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 %02x:%02x:%02x:%02x:%02x:%02x\n",
+			   sa.sa_data[0], sa.sa_data[1], sa.sa_data[2],
+			   sa.sa_data[3], sa.sa_data[4], sa.sa_data[5]);
 	} 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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next 2/2] r8152: use eth_hw_addr_random
  2014-09-02  9:55 ` [PATCH net-next 2/2] r8152: use eth_hw_addr_random Hayes Wang
@ 2014-09-02 12:53   ` Sergei Shtylyov
  0 siblings, 0 replies; 9+ messages in thread
From: Sergei Shtylyov @ 2014-09-02 12:53 UTC (permalink / raw)
  To: Hayes Wang, netdev; +Cc: nic_swsd, linux-kernel, linux-usb

Hello.

On 9/2/2014 1:55 PM, Hayes Wang wrote:

> 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 <hayeswang@realtek.com>
> ---
>   drivers/net/usb/r8152.c | 39 ++++++++++++++++++++++++---------------
>   1 file changed, 24 insertions(+), 15 deletions(-)

> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index b5ff933..2bc1b8d 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -992,32 +992,41 @@ 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 %02x:%02x:%02x:%02x:%02x:%02x\n",

   There's now "%pM" format specifier for printing a MAC address.

> +			  sa.sa_data[0], sa.sa_data[1], sa.sa_data[2],
> +			  sa.sa_data[3], sa.sa_data[4], sa.sa_data[5]);
> +		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 %02x:%02x:%02x:%02x:%02x:%02x\n",

    Likewise.

WBR, Sergei

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net-next v2 0/2] r8152: random MAC address
  2014-09-02  9:55 [PATCH net-next 0/2] r8152: random MAC address Hayes Wang
  2014-09-02  9:55 ` [PATCH net-next 1/2] r8152: change the location of rtl8152_set_mac_address Hayes Wang
  2014-09-02  9:55 ` [PATCH net-next 2/2] r8152: use eth_hw_addr_random Hayes Wang
@ 2014-09-03  2:59 ` Hayes Wang
  2014-09-03  2:59   ` [PATCH net-next v2 1/2] r8152: change the location of rtl8152_set_mac_address Hayes Wang
  2014-09-03  2:59   ` [PATCH net-next v2 2/2] r8152: use eth_hw_addr_random Hayes Wang
       [not found] ` <1394712342-15778-32-Taiwan-albertk@realtek.com>
  3 siblings, 2 replies; 9+ messages in thread
From: Hayes Wang @ 2014-09-03  2:59 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb

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

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

Hayes Wang (2):
  r8152: change the location of rtl8152_set_mac_address
  r8152: use eth_hw_addr_random

 drivers/net/usb/r8152.c | 65 ++++++++++++++++++++++++++++---------------------
 1 file changed, 37 insertions(+), 28 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net-next v2 1/2] r8152: change the location of rtl8152_set_mac_address
  2014-09-03  2:59 ` [PATCH net-next v2 0/2] r8152: random MAC address Hayes Wang
@ 2014-09-03  2:59   ` Hayes Wang
  2014-09-03  2:59   ` [PATCH net-next v2 2/2] r8152: use eth_hw_addr_random Hayes Wang
  1 sibling, 0 replies; 9+ messages in thread
From: Hayes Wang @ 2014-09-03  2:59 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb

Exchange the location of rtl8152_set_mac_address() and
set_ethernet_addr(). Then, the set_ethernet_addr() could
set the MAC address by calling rtl8152_set_mac_address()
later.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 80b0179..b5ff933 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -975,6 +975,23 @@ 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 int rtl8152_set_mac_address(struct net_device *netdev, void *p)
+{
+	struct r8152 *tp = netdev_priv(netdev);
+	struct sockaddr *addr = p;
+
+	if (!is_valid_ether_addr(addr->sa_data))
+		return -EADDRNOTAVAIL;
+
+	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
+	pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data);
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
+
+	return 0;
+}
+
 static inline void set_ethernet_addr(struct r8152 *tp)
 {
 	struct net_device *dev = tp->netdev;
@@ -1003,23 +1020,6 @@ static inline void set_ethernet_addr(struct r8152 *tp)
 	}
 }
 
-static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
-{
-	struct r8152 *tp = netdev_priv(netdev);
-	struct sockaddr *addr = p;
-
-	if (!is_valid_ether_addr(addr->sa_data))
-		return -EADDRNOTAVAIL;
-
-	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
-
-	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
-	pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data);
-	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
-
-	return 0;
-}
-
 static void read_bulk_callback(struct urb *urb)
 {
 	struct net_device *netdev;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v2 2/2] r8152: use eth_hw_addr_random
  2014-09-03  2:59 ` [PATCH net-next v2 0/2] r8152: random MAC address Hayes Wang
  2014-09-03  2:59   ` [PATCH net-next v2 1/2] r8152: change the location of rtl8152_set_mac_address Hayes Wang
@ 2014-09-03  2:59   ` Hayes Wang
       [not found]     ` <1394712342-15778-31-Taiwan-albertk-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
  1 sibling, 1 reply; 9+ messages in thread
From: Hayes Wang @ 2014-09-03  2:59 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb

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 <hayeswang@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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next v2 2/2] r8152: use eth_hw_addr_random
       [not found]     ` <1394712342-15778-31-Taiwan-albertk-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
@ 2014-09-03  8:33       ` Bjørn Mork
  0 siblings, 0 replies; 9+ messages in thread
From: Bjørn Mork @ 2014-09-03  8:33 UTC (permalink / raw)
  To: Hayes Wang
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, nic_swsd-Rasf1IRRPZFBDgjK7y7TUQ,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA

Hayes Wang <hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org> 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-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next v3 0/2] r8152: random MAC address
       [not found] ` <1394712342-15778-32-Taiwan-albertk@realtek.com>
@ 2014-09-05 19:18   ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2014-09-05 19:18 UTC (permalink / raw)
  To: hayeswang; +Cc: netdev, nic_swsd, linux-kernel, linux-usb

From: Hayes Wang <hayeswang@realtek.com>
Date: Thu, 4 Sep 2014 16:15:40 +0800

> 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.

Series applied, thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-09-05 19:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-02  9:55 [PATCH net-next 0/2] r8152: random MAC address Hayes Wang
2014-09-02  9:55 ` [PATCH net-next 1/2] r8152: change the location of rtl8152_set_mac_address Hayes Wang
2014-09-02  9:55 ` [PATCH net-next 2/2] r8152: use eth_hw_addr_random Hayes Wang
2014-09-02 12:53   ` Sergei Shtylyov
2014-09-03  2:59 ` [PATCH net-next v2 0/2] r8152: random MAC address Hayes Wang
2014-09-03  2:59   ` [PATCH net-next v2 1/2] r8152: change the location of rtl8152_set_mac_address Hayes Wang
2014-09-03  2:59   ` [PATCH net-next v2 2/2] r8152: use eth_hw_addr_random Hayes Wang
     [not found]     ` <1394712342-15778-31-Taiwan-albertk-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-09-03  8:33       ` Bjørn Mork
     [not found] ` <1394712342-15778-32-Taiwan-albertk@realtek.com>
2014-09-05 19:18   ` [PATCH net-next v3 0/2] r8152: random MAC address 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).