1 /* SPDX-License-Identifier: GPL-2.0 */
3 * The device /dev/cryptocop is accessible using this driver using
4 * CRYPTOCOP_MAJOR (254) and minor number 0.
9 #include <uapi/arch-v32/arch/cryptocop.h>
12 /********** The API to use from inside the kernel. ************/
14 #include <arch/hwregs/dma.h>
17 cryptocop_alg_csum = 0,
18 cryptocop_alg_mem2mem,
25 } cryptocop_algorithm;
27 typedef u8 cryptocop_tfrm_id;
30 struct cryptocop_operation;
32 typedef void (cryptocop_callback)(struct cryptocop_operation*, void*);
34 struct cryptocop_transform_init {
35 cryptocop_algorithm alg;
36 /* Keydata for ciphers. */
37 unsigned char key[CRYPTOCOP_MAX_KEY_LENGTH];
39 cryptocop_cipher_mode cipher_mode;
40 cryptocop_3des_mode tdes_mode;
41 cryptocop_csum_type csum_mode; /* cryptocop_csum_none is not allowed when alg==cryptocop_alg_csum */
43 cryptocop_tfrm_id tid; /* Locally unique in session; assigned by user, checked by driver. */
44 struct cryptocop_transform_init *next;
49 cryptocop_source_dma = 0,
51 cryptocop_source_3des,
54 cryptocop_source_sha1,
55 cryptocop_source_csum,
56 cryptocop_source_none,
60 struct cryptocop_desc_cfg {
61 cryptocop_tfrm_id tid;
63 unsigned int last:1; /* Last use of this transform in the operation. Will push outdata when encountered. */
64 struct cryptocop_desc_cfg *next;
67 struct cryptocop_desc {
69 struct cryptocop_desc_cfg *cfg;
70 struct cryptocop_desc *next;
74 /* Flags for cryptocop_tfrm_cfg */
75 #define CRYPTOCOP_NO_FLAG (0x00)
76 #define CRYPTOCOP_ENCRYPT (0x01)
77 #define CRYPTOCOP_DECRYPT (0x02)
78 #define CRYPTOCOP_EXPLICIT_IV (0x04)
80 struct cryptocop_tfrm_cfg {
81 cryptocop_tfrm_id tid;
83 unsigned int flags; /* DECRYPT, ENCRYPT, EXPLICIT_IV */
85 /* CBC initialisation vector for ciphers. */
86 u8 iv[CRYPTOCOP_MAX_IV_LENGTH];
88 /* The position in output where to write the transform output. The order
89 in which the driver writes the output is unspecified, hence if several
90 transforms write on the same positions in the output the result is
94 struct cryptocop_tfrm_cfg *next;
99 struct cryptocop_dma_list_operation{
100 /* The consumer can provide DMA lists to send to the co-processor. 'use_dmalists' in
101 struct cryptocop_operation must be set for the driver to use them. outlist,
102 out_data_buf, inlist and in_data_buf must all be physical addresses since they will
103 be loaded to DMA . */
104 dma_descr_data *outlist; /* Out from memory to the co-processor. */
106 dma_descr_data *inlist; /* In from the co-processor to memory. */
109 cryptocop_3des_mode tdes_mode;
110 cryptocop_csum_type csum_mode;
114 struct cryptocop_tfrm_operation{
115 /* Operation configuration, if not 'use_dmalists' is set. */
116 struct cryptocop_tfrm_cfg *tfrm_cfg;
117 struct cryptocop_desc *desc;
119 struct iovec *indata;
121 size_t inlen; /* Total inlength. */
123 struct iovec *outdata;
125 size_t outlen; /* Total outlength. */
129 struct cryptocop_operation {
130 cryptocop_callback *cb;
133 cryptocop_session_id sid;
135 /* The status of the operation when returned to consumer. */
136 int operation_status; /* 0, -EAGAIN */
139 unsigned int use_dmalists:1; /* Use outlist and inlist instead of the desc/tfrm_cfg configuration. */
140 unsigned int in_interrupt:1; /* Set if inserting job from interrupt context. */
141 unsigned int fast_callback:1; /* Set if fast callback wanted, i.e. from interrupt context. */
144 struct cryptocop_dma_list_operation list_op;
145 struct cryptocop_tfrm_operation tfrm_op;
150 int cryptocop_new_session(cryptocop_session_id *sid, struct cryptocop_transform_init *tinit, int alloc_flag);
151 int cryptocop_free_session(cryptocop_session_id sid);
153 int cryptocop_job_queue_insert_csum(struct cryptocop_operation *operation);
155 int cryptocop_job_queue_insert_crypto(struct cryptocop_operation *operation);
157 int cryptocop_job_queue_insert_user_job(struct cryptocop_operation *operation);
159 #endif /* CRYPTOCOP_H */