From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Nicolai Buchwitz" <nb@tipi-net.de>,
"Théo Lebrun" <theo.lebrun@bootlin.com>
Cc: "Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Richard Cochran" <richardcochran@gmail.com>,
"Russell King" <linux@armlinux.org.uk>,
"Paolo Valerio" <pvalerio@redhat.com>,
"Conor Dooley" <conor@kernel.org>,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Benoît Monin" <benoit.monin@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 06/11] net: macb: introduce macb_context struct for buffer management
Date: Thu, 02 Apr 2026 16:11:21 +0200 [thread overview]
Message-ID: <DHIQAC7SA3E0.2U7L5MI8IQ4SH@bootlin.com> (raw)
In-Reply-To: <70b176b84fbff4a57d7f6be5f42fc753@tipi-net.de>
On Thu Apr 2, 2026 at 1:22 PM CEST, Nicolai Buchwitz wrote:
> On 1.4.2026 18:39, Théo Lebrun wrote:
>> Whenever an operation requires buffer realloc, we close the interface,
>> update parameters and reopen. To improve reliability under memory
>> pressure, we should rather alloc new buffers, reconfigure HW and free
>> old buffers. This requires MACB to support having multiple "contexts"
>> in parallel.
>>
>> Introduce this concept by adding the macb_context struct, which owns
>> all
>> queue buffers and the parameters associated. We do not yet support
>> multiple contexts in parallel, because all functions access bp->ctx
>> (the currently active context) directly.
>>
>> Steps:
>>
>> - Introduce `struct macb_context` and its children `struct macb_rxq`
>> and `struct macb_txq`. Context fields are stolen from `struct macb`
>> and rxq/txq fields are from `struct macb_queue`.
>>
>> Making it two separate structs per queue simplifies accesses: we
>> grab
>> a txq/rxq local variable and access fields like txq->head instead of
>> queue->tx_head. It also anecdotally improves data locality.
>>
>> - macb_init_dflt() does not set bp->ctx->{rx,tx}_ring_size to default
>> values as ctx is not allocated yet. Instead, introduce
>> bp->configured_{rx,tx}_ring_size which get updated on user requests.
>>
>> - macb_open() starts by allocating bp->ctx. It gets freed in the
>> open error codepath or by macb_close().
>>
>> - Guided by compile errors, update all codepaths. Most diff is
>> changing
>> `queue->tx_*` to `txq->*` and `queue->rx_*` to `rxq->*`, with a new
>> local variable. Also rx_buffer_size / rx_ring_size / tx_ring_size
>> move from bp to bp->ctx.
>>
>> Introduce two helpers macb_tx|rx() functions to convert macb_queue
>> pointers.
>>
>> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
>> ---
>> drivers/net/ethernet/cadence/macb.h | 49 ++--
>> drivers/net/ethernet/cadence/macb_main.c | 442
>> ++++++++++++++++++-------------
>> 2 files changed, 296 insertions(+), 195 deletions(-)
>>
>
>> [...]
>
>> diff --git a/drivers/net/ethernet/cadence/macb_main.c
>> b/drivers/net/ethernet/cadence/macb_main.c
>> index d5023fdc0756..0f63d9b89c11 100644
>> --- a/drivers/net/ethernet/cadence/macb_main.c
>> +++ b/drivers/net/ethernet/cadence/macb_main.c
>
>> [...]
>
>> @@ -3596,14 +3677,15 @@ static void macb_get_regs(struct net_device
>> *netdev, struct ethtool_regs *regs,
>> void *p)
>> {
>> struct macb *bp = netdev_priv(netdev);
>> + struct macb_txq *txq = &bp->ctx->txq[0];
>
> bp->ctx is NULL when the interface is down. This will crash if
> ethtool -d is called while the interface is not running. Same
> issue below in macb_get_ringparam().
Agreed. Will check if context is alive and use default values otherwise.
Something like this for V2:
static void macb_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
void *p)
{
dma_addr_t tx_dma_tail = 0, tx_dma_head = 0;
struct macb *bp = netdev_priv(netdev);
unsigned int tail = 0, head = 0;
struct macb_txq *txq;
u32 *regs_buff = p;
regs->version = (macb_readl(bp, MID) & ((1 << MACB_REV_SIZE) - 1))
| MACB_GREGS_VERSION;
if (bp->ctx) {
txq = &bp->ctx->txq[0];
tail = macb_tx_ring_wrap(bp->ctx, txq->tail);
head = macb_tx_ring_wrap(bp->ctx, txq->head);
tx_dma_tail = macb_tx_dma(&bp->queues[0], tail);
tx_dma_head = macb_tx_dma(&bp->queues[0], head);
}
regs_buff[0] = macb_readl(bp, NCR);
regs_buff[1] = macb_or_gem_readl(bp, NCFGR);
regs_buff[2] = macb_readl(bp, NSR);
regs_buff[3] = macb_readl(bp, TSR);
regs_buff[4] = macb_readl(bp, RBQP);
regs_buff[5] = macb_readl(bp, TBQP);
regs_buff[6] = macb_readl(bp, RSR);
regs_buff[7] = macb_readl(bp, IMR);
regs_buff[8] = tail;
regs_buff[9] = head;
regs_buff[10] = tx_dma_tail;
regs_buff[11] = tx_dma_head;
if (!(bp->caps & MACB_CAPS_USRIO_DISABLED))
regs_buff[12] = macb_or_gem_readl(bp, USRIO);
if (macb_is_gem(bp->caps))
regs_buff[13] = gem_readl(bp, DMACFG);
}
>
>> unsigned int tail, head;
>> u32 *regs_buff = p;
>>
>> regs->version = (macb_readl(bp, MID) & ((1 << MACB_REV_SIZE) - 1))
>> | MACB_GREGS_VERSION;
>>
>> - tail = macb_tx_ring_wrap(bp, bp->queues[0].tx_tail);
>> - head = macb_tx_ring_wrap(bp, bp->queues[0].tx_head);
>> + tail = macb_tx_ring_wrap(bp, txq->tail);
>> + head = macb_tx_ring_wrap(bp, txq->head);
>>
>> regs_buff[0] = macb_readl(bp, NCR);
>> regs_buff[1] = macb_or_gem_readl(bp, NCFGR);
>> @@ -3682,8 +3764,8 @@ static void macb_get_ringparam(struct net_device
>> *netdev,
>> ring->rx_max_pending = MAX_RX_RING_SIZE;
>> ring->tx_max_pending = MAX_TX_RING_SIZE;
>>
>> - ring->rx_pending = bp->rx_ring_size;
>> - ring->tx_pending = bp->tx_ring_size;
>> + ring->rx_pending = bp->ctx->rx_ring_size;
>> + ring->tx_pending = bp->ctx->tx_ring_size;
>
> Same NULL ctx issue as above. This one could just read from
> bp->configured_{rx,tx}_ring_size instead.
Agreed with the fix, easy one.
Thanks!
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-04-02 14:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 16:39 [PATCH net-next 00/11] net: macb: implement context swapping Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 01/11] net: macb: unify device pointer naming convention Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 02/11] net: macb: unify `struct macb *` " Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 03/11] net: macb: unify queue index variable naming convention and types Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 04/11] net: macb: enforce reverse christmas tree (RCT) convention Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 05/11] net: macb: allocate tieoff descriptor once across device lifetime Théo Lebrun
2026-04-02 11:14 ` Nicolai Buchwitz
2026-04-02 13:57 ` Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 06/11] net: macb: introduce macb_context struct for buffer management Théo Lebrun
2026-04-02 11:22 ` Nicolai Buchwitz
2026-04-02 14:11 ` Théo Lebrun [this message]
2026-04-01 16:39 ` [PATCH net-next 07/11] net: macb: avoid macb_init_rx_buffer_size() modifying state Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 08/11] net: macb: make `struct macb` subset reachable from macb_context struct Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 09/11] net: macb: introduce macb_context_alloc() helper Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 10/11] net: macb: use context swapping in .set_ringparam() Théo Lebrun
2026-04-01 20:17 ` Maxime Chevallier
2026-04-02 16:34 ` Théo Lebrun
2026-04-02 11:29 ` Nicolai Buchwitz
2026-04-02 16:31 ` Théo Lebrun
2026-04-03 9:03 ` Théo Lebrun
2026-04-01 16:39 ` [PATCH net-next 11/11] net: macb: use context swapping in .ndo_change_mtu() Théo Lebrun
2026-04-02 11:30 ` Nicolai Buchwitz
2026-04-02 11:35 ` [PATCH net-next 00/11] net: macb: implement context swapping Nicolai Buchwitz
2026-04-02 13:46 ` Théo Lebrun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DHIQAC7SA3E0.2U7L5MI8IQ4SH@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=benoit.monin@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregory.clement@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=nb@tipi-net.de \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.com \
--cc=pvalerio@redhat.com \
--cc=richardcochran@gmail.com \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.kondratiev@mobileye.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox