Skip to content

Commit

Permalink
crypto: caam - use non-irq versions of spinlocks for job rings
Browse files Browse the repository at this point in the history
The enqueue lock isn't used in any interrupt context, and
the dequeue lock isn't used in the h/w interrupt context,
only in bh context.

Signed-off-by: Kim Phillips <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
kimphill authored and herbertx committed Jun 27, 2012
1 parent 1a07668 commit 4bba1e9
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions drivers/crypto/caam/jr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* CAAM/SEC 4.x transport/backend driver
* JobR backend functionality
*
* Copyright 2008-2011 Freescale Semiconductor, Inc.
* Copyright 2008-2012 Freescale Semiconductor, Inc.
*/

#include "compat.h"
Expand Down Expand Up @@ -58,9 +58,8 @@ static void caam_jr_dequeue(unsigned long devarg)
void (*usercall)(struct device *dev, u32 *desc, u32 status, void *arg);
u32 *userdesc, userstatus;
void *userarg;
unsigned long flags;

spin_lock_irqsave(&jrp->outlock, flags);
spin_lock_bh(&jrp->outlock);

head = ACCESS_ONCE(jrp->head);
sw_idx = tail = jrp->tail;
Expand Down Expand Up @@ -118,18 +117,18 @@ static void caam_jr_dequeue(unsigned long devarg)
/* set done */
wr_reg32(&jrp->rregs->outring_rmvd, 1);

spin_unlock_irqrestore(&jrp->outlock, flags);
spin_unlock_bh(&jrp->outlock);

/* Finally, execute user's callback */
usercall(dev, userdesc, userstatus, userarg);

spin_lock_irqsave(&jrp->outlock, flags);
spin_lock_bh(&jrp->outlock);

head = ACCESS_ONCE(jrp->head);
sw_idx = tail = jrp->tail;
}

spin_unlock_irqrestore(&jrp->outlock, flags);
spin_unlock_bh(&jrp->outlock);

/* reenable / unmask IRQs */
clrbits32(&jrp->rregs->rconfig_lo, JRCFG_IMSK);
Expand All @@ -148,23 +147,22 @@ int caam_jr_register(struct device *ctrldev, struct device **rdev)
{
struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev);
struct caam_drv_private_jr *jrpriv = NULL;
unsigned long flags;
int ring;

/* Lock, if free ring - assign, unlock */
spin_lock_irqsave(&ctrlpriv->jr_alloc_lock, flags);
spin_lock(&ctrlpriv->jr_alloc_lock);
for (ring = 0; ring < ctrlpriv->total_jobrs; ring++) {
jrpriv = dev_get_drvdata(ctrlpriv->jrdev[ring]);
if (jrpriv->assign == JOBR_UNASSIGNED) {
jrpriv->assign = JOBR_ASSIGNED;
*rdev = ctrlpriv->jrdev[ring];
spin_unlock_irqrestore(&ctrlpriv->jr_alloc_lock, flags);
spin_unlock(&ctrlpriv->jr_alloc_lock);
return ring;
}
}

/* If assigned, write dev where caller needs it */
spin_unlock_irqrestore(&ctrlpriv->jr_alloc_lock, flags);
spin_unlock(&ctrlpriv->jr_alloc_lock);
*rdev = NULL;

return -ENODEV;
Expand All @@ -182,7 +180,6 @@ int caam_jr_deregister(struct device *rdev)
{
struct caam_drv_private_jr *jrpriv = dev_get_drvdata(rdev);
struct caam_drv_private *ctrlpriv;
unsigned long flags;

/* Get the owning controller's private space */
ctrlpriv = dev_get_drvdata(jrpriv->parentdev);
Expand All @@ -195,9 +192,9 @@ int caam_jr_deregister(struct device *rdev)
return -EBUSY;

/* Release ring */
spin_lock_irqsave(&ctrlpriv->jr_alloc_lock, flags);
spin_lock(&ctrlpriv->jr_alloc_lock);
jrpriv->assign = JOBR_UNASSIGNED;
spin_unlock_irqrestore(&ctrlpriv->jr_alloc_lock, flags);
spin_unlock(&ctrlpriv->jr_alloc_lock);

return 0;
}
Expand Down Expand Up @@ -238,7 +235,6 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,
{
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
struct caam_jrentry_info *head_entry;
unsigned long flags;
int head, tail, desc_size;
dma_addr_t desc_dma;

Expand All @@ -249,14 +245,14 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,
return -EIO;
}

spin_lock_irqsave(&jrp->inplock, flags);
spin_lock(&jrp->inplock);

head = jrp->head;
tail = ACCESS_ONCE(jrp->tail);

if (!rd_reg32(&jrp->rregs->inpring_avail) ||
CIRC_SPACE(head, tail, JOBR_DEPTH) <= 0) {
spin_unlock_irqrestore(&jrp->inplock, flags);
spin_unlock(&jrp->inplock);
dma_unmap_single(dev, desc_dma, desc_size, DMA_TO_DEVICE);
return -EBUSY;
}
Expand All @@ -280,7 +276,7 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,

wr_reg32(&jrp->rregs->inpring_jobadd, 1);

spin_unlock_irqrestore(&jrp->inplock, flags);
spin_unlock(&jrp->inplock);

return 0;
}
Expand Down

0 comments on commit 4bba1e9

Please sign in to comment.