net: stmmac: pcs support part 2
Subsystems (4)
cover net: stmmac: pcs support part 2
Hi,
This is the next part of stmmac PCS support. Not much here, other than dealing with what remains of the interrupts, which are the PCS AN complete and PCS Link interrupts, which are just cleared and update accounting.
Currently, they are enabled at core init time, but if we have an implementation that supports multiple PHY interfaces, we want to enable only the appropriate interrupts.
I also noticed that stmmac_fpe_configure_pmac() also modifies the interrupt mask during run time. As a pre-requisit, we need a way to ensure that we don't have different threads modifying the interrupt settings at the same time. So, the first patch introduces a new function and a spinlock which must be held when manipulating the interrupt enable/mask state.
The second patch adds the PCS bits for enabling the PCS AN and PCS link interrupts when the PCS is in-use.
drivers/net/ethernet/stmicro/stmmac/common.h | 5 ++++ drivers/net/ethernet/stmicro/stmmac/dwmac1000.h | 7 +++--- .../net/ethernet/stmicro/stmmac/dwmac1000_core.c | 26 +++++++++++++++------ drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 2 -- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 27 ++++++++++++++++------ .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 16 +++++++++++++ drivers/net/ethernet/stmicro/stmmac/hwif.c | 2 ++ drivers/net/ethernet/stmicro/stmmac/hwif.h | 4 ++++ drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c | 3 +++ drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c | 22 +++++++++++++++++- drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.h | 4 +++- 11 files changed, 96 insertions(+), 22 deletions(-)
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!
PATCH 1/2 net: stmmac: add stmmac_mac_irq_modify()
Add a function to allow interrupts to be enabled and disabled in a core independent manner.
--- drivers/net/ethernet/stmicro/stmmac/common.h | 5 +++++ .../ethernet/stmicro/stmmac/dwmac1000_core.c | 15 +++++++++++++++ .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 17 +++++++++++++++++ .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 16 ++++++++++++++++ drivers/net/ethernet/stmicro/stmmac/hwif.c | 2 ++ drivers/net/ethernet/stmicro/stmmac/hwif.h | 4 ++++ .../net/ethernet/stmicro/stmmac/stmmac_fpe.c | 3 +++ 7 files changed, 62 insertions(+)
drivers/net/ethernet/stmicro/stmmac/common.h +5 -0
@@ -611,6 +611,11 @@ struct mac_device_info {u8 vlan_fail_q;bool hw_vlan_en;bool reverse_sgmii_enable; + +/* This spinlock protects read-modify-write of the interrupt +* mask/enable registers. +*/ +spinlock_t irq_ctrl_lock; };struct stmmac_rx_routing {
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +15 -0
@@ -61,6 +61,20 @@ static void dwmac1000_core_init(struct mac_device_info *hw,#endif } +static void dwmac1000_irq_modify (struct mac_device_info *hw,u32 disable, +u32 enable) +{ +void __iomem *int_mask = hw->pcsr +GMAC_INT_MASK ; +unsigned long flags; +u32 value; + +spin_lock_irqsave (&hw->irq_ctrl_lock, flags); + value =readl (int_mask) | disable; + value &= ~enable; +writel (value, int_mask); +spin_unlock_irqrestore (&hw->irq_ctrl_lock, flags); +} +static int dwmac1000_rx_ipc_enable (struct mac_device_info *hw) {void __iomem *ioaddr = hw->pcsr;
@@ -445,6 +459,7 @@ static void dwmac1000_set_mac_loopback(void __iomem *ioaddr, bool enable)const struct stmmac_ops dwmac1000_ops = { .pcs_init = dwmac1000_pcs_init, .core_init = dwmac1000_core_init, + .irq_modify = dwmac1000_irq_modify, .set_mac = stmmac_set_mac, .rx_ipc = dwmac1000_rx_ipc_enable, .dump_regs = dwmac1000_dump_regs,
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +17 -0
@@ -57,6 +57,20 @@ static void dwmac4_core_init(struct mac_device_info *hw,init_waitqueue_head (&priv->tstamp_busy_wait); } +static void dwmac4_irq_modify (struct mac_device_info *hw,u32 disable, +u32 enable) +{ +void __iomem *int_mask = hw->pcsr +GMAC_INT_EN ; +unsigned long flags; +u32 value; + +spin_lock_irqsave (&hw->irq_ctrl_lock, flags); + value =readl (int_mask) & ~disable; + value |= enable; +writel (value, int_mask); +spin_unlock_irqrestore (&hw->irq_ctrl_lock, flags); +} +static void dwmac4_update_caps (struct stmmac_priv *priv) {if (priv->plat->tx_queues_to_use >1 )
@@ -885,6 +899,7 @@ static int dwmac4_config_l4_filter(struct mac_device_info *hw, u32 filter_no,const struct stmmac_ops dwmac4_ops = { .pcs_init = dwmac4_pcs_init, .core_init = dwmac4_core_init, + .irq_modify = dwmac4_irq_modify, .update_caps = dwmac4_update_caps, .set_mac = stmmac_set_mac, .rx_ipc = dwmac4_rx_ipc_enable,
@@ -920,6 +935,7 @@ const struct stmmac_ops dwmac4_ops = {const struct stmmac_ops dwmac410_ops = { .pcs_init = dwmac4_pcs_init, .core_init = dwmac4_core_init, + .irq_modify = dwmac4_irq_modify, .update_caps = dwmac4_update_caps, .set_mac = stmmac_dwmac4_set_mac, .rx_ipc = dwmac4_rx_ipc_enable,
@@ -957,6 +973,7 @@ const struct stmmac_ops dwmac410_ops = {const struct stmmac_ops dwmac510_ops = { .pcs_init = dwmac4_pcs_init, .core_init = dwmac4_core_init, + .irq_modify = dwmac4_irq_modify, .update_caps = dwmac4_update_caps, .set_mac = stmmac_dwmac4_set_mac, .rx_ipc = dwmac4_rx_ipc_enable,
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +16 -0
@@ -28,6 +28,20 @@ static void dwxgmac2_core_init(struct mac_device_info *hw,writel (XGMAC_INT_DEFAULT_EN , ioaddr +XGMAC_INT_EN ); } +static void dwxgmac2_irq_modify (struct mac_device_info *hw,u32 disable, +u32 enable) +{ +void __iomem *int_mask = hw->pcsr +XGMAC_INT_EN ; +unsigned long flags; +u32 value; + +spin_lock_irqsave (&hw->irq_ctrl_lock, flags); + value =readl (int_mask) & ~disable; + value |= enable; +writel (value, int_mask); +spin_unlock_irqrestore (&hw->irq_ctrl_lock, flags); +} +static void dwxgmac2_update_caps (struct stmmac_priv *priv) {if (!priv->dma_cap.mbps_10_100)
@@ -1411,6 +1425,7 @@ static void dwxgmac2_set_arp_offload(struct mac_device_info *hw, bool en,const struct stmmac_ops dwxgmac210_ops = { .core_init = dwxgmac2_core_init, + .irq_modify = dwxgmac2_irq_modify, .update_caps = dwxgmac2_update_caps, .set_mac = dwxgmac2_set_mac, .rx_ipc = dwxgmac2_rx_ipc,
@@ -1466,6 +1481,7 @@ static void dwxlgmac2_rx_queue_enable(struct mac_device_info *hw, u8 mode,const struct stmmac_ops dwxlgmac2_ops = { .core_init = dwxgmac2_core_init, + .irq_modify = dwxgmac2_irq_modify, .set_mac = dwxgmac2_set_mac, .rx_ipc = dwxgmac2_rx_ipc, .rx_queue_enable = dwxlgmac2_rx_queue_enable,
drivers/net/ethernet/stmicro/stmmac/hwif.c +2 -0
@@ -333,6 +333,8 @@ int stmmac_hwif_init(struct stmmac_priv *priv)if (!mac)return -ENOMEM ; +spin_lock_init (&mac->irq_ctrl_lock); +/* Fallback to generic HW */ for (i =ARRAY_SIZE (stmmac_hw) -1 ; i >=0 ; i--) { entry = &stmmac_hw[i];
drivers/net/ethernet/stmicro/stmmac/hwif.h +4 -0
@@ -319,6 +319,8 @@ struct stmmac_ops {void (*core_init)(struct mac_device_info *hw,struct net_device *dev);/* Update MAC capabilities */ void (*update_caps)(struct stmmac_priv *priv); +/* Change the interrupt enable setting. Enable takes precedence. */ +void (*irq_modify)(struct mac_device_info *hw,u32 disable,u32 enable);/* Enable the MAC RX/TX */ void (*set_mac)(void __iomem *ioaddr,bool enable);/* Enable and verify that the IPC module is supported */
@@ -421,6 +423,8 @@ struct stmmac_ops { stmmac_do_void_callback(__priv, mac, core_init, __args)#define stmmac_mac_update_caps (__priv) \ stmmac_do_void_callback(__priv, mac, update_caps, __priv) +#define stmmac_mac_irq_modify(__priv, __args...) \ + stmmac_do_void_callback(__priv, mac, irq_modify, (__priv)->hw, __args) #define stmmac_mac_set(__priv, __args...) \ stmmac_do_void_callback(__priv, mac, set_mac, __args) #define stmmac_rx_ipc(__priv, __args...) \
drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c +3 -0
@@ -70,8 +70,10 @@ static void stmmac_fpe_configure_pmac(struct ethtool_mmsv *mmsv, bool pmac_enabl struct stmmac_priv *priv = container_of(cfg, struct stmmac_priv, fpe_cfg);const struct stmmac_fpe_reg *reg = cfg->reg;void __iomem *ioaddr = priv->ioaddr; +unsigned long flags;u32 value; +spin_lock_irqsave (&priv->hw->irq_ctrl_lock, flags); value =readl (ioaddr + reg->int_en_reg);if (pmac_enable) {
@@ -86,6 +88,7 @@ static void stmmac_fpe_configure_pmac(struct ethtool_mmsv *mmsv, bool pmac_enabl }writel (value, ioaddr + reg->int_en_reg); +spin_unlock_irqrestore (&priv->hw->irq_ctrl_lock, flags); } static void stmmac_fpe_send_mpacket(struct ethtool_mmsv *mmsv,
Signature · 1 line
2.47.3
PATCH 2/2 net: stmmac: add support for controlling PCS interrupts
In reply to Russell King (Oracle)Add support to the PCS instance for controlling the PCS interrupts depending on whether the PCS is used.
--- .../net/ethernet/stmicro/stmmac/dwmac1000.h | 7 +++--- .../ethernet/stmicro/stmmac/dwmac1000_core.c | 11 ++++------ drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 2 -- .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 10 +++------ .../net/ethernet/stmicro/stmmac/stmmac_pcs.c | 22 ++++++++++++++++++- .../net/ethernet/stmicro/stmmac/stmmac_pcs.h | 4 +++- 6 files changed, 34 insertions(+), 22 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +3 -4
@@ -38,11 +38,10 @@#define GMAC_INT_DISABLE_PCSAN BIT(2)#define GMAC_INT_DISABLE_PMT BIT(3)#define GMAC_INT_DISABLE_TIMESTAMP BIT(9) -#define GMAC_INT_DISABLE_PCS (GMAC_INT_DISABLE_PCSLINK | \ - GMAC_INT_DISABLE_PCSAN)#define GMAC_INT_DEFAULT_MASK (GMAC_INT_DISABLE_RGMII | \ - GMAC_INT_DISABLE_TIMESTAMP | \ - GMAC_INT_DISABLE_PCS) + GMAC_INT_DISABLE_PCSLINK | \ + GMAC_INT_DISABLE_PCSAN | \ + GMAC_INT_DISABLE_TIMESTAMP)/* PMT Control and Status */ #define GMAC_PMT 0x0000002c
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +4 -7
@@ -27,7 +27,9 @@ static int dwmac1000_pcs_init(struct stmmac_priv *priv)if (!priv->dma_cap.pcs)return 0 ; -return stmmac_integrated_pcs_init (priv,GMAC_PCS_BASE ); +return stmmac_integrated_pcs_init (priv,GMAC_PCS_BASE , +GMAC_INT_DISABLE_PCSLINK | +GMAC_INT_DISABLE_PCSAN ); } static void dwmac1000_core_init(struct mac_device_info *hw,
@@ -48,12 +50,7 @@ static void dwmac1000_core_init(struct mac_device_info *hw,writel (value |GMAC_CORE_INIT , ioaddr +GMAC_CONTROL );/* Mask GMAC interrupts */ - value =GMAC_INT_DEFAULT_MASK ; - -if (hw->pcs) - value &= ~GMAC_INT_DISABLE_PCS ; - -writel (value, ioaddr +GMAC_INT_MASK ); +writel (GMAC_INT_DEFAULT_MASK , ioaddr +GMAC_INT_MASK );#ifdef STMMAC_VLAN_TAG_USED /* Tag detection without filtering */
drivers/net/ethernet/stmicro/stmmac/dwmac4.h +0 -2
@@ -106,8 +106,6 @@#define GMAC_INT_LPI_EN BIT(5)#define GMAC_INT_TSIE BIT(12) -#define GMAC_PCS_IRQ_DEFAULT (GMAC_INT_PCS_LINK | GMAC_INT_PCS_ANE) -#define GMAC_INT_DEFAULT_ENABLE (GMAC_INT_PMT_EN | GMAC_INT_LPI_EN | \ GMAC_INT_TSIE)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +3 -7
@@ -27,7 +27,8 @@ static int dwmac4_pcs_init(struct stmmac_priv *priv)if (!priv->dma_cap.pcs)return 0 ; -return stmmac_integrated_pcs_init (priv,GMAC_PCS_BASE ); +return stmmac_integrated_pcs_init (priv,GMAC_PCS_BASE , +GMAC_INT_PCS_LINK |GMAC_INT_PCS_ANE ); } static void dwmac4_core_init(struct mac_device_info *hw,
@@ -46,12 +47,7 @@ static void dwmac4_core_init(struct mac_device_info *hw,writel ((clk_rate /1000000 ) -1 , ioaddr +GMAC4_MAC_ONEUS_TIC_COUNTER );/* Enable GMAC interrupts */ - value =GMAC_INT_DEFAULT_ENABLE ; - -if (hw->pcs) - value |=GMAC_PCS_IRQ_DEFAULT ; - -writel (value, ioaddr +GMAC_INT_EN ); +writel (GMAC_INT_DEFAULT_ENABLE , ioaddr +GMAC_INT_EN );if (GMAC_INT_DEFAULT_ENABLE &GMAC_INT_TSIE )init_waitqueue_head (&priv->tstamp_busy_wait);
drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c +21 -1
@@ -2,6 +2,22 @@#include "stmmac.h" #include "stmmac_pcs.h" +static int dwmac_integrated_pcs_enable (struct phylink_pcs *pcs) +{ +struct stmmac_pcs *spcs =phylink_pcs_to_stmmac_pcs (pcs); + +stmmac_mac_irq_modify (spcs->priv,0 , spcs->int_mask); + +return 0 ; +} + +static void dwmac_integrated_pcs_disable (struct phylink_pcs *pcs) +{ +struct stmmac_pcs *spcs =phylink_pcs_to_stmmac_pcs (pcs); + +stmmac_mac_irq_modify (spcs->priv, spcs->int_mask,0 ); +} +static void dwmac_integrated_pcs_get_state (struct phylink_pcs *pcs,unsigned int neg_mode,struct phylink_link_state *state)
@@ -23,11 +39,14 @@ static int dwmac_integrated_pcs_config(struct phylink_pcs *pcs, }static const struct phylink_pcs_ops dwmac_integrated_pcs_ops = { + .pcs_enable = dwmac_integrated_pcs_enable, + .pcs_disable = dwmac_integrated_pcs_disable, .pcs_get_state = dwmac_integrated_pcs_get_state, .pcs_config = dwmac_integrated_pcs_config, }; -int stmmac_integrated_pcs_init (struct stmmac_priv *priv,unsigned int offset) +int stmmac_integrated_pcs_init (struct stmmac_priv *priv,unsigned int offset, +u32 int_mask) {struct stmmac_pcs *spcs;
@@ -37,6 +56,7 @@ int stmmac_integrated_pcs_init(struct stmmac_priv *priv, unsigned int offset) spcs->priv = priv; spcs->base = priv->ioaddr + offset; + spcs->int_mask = int_mask; spcs->pcs.ops = &dwmac_integrated_pcs_ops;__set_bit (PHY_INTERFACE_MODE_SGMII , spcs->pcs.supported_interfaces);
drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.h +3 -1
@@ -52,6 +52,7 @@ struct stmmac_priv;struct stmmac_pcs {struct stmmac_priv *priv;void __iomem *base; +u32 int_mask;struct phylink_pcs pcs; };
@@ -61,7 +62,8 @@ phylink_pcs_to_stmmac_pcs(struct phylink_pcs *pcs) return container_of(pcs, struct stmmac_pcs, pcs); } -int stmmac_integrated_pcs_init (struct stmmac_priv *priv,unsigned int offset); +int stmmac_integrated_pcs_init (struct stmmac_priv *priv,unsigned int offset, +u32 int_mask);/** * dwmac_pcs_isr - TBI, RTBI, or SGMII PHY ISR
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [PATCH net-next 1/2] net: stmmac: add stmmac_mac_irq_modify()
In reply to Russell King (Oracle)Quoted 2 lines · On Thu, 23 Oct 2025 10:46:20 +0100 Russell King (Oracle) wrote:
Add a function to allow interrupts to be enabled and disabled in a core independent manner.
Sorry for a general question but I'm curious why stick to the callback format this driver insists on. Looks like we could get away with parameterizing the code with the register offset via the priv structure.
Is it for consistency? Do you like this code structure? Is there more logic coming for .irq_modify variants? Or am I missing something else?
Mostly curious. Personally, I'm always annoyed having to dig thru the indirections in this driver.
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Thu, 23 Oct 2025 10:46:09 +0100 you wrote:
Hi,
This is the next part of stmmac PCS support. Not much here, other than dealing with what remains of the interrupts, which are the PCS AN complete and PCS Link interrupts, which are just cleared and update accounting.
[...]
Here is the summary with links:
- [net-next,1/2] net: stmmac: add stmmac_mac_irq_modify()
https://git.kernel.org/netdev/net-next/c/442a8c68f083 - [net-next,2/2] net: stmmac: add support for controlling PCS interrupts https://git.kernel.org/netdev/net-next/c/eed68edac508
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH net-next 1/2] net: stmmac: add stmmac_mac_irq_modify()
In reply to Jakub KicinskiQuoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 23 Oct 2025 10:46:20 +0100 Russell King (Oracle) wrote:
Add a function to allow interrupts to be enabled and disabled in a core independent manner.
Sorry for a general question but I'm curious why stick to the callback format this driver insists on. Looks like we could get away with parameterizing the code with the register offset via the priv structure.
Not quite - some cores, it's a mask (bits need to be set to be disabled). Other cores, it's an enable (bits need to be set to enable). So one can't get away with just "this is where the register is", it would need three pieces of information - register offset, type of regster (mask or enable) and then a core specific bitmask.
Quoted 2 lines
Mostly curious. Personally, I'm always annoyed having to dig thru the indirections in this driver.
Me too, especially when it's not obvious what is an indirection and what is not. There's the fun that a lot of the PTP-related indirection actually has no difference. For example, at the bottom of stmmac_hwtstamp.c, the struct stmmac_hwtimestamp initialisers have almost all of the methods pointing at the same implementation with the exeption of .get_ptptime, .timestamp_interrupt and .hwtstamp_correct_latency.
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!
Maxime Chevallier
maintainerRe: [PATCH net-next 1/2] net: stmmac: add stmmac_mac_irq_modify()
Quoted 15 lines · Russell King (Oracle)
Quoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 23 Oct 2025 10:46:20 +0100 Russell King (Oracle) wrote:
Add a function to allow interrupts to be enabled and disabled in a core independent manner.
Sorry for a general question but I'm curious why stick to the callback format this driver insists on. Looks like we could get away with parameterizing the code with the register offset via the priv structure.
Not quite - some cores, it's a mask (bits need to be set to be disabled). Other cores, it's an enable (bits need to be set to enable). So one can't get away with just "this is where the register is", it would need three pieces of information - register offset, type of regster (mask or enable) and then a core specific bitmask.
Quoted 5 lines
Quoted 2 lines
Mostly curious. Personally, I'm always annoyed having to dig thru the indirections in this driver.
Me too, especially when it's not obvious what is an indirection and what is not.
Same here...
Quoted 6 lines
There's the fun that a lot of the PTP-related indirection actually has no difference. For example, at the bottom of
stmmac_hwtstamp.c, the structstmmac_hwtimestampinitialisers have almost all of the methods pointing at the same implementation with the exeption of .get_ptptime, .timestamp_interrupt and .hwtstamp_correct_latency.
Well I introduced that last year. GMAC1000 and GMAC4 have what appears to be different versions of the timestamping IP, registers are either at a different address, or same address with a different layout bitwise, or with just different behaviours.
There used to be a single instance of the stmmac_hwtimestamp ops, which didn't even account for the differences between these IP versions. TBH I don't even know why we had a stmmac_hwtimestamp struct with a single instance back then, but I figured that using that was a good way to at least split the gmac1000/gmac4 diffs back then.
We coud now very much get rid of the common ops and avoid the indirections for the TS ops that are the same between all IP blocks :)
As I'm doing quite a bit of timestamping in stmmac right now, I may find a bit of time here and there to do that at some point :)
Maxime