Skip to content

Commit 6123429

Browse files
Andre Guedesanguy11
authored andcommitted
igc: Introduce igc_unmap_tx_buffer() helper
In preparation for AF_XDP zero-copy support, encapsulate the code that unmaps Tx buffers into its own local helper so we can reuse it, avoiding code duplication. Signed-off-by: Andre Guedes <[email protected]> Signed-off-by: Vedang Patel <[email protected]> Signed-off-by: Jithu Joseph <[email protected]> Reviewed-by: Maciej Fijalkowski <[email protected]> Tested-by: Dvora Fuxbrumer <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent a27e6e7 commit 6123429

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

drivers/net/ethernet/intel/igc/igc_main.c

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ static void igc_get_hw_control(struct igc_adapter *adapter)
171171
ctrl_ext | IGC_CTRL_EXT_DRV_LOAD);
172172
}
173173

174+
static void igc_unmap_tx_buffer(struct device *dev, struct igc_tx_buffer *buf)
175+
{
176+
dma_unmap_single(dev, dma_unmap_addr(buf, dma),
177+
dma_unmap_len(buf, len), DMA_TO_DEVICE);
178+
179+
dma_unmap_len_set(buf, len, 0);
180+
}
181+
174182
/**
175183
* igc_clean_tx_ring - Free Tx Buffers
176184
* @tx_ring: ring to be cleaned
@@ -188,11 +196,7 @@ static void igc_clean_tx_ring(struct igc_ring *tx_ring)
188196
else
189197
dev_kfree_skb_any(tx_buffer->skb);
190198

191-
/* unmap skb header data */
192-
dma_unmap_single(tx_ring->dev,
193-
dma_unmap_addr(tx_buffer, dma),
194-
dma_unmap_len(tx_buffer, len),
195-
DMA_TO_DEVICE);
199+
igc_unmap_tx_buffer(tx_ring->dev, tx_buffer);
196200

197201
/* check for eop_desc to determine the end of the packet */
198202
eop_desc = tx_buffer->next_to_watch;
@@ -211,10 +215,7 @@ static void igc_clean_tx_ring(struct igc_ring *tx_ring)
211215

212216
/* unmap any remaining paged data */
213217
if (dma_unmap_len(tx_buffer, len))
214-
dma_unmap_page(tx_ring->dev,
215-
dma_unmap_addr(tx_buffer, dma),
216-
dma_unmap_len(tx_buffer, len),
217-
DMA_TO_DEVICE);
218+
igc_unmap_tx_buffer(tx_ring->dev, tx_buffer);
218219
}
219220

220221
/* move us one more past the eop_desc for start of next pkt */
@@ -1219,23 +1220,15 @@ static int igc_tx_map(struct igc_ring *tx_ring,
12191220
/* clear dma mappings for failed tx_buffer_info map */
12201221
while (tx_buffer != first) {
12211222
if (dma_unmap_len(tx_buffer, len))
1222-
dma_unmap_page(tx_ring->dev,
1223-
dma_unmap_addr(tx_buffer, dma),
1224-
dma_unmap_len(tx_buffer, len),
1225-
DMA_TO_DEVICE);
1226-
dma_unmap_len_set(tx_buffer, len, 0);
1223+
igc_unmap_tx_buffer(tx_ring->dev, tx_buffer);
12271224

12281225
if (i-- == 0)
12291226
i += tx_ring->count;
12301227
tx_buffer = &tx_ring->tx_buffer_info[i];
12311228
}
12321229

12331230
if (dma_unmap_len(tx_buffer, len))
1234-
dma_unmap_single(tx_ring->dev,
1235-
dma_unmap_addr(tx_buffer, dma),
1236-
dma_unmap_len(tx_buffer, len),
1237-
DMA_TO_DEVICE);
1238-
dma_unmap_len_set(tx_buffer, len, 0);
1231+
igc_unmap_tx_buffer(tx_ring->dev, tx_buffer);
12391232

12401233
dev_kfree_skb_any(tx_buffer->skb);
12411234
tx_buffer->skb = NULL;
@@ -2317,14 +2310,7 @@ static bool igc_clean_tx_irq(struct igc_q_vector *q_vector, int napi_budget)
23172310
else
23182311
napi_consume_skb(tx_buffer->skb, napi_budget);
23192312

2320-
/* unmap skb header data */
2321-
dma_unmap_single(tx_ring->dev,
2322-
dma_unmap_addr(tx_buffer, dma),
2323-
dma_unmap_len(tx_buffer, len),
2324-
DMA_TO_DEVICE);
2325-
2326-
/* clear tx_buffer data */
2327-
dma_unmap_len_set(tx_buffer, len, 0);
2313+
igc_unmap_tx_buffer(tx_ring->dev, tx_buffer);
23282314

23292315
/* clear last DMA location and unmap remaining buffers */
23302316
while (tx_desc != eop_desc) {
@@ -2338,13 +2324,8 @@ static bool igc_clean_tx_irq(struct igc_q_vector *q_vector, int napi_budget)
23382324
}
23392325

23402326
/* unmap any remaining paged data */
2341-
if (dma_unmap_len(tx_buffer, len)) {
2342-
dma_unmap_page(tx_ring->dev,
2343-
dma_unmap_addr(tx_buffer, dma),
2344-
dma_unmap_len(tx_buffer, len),
2345-
DMA_TO_DEVICE);
2346-
dma_unmap_len_set(tx_buffer, len, 0);
2347-
}
2327+
if (dma_unmap_len(tx_buffer, len))
2328+
igc_unmap_tx_buffer(tx_ring->dev, tx_buffer);
23482329
}
23492330

23502331
/* move us one more past the eop_desc for start of next pkt */

0 commit comments

Comments
 (0)