dmanegine: idxd: add debugfs for event log dump
authorDave Jiang <dave.jiang@intel.com>
Fri, 7 Apr 2023 20:31:32 +0000 (13:31 -0700)
committerVinod Koul <vkoul@kernel.org>
Wed, 12 Apr 2023 17:48:45 +0000 (23:18 +0530)
Add debugfs entry to dump the content of the event log for debugging. The
function will dump all non-zero entries in the event log. It will note
which entries are processed and which entries are still pending processing
at the time of the dump. The entries may not always be in chronological
order due to the log is a circular buffer.

Tested-by: Tony Zhu <tony.zhu@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Link: https://lore.kernel.org/r/20230407203143.2189681-6-fenghua.yu@intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/idxd/Makefile
drivers/dma/idxd/debugfs.c [new file with mode: 0644]
drivers/dma/idxd/idxd.h
drivers/dma/idxd/init.c
include/uapi/linux/idxd.h

index a1e9f2b3a37ccac9c78e3bd5cc3e52e96a0982a9..dc096839ac63749e36665e248e356700559f417e 100644 (file)
@@ -1,7 +1,7 @@
 ccflags-y += -DDEFAULT_SYMBOL_NAMESPACE=IDXD
 
 obj-$(CONFIG_INTEL_IDXD) += idxd.o
-idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o
+idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o
 
 idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.o
 
diff --git a/drivers/dma/idxd/debugfs.c b/drivers/dma/idxd/debugfs.c
new file mode 100644 (file)
index 0000000..9cfbd9b
--- /dev/null
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/debugfs.h>
+#include <linux/io-64-nonatomic-lo-hi.h>
+#include <uapi/linux/idxd.h>
+#include "idxd.h"
+#include "registers.h"
+
+static struct dentry *idxd_debugfs_dir;
+
+static void dump_event_entry(struct idxd_device *idxd, struct seq_file *s,
+                            u16 index, int *count, bool processed)
+{
+       struct idxd_evl *evl = idxd->evl;
+       struct dsa_evl_entry *entry;
+       struct dsa_completion_record *cr;
+       u64 *raw;
+       int i;
+       int evl_strides = evl_ent_size(idxd) / sizeof(u64);
+
+       entry = (struct dsa_evl_entry *)evl->log + index;
+
+       if (!entry->e.desc_valid)
+               return;
+
+       seq_printf(s, "Event Log entry %d (real index %u) processed: %u\n",
+                  *count, index, processed);
+
+       seq_printf(s, "desc valid %u wq idx valid %u\n"
+                  "batch %u fault rw %u priv %u error 0x%x\n"
+                  "wq idx %u op %#x pasid %u batch idx %u\n"
+                  "fault addr %#llx\n",
+                  entry->e.desc_valid, entry->e.wq_idx_valid,
+                  entry->e.batch, entry->e.fault_rw, entry->e.priv,
+                  entry->e.error, entry->e.wq_idx, entry->e.operation,
+                  entry->e.pasid, entry->e.batch_idx, entry->e.fault_addr);
+
+       cr = &entry->cr;
+       seq_printf(s, "status %#x result %#x fault_info %#x bytes_completed %u\n"
+                  "fault addr %#llx inv flags %#x\n\n",
+                  cr->status, cr->result, cr->fault_info, cr->bytes_completed,
+                  cr->fault_addr, cr->invalid_flags);
+
+       raw = (u64 *)entry;
+
+       for (i = 0; i < evl_strides; i++)
+               seq_printf(s, "entry[%d] = %#llx\n", i, raw[i]);
+
+       seq_puts(s, "\n");
+       *count += 1;
+}
+
+static int debugfs_evl_show(struct seq_file *s, void *d)
+{
+       struct idxd_device *idxd = s->private;
+       struct idxd_evl *evl = idxd->evl;
+       union evl_status_reg evl_status;
+       u16 h, t, evl_size, i;
+       int count = 0;
+       bool processed = true;
+
+       if (!evl || !evl->log)
+               return 0;
+
+       spin_lock(&evl->lock);
+
+       h = evl->head;
+       evl_status.bits = ioread64(idxd->reg_base + IDXD_EVLSTATUS_OFFSET);
+       t = evl_status.tail;
+       evl_size = evl->size;
+
+       seq_printf(s, "Event Log head %u tail %u interrupt pending %u\n\n",
+                  evl_status.head, evl_status.tail, evl_status.int_pending);
+
+       i = t;
+       while (1) {
+               i = (i + 1) % evl_size;
+               if (i == t)
+                       break;
+
+               if (processed && i == h)
+                       processed = false;
+               dump_event_entry(idxd, s, i, &count, processed);
+       }
+
+       spin_unlock(&evl->lock);
+       return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(debugfs_evl);
+
+int idxd_device_init_debugfs(struct idxd_device *idxd)
+{
+       if (IS_ERR_OR_NULL(idxd_debugfs_dir))
+               return 0;
+
+       idxd->dbgfs_dir = debugfs_create_dir(dev_name(idxd_confdev(idxd)), idxd_debugfs_dir);
+       if (IS_ERR(idxd->dbgfs_dir))
+               return PTR_ERR(idxd->dbgfs_dir);
+
+       if (idxd->evl) {
+               idxd->dbgfs_evl_file = debugfs_create_file("event_log", 0400,
+                                                          idxd->dbgfs_dir, idxd,
+                                                          &debugfs_evl_fops);
+               if (IS_ERR(idxd->dbgfs_evl_file)) {
+                       debugfs_remove_recursive(idxd->dbgfs_dir);
+                       idxd->dbgfs_dir = NULL;
+                       return PTR_ERR(idxd->dbgfs_evl_file);
+               }
+       }
+
+       return 0;
+}
+
+void idxd_device_remove_debugfs(struct idxd_device *idxd)
+{
+       debugfs_remove_recursive(idxd->dbgfs_dir);
+}
+
+int idxd_init_debugfs(void)
+{
+       if (!debugfs_initialized())
+               return 0;
+
+       idxd_debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
+       if (IS_ERR(idxd_debugfs_dir))
+               return  PTR_ERR(idxd_debugfs_dir);
+       return 0;
+}
+
+void idxd_remove_debugfs(void)
+{
+       debugfs_remove_recursive(idxd_debugfs_dir);
+}
index c74681f02b18a0ac5417d969335f8f9aad0637c4..b923b90b729975768c71f1ee1534688ef823a1b8 100644 (file)
@@ -330,6 +330,9 @@ struct idxd_device {
 
        unsigned long *opcap_bmap;
        struct idxd_evl *evl;
+
+       struct dentry *dbgfs_dir;
+       struct dentry *dbgfs_evl_file;
 };
 
 static inline unsigned int evl_ent_size(struct idxd_device *idxd)
@@ -704,4 +707,10 @@ static inline void perfmon_init(void) {}
 static inline void perfmon_exit(void) {}
 #endif
 
+/* debugfs */
+int idxd_device_init_debugfs(struct idxd_device *idxd);
+void idxd_device_remove_debugfs(struct idxd_device *idxd);
+int idxd_init_debugfs(void);
+void idxd_remove_debugfs(void);
+
 #endif
index f44719a11c95a3d73b6deb4a3f30e4b36d4ab12d..e21c4b7a1d32f075b8453c53c35504cfd7e31d8e 100644 (file)
@@ -669,6 +669,10 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
                goto err_dev_register;
        }
 
