crypto: hisilicon/qm - add debugfs to the QM state machine
authorLongfang Liu <liulongfang@huawei.com>
Fri, 15 May 2020 09:13:55 +0000 (17:13 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 22 May 2020 14:08:21 +0000 (00:08 +1000)
The QM driver uses debugfs to provides the current state of
the QM state machine

Signed-off-by: Longfang Liu <liulongfang@huawei.com>
Signed-off-by: Shukun Tan <tanshukun1@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Documentation/ABI/testing/debugfs-hisi-hpre
Documentation/ABI/testing/debugfs-hisi-sec
Documentation/ABI/testing/debugfs-hisi-zip
drivers/crypto/hisilicon/qm.c

index 1f966654c1770d7c84c7909e792c5bbd8b45e571..093cf46a4e29c81e425c41125c7aeccfe10e87a4 100644 (file)
@@ -86,3 +86,10 @@ Date:           Apr 2020
 Contact:        linux-crypto@vger.kernel.org
 Description:    Dump the number of failed QM mailbox commands.
                Available for both PF and VF, and take no other effect on HPRE.
+
+What:           /sys/kernel/debug/hisi_hpre/<bdf>/qm/status
+Date:           Apr 2020
+Contact:        linux-crypto@vger.kernel.org
+Description:    Dump the status of the QM.
+               Four states: initiated, started, stopped and closed.
+               Available for both PF and VF, and take no other effect on HPRE.
index c3ba09cf0b3ee6c2280f6b9d6699dae6d4fadc32..54699a1ac9b0452aa1a49f6217914dbf612bfa07 100644 (file)
@@ -72,3 +72,10 @@ Date:           Apr 2020
 Contact:        linux-crypto@vger.kernel.org
 Description:    Dump the number of failed QM mailbox commands.
                Available for both PF and VF, and take no other effect on SEC.
+
+What:           /sys/kernel/debug/hisi_sec2/<bdf>/qm/status
+Date:           Apr 2020
+Contact:        linux-crypto@vger.kernel.org
+Description:    Dump the status of the QM.
+               Four states: initiated, started, stopped and closed.
+               Available for both PF and VF, and take no other effect on SEC.
index cc568fde8ff700148b7d655b175340daf0591edc..1002a01e6342d579664c010091ccdbbaa57b1b5a 100644 (file)
@@ -79,3 +79,10 @@ Date:           Apr 2020
 Contact:        linux-crypto@vger.kernel.org
 Description:    Dump the number of failed QM mailbox commands.
                Available for both PF and VF, and take no other effect on ZIP.
+
+What:           /sys/kernel/debug/hisi_zip/<bdf>/qm/status
+Date:           Apr 2020
+Contact:        linux-crypto@vger.kernel.org
+Description:    Dump the status of the QM.
+               Four states: initiated, started, stopped and closed.
+               Available for both PF and VF, and take no other effect on ZIP.
index 744d1310f6a9cf798ca56555abb94e7e7108a9ea..7c1982fd215611d3fa026feea089bcea5863b160 100644 (file)
 #define QM_SQE_DATA_ALIGN_MASK         GENMASK(6, 0)
 #define QMC_ALIGN(sz)                  ALIGN(sz, 32)
 
+#define QM_DBG_READ_LEN                256
 #define QM_DBG_TMP_BUF_LEN             22
 #define QM_PCI_COMMAND_INVALID         ~0
 
@@ -2268,6 +2269,37 @@ err_unlock:
 }
 EXPORT_SYMBOL_GPL(hisi_qm_stop);
 
+static ssize_t qm_status_read(struct file *filp, char __user *buffer,
+                             size_t count, loff_t *pos)
+{
+       struct hisi_qm *qm = filp->private_data;
+       char buf[QM_DBG_READ_LEN];
+       int val, cp_len, len;
+
+       if (*pos)
+               return 0;
+
+       if (count < QM_DBG_READ_LEN)
+               return -ENOSPC;
+
+       val = atomic_read(&qm->status.flags);
+       len = snprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
+       if (!len)
+               return -EFAULT;
+
+       cp_len = copy_to_user(buffer, buf, len);
+       if (cp_len)
+               return -EFAULT;
+
+       return (*pos = len);
+}
+
+static const struct file_operations qm_status_fops = {
+       .owner = THIS_MODULE,
+       .open = simple_open,
+       .read = qm_status_read,
+};
+
 static int qm_debugfs_atomic64_set(void *data, u64 val)
 {
        if (val)
@@ -2314,6 +2346,8 @@ int hisi_qm_debug_init(struct hisi_qm *qm)
 
        debugfs_create_file("qm_regs", 0444, qm->debug.qm_d, qm, &qm_regs_fops);
 
+       debugfs_create_file("status", 0444, qm->debug.qm_d, qm,
+                       &qm_status_fops);
        for (i = 0; i < ARRAY_SIZE(qm_dfx_files); i++) {
                data = (atomic64_t *)((uintptr_t)dfx + qm_dfx_files[i].offset);
                debugfs_create_file(qm_dfx_files[i].name,