caamalg_qi2.h 5.6 KB

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