+       rc = idxd_device_init_debugfs(idxd);
+       if (rc)
+               dev_warn(dev, "IDXD debugfs failed to setup\n");
+
        dev_info(&pdev->dev, "Intel(R) Accelerator Device (v%x)\n",
                 idxd->hw.version);
 
@@ -731,6 +735,7 @@ static void idxd_remove(struct pci_dev *pdev)
        idxd_shutdown(pdev);
        if (device_pasid_enabled(idxd))
                idxd_disable_system_pasid(idxd);
+       idxd_device_remove_debugfs(idxd);
 
        irq_entry = idxd_get_ie(idxd, 0);
        free_irq(irq_entry->vector, irq_entry);
@@ -788,6 +793,10 @@ static int __init idxd_init_module(void)
        if (err)
                goto err_cdev_register;
 
+       err = idxd_init_debugfs();
+       if (err)
+               goto err_debugfs;
+
        err = pci_register_driver(&idxd_pci_driver);
        if (err)
                goto err_pci_register;
@@ -795,6 +804,8 @@ static int __init idxd_init_module(void)
        return 0;
 
 err_pci_register:
+       idxd_remove_debugfs();
+err_debugfs:
        idxd_cdev_remove();
 err_cdev_register:
        idxd_driver_unregister(&idxd_user_drv);
@@ -815,5 +826,6 @@ static void __exit idxd_exit_module(void)
        pci_unregister_driver(&idxd_pci_driver);
        idxd_cdev_remove();
        perfmon_exit();
+       idxd_remove_debugfs();
 }
 module_exit(idxd_exit_module);
index 0bc8eea18586580c28ce78059d3eb82266e370c7..e86199d09a91fb1979b8318eb194d55750ab2fc4 100644 (file)
@@ -311,7 +311,8 @@ struct dsa_completion_record {
                uint8_t         result;
                uint8_t         dif_status;
        };
-       uint16_t                rsvd;
+       uint8_t                 fault_info;
+       uint8_t                 rsvd;
        uint32_t                bytes_completed;
        uint64_t                fault_addr;
        union {
@@ -368,7 +369,8 @@ struct dsa_raw_completion_record {
 struct iax_completion_record {
        volatile uint8_t        status;
        uint8_t                 error_code;
-       uint16_t                rsvd;
+       uint8_t                 fault_info;
+       uint8_t                 rsvd;
        uint32_t                bytes_completed;
        uint64_t                fault_addr;
        uint32_t                invalid_flags;