NTB: debugfs device entry
authorJon Mason <jon.mason@intel.com>
Mon, 7 Apr 2014 17:55:47 +0000 (10:55 -0700)
committerJon Mason <jdmason@kudzu.us>
Fri, 17 Oct 2014 11:08:50 +0000 (07:08 -0400)
Create a debugfs entry for the NTB device to log the basic device info,
as well as display the error count on a number of registers.

Signed-off-by: Jon Mason <jon.mason@intel.com>
drivers/ntb/ntb_hw.c
drivers/ntb/ntb_hw.h
drivers/ntb/ntb_regs.h

index 372e08c4ffefb76852e4d640e6936f3529e8c215..a3990363a1712e9b7347db7699a0fdd002218f32 100644 (file)
@@ -1344,6 +1344,101 @@ static void ntb_free_callbacks(struct ntb_device *ndev)
        kfree(ndev->db_cb);
 }
 
+static ssize_t ntb_debugfs_read(struct file *filp, char __user *ubuf,
+                               size_t count, loff_t *offp)
+{
+       struct ntb_device *ndev;
+       char *buf;
+       ssize_t ret, offset, out_count;
+
+       out_count = 500;
+
+       buf = kmalloc(out_count, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       ndev = filp->private_data;
+       offset = 0;
+       offset += snprintf(buf + offset, out_count - offset,
+                          "NTB Device Information:\n");
+       offset += snprintf(buf + offset, out_count - offset,
+                          "Connection Type - \t\t%s\n",
+                          ndev->conn_type == NTB_CONN_TRANSPARENT ?
+                          "Transparent" : (ndev->conn_type == NTB_CONN_B2B) ?
+                          "Back to back" : "Root Port");
+       offset += snprintf(buf + offset, out_count - offset,
+                          "Device Type - \t\t\t%s\n",
+                          ndev->dev_type == NTB_DEV_USD ?
+                          "DSD/USP" : "USD/DSP");
+       offset += snprintf(buf + offset, out_count - offset,
+                          "Max Number of Callbacks - \t%u\n",
+                          ntb_max_cbs(ndev));
+       offset += snprintf(buf + offset, out_count - offset,
+                          "Link Status - \t\t\t%s\n",
+                          ntb_hw_link_status(ndev) ? "Up" : "Down");
+       if (ntb_hw_link_status(ndev)) {
+               offset += snprintf(buf + offset, out_count - offset,
+                                  "Link Speed - \t\t\tPCI-E Gen %u\n",
+                                  ndev->link_speed);
+               offset += snprintf(buf + offset, out_count - offset,
+                                  "Link Width - \t\t\tx%u\n",
+                                  ndev->link_width);
+       }
+
+       if (ndev->hw_type != BWD_HW) {
+               u32 status32;
+               u16 status16;
+               int rc;
+
+               offset += snprintf(buf + offset, out_count - offset,
+                                  "\nNTB Device Statistics:\n");
+               offset += snprintf(buf + offset, out_count - offset,
+                                  "Upstream Memory Miss - \t%u\n",
+                                  readw(ndev->reg_base +
+                                        SNB_USMEMMISS_OFFSET));
+
+               offset += snprintf(buf + offset, out_count - offset,
+                                  "\nNTB Hardware Errors:\n");
+
+               rc = pci_read_config_word(ndev->pdev, SNB_DEVSTS_OFFSET,
+                                         &status16);
+               if (!rc)
+                       offset += snprintf(buf + offset, out_count - offset,
+                                          "DEVSTS - \t%#06x\n", status16);
+
+               rc = pci_read_config_word(ndev->pdev, SNB_LINK_STATUS_OFFSET,
+                                         &status16);
+               if (!rc)
+                       offset += snprintf(buf + offset, out_count - offset,
+                                          "LNKSTS - \t%#06x\n", status16);
+
+               rc = pci_read_config_dword(ndev->pdev, SNB_UNCERRSTS_OFFSET,
+                                          &status32);
+               if (!rc)
+                       offset += snprintf(buf + offset, out_count - offset,
+                                          "UNCERRSTS - \t%#010x\n", status32);
+
+               rc = pci_read_config_dword(ndev->pdev, SNB_CORERRSTS_OFFSET,
+                                          &status32);
+               if (!rc)
+                       offset += snprintf(buf + offset, out_count - offset,
+                                          "CORERRSTS - \t%#010x\n", status32);
+       }
+
+       if (offset > out_count)
+               offset = out_count;
+
+       ret = simple_read_from_buffer(ubuf, count, offp, buf, offset);
+       kfree(buf);
+       return ret;
+}
+
+static const struct file_operations ntb_debugfs_info = {
+       .owner = THIS_MODULE,
+       .open = simple_open,
+       .read = ntb_debugfs_read,
+};
+
 static void ntb_setup_debugfs(struct ntb_device *ndev)
 {
        if (!debugfs_initialized())
@@ -1354,6 +1449,11 @@ static void ntb_setup_debugfs(struct ntb_device *ndev)
 
        ndev->debugfs_dir = debugfs_create_dir(pci_name(ndev->pdev),
                                               debugfs_dir);
+       if (ndev->debugfs_dir)
+               ndev->debugfs_info = debugfs_create_file("info", S_IRUSR,
+                                                        ndev->debugfs_dir,
+                                                        ndev,
+                                                        &ntb_debugfs_info);
 }
 
 static void ntb_free_debugfs(struct ntb_device *ndev)
@@ -1542,4 +1642,5 @@ static struct pci_driver ntb_pci_driver = {
        .probe = ntb_pci_probe,
        .remove = ntb_pci_remove,
 };
+
 module_pci_driver(ntb_pci_driver);
index 465517b7393efe4e995d323dc20f48b1eab859ae..ddbcbfda0f49c0c150fea4d76f21a2a542100236 100644 (file)
@@ -152,6 +152,7 @@ struct ntb_device {
        struct delayed_work lr_timer;
 
        struct dentry *debugfs_dir;
+       struct dentry *debugfs_info;
 };
 
 /**
index 9774506419d75ba1a5dc08a5f0e4d52e90d33ad7..07872057c76ef277992bbbcaac7ae0e9c5a7545e 100644 (file)
 
 #define SNB_DB_HW_LINK         0x8000
 
+#define SNB_UNCERRSTS_OFFSET   0x014C
+#define SNB_CORERRSTS_OFFSET   0x0158
+#define SNB_LINK_STATUS_OFFSET 0x01A2
 #define SNB_PCICMD_OFFSET      0x0504
 #define SNB_DEVCTRL_OFFSET     0x0598
+#define SNB_DEVSTS_OFFSET      0x059A
 #define SNB_SLINK_STATUS_OFFSET        0x05A2
-#define SNB_LINK_STATUS_OFFSET 0x01A2
 
 #define SNB_PBAR2LMT_OFFSET    0x0000
 #define SNB_PBAR4LMT_OFFSET    0x0008
@@ -84,7 +87,7 @@
 #define SNB_PDBMSK_OFFSET      0x0062
 #define SNB_SDOORBELL_OFFSET   0x0064
 #define SNB_SDBMSK_OFFSET      0x0066
-#define SNB_USMEMMISS          0x0070
+#define SNB_USMEMMISS_OFFSET   0x0070
 #define SNB_SPAD_OFFSET                0x0080
 #define SNB_SPADSEMA4_OFFSET   0x00c0
 #define SNB_WCCNTRL_OFFSET     0x00e0