From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: Victoria Milhoan <vicki.milhoan@freescale.com>
Cc: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au,
horia.geanta@freescale.com, ruchika.gupta@freescale.com
Subject: Re: [PATCH RFC 01/11] crypto: caam - Add cache coherency support
Date: Wed, 17 Jun 2015 10:23:03 +0200 [thread overview]
Message-ID: <20150617082303.GM7947@pengutronix.de> (raw)
In-Reply-To: <1434412379-11623-2-git-send-email-vicki.milhoan@freescale.com>
On Mon, Jun 15, 2015 at 04:52:49PM -0700, Victoria Milhoan wrote:
> Freescale i.MX6 ARM platforms do not support hardware cache coherency. This
> patch adds cache coherency support to the CAAM driver.
>
> Signed-off-by: Victoria Milhoan <vicki.milhoan@freescale.com>
> ---
> drivers/crypto/caam/caamhash.c | 28 +++++++++++++++++----------
> drivers/crypto/caam/caamrng.c | 10 +++++++++-
> drivers/crypto/caam/jr.c | 42 +++++++++++++++++++++++++++++++++++++++-
> drivers/crypto/caam/key_gen.c | 4 +++-
> drivers/crypto/caam/sg_sw_sec4.h | 1 +
> 5 files changed, 72 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
> index ba0532e..1662c65 100644
> --- a/drivers/crypto/caam/caamhash.c
> +++ b/drivers/crypto/caam/caamhash.c
> @@ -500,6 +500,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in,
> #endif
> }
> dma_unmap_single(jrdev, src_dma, *keylen, DMA_TO_DEVICE);
> + dma_sync_single_for_cpu(jrdev, dst_dma, digestsize, DMA_FROM_DEVICE);
> dma_unmap_single(jrdev, dst_dma, digestsize, DMA_FROM_DEVICE);
>
> *keylen = digestsize;
> @@ -608,8 +609,11 @@ static inline void ahash_unmap(struct device *dev,
> if (edesc->src_nents)
> dma_unmap_sg_chained(dev, req->src, edesc->src_nents,
> DMA_TO_DEVICE, edesc->chained);
> - if (edesc->dst_dma)
> + if (edesc->dst_dma) {
> + dma_sync_single_for_cpu(dev, edesc->dst_dma, dst_len,
> + DMA_FROM_DEVICE);
> dma_unmap_single(dev, edesc->dst_dma, dst_len, DMA_FROM_DEVICE);
> + }
>
> if (edesc->sec4_sg_bytes)
> dma_unmap_single(dev, edesc->sec4_sg_dma,
> @@ -624,8 +628,12 @@ static inline void ahash_unmap_ctx(struct device *dev,
> struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
> struct caam_hash_state *state = ahash_request_ctx(req);
>
> - if (state->ctx_dma)
> + if (state->ctx_dma) {
> + if ((flag == DMA_FROM_DEVICE) || (flag == DMA_BIDIRECTIONAL))
> + dma_sync_single_for_cpu(dev, state->ctx_dma,
> + ctx->ctx_len, flag);
> dma_unmap_single(dev, state->ctx_dma, ctx->ctx_len, flag);
> + }
> ahash_unmap(dev, edesc, req, dst_len);
> }
Unneeded syncing, dma_unmap does it as long as it is not told otherwise.
(...)
> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> index 26a544b..a8c4af9 100644
> --- a/drivers/crypto/caam/caamrng.c
> +++ b/drivers/crypto/caam/caamrng.c
> @@ -80,9 +80,12 @@ static struct caam_rng_ctx *rng_ctx;
>
> static inline void rng_unmap_buf(struct device *jrdev, struct buf_data *bd)
> {
> - if (bd->addr)
> + if (bd->addr) {
> + dma_sync_single_for_cpu(jrdev, bd->addr, RN_BUF_SIZE,
> + DMA_FROM_DEVICE);
> dma_unmap_single(jrdev, bd->addr, RN_BUF_SIZE,
> DMA_FROM_DEVICE);
> + }
> }
>
dito
> static inline void rng_unmap_ctx(struct caam_rng_ctx *ctx)
> @@ -108,6 +111,10 @@ static void rng_done(struct device *jrdev, u32 *desc, u32 err, void *context)
>
> atomic_set(&bd->empty, BUF_NOT_EMPTY);
> complete(&bd->filled);
> +
> + /* Buffer refilled, invalidate cache */
> + dma_sync_single_for_cpu(jrdev, bd->addr, RN_BUF_SIZE, DMA_FROM_DEVICE);
> +
This seems to be okay, though.
> #ifdef DEBUG
> print_hex_dump(KERN_ERR, "rng refreshed buf@: ",
> DUMP_PREFIX_ADDRESS, 16, 4, bd->buf, RN_BUF_SIZE, 1);
> @@ -211,6 +218,7 @@ static inline int rng_create_sh_desc(struct caam_rng_ctx *ctx)
> print_hex_dump(KERN_ERR, "rng shdesc@: ", DUMP_PREFIX_ADDRESS, 16, 4,
> desc, desc_bytes(desc), 1);
> #endif
> +
> return 0;
> }
>
> diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> index b8b5d47..a693bf7 100644
> --- a/drivers/crypto/caam/jr.c
> +++ b/drivers/crypto/caam/jr.c
> @@ -168,6 +168,9 @@ static void caam_jr_dequeue(unsigned long devarg)
> void (*usercall)(struct device *dev, u32 *desc, u32 status, void *arg);
> u32 *userdesc, userstatus;
> void *userarg;
> + dma_addr_t outbusaddr;
> +
> + outbusaddr = rd_reg64(&jrp->rregs->outring_base);
>
> while (rd_reg32(&jrp->rregs->outring_used)) {
>
> @@ -177,10 +180,19 @@ static void caam_jr_dequeue(unsigned long devarg)
>
> sw_idx = tail = jrp->tail;
> hw_idx = jrp->out_ring_read_index;
> + dma_sync_single_for_cpu(dev, outbusaddr,
> + sizeof(struct jr_outentry) * JOBR_DEPTH,
> + DMA_FROM_DEVICE);
>
This one and ...
(...)
> @@ -321,7 +346,7 @@ 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;
> int head, tail, desc_size;
> - dma_addr_t desc_dma;
> + dma_addr_t desc_dma, inpbusaddr;
>
> desc_size = (*desc & HDR_JD_LENGTH_MASK) * sizeof(u32);
> desc_dma = dma_map_single(dev, desc, desc_size, DMA_TO_DEVICE);
> @@ -330,6 +355,11 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,
> return -EIO;
> }
>
> + inpbusaddr = rd_reg64(&jrp->rregs->inpring_base);
> + dma_sync_single_for_device(dev, inpbusaddr,
> + sizeof(dma_addr_t) * JOBR_DEPTH,
> + DMA_TO_DEVICE);
> +
> spin_lock_bh(&jrp->inplock);
>
> head = jrp->head;
> @@ -351,12 +381,22 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,
>
> jrp->inpring[jrp->inp_ring_write_index] = desc_dma;
>
> + dma_sync_single_for_device(dev, inpbusaddr,
> + sizeof(dma_addr_t) * JOBR_DEPTH,
> + DMA_TO_DEVICE);
> +
... these one are also unnecessary, because the buffers are mapped with
dma_alloc_coherent.
> smp_wmb();
>
> jrp->inp_ring_write_index = (jrp->inp_ring_write_index + 1) &
> (JOBR_DEPTH - 1);
> jrp->head = (head + 1) & (JOBR_DEPTH - 1);
>
> + /*
> + * Ensure that all job information has been written before
> + * notifying CAAM that a new job was added to the input ring.
> + */
> + wmb();
> +
> wr_reg32(&jrp->rregs->inpring_jobadd, 1);
>
> spin_unlock_bh(&jrp->inplock);
> diff --git a/drivers/crypto/caam/key_gen.c b/drivers/crypto/caam/key_gen.c
> index e1eaf4f..6481f71 100644
> --- a/drivers/crypto/caam/key_gen.c
> +++ b/drivers/crypto/caam/key_gen.c
> @@ -71,6 +71,7 @@ int gen_split_key(struct device *jrdev, u8 *key_out, int split_key_len,
> }
>
> init_job_desc(desc, 0);
> +
> append_key(desc, dma_addr_in, keylen, CLASS_2 | KEY_DEST_CLASS_REG);
>
> /* Sets MDHA up into an HMAC-INIT */
> @@ -111,7 +112,8 @@ int gen_split_key(struct device *jrdev, u8 *key_out, int split_key_len,
> split_key_pad_len, 1);
> #endif
> }
> -
> + dma_sync_single_for_cpu(jrdev, dma_addr_out, split_key_pad_len,
> + DMA_FROM_DEVICE);
> dma_unmap_single(jrdev, dma_addr_out, split_key_pad_len,
> DMA_FROM_DEVICE);
> out_unmap_in:
unneeded.
Regards,
Steffen
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2015-06-17 8:23 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-15 23:52 [PATCH RFC 00/11] crypto: caam - Add i.MX6 support to the Freescale CAAM driver Victoria Milhoan
2015-06-15 23:52 ` [PATCH RFC 01/11] crypto: caam - Add cache coherency support Victoria Milhoan
2015-06-16 1:35 ` Herbert Xu
2015-06-16 2:33 ` Herbert Xu
2015-06-16 3:29 ` Herbert Xu
2015-06-17 8:23 ` Steffen Trumtrar [this message]
2015-06-15 23:52 ` [PATCH RFC 02/11] crypto: caam - Add register I/O primitives for ARM compatibility Victoria Milhoan
2015-06-15 23:52 ` [PATCH RFC 03/11] crypto: caam - Enable and disable clocks on Freescale i.MX platforms Victoria Milhoan
2015-06-16 4:30 ` Herbert Xu
2015-06-16 4:32 ` Herbert Xu
2015-06-15 23:52 ` [PATCH RFC 04/11] crypto: caam - Modify Freescale CAAM driver Scatter Gather entry definition Victoria Milhoan
2015-06-15 23:52 ` [PATCH RFC 05/11] crypto: caam - Add cache coherency support to Freescale CAAM scatterlist implementation Victoria Milhoan
2015-06-16 6:04 ` Herbert Xu
2015-06-17 7:44 ` Steffen Trumtrar
2015-06-15 23:52 ` [PATCH RFC 06/11] crypto: caam - Enable MXC devices to select CAAM driver in Kconfig Victoria Milhoan
2015-06-17 7:27 ` Steffen Trumtrar
2015-07-24 17:14 ` Horia Geantă
2015-07-25 1:43 ` Herbert Xu
2015-06-15 23:52 ` [PATCH RFC 07/11] crypto: caam - Unmap data prior to displaying data in print statements Victoria Milhoan
2015-06-15 23:52 ` [PATCH RFC 08/11] crypto: caam - improve initalization for context state saves Victoria Milhoan
2015-06-16 6:41 ` Herbert Xu
2015-06-15 23:52 ` [PATCH RFC 09/11] crypto: caam - Fix incorrect size when DMA unmapping buffer Victoria Milhoan
2015-06-16 6:41 ` Herbert Xu
2015-06-15 23:52 ` [PATCH RFC 10/11] crypto: caam - Provide correct value to iounmap() in controller driver Victoria Milhoan
2015-06-16 6:41 ` Herbert Xu
2015-06-15 23:52 ` [PATCH RFC 11/11] crypto: caam - fix RNG buffer cache alignment Victoria Milhoan
2015-06-16 6:41 ` Herbert Xu
2015-06-16 0:34 ` [PATCH RFC 00/11] crypto: caam - Add i.MX6 support to the Freescale CAAM driver Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150617082303.GM7947@pengutronix.de \
--to=s.trumtrar@pengutronix.de \
--cc=herbert@gondor.apana.org.au \
--cc=horia.geanta@freescale.com \
--cc=linux-crypto@vger.kernel.org \
--cc=ruchika.gupta@freescale.com \
--cc=vicki.milhoan@freescale.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.