diff mbox series

[net,v2,2/2] net: dsa: b53: Support setting learning on port

Message ID 20210222223010.2907234-3-f.fainelli@gmail.com (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: Learning fixes for b53/bcm_sf2 | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 81 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Florian Fainelli Feb. 22, 2021, 10:30 p.m. UTC
Add support for being able to set the learning attribute on port, and
make sure that the standalone ports start up with learning disabled.

We can remove the code in bcm_sf2 that configured the ports learning
attribute because we want the standalone ports to have learning disabled
by default and port 7 cannot be bridged, so its learning attribute will
not change past its initial configuration.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 20 +++++++++++++++++++-
 drivers/net/dsa/b53/b53_regs.h   |  1 +
 drivers/net/dsa/bcm_sf2.c        | 15 +--------------
 3 files changed, 21 insertions(+), 15 deletions(-)

Comments

Vladimir Oltean Feb. 22, 2021, 11:18 p.m. UTC | #1
On Mon, Feb 22, 2021 at 02:30:10PM -0800, Florian Fainelli wrote:
> diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
> index c90985c294a2..b2c539a42154 100644
> --- a/drivers/net/dsa/b53/b53_regs.h
> +++ b/drivers/net/dsa/b53/b53_regs.h
> @@ -115,6 +115,7 @@
>  #define B53_UC_FLOOD_MASK		0x32
>  #define B53_MC_FLOOD_MASK		0x34
>  #define B53_IPMC_FLOOD_MASK		0x36
> +#define B53_DIS_LEARNING		0x3c
>  
>  /*
>   * Override Ports 0-7 State on devices with xMII interfaces (8 bit)
> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
> index 3eaedbb12815..5ee8103b8e9c 100644
> --- a/drivers/net/dsa/bcm_sf2.c
> +++ b/drivers/net/dsa/bcm_sf2.c
> @@ -223,23 +223,10 @@ static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,
>  	reg &= ~P_TXQ_PSM_VDD(port);
>  	core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL);
>  
> -	/* Enable learning */
> -	reg = core_readl(priv, CORE_DIS_LEARN);
> -	reg &= ~BIT(port);
> -	core_writel(priv, reg, CORE_DIS_LEARN);
> -
>  	/* Enable Broadcom tags for that port if requested */
> -	if (priv->brcm_tag_mask & BIT(port)) {
> +	if (priv->brcm_tag_mask & BIT(port))
>  		b53_brcm_hdr_setup(ds, port);
>  
> -		/* Disable learning on ASP port */
> -		if (port == 7) {
> -			reg = core_readl(priv, CORE_DIS_LEARN);
> -			reg |= BIT(port);
> -			core_writel(priv, reg, CORE_DIS_LEARN);
> -		}
> -	}
> -

In sf2, CORE_DIS_LEARN is at address 0xf0, while in b53, B53_DIS_LEARN
is at 0x3c. Are they even configuring the same thing?
Florian Fainelli Feb. 22, 2021, 11:44 p.m. UTC | #2
On 2/22/2021 3:18 PM, Vladimir Oltean wrote:
> On Mon, Feb 22, 2021 at 02:30:10PM -0800, Florian Fainelli wrote:
>> diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
>> index c90985c294a2..b2c539a42154 100644
>> --- a/drivers/net/dsa/b53/b53_regs.h
>> +++ b/drivers/net/dsa/b53/b53_regs.h
>> @@ -115,6 +115,7 @@
>>  #define B53_UC_FLOOD_MASK		0x32
>>  #define B53_MC_FLOOD_MASK		0x34
>>  #define B53_IPMC_FLOOD_MASK		0x36
>> +#define B53_DIS_LEARNING		0x3c
>>  
>>  /*
>>   * Override Ports 0-7 State on devices with xMII interfaces (8 bit)
>> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
>> index 3eaedbb12815..5ee8103b8e9c 100644
>> --- a/drivers/net/dsa/bcm_sf2.c
>> +++ b/drivers/net/dsa/bcm_sf2.c
>> @@ -223,23 +223,10 @@ static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,
>>  	reg &= ~P_TXQ_PSM_VDD(port);
>>  	core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL);
>>  
>> -	/* Enable learning */
>> -	reg = core_readl(priv, CORE_DIS_LEARN);
>> -	reg &= ~BIT(port);
>> -	core_writel(priv, reg, CORE_DIS_LEARN);
>> -
>>  	/* Enable Broadcom tags for that port if requested */
>> -	if (priv->brcm_tag_mask & BIT(port)) {
>> +	if (priv->brcm_tag_mask & BIT(port))
>>  		b53_brcm_hdr_setup(ds, port);
>>  
>> -		/* Disable learning on ASP port */
>> -		if (port == 7) {
>> -			reg = core_readl(priv, CORE_DIS_LEARN);
>> -			reg |= BIT(port);
>> -			core_writel(priv, reg, CORE_DIS_LEARN);
>> -		}
>> -	}
>> -
> 
> In sf2, CORE_DIS_LEARN is at address 0xf0, while in b53, B53_DIS_LEARN
> is at 0x3c. Are they even configuring the same thing?

They are the SF2 switch was integrated with a bridge that would flatten
its address space such that there would be no need to access the
registers indirectly like what b53_srab does.

This is the reason why we have the SF2_PAGE_REG_MKADDR() macro to
convert from a {page, offset} tuple to a memory mapped address and here
0x3c << 2 = 0xf0.
Vladimir Oltean Feb. 23, 2021, 12:10 a.m. UTC | #3
On Mon, Feb 22, 2021 at 03:44:21PM -0800, Florian Fainelli wrote:
> > In sf2, CORE_DIS_LEARN is at address 0xf0, while in b53, B53_DIS_LEARN
> > is at 0x3c. Are they even configuring the same thing?
> 
> They are the SF2 switch was integrated with a bridge that would flatten
> its address space such that there would be no need to access the
> registers indirectly like what b53_srab does.
> 
> This is the reason why we have the SF2_PAGE_REG_MKADDR() macro to
> convert from a {page, offset} tuple to a memory mapped address and here
> 0x3c << 2 = 0xf0.

Thanks, now I have more context to understand why sf2 uses one kind of
I/O and b53 another, and also how the paged address map managed by the
b53 driver gets linearized before accessing the sf2 registers.

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
diff mbox series

Patch

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index fceca3f5b6a5..a162499bcafc 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -543,6 +543,19 @@  static void b53_port_set_mcast_flood(struct b53_device *dev, int port,
 	b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc);
 }
 
