[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aGFM1UQ1P3IQjoex@makrotopia.org>
Date: Sun, 29 Jun 2025 15:25:25 +0100
From: Daniel Golle <daniel@...rotopia.org>
To: Andrew Lunn <andrew@...n.ch>
Cc: Sky Huang <skylake.huang@...iatek.com>, netdev@...r.kernel.org,
Sean Wang <sean.wang@...iatek.com>,
linux-mediatek@...ts.infradead.org, linux-kernel@...r.kernel.org,
Andrew Lunn <andrew+netdev@...n.ch>,
Eric Dumazet <edumazet@...gle.com>,
Matthias Brugger <matthias.bgg@...il.com>,
linux-arm-kernel@...ts.infradead.org,
Bo-Cun Chen <bc-bocun.chen@...iatek.com>,
Eric Woudstra <ericwouds@...il.com>, Elad Yifee <eladwf@...il.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Lorenzo Bianconi <lorenzo@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
Felix Fietkau <nbd@....name>
Subject: Re: [PATCH net/next 3/3] net: ethernet: mtk_eth_soc: use genpool
allocator for SRAM
On Sat, Jun 28, 2025 at 10:13:51AM +0200, Andrew Lunn wrote:
> > +static void *mtk_dma_ring_alloc(struct mtk_eth *eth, size_t size,
> > + dma_addr_t *dma_handle)
> > +{
> > + void *dma_ring;
> > +
> > + if (WARN_ON(mtk_use_legacy_sram(eth)))
> > + return -ENOMEM;
> > +
> > + if (eth->sram_pool) {
> > + dma_ring = (void *)gen_pool_alloc(eth->sram_pool, size);
> > + if (!dma_ring)
> > + return dma_ring;
> > + *dma_handle = gen_pool_virt_to_phys(eth->sram_pool, (unsigned long)dma_ring);
>
> I don't particularly like all the casting backwards and forwards
> between unsigned long and void *. These two APIs are not really
> compatible with each other. So any sort of wrapping is going to be
> messy.
>
> Maybe define a cookie union:
>
> struct mtk_dma_cookie {
> union {
> unsigned long gen_pool;
> void *coherent;
> }
> }
I've implemented that idea and the diffstat grew quite a lot. Also,
it didn't really make the code more readable (see below why).
>
> Only dma_handle appears to be used by the rest of the code, so only
> the _alloc and _free need to know about the union.
That's not true. The void* ring->dma is used to access the RX and TX
descriptors, so keeping it void* is useful and using the struct you
are suggesting will make things even more messy than they already are.
See all the places in the code where we assume ring->dma being void*.
Converting all of those to use struct mtk_dma_cookie will not make things
better imho.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n1337
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n1345
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n1358
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n1804
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n2172
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n2490
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n2638
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n2668
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mediatek/mtk_eth_soc.c#n2904
I think keeping the two casts in mtk_dma_ring_alloc() and
mtk_dma_ring_free() is the better option.
Powered by blists - more mailing lists