crypto: hisilicon/qm - check function qp num before alg register

When the Kunpeng accelerator executes tasks such as encryption
and decryption have minimum requirements on the number of device
queues. If the number of queues does not meet the requirement,
the process initialization will fail. Therefore, the driver checks
the number of queues on the device before registering the algorithm.
If the number does not meet the requirements, the driver does not register
the algorithm to crypto subsystem, the device is still added to the
qm_list.

Signed-off-by: Weili Qian <qianweili@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Weili Qian
2023-09-28 17:21:47 +08:00
committed by Herbert Xu
parent ff3ddca9ca
commit b42ab1c61a
8 changed files with 134 additions and 63 deletions

View File

@@ -104,6 +104,9 @@
#define IV_CTR_INIT 0x1
#define IV_BYTE_OFFSET 0x8
static DEFINE_MUTEX(sec_algs_lock);
static unsigned int sec_available_devs;
struct sec_skcipher {
u64 alg_msk;
struct skcipher_alg alg;
@@ -2545,16 +2548,31 @@ err:
int sec_register_to_crypto(struct hisi_qm *qm)
{
u64 alg_mask = sec_get_alg_bitmap(qm, SEC_DRV_ALG_BITMAP_HIGH, SEC_DRV_ALG_BITMAP_LOW);
int ret;
int ret = 0;
mutex_lock(&sec_algs_lock);
if (sec_available_devs) {
sec_available_devs++;
goto unlock;
}
ret = sec_register_skcipher(alg_mask);
if (ret)
return ret;
goto unlock;
ret = sec_register_aead(alg_mask);
if (ret)
sec_unregister_skcipher(alg_mask, ARRAY_SIZE(sec_skciphers));
goto unreg_skcipher;
sec_available_devs++;
mutex_unlock(&sec_algs_lock);
return 0;
unreg_skcipher:
sec_unregister_skcipher(alg_mask, ARRAY_SIZE(sec_skciphers));
unlock:
mutex_unlock(&sec_algs_lock);
return ret;
}
@@ -2562,6 +2580,13 @@ void sec_unregister_from_crypto(struct hisi_qm *qm)
{
u64 alg_mask = sec_get_alg_bitmap(qm, SEC_DRV_ALG_BITMAP_HIGH, SEC_DRV_ALG_BITMAP_LOW);
mutex_lock(&sec_algs_lock);
if (--sec_available_devs)
goto unlock;
sec_unregister_aead(alg_mask, ARRAY_SIZE(sec_aeads));
sec_unregister_skcipher(alg_mask, ARRAY_SIZE(sec_skciphers));
unlock:
mutex_unlock(&sec_algs_lock);
}