blob: fe2cb1541a9b27e5ef3eb91fbb25039cced91ca3 [file] [log] [blame]
developerebe38fd2024-03-22 14:36:06 +08001// 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
developerb3c41cd2024-06-04 17:52:08 +080018inline 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
23void mtk_crypto_dequeue(struct mtk_crypto_priv *priv, int ring)
developerebe38fd2024-03-22 14:36:06 +080024{
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) {
developerb3c41cd2024-06-04 17:52:08 +080031 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);
developerebe38fd2024-03-22 14:36:06 +080035
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
48finalize:
49 return;
50}
51
52void 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);
developerb3c41cd2024-06-04 17:52:08 +080056 mtk_crypto_dequeue(data->priv, data->ring);
developerebe38fd2024-03-22 14:36:06 +080057}