crypto/octeontx: add session management operations
[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_ALWAYS_USE_SG_MODE */
29 #define CPT_ALWAYS_USE_SEPARATE_BUF
30
31 typedef struct sglist_comp {
32         union {
33                 uint64_t len;
34                 struct {
35                         uint16_t len[4];
36                 } s;
37         } u;
38         uint64_t ptr[4];
39 } sg_comp_t;
40
41 struct cpt_sess_misc {
42         /** CPT opcode */
43         uint16_t cpt_op:4;
44         /** ZUC, SNOW3G &  KASUMI flags */
45         uint16_t zsk_flag:4;
46         /** Flag for AES GCM */
47         uint16_t aes_gcm:1;
48         /** Flag for AES CTR */
49         uint16_t aes_ctr:1;
50         /** Flag for NULL cipher/auth */
51         uint16_t is_null:1;
52         /** Flag for GMAC */
53         uint16_t is_gmac:1;
54         /** AAD length */
55         uint16_t aad_length;
56         /** MAC len in bytes */
57         uint8_t mac_len;
58         /** IV length in bytes */
59         uint8_t iv_length;
60         /** Auth IV length in bytes */
61         uint8_t auth_iv_length;
62         /** Reserved field */
63         uint8_t rsvd1;
64         /** IV offset in bytes */
65         uint16_t iv_offset;
66         /** Auth IV offset in bytes */
67         uint16_t auth_iv_offset;
68         /** Salt */
69         uint32_t salt;
70         /** Context DMA address */
71         phys_addr_t ctx_dma_addr;
72 };
73
74 typedef union {
75         uint64_t flags;
76         struct {
77 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
78                 uint64_t enc_cipher   : 4;
79                 uint64_t reserved1    : 1;
80                 uint64_t aes_key      : 2;
81                 uint64_t iv_source    : 1;
82                 uint64_t hash_type    : 4;
83                 uint64_t reserved2    : 3;
84                 uint64_t auth_input_type : 1;
85                 uint64_t mac_len      : 8;
86                 uint64_t reserved3    : 8;
87                 uint64_t encr_offset  : 16;
88                 uint64_t iv_offset    : 8;
89                 uint64_t auth_offset  : 8;
90 #else
91                 uint64_t auth_offset  : 8;
92                 uint64_t iv_offset    : 8;
93                 uint64_t encr_offset  : 16;
94                 uint64_t reserved3    : 8;
95                 uint64_t mac_len      : 8;
96                 uint64_t auth_input_type : 1;
97                 uint64_t reserved2    : 3;
98                 uint64_t hash_type    : 4;
99                 uint64_t iv_source    : 1;
100                 uint64_t aes_key      : 2;
101                 uint64_t reserved1    : 1;
102                 uint64_t enc_cipher   : 4;
103 #endif
104         } e;
105 } encr_ctrl_t;
106
107 typedef struct {
108         encr_ctrl_t enc_ctrl;
109         uint8_t  encr_key[32];
110         uint8_t  encr_iv[16];
111 } mc_enc_context_t;
112
113 typedef struct {
114         uint8_t  ipad[64];
115         uint8_t  opad[64];
116 } mc_fc_hmac_context_t;
117
118 typedef struct {
119         mc_enc_context_t     enc;
120         mc_fc_hmac_context_t hmac;
121 } mc_fc_context_t;
122
123 typedef struct {
124         uint8_t encr_auth_iv[16];
125         uint8_t ci_key[16];
126         uint8_t zuc_const[32];
127 } mc_zuc_snow3g_ctx_t;
128
129 typedef struct {
130         uint8_t reg_A[8];
131         uint8_t ci_key[16];
132 } mc_kasumi_ctx_t;
133
134 struct cpt_ctx {
135         /* Below fields are accessed by sw */
136         uint64_t enc_cipher     :8;
137         uint64_t hash_type      :8;
138         uint64_t mac_len        :8;
139         uint64_t auth_key_len   :8;
140         uint64_t fc_type        :4;
141         uint64_t hmac           :1;
142         uint64_t zsk_flags      :3;
143         uint64_t k_ecb          :1;
144         uint64_t snow3g         :1;
145         uint64_t rsvd           :22;
146         /* Below fields are accessed by hardware */
147         union {
148                 mc_fc_context_t fctx;
149                 mc_zuc_snow3g_ctx_t zs_ctx;
150                 mc_kasumi_ctx_t k_ctx;
151         };
152         uint8_t  auth_key[64];
153 };
154
155 #define CPT_P_ENC_CTRL(fctx)  fctx->enc.enc_ctrl.e
156
157 #endif /* _CPT_MCODE_DEFINES_H_ */