Skip to content

Commit 76f24b4

Browse files
linuswherbertx
authored andcommitted
crypto: ixp4xx - Add device tree support
This makes the IXP4xx driver probe from the device tree and retrieve the NPE and two queue manager handled used to process crypto from the device tree. As the crypto engine is topologically a part of the NPE hardware, we augment the NPE driver to spawn the crypto engine as a child. The platform data probe path is going away in due time, for now it is an isolated else clause. Cc: Corentin Labbe <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 9372649 commit 76f24b4

File tree

2 files changed

+86
-28
lines changed

2 files changed

+86
-28
lines changed

drivers/crypto/ixp4xx_crypto.c

Lines changed: 79 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/spinlock.h>
1616
#include <linux/gfp.h>
1717
#include <linux/module.h>
18+
#include <linux/of.h>
1819

1920
#include <crypto/ctr.h>
2021
#include <crypto/internal/des.h>
@@ -71,15 +72,11 @@
7172
#define MOD_AES256 (0x0a00 | KEYLEN_256)
7273

7374
#define MAX_IVLEN 16
74-
#define NPE_ID 2 /* NPE C */
7575
#define NPE_QLEN 16
7676
/* Space for registering when the first
7777
* NPE_QLEN crypt_ctl are busy */
7878
#define NPE_QLEN_TOTAL 64
7979

80-
#define SEND_QID 29
81-
#define RECV_QID 30
82-
8380
#define CTL_FLAG_UNUSED 0x0000
8481
#define CTL_FLAG_USED 0x1000
8582
#define CTL_FLAG_PERFORM_ABLK 0x0001
@@ -221,6 +218,9 @@ static const struct ix_hash_algo hash_alg_sha1 = {
221218
};
222219

223220
static struct npe *npe_c;
221+
222+
static unsigned int send_qid;
223+
static unsigned int recv_qid;
224224
static struct dma_pool *buffer_pool;
225225
static struct dma_pool *ctx_pool;
226226

@@ -437,8 +437,7 @@ static void crypto_done_action(unsigned long arg)
437437
int i;
438438

