2022-08-15 17:53:14

by Florian Fainelli

[permalink] [raw]
Subject: [PATCH net-next 0/2] net: dsa: bcm_sf2: Utilize PHYLINK for all ports

Hi all,

This patch series has the bcm_sf2 driver utilize PHYLINK to configure
the CPU port link parameters to unify the configuration and pave the way
for DSA to utilize PHYLINK for all ports in the future.

Tested on BCM7445 and BCM7278

Florian Fainelli (2):
net: dsa: bcm_sf2: Introduce helper for port override offset
net: dsa: bcm_sf2: Have PHYLINK configure CPU/IMP port(s)

drivers/net/dsa/bcm_sf2.c | 130 ++++++++++++++++++--------------------
1 file changed, 63 insertions(+), 67 deletions(-)

--
2.25.1


2022-08-15 17:54:11

by Florian Fainelli

[permalink] [raw]
Subject: [PATCH net-next 1/2] net: dsa: bcm_sf2: Introduce helper for port override offset

Depending upon the generation of switches, we have different offsets for
configuring a given port's status override where link parameters are
applied. Introduce a helper function that we re-use throughout the code
in order to let phylink callbacks configure the IMP/CPU port(s) in
subsequent changes.

Signed-off-by: Florian Fainelli <[email protected]>
---
drivers/net/dsa/bcm_sf2.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index be0edfa093d0..10de0cffa047 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -94,6 +94,24 @@ static u16 bcm_sf2_reg_led_base(struct bcm_sf2_priv *priv, int port)
return REG_SWITCH_STATUS;
}

+static u32 bcm_sf2_port_override_offset(struct bcm_sf2_priv *priv, int port)
+{
+ switch (priv->type) {
+ case BCM4908_DEVICE_ID:
+ case BCM7445_DEVICE_ID:
+ return port == 8 ? CORE_STS_OVERRIDE_IMP :
+ CORE_STS_OVERRIDE_GMIIP_PORT(port);
+ case BCM7278_DEVICE_ID:
+ return port == 8 ? CORE_STS_OVERRIDE_IMP2 :
+ CORE_STS_OVERRIDE_GMIIP2_PORT(port);
+ default:
+ WARN_ONCE(1, "Unsupported device: %d\n", priv->type);
+ }
+
+ /* RO fallback register */
+ return REG_SWITCH_STATUS;
+}
+
/* Return the number of active ports, not counting the IMP (CPU) port */
static unsigned int bcm_sf2_num_active_ports(struct dsa_switch *ds)
{
@@ -167,11 +185,7 @@ static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port)
b53_brcm_hdr_setup(ds, port);

