From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (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 F3454227BA4; Sun, 29 Jun 2025 14:25:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751207150; cv=none; b=ub3eNmKkMjNwyOa2TVaCPJsumxD7JEqiZBYjFo/F3zPncO5beaaqGIX5e4konkSUdhKjp1kvIjlzTxOhDueWD55IaKpiKiO0KHewGsjxzlMjJXjpA5EILxlwJkquq6upCCFRYwHxtTe0Tiz9SPHGiMAT4+2R94uqvXV1ofi5xgs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751207150; c=relaxed/simple; bh=E6AUdqXg1UQebluQC1Qcloluh833TMA6tD31kT9MSCc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pX577WlsD30HHpsPN1MrhSx5F5vYRSNSNX1QqlJJrQ/VNhhHBs0F/kOyMc+lbh6xaGUzCVhHgWThPvJ3HHiTRTtyWW+XbHyPt3wBXBteFLqf9nMWMSLS4PPJYROEb4lpdDv22MLjOugLmFaE5y5nljHZgDZhrIR58+pJFHxYn2c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.98.2) (envelope-from ) id 1uVsyM-0000000015j-3WGk; Sun, 29 Jun 2025 14:25:34 +0000 Date: Sun, 29 Jun 2025 15:25:25 +0100 From: Daniel Golle To: Andrew Lunn Cc: Sky Huang , netdev@vger.kernel.org, Sean Wang , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Lunn , Eric Dumazet , Matthias Brugger , linux-arm-kernel@lists.infradead.org, Bo-Cun Chen , Eric Woudstra , Elad Yifee , Jakub Kicinski , Paolo Abeni , Lorenzo Bianconi , "David S. Miller" , AngeloGioacchino Del Regno , Felix Fietkau Subject: Re: [PATCH net/next 3/3] net: ethernet: mtk_eth_soc: use genpool allocator for SRAM Message-ID: References: <566ca90fc59ad0d3aff8bc8dc22ebaf0544bce47.1751072868.git.daniel@makrotopia.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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.