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 EB177472F8C for ; Fri, 31 Jul 2026 16:35:02 +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=1785515704; cv=none; b=l8QK5RXJpYQKY9P8tV3OmfwGAKPF1LLptUAXCItgfFI5kEGGb6slWAlfzTQJ7ZZuMgPEhxic/P2hvl9qifgZleMZZkSqQ+5glinZRuixCGsj2i/N2LQj5AB9AJZYUDg/8jwtUngDjdtAXa6pnWm/kTzsVpKYqMx1aetAxB1ivCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785515704; c=relaxed/simple; bh=XsU/eH/XzSnxCbLAtrwuPVJfLuArJriwwYTQtc++8/M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Oz/EKjeJDFLVVMIGFIitbmEM0/Wo409Uaur1I+NsHcDWajrssygo1rNdBth6FuvPJdPAe9uoYXH+vMO35NovByecg/iz2DihCqSqBiJZQ95vKaSPPYwzy8dGRg19wEAmiiNC0AYGz6H5p/zTPZ9EqQYPhmQTTres/LFiOZDt6eg= 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=D1lsDpzp; 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="D1lsDpzp" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 6C7E71A1369; Fri, 31 Jul 2026 16:35:01 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 3DC47603C2; Fri, 31 Jul 2026 16:35:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1C08911C16AE7; Fri, 31 Jul 2026 18:34:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1785515699; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=/uKOJmi1j21USZ+AZANmLf1uL0f6b790ehkq5tA46S4=; b=D1lsDpzp4G8qQ9KsNSCJdpMGnubfqP4ABbaycIwNT8S9x9K+eU+WCtCdkfUy/MF4L8YSfa KYtGTsfEVCwUySKpFy7tgsHI9M2SvMLyA8UiUYJeZ2H2khYaHF2/CN46uPvAiUJ1iwkqIv Y+fXyV/lVcGOeCaXV2odWCDeqdY3kZBve4IAtKWlmccFum9Ulk0kFa63/xcD1WAwLu8ulr A+EvkCiumJ5c4cXXZXgV6JUVsie7H6gf9yIzjHLMLCZMtqh2nAeO5s7PFSzBSPDOJQlSOa c1Ew5PncmebeAn4sD6zPWVsmbZT0bwrEpHwRzAIEvIMrLpPuSousaaSOfyNYmA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 31 Jul 2026 18:34:18 +0200 Subject: [PATCH net-next v6 08/16] net: macb: avoid macb_init_rx_buffer_size() modifying state Precedence: bulk X-Mailing-List: netdev@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: <20260731-macb-context-v6-8-49d5a1439d48@bootlin.com> References: <20260731-macb-context-v6-0-49d5a1439d48@bootlin.com> In-Reply-To: <20260731-macb-context-v6-0-49d5a1439d48@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, Nicolas Ferre , Claudiu Beznea , Paolo Valerio , Nicolai Buchwitz , Vladimir Kondratiev , Gregory CLEMENT , =?utf-8?q?Beno=C3=AEt_Monin?= , Tawfik Bayouk , Thomas Petazzoni , Maxime Chevallier X-Mailer: b4 0.15.2 X-Last-TLS-Session-Version: TLSv1.3 macb_init_rx_buffer_size() takes the macb private data struct and overrides its bp->ctx->rx_buffer_size. To make it usable with multiple contexts, make it return its value. Also, move the `bufsz` computation into it. The value is only used if GEM, and for historical reason it currently lives in macb_open(). Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo Lebrun --- drivers/net/ethernet/cadence/macb_main.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index d294d906adf0..ef1cbd5e4f57 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2617,25 +2617,26 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, return ret; } -static void macb_init_rx_buffer_size(struct macb *bp, size_t size) +static unsigned int macb_rx_buffer_size(struct macb *bp, unsigned int mtu) { - if (!macb_is_gem(bp)) { - bp->ctx->rx_buffer_size = MACB_RX_BUFFER_SIZE; - } else { - bp->ctx->rx_buffer_size = MIN(size, RX_BUFFER_MAX); + unsigned int size; - if (bp->ctx->rx_buffer_size % RX_BUFFER_MULTIPLE) { + if (!macb_is_gem(bp)) { + size = MACB_RX_BUFFER_SIZE; + } else { + size = mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN; + size = MIN(size, RX_BUFFER_MAX); + + if (size % RX_BUFFER_MULTIPLE) { netdev_dbg(bp->netdev, "RX buffer must be multiple of %d bytes, expanding\n", RX_BUFFER_MULTIPLE); - bp->ctx->rx_buffer_size = - roundup(bp->ctx->rx_buffer_size, - RX_BUFFER_MULTIPLE); + size = roundup(size, RX_BUFFER_MULTIPLE); } } - netdev_dbg(bp->netdev, "mtu [%u] rx_buffer_size [%u]\n", - bp->netdev->mtu, bp->ctx->rx_buffer_size); + netdev_dbg(bp->netdev, "mtu [%u] rx_buffer_size [%u]\n", mtu, size); + return size; } static void gem_free_rx_buffers(struct macb *bp) @@ -3195,7 +3196,6 @@ static void macb_set_rx_mode(struct net_device *netdev) static int macb_open(struct net_device *netdev) { - size_t bufsz = netdev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN; struct macb *bp = netdev_priv(netdev); struct macb_queue *queue; unsigned int q; @@ -3214,7 +3214,7 @@ static int macb_open(struct net_device *netdev) } /* RX buffers initialization */ - macb_init_rx_buffer_size(bp, bufsz); + bp->ctx->rx_buffer_size = macb_rx_buffer_size(bp, netdev->mtu); bp->ctx->rx_ring_size = bp->configured_rx_ring_size; bp->ctx->tx_ring_size = bp->configured_tx_ring_size; -- 2.55.0