if (port == 8) {
- if (priv->type == BCM4908_DEVICE_ID ||
- priv->type == BCM7445_DEVICE_ID)
- offset = CORE_STS_OVERRIDE_IMP;
- else
- offset = CORE_STS_OVERRIDE_IMP2;
+ offset = bcm_sf2_port_override_offset(priv, port);

/* Force link status for IMP port */
reg = core_readl(priv, offset);
@@ -813,12 +827,7 @@ static void bcm_sf2_sw_mac_link_down(struct dsa_switch *ds, int port,
return;

if (port != core_readl(priv, CORE_IMP0_PRT_ID)) {
- if (priv->type == BCM4908_DEVICE_ID ||
- priv->type == BCM7445_DEVICE_ID)
- offset = CORE_STS_OVERRIDE_GMIIP_PORT(port);
- else
- offset = CORE_STS_OVERRIDE_GMIIP2_PORT(port);
-
+ offset = bcm_sf2_port_override_offset(priv, port);
reg = core_readl(priv, offset);
reg &= ~LINK_STS;
core_writel(priv, reg, offset);
@@ -843,11 +852,7 @@ static void bcm_sf2_sw_mac_link_up(struct dsa_switch *ds, int port,
u32 reg_rgmii_ctrl = 0;
u32 reg, offset;

- if (priv->type == BCM4908_DEVICE_ID ||
- priv->type == BCM7445_DEVICE_ID)
- offset = CORE_STS_OVERRIDE_GMIIP_PORT(port);
- else
- offset = CORE_STS_OVERRIDE_GMIIP2_PORT(port);
+ offset = bcm_sf2_port_override_offset(priv, port);

if (interface == PHY_INTERFACE_MODE_RGMII ||
interface == PHY_INTERFACE_MODE_RGMII_TXID ||
--
2.25.1

2022-08-15 18:47:28

by Florian Fainelli

[permalink] [raw]
Subject: [PATCH net-next 2/2] net: dsa: bcm_sf2: Have PHYLINK configure CPU/IMP port(s)

Remove the artificial limitations imposed upon
bcm_sf2_sw_mac_link_{up,down} and allow us to override the link
parameters for IMP port(s) as well as regular ports by accounting for
the special differences that exist there.

Remove the code that did override the link parameters in
bcm_sf2_imp_setup().

Signed-off-by: Florian Fainelli <[email protected]>
---
drivers/net/dsa/bcm_sf2.c | 95 ++++++++++++++++++---------------------
1 file changed, 43 insertions(+), 52 deletions(-)

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 10de0cffa047..572f7450b527 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -159,7 +159,7 @@ static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port)
{
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
unsigned int i;
- u32 reg, offset;
+ u32 reg;

/* Enable the port memories */
reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL);
@@ -185,17 +185,6 @@ static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port)
b53_brcm_hdr_setup(ds, port);

if (port == 8) {
- offset = bcm_sf2_port_override_offset(priv, port);
-
- /* Force link status for IMP port */
- reg = core_readl(priv, offset);
- reg |= (MII_SW_OR | LINK_STS);
- if (priv->type == BCM4908_DEVICE_ID)
- reg |= GMII_SPEED_UP_2G;
- else
- reg &= ~GMII_SPEED_UP_2G;
- core_writel(priv, reg, offset);
-
/* Enable Broadcast, Multicast, Unicast forwarding to IMP port */
reg = core_readl(priv, CORE_IMP_CTL);
reg |= (RX_BCST_EN | RX_MCST_EN | RX_UCST_EN);
@@ -826,12 +815,10 @@ static void bcm_sf2_sw_mac_link_down(struct dsa_switch *ds, int port,
if (priv->wol_ports_mask & BIT(port))
return;

- if (port != core_readl(priv, CORE_IMP0_PRT_ID)) {
- offset = bcm_sf2_port_override_offset(priv, port);
- reg = core_readl(priv, offset);
- reg &= ~LINK_STS;
- core_writel(priv, reg, offset);
- }
+ offset = bcm_sf2_port_override_offset(priv, port);
+ reg = core_readl(priv, offset);
+ reg &= ~LINK_STS;
+ core_writel(priv, reg, offset);

bcm_sf2_sw_mac_link_set(ds, port, interface, false);
}
@@ -845,51 +832,55 @@ static void bcm_sf2_sw_mac_link_up(struct dsa_switch *ds, int port,
{
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
struct ethtool_eee *p = &priv->dev->ports[port].eee;
+ u32 reg_rgmii_ctrl = 0;
+ u32 reg, offset;

bcm_sf2_sw_mac_link_set(ds, port, interface, true);

- if (port != core_readl(priv, CORE_IMP0_PRT_ID)) {
- u32 reg_rgmii_ctrl = 0;
- u32 reg, offset;
+ offset = bcm_sf2_port_override_offset(priv, port);

- offset = bcm_sf2_port_override_offset(priv, port);
+ if (phy_interface_mode_is_rgmii(interface) ||
+ interface == PHY_INTERFACE_MODE_MII ||
+ interface == PHY_INTERFACE_MODE_REVMII) {
+ reg_rgmii_ctrl = bcm_sf2_reg_rgmii_cntrl(priv, port);
+ reg = reg_readl(priv, reg_rgmii_ctrl);
+ reg &= ~(RX_PAUSE_EN | TX_PAUSE_EN);

- if (interface == PHY_INTERFACE_MODE_RGMII ||
- interface == PHY_INTERFACE_MODE_RGMII_TXID ||
- interface == PHY_INTERFACE_MODE_MII ||
- interface == PHY_INTERFACE_MODE_REVMII) {
- reg_rgmii_ctrl = bcm_sf2_reg_rgmii_cntrl(priv, port);
- reg = reg_readl(priv, reg_rgmii_ctrl);
- reg &= ~(RX_PAUSE_EN | TX_PAUSE_EN);
+ if (tx_pause)
+ reg |= TX_PAUSE_EN;
+ if (rx_pause)
+ reg |= RX_PAUSE_EN;

- if (tx_pause)
- reg |= TX_PAUSE_EN;
- if (rx_pause)
- reg |= RX_PAUSE_EN;
+ reg_writel(priv, reg, reg_rgmii_ctrl);
+ }

- reg_writel(priv, reg, reg_rgmii_ctrl);
- }
+ reg = LINK_STS;
+ if (port == 8) {
+ if (priv->type == BCM4908_DEVICE_ID)
+ reg |= GMII_SPEED_UP_2G;
+ reg |= MII_SW_OR;
+ } else {
+ reg |= SW_OVERRIDE;
+ }

- reg = SW_OVERRIDE | LINK_STS;
- switch (speed) {
- case SPEED_1000:
- reg |= SPDSTS_1000 << SPEED_SHIFT;
- break;
- case SPEED_100:
- reg |= SPDSTS_100 << SPEED_SHIFT;
- break;
- }
+ switch (speed) {
+ case SPEED_1000:
+ reg |= SPDSTS_1000 << SPEED_SHIFT;
+ break;
+ case SPEED_100:
+ reg |= SPDSTS_100 << SPEED_SHIFT;
+ break;
+ }

- if (duplex == DUPLEX_FULL)
- reg |= DUPLX_MODE;
+ if (duplex == DUPLEX_FULL)
+ reg |= DUPLX_MODE;

- if (tx_pause)
- reg |= TXFLOW_CNTL;
- if (rx_pause)
- reg |= RXFLOW_CNTL;
+ if (tx_pause)
+ reg |= TXFLOW_CNTL;
+ if (rx_pause)
+ reg |= RXFLOW_CNTL;

- core_writel(priv, reg, offset);
- }
+ core_writel(priv, reg, offset);

if (mode == MLO_AN_PHY && phydev)
p->eee_enabled = b53_eee_init(ds, port, phydev);
--
2.25.1

2022-08-17 15:57:24

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH net-next 0/2] net: dsa: bcm_sf2: Utilize PHYLINK for all ports

On Mon, 15 Aug 2022 10:50:07 -0700 Florian Fainelli wrote:
> Hi all,
>
> This patch series has the bcm_sf2 driver utilize PHYLINK to configure
> the CPU port link parameters to unify the configuration and pave the way
> for DSA to utilize PHYLINK for all ports in the future.
>
> Tested on BCM7445 and BCM7278

Last call for reviews..

2022-08-17 18:19:28

by Vladimir Oltean

[permalink] [raw]
Subject: Re: [PATCH net-next 0/2] net: dsa: bcm_sf2: Utilize PHYLINK for all ports

On Wed, Aug 17, 2022 at 08:54:14AM -0700, Jakub Kicinski wrote:
> On Mon, 15 Aug 2022 10:50:07 -0700 Florian Fainelli wrote:
> > Hi all,
> >
> > This patch series has the bcm_sf2 driver utilize PHYLINK to configure
> > the CPU port link parameters to unify the configuration and pave the way
> > for DSA to utilize PHYLINK for all ports in the future.
> >
> > Tested on BCM7445 and BCM7278
>
> Last call for reviews..

My review is: let's see what breaks...

2022-08-17 18:20:18

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH net-next 0/2] net: dsa: bcm_sf2: Utilize PHYLINK for all ports

On Wed, 17 Aug 2022 20:27:04 +0300 Vladimir Oltean wrote:
> On Wed, Aug 17, 2022 at 08:54:14AM -0700, Jakub Kicinski wrote:
> > On Mon, 15 Aug 2022 10:50:07 -0700 Florian Fainelli wrote:
> > > Hi all,
> > >
> > > This patch series has the bcm_sf2 driver utilize PHYLINK to configure
> > > the CPU port link parameters to unify the configuration and pave the way
> > > for DSA to utilize PHYLINK for all ports in the future.
> > >
> > > Tested on BCM7445 and BCM7278
> >
> > Last call for reviews..
>
> My review is: let's see what breaks...

*nod*, thanks!

2022-08-17 18:45:03

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net-next 0/2] net: dsa: bcm_sf2: Utilize PHYLINK for all ports

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <[email protected]>:

On Mon, 15 Aug 2022 10:50:07 -0700 you wrote:
> Hi all,
>
> This patch series has the bcm_sf2 driver utilize PHYLINK to configure
> the CPU port link parameters to unify the configuration and pave the way
> for DSA to utilize PHYLINK for all ports in the future.
>
> Tested on BCM7445 and BCM7278
>
> [...]

Here is the summary with links:
- [net-next,1/2] net: dsa: bcm_sf2: Introduce helper for port override offset
https://git.kernel.org/netdev/net-next/c/1ed26ce4850a
- [net-next,2/2] net: dsa: bcm_sf2: Have PHYLINK configure CPU/IMP port(s)
https://git.kernel.org/netdev/net-next/c/4d2f6dde4daa

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html