* [PATCH v2 0/3] CAAM job ring driver cleanups
@ 2019-03-15 11:25 Vakul Garg
2019-03-15 11:25 ` [PATCH v2 1/3] crypto: caam/jr - Remove spinlock for output job ring Vakul Garg
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Vakul Garg @ 2019-03-15 11:25 UTC (permalink / raw)
To: linux-crypto, herbert; +Cc: Horia Geanta, Aymen Sghaier, Vakul Garg
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/linux-crypto@vger.kernel.org/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(-)
--
2.13.6
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/3] crypto: caam/jr - Remove spinlock for output job ring
2019-03-15 11:25 [PATCH v2 0/3] CAAM job ring driver cleanups Vakul Garg
@ 2019-03-15 11:25 ` Vakul Garg
2019-03-21 16:42 ` Horia Geanta
2019-03-15 11:25 ` [PATCH v2 2/3] crypto: caam/jr - Removed redundant vars from job ring private data Vakul Garg
2019-03-15 11:25 ` [PATCH v2 3/3] crypto: caam/jr - Remove extra memory barrier during job ring enqueue Vakul Garg
2 siblings, 1 reply; 7+ messages in thread
From: Vakul Garg @ 2019-03-15 11:25 UTC (permalink / raw)
To: linux-crypto, herbert; +Cc: Horia Geanta, Aymen Sghaier, 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.
Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
---
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(-)
diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h
index 30d5b6c5892f..48d62e020599 100644
--- a/drivers/crypto/caam/intern.h
+++ b/drivers/crypto/caam/intern.h
@@ -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 */
diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index b9caa95755d1..d1021026f5b2 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -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 |
--
2.13.6
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/3] crypto: caam/jr - Removed redundant vars from job ring private data
2019-03-15 11:25 [PATCH v2 0/3] CAAM job ring driver cleanups Vakul Garg
2019-03-15 11:25 ` [PATCH v2 1/3] crypto: caam/jr - Remove spinlock for output job ring Vakul Garg
@ 2019-03-15 11:25 ` Vakul Garg
2019-03-21 15:34 ` Horia Geanta
2019-03-15 11:25 ` [PATCH v2 3/3] crypto: caam/jr - Remove extra memory barrier during job ring enqueue Vakul Garg
2 siblings, 1 reply; 7+ messages in thread
From: Vakul Garg @ 2019-03-15 11:25 UTC (permalink / raw)
To: linux-crypto, herbert; +Cc: Horia Geanta, Aymen Sghaier, 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.
Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
---
drivers/crypto/caam/intern.h | 2 --
drivers/crypto/caam/jr.c | 6 +-----
2 files changed, 1 insertion(+), 7 deletions(-)
diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h
index 48d62e020599..3392615dc91b 100644
--- a/drivers/crypto/caam/intern.h
+++ b/drivers/crypto/caam/intern.h
@@ -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 */
diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index d1021026f5b2..e95f82778fa1 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -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);
--
2.13.6
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] crypto: caam/jr - Remove extra memory barrier during job ring enqueue
2019-03-15 11:25 [PATCH v2 0/3] CAAM job ring driver cleanups Vakul Garg
2019-03-15 11:25 ` [PATCH v2 1/3] crypto: caam/jr - Remove spinlock for output job ring Vakul Garg
2019-03-15 11:25 ` [PATCH v2 2/3] crypto: caam/jr - Removed redundant vars from job ring private data Vakul Garg
@ 2019-03-15 11:25 ` Vakul Garg
2019-03-21 11:45 ` Horia Geanta
2 siblings, 1 reply; 7+ messages in thread
From: Vakul Garg @ 2019-03-15 11:25 UTC (permalink / raw)
To: linux-crypto, herbert; +Cc: Horia Geanta, Aymen Sghaier, 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.
Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
---
drivers/crypto/caam/jr.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index e95f82778fa1..1de2562d0982 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -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);
--
2.13.6
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/3] crypto: caam/jr - Remove extra memory barrier during job ring enqueue
2019-03-15 11:25 ` [PATCH v2 3/3] crypto: caam/jr - Remove extra memory barrier during job ring enqueue Vakul Garg
@ 2019-03-21 11:45 ` Horia Geanta
0 siblings, 0 replies; 7+ messages in thread
From: Horia Geanta @ 2019-03-21 11:45 UTC (permalink / raw)
To: Vakul Garg, linux-crypto, herbert; +Cc: Aymen Sghaier
On 3/15/2019 1:25 PM, Vakul Garg wrote:
> 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.
>
> Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Thanks,
Horia
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] crypto: caam/jr - Removed redundant vars from job ring private data
2019-03-15 11:25 ` [PATCH v2 2/3] crypto: caam/jr - Removed redundant vars from job ring private data Vakul Garg
@ 2019-03-21 15:34 ` Horia Geanta
0 siblings, 0 replies; 7+ messages in thread
From: Horia Geanta @ 2019-03-21 15:34 UTC (permalink / raw)
To: Vakul Garg, linux-crypto, herbert; +Cc: Aymen Sghaier
On 3/15/2019 1:25 PM, Vakul Garg wrote:
> 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
> - int inp_ring_write_index; /* Input index "tail" */
[snip]
> - jrp->inpring[jrp->inp_ring_write_index] = cpu_to_caam_dma(desc_dma);
> + jrp->inpring[head] = cpu_to_caam_dma(desc_dma);
[snip]
> - jrp->inp_ring_write_index = (jrp->inp_ring_write_index + 1) &
> - (JOBR_DEPTH - 1);
[snip]
> - jrp->inp_ring_write_index = 0;
Horia
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/3] crypto: caam/jr - Remove spinlock for output job ring
2019-03-15 11:25 ` [PATCH v2 1/3] crypto: caam/jr - Remove spinlock for output job ring Vakul Garg
@ 2019-03-21 16:42 ` Horia Geanta
0 siblings, 0 replies; 7+ messages in thread
From: Horia Geanta @ 2019-03-21 16:42 UTC (permalink / raw)
To: Vakul Garg, linux-crypto, herbert; +Cc: Aymen Sghaier
On 3/15/2019 1:25 PM, Vakul Garg wrote:
> 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.
>
> Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Thanks,
Horia
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-03-21 16:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-15 11:25 [PATCH v2 0/3] CAAM job ring driver cleanups Vakul Garg
2019-03-15 11:25 ` [PATCH v2 1/3] crypto: caam/jr - Remove spinlock for output job ring Vakul Garg
2019-03-21 16:42 ` Horia Geanta
2019-03-15 11:25 ` [PATCH v2 2/3] crypto: caam/jr - Removed redundant vars from job ring private data Vakul Garg
2019-03-21 15:34 ` Horia Geanta
2019-03-15 11:25 ` [PATCH v2 3/3] crypto: caam/jr - Remove extra memory barrier during job ring enqueue Vakul Garg
2019-03-21 11:45 ` Horia Geanta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).