Netdev List
 help / color / mirror / Atom feed
* Re: [PATCH net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions
From: Joe Perches @ 2018-07-27 20:04 UTC (permalink / raw)
  To: Ivan Khoronzhuk
  Cc: grygorii.strashko, davem, linux-omap, netdev, linux-kernel
In-Reply-To: <20180727193641.GA2619@khorivan>

On Fri, 2018-07-27 at 22:36 +0300, Ivan Khoronzhuk wrote:
> On Fri, Jul 27, 2018 at 12:21:07PM -0700, Joe Perches wrote:
> > On Fri, 2018-07-27 at 22:13 +0300, Ivan Khoronzhuk wrote:
> > > Replace ugly macroses on functions.
> > 
> > Careful, see below.
> > 
> > > diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
> > 
> > []
> > > @@ -565,40 +565,40 @@ static const struct cpsw_stats cpsw_gstrings_ch_stats[] = {
> > >  				(func)(slave++, ##arg);			\
> > >  	} while (0)
> > > 
> > > -#define cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb)		\
> > > -	do {								\
> > > -		if (!cpsw->data.dual_emac)				\
> > > -			break;						\
> > > -		if (CPDMA_RX_SOURCE_PORT(status) == 1) {		\
> > > -			ndev = cpsw->slaves[0].ndev;			\
> > > -			skb->dev = ndev;				\
> > > -		} else if (CPDMA_RX_SOURCE_PORT(status) == 2) {		\
> > > -			ndev = cpsw->slaves[1].ndev;			\
> > > -			skb->dev = ndev;				\
> > > -		}							\
> > > -	} while (0)
> > > -#define cpsw_add_mcast(cpsw, priv, addr)				\
> > > -	do {								\
> > > -		if (cpsw->data.dual_emac) {				\
> > > -			struct cpsw_slave *slave = cpsw->slaves +	\
> > > -						priv->emac_port;	\
> > > -			int slave_port = cpsw_get_slave_port(		\
> > > -						slave->slave_num);	\
> > > -			cpsw_ale_add_mcast(cpsw->ale, addr,		\
> > > -				1 << slave_port | ALE_PORT_HOST,	\
> > > -				ALE_VLAN, slave->port_vlan, 0);		\
> > > -		} else {						\
> > > -			cpsw_ale_add_mcast(cpsw->ale, addr,		\
> > > -				ALE_ALL_PORTS,				\
> > > -				0, 0, 0);				\
> > > -		}							\
> > > -	} while (0)
> > > -
> > >  static inline int cpsw_get_slave_port(u32 slave_num)
> > >  {
> > >  	return slave_num + 1;
> > >  }
> > > 
> > > +static inline void cpsw_src_port_detect(struct cpsw_common *cpsw, int status,
> > > +					struct sk_buff *skb)
> > > +{
> > > +	if (!cpsw->data.dual_emac)
> > > +		return;
> > > +
> > > +	if (CPDMA_RX_SOURCE_PORT(status) == 1)
> > > +		skb->dev = cpsw->slaves[0].ndev;
> > > +	else if (CPDMA_RX_SOURCE_PORT(status) == 2)
> > > +		skb->dev = cpsw->slaves[1].ndev;
> > > +}
> > 
> > perhaps better as a switch/case
> 
> not better, it's shorter.

True for the source code but it compiles to more object code.

$ cat foo.c
struct cpsw_common {
	struct {
		int dual_emac;
	} data;
	struct {
		int ndev;
	} slaves[2];
};

struct sk_buff {
	int dev;
};

#define CPDMA_RX_SOURCE_PORT(__status__)        ((__status__ >> 16) & 0x7)

#if defined SWITCH

void foo(struct cpsw_common *cpsw, int status, struct sk_buff *skb)
{
	if (!cpsw->data.dual_emac)
		return;

	switch (CPDMA_RX_SOURCE_PORT(status)) {
	case 1:
		skb->dev = cpsw->slaves[0].ndev;
		break;
	case 2:
		skb->dev = cpsw->slaves[1].ndev;
		break;
	}
}

#else

void foo(struct cpsw_common *cpsw, int status, struct sk_buff *skb)
{
	if (!cpsw->data.dual_emac)
		return;

	if (CPDMA_RX_SOURCE_PORT(status) == 1)
		skb->dev = cpsw->slaves[0].ndev;
	else if (CPDMA_RX_SOURCE_PORT(status) == 2)
		skb->dev = cpsw->slaves[1].ndev;
}

#endif
$ gcc -c -O2 -DSWITCH foo.c
$ size foo.o
   text	   data	    bss	    dec	    hex	filename
     94	      0	      0	     94	     5e	foo.o
$ objdump -d foo.o

foo.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <foo>:
   0:	8b 07                	mov    (%rdi),%eax
   2:	85 c0                	test   %eax,%eax
   4:	74 15                	je     1b <foo+0x1b>
   6:	c1 fe 10             	sar    $0x10,%esi
   9:	83 e6 07             	and    $0x7,%esi
   c:	83 fe 01             	cmp    $0x1,%esi
   f:	74 17                	je     28 <foo+0x28>
  11:	83 fe 02             	cmp    $0x2,%esi
  14:	75 0a                	jne    20 <foo+0x20>
  16:	8b 47 08             	mov    0x8(%rdi),%eax
  19:	89 02                	mov    %eax,(%rdx)
  1b:	f3 c3                	repz retq 
  1d:	0f 1f 00             	nopl   (%rax)
  20:	f3 c3                	repz retq 
  22:	66 0f 1f 44 00 00    	nopw   0x0(%rax,%rax,1)
  28:	8b 47 04             	mov    0x4(%rdi),%eax
  2b:	89 02                	mov    %eax,(%rdx)
  2d:	c3                   	retq   
$ gcc -c -O2 foo.c
$ size foo.o
   text	   data	    bss	    dec	    hex	filename
    102	      0	      0	    102	     66	foo.o
$ objdump -d foo.o

foo.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <foo>:
   0:	8b 07                	mov    (%rdi),%eax
   2:	85 c0                	test   %eax,%eax
   4:	74 10                	je     16 <foo+0x16>
   6:	c1 fe 10             	sar    $0x10,%esi
   9:	83 e6 07             	and    $0x7,%esi
   c:	83 fe 01             	cmp    $0x1,%esi
   f:	74 0f                	je     20 <foo+0x20>
  11:	83 fe 02             	cmp    $0x2,%esi
  14:	74 1a                	je     30 <foo+0x30>
  16:	f3 c3                	repz retq 
  18:	0f 1f 84 00 00 00 00 	nopl   0x0(%rax,%rax,1)
  1f:	00 
  20:	8b 47 04             	mov    0x4(%rdi),%eax
  23:	89 02                	mov    %eax,(%rdx)
  25:	c3                   	retq   
  26:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
  2d:	00 00 00 
  30:	8b 47 08             	mov    0x8(%rdi),%eax
  33:	89 02                	mov    %eax,(%rdx)
  35:	c3                   	retq   

^ permalink raw reply

* Hello Dear
From: Tracy William @ 2018-07-27 18:51 UTC (permalink / raw)

In-Reply-To: <27112956.374460.1532717477218.ref@mail.yahoo.com>



Hello Dear, 

how are you today,I hope you are doing great. 

It is my great pleasure to contact you,I want to make a new and special friend,I hope you don't mind. My name is Tracy William from the United States, Am a french and English nationality. I will give you pictures and more details about my self as soon as i hear from you in my email account bellow, 

Thanks 
Tracy

^ permalink raw reply

* Re: [PATCH] net/rds/Kconfig: Correct the RDS depends
From: David Miller @ 2018-07-27 20:19 UTC (permalink / raw)
  To: anders.roxell
  Cc: santosh.shilimkar, eric.dumazet, netdev, linux-rdma, rds-devel,
	linux-kernel
In-Reply-To: <20180727131849.18488-1-anders.roxell@linaro.org>

From: Anders Roxell <anders.roxell@linaro.org>
Date: Fri, 27 Jul 2018 15:18:49 +0200

> Remove prefix 'CONFIG_' from CONFIG_IPV6
> 
> Fixes: ba7d7e2677c0 ("net/rds/Kconfig: RDS should depend on IPV6")
> Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>

Oops, applied :)

^ permalink raw reply

* Re: [PATCH net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions
From: Ivan Khoronzhuk @ 2018-07-27 20:23 UTC (permalink / raw)
  To: Joe Perches; +Cc: grygorii.strashko, davem, linux-omap, netdev, linux-kernel
In-Reply-To: <f22d3024773abbd811673c4eb957e4a5ffca1387.camel@perches.com>

On Fri, Jul 27, 2018 at 01:04:22PM -0700, Joe Perches wrote:
>On Fri, 2018-07-27 at 22:36 +0300, Ivan Khoronzhuk wrote:
>> On Fri, Jul 27, 2018 at 12:21:07PM -0700, Joe Perches wrote:
>> > On Fri, 2018-07-27 at 22:13 +0300, Ivan Khoronzhuk wrote:
>> > > Replace ugly macroses on functions.
>> >
>> > Careful, see below.
>> >
>> > > diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
>> >
>> > []
>> > > @@ -565,40 +565,40 @@ static const struct cpsw_stats cpsw_gstrings_ch_stats[] = {
>> > >  				(func)(slave++, ##arg);			\
>> > >  	} while (0)
>> > >
>> > > -#define cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb)		\
>> > > -	do {								\
>> > > -		if (!cpsw->data.dual_emac)				\
>> > > -			break;						\
>> > > -		if (CPDMA_RX_SOURCE_PORT(status) == 1) {		\
>> > > -			ndev = cpsw->slaves[0].ndev;			\
>> > > -			skb->dev = ndev;				\
>> > > -		} else if (CPDMA_RX_SOURCE_PORT(status) == 2) {		\
>> > > -			ndev = cpsw->slaves[1].ndev;			\
>> > > -			skb->dev = ndev;				\
>> > > -		}							\
>> > > -	} while (0)
>> > > -#define cpsw_add_mcast(cpsw, priv, addr)				\
>> > > -	do {								\
>> > > -		if (cpsw->data.dual_emac) {				\
>> > > -			struct cpsw_slave *slave = cpsw->slaves +	\
>> > > -						priv->emac_port;	\
>> > > -			int slave_port = cpsw_get_slave_port(		\
>> > > -						slave->slave_num);	\
>> > > -			cpsw_ale_add_mcast(cpsw->ale, addr,		\
>> > > -				1 << slave_port | ALE_PORT_HOST,	\
>> > > -				ALE_VLAN, slave->port_vlan, 0);		\
>> > > -		} else {						\
>> > > -			cpsw_ale_add_mcast(cpsw->ale, addr,		\
>> > > -				ALE_ALL_PORTS,				\
>> > > -				0, 0, 0);				\
>> > > -		}							\
>> > > -	} while (0)
>> > > -
>> > >  static inline int cpsw_get_slave_port(u32 slave_num)
>> > >  {
>> > >  	return slave_num + 1;
>> > >  }
>> > >
>> > > +static inline void cpsw_src_port_detect(struct cpsw_common *cpsw, int status,
>> > > +					struct sk_buff *skb)
>> > > +{
>> > > +	if (!cpsw->data.dual_emac)
>> > > +		return;
>> > > +
>> > > +	if (CPDMA_RX_SOURCE_PORT(status) == 1)
>> > > +		skb->dev = cpsw->slaves[0].ndev;
>> > > +	else if (CPDMA_RX_SOURCE_PORT(status) == 2)
>> > > +		skb->dev = cpsw->slaves[1].ndev;
>> > > +}
>> >
>> > perhaps better as a switch/case
>>
>> not better, it's shorter.
>
>True for the source code but it compiles to more object code.
>
>$ cat foo.c
>struct cpsw_common {
>	struct {
>		int dual_emac;
>	} data;
>	struct {
>		int ndev;
>	} slaves[2];
>};
>
>struct sk_buff {
>	int dev;
>};
>
>#define CPDMA_RX_SOURCE_PORT(__status__)        ((__status__ >> 16) & 0x7)
>
>#if defined SWITCH
>
>void foo(struct cpsw_common *cpsw, int status, struct sk_buff *skb)
>{
>	if (!cpsw->data.dual_emac)
>		return;
>
>	switch (CPDMA_RX_SOURCE_PORT(status)) {
>	case 1:
>		skb->dev = cpsw->slaves[0].ndev;
>		break;
>	case 2:
>		skb->dev = cpsw->slaves[1].ndev;
>		break;
>	}
>}
>
>#else
>
>void foo(struct cpsw_common *cpsw, int status, struct sk_buff *skb)
>{
>	if (!cpsw->data.dual_emac)
>		return;
>
>	if (CPDMA_RX_SOURCE_PORT(status) == 1)
>		skb->dev = cpsw->slaves[0].ndev;
>	else if (CPDMA_RX_SOURCE_PORT(status) == 2)
>		skb->dev = cpsw->slaves[1].ndev;
>}
>
>#endif
>$ gcc -c -O2 -DSWITCH foo.c
>$ size foo.o
>   text	   data	    bss	    dec	    hex	filename
>     94	      0	      0	     94	     5e	foo.o
>$ objdump -d foo.o
>
>foo.o:     file format elf64-x86-64
>
>
>Disassembly of section .text:
>
>0000000000000000 <foo>:
>   0:	8b 07                	mov    (%rdi),%eax
>   2:	85 c0                	test   %eax,%eax
>   4:	74 15                	je     1b <foo+0x1b>
>   6:	c1 fe 10             	sar    $0x10,%esi
>   9:	83 e6 07             	and    $0x7,%esi
>   c:	83 fe 01             	cmp    $0x1,%esi
>   f:	74 17                	je     28 <foo+0x28>
>  11:	83 fe 02             	cmp    $0x2,%esi
>  14:	75 0a                	jne    20 <foo+0x20>
>  16:	8b 47 08             	mov    0x8(%rdi),%eax
>  19:	89 02                	mov    %eax,(%rdx)
>  1b:	f3 c3                	repz retq
>  1d:	0f 1f 00             	nopl   (%rax)
>  20:	f3 c3                	repz retq
>  22:	66 0f 1f 44 00 00    	nopw   0x0(%rax,%rax,1)
>  28:	8b 47 04             	mov    0x4(%rdi),%eax
>  2b:	89 02                	mov    %eax,(%rdx)
>  2d:	c3                   	retq
>$ gcc -c -O2 foo.c
>$ size foo.o
>   text	   data	    bss	    dec	    hex	filename
>    102	      0	      0	    102	     66	foo.o
>$ objdump -d foo.o
>
>foo.o:     file format elf64-x86-64
>
>
>Disassembly of section .text:
>
>0000000000000000 <foo>:
>   0:	8b 07                	mov    (%rdi),%eax
>   2:	85 c0                	test   %eax,%eax
>   4:	74 10                	je     16 <foo+0x16>
>   6:	c1 fe 10             	sar    $0x10,%esi
>   9:	83 e6 07             	and    $0x7,%esi
>   c:	83 fe 01             	cmp    $0x1,%esi
>   f:	74 0f                	je     20 <foo+0x20>
>  11:	83 fe 02             	cmp    $0x2,%esi
>  14:	74 1a                	je     30 <foo+0x30>
>  16:	f3 c3                	repz retq
>  18:	0f 1f 84 00 00 00 00 	nopl   0x0(%rax,%rax,1)
>  1f:	00
>  20:	8b 47 04             	mov    0x4(%rdi),%eax
>  23:	89 02                	mov    %eax,(%rdx)
>  25:	c3                   	retq
>  26:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
>  2d:	00 00 00
>  30:	8b 47 08             	mov    0x8(%rdi),%eax
>  33:	89 02                	mov    %eax,(%rdx)
>  35:	c3                   	retq
>
>

This driver, mainly used for ARM

For ARM, situation a little bit different:
$ arm-linux-gnueabihf-gcc -c -O2 -DSWITCH foo.c
$ size foo.o
   text	   data	    bss	    dec	    hex	filename
     32	      0	      0	     32	     20	foo.o

$ arm-linux-gnueabihf-objdump -d foo.o

foo.o:     file format elf32-littlearm


Disassembly of section .text:

00000000 <foo>:
   0:	6803      	ldr	r3, [r0, #0]
   2:	b143      	cbz	r3, 16 <foo+0x16>
   4:	f3c1 4102 	ubfx	r1, r1, #16, #3
   8:	2901      	cmp	r1, #1
   a:	d005      	beq.n	18 <foo+0x18>
   c:	2902      	cmp	r1, #2
   e:	d000      	beq.n	12 <foo+0x12>
  10:	4770      	bx	lr
  12:	6883      	ldr	r3, [r0, #8]
  14:	6013      	str	r3, [r2, #0]
  16:	4770      	bx	lr
  18:	6843      	ldr	r3, [r0, #4]
  1a:	6013      	str	r3, [r2, #0]
  1c:	4770      	bx	lr
  1e:	bf00      	nop



$ arm-linux-gnueabihf-gcc -c -O2 foo.c
$ size foo.o
   text	   data	    bss	    dec	    hex	filename
     28	      0	      0	     28	     1c	foo.o

$ arm-linux-gnueabihf-objdump -d foo.o

foo.o:     file format elf32-littlearm


Disassembly of section .text:

00000000 <foo>:
   0:	6803      	ldr	r3, [r0, #0]
   2:	b13b      	cbz	r3, 14 <foo+0x14>
   4:	f3c1 4102 	ubfx	r1, r1, #16, #3
   8:	2901      	cmp	r1, #1
   a:	d004      	beq.n	16 <foo+0x16>
   c:	2902      	cmp	r1, #2
   e:	bf04      	itt	eq
  10:	6883      	ldreq	r3, [r0, #8]
  12:	6013      	streq	r3, [r2, #0]
  14:	4770      	bx	lr
  16:	6843      	ldr	r3, [r0, #4]
  18:	6013      	str	r3, [r2, #0]
  1a:	4770      	bx	lr

So, it's shorter.

-- 
Regards,
Ivan Khoronzhuk

^ permalink raw reply

* Re: [PATCH net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions
From: Joe Perches @ 2018-07-27 20:29 UTC (permalink / raw)
  To: Ivan Khoronzhuk
  Cc: grygorii.strashko, davem, linux-omap, netdev, linux-kernel
In-Reply-To: <20180727202348.GC2619@khorivan>

On Fri, 2018-07-27 at 23:23 +0300, Ivan Khoronzhuk wrote:
> For ARM, situation a little bit different:
> $ arm-linux-gnueabihf-gcc -c -O2 -DSWITCH foo.c
> $ size foo.o
>    text	   data	    bss	    dec	    hex	filename
>      32	      0	      0	     32	     20	foo.o
[]
> $ arm-linux-gnueabihf-gcc -c -O2 foo.c
> $ size foo.o
>    text	   data	    bss	    dec	    hex	filename
>      28	      0	      0	     28	     1c	foo.o
[]
> So, it's shorter.

No worries.

I was kinda surprised the object code wasn't identical anyway.

cheers, Joe

^ permalink raw reply

* Re: [PATCH net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions
From: Andrew Lunn @ 2018-07-27 20:32 UTC (permalink / raw)
  To: Ivan Khoronzhuk
  Cc: grygorii.strashko, davem, linux-omap, netdev, linux-kernel
In-Reply-To: <20180727191318.18698-1-ivan.khoronzhuk@linaro.org>

> +static inline void cpsw_src_port_detect(struct cpsw_common *cpsw, int status,
> +					struct sk_buff *skb)

Please don't use inline. Let the compiler decide.

       Andrew

^ permalink raw reply

* [PATCH net-next] Implement a rtnetlink device which simulates wifi.
From: Cody Schuffelen @ 2018-07-25  0:10 UTC (permalink / raw)


The device added here is used through "ip link add ... type virt_wifi"
The intention is to take over an existing network device and produce a
new one that appears like a wireless connection, returning enough canned
responses to nl80211 to satisfy a standard network manager. If
necessary, it can also be set up one step removed from an existing
network device, such as through a vlan/80211Q or macvlan connection to
not disrupt the existing network interface.

This is being used for Google's Remote Android Virtual Device project,
which runs Android devices in virtual machines. The standard network
interfaces provided inside the virtual machines are all ethernet.
However, Android is not interested in ethernet devices and would rather
connect to a wireless interface. This patch allows the virtual machine
guest to treat one of its network connections as wireless rather than
ethernet, satisfying Android's network connection requirements.

We believe this is a generally useful driver for simulating wireless
network connections in other environments where a wireless connection is
desired by some userspace process but is not available. Future work can
also include exporting the wireless control plane to userspace, so the
device can configure the behavior of the simulated wireless network
itself.

This is distinct from other testing efforts such as mac80211_hwsim by
being a cfg80211 device instead of mac80211 device, allowing straight
pass-through on the data plane instead of forcing packaging of ethernet
data into mac80211 frames.

Signed-off-by: A. Cody Schuffelen <schuffelen@google.com>
Acked-by: Alistair Strachan <astrachan@google.com>
Acked-by: Greg Hartman <ghartman@google.com>
---
 drivers/net/wireless/Kconfig     |   7 +
 drivers/net/wireless/Makefile    |   2 +
 drivers/net/wireless/virt_wifi.c | 544 +++++++++++++++++++++++++++++++
 3 files changed, 553 insertions(+)
 create mode 100644 drivers/net/wireless/virt_wifi.c

diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 166920ae23f8..1781d8a7f05a 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -114,4 +114,11 @@ config USB_NET_RNDIS_WLAN
 
 	  If you choose to build a module, it'll be called rndis_wlan.
 
+config VIRT_WIFI
+	tristate "Wifi wrapper for ethernet drivers"
+	default n
+	---help---
+	  This option adds support for ethernet connections to appear as if they
+	  are wifi connections through a special rtnetlink device.
+
 endif # WLAN
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 7fc96306712a..6cfe74515c95 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -27,3 +27,5 @@ obj-$(CONFIG_PCMCIA_WL3501)	+= wl3501_cs.o
 obj-$(CONFIG_USB_NET_RNDIS_WLAN)	+= rndis_wlan.o
 
 obj-$(CONFIG_MAC80211_HWSIM)	+= mac80211_hwsim.o
+
+obj-$(CONFIG_VIRT_WIFI)	+= virt_wifi.o
diff --git a/drivers/net/wireless/virt_wifi.c b/drivers/net/wireless/virt_wifi.c
new file mode 100644
index 000000000000..602bf462b444
--- /dev/null
+++ b/drivers/net/wireless/virt_wifi.c
@@ -0,0 +1,544 @@
+// SPDX-License-Identifier: GPL-2.0
+/* drivers/net/wireless/virt_wifi.c
+ *
+ * A fake implementation of cfg80211_ops that can be tacked on to an ethernet
+ * net_device to make it appear as a wireless connection.
+ *
+ * Copyright (C) 2018 Google, Inc.
+ *
+ * Author: schuffelen@google.com
+ */
+
+#include <net/cfg80211.h>
+#include <net/rtnetlink.h>
+#include <linux/etherdevice.h>
+#include <linux/module.h>
+
+struct virt_wifi_priv {
+	bool being_deleted;
+	struct cfg80211_scan_request *scan_request;
+	struct delayed_work scan_result;
+	struct delayed_work scan_complete;
+};
+
+static struct ieee80211_channel channel = {
+	.band = NL80211_BAND_5GHZ,
+	.center_freq = 5500,
+	.hw_value = 5500,
+
+	.flags = 0, /* ieee80211_channel_flags */
+	.max_antenna_gain = 20,
+	.max_power = 5500,
+	.max_reg_power = 9999,
+};
+
+static struct ieee80211_rate bitrate = {
+	.flags = IEEE80211_RATE_SHORT_PREAMBLE, /* ieee80211_rate_flags */
+	.bitrate = 1000,
+};
+
+static struct ieee80211_supported_band band_5ghz = {
+	.channels = &channel,
+	.bitrates = &bitrate,
+	.band = NL80211_BAND_5GHZ,
+	.n_channels = 1,
+	.n_bitrates = 1,
+};
+
+static struct cfg80211_inform_bss mock_inform_bss = {
+	/* ieee80211_channel* */ .chan = &channel,
+	/* nl80211_bss_scan_width */ .scan_width = NL80211_BSS_CHAN_WIDTH_20,
+	/* s32 */ .signal = 99,
+};
+
+static u8 fake_router_bssid[] = {4, 4, 4, 4, 4, 4};
+
+static int virt_wifi_scan(struct wiphy *wiphy,
+			  struct cfg80211_scan_request *request)
+{
+	struct virt_wifi_priv *priv = wiphy_priv(wiphy);
+
+	wiphy_debug(wiphy, "scan\n");
+
+	if (priv->scan_request || priv->being_deleted)
+		return -EBUSY;
+
+	if (request->ie_len > 0)
+		wiphy_debug(wiphy, "scan: first ie: %d\n", (int)request->ie[0]);
+
+	if (request->n_ssids > 0) {
+		int i;
+		u8 request_ssid_copy[IEEE80211_MAX_SSID_LEN + 1];
+
+		for (i = 0; i < request->n_ssids; i++) {
+			strncpy(request_ssid_copy, request->ssids[i].ssid,
+				request->ssids[i].ssid_len);
+			request_ssid_copy[request->ssids[i].ssid_len] = 0;
+			wiphy_debug(wiphy, "scan: ssid: %s\n",
+				    request_ssid_copy);
+		}
+	}
+
+	priv->scan_request = request;
+	schedule_delayed_work(&priv->scan_result, HZ / 100);
+
+	return 0;
+}
+
+static void virt_wifi_scan_result(struct work_struct *work)
+{
+	struct virt_wifi_priv *priv =
+		container_of(work, struct virt_wifi_priv,
+			     scan_result.work);
+	struct wiphy *wiphy = priv_to_wiphy(priv);
+	char ssid[] = "__VirtWifi";
+	struct cfg80211_bss *informed_bss;
+
+	mock_inform_bss.boottime_ns = ktime_get_boot_ns();
+
+	ssid[0] = WLAN_EID_SSID;
+	/* size of the array minus null terminator, length byte, tag byte */
+	ssid[1] = sizeof(ssid) - 3;
+
+	informed_bss =
+		cfg80211_inform_bss_data(wiphy, &mock_inform_bss,
+					 CFG80211_BSS_FTYPE_PRESP,
+					 fake_router_bssid,
+					 mock_inform_bss.boottime_ns,
+					 WLAN_CAPABILITY_ESS, 0, ssid,
+					 /* Truncate before the terminator. */
+					 sizeof(ssid) - 1, GFP_KERNEL);
+	cfg80211_put_bss(wiphy, informed_bss);
+
+	informed_bss =
+		cfg80211_inform_bss_data(wiphy, &mock_inform_bss,
+					 CFG80211_BSS_FTYPE_BEACON,
+					 fake_router_bssid,
+					 mock_inform_bss.boottime_ns,
+					 WLAN_CAPABILITY_ESS, 0, ssid,
+					 /* Truncate before the terminator. */
+					 sizeof(ssid) - 1, GFP_KERNEL);
+	cfg80211_put_bss(wiphy, informed_bss);
+
+	schedule_delayed_work(&priv->scan_complete, HZ / 100);
+}
+
+static void virt_wifi_scan_complete(struct work_struct *work)
+{
+	struct virt_wifi_priv *priv =
+		container_of(work, struct virt_wifi_priv,
+			     scan_complete.work);
+	struct cfg80211_scan_info scan_info = {
+		.aborted = false,
+	};
+
+	cfg80211_scan_done(priv->scan_request, &scan_info);
+	priv->scan_request = NULL;
+}
+
+static struct ieee80211_mgmt auth_mgmt_frame = {
+	.frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT
+				     | IEEE80211_STYPE_AUTH),
+	.duration = cpu_to_le16(1), /* ??? */
+	.u = {
+		.auth = {
+			.auth_alg = WLAN_AUTH_OPEN,
+			/* auth request has 1, auth response has 2 */
+			.auth_transaction = cpu_to_le16(2),
+		},
+	},
+};
+
+static int virt_wifi_auth(struct wiphy *wiphy,  struct net_device *dev,
+			  struct cfg80211_auth_request *req)
+{
+	wiphy_debug(wiphy, "auth\n");
+	memcpy(auth_mgmt_frame.da, dev->dev_addr, dev->addr_len);
+	memcpy(auth_mgmt_frame.sa, fake_router_bssid,
+	       sizeof(fake_router_bssid));
+	memcpy(auth_mgmt_frame.bssid, fake_router_bssid,
+	       sizeof(fake_router_bssid));
+	/* Must call cfg80211_rx_mlme_mgmt to notify about the response to this.
+	 * This must hold the mutex for the wedev while calling the function.
+	 * Luckily the nl80211 code invoking this already holds that mutex.
+	 */
+	cfg80211_rx_mlme_mgmt(dev, (const u8 *)&auth_mgmt_frame,
+			      sizeof(auth_mgmt_frame));
+	return 0;
+}
+
+static struct ieee80211_mgmt assoc_mgmt_frame = {
+	.frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT
+				     | IEEE80211_STYPE_ASSOC_RESP),
+	.duration = cpu_to_le16(1), /* ??? */
+	.u = {
+		.assoc_resp = {
+			.capab_info = cpu_to_le16(1),
+			.status_code = cpu_to_le16(0),
+			.aid = cpu_to_le16(2), /* "association id" */
+		},
+	},
+};
+
+static int virt_wifi_assoc(struct wiphy *wiphy, struct net_device *dev,
+			   struct cfg80211_assoc_request *req)
+{
+	wiphy_debug(wiphy, "assoc\n");
+	memcpy(assoc_mgmt_frame.da, dev->dev_addr, dev->addr_len);
+	memcpy(assoc_mgmt_frame.sa, fake_router_bssid,
+	       sizeof(fake_router_bssid));
+	memcpy(assoc_mgmt_frame.bssid, fake_router_bssid,
+	       sizeof(fake_router_bssid));
+	/* Must call cfg80211_rx_assoc_resp to notify about the response to
+	 * this. This must hold the mutex for the wedev while calling the
+	 * function. Luckily the nl80211 code invoking this already holds that
+	 * mutex.
+	 */
+	cfg80211_rx_assoc_resp(dev, req->bss, (const u8 *)&assoc_mgmt_frame,
+			       sizeof(assoc_mgmt_frame), -1);
+	return 0;
+}
+
+static struct ieee80211_mgmt deauth_mgmt_frame = {
+	.frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT
+				     | IEEE80211_STYPE_DEAUTH),
+	.duration = cpu_to_le16(1), /* ??? */
+};
+
+static int virt_wifi_deauth(struct wiphy *wiphy, struct net_device *dev,
+			    struct cfg80211_deauth_request *req)
+{
+	wiphy_debug(wiphy, "deauth\n");
+	memcpy(deauth_mgmt_frame.da, dev->dev_addr, dev->addr_len);
+	memcpy(deauth_mgmt_frame.sa, fake_router_bssid,
+	       sizeof(fake_router_bssid));
+	memcpy(deauth_mgmt_frame.bssid, fake_router_bssid,
+	       sizeof(fake_router_bssid));
+	deauth_mgmt_frame.u.deauth.reason_code = cpu_to_le16(req->reason_code);
+	/* Must call cfg80211_rx_mlme_mgmt to notify about the response to this.
+	 * This must hold the mutex for the wedev while calling the function.
+	 * Luckily the nl80211 code invoking this already holds that mutex.
+	 */
+	cfg80211_rx_mlme_mgmt(dev, (const u8 *)&deauth_mgmt_frame,
+			      sizeof(auth_mgmt_frame));
+	return 0;
+}
+
+static struct ieee80211_mgmt disassoc_mgmt_frame = {
+	.frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT
+				     | IEEE80211_STYPE_DISASSOC),
+	.duration = cpu_to_le16(1), /* ??? */
+};
+
+static int virt_wifi_disassoc(struct wiphy *wiphy, struct net_device *dev,
+			      struct cfg80211_disassoc_request *req)
+{
+	wiphy_debug(wiphy, "disassoc\n");
+	memcpy(disassoc_mgmt_frame.da, dev->dev_addr, dev->addr_len);
+	memcpy(disassoc_mgmt_frame.sa, fake_router_bssid,
+	       sizeof(fake_router_bssid));
+	memcpy(disassoc_mgmt_frame.bssid, fake_router_bssid,
+	       sizeof(fake_router_bssid));
+	disassoc_mgmt_frame.u.disassoc.reason_code =
+		cpu_to_le16(req->reason_code);
+	/* Must call cfg80211_rx_mlme_mgmt to notify about the response to this.
+	 * This must hold the mutex for the wedev while calling the function.
+	 * Luckily the nl80211 code invoking this already holds that mutex.
+	 */
+	cfg80211_rx_mlme_mgmt(dev, (const u8 *)&disassoc_mgmt_frame,
+			      sizeof(auth_mgmt_frame));
+	return 0;
+}
+
+static int virt_wifi_get_station(struct wiphy *wiphy, struct net_device *dev,
+				 const u8 *mac, struct station_info *sinfo)
+{
+	wiphy_debug(wiphy, "get_station\n");
+	/* Only the values used by netlink_utils.cpp. */
+	sinfo->filled = BIT(NL80211_STA_INFO_TX_PACKETS) |
+		BIT(NL80211_STA_INFO_TX_FAILED) | BIT(NL80211_STA_INFO_SIGNAL) |
+		BIT(NL80211_STA_INFO_TX_BITRATE);
+	sinfo->tx_packets = 1;
+	sinfo->tx_failed = 0;
+	sinfo->signal = -1; /* -1 is the maximum signal strength, somehow. */
+	sinfo->txrate = (struct rate_info) {
+		.legacy = 10000, /* units are 100kbit/s */
+	};
+	return 0;
+}
+
+static const struct cfg80211_ops virt_wifi_cfg80211_ops = {
+	.scan = virt_wifi_scan,
+
+	.auth = virt_wifi_auth,
+	.assoc = virt_wifi_assoc,
+	.deauth = virt_wifi_deauth,
+	.disassoc = virt_wifi_disassoc,
+
+	.get_station = virt_wifi_get_station,
+};
+
+static struct wireless_dev *virt_wireless_dev(struct device *device)
+{
+	struct wireless_dev *wdev;
+	struct wiphy *wiphy;
+	struct virt_wifi_priv *priv;
+
+	wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
+
+	if (!wdev)
+		return ERR_PTR(-ENOMEM);
+
+	wdev->iftype = NL80211_IFTYPE_STATION;
+	wiphy = wiphy_new(&virt_wifi_cfg80211_ops,
+			  sizeof(struct virt_wifi_priv));
+
+	if (!wiphy) {
+		kfree(wdev);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	wdev->wiphy = wiphy;
+
+	/* 100 SSIDs should be enough for anyone! */
+	wiphy->max_scan_ssids = 101;
+	wiphy->max_scan_ie_len = 1000;
+	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
+
+	wiphy->bands[NL80211_BAND_2GHZ] = NULL;
+	wiphy->bands[NL80211_BAND_5GHZ] = &band_5ghz;
+	wiphy->bands[NL80211_BAND_60GHZ] = NULL;
+
+	/* Don't worry about frequency regulations. */
+	wiphy->regulatory_flags = REGULATORY_WIPHY_SELF_MANAGED;
+	wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
+				     BIT(NL80211_IFTYPE_AP) |
+				     BIT(NL80211_IFTYPE_P2P_CLIENT) |
+				     BIT(NL80211_IFTYPE_P2P_GO) |
+				     BIT(NL80211_IFTYPE_ADHOC) |
+				     BIT(NL80211_IFTYPE_MESH_POINT) |
+				     BIT(NL80211_IFTYPE_MONITOR);
+	wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
+			    WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
+			    WIPHY_FLAG_AP_UAPSD |
+			    WIPHY_FLAG_HAS_CHANNEL_SWITCH;
+	wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
+			       NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
+			       NL80211_FEATURE_STATIC_SMPS |
+			       NL80211_FEATURE_DYNAMIC_SMPS |
+			       NL80211_FEATURE_AP_SCAN |
+			       NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
+	set_wiphy_dev(wiphy, device);
+
+	priv = wiphy_priv(wiphy);
+	priv->being_deleted = false;
+	priv->scan_request = NULL;
+	INIT_DELAYED_WORK(&priv->scan_result, virt_wifi_scan_result);
+	INIT_DELAYED_WORK(&priv->scan_complete, virt_wifi_scan_complete);
+
+	return wdev;
+}
+
+struct virt_wifi_netdev_priv {
+	struct net_device *lowerdev;
+	struct net_device *upperdev;
+	struct work_struct register_wiphy_work;
+};
+
+static netdev_tx_t virt_wifi_start_xmit(struct sk_buff *skb,
+					struct net_device *dev)
+{
+	struct virt_wifi_netdev_priv *priv = netdev_priv(dev);
+
+	skb->dev = priv->lowerdev;
+	return dev_queue_xmit(skb);
+}
+
+static const struct net_device_ops wifi_vlan_ops = {
+	.ndo_start_xmit = virt_wifi_start_xmit,
+};
+
+static void free_wiphy(struct net_device *dev)
+{
+	struct virt_wifi_netdev_priv *priv = netdev_priv(dev);
+	struct virt_wifi_priv *w_priv;
+
+	flush_work(&priv->register_wiphy_work);
+	if (dev->ieee80211_ptr && !IS_ERR(dev->ieee80211_ptr)) {
+		w_priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
+		w_priv->being_deleted = true;
+		flush_delayed_work(&w_priv->scan_result);
+		flush_delayed_work(&w_priv->scan_complete);
+
+		if (dev->ieee80211_ptr->wiphy->registered)
+			wiphy_unregister(dev->ieee80211_ptr->wiphy);
+		wiphy_free(dev->ieee80211_ptr->wiphy);
+		kfree(dev->ieee80211_ptr);
+	}
+}
+
+static void virt_wifi_setup(struct net_device *dev)
+{
+	ether_setup(dev);
+	dev->netdev_ops = &wifi_vlan_ops;
+	dev->needs_free_netdev = true;
+	dev->priv_destructor = free_wiphy;
+}
+
+/* Called under rcu_read_lock() from netif_receive_skb */
+static rx_handler_result_t virt_wifi_rx_handler(struct sk_buff **pskb)
+{
+	struct sk_buff *skb = *pskb;
+	struct virt_wifi_netdev_priv *priv =
+		rcu_dereference(skb->dev->rx_handler_data);
+
+	/* macvlan uses GFP_ATOMIC here. */
+	skb = skb_share_check(skb, GFP_ATOMIC);
+	if (!skb) {
+		dev_err(&priv->upperdev->dev, "can't skb_share_check\n");
+		return RX_HANDLER_CONSUMED;
+	}
+
+	*pskb = skb;
+	skb->dev = priv->upperdev;
+	skb->pkt_type = PACKET_HOST;
+	return RX_HANDLER_ANOTHER;
+}
+
+static void virt_wifi_register_wiphy(struct work_struct *work)
+{
+	struct virt_wifi_netdev_priv *priv =
+		container_of(work, struct virt_wifi_netdev_priv,
+			     register_wiphy_work);
+	struct wireless_dev *wdev = priv->upperdev->ieee80211_ptr;
+	int err;
+
+	err = wiphy_register(wdev->wiphy);
+	if (err < 0) {
+		dev_err(&priv->upperdev->dev, "can't wiphy_register (%d)\n",
+			err);
+
+		/* Roll back the net_device, it's not going to do wifi. */
+		rtnl_lock();
+		err = rtnl_delete_link(priv->upperdev);
+		rtnl_unlock();
+
+		/* rtnl_delete_link should only throw errors if it's not a
+		 * netlink device, but we know here it is already a virt_wifi
+		 * device.
+		 */
+		WARN_ONCE(err, "rtnl_delete_link failed on a virt_wifi device");
+	}
+}
+
+/* Called with rtnl lock held. */
+static int virt_wifi_newlink(struct net *src_net, struct net_device *dev,
+			     struct nlattr *tb[], struct nlattr *data[],
+			     struct netlink_ext_ack *extack)
+{
+	struct virt_wifi_netdev_priv *priv = netdev_priv(dev);
+	int err;
+
+	if (!tb[IFLA_LINK])
+		return -EINVAL;
+
+	priv->upperdev = dev;
+	priv->lowerdev = __dev_get_by_index(src_net,
+					    nla_get_u32(tb[IFLA_LINK]));
+
+	if (!priv->lowerdev)
+		return -ENODEV;
+	if (!tb[IFLA_MTU])
+		dev->mtu = priv->lowerdev->mtu;
+	else if (dev->mtu > priv->lowerdev->mtu)
+		return -EINVAL;
+
+	err = netdev_rx_handler_register(priv->lowerdev, virt_wifi_rx_handler,
+					 priv);
+	if (err != 0) {
+		dev_err(&priv->lowerdev->dev,
+			"can't netdev_rx_handler_register: %ld\n",
+			PTR_ERR(dev->ieee80211_ptr));
+		return err;
+	}
+
+	eth_hw_addr_inherit(dev, priv->lowerdev);
+	netif_stacked_transfer_operstate(priv->lowerdev, dev);
+
+	SET_NETDEV_DEV(dev, &priv->lowerdev->dev);
+	dev->ieee80211_ptr = virt_wireless_dev(&priv->lowerdev->dev);
+
+	if (IS_ERR(dev->ieee80211_ptr)) {
+		dev_err(&priv->lowerdev->dev, "can't init wireless: %ld\n",
+			PTR_ERR(dev->ieee80211_ptr));
+		return PTR_ERR(dev->ieee80211_ptr);
+	}
+
+	err = register_netdevice(dev);
+	if (err) {
+		dev_err(&priv->lowerdev->dev, "can't register_netdevice: %d\n",
+			err);
+		goto remove_handler;
+	}
+
+	err = netdev_upper_dev_link(priv->lowerdev, dev, extack);
+	if (err) {
+		dev_err(&priv->lowerdev->dev, "can't netdev_upper_dev_link: %d\n",
+			err);
+		goto unregister_netdev;
+	}
+
+	/* The newlink callback is invoked while holding the rtnl lock, but
+	 * register_wiphy wants to claim the rtnl lock itself.
+	 */
+	INIT_WORK(&priv->register_wiphy_work, virt_wifi_register_wiphy);
+	schedule_work(&priv->register_wiphy_work);
+
+	return 0;
+remove_handler:
+	netdev_rx_handler_unregister(priv->lowerdev);
+unregister_netdev:
+	unregister_netdevice(dev);
+
+	return err;
+}
+
+/** Called with rtnl lock held. */
+static void virt_wifi_dellink(struct net_device *dev,
+			      struct list_head *head)
+{
+	struct virt_wifi_netdev_priv *priv = netdev_priv(dev);
+
+	netdev_rx_handler_unregister(priv->lowerdev);
+	netdev_upper_dev_unlink(priv->lowerdev, dev);
+
+	unregister_netdevice_queue(dev, head);
+
+	/* Deleting the wiphy is handled in the netdev destructor. */
+}
+
+static struct rtnl_link_ops virt_wifi_link_ops = {
+	.kind		= "virt_wifi",
+	.setup		= virt_wifi_setup,
+	.newlink	= virt_wifi_newlink,
+	.dellink	= virt_wifi_dellink,
+	.priv_size	= sizeof(struct virt_wifi_netdev_priv),
+};
+
+static int __init virt_wifi_init_module(void)
+{
+	return rtnl_link_register(&virt_wifi_link_ops);
+}
+
+static void __exit virt_wifi_cleanup_module(void)
+{
+	rtnl_link_unregister(&virt_wifi_link_ops);
+}
+
+module_init(virt_wifi_init_module);
+module_exit(virt_wifi_cleanup_module);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("A. Cody Schuffelen <schuffelen@google.com>");
+MODULE_DESCRIPTION("Driver for a wireless wrapper of ethernet devices");
+MODULE_ALIAS_RTNL_LINK("virt_wifi");
-- 
2.18.0.233.g985f88cf7e-goog

^ permalink raw reply related

* Re: [PATCH net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions
From: Joe Perches @ 2018-07-27 19:21 UTC (permalink / raw)
  To: Ivan Khoronzhuk, grygorii.strashko, davem
  Cc: linux-omap, netdev, linux-kernel
In-Reply-To: <20180727191318.18698-1-ivan.khoronzhuk@linaro.org>

On Fri, 2018-07-27 at 22:13 +0300, Ivan Khoronzhuk wrote:
> Replace ugly macroses on functions.

Careful, see below.

> diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
[]
> @@ -565,40 +565,40 @@ static const struct cpsw_stats cpsw_gstrings_ch_stats[] = {
>  				(func)(slave++, ##arg);			\
>  	} while (0)
>  
> -#define cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb)		\
> -	do {								\
> -		if (!cpsw->data.dual_emac)				\
> -			break;						\
> -		if (CPDMA_RX_SOURCE_PORT(status) == 1) {		\
> -			ndev = cpsw->slaves[0].ndev;			\
> -			skb->dev = ndev;				\
> -		} else if (CPDMA_RX_SOURCE_PORT(status) == 2) {		\
> -			ndev = cpsw->slaves[1].ndev;			\
> -			skb->dev = ndev;				\
> -		}							\
> -	} while (0)
> -#define cpsw_add_mcast(cpsw, priv, addr)				\
> -	do {								\
> -		if (cpsw->data.dual_emac) {				\
> -			struct cpsw_slave *slave = cpsw->slaves +	\
> -						priv->emac_port;	\
> -			int slave_port = cpsw_get_slave_port(		\
> -						slave->slave_num);	\
> -			cpsw_ale_add_mcast(cpsw->ale, addr,		\
> -				1 << slave_port | ALE_PORT_HOST,	\
> -				ALE_VLAN, slave->port_vlan, 0);		\
> -		} else {						\
> -			cpsw_ale_add_mcast(cpsw->ale, addr,		\
> -				ALE_ALL_PORTS,				\
> -				0, 0, 0);				\
> -		}							\
> -	} while (0)
> -
>  static inline int cpsw_get_slave_port(u32 slave_num)
>  {
>  	return slave_num + 1;
>  }
>  
> +static inline void cpsw_src_port_detect(struct cpsw_common *cpsw, int status,
> +					struct sk_buff *skb)
> +{
> +	if (!cpsw->data.dual_emac)
> +		return;
> +
> +	if (CPDMA_RX_SOURCE_PORT(status) == 1)
> +		skb->dev = cpsw->slaves[0].ndev;
> +	else if (CPDMA_RX_SOURCE_PORT(status) == 2)
> +		skb->dev = cpsw->slaves[1].ndev;
> +}

perhaps better as a switch/case

> +
> +static void cpsw_add_mcast(struct cpsw_priv *priv, u8 *addr)
> +{
> +	struct cpsw_common *cpsw = priv->cpsw;
> +
> +	if (cpsw->data.dual_emac) {
> +		struct cpsw_slave *slave = cpsw->slaves + priv->emac_port;
> +		int slave_port = cpsw_get_slave_port(slave->slave_num);
> +
> +		cpsw_ale_add_mcast(cpsw->ale, addr,
> +				   1 << slave_port | ALE_PORT_HOST,
> +				   ALE_VLAN, slave->port_vlan, 0);
> +		return;
> +	}
> +
> +	cpsw_ale_add_mcast(cpsw->ale, addr, ALE_ALL_PORTS, 0, 0, 0);
> +}
> +
>  static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
>  {
>  	struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
> @@ -706,7 +706,7 @@ static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
>  
>  		/* program multicast address list into ALE register */
>  		netdev_for_each_mc_addr(ha, ndev) {
> -			cpsw_add_mcast(cpsw, priv, (u8 *)ha->addr);
> +			cpsw_add_mcast(priv, (u8 *)ha->addr);
>  		}
>  	}
>  }
> @@ -801,7 +801,8 @@ static void cpsw_rx_handler(void *token, int len, int status)
>  	int			ret = 0;
>  	struct cpsw_common	*cpsw = ndev_to_cpsw(ndev);
>  
> -	cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb);
> +	cpsw_src_port_detect(cpsw, status, skb);
> +	ndev = skb->dev;

This is not the same code as the new function
is not guaranteed to succeed or set skb->dev.

>  	if (unlikely(status < 0) || unlikely(!netif_running(ndev))) {
>  		/* In dual emac mode check for all interfaces */

^ permalink raw reply

* Re: [PATCH net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions
From: Ivan Khoronzhuk @ 2018-07-27 20:49 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: grygorii.strashko, davem, linux-omap, netdev, linux-kernel
In-Reply-To: <20180727203203.GB17441@lunn.ch>

On Fri, Jul 27, 2018 at 10:32:03PM +0200, Andrew Lunn wrote:
>> +static inline void cpsw_src_port_detect(struct cpsw_common *cpsw, int status,
>> +					struct sk_buff *skb)
>
>Please don't use inline. Let the compiler decide.
>
>       Andrew

Corrected in v2

-- 
Regards,
Ivan Khoronzhuk

^ permalink raw reply

* [PATCH v2 net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions
From: Ivan Khoronzhuk @ 2018-07-27 20:49 UTC (permalink / raw)
  To: grygorii.strashko, davem
  Cc: andrew, joe, linux-omap, netdev, linux-kernel, Ivan Khoronzhuk

Replace ugly macroses on functions.

v2..v1:
 - removed inline for cpsw_src_port_detect()

Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
Based on net-next/master

 drivers/net/ethernet/ti/cpsw.c | 63 +++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 1b54c26c2bec..9cacfe4ad065 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -565,40 +565,40 @@ static const struct cpsw_stats cpsw_gstrings_ch_stats[] = {
 				(func)(slave++, ##arg);			\
 	} while (0)
 
-#define cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb)		\
-	do {								\
-		if (!cpsw->data.dual_emac)				\
-			break;						\
-		if (CPDMA_RX_SOURCE_PORT(status) == 1) {		\
-			ndev = cpsw->slaves[0].ndev;			\
-			skb->dev = ndev;				\
-		} else if (CPDMA_RX_SOURCE_PORT(status) == 2) {		\
-			ndev = cpsw->slaves[1].ndev;			\
-			skb->dev = ndev;				\
-		}							\
-	} while (0)
-#define cpsw_add_mcast(cpsw, priv, addr)				\
-	do {								\
-		if (cpsw->data.dual_emac) {				\
-			struct cpsw_slave *slave = cpsw->slaves +	\
-						priv->emac_port;	\
-			int slave_port = cpsw_get_slave_port(		\
-						slave->slave_num);	\
-			cpsw_ale_add_mcast(cpsw->ale, addr,		\
-				1 << slave_port | ALE_PORT_HOST,	\
-				ALE_VLAN, slave->port_vlan, 0);		\
-		} else {						\
-			cpsw_ale_add_mcast(cpsw->ale, addr,		\
-				ALE_ALL_PORTS,				\
-				0, 0, 0);				\
-		}							\
-	} while (0)
-
 static inline int cpsw_get_slave_port(u32 slave_num)
 {
 	return slave_num + 1;
 }
 
+static void cpsw_src_port_detect(struct cpsw_common *cpsw, int status,
+				 struct sk_buff *skb)
+{
+	if (!cpsw->data.dual_emac)
+		return;
+
+	if (CPDMA_RX_SOURCE_PORT(status) == 1)
+		skb->dev = cpsw->slaves[0].ndev;
+	else if (CPDMA_RX_SOURCE_PORT(status) == 2)
+		skb->dev = cpsw->slaves[1].ndev;
+}
+
+static void cpsw_add_mcast(struct cpsw_priv *priv, u8 *addr)
+{
+	struct cpsw_common *cpsw = priv->cpsw;
+
+	if (cpsw->data.dual_emac) {
+		struct cpsw_slave *slave = cpsw->slaves + priv->emac_port;
+		int slave_port = cpsw_get_slave_port(slave->slave_num);
+
+		cpsw_ale_add_mcast(cpsw->ale, addr,
+				   1 << slave_port | ALE_PORT_HOST,
+				   ALE_VLAN, slave->port_vlan, 0);
+		return;
+	}
+
+	cpsw_ale_add_mcast(cpsw->ale, addr, ALE_ALL_PORTS, 0, 0, 0);
+}
+
 static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
 {
 	struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
@@ -706,7 +706,7 @@ static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
 
 		/* program multicast address list into ALE register */
 		netdev_for_each_mc_addr(ha, ndev) {
-			cpsw_add_mcast(cpsw, priv, (u8 *)ha->addr);
+			cpsw_add_mcast(priv, (u8 *)ha->addr);
 		}
 	}
 }
@@ -801,7 +801,8 @@ static void cpsw_rx_handler(void *token, int len, int status)
 	int			ret = 0;
 	struct cpsw_common	*cpsw = ndev_to_cpsw(ndev);
 
-	cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb);
+	cpsw_src_port_detect(cpsw, status, skb);
+	ndev = skb->dev;
 
 	if (unlikely(status < 0) || unlikely(!netif_running(ndev))) {
 		/* In dual emac mode check for all interfaces */
-- 
2.17.1

^ permalink raw reply related

* Re: [PATCH v2 net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions
From: Andrew Lunn @ 2018-07-27 21:09 UTC (permalink / raw)
  To: Ivan Khoronzhuk
  Cc: grygorii.strashko, davem, joe, linux-omap, netdev, linux-kernel
In-Reply-To: <20180727204958.23658-1-ivan.khoronzhuk@linaro.org>

On Fri, Jul 27, 2018 at 11:49:58PM +0300, Ivan Khoronzhuk wrote:
> Replace ugly macroses on functions.
> 
> v2..v1:
>  - removed inline for cpsw_src_port_detect()

Hi Ivan

Comments like this should be placed under the ---. Otherwise the
appear in the commit message.

	 Andrew

^ permalink raw reply

* Re: [PATCH] net: amd: pcnet32: Replace GFP_ATOMIC with GFP_KERNEL in pcnet32_alloc_ring()
From: David Miller @ 2018-07-27 21:11 UTC (permalink / raw)
  To: baijiaju1990; +Cc: pcnet32, netdev, linux-kernel
In-Reply-To: <20180727075758.2516-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Fri, 27 Jul 2018 15:57:58 +0800

> pcnet32_alloc_ring() is never called in atomic context.
> It calls kcalloc() with GFP_ATOMIC, which is not necessary.
> GFP_ATOMIC can be replaced with GFP_KERNEL.
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH] net: hisilicon: hns: Replace mdelay() with msleep()
From: David Miller @ 2018-07-27 21:12 UTC (permalink / raw)
  To: baijiaju1990
  Cc: yisen.zhuang, salil.mehta, linyunsheng, joe, pombredanne,
	bianpan2016, shenjian15, keescook, netdev, linux-kernel
In-Reply-To: <20180727080141.3079-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Fri, 27 Jul 2018 16:01:41 +0800

> hns_ppe_common_init_hw() and hns_xgmac_init() are never 
> called in atomic context.
> They call mdelay() to busily wait, which is not necessary.
> mdelay() can be replaced with msleep().
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH] net: jme: Replace mdelay() with msleep() and usleep_range() in jme_wait_link()
From: David Miller @ 2018-07-27 21:12 UTC (permalink / raw)
  To: baijiaju1990; +Cc: cooldavid, netdev, linux-kernel
In-Reply-To: <20180727082507.3917-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Fri, 27 Jul 2018 16:25:07 +0800

> jme_wait_link() is never called in atomic context.
> It calls mdelay() to busily wait, which is not necessary.
> mdelay() can be replaced with msleep() and usleep_range().
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH] net: nvidia: forcedeth: Replace GFP_ATOMIC with GFP_KERNEL in nv_probe()
From: David Miller @ 2018-07-27 21:12 UTC (permalink / raw)
  To: baijiaju1990; +Cc: yanjun.zhu, keescook, netdev, linux-kernel
In-Reply-To: <20180727082931.7340-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Fri, 27 Jul 2018 16:29:31 +0800

> nv_probe() is never called in atomic context.
> It calls dma_alloc_coherent() with GFP_ATOMIC, which is not necessary.
> GFP_ATOMIC can be replaced with GFP_KERNEL.
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH] net: phy: marvell: Replace mdelay() with msleep() in m88e1116r_config_init()
From: David Miller @ 2018-07-27 21:12 UTC (permalink / raw)
  To: baijiaju1990; +Cc: andrew, f.fainelli, netdev, linux-kernel
In-Reply-To: <20180727083425.14481-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Fri, 27 Jul 2018 16:34:25 +0800

> m88e1116r_config_init() is never called in atomic context.
> It calls mdelay() to busily wait, which is not necessary.
> mdelay() can be replaced with msleep().
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH] net: usb: sr9700: Replace mdelay() with msleep() in sr9700_bind()
From: David Miller @ 2018-07-27 21:12 UTC (permalink / raw)
  To: baijiaju1990; +Cc: liujunliang_ljl, linux-usb, netdev, linux-kernel
In-Reply-To: <20180727084104.29726-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Fri, 27 Jul 2018 16:41:04 +0800

> sr9700_bind() is never called in atomic context.
> It calls mdelay() to busily wait, which is not necessary.
> mdelay() can be replaced with msleep().
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH] net: tipc: name_table: Replace GFP_ATOMIC with GFP_KERNEL in tipc_nametbl_init()
From: David Miller @ 2018-07-27 21:13 UTC (permalink / raw)
  To: baijiaju1990; +Cc: jon.maloy, ying.xue, netdev, tipc-discussion, linux-kernel
In-Reply-To: <20180727092825.7370-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Fri, 27 Jul 2018 17:28:25 +0800

> tipc_nametbl_init() is never called in atomic context.
> It calls kzalloc() with GFP_ATOMIC, which is not necessary.
> GFP_ATOMIC can be replaced with GFP_KERNEL.
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH] net: tipc: bcast: Replace GFP_ATOMIC with GFP_KERNEL in tipc_bcast_init()
From: David Miller @ 2018-07-27 21:13 UTC (permalink / raw)
  To: baijiaju1990; +Cc: jon.maloy, ying.xue, netdev, tipc-discussion, linux-kernel
In-Reply-To: <20180727093135.7469-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Fri, 27 Jul 2018 17:31:35 +0800

> tipc_bcast_init() is never called in atomic context.
> It calls kzalloc() with GFP_ATOMIC, which is not necessary.
> GFP_ATOMIC can be replaced with GFP_KERNEL.
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Applied.

^ permalink raw reply

* [PATCH] phy: Move "device present" masks earlier in file
From: Robert P. J. Day @ 2018-07-27 19:32 UTC (permalink / raw)
  To: netdev; +Cc: andrew, f.fainelli

Move the "device present" mask bits up immediately after the MMD
device definitions, since it makes no sense to have them further down
in the file.

This is purely a cosmetic change for readability.

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

---

  since the *only* thing that actually uses the MMD definitions in
that file are the mask bits, it only makes sense to put them next to
each other -- there should be no functional change.

diff --git a/include/uapi/linux/mdio.h b/include/uapi/linux/mdio.h
index d435b00d64ad..4897f17b0639 100644
--- a/include/uapi/linux/mdio.h
+++ b/include/uapi/linux/mdio.h
@@ -27,6 +27,17 @@
 #define MDIO_MMD_VEND1		30	/* Vendor specific 1 */
 #define MDIO_MMD_VEND2		31	/* Vendor specific 2 */

+/* Device present mask bits. */
+#define MDIO_DEVS_PRESENT(devad)	(1 << (devad))
+#define MDIO_DEVS_PMAPMD		MDIO_DEVS_PRESENT(MDIO_MMD_PMAPMD)
+#define MDIO_DEVS_WIS			MDIO_DEVS_PRESENT(MDIO_MMD_WIS)
+#define MDIO_DEVS_PCS			MDIO_DEVS_PRESENT(MDIO_MMD_PCS)
+#define MDIO_DEVS_PHYXS			MDIO_DEVS_PRESENT(MDIO_MMD_PHYXS)
+#define MDIO_DEVS_DTEXS			MDIO_DEVS_PRESENT(MDIO_MMD_DTEXS)
+#define MDIO_DEVS_TC			MDIO_DEVS_PRESENT(MDIO_MMD_TC)
+#define MDIO_DEVS_AN			MDIO_DEVS_PRESENT(MDIO_MMD_AN)
+#define MDIO_DEVS_C22EXT		MDIO_DEVS_PRESENT(MDIO_MMD_C22EXT)
+
 /* Generic MDIO registers. */
 #define MDIO_CTRL1		MII_BMCR
 #define MDIO_STAT1		MII_BMSR
@@ -113,17 +124,6 @@
 #define MDIO_PMA_SPEED_10		0x0040	/* 10M capable */
 #define MDIO_PCS_SPEED_10P2B		0x0002	/* 10PASS-TS/2BASE-TL capable */

-/* Device present registers. */
-#define MDIO_DEVS_PRESENT(devad)	(1 << (devad))
-#define MDIO_DEVS_PMAPMD		MDIO_DEVS_PRESENT(MDIO_MMD_PMAPMD)
-#define MDIO_DEVS_WIS			MDIO_DEVS_PRESENT(MDIO_MMD_WIS)
-#define MDIO_DEVS_PCS			MDIO_DEVS_PRESENT(MDIO_MMD_PCS)
-#define MDIO_DEVS_PHYXS			MDIO_DEVS_PRESENT(MDIO_MMD_PHYXS)
-#define MDIO_DEVS_DTEXS			MDIO_DEVS_PRESENT(MDIO_MMD_DTEXS)
-#define MDIO_DEVS_TC			MDIO_DEVS_PRESENT(MDIO_MMD_TC)
-#define MDIO_DEVS_AN			MDIO_DEVS_PRESENT(MDIO_MMD_AN)
-#define MDIO_DEVS_C22EXT		MDIO_DEVS_PRESENT(MDIO_MMD_C22EXT)
-
 /* Control register 2. */
 #define MDIO_PMA_CTRL2_TYPE		0x000f	/* PMA/PMD type selection */
 #define MDIO_PMA_CTRL2_10GBCX4		0x0000	/* 10GBASE-CX4 type */

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                  http://crashcourse.ca/dokuwiki

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

^ permalink raw reply related

* [PATCH v2 0/7] Add clock config and pm support to bcm iProc mdio mux
From: Arun Parameswaran @ 2018-07-27 21:23 UTC (permalink / raw)
  To: David S. Miller, Florian Fainelli, Andrew Lunn, Rob Herring,
	Mark Rutland, Ray Jui, Scott Branden, Catalin Marinas,
	Will Deacon
  Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
	bcm-kernel-feedback-list, Arun Parameswaran

Hi,
The patchset is based on David Miller's "net-next" repo.

The patchset extends the Broadcom iProc mdio mux to add support for
suspend/resume and the ability to configure the internal clock
divider. The patchset also sets the scan control register to
disable external master access.

The base address of the mdio-mux-bcm-iproc is modified to point to the
start of the mdio block's address space, to be able to access all the
mdio's registers. The missing registers are required to configure the
internal clock divider registers in some of the Broadcom SoC's.

Changes from v1:
 - Addressed Andrew's comments.
   - Reworked the patches to be based on 'net-next'
   - Removed 'fixes' from the commit messages, the changes are related
     to the new features being added.
   - Maintained backward compatibility to older dt-blob's specifying
     base addresse with an offset. The correction is applied in the
     driver and a message is printed to update the dt-blob.
   - Re-worked and re-ordered the last four patches (4-7).
     - Added setting of the scan control register as a new patch
     - Added a call to 'clk_prepare_enable()' in the patch that adds
       the clock config support, removed the debug message when clock
       is not passed.
     - Simplified the pm support patch (removed the array used for the
       save/restore logic).

Thanks
Arun

Arun Parameswaran (7):
  dt-bindings: net: Fix Broadcom iProc mdio mux driver base address
  net: phy: Fix the register offsets in Broadcom iProc mdio mux driver
  arm64: dts: Fix the base address of the Broadcom iProc mdio mux
  net: phy: Disable external master access in bcm mdio mux driver
  dt-bindings: net: Add clock handle to Broadcom iProc mdio mux
  net: phy: Add support to configure clock in Broadcom iProc mdio mux
  net: phy: Add pm support to Broadcom iProc mdio mux driver

 .../bindings/net/brcm,mdio-mux-iproc.txt           |   7 +-
 arch/arm64/boot/dts/broadcom/northstar2/ns2.dtsi   |   4 +-
 .../arm64/boot/dts/broadcom/stingray/stingray.dtsi |   4 +-
 drivers/net/phy/mdio-mux-bcm-iproc.c               | 109 +++++++++++++++++++--
 4 files changed, 109 insertions(+), 15 deletions(-)

-- 
1.9.1

^ permalink raw reply

* [PATCH v2 1/7] dt-bindings: net: Fix Broadcom iProc mdio mux driver base address
From: Arun Parameswaran @ 2018-07-27 21:23 UTC (permalink / raw)
  To: David S. Miller, Florian Fainelli, Andrew Lunn, Rob Herring,
	Mark Rutland, Ray Jui, Scott Branden, Catalin Marinas,
	Will Deacon
  Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
	bcm-kernel-feedback-list, Arun Parameswaran
In-Reply-To: <1532726613-6483-1-git-send-email-arun.parameswaran@broadcom.com>

Modify the base address of the Broadcom iProc MDIO mux driver to
point to the start of the block's register address space.

Signed-off-by: Arun Parameswaran <arun.parameswaran@broadcom.com>
---
 Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt b/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
index dfe287a..dc8aa68 100644
--- a/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
+++ b/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
@@ -18,9 +18,9 @@ at- Documentation/devicetree/bindings/net/mdio-mux.txt
 
 
 for example:
-		mdio_mux_iproc: mdio-mux@6602023c {
+		mdio_mux_iproc: mdio-mux@66020000 {
 			compatible = "brcm,mdio-mux-iproc";
-			reg = <0x6602023c 0x14>;
+			reg = <0x66020000 0x250>;
 			#address-cells = <1>;
 			#size-cells = <0>;
 
-- 
1.9.1

^ permalink raw reply related

* [PATCH v2 2/7] net: phy: Fix the register offsets in Broadcom iProc mdio mux driver
From: Arun Parameswaran @ 2018-07-27 21:23 UTC (permalink / raw)
  To: David S. Miller, Florian Fainelli, Andrew Lunn, Rob Herring,
	Mark Rutland, Ray Jui, Scott Branden, Catalin Marinas,
	Will Deacon
  Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
	bcm-kernel-feedback-list, Arun Parameswaran
In-Reply-To: <1532726613-6483-1-git-send-email-arun.parameswaran@broadcom.com>

Modify the register offsets in the Broadcom iProc mdio mux to start
from the top of the register address space.

Earlier, the base address pointed to the end of the block's register
space. The base address will now point to the start of the mdio's
address space. The offsets have been fixed to match this.

Signed-off-by: Arun Parameswaran <arun.parameswaran@broadcom.com>
---
 drivers/net/phy/mdio-mux-bcm-iproc.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/mdio-mux-bcm-iproc.c b/drivers/net/phy/mdio-mux-bcm-iproc.c
index 0831b71..48bb74a 100644
--- a/drivers/net/phy/mdio-mux-bcm-iproc.c
+++ b/drivers/net/phy/mdio-mux-bcm-iproc.c
@@ -22,7 +22,7 @@
 #include <linux/mdio-mux.h>
 #include <linux/delay.h>
 
-#define MDIO_PARAM_OFFSET		0x00
+#define MDIO_PARAM_OFFSET		0x23c
 #define MDIO_PARAM_MIIM_CYCLE		29
 #define MDIO_PARAM_INTERNAL_SEL		25
 #define MDIO_PARAM_BUS_ID		22
@@ -30,20 +30,22 @@
 #define MDIO_PARAM_PHY_ID		16
 #define MDIO_PARAM_PHY_DATA		0
 
-#define MDIO_READ_OFFSET		0x04
+#define MDIO_READ_OFFSET		0x240
 #define MDIO_READ_DATA_MASK		0xffff
-#define MDIO_ADDR_OFFSET		0x08
+#define MDIO_ADDR_OFFSET		0x244
 
-#define MDIO_CTRL_OFFSET		0x0C
+#define MDIO_CTRL_OFFSET		0x248
 #define MDIO_CTRL_WRITE_OP		0x1
 #define MDIO_CTRL_READ_OP		0x2
 
-#define MDIO_STAT_OFFSET		0x10
+#define MDIO_STAT_OFFSET		0x24c
 #define MDIO_STAT_DONE			1
 
 #define BUS_MAX_ADDR			32
 #define EXT_BUS_START_ADDR		16
 
+#define MDIO_REG_ADDR_SPACE_SIZE	0x250
+
 struct iproc_mdiomux_desc {
 	void *mux_handle;
 	void __iomem *base;
@@ -169,6 +171,14 @@ static int mdio_mux_iproc_probe(struct platform_device *pdev)
 	md->dev = &pdev->dev;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (res->start & 0xfff) {
+		/* For backward compatibility in case the
+		 * base address is specified with an offset.
+		 */
+		dev_info(&pdev->dev, "fix base address in dt-blob\n");
+		res->start &= ~0xfff;
+		res->end = res->start + MDIO_REG_ADDR_SPACE_SIZE - 1;
+	}
 	md->base = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(md->base)) {
 		dev_err(&pdev->dev, "failed to ioremap register\n");
-- 
1.9.1

^ permalink raw reply related

* [PATCH v2 3/7] arm64: dts: Fix the base address of the Broadcom iProc mdio mux
From: Arun Parameswaran @ 2018-07-27 21:23 UTC (permalink / raw)
  To: David S. Miller, Florian Fainelli, Andrew Lunn, Rob Herring,
	Mark Rutland, Ray Jui, Scott Branden, Catalin Marinas,
	Will Deacon
  Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
	bcm-kernel-feedback-list, Arun Parameswaran
In-Reply-To: <1532726613-6483-1-git-send-email-arun.parameswaran@broadcom.com>

Modify the base address of the mdio mux driver to point to the
start of the mdio mux block's register address space.

Signed-off-by: Arun Parameswaran <arun.parameswaran@broadcom.com>
---
 arch/arm64/boot/dts/broadcom/northstar2/ns2.dtsi    | 4 ++--
 arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/boot/dts/broadcom/northstar2/ns2.dtsi b/arch/arm64/boot/dts/broadcom/northstar2/ns2.dtsi
index 4057197..1a406a7 100644
--- a/arch/arm64/boot/dts/broadcom/northstar2/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/northstar2/ns2.dtsi
@@ -482,9 +482,9 @@
 			status = "disabled";
 		};
 
-		mdio_mux_iproc: mdio-mux@6602023c {
+		mdio_mux_iproc: mdio-mux@66020000 {
 			compatible = "brcm,mdio-mux-iproc";
-			reg = <0x6602023c 0x14>;
+			reg = <0x66020000 0x250>;
 			#address-cells = <1>;
 			#size-cells = <0>;
 
diff --git a/arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi b/arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi
index b203152..a70e8dd 100644
--- a/arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi
+++ b/arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi
@@ -278,9 +278,9 @@
 
 		#include "stingray-pinctrl.dtsi"
 
-		mdio_mux_iproc: mdio-mux@2023c {
+		mdio_mux_iproc: mdio-mux@20000 {
 			compatible = "brcm,mdio-mux-iproc";
-			reg = <0x0002023c 0x14>;
+			reg = <0x00020000 0x250>;
 			#address-cells = <1>;
 			#size-cells = <0>;
 
-- 
1.9.1

^ permalink raw reply related

* [PATCH v2 4/7] net: phy: Disable external master access in bcm mdio mux driver
From: Arun Parameswaran @ 2018-07-27 21:23 UTC (permalink / raw)
  To: David S. Miller, Florian Fainelli, Andrew Lunn, Rob Herring,
	Mark Rutland, Ray Jui, Scott Branden, Catalin Marinas,
	Will Deacon
  Cc: netdev, devicetree, linux-arm-kernel, linux-kernel,
	bcm-kernel-feedback-list, Arun Parameswaran
In-Reply-To: <1532726613-6483-1-git-send-email-arun.parameswaran@broadcom.com>

Configure the scan control register in the Broadcom iProc
mdio mux driver to disable access to external master.

In some SoC's, the scan control register defaults to an incorrect
value.

Signed-off-by: Arun Parameswaran <arun.parameswaran@broadcom.com>
---
 drivers/net/phy/mdio-mux-bcm-iproc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/net/phy/mdio-mux-bcm-iproc.c b/drivers/net/phy/mdio-mux-bcm-iproc.c
index 48bb74a..c36ce4b 100644
--- a/drivers/net/phy/mdio-mux-bcm-iproc.c
+++ b/drivers/net/phy/mdio-mux-bcm-iproc.c
@@ -22,6 +22,9 @@
 #include <linux/mdio-mux.h>
 #include <linux/delay.h>
 
+#define MDIO_SCAN_CTRL_OFFSET		0x008
+#define MDIO_SCAN_CTRL_OVRIDE_EXT_MSTR	28
+
 #define MDIO_PARAM_OFFSET		0x23c
 #define MDIO_PARAM_MIIM_CYCLE		29
 #define MDIO_PARAM_INTERNAL_SEL		25
@@ -53,6 +56,16 @@ struct iproc_mdiomux_desc {
 	struct mii_bus *mii_bus;
 };
 
+static void mdio_mux_iproc_config(struct iproc_mdiomux_desc *md)
+{
+	u32 val;
+
+	/* Disable external mdio master access */
+	val = readl(md->base + MDIO_SCAN_CTRL_OFFSET);
+	val |= BIT(MDIO_SCAN_CTRL_OVRIDE_EXT_MSTR);
+	writel(val, md->base + MDIO_SCAN_CTRL_OFFSET);
+}
+
 static int iproc_mdio_wait_for_idle(void __iomem *base, bool result)
 {
 	unsigned int timeout = 1000; /* loop for 1s */
@@ -216,6 +229,8 @@ static int mdio_mux_iproc_probe(struct platform_device *pdev)
 		goto out_register;
 	}
 
+	mdio_mux_iproc_config(md);
+
 	dev_info(md->dev, "iProc mdiomux registered\n");
 	return 0;
 
-- 
1.9.1

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox