Skip to contentSkip to conversation

CAAM job ring driver cleanups

PATCH Superseded Vakul Garg 2 participants 7 messages Mar 15, 2019 – Mar 21, 2019

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Vakul Garg

author
#0 lore raw

v2 cover CAAM job ring driver cleanups

This patchset cleans up caam job ring driver.
The patch series needs to be applied after merging below mentioned patch.

https://www.mail-archive.com/[email protected]/msg37068.html

Vakul Garg (3):
crypto: caam/jr - Remove spinlock for output job ring
crypto: caam/jr - Remove redundant vars from job ring private data
crypto: caam/jr - Remove extra memory barrier during job ring enqueue

 drivers/crypto/caam/intern.h |  3 ---
 drivers/crypto/caam/jr.c     | 17 +++++------------
 2 files changed, 5 insertions(+), 15 deletions(-)
Signature · 1 line
2.13.6
author
#1 lore raw

PATCH v2 1/3 crypto: caam/jr - Remove spinlock for output job ring

For each job ring pair, the output ring is processed exactly by one cpu at a time under a tasklet context (one per ring). Therefore, there is no need to protect a job ring's access & its private data structure using a lock. Hence the lock can be removed.

---
Changes since v1:
- Corrected code comment as per Chris Spencer's suggestion

 drivers/crypto/caam/intern.h | 1 -
 drivers/crypto/caam/jr.c     | 7 +------
 2 files changed, 1 insertion(+), 7 deletions(-)
drivers/crypto/caam/intern.h +0 -1
index 30d5b6c5892f..48d62e020599 100644
@@ -56,7 +56,6 @@ struct caam_drv_private_jr {
 	u32 inpring_avail;	/* Number of free entries in input ring */
 	int head;			/* entinfo (s/w ring) head index */
 	dma_addr_t *inpring;	/* Base of input ring, alloc DMA-safe */
-	spinlock_t outlock ____cacheline_aligned; /* Output ring index lock */
 	int out_ring_read_index;	/* Output index "tail" */
 	int tail;			/* entinfo (s/w ring) tail index */
 	struct jr_outentry *outring;	/* Base of output ring, DMA-safe */
drivers/crypto/caam/jr.c +1 -6
index b9caa95755d1..d1021026f5b2 100644
@@ -177,8 +177,6 @@ static void caam_jr_dequeue(unsigned long devarg)
 
 		head = READ_ONCE(jrp->head);
 
-		spin_lock(&jrp->outlock);
-
 		sw_idx = tail = jrp->tail;
 		hw_idx = jrp->out_ring_read_index;
 
@@ -201,7 +199,7 @@ static void caam_jr_dequeue(unsigned long devarg)
 		/* mark completed, avoid matching on a recycled desc addr */
 		jrp->entinfo[sw_idx].desc_addr_dma = 0;
 
-		/* Stash callback params for use outside of lock */
+		/* Stash callback params */
 		usercall = jrp->entinfo[sw_idx].callbk;
 		userarg = jrp->entinfo[sw_idx].cbkarg;
 		userdesc = jrp->entinfo[sw_idx].desc_addr_virt;
@@ -234,8 +232,6 @@ static void caam_jr_dequeue(unsigned long devarg)
 			jrp->tail = tail;
 		}
 
-		spin_unlock(&jrp->outlock);
-
 		/* Finally, execute user's callback */
 		usercall(dev, userdesc, userstatus, userarg);
 		outring_used--;
@@ -452,7 +448,6 @@ static int caam_jr_init(struct device *dev)
 	jrp->inpring_avail = JOBR_DEPTH;
 
 	spin_lock_init(&jrp->inplock);
-	spin_lock_init(&jrp->outlock);
 
 	/* Select interrupt coalescing parameters */
 	clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JOBR_INTC |
Signature · 1 line
2.13.6
maintainer Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] crypto: caam/jr - Remove spinlock for output job ring

Quoted 6 lines · Vakul Garg

For each job ring pair, the output ring is processed exactly by one cpu at a time under a tasklet context (one per ring). Therefore, there is no need to protect a job ring's access & its private data structure using a lock. Hence the lock can be removed.

Thanks,
Horia

author
#3 lore raw

PATCH v2 2/3 crypto: caam/jr - Removed redundant vars from job ring private data

In reply to Vakul Garg

For each job ring, the variable 'ringsize' is initialised but never used. Similarly variables 'inp_ring_read_index' and 'head' always track the same value and instead of 'inp_ring_read_index', caam_jr_enqueue() can use 'head' itself. Both these variables have been removed.

---
 drivers/crypto/caam/intern.h | 2 --
 drivers/crypto/caam/jr.c     | 6 +-----
 2 files changed, 1 insertion(+), 7 deletions(-)
