caamalg_qi2.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 <crypto/internal/skcipher.h>
  9. #include <linux/compiler_attributes.h>
  10. #include <soc/fsl/dpaa2-io.h>
  11. #include <soc/fsl/dpaa2-fd.h>
  12. #include <linux/threads.h>
  13. #include <linux/netdevice.h>
  14. #include "dpseci.h"
  15. #include "desc_constr.h"
  16. #define DPAA2_CAAM_STORE_SIZE 16
  17. /* NAPI weight *must* be a multiple of the store size. */
  18. #define DPAA2_CAAM_NAPI_WEIGHT 512
  19. /* The congestion entrance threshold was chosen so that on LS2088
  20. * we support the maximum throughput for the available memory
  21. */
  22. #define DPAA2_SEC_CONG_ENTRY_THRESH (128 * 1024 * 1024)
  23. #define DPAA2_SEC_CONG_EXIT_THRESH (DPAA2_SEC_CONG_ENTRY_THRESH * 9 / 10)
  24. /**
  25. * dpaa2_caam_priv - driver private data
  26. * @dpseci_id: DPSECI object unique ID
  27. * @major_ver: DPSECI major version
  28. * @minor_ver: DPSECI minor version
  29. * @dpseci_attr: DPSECI attributes
  30. * @sec_attr: SEC engine attributes
  31. * @rx_queue_attr: array of Rx queue attributes
  32. * @tx_queue_attr: array of Tx queue attributes
  33. * @cscn_mem: pointer to memory region containing the congestion SCN
  34. * it's size is larger than to accommodate alignment
  35. * @cscn_dma: dma address used by the QMAN to write CSCN messages
  36. * @dev: device associated with the DPSECI object
  37. * @mc_io: pointer to MC portal's I/O object
  38. * @domain: IOMMU domain
  39. * @ppriv: per CPU pointers to privata data
  40. */
  41. struct dpaa2_caam_priv {
  42. int dpsec_id;
  43. u16 major_ver;
  44. u16 minor_ver;
  45. struct dpseci_attr dpseci_attr;
  46. struct dpseci_sec_attr sec_attr;
  47. struct dpseci_rx_queue_attr rx_queue_attr[DPSECI_MAX_QUEUE_NUM];
  48. struct dpseci_tx_queue_attr tx_queue_attr[DPSECI_MAX_QUEUE_NUM];
  49. int num_pairs;
  50. /* congestion */
  51. void *cscn_mem;
  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. struct dentry *dfs_root;
  58. };
  59. /**
  60. * dpaa2_caam_priv_per_cpu - per CPU private data
  61. * @napi: napi structure
  62. * @net_dev: netdev used by napi
  63. * @req_fqid: (virtual) request (Tx / enqueue) FQID
  64. * @rsp_fqid: (virtual) response (Rx / dequeue) FQID
  65. * @prio: internal queue number - index for dpaa2_caam_priv.*_queue_attr
  66. * @nctx: notification context of response FQ
  67. * @store: where dequeued frames are stored
  68. * @priv: backpointer to dpaa2_caam_priv
  69. * @dpio: portal used for data path operations
  70. */
  71. struct dpaa2_caam_priv_per_cpu {
  72. struct napi_struct napi;
  73. struct net_device *net_dev;
  74. int req_fqid;
  75. int rsp_fqid;
  76. int prio;
  77. struct dpaa2_io_notification_ctx nctx;
  78. struct dpaa2_io_store *store;
  79. struct dpaa2_caam_priv *priv;
  80. struct dpaa2_io *dpio;
  81. };
  82. /* Length of a single buffer in the QI driver memory cache */
  83. #define CAAM_QI_MEMCACHE_SIZE 512
  84. /*
  85. * aead_edesc - s/w-extended aead descriptor
  86. * @src_nents: number of segments in input scatterlist
  87. * @dst_nents: number of segments in output scatterlist
  88. * @iv_dma: dma address of iv for checking continuity and link table
  89. * @qm_sg_bytes: length of dma mapped h/w link table
  90. * @qm_sg_dma: bus physical mapped address of h/w link table
  91. * @assoclen: associated data length, in CAAM endianness
  92. * @assoclen_dma: bus physical mapped address of req->assoclen
  93. * @sgt: the h/w link table, followed by IV
  94. */
  95. struct aead_edesc {
  96. int src_nents;
  97. int dst_nents;
  98. dma_addr_t iv_dma;
  99. int qm_sg_bytes;
  100. dma_addr_t qm_sg_dma;
  101. unsigned int assoclen;
  102. dma_addr_t assoclen_dma;
  103. struct dpaa2_sg_entry sgt[];
  104. };
  105. /*
  106. * skcipher_edesc - s/w-extended skcipher descriptor
  107. * @src_nents: number of segments in input scatterlist
  108. * @dst_nents: number of segments in output scatterlist
  109. * @iv_dma: dma address of iv for checking continuity and link table
  110. * @qm_sg_bytes: length of dma mapped qm_sg space
  111. * @qm_sg_dma: I/O virtual address of h/w link table
  112. * @sgt: the h/w link table, followed by IV
  113. */
  114. struct skcipher_edesc {
  115. int src_nents;
  116. int dst_nents;
  117. dma_addr_t iv_dma;
  118. int qm_sg_bytes;
  119. dma_addr_t qm_sg_dma;
  120. struct dpaa2_sg_entry sgt[];
  121. };
  122. /*
  123. * ahash_edesc - s/w-extended ahash descriptor
  124. * @qm_sg_dma: I/O virtual address of h/w link table
  125. * @src_nents: number of segments in input scatterlist
  126. * @qm_sg_bytes: length of dma mapped qm_sg space
  127. * @sgt: pointer to h/w link table
  128. */
  129. struct ahash_edesc {
  130. dma_addr_t qm_sg_dma;
  131. int src_nents;
  132. int qm_sg_bytes;
  133. struct dpaa2_sg_entry sgt[];
  134. };
  135. /**
  136. * caam_flc - Flow Context (FLC)
  137. * @flc: Flow Context options
  138. * @sh_desc: Shared Descriptor
  139. */
  140. struct caam_flc {
  141. u32 flc[16];
  142. u32 sh_desc[MAX_SDLEN];
  143. } __aligned(CRYPTO_DMA_ALIGN);
  144. enum optype {
  145. ENCRYPT = 0,
  146. DECRYPT,
  147. NUM_OP
  148. };
  149. /**
  150. * caam_request - the request structure the driver application should fill while
  151. * submitting a job to driver.
  152. * @fd_flt: Frame list table defining input and output
  153. * fd_flt[0] - FLE pointing to output buffer
  154. * fd_flt[1] - FLE pointing to input buffer
  155. * @fd_flt_dma: DMA address for the frame list table
  156. * @flc: Flow Context
  157. * @flc_dma: I/O virtual address of Flow Context
  158. * @cbk: Callback function to invoke when job is completed
  159. * @ctx: arbit context attached with request by the application
  160. * @edesc: extended descriptor; points to one of {skcipher,aead}_edesc
  161. */
  162. struct caam_request {
  163. struct dpaa2_fl_entry fd_flt[2] __aligned(CRYPTO_DMA_ALIGN);
  164. dma_addr_t fd_flt_dma;
  165. struct caam_flc *flc;
  166. dma_addr_t flc_dma;
  167. void (*cbk)(void *ctx, u32 err);
  168. void *ctx;
  169. void *edesc;
  170. struct skcipher_request fallback_req;
  171. };
  172. /**
  173. * dpaa2_caam_enqueue() - enqueue a crypto request
  174. * @dev: device associated with the DPSECI object
  175. * @req: pointer to caam_request
  176. */
  177. int dpaa2_caam_enqueue(struct device *dev, struct caam_request *req);
  178. #endif /* _CAAMALG_QI2_H_ */