Skip to contentSkip to conversation

net: pcs: xpcs: Add 2500BASE-X case in get state for XPCS drivers

PATCH Applied Raju Lakkaraju 4 participants 7 messages Oct 27, 2023 – Oct 31, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: pcs: xpcs: Add 2500BASE-X case in get state for XPCS drivers

Add DW_2500BASEX case in xpcs_get_state( ) to update speed, duplex and pause

---
 drivers/net/pcs/pcs-xpcs.c | 29 +++++++++++++++++++++++++++++
 drivers/net/pcs/pcs-xpcs.h |  2 ++
 2 files changed, 31 insertions(+)
drivers/net/pcs/pcs-xpcs.c +29 -0
index 4dbc21f604f2..31f0beba638a 100644
@@ -1090,6 +1090,28 @@ static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs,
 	return 0;
 }
 
+static int xpcs_get_state_2500basex(struct dw_xpcs *xpcs,
+				    struct phylink_link_state *state)
+{
+	int ret;
+
+	ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_STS);
+	if (ret < 0) {
+		state->link = 0;
+		return ret;
+	}
+
+	state->link = !!(ret & DW_VR_MII_MMD_STS_LINK_STS);
+	if (!state->link)
+		return 0;
+
+	state->speed = SPEED_2500;
+	state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;
+	state->duplex = DUPLEX_FULL;
+
+	return 0;
+}
+
 static void xpcs_get_state(struct phylink_pcs *pcs,
 			   struct phylink_link_state *state)
 {
@@ -1127,6 +1149,13 @@ static void xpcs_get_state(struct phylink_pcs *pcs,
 			       ERR_PTR(ret));
 		}
 		break;
+	case DW_2500BASEX:
+		ret = xpcs_get_state_2500basex(xpcs, state);
+		if (ret) {
+			pr_err("xpcs_get_state_2500basex returned %pe\n",
+			       ERR_PTR(ret));
+		}
+		break;
 	default:
 		return;
 	}
drivers/net/pcs/pcs-xpcs.h +2 -0
index 39a90417e535..96c36b32ca99 100644
@@ -55,6 +55,8 @@
 /* Clause 37 Defines */
 /* VR MII MMD registers offsets */
 #define DW_VR_MII_MMD_CTRL		0x0000
+#define DW_VR_MII_MMD_STS		0x0001
+#define DW_VR_MII_MMD_STS_LINK_STS	BIT(2)
 #define DW_VR_MII_DIG_CTRL1		0x8000
 #define DW_VR_MII_AN_CTRL		0x8001
 #define DW_VR_MII_AN_INTR_STS		0x8002
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw

Cc += Russell

* It's a good practice to add all the reviewers to Cc in the new patch
* revisions.

Quoted 3 lines · Raju Lakkaraju

Add DW_2500BASEX case in xpcs_get_state( ) to update speed, duplex and pause

With a nitpick below clarified, feel free to add:

Quoted 21 lines
---
 drivers/net/pcs/pcs-xpcs.c | 29 +++++++++++++++++++++++++++++
 drivers/net/pcs/pcs-xpcs.h |  2 ++
 2 files changed, 31 insertions(+)
drivers/net/pcs/pcs-xpcs.c +8 -0
index 4dbc21f604f2..31f0beba638a 100644
@@ -1090,6 +1090,28 @@ static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs,
 	return 0;
 }
 
+static int xpcs_get_state_2500basex(struct dw_xpcs *xpcs,
+				    struct phylink_link_state *state)
+{
+	int ret;
+
+	ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_STS);
+	if (ret < 0) {
+		state->link = 0;

drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs, · line 1110

Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +9 -0
+		return ret;
+	}
+
+	state->link = !!(ret & DW_VR_MII_MMD_STS_LINK_STS);
+	if (!state->link)
+		return 0;
+
+	state->speed = SPEED_2500;
 
+	state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;

Why is it '|=' instead of just '='? Is it possible to have the 'pause' field having some additional flags set which would be required to preserve?

-Serge(y)