439439
for (i = 0; i < 4; i++) {
440-
dma_addr_t phys = qmgr_get_entry(RECV_QID);
441-
440+
dma_addr_t phys = qmgr_get_entry(recv_qid);
442441
if (!phys)
443442
return;
444443
one_packet(phys);
@@ -448,10 +447,52 @@ static void crypto_done_action(unsigned long arg)
448447

449448
static int init_ixp_crypto(struct device *dev)
450449
{
451-
int ret = -ENODEV;
450+
struct device_node *np = dev->of_node;
452451
u32 msg[2] = { 0, 0 };
452+
int ret = -ENODEV;
453+
u32 npe_id;
454+
455+
dev_info(dev, "probing...\n");
456+
457+
/* Locate the NPE and queue manager to use from device tree */
458+
if (IS_ENABLED(CONFIG_OF) && np) {
459+
struct of_phandle_args queue_spec;
460+
struct of_phandle_args npe_spec;
461+
462+
ret = of_parse_phandle_with_fixed_args(np, "intel,npe-handle",
463+
1, 0, &npe_spec);
464+
if (ret) {
465+
dev_err(dev, "no NPE engine specified\n");
466+
return -ENODEV;
467+
}
468+
npe_id = npe_spec.args[0];
453469

454-
npe_c = npe_request(NPE_ID);
470+
ret = of_parse_phandle_with_fixed_args(np, "queue-rx", 1, 0,
471+
&queue_spec);
472+
if (ret) {
473+
dev_err(dev, "no rx queue phandle\n");
474+
return -ENODEV;
475+
}
476+
recv_qid = queue_spec.args[0];
477+
478+
ret = of_parse_phandle_with_fixed_args(np, "queue-txready", 1, 0,
479+
&queue_spec);
480+
if (ret) {
481+
dev_err(dev, "no txready queue phandle\n");
482+
return -ENODEV;
483+
}
484+
send_qid = queue_spec.args[0];
485+
} else {
486+
/*
487+
* Hardcoded engine when using platform data, this goes away
488+
* when we switch to using DT only.
489+
*/
490+
npe_id = 2;
491+
send_qid = 29;
492+
recv_qid = 30;
493+
}
494+
495+
npe_c = npe_request(npe_id);
455496
if (!npe_c)
456497
return ret;
457498

@@ -497,20 +538,20 @@ static int init_ixp_crypto(struct device *dev)
497538
if (!ctx_pool)
498539
goto err;
499540

500-
ret = qmgr_request_queue(SEND_QID, NPE_QLEN_TOTAL, 0, 0,
541+
ret = qmgr_request_queue(send_qid, NPE_QLEN_TOTAL, 0, 0,
501542
"ixp_crypto:out", NULL);
502543
if (ret)
503544
goto err;
504-
ret = qmgr_request_queue(RECV_QID, NPE_QLEN, 0, 0,
545+
ret = qmgr_request_queue(recv_qid, NPE_QLEN, 0, 0,
505546
"ixp_crypto:in", NULL);
506547
if (ret) {
507-
qmgr_release_queue(SEND_QID);
548+
qmgr_release_queue(send_qid);
508549
goto err;
509550
}
510-
qmgr_set_irq(RECV_QID, QUEUE_IRQ_SRC_NOT_EMPTY, irqhandler, NULL);
551+
qmgr_set_irq(recv_qid, QUEUE_IRQ_SRC_NOT_EMPTY, irqhandler, NULL);
511552
tasklet_init(&crypto_done_tasklet, crypto_done_action, 0);
512553

513-
qmgr_enable_irq(RECV_QID);
554+
qmgr_enable_irq(recv_qid);
514555
return 0;
515556

516557
npe_error:
@@ -526,11 +567,11 @@ static int init_ixp_crypto(struct device *dev)
526567

527568
static void release_ixp_crypto(struct device *dev)
528569
{
529-
qmgr_disable_irq(RECV_QID);
570+
qmgr_disable_irq(recv_qid);
530571
tasklet_kill(&crypto_done_tasklet);
531572

532-
qmgr_release_queue(SEND_QID);
533-
qmgr_release_queue(RECV_QID);
573+
qmgr_release_queue(send_qid);
574+
qmgr_release_queue(recv_qid);
534575

535576
dma_pool_destroy(ctx_pool);
536577
dma_pool_destroy(buffer_pool);
@@ -682,8 +723,8 @@ static int register_chain_var(struct crypto_tfm *tfm, u8 xpad, u32 target,
682723
buf->phys_addr = pad_phys;
683724

684725
atomic_inc(&ctx->configuring);
685-
qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt));
686-
BUG_ON(qmgr_stat_overflow(SEND_QID));
726+
qmgr_put_entry(send_qid, crypt_virt2phys(crypt));
727+
BUG_ON(qmgr_stat_overflow(send_qid));
687728
return 0;
688729
}
689730

@@ -757,8 +798,8 @@ static int gen_rev_aes_key(struct crypto_tfm *tfm)
757798
crypt->ctl_flags |= CTL_FLAG_GEN_REVAES;
758799

759800
atomic_inc(&ctx->configuring);
760-
qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt));
761-
BUG_ON(qmgr_stat_overflow(SEND_QID));
801+
qmgr_put_entry(send_qid, crypt_virt2phys(crypt));
802+
BUG_ON(qmgr_stat_overflow(send_qid));
762803
return 0;
763804
}
764805

@@ -943,7 +984,7 @@ static int ablk_perform(struct skcipher_request *req, int encrypt)
943984
if (sg_nents(req->src) > 1 || sg_nents(req->dst) > 1)
944985
return ixp4xx_cipher_fallback(req, encrypt);
945986

