Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only
0002  * Copyright (C) 2020 Marvell.
0003  */
0004 
0005 #ifndef __OTX2_CPT_ALGS_H
0006 #define __OTX2_CPT_ALGS_H
0007 
0008 #include <crypto/hash.h>
0009 #include <crypto/skcipher.h>
0010 #include <crypto/aead.h>
0011 #include "otx2_cpt_common.h"
0012 
0013 #define OTX2_CPT_MAX_ENC_KEY_SIZE    32
0014 #define OTX2_CPT_MAX_HASH_KEY_SIZE   64
0015 #define OTX2_CPT_MAX_KEY_SIZE (OTX2_CPT_MAX_ENC_KEY_SIZE + \
0016                    OTX2_CPT_MAX_HASH_KEY_SIZE)
0017 enum otx2_cpt_request_type {
0018     OTX2_CPT_ENC_DEC_REQ            = 0x1,
0019     OTX2_CPT_AEAD_ENC_DEC_REQ       = 0x2,
0020     OTX2_CPT_AEAD_ENC_DEC_NULL_REQ  = 0x3,
0021     OTX2_CPT_PASSTHROUGH_REQ    = 0x4
0022 };
0023 
0024 enum otx2_cpt_major_opcodes {
0025     OTX2_CPT_MAJOR_OP_MISC = 0x01,
0026     OTX2_CPT_MAJOR_OP_FC   = 0x33,
0027     OTX2_CPT_MAJOR_OP_HMAC = 0x35,
0028 };
0029 
0030 enum otx2_cpt_cipher_type {
0031     OTX2_CPT_CIPHER_NULL = 0x0,
0032     OTX2_CPT_DES3_CBC = 0x1,
0033     OTX2_CPT_DES3_ECB = 0x2,
0034     OTX2_CPT_AES_CBC  = 0x3,
0035     OTX2_CPT_AES_ECB  = 0x4,
0036     OTX2_CPT_AES_CFB  = 0x5,
0037     OTX2_CPT_AES_CTR  = 0x6,
0038     OTX2_CPT_AES_GCM  = 0x7,
0039     OTX2_CPT_AES_XTS  = 0x8
0040 };
0041 
0042 enum otx2_cpt_mac_type {
0043     OTX2_CPT_MAC_NULL = 0x0,
0044     OTX2_CPT_MD5      = 0x1,
0045     OTX2_CPT_SHA1     = 0x2,
0046     OTX2_CPT_SHA224   = 0x3,
0047     OTX2_CPT_SHA256   = 0x4,
0048     OTX2_CPT_SHA384   = 0x5,
0049     OTX2_CPT_SHA512   = 0x6,
0050     OTX2_CPT_GMAC     = 0x7
0051 };
0052 
0053 enum otx2_cpt_aes_key_len {
0054     OTX2_CPT_AES_128_BIT = 0x1,
0055     OTX2_CPT_AES_192_BIT = 0x2,
0056     OTX2_CPT_AES_256_BIT = 0x3
0057 };
0058 
0059 union otx2_cpt_encr_ctrl {
0060     u64 u;
0061     struct {
0062 #if defined(__BIG_ENDIAN_BITFIELD)
0063         u64 enc_cipher:4;
0064         u64 reserved_59:1;
0065         u64 aes_key:2;
0066         u64 iv_source:1;
0067         u64 mac_type:4;
0068         u64 reserved_49_51:3;
0069         u64 auth_input_type:1;
0070         u64 mac_len:8;
0071         u64 reserved_32_39:8;
0072         u64 encr_offset:16;
0073         u64 iv_offset:8;
0074         u64 auth_offset:8;
0075 #else
0076         u64 auth_offset:8;
0077         u64 iv_offset:8;
0078         u64 encr_offset:16;
0079         u64 reserved_32_39:8;
0080         u64 mac_len:8;
0081         u64 auth_input_type:1;
0082         u64 reserved_49_51:3;
0083         u64 mac_type:4;
0084         u64 iv_source:1;
0085         u64 aes_key:2;
0086         u64 reserved_59:1;
0087         u64 enc_cipher:4;
0088 #endif
0089     } e;
0090 };
0091 
0092 struct otx2_cpt_cipher {
0093     const char *name;
0094     u8 value;
0095 };
0096 
0097 struct otx2_cpt_fc_enc_ctx {
0098     union otx2_cpt_encr_ctrl enc_ctrl;
0099     u8 encr_key[32];
0100     u8 encr_iv[16];
0101 };
0102 
0103 union otx2_cpt_fc_hmac_ctx {
0104     struct {
0105         u8 ipad[64];
0106         u8 opad[64];
0107     } e;
0108     struct {
0109         u8 hmac_calc[64]; /* HMAC calculated */
0110         u8 hmac_recv[64]; /* HMAC received */
0111     } s;
0112 };
0113 
0114 struct otx2_cpt_fc_ctx {
0115     struct otx2_cpt_fc_enc_ctx enc;
0116     union otx2_cpt_fc_hmac_ctx hmac;
0117 };
0118 
0119 struct otx2_cpt_enc_ctx {
0120     u32 key_len;
0121     u8 enc_key[OTX2_CPT_MAX_KEY_SIZE];
0122     u8 cipher_type;
0123     u8 key_type;
0124     u8 enc_align_len;
0125     struct crypto_skcipher *fbk_cipher;
0126 };
0127 
0128 union otx2_cpt_offset_ctrl {
0129     u64 flags;
0130     struct {
0131 #if defined(__BIG_ENDIAN_BITFIELD)
0132         u64 reserved:32;
0133         u64 enc_data_offset:16;
0134         u64 iv_offset:8;
0135         u64 auth_offset:8;
0136 #else
0137         u64 auth_offset:8;
0138         u64 iv_offset:8;
0139         u64 enc_data_offset:16;
0140         u64 reserved:32;
0141 #endif
0142     } e;
0143 };
0144 
0145 struct otx2_cpt_req_ctx {
0146     struct otx2_cpt_req_info cpt_req;
0147     union otx2_cpt_offset_ctrl ctrl_word;
0148     struct otx2_cpt_fc_ctx fctx;
0149     union {
0150         struct skcipher_request sk_fbk_req;
0151         struct aead_request fbk_req;
0152     };
0153 };
0154 
0155 struct otx2_cpt_sdesc {
0156     struct shash_desc shash;
0157 };
0158 
0159 struct otx2_cpt_aead_ctx {
0160     u8 key[OTX2_CPT_MAX_KEY_SIZE];
0161     struct crypto_shash *hashalg;
0162     struct otx2_cpt_sdesc *sdesc;
0163     struct crypto_aead *fbk_cipher;
0164     u8 *ipad;
0165     u8 *opad;
0166     u32 enc_key_len;
0167     u32 auth_key_len;
0168     u8 cipher_type;
0169     u8 mac_type;
0170     u8 key_type;
0171     u8 is_trunc_hmac;
0172     u8 enc_align_len;
0173 };
0174 int otx2_cpt_crypto_init(struct pci_dev *pdev, struct module *mod,
0175              int num_queues, int num_devices);
0176 void otx2_cpt_crypto_exit(struct pci_dev *pdev, struct module *mod);
0177 
0178 #endif /* __OTX2_CPT_ALGS_H */