50657a289910a9f36cdf1460b2bca19d50ed9371
[dpdk.git] / drivers / common / cpt / cpt_mcode_defines.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium, Inc
3  */
4
5 #ifndef _CPT_MCODE_DEFINES_H_
6 #define _CPT_MCODE_DEFINES_H_
7
8 #include <rte_byteorder.h>
9 #include <rte_memory.h>
10
11 /*
12  * This file defines macros and structures according to microcode spec
13  *
14  */
15
16 #define CPT_BYTE_16             16
17 #define CPT_BYTE_24             24
18 #define CPT_BYTE_32             32
19 #define CPT_MAX_SG_IN_OUT_CNT   32
20 #define CPT_MAX_SG_CNT          (CPT_MAX_SG_IN_OUT_CNT/2)
21
22 #define COMPLETION_CODE_SIZE    8
23 #define COMPLETION_CODE_INIT    0
24
25 #define SG_LIST_HDR_SIZE        (8u)
26 #define SG_ENTRY_SIZE           sizeof(sg_comp_t)
27
28 #define CPT_DMA_MODE            (1 << 7)
29
30 #define CPT_FROM_CTX            0
31 #define CPT_FROM_DPTR           1
32
33 #define FC_GEN                  0x1
34 #define ZUC_SNOW3G              0x2
35 #define KASUMI                  0x3
36 #define HASH_HMAC               0x4
37
38 #define ZS_EA                   0x1
39 #define ZS_IA                   0x2
40 #define K_F8                    0x4
41 #define K_F9                    0x8
42
43 #define CPT_OP_CIPHER_ENCRYPT   0x1
44 #define CPT_OP_CIPHER_DECRYPT   0x2
45 #define CPT_OP_CIPHER_MASK      0x3
46
47 #define CPT_OP_AUTH_VERIFY      0x4
48 #define CPT_OP_AUTH_GENERATE    0x8
49 #define CPT_OP_AUTH_MASK        0xC
50
51 #define CPT_OP_ENCODE   (CPT_OP_CIPHER_ENCRYPT | CPT_OP_AUTH_GENERATE)
52 #define CPT_OP_DECODE   (CPT_OP_CIPHER_DECRYPT | CPT_OP_AUTH_VERIFY)
53
54 /* #define CPT_ALWAYS_USE_SG_MODE */
55 #define CPT_ALWAYS_USE_SEPARATE_BUF
56
57 typedef enum {
58         MD5_TYPE        = 1,
59         SHA1_TYPE       = 2,
60         SHA2_SHA224     = 3,
61         SHA2_SHA256     = 4,
62         SHA2_SHA384     = 5,
63         SHA2_SHA512     = 6,
64         GMAC_TYPE       = 7,
65         XCBC_TYPE       = 8,
66         SHA3_SHA224     = 10,
67         SHA3_SHA256     = 11,
68         SHA3_SHA384     = 12,
69         SHA3_SHA512     = 13,
70         SHA3_SHAKE256   = 14,
71         SHA3_SHAKE512   = 15,
72
73         /* These are only for software use */
74         ZUC_EIA3        = 0x90,
75         SNOW3G_UIA2     = 0x91,
76         KASUMI_F9_CBC   = 0x92,
77         KASUMI_F9_ECB   = 0x93,
78 } mc_hash_type_t;
79
80 typedef enum {
81         /* To support passthrough */
82         PASSTHROUGH  = 0x0,
83         /*
84          * These are defined by MC for Flexi crypto
85          * for field of 4 bits
86          */
87         DES3_CBC    = 0x1,
88         DES3_ECB    = 0x2,
89         AES_CBC     = 0x3,
90         AES_ECB     = 0x4,
91         AES_CFB     = 0x5,
92         AES_CTR     = 0x6,
93         AES_GCM     = 0x7,
94         AES_XTS     = 0x8,
95
96         /* These are only for software use */
97         ZUC_EEA3        = 0x90,
98         SNOW3G_UEA2     = 0x91,
99         KASUMI_F8_CBC   = 0x92,
100         KASUMI_F8_ECB   = 0x93,
101 } mc_cipher_type_t;
102
103 typedef enum {
104         AES_128_BIT = 0x1,
105         AES_192_BIT = 0x2,
106         AES_256_BIT = 0x3
107 } mc_aes_type_t;
108
109
110 typedef struct sglist_comp {
111         union {
112                 uint64_t len;
113                 struct {
114                         uint16_t len[4];
115                 } s;
116         } u;
117         uint64_t ptr[4];
118 } sg_comp_t;
119
120 struct cpt_sess_misc {
121         /** CPT opcode */
122         uint16_t cpt_op:4;
123         /** ZUC, SNOW3G &  KASUMI flags */
124         uint16_t zsk_flag:4;
125         /** Flag for AES GCM */
126         uint16_t aes_gcm:1;
127         /** Flag for AES CTR */
128         uint16_t aes_ctr:1;
129         /** Flag for NULL cipher/auth */
130         uint16_t is_null:1;
131         /** Flag for GMAC */
132         uint16_t is_gmac:1;
133         /** AAD length */
134         uint16_t aad_length;
135         /** MAC len in bytes */
136         uint8_t mac_len;
137         /** IV length in bytes */
138         uint8_t iv_length;
139         /** Auth IV length in bytes */
140         uint8_t auth_iv_length;
141         /** Reserved field */
142         uint8_t rsvd1;
143         /** IV offset in bytes */
144         uint16_t iv_offset;
145         /** Auth IV offset in bytes */
146         uint16_t auth_iv_offset;
147         /** Salt */
148         uint32_t salt;
149         /** Context DMA address */
150         phys_addr_t ctx_dma_addr;
151 };
152
153 typedef union {
154         uint64_t flags;
155         struct {
156 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
157                 uint64_t enc_cipher   : 4;
158                 uint64_t reserved1    : 1;
159                 uint64_t aes_key      : 2;
160                 uint64_t iv_source    : 1;
161                 uint64_t hash_type    : 4;
162                 uint64_t reserved2    : 3;
163                 uint64_t auth_input_type : 1;
164                 uint64_t mac_len      : 8;
165                 uint64_t reserved3    : 8;
166                 uint64_t encr_offset  : 16;
167                 uint64_t iv_offset    : 8;
168                 uint64_t auth_offset  : 8;
169 #else
170                 uint64_t auth_offset  : 8;
171                 uint64_t iv_offset    : 8;
172                 uint64_t encr_offset  : 16;
173                 uint64_t reserved3    : 8;
174                 uint64_t mac_len      : 8;
175                 uint64_t auth_input_type : 1;
176                 uint64_t reserved2    : 3;
177                 uint64_t hash_type    : 4;
178                 uint64_t iv_source    : 1;
179                 uint64_t aes_key      : 2;
180                 uint64_t reserved1    : 1;
181                 uint64_t enc_cipher   : 4;
182 #endif
183         } e;
184 } encr_ctrl_t;
185
186 typedef struct {
187         encr_ctrl_t enc_ctrl;
188         uint8_t  encr_key[32];
189         uint8_t  encr_iv[16];
190 } mc_enc_context_t;
191
192 typedef struct {
193         uint8_t  ipad[64];
194         uint8_t  opad[64];
195 } mc_fc_hmac_context_t;
196
197 typedef struct {
198         mc_enc_context_t     enc;
199         mc_fc_hmac_context_t hmac;
200 } mc_fc_context_t;
201
202 typedef struct {
203         uint8_t encr_auth_iv[16];
204         uint8_t ci_key[16];
205         uint8_t zuc_const[32];
206 } mc_zuc_snow3g_ctx_t;
207
208 typedef struct {
209         uint8_t reg_A[8];
210         uint8_t ci_key[16];
211 } mc_kasumi_ctx_t;
212
213 struct cpt_ctx {
214         /* Below fields are accessed by sw */
215         uint64_t enc_cipher     :8;
216         uint64_t hash_type      :8;
217         uint64_t mac_len        :8;
218         uint64_t auth_key_len   :8;
219         uint64_t fc_type        :4;
220         uint64_t hmac           :1;
221         uint64_t zsk_flags      :3;
222         uint64_t k_ecb          :1;
223         uint64_t snow3g         :1;
224         uint64_t rsvd           :22;
225         /* Below fields are accessed by hardware */
226         union {
227                 mc_fc_context_t fctx;
228                 mc_zuc_snow3g_ctx_t zs_ctx;
229                 mc_kasumi_ctx_t k_ctx;
230         };
231         uint8_t  auth_key[64];
232 };
233
234 typedef struct fc_params digest_params_t;
235
236 /* Cipher Algorithms */
237 typedef mc_cipher_type_t cipher_type_t;
238
239 /* Auth Algorithms */
240 typedef mc_hash_type_t auth_type_t;
241
242 #define CPT_P_ENC_CTRL(fctx)  fctx->enc.enc_ctrl.e
243
244 #define SESS_PRIV(__sess) \
245         (void *)((uint8_t *)__sess + sizeof(struct cpt_sess_misc))
246
247 #endif /* _CPT_MCODE_DEFINES_H_ */