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