+static void b53_port_set_learning(struct b53_device *dev, int port,
+				  bool learning)
+{
+	u16 reg;
+
+	b53_read16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, &reg);
+	if (learning)
+		reg &= ~BIT(port);
+	else
+		reg |= BIT(port);
+	b53_write16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, reg);
+}
+
 int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
 {
 	struct b53_device *dev = ds->priv;
@@ -557,6 +570,7 @@  int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
 
 	b53_port_set_ucast_flood(dev, port, true);
 	b53_port_set_mcast_flood(dev, port, true);
+	b53_port_set_learning(dev, port, false);
 
 	if (dev->ops->irq_enable)
 		ret = dev->ops->irq_enable(dev, port);
@@ -691,6 +705,7 @@  static void b53_enable_cpu_port(struct b53_device *dev, int port)
 
 	b53_port_set_ucast_flood(dev, port, true);
 	b53_port_set_mcast_flood(dev, port, true);
+	b53_port_set_learning(dev, port, false);
 }
 
 static void b53_enable_mib(struct b53_device *dev)
@@ -1957,7 +1972,7 @@  int b53_br_flags_pre(struct dsa_switch *ds, int port,
 		     struct switchdev_brport_flags flags,
 		     struct netlink_ext_ack *extack)
 {
-	if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD))
+	if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_LEARNING))
 		return -EINVAL;
 
 	return 0;
@@ -1974,6 +1989,9 @@  int b53_br_flags(struct dsa_switch *ds, int port,
 	if (flags.mask & BR_MCAST_FLOOD)
 		b53_port_set_mcast_flood(ds->priv, port,
 					 !!(flags.val & BR_MCAST_FLOOD));
+	if (flags.mask & BR_LEARNING)
+		b53_port_set_learning(ds->priv, port,
+				      !!(flags.val & BR_LEARNING));
 
 	return 0;
 }
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index c90985c294a2..b2c539a42154 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -115,6 +115,7 @@ 
 #define B53_UC_FLOOD_MASK		0x32
 #define B53_MC_FLOOD_MASK		0x34
 #define B53_IPMC_FLOOD_MASK		0x36
+#define B53_DIS_LEARNING		0x3c
 
 /*
  * Override Ports 0-7 State on devices with xMII interfaces (8 bit)
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 3eaedbb12815..5ee8103b8e9c 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -223,23 +223,10 @@  static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,
 	reg &= ~P_TXQ_PSM_VDD(port);
 	core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL);
 
-	/* Enable learning */
-	reg = core_readl(priv, CORE_DIS_LEARN);
-	reg &= ~BIT(port);
-	core_writel(priv, reg, CORE_DIS_LEARN);
-
 	/* Enable Broadcom tags for that port if requested */
-	if (priv->brcm_tag_mask & BIT(port)) {
+	if (priv->brcm_tag_mask & BIT(port))
 		b53_brcm_hdr_setup(ds, port);
 
-		/* Disable learning on ASP port */
-		if (port == 7) {
-			reg = core_readl(priv, CORE_DIS_LEARN);
-			reg |= BIT(port);
-			core_writel(priv, reg, CORE_DIS_LEARN);
-		}
-	}
-
 	/* Configure Traffic Class to QoS mapping, allow each priority to map
 	 * to a different queue number
 	 */