safevar.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*-
  2. * The linux port of this code done by David McCullough
  3. * Copyright (C) 2004-2010 David McCullough <david_mccullough@mcafee.com>
  4. * The license and original author are listed below.
  5. *
  6. * Copyright (c) 2003 Sam Leffler, Errno Consulting
  7. * Copyright (c) 2003 Global Technology Associates, Inc.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * $FreeBSD: src/sys/dev/safe/safevar.h,v 1.2 2006/05/17 18:34:26 pjd Exp $
  32. */
  33. #ifndef _SAFE_SAFEVAR_H_
  34. #define _SAFE_SAFEVAR_H_
  35. /* Maximum queue length */
  36. #ifndef SAFE_MAX_NQUEUE
  37. #define SAFE_MAX_NQUEUE 60
  38. #endif
  39. #define SAFE_MAX_PART 64 /* Maximum scatter/gather depth */
  40. #define SAFE_DMA_BOUNDARY 0 /* No boundary for source DMA ops */
  41. #define SAFE_MAX_DSIZE 2048 /* MCLBYTES Fixed scatter particle size */
  42. #define SAFE_MAX_SSIZE 0x0ffff /* Maximum gather particle size */
  43. #define SAFE_MAX_DMA 0xfffff /* Maximum PE operand size (20 bits) */
  44. /* total src+dst particle descriptors */
  45. #define SAFE_TOTAL_DPART (SAFE_MAX_NQUEUE * SAFE_MAX_PART)
  46. #define SAFE_TOTAL_SPART (SAFE_MAX_NQUEUE * SAFE_MAX_PART)
  47. #define SAFE_RNG_MAXBUFSIZ 128 /* 32-bit words */
  48. #define SAFE_CARD(sid) (((sid) & 0xf0000000) >> 28)
  49. #define SAFE_SESSION(sid) ( (sid) & 0x0fffffff)
  50. #define SAFE_SID(crd, sesn) (((crd) << 28) | ((sesn) & 0x0fffffff))
  51. #define SAFE_DEF_RTY 0xff /* PCI Retry Timeout */
  52. #define SAFE_DEF_TOUT 0xff /* PCI TRDY Timeout */
  53. #define SAFE_DEF_CACHELINE 0x01 /* Cache Line setting */
  54. #ifdef __KERNEL__
  55. /*
  56. * State associated with the allocation of each chunk
  57. * of memory setup for DMA.
  58. */
  59. struct safe_dma_alloc {
  60. dma_addr_t dma_paddr;
  61. void *dma_vaddr;
  62. };
  63. /*
  64. * Cryptographic operand state. One of these exists for each
  65. * source and destination operand passed in from the crypto
  66. * subsystem. When possible source and destination operands
  67. * refer to the same memory. More often they are distinct.
  68. * We track the virtual address of each operand as well as
  69. * where each is mapped for DMA.
  70. */
  71. struct safe_operand {
  72. union {
  73. struct sk_buff *skb;
  74. struct uio *io;
  75. } u;
  76. void *map;
  77. int mapsize; /* total number of bytes in segs */
  78. struct {
  79. dma_addr_t ds_addr;
  80. int ds_len;
  81. int ds_tlen;
  82. } segs[SAFE_MAX_PART];
  83. int nsegs;
  84. };
  85. /*
  86. * Packet engine ring entry and cryptographic operation state.
  87. * The packet engine requires a ring of descriptors that contain
  88. * pointers to various cryptographic state. However the ring
  89. * configuration register allows you to specify an arbitrary size
  90. * for ring entries. We use this feature to collect most of the
  91. * state for each cryptographic request into one spot. Other than
  92. * ring entries only the ``particle descriptors'' (scatter/gather
  93. * lists) and the actual operand data are kept separate. The
  94. * particle descriptors must also be organized in rings. The
  95. * operand data can be located aribtrarily (modulo alignment constraints).
  96. *
  97. * Note that the descriptor ring is mapped onto the PCI bus so
  98. * the hardware can DMA data. This means the entire ring must be
  99. * contiguous.
  100. */
  101. struct safe_ringentry {
  102. struct safe_desc re_desc; /* command descriptor */
  103. struct safe_sarec re_sa; /* SA record */
  104. struct safe_sastate re_sastate; /* SA state record */
  105. struct cryptop *re_crp; /* crypto operation */
  106. struct safe_operand re_src; /* source operand */
  107. struct safe_operand re_dst; /* destination operand */
  108. int re_sesn; /* crypto session ID */
  109. int re_flags;
  110. #define SAFE_QFLAGS_COPYOUTIV 0x1 /* copy back on completion */
  111. #define SAFE_QFLAGS_COPYOUTICV 0x2 /* copy back on completion */
  112. };
  113. #define re_src_skb re_src.u.skb
  114. #define re_src_io re_src.u.io
  115. #define re_src_map re_src.map
  116. #define re_src_nsegs re_src.nsegs
  117. #define re_src_segs re_src.segs
  118. #define re_src_mapsize re_src.mapsize
  119. #define re_dst_skb re_dst.u.skb
  120. #define re_dst_io re_dst.u.io
  121. #define re_dst_map re_dst.map
  122. #define re_dst_nsegs re_dst.nsegs
  123. #define re_dst_segs re_dst.segs
  124. #define re_dst_mapsize re_dst.mapsize
  125. struct rndstate_test;
  126. struct safe_session {
  127. u_int32_t ses_used;
  128. u_int32_t ses_klen; /* key length in bits */
  129. u_int32_t ses_key[8]; /* DES/3DES/AES key */
  130. u_int32_t ses_mlen; /* hmac length in bytes */
  131. u_int32_t ses_hminner[5]; /* hmac inner state */
  132. u_int32_t ses_hmouter[5]; /* hmac outer state */
  133. };
  134. struct safe_pkq {
  135. struct list_head pkq_list;
  136. struct cryptkop *pkq_krp;
  137. };
  138. struct safe_softc {
  139. softc_device_decl sc_dev;
  140. u32 sc_irq;
  141. struct pci_dev *sc_pcidev;
  142. ocf_iomem_t sc_base_addr;
  143. u_int sc_chiprev; /* major/minor chip revision */
  144. int sc_flags; /* device specific flags */
  145. #define SAFE_FLAGS_KEY 0x01 /* has key accelerator */
  146. #define SAFE_FLAGS_RNG 0x02 /* hardware rng */
  147. int sc_suspended;
  148. int sc_needwakeup; /* notify crypto layer */
  149. int32_t sc_cid; /* crypto tag */
  150. struct safe_dma_alloc sc_ringalloc; /* PE ring allocation state */
  151. struct safe_ringentry *sc_ring; /* PE ring */
  152. struct safe_ringentry *sc_ringtop; /* PE ring top */
  153. struct safe_ringentry *sc_front; /* next free entry */
  154. struct safe_ringentry *sc_back; /* next pending entry */
  155. int sc_nqchip; /* # passed to chip */
  156. spinlock_t sc_ringmtx; /* PE ring lock */
  157. struct safe_pdesc *sc_spring; /* src particle ring */
  158. struct safe_pdesc *sc_springtop; /* src particle ring top */
  159. struct safe_pdesc *sc_spfree; /* next free src particle */
  160. struct safe_dma_alloc sc_spalloc; /* src particle ring state */
  161. struct safe_pdesc *sc_dpring; /* dest particle ring */
  162. struct safe_pdesc *sc_dpringtop; /* dest particle ring top */
  163. struct safe_pdesc *sc_dpfree; /* next free dest particle */
  164. struct safe_dma_alloc sc_dpalloc; /* dst particle ring state */
  165. int sc_nsessions; /* # of sessions */
  166. struct safe_session *sc_sessions; /* sessions */
  167. struct timer_list sc_pkto; /* PK polling */
  168. spinlock_t sc_pkmtx; /* PK lock */
  169. struct list_head sc_pkq; /* queue of PK requests */
  170. struct safe_pkq *sc_pkq_cur; /* current processing request */
  171. u_int32_t sc_pk_reslen, sc_pk_resoff;
  172. int sc_max_dsize; /* maximum safe DMA size */
  173. };
  174. #endif /* __KERNEL__ */
  175. struct safe_stats {
  176. u_int64_t st_ibytes;
  177. u_int64_t st_obytes;
  178. u_int32_t st_ipackets;
  179. u_int32_t st_opackets;
  180. u_int32_t st_invalid; /* invalid argument */
  181. u_int32_t st_badsession; /* invalid session id */
  182. u_int32_t st_badflags; /* flags indicate !(mbuf | uio) */
  183. u_int32_t st_nodesc; /* op submitted w/o descriptors */
  184. u_int32_t st_badalg; /* unsupported algorithm */
  185. u_int32_t st_ringfull; /* PE descriptor ring full */
  186. u_int32_t st_peoperr; /* PE marked error */
  187. u_int32_t st_dmaerr; /* PE DMA error */
  188. u_int32_t st_bypasstoobig; /* bypass > 96 bytes */
  189. u_int32_t st_skipmismatch; /* enc part begins before auth part */
  190. u_int32_t st_lenmismatch; /* enc length different auth length */
  191. u_int32_t st_coffmisaligned; /* crypto offset not 32-bit aligned */
  192. u_int32_t st_cofftoobig; /* crypto offset > 255 words */
  193. u_int32_t st_iovmisaligned; /* iov op not aligned */
  194. u_int32_t st_iovnotuniform; /* iov op not suitable */
  195. u_int32_t st_unaligned; /* unaligned src caused copy */
  196. u_int32_t st_notuniform; /* non-uniform src caused copy */
  197. u_int32_t st_nomap; /* bus_dmamap_create failed */
  198. u_int32_t st_noload; /* bus_dmamap_load_* failed */
  199. u_int32_t st_nombuf; /* MGET* failed */
  200. u_int32_t st_nomcl; /* MCLGET* failed */
  201. u_int32_t st_maxqchip; /* max mcr1 ops out for processing */
  202. u_int32_t st_rng; /* RNG requests */
  203. u_int32_t st_rngalarm; /* RNG alarm requests */
  204. u_int32_t st_noicvcopy; /* ICV data copies suppressed */
  205. };
  206. #endif /* _SAFE_SAFEVAR_H_ */