]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
51533b61 MS |
2 | /* |
3 | * The device /dev/cryptocop is accessible using this driver using | |
4 | * CRYPTOCOP_MAJOR (254) and minor number 0. | |
5 | */ | |
51533b61 MS |
6 | #ifndef CRYPTOCOP_H |
7 | #define CRYPTOCOP_H | |
8 | ||
98d848ea | 9 | #include <uapi/arch-v32/arch/cryptocop.h> |
51533b61 MS |
10 | |
11 | ||
51533b61 MS |
12 | /********** The API to use from inside the kernel. ************/ |
13 | ||
556dcee7 | 14 | #include <arch/hwregs/dma.h> |
51533b61 MS |
15 | |
16 | typedef enum { | |
17 | cryptocop_alg_csum = 0, | |
18 | cryptocop_alg_mem2mem, | |
19 | cryptocop_alg_md5, | |
20 | cryptocop_alg_sha1, | |
21 | cryptocop_alg_des, | |
22 | cryptocop_alg_3des, | |
23 | cryptocop_alg_aes, | |
24 | cryptocop_no_alg, | |
25 | } cryptocop_algorithm; | |
26 | ||
27 | typedef u8 cryptocop_tfrm_id; | |
28 | ||
29 | ||
30 | struct cryptocop_operation; | |
31 | ||
32 | typedef void (cryptocop_callback)(struct cryptocop_operation*, void*); | |
33 | ||
34 | struct cryptocop_transform_init { | |
35 | cryptocop_algorithm alg; | |
36 | /* Keydata for ciphers. */ | |
37 | unsigned char key[CRYPTOCOP_MAX_KEY_LENGTH]; | |
38 | unsigned int keylen; | |
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 */ | |
42 | ||
43 | cryptocop_tfrm_id tid; /* Locally unique in session; assigned by user, checked by driver. */ | |
44 | struct cryptocop_transform_init *next; | |
45 | }; | |
46 | ||
47 | ||
48 | typedef enum { | |
49 | cryptocop_source_dma = 0, | |
50 | cryptocop_source_des, | |
51 | cryptocop_source_3des, | |
52 | cryptocop_source_aes, | |
53 | cryptocop_source_md5, | |
54 | cryptocop_source_sha1, | |
55 | cryptocop_source_csum, | |
56 | cryptocop_source_none, | |
57 | } cryptocop_source; | |
58 | ||
59 | ||
60 | struct cryptocop_desc_cfg { | |
61 | cryptocop_tfrm_id tid; | |
62 | cryptocop_source src; | |
63 | unsigned int last:1; /* Last use of this transform in the operation. Will push outdata when encountered. */ | |
64 | struct cryptocop_desc_cfg *next; | |
65 | }; | |
66 | ||
67 | struct cryptocop_desc { | |
68 | size_t length; | |
69 | struct cryptocop_desc_cfg *cfg; | |
70 | struct cryptocop_desc *next; | |
71 | }; | |
72 | ||
73 | ||
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) | |
79 | ||
80 | struct cryptocop_tfrm_cfg { | |
81 | cryptocop_tfrm_id tid; | |
82 | ||
83 | unsigned int flags; /* DECRYPT, ENCRYPT, EXPLICIT_IV */ | |
84 | ||
60a7a199 | 85 | /* CBC initialisation vector for ciphers. */ |
51533b61 MS |
86 | u8 iv[CRYPTOCOP_MAX_IV_LENGTH]; |
87 | ||
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 | |
91 | unspecified. */ | |
92 | size_t inject_ix; | |
93 | ||
94 | struct cryptocop_tfrm_cfg *next; | |
95 | }; | |
96 | ||
97 | ||
98 | ||
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. */ | |
105 | char *out_data_buf; | |
106 | dma_descr_data *inlist; /* In from the co-processor to memory. */ | |
107 | char *in_data_buf; | |
108 | ||
109 | cryptocop_3des_mode tdes_mode; | |
110 | cryptocop_csum_type csum_mode; | |
111 | }; | |
112 | ||
113 | ||
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; | |
118 | ||
119 | struct iovec *indata; | |
120 | size_t incount; | |
121 | size_t inlen; /* Total inlength. */ | |
122 | ||
123 | struct iovec *outdata; | |
124 | size_t outcount; | |
125 | size_t outlen; /* Total outlength. */ | |
126 | }; | |
127 | ||
128 | ||
129 | struct cryptocop_operation { | |
130 | cryptocop_callback *cb; | |
131 | void *cb_data; | |
132 | ||
133 | cryptocop_session_id sid; | |
134 | ||
135 | /* The status of the operation when returned to consumer. */ | |
136 | int operation_status; /* 0, -EAGAIN */ | |
137 | ||
138 | /* Flags */ | |
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. */ | |
142 | ||
143 | union{ | |
144 | struct cryptocop_dma_list_operation list_op; | |
145 | struct cryptocop_tfrm_operation tfrm_op; | |
146 | }; | |
147 | }; | |
148 | ||
149 | ||
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); | |
152 | ||
153 | int cryptocop_job_queue_insert_csum(struct cryptocop_operation *operation); | |
154 | ||
155 | int cryptocop_job_queue_insert_crypto(struct cryptocop_operation *operation); | |
156 | ||
157 | int cryptocop_job_queue_insert_user_job(struct cryptocop_operation *operation); | |
158 | ||
51533b61 | 159 | #endif /* CRYPTOCOP_H */ |