Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management
@ 2026-11-12 13:30 Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 01/19] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
                   ` (18 more replies)
  0 siblings, 19 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The Gemini ethernet uses a custom software free queue shared by both
ports. Its page metadata, DMA mappings and fragment references are not
managed consistently as pages move through the free queue and RX queues.

Correct the DMA address bookkeeping and synchronization.

Track exact fragment mappings with an XArray and keep
in-flight page metadata in bitmap-allocated slots until all hardware
references have been claimed.

Serialize queue resize against the refill interrupt, harden fragment
validation and teardown, then scale the default queue sizes for systems
with 32 or 64 MiB of RAM.

This series wasn't so complex to begin with but Sashiko and the other
LLMs just find more and more corner cases. It's for the better I
guess.

Before these patches the network driver would crash under strong load
but it does not happen any more after. Tested on the D-Link DIR-685
playing back media and transfering new media using ksmbd while
issuing ping storms.

Target the series for net-next, Sashiko keeps insisting to make some
patches Fixes: tagged, and yeah maybe it's true but OpenWrt is the
only user and I will surely backport all patches to OpenWrt anyway.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
Changes in v8:
- Protect TX fragment statistics updates during process-context teardown.
- Rebuild idle shared free queues on reopen to reclaim unclaimed fragments.
- Separate RX buffer capacity from retained-pointer descriptor ring sizing.
- Preserve PHY probe deferral and clean up fixed links on probe failure or removal.
- Link to v7: https://patch.msgid.link/20261110-gemini-ethernet-fixes-3-v7-0-9c32a1a46aec@kernel.org

Changes in v7:
- Bound free queue refill work and release surplus metadata on downsizing.
- Serialize TX completion statistics with the IRQ-side writers.
- Fix ethtool statistics retry bounds and counter synchronization.
- Reject pfmemalloc pages when recycling RX buffers.
- Document XArray dependency for lifetime and recycling backports.
- Reject TX rings smaller than retained hardware pointers, so now the
  series has also started to fix things on the TX path.
- Document the retained SWFQ pointer shrink and allocation limits.
- Keep ports IRQ-only after PHY setup or netdev registration failure.
- Keep parent-held port clocks enabled through IRQ draining and queue teardown.
- Link to v6: https://patch.msgid.link/20261103-gemini-ethernet-fixes-3-v6-0-c4b5ff8a65d8@kernel.org

Changes in v6:
- Initialize statistics synchronization objects for lockdep.
- Post free queue pages from the exact retained descriptor pointer.
- Document replacement-page lookup failures and tag the DMA mapping fix.
- Initialize and drain the RX coalescing timer around its IRQ lifetime.
- Rebased on v7.4-rc1
- Link to v5: https://patch.msgid.link/20261015-gemini-ethernet-fixes-3-v5-0-b5c9e2f7b8a3@kernel.org

Changes in v5:
- Preserve complete frames terminated by an empty EOF descriptor.
- Recheck concurrently retired pages before consuming fresh metadata slots.
- Fold RX ring metadata sizing and resize rollback into the page lifetime
  fix.
- Match free queue teardown unmaps to the saved full-page DMA mapping.
- Preserve the hardware-owned free queue read pointer across rebuilds and
  keep replacement rings large enough for its retained position.
- Keep shared initialization parent-owned, quiesce inherited IRQ state
  before child handlers register and force first queue setup from ring
  state.
- Link to v4: https://patch.msgid.link/20261011-gemini-ethernet-fixes-3-v4-0-4b1631b08f5d@kernel.org

Changes in v4:
- Protect stop-path RX statistics updates against preemption on 32-bit systems.
- Validate final RX lengths against the Ethernet minimum and descriptor
  transfer size so malformed chains cannot pass short skbs to GRO.
- Charge the full posted RX fragment size in skb truesize accounting.
- Reject free queue geometries that cannot post one complete page and
  document the changed refill and recycling behavior.
- Reset the free queue allocation cursor with its bitmap during teardown.
- Bound recycler IRQ latency and release retained mappings for stack-owned
  pages before allocating replacements.
- Rebuild oversized free queues while both ports are down so RX ring
  downsizing releases the surplus pages.
- Scope RX statistics writer sections to counter updates for PREEMPT_RT.
- Restrict shared free queue handling to port 1 so IRQ draining covers
  every registered handler path.
- Reset and mask free queue pointers when rebuilding the queue.
- Reorder the shared queue ownership fix before the port lifetime fix.
- Publish ports only after setup, serialize their lifetime with RTNL and
  suppress independent child unbind while port 1 owns the shared IRQ.
- Move child-unbind suppression and PHY teardown ordering into the
  parent-ownership patch.
- Link to v3: https://patch.msgid.link/20261002-gemini-ethernet-fixes-3-v3-0-3e1f25890ae8@kernel.org

Changes in v3:
- Add Fixes tags throughout the series, using the original driver commit
  where no more specific offending commit exists, and replace Resolves with
  Closes on the lifetime fix. I did not retarget the series to net
  because there are dependencies in net-next and we are getting closer
  to the merge window.
- Keep PHY-less port 1 bound as the shared free queue IRQ owner and clear
  stale parent port pointers.
- Disable the port 1 Linux IRQ throughout free queue resizing so no newly
  woken threaded handler can race queue teardown or setup.
- Keep failed queue rebuilds quiescent in the IRQ-drain patch.
- Serialize linear DMA lookups before converting them to an XArray.
- Keep all XArray mutation under the IRQ-safe free queue lock.
- Defer page unmapping until fragment lifetime is tracked, and fold DMA
  synchronization into that fix.
- Check free queue space before allocating and mapping a candidate page.
- Rebuild free queue metadata when RX rings grow and roll back rejected
  ring changes.
- Recycle released pages with explicit DMA synchronization using the
  existing free queue allocator.
- Account inconsistent RX descriptor lengths as drops rather than wire
  length errors.
- Count partial RX frames discarded during stop as dropped.
- Drop the cleanup guard conversion because it is not recommended for
  network drivers.
- Link to v2: https://patch.msgid.link/20260928-gemini-ethernet-fixes-3-v2-0-758a795d7a78@kernel.org

Changes in v2:
- Replace the page_pool conversion with several smaller fixes using the
  existing free queue page allocator.
- Split DMA bookkeeping, XArray lookup, bitmap allocation, cursor rotation,
  synchronization, validation and teardown into individual patches.
- Drain the threaded free queue interrupt before resizing the shared queue.
- Allocate and DMA-map refill pages outside the IRQ-disabled free queue
  lock.
- Reject and unwind partial initial free queue fills, reset their hardware
  pointers and leave the refill interrupt masked so setup can be retried.
- Avoid full-page CPU synchronization after fragments enter the network
  stack.
- Bound RX lengths to the posted fragment and account rejected lengths as
  receive errors.
- Keep the fixes, and keep the add-on RAM sizing patch.
- Link to v1: https://patch.msgid.link/20260920-gemini-ethernet-fixes-3-v1-0-3a2a50a83d89@kernel.org

---
Linus Walleij (19):
      net: ethernet: cortina: Keep shared free queue parent-owned
      net: ethernet: cortina: Keep ports bound for shared IRQ
      net: ethernet: cortina: Drain free queue IRQ before resize
      net: ethernet: cortina: Normalize free queue pointers on rebuild
      net: ethernet: cortina: Correct free queue DMA mappings
      net: ethernet: cortina: Index free queue fragments with XArray
      net: ethernet: cortina: Preserve in-flight free queue pages
      net: ethernet: cortina: Rotate free queue page allocation
      net: ethernet: cortina: Recycle claimed free queue pages
      net: ethernet: cortina: Separate RX buffer capacity from free queue size
      net: ethernet: cortina: Validate RX fragment lengths
      net: ethernet: cortina: Account RX buffer size in truesize
      net: ethernet: cortina: Release partial RX frames on stop
      net: ethernet: cortina: Scale Gemini RX queues to system memory
      net: ethernet: cortina: Serialize TX completion statistics
      net: ethernet: cortina: Scope RX statistics updates
      net: ethernet: cortina: Drain RX coalescing timer on stop
      net: ethernet: cortina: Reject TX rings smaller than retained pointers
      net: ethernet: cortina: Fix ethtool statistics reads

 drivers/net/ethernet/cortina/gemini.c | 1009 +++++++++++++++++++++++++--------
 drivers/net/ethernet/cortina/gemini.h |    2 +-
 2 files changed, 766 insertions(+), 245 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260919-gemini-ethernet-fixes-3-f0403653f23a

Best regards,
--  
Linus Walleij <linusw@kernel.org>


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 01/19] net: ethernet: cortina: Keep shared free queue parent-owned
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The software free queue is shared by both Ethernet ports, but teardown is
not ordered around that ownership. On parent unbind or module unload, the
parent remove callback runs before devres depopulates the child devices. It
therefore destroys the queue while both child netdevs are still registered
and can be doing DMA. Devres then removes each child, and both child remove
callbacks destroy the same queue again, resulting in up to three cleanup
attempts.

Removal before the first interface has been opened is broken as well. The
shared block initialization assigns a nonzero queue order, but allocation
is deferred until open. Cleanup consequently derives a nonzero page count
and dereferences the NULL queue ring.

Depopulate both port devices before cleaning up the queue, and perform that
cleanup only from the parent. Disable the free-queue interrupt after the
managed handlers have drained, since its threaded handler can re-enable it.
Guard cleanup for paths where no queue was allocated.

Hold parent-managed enables on the port clocks across child removal, IRQ
draining and shared queue cleanup, so teardown never relies on clocks
already released by the children.

Port 1 owns the shared refill interrupt, so prevent the children from being
unbound independently. Unregister each netdev before detaching its PHY so
ndo_stop can still access netdev->phydev.

Reported-by: Myeonghun Pak <mhun512@gmail.com>
Closes: https://lore.kernel.org/netdev/20260917192835.58126-1-mhun512@gmail.com/
Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 40 +++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 2fe7fd0202d2..0b05a1552983 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1004,6 +1004,9 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 	unsigned int pages = len >> fpp_order;
 	unsigned int pn;
 
+	if (!geth->freeq_ring)
+		return;
+
 	writew(readw(geth->base + GLOBAL_SWFQ_RWPTR_REG),
 	       geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
 	writel(0, geth->base + GLOBAL_SW_FREEQ_BASE_SIZE_REG);
@@ -2387,11 +2390,10 @@ static irqreturn_t gemini_port_irq(int irq, void *data)
 static void gemini_port_remove(struct gemini_ethernet_port *port)
 {
 	if (port->netdev) {
-		phy_disconnect(port->netdev->phydev);
 		unregister_netdev(port->netdev);
+		phy_disconnect(port->netdev->phydev);
 	}
 	clk_disable_unprepare(port->pclk);
-	geth_cleanup_freeq(port->geth);
 }
 
 static void gemini_ethernet_init(struct gemini_ethernet *geth)
@@ -2635,17 +2637,25 @@ static struct platform_driver gemini_ethernet_port_driver = {
 	.driver = {
 		.name = "gemini-ethernet-port",
 		.of_match_table = gemini_ethernet_port_of_match,
+		.suppress_bind_attrs = true,
 	},
 	.probe = gemini_ethernet_port_probe,
 	.remove = gemini_ethernet_port_remove,
 };
 
+static void gemini_ethernet_disable_clk(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int gemini_ethernet_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct gemini_ethernet *geth;
 	unsigned int retry = 5;
+	unsigned int clocks = 0;
 	u32 val;
+	int ret;
 
 	/* Global registers */
 	geth = devm_kzalloc(dev, sizeof(*geth), GFP_KERNEL);
@@ -2656,6 +2666,30 @@ static int gemini_ethernet_probe(struct platform_device *pdev)
 		return PTR_ERR(geth->base);
 	geth->dev = dev;
 
+	/* Keep both port clocks enabled until the shared queue is torn down. */
+	for_each_available_child_of_node_scoped(dev->of_node, child) {
+		struct clk *clk;
+
+		if (!of_device_is_compatible(child, "cortina,gemini-ethernet-port"))
+			continue;
+
+		clk = devm_get_clk_from_child(dev, child, "PCLK");
+		if (IS_ERR(clk))
+			return dev_err_probe(dev, PTR_ERR(clk),
+					     "failed to get port clock\n");
+
+		ret = clk_prepare_enable(clk);
+		if (ret)
+			return ret;
+		ret = devm_add_action_or_reset(dev, gemini_ethernet_disable_clk,
+					       clk);
+		if (ret)
+			return ret;
+		clocks++;
+	}
+	if (!clocks)
+		return -ENODEV;
+
 	/* Wait for ports to stabilize */
 	do {
 		udelay(2);
@@ -2683,6 +2717,8 @@ static void gemini_ethernet_remove(struct platform_device *pdev)
 {
 	struct gemini_ethernet *geth = platform_get_drvdata(pdev);
 
+	devm_of_platform_depopulate(&pdev->dev);
+	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
 	geth_cleanup_freeq(geth);
 	geth->initialized = false;
 }

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 01/19] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-16 14:45   ` netdev-bot+sashiko
  2026-11-12 13:30 ` [PATCH net-next v8 03/19] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
                   ` (16 subsequent siblings)
  18 siblings, 1 reply; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

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


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 03/19] net: ethernet: cortina: Drain free queue IRQ before resize
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 01/19] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 04/19] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The software free queue interrupt remains registered while both netdevs
are down. Merely masking the device source does not stop a threaded
handler which was already woken. That handler can refill the queue while
resize frees its ring and page metadata, or re-enable the source after
teardown.

The free queue interrupt is routed through port 1, but both port IRQs
register the global handler. Ignore the source on port 0, then disable the
port 1 Linux IRQ for the entire resize. disable_irq() drains hard and
threaded handlers and prevents a new thread from being woken.

After the drain, mask the device source and rebuild the queue. If setup
succeeds, re-enable the source before the Linux IRQ. On failure, keep the
source masked, clear freed queue state and restore the Linux IRQ so a later
open retries setup safely.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 53 +++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 1b959ca853c6..5eade1394a56 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1019,6 +1019,8 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	}
 
 	kfree(geth->freeq_pages);
+	geth->freeq_pages = NULL;
+	geth->num_freeq_pages = 0;
 err_freeq:
 	dma_free_coherent(geth->dev,
 			  sizeof(*geth->freeq_ring) << geth->freeq_order,
@@ -1059,20 +1061,37 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 	}
 
 	kfree(geth->freeq_pages);
+	geth->freeq_pages = NULL;
+	geth->num_freeq_pages = 0;
 
 	dma_free_coherent(geth->dev,
 			  sizeof(*geth->freeq_ring) << geth->freeq_order,
 			  geth->freeq_ring, geth->freeq_dma_base);
