1 /* $OpenBSD: noctvar.h,v 1.7 2003/06/02 19:08:58 jason Exp $ */
2
3 /*
4 * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Effort sponsored in part by the Defense Advanced Research Projects
29 * Agency (DARPA) and Air Force Research Laboratory, Air Force
30 * Materiel Command, USAF, under agreement number F30602-01-2-0537.
31 *
32 */
33
34 #define NOCT_RNG_QLEN 15
35 #define NOCT_RNG_ENTRIES (1 << NOCT_RNG_QLEN)
36 #define NOCT_RNG_BUFSIZE (NOCT_RNG_ENTRIES * sizeof(u_int64_t))
37
38 #define NOCT_PKH_QLEN 15
39 #define NOCT_PKH_ENTRIES (1 << NOCT_PKH_QLEN)
40 #define NOCT_PKH_BUFSIZE (NOCT_PKH_ENTRIES * sizeof(union noct_pkh_cmd))
41
42 #define NOCT_EA_QLEN 15
43 #define NOCT_EA_ENTRIES (1 << NOCT_EA_QLEN)
44 #define NOCT_EA_BUFSIZE (NOCT_EA_ENTRIES * sizeof(struct noct_ea_cmd))
45
46 #define NOCT_BN_CACHE_SIZE ((256) * (128 / 8))
47
48 struct noct_workq {
49 SIMPLEQ_ENTRY(noct_workq) q_next;
50 struct cryptop *q_crp;
51 bus_dmamap_t q_dmamap;
52 bus_dma_segment_t q_dmaseg;
53 caddr_t q_buf;
54 u_int8_t q_macbuf[20];
55 };
56
57 struct noct_softc;
58
59 struct noct_bnc_sw {
60 u_long bn_off; /* cache offset */
61 u_long bn_siz; /* cache size */
62 void (*bn_callback)(struct noct_softc *, u_int32_t, int);
63 struct cryptkop *bn_krp;
64 };
65
66 struct noct_softc {
67 struct device sc_dv;
68 bus_space_tag_t sc_st;
69 bus_space_handle_t sc_sh;
70 bus_dma_tag_t sc_dmat;
71 void *sc_ih;
72 bus_size_t sc_rar_last, sc_waw_last;
73 u_int sc_ramsize;
74 int32_t sc_cid; /* cryptodev id */
75
76 u_int64_t *sc_rngbuf;
77 bus_dmamap_t sc_rngmap;
78 struct timeout sc_rngto;
79 int sc_rngtick;
80
81 bus_dmamap_t sc_pkhmap; /* pkh buffer map */
82 bus_dmamap_t sc_bnmap; /* bignumber cache map */
83 union noct_pkh_cmd *sc_pkhcmd; /* pkh command buffers */
84 u_int8_t *sc_bncache; /* bignumber cache buffer */
85 u_int32_t sc_pkhwp; /* pkh write pointer */
86 u_int32_t sc_pkhrp; /* pkh read pointer */
87 struct extent *sc_pkh_bn; /* pkh big number cache usage */
88 struct noct_bnc_sw sc_pkh_bnsw[NOCT_PKH_ENTRIES];
89
90 bus_dmamap_t sc_eamap; /* ea buffer map */
91 u_int32_t sc_eawp; /* ea write pointer */
92 u_int32_t sc_earp; /* ea read pointer */
93 struct noct_ea_cmd *sc_eacmd; /* ea command buffers */
94
95 SIMPLEQ_HEAD(,noct_workq) sc_inq;
96 SIMPLEQ_HEAD(,noct_workq) sc_chipq;
97 SIMPLEQ_HEAD(,noct_workq) sc_outq;
98 };
99
100 #define NOCT_READ_4(sc,r) noct_read_4((sc), (r))
101 #define NOCT_WRITE_4(sc,r,v) noct_write_4((sc), (r), (v))
102 #define NOCT_READ_8(sc,r) noct_read_8((sc), (r))
103 #define NOCT_WRITE_8(sc,r,v) noct_write_8((sc), (r), (v))
104
105 #define NOCT_CARD(sid) (((sid) & 0xf0000000) >> 28)
106 #define NOCT_SESSION(sid) ( (sid) & 0x0fffffff)
107 #define NOCT_SID(crd, sesn) (((crd) << 28) | ((sesn) & 0x0fffffff))
108
109 #define NOCT_WAKEUP(sc) wakeup(&(sc)->sc_eawp)
110 #define NOCT_SLEEP(sc) tsleep(&(sc)->sc_eawp, PWAIT, "noctea", 0)
111