crypto: caam/qi - fix address translations with IOMMU enabled
authorHoria Geantă <horia.geanta@nxp.com>
Fri, 3 May 2019 14:17:41 +0000 (17:17 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 23 May 2019 06:01:04 +0000 (14:01 +0800)
When IOMMU is enabled, iova -> phys address translation should be
performed using iommu_ops, not dma_to_phys().

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/caam/ctrl.c
drivers/crypto/caam/intern.h
drivers/crypto/caam/qi.c

index 38bcbbccdfda42336e80aba54e2b606258d0a806..bbde6efce8af212396c0b47f7882bb2c799346f3 100644 (file)
@@ -702,6 +702,7 @@ static int caam_probe(struct platform_device *pdev)
        }
 
        ctrlpriv->era = caam_get_era(ctrl);
+       ctrlpriv->domain = iommu_get_domain_for_dev(dev);
 
 #ifdef CONFIG_DEBUG_FS
        /*
index c9089da5dbaf0560a78342923050f76d04a48ce9..6af84bbc612c7c36629c30ac758271b149e0e9d1 100644 (file)
@@ -70,6 +70,8 @@ struct caam_drv_private {
        struct caam_queue_if __iomem *qi; /* QI control region */
        struct caam_job_ring __iomem *jr[4];    /* JobR's register space */
 
+       struct iommu_domain *domain;
+
        /*
         * Detected geometry block. Filled in from device tree if powerpc,
         * or from register-based version detection code
index 46fca2c9fb24694217ea43b84bc165ba6ff21938..0fe618e3804a91c176d97c90165ae50beb80c98f 100644 (file)
@@ -94,6 +94,16 @@ static u64 times_congested;
  */
 static struct kmem_cache *qi_cache;
 
+static void *caam_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);
+}
+
 int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req)
 {
        struct qm_fd fd;
@@ -134,6 +144,7 @@ static void caam_fq_ern_cb(struct qman_portal *qm, struct qman_fq *fq,
        const struct qm_fd *fd;
        struct caam_drv_req *drv_req;
        struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev.dev);
+       struct caam_drv_private *priv = dev_get_drvdata(qidev);
 
        fd = &msg->ern.fd;
 
@@ -142,7 +153,7 @@ static void caam_fq_ern_cb(struct qman_portal *qm, struct qman_fq *fq,
                return;
        }
 
-       drv_req = (struct caam_drv_req *)phys_to_virt(qm_fd_addr_get64(fd));
+       drv_req = caam_iova_to_virt(priv->domain, qm_fd_addr_get64(fd));
        if (!drv_req) {
                dev_err(qidev,
                        "Can't find original request for CAAM response\n");
@@ -549,6 +560,7 @@ static enum qman_cb_dqrr_result caam_rsp_fq_dqrr_cb(struct qman_portal *p,
        struct caam_drv_req *drv_req;
        const struct qm_fd *fd;
        struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev.dev);
+       struct caam_drv_private *priv = dev_get_drvdata(qidev);
        u32 status;
 
        if (caam_qi_napi_schedule(p, caam_napi))
@@ -571,7 +583,7 @@ static enum qman_cb_dqrr_result caam_rsp_fq_dqrr_cb(struct qman_portal *p,
                return qman_cb_dqrr_consume;
        }
 
-       drv_req = (struct caam_drv_req *)phys_to_virt(qm_fd_addr_get64(fd));
+       drv_req = caam_iova_to_virt(priv->domain, qm_fd_addr_get64(fd));
        if (unlikely(!drv_req)) {
                dev_err(qidev,
                        "Can't find original request for caam response\n");