| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 | 
							- From 01e6f8ad8d26ced14b0cf288c42e55d03a7c5070 Mon Sep 17 00:00:00 2001
 
- From: Christian Marangi <[email protected]>
 
- Date: Sun, 30 Jul 2023 09:41:13 +0200
 
- Subject: [PATCH 4/4] net: dsa: qca8k: use dsa_for_each macro instead of for
 
-  loop
 
- Convert for loop to dsa_for_each macro to save some redundant write on
 
- unconnected/unused port and tidy things up.
 
- Signed-off-by: Christian Marangi <[email protected]>
 
- Reviewed-by: Florian Fainelli <[email protected]>
 
- Link: https://lore.kernel.org/r/[email protected]
 
- Signed-off-by: Paolo Abeni <[email protected]>
 
- ---
 
-  drivers/net/dsa/qca/qca8k-8xxx.c | 107 ++++++++++++++++---------------
 
-  1 file changed, 54 insertions(+), 53 deletions(-)
 
- --- a/drivers/net/dsa/qca/qca8k-8xxx.c
 
- +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
 
- @@ -1839,7 +1839,8 @@ static int
 
-  qca8k_setup(struct dsa_switch *ds)
 
-  {
 
-  	struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
 
- -	int cpu_port, ret, i;
 
- +	struct dsa_port *dp;
 
- +	int cpu_port, ret;
 
-  	u32 mask;
 
-  
 
-  	cpu_port = qca8k_find_cpu_port(ds);
 
- @@ -1890,27 +1891,27 @@ qca8k_setup(struct dsa_switch *ds)
 
-  		dev_warn(priv->dev, "mib init failed");
 
-  
 
-  	/* Initial setup of all ports */
 
- -	for (i = 0; i < QCA8K_NUM_PORTS; i++) {
 
- +	dsa_switch_for_each_port(dp, ds) {
 
-  		/* Disable forwarding by default on all ports */
 
- -		ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
 
- +		ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(dp->index),
 
-  				QCA8K_PORT_LOOKUP_MEMBER, 0);
 
-  		if (ret)
 
-  			return ret;
 
- +	}
 
-  
 
- -		/* Enable QCA header mode on all cpu ports */
 
- -		if (dsa_is_cpu_port(ds, i)) {
 
- -			ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(i),
 
- -					  FIELD_PREP(QCA8K_PORT_HDR_CTRL_TX_MASK, QCA8K_PORT_HDR_CTRL_ALL) |
 
- -					  FIELD_PREP(QCA8K_PORT_HDR_CTRL_RX_MASK, QCA8K_PORT_HDR_CTRL_ALL));
 
- -			if (ret) {
 
- -				dev_err(priv->dev, "failed enabling QCA header mode");
 
- -				return ret;
 
- -			}
 
- +	/* Disable MAC by default on all user ports */
 
- +	dsa_switch_for_each_user_port(dp, ds)
 
- +		qca8k_port_set_status(priv, dp->index, 0);
 
- +
 
- +	/* Enable QCA header mode on all cpu ports */
 
- +	dsa_switch_for_each_cpu_port(dp, ds) {
 
- +		ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(dp->index),
 
- +				  FIELD_PREP(QCA8K_PORT_HDR_CTRL_TX_MASK, QCA8K_PORT_HDR_CTRL_ALL) |
 
- +				  FIELD_PREP(QCA8K_PORT_HDR_CTRL_RX_MASK, QCA8K_PORT_HDR_CTRL_ALL));
 
- +		if (ret) {
 
- +			dev_err(priv->dev, "failed enabling QCA header mode on port %d", dp->index);
 
- +			return ret;
 
-  		}
 
- -
 
- -		/* Disable MAC by default on all user ports */
 
- -		if (dsa_is_user_port(ds, i))
 
- -			qca8k_port_set_status(priv, i, 0);
 
-  	}
 
-  
 
-  	/* Forward all unknown frames to CPU port for Linux processing
 
- @@ -1932,48 +1933,48 @@ qca8k_setup(struct dsa_switch *ds)
 
-  		return ret;
 
-  
 
-  	/* Setup connection between CPU port & user ports
 
- -	 * Configure specific switch configuration for ports
 
- +	 * Individual user ports get connected to CPU port only
 
-  	 */
 
- -	for (i = 0; i < QCA8K_NUM_PORTS; i++) {
 
- -		/* Individual user ports get connected to CPU port only */
 
- -		if (dsa_is_user_port(ds, i)) {
 
- -			ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
 
- -					QCA8K_PORT_LOOKUP_MEMBER,
 
- -					BIT(cpu_port));
 
- -			if (ret)
 
- -				return ret;
 
- -
 
- -			ret = regmap_clear_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(i),
 
- -						QCA8K_PORT_LOOKUP_LEARN);
 
- -			if (ret)
 
- -				return ret;
 
- -
 
- -			/* For port based vlans to work we need to set the
 
- -			 * default egress vid
 
- -			 */
 
- -			ret = qca8k_rmw(priv, QCA8K_EGRESS_VLAN(i),
 
- -					QCA8K_EGREES_VLAN_PORT_MASK(i),
 
- -					QCA8K_EGREES_VLAN_PORT(i, QCA8K_PORT_VID_DEF));
 
- -			if (ret)
 
- -				return ret;
 
- -
 
- -			ret = qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(i),
 
- -					  QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
 
- -					  QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
 
- -			if (ret)
 
- -				return ret;
 
- -		}
 
- +	dsa_switch_for_each_user_port(dp, ds) {
 
- +		u8 port = dp->index;
 
-  
 
- -		/* The port 5 of the qca8337 have some problem in flood condition. The
 
- -		 * original legacy driver had some specific buffer and priority settings
 
- -		 * for the different port suggested by the QCA switch team. Add this
 
- -		 * missing settings to improve switch stability under load condition.
 
- -		 * This problem is limited to qca8337 and other qca8k switch are not affected.
 
- +		ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
 
- +				QCA8K_PORT_LOOKUP_MEMBER,
 
- +				BIT(cpu_port));
 
- +		if (ret)
 
- +			return ret;
 
- +
 
- +		ret = regmap_clear_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(port),
 
- +					QCA8K_PORT_LOOKUP_LEARN);
 
- +		if (ret)
 
- +			return ret;
 
- +
 
- +		/* For port based vlans to work we need to set the
 
- +		 * default egress vid
 
-  		 */
 
- -		if (priv->switch_id == QCA8K_ID_QCA8337)
 
- -			qca8k_setup_hol_fixup(priv, i);
 
- +		ret = qca8k_rmw(priv, QCA8K_EGRESS_VLAN(port),
 
- +				QCA8K_EGREES_VLAN_PORT_MASK(port),
 
- +				QCA8K_EGREES_VLAN_PORT(port, QCA8K_PORT_VID_DEF));
 
- +		if (ret)
 
- +			return ret;
 
- +
 
- +		ret = qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(port),
 
- +				  QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
 
- +				  QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
 
- +		if (ret)
 
- +			return ret;
 
-  	}
 
-  
 
- +	/* The port 5 of the qca8337 have some problem in flood condition. The
 
- +	 * original legacy driver had some specific buffer and priority settings
 
- +	 * for the different port suggested by the QCA switch team. Add this
 
- +	 * missing settings to improve switch stability under load condition.
 
- +	 * This problem is limited to qca8337 and other qca8k switch are not affected.
 
- +	 */
 
- +	if (priv->switch_id == QCA8K_ID_QCA8337)
 
- +		dsa_switch_for_each_available_port(dp, ds)
 
- +			qca8k_setup_hol_fixup(priv, dp->index);
 
- +
 
-  	/* Special GLOBAL_FC_THRESH value are needed for ar8327 switch */
 
-  	if (priv->switch_id == QCA8K_ID_QCA8327) {
 
-  		mask = QCA8K_GLOBAL_FC_GOL_XON_THRES(288) |
 
 
  |