hifn7751var.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /* $FreeBSD: src/sys/dev/hifn/hifn7751var.h,v 1.9 2007/03/21 03:42:49 sam Exp $ */
  2. /* $OpenBSD: hifn7751var.h,v 1.42 2002/04/08 17:49:42 jason Exp $ */
  3. /*-
  4. * Invertex AEON / Hifn 7751 driver
  5. * Copyright (c) 1999 Invertex Inc. All rights reserved.
  6. * Copyright (c) 1999 Theo de Raadt
  7. * Copyright (c) 2000-2001 Network Security Technologies, Inc.
  8. * http://www.netsec.net
  9. *
  10. * Please send any comments, feedback, bug-fixes, or feature requests to
  11. * software@invertex.com.
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. *
  17. * 1. Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the distribution.
  22. * 3. The name of the author may not be used to endorse or promote products
  23. * derived from this software without specific prior written permission.
  24. *
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  27. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  28. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  29. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  30. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  31. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  35. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * Effort sponsored in part by the Defense Advanced Research Projects
  38. * Agency (DARPA) and Air Force Research Laboratory, Air Force
  39. * Materiel Command, USAF, under agreement number F30602-01-2-0537.
  40. *
  41. */
  42. #ifndef __HIFN7751VAR_H__
  43. #define __HIFN7751VAR_H__
  44. #ifdef __KERNEL__
  45. /*
  46. * Some configurable values for the driver. By default command+result
  47. * descriptor rings are the same size. The src+dst descriptor rings
  48. * are sized at 3.5x the number of potential commands. Slower parts
  49. * (e.g. 7951) tend to run out of src descriptors; faster parts (7811)
  50. * src+cmd/result descriptors. It's not clear that increasing the size
  51. * of the descriptor rings helps performance significantly as other
  52. * factors tend to come into play (e.g. copying misaligned packets).
  53. */
  54. #define HIFN_D_CMD_RSIZE 24 /* command descriptors */
  55. #define HIFN_D_SRC_RSIZE ((HIFN_D_CMD_RSIZE * 7) / 2) /* source descriptors */
  56. #define HIFN_D_RES_RSIZE HIFN_D_CMD_RSIZE /* result descriptors */
  57. #define HIFN_D_DST_RSIZE HIFN_D_SRC_RSIZE /* destination descriptors */
  58. /*
  59. * Length values for cryptography
  60. */
  61. #define HIFN_DES_KEY_LENGTH 8
  62. #define HIFN_3DES_KEY_LENGTH 24
  63. #define HIFN_MAX_CRYPT_KEY_LENGTH HIFN_3DES_KEY_LENGTH
  64. #define HIFN_IV_LENGTH 8
  65. #define HIFN_AES_IV_LENGTH 16
  66. #define HIFN_MAX_IV_LENGTH HIFN_AES_IV_LENGTH
  67. /*
  68. * Length values for authentication
  69. */
  70. #define HIFN_MAC_KEY_LENGTH 64
  71. #define HIFN_MD5_LENGTH 16
  72. #define HIFN_SHA1_LENGTH 20
  73. #define HIFN_MAC_TRUNC_LENGTH 12
  74. #define MAX_SCATTER 64
  75. /*
  76. * Data structure to hold all 4 rings and any other ring related data.
  77. */
  78. struct hifn_dma {
  79. /*
  80. * Descriptor rings. We add +1 to the size to accomidate the
  81. * jump descriptor.
  82. */
  83. struct hifn_desc cmdr[HIFN_D_CMD_RSIZE+1];
  84. struct hifn_desc srcr[HIFN_D_SRC_RSIZE+1];
  85. struct hifn_desc dstr[HIFN_D_DST_RSIZE+1];
  86. struct hifn_desc resr[HIFN_D_RES_RSIZE+1];
  87. struct hifn_command *hifn_commands[HIFN_D_RES_RSIZE];
  88. u_char command_bufs[HIFN_D_CMD_RSIZE][HIFN_MAX_COMMAND];
  89. u_char result_bufs[HIFN_D_CMD_RSIZE][HIFN_MAX_RESULT];
  90. u_int32_t slop[HIFN_D_CMD_RSIZE];
  91. u_int64_t test_src, test_dst;
  92. /*
  93. * Our current positions for insertion and removal from the desriptor
  94. * rings.
  95. */
  96. int cmdi, srci, dsti, resi;
  97. volatile int cmdu, srcu, dstu, resu;
  98. int cmdk, srck, dstk, resk;
  99. };
  100. struct hifn_session {
  101. int hs_used;
  102. int hs_mlen;
  103. };
  104. #define HIFN_RING_SYNC(sc, r, i, f) \
  105. /* DAVIDM bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap, (f)) */
  106. #define HIFN_CMDR_SYNC(sc, i, f) HIFN_RING_SYNC((sc), cmdr, (i), (f))
  107. #define HIFN_RESR_SYNC(sc, i, f) HIFN_RING_SYNC((sc), resr, (i), (f))
  108. #define HIFN_SRCR_SYNC(sc, i, f) HIFN_RING_SYNC((sc), srcr, (i), (f))
  109. #define HIFN_DSTR_SYNC(sc, i, f) HIFN_RING_SYNC((sc), dstr, (i), (f))
  110. #define HIFN_CMD_SYNC(sc, i, f) \
  111. /* DAVIDM bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap, (f)) */
  112. #define HIFN_RES_SYNC(sc, i, f) \
  113. /* DAVIDM bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap, (f)) */
  114. typedef int bus_size_t;
  115. /*
  116. * Holds data specific to a single HIFN board.
  117. */
  118. struct hifn_softc {
  119. softc_device_decl sc_dev;
  120. struct pci_dev *sc_pcidev; /* PCI device pointer */
  121. spinlock_t sc_mtx; /* per-instance lock */
  122. int sc_num; /* for multiple devs */
  123. ocf_iomem_t sc_bar0;
  124. bus_size_t sc_bar0_lastreg;/* bar0 last reg written */
  125. ocf_iomem_t sc_bar1;
  126. bus_size_t sc_bar1_lastreg;/* bar1 last reg written */
  127. int sc_irq;
  128. u_int32_t sc_dmaier;
  129. u_int32_t sc_drammodel; /* 1=dram, 0=sram */
  130. u_int32_t sc_pllconfig; /* 7954/7955/7956 PLL config */
  131. struct hifn_dma *sc_dma;
  132. dma_addr_t sc_dma_physaddr;/* physical address of sc_dma */
  133. int sc_dmansegs;
  134. int32_t sc_cid;
  135. int sc_maxses;
  136. int sc_nsessions;
  137. struct hifn_session *sc_sessions;
  138. int sc_ramsize;
  139. int sc_flags;
  140. #define HIFN_HAS_RNG 0x1 /* includes random number generator */
  141. #define HIFN_HAS_PUBLIC 0x2 /* includes public key support */
  142. #define HIFN_HAS_AES 0x4 /* includes AES support */
  143. #define HIFN_IS_7811 0x8 /* Hifn 7811 part */
  144. #define HIFN_IS_7956 0x10 /* Hifn 7956/7955 don't have SDRAM */
  145. struct timer_list sc_tickto; /* for managing DMA */
  146. int sc_rngfirst;
  147. int sc_rnghz; /* RNG polling frequency */
  148. int sc_c_busy; /* command ring busy */
  149. int sc_s_busy; /* source data ring busy */
  150. int sc_d_busy; /* destination data ring busy */
  151. int sc_r_busy; /* result ring busy */
  152. int sc_active; /* for initial countdown */
  153. int sc_needwakeup; /* ops q'd wating on resources */
  154. int sc_curbatch; /* # ops submitted w/o int */
  155. int sc_suspended;
  156. #ifdef HIFN_VULCANDEV
  157. struct cdev *sc_pkdev;
  158. #endif
  159. };
  160. #define HIFN_LOCK(_sc) spin_lock_irqsave(&(_sc)->sc_mtx, l_flags)
  161. #define HIFN_UNLOCK(_sc) spin_unlock_irqrestore(&(_sc)->sc_mtx, l_flags)
  162. /*
  163. * hifn_command_t
  164. *
  165. * This is the control structure used to pass commands to hifn_encrypt().
  166. *
  167. * flags
  168. * -----
  169. * Flags is the bitwise "or" values for command configuration. A single
  170. * encrypt direction needs to be set:
  171. *
  172. * HIFN_ENCODE or HIFN_DECODE
  173. *
  174. * To use cryptography, a single crypto algorithm must be included:
  175. *
  176. * HIFN_CRYPT_3DES or HIFN_CRYPT_DES
  177. *
  178. * To use authentication is used, a single MAC algorithm must be included:
  179. *
  180. * HIFN_MAC_MD5 or HIFN_MAC_SHA1
  181. *
  182. * By default MD5 uses a 16 byte hash and SHA-1 uses a 20 byte hash.
  183. * If the value below is set, hash values are truncated or assumed
  184. * truncated to 12 bytes:
  185. *
  186. * HIFN_MAC_TRUNC
  187. *
  188. * Keys for encryption and authentication can be sent as part of a command,
  189. * or the last key value used with a particular session can be retrieved
  190. * and used again if either of these flags are not specified.
  191. *
  192. * HIFN_CRYPT_NEW_KEY, HIFN_MAC_NEW_KEY
  193. *
  194. * session_num
  195. * -----------
  196. * A number between 0 and 2048 (for DRAM models) or a number between
  197. * 0 and 768 (for SRAM models). Those who don't want to use session
  198. * numbers should leave value at zero and send a new crypt key and/or
  199. * new MAC key on every command. If you use session numbers and
  200. * don't send a key with a command, the last key sent for that same
  201. * session number will be used.
  202. *
  203. * Warning: Using session numbers and multiboard at the same time
  204. * is currently broken.
  205. *
  206. * mbuf
  207. * ----
  208. * Either fill in the mbuf pointer and npa=0 or
  209. * fill packp[] and packl[] and set npa to > 0
  210. *
  211. * mac_header_skip
  212. * ---------------
  213. * The number of bytes of the source_buf that are skipped over before
  214. * authentication begins. This must be a number between 0 and 2^16-1
  215. * and can be used by IPsec implementers to skip over IP headers.
  216. * *** Value ignored if authentication not used ***
  217. *
  218. * crypt_header_skip
  219. * -----------------
  220. * The number of bytes of the source_buf that are skipped over before
  221. * the cryptographic operation begins. This must be a number between 0
  222. * and 2^16-1. For IPsec, this number will always be 8 bytes larger
  223. * than the auth_header_skip (to skip over the ESP header).
  224. * *** Value ignored if cryptography not used ***
  225. *
  226. */
  227. struct hifn_operand {
  228. union {
  229. struct sk_buff *skb;
  230. struct uio *io;
  231. unsigned char *buf;
  232. } u;
  233. void *map;
  234. bus_size_t mapsize;
  235. int nsegs;
  236. struct {
  237. dma_addr_t ds_addr;
  238. int ds_len;
  239. } segs[MAX_SCATTER];
  240. };
  241. struct hifn_command {
  242. u_int16_t session_num;
  243. u_int16_t base_masks, cry_masks, mac_masks;
  244. u_int8_t iv[HIFN_MAX_IV_LENGTH], *ck, mac[HIFN_MAC_KEY_LENGTH];
  245. int cklen;
  246. int sloplen, slopidx;
  247. struct hifn_operand src;
  248. struct hifn_operand dst;
  249. struct hifn_softc *softc;
  250. struct cryptop *crp;
  251. struct cryptodesc *enccrd, *maccrd;
  252. };
  253. #define src_skb src.u.skb
  254. #define src_io src.u.io
  255. #define src_map src.map
  256. #define src_mapsize src.mapsize
  257. #define src_segs src.segs
  258. #define src_nsegs src.nsegs
  259. #define src_buf src.u.buf
  260. #define dst_skb dst.u.skb
  261. #define dst_io dst.u.io
  262. #define dst_map dst.map
  263. #define dst_mapsize dst.mapsize
  264. #define dst_segs dst.segs
  265. #define dst_nsegs dst.nsegs
  266. #define dst_buf dst.u.buf
  267. /*
  268. * Return values for hifn_crypto()
  269. */
  270. #define HIFN_CRYPTO_SUCCESS 0
  271. #define HIFN_CRYPTO_BAD_INPUT (-1)
  272. #define HIFN_CRYPTO_RINGS_FULL (-2)
  273. /**************************************************************************
  274. *
  275. * Function: hifn_crypto
  276. *
  277. * Purpose: Called by external drivers to begin an encryption on the
  278. * HIFN board.
  279. *
  280. * Blocking/Non-blocking Issues
  281. * ============================
  282. * The driver cannot block in hifn_crypto (no calls to tsleep) currently.
  283. * hifn_crypto() returns HIFN_CRYPTO_RINGS_FULL if there is not enough
  284. * room in any of the rings for the request to proceed.
  285. *
  286. * Return Values
  287. * =============
  288. * 0 for success, negative values on error
  289. *
  290. * Defines for negative error codes are:
  291. *
  292. * HIFN_CRYPTO_BAD_INPUT : The passed in command had invalid settings.
  293. * HIFN_CRYPTO_RINGS_FULL : All DMA rings were full and non-blocking
  294. * behaviour was requested.
  295. *
  296. *************************************************************************/
  297. /*
  298. * Convert back and forth from 'sid' to 'card' and 'session'
  299. */
  300. #define HIFN_CARD(sid) (((sid) & 0xf0000000) >> 28)
  301. #define HIFN_SESSION(sid) ((sid) & 0x000007ff)
  302. #define HIFN_SID(crd,ses) (((crd) << 28) | ((ses) & 0x7ff))
  303. #endif /* _KERNEL */
  304. struct hifn_stats {
  305. u_int64_t hst_ibytes;
  306. u_int64_t hst_obytes;
  307. u_int32_t hst_ipackets;
  308. u_int32_t hst_opackets;
  309. u_int32_t hst_invalid;
  310. u_int32_t hst_nomem; /* malloc or one of hst_nomem_* */
  311. u_int32_t hst_abort;
  312. u_int32_t hst_noirq; /* IRQ for no reason */
  313. u_int32_t hst_totbatch; /* ops submitted w/o interrupt */
  314. u_int32_t hst_maxbatch; /* max ops submitted together */
  315. u_int32_t hst_unaligned; /* unaligned src caused copy */
  316. /*
  317. * The following divides hst_nomem into more specific buckets.
  318. */
  319. u_int32_t hst_nomem_map; /* bus_dmamap_create failed */
  320. u_int32_t hst_nomem_load; /* bus_dmamap_load_* failed */
  321. u_int32_t hst_nomem_mbuf; /* MGET* failed */
  322. u_int32_t hst_nomem_mcl; /* MCLGET* failed */
  323. u_int32_t hst_nomem_cr; /* out of command/result descriptor */
  324. u_int32_t hst_nomem_sd; /* out of src/dst descriptors */
  325. };
  326. #endif /* __HIFN7751VAR_H__ */