blob: e99f7d7ef6cf7013eb4f2cbfc3f0ca37ddf3cb99 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001Introduction:
2=============
3
4The Qualcomm crypto engine (qce40) driver is a module that
5provides common services for accessing the Qualcomm crypto device.
6Currently, the two main clients of qce40 are
7-qcrypto driver (module provided for accessing CE HW by kernel space apps)
8-qcedev driver (module provided for accessing CE HW by user space apps)
9This module provides the same interface to the clients as does qce.c and is
10based off qce.c. Following are the updates from qce.c
11- Add support for AES XTS mode
12- Add support for CMAC mode
13- Add support for AES CCM mode
14- Add support for SHA1/SHA256 HMAC
15- Read HASH/MAC information directly from CE hardware registers instead of
16 using datamover.
17
18The crypto engine (qce40) module is a client to the DMA driver for the Qualcomm
19DMA device - Application Data Mover (ADM). ADM is used to provide the DMA
20transfer capability between Qualcomm crypto device hardware and DDR memory
21for crypto operations.
22
23 Figure 1.
24 ---------
25
26 Linux kernel
27 (ex:IPSec)<--*Qualcomm crypto driver----+
28 (qcrypto) |
29 (for kernel space app) |
30 |
31 +-->|
32 |
33 | *qce40 <----> Qualcomm
34 | driver ADM driver <---> ADM HW
35 +-->| | |
36 | | |
37 | | |
38 | | |
39 Linux kernel | | |
40 misc device <--- *QCEDEV Driver-------+ | |
41 interface (qcedev) (Reg interface) (DMA interface)
42 (for user space app) \ /
43 \ /
44 \ /
45 \ /
46 \ /
47 \ /
48 \ /
49 Qualcomm crypto CE3 HW
50
51
52 The entities marked with (*) in the Figure 1, are the software components of
53 the Linux Qualcomm crypto modules.
54
55===============
56IMPORTANT NOTE:
57===============
58(1) The CE hardware can be accessed either from user space OR kernel space,
59 at one time. Both user space and kernel space clients cannot access the
60 qce driver (and the CE hardware) at the same time.
61 - If your device has user space apps that needs to access the crypto
62 hardware, make sure to have the qcrypto module disabled/unloaded.
63 This will result in the kernel space apps to use the registered
64 software implementation of the crypto algorithms.
65 - If your device has kernel space apps that needs to access the
66 crypto hardware, make sure to have qcedev module disabled/unloaded
67 and implement your user space application to use the software
68 implemenation (ex: openssl/crypto) of the crypto algorithms.
69
70(2) If your device has Playready(Windows Media DRM) application enabled and
71 uses the qcedev module to access the crypto hardware accelarator,
72 please be informed that for performance reasons, the CE hardware will need
73 to be dedicated to playready application. Any other user space application
74 should be implemented to use the software implemenation (ex: openssl/crypto)
75 of the crypto algorithms.
76
77
78Hardware description:
79=====================
80
81Qualcomm Crypto HW device family provides a series of algorithms implemented
82in the device hardware.
83
84Crypto 2 hardware provides hashing - SHA-1, SHA-256, ciphering - DES, 3DES, AES
85algorithms, and concurrent operations of hashing and ciphering.
86
87In addition to those functions provided by Crypto 2 HW, Crypto 3 HW provides
88fast AES algorithms.
89
90In addition to those functions provided by Crypto 3 HW, Crypto 3E provides
91HMAC-SHA1 hashing algorithm, and Over The Air (OTA) f8/f9 algorithms as
92defined by the 3GPP forum.
93
94
95Software description
96====================
97
98The crypto device is defined as a platform device. The driver is
99independent of the platform. The driver supports multiple instances of
100crypto HW.
101All the platform specific parameters are defined in the board init
102file, eg. arch/arm/mach-msm/board-msm8960.c for MSM8960.
103
104The qce40 driver provide the common services of HW crypto
105access to the two drivers as listed above (qcedev, qcrypto. It sets up
106the crypto HW device for the operation, then it requests ADM driver for
107the DMA of the crypto operation.
108
109Two ADM channels and two command lists (one command list for each
110channel) are involved in an operation.
111
112The setting up of the command lists and the procedure of the operation
113of the crypto device are described in the following sections.
114
115The command lists contains a single command. For the first DMA channel it
116is set up as follows:
117
118 The command is for the DMA transfer from DDR memory to the
119 crypto device to input data to crypto device. The dst crci of the command
120 is set for crci-in for this crypto device.
121
122The command list for the second DMA channel is set up as follows:
123
124 One command to DMA data from crypto device to DDR memory for encryption or
125 decryption output from crypto device.
126
127To accomplish ciphering and authentication concurrent operations, the driver
128performs the following steps:
129 (a). set up HW crypto device
130 (b). hit the crypto go register.
131 (c). issue the DMA command of first channel to the ADM driver,
132 (d). issue the DMA command of 2nd channel to the ADM driver.
133
134SHA1/SHA256 is an authentication/integrity hash algorithm. To accomplish
135hash operation (or any authentication only algorithm), 2nd DMA channel is
136not required. Only steps (a) to (c) are performed.
137
138At the completion of the DMA operation (for (c) and (d)) ADM driver
139invokes the callback registered to the DMA driver. This signifies the end of
140the DMA operation(s). The driver reads the status and other information from
141the CE hardware register. For HASH functions (SHA1/SHA256, HMAC, CMAC and
142CCM) were the MAC/HASH information is read off hardware registers.
143
144[ NOTE: This is different from what is done in the qce module that support
145CE3.x hardware. In CE4.0 there is not CRCI_HASH and hence we cannot rely
146on the data mover to populate the HMAC/SHA information. This information
147is acquired fromte h ahrdware by reading directly from some registers that
148hold this information ]
149
150The driver than nvokes the callback to the qce driver client.
151This signal the completion and the results of the DMA along with the status of
152the CE hardware to the qce40 driver client. This completes a crypto operation.
153
154In the qce40 driver initialization, memory for the two command lists, descriptor
155lists for each crypto device are allocated out of coherent memory, using Linux
156DMA API. The driver pre-configures most of the two ADM command lists
157in the initialization. During each crypto operation, minimal set up is required.
158src_dscr or/and dst_dscr descriptor list of the ADM command are populated
159from the information obtained from the corresponding data structure. eg: for
160AEAD request, the following data structure provides the information:
161
162 struct aead_request *req
163 ......
164 req->assoc
165 req->src
166 req->dst
167
168The DMA address of a scatter list will be retrieved and set up in the
169descriptor list of an ADM command.
170
171Power Management
172================
173 none
174
175
176Interface:
177==========
178
179The interface is defined in kernel/drivers/crypto/msm/inc/qce.h
180
181The clients qcrypto, qcedev drivers are the clients using
182the interfaces.
183
184The following services are provided by the qce driver -
185
186 qce_open(), qce_close(), qce_ablk_cipher_req(),
187 qce_hw_support(), qce_process_sha_req()
188
189 qce_open() is the first request from the client, ex. Qualcomm crypto
190 driver (qcedev, qcrypto), to open a crypto engine. It is normally
191 called at the probe function of the client for a device. During the
192 probe,
193 - ADM command list structure will be set up
194 - Crypto device will be initialized.
195 - Resource associated with the crypto engine is retrieved by doing
196 platform_get_resource() or platform_get_resource_byname().
197
198 The resources for a device are
199 - crci-in, crci-out, crci-hash-done
200 - two DMA channel IDs, one for encryption and decryption input, one for
201 output.
202 - base address of the HW crypto device.
203
204 qce_close() is the last request from the client. Normally, it is
205 called from the remove function of the client.
206
207 qce_hw_support() allows the client to query what is supported
208 by the crypto engine hardware.
209
210 qce_ablk_cipher_req() provides ciphering service to the client.
211 qce_process_sha_req() provides hashing service to the client.
212 qce_aead_req() provides aead service to the client.
213
214
215Module parameters:
216==================
217
218The following module parameters are defined in the board init file.
219-CE hardware base register address
220-Data mover channel used for transfer to/from CE hardware
221These parameters differ in each platform.
222
223
224Dependencies:
225=============
226
227Existing DMA driver.
228The transfers are DMA'ed between the crypto hardware and DDR memory via the
229data mover, ADM. The data transfers are set up to use the existing dma driver.
230
231User space utilities:
232=====================
233 n/a
234
235Known issues:
236=============
237 n/a
238
239To do:
240======
241 n/a