* [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev
@ 2023-05-26 10:13 Russell King (Oracle)
2023-05-26 10:14 ` [PATCH net-next 3/6] net: stmmac: use xpcs_create_mdiodev() Russell King (Oracle)
2023-05-30 5:00 ` [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev patchwork-bot+netdevbpf
0 siblings, 2 replies; 4+ messages in thread
From: Russell King (Oracle) @ 2023-05-26 10:13 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Belloni, Alexandre Torgue, Claudiu Manoil,
David S. Miller, Eric Dumazet, Florian Fainelli,
Giuseppe Cavallaro, Ioana Ciornei, Jakub Kicinski, Jiawen Wu,
Jose Abreu, Jose Abreu, linux-arm-kernel, linux-stm32,
Maxime Chevallier, Maxime Coquelin, netdev, Paolo Abeni,
Simon Horman, UNGLinuxDriver, Vladimir Oltean
Hi,
This morning, we have had two instances where the destruction of the
MDIO device associated with XPCS and Lynx has been wrong. Rather than
allowing this pattern of errors to continue, let's make it easier for
driver authors to get this right by adding a helper.
The changes are essentially:
1. Add two new mdio device helpers to manage the underlying struct
device reference count. Note that the existing mdio_device_free()
doesn't actually free anything, it merely puts the reference count.
2. Make the existing _create() and _destroy() PCS driver methods
increment and decrement this refcount using these helpers. This
results in no overall change, although drivers may hang on to
the mdio device for a few cycles longer.
3. Add _create_mdiodev() which creates the mdio device before calling
the existing _create() method. Once the _create() method has
returned, we put the reference count on the mdio device.
If _create() was successful, then the reference count taken there
will "hold" the mdio device for the lifetime of the PCS (in other
words, until _destroy() is called.) However, if _create() failed,
then dropping the refcount at this point will free the mdio device.
This is the exact behaviour we desire.
4. Convert users that create a mdio device and then call the PCS's
_create() method over to the new _create_mdiodev() method, and
simplify the cleanup.
We also have DPAA2 and fmem_memac that look up their PCS rather than
creating it. These could also drop their reference count on the MDIO
device immediately after calling lynx_pcs_create(), which would then
mean we wouldn't need lynx_get_mdio_device() and the associated
complexity to put the device in dpaa2_pcs_destroy() and pcs_put().
Note that DPAA2 bypasses the mdio device's abstractions by calling
put_device() directly.
drivers/net/dsa/ocelot/felix_vsc9959.c | 20 +++------------
drivers/net/dsa/ocelot/seville_vsc9953.c | 20 +++------------
drivers/net/ethernet/freescale/enetc/enetc_pf.c | 22 +++-------------
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 15 +++--------
drivers/net/pcs/pcs-lynx.c | 31 +++++++++++++++++++++++
drivers/net/pcs/pcs-xpcs.c | 28 ++++++++++++++++++++
include/linux/mdio.h | 10 ++++++++
include/linux/pcs-lynx.h | 1 +
include/linux/pcs/pcs-xpcs.h | 2 ++
9 files changed, 87 insertions(+), 62 deletions(-)
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next 3/6] net: stmmac: use xpcs_create_mdiodev()
2023-05-26 10:13 [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev Russell King (Oracle)
@ 2023-05-26 10:14 ` Russell King (Oracle)
2023-05-29 15:26 ` Andrew Lunn
2023-05-30 5:00 ` [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev patchwork-bot+netdevbpf
1 sibling, 1 reply; 4+ messages in thread
From: Russell King (Oracle) @ 2023-05-26 10:14 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Jiawen Wu, Maxime Chevallier, Simon Horman, Giuseppe Cavallaro,
Alexandre Torgue, Jose Abreu, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, netdev, linux-stm32,
linux-arm-kernel
Use the new xpcs_create_mdiodev() creator, which simplifies the
creation and destruction of the mdio device associated with xpcs.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 6807c4c1a0a2..3db1cb0fd160 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -491,7 +491,6 @@ int stmmac_mdio_reset(struct mii_bus *bus)
int stmmac_xpcs_setup(struct mii_bus *bus)
{
struct net_device *ndev = bus->priv;
- struct mdio_device *mdiodev;
struct stmmac_priv *priv;
struct dw_xpcs *xpcs;
int mode, addr;
@@ -501,16 +500,10 @@ int stmmac_xpcs_setup(struct mii_bus *bus)
/* Try to probe the XPCS by scanning all addresses. */
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
- mdiodev = mdio_device_create(bus, addr);
- if (IS_ERR(mdiodev))
+ xpcs = xpcs_create_mdiodev(bus, addr, mode);
+ if (IS_ERR(xpcs))
continue;
- xpcs = xpcs_create(mdiodev, mode);
- if (IS_ERR_OR_NULL(xpcs)) {
- mdio_device_free(mdiodev);
- continue;
- }
-
priv->hw->xpcs = xpcs;
break;
}
@@ -669,10 +662,8 @@ int stmmac_mdio_unregister(struct net_device *ndev)
if (!priv->mii)
return 0;
- if (priv->hw->xpcs) {
- mdio_device_free(priv->hw->xpcs->mdiodev);
+ if (priv->hw->xpcs)
xpcs_destroy(priv->hw->xpcs);
- }
mdiobus_unregister(priv->mii);
priv->mii->priv = NULL;
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net-next 3/6] net: stmmac: use xpcs_create_mdiodev()
2023-05-26 10:14 ` [PATCH net-next 3/6] net: stmmac: use xpcs_create_mdiodev() Russell King (Oracle)
@ 2023-05-29 15:26 ` Andrew Lunn
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2023-05-29 15:26 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: Heiner Kallweit, Jiawen Wu, Maxime Chevallier, Simon Horman,
Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
netdev, linux-stm32, linux-arm-kernel
On Fri, May 26, 2023 at 11:14:34AM +0100, Russell King (Oracle) wrote:
> Use the new xpcs_create_mdiodev() creator, which simplifies the
> creation and destruction of the mdio device associated with xpcs.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev
2023-05-26 10:13 [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev Russell King (Oracle)
2023-05-26 10:14 ` [PATCH net-next 3/6] net: stmmac: use xpcs_create_mdiodev() Russell King (Oracle)
@ 2023-05-30 5:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-05-30 5:00 UTC (permalink / raw)
To: Russell King
Cc: andrew, hkallweit1, alexandre.belloni, alexandre.torgue,
claudiu.manoil, davem, edumazet, f.fainelli, peppe.cavallaro,
ioana.ciornei, kuba, jiawenwu, joabreu, Jose.Abreu,
linux-arm-kernel, linux-stm32, maxime.chevallier, mcoquelin.stm32,
netdev, pabeni, simon.horman, UNGLinuxDriver, vladimir.oltean
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 26 May 2023 11:13:59 +0100 you wrote:
> Hi,
>
> This morning, we have had two instances where the destruction of the
> MDIO device associated with XPCS and Lynx has been wrong. Rather than
> allowing this pattern of errors to continue, let's make it easier for
> driver authors to get this right by adding a helper.
>
> [...]
Here is the summary with links:
- [net-next,1/6] net: mdio: add mdio_device_get() and mdio_device_put()
https://git.kernel.org/netdev/net-next/c/c4933fa88a68
- [net-next,2/6] net: pcs: xpcs: add xpcs_create_mdiodev()
https://git.kernel.org/netdev/net-next/c/9a5d500cffdb
- [net-next,3/6] net: stmmac: use xpcs_create_mdiodev()
https://git.kernel.org/netdev/net-next/c/727e373f897d
- [net-next,4/6] net: pcs: lynx: add lynx_pcs_create_mdiodev()
https://git.kernel.org/netdev/net-next/c/86b5f2d8cd78
- [net-next,5/6] net: dsa: ocelot: use lynx_pcs_create_mdiodev()
https://git.kernel.org/netdev/net-next/c/5767c6a8d9b7
- [net-next,6/6] net: enetc: use lynx_pcs_create_mdiodev()
https://git.kernel.org/netdev/net-next/c/b7d5d0438e01
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-30 5:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-26 10:13 [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev Russell King (Oracle)
2023-05-26 10:14 ` [PATCH net-next 3/6] net: stmmac: use xpcs_create_mdiodev() Russell King (Oracle)
2023-05-29 15:26 ` Andrew Lunn
2023-05-30 5:00 ` [PATCH net-next 0/6] net: pcs: add helpers to xpcs and lynx to manage mdiodev patchwork-bot+netdevbpf
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).