[PATCH net/next 3/3] net: ethernet: mtk_eth_soc: use genpool allocator for SRAM
Andrew Lunn
andrew at lunn.ch
Sun Jun 29 11:23:36 PDT 2025
On Sun, Jun 29, 2025 at 03:25:25PM +0100, Daniel Golle wrote:
> 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).
O.K, thanks for trying. Please keep with the casts back and forth.
Andrew
More information about the Linux-mediatek
mailing list