@@ -234,19 +234,18 @@ static bool rswitch_is_queue_rxed(struct rswitch_gwca_queue *gq)
234
234
return false;
235
235
}
236
236
237
- static int rswitch_gwca_queue_alloc_skb (struct rswitch_gwca_queue * gq ,
238
- unsigned int start_index ,
239
- unsigned int num )
237
+ static int rswitch_gwca_queue_alloc_rx_buf (struct rswitch_gwca_queue * gq ,
238
+ unsigned int start_index ,
239
+ unsigned int num )
240
240
{
241
241
unsigned int i , index ;
242
242
243
243
for (i = 0 ; i < num ; i ++ ) {
244
244
index = (i + start_index ) % gq -> ring_size ;
245
- if (gq -> skbs [index ])
245
+ if (gq -> rx_bufs [index ])
246
246
continue ;
247
- gq -> skbs [index ] = netdev_alloc_skb_ip_align (gq -> ndev ,
248
- PKT_BUF_SZ + RSWITCH_ALIGN - 1 );
249
- if (!gq -> skbs [index ])
247
+ gq -> rx_bufs [index ] = netdev_alloc_frag (RSWITCH_BUF_SIZE );
248
+ if (!gq -> rx_bufs [index ])
250
249
goto err ;
251
250
}
252
251
@@ -255,8 +254,8 @@ static int rswitch_gwca_queue_alloc_skb(struct rswitch_gwca_queue *gq,
255
254
err :
256
255
for (; i -- > 0 ; ) {
257
256
index = (i + start_index ) % gq -> ring_size ;
258
- dev_kfree_skb (gq -> skbs [index ]);
259
- gq -> skbs [index ] = NULL ;
257
+ skb_free_frag (gq -> rx_bufs [index ]);
258
+ gq -> rx_bufs [index ] = NULL ;
260
259
}
261
260
262
261
return - ENOMEM ;
@@ -274,16 +273,17 @@ static void rswitch_gwca_queue_free(struct net_device *ndev,
274
273
gq -> rx_ring = NULL ;
275
274
276
275
for (i = 0 ; i < gq -> ring_size ; i ++ )
277
- dev_kfree_skb (gq -> skbs [i ]);
276
+ skb_free_frag (gq -> rx_bufs [i ]);
277
+ kfree (gq -> rx_bufs );
278
+ gq -> rx_bufs = NULL ;
278
279
} else {
279
280
dma_free_coherent (ndev -> dev .parent ,
280
281
sizeof (struct rswitch_ext_desc ) *
281
282
(gq -> ring_size + 1 ), gq -> tx_ring , gq -> ring_dma );
282
283
gq -> tx_ring = NULL ;
284
+ kfree (gq -> skbs );
285
+ gq -> skbs = NULL ;
283
286
}
284
-
285
- kfree (gq -> skbs );
286
- gq -> skbs = NULL ;
287
287
}
288
288
289
289
static void rswitch_gwca_ts_queue_free (struct rswitch_private * priv )
@@ -307,17 +307,20 @@ static int rswitch_gwca_queue_alloc(struct net_device *ndev,
307
307
gq -> ring_size = ring_size ;
308
308
gq -> ndev = ndev ;
309
309
310
- gq -> skbs = kcalloc (gq -> ring_size , sizeof (* gq -> skbs ), GFP_KERNEL );
311
- if (!gq -> skbs )
312
- return - ENOMEM ;
313
-
314
310
if (!dir_tx ) {
315
- rswitch_gwca_queue_alloc_skb (gq , 0 , gq -> ring_size );
311
+ gq -> rx_bufs = kcalloc (gq -> ring_size , sizeof (* gq -> rx_bufs ), GFP_KERNEL );
312
+ if (!gq -> rx_bufs )
313
+ return - ENOMEM ;
314
+ if (rswitch_gwca_queue_alloc_rx_buf (gq , 0 , gq -> ring_size ) < 0 )
315
+ goto out ;
316
316
317
317
gq -> rx_ring = dma_alloc_coherent (ndev -> dev .parent ,
318
318
sizeof (struct rswitch_ext_ts_desc ) *
319
319
(gq -> ring_size + 1 ), & gq -> ring_dma , GFP_KERNEL );
320
320
} else {
321
+ gq -> skbs = kcalloc (gq -> ring_size , sizeof (* gq -> skbs ), GFP_KERNEL );
322
+ if (!gq -> skbs )
323
+ return - ENOMEM ;
321
324
gq -> tx_ring = dma_alloc_coherent (ndev -> dev .parent ,
322
325
sizeof (struct rswitch_ext_desc ) *
323
326
(gq -> ring_size + 1 ), & gq -> ring_dma , GFP_KERNEL );
@@ -366,12 +369,13 @@ static int rswitch_gwca_queue_format(struct net_device *ndev,
366
369
for (i = 0 , desc = gq -> tx_ring ; i < gq -> ring_size ; i ++ , desc ++ ) {
367
370
if (!gq -> dir_tx ) {
368
371
dma_addr = dma_map_single (ndev -> dev .parent ,
369
- gq -> skbs [i ]-> data , PKT_BUF_SZ ,
372
+ gq -> rx_bufs [i ] + RSWITCH_HEADROOM ,
373
+ RSWITCH_MAP_BUF_SIZE ,
370
374
DMA_FROM_DEVICE );
371
375
if (dma_mapping_error (ndev -> dev .parent , dma_addr ))
372
376
goto err ;
373
377
374
- desc -> desc .info_ds = cpu_to_le16 (PKT_BUF_SZ );
378
+ desc -> desc .info_ds = cpu_to_le16 (RSWITCH_DESC_BUF_SIZE );
375
379
rswitch_desc_set_dptr (& desc -> desc , dma_addr );
376
380
desc -> desc .die_dt = DT_FEMPTY | DIE ;
377
381
} else {
@@ -394,8 +398,8 @@ static int rswitch_gwca_queue_format(struct net_device *ndev,
394
398
if (!gq -> dir_tx ) {
395
399
for (desc = gq -> tx_ring ; i -- > 0 ; desc ++ ) {
396
400
dma_addr = rswitch_desc_get_dptr (& desc -> desc );
397
- dma_unmap_single (ndev -> dev .parent , dma_addr , PKT_BUF_SZ ,
398
- DMA_FROM_DEVICE );
401
+ dma_unmap_single (ndev -> dev .parent , dma_addr ,
402
+ RSWITCH_MAP_BUF_SIZE , DMA_FROM_DEVICE );
399
403
}
400
404
}
401
405
@@ -432,12 +436,13 @@ static int rswitch_gwca_queue_ext_ts_fill(struct net_device *ndev,
432
436
desc = & gq -> rx_ring [index ];
433
437
if (!gq -> dir_tx ) {
434
438
dma_addr = dma_map_single (ndev -> dev .parent ,
435
- gq -> skbs [index ]-> data , PKT_BUF_SZ ,
439
+ gq -> rx_bufs [index ] + RSWITCH_HEADROOM ,
440
+ RSWITCH_MAP_BUF_SIZE ,
436
441
DMA_FROM_DEVICE );
437
442
if (dma_mapping_error (ndev -> dev .parent , dma_addr ))
438
443
goto err ;
439
444
440
- desc -> desc .info_ds = cpu_to_le16 (PKT_BUF_SZ );
445
+ desc -> desc .info_ds = cpu_to_le16 (RSWITCH_DESC_BUF_SIZE );
441
446
rswitch_desc_set_dptr (& desc -> desc , dma_addr );
442
447
dma_wmb ();
443
448
desc -> desc .die_dt = DT_FEMPTY | DIE ;
@@ -455,8 +460,8 @@ static int rswitch_gwca_queue_ext_ts_fill(struct net_device *ndev,
455
460
index = (i + start_index ) % gq -> ring_size ;
456
461
desc = & gq -> rx_ring [index ];
457
462
dma_addr = rswitch_desc_get_dptr (& desc -> desc );
458
- dma_unmap_single (ndev -> dev .parent , dma_addr , PKT_BUF_SZ ,
459
- DMA_FROM_DEVICE );
463
+ dma_unmap_single (ndev -> dev .parent , dma_addr ,
464
+ RSWITCH_MAP_BUF_SIZE , DMA_FROM_DEVICE );
460
465
}
461
466
}
462
467
@@ -723,10 +728,15 @@ static bool rswitch_rx(struct net_device *ndev, int *quota)
723
728
while ((desc -> desc .die_dt & DT_MASK ) != DT_FEMPTY ) {
724
729
dma_rmb ();
725
730
pkt_len = le16_to_cpu (desc -> desc .info_ds ) & RX_DS ;
726
- skb = gq -> skbs [gq -> cur ];
727
- gq -> skbs [gq -> cur ] = NULL ;
728
731
dma_addr = rswitch_desc_get_dptr (& desc -> desc );
729
- dma_unmap_single (ndev -> dev .parent , dma_addr , PKT_BUF_SZ , DMA_FROM_DEVICE );
732
+ dma_unmap_single (ndev -> dev .parent , dma_addr ,
733
+ RSWITCH_MAP_BUF_SIZE , DMA_FROM_DEVICE );
734
+ skb = build_skb (gq -> rx_bufs [gq -> cur ], RSWITCH_BUF_SIZE );
735
+ if (!skb )
736
+ goto out ;
737
+ skb_reserve (skb , RSWITCH_HEADROOM );
738
+ skb_put (skb , pkt_len );
739
+
730
740
get_ts = rdev -> priv -> ptp_priv -> tstamp_rx_ctrl & RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT ;
731
741
if (get_ts ) {
732
742
struct skb_shared_hwtstamps * shhwtstamps ;
@@ -738,12 +748,13 @@ static bool rswitch_rx(struct net_device *ndev, int *quota)
738
748
ts .tv_nsec = __le32_to_cpu (desc -> ts_nsec & cpu_to_le32 (0x3fffffff ));
739
749
shhwtstamps -> hwtstamp = timespec64_to_ktime (ts );
740
750
}
741
- skb_put (skb , pkt_len );
742
751
skb -> protocol = eth_type_trans (skb , ndev );
743
752
napi_gro_receive (& rdev -> napi , skb );
744
753
rdev -> ndev -> stats .rx_packets ++ ;
745
754
rdev -> ndev -> stats .rx_bytes += pkt_len ;
746
755
756
+ out :
757
+ gq -> rx_bufs [gq -> cur ] = NULL ;
747
758
gq -> cur = rswitch_next_queue_index (gq , true, 1 );
748
759
desc = & gq -> rx_ring [gq -> cur ];
749
760
@@ -752,7 +763,7 @@ static bool rswitch_rx(struct net_device *ndev, int *quota)
752
763
}
753
764
754
765
num = rswitch_get_num_cur_queues (gq );
755
- ret = rswitch_gwca_queue_alloc_skb (gq , gq -> dirty , num );
766
+ ret = rswitch_gwca_queue_alloc_rx_buf (gq , gq -> dirty , num );
756
767
if (ret < 0 )
757
768
goto err ;
758
769
ret = rswitch_gwca_queue_ext_ts_fill (ndev , gq , gq -> dirty , num );
0 commit comments