Skip to content

Commit

Permalink
uadk: wd_request_drv requests drv via alg_task_type
Browse files Browse the repository at this point in the history
User want to choose sve or ce instruction explicitly,
so modify wd_request_drv to request drv via para
alg_task_type

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
  • Loading branch information
zhangfeigao committed Jan 4, 2024
1 parent 59b82af commit 5e3c716
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 24 deletions.
4 changes: 2 additions & 2 deletions include/wd_alg.h
Expand Up @@ -125,11 +125,11 @@ struct wd_alg_list {
/**
* wd_request_drv() - Apply for an algorithm driver.
* @alg_name: task algorithm name.
* @hw_mask: the flag of shield hardware device drivers.
* @task_type: task_type required from user.
*
* Returns the applied algorithm driver, non means error.
*/
struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask);
struct wd_alg_driver *wd_request_drv(const char *alg_name, int task_type);
void wd_release_drv(struct wd_alg_driver *drv);

/**
Expand Down
2 changes: 2 additions & 0 deletions include/wd_alg_common.h
Expand Up @@ -46,6 +46,8 @@ enum alg_task_type {
TASK_MIX = 0x0,
TASK_HW,
TASK_INSTR,
TASK_CE,
TASK_SVE,
TASK_MAX_TYPE,
};

Expand Down
2 changes: 1 addition & 1 deletion wd_aead.c
Expand Up @@ -88,7 +88,7 @@ static int wd_aead_open_driver(void)
return -WD_EINVAL;
}

driver = wd_request_drv(alg_name, false);
driver = wd_request_drv(alg_name, TASK_HW);
if (!driver) {
wd_aead_close_driver();
WD_ERR("failed to get %s driver support\n", alg_name);
Expand Down
34 changes: 22 additions & 12 deletions wd_alg.c
Expand Up @@ -12,6 +12,7 @@

#include "wd.h"
#include "wd_alg.h"
#include "wd_alg_common.h"

#define SYS_CLASS_DIR "/sys/class/uacce"
#define SVA_FILE_NAME "flags"
Expand Down Expand Up @@ -273,34 +274,43 @@ void wd_disable_drv(struct wd_alg_driver *drv)
pthread_mutex_unlock(&mutex);
}

struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask)
struct wd_alg_driver *wd_request_drv(const char *alg_name, int task_type)
{
struct wd_alg_list *head = &alg_list_head;
struct wd_alg_list *pnext = head->next;
struct wd_alg_list *select_node = NULL;
struct wd_alg_driver *drv = NULL;
int tmp_priority = -1;
int calc_type;

if (!pnext || !alg_name) {
WD_ERR("invalid: request alg param is error!\n");
return NULL;
}

/* Check the list to get an best driver */
pthread_mutex_lock(&mutex);
while (pnext) {
/* hw_mask true mean not to used hardware dev */
if (hw_mask && pnext->drv->calc_type == UADK_ALG_HW) {
pnext = pnext->next;
continue;
}
if (!strcmp(alg_name, pnext->alg_name) && pnext->available) {
calc_type = pnext->drv->calc_type;

if (!strcmp(alg_name, pnext->alg_name) && pnext->available &&
pnext->drv->priority > tmp_priority) {
tmp_priority = pnext->drv->priority;
select_node = pnext;
drv = pnext->drv;
if ((task_type == TASK_HW && calc_type == UADK_ALG_HW) ||
(task_type == TASK_CE && calc_type == UADK_ALG_CE_INSTR) ||
(task_type == TASK_SVE && calc_type == UADK_ALG_SVE_INSTR)) {
select_node = pnext;
drv = pnext->drv;
break;
}

/* fallback drv should not be hw */
if (task_type == TASK_INSTR &&
calc_type != UADK_ALG_HW &&
pnext->drv->priority > tmp_priority) {
tmp_priority = pnext->drv->priority;
select_node = pnext;
drv = pnext->drv;
}
}

pnext = pnext->next;
}

Expand Down
2 changes: 1 addition & 1 deletion wd_cipher.c
Expand Up @@ -101,7 +101,7 @@ static int wd_cipher_open_driver(void)
return -WD_EINVAL;
}

