crypto: caam/qi - don't allocate an extra platform device
authorHoria Geantă <horia.geanta@nxp.com>
Fri, 3 May 2019 14:17:40 +0000 (17:17 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 23 May 2019 06:01:04 +0000 (14:01 +0800)
Use the controller device for caam/qi instead of allocating
a new platform device.
This is needed as a preparation to add support for working behind an
SMMU. A platform device allocated using platform_device_register_full()
is not completely set up - most importantly .dma_configure()
is not called.

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

index 2737aa2875c041aa0805ee8204f2a688aa374edf..f3095933556748091ff04579df8d1536bd1e7784 100644 (file)
@@ -2443,7 +2443,7 @@ static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam,
        ctx->cdata.algtype = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
        ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
 
-       ctx->qidev = priv->qidev;
+       ctx->qidev = ctx->jrdev->parent;
 
        spin_lock_init(&ctx->lock);
        ctx->drv_ctx[ENCRYPT] = NULL;
@@ -2602,7 +2602,7 @@ int caam_qi_algapi_init(struct device *ctrldev)
 
                err = crypto_register_skcipher(&t_alg->skcipher);
                if (err) {
-                       dev_warn(priv->qidev, "%s alg registration failed\n",
+                       dev_warn(ctrldev, "%s alg registration failed\n",
                                 t_alg->skcipher.base.cra_driver_name);
                        continue;
                }
@@ -2658,7 +2658,7 @@ int caam_qi_algapi_init(struct device *ctrldev)
        }
 
        if (registered)
-               dev_info(priv->qidev, "algorithms registered in /proc/crypto\n");
+               dev_info(ctrldev, "algorithms registered in /proc/crypto\n");
 
        return err;
 }
index 36c2f15100a4060b88a8f3f008a6168f1a6463bc..38bcbbccdfda42336e80aba54e2b606258d0a806 100644 (file)
@@ -323,8 +323,8 @@ static int caam_remove(struct platform_device *pdev)
        of_platform_depopulate(ctrldev);
 
 #ifdef CONFIG_CAAM_QI
