Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0
0002  * Marvell OcteonTX CPT driver
0003  *
0004  * Copyright (C) 2019 Marvell International Ltd.
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License version 2 as
0008  * published by the Free Software Foundation.
0009  */
0010 
0011 #ifndef __OTX_CPT_ALGS_H
0012 #define __OTX_CPT_ALGS_H
0013 
0014 #include <crypto/hash.h>
0015 #include "otx_cpt_common.h"
0016 
0017 #define OTX_CPT_MAX_ENC_KEY_SIZE    32
0018 #define OTX_CPT_MAX_HASH_KEY_SIZE   64
0019 #define OTX_CPT_MAX_KEY_SIZE (OTX_CPT_MAX_ENC_KEY_SIZE + \
0020                   OTX_CPT_MAX_HASH_KEY_SIZE)
0021 enum otx_cpt_request_type {
0022     OTX_CPT_ENC_DEC_REQ            = 0x1,
0023     OTX_CPT_AEAD_ENC_DEC_REQ       = 0x2,
0024     OTX_CPT_AEAD_ENC_DEC_NULL_REQ  = 0x3,
0025     OTX_CPT_PASSTHROUGH_REQ        = 0x4
0026 };
0027 
0028 enum otx_cpt_major_opcodes {
0029     OTX_CPT_MAJOR_OP_MISC = 0x01,
0030     OTX_CPT_MAJOR_OP_FC   = 0x33,
0031     OTX_CPT_MAJOR_OP_HMAC = 0x35,
0032 };
0033 
0034 enum otx_cpt_req_type {
0035         OTX_CPT_AE_CORE_REQ,
0036         OTX_CPT_SE_CORE_REQ
0037 };
0038 
0039 enum otx_cpt_cipher_type {
0040     OTX_CPT_CIPHER_NULL = 0x0,
0041     OTX_CPT_DES3_CBC = 0x1,
0042     OTX_CPT_DES3_ECB = 0x2,
0043     OTX_CPT_AES_CBC  = 0x3,
0044     OTX_CPT_AES_ECB  = 0x4,
0045     OTX_CPT_AES_CFB  = 0x5,
0046     OTX_CPT_AES_CTR  = 0x6,
0047     OTX_CPT_AES_GCM  = 0x7,
0048     OTX_CPT_AES_XTS  = 0x8
0049 };
0050 
0051 enum otx_cpt_mac_type {
0052     OTX_CPT_MAC_NULL = 0x0,
0053     OTX_CPT_MD5      = 0x1,
0054     OTX_CPT_SHA1     = 0x2,
0055     OTX_CPT_SHA224   = 0x3,
0056     OTX_CPT_SHA256   = 0x4,
0057     OTX_CPT_SHA384   = 0x5,
0058     OTX_CPT_SHA512   = 0x6,
0059     OTX_CPT_GMAC     = 0x7
0060 };
0061 
0062 enum otx_cpt_aes_key_len {
0063     OTX_CPT_AES_128_BIT = 0x1,
0064     OTX_CPT_AES_192_BIT = 0x2,
0065     OTX_CPT_AES_256_BIT = 0x3
0066 };
0067 
0068 union otx_cpt_encr_ctrl {
0069     __be64 flags;
0070     u64 cflags;
0071     struct {
0072 #if defined(__BIG_ENDIAN_BITFIELD)
0073         u64 enc_cipher:4;
0074         u64 reserved1:1;
0075         u64 aes_key:2;
0076         u64 iv_source:1;
0077         u64 mac_type:4;
0078         u64 reserved2:3;
0079         u64 auth_input_type:1;
0080         u64 mac_len:8;
0081         u64 reserved3:8;
0082         u64 encr_offset:16;
0083         u64 iv_offset:8;
0084         u64 auth_offset:8;
0085 #else
0086         u64 auth_offset:8;
0087         u64 iv_offset:8;
0088         u64 encr_offset:16;
0089         u64 reserved3:8;
0090         u64 mac_len:8;
0091         u64 auth_input_type:1;
0092         u64 reserved2:3;
0093         u64 mac_type:4;
0094         u64 iv_source:1;
0095         u64 aes_key:2;
0096         u64 reserved1:1;
0097         u64 enc_cipher:4;
0098 #endif
0099     } e;
0100 };
0101 
0102 struct otx_cpt_cipher {
0103     const char *name;
0104     u8 value;
0105 };
0106 
0107 struct otx_cpt_enc_context {
0108     union otx_cpt_encr_ctrl enc_ctrl;
0109     u8 encr_key[32];
0110     u8 encr_iv[16];
0111 };
0112 
0113 union otx_cpt_fchmac_ctx {
0114     struct {
0115         u8 ipad[64];
0116         u8 opad[64];
0117     } e;
0118     struct {
0119         u8 hmac_calc[64]; /* HMAC calculated */
0120         u8 hmac_recv[64]; /* HMAC received */
0121     } s;
0122 };
0123 
0124 struct otx_cpt_fc_ctx {
0125     struct otx_cpt_enc_context enc;
0126     union otx_cpt_fchmac_ctx hmac;
0127 };
0128 
0129 struct otx_cpt_enc_ctx {
0130     u32 key_len;
0131     u8 enc_key[OTX_CPT_MAX_KEY_SIZE];
0132     u8 cipher_type;
0133     u8 key_type;
0134 };
0135 
0136 struct otx_cpt_des3_ctx {
0137     u32 key_len;
0138     u8 des3_key[OTX_CPT_MAX_KEY_SIZE];
0139 };
0140 
0141 union otx_cpt_offset_ctrl_word {
0142     __be64 flags;
0143     u64 cflags;
0144     struct {
0145 #if defined(__BIG_ENDIAN_BITFIELD)
0146         u64 reserved:32;
0147         u64 enc_data_offset:16;
0148         u64 iv_offset:8;
0149         u64 auth_offset:8;
0150 #else
0151         u64 auth_offset:8;
0152         u64 iv_offset:8;
0153         u64 enc_data_offset:16;
0154         u64 reserved:32;
0155 #endif
0156     } e;
0157 };
0158 
0159 struct otx_cpt_req_ctx {
0160     struct otx_cpt_req_info cpt_req;
0161     union otx_cpt_offset_ctrl_word ctrl_word;
0162     struct otx_cpt_fc_ctx fctx;
0163 };
0164 
0165 struct otx_cpt_sdesc {
0166     struct shash_desc shash;
0167 };
0168 
0169 struct otx_cpt_aead_ctx {
0170     u8 key[OTX_CPT_MAX_KEY_SIZE];
0171     struct crypto_shash *hashalg;
0172     struct otx_cpt_sdesc *sdesc;
0173     u8 *ipad;
0174     u8 *opad;
0175     u32 enc_key_len;
0176     u32 auth_key_len;
0177     u8 cipher_type;
0178     u8 mac_type;
0179     u8 key_type;
0180     u8 is_trunc_hmac;
0181 };
0182 int otx_cpt_crypto_init(struct pci_dev *pdev, struct module *mod,
0183             enum otx_cptpf_type pf_type,
0184             enum otx_cptvf_type engine_type,
0185             int num_queues, int num_devices);
0186 void otx_cpt_crypto_exit(struct pci_dev *pdev, struct module *mod,
0187              enum otx_cptvf_type engine_type);
0188 void otx_cpt_callback(int status, void *arg, void *req);
0189 
0190 #endif /* __OTX_CPT_ALGS_H */