[][openwrt][mt7988][crypto][Add timer for DDK interrupt]
[Description]
Add timer for DDK interrupt.
In DDK, we use PEC_ResultNotify_Request() to invoke packet-coalescing
interrupts. However, there are no time-coalescing in EIP. If the packet
number for invoking interrupt is too small, performance is not good. Too
high then connection with only few packets will disconnected. So, we add
a timer to make a balance between them.
[Release-log]
N/A
Change-Id: I3513b33dea454289b5b3f04b19aa51112c51501d
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/9516358
diff --git a/feed/kernel/crypto-eip/src/ddk-wrapper.c b/feed/kernel/crypto-eip/src/ddk-wrapper.c
index 0c04798..a0559db 100644
--- a/feed/kernel/crypto-eip/src/ddk-wrapper.c
+++ b/feed/kernel/crypto-eip/src/ddk-wrapper.c
@@ -11,6 +11,7 @@
#include <crypto/hmac.h>
#include <crypto/md5.h>
#include <linux/delay.h>
+#include <linux/jiffies.h>
#include <crypto/internal/hash.h>
#include <crypto-eip/ddk/slad/api_pcl.h>
@@ -439,6 +440,22 @@
mtk_crypto_ring3_handler
};
+void mtk_crypto_req_expired_timer(struct timer_list *t)
+{
+ struct mtk_crypto_cipher_ctx *ctx = from_timer(ctx, t, poll_timer);
+ PEC_NotifyFunction_t CBFunc;
+ int ring = ctx->base.ring;
+ int rc;
+
+ del_timer(&ctx->poll_timer);
+ ctx->poll_timer.expires = 0;
+
+ CBFunc = mtk_crypto_interrupt_handler[ring];
+ rc = PEC_ResultNotify_Request(ring, CBFunc, 1);
+ if (rc != PEC_STATUS_OK)
+ CRYPTO_ERR("PEC_ResultNotify_Request failed with rc = %d\n", rc);
+}
+
int mtk_crypto_ddk_alloc_buff(struct mtk_crypto_cipher_ctx *ctx, int dir, unsigned int digestsize,
struct mtk_crypto_engine_data *data)
{
@@ -876,15 +893,25 @@
result->eip.pkt_handle = SrcSGListHandle.p;
result->async = async;
result->dst = DstSGListHandle.p;
+ CBFunc = mtk_crypto_interrupt_handler[ring];
spin_lock_bh(&priv->mtk_eip_ring[ring].ring_lock);
list_add_tail(&result->list, &priv->mtk_eip_ring[ring].list);
spin_unlock_bh(&priv->mtk_eip_ring[ring].ring_lock);
- CBFunc = mtk_crypto_interrupt_handler[ring];
- rc = PEC_ResultNotify_Request(ring, CBFunc, 1);
- if (rc != PEC_STATUS_OK) {
- CRYPTO_ERR("PEC_ResultNotify_Request failed with rc = %d\n", rc);
- goto error_remove_sg;
+
+ if (ctx->poll_timer.expires == 0) {
+ ctx->poll_timer.expires = jiffies + (2 * HZ / 1000);
+ add_timer(&ctx->poll_timer);
+ }
+
+ if ((atomic_inc_return(&ctx->base.req_count) % REQ_PKT_NUM) == 0) {
+ del_timer(&ctx->poll_timer);
+ ctx->poll_timer.expires = 0;
+ rc = PEC_ResultNotify_Request(ring, CBFunc, 1);
+ if (rc != PEC_STATUS_OK) {
+ CRYPTO_ERR("PEC_ResultNotify_Request failed with rc = %d\n", rc);
+ goto error_remove_sg;
+ }
}
return rc;
diff --git a/feed/kernel/crypto-eip/src/inc/crypto-eip/crypto-eip.h b/feed/kernel/crypto-eip/src/inc/crypto-eip/crypto-eip.h
index 7d5d21a..9286b6e 100644
--- a/feed/kernel/crypto-eip/src/inc/crypto-eip/crypto-eip.h
+++ b/feed/kernel/crypto-eip/src/inc/crypto-eip/crypto-eip.h
@@ -12,6 +12,7 @@
#include <crypto/sha.h>
#include <linux/io.h>
#include <linux/list.h>
+#include <linux/timer.h>
#include <net/xfrm.h>
#include "crypto-eip/crypto-eip197-inline-ddk.h"
diff --git a/feed/kernel/crypto-eip/src/inc/crypto-eip/ddk-wrapper.h b/feed/kernel/crypto-eip/src/inc/crypto-eip/ddk-wrapper.h
index 99f33ba..f6240e6 100644
--- a/feed/kernel/crypto-eip/src/inc/crypto-eip/ddk-wrapper.h
+++ b/feed/kernel/crypto-eip/src/inc/crypto-eip/ddk-wrapper.h
@@ -13,6 +13,8 @@
#include "lookaside.h"
#include "crypto-eip197-inline-ddk.h"
+#define REQ_PKT_NUM 10
+
u32 *mtk_ddk_tr_ipsec_build(struct mtk_xfrm_params *xfrm_params, u32 ipsec_mod);
int mtk_crypto_ddk_alloc_buff(struct mtk_crypto_cipher_ctx *ctx, int dir, unsigned int digestsize,
struct mtk_crypto_engine_data *data);
@@ -40,6 +42,7 @@
void crypto_free_token(void *token);
void crypto_free_pkt(void *pkt);
void crypto_free_sglist(void *sglist);
+void mtk_crypto_req_expired_timer(struct timer_list *t);
void *mtk_ddk_tr_capwap_dtls_build(const bool capwap,
struct DTLS_param *DTLSParam_p, u32 dir);
diff --git a/feed/kernel/crypto-eip/src/inc/crypto-eip/lookaside.h b/feed/kernel/crypto-eip/src/inc/crypto-eip/lookaside.h
index 11ac275..d4ab7dd 100644
--- a/feed/kernel/crypto-eip/src/inc/crypto-eip/lookaside.h
+++ b/feed/kernel/crypto-eip/src/inc/crypto-eip/lookaside.h
@@ -142,6 +142,7 @@
int (*send)(struct crypto_async_request *req);
int (*handle_result)(struct mtk_crypto_result *req, int err);
int ring;
+ atomic_t req_count;
};
enum mtk_crypto_cipher_direction {
@@ -206,6 +207,8 @@
struct crypto_cipher *hkaes;
struct crypto_aead *fback;
+ struct timer_list poll_timer;
+
struct mtk_crypto_engine_data enc;
struct mtk_crypto_engine_data dec;
};
diff --git a/feed/kernel/crypto-eip/src/lookaside-cipher.c b/feed/kernel/crypto-eip/src/lookaside-cipher.c
index 7527d44..6d8ddc9 100644
--- a/feed/kernel/crypto-eip/src/lookaside-cipher.c
+++ b/feed/kernel/crypto-eip/src/lookaside-cipher.c
@@ -156,6 +156,9 @@
ctx->base.ring = -1;
ctx->enc.valid = 0;
ctx->dec.valid = 0;
+
+ timer_setup(&ctx->poll_timer, mtk_crypto_req_expired_timer, 0);
+
return 0;
}
@@ -669,6 +672,9 @@
ctx->base.ring = -1;
ctx->enc.valid = 0;
ctx->dec.valid = 0;
+
+ timer_setup(&ctx->poll_timer, mtk_crypto_req_expired_timer, 0);
+
return 0;
}