ubsecvar.h revision 1.6 1 1.6 bad /* $NetBSD: ubsecvar.h,v 1.6 2013/11/17 17:16:25 bad Exp $ */
2 1.1 jonathan /* $OpenBSD: ubsecvar.h,v 1.36 2003/06/04 16:02:41 jason 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.1 jonathan #define UBS_MAX_AGGR 5 /* Maximum aggregation count */
44 1.1 jonathan #endif
45 1.1 jonathan
46 1.1 jonathan #define UBSEC_CARD(sid) (((sid) & 0xf0000000) >> 28)
47 1.1 jonathan #define UBSEC_SESSION(sid) ( (sid) & 0x0fffffff)
48 1.1 jonathan #define UBSEC_SID(crd, sesn) (((crd) << 28) | ((sesn) & 0x0fffffff))
49 1.1 jonathan
50 1.1 jonathan #define UBS_DEF_RTY 0xff /* PCI Retry Timeout */
51 1.1 jonathan #define UBS_DEF_TOUT 0xff /* PCI TRDY Timeout */
52 1.1 jonathan #define UBS_DEF_CACHELINE 0x01 /* Cache Line setting */
53 1.1 jonathan
54 1.1 jonathan struct ubsec_dma_alloc {
55 1.1 jonathan u_int32_t dma_paddr;
56 1.3 christos void * dma_vaddr;
57 1.1 jonathan bus_dmamap_t dma_map;
58 1.1 jonathan bus_dma_segment_t dma_seg;
59 1.1 jonathan bus_size_t dma_size;
60 1.1 jonathan int dma_nseg;
61 1.1 jonathan };
62 1.1 jonathan
63 1.1 jonathan struct ubsec_q2 {
64 1.1 jonathan SIMPLEQ_ENTRY(ubsec_q2) q_next;
65 1.1 jonathan struct ubsec_dma_alloc q_mcr;
66 1.1 jonathan struct ubsec_dma_alloc q_ctx;
67 1.1 jonathan u_int q_type;
68 1.1 jonathan };
69 1.1 jonathan
70 1.1 jonathan struct ubsec_q2_rng {
71 1.1 jonathan struct ubsec_q2 rng_q;
72 1.1 jonathan struct ubsec_dma_alloc rng_buf;
73 1.1 jonathan int rng_used;
74 1.1 jonathan };
75 1.1 jonathan
76 1.1 jonathan /* C = (M ^ E) mod N */
77 1.1 jonathan #define UBS_MODEXP_PAR_M 0
78 1.1 jonathan #define UBS_MODEXP_PAR_E 1
79 1.1 jonathan #define UBS_MODEXP_PAR_N 2
80 1.1 jonathan struct ubsec_q2_modexp {
81 1.1 jonathan struct ubsec_q2 me_q;
82 1.1 jonathan struct cryptkop * me_krp;
83 1.1 jonathan struct ubsec_dma_alloc me_M;
84 1.1 jonathan struct ubsec_dma_alloc me_E;
85 1.1 jonathan struct ubsec_dma_alloc me_C;
86 1.1 jonathan struct ubsec_dma_alloc me_epb;
87 1.1 jonathan int me_modbits;
88 1.1 jonathan int me_shiftbits;
89 1.1 jonathan int me_normbits;
90 1.1 jonathan };
91 1.1 jonathan
92 1.1 jonathan #define UBS_RSAPRIV_PAR_P 0
93 1.1 jonathan #define UBS_RSAPRIV_PAR_Q 1
94 1.1 jonathan #define UBS_RSAPRIV_PAR_DP 2
95 1.1 jonathan #define UBS_RSAPRIV_PAR_DQ 3
96 1.1 jonathan #define UBS_RSAPRIV_PAR_PINV 4
97 1.1 jonathan #define UBS_RSAPRIV_PAR_MSGIN 5
98 1.1 jonathan #define UBS_RSAPRIV_PAR_MSGOUT 6
99 1.1 jonathan struct ubsec_q2_rsapriv {
100 1.1 jonathan struct ubsec_q2 rpr_q;
101 1.1 jonathan struct cryptkop * rpr_krp;
102 1.1 jonathan struct ubsec_dma_alloc rpr_msgin;
103 1.1 jonathan struct ubsec_dma_alloc rpr_msgout;
104 1.1 jonathan };
105 1.1 jonathan
106 1.1 jonathan #define UBSEC_RNG_BUFSIZ 16 /* measured in 32bit words */
107 1.1 jonathan
108 1.1 jonathan struct ubsec_dmachunk {
109 1.1 jonathan struct ubsec_mcr d_mcr;
110 1.1 jonathan struct ubsec_mcr_add d_mcradd[UBS_MAX_AGGR-1];
111 1.1 jonathan struct ubsec_pktbuf d_sbuf[UBS_MAX_SCATTER-1];
112 1.1 jonathan struct ubsec_pktbuf d_dbuf[UBS_MAX_SCATTER-1];
113 1.1 jonathan u_int32_t d_macbuf[5];
114 1.1 jonathan union {
115 1.1 jonathan struct ubsec_pktctx_long ctxl;
116 1.1 jonathan struct ubsec_pktctx ctx;
117 1.1 jonathan } d_ctx;
118 1.1 jonathan };
119 1.1 jonathan
120 1.1 jonathan struct ubsec_dma {
121 1.1 jonathan SIMPLEQ_ENTRY(ubsec_dma) d_next;
122 1.1 jonathan struct ubsec_dmachunk *d_dma;
123 1.1 jonathan struct ubsec_dma_alloc d_alloc;
124 1.1 jonathan };
125 1.1 jonathan
126 1.1 jonathan #define UBS_FLAGS_KEY 0x01 /* has key accelerator */
127 1.1 jonathan #define UBS_FLAGS_LONGCTX 0x02 /* uses long ipsec ctx */
128 1.1 jonathan #define UBS_FLAGS_BIGKEY 0x04 /* 2048bit keys */
129 1.1 jonathan #define UBS_FLAGS_HWNORM 0x08 /* hardware normalization */
130 1.1 jonathan #define UBS_FLAGS_RNG 0x10 /* hardware rng */
131 1.1 jonathan
132 1.1 jonathan struct ubsec_q {
133 1.1 jonathan SIMPLEQ_ENTRY(ubsec_q) q_next;
134 1.1 jonathan int q_nstacked_mcrs;
135 1.1 jonathan struct ubsec_q *q_stacked_mcr[UBS_MAX_AGGR-1];
136 1.1 jonathan struct cryptop *q_crp;
137 1.1 jonathan struct ubsec_dma *q_dma;
138 1.1 jonathan
139 1.1 jonathan struct mbuf *q_src_m, *q_dst_m;
140 1.1 jonathan struct uio *q_src_io, *q_dst_io;
141 1.1 jonathan
142 1.1 jonathan bus_dmamap_t q_src_map;
143 1.1 jonathan bus_dmamap_t q_dst_map;
144 1.1 jonathan
145 1.1 jonathan int q_sesn;
146 1.1 jonathan int q_flags;
147 1.1 jonathan };
148 1.1 jonathan
149 1.1 jonathan struct ubsec_softc {
150 1.4 chs device_t sc_dev; /* generic device */
151 1.1 jonathan void *sc_ih; /* interrupt handler cookie */
152 1.5 tls kmutex_t sc_mtx;
153 1.6 bad pci_chipset_tag_t sc_pct; /* pci chipset tag */
154 1.1 jonathan bus_space_handle_t sc_sh; /* memory handle */
155 1.1 jonathan bus_space_tag_t sc_st; /* memory tag */
156 1.1 jonathan bus_dma_tag_t sc_dmat; /* dma tag */
157 1.1 jonathan int sc_flags; /* device specific flags */
158 1.1 jonathan int sc_suspended;
159 1.1 jonathan int sc_needwakeup; /* notify crypto layer */
160 1.1 jonathan u_int32_t sc_statmask; /* interrupt status mask */
161 1.1 jonathan int32_t sc_cid; /* crypto tag */
162 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q) sc_queue; /* packet queue, mcr1 */
163 1.1 jonathan int sc_nqueue; /* count enqueued, mcr1 */
164 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q) sc_qchip; /* on chip, mcr1 */
165 1.1 jonathan int sc_nqchip; /* count on chip, mcr1 */
166 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q) sc_freequeue; /* list of free queue elements */
167 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q2) sc_queue2; /* packet queue, mcr2 */
168 1.1 jonathan int sc_nqueue2; /* count enqueued, mcr2 */
169 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q2) sc_qchip2; /* on chip, mcr2 */
170 1.1 jonathan int sc_nsessions; /* # of sessions */
171 1.1 jonathan struct ubsec_session *sc_sessions; /* sessions */
172 1.1 jonathan struct callout sc_rngto; /* rng timeout */
173 1.1 jonathan int sc_rnghz; /* rng poll time */
174 1.1 jonathan struct ubsec_q2_rng sc_rng;
175 1.5 tls krndsource_t sc_rnd_source;
176 1.5 tls int sc_rng_need; /* how many bytes wanted */
177 1.1 jonathan struct ubsec_dma sc_dmaa[UBS_MAX_NQUEUE];
178 1.1 jonathan struct ubsec_q *sc_queuea[UBS_MAX_NQUEUE];
179 1.1 jonathan SIMPLEQ_HEAD(,ubsec_q2) sc_q2free; /* free list */
180 1.6 bad bus_size_t sc_memsize; /* size mapped by sc_sh */
181 1.1 jonathan };
182 1.1 jonathan
183 1.1 jonathan #define UBSEC_QFLAGS_COPYOUTIV 0x1
184 1.1 jonathan
185 1.1 jonathan struct ubsec_session {
186 1.1 jonathan u_int32_t ses_used;
187 1.1 jonathan u_int32_t ses_deskey[6]; /* 3DES key */
188 1.1 jonathan u_int32_t ses_hminner[5]; /* hmac inner state */
189 1.1 jonathan u_int32_t ses_hmouter[5]; /* hmac outer state */
190 1.1 jonathan u_int32_t ses_iv[2]; /* [3]DES iv */
191 1.1 jonathan };
192 1.1 jonathan
193 1.1 jonathan struct ubsec_stats {
194 1.1 jonathan u_int64_t hst_ibytes;
195 1.1 jonathan u_int64_t hst_obytes;
196 1.1 jonathan u_int32_t hst_ipackets;
197 1.1 jonathan u_int32_t hst_opackets;
198 1.1 jonathan u_int32_t hst_invalid; /* invalid argument */
199 1.1 jonathan u_int32_t hst_badsession; /* invalid session id */
200 1.1 jonathan u_int32_t hst_badflags; /* flags indicate !(mbuf | uio) */
201 1.1 jonathan u_int32_t hst_nodesc; /* op submitted w/o descriptors */
202 1.1 jonathan u_int32_t hst_badalg; /* unsupported algorithm */
203 1.1 jonathan
204 1.1 jonathan u_int32_t hst_nomem;
205 1.1 jonathan u_int32_t hst_queuefull;
206 1.1 jonathan u_int32_t hst_dmaerr;
207 1.1 jonathan u_int32_t hst_mcrerr;
208 1.1 jonathan u_int32_t hst_nodmafree;
209 1.1 jonathan
210 1.1 jonathan u_int32_t hst_lenmismatch; /* enc/auth lengths different */
211 1.1 jonathan u_int32_t hst_skipmismatch; /* enc part begins before auth part */
212 1.1 jonathan u_int32_t hst_iovmisaligned; /* iov op not aligned */
213 1.1 jonathan u_int32_t hst_noirq; /* IRQ for no reason */
214 1.1 jonathan u_int32_t hst_unaligned; /* unaligned src caused copy */
215 1.1 jonathan u_int32_t hst_nomap; /* bus_dmamap_create failed */
216 1.1 jonathan u_int32_t hst_noload; /* bus_dmamap_load_* failed */
217 1.1 jonathan u_int32_t hst_nombuf; /* MGET* failed */
218 1.1 jonathan u_int32_t hst_nomcl; /* MCLGET* failed */
219 1.1 jonathan u_int32_t hst_totbatch; /* ops submitted w/o interrupt */
220 1.1 jonathan u_int32_t hst_maxbatch; /* max ops submitted together */
221 1.1 jonathan u_int32_t hst_maxqueue; /* max ops queued for submission */
222 1.1 jonathan u_int32_t hst_maxqchip; /* max mcr1 ops out for processing */
223 1.1 jonathan u_int32_t hst_mcr1full; /* MCR1 too busy to take ops */
224 1.1 jonathan u_int32_t hst_rng; /* RNG requests */
225 1.1 jonathan u_int32_t hst_modexp; /* MOD EXP requests */
226 1.1 jonathan u_int32_t hst_modexpcrt; /* MOD EXP CRT requests */
227 1.1 jonathan };
228