From mboxrd@z Thu Jan 1 00:00:00 1970 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 9BF78320CBE; Wed, 30 Sep 2026 22:54:10 +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=1790808855; cv=none; b=mL/gdYSU1yuyEBenIXLRG+Fpc3rk5IUrYrP894UefX4vDVuqKzhec2GtQfRJ69qZ/5JwJUjr3VTgrJujBshXBT+m7UN8tNqUhdI9qz2zCY2j8MpHmiIYFjSA5TgHdU+FwITdcB9zBeNS3VzTsotKNCDBFZBFLm7oKkT7B5Jl61A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790808855; c=relaxed/simple; bh=8PTlBUpM270BZW8cbvdD+i7+Hu9j75uFQSvzTDzy1Xc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KLXkcORCPt2hl4SJHa3T7yc3SPzXp8ftprJrI/kWuJLx/La+HgaURSYq3+/uU77ZSxPj4HZUBFUanJt7SSBb9HqM2Xpz+lamgvbOpl0ZeB215Kymatt3tJvrWjd2xcy/6zhyCoekIwui2BtW+kutAOlJcmfdDpWVY8dIidQbs9I= 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=MH8doJZ/; 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="MH8doJZ/" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id D51311A108A; Wed, 30 Sep 2026 22:54:07 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A942C60749; Wed, 30 Sep 2026 22:54:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E7CBC1032974F; Thu, 1 Oct 2026 00:54:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1790808846; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=73D3OSlDiNS8wycnLE7vVmXNcko4seMssV7V/nPNM44=; b=MH8doJZ/nXRI4RLn5vyQiJY4Ld4Y7gGgQgGOV9Ab3elcW+nNLLr2KorwrkRNvgqZwLK9jF n5X8EN5XcCLFFwlzX+ucwKLGyEz2CmBZqZn4YrAiUC72RaVygrwVBhii91kBlLRDV2BV4X YA3vr0dF4Ppm4c1OFgml6ljcQe6D1orrgGhUs0SFqOBzV15ptM8fz4HwadL8WEQJoOgObF AxtpSZcf+L20Bcb4k7bHaWuYwpYk0tD1qt0ieaRxWuz3Jro9JlKpLgE/n+Zulm1SpOD508 fQG/iaKLPNo7OGaY6/VZRTPk2pBCAO1UgEvXxXDyyxUVY846fMEKRKQnZVkJ5g== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Thu, 01 Oct 2026 00:53:47 +0200 Subject: [PATCH net-next v10 3/8] net: macb: make `struct macb` subset reachable from macb_context struct 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: 8bit Message-Id: <20261001-macb-context-v10-3-beb541bbb7df@bootlin.com> References: <20261001-macb-context-v10-0-beb541bbb7df@bootlin.com> In-Reply-To: <20261001-macb-context-v10-0-beb541bbb7df@bootlin.com> To: =?utf-8?q?Th=C3=A9o_Lebrun?= , Conor Dooley , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Valerio , Nicolai Buchwitz , Vladimir Kondratiev , Gregory CLEMENT , =?utf-8?q?Beno=C3=AEt_Monin?= , Tawfik Bayouk , Thomas Petazzoni X-Mailer: b4 0.15.2 X-Last-TLS-Session-Version: TLSv1.3 For parallel MACB context to start become a reality, many functions need to stop operating on bp->ctx (the currently active context) and instead work on a context they get passed. That context might be (1) the new one that is getting allocated and initialised, or, (2) the old one to be freed. To reduce bug surface area, we will taint those functions to *only* take a context and no `struct macb *bp`. That way, no bug of using `bp->ctx` instead of `ctx` will ever occur. For that, we need to embed a subset of `struct macb` information into each context so that all helpers can still do their jobs. That subset must be constant once probe is completed. Do this by taking a pointer to a subset of macb called `struct macb_info`. That subset is accessible from context (ctx->info->caps) or from bp (bp->caps) using `-fms-extensions` option, thanks to commit c4781dc3d1cf ("Kbuild: enable -fms-extensions"). https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html Add the structure and assign ctx->info at alloc, but nothing uses it yet. Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun --- drivers/net/ethernet/cadence/macb.h | 31 ++++++++++++++++++++++--------- drivers/net/ethernet/cadence/macb_main.c | 6 ++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 30bba15834eb..cbec4a37dcd1 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1287,6 +1287,17 @@ struct ethtool_rx_fs_list { unsigned int count; }; +struct macb_info { + struct platform_device *pdev; + struct net_device *netdev; + struct macb_or_gem_ops macbgem_ops; + unsigned int num_queues; + u32 caps; + int rx_bd_rd_prefetch; + int tx_bd_rd_prefetch; + struct queue_stats *queue_stats[MACB_MAX_QUEUES]; +}; + struct macb_rxq { struct macb_dma_desc *ring; /* MACB & GEM */ dma_addr_t ring_dma; /* MACB & GEM */ @@ -1306,6 +1317,8 @@ struct macb_txq { }; struct macb_context { + const struct macb_info *info; + unsigned int rx_buffer_size; unsigned int rx_ring_size; unsigned int tx_ring_size; @@ -1321,6 +1334,15 @@ struct macb { u32 (*macb_reg_readl)(struct macb *bp, int offset); void (*macb_reg_writel)(struct macb *bp, int offset, u32 value); + /* + * Give direct access (bp->caps) and + * allow taking a pointer to it (&bp->info) for contexts. + */ + union { + struct macb_info; + struct macb_info info; + }; + /* * Context stores all its parameters. * But we must remember them across closure. @@ -1332,17 +1354,14 @@ struct macb { struct macb_dma_desc *rx_ring_tieoff; dma_addr_t rx_ring_tieoff_dma; - unsigned int num_queues; struct macb_queue queues[MACB_MAX_QUEUES]; spinlock_t lock; - struct platform_device *pdev; struct clk *pclk; struct clk *hclk; struct clk *tx_clk; struct clk *rx_clk; struct clk *tsu_clk; - struct net_device *netdev; /* Protects hw_stats and ethtool_stats */ spinlock_t stats_lock; union { @@ -1350,15 +1369,12 @@ struct macb { struct gem_stats gem; } hw_stats; - struct macb_or_gem_ops macbgem_ops; - struct mii_bus *mii_bus; struct phylink *phylink; struct phylink_config phylink_config; struct phylink_pcs phylink_usx_pcs; struct phylink_pcs phylink_sgmii_pcs; - u32 caps; unsigned int dma_burst_length; phy_interface_t phy_interface; @@ -1406,9 +1422,6 @@ struct macb { */ bool irq_quiesced; - int rx_bd_rd_prefetch; - int tx_bd_rd_prefetch; - u32 rx_intr_mask; struct macb_pm_data pm_data; diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 228ae4e58880..91f58c35165a 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -3329,6 +3329,8 @@ static int macb_open(struct net_device *netdev) goto pm_exit; } + bp->ctx->info = &bp->info; + /* RX buffers initialization */ bp->ctx->rx_buffer_size = macb_rx_buffer_size(bp, netdev->mtu); bp->ctx->rx_ring_size = bp->configured_rx_ring_size; @@ -5273,6 +5275,7 @@ static int at91ether_open(struct net_device *netdev) ret = -ENOMEM; goto pm_exit; } + bp->ctx->info = &bp->info; /* Clear internal statistics */ ctl = macb_readl(bp, NCR); @@ -5995,6 +5998,7 @@ static int macb_probe(struct platform_device *pdev) u32 wtrmrk_rst_val; void __iomem *mem; struct macb *bp; + unsigned int q; int num_queues; bool native_io; int err, val; @@ -6040,6 +6044,8 @@ static int macb_probe(struct platform_device *pdev) bp->netdev = netdev; bp->regs = mem; bp->native_io = native_io; + for (q = 0; q < MACB_MAX_QUEUES; q++) + bp->info.queue_stats[q] = &bp->queues[q].stats; if (native_io) { bp->macb_reg_readl = hw_readl_native; bp->macb_reg_writel = hw_writel_native; -- 2.55.0