blob: 0638dd97fc704a4cbc6e4a499629b431176b0b4e [file] [log] [blame]
AnilKumar Chimatae78789a2017-04-07 12:18:46 -07001Introduction:
2=============
3
4This driver provides IOCTLS for user space application to access crypto
5engine hardware for the qcedev crypto services. The driver supports the
6following crypto algorithms
7- AES-128, AES-256 (ECB, CBC and CTR mode)
8- AES-192, (ECB, CBC and CTR mode)
9 (support exists on platform supporting CE 3.x hardware)
10- SHA1/SHA256
11- AES-128, AES-256 (XTS), AES CMAC, SHA1/SHA256 HMAC
12 (support exists on platform supporting CE 4.x hardware)
13
14Hardware description:
15=====================
16Crypto 3E provides cipher and hash algorithms as defined in the
173GPP forum specifications.
18
19
20Software description
21====================
22
23The driver is a Linux platform device driver. For an msm target,
24there can be multiple crypto devices assigned for QCEDEV.
25
26The driver is a misc device driver as well.
27The following operations are registered in the driver,
28-qcedev_ioctl()
29-qcedev_open()
30-qcedev_release()
31
32The following IOCTLS are available to the user space application(s)-
33
34 Cipher IOCTLs:
35 --------------
36 QCEDEV_IOCTL_ENC_REQ is for encrypting data.
37 QCEDEV_IOCTL_DEC_REQ is for decrypting data.
38
39 Hashing/HMAC IOCTLs
40 -------------------
41
42 QCEDEV_IOCTL_SHA_INIT_REQ is for initializing a hash/hmac request.
43 QCEDEV_IOCTL_SHA_UPDATE_REQ is for updating hash/hmac.
44 QCEDEV_IOCTL_SHA_FINAL_REQ is for ending the hash/mac request.
45 QCEDEV_IOCTL_GET_SHA_REQ is for retrieving the hash/hmac for data
46 packet of known size.
47 QCEDEV_IOCTL_GET_CMAC_REQ is for retrieving the MAC (using AES CMAC
48 algorithm) for data packet of known size.
49
50The requests are synchronous. The driver will put the process to
51sleep, waiting for the completion of the requests using wait_for_completion().
52
53Since the requests are coming out of user space application, before giving
54the requests to the low level qce driver, the ioctl requests and the
55associated input/output buffer will have to be safe checked, and copied
56to/from kernel space.
57
58The extra copying of requests/buffer can affect the performance. The issue
59with copying the data buffer is resolved by having the client use PMEM
60allocated buffers.
61
62NOTE: Using memory allocated via PMEM is supported only for in place
63 operations where source and destination buffers point to the same
64 location. Support for different source and destination buffers
65 is not supported currently.
66 Furthermore, when using PMEM, and in AES CTR mode, when issuing an
67 encryption or decryption request, a non-zero byteoffset is not
68 supported.
69
70The design of the driver is to allow multiple open, and multiple requests
71to be issued from application(s). Therefore, the driver will internally queue
72the requests, and serialize the requests to the low level qce (or qce40) driver.
73
74On an IOCTL request from an application, if there is no outstanding
75request, a the driver will issue a "qce" request, otherwise,
76the request is queued in the driver queue. The process is suspended
77waiting for completion.
78
79On completion of a request by the low level qce driver, the internal
80tasklet (done_tasklet) is scheduled. The sole purpose of done_tasklet is
81to call the completion of the current active request (complete()), and
82issue more requests to the qce, if any.
83When the process wakes up from wait_for_completion(), it will collect the
84return code, and return the ioctl.
85
86A spin lock is used to protect the critical section of internal queue to
87be accessed from multiple tasks, SMP, and completion callback
88from qce.
89
90The driver maintains a set of statistics using debug fs. The files are
91in /debug/qcedev/stats1, /debug/qcedev/stats2, /debug/qcedev/stats3;
92one for each instance of device. Reading the file associated with
93a device will retrieve the driver statistics for that device.
94Any write to the file will clear the statistics.
95
96
97Power Management
98================
99n/a
100
101
102Interface:
103==========
104
105Linux user space applications will need to open a handle
106(file descriptor) to the qcedev device. This is achieved by doing
107the following to retrieve a file descriptor to the device.
108
109 fd = open("/dev/qce", O_RDWR);
110 ..
111 ioctl(fd, ...);
112
113Once a valid fd is retrieved, user can call the following ioctls with
114the fd as the first parameter and a pointer to an appropriate data
115structure, qcedev_cipher_op_req or qcedev_sha_op_req (depending on
116cipher/hash functionality) as the second parameter.
117
118The following IOCTLS are available to the user space application(s)-
119
120 Cipher IOCTLs:
121 --------------
122 QCEDEV_IOCTL_ENC_REQ is for encrypting data.
123 QCEDEV_IOCTL_DEC_REQ is for decrypting data.
124
125 The caller of the IOCTL passes a pointer to the structure shown
126 below, as the second parameter.
127
128 struct qcedev_cipher_op_req {
129 int use_pmem;
130 union{
131 struct qcedev_pmem_info pmem;
132 struct qcedev_vbuf_info vbuf;
133 };
134 uint32_t entries;
135 uint32_t data_len;
136 uint8_t in_place_op;
137 uint8_t enckey[QCEDEV_MAX_KEY_SIZE];
138 uint32_t encklen;
139 uint8_t iv[QCEDEV_MAX_IV_SIZE];
140 uint32_t ivlen;
141 uint32_t byteoffset;
142 enum qcedev_cipher_alg_enum alg;
143 enum qcedev_cipher_mode_enum mode;
144 enum qcedev_oper_enum op;
145 };
146
147 Hashing/HMAC IOCTLs
148 -------------------
149
150 QCEDEV_IOCTL_SHA_INIT_REQ is for initializing a hash/hmac request.
151 QCEDEV_IOCTL_SHA_UPDATE_REQ is for updating hash/hmac.
152 QCEDEV_IOCTL_SHA_FINAL_REQ is for ending the hash/mac request.
153 QCEDEV_IOCTL_GET_SHA_REQ is for retrieving the hash/hmac for data
154 packet of known size.
155 QCEDEV_IOCTL_GET_CMAC_REQ is for retrieving the MAC (using AES CMAC
156 algorithm) for data packet of known size.
157
158 The caller of the IOCTL passes a pointer to the structure shown
159 below, as the second parameter.
160
161 struct qcedev_sha_op_req {
162 struct buf_info data[QCEDEV_MAX_BUFFERS];
163 uint32_t entries;
164 uint32_t data_len;
165 uint8_t digest[QCEDEV_MAX_SHA_DIGEST];
166 uint32_t diglen;
167 uint8_t *authkey;
168 uint32_t authklen;
169 enum qcedev_sha_alg_enum alg;
170 struct qcedev_sha_ctxt ctxt;
171 };
172
173The IOCTLs and associated request data structures are defined in qcedev.h
174
175
176Module parameters:
177==================
178
179The following module parameters are defined in the board init file.
180-CE hardware nase register address
181-Data mover channel used for transfer to/from CE hardware
182These parameters differ in each platform.
183
184
185
186Dependencies:
187=============
188qce driver. Please see Documentation/arm/msm/qce.txt.
189
190
191User space utilities:
192=====================
193
194none
195
196Known issues:
197=============
198
199none.
200
201
202To do:
203======
204 Enhance Cipher functionality:
205 (1) Add support for handling > 32KB for ciphering functionality when
206 - operation is not an "in place" operation (source != destination).
207 (when using PMEM allocated memory)
208
209Limitations:
210============
211 (1) In case of cipher functionality, Driver does not support
212 a combination of different memory sources for source/destination.
213 In other words, memory pointed to by src and dst,
214 must BOTH (src/dst) be "pmem" or BOTH(src/dst) be "vbuf".
215
216 (2) In case of hash functionality, driver does not support handling data
217 buffers allocated via PMEM.
218
219 (3) Do not load this driver if your device already has kernel space apps
220 that need to access the crypto hardware.
221 Make sure to have qcedev module disabled/unloaded and implement your user
222 space application to use the software implementation (ex: openssl/crypto)
223 of the crypto algorithms.
224 (NOTE: Please refer to details on the limitations listed in qce.txt)
225
226 (4) If your device has Playready (Windows Media DRM) application enabled
227 and uses the qcedev module to access the crypto hardware accelerator,
228 please be informed that for performance reasons, the CE hardware will
229 need to be dedicated to playready application. Any other user space
230 application should be implemented to use the software implementation
231 (ex: openssl/crypto) of the crypto algorithms.