From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: Serge Semin <fancer.lancer@gmail.com>
Cc: Andrew Halaney <ahalaney@redhat.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH RFC net-next v2 3/8] net: stmmac: dwmac1000: convert sgmii/rgmii "pcs" to phylink
Date: Fri, 31 May 2024 12:26:25 +0100 [thread overview]
Message-ID: <E1sD0Ov-00EzBu-BC@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <Zlmzu7/ANyZxOOQL@shell.armlinux.org.uk>
Convert dwmac1000 sgmii/rgmii "pcs" implementation to use a phylink_pcs
so we can eventually get rid of the exceptional paths that conflict
with phylink.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../ethernet/stmicro/stmmac/dwmac1000_core.c | 113 ++++++++++++------
1 file changed, 75 insertions(+), 38 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index d413d76a8936..4a0572d5f865 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -16,6 +16,7 @@
#include <linux/slab.h>
#include <linux/ethtool.h>
#include <linux/io.h>
+#include <linux/phylink.h>
#include "stmmac.h"
#include "stmmac_pcs.h"
#include "dwmac1000.h"
@@ -261,39 +262,6 @@ static void dwmac1000_pmt(struct mac_device_info *hw, unsigned long mode)
writel(pmt, ioaddr + GMAC_PMT);
}
-/* RGMII or SMII interface */
-static void dwmac1000_rgsmii(void __iomem *ioaddr, struct stmmac_extra_stats *x)
-{
- u32 status;
-
- status = readl(ioaddr + GMAC_RGSMIIIS);
- x->irq_rgmii_n++;
-
- /* Check the link status */
- if (status & GMAC_RGSMIIIS_LNKSTS) {
- int speed_value;
-
- x->pcs_link = 1;
-
- speed_value = ((status & GMAC_RGSMIIIS_SPEED) >>
- GMAC_RGSMIIIS_SPEED_SHIFT);
- if (speed_value == GMAC_RGSMIIIS_SPEED_125)
- x->pcs_speed = SPEED_1000;
- else if (speed_value == GMAC_RGSMIIIS_SPEED_25)
- x->pcs_speed = SPEED_100;
- else
- x->pcs_speed = SPEED_10;
-
- x->pcs_duplex = (status & GMAC_RGSMIIIS_LNKMOD_MASK);
-
- pr_info("Link is Up - %d/%s\n", (int)x->pcs_speed,
- x->pcs_duplex ? "Full" : "Half");
- } else {
- x->pcs_link = 0;
- pr_info("Link is Down\n");
- }
-}
-
static int dwmac1000_irq_status(struct mac_device_info *hw,
struct stmmac_extra_stats *x)
{
@@ -335,8 +303,12 @@ static int dwmac1000_irq_status(struct mac_device_info *hw,
dwmac_pcs_isr(ioaddr, GMAC_PCS_BASE, intr_status, x);
- if (intr_status & PCS_RGSMIIIS_IRQ)
- dwmac1000_rgsmii(ioaddr, x);
+ if (intr_status & PCS_RGSMIIIS_IRQ) {
+ /* TODO Dummy-read to clear the IRQ status */
+ readl(ioaddr + GMAC_RGSMIIIS);
+ phylink_pcs_change(&hw->mac_pcs, false);
+ x->irq_rgmii_n++;
+ }
return ret;
}
@@ -404,9 +376,71 @@ static void dwmac1000_ctrl_ane(void __iomem *ioaddr, bool ane, bool srgmi_ral,
dwmac_ctrl_ane(ioaddr, GMAC_PCS_BASE, ane, srgmi_ral, loopback);
}
-static void dwmac1000_get_adv_lp(void __iomem *ioaddr, struct rgmii_adv *adv)
+static int dwmac1000_mii_pcs_validate(struct phylink_pcs *pcs,
+ unsigned long *supported,
+ const struct phylink_link_state *state)
+{
+ /* Only support in-band */
+ if (!test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, state->advertising))
+ return -EINVAL;
+
+ return 0;
+}
+
+static int dwmac1000_mii_pcs_config(struct phylink_pcs *pcs,
+ unsigned int neg_mode,
+ phy_interface_t interface,
+ const unsigned long *advertising,
+ bool permit_pause_to_mac)
{
- dwmac_get_adv_lp(ioaddr, GMAC_PCS_BASE, adv);
+ struct mac_device_info *hw = phylink_pcs_to_mac_dev_info(pcs);
+
+ return dwmac_pcs_config(hw, neg_mode, interface, advertising,
+ GMAC_PCS_BASE);
+}
+
+static void dwmac1000_mii_pcs_get_state(struct phylink_pcs *pcs,
+ struct phylink_link_state *state)
+{
+ struct mac_device_info *hw = phylink_pcs_to_mac_dev_info(pcs);
+ unsigned int spd_clk;
+ u32 status;
+
+ status = readl(hw->pcsr + GMAC_RGSMIIIS);
+
+ state->link = status & GMAC_RGSMIIIS_LNKSTS;
+ if (!state->link)
+ return;
+
+ spd_clk = FIELD_GET(GMAC_RGSMIIIS_SPEED, status);
+ if (spd_clk == GMAC_RGSMIIIS_SPEED_125)
+ state->speed = SPEED_1000;
+ else if (spd_clk == GMAC_RGSMIIIS_SPEED_25)
+ state->speed = SPEED_100;
+ else if (spd_clk == GMAC_RGSMIIIS_SPEED_2_5)
+ state->speed = SPEED_10;
+
+ state->duplex = status & GMAC_RGSMIIIS_LNKMOD_MASK ?
+ DUPLEX_FULL : DUPLEX_HALF;
+
+ dwmac_pcs_get_state(hw, state, GMAC_PCS_BASE);
+}
+
+static const struct phylink_pcs_ops dwmac1000_mii_pcs_ops = {
+ .pcs_validate = dwmac1000_mii_pcs_validate,
+ .pcs_config = dwmac1000_mii_pcs_config,
+ .pcs_get_state = dwmac1000_mii_pcs_get_state,
+};
+
+static struct phylink_pcs *
+dwmac1000_phylink_select_pcs(struct stmmac_priv *priv,
+ phy_interface_t interface)
+{
+ if (priv->hw->pcs & STMMAC_PCS_RGMII ||
+ priv->hw->pcs & STMMAC_PCS_SGMII)
+ return &priv->hw->mac_pcs;
+
+ return NULL;
}
static void dwmac1000_debug(struct stmmac_priv *priv, void __iomem *ioaddr,
@@ -499,6 +533,7 @@ static void dwmac1000_set_mac_loopback(void __iomem *ioaddr, bool enable)
const struct stmmac_ops dwmac1000_ops = {
.core_init = dwmac1000_core_init,
+ .phylink_select_pcs = dwmac1000_phylink_select_pcs,
.set_mac = stmmac_set_mac,
.rx_ipc = dwmac1000_rx_ipc_enable,
.dump_regs = dwmac1000_dump_regs,
@@ -514,7 +549,6 @@ const struct stmmac_ops dwmac1000_ops = {
.set_eee_pls = dwmac1000_set_eee_pls,
.debug = dwmac1000_debug,
.pcs_ctrl_ane = dwmac1000_ctrl_ane,
- .pcs_get_adv_lp = dwmac1000_get_adv_lp,
.set_mac_loopback = dwmac1000_set_mac_loopback,
};
@@ -549,5 +583,8 @@ int dwmac1000_setup(struct stmmac_priv *priv)
mac->mii.clk_csr_shift = 2;
mac->mii.clk_csr_mask = GENMASK(5, 2);
+ mac->mac_pcs.ops = &dwmac1000_mii_pcs_ops;
+ mac->mac_pcs.neg_mode = true;
+
return 0;
}
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-05-31 11:27 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-31 11:25 [PATCH RFC v2 0/8] net: stmmac: convert stmmac "pcs" to phylink Russell King (Oracle)
2024-05-31 11:26 ` [PATCH RFC net-next v2 1/8] net: stmmac: add infrastructure for hwifs to provide PCS Russell King (Oracle)
2024-06-05 19:57 ` Andrew Halaney
2024-06-10 9:16 ` Russell King (Oracle)
2024-05-31 11:26 ` [PATCH RFC net-next v2 2/8] net: stmmac: provide core phylink PCS infrastructure Russell King (Oracle)
2024-05-31 11:26 ` Russell King (Oracle) [this message]
2024-06-05 20:05 ` [PATCH RFC net-next v2 3/8] net: stmmac: dwmac1000: convert sgmii/rgmii "pcs" to phylink Andrew Halaney
2024-06-05 21:59 ` Andrew Halaney
2024-06-10 9:24 ` Russell King (Oracle)
2024-06-10 9:19 ` Russell King (Oracle)
2024-06-11 12:25 ` Serge Semin
2024-06-12 22:04 ` Russell King (Oracle)
2024-06-13 21:14 ` Serge Semin
2024-06-18 10:26 ` Serge Semin
2024-06-24 1:32 ` Serge Semin
2024-06-24 13:40 ` Serge Semin
2024-05-31 11:26 ` [PATCH RFC net-next v2 4/8] net: stmmac: dwmac1000: move PCS interrupt control Russell King (Oracle)
2024-05-31 11:26 ` [PATCH RFC net-next v2 5/8] net: stmmac: dwmac4: convert sgmii/rgmii "pcs" to phylink Russell King (Oracle)
2024-06-05 22:35 ` Andrew Halaney
2024-06-11 18:22 ` Abhishek Chauhan (ABC)
2024-05-31 11:26 ` [PATCH RFC net-next v2 6/8] net: stmmac: dwmac4: move PCS interrupt control Russell King (Oracle)
2024-05-31 11:26 ` [PATCH RFC net-next v2 7/8] net: stmmac: remove obsolete pcs methods and associated code Russell King (Oracle)
2024-06-05 22:09 ` Andrew Halaney
2024-05-31 11:26 ` [PATCH RFC net-next v2 8/8] net: stmmac: Activate Inband/PCS flag based on the selected iface Russell King
2024-06-03 21:39 ` [PATCH RFC v2 0/8] net: stmmac: convert stmmac "pcs" to phylink Andrew Halaney
2024-06-24 13:26 ` [PATCH RFC net-next v2 09/17] net: stmmac: Introduce mac_device_info::priv pointer Serge Semin
2024-06-24 13:26 ` [PATCH RFC net-next v2 10/17] net: stmmac: Introduce internal PCS offset-based CSR access Serge Semin
2024-06-28 14:54 ` Russell King (Oracle)
2024-07-03 18:03 ` Serge Semin
2024-06-24 13:26 ` [PATCH RFC net-next v2 11/17] net: stmmac: Introduce internal PCS config register getter Serge Semin
2024-06-24 13:26 ` [PATCH RFC net-next v2 12/17] net: stmmac: Introduce internal PCS IRQ enable/disable methods Serge Semin
2024-06-24 13:26 ` [PATCH RFC net-next v2 13/17] net: stmmac: Move internal PCS ANE-control method to dwmac-qcom-ethqos.c Serge Semin
2024-06-24 13:26 ` [PATCH RFC net-next v2 14/17] net: stmmac: Move internal PCS PHYLINK ops to stmmac_pcs.c Serge Semin
2024-06-28 15:07 ` Russell King (Oracle)
2024-07-03 19:08 ` Serge Semin
2024-07-03 20:07 ` Russell King (Oracle)
2024-07-04 19:56 ` Serge Semin
2024-06-24 13:26 ` [PATCH RFC net-next v2 15/17] net: stmmac: Move internal PCS ISR " Serge Semin
2024-06-24 13:26 ` [PATCH RFC net-next v2 16/17] net: stmmac: Move internal PCS init method " Serge Semin
2024-06-28 14:36 ` Russell King (Oracle)
2024-07-04 12:55 ` Serge Semin
2024-06-24 13:26 ` [PATCH RFC net-next v2 17/17] net: stmmac: pcs: Drop the _SHIFT macros Serge Semin
2024-06-28 14:42 ` Russell King (Oracle)
2024-07-04 13:19 ` Serge Semin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1sD0Ov-00EzBu-BC@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=ahalaney@redhat.com \
--cc=alexandre.torgue@foss.st.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fancer.lancer@gmail.com \
--cc=joabreu@synopsys.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).