Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Linus Walleij
Thu, 12 Nov 2026 13:30
[PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ
Author: Linus Walleij
Date: Thu, 12 Nov 2026 13:30
Date: Thu, 12 Nov 2026 13:30
325 lines
17688 bytes
17688 bytes
The software free queue interrupt is routed through port 1 even on
boards which only connect a PHY to port 0. Since PHY setup was moved
into probe, the PHY-less port fails to bind and releases the threaded
handler needed by the shared queue.
Publishing the port before PHY setup also leaves a dangling parent pointer
when probe fails and devres frees the netdev private data. Opening the
sibling can then dereference freed memory.
Keep children bound as IRQ-only ports when no PHY is described or when PHY
setup or netdev registration fails permanently, so an unusable interface
does not disable its sibling. Disconnect any attached PHY after
registration failure. Continue to propagate deferred-probe and mandatory
resource errors.
Resolve referenced PHYs explicitly and defer probe until they register.
Preserve fixed-link registration and PHY connection errors, and release
fixed links on probe failure or removal. This avoids permanently binding
a port IRQ-only just because its MDIO bus has not probed yet.
Publish a port to the parent only after its IRQ and optional netdev are
ready, and protect port lifetime with RTNL. Refuse shared queue setup
until both ports have completed initialization.
Keep shared hardware initialization parent-owned across individual child
removal so recreating one child cannot reset a live sibling. Mask
firmware interrupt state before child IRQ handlers are registered, and
use the allocated ring rather than an order sentinel to decide whether
the queue still needs initial setup.
Fixes: 3e813d61401a ("net: gemini: Clean up phy registration")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
drivers/net/ethernet/cortina/gemini.c | 165 ++++++++++++++++++++++++++--------
1 file changed, 129 insertions(+), 36 deletions(-)
diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 0b05a1552983..1b959ca853c6 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -25,6 +25,7 @@
#include <linux/interrupt.h>
#include <linux/reset.h>
#include <linux/clk.h>
+#include <linux/rtnetlink.h>
#include <linux/of.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
@@ -155,6 +156,7 @@ struct gemini_ethernet_port {
struct gemini_ethernet {
struct device *dev;
void __iomem *base;
+ /* Protected by RTNL. */
struct gemini_ethernet_port *port0;
struct gemini_ethernet_port *port1;
bool initialized;
@@ -359,18 +361,51 @@ static void gmac_adjust_link(struct net_device *netdev)
gmac_enable_tx_rx(netdev);
}
+static void gmac_deregister_fixed_link(void *data)
+{
+ of_phy_deregister_fixed_link(data);
+}
+
static int gmac_setup_phy(struct net_device *netdev)
{
struct gemini_ethernet_port *port = netdev_priv(netdev);
union gmac_status status = { .bits32 = 0 };
struct device *dev = port->dev;
+ struct device_node *phy_np;
+ phy_interface_t interface;
struct phy_device *phy;
+ int ret;
+
+ ret = of_get_phy_mode(dev->of_node, &interface);
+ if (ret)
+ return ret;
+
+ if (of_phy_is_fixed_link(dev->of_node)) {
+ ret = of_phy_register_fixed_link(dev->of_node);
+ if (ret)
+ return ret;
- phy = of_phy_get_and_connect(netdev,
- dev->of_node,
- gmac_adjust_link);
+ ret = devm_add_action_or_reset(dev, gmac_deregister_fixed_link,
+ dev->of_node);
+ if (ret)
+ return ret;
+
+ phy_np = of_node_get(dev->of_node);
+ } else {
+ phy_np = of_parse_phandle(dev->of_node, "phy-handle", 0);
+ if (!phy_np)
+ return -ENODEV;
+ }
+
+ phy = of_phy_find_device(phy_np);
+ of_node_put(phy_np);
if (!phy)
- return -ENODEV;
+ return -EPROBE_DEFER;
+
+ ret = phy_connect_direct(netdev, phy, gmac_adjust_link, interface);
+ put_device(&phy->mdio.dev);
+ if (ret)
+ return ret;
netdev->phydev = phy;
phy_set_max_speed(phy, SPEED_1000);
@@ -1051,10 +1086,17 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
u32 en;
int ret;
+ ASSERT_RTNL();
+
+ /* The software free queue interrupt is routed through port 1. */
+ if (!geth->initialized || !geth->port0 || !geth->port1)
+ return -ENODEV;
+
if (netdev->dev_id == 0)
- other_netdev = geth->port1->netdev;
+ other_port = geth->port1;
else
- other_netdev = geth->port0->netdev;
+ other_port = geth->port0;
+ other_netdev = other_port ? other_port->netdev : NULL;
if (other_netdev && netif_running(other_netdev))
return -EBUSY;
@@ -1065,7 +1107,6 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
new_size,
port->rxq_order);
if (other_netdev) {
- other_port = netdev_priv(other_netdev);
new_size += 1 << (other_port->rxq_order + 1);
netdev_dbg(other_netdev, "port %d size: %d order %d\n",
other_netdev->dev_id,
@@ -1076,7 +1117,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
new_order = min(15, ilog2(new_size - 1) + 1);
dev_dbg(geth->dev, "set shared queue to size %d order %d\n",
new_size, new_order);
- if (geth->freeq_order == new_order)
+ if (geth->freeq_ring && geth->freeq_order == new_order)
return 0;
spin_lock_irqsave(&geth->irq_lock, flags);
@@ -2387,8 +2428,35 @@ static irqreturn_t gemini_port_irq(int irq, void *data)
return ret;
}
+static void gemini_port_clear(struct gemini_ethernet_port *port)
+{
+ struct gemini_ethernet *geth = port->geth;
+
+ ASSERT_RTNL();
+
+ if (!port->id && geth->port0 == port)
+ geth->port0 = NULL;
+ else if (port->id && geth->port1 == port)
+ geth->port1 = NULL;
+ else
+ return;
+}
+
+static void gemini_ethernet_disable_irqs(struct gemini_ethernet *geth)
+{
+ writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_0_REG);
+ writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_1_REG);
+ writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_2_REG);
+ writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_3_REG);
+ writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
+}
+
static void gemini_port_remove(struct gemini_ethernet_port *port)
{
+ rtnl_lock();
+ gemini_port_clear(port);
+ rtnl_unlock();
+
if (port->netdev) {
unregister_netdev(port->netdev);
phy_disconnect(port->netdev->phydev);
@@ -2398,19 +2466,15 @@ static void gemini_port_remove(struct gemini_ethernet_port *port)
static void gemini_ethernet_init(struct gemini_ethernet *geth)
{
+ ASSERT_RTNL();
+
/* Only do this once both ports are online */
if (geth->initialized)
return;
- if (geth->port0 && geth->port1)
- geth->initialized = true;
- else
+ if (!geth->port0 || !geth->port1)
return;
- writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_0_REG);
- writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_1_REG);
- writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_2_REG);
- writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_3_REG);
- writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
+ gemini_ethernet_disable_irqs(geth);
/* Interrupt config:
*
@@ -2442,10 +2506,20 @@ static void gemini_ethernet_init(struct gemini_ethernet *geth)
writel(0, geth->base + GLOBAL_HWFQ_RWPTR_REG);
geth->freeq_frag_order = DEFAULT_RX_BUF_ORDER;
- /* This makes the queue resize on probe() so that we
- * set up and enable the queue IRQ. FIXME: fragile.
- */
- geth->freeq_order = 1;
+ geth->initialized = true;
+}
+
+static void gemini_port_publish(struct gemini_ethernet_port *port)
+{
+ struct gemini_ethernet *geth = port->geth;
+
+ ASSERT_RTNL();
+
+ if (!port->id)
+ geth->port0 = port;
+ else
+ geth->port1 = port;
+ gemini_ethernet_init(geth);
}
static void gemini_port_save_mac_addr(struct gemini_ethernet_port *port)
@@ -2541,15 +2615,6 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
reset_control_reset(port->reset);
usleep_range(100, 500);
- /* Assign pointer in the main state container */
- if (!id)
- geth->port0 = port;
- else
- geth->port1 = port;
-
- /* This will just be done once both ports are up and reset */
- gemini_ethernet_init(geth);
-
platform_set_drvdata(pdev, port);
/* Set up and register the netdev */
@@ -2600,17 +2665,39 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
if (ret)
goto unprepare;
+ if (!of_property_present(np, "phy-handle") &&
+ !of_phy_is_fixed_link(np)) {
+ dev_info(dev, "no PHY\n");
+ goto irq_only;
+ }
+
ret = gmac_setup_phy(netdev);
if (ret) {
- netdev_err(netdev,
- "PHY init failed\n");
- goto unprepare;
+ dev_err_probe(dev, ret, "PHY init failed\n");
+ if (ret == -EPROBE_DEFER)
+ goto unprepare;
+ goto irq_only;
}
- ret = register_netdev(netdev);
- if (ret)
- goto unprepare;
+ rtnl_lock();
+ ret = register_netdevice(netdev);
+ if (!ret)
+ gemini_port_publish(port);
+ rtnl_unlock();
+ if (ret) {
+ phy_disconnect(netdev->phydev);
+ dev_err(dev, "netdev registration failed: %d\n", ret);
+ goto irq_only;
+ }
+
+ return 0;
+irq_only:
+ dev_info(dev, "keeping port for shared IRQ\n");
+ port->netdev = NULL;
+ rtnl_lock();
+ gemini_port_publish(port);
+ rtnl_unlock();
return 0;
unprepare:
@@ -2706,6 +2793,9 @@ static int gemini_ethernet_probe(struct platform_device *pdev)
spin_lock_init(&geth->irq_lock);
spin_lock_init(&geth->freeq_lock);
+ /* Quiesce firmware state before child IRQ handlers are registered. */
+ gemini_ethernet_disable_irqs(geth);
+
/* The children will use this */
platform_set_drvdata(pdev, geth);
@@ -2717,10 +2807,13 @@ static void gemini_ethernet_remove(struct platform_device *pdev)
{
struct gemini_ethernet *geth = platform_get_drvdata(pdev);
+ rtnl_lock();
+ geth->initialized = false;
+ rtnl_unlock();
+
devm_of_platform_depopulate(&pdev->dev);
writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
geth_cleanup_freeq(geth);
- geth->initialized = false;
}
static const struct of_device_id gemini_ethernet_of_match[] = {
--
2.56.0
Re: [PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 14:45
Date: Mon, 16 Nov 2026 14:45
199 lines
14930 bytes
14930 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (2) · Medium: 0 · Low: 0 (1)
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] In gmac_setup_phy() (drivers/net/ethernet/cortina/gemini.c),
every NULL return from of_phy_find_device() becomes -EPROBE_DEFER.
Pre-existing issues:
- [High] At this commit, geth_resize_freeq() re-enables
SWFQ_EMPTY_INT_BIT even when geth_setup_freeq() fails.
- [High] At this commit, geth_resize_freeq() frees and rebuilds the
shared free queue under RTNL only.
- [Low] The geth_resize_freeq() kernel-doc says it 'gets called at least
once during probe()', but its only callers are gmac_open() and…
--
net: ethernet: cortina: Keep ports bound for shared IRQ
The patch keeps gemini child ports bound in an IRQ-only mode when no PHY
is described, or when PHY setup or netdev registration fails, so the
shared free queue IRQ on port 1 stays available. It looks up referenced
PHYs explicitly and defers probe until they register. It publishes a
port to the parent only once the port is ready, and the port pointers
are protected by RTNL.
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 0b05a15529832..1b959ca853c64 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
[ ... ]
> @@ -359,18 +361,51 @@ static void gmac_adjust_link(struct net_device *netdev)
[ ... ]
> static int gmac_setup_phy(struct net_device *netdev)
> {
[ ... ]
> + } else {
> + phy_np = of_parse_phandle(dev->of_node, "phy-handle", 0);
> + if (!phy_np)
> + return -ENODEV;
> + }
> +
> + phy = of_phy_find_device(phy_np);
> + of_node_put(phy_np);
> if (!phy)
> - return -ENODEV;
> + return -EPROBE_DEFER;
[Severity: High]
Can a NULL return from of_phy_find_device() here be permanent instead
of transient?
Say the MDIO bus has registered, but the PHY at that address never
answered. __of_mdiobus_parse_phys() logs the error, skips the PHY and
still registers the bus:
drivers/net/mdio/of_mdio.c:__of_mdiobus_parse_phys() {
...
if (rc == -ENODEV)
dev_err(&mdio->dev,
"MDIO device at address %d is missing.\n",
addr);
...
}
The same thing happens if the phy-handle target is not a PHY, or if its
bus driver is not built. In all of these cases no phy_device will ever
show up, but gemini_ethernet_port_probe() treats the result as a
deferral:
ret = gmac_setup_phy(netdev);
if (ret) {
dev_err_probe(dev, ret, "PHY init failed\n");
if (ret == -EPROBE_DEFER)
goto unprepare;
goto irq_only;
}
The port then never reaches gemini_port_publish(). That leaves
geth->port0 or geth->port1 NULL and geth->initialized false, and the
sibling's gmac_open()->geth_resize_freeq() returns -ENODEV on every
open:
if (!geth->initialized || !geth->port0 || !geth->port1)
return -ENODEV;
Doesn't this mean a PHY that is described but absent on one port still
disables the working sibling? The commit message says this should no
longer happen ("so an unusable interface does not disable its
sibling").
gemini-ssi1328.dts and gemini-wbd222.dts both use phy-handle on
ethernet-port@1. On those boards, an unpopulated or unresponsive PHY1
would leave no working Ethernet, and the port would stay on the deferred
probe list for good. fw_devlink does not parse phy-handle, so nothing
puts a limit on the deferral.
Could the code tell a not-yet-probed MDIO bus apart from a missing PHY,
for example by checking whether the PHY node's parent bus has
registered?
[ ... ]
> @@ -1051,10 +1086,17 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
> u32 en;
> int ret;
>
> + ASSERT_RTNL();
> +
> + /* The software free queue interrupt is routed through port 1. */
> + if (!geth->initialized || !geth->port0 || !geth->port1)
> + return -ENODEV;
> +
[Severity: Low]
This isn't a bug introduced by this patch, but the kernel-doc above
geth_resize_freeq() still says:
* This gets called at least once during probe() so the device queue gets
* "resized" from the hardware defaults.
The only callers are gmac_open() and gmac_set_ringparam(). The doc also
doesn't mention the new ASSERT_RTNL() requirement or the -ENODEV return.
A later patch in the series rewrites it to "This is called when a port
is opened or its RX ring size changes."
[ ... ]
> @@ -1076,7 +1117,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
> new_order = min(15, ilog2(new_size - 1) + 1);
> dev_dbg(geth->dev, "set shared queue to size %d order %d\n",
> new_size, new_order);
> - if (geth->freeq_order == new_order)
> + if (geth->freeq_ring && geth->freeq_order == new_order)
> return 0;
>
> spin_lock_irqsave(&geth->irq_lock, flags);
[Severity: High]
This is a pre-existing issue and was not introduced by this patch.
Further down in geth_resize_freeq(), SWFQ_EMPTY_INT_BIT is turned back
on even when geth_setup_freeq() fails:
geth->freeq_order = new_order;
ret = geth_setup_freeq(geth);
...
spin_lock_irqsave(&geth->irq_lock, flags);
en |= SWFQ_EMPTY_INT_BIT;
writel(en, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
spin_unlock_irqrestore(&geth->irq_lock, flags);
return ret;
If setup fails, freeq_ring is left NULL while freeq_pages still points
at freed memory. Can gemini_port_irq_thread()->geth_fill_freeq() then
dereference the freed array and call page_ref_add() on stale pages?
This looks like it is addressed later in the series by "net: ethernet:
cortina: Drain free queue IRQ before resize". That commit enables the
source only when setup succeeds, and geth_setup_freeq() and
geth_cleanup_freeq() set freeq_pages and freeq_ring to NULL.
[Severity: High]
This is also a pre-existing issue and not something added by this patch.
In geth_resize_freeq(), only RTNL serializes the queue teardown:
/* Drop the old queue */
if (geth->freeq_ring)
geth_cleanup_freeq(geth);
There is no synchronize_irq() here, and freeq_lock is not held. If
gemini_port_irq_thread() was already woken, could it run
geth_fill_freeq() on the freed freeq_pages and freeq_ring? Could it
then re-arm the source while the queue is being torn down?
irqmask |= readl(geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
writel(irqmask, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
The same later commit, "net: ethernet: cortina: Drain free queue IRQ
before resize", wraps the rebuild in disable_irq(geth->port1->irq) and
enable_irq(). That drains both the hard and the threaded handler.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3%40kernel.org
Re: [PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ
Author: Linus Walleij
Date: Tue, 17 Nov 2026 07:53
Date: Tue, 17 Nov 2026 07:53
44 lines
10368 bytes
10368 bytes
On Mon, Nov 16, 2026 at 3:45 PM <netdev-bot+sashiko@kernel.org> wrote:
> > + } else {
> > + phy_np = of_parse_phandle(dev->of_node, "phy-handle", 0);
> > + if (!phy_np)
> > + return -ENODEV;
> > + }
> > +
> > + phy = of_phy_find_device(phy_np);
> > + of_node_put(phy_np);
> > if (!phy)
> > - return -ENODEV;
> > + return -EPROBE_DEFER;
>
> [Severity: High]
> Can a NULL return from of_phy_find_device() here be permanent instead
> of transient?
I guess yes? Then things never probe, such things happen.
> Doesn't this mean a PHY that is described but absent on one port still
> disables the working sibling? The commit message says this should no
> longer happen ("so an unusable interface does not disable its
> sibling").
>
> gemini-ssi1328.dts and gemini-wbd222.dts both use phy-handle on
> ethernet-port@1. On those boards, an unpopulated or unresponsive PHY1
> would leave no working Ethernet, and the port would stay on the deferred
> probe list for good. fw_devlink does not parse phy-handle, so nothing
> puts a limit on the deferral.
>
> Could the code tell a not-yet-probed MDIO bus apart from a missing PHY,
> for example by checking whether the PHY node's parent bus has
> registered?
So this is essentially trying to safeguard from hw failure which
is overzealous. If the PHY does the driver doesn't probe eventually
deferred probe gives up, thats OK.
Yours,
Linus Walleij
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads