Skip to content

Commit 070e1f0

Browse files
chleroydavem330
authored andcommitted
net: fs_enet: don't unmap DMA when packet len is below copybreak
When the length of the packet is below the defined copybreak limit, the received packet is copied into a newly allocated skb in order to reuse the skb. This is only interesting if it allow us to avoid a new DMA mapping. We shall therefore not DMA unmap and remap the skb->data. Instead, we invalidate the cache with dma_sync_single_for_cpu() once the received data has been copied into the new skb. The following measures have been obtained on a mpc885 running at 132Mhz. Measurement is done using the timebase with packets sent to the target with 'ping -s 1' (packet len is 60): * Without this patch: 182 TB ticks * With this patch: 143 TB ticks As a comparison, if we set the copybreak limit to 0, then we get 148 TB ticks. It means that without this patch, duration is even worse when copying received data to a new skb instead of allocating a new skb for next packet to be received Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8572763 commit 070e1f0

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

‎drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,10 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
226226
if (sc & BD_ENET_RX_OV)
227227
fep->stats.rx_crc_errors++;
228228

229-
skb = fep->rx_skbuff[curidx];
230-
231-
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
232-
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
233-
DMA_FROM_DEVICE);
234-
235-
skbn = skb;
236-
229+
skbn = fep->rx_skbuff[curidx];
237230
} else {
238231
skb = fep->rx_skbuff[curidx];
239232

240-
dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
241-
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
242-
DMA_FROM_DEVICE);
243-
244233
/*
245234
* Process the incoming frame.
246235
*/
@@ -256,12 +245,30 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
256245
skb_copy_from_linear_data(skb,
257246
skbn->data, pkt_len);
258247
swap(skb, skbn);
248+
dma_sync_single_for_cpu(fep->dev,
249+
CBDR_BUFADDR(bdp),
250+
L1_CACHE_ALIGN(pkt_len),
251+
DMA_FROM_DEVICE);
259252
}
260253
} else {
261254
skbn = netdev_alloc_skb(dev, ENET_RX_FRSIZE);
262255

263-
if (skbn)
256+
if (skbn) {
257+
dma_addr_t dma;
258+
264259
skb_align(skbn, ENET_RX_ALIGN);
260+
261+
dma_unmap_single(fep->dev,
262+
CBDR_BUFADDR(bdp),
263+
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
264+
DMA_FROM_DEVICE);
265+
266+
dma = dma_map_single(fep->dev,
267+
skbn->data,
268+
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
269+
DMA_FROM_DEVICE);
270+
CBDW_BUFADDR(bdp, dma);
271+
}
265272
}
266273

267274
if (skbn != NULL) {
@@ -276,9 +283,6 @@ static int fs_enet_napi(struct napi_struct *napi, int budget)
276283
}
277284

278285
fep->rx_skbuff[curidx] = skbn;
279-
CBDW_BUFADDR(bdp, dma_map_single(fep->dev, skbn->data,
280-
L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
281-
DMA_FROM_DEVICE));
282286
CBDW_DATLEN(bdp, 0);
283287
CBDW_SC(bdp, (sc & ~BD_ENET_RX_STATS) | BD_ENET_RX_EMPTY);
284288

0 commit comments

Comments
 (0)