From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24868606A32C for ; Fri, 4 Dec 2026 20:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=gllDEA4S; dkim=pass (2048-bit key, unprotected) header.d=c127.dev header.i=@c127.dev header.a=rsa-sha256 header.s=purelymail1 header.b=RI9d6SNI; dkim=pass (2048-bit key, unprotected) header.d=purelymail.com header.i=@purelymail.com header.a=rsa-sha256 header.s=purelymail1 header.b=Lt7o98Pv DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=CGWNQLV2k5knOWoxUBPfLcnAP+AeUaRAMY2C2F5X2A0=; b=gllDEA4Say1xq4GLcogGwchs+X QvGeDIKZmYb4M7PKVyOEYLtr59zhTGkwJeYsDVSqyNMeRBK17mOrTcFfmFxPq243LtyvgN3DS3GOF GmJ26p9fzkmh/0FZp6xDjKiYRohLvWtIlmzi4rDtCWVuwMpj85wjT5nBr3hkeeJbYh9lE6AmP8x6C BeRVi45eOFnrwBxyNifjj0DnErgEk+rnNNnS4mfHsM2kimGaYnsgWHxYZB8x5DH6DrMViGkChcEju HzlGk1gpoi/0ByyCQ2C2bwhCUES+6+UO8Z+by6C1RfwjphYB7uuL2KQA1Bpr27rqEXOazlFmF2ptf x9Rhr+9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZZxG-00000001S2b-1T4p; Fri, 04 Dec 2026 20:32:30 +0000 Received: from sendmail.purelymail.com ([34.202.193.197]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZZx7-00000001RyJ-1LyZ for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 20:32:26 +0000 DKIM-Signature: a=rsa-sha256; b=RI9d6SNI62eTtJNnggXT1Me6pMwblR9ghQL+chMKCfolOkfUvKvnkojJdIGxwcVpQW3+t5hRGt2XqzHwnQs74snH+it3ys0hJbYZqHFlgpgMRS0DntCVxk5y887fGTLPX5+zbOypOFviZQQsT4Z7DlXGz1JIAMiQq8e+K4LrpvNMzQ2fcSARwSL8OxOfGhpOM3LTb2EhwFZ5mxDGU2axWWwFvYfwpIX6o4meqK9QB0aADqC5edhvPIXzkQ8wkxaqYIY+ZJgTsquor2EZIfjLNNX3Fb40Ox9MoAIaEgJABbYjGbUq7ZSZLJxzU3D7epp0LOAw9Wtdlc48x4U3Qd3Skw==; s=purelymail1; d=c127.dev; v=1; bh=Gb19VjtXrkmoUAkpm416BEW0S/zqROO93JVK+pCXXw0=; h=Received:From:To:Subject:Date:Message-ID; DKIM-Signature: a=rsa-sha256; b=Lt7o98PvO7zKSj235mZNRQm5bEZEA88d/kVG/2/So2n7KftIwj6dAqMCq1FoKIFML/zjAP3xSp6ju4UPxr8vCNxMyooTQm4g77ukTDmvyl/Fan/7pM7WtLD4dyQpb97UId93+5DwJedGKmDgrHwEjcq5kLfCqwZDwYPo7H1f46TJcueHQpmNpE5UuxTR7K7WrNr4OnMyy55zfZLUrwQzA3jOv0vGbuC9smqYBUJBEfu7GMx8+EHFt6zpXLo8z2n7ghn5vp5hwDxwS2CKkjD4pVqY0S5v4V2dZwf2jCro9bE4Jzp8/i1We64Wlpy2kgI8YnMkscyaEHW0ElY+1nIHMg==; s=purelymail1; d=purelymail.com; v=1; bh=Gb19VjtXrkmoUAkpm416BEW0S/zqROO93JVK+pCXXw0=; h=Feedback-ID:Received:From:To:Subject:Date:Message-ID; Feedback-ID: 1017243:43747:null:purelymail X-Pm-Original-To: linux-arm-kernel@lists.infradead.org Authentication-Results: purelymail.com; auth=pass Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -58822524; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Fri, 04 Dec 2026 20:31:44 +0000 (UTC) From: Johan Alvarado To: Jakub Kicinski , Paolo Abeni , Eric Dumazet , "David S . Miller" , Andrew Lunn , Maxime Chevallier , Yao Zi Cc: Maxime Coquelin , Alexandre Torgue , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Johan Alvarado , Pengfei Zhang Subject: [PATCH net-next 2/3] net: stmmac: add an opt-in MSI vector mask for NAPI Date: Fri, 4 Dec 2026 15:31:29 -0500 Message-ID: <20261204203130.287919-3-contact@c127.dev> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204203130.287919-1-contact@c127.dev> References: <20261204203130.287919-1-contact@c127.dev> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by Purelymail Content-Type: text/plain; charset=UTF-8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_123221_588408_03191E4E X-CRM114-Status: GOOD ( 15.51 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 With one MSI per DMA channel, stmmac masks the channel interrupt in DMA_CHAN_INTR_ENA during NAPI. On the YT6801, an RI or TI set while masked raises no interrupt on unmask. The event waits for an unrelated interrupt or the TX coalesce timer. Add STMMAC_FLAG_NAPI_MASK_MSI_VEC. When it and STMMAC_FLAG_MULTI_MSI_EN are set, the RX and TX MSI handlers disable their vector with disable_irq_nosync() and the poll enables it again. The DMA channel interrupt stays enabled, so the irq core resends events raised during the poll on enable_irq(). The vendor driver does the same. The channel records which vector it disabled, and a completing poll undoes only its own mask. The TX timer and the shared interrupt keep the DMA mask. stmmac_enable_all_dma_irq() and stmmac_enable_rx/tx_queue() re-enable a vector left disabled by napi_disable(). Freeing the interrupts clears the record. The resend uses irq_retrigger() or CONFIG_HARDIRQS_SW_RESEND, which arm64 and x86 select. Setting IRQ_DISABLE_UNLAZY instead would add two PCIe writes per NAPI cycle. The default is unchanged. The vector mask is untested on dwmac-intel and dwmac-loongson. Signed-off-by: Johan Alvarado --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 105 ++++++++++++++++-- include/linux/stmmac.h | 1 + 3 files changed, 101 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/eth= ernet/stmicro/stmmac/stmmac.h index fcc395321816..b3eb4b0d8491 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -146,6 +146,9 @@ struct stmmac_channel { =09struct stmmac_priv *priv_data; =09spinlock_t lock; =09u32 index; +=09/* RX/TX MSI vector disabled for NAPI, STMMAC_FLAG_NAPI_MASK_MSI_VEC */ +=09bool rx_vec_masked; +=09bool tx_vec_masked; }; =20 struct stmmac_fpe_cfg { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index b3524d46863d..b34942ad08ba 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2592,6 +2592,78 @@ static void stmmac_stop_tx_dma(struct stmmac_priv *p= riv, u32 chan) =09stmmac_stop_tx(priv, priv->ioaddr, chan); } =20 +/* Mask a channel interrupt for NAPI. With STMMAC_FLAG_NAPI_MASK_MSI_VEC + * and per-channel MSIs, the MSI vector is disabled instead of the DMA + * channel interrupt, so an event raised meanwhile is resent by the irq + * core (lazy disable) when the vector is enabled again. Called with + * ch->lock held. + */ +static void stmmac_napi_mask_irq(struct stmmac_priv *priv, u32 chan, +=09=09=09=09 u32 dir) +{ +=09struct stmmac_channel *ch =3D &priv->channel[chan]; + +=09if ((priv->plat->flags & STMMAC_FLAG_NAPI_MASK_MSI_VEC) && +=09 (priv->plat->flags & STMMAC_FLAG_MULTI_MSI_EN)) { +=09=09if (dir =3D=3D DMA_DIR_RX && !ch->rx_vec_masked) { +=09=09=09ch->rx_vec_masked =3D true; +=09=09=09disable_irq_nosync(priv->msi->rx_irq[chan]); +=09=09=09return; +=09=09} +=09=09if (dir =3D=3D DMA_DIR_TX && !ch->tx_vec_masked) { +=09=09=09ch->tx_vec_masked =3D true; +=09=09=09disable_irq_nosync(priv->msi->tx_irq[chan]); +=09=09=09return; +=09=09} +=09} + +=09stmmac_disable_dma_irq(priv, priv->ioaddr, chan, dir !=3D DMA_DIR_TX, +=09=09=09 dir !=3D DMA_DIR_RX); +} + +/* Enable the MSI vectors stmmac_napi_mask_irq() disabled for @rx/@tx and + * clear @rx/@tx for them. Called with ch->lock held. + */ +static void stmmac_napi_unmask_vec(struct stmmac_priv *priv, u32 chan, +=09=09=09=09 bool *rx, bool *tx) +{ +=09struct stmmac_channel *ch =3D &priv->channel[chan]; + +=09if (*rx && ch->rx_vec_masked) { +=09=09ch->rx_vec_masked =3D false; +=09=09enable_irq(priv->msi->rx_irq[chan]); +=09=09*rx =3D false; +=09} +=09if (*tx && ch->tx_vec_masked) { +=09=09ch->tx_vec_masked =3D false; +=09=09enable_irq(priv->msi->tx_irq[chan]); +=09=09*tx =3D false; +=09} +} + +/* Undo stmmac_napi_mask_irq() or a DMA mask from the other NAPI + * schedulers when a poll completes. Called with ch->lock held. + */ +static void stmmac_napi_unmask_irq(struct stmmac_priv *priv, u32 chan, +=09=09=09=09 bool rx, bool tx) +{ +=09stmmac_napi_unmask_vec(priv, chan, &rx, &tx); +=09if (rx || tx) +=09=09stmmac_enable_dma_irq(priv, priv->ioaddr, chan, rx, tx); +} + +/* Enable the channel interrupts when a queue (re)starts. A NAPI stopped + * by napi_disable() may have left its vector disabled. + */ +static void stmmac_start_chan_irq(struct stmmac_priv *priv, u32 chan, +=09=09=09=09 bool rx, bool tx) +{ +=09bool vrx =3D rx, vtx =3D tx; + +=09stmmac_napi_unmask_vec(priv, chan, &vrx, &vtx); +=09stmmac_enable_dma_irq(priv, priv->ioaddr, chan, rx, tx); +} + static void stmmac_enable_all_dma_irq(struct stmmac_priv *priv) { =09u8 rx_channels_count =3D priv->plat->rx_queues_to_use; @@ -2604,7 +2676,7 @@ static void stmmac_enable_all_dma_irq(struct stmmac_p= riv *priv) =09=09unsigned long flags; =20 =09=09spin_lock_irqsave(&ch->lock, flags); -=09=09stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 1, 1); +=09=09stmmac_start_chan_irq(priv, chan, true, true); =09=09spin_unlock_irqrestore(&ch->lock, flags); =09} } @@ -3179,7 +3251,11 @@ static int stmmac_napi_check(struct stmmac_priv *pri= v, u32 chan, u32 dir) =09if ((status & handle_rx) && (chan < priv->plat->rx_queues_to_use)) { =09=09if (napi_schedule_prep(rx_napi)) { =09=09=09spin_lock_irqsave(&ch->lock, flags); -=09=09=09stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 0); +=09=09=09if (dir =3D=3D DMA_DIR_RX) +=09=09=09=09stmmac_napi_mask_irq(priv, chan, dir); +=09=09=09else +=09=09=09=09stmmac_disable_dma_irq(priv, priv->ioaddr, chan, +=09=09=09=09=09=09 1, 0); =09=09=09spin_unlock_irqrestore(&ch->lock, flags); =09=09=09__napi_schedule(rx_napi); =09=09} @@ -3188,7 +3264,11 @@ static int stmmac_napi_check(struct stmmac_priv *pri= v, u32 chan, u32 dir) =09if ((status & handle_tx) && (chan < priv->plat->tx_queues_to_use)) { =09=09if (napi_schedule_prep(tx_napi)) { =09=09=09spin_lock_irqsave(&ch->lock, flags); -=09=09=09stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 0, 1); +=09=09=09if (dir =3D=3D DMA_DIR_TX) +=09=09=09=09stmmac_napi_mask_irq(priv, chan, dir); +=09=09=09else +=09=09=09=09stmmac_disable_dma_irq(priv, priv->ioaddr, chan, +=09=09=09=09=09=09 0, 1); =09=09=09spin_unlock_irqrestore(&ch->lock, flags); =09=09=09__napi_schedule(tx_napi); =09=09} @@ -3875,6 +3955,15 @@ static void stmmac_free_irq(struct net_device *dev, =09struct stmmac_msi *msi =3D priv->msi; =09int j; =20 +=09/* NAPI and the TX timers are stopped here, so no lock is needed. +=09 * With MULTI_MSI_EN the vectors are not shared, so request_irq() +=09 * sets their disable depth back to 0. +=09 */ +=09for (j =3D 0; j < ARRAY_SIZE(priv->channel); j++) { +=09=09priv->channel[j].rx_vec_masked =3D false; +=09=09priv->channel[j].tx_vec_masked =3D false; +=09} + =09switch (irq_err) { =09case REQ_IRQ_ERR_ALL: =09=09irq_idx =3D priv->plat->tx_queues_to_use; @@ -6217,7 +6306,7 @@ static int stmmac_napi_poll_rx(struct napi_struct *na= pi, int budget) =09=09unsigned long flags; =20 =09=09spin_lock_irqsave(&ch->lock, flags); -=09=09stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 1, 0); +=09=09stmmac_napi_unmask_irq(priv, chan, true, false); =09=09spin_unlock_irqrestore(&ch->lock, flags); =09} =20 @@ -6246,7 +6335,7 @@ static int stmmac_napi_poll_tx(struct napi_struct *na= pi, int budget) =09=09unsigned long flags; =20 =09=09spin_lock_irqsave(&ch->lock, flags); -=09=09stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 0, 1); +=09=09stmmac_napi_unmask_irq(priv, chan, false, true); =09=09spin_unlock_irqrestore(&ch->lock, flags); =09} =20 @@ -6299,7 +6388,7 @@ static int stmmac_napi_poll_rxtx(struct napi_struct *= napi, int budget) =09=09/* Both RX and TX work done are complete, =09=09 * so enable both RX & TX IRQs. =09=09 */ -=09=09stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 1, 1); +=09=09stmmac_napi_unmask_irq(priv, chan, true, true); =09=09spin_unlock_irqrestore(&ch->lock, flags); =09} =20 @@ -7303,7 +7392,7 @@ void stmmac_enable_rx_queue(struct stmmac_priv *priv,= u32 queue) =09stmmac_start_rx_dma(priv, queue); =20 =09spin_lock_irqsave(&ch->lock, flags); -=09stmmac_enable_dma_irq(priv, priv->ioaddr, queue, 1, 0); +=09stmmac_start_chan_irq(priv, queue, true, false); =09spin_unlock_irqrestore(&ch->lock, flags); } =20 @@ -7354,7 +7443,7 @@ void stmmac_enable_tx_queue(struct stmmac_priv *priv,= u32 queue) =09stmmac_start_tx_dma(priv, queue); =20 =09spin_lock_irqsave(&ch->lock, flags); -=09stmmac_enable_dma_irq(priv, priv->ioaddr, queue, 0, 1); +=09stmmac_start_chan_irq(priv, queue, false, true); =09spin_unlock_irqrestore(&ch->lock, flags); } =20 diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index 00be2df63d22..37e3f5c001b0 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -211,6 +211,7 @@ enum dwmac_core_type { #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY=09BIT(14) #define STMMAC_FLAG_KEEP_PREAMBLE_BEFORE_SFD=09BIT(15) #define STMMAC_FLAG_SERDES_SUPPORTS_2500M=09BIT(16) +#define STMMAC_FLAG_NAPI_MASK_MSI_VEC=09=09BIT(17) =20 struct mac_device_info; =20 --=20 2.56.1