netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: Andrew Lunn <andrew@lunn.ch>
Cc: netdev <netdev@vger.kernel.org>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH RFC RFT net-next 03/10] net: dsa: mv88e6060: Replace REG_WRITE macro
Date: Wed, 30 Jan 2019 10:24:51 +0100	[thread overview]
Message-ID: <20190130092451.GA22071@amd> (raw)
In-Reply-To: <20190130003758.23852-4-andrew@lunn.ch>

[-- Attachment #1: Type: text/plain, Size: 5780 bytes --]

On Wed 2019-01-30 01:37:51, Andrew Lunn wrote:
> The REG_WRITE macro contains a return statement, making it not very
> safe. Remove it by inlining the code.

Not bad, but maybe there should be dev_err() or something in case of
reg_write() returns an error?

Because no errors are expected in this case... AFAICT.
								Pavel

> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  drivers/net/dsa/mv88e6060.c | 73 +++++++++++++++++++++----------------
>  1 file changed, 41 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c
> index 631358bf3d6b..da88c56e092c 100644
> --- a/drivers/net/dsa/mv88e6060.c
> +++ b/drivers/net/dsa/mv88e6060.c
> @@ -39,15 +39,6 @@ static int reg_write(struct mv88e6060_priv *priv, int addr, int reg, u16 val)
>  	return mdiobus_write_nested(priv->bus, priv->sw_addr + addr, reg, val);
>  }
>  
> -#define REG_WRITE(addr, reg, val)				\
> -	({							\
> -		int __ret;					\
> -								\
> -		__ret = reg_write(priv, addr, reg, val);		\
> -		if (__ret < 0)					\
> -			return __ret;				\
> -	})
> -
>  static const char *mv88e6060_get_name(struct mii_bus *bus, int sw_addr)
>  {
>  	int ret;
> @@ -102,17 +93,21 @@ static int mv88e6060_switch_reset(struct mv88e6060_priv *priv)
>  	/* Set all ports to the disabled state. */
>  	for (i = 0; i < MV88E6060_PORTS; i++) {
>  		ret = REG_READ(REG_PORT(i), PORT_CONTROL);
> -		REG_WRITE(REG_PORT(i), PORT_CONTROL,
> -			  ret & ~PORT_CONTROL_STATE_MASK);
> +		ret = reg_write(priv, REG_PORT(i), PORT_CONTROL,
> +				ret & ~PORT_CONTROL_STATE_MASK);
> +		if (ret)
> +			return ret;
>  	}
>  
>  	/* Wait for transmit queues to drain. */
>  	usleep_range(2000, 4000);
>  
>  	/* Reset the switch. */
> -	REG_WRITE(REG_GLOBAL, GLOBAL_ATU_CONTROL,
> -		  GLOBAL_ATU_CONTROL_SWRESET |
> -		  GLOBAL_ATU_CONTROL_LEARNDIS);
> +	ret = reg_write(priv, REG_GLOBAL, GLOBAL_ATU_CONTROL,
> +			GLOBAL_ATU_CONTROL_SWRESET |
> +			GLOBAL_ATU_CONTROL_LEARNDIS);
> +	if (ret)
> +		return ret;
>  
>  	/* Wait up to one second for reset to complete. */
>  	timeout = jiffies + 1 * HZ;
> @@ -131,59 +126,67 @@ static int mv88e6060_switch_reset(struct mv88e6060_priv *priv)
>  
>  static int mv88e6060_setup_global(struct mv88e6060_priv *priv)
>  {
> +	int ret;
> +
>  	/* Disable discarding of frames with excessive collisions,
>  	 * set the maximum frame size to 1536 bytes, and mask all
>  	 * interrupt sources.
>  	 */
> -	REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, GLOBAL_CONTROL_MAX_FRAME_1536);
> +	ret = reg_write(priv, REG_GLOBAL, GLOBAL_CONTROL,
> +			GLOBAL_CONTROL_MAX_FRAME_1536);
> +	if (ret)
> +		return ret;
>  
>  	/* Disable automatic address learning.
>  	 */
> -	REG_WRITE(REG_GLOBAL, GLOBAL_ATU_CONTROL,
> -		  GLOBAL_ATU_CONTROL_LEARNDIS);
> -
> -	return 0;
> +	return reg_write(priv, REG_GLOBAL, GLOBAL_ATU_CONTROL,
> +			 GLOBAL_ATU_CONTROL_LEARNDIS);
>  }
>  
>  static int mv88e6060_setup_port(struct mv88e6060_priv *priv, int p)
>  {
>  	int addr = REG_PORT(p);
> +	int ret;
>  
>  	/* Do not force flow control, disable Ingress and Egress
>  	 * Header tagging, disable VLAN tunneling, and set the port
>  	 * state to Forwarding.  Additionally, if this is the CPU
>  	 * port, enable Ingress and Egress Trailer tagging mode.
>  	 */
> -	REG_WRITE(addr, PORT_CONTROL,
> -		  dsa_is_cpu_port(priv->ds, p) ?
> +	ret = reg_write(priv, addr, PORT_CONTROL,
> +			dsa_is_cpu_port(priv->ds, p) ?
>  			PORT_CONTROL_TRAILER |
>  			PORT_CONTROL_INGRESS_MODE |
>  			PORT_CONTROL_STATE_FORWARDING :
>  			PORT_CONTROL_STATE_FORWARDING);
> +	if (ret)
> +		return ret;
>  
>  	/* Port based VLAN map: give each port its own address
>  	 * database, allow the CPU port to talk to each of the 'real'
>  	 * ports, and allow each of the 'real' ports to only talk to
>  	 * the CPU port.
>  	 */
> -	REG_WRITE(addr, PORT_VLAN_MAP,
> -		  ((p & 0xf) << PORT_VLAN_MAP_DBNUM_SHIFT) |
> -		   (dsa_is_cpu_port(priv->ds, p) ? dsa_user_ports(priv->ds) :
> -		    BIT(dsa_to_port(priv->ds, p)->cpu_dp->index)));
> +	ret = reg_write(priv, addr, PORT_VLAN_MAP,
> +			((p & 0xf) << PORT_VLAN_MAP_DBNUM_SHIFT) |
> +			(dsa_is_cpu_port(priv->ds, p) ?
> +			 dsa_user_ports(priv->ds) :
> +			 BIT(dsa_to_port(priv->ds, p)->cpu_dp->index)));
> +	if (ret)
> +		return ret;
>  
>  	/* Port Association Vector: when learning source addresses
>  	 * of packets, add the address to the address database using
>  	 * a port bitmap that has only the bit for this port set and
>  	 * the other bits clear.
>  	 */
> -	REG_WRITE(addr, PORT_ASSOC_VECTOR, BIT(p));
> -
> -	return 0;
> +	return reg_write(priv, addr, PORT_ASSOC_VECTOR, BIT(p));
>  }
>  
>  static int mv88e6060_setup_addr(struct mv88e6060_priv *priv)
>  {
>  	u8 addr[ETH_ALEN];
> +	int ret;
>  	u16 val;
>  
>  	eth_random_addr(addr);
> @@ -195,11 +198,17 @@ static int mv88e6060_setup_addr(struct mv88e6060_priv *priv)
>  	 */
>  	val &= 0xfeff;
>  
> -	REG_WRITE(REG_GLOBAL, GLOBAL_MAC_01, val);
> -	REG_WRITE(REG_GLOBAL, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
> -	REG_WRITE(REG_GLOBAL, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
> +	ret = reg_write(priv, REG_GLOBAL, GLOBAL_MAC_01, val);
> +	if (ret)
> +		return ret;
> +
> +	ret = reg_write(priv, REG_GLOBAL, GLOBAL_MAC_23,
> +			(addr[2] << 8) | addr[3]);
> +	if (ret)
> +		return ret;
>  
> -	return 0;
> +	return reg_write(priv, REG_GLOBAL, GLOBAL_MAC_45,
> +			 (addr[4] << 8) | addr[5]);
>  }
>  
>  static int mv88e6060_setup(struct dsa_switch *ds)

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2019-01-30  9:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-30  0:37 [PATCH RFC RFT net-next 00/10] Modernize mv88e6060 and remove legacy probe Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 01/10] net: dsa: mv88e6xxx: Remove legacy probe support Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 02/10] net: dsa: mv88e6060: Replace ds with priv Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 03/10] net: dsa: mv88e6060: Replace REG_WRITE macro Andrew Lunn
2019-01-30  9:24   ` Pavel Machek [this message]
2019-01-30 15:42     ` Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 04/10] net: dsa: mv88e6060: Replace REG_READ macro Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 05/10] net: dsa: mv88e6060: Support probing as an mdio device Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 06/10] net: dsa: mv88e6060: Remove support for legacy probing Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 07/10] net: dsa: mv88e6060: Add SPDX header Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 08/10] net: dsa: Remove legacy probing support Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 09/10] arch: arm: dts: Remove disabled marvell,dsa properties Andrew Lunn
2019-01-30  0:37 ` [PATCH RFC RFT net-next 10/10] bt-bindings: net: DSA: Remove legacy binding Andrew Lunn
2019-01-30  9:27 ` [PATCH RFC RFT net-next 00/10] Modernize mv88e6060 and remove legacy probe Pavel Machek
2019-02-06 11:31 ` Gregory CLEMENT
2019-02-06 12:58   ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190130092451.GA22071@amd \
    --to=pavel@ucw.cz \
    --cc=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).