0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <crypto/aes.h>
0017 #include <crypto/engine.h>
0018 #include <crypto/scatterwalk.h>
0019 #include <crypto/skcipher.h>
0020 #include <linux/crypto.h>
0021 #include <linux/debugfs.h>
0022 #include <linux/hw_random.h>
0023
0024 #define TQ0_TYPE_DATA 0
0025 #define TQ0_TYPE_CTRL BIT(0)
0026 #define TQ1_CIPHER BIT(1)
0027 #define TQ2_AUTH BIT(2)
0028 #define TQ3_IV BIT(3)
0029 #define TQ4_KEY0 BIT(4)
0030 #define TQ5_KEY4 BIT(5)
0031 #define TQ6_KEY6 BIT(6)
0032 #define TQ7_AKEY0 BIT(7)
0033 #define TQ8_AKEY2 BIT(8)
0034 #define TQ9_AKEY2 BIT(9)
0035
0036 #define ECB_AES 0x2
0037
0038 #define DESC_LAST 0x01
0039 #define DESC_FIRST 0x02
0040
0041 #define IPSEC_ID 0x0000
0042 #define IPSEC_STATUS_REG 0x00a8
0043 #define IPSEC_RAND_NUM_REG 0x00ac
0044 #define IPSEC_DMA_DEVICE_ID 0xff00
0045 #define IPSEC_DMA_STATUS 0xff04
0046 #define IPSEC_TXDMA_CTRL 0xff08
0047 #define IPSEC_TXDMA_FIRST_DESC 0xff0c
0048 #define IPSEC_TXDMA_CURR_DESC 0xff10
0049 #define IPSEC_RXDMA_CTRL 0xff14
0050 #define IPSEC_RXDMA_FIRST_DESC 0xff18
0051 #define IPSEC_RXDMA_CURR_DESC 0xff1c
0052 #define IPSEC_TXDMA_BUF_ADDR 0xff28
0053 #define IPSEC_RXDMA_BUF_ADDR 0xff38
0054 #define IPSEC_RXDMA_BUF_SIZE 0xff30
0055
0056 #define CE_ENCRYPTION 0x01
0057 #define CE_DECRYPTION 0x03
0058
0059 #define MAXDESC 6
0060
0061 #define DMA_STATUS_RS_EOFI BIT(22)
0062 #define DMA_STATUS_RS_PERR BIT(24)
0063 #define DMA_STATUS_RS_DERR BIT(25)
0064 #define DMA_STATUS_TS_EOFI BIT(27)
0065 #define DMA_STATUS_TS_PERR BIT(29)
0066 #define DMA_STATUS_TS_DERR BIT(30)
0067
0068 #define TXDMA_CTRL_START BIT(31)
0069 #define TXDMA_CTRL_CONTINUE BIT(30)
0070 #define TXDMA_CTRL_CHAIN_MODE BIT(29)
0071
0072 #define TXDMA_CTRL_BURST_UNK BIT(22)
0073 #define TXDMA_CTRL_INT_FAIL BIT(17)
0074 #define TXDMA_CTRL_INT_PERR BIT(16)
0075
0076 #define RXDMA_CTRL_START BIT(31)
0077 #define RXDMA_CTRL_CONTINUE BIT(30)
0078 #define RXDMA_CTRL_CHAIN_MODE BIT(29)
0079
0080 #define RXDMA_CTRL_BURST_UNK BIT(22)
0081 #define RXDMA_CTRL_INT_FINISH BIT(18)
0082 #define RXDMA_CTRL_INT_FAIL BIT(17)
0083 #define RXDMA_CTRL_INT_PERR BIT(16)
0084 #define RXDMA_CTRL_INT_EOD BIT(15)
0085 #define RXDMA_CTRL_INT_EOF BIT(14)
0086
0087 #define CE_CPU 0
0088 #define CE_DMA 1
0089
0090
0091
0092
0093
0094
0095
0096
0097 struct descriptor {
0098 union {
0099 u32 raw;
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 struct desc_frame_ctrl {
0113 u32 buffer_size :16;
0114 u32 desc_count :6;
0115 u32 checksum :6;
0116 u32 authcomp :1;
0117 u32 perr :1;
0118 u32 derr :1;
0119 u32 own :1;
0120 } bits;
0121 } frame_ctrl;
0122
0123 union {
0124 u32 raw;
0125
0126
0127
0128
0129
0130 struct desc_tx_flag_status {
0131 u32 tqflag :10;
0132 u32 unused :22;
0133 } tx_flag;
0134 } flag_status;
0135
0136 u32 buf_adr;
0137
0138 union {
0139 u32 next_descriptor;
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 struct desc_next {
0150 u32 sof_eof :2;
0151 u32 dec :1;
0152 u32 eofie :1;
0153 u32 ndar :28;
0154 } bits;
0155 } next_desc;
0156 };
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173 struct pkt_control_header {
0174 u32 process_id :8;
0175 u32 auth_check_len :3;
0176 u32 un1 :1;
0177 u32 auth_algorithm :3;
0178 u32 auth_mode :1;
0179 u32 fcs_stream_copy :1;
0180 u32 un2 :2;
0181 u32 mix_key_sel :1;
0182 u32 aesnk :4;
0183 u32 cipher_algorithm :3;
0184 u32 un3 :1;
0185 u32 op_mode :4;
0186 };
0187
0188 struct pkt_control_cipher {
0189 u32 algorithm_len :16;
0190 u32 header_len :16;
0191 };
0192
0193
0194
0195
0196 struct pkt_control_ecb {
0197 struct pkt_control_header control;
0198 struct pkt_control_cipher cipher;
0199 unsigned char key[AES_MAX_KEY_SIZE];
0200 };
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230 struct sl3516_ce_dev {
0231 void __iomem *base;
0232 struct clk *clks;
0233 struct reset_control *reset;
0234 struct device *dev;
0235 struct crypto_engine *engine;
0236 struct completion complete;
0237 int status;
0238 dma_addr_t dtx;
0239 struct descriptor *tx;
0240 dma_addr_t drx;
0241 struct descriptor *rx;
0242 int ctx;
0243 int crx;
0244 struct hwrng trng;
0245 unsigned long hwrng_stat_req;
0246 unsigned long hwrng_stat_bytes;
0247 unsigned long stat_irq;
0248 unsigned long stat_irq_tx;
0249 unsigned long stat_irq_rx;
0250 unsigned long stat_req;
0251 unsigned long fallback_sg_count_tx;
0252 unsigned long fallback_sg_count_rx;
0253 unsigned long fallback_not_same_len;
0254 unsigned long fallback_mod16;
0255 unsigned long fallback_align16;
0256 #ifdef CONFIG_CRYPTO_DEV_SL3516_DEBUG
0257 struct dentry *dbgfs_dir;
0258 struct dentry *dbgfs_stats;
0259 #endif
0260 void *pctrl;
0261 dma_addr_t dctrl;
0262 };
0263
0264 struct sginfo {
0265 u32 addr;
0266 u32 len;
0267 };
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281 struct sl3516_ce_cipher_req_ctx {
0282 struct sginfo t_src[MAXDESC];
0283 struct sginfo t_dst[MAXDESC];
0284 u32 op_dir;
0285 unsigned int pctrllen;
0286 u32 tqflag;
0287 struct pkt_control_cipher *h;
0288 int nr_sgs;
0289 int nr_sgd;
0290 struct skcipher_request fallback_req;
0291 };
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303 struct sl3516_ce_cipher_tfm_ctx {
0304 struct crypto_engine_ctx enginectx;
0305 u32 *key;
0306 u32 keylen;
0307 struct sl3516_ce_dev *ce;
0308 struct crypto_skcipher *fallback_tfm;
0309 };
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322 struct sl3516_ce_alg_template {
0323 u32 type;
0324 u32 mode;
0325 struct sl3516_ce_dev *ce;
0326 union {
0327 struct skcipher_alg skcipher;
0328 } alg;
0329 unsigned long stat_req;
0330 unsigned long stat_fb;
0331 unsigned long stat_bytes;
0332 };
0333
0334 int sl3516_ce_enqueue(struct crypto_async_request *areq, u32 type);
0335
0336 int sl3516_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
0337 unsigned int keylen);
0338 int sl3516_ce_cipher_init(struct crypto_tfm *tfm);
0339 void sl3516_ce_cipher_exit(struct crypto_tfm *tfm);
0340 int sl3516_ce_skdecrypt(struct skcipher_request *areq);
0341 int sl3516_ce_skencrypt(struct skcipher_request *areq);
0342
0343 int sl3516_ce_run_task(struct sl3516_ce_dev *ce,
0344 struct sl3516_ce_cipher_req_ctx *rctx, const char *name);
0345
0346 int sl3516_ce_rng_register(struct sl3516_ce_dev *ce);
0347 void sl3516_ce_rng_unregister(struct sl3516_ce_dev *ce);