Quoted 38 lines
drivers/net/pcs/pcs-xpcs.c +5 -0
+	state->duplex = DUPLEX_FULL;
+
+	return 0;
+}
+
 static void xpcs_get_state(struct phylink_pcs *pcs,
 			   struct phylink_link_state *state)

{

drivers/net/pcs/pcs-xpcs.c +7 -0
@@ -1127,6 +1149,13 @@ static void xpcs_get_state(struct phylink_pcs *pcs,
 			       ERR_PTR(ret));
 		}
 		break;
+	case DW_2500BASEX:
+		ret = xpcs_get_state_2500basex(xpcs, state);
+		if (ret) {
+			pr_err("xpcs_get_state_2500basex returned %pe\n",
+			       ERR_PTR(ret));
+		}
+		break;
 	default:
 		return;
 	}
drivers/net/pcs/pcs-xpcs.h +2 -0
index 39a90417e535..96c36b32ca99 100644
@@ -55,6 +55,8 @@
 /* Clause 37 Defines */
 /* VR MII MMD registers offsets */
 #define DW_VR_MII_MMD_CTRL		0x0000
+#define DW_VR_MII_MMD_STS		0x0001
+#define DW_VR_MII_MMD_STS_LINK_STS	BIT(2)
 #define DW_VR_MII_DIG_CTRL1		0x8000
 #define DW_VR_MII_AN_CTRL		0x8001
 #define DW_VR_MII_AN_INTR_STS		0x8002
Signature · 1 line
2.34.1
#2 lore raw
Quoted 43 lines · Serge Semin

Cc += Russell

* It's a good practice to add all the reviewers to Cc in the new patch
* revisions.

Quoted 3 lines · Raju Lakkaraju

Add DW_2500BASEX case in xpcs_get_state( ) to update speed, duplex and pause

With a nitpick below clarified, feel free to add:

Quoted 29 lines
---
 drivers/net/pcs/pcs-xpcs.c | 29 +++++++++++++++++++++++++++++
 drivers/net/pcs/pcs-xpcs.h |  2 ++
 2 files changed, 31 insertions(+)
drivers/net/pcs/pcs-xpcs.c +16 -0
index 4dbc21f604f2..31f0beba638a 100644
@@ -1090,6 +1090,28 @@ static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs,
 	return 0;
 }
 
+static int xpcs_get_state_2500basex(struct dw_xpcs *xpcs,
+				    struct phylink_link_state *state)
+{
+	int ret;
+
+	ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_STS);
+	if (ret < 0) {
+		state->link = 0;
+		return ret;
+	}
+
+	state->link = !!(ret & DW_VR_MII_MMD_STS_LINK_STS);
+	if (!state->link)
+		return 0;
+
+	state->speed = SPEED_2500;
Quoted 5 lines

drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs, · line 1109

Quoted 1 line
drivers/net/pcs/pcs-xpcs.c +1 -0
+	state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;

Why is it '|=' instead of just '='? Is it possible to have the 'pause' field having some additional flags set which would be required to preserve?

The code is correct. There are other flags on state->pause other than these, and phylink initialises state->pause prior to calling the function. The only flags that should be modified here are these two bits that the code is setting.

Phylink will initialise it to MLO_PAUSE_NONE if expecting autoneg, or the configured values if autoneg on the link is disabled.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#3 lore raw

Hi Russell

Quoted 50 lines · Russell King (Oracle)
Quoted 43 lines · Serge Semin

Cc += Russell

* It's a good practice to add all the reviewers to Cc in the new patch
* revisions.

Quoted 3 lines · Raju Lakkaraju

Add DW_2500BASEX case in xpcs_get_state( ) to update speed, duplex and pause

With a nitpick below clarified, feel free to add:

Quoted 29 lines
---
 drivers/net/pcs/pcs-xpcs.c | 29 +++++++++++++++++++++++++++++
 drivers/net/pcs/pcs-xpcs.h |  2 ++
 2 files changed, 31 insertions(+)
drivers/net/pcs/pcs-xpcs.c +16 -0
index 4dbc21f604f2..31f0beba638a 100644
@@ -1090,6 +1090,28 @@ static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs,
 	return 0;
 }
 
