[PATCH 2/4] crypto: hisilicon/qm - return error for abnormal device capability version
From: Weili Qian
Date: Thu Sep 24 2026 - 07:43:04 EST
When the device is abnormal, QM_FUNC_CAPS_REG returns 0xffffffff and
cap_ver becomes 0xff, but the driver continues with an invalid version.
Read the register unconditionally and return -EIO when cap_ver equals
QM_CAPBILITY_VERSION, indicating an abnormal device.
Fixes: 82f00b24f532 ("crypto: hisilicon/qm - get hardware features from hardware registers")
Signed-off-by: Weili Qian <qianweili@xxxxxxxxxx>
---
drivers/crypto/hisilicon/qm.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index 4f555912f5fc..bde44401ddb6 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -5770,9 +5770,19 @@ static int qm_get_hw_caps(struct hisi_qm *qm)
if (val)
set_bit(QM_SUPPORT_DB_ISOLATION, &qm->caps);
- if (qm->ver >= QM_HW_V3) {
- val = readl(qm->io_base + QM_FUNC_CAPS_REG);
- qm->cap_ver = val & QM_CAPBILITY_VERSION;
+ /*
+ * Read capability version from hardware register unconditionally.
+ * For V1/V2 hardware, this register is not implemented and returns 0
+ * in normal condition, but returns 0xffffffff when the device is
+ * abnormal, same as V3+ abnormal devices.
+ * When cap_ver equals QM_CAPBILITY_VERSION (0xff), the device is
+ * abnormal and probe should fail early.
+ */
+ val = readl(qm->io_base + QM_FUNC_CAPS_REG);
+ qm->cap_ver = val & QM_CAPBILITY_VERSION;
+ if (qm->cap_ver == QM_CAPBILITY_VERSION) {
+ dev_err(&qm->pdev->dev, "abnormal device detected\n");
+ return -EIO;
}
/* Get PF/VF common capbility */
--
2.43.0