1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  BCM5821 cryptoaccelerator		       File: bcm5821.h
5    *
6    *********************************************************************
7    *
8    *  Copyright 2000,2001,2002,2003
9    *  Broadcom Corporation. All rights reserved.
10    *
11    *  This software is furnished under license and may be used and
12    *  copied only in accordance with the following terms and
13    *  conditions.  Subject to these conditions, you may download,
14    *  copy, install, use, modify and distribute modified or unmodified
15    *  copies of this software in source and/or binary form.  No title
16    *  or ownership is transferred hereby.
17    *
18    *  1) Any source code used, modified or distributed must reproduce
19    *     and retain this copyright notice and list of conditions
20    *     as they appear in the source file.
21    *
22    *  2) No right is granted to use any trade name, trademark, or
23    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
24    *     name may not be used to endorse or promote products derived
25    *     from this software without the prior written permission of
26    *     Broadcom Corporation.
27    *
28    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
29    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
30    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
31    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
32    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
33    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
34    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
36    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
37    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
38    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
40    *     THE POSSIBILITY OF SUCH DAMAGE.
41    ********************************************************************* */
42
43#ifndef _BCM5821_H_
44#define _BCM5821_H_
45
46/* Register and field definitions for the Broadcom BCM5821 crypto
47   accelerator.  The BCM5820 implements a compatible (modulo bugs)
48   subset of the BCM5821. */
49
50#define K_PCI_VENDOR_BROADCOM    0x14e4
51#define K_PCI_ID_BCM5820         0x5820
52#define K_PCI_ID_BCM5821         0x5821
53
54#define _DD_MAKEMASK1(n) (1 << (n))
55#define _DD_MAKEMASK(v,n) ((((1)<<(v))-1) << (n))
56#define _DD_MAKEVALUE(v,n) ((v) << (n))
57#define _DD_GETVALUE(v,n,m) (((v) & (m)) >> (n))
58
59
60/* DMA Control and Status Register offsets */
61
62#define R_MCR1                   0x00
63#define R_DMA_CTRL               0x04
64#define R_DMA_STAT               0x08
65#define R_DMA_ERR                0x0C
66#define R_MCR2                   0x10
67
68
69/* 0x00  MCR1@: Master Command Record 1 Address */
70/* 0x10  MCR2@: Master Command Record 2 Address */
71
72
73/* 0x04  DMA Control */
74
75#define  M_DMA_CTRL_WR_BURST     _DD_MAKEMASK1(16)   /* Not 5820 */
76
77#define  K_DMA_WR_BURST_128      0
78#define  K_DMA_WR_BURST_240      M_DMA_CRTL_WR_BURST
79
80#define M_DMA_CTRL_MOD_NORM      _DD_MAKEMASK1(22)
81#define M_DMA_CTRL_RNG_MODE      _DD_MAKEMASK1(23)
82#define M_DMA_CTRL_DMAERR_EN     _DD_MAKEMASK1(25)
83#define M_DMA_CTRL_NORM_PCI      _DD_MAKEMASK1(26)   /* Not 5820 */
84#define M_DMA_CTRL_LE_CRYPTO     _DD_MAKEMASK1(27)   /* Not 5820 */
85#define M_DMA_CTRL_MCR1_INT_EN   _DD_MAKEMASK1(29)
86#define M_DMA_CTRL_MCR2_INT_EN   _DD_MAKEMASK1(30)
87#define M_DMA_CTRL_RESET         _DD_MAKEMASK1(31)
88
89
90/* 0x08  DMA Status */
91
92#define M_DMA_STAT_MCR2_EMPTY    _DD_MAKEMASK1(24)   /* Not 5820 */
93#define M_DMA_STAT_MCR1_EMPTY    _DD_MAKEMASK1(25)   /* Not 5820 */
94#define M_DMA_STAT_MCR2_INTR     _DD_MAKEMASK1(26)
95#define M_DMA_STAT_MCR2_FULL     _DD_MAKEMASK1(27)
96#define M_DMA_STAT_DMAERR_INTR   _DD_MAKEMASK1(28)
97#define M_DMA_STAT_MCR1_INTR     _DD_MAKEMASK1(29)
98#define M_DMA_STAT_MCR1_FULL     _DD_MAKEMASK1(30)
99#define M_DMA_STAT_MSTR_ACCESS   _DD_MAKEMASK1(31)
100
101/* 0x0C  DMA Error Address */
102
103#define M_DMA_ERR_RD_FAULT       _DD_MAKEMASK1(1)
104#define M_DMA_ERR_ADDR           0xFFFFFFFC
105
106
107/* Master Command Record Header Format */
108
109#define S_MCR_NUM_PACKETS        0
110#define M_MCR_NUM_PACKETS        _DD_MAKEMASK(16,S_MCR_NUM_PACKETS)
111#define V_MCR_NUM_PACKETS(x)     _DD_MAKEVALUE(x,S_MCR_NUM_PACKETS)
112#define G_MCR_NUM_PACKETS(x)     _DD_GETVALUE(x,S_MCR_NUM_PACKETS,M_MCR_NUM_PACKETS)
113
114/* Input flags */
115
116#define M_MCR_SUPPRESS_INTR      _DD_MAKEMASK1(31)
117
118/* Output flags */
119
120#define M_MCR_DONE               _DD_MAKEMASK1(16)
121#define M_MCR_ERROR              _DD_MAKEMASK1(17)
122
123#define S_MCR_ERROR_CODE         24
124#define M_MCR_ERROR_CODE         _DD_MAKEMASK(8,S_MCR_ERROR_CODE)
125#define V_MCR_ERROR_CODE(x)      _DD_MAKEVALUE(x,S_MCR_ERROR_CODE)
126#define G_MCR_ERROR_CODE(x)      _DD_GETVALUE(x,S_MCR_ERROR_CODE,M_MCR_ERROR_CODE)
127#define K_MCR_ERROR_OK           0
128#define K_MCR_ERROR_UNKNOWN_OP   1
129#define K_MCR_ERROR_DSA_SHORT    2
130#define K_MCR_ERROR_PKI_SHORT    3
131#define K_MCR_ERROR_PKO_SHORT    4                    /* Not 5820 */
132#define K_MCR_ERROR_CHAIN_SHORT  5                    /* Not 5820 */
133#define K_MCR_ERROR_FIFO         6                    /* Not 5820 */
134
135/* In both cases, the header word is followed by an array of N PD entries:
136     commandContext[0]
137     dataBuffer[0]
138     pktLen[0]
139     outputBuffer[0]
140     ...
141     commandContext[n-1]
142     dataBuffer[n-1]
143     pktLen[n-1]
144     outputBuffer[n-1]
145*/
146
147#define MCR_WORDS(n)  (1+8*(n))
148#define MCR_BYTES(n)  ((1+8*(n))*4)
149
150
151/* Data Buffer Chain Entry Offsets */
152
153#define DBC_ADDR                 0
154#define DBC_NEXT                 4
155#define DBC_LEN                  8
156
157#define CHAIN_WORDS              3
158
159#define S_DBC_DATA_LEN           0
160#define M_DBC_DATA_LEN           _DD_MAKEMASK(16,S_DBC_DATA_LEN)
161#define V_DBC_DATA_LEN(x)        _DD_MAKEVALUE(x,S_DBC_DATA_LEN)
162#define G_DBC_DATA_LEN(x)        _DD_GETVALUE(x,S_DBC_DATA_LEN,M_DBC_DATA_LEN)
163
164/* Packet Descriptor Offsets */
165
166#define PD_CC_ADDR               0
167#define PD_INPUT_FRAG            4
168#define PD_INPUT_FRAG_ADDR       (PD_INPUT_FRAG+DBC_ADDR)
169#define PD_INPUT_FRAG_NEXT       (PD_INPUT_FRAG+DBC_NEXT)
170#define PD_INPUT_FRAG_LEN        (PD_INPUT_FRAG+DBC_LEN)
171#define PD_PKT_LEN               16
172#define PD_OUTPUT_FRAG           20
173#define PD_OUTPUT_FRAG_ADDR      (PD_OUTPUT_FRAG+DBC_ADDR)
174#define PD_OUTPUT_FRAG_NEXT      (PD_OUTPUT_FRAG+DBC_NEXT)
175#define PD_OUTPUT_FRAG_LEN       (PD_OUTPUT_FRAG+DBC_LEN)
176
177#define PD_SIZE                  32
178
179#define S_PD_PKT_LEN             16
180#define M_PD_PKT_LEN             _DD_MAKEMASK(16,S_PD_PKT_LEN)
181#define V_PD_PKT_LEN(x)          _DD_MAKEVALUE(x,S_PD_PKT_LEN)
182#define G_PD_PKT_LEN(x)          _DD_GETVALUE(x,S_PD_PKT_LEN,M_PD_PKT_LEN)
183
184
185/* Crypotographic Operations */
186
187/* MCR1 only (symmetric) */
188#define K_IPSEC_3DES             0x0000                /* Not 5820 */
189#define K_SSL_MAC                0x0001
190#define K_TLS_HMAC               0x0002
191#define K_SSL_3DES               0x0003
192#define K_ARC4                   0x0004
193#define K_HASH                   0x0005
194
195/* MCR2 only (asymmetric) */
196#define K_DH_PK_GEN              0x0001
197#define K_DH_SK_GEN              0x0002
198#define K_RSA_PK_OP              0x0003
199#define K_RSA_SK_OP              0x0004
200#define K_DSA_SIGN               0x0005
201#define K_DSA_VERIF              0x0006
202#define K_RNG_DIRECT             0x0041
203#define K_RNG_SHA1               0x0042
204#define K_MOD_ADD                0x0043
205#define K_MOD_SUB                0x0044
206#define K_MOD_MUL                0x0045
207#define K_MOD_REDUCE             0x0046
208#define K_MOD_EXP                0x0047
209#define K_MOD_INV                0x0048               /* Not 5821 */
210#define K_MOD_2EXP               0x0049               /* Not 5820 */
211
212
213/* Command Context Header */
214
215/* Word 0 */
216
217#define S_CC_OPCODE              16
218#define M_CC_OPCODE              _DD_MAKEMASK(16,S_CC_OPCODE)
219#define V_CC_OPCODE(x)           _DD_MAKEVALUE(x,S_CC_OPCODE)
220#define G_CC_OPCODE(x)           _DD_GETVALUE(x,S_CC_OPCODE,M_CC_OPCODE)
221
222#define S_CC_LEN                 0
223#define M_CC_LEN                 _DD_MAKEMASK(16,S_CC_LEN)
224#define V_CC_LEN(x)              _DD_MAKEVALUE(x,S_CC_LEN)
225#define G_CC_LEN(x)              _DD_GETVALUE(x,S_CC_LEN,M_CC_LEN)
226
227/* Word 1 */
228
229#define S_CC_FLAGS               12
230#define M_CC_FLAGS               _DD_MAKEMASK(4,S_CC_FLAGS)
231#define V_CC_FLAGS(x)            _DD_MAKEVALUE(x,S_CC_FLAGS)
232#define G_CC_FLAGS(x)            _DD_GETVALUE(x,S_CC_OPCODE,M_CC_OPCODE)
233
234/* The remaining command context fields depend on the opcode. */
235
236/* IPSEC 3DES (K_IPSEC_3DES) */
237
238/* SSL MAC (K_SSL_MAC) */
239/* TLS HMAC (K_TLS_HMAC) */
240/* Pure MD5/SHA-1 Hash (K_HASH) */
241
242#define K_HASH_FLAGS_MD5         1
243#define K_HASH_FLAGS_SHA1        2
244
245/* SSL MAC (K_SSL_MAC) */
246
247#define SSL_MAC_CMD_WORDS        22
248
249/* TLS HMAC (K_TLS_HMAC) */
250
251#define TLS_HMAC_CMD_WORDS       16
252
253/* Pure MD5/SHA-1 Hash (K_HASH) */
254
255/* SSL/TLS DES/3DES (K_SSL_3DES) */
256
257/* ARCFOUR (K_ARC4) */
258
259#define ARC4_STATE_WORDS         (1 + 256/4)
260#define ARC4_CMD_WORDS           (2 + ARC4_STATE_WORDS)
261
262#define M_ARC4_FLAGS_KEY         _DD_MAKEMASK1(10)
263#define M_ARC4_FLAGS_WRITEBACK   _DD_MAKEMASK1(11)
264#define M_ARC4_FLAGS_NULLDATA    _DD_MAKEMASK1(12)
265
266
267/* Random number generation (K_RNG_DIRECT, K_RNG_SHA1) */
268
269/* Modular arithmetic (K_MOD_ADD, K_MOD_SUB, K_MOD_MUL) */
270
271/* Modular Remainder (K_MOD_REDUCE) */
272
273/* Modular Exponentiation (K_MOD_EXP) */
274
275/* Double Modular Exponentiation (K_MOD_2EXP) */
276
277
278#endif /* _BCM_5821_H_ */
279