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