Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Support for Marvell's Cryptographic Engine and Security Accelerator (CESA) |
| 3 | * that can be found on the following platform: Orion, Kirkwood, Armada. This |
| 4 | * driver supports the TDMA engine on platforms on which it is available. |
| 5 | * |
| 6 | * Author: Boris Brezillon <boris.brezillon@free-electrons.com> |
| 7 | * Author: Arnaud Ebalard <arno@natisbad.org> |
| 8 | * |
| 9 | * This work is based on an initial version written by |
| 10 | * Sebastian Andrzej Siewior < sebastian at breakpoint dot cc > |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License version 2 as published |
| 14 | * by the Free Software Foundation. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/genalloc.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/kthread.h> |
| 22 | #include <linux/mbus.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/scatterlist.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/clk.h> |
| 28 | #include <linux/of.h> |
| 29 | #include <linux/of_platform.h> |
| 30 | #include <linux/of_irq.h> |
| 31 | |
| 32 | #include "cesa.h" |
| 33 | |
Boris BREZILLON | 64c55d4 | 2015-06-18 15:46:27 +0200 | [diff] [blame] | 34 | static int allhwsupport = !IS_ENABLED(CONFIG_CRYPTO_DEV_MV_CESA); |
| 35 | module_param_named(allhwsupport, allhwsupport, int, 0444); |
| 36 | MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if overlaps with the mv_cesa driver)"); |
| 37 | |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 38 | struct mv_cesa_dev *cesa_dev; |
| 39 | |
| 40 | static void mv_cesa_dequeue_req_unlocked(struct mv_cesa_engine *engine) |
| 41 | { |
| 42 | struct crypto_async_request *req, *backlog; |
| 43 | struct mv_cesa_ctx *ctx; |
| 44 | |
| 45 | spin_lock_bh(&cesa_dev->lock); |
| 46 | backlog = crypto_get_backlog(&cesa_dev->queue); |
| 47 | req = crypto_dequeue_request(&cesa_dev->queue); |
| 48 | engine->req = req; |
| 49 | spin_unlock_bh(&cesa_dev->lock); |
| 50 | |
| 51 | if (!req) |
| 52 | return; |
| 53 | |
| 54 | if (backlog) |
| 55 | backlog->complete(backlog, -EINPROGRESS); |
| 56 | |
| 57 | ctx = crypto_tfm_ctx(req->tfm); |
| 58 | ctx->ops->prepare(req, engine); |
| 59 | ctx->ops->step(req); |
| 60 | } |
| 61 | |
| 62 | static irqreturn_t mv_cesa_int(int irq, void *priv) |
| 63 | { |
| 64 | struct mv_cesa_engine *engine = priv; |
| 65 | struct crypto_async_request *req; |
| 66 | struct mv_cesa_ctx *ctx; |
| 67 | u32 status, mask; |
| 68 | irqreturn_t ret = IRQ_NONE; |
| 69 | |
| 70 | while (true) { |
| 71 | int res; |
| 72 | |
| 73 | mask = mv_cesa_get_int_mask(engine); |
| 74 | status = readl(engine->regs + CESA_SA_INT_STATUS); |
| 75 | |
| 76 | if (!(status & mask)) |
| 77 | break; |
| 78 | |
| 79 | /* |
| 80 | * TODO: avoid clearing the FPGA_INT_STATUS if this not |
| 81 | * relevant on some platforms. |
| 82 | */ |
| 83 | writel(~status, engine->regs + CESA_SA_FPGA_INT_STATUS); |
| 84 | writel(~status, engine->regs + CESA_SA_INT_STATUS); |
| 85 | |
| 86 | ret = IRQ_HANDLED; |
| 87 | spin_lock_bh(&engine->lock); |
| 88 | req = engine->req; |
| 89 | spin_unlock_bh(&engine->lock); |
| 90 | if (req) { |
| 91 | ctx = crypto_tfm_ctx(req->tfm); |
| 92 | res = ctx->ops->process(req, status & mask); |
| 93 | if (res != -EINPROGRESS) { |
| 94 | spin_lock_bh(&engine->lock); |
| 95 | engine->req = NULL; |
| 96 | mv_cesa_dequeue_req_unlocked(engine); |
| 97 | spin_unlock_bh(&engine->lock); |
| 98 | ctx->ops->cleanup(req); |
| 99 | local_bh_disable(); |
| 100 | req->complete(req, res); |
| 101 | local_bh_enable(); |
| 102 | } else { |
| 103 | ctx->ops->step(req); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return ret; |
| 109 | } |
| 110 | |
| 111 | int mv_cesa_queue_req(struct crypto_async_request *req) |
| 112 | { |
| 113 | int ret; |
| 114 | int i; |
| 115 | |
| 116 | spin_lock_bh(&cesa_dev->lock); |
| 117 | ret = crypto_enqueue_request(&cesa_dev->queue, req); |
| 118 | spin_unlock_bh(&cesa_dev->lock); |
| 119 | |
| 120 | if (ret != -EINPROGRESS) |
| 121 | return ret; |
| 122 | |
| 123 | for (i = 0; i < cesa_dev->caps->nengines; i++) { |
| 124 | spin_lock_bh(&cesa_dev->engines[i].lock); |
| 125 | if (!cesa_dev->engines[i].req) |
| 126 | mv_cesa_dequeue_req_unlocked(&cesa_dev->engines[i]); |
| 127 | spin_unlock_bh(&cesa_dev->engines[i].lock); |
| 128 | } |
| 129 | |
| 130 | return -EINPROGRESS; |
| 131 | } |
| 132 | |
| 133 | static int mv_cesa_add_algs(struct mv_cesa_dev *cesa) |
| 134 | { |
| 135 | int ret; |
| 136 | int i, j; |
| 137 | |
| 138 | for (i = 0; i < cesa->caps->ncipher_algs; i++) { |
| 139 | ret = crypto_register_alg(cesa->caps->cipher_algs[i]); |
| 140 | if (ret) |
| 141 | goto err_unregister_crypto; |
| 142 | } |
| 143 | |
| 144 | for (i = 0; i < cesa->caps->nahash_algs; i++) { |
| 145 | ret = crypto_register_ahash(cesa->caps->ahash_algs[i]); |
| 146 | if (ret) |
| 147 | goto err_unregister_ahash; |
| 148 | } |
| 149 | |
| 150 | return 0; |
| 151 | |
| 152 | err_unregister_ahash: |
| 153 | for (j = 0; j < i; j++) |
| 154 | crypto_unregister_ahash(cesa->caps->ahash_algs[j]); |
| 155 | i = cesa->caps->ncipher_algs; |
| 156 | |
| 157 | err_unregister_crypto: |
| 158 | for (j = 0; j < i; j++) |
| 159 | crypto_unregister_alg(cesa->caps->cipher_algs[j]); |
| 160 | |
| 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | static void mv_cesa_remove_algs(struct mv_cesa_dev *cesa) |
| 165 | { |
| 166 | int i; |
| 167 | |
| 168 | for (i = 0; i < cesa->caps->nahash_algs; i++) |
| 169 | crypto_unregister_ahash(cesa->caps->ahash_algs[i]); |
| 170 | |
| 171 | for (i = 0; i < cesa->caps->ncipher_algs; i++) |
| 172 | crypto_unregister_alg(cesa->caps->cipher_algs[i]); |
| 173 | } |
| 174 | |
Boris BREZILLON | 0bf6948 | 2015-06-18 15:46:28 +0200 | [diff] [blame^] | 175 | static struct crypto_alg *orion_cipher_algs[] = { |
| 176 | &mv_cesa_ecb_des_alg, |
| 177 | &mv_cesa_cbc_des_alg, |
| 178 | &mv_cesa_ecb_des3_ede_alg, |
| 179 | &mv_cesa_cbc_des3_ede_alg, |
| 180 | &mv_cesa_ecb_aes_alg, |
| 181 | &mv_cesa_cbc_aes_alg, |
| 182 | }; |
| 183 | |
| 184 | static struct ahash_alg *orion_ahash_algs[] = { |
| 185 | &mv_md5_alg, |
| 186 | &mv_sha1_alg, |
| 187 | &mv_ahmac_md5_alg, |
| 188 | &mv_ahmac_sha1_alg, |
| 189 | }; |
| 190 | |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 191 | static struct crypto_alg *armada_370_cipher_algs[] = { |
Boris BREZILLON | 7b3aaaa | 2015-06-18 15:46:22 +0200 | [diff] [blame] | 192 | &mv_cesa_ecb_des_alg, |
| 193 | &mv_cesa_cbc_des_alg, |
Arnaud Ebalard | 4ada483 | 2015-06-18 15:46:23 +0200 | [diff] [blame] | 194 | &mv_cesa_ecb_des3_ede_alg, |
| 195 | &mv_cesa_cbc_des3_ede_alg, |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 196 | &mv_cesa_ecb_aes_alg, |
| 197 | &mv_cesa_cbc_aes_alg, |
| 198 | }; |
| 199 | |
| 200 | static struct ahash_alg *armada_370_ahash_algs[] = { |
Arnaud Ebalard | 7aeef69 | 2015-06-18 15:46:24 +0200 | [diff] [blame] | 201 | &mv_md5_alg, |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 202 | &mv_sha1_alg, |
Arnaud Ebalard | f85a762 | 2015-06-18 15:46:25 +0200 | [diff] [blame] | 203 | &mv_sha256_alg, |
Arnaud Ebalard | 7aeef69 | 2015-06-18 15:46:24 +0200 | [diff] [blame] | 204 | &mv_ahmac_md5_alg, |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 205 | &mv_ahmac_sha1_alg, |
Arnaud Ebalard | f85a762 | 2015-06-18 15:46:25 +0200 | [diff] [blame] | 206 | &mv_ahmac_sha256_alg, |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 207 | }; |
| 208 | |
Boris BREZILLON | 0bf6948 | 2015-06-18 15:46:28 +0200 | [diff] [blame^] | 209 | static const struct mv_cesa_caps orion_caps = { |
| 210 | .nengines = 1, |
| 211 | .cipher_algs = orion_cipher_algs, |
| 212 | .ncipher_algs = ARRAY_SIZE(orion_cipher_algs), |
| 213 | .ahash_algs = orion_ahash_algs, |
| 214 | .nahash_algs = ARRAY_SIZE(orion_ahash_algs), |
| 215 | .has_tdma = false, |
| 216 | }; |
| 217 | |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 218 | static const struct mv_cesa_caps armada_370_caps = { |
| 219 | .nengines = 1, |
| 220 | .cipher_algs = armada_370_cipher_algs, |
| 221 | .ncipher_algs = ARRAY_SIZE(armada_370_cipher_algs), |
| 222 | .ahash_algs = armada_370_ahash_algs, |
| 223 | .nahash_algs = ARRAY_SIZE(armada_370_ahash_algs), |
Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 224 | .has_tdma = true, |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 225 | }; |
| 226 | |
Boris BREZILLON | 898c9d5 | 2015-06-18 15:46:26 +0200 | [diff] [blame] | 227 | static const struct mv_cesa_caps armada_xp_caps = { |
| 228 | .nengines = 2, |
| 229 | .cipher_algs = armada_370_cipher_algs, |
| 230 | .ncipher_algs = ARRAY_SIZE(armada_370_cipher_algs), |
| 231 | .ahash_algs = armada_370_ahash_algs, |
| 232 | .nahash_algs = ARRAY_SIZE(armada_370_ahash_algs), |
| 233 | .has_tdma = true, |
| 234 | }; |
| 235 | |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 236 | static const struct of_device_id mv_cesa_of_match_table[] = { |
Boris BREZILLON | 0bf6948 | 2015-06-18 15:46:28 +0200 | [diff] [blame^] | 237 | { .compatible = "marvell,orion-crypto", .data = &orion_caps }, |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 238 | { .compatible = "marvell,armada-370-crypto", .data = &armada_370_caps }, |
Boris BREZILLON | 898c9d5 | 2015-06-18 15:46:26 +0200 | [diff] [blame] | 239 | { .compatible = "marvell,armada-xp-crypto", .data = &armada_xp_caps }, |
| 240 | { .compatible = "marvell,armada-375-crypto", .data = &armada_xp_caps }, |
| 241 | { .compatible = "marvell,armada-38x-crypto", .data = &armada_xp_caps }, |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 242 | {} |
| 243 | }; |
| 244 | MODULE_DEVICE_TABLE(of, mv_cesa_of_match_table); |
| 245 | |
Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 246 | static void |
| 247 | mv_cesa_conf_mbus_windows(struct mv_cesa_engine *engine, |
| 248 | const struct mbus_dram_target_info *dram) |
| 249 | { |
| 250 | void __iomem *iobase = engine->regs; |
| 251 | int i; |
| 252 | |
| 253 | for (i = 0; i < 4; i++) { |
| 254 | writel(0, iobase + CESA_TDMA_WINDOW_CTRL(i)); |
| 255 | writel(0, iobase + CESA_TDMA_WINDOW_BASE(i)); |
| 256 | } |
| 257 | |
| 258 | for (i = 0; i < dram->num_cs; i++) { |
| 259 | const struct mbus_dram_window *cs = dram->cs + i; |
| 260 | |
| 261 | writel(((cs->size - 1) & 0xffff0000) | |
| 262 | (cs->mbus_attr << 8) | |
| 263 | (dram->mbus_dram_target_id << 4) | 1, |
| 264 | iobase + CESA_TDMA_WINDOW_CTRL(i)); |
| 265 | writel(cs->base, iobase + CESA_TDMA_WINDOW_BASE(i)); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | static int mv_cesa_dev_dma_init(struct mv_cesa_dev *cesa) |
| 270 | { |
| 271 | struct device *dev = cesa->dev; |
| 272 | struct mv_cesa_dev_dma *dma; |
| 273 | |
| 274 | if (!cesa->caps->has_tdma) |
| 275 | return 0; |
| 276 | |
| 277 | dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); |
| 278 | if (!dma) |
| 279 | return -ENOMEM; |
| 280 | |
| 281 | dma->tdma_desc_pool = dmam_pool_create("tdma_desc", dev, |
| 282 | sizeof(struct mv_cesa_tdma_desc), |
| 283 | 16, 0); |
| 284 | if (!dma->tdma_desc_pool) |
| 285 | return -ENOMEM; |
| 286 | |
| 287 | dma->op_pool = dmam_pool_create("cesa_op", dev, |
| 288 | sizeof(struct mv_cesa_op_ctx), 16, 0); |
| 289 | if (!dma->op_pool) |
| 290 | return -ENOMEM; |
| 291 | |
| 292 | dma->cache_pool = dmam_pool_create("cesa_cache", dev, |
| 293 | CESA_MAX_HASH_BLOCK_SIZE, 1, 0); |
| 294 | if (!dma->cache_pool) |
| 295 | return -ENOMEM; |
| 296 | |
| 297 | dma->padding_pool = dmam_pool_create("cesa_padding", dev, 72, 1, 0); |
| 298 | if (!dma->cache_pool) |
| 299 | return -ENOMEM; |
| 300 | |
| 301 | cesa->dma = dma; |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 306 | static int mv_cesa_get_sram(struct platform_device *pdev, int idx) |
| 307 | { |
| 308 | struct mv_cesa_dev *cesa = platform_get_drvdata(pdev); |
| 309 | struct mv_cesa_engine *engine = &cesa->engines[idx]; |
| 310 | const char *res_name = "sram"; |
| 311 | struct resource *res; |
| 312 | |
| 313 | engine->pool = of_get_named_gen_pool(cesa->dev->of_node, |
| 314 | "marvell,crypto-srams", |
| 315 | idx); |
| 316 | if (engine->pool) { |
| 317 | engine->sram = gen_pool_dma_alloc(engine->pool, |
| 318 | cesa->sram_size, |
| 319 | &engine->sram_dma); |
| 320 | if (engine->sram) |
| 321 | return 0; |
| 322 | |
| 323 | engine->pool = NULL; |
| 324 | return -ENOMEM; |
| 325 | } |
| 326 | |
| 327 | if (cesa->caps->nengines > 1) { |
| 328 | if (!idx) |
| 329 | res_name = "sram0"; |
| 330 | else |
| 331 | res_name = "sram1"; |
| 332 | } |
| 333 | |
| 334 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 335 | res_name); |
| 336 | if (!res || resource_size(res) < cesa->sram_size) |
| 337 | return -EINVAL; |
| 338 | |
| 339 | engine->sram = devm_ioremap_resource(cesa->dev, res); |
| 340 | if (IS_ERR(engine->sram)) |
| 341 | return PTR_ERR(engine->sram); |
| 342 | |
| 343 | engine->sram_dma = phys_to_dma(cesa->dev, |
| 344 | (phys_addr_t)res->start); |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static void mv_cesa_put_sram(struct platform_device *pdev, int idx) |
| 350 | { |
| 351 | struct mv_cesa_dev *cesa = platform_get_drvdata(pdev); |
| 352 | struct mv_cesa_engine *engine = &cesa->engines[idx]; |
| 353 | |
| 354 | if (!engine->pool) |
| 355 | return; |
| 356 | |
| 357 | gen_pool_free(engine->pool, (unsigned long)engine->sram, |
| 358 | cesa->sram_size); |
| 359 | } |
| 360 | |
| 361 | static int mv_cesa_probe(struct platform_device *pdev) |
| 362 | { |
Boris BREZILLON | 0bf6948 | 2015-06-18 15:46:28 +0200 | [diff] [blame^] | 363 | const struct mv_cesa_caps *caps = &orion_caps; |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 364 | const struct mbus_dram_target_info *dram; |
| 365 | const struct of_device_id *match; |
| 366 | struct device *dev = &pdev->dev; |
| 367 | struct mv_cesa_dev *cesa; |
| 368 | struct mv_cesa_engine *engines; |
| 369 | struct resource *res; |
| 370 | int irq, ret, i; |
| 371 | u32 sram_size; |
| 372 | |
| 373 | if (cesa_dev) { |
| 374 | dev_err(&pdev->dev, "Only one CESA device authorized\n"); |
| 375 | return -EEXIST; |
| 376 | } |
| 377 | |
Boris BREZILLON | 0bf6948 | 2015-06-18 15:46:28 +0200 | [diff] [blame^] | 378 | if (dev->of_node) { |
| 379 | match = of_match_node(mv_cesa_of_match_table, dev->of_node); |
| 380 | if (!match || !match->data) |
| 381 | return -ENOTSUPP; |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 382 | |
Boris BREZILLON | 0bf6948 | 2015-06-18 15:46:28 +0200 | [diff] [blame^] | 383 | caps = match->data; |
| 384 | } |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 385 | |
Boris BREZILLON | 0bf6948 | 2015-06-18 15:46:28 +0200 | [diff] [blame^] | 386 | if (caps == &orion_caps && !allhwsupport) |
| 387 | return -ENOTSUPP; |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 388 | |
| 389 | cesa = devm_kzalloc(dev, sizeof(*cesa), GFP_KERNEL); |
| 390 | if (!cesa) |
| 391 | return -ENOMEM; |
| 392 | |
| 393 | cesa->caps = caps; |
| 394 | cesa->dev = dev; |
| 395 | |
| 396 | sram_size = CESA_SA_DEFAULT_SRAM_SIZE; |
| 397 | of_property_read_u32(cesa->dev->of_node, "marvell,crypto-sram-size", |
| 398 | &sram_size); |
| 399 | if (sram_size < CESA_SA_MIN_SRAM_SIZE) |
| 400 | sram_size = CESA_SA_MIN_SRAM_SIZE; |
| 401 | |
| 402 | cesa->sram_size = sram_size; |
| 403 | cesa->engines = devm_kzalloc(dev, caps->nengines * sizeof(*engines), |
| 404 | GFP_KERNEL); |
| 405 | if (!cesa->engines) |
| 406 | return -ENOMEM; |
| 407 | |
| 408 | spin_lock_init(&cesa->lock); |
| 409 | crypto_init_queue(&cesa->queue, 50); |
| 410 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); |
| 411 | cesa->regs = devm_ioremap_resource(dev, res); |
| 412 | if (IS_ERR(cesa->regs)) |
| 413 | return -ENOMEM; |
| 414 | |
Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 415 | ret = mv_cesa_dev_dma_init(cesa); |
| 416 | if (ret) |
| 417 | return ret; |
| 418 | |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 419 | dram = mv_mbus_dram_info_nooverlap(); |
| 420 | |
| 421 | platform_set_drvdata(pdev, cesa); |
| 422 | |
| 423 | for (i = 0; i < caps->nengines; i++) { |
| 424 | struct mv_cesa_engine *engine = &cesa->engines[i]; |
| 425 | char res_name[7]; |
| 426 | |
| 427 | engine->id = i; |
| 428 | spin_lock_init(&engine->lock); |
| 429 | |
| 430 | ret = mv_cesa_get_sram(pdev, i); |
| 431 | if (ret) |
| 432 | goto err_cleanup; |
| 433 | |
| 434 | irq = platform_get_irq(pdev, i); |
| 435 | if (irq < 0) { |
| 436 | ret = irq; |
| 437 | goto err_cleanup; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * Not all platforms can gate the CESA clocks: do not complain |
| 442 | * if the clock does not exist. |
| 443 | */ |
| 444 | snprintf(res_name, sizeof(res_name), "cesa%d", i); |
| 445 | engine->clk = devm_clk_get(dev, res_name); |
| 446 | if (IS_ERR(engine->clk)) { |
| 447 | engine->clk = devm_clk_get(dev, NULL); |
| 448 | if (IS_ERR(engine->clk)) |
| 449 | engine->clk = NULL; |
| 450 | } |
| 451 | |
| 452 | snprintf(res_name, sizeof(res_name), "cesaz%d", i); |
| 453 | engine->zclk = devm_clk_get(dev, res_name); |
| 454 | if (IS_ERR(engine->zclk)) |
| 455 | engine->zclk = NULL; |
| 456 | |
| 457 | ret = clk_prepare_enable(engine->clk); |
| 458 | if (ret) |
| 459 | goto err_cleanup; |
| 460 | |
| 461 | ret = clk_prepare_enable(engine->zclk); |
| 462 | if (ret) |
| 463 | goto err_cleanup; |
| 464 | |
| 465 | engine->regs = cesa->regs + CESA_ENGINE_OFF(i); |
| 466 | |
Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 467 | if (dram && cesa->caps->has_tdma) |
| 468 | mv_cesa_conf_mbus_windows(&cesa->engines[i], dram); |
| 469 | |
Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 470 | writel(0, cesa->engines[i].regs + CESA_SA_INT_STATUS); |
| 471 | writel(CESA_SA_CFG_STOP_DIG_ERR, |
| 472 | cesa->engines[i].regs + CESA_SA_CFG); |
| 473 | writel(engine->sram_dma & CESA_SA_SRAM_MSK, |
| 474 | cesa->engines[i].regs + CESA_SA_DESC_P0); |
| 475 | |
| 476 | ret = devm_request_threaded_irq(dev, irq, NULL, mv_cesa_int, |
| 477 | IRQF_ONESHOT, |
| 478 | dev_name(&pdev->dev), |
| 479 | &cesa->engines[i]); |
| 480 | if (ret) |
| 481 | goto err_cleanup; |
| 482 | } |
| 483 | |
| 484 | cesa_dev = cesa; |
| 485 | |
| 486 | ret = mv_cesa_add_algs(cesa); |
| 487 | if (ret) { |
| 488 | cesa_dev = NULL; |
| 489 | goto err_cleanup; |
| 490 | } |
| 491 | |
| 492 | dev_info(dev, "CESA device successfully registered\n"); |
| 493 | |
| 494 | return 0; |
| 495 | |
| 496 | err_cleanup: |
| 497 | for (i = 0; i < caps->nengines; i++) { |
| 498 | clk_disable_unprepare(cesa->engines[i].zclk); |
| 499 | clk_disable_unprepare(cesa->engines[i].clk); |
| 500 | mv_cesa_put_sram(pdev, i); |
| 501 | } |
| 502 | |
| 503 | return ret; |
| 504 | } |
| 505 | |
| 506 | static int mv_cesa_remove(struct platform_device *pdev) |
| 507 | { |
| 508 | struct mv_cesa_dev *cesa = platform_get_drvdata(pdev); |
| 509 | int i; |
| 510 | |
| 511 | mv_cesa_remove_algs(cesa); |
| 512 | |
| 513 | for (i = 0; i < cesa->caps->nengines; i++) { |
| 514 | clk_disable_unprepare(cesa->engines[i].zclk); |
| 515 | clk_disable_unprepare(cesa->engines[i].clk); |
| 516 | mv_cesa_put_sram(pdev, i); |
| 517 | } |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static struct platform_driver marvell_cesa = { |
| 523 | .probe = mv_cesa_probe, |
| 524 | .remove = mv_cesa_remove, |
| 525 | .driver = { |
| 526 | .owner = THIS_MODULE, |
| 527 | .name = "marvell-cesa", |
| 528 | .of_match_table = mv_cesa_of_match_table, |
| 529 | }, |
| 530 | }; |
| 531 | module_platform_driver(marvell_cesa); |
| 532 | |
| 533 | MODULE_ALIAS("platform:mv_crypto"); |
| 534 | MODULE_AUTHOR("Boris Brezillon <boris.brezillon@free-electrons.com>"); |
| 535 | MODULE_AUTHOR("Arnaud Ebalard <arno@natisbad.org>"); |
| 536 | MODULE_DESCRIPTION("Support for Marvell's cryptographic engine"); |
| 537 | MODULE_LICENSE("GPL v2"); |