Netdev List
 help / color / mirror / Atom feed
* Re: [PATCH net-next v2 1/1] qed: Add new ethtool supported port types based on media.
From: David Miller @ 2019-08-09  1:14 UTC (permalink / raw)
  To: rahulv; +Cc: netdev, aelior, mkalderon
In-Reply-To: <20190806065950.19073-1-rahulv@marvell.com>

From: Rahul Verma <rahulv@marvell.com>
Date: Mon, 5 Aug 2019 23:59:50 -0700

> Supported ports in ethtool <eth1> are displayed based on media type.
> For media type fibre and twinaxial, port type is "FIBRE". Media type
> Base-T is "TP" and media KR is "Backplane".
> 
> V1->V2:
> Corrected the subject.
> 
> Signed-off-by: Rahul Verma <rahulv@marvell.com>
> Signed-off-by: Michal Kalderon <michal.kalderon@marvell.com>

Applied.

^ permalink raw reply

* Re: [PATCH net] hv_netvsc: Fix a warning of suspicious RCU usage
From: David Miller @ 2019-08-09  1:13 UTC (permalink / raw)
  To: decui
  Cc: netdev, haiyangz, sthemmin, sashal, kys, mikelley, linux-hyperv,
	linux-kernel, olaf, apw, jasowang, vkuznets, marcelo.cerri
In-Reply-To: <PU1P153MB0169AECABF6094A3E7BEE381BFD50@PU1P153MB0169.APCP153.PROD.OUTLOOK.COM>

From: Dexuan Cui <decui@microsoft.com>
Date: Tue, 6 Aug 2019 05:17:44 +0000

> 
> This fixes a warning of "suspicious rcu_dereference_check() usage"
> when nload runs.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Dexuan Cui <decui@microsoft.com>

Please resend with appropriate fixes tag.

^ permalink raw reply

* Re: [PATCH 2/2] cxgb4: smt: Use normal int for refcount
From: David Miller @ 2019-08-09  1:12 UTC (permalink / raw)
  To: hslester96; +Cc: vishal, netdev, linux-kernel
In-Reply-To: <20190806025854.17076-1-hslester96@gmail.com>

From: Chuhong Yuan <hslester96@gmail.com>
Date: Tue,  6 Aug 2019 10:58:54 +0800

> All refcount operations are protected by spinlocks now.
> Then the atomic counter can be replaced by a normal int.
> 
> This patch depends on PATCH 1/2.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH 1/2] cxgb4: smt: Add lock for atomic_dec_and_test
From: David Miller @ 2019-08-09  1:12 UTC (permalink / raw)
  To: hslester96; +Cc: vishal, netdev, linux-kernel
In-Reply-To: <20190806025846.17022-1-hslester96@gmail.com>

From: Chuhong Yuan <hslester96@gmail.com>
Date: Tue,  6 Aug 2019 10:58:46 +0800

> The atomic_dec_and_test() is not safe because it is
> outside of locks.
> Move the locks of t4_smte_free() to its caller,
> cxgb4_smt_release() to protect the atomic decrement.
> 
> Fixes: 3bdb376e6944 ("cxgb4: introduce SMT ops to prepare for SMAC rewrite support")
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH net-next] net: delete "register" keyword
From: Simon Horman @ 2019-08-09  1:10 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: davem, netdev, lvs-devel
In-Reply-To: <20190805203441.GA24674@avx2>

On Mon, Aug 05, 2019 at 11:34:41PM +0300, Alexey Dobriyan wrote:
> Delete long obsoleted "register" keyword.
> 
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
> 
>  drivers/net/ethernet/apple/bmac.c |    4 ++--
>  drivers/net/slip/slhc.c           |   30 +++++++++++++++---------------
>  net/netfilter/ipvs/ip_vs_ctl.c    |    4 ++--
>  net/netfilter/ipvs/ip_vs_lblcr.c  |    4 ++--
>  4 files changed, 21 insertions(+), 21 deletions(-)

IPVS portion:

Reviewed-by: Simon Horman <horms@verge.net.au>

