uadk_engine/0059-uadk-fix-cipher-switchover-to-software-calculation-f.patch
2023-11-21 11:24:33 +08:00

85 lines
2.2 KiB
Diff

From f8c8181e68dfa14360aaaa2feff24779fc03ce76 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Thu, 9 Nov 2023 11:23:41 +0800
Subject: [PATCH 59/63] uadk: fix cipher switchover to software calculation
fails
In the multi-thread scenario, if the hardware is faulty
and the get_dev return is empty, the uadk engine should
continue to complete registration instead of returning.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
src/uadk_cipher_adapter.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/src/uadk_cipher_adapter.c b/src/uadk_cipher_adapter.c
index c915df8..2c4ed15 100644
--- a/src/uadk_cipher_adapter.c
+++ b/src/uadk_cipher_adapter.c
@@ -16,9 +16,11 @@
*/
#include "uadk_cipher_adapter.h"
-#define HW_SEC_V2 0
-#define HW_SEC_V3 1
-#define OTHERS_HW 2
+#define HW_UNINIT -1
+#define HW_SEC_V2 0
+#define HW_SEC_V3 1
+
+static int g_platform = HW_UNINIT;
static int cipher_hw_v2_nids[] = {
NID_aes_128_cbc,
@@ -140,7 +142,6 @@ static void uadk_e_create_ciphers(int index)
int uadk_e_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid)
{
- int platform = OTHERS_HW;
struct uacce_dev *dev;
__u32 i;
@@ -153,24 +154,26 @@ int uadk_e_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int n
return 0;
}
- dev = wd_get_accel_dev("cipher");
- if (!dev) {
- fprintf(stderr, "no device available, switch to software!\n");
- return 0;
- }
+ if (g_platform == HW_UNINIT) {
+ dev = wd_get_accel_dev("cipher");
+ if (!dev) {
+ fprintf(stderr, "no device available, switch to software!\n");
+ return 0;
+ }
- if (!strcmp(dev->api, "hisi_qm_v2"))
- platform = HW_SEC_V2;
- else if (!strcmp(dev->api, "hisi_qm_v3"))
- platform = HW_SEC_V3;
+ if (!strcmp(dev->api, "hisi_qm_v2"))
+ g_platform = HW_SEC_V2;
+ else
+ g_platform = HW_SEC_V3;
- free(dev);
+ free(dev);
+ }
if (cipher == NULL) {
- if (platform == HW_SEC_V2) {
+ if (g_platform == HW_SEC_V2) {
*nids = cipher_hw_v2_nids;
return ARRAY_SIZE(cipher_hw_v2_nids);
- } else if (platform == HW_SEC_V3) {
+ } else if (g_platform == HW_SEC_V3) {
*nids = cipher_hw_v3_nids;
return ARRAY_SIZE(cipher_hw_v3_nids);
}
--
2.25.1