+	geth->freeq_ring = NULL;
+}
+
+static void geth_set_freeq_irq(struct gemini_ethernet *geth, bool enable)
+{
+	unsigned long flags;
+	u32 val;
+
+	spin_lock_irqsave(&geth->irq_lock, flags);
+	val = readl(geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
+	if (enable)
+		val |= SWFQ_EMPTY_INT_BIT;
+	else
+		val &= ~SWFQ_EMPTY_INT_BIT;
+	writel(val, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
+	spin_unlock_irqrestore(&geth->irq_lock, flags);
 }
 
 /**
  * geth_resize_freeq() - resize the software queue depth
  * @port: the port requesting the change
  *
- * This gets called at least once during probe() so the device queue gets
- * "resized" from the hardware defaults. Since both ports/net devices share
- * the same hardware queue, some synchronization between the ports is
- * needed.
+ * This is called when a port is opened or its RX ring size changes. Since
+ * both ports/net devices share the same hardware queue, some synchronization
+ * between the ports is needed.
  */
 static int geth_resize_freeq(struct gemini_ethernet_port *port)
 {
@@ -1082,8 +1101,6 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	struct net_device *other_netdev;
 	unsigned int new_size = 0;
 	unsigned int new_order;
-	unsigned long flags;
-	u32 en;
 	int ret;
 
 	ASSERT_RTNL();
@@ -1120,13 +1137,8 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	if (geth->freeq_ring && geth->freeq_order == new_order)
 		return 0;
 
-	spin_lock_irqsave(&geth->irq_lock, flags);
-
-	/* Disable the software queue IRQs */
-	en = readl(geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
-	en &= ~SWFQ_EMPTY_INT_BIT;
-	writel(en, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
-	spin_unlock_irqrestore(&geth->irq_lock, flags);
+	disable_irq(geth->port1->irq);
+	geth_set_freeq_irq(geth, false);
 
 	/* Drop the old queue */
 	if (geth->freeq_ring)
@@ -1136,14 +1148,10 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	geth->freeq_order = new_order;
 	ret = geth_setup_freeq(geth);
 
-	/* Restart the interrupts - NOTE if this is the first resize
-	 * after probe(), this is where the interrupts get turned on
-	 * in the first place.
-	 */
-	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);
+	/* Enable the queue interrupt only after successful setup. */
+	if (!ret)
+		geth_set_freeq_irq(geth, true);
+	enable_irq(geth->port1->irq);
 
 	return ret;
 }
@@ -2406,6 +2414,9 @@ static irqreturn_t gemini_port_irq(int irq, void *data)
 	irqreturn_t ret = IRQ_NONE;
 	u32 val, en;
 
+	if (!port->id)
+		return IRQ_NONE;
+
 	geth = port->geth;
 	spin_lock(&geth->irq_lock);
 

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 04/19] net: ethernet: cortina: Normalize free queue pointers on rebuild
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (2 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 03/19] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 05/19] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The free queue read pointer is owned by hardware and can retain a
position from the previous ring when the queue is rebuilt at a smaller
order. Using an unmasked pointer to index the replacement page table can
then access it out of bounds. A replacement ring which does not contain
the raw retained pointer can also let hardware address past the new
allocation.

Mask software page indices to the active queue order. Keep the
replacement ring large enough for the retained hardware pointer and
initialize the software-owned write pointer from it before filling the
ring. This represents an empty queue without relying on a read-pointer
reset.

Testing on a D-Link DIR-685 with both ports stopped and the free queue
disabled showed that neither a 16-bit zero write to rptr nor a 32-bit
zero write to the pointer register resets rptr. The latter clears only
wptr. Clearing the queue base also leaves rptr unchanged. Networking
recovered after each rebuild, with all ten ping replies received.

A retained pointer can prevent shrinking the descriptor allocation. At
order 15 this is a 512 KiB ring. Buffer allocation initially follows that
order too, approaching 64 MiB; a following patch decouples the RX buffer
budget from descriptor geometry. If allocation fails, retries see the
same floor while DMA is stopped. Keep the queue disabled rather than use
a descriptor ring that cannot contain the retained pointer. Removing
this restriction requires verified pointer-reset or truncation behaviour.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 5eade1394a56..31dd4ddad9ea 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -920,6 +920,7 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth, bool refill)
 
 	rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 	pn = (refill ? rw.bits.wptr : rw.bits.rptr) >> fpp_order;
+	pn &= m_pn;
 	epn = (rw.bits.rptr >> fpp_order) - 1;
 	epn &= m_pn;
 
@@ -969,6 +970,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	union dma_skb_size skbsz;
 	unsigned int filled;
 	unsigned int pn;
+	u16 rptr;
 
 	geth->freeq_ring = dma_alloc_coherent(geth->dev,
 		sizeof(*geth->freeq_ring) << geth->freeq_order,
@@ -991,6 +993,10 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 		if (!geth_freeq_alloc_map_page(geth, pn))
 			goto err_freeq_alloc;
 
+	/* Match the software pointer to the retained hardware pointer. */
+	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
+	SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, rptr & (len - 1));
+
 	filled = geth_fill_freeq(geth, false);
 	if (!filled)
 		goto err_freeq_alloc;
@@ -1101,6 +1107,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	struct net_device *other_netdev;
 	unsigned int new_size = 0;
 	unsigned int new_order;
+	u16 rptr;
 	int ret;
 
 	ASSERT_RTNL();
@@ -1132,6 +1139,10 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	}
 
 	new_order = min(15, ilog2(new_size - 1) + 1);
+	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
+	if (rptr >= BIT(15))
+		return -EIO;
+	new_order = max_t(unsigned int, new_order, fls(rptr));
 	dev_dbg(geth->dev, "set shared queue to size %d order %d\n",
 		new_size, new_order);
 	if (geth->freeq_ring && geth->freeq_order == new_order)

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 05/19] net: ethernet: cortina: Correct free queue DMA mappings
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (3 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 04/19] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 06/19] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The free queue maps complete pages and splits each mapping between its
fragment descriptors. The mapping variable is advanced while filling the
descriptors and that advanced address is then saved as the page mapping.

Replacement also reads the old address after overwriting the descriptor
with the new mapping, so it unmaps the new buffer while leaving the old
mapping live.

The same reassignment leaves replacement metadata holding the new page
base while gmac_rx() still adds PAGE_SIZE before lookup. Once a page is
replaced under RX load, lookup therefore normally fails with "could not
find mapping" and drops the frame. If the resulting key matches another
page, RX can instead attach that page to the skb and drop the wrong page
reference.

Keep the page DMA base separate from the fragment iterator and remove the
invalid replacement unmap. The replaced mapping cannot be released until
its in-flight fragments have been claimed, which is handled with their
lifetime later in the series. Use the saved DMA base and PAGE_SIZE when
unwinding setup and tearing down the current queue.

Reject mappings that cannot fit in the 32-bit hardware descriptors and
derive fragment offsets from the saved DMA base instead of assuming
page-aligned DMA addresses. Snapshot the page, DMA base and offset under
the free queue lock so refill cannot replace them between lookup and use.

The locked linear scan is temporary: the following "Index free queue
fragments with XArray" patch removes it. Backport this change together
with that patch, "Preserve in-flight free queue pages" and "Recycle
claimed free queue pages", which complete the mapping lifetime and DMA
synchronization fixes.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 112 ++++++++++++++++++----------------
 1 file changed, 58 insertions(+), 54 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 31dd4ddad9ea..b96325f652bb 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -759,32 +759,43 @@ static int gmac_setup_rxq(struct net_device *netdev)
 	return 0;
 }
 
-static struct gmac_queue_page *
-gmac_get_queue_page(struct gemini_ethernet *geth,
-		    struct gemini_ethernet_port *port,
-		    dma_addr_t addr)
+static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
+				      dma_addr_t mapping,
+				      unsigned int *page_offs)
 {
+	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	struct gmac_queue_page *gpage;
-	dma_addr_t mapping;
+	unsigned long flags;
+	dma_addr_t page_mapping;
+	struct page *page = NULL;
 	int i;
 
-	/* Only look for even pages */
-	mapping = addr & PAGE_MASK;
-
+	spin_lock_irqsave(&geth->freeq_lock, flags);
 	if (!geth->freeq_pages) {
 		dev_err_ratelimited(geth->dev,
 				    "try to get page with no page list\n");
-		return NULL;
+		goto unlock;
 	}
 
 	/* Look up a ring buffer page from virtual mapping */
 	for (i = 0; i < geth->num_freeq_pages; i++) {
 		gpage = &geth->freeq_pages[i];
-		if (gpage->mapping == mapping)
-			return gpage;
+		if (!gpage->page || mapping < gpage->mapping)
+			continue;
+
+		page_mapping = gpage->mapping;
+		if (mapping - page_mapping > PAGE_SIZE - frag_len ||
+		    ((mapping - page_mapping) & (frag_len - 1)))
+			continue;
+
+		page = gpage->page;
+		*page_offs = mapping - page_mapping;
+		break;
 	}
 
-	return NULL;
+unlock:
+	spin_unlock_irqrestore(&geth->freeq_lock, flags);
+	return page;
 }
 
 static void gmac_cleanup_rxq(struct net_device *netdev)
@@ -792,11 +803,12 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	struct gemini_ethernet *geth = port->geth;
 	struct gmac_rxdesc *rxd = port->rxq_ring;
-	static struct gmac_queue_page *gpage;
 	struct nontoe_qhdr __iomem *qhdr;
 	void __iomem *dma_reg;
 	void __iomem *ptr_reg;
+	unsigned int page_offs;
 	dma_addr_t mapping;
+	struct page *page;
 	union dma_rwptr rw;
 	unsigned int r, w;
 
@@ -823,14 +835,13 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
 		if (!mapping)
 			continue;
 
-		/* Freeq pointers are one page off */
-		gpage = gmac_get_queue_page(geth, port, mapping + PAGE_SIZE);
-		if (!gpage) {
+		page = geth_freeq_lookup(geth, mapping, &page_offs);
+		if (!page) {
 			dev_err(geth->dev, "could not find page\n");
 			continue;
 		}
 		/* Release the RX queue reference to the page */
-		put_page(gpage->page);
+		put_page(page);
 	}
 
 	dma_free_coherent(geth->dev, sizeof(*port->rxq_ring) << port->rxq_order,
@@ -844,6 +855,7 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	struct gmac_queue_page *gpage;
 	unsigned int fpp_order;
 	unsigned int frag_len;
+	dma_addr_t page_mapping;
 	dma_addr_t mapping;
 	struct page *page;
 	int i;
@@ -853,9 +865,17 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	if (!page)
 		return NULL;
 
-	mapping = dma_map_single(geth->dev, page_address(page),
-				 PAGE_SIZE, DMA_FROM_DEVICE);
-	if (dma_mapping_error(geth->dev, mapping)) {
+	page_mapping = dma_map_single(geth->dev, page_address(page),
+				      PAGE_SIZE, DMA_FROM_DEVICE);
+	if (dma_mapping_error(geth->dev, page_mapping)) {
+		put_page(page);
+		return NULL;
+	}
+	if (page_mapping > U32_MAX - (PAGE_SIZE - 1)) {
+		dev_err_ratelimited(geth->dev,
+				    "freeq DMA mapping exceeds 32 bits\n");
+		dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
+				 DMA_FROM_DEVICE);
 		put_page(page);
 		return NULL;
 	}
@@ -868,31 +888,25 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	 */
 	frag_len = 1 << geth->freeq_frag_order; /* Usually 2048 */
 	fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	gpage = &geth->freeq_pages[pn];
+	if (gpage->page)
+		put_page(gpage->page);
+
+	/* Then put our new mapping into the page table */
+	gpage->mapping = page_mapping;
+	gpage->page = page;
+
 	freeq_entry = geth->freeq_ring + (pn << fpp_order);
 	dev_dbg(geth->dev, "allocate page %d fragment length %d fragments per page %d, freeq entry %p\n",
-		 pn, frag_len, (1 << fpp_order), freeq_entry);
+		pn, frag_len, (1 << fpp_order), freeq_entry);
+	mapping = page_mapping;
 	for (i = (1 << fpp_order); i > 0; i--) {
 		freeq_entry->word2.buf_adr = mapping;
 		freeq_entry++;
 		mapping += frag_len;
 	}
-
-	/* If the freeq entry already has a page mapped, then unmap it. */
-	gpage = &geth->freeq_pages[pn];
-	if (gpage->page) {
-		mapping = geth->freeq_ring[pn << fpp_order].word2.buf_adr;
-		dma_unmap_single(geth->dev, mapping, frag_len, DMA_FROM_DEVICE);
-		/* This should be the last reference to the page so it gets
-		 * released
-		 */
-		put_page(gpage->page);
-	}
-
-	/* Then put our new mapping into the page table */
-	dev_dbg(geth->dev, "page %d, DMA addr: %08x, page %p\n",
-		pn, (unsigned int)mapping, page);
-	gpage->mapping = mapping;
-	gpage->page = page;
+	dev_dbg(geth->dev, "page %d, DMA addr: %pad, page %p\n",
+		pn, &page_mapping, page);
 
 	return page;
 }
@@ -963,7 +977,6 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth, bool refill)
 static int geth_setup_freeq(struct gemini_ethernet *geth)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
-	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	unsigned int len = 1 << geth->freeq_order;
 	unsigned int pages = len >> fpp_order;
 	union queue_threshold qt;
@@ -1015,12 +1028,11 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 err_freeq_alloc:
 	while (pn > 0) {
 		struct gmac_queue_page *gpage;
-		dma_addr_t mapping;
 
 		--pn;
-		mapping = geth->freeq_ring[pn << fpp_order].word2.buf_adr;
-		dma_unmap_single(geth->dev, mapping, frag_len, DMA_FROM_DEVICE);
 		gpage = &geth->freeq_pages[pn];
+		dma_unmap_single(geth->dev, gpage->mapping, PAGE_SIZE,
+				 DMA_FROM_DEVICE);
 		put_page(gpage->page);
 	}
 
@@ -1042,7 +1054,6 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
-	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	unsigned int len = 1 << geth->freeq_order;
 	unsigned int pages = len >> fpp_order;
 	unsigned int pn;
@@ -1056,12 +1067,10 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 
 	for (pn = 0; pn < pages; pn++) {
 		struct gmac_queue_page *gpage;
-		dma_addr_t mapping;
-
-		mapping = geth->freeq_ring[pn << fpp_order].word2.buf_adr;
-		dma_unmap_single(geth->dev, mapping, frag_len, DMA_FROM_DEVICE);
 
 		gpage = &geth->freeq_pages[pn];
+		dma_unmap_single(geth->dev, gpage->mapping, PAGE_SIZE,
+				 DMA_FROM_DEVICE);
 		while (page_ref_count(gpage->page) > 0)
 			put_page(gpage->page);
 	}
@@ -1519,7 +1528,6 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 	unsigned int consumed = 0;
 	unsigned int frame_len, frag_len;
 	struct gmac_rxdesc *rx = NULL;
-	struct gmac_queue_page *gpage;
 	unsigned int received = 0;
 	bool dropping = port->rx_dropping;
 	union gmac_rxdesc_0 word0;
@@ -1556,8 +1564,6 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 
 		frag_len = word0.bits.buffer_size;
 		frame_len = word1.bits.byte_count;
