From 9453dd339c43df967cff11f92f270de6f48615a1 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:08 +0800
Subject: [PATCH 134/183] rsa: remove repeated send BD

If -WD_EBUSY is returned When BD is sent, the app
determines whether to resend the BD. The function wd_do_rsa_sync
and wd_do_rsa_async does not try to resend the BD.

Signed-off-by: Weili Qian <qianweili@huawei.com>
---
 wd_rsa.c | 37 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)

diff --git a/wd_rsa.c b/wd_rsa.c
index 836c8ae..024f0e0 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -20,7 +20,6 @@
 #define WD_HW_EACCESS			62
 
 #define RSA_BALANCE_THRHD		1280
-#define RSA_RESEND_CNT	8
 #define RSA_MAX_KEY_SIZE		512
 #define RSA_RECV_MAX_CNT		60000000 // 1 min
 
@@ -252,28 +251,6 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req,
 	return 0;
 }
 
-static int rsa_send(handle_t ctx, struct wd_rsa_msg *msg)
-{
-	__u32 tx_cnt = 0;
-	int ret;
-
-	do {
-		ret = wd_rsa_setting.driver->send(ctx, msg);
-		if (ret == -WD_EBUSY) {
-			if (tx_cnt++ >= RSA_RESEND_CNT) {
-				WD_ERR("failed to send: retry exit!\n");
-				break;
-			}
-			usleep(1);
-		} else if (ret < 0) {
-			WD_ERR("failed to send: send error = %d!\n", ret);
-			break;
-		}
-	} while (ret);
-
-	return ret;
-}
-
 static int rsa_recv_sync(handle_t ctx, struct wd_rsa_msg *msg)
 {
 	struct wd_rsa_req *req = &msg->req;
@@ -339,9 +316,11 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req)
 		return ret;
 
 	pthread_spin_lock(&ctx->lock);
-	ret = rsa_send(ctx->ctx, &msg);
-	if (unlikely(ret))
+	ret = wd_rsa_setting.driver->send(ctx->ctx, &msg);
+	if (unlikely(ret < 0)) {
+		WD_ERR("failed to send rsa BD, ret = %d!\n", ret);
 		goto fail;
+	}
 
 	ret = rsa_recv_sync(ctx->ctx, &msg);
 fail:
@@ -383,9 +362,13 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
 		goto fail_with_msg;
 	msg->tag = mid;
 
-	ret = rsa_send(ctx->ctx, msg);
-	if (ret)
+	ret = wd_rsa_setting.driver->send(ctx->ctx, msg);
+	if (unlikely(ret)) {
+		if (ret != -WD_EBUSY)
+			WD_ERR("failed to send rsa BD, hw is err!\n");
+
 		goto fail_with_msg;
+	}
 
 	ret = wd_add_task_to_async_queue(&wd_rsa_env_config, idx);
 	if (ret)
-- 
2.27.0