-       if (ctrlpriv->qidev)
-               caam_qi_shutdown(ctrlpriv->qidev);
+       if (ctrlpriv->qi_init)
+               caam_qi_shutdown(ctrldev);
 #endif
 
        /*
@@ -900,8 +900,8 @@ caam_remove:
 
 shutdown_qi:
 #ifdef CONFIG_CAAM_QI
-       if (ctrlpriv->qidev)
-               caam_qi_shutdown(ctrlpriv->qidev);
+       if (ctrlpriv->qi_init)
+               caam_qi_shutdown(dev);
 #endif
 iounmap_ctrl:
        iounmap(ctrl);
index 50e24ebc533b5d1b1988640727accb29de4d47fc..c9089da5dbaf0560a78342923050f76d04a48ce9 100644 (file)
@@ -63,10 +63,6 @@ struct caam_drv_private_jr {
  * Driver-private storage for a single CAAM block instance
  */
 struct caam_drv_private {
-#ifdef CONFIG_CAAM_QI
-       struct device *qidev;
-#endif
-
        /* Physical-presence section */
        struct caam_ctrl __iomem *ctrl; /* controller region */
        struct caam_deco __iomem *deco; /* DECO/CCB views */
@@ -80,6 +76,9 @@ struct caam_drv_private {
         */
        u8 total_jobrs;         /* Total Job Rings in device */
        u8 qi_present;          /* Nonzero if QI present in device */
+#ifdef CONFIG_CAAM_QI
+       u8 qi_init;             /* Nonzero if QI has been initialized */
+#endif
        u8 mc_en;               /* Nonzero if MC f/w is active */
        int secvio_irq;         /* Security violation interrupt number */
        int virt_en;            /* Virtualization enabled in CAAM */
index 2d9b0485141fbfc74f13c51912ac402fe4fe8aba..46fca2c9fb24694217ea43b84bc165ba6ff21938 100644 (file)
@@ -4,7 +4,7 @@
  * Queue Interface backend functionality
  *
  * Copyright 2013-2016 Freescale Semiconductor, Inc.
- * Copyright 2016-2017 NXP
+ * Copyright 2016-2017, 2019 NXP
  */
 
 #include <linux/cpumask.h>
@@ -59,11 +59,9 @@ static DEFINE_PER_CPU(int, last_cpu);
 /*
  * caam_qi_priv - CAAM QI backend private params
  * @cgr: QMan congestion group
- * @qi_pdev: platform device for QI backend
  */
 struct caam_qi_priv {
        struct qman_cgr cgr;
-       struct platform_device *qi_pdev;
 };
 
 static struct caam_qi_priv qipriv ____cacheline_aligned;
@@ -491,7 +489,7 @@ EXPORT_SYMBOL(caam_drv_ctx_rel);
 void caam_qi_shutdown(struct device *qidev)
 {
        int i;
-       struct caam_qi_priv *priv = dev_get_drvdata(qidev);
+       struct caam_qi_priv *priv = &qipriv;
        const cpumask_t *cpus = qman_affine_cpus();
 
        for_each_cpu(i, cpus) {
@@ -509,8 +507,6 @@ void caam_qi_shutdown(struct device *qidev)
        qman_release_cgrid(priv->cgr.cgrid);
 
        kmem_cache_destroy(qi_cache);
-
-       platform_device_unregister(priv->qi_pdev);
 }
 
 static void cgr_cb(struct qman_portal *qm, struct qman_cgr *cgr, int congested)
@@ -695,33 +691,17 @@ static void free_rsp_fqs(void)
 int caam_qi_init(struct platform_device *caam_pdev)
 {
        int err, i;
-       struct platform_device *qi_pdev;
        struct device *ctrldev = &caam_pdev->dev, *qidev;
        struct caam_drv_private *ctrlpriv;
        const cpumask_t *cpus = qman_affine_cpus();
-       static struct platform_device_info qi_pdev_info = {
-               .name = "caam_qi",
-               .id = PLATFORM_DEVID_NONE
-       };
-
-       qi_pdev_info.parent = ctrldev;
-       qi_pdev_info.dma_mask = dma_get_mask(ctrldev);
-       qi_pdev = platform_device_register_full(&qi_pdev_info);
-       if (IS_ERR(qi_pdev))
-               return PTR_ERR(qi_pdev);
-       set_dma_ops(&qi_pdev->dev, get_dma_ops(ctrldev));
 
        ctrlpriv = dev_get_drvdata(ctrldev);
-       qidev = &qi_pdev->dev;
-
-       qipriv.qi_pdev = qi_pdev;
-       dev_set_drvdata(qidev, &qipriv);
+       qidev = ctrldev;
 
        /* Initialize the congestion detection */
        err = init_cgr(qidev);
        if (err) {
                dev_err(qidev, "CGR initialization failed: %d\n", err);
-               platform_device_unregister(qi_pdev);
                return err;
        }
 
@@ -730,7 +710,6 @@ int caam_qi_init(struct platform_device *caam_pdev)
        if (err) {
                dev_err(qidev, "Can't allocate CAAM response FQs: %d\n", err);
                free_rsp_fqs();
-               platform_device_unregister(qi_pdev);
                return err;
        }
 
@@ -753,15 +732,11 @@ int caam_qi_init(struct platform_device *caam_pdev)
                napi_enable(irqtask);
        }
 
-       /* Hook up QI device to parent controlling caam device */
-       ctrlpriv->qidev = qidev;
-
        qi_cache = kmem_cache_create("caamqicache", CAAM_QI_MEMCACHE_SIZE, 0,
                                     SLAB_CACHE_DMA, NULL);
        if (!qi_cache) {
                dev_err(qidev, "Can't allocate CAAM cache\n");
                free_rsp_fqs();
-               platform_device_unregister(qi_pdev);
                return -ENOMEM;
        }
 
@@ -769,6 +744,8 @@ int caam_qi_init(struct platform_device *caam_pdev)
        debugfs_create_file("qi_congested", 0444, ctrlpriv->ctl,
                            &times_congested, &caam_fops_u64_ro);
 #endif
+
+       ctrlpriv->qi_init = 1;
        dev_info(qidev, "Linux CAAM Queue I/F driver initialised\n");
        return 0;
 }