Skip to content

Commit cfbfd86

Browse files
tlendackydavem330
authored andcommitted
amd-xgbe: Fix DMA API debug warning
When running a kernel configured with CONFIG_DMA_API_DEBUG=y a warning is issued: DMA-API: device driver tries to sync DMA memory it has not allocated This warning is the result of mapping the full range of the Rx buffer pages allocated and then performing a dma_sync_single_for_cpu against a calculated DMA address. The proper thing to do is to use the dma_sync_single_range_for_cpu with a base DMA address and an offset. Reported-by: Kim Phillips <[email protected]> Signed-off-by: Tom Lendacky <[email protected]> Tested-by: Kim Phillips <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 95ec655 commit cfbfd86

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

drivers/net/ethernet/amd/xgbe/xgbe-desc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ static void xgbe_set_buffer_data(struct xgbe_buffer_data *bd,
303303
get_page(pa->pages);
304304
bd->pa = *pa;
305305

306-
bd->dma = pa->pages_dma + pa->pages_offset;
306+
bd->dma_base = pa->pages_dma;
307+
bd->dma_off = pa->pages_offset;
307308
bd->dma_len = len;
308309

309310
pa->pages_offset += len;

drivers/net/ethernet/amd/xgbe/xgbe-dev.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
11101110
unsigned int rx_usecs = pdata->rx_usecs;
11111111
unsigned int rx_frames = pdata->rx_frames;
11121112
unsigned int inte;
1113+
dma_addr_t hdr_dma, buf_dma;
11131114

11141115
if (!rx_usecs && !rx_frames) {
11151116
/* No coalescing, interrupt for every descriptor */
@@ -1129,10 +1130,12 @@ static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
11291130
* Set buffer 2 (hi) address to buffer dma address (hi) and
11301131
* set control bits OWN and INTE
11311132
*/
1132-
rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->rx.hdr.dma));
1133-
rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->rx.hdr.dma));
1134-
rdesc->desc2 = cpu_to_le32(lower_32_bits(rdata->rx.buf.dma));
1135-
rdesc->desc3 = cpu_to_le32(upper_32_bits(rdata->rx.buf.dma));
1133+
hdr_dma = rdata->rx.hdr.dma_base + rdata->rx.hdr.dma_off;
1134+
buf_dma = rdata->rx.buf.dma_base + rdata->rx.buf.dma_off;
1135+
rdesc->desc0 = cpu_to_le32(lower_32_bits(hdr_dma));
1136+
rdesc->desc1 = cpu_to_le32(upper_32_bits(hdr_dma));
1137+
rdesc->desc2 = cpu_to_le32(lower_32_bits(buf_dma));
1138+
rdesc->desc3 = cpu_to_le32(upper_32_bits(buf_dma));
11361139

11371140
XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte);
11381141

drivers/net/ethernet/amd/xgbe/xgbe-drv.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,8 +1765,9 @@ static struct sk_buff *xgbe_create_skb(struct xgbe_prv_data *pdata,
17651765
/* Start with the header buffer which may contain just the header
17661766
* or the header plus data
17671767
*/
1768-
dma_sync_single_for_cpu(pdata->dev, rdata->rx.hdr.dma,
1769-
rdata->rx.hdr.dma_len, DMA_FROM_DEVICE);
1768+
dma_sync_single_range_for_cpu(pdata->dev, rdata->rx.hdr.dma_base,
1769+
rdata->rx.hdr.dma_off,
1770+
rdata->rx.hdr.dma_len, DMA_FROM_DEVICE);
17701771

17711772
packet = page_address(rdata->rx.hdr.pa.pages) +
17721773
rdata->rx.hdr.pa.pages_offset;
@@ -1778,8 +1779,11 @@ static struct sk_buff *xgbe_create_skb(struct xgbe_prv_data *pdata,
17781779
len -= copy_len;
17791780
if (len) {
17801781
/* Add the remaining data as a frag */
1781-
dma_sync_single_for_cpu(pdata->dev, rdata->rx.buf.dma,
1782-
rdata->rx.buf.dma_len, DMA_FROM_DEVICE);
1782+
dma_sync_single_range_for_cpu(pdata->dev,
1783+
rdata->rx.buf.dma_base,
1784+
rdata->rx.buf.dma_off,
1785+
rdata->rx.buf.dma_len,
1786+
DMA_FROM_DEVICE);
17831787

17841788
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
17851789
rdata->rx.buf.pa.pages,
@@ -1945,8 +1949,9 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
19451949
if (!skb)
19461950
error = 1;
19471951
} else if (rdesc_len) {
1948-
dma_sync_single_for_cpu(pdata->dev,
1949-
rdata->rx.buf.dma,
1952+
dma_sync_single_range_for_cpu(pdata->dev,
1953+
rdata->rx.buf.dma_base,
1954+
rdata->rx.buf.dma_off,
19501955
rdata->rx.buf.dma_len,
19511956
DMA_FROM_DEVICE);
19521957

drivers/net/ethernet/amd/xgbe/xgbe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ struct xgbe_buffer_data {
337337
struct xgbe_page_alloc pa;
338338
struct xgbe_page_alloc pa_unmap;
339339

340-
dma_addr_t dma;
340+
dma_addr_t dma_base;
341+
unsigned long dma_off;
341342
unsigned int dma_len;
342343
};
343344

0 commit comments

Comments
 (0)