* [PATCH] net: dsa: mt7530: add support for in-band link status
@ 2022-09-10 1:12 Daniel Golle
2022-09-11 19:58 ` Russell King (Oracle)
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Golle @ 2022-09-10 1:12 UTC (permalink / raw)
To: linux-mediatek, netdev
Cc: Russell King, Sean Wang, Landen Chao, DENG Qingfang, Andrew Lunn,
Vivien Didelot, Florian Fainelli, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, Philipp Zabel,
Alexander 'lynxis' Couzens
Read link status from SGMII PCS for in-band managed 2500Base-X and
1000Base-X connection on a MAC port of the MT7531. This is needed to
get the SFP cage working which is connected to SGMII interface of
port 5 of the MT7531 switch IC on the Bananapi BPi-R3 board.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/net/dsa/mt7530.c | 48 +++++++++++++++++++++++++++++-----------
1 file changed, 35 insertions(+), 13 deletions(-)
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2703,9 +2703,6 @@ mt7531_mac_config(struct dsa_switch *ds,
case PHY_INTERFACE_MODE_NA:
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_2500BASEX:
- if (phylink_autoneg_inband(mode))
- return -EINVAL;
-
return mt7531_sgmii_setup_mode_force(priv, port, interface);
default:
return -EINVAL;
@@ -2781,13 +2778,6 @@ unsupported:
return;
}
- if (phylink_autoneg_inband(mode) &&
- state->interface != PHY_INTERFACE_MODE_SGMII) {
- dev_err(ds->dev, "%s: in-band negotiation unsupported\n",
- __func__);
- return;
- }
-
mcr_cur = mt7530_read(priv, MT7530_PMCR_P(port));
mcr_new = mcr_cur;
mcr_new &= ~PMCR_LINK_SETTINGS_MASK;
@@ -2924,6 +2914,9 @@ static void mt753x_phylink_get_caps(stru
config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_10 | MAC_100 | MAC_1000FD;
+ if ((priv->id == ID_MT7531) && mt753x_is_mac_port(port))
+ config->mac_capabilities |= MAC_2500FD;
+
/* This driver does not make use of the speed, duplex, pause or the
* advertisement in its mac_config, so it is safe to mark this driver
* as non-legacy.
@@ -3019,16 +3012,43 @@ mt7531_sgmii_pcs_get_state_an(struct mt7
return 0;
}
+static void
+mt7531_sgmii_pcs_get_state_inband(struct mt7530_priv *priv, int port,
+ struct phylink_link_state *state)
+{
+ unsigned int val;
+
+ val = mt7530_read(priv, MT7531_PCS_CONTROL_1(port));
+ state->link = !!(val & MT7531_SGMII_LINK_STATUS);
+ if (!state->link)
+ return;
+
+ if (state->interface == PHY_INTERFACE_MODE_2500BASEX)
+ state->speed = SPEED_2500;
+ else
+ state->speed = SPEED_1000;
+
+ state->duplex = DUPLEX_FULL;
+ state->pause = 0;
+}
+
static void mt7531_pcs_get_state(struct phylink_pcs *pcs,
struct phylink_link_state *state)
{
struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv;
int port = pcs_to_mt753x_pcs(pcs)->port;
+ unsigned int val;
- if (state->interface == PHY_INTERFACE_MODE_SGMII)
+ if (state->interface == PHY_INTERFACE_MODE_SGMII) {
mt7531_sgmii_pcs_get_state_an(priv, port, state);
- else
- state->link = false;
+ return;
+ } else if ((state->interface == PHY_INTERFACE_MODE_1000BASEX) ||
+ (state->interface == PHY_INTERFACE_MODE_2500BASEX)) {
+ mt7531_sgmii_pcs_get_state_inband(priv, port, state);
+ return;
+ }
+
+ state->link = false;
}
static int mt753x_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
@@ -3069,6 +3089,8 @@ mt753x_setup(struct dsa_switch *ds)
priv->pcs[i].pcs.ops = priv->info->pcs_ops;
priv->pcs[i].priv = priv;
priv->pcs[i].port = i;
+ if (mt753x_is_mac_port(i))
+ priv->pcs[i].pcs.poll = 1;
}
ret = priv->info->sw_setup(ds);
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] net: dsa: mt7530: add support for in-band link status
2022-09-10 1:12 [PATCH] net: dsa: mt7530: add support for in-band link status Daniel Golle
@ 2022-09-11 19:58 ` Russell King (Oracle)
2022-09-11 20:45 ` [PATCH v2] " Daniel Golle
0 siblings, 1 reply; 5+ messages in thread
From: Russell King (Oracle) @ 2022-09-11 19:58 UTC (permalink / raw)
To: Daniel Golle
Cc: linux-mediatek, netdev, Sean Wang, Landen Chao, DENG Qingfang,
Andrew Lunn, Vivien Didelot, Florian Fainelli, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, Philipp Zabel,
Alexander 'lynxis' Couzens
Hi,
Just two points please:
On Sat, Sep 10, 2022 at 02:12:12AM +0100, Daniel Golle wrote:
> +static void
> +mt7531_sgmii_pcs_get_state_inband(struct mt7530_priv *priv, int port,
> + struct phylink_link_state *state)
> +{
> + unsigned int val;
> +
> + val = mt7530_read(priv, MT7531_PCS_CONTROL_1(port));
> + state->link = !!(val & MT7531_SGMII_LINK_STATUS);
> + if (!state->link)
> + return;
> +
> + if (state->interface == PHY_INTERFACE_MODE_2500BASEX)
> + state->speed = SPEED_2500;
> + else
> + state->speed = SPEED_1000;
> +
> + state->duplex = DUPLEX_FULL;
> + state->pause = 0;
MLO_PAUSE_NONE please.
Also, please set state->an_complete appropriately.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2] net: dsa: mt7530: add support for in-band link status
2022-09-11 19:58 ` Russell King (Oracle)
@ 2022-09-11 20:45 ` Daniel Golle
2022-09-20 1:36 ` Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Golle @ 2022-09-11 20:45 UTC (permalink / raw)
To: Russell King, linux-mediatek, netdev
Cc: Sean Wang, Landen Chao, DENG Qingfang, Andrew Lunn,
Vivien Didelot, Florian Fainelli, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, Philipp Zabel,
Alexander 'lynxis' Couzens
Read link status from SGMII PCS for in-band managed 2500Base-X and
1000Base-X connection on a MAC port of the MT7531. This is needed to
get the SFP cage working which is connected to SGMII interface of
port 5 of the MT7531 switch IC on the Bananapi BPi-R3 board.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
v2: Use MLO_PAUSE_NONE and read an_complete from SGMII status register.
drivers/net/dsa/mt7530.c | 50 +++++++++++++++++++++++++++++-----------
drivers/net/dsa/mt7530.h | 1 +
2 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 835807911be019..2e329881f461d9 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2699,9 +2699,6 @@ mt7531_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
case PHY_INTERFACE_MODE_NA:
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_2500BASEX:
- if (phylink_autoneg_inband(mode))
- return -EINVAL;
-
return mt7531_sgmii_setup_mode_force(priv, port, interface);
default:
return -EINVAL;
@@ -2777,13 +2774,6 @@ mt753x_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
return;
}
- if (phylink_autoneg_inband(mode) &&
- state->interface != PHY_INTERFACE_MODE_SGMII) {
- dev_err(ds->dev, "%s: in-band negotiation unsupported\n",
- __func__);
- return;
- }
-
mcr_cur = mt7530_read(priv, MT7530_PMCR_P(port));
mcr_new = mcr_cur;
mcr_new &= ~PMCR_LINK_SETTINGS_MASK;
@@ -2922,6 +2912,9 @@ static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_10 | MAC_100 | MAC_1000FD;
+ if ((priv->id == ID_MT7531) && mt753x_is_mac_port(port))
+ config->mac_capabilities |= MAC_2500FD;
+
/* This driver does not make use of the speed, duplex, pause or the
* advertisement in its mac_config, so it is safe to mark this driver
* as non-legacy.
@@ -3017,16 +3010,45 @@ mt7531_sgmii_pcs_get_state_an(struct mt7530_priv *priv, int port,
return 0;
}
+static void
+mt7531_sgmii_pcs_get_state_inband(struct mt7530_priv *priv, int port,
+ struct phylink_link_state *state)
+{
+ unsigned int val;
+
+ val = mt7530_read(priv, MT7531_PCS_CONTROL_1(port));
+ state->link = !!(val & MT7531_SGMII_LINK_STATUS);
+ if (!state->link)
+ return;
+
+ state->an_complete = !!(val & MT7531_SGMII_AN_COMPLETE);
+
+ if (state->interface == PHY_INTERFACE_MODE_2500BASEX)
+ state->speed = SPEED_2500;
+ else
+ state->speed = SPEED_1000;
+
+ state->duplex = DUPLEX_FULL;
+ state->pause = MLO_PAUSE_NONE;
+}
+
static void mt7531_pcs_get_state(struct phylink_pcs *pcs,
struct phylink_link_state *state)
{
struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv;
int port = pcs_to_mt753x_pcs(pcs)->port;
+ unsigned int val;
- if (state->interface == PHY_INTERFACE_MODE_SGMII)
+ if (state->interface == PHY_INTERFACE_MODE_SGMII) {
mt7531_sgmii_pcs_get_state_an(priv, port, state);
- else
- state->link = false;
+ return;
+ } else if ((state->interface == PHY_INTERFACE_MODE_1000BASEX) ||
+ (state->interface == PHY_INTERFACE_MODE_2500BASEX)) {
+ mt7531_sgmii_pcs_get_state_inband(priv, port, state);
+ return;
+ }
+
+ state->link = false;
}
static int mt753x_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
@@ -3067,6 +3089,8 @@ mt753x_setup(struct dsa_switch *ds)
priv->pcs[i].pcs.ops = priv->info->pcs_ops;
priv->pcs[i].priv = priv;
priv->pcs[i].port = i;
+ if (mt753x_is_mac_port(i))
+ priv->pcs[i].pcs.poll = 1;
}
ret = priv->info->sw_setup(ds);
diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
index e509af95c35414..e8d9664353504f 100644
--- a/drivers/net/dsa/mt7530.h
+++ b/drivers/net/dsa/mt7530.h
@@ -373,6 +373,7 @@ enum mt7530_vlan_port_acc_frm {
#define MT7531_SGMII_LINK_STATUS BIT(18)
#define MT7531_SGMII_AN_ENABLE BIT(12)
#define MT7531_SGMII_AN_RESTART BIT(9)
+#define MT7531_SGMII_AN_COMPLETE BIT(21)
/* Register for SGMII PCS_SPPED_ABILITY */
#define MT7531_PCS_SPEED_ABILITY(p) MT7531_SGMII_REG(p, 0x08)
--
2.37.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] net: dsa: mt7530: add support for in-band link status
2022-09-11 20:45 ` [PATCH v2] " Daniel Golle
@ 2022-09-20 1:36 ` Jakub Kicinski
2022-09-20 22:28 ` Daniel Golle
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2022-09-20 1:36 UTC (permalink / raw)
To: Daniel Golle
Cc: Russell King, linux-mediatek, netdev, Sean Wang, Landen Chao,
DENG Qingfang, Andrew Lunn, Vivien Didelot, Florian Fainelli,
Vladimir Oltean, David S. Miller, Eric Dumazet, Paolo Abeni,
Matthias Brugger, Philipp Zabel,
Alexander 'lynxis' Couzens
On Sun, 11 Sep 2022 21:45:30 +0100 Daniel Golle wrote:
> static void mt7531_pcs_get_state(struct phylink_pcs *pcs,
> struct phylink_link_state *state)
> {
> struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv;
> int port = pcs_to_mt753x_pcs(pcs)->port;
> + unsigned int val;
>
> - if (state->interface == PHY_INTERFACE_MODE_SGMII)
> + if (state->interface == PHY_INTERFACE_MODE_SGMII) {
> mt7531_sgmii_pcs_get_state_an(priv, port, state);
> - else
> - state->link = false;
> + return;
> + } else if ((state->interface == PHY_INTERFACE_MODE_1000BASEX) ||
> + (state->interface == PHY_INTERFACE_MODE_2500BASEX)) {
> + mt7531_sgmii_pcs_get_state_inband(priv, port, state);
> + return;
> + }
> +
> + state->link = false;
drivers/net/dsa/mt7530.c:3040:15: warning: unused variable 'val' [-Wunused-variable]
unsigned int val;
^
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] net: dsa: mt7530: add support for in-band link status
2022-09-20 1:36 ` Jakub Kicinski
@ 2022-09-20 22:28 ` Daniel Golle
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Golle @ 2022-09-20 22:28 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Russell King, linux-mediatek, netdev, Sean Wang, Landen Chao,
DENG Qingfang, Andrew Lunn, Vivien Didelot, Florian Fainelli,
Vladimir Oltean, David S. Miller, Eric Dumazet, Paolo Abeni,
Matthias Brugger, Philipp Zabel,
Alexander 'lynxis' Couzens
On Mon, Sep 19, 2022 at 06:36:22PM -0700, Jakub Kicinski wrote:
> On Sun, 11 Sep 2022 21:45:30 +0100 Daniel Golle wrote:
> > static void mt7531_pcs_get_state(struct phylink_pcs *pcs,
> > struct phylink_link_state *state)
> > {
> > struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv;
> > int port = pcs_to_mt753x_pcs(pcs)->port;
> > + unsigned int val;
> >
> > - if (state->interface == PHY_INTERFACE_MODE_SGMII)
> > + if (state->interface == PHY_INTERFACE_MODE_SGMII) {
> > mt7531_sgmii_pcs_get_state_an(priv, port, state);
> > - else
> > - state->link = false;
> > + return;
> > + } else if ((state->interface == PHY_INTERFACE_MODE_1000BASEX) ||
> > + (state->interface == PHY_INTERFACE_MODE_2500BASEX)) {
> > + mt7531_sgmii_pcs_get_state_inband(priv, port, state);
> > + return;
> > + }
> > +
> > + state->link = false;
>
> drivers/net/dsa/mt7530.c:3040:15: warning: unused variable 'val' [-Wunused-variable]
> unsigned int val;
> ^
Oops, forgot that one there. Just sent out v3 with this fixed and
an_complete handled more decently.
Thank you for the review!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-09-20 22:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-10 1:12 [PATCH] net: dsa: mt7530: add support for in-band link status Daniel Golle
2022-09-11 19:58 ` Russell King (Oracle)
2022-09-11 20:45 ` [PATCH v2] " Daniel Golle
2022-09-20 1:36 ` Jakub Kicinski
2022-09-20 22:28 ` Daniel Golle
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).