Skip to content

Commit c9f14bf

Browse files
Alexander DuyckJeff Kirsher
authored andcommitted
igb: Use dma_unmap_addr and dma_unmap_len defines
This change is meant to improve performance on systems that do not require the DMA unmap calls. On those systems we do not need to make use of the unmap address for Tx or the unmap length so we can drop both thereby reducing the size of the Tx buffer info structure. In addition I have changed the logic to check for unmap length instead of unmap address when checking to see if a buffer needs to be unmapped from DMA use. The reasons for this change is that on some platforms it is possible to receive a valid DMA address of 0 from an IOMMU. Signed-off-by: Alexander Duyck <[email protected]> Tested-by: Aaron Brown <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent a57fe23 commit c9f14bf

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

drivers/net/ethernet/intel/igb/igb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ struct igb_tx_buffer {
168168
unsigned int bytecount;
169169
u16 gso_segs;
170170
__be16 protocol;
171-
dma_addr_t dma;
172-
u32 length;
171+
DEFINE_DMA_UNMAP_ADDR(dma);
172+
DEFINE_DMA_UNMAP_LEN(len);
173173
u32 tx_flags;
174174
};
175175

drivers/net/ethernet/intel/igb/igb_main.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ static void igb_dump(struct igb_adapter *adapter)
403403
buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
404404
pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
405405
n, tx_ring->next_to_use, tx_ring->next_to_clean,
406-
(u64)buffer_info->dma,
407-
buffer_info->length,
406+
(u64)dma_unmap_addr(buffer_info, dma),
407+
dma_unmap_len(buffer_info, len),
408408
buffer_info->next_to_watch,
409409
(u64)buffer_info->time_stamp);
410410
}
@@ -455,8 +455,8 @@ static void igb_dump(struct igb_adapter *adapter)
455455
" %04X %p %016llX %p%s\n", i,
456456
le64_to_cpu(u0->a),
457457
le64_to_cpu(u0->b),
458-
(u64)buffer_info->dma,
459-
buffer_info->length,
458+
(u64)dma_unmap_addr(buffer_info, dma),
459+
dma_unmap_len(buffer_info, len),
460460
buffer_info->next_to_watch,
461461
(u64)buffer_info->time_stamp,
462462
buffer_info->skb, next_desc);
@@ -465,7 +465,8 @@ static void igb_dump(struct igb_adapter *adapter)
465465
print_hex_dump(KERN_INFO, "",
466466
DUMP_PREFIX_ADDRESS,
467467
16, 1, buffer_info->skb->data,
468-
buffer_info->length, true);
468+
dma_unmap_len(buffer_info, len),
469+
true);
469470
}
470471
}
471472

@@ -3198,20 +3199,20 @@ void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
31983199
{
31993200
if (tx_buffer->skb) {
32003201
dev_kfree_skb_any(tx_buffer->skb);
3201-
if (tx_buffer->dma)
3202+
if (dma_unmap_len(tx_buffer, len))
32023203
dma_unmap_single(ring->dev,
3203-
tx_buffer->dma,
3204-
tx_buffer->length,
3204+
dma_unmap_addr(tx_buffer, dma),
3205+
dma_unmap_len(tx_buffer, len),
32053206
DMA_TO_DEVICE);
3206-
} else if (tx_buffer->dma) {
3207+
} else if (dma_unmap_len(tx_buffer, len)) {
32073208
dma_unmap_page(ring->dev,
3208-
tx_buffer->dma,
3209-
tx_buffer->length,
3209+
dma_unmap_addr(tx_buffer, dma),
3210+
dma_unmap_len(tx_buffer, len),
32103211
DMA_TO_DEVICE);
32113212
}
32123213
tx_buffer->next_to_watch = NULL;
32133214
tx_buffer->skb = NULL;
3214-
tx_buffer->dma = 0;
3215+
dma_unmap_len_set(tx_buffer, len, 0);
32153216
/* buffer_info must be completely set up in the transmit path */
32163217
}
32173218

