Skip to content

Commit 5e3c716

Browse files
committed
uadk: wd_request_drv requests drv via alg_task_type
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>
1 parent 59b82af commit 5e3c716

File tree

11 files changed

+38
-24
lines changed

11 files changed

+38
-24
lines changed

include/wd_alg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ struct wd_alg_list {
125125
/**
126126
* wd_request_drv() - Apply for an algorithm driver.
127127
* @alg_name: task algorithm name.
128-
* @hw_mask: the flag of shield hardware device drivers.
128+
* @task_type: task_type required from user.
129129
*
130130
* Returns the applied algorithm driver, non means error.
131131
*/
132-
struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask);
132+
struct wd_alg_driver *wd_request_drv(const char *alg_name, int task_type);
133133
void wd_release_drv(struct wd_alg_driver *drv);
134134

135135
/**

include/wd_alg_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ enum alg_task_type {
4646
TASK_MIX = 0x0,
4747
TASK_HW,
4848
TASK_INSTR,
49+
TASK_CE,
50+
TASK_SVE,
4951
TASK_MAX_TYPE,
5052
};
5153

wd_aead.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int wd_aead_open_driver(void)
8888
return -WD_EINVAL;
8989
}
9090

91-
driver = wd_request_drv(alg_name, false);
91+
driver = wd_request_drv(alg_name, TASK_HW);
9292
if (!driver) {
9393
wd_aead_close_driver();
9494
WD_ERR("failed to get %s driver support\n", alg_name);

wd_alg.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "wd.h"
1414
#include "wd_alg.h"
15+
#include "wd_alg_common.h"
1516

1617
#define SYS_CLASS_DIR "/sys/class/uacce"
1718
#define SVA_FILE_NAME "flags"
@@ -273,34 +274,43 @@ void wd_disable_drv(struct wd_alg_driver *drv)
273274
pthread_mutex_unlock(&mutex);
274275
}
275276

276-
struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask)
277+
struct wd_alg_driver *wd_request_drv(const char *alg_name, int task_type)
277278
{
278279
struct wd_alg_list *head = &alg_list_head;
279280
struct wd_alg_list *pnext = head->next;
280281
struct wd_alg_list *select_node = NULL;
281282
struct wd_alg_driver *drv = NULL;
282283
int tmp_priority = -1;
284+
int calc_type;
283285

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

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

298-
if (!strcmp(alg_name, pnext->alg_name) && pnext->available &&
299-
pnext->drv->priority > tmp_priority) {
300-
tmp_priority = pnext->drv->priority;
301-
select_node = pnext;
302-
drv = pnext->drv;
296+
if ((task_type == TASK_HW && calc_type == UADK_ALG_HW) ||
297+
(task_type == TASK_CE && calc_type == UADK_ALG_CE_INSTR) ||
298+
(task_type == TASK_SVE && calc_type == UADK_ALG_SVE_INSTR)) {
299+
select_node = pnext;
300+
drv = pnext->drv;
301+
break;
302+
}
303+
304+
/* fallback drv should not be hw */
305+
if (task_type == TASK_INSTR &&
306+
calc_type != UADK_ALG_HW &&
307+
pnext->drv->priority > tmp_priority) {
308+
tmp_priority = pnext->drv->priority;
309+
select_node = pnext;
310+
drv = pnext->drv;
311+
}
303312
}
313+
304314
pnext = pnext->next;
305315
}
306316

wd_cipher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int wd_cipher_open_driver(void)
101101
return -WD_EINVAL;
102102
}
103103

104-
driver = wd_request_drv(alg_name, false);
104+
driver = wd_request_drv(alg_name, TASK_HW);
105105
if (!driver) {
106106
wd_cipher_close_driver();
107107
WD_ERR("failed to get %s driver support\n", alg_name);

wd_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static int wd_comp_open_driver(void)
8585
return -WD_EINVAL;
8686
}
8787

88-
driver = wd_request_drv(alg_name, false);
88+
driver = wd_request_drv(alg_name, TASK_HW);
8989
if (!driver) {
9090
wd_comp_close_driver();
9191
WD_ERR("failed to get %s driver support\n", alg_name);

wd_dh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int wd_dh_open_driver(void)
6868
return -WD_EINVAL;
6969
}
7070

71-
driver = wd_request_drv(alg_name, false);
71+
driver = wd_request_drv(alg_name, TASK_HW);
7272
if (!driver) {
7373
wd_dh_close_driver();
7474
WD_ERR("failed to get %s driver support\n", alg_name);

wd_digest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int wd_digest_open_driver(void)
9696
return -WD_EINVAL;
9797
}
9898

99-
driver = wd_request_drv(alg_name, false);
99+
driver = wd_request_drv(alg_name, TASK_HW);
100100
if (!driver) {
101101
wd_digest_close_driver();
102102
WD_ERR("failed to get %s driver support\n", alg_name);

wd_ecc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static int wd_ecc_open_driver(void)
122122
return -WD_EINVAL;
123123
}
124124

125-
driver = wd_request_drv(alg_name, false);
125+
driver = wd_request_drv(alg_name, TASK_HW);
126126
if (!driver) {
127127
wd_ecc_close_driver();
128128
WD_ERR("failed to get %s driver support\n", alg_name);

wd_rsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static int wd_rsa_open_driver(void)
107107
return -WD_EINVAL;
108108
}
109109

110-
driver = wd_request_drv(alg_name, false);
110+
driver = wd_request_drv(alg_name, TASK_HW);
111111
if (!driver) {
112112
wd_rsa_close_driver();
113113
WD_ERR("failed to get %s driver support!\n", alg_name);

wd_util.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,9 @@ struct wd_alg_driver *wd_alg_drv_bind(int task_type, char *alg_name)
22872287
/* Get alg driver and dev name */
22882288
switch (task_type) {
22892289
case TASK_INSTR:
2290-
drv = wd_request_drv(alg_name, true);
2290+
case TASK_CE:
2291+
case TASK_SVE:
2292+
drv = wd_request_drv(alg_name, task_type);
22912293
if (!drv) {
22922294
WD_ERR("no soft %s driver support\n", alg_name);
22932295
return NULL;
@@ -2297,15 +2299,15 @@ struct wd_alg_driver *wd_alg_drv_bind(int task_type, char *alg_name)
22972299
break;
22982300
case TASK_HW:
22992301
case TASK_MIX:
2300-
drv = wd_request_drv(alg_name, false);
2302+
drv = wd_request_drv(alg_name, TASK_HW);
23012303
if (!drv) {
23022304
WD_ERR("no HW %s driver support\n", alg_name);
23032305
return NULL;
23042306
}
23052307
set_driver = drv;
23062308
set_driver->fallback = 0;
23072309
if (task_type == TASK_MIX) {
2308-
drv = wd_request_drv(alg_name, true);
2310+
drv = wd_request_drv(alg_name, TASK_INSTR);
23092311
if (!drv) {
23102312
set_driver->fallback = 0;
23112313
WD_ERR("no soft %s driver support\n", alg_name);

0 commit comments

Comments
 (0)