From mboxrd@z Thu Jan 1 00:00:00 1970 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 B669538C414; Fri, 10 Apr 2026 19:52:25 +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=1775850747; cv=none; b=aCxS2WowNFFBJhviTz7xuJtWj/MyUtTTU4PsoJ4VP6d7myZ4SLNLjFFTwmnRK0o3QCSfYRIVDF2l5SR4JKRuC3YBcrjya7DqeyADH9zXS4qAofM6In0/rSX1rmWbidqxm1o5bqYPw52NWyvBrXuJi1MDu+NCvesnUdj6h4b7oOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775850747; c=relaxed/simple; bh=ckMfHjQDxQZK3Gjb9gu8GV39Ulx2v+K1gkAGFpa5qIg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uu6nwhzG+CP9BnVzF80iJw//3GZ1A/Kb14/Oy8SsBgG93orjhpL5DrkS8hCjPytyF4QpDmhauNaNFMDgYWItyYniJNnA/E47ukl1moN0XtPj3t47zaYGImB/bixjixlQjs3F4y7Wn8QC0qDWGaAy6XJ/Nzq450ZNDoiJPFWiljs= 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=0/nSa8pv; 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="0/nSa8pv" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 3F5624E42993; Fri, 10 Apr 2026 19:52:24 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 02181603F0; Fri, 10 Apr 2026 19:52:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id ACB521045008D; Fri, 10 Apr 2026 21:52:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1775850742; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=Zu6oI5hHvN4oKY1rozzTrmOSy44V0NqxE2nOSo00uDM=; b=0/nSa8pvGK9FADSZoh4JBcv2EdDW4xpBsQ+74IY96BACSirIBDaDO12mf4gw3WmKLalfHJ RcE725iemlfukIlUIZgVhCdt3ovnDGgDYplMhX7KND2V42sYQi7zqBtjCbT5G7C2OEqkw4 ar8QoBAOUOQCZ5VR3qGlaD/QtZxbLqH2HfwWH8CE1BeQkdKY1Pwe4qYfK9txf+roa03oge Dyr6WGKCR7QzNZGKmR3mHU+8Yw3VbMkr4bcVbskVTjLkm9C43WJCE+nfCRr2w4FAvk2v0t LiQEgafs3ZBQAu9S8QL0I/Hs6yFekTf/j4SVhVEN5gg0/Y2Nsffrfe6TggfZsg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 10 Apr 2026 21:51:55 +0200 Subject: [PATCH net-next v2 07/14] 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: <20260410-macb-context-v2-7-af39f71d40b6@bootlin.com> References: <20260410-macb-context-v2-0-af39f71d40b6@bootlin.com> In-Reply-To: <20260410-macb-context-v2-0-af39f71d40b6@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.1 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(). 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 3e596cbe9fc8..2eddc7892073 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2615,25 +2615,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) @@ -3177,7 +3178,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; @@ -3196,7 +3196,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.53.0