qce.txt 8.1 KB

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