-		page_offs = mapping & ~PAGE_MASK;
-
 		if (word3.bits32 & SOF_BIT) {
 			if (skb) {
 				napi_free_frags(&port->napi);
@@ -1576,14 +1582,12 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			goto err_drop;
 		}
 
-		/* Freeq pointers are one page off */
-		gpage = gmac_get_queue_page(geth, port, mapping + PAGE_SIZE);
-		if (!gpage) {
+		page = geth_freeq_lookup(geth, mapping, &page_offs);
+		if (!page) {
 			dev_err_ratelimited(geth->dev,
 					    "could not find mapping\n");
 			goto err_drop;
 		}
-		page = gpage->page;
 
 		if (word3.bits32 & SOF_BIT) {
 			skb = gmac_skb_if_good_frame(port, word0, frame_len);

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 06/19] net: ethernet: cortina: Index free queue fragments with XArray
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (4 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 05/19] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-16 14:45   ` netdev-bot+sashiko
  2026-11-12 13:30 ` [PATCH net-next v8 07/19] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
                   ` (12 subsequent siblings)
  18 siblings, 1 reply; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

RX descriptors return the DMA address of the free queue fragment used by
the hardware. The driver currently recovers its page by scanning every
free queue page and comparing address ranges.

This isn't very efficient...

Instead index each fragment in an XArray using its DMA address in
fragment units.

Populate and erase the fragment index under the free queue lock. The
lookup remains serialized with refill and validates the exact fragment
address before returning the page and offset snapshot.

The per-fragment index is a prerequisite for the following
"Preserve in-flight free queue pages" fix, which keeps each mapping until
its RX descriptor is claimed. Include this patch when backporting that
fix and its subsequent recycling changes.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 105 ++++++++++++++++++++++++----------
 1 file changed, 76 insertions(+), 29 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index b96325f652bb..4ee630a9f589 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -38,6 +38,7 @@
 #include <linux/ethtool.h>
 #include <linux/tcp.h>
 #include <linux/u64_stats_sync.h>
+#include <linux/xarray.h>
 
 #include <linux/in.h>
 #include <linux/ip.h>
@@ -167,6 +168,7 @@ struct gemini_ethernet {
 	struct gmac_rxdesc *freeq_ring;
 	dma_addr_t	freeq_dma_base;
 	struct gmac_queue_page	*freeq_pages;
+	struct xarray	freeq_mappings;
 	unsigned int	num_freeq_pages;
 	spinlock_t	freeq_lock; /* Locks queue from reentrance */
 };
@@ -759,43 +761,47 @@ static int gmac_setup_rxq(struct net_device *netdev)
 	return 0;
 }
 
+static unsigned long
+geth_freeq_mapping_index(const struct gemini_ethernet *geth,
+			 dma_addr_t mapping)
+{
+	return (unsigned long)(mapping >> geth->freeq_frag_order);
+}
+
 static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
 				      dma_addr_t mapping,
 				      unsigned int *page_offs)
 {
 	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	struct gmac_queue_page *gpage;
+	unsigned long index;
 	unsigned long flags;
 	dma_addr_t page_mapping;
-	struct page *page = NULL;
-	int i;
-
-	spin_lock_irqsave(&geth->freeq_lock, flags);
-	if (!geth->freeq_pages) {
-		dev_err_ratelimited(geth->dev,
-				    "try to get page with no page list\n");
-		goto unlock;
-	}
-
-	/* Look up a ring buffer page from virtual mapping */
-	for (i = 0; i < geth->num_freeq_pages; i++) {
-		gpage = &geth->freeq_pages[i];
-		if (!gpage->page || mapping < gpage->mapping)
-			continue;
-
-		page_mapping = gpage->mapping;
-		if (mapping - page_mapping > PAGE_SIZE - frag_len ||
-		    ((mapping - page_mapping) & (frag_len - 1)))
-			continue;
+	struct page *page;
+	bool valid;
 
-		page = gpage->page;
-		*page_offs = mapping - page_mapping;
-		break;
-	}
+	index = geth_freeq_mapping_index(geth, mapping);
 
-unlock:
+	spin_lock_irqsave(&geth->freeq_lock, flags);
+	gpage = xa_load(&geth->freeq_mappings, index);
+	if (!gpage || !gpage->page)
+		goto err_unlock;
+
+	page = gpage->page;
+	page_mapping = gpage->mapping;
+	valid = mapping >= page_mapping &&
+		mapping - page_mapping <= PAGE_SIZE - frag_len &&
+		!((mapping - page_mapping) & (frag_len - 1));
+	if (!valid)
+		goto err_unlock;
+
+	*page_offs = mapping - page_mapping;
 	spin_unlock_irqrestore(&geth->freeq_lock, flags);
 	return page;
+
+err_unlock:
+	spin_unlock_irqrestore(&geth->freeq_lock, flags);
+	return NULL;
 }
 
 static void gmac_cleanup_rxq(struct net_device *netdev)
@@ -854,12 +860,16 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	struct gmac_rxdesc *freeq_entry;
 	struct gmac_queue_page *gpage;
 	unsigned int fpp_order;
+	unsigned int fragments;
 	unsigned int frag_len;
 	dma_addr_t page_mapping;
 	dma_addr_t mapping;
 	struct page *page;
+	int ret;
 	int i;
 
+	lockdep_assert_held(&geth->freeq_lock);
+
 	/* First allocate and DMA map a single page */
 	page = alloc_page(GFP_ATOMIC);
 	if (!page)
@@ -888,9 +898,26 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	 */
 	frag_len = 1 << geth->freeq_frag_order; /* Usually 2048 */
 	fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	fragments = 1 << fpp_order;
+
 	gpage = &geth->freeq_pages[pn];
-	if (gpage->page)
+	for (i = 0; i < fragments; i++) {
+		mapping = page_mapping + i * frag_len;
+		ret = xa_insert(&geth->freeq_mappings,
+				geth_freeq_mapping_index(geth, mapping),
+				gpage, GFP_ATOMIC);
+		if (ret)
+			goto err_mappings;
+	}
+
+	if (gpage->page) {
+		for (i = 0; i < fragments; i++) {
+			mapping = gpage->mapping + i * frag_len;
+			xa_erase(&geth->freeq_mappings,
+				 geth_freeq_mapping_index(geth, mapping));
+		}
 		put_page(gpage->page);
+	}
 
 	/* Then put our new mapping into the page table */
 	gpage->mapping = page_mapping;
@@ -909,6 +936,17 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 		pn, &page_mapping, page);
 
 	return page;
+
+err_mappings:
+	while (i--) {
+		mapping = page_mapping + i * frag_len;
+		xa_erase(&geth->freeq_mappings,
+			 geth_freeq_mapping_index(geth, mapping));
+	}
+	dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
+			 DMA_FROM_DEVICE);
+	put_page(page);
+	return NULL;
 }
 
 /**
@@ -981,6 +1019,8 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	unsigned int pages = len >> fpp_order;
 	union queue_threshold qt;
 	union dma_skb_size skbsz;
+	unsigned long flags;
+	struct page *page;
 	unsigned int filled;
 	unsigned int pn;
 	u16 rptr;
@@ -995,16 +1035,20 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 		goto err_freeq;
 	}
 
-	/* Allocate a mapping to page look-up index */
+	/* Allocate page metadata referenced by the mapping index */
 	geth->freeq_pages = kzalloc_objs(*geth->freeq_pages, pages);
 	if (!geth->freeq_pages)
 		goto err_freeq;
 	geth->num_freeq_pages = pages;
 
 	dev_info(geth->dev, "allocate %d pages for queue\n", pages);
-	for (pn = 0; pn < pages; pn++)
-		if (!geth_freeq_alloc_map_page(geth, pn))
+	for (pn = 0; pn < pages; pn++) {
+		spin_lock_irqsave(&geth->freeq_lock, flags);
+		page = geth_freeq_alloc_map_page(geth, pn);
+		spin_unlock_irqrestore(&geth->freeq_lock, flags);
+		if (!page)
 			goto err_freeq_alloc;
+	}
 
 	/* Match the software pointer to the retained hardware pointer. */
 	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
@@ -1035,6 +1079,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 				 DMA_FROM_DEVICE);
 		put_page(gpage->page);
 	}
+	xa_destroy(&geth->freeq_mappings);
 
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
@@ -1074,6 +1119,7 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 		while (page_ref_count(gpage->page) > 0)
 			put_page(gpage->page);
 	}
+	xa_destroy(&geth->freeq_mappings);
 
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
@@ -2818,6 +2864,7 @@ static int gemini_ethernet_probe(struct platform_device *pdev)
 
 	spin_lock_init(&geth->irq_lock);
 	spin_lock_init(&geth->freeq_lock);
+	xa_init(&geth->freeq_mappings);
 
 	/* Quiesce firmware state before child IRQ handlers are registered. */
 	gemini_ethernet_disable_irqs(geth);

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 07/19] net: ethernet: cortina: Preserve in-flight free queue pages
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (5 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 06/19] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-16 14:45   ` netdev-bot+sashiko
  2026-11-12 13:30 ` [PATCH net-next v8 08/19] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
                   ` (11 subsequent siblings)
  18 siblings, 1 reply; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The software free queue and the two per-port RX queues have independent
lifetimes. A free queue ring position becomes reusable once hardware has
taken its buffer address, but the resulting RX descriptor can remain
unprocessed for longer.

With the default 2K fragments, the sequence is:

1. Free queue entries 2n and 2n + 1 contain the first and second halves
   of page A.
2. Hardware consumes those entries and copies their DMA addresses into RX
   descriptors, potentially in the RX queues of different ports.
3. The free queue read pointer advances, making entries 2n and 2n + 1
   available for refill.
4. NAPI may not yet have processed the RX descriptors referring to page A,
   so their DMA-to-page association must remain valid.
5. Refilling the same free queue positions with page B must therefore not
   replace the metadata describing page A.

The driver currently indexes page metadata by free queue position. Step 5
therefore overwrites page A's association with page B. When NAPI later
processes an old descriptor containing page A's DMA address, the driver can
no longer find the mapping. This may explain long-standing reports of the
driver failing to find RX mappings.

This is not just caused by splitting a 4K page into two 2K
fragments: the metadata would also have to outlive its free queue
position with one full-page buffer per entry, but the 2K split makes
the lifetime more involved because the two halves of one page are
independently consumed and may be waiting in different port RX queues.
The page cannot be unmapped until both fragment references have been
claimed.

Keep free queue positions in descriptor units when posting pages. The
retained hardware pointer need not be aligned to the number of fragments
per page; rounding it down would place one fragment behind the hardware
read pointer and retain its mapping and reference until teardown. Wrap
individual descriptor entries instead.

Allocate page metadata slots independently of free queue positions and
track occupied slots with a bitmap. Keep each exact fragment DMA address in
the XArray until software claims its descriptor.

The pages use streaming DMA_FROM_DEVICE mappings. Synchronize each
fragment when claimed and unmap the page with DMA_ATTR_SKIP_CPU_SYNC after
both are claimed. This has no known visible effect on Gemini's FA526,
where CPU sync is currently a no-op, but follows the DMA API and avoids
resynchronizing a sibling on other implementations. During teardown,
synchronize only fragments still owned by hardware.

Give each posted fragment its own page reference. Queue and error cleanup
can then release precisely the outstanding hardware references without
dropping references held by delivered skbs.

Allocate and DMA-map each candidate page before taking the free queue
lock, then re-read the hardware pointers and publish one complete page at
a time. The old refill path reused pages by queue position and only
allocated replacements once the queued fill fell to 64 descriptors or
fewer. This change allocates replacements to fill the ring, but limits
each call to one usable ring's worth of fragments and a finite number of
iterations.
The iteration allowance covers the metadata slots and one ring of pages,
so later recycling retries remain bounded too, independently of hardware
progress.

The following "Recycle claimed free queue pages" patch restores recycling
independently of queue position. Backport both changes together with
their prerequisites, including "Index free queue fragments with XArray".

Size the metadata pool for the shared free queue and both registered RX
rings. Include that capacity in resize decisions and reuse the queue only
while the peer is running and the existing capacity is sufficient. Rebuild
with the peer down even if the geometry is unchanged, so taking both ports
down and reopening can reclaim fragments that never returned a usable RX
address. This does not reclaim unclaimed fragments while the peer runs.
Roll back rejected RX ring changes to prevent same-order ring growth from
exhausting page slots and let downsizing release surplus pages.

Reject queue geometries that cannot post one complete page before tearing
down the existing queue. Require the initial fill to populate every usable
queue entry. If mapping or metadata allocation stops the fill early,
rewind the hardware write pointer, release the partial population and fail
setup.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 380 +++++++++++++++++++++-------------
 1 file changed, 238 insertions(+), 142 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 4ee630a9f589..4b0c10d732ab 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -14,6 +14,7 @@
  * Gary Chen & Ch Hsu Storlink Semiconductor
  */
 #include <linux/kernel.h>
+#include <linux/bitmap.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/net.h>
@@ -21,6 +22,7 @@
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
+#include <linux/circ_buf.h>
 #include <linux/cache.h>
 #include <linux/interrupt.h>
 #include <linux/reset.h>
@@ -89,11 +91,13 @@ MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
 /**
  * struct gmac_queue_page - page buffer per-page info
  * @page: the page struct
- * @mapping: the dma address handle
+ * @mapping: DMA address of the first fragment
+ * @fragments: number of fragments not yet claimed from the hardware
  */
 struct gmac_queue_page {
 	struct page *page;
 	dma_addr_t mapping;
+	unsigned int fragments;
 };
 
 struct gmac_txq {
@@ -170,6 +174,7 @@ struct gemini_ethernet {
 	struct gmac_queue_page	*freeq_pages;
 	struct xarray	freeq_mappings;
 	unsigned int	num_freeq_pages;
+	unsigned long	*freeq_page_bitmap;
 	spinlock_t	freeq_lock; /* Locks queue from reentrance */
 };
 
@@ -768,15 +773,32 @@ geth_freeq_mapping_index(const struct gemini_ethernet *geth,
 	return (unsigned long)(mapping >> geth->freeq_frag_order);
 }
 
-static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
-				      dma_addr_t mapping,
-				      unsigned int *page_offs)
+static int geth_freeq_alloc_slot(struct gemini_ethernet *geth)
+{
+	unsigned int slot;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	slot = find_first_zero_bit(geth->freeq_page_bitmap,
+				   geth->num_freeq_pages);
+	if (slot == geth->num_freeq_pages)
+		return -ENOSPC;
+
+	__set_bit(slot, geth->freeq_page_bitmap);
+
+	return slot;
+}
+
+static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
+				     dma_addr_t mapping,
+				     unsigned int *page_offs)
 {
 	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	struct gmac_queue_page *gpage;
 	unsigned long index;
 	unsigned long flags;
 	dma_addr_t page_mapping;
+	unsigned int slot;
 	struct page *page;
 	bool valid;
 
@@ -784,7 +806,7 @@ static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
 
 	spin_lock_irqsave(&geth->freeq_lock, flags);
 	gpage = xa_load(&geth->freeq_mappings, index);
-	if (!gpage || !gpage->page)
+	if (!gpage || !gpage->page || !gpage->fragments)
 		goto err_unlock;
 
 	page = gpage->page;
@@ -795,6 +817,21 @@ static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
 	if (!valid)
 		goto err_unlock;
 
+	dma_sync_single_range_for_cpu(geth->dev, page_mapping,
+				      mapping - page_mapping, frag_len,
+				      DMA_FROM_DEVICE);
+	xa_erase(&geth->freeq_mappings, index);
+	if (!--gpage->fragments) {
+		slot = gpage - geth->freeq_pages;
+		dma_unmap_single_attrs(geth->dev, page_mapping, PAGE_SIZE,
+				       DMA_FROM_DEVICE,
+				       DMA_ATTR_SKIP_CPU_SYNC);
+		gpage->page = NULL;
+		gpage->mapping = 0;
+		__clear_bit(slot, geth->freeq_page_bitmap);
+		put_page(page);
+	}
+
 	*page_offs = mapping - page_mapping;
 	spin_unlock_irqrestore(&geth->freeq_lock, flags);
 	return page;
@@ -841,7 +878,7 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
 		if (!mapping)
 			continue;
 
-		page = geth_freeq_lookup(geth, mapping, &page_offs);
+		page = geth_freeq_claim(geth, mapping, &page_offs);
 		if (!page) {
 			dev_err(geth->dev, "could not find page\n");
 			continue;
@@ -854,32 +891,22 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
 			  port->rxq_ring, port->rxq_dma_base);
 }
 
-static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
-					      int pn)
+static int geth_freeq_map_page(struct gemini_ethernet *geth,
+			       struct page **pagep,
+			       dma_addr_t *page_mappingp)
 {
-	struct gmac_rxdesc *freeq_entry;
-	struct gmac_queue_page *gpage;
-	unsigned int fpp_order;
-	unsigned int fragments;
-	unsigned int frag_len;
 	dma_addr_t page_mapping;
-	dma_addr_t mapping;
 	struct page *page;
-	int ret;
-	int i;
 
-	lockdep_assert_held(&geth->freeq_lock);
-
-	/* First allocate and DMA map a single page */
 	page = alloc_page(GFP_ATOMIC);
 	if (!page)
-		return NULL;
+		return -ENOMEM;
 
 	page_mapping = dma_map_single(geth->dev, page_address(page),
 				      PAGE_SIZE, DMA_FROM_DEVICE);
 	if (dma_mapping_error(geth->dev, page_mapping)) {
 		put_page(page);
-		return NULL;
+		return -ENOMEM;
 	}
 	if (page_mapping > U32_MAX - (PAGE_SIZE - 1)) {
 		dev_err_ratelimited(geth->dev,
@@ -887,9 +914,35 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 		dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
 				 DMA_FROM_DEVICE);
 		put_page(page);
-		return NULL;
+		return -EOVERFLOW;
 	}
 
+	*pagep = page;
+	*page_mappingp = page_mapping;
+
+	return 0;
+}
+
+static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
+			       struct page *page, dma_addr_t page_mapping)
+{
+	struct gmac_rxdesc *freeq_entry;
+	struct gmac_queue_page *gpage;
+	unsigned int ring_mask;
+	unsigned int fpp_order;
+	unsigned int fragments;
+	unsigned int frag_len;
+	dma_addr_t mapping;
+	int ret;
+	int slot;
+	int i;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	slot = geth_freeq_alloc_slot(geth);
+	if (slot < 0)
+		return slot;
+
 	/* The assign the page mapping (physical address) to the buffer address
 	 * in the hardware queue. PAGE_SHIFT on ARM is 12 (1 page is 4096 bytes,
 	 * 4k), and the default RX frag order is 11 (fragments are up 20 2048
@@ -899,8 +952,11 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	frag_len = 1 << geth->freeq_frag_order; /* Usually 2048 */
 	fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
 	fragments = 1 << fpp_order;
+	ring_mask = (1 << geth->freeq_order) - 1;
 
-	gpage = &geth->freeq_pages[pn];
+	gpage = &geth->freeq_pages[slot];
+	gpage->page = page;
+	gpage->mapping = page_mapping;
 	for (i = 0; i < fragments; i++) {
 		mapping = page_mapping + i * frag_len;
 		ret = xa_insert(&geth->freeq_mappings,
@@ -909,33 +965,22 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 		if (ret)
 			goto err_mappings;
 	}
+	gpage->fragments = fragments;
+	page_ref_add(page, fragments);
 
-	if (gpage->page) {
-		for (i = 0; i < fragments; i++) {
-			mapping = gpage->mapping + i * frag_len;
-			xa_erase(&geth->freeq_mappings,
-				 geth_freeq_mapping_index(geth, mapping));
-		}
-		put_page(gpage->page);
-	}
-
-	/* Then put our new mapping into the page table */
-	gpage->mapping = page_mapping;
-	gpage->page = page;
-
-	freeq_entry = geth->freeq_ring + (pn << fpp_order);
-	dev_dbg(geth->dev, "allocate page %d fragment length %d fragments per page %d, freeq entry %p\n",
-		pn, frag_len, (1 << fpp_order), freeq_entry);
+	dev_dbg(geth->dev,
+		"post page at entry %u fragment length %u fragments per page %u\n",
+		wptr, frag_len, fragments);
 	mapping = page_mapping;
-	for (i = (1 << fpp_order); i > 0; i--) {
+	for (i = 0; i < fragments; i++) {
+		freeq_entry = geth->freeq_ring + ((wptr + i) & ring_mask);
 		freeq_entry->word2.buf_adr = mapping;
-		freeq_entry++;
 		mapping += frag_len;
 	}
-	dev_dbg(geth->dev, "page %d, DMA addr: %pad, page %p\n",
-		pn, &page_mapping, page);
+	dev_dbg(geth->dev, "DMA addr: %pad, page %p\n",
+		&page_mapping, page);
 
-	return page;
+	return 0;
 
 err_mappings:
 	while (i--) {
@@ -943,88 +988,147 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 		xa_erase(&geth->freeq_mappings,
 			 geth_freeq_mapping_index(geth, mapping));
 	}
-	dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
-			 DMA_FROM_DEVICE);
-	put_page(page);
-	return NULL;
+	gpage->page = NULL;
+	gpage->mapping = 0;
+	__clear_bit(slot, geth->freeq_page_bitmap);
+	return ret;
 }
 
 /**
  * geth_fill_freeq() - Fill the freeq with empty fragments to use
  * @geth: the ethernet adapter
- * @refill: whether to reset the queue by filling in all freeq entries or
- * just refill it, usually the interrupt to refill the queue happens when
- * the queue is half empty.
+ *
+ * Usually the interrupt to refill the queue happens when the queue is half
+ * empty.
  */
-static unsigned int geth_fill_freeq(struct gemini_ethernet *geth, bool refill)
+static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	unsigned int fragments = 1 << fpp_order;
+	unsigned int len = 1 << geth->freeq_order;
+	unsigned int ring_mask = len - 1;
+	unsigned int remaining = geth->num_freeq_pages + (len >> fpp_order);
 	unsigned int count = 0;
-	unsigned int pn, epn;
+	unsigned int rptr, wptr;
 	unsigned long flags;
 	union dma_rwptr rw;
-	unsigned int m_pn;
+	bool space;
 
-	/* Mask for page */
-	m_pn = (1 << (geth->freeq_order - fpp_order)) - 1;
+	/* Bound retries and post at most one ring's worth of fragments. */
+	while (remaining-- && count < len - fragments) {
+		dma_addr_t page_mapping;
+		struct page *page;
+		int ret;
 
-	spin_lock_irqsave(&geth->freeq_lock, flags);
+		spin_lock_irqsave(&geth->freeq_lock, flags);
+		rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
+		rptr = rw.bits.rptr & ring_mask;
+		wptr = rw.bits.wptr & ring_mask;
+		space = CIRC_SPACE(wptr, rptr, len) >= fragments;
+		spin_unlock_irqrestore(&geth->freeq_lock, flags);
+		if (!space)
+			break;
+
+		ret = geth_freeq_map_page(geth, &page, &page_mapping);
+		if (ret)
+			break;
+
+		spin_lock_irqsave(&geth->freeq_lock, flags);
+
+		rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
+		rptr = rw.bits.rptr & ring_mask;
+		wptr = rw.bits.wptr & ring_mask;
+		if (CIRC_SPACE(wptr, rptr, len) < fragments) {
+			ret = -ENOSPC;
+		} else {
+			ret = geth_freeq_add_page(geth, wptr, page,
+						  page_mapping);
+			if (!ret) {
+				count += fragments;
+				wptr = (wptr + fragments) & ring_mask;
+				SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, wptr);
+			}
+		}
+
+		spin_unlock_irqrestore(&geth->freeq_lock, flags);
+
+		if (ret) {
+			dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
+					 DMA_FROM_DEVICE);
+			put_page(page);
+			break;
+		}
+	}
 
