developer | ebe38fd | 2024-03-22 14:36:06 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (C) 2023 MediaTek Inc. |
| 4 | * |
| 5 | * Author: Chris.Chou <chris.chou@mediatek.com> |
| 6 | * Ren-Ting Wang <ren-ting.wang@mediatek.com> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/bitops.h> |
| 10 | #include <crypto/aes.h> |
| 11 | #include <crypto/internal/skcipher.h> |
| 12 | |
| 13 | #include "crypto-eip/crypto-eip.h" |
| 14 | #include "crypto-eip/ddk-wrapper.h" |
| 15 | #include "crypto-eip/lookaside.h" |
| 16 | #include "crypto-eip/internal.h" |
| 17 | |
developer | b3c41cd | 2024-06-04 17:52:08 +0800 | [diff] [blame] | 18 | inline int mtk_crypto_select_ring(struct mtk_crypto_priv *priv) |
| 19 | { |
| 20 | return (atomic_inc_return(&priv->ring_used) % PEC_MAX_INTERFACE_NUM); |
| 21 | } |
| 22 | |
| 23 | void mtk_crypto_dequeue(struct mtk_crypto_priv *priv, int ring) |
developer | ebe38fd | 2024-03-22 14:36:06 +0800 | [diff] [blame] | 24 | { |
| 25 | struct crypto_async_request *req; |
| 26 | struct crypto_async_request *backlog; |
| 27 | struct mtk_crypto_context *ctx; |
| 28 | int ret; |
| 29 | |
| 30 | while (true) { |
developer | b3c41cd | 2024-06-04 17:52:08 +0800 | [diff] [blame] | 31 | spin_lock_bh(&priv->mtk_eip_ring[ring].queue_lock); |
| 32 | backlog = crypto_get_backlog(&priv->mtk_eip_ring[ring].queue); |
| 33 | req = crypto_dequeue_request(&priv->mtk_eip_ring[ring].queue); |
| 34 | spin_unlock_bh(&priv->mtk_eip_ring[ring].queue_lock); |
developer | ebe38fd | 2024-03-22 14:36:06 +0800 | [diff] [blame] | 35 | |
| 36 | if (!req) |
| 37 | goto finalize; |
| 38 | |
| 39 | ctx = crypto_tfm_ctx(req->tfm); |
| 40 | ret = ctx->send(req); |
| 41 | if (ret) |
| 42 | goto finalize; |
| 43 | |
| 44 | if (backlog) |
| 45 | backlog->complete(backlog, -EINPROGRESS); |
| 46 | } |
| 47 | |
| 48 | finalize: |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | void mtk_crypto_dequeue_work(struct work_struct *work) |
| 53 | { |
| 54 | struct mtk_crypto_work_data *data = |
| 55 | container_of(work, struct mtk_crypto_work_data, work); |
developer | b3c41cd | 2024-06-04 17:52:08 +0800 | [diff] [blame] | 56 | mtk_crypto_dequeue(data->priv, data->ring); |
developer | ebe38fd | 2024-03-22 14:36:06 +0800 | [diff] [blame] | 57 | } |