From nobody Sat Oct 4 03:15:46 2025 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 020FC3203B5; Wed, 20 Aug 2025 14:55:50 +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=1755701752; cv=none; b=nh2oV8ivS+9zbG+wyNqyKknf/HQ1JAhYPnsv5jAqmIzB/ZjpR9WpjycDL+SUCn2J/H5b/Wy2mz89kk7Vh09WhspQkeS357mlYOZM/g2m6LZrIFcqW2s0LzSJM7XAfVc71WgesihEYa5Su5hYQtdpe5tEfjkDhosHctN2o9PUvME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701752; c=relaxed/simple; bh=DGvp8XTAbNeIQIdK1hHPZKMKWnCqv1hyvU/+vQAFNb4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V/Zya6H8md9FTquBWEMmK0hZ78XbbX0LHtZdfqr4xBV3DMU6R68Cf5gDYJGokzfmXexhZlsQKMb56hbRMx1Z1PMR0j8mbqbNFC1kkHFShZVYdgatb/8WzUSut/+vXe3Updy+4mqRvXAw3hWx8sQnhNA6OBdvVWvkbVHEJollqNE= 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=I3jqBNGl; 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="I3jqBNGl" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id A8ABDC6B3A6; Wed, 20 Aug 2025 14:55:35 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 533E0606A0; Wed, 20 Aug 2025 14:55:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DCF1D1C22C74C; Wed, 20 Aug 2025 16:55:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1755701748; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=AccY9f1aSR6b7hyUSSVrdnIcUcn+hK4CKvMlg1bZh4Y=; b=I3jqBNGl4aI/AnqqHFxxPDrOM2AU6VjZ8Y7W5o/jL2pm4yetFcSdnuufWDgOi1DRcb8ejB 21hYPgfdZKsaxc82zUbixcy27a2zVNY0qn1QaWEKjmiQynTN3XyjPY/xhgB7S+kegLPk6q u1xZ0mBj0Ab3odoBjupC2jmmtZFb8vaeCe1/vZBLR0wB3/VtPpVD0h6xKLWwIH+xB8nNqN EvVJBNFA3Qo8uGORFrrcYzCUg1s81Kx2WPYJXbysabdR6PiKCqb0FTPhT7es0wjCCO2bkC S5aHXWoa0amU7g8cMhjxSfIHyujM0MtOpqJfpAYWo5wMJCBVItPOJhwrTieGGg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 20 Aug 2025 16:55:05 +0200 Subject: [PATCH net v4 1/5] dt-bindings: net: cdns,macb: allow tsu_clk without tx_clk 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: <20250820-macb-fixes-v4-1-23c399429164@bootlin.com> References: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> In-Reply-To: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Ferre , Claudiu Beznea , Geert Uytterhoeven , Harini Katakam , Richard Cochran , Russell King Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= , Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 Allow providing tsu_clk without a tx_clk as both are optional. This is about relaxing unneeded constraints. It so happened that in the past HW that needed a tsu_clk always needed a tx_clk. Fixes: 4e5b6de1f46d ("dt-bindings: net: cdns,macb: Convert to json-schema") Reviewed-by: Krzysztof Kozlowski Signed-off-by: Th=C3=A9o Lebrun Acked-by: Nicolas Ferre --- Documentation/devicetree/bindings/net/cdns,macb.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/net/cdns,macb.yaml b/Documen= tation/devicetree/bindings/net/cdns,macb.yaml index 559d0f733e7e7ac2909b87ab759be51d59be51c2..6e20d67e7628cd9dcef6e430b2a= 49eeedd0991a7 100644 --- a/Documentation/devicetree/bindings/net/cdns,macb.yaml +++ b/Documentation/devicetree/bindings/net/cdns,macb.yaml @@ -85,7 +85,7 @@ properties: items: - enum: [ ether_clk, hclk, pclk ] - enum: [ hclk, pclk ] - - const: tx_clk + - enum: [ tx_clk, tsu_clk ] - enum: [ rx_clk, tsu_clk ] - const: tsu_clk =20 --=20 2.50.1 From nobody Sat Oct 4 03:15:46 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 C334B321F4F; Wed, 20 Aug 2025 14:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701755; cv=none; b=aHxrk0e+J6iv9wdS65AS7ut48ptO7Jos8KAjFzNzgtFZr2hmpCFhDbHz1OZAaTZazLIUDGTVPwhkTjmZQp8nUDBMqdkD8elhYx3tuUurkJgZMF1v9q1MPNP9yRfSorA4ArESiNbFiLaSN/Nu/+J1+Cy0dQh59kfgD3/LKJuGdZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701755; c=relaxed/simple; bh=nFdYNmYaVP7xY8B5M9EfwLVyf/HpuiOfR234JcCTn/I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PWkWUolJh4wlvgMWKVU0GoATU8BUC4Ir9HEJqJVZxZZGnXgnoUdAuRDqKvQZjxvNNenwelHdLHJpJ0IFm6hMS30DEE9QO3PqTVTOjQ3fd+Q65KMX1g/QEllLqUiAdldhDPAfN+uRIT8qEAuFKwJ6T/3D6Da88t0NBz9qJvR3+cc= 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=gavRSegl; arc=none smtp.client-ip=185.246.84.56 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="gavRSegl" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 5E2EF1A0D4F; Wed, 20 Aug 2025 14:55:52 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 35F2F606A0; Wed, 20 Aug 2025 14:55:52 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 927BB1C22C54F; Wed, 20 Aug 2025 16:55:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1755701751; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=k8o7htJcB+PWfJpR0G3Ao2g5DXgHwDZ9wOdSNlZxp+A=; b=gavRSegln3rIrSUfgArRvy8QCVjiqGfa7CuRo+L79gSBPCVZSN7XhhNs0zn4/XP9EBnaLp B3/5n/Wy/Q4bdiwwPv6sHxPUiCjhKgFkHwd7lUr8svCL+y8JOTRYGd22IhK57Dq245lwrg B2iU+AaPP1pbucCDG7X3xq3E5p6ogM2L6qzA0hAEbp+ydWQLoBeB05NP5SFddBw+eEn+P1 +S9QCLINzCsTKfhY7LucEMY1uqDm8YEolvQ8HA9QHI3eSbBAHoDMF8JDM+Rot1cddxbxhp 63CmbfN0qgnFlEid5W6vxWdCjUomBi1Z6rDPFjZjNbk85FX1dsnyRW0TDVb5vg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 20 Aug 2025 16:55:06 +0200 Subject: [PATCH net v4 2/5] net: macb: remove illusion about TBQPH/RBQPH being per-queue 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: <20250820-macb-fixes-v4-2-23c399429164@bootlin.com> References: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> In-Reply-To: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Ferre , Claudiu Beznea , Geert Uytterhoeven , Harini Katakam , Richard Cochran , Russell King Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= , Sean Anderson X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 The MACB driver acts as if TBQPH/RBQPH are configurable on a per queue basis; this is a lie. A single register configures the upper 32 bits of each DMA descriptor buffers for all queues. Concrete actions: - Drop GEM_TBQPH/GEM_RBQPH macros which have a queue index argument. Only use MACB_TBQPH/MACB_RBQPH constants. - Drop struct macb_queue->TBQPH/RBQPH fields. - In macb_init_buffers(): do a single write to TBQPH and RBQPH for all queues instead of a write per queue. - In macb_tx_error_task(): drop the write to TBQPH. - In macb_alloc_consistent(): if allocations give different upper 32-bits, fail. Previously, it would have lead to silent memory corruption as queues would have used the upper 32 bits of the alloc from queue 0 and their own low 32 bits. - In macb_suspend(): if we use the tie off descriptor for suspend, do the write once for all queues instead of once per queue. Fixes: fff8019a08b6 ("net: macb: Add 64 bit addressing support for GEM") Fixes: ae1f2a56d273 ("net: macb: Added support for many RX queues") Reviewed-by: Sean Anderson Signed-off-by: Th=C3=A9o Lebrun Acked-by: Nicolas Ferre --- drivers/net/ethernet/cadence/macb.h | 4 --- drivers/net/ethernet/cadence/macb_main.c | 57 ++++++++++++++--------------= ---- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cad= ence/macb.h index c9a5c8beb2fa8166195d1d83f187d2d0c62668a8..a7e845fee4b3a2e3d14abb49abd= baf3e8e6ea02b 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -213,10 +213,8 @@ =20 #define GEM_ISR(hw_q) (0x0400 + ((hw_q) << 2)) #define GEM_TBQP(hw_q) (0x0440 + ((hw_q) << 2)) -#define GEM_TBQPH(hw_q) (0x04C8) #define GEM_RBQP(hw_q) (0x0480 + ((hw_q) << 2)) #define GEM_RBQS(hw_q) (0x04A0 + ((hw_q) << 2)) -#define GEM_RBQPH(hw_q) (0x04D4) #define GEM_IER(hw_q) (0x0600 + ((hw_q) << 2)) #define GEM_IDR(hw_q) (0x0620 + ((hw_q) << 2)) #define GEM_IMR(hw_q) (0x0640 + ((hw_q) << 2)) @@ -1214,10 +1212,8 @@ struct macb_queue { unsigned int IDR; unsigned int IMR; unsigned int TBQP; - unsigned int TBQPH; unsigned int RBQS; unsigned int RBQP; - unsigned int RBQPH; =20 /* Lock to protect tx_head and tx_tail */ spinlock_t tx_ptr_lock; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index ce95fad8cedd7331d4818ba9f73fb6970249e85c..69325665c766927797ca2e1eb13= 84105bcde3cb5 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -495,19 +495,19 @@ static void macb_init_buffers(struct macb *bp) struct macb_queue *queue; unsigned int q; =20 +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT + /* Single register for all queues' high 32 bits. */ + if (bp->hw_dma_cap & HW_DMA_CAP_64B) { + macb_writel(bp, RBQPH, + upper_32_bits(bp->queues[0].rx_ring_dma)); + macb_writel(bp, TBQPH, + upper_32_bits(bp->queues[0].tx_ring_dma)); + } +#endif + for (q =3D 0, queue =3D bp->queues; q < bp->num_queues; ++q, ++queue) { queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma)); -#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT - if (bp->hw_dma_cap & HW_DMA_CAP_64B) - queue_writel(queue, RBQPH, - upper_32_bits(queue->rx_ring_dma)); -#endif queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma)); -#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT - if (bp->hw_dma_cap & HW_DMA_CAP_64B) - queue_writel(queue, TBQPH, - upper_32_bits(queue->tx_ring_dma)); -#endif } } =20 @@ -1166,10 +1166,6 @@ static void macb_tx_error_task(struct work_struct *w= ork) =20 /* Reinitialize the TX desc queue */ queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma)); -#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT - if (bp->hw_dma_cap & HW_DMA_CAP_64B) - queue_writel(queue, TBQPH, upper_32_bits(queue->tx_ring_dma)); -#endif /* Make TX ring reflect state of hardware */ queue->tx_head =3D 0; queue->tx_tail =3D 0; @@ -2542,6 +2538,7 @@ static int macb_alloc_consistent(struct macb *bp) { struct macb_queue *queue; unsigned int q; + u32 upper; int size; =20 for (q =3D 0, queue =3D bp->queues; q < bp->num_queues; ++q, ++queue) { @@ -2549,7 +2546,9 @@ static int macb_alloc_consistent(struct macb *bp) queue->tx_ring =3D dma_alloc_coherent(&bp->pdev->dev, size, &queue->tx_ring_dma, GFP_KERNEL); - if (!queue->tx_ring) + upper =3D upper_32_bits(queue->tx_ring_dma); + if (!queue->tx_ring || + upper !=3D upper_32_bits(bp->queues[0].tx_ring_dma)) goto out_err; netdev_dbg(bp->dev, "Allocated TX ring for queue %u of %d bytes at %08lx (mapped %p)\n", @@ -2563,8 +2562,11 @@ static int macb_alloc_consistent(struct macb *bp) =20 size =3D RX_RING_BYTES(bp) + bp->rx_bd_rd_prefetch; queue->rx_ring =3D dma_alloc_coherent(&bp->pdev->dev, size, - &queue->rx_ring_dma, GFP_KERNEL); - if (!queue->rx_ring) + &queue->rx_ring_dma, + GFP_KERNEL); + upper =3D upper_32_bits(queue->rx_ring_dma); + if (!queue->rx_ring || + upper !=3D upper_32_bits(bp->queues[0].rx_ring_dma)) goto out_err; netdev_dbg(bp->dev, "Allocated RX ring of %d bytes at %08lx (mapped %p)\n", @@ -4305,12 +4307,6 @@ static int macb_init(struct platform_device *pdev) queue->TBQP =3D GEM_TBQP(hw_q - 1); queue->RBQP =3D GEM_RBQP(hw_q - 1); queue->RBQS =3D GEM_RBQS(hw_q - 1); -#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT - if (bp->hw_dma_cap & HW_DMA_CAP_64B) { - queue->TBQPH =3D GEM_TBQPH(hw_q - 1); - queue->RBQPH =3D GEM_RBQPH(hw_q - 1); - } -#endif } else { /* queue0 uses legacy registers */ queue->ISR =3D MACB_ISR; @@ -4319,12 +4315,6 @@ static int macb_init(struct platform_device *pdev) queue->IMR =3D MACB_IMR; queue->TBQP =3D MACB_TBQP; queue->RBQP =3D MACB_RBQP; -#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT - if (bp->hw_dma_cap & HW_DMA_CAP_64B) { - queue->TBQPH =3D MACB_TBQPH; - queue->RBQPH =3D MACB_RBQPH; - } -#endif } =20 /* get irq: here we use the linux queue index, not the hardware @@ -5450,6 +5440,11 @@ static int __maybe_unused macb_suspend(struct device= *dev) */ tmp =3D macb_readl(bp, NCR); macb_writel(bp, NCR, tmp & ~(MACB_BIT(TE) | MACB_BIT(RE))); +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT + if (!(bp->caps & MACB_CAPS_QUEUE_DISABLE)) + macb_writel(bp, RBQPH, + upper_32_bits(bp->rx_ring_tieoff_dma)); +#endif for (q =3D 0, queue =3D bp->queues; q < bp->num_queues; ++q, ++queue) { /* Disable RX queues */ @@ -5459,10 +5454,6 @@ static int __maybe_unused macb_suspend(struct device= *dev) /* Tie off RX queues */ queue_writel(queue, RBQP, lower_32_bits(bp->rx_ring_tieoff_dma)); -#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT - queue_writel(queue, RBQPH, - upper_32_bits(bp->rx_ring_tieoff_dma)); -#endif } /* Disable all interrupts */ queue_writel(queue, IDR, -1); --=20 2.50.1 From nobody Sat Oct 4 03:15:46 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 B99833203B5 for ; Wed, 20 Aug 2025 14:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701757; cv=none; b=OMwU5AcwQH+PKAlEDjW1yit1BbTVudhxYBcFkiVudt6D9a46KYe991qZMKUYXwrI9lHJ4ejiUuLWdJ+WBJ6Jt7Ew6SoQ+Y26NBREsHNFg5eyGej2t2KAtGNG+qOuDbZDtWIDsxFkYmn+mUcwelAEIEwHiEY3vK0mei3OuWTIkFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701757; c=relaxed/simple; bh=bMlWjWqjobDxiLBWkDzWIzpY1xcGuH1rFnWv9puwpSM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DHL2Aii9qq6RvPbyZ0CTeV4GuoBMoi5EeBeE6zPNmBh2bC+y2qczqtyEzze9pDaNoBQt/Zw+BMewkKj2buJ4K6K03GsLC6H3mqddziYV/URMYCecyULWcla1qxqt/wYLbB8hga9uoruwOQVgIVVTpx/2ayUAHiJLXolTdVC3msE= 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=IVLMptdK; arc=none smtp.client-ip=185.246.85.4 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="IVLMptdK" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 755E84E40C58; Wed, 20 Aug 2025 14:55:54 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4E68B606A0; Wed, 20 Aug 2025 14:55:54 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 614FC1C22862A; Wed, 20 Aug 2025 16:55:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1755701753; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=sjEQkGkfGGmFcD/QqK94etV1EzeES0FgbJFhn32rCEE=; b=IVLMptdKEOmov+bMCCnRSjJXk630u9DdKbBvJQUlUnOFB6kGn0ocedvQuzuq5jpPlY6XjA /RrcqyIsXq4FPB0sbhyqPSUGNAGoK/5mRKy8cc5lZA+iGoesDMx9JQF9dB0SAku0VE3i/B RbdMhQy8Nuq6/jziHHSlOB10GzmnFo/8KtyNIlzVQ+tfj1S49cdSt2uhB6RBqVY0ixvI71 yN0EBIQeYUiMgQseZXRN6aUkCmGymNKn15kn5bOVLHYzAcnflG+69fjRqz0oeFyIPe/XVD WBdGwUboQwFqfla72A5K1aser+yp7MZrPO3jR1wR6UwjCXWp6IiV7uLA2HgVrg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 20 Aug 2025 16:55:07 +0200 Subject: [PATCH net v4 3/5] net: macb: move ring size computation to functions 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: <20250820-macb-fixes-v4-3-23c399429164@bootlin.com> References: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> In-Reply-To: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Ferre , Claudiu Beznea , Geert Uytterhoeven , Harini Katakam , Richard Cochran , Russell King Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 The tx/rx ring size calculation is somewhat complex and partially hidden behind a macro. Move that out of the {RX,TX}_RING_BYTES() macros and macb_{alloc,free}_consistent() functions into neat separate functions. In macb_free_consistent(), we drop the size variable and directly call the size helpers in the arguments list. In macb_alloc_consistent(), we keep the size variable that is used by netdev_dbg() calls. Signed-off-by: Th=C3=A9o Lebrun Acked-by: Nicolas Ferre --- drivers/net/ethernet/cadence/macb_main.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index 69325665c766927797ca2e1eb1384105bcde3cb5..d413e8bd4977187fd73f7cc4826= 8baf933aab051 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -51,14 +51,10 @@ struct sifive_fu540_macb_mgmt { #define DEFAULT_RX_RING_SIZE 512 /* must be power of 2 */ #define MIN_RX_RING_SIZE 64 #define MAX_RX_RING_SIZE 8192 -#define RX_RING_BYTES(bp) (macb_dma_desc_get_size(bp) \ - * (bp)->rx_ring_size) =20 #define DEFAULT_TX_RING_SIZE 512 /* must be power of 2 */ #define MIN_TX_RING_SIZE 64 #define MAX_TX_RING_SIZE 4096 -#define TX_RING_BYTES(bp) (macb_dma_desc_get_size(bp) \ - * (bp)->tx_ring_size) =20 /* level of occupied TX descriptors under which we wake up TX process */ #define MACB_TX_WAKEUP_THRESH(bp) (3 * (bp)->tx_ring_size / 4) @@ -2466,11 +2462,20 @@ static void macb_free_rx_buffers(struct macb *bp) } } =20 +static unsigned int macb_tx_ring_size_per_queue(struct macb *bp) +{ + return macb_dma_desc_get_size(bp) * bp->tx_ring_size + bp->tx_bd_rd_prefe= tch; +} + +static unsigned int macb_rx_ring_size_per_queue(struct macb *bp) +{ + return macb_dma_desc_get_size(bp) * bp->rx_ring_size + bp->rx_bd_rd_prefe= tch; +} + static void macb_free_consistent(struct macb *bp) { struct macb_queue *queue; unsigned int q; - int size; =20 if (bp->rx_ring_tieoff) { dma_free_coherent(&bp->pdev->dev, macb_dma_desc_get_size(bp), @@ -2484,14 +2489,14 @@ static void macb_free_consistent(struct macb *bp) kfree(queue->tx_skb); queue->tx_skb =3D NULL; if (queue->tx_ring) { - size =3D TX_RING_BYTES(bp) + bp->tx_bd_rd_prefetch; - dma_free_coherent(&bp->pdev->dev, size, + dma_free_coherent(&bp->pdev->dev, + macb_tx_ring_size_per_queue(bp), queue->tx_ring, queue->tx_ring_dma); queue->tx_ring =3D NULL; } if (queue->rx_ring) { - size =3D RX_RING_BYTES(bp) + bp->rx_bd_rd_prefetch; - dma_free_coherent(&bp->pdev->dev, size, + dma_free_coherent(&bp->pdev->dev, + macb_rx_ring_size_per_queue(bp), queue->rx_ring, queue->rx_ring_dma); queue->rx_ring =3D NULL; } @@ -2542,7 +2547,7 @@ static int macb_alloc_consistent(struct macb *bp) int size; =20 for (q =3D 0, queue =3D bp->queues; q < bp->num_queues; ++q, ++queue) { - size =3D TX_RING_BYTES(bp) + bp->tx_bd_rd_prefetch; + size =3D macb_tx_ring_size_per_queue(bp); queue->tx_ring =3D dma_alloc_coherent(&bp->pdev->dev, size, &queue->tx_ring_dma, GFP_KERNEL); @@ -2560,7 +2565,7 @@ static int macb_alloc_consistent(struct macb *bp) if (!queue->tx_skb) goto out_err; =20 - size =3D RX_RING_BYTES(bp) + bp->rx_bd_rd_prefetch; + size =3D macb_rx_ring_size_per_queue(bp); queue->rx_ring =3D dma_alloc_coherent(&bp->pdev->dev, size, &queue->rx_ring_dma, GFP_KERNEL); --=20 2.50.1 From nobody Sat Oct 4 03:15:46 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 6A17232276A for ; Wed, 20 Aug 2025 14:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701760; cv=none; b=ZMvG80EbHt5cSqyF36teU/YeR+0xb/GcBO70d1KPIy4eBLbvNJwnowOp1uYGCTQhsjs+2Kj8h5oOa321zT/rcABNCS0sXKgw8qooCR+4ymAF2H+w6qPdryW5WvLRu5Op8bP3UGVwSUcxNQ5xGd+D77WAbdpZf+cMLkoA+wbRfrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701760; c=relaxed/simple; bh=pMwgAM3mK5HlmmxttB23AV1CD/3qDJooqvU4uXnUwkY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B8POIteDRbc0k6GEVcxEPs86PMyDgEJgZtQZFDBiTb0JS90SMt8ye/XS0jmbGX5b0RuLIgFMxV0OvXk9qBEvm94yJFdJEhagEug8azV3iewGqVMnlvQqaMlaoB+EqlTlg9COqMXqjN6OOQXH+r6ekg9tkBckVBpGYZjJ0DD9Svw= 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=k6XoDNOU; arc=none smtp.client-ip=185.246.84.56 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="k6XoDNOU" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 0190C1A0D52; Wed, 20 Aug 2025 14:55:57 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id CE342606A0; Wed, 20 Aug 2025 14:55:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 987881C2286DB; Wed, 20 Aug 2025 16:55:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1755701755; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=nsFJ9znWtVRJWAKG3cXq6r3YWRygtCDg6ibIfdm4SIQ=; b=k6XoDNOUERVc/EQIdXEPBkmilI1zOHaT5huoe3p903ePzH93Z6H7rbwiXLRvm211gJDddw Q3MeJmctVJtBCIdQiMJIESGecqDJuPGvUmigra4RMCjm/mlCYAXjz36N5WlD02gdrJ4lbe rL16tMs3pLBuE4JgCobOuF6paXLpCji/8DVzvdgry+65+MUpssMj0lHTc+DCKhFakuhhNl L5kfGTssD+0hbzs6OqUD+RPg5woC4K6mDLdI6vPXPHC3Tuz1VFAlJSXWym6Ft83d7tgVJG dD44fT5TNoyR5Mq8713RaeW9D/A6OuTkaoXSTnREvvK8B9D56Ak/zAYpZ2dEZw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 20 Aug 2025 16:55:08 +0200 Subject: [PATCH net v4 4/5] net: macb: single dma_alloc_coherent() for DMA descriptors 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: <20250820-macb-fixes-v4-4-23c399429164@bootlin.com> References: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> In-Reply-To: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Ferre , Claudiu Beznea , Geert Uytterhoeven , Harini Katakam , Richard Cochran , Russell King Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= , Sean Anderson X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 Move from 2*NUM_QUEUES dma_alloc_coherent() for DMA descriptor rings to 2 calls overall. Issue is with how all queues share the same register for configuring the upper 32-bits of Tx/Rx descriptor rings. Taking Tx, notice how TBQPH does *not* depend on the queue index: #define GEM_TBQP(hw_q) (0x0440 + ((hw_q) << 2)) #define GEM_TBQPH(hw_q) (0x04C8) queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma)); #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT if (bp->hw_dma_cap & HW_DMA_CAP_64B) queue_writel(queue, TBQPH, upper_32_bits(queue->tx_ring_dma)); #endif To maximise our chances of getting valid DMA addresses, we do a single dma_alloc_coherent() across queues. This improves the odds because alloc_pages() guarantees natural alignment. Other codepaths (IOMMU or dev/arch dma_map_ops) don't give high enough guarantees (even page-aligned isn't enough). Two consideration: - dma_alloc_coherent() gives us page alignment. Here we remove this constraint meaning each queue's ring won't be page-aligned anymore. - This can save some tiny amounts of memory. Fewer allocations means (1) less overhead (constant cost per alloc) and (2) less wasted bytes due to alignment constraints. Example for (2): 4 queues, default ring size (512), 64-bit DMA descriptors, 16K pages: - Before: 8 allocs of 8K, each rounded to 16K =3D> 64K wasted. - After: 2 allocs of 32K =3D> 0K wasted. Fixes: 02c958dd3446 ("net/macb: add TX multiqueue support for gem") Reviewed-by: Sean Anderson Signed-off-by: Th=C3=A9o Lebrun Acked-by: Nicolas Ferre Tested-by: Nicolas Ferre # on sam9x75 --- drivers/net/ethernet/cadence/macb_main.c | 80 ++++++++++++++++------------= ---- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index d413e8bd4977187fd73f7cc48268baf933aab051..7f31f264a6d342ea01e2f61944b= 12c9b9a3fe66e 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2474,32 +2474,30 @@ static unsigned int macb_rx_ring_size_per_queue(str= uct macb *bp) =20 static void macb_free_consistent(struct macb *bp) { + struct device *dev =3D &bp->pdev->dev; struct macb_queue *queue; unsigned int q; + size_t size; =20 if (bp->rx_ring_tieoff) { - dma_free_coherent(&bp->pdev->dev, macb_dma_desc_get_size(bp), + 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; } =20 bp->macbgem_ops.mog_free_rx_buffers(bp); =20 + size =3D bp->num_queues * macb_tx_ring_size_per_queue(bp); + dma_free_coherent(dev, size, bp->queues[0].tx_ring, bp->queues[0].tx_ring= _dma); + + size =3D bp->num_queues * macb_rx_ring_size_per_queue(bp); + dma_free_coherent(dev, size, bp->queues[0].rx_ring, bp->queues[0].rx_ring= _dma); + for (q =3D 0, queue =3D bp->queues; q < bp->num_queues; ++q, ++queue) { kfree(queue->tx_skb); queue->tx_skb =3D NULL; - if (queue->tx_ring) { - dma_free_coherent(&bp->pdev->dev, - macb_tx_ring_size_per_queue(bp), - queue->tx_ring, queue->tx_ring_dma); - queue->tx_ring =3D NULL; - } - if (queue->rx_ring) { - dma_free_coherent(&bp->pdev->dev, - macb_rx_ring_size_per_queue(bp), - queue->rx_ring, queue->rx_ring_dma); - queue->rx_ring =3D NULL; - } + queue->tx_ring =3D NULL; + queue->rx_ring =3D NULL; } } =20 @@ -2541,41 +2539,45 @@ static int macb_alloc_rx_buffers(struct macb *bp) =20 static int macb_alloc_consistent(struct macb *bp) { + struct device *dev =3D &bp->pdev->dev; + dma_addr_t tx_dma, rx_dma; struct macb_queue *queue; unsigned int q; - u32 upper; - int size; + void *tx, *rx; + size_t size; + + /* + * Upper 32-bits of Tx/Rx DMA descriptor for each queues much match! + * We cannot enforce this guarantee, the best we can do is do a single + * allocation and hope it will land into alloc_pages() that guarantees + * natural alignment of physical addresses. + */ + + size =3D bp->num_queues * macb_tx_ring_size_per_queue(bp); + tx =3D dma_alloc_coherent(dev, size, &tx_dma, GFP_KERNEL); + if (!tx || upper_32_bits(tx_dma) !=3D upper_32_bits(tx_dma + size - 1)) + goto out_err; + netdev_dbg(bp->dev, "Allocated %zu bytes for %u TX rings at %08lx (mapped= %p)\n", + size, bp->num_queues, (unsigned long)tx_dma, tx); + + size =3D bp->num_queues * macb_rx_ring_size_per_queue(bp); + rx =3D dma_alloc_coherent(dev, size, &rx_dma, GFP_KERNEL); + if (!rx || upper_32_bits(rx_dma) !=3D upper_32_bits(rx_dma + size - 1)) + goto out_err; + netdev_dbg(bp->dev, "Allocated %zu bytes for %u RX rings at %08lx (mapped= %p)\n", + size, bp->num_queues, (unsigned long)rx_dma, rx); =20 for (q =3D 0, queue =3D bp->queues; q < bp->num_queues; ++q, ++queue) { - size =3D macb_tx_ring_size_per_queue(bp); - queue->tx_ring =3D dma_alloc_coherent(&bp->pdev->dev, size, - &queue->tx_ring_dma, - GFP_KERNEL); - upper =3D upper_32_bits(queue->tx_ring_dma); - if (!queue->tx_ring || - upper !=3D upper_32_bits(bp->queues[0].tx_ring_dma)) - goto out_err; - netdev_dbg(bp->dev, - "Allocated TX ring for queue %u of %d bytes at %08lx (mapped %p)\n", - q, size, (unsigned long)queue->tx_ring_dma, - queue->tx_ring); + queue->tx_ring =3D tx + macb_tx_ring_size_per_queue(bp) * q; + queue->tx_ring_dma =3D tx_dma + macb_tx_ring_size_per_queue(bp) * q; + + queue->rx_ring =3D rx + macb_rx_ring_size_per_queue(bp) * q; + queue->rx_ring_dma =3D rx_dma + macb_rx_ring_size_per_queue(bp) * q; =20 size =3D bp->tx_ring_size * sizeof(struct macb_tx_skb); queue->tx_skb =3D kmalloc(size, GFP_KERNEL); if (!queue->tx_skb) goto out_err; - - size =3D macb_rx_ring_size_per_queue(bp); - queue->rx_ring =3D dma_alloc_coherent(&bp->pdev->dev, size, - &queue->rx_ring_dma, - GFP_KERNEL); - upper =3D upper_32_bits(queue->rx_ring_dma); - if (!queue->rx_ring || - upper !=3D upper_32_bits(bp->queues[0].rx_ring_dma)) - goto out_err; - netdev_dbg(bp->dev, - "Allocated RX ring of %d bytes at %08lx (mapped %p)\n", - size, (unsigned long)queue->rx_ring_dma, queue->rx_ring); } if (bp->macbgem_ops.mog_alloc_rx_buffers(bp)) goto out_err; --=20 2.50.1 From nobody Sat Oct 4 03:15:46 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 D8EBC322A22; Wed, 20 Aug 2025 14:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701762; cv=none; b=s1t+B7+UidbWCrv00WFNpijgt6NEDJFgrtsbNS7dbmFrHlVCMWFhK1yq4/7CfTZ6kE9huM2FUKeCJZS3w4aupohnLBU7zo9BddMK60ELOOxBObTELwXc+q18cDIz9iraYMfTTjcivbmCTOEM9bYd2ar9n00aJzhA5jdOObgMEU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755701762; c=relaxed/simple; bh=FnC+p/sUSZ/8vypJY90CDETgjSq0rMg4Fj0Db5/cyk4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tJByTPB6bP2RU0Z7xmgDL4nxFF1CjZDfGkJJfIrqmYGQUXfPQtotLuuqgMJBOowq5mkmoTgkp/03p9B014goO84h+D1Ec8XW76WgEtmo0QAZubeZzhVqkC/ZmMjL1srP+7lTSvdd0aR1B9ZGX8XzU0B4u5doBt/sIDiYuvLbasc= 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=sEAKzLHg; arc=none smtp.client-ip=185.246.84.56 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="sEAKzLHg" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 904B21A0D5D; Wed, 20 Aug 2025 14:55:59 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 68B75606A0; Wed, 20 Aug 2025 14:55:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 30F841C22C74C; Wed, 20 Aug 2025 16:55:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1755701758; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=I8FcTJYmvlUFZA4Oe3duQag7ifxxlbPmqhzgDbiK/Sw=; b=sEAKzLHgMzI2aggcBjUCOnaVGFJs5Ula33FZzNZuDTacfbYeMncsSRgjkb+xX02xF6MDhB Ad5DLw1nbLhezr8ONWHfZHOlQBCqoLQAb74r/2NGdtqELH72kCzVfd8WjtSflMC8aleOdy S9+kqiSm+QyF2I1Il2WzoBybXLSZmidLqkI/MBnAH26BwzwxVrOMdRCAeVQNY7T91i/UhP nOjATVBWSD6JFtDleLZ/k4LRofeReJ0yHA/OK9kDMMGHyd4GuhsqO2zjCqnFJjjIzucVo5 LPlkmtYgm0v/u04PoAt4h9Yv3/PZ26gsv97fUGwV32XHlhAcUjssh8wYJOMaTg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 20 Aug 2025 16:55:09 +0200 Subject: [PATCH net v4 5/5] net: macb: avoid double endianness swap in macb_set_hwaddr() 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: <20250820-macb-fixes-v4-5-23c399429164@bootlin.com> References: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> In-Reply-To: <20250820-macb-fixes-v4-0-23c399429164@bootlin.com> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nicolas Ferre , Claudiu Beznea , Geert Uytterhoeven , Harini Katakam , Richard Cochran , Russell King Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= , Sean Anderson X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 writel() does a CPU->LE conversion. Drop manual cpu_to_le*() calls. On little-endian system: - cpu_to_le32() is a no-op (LE->LE), - writel() is a no-op (LE->LE), - dev_addr will therefore not be swapped and written as-is. On big-endian system: - cpu_to_le32() is a swap (BE->LE), - writel() is a swap (BE->LE), - dev_addr will therefore be swapped twice and written as a BE value. This was found using sparse: =E2=9F=A9 make C=3D2 drivers/net/ethernet/cadence/macb_main.o warning: incorrect type in assignment (different base types) expected unsigned int [usertype] bottom got restricted __le32 [usertype] warning: incorrect type in assignment (different base types) expected unsigned short [usertype] top got restricted __le16 [usertype] ... Fixes: 89e5785fc8a6 ("[PATCH] Atmel MACB ethernet driver") Reviewed-by: Sean Anderson Signed-off-by: Th=C3=A9o Lebrun --- drivers/net/ethernet/cadence/macb_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index 7f31f264a6d342ea01e2f61944b12c9b9a3fe66e..fe319d77f2a8f6b1f3b698e0d11= 781936345ea8f 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -274,9 +274,9 @@ static void macb_set_hwaddr(struct macb *bp) u32 bottom; u16 top; =20 - bottom =3D cpu_to_le32(*((u32 *)bp->dev->dev_addr)); + bottom =3D *((u32 *)bp->dev->dev_addr); macb_or_gem_writel(bp, SA1B, bottom); - top =3D cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4))); + top =3D *((u16 *)(bp->dev->dev_addr + 4)); macb_or_gem_writel(bp, SA1T, top); =20 if (gem_has_ptp(bp)) { --=20 2.50.1