RFC: support for MV_CESA with TDMA
Subsystems (4)
PATCH 4/13 mv_cesa: split up processing callbacks
In reply to Phil SutterHave a dedicated function initialising the full SRAM config, then use a minimal callback for changing only relevant parts of it.
--- drivers/crypto/mv_cesa.c | 87 +++++++++++++++++++++++++++++++++------------ 1 files changed, 64 insertions(+), 23 deletions(-)
drivers/crypto/mv_cesa.c +64 -23
@@ -62,7 +62,7 @@ struct req_progress {struct scatterlist *src_sg;struct scatterlist *dst_sg;void (*complete) (void ); -void (*process) (int is_first); +void (*process) (void );/* src mostly */ int sg_src_left;
@@ -265,9 +265,8 @@ static void setup_data_in(void) p->crypt_len = data_in_sram; } -static void mv_process_current_q (int first_block) +static void mv_init_crypt_config (struct ablkcipher_request *req) { -struct ablkcipher_request *req =ablkcipher_request_cast (cpg->cur_req);struct mv_ctx *ctx =crypto_tfm_ctx (req->base.tfm);struct mv_req_ctx *req_ctx =ablkcipher_request_ctx (req);struct sec_accel_config *op = &cpg->sa_sram.op;
@@ -281,8 +280,6 @@ static void mv_process_current_q(int first_block) op->config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_CBC ; op->enc_iv =ENC_IV_POINT (SRAM_DATA_IV ) |ENC_IV_BUF_POINT (SRAM_DATA_IV_BUF ); -if (!first_block) -memcpy (req->info, cpg->sram +SRAM_DATA_IV_BUF ,16 );memcpy (cpg->sa_sram.sa_iv, req->info,16 );break ; }
@@ -308,9 +305,8 @@ static void mv_process_current_q(int first_block) op->enc_p =ENC_P_SRC (SRAM_DATA_IN_START ) |ENC_P_DST (SRAM_DATA_OUT_START ); op->enc_key_p =SRAM_DATA_KEY_P ; - -setup_data_in (); op->enc_len = cpg->p.crypt_len; +memcpy (cpg->sram +SRAM_CONFIG , &cpg->sa_sram,sizeof (struct sec_accel_sram ));
@@ -319,6 +315,17 @@ static void mv_process_current_q(int first_block)writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); } +static void mv_update_crypt_config (void ) +{ +/* update the enc_len field only */ +memcpy (cpg->sram +SRAM_CONFIG +2 *sizeof (u32), + &cpg->p.crypt_len,sizeof (u32)); + +/* GO */ +mv_setup_timer (); +writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); +} +static void mv_crypto_algo_completion (void ) {struct ablkcipher_request *req =ablkcipher_request_cast (cpg->cur_req);
@@ -330,9 +337,8 @@ static void mv_crypto_algo_completion(void)memcpy (req->info, cpg->sram +SRAM_DATA_IV_BUF ,16 ); } -static void mv_process_hash_current (int first_block) +static void mv_init_hash_config (struct ahash_request *req) { -struct ahash_request *req =ahash_request_cast (cpg->cur_req);const struct mv_tfm_hash_ctx *tfm_ctx =crypto_tfm_ctx (req->base.tfm);struct mv_req_hash_ctx *req_ctx =ahash_request_ctx (req);struct req_progress *p = &cpg->p;
@@ -355,8 +361,6 @@ static void mv_process_hash_current(int first_block)MAC_SRC_DATA_P (SRAM_DATA_IN_START ) |MAC_SRC_TOTAL_LEN ((u32 )req_ctx->count); -setup_data_in (); - op->mac_digest =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); op->mac_iv =
@@ -379,13 +383,11 @@ static void mv_process_hash_current(int first_block)else op->config |=CFG_MID_FRAG ; -if (first_block) { -writel (req_ctx->state[0 ], cpg->reg +DIGEST_INITIAL_VAL_A ); -writel (req_ctx->state[1 ], cpg->reg +DIGEST_INITIAL_VAL_B ); -writel (req_ctx->state[2 ], cpg->reg +DIGEST_INITIAL_VAL_C ); -writel (req_ctx->state[3 ], cpg->reg +DIGEST_INITIAL_VAL_D ); -writel (req_ctx->state[4 ], cpg->reg +DIGEST_INITIAL_VAL_E ); - } +writel (req_ctx->state[0 ], cpg->reg +DIGEST_INITIAL_VAL_A ); +writel (req_ctx->state[1 ], cpg->reg +DIGEST_INITIAL_VAL_B ); +writel (req_ctx->state[2 ], cpg->reg +DIGEST_INITIAL_VAL_C ); +writel (req_ctx->state[3 ], cpg->reg +DIGEST_INITIAL_VAL_D ); +writel (req_ctx->state[4 ], cpg->reg +DIGEST_INITIAL_VAL_E ); } memcpy(cpg->sram + SRAM_CONFIG, &cpg->sa_sram,
@@ -396,6 +398,42 @@ static void mv_process_hash_current(int first_block)writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); } +static void mv_update_hash_config (void ) +{ +struct ahash_request *req =ahash_request_cast (cpg->cur_req); +struct mv_req_hash_ctx *req_ctx =ahash_request_ctx (req); +struct req_progress *p = &cpg->p; +struct sec_accel_config *op = &cpg->sa_sram.op; +int is_last; + +/* update only the config (for changed fragment state) and +* mac_digest (for changed frag len) fields */ + +switch (req_ctx->op) { +case COP_SHA1 : +default : + op->config =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ; +break ; +case COP_HMAC_SHA1 : + op->config =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ; +break ; + } + + is_last = req_ctx->last_chunk + && (p->hw_processed_bytes + p->crypt_len >= p->hw_nbytes) + && (req_ctx->count <=MAX_HW_HASH_SIZE ); + + op->config |= is_last ?CFG_LAST_FRAG :CFG_MID_FRAG ; +memcpy (cpg->sram +SRAM_CONFIG , &op->config,sizeof (u32)); + + op->mac_digest =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); +memcpy (cpg->sram +SRAM_CONFIG +6 *sizeof (u32), &op->mac_digest,sizeof (u32)); + +/* GO */ +mv_setup_timer (); +writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); +} +static inline int mv_hash_import_sha1_ctx (const struct mv_req_hash_ctx *ctx,struct shash_desc *desc) {
@@ -507,7 +545,8 @@ static void dequeue_complete_req(void)if (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) {/* process next scatter list entry */ cpg->eng_st =ENGINE_BUSY ; - cpg->p.process (0 ); +setup_data_in (); + cpg->p.process (); }else { cpg->p.complete (); cpg->eng_st =ENGINE_IDLE ;
@@ -542,7 +581,7 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req)memset (p,0 ,sizeof (struct req_progress )); p->hw_nbytes = req->nbytes; p->complete = mv_crypto_algo_completion; - p->process = mv_process_current_q; + p->process = mv_update_crypt_config; p->copy_back =1 ; p->src_sg = req->src;
@@ -554,7 +593,8 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req) p->sg_dst_left = req->dst->length; } -mv_process_current_q (1 ); +setup_data_in (); +mv_init_crypt_config (req); }static void mv_start_new_hash_req (struct ahash_request *req)
@@ -583,7 +623,7 @@ static void mv_start_new_hash_req(struct ahash_request *req)if (hw_bytes) { p->hw_nbytes = hw_bytes; p->complete = mv_hash_algo_completion; - p->process = mv_process_hash_current; + p->process = mv_update_hash_config;if (unlikely (old_extra_bytes)) { memcpy(cpg->sram + SRAM_DATA_IN_START, ctx->buffer,
@@ -591,7 +631,8 @@ static void mv_start_new_hash_req(struct ahash_request *req) p->crypt_len = old_extra_bytes; } -mv_process_hash_current (1 ); +setup_data_in (); +mv_init_hash_config (req); }else {copy_src_to_buf (p, ctx->buffer + old_extra_bytes, ctx->extra_bytes - old_extra_bytes);
Signature · 1 line
1.7.3.4
PATCH 11/13 mv_cesa: implement descriptor chaining for hashes, too
In reply to Phil Sutter--- drivers/crypto/mv_cesa.c | 89 ++++++++++++++++++---------------------------- 1 files changed, 35 insertions(+), 54 deletions(-)
drivers/crypto/mv_cesa.c +35 -54
@@ -536,34 +536,14 @@ static void mv_init_hash_config(struct ahash_request *req) sizeof(struct sec_accel_sram), DMA_TO_DEVICE);mv_tdma_memcpy (cpg->sram_phys +SRAM_CONFIG , cpg->sa_sram_dma,sizeof (struct sec_accel_sram )); - -mv_tdma_separator (); - -if (req->result) { - req_ctx->result_dma =dma_map_single (cpg->dev, req->result, - req_ctx->digestsize,DMA_FROM_DEVICE ); -mv_tdma_memcpy (req_ctx->result_dma, - cpg->sram_phys +SRAM_DIGEST_BUF , req_ctx->digestsize); - }else { -/* XXX: this fixes some ugly register fuckup bug in the tdma engine -* (no need to sync since the data is ignored anyway) */ -mv_tdma_memcpy (cpg->sa_sram_dma, - cpg->sram_phys +SRAM_CONFIG ,1 ); - } - -/* GO */ -mv_setup_timer (); -mv_tdma_trigger (); -writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); } -static void mv_update_hash_config (void ) +static void mv_update_hash_config (struct ahash_request *req) { -struct ahash_request *req =ahash_request_cast (cpg->cur_req);struct mv_req_hash_ctx *req_ctx =ahash_request_ctx (req);struct req_progress *p = &cpg->p; -struct sec_accel_config *op = &cpg->sa_sram.op;int is_last; +u32 val;/* update only the config (for changed fragment state) and * mac_digest (for changed frag len) fields */
@@ -571,10 +551,10 @@ static void mv_update_hash_config(void)switch (req_ctx->op) {case COP_SHA1 :default : - op->config =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ; + val =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ;break ;case COP_HMAC_SHA1 : - op->config =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ; + val =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ;break ; }
@@ -582,36 +562,11 @@ static void mv_update_hash_config(void) && (p->hw_processed_bytes + p->crypt_len >= p->hw_nbytes) && (req_ctx->count <=MAX_HW_HASH_SIZE ); - op->config |= is_last ?CFG_LAST_FRAG :CFG_MID_FRAG ; -dma_sync_single_for_device (cpg->dev, cpg->sa_sram_dma, -sizeof (u32),DMA_TO_DEVICE ); -mv_tdma_memcpy (cpg->sram_phys +SRAM_CONFIG , - cpg->sa_sram_dma,sizeof (u32)); - - op->mac_digest =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); -dma_sync_single_for_device (cpg->dev, cpg->sa_sram_dma +6 *sizeof (u32), -sizeof (u32),DMA_TO_DEVICE ); -mv_tdma_memcpy (cpg->sram_phys +SRAM_CONFIG +6 *sizeof (u32), - cpg->sa_sram_dma +6 *sizeof (u32),sizeof (u32)); - -mv_tdma_separator (); - -if (req->result) { - req_ctx->result_dma =dma_map_single (cpg->dev, req->result, - req_ctx->digestsize,DMA_FROM_DEVICE ); -mv_tdma_memcpy (req_ctx->result_dma, - cpg->sram_phys +SRAM_DIGEST_BUF , req_ctx->digestsize); - }else { -/* XXX: this fixes some ugly register fuckup bug in the tdma engine -* (no need to sync since the data is ignored anyway) */ -mv_tdma_memcpy (cpg->sa_sram_dma, - cpg->sram_phys +SRAM_CONFIG ,1 ); - } + val |= is_last ?CFG_LAST_FRAG :CFG_MID_FRAG ; +mv_tdma_u32_copy (cpg->sram_phys +SRAM_CONFIG , val); -/* GO */ -mv_setup_timer (); -mv_tdma_trigger (); -writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); + val =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); +mv_tdma_u32_copy (cpg->sram_phys +SRAM_CONFIG +6 *sizeof (u32), val); } static inline int mv_hash_import_sha1_ctx(const struct mv_req_hash_ctx *ctx,
@@ -835,7 +790,6 @@ static void mv_start_new_hash_req(struct ahash_request *req) p->hw_nbytes = hw_bytes; p->complete = mv_hash_algo_completion; - p->process = mv_update_hash_config;if (unlikely (old_extra_bytes)) { dma_sync_single_for_device(cpg->dev, ctx->buffer_dma,
@@ -847,6 +801,33 @@ static void mv_start_new_hash_req(struct ahash_request *req)setup_data_in ();mv_init_hash_config (req); +mv_tdma_separator (); + cpg->p.hw_processed_bytes += cpg->p.crypt_len; +while (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) { + cpg->p.crypt_len =0 ; + +setup_data_in (); +mv_update_hash_config (req); +mv_tdma_separator (); + cpg->p.hw_processed_bytes += cpg->p.crypt_len; + } +if (req->result) { + ctx->result_dma =dma_map_single (cpg->dev, req->result, + ctx->digestsize,DMA_FROM_DEVICE ); +mv_tdma_memcpy (ctx->result_dma, + cpg->sram_phys +SRAM_DIGEST_BUF , + ctx->digestsize); + }else { +/* XXX: this fixes some ugly register fuckup bug in the tdma engine +* (no need to sync since the data is ignored anyway) */ +mv_tdma_memcpy (cpg->sa_sram_dma, + cpg->sram_phys +SRAM_CONFIG ,1 ); + } + +/* GO */ +mv_setup_timer (); +mv_tdma_trigger (); +writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); }static int queue_manag (void *data)
Signature · 1 line
1.7.3.4
PATCH 13/13 mv_cesa, mv_tdma: outsource common dma-pool handling code
In reply to Phil Sutter--- drivers/crypto/dma_desclist.h | 79 +++++++++++++++++++++++++++++++++++ drivers/crypto/mv_cesa.c | 81 +++++++++---------------------------- drivers/crypto/mv_tdma.c | 91 ++++++++++++----------------------------- 3 files changed, 125 insertions(+), 126 deletions(-) create mode 100644 drivers/crypto/dma_desclist.h
drivers/crypto/dma_desclist.h new file +79 -0
@@ -0,0 +1,79 @@ +#ifndef __DMA_DESCLIST__ +#define __DMA_DESCLIST__ + +struct dma_desc { +void *virt; +dma_addr_t phys; +}; + +struct dma_desclist { +struct dma_pool *itempool; +struct dma_desc *desclist; +unsigned long length; +unsigned long usage; +}; + +#define DESCLIST_ITEM (dl, x) ((dl).desclist[(x)].virt) +#define DESCLIST_ITEM_DMA (dl, x) ((dl).desclist[(x)].phys) +#define DESCLIST_FULL (dl) ((dl).length == (dl).usage) + +static inline int +init_dma_desclist (struct dma_desclist *dl,struct device *dev, +size_t size,size_t align,size_t boundary) +{ +#define STRX (x) #x +#define STR (x) STRX(x) + dl->itempool =dma_pool_create ( + "DMA Desclist Pool at "__FILE__"("STR(__LINE__)")", + dev, size, align, boundary); +#undef STR +#undef STRX +if (!dl->itempool) +return 1 ; + dl->desclist =NULL ; + dl->length = dl->usage =0 ; +return 0 ; +} + +static inline int +set_dma_desclist_size (struct dma_desclist *dl,unsigned long nelem) +{ +/* need to increase size first if requested */ +if (nelem > dl->length) { +struct dma_desc *newmem; +int newsize = nelem *sizeof (struct dma_desc ); + + newmem =krealloc (dl->desclist, newsize,GFP_KERNEL ); +if (!newmem) +return -ENOMEM ; + dl->desclist = newmem; + } + +/* allocate/free dma descriptors, adjusting dl->length on the go */ +for (; dl->length < nelem; dl->length++) { +DESCLIST_ITEM (*dl, dl->length) =dma_pool_alloc (dl->itempool, +GFP_KERNEL , &DESCLIST_ITEM_DMA (*dl, dl->length)); +if (!DESCLIST_ITEM (*dl, dl->length)) +return -ENOMEM ; + } +for (; dl->length > nelem; dl->length--) +dma_pool_free (dl->itempool,DESCLIST_ITEM (*dl, dl->length -1 ), +DESCLIST_ITEM_DMA (*dl, dl->length -1 )); + +/* ignore size decreases but those to zero */ +if (!nelem) { +kfree (dl->desclist); + dl->desclist =0 ; + } +return 0 ; +} + +static inline void +fini_dma_desclist (struct dma_desclist *dl) +{ +set_dma_desclist_size (dl,0 ); +dma_pool_destroy (dl->itempool); + dl->length = dl->usage =0 ; +} + +#endif /* __DMA_DESCLIST__ */
drivers/crypto/mv_cesa.c +19 -62
147 lines not on this page · raw message
drivers/crypto/mv_tdma.c +27 -64
167 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 8/13 mv_cesa: fetch extra_bytes via TDMA engine, too
In reply to Phil Sutter--- drivers/crypto/mv_cesa.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/crypto/mv_cesa.c +10 -2
@@ -156,6 +156,7 @@ struct mv_req_hash_ctx {u64 count;u32 state[SHA1_DIGEST_SIZE /4 ];u8 buffer[SHA1_BLOCK_SIZE ]; +dma_addr_t buffer_dma;int first_hash;/* marks that we don't have previous state */ int last_chunk;/* marks that this is the 'final' request */ int extra_bytes;/* unprocessed bytes in buffer */
@@ -636,6 +637,9 @@ static void mv_hash_algo_completion(void)dma_unmap_single (cpg->dev, ctx->result_dma, ctx->digestsize,DMA_FROM_DEVICE ); +dma_unmap_single (cpg->dev, ctx->buffer_dma, +SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); +if (unlikely (ctx->count >MAX_HW_HASH_SIZE )) {mv_save_digest_state (ctx);mv_hash_final_fallback (req);
@@ -755,8 +759,10 @@ static void mv_start_new_hash_req(struct ahash_request *req) p->process = mv_update_hash_config;if (unlikely (old_extra_bytes)) { -memcpy (cpg->sram +SRAM_DATA_IN_START , ctx->buffer, - old_extra_bytes); +dma_sync_single_for_device (cpg->dev, ctx->buffer_dma, +SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); +mv_tdma_memcpy (cpg->sram_phys +SRAM_DATA_IN_START , + ctx->buffer_dma, old_extra_bytes); p->crypt_len = old_extra_bytes; }
@@ -901,6 +907,8 @@ static void mv_init_hash_req_ctx(struct mv_req_hash_ctx *ctx, int op, ctx->first_hash =1 ; ctx->last_chunk = is_last; ctx->count_add = count_add; + ctx->buffer_dma =dma_map_single (cpg->dev, ctx->buffer, +SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); } static void mv_update_hash_req_ctx(struct mv_req_hash_ctx *ctx, int is_last,
Signature · 1 line
1.7.3.4
PATCH 7/13 mv_cesa: have TDMA copy back the digest result
In reply to Phil Sutter--- drivers/crypto/mv_cesa.c | 40 +++++++++++++++++++++++++++++----------- 1 files changed, 29 insertions(+), 11 deletions(-)
drivers/crypto/mv_cesa.c +29 -11
@@ -159,8 +159,10 @@ struct mv_req_hash_ctx {int first_hash;/* marks that we don't have previous state */ int last_chunk;/* marks that this is the 'final' request */ int extra_bytes;/* unprocessed bytes in buffer */ +int digestsize;/* size of the digest */ enum hash_op op;int count_add; +dma_addr_t result_dma; };static void mv_completion_timer_callback (unsigned long unused)
@@ -497,9 +499,17 @@ static void mv_init_hash_config(struct ahash_request *req)mv_tdma_separator (); -/* XXX: this fixes some ugly register fuckup bug in the tdma engine -* (no need to sync since the data is ignored anyway) */ -mv_tdma_memcpy (cpg->sa_sram_dma, cpg->sram_phys +SRAM_CONFIG ,1 ); +if (req->result) { + req_ctx->result_dma =dma_map_single (cpg->dev, req->result, + req_ctx->digestsize,DMA_FROM_DEVICE ); +mv_tdma_memcpy (req_ctx->result_dma, + cpg->sram_phys +SRAM_DIGEST_BUF , req_ctx->digestsize); + }else { +/* XXX: this fixes some ugly register fuckup bug in the tdma engine +* (no need to sync since the data is ignored anyway) */ +mv_tdma_memcpy (cpg->sa_sram_dma, + cpg->sram_phys +SRAM_CONFIG ,1 ); + }/* GO */ mv_setup_timer ();
@@ -546,9 +556,17 @@ static void mv_update_hash_config(void)mv_tdma_separator (); -/* XXX: this fixes some ugly register fuckup bug in the tdma engine -* (no need to sync since the data is ignored anyway) */ -mv_tdma_memcpy (cpg->sa_sram_dma, cpg->sram_phys +SRAM_CONFIG ,1 ); +if (req->result) { + req_ctx->result_dma =dma_map_single (cpg->dev, req->result, + req_ctx->digestsize,DMA_FROM_DEVICE ); +mv_tdma_memcpy (req_ctx->result_dma, + cpg->sram_phys +SRAM_DIGEST_BUF , req_ctx->digestsize); + }else { +/* XXX: this fixes some ugly register fuckup bug in the tdma engine +* (no need to sync since the data is ignored anyway) */ +mv_tdma_memcpy (cpg->sa_sram_dma, + cpg->sram_phys +SRAM_CONFIG ,1 ); + }/* GO */ mv_setup_timer ();
@@ -615,11 +633,10 @@ static void mv_hash_algo_completion(void)copy_src_to_buf (&cpg->p, ctx->buffer, ctx->extra_bytes);if (likely (ctx->last_chunk)) { -if (likely (ctx->count <=MAX_HW_HASH_SIZE )) { -memcpy (req->result, cpg->sram +SRAM_DIGEST_BUF , -crypto_ahash_digestsize (crypto_ahash_reqtfm - (req))); - }else { +dma_unmap_single (cpg->dev, ctx->result_dma, + ctx->digestsize,DMA_FROM_DEVICE ); + +if (unlikely (ctx->count >MAX_HW_HASH_SIZE )) {mv_save_digest_state (ctx);mv_hash_final_fallback (req); }
@@ -717,6 +734,7 @@ static void mv_start_new_hash_req(struct ahash_request *req)memset (p,0 ,sizeof (struct req_progress )); hw_bytes = req->nbytes + ctx->extra_bytes; old_extra_bytes = ctx->extra_bytes; + ctx->digestsize =crypto_ahash_digestsize (crypto_ahash_reqtfm (req)); ctx->extra_bytes = hw_bytes %SHA1_BLOCK_SIZE ; if (ctx->extra_bytes != 0
Signature · 1 line
1.7.3.4
PATCH 6/13 mv_cesa: use TDMA engine for data transfers
In reply to Phil SutterSimply chose the same DMA mask value as for mvsdio and ehci.
--- arch/arm/plat-orion/common.c | 6 + drivers/crypto/mv_cesa.c | 214 +++++++++++++++++++++++++++++++++--------- 2 files changed, 175 insertions(+), 45 deletions(-)
arch/arm/plat-orion/common.c +6 -0
@@ -916,9 +916,15 @@ static struct resource orion_crypto_resources[] = { }, }; +static u64 mv_crypto_dmamask =DMA_BIT_MASK (32 ); +static struct platform_device orion_crypto = { .name ="mv_crypto" , .id =-1 , + .dev = { + .dma_mask = &mv_crypto_dmamask, + .coherent_dma_mask =DMA_BIT_MASK (32 ), + }, }; void __init orion_crypto_init(unsigned long mapbase,
drivers/crypto/mv_cesa.c +169 -45
396 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 2/13 mv_cesa: minor formatting cleanup, will all make sense soon
In reply to Phil SutterThis is just to keep formatting changes out of the following commit, hopefully simplifying it a bit.
--- drivers/crypto/mv_cesa.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
drivers/crypto/mv_cesa.c +6 -8
@@ -267,12 +267,10 @@ static void mv_process_current_q(int first_block) }if (req_ctx->decrypt) { op.config |=CFG_DIR_DEC ; -memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_dec_key, -AES_KEY_LEN ); +memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_dec_key,AES_KEY_LEN ); }else { op.config |=CFG_DIR_ENC ; -memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_enc_key, -AES_KEY_LEN ); +memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_enc_key,AES_KEY_LEN ); }switch (ctx->key_len) {
@@ -333,9 +331,8 @@ static void mv_process_hash_current(int first_block) } op.mac_src_p = -MAC_SRC_DATA_P (SRAM_DATA_IN_START ) |MAC_SRC_TOTAL_LEN ((u32 ) - req_ctx-> - count); +MAC_SRC_DATA_P (SRAM_DATA_IN_START ) | +MAC_SRC_TOTAL_LEN ((u32 )req_ctx->count);setup_data_in ();
@@ -370,7 +367,8 @@ static void mv_process_hash_current(int first_block) } } -memcpy (cpg->sram +SRAM_CONFIG , &op,sizeof (struct sec_accel_config )); +memcpy (cpg->sram +SRAM_CONFIG , &op, +sizeof (struct sec_accel_config ));/* GO */ mv_setup_timer ();
Signature · 1 line
1.7.3.4
PATCH 5/13 add a driver for the Marvell TDMA engine
In reply to Phil SutterThis is a DMA engine integrated into the Marvell Kirkwood SoC, designed to offload data transfers from/to the CESA crypto engine.
--- arch/arm/mach-kirkwood/common.c | 33 +++ arch/arm/mach-kirkwood/include/mach/irqs.h | 1 + drivers/crypto/Kconfig | 5 + drivers/crypto/Makefile | 3 +- drivers/crypto/mv_tdma.c | 377 ++++++++++++++++++++++++++++ drivers/crypto/mv_tdma.h | 50 ++++ 6 files changed, 468 insertions(+), 1 deletions(-) create mode 100644 drivers/crypto/mv_tdma.c create mode 100644 drivers/crypto/mv_tdma.h
arch/arm/mach-kirkwood/common.c +33 -0
@@ -269,9 +269,42 @@ void __init kirkwood_uart1_init(void)/***************************************************************************** * Cryptographic Engines and Security Accelerator (CESA) ****************************************************************************/ +static struct resource kirkwood_tdma_res[] = { + { + .name ="regs deco" , + .start =CRYPTO_PHYS_BASE +0xA00 , + .end =CRYPTO_PHYS_BASE +0xA24 , + .flags =IORESOURCE_MEM , + }, { + .name ="regs control and error" , + .start =CRYPTO_PHYS_BASE +0x800 , + .end =CRYPTO_PHYS_BASE +0x8CF , + .flags =IORESOURCE_MEM , + }, { + .name ="crypto error" , + .start =IRQ_KIRKWOOD_TDMA_ERR , + .end =IRQ_KIRKWOOD_TDMA_ERR , + .flags =IORESOURCE_IRQ , + }, +}; + +static u64 mv_tdma_dma_mask =0xffffffffUL ; + +static struct platform_device kirkwood_tdma_device = { + .name ="mv_tdma" , + .id =-1 , + .dev = { + .dma_mask = &mv_tdma_dma_mask, + .coherent_dma_mask =0xffffffff , + }, + .num_resources =ARRAY_SIZE (kirkwood_tdma_res), + .resource = kirkwood_tdma_res, +}; +void __init kirkwood_crypto_init (void ) { kirkwood_clk_ctrl |=CGC_CRYPTO ; +platform_device_register (&kirkwood_tdma_device);orion_crypto_init (CRYPTO_PHYS_BASE ,KIRKWOOD_SRAM_PHYS_BASE ,KIRKWOOD_SRAM_SIZE ,IRQ_KIRKWOOD_CRYPTO ); }
arch/arm/mach-kirkwood/include/mach/irqs.h +1 -0
@@ -51,6 +51,7 @@#define IRQ_KIRKWOOD_GPIO_HIGH_16_23 41#define IRQ_KIRKWOOD_GE00_ERR 46#define IRQ_KIRKWOOD_GE01_ERR 47 +#define IRQ_KIRKWOOD_TDMA_ERR 49#define IRQ_KIRKWOOD_RTC 53/*
drivers/crypto/Kconfig +5 -0
@@ -159,6 +159,10 @@ config CRYPTO_GHASH_S390 It is available as of z196. +config CRYPTO_DEV_MV_TDMA + tristate + default no + config CRYPTO_DEV_MV_CESA tristate "Marvell's Cryptographic Engine" depends on PLAT_ORION
@@ -166,6 +170,7 @@ config CRYPTO_DEV_MV_CESA select CRYPTO_AES select CRYPTO_BLKCIPHER2 select CRYPTO_HASH + select CRYPTO_DEV_MV_TDMA help This driver allows you to utilize the Cryptographic Engines and Security Accelerator (CESA) which can be found on the Marvell Orion
drivers/crypto/Makefile +2 -1
@@ -4,6 +4,7 @@ obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o obj-$(CONFIG_CRYPTO_DEV_NIAGARA2) += n2_crypto.o n2_crypto-y := n2_core.o n2_asm.o obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o +obj-$(CONFIG_CRYPTO_DEV_MV_TDMA) += mv_tdma.o obj-$(CONFIG_CRYPTO_DEV_MV_CESA) += mv_cesa.o obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM) += caam/
@@ -14,4 +15,4 @@ obj-$(CONFIG_CRYPTO_DEV_OMAP_AES) += omap-aes.o obj-$(CONFIG_CRYPTO_DEV_PICOXCELL) += picoxcell_crypto.o obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o obj-$(CONFIG_CRYPTO_DEV_TEGRA_AES) += tegra-aes.o -obj-$(CONFIG_CRYPTO_DEV_UX500) += ux500/ +obj-$(CONFIG_CRYPTO_DEV_UX500) += ux500/
drivers/crypto/mv_tdma.c new file +377 -0
377 lines not on this page · raw message
drivers/crypto/mv_tdma.h new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 10/13 mv_cesa: reorganise mv_start_new_hash_req a bit
In reply to Phil SutterCheck and exit early for whether CESA can be used at all.
--- drivers/crypto/mv_cesa.c | 61 +++++++++++++++++++++++++--------------------- 1 files changed, 33 insertions(+), 28 deletions(-)
drivers/crypto/mv_cesa.c +33 -28
@@ -804,35 +804,13 @@ static void mv_start_new_hash_req(struct ahash_request *req)else ctx->extra_bytes =0 ; - p->src_sg = req->src; -if (req->nbytes) { -BUG_ON (!req->src); - p->sg_src_left = req->src->length; - } - -if (hw_bytes) { - p->hw_nbytes = hw_bytes; - p->complete = mv_hash_algo_completion; - p->process = mv_update_hash_config; - -if (unlikely (old_extra_bytes)) { -dma_sync_single_for_device (cpg->dev, ctx->buffer_dma, -SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); -mv_tdma_memcpy (cpg->sram_phys +SRAM_DATA_IN_START , - ctx->buffer_dma, old_extra_bytes); - p->crypt_len = old_extra_bytes; +if (unlikely (!hw_bytes)) {/* too little data for CESA */ +if (req->nbytes) { + p->src_sg = req->src; + p->sg_src_left = req->src->length; +copy_src_to_buf (p, ctx->buffer + old_extra_bytes, + req->nbytes); } - -if (!mv_dma_map_sg (req->src, req->nbytes,DMA_TO_DEVICE )) { -printk (KERN_ERR "%s: out of memory\n" , __func__); -return ; - } - -setup_data_in (); -mv_init_hash_config (req); - }else { -copy_src_to_buf (p, ctx->buffer + old_extra_bytes, - ctx->extra_bytes - old_extra_bytes);if (ctx->last_chunk) rc =mv_hash_final_fallback (req);else
@@ -841,7 +819,34 @@ static void mv_start_new_hash_req(struct ahash_request *req)local_bh_disable (); req->base.complete (&req->base, rc);local_bh_enable (); +return ; } + +if (likely (req->nbytes)) { +BUG_ON (!req->src); + +if (!mv_dma_map_sg (req->src, req->nbytes,DMA_TO_DEVICE )) { +printk (KERN_ERR "%s: out of memory\n" , __func__); +return ; + } + p->sg_src_left =sg_dma_len (req->src); + p->src_sg = req->src; + } + + p->hw_nbytes = hw_bytes; + p->complete = mv_hash_algo_completion; + p->process = mv_update_hash_config; + +if (unlikely (old_extra_bytes)) { +dma_sync_single_for_device (cpg->dev, ctx->buffer_dma, +SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); +mv_tdma_memcpy (cpg->sram_phys +SRAM_DATA_IN_START , + ctx->buffer_dma, old_extra_bytes); + p->crypt_len = old_extra_bytes; + } + +setup_data_in (); +mv_init_hash_config (req); }static int queue_manag (void *data)
Signature · 1 line
1.7.3.4
PATCH 12/13 mv_cesa: drop the now unused process callback
In reply to Phil SutterAnd while here, simplify dequeue_complete_req() a bit.
--- drivers/crypto/mv_cesa.c | 21 ++++++--------------- 1 files changed, 6 insertions(+), 15 deletions(-)
drivers/crypto/mv_cesa.c +6 -15
@@ -69,7 +69,6 @@ struct req_progress {struct scatterlist *src_sg;struct scatterlist *dst_sg;void (*complete) (void ); -void (*process) (void );/* src mostly */ int sg_src_left;
@@ -648,25 +647,17 @@ static void mv_hash_algo_completion(void)static void dequeue_complete_req (void ) {struct crypto_async_request *req = cpg->cur_req; - cpg->p.hw_processed_bytes += cpg->p.crypt_len; - cpg->p.crypt_len =0 ;mv_tdma_clear (); cpg->u32_usage =0 ;BUG_ON (cpg->eng_st !=ENGINE_W_DEQUEUE ); -if (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) { -/* process next scatter list entry */ - cpg->eng_st =ENGINE_BUSY ; -setup_data_in (); - cpg->p.process (); - }else { - cpg->p.complete (); - cpg->eng_st =ENGINE_IDLE ; -local_bh_disable (); - req->complete (req,0 ); -local_bh_enable (); - } + + cpg->p.complete (); + cpg->eng_st =ENGINE_IDLE ; +local_bh_disable (); + req->complete (req,0 ); +local_bh_enable (); }static int count_sgs (struct scatterlist *sl,unsigned int total_bytes)
Signature · 1 line
1.7.3.4
PATCH 3/13 mv_cesa: prepare the full sram config in dram
In reply to Phil SutterThis way reconfiguring the cryptographic accelerator consists of a single step (memcpy here), which in future can be done by the tdma engine.
This patch introduces some ugly IV copying, necessary for input buffers above 1920bytes. But this will go away later.
--- drivers/crypto/mv_cesa.c | 83 ++++++++++++++++++++++++++++----------------- 1 files changed, 52 insertions(+), 31 deletions(-)
drivers/crypto/mv_cesa.c +52 -31
@@ -76,6 +76,24 @@ struct req_progress {int hw_processed_bytes; }; +struct sec_accel_sram { +struct sec_accel_config op; +union { +struct { +u32 key[8 ]; +u32 iv[4 ]; + } crypt; +struct { +u32 ivi[5 ]; +u32 ivo[5 ]; + } hash; + } type; +#define sa_key type.crypt.key +#define sa_iv type.crypt.iv +#define sa_ivi type.hash.ivi +#define sa_ivo type.hash.ivo +} __attribute__((packed)); +struct crypto_priv {void __iomem *reg;void __iomem *sram;
@@ -93,6 +111,8 @@ struct crypto_priv {int sram_size;int has_sha1;int has_hmac_sha1; + +struct sec_accel_sram sa_sram; };static struct crypto_priv *cpg;
@@ -250,48 +270,49 @@ static void mv_process_current_q(int first_block)struct ablkcipher_request *req =ablkcipher_request_cast (cpg->cur_req);struct mv_ctx *ctx =crypto_tfm_ctx (req->base.tfm);struct mv_req_ctx *req_ctx =ablkcipher_request_ctx (req); -struct sec_accel_config op; +struct sec_accel_config *op = &cpg->sa_sram.op;switch (req_ctx->op) {case COP_AES_ECB : - op.config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_ECB ; + op->config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_ECB ;break ;case COP_AES_CBC :default : - op.config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_CBC ; - op.enc_iv =ENC_IV_POINT (SRAM_DATA_IV ) | + op->config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_CBC ; + op->enc_iv =ENC_IV_POINT (SRAM_DATA_IV ) |ENC_IV_BUF_POINT (SRAM_DATA_IV_BUF ); -if (first_block) -memcpy (cpg->sram +SRAM_DATA_IV , req->info,16 ); +if (!first_block) +memcpy (req->info, cpg->sram +SRAM_DATA_IV_BUF ,16 ); +memcpy (cpg->sa_sram.sa_iv, req->info,16 );break ; }if (req_ctx->decrypt) { - op.config |=CFG_DIR_DEC ; -memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_dec_key,AES_KEY_LEN ); + op->config |=CFG_DIR_DEC ; +memcpy (cpg->sa_sram.sa_key, ctx->aes_dec_key,AES_KEY_LEN ); }else { - op.config |=CFG_DIR_ENC ; -memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_enc_key,AES_KEY_LEN ); + op->config |=CFG_DIR_ENC ; +memcpy (cpg->sa_sram.sa_key, ctx->aes_enc_key,AES_KEY_LEN ); }switch (ctx->key_len) {case AES_KEYSIZE_128 : - op.config |=CFG_AES_LEN_128 ; + op->config |=CFG_AES_LEN_128 ;break ;case AES_KEYSIZE_192 : - op.config |=CFG_AES_LEN_192 ; + op->config |=CFG_AES_LEN_192 ;break ;case AES_KEYSIZE_256 : - op.config |=CFG_AES_LEN_256 ; + op->config |=CFG_AES_LEN_256 ;break ; } - op.enc_p =ENC_P_SRC (SRAM_DATA_IN_START ) | + op->enc_p =ENC_P_SRC (SRAM_DATA_IN_START ) |ENC_P_DST (SRAM_DATA_OUT_START ); - op.enc_key_p =SRAM_DATA_KEY_P ; + op->enc_key_p =SRAM_DATA_KEY_P ;setup_data_in (); - op.enc_len = cpg->p.crypt_len; -memcpy (cpg->sram +SRAM_CONFIG , &op, -sizeof (struct sec_accel_config )); + op->enc_len = cpg->p.crypt_len; +memcpy (cpg->sram +SRAM_CONFIG , &cpg->sa_sram, +sizeof (struct sec_accel_sram ));/* GO */ mv_setup_timer ();
@@ -315,30 +336,30 @@ static void mv_process_hash_current(int first_block)const struct mv_tfm_hash_ctx *tfm_ctx =crypto_tfm_ctx (req->base.tfm);struct mv_req_hash_ctx *req_ctx =ahash_request_ctx (req);struct req_progress *p = &cpg->p; -struct sec_accel_config op = {0 }; +struct sec_accel_config *op = &cpg->sa_sram.op;int is_last;switch (req_ctx->op) {case COP_SHA1 :default : - op.config =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ; + op->config =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ;break ;case COP_HMAC_SHA1 : - op.config =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ; -memcpy (cpg->sram +SRAM_HMAC_IV_IN , + op->config =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ; +memcpy (cpg->sa_sram.sa_ivi, tfm_ctx->ivs,sizeof (tfm_ctx->ivs));break ; } - op.mac_src_p = + op->mac_src_p =MAC_SRC_DATA_P (SRAM_DATA_IN_START ) |MAC_SRC_TOTAL_LEN ((u32 )req_ctx->count);setup_data_in (); - op.mac_digest = + op->mac_digest =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); - op.mac_iv = + op->mac_iv =MAC_INNER_IV_P (SRAM_HMAC_IV_IN ) |MAC_OUTER_IV_P (SRAM_HMAC_IV_OUT );
@@ -347,16 +368,16 @@ static void mv_process_hash_current(int first_block) && (req_ctx->count <=MAX_HW_HASH_SIZE );if (req_ctx->first_hash) {if (is_last) - op.config |=CFG_NOT_FRAG ; + op->config |=CFG_NOT_FRAG ;else - op.config |=CFG_FIRST_FRAG ; + op->config |=CFG_FIRST_FRAG ; req_ctx->first_hash =0 ; }else {if (is_last) - op.config |=CFG_LAST_FRAG ; + op->config |=CFG_LAST_FRAG ;else - op.config |=CFG_MID_FRAG ; + op->config |=CFG_MID_FRAG ;if (first_block) {writel (req_ctx->state[0 ], cpg->reg +DIGEST_INITIAL_VAL_A );
@@ -367,8 +388,8 @@ static void mv_process_hash_current(int first_block) } } -memcpy (cpg->sram +SRAM_CONFIG , &op, -sizeof (struct sec_accel_config )); +memcpy (cpg->sram +SRAM_CONFIG , &cpg->sa_sram, +sizeof (struct sec_accel_sram ));/* GO */ mv_setup_timer ();
Signature · 1 line
1.7.3.4
PATCH 9/13 mv_cesa: implementing packet chain mode, only aes for now
In reply to Phil SutterThis introduces a pool of four-byte DMA buffers for security accelerator config updates.
--- drivers/crypto/mv_cesa.c | 134 ++++++++++++++++++++++++++++++++++++---------- drivers/crypto/mv_cesa.h | 1 + 2 files changed, 106 insertions(+), 29 deletions(-)
drivers/crypto/mv_cesa.c +105 -29
@@ -10,6 +10,7 @@#include <crypto/algapi.h> #include <linux/crypto.h> #include <linux/dma-mapping.h> +#include <linux/dmapool.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/kthread.h>
@@ -27,6 +28,9 @@#define MAX_HW_HASH_SIZE 0xFFFF#define MV_CESA_EXPIRE 500/* msec */ +#define MV_DMA_INIT_POOLSIZE 16 +#define MV_DMA_ALIGN 16 +static int count_sgs (struct scatterlist *,unsigned int );/*
@@ -96,6 +100,11 @@ struct sec_accel_sram {#define sa_ivo type.hash.ivo } __attribute__((packed)); +struct u32_mempair { +u32 *vaddr; +dma_addr_t daddr; +}; +struct crypto_priv {struct device *dev;void __iomem *reg;
@@ -118,6 +127,11 @@ struct crypto_priv {struct sec_accel_sram sa_sram;dma_addr_t sa_sram_dma; + +struct dma_pool *u32_pool; +struct u32_mempair *u32_list; +int u32_list_len; +int u32_usage; };static struct crypto_priv *cpg;
@@ -189,6 +203,54 @@ static void mv_setup_timer(void) jiffies + msecs_to_jiffies(MV_CESA_EXPIRE)); } +#define U32_ITEM (x) (cpg->u32_list[x].vaddr) +#define U32_ITEM_DMA (x) (cpg->u32_list[x].daddr) + +static inline int set_u32_poolsize (int nelem) +{ +/* need to increase size first if requested */ +if (nelem > cpg->u32_list_len) { +struct u32_mempair *newmem; +int newsize = nelem *sizeof (struct u32_mempair ); + + newmem =krealloc (cpg->u32_list, newsize,GFP_KERNEL ); +if (!newmem) +return -ENOMEM ; + cpg->u32_list = newmem; + } + +/* allocate/free dma descriptors, adjusting cpg->u32_list_len on the go */ +for (; cpg->u32_list_len < nelem; cpg->u32_list_len++) { +U32_ITEM (cpg->u32_list_len) =dma_pool_alloc (cpg->u32_pool, +GFP_KERNEL , &U32_ITEM_DMA (cpg->u32_list_len)); +if (!U32_ITEM ((cpg->u32_list_len))) +return -ENOMEM ; + } +for (; cpg->u32_list_len > nelem; cpg->u32_list_len--) +dma_pool_free (cpg->u32_pool,U32_ITEM (cpg->u32_list_len -1 ), +U32_ITEM_DMA (cpg->u32_list_len -1 )); + +/* ignore size decreases but those to zero */ +if (!nelem) { +kfree (cpg->u32_list); + cpg->u32_list =0 ; + } +return 0 ; +} + +static inline void mv_tdma_u32_copy (dma_addr_t dst,u32 val) +{ +if (unlikely (cpg->u32_usage == cpg->u32_list_len) + &&set_u32_poolsize (cpg->u32_list_len <<1 )) { + printk(KERN_ERR MV_CESA "resizing poolsize to %d failed\n", + cpg->u32_list_len << 1); +return ; + } + *(U32_ITEM (cpg->u32_usage)) = val; +mv_tdma_memcpy (dst,U32_ITEM_DMA (cpg->u32_usage),sizeof (u32)); + cpg->u32_usage++; +} +static inline bool mv_dma_map_sg (struct scatterlist *sg,int nbytes,enum dma_data_direction dir) {
@@ -390,36 +452,13 @@ static void mv_init_crypt_config(struct ablkcipher_request *req) sizeof(struct sec_accel_sram), DMA_TO_DEVICE);mv_tdma_memcpy (cpg->sram_phys +SRAM_CONFIG , cpg->sa_sram_dma,sizeof (struct sec_accel_sram )); - -mv_tdma_separator (); -dma_copy_buf_to_dst (&cpg->p, cpg->sram_phys +SRAM_DATA_OUT_START , cpg->p.crypt_len); - -/* GO */ -mv_setup_timer (); -mv_tdma_trigger (); -writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); }static void mv_update_crypt_config (void ) { -struct sec_accel_config *op = &cpg->sa_sram.op; -/* update the enc_len field only */ - - op->enc_len = cpg->p.crypt_len; - -dma_sync_single_for_device (cpg->dev, cpg->sa_sram_dma +2 *sizeof (u32), -sizeof (u32),DMA_TO_DEVICE ); -mv_tdma_memcpy (cpg->sram_phys +SRAM_CONFIG +2 *sizeof (u32), - cpg->sa_sram_dma +2 *sizeof (u32),sizeof (u32)); - -mv_tdma_separator (); -dma_copy_buf_to_dst (&cpg->p, cpg->sram_phys +SRAM_DATA_OUT_START , cpg->p.crypt_len); - -/* GO */ -mv_setup_timer (); -mv_tdma_trigger (); -writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); +mv_tdma_u32_copy (cpg->sram_phys +SRAM_CONFIG +2 *sizeof (u32), + (u32 )cpg->p.crypt_len); }static void mv_crypto_algo_completion (void )
@@ -658,6 +697,7 @@ static void dequeue_complete_req(void) cpg->p.crypt_len =0 ;mv_tdma_clear (); + cpg->u32_usage =0 ;BUG_ON (cpg->eng_st !=ENGINE_W_DEQUEUE );if (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) {
@@ -699,7 +739,6 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req)memset (p,0 ,sizeof (struct req_progress )); p->hw_nbytes = req->nbytes; p->complete = mv_crypto_algo_completion; - p->process = mv_update_crypt_config;/* assume inplace request */ if (req->src == req->dst) {
@@ -726,6 +765,24 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req)setup_data_in ();mv_init_crypt_config (req); +mv_tdma_separator (); +dma_copy_buf_to_dst (&cpg->p, cpg->sram_phys +SRAM_DATA_OUT_START , cpg->p.crypt_len); + cpg->p.hw_processed_bytes += cpg->p.crypt_len; +while (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) { + cpg->p.crypt_len =0 ; + +setup_data_in (); +mv_update_crypt_config (); +mv_tdma_separator (); +dma_copy_buf_to_dst (&cpg->p, cpg->sram_phys +SRAM_DATA_OUT_START , cpg->p.crypt_len); + cpg->p.hw_processed_bytes += cpg->p.crypt_len; + } + + +/* GO */ +mv_setup_timer (); +mv_tdma_trigger (); +writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); }static void mv_start_new_hash_req (struct ahash_request *req)
@@ -1285,18 +1342,29 @@ static int mv_probe(struct platform_device *pdev)writel (0 , cpg->reg +SEC_ACCEL_INT_STATUS );writel (SEC_INT_ACC0_IDMA_DONE , cpg->reg +SEC_ACCEL_INT_MASK ); -writel ((SEC_CFG_STOP_DIG_ERR |SEC_CFG_CH0_W_IDMA | +writel ((SEC_CFG_STOP_DIG_ERR |SEC_CFG_CH0_W_IDMA |SEC_CFG_MP_CHAIN |SEC_CFG_ACT_CH0_IDMA ), cpg->reg +SEC_ACCEL_CFG );writel (SRAM_CONFIG , cpg->reg +SEC_ACCEL_DESC_P0 ); cp->sa_sram_dma =dma_map_single (&pdev->dev, &cp->sa_sram,sizeof (struct sec_accel_sram ),DMA_TO_DEVICE ); + cpg->u32_pool =dma_pool_create ("CESA U32 Item Pool" , + &pdev->dev,sizeof (u32),MV_DMA_ALIGN ,0 ); +if (!cpg->u32_pool) { + ret = -ENOMEM ; + goto err_mapping; + } +if (set_u32_poolsize (MV_DMA_INIT_POOLSIZE )) { + printk(KERN_ERR MV_CESA "failed to initialise poolsize\n"); + goto err_pool; + } + ret =crypto_register_alg (&mv_aes_alg_ecb);if (ret) { printk(KERN_WARNING MV_CESA "Could not register aes-ecb driver\n"); - goto err_irq; + goto err_poolsize; } ret =crypto_register_alg (&mv_aes_alg_cbc);
@@ -1323,7 +1391,13 @@ static int mv_probe(struct platform_device *pdev)return 0 ; err_unreg_ecb:crypto_unregister_alg (&mv_aes_alg_ecb); -err_irq: +err_poolsize: +set_u32_poolsize (0 ); +err_pool: +dma_pool_destroy (cpg->u32_pool); +err_mapping: +dma_unmap_single (&pdev->dev, cpg->sa_sram_dma, +sizeof (struct sec_accel_sram ),DMA_TO_DEVICE );free_irq (irq, cp); err_thread:kthread_stop (cp->queue_th);
@@ -1352,6 +1426,8 @@ static int mv_remove(struct platform_device *pdev)free_irq (cp->irq, cp);dma_unmap_single (&pdev->dev, cpg->sa_sram_dma,sizeof (struct sec_accel_sram ),DMA_TO_DEVICE ); +set_u32_poolsize (0 ); +dma_pool_destroy (cpg->u32_pool);memset (cp->sram,0 , cp->sram_size);iounmap (cp->sram);iounmap (cp->reg);
drivers/crypto/mv_cesa.h +1 -0
@@ -24,6 +24,7 @@#define SEC_CFG_CH1_W_IDMA (1 << 8)#define SEC_CFG_ACT_CH0_IDMA (1 << 9)#define SEC_CFG_ACT_CH1_IDMA (1 << 10) +#define SEC_CFG_MP_CHAIN (1 << 11)#define SEC_ACCEL_STATUS 0xde0c#define SEC_ST_ACT_0 (1 << 0)
Signature · 1 line
1.7.3.4
Hi,
The following patch series adds support for the TDMA engine built into Marvell's Kirkwood-based SoCs, and enhances mv_cesa.c in order to use it for speeding up crypto operations. Kirkwood hardware contains a security accelerator, which can control DMA as well as crypto engines. It allows for operation with minimal software intervenience, which the following patches implement: using a chain of DMA descriptors, data input, configuration, engine startup and data output repeat fully automatically until the whole input data has been handled.
The point for this being RFC is backwards-compatibility: earlier hardware (Orion) ships a (slightly) different DMA engine (IDMA) along with the same crypto engine, so in fact mv_cesa.c is in use on these platforms, too. But since I don't possess hardware of this kind, I am not able to make this code IDMA-compatible. Also, due to the quite massive reorganisation of code flow, I don't really see how to make TDMA support optional in mv_cesa.c.
Greetings, Phil
PATCH 1/13 mv_cesa: do not use scatterlist iterators
The big problem is they cannot be used to iterate over DMA mapped scatterlists, so get rid of them in order to add DMA functionality to mv_cesa.
--- drivers/crypto/mv_cesa.c | 57 ++++++++++++++++++++++----------------------- 1 files changed, 28 insertions(+), 29 deletions(-)
drivers/crypto/mv_cesa.c +28 -29
@@ -43,8 +43,8 @@ enum engine_status {/** * struct req_progress - used for every crypt request -* @src_sg_it: sg iterator for src -* @dst_sg_it: sg iterator for dst +* @src_sg: sg list for src +* @dst_sg: sg list for dst * @sg_src_left: bytes left in src to process (scatter list) * @src_start: offset to add to src start position (scatter list) * @crypt_len: length of current hw crypt/hash process
@@ -59,8 +59,8 @@ enum engine_status {* track of progress within current scatterlist. */ struct req_progress { -struct sg_mapping_iter src_sg_it; -struct sg_mapping_iter dst_sg_it; +struct scatterlist *src_sg; +struct scatterlist *dst_sg;void (*complete) (void );void (*process) (int is_first);
@@ -210,19 +210,19 @@ static int mv_setkey_aes(struct crypto_ablkcipher *cipher, const u8 *key,static void copy_src_to_buf (struct req_progress *p,char *dbuf,int len) { -int ret;void *sbuf;int copy_len;while (len) {if (!p->sg_src_left) { - ret =sg_miter_next (&p->src_sg_it); -BUG_ON (!ret); - p->sg_src_left = p->src_sg_it.length; +/* next sg please */ + p->src_sg =sg_next (p->src_sg); +BUG_ON (!p->src_sg); + p->sg_src_left = p->src_sg->length; p->src_start =0 ; } - sbuf = p->src_sg_it.addr + p->src_start; + sbuf =sg_virt (p->src_sg) + p->src_start; copy_len =min (p->sg_src_left, len);memcpy (dbuf, sbuf, copy_len);
@@ -305,9 +305,6 @@ static void mv_crypto_algo_completion(void)struct ablkcipher_request *req =ablkcipher_request_cast (cpg->cur_req);struct mv_req_ctx *req_ctx =ablkcipher_request_ctx (req); -sg_miter_stop (&cpg->p.src_sg_it); -sg_miter_stop (&cpg->p.dst_sg_it); -if (req_ctx->op !=COP_AES_CBC )return ;
@@ -437,7 +434,6 @@ static void mv_hash_algo_completion(void)if (ctx->extra_bytes)copy_src_to_buf (&cpg->p, ctx->buffer, ctx->extra_bytes); -sg_miter_stop (&cpg->p.src_sg_it);if (likely (ctx->last_chunk)) {if (likely (ctx->count <=MAX_HW_HASH_SIZE )) {
@@ -457,7 +453,6 @@ static void dequeue_complete_req(void) {struct crypto_async_request *req = cpg->cur_req;void *buf; -int ret; cpg->p.hw_processed_bytes += cpg->p.crypt_len;if (cpg->p.copy_back) {int need_copy_len = cpg->p.crypt_len;
@@ -466,14 +461,14 @@ static void dequeue_complete_req(void)int dst_copy;if (!cpg->p.sg_dst_left) { - ret =sg_miter_next (&cpg->p.dst_sg_it); -BUG_ON (!ret); - cpg->p.sg_dst_left = cpg->p.dst_sg_it.length; +/* next sg please */ + cpg->p.dst_sg =sg_next (cpg->p.dst_sg); +BUG_ON (!cpg->p.dst_sg); + cpg->p.sg_dst_left = cpg->p.dst_sg->length; cpg->p.dst_start =0 ; } - buf = cpg->p.dst_sg_it.addr; - buf += cpg->p.dst_start; + buf =sg_virt (cpg->p.dst_sg) + cpg->p.dst_start; dst_copy =min (need_copy_len, cpg->p.sg_dst_left);
@@ -523,7 +518,6 @@ static int count_sgs(struct scatterlist *sl, unsigned int total_bytes)static void mv_start_new_crypt_req (struct ablkcipher_request *req) {struct req_progress *p = &cpg->p; -int num_sgs; cpg->cur_req = &req->base;memset (p,0 ,sizeof (struct req_progress ));
@@ -532,11 +526,14 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req) p->process = mv_process_current_q; p->copy_back =1 ; - num_sgs =count_sgs (req->src, req->nbytes); -sg_miter_start (&p->src_sg_it, req->src, num_sgs,SG_MITER_FROM_SG ); - - num_sgs =count_sgs (req->dst, req->nbytes); -sg_miter_start (&p->dst_sg_it, req->dst, num_sgs,SG_MITER_TO_SG ); + p->src_sg = req->src; + p->dst_sg = req->dst; +if (req->nbytes) { +BUG_ON (!req->src); +BUG_ON (!req->dst); + p->sg_src_left = req->src->length; + p->sg_dst_left = req->dst->length; + }mv_process_current_q (1 ); }
@@ -545,7 +542,7 @@ static void mv_start_new_hash_req(struct ahash_request *req) {struct req_progress *p = &cpg->p;struct mv_req_hash_ctx *ctx =ahash_request_ctx (req); -int num_sgs, hw_bytes, old_extra_bytes, rc; +int hw_bytes, old_extra_bytes, rc; cpg->cur_req = &req->base;memset (p,0 ,sizeof (struct req_progress )); hw_bytes = req->nbytes + ctx->extra_bytes;
@@ -558,8 +555,11 @@ static void mv_start_new_hash_req(struct ahash_request *req)else ctx->extra_bytes =0 ; - num_sgs =count_sgs (req->src, req->nbytes); -sg_miter_start (&p->src_sg_it, req->src, num_sgs,SG_MITER_FROM_SG ); + p->src_sg = req->src; +if (req->nbytes) { +BUG_ON (!req->src); + p->sg_src_left = req->src->length; + }if (hw_bytes) { p->hw_nbytes = hw_bytes;
@@ -576,7 +576,6 @@ static void mv_start_new_hash_req(struct ahash_request *req) }else {copy_src_to_buf (p, ctx->buffer + old_extra_bytes, ctx->extra_bytes - old_extra_bytes); -sg_miter_stop (&p->src_sg_it);if (ctx->last_chunk) rc =mv_hash_final_fallback (req);else
Signature · 1 line
1.7.3.4
Quoted 19 lines · Phil Sutter
Hi,
The following patch series adds support for the TDMA engine built into Marvell's Kirkwood-based SoCs, and enhances
mv_cesa.cin order to use it for speeding up crypto operations. Kirkwood hardware contains a security accelerator, which can control DMA as well as crypto engines. It allows for operation with minimal software intervenience, which the following patches implement: using a chain of DMA descriptors, data input, configuration, engine startup and data output repeat fully automatically until the whole input data has been handled.The point for this being RFC is backwards-compatibility: earlier hardware (Orion) ships a (slightly) different DMA engine (IDMA) along with the same crypto engine, so in fact
mv_cesa.cis in use on these platforms, too. But since I don't possess hardware of this kind, I am not able to make this code IDMA-compatible. Also, due to the quite massive reorganisation of code flow, I don't really see how to make TDMA support optional inmv_cesa.c.
Quoted 5 lines
Greetings, Phil
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Could the source code from the manufacturers of hardwares using kirkwood be helpful?
I saw the source code of ls-wvl from buffalo contains driver for CESA. And it deals with both IDMA and TDMA. If you need, I can send you the download link.
I also have to point out that CESA of some orion revisions has hardware flaws that needs to be addressed which currently doesn't. Information about those flaws can be found in 88F5182_Functional_Errata.pdf which is available on the net.
Hi,
Quoted 5 lines · cloudy.linux
Could the source code from the manufacturers of hardwares using kirkwood be helpful?
I saw the source code of ls-wvl from buffalo contains driver for CESA. And it deals with both IDMA and TDMA. If you need, I can send you the download link.
Actually, I do have the sources. Just had doubts about how useful it would be to write code for something I couldn't test at all. OTOH, that's probably a better start than nothing.
Quoted 4 lines
I also have to point out that CESA of some orion revisions has hardware flaws that needs to be addressed which currently doesn't. Information about those flaws can be found in 88F5182_Functional_Errata.pdf which is available on the net.
OK, thanks for the pointer! Looks like implementing combined (crypto/digest) operation for Orion will be no fun at least.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
Herbert Xu
maintainerQuoted 8 lines · Phil Sutter
The point for this being RFC is backwards-compatibility: earlier hardware (Orion) ships a (slightly) different DMA engine (IDMA) along with the same crypto engine, so in fact
mv_cesa.cis in use on these platforms, too. But since I don't possess hardware of this kind, I am not able to make this code IDMA-compatible. Also, due to the quite massive reorganisation of code flow, I don't really see how to make TDMA support optional inmv_cesa.c.
So does this break existing functionality or not?
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 11 lines · Herbert Xu
Quoted 8 lines · Phil Sutter
The point for this being RFC is backwards-compatibility: earlier hardware (Orion) ships a (slightly) different DMA engine (IDMA) along with the same crypto engine, so in fact
mv_cesa.cis in use on these platforms, too. But since I don't possess hardware of this kind, I am not able to make this code IDMA-compatible. Also, due to the quite massive reorganisation of code flow, I don't really see how to make TDMA support optional inmv_cesa.c.So does this break existing functionality or not?
It does break mv_cesa on Orion-based devices (precisely those with IDMA instead of TDMA). I am currently working on a version which supports IDMA, too. Since all CESA-equipped hardware comes with either TDMA or IDMA, that version then should improve all platforms without breaking any.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
Herbert Xu
maintainerQuoted 6 lines · Phil Sutter
It does break
mv_cesaon Orion-based devices (precisely those with IDMA instead of TDMA). I am currently working on a version which supports IDMA, too. Since all CESA-equipped hardware comes with either TDMA or IDMA, that version then should improve all platforms without breaking any.
Thanks for the explanation. I'll wait for your new patches :)
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
PATCH 10/13 mv_cesa: reorganise mv_start_new_hash_req a bit
In reply to Phil SutterCheck and exit early for whether CESA can be used at all.
--- drivers/crypto/mv_cesa.c | 61 +++++++++++++++++++++++++--------------------- 1 files changed, 33 insertions(+), 28 deletions(-)
drivers/crypto/mv_cesa.c +33 -28
@@ -806,35 +806,13 @@ static void mv_start_new_hash_req(struct ahash_request *req)else ctx->extra_bytes =0 ; - p->src_sg = req->src; -if (req->nbytes) { -BUG_ON (!req->src); - p->sg_src_left = req->src->length; - } - -if (hw_bytes) { - p->hw_nbytes = hw_bytes; - p->complete = mv_hash_algo_completion; - p->process = mv_update_hash_config; - -if (unlikely (old_extra_bytes)) { -dma_sync_single_for_device (cpg->dev, ctx->buffer_dma, -SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); -mv_dma_memcpy (cpg->sram_phys +SRAM_DATA_IN_START , - ctx->buffer_dma, old_extra_bytes); - p->crypt_len = old_extra_bytes; +if (unlikely (!hw_bytes)) {/* too little data for CESA */ +if (req->nbytes) { + p->src_sg = req->src; + p->sg_src_left = req->src->length; +copy_src_to_buf (p, ctx->buffer + old_extra_bytes, + req->nbytes); } - -if (!mv_dma_map_sg (req->src, req->nbytes,DMA_TO_DEVICE )) { -printk (KERN_ERR "%s: out of memory\n" , __func__); -return ; - } - -setup_data_in (); -mv_init_hash_config (req); - }else { -copy_src_to_buf (p, ctx->buffer + old_extra_bytes, - ctx->extra_bytes - old_extra_bytes);if (ctx->last_chunk) rc =mv_hash_final_fallback (req);else
@@ -843,7 +821,34 @@ static void mv_start_new_hash_req(struct ahash_request *req)local_bh_disable (); req->base.complete (&req->base, rc);local_bh_enable (); +return ; } + +if (likely (req->nbytes)) { +BUG_ON (!req->src); + +if (!mv_dma_map_sg (req->src, req->nbytes,DMA_TO_DEVICE )) { +printk (KERN_ERR "%s: out of memory\n" , __func__); +return ; + } + p->sg_src_left =sg_dma_len (req->src); + p->src_sg = req->src; + } + + p->hw_nbytes = hw_bytes; + p->complete = mv_hash_algo_completion; + p->process = mv_update_hash_config; + +if (unlikely (old_extra_bytes)) { +dma_sync_single_for_device (cpg->dev, ctx->buffer_dma, +SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); +mv_dma_memcpy (cpg->sram_phys +SRAM_DATA_IN_START , + ctx->buffer_dma, old_extra_bytes); + p->crypt_len = old_extra_bytes; + } + +setup_data_in (); +mv_init_hash_config (req); }static int queue_manag (void *data)
Signature · 1 line
1.7.3.4
PATCH 12/13 mv_cesa: drop the now unused process callback
In reply to Phil SutterAnd while here, simplify dequeue_complete_req() a bit.
--- drivers/crypto/mv_cesa.c | 21 ++++++--------------- 1 files changed, 6 insertions(+), 15 deletions(-)
drivers/crypto/mv_cesa.c +6 -15
@@ -70,7 +70,6 @@ struct req_progress {struct scatterlist *src_sg;struct scatterlist *dst_sg;void (*complete) (void ); -void (*process) (void );/* src mostly */ int sg_src_left;
@@ -650,25 +649,17 @@ static void mv_hash_algo_completion(void)static void dequeue_complete_req (void ) {struct crypto_async_request *req = cpg->cur_req; - cpg->p.hw_processed_bytes += cpg->p.crypt_len; - cpg->p.crypt_len =0 ;mv_dma_clear (); cpg->u32_usage =0 ;BUG_ON (cpg->eng_st !=ENGINE_W_DEQUEUE ); -if (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) { -/* process next scatter list entry */ - cpg->eng_st =ENGINE_BUSY ; -setup_data_in (); - cpg->p.process (); - }else { - cpg->p.complete (); - cpg->eng_st =ENGINE_IDLE ; -local_bh_disable (); - req->complete (req,0 ); -local_bh_enable (); - } + + cpg->p.complete (); + cpg->eng_st =ENGINE_IDLE ; +local_bh_disable (); + req->complete (req,0 ); +local_bh_enable (); }static int count_sgs (struct scatterlist *sl,unsigned int total_bytes)
Signature · 1 line
1.7.3.4
PATCH 9/13 mv_cesa: implementing packet chain mode, only aes for now
In reply to Phil SutterThis introduces a pool of four-byte DMA buffers for security accelerator config updates.
--- drivers/crypto/mv_cesa.c | 134 ++++++++++++++++++++++++++++++++++++---------- drivers/crypto/mv_cesa.h | 1 + 2 files changed, 106 insertions(+), 29 deletions(-)
drivers/crypto/mv_cesa.c +105 -29
@@ -10,6 +10,7 @@#include <crypto/algapi.h> #include <linux/crypto.h> #include <linux/dma-mapping.h> +#include <linux/dmapool.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/kthread.h>
@@ -28,6 +29,9 @@#define MAX_HW_HASH_SIZE 0xFFFF#define MV_CESA_EXPIRE 500/* msec */ +#define MV_DMA_INIT_POOLSIZE 16 +#define MV_DMA_ALIGN 16 +static int count_sgs (struct scatterlist *,unsigned int );/*
@@ -97,6 +101,11 @@ struct sec_accel_sram {#define sa_ivo type.hash.ivo } __attribute__((packed)); +struct u32_mempair { +u32 *vaddr; +dma_addr_t daddr; +}; +struct crypto_priv {struct device *dev;void __iomem *reg;
@@ -120,6 +129,11 @@ struct crypto_priv {struct sec_accel_sram sa_sram;dma_addr_t sa_sram_dma; + +struct dma_pool *u32_pool; +struct u32_mempair *u32_list; +int u32_list_len; +int u32_usage; };static struct crypto_priv *cpg;
@@ -191,6 +205,54 @@ static void mv_setup_timer(void) jiffies + msecs_to_jiffies(MV_CESA_EXPIRE)); } +#define U32_ITEM (x) (cpg->u32_list[x].vaddr) +#define U32_ITEM_DMA (x) (cpg->u32_list[x].daddr) + +static inline int set_u32_poolsize (int nelem) +{ +/* need to increase size first if requested */ +if (nelem > cpg->u32_list_len) { +struct u32_mempair *newmem; +int newsize = nelem *sizeof (struct u32_mempair ); + + newmem =krealloc (cpg->u32_list, newsize,GFP_KERNEL ); +if (!newmem) +return -ENOMEM ; + cpg->u32_list = newmem; + } + +/* allocate/free dma descriptors, adjusting cpg->u32_list_len on the go */ +for (; cpg->u32_list_len < nelem; cpg->u32_list_len++) { +U32_ITEM (cpg->u32_list_len) =dma_pool_alloc (cpg->u32_pool, +GFP_KERNEL , &U32_ITEM_DMA (cpg->u32_list_len)); +if (!U32_ITEM ((cpg->u32_list_len))) +return -ENOMEM ; + } +for (; cpg->u32_list_len > nelem; cpg->u32_list_len--) +dma_pool_free (cpg->u32_pool,U32_ITEM (cpg->u32_list_len -1 ), +U32_ITEM_DMA (cpg->u32_list_len -1 )); + +/* ignore size decreases but those to zero */ +if (!nelem) { +kfree (cpg->u32_list); + cpg->u32_list =0 ; + } +return 0 ; +} + +static inline void mv_dma_u32_copy (dma_addr_t dst,u32 val) +{ +if (unlikely (cpg->u32_usage == cpg->u32_list_len) + &&set_u32_poolsize (cpg->u32_list_len <<1 )) { + printk(KERN_ERR MV_CESA "resizing poolsize to %d failed\n", + cpg->u32_list_len << 1); +return ; + } + *(U32_ITEM (cpg->u32_usage)) = val; +mv_dma_memcpy (dst,U32_ITEM_DMA (cpg->u32_usage),sizeof (u32)); + cpg->u32_usage++; +} +static inline bool mv_dma_map_sg (struct scatterlist *sg,int nbytes,enum dma_data_direction dir) {
@@ -392,36 +454,13 @@ static void mv_init_crypt_config(struct ablkcipher_request *req) sizeof(struct sec_accel_sram), DMA_TO_DEVICE);mv_dma_memcpy (cpg->sram_phys +SRAM_CONFIG , cpg->sa_sram_dma,sizeof (struct sec_accel_sram )); - -mv_dma_separator (); -dma_copy_buf_to_dst (&cpg->p, cpg->sram_phys +SRAM_DATA_OUT_START , cpg->p.crypt_len); - -/* GO */ -mv_setup_timer (); -mv_dma_trigger (); -writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); }static void mv_update_crypt_config (void ) { -struct sec_accel_config *op = &cpg->sa_sram.op; -/* update the enc_len field only */ - - op->enc_len = cpg->p.crypt_len; - -dma_sync_single_for_device (cpg->dev, cpg->sa_sram_dma +2 *sizeof (u32), -sizeof (u32),DMA_TO_DEVICE ); -mv_dma_memcpy (cpg->sram_phys +SRAM_CONFIG +2 *sizeof (u32), - cpg->sa_sram_dma +2 *sizeof (u32),sizeof (u32)); - -mv_dma_separator (); -dma_copy_buf_to_dst (&cpg->p, cpg->sram_phys +SRAM_DATA_OUT_START , cpg->p.crypt_len); - -/* GO */ -mv_setup_timer (); -mv_dma_trigger (); -writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); +mv_dma_u32_copy (cpg->sram_phys +SRAM_CONFIG +2 *sizeof (u32), + (u32 )cpg->p.crypt_len); }static void mv_crypto_algo_completion (void )
@@ -660,6 +699,7 @@ static void dequeue_complete_req(void) cpg->p.crypt_len =0 ;mv_dma_clear (); + cpg->u32_usage =0 ;BUG_ON (cpg->eng_st !=ENGINE_W_DEQUEUE );if (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) {
@@ -701,7 +741,6 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req)memset (p,0 ,sizeof (struct req_progress )); p->hw_nbytes = req->nbytes; p->complete = mv_crypto_algo_completion; - p->process = mv_update_crypt_config;/* assume inplace request */ if (req->src == req->dst) {
@@ -728,6 +767,24 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req)setup_data_in ();mv_init_crypt_config (req); +mv_dma_separator (); +dma_copy_buf_to_dst (&cpg->p, cpg->sram_phys +SRAM_DATA_OUT_START , cpg->p.crypt_len); + cpg->p.hw_processed_bytes += cpg->p.crypt_len; +while (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) { + cpg->p.crypt_len =0 ; + +setup_data_in (); +mv_update_crypt_config (); +mv_dma_separator (); +dma_copy_buf_to_dst (&cpg->p, cpg->sram_phys +SRAM_DATA_OUT_START , cpg->p.crypt_len); + cpg->p.hw_processed_bytes += cpg->p.crypt_len; + } + + +/* GO */ +mv_setup_timer (); +mv_dma_trigger (); +writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); }static void mv_start_new_hash_req (struct ahash_request *req)
@@ -1294,18 +1351,29 @@ static int mv_probe(struct platform_device *pdev)writel (0 , cpg->reg +SEC_ACCEL_INT_STATUS );writel (SEC_INT_ACC0_IDMA_DONE , cpg->reg +SEC_ACCEL_INT_MASK ); -writel ((SEC_CFG_STOP_DIG_ERR |SEC_CFG_CH0_W_IDMA | +writel ((SEC_CFG_STOP_DIG_ERR |SEC_CFG_CH0_W_IDMA |SEC_CFG_MP_CHAIN |SEC_CFG_ACT_CH0_IDMA ), cpg->reg +SEC_ACCEL_CFG );writel (SRAM_CONFIG , cpg->reg +SEC_ACCEL_DESC_P0 ); cp->sa_sram_dma =dma_map_single (&pdev->dev, &cp->sa_sram,sizeof (struct sec_accel_sram ),DMA_TO_DEVICE ); + cpg->u32_pool =dma_pool_create ("CESA U32 Item Pool" , + &pdev->dev,sizeof (u32),MV_DMA_ALIGN ,0 ); +if (!cpg->u32_pool) { + ret = -ENOMEM ; + goto err_mapping; + } +if (set_u32_poolsize (MV_DMA_INIT_POOLSIZE )) { + printk(KERN_ERR MV_CESA "failed to initialise poolsize\n"); + goto err_pool; + } + ret =crypto_register_alg (&mv_aes_alg_ecb);if (ret) { printk(KERN_WARNING MV_CESA "Could not register aes-ecb driver\n"); - goto err_irq; + goto err_poolsize; } ret =crypto_register_alg (&mv_aes_alg_cbc);
@@ -1332,7 +1400,13 @@ static int mv_probe(struct platform_device *pdev)return 0 ; err_unreg_ecb:crypto_unregister_alg (&mv_aes_alg_ecb); -err_irq: +err_poolsize: +set_u32_poolsize (0 ); +err_pool: +dma_pool_destroy (cpg->u32_pool); +err_mapping: +dma_unmap_single (&pdev->dev, cpg->sa_sram_dma, +sizeof (struct sec_accel_sram ),DMA_TO_DEVICE );free_irq (irq, cp); err_thread:kthread_stop (cp->queue_th);
@@ -1361,6 +1435,8 @@ static int mv_remove(struct platform_device *pdev)free_irq (cp->irq, cp);dma_unmap_single (&pdev->dev, cpg->sa_sram_dma,sizeof (struct sec_accel_sram ),DMA_TO_DEVICE ); +set_u32_poolsize (0 ); +dma_pool_destroy (cpg->u32_pool);memset (cp->sram,0 , cp->sram_size);iounmap (cp->sram);iounmap (cp->reg);
drivers/crypto/mv_cesa.h +1 -0
@@ -24,6 +24,7 @@#define SEC_CFG_CH1_W_IDMA (1 << 8)#define SEC_CFG_ACT_CH0_IDMA (1 << 9)#define SEC_CFG_ACT_CH1_IDMA (1 << 10) +#define SEC_CFG_MP_CHAIN (1 << 11)#define SEC_ACCEL_STATUS 0xde0c#define SEC_ST_ACT_0 (1 << 0)
Signature · 1 line
1.7.3.4
PATCH 7/13 mv_cesa: have DMA engine copy back the digest result
In reply to Phil Sutter--- drivers/crypto/mv_cesa.c | 40 +++++++++++++++++++++++++++++----------- 1 files changed, 29 insertions(+), 11 deletions(-)
drivers/crypto/mv_cesa.c +29 -11
@@ -161,8 +161,10 @@ struct mv_req_hash_ctx {int first_hash;/* marks that we don't have previous state */ int last_chunk;/* marks that this is the 'final' request */ int extra_bytes;/* unprocessed bytes in buffer */ +int digestsize;/* size of the digest */ enum hash_op op;int count_add; +dma_addr_t result_dma; };static void mv_completion_timer_callback (unsigned long unused)
@@ -499,9 +501,17 @@ static void mv_init_hash_config(struct ahash_request *req)mv_dma_separator (); -/* XXX: this fixes some ugly register fuckup bug in the tdma engine -* (no need to sync since the data is ignored anyway) */ -mv_dma_memcpy (cpg->sa_sram_dma, cpg->sram_phys +SRAM_CONFIG ,1 ); +if (req->result) { + req_ctx->result_dma =dma_map_single (cpg->dev, req->result, + req_ctx->digestsize,DMA_FROM_DEVICE ); +mv_dma_memcpy (req_ctx->result_dma, + cpg->sram_phys +SRAM_DIGEST_BUF , req_ctx->digestsize); + }else { +/* XXX: this fixes some ugly register fuckup bug in the tdma engine +* (no need to sync since the data is ignored anyway) */ +mv_dma_memcpy (cpg->sa_sram_dma, + cpg->sram_phys +SRAM_CONFIG ,1 ); + }/* GO */ mv_setup_timer ();
@@ -548,9 +558,17 @@ static void mv_update_hash_config(void)mv_dma_separator (); -/* XXX: this fixes some ugly register fuckup bug in the tdma engine -* (no need to sync since the data is ignored anyway) */ -mv_dma_memcpy (cpg->sa_sram_dma, cpg->sram_phys +SRAM_CONFIG ,1 ); +if (req->result) { + req_ctx->result_dma =dma_map_single (cpg->dev, req->result, + req_ctx->digestsize,DMA_FROM_DEVICE ); +mv_dma_memcpy (req_ctx->result_dma, + cpg->sram_phys +SRAM_DIGEST_BUF , req_ctx->digestsize); + }else { +/* XXX: this fixes some ugly register fuckup bug in the tdma engine +* (no need to sync since the data is ignored anyway) */ +mv_dma_memcpy (cpg->sa_sram_dma, + cpg->sram_phys +SRAM_CONFIG ,1 ); + }/* GO */ mv_setup_timer ();
@@ -617,11 +635,10 @@ static void mv_hash_algo_completion(void)copy_src_to_buf (&cpg->p, ctx->buffer, ctx->extra_bytes);if (likely (ctx->last_chunk)) { -if (likely (ctx->count <=MAX_HW_HASH_SIZE )) { -memcpy (req->result, cpg->sram +SRAM_DIGEST_BUF , -crypto_ahash_digestsize (crypto_ahash_reqtfm - (req))); - }else { +dma_unmap_single (cpg->dev, ctx->result_dma, + ctx->digestsize,DMA_FROM_DEVICE ); + +if (unlikely (ctx->count >MAX_HW_HASH_SIZE )) {mv_save_digest_state (ctx);mv_hash_final_fallback (req); }
@@ -719,6 +736,7 @@ static void mv_start_new_hash_req(struct ahash_request *req)memset (p,0 ,sizeof (struct req_progress )); hw_bytes = req->nbytes + ctx->extra_bytes; old_extra_bytes = ctx->extra_bytes; + ctx->digestsize =crypto_ahash_digestsize (crypto_ahash_reqtfm (req)); ctx->extra_bytes = hw_bytes %SHA1_BLOCK_SIZE ; if (ctx->extra_bytes != 0
Signature · 1 line
1.7.3.4
PATCH 13/13 mv_cesa, mv_dma: outsource common dma-pool handling code
In reply to Phil Sutter--- drivers/crypto/dma_desclist.h | 79 +++++++++++++++++++++++++++++++++++ drivers/crypto/mv_cesa.c | 81 +++++++++---------------------------- drivers/crypto/mv_dma.c | 91 ++++++++++++----------------------------- 3 files changed, 125 insertions(+), 126 deletions(-) create mode 100644 drivers/crypto/dma_desclist.h
drivers/crypto/dma_desclist.h new file +79 -0
@@ -0,0 +1,79 @@ +#ifndef __DMA_DESCLIST__ +#define __DMA_DESCLIST__ + +struct dma_desc { +void *virt; +dma_addr_t phys; +}; + +struct dma_desclist { +struct dma_pool *itempool; +struct dma_desc *desclist; +unsigned long length; +unsigned long usage; +}; + +#define DESCLIST_ITEM (dl, x) ((dl).desclist[(x)].virt) +#define DESCLIST_ITEM_DMA (dl, x) ((dl).desclist[(x)].phys) +#define DESCLIST_FULL (dl) ((dl).length == (dl).usage) + +static inline int +init_dma_desclist (struct dma_desclist *dl,struct device *dev, +size_t size,size_t align,size_t boundary) +{ +#define STRX (x) #x +#define STR (x) STRX(x) + dl->itempool =dma_pool_create ( + "DMA Desclist Pool at "__FILE__"("STR(__LINE__)")", + dev, size, align, boundary); +#undef STR +#undef STRX +if (!dl->itempool) +return 1 ; + dl->desclist =NULL ; + dl->length = dl->usage =0 ; +return 0 ; +} + +static inline int +set_dma_desclist_size (struct dma_desclist *dl,unsigned long nelem) +{ +/* need to increase size first if requested */ +if (nelem > dl->length) { +struct dma_desc *newmem; +int newsize = nelem *sizeof (struct dma_desc ); + + newmem =krealloc (dl->desclist, newsize,GFP_KERNEL ); +if (!newmem) +return -ENOMEM ; + dl->desclist = newmem; + } + +/* allocate/free dma descriptors, adjusting dl->length on the go */ +for (; dl->length < nelem; dl->length++) { +DESCLIST_ITEM (*dl, dl->length) =dma_pool_alloc (dl->itempool, +GFP_KERNEL , &DESCLIST_ITEM_DMA (*dl, dl->length)); +if (!DESCLIST_ITEM (*dl, dl->length)) +return -ENOMEM ; + } +for (; dl->length > nelem; dl->length--) +dma_pool_free (dl->itempool,DESCLIST_ITEM (*dl, dl->length -1 ), +DESCLIST_ITEM_DMA (*dl, dl->length -1 )); + +/* ignore size decreases but those to zero */ +if (!nelem) { +kfree (dl->desclist); + dl->desclist =0 ; + } +return 0 ; +} + +static inline void +fini_dma_desclist (struct dma_desclist *dl) +{ +set_dma_desclist_size (dl,0 ); +dma_pool_destroy (dl->itempool); + dl->length = dl->usage =0 ; +} + +#endif /* __DMA_DESCLIST__ */
drivers/crypto/mv_cesa.c +19 -62
147 lines not on this page · raw message
drivers/crypto/mv_dma.c +27 -64
168 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 4/13 mv_cesa: split up processing callbacks
In reply to Phil SutterHave a dedicated function initialising the full SRAM config, then use a minimal callback for changing only relevant parts of it.
--- drivers/crypto/mv_cesa.c | 87 +++++++++++++++++++++++++++++++++------------ 1 files changed, 64 insertions(+), 23 deletions(-)
drivers/crypto/mv_cesa.c +64 -23
@@ -63,7 +63,7 @@ struct req_progress {struct scatterlist *src_sg;struct scatterlist *dst_sg;void (*complete) (void ); -void (*process) (int is_first); +void (*process) (void );/* src mostly */ int sg_src_left;
@@ -267,9 +267,8 @@ static void setup_data_in(void) p->crypt_len = data_in_sram; } -static void mv_process_current_q (int first_block) +static void mv_init_crypt_config (struct ablkcipher_request *req) { -struct ablkcipher_request *req =ablkcipher_request_cast (cpg->cur_req);struct mv_ctx *ctx =crypto_tfm_ctx (req->base.tfm);struct mv_req_ctx *req_ctx =ablkcipher_request_ctx (req);struct sec_accel_config *op = &cpg->sa_sram.op;
@@ -283,8 +282,6 @@ static void mv_process_current_q(int first_block) op->config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_CBC ; op->enc_iv =ENC_IV_POINT (SRAM_DATA_IV ) |ENC_IV_BUF_POINT (SRAM_DATA_IV_BUF ); -if (!first_block) -memcpy (req->info, cpg->sram +SRAM_DATA_IV_BUF ,16 );memcpy (cpg->sa_sram.sa_iv, req->info,16 );break ; }
@@ -310,9 +307,8 @@ static void mv_process_current_q(int first_block) op->enc_p =ENC_P_SRC (SRAM_DATA_IN_START ) |ENC_P_DST (SRAM_DATA_OUT_START ); op->enc_key_p =SRAM_DATA_KEY_P ; - -setup_data_in (); op->enc_len = cpg->p.crypt_len; +memcpy (cpg->sram +SRAM_CONFIG , &cpg->sa_sram,sizeof (struct sec_accel_sram ));
@@ -321,6 +317,17 @@ static void mv_process_current_q(int first_block)writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); } +static void mv_update_crypt_config (void ) +{ +/* update the enc_len field only */ +memcpy (cpg->sram +SRAM_CONFIG +2 *sizeof (u32), + &cpg->p.crypt_len,sizeof (u32)); + +/* GO */ +mv_setup_timer (); +writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); +} +static void mv_crypto_algo_completion (void ) {struct ablkcipher_request *req =ablkcipher_request_cast (cpg->cur_req);
@@ -332,9 +339,8 @@ static void mv_crypto_algo_completion(void)memcpy (req->info, cpg->sram +SRAM_DATA_IV_BUF ,16 ); } -static void mv_process_hash_current (int first_block) +static void mv_init_hash_config (struct ahash_request *req) { -struct ahash_request *req =ahash_request_cast (cpg->cur_req);const struct mv_tfm_hash_ctx *tfm_ctx =crypto_tfm_ctx (req->base.tfm);struct mv_req_hash_ctx *req_ctx =ahash_request_ctx (req);struct req_progress *p = &cpg->p;
@@ -357,8 +363,6 @@ static void mv_process_hash_current(int first_block)MAC_SRC_DATA_P (SRAM_DATA_IN_START ) |MAC_SRC_TOTAL_LEN ((u32 )req_ctx->count); -setup_data_in (); - op->mac_digest =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); op->mac_iv =
@@ -381,13 +385,11 @@ static void mv_process_hash_current(int first_block)else op->config |=CFG_MID_FRAG ; -if (first_block) { -writel (req_ctx->state[0 ], cpg->reg +DIGEST_INITIAL_VAL_A ); -writel (req_ctx->state[1 ], cpg->reg +DIGEST_INITIAL_VAL_B ); -writel (req_ctx->state[2 ], cpg->reg +DIGEST_INITIAL_VAL_C ); -writel (req_ctx->state[3 ], cpg->reg +DIGEST_INITIAL_VAL_D ); -writel (req_ctx->state[4 ], cpg->reg +DIGEST_INITIAL_VAL_E ); - } +writel (req_ctx->state[0 ], cpg->reg +DIGEST_INITIAL_VAL_A ); +writel (req_ctx->state[1 ], cpg->reg +DIGEST_INITIAL_VAL_B ); +writel (req_ctx->state[2 ], cpg->reg +DIGEST_INITIAL_VAL_C ); +writel (req_ctx->state[3 ], cpg->reg +DIGEST_INITIAL_VAL_D ); +writel (req_ctx->state[4 ], cpg->reg +DIGEST_INITIAL_VAL_E ); } memcpy(cpg->sram + SRAM_CONFIG, &cpg->sa_sram,
@@ -398,6 +400,42 @@ static void mv_process_hash_current(int first_block)writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); } +static void mv_update_hash_config (void ) +{ +struct ahash_request *req =ahash_request_cast (cpg->cur_req); +struct mv_req_hash_ctx *req_ctx =ahash_request_ctx (req); +struct req_progress *p = &cpg->p; +struct sec_accel_config *op = &cpg->sa_sram.op; +int is_last; + +/* update only the config (for changed fragment state) and +* mac_digest (for changed frag len) fields */ + +switch (req_ctx->op) { +case COP_SHA1 : +default : + op->config =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ; +break ; +case COP_HMAC_SHA1 : + op->config =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ; +break ; + } + + is_last = req_ctx->last_chunk + && (p->hw_processed_bytes + p->crypt_len >= p->hw_nbytes) + && (req_ctx->count <=MAX_HW_HASH_SIZE ); + + op->config |= is_last ?CFG_LAST_FRAG :CFG_MID_FRAG ; +memcpy (cpg->sram +SRAM_CONFIG , &op->config,sizeof (u32)); + + op->mac_digest =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); +memcpy (cpg->sram +SRAM_CONFIG +6 *sizeof (u32), &op->mac_digest,sizeof (u32)); + +/* GO */ +mv_setup_timer (); +writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); +} +static inline int mv_hash_import_sha1_ctx (const struct mv_req_hash_ctx *ctx,struct shash_desc *desc) {
@@ -509,7 +547,8 @@ static void dequeue_complete_req(void)if (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) {/* process next scatter list entry */ cpg->eng_st =ENGINE_BUSY ; - cpg->p.process (0 ); +setup_data_in (); + cpg->p.process (); }else { cpg->p.complete (); cpg->eng_st =ENGINE_IDLE ;
@@ -544,7 +583,7 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req)memset (p,0 ,sizeof (struct req_progress )); p->hw_nbytes = req->nbytes; p->complete = mv_crypto_algo_completion; - p->process = mv_process_current_q; + p->process = mv_update_crypt_config; p->copy_back =1 ; p->src_sg = req->src;
@@ -556,7 +595,8 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req) p->sg_dst_left = req->dst->length; } -mv_process_current_q (1 ); +setup_data_in (); +mv_init_crypt_config (req); }static void mv_start_new_hash_req (struct ahash_request *req)
@@ -585,7 +625,7 @@ static void mv_start_new_hash_req(struct ahash_request *req)if (hw_bytes) { p->hw_nbytes = hw_bytes; p->complete = mv_hash_algo_completion; - p->process = mv_process_hash_current; + p->process = mv_update_hash_config;if (unlikely (old_extra_bytes)) { memcpy(cpg->sram + SRAM_DATA_IN_START, ctx->buffer,
@@ -593,7 +633,8 @@ static void mv_start_new_hash_req(struct ahash_request *req) p->crypt_len = old_extra_bytes; } -mv_process_hash_current (1 ); +setup_data_in (); +mv_init_hash_config (req); }else {copy_src_to_buf (p, ctx->buffer + old_extra_bytes, ctx->extra_bytes - old_extra_bytes);
Signature · 1 line
1.7.3.4
PATCH 6/13 mv_cesa: use DMA engine for data transfers
In reply to Phil Sutter--- arch/arm/plat-orion/common.c | 6 + drivers/crypto/mv_cesa.c | 214 +++++++++++++++++++++++++++++++++--------- 2 files changed, 175 insertions(+), 45 deletions(-)
arch/arm/plat-orion/common.c +6 -0
@@ -924,9 +924,15 @@ static struct resource orion_crypto_resources[] = { }, }; +static u64 mv_crypto_dmamask =DMA_BIT_MASK (32 ); +static struct platform_device orion_crypto = { .name ="mv_crypto" , .id =-1 , + .dev = { + .dma_mask = &mv_crypto_dmamask, + .coherent_dma_mask =DMA_BIT_MASK (32 ), + }, }; void __init orion_crypto_init(unsigned long mapbase,
drivers/crypto/mv_cesa.c +169 -45
396 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 3/13 mv_cesa: prepare the full sram config in dram
In reply to Phil SutterThis way reconfiguring the cryptographic accelerator consists of a single step (memcpy here), which in future can be done by the tdma engine.
This patch introduces some ugly IV copying, necessary for input buffers above 1920bytes. But this will go away later.
--- drivers/crypto/mv_cesa.c | 83 ++++++++++++++++++++++++++++----------------- 1 files changed, 52 insertions(+), 31 deletions(-)
drivers/crypto/mv_cesa.c +52 -31
@@ -77,6 +77,24 @@ struct req_progress {int hw_processed_bytes; }; +struct sec_accel_sram { +struct sec_accel_config op; +union { +struct { +u32 key[8 ]; +u32 iv[4 ]; + } crypt; +struct { +u32 ivi[5 ]; +u32 ivo[5 ]; + } hash; + } type; +#define sa_key type.crypt.key +#define sa_iv type.crypt.iv +#define sa_ivi type.hash.ivi +#define sa_ivo type.hash.ivo +} __attribute__((packed)); +struct crypto_priv {void __iomem *reg;void __iomem *sram;
@@ -95,6 +113,8 @@ struct crypto_priv {int sram_size;int has_sha1;int has_hmac_sha1; + +struct sec_accel_sram sa_sram; };static struct crypto_priv *cpg;
@@ -252,48 +272,49 @@ static void mv_process_current_q(int first_block)struct ablkcipher_request *req =ablkcipher_request_cast (cpg->cur_req);struct mv_ctx *ctx =crypto_tfm_ctx (req->base.tfm);struct mv_req_ctx *req_ctx =ablkcipher_request_ctx (req); -struct sec_accel_config op; +struct sec_accel_config *op = &cpg->sa_sram.op;switch (req_ctx->op) {case COP_AES_ECB : - op.config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_ECB ; + op->config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_ECB ;break ;case COP_AES_CBC :default : - op.config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_CBC ; - op.enc_iv =ENC_IV_POINT (SRAM_DATA_IV ) | + op->config =CFG_OP_CRYPT_ONLY |CFG_ENCM_AES |CFG_ENC_MODE_CBC ; + op->enc_iv =ENC_IV_POINT (SRAM_DATA_IV ) |ENC_IV_BUF_POINT (SRAM_DATA_IV_BUF ); -if (first_block) -memcpy (cpg->sram +SRAM_DATA_IV , req->info,16 ); +if (!first_block) +memcpy (req->info, cpg->sram +SRAM_DATA_IV_BUF ,16 ); +memcpy (cpg->sa_sram.sa_iv, req->info,16 );break ; }if (req_ctx->decrypt) { - op.config |=CFG_DIR_DEC ; -memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_dec_key,AES_KEY_LEN ); + op->config |=CFG_DIR_DEC ; +memcpy (cpg->sa_sram.sa_key, ctx->aes_dec_key,AES_KEY_LEN ); }else { - op.config |=CFG_DIR_ENC ; -memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_enc_key,AES_KEY_LEN ); + op->config |=CFG_DIR_ENC ; +memcpy (cpg->sa_sram.sa_key, ctx->aes_enc_key,AES_KEY_LEN ); }switch (ctx->key_len) {case AES_KEYSIZE_128 : - op.config |=CFG_AES_LEN_128 ; + op->config |=CFG_AES_LEN_128 ;break ;case AES_KEYSIZE_192 : - op.config |=CFG_AES_LEN_192 ; + op->config |=CFG_AES_LEN_192 ;break ;case AES_KEYSIZE_256 : - op.config |=CFG_AES_LEN_256 ; + op->config |=CFG_AES_LEN_256 ;break ; } - op.enc_p =ENC_P_SRC (SRAM_DATA_IN_START ) | + op->enc_p =ENC_P_SRC (SRAM_DATA_IN_START ) |ENC_P_DST (SRAM_DATA_OUT_START ); - op.enc_key_p =SRAM_DATA_KEY_P ; + op->enc_key_p =SRAM_DATA_KEY_P ;setup_data_in (); - op.enc_len = cpg->p.crypt_len; -memcpy (cpg->sram +SRAM_CONFIG , &op, -sizeof (struct sec_accel_config )); + op->enc_len = cpg->p.crypt_len; +memcpy (cpg->sram +SRAM_CONFIG , &cpg->sa_sram, +sizeof (struct sec_accel_sram ));/* GO */ mv_setup_timer ();
@@ -317,30 +338,30 @@ static void mv_process_hash_current(int first_block)const struct mv_tfm_hash_ctx *tfm_ctx =crypto_tfm_ctx (req->base.tfm);struct mv_req_hash_ctx *req_ctx =ahash_request_ctx (req);struct req_progress *p = &cpg->p; -struct sec_accel_config op = {0 }; +struct sec_accel_config *op = &cpg->sa_sram.op;int is_last;switch (req_ctx->op) {case COP_SHA1 :default : - op.config =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ; + op->config =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ;break ;case COP_HMAC_SHA1 : - op.config =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ; -memcpy (cpg->sram +SRAM_HMAC_IV_IN , + op->config =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ; +memcpy (cpg->sa_sram.sa_ivi, tfm_ctx->ivs,sizeof (tfm_ctx->ivs));break ; } - op.mac_src_p = + op->mac_src_p =MAC_SRC_DATA_P (SRAM_DATA_IN_START ) |MAC_SRC_TOTAL_LEN ((u32 )req_ctx->count);setup_data_in (); - op.mac_digest = + op->mac_digest =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); - op.mac_iv = + op->mac_iv =MAC_INNER_IV_P (SRAM_HMAC_IV_IN ) |MAC_OUTER_IV_P (SRAM_HMAC_IV_OUT );
@@ -349,16 +370,16 @@ static void mv_process_hash_current(int first_block) && (req_ctx->count <=MAX_HW_HASH_SIZE );if (req_ctx->first_hash) {if (is_last) - op.config |=CFG_NOT_FRAG ; + op->config |=CFG_NOT_FRAG ;else - op.config |=CFG_FIRST_FRAG ; + op->config |=CFG_FIRST_FRAG ; req_ctx->first_hash =0 ; }else {if (is_last) - op.config |=CFG_LAST_FRAG ; + op->config |=CFG_LAST_FRAG ;else - op.config |=CFG_MID_FRAG ; + op->config |=CFG_MID_FRAG ;if (first_block) {writel (req_ctx->state[0 ], cpg->reg +DIGEST_INITIAL_VAL_A );
@@ -369,8 +390,8 @@ static void mv_process_hash_current(int first_block) } } -memcpy (cpg->sram +SRAM_CONFIG , &op, -sizeof (struct sec_accel_config )); +memcpy (cpg->sram +SRAM_CONFIG , &cpg->sa_sram, +sizeof (struct sec_accel_sram ));/* GO */ mv_setup_timer ();
Signature · 1 line
1.7.3.4
PATCH 8/13 mv_cesa: fetch extra_bytes via DMA engine, too
In reply to Phil Sutter--- drivers/crypto/mv_cesa.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/crypto/mv_cesa.c +10 -2
@@ -158,6 +158,7 @@ struct mv_req_hash_ctx {u64 count;u32 state[SHA1_DIGEST_SIZE /4 ];u8 buffer[SHA1_BLOCK_SIZE ]; +dma_addr_t buffer_dma;int first_hash;/* marks that we don't have previous state */ int last_chunk;/* marks that this is the 'final' request */ int extra_bytes;/* unprocessed bytes in buffer */
@@ -638,6 +639,9 @@ static void mv_hash_algo_completion(void)dma_unmap_single (cpg->dev, ctx->result_dma, ctx->digestsize,DMA_FROM_DEVICE ); +dma_unmap_single (cpg->dev, ctx->buffer_dma, +SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); +if (unlikely (ctx->count >MAX_HW_HASH_SIZE )) {mv_save_digest_state (ctx);mv_hash_final_fallback (req);
@@ -757,8 +761,10 @@ static void mv_start_new_hash_req(struct ahash_request *req) p->process = mv_update_hash_config;if (unlikely (old_extra_bytes)) { -memcpy (cpg->sram +SRAM_DATA_IN_START , ctx->buffer, - old_extra_bytes); +dma_sync_single_for_device (cpg->dev, ctx->buffer_dma, +SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); +mv_dma_memcpy (cpg->sram_phys +SRAM_DATA_IN_START , + ctx->buffer_dma, old_extra_bytes); p->crypt_len = old_extra_bytes; }
@@ -903,6 +909,8 @@ static void mv_init_hash_req_ctx(struct mv_req_hash_ctx *ctx, int op, ctx->first_hash =1 ; ctx->last_chunk = is_last; ctx->count_add = count_add; + ctx->buffer_dma =dma_map_single (cpg->dev, ctx->buffer, +SHA1_BLOCK_SIZE ,DMA_TO_DEVICE ); } static void mv_update_hash_req_ctx(struct mv_req_hash_ctx *ctx, int is_last,
Signature · 1 line
1.7.3.4
PATCH 11/13 mv_cesa: implement descriptor chaining for hashes, too
In reply to Phil Sutter--- drivers/crypto/mv_cesa.c | 89 ++++++++++++++++++---------------------------- 1 files changed, 35 insertions(+), 54 deletions(-)
drivers/crypto/mv_cesa.c +35 -54
@@ -538,34 +538,14 @@ static void mv_init_hash_config(struct ahash_request *req) sizeof(struct sec_accel_sram), DMA_TO_DEVICE);mv_dma_memcpy (cpg->sram_phys +SRAM_CONFIG , cpg->sa_sram_dma,sizeof (struct sec_accel_sram )); - -mv_dma_separator (); - -if (req->result) { - req_ctx->result_dma =dma_map_single (cpg->dev, req->result, - req_ctx->digestsize,DMA_FROM_DEVICE ); -mv_dma_memcpy (req_ctx->result_dma, - cpg->sram_phys +SRAM_DIGEST_BUF , req_ctx->digestsize); - }else { -/* XXX: this fixes some ugly register fuckup bug in the tdma engine -* (no need to sync since the data is ignored anyway) */ -mv_dma_memcpy (cpg->sa_sram_dma, - cpg->sram_phys +SRAM_CONFIG ,1 ); - } - -/* GO */ -mv_setup_timer (); -mv_dma_trigger (); -writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); } -static void mv_update_hash_config (void ) +static void mv_update_hash_config (struct ahash_request *req) { -struct ahash_request *req =ahash_request_cast (cpg->cur_req);struct mv_req_hash_ctx *req_ctx =ahash_request_ctx (req);struct req_progress *p = &cpg->p; -struct sec_accel_config *op = &cpg->sa_sram.op;int is_last; +u32 val;/* update only the config (for changed fragment state) and * mac_digest (for changed frag len) fields */
@@ -573,10 +553,10 @@ static void mv_update_hash_config(void)switch (req_ctx->op) {case COP_SHA1 :default : - op->config =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ; + val =CFG_OP_MAC_ONLY |CFG_MACM_SHA1 ;break ;case COP_HMAC_SHA1 : - op->config =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ; + val =CFG_OP_MAC_ONLY |CFG_MACM_HMAC_SHA1 ;break ; }
@@ -584,36 +564,11 @@ static void mv_update_hash_config(void) && (p->hw_processed_bytes + p->crypt_len >= p->hw_nbytes) && (req_ctx->count <=MAX_HW_HASH_SIZE ); - op->config |= is_last ?CFG_LAST_FRAG :CFG_MID_FRAG ; -dma_sync_single_for_device (cpg->dev, cpg->sa_sram_dma, -sizeof (u32),DMA_TO_DEVICE ); -mv_dma_memcpy (cpg->sram_phys +SRAM_CONFIG , - cpg->sa_sram_dma,sizeof (u32)); - - op->mac_digest =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); -dma_sync_single_for_device (cpg->dev, cpg->sa_sram_dma +6 *sizeof (u32), -sizeof (u32),DMA_TO_DEVICE ); -mv_dma_memcpy (cpg->sram_phys +SRAM_CONFIG +6 *sizeof (u32), - cpg->sa_sram_dma +6 *sizeof (u32),sizeof (u32)); - -mv_dma_separator (); - -if (req->result) { - req_ctx->result_dma =dma_map_single (cpg->dev, req->result, - req_ctx->digestsize,DMA_FROM_DEVICE ); -mv_dma_memcpy (req_ctx->result_dma, - cpg->sram_phys +SRAM_DIGEST_BUF , req_ctx->digestsize); - }else { -/* XXX: this fixes some ugly register fuckup bug in the tdma engine -* (no need to sync since the data is ignored anyway) */ -mv_dma_memcpy (cpg->sa_sram_dma, - cpg->sram_phys +SRAM_CONFIG ,1 ); - } + val |= is_last ?CFG_LAST_FRAG :CFG_MID_FRAG ; +mv_dma_u32_copy (cpg->sram_phys +SRAM_CONFIG , val); -/* GO */ -mv_setup_timer (); -mv_dma_trigger (); -writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); + val =MAC_DIGEST_P (SRAM_DIGEST_BUF ) |MAC_FRAG_LEN (p->crypt_len); +mv_dma_u32_copy (cpg->sram_phys +SRAM_CONFIG +6 *sizeof (u32), val); } static inline int mv_hash_import_sha1_ctx(const struct mv_req_hash_ctx *ctx,
@@ -837,7 +792,6 @@ static void mv_start_new_hash_req(struct ahash_request *req) p->hw_nbytes = hw_bytes; p->complete = mv_hash_algo_completion; - p->process = mv_update_hash_config;if (unlikely (old_extra_bytes)) { dma_sync_single_for_device(cpg->dev, ctx->buffer_dma,
@@ -849,6 +803,33 @@ static void mv_start_new_hash_req(struct ahash_request *req)setup_data_in ();mv_init_hash_config (req); +mv_dma_separator (); + cpg->p.hw_processed_bytes += cpg->p.crypt_len; +while (cpg->p.hw_processed_bytes < cpg->p.hw_nbytes) { + cpg->p.crypt_len =0 ; + +setup_data_in (); +mv_update_hash_config (req); +mv_dma_separator (); + cpg->p.hw_processed_bytes += cpg->p.crypt_len; + } +if (req->result) { + ctx->result_dma =dma_map_single (cpg->dev, req->result, + ctx->digestsize,DMA_FROM_DEVICE ); +mv_dma_memcpy (ctx->result_dma, + cpg->sram_phys +SRAM_DIGEST_BUF , + ctx->digestsize); + }else { +/* XXX: this fixes some ugly register fuckup bug in the tdma engine +* (no need to sync since the data is ignored anyway) */ +mv_dma_memcpy (cpg->sa_sram_dma, + cpg->sram_phys +SRAM_CONFIG ,1 ); + } + +/* GO */ +mv_setup_timer (); +mv_dma_trigger (); +writel (SEC_CMD_EN_SEC_ACCL0 , cpg->reg +SEC_ACCEL_CMD ); }static int queue_manag (void *data)
Signature · 1 line
1.7.3.4
RFC: support for MV_CESA with IDMA or TDMA
In reply to Herbert XuHi,
The following patch series adds support for the TDMA engine built into Marvell's Kirkwood-based SoCs as well as the IDMA engine built into Marvell's Orion-based SoCs and enhances mv_cesa.c in order to use it for speeding up crypto operations. The hardware contains a security accelerator, which can control DMA as well as crypto engines. It allows for operation with minimal software intervention, which the following patches implement: using a chain of DMA descriptors, data input, configuration, engine startup and data output repeat fully automatically until the whole input data has been handled.
The point for this being RFC is lack of hardware on my side for testing the IDMA support. I'd highly appreciate if someone with Orion hardware could test this, preferably using the hmac_comp tool shipped with cryptodev-linux as it does a more extensive testing (with bigger buffer sizes at least) than tcrypt or the standard kernel-internal use cases.
Greetings, Phil
PATCH 2/13 mv_cesa: minor formatting cleanup, will all make sense soon
This is just to keep formatting changes out of the following commit, hopefully simplifying it a bit.
--- drivers/crypto/mv_cesa.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
drivers/crypto/mv_cesa.c +6 -8
@@ -269,12 +269,10 @@ static void mv_process_current_q(int first_block) }if (req_ctx->decrypt) { op.config |=CFG_DIR_DEC ; -memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_dec_key, -AES_KEY_LEN ); +memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_dec_key,AES_KEY_LEN ); }else { op.config |=CFG_DIR_ENC ; -memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_enc_key, -AES_KEY_LEN ); +memcpy (cpg->sram +SRAM_DATA_KEY_P , ctx->aes_enc_key,AES_KEY_LEN ); }switch (ctx->key_len) {
@@ -335,9 +333,8 @@ static void mv_process_hash_current(int first_block) } op.mac_src_p = -MAC_SRC_DATA_P (SRAM_DATA_IN_START ) |MAC_SRC_TOTAL_LEN ((u32 ) - req_ctx-> - count); +MAC_SRC_DATA_P (SRAM_DATA_IN_START ) | +MAC_SRC_TOTAL_LEN ((u32 )req_ctx->count);setup_data_in ();
@@ -372,7 +369,8 @@ static void mv_process_hash_current(int first_block) } } -memcpy (cpg->sram +SRAM_CONFIG , &op,sizeof (struct sec_accel_config )); +memcpy (cpg->sram +SRAM_CONFIG , &op, +sizeof (struct sec_accel_config ));/* GO */ mv_setup_timer ();
Signature · 1 line
1.7.3.4
PATCH 5/13 add a driver for the Marvell IDMA/TDMA engines
In reply to Phil SutterThese are DMA engines integrated into the Marvell Orion/Kirkwood SoCs, designed to offload data transfers from/to the CESA crypto engine.
--- arch/arm/mach-kirkwood/common.c | 33 ++ arch/arm/mach-kirkwood/include/mach/irqs.h | 1 + arch/arm/mach-orion5x/common.c | 33 ++ arch/arm/mach-orion5x/include/mach/orion5x.h | 2 + drivers/crypto/Kconfig | 5 + drivers/crypto/Makefile | 3 +- drivers/crypto/mv_dma.c | 464 ++++++++++++++++++++++++++ drivers/crypto/mv_dma.h | 127 +++++++ 8 files changed, 667 insertions(+), 1 deletions(-) create mode 100644 drivers/crypto/mv_dma.c create mode 100644 drivers/crypto/mv_dma.h
arch/arm/mach-kirkwood/common.c +33 -0
@@ -426,8 +426,41 @@ void __init kirkwood_uart1_init(void)/***************************************************************************** * Cryptographic Engines and Security Accelerator (CESA) ****************************************************************************/ +static struct resource kirkwood_tdma_res[] = { + { + .name ="regs deco" , + .start =CRYPTO_PHYS_BASE +0xA00 , + .end =CRYPTO_PHYS_BASE +0xA24 , + .flags =IORESOURCE_MEM , + }, { + .name ="regs control and error" , + .start =CRYPTO_PHYS_BASE +0x800 , + .end =CRYPTO_PHYS_BASE +0x8CF , + .flags =IORESOURCE_MEM , + }, { + .name ="crypto error" , + .start =IRQ_KIRKWOOD_TDMA_ERR , + .end =IRQ_KIRKWOOD_TDMA_ERR , + .flags =IORESOURCE_IRQ , + }, +}; + +static u64 mv_tdma_dma_mask =DMA_BIT_MASK (32 ); + +static struct platform_device kirkwood_tdma_device = { + .name ="mv_tdma" , + .id =-1 , + .dev = { + .dma_mask = &mv_tdma_dma_mask, + .coherent_dma_mask =DMA_BIT_MASK (32 ), + }, + .num_resources =ARRAY_SIZE (kirkwood_tdma_res), + .resource = kirkwood_tdma_res, +}; +void __init kirkwood_crypto_init (void ) { +platform_device_register (&kirkwood_tdma_device);orion_crypto_init (CRYPTO_PHYS_BASE ,KIRKWOOD_SRAM_PHYS_BASE ,KIRKWOOD_SRAM_SIZE ,IRQ_KIRKWOOD_CRYPTO ); }
arch/arm/mach-kirkwood/include/mach/irqs.h +1 -0
@@ -51,6 +51,7 @@#define IRQ_KIRKWOOD_GPIO_HIGH_16_23 41#define IRQ_KIRKWOOD_GE00_ERR 46#define IRQ_KIRKWOOD_GE01_ERR 47 +#define IRQ_KIRKWOOD_TDMA_ERR 49#define IRQ_KIRKWOOD_RTC 53/*
arch/arm/mach-orion5x/common.c +33 -0
@@ -181,9 +181,42 @@ void __init orion5x_xor_init(void)/***************************************************************************** * Cryptographic Engines and Security Accelerator (CESA) ****************************************************************************/ +static struct resource orion_idma_res[] = { + { + .name ="regs deco" , + .start =ORION5X_IDMA_PHYS_BASE +0xA00 , + .end =ORION5X_IDMA_PHYS_BASE +0xA24 , + .flags =IORESOURCE_MEM , + }, { + .name ="regs control and error" , + .start =ORION5X_IDMA_PHYS_BASE +0x800 , + .end =ORION5X_IDMA_PHYS_BASE +0x8CF , + .flags =IORESOURCE_MEM , + }, { + .name ="crypto error" , + .start =IRQ_ORION5X_IDMA_ERR , + .end =IRQ_ORION5X_IDMA_ERR , + .flags =IORESOURCE_IRQ , + }, +}; + +static u64 mv_idma_dma_mask =DMA_BIT_MASK (32 ); + +static struct platform_device orion_idma_device = { + .name ="mv_idma" , + .id =-1 , + .dev = { + .dma_mask = &mv_idma_dma_mask, + .coherent_dma_mask =DMA_BIT_MASK (32 ), + }, + .num_resources =ARRAY_SIZE (orion_idma_res), + .resource = orion_idma_res, +}; +static void __init orion5x_crypto_init (void ) {orion5x_setup_sram_win (); +platform_device_register (&orion_idma_device);orion_crypto_init (ORION5X_CRYPTO_PHYS_BASE ,ORION5X_SRAM_PHYS_BASE ,SZ_8K ,IRQ_ORION5X_CESA ); }
arch/arm/mach-orion5x/include/mach/orion5x.h +2 -0
@@ -90,6 +90,8 @@#define ORION5X_USB0_PHYS_BASE (ORION5X_REGS_PHYS_BASE | 0x50000)#define ORION5X_USB0_VIRT_BASE (ORION5X_REGS_VIRT_BASE | 0x50000) +#define ORION5X_IDMA_PHYS_BASE (ORION5X_REGS_PHYS_BASE | 0x60000) +#define ORION5X_XOR_PHYS_BASE (ORION5X_REGS_PHYS_BASE | 0x60900)#define ORION5X_XOR_VIRT_BASE (ORION5X_REGS_VIRT_BASE | 0x60900)
drivers/crypto/Kconfig +5 -0
@@ -159,6 +159,10 @@ config CRYPTO_GHASH_S390 It is available as of z196. +config CRYPTO_DEV_MV_DMA + tristate + default no + config CRYPTO_DEV_MV_CESA tristate "Marvell's Cryptographic Engine" depends on PLAT_ORION
@@ -166,6 +170,7 @@ config CRYPTO_DEV_MV_CESA select CRYPTO_AES select CRYPTO_BLKCIPHER2 select CRYPTO_HASH + select CRYPTO_DEV_MV_DMA help This driver allows you to utilize the Cryptographic Engines and Security Accelerator (CESA) which can be found on the Marvell Orion
drivers/crypto/Makefile +2 -1
@@ -4,6 +4,7 @@ obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o obj-$(CONFIG_CRYPTO_DEV_NIAGARA2) += n2_crypto.o n2_crypto-y := n2_core.o n2_asm.o obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o +obj-$(CONFIG_CRYPTO_DEV_MV_DMA) += mv_dma.o obj-$(CONFIG_CRYPTO_DEV_MV_CESA) += mv_cesa.o obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM) += caam/
@@ -14,4 +15,4 @@ obj-$(CONFIG_CRYPTO_DEV_OMAP_AES) += omap-aes.o obj-$(CONFIG_CRYPTO_DEV_PICOXCELL) += picoxcell_crypto.o obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o obj-$(CONFIG_CRYPTO_DEV_TEGRA_AES) += tegra-aes.o -obj-$(CONFIG_CRYPTO_DEV_UX500) += ux500/ +obj-$(CONFIG_CRYPTO_DEV_UX500) += ux500/
drivers/crypto/mv_dma.c new file +464 -0
464 lines not on this page · raw message
drivers/crypto/mv_dma.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 1/13 mv_cesa: do not use scatterlist iterators
In reply to Phil SutterThe big problem is they cannot be used to iterate over DMA mapped scatterlists, so get rid of them in order to add DMA functionality to mv_cesa.
--- drivers/crypto/mv_cesa.c | 57 ++++++++++++++++++++++----------------------- 1 files changed, 28 insertions(+), 29 deletions(-)
drivers/crypto/mv_cesa.c +28 -29
@@ -44,8 +44,8 @@ enum engine_status {/** * struct req_progress - used for every crypt request -* @src_sg_it: sg iterator for src -* @dst_sg_it: sg iterator for dst +* @src_sg: sg list for src +* @dst_sg: sg list for dst * @sg_src_left: bytes left in src to process (scatter list) * @src_start: offset to add to src start position (scatter list) * @crypt_len: length of current hw crypt/hash process
@@ -60,8 +60,8 @@ enum engine_status {* track of progress within current scatterlist. */ struct req_progress { -struct sg_mapping_iter src_sg_it; -struct sg_mapping_iter dst_sg_it; +struct scatterlist *src_sg; +struct scatterlist *dst_sg;void (*complete) (void );void (*process) (int is_first);
@@ -212,19 +212,19 @@ static int mv_setkey_aes(struct crypto_ablkcipher *cipher, const u8 *key,static void copy_src_to_buf (struct req_progress *p,char *dbuf,int len) { -int ret;void *sbuf;int copy_len;while (len) {if (!p->sg_src_left) { - ret =sg_miter_next (&p->src_sg_it); -BUG_ON (!ret); - p->sg_src_left = p->src_sg_it.length; +/* next sg please */ + p->src_sg =sg_next (p->src_sg); +BUG_ON (!p->src_sg); + p->sg_src_left = p->src_sg->length; p->src_start =0 ; } - sbuf = p->src_sg_it.addr + p->src_start; + sbuf =sg_virt (p->src_sg) + p->src_start; copy_len =min (p->sg_src_left, len);memcpy (dbuf, sbuf, copy_len);
@@ -307,9 +307,6 @@ static void mv_crypto_algo_completion(void)struct ablkcipher_request *req =ablkcipher_request_cast (cpg->cur_req);struct mv_req_ctx *req_ctx =ablkcipher_request_ctx (req); -sg_miter_stop (&cpg->p.src_sg_it); -sg_miter_stop (&cpg->p.dst_sg_it); -if (req_ctx->op !=COP_AES_CBC )return ;
@@ -439,7 +436,6 @@ static void mv_hash_algo_completion(void)if (ctx->extra_bytes)copy_src_to_buf (&cpg->p, ctx->buffer, ctx->extra_bytes); -sg_miter_stop (&cpg->p.src_sg_it);if (likely (ctx->last_chunk)) {if (likely (ctx->count <=MAX_HW_HASH_SIZE )) {
@@ -459,7 +455,6 @@ static void dequeue_complete_req(void) {struct crypto_async_request *req = cpg->cur_req;void *buf; -int ret; cpg->p.hw_processed_bytes += cpg->p.crypt_len;if (cpg->p.copy_back) {int need_copy_len = cpg->p.crypt_len;
@@ -468,14 +463,14 @@ static void dequeue_complete_req(void)int dst_copy;if (!cpg->p.sg_dst_left) { - ret =sg_miter_next (&cpg->p.dst_sg_it); -BUG_ON (!ret); - cpg->p.sg_dst_left = cpg->p.dst_sg_it.length; +/* next sg please */ + cpg->p.dst_sg =sg_next (cpg->p.dst_sg); +BUG_ON (!cpg->p.dst_sg); + cpg->p.sg_dst_left = cpg->p.dst_sg->length; cpg->p.dst_start =0 ; } - buf = cpg->p.dst_sg_it.addr; - buf += cpg->p.dst_start; + buf =sg_virt (cpg->p.dst_sg) + cpg->p.dst_start; dst_copy =min (need_copy_len, cpg->p.sg_dst_left);
@@ -525,7 +520,6 @@ static int count_sgs(struct scatterlist *sl, unsigned int total_bytes)static void mv_start_new_crypt_req (struct ablkcipher_request *req) {struct req_progress *p = &cpg->p; -int num_sgs; cpg->cur_req = &req->base;memset (p,0 ,sizeof (struct req_progress ));
@@ -534,11 +528,14 @@ static void mv_start_new_crypt_req(struct ablkcipher_request *req) p->process = mv_process_current_q; p->copy_back =1 ; - num_sgs =count_sgs (req->src, req->nbytes); -sg_miter_start (&p->src_sg_it, req->src, num_sgs,SG_MITER_FROM_SG ); - - num_sgs =count_sgs (req->dst, req->nbytes); -sg_miter_start (&p->dst_sg_it, req->dst, num_sgs,SG_MITER_TO_SG ); + p->src_sg = req->src; + p->dst_sg = req->dst; +if (req->nbytes) { +BUG_ON (!req->src); +BUG_ON (!req->dst); + p->sg_src_left = req->src->length; + p->sg_dst_left = req->dst->length; + }mv_process_current_q (1 ); }
@@ -547,7 +544,7 @@ static void mv_start_new_hash_req(struct ahash_request *req) {struct req_progress *p = &cpg->p;struct mv_req_hash_ctx *ctx =ahash_request_ctx (req); -int num_sgs, hw_bytes, old_extra_bytes, rc; +int hw_bytes, old_extra_bytes, rc; cpg->cur_req = &req->base;memset (p,0 ,sizeof (struct req_progress )); hw_bytes = req->nbytes + ctx->extra_bytes;
@@ -560,8 +557,11 @@ static void mv_start_new_hash_req(struct ahash_request *req)else ctx->extra_bytes =0 ; - num_sgs =count_sgs (req->src, req->nbytes); -sg_miter_start (&p->src_sg_it, req->src, num_sgs,SG_MITER_FROM_SG ); + p->src_sg = req->src; +if (req->nbytes) { +BUG_ON (!req->src); + p->sg_src_left = req->src->length; + }if (hw_bytes) { p->hw_nbytes = hw_bytes;
@@ -578,7 +578,6 @@ static void mv_start_new_hash_req(struct ahash_request *req) }else {copy_src_to_buf (p, ctx->buffer + old_extra_bytes, ctx->extra_bytes - old_extra_bytes); -sg_miter_stop (&p->src_sg_it);if (ctx->last_chunk) rc =mv_hash_final_fallback (req);else
Signature · 1 line
1.7.3.4
Re: RFC: support for MV_CESA with IDMA or TDMA
In reply to Phil SutterQuoted 18 lines · Phil Sutter
Hi,
The following patch series adds support for the TDMA engine built into Marvell's Kirkwood-based SoCs as well as the IDMA engine built into Marvell's Orion-based SoCs and enhances
mv_cesa.cin order to use it for speeding up crypto operations. The hardware contains a security accelerator, which can control DMA as well as crypto engines. It allows for operation with minimal software intervention, which the following patches implement: using a chain of DMA descriptors, data input, configuration, engine startup and data output repeat fully automatically until the whole input data has been handled.The point for this being RFC is lack of hardware on my side for testing the IDMA support. I'd highly appreciate if someone with Orion hardware could test this, preferably using the
hmac_comptool shipped with cryptodev-linux as it does a more extensive testing (with bigger buffer sizes at least) than tcrypt or the standard kernel-internal use cases.
Quoted 6 lines
Greetings, Phil
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
I would like to have a try on those patches. But what version of kernel should I apply those patches on?
Thanks.
Re: RFC: support for MV_CESA with IDMA or TDMA
Hi,
Quoted 2 lines · cloudy.linux
I would like to have a try on those patches. But what version of kernel should I apply those patches on?
Sorry for the caused confusion. I have applied those patches to linus' git, preceded by the three accepted ones of the earlier four. Yay.
Long story short, please just fetch git://nwl.cc/~n0-1/linux.git and checkout the 'cesa-dma' branch. It's exactly what I formatted the patches from.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
cover Fixes for MV_CESA with IDMA or TDMA
In reply to Phil SutterHi Phil,
thanks for providing these patches; it's great to finally see DMA support for CESA in the kernel. Additionally, the implementation seems to be fine regarding cache incoherencies (at least my test in [*] works).
I have two patches for your patchset...
- Fix for mv_init_engine error handling
- My system locked up hard when mv_dma and mv_cesa were built as modules. mv_cesa has code to enable the crypto clock in 3.5, but mv_dma already accesses the CESA engine before. Thus, we need to enable this clock here, too.
[*] http://www.spinics.net/lists/arm-kernel/msg176913.html
Simon Baatz (2):
mv_dma: fix mv_init_engine() error case
ARM: Orion: mv_dma: Add support for clk
arch/arm/mach-kirkwood/common.c | 1 + drivers/crypto/mv_dma.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/2 mv_dma: fix mv_init_engine() error case
Fix wrongly placed free_irq in mv_init_engine() error recovery. In fact, we can remove the respective label, since request_irq() is the last thing the function does anyway.
--- drivers/crypto/mv_dma.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/crypto/mv_dma.c +1 -3
@@ -296,7 +296,7 @@ static int mv_init_engine(struct platform_device *pdev,if (init_dma_desclist (&tpg.desclist, tpg.dev,sizeof (struct mv_dma_desc ),MV_DMA_ALIGN ,0 )) { rc = -ENOMEM ; - goto out_free_irq; + goto out_unmap_reg; }if (set_dma_desclist_size (&tpg.desclist,MV_DMA_INIT_POOLSIZE )) { rc = -ENOMEM ;
@@ -330,8 +330,6 @@ out_free_all:platform_set_drvdata (pdev,NULL ); out_free_desclist:fini_dma_desclist (&tpg.desclist); -out_free_irq: -free_irq (tpg.irq, &tpg); out_unmap_reg:iounmap (tpg.reg); tpg.dev =NULL ;
Signature · 1 line
1.7.9.5
PATCH 2/2 ARM: Orion: mv_dma: Add support for clk
In reply to Simon Baatzmv_dma needs the crypto clock. Some orion platforms support gating of the clock. If the clock exists enable/disable it as appropriate.
--- arch/arm/mach-kirkwood/common.c | 1 + drivers/crypto/mv_dma.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
arch/arm/mach-kirkwood/common.c +1 -0
@@ -234,6 +234,7 @@ void __init kirkwood_clk_init(void)orion_clkdev_add (NULL ,"orion-ehci.0" , usb0);orion_clkdev_add (NULL ,"orion_nand" , runit);orion_clkdev_add (NULL ,"mvsdio" , sdio); +orion_clkdev_add (NULL ,"mv_tdma" , crypto);orion_clkdev_add (NULL ,"mv_crypto" , crypto);orion_clkdev_add (NULL ,MV_XOR_SHARED_NAME ".0" , xor0);orion_clkdev_add (NULL ,MV_XOR_SHARED_NAME ".1" , xor1);
drivers/crypto/mv_dma.c +14 -0
@@ -13,6 +13,7 @@#include <linux/dmapool.h> #include <linux/interrupt.h> #include <linux/module.h> +#include <linux/clk.h> #include <linux/slab.h> #include <linux/platform_device.h>
@@ -36,6 +37,7 @@ struct mv_dma_priv {struct device *dev;void __iomem *reg;int irq; +struct clk *clk;/* protecting the dma descriptors and stuff */ spinlock_t lock;struct dma_desclist desclist;
@@ -292,6 +294,12 @@ static int mv_init_engine(struct platform_device *pdev, goto out_unmap_reg; } +/* Not all platforms can gate the clock, so it is not +an error if the clock does not exists. */ + tpg.clk =clk_get (&pdev->dev,NULL ); +if (!IS_ERR (tpg.clk)) +clk_prepare_enable (tpg.clk); +/* initialise DMA descriptor list */ if (init_dma_desclist (&tpg.desclist, tpg.dev,sizeof (struct mv_dma_desc ),MV_DMA_ALIGN ,0 )) {
@@ -343,6 +351,12 @@ static int mv_remove(struct platform_device *pdev)fini_dma_desclist (&tpg.desclist);free_irq (tpg.irq, &tpg);iounmap (tpg.reg); + +if (!IS_ERR (tpg.clk)) { +clk_disable_unprepare (tpg.clk); +clk_put (tpg.clk); + } + tpg.dev =NULL ;return 0 ; }
Signature · 1 line
1.7.9.5
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
In reply to Simon BaatzHi Simon,
Quoted 4 lines · Simon Baatz
thanks for providing these patches; it's great to finally see DMA support for CESA in the kernel. Additionally, the implementation seems to be fine regarding cache incoherencies (at least my test in [*] works).
Thanks for testing and the fixes. Could you also specify the platform you are testing on?
Quoted 8 lines
I have two patches for your patchset...
- Fix for
mv_init_engineerror handling- My system locked up hard when
mv_dmaandmv_cesawere built as modules.mv_cesahas code to enable the crypto clock in 3.5, butmv_dmaalready accesses the CESA engine before. Thus, we need to enable this clock here, too.
I have folded them into my patch series, thanks again. I somewhat miss the orion_clkdev_add() part for orion5x platforms, but also fail to find any equivalent place in the correspondent subdirectory. So I hope it is OK like this.
The updated patch series is available at git://nwl.cc/~n0-1/linux.git,
branch 'cesa-dma'. My push changed history, so you have to either reset --hard to it's HEAD, or rebase skipping the outdated patches.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi Phil,
Quoted 8 lines · Phil Sutter
Quoted 4 lines · Simon Baatz
thanks for providing these patches; it's great to finally see DMA support for CESA in the kernel. Additionally, the implementation seems to be fine regarding cache incoherencies (at least my test in [*] works).
Thanks for testing and the fixes. Could you also specify the platform you are testing on?
This is a Marvell Kirkwood MV88F6281-A1.
I see one effect that I don't fully understand. Similar to the previous implementation, the system is mostly in kernel space when accessing an encrypted dm-crypt device:
# cryptsetup --cipher=aes-cbc-plain --key-size=128 create c_sda2 /dev/sda2 Enter passphrase: # dd if=/dev/mapper/c_sda2 of=/dev/null bs=64k count=2048 2048+0 records in 2048+0 records out 134217728 bytes (134 MB) copied, 10.7324 s, 12.5 MB/s
Doing an "mpstat 1" at the same time gives:
21:21:42 CPU %usr %nice %sys %iowait %irq %soft ... 21:21:45 all 0.00 0.00 0.00 0.00 0.00 0.00 21:21:46 all 0.00 0.00 79.00 0.00 0.00 2.00 21:21:47 all 0.00 0.00 95.00 0.00 0.00 5.00 21:21:48 all 0.00 0.00 94.00 0.00 0.00 6.00 21:21:49 all 0.00 0.00 96.00 0.00 0.00 4.00
...
The underlying device is a SATA drive and should not be the limit:
# dd if=/dev/sda2 of=/dev/null bs=64k count=2048 2048+0 records in 2048+0 records out 134217728 bytes (134 MB) copied, 1.79804 s, 74.6 MB/s
I did not dare hope the DMA implementation to be much faster than the old one, but I would have expected a rather low CPU usage using DMA. Do you have an idea where the kernel spends its time? (Am I hitting a non/only partially accelerated path here?)
Quoted 9 lines
Quoted 4 lines
- My system locked up hard when
mv_dmaandmv_cesawere built as modules.mv_cesahas code to enable the crypto clock in 3.5, butmv_dmaalready accesses the CESA engine before. Thus, we need to enable this clock here, too.I have folded them into my patch series, thanks again. I somewhat miss the
orion_clkdev_add()part for orion5x platforms, but also fail to find any equivalent place in the correspondent subdirectory. So I hope it is OK like this.
The change follows the original clk changes by Andrew. I don't know orion5x, but apparently, only kirkwood has such fine grained clock gates:
/* Create clkdev entries for all orion platforms except kirkwood.
Kirkwood has gated clocks for some of its peripherals, so creates its own clkdev entries. For all the other orion devices, create clkdev entries to the tclk. */
(from plat-orion/common.c)
This is why the clock enabling code in the modules ignores the case that the clock can't be found. I think the clocks defined by plat-orion are for those drivers that need the actual TCLK rate (but there is no clock gate functionality here).
- Simon
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi Simon,
Quoted 11 lines · Simon Baatz
Quoted 8 lines · Phil Sutter
Quoted 4 lines · Simon Baatz
thanks for providing these patches; it's great to finally see DMA support for CESA in the kernel. Additionally, the implementation seems to be fine regarding cache incoherencies (at least my test in [*] works).
Thanks for testing and the fixes. Could you also specify the platform you are testing on?
This is a Marvell Kirkwood MV88F6281-A1.
OK, thanks. Just wanted to be sure it's not already the Orion test I'm hoping for. :)
Quoted 28 lines
I see one effect that I don't fully understand. Similar to the previous implementation, the system is mostly in kernel space when accessing an encrypted dm-crypt device:
# cryptsetup --cipher=aes-cbc-plain --key-size=128 create c_sda2 /dev/sda2 Enter passphrase: # dd if=/dev/mapper/c_sda2 of=/dev/null bs=64k count=2048 2048+0 records in 2048+0 records out 134217728 bytes (134 MB) copied, 10.7324 s, 12.5 MB/sDoing an "mpstat 1" at the same time gives:
21:21:42 CPU %usr %nice %sys %iowait %irq %soft ... 21:21:45 all 0.00 0.00 0.00 0.00 0.00 0.00 21:21:46 all 0.00 0.00 79.00 0.00 0.00 2.00 21:21:47 all 0.00 0.00 95.00 0.00 0.00 5.00 21:21:48 all 0.00 0.00 94.00 0.00 0.00 6.00 21:21:49 all 0.00 0.00 96.00 0.00 0.00 4.00...
The underlying device is a SATA drive and should not be the limit:
# dd if=/dev/sda2 of=/dev/null bs=64k count=2048 2048+0 records in 2048+0 records out 134217728 bytes (134 MB) copied, 1.79804 s, 74.6 MB/s
Quoted 4 lines
I did not dare hope the DMA implementation to be much faster than the old one, but I would have expected a rather low CPU usage using DMA. Do you have an idea where the kernel spends its time? (Am I hitting a non/only partially accelerated path here?)
Hmm. Though you passed bs=64k to dd, block sizes may still be the bottleneck. No idea if the parameter is really passed down to dm-crypt or if that uses the underlying device's block size anyway. I just did a short speed test on the 2.6.39.2 we're using productively:
| Testing AES-128-CBC cipher: | Encrypting in chunks of 512 bytes: done. 46.19 MB in 5.00 secs: 9.24 MB/sec | Encrypting in chunks of 1024 bytes: done. 81.82 MB in 5.00 secs: 16.36 MB/sec | Encrypting in chunks of 2048 bytes: done. 124.63 MB in 5.00 secs: 24.93 MB/sec | Encrypting in chunks of 4096 bytes: done. 162.88 MB in 5.00 secs: 32.58 MB/sec | Encrypting in chunks of 8192 bytes: done. 200.47 MB in 5.00 secs: 40.09 MB/sec | Encrypting in chunks of 16384 bytes: done. 226.61 MB in 5.00 secs: 45.32 MB/sec | Encrypting in chunks of 32768 bytes: done. 242.78 MB in 5.00 secs: 48.55 MB/sec | Encrypting in chunks of 65536 bytes: done. 251.85 MB in 5.00 secs: 50.36 MB/sec | | Testing AES-256-CBC cipher: | Encrypting in chunks of 512 bytes: done. 45.15 MB in 5.00 secs: 9.03 MB/sec | Encrypting in chunks of 1024 bytes: done. 78.72 MB in 5.00 secs: 15.74 MB/sec | Encrypting in chunks of 2048 bytes: done. 117.59 MB in 5.00 secs: 23.52 MB/sec | Encrypting in chunks of 4096 bytes: done. 151.59 MB in 5.00 secs: 30.32 MB/sec | Encrypting in chunks of 8192 bytes: done. 182.95 MB in 5.00 secs: 36.59 MB/sec | Encrypting in chunks of 16384 bytes: done. 204.00 MB in 5.00 secs: 40.80 MB/sec | Encrypting in chunks of 32768 bytes: done. 216.17 MB in 5.00 secs: 43.23 MB/sec | Encrypting in chunks of 65536 bytes: done. 223.22 MB in 5.00 secs: 44.64 MB/sec
Observing top while it was running revealed that system load was decreasing with increased block sizes - ~75% at 512B, ~20% at 32kB. I fear this is a limitation we have to live with, the overhead of setting up DMA descriptors and handling the returned data is quite high, especially when compared to the time it takes the engine to encrypt 512B. I was playing around with descriptor preparation at some point (i.e. preparing the next descriptor chaing while the engine is active), but without satisfying results. Maybe I should have another look at it, especially regarding the case of small chunk sizes. OTOH this all makes sense only when used asymmetrically, and I have no idea whether dm-crypt (or fellows like IPsec) makes use of that interface at all.
Quoted 19 lines
Quoted 9 lines
Quoted 4 lines
- My system locked up hard when
mv_dmaandmv_cesawere built as modules.mv_cesahas code to enable the crypto clock in 3.5, butmv_dmaalready accesses the CESA engine before. Thus, we need to enable this clock here, too.I have folded them into my patch series, thanks again. I somewhat miss the
orion_clkdev_add()part for orion5x platforms, but also fail to find any equivalent place in the correspondent subdirectory. So I hope it is OK like this.The change follows the original clk changes by Andrew. I don't know orion5x, but apparently, only kirkwood has such fine grained clock gates:
/* Create clkdev entries for all orion platforms except kirkwood.
Kirkwood has gated clocks for some of its peripherals, so creates its own clkdev entries. For all the other orion devices, create clkdev entries to the tclk. */
Quoted 6 lines
(from
plat-orion/common.c)This is why the clock enabling code in the modules ignores the case that the clock can't be found. I think the clocks defined by plat-orion are for those drivers that need the actual TCLK rate (but there is no clock gate functionality here).
Ah, OK. Reading helps, they say. Thanks anyway for your explanation.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Quoted 10 lines · Phil Sutter
Hi Simon,
Quoted 7 lines · Simon Baatz
Quoted 6 lines · Phil Sutter
Quoted 4 lines · Simon Baatz
thanks for providing these patches; it's great to finally see DMA support for CESA in the kernel. Additionally, the implementation seems to be fine regarding cache incoherencies (at least my test in [*] works).
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Thanks for testing and the fixes. Could you also specify the platform you are testing on?
This is a Marvell Kirkwood MV88F6281-A1.
OK, thanks. Just wanted to be sure it's not already the Orion test I'm hoping for. :)
OK, here comes the Orion test result - Linkstation Pro with 88F5182 A2. I didn't enable any debug option yet (I don't know what to be enabled in fact). Hope the mv_cesa and mv_dma related kernel messages below could be helpful though:
...
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x80000010
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x79b4008
MV-DMA: tpg.reg + DMA_DST_ADDR = 0xf2200080
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x79b1010
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x79b1000
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0 MV-CESA:got an interrupt but no pending timer?
alg: skcipher: Test 1 failed on encryption for mv-ecb-aes
00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
...
MV-CESA:completion timer expired (CESA active), cleaning up. MV-CESA:mv_completion_timer_callback: waiting for engine finishing MV-CESA:mv_completion_timer_callback: waiting for engine finishing
Then the console was flooded by the "waiting for engine finshing" message and the boot can't finish.
I'll be happy to help to debug this. Just tell me how.
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi,
Quoted 49 lines · cloudy.linux
Quoted 10 lines · Phil Sutter
Hi Simon,
Quoted 7 lines · Simon Baatz
Quoted 6 lines · Phil Sutter
Quoted 4 lines · Simon Baatz
thanks for providing these patches; it's great to finally see DMA support for CESA in the kernel. Additionally, the implementation seems to be fine regarding cache incoherencies (at least my test in [*] works).
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Thanks for testing and the fixes. Could you also specify the platform you are testing on?
This is a Marvell Kirkwood MV88F6281-A1.
OK, thanks. Just wanted to be sure it's not already the Orion test I'm hoping for. :)
OK, here comes the Orion test result - Linkstation Pro with 88F5182 A2. I didn't enable any debug option yet (I don't know what to be enabled in fact). Hope the
mv_cesaandmv_dmarelated kernel messages below could be helpful though:...
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA:idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg +DMA_CTRL=0x80001d04
MV-DMA: tpg.reg +DMA_BYTE_COUNT=0x80000010
MV-DMA: tpg.reg +DMA_SRC_ADDR=0x79b4008
MV-DMA: tpg.reg +DMA_DST_ADDR=0xf2200080
MV-DMA: tpg.reg +DMA_NEXT_DESC=0x79b1010
MV-DMA: tpg.reg +DMA_CURR_DESC=0x79b1000
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at0xffdbb000: dma addr0x79b1000, src0x79b4000, dst0xf2200080, count 16, own 1, next0x79b1010
MV-DMA: entry 1 at0xffdbb010: dma addr0x79b1010, src0x799c28c, dst0xf2200000, count 80, own 1, next0x79b1020
MV-DMA: entry 2 at0xffdbb020: dma addr0x79b1020, src0x0, dst0x0, count 0, own 0, next0x79b1030
MV-DMA: entry 3 at0xffdbb030: dma addr0x79b1030, src0xf2200080, dst0x79b4000, count 16, own 1, next0x0
MV-CESA:got an interrupt but no pending timer?
alg: skcipher: Test 1 failed on encryption for mv-ecb-aes 00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
...
Quoted 8 lines
MV-CESA:completion timer expired (CESA active), cleaning up. MV-CESA:mv_completion_timer_callback: waiting for engine finishing MV-CESA:mv_completion_timer_callback: waiting for engine finishing
Then the console was flooded by the "waiting for engine finshing" message and the boot can't finish.
I'll be happy to help to debug this. Just tell me how.
OK. IDMA bailing out was more or less expected, but the error path flooding the log makes me deserve the darwin award. ;)
I suspect address decoding to be the real problem here (kirkwood seems not to need any setup, so I completely skipped that), at least the IDMA interrupt cause points that out. OTOH I found out that CESA wasn't exactly configured as stated in the specs, so could you please test the attached diff? (Should also sanitise the error case a bit.)
In any case, thanks a lot for your time!
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
drivers/crypto/mv_cesa.c +11 -5
@@ -9,6 +9,7 @@#include <crypto/aes.h> #include <crypto/algapi.h> #include <linux/crypto.h> +#include <linux/delay.h> #include <linux/dma-mapping.h> #include <linux/dmapool.h> #include <linux/interrupt.h>
@@ -180,6 +181,7 @@ struct mv_req_hash_ctx {static void mv_completion_timer_callback (unsigned long unused) {int active =readl (cpg->reg +SEC_ACCEL_CMD ) &SEC_CMD_EN_SEC_ACCL0 ; +int count =5 ; printk(KERN_ERR MV_CESA "completion timer expired (CESA %sactive), cleaning up.\n",
@@ -187,8 +189,12 @@ static void mv_completion_timer_callback(unsigned long unused)del_timer (&cpg->completion_timer);writel (SEC_CMD_DISABLE_SEC , cpg->reg +SEC_ACCEL_CMD ); -while (readl (cpg->reg +SEC_ACCEL_CMD ) &SEC_CMD_DISABLE_SEC ) - printk(KERN_INFO MV_CESA "%s: waiting for engine finishing\n", __func__); +while ((readl (cpg->reg +SEC_ACCEL_CMD ) &SEC_CMD_DISABLE_SEC ) && count) { + printk(KERN_INFO MV_CESA "%s: waiting for engine finishing (%d)\n", + __func__, count--); +mdelay (1000 ); + } +BUG_ON (!count); cpg->eng_st =ENGINE_W_DEQUEUE ;wake_up_process (cpg->queue_th); }
@@ -1288,9 +1294,9 @@ static int mv_probe(struct platform_device *pdev)clk_prepare_enable (cp->clk);writel (0 , cpg->reg +SEC_ACCEL_INT_STATUS ); -writel (SEC_INT_ACC0_IDMA_DONE , cpg->reg +SEC_ACCEL_INT_MASK ); -writel ((SEC_CFG_STOP_DIG_ERR |SEC_CFG_CH0_W_IDMA |SEC_CFG_MP_CHAIN | -SEC_CFG_ACT_CH0_IDMA ), cpg->reg +SEC_ACCEL_CFG ); +writel (SEC_INT_ACC0_IDMA_DONE |SEC_INT_ACC1_IDMA_DONE , cpg->reg +SEC_ACCEL_INT_MASK ); +writel ((SEC_CFG_STOP_DIG_ERR |SEC_CFG_CH0_W_IDMA |SEC_CFG_CH1_W_IDMA |SEC_CFG_MP_CHAIN | +SEC_CFG_ACT_CH0_IDMA |SEC_CFG_ACT_CH1_IDMA ), cpg->reg +SEC_ACCEL_CFG );writel (SRAM_CONFIG , cpg->reg +SEC_ACCEL_DESC_P0 ); cp->sa_sram_dma = dma_map_single(&pdev->dev, &cp->sa_sram,
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
The CESA still didn't work as expected. But this time the machine managed to finish the boot.
...
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x80000010
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x79b4008
MV-DMA: tpg.reg + DMA_DST_ADDR = 0xf2200080
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x79b1010
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x79b1000
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0 MV-CESA:got an interrupt but no pending timer?
alg: skcipher: Test 1 failed on encryption for mv-ecb-aes
00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
...
MV-CESA:completion timer expired (CESA active), cleaning up. MV-CESA:mv_completion_timer_callback: waiting for engine finishing (5) MV-CESA:mv_completion_timer_callback: waiting for engine finishing (4) MV-CESA:mv_completion_timer_callback: waiting for engine finishing (3) MV-CESA:mv_completion_timer_callback: waiting for engine finishing (2) MV-CESA:mv_completion_timer_callback: waiting for engine finishing (1)
alg: hash: Test 1 failed for mv-sha1
00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000010: 00 00 00 00
ata2: SATA link down (SStatus 0 SControl 300) MV-CESA:completion timer expired (CESA active), cleaning up. MV-CESA:mv_completion_timer_callback: waiting for engine finishing (5) MV-CESA:mv_completion_timer_callback: waiting for engine finishing (4) MV-CESA:mv_completion_timer_callback: waiting for engine finishing (3) MV-CESA:mv_completion_timer_callback: waiting for engine finishing (2) MV-CESA:mv_completion_timer_callback: waiting for engine finishing (1)
alg: hash: Test 1 failed for mv-hmac-sha1
00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000010: 00 00 00 00
...
Regards
Cloudy
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
In reply to Simon BaatzHi Phil
Quoted 3 lines · Simon Baatz
I see one effect that I don't fully understand. Similar to the previous implementation, the system is mostly in kernel space when accessing an encrypted dm-crypt device:
Today I also compiled the patched 3.5.0-rc3 for another NAS box with MV88F6282-Rev-A0 (LS-WVL), I noticed one thing that when the CESA engine was used, the interrupt number of mv_crypto kept rising, but the interrupt number of mv_tdma was always zero.
$ cat /proc/interrupts
CPU0
1: 31296 orion_irq orion_tick
5: 2 orion_irq mv_xor.0
6: 2 orion_irq mv_xor.1
7: 2 orion_irq mv_xor.2
8: 2 orion_irq mv_xor.3
11: 23763 orion_irq eth0
19: 0 orion_irq ehci_hcd:usb1
21: 4696 orion_irq sata_mv
22: 64907 orion_irq mv_crypto
33: 432 orion_irq serial
46: 51 orion_irq mv643xx_eth
49: 0 orion_irq mv_tdma
53: 0 orion_irq rtc-mv
107: 0 - GPIO fan alarm
109: 0 - function
110: 0 - power-on
111: 0 - power-auto
Err: 0Is this normal?
Regards
Cloudy
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi Cloudy,
Quoted 9 lines · cloudy.linux
Quoted 3 lines · Simon Baatz
I see one effect that I don't fully understand. Similar to the previous implementation, the system is mostly in kernel space when accessing an encrypted dm-crypt device:
Today I also compiled the patched 3.5.0-rc3 for another NAS box with MV88F6282-Rev-A0 (LS-WVL), I noticed one thing that when the CESA engine was used, the interrupt number of
mv_cryptokept rising, but the interrupt number ofmv_tdmawas always zero.
Yes, that is exactly how it should be: the DMA engine is configured to run "attached" to CESA, meaning that when CESA is triggered from mv_cesa.c, it first enables the DMA engine. Using a special descriptor in the chain, the DMA engine knows when to stop and signals CESA again so it can start the crypto operation. Afterwards, CESA triggers the DMA engine again for copying back the results (or more specific: process the remaining descriptors in the chain after the special one). After a descriptor with it's next descriptor field being zero has been handled, CESA is signaled again which in turn generates the interrupt to signal the software. So no DMA interrupt needed, and no software interaction in between data copying and crypto operation, of course. :)
Greetings, Phil
PS: I am currently working at the address decoding problem, will get back to in a few days when I have something to test. So stay tuned!
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi,
Quoted 2 lines · Phil Sutter
PS: I am currently working at the address decoding problem, will get back to in a few days when I have something to test. So stay tuned!
I have updated the cesa-dma branch at git://nwl.cc/~n0-1/linux.git with code setting the decoding windows. I hope this fixes the issues on orion. I decided not to publish the changes regarding the second DMA channel for now, as this seems to be support for a second crypto session (handled consecutively, so no real improvement) which is not supported anyway.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Quoted 13 lines · Phil Sutter
Hi,
Quoted 2 lines · Phil Sutter
PS: I am currently working at the address decoding problem, will get back to in a few days when I have something to test. So stay tuned!
I have updated the cesa-dma branch at
git://nwl.cc/~n0-1/linux.gitwith code setting the decoding windows. I hope this fixes the issues on orion. I decided not to publish the changes regarding the second DMA channel for now, as this seems to be support for a second crypto session (handled consecutively, so no real improvement) which is not supported anyway.
Quoted 6 lines
Greetings, Phil
Phil Sutter
Software Engineer
Thanks Phil. I'm cloning your git now but the speed is really slow. Last time I tried to do this but had to cancel after hours of downloading (at only about 20% progress). So the previous tests were actually done with 3.5-rc3 (I tried the up-to-date Linus' linux-git, but met compiling problem), of course with your patch and Simon's. Could you provide a diff based on your last round patch (diff to the not patched kernel should also be good, I think)?
In the mean time, I'm still trying with a cloning speed of 5KiB/s ...
Regards
Cloudy
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi,
Quoted 29 lines · cloudy.linux
Quoted 13 lines · Phil Sutter
Hi,
Quoted 2 lines · Phil Sutter
PS: I am currently working at the address decoding problem, will get back to in a few days when I have something to test. So stay tuned!
I have updated the cesa-dma branch at
git://nwl.cc/~n0-1/linux.gitwith code setting the decoding windows. I hope this fixes the issues on orion. I decided not to publish the changes regarding the second DMA channel for now, as this seems to be support for a second crypto session (handled consecutively, so no real improvement) which is not supported anyway.Quoted 6 lines
Greetings, Phil
Phil Sutter
Software EngineerThanks Phil. I'm cloning your git now but the speed is really slow. Last time I tried to do this but had to cancel after hours of downloading (at only about 20% progress). So the previous tests were actually done with 3.5-rc3 (I tried the up-to-date Linus' linux-git, but met compiling problem), of course with your patch and Simon's. Could you provide a diff based on your last round patch (diff to the not patched kernel should also be good, I think)?
Quoted 1 line
In the mean time, I'm still trying with a cloning speed of 5KiB/s ...
Ugh, that's horrible. No idea what's going wrong there, and no access to the management interface right now. In the mean time, please refer to the attached patch. It bases on 94fa83c in linus' git but should cleanly apply to it's current HEAD, too.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
arch/arm/mach-kirkwood/common.c +34 -0
@@ -232,6 +232,7 @@ void __init kirkwood_clk_init(void)orion_clkdev_add (NULL ,"orion-ehci.0" , usb0);orion_clkdev_add (NULL ,"orion_nand" , runit);orion_clkdev_add (NULL ,"mvsdio" , sdio); +orion_clkdev_add (NULL ,"mv_tdma" , crypto);orion_clkdev_add (NULL ,"mv_crypto" , crypto);orion_clkdev_add (NULL ,MV_XOR_SHARED_NAME ".0" , xor0);orion_clkdev_add (NULL ,MV_XOR_SHARED_NAME ".1" , xor1);
@@ -426,8 +427,41 @@ void __init kirkwood_uart1_init(void)/***************************************************************************** * Cryptographic Engines and Security Accelerator (CESA) ****************************************************************************/ +static struct resource kirkwood_tdma_res[] = { + { + .name ="regs deco" , + .start =CRYPTO_PHYS_BASE +0xA00 , + .end =CRYPTO_PHYS_BASE +0xA24 , + .flags =IORESOURCE_MEM , + }, { + .name ="regs control and error" , + .start =CRYPTO_PHYS_BASE +0x800 , + .end =CRYPTO_PHYS_BASE +0x8CF , + .flags =IORESOURCE_MEM , + }, { + .name ="crypto error" , + .start =IRQ_KIRKWOOD_TDMA_ERR , + .end =IRQ_KIRKWOOD_TDMA_ERR , + .flags =IORESOURCE_IRQ , + }, +}; + +static u64 mv_tdma_dma_mask =DMA_BIT_MASK (32 ); + +static struct platform_device kirkwood_tdma_device = { + .name ="mv_tdma" , + .id =-1 , + .dev = { + .dma_mask = &mv_tdma_dma_mask, + .coherent_dma_mask =DMA_BIT_MASK (32 ), + }, + .num_resources =ARRAY_SIZE (kirkwood_tdma_res), + .resource = kirkwood_tdma_res, +}; +void __init kirkwood_crypto_init (void ) { +platform_device_register (&kirkwood_tdma_device);orion_crypto_init (CRYPTO_PHYS_BASE ,KIRKWOOD_SRAM_PHYS_BASE ,KIRKWOOD_SRAM_SIZE ,IRQ_KIRKWOOD_CRYPTO ); }
arch/arm/mach-kirkwood/include/mach/irqs.h +1 -0
@@ -51,6 +51,7 @@#define IRQ_KIRKWOOD_GPIO_HIGH_16_23 41#define IRQ_KIRKWOOD_GE00_ERR 46#define IRQ_KIRKWOOD_GE01_ERR 47 +#define IRQ_KIRKWOOD_TDMA_ERR 49#define IRQ_KIRKWOOD_RTC 53/*
arch/arm/mach-orion5x/common.c +40 -0
@@ -181,9 +181,49 @@ void __init orion5x_xor_init(void)/***************************************************************************** * Cryptographic Engines and Security Accelerator (CESA) ****************************************************************************/ +static struct resource orion_idma_res[] = { + { + .name ="regs deco" , + .start =ORION5X_IDMA_PHYS_BASE +0xA00 , + .end =ORION5X_IDMA_PHYS_BASE +0xA24 , + .flags =IORESOURCE_MEM , + }, { + .name ="regs control and error" , + .start =ORION5X_IDMA_PHYS_BASE +0x800 , + .end =ORION5X_IDMA_PHYS_BASE +0x8CF , + .flags =IORESOURCE_MEM , + }, { + .name ="crypto error" , + .start =IRQ_ORION5X_IDMA_ERR , + .end =IRQ_ORION5X_IDMA_ERR , + .flags =IORESOURCE_IRQ , + }, +}; + +static u64 mv_idma_dma_mask =DMA_BIT_MASK (32 ); + +static struct mv_dma_pdata mv_idma_pdata = { + .sram_target_id =TARGET_SRAM , + .sram_attr =0 , + .sram_base =ORION5X_SRAM_PHYS_BASE , +}; + +static struct platform_device orion_idma_device = { + .name ="mv_idma" , + .id =-1 , + .dev = { + .dma_mask = &mv_idma_dma_mask, + .coherent_dma_mask =DMA_BIT_MASK (32 ), + .platform_data = &mv_idma_pdata, + }, + .num_resources =ARRAY_SIZE (orion_idma_res), + .resource = orion_idma_res, +}; +static void __init orion5x_crypto_init (void ) {orion5x_setup_sram_win (); +platform_device_register (&orion_idma_device);orion_crypto_init (ORION5X_CRYPTO_PHYS_BASE ,ORION5X_SRAM_PHYS_BASE ,SZ_8K ,IRQ_ORION5X_CESA ); }
arch/arm/mach-orion5x/include/mach/orion5x.h +2 -0
@@ -90,6 +90,8 @@#define ORION5X_USB0_PHYS_BASE (ORION5X_REGS_PHYS_BASE | 0x50000)#define ORION5X_USB0_VIRT_BASE (ORION5X_REGS_VIRT_BASE | 0x50000) +#define ORION5X_IDMA_PHYS_BASE (ORION5X_REGS_PHYS_BASE | 0x60000) +#define ORION5X_XOR_PHYS_BASE (ORION5X_REGS_PHYS_BASE | 0x60900)#define ORION5X_XOR_VIRT_BASE (ORION5X_REGS_VIRT_BASE | 0x60900)
arch/arm/plat-orion/common.c +6 -0
@@ -924,9 +924,15 @@ static struct resource orion_crypto_resources[] = { }, }; +static u64 mv_crypto_dmamask =DMA_BIT_MASK (32 ); +static struct platform_device orion_crypto = { .name ="mv_crypto" , .id =-1 , + .dev = { + .dma_mask = &mv_crypto_dmamask, + .coherent_dma_mask =DMA_BIT_MASK (32 ), + }, }; void __init orion_crypto_init(unsigned long mapbase,
arch/arm/plat-orion/include/plat/mv_dma.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* arch/arm/plat-orion/include/plat/mv_dma.h +* +* Marvell IDMA/TDMA platform device data definition file. +*/ +#ifndef __PLAT_MV_DMA_H +#define __PLAT_MV_DMA_H + +struct mv_dma_pdata { +unsigned int sram_target_id; +unsigned int sram_attr; +unsigned int sram_base; +}; + +#endif /* __PLAT_MV_DMA_H */
drivers/crypto/Kconfig +5 -0
@@ -159,6 +159,10 @@ config CRYPTO_GHASH_S390 It is available as of z196. +config CRYPTO_DEV_MV_DMA + tristate + default no + config CRYPTO_DEV_MV_CESA tristate "Marvell's Cryptographic Engine" depends on PLAT_ORION
@@ -166,6 +170,7 @@ config CRYPTO_DEV_MV_CESA select CRYPTO_AES select CRYPTO_BLKCIPHER2 select CRYPTO_HASH + select CRYPTO_DEV_MV_DMA help This driver allows you to utilize the Cryptographic Engines and Security Accelerator (CESA) which can be found on the Marvell Orion
drivers/crypto/Makefile +2 -1
@@ -4,6 +4,7 @@ obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o obj-$(CONFIG_CRYPTO_DEV_NIAGARA2) += n2_crypto.o n2_crypto-y := n2_core.o n2_asm.o obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o +obj-$(CONFIG_CRYPTO_DEV_MV_DMA) += mv_dma.o obj-$(CONFIG_CRYPTO_DEV_MV_CESA) += mv_cesa.o obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM) += caam/
@@ -14,4 +15,4 @@ obj-$(CONFIG_CRYPTO_DEV_OMAP_AES) += omap-aes.o obj-$(CONFIG_CRYPTO_DEV_PICOXCELL) += picoxcell_crypto.o obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o obj-$(CONFIG_CRYPTO_DEV_TEGRA_AES) += tegra-aes.o -obj-$(CONFIG_CRYPTO_DEV_UX500) += ux500/ +obj-$(CONFIG_CRYPTO_DEV_UX500) += ux500/
drivers/crypto/dma_desclist.h new file +79 -0
79 lines not on this page · raw message
drivers/crypto/mv_cesa.c +419 -164
872 lines not on this page · raw message
drivers/crypto/mv_cesa.h +1 -0
@@ -24,6 +24,7 @@#define SEC_CFG_CH1_W_IDMA (1 << 8)#define SEC_CFG_ACT_CH0_IDMA (1 << 9)#define SEC_CFG_ACT_CH1_IDMA (1 << 10) +#define SEC_CFG_MP_CHAIN (1 << 11)#define SEC_ACCEL_STATUS 0xde0c#define SEC_ST_ACT_0 (1 << 0)
drivers/crypto/mv_dma.c new file +520 -0
520 lines not on this page · raw message
drivers/crypto/mv_dma.h new file +150 -0
150 lines not on this page · raw message
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
In reply to cloudy.linuxQuoted 29 lines · cloudy.linux
Quoted 13 lines · Phil Sutter
Hi,
Quoted 2 lines · Phil Sutter
PS: I am currently working at the address decoding problem, will get back to in a few days when I have something to test. So stay tuned!
I have updated the cesa-dma branch at
git://nwl.cc/~n0-1/linux.gitwith code setting the decoding windows. I hope this fixes the issues on orion. I decided not to publish the changes regarding the second DMA channel for now, as this seems to be support for a second crypto session (handled consecutively, so no real improvement) which is not supported anyway.Quoted 6 lines
Greetings, Phil
Phil Sutter
Software EngineerThanks Phil. I'm cloning your git now but the speed is really slow. Last time I tried to do this but had to cancel after hours of downloading (at only about 20% progress). So the previous tests were actually done with 3.5-rc3 (I tried the up-to-date Linus' linux-git, but met compiling problem), of course with your patch and Simon's. Could you provide a diff based on your last round patch (diff to the not patched kernel should also be good, I think)?
Quoted 4 lines
In the mean time, I'm still trying with a cloning speed of 5KiB/s ...
Regards
Cloudy
Hi Phil
This time the machine can't finish the boot again and the console was flooded by the message like below:
...
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x79b1000
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0 MV-CESA:got an interrupt but no pending timer?
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0 MV-CESA:got an interrupt but no pending timer?
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0 MV-CESA:got an interrupt but no pending timer?
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0
Also, I had to make some modifications to the arch/arm/mach-orion5x/common.c to let it compile successfully:
1 Add including of mv_dma.h
2 Add macro to define TARGET_SRAM as 9 (which is defined in addr-map.c, so I think the clean solution should be modify the addr-map.h? Anyway, as a quick solution the source finally got compiled)
Regards
Cloudy
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi,
Quoted 2 lines · cloudy.linux
This time the machine can't finish the boot again and the console was flooded by the message like below:
Oh well. I decided to drop that BUG_ON() again, since I saw it once being triggered while in interrupt context. But since the error is non-recovering anyway, I guess it may stay there as well.
Quoted 6 lines
Also, I had to make some modifications to the
arch/arm/mach-orion5x/common.cto let it compile successfully:
1 Add including ofmv_dma.h
2 Add macro to defineTARGET_SRAMas 9 (which is defined inaddr-map.c, so I think the clean solution should be modify theaddr-map.h? Anyway, as a quick solution the source finally got compiled)
Hmm, yeah. Test-compiling for the platform one is writing code for is still a good idea. But it's even worse than that: according to the specs, for IDMA the SRAM target ID is 5, not 9 like it is for the CPU.
Please apply the attached patch on top of the one I sent earlier, without your modifications (the necessary parts are contained in it). Also, I've added some log output to the decode window setter, so we see what's going on there.
Anyway, thanks a lot for your help so far! I hope next try shows some progress at least.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 15 lines
Viprinet GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Phone/Zentrale: +49-6721-49030-0 Direct line/Durchwahl: +49-6721-49030-134 Fax: +49-6721-49030-209 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein Commercial register/Handelsregister: Amtsgericht Mainz HRB40380 CEO/Geschäftsführer: Simon Kissel
arch/arm/mach-orion5x/common.c +2 -1
@@ -35,6 +35,7 @@#include <plat/time.h> #include <plat/common.h> #include <plat/addr-map.h> +#include <plat/mv_dma.h> #include "common.h" /*****************************************************************************
@@ -203,7 +204,7 @@ static struct resource orion_idma_res[] = {static u64 mv_idma_dma_mask =DMA_BIT_MASK (32 );static struct mv_dma_pdata mv_idma_pdata = { - .sram_target_id =TARGET_SRAM , + .sram_target_id =5 , .sram_attr =0 , .sram_base =ORION5X_SRAM_PHYS_BASE , };
drivers/crypto/mv_cesa.c +1 -0
@@ -195,6 +195,7 @@ static void mv_completion_timer_callback(unsigned long unused)if (count <0 ) { printk(KERN_ERR MV_CESA "%s: engine reset timed out!\n", __func__); +BUG (); } cpg->eng_st =ENGINE_W_DEQUEUE ;wake_up_process (cpg->queue_th);
drivers/crypto/mv_dma.c +4 -0
@@ -318,6 +318,8 @@ static void setup_mbus_windows(void __iomem *regs, struct mv_dma_pdata *pdata,for (chan =0 ; chan < dram->num_cs; chan++) {const struct mbus_dram_window *cs = &dram->cs[chan]; + printk(KERN_INFO MV_DMA "window at bar%d: target %d, attr %d, base %x, size %x\n", + chan, dram->mbus_dram_target_id, cs->mbus_attr, cs->base, cs->size); (*win_setter)(regs, chan, dram->mbus_dram_target_id, cs->mbus_attr, cs->base, cs->size); }
@@ -330,6 +332,8 @@ static void setup_mbus_windows(void __iomem *regs, struct mv_dma_pdata *pdata,* Size is in 64k granularity, max SRAM size is 8k - * so a single "unit" easily suffices. */ + printk(KERN_INFO MV_DMA "window at bar%d: target %d, attr %d, base %x, size %x\n", + chan, pdata->sram_target_id, pdata->sram_attr, pdata->sram_base, 1 << 16); (*win_setter)(regs, chan, pdata->sram_target_id, pdata->sram_attr, pdata->sram_base,1 <<16 ); }
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Quoted 26 lines · Phil Sutter
Hi,
Quoted 2 lines · cloudy.linux
This time the machine can't finish the boot again and the console was flooded by the message like below:
Oh well. I decided to drop that
BUG_ON()again, since I saw it once being triggered while in interrupt context. But since the error is non-recovering anyway, I guess it may stay there as well.Quoted 6 lines
Also, I had to make some modifications to the
arch/arm/mach-orion5x/common.cto let it compile successfully:
1 Add including ofmv_dma.h
2 Add macro to defineTARGET_SRAMas 9 (which is defined inaddr-map.c, so I think the clean solution should be modify theaddr-map.h? Anyway, as a quick solution the source finally got compiled)Hmm, yeah. Test-compiling for the platform one is writing code for is still a good idea. But it's even worse than that: according to the specs, for IDMA the SRAM target ID is 5, not 9 like it is for the CPU.
Please apply the attached patch on top of the one I sent earlier, without your modifications (the necessary parts are contained in it). Also, I've added some log output to the decode window setter, so we see what's going on there.
Quoted 9 lines
Anyway, thanks a lot for your help so far! I hope next try shows some progress at least.
Greetings, Phil
Phil Sutter
Software Engineer
Kernel message after applying the latest patch:
MV-DMA: window at bar0: target 0, attr 14, base 0, size 8000000
MV-DMA: window at bar1: target 5, attr 0, base f2200000, size 10000
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x79b1000
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0 MV-CESA:got an interrupt but no pending timer?
------------[ cut here ]------------ kernel BUG at drivers/crypto/mv_cesa.c:1126! Internal error: Oops - BUG: 0 [#1] ARM Modules linked in: CPU: 0 Not tainted (3.5.0-rc4+ #2) pc : [<c01dfcd0>] lr : [<c0015c20>] psr: 20000093
sp : c79b9e58 ip : c79b9da8 fp : c79b9e6c
r10: c02f4184 r9 : c0308342 r8 : 0000001c
r7 : 00000000 r6 : 00000000 r5 : c03149a4 r4 : 00000002 r3 : c799c200 r2 : 0000de20 r1 : fdd90000 r0 : fdd90000
Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment kernel
Control: a005317f Table: 00004000 DAC: 00000017
Process mv_crypto (pid: 276, stack limit = 0xc79b8270)
Stack: (0xc79b9e58 to 0xc79ba000)
9e40: c79afc40 0000001c
9e60: c79b9ea4 c79b9e70 c0047aa8 c01dfc48 c788929c 4bfb2bc9 00000000 c02f4184 9e80: 0000001c 00000000 c79b9f4c c79bbe18 c02eec18 c02f10a0 c79b9ebc c79b9ea8 9ea0: c0047c58 c0047a64 00022000 c02f4184 c79b9ed4 c79b9ec0 c0049f60 c0047c38 9ec0: c0049ed8 c0301758 c79b9ee4 c79b9ed8 c00473e4 c0049ee8 c79b9f04 c79b9ee8 9ee0: c000985c c00473c4 c01debf4 c025dfdc a0000013 fdd20200 c79b9f14 c79b9f08 9f00: c0008170 c0009834 c79b9f6c c79b9f18 c0008c14 c0008170 00000000 00000001 9f20: c79b9f60 c78897a0 c03149a4 c799c200 c7936cc0 c79ac780 c79bbe18 c02eec18 9f40: c02f10a0 c79b9f6c c79b9f70 c79b9f60 c01debf4 c025dfdc a0000013 ffffffff 9f60: c79b9fbc c79b9f70 c01debf4 c025dfd0 00000000 c79b9f80 c025dd54 c0035418 9f80: c78897a0 c7827de8 c79b8000 c02eec18 00000013 c7827de8 c799c200 c01dea10 9fa0: 00000013 00000000 00000000 00000000 c79b9ff4 c79b9fc0 c002de90 c01dea20 9fc0: c7827de8 00000000 c799c200 00000000 c79b9fd0 c79b9fd0 00000000 c7827de8 9fe0: c002de00 c001877c 00000000 c79b9ff8 c001877c c002de10 01e6e7fe 01e6e7ff
Backtrace:
Function entered at [<c01dfc38>] from [<c0047aa8>]
r5:0000001c r4:c79afc40
Function entered at [<c0047a54>] from [<c0047c58>] Function entered at [<c0047c28>] from [<c0049f60>]
r4:c02f4184 r3:00022000
Function entered at [<c0049ed8>] from [<c00473e4>]
r4:c0301758 r3:c0049ed8
Function entered at [<c00473b4>] from [<c000985c>] Function entered at [<c0009824>] from [<c0008170>]
r6:fdd20200 r5:a0000013 r4:c025dfdc r3:c01debf4
Function entered at [<c0008160>] from [<c0008c14>]
Exception stack(0xc79b9f18 to 0xc79b9f60)
9f00: 00000000 00000001
9f20: c79b9f60 c78897a0 c03149a4 c799c200 c7936cc0 c79ac780 c79bbe18 c02eec18 9f40: c02f10a0 c79b9f6c c79b9f70 c79b9f60 c01debf4 c025dfdc a0000013 ffffffff Function entered at [<c025dfc0>] from [<c01debf4>]
Function entered at [<c01dea10>] from [<c002de90>]
Function entered at [<c002de00>] from [<c001877c>]
r6:c001877c r5:c002de00 r4:c7827de8
Code: e89da830 e59f000c eb01ec50 eaffffe9 (e7f001f2)
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0
cover MV_CESA with DMA: Clk init fixes
In reply to Phil SutterHi Phil,
I just found the time to test your updates. Alas, the mv_dma module hangs at boot again. The culprit seems to be setup_mbus_windows(), which is called before the clock is turned on but accesses the DMA engine.
I shifted the clock init code a bit and while doing so, fixed some error case handling for mv_dma and mv_cesa. See proposed patch in next mail.
- Simon
Simon Baatz (1):
mv_dma: mv_cesa: fixes for clock init
drivers/crypto/mv_cesa.c | 7 ++++++- drivers/crypto/mv_dma.c | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/1 mv_dma: mv_cesa: fixes for clock init
mv_dma tries to access CESA engine registers before the CESA clock is enabled. Shift the clock enable code to the proper position.
Additionally, both mv_dma and mv_cesa did not disable the clock if something went wrong during init.
--- drivers/crypto/mv_cesa.c | 7 ++++++- drivers/crypto/mv_dma.c | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 16 deletions(-)
drivers/crypto/mv_cesa.c +6 -1
@@ -1308,7 +1308,8 @@ static int mv_probe(struct platform_device *pdev) ret = -ENOMEM ; goto err_mapping; } -if (set_dma_desclist_size (&cpg->desclist,MV_DMA_INIT_POOLSIZE )) { + ret =set_dma_desclist_size (&cpg->desclist,MV_DMA_INIT_POOLSIZE ); +if (ret) { printk(KERN_ERR MV_CESA "failed to initialise poolsize\n"); goto err_pool; }
@@ -1350,6 +1351,10 @@ err_mapping:dma_unmap_single (&pdev->dev, cpg->sa_sram_dma,sizeof (struct sec_accel_sram ),DMA_TO_DEVICE );free_irq (irq, cp); +if (!IS_ERR (cp->clk)) { +clk_disable_unprepare (cp->clk); +clk_put (cp->clk); + } err_thread:kthread_stop (cp->queue_th); err_unmap_sram:
drivers/crypto/mv_dma.c +29 -15
74 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
In reply to Phil SutterHi Phil
Although I had no idea about what's wrong, I looked in the functional errata (again), And I found what's attached (The doc I got from Internet was a protected PDF, that's why I had to use screen capture). Is this relevant? Or maybe you have already addressed this in the code (I can just read some simple C code)?
Regards
Cloudy
Quoted 35 lines · Phil Sutter
Hi,
Quoted 2 lines · cloudy.linux
This time the machine can't finish the boot again and the console was flooded by the message like below:
Oh well. I decided to drop that
BUG_ON()again, since I saw it once being triggered while in interrupt context. But since the error is non-recovering anyway, I guess it may stay there as well.Quoted 6 lines
Also, I had to make some modifications to the
arch/arm/mach-orion5x/common.cto let it compile successfully:
1 Add including ofmv_dma.h
2 Add macro to defineTARGET_SRAMas 9 (which is defined inaddr-map.c, so I think the clean solution should be modify theaddr-map.h? Anyway, as a quick solution the source finally got compiled)Hmm, yeah. Test-compiling for the platform one is writing code for is still a good idea. But it's even worse than that: according to the specs, for IDMA the SRAM target ID is 5, not 9 like it is for the CPU.
Please apply the attached patch on top of the one I sent earlier, without your modifications (the necessary parts are contained in it). Also, I've added some log output to the decode window setter, so we see what's going on there.
Anyway, thanks a lot for your help so far! I hope next try shows some progress at least.
Greetings, Phil
Phil Sutter
Software Engineer
Phil Sutter
AppliedRe: [PATCH 0/1] MV_CESA with DMA: Clk init fixes
In reply to Simon BaatzHi Simon,
Quoted 7 lines · Simon Baatz
I just found the time to test your updates. Alas, the
mv_dmamodule hangs at boot again. The culprit seems to besetup_mbus_windows(), which is called before the clock is turned on but accesses the DMA engine.I shifted the clock init code a bit and while doing so, fixed some error case handling for
mv_dmaandmv_cesa. See proposed patch in next mail.
I applied that to my public git, thanks a lot!
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 20 lines
VNet Europe GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Management Buy-Out at Viprinet - please read http://www.viprinet.com/en/mbo Management Buy-Out bei Viprinet - bitte lesen Sie http://www.viprinet.com/de/mbo Phone/Zentrale: +49 6721 49030-0 Direct line/Durchwahl: +49 6721 49030-134 Fax: +49 6721 49030-109 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein, Germany Commercial register/Handelsregister: Amtsgericht Mainz HRB44090 CEO/Geschäftsführer: Simon Kissel
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
In reply to cloudy.linuxHi Cloudy,
Quoted 5 lines · cloudy.linux
Although I had no idea about what's wrong, I looked in the functional errata (again), And I found what's attached (The doc I got from Internet was a protected PDF, that's why I had to use screen capture). Is this relevant? Or maybe you have already addressed this in the code (I can just read some simple C code)?
To me, doesn't read like a real problem, just a guideline for doing things. From the output you sent me in your previous mail, I'd rather suspect fetching the first descriptor to be faulty: the next descriptor pointer contains the first descriptor's DMA address, all other fields are zero (this is the situation when triggering the engine, as on kirkwood all I have to do is fill the first descriptor's address in and TDMA does the rest) and IDMA triggers an address miss interrupt at address 0x0. So probably IDMA starts up and tries to look up decoding windows for he up the still zero source and destination addresses.
According to the specs, when using the next descriptor field for fetching the first descriptor one also has to set the FETCH_ND field in DMA_CTRL register, also for TDMA. Though, on my hardware the only working configuration is the implemented one, i.e. without FETCH_ND being set.
I have implemented a separate approach just for IDMA, which instead of just writing the first descriptor's address to NEXT_DESC does:
1. clear CTRL_ENABLE bit
2. fill NEXT_DESC
3. set CTRL_ENABLE along with FETCH_ND
hopefully this is the way to go on Orion. Since Marvell's BSP doesn't implement *DMA attached to CESA, I have nowhere to look this up. Getting it right for TDMA was just a matter of trial and error.
My public git got a few updates, including the code described above. Would be great if you could give it a try.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 20 lines
VNet Europe GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Management Buy-Out at Viprinet - please read http://www.viprinet.com/en/mbo Management Buy-Out bei Viprinet - bitte lesen Sie http://www.viprinet.com/de/mbo Phone/Zentrale: +49 6721 49030-0 Direct line/Durchwahl: +49 6721 49030-134 Fax: +49 6721 49030-109 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein, Germany Commercial register/Handelsregister: Amtsgericht Mainz HRB44090 CEO/Geschäftsführer: Simon Kissel
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Quoted 37 lines · Phil Sutter
Hi Cloudy,
Quoted 5 lines · cloudy.linux
Although I had no idea about what's wrong, I looked in the functional errata (again), And I found what's attached (The doc I got from Internet was a protected PDF, that's why I had to use screen capture). Is this relevant? Or maybe you have already addressed this in the code (I can just read some simple C code)?
To me, doesn't read like a real problem, just a guideline for doing things. From the output you sent me in your previous mail, I'd rather suspect fetching the first descriptor to be faulty: the next descriptor pointer contains the first descriptor's DMA address, all other fields are zero (this is the situation when triggering the engine, as on kirkwood all I have to do is fill the first descriptor's address in and TDMA does the rest) and IDMA triggers an address miss interrupt at address
0x0. So probably IDMA starts up and tries to look up decoding windows for he up the still zero source and destination addresses.According to the specs, when using the next descriptor field for fetching the first descriptor one also has to set the
FETCH_NDfield inDMA_CTRLregister, also for TDMA. Though, on my hardware the only working configuration is the implemented one, i.e. withoutFETCH_NDbeing set.I have implemented a separate approach just for IDMA, which instead of just writing the first descriptor's address to
NEXT_DESCdoes:
1. clearCTRL_ENABLEbit
2. fillNEXT_DESC
3. setCTRL_ENABLEalong withFETCH_ND
hopefully this is the way to go on Orion. Since Marvell's BSP doesn't implement *DMA attached to CESA, I have nowhere to look this up. Getting it right for TDMA was just a matter of trial and error.My public git got a few updates, including the code described above. Would be great if you could give it a try.
Quoted 7 lines
Greetings, Phil
Phil Sutter
Software Engineer
Hi
Newest result. Still couldn't boot up. This time the source was cloned from your git repository.
MV-DMA: window at bar0: target 0, attr 14, base 0, size 8000000
MV-DMA: window at bar1: target 5, attr 0, base f2200000, size 10000
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x79b1000
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0 MV-CESA:got an interrupt but no pending timer?
------------[ cut here ]------------ kernel BUG at drivers/crypto/mv_cesa.c:1126! Internal error: Oops - BUG: 0 [#1] ARM Modules linked in: CPU: 0 Not tainted (3.5.0-rc2+ #3) pc : [<c01df8e0>] lr : [<c0015810>] psr: 20000093
sp : c79b9e58 ip : c79b9da8 fp : c79b9e6c
r10: c02f2164 r9 : c0306322 r8 : 0000001c
r7 : 00000000 r6 : 00000000 r5 : c0312988 r4 : 00000002 r3 : c799c200 r2 : 0000de20 r1 : fdd90000 r0 : fdd90000
Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment kernel
Control: a005317f Table: 00004000 DAC: 00000017
Process mv_crypto (pid: 276, stack limit = 0xc79b8270)
Stack: (0xc79b9e58 to 0xc79ba000)
9e40: c79afc40 0000001c
9e60: c79b9ea4 c79b9e70 c0047694 c01df858 c788929c 4bf287d9 00000000 c02f2164 9e80: 0000001c 00000000 c79b9f4c c79bbe18 c02ecc18 c02ef0a0 c79b9ebc c79b9ea8 9ea0: c0047844 c0047650 00022000 c02f2164 c79b9ed4 c79b9ec0 c0049b4c c0047824 9ec0: c0049ac4 c02ff738 c79b9ee4 c79b9ed8 c0046fd0 c0049ad4 c79b9f04 c79b9ee8 9ee0: c000985c c0046fb0 c01de804 c025db80 a0000013 fdd20200 c79b9f14 c79b9f08 9f00: c0008170 c0009834 c79b9f6c c79b9f18 c0008c14 c0008170 00000000 00000001 9f20: c79b9f60 0000de00 c0312988 c799c200 c7936cc0 c79ac780 c79bbe18 c02ecc18 9f40: c02ef0a0 c79b9f6c c79b9f70 c79b9f60 c01de804 c025db80 a0000013 ffffffff 9f60: c79b9fbc c79b9f70 c01de804 c025db80 00000000 c79b9f80 c025d904 c0035000 9f80: c78897a0 c7827de8 c79b8000 c02ecc18 00000013 c7827de8 c799c200 c01de620 9fa0: 00000013 00000000 00000000 00000000 c79b9ff4 c79b9fc0 c002da78 c01de630 9fc0: c7827de8 00000000 c799c200 00000000 c79b9fd0 c79b9fd0 00000000 c7827de8 9fe0: c002d9e8 c0018354 00000000 c79b9ff8 c0018354 c002d9f8 01e6e7fe 01e6e7ff
Backtrace:
Function entered at [<c01df848>] from [<c0047694>]
r5:0000001c r4:c79afc40
Function entered at [<c0047640>] from [<c0047844>] Function entered at [<c0047814>] from [<c0049b4c>]
r4:c02f2164 r3:00022000
Function entered at [<c0049ac4>] from [<c0046fd0>]
r4:c02ff738 r3:c0049ac4
Function entered at [<c0046fa0>] from [<c000985c>] Function entered at [<c0009824>] from [<c0008170>]
r6:fdd20200 r5:a0000013 r4:c025db80 r3:c01de804
Function entered at [<c0008160>] from [<c0008c14>]
Exception stack(0xc79b9f18 to 0xc79b9f60)
9f00: 00000000 00000001
9f20: c79b9f60 0000de00 c0312988 c799c200 c7936cc0 c79ac780 c79bbe18 c02ecc18 9f40: c02ef0a0 c79b9f6c c79b9f70 c79b9f60 c01de804 c025db80 a0000013 ffffffff Function entered at [<c025db70>] from [<c01de804>]
Function entered at [<c01de620>] from [<c002da78>]
Function entered at [<c002d9e8>] from [<c0018354>]
r6:c0018354 r5:c002d9e8 r4:c7827de8
Code: e89da830 e59f000c eb01ec39 eaffffe9 (e7f001f2)
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0
Regards
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi,
Quoted 15 lines · cloudy.linux
Newest result. Still couldn't boot up. This time the source was cloned from your git repository.
MV-DMA: window at bar0: target 0, attr 14, base 0, size 8000000
MV-DMA: window at bar1: target 5, attr 0, basef2200000, size 10000
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA:idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg +DMA_CTRL=0x80001d04
MV-DMA: tpg.reg +DMA_BYTE_COUNT=0x0
MV-DMA: tpg.reg +DMA_SRC_ADDR=0x0
MV-DMA: tpg.reg +DMA_DST_ADDR=0x0
MV-DMA: tpg.reg +DMA_NEXT_DESC=0x79b1000
MV-DMA: tpg.reg +DMA_CURR_DESC=0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at0xffdbb000: dma addr0x79b1000, src0x79b4000, dst
Quoted 8 lines
0xf2200080, count 16, own 1, next0x79b1010
MV-DMA: entry 1 at0xffdbb010: dma addr0x79b1010, src0x799c28c, dst0xf2200000, count 80, own 1, next0x79b1020
MV-DMA: entry 2 at0xffdbb020: dma addr0x79b1020, src0x0, dst0x0, count 0, own 0, next0x79b1030
MV-DMA: entry 3 at0xffdbb030: dma addr0x79b1030, src0xf2200080, dst0x79b4000, count 16, own 1, next0x0
MV-CESA:got an interrupt but no pending timer?
Sucks. What's making me wonder here is, address decoding of address 0x0 actually shouldn't fail, since window 0 includes this address.
For now, I have pushed two new commits to my public git, adding more debugging output for decoding window logic and interrupt case as well as decoding window permission fix and changing from FETCH_ND to programming the first DMA descriptor's values manually.
In the long term, I probably should try to get access to some appropriate hardware myself. This is rather a quiz game than actual bug tracking.
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 20 lines
VNet Europe GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Management Buy-Out at Viprinet - please read http://www.viprinet.com/en/mbo Management Buy-Out bei Viprinet - bitte lesen Sie http://www.viprinet.com/de/mbo Phone/Zentrale: +49 6721 49030-0 Direct line/Durchwahl: +49 6721 49030-134 Fax: +49 6721 49030-109 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein, Germany Commercial register/Handelsregister: Amtsgericht Mainz HRB44090 CEO/Geschäftsführer: Simon Kissel
Andrew Lunn
maintainerRe: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
In reply to cloudy.linuxHi Cloudy
I've not been following this thread too closely..
Do you have any patches you want included into mainline?
Thanks
Andrew
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hey Andrew,
Quoted 3 lines · Andrew Lunn
I've not been following this thread too closely..
Do you have any patches you want included into mainline?
No need to fix anything mainline, he's just testing my RFC-state DMA engine addon to MV_CESA. Current state is failing operation on IDMA-based machines due to errors in hardware configuration I have not been able to track down yet. On Kirkwood (i.e. TDMA), the only hardware I have access to, the same code runs fine.
After all, I am not sure why he decided to put you in Cc in the first place?
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 20 lines
VNet Europe GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Management Buy-Out at Viprinet - please read http://www.viprinet.com/en/mbo Management Buy-Out bei Viprinet - bitte lesen Sie http://www.viprinet.com/de/mbo Phone/Zentrale: +49 6721 49030-0 Direct line/Durchwahl: +49 6721 49030-134 Fax: +49 6721 49030-109 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein, Germany Commercial register/Handelsregister: Amtsgericht Mainz HRB44090 CEO/Geschäftsführer: Simon Kissel
Andrew Lunn
maintainerRe: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Quoted 8 lines · Phil Sutter
Hey Andrew,
Quoted 3 lines · Andrew Lunn
I've not been following this thread too closely..
Do you have any patches you want included into mainline?
No need to fix anything mainline
O.K. I thought there was a problem with user space using it, some flushes missing somewhere? Or VM mapping problem? Has that been fixed?
Thanks
Andrew
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Quoted 4 lines · Andrew Lunn
Quoted 3 lines · Phil Sutter
Hey Andrew,
On Mon, Jul 16, 2012 at 11:32:25AM +0200, Andrew Lunn wrote:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
I've not been following this thread too closely..
Do you have any patches you want included into mainline?
No need to fix anything mainline
O.K. I thought there was a problem with user space using it, some flushes missing somewhere? Or VM mapping problem? Has that been fixed?
Hmm, there was some discussion about an issue like that in this list at end of February/beginning of March, which was resolved then. On the other hand there is an unanswered mail from Cloudy at 20. April about a failing kernel hash test. Maybe he can elaborate on this?
Greetings, Phil
Phil Sutter
Software Engineer
Signature · 20 lines
VNet Europe GmbH Mainzer Str. 43 55411 Bingen am Rhein Germany Management Buy-Out at Viprinet - please read http://www.viprinet.com/en/mbo Management Buy-Out bei Viprinet - bitte lesen Sie http://www.viprinet.com/de/mbo Phone/Zentrale: +49 6721 49030-0 Direct line/Durchwahl: +49 6721 49030-134 Fax: +49 6721 49030-109 [email protected] http://www.viprinet.com Registered office/Sitz der Gesellschaft: Bingen am Rhein, Germany Commercial register/Handelsregister: Amtsgericht Mainz HRB44090 CEO/Geschäftsführer: Simon Kissel
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hi Andrew, Phil,
Quoted 11 lines · Phil Sutter
Quoted 10 lines · Andrew Lunn
Quoted 8 lines · Phil Sutter
Hey Andrew,
Quoted 3 lines · Andrew Lunn
I've not been following this thread too closely..
Do you have any patches you want included into mainline?
No need to fix anything mainline
Quoted 8 lines
Quoted 2 lines
O.K. I thought there was a problem with user space using it, some flushes missing somewhere? Or VM mapping problem? Has that been fixed?
Hmm, there was some discussion about an issue like that in this list at end of February/beginning of March, which was resolved then. On the other hand there is an unanswered mail from Cloudy at 20. April about a failing kernel hash test. Maybe he can elaborate on this?
I think the problem is not in mv_cesa but in flush_kernel_dcache_page(). I have proposed a fix here:
http://www.spinics.net/lists/arm-kernel/msg176913.html
There was a little bit of discussion on the patch, but it has not been picked up yet.
- Simon
Andrew Lunn
maintainerRe: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Quoted 7 lines
I think the problem is not in
mv_cesabut inflush_kernel_dcache_page(). I have proposed a fix here:http://www.spinics.net/lists/arm-kernel/msg176913.html
There was a little bit of discussion on the patch, but it has not been picked up yet.
Hi Simon
This is core code, not an area i feel comfortable about.
I suggest you repost it, CC: Catalin and Russell.
Andrew
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
In reply to Phil SutterHi Phil
Quoted 39 lines · Phil Sutter
Hi,
Quoted 15 lines · cloudy.linux
Newest result. Still couldn't boot up. This time the source was cloned from your git repository.
MV-DMA: window at bar0: target 0, attr 14, base 0, size 8000000
MV-DMA: window at bar1: target 5, attr 0, basef2200000, size 10000
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA:idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg +DMA_CTRL=0x80001d04
MV-DMA: tpg.reg +DMA_BYTE_COUNT=0x0
MV-DMA: tpg.reg +DMA_SRC_ADDR=0x0
MV-DMA: tpg.reg +DMA_DST_ADDR=0x0
MV-DMA: tpg.reg +DMA_NEXT_DESC=0x79b1000
MV-DMA: tpg.reg +DMA_CURR_DESC=0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at0xffdbb000: dma addr0x79b1000, src0x79b4000, dstQuoted 8 lines
0xf2200080, count 16, own 1, next0x79b1010
MV-DMA: entry 1 at0xffdbb010: dma addr0x79b1010, src0x799c28c, dst0xf2200000, count 80, own 1, next0x79b1020
MV-DMA: entry 2 at0xffdbb020: dma addr0x79b1020, src0x0, dst0x0, count 0, own 0, next0x79b1030
MV-DMA: entry 3 at0xffdbb030: dma addr0x79b1030, src0xf2200080, dst0x79b4000, count 16, own 1, next0x0
MV-CESA:got an interrupt but no pending timer?Sucks. What's making me wonder here is, address decoding of address
0x0actually shouldn't fail, since window 0 includes this address.For now, I have pushed two new commits to my public git, adding more debugging output for decoding window logic and interrupt case as well as decoding window permission fix and changing from
FETCH_NDto programming the first DMA descriptor's values manually.In the long term, I probably should try to get access to some appropriate hardware myself. This is rather a quiz game than actual bug tracking.
Quoted 6 lines
Greetings, Phil
Phil Sutter
Software Engineer
Sorry for taking so long time to try the latest code. Just came back from a vacation and tried several days to get a tight sleep.
The latest console output:
MV-DMA: window at bar0: target 0, attr 14, base 0, size 8000000
MV-DMA: idma_set_deco_win: win(0): BAR 0x7ff0000, size 0x0, enable 0xffff, prot 0xc031295c
MV-DMA: window at bar1: target 5, attr 0, base f2200000, size 10000
MV-DMA: idma_set_deco_win: win(1): BAR 0x0, size 0x0, enable 0xffff, prot 0xc031295c
MV-DMA: IDMA engine up and running, IRQ 23
MV-DMA: idma_print_and_clear_irq: cause 0x3, select 0x1, addr 0x79b4000
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x80000010
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x79b4000
MV-DMA: tpg.reg + DMA_DST_ADDR = 0xf2200080
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x79b1010
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0 MV-CESA:got an interrupt but no pending timer?
------------[ cut here ]------------ kernel BUG at drivers/crypto/mv_cesa.c:1126! Internal error: Oops - BUG: 0 [#1] ARM Modules linked in: CPU: 0 Not tainted (3.5.0-rc2+ #4) pc : [<c01df9d8>] lr : [<c0015810>] psr: 20000093
sp : c79b9e68 ip : c79b9db8 fp : c79b9e7c
r10: c02f2164 r9 : c0306322 r8 : 0000001c
r7 : 00000000 r6 : 00000000 r5 : c0312988 r4 : 00000002 r3 : c799c200 r2 : 0000de20 r1 : fdd90000 r0 : fdd90000
Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment kernel
Control: a005317f Table: 00004000 DAC: 00000017
Process mv_crypto (pid: 276, stack limit = 0xc79b8270)
Stack: (0xc79b9e68 to 0xc79ba000)
9e60: c79afc40 0000001c c79b9eb4 c79b9e80 c0047694 c01df950
9e80: c7824540 00000001 c79b9eac c02f2164 0000001c 00000000 c79b9f5c c79bbe18 9ea0: c02ecc18 c02ef0a0 c79b9ecc c79b9eb8 c0047844 c0047650 00022000 c02f2164 9ec0: c79b9ee4 c79b9ed0 c0049b4c c0047824 c0049ac4 c02ff738 c79b9ef4 c79b9ee8 9ee0: c0046fd0 c0049ad4 c79b9f14 c79b9ef8 c000985c c0046fb0 c01dc330 c01dee08 9f00: a0000013 fdd20200 c79b9f24 c79b9f18 c0008170 c0009834 c79b9fbc c79b9f28 9f20: c0008c14 c0008170 0000009b 00000001 fdd90000 0000de00 c0312988 c799c200 9f40: c7936cc0 c79ac780 c79bbe18 c02ecc18 c02ef0a0 c79b9fbc 00000010 c79b9f70 9f60: c01dc330 c01dee08 a0000013 ffffffff 00000000 c79b9f80 c025d9fc c0035000 9f80: c78897a0 c7827de8 c79b8000 c02ecc18 00000013 c7827de8 c799c200 c01de718 9fa0: 00000013 00000000 00000000 00000000 c79b9ff4 c79b9fc0 c002da78 c01de728 9fc0: c7827de8 00000000 c799c200 00000000 c79b9fd0 c79b9fd0 00000000 c7827de8 9fe0: c002d9e8 c0018354 00000000 c79b9ff8 c0018354 c002d9f8 01e6e7fe 01e6e7ff
Backtrace:
Function entered at [<c01df940>] from [<c0047694>]
r5:0000001c r4:c79afc40
Function entered at [<c0047640>] from [<c0047844>] Function entered at [<c0047814>] from [<c0049b4c>]
r4:c02f2164 r3:00022000
Function entered at [<c0049ac4>] from [<c0046fd0>]
r4:c02ff738 r3:c0049ac4
Function entered at [<c0046fa0>] from [<c000985c>] Function entered at [<c0009824>] from [<c0008170>]
r6:fdd20200 r5:a0000013 r4:c01dee08 r3:c01dc330
Function entered at [<c0008160>] from [<c0008c14>]
Exception stack(0xc79b9f28 to 0xc79b9f70)
9f20: 0000009b 00000001 fdd90000 0000de00 c0312988 c799c200
9f40: c7936cc0 c79ac780 c79bbe18 c02ecc18 c02ef0a0 c79b9fbc 00000010 c79b9f70 9f60: c01dc330 c01dee08 a0000013 ffffffff
Function entered at [<c01de718>] from [<c002da78>]
Function entered at [<c002d9e8>] from [<c0018354>]
r6:c0018354 r5:c002d9e8 r4:c7827de8
Code: e89da830 e59f000c eb01ec39 eaffffe9 (e7f001f2)
MV-DMA: idma_print_and_clear_irq: cause 0x3, select 0x1, addr 0x0
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0
MV-DMA: idma_print_and_clear_irq: cause 0x3, select 0x1, addr 0x0
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
MV-DMA: DMA descriptor list:
MV-DMA: entry 0 at 0xffdbb000: dma addr 0x79b1000, src 0x79b4000, dst 0xf2200080, count 16, own 1, next 0x79b1010
MV-DMA: entry 1 at 0xffdbb010: dma addr 0x79b1010, src 0x799c28c, dst 0xf2200000, count 80, own 1, next 0x79b1020
MV-DMA: entry 2 at 0xffdbb020: dma addr 0x79b1020, src 0x0, dst 0x0, count 0, own 0, next 0x79b1030
MV-DMA: entry 3 at 0xffdbb030: dma addr 0x79b1030, src 0xf2200080, dst 0x79b4000, count 16, own 1, next 0x0
MV-DMA: idma_print_and_clear_irq: cause 0x3, select 0x1, addr 0x0
MV-DMA: idma_print_and_clear_irq: address miss @0!
MV-DMA: tpg.reg + DMA_CTRL = 0x80001d04
MV-DMA: tpg.reg + DMA_BYTE_COUNT = 0x0
MV-DMA: tpg.reg + DMA_SRC_ADDR = 0x0
MV-DMA: tpg.reg + DMA_DST_ADDR = 0x0
MV-DMA: tpg.reg + DMA_NEXT_DESC = 0x0
MV-DMA: tpg.reg + DMA_CURR_DESC = 0x0
...
Best Regards
Cloudy
Re: [PATCH 0/2] Fixes for MV_CESA with IDMA or TDMA
Hey,
Quoted 2 lines · cloudy.linux
Sorry for taking so long time to try the latest code. Just came back from a vacation and tried several days to get a tight sleep.
My apologies for having a ~3months lag. Somehow I have totally forgotten about your mail in my inbox and just recently found it again.
Luckily, I received testing hardware from a colleague a few days ago on which I can reproduce the problems at hand. So for now, I can do the testing on my own. Thanks a lot for yours!
I'll get back to you (probably via linux-crypto) as soon as I have some useful progress. Could be that I have to implement bigger changes in code flow for Orion, as the IDMA seems to lag this "Enhanced Software Flow" functionality (how the Kirkwood datasheet calls it) I am relying upon in my current code. Will see.
Best wishes, Phil