Lines Matching +full:dma +full:- +full:engine

1 // SPDX-License-Identifier: GPL-2.0+
6 #include "aspeed-hace.h"
7 #include <crypto/engine.h>
9 #include <linux/dma-mapping.h>
23 dev_info((d)->dev, "%s() " fmt, __func__, ##__VA_ARGS__)
26 dev_dbg((d)->dev, "%s() " fmt, __func__, ##__VA_ARGS__)
33 struct aspeed_engine_crypto *crypto_engine = &hace_dev->crypto_engine; in aspeed_hace_irq()
34 struct aspeed_engine_hash *hash_engine = &hace_dev->hash_engine; in aspeed_hace_irq()
43 if (hash_engine->flags & CRYPTO_FLAGS_BUSY) in aspeed_hace_irq()
44 tasklet_schedule(&hash_engine->done_task); in aspeed_hace_irq()
46 dev_warn(hace_dev->dev, "HASH no active requests.\n"); in aspeed_hace_irq()
50 if (crypto_engine->flags & CRYPTO_FLAGS_BUSY) in aspeed_hace_irq()
51 tasklet_schedule(&crypto_engine->done_task); in aspeed_hace_irq()
53 dev_warn(hace_dev->dev, "CRYPTO no active requests.\n"); in aspeed_hace_irq()
62 struct aspeed_engine_crypto *crypto_engine = &hace_dev->crypto_engine; in aspeed_hace_crypto_done_task()
64 crypto_engine->resume(hace_dev); in aspeed_hace_crypto_done_task()
70 struct aspeed_engine_hash *hash_engine = &hace_dev->hash_engine; in aspeed_hace_hash_done_task()
72 hash_engine->resume(hace_dev); in aspeed_hace_hash_done_task()
96 { .compatible = "aspeed,ast2500-hace", .data = (void *)5, },
97 { .compatible = "aspeed,ast2600-hace", .data = (void *)6, },
109 hace_dev = devm_kzalloc(&pdev->dev, sizeof(struct aspeed_hace_dev), in aspeed_hace_probe()
112 return -ENOMEM; in aspeed_hace_probe()
114 hace_dev_id = of_match_device(aspeed_hace_of_matches, &pdev->dev); in aspeed_hace_probe()
116 dev_err(&pdev->dev, "Failed to match hace dev id\n"); in aspeed_hace_probe()
117 return -EINVAL; in aspeed_hace_probe()
120 hace_dev->dev = &pdev->dev; in aspeed_hace_probe()
121 hace_dev->version = (unsigned long)hace_dev_id->data; in aspeed_hace_probe()
122 hash_engine = &hace_dev->hash_engine; in aspeed_hace_probe()
123 crypto_engine = &hace_dev->crypto_engine; in aspeed_hace_probe()
127 hace_dev->regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in aspeed_hace_probe()
128 if (IS_ERR(hace_dev->regs)) in aspeed_hace_probe()
129 return PTR_ERR(hace_dev->regs); in aspeed_hace_probe()
132 hace_dev->irq = platform_get_irq(pdev, 0); in aspeed_hace_probe()
133 if (hace_dev->irq < 0) in aspeed_hace_probe()
134 return -ENXIO; in aspeed_hace_probe()
136 rc = devm_request_irq(&pdev->dev, hace_dev->irq, aspeed_hace_irq, 0, in aspeed_hace_probe()
137 dev_name(&pdev->dev), hace_dev); in aspeed_hace_probe()
139 dev_err(&pdev->dev, "Failed to request interrupt\n"); in aspeed_hace_probe()
144 hace_dev->clk = devm_clk_get(&pdev->dev, NULL); in aspeed_hace_probe()
145 if (IS_ERR(hace_dev->clk)) { in aspeed_hace_probe()
146 dev_err(&pdev->dev, "Failed to get clk\n"); in aspeed_hace_probe()
147 return -ENODEV; in aspeed_hace_probe()
150 rc = clk_prepare_enable(hace_dev->clk); in aspeed_hace_probe()
152 dev_err(&pdev->dev, "Failed to enable clock 0x%x\n", rc); in aspeed_hace_probe()
156 /* Initialize crypto hardware engine structure for hash */ in aspeed_hace_probe()
157 hace_dev->crypt_engine_hash = crypto_engine_alloc_init(hace_dev->dev, in aspeed_hace_probe()
159 if (!hace_dev->crypt_engine_hash) { in aspeed_hace_probe()
160 rc = -ENOMEM; in aspeed_hace_probe()
164 rc = crypto_engine_start(hace_dev->crypt_engine_hash); in aspeed_hace_probe()
168 tasklet_init(&hash_engine->done_task, aspeed_hace_hash_done_task, in aspeed_hace_probe()
171 /* Initialize crypto hardware engine structure for crypto */ in aspeed_hace_probe()
172 hace_dev->crypt_engine_crypto = crypto_engine_alloc_init(hace_dev->dev, in aspeed_hace_probe()
174 if (!hace_dev->crypt_engine_crypto) { in aspeed_hace_probe()
175 rc = -ENOMEM; in aspeed_hace_probe()
179 rc = crypto_engine_start(hace_dev->crypt_engine_crypto); in aspeed_hace_probe()
183 tasklet_init(&crypto_engine->done_task, aspeed_hace_crypto_done_task, in aspeed_hace_probe()
186 /* Allocate DMA buffer for hash engine input used */ in aspeed_hace_probe()
187 hash_engine->ahash_src_addr = in aspeed_hace_probe()
188 dmam_alloc_coherent(&pdev->dev, in aspeed_hace_probe()
190 &hash_engine->ahash_src_dma_addr, in aspeed_hace_probe()
192 if (!hash_engine->ahash_src_addr) { in aspeed_hace_probe()
193 dev_err(&pdev->dev, "Failed to allocate dma buffer\n"); in aspeed_hace_probe()
194 rc = -ENOMEM; in aspeed_hace_probe()
198 /* Allocate DMA buffer for crypto engine context used */ in aspeed_hace_probe()
199 crypto_engine->cipher_ctx = in aspeed_hace_probe()
200 dmam_alloc_coherent(&pdev->dev, in aspeed_hace_probe()
202 &crypto_engine->cipher_ctx_dma, in aspeed_hace_probe()
204 if (!crypto_engine->cipher_ctx) { in aspeed_hace_probe()
205 dev_err(&pdev->dev, "Failed to allocate cipher ctx dma\n"); in aspeed_hace_probe()
206 rc = -ENOMEM; in aspeed_hace_probe()
210 /* Allocate DMA buffer for crypto engine input used */ in aspeed_hace_probe()
211 crypto_engine->cipher_addr = in aspeed_hace_probe()
212 dmam_alloc_coherent(&pdev->dev, in aspeed_hace_probe()
214 &crypto_engine->cipher_dma_addr, in aspeed_hace_probe()
216 if (!crypto_engine->cipher_addr) { in aspeed_hace_probe()
217 dev_err(&pdev->dev, "Failed to allocate cipher addr dma\n"); in aspeed_hace_probe()
218 rc = -ENOMEM; in aspeed_hace_probe()
222 /* Allocate DMA buffer for crypto engine output used */ in aspeed_hace_probe()
223 if (hace_dev->version == AST2600_VERSION) { in aspeed_hace_probe()
224 crypto_engine->dst_sg_addr = in aspeed_hace_probe()
225 dmam_alloc_coherent(&pdev->dev, in aspeed_hace_probe()
227 &crypto_engine->dst_sg_dma_addr, in aspeed_hace_probe()
229 if (!crypto_engine->dst_sg_addr) { in aspeed_hace_probe()
230 dev_err(&pdev->dev, "Failed to allocate dst_sg dma\n"); in aspeed_hace_probe()
231 rc = -ENOMEM; in aspeed_hace_probe()
238 dev_info(&pdev->dev, "Aspeed Crypto Accelerator successfully registered\n"); in aspeed_hace_probe()
243 crypto_engine_exit(hace_dev->crypt_engine_crypto); in aspeed_hace_probe()
245 crypto_engine_exit(hace_dev->crypt_engine_hash); in aspeed_hace_probe()
247 clk_disable_unprepare(hace_dev->clk); in aspeed_hace_probe()
255 struct aspeed_engine_crypto *crypto_engine = &hace_dev->crypto_engine; in aspeed_hace_remove()
256 struct aspeed_engine_hash *hash_engine = &hace_dev->hash_engine; in aspeed_hace_remove()
260 crypto_engine_exit(hace_dev->crypt_engine_hash); in aspeed_hace_remove()
261 crypto_engine_exit(hace_dev->crypt_engine_crypto); in aspeed_hace_remove()
263 tasklet_kill(&hash_engine->done_task); in aspeed_hace_remove()
264 tasklet_kill(&crypto_engine->done_task); in aspeed_hace_remove()
266 clk_disable_unprepare(hace_dev->clk); in aspeed_hace_remove()