Skip to content

Commit

Permalink
crypto: caam/qi - fix address translations with IOMMU enabled
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Horia Geantă authored and Herbert Xu committed May 23, 2019
1 parent 6b17568 commit b2b2ee3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/crypto/caam/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*
Expand Down
2 changes: 2 additions & 0 deletions drivers/crypto/caam/intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions drivers/crypto/caam/qi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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");
Expand Down Expand Up @@ -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))
Expand All @@ -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");
Expand Down

0 comments on commit b2b2ee3

Please sign in to comment.