@@ -4206,7 +4207,7 @@ static void igb_tx_map(struct igb_ring *tx_ring,
42064207
const u8 hdr_len)
42074208
{
42084209
struct sk_buff *skb = first->skb;
4209-
struct igb_tx_buffer *tx_buffer_info;
4210+
struct igb_tx_buffer *tx_buffer;
42104211
union e1000_adv_tx_desc *tx_desc;
42114212
dma_addr_t dma;
42124213
struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
@@ -4227,8 +4228,8 @@ static void igb_tx_map(struct igb_ring *tx_ring,
42274228
goto dma_error;
42284229

42294230
/* record length, and DMA address */
4230-
first->length = size;
4231-
first->dma = dma;
4231+
dma_unmap_len_set(first, len, size);
4232+
dma_unmap_addr_set(first, dma, dma);
42324233
tx_desc->read.buffer_addr = cpu_to_le64(dma);
42334234

42344235
for (;;) {
@@ -4270,9 +4271,9 @@ static void igb_tx_map(struct igb_ring *tx_ring,
42704271
if (dma_mapping_error(tx_ring->dev, dma))
42714272
goto dma_error;
42724273

4273-
tx_buffer_info = &tx_ring->tx_buffer_info[i];
4274-
tx_buffer_info->length = size;
4275-
tx_buffer_info->dma = dma;
4274+
tx_buffer = &tx_ring->tx_buffer_info[i];
4275+
dma_unmap_len_set(tx_buffer, len, size);
4276+
dma_unmap_addr_set(tx_buffer, dma, dma);
42764277

42774278
tx_desc->read.olinfo_status = 0;
42784279
tx_desc->read.buffer_addr = cpu_to_le64(dma);
@@ -4323,9 +4324,9 @@ static void igb_tx_map(struct igb_ring *tx_ring,
43234324

43244325
/* clear dma mappings for failed tx_buffer_info map */
43254326
for (;;) {
4326-
tx_buffer_info = &tx_ring->tx_buffer_info[i];
4327-
igb_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
4328-
if (tx_buffer_info == first)
4327+
tx_buffer = &tx_ring->tx_buffer_info[i];
4328+
igb_unmap_and_free_tx_resource(tx_ring, tx_buffer);
4329+
if (tx_buffer == first)
43294330
break;
43304331
if (i == 0)
43314332
i = tx_ring->count;
@@ -5716,18 +5717,19 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
57165717

57175718
/* free the skb */
57185719
dev_kfree_skb_any(tx_buffer->skb);
5719-
tx_buffer->skb = NULL;
57205720

57215721
/* unmap skb header data */
57225722
dma_unmap_single(tx_ring->dev,
5723-
tx_buffer->dma,
5724-
tx_buffer->length,
5723+
dma_unmap_addr(tx_buffer, dma),
5724+
dma_unmap_len(tx_buffer, len),
57255725
DMA_TO_DEVICE);
57265726

5727+
/* clear tx_buffer data */
5728+
tx_buffer->skb = NULL;
5729+
dma_unmap_len_set(tx_buffer, len, 0);
5730+
57275731
/* clear last DMA location and unmap remaining buffers */
57285732
while (tx_desc != eop_desc) {
5729-
tx_buffer->dma = 0;
5730-
57315733
tx_buffer++;
57325734
tx_desc++;
57335735
i++;
@@ -5738,17 +5740,15 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
57385740
}
57395741

57405742
/* unmap any remaining paged data */
5741-
if (tx_buffer->dma) {
5743+
if (dma_unmap_len(tx_buffer, len)) {
57425744
dma_unmap_page(tx_ring->dev,
5743-
tx_buffer->dma,
5744-
tx_buffer->length,
5745+
dma_unmap_addr(tx_buffer, dma),
5746+
dma_unmap_len(tx_buffer, len),
57455747
DMA_TO_DEVICE);
5748+
dma_unmap_len_set(tx_buffer, len, 0);
57465749
}
57475750
}
57485751

5749-
/* clear last DMA location */
5750-
tx_buffer->dma = 0;
5751-
57525752
/* move us one more past the eop_desc for start of next pkt */
57535753
tx_buffer++;
57545754
tx_desc++;

0 commit comments

Comments
 (0)