qce40.txt 8.6 KB

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