Commit 08eb2397 authored by Ioana Radulescu's avatar Ioana Radulescu Committed by Greg Kroah-Hartman

staging: fsl-dpaa2/eth: Fix address translations

Use the correct mechanisms for translating a DMA-mapped IOVA
address into a virtual one. Without this fix, once SMMU is
enabled on Layerscape platforms, the Ethernet driver throws
IOMMU translation faults.
Signed-off-by: default avatarNipun Gupta <nipun.gupta@nxp.com>
Signed-off-by: default avatarIoana Radulescu <ruxandra.radulescu@nxp.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3ddf70e1
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/msi.h> #include <linux/msi.h>
#include <linux/kthread.h> #include <linux/kthread.h>
#include <linux/iommu.h>
#include "../../fsl-mc/include/mc.h" #include "../../fsl-mc/include/mc.h"
#include "../../fsl-mc/include/mc-sys.h" #include "../../fsl-mc/include/mc-sys.h"
...@@ -54,6 +55,16 @@ MODULE_DESCRIPTION("Freescale DPAA2 Ethernet Driver"); ...@@ -54,6 +55,16 @@ MODULE_DESCRIPTION("Freescale DPAA2 Ethernet Driver");
const char dpaa2_eth_drv_version[] = "0.1"; const char dpaa2_eth_drv_version[] = "0.1";
static void *dpaa2_iova_to_virt(struct iommu_domain *domain,
dma_addr_t iova_addr)
{
phys_addr_t phys_addr;
phys_addr = domain ? iommu_iova_to_phys(domain, iova_addr) : iova_addr;
return phys_to_virt(phys_addr);
}
static void validate_rx_csum(struct dpaa2_eth_priv *priv, static void validate_rx_csum(struct dpaa2_eth_priv *priv,
u32 fd_status, u32 fd_status,
struct sk_buff *skb) struct sk_buff *skb)
...@@ -98,12 +109,11 @@ static void free_rx_fd(struct dpaa2_eth_priv *priv, ...@@ -98,12 +109,11 @@ static void free_rx_fd(struct dpaa2_eth_priv *priv,
sgt = vaddr + dpaa2_fd_get_offset(fd); sgt = vaddr + dpaa2_fd_get_offset(fd);
for (i = 0; i < DPAA2_ETH_MAX_SG_ENTRIES; i++) { for (i = 0; i < DPAA2_ETH_MAX_SG_ENTRIES; i++) {
addr = dpaa2_sg_get_addr(&sgt[i]); addr = dpaa2_sg_get_addr(&sgt[i]);
sg_vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr);
dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE, dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
sg_vaddr = phys_to_virt(addr);
skb_free_frag(sg_vaddr); skb_free_frag(sg_vaddr);
if (dpaa2_sg_is_final(&sgt[i])) if (dpaa2_sg_is_final(&sgt[i]))
break; break;
} }
...@@ -159,10 +169,10 @@ static struct sk_buff *build_frag_skb(struct dpaa2_eth_priv *priv, ...@@ -159,10 +169,10 @@ static struct sk_buff *build_frag_skb(struct dpaa2_eth_priv *priv,
/* Get the address and length from the S/G entry */ /* Get the address and length from the S/G entry */
sg_addr = dpaa2_sg_get_addr(sge); sg_addr = dpaa2_sg_get_addr(sge);
sg_vaddr = dpaa2_iova_to_virt(priv->iommu_domain, sg_addr);
dma_unmap_single(dev, sg_addr, DPAA2_ETH_RX_BUF_SIZE, dma_unmap_single(dev, sg_addr, DPAA2_ETH_RX_BUF_SIZE,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
sg_vaddr = phys_to_virt(sg_addr);
sg_length = dpaa2_sg_get_len(sge); sg_length = dpaa2_sg_get_len(sge);
if (i == 0) { if (i == 0) {
...@@ -222,8 +232,8 @@ static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv, ...@@ -222,8 +232,8 @@ static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv,
/* Tracing point */ /* Tracing point */
trace_dpaa2_rx_fd(priv->net_dev, fd); trace_dpaa2_rx_fd(priv->net_dev, fd);
vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr);
dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE, DMA_FROM_DEVICE); dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE, DMA_FROM_DEVICE);
vaddr = phys_to_virt(addr);
prefetch(vaddr + priv->buf_layout.private_data_size); prefetch(vaddr + priv->buf_layout.private_data_size);
prefetch(vaddr + dpaa2_fd_get_offset(fd)); prefetch(vaddr + dpaa2_fd_get_offset(fd));
...@@ -490,7 +500,7 @@ static void free_tx_fd(const struct dpaa2_eth_priv *priv, ...@@ -490,7 +500,7 @@ static void free_tx_fd(const struct dpaa2_eth_priv *priv,
struct dpaa2_fas *fas; struct dpaa2_fas *fas;
fd_addr = dpaa2_fd_get_addr(fd); fd_addr = dpaa2_fd_get_addr(fd);
skbh = phys_to_virt(fd_addr); skbh = dpaa2_iova_to_virt(priv->iommu_domain, fd_addr);
if (fd_format == dpaa2_fd_single) { if (fd_format == dpaa2_fd_single) {
skb = *skbh; skb = *skbh;
...@@ -802,10 +812,11 @@ static void drain_bufs(struct dpaa2_eth_priv *priv, int count) ...@@ -802,10 +812,11 @@ static void drain_bufs(struct dpaa2_eth_priv *priv, int count)
} }
for (i = 0; i < ret; i++) { for (i = 0; i < ret; i++) {
/* Same logic as on regular Rx path */ /* Same logic as on regular Rx path */
vaddr = dpaa2_iova_to_virt(priv->iommu_domain,
buf_array[i]);
dma_unmap_single(dev, buf_array[i], dma_unmap_single(dev, buf_array[i],
DPAA2_ETH_RX_BUF_SIZE, DPAA2_ETH_RX_BUF_SIZE,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
vaddr = phys_to_virt(buf_array[i]);
skb_free_frag(vaddr); skb_free_frag(vaddr);
} }
} while (ret); } while (ret);
...@@ -2358,6 +2369,8 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev) ...@@ -2358,6 +2369,8 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
priv = netdev_priv(net_dev); priv = netdev_priv(net_dev);
priv->net_dev = net_dev; priv->net_dev = net_dev;
priv->iommu_domain = iommu_get_domain_for_dev(dev);
/* Obtain a MC portal */ /* Obtain a MC portal */
err = fsl_mc_portal_allocate(dpni_dev, FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, err = fsl_mc_portal_allocate(dpni_dev, FSL_MC_IO_ATOMIC_CONTEXT_PORTAL,
&priv->mc_io); &priv->mc_io);
......
...@@ -301,6 +301,7 @@ struct dpaa2_eth_priv { ...@@ -301,6 +301,7 @@ struct dpaa2_eth_priv {
struct fsl_mc_device *dpbp_dev; struct fsl_mc_device *dpbp_dev;
struct dpbp_attr dpbp_attrs; struct dpbp_attr dpbp_attrs;
struct iommu_domain *iommu_domain;
u16 tx_qdid; u16 tx_qdid;
struct fsl_mc_io *mc_io; struct fsl_mc_io *mc_io;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment