Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
[firefly-linux-kernel-4.4.55.git] / arch / s390 / pci / pci_debug.c
index c22d4402ae45cde3f18878600bb9fdd50d1d0a1c..4129b0a5fd780f1f1b74260ee6be656ff93d91c1 100644 (file)
@@ -31,12 +31,25 @@ static char *pci_perf_names[] = {
        "Refresh operations",
        "DMA read bytes",
        "DMA write bytes",
-       /* software counters */
+};
+
+static char *pci_sw_names[] = {
        "Allocated pages",
        "Mapped pages",
        "Unmapped pages",
 };
 
+static void pci_sw_counter_show(struct seq_file *m)
+{
+       struct zpci_dev *zdev = m->private;
+       atomic64_t *counter = &zdev->allocated_pages;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(pci_sw_names); i++, counter++)
+               seq_printf(m, "%26s:\t%llu\n", pci_sw_names[i],
+                          atomic64_read(counter));
+}
+
 static int pci_perf_show(struct seq_file *m, void *v)
 {
        struct zpci_dev *zdev = m->private;
@@ -45,7 +58,10 @@ static int pci_perf_show(struct seq_file *m, void *v)
 
        if (!zdev)
                return 0;
+
+       mutex_lock(&zdev->lock);
        if (!zdev->fmb) {
+               mutex_unlock(&zdev->lock);
                seq_puts(m, "FMB statistics disabled\n");
                return 0;
        }
@@ -65,12 +81,9 @@ static int pci_perf_show(struct seq_file *m, void *v)
                for (i = 4; i < 6; i++)
                        seq_printf(m, "%26s:\t%llu\n",
                                   pci_perf_names[i], *(stat + i));
-       /* software counters */
-       for (i = 6; i < ARRAY_SIZE(pci_perf_names); i++)
-               seq_printf(m, "%26s:\t%llu\n",
-                          pci_perf_names[i],
-                          atomic64_read((atomic64_t *) (stat + i)));
 
+       pci_sw_counter_show(m);
+       mutex_unlock(&zdev->lock);
        return 0;
 }
 
@@ -88,19 +101,17 @@ static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
        if (rc)
                return rc;
 
+       mutex_lock(&zdev->lock);
        switch (val) {
        case 0:
                rc = zpci_fmb_disable_device(zdev);
-               if (rc)
-                       return rc;
                break;
        case 1:
                rc = zpci_fmb_enable_device(zdev);
-               if (rc)
-                       return rc;
                break;
        }
-       return count;
+       mutex_unlock(&zdev->lock);
+       return rc ? rc : count;
 }
 
 static int pci_perf_seq_open(struct inode *inode, struct file *filp)