-	rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
-	pn = (refill ? rw.bits.wptr : rw.bits.rptr) >> fpp_order;
-	pn &= m_pn;
-	epn = (rw.bits.rptr >> fpp_order) - 1;
-	epn &= m_pn;
+	return count;
+}
 
-	/* Loop over the freeq ring buffer entries */
-	while (pn != epn) {
+static void geth_freeq_release_pages(struct gemini_ethernet *geth)
+{
+	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	unsigned int frag_len = 1 << geth->freeq_frag_order;
+	unsigned int pn;
+
+	for (pn = 0; pn < geth->num_freeq_pages; pn++) {
 		struct gmac_queue_page *gpage;
+		dma_addr_t mapping;
 		struct page *page;
+		unsigned int i;
 
 		gpage = &geth->freeq_pages[pn];
-		page = gpage->page;
-
-		dev_dbg(geth->dev, "fill entry %d page ref count %d add %d refs\n",
-			pn, page_ref_count(page), 1 << fpp_order);
-
-		if (page_ref_count(page) > 1) {
-			unsigned int fl = (pn - epn) & m_pn;
+		if (!gpage->page)
+			continue;
 
-			if (fl > 64 >> fpp_order)
-				break;
+		page = gpage->page;
+		for (i = 0; i < (1 << fpp_order); i++) {
+			mapping = gpage->mapping + i * frag_len;
+			if (xa_load(&geth->freeq_mappings,
+				    geth_freeq_mapping_index(geth, mapping)) != gpage)
+				continue;
 
-			page = geth_freeq_alloc_map_page(geth, pn);
-			if (!page)
-				break;
+			dma_sync_single_range_for_cpu(geth->dev, gpage->mapping,
+						      i * frag_len, frag_len,
+						      DMA_FROM_DEVICE);
 		}
-
-		/* Add one reference per fragment in the page */
-		page_ref_add(page, 1 << fpp_order);
-		count += 1 << fpp_order;
-		pn++;
-		pn &= m_pn;
+		dma_unmap_single_attrs(geth->dev, gpage->mapping, PAGE_SIZE,
+				       DMA_FROM_DEVICE,
+				       DMA_ATTR_SKIP_CPU_SYNC);
+		while (gpage->fragments) {
+			put_page(page);
+			gpage->fragments--;
+		}
+		put_page(page);
 	}
+	xa_destroy(&geth->freeq_mappings);
+}
 
-	writew(pn << fpp_order, geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
+static unsigned int
+geth_freeq_page_slots(struct gemini_ethernet *geth, unsigned int order)
+{
+	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	unsigned int slots = 1 << (order - fpp_order);
 
-	spin_unlock_irqrestore(&geth->freeq_lock, flags);
+	if (geth->port0 && geth->port0->netdev)
+		slots += 1 << geth->port0->rxq_order;
+	if (geth->port1 && geth->port1->netdev)
+		slots += 1 << geth->port1->rxq_order;
 
-	return count;
+	return slots;
 }
 
 static int geth_setup_freeq(struct gemini_ethernet *geth)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
 	unsigned int len = 1 << geth->freeq_order;
-	unsigned int pages = len >> fpp_order;
+	unsigned int page_slots;
+	unsigned int expected;
 	union queue_threshold qt;
 	union dma_skb_size skbsz;
-	unsigned long flags;
-	struct page *page;
 	unsigned int filled;
-	unsigned int pn;
 	u16 rptr;
 
+	page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
+
 	geth->freeq_ring = dma_alloc_coherent(geth->dev,
 		sizeof(*geth->freeq_ring) << geth->freeq_order,
 		&geth->freeq_dma_base, GFP_KERNEL);
@@ -1036,27 +1140,22 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	}
 
 	/* Allocate page metadata referenced by the mapping index */
-	geth->freeq_pages = kzalloc_objs(*geth->freeq_pages, pages);
+	geth->freeq_pages = kzalloc_objs(*geth->freeq_pages, page_slots);
 	if (!geth->freeq_pages)
 		goto err_freeq;
-	geth->num_freeq_pages = pages;
-
-	dev_info(geth->dev, "allocate %d pages for queue\n", pages);
-	for (pn = 0; pn < pages; pn++) {
-		spin_lock_irqsave(&geth->freeq_lock, flags);
-		page = geth_freeq_alloc_map_page(geth, pn);
-		spin_unlock_irqrestore(&geth->freeq_lock, flags);
-		if (!page)
-			goto err_freeq_alloc;
-	}
+	geth->freeq_page_bitmap = bitmap_zalloc(page_slots, GFP_KERNEL);
+	if (!geth->freeq_page_bitmap)
+		goto err_freeq_pages;
+	geth->num_freeq_pages = page_slots;
 
 	/* Match the software pointer to the retained hardware pointer. */
 	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 	SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, rptr & (len - 1));
 
-	filled = geth_fill_freeq(geth, false);
-	if (!filled)
-		goto err_freeq_alloc;
+	expected = len - (1 << fpp_order);
+	filled = geth_fill_freeq(geth);
+	if (filled != expected)
+		goto err_freeq_bitmap;
 
 	qt.bits32 = readl(geth->base + GLOBAL_QUEUE_THRESHOLD_REG);
 	qt.bits.swfq_empty = 32;
@@ -1069,18 +1168,13 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 
 	return 0;
 
-err_freeq_alloc:
-	while (pn > 0) {
-		struct gmac_queue_page *gpage;
-
-		--pn;
-		gpage = &geth->freeq_pages[pn];
-		dma_unmap_single(geth->dev, gpage->mapping, PAGE_SIZE,
-				 DMA_FROM_DEVICE);
-		put_page(gpage->page);
-	}
-	xa_destroy(&geth->freeq_mappings);
-
+err_freeq_bitmap:
+	writew(readw(geth->base + GLOBAL_SWFQ_RWPTR_REG),
+	       geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
+	geth_freeq_release_pages(geth);
+	bitmap_free(geth->freeq_page_bitmap);
+	geth->freeq_page_bitmap = NULL;
+err_freeq_pages:
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
 	geth->num_freeq_pages = 0;
@@ -1098,11 +1192,6 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
  */
 static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 {
-	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
-	unsigned int len = 1 << geth->freeq_order;
-	unsigned int pages = len >> fpp_order;
-	unsigned int pn;
-
 	if (!geth->freeq_ring)
 		return;
 
@@ -1110,17 +1199,10 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 	       geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
 	writel(0, geth->base + GLOBAL_SW_FREEQ_BASE_SIZE_REG);
 
-	for (pn = 0; pn < pages; pn++) {
-		struct gmac_queue_page *gpage;
-
-		gpage = &geth->freeq_pages[pn];
-		dma_unmap_single(geth->dev, gpage->mapping, PAGE_SIZE,
-				 DMA_FROM_DEVICE);
-		while (page_ref_count(gpage->page) > 0)
-			put_page(gpage->page);
-	}
-	xa_destroy(&geth->freeq_mappings);
+	geth_freeq_release_pages(geth);
 
+	bitmap_free(geth->freeq_page_bitmap);
+	geth->freeq_page_bitmap = NULL;
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
 	geth->num_freeq_pages = 0;
@@ -1160,7 +1242,9 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	struct net_device *netdev = port->netdev;
 	struct gemini_ethernet_port *other_port;
 	struct net_device *other_netdev;
+	bool other_running;
 	unsigned int new_size = 0;
+	unsigned int page_slots;
 	unsigned int new_order;
 	u16 rptr;
 	int ret;
@@ -1176,9 +1260,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	else
 		other_port = geth->port0;
 	other_netdev = other_port ? other_port->netdev : NULL;
-
-	if (other_netdev && netif_running(other_netdev))
-		return -EBUSY;
+	other_running = other_netdev && netif_running(other_netdev);
 
 	new_size = 1 << (port->rxq_order + 1);
 	netdev_dbg(netdev, "port %d size: %d order %d\n",
@@ -1200,8 +1282,19 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	new_order = max_t(unsigned int, new_order, fls(rptr));
 	dev_dbg(geth->dev, "set shared queue to size %d order %d\n",
 		new_size, new_order);
-	if (geth->freeq_ring && geth->freeq_order == new_order)
-		return 0;
+	if (new_order <= PAGE_SHIFT - geth->freeq_frag_order)
+		return -EINVAL;
+
+	/* Rebuild an idle queue to reclaim fragments which were never claimed. */
+	if (geth->freeq_ring && other_running) {
+		page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
+		if (geth->freeq_order >= new_order &&
+		    geth->num_freeq_pages >= page_slots)
+			return 0;
+	}
+
+	if (other_running)
+		return -EBUSY;
 
 	disable_irq(geth->port1->irq);
 	geth_set_freeq_irq(geth, false);
@@ -1628,7 +1721,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			goto err_drop;
 		}
 
-		page = geth_freeq_lookup(geth, mapping, &page_offs);
+		page = geth_freeq_claim(geth, mapping, &page_offs);
 		if (!page) {
 			dev_err_ratelimited(geth->dev,
 					    "could not find mapping\n");
@@ -1725,7 +1818,7 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)
 	port->freeq_refill += freeq_consumed;
 	if (port->freeq_refill > freeq_threshold) {
 		port->freeq_refill -= freeq_threshold;
-		geth_fill_freeq(geth, true);
+		geth_fill_freeq(geth);
 	}
 
 	if (!reschedule && received < budget &&
@@ -1980,10 +2073,7 @@ static int gmac_open(struct net_device *netdev)
 	phy_start(netdev->phydev);
 
 	err = geth_resize_freeq(port);
-	/* It's fine if it's just busy, the other port has set up
-	 * the freeq in that case.
-	 */
-	if (err && (err != -EBUSY)) {
+	if (err) {
 		netdev_err(netdev, "could not resize freeq\n");
 		goto err_stop_phy;
 	}
@@ -2342,14 +2432,20 @@ static int gmac_set_ringparam(struct net_device *netdev,
 			      struct netlink_ext_ack *extack)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
+	unsigned int old_rxq_order;
 	int err = 0;
 
 	if (netif_running(netdev))
 		return -EBUSY;
 
 	if (rp->rx_pending) {
+		old_rxq_order = port->rxq_order;
 		port->rxq_order = min(15, ilog2(rp->rx_pending - 1) + 1);
 		err = geth_resize_freeq(port);
+		if (err) {
+			port->rxq_order = old_rxq_order;
+			return err;
+		}
 	}
 	if (rp->tx_pending) {
 		port->txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
@@ -2455,7 +2551,7 @@ static irqreturn_t gemini_port_irq_thread(int irq, void *data)
 
 	geth = port->geth;
 	/* The queue is half empty so refill it */
-	geth_fill_freeq(geth, true);
+	geth_fill_freeq(geth);
 
 	spin_lock_irqsave(&geth->irq_lock, flags);
 	/* ACK queue interrupt */

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 08/19] net: ethernet: cortina: Rotate free queue page allocation
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (6 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 07/19] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 09/19] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The free queue metadata bitmap currently searches for a free slot from
zero for every page allocation. Under sustained traffic this repeatedly
scans occupied low-numbered slots.

Remember the position after the most recently allocated slot and wrap the
bitmap search at its end. Reset the cursor when the bitmap is released so
the two remain consistent across failed setup and teardown. This keeps
allocation cost distributed across the metadata table.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 4b0c10d732ab..64c8c7e463f2 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -175,6 +175,7 @@ struct gemini_ethernet {
 	struct xarray	freeq_mappings;
 	unsigned int	num_freeq_pages;
 	unsigned long	*freeq_page_bitmap;
+	unsigned int	freeq_page_cursor;
 	spinlock_t	freeq_lock; /* Locks queue from reentrance */
 };
 
@@ -779,12 +780,20 @@ static int geth_freeq_alloc_slot(struct gemini_ethernet *geth)
 
 	lockdep_assert_held(&geth->freeq_lock);
 
-	slot = find_first_zero_bit(geth->freeq_page_bitmap,
-				   geth->num_freeq_pages);
-	if (slot == geth->num_freeq_pages)
-		return -ENOSPC;
+	slot = find_next_zero_bit(geth->freeq_page_bitmap,
+				  geth->num_freeq_pages,
+				  geth->freeq_page_cursor);
+	if (slot == geth->num_freeq_pages) {
+		slot = find_first_zero_bit(geth->freeq_page_bitmap,
+					   geth->freeq_page_cursor);
+		if (slot == geth->freeq_page_cursor)
+			return -ENOSPC;
+	}
 
 	__set_bit(slot, geth->freeq_page_bitmap);
+	geth->freeq_page_cursor = slot + 1;
+	if (geth->freeq_page_cursor == geth->num_freeq_pages)
+		geth->freeq_page_cursor = 0;
 
 	return slot;
 }
@@ -1147,6 +1156,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	if (!geth->freeq_page_bitmap)
 		goto err_freeq_pages;
 	geth->num_freeq_pages = page_slots;
+	geth->freeq_page_cursor = 0;
 
 	/* Match the software pointer to the retained hardware pointer. */
 	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
@@ -1178,6 +1188,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
 	geth->num_freeq_pages = 0;
+	geth->freeq_page_cursor = 0;
 err_freeq:
 	dma_free_coherent(geth->dev,
 			  sizeof(*geth->freeq_ring) << geth->freeq_order,
@@ -1206,6 +1217,7 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
 	geth->num_freeq_pages = 0;
+	geth->freeq_page_cursor = 0;
 
 	dma_free_coherent(geth->dev,
 			  sizeof(*geth->freeq_ring) << geth->freeq_order,

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 09/19] net: ethernet: cortina: Recycle claimed free queue pages
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (7 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 08/19] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 10/19] net: ethernet: cortina: Separate RX buffer capacity from free queue size Linus Walleij
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The preceding "Preserve in-flight free queue pages" fix releases each
mapping after its last descriptor is claimed. Refilling therefore
allocates and maps a fresh page at line rate even after the network stack
has released all references to an old page.

Keep the free queue base reference and streaming mapping after the
fragments are claimed. Track fully claimed slots in a separate bitmap and
inspect one at a time during refill. Recycle a page once its reference
count returns to one. If the stack still owns fragments, unmap the page
and relinquish the base reference before allocating its replacement.

Reject pfmemalloc pages when recycling so emergency-reserve pages return
to the allocator instead of remaining pinned in the free queue.

This prevents retained pages from exhausting the finite metadata table
and bounds the IRQ-disabled search to a bitmap lookup and one reference
count check. It retains the existing free queue allocator without
introducing a page pool.

Recheck the recycle bitmap on each refill iteration and again after mapping
a candidate page. If another RX path retires a page concurrently, release
the candidate and return to the recycler before consuming another metadata
slot. Retry recycling immediately when a retained page is discarded so
other pending entries are examined before allocating a replacement. This
avoids stopping refill while recyclable slots are pending.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 153 +++++++++++++++++++++++++++++-----
 1 file changed, 131 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 64c8c7e463f2..aedd8eca3f15 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -175,7 +175,9 @@ struct gemini_ethernet {
 	struct xarray	freeq_mappings;
 	unsigned int	num_freeq_pages;
 	unsigned long	*freeq_page_bitmap;
+	unsigned long	*freeq_recycle_bitmap;
 	unsigned int	freeq_page_cursor;
+	unsigned int	freeq_recycle_pending;
 	spinlock_t	freeq_lock; /* Locks queue from reentrance */
 };
 
@@ -798,6 +800,34 @@ static int geth_freeq_alloc_slot(struct gemini_ethernet *geth)
 	return slot;
 }
 
+static int geth_freeq_recycle_slot(struct gemini_ethernet *geth)
+{
+	unsigned int slot = geth->freeq_page_cursor;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	if (!geth->freeq_recycle_pending)
+		return -ENOSPC;
+
+	slot = find_next_bit(geth->freeq_recycle_bitmap,
+			     geth->num_freeq_pages,
+			     geth->freeq_page_cursor);
+	if (slot == geth->num_freeq_pages) {
+		slot = find_first_bit(geth->freeq_recycle_bitmap,
+				      geth->freeq_page_cursor);
+		if (slot == geth->freeq_page_cursor)
+			return -ENOSPC;
+	}
+
+	__clear_bit(slot, geth->freeq_recycle_bitmap);
+	geth->freeq_page_cursor = slot + 1;
+	if (geth->freeq_page_cursor == geth->num_freeq_pages)
+		geth->freeq_page_cursor = 0;
+	geth->freeq_recycle_pending--;
+
+	return slot;
+}
+
 static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
 				     dma_addr_t mapping,
 				     unsigned int *page_offs)
@@ -807,8 +837,8 @@ static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
 	unsigned long index;
 	unsigned long flags;
 	dma_addr_t page_mapping;
-	unsigned int slot;
 	struct page *page;
+	unsigned int slot;
 	bool valid;
 
 	index = geth_freeq_mapping_index(geth, mapping);
@@ -832,13 +862,8 @@ static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
 	xa_erase(&geth->freeq_mappings, index);
 	if (!--gpage->fragments) {
 		slot = gpage - geth->freeq_pages;
-		dma_unmap_single_attrs(geth->dev, page_mapping, PAGE_SIZE,
-				       DMA_FROM_DEVICE,
-				       DMA_ATTR_SKIP_CPU_SYNC);
-		gpage->page = NULL;
-		gpage->mapping = 0;
-		__clear_bit(slot, geth->freeq_page_bitmap);
-		put_page(page);
+		__set_bit(slot, geth->freeq_recycle_bitmap);
+		geth->freeq_recycle_pending++;
 	}
 
 	*page_offs = mapping - page_mapping;
@@ -932,26 +957,23 @@ static int geth_freeq_map_page(struct gemini_ethernet *geth,
 	return 0;
 }
 
-static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
-			       struct page *page, dma_addr_t page_mapping)
+static int geth_freeq_post_page(struct gemini_ethernet *geth,
+				unsigned int wptr,
+				struct gmac_queue_page *gpage, bool recycle)
 {
 	struct gmac_rxdesc *freeq_entry;
-	struct gmac_queue_page *gpage;
 	unsigned int ring_mask;
 	unsigned int fpp_order;
 	unsigned int fragments;
 	unsigned int frag_len;
+	dma_addr_t page_mapping = gpage->mapping;
 	dma_addr_t mapping;
+	struct page *page = gpage->page;
 	int ret;
-	int slot;
 	int i;
 
 	lockdep_assert_held(&geth->freeq_lock);
 
-	slot = geth_freeq_alloc_slot(geth);
-	if (slot < 0)
-		return slot;
-
 	/* The assign the page mapping (physical address) to the buffer address
 	 * in the hardware queue. PAGE_SHIFT on ARM is 12 (1 page is 4096 bytes,
 	 * 4k), and the default RX frag order is 11 (fragments are up 20 2048
@@ -963,9 +985,6 @@ static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
 	fragments = 1 << fpp_order;
 	ring_mask = (1 << geth->freeq_order) - 1;
 
-	gpage = &geth->freeq_pages[slot];
-	gpage->page = page;
-	gpage->mapping = page_mapping;
 	for (i = 0; i < fragments; i++) {
 		mapping = page_mapping + i * frag_len;
 		ret = xa_insert(&geth->freeq_mappings,
@@ -974,6 +993,9 @@ static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
 		if (ret)
 			goto err_mappings;
 	}
+	if (recycle)
+		dma_sync_single_for_device(geth->dev, page_mapping, PAGE_SIZE,
+					   DMA_FROM_DEVICE);
 	gpage->fragments = fragments;
 	page_ref_add(page, fragments);
 
@@ -997,9 +1019,70 @@ static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
 		xa_erase(&geth->freeq_mappings,
 			 geth_freeq_mapping_index(geth, mapping));
 	}
-	gpage->page = NULL;
-	gpage->mapping = 0;
-	__clear_bit(slot, geth->freeq_page_bitmap);
+	return ret;
+}
+
+static int geth_freeq_add_page(struct gemini_ethernet *geth,
+			       unsigned int wptr,
+			       struct page *page, dma_addr_t page_mapping)
+{
+	struct gmac_queue_page *gpage;
+	int ret;
+	int slot;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	slot = geth_freeq_alloc_slot(geth);
+	if (slot < 0)
+		return slot;
+
+	gpage = &geth->freeq_pages[slot];
+	gpage->page = page;
+	gpage->mapping = page_mapping;
+	ret = geth_freeq_post_page(geth, wptr, gpage, false);
+	if (ret) {
+		gpage->page = NULL;
+		gpage->mapping = 0;
+		__clear_bit(slot, geth->freeq_page_bitmap);
+	}
+
+	return ret;
+}
+
+static int geth_freeq_recycle_page(struct gemini_ethernet *geth,
+				   unsigned int wptr)
+{
+	struct gmac_queue_page *gpage;
+	struct page *page;
+	int ret;
+	int slot;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	slot = geth_freeq_recycle_slot(geth);
+	if (slot < 0)
+		return slot;
+
+	gpage = &geth->freeq_pages[slot];
+	if (page_ref_count(gpage->page) > 1 ||
+	    !dev_page_is_reusable(gpage->page)) {
+		page = gpage->page;
+		dma_unmap_single_attrs(geth->dev, gpage->mapping, PAGE_SIZE,
+				       DMA_FROM_DEVICE,
+				       DMA_ATTR_SKIP_CPU_SYNC);
+		gpage->page = NULL;
+		gpage->mapping = 0;
+		__clear_bit(slot, geth->freeq_page_bitmap);
+		put_page(page);
+		return -EAGAIN;
+	}
+
+	ret = geth_freeq_post_page(geth, wptr, gpage, true);
+	if (ret) {
+		__set_bit(slot, geth->freeq_recycle_bitmap);
+		geth->freeq_recycle_pending++;
+	}
+
 	return ret;
 }
 
@@ -1034,9 +1117,22 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 		rptr = rw.bits.rptr & ring_mask;
 		wptr = rw.bits.wptr & ring_mask;
 		space = CIRC_SPACE(wptr, rptr, len) >= fragments;
+		ret = -ENOSPC;
+		if (space && geth->freeq_recycle_pending) {
+			ret = geth_freeq_recycle_page(geth, wptr);
+			if (!ret) {
+				count += fragments;
+				wptr = (wptr + fragments) & ring_mask;
+				SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, wptr);
+			}
+		}
 		spin_unlock_irqrestore(&geth->freeq_lock, flags);
 		if (!space)
 			break;
+		if (!ret || ret == -EAGAIN)
+			continue;
+		if (ret != -ENOSPC)
+			break;
 
 		ret = geth_freeq_map_page(geth, &page, &page_mapping);
 		if (ret)
@@ -1049,6 +1145,8 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 		wptr = rw.bits.wptr & ring_mask;
 		if (CIRC_SPACE(wptr, rptr, len) < fragments) {
 			ret = -ENOSPC;
+		} else if (geth->freeq_recycle_pending) {
+			ret = -EAGAIN;
 		} else {
 			ret = geth_freeq_add_page(geth, wptr, page,
 						  page_mapping);
@@ -1065,6 +1163,8 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 			dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
 					 DMA_FROM_DEVICE);
 			put_page(page);
+			if (ret == -EAGAIN)
+				continue;
 			break;
 		}
 	}
@@ -1109,6 +1209,7 @@ static void geth_freeq_release_pages(struct gemini_ethernet *geth)
 		put_page(page);
 	}
 	xa_destroy(&geth->freeq_mappings);
+	geth->freeq_recycle_pending = 0;
 }
 
 static unsigned int
@@ -1155,6 +1256,9 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	geth->freeq_page_bitmap = bitmap_zalloc(page_slots, GFP_KERNEL);
 	if (!geth->freeq_page_bitmap)
 		goto err_freeq_pages;
+	geth->freeq_recycle_bitmap = bitmap_zalloc(page_slots, GFP_KERNEL);
+	if (!geth->freeq_recycle_bitmap)
+		goto err_freeq_page_bitmap;
 	geth->num_freeq_pages = page_slots;
 	geth->freeq_page_cursor = 0;
 
@@ -1182,6 +1286,9 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	writew(readw(geth->base + GLOBAL_SWFQ_RWPTR_REG),
 	       geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
 	geth_freeq_release_pages(geth);
+	bitmap_free(geth->freeq_recycle_bitmap);
+	geth->freeq_recycle_bitmap = NULL;
+err_freeq_page_bitmap:
 	bitmap_free(geth->freeq_page_bitmap);
 	geth->freeq_page_bitmap = NULL;
 err_freeq_pages:
@@ -1212,6 +1319,8 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 
 	geth_freeq_release_pages(geth);
 
+	bitmap_free(geth->freeq_recycle_bitmap);
+	geth->freeq_recycle_bitmap = NULL;
 	bitmap_free(geth->freeq_page_bitmap);
 	geth->freeq_page_bitmap = NULL;
 	kfree(geth->freeq_pages);

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 10/19] net: ethernet: cortina: Separate RX buffer capacity from free queue size
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (8 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 09/19] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-16 14:45   ` netdev-bot+sashiko
  2026-11-12 13:30 ` [PATCH net-next v8 11/19] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
                   ` (8 subsequent siblings)
  18 siblings, 1 reply; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

Containing a retained hardware read pointer can force an order-15 free
queue even when the configured RX rings need far fewer buffers. Filling
that descriptor ring requires nearly 64 MiB of pages on systems with
32 to 128 MiB of RAM. Allocation failure persists across retries because
the stopped DMA engine cannot advance the pointer.

Keep the descriptor geometry required by the retained pointer, but size
the RX buffer budget from the configured port rings. Bound the posted
occupancy and refill work by that budget, including after dropping the
free queue lock to allocate a page. Size page metadata and the NAPI refill
threshold from the same budget.

For a retained pointer of 16384 and a requested buffer order of 10, this
keeps the 512 KiB descriptor ring but posts 2044 KiB of RX pages instead
of 65532 KiB. No hardware pointer-reset behaviour is assumed.

Found by review and checked with a ring-geometry model covering every
supported retained pointer and buffer order.

Fixes: 0bf8c8c94af2 ("net: ethernet: cortina: Normalize free queue pointers on rebuild")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 40 ++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index aedd8eca3f15..72d2c002f8fc 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -168,6 +168,7 @@ struct gemini_ethernet {
 
 	spinlock_t	irq_lock; /* Locks IRQ-related registers */
 	unsigned int	freeq_order;
+	unsigned int	freeq_buf_order; /* RX buffer budget, independent of ring size */
 	unsigned int	freeq_frag_order;
 	struct gmac_rxdesc *freeq_ring;
 	dma_addr_t	freeq_dma_base;
@@ -1099,15 +1100,17 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 	unsigned int fragments = 1 << fpp_order;
 	unsigned int len = 1 << geth->freeq_order;
 	unsigned int ring_mask = len - 1;
-	unsigned int remaining = geth->num_freeq_pages + (len >> fpp_order);
+	unsigned int buf_len = 1 << geth->freeq_buf_order;
+	unsigned int capacity = buf_len - fragments;
+	unsigned int remaining = geth->num_freeq_pages + (buf_len >> fpp_order);
 	unsigned int count = 0;
 	unsigned int rptr, wptr;
 	unsigned long flags;
 	union dma_rwptr rw;
 	bool space;
 
-	/* Bound retries and post at most one ring's worth of fragments. */
-	while (remaining-- && count < len - fragments) {
+	/* Bound retries and post at most one buffer budget per refill. */
+	while (remaining-- && count < capacity) {
 		dma_addr_t page_mapping;
 		struct page *page;
 		int ret;
@@ -1116,7 +1119,8 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 		rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 		rptr = rw.bits.rptr & ring_mask;
 		wptr = rw.bits.wptr & ring_mask;
-		space = CIRC_SPACE(wptr, rptr, len) >= fragments;
+		space = CIRC_SPACE(wptr, rptr, len) >= fragments &&
+			CIRC_CNT(wptr, rptr, len) <= capacity - fragments;
 		ret = -ENOSPC;
 		if (space && geth->freeq_recycle_pending) {
 			ret = geth_freeq_recycle_page(geth, wptr);
@@ -1143,7 +1147,8 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 		rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 		rptr = rw.bits.rptr & ring_mask;
 		wptr = rw.bits.wptr & ring_mask;
-		if (CIRC_SPACE(wptr, rptr, len) < fragments) {
+		if (CIRC_SPACE(wptr, rptr, len) < fragments ||
+		    CIRC_CNT(wptr, rptr, len) > capacity - fragments) {
 			ret = -ENOSPC;
 		} else if (geth->freeq_recycle_pending) {
 			ret = -EAGAIN;
@@ -1213,10 +1218,10 @@ static void geth_freeq_release_pages(struct gemini_ethernet *geth)
 }
 
 static unsigned int
-geth_freeq_page_slots(struct gemini_ethernet *geth, unsigned int order)
+geth_freeq_page_slots(struct gemini_ethernet *geth, unsigned int buf_order)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
-	unsigned int slots = 1 << (order - fpp_order);
+	unsigned int slots = 1 << (buf_order - fpp_order);
 
 	if (geth->port0 && geth->port0->netdev)
 		slots += 1 << geth->port0->rxq_order;
@@ -1237,7 +1242,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	unsigned int filled;
 	u16 rptr;
 
-	page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
+	page_slots = geth_freeq_page_slots(geth, geth->freeq_buf_order);
 
 	geth->freeq_ring = dma_alloc_coherent(geth->dev,
 		sizeof(*geth->freeq_ring) << geth->freeq_order,
@@ -1266,7 +1271,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 	SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, rptr & (len - 1));
 
-	expected = len - (1 << fpp_order);
+	expected = (1 << geth->freeq_buf_order) - (1 << fpp_order);
 	filled = geth_fill_freeq(geth);
 	if (filled != expected)
 		goto err_freeq_bitmap;
@@ -1367,6 +1372,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	unsigned int new_size = 0;
 	unsigned int page_slots;
 	unsigned int new_order;
+	unsigned int buf_order;
 	u16 rptr;
 	int ret;
 
@@ -1396,20 +1402,23 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 			   other_port->rxq_order);
 	}
 
-	new_order = min(15, ilog2(new_size - 1) + 1);
+	buf_order = min(15, ilog2(new_size - 1) + 1);
+	if (buf_order <= PAGE_SHIFT - geth->freeq_frag_order)
+		return -EINVAL;
+
 	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 	if (rptr >= BIT(15))
 		return -EIO;
-	new_order = max_t(unsigned int, new_order, fls(rptr));
+	/* Contain the retained pointer without increasing RX buffer memory. */
+	new_order = max_t(unsigned int, buf_order, fls(rptr));
 	dev_dbg(geth->dev, "set shared queue to size %d order %d\n",
 		new_size, new_order);
-	if (new_order <= PAGE_SHIFT - geth->freeq_frag_order)
-		return -EINVAL;
 
 	/* Rebuild an idle queue to reclaim fragments which were never claimed. */
 	if (geth->freeq_ring && other_running) {
-		page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
+		page_slots = geth_freeq_page_slots(geth, buf_order);
 		if (geth->freeq_order >= new_order &&
+		    geth->freeq_buf_order >= buf_order &&
 		    geth->num_freeq_pages >= page_slots)
 			return 0;
 	}
@@ -1426,6 +1435,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 
 	/* Allocate a new queue with the desired order */
 	geth->freeq_order = new_order;
+	geth->freeq_buf_order = buf_order;
 	ret = geth_setup_freeq(geth);
 
 	/* Enable the queue interrupt only after successful setup. */
@@ -1927,7 +1937,7 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)
 	unsigned int received;
 	bool reschedule;
 
-	freeq_threshold = 1 << (geth->freeq_order - 1);
+	freeq_threshold = 1 << (geth->freeq_buf_order - 1);
 	u64_stats_update_begin(&port->rx_stats_syncp);
 
 	received = gmac_rx(napi->dev, budget, &freeq_consumed, &reschedule);

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 11/19] net: ethernet: cortina: Validate RX fragment lengths
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (9 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 10/19] net: ethernet: cortina: Separate RX buffer capacity from free queue size Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-16 14:45   ` netdev-bot+sashiko
  2026-11-12 13:30 ` [PATCH net-next v8 12/19] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
                   ` (7 subsequent siblings)
  18 siblings, 1 reply; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

RX descriptor lengths are used to adjust the page offset and populate skb
fragments without checking that the resulting range remains inside the
posted free queue fragment. A zero-length descriptor is logged but is still
appended.

The backing page is larger than the default 2 KiB DMA fragment, so checking
only the page boundary would allow a malformed descriptor for the first
half of a page to consume data from the sibling fragment. That fragment may
still be owned by the device.

Reject a short initial fragment before applying NET_IP_ALIGN. Validate the
final fragment length derived from the total frame byte count, rejecting
underflow and ranges extending beyond either the DMA fragment or the page.

Drop zero-length non-final descriptors. If an EOF descriptor carries no new
data after earlier descriptors completed the frame, release its unused page
reference and pass the assembled skb to GRO. Check this case before the
fragment limit so an empty EOF can terminate a full fragment array.

Correct the copied buffer_size comment to match the Gemini manual, which
defines it as the transfer buffer size associated with the descriptor.
Require the final frame length to cover an Ethernet frame so a malformed
chain cannot pass a short skb to GRO. Account descriptor inconsistencies as
drops rather than wire length errors.

The issue was found by inspecting the descriptor arithmetic and validated
against the Gemini receive descriptor definitions. The series was tested on
a D-Link DIR-685 with media playback and ksmbd transfers under ping load.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 42 +++++++++++++++++++++++++++--------
 drivers/net/ethernet/cortina/gemini.h |  2 +-
 2 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 72d2c002f8fc..364504c9d441 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1790,6 +1790,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	unsigned short m = (1 << port->rxq_order) - 1;
 	struct gemini_ethernet *geth = port->geth;
+	unsigned int freeq_frag_len = 1 << geth->freeq_frag_order;
 	void __iomem *ptr_reg = port->rxq_rwptr;
 	unsigned int frag_nr = port->rx_frag_nr;
 	struct sk_buff *skb = port->rx_skb;
@@ -1864,6 +1865,9 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			if (!skb)
 				goto err_drop;
 
+			if (frag_len < NET_IP_ALIGN)
+				goto err_drop;
+
 			page_offs += NET_IP_ALIGN;
 			frag_len -= NET_IP_ALIGN;
 			frag_nr = 0;
@@ -1872,15 +1876,33 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			goto err_drop;
 		}
 
-		if (word3.bits32 & EOF_BIT)
+		if (word3.bits32 & EOF_BIT) {
+			if (frame_len < ETH_ZLEN ||
+			    frame_len < skb->len)
+				goto err_drop;
 			frag_len = frame_len - skb->len;
+		}
+
+		if (!frag_len) {
+			if (word3.bits32 & EOF_BIT) {
+				put_page(page);
+				page = NULL;
+				goto complete_frame;
+			}
+
+			if (net_ratelimit())
+				netdev_err(netdev,
+					   "Received fragment with len = 0\n");
+			goto err_drop;
+		}
 
 		/* append page frag to skb */
 		if (frag_nr == MAX_SKB_FRAGS)
 			goto err_drop;
-
-		if (frag_len == 0 && net_ratelimit())
-			netdev_err(netdev, "Received fragment with len = 0\n");
+		if (frag_len > freeq_frag_len -
+			       (page_offs & (freeq_frag_len - 1)) ||
+		    frag_len > PAGE_SIZE - page_offs)
+			goto err_drop;
 
 		skb_fill_page_desc(skb, frag_nr, page, page_offs, frag_len);
 		skb->len += frag_len;
@@ -1888,11 +1910,13 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 		skb->truesize += frag_len;
 		frag_nr++;
 
-		if (word3.bits32 & EOF_BIT) {
-			napi_gro_frags(&port->napi);
-			skb = NULL;
-			frag_nr = 0;
-		}
+		if (!(word3.bits32 & EOF_BIT))
+			goto next_desc;
+
+complete_frame:
+		napi_gro_frags(&port->napi);
+		skb = NULL;
+		frag_nr = 0;
 		goto next_desc;
 
 err_drop:
diff --git a/drivers/net/ethernet/cortina/gemini.h b/drivers/net/ethernet/cortina/gemini.h
index d359c633c5de..43006fe44c9f 100644
--- a/drivers/net/ethernet/cortina/gemini.h
+++ b/drivers/net/ethernet/cortina/gemini.h
@@ -519,7 +519,7 @@ struct gmac_txdesc {
 union gmac_rxdesc_0 {
 	unsigned int bits32;
 	struct bit_8060 {
-		/* bit 15:0 number of descriptors used for the current frame */
+		/* bit 15:0 transfer buffer size for this descriptor */
 		unsigned int buffer_size:16;
 		/* bit 21:16 number of descriptors used for the current frame */
 		unsigned int desc_count:6;

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 12/19] net: ethernet: cortina: Account RX buffer size in truesize
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (10 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 11/19] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 13/19] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

gmac_rx() charges only the received payload length for each page fragment
attached to an skb. Each fragment pins a complete free queue DMA buffer, so
short packets understate their memory use to GRO and socket accounting.

Charge the full posted fragment size for every attached fragment. The skb
already accounts for its own head separately.

The issue was found by reviewing the RX fragment accounting. The series was
tested on a D-Link DIR-685 with media playback and ksmbd transfers under
ping load.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 364504c9d441..f31fd0de0059 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1907,7 +1907,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 		skb_fill_page_desc(skb, frag_nr, page, page_offs, frag_len);
 		skb->len += frag_len;
 		skb->data_len += frag_len;
-		skb->truesize += frag_len;
+		skb->truesize += freeq_frag_len;
 		frag_nr++;
 
 		if (!(word3.bits32 & EOF_BIT))

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 13/19] net: ethernet: cortina: Release partial RX frames on stop
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (11 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 12/19] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 14/19] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

A NAPI poll can retain a partially assembled frame across invocations. The
stop path clears port->rx_skb without freeing the skb retained in
napi->skb. If the interface is reopened, napi_get_frags() returns that
stale skb. The next frame overwrites its fragment array from index zero
while len and data_len still include the partial frame.

This can lose page references belonging to the old fragments or pass an
skb with inconsistent fragment accounting to GRO. If the interface is
removed without reopening, NAPI teardown eventually frees the stale skb.

Free a pending fragment skb after disabling NAPI and before clearing the
saved RX state. Count the discarded frame as dropped under the RX
statistics sequence counter. Use the irqsave update helpers because
ndo_stop runs in preemptible process context while 32-bit statistics
writers must not be preempted.

The issue was found by inspecting the partial frame lifetime and statistics
writer contexts. The series was tested on a D-Link DIR-685 with media
playback and ksmbd transfers under ping load.

Fixes: 06937db21ee3 ("net: ethernet: cortina: Make RX SKB per-port")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index f31fd0de0059..0588e573f8da 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2269,12 +2269,19 @@ static int gmac_open(struct net_device *netdev)
 static int gmac_stop(struct net_device *netdev)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
+	unsigned long flags;
 
 	hrtimer_cancel(&port->rx_coalesce_timer);
 	netif_tx_stop_all_queues(netdev);
 	gmac_disable_tx_rx(netdev);
 	gmac_stop_dma(port);
 	napi_disable(&port->napi);
+	if (port->rx_skb) {
+		napi_free_frags(&port->napi);
+		flags = u64_stats_update_begin_irqsave(&port->rx_stats_syncp);
+		port->stats.rx_dropped++;
+		u64_stats_update_end_irqrestore(&port->rx_stats_syncp, flags);
+	}
 	port->rx_skb = NULL;
 	port->rx_frag_nr = 0;
 	port->rx_dropping = false;

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 14/19] net: ethernet: cortina: Scale Gemini RX queues to system memory
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (12 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 13/19] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 15/19] net: ethernet: cortina: Serialize TX completion statistics Linus Walleij
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The default RX queues contain 512 descriptors per port. The shared
software free queue is sized at twice their combined capacity, requiring
4 MiB of page fragments even on Gemini systems with only 32 or 64 MiB of
RAM.

Choose smaller default RX queues on memory-constrained systems. Use 256
descriptors per port and a 2 MiB free queue with at most 64 MiB of RAM,
and 128 descriptors per port with a 1 MiB free queue with at most 32 MiB.
Keep the existing defaults on systems with more memory.

This preserves the existing relationship between RX descriptor capacity
and the free queue. Users can still override the defaults with ethtool.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 0588e573f8da..5a87d88607cd 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -16,6 +16,7 @@
 #include <linux/kernel.h>
 #include <linux/bitmap.h>
 #include <linux/init.h>
+#include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/net.h>
 #include <linux/platform_device.h>
@@ -37,6 +38,7 @@
 #include <linux/skbuff.h>
 #include <linux/phy.h>
 #include <linux/crc32.h>
+#include <linux/sizes.h>
 #include <linux/ethtool.h>
 #include <linux/tcp.h>
 #include <linux/u64_stats_sync.h>
@@ -509,6 +511,17 @@ static int gmac_pick_rx_max_len(unsigned int max_l3_len)
 	return -1;
 }
 
+static unsigned int gmac_pick_rxq_order(void)
+{
+	if (totalram_pages() <= (SZ_32M >> PAGE_SHIFT))
+		return DEFAULT_GMAC_RXQ_ORDER - 2;
+
+	if (totalram_pages() <= (SZ_64M >> PAGE_SHIFT))
+		return DEFAULT_GMAC_RXQ_ORDER - 1;
+
+	return DEFAULT_GMAC_RXQ_ORDER;
+}
+
 static int gmac_init(struct net_device *netdev)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
@@ -577,7 +590,7 @@ static int gmac_init(struct net_device *netdev)
 	writel(sw_weigh.bits32,
 	       port->dma_base + GMAC_TX_WEIGHTING_CTRL_1_REG);
 
-	port->rxq_order = DEFAULT_GMAC_RXQ_ORDER;
+	port->rxq_order = gmac_pick_rxq_order();
 	port->txq_order = DEFAULT_GMAC_TXQ_ORDER;
 	port->rx_coalesce_nsecs = DEFAULT_RX_COALESCE_NSECS;
 

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 15/19] net: ethernet: cortina: Serialize TX completion statistics
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (13 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 14/19] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-16 14:45   ` netdev-bot+sashiko
  2026-11-12 13:30 ` [PATCH net-next v8 16/19] net: ethernet: cortina: Scope RX statistics updates Linus Walleij
                   ` (3 subsequent siblings)
  18 siblings, 1 reply; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

gmac_clean_txq() updates ir_stats_syncp with hard interrupts enabled,
while the MIB and RX overrun interrupt paths update the same seqcount.
Initializing its lockdep key exposes the incompatible IRQ contexts on
32-bit debug kernels. The writer sections also lack mutual exclusion.

Take the existing IRQ-safe irq_lock around the TX completion statistics
update, matching the other ir_stats_syncp writers. Acquire it before
opening the seqcount writer section so PREEMPT_RT does not acquire a
potentially sleeping spinlock with preemption disabled.

The TX fragment counter also uses tx_stats_syncp from both start_xmit()
and process-context teardown. Use IRQ-safe writer helpers around that
increment so a statistics reader cannot interrupt the writer and spin on
an odd sequence. Keep this protection local to the counter update rather
than covering the entire TX cleanup.

Found during Sashiko review and confirmed by tracing the IRQ, transmit and
stop paths. Cross-built gemini.o for ARM with W=1. No hardware lockdep or
PREEMPT_RT runtime testing was performed for this change.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 5a87d88607cd..cc26ff16a0a3 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -671,6 +671,7 @@ static void gmac_clean_txq(struct net_device *netdev, struct gmac_txq *txq,
 	union gmac_txdesc_1 word1;
 	unsigned int hwchksum = 0;
 	unsigned long bytes = 0;
+	unsigned long flags;
 	struct gmac_txdesc *txd;
 	unsigned short nfrags;
 	unsigned int errs = 0;
@@ -716,18 +717,21 @@ static void gmac_clean_txq(struct net_device *netdev, struct gmac_txq *txq,
 			if (nfrags >= TX_MAX_FRAGS)
 				nfrags = TX_MAX_FRAGS - 1;
 
-			u64_stats_update_begin(&port->tx_stats_syncp);
+			flags = u64_stats_update_begin_irqsave(&port->tx_stats_syncp);
 			port->tx_frag_stats[nfrags]++;
-			u64_stats_update_end(&port->tx_stats_syncp);
+			u64_stats_update_end_irqrestore(&port->tx_stats_syncp,
+							flags);
 		}
 	}
 
+	spin_lock_irqsave(&geth->irq_lock, flags);
 	u64_stats_update_begin(&port->ir_stats_syncp);
 	port->stats.tx_errors += errs;
 	port->stats.tx_packets += pkts;
 	port->stats.tx_bytes += bytes;
 	port->tx_hw_csummed += hwchksum;
 	u64_stats_update_end(&port->ir_stats_syncp);
+	spin_unlock_irqrestore(&geth->irq_lock, flags);
 
 	txq->cptr = c;
 }

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 16/19] net: ethernet: cortina: Scope RX statistics updates
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (14 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 15/19] net: ethernet: cortina: Serialize TX completion statistics Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 17/19] net: ethernet: cortina: Drain RX coalescing timer on stop Linus Walleij
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

