From: Qi Tao taoqi10@huawei.com
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); }