From nobody Wed Apr 1 22:20:21 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8339E478E4A for ; Wed, 1 Apr 2026 16:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775061581; cv=none; b=D1fxy8p7OV1+5mPUW56yp7shOgg9+M92g19T2Zvr9o8Qk0Df9NLWQQPKi3zFLLSr5pfqIl+mcw5vny6eItn14mx1pkl5tfCoBLGX5IA4DH9JDoGx1+2r+IbvFCR8wnLZmR3HQd6zjia0AHpeRK0n1AZpPekvf4Ajb05r828F7+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775061581; c=relaxed/simple; bh=YP6CtUF9AL4yooz8CZtnf8bQL1uJ5a4WtdyvnKsuHT8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f4NleSBhkOXI8PbkzNku1PKh3bn3npBM5uRFYXhUo5GHwgNABcKyoOzNkuk9UxatLOoDhAvqQQVscWYRMjiTFgnPHoxTXrDFHfyx7pFOs58RKi7Qp7cDRGEIXaU9DFo2xRYaqK2cV0UbH+si+XExtCBkZTuNRMKpEVt5Sz76Eac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=T2eMdf8U; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="T2eMdf8U" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id C1F46C5996C; Wed, 1 Apr 2026 16:40:06 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id AEF10602BF; Wed, 1 Apr 2026 16:39:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4D661104507D9; Wed, 1 Apr 2026 18:39:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1775061574; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=0+PuJJPyolIoWacMBFDdkg6OvWsMTEUZdEigZZJOtyI=; b=T2eMdf8UA6kMo1dMR2i8CJydBOl46HuFTA9a7unpQeGbpkL5kswazb0c4ZBE1fBIEAJKjW DY9sMrCnEETVtc4YwVLc8JpNa26Ti/l3Um+Aod4nkzF4/Z5DgaHsNZVcJs3YwWKdbRhcPj CeigXU7P7cAqXqFEfPRsRFjm7HNdc2bH61WLIGkJEHPbZkjPIwfyPRPU2iDJ9h/17cNV1o sMhawq20xvHW37GJISpP1l2ffZRPx7VC5hItQHTO+Z+jwtnjogphTFxdtj+9WYA4MOTQ5e fOiLim58Pq6f9unBagr76K+198DGpVuNcfE/GDLK8ClStRGJtMOifVZCc1xQKg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 01 Apr 2026 18:39:08 +0200 Subject: [PATCH net-next 05/11] net: macb: allocate tieoff descriptor once across device lifetime Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260401-macb-context-v1-5-9590c5ab7272@bootlin.com> References: <20260401-macb-context-v1-0-9590c5ab7272@bootlin.com> In-Reply-To: <20260401-macb-context-v1-0-9590c5ab7272@bootlin.com> To: Nicolas Ferre , Claudiu Beznea , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Russell King Cc: Paolo Valerio , Conor Dooley , Nicolai Buchwitz , Vladimir Kondratiev , Gregory CLEMENT , =?utf-8?q?Beno=C3=AEt_Monin?= , Tawfik Bayouk , Thomas Petazzoni , Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.15.0 X-Last-TLS-Session-Version: TLSv1.3 The tieoff descriptor is a RX DMA descriptor ring of size one. It gets configured onto queues for Wake-on-LAN during system-wide suspend when hardware does not support disabling individual queues (MACB_CAPS_QUEUE_DISABLE). MACB/GEM driver allocates it alongside the main RX ring inside macb_alloc_consistent() at open. Free is done by macb_free_consistent() at close. Change to allocate once at probe and free on probe failure or device removal. This makes the tieoff descriptor lifetime much longer, avoiding repeating coherent buffer allocation on each open/close cycle. Main benefit: we dissociate its lifetime from the main ring's lifetime. That way there is less work to be doing on resources (re)alloc. This currently happens on close/open, but will soon also happen on context swap operations (set_ringparam, change_mtu, set_channels, etc). Signed-off-by: Th=C3=A9o Lebrun --- drivers/net/ethernet/cadence/macb_main.c | 70 ++++++++++++++++------------= ---- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index 081f220f6756..d5023fdc0756 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2679,12 +2679,6 @@ static void macb_free_consistent(struct macb *bp) unsigned int q; size_t size; =20 - if (bp->rx_ring_tieoff) { - dma_free_coherent(dev, macb_dma_desc_get_size(bp), - bp->rx_ring_tieoff, bp->rx_ring_tieoff_dma); - bp->rx_ring_tieoff =3D NULL; - } - bp->macbgem_ops.mog_free_rx_buffers(bp); =20 size =3D bp->num_queues * macb_tx_ring_size_per_queue(bp); @@ -2782,16 +2776,6 @@ static int macb_alloc_consistent(struct macb *bp) if (bp->macbgem_ops.mog_alloc_rx_buffers(bp)) goto out_err; =20 - /* Required for tie off descriptor for PM cases */ - if (!(bp->caps & MACB_CAPS_QUEUE_DISABLE)) { - bp->rx_ring_tieoff =3D dma_alloc_coherent(&bp->pdev->dev, - macb_dma_desc_get_size(bp), - &bp->rx_ring_tieoff_dma, - GFP_KERNEL); - if (!bp->rx_ring_tieoff) - goto out_err; - } - return 0; =20 out_err: @@ -2799,19 +2783,6 @@ static int macb_alloc_consistent(struct macb *bp) return -ENOMEM; } =20 -static void macb_init_tieoff(struct macb *bp) -{ - struct macb_dma_desc *desc =3D bp->rx_ring_tieoff; - - if (bp->caps & MACB_CAPS_QUEUE_DISABLE) - return; - /* Setup a wrapping descriptor with no free slots - * (WRAP and USED) to tie off/disable unused RX queues. - */ - macb_set_addr(bp, desc, MACB_BIT(RX_WRAP) | MACB_BIT(RX_USED)); - desc->ctrl =3D 0; -} - static void gem_init_rx_ring(struct macb_queue *queue) { queue->rx_tail =3D 0; @@ -2839,8 +2810,6 @@ static void gem_init_rings(struct macb *bp) =20 gem_init_rx_ring(queue); } - - macb_init_tieoff(bp); } =20 static void macb_init_rings(struct macb *bp) @@ -2858,8 +2827,6 @@ static void macb_init_rings(struct macb *bp) bp->queues[0].tx_head =3D 0; bp->queues[0].tx_tail =3D 0; desc->ctrl |=3D MACB_BIT(TX_WRAP); - - macb_init_tieoff(bp); } =20 static void macb_reset_hw(struct macb *bp) @@ -5530,6 +5497,33 @@ static int eyeq5_init(struct platform_device *pdev) return ret; } =20 +static int macb_alloc_tieoff(struct macb *bp) +{ + /* Tieoff is a workaround in case HW cannot disable queues, for PM. */ + if (bp->caps & MACB_CAPS_QUEUE_DISABLE) + return 0; + + bp->rx_ring_tieoff =3D dma_alloc_coherent(&bp->pdev->dev, + macb_dma_desc_get_size(bp), + &bp->rx_ring_tieoff_dma, + GFP_KERNEL); + if (!bp->rx_ring_tieoff) + return -ENOMEM; + + return 0; +} + +static void macb_free_tieoff(struct macb *bp) +{ + if (!bp->rx_ring_tieoff) + return; + + dma_free_coherent(&bp->pdev->dev, macb_dma_desc_get_size(bp), + bp->rx_ring_tieoff, + bp->rx_ring_tieoff_dma); + bp->rx_ring_tieoff =3D NULL; +} + static const struct macb_usrio_config at91_default_usrio =3D { .mii =3D MACB_BIT(MII), .rmii =3D MACB_BIT(RMII), @@ -5946,10 +5940,14 @@ static int macb_probe(struct platform_device *pdev) =20 netif_carrier_off(netdev); =20 + err =3D macb_alloc_tieoff(bp); + if (err) + goto err_out_unregister_mdio; + err =3D register_netdev(netdev); if (err) { dev_err(&pdev->dev, "Cannot register net device, aborting.\n"); - goto err_out_unregister_mdio; + goto err_out_free_tieoff; } =20 INIT_WORK(&bp->hresp_err_bh_work, macb_hresp_error_task); @@ -5963,6 +5961,9 @@ static int macb_probe(struct platform_device *pdev) =20 return 0; =20 +err_out_free_tieoff: + macb_free_tieoff(bp); + err_out_unregister_mdio: mdiobus_unregister(bp->mii_bus); mdiobus_free(bp->mii_bus); @@ -5992,6 +5993,7 @@ static void macb_remove(struct platform_device *pdev) if (netdev) { bp =3D netdev_priv(netdev); unregister_netdev(netdev); + macb_free_tieoff(bp); phy_exit(bp->phy); mdiobus_unregister(bp->mii_bus); mdiobus_free(bp->mii_bus); --=20 2.53.0