Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

au1000_eth: stop using virt_to_bus()

The conversion to the dma-mapping API in linux-2.6.11 was incomplete
and left a virt_to_bus() call around. There have been a number of
fixes for DMA mapping API abuse in this driver, but this one always
slipped through.

Change it to just use the existing dma_addr_t pointer, and make it
use the correct types throughout the driver to make it easier to
understand the virtual vs dma address spaces.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Manuel Lauss <manuel.lauss@gmail.com>
Link: https://lore.kernel.org/r/20220607090206.19830-1-arnd@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Arnd Bergmann and committed by
Jakub Kicinski
a6958951 f638a84a

+13 -13
+11 -11
drivers/net/ethernet/amd/au1000_eth.c
··· 820 820 pr_cont("\n"); 821 821 } 822 822 } 823 - prxd->buff_stat = (u32)(pDB->dma_addr | RX_DMA_ENABLE); 823 + prxd->buff_stat = lower_32_bits(pDB->dma_addr) | RX_DMA_ENABLE; 824 824 aup->rx_head = (aup->rx_head + 1) & (NUM_RX_DMA - 1); 825 825 wmb(); /* drain writebuffer */ 826 826 ··· 996 996 ps->tx_packets++; 997 997 ps->tx_bytes += ptxd->len; 998 998 999 - ptxd->buff_stat = pDB->dma_addr | TX_DMA_ENABLE; 999 + ptxd->buff_stat = lower_32_bits(pDB->dma_addr) | TX_DMA_ENABLE; 1000 1000 wmb(); /* drain writebuffer */ 1001 1001 dev_kfree_skb(skb); 1002 1002 aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1); ··· 1131 1131 /* Allocate the data buffers 1132 1132 * Snooping works fine with eth on all au1xxx 1133 1133 */ 1134 - aup->vaddr = (u32)dma_alloc_coherent(&pdev->dev, MAX_BUF_SIZE * 1135 - (NUM_TX_BUFFS + NUM_RX_BUFFS), 1136 - &aup->dma_addr, 0); 1134 + aup->vaddr = dma_alloc_coherent(&pdev->dev, MAX_BUF_SIZE * 1135 + (NUM_TX_BUFFS + NUM_RX_BUFFS), 1136 + &aup->dma_addr, 0); 1137 1137 if (!aup->vaddr) { 1138 1138 dev_err(&pdev->dev, "failed to allocate data buffers\n"); 1139 1139 err = -ENOMEM; ··· 1234 1234 for (i = 0; i < (NUM_TX_BUFFS+NUM_RX_BUFFS); i++) { 1235 1235 pDB->pnext = pDBfree; 1236 1236 pDBfree = pDB; 1237 - pDB->vaddr = (u32 *)((unsigned)aup->vaddr + MAX_BUF_SIZE*i); 1238 - pDB->dma_addr = (dma_addr_t)virt_to_bus(pDB->vaddr); 1237 + pDB->vaddr = aup->vaddr + MAX_BUF_SIZE * i; 1238 + pDB->dma_addr = aup->dma_addr + MAX_BUF_SIZE * i; 1239 1239 pDB++; 1240 1240 } 1241 1241 aup->pDBfree = pDBfree; ··· 1246 1246 if (!pDB) 1247 1247 goto err_out; 1248 1248 1249 - aup->rx_dma_ring[i]->buff_stat = (unsigned)pDB->dma_addr; 1249 + aup->rx_dma_ring[i]->buff_stat = lower_32_bits(pDB->dma_addr); 1250 1250 aup->rx_db_inuse[i] = pDB; 1251 1251 } 1252 1252 ··· 1255 1255 if (!pDB) 1256 1256 goto err_out; 1257 1257 1258 - aup->tx_dma_ring[i]->buff_stat = (unsigned)pDB->dma_addr; 1258 + aup->tx_dma_ring[i]->buff_stat = lower_32_bits(pDB->dma_addr); 1259 1259 aup->tx_dma_ring[i]->len = 0; 1260 1260 aup->tx_db_inuse[i] = pDB; 1261 1261 } ··· 1310 1310 iounmap(aup->mac); 1311 1311 err_remap1: 1312 1312 dma_free_coherent(&pdev->dev, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), 1313 - (void *)aup->vaddr, aup->dma_addr); 1313 + aup->vaddr, aup->dma_addr); 1314 1314 err_vaddr: 1315 1315 free_netdev(dev); 1316 1316 err_alloc: ··· 1343 1343 au1000_ReleaseDB(aup, aup->tx_db_inuse[i]); 1344 1344 1345 1345 dma_free_coherent(&pdev->dev, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), 1346 - (void *)aup->vaddr, aup->dma_addr); 1346 + aup->vaddr, aup->dma_addr); 1347 1347 1348 1348 iounmap(aup->macdma); 1349 1349 iounmap(aup->mac);
+2 -2
drivers/net/ethernet/amd/au1000_eth.h
··· 106 106 struct mac_reg *mac; /* mac registers */ 107 107 u32 *enable; /* address of MAC Enable Register */ 108 108 void __iomem *macdma; /* base of MAC DMA port */ 109 - u32 vaddr; /* virtual address of rx/tx buffers */ 110 - dma_addr_t dma_addr; /* dma address of rx/tx buffers */ 109 + void *vaddr; /* virtual address of rx/tx buffers */ 110 + dma_addr_t dma_addr; /* dma address of rx/tx buffers */ 111 111 112 112 spinlock_t lock; /* Serialise access to device */ 113 113