uadk_engine/0079-cipher-uadk_e_bind_ciphers-function-is-optimized.patch
2023-11-29 16:35:32 +08:00

90 lines
2.2 KiB
Diff

From a3dffc15df2212ca8fa3161f82393048c3e9cbc5 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Sat, 25 Nov 2023 16:13:30 +0800
Subject: [PATCH 79/82] cipher: uadk_e_bind_ciphers function is optimized
The uadk_e_bind_ciphers function is executed only once,
however, the uadk_e_ciphers may be executed multiple times,
it is better to check whether the hardware is available
at the beginning of uadk_e_bind_ciphers.
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
src/uadk_cipher_adapter.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/src/uadk_cipher_adapter.c b/src/uadk_cipher_adapter.c
index 065575b..caf8af3 100644
--- a/src/uadk_cipher_adapter.c
+++ b/src/uadk_cipher_adapter.c
@@ -16,11 +16,10 @@
*/
#include "uadk_cipher_adapter.h"
-#define HW_UNINIT -1
-#define HW_SEC_V2 0
-#define HW_SEC_V3 1
+#define HW_SEC_V2 2
+#define HW_SEC_V3 3
-static int g_platform = HW_UNINIT;
+static int g_platform;
static int cipher_hw_v2_nids[] = {
NID_aes_128_cbc,
@@ -143,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)
{
- struct uacce_dev *dev;
__u32 i;
if (!e)
@@ -155,21 +153,6 @@ int uadk_e_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int 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"))
- g_platform = HW_SEC_V2;
- else
- g_platform = HW_SEC_V3;
-
- free(dev);
- }
-
if (cipher == NULL) {
if (g_platform == HW_SEC_V2) {
*nids = cipher_hw_v2_nids;
@@ -198,6 +181,21 @@ int uadk_e_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int n
int uadk_e_bind_ciphers(ENGINE *e)
{
+ struct uacce_dev *dev;
+
+ 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"))
+ g_platform = HW_SEC_V2;
+ else
+ g_platform = HW_SEC_V3;
+
+ free(dev);
+
return ENGINE_set_ciphers(e, uadk_e_ciphers);
}
--
2.25.1