ubsecvar.h revision 1.9 1 1.9 bad /* $NetBSD: ubsecvar.h,v 1.9 2014/04/19 12:29:24 bad Exp $ */
2 1.9 bad /* $OpenBSD: ubsecvar.h,v 1.38 2009/03/27 13:31:30 reyk Exp $ */
3 1.1 jonathan
4 1.1 jonathan /*
5 1.1 jonathan * Copyright (c) 2000 Theo de Raadt
6 1.1 jonathan * Copyright (c) 2001 Patrik Lindergren (patrik (at) ipunplugged.com)
7 1.1 jonathan *
8 1.1 jonathan * Redistribution and use in source and binary forms, with or without
9 1.1 jonathan * modification, are permitted provided that the following conditions
10 1.1 jonathan * are met:
11 1.1 jonathan *
12 1.1 jonathan * 1. Redistributions of source code must retain the above copyright
13 1.1 jonathan * notice, this list of conditions and the following disclaimer.
14 1.1 jonathan * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 jonathan * notice, this list of conditions and the following disclaimer in the
16 1.1 jonathan * documentation and/or other materials provided with the distribution.
17 1.1 jonathan *
18 1.1 jonathan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 jonathan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 jonathan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 jonathan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 jonathan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 jonathan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 jonathan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 jonathan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 jonathan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 jonathan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 jonathan *
29 1.1 jonathan * Effort sponsored in part by the Defense Advanced Research Projects
30 1.1 jonathan * Agency (DARPA) and Air Force Research Laboratory, Air Force
31 1.1 jonathan * Materiel Command, USAF, under agreement number F30602-01-2-0537.
32 1.1 jonathan *
33 1.1 jonathan */
34 1.1 jonathan
35 1.1 jonathan /* Maximum queue length */
36 1.1 jonathan #ifndef UBS_MAX_NQUEUE
37 1.1 jonathan #define UBS_MAX_NQUEUE 60
38 1.1 jonathan #endif
39 1.1 jonathan
40 1.1 jonathan #define UBS_MAX_SCATTER 64 /* Maximum scatter/gather depth */
41 1.1 jonathan
42 1.1 jonathan #ifndef UBS_MAX_AGGR
43 1.7 bad #define UBS_MAX_AGGR 17 /* Maximum aggregation count */
44 1.7 bad #endif
45 1.7 bad
46 1.7 bad #ifndef UBS_MIN_AGGR
47 1.7 bad #define UBS_MIN_AGGR 5 /* < 5827, Maximum aggregation count */
48 1.1 jonathan #endif
49 1.1 jonathan
50 1.1 jonathan #define UBSEC_CARD(sid) (((sid) & 0xf0000000) >> 28)
51 1.1 jonathan #define UBSEC_SESSION(sid) ( (sid) & 0x0fffffff)
52 1.1 jonathan #define UBSEC_SID(crd, sesn) (((crd) << 28) | ((sesn) & 0x0fffffff))
53 1.1 jonathan
54 1.1 jonathan #define UBS_DEF_RTY 0xff /* PCI Retry Timeout */
55 1.1 jonathan #define UBS_DEF_TOUT 0xff /* PCI TRDY Timeout */
56 1.1 jonathan #define UBS_DEF_CACHELINE 0x01 /* Cache Line setting */
57 1.1 jonathan
58 1.1 jonathan struct ubsec_dma_alloc {
59 1.1 jonathan u_int32_t dma_paddr;
60 1.3 christos void * dma_vaddr;
61 1.1 jonathan bus_dmamap_t dma_map;
62 1.1 jonathan bus_dma_segment_t dma_seg;
63 1.1 jonathan bus_size_t dma_size;
64 1.1 jonathan int dma_nseg;
65 1.1 jonathan };
66 1.1 jonathan
67 1.1 jonathan struct ubsec_q2 {
68 1.1 jonathan SIMPLEQ_ENTRY(ubsec_q2) q_next;
69 1.1 jonathan struct ubsec_dma_alloc q_mcr;
70 1.1 jonathan struct ubsec_dma_alloc q_ctx;
71 1.1 jonathan u_int q_type;
72 1.1 jonathan };
73 1.1 jonathan
74 1.1 jonathan struct ubsec_q2_rng {
75 1.1 jonathan struct ubsec_q2 rng_q;
76 1.1 jonathan struct ubsec_dma_alloc rng_buf;
77 1.1 jonathan int rng_used;
78 1.1 jonathan };
79 1.1 jonathan
80 1.1 jonathan /* C = (M ^ E) mod N */
81 1.1 jonathan #define UBS_MODEXP_PAR_M 0
82 1.1 jonathan #define UBS_MODEXP_PAR_E 1
83 1.1 jonathan #define UBS_MODEXP_PAR_N 2
84 1.1 jonathan struct ubsec_q2_modexp {
85 1.1 jonathan struct ubsec_q2 me_q;
86 1.1 jonathan struct cryptkop * me_krp;
87 1.1 jonathan struct ubsec_dma_alloc me_M;
88 1.1 jonathan struct ubsec_dma_alloc me_E;
89 1.1 jonathan struct ubsec_dma_alloc me_C;
90 1.1 jonathan struct ubsec_dma_alloc me_epb;
91 1.1 jonathan int me_modbits;
92 1.1 jonathan int me_shiftbits;
93 1.1 jonathan int me_normbits;
94 1.1 jonathan };
95 1.1 jonathan
96 1.1 jonathan #define UBS_RSAPRIV_PAR_P 0
97 1.1 jonathan #define UBS_RSAPRIV_PAR_Q 1
98 1.1 jonathan #define UBS_RSAPRIV_PAR_DP 2
99 1.1 jonathan #define UBS_RSAPRIV_PAR_DQ 3
100 1.1 jonathan #define UBS_RSAPRIV_PAR_PINV 4
101 1.1 jonathan #define UBS_RSAPRIV_PAR_MSGIN 5
102 1.1 jonathan #define UBS_RSAPRIV_PAR_MSGOUT 6
103 1.1 jonathan struct ubsec_q2_rsapriv {
104 1.1 jonathan struct ubsec_q2 rpr_q;
105 1.1 jonathan struct cryptkop * rpr_krp;
106 1.1 jonathan struct ubsec_dma_alloc rpr_msgin;
107 1.1 jonathan struct ubsec_dma_alloc rpr_msgout;
108 1.1 jonathan };
109 1.1 jonathan
110 1.1 jonathan #define UBSEC_RNG_BUFSIZ 16 /* measured in 32bit words */
111 1.1 jonathan
112 1.1 jonathan struct ubsec_dmachunk {
113 1.1 jonathan struct ubsec_mcr d_mcr;
114 1.1 jonathan struct ubsec_mcr_add d_mcradd[UBS_MAX_AGGR-1];
115 1.1 jonathan struct ubsec_pktbuf d_sbuf[UBS_MAX_SCATTER-1];
116 1.1 jonathan struct ubsec_pktbuf d_dbuf[UBS_MAX_SCATTER-1];
117 1.1 jonathan u_int32_t d_macbuf[5];
118 1.1 jonathan union {
119 1.9 bad struct ubsec_pktctx_aes256 ctx_aes256;
120 1.9 bad struct ubsec_pktctx_aes192 ctx_aes192;
121 1.9 bad struct ubsec_pktctx_aes128 ctx_aes128;
122 1.9 bad struct ubsec_pktctx_3des ctx_3des;
123 1.1 jonathan struct ubsec_pktctx ctx;
124 1.1 jonathan } d_ctx;
125 1.1 jonathan };
126 1.1 jonathan
127 1.1 jonathan struct ubsec_dma {
128 1.1 jonathan SIMPLEQ_ENTRY(ubsec_dma) d_next;
129 1.1 jonathan struct ubsec_dmachunk *d_dma;
130 1.1 jonathan struct ubsec_dma_alloc d_alloc;
131 1.1 jonathan };
132 1.1 jonathan
133 1.1 jonathan #define UBS_FLAGS_KEY 0x01 /* has key accelerator */
134 1.1 jonathan #define UBS_FLAGS_LONGCTX 0x02 /* uses long ipsec ctx */
135 1.1 jonathan #define UBS_FLAGS_BIGKEY 0x04 /* 2048bit keys */
136 1.1 jonathan #define UBS_FLAGS_HWNORM 0x08 /* hardware normalization */
137 1.1 jonathan #define UBS_FLAGS_RNG 0x10 /* hardware rng */
138 1.7 bad #define UBS_FLAGS_AES 0x20 /* supports AES */
139 1.7 bad #define UBS_FLAGS_MULTIMCR 0x40 /* 5827+ with 4 MCRs */
140 1.7 bad #define UBS_FLAGS_RNG4 0x80 /* 5827+ RNG on MCR4 */
141 1.1 jonathan
142 1.1 jonathan struct ubsec_q {
143 1.1 jonathan SIMPLEQ_ENTRY(ubsec_q) q_next;
144 1.1 jonathan int q_nstacked_mcrs;
145 1.1 jonathan struct ubsec_q *q_stacked_mcr[UBS_MAX_AGGR-1];
146 1.1 jonathan struct cryptop *q_crp;
147 1.1 jonathan struct ubsec_dma *q_dma;
148 1.1 jonathan
149 1.1 jonathan struct mbuf *q_src_m, *q_dst_m;
150 1.1 jonathan struct uio *q_src_io, *q_dst_io;
151 1.1 jonathan
152 1.1 jonathan int q_sesn;
153 1.1 jonathan int q_flags;
154 1.8 bad
155 1.8 bad bus_dmamap_t q_dst_map;
156 1.8 bad bus_dmamap_t q_src_map; /* cached src_map */
157 1.8 bad bus_dmamap_t q_cached_dst_map; /* cached dst_map */
158 1.1 jonathan };
159 1.1 jonathan
160 1.1 jonathan struct ubsec_softc {
161 1.4 chs device_t sc_dev; /* generic device */
162 1.1 jonathan void *sc_ih; /* interrupt handler cookie */
163 1.5 tls kmutex_t sc_mtx;
164 1.6 bad pci_chipset_tag_t sc_pct; /* pci chipset tag */
165 1.1 jonathan bus_space_handle_t sc_sh; /* memory handle */
166 1.1 jonathan bus_space_tag_t sc_st; /* memory tag */
167 1.1 jonathan bus_dma_tag_t sc_dmat; /* dma tag */
168 1.1 jonathan int sc_flags; /* device specific flags */
169 1.1 jonathan int sc_suspended;
170 1.1 jonathan int sc_needwakeup; /* notify crypto layer */
171 1.1 jonathan u_int32_t sc_statmask; /* interrupt status mask */
172 1.1 jonathan int32_t sc_cid; /* crypto tag */
173 1.7 bad int sc_maxaggr; /* max pkt aggregation */
174 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q) sc_queue; /* packet queue, mcr1 */
175 1.1 jonathan int sc_nqueue; /* count enqueued, mcr1 */
176 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q) sc_qchip; /* on chip, mcr1 */
177 1.1 jonathan int sc_nqchip; /* count on chip, mcr1 */
178 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q) sc_freequeue; /* list of free queue elements */
179 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q2) sc_queue2; /* packet queue, mcr2 */
180 1.1 jonathan int sc_nqueue2; /* count enqueued, mcr2 */
181 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q2) sc_qchip2; /* on chip, mcr2 */
182 1.7 bad SIMPLEQ_HEAD(,ubsec_q2) sc_queue4; /* packet queue, mcr4 */
183 1.7 bad int sc_nqueue4; /* count enqueued, mcr4 */
184 1.7 bad SIMPLEQ_HEAD(,ubsec_q2) sc_qchip4; /* on chip, mcr4 */
185 1.1 jonathan int sc_nsessions; /* # of sessions */
186 1.1 jonathan struct ubsec_session *sc_sessions; /* sessions */
187 1.1 jonathan struct callout sc_rngto; /* rng timeout */
188 1.1 jonathan int sc_rnghz; /* rng poll time */
189 1.1 jonathan struct ubsec_q2_rng sc_rng;
190 1.5 tls krndsource_t sc_rnd_source;
191 1.5 tls int sc_rng_need; /* how many bytes wanted */
192 1.1 jonathan struct ubsec_dma sc_dmaa[UBS_MAX_NQUEUE];
193 1.1 jonathan struct ubsec_q *sc_queuea[UBS_MAX_NQUEUE];
194 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q2) sc_q2free; /* free list */
195 1.6 bad bus_size_t sc_memsize; /* size mapped by sc_sh */
196 1.1 jonathan };
197 1.1 jonathan
198 1.1 jonathan #define UBSEC_QFLAGS_COPYOUTIV 0x1
199 1.1 jonathan
200 1.1 jonathan struct ubsec_session {
201 1.1 jonathan u_int32_t ses_used;
202 1.9 bad u_int32_t ses_key[8]; /* 3DES/AES key */
203 1.1 jonathan u_int32_t ses_hminner[5]; /* hmac inner state */
204 1.1 jonathan u_int32_t ses_hmouter[5]; /* hmac outer state */
205 1.9 bad u_int32_t ses_iv[4]; /* [3]DES iv or AES iv/icv */
206 1.1 jonathan };
207 1.1 jonathan
208 1.1 jonathan struct ubsec_stats {
209 1.1 jonathan u_int64_t hst_ibytes;
210 1.1 jonathan u_int64_t hst_obytes;
211 1.1 jonathan u_int32_t hst_ipackets;
212 1.1 jonathan u_int32_t hst_opackets;
213 1.1 jonathan u_int32_t hst_invalid; /* invalid argument */
214 1.1 jonathan u_int32_t hst_badsession; /* invalid session id */
215 1.1 jonathan u_int32_t hst_badflags; /* flags indicate !(mbuf | uio) */
216 1.1 jonathan u_int32_t hst_nodesc; /* op submitted w/o descriptors */
217 1.1 jonathan u_int32_t hst_badalg; /* unsupported algorithm */
218 1.1 jonathan
219 1.1 jonathan u_int32_t hst_nomem;
220 1.1 jonathan u_int32_t hst_queuefull;
221 1.1 jonathan u_int32_t hst_dmaerr;
222 1.1 jonathan u_int32_t hst_mcrerr;
223 1.1 jonathan u_int32_t hst_nodmafree;
224 1.1 jonathan
225 1.1 jonathan u_int32_t hst_lenmismatch; /* enc/auth lengths different */
226 1.1 jonathan u_int32_t hst_skipmismatch; /* enc part begins before auth part */
227 1.1 jonathan u_int32_t hst_iovmisaligned; /* iov op not aligned */
228 1.1 jonathan u_int32_t hst_noirq; /* IRQ for no reason */
229 1.1 jonathan u_int32_t hst_unaligned; /* unaligned src caused copy */
230 1.1 jonathan u_int32_t hst_nomap; /* bus_dmamap_create failed */
231 1.1 jonathan u_int32_t hst_noload; /* bus_dmamap_load_* failed */
232 1.1 jonathan u_int32_t hst_nombuf; /* MGET* failed */
233 1.1 jonathan u_int32_t hst_nomcl; /* MCLGET* failed */
234 1.1 jonathan u_int32_t hst_totbatch; /* ops submitted w/o interrupt */
235 1.1 jonathan u_int32_t hst_maxbatch; /* max ops submitted together */
236 1.1 jonathan u_int32_t hst_maxqueue; /* max ops queued for submission */
237 1.1 jonathan u_int32_t hst_maxqchip; /* max mcr1 ops out for processing */
238 1.1 jonathan u_int32_t hst_mcr1full; /* MCR1 too busy to take ops */
239 1.1 jonathan u_int32_t hst_rng; /* RNG requests */
240 1.1 jonathan u_int32_t hst_modexp; /* MOD EXP requests */
241 1.1 jonathan u_int32_t hst_modexpcrt; /* MOD EXP CRT requests */
242 1.1 jonathan };
243