On 32-bit PREEMPT_RT systems u64_stats_update_begin() disables
preemption. The RX poll currently holds that writer section across
gmac_rx(), which takes spinlock_t locks and calls into GRO and fragment
handling. spinlock_t can sleep on PREEMPT_RT and must not be acquired
with preemption disabled.

Keep the writer sections around the counter updates only. NAPI ownership
continues to serialize normal RX writers, while the stop path updates its
counter after napi_disable(). This preserves the existing accounting
without covering potentially sleeping operations.

Initialize the dynamically allocated statistics synchronization objects
so their seqcount lockdep keys are valid on 32-bit debug kernels.

The issue was found by inspecting the u64_stats_sync writer scope. The
series was tested on a D-Link DIR-685 with media playback and ksmbd
transfers under ping load. PREEMPT_RT was not runtime-tested.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index cc26ff16a0a3..d0d161654f49 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1769,12 +1769,12 @@ static struct sk_buff *gmac_skb_if_good_frame(struct gemini_ethernet_port *port,
 	unsigned int rx_status = word0.bits.status;
 	struct sk_buff *skb = NULL;
 
-	port->rx_stats[rx_status]++;
-	port->rx_csum_stats[rx_csum]++;
-
 	if (word0.bits.derr || word0.bits.perr ||
 	    rx_status || frame_len < ETH_ZLEN ||
 	    rx_csum >= RX_CHKSUM_IP_ERR_UNKNOWN) {
+		u64_stats_update_begin(&port->rx_stats_syncp);
+		port->rx_stats[rx_status]++;
+		port->rx_csum_stats[rx_csum]++;
 		port->stats.rx_errors++;
 
 		if (frame_len < ETH_ZLEN || RX_ERROR_LENGTH(rx_status))
@@ -1785,6 +1785,7 @@ static struct sk_buff *gmac_skb_if_good_frame(struct gemini_ethernet_port *port,
 			port->stats.rx_crc_errors++;
 		if (RX_ERROR_FRAME(rx_status))
 			port->stats.rx_frame_errors++;
+		u64_stats_update_end(&port->rx_stats_syncp);
 		return NULL;
 	}
 
@@ -1796,8 +1797,12 @@ static struct sk_buff *gmac_skb_if_good_frame(struct gemini_ethernet_port *port,
 		skb->ip_summed = CHECKSUM_UNNECESSARY;
 
 update_exit:
+	u64_stats_update_begin(&port->rx_stats_syncp);
+	port->rx_stats[rx_status]++;
+	port->rx_csum_stats[rx_csum]++;
 	port->stats.rx_bytes += frame_len;
 	port->stats.rx_packets++;
+	u64_stats_update_end(&port->rx_stats_syncp);
 	return skb;
 }
 
@@ -1855,7 +1860,9 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 		if (word3.bits32 & SOF_BIT) {
 			if (skb) {
 				napi_free_frags(&port->napi);
+				u64_stats_update_begin(&port->rx_stats_syncp);
 				port->stats.rx_dropped++;
+				u64_stats_update_end(&port->rx_stats_syncp);
 				skb = NULL;
 				frag_nr = 0;
 			}
@@ -1947,7 +1954,9 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			put_page(page);
 
 		if (!dropping) {
+			u64_stats_update_begin(&port->rx_stats_syncp);
 			port->stats.rx_dropped++;
+			u64_stats_update_end(&port->rx_stats_syncp);
 			dropping = true;
 		}
 
@@ -1979,13 +1988,13 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)
 	bool reschedule;
 
 	freeq_threshold = 1 << (geth->freeq_buf_order - 1);
-	u64_stats_update_begin(&port->rx_stats_syncp);
 
 	received = gmac_rx(napi->dev, budget, &freeq_consumed, &reschedule);
-	if (!reschedule && received < budget)
+	if (!reschedule && received < budget) {
+		u64_stats_update_begin(&port->rx_stats_syncp);
 		++port->rx_napi_exits;
-
-	u64_stats_update_end(&port->rx_stats_syncp);
+		u64_stats_update_end(&port->rx_stats_syncp);
+	}
 
 	port->freeq_refill += freeq_consumed;
 	if (port->freeq_refill > freeq_threshold) {
@@ -2912,6 +2921,9 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	}
 
 	port = netdev_priv(netdev);
+	u64_stats_init(&port->tx_stats_syncp);
+	u64_stats_init(&port->rx_stats_syncp);
+	u64_stats_init(&port->ir_stats_syncp);
 	SET_NETDEV_DEV(netdev, dev);
 	port->netdev = netdev;
 	port->id = id;

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 17/19] net: ethernet: cortina: Drain RX coalescing timer on stop
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (15 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 16/19] net: ethernet: cortina: Scope RX statistics updates Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 18/19] net: ethernet: cortina: Reject TX rings smaller than retained pointers Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads Linus Walleij
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

