diff mbox series

[net-next,v1] ps3_gelic_net: Use napi routines for RX SKB

Message ID ddb7f076-06a7-45df-ae98-b4120d9dc275@infradead.org (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v1] ps3_gelic_net: Use napi routines for RX SKB | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 9 maintainers not CCed: pabeni@redhat.com edumazet@google.com linuxppc-dev@lists.ozlabs.org mpe@ellerman.id.au aneesh.kumar@kernel.org kuba@kernel.org npiggin@gmail.com christophe.leroy@csgroup.eu naveen.n.rao@linux.ibm.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 81 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-05--03-00 (tests: 890)

Commit Message

Geoff Levand March 1, 2024, 8:20 a.m. UTC
Convert the PS3 Gelic network driver's RX SK buffers over to
use the napi_alloc_frag_align and napi_build_skb routines.

Signed-off-by: Geoff Levand <geoff@infradead.org>

Comments

Jakub Kicinski March 5, 2024, 4:42 a.m. UTC | #1
On Fri, 1 Mar 2024 17:20:11 +0900 Geoff Levand wrote:
> +	descr->skb = napi_build_skb(napi_buff, napi_buff_size);
> +
> +	if (unlikely(!descr->skb)) {
> +		skb_free_frag(napi_buff);
>  		return -ENOMEM;
>  	}
>  
> -	offset = ((unsigned long)descr->skb->data) &
> -		(GELIC_NET_RXBUF_ALIGN - 1);
> -	if (offset)
> -		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
> -	/* io-mmu-map the skb */
> -	cpu_addr = dma_map_single(ctodev(card), descr->skb->data,
> -				  GELIC_NET_MAX_FRAME, DMA_FROM_DEVICE);
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> -	if (dma_mapping_error(ctodev(card), cpu_addr)) {
> -		dev_kfree_skb_any(descr->skb);
> +	cpu_addr = dma_map_single(dev, napi_buff, napi_buff_size,
> +				  DMA_FROM_DEVICE);
> +
> +	if (dma_mapping_error(dev, cpu_addr)) {
> +		skb_free_frag(napi_buff);

After you called napi_build_skb() you should be operating (here:
freeing) the skb not the underlying buffer.
Ratheesh Kannoth March 5, 2024, 5:24 a.m. UTC | #2
On 2024-03-01 at 13:50:11, Geoff Levand (geoff@infradead.org) wrote:
> +	if (unlikely(!napi_buff))
> +		return -ENOMEM;
>
> -	descr->skb = netdev_alloc_skb(*card->netdev, rx_skb_size);
> -	if (!descr->skb) {
> -		descr->hw_regs.payload.dev_addr = 0; /* tell DMAC don't touch memory */
> +	descr->skb = napi_build_skb(napi_buff, napi_buff_size);
> +
> +	if (unlikely(!descr->skb)) {
> +		skb_free_frag(napi_buff);
>  		return -ENOMEM;
>  	}
>
> -	offset = ((unsigned long)descr->skb->data) &
> -		(GELIC_NET_RXBUF_ALIGN - 1);
> -	if (offset)
> -		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
> -	/* io-mmu-map the skb */
> -	cpu_addr = dma_map_single(ctodev(card), descr->skb->data,
> -				  GELIC_NET_MAX_FRAME, DMA_FROM_DEVICE);
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> -	if (dma_mapping_error(ctodev(card), cpu_addr)) {
> -		dev_kfree_skb_any(descr->skb);
> +	cpu_addr = dma_map_single(dev, napi_buff, napi_buff_size,
> +				  DMA_FROM_DEVICE);
> +
> +	if (dma_mapping_error(dev, cpu_addr)) {
> +		skb_free_frag(napi_buff);
skb->head is freed; dont you need to free skb as well ?

>  		descr->skb = NULL;
diff mbox series

Patch

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 5ee8e8980393..fb5c015851b8 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -375,14 +375,14 @@  static int gelic_card_init_chain(struct gelic_card *card,
 static int gelic_descr_prepare_rx(struct gelic_card *card,
 				  struct gelic_descr *descr)
 {
-	static const unsigned int rx_skb_size =
-		ALIGN(GELIC_NET_MAX_FRAME, GELIC_NET_RXBUF_ALIGN) +
-		GELIC_NET_RXBUF_ALIGN - 1;
+	static const unsigned int napi_buff_size =
+		round_up(GELIC_NET_MAX_FRAME, GELIC_NET_RXBUF_ALIGN);
+	struct device *dev = ctodev(card);
 	dma_addr_t cpu_addr;
-	int offset;
+	void *napi_buff;
 
 	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
-		dev_info(ctodev(card), "%s: ERROR status\n", __func__);
+		dev_info(dev, "%s: ERROR status\n", __func__);
 
 	descr->hw_regs.dmac_cmd_status = 0;
 	descr->hw_regs.result_size = 0;
@@ -390,31 +390,34 @@  static int gelic_descr_prepare_rx(struct gelic_card *card,
 	descr->hw_regs.data_error = 0;
 	descr->hw_regs.payload.dev_addr = 0;
 	descr->hw_regs.payload.size = 0;
+	descr->skb = NULL;
+
+	napi_buff = napi_alloc_frag_align(napi_buff_size,
+					  GELIC_NET_RXBUF_ALIGN);
+
+	if (unlikely(!napi_buff))
+		return -ENOMEM;
 
-	descr->skb = netdev_alloc_skb(*card->netdev, rx_skb_size);
-	if (!descr->skb) {
-		descr->hw_regs.payload.dev_addr = 0; /* tell DMAC don't touch memory */
+	descr->skb = napi_build_skb(napi_buff, napi_buff_size);
+
+	if (unlikely(!descr->skb)) {
+		skb_free_frag(napi_buff);
 		return -ENOMEM;
 	}
 
-	offset = ((unsigned long)descr->skb->data) &
-		(GELIC_NET_RXBUF_ALIGN - 1);
-	if (offset)
-		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
-	/* io-mmu-map the skb */
-	cpu_addr = dma_map_single(ctodev(card), descr->skb->data,
-				  GELIC_NET_MAX_FRAME, DMA_FROM_DEVICE);
-	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
-	if (dma_mapping_error(ctodev(card), cpu_addr)) {
-		dev_kfree_skb_any(descr->skb);
+	cpu_addr = dma_map_single(dev, napi_buff, napi_buff_size,
+				  DMA_FROM_DEVICE);
+
+	if (dma_mapping_error(dev, cpu_addr)) {
+		skb_free_frag(napi_buff);
 		descr->skb = NULL;
-		dev_info(ctodev(card),
-			 "%s:Could not iommu-map rx buffer\n", __func__);
+		dev_err_once(dev, "%s:Could not iommu-map rx buffer\n",
+			     __func__);
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
 		return -ENOMEM;
 	}
 
-	descr->hw_regs.payload.size = cpu_to_be32(GELIC_NET_MAX_FRAME);
+	descr->hw_regs.payload.size = cpu_to_be32(napi_buff_size);
 	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
 
 	gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.h b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
index f7d7931e51b7..e8f7de8e7e9b 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.h
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
@@ -19,10 +19,10 @@ 
 #define GELIC_NET_RX_DESCRIPTORS        128 /* num of descriptors */
 #define GELIC_NET_TX_DESCRIPTORS        128 /* num of descriptors */
 
-#define GELIC_NET_MAX_FRAME             2312
+#define GELIC_NET_MAX_FRAME             2312U
 #define GELIC_NET_MAX_MTU               2294
 #define GELIC_NET_MIN_MTU               64
-#define GELIC_NET_RXBUF_ALIGN           128
+#define GELIC_NET_RXBUF_ALIGN           128U
 #define GELIC_CARD_RX_CSUM_DEFAULT      1 /* hw chksum */
 #define GELIC_NET_WATCHDOG_TIMEOUT      5*HZ
 #define GELIC_NET_BROADCAST_ADDR        0xffffffffffffL