Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | Introduction: |
| 2 | ============= |
| 3 | |
| 4 | The Qualcomm crypto engine (qce40) driver is a module that |
| 5 | provides common services for accessing the Qualcomm crypto device. |
| 6 | Currently, 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) |
| 9 | This module provides the same interface to the clients as does qce.c and is |
| 10 | based 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 | |
| 18 | The crypto engine (qce40) module is a client to the DMA driver for the Qualcomm |
| 19 | DMA device - Application Data Mover (ADM). ADM is used to provide the DMA |
| 20 | transfer capability between Qualcomm crypto device hardware and DDR memory |
| 21 | for 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 | =============== |
| 56 | IMPORTANT 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 | |
| 78 | Hardware description: |
| 79 | ===================== |
| 80 | |
| 81 | Qualcomm Crypto HW device family provides a series of algorithms implemented |
| 82 | in the device hardware. |
| 83 | |
| 84 | Crypto 2 hardware provides hashing - SHA-1, SHA-256, ciphering - DES, 3DES, AES |
| 85 | algorithms, and concurrent operations of hashing and ciphering. |
| 86 | |
| 87 | In addition to those functions provided by Crypto 2 HW, Crypto 3 HW provides |
| 88 | fast AES algorithms. |
| 89 | |
| 90 | In addition to those functions provided by Crypto 3 HW, Crypto 3E provides |
| 91 | HMAC-SHA1 hashing algorithm, and Over The Air (OTA) f8/f9 algorithms as |
| 92 | defined by the 3GPP forum. |
| 93 | |
| 94 | |
| 95 | Software description |
| 96 | ==================== |
| 97 | |
| 98 | The crypto device is defined as a platform device. The driver is |
| 99 | independent of the platform. The driver supports multiple instances of |
| 100 | crypto HW. |
| 101 | All the platform specific parameters are defined in the board init |
| 102 | file, eg. arch/arm/mach-msm/board-msm8960.c for MSM8960. |
| 103 | |
| 104 | The qce40 driver provide the common services of HW crypto |
| 105 | access to the two drivers as listed above (qcedev, qcrypto. It sets up |
| 106 | the crypto HW device for the operation, then it requests ADM driver for |
| 107 | the DMA of the crypto operation. |
| 108 | |
| 109 | Two ADM channels and two command lists (one command list for each |
| 110 | channel) are involved in an operation. |
| 111 | |
| 112 | The setting up of the command lists and the procedure of the operation |
| 113 | of the crypto device are described in the following sections. |
| 114 | |
| 115 | The command lists contains a single command. For the first DMA channel it |
| 116 | is 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 | |
| 122 | The 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 | |
| 127 | To accomplish ciphering and authentication concurrent operations, the driver |
| 128 | performs 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 | |
| 134 | SHA1/SHA256 is an authentication/integrity hash algorithm. To accomplish |
| 135 | hash operation (or any authentication only algorithm), 2nd DMA channel is |
| 136 | not required. Only steps (a) to (c) are performed. |
| 137 | |
| 138 | At the completion of the DMA operation (for (c) and (d)) ADM driver |
| 139 | invokes the callback registered to the DMA driver. This signifies the end of |
| 140 | the DMA operation(s). The driver reads the status and other information from |
| 141 | the CE hardware register. For HASH functions (SHA1/SHA256, HMAC, CMAC and |
| 142 | CCM) 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 |
| 145 | CE3.x hardware. In CE4.0 there is not CRCI_HASH and hence we cannot rely |
| 146 | on the data mover to populate the HMAC/SHA information. This information |
| 147 | is acquired fromte h ahrdware by reading directly from some registers that |
| 148 | hold this information ] |
| 149 | |
| 150 | The driver than nvokes the callback to the qce driver client. |
| 151 | This signal the completion and the results of the DMA along with the status of |
| 152 | the CE hardware to the qce40 driver client. This completes a crypto operation. |
| 153 | |
| 154 | In the qce40 driver initialization, memory for the two command lists, descriptor |
| 155 | lists for each crypto device are allocated out of coherent memory, using Linux |
| 156 | DMA API. The driver pre-configures most of the two ADM command lists |
| 157 | in the initialization. During each crypto operation, minimal set up is required. |
| 158 | src_dscr or/and dst_dscr descriptor list of the ADM command are populated |
| 159 | from the information obtained from the corresponding data structure. eg: for |
| 160 | AEAD 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 | |
| 168 | The DMA address of a scatter list will be retrieved and set up in the |
| 169 | descriptor list of an ADM command. |
| 170 | |
| 171 | Power Management |
| 172 | ================ |
| 173 | none |
| 174 | |
| 175 | |
| 176 | Interface: |
| 177 | ========== |
| 178 | |
| 179 | The interface is defined in kernel/drivers/crypto/msm/inc/qce.h |
| 180 | |
| 181 | The clients qcrypto, qcedev drivers are the clients using |
| 182 | the interfaces. |
| 183 | |
| 184 | The 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 | |
| 215 | Module parameters: |
| 216 | ================== |
| 217 | |
| 218 | The 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 |
| 221 | These parameters differ in each platform. |
| 222 | |
| 223 | |
| 224 | Dependencies: |
| 225 | ============= |
| 226 | |
| 227 | Existing DMA driver. |
| 228 | The transfers are DMA'ed between the crypto hardware and DDR memory via the |
| 229 | data mover, ADM. The data transfers are set up to use the existing dma driver. |
| 230 | |
| 231 | User space utilities: |
| 232 | ===================== |
| 233 | n/a |
| 234 | |
| 235 | Known issues: |
| 236 | ============= |
| 237 | n/a |
| 238 | |
| 239 | To do: |
| 240 | ====== |
| 241 | n/a |