AnilKumar Chimata | e78789a | 2017-04-07 12:18:46 -0700 | [diff] [blame] | 1 | Introduction: |
| 2 | ============= |
| 3 | |
| 4 | This driver provides IOCTLS for user space application to access crypto |
| 5 | engine hardware for the qcedev crypto services. The driver supports the |
| 6 | following 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 | |
| 14 | Hardware description: |
| 15 | ===================== |
| 16 | Crypto 3E provides cipher and hash algorithms as defined in the |
| 17 | 3GPP forum specifications. |
| 18 | |
| 19 | |
| 20 | Software description |
| 21 | ==================== |
| 22 | |
| 23 | The driver is a Linux platform device driver. For an msm target, |
| 24 | there can be multiple crypto devices assigned for QCEDEV. |
| 25 | |
| 26 | The driver is a misc device driver as well. |
| 27 | The following operations are registered in the driver, |
| 28 | -qcedev_ioctl() |
| 29 | -qcedev_open() |
| 30 | -qcedev_release() |
| 31 | |
| 32 | The 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 | |
| 50 | The requests are synchronous. The driver will put the process to |
| 51 | sleep, waiting for the completion of the requests using wait_for_completion(). |
| 52 | |
| 53 | Since the requests are coming out of user space application, before giving |
| 54 | the requests to the low level qce driver, the ioctl requests and the |
| 55 | associated input/output buffer will have to be safe checked, and copied |
| 56 | to/from kernel space. |
| 57 | |
| 58 | The extra copying of requests/buffer can affect the performance. The issue |
| 59 | with copying the data buffer is resolved by having the client use PMEM |
| 60 | allocated buffers. |
| 61 | |
| 62 | NOTE: 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 | |
| 70 | The design of the driver is to allow multiple open, and multiple requests |
| 71 | to be issued from application(s). Therefore, the driver will internally queue |
| 72 | the requests, and serialize the requests to the low level qce (or qce40) driver. |
| 73 | |
| 74 | On an IOCTL request from an application, if there is no outstanding |
| 75 | request, a the driver will issue a "qce" request, otherwise, |
| 76 | the request is queued in the driver queue. The process is suspended |
| 77 | waiting for completion. |
| 78 | |
| 79 | On completion of a request by the low level qce driver, the internal |
| 80 | tasklet (done_tasklet) is scheduled. The sole purpose of done_tasklet is |
| 81 | to call the completion of the current active request (complete()), and |
| 82 | issue more requests to the qce, if any. |
| 83 | When the process wakes up from wait_for_completion(), it will collect the |
| 84 | return code, and return the ioctl. |
| 85 | |
| 86 | A spin lock is used to protect the critical section of internal queue to |
| 87 | be accessed from multiple tasks, SMP, and completion callback |
| 88 | from qce. |
| 89 | |
| 90 | The driver maintains a set of statistics using debug fs. The files are |
| 91 | in /debug/qcedev/stats1, /debug/qcedev/stats2, /debug/qcedev/stats3; |
| 92 | one for each instance of device. Reading the file associated with |
| 93 | a device will retrieve the driver statistics for that device. |
| 94 | Any write to the file will clear the statistics. |
| 95 | |
| 96 | |
| 97 | Power Management |
| 98 | ================ |
| 99 | n/a |
| 100 | |
| 101 | |
| 102 | Interface: |
| 103 | ========== |
| 104 | |
| 105 | Linux user space applications will need to open a handle |
| 106 | (file descriptor) to the qcedev device. This is achieved by doing |
| 107 | the following to retrieve a file descriptor to the device. |
| 108 | |
| 109 | fd = open("/dev/qce", O_RDWR); |
| 110 | .. |
| 111 | ioctl(fd, ...); |
| 112 | |
| 113 | Once a valid fd is retrieved, user can call the following ioctls with |
| 114 | the fd as the first parameter and a pointer to an appropriate data |
| 115 | structure, qcedev_cipher_op_req or qcedev_sha_op_req (depending on |
| 116 | cipher/hash functionality) as the second parameter. |
| 117 | |
| 118 | The 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 | |
| 173 | The IOCTLs and associated request data structures are defined in qcedev.h |
| 174 | |
| 175 | |
| 176 | Module parameters: |
| 177 | ================== |
| 178 | |
| 179 | The 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 |
| 182 | These parameters differ in each platform. |
| 183 | |
| 184 | |
| 185 | |
| 186 | Dependencies: |
| 187 | ============= |
| 188 | qce driver. Please see Documentation/arm/msm/qce.txt. |
| 189 | |
| 190 | |
| 191 | User space utilities: |
| 192 | ===================== |
| 193 | |
| 194 | none |
| 195 | |
| 196 | Known issues: |
| 197 | ============= |
| 198 | |
| 199 | none. |
| 200 | |
| 201 | |
| 202 | To 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 | |
| 209 | Limitations: |
| 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. |