946-
if (qmgr_stat_full(SEND_QID))
987+
if (qmgr_stat_full(send_qid))
947988
return -EAGAIN;
948989
if (atomic_read(&ctx->configuring))
949990
return -EAGAIN;
@@ -993,8 +1034,8 @@ static int ablk_perform(struct skcipher_request *req, int encrypt)
9931034
req_ctx->src = src_hook.next;
9941035
crypt->src_buf = src_hook.phys_next;
9951036
crypt->ctl_flags |= CTL_FLAG_PERFORM_ABLK;
996-
qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt));
997-
BUG_ON(qmgr_stat_overflow(SEND_QID));
1037+
qmgr_put_entry(send_qid, crypt_virt2phys(crypt));
1038+
BUG_ON(qmgr_stat_overflow(send_qid));
9981039
return -EINPROGRESS;
9991040

10001041
free_buf_src:
@@ -1057,7 +1098,7 @@ static int aead_perform(struct aead_request *req, int encrypt,
10571098
enum dma_data_direction src_direction = DMA_BIDIRECTIONAL;
10581099
unsigned int lastlen;
10591100

1060-
if (qmgr_stat_full(SEND_QID))
1101+
if (qmgr_stat_full(send_qid))
10611102
return -EAGAIN;
10621103
if (atomic_read(&ctx->configuring))
10631104
return -EAGAIN;
@@ -1141,8 +1182,8 @@ static int aead_perform(struct aead_request *req, int encrypt,
11411182
}
11421183

11431184
crypt->ctl_flags |= CTL_FLAG_PERFORM_AEAD;
1144-
qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt));
1145-
BUG_ON(qmgr_stat_overflow(SEND_QID));
1185+
qmgr_put_entry(send_qid, crypt_virt2phys(crypt));
1186+
BUG_ON(qmgr_stat_overflow(send_qid));
11461187
return -EINPROGRESS;
11471188

11481189
free_buf_dst:
@@ -1436,12 +1477,13 @@ static struct ixp_aead_alg ixp4xx_aeads[] = {
14361477

14371478
static int ixp_crypto_probe(struct platform_device *_pdev)
14381479
{
1480+
struct device *dev = &_pdev->dev;
14391481
int num = ARRAY_SIZE(ixp4xx_algos);
14401482
int i, err;
14411483

14421484
pdev = _pdev;
14431485

1444-
err = init_ixp_crypto(&pdev->dev);
1486+
err = init_ixp_crypto(dev);
14451487
if (err)
14461488
return err;
14471489

@@ -1533,11 +1575,20 @@ static int ixp_crypto_remove(struct platform_device *pdev)
15331575

15341576
return 0;
15351577
}
1578+
static const struct of_device_id ixp4xx_crypto_of_match[] = {
1579+
{
1580+
.compatible = "intel,ixp4xx-crypto",
1581+
},
1582+
{},
1583+
};
15361584

15371585
static struct platform_driver ixp_crypto_driver = {
15381586
.probe = ixp_crypto_probe,
15391587
.remove = ixp_crypto_remove,
1540-
.driver = { .name = "ixp4xx_crypto" },
1588+
.driver = {
1589+
.name = "ixp4xx_crypto",
1590+
.of_match_table = ixp4xx_crypto_of_match,
1591+
},
15411592
};
15421593
module_platform_driver(ixp_crypto_driver);
15431594

drivers/soc/ixp4xx/ixp4xx-npe.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/kernel.h>
1919
#include <linux/module.h>
2020
#include <linux/of.h>
21+
#include <linux/of_platform.h>
2122
#include <linux/platform_device.h>
2223
#include <linux/soc/ixp4xx/npe.h>
2324

@@ -679,6 +680,7 @@ static int ixp4xx_npe_probe(struct platform_device *pdev)
679680
{
680681
int i, found = 0;
681682
struct device *dev = &pdev->dev;
683+
struct device_node *np = dev->of_node;
682684
struct resource *res;
683685

684686
for (i = 0; i < NPE_COUNT; i++) {
@@ -711,6 +713,11 @@ static int ixp4xx_npe_probe(struct platform_device *pdev)
711713

712714
if (!found)
713715
return -ENODEV;
716+
717+
/* Spawn crypto subdevice if using device tree */
718+
if (IS_ENABLED(CONFIG_OF) && np)
719+
devm_of_platform_populate(dev);
720+
714721
return 0;
715722
}
716723

0 commit comments

Comments
 (0)