caamalg_qi2.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
  2. /*
  3. * Copyright 2015-2016 Freescale Semiconductor Inc.
  4. * Copyright 2017-2018 NXP
  5. */
  6. #ifndef _CAAMALG_QI2_H_
  7. #define _CAAMALG_QI2_H_
  8. #include <soc/fsl/dpaa2-io.h>
  9. #include <soc/fsl/dpaa2-fd.h>
  10. #include <linux/threads.h>
  11. #include "dpseci.h"
  12. #include "desc_constr.h"
  13. #define DPAA2_CAAM_STORE_SIZE 16
  14. /* NAPI weight *must* be a multiple of the store size. */
  15. #define DPAA2_CAAM_NAPI_WEIGHT 64
  16. /* The congestion entrance threshold was chosen so that on LS2088
  17. * we support the maximum throughput for the available memory
  18. */
  19. #define DPAA2_SEC_CONG_ENTRY_THRESH (128 * 1024 * 1024)
  20. #define DPAA2_SEC_CONG_EXIT_THRESH (DPAA2_SEC_CONG_ENTRY_THRESH * 9 / 10)
  21. /**
  22. * dpaa2_caam_priv - driver private data
  23. * @dpseci_id: DPSECI object unique ID
  24. * @major_ver: DPSECI major version
  25. * @minor_ver: DPSECI minor version
  26. * @dpseci_attr: DPSECI attributes
  27. * @sec_attr: SEC engine attributes
  28. * @rx_queue_attr: array of Rx queue attributes
  29. * @tx_queue_attr: array of Tx queue attributes
  30. * @cscn_mem: pointer to memory region containing the congestion SCN
  31. * it's size is larger than to accommodate alignment
  32. * @cscn_mem_aligned: pointer to congestion SCN; it is computed as
  33. * PTR_ALIGN(cscn_mem, DPAA2_CSCN_ALIGN)
  34. * @cscn_dma: dma address used by the QMAN to write CSCN messages
  35. * @dev: device associated with the DPSECI object
  36. * @mc_io: pointer to MC portal's I/O object
  37. * @domain: IOMMU domain
  38. * @ppriv: per CPU pointers to privata data
  39. */
  40. struct dpaa2_caam_priv {
  41. int dpsec_id;
  42. u16 major_ver;
  43. u16 minor_ver;
  44. struct dpseci_attr dpseci_attr;
  45. struct dpseci_sec_attr sec_attr;
  46. struct dpseci_rx_queue_attr rx_queue_attr[DPSECI_MAX_QUEUE_NUM];
  47. struct dpseci_tx_queue_attr tx_queue_attr[DPSECI_MAX_QUEUE_NUM];
  48. int num_pairs;
  49. /* congestion */
  50. void *cscn_mem;
  51. void *cscn_mem_aligned;
  52. dma_addr_t cscn_dma;
  53. struct device *dev;
  54. struct fsl_mc_io *mc_io;
  55. struct iommu_domain *domain;
  56. struct dpaa2_caam_priv_per_cpu __percpu *ppriv;
  57. };
  58. /**
  59. * dpaa2_caam_priv_per_cpu - per CPU private data
  60. * @napi: napi structure
  61. * @net_dev: netdev used by napi
  62. * @req_fqid: (virtual) request (Tx / enqueue) FQID
  63. * @rsp_fqid: (virtual) response (Rx / dequeue) FQID
  64. * @prio: internal queue number - index for dpaa2_caam_priv.*_queue_attr
  65. * @nctx: notification context of response FQ
  66. * @store: where dequeued frames are stored
  67. * @priv: backpointer to dpaa2_caam_priv
  68. */
  69. struct dpaa2_caam_priv_per_cpu {
  70. struct napi_struct napi;
  71. struct net_device net_dev;
  72. int req_fqid;
  73. int rsp_fqid;
  74. int prio;
  75. struct dpaa2_io_notification_ctx nctx;
  76. struct dpaa2_io_store *store;
  77. struct dpaa2_caam_priv *priv;
  78. };
  79. /*
  80. * The CAAM QI hardware constructs a job descriptor which points
  81. * to shared descriptor (as pointed by context_a of FQ to CAAM).
  82. * When the job descriptor is executed by deco, the whole job
  83. * descriptor together with shared descriptor gets loaded in
  84. * deco buffer which is 64 words long (each 32-bit).
  85. *
  86. * The job descriptor constructed by QI hardware has layout:
  87. *
  88. * HEADER (1 word)
  89. * Shdesc ptr (1 or 2 words)
  90. * SEQ_OUT_PTR (1 word)
  91. * Out ptr (1 or 2 words)
  92. * Out length (1 word)
  93. * SEQ_IN_PTR (1 word)
  94. * In ptr (1 or 2 words)
  95. * In length (1 word)
  96. *
  97. * The shdesc ptr is used to fetch shared descriptor contents
  98. * into deco buffer.
  99. *
  100. * Apart from shdesc contents, the total number of words that
  101. * get loaded in deco buffer are '8' or '11'. The remaining words
  102. * in deco buffer can be used for storing shared descriptor.
  103. */
  104. #define MAX_SDLEN ((CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN) / CAAM_CMD_SZ)
  105. /* Length of a single buffer in the QI driver memory cache */
  106. #define CAAM_QI_MEMCACHE_SIZE 512
  107. /*
  108. * aead_edesc - s/w-extended aead descriptor
  109. * @src_nents: number of segments in input scatterlist
  110. * @dst_nents: number of segments in output scatterlist
  111. * @iv_dma: dma address of iv for checking continuity and link table
  112. * @qm_sg_bytes: length of dma mapped h/w link table
  113. * @qm_sg_dma: bus physical mapped address of h/w link table
  114. * @assoclen: associated data length, in CAAM endianness
  115. * @assoclen_dma: bus physical mapped address of req->assoclen
  116. * @sgt: the h/w link table, followed by IV
  117. */
  118. struct aead_edesc {
  119. int src_nents;
  120. int dst_nents;
  121. dma_addr_t iv_dma;
  122. int qm_sg_bytes;
  123. dma_addr_t qm_sg_dma;
  124. unsigned int assoclen;
  125. dma_addr_t assoclen_dma;
  126. struct dpaa2_sg_entry sgt[0];
  127. };
  128. /*
  129. * skcipher_edesc - s/w-extended skcipher descriptor
  130. * @src_nents: number of segments in input scatterlist
  131. * @dst_nents: number of segments in output scatterlist
  132. * @iv_dma: dma address of iv for checking continuity and link table
  133. * @qm_sg_bytes: length of dma mapped qm_sg space
  134. * @qm_sg_dma: I/O virtual address of h/w link table
  135. * @sgt: the h/w link table, followed by IV
  136. */
  137. struct skcipher_edesc {
  138. int src_nents;
  139. int dst_nents;
  140. dma_addr_t iv_dma;
  141. int qm_sg_bytes;
  142. dma_addr_t qm_sg_dma;
  143. struct dpaa2_sg_entry sgt[0];
  144. };
  145. /*
  146. * ahash_edesc - s/w-extended ahash descriptor
  147. * @dst_dma: I/O virtual address of req->result
  148. * @qm_sg_dma: I/O virtual address of h/w link table
  149. * @src_nents: number of segments in input scatterlist
  150. * @qm_sg_bytes: length of dma mapped qm_sg space
  151. * @sgt: pointer to h/w link table
  152. */
  153. struct ahash_edesc {
  154. dma_addr_t dst_dma;
  155. dma_addr_t qm_sg_dma;
  156. int src_nents;
  157. int qm_sg_bytes;
  158. struct dpaa2_sg_entry sgt[0];
  159. };
  160. /**
  161. * caam_flc - Flow Context (FLC)
  162. * @flc: Flow Context options
  163. * @sh_desc: Shared Descriptor
  164. */
  165. struct caam_flc {
  166. u32 flc[16];
  167. u32 sh_desc[MAX_SDLEN];
  168. } ____cacheline_aligned;
  169. enum optype {
  170. ENCRYPT = 0,
  171. DECRYPT,
  172. NUM_OP
  173. };
  174. /**
  175. * caam_request - the request structure the driver application should fill while
  176. * submitting a job to driver.
  177. * @fd_flt: Frame list table defining input and output
  178. * fd_flt[0] - FLE pointing to output buffer
  179. * fd_flt[1] - FLE pointing to input buffer
  180. * @fd_flt_dma: DMA address for the frame list table
  181. * @flc: Flow Context
  182. * @flc_dma: I/O virtual address of Flow Context
  183. * @cbk: Callback function to invoke when job is completed
  184. * @ctx: arbit context attached with request by the application
  185. * @edesc: extended descriptor; points to one of {skcipher,aead}_edesc
  186. */
  187. struct caam_request {
  188. struct dpaa2_fl_entry fd_flt[2];
  189. dma_addr_t fd_flt_dma;
  190. struct caam_flc *flc;
  191. dma_addr_t flc_dma;
  192. void (*cbk)(void *ctx, u32 err);
  193. void *ctx;
  194. void *edesc;
  195. };
  196. /**
  197. * dpaa2_caam_enqueue() - enqueue a crypto request
  198. * @dev: device associated with the DPSECI object
  199. * @req: pointer to caam_request
  200. */
  201. int dpaa2_caam_enqueue(struct device *dev, struct caam_request *req);
  202. #endif /* _CAAMALG_QI2_H_ */