| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 2d7b6e7daf076b63f461ce9c4ec6022ddc3d15bb Mon Sep 17 00:00:00 2001 | 
|  | 2 | From: Camelia Groza <camelia.groza@nxp.com> | 
|  | 3 | Date: Mon, 15 Jan 2018 17:42:42 +0200 | 
|  | 4 | Subject: [PATCH] sdk_dpaa: update comments about recycling and back-pointer | 
|  | 5 | storage | 
|  | 6 |  | 
|  | 7 | Signed-off-by: Camelia Groza <camelia.groza@nxp.com> | 
|  | 8 | --- | 
|  | 9 | drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_sg.c | 18 ++++++++++++++++-- | 
|  | 10 | 1 file changed, 16 insertions(+), 2 deletions(-) | 
|  | 11 |  | 
|  | 12 | --- a/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_sg.c | 
|  | 13 | +++ b/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_sg.c | 
|  | 14 | @@ -121,6 +121,10 @@ static int _dpa_bp_add_8_bufs(const stru | 
|  | 15 | put_page(virt_to_head_page(new_buf)); | 
|  | 16 | goto build_skb_failed; | 
|  | 17 | } | 
|  | 18 | + | 
|  | 19 | +		/* Store the skb back-pointer before the start of the buffer. | 
|  | 20 | +		 * Otherwise it will be overwritten by the FMan. | 
|  | 21 | +		 */ | 
|  | 22 | DPA_WRITE_SKB_PTR(skb, skbh, new_buf, -1); | 
|  | 23 |  | 
|  | 24 | addr = dma_map_single(dev, new_buf, | 
|  | 25 | @@ -344,7 +348,10 @@ bool dpa_buf_is_recyclable(struct sk_buf | 
|  | 26 | * - buffer address aligned to cacheline bytes | 
|  | 27 | * - offset of data from start of buffer no lower than a minimum value | 
|  | 28 | * - offset of data from start of buffer no higher than a maximum value | 
|  | 29 | +	 * - the skb back-pointer is stored safely | 
|  | 30 | */ | 
|  | 31 | + | 
|  | 32 | +	/* guarantee both the minimum size and the minimum data offset */ | 
|  | 33 | new = min(skb_end_pointer(skb) - min_size, skb->data - min_offset); | 
|  | 34 |  | 
|  | 35 | /* left align to the nearest cacheline */ | 
|  | 36 | @@ -694,6 +701,9 @@ int __hot skb_to_contig_fd(struct dpa_pr | 
|  | 37 | dma_dir = DMA_BIDIRECTIONAL; | 
|  | 38 | dma_map_size = dpa_bp->size; | 
|  | 39 |  | 
|  | 40 | +		/* Store the skb back-pointer before the start of the buffer. | 
|  | 41 | +		 * Otherwise it will be overwritten by the FMan. | 
|  | 42 | +		 */ | 
|  | 43 | DPA_WRITE_SKB_PTR(skb, skbh, buffer_start, -1); | 
|  | 44 | *offset = skb_headroom(skb) - fd->offset; | 
|  | 45 | } else | 
|  | 46 | @@ -711,7 +721,7 @@ int __hot skb_to_contig_fd(struct dpa_pr | 
|  | 47 |  | 
|  | 48 | /* The buffer will be Tx-confirmed, but the TxConf cb must | 
|  | 49 | * necessarily look at our Tx private data to retrieve the | 
|  | 50 | -		 * skbuff. (In short: can't use DPA_WRITE_SKB_PTR() here.) | 
|  | 51 | +		 * skbuff. Store the back-pointer inside the buffer. | 
|  | 52 | */ | 
|  | 53 | DPA_WRITE_SKB_PTR(skb, skbh, buffer_start, 0); | 
|  | 54 | } | 
|  | 55 | @@ -975,7 +985,11 @@ int __hot skb_to_sg_fd(struct dpa_priv_s | 
|  | 56 | fd->length20 = skb->len; | 
|  | 57 | fd->offset = priv->tx_headroom; | 
|  | 58 |  | 
|  | 59 | -	/* DMA map the SGT page */ | 
|  | 60 | +	/* DMA map the SGT page | 
|  | 61 | +	 * | 
|  | 62 | +	 * It's safe to store the skb back-pointer inside the buffer since | 
|  | 63 | +	 * S/G frames are non-recyclable. | 
|  | 64 | +	 */ | 
|  | 65 | DPA_WRITE_SKB_PTR(skb, skbh, sgt_buf, 0); | 
|  | 66 | addr = dma_map_single(dpa_bp->dev, sgt_buf, | 
|  | 67 | priv->tx_headroom + sgt_size, |