drivers/crypto/caam/intern.h +0 -2
index 48d62e020599..3392615dc91b 100644
@@ -49,10 +49,8 @@ struct caam_drv_private_jr {
 	atomic_t tfm_count ____cacheline_aligned;
 
 	/* Job ring info */
-	int ringsize;	/* Size of rings (assume input = output) */
 	struct caam_jrentry_info *entinfo;	/* Alloc'ed 1 per ring entry */
 	spinlock_t inplock ____cacheline_aligned; /* Input ring index lock */
-	int inp_ring_write_index;	/* Input index "tail" */
 	u32 inpring_avail;	/* Number of free entries in input ring */
 	int head;			/* entinfo (s/w ring) head index */
 	dma_addr_t *inpring;	/* Base of input ring, alloc DMA-safe */
drivers/crypto/caam/jr.c +1 -5
index d1021026f5b2..e95f82778fa1 100644
@@ -358,7 +358,7 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,
 	head_entry->cbkarg = areq;
 	head_entry->desc_addr_dma = desc_dma;
 
-	jrp->inpring[jrp->inp_ring_write_index] = cpu_to_caam_dma(desc_dma);
+	jrp->inpring[head] = cpu_to_caam_dma(desc_dma);
 
 	/*
 	 * Guarantee that the descriptor's DMA address has been written to
@@ -367,8 +367,6 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,
 	 */
 	smp_wmb();
 
-	jrp->inp_ring_write_index = (jrp->inp_ring_write_index + 1) &
-				    (JOBR_DEPTH - 1);
 	jrp->head = (head + 1) & (JOBR_DEPTH - 1);
 
 	/*
@@ -434,7 +432,6 @@ static int caam_jr_init(struct device *dev)
 		jrp->entinfo[i].desc_addr_dma = !0;
 
 	/* Setup rings */
-	jrp->inp_ring_write_index = 0;
 	jrp->out_ring_read_index = 0;
 	jrp->head = 0;
 	jrp->tail = 0;
@@ -444,7 +441,6 @@ static int caam_jr_init(struct device *dev)
 	wr_reg32(&jrp->rregs->inpring_size, JOBR_DEPTH);
 	wr_reg32(&jrp->rregs->outring_size, JOBR_DEPTH);
 
-	jrp->ringsize = JOBR_DEPTH;
 	jrp->inpring_avail = JOBR_DEPTH;
 
 	spin_lock_init(&jrp->inplock);
Signature · 1 line
2.13.6
maintainer
#4 lore raw

Re: [PATCH v2 2/3] crypto: caam/jr - Removed redundant vars from job ring private data

Quoted 5 lines · Vakul Garg

For each job ring, the variable 'ringsize' is initialised but never used. Similarly variables 'inp_ring_read_index' and 'head' always track the same value and instead of 'inp_ring_read_index', caam_jr_enqueue() can use 'head' itself. Both these variables have been removed.

Typo: s/inp_ring_read_index/inp_ring_write_index

Quoted 1 line
drivers/crypto/caam/intern.h +0 -1
-	int inp_ring_write_index;	/* Input index "tail" */

[snip]

Quoted 2 lines
drivers/crypto/caam/jr.c +1 -1
-	jrp->inpring[jrp->inp_ring_write_index] = cpu_to_caam_dma(desc_dma);
+	jrp->inpring[head] = cpu_to_caam_dma(desc_dma);

[snip]

Quoted 2 lines
drivers/crypto/caam/jr.c +0 -2
-	jrp->inp_ring_write_index = (jrp->inp_ring_write_index + 1) &
-				    (JOBR_DEPTH - 1);

[snip]

drivers/crypto/caam/jr.c static int caam_jr_init(struct device *dev) · line 437

Quoted 1 line
drivers/crypto/caam/jr.c +0 -1
-	jrp->inp_ring_write_index = 0;

Horia

author
#5 lore raw

PATCH v2 3/3 crypto: caam/jr - Remove extra memory barrier during job ring enqueue

In reply to Vakul Garg

In caam_jr_enqueue(), a write barrier is needed to order stores to job ring slot before declaring addition of new job into input job ring. The register write is done using wr_reg32() which internally uses iowrite32() for write operation. The api iowrite32() issues a write barrier before issuing write operation. Therefore, the wmb() preceding wr_reg32() can be safely removed.

---
 drivers/crypto/caam/jr.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/crypto/caam/jr.c +4 -2
index e95f82778fa1..1de2562d0982 100644
@@ -371,9 +371,11 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,
 
 	/*
 	 * Ensure that all job information has been written before
-	 * notifying CAAM that a new job was added to the input ring.
+	 * 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.
 	 */
-	wmb();
 
 	wr_reg32(&jrp->rregs->inpring_jobadd, 1);
 
Signature · 1 line
2.13.6
maintainer Reviewed-by on v2 3/3
#6 lore raw

Re: [PATCH v2 3/3] crypto: caam/jr - Remove extra memory barrier during job ring enqueue

Quoted 8 lines · Vakul Garg

In caam_jr_enqueue(), a write barrier is needed to order stores to job ring slot before declaring addition of new job into input job ring. The register write is done using wr_reg32() which internally uses iowrite32() for write operation. The api iowrite32() issues a write barrier before issuing write operation. Therefore, the wmb() preceding wr_reg32() can be safely removed.

Thanks,
Horia