> 
> --- a/drivers/net/ethernet/apple/bmac.c
> +++ b/drivers/net/ethernet/apple/bmac.c
> @@ -815,8 +815,8 @@ static int reverse6[64] = {
>  static unsigned int
>  crc416(unsigned int curval, unsigned short nxtval)
>  {
> -	register unsigned int counter, cur = curval, next = nxtval;
> -	register int high_crc_set, low_data_set;
> +	unsigned int counter, cur = curval, next = nxtval;
> +	int high_crc_set, low_data_set;
>  
>  	/* Swap bytes */
>  	next = ((next & 0x00FF) << 8) | (next >> 8);
> --- a/drivers/net/slip/slhc.c
> +++ b/drivers/net/slip/slhc.c
> @@ -91,8 +91,8 @@ static unsigned short pull16(unsigned char **cpp);
>  struct slcompress *
>  slhc_init(int rslots, int tslots)
>  {
> -	register short i;
> -	register struct cstate *ts;
> +	short i;
> +	struct cstate *ts;
>  	struct slcompress *comp;
>  
>  	if (rslots < 0 || rslots > 255 || tslots < 0 || tslots > 255)
> @@ -206,7 +206,7 @@ pull16(unsigned char **cpp)
>  static long
>  decode(unsigned char **cpp)
>  {
> -	register int x;
> +	int x;
>  
>  	x = *(*cpp)++;
>  	if(x == 0){
> @@ -227,14 +227,14 @@ int
>  slhc_compress(struct slcompress *comp, unsigned char *icp, int isize,
>  	unsigned char *ocp, unsigned char **cpp, int compress_cid)
>  {
> -	register struct cstate *ocs = &(comp->tstate[comp->xmit_oldest]);
> -	register struct cstate *lcs = ocs;
> -	register struct cstate *cs = lcs->next;
> -	register unsigned long deltaS, deltaA;
> -	register short changes = 0;
> +	struct cstate *ocs = &(comp->tstate[comp->xmit_oldest]);
> +	struct cstate *lcs = ocs;
> +	struct cstate *cs = lcs->next;
> +	unsigned long deltaS, deltaA;
> +	short changes = 0;
>  	int hlen;
>  	unsigned char new_seq[16];
> -	register unsigned char *cp = new_seq;
> +	unsigned char *cp = new_seq;
>  	struct iphdr *ip;
>  	struct tcphdr *th, *oth;
>  	__sum16 csum;
> @@ -486,11 +486,11 @@ slhc_compress(struct slcompress *comp, unsigned char *icp, int isize,
>  int
>  slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
>  {
> -	register int changes;
> +	int changes;
>  	long x;
> -	register struct tcphdr *thp;
> -	register struct iphdr *ip;
> -	register struct cstate *cs;
> +	struct tcphdr *thp;
> +	struct iphdr *ip;
> +	struct cstate *cs;
>  	int len, hdrlen;
>  	unsigned char *cp = icp;
>  
> @@ -543,7 +543,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
>  	switch(changes & SPECIALS_MASK){
>  	case SPECIAL_I:		/* Echoed terminal traffic */
>  		{
> -		register short i;
> +		short i;
>  		i = ntohs(ip->tot_len) - hdrlen;
>  		thp->ack_seq = htonl( ntohl(thp->ack_seq) + i);
>  		thp->seq = htonl( ntohl(thp->seq) + i);
> @@ -637,7 +637,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
>  int
>  slhc_remember(struct slcompress *comp, unsigned char *icp, int isize)
>  {
> -	register struct cstate *cs;
> +	struct cstate *cs;
>  	unsigned ihl;
>  
>  	unsigned char index;
> --- a/net/netfilter/ipvs/ip_vs_ctl.c
> +++ b/net/netfilter/ipvs/ip_vs_ctl.c
> @@ -262,7 +262,7 @@ static inline unsigned int
>  ip_vs_svc_hashkey(struct netns_ipvs *ipvs, int af, unsigned int proto,
>  		  const union nf_inet_addr *addr, __be16 port)
>  {
> -	register unsigned int porth = ntohs(port);
> +	unsigned int porth = ntohs(port);
>  	__be32 addr_fold = addr->ip;
>  	__u32 ahash;
>  
> @@ -493,7 +493,7 @@ static inline unsigned int ip_vs_rs_hashkey(int af,
>  					    const union nf_inet_addr *addr,
>  					    __be16 port)
>  {
> -	register unsigned int porth = ntohs(port);
> +	unsigned int porth = ntohs(port);
>  	__be32 addr_fold = addr->ip;
>  
>  #ifdef CONFIG_IP_VS_IPV6
> --- a/net/netfilter/ipvs/ip_vs_lblcr.c
> +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
> @@ -160,7 +160,7 @@ static void ip_vs_dest_set_eraseall(struct ip_vs_dest_set *set)
>  /* get weighted least-connection node in the destination set */
>  static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
>  {
> -	register struct ip_vs_dest_set_elem *e;
> +	struct ip_vs_dest_set_elem *e;
>  	struct ip_vs_dest *dest, *least;
>  	int loh, doh;
>  
> @@ -209,7 +209,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
>  /* get weighted most-connection node in the destination set */
>  static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
>  {
> -	register struct ip_vs_dest_set_elem *e;
> +	struct ip_vs_dest_set_elem *e;
>  	struct ip_vs_dest *dest, *most;
>  	int moh, doh;
>  
> 

^ permalink raw reply

* Re: [PATCH v2 net-next] selftests: Add l2tp tests
From: David Miller @ 2019-08-09  1:08 UTC (permalink / raw)
  To: dsahern; +Cc: netdev, dsahern
In-Reply-To: <20190805224137.15236-1-dsahern@kernel.org>

From: David Ahern <dsahern@kernel.org>
Date: Mon,  5 Aug 2019 15:41:37 -0700

> From: David Ahern <dsahern@gmail.com>
> 
> Add IPv4 and IPv6 l2tp tests. Current set is over IP and with
> IPsec.
> 
> v2
> - add l2tp.sh to TEST_PROGS in Makefile
> 
> Signed-off-by: David Ahern <dsahern@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH net 2/2] net: docs: replace IPX in tuntap documentation
From: David Miller @ 2019-08-09  1:07 UTC (permalink / raw)
  To: stephen; +Cc: corbet, linux-dog, netdev
In-Reply-To: <20190805223003.13444-2-stephen@networkplumber.org>

From: Stephen Hemminger <stephen@networkplumber.org>
Date: Mon,  5 Aug 2019 15:30:03 -0700

> IPX is no longer supported, but the example in the documentation
> might useful. Replace it with IPv6.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Applied.

^ permalink raw reply

* Re: [PATCH net 1/2] docs: admin-guide: remove references to IPX and token-ring
From: David Miller @ 2019-08-09  1:07 UTC (permalink / raw)
  To: stephen; +Cc: corbet, linux-dog, netdev
In-Reply-To: <20190805223003.13444-1-stephen@networkplumber.org>

From: Stephen Hemminger <stephen@networkplumber.org>
Date: Mon,  5 Aug 2019 15:30:02 -0700

> Both IPX and TR have not been supported for a while now.
> Remove them from the /proc/sys/net documentation.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Applied.

^ permalink raw reply

* Re: [PATCH net-next] net: use "nb" for notifier blocks
From: David Miller @ 2019-08-09  1:05 UTC (permalink / raw)
  To: adobriyan; +Cc: netdev, netfilter-devel, linux-sctp, bpf
In-Reply-To: <20190805204331.GA25178@avx2>

From: Alexey Dobriyan <adobriyan@gmail.com>
Date: Mon, 5 Aug 2019 23:43:31 +0300

> Use more pleasant looking
> 
> 	struct notifier_block *nb,
> 
> instead of "this".
> 
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>

Sorry, this is a lot of churn for something that is basically an
opinion of being nicer or less nice.

I actually kind of like "this".

^ permalink raw reply

* Re: [PATCH net-next] net: delete "register" keyword
From: David Miller @ 2019-08-09  1:04 UTC (permalink / raw)
  To: adobriyan; +Cc: netdev, lvs-devel
In-Reply-To: <20190805203441.GA24674@avx2>

From: Alexey Dobriyan <adobriyan@gmail.com>
Date: Mon, 5 Aug 2019 23:34:41 +0300

> Delete long obsoleted "register" keyword.
> 
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>

Applied.

^ permalink raw reply

* Re: [PATCH] xen/netback: Reset nr_frags before freeing skb
From: David Miller @ 2019-08-09  1:02 UTC (permalink / raw)
  To: ross.lagerwall; +Cc: netdev, xen-devel, paul.durrant, wei.liu
In-Reply-To: <20190805153434.12144-1-ross.lagerwall@citrix.com>

From: Ross Lagerwall <ross.lagerwall@citrix.com>
Date: Mon, 5 Aug 2019 16:34:34 +0100

> At this point nr_frags has been incremented but the frag does not yet
> have a page assigned so freeing the skb results in a crash. Reset
> nr_frags before freeing the skb to prevent this.
> 
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>

Applied and queued up for -stable.

^ permalink raw reply

* Re: [PATCH v2] mkiss: Use refcount_t for refcount
From: David Miller @ 2019-08-09  0:59 UTC (permalink / raw)
  To: hslester96; +Cc: netdev, linux-kernel
In-Reply-To: <20190802164821.20189-1-hslester96@gmail.com>

From: Chuhong Yuan <hslester96@gmail.com>
Date: Sat,  3 Aug 2019 00:48:21 +0800

> refcount_t is better for reference counters since its
> implementation can prevent overflows.
> So convert atomic_t ref counters to refcount_t.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
> Changes in v2:
>   - Add #include.

Applied to net-next.

^ permalink raw reply

* Re: [PATCH v2] dpaa_eth: Use refcount_t for refcount
From: David Miller @ 2019-08-09  0:59 UTC (permalink / raw)
  To: hslester96; +Cc: madalin.bucur, netdev, linux-kernel
In-Reply-To: <20190802164759.20135-1-hslester96@gmail.com>

From: Chuhong Yuan <hslester96@gmail.com>
Date: Sat,  3 Aug 2019 00:47:59 +0800

> refcount_t is better for reference counters since its
> implementation can prevent overflows.
> So convert atomic_t ref counters to refcount_t.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
> Changes in v2:
>   - Add #include in dpaa_eth.h.

Applied to net-next.

^ permalink raw reply

* [PATCH] net: phy: at803x: stop switching phy delay config needlessly
From: André Draszik @ 2019-08-09  0:57 UTC (permalink / raw)
  To: linux-kernel
  Cc: André Draszik, Andrew Lunn, Florian Fainelli,
	Heiner Kallweit, David S. Miller, netdev

This driver does a funny dance disabling and re-enabling
RX and/or TX delays. In any of the RGMII-ID modes, it first
disables the delays, just to re-enable them again right
away. This looks like a needless exercise.

Just enable the respective delays when in any of the
relevant 'id' modes, and disable them otherwise.

Also, remove comments which don't add anything that can't be
seen by looking at the code.

Signed-off-by: André Draszik <git@andred.net>
CC: Andrew Lunn <andrew@lunn.ch>
CC: Florian Fainelli <f.fainelli@gmail.com>
CC: Heiner Kallweit <hkallweit1@gmail.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: netdev@vger.kernel.org
---
 drivers/net/phy/at803x.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index 222ccd9ecfce..2ab51f552e92 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -257,35 +257,21 @@ static int at803x_config_init(struct phy_device *phydev)
 	 *   after HW reset: RX delay enabled and TX delay disabled
 	 *   after SW reset: RX delay enabled, while TX delay retains the
 	 *   value before reset.
-	 *
-	 * So let's first disable the RX and TX delays in PHY and enable
-	 * them based on the mode selected (this also takes care of RGMII
-	 * mode where we expect delays to be disabled)
 	 */
-
-	ret = at803x_disable_rx_delay(phydev);
-	if (ret < 0)
-		return ret;
-	ret = at803x_disable_tx_delay(phydev);
-	if (ret < 0)
-		return ret;
-
 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
 	    phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
-		/* If RGMII_ID or RGMII_RXID are specified enable RX delay,
-		 * otherwise keep it disabled
-		 */
 		ret = at803x_enable_rx_delay(phydev);
-		if (ret < 0)
-			return ret;
+	} else {
+		ret = at803x_disable_rx_delay(phydev);
 	}
+	if (ret < 0)
+		return ret;
 
 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
 	    phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
-		/* If RGMII_ID or RGMII_TXID are specified enable TX delay,
-		 * otherwise keep it disabled
-		 */
 		ret = at803x_enable_tx_delay(phydev);
+	} else {
+		ret = at803x_disable_tx_delay(phydev);
 	}
 
 	return ret;
-- 
2.20.1


^ permalink raw reply related

* [PATCH v2] tipc: initialise addr_trail_end when setting node addresses
From: Chris Packham @ 2019-08-09  0:54 UTC (permalink / raw)
  To: jon.maloy, ying.xue, davem
  Cc: netdev, tipc-discussion, linux-kernel, Chris Packham

Ensure addr_trail_end is set to jiffies when configuring the node
address. This ensures that we don't treat the initial value of 0 as
being a wrapped. This isn't a problem when using auto-generated node
addresses because the addr_trail_end is updated for the duplicate
address detection phase.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- move setting to tipc_set_node_addr() as suggested
- reword commit message

 net/tipc/addr.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/tipc/addr.c b/net/tipc/addr.c
index b88d48d00913..0f1eaed1bd1b 100644
--- a/net/tipc/addr.c
+++ b/net/tipc/addr.c
@@ -75,6 +75,7 @@ void tipc_set_node_addr(struct net *net, u32 addr)
 		tipc_set_node_id(net, node_id);
 	}
 	tn->trial_addr = addr;
+	tn->addr_trial_end = jiffies;
 	pr_info("32-bit node address hash set to %x\n", addr);
 }
 
-- 
2.22.0


^ permalink raw reply related

* Re: memory leak in internal_dev_create
From: Marcelo Ricardo Leitner @ 2019-08-09  0:45 UTC (permalink / raw)
  To: Pravin Shelar
  Cc: Hillf Danton, syzbot, David S. Miller, ovs dev, linux-kernel,
	Linux Kernel Network Developers, syzkaller-bugs
In-Reply-To: <CAOrHB_BmuAxdch-nbaTS-1eXN-0goUb5UXtYDr==0KeM9vVsRw@mail.gmail.com>

On Wed, Aug 07, 2019 at 01:32:40PM -0700, Pravin Shelar wrote:
> On Tue, Aug 6, 2019 at 5:00 AM Hillf Danton <hdanton@sina.com> wrote:
> >
> >
> > On Tue, 06 Aug 2019 01:58:05 -0700
> > > Hello,
> > >
> > > syzbot found the following crash on:
> > >
> 
> ...
> > > BUG: memory leak
> > > unreferenced object 0xffff8881228ca500 (size 128):
> > >    comm "syz-executor032", pid 7015, jiffies 4294944622 (age 7.880s)
> > >    hex dump (first 32 bytes):
> > >      00 f0 27 18 81 88 ff ff 80 ac 8c 22 81 88 ff ff  ..'........"....
> > >      40 b7 23 17 81 88 ff ff 00 00 00 00 00 00 00 00  @.#.............
> > >    backtrace:
> > >      [<000000000eb78212>] kmemleak_alloc_recursive  include/linux/kmemleak.h:43 [inline]
> > >      [<000000000eb78212>] slab_post_alloc_hook mm/slab.h:522 [inline]
> > >      [<000000000eb78212>] slab_alloc mm/slab.c:3319 [inline]
> > >      [<000000000eb78212>] kmem_cache_alloc_trace+0x145/0x2c0 mm/slab.c:3548
> > >      [<00000000006ea6c6>] kmalloc include/linux/slab.h:552 [inline]
> > >      [<00000000006ea6c6>] kzalloc include/linux/slab.h:748 [inline]
> > >      [<00000000006ea6c6>] ovs_vport_alloc+0x37/0xf0  net/openvswitch/vport.c:130
> > >      [<00000000f9a04a7d>] internal_dev_create+0x24/0x1d0  net/openvswitch/vport-internal_dev.c:164
> > >      [<0000000056ee7c13>] ovs_vport_add+0x81/0x190  net/openvswitch/vport.c:199
> > >      [<000000005434efc7>] new_vport+0x19/0x80 net/openvswitch/datapath.c:194
> > >      [<00000000b7b253f1>] ovs_dp_cmd_new+0x22f/0x410  net/openvswitch/datapath.c:1614
> > >      [<00000000e0988518>] genl_family_rcv_msg+0x2ab/0x5b0  net/netlink/genetlink.c:629
> > >      [<00000000d0cc9347>] genl_rcv_msg+0x54/0x9c net/netlink/genetlink.c:654
> > >      [<000000006694b647>] netlink_rcv_skb+0x61/0x170  net/netlink/af_netlink.c:2477
> > >      [<0000000088381f37>] genl_rcv+0x29/0x40 net/netlink/genetlink.c:665
> > >      [<00000000dad42a47>] netlink_unicast_kernel  net/netlink/af_netlink.c:1302 [inline]
> > >      [<00000000dad42a47>] netlink_unicast+0x1ec/0x2d0  net/netlink/af_netlink.c:1328
> > >      [<0000000067e6b079>] netlink_sendmsg+0x270/0x480  net/netlink/af_netlink.c:1917
> > >      [<00000000aab08a47>] sock_sendmsg_nosec net/socket.c:637 [inline]
> > >      [<00000000aab08a47>] sock_sendmsg+0x54/0x70 net/socket.c:657
> > >      [<000000004cb7c11d>] ___sys_sendmsg+0x393/0x3c0 net/socket.c:2311
> > >      [<00000000c4901c63>] __sys_sendmsg+0x80/0xf0 net/socket.c:2356
> > >      [<00000000c10abb2d>] __do_sys_sendmsg net/socket.c:2365 [inline]
> > >      [<00000000c10abb2d>] __se_sys_sendmsg net/socket.c:2363 [inline]
> > >      [<00000000c10abb2d>] __x64_sys_sendmsg+0x23/0x30 net/socket.c:2363
> >
> >
> > Always free vport manually unless register_netdevice() succeeds.
> >
> > --- a/net/openvswitch/vport-internal_dev.c
> > +++ b/net/openvswitch/vport-internal_dev.c
> > @@ -137,7 +137,7 @@ static void do_setup(struct net_device *
> >         netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH |
> >                               IFF_NO_QUEUE;
> >         netdev->needs_free_netdev = true;
> > -       netdev->priv_destructor = internal_dev_destructor;
> > +       netdev->priv_destructor = NULL;
> >         netdev->ethtool_ops = &internal_dev_ethtool_ops;
> >         netdev->rtnl_link_ops = &internal_dev_link_ops;
> >
> > @@ -159,7 +159,6 @@ static struct vport *internal_dev_create
> >         struct internal_dev *internal_dev;
> >         struct net_device *dev;
> >         int err;
> > -       bool free_vport = true;
> >
> >         vport = ovs_vport_alloc(0, &ovs_internal_vport_ops, parms);
> >         if (IS_ERR(vport)) {
> > @@ -190,10 +189,9 @@ static struct vport *internal_dev_create
> >
> >         rtnl_lock();
> >         err = register_netdevice(vport->dev);
> > -       if (err) {
> > -               free_vport = false;
> > +       if (err)
> >                 goto error_unlock;
> > -       }
> > +       vport->dev->priv_destructor = internal_dev_destructor;
> >
> I am not sure why have you moved this assignment out of do_setup().
> 
> Otherwise patch looks good to me.
> 
> Thanks.

Seems it's to avoid re-introducing the issue that was fixed by:

commit 309b66970ee2abf721ecd0876a48940fa0b99a35
Author: Taehee Yoo <ap420073@gmail.com>
Date:   Sun Jun 9 23:26:21 2019 +0900

    net: openvswitch: do not free vport if register_netdevice() is failed.

A Fixes: 309b66970ee2a  is welcomed then.

> >         dev_set_promiscuity(vport->dev, 1);
> >         rtnl_unlock();
> > @@ -207,8 +205,7 @@ error_unlock:
> >  error_free_netdev:
> >         free_netdev(dev);
> >  error_free_vport:
> > -       if (free_vport)
> > -               ovs_vport_free(vport);
> > +       ovs_vport_free(vport);
> >  error:
> >         return ERR_PTR(err);
> >  }
> > --
> >
> 

^ permalink raw reply

* [PATCH v3] tools: bpftool: fix reading from /proc/config.gz
From: Peter Wu @ 2019-08-09  0:39 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, Stanislav Fomichev, Jakub Kicinski, Quentin Monnet

/proc/config has never existed as far as I can see, but /proc/config.gz
is present on Arch Linux. Add support for decompressing config.gz using
zlib which is a mandatory dependency of libelf. Replace existing stdio
functions with gzFile operations since the latter transparently handles
uncompressed and gzip-compressed files.

Cc: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
---
 v3: replace popen(gunzip) by linking directly to zlib. Reword commit
     message, remove "Fixes" line. (this patch)
 v2: fix style (reorder vars as reverse xmas tree, rename function,
     braces), fallback to /proc/config.gz if uname() fails.
     https://lkml.kernel.org/r/20190806010702.3303-1-peter@lekensteyn.nl
 v1: https://lkml.kernel.org/r/20190805001541.8096-1-peter@lekensteyn.nl

Hi,

Thanks to Jakub for observing that zlib is already used by libelf, this
simplifies the patch tremendously as the same API can be used for both
compressed and uncompressed files. No special case exists anymore for
fclose/pclose.

According to configure.ac in elfutils, zlib is mandatory, so I just
assume it to be available. For simplicity I also silently assume lines
to be less than 4096 characters. If that is not the case, then lines
will appear truncated, but that should not be an issue for the
CONFIG_xyz lines that we are scanning for.

Jakub requested the handle leak fix to be posted separately against the
bpf tree, but since the whole code is rewritten I am not sure if it is
worth it. It is an unusual edge case: /boot/config-$(uname -r) could be
opened, but starts with unexpected data.

Kind regards,
Peter
---
 tools/bpf/bpftool/Makefile  |   2 +-
 tools/bpf/bpftool/feature.c | 105 ++++++++++++++++++------------------
 2 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index a7afea4dec47..078bd0dcfba5 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -52,7 +52,7 @@ ifneq ($(EXTRA_LDFLAGS),)
 LDFLAGS += $(EXTRA_LDFLAGS)
 endif
 
-LIBS = -lelf $(LIBBPF)
+LIBS = -lelf -lz $(LIBBPF)
 
 INSTALL ?= install
 RM ?= rm -f
diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
index d672d9086fff..03bdc5b3ac49 100644
--- a/tools/bpf/bpftool/feature.c
+++ b/tools/bpf/bpftool/feature.c
@@ -14,6 +14,7 @@
 
 #include <bpf.h>
 #include <libbpf.h>
+#include <zlib.h>
 
 #include "main.h"
 
@@ -284,34 +285,32 @@ static void probe_jit_limit(void)
 	}
 }
 
-static char *get_kernel_config_option(FILE *fd, const char *option)
+static bool read_next_kernel_config_option(gzFile file, char *buf, size_t n,
+					   char **value)
 {
-	size_t line_n = 0, optlen = strlen(option);
-	char *res, *strval, *line = NULL;
-	ssize_t n;
+	char *sep;
 
-	rewind(fd);
-	while ((n = getline(&line, &line_n, fd)) > 0) {
-		if (strncmp(line, option, optlen))
+	while (gzgets(file, buf, n)) {
+		if (strncmp(buf, "CONFIG_", 7))
 			continue;
-		/* Check we have at least '=', value, and '\n' */
-		if (strlen(line) < optlen + 3)
-			continue;
-		if (*(line + optlen) != '=')
+
+		sep = strchr(buf, '=');
+		if (!sep)
 			continue;
 
 		/* Trim ending '\n' */
-		line[strlen(line) - 1] = '\0';
+		buf[strlen(buf) - 1] = '\0';
+
+		/* Split on '=' and ensure that a value is present. */
+		*sep = '\0';
+		if (!sep[1])
+			continue;
 
-		/* Copy and return config option value */
-		strval = line + optlen + 1;
-		res = strdup(strval);
-		free(line);
-		return res;
+		*value = sep + 1;
+		return true;
 	}
-	free(line);
 
-	return NULL;
+	return false;
 }
 
 static void probe_kernel_image_config(void)
@@ -386,59 +385,61 @@ static void probe_kernel_image_config(void)
 		/* test_bpf module for BPF tests */
 		"CONFIG_TEST_BPF",
 	};
-	char *value, *buf = NULL;
+	char *values[ARRAY_SIZE(options)] = { };
 	struct utsname utsn;
 	char path[PATH_MAX];
-	size_t i, n;
-	ssize_t ret;
-	FILE *fd;
+	gzFile file = NULL;
+	char buf[4096];
+	char *value;
+	size_t i;
 
-	if (uname(&utsn))
-		goto no_config;
+	if (!uname(&utsn)) {
+		snprintf(path, sizeof(path), "/boot/config-%s", utsn.release);
 
-	snprintf(path, sizeof(path), "/boot/config-%s", utsn.release);
+		/* gzopen also accepts uncompressed files. */
+		file = gzopen(path, "r");
+	}
 
-	fd = fopen(path, "r");
-	if (!fd && errno == ENOENT) {
-		/* Some distributions put the config file at /proc/config, give
-		 * it a try.
-		 * Sometimes it is also at /proc/config.gz but we do not try
-		 * this one for now, it would require linking against libz.
+	if (!file) {
+		/* Some distributions build with CONFIG_IKCONFIG=y and put the
+		 * config file at /proc/config.gz.
 		 */
-		fd = fopen("/proc/config", "r");
+		file = gzopen("/proc/config.gz", "r");
 	}
-	if (!fd) {
+	if (!file) {
 		p_info("skipping kernel config, can't open file: %s",
 		       strerror(errno));
-		goto no_config;
+		goto end_parse;
 	}
 	/* Sanity checks */
-	ret = getline(&buf, &n, fd);
-	ret = getline(&buf, &n, fd);
-	if (!buf || !ret) {
+	if (!gzgets(file, buf, sizeof(buf)) ||
+	    !gzgets(file, buf, sizeof(buf))) {
 		p_info("skipping kernel config, can't read from file: %s",
 		       strerror(errno));
-		free(buf);
-		goto no_config;
+		goto end_parse;
 	}
 	if (strcmp(buf, "# Automatically generated file; DO NOT EDIT.\n")) {
 		p_info("skipping kernel config, can't find correct file");
-		free(buf);
-		goto no_config;
+		goto end_parse;
 	}
-	free(buf);
 
-	for (i = 0; i < ARRAY_SIZE(options); i++) {
-		value = get_kernel_config_option(fd, options[i]);
-		print_kernel_option(options[i], value);
-		free(value);
+	while (read_next_kernel_config_option(file, buf, sizeof(buf), &value)) {
+		for (i = 0; i < ARRAY_SIZE(options); i++) {
+			if (values[i] || strcmp(buf, options[i]))
+				continue;
+
+			values[i] = strdup(value);
+		}
 	}
-	fclose(fd);
-	return;
 
-no_config:
-	for (i = 0; i < ARRAY_SIZE(options); i++)
-		print_kernel_option(options[i], NULL);
+end_parse:
+	if (file)
+		gzclose(file);
+
+	for (i = 0; i < ARRAY_SIZE(options); i++) {
+		print_kernel_option(options[i], values[i]);
+		free(values[i]);
+	}
 }
 
 static bool probe_bpf_syscall(const char *define_prefix)
-- 
2.22.0


^ permalink raw reply related

* [PATCHv2 net 2/2] ibmveth: use netdev_err_ratelimited when set_multicast_list
From: Hangbin Liu @ 2019-08-09  0:29 UTC (permalink / raw)
  To: netdev; +Cc: Joe Perches, Thomas Falcon, David S . Miller, Hangbin Liu
In-Reply-To: <20190809002941.15341-1-liuhangbin@gmail.com>

When add lots of (e.g. add 3000) memberships in one multicast group on
ibmveth, the following error message flushes our console log file

8507    [  901.478251] ibmveth 30000003 env3: h_multicast_ctrl rc=4 when adding an entry to the filter table
...
1718386 [ 5636.808658] ibmveth 30000003 env3: h_multicast_ctrl rc=4 when adding an entry to the filter table

We got 1.5 million lines of messages in 1.3h. Let's replace netdev_err() by
netdev_err_ratelimited() to avoid this issue.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 drivers/net/ethernet/ibm/ibmveth.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index d654c234aaf7..138523ee5e84 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -1446,9 +1446,8 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
 						   IbmVethMcastAddFilter,
 						   mcast_addr);
 			if (lpar_rc != H_SUCCESS) {
-				netdev_err(netdev, "h_multicast_ctrl rc=%ld "
-					   "when adding an entry to the filter "
-					   "table\n", lpar_rc);
+				netdev_err_ratelimited(netdev, "h_multicast_ctrl rc=%ld when adding an entry to the filter table\n",
+						       lpar_rc);
 			}
 		}
 
-- 
2.19.2


^ permalink raw reply related

* [PATCHv2 net 1/2] netdevice.h: add netdev_level_ratelimited for netdevice
From: Hangbin Liu @ 2019-08-09  0:29 UTC (permalink / raw)
  To: netdev; +Cc: Joe Perches, Thomas Falcon, David S . Miller, Hangbin Liu
In-Reply-To: <20190809002941.15341-1-liuhangbin@gmail.com>

Add netdev_level_ratelimited so we can use it in the future.
The code is copied from device.h.

Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 include/linux/netdevice.h | 53 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 88292953aa6f..4e37065c6717 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -4737,6 +4737,59 @@ do {								\
 #define netdev_info_once(dev, fmt, ...) \
 	netdev_level_once(KERN_INFO, dev, fmt, ##__VA_ARGS__)
 
+#define netdev_level_ratelimited(netdev_level, dev, fmt, ...)		\
+do {									\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+	if (__ratelimit(&_rs))						\
+		netdev_level(dev, fmt, ##__VA_ARGS__);			\
+} while (0)
+
+#define netdev_emerg_ratelimited(dev, fmt, ...)				\
+	netdev_level_ratelimited(netdev_emerg, dev, fmt, ##__VA_ARGS__)
+#define netdev_alert_ratelimited(dev, fmt, ...)				\
+	netdev_level_ratelimited(netdev_alert, dev, fmt, ##__VA_ARGS__)
+#define netdev_crit_ratelimited(dev, fmt, ...)				\
+	netdev_level_ratelimited(netdev_crit, dev, fmt, ##__VA_ARGS__)
+#define netdev_err_ratelimited(dev, fmt, ...)				\
+	netdev_level_ratelimited(netdev_err, dev, fmt, ##__VA_ARGS__)
+#define netdev_warn_ratelimited(dev, fmt, ...)				\
+	netdev_level_ratelimited(netdev_warn, dev, fmt, ##__VA_ARGS__)
+#define netdev_notice_ratelimited(dev, fmt, ...)			\
+	netdev_level_ratelimited(netdev_notice, dev, fmt, ##__VA_ARGS__)
+#define netdev_info_ratelimited(dev, fmt, ...)				\
+	netdev_level_ratelimited(netdev_info, dev, fmt, ##__VA_ARGS__)
+#if defined(CONFIG_DYNAMIC_DEBUG)
+/* descriptor check is first to prevent flooding with "callbacks suppressed" */
+#define netdev_dbg_ratelimited(dev, fmt, ...)				\
+do {									\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);			\
+	if (DYNAMIC_DEBUG_BRANCH(descriptor) &&				\
+	    __ratelimit(&_rs))						\
+		__dynamic_netdev_dbg(&descriptor, dev, dev_fmt(fmt),	\
+				     ##__VA_ARGS__);			\
+} while (0)
+#elif defined(DEBUG)
+#define netdev_dbg_ratelimited(dev, fmt, ...)				\
+do {									\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+	if (__ratelimit(&_rs))						\
+		netdev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+} while (0)
+#else
+#define netdev_dbg_ratelimited(dev, fmt, ...)				\
+do {									\
+	if (0)								\
+		netdev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+} while (0)
+#endif
+
 #define MODULE_ALIAS_NETDEV(device) \
 	MODULE_ALIAS("netdev-" device)
 
-- 
2.19.2


^ permalink raw reply related

* [PATCHv2 net 0/2] Add netdev_level_ratelimited to avoid netdev msg flush
From: Hangbin Liu @ 2019-08-09  0:29 UTC (permalink / raw)
  To: netdev; +Cc: Joe Perches, Thomas Falcon, David S . Miller, Hangbin Liu
In-Reply-To: <20190801090347.8258-1-liuhangbin@gmail.com>

This patch set add netdev_level_ratelimited to avoid netdev msg flush.
The second patch fixed ibmveth msg flush when add lots of(e.g. 2000) group
memberships in one group at the same time.

In my testing, there will be the

ibmveth 30000003 env3: h_multicast_ctrl rc=4 when adding an entry to the filter table

error when add more thann 256 memberships in one multicast group. I haven't
found this issue on other driver. It looks like an ibm driver issue and need
to be fixed separately.

v2: add netdev_level_ratelimited as Joe Perches suggested

Hangbin Liu (2):
  netdevice.h: add netdev_level_ratelimited for netdevice
  ibmveth: use net_err_ratelimited when set_multicast_list

 drivers/net/ethernet/ibm/ibmveth.c |  5 ++-
 include/linux/netdevice.h          | 53 ++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 3 deletions(-)

-- 
2.19.2


^ permalink raw reply

* Re: KASAN: use-after-free Read in tls_wait_data
From: Jakub Kicinski @ 2019-08-09  0:20 UTC (permalink / raw)
  To: syzbot
  Cc: ast, aviadye, borisp, bpf, daniel, davejwatson, davem,
	john.fastabend, kafai, linux-kernel, netdev, songliubraving,
	syzkaller-bugs, yhs
In-Reply-To: <000000000000262820058f9dc474@google.com>

On Thu, 08 Aug 2019 09:44:07 -0700, syzbot wrote:
> Hello,
> 
> syzbot found the following crash on:
> 
> HEAD commit:    7b4980e0 Add linux-next specific files for 20190802
> git tree:       linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=14a749b4600000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=7e1348afd44b5e02
> dashboard link: https://syzkaller.appspot.com/bug?extid=30c791a76814a3c6c9f9
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> 
> Unfortunately, I don't have any reproducer for this crash yet.
> 
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+30c791a76814a3c6c9f9@syzkaller.appspotmail.com

Also old tree, pretty confidently I can say:

#syz fix: net/tls: partially revert fix transition through disconnect with close

^ permalink raw reply

* Re: general protection fault in tls_tx_records
From: Jakub Kicinski @ 2019-08-09  0:19 UTC (permalink / raw)
  To: syzbot
  Cc: ast, aviadye, borisp, bpf, daniel, davejwatson, davem,
	john.fastabend, kafai, linux-kernel, netdev, songliubraving,
	syzkaller-bugs, yhs
In-Reply-To: <000000000000216779058f9dc40e@google.com>

On Thu, 08 Aug 2019 09:44:06 -0700, syzbot wrote:
> Hello,
> 
> syzbot found the following crash on:
> 
> HEAD commit:    ce96e791 Add linux-next specific files for 20190731
> git tree:       linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=13ce4fd0600000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=fca5b9d53db6585c
> dashboard link: https://syzkaller.appspot.com/bug?extid=97d0cf528b9c8e9be7f4
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)

Looks like this was an old tree here, so most likely:

#syz fix: net/tls: partially revert fix transition through disconnect with close

^ permalink raw reply

* Re: [v3,2/4] tools: bpftool: add net detach command to detach XDP on interface
From: Jakub Kicinski @ 2019-08-09  0:05 UTC (permalink / raw)
  To: Y Song
  Cc: Maciej Fijalkowski, Daniel T. Lee, Daniel Borkmann,
	Alexei Starovoitov, netdev
In-Reply-To: <CAH3MdRWeD+9Lmz+mJt3EnNkX8kbcyCW4sNgRindCiObnzAj-yQ@mail.gmail.com>

On Thu, 8 Aug 2019 12:52:11 -0700, Y Song wrote:
> > Ah ok. In this scenario if driver has a native xdp support we would be invoking
> > its ndo_bpf even if there's no prog currently attached and it wouldn't return
> > error value.
> >
> > Looking at dev_xdp_uninstall, setting driver's prog to NULL is being done only
> > when prog is attached. Maybe we should consider querying the driver in
> > dev_change_xdp_fd regardless of passed fd value? E.g. don't query only when
> > prog >= 0.
> >
> > I don't recall whether this was brought up previously.  
> 
> Thanks for explanation. I think return an error is better in
> such error cases. Otherwise, people mistakenly write wrong
> device name and they may think xdp is detached and it is
> actually not.
> 
> But this probably should not prevent
> this patch as it is more like a kernel issue.

Agreed, we'd probably need a flag here, similar to IF_NOEXIST to keep
backward compat.

^ permalink raw reply

* [PATCH net-next v5 2/3] net: phy: add support for clause 37 auto-negotiation
From: Tao Ren @ 2019-08-08 23:48 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, Heiner Kallweit, David S . Miller,
	Arun Parameswaran, Justin Chen, Vladimir Oltean, netdev,
	linux-kernel, openbmc

From: Heiner Kallweit <hkallweit1@gmail.com>

This patch adds support for clause 37 1000Base-X auto-negotiation.
It's compile-tested only as I don't have fiber equipment.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy_device.c | 139 +++++++++++++++++++++++++++++++++++
 include/linux/phy.h          |   5 ++
 2 files changed, 144 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 252a712d1b2b..7c5315302937 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1617,6 +1617,40 @@ static int genphy_config_advert(struct phy_device *phydev)
 	return changed;
 }
 
+/**
+ * genphy_c37_config_advert - sanitize and advertise auto-negotiation parameters
+ * @phydev: target phy_device struct
+ *
+ * Description: Writes MII_ADVERTISE with the appropriate values,
+ *   after sanitizing the values to make sure we only advertise
+ *   what is supported.  Returns < 0 on error, 0 if the PHY's advertisement
+ *   hasn't changed, and > 0 if it has changed. This function is intended
+ *   for Clause 37 1000Base-X mode.
+ */
+static int genphy_c37_config_advert(struct phy_device *phydev)
+{
+	u16 adv = 0;
+
+	/* Only allow advertising what this PHY supports */
+	linkmode_and(phydev->advertising, phydev->advertising,
+		     phydev->supported);
+
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
+			      phydev->advertising))
+		adv |= ADVERTISE_1000XFULL;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,
+			      phydev->advertising))
+		adv |= ADVERTISE_1000XPAUSE;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+			      phydev->advertising))
+		adv |= ADVERTISE_1000XPSE_ASYM;
+
+	return phy_modify_changed(phydev, MII_ADVERTISE,
+				  ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
+				  ADVERTISE_1000XHALF | ADVERTISE_1000XPSE_ASYM,
+				  adv);
+}
+
 /**
  * genphy_config_eee_advert - disable unwanted eee mode advertisement
  * @phydev: target phy_device struct
@@ -1726,6 +1760,54 @@ int genphy_config_aneg(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_config_aneg);
 
+/**
+ * genphy_c37_config_aneg - restart auto-negotiation or write BMCR
+ * @phydev: target phy_device struct
+ *
+ * Description: If auto-negotiation is enabled, we configure the
+ *   advertising, and then restart auto-negotiation.  If it is not
+ *   enabled, then we write the BMCR. This function is intended
+ *   for use with Clause 37 1000Base-X mode.
+ */
+int genphy_c37_config_aneg(struct phy_device *phydev)
+{
+	int err, changed;
+
+	if (AUTONEG_ENABLE != phydev->autoneg)
+		return genphy_setup_forced(phydev);
+
+	err = phy_modify(phydev, MII_BMCR, BMCR_SPEED1000 | BMCR_SPEED100,
+			 BMCR_SPEED1000);
+	if (err)
+		return err;
+
+	changed = genphy_c37_config_advert(phydev);
+	if (changed < 0) /* error */
+		return changed;
+
+	if (!changed) {
+		/* Advertisement hasn't changed, but maybe aneg was never on to
+		 * begin with?  Or maybe phy was isolated?
+		 */
+		int ctl = phy_read(phydev, MII_BMCR);
+
+		if (ctl < 0)
+			return ctl;
+
+		if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
+			changed = 1; /* do restart aneg */
+	}
+
+	/* Only restart aneg if we are advertising something different
+	 * than we were before.
+	 */
+	if (changed > 0)
+		return genphy_restart_aneg(phydev);
+
+	return 0;
+}
+EXPORT_SYMBOL(genphy_c37_config_aneg);
+
 /**
  * genphy_aneg_done - return auto-negotiation status
  * @phydev: target phy_device struct
@@ -1864,6 +1946,63 @@ int genphy_read_status(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_read_status);
 
+/**
+ * genphy_c37_read_status - check the link status and update current link state
+ * @phydev: target phy_device struct
+ *
+ * Description: Check the link, then figure out the current state
+ *   by comparing what we advertise with what the link partner
+ *   advertises. This function is for Clause 37 1000Base-X mode.
+ */
+int genphy_c37_read_status(struct phy_device *phydev)
+{
+	int lpa, err, old_link = phydev->link;
+
+	/* Update the link, but return if there was an error */
+	err = genphy_update_link(phydev);
+	if (err)
+		return err;
+
+	/* why bother the PHY if nothing can have changed */
+	if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
+		return 0;
+
+	phydev->duplex = DUPLEX_UNKNOWN;
+	phydev->pause = 0;
+	phydev->asym_pause = 0;
+
+	if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
+		lpa = phy_read(phydev, MII_LPA);
+		if (lpa < 0)
+			return lpa;
+
+		linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+				 phydev->lp_advertising, lpa & LPA_LPACK);
+		linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
+				 phydev->lp_advertising, lpa & LPA_1000XFULL);
+		linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT,
+				 phydev->lp_advertising, lpa & LPA_1000XPAUSE);
+		linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+				 phydev->lp_advertising,
+				 lpa & LPA_1000XPAUSE_ASYM);
+
+		phy_resolve_aneg_linkmode(phydev);
+	} else if (phydev->autoneg == AUTONEG_DISABLE) {
+		int bmcr = phy_read(phydev, MII_BMCR);
+
+		if (bmcr < 0)
+			return bmcr;
+
+		if (bmcr & BMCR_FULLDPLX)
+			phydev->duplex = DUPLEX_FULL;
+		else
+			phydev->duplex = DUPLEX_HALF;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(genphy_c37_read_status);
+
 /**
  * genphy_soft_reset - software reset the PHY via BMCR_RESET bit
  * @phydev: target phy_device struct
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 462b90b73f93..81a2921512ee 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1077,6 +1077,11 @@ int genphy_suspend(struct phy_device *phydev);
 int genphy_resume(struct phy_device *phydev);
 int genphy_loopback(struct phy_device *phydev, bool enable);
 int genphy_soft_reset(struct phy_device *phydev);
+
+/* Clause 37 */
+int genphy_c37_config_aneg(struct phy_device *phydev);
+int genphy_c37_read_status(struct phy_device *phydev);
+
 static inline int genphy_no_soft_reset(struct phy_device *phydev)
 {
 	return 0;
-- 
2.17.1


^ permalink raw reply related

* [PATCH v2 net-next 2/2] net: mvpp2: support multiple comphy lanes
From: Matt Pelland @ 2019-08-08 23:06 UTC (permalink / raw)
  To: netdev; +Cc: Matt Pelland, davem, maxime.chevallier, antoine.tenart
In-Reply-To: <20190808230606.7900-1-mpelland@starry.com>

mvpp 2.2 supports RXAUI, which requires two serdes lanes, and XAUI which
requires four serdes lanes instead of the usual single lane required by other
interface modes. This patch expands the number of lanes that can be associated
to a port so that all relevant serdes lanes are correctly configured at the
appropriate times when either RXAUI or XAUI is in use.

Signed-off-by: Matt Pelland <mpelland@starry.com>
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h    |  7 +-
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 97 ++++++++++++++-----
 2 files changed, 77 insertions(+), 27 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 256e7c796631..d74f458ca099 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -655,6 +655,11 @@
 #define MVPP2_F_LOOPBACK		BIT(0)
 #define MVPP2_F_DT_COMPAT		BIT(1)
 
+/* MVPP22 supports RXAUI which requires two comphy lanes and XAUI which
+ * requires four comphy lanes. All other modes require one.
+ */
+#define MVPP22_MAX_COMPHYS		4
+
 /* Marvell tag types */
 enum mvpp2_tag_type {
 	MVPP2_TAG_TYPE_NONE = 0,
@@ -935,7 +940,7 @@ struct mvpp2_port {
 	phy_interface_t phy_interface;
 	struct phylink *phylink;
 	struct phylink_config phylink_config;
-	struct phy *comphy;
+	struct phy *comphys[MVPP22_MAX_COMPHYS];
 
 	struct mvpp2_bm_pool *pool_long;
 	struct mvpp2_bm_pool *pool_short;
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 1a5037a398fc..100972703f60 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1200,17 +1200,40 @@ static void mvpp22_gop_setup_irq(struct mvpp2_port *port)
  */
 static int mvpp22_comphy_init(struct mvpp2_port *port)
 {
-	int ret;
+	int i, ret;
 
-	if (!port->comphy)
-		return 0;
+	for (i = 0; i < ARRAY_SIZE(port->comphys); i++) {
+		if (!port->comphys[i])
+			return 0;
 
-	ret = phy_set_mode_ext(port->comphy, PHY_MODE_ETHERNET,
-			       port->phy_interface);
-	if (ret)
-		return ret;
+		ret = phy_set_mode_ext(port->comphys[i],
+				       PHY_MODE_ETHERNET,
+				       port->phy_interface);
+		if (ret)
+			return ret;
+
+		ret = phy_power_on(port->comphys[i]);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int mvpp22_comphy_deinit(struct mvpp2_port *port)
+{
+	int i, ret;
+
+	for (i = 0; i < ARRAY_SIZE(port->comphys); i++) {
+		if (!port->comphys[i])
+			return 0;
+
+		ret = phy_power_off(port->comphys[i]);
+		if (ret)
+			return ret;
+	}
 
-	return phy_power_on(port->comphy);
+	return 0;
 }
 
 static void mvpp2_port_enable(struct mvpp2_port *port)
@@ -3389,7 +3412,9 @@ static void mvpp2_stop_dev(struct mvpp2_port *port)
 
 	if (port->phylink)
 		phylink_stop(port->phylink);
-	phy_power_off(port->comphy);
+
+	if (port->priv->hw_version == MVPP22)
+		mvpp22_comphy_deinit(port);
 }
 
 static int mvpp2_check_ringparam_valid(struct net_device *dev,
@@ -4946,7 +4971,7 @@ static void mvpp2_mac_config(struct phylink_config *config, unsigned int mode,
 		port->phy_interface = state->interface;
 
 		/* Reconfigure the serdes lanes */
-		phy_power_off(port->comphy);
+		mvpp22_comphy_deinit(port);
 		mvpp22_mode_reconfigure(port);
 	}
 
@@ -5037,20 +5062,18 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 			    struct fwnode_handle *port_fwnode,
 			    struct mvpp2 *priv)
 {
-	struct phy *comphy = NULL;
-	struct mvpp2_port *port;
-	struct mvpp2_port_pcpu *port_pcpu;
+	unsigned int ntxqs, nrxqs, ncomphys, nrequired_comphys, thread;
 	struct device_node *port_node = to_of_node(port_fwnode);
+	struct mvpp2_port_pcpu *port_pcpu;
 	netdev_features_t features;
-	struct net_device *dev;
 	struct phylink *phylink;
-	char *mac_from = "";
-	unsigned int ntxqs, nrxqs, thread;
+	struct mvpp2_port *port;
 	unsigned long flags = 0;
+	struct net_device *dev;
+	int err, i, phy_mode;
+	char *mac_from = "";
 	bool has_tx_irqs;
 	u32 id;
-	int phy_mode;
-	int err, i;
 
 	has_tx_irqs = mvpp2_port_has_irqs(priv, port_node, &flags);
 	if (!has_tx_irqs && queue_mode == MVPP2_QDIST_MULTI_MODE) {
@@ -5084,14 +5107,38 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 		goto err_free_netdev;
 	}
 
+	port = netdev_priv(dev);
+
 	if (port_node) {
-		comphy = devm_of_phy_get(&pdev->dev, port_node, NULL);
-		if (IS_ERR(comphy)) {
-			if (PTR_ERR(comphy) == -EPROBE_DEFER) {
-				err = -EPROBE_DEFER;
-				goto err_free_netdev;
+		for (i = 0, ncomphys = 0; i < ARRAY_SIZE(port->comphys); i++) {
+			port->comphys[i] = devm_of_phy_get_by_index(&pdev->dev,
+								    port_node,
+								    i);
+			if (IS_ERR(port->comphys[i])) {
+				err = PTR_ERR(port->comphys[i]);
+				port->comphys[i] = NULL;
+				if (err == -EPROBE_DEFER)
+					goto err_free_netdev;
+				err = 0;
+				break;
 			}
-			comphy = NULL;
+
+			++ncomphys;
+		}
+
+		if (phy_mode == PHY_INTERFACE_MODE_XAUI)
+			nrequired_comphys = 4;
+		else if (phy_mode == PHY_INTERFACE_MODE_RXAUI)
+			nrequired_comphys = 2;
+		else
+			nrequired_comphys = 1;
+
+		if (ncomphys < nrequired_comphys) {
+			dev_err(&pdev->dev,
+				"not enough comphys to support %s\n",
+				phy_modes(phy_mode));
+			err = -EINVAL;
+			goto err_free_netdev;
 		}
 	}
 
@@ -5106,7 +5153,6 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 	dev->netdev_ops = &mvpp2_netdev_ops;
 	dev->ethtool_ops = &mvpp2_eth_tool_ops;
 
-	port = netdev_priv(dev);
 	port->dev = dev;
 	port->fwnode = port_fwnode;
 	port->has_phy = !!of_find_property(port_node, "phy", NULL);
@@ -5143,7 +5189,6 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 
 	port->of_node = port_node;
 	port->phy_interface = phy_mode;
-	port->comphy = comphy;
 
 	if (priv->hw_version == MVPP21) {
 		port->base = devm_platform_ioremap_resource(pdev, 2 + id);
-- 
2.21.0


^ 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