driver = wd_request_drv(alg_name, false);
driver = wd_request_drv(alg_name, TASK_HW);
if (!driver) {
wd_cipher_close_driver();
WD_ERR("failed to get %s driver support\n", alg_name);
Expand Down
2 changes: 1 addition & 1 deletion wd_comp.c
Expand Up @@ -85,7 +85,7 @@ static int wd_comp_open_driver(void)
return -WD_EINVAL;
}

driver = wd_request_drv(alg_name, false);
driver = wd_request_drv(alg_name, TASK_HW);
if (!driver) {
wd_comp_close_driver();
WD_ERR("failed to get %s driver support\n", alg_name);
Expand Down
2 changes: 1 addition & 1 deletion wd_dh.c
Expand Up @@ -68,7 +68,7 @@ static int wd_dh_open_driver(void)
return -WD_EINVAL;
}

driver = wd_request_drv(alg_name, false);
driver = wd_request_drv(alg_name, TASK_HW);
if (!driver) {
wd_dh_close_driver();
WD_ERR("failed to get %s driver support\n", alg_name);
Expand Down
2 changes: 1 addition & 1 deletion wd_digest.c
Expand Up @@ -96,7 +96,7 @@ static int wd_digest_open_driver(void)
return -WD_EINVAL;
}

driver = wd_request_drv(alg_name, false);
driver = wd_request_drv(alg_name, TASK_HW);
if (!driver) {
wd_digest_close_driver();
WD_ERR("failed to get %s driver support\n", alg_name);
Expand Down
2 changes: 1 addition & 1 deletion wd_ecc.c
Expand Up @@ -122,7 +122,7 @@ static int wd_ecc_open_driver(void)
return -WD_EINVAL;
}

driver = wd_request_drv(alg_name, false);
driver = wd_request_drv(alg_name, TASK_HW);
if (!driver) {
wd_ecc_close_driver();
WD_ERR("failed to get %s driver support\n", alg_name);
Expand Down
2 changes: 1 addition & 1 deletion wd_rsa.c
Expand Up @@ -107,7 +107,7 @@ static int wd_rsa_open_driver(void)
return -WD_EINVAL;
}

driver = wd_request_drv(alg_name, false);
driver = wd_request_drv(alg_name, TASK_HW);
if (!driver) {
wd_rsa_close_driver();
WD_ERR("failed to get %s driver support!\n", alg_name);
Expand Down
8 changes: 5 additions & 3 deletions wd_util.c
Expand Up @@ -2287,7 +2287,9 @@ struct wd_alg_driver *wd_alg_drv_bind(int task_type, char *alg_name)
/* Get alg driver and dev name */
switch (task_type) {
case TASK_INSTR:
drv = wd_request_drv(alg_name, true);
case TASK_CE:
case TASK_SVE:
drv = wd_request_drv(alg_name, task_type);
if (!drv) {
WD_ERR("no soft %s driver support\n", alg_name);
return NULL;
Expand All @@ -2297,15 +2299,15 @@ struct wd_alg_driver *wd_alg_drv_bind(int task_type, char *alg_name)
break;
case TASK_HW:
case TASK_MIX:
drv = wd_request_drv(alg_name, false);
drv = wd_request_drv(alg_name, TASK_HW);
if (!drv) {
WD_ERR("no HW %s driver support\n", alg_name);
return NULL;
}
set_driver = drv;
set_driver->fallback = 0;
if (task_type == TASK_MIX) {
drv = wd_request_drv(alg_name, true);
drv = wd_request_drv(alg_name, TASK_INSTR);
if (!drv) {
set_driver->fallback = 0;
WD_ERR("no soft %s driver support\n", alg_name);
Expand Down

0 comments on commit 5e3c716

Please sign in to comment.