1 #ifndef __MARVELL_CESA_H__
2 #define __MARVELL_CESA_H__
4 #include <crypto/algapi.h>
5 #include <crypto/hash.h>
6 #include <crypto/internal/hash.h>
8 #include <linux/crypto.h>
9 #include <linux/dmapool.h>
11 #define CESA_ENGINE_OFF(i) (((i) * 0x2000))
13 #define CESA_TDMA_BYTE_CNT 0x800
14 #define CESA_TDMA_SRC_ADDR 0x810
15 #define CESA_TDMA_DST_ADDR 0x820
16 #define CESA_TDMA_NEXT_ADDR 0x830
18 #define CESA_TDMA_CONTROL 0x840
19 #define CESA_TDMA_DST_BURST GENMASK(2, 0)
20 #define CESA_TDMA_DST_BURST_32B 3
21 #define CESA_TDMA_DST_BURST_128B 4
22 #define CESA_TDMA_OUT_RD_EN BIT(4)
23 #define CESA_TDMA_SRC_BURST GENMASK(8, 6)
24 #define CESA_TDMA_SRC_BURST_32B (3 << 6)
25 #define CESA_TDMA_SRC_BURST_128B (4 << 6)
26 #define CESA_TDMA_CHAIN BIT(9)
27 #define CESA_TDMA_BYTE_SWAP BIT(11)
28 #define CESA_TDMA_NO_BYTE_SWAP BIT(11)
29 #define CESA_TDMA_EN BIT(12)
30 #define CESA_TDMA_FETCH_ND BIT(13)
31 #define CESA_TDMA_ACT BIT(14)
33 #define CESA_TDMA_CUR 0x870
34 #define CESA_TDMA_ERROR_CAUSE 0x8c8
35 #define CESA_TDMA_ERROR_MSK 0x8cc
37 #define CESA_TDMA_WINDOW_BASE(x) (((x) * 0x8) + 0xa00)
38 #define CESA_TDMA_WINDOW_CTRL(x) (((x) * 0x8) + 0xa04)
40 #define CESA_IVDIG(x) (0xdd00 + ((x) * 4) + \
41 (((x) < 5) ? 0 : 0x14))
43 #define CESA_SA_CMD 0xde00
44 #define CESA_SA_CMD_EN_CESA_SA_ACCL0 BIT(0)
45 #define CESA_SA_CMD_EN_CESA_SA_ACCL1 BIT(1)
46 #define CESA_SA_CMD_DISABLE_SEC BIT(2)
48 #define CESA_SA_DESC_P0 0xde04
50 #define CESA_SA_DESC_P1 0xde14
52 #define CESA_SA_CFG 0xde08
53 #define CESA_SA_CFG_STOP_DIG_ERR GENMASK(1, 0)
54 #define CESA_SA_CFG_DIG_ERR_CONT 0
55 #define CESA_SA_CFG_DIG_ERR_SKIP 1
56 #define CESA_SA_CFG_DIG_ERR_STOP 3
57 #define CESA_SA_CFG_CH0_W_IDMA BIT(7)
58 #define CESA_SA_CFG_CH1_W_IDMA BIT(8)
59 #define CESA_SA_CFG_ACT_CH0_IDMA BIT(9)
60 #define CESA_SA_CFG_ACT_CH1_IDMA BIT(10)
61 #define CESA_SA_CFG_MULTI_PKT BIT(11)
62 #define CESA_SA_CFG_PARA_DIS BIT(13)
64 #define CESA_SA_ACCEL_STATUS 0xde0c
65 #define CESA_SA_ST_ACT_0 BIT(0)
66 #define CESA_SA_ST_ACT_1 BIT(1)
69 * CESA_SA_FPGA_INT_STATUS looks like a FPGA leftover and is documented only
70 * in Errata 4.12. It looks like that it was part of an IRQ-controller in FPGA
71 * and someone forgot to remove it while switching to the core and moving to
74 #define CESA_SA_FPGA_INT_STATUS 0xdd68
75 #define CESA_SA_INT_STATUS 0xde20
76 #define CESA_SA_INT_AUTH_DONE BIT(0)
77 #define CESA_SA_INT_DES_E_DONE BIT(1)
78 #define CESA_SA_INT_AES_E_DONE BIT(2)
79 #define CESA_SA_INT_AES_D_DONE BIT(3)
80 #define CESA_SA_INT_ENC_DONE BIT(4)
81 #define CESA_SA_INT_ACCEL0_DONE BIT(5)
82 #define CESA_SA_INT_ACCEL1_DONE BIT(6)
83 #define CESA_SA_INT_ACC0_IDMA_DONE BIT(7)
84 #define CESA_SA_INT_ACC1_IDMA_DONE BIT(8)
85 #define CESA_SA_INT_IDMA_DONE BIT(9)
86 #define CESA_SA_INT_IDMA_OWN_ERR BIT(10)
88 #define CESA_SA_INT_MSK 0xde24
90 #define CESA_SA_DESC_CFG_OP_MAC_ONLY 0
91 #define CESA_SA_DESC_CFG_OP_CRYPT_ONLY 1
92 #define CESA_SA_DESC_CFG_OP_MAC_CRYPT 2
93 #define CESA_SA_DESC_CFG_OP_CRYPT_MAC 3
94 #define CESA_SA_DESC_CFG_OP_MSK GENMASK(1, 0)
95 #define CESA_SA_DESC_CFG_MACM_SHA256 (1 << 4)
96 #define CESA_SA_DESC_CFG_MACM_HMAC_SHA256 (3 << 4)
97 #define CESA_SA_DESC_CFG_MACM_MD5 (4 << 4)
98 #define CESA_SA_DESC_CFG_MACM_SHA1 (5 << 4)
99 #define CESA_SA_DESC_CFG_MACM_HMAC_MD5 (6 << 4)
100 #define CESA_SA_DESC_CFG_MACM_HMAC_SHA1 (7 << 4)
101 #define CESA_SA_DESC_CFG_MACM_MSK GENMASK(6, 4)
102 #define CESA_SA_DESC_CFG_CRYPTM_DES (1 << 8)
103 #define CESA_SA_DESC_CFG_CRYPTM_3DES (2 << 8)
104 #define CESA_SA_DESC_CFG_CRYPTM_AES (3 << 8)
105 #define CESA_SA_DESC_CFG_CRYPTM_MSK GENMASK(9, 8)
106 #define CESA_SA_DESC_CFG_DIR_ENC (0 << 12)
107 #define CESA_SA_DESC_CFG_DIR_DEC (1 << 12)
108 #define CESA_SA_DESC_CFG_CRYPTCM_ECB (0 << 16)
109 #define CESA_SA_DESC_CFG_CRYPTCM_CBC (1 << 16)
110 #define CESA_SA_DESC_CFG_CRYPTCM_MSK BIT(16)
111 #define CESA_SA_DESC_CFG_3DES_EEE (0 << 20)
112 #define CESA_SA_DESC_CFG_3DES_EDE (1 << 20)
113 #define CESA_SA_DESC_CFG_AES_LEN_128 (0 << 24)
114 #define CESA_SA_DESC_CFG_AES_LEN_192 (1 << 24)
115 #define CESA_SA_DESC_CFG_AES_LEN_256 (2 << 24)
116 #define CESA_SA_DESC_CFG_AES_LEN_MSK GENMASK(25, 24)
117 #define CESA_SA_DESC_CFG_NOT_FRAG (0 << 30)
118 #define CESA_SA_DESC_CFG_FIRST_FRAG (1 << 30)
119 #define CESA_SA_DESC_CFG_LAST_FRAG (2 << 30)
120 #define CESA_SA_DESC_CFG_MID_FRAG (3 << 30)
121 #define CESA_SA_DESC_CFG_FRAG_MSK GENMASK(31, 30)
125 * | ACCEL CFG | 4 * 8
127 * | CRYPT KEY | 8 * 4
130 * |-----------| 0x40 (inplace)
133 * | DATA IN | 16 * x (max ->max_req_size)
134 * |-----------| 0x80 (inplace operation)
135 * | DATA OUT | 16 * x (max ->max_req_size)
136 * \-----------/ SRAM size
140 * Hashing memory map:
142 * | ACCEL CFG | 4 * 8
148 * | Output BUF| 8 * 4
150 * | DATA IN | 64 * x (max ->max_req_size)
151 * \-----------/ SRAM size
154 #define CESA_SA_CFG_SRAM_OFFSET 0x00
155 #define CESA_SA_DATA_SRAM_OFFSET 0x80
157 #define CESA_SA_CRYPT_KEY_SRAM_OFFSET 0x20
158 #define CESA_SA_CRYPT_IV_SRAM_OFFSET 0x40
160 #define CESA_SA_MAC_IIV_SRAM_OFFSET 0x20
161 #define CESA_SA_MAC_OIV_SRAM_OFFSET 0x40
162 #define CESA_SA_MAC_DIG_SRAM_OFFSET 0x60
164 #define CESA_SA_DESC_CRYPT_DATA(offset) \
165 cpu_to_le32((CESA_SA_DATA_SRAM_OFFSET + (offset)) | \
166 ((CESA_SA_DATA_SRAM_OFFSET + (offset)) << 16))
168 #define CESA_SA_DESC_CRYPT_IV(offset) \
169 cpu_to_le32((CESA_SA_CRYPT_IV_SRAM_OFFSET + (offset)) | \
170 ((CESA_SA_CRYPT_IV_SRAM_OFFSET + (offset)) << 16))
172 #define CESA_SA_DESC_CRYPT_KEY(offset) \
173 cpu_to_le32(CESA_SA_CRYPT_KEY_SRAM_OFFSET + (offset))
175 #define CESA_SA_DESC_MAC_DATA(offset) \
176 cpu_to_le32(CESA_SA_DATA_SRAM_OFFSET + (offset))
177 #define CESA_SA_DESC_MAC_DATA_MSK cpu_to_le32(GENMASK(15, 0))
179 #define CESA_SA_DESC_MAC_TOTAL_LEN(total_len) cpu_to_le32((total_len) << 16)
180 #define CESA_SA_DESC_MAC_TOTAL_LEN_MSK cpu_to_le32(GENMASK(31, 16))
182 #define CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX 0xffff
184 #define CESA_SA_DESC_MAC_DIGEST(offset) \
185 cpu_to_le32(CESA_SA_MAC_DIG_SRAM_OFFSET + (offset))
186 #define CESA_SA_DESC_MAC_DIGEST_MSK cpu_to_le32(GENMASK(15, 0))
188 #define CESA_SA_DESC_MAC_FRAG_LEN(frag_len) cpu_to_le32((frag_len) << 16)
189 #define CESA_SA_DESC_MAC_FRAG_LEN_MSK cpu_to_le32(GENMASK(31, 16))
191 #define CESA_SA_DESC_MAC_IV(offset) \
192 cpu_to_le32((CESA_SA_MAC_IIV_SRAM_OFFSET + (offset)) | \
193 ((CESA_SA_MAC_OIV_SRAM_OFFSET + (offset)) << 16))
195 #define CESA_SA_SRAM_SIZE 2048
196 #define CESA_SA_SRAM_PAYLOAD_SIZE (cesa_dev->sram_size - \
197 CESA_SA_DATA_SRAM_OFFSET)
199 #define CESA_SA_DEFAULT_SRAM_SIZE 2048
200 #define CESA_SA_MIN_SRAM_SIZE 1024
202 #define CESA_SA_SRAM_MSK (2048 - 1)
204 #define CESA_MAX_HASH_BLOCK_SIZE 64
205 #define CESA_HASH_BLOCK_SIZE_MSK (CESA_MAX_HASH_BLOCK_SIZE - 1)
208 * struct mv_cesa_sec_accel_desc - security accelerator descriptor
209 * @config: engine config
210 * @enc_p: input and output data pointers for a cipher operation
211 * @enc_len: cipher operation length
212 * @enc_key_p: cipher key pointer
213 * @enc_iv: cipher IV pointers
214 * @mac_src_p: input pointer and total hash length
215 * @mac_digest: digest pointer and hash operation length
216 * @mac_iv: hmac IV pointers
218 * Structure passed to the CESA engine to describe the crypto operation
221 struct mv_cesa_sec_accel_desc {
233 * struct mv_cesa_blkcipher_op_ctx - cipher operation context
237 * Context associated to a cipher operation.
239 struct mv_cesa_blkcipher_op_ctx {
245 * struct mv_cesa_hash_op_ctx - hash or hmac operation context
249 * Context associated to an hash or hmac operation.
251 struct mv_cesa_hash_op_ctx {
257 * struct mv_cesa_op_ctx - crypto operation context
258 * @desc: CESA descriptor
259 * @ctx: context associated to the crypto operation
261 * Context associated to a crypto operation.
263 struct mv_cesa_op_ctx {
264 struct mv_cesa_sec_accel_desc desc;
266 struct mv_cesa_blkcipher_op_ctx blkcipher;
267 struct mv_cesa_hash_op_ctx hash;
271 /* TDMA descriptor flags */
272 #define CESA_TDMA_DST_IN_SRAM BIT(31)
273 #define CESA_TDMA_SRC_IN_SRAM BIT(30)
274 #define CESA_TDMA_TYPE_MSK GENMASK(29, 0)
275 #define CESA_TDMA_DUMMY 0
276 #define CESA_TDMA_DATA 1
277 #define CESA_TDMA_OP 2
280 * struct mv_cesa_tdma_desc - TDMA descriptor
281 * @byte_cnt: number of bytes to transfer
282 * @src: DMA address of the source
283 * @dst: DMA address of the destination
284 * @next_dma: DMA address of the next TDMA descriptor
285 * @cur_dma: DMA address of this TDMA descriptor
286 * @next: pointer to the next TDMA descriptor
287 * @op: CESA operation attached to this TDMA descriptor
288 * @data: raw data attached to this TDMA descriptor
289 * @flags: flags describing the TDMA transfer. See the
290 * "TDMA descriptor flags" section above
292 * TDMA descriptor used to create a transfer chain describing a crypto
295 struct mv_cesa_tdma_desc {
303 struct mv_cesa_tdma_desc *next;
305 struct mv_cesa_op_ctx *op;
312 * struct mv_cesa_sg_dma_iter - scatter-gather iterator
313 * @dir: transfer direction
315 * @offset: current position in the scatter list
316 * @op_offset: current position in the crypto operation
318 * Iterator used to iterate over a scatterlist while creating a TDMA chain for
319 * a crypto operation.
321 struct mv_cesa_sg_dma_iter {
322 enum dma_data_direction dir;
323 struct scatterlist *sg;
325 unsigned int op_offset;
329 * struct mv_cesa_dma_iter - crypto operation iterator
330 * @len: the crypto operation length
331 * @offset: current position in the crypto operation
332 * @op_len: sub-operation length (the crypto engine can only act on 2kb
335 * Iterator used to create a TDMA chain for a given crypto operation.
337 struct mv_cesa_dma_iter {
344 * struct mv_cesa_tdma_chain - TDMA chain
345 * @first: first entry in the TDMA chain
346 * @last: last entry in the TDMA chain
348 * Stores a TDMA chain for a specific crypto operation.
350 struct mv_cesa_tdma_chain {
351 struct mv_cesa_tdma_desc *first;
352 struct mv_cesa_tdma_desc *last;
355 struct mv_cesa_engine;
358 * struct mv_cesa_caps - CESA device capabilities
359 * @engines: number of engines
360 * @has_tdma: whether this device has a TDMA block
361 * @cipher_algs: supported cipher algorithms
362 * @ncipher_algs: number of supported cipher algorithms
363 * @ahash_algs: supported hash algorithms
364 * @nahash_algs: number of supported hash algorithms
366 * Structure used to describe CESA device capabilities.
368 struct mv_cesa_caps {
371 struct crypto_alg **cipher_algs;
373 struct ahash_alg **ahash_algs;
378 * struct mv_cesa_dev_dma - DMA pools
379 * @tdma_desc_pool: TDMA desc pool
380 * @op_pool: crypto operation pool
381 * @cache_pool: data cache pool (used by hash implementation when the
382 * hash request is smaller than the hash block size)
383 * @padding_pool: padding pool (used by hash implementation when hardware
384 * padding cannot be used)
386 * Structure containing the different DMA pools used by this driver.
388 struct mv_cesa_dev_dma {
389 struct dma_pool *tdma_desc_pool;
390 struct dma_pool *op_pool;
391 struct dma_pool *cache_pool;
392 struct dma_pool *padding_pool;
396 * struct mv_cesa_dev - CESA device
397 * @caps: device capabilities
398 * @regs: device registers
399 * @sram_size: usable SRAM size
401 * @queue: crypto request queue
402 * @engines: array of engines
405 * Structure storing CESA device information.
408 const struct mv_cesa_caps *caps;
411 unsigned int sram_size;
413 struct crypto_queue queue;
414 struct mv_cesa_engine *engines;
415 struct mv_cesa_dev_dma *dma;
419 * struct mv_cesa_engine - CESA engine
421 * @regs: engine registers
422 * @sram: SRAM memory region
423 * @sram_dma: DMA address of the SRAM memory region
425 * @req: current crypto request
428 * @max_req_len: maximum chunk length (useful to create the TDMA chain)
429 * @int_mask: interrupt mask cache
430 * @pool: memory pool pointing to the memory region reserved in
433 * Structure storing CESA engine information.
435 struct mv_cesa_engine {
441 struct crypto_async_request *req;
446 struct gen_pool *pool;
450 * struct mv_cesa_req_ops - CESA request operations
451 * @prepare: prepare a request to be executed on the specified engine
452 * @process: process a request chunk result (should return 0 if the
453 * operation, -EINPROGRESS if it needs more steps or an error
455 * @step: launch the crypto operation on the next chunk
456 * @cleanup: cleanup the crypto request (release associated data)
458 struct mv_cesa_req_ops {
459 void (*prepare)(struct crypto_async_request *req,
460 struct mv_cesa_engine *engine);
461 int (*process)(struct crypto_async_request *req, u32 status);
462 void (*step)(struct crypto_async_request *req);
463 void (*cleanup)(struct crypto_async_request *req);
467 * struct mv_cesa_ctx - CESA operation context
468 * @ops: crypto operations
470 * Base context structure inherited by operation specific ones.
473 const struct mv_cesa_req_ops *ops;
477 * struct mv_cesa_hash_ctx - CESA hash operation context
478 * @base: base context structure
480 * Hash context structure.
482 struct mv_cesa_hash_ctx {
483 struct mv_cesa_ctx base;
487 * struct mv_cesa_hash_ctx - CESA hmac operation context
488 * @base: base context structure
489 * @iv: initialization vectors
491 * HMAC context structure.
493 struct mv_cesa_hmac_ctx {
494 struct mv_cesa_ctx base;
499 * enum mv_cesa_req_type - request type definitions
500 * @CESA_STD_REQ: standard request
501 * @CESA_DMA_REQ: DMA request
503 enum mv_cesa_req_type {
509 * struct mv_cesa_req - CESA request
510 * @type: request type
511 * @engine: engine associated with this request
514 enum mv_cesa_req_type type;
515 struct mv_cesa_engine *engine;
519 * struct mv_cesa_tdma_req - CESA TDMA request
520 * @base: base information
523 struct mv_cesa_tdma_req {
524 struct mv_cesa_req base;
525 struct mv_cesa_tdma_chain chain;
529 * struct mv_cesa_sg_std_iter - CESA scatter-gather iterator for standard
531 * @iter: sg mapping iterator
532 * @offset: current offset in the SG entry mapped in memory
534 struct mv_cesa_sg_std_iter {
535 struct sg_mapping_iter iter;
540 * struct mv_cesa_ablkcipher_std_req - cipher standard request
541 * @base: base information
542 * @op: operation context
543 * @offset: current operation offset
544 * @size: size of the crypto operation
546 struct mv_cesa_ablkcipher_std_req {
547 struct mv_cesa_req base;
548 struct mv_cesa_op_ctx op;
555 * struct mv_cesa_ablkcipher_req - cipher request
556 * @req: type specific request information
557 * @src_nents: number of entries in the src sg list
558 * @dst_nents: number of entries in the dest sg list
560 struct mv_cesa_ablkcipher_req {
562 struct mv_cesa_req base;
563 struct mv_cesa_tdma_req dma;
564 struct mv_cesa_ablkcipher_std_req std;
571 * struct mv_cesa_ahash_std_req - standard hash request
572 * @base: base information
573 * @offset: current operation offset
575 struct mv_cesa_ahash_std_req {
576 struct mv_cesa_req base;
581 * struct mv_cesa_ahash_dma_req - DMA hash request
582 * @base: base information
583 * @padding: padding buffer
584 * @padding_dma: DMA address of the padding buffer
585 * @cache_dma: DMA address of the cache buffer
587 struct mv_cesa_ahash_dma_req {
588 struct mv_cesa_tdma_req base;
590 dma_addr_t padding_dma;
591 dma_addr_t cache_dma;
595 * struct mv_cesa_ahash_req - hash request
596 * @req: type specific request information
597 * @cache: cache buffer
598 * @cache_ptr: write pointer in the cache buffer
599 * @len: hash total length
600 * @src_nents: number of entries in the scatterlist
601 * @last_req: define whether the current operation is the last one
605 struct mv_cesa_ahash_req {
607 struct mv_cesa_req base;
608 struct mv_cesa_ahash_dma_req dma;
609 struct mv_cesa_ahash_std_req std;
611 struct mv_cesa_op_ctx op_tmpl;
613 unsigned int cache_ptr;
623 extern struct mv_cesa_dev *cesa_dev;
625 static inline void mv_cesa_update_op_cfg(struct mv_cesa_op_ctx *op,
628 op->desc.config &= cpu_to_le32(~mask);
629 op->desc.config |= cpu_to_le32(cfg);
632 static inline u32 mv_cesa_get_op_cfg(const struct mv_cesa_op_ctx *op)
634 return le32_to_cpu(op->desc.config);
637 static inline void mv_cesa_set_op_cfg(struct mv_cesa_op_ctx *op, u32 cfg)
639 op->desc.config = cpu_to_le32(cfg);
642 static inline void mv_cesa_adjust_op(struct mv_cesa_engine *engine,
643 struct mv_cesa_op_ctx *op)
645 u32 offset = engine->sram_dma & CESA_SA_SRAM_MSK;
647 op->desc.enc_p = CESA_SA_DESC_CRYPT_DATA(offset);
648 op->desc.enc_key_p = CESA_SA_DESC_CRYPT_KEY(offset);
649 op->desc.enc_iv = CESA_SA_DESC_CRYPT_IV(offset);
650 op->desc.mac_src_p &= ~CESA_SA_DESC_MAC_DATA_MSK;
651 op->desc.mac_src_p |= CESA_SA_DESC_MAC_DATA(offset);
652 op->desc.mac_digest &= ~CESA_SA_DESC_MAC_DIGEST_MSK;
653 op->desc.mac_digest |= CESA_SA_DESC_MAC_DIGEST(offset);
654 op->desc.mac_iv = CESA_SA_DESC_MAC_IV(offset);
657 static inline void mv_cesa_set_crypt_op_len(struct mv_cesa_op_ctx *op, int len)
659 op->desc.enc_len = cpu_to_le32(len);
662 static inline void mv_cesa_set_mac_op_total_len(struct mv_cesa_op_ctx *op,
665 op->desc.mac_src_p &= ~CESA_SA_DESC_MAC_TOTAL_LEN_MSK;
666 op->desc.mac_src_p |= CESA_SA_DESC_MAC_TOTAL_LEN(len);
669 static inline void mv_cesa_set_mac_op_frag_len(struct mv_cesa_op_ctx *op,
672 op->desc.mac_digest &= ~CESA_SA_DESC_MAC_FRAG_LEN_MSK;
673 op->desc.mac_digest |= CESA_SA_DESC_MAC_FRAG_LEN(len);
676 static inline void mv_cesa_set_int_mask(struct mv_cesa_engine *engine,
679 if (int_mask == engine->int_mask)
682 writel_relaxed(int_mask, engine->regs + CESA_SA_INT_MSK);
683 engine->int_mask = int_mask;
686 static inline u32 mv_cesa_get_int_mask(struct mv_cesa_engine *engine)
688 return engine->int_mask;
691 static inline bool mv_cesa_mac_op_is_first_frag(const struct mv_cesa_op_ctx *op)
693 return (mv_cesa_get_op_cfg(op) & CESA_SA_DESC_CFG_FRAG_MSK) ==
694 CESA_SA_DESC_CFG_FIRST_FRAG;
697 int mv_cesa_queue_req(struct crypto_async_request *req);
700 * Helper function that indicates whether a crypto request needs to be
701 * cleaned up or not after being enqueued using mv_cesa_queue_req().
703 static inline int mv_cesa_req_needs_cleanup(struct crypto_async_request *req,
707 * The queue still had some space, the request was queued
708 * normally, so there's no need to clean it up.
710 if (ret == -EINPROGRESS)
714 * The queue had not space left, but since the request is
715 * flagged with CRYPTO_TFM_REQ_MAY_BACKLOG, it was added to
716 * the backlog and will be processed later. There's no need to
719 if (ret == -EBUSY && req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG)
722 /* Request wasn't queued, we need to clean it up */
728 static inline void mv_cesa_req_dma_iter_init(struct mv_cesa_dma_iter *iter,
732 iter->op_len = min(len, CESA_SA_SRAM_PAYLOAD_SIZE);
736 static inline void mv_cesa_sg_dma_iter_init(struct mv_cesa_sg_dma_iter *iter,
737 struct scatterlist *sg,
738 enum dma_data_direction dir)
746 static inline unsigned int
747 mv_cesa_req_dma_iter_transfer_len(struct mv_cesa_dma_iter *iter,
748 struct mv_cesa_sg_dma_iter *sgiter)
750 return min(iter->op_len - sgiter->op_offset,
751 sg_dma_len(sgiter->sg) - sgiter->offset);
754 bool mv_cesa_req_dma_iter_next_transfer(struct mv_cesa_dma_iter *chain,
755 struct mv_cesa_sg_dma_iter *sgiter,
758 static inline bool mv_cesa_req_dma_iter_next_op(struct mv_cesa_dma_iter *iter)
760 iter->offset += iter->op_len;
761 iter->op_len = min(iter->len - iter->offset,
762 CESA_SA_SRAM_PAYLOAD_SIZE);
767 void mv_cesa_dma_step(struct mv_cesa_tdma_req *dreq);
769 static inline int mv_cesa_dma_process(struct mv_cesa_tdma_req *dreq,
772 if (!(status & CESA_SA_INT_ACC0_IDMA_DONE))
775 if (status & CESA_SA_INT_IDMA_OWN_ERR)
781 void mv_cesa_dma_prepare(struct mv_cesa_tdma_req *dreq,
782 struct mv_cesa_engine *engine);
784 void mv_cesa_dma_cleanup(struct mv_cesa_tdma_req *dreq);
787 mv_cesa_tdma_desc_iter_init(struct mv_cesa_tdma_chain *chain)
789 memset(chain, 0, sizeof(*chain));
792 struct mv_cesa_op_ctx *mv_cesa_dma_add_op(struct mv_cesa_tdma_chain *chain,
793 const struct mv_cesa_op_ctx *op_templ,
797 int mv_cesa_dma_add_data_transfer(struct mv_cesa_tdma_chain *chain,
798 dma_addr_t dst, dma_addr_t src, u32 size,
799 u32 flags, gfp_t gfp_flags);
801 int mv_cesa_dma_add_dummy_launch(struct mv_cesa_tdma_chain *chain, gfp_t flags);
802 int mv_cesa_dma_add_dummy_end(struct mv_cesa_tdma_chain *chain, gfp_t flags);
804 int mv_cesa_dma_add_op_transfers(struct mv_cesa_tdma_chain *chain,
805 struct mv_cesa_dma_iter *dma_iter,
806 struct mv_cesa_sg_dma_iter *sgiter,
809 /* Algorithm definitions */
811 extern struct ahash_alg mv_md5_alg;
812 extern struct ahash_alg mv_sha1_alg;
813 extern struct ahash_alg mv_sha256_alg;
814 extern struct ahash_alg mv_ahmac_md5_alg;
815 extern struct ahash_alg mv_ahmac_sha1_alg;
816 extern struct ahash_alg mv_ahmac_sha256_alg;
818 extern struct crypto_alg mv_cesa_ecb_des_alg;
819 extern struct crypto_alg mv_cesa_cbc_des_alg;
820 extern struct crypto_alg mv_cesa_ecb_des3_ede_alg;
821 extern struct crypto_alg mv_cesa_cbc_des3_ede_alg;
822 extern struct crypto_alg mv_cesa_ecb_aes_alg;
823 extern struct crypto_alg mv_cesa_cbc_aes_alg;
825 #endif /* __MARVELL_CESA_H__ */