xref: /freebsd/sys/dev/safe/safereg.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1b7e3f244SSam Leffler /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4b7e3f244SSam Leffler  * Copyright (c) 2003 Sam Leffler, Errno Consulting
5b7e3f244SSam Leffler  * Copyright (c) 2003 Global Technology Associates, Inc.
6b7e3f244SSam Leffler  * All rights reserved.
7b7e3f244SSam Leffler  *
8b7e3f244SSam Leffler  * Redistribution and use in source and binary forms, with or without
9b7e3f244SSam Leffler  * modification, are permitted provided that the following conditions
10b7e3f244SSam Leffler  * are met:
11b7e3f244SSam Leffler  * 1. Redistributions of source code must retain the above copyright
12b7e3f244SSam Leffler  *    notice, this list of conditions and the following disclaimer.
13b7e3f244SSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
14b7e3f244SSam Leffler  *    notice, this list of conditions and the following disclaimer in the
15b7e3f244SSam Leffler  *    documentation and/or other materials provided with the distribution.
16b7e3f244SSam Leffler  *
17b7e3f244SSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18b7e3f244SSam Leffler  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19b7e3f244SSam Leffler  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20b7e3f244SSam Leffler  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21b7e3f244SSam Leffler  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22b7e3f244SSam Leffler  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23b7e3f244SSam Leffler  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24b7e3f244SSam Leffler  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25b7e3f244SSam Leffler  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26b7e3f244SSam Leffler  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27b7e3f244SSam Leffler  * SUCH DAMAGE.
28b7e3f244SSam Leffler  */
29b7e3f244SSam Leffler #ifndef _SAFE_SAFEREG_H_
30b7e3f244SSam Leffler #define	_SAFE_SAFEREG_H_
31b7e3f244SSam Leffler 
32b7e3f244SSam Leffler /*
33b7e3f244SSam Leffler  * Register definitions for SafeNet SafeXcel-1141 crypto device.
34b7e3f244SSam Leffler  * Definitions from revision 1.3 (Nov 6 2002) of the User's Manual.
35b7e3f244SSam Leffler  */
36b7e3f244SSam Leffler 
37b7e3f244SSam Leffler #define BS_BAR			0x10	/* DMA base address register */
38b7e3f244SSam Leffler #define	BS_TRDY_TIMEOUT		0x40	/* TRDY timeout */
39b7e3f244SSam Leffler #define	BS_RETRY_TIMEOUT	0x41	/* DMA retry timeout */
40b7e3f244SSam Leffler 
41b7e3f244SSam Leffler #define	PCI_VENDOR_SAFENET	0x16ae		/* SafeNet, Inc. */
42b7e3f244SSam Leffler 
43b7e3f244SSam Leffler /* SafeNet */
44b7e3f244SSam Leffler #define	PCI_PRODUCT_SAFEXCEL	0x1141		/* 1141 */
45b7e3f244SSam Leffler 
46b7e3f244SSam Leffler #define	SAFE_PE_CSR		0x0000	/* Packet Enginge Ctrl/Status */
47b7e3f244SSam Leffler #define	SAFE_PE_SRC		0x0004	/* Packet Engine Source */
48b7e3f244SSam Leffler #define	SAFE_PE_DST		0x0008	/* Packet Engine Destination */
49b7e3f244SSam Leffler #define	SAFE_PE_SA		0x000c	/* Packet Engine SA */
50b7e3f244SSam Leffler #define	SAFE_PE_LEN		0x0010	/* Packet Engine Length */
51b7e3f244SSam Leffler #define	SAFE_PE_DMACFG		0x0040	/* Packet Engine DMA Configuration */
52b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT		0x0044	/* Packet Engine DMA Status */
53b7e3f244SSam Leffler #define	SAFE_PE_PDRBASE		0x0048	/* Packet Engine Descriptor Ring Base */
54b7e3f244SSam Leffler #define	SAFE_PE_RDRBASE		0x004c	/* Packet Engine Result Ring Base */
55b7e3f244SSam Leffler #define	SAFE_PE_RINGCFG		0x0050	/* Packet Engine Ring Configuration */
56b7e3f244SSam Leffler #define	SAFE_PE_RINGPOLL	0x0054	/* Packet Engine Ring Poll */
57b7e3f244SSam Leffler #define	SAFE_PE_IRNGSTAT	0x0058	/* Packet Engine Internal Ring Status */
58b7e3f244SSam Leffler #define	SAFE_PE_ERNGSTAT	0x005c	/* Packet Engine External Ring Status */
59b7e3f244SSam Leffler #define	SAFE_PE_IOTHRESH	0x0060	/* Packet Engine I/O Threshold */
60b7e3f244SSam Leffler #define	SAFE_PE_GRNGBASE	0x0064	/* Packet Engine Gather Ring Base */
61b7e3f244SSam Leffler #define	SAFE_PE_SRNGBASE	0x0068	/* Packet Engine Scatter Ring Base */
62b7e3f244SSam Leffler #define	SAFE_PE_PARTSIZE	0x006c	/* Packet Engine Particlar Ring Size */
63b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG		0x0070	/* Packet Engine Particle Ring Config */
64b7e3f244SSam Leffler #define	SAFE_CRYPTO_CTRL	0x0080	/* Crypto Control */
65b7e3f244SSam Leffler #define	SAFE_DEVID		0x0084	/* Device ID */
66b7e3f244SSam Leffler #define	SAFE_DEVINFO		0x0088	/* Device Info */
67b7e3f244SSam Leffler #define	SAFE_HU_STAT		0x00a0	/* Host Unmasked Status */
68b7e3f244SSam Leffler #define	SAFE_HM_STAT		0x00a4	/* Host Masked Status (read-only) */
69b7e3f244SSam Leffler #define	SAFE_HI_CLR		0x00a4	/* Host Clear Interrupt (write-only) */
70b7e3f244SSam Leffler #define	SAFE_HI_MASK		0x00a8	/* Host Mask Control */
71b7e3f244SSam Leffler #define	SAFE_HI_CFG		0x00ac	/* Interrupt Configuration */
72b7e3f244SSam Leffler #define	SAFE_HI_RD_DESCR	0x00b4	/* Force Descriptor Read */
73b7e3f244SSam Leffler #define	SAFE_HI_DESC_CNT	0x00b8	/* Host Descriptor Done Count */
74b7e3f244SSam Leffler #define	SAFE_DMA_ENDIAN		0x00c0	/* Master Endian Status */
75b7e3f244SSam Leffler #define	SAFE_DMA_SRCADDR	0x00c4	/* DMA Source Address Status */
76b7e3f244SSam Leffler #define	SAFE_DMA_DSTADDR	0x00c8	/* DMA Destination Address Status */
77b7e3f244SSam Leffler #define	SAFE_DMA_STAT		0x00cc	/* DMA Current Status */
78b7e3f244SSam Leffler #define	SAFE_DMA_CFG		0x00d4	/* DMA Configuration/Status */
79b7e3f244SSam Leffler #define	SAFE_ENDIAN		0x00e0	/* Endian Configuration */
80b7e3f244SSam Leffler #define	SAFE_PK_A_ADDR		0x0800	/* Public Key A Address */
81b7e3f244SSam Leffler #define	SAFE_PK_B_ADDR		0x0804	/* Public Key B Address */
82b7e3f244SSam Leffler #define	SAFE_PK_C_ADDR		0x0808	/* Public Key C Address */
83b7e3f244SSam Leffler #define	SAFE_PK_D_ADDR		0x080c	/* Public Key D Address */
84b7e3f244SSam Leffler #define	SAFE_PK_A_LEN		0x0810	/* Public Key A Length */
85b7e3f244SSam Leffler #define	SAFE_PK_B_LEN		0x0814	/* Public Key B Length */
86b7e3f244SSam Leffler #define	SAFE_PK_SHIFT		0x0818	/* Public Key Shift */
87b7e3f244SSam Leffler #define	SAFE_PK_FUNC		0x081c	/* Public Key Function */
88b7e3f244SSam Leffler #define	SAFE_RNG_OUT		0x0100	/* RNG Output */
89b7e3f244SSam Leffler #define	SAFE_RNG_STAT		0x0104	/* RNG Status */
90b7e3f244SSam Leffler #define	SAFE_RNG_CTRL		0x0108	/* RNG Control */
91b7e3f244SSam Leffler #define	SAFE_RNG_A		0x010c	/* RNG A */
92b7e3f244SSam Leffler #define	SAFE_RNG_B		0x0110	/* RNG B */
93b7e3f244SSam Leffler #define	SAFE_RNG_X_LO		0x0114	/* RNG X [31:0] */
94b7e3f244SSam Leffler #define	SAFE_RNG_X_MID		0x0118	/* RNG X [63:32] */
95b7e3f244SSam Leffler #define	SAFE_RNG_X_HI		0x011c	/* RNG X [80:64] */
96b7e3f244SSam Leffler #define	SAFE_RNG_X_CNTR		0x0120	/* RNG Counter */
97b7e3f244SSam Leffler #define	SAFE_RNG_ALM_CNT	0x0124	/* RNG Alarm Count */
98b7e3f244SSam Leffler #define	SAFE_RNG_CNFG		0x0128	/* RNG Configuration */
99b7e3f244SSam Leffler #define	SAFE_RNG_LFSR1_LO	0x012c	/* RNG LFSR1 [31:0] */
100b7e3f244SSam Leffler #define	SAFE_RNG_LFSR1_HI	0x0130	/* RNG LFSR1 [47:32] */
101b7e3f244SSam Leffler #define	SAFE_RNG_LFSR2_LO	0x0134	/* RNG LFSR1 [31:0] */
102b7e3f244SSam Leffler #define	SAFE_RNG_LFSR2_HI	0x0138	/* RNG LFSR1 [47:32] */
103b7e3f244SSam Leffler 
104b7e3f244SSam Leffler #define	SAFE_PE_CSR_READY	0x00000001	/* ready for processing */
105b7e3f244SSam Leffler #define	SAFE_PE_CSR_DONE	0x00000002	/* h/w completed processing */
106b7e3f244SSam Leffler #define	SAFE_PE_CSR_LOADSA	0x00000004	/* load SA digests */
107b7e3f244SSam Leffler #define	SAFE_PE_CSR_HASHFINAL	0x00000010	/* do hash pad & write result */
108b7e3f244SSam Leffler #define	SAFE_PE_CSR_SABUSID	0x000000c0	/* bus id for SA */
109b7e3f244SSam Leffler #define	SAFE_PE_CSR_SAPCI	0x00000040	/* PCI bus id for SA */
110b7e3f244SSam Leffler #define	SAFE_PE_CSR_NXTHDR	0x0000ff00	/* next hdr value for IPsec */
111b7e3f244SSam Leffler #define	SAFE_PE_CSR_FPAD	0x0000ff00	/* fixed pad for basic ops */
112b7e3f244SSam Leffler #define	SAFE_PE_CSR_STATUS	0x00ff0000	/* operation result status */
113b7e3f244SSam Leffler #define	SAFE_PE_CSR_AUTH_FAIL	0x00010000	/* ICV mismatch (inbound) */
114b7e3f244SSam Leffler #define	SAFE_PE_CSR_PAD_FAIL	0x00020000	/* pad verify fail (inbound) */
115b7e3f244SSam Leffler #define	SAFE_PE_CSR_SEQ_FAIL	0x00040000	/* sequence number (inbound) */
116b7e3f244SSam Leffler #define	SAFE_PE_CSR_XERROR	0x00080000	/* extended error follows */
117b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE	0x00f00000	/* extended error code */
118b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_S	20
119b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_BADCMD	0	/* invalid command */
120b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_BADALG	1	/* invalid algorithm */
121b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_ALGDIS	2	/* algorithm disabled */
122b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_ZEROLEN	3	/* zero packet length */
123b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_DMAERR	4	/* bus DMA error */
124b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_PIPEABORT	5	/* secondary bus DMA error */
125b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_BADSPI	6	/* IPsec SPI mismatch */
126b7e3f244SSam Leffler #define	SAFE_PE_CSR_XECODE_TIMEOUT	10	/* failsafe timeout */
127b7e3f244SSam Leffler #define	SAFE_PE_CSR_PAD		0xff000000	/* ESP padding control/status */
128b7e3f244SSam Leffler #define	SAFE_PE_CSR_PAD_MIN	0x00000000	/* minimum IPsec padding */
129b7e3f244SSam Leffler #define	SAFE_PE_CSR_PAD_16	0x08000000	/* pad to 16-byte boundary */
130b7e3f244SSam Leffler #define	SAFE_PE_CSR_PAD_32	0x10000000	/* pad to 32-byte boundary */
131b7e3f244SSam Leffler #define	SAFE_PE_CSR_PAD_64	0x20000000	/* pad to 64-byte boundary */
132b7e3f244SSam Leffler #define	SAFE_PE_CSR_PAD_128	0x40000000	/* pad to 128-byte boundary */
133b7e3f244SSam Leffler #define	SAFE_PE_CSR_PAD_256	0x80000000	/* pad to 256-byte boundary */
134b7e3f244SSam Leffler 
135b7e3f244SSam Leffler /*
136b7e3f244SSam Leffler  * Check the CSR to see if the PE has returned ownership to
137b7e3f244SSam Leffler  * the host.  Note that before processing a descriptor this
138b7e3f244SSam Leffler  * must be done followed by a check of the SAFE_PE_LEN register
139b7e3f244SSam Leffler  * status bits to avoid premature processing of a descriptor
140b7e3f244SSam Leffler  * on its way back to the host.
141b7e3f244SSam Leffler  */
142b7e3f244SSam Leffler #define	SAFE_PE_CSR_IS_DONE(_csr) \
143b7e3f244SSam Leffler     (((_csr) & (SAFE_PE_CSR_READY | SAFE_PE_CSR_DONE)) == SAFE_PE_CSR_DONE)
144b7e3f244SSam Leffler 
145b7e3f244SSam Leffler #define	SAFE_PE_LEN_LENGTH	0x000fffff	/* total length (bytes) */
146b7e3f244SSam Leffler #define	SAFE_PE_LEN_READY	0x00400000	/* ready for processing */
147b7e3f244SSam Leffler #define	SAFE_PE_LEN_DONE	0x00800000	/* h/w completed processing */
148b7e3f244SSam Leffler #define	SAFE_PE_LEN_BYPASS	0xff000000	/* bypass offset (bytes) */
149b7e3f244SSam Leffler #define	SAFE_PE_LEN_BYPASS_S	24
150b7e3f244SSam Leffler 
151b7e3f244SSam Leffler #define	SAFE_PE_LEN_IS_DONE(_len) \
152b7e3f244SSam Leffler     (((_len) & (SAFE_PE_LEN_READY | SAFE_PE_LEN_DONE)) == SAFE_PE_LEN_DONE)
153b7e3f244SSam Leffler 
154b7e3f244SSam Leffler /* NB: these apply to HU_STAT, HM_STAT, HI_CLR, and HI_MASK */
155b7e3f244SSam Leffler #define	SAFE_INT_PE_CDONE	0x00000002	/* PE context done */
156b7e3f244SSam Leffler #define	SAFE_INT_PE_DDONE	0x00000008	/* PE descriptor done */
157b7e3f244SSam Leffler #define	SAFE_INT_PE_ERROR	0x00000010	/* PE error */
158b7e3f244SSam Leffler #define	SAFE_INT_PE_ODONE	0x00000020	/* PE operation done */
159b7e3f244SSam Leffler 
160b7e3f244SSam Leffler #define	SAFE_HI_CFG_PULSE	0x00000001	/* use pulse interrupt */
161b7e3f244SSam Leffler #define	SAFE_HI_CFG_LEVEL	0x00000000	/* use level interrupt */
162b7e3f244SSam Leffler #define	SAFE_HI_CFG_AUTOCLR	0x00000002	/* auto-clear pulse interrupt */
163b7e3f244SSam Leffler 
164b7e3f244SSam Leffler #define	SAFE_ENDIAN_PASS	0x000000e4	/* straight pass-thru */
165b7e3f244SSam Leffler #define	SAFE_ENDIAN_SWAB	0x0000001b	/* swap bytes in 32-bit word */
166b7e3f244SSam Leffler 
167b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_PERESET	0x00000001	/* reset packet engine */
168b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_PDRRESET	0x00000002	/* reset PDR counters/ptrs */
169b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_SGRESET	0x00000004	/* reset scatter/gather cache */
170b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_FSENA	0x00000008	/* enable failsafe reset */
171b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_PEMODE	0x00000100	/* packet engine mode */
172b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_SAPREC	0x00000200	/* SA precedes packet */
173b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_PKFOLL	0x00000400	/* packet follows descriptor */
174b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_GPRBID	0x00003000	/* gather particle ring busid */
175b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_GPRPCI	0x00001000	/* PCI gather particle ring */
176b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_SPRBID	0x0000c000	/* scatter part. ring busid */
177b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_SPRPCI	0x00004000	/* PCI scatter part. ring */
178b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_ESDESC	0x00010000	/* endian swap descriptors */
179b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_ESSA	0x00020000	/* endian swap SA data */
180b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_ESPACKET	0x00040000	/* endian swap packet data */
181b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_ESPDESC	0x00080000	/* endian swap particle desc. */
182b7e3f244SSam Leffler #define	SAFE_PE_DMACFG_NOPDRUP	0x00100000	/* supp. PDR ownership update */
183b7e3f244SSam Leffler #define	SAFE_PD_EDMACFG_PCIMODE	0x01000000	/* PCI target mode */
184b7e3f244SSam Leffler 
185b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_PEIDONE	0x00000001	/* PE core input done */
186b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_PEODONE	0x00000002	/* PE core output done */
187b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_ENCDONE	0x00000004	/* encryption done */
188b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_IHDONE	0x00000008	/* inner hash done */
189b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_OHDONE	0x00000010	/* outer hash (HMAC) done */
190b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_PADFLT	0x00000020	/* crypto pad fault */
191b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_ICVFLT	0x00000040	/* ICV fault */
192b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_SPIMIS	0x00000080	/* SPI mismatch */
193b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_CRYPTO	0x00000100	/* crypto engine timeout */
194b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_CQACT	0x00000200	/* command queue active */
195b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_IRACT	0x00000400	/* input request active */
196b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_ORACT	0x00000800	/* output request active */
197b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_PEISIZE	0x003ff000	/* PE input size:32-bit words */
198b7e3f244SSam Leffler #define	SAFE_PE_DMASTAT_PEOSIZE	0xffc00000	/* PE out. size:32-bit words */
199b7e3f244SSam Leffler 
200b7e3f244SSam Leffler #define	SAFE_PE_RINGCFG_SIZE	0x000003ff	/* ring size (descriptors) */
201b7e3f244SSam Leffler #define	SAFE_PE_RINGCFG_OFFSET	0xffff0000	/* offset btw desc's (dwords) */
202b7e3f244SSam Leffler #define	SAFE_PE_RINGCFG_OFFSET_S	16
203b7e3f244SSam Leffler 
204b7e3f244SSam Leffler #define	SAFE_PE_RINGPOLL_POLL	0x00000fff	/* polling frequency/divisor */
205b7e3f244SSam Leffler #define	SAFE_PE_RINGPOLL_RETRY	0x03ff0000	/* polling frequency/divisor */
206b7e3f244SSam Leffler #define	SAFE_PE_RINGPOLL_CONT	0x80000000	/* continuously poll */
207b7e3f244SSam Leffler 
208b7e3f244SSam Leffler #define	SAFE_PE_IRNGSTAT_CQAVAIL 0x00000001	/* command queue available */
209b7e3f244SSam Leffler 
210b7e3f244SSam Leffler #define	SAFE_PE_ERNGSTAT_NEXT	0x03ff0000	/* index of next packet desc. */
211b7e3f244SSam Leffler #define	SAFE_PE_ERNGSTAT_NEXT_S	16
212b7e3f244SSam Leffler 
213b7e3f244SSam Leffler #define	SAFE_PE_IOTHRESH_INPUT	0x000003ff	/* input threshold (dwords) */
214b7e3f244SSam Leffler #define	SAFE_PE_IOTHRESH_OUTPUT	0x03ff0000	/* output threshold (dwords) */
215b7e3f244SSam Leffler 
216b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_SIZE	0x0000ffff	/* scatter particle size */
217b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_GBURST	0x00030000	/* gather particle burst */
218b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_GBURST_2	0x00000000
219b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_GBURST_4	0x00010000
220b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_GBURST_8	0x00020000
221b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_GBURST_16	0x00030000
222b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_SBURST	0x000c0000	/* scatter particle burst */
223b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_SBURST_2	0x00000000
224b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_SBURST_4	0x00040000
225b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_SBURST_8	0x00080000
226b7e3f244SSam Leffler #define	SAFE_PE_PARTCFG_SBURST_16	0x000c0000
227b7e3f244SSam Leffler 
228b7e3f244SSam Leffler #define	SAFE_PE_PARTSIZE_SCAT	0xffff0000	/* scatter particle ring size */
229b7e3f244SSam Leffler #define	SAFE_PE_PARTSIZE_GATH	0x0000ffff	/* gather particle ring size */
230b7e3f244SSam Leffler 
231b7e3f244SSam Leffler #define	SAFE_CRYPTO_CTRL_3DES	0x00000001	/* enable 3DES support */
232b7e3f244SSam Leffler #define	SAFE_CRYPTO_CTRL_PKEY	0x00010000	/* enable public key support */
233b7e3f244SSam Leffler #define	SAFE_CRYPTO_CTRL_RNG	0x00020000	/* enable RNG support */
234b7e3f244SSam Leffler 
235b7e3f244SSam Leffler #define	SAFE_DEVINFO_REV_MIN	0x0000000f	/* minor rev for chip */
236b7e3f244SSam Leffler #define	SAFE_DEVINFO_REV_MAJ	0x000000f0	/* major rev for chip */
237b7e3f244SSam Leffler #define	SAFE_DEVINFO_REV_MAJ_S	4
238b7e3f244SSam Leffler #define	SAFE_DEVINFO_DES	0x00000100	/* DES/3DES support present */
239b7e3f244SSam Leffler #define	SAFE_DEVINFO_ARC4	0x00000200	/* ARC4 support present */
240b7e3f244SSam Leffler #define	SAFE_DEVINFO_AES	0x00000400	/* AES support present */
241b7e3f244SSam Leffler #define	SAFE_DEVINFO_MD5	0x00001000	/* MD5 support present */
242b7e3f244SSam Leffler #define	SAFE_DEVINFO_SHA1	0x00002000	/* SHA-1 support present */
243b7e3f244SSam Leffler #define	SAFE_DEVINFO_RIPEMD	0x00004000	/* RIPEMD support present */
244b7e3f244SSam Leffler #define	SAFE_DEVINFO_DEFLATE	0x00010000	/* Deflate support present */
245b7e3f244SSam Leffler #define	SAFE_DEVINFO_SARAM	0x00100000	/* on-chip SA RAM present */
246b7e3f244SSam Leffler #define	SAFE_DEVINFO_EMIBUS	0x00200000	/* EMI bus present */
247b7e3f244SSam Leffler #define	SAFE_DEVINFO_PKEY	0x00400000	/* public key support present */
248b7e3f244SSam Leffler #define	SAFE_DEVINFO_RNG	0x00800000	/* RNG present */
249b7e3f244SSam Leffler 
250b7e3f244SSam Leffler #define	SAFE_REV(_maj, _min)	(((_maj) << SAFE_DEVINFO_REV_MAJ_S) | (_min))
251b7e3f244SSam Leffler #define	SAFE_REV_MAJ(_chiprev) \
252b7e3f244SSam Leffler 	(((_chiprev) & SAFE_DEVINFO_REV_MAJ) >> SAFE_DEVINFO_REV_MAJ_S)
253b7e3f244SSam Leffler #define	SAFE_REV_MIN(_chiprev)	((_chiprev) & SAFE_DEVINFO_REV_MIN)
254b7e3f244SSam Leffler 
255b7e3f244SSam Leffler #define	SAFE_PK_FUNC_MULT	0x00000001	/* Multiply function */
256b7e3f244SSam Leffler #define	SAFE_PK_FUNC_SQUARE	0x00000004	/* Square function */
257b7e3f244SSam Leffler #define	SAFE_PK_FUNC_ADD	0x00000010	/* Add function */
258b7e3f244SSam Leffler #define	SAFE_PK_FUNC_SUB	0x00000020	/* Subtract function */
259b7e3f244SSam Leffler #define	SAFE_PK_FUNC_LSHIFT	0x00000040	/* Left-shift function */
260b7e3f244SSam Leffler #define	SAFE_PK_FUNC_RSHIFT	0x00000080	/* Right-shift function */
261b7e3f244SSam Leffler #define	SAFE_PK_FUNC_DIV	0x00000100	/* Divide function */
262b7e3f244SSam Leffler #define	SAFE_PK_FUNC_CMP	0x00000400	/* Compare function */
263b7e3f244SSam Leffler #define	SAFE_PK_FUNC_COPY	0x00000800	/* Copy function */
264b7e3f244SSam Leffler #define	SAFE_PK_FUNC_EXP16	0x00002000	/* Exponentiate (4-bit ACT) */
265b7e3f244SSam Leffler #define	SAFE_PK_FUNC_EXP4	0x00004000	/* Exponentiate (2-bit ACT) */
266b7e3f244SSam Leffler 
267b7e3f244SSam Leffler #define	SAFE_RNG_STAT_BUSY	0x00000001	/* busy, data not valid */
268b7e3f244SSam Leffler 
269b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_PRE_LFSR	0x00000001	/* enable output pre-LFSR */
270b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_TST_MODE	0x00000002	/* enable test mode */
271b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_TST_RUN	0x00000004	/* start test state machine */
272b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_ENA_RING1	0x00000008	/* test entropy oscillator #1 */
273b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_ENA_RING2	0x00000010	/* test entropy oscillator #2 */
274b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_DIS_ALARM	0x00000020	/* disable RNG alarm reports */
275b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_TST_CLOCK	0x00000040	/* enable test clock */
276b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_SHORTEN	0x00000080	/* shorten state timers */
277b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_TST_ALARM	0x00000100	/* simulate alarm state */
278b7e3f244SSam Leffler #define	SAFE_RNG_CTRL_RST_LFSR	0x00000200	/* reset LFSR */
279b7e3f244SSam Leffler 
280b7e3f244SSam Leffler /*
281b7e3f244SSam Leffler  * Packet engine descriptor.  Note that d_csr is a copy of the
282b7e3f244SSam Leffler  * SAFE_PE_CSR register and all definitions apply, and d_len
283b7e3f244SSam Leffler  * is a copy of the SAFE_PE_LEN register and all definitions apply.
284b7e3f244SSam Leffler  * d_src and d_len may point directly to contiguous data or to a
285b7e3f244SSam Leffler  * list of ``particle descriptors'' when using scatter/gather i/o.
286b7e3f244SSam Leffler  */
287b7e3f244SSam Leffler struct safe_desc {
288b7e3f244SSam Leffler 	u_int32_t	d_csr;			/* per-packet control/status */
289b7e3f244SSam Leffler 	u_int32_t	d_src;			/* source address */
290b7e3f244SSam Leffler 	u_int32_t	d_dst;			/* destination address */
291b7e3f244SSam Leffler 	u_int32_t	d_sa;			/* SA address */
292b7e3f244SSam Leffler 	u_int32_t	d_len;			/* length, bypass, status */
293b7e3f244SSam Leffler };
294b7e3f244SSam Leffler 
295b7e3f244SSam Leffler /*
296b7e3f244SSam Leffler  * Scatter/Gather particle descriptor.
297b7e3f244SSam Leffler  *
298b7e3f244SSam Leffler  * NB: scatter descriptors do not specify a size; this is fixed
299b7e3f244SSam Leffler  *     by the setting of the SAFE_PE_PARTCFG register.
300b7e3f244SSam Leffler  */
301b7e3f244SSam Leffler struct safe_pdesc {
302b7e3f244SSam Leffler 	u_int32_t	pd_addr;		/* particle address */
303b7e3f244SSam Leffler 	u_int16_t	pd_flags;		/* control word */
304b7e3f244SSam Leffler 	u_int16_t	pd_size;		/* particle size (bytes) */
305b7e3f244SSam Leffler };
306b7e3f244SSam Leffler 
307b7e3f244SSam Leffler #define	SAFE_PD_READY	0x0001			/* ready for processing */
308b7e3f244SSam Leffler #define	SAFE_PD_DONE	0x0002			/* h/w completed processing */
309b7e3f244SSam Leffler 
310b7e3f244SSam Leffler /*
311b7e3f244SSam Leffler  * Security Association (SA) Record (Rev 1).  One of these is
312b7e3f244SSam Leffler  * required for each operation processed by the packet engine.
313b7e3f244SSam Leffler  */
314b7e3f244SSam Leffler struct safe_sarec {
315b7e3f244SSam Leffler 	u_int32_t	sa_cmd0;
316b7e3f244SSam Leffler 	u_int32_t	sa_cmd1;
317b7e3f244SSam Leffler 	u_int32_t	sa_resv0;
318b7e3f244SSam Leffler 	u_int32_t	sa_resv1;
319b7e3f244SSam Leffler 	u_int32_t	sa_key[8];		/* DES/3DES/AES key */
320b7e3f244SSam Leffler 	u_int32_t	sa_indigest[5];		/* inner digest */
321b7e3f244SSam Leffler 	u_int32_t	sa_outdigest[5];	/* outer digest */
322b7e3f244SSam Leffler 	u_int32_t	sa_spi;			/* SPI */
323b7e3f244SSam Leffler 	u_int32_t	sa_seqnum;		/* sequence number */
324b7e3f244SSam Leffler 	u_int32_t	sa_seqmask[2];		/* sequence number mask */
325b7e3f244SSam Leffler 	u_int32_t	sa_resv2;
326b7e3f244SSam Leffler 	u_int32_t	sa_staterec;		/* address of state record */
327b7e3f244SSam Leffler 	u_int32_t	sa_resv3[2];
328b7e3f244SSam Leffler 	u_int32_t	sa_samgmt0;		/* SA management field 0 */
329b7e3f244SSam Leffler 	u_int32_t	sa_samgmt1;		/* SA management field 0 */
330b7e3f244SSam Leffler };
331b7e3f244SSam Leffler 
332b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OP		0x00000007	/* operation code */
333b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OP_CRYPT	0x00000000	/* encrypt/decrypt (basic) */
334b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OP_BOTH	0x00000001	/* encrypt-hash/hash-decrypto */
335b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OP_HASH	0x00000003	/* hash (outbound-only) */
336b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OP_ESP	0x00000000	/* ESP in/out (proto) */
337b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OP_AH	0x00000001	/* AH in/out (proto) */
338b7e3f244SSam Leffler #define	SAFE_SA_CMD0_INBOUND	0x00000008	/* inbound operation */
339b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OUTBOUND	0x00000000	/* outbound operation */
340b7e3f244SSam Leffler #define	SAFE_SA_CMD0_GROUP	0x00000030	/* operation group */
341b7e3f244SSam Leffler #define	SAFE_SA_CMD0_BASIC	0x00000000	/* basic operation */
342b7e3f244SSam Leffler #define	SAFE_SA_CMD0_PROTO	0x00000010	/* protocol/packet operation */
343b7e3f244SSam Leffler #define	SAFE_SA_CMD0_BUNDLE	0x00000020	/* bundled operation (resvd) */
344b7e3f244SSam Leffler #define	SAFE_SA_CMD0_PAD	0x000000c0	/* crypto pad method */
345b7e3f244SSam Leffler #define	SAFE_SA_CMD0_PAD_IPSEC	0x00000000	/* IPsec padding */
346b7e3f244SSam Leffler #define	SAFE_SA_CMD0_PAD_PKCS7	0x00000040	/* PKCS#7 padding */
347b7e3f244SSam Leffler #define	SAFE_SA_CMD0_PAD_CONS	0x00000080	/* constant padding */
348b7e3f244SSam Leffler #define	SAFE_SA_CMD0_PAD_ZERO	0x000000c0	/* zero padding */
349b7e3f244SSam Leffler #define	SAFE_SA_CMD0_CRYPT_ALG	0x00000f00	/* symmetric crypto algorithm */
350b7e3f244SSam Leffler #define	SAFE_SA_CMD0_DES	0x00000000	/* DES crypto algorithm */
351b7e3f244SSam Leffler #define	SAFE_SA_CMD0_3DES	0x00000100	/* 3DES crypto algorithm */
352b7e3f244SSam Leffler #define	SAFE_SA_CMD0_AES	0x00000300	/* AES crypto algorithm */
353b7e3f244SSam Leffler #define	SAFE_SA_CMD0_CRYPT_NULL	0x00000f00	/* null crypto algorithm */
354b7e3f244SSam Leffler #define	SAFE_SA_CMD0_HASH_ALG	0x0000f000	/* hash algorithm */
355b7e3f244SSam Leffler #define	SAFE_SA_CMD0_MD5	0x00000000	/* MD5 hash algorithm */
356b7e3f244SSam Leffler #define	SAFE_SA_CMD0_SHA1	0x00001000	/* SHA-1 hash algorithm */
357b7e3f244SSam Leffler #define	SAFE_SA_CMD0_HASH_NULL	0x0000f000	/* null hash algorithm */
358b7e3f244SSam Leffler #define	SAFE_SA_CMD0_HDR_PROC	0x00080000	/* header processing */
359b7e3f244SSam Leffler #define	SAFE_SA_CMD0_IBUSID	0x00300000	/* input bus id */
360b7e3f244SSam Leffler #define	SAFE_SA_CMD0_IPCI	0x00100000	/* PCI input bus id */
361b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OBUSID	0x00c00000	/* output bus id */
362b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OPCI	0x00400000	/* PCI output bus id */
363b7e3f244SSam Leffler #define	SAFE_SA_CMD0_IVLD	0x03000000	/* IV loading */
364b7e3f244SSam Leffler #define	SAFE_SA_CMD0_IVLD_NONE	0x00000000	/* IV no load (reuse) */
365b7e3f244SSam Leffler #define	SAFE_SA_CMD0_IVLD_IBUF	0x01000000	/* IV load from input buffer */
366b7e3f244SSam Leffler #define	SAFE_SA_CMD0_IVLD_STATE	0x02000000	/* IV load from state */
367b7e3f244SSam Leffler #define	SAFE_SA_CMD0_HSLD	0x0c000000	/* hash state loading */
368b7e3f244SSam Leffler #define	SAFE_SA_CMD0_HSLD_SA	0x00000000	/* hash state load from SA */
369b7e3f244SSam Leffler #define	SAFE_SA_CMD0_HSLD_STATE	0x08000000	/* hash state load from state */
370b7e3f244SSam Leffler #define	SAFE_SA_CMD0_HSLD_NONE	0x0c000000	/* hash state no load */
371b7e3f244SSam Leffler #define	SAFE_SA_CMD0_SAVEIV	0x10000000	/* save IV */
372b7e3f244SSam Leffler #define	SAFE_SA_CMD0_SAVEHASH	0x20000000	/* save hash state */
373b7e3f244SSam Leffler #define	SAFE_SA_CMD0_IGATHER	0x40000000	/* input gather */
374b7e3f244SSam Leffler #define	SAFE_SA_CMD0_OSCATTER	0x80000000	/* output scatter */
375b7e3f244SSam Leffler 
376b7e3f244SSam Leffler #define	SAFE_SA_CMD1_HDRCOPY	0x00000002	/* copy header to output */
377b7e3f244SSam Leffler #define	SAFE_SA_CMD1_PAYCOPY	0x00000004	/* copy payload to output */
378b7e3f244SSam Leffler #define	SAFE_SA_CMD1_PADCOPY	0x00000008	/* copy pad to output */
379b7e3f244SSam Leffler #define	SAFE_SA_CMD1_IPV4	0x00000000	/* IPv4 protocol */
380b7e3f244SSam Leffler #define	SAFE_SA_CMD1_IPV6	0x00000010	/* IPv6 protocol */
381b7e3f244SSam Leffler #define	SAFE_SA_CMD1_MUTABLE	0x00000020	/* mutable bit processing */
382b7e3f244SSam Leffler #define	SAFE_SA_CMD1_SRBUSID	0x000000c0	/* state record bus id */
383b7e3f244SSam Leffler #define	SAFE_SA_CMD1_SRPCI	0x00000040	/* state record from PCI */
384b7e3f244SSam Leffler #define	SAFE_SA_CMD1_CRMODE	0x00000300	/* crypto mode */
385b7e3f244SSam Leffler #define	SAFE_SA_CMD1_ECB	0x00000000	/* ECB crypto mode */
386b7e3f244SSam Leffler #define	SAFE_SA_CMD1_CBC	0x00000100	/* CBC crypto mode */
387b7e3f244SSam Leffler #define	SAFE_SA_CMD1_OFB	0x00000200	/* OFB crypto mode */
388b7e3f244SSam Leffler #define	SAFE_SA_CMD1_CFB	0x00000300	/* CFB crypto mode */
389b7e3f244SSam Leffler #define	SAFE_SA_CMD1_CRFEEDBACK	0x00000c00	/* crypto feedback mode */
390b7e3f244SSam Leffler #define	SAFE_SA_CMD1_64BIT	0x00000000	/* 64-bit crypto feedback */
391b7e3f244SSam Leffler #define	SAFE_SA_CMD1_8BIT	0x00000400	/* 8-bit crypto feedback */
392b7e3f244SSam Leffler #define	SAFE_SA_CMD1_1BIT	0x00000800	/* 1-bit crypto feedback */
393b7e3f244SSam Leffler #define	SAFE_SA_CMD1_128BIT	0x00000c00	/* 128-bit crypto feedback */
394b7e3f244SSam Leffler #define	SAFE_SA_CMD1_OPTIONS	0x00001000	/* HMAC/options mutable bit */
395b7e3f244SSam Leffler #define	SAFE_SA_CMD1_HMAC	SAFE_SA_CMD1_OPTIONS
396b7e3f244SSam Leffler #define	SAFE_SA_CMD1_SAREV1	0x00008000	/* SA Revision 1 */
397b7e3f244SSam Leffler #define	SAFE_SA_CMD1_OFFSET	0x00ff0000	/* hash/crypto offset(dwords) */
398b7e3f244SSam Leffler #define	SAFE_SA_CMD1_OFFSET_S	16
399b7e3f244SSam Leffler #define	SAFE_SA_CMD1_AESKEYLEN	0x0f000000	/* AES key length */
400b7e3f244SSam Leffler #define	SAFE_SA_CMD1_AES128	0x02000000	/* 128-bit AES key */
401b7e3f244SSam Leffler #define	SAFE_SA_CMD1_AES192	0x03000000	/* 192-bit AES key */
402b7e3f244SSam Leffler #define	SAFE_SA_CMD1_AES256	0x04000000	/* 256-bit AES key */
403b7e3f244SSam Leffler 
404b7e3f244SSam Leffler /*
405b7e3f244SSam Leffler  * Security Associate State Record (Rev 1).
406b7e3f244SSam Leffler  */
407b7e3f244SSam Leffler struct safe_sastate {
408b7e3f244SSam Leffler 	u_int32_t	sa_saved_iv[4];		/* saved IV (DES/3DES/AES) */
409b7e3f244SSam Leffler 	u_int32_t	sa_saved_hashbc;	/* saved hash byte count */
410b7e3f244SSam Leffler 	u_int32_t	sa_saved_indigest[5];	/* saved inner digest */
411b7e3f244SSam Leffler };
412b7e3f244SSam Leffler #endif /* _SAFE_SAFEREG_H_ */
413