🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10548

[PATCH net-next v6 03/15] net: ethernet: cortina: Drain free queue IRQ before resize

#10548
From: Linus Walleij
Date: Tue, 03 Nov 2026 17:51
135 lines
12352 bytes
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 79c046364292..003108270d06 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -986,6 +986,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,
@@ -1026,20 +1028,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)
 {
@@ -1049,8 +1068,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();
@@ -1087,13 +1104,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)
@@ -1103,14 +1115,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;
 }
@@ -2373,6 +2381,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
Technical Details
Message-ID: <20261103-gemini-ethernet-fixes-3-v6-3-c4b5ff8a65d8@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355884-linux-kernel-netdev=dewy.ru
References: <20261103-gemini-ethernet-fixes-3-v6-0-c4b5ff8a65d8@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355884-linux-kernel-netdev=dewy.ru
From: linusw@kernel.org (Linus Walleij)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v6 03/15] net: ethernet: cortina: Drain free queue
 IRQ before resize
Date: Tue, 03 Nov 2026 18:51:14 +0100
Organization: Usenet Network
Message-ID: <20261103-gemini-ethernet-fixes-3-v6-3-c4b5ff8a65d8@kernel.org>
References: <20261103-gemini-ethernet-fixes-3-v6-0-c4b5ff8a65d8@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3224113"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:eZejmP4A3i9tEdTjqkL1NfbHj6c= sha256:SmayvyKYxm00Td/HemrbQ2pTepwkxY2KaIMEiSEhCOw=
	sha1:6ZZNLZUKbBO0S+Q9XZ45pJqej5I= sha256:3BiUD6SFwvaL2g3tQSvnujb+0/B38ZG6MPHNsV7bIqA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 55B80112980; Tue,  3 Nov 2026 20:52:07 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id BbqyN_38Eo76;
	Tue,  3 Nov 2026 20:52:04 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-355884-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id A4F73112956; Tue,  3 Nov 2026 20:51:56 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 6FE7A605D7A; Tue,  3 Nov 2026 17:51:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793728287;
	b=AQPIVy25avgjDzEk785aCiD4JeX8MDuRd3iGHgM75/J65SM37FFSgF8iLXno1vLFRLsn
	 aqpaGDBIUmXFbBXSV6pqzIfiVvfbRo5HrNt/y5b67vXv+US/vAwqNBTsL/XnuAtS/RSFN
	 iOH03SKjVS0OAHkll8Y2L4iouK+jMiuXtBVR2yuz2o+sq0SCyeMHQCsvCI2X2mUc3Fy3i
	 Fyi8CLd6/Fze+tGZHNL2ziXfdCgn+ihbmKR/ggpsvviIqZIc1yl6Ikvvk7vGozaZpdA5o
	 JY9FQJ5qGIcxzD3np0/rAZ0cXjtQiCfVotbUkXGu88OcMGCbYCN0N2S8Tf/weODmkmg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793728287;
	h=X-Original-To:Received:Received:DKIM-Signature:From:Date:Subject:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
	 X-Mailer;
	bh=sk0HzFlKhHff/S2BSJsJ/wZnzdUaYotaq8LbvBpO3eU=;
	b=hfuBln43OYwUr8nhPO91Nx0hsDKFHNKKQhhT9mXSXpL49Hih3rOyj9iruUAhtidPrEeM
	 tP1xQHiaCLW7ZE0GcMsnKhMI5P/w+RcFk/AfgEh6DJYL8ijYoXWusKaP03G54OCipolhI
	 Z42LIMrJzI00Sr2fQJC/AH/KipJ7Iv0EnpjAfTfMYnqoP5OvS8NApTVWHEQB0UpIhi8/J
	 8lEpu6VVnT14u0ILxFy8byPKKSnuNPkqVi541rtV4qpF83nSWSKZDksmw7hXwkOzM+E8s
	 QLHGGWA2Q4a0A2NobiWjS9R4EmX8ydRcJtM2qODXfoF0nsHvLZGqm9Bl8zYBmwvJi/g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AgSOwQls;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B26AB606A332;
	Tue,  3 Nov 2026 17:51:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AgSOwQls
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793728286;
	b=PZ/vYDFY3TVIigOvoWgvcAt3utxU9fhminLF52sC4GlMY/wc0oOrcHNkXipuMNo1ffIt
	 7cJ4kw7uI/Ywp4UKEMQrM2x9ua0ooT4wQGYP0nvjUKvBvpNEqwQ8LPq+xh3RTGkSVMihl
	 yBzrchpNVmal3YggrEd+ZZSE+U4sLoEYgNHBgj8XbAfGtGbT+BPkm/B7rozf+8JC534sw
	 N5WfFc4uyc7stkcF3CfcSiHNUTnYd55uBkEQ78eUdn3sk3hnyrjSTwTZ5q2s3NtzTRbhc
	 jwjhuXMLxKCKW0QkSYQ73fLbxqDlD4PrpF6qGdFCA+p29xiO1MkHjWk/t8mj/DFVZOA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793728286;
	h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
	 X-Mailer;
	bh=sk0HzFlKhHff/S2BSJsJ/wZnzdUaYotaq8LbvBpO3eU=;
	b=iNYRtxmbl3QMmfmp05DNC5lAjk5P0AkOaV5IazaOeVnp5oWEZwADZEwav9CTVjrhMaFL
	 sFaZRR1r08GNWqohnvF1unjS1rOCyOyNHosHtwckw/0nmuRSMBkyRgnU4lZCgsnuTZP/R
	 ZG/asGEz/KW7lj1/4EwMtHBKQwaI2y1z4k0oKpk4l0x57egmT06meL5NtXdt8xxedTCWU
	 lKA8hjEi6QNGVGEpxJ2NmgdNO5Gt5wTBmSSzXqi0sF2fhEHoT83MBsFMwtzKRw3EmsvOt
	 kcq62mglvviyu94iksHpp6Znz5HM8FU5Y7WzPpT2vmS6FWZr6Cp2MmARRbqGtLaN3GQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AgSOwQls;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93E36606A334
	for <netdev@vger.kernel.org>; Tue,  3 Nov 2026 17:51:26 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E80341F00919;
	Tue,  3 Nov 2026 17:51:23 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793728286;
	bh=sk0HzFlKhHff/S2BSJsJ/wZnzdUaYotaq8LbvBpO3eU=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=AgSOwQlsnMBnlqRK5fOuKX+TH0Pv25w8dQqhxIGA3Wx+NyRtnIvNtzYnV3a7+NfNI
	 VE3kmlCP8eM/tedoTPhrol+F5SwbGBHxUb/7Q9PR6kdlgth/cG6B0UZ0rY3rAxHNs9
	 MOLjXKqEVL+qDeIprW6YQNlht6ngqn8sj1GCJUR/03QgAIrJc6nepf0EELHOCvuO5Y
	 74FwmB5szSza9kr8OdpcguGxX21+YD0jbgCS0cyZfZO61nprA5zcR7crb5rDUA8VZK
	 ip2edKbF9iXLBTlE/DrIThqIwOsOyTPvzIcjTdqFfSj19dMB9wRpBIwRKw1euKs06o
	 W45f16SN1laKQ==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261103-gemini-ethernet-fixes-3-v6-0-c4b5ff8a65d8@kernel.org>
X-Cc: netdev@vger.kernel.org, Linus Walleij <linusw@kernel.org>
X-Mailer: b4 0.16.0