caamalg_qi2.h 5.7 KB

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