+static int xpcs_get_state_2500basex(struct dw_xpcs *xpcs,
+				    struct phylink_link_state *state)
+{
+	int ret;
+
+	ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_STS);
+	if (ret < 0) {
+		state->link = 0;
+		return ret;
+	}
+
+	state->link = !!(ret & DW_VR_MII_MMD_STS_LINK_STS);
+	if (!state->link)
+		return 0;
+
+	state->speed = SPEED_2500;
Quoted 5 lines

drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs, · line 1109

Quoted 1 line
drivers/net/pcs/pcs-xpcs.c +1 -0
+	state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;

Why is it '|=' instead of just '='? Is it possible to have the 'pause' field having some additional flags set which would be required to preserve?

Quoted 7 lines

The code is correct. There are other flags on state->pause other than these, and phylink initialises state->pause prior to calling the function. The only flags that should be modified here are these two bits that the code is setting.

Phylink will initialise it to MLO_PAUSE_NONE if expecting autoneg, or the configured values if autoneg on the link is disabled.

Thanks for clarification. Then no more comments from my side in this patch regard.

Regarding the XPCS driver in general. Based on what you said the rest of the XPCS state getters are wrong in fully re-writing the 'pause' field. Right?

-Serge(y)

Quoted 4 lines
Signature · 3 lines
-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#4 lore raw
Quoted 61 lines · Serge Semin

Hi Russell

Quoted 50 lines · Russell King (Oracle)
Quoted 43 lines · Serge Semin

Cc += Russell

* It's a good practice to add all the reviewers to Cc in the new patch
* revisions.

Quoted 3 lines · Raju Lakkaraju

Add DW_2500BASEX case in xpcs_get_state( ) to update speed, duplex and pause

With a nitpick below clarified, feel free to add:

Quoted 29 lines
---
 drivers/net/pcs/pcs-xpcs.c | 29 +++++++++++++++++++++++++++++
 drivers/net/pcs/pcs-xpcs.h |  2 ++
 2 files changed, 31 insertions(+)
drivers/net/pcs/pcs-xpcs.c +16 -0
index 4dbc21f604f2..31f0beba638a 100644
@@ -1090,6 +1090,28 @@ static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs,
 	return 0;
 }
 
+static int xpcs_get_state_2500basex(struct dw_xpcs *xpcs,
+				    struct phylink_link_state *state)
+{
+	int ret;
+
+	ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_STS);
+	if (ret < 0) {
+		state->link = 0;
+		return ret;
+	}
+
+	state->link = !!(ret & DW_VR_MII_MMD_STS_LINK_STS);
+	if (!state->link)
+		return 0;
+
+	state->speed = SPEED_2500;
Quoted 5 lines

drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs, · line 1109

Quoted 1 line
drivers/net/pcs/pcs-xpcs.c +1 -0
+	state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;

Why is it '|=' instead of just '='? Is it possible to have the 'pause' field having some additional flags set which would be required to preserve?

Quoted 7 lines

The code is correct. There are other flags on state->pause other than these, and phylink initialises state->pause prior to calling the function. The only flags that should be modified here are these two bits that the code is setting.

Phylink will initialise it to MLO_PAUSE_NONE if expecting autoneg, or the configured values if autoneg on the link is disabled.

Quoted 6 lines

Thanks for clarification. Then no more comments from my side in this patch regard.

Regarding the XPCS driver in general. Based on what you said the rest of the XPCS state getters are wrong in fully re-writing the 'pause' field. Right?

Yes.

xpcs_resolve_pma:

        state->pause = MLO_PAUSE_TX | MLO_PAUSE_RX;

xpcs_get_state_c37_sgmii:

        state->pause = 0;

are both incorrect. The former should be |=, the latter is totally unnecessary.

Documentation:
* pcs_get_state() - Read the current inband link state from the hardware
* @pcs: a pointer to a &struct phylink_pcs.
* @state: a pointer to a &struct phylink_link_state.
*
* Read the current inband link state from the MAC PCS, reporting the
* current speed in @state->speed, duplex mode in @state->duplex, pause

                                                                  ^^^^^

* mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I guess I need to make that more explicit that pcs_get_state() methods are only expected to _set_ these two bits as appropriate, leaving all other bits as-is.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#5 lore raw
Quoted 87 lines · Russell King (Oracle)
Quoted 61 lines · Serge Semin

Hi Russell

Quoted 50 lines · Russell King (Oracle)
Quoted 43 lines · Serge Semin

Cc += Russell

* It's a good practice to add all the reviewers to Cc in the new patch
* revisions.

Quoted 3 lines · Raju Lakkaraju

Add DW_2500BASEX case in xpcs_get_state( ) to update speed, duplex and pause

With a nitpick below clarified, feel free to add:

Quoted 29 lines
---
 drivers/net/pcs/pcs-xpcs.c | 29 +++++++++++++++++++++++++++++
 drivers/net/pcs/pcs-xpcs.h |  2 ++
 2 files changed, 31 insertions(+)
drivers/net/pcs/pcs-xpcs.c +16 -0
index 4dbc21f604f2..31f0beba638a 100644
@@ -1090,6 +1090,28 @@ static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs,
 	return 0;
 }
 
+static int xpcs_get_state_2500basex(struct dw_xpcs *xpcs,
+				    struct phylink_link_state *state)
+{
+	int ret;
+
+	ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_STS);
+	if (ret < 0) {
+		state->link = 0;
+		return ret;
+	}
+
+	state->link = !!(ret & DW_VR_MII_MMD_STS_LINK_STS);
+	if (!state->link)
+		return 0;
+
+	state->speed = SPEED_2500;
Quoted 5 lines

drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_1000basex(struct dw_xpcs *xpcs, · line 1109

Quoted 1 line
drivers/net/pcs/pcs-xpcs.c +1 -0
+	state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;

Why is it '|=' instead of just '='? Is it possible to have the 'pause' field having some additional flags set which would be required to preserve?

Quoted 7 lines

The code is correct. There are other flags on state->pause other than these, and phylink initialises state->pause prior to calling the function. The only flags that should be modified here are these two bits that the code is setting.

Phylink will initialise it to MLO_PAUSE_NONE if expecting autoneg, or the configured values if autoneg on the link is disabled.

Quoted 6 lines

Thanks for clarification. Then no more comments from my side in this patch regard.

Regarding the XPCS driver in general. Based on what you said the rest of the XPCS state getters are wrong in fully re-writing the 'pause' field. Right?

Yes.

xpcs_resolve_pma:

        state->pause = MLO_PAUSE_TX | MLO_PAUSE_RX;

xpcs_get_state_c37_sgmii:

        state->pause = 0;

are both incorrect. The former should be |=, the latter is totally unnecessary.

Documentation:
* pcs_get_state() - Read the current inband link state from the hardware
* @pcs: a pointer to a &struct phylink_pcs.
* @state: a pointer to a &struct phylink_link_state.
*
* Read the current inband link state from the MAC PCS, reporting the
* current speed in @state->speed, duplex mode in @state->duplex, pause

Quoted 7 lines
                                                                  ^^^^^

* mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I guess I need to make that more explicit that pcs_get_state() methods are only expected to _set_ these two bits as appropriate, leaving all other bits as-is.

Thanks for the detailed response. I'll send fixup patches for the denoted problems as soon as I get some free time for it. Hopefully within a month if nobody does it sooner.

-Serge(y)

Quoted 4 lines
Signature · 3 lines
-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#6 lore raw
In reply to Raju Lakkaraju
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 7 lines · On Fri, 27 Oct 2023 10:13:06 +0530 you wrote:

Add DW_2500BASEX case in xpcs_get_state( ) to update speed, duplex and pause

---
 drivers/net/pcs/pcs-xpcs.c | 29 +++++++++++++++++++++++++++++
 drivers/net/pcs/pcs-xpcs.h |  2 ++
 2 files changed, 31 insertions(+)

Here is the summary with links:
- [net-next,V3] net: pcs: xpcs: Add 2500BASE-X case in get state for XPCS drivers

    https://git.kernel.org/netdev/net-next/c/f1c73396133c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html