2018-10-10 19:26:48 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-03-13 16:54:26 +08:00
|
|
|
/*
|
|
|
|
* CAAM/SEC 4.x transport/backend driver
|
|
|
|
* JobR backend functionality
|
|
|
|
*
|
2012-06-23 08:48:54 +08:00
|
|
|
* Copyright 2008-2012 Freescale Semiconductor, Inc.
|
2019-05-03 22:17:39 +08:00
|
|
|
* Copyright 2019 NXP
|
2011-03-13 16:54:26 +08:00
|
|
|
*/
|
|
|
|
|
2013-09-18 03:28:33 +08:00
|
|
|
#include <linux/of_irq.h>
|
2013-11-18 12:20:01 +08:00
|
|
|
#include <linux/of_address.h>
|
2013-09-18 03:28:33 +08:00
|
|
|
|
2011-03-13 16:54:26 +08:00
|
|
|
#include "compat.h"
|
2017-07-18 23:30:47 +08:00
|
|
|
#include "ctrl.h"
|
2011-03-13 16:54:26 +08:00
|
|
|
#include "regs.h"
|
|
|
|
#include "jr.h"
|
|
|
|
#include "desc.h"
|
|
|
|
#include "intern.h"
|
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
struct jr_driver_data {
|
|
|
|
/* List of Physical JobR's with the Driver */
|
|
|
|
struct list_head jr_list;
|
|
|
|
spinlock_t jr_alloc_lock; /* jr_list lock */
|
|
|
|
} ____cacheline_aligned;
|
|
|
|
|
|
|
|
static struct jr_driver_data driver_data;
|
2019-05-03 22:17:39 +08:00
|
|
|
static DEFINE_MUTEX(algs_lock);
|
|
|
|
static unsigned int active_devs;
|
|
|
|
|
2020-03-20 00:12:27 +08:00
|
|
|
static void register_algs(struct caam_drv_private_jr *jrpriv,
|
|
|
|
struct device *dev)
|
2019-05-03 22:17:39 +08:00
|
|
|
{
|
|
|
|
mutex_lock(&algs_lock);
|
|
|
|
|
|
|
|
if (++active_devs != 1)
|
|
|
|
goto algs_unlock;
|
|
|
|
|
|
|
|
caam_algapi_init(dev);
|
|
|
|
caam_algapi_hash_init(dev);
|
|
|
|
caam_pkc_init(dev);
|
2020-03-20 00:12:27 +08:00
|
|
|
jrpriv->hwrng = !caam_rng_init(dev);
|
2019-05-03 22:17:39 +08:00
|
|
|
caam_qi_algapi_init(dev);
|
|
|
|
|
|
|
|
algs_unlock:
|
|
|
|
mutex_unlock(&algs_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unregister_algs(void)
|
|
|
|
{
|
|
|
|
mutex_lock(&algs_lock);
|
|
|
|
|
|
|
|
if (--active_devs != 0)
|
|
|
|
goto algs_unlock;
|
|
|
|
|
|
|
|
caam_qi_algapi_exit();
|
|
|
|
|
|
|
|
caam_pkc_exit();
|
|
|
|
caam_algapi_hash_exit();
|
|
|
|
caam_algapi_exit();
|
|
|
|
|
|
|
|
algs_unlock:
|
|
|
|
mutex_unlock(&algs_lock);
|
|
|
|
}
|
2013-10-25 14:31:01 +08:00
|
|
|
|
2020-02-13 01:55:21 +08:00
|
|
|
static void caam_jr_crypto_engine_exit(void *data)
|
|
|
|
{
|
|
|
|
struct device *jrdev = data;
|
|
|
|
struct caam_drv_private_jr *jrpriv = dev_get_drvdata(jrdev);
|
|
|
|
|
|
|
|
/* Free the resources of crypto-engine */
|
|
|
|
crypto_engine_exit(jrpriv->engine);
|
|
|
|
}
|
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
static int caam_reset_hw_jr(struct device *dev)
|
|
|
|
{
|
|
|
|
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
|
|
|
|
unsigned int timeout = 100000;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mask interrupts since we are going to poll
|
|
|
|
* for reset completion status
|
|
|
|
*/
|
2016-05-19 23:11:26 +08:00
|
|
|
clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
|
2013-10-25 14:31:01 +08:00
|
|
|
|
|
|
|
/* initiate flush (required prior to reset) */
|
|
|
|
wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
|
|
|
|
while (((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK) ==
|
|
|
|
JRINT_ERR_HALT_INPROGRESS) && --timeout)
|
|
|
|
cpu_relax();
|
|
|
|
|
|
|
|
if ((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK) !=
|
|
|
|
JRINT_ERR_HALT_COMPLETE || timeout == 0) {
|
|
|
|
dev_err(dev, "failed to flush job ring %d\n", jrp->ridx);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initiate reset */
|
|
|
|
timeout = 100000;
|
|
|
|
wr_reg32(&jrp->rregs->jrcommand, JRCR_RESET);
|
|
|
|
while ((rd_reg32(&jrp->rregs->jrcommand) & JRCR_RESET) && --timeout)
|
|
|
|
cpu_relax();
|
|
|
|
|
|
|
|
if (timeout == 0) {
|
|
|
|
dev_err(dev, "failed to reset job ring %d\n", jrp->ridx);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unmask interrupts */
|
2016-05-19 23:11:26 +08:00
|
|
|
clrsetbits_32(&jrp->rregs->rconfig_lo, JRCFG_IMSK, 0);
|
2013-10-25 14:31:01 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown JobR independent of platform property code
|
|
|
|
*/
|
2016-02-14 23:08:21 +08:00
|
|
|
static int caam_jr_shutdown(struct device *dev)
|
2013-10-25 14:31:01 +08:00
|
|
|
{
|
|
|
|
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = caam_reset_hw_jr(dev);
|
|
|
|
|
2016-11-09 16:46:21 +08:00
|
|
|
tasklet_kill(&jrp->irqtask);
|
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int caam_jr_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct device *jrdev;
|
|
|
|
struct caam_drv_private_jr *jrpriv;
|
|
|
|
|
|
|
|
jrdev = &pdev->dev;
|
|
|
|
jrpriv = dev_get_drvdata(jrdev);
|
|
|
|
|
2020-03-20 00:12:27 +08:00
|
|
|
if (jrpriv->hwrng)
|
|
|
|
caam_rng_exit(jrdev->parent);
|
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
/*
|
2013-10-25 14:31:02 +08:00
|
|
|
* Return EBUSY if job ring already allocated.
|
2013-10-25 14:31:01 +08:00
|
|
|
*/
|
2013-10-25 14:31:02 +08:00
|
|
|
if (atomic_read(&jrpriv->tfm_count)) {
|
2013-10-25 14:31:01 +08:00
|
|
|
dev_err(jrdev, "Device is busy\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2019-05-03 22:17:39 +08:00
|
|
|
/* Unregister JR-based RNG & crypto algorithms */
|
|
|
|
unregister_algs();
|
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
/* Remove the node from Physical JobR list maintained by driver */
|
|
|
|
spin_lock(&driver_data.jr_alloc_lock);
|
|
|
|
list_del(&jrpriv->list_node);
|
|
|
|
spin_unlock(&driver_data.jr_alloc_lock);
|
|
|
|
|
|
|
|
/* Release ring */
|
|
|
|
ret = caam_jr_shutdown(jrdev);
|
|
|
|
if (ret)
|
|
|
|
dev_err(jrdev, "Failed to shut down job ring\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-13 16:54:26 +08:00
|
|
|
/* Main per-ring interrupt handler */
|
|
|
|
static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
|
|
|
|
{
|
|
|
|
struct device *dev = st_dev;
|
|
|
|
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
|
|
|
|
u32 irqstate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the output ring for ready responses, kick
|
2016-11-09 16:46:21 +08:00
|
|
|
* tasklet if jobs done.
|
2011-03-13 16:54:26 +08:00
|
|
|
*/
|
|
|
|
irqstate = rd_reg32(&jrp->rregs->jrintstatus);
|
|
|
|
if (!irqstate)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If JobR error, we got more development work to do
|
|
|
|
* Flag a bug now, but we really need to shut down and
|
|
|
|
* restart the queue (and fix code).
|
|
|
|
*/
|
|
|
|
if (irqstate & JRINT_JR_ERROR) {
|
|
|
|
dev_err(dev, "job ring error: irqstate: %08x\n", irqstate);
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mask valid interrupts */
|
2016-05-19 23:11:26 +08:00
|
|
|
clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
|
2011-03-13 16:54:26 +08:00
|
|
|
|
|
|
|
/* Have valid interrupt at this point, just ACK and trigger */
|
|
|
|
wr_reg32(&jrp->rregs->jrintstatus, irqstate);
|
|
|
|
|
2016-11-09 16:46:21 +08:00
|
|
|
preempt_disable();
|
|
|
|
tasklet_schedule(&jrp->irqtask);
|
|
|
|
preempt_enable();
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
|
|
|
|
2016-11-09 16:46:21 +08:00
|
|
|
/* Deferred service handler, run as interrupt-fired tasklet */
|
|
|
|
static void caam_jr_dequeue(unsigned long devarg)
|
2011-03-13 16:54:26 +08:00
|
|
|
{
|
|
|
|
int hw_idx, sw_idx, i, head, tail;
|
2016-11-09 16:46:21 +08:00
|
|
|
struct device *dev = (struct device *)devarg;
|
2011-03-13 16:54:26 +08:00
|
|
|
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
|
|
|
|
void (*usercall)(struct device *dev, u32 *desc, u32 status, void *arg);
|
|
|
|
u32 *userdesc, userstatus;
|
|
|
|
void *userarg;
|
2019-03-06 02:03:14 +08:00
|
|
|
u32 outring_used = 0;
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2019-03-06 02:03:14 +08:00
|
|
|
while (outring_used ||
|
|
|
|
(outring_used = rd_reg32(&jrp->rregs->outring_used))) {
|
2011-03-13 16:54:26 +08:00
|
|
|
|
locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
Please do not apply this to mainline directly, instead please re-run the
coccinelle script shown below and apply its output.
For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
preference to ACCESS_ONCE(), and new code is expected to use one of the
former. So far, there's been no reason to change most existing uses of
ACCESS_ONCE(), as these aren't harmful, and changing them results in
churn.
However, for some features, the read/write distinction is critical to
correct operation. To distinguish these cases, separate read/write
accessors must be used. This patch migrates (most) remaining
ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
coccinelle script:
----
// Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
// WRITE_ONCE()
// $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch
virtual patch
@ depends on patch @
expression E1, E2;
@@
- ACCESS_ONCE(E1) = E2
+ WRITE_ONCE(E1, E2)
@ depends on patch @
expression E;
@@
- ACCESS_ONCE(E)
+ READ_ONCE(E)
----
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: davem@davemloft.net
Cc: linux-arch@vger.kernel.org
Cc: mpe@ellerman.id.au
Cc: shuah@kernel.org
Cc: snitzer@redhat.com
Cc: thor.thayer@linux.intel.com
Cc: tj@kernel.org
Cc: viro@zeniv.linux.org.uk
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-24 05:07:29 +08:00
|
|
|
head = READ_ONCE(jrp->head);
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2012-06-23 08:48:55 +08:00
|
|
|
sw_idx = tail = jrp->tail;
|
2011-03-13 16:54:26 +08:00
|
|
|
hw_idx = jrp->out_ring_read_index;
|
2012-06-23 08:48:55 +08:00
|
|
|
|
2011-03-13 16:54:26 +08:00
|
|
|
for (i = 0; CIRC_CNT(head, tail + i, JOBR_DEPTH) >= 1; i++) {
|
|
|
|
sw_idx = (tail + i) & (JOBR_DEPTH - 1);
|
|
|
|
|
2019-08-21 04:23:57 +08:00
|
|
|
if (jr_outentry_desc(jrp->outring, hw_idx) ==
|
2016-05-19 23:11:26 +08:00
|
|
|
caam_dma_to_cpu(jrp->entinfo[sw_idx].desc_addr_dma))
|
2011-03-13 16:54:26 +08:00
|
|
|
break; /* found */
|
|
|
|
}
|
|
|
|
/* we should never fail to find a matching descriptor */
|
|
|
|
BUG_ON(CIRC_CNT(head, tail + i, JOBR_DEPTH) <= 0);
|
|
|
|
|
|
|
|
/* Unmap just-run descriptor so we can post-process */
|
2018-08-06 20:29:09 +08:00
|
|
|
dma_unmap_single(dev,
|
2019-08-21 04:23:57 +08:00
|
|
|
caam_dma_to_cpu(jr_outentry_desc(jrp->outring,
|
|
|
|
hw_idx)),
|
2011-03-13 16:54:26 +08:00
|
|
|
jrp->entinfo[sw_idx].desc_size,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
|
|
|
/* mark completed, avoid matching on a recycled desc addr */
|
|
|
|
jrp->entinfo[sw_idx].desc_addr_dma = 0;
|
|
|
|
|
2019-03-22 10:00:34 +08:00
|
|
|
/* Stash callback params */
|
2011-03-13 16:54:26 +08:00
|
|
|
usercall = jrp->entinfo[sw_idx].callbk;
|
|
|
|
userarg = jrp->entinfo[sw_idx].cbkarg;
|
|
|
|
userdesc = jrp->entinfo[sw_idx].desc_addr_virt;
|
2019-08-21 04:23:57 +08:00
|
|
|
userstatus = caam32_to_cpu(jr_outentry_jrstatus(jrp->outring,
|
|
|
|
hw_idx));
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2015-08-06 02:28:35 +08:00
|
|
|
/*
|
|
|
|
* Make sure all information from the job has been obtained
|
|
|
|
* before telling CAAM that the job has been removed from the
|
|
|
|
* output ring.
|
|
|
|
*/
|
|
|
|
mb();
|
|
|
|
|
2012-06-23 08:48:56 +08:00
|
|
|
/* set done */
|
2019-05-09 13:20:48 +08:00
|
|
|
wr_reg32(&jrp->rregs->outring_rmvd, 1);
|
2011-03-13 16:54:26 +08:00
|
|
|
|
|
|
|
jrp->out_ring_read_index = (jrp->out_ring_read_index + 1) &
|
|
|
|
(JOBR_DEPTH - 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if this job completed out-of-order, do not increment
|
|
|
|
* the tail. Otherwise, increment tail by 1 plus the
|
|
|
|
* number of subsequent jobs already completed out-of-order
|
|
|
|
*/
|
|
|
|
if (sw_idx == tail) {
|
|
|
|
do {
|
|
|
|
tail = (tail + 1) & (JOBR_DEPTH - 1);
|
|
|
|
} while (CIRC_CNT(head, tail, JOBR_DEPTH) >= 1 &&
|
|
|
|
jrp->entinfo[tail].desc_addr_dma == 0);
|
|
|
|
|
|
|
|
jrp->tail = tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, execute user's callback */
|
|
|
|
usercall(dev, userdesc, userstatus, userarg);
|
2019-03-06 02:03:14 +08:00
|
|
|
outring_used--;
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* reenable / unmask IRQs */
|
2016-05-19 23:11:26 +08:00
|
|
|
clrsetbits_32(&jrp->rregs->rconfig_lo, JRCFG_IMSK, 0);
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
|
|
|
|
2013-10-25 14:31:02 +08:00
|
|
|
/**
|
|
|
|
* caam_jr_alloc() - Alloc a job ring for someone to use as needed.
|
|
|
|
*
|
|
|
|
* returns : pointer to the newly allocated physical
|
|
|
|
* JobR dev can be written to if successful.
|
|
|
|
**/
|
|
|
|
struct device *caam_jr_alloc(void)
|
|
|
|
{
|
|
|
|
struct caam_drv_private_jr *jrpriv, *min_jrpriv = NULL;
|
2016-05-06 21:18:53 +08:00
|
|
|
struct device *dev = ERR_PTR(-ENODEV);
|
2013-10-25 14:31:02 +08:00
|
|
|
int min_tfm_cnt = INT_MAX;
|
|
|
|
int tfm_cnt;
|
|
|
|
|
|
|
|
spin_lock(&driver_data.jr_alloc_lock);
|
|
|
|
|
|
|
|
if (list_empty(&driver_data.jr_list)) {
|
|
|
|
spin_unlock(&driver_data.jr_alloc_lock);
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(jrpriv, &driver_data.jr_list, list_node) {
|
|
|
|
tfm_cnt = atomic_read(&jrpriv->tfm_count);
|
|
|
|
if (tfm_cnt < min_tfm_cnt) {
|
|
|
|
min_tfm_cnt = tfm_cnt;
|
|
|
|
min_jrpriv = jrpriv;
|
|
|
|
}
|
|
|
|
if (!min_tfm_cnt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_jrpriv) {
|
|
|
|
atomic_inc(&min_jrpriv->tfm_count);
|
|
|
|
dev = min_jrpriv->dev;
|
|
|
|
}
|
|
|
|
spin_unlock(&driver_data.jr_alloc_lock);
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(caam_jr_alloc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* caam_jr_free() - Free the Job Ring
|
2020-09-11 03:29:16 +08:00
|
|
|
* @rdev: points to the dev that identifies the Job ring to
|
2013-10-25 14:31:02 +08:00
|
|
|
* be released.
|
|
|
|
**/
|
|
|
|
void caam_jr_free(struct device *rdev)
|
|
|
|
{
|
|
|
|
struct caam_drv_private_jr *jrpriv = dev_get_drvdata(rdev);
|
|
|
|
|
|
|
|
atomic_dec(&jrpriv->tfm_count);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(caam_jr_free);
|
|
|
|
|
2011-03-13 16:54:26 +08:00
|
|
|
/**
|
2020-02-13 01:55:20 +08:00
|
|
|
* caam_jr_enqueue() - Enqueue a job descriptor head. Returns -EINPROGRESS
|
|
|
|
* if OK, -ENOSPC if the queue is full, -EIO if it cannot map the caller's
|
2011-03-13 16:54:26 +08:00
|
|
|
* descriptor.
|
2020-07-22 20:14:56 +08:00
|
|
|
* @dev: struct device of the job ring to be used
|
2011-03-13 16:54:26 +08:00
|
|
|
* @desc: points to a job descriptor that execute our request. All
|
|
|
|
* descriptors (and all referenced data) must be in a DMAable
|
|
|
|
* region, and all data references must be physical addresses
|
|
|
|
* accessible to CAAM (i.e. within a PAMU window granted
|
|
|
|
* to it).
|
|
|
|
* @cbk: pointer to a callback function to be invoked upon completion
|
|
|
|
* of this request. This has the form:
|
|
|
|
* callback(struct device *dev, u32 *desc, u32 stat, void *arg)
|
|
|
|
* where:
|
2020-09-11 03:29:16 +08:00
|
|
|
* dev: contains the job ring device that processed this
|
2011-03-13 16:54:26 +08:00
|
|
|
* response.
|
2020-09-11 03:29:16 +08:00
|
|
|
* desc: descriptor that initiated the request, same as
|
2011-03-13 16:54:26 +08:00
|
|
|
* "desc" being argued to caam_jr_enqueue().
|
2020-09-11 03:29:16 +08:00
|
|
|
* status: untranslated status received from CAAM. See the
|
2011-03-13 16:54:26 +08:00
|
|
|
* reference manual for a detailed description of
|
|
|
|
* error meaning, or see the JRSTA definitions in the
|
|
|
|
* register header file
|
2020-09-11 03:29:16 +08:00
|
|
|
* areq: optional pointer to an argument passed with the
|
2011-03-13 16:54:26 +08:00
|
|
|
* original request
|
|
|
|
* @areq: optional pointer to a user argument for use at callback
|
|
|
|
* time.
|
|
|
|
**/
|
|
|
|
int caam_jr_enqueue(struct device *dev, u32 *desc,
|
|
|
|
void (*cbk)(struct device *dev, u32 *desc,
|
|
|
|
u32 status, void *areq),
|
|
|
|
void *areq)
|
|
|
|
{
|
|
|
|
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
|
|
|
|
struct caam_jrentry_info *head_entry;
|
|
|
|
int head, tail, desc_size;
|
|
|
|
dma_addr_t desc_dma;
|
|
|
|
|
2016-05-19 23:11:26 +08:00
|
|
|
desc_size = (caam32_to_cpu(*desc) & HDR_JD_LENGTH_MASK) * sizeof(u32);
|
2011-03-13 16:54:26 +08:00
|
|
|
desc_dma = dma_map_single(dev, desc, desc_size, DMA_TO_DEVICE);
|
|
|
|
if (dma_mapping_error(dev, desc_dma)) {
|
|
|
|
dev_err(dev, "caam_jr_enqueue(): can't map jobdesc\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
crypto: caam - fix possible deadlock condition
commit "crypto: caam - use non-irq versions of spinlocks for job rings"
made two bad assumptions:
(a) The caam_jr_enqueue lock isn't used in softirq context.
Not true: jr_enqueue can be interrupted by an incoming net
interrupt and the received packet may be sent for encryption,
via caam_jr_enqueue in softirq context, thereby inducing a
deadlock.
This is evidenced when running netperf over an IPSec tunnel
between two P4080's, with spinlock debugging turned on:
[ 892.092569] BUG: spinlock lockup on CPU#7, netperf/10634, e8bf5f70
[ 892.098747] Call Trace:
[ 892.101197] [eff9fc10] [c00084c0] show_stack+0x48/0x15c (unreliable)
[ 892.107563] [eff9fc50] [c0239c2c] do_raw_spin_lock+0x16c/0x174
[ 892.113399] [eff9fc80] [c0596494] _raw_spin_lock+0x3c/0x50
[ 892.118889] [eff9fc90] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.124550] [eff9fcd0] [c044a644] aead_decrypt+0x6c/0xc8
[ 892.129625] BUG: spinlock lockup on CPU#5, swapper/5/0, e8bf5f70
[ 892.129629] Call Trace:
[ 892.129637] [effa7c10] [c00084c0] show_stack+0x48/0x15c (unreliable)
[ 892.129645] [effa7c50] [c0239c2c] do_raw_spin_lock+0x16c/0x174
[ 892.129652] [effa7c80] [c0596494] _raw_spin_lock+0x3c/0x50
[ 892.129660] [effa7c90] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.129666] [effa7cd0] [c044a644] aead_decrypt+0x6c/0xc8
[ 892.129674] [effa7d00] [c0509724] esp_input+0x178/0x334
[ 892.129681] [effa7d50] [c0519778] xfrm_input+0x77c/0x818
[ 892.129688] [effa7da0] [c050e344] xfrm4_rcv_encap+0x20/0x30
[ 892.129697] [effa7db0] [c04b90c8] ip_local_deliver+0x190/0x408
[ 892.129703] [effa7de0] [c04b966c] ip_rcv+0x32c/0x898
[ 892.129709] [effa7e10] [c048b998] __netif_receive_skb+0x27c/0x4e8
[ 892.129715] [effa7e80] [c048d744] netif_receive_skb+0x4c/0x13c
[ 892.129726] [effa7eb0] [c03c28ac] _dpa_rx+0x1a8/0x354
[ 892.129732] [effa7ef0] [c03c2ac4] ingress_rx_default_dqrr+0x6c/0x108
[ 892.129742] [effa7f10] [c0467ae0] qman_poll_dqrr+0x170/0x1d4
[ 892.129748] [effa7f40] [c03c153c] dpaa_eth_poll+0x20/0x94
[ 892.129754] [effa7f60] [c048dbd0] net_rx_action+0x13c/0x1f4
[ 892.129763] [effa7fa0] [c003d1b8] __do_softirq+0x108/0x1b0
[ 892.129769] [effa7ff0] [c000df58] call_do_softirq+0x14/0x24
[ 892.129775] [ebacfe70] [c0004868] do_softirq+0xd8/0x104
[ 892.129780] [ebacfe90] [c003d5a4] irq_exit+0xb8/0xd8
[ 892.129786] [ebacfea0] [c0004498] do_IRQ+0xa4/0x1b0
[ 892.129792] [ebacfed0] [c000fad8] ret_from_except+0x0/0x18
[ 892.129798] [ebacff90] [c0009010] cpu_idle+0x94/0xf0
[ 892.129804] [ebacffb0] [c059ff88] start_secondary+0x42c/0x430
[ 892.129809] [ebacfff0] [c0001e28] __secondary_start+0x30/0x84
[ 892.281474]
[ 892.282959] [eff9fd00] [c0509724] esp_input+0x178/0x334
[ 892.288186] [eff9fd50] [c0519778] xfrm_input+0x77c/0x818
[ 892.293499] [eff9fda0] [c050e344] xfrm4_rcv_encap+0x20/0x30
[ 892.299074] [eff9fdb0] [c04b90c8] ip_local_deliver+0x190/0x408
[ 892.304907] [eff9fde0] [c04b966c] ip_rcv+0x32c/0x898
[ 892.309872] [eff9fe10] [c048b998] __netif_receive_skb+0x27c/0x4e8
[ 892.315966] [eff9fe80] [c048d744] netif_receive_skb+0x4c/0x13c
[ 892.321803] [eff9feb0] [c03c28ac] _dpa_rx+0x1a8/0x354
[ 892.326855] [eff9fef0] [c03c2ac4] ingress_rx_default_dqrr+0x6c/0x108
[ 892.333212] [eff9ff10] [c0467ae0] qman_poll_dqrr+0x170/0x1d4
[ 892.338872] [eff9ff40] [c03c153c] dpaa_eth_poll+0x20/0x94
[ 892.344271] [eff9ff60] [c048dbd0] net_rx_action+0x13c/0x1f4
[ 892.349846] [eff9ffa0] [c003d1b8] __do_softirq+0x108/0x1b0
[ 892.355338] [eff9fff0] [c000df58] call_do_softirq+0x14/0x24
[ 892.360910] [e7169950] [c0004868] do_softirq+0xd8/0x104
[ 892.366135] [e7169970] [c003d5a4] irq_exit+0xb8/0xd8
[ 892.371101] [e7169980] [c0004498] do_IRQ+0xa4/0x1b0
[ 892.375979] [e71699b0] [c000fad8] ret_from_except+0x0/0x18
[ 892.381466] [e7169a70] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.387127] [e7169ab0] [c044ad4c] aead_givencrypt+0x6ac/0xa70
[ 892.392873] [e7169b20] [c050a0b8] esp_output+0x2b4/0x570
[ 892.398186] [e7169b80] [c0519b9c] xfrm_output_resume+0x248/0x7c0
[ 892.404194] [e7169bb0] [c050e89c] xfrm4_output_finish+0x18/0x28
[ 892.410113] [e7169bc0] [c050e8f4] xfrm4_output+0x48/0x98
[ 892.415427] [e7169bd0] [c04beac0] ip_local_out+0x48/0x98
[ 892.420740] [e7169be0] [c04bec7c] ip_queue_xmit+0x16c/0x490
[ 892.426314] [e7169c10] [c04d6128] tcp_transmit_skb+0x35c/0x9a4
[ 892.432147] [e7169c70] [c04d6f98] tcp_write_xmit+0x200/0xa04
[ 892.437808] [e7169cc0] [c04c8ccc] tcp_sendmsg+0x994/0xcec
[ 892.443213] [e7169d40] [c04eebfc] inet_sendmsg+0xd0/0x164
[ 892.448617] [e7169d70] [c04792f8] sock_sendmsg+0x8c/0xbc
[ 892.453931] [e7169e40] [c047aecc] sys_sendto+0xc0/0xfc
[ 892.459069] [e7169f10] [c047b934] sys_socketcall+0x110/0x25c
[ 892.464729] [e7169f40] [c000f480] ret_from_syscall+0x0/0x3c
(b) since the caam_jr_dequeue lock is only used in bh context,
then semantically it should use _bh spin_lock types. spin_lock_bh
semantics are to disable back-halves, and used when a lock is shared
between softirq (bh) context and process and/or h/w IRQ context.
Since the lock is only used within softirq context, and this tasklet
is atomic, there is no need to do the additional work to disable
back halves.
This patch adds back-half disabling protection to caam_jr_enqueue
spin_locks to fix (a), and drops it from caam_jr_dequeue to fix (b).
Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2012-07-14 07:04:23 +08:00
|
|
|
spin_lock_bh(&jrp->inplock);
|
2011-03-13 16:54:26 +08:00
|
|
|
|
|
|
|
head = jrp->head;
|
locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
Please do not apply this to mainline directly, instead please re-run the
coccinelle script shown below and apply its output.
For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
preference to ACCESS_ONCE(), and new code is expected to use one of the
former. So far, there's been no reason to change most existing uses of
ACCESS_ONCE(), as these aren't harmful, and changing them results in
churn.
However, for some features, the read/write distinction is critical to
correct operation. To distinguish these cases, separate read/write
accessors must be used. This patch migrates (most) remaining
ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
coccinelle script:
----
// Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
// WRITE_ONCE()
// $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch
virtual patch
@ depends on patch @
expression E1, E2;
@@
- ACCESS_ONCE(E1) = E2
+ WRITE_ONCE(E1, E2)
@ depends on patch @
expression E;
@@
- ACCESS_ONCE(E)
+ READ_ONCE(E)
----
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: davem@davemloft.net
Cc: linux-arch@vger.kernel.org
Cc: mpe@ellerman.id.au
Cc: shuah@kernel.org
Cc: snitzer@redhat.com
Cc: thor.thayer@linux.intel.com
Cc: tj@kernel.org
Cc: viro@zeniv.linux.org.uk
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-24 05:07:29 +08:00
|
|
|
tail = READ_ONCE(jrp->tail);
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2019-03-06 02:03:14 +08:00
|
|
|
if (!jrp->inpring_avail ||
|
2011-03-13 16:54:26 +08:00
|
|
|
CIRC_SPACE(head, tail, JOBR_DEPTH) <= 0) {
|
crypto: caam - fix possible deadlock condition
commit "crypto: caam - use non-irq versions of spinlocks for job rings"
made two bad assumptions:
(a) The caam_jr_enqueue lock isn't used in softirq context.
Not true: jr_enqueue can be interrupted by an incoming net
interrupt and the received packet may be sent for encryption,
via caam_jr_enqueue in softirq context, thereby inducing a
deadlock.
This is evidenced when running netperf over an IPSec tunnel
between two P4080's, with spinlock debugging turned on:
[ 892.092569] BUG: spinlock lockup on CPU#7, netperf/10634, e8bf5f70
[ 892.098747] Call Trace:
[ 892.101197] [eff9fc10] [c00084c0] show_stack+0x48/0x15c (unreliable)
[ 892.107563] [eff9fc50] [c0239c2c] do_raw_spin_lock+0x16c/0x174
[ 892.113399] [eff9fc80] [c0596494] _raw_spin_lock+0x3c/0x50
[ 892.118889] [eff9fc90] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.124550] [eff9fcd0] [c044a644] aead_decrypt+0x6c/0xc8
[ 892.129625] BUG: spinlock lockup on CPU#5, swapper/5/0, e8bf5f70
[ 892.129629] Call Trace:
[ 892.129637] [effa7c10] [c00084c0] show_stack+0x48/0x15c (unreliable)
[ 892.129645] [effa7c50] [c0239c2c] do_raw_spin_lock+0x16c/0x174
[ 892.129652] [effa7c80] [c0596494] _raw_spin_lock+0x3c/0x50
[ 892.129660] [effa7c90] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.129666] [effa7cd0] [c044a644] aead_decrypt+0x6c/0xc8
[ 892.129674] [effa7d00] [c0509724] esp_input+0x178/0x334
[ 892.129681] [effa7d50] [c0519778] xfrm_input+0x77c/0x818
[ 892.129688] [effa7da0] [c050e344] xfrm4_rcv_encap+0x20/0x30
[ 892.129697] [effa7db0] [c04b90c8] ip_local_deliver+0x190/0x408
[ 892.129703] [effa7de0] [c04b966c] ip_rcv+0x32c/0x898
[ 892.129709] [effa7e10] [c048b998] __netif_receive_skb+0x27c/0x4e8
[ 892.129715] [effa7e80] [c048d744] netif_receive_skb+0x4c/0x13c
[ 892.129726] [effa7eb0] [c03c28ac] _dpa_rx+0x1a8/0x354
[ 892.129732] [effa7ef0] [c03c2ac4] ingress_rx_default_dqrr+0x6c/0x108
[ 892.129742] [effa7f10] [c0467ae0] qman_poll_dqrr+0x170/0x1d4
[ 892.129748] [effa7f40] [c03c153c] dpaa_eth_poll+0x20/0x94
[ 892.129754] [effa7f60] [c048dbd0] net_rx_action+0x13c/0x1f4
[ 892.129763] [effa7fa0] [c003d1b8] __do_softirq+0x108/0x1b0
[ 892.129769] [effa7ff0] [c000df58] call_do_softirq+0x14/0x24
[ 892.129775] [ebacfe70] [c0004868] do_softirq+0xd8/0x104
[ 892.129780] [ebacfe90] [c003d5a4] irq_exit+0xb8/0xd8
[ 892.129786] [ebacfea0] [c0004498] do_IRQ+0xa4/0x1b0
[ 892.129792] [ebacfed0] [c000fad8] ret_from_except+0x0/0x18
[ 892.129798] [ebacff90] [c0009010] cpu_idle+0x94/0xf0
[ 892.129804] [ebacffb0] [c059ff88] start_secondary+0x42c/0x430
[ 892.129809] [ebacfff0] [c0001e28] __secondary_start+0x30/0x84
[ 892.281474]
[ 892.282959] [eff9fd00] [c0509724] esp_input+0x178/0x334
[ 892.288186] [eff9fd50] [c0519778] xfrm_input+0x77c/0x818
[ 892.293499] [eff9fda0] [c050e344] xfrm4_rcv_encap+0x20/0x30
[ 892.299074] [eff9fdb0] [c04b90c8] ip_local_deliver+0x190/0x408
[ 892.304907] [eff9fde0] [c04b966c] ip_rcv+0x32c/0x898
[ 892.309872] [eff9fe10] [c048b998] __netif_receive_skb+0x27c/0x4e8
[ 892.315966] [eff9fe80] [c048d744] netif_receive_skb+0x4c/0x13c
[ 892.321803] [eff9feb0] [c03c28ac] _dpa_rx+0x1a8/0x354
[ 892.326855] [eff9fef0] [c03c2ac4] ingress_rx_default_dqrr+0x6c/0x108
[ 892.333212] [eff9ff10] [c0467ae0] qman_poll_dqrr+0x170/0x1d4
[ 892.338872] [eff9ff40] [c03c153c] dpaa_eth_poll+0x20/0x94
[ 892.344271] [eff9ff60] [c048dbd0] net_rx_action+0x13c/0x1f4
[ 892.349846] [eff9ffa0] [c003d1b8] __do_softirq+0x108/0x1b0
[ 892.355338] [eff9fff0] [c000df58] call_do_softirq+0x14/0x24
[ 892.360910] [e7169950] [c0004868] do_softirq+0xd8/0x104
[ 892.366135] [e7169970] [c003d5a4] irq_exit+0xb8/0xd8
[ 892.371101] [e7169980] [c0004498] do_IRQ+0xa4/0x1b0
[ 892.375979] [e71699b0] [c000fad8] ret_from_except+0x0/0x18
[ 892.381466] [e7169a70] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.387127] [e7169ab0] [c044ad4c] aead_givencrypt+0x6ac/0xa70
[ 892.392873] [e7169b20] [c050a0b8] esp_output+0x2b4/0x570
[ 892.398186] [e7169b80] [c0519b9c] xfrm_output_resume+0x248/0x7c0
[ 892.404194] [e7169bb0] [c050e89c] xfrm4_output_finish+0x18/0x28
[ 892.410113] [e7169bc0] [c050e8f4] xfrm4_output+0x48/0x98
[ 892.415427] [e7169bd0] [c04beac0] ip_local_out+0x48/0x98
[ 892.420740] [e7169be0] [c04bec7c] ip_queue_xmit+0x16c/0x490
[ 892.426314] [e7169c10] [c04d6128] tcp_transmit_skb+0x35c/0x9a4
[ 892.432147] [e7169c70] [c04d6f98] tcp_write_xmit+0x200/0xa04
[ 892.437808] [e7169cc0] [c04c8ccc] tcp_sendmsg+0x994/0xcec
[ 892.443213] [e7169d40] [c04eebfc] inet_sendmsg+0xd0/0x164
[ 892.448617] [e7169d70] [c04792f8] sock_sendmsg+0x8c/0xbc
[ 892.453931] [e7169e40] [c047aecc] sys_sendto+0xc0/0xfc
[ 892.459069] [e7169f10] [c047b934] sys_socketcall+0x110/0x25c
[ 892.464729] [e7169f40] [c000f480] ret_from_syscall+0x0/0x3c
(b) since the caam_jr_dequeue lock is only used in bh context,
then semantically it should use _bh spin_lock types. spin_lock_bh
semantics are to disable back-halves, and used when a lock is shared
between softirq (bh) context and process and/or h/w IRQ context.
Since the lock is only used within softirq context, and this tasklet
is atomic, there is no need to do the additional work to disable
back halves.
This patch adds back-half disabling protection to caam_jr_enqueue
spin_locks to fix (a), and drops it from caam_jr_dequeue to fix (b).
Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2012-07-14 07:04:23 +08:00
|
|
|
spin_unlock_bh(&jrp->inplock);
|
2011-03-13 16:54:26 +08:00
|
|
|
dma_unmap_single(dev, desc_dma, desc_size, DMA_TO_DEVICE);
|
2020-02-13 01:55:20 +08:00
|
|
|
return -ENOSPC;
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
head_entry = &jrp->entinfo[head];
|
|
|
|
head_entry->desc_addr_virt = desc;
|
|
|
|
head_entry->desc_size = desc_size;
|
|
|
|
head_entry->callbk = (void *)cbk;
|
|
|
|
head_entry->cbkarg = areq;
|
|
|
|
head_entry->desc_addr_dma = desc_dma;
|
|
|
|
|
2019-08-21 04:23:58 +08:00
|
|
|
jr_inpentry_set(jrp->inpring, head, cpu_to_caam_dma(desc_dma));
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2015-08-06 02:28:35 +08:00
|
|
|
/*
|
|
|
|
* Guarantee that the descriptor's DMA address has been written to
|
|
|
|
* the next slot in the ring before the write index is updated, since
|
|
|
|
* other cores may update this index independently.
|
|
|
|
*/
|
2011-03-13 16:54:26 +08:00
|
|
|
smp_wmb();
|
|
|
|
|
|
|
|
jrp->head = (head + 1) & (JOBR_DEPTH - 1);
|
|
|
|
|
2015-08-06 02:28:35 +08:00
|
|
|
/*
|
|
|
|
* Ensure that all job information has been written before
|
2019-03-22 10:00:37 +08:00
|
|
|
* notifying CAAM that a new job was added to the input ring
|
|
|
|
* using a memory barrier. The wr_reg32() uses api iowrite32()
|
|
|
|
* to do the register write. iowrite32() issues a memory barrier
|
|
|
|
* before the write operation.
|
2015-08-06 02:28:35 +08:00
|
|
|
*/
|
|
|
|
|
2011-03-13 16:54:26 +08:00
|
|
|
wr_reg32(&jrp->rregs->inpring_jobadd, 1);
|
|
|
|
|
2019-03-06 02:03:14 +08:00
|
|
|
jrp->inpring_avail--;
|
|
|
|
if (!jrp->inpring_avail)
|
|
|
|
jrp->inpring_avail = rd_reg32(&jrp->rregs->inpring_avail);
|
|
|
|
|
crypto: caam - fix possible deadlock condition
commit "crypto: caam - use non-irq versions of spinlocks for job rings"
made two bad assumptions:
(a) The caam_jr_enqueue lock isn't used in softirq context.
Not true: jr_enqueue can be interrupted by an incoming net
interrupt and the received packet may be sent for encryption,
via caam_jr_enqueue in softirq context, thereby inducing a
deadlock.
This is evidenced when running netperf over an IPSec tunnel
between two P4080's, with spinlock debugging turned on:
[ 892.092569] BUG: spinlock lockup on CPU#7, netperf/10634, e8bf5f70
[ 892.098747] Call Trace:
[ 892.101197] [eff9fc10] [c00084c0] show_stack+0x48/0x15c (unreliable)
[ 892.107563] [eff9fc50] [c0239c2c] do_raw_spin_lock+0x16c/0x174
[ 892.113399] [eff9fc80] [c0596494] _raw_spin_lock+0x3c/0x50
[ 892.118889] [eff9fc90] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.124550] [eff9fcd0] [c044a644] aead_decrypt+0x6c/0xc8
[ 892.129625] BUG: spinlock lockup on CPU#5, swapper/5/0, e8bf5f70
[ 892.129629] Call Trace:
[ 892.129637] [effa7c10] [c00084c0] show_stack+0x48/0x15c (unreliable)
[ 892.129645] [effa7c50] [c0239c2c] do_raw_spin_lock+0x16c/0x174
[ 892.129652] [effa7c80] [c0596494] _raw_spin_lock+0x3c/0x50
[ 892.129660] [effa7c90] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.129666] [effa7cd0] [c044a644] aead_decrypt+0x6c/0xc8
[ 892.129674] [effa7d00] [c0509724] esp_input+0x178/0x334
[ 892.129681] [effa7d50] [c0519778] xfrm_input+0x77c/0x818
[ 892.129688] [effa7da0] [c050e344] xfrm4_rcv_encap+0x20/0x30
[ 892.129697] [effa7db0] [c04b90c8] ip_local_deliver+0x190/0x408
[ 892.129703] [effa7de0] [c04b966c] ip_rcv+0x32c/0x898
[ 892.129709] [effa7e10] [c048b998] __netif_receive_skb+0x27c/0x4e8
[ 892.129715] [effa7e80] [c048d744] netif_receive_skb+0x4c/0x13c
[ 892.129726] [effa7eb0] [c03c28ac] _dpa_rx+0x1a8/0x354
[ 892.129732] [effa7ef0] [c03c2ac4] ingress_rx_default_dqrr+0x6c/0x108
[ 892.129742] [effa7f10] [c0467ae0] qman_poll_dqrr+0x170/0x1d4
[ 892.129748] [effa7f40] [c03c153c] dpaa_eth_poll+0x20/0x94
[ 892.129754] [effa7f60] [c048dbd0] net_rx_action+0x13c/0x1f4
[ 892.129763] [effa7fa0] [c003d1b8] __do_softirq+0x108/0x1b0
[ 892.129769] [effa7ff0] [c000df58] call_do_softirq+0x14/0x24
[ 892.129775] [ebacfe70] [c0004868] do_softirq+0xd8/0x104
[ 892.129780] [ebacfe90] [c003d5a4] irq_exit+0xb8/0xd8
[ 892.129786] [ebacfea0] [c0004498] do_IRQ+0xa4/0x1b0
[ 892.129792] [ebacfed0] [c000fad8] ret_from_except+0x0/0x18
[ 892.129798] [ebacff90] [c0009010] cpu_idle+0x94/0xf0
[ 892.129804] [ebacffb0] [c059ff88] start_secondary+0x42c/0x430
[ 892.129809] [ebacfff0] [c0001e28] __secondary_start+0x30/0x84
[ 892.281474]
[ 892.282959] [eff9fd00] [c0509724] esp_input+0x178/0x334
[ 892.288186] [eff9fd50] [c0519778] xfrm_input+0x77c/0x818
[ 892.293499] [eff9fda0] [c050e344] xfrm4_rcv_encap+0x20/0x30
[ 892.299074] [eff9fdb0] [c04b90c8] ip_local_deliver+0x190/0x408
[ 892.304907] [eff9fde0] [c04b966c] ip_rcv+0x32c/0x898
[ 892.309872] [eff9fe10] [c048b998] __netif_receive_skb+0x27c/0x4e8
[ 892.315966] [eff9fe80] [c048d744] netif_receive_skb+0x4c/0x13c
[ 892.321803] [eff9feb0] [c03c28ac] _dpa_rx+0x1a8/0x354
[ 892.326855] [eff9fef0] [c03c2ac4] ingress_rx_default_dqrr+0x6c/0x108
[ 892.333212] [eff9ff10] [c0467ae0] qman_poll_dqrr+0x170/0x1d4
[ 892.338872] [eff9ff40] [c03c153c] dpaa_eth_poll+0x20/0x94
[ 892.344271] [eff9ff60] [c048dbd0] net_rx_action+0x13c/0x1f4
[ 892.349846] [eff9ffa0] [c003d1b8] __do_softirq+0x108/0x1b0
[ 892.355338] [eff9fff0] [c000df58] call_do_softirq+0x14/0x24
[ 892.360910] [e7169950] [c0004868] do_softirq+0xd8/0x104
[ 892.366135] [e7169970] [c003d5a4] irq_exit+0xb8/0xd8
[ 892.371101] [e7169980] [c0004498] do_IRQ+0xa4/0x1b0
[ 892.375979] [e71699b0] [c000fad8] ret_from_except+0x0/0x18
[ 892.381466] [e7169a70] [c0445e74] caam_jr_enqueue+0xf8/0x250
[ 892.387127] [e7169ab0] [c044ad4c] aead_givencrypt+0x6ac/0xa70
[ 892.392873] [e7169b20] [c050a0b8] esp_output+0x2b4/0x570
[ 892.398186] [e7169b80] [c0519b9c] xfrm_output_resume+0x248/0x7c0
[ 892.404194] [e7169bb0] [c050e89c] xfrm4_output_finish+0x18/0x28
[ 892.410113] [e7169bc0] [c050e8f4] xfrm4_output+0x48/0x98
[ 892.415427] [e7169bd0] [c04beac0] ip_local_out+0x48/0x98
[ 892.420740] [e7169be0] [c04bec7c] ip_queue_xmit+0x16c/0x490
[ 892.426314] [e7169c10] [c04d6128] tcp_transmit_skb+0x35c/0x9a4
[ 892.432147] [e7169c70] [c04d6f98] tcp_write_xmit+0x200/0xa04
[ 892.437808] [e7169cc0] [c04c8ccc] tcp_sendmsg+0x994/0xcec
[ 892.443213] [e7169d40] [c04eebfc] inet_sendmsg+0xd0/0x164
[ 892.448617] [e7169d70] [c04792f8] sock_sendmsg+0x8c/0xbc
[ 892.453931] [e7169e40] [c047aecc] sys_sendto+0xc0/0xfc
[ 892.459069] [e7169f10] [c047b934] sys_socketcall+0x110/0x25c
[ 892.464729] [e7169f40] [c000f480] ret_from_syscall+0x0/0x3c
(b) since the caam_jr_dequeue lock is only used in bh context,
then semantically it should use _bh spin_lock types. spin_lock_bh
semantics are to disable back-halves, and used when a lock is shared
between softirq (bh) context and process and/or h/w IRQ context.
Since the lock is only used within softirq context, and this tasklet
is atomic, there is no need to do the additional work to disable
back halves.
This patch adds back-half disabling protection to caam_jr_enqueue
spin_locks to fix (a), and drops it from caam_jr_dequeue to fix (b).
Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2012-07-14 07:04:23 +08:00
|
|
|
spin_unlock_bh(&jrp->inplock);
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2020-02-13 01:55:20 +08:00
|
|
|
return -EINPROGRESS;
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(caam_jr_enqueue);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init JobR independent of platform property detection
|
|
|
|
*/
|
|
|
|
static int caam_jr_init(struct device *dev)
|
|
|
|
{
|
|
|
|
struct caam_drv_private_jr *jrp;
|
|
|
|
dma_addr_t inpbusaddr, outbusaddr;
|
|
|
|
int i, error;
|
|
|
|
|
|
|
|
jrp = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
error = caam_reset_hw_jr(dev);
|
|
|
|
if (error)
|
2019-08-21 04:23:50 +08:00
|
|
|
return error;
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2019-08-21 04:23:58 +08:00
|
|
|
jrp->inpring = dmam_alloc_coherent(dev, SIZEOF_JR_INPENTRY *
|
2019-08-21 04:23:49 +08:00
|
|
|
JOBR_DEPTH, &inpbusaddr,
|
|
|
|
GFP_KERNEL);
|
2015-01-22 22:00:49 +08:00
|
|
|
if (!jrp->inpring)
|
2019-08-21 04:23:50 +08:00
|
|
|
return -ENOMEM;
|
2012-07-11 11:06:10 +08:00
|
|
|
|
2019-08-21 04:23:57 +08:00
|
|
|
jrp->outring = dmam_alloc_coherent(dev, SIZEOF_JR_OUTENTRY *
|
2019-08-21 04:23:49 +08:00
|
|
|
JOBR_DEPTH, &outbusaddr,
|
|
|
|
GFP_KERNEL);
|
2015-01-22 22:00:49 +08:00
|
|
|
if (!jrp->outring)
|
2019-08-21 04:23:50 +08:00
|
|
|
return -ENOMEM;
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2019-08-21 04:23:49 +08:00
|
|
|
jrp->entinfo = devm_kcalloc(dev, JOBR_DEPTH, sizeof(*jrp->entinfo),
|
|
|
|
GFP_KERNEL);
|
2015-01-22 22:00:49 +08:00
|
|
|
if (!jrp->entinfo)
|
2019-08-21 04:23:50 +08:00
|
|
|
return -ENOMEM;
|
2011-03-13 16:54:26 +08:00
|
|
|
|
|
|
|
for (i = 0; i < JOBR_DEPTH; i++)
|
|
|
|
jrp->entinfo[i].desc_addr_dma = !0;
|
|
|
|
|
|
|
|
/* Setup rings */
|
|
|
|
jrp->out_ring_read_index = 0;
|
|
|
|
jrp->head = 0;
|
|
|
|
jrp->tail = 0;
|
|
|
|
|
|
|
|
wr_reg64(&jrp->rregs->inpring_base, inpbusaddr);
|
|
|
|
wr_reg64(&jrp->rregs->outring_base, outbusaddr);
|
|
|
|
wr_reg32(&jrp->rregs->inpring_size, JOBR_DEPTH);
|
|
|
|
wr_reg32(&jrp->rregs->outring_size, JOBR_DEPTH);
|
|
|
|
|
2019-03-06 02:03:14 +08:00
|
|
|
jrp->inpring_avail = JOBR_DEPTH;
|
2011-03-13 16:54:26 +08:00
|
|
|
|
|
|
|
spin_lock_init(&jrp->inplock);
|
|
|
|
|
|
|
|
/* Select interrupt coalescing parameters */
|
2016-05-19 23:11:26 +08:00
|
|
|
clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JOBR_INTC |
|
|
|
|
(JOBR_INTC_COUNT_THLD << JRCFG_ICDCT_SHIFT) |
|
|
|
|
(JOBR_INTC_TIME_THLD << JRCFG_ICTT_SHIFT));
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2019-08-21 04:23:50 +08:00
|
|
|
tasklet_init(&jrp->irqtask, caam_jr_dequeue, (unsigned long)dev);
|
|
|
|
|
|
|
|
/* Connect job ring interrupt handler. */
|
|
|
|
error = devm_request_irq(dev, jrp->irq, caam_jr_interrupt, IRQF_SHARED,
|
|
|
|
dev_name(dev), dev);
|
|
|
|
if (error) {
|
|
|
|
dev_err(dev, "can't connect JobR %d interrupt (%d)\n",
|
|
|
|
jrp->ridx, jrp->irq);
|
|
|
|
tasklet_kill(&jrp->irqtask);
|
|
|
|
}
|
|
|
|
|
2015-01-22 22:00:49 +08:00
|
|
|
return error;
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 10:35:07 +08:00
|
|
|
static void caam_jr_irq_dispose_mapping(void *data)
|
|
|
|
{
|
2019-09-09 21:55:29 +08:00
|
|
|
irq_dispose_mapping((unsigned long)data);
|
2019-09-04 10:35:07 +08:00
|
|
|
}
|
2011-03-13 16:54:26 +08:00
|
|
|
|
|
|
|
/*
|
2013-10-25 14:31:01 +08:00
|
|
|
* Probe routine for each detected JobR subsystem.
|
2011-03-13 16:54:26 +08:00
|
|
|
*/
|
2013-10-25 14:31:01 +08:00
|
|
|
static int caam_jr_probe(struct platform_device *pdev)
|
2011-03-13 16:54:26 +08:00
|
|
|
{
|
2013-10-25 14:31:01 +08:00
|
|
|
struct device *jrdev;
|
|
|
|
struct device_node *nprop;
|
|
|
|
struct caam_job_ring __iomem *ctrl;
|
2011-03-13 16:54:26 +08:00
|
|
|
struct caam_drv_private_jr *jrpriv;
|
2013-10-25 14:31:01 +08:00
|
|
|
static int total_jobrs;
|
2019-09-04 10:35:05 +08:00
|
|
|
struct resource *r;
|
2011-03-13 16:54:26 +08:00
|
|
|
int error;
|
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
jrdev = &pdev->dev;
|
2020-03-20 00:12:27 +08:00
|
|
|
jrpriv = devm_kzalloc(jrdev, sizeof(*jrpriv), GFP_KERNEL);
|
2013-10-25 14:31:01 +08:00
|
|
|
if (!jrpriv)
|
2011-03-13 16:54:26 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
dev_set_drvdata(jrdev, jrpriv);
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
/* save ring identity relative to detection */
|
|
|
|
jrpriv->ridx = total_jobrs++;
|
|
|
|
|
|
|
|
nprop = pdev->dev.of_node;
|
|
|
|
/* Get configuration properties from device tree */
|
|
|
|
/* First, get register page */
|
2019-09-04 10:35:05 +08:00
|
|
|
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!r) {
|
|
|
|
dev_err(jrdev, "platform_get_resource() failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctrl = devm_ioremap(jrdev, r->start, resource_size(r));
|
2013-10-25 14:31:01 +08:00
|
|
|
if (!ctrl) {
|
2019-09-04 10:35:05 +08:00
|
|
|
dev_err(jrdev, "devm_ioremap() failed\n");
|
2013-10-25 14:31:01 +08:00
|
|
|
return -ENOMEM;
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
2013-04-15 12:25:51 +08:00
|
|
|
|
2016-11-09 16:46:14 +08:00
|
|
|
jrpriv->rregs = (struct caam_job_ring __iomem __force *)ctrl;
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2019-08-21 04:23:47 +08:00
|
|
|
error = dma_set_mask_and_coherent(jrdev, caam_get_dma_mask(jrdev));
|
2017-02-10 20:07:15 +08:00
|
|
|
if (error) {
|
|
|
|
dev_err(jrdev, "dma_set_mask_and_coherent failed (%d)\n",
|
|
|
|
error);
|
|
|
|
return error;
|
|
|
|
}
|
2012-06-23 08:48:51 +08:00
|
|
|
|
2020-02-13 01:55:21 +08:00
|
|
|
/* Initialize crypto engine */
|
2020-10-27 03:06:26 +08:00
|
|
|
jrpriv->engine = crypto_engine_alloc_init_and_set(jrdev, true, NULL,
|
|
|
|
false,
|
|
|
|
CRYPTO_ENGINE_MAX_QLEN);
|
2020-02-13 01:55:21 +08:00
|
|
|
if (!jrpriv->engine) {
|
|
|
|
dev_err(jrdev, "Could not init crypto-engine\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = devm_add_action_or_reset(jrdev, caam_jr_crypto_engine_exit,
|
|
|
|
jrdev);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Start crypto engine */
|
|
|
|
error = crypto_engine_start(jrpriv->engine);
|
|
|
|
if (error) {
|
|
|
|
dev_err(jrdev, "Could not start crypto-engine\n");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-03-13 16:54:26 +08:00
|
|
|
/* Identify the interrupt */
|
2013-11-24 08:18:25 +08:00
|
|
|
jrpriv->irq = irq_of_parse_and_map(nprop, 0);
|
2019-09-04 10:35:06 +08:00
|
|
|
if (!jrpriv->irq) {
|
|
|
|
dev_err(jrdev, "irq_of_parse_and_map failed\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-03-13 16:54:26 +08:00
|
|
|
|
2019-09-04 10:35:07 +08:00
|
|
|
error = devm_add_action_or_reset(jrdev, caam_jr_irq_dispose_mapping,
|
2019-09-09 21:55:29 +08:00
|
|
|
(void *)(unsigned long)jrpriv->irq);
|
2019-09-04 10:35:07 +08:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2011-03-13 16:54:26 +08:00
|
|
|
/* Now do the platform independent part */
|
|
|
|
error = caam_jr_init(jrdev); /* now turn on hardware */
|
2019-09-04 10:35:07 +08:00
|
|
|
if (error)
|
2011-03-13 16:54:26 +08:00
|
|
|
return error;
|
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
jrpriv->dev = jrdev;
|
|
|
|
spin_lock(&driver_data.jr_alloc_lock);
|
|
|
|
list_add_tail(&jrpriv->list_node, &driver_data.jr_list);
|
|
|
|
spin_unlock(&driver_data.jr_alloc_lock);
|
|
|
|
|
2013-10-25 14:31:02 +08:00
|
|
|
atomic_set(&jrpriv->tfm_count, 0);
|
|
|
|
|
2020-03-20 00:12:27 +08:00
|
|
|
register_algs(jrpriv, jrdev->parent);
|
2019-05-03 22:17:39 +08:00
|
|
|
|
2013-10-25 14:31:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-16 17:16:44 +08:00
|
|
|
static const struct of_device_id caam_jr_match[] = {
|
2013-10-25 14:31:01 +08:00
|
|
|
{
|
|
|
|
.compatible = "fsl,sec-v4.0-job-ring",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "fsl,sec4.0-job-ring",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, caam_jr_match);
|
|
|
|
|
|
|
|
static struct platform_driver caam_jr_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "caam_jr",
|
|
|
|
.of_match_table = caam_jr_match,
|
|
|
|
},
|
|
|
|
.probe = caam_jr_probe,
|
|
|
|
.remove = caam_jr_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init jr_driver_init(void)
|
|
|
|
{
|
|
|
|
spin_lock_init(&driver_data.jr_alloc_lock);
|
|
|
|
INIT_LIST_HEAD(&driver_data.jr_list);
|
|
|
|
return platform_driver_register(&caam_jr_driver);
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
2013-10-25 14:31:01 +08:00
|
|
|
|
|
|
|
static void __exit jr_driver_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&caam_jr_driver);
|
2011-03-13 16:54:26 +08:00
|
|
|
}
|
2013-10-25 14:31:01 +08:00
|
|
|
|
|
|
|
module_init(jr_driver_init);
|
|
|
|
module_exit(jr_driver_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("FSL CAAM JR request backend");
|
|
|
|
MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");
|