Linux 5.1.15
[linux/fpc-iii.git] / drivers / crypto / bcm / spum.h
blobd0a5b58286387990e1ca6ba149c46dd97c29ecdf
1 /*
2 * Copyright 2016 Broadcom
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2, as
6 * published by the Free Software Foundation (the "GPL").
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License version 2 (GPLv2) for more details.
13 * You should have received a copy of the GNU General Public License
14 * version 2 (GPLv2) along with this source code.
18 * This file contains SPU message definitions specific to SPU-M.
21 #ifndef _SPUM_H_
22 #define _SPUM_H_
24 #define SPU_CRYPTO_OPERATION_GENERIC 0x1
26 /* Length of STATUS field in tx and rx packets */
27 #define SPU_TX_STATUS_LEN 4
29 /* SPU-M error codes */
30 #define SPU_STATUS_MASK 0x0000FF00
31 #define SPU_STATUS_SUCCESS 0x00000000
32 #define SPU_STATUS_INVALID_ICV 0x00000100
34 #define SPU_STATUS_ERROR_FLAG 0x00020000
36 /* Request message. MH + EMH + BDESC + BD header */
37 #define SPU_REQ_FIXED_LEN 24
40 * Max length of a SPU message header. Used to allocate a buffer where
41 * the SPU message header is constructed. Can be used for either a SPU-M
42 * header or a SPU2 header.
43 * For SPU-M, sum of the following:
44 * MH - 4 bytes
45 * EMH - 4
46 * SCTX - 3 +
47 * max auth key len - 64
48 * max cipher key len - 264 (RC4)
49 * max IV len - 16
50 * BDESC - 12
51 * BD header - 4
52 * Total: 371
54 * For SPU2, FMD_SIZE (32) plus lengths of hash and cipher keys,
55 * hash and cipher IVs. If SPU2 does not support RC4, then
57 #define SPU_HEADER_ALLOC_LEN (SPU_REQ_FIXED_LEN + MAX_KEY_SIZE + \
58 MAX_KEY_SIZE + MAX_IV_SIZE)
61 * Response message header length. Normally MH, EMH, BD header, but when
62 * BD_SUPPRESS is used for hash requests, there is no BD header.
64 #define SPU_RESP_HDR_LEN 12
65 #define SPU_HASH_RESP_HDR_LEN 8
68 * Max value that can be represented in the Payload Length field of the BD
69 * header. This is a 16-bit field.
71 #define SPUM_NS2_MAX_PAYLOAD (BIT(16) - 1)
74 * NSP SPU is limited to ~9KB because of FA2 FIFO size limitations;
75 * Set MAX_PAYLOAD to 8k to allow for addition of header, digest, etc.
76 * and stay within limitation.
79 #define SPUM_NSP_MAX_PAYLOAD 8192
81 /* Buffer Descriptor Header [BDESC]. SPU in big-endian mode. */
82 struct BDESC_HEADER {
83 u16 offset_mac; /* word 0 [31-16] */
84 u16 length_mac; /* word 0 [15-0] */
85 u16 offset_crypto; /* word 1 [31-16] */
86 u16 length_crypto; /* word 1 [15-0] */
87 u16 offset_icv; /* word 2 [31-16] */
88 u16 offset_iv; /* word 2 [15-0] */
91 /* Buffer Data Header [BD]. SPU in big-endian mode. */
92 struct BD_HEADER {
93 u16 size;
94 u16 prev_length;
97 /* Command Context Header. SPU-M in big endian mode. */
98 struct MHEADER {
99 u8 flags; /* [31:24] */
100 u8 op_code; /* [23:16] */
101 u16 reserved; /* [15:0] */
104 /* MH header flags bits */
105 #define MH_SUPDT_PRES BIT(0)
106 #define MH_HASH_PRES BIT(2)
107 #define MH_BD_PRES BIT(3)
108 #define MH_MFM_PRES BIT(4)
109 #define MH_BDESC_PRES BIT(5)
110 #define MH_SCTX_PRES BIT(7)
112 /* SCTX word 0 bit offsets and fields masks */
113 #define SCTX_SIZE 0x000000FF
115 /* SCTX word 1 bit shifts and field masks */
116 #define UPDT_OFST 0x000000FF /* offset of SCTX updateable fld */
117 #define HASH_TYPE 0x00000300 /* hash alg operation type */
118 #define HASH_TYPE_SHIFT 8
119 #define HASH_MODE 0x00001C00 /* one of spu2_hash_mode */
120 #define HASH_MODE_SHIFT 10
121 #define HASH_ALG 0x0000E000 /* hash algorithm */
122 #define HASH_ALG_SHIFT 13
123 #define CIPHER_TYPE 0x00030000 /* encryption operation type */
124 #define CIPHER_TYPE_SHIFT 16
125 #define CIPHER_MODE 0x001C0000 /* encryption mode */
126 #define CIPHER_MODE_SHIFT 18
127 #define CIPHER_ALG 0x00E00000 /* encryption algo */
128 #define CIPHER_ALG_SHIFT 21
129 #define ICV_IS_512 BIT(27)
130 #define ICV_IS_512_SHIFT 27
131 #define CIPHER_ORDER BIT(30)
132 #define CIPHER_ORDER_SHIFT 30
133 #define CIPHER_INBOUND BIT(31)
134 #define CIPHER_INBOUND_SHIFT 31
136 /* SCTX word 2 bit shifts and field masks */
137 #define EXP_IV_SIZE 0x7
138 #define IV_OFFSET BIT(3)
139 #define IV_OFFSET_SHIFT 3
140 #define GEN_IV BIT(5)
141 #define GEN_IV_SHIFT 5
142 #define EXPLICIT_IV BIT(6)
143 #define EXPLICIT_IV_SHIFT 6
144 #define SCTX_IV BIT(7)
145 #define SCTX_IV_SHIFT 7
146 #define ICV_SIZE 0x0F00
147 #define ICV_SIZE_SHIFT 8
148 #define CHECK_ICV BIT(12)
149 #define CHECK_ICV_SHIFT 12
150 #define INSERT_ICV BIT(13)
151 #define INSERT_ICV_SHIFT 13
152 #define BD_SUPPRESS BIT(19)
153 #define BD_SUPPRESS_SHIFT 19
155 /* Generic Mode Security Context Structure [SCTX] */
156 struct SCTX {
157 /* word 0: protocol flags */
158 u32 proto_flags;
160 /* word 1: cipher flags */
161 u32 cipher_flags;
163 /* word 2: Extended cipher flags */
164 u32 ecf;
168 struct SPUHEADER {
169 struct MHEADER mh;
170 u32 emh;
171 struct SCTX sa;
174 #endif /* _SPUM_H_ */