gmac_stop() cancels the RX coalescing timer before disabling and
freeing the IRQ. An RX interrupt racing with that cancellation can
rearm the timer, leaving it queued after the netdev and its private
port state have been freed.

gmac_open() also initializes the timer after enabling RX interrupts.
With RX coalescing configured, an interrupt can start an uninitialized
timer on first open, or one that setup then reinitializes while queued
on reopen.

Initialize the timer before requesting the IRQ. Keep the early stop-path
cancellation as a best-effort drain of an existing timer; an RX interrupt
can still rearm it before IRQ teardown. napi_disable() handles concurrent
scheduling attempts. Cancel the timer again after free_irq() has drained
the handler, so no timer callback can outlive the port.

This was found by code inspection and tested on the D-Link DIR-685.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index d0d161654f49..24a66fc34738 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2243,6 +2243,10 @@ static int gmac_open(struct net_device *netdev)
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	int err;
 
+	hrtimer_setup(&port->rx_coalesce_timer,
+		      &gmac_coalesce_delay_expired,
+		      CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+
 	err = request_irq(netdev->irq, gmac_irq,
 			  IRQF_SHARED, netdev->name, netdev);
 	if (err) {
@@ -2279,9 +2283,6 @@ static int gmac_open(struct net_device *netdev)
 	gmac_enable_tx_rx(netdev);
 	netif_tx_start_all_queues(netdev);
 
-	hrtimer_setup(&port->rx_coalesce_timer, &gmac_coalesce_delay_expired, CLOCK_MONOTONIC,
-		      HRTIMER_MODE_REL);
-
 	netdev_dbg(netdev, "opened\n");
 
 	return 0;
@@ -2318,6 +2319,7 @@ static int gmac_stop(struct net_device *netdev)
 
 	phy_stop(netdev->phydev);
 	free_irq(netdev->irq, netdev);
+	hrtimer_cancel(&port->rx_coalesce_timer);
 
 	gmac_update_hw_stats(netdev);
 	return 0;

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 18/19] net: ethernet: cortina: Reject TX rings smaller than retained pointers
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (16 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 17/19] net: ethernet: cortina: Drain RX coalescing timer on stop Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-12 13:30 ` [PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads Linus Walleij
  18 siblings, 0 replies; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The hardware-owned TX read pointers can retain their positions when the
queues are rebuilt. After shrinking the TX ring with ethtool -G while
the interface is down, gmac_setup_txqs() copies those pointers into the
write and clean pointers without checking the new ring size. A retained
pointer outside the smaller ring can then index past both the skb table
and the coherent descriptor allocation.

Reject a TX ring size that cannot contain every retained read pointer,
before applying any RX ring changes in the same ethtool request. Check
again before allocating and programming the TX rings on open, including
for pointer state inherited from firmware. DMA is stopped at both checks.
Do not just mask the software pointers, which would leave the hardware
read pointer outside the new ring.

Found during Sashiko review and confirmed with a pointer arithmetic
model: a retained pointer of 200 with 16 entries reports 15 free entries
and permits the first TX write at index 200. Checked all 16-bit pointer
values against queue orders 0 through 15 and cross-built the driver for
ARM.

Tested on the D-Link DIR-685 with intense transfers and ping storms.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 24a66fc34738..899d96420b1b 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -602,6 +602,20 @@ static int gmac_init(struct net_device *netdev)
 	return 0;
 }
 
+static bool gmac_txq_size_valid(struct net_device *netdev, unsigned int entries)
+{
+	struct gemini_ethernet_port *port = netdev_priv(netdev);
+	unsigned int i;
+
+	/* DMA is stopped, so the hardware read pointers cannot advance. */
+	for (i = 0; i < netdev->num_tx_queues; i++)
+		if (GET_RPTR(port->dma_base + GMAC_SW_TX_QUEUE_PTR_REG(i)) >=
+		    entries)
+			return false;
+
+	return true;
+}
+
 static int gmac_setup_txqs(struct net_device *netdev)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
@@ -616,6 +630,12 @@ static int gmac_setup_txqs(struct net_device *netdev)
 	unsigned int r;
 	int i;
 
+	if (!gmac_txq_size_valid(netdev, entries)) {
+		netdev_err(netdev,
+			   "TX ring is too small for the retained read pointer\n");
+		return -EINVAL;
+	}
+
 	rwptr_reg = port->dma_base + GMAC_SW_TX_QUEUE0_PTR_REG;
 
 	skb_tab = kzalloc_objs(*skb_tab, len);
@@ -2623,11 +2643,21 @@ static int gmac_set_ringparam(struct net_device *netdev,
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	unsigned int old_rxq_order;
+	unsigned int txq_order = port->txq_order;
 	int err = 0;
 
 	if (netif_running(netdev))
 		return -EBUSY;
 
+	if (rp->tx_pending) {
+		txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
+		if (!gmac_txq_size_valid(netdev, BIT(txq_order))) {
+			NL_SET_ERR_MSG(extack,
+				       "TX ring is too small for the retained read pointer");
+			return -EINVAL;
+		}
+	}
+
 	if (rp->rx_pending) {
 		old_rxq_order = port->rxq_order;
 		port->rxq_order = min(15, ilog2(rp->rx_pending - 1) + 1);
@@ -2638,7 +2668,7 @@ static int gmac_set_ringparam(struct net_device *netdev,
 		}
 	}
 	if (rp->tx_pending) {
-		port->txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
+		port->txq_order = txq_order;
 		port->irq_every_tx_packets = 1 << (port->txq_order - 2);
 	}
 

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads
  2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
                   ` (17 preceding siblings ...)
  2026-11-12 13:30 ` [PATCH net-next v8 18/19] net: ethernet: cortina: Reject TX rings smaller than retained pointers Linus Walleij
@ 2026-11-12 13:30 ` Linus Walleij
  2026-11-16 14:45   ` netdev-bot+sashiko
  18 siblings, 1 reply; 27+ messages in thread
From: Linus Walleij @ 2026-11-12 13:30 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The TX statistics reader resets p on a seqcount retry but writes through
values instead. A retry on 32-bit systems therefore writes another 18
counters past the end of the ethtool statistics array. ETHTOOL_GSTATS
does not require privileges.

Write through p so each retry overwrites the same output slots. Stop
clearing the fragment counters from the reader, which races with TX
updates and resets the counters on each read. Snapshot tx_hw_csummed
under ir_stats_syncp, matching its writer, and retain its output position.

Found during Sashiko review and checked with an extracted-reader host
harness that forces seqcount retries. The old reader overwrote guard
entries and cleared counters; the fixed reader stays within the output
array and preserves counters.

Tested on the D-Link DIR-685 with intense transfers and ping storms,
reading out stats with ethtool at the same time.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 899d96420b1b..d4aa283ccb7b 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2520,6 +2520,7 @@ static void gmac_get_ethtool_stats(struct net_device *netdev,
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	unsigned int start;
+	u64 tx_hw_csummed;
 	u64 *p;
 	int i;
 
@@ -2532,6 +2533,7 @@ static void gmac_get_ethtool_stats(struct net_device *netdev,
 
 		for (i = 0; i < RX_STATS_NUM; i++)
 			*p++ = port->hw_stats[i];
+		tx_hw_csummed = port->tx_hw_csummed;
 
 	} while (u64_stats_fetch_retry(&port->ir_stats_syncp, start));
 	values = p;
@@ -2555,12 +2557,10 @@ static void gmac_get_ethtool_stats(struct net_device *netdev,
 		p = values;
 		start = u64_stats_fetch_begin(&port->tx_stats_syncp);
 
-		for (i = 0; i < TX_MAX_FRAGS; i++) {
-			*values++ = port->tx_frag_stats[i];
-			port->tx_frag_stats[i] = 0;
-		}
-		*values++ = port->tx_frags_linearized;
-		*values++ = port->tx_hw_csummed;
+		for (i = 0; i < TX_MAX_FRAGS; i++)
+			*p++ = port->tx_frag_stats[i];
+		*p++ = port->tx_frags_linearized;
+		*p++ = tx_hw_csummed;
 
 	} while (u64_stats_fetch_retry(&port->tx_stats_syncp, start));
 }

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ
  2026-11-12 13:30 ` [PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
@ 2026-11-16 14:45   ` netdev-bot+sashiko
  0 siblings, 0 replies; 27+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 14:45 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v8 06/19] net: ethernet: cortina: Index free queue fragments with XArray
  2026-11-12 13:30 ` [PATCH net-next v8 06/19] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
@ 2026-11-16 14:45   ` netdev-bot+sashiko
  0 siblings, 0 replies; 27+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 14:45 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In geth_freeq_alloc_map_page()
  (drivers/net/ethernet/cortina/gemini.c), the patch adds one…
- [Low] geth_setup_freeq() (drivers/net/ethernet/cortina/gemini.c) now
  wraps every geth_freeq_alloc_map_page() call in…

--

net: ethernet: cortina: Index free queue fragments with XArray

This commit replaces the linear scan in geth_freeq_lookup() with an XArray
that indexes each free queue fragment by its DMA address in fragment units.
Index entries are inserted and erased in geth_freeq_alloc_map_page() under
freeq_lock, and geth_setup_freeq() now takes freeq_lock around each page
allocation.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index b96325f652bba..4ee630a9f5897 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -888,9 +898,26 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
>  	 */
>  	frag_len = 1 << geth->freeq_frag_order; /* Usually 2048 */
>  	fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
> +	fragments = 1 << fpp_order;
> +
>  	gpage = &geth->freeq_pages[pn];
> -	if (gpage->page)
> +	for (i = 0; i < fragments; i++) {
> +		mapping = page_mapping + i * frag_len;
> +		ret = xa_insert(&geth->freeq_mappings,
> +				geth_freeq_mapping_index(geth, mapping),
> +				gpage, GFP_ATOMIC);
> +		if (ret)
> +			goto err_mappings;
> +	}

[Severity: Low]
Should the commit message mention what this xa_insert() costs?

The commit message describes the change only as removing an inefficient
linear scan. However, geth_freeq_alloc_map_page() now does GFP_ATOMIC
xa_node allocations on both the NAPI refill path and the setup path:

gmac_napi_poll()
  geth_fill_freeq(geth, true)
    geth_freeq_alloc_map_page()
      xa_insert(..., GFP_ATOMIC)

That works out to roughly one leaf node per 128 KiB of physical address
range touched (64 slots of 2 KiB each).

There is also a new way for this function to fail. If only the index
allocation fails, err_mappings unmaps and frees a page that was allocated
and DMA mapped successfully. geth_fill_freeq() then stops refilling, and
geth_setup_freeq() fails open or resize with -ENOMEM.

The unwind looks correct, and the failure is handled the same way as an
alloc_page(GFP_ATOMIC) failure. So the concern is the commit message, not
the runtime behaviour.

Could the commit message describe the extra atomic allocations and the new
failure mode? The same GFP_ATOMIC xa_insert() is still in
geth_freeq_post_page() at the end of the series.

[ ... ]

> @@ -995,16 +1035,20 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
>  		goto err_freeq;
>  	}
>  
> -	/* Allocate a mapping to page look-up index */
> +	/* Allocate page metadata referenced by the mapping index */
>  	geth->freeq_pages = kzalloc_objs(*geth->freeq_pages, pages);
>  	if (!geth->freeq_pages)
>  		goto err_freeq;
>  	geth->num_freeq_pages = pages;
>  
>  	dev_info(geth->dev, "allocate %d pages for queue\n", pages);
> -	for (pn = 0; pn < pages; pn++)
> -		if (!geth_freeq_alloc_map_page(geth, pn))
> +	for (pn = 0; pn < pages; pn++) {
> +		spin_lock_irqsave(&geth->freeq_lock, flags);
> +		page = geth_freeq_alloc_map_page(geth, pn);
> +		spin_unlock_irqrestore(&geth->freeq_lock, flags);
> +		if (!page)
>  			goto err_freeq_alloc;
> +	}

[Severity: Low]
Does holding freeq_lock here mean the setup path builds the whole index
from atomic reserves?

geth_setup_freeq() is reached from geth_resize_freeq() in sleepable process
context under RTNL (ndo_open or ethtool -G). With freeq_lock held and IRQs
off, every xa_insert() in geth_freeq_alloc_map_page() has to use GFP_ATOMIC
and cannot do direct reclaim:

geth_resize_freeq()
  geth_setup_freeq()
    spin_lock_irqsave(&geth->freeq_lock, flags)
    geth_freeq_alloc_map_page()
      xa_insert(..., GFP_ATOMIC)

A large ring (up to 2^15 entries, about 16K pages) needs a burst of these
node allocations. Under memory pressure, that makes open or ring resize
more likely to fail with -ENOMEM.

The effect is small, because the RX pages were already allocated with
alloc_page(GFP_ATOMIC) before this patch. The same pattern is still there
at the end of the series via
geth_setup_freeq()->geth_fill_freeq()->geth_freeq_post_page().

On the setup path, could the index entries be reserved with GFP_KERNEL
before taking the lock (for example with xa_reserve())? Alternatively,
could a gfp argument be passed down so that setup can use sleeping
allocations?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3%40kernel.org

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v8 07/19] net: ethernet: cortina: Preserve in-flight free queue pages
  2026-11-12 13:30 ` [PATCH net-next v8 07/19] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
@ 2026-11-16 14:45   ` netdev-bot+sashiko
  0 siblings, 0 replies; 27+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 14:45 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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).

- [Medium] This patch replaces position-indexed free queue metadata with
  a fixed pool of page slots.

--

net: ethernet: cortina: Preserve in-flight free queue pages

Free queue page metadata is no longer indexed by free queue ring position.
Metadata slots now come from a pool tracked by a bitmap, sized for the
free queue plus both RX rings. Each posted fragment keeps its own page
reference and XArray entry until it is claimed. The page is unmapped and
its slot released once all of its fragments have been claimed. The shared
queue is only rebuilt while the peer port is down.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 4ee630a9f5897..4b0c10d732ab5 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -795,6 +817,21 @@ static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
>  	if (!valid)
>  		goto err_unlock;
>  
> +	dma_sync_single_range_for_cpu(geth->dev, page_mapping,
> +				      mapping - page_mapping, frag_len,
> +				      DMA_FROM_DEVICE);
> +	xa_erase(&geth->freeq_mappings, index);
> +	if (!--gpage->fragments) {
> +		slot = gpage - geth->freeq_pages;
> +		dma_unmap_single_attrs(geth->dev, page_mapping, PAGE_SIZE,
> +				       DMA_FROM_DEVICE,
> +				       DMA_ATTR_SKIP_CPU_SYNC);
> +		gpage->page = NULL;
> +		gpage->mapping = 0;
> +		__clear_bit(slot, geth->freeq_page_bitmap);
> +		put_page(page);
> +	}

[Severity: Medium]
With the new slot pool, this block in geth_freeq_claim() is the only
runtime path that releases a slot, its page and its DMA mapping. It only
runs once every fragment of the page has been claimed.

What happens to a fragment that the hardware takes from the free queue
but never returns as a usable RX descriptor?

gmac_rx() has two paths that drop the descriptor without claiming
anything:

	if (!mapping) {
		if (net_ratelimit())
			netdev_err(netdev,
				   "rxq[%u]: HW BUG: zero DMA desc\n",
				   r);
		goto err_drop;
	}

	page = geth_freeq_claim(geth, mapping, &page_offs);
	if (!page) {
		dev_err_ratelimited(geth->dev,
				    "could not find mapping\n");
		goto err_drop;
	}

gmac_cleanup_rxq() also skips zero mappings. In these cases
gpage->fragments never reaches zero. The page, its streaming mapping and
its bit in freeq_page_bitmap then stay held until geth_cleanup_freeq().

The commit message acknowledges such fragments exist: "This does not
reclaim unclaimed fragments while the peer runs." Also,
geth_resize_freeq() only rebuilds when the peer is down:

	if (other_running)
		return -EBUSY;

The pool from geth_freeq_page_slots() has very little headroom. With the
defaults it is 1024 + 512 + 512 = 2048 slots. The legitimate in-flight
worst case is roughly len/2 - 1 free queue pages plus
(1 << rxq_order) - 1 per RX ring, which leaves about 3 spare slots.

As lost fragments build up, geth_freeq_alloc_slot() will start
returning -ENOSPC. geth_fill_freeq() then stops at the first failed
geth_freeq_add_page() call. Could this first limit refill during RX
bursts and eventually starve RX altogether?

On a dual-port setup with both interfaces kept up, it looks like the
only recovery is to take both interfaces down. The old design
overwrote metadata by queue position, so a lost fragment could not
reduce refill capacity.

The later patches in the series don't seem to change this. "Recycle
claimed free queue pages" only recycles slots whose fragments have all
been claimed. "Separate RX buffer capacity from free queue size" keeps
the same sizing scheme. At the end of the series, gmac_rx() still drops
zero and unknown mappings without claiming them.

Would it make sense to reclaim these fragments some other way, or to
size the pool with more headroom?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3%40kernel.org

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v8 10/19] net: ethernet: cortina: Separate RX buffer capacity from free queue size
  2026-11-12 13:30 ` [PATCH net-next v8 10/19] net: ethernet: cortina: Separate RX buffer capacity from free queue size Linus Walleij
@ 2026-11-16 14:45   ` netdev-bot+sashiko
  0 siblings, 0 replies; 27+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 14:45 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message has `Fixes: 0bf8c8c94af2 ("net: ethernet:
  cortina: Normalize free queue pointers on rebuild")`, but that SHA…

--

net: ethernet: cortina: Separate RX buffer capacity from free queue size

This patch keeps the free queue descriptor ring large enough to contain
the retained hardware read pointer. The RX page budget is now sized
separately, from the configured port RX rings. Refill occupancy, page
metadata and the NAPI refill threshold are bounded by that new
freeq_buf_order instead of freeq_order.

> Fixes: 0bf8c8c94af2 ("net: ethernet: cortina: Normalize free queue pointers on rebuild")

[Severity: Low]
Is this Fixes tag pointing at the right commit? 0bf8c8c94af2 does not
resolve in the tree. The commit with this subject is 1e7aa52a9993,
earlier in this same series.

That commit adds the floor in geth_resize_freeq():

    new_order = max_t(unsigned int, new_order, fls(rptr));

Page allocation is still tied to the ring order at that point. So any
retained rptr >= 16384 forces an order-15 ring and about 64 MiB of RX
pages.

Its message only says "a following patch decouples the RX buffer budget
from descriptor geometry". It carries Fixes: 4d5ae32f5e1e, which makes it
a stable candidate. It does not name this patch as a required companion.

Other patches in the series do state their pairings. For example,
"Preserve in-flight free queue pages" says "Backport both changes
together with their prerequisites".

Since the tag here does not resolve, could stable or AUTOSEL tooling pick
up "Normalize free queue pointers on rebuild" without this follow-up? On
32 to 128 MiB Gemini boards, open() would then keep failing whenever the
retained rptr is >= 16384. The bisect window between the two commits in
this series has the same allocation problem.

This patch also cannot be applied directly on top of "Normalize free
queue pointers on rebuild". It changes geth_freeq_page_slots(), the
capacity-bounded loop in geth_fill_freeq() and the
freeq_recycle_pending path. Those come from "Preserve in-flight free
queue pages" and "Recycle claimed free queue pages", and the commit
message does not mention them as prerequisites.

Would it be cleaner to squash this change into "Normalize free queue
pointers on rebuild"? If not, could the Fixes tag be corrected to
1e7aa52a9993, with the backport pairing and prerequisites listed in both
commit messages?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3%40kernel.org

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v8 11/19] net: ethernet: cortina: Validate RX fragment lengths
  2026-11-12 13:30 ` [PATCH net-next v8 11/19] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
@ 2026-11-16 14:45   ` netdev-bot+sashiko
  0 siblings, 0 replies; 27+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 14:45 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In drivers/net/ethernet/cortina/gemini.c, gmac_rx() calls
  gmac_skb_if_good_frame() on the SOF descriptor.

--

net: ethernet: cortina: Validate RX fragment lengths

This patch adds checks in gmac_rx() so that an RX fragment cannot run
past its posted free queue fragment or past the page. Zero-length
non-final descriptors are now dropped, and an empty EOF descriptor
completes the frame that is already assembled.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 72d2c002f8fc2..364504c9d441a 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -1864,6 +1865,9 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
>  			if (!skb)
>  				goto err_drop;
>  
> +			if (frag_len < NET_IP_ALIGN)
> +				goto err_drop;
> +
>  			page_offs += NET_IP_ALIGN;
>  			frag_len -= NET_IP_ALIGN;
>  			frag_nr = 0;

[Severity: Low]
Is this frame now counted as both received and dropped?

By the time this check runs, gmac_skb_if_good_frame() has already counted
the frame as received:

drivers/net/ethernet/cortina/gemini.c:gmac_skb_if_good_frame() {
    ...
update_exit:
	port->stats.rx_bytes += frame_len;
	port->stats.rx_packets++;
	return skb;
}

err_drop then frees the skb and increments rx_dropped. The dropping flag
was reset to false on SOF, so that increment always happens:

err_drop:
	if (skb) {
		napi_free_frags(&port->napi);
	...
	if (!dropping) {
		port->stats.rx_dropped++;
		dropping = true;
	}

Nothing takes back the earlier rx_packets and rx_bytes increments. The
rx_bytes value also comes from the hardware byte_count, which this patch
otherwise treats as untrusted.

The other new paths into err_drop that this patch adds later in gmac_rx()
do the same thing:

- the frame_len < ETH_ZLEN || frame_len < skb->len check on EOF
- the zero-length non-final descriptor
- the freeq_frag_len / PAGE_SIZE bounds check

The commit message says:

    Account descriptor inconsistencies as drops rather than wire length
    errors.

Is that accurate, given that these frames also show up in rx_packets and
rx_bytes?

The napi_get_frags() failure path and failures on later descriptors
already double count like this. This patch adds more ways to reach it. The
problem is also still there at the end of the series: "net: ethernet:
cortina: Scope RX statistics updates" only wraps the same update_exit
increments in u64_stats_update_begin()/u64_stats_update_end().

Could the rx_packets/rx_bytes update move to the napi_gro_frags()
completion point instead?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3%40kernel.org

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v8 15/19] net: ethernet: cortina: Serialize TX completion statistics
  2026-11-12 13:30 ` [PATCH net-next v8 15/19] net: ethernet: cortina: Serialize TX completion statistics Linus Walleij
@ 2026-11-16 14:45   ` netdev-bot+sashiko
  0 siblings, 0 replies; 27+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 14:45 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The comment on geth->irq_lock still describes it as a lock for
  IRQ-related registers.

--

net: ethernet: cortina: Serialize TX completion statistics

This commit takes geth->irq_lock around the ir_stats_syncp writer section
in gmac_clean_txq(), so the TX completion counters are serialized against
the MIB and RX overrun writers. It also switches the tx_frag_stats update
to the irqsave variants of the u64_stats writer helpers.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 5a87d88607cdb..cc26ff16a0a36 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -716,18 +717,21 @@ static void gmac_clean_txq(struct net_device *netdev, struct gmac_txq *txq,

[ ... ]

> +	spin_lock_irqsave(&geth->irq_lock, flags);
>  	u64_stats_update_begin(&port->ir_stats_syncp);
>  	port->stats.tx_errors += errs;
>  	port->stats.tx_packets += pkts;
>  	port->stats.tx_bytes += bytes;
>  	port->tx_hw_csummed += hwchksum;
>  	u64_stats_update_end(&port->ir_stats_syncp);
> +	spin_unlock_irqrestore(&geth->irq_lock, flags);

[Severity: Low]
This isn't a bug, but should the comment on irq_lock in struct
gemini_ethernet be updated as well? It still says:

    spinlock_t	irq_lock; /* Locks IRQ-related registers */

This new critical section in gmac_clean_txq() does not touch any registers.
It only serializes the software counters under ir_stats_syncp against the
writers in gmac_update_hw_stats() and gmac_irq(). After this patch, irq_lock
is also the lock every ir_stats_syncp writer has to hold, and the struct
comment does not mention that.

A related issue predates this patch and was not introduced by it. The
reader in gmac_get_stats64() says:

    /* Racing with MIB and TX completion interrupts */

gmac_clean_txq() is only called from gmac_start_xmit() and
gmac_cleanup_txqs(), never from an interrupt handler. Could that comment be
corrected at the same time?

>  
>  	txq->cptr = c;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3%40kernel.org

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads
  2026-11-12 13:30 ` [PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads Linus Walleij
@ 2026-11-16 14:45   ` netdev-bot+sashiko
  0 siblings, 0 replies; 27+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 14:45 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In gmac_get_ethtool_stats()
  (drivers/net/ethernet/cortina/gemini.c), the patch adds `tx_hw_csummed…

--

net: ethernet: cortina: Fix ethtool statistics reads

This fixes the TX statistics retry loop in gmac_get_ethtool_stats(). The
loop wrote through values instead of p, so a seqcount retry could write
past the end of the ethtool stats array. It also stops clearing
tx_frag_stats[] from the reader, and now snapshots tx_hw_csummed under
ir_stats_syncp to match its writer.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 899d96420b1b8..d4aa283ccb7b7 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -2532,6 +2533,7 @@ static void gmac_get_ethtool_stats(struct net_device *netdev,
>  
>  		for (i = 0; i < RX_STATS_NUM; i++)
>  			*p++ = port->hw_stats[i];
> +		tx_hw_csummed = port->tx_hw_csummed;
>  
>  	} while (u64_stats_fetch_retry(&port->ir_stats_syncp, start));
>  	values = p;

[Severity: Low]
This isn't a bug, but should the comment above this loop be updated as
well? It still says only:

	/* Racing with MIB interrupt */
	do {
		p = values;
		start = u64_stats_fetch_begin(&port->ir_stats_syncp);

The MIB path, gmac_update_hw_stats(), never writes tx_hw_csummed. The
only writer is gmac_clean_txq(), which is reached from gmac_start_xmit()
and gmac_cleanup_txqs():

drivers/net/ethernet/cortina/gemini.c:gmac_clean_txq() {
    ...
	spin_lock_irqsave(&geth->irq_lock, flags);
	u64_stats_update_begin(&port->ir_stats_syncp);
	...
	port->tx_hw_csummed += hwchksum;
	u64_stats_update_end(&port->ir_stats_syncp);
    ...
}

Before this patch the loop only read hw_stats[], so the comment was
accurate. The other ir_stats_syncp reader, gmac_get_stats64(), already
lists both writers:

	/* Racing with MIB and TX completion interrupts */

Could this loop's comment name the TX completion writer too, so the two
readers describe the same seqcount the same way?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3%40kernel.org

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2026-11-16 14:45 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 13:30 [PATCH net-next v8 00/19] net: ethernet: cortina: Fix Gemini RX/TX buffer management Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 01/19] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 02/19] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
2026-11-16 14:45   ` netdev-bot+sashiko
2026-11-12 13:30 ` [PATCH net-next v8 03/19] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 04/19] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 05/19] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 06/19] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
2026-11-16 14:45   ` netdev-bot+sashiko
2026-11-12 13:30 ` [PATCH net-next v8 07/19] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
2026-11-16 14:45   ` netdev-bot+sashiko
2026-11-12 13:30 ` [PATCH net-next v8 08/19] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 09/19] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 10/19] net: ethernet: cortina: Separate RX buffer capacity from free queue size Linus Walleij
2026-11-16 14:45   ` netdev-bot+sashiko
2026-11-12 13:30 ` [PATCH net-next v8 11/19] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
2026-11-16 14:45   ` netdev-bot+sashiko
2026-11-12 13:30 ` [PATCH net-next v8 12/19] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 13/19] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 14/19] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 15/19] net: ethernet: cortina: Serialize TX completion statistics Linus Walleij
2026-11-16 14:45   ` netdev-bot+sashiko
2026-11-12 13:30 ` [PATCH net-next v8 16/19] net: ethernet: cortina: Scope RX statistics updates Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 17/19] net: ethernet: cortina: Drain RX coalescing timer on stop Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 18/19] net: ethernet: cortina: Reject TX rings smaller than retained pointers Linus Walleij
2026-11-12 13:30 ` [PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads Linus Walleij
2026-11-16 14:45   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox