qcedev.txt 7.8 KB

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