blob: 98730aab287c3d4443576d7089ad9b2f22d6c070 [file] [log] [blame]
Thomas Gleixner25763b32019-05-28 10:10:09 -07001// SPDX-License-Identifier: GPL-2.0-only
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08002/*
3 * Intel IXP4xx NPE-C crypto driver
4 *
5 * Copyright (C) 2008 Christian Hohnstaedt <chohnstaedt@innominate.com>
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08006 */
7
8#include <linux/platform_device.h>
9#include <linux/dma-mapping.h>
10#include <linux/dmapool.h>
11#include <linux/crypto.h>
12#include <linux/kernel.h>
13#include <linux/rtnetlink.h>
14#include <linux/interrupt.h>
15#include <linux/spinlock.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/gfp.h>
Michał Wróbel752587232012-04-05 20:34:21 +080017#include <linux/module.h>
Linus Walleij76f24b42021-05-25 10:50:56 +020018#include <linux/of.h>
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080019
20#include <crypto/ctr.h>
Ard Biesheuvel3ca20b62019-08-15 12:00:56 +030021#include <crypto/internal/des.h>
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080022#include <crypto/aes.h>
Corentin LABBEbb9634d2017-05-19 08:53:25 +020023#include <crypto/hmac.h>
Eric Biggersa24d22b2020-11-12 21:20:21 -080024#include <crypto/sha1.h>
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080025#include <crypto/algapi.h>
Herbert Xu5290b422015-05-11 17:47:44 +080026#include <crypto/internal/aead.h>
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +010027#include <crypto/internal/skcipher.h>
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080028#include <crypto/authenc.h>
29#include <crypto/scatterwalk.h>
30
Linus Walleij4af20dc2019-02-10 14:55:58 +010031#include <linux/soc/ixp4xx/npe.h>
32#include <linux/soc/ixp4xx/qmgr.h>
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080033
Arnd Bergmann09aa9aa2019-08-25 21:57:25 +020034/* Intermittent includes, delete this after v5.14-rc1 */
35#include <linux/soc/ixp4xx/cpu.h>
36#include <mach/ixp4xx-regs.h>
37
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080038#define MAX_KEYLEN 32
39
40/* hash: cfgword + 2 * digestlen; crypt: keylen + cfgword */
41#define NPE_CTX_LEN 80
42#define AES_BLOCK128 16
43
44#define NPE_OP_HASH_VERIFY 0x01
45#define NPE_OP_CCM_ENABLE 0x04
46#define NPE_OP_CRYPT_ENABLE 0x08
47#define NPE_OP_HASH_ENABLE 0x10
48#define NPE_OP_NOT_IN_PLACE 0x20
49#define NPE_OP_HMAC_DISABLE 0x40
50#define NPE_OP_CRYPT_ENCRYPT 0x80
51
52#define NPE_OP_CCM_GEN_MIC 0xcc
53#define NPE_OP_HASH_GEN_ICV 0x50
54#define NPE_OP_ENC_GEN_KEY 0xc9
55
56#define MOD_ECB 0x0000
57#define MOD_CTR 0x1000
58#define MOD_CBC_ENC 0x2000
59#define MOD_CBC_DEC 0x3000
60#define MOD_CCM_ENC 0x4000
61#define MOD_CCM_DEC 0x5000
62
63#define KEYLEN_128 4
64#define KEYLEN_192 6
65#define KEYLEN_256 8
66
67#define CIPH_DECR 0x0000
68#define CIPH_ENCR 0x0400
69
70#define MOD_DES 0x0000
71#define MOD_TDEA2 0x0100
72#define MOD_3DES 0x0200
73#define MOD_AES 0x0800
74#define MOD_AES128 (0x0800 | KEYLEN_128)
75#define MOD_AES192 (0x0900 | KEYLEN_192)
76#define MOD_AES256 (0x0a00 | KEYLEN_256)
77
78#define MAX_IVLEN 16
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080079#define NPE_QLEN 16
80/* Space for registering when the first
81 * NPE_QLEN crypt_ctl are busy */
82#define NPE_QLEN_TOTAL 64
83
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080084#define CTL_FLAG_UNUSED 0x0000
85#define CTL_FLAG_USED 0x1000
86#define CTL_FLAG_PERFORM_ABLK 0x0001
87#define CTL_FLAG_GEN_ICV 0x0002
88#define CTL_FLAG_GEN_REVAES 0x0004
89#define CTL_FLAG_PERFORM_AEAD 0x0008
90#define CTL_FLAG_MASK 0x000f
91
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080092#define HMAC_PAD_BLOCKLEN SHA1_BLOCK_SIZE
93
94#define MD5_DIGEST_SIZE 16
95
96struct buffer_desc {
97 u32 phys_next;
Krzysztof Hałasace057292010-01-10 14:20:10 +010098#ifdef __ARMEB__
Christian Hohnstaedt81bef012008-06-25 14:38:47 +080099 u16 buf_len;
100 u16 pkt_len;
Krzysztof Hałasace057292010-01-10 14:20:10 +0100101#else
102 u16 pkt_len;
103 u16 buf_len;
104#endif
Herbert Xuff455ad92019-05-23 14:35:30 +0800105 dma_addr_t phys_addr;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800106 u32 __reserved[4];
107 struct buffer_desc *next;
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800108 enum dma_data_direction dir;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800109};
110
111struct crypt_ctl {
Krzysztof Hałasace057292010-01-10 14:20:10 +0100112#ifdef __ARMEB__
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800113 u8 mode; /* NPE_OP_* operation mode */
114 u8 init_len;
115 u16 reserved;
Krzysztof Hałasace057292010-01-10 14:20:10 +0100116#else
117 u16 reserved;
118 u8 init_len;
119 u8 mode; /* NPE_OP_* operation mode */
120#endif
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800121 u8 iv[MAX_IVLEN]; /* IV for CBC mode or CTR IV for CTR mode */
Herbert Xuff455ad92019-05-23 14:35:30 +0800122 dma_addr_t icv_rev_aes; /* icv or rev aes */
123 dma_addr_t src_buf;
124 dma_addr_t dst_buf;
Krzysztof Hałasace057292010-01-10 14:20:10 +0100125#ifdef __ARMEB__
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800126 u16 auth_offs; /* Authentication start offset */
127 u16 auth_len; /* Authentication data length */
128 u16 crypt_offs; /* Cryption start offset */
129 u16 crypt_len; /* Cryption data length */
Krzysztof Hałasace057292010-01-10 14:20:10 +0100130#else
131 u16 auth_len; /* Authentication data length */
132 u16 auth_offs; /* Authentication start offset */
133 u16 crypt_len; /* Cryption data length */
134 u16 crypt_offs; /* Cryption start offset */
135#endif
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800136 u32 aadAddr; /* Additional Auth Data Addr for CCM mode */
137 u32 crypto_ctx; /* NPE Crypto Param structure address */
138
139 /* Used by Host: 4*4 bytes*/
Corentin Labbe35570842021-05-05 20:26:11 +0000140 unsigned int ctl_flags;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800141 union {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100142 struct skcipher_request *ablk_req;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800143 struct aead_request *aead_req;
144 struct crypto_tfm *tfm;
145 } data;
146 struct buffer_desc *regist_buf;
147 u8 *regist_ptr;
148};
149
150struct ablk_ctx {
151 struct buffer_desc *src;
152 struct buffer_desc *dst;
Corentin Labbee8acf012021-05-05 20:26:09 +0000153 u8 iv[MAX_IVLEN];
154 bool encrypt;
Corentin Labbedfb098d2021-05-05 20:26:10 +0000155 struct skcipher_request fallback_req; // keep at the end
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800156};
157
158struct aead_ctx {
Herbert Xud7295a82015-07-30 17:53:18 +0800159 struct buffer_desc *src;
160 struct buffer_desc *dst;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800161 struct scatterlist ivlist;
162 /* used when the hmac is not on one sg entry */
163 u8 *hmac_virt;
164 int encrypt;
165};
166
167struct ix_hash_algo {
168 u32 cfgword;
169 unsigned char *icv;
170};
171
172struct ix_sa_dir {
173 unsigned char *npe_ctx;
174 dma_addr_t npe_ctx_phys;
175 int npe_ctx_idx;
176 u8 npe_mode;
177};
178
179struct ixp_ctx {
180 struct ix_sa_dir encrypt;
181 struct ix_sa_dir decrypt;
182 int authkey_len;
183 u8 authkey[MAX_KEYLEN];
184 int enckey_len;
185 u8 enckey[MAX_KEYLEN];
186 u8 salt[MAX_IVLEN];
187 u8 nonce[CTR_RFC3686_NONCE_SIZE];
Corentin Labbe35570842021-05-05 20:26:11 +0000188 unsigned int salted;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800189 atomic_t configuring;
190 struct completion completion;
Corentin Labbedfb098d2021-05-05 20:26:10 +0000191 struct crypto_skcipher *fallback_tfm;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800192};
193
194struct ixp_alg {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100195 struct skcipher_alg crypto;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800196 const struct ix_hash_algo *hash;
197 u32 cfg_enc;
198 u32 cfg_dec;
199
200 int registered;
201};
202
Herbert Xud7295a82015-07-30 17:53:18 +0800203struct ixp_aead_alg {
204 struct aead_alg crypto;
205 const struct ix_hash_algo *hash;
206 u32 cfg_enc;
207 u32 cfg_dec;
208
209 int registered;
210};
211
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800212static const struct ix_hash_algo hash_alg_md5 = {
213 .cfgword = 0xAA010004,
214 .icv = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
215 "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
216};
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000217
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800218static const struct ix_hash_algo hash_alg_sha1 = {
219 .cfgword = 0x00000005,
220 .icv = "\x67\x45\x23\x01\xEF\xCD\xAB\x89\x98\xBA"
221 "\xDC\xFE\x10\x32\x54\x76\xC3\xD2\xE1\xF0",
222};
223
224static struct npe *npe_c;
Linus Walleij76f24b42021-05-25 10:50:56 +0200225
226static unsigned int send_qid;
227static unsigned int recv_qid;
Corentin Labbe87d11a52021-05-05 20:26:14 +0000228static struct dma_pool *buffer_pool;
229static struct dma_pool *ctx_pool;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800230
Corentin Labbe87d11a52021-05-05 20:26:14 +0000231static struct crypt_ctl *crypt_virt;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800232static dma_addr_t crypt_phys;
233
234static int support_aes = 1;
235
Russell Kingd8cbc3f2013-06-10 18:52:52 +0100236static struct platform_device *pdev;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800237
238static inline dma_addr_t crypt_virt2phys(struct crypt_ctl *virt)
239{
240 return crypt_phys + (virt - crypt_virt) * sizeof(struct crypt_ctl);
241}
242
243static inline struct crypt_ctl *crypt_phys2virt(dma_addr_t phys)
244{
245 return crypt_virt + (phys - crypt_phys) / sizeof(struct crypt_ctl);
246}
247
248static inline u32 cipher_cfg_enc(struct crypto_tfm *tfm)
249{
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000250 return container_of(tfm->__crt_alg, struct ixp_alg, crypto.base)->cfg_enc;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800251}
252
253static inline u32 cipher_cfg_dec(struct crypto_tfm *tfm)
254{
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000255 return container_of(tfm->__crt_alg, struct ixp_alg, crypto.base)->cfg_dec;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800256}
257
258static inline const struct ix_hash_algo *ix_hash(struct crypto_tfm *tfm)
259{
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100260 return container_of(tfm->__crt_alg, struct ixp_alg, crypto.base)->hash;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800261}
262
263static int setup_crypt_desc(void)
264{
Russell King27c17892013-06-10 19:09:45 +0100265 struct device *dev = &pdev->dev;
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000266
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800267 BUILD_BUG_ON(sizeof(struct crypt_ctl) != 64);
Luis Chamberlain750afb02019-01-04 09:23:09 +0100268 crypt_virt = dma_alloc_coherent(dev,
269 NPE_QLEN * sizeof(struct crypt_ctl),
270 &crypt_phys, GFP_ATOMIC);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800271 if (!crypt_virt)
272 return -ENOMEM;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800273 return 0;
274}
275
Guobin Huang7dad7d02021-04-06 20:02:57 +0800276static DEFINE_SPINLOCK(desc_lock);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800277static struct crypt_ctl *get_crypt_desc(void)
278{
279 int i;
Corentin Labbe87d11a52021-05-05 20:26:14 +0000280 static int idx;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800281 unsigned long flags;
282
283 spin_lock_irqsave(&desc_lock, flags);
284
285 if (unlikely(!crypt_virt))
286 setup_crypt_desc();
287 if (unlikely(!crypt_virt)) {
288 spin_unlock_irqrestore(&desc_lock, flags);
289 return NULL;
290 }
291 i = idx;
292 if (crypt_virt[i].ctl_flags == CTL_FLAG_UNUSED) {
293 if (++idx >= NPE_QLEN)
294 idx = 0;
295 crypt_virt[i].ctl_flags = CTL_FLAG_USED;
296 spin_unlock_irqrestore(&desc_lock, flags);
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000297 return crypt_virt + i;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800298 } else {
299 spin_unlock_irqrestore(&desc_lock, flags);
300 return NULL;
301 }
302}
303
Guobin Huang7dad7d02021-04-06 20:02:57 +0800304static DEFINE_SPINLOCK(emerg_lock);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800305static struct crypt_ctl *get_crypt_desc_emerg(void)
306{
307 int i;
308 static int idx = NPE_QLEN;
309 struct crypt_ctl *desc;
310 unsigned long flags;
311
312 desc = get_crypt_desc();
313 if (desc)
314 return desc;
315 if (unlikely(!crypt_virt))
316 return NULL;
317
318 spin_lock_irqsave(&emerg_lock, flags);
319 i = idx;
320 if (crypt_virt[i].ctl_flags == CTL_FLAG_UNUSED) {
321 if (++idx >= NPE_QLEN_TOTAL)
322 idx = NPE_QLEN;
323 crypt_virt[i].ctl_flags = CTL_FLAG_USED;
324 spin_unlock_irqrestore(&emerg_lock, flags);
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000325 return crypt_virt + i;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800326 } else {
327 spin_unlock_irqrestore(&emerg_lock, flags);
328 return NULL;
329 }
330}
331
Herbert Xuff455ad92019-05-23 14:35:30 +0800332static void free_buf_chain(struct device *dev, struct buffer_desc *buf,
333 dma_addr_t phys)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800334{
335 while (buf) {
336 struct buffer_desc *buf1;
337 u32 phys1;
338
339 buf1 = buf->next;
340 phys1 = buf->phys_next;
Corentin Labbe9395c582021-05-05 20:26:08 +0000341 dma_unmap_single(dev, buf->phys_addr, buf->buf_len, buf->dir);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800342 dma_pool_free(buffer_pool, buf, phys);
343 buf = buf1;
344 phys = phys1;
345 }
346}
347
348static struct tasklet_struct crypto_done_tasklet;
349
350static void finish_scattered_hmac(struct crypt_ctl *crypt)
351{
352 struct aead_request *req = crypt->data.aead_req;
353 struct aead_ctx *req_ctx = aead_request_ctx(req);
354 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
355 int authsize = crypto_aead_authsize(tfm);
Herbert Xud7295a82015-07-30 17:53:18 +0800356 int decryptlen = req->assoclen + req->cryptlen - authsize;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800357
358 if (req_ctx->encrypt) {
Corentin Labbec5e07032021-05-05 20:26:16 +0000359 scatterwalk_map_and_copy(req_ctx->hmac_virt, req->dst,
360 decryptlen, authsize, 1);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800361 }
362 dma_pool_free(buffer_pool, req_ctx->hmac_virt, crypt->icv_rev_aes);
363}
364
365static void one_packet(dma_addr_t phys)
366{
Russell King27c17892013-06-10 19:09:45 +0100367 struct device *dev = &pdev->dev;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800368 struct crypt_ctl *crypt;
369 struct ixp_ctx *ctx;
370 int failed;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800371
372 failed = phys & 0x1 ? -EBADMSG : 0;
373 phys &= ~0x3;
374 crypt = crypt_phys2virt(phys);
375
376 switch (crypt->ctl_flags & CTL_FLAG_MASK) {
377 case CTL_FLAG_PERFORM_AEAD: {
378 struct aead_request *req = crypt->data.aead_req;
379 struct aead_ctx *req_ctx = aead_request_ctx(req);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800380
Herbert Xud7295a82015-07-30 17:53:18 +0800381 free_buf_chain(dev, req_ctx->src, crypt->src_buf);
382 free_buf_chain(dev, req_ctx->dst, crypt->dst_buf);
Corentin Labbeffb017e2021-05-05 20:26:15 +0000383 if (req_ctx->hmac_virt)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800384 finish_scattered_hmac(crypt);
Corentin Labbeffb017e2021-05-05 20:26:15 +0000385
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800386 req->base.complete(&req->base, failed);
387 break;
388 }
389 case CTL_FLAG_PERFORM_ABLK: {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100390 struct skcipher_request *req = crypt->data.ablk_req;
391 struct ablk_ctx *req_ctx = skcipher_request_ctx(req);
Corentin Labbee8acf012021-05-05 20:26:09 +0000392 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
393 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
394 unsigned int offset;
395
396 if (ivsize > 0) {
397 offset = req->cryptlen - ivsize;
398 if (req_ctx->encrypt) {
399 scatterwalk_map_and_copy(req->iv, req->dst,
400 offset, ivsize, 0);
401 } else {
402 memcpy(req->iv, req_ctx->iv, ivsize);
403 memzero_explicit(req_ctx->iv, ivsize);
404 }
405 }
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800406
Corentin Labbeffb017e2021-05-05 20:26:15 +0000407 if (req_ctx->dst)
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800408 free_buf_chain(dev, req_ctx->dst, crypt->dst_buf);
Corentin Labbeffb017e2021-05-05 20:26:15 +0000409
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800410 free_buf_chain(dev, req_ctx->src, crypt->src_buf);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800411 req->base.complete(&req->base, failed);
412 break;
413 }
414 case CTL_FLAG_GEN_ICV:
415 ctx = crypto_tfm_ctx(crypt->data.tfm);
416 dma_pool_free(ctx_pool, crypt->regist_ptr,
Corentin Labbec5e07032021-05-05 20:26:16 +0000417 crypt->regist_buf->phys_addr);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800418 dma_pool_free(buffer_pool, crypt->regist_buf, crypt->src_buf);
419 if (atomic_dec_and_test(&ctx->configuring))
420 complete(&ctx->completion);
421 break;
422 case CTL_FLAG_GEN_REVAES:
423 ctx = crypto_tfm_ctx(crypt->data.tfm);
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000424 *(u32 *)ctx->decrypt.npe_ctx &= cpu_to_be32(~CIPH_ENCR);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800425 if (atomic_dec_and_test(&ctx->configuring))
426 complete(&ctx->completion);
427 break;
428 default:
429 BUG();
430 }
431 crypt->ctl_flags = CTL_FLAG_UNUSED;
432}
433
434static void irqhandler(void *_unused)
435{
436 tasklet_schedule(&crypto_done_tasklet);
437}
438
439static void crypto_done_action(unsigned long arg)
440{
441 int i;
442
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000443 for (i = 0; i < 4; i++) {
Linus Walleij76f24b42021-05-25 10:50:56 +0200444 dma_addr_t phys = qmgr_get_entry(recv_qid);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800445 if (!phys)
446 return;
447 one_packet(phys);
448 }
449 tasklet_schedule(&crypto_done_tasklet);
450}
451
Russell King27c17892013-06-10 19:09:45 +0100452static int init_ixp_crypto(struct device *dev)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800453{
Linus Walleij76f24b42021-05-25 10:50:56 +0200454 struct device_node *np = dev->of_node;
Christian Hohnstaedt295c01f2009-04-12 13:01:44 +0800455 u32 msg[2] = { 0, 0 };
Linus Walleij76f24b42021-05-25 10:50:56 +0200456 int ret = -ENODEV;
457 u32 npe_id;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800458
Linus Walleij76f24b42021-05-25 10:50:56 +0200459 dev_info(dev, "probing...\n");
460
461 /* Locate the NPE and queue manager to use from device tree */
462 if (IS_ENABLED(CONFIG_OF) && np) {
463 struct of_phandle_args queue_spec;
464 struct of_phandle_args npe_spec;
465
466 ret = of_parse_phandle_with_fixed_args(np, "intel,npe-handle",
467 1, 0, &npe_spec);
468 if (ret) {
469 dev_err(dev, "no NPE engine specified\n");
470 return -ENODEV;
471 }
472 npe_id = npe_spec.args[0];
473
474 ret = of_parse_phandle_with_fixed_args(np, "queue-rx", 1, 0,
475 &queue_spec);
476 if (ret) {
477 dev_err(dev, "no rx queue phandle\n");
478 return -ENODEV;
479 }
480 recv_qid = queue_spec.args[0];
481
482 ret = of_parse_phandle_with_fixed_args(np, "queue-txready", 1, 0,
483 &queue_spec);
484 if (ret) {
485 dev_err(dev, "no txready queue phandle\n");
486 return -ENODEV;
487 }
488 send_qid = queue_spec.args[0];
489 } else {
490 /*
491 * Hardcoded engine when using platform data, this goes away
492 * when we switch to using DT only.
493 */
494 npe_id = 2;
495 send_qid = 29;
496 recv_qid = 30;
497 }
498
499 npe_c = npe_request(npe_id);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800500 if (!npe_c)
501 return ret;
502
503 if (!npe_running(npe_c)) {
Christian Hohnstaedt295c01f2009-04-12 13:01:44 +0800504 ret = npe_load_firmware(npe_c, npe_name(npe_c), dev);
Quentin Lambertb3637002016-07-22 15:32:42 +0200505 if (ret)
Quentin Lambertc5736a42016-07-22 15:32:41 +0200506 goto npe_release;
Christian Hohnstaedt295c01f2009-04-12 13:01:44 +0800507 if (npe_recv_message(npe_c, msg, "STATUS_MSG"))
508 goto npe_error;
509 } else {
510 if (npe_send_message(npe_c, msg, "STATUS_MSG"))
511 goto npe_error;
512
513 if (npe_recv_message(npe_c, msg, "STATUS_MSG"))
514 goto npe_error;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800515 }
516
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000517 switch ((msg[1] >> 16) & 0xff) {
Christian Hohnstaedt295c01f2009-04-12 13:01:44 +0800518 case 3:
Corentin Labbef5b82be2021-05-05 20:26:12 +0000519 dev_warn(dev, "Firmware of %s lacks AES support\n", npe_name(npe_c));
Christian Hohnstaedt295c01f2009-04-12 13:01:44 +0800520 support_aes = 0;
521 break;
522 case 4:
523 case 5:
524 support_aes = 1;
525 break;
526 default:
Corentin Labbef5b82be2021-05-05 20:26:12 +0000527 dev_err(dev, "Firmware of %s lacks crypto support\n", npe_name(npe_c));
Quentin Lambertc5736a42016-07-22 15:32:41 +0200528 ret = -ENODEV;
529 goto npe_release;
Christian Hohnstaedt295c01f2009-04-12 13:01:44 +0800530 }
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800531 /* buffer_pool will also be used to sometimes store the hmac,
532 * so assure it is large enough
533 */
534 BUILD_BUG_ON(SHA1_DIGEST_SIZE > sizeof(struct buffer_desc));
Corentin Labbec5e07032021-05-05 20:26:16 +0000535 buffer_pool = dma_pool_create("buffer", dev, sizeof(struct buffer_desc),
536 32, 0);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800537 ret = -ENOMEM;
Corentin Labbeffb017e2021-05-05 20:26:15 +0000538 if (!buffer_pool)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800539 goto err;
Corentin Labbeffb017e2021-05-05 20:26:15 +0000540
Corentin Labbec5e07032021-05-05 20:26:16 +0000541 ctx_pool = dma_pool_create("context", dev, NPE_CTX_LEN, 16, 0);
Corentin Labbeffb017e2021-05-05 20:26:15 +0000542 if (!ctx_pool)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800543 goto err;
Corentin Labbeffb017e2021-05-05 20:26:15 +0000544
Linus Walleij76f24b42021-05-25 10:50:56 +0200545 ret = qmgr_request_queue(send_qid, NPE_QLEN_TOTAL, 0, 0,
Krzysztof Hałasa1777f1a2009-03-04 08:01:22 +0800546 "ixp_crypto:out", NULL);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800547 if (ret)
548 goto err;
Linus Walleij76f24b42021-05-25 10:50:56 +0200549 ret = qmgr_request_queue(recv_qid, NPE_QLEN, 0, 0,
Krzysztof Hałasa1777f1a2009-03-04 08:01:22 +0800550 "ixp_crypto:in", NULL);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800551 if (ret) {
Linus Walleij76f24b42021-05-25 10:50:56 +0200552 qmgr_release_queue(send_qid);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800553 goto err;
554 }
Linus Walleij76f24b42021-05-25 10:50:56 +0200555 qmgr_set_irq(recv_qid, QUEUE_IRQ_SRC_NOT_EMPTY, irqhandler, NULL);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800556 tasklet_init(&crypto_done_tasklet, crypto_done_action, 0);
557
Linus Walleij76f24b42021-05-25 10:50:56 +0200558 qmgr_enable_irq(recv_qid);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800559 return 0;
Christian Hohnstaedt295c01f2009-04-12 13:01:44 +0800560
561npe_error:
Corentin Labbef5b82be2021-05-05 20:26:12 +0000562 dev_err(dev, "%s not responding\n", npe_name(npe_c));
Christian Hohnstaedt295c01f2009-04-12 13:01:44 +0800563 ret = -EIO;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800564err:
Markus Elfringf9d12932015-11-15 16:51:21 +0100565 dma_pool_destroy(ctx_pool);
566 dma_pool_destroy(buffer_pool);
Quentin Lambertc5736a42016-07-22 15:32:41 +0200567npe_release:
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800568 npe_release(npe_c);
569 return ret;
570}
571
Russell King27c17892013-06-10 19:09:45 +0100572static void release_ixp_crypto(struct device *dev)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800573{
Linus Walleij76f24b42021-05-25 10:50:56 +0200574 qmgr_disable_irq(recv_qid);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800575 tasklet_kill(&crypto_done_tasklet);
576
Linus Walleij76f24b42021-05-25 10:50:56 +0200577 qmgr_release_queue(send_qid);
578 qmgr_release_queue(recv_qid);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800579
580 dma_pool_destroy(ctx_pool);
581 dma_pool_destroy(buffer_pool);
582
583 npe_release(npe_c);
584
Corentin Labbeffb017e2021-05-05 20:26:15 +0000585 if (crypt_virt)
Corentin Labbec5e07032021-05-05 20:26:16 +0000586 dma_free_coherent(dev, NPE_QLEN * sizeof(struct crypt_ctl),
587 crypt_virt, crypt_phys);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800588}
589
590static void reset_sa_dir(struct ix_sa_dir *dir)
591{
592 memset(dir->npe_ctx, 0, NPE_CTX_LEN);
593 dir->npe_ctx_idx = 0;
594 dir->npe_mode = 0;
595}
596
597static int init_sa_dir(struct ix_sa_dir *dir)
598{
599 dir->npe_ctx = dma_pool_alloc(ctx_pool, GFP_KERNEL, &dir->npe_ctx_phys);
Corentin Labbeffb017e2021-05-05 20:26:15 +0000600 if (!dir->npe_ctx)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800601 return -ENOMEM;
Corentin Labbeffb017e2021-05-05 20:26:15 +0000602
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800603 reset_sa_dir(dir);
604 return 0;
605}
606
607static void free_sa_dir(struct ix_sa_dir *dir)
608{
609 memset(dir->npe_ctx, 0, NPE_CTX_LEN);
610 dma_pool_free(ctx_pool, dir->npe_ctx, dir->npe_ctx_phys);
611}
612
613static int init_tfm(struct crypto_tfm *tfm)
614{
615 struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
616 int ret;
617
618 atomic_set(&ctx->configuring, 0);
619 ret = init_sa_dir(&ctx->encrypt);
620 if (ret)
621 return ret;
622 ret = init_sa_dir(&ctx->decrypt);
Corentin Labbeffb017e2021-05-05 20:26:15 +0000623 if (ret)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800624 free_sa_dir(&ctx->encrypt);
Corentin Labbeffb017e2021-05-05 20:26:15 +0000625
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800626 return ret;
627}
628
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100629static int init_tfm_ablk(struct crypto_skcipher *tfm)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800630{
Corentin Labbedfb098d2021-05-05 20:26:10 +0000631 struct crypto_tfm *ctfm = crypto_skcipher_tfm(tfm);
632 struct ixp_ctx *ctx = crypto_tfm_ctx(ctfm);
633 const char *name = crypto_tfm_alg_name(ctfm);
634
635 ctx->fallback_tfm = crypto_alloc_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK);
636 if (IS_ERR(ctx->fallback_tfm)) {
637 pr_err("ERROR: Cannot allocate fallback for %s %ld\n",
638 name, PTR_ERR(ctx->fallback_tfm));
639 return PTR_ERR(ctx->fallback_tfm);
640 }
641
642 pr_info("Fallback for %s is %s\n",
643 crypto_tfm_alg_driver_name(&tfm->base),
644 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(ctx->fallback_tfm))
645 );
646
647 crypto_skcipher_set_reqsize(tfm, sizeof(struct ablk_ctx) + crypto_skcipher_reqsize(ctx->fallback_tfm));
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100648 return init_tfm(crypto_skcipher_tfm(tfm));
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800649}
650
Herbert Xud7295a82015-07-30 17:53:18 +0800651static int init_tfm_aead(struct crypto_aead *tfm)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800652{
Herbert Xud7295a82015-07-30 17:53:18 +0800653 crypto_aead_set_reqsize(tfm, sizeof(struct aead_ctx));
654 return init_tfm(crypto_aead_tfm(tfm));
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800655}
656
657static void exit_tfm(struct crypto_tfm *tfm)
658{
659 struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000660
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800661 free_sa_dir(&ctx->encrypt);
662 free_sa_dir(&ctx->decrypt);
663}
664
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100665static void exit_tfm_ablk(struct crypto_skcipher *tfm)
666{
Corentin Labbedfb098d2021-05-05 20:26:10 +0000667 struct crypto_tfm *ctfm = crypto_skcipher_tfm(tfm);
668 struct ixp_ctx *ctx = crypto_tfm_ctx(ctfm);
669
670 crypto_free_skcipher(ctx->fallback_tfm);
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100671 exit_tfm(crypto_skcipher_tfm(tfm));
672}
673
Herbert Xud7295a82015-07-30 17:53:18 +0800674static void exit_tfm_aead(struct crypto_aead *tfm)
675{
676 exit_tfm(crypto_aead_tfm(tfm));
677}
678
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800679static int register_chain_var(struct crypto_tfm *tfm, u8 xpad, u32 target,
Corentin Labbec5e07032021-05-05 20:26:16 +0000680 int init_len, u32 ctx_addr, const u8 *key,
681 int key_len)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800682{
683 struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
684 struct crypt_ctl *crypt;
685 struct buffer_desc *buf;
686 int i;
687 u8 *pad;
Herbert Xuff455ad92019-05-23 14:35:30 +0800688 dma_addr_t pad_phys, buf_phys;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800689
690 BUILD_BUG_ON(NPE_CTX_LEN < HMAC_PAD_BLOCKLEN);
691 pad = dma_pool_alloc(ctx_pool, GFP_KERNEL, &pad_phys);
692 if (!pad)
693 return -ENOMEM;
694 buf = dma_pool_alloc(buffer_pool, GFP_KERNEL, &buf_phys);
695 if (!buf) {
696 dma_pool_free(ctx_pool, pad, pad_phys);
697 return -ENOMEM;
698 }
699 crypt = get_crypt_desc_emerg();
700 if (!crypt) {
701 dma_pool_free(ctx_pool, pad, pad_phys);
702 dma_pool_free(buffer_pool, buf, buf_phys);
703 return -EAGAIN;
704 }
705
706 memcpy(pad, key, key_len);
707 memset(pad + key_len, 0, HMAC_PAD_BLOCKLEN - key_len);
Corentin Labbeffb017e2021-05-05 20:26:15 +0000708 for (i = 0; i < HMAC_PAD_BLOCKLEN; i++)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800709 pad[i] ^= xpad;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800710
711 crypt->data.tfm = tfm;
712 crypt->regist_ptr = pad;
713 crypt->regist_buf = buf;
714
715 crypt->auth_offs = 0;
716 crypt->auth_len = HMAC_PAD_BLOCKLEN;
717 crypt->crypto_ctx = ctx_addr;
718 crypt->src_buf = buf_phys;
719 crypt->icv_rev_aes = target;
720 crypt->mode = NPE_OP_HASH_GEN_ICV;
721 crypt->init_len = init_len;
722 crypt->ctl_flags |= CTL_FLAG_GEN_ICV;
723
724 buf->next = 0;
725 buf->buf_len = HMAC_PAD_BLOCKLEN;
726 buf->pkt_len = 0;
727 buf->phys_addr = pad_phys;
728
729 atomic_inc(&ctx->configuring);
Linus Walleij76f24b42021-05-25 10:50:56 +0200730 qmgr_put_entry(send_qid, crypt_virt2phys(crypt));
731 BUG_ON(qmgr_stat_overflow(send_qid));
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800732 return 0;
733}
734
Corentin Labbe35570842021-05-05 20:26:11 +0000735static int setup_auth(struct crypto_tfm *tfm, int encrypt, unsigned int authsize,
736 const u8 *key, int key_len, unsigned int digest_len)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800737{
738 u32 itarget, otarget, npe_ctx_addr;
739 unsigned char *cinfo;
740 int init_len, ret = 0;
741 u32 cfgword;
742 struct ix_sa_dir *dir;
743 struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
744 const struct ix_hash_algo *algo;
745
746 dir = encrypt ? &ctx->encrypt : &ctx->decrypt;
747 cinfo = dir->npe_ctx + dir->npe_ctx_idx;
748 algo = ix_hash(tfm);
749
750 /* write cfg word to cryptinfo */
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000751 cfgword = algo->cfgword | (authsize << 6); /* (authsize/4) << 8 */
Krzysztof Hałasace057292010-01-10 14:20:10 +0100752#ifndef __ARMEB__
753 cfgword ^= 0xAA000000; /* change the "byte swap" flags */
754#endif
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000755 *(u32 *)cinfo = cpu_to_be32(cfgword);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800756 cinfo += sizeof(cfgword);
757
758 /* write ICV to cryptinfo */
759 memcpy(cinfo, algo->icv, digest_len);
760 cinfo += digest_len;
761
762 itarget = dir->npe_ctx_phys + dir->npe_ctx_idx
763 + sizeof(algo->cfgword);
764 otarget = itarget + digest_len;
765 init_len = cinfo - (dir->npe_ctx + dir->npe_ctx_idx);
766 npe_ctx_addr = dir->npe_ctx_phys + dir->npe_ctx_idx;
767
768 dir->npe_ctx_idx += init_len;
769 dir->npe_mode |= NPE_OP_HASH_ENABLE;
770
771 if (!encrypt)
772 dir->npe_mode |= NPE_OP_HASH_VERIFY;
773
774 ret = register_chain_var(tfm, HMAC_OPAD_VALUE, otarget,
Corentin Labbec5e07032021-05-05 20:26:16 +0000775 init_len, npe_ctx_addr, key, key_len);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800776 if (ret)
777 return ret;
778 return register_chain_var(tfm, HMAC_IPAD_VALUE, itarget,
Corentin Labbec5e07032021-05-05 20:26:16 +0000779 init_len, npe_ctx_addr, key, key_len);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800780}
781
782static int gen_rev_aes_key(struct crypto_tfm *tfm)
783{
784 struct crypt_ctl *crypt;
785 struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
786 struct ix_sa_dir *dir = &ctx->decrypt;
787
788 crypt = get_crypt_desc_emerg();
Corentin Labbeffb017e2021-05-05 20:26:15 +0000789 if (!crypt)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800790 return -EAGAIN;
Corentin Labbeffb017e2021-05-05 20:26:15 +0000791
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000792 *(u32 *)dir->npe_ctx |= cpu_to_be32(CIPH_ENCR);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800793
794 crypt->data.tfm = tfm;
795 crypt->crypt_offs = 0;
796 crypt->crypt_len = AES_BLOCK128;
797 crypt->src_buf = 0;
798 crypt->crypto_ctx = dir->npe_ctx_phys;
799 crypt->icv_rev_aes = dir->npe_ctx_phys + sizeof(u32);
800 crypt->mode = NPE_OP_ENC_GEN_KEY;
801 crypt->init_len = dir->npe_ctx_idx;
802 crypt->ctl_flags |= CTL_FLAG_GEN_REVAES;
803
804 atomic_inc(&ctx->configuring);
Linus Walleij76f24b42021-05-25 10:50:56 +0200805 qmgr_put_entry(send_qid, crypt_virt2phys(crypt));
806 BUG_ON(qmgr_stat_overflow(send_qid));
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800807 return 0;
808}
809
Corentin Labbec5e07032021-05-05 20:26:16 +0000810static int setup_cipher(struct crypto_tfm *tfm, int encrypt, const u8 *key,
811 int key_len)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800812{
813 u8 *cinfo;
814 u32 cipher_cfg;
815 u32 keylen_cfg = 0;
816 struct ix_sa_dir *dir;
817 struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
Eric Biggersc4c4db02019-12-30 21:19:37 -0600818 int err;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800819
820 dir = encrypt ? &ctx->encrypt : &ctx->decrypt;
821 cinfo = dir->npe_ctx;
822
823 if (encrypt) {
824 cipher_cfg = cipher_cfg_enc(tfm);
825 dir->npe_mode |= NPE_OP_CRYPT_ENCRYPT;
826 } else {
827 cipher_cfg = cipher_cfg_dec(tfm);
828 }
829 if (cipher_cfg & MOD_AES) {
830 switch (key_len) {
Corentin Labbec5e07032021-05-05 20:26:16 +0000831 case 16:
832 keylen_cfg = MOD_AES128;
833 break;
834 case 24:
835 keylen_cfg = MOD_AES192;
836 break;
837 case 32:
838 keylen_cfg = MOD_AES256;
839 break;
Krzysztof Hałasa9792eb12010-12-28 13:08:18 +0100840 default:
Krzysztof Hałasa9792eb12010-12-28 13:08:18 +0100841 return -EINVAL;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800842 }
843 cipher_cfg |= keylen_cfg;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800844 } else {
Eric Biggersc4c4db02019-12-30 21:19:37 -0600845 err = crypto_des_verify_key(tfm, key);
846 if (err)
847 return err;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800848 }
849 /* write cfg word to cryptinfo */
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000850 *(u32 *)cinfo = cpu_to_be32(cipher_cfg);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800851 cinfo += sizeof(cipher_cfg);
852
853 /* write cipher key to cryptinfo */
854 memcpy(cinfo, key, key_len);
855 /* NPE wants keylen set to DES3_EDE_KEY_SIZE even for single DES */
856 if (key_len < DES3_EDE_KEY_SIZE && !(cipher_cfg & MOD_AES)) {
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000857 memset(cinfo + key_len, 0, DES3_EDE_KEY_SIZE - key_len);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800858 key_len = DES3_EDE_KEY_SIZE;
859 }
860 dir->npe_ctx_idx = sizeof(cipher_cfg) + key_len;
861 dir->npe_mode |= NPE_OP_CRYPT_ENABLE;
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000862 if ((cipher_cfg & MOD_AES) && !encrypt)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800863 return gen_rev_aes_key(tfm);
Corentin Labbe39e39cf2021-05-05 20:26:13 +0000864
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800865 return 0;
866}
867
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800868static struct buffer_desc *chainup_buffers(struct device *dev,
Corentin Labbe35570842021-05-05 20:26:11 +0000869 struct scatterlist *sg, unsigned int nbytes,
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800870 struct buffer_desc *buf, gfp_t flags,
871 enum dma_data_direction dir)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800872{
Cristian Stoica5be4d4c2015-01-20 10:06:16 +0200873 for (; nbytes > 0; sg = sg_next(sg)) {
Corentin Labbe35570842021-05-05 20:26:11 +0000874 unsigned int len = min(nbytes, sg->length);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800875 struct buffer_desc *next_buf;
Herbert Xuff455ad92019-05-23 14:35:30 +0800876 dma_addr_t next_buf_phys;
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800877 void *ptr;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800878
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800879 nbytes -= len;
Geliang Tang796b40c2017-03-23 21:16:30 +0800880 ptr = sg_virt(sg);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800881 next_buf = dma_pool_alloc(buffer_pool, flags, &next_buf_phys);
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800882 if (!next_buf) {
883 buf = NULL;
884 break;
885 }
886 sg_dma_address(sg) = dma_map_single(dev, ptr, len, dir);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800887 buf->next = next_buf;
888 buf->phys_next = next_buf_phys;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800889 buf = next_buf;
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800890
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800891 buf->phys_addr = sg_dma_address(sg);
892 buf->buf_len = len;
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800893 buf->dir = dir;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800894 }
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800895 buf->next = NULL;
896 buf->phys_next = 0;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800897 return buf;
898}
899
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100900static int ablk_setkey(struct crypto_skcipher *tfm, const u8 *key,
Corentin Labbec5e07032021-05-05 20:26:16 +0000901 unsigned int key_len)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800902{
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100903 struct ixp_ctx *ctx = crypto_skcipher_ctx(tfm);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800904 int ret;
905
906 init_completion(&ctx->completion);
907 atomic_inc(&ctx->configuring);
908
909 reset_sa_dir(&ctx->encrypt);
910 reset_sa_dir(&ctx->decrypt);
911
912 ctx->encrypt.npe_mode = NPE_OP_HMAC_DISABLE;
913 ctx->decrypt.npe_mode = NPE_OP_HMAC_DISABLE;
914
915 ret = setup_cipher(&tfm->base, 0, key, key_len);
916 if (ret)
917 goto out;
918 ret = setup_cipher(&tfm->base, 1, key, key_len);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800919out:
920 if (!atomic_dec_and_test(&ctx->configuring))
921 wait_for_completion(&ctx->completion);
Corentin Labbedfb098d2021-05-05 20:26:10 +0000922 if (ret)
923 return ret;
924 crypto_skcipher_clear_flags(ctx->fallback_tfm, CRYPTO_TFM_REQ_MASK);
925 crypto_skcipher_set_flags(ctx->fallback_tfm, tfm->base.crt_flags & CRYPTO_TFM_REQ_MASK);
926
927 return crypto_skcipher_setkey(ctx->fallback_tfm, key, key_len);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800928}
929
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100930static int ablk_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
Herbert Xudba434a2019-04-11 16:51:11 +0800931 unsigned int key_len)
932{
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100933 return verify_skcipher_des3_key(tfm, key) ?:
Ard Biesheuvel3ca20b62019-08-15 12:00:56 +0300934 ablk_setkey(tfm, key, key_len);
Herbert Xudba434a2019-04-11 16:51:11 +0800935}
936
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100937static int ablk_rfc3686_setkey(struct crypto_skcipher *tfm, const u8 *key,
Corentin Labbec5e07032021-05-05 20:26:16 +0000938 unsigned int key_len)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800939{
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100940 struct ixp_ctx *ctx = crypto_skcipher_ctx(tfm);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800941
942 /* the nonce is stored in bytes at end of key */
943 if (key_len < CTR_RFC3686_NONCE_SIZE)
944 return -EINVAL;
945
946 memcpy(ctx->nonce, key + (key_len - CTR_RFC3686_NONCE_SIZE),
Corentin Labbec5e07032021-05-05 20:26:16 +0000947 CTR_RFC3686_NONCE_SIZE);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800948
949 key_len -= CTR_RFC3686_NONCE_SIZE;
950 return ablk_setkey(tfm, key, key_len);
951}
952
Corentin Labbedfb098d2021-05-05 20:26:10 +0000953static int ixp4xx_cipher_fallback(struct skcipher_request *areq, int encrypt)
954{
955 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
956 struct ixp_ctx *op = crypto_skcipher_ctx(tfm);
957 struct ablk_ctx *rctx = skcipher_request_ctx(areq);
958 int err;
959
960 skcipher_request_set_tfm(&rctx->fallback_req, op->fallback_tfm);
961 skcipher_request_set_callback(&rctx->fallback_req, areq->base.flags,
962 areq->base.complete, areq->base.data);
963 skcipher_request_set_crypt(&rctx->fallback_req, areq->src, areq->dst,
964 areq->cryptlen, areq->iv);
965 if (encrypt)
966 err = crypto_skcipher_encrypt(&rctx->fallback_req);
967 else
968 err = crypto_skcipher_decrypt(&rctx->fallback_req);
969 return err;
970}
971
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100972static int ablk_perform(struct skcipher_request *req, int encrypt)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800973{
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100974 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
975 struct ixp_ctx *ctx = crypto_skcipher_ctx(tfm);
Corentin Labbe35570842021-05-05 20:26:11 +0000976 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800977 struct ix_sa_dir *dir;
978 struct crypt_ctl *crypt;
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100979 unsigned int nbytes = req->cryptlen;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800980 enum dma_data_direction src_direction = DMA_BIDIRECTIONAL;
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +0100981 struct ablk_ctx *req_ctx = skcipher_request_ctx(req);
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +0800982 struct buffer_desc src_hook;
Russell King27c17892013-06-10 19:09:45 +0100983 struct device *dev = &pdev->dev;
Corentin Labbee8acf012021-05-05 20:26:09 +0000984 unsigned int offset;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800985 gfp_t flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
986 GFP_KERNEL : GFP_ATOMIC;
987
Corentin Labbedfb098d2021-05-05 20:26:10 +0000988 if (sg_nents(req->src) > 1 || sg_nents(req->dst) > 1)
989 return ixp4xx_cipher_fallback(req, encrypt);
990
Linus Walleij76f24b42021-05-25 10:50:56 +0200991 if (qmgr_stat_full(send_qid))
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800992 return -EAGAIN;
993 if (atomic_read(&ctx->configuring))
994 return -EAGAIN;
995
996 dir = encrypt ? &ctx->encrypt : &ctx->decrypt;
Corentin Labbee8acf012021-05-05 20:26:09 +0000997 req_ctx->encrypt = encrypt;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +0800998
999 crypt = get_crypt_desc();
1000 if (!crypt)
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001001 return -ENOMEM;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001002
1003 crypt->data.ablk_req = req;
1004 crypt->crypto_ctx = dir->npe_ctx_phys;
1005 crypt->mode = dir->npe_mode;
1006 crypt->init_len = dir->npe_ctx_idx;
1007
1008 crypt->crypt_offs = 0;
1009 crypt->crypt_len = nbytes;
1010
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001011 BUG_ON(ivsize && !req->iv);
1012 memcpy(crypt->iv, req->iv, ivsize);
Corentin Labbee8acf012021-05-05 20:26:09 +00001013 if (ivsize > 0 && !encrypt) {
1014 offset = req->cryptlen - ivsize;
1015 scatterwalk_map_and_copy(req_ctx->iv, req->src, offset, ivsize, 0);
1016 }
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001017 if (req->src != req->dst) {
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001018 struct buffer_desc dst_hook;
Corentin Labbe39e39cf2021-05-05 20:26:13 +00001019
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001020 crypt->mode |= NPE_OP_NOT_IN_PLACE;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001021 /* This was never tested by Intel
1022 * for more than one dst buffer, I think. */
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001023 req_ctx->dst = NULL;
1024 if (!chainup_buffers(dev, req->dst, nbytes, &dst_hook,
Corentin Labbec5e07032021-05-05 20:26:16 +00001025 flags, DMA_FROM_DEVICE))
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001026 goto free_buf_dest;
1027 src_direction = DMA_TO_DEVICE;
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001028 req_ctx->dst = dst_hook.next;
1029 crypt->dst_buf = dst_hook.phys_next;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001030 } else {
1031 req_ctx->dst = NULL;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001032 }
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001033 req_ctx->src = NULL;
Corentin Labbec5e07032021-05-05 20:26:16 +00001034 if (!chainup_buffers(dev, req->src, nbytes, &src_hook, flags,
1035 src_direction))
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001036 goto free_buf_src;
1037
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001038 req_ctx->src = src_hook.next;
1039 crypt->src_buf = src_hook.phys_next;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001040 crypt->ctl_flags |= CTL_FLAG_PERFORM_ABLK;
Linus Walleij76f24b42021-05-25 10:50:56 +02001041 qmgr_put_entry(send_qid, crypt_virt2phys(crypt));
1042 BUG_ON(qmgr_stat_overflow(send_qid));
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001043 return -EINPROGRESS;
1044
1045free_buf_src:
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001046 free_buf_chain(dev, req_ctx->src, crypt->src_buf);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001047free_buf_dest:
Corentin Labbeffb017e2021-05-05 20:26:15 +00001048 if (req->src != req->dst)
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001049 free_buf_chain(dev, req_ctx->dst, crypt->dst_buf);
Corentin Labbeffb017e2021-05-05 20:26:15 +00001050
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001051 crypt->ctl_flags = CTL_FLAG_UNUSED;
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001052 return -ENOMEM;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001053}
1054
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001055static int ablk_encrypt(struct skcipher_request *req)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001056{
1057 return ablk_perform(req, 1);
1058}
1059
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001060static int ablk_decrypt(struct skcipher_request *req)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001061{
1062 return ablk_perform(req, 0);
1063}
1064
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001065static int ablk_rfc3686_crypt(struct skcipher_request *req)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001066{
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001067 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1068 struct ixp_ctx *ctx = crypto_skcipher_ctx(tfm);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001069 u8 iv[CTR_RFC3686_BLOCK_SIZE];
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001070 u8 *info = req->iv;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001071 int ret;
1072
1073 /* set up counter block */
Corentin Labbe39e39cf2021-05-05 20:26:13 +00001074 memcpy(iv, ctx->nonce, CTR_RFC3686_NONCE_SIZE);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001075 memcpy(iv + CTR_RFC3686_NONCE_SIZE, info, CTR_RFC3686_IV_SIZE);
1076
1077 /* initialize counter portion of counter block */
1078 *(__be32 *)(iv + CTR_RFC3686_NONCE_SIZE + CTR_RFC3686_IV_SIZE) =
1079 cpu_to_be32(1);
1080
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001081 req->iv = iv;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001082 ret = ablk_perform(req, 1);
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001083 req->iv = info;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001084 return ret;
1085}
1086
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001087static int aead_perform(struct aead_request *req, int encrypt,
Corentin Labbec5e07032021-05-05 20:26:16 +00001088 int cryptoffset, int eff_cryptlen, u8 *iv)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001089{
1090 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1091 struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
Corentin Labbe35570842021-05-05 20:26:11 +00001092 unsigned int ivsize = crypto_aead_ivsize(tfm);
1093 unsigned int authsize = crypto_aead_authsize(tfm);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001094 struct ix_sa_dir *dir;
1095 struct crypt_ctl *crypt;
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001096 unsigned int cryptlen;
1097 struct buffer_desc *buf, src_hook;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001098 struct aead_ctx *req_ctx = aead_request_ctx(req);
Russell King27c17892013-06-10 19:09:45 +01001099 struct device *dev = &pdev->dev;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001100 gfp_t flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
1101 GFP_KERNEL : GFP_ATOMIC;
Herbert Xud7295a82015-07-30 17:53:18 +08001102 enum dma_data_direction src_direction = DMA_BIDIRECTIONAL;
1103 unsigned int lastlen;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001104
Linus Walleij76f24b42021-05-25 10:50:56 +02001105 if (qmgr_stat_full(send_qid))
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001106 return -EAGAIN;
1107 if (atomic_read(&ctx->configuring))
1108 return -EAGAIN;
1109
1110 if (encrypt) {
1111 dir = &ctx->encrypt;
1112 cryptlen = req->cryptlen;
1113 } else {
1114 dir = &ctx->decrypt;
1115 /* req->cryptlen includes the authsize when decrypting */
Corentin Labbe39e39cf2021-05-05 20:26:13 +00001116 cryptlen = req->cryptlen - authsize;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001117 eff_cryptlen -= authsize;
1118 }
1119 crypt = get_crypt_desc();
1120 if (!crypt)
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001121 return -ENOMEM;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001122
1123 crypt->data.aead_req = req;
1124 crypt->crypto_ctx = dir->npe_ctx_phys;
1125 crypt->mode = dir->npe_mode;
1126 crypt->init_len = dir->npe_ctx_idx;
1127
1128 crypt->crypt_offs = cryptoffset;
1129 crypt->crypt_len = eff_cryptlen;
1130
1131 crypt->auth_offs = 0;
Herbert Xud7295a82015-07-30 17:53:18 +08001132 crypt->auth_len = req->assoclen + cryptlen;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001133 BUG_ON(ivsize && !req->iv);
1134 memcpy(crypt->iv, req->iv, ivsize);
1135
Herbert Xu0f987e22016-01-19 09:00:21 +08001136 buf = chainup_buffers(dev, req->src, crypt->auth_len,
1137 &src_hook, flags, src_direction);
1138 req_ctx->src = src_hook.next;
1139 crypt->src_buf = src_hook.phys_next;
1140 if (!buf)
1141 goto free_buf_src;
1142
1143 lastlen = buf->buf_len;
1144 if (lastlen >= authsize)
1145 crypt->icv_rev_aes = buf->phys_addr +
1146 buf->buf_len - authsize;
1147
Herbert Xud7295a82015-07-30 17:53:18 +08001148 req_ctx->dst = NULL;
1149
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001150 if (req->src != req->dst) {
Herbert Xud7295a82015-07-30 17:53:18 +08001151 struct buffer_desc dst_hook;
1152
1153 crypt->mode |= NPE_OP_NOT_IN_PLACE;
1154 src_direction = DMA_TO_DEVICE;
1155
1156 buf = chainup_buffers(dev, req->dst, crypt->auth_len,
1157 &dst_hook, flags, DMA_FROM_DEVICE);
1158 req_ctx->dst = dst_hook.next;
1159 crypt->dst_buf = dst_hook.phys_next;
1160
1161 if (!buf)
1162 goto free_buf_dst;
1163
1164 if (encrypt) {
1165 lastlen = buf->buf_len;
1166 if (lastlen >= authsize)
1167 crypt->icv_rev_aes = buf->phys_addr +
1168 buf->buf_len - authsize;
1169 }
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001170 }
1171
Herbert Xud7295a82015-07-30 17:53:18 +08001172 if (unlikely(lastlen < authsize)) {
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001173 /* The 12 hmac bytes are scattered,
1174 * we need to copy them into a safe buffer */
1175 req_ctx->hmac_virt = dma_pool_alloc(buffer_pool, flags,
Corentin Labbec5e07032021-05-05 20:26:16 +00001176 &crypt->icv_rev_aes);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001177 if (unlikely(!req_ctx->hmac_virt))
Herbert Xu28389572017-08-02 16:40:47 +08001178 goto free_buf_dst;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001179 if (!encrypt) {
1180 scatterwalk_map_and_copy(req_ctx->hmac_virt,
Corentin Labbec5e07032021-05-05 20:26:16 +00001181 req->src, cryptlen, authsize, 0);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001182 }
1183 req_ctx->encrypt = encrypt;
1184 } else {
1185 req_ctx->hmac_virt = NULL;
1186 }
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001187
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001188 crypt->ctl_flags |= CTL_FLAG_PERFORM_AEAD;
Linus Walleij76f24b42021-05-25 10:50:56 +02001189 qmgr_put_entry(send_qid, crypt_virt2phys(crypt));
1190 BUG_ON(qmgr_stat_overflow(send_qid));
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001191 return -EINPROGRESS;
Herbert Xud7295a82015-07-30 17:53:18 +08001192
Herbert Xud7295a82015-07-30 17:53:18 +08001193free_buf_dst:
1194 free_buf_chain(dev, req_ctx->dst, crypt->dst_buf);
Herbert Xu28389572017-08-02 16:40:47 +08001195free_buf_src:
1196 free_buf_chain(dev, req_ctx->src, crypt->src_buf);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001197 crypt->ctl_flags = CTL_FLAG_UNUSED;
Christian Hohnstaedt0d44dc52009-03-27 15:09:05 +08001198 return -ENOMEM;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001199}
1200
1201static int aead_setup(struct crypto_aead *tfm, unsigned int authsize)
1202{
1203 struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
Corentin Labbe35570842021-05-05 20:26:11 +00001204 unsigned int digest_len = crypto_aead_maxauthsize(tfm);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001205 int ret;
1206
1207 if (!ctx->enckey_len && !ctx->authkey_len)
1208 return 0;
1209 init_completion(&ctx->completion);
1210 atomic_inc(&ctx->configuring);
1211
1212 reset_sa_dir(&ctx->encrypt);
1213 reset_sa_dir(&ctx->decrypt);
1214
1215 ret = setup_cipher(&tfm->base, 0, ctx->enckey, ctx->enckey_len);
1216 if (ret)
1217 goto out;
1218 ret = setup_cipher(&tfm->base, 1, ctx->enckey, ctx->enckey_len);
1219 if (ret)
1220 goto out;
1221 ret = setup_auth(&tfm->base, 0, authsize, ctx->authkey,
Corentin Labbec5e07032021-05-05 20:26:16 +00001222 ctx->authkey_len, digest_len);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001223 if (ret)
1224 goto out;
1225 ret = setup_auth(&tfm->base, 1, authsize, ctx->authkey,
Corentin Labbec5e07032021-05-05 20:26:16 +00001226 ctx->authkey_len, digest_len);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001227out:
1228 if (!atomic_dec_and_test(&ctx->configuring))
1229 wait_for_completion(&ctx->completion);
1230 return ret;
1231}
1232
1233static int aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
1234{
Herbert Xu6da9c232015-05-21 15:11:06 +08001235 int max = crypto_aead_maxauthsize(tfm) >> 2;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001236
Corentin Labbe39e39cf2021-05-05 20:26:13 +00001237 if ((authsize >> 2) < 1 || (authsize >> 2) > max || (authsize & 3))
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001238 return -EINVAL;
1239 return aead_setup(tfm, authsize);
1240}
1241
1242static int aead_setkey(struct crypto_aead *tfm, const u8 *key,
Corentin Labbec5e07032021-05-05 20:26:16 +00001243 unsigned int keylen)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001244{
1245 struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
Mathias Krause56902782013-10-15 13:49:32 +02001246 struct crypto_authenc_keys keys;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001247
Mathias Krause56902782013-10-15 13:49:32 +02001248 if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001249 goto badkey;
1250
Mathias Krause56902782013-10-15 13:49:32 +02001251 if (keys.authkeylen > sizeof(ctx->authkey))
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001252 goto badkey;
1253
Mathias Krause56902782013-10-15 13:49:32 +02001254 if (keys.enckeylen > sizeof(ctx->enckey))
1255 goto badkey;
1256
1257 memcpy(ctx->authkey, keys.authkey, keys.authkeylen);
1258 memcpy(ctx->enckey, keys.enckey, keys.enckeylen);
1259 ctx->authkey_len = keys.authkeylen;
1260 ctx->enckey_len = keys.enckeylen;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001261
Tudor-Dan Ambarus0e7da292018-03-23 12:42:21 +02001262 memzero_explicit(&keys, sizeof(keys));
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001263 return aead_setup(tfm, crypto_aead_authsize(tfm));
1264badkey:
Tudor-Dan Ambarus0e7da292018-03-23 12:42:21 +02001265 memzero_explicit(&keys, sizeof(keys));
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001266 return -EINVAL;
1267}
1268
Herbert Xudba434a2019-04-11 16:51:11 +08001269static int des3_aead_setkey(struct crypto_aead *tfm, const u8 *key,
1270 unsigned int keylen)
1271{
1272 struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
Herbert Xudba434a2019-04-11 16:51:11 +08001273 struct crypto_authenc_keys keys;
1274 int err;
1275
1276 err = crypto_authenc_extractkeys(&keys, key, keylen);
1277 if (unlikely(err))
1278 goto badkey;
1279
1280 err = -EINVAL;
1281 if (keys.authkeylen > sizeof(ctx->authkey))
1282 goto badkey;
1283
Ard Biesheuvel3ca20b62019-08-15 12:00:56 +03001284 err = verify_aead_des3_key(tfm, keys.enckey, keys.enckeylen);
1285 if (err)
Herbert Xudba434a2019-04-11 16:51:11 +08001286 goto badkey;
1287
1288 memcpy(ctx->authkey, keys.authkey, keys.authkeylen);
1289 memcpy(ctx->enckey, keys.enckey, keys.enckeylen);
1290 ctx->authkey_len = keys.authkeylen;
1291 ctx->enckey_len = keys.enckeylen;
1292
1293 memzero_explicit(&keys, sizeof(keys));
1294 return aead_setup(tfm, crypto_aead_authsize(tfm));
1295badkey:
Herbert Xudba434a2019-04-11 16:51:11 +08001296 memzero_explicit(&keys, sizeof(keys));
1297 return err;
1298}
1299
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001300static int aead_encrypt(struct aead_request *req)
1301{
Herbert Xud7295a82015-07-30 17:53:18 +08001302 return aead_perform(req, 1, req->assoclen, req->cryptlen, req->iv);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001303}
1304
1305static int aead_decrypt(struct aead_request *req)
1306{
Herbert Xud7295a82015-07-30 17:53:18 +08001307 return aead_perform(req, 0, req->assoclen, req->cryptlen, req->iv);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001308}
1309
1310static struct ixp_alg ixp4xx_algos[] = {
1311{
1312 .crypto = {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001313 .base.cra_name = "cbc(des)",
1314 .base.cra_blocksize = DES_BLOCK_SIZE,
1315
1316 .min_keysize = DES_KEY_SIZE,
1317 .max_keysize = DES_KEY_SIZE,
1318 .ivsize = DES_BLOCK_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001319 },
1320 .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192,
1321 .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192,
1322
1323}, {
1324 .crypto = {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001325 .base.cra_name = "ecb(des)",
1326 .base.cra_blocksize = DES_BLOCK_SIZE,
1327 .min_keysize = DES_KEY_SIZE,
1328 .max_keysize = DES_KEY_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001329 },
1330 .cfg_enc = CIPH_ENCR | MOD_DES | MOD_ECB | KEYLEN_192,
1331 .cfg_dec = CIPH_DECR | MOD_DES | MOD_ECB | KEYLEN_192,
1332}, {
1333 .crypto = {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001334 .base.cra_name = "cbc(des3_ede)",
1335 .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
1336
1337 .min_keysize = DES3_EDE_KEY_SIZE,
1338 .max_keysize = DES3_EDE_KEY_SIZE,
1339 .ivsize = DES3_EDE_BLOCK_SIZE,
1340 .setkey = ablk_des3_setkey,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001341 },
1342 .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192,
1343 .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192,
1344}, {
1345 .crypto = {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001346 .base.cra_name = "ecb(des3_ede)",
1347 .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
1348
1349 .min_keysize = DES3_EDE_KEY_SIZE,
1350 .max_keysize = DES3_EDE_KEY_SIZE,
1351 .setkey = ablk_des3_setkey,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001352 },
1353 .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_ECB | KEYLEN_192,
1354 .cfg_dec = CIPH_DECR | MOD_3DES | MOD_ECB | KEYLEN_192,
1355}, {
1356 .crypto = {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001357 .base.cra_name = "cbc(aes)",
1358 .base.cra_blocksize = AES_BLOCK_SIZE,
1359
1360 .min_keysize = AES_MIN_KEY_SIZE,
1361 .max_keysize = AES_MAX_KEY_SIZE,
1362 .ivsize = AES_BLOCK_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001363 },
1364 .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC,
1365 .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC,
1366}, {
1367 .crypto = {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001368 .base.cra_name = "ecb(aes)",
1369 .base.cra_blocksize = AES_BLOCK_SIZE,
1370
1371 .min_keysize = AES_MIN_KEY_SIZE,
1372 .max_keysize = AES_MAX_KEY_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001373 },
1374 .cfg_enc = CIPH_ENCR | MOD_AES | MOD_ECB,
1375 .cfg_dec = CIPH_DECR | MOD_AES | MOD_ECB,
1376}, {
1377 .crypto = {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001378 .base.cra_name = "ctr(aes)",
1379 .base.cra_blocksize = 1,
1380
1381 .min_keysize = AES_MIN_KEY_SIZE,
1382 .max_keysize = AES_MAX_KEY_SIZE,
1383 .ivsize = AES_BLOCK_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001384 },
1385 .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CTR,
1386 .cfg_dec = CIPH_ENCR | MOD_AES | MOD_CTR,
1387}, {
1388 .crypto = {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001389 .base.cra_name = "rfc3686(ctr(aes))",
1390 .base.cra_blocksize = 1,
1391
1392 .min_keysize = AES_MIN_KEY_SIZE,
1393 .max_keysize = AES_MAX_KEY_SIZE,
1394 .ivsize = AES_BLOCK_SIZE,
1395 .setkey = ablk_rfc3686_setkey,
1396 .encrypt = ablk_rfc3686_crypt,
1397 .decrypt = ablk_rfc3686_crypt,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001398 },
1399 .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CTR,
1400 .cfg_dec = CIPH_ENCR | MOD_AES | MOD_CTR,
Herbert Xud7295a82015-07-30 17:53:18 +08001401} };
1402
1403static struct ixp_aead_alg ixp4xx_aeads[] = {
1404{
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001405 .crypto = {
Herbert Xud7295a82015-07-30 17:53:18 +08001406 .base = {
1407 .cra_name = "authenc(hmac(md5),cbc(des))",
1408 .cra_blocksize = DES_BLOCK_SIZE,
1409 },
1410 .ivsize = DES_BLOCK_SIZE,
1411 .maxauthsize = MD5_DIGEST_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001412 },
1413 .hash = &hash_alg_md5,
1414 .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192,
1415 .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192,
1416}, {
1417 .crypto = {
Herbert Xud7295a82015-07-30 17:53:18 +08001418 .base = {
1419 .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
1420 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1421 },
1422 .ivsize = DES3_EDE_BLOCK_SIZE,
1423 .maxauthsize = MD5_DIGEST_SIZE,
Herbert Xudba434a2019-04-11 16:51:11 +08001424 .setkey = des3_aead_setkey,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001425 },
1426 .hash = &hash_alg_md5,
1427 .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192,
1428 .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192,
1429}, {
1430 .crypto = {
Herbert Xud7295a82015-07-30 17:53:18 +08001431 .base = {
1432 .cra_name = "authenc(hmac(sha1),cbc(des))",
1433 .cra_blocksize = DES_BLOCK_SIZE,
1434 },
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001435 .ivsize = DES_BLOCK_SIZE,
1436 .maxauthsize = SHA1_DIGEST_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001437 },
1438 .hash = &hash_alg_sha1,
1439 .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192,
1440 .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192,
1441}, {
1442 .crypto = {
Herbert Xud7295a82015-07-30 17:53:18 +08001443 .base = {
1444 .cra_name = "authenc(hmac(sha1),cbc(des3_ede))",
1445 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1446 },
1447 .ivsize = DES3_EDE_BLOCK_SIZE,
1448 .maxauthsize = SHA1_DIGEST_SIZE,
Herbert Xudba434a2019-04-11 16:51:11 +08001449 .setkey = des3_aead_setkey,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001450 },
1451 .hash = &hash_alg_sha1,
1452 .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192,
1453 .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192,
1454}, {
1455 .crypto = {
Herbert Xud7295a82015-07-30 17:53:18 +08001456 .base = {
1457 .cra_name = "authenc(hmac(md5),cbc(aes))",
1458 .cra_blocksize = AES_BLOCK_SIZE,
1459 },
1460 .ivsize = AES_BLOCK_SIZE,
1461 .maxauthsize = MD5_DIGEST_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001462 },
1463 .hash = &hash_alg_md5,
1464 .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC,
1465 .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC,
1466}, {
1467 .crypto = {
Herbert Xud7295a82015-07-30 17:53:18 +08001468 .base = {
1469 .cra_name = "authenc(hmac(sha1),cbc(aes))",
1470 .cra_blocksize = AES_BLOCK_SIZE,
1471 },
1472 .ivsize = AES_BLOCK_SIZE,
1473 .maxauthsize = SHA1_DIGEST_SIZE,
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001474 },
1475 .hash = &hash_alg_sha1,
1476 .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC,
1477 .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC,
1478} };
1479
1480#define IXP_POSTFIX "-ixp4xx"
Russell Kingd8cbc3f2013-06-10 18:52:52 +01001481
Arnd Bergmannf5a6bf02021-05-25 10:30:46 +02001482static int ixp_crypto_probe(struct platform_device *_pdev)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001483{
Linus Walleij76f24b42021-05-25 10:50:56 +02001484 struct device *dev = &_pdev->dev;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001485 int num = ARRAY_SIZE(ixp4xx_algos);
Krzysztof Hałasaefb753b2013-12-31 11:51:16 +01001486 int i, err;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001487
Arnd Bergmannf5a6bf02021-05-25 10:30:46 +02001488 pdev = _pdev;
Russell Kingd8cbc3f2013-06-10 18:52:52 +01001489
Linus Walleij76f24b42021-05-25 10:50:56 +02001490 err = init_ixp_crypto(dev);
Arnd Bergmannf5a6bf02021-05-25 10:30:46 +02001491 if (err)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001492 return err;
Arnd Bergmannf5a6bf02021-05-25 10:30:46 +02001493
Corentin Labbe39e39cf2021-05-05 20:26:13 +00001494 for (i = 0; i < num; i++) {
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001495 struct skcipher_alg *cra = &ixp4xx_algos[i].crypto;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001496
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001497 if (snprintf(cra->base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
Corentin Labbeffb017e2021-05-05 20:26:15 +00001498 "%s"IXP_POSTFIX, cra->base.cra_name) >=
1499 CRYPTO_MAX_ALG_NAME)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001500 continue;
Corentin Labbeffb017e2021-05-05 20:26:15 +00001501 if (!support_aes && (ixp4xx_algos[i].cfg_enc & MOD_AES))
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001502 continue;
Herbert Xud7295a82015-07-30 17:53:18 +08001503
1504 /* block ciphers */
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001505 cra->base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY |
Mikulas Patockab8aa7dc2020-07-09 23:20:41 -07001506 CRYPTO_ALG_ASYNC |
Corentin Labbedfb098d2021-05-05 20:26:10 +00001507 CRYPTO_ALG_ALLOCATES_MEMORY |
1508 CRYPTO_ALG_NEED_FALLBACK;
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001509 if (!cra->setkey)
1510 cra->setkey = ablk_setkey;
1511 if (!cra->encrypt)
1512 cra->encrypt = ablk_encrypt;
1513 if (!cra->decrypt)
1514 cra->decrypt = ablk_decrypt;
1515 cra->init = init_tfm_ablk;
1516 cra->exit = exit_tfm_ablk;
Herbert Xud7295a82015-07-30 17:53:18 +08001517
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001518 cra->base.cra_ctxsize = sizeof(struct ixp_ctx);
1519 cra->base.cra_module = THIS_MODULE;
1520 cra->base.cra_alignmask = 3;
1521 cra->base.cra_priority = 300;
1522 if (crypto_register_skcipher(cra))
Corentin Labbef5b82be2021-05-05 20:26:12 +00001523 dev_err(&pdev->dev, "Failed to register '%s'\n",
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001524 cra->base.cra_name);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001525 else
1526 ixp4xx_algos[i].registered = 1;
1527 }
Herbert Xud7295a82015-07-30 17:53:18 +08001528
1529 for (i = 0; i < ARRAY_SIZE(ixp4xx_aeads); i++) {
1530 struct aead_alg *cra = &ixp4xx_aeads[i].crypto;
1531
1532 if (snprintf(cra->base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
1533 "%s"IXP_POSTFIX, cra->base.cra_name) >=
1534 CRYPTO_MAX_ALG_NAME)
1535 continue;
1536 if (!support_aes && (ixp4xx_algos[i].cfg_enc & MOD_AES))
1537 continue;
1538
1539 /* authenc */
1540 cra->base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY |
Mikulas Patockab8aa7dc2020-07-09 23:20:41 -07001541 CRYPTO_ALG_ASYNC |
1542 CRYPTO_ALG_ALLOCATES_MEMORY;
Herbert Xudba434a2019-04-11 16:51:11 +08001543 cra->setkey = cra->setkey ?: aead_setkey;
Herbert Xud7295a82015-07-30 17:53:18 +08001544 cra->setauthsize = aead_setauthsize;
1545 cra->encrypt = aead_encrypt;
1546 cra->decrypt = aead_decrypt;
1547 cra->init = init_tfm_aead;
1548 cra->exit = exit_tfm_aead;
1549
1550 cra->base.cra_ctxsize = sizeof(struct ixp_ctx);
1551 cra->base.cra_module = THIS_MODULE;
1552 cra->base.cra_alignmask = 3;
1553 cra->base.cra_priority = 300;
1554
1555 if (crypto_register_aead(cra))
Corentin Labbef5b82be2021-05-05 20:26:12 +00001556 dev_err(&pdev->dev, "Failed to register '%s'\n",
Herbert Xud7295a82015-07-30 17:53:18 +08001557 cra->base.cra_driver_name);
1558 else
1559 ixp4xx_aeads[i].registered = 1;
1560 }
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001561 return 0;
1562}
1563
Arnd Bergmannf5a6bf02021-05-25 10:30:46 +02001564static int ixp_crypto_remove(struct platform_device *pdev)
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001565{
1566 int num = ARRAY_SIZE(ixp4xx_algos);
1567 int i;
1568
Herbert Xud7295a82015-07-30 17:53:18 +08001569 for (i = 0; i < ARRAY_SIZE(ixp4xx_aeads); i++) {
1570 if (ixp4xx_aeads[i].registered)
1571 crypto_unregister_aead(&ixp4xx_aeads[i].crypto);
1572 }
1573
Corentin Labbe39e39cf2021-05-05 20:26:13 +00001574 for (i = 0; i < num; i++) {
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001575 if (ixp4xx_algos[i].registered)
Ard Biesheuvel4aaf3842019-11-09 18:09:40 +01001576 crypto_unregister_skcipher(&ixp4xx_algos[i].crypto);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001577 }
Russell King27c17892013-06-10 19:09:45 +01001578 release_ixp_crypto(&pdev->dev);
Arnd Bergmannf5a6bf02021-05-25 10:30:46 +02001579
1580 return 0;
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001581}
Linus Walleij76f24b42021-05-25 10:50:56 +02001582static const struct of_device_id ixp4xx_crypto_of_match[] = {
1583 {
1584 .compatible = "intel,ixp4xx-crypto",
1585 },
1586 {},
1587};
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001588
Arnd Bergmannf5a6bf02021-05-25 10:30:46 +02001589static struct platform_driver ixp_crypto_driver = {
1590 .probe = ixp_crypto_probe,
1591 .remove = ixp_crypto_remove,
Linus Walleij76f24b42021-05-25 10:50:56 +02001592 .driver = {
1593 .name = "ixp4xx_crypto",
1594 .of_match_table = ixp4xx_crypto_of_match,
1595 },
Arnd Bergmannf5a6bf02021-05-25 10:30:46 +02001596};
1597module_platform_driver(ixp_crypto_driver);
Christian Hohnstaedt81bef012008-06-25 14:38:47 +08001598
1599MODULE_LICENSE("GPL");
1600MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>");
1601MODULE_DESCRIPTION("IXP4xx hardware crypto");
1602