Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright IBM Corp. 2012 |
| 3 | * |
| 4 | * Author(s): |
| 5 | * Jan Glauber <jang@linux.vnet.ibm.com> |
| 6 | */ |
| 7 | |
Gerald Schaefer | 896cb7e | 2014-07-16 17:21:01 +0200 | [diff] [blame] | 8 | #define KMSG_COMPONENT "zpci" |
| 9 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/seq_file.h> |
| 13 | #include <linux/debugfs.h> |
Sebastian Ott | a2ab833 | 2013-04-16 14:11:14 +0200 | [diff] [blame] | 14 | #include <linux/export.h> |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 15 | #include <linux/pci.h> |
| 16 | #include <asm/debug.h> |
| 17 | |
| 18 | #include <asm/pci_dma.h> |
| 19 | |
| 20 | static struct dentry *debugfs_root; |
Sebastian Ott | a2ab833 | 2013-04-16 14:11:14 +0200 | [diff] [blame] | 21 | debug_info_t *pci_debug_msg_id; |
| 22 | EXPORT_SYMBOL_GPL(pci_debug_msg_id); |
| 23 | debug_info_t *pci_debug_err_id; |
| 24 | EXPORT_SYMBOL_GPL(pci_debug_err_id); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 25 | |
| 26 | static char *pci_perf_names[] = { |
| 27 | /* hardware counters */ |
| 28 | "Load operations", |
| 29 | "Store operations", |
| 30 | "Store block operations", |
| 31 | "Refresh operations", |
| 32 | "DMA read bytes", |
| 33 | "DMA write bytes", |
Sebastian Ott | 6001018 | 2015-04-10 14:33:08 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static char *pci_sw_names[] = { |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 37 | "Allocated pages", |
| 38 | "Mapped pages", |
| 39 | "Unmapped pages", |
| 40 | }; |
| 41 | |
Sebastian Ott | 6001018 | 2015-04-10 14:33:08 +0200 | [diff] [blame] | 42 | static void pci_sw_counter_show(struct seq_file *m) |
| 43 | { |
| 44 | struct zpci_dev *zdev = m->private; |
| 45 | atomic64_t *counter = &zdev->allocated_pages; |
| 46 | int i; |
| 47 | |
| 48 | for (i = 0; i < ARRAY_SIZE(pci_sw_names); i++, counter++) |
| 49 | seq_printf(m, "%26s:\t%llu\n", pci_sw_names[i], |
| 50 | atomic64_read(counter)); |
| 51 | } |
| 52 | |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 53 | static int pci_perf_show(struct seq_file *m, void *v) |
| 54 | { |
| 55 | struct zpci_dev *zdev = m->private; |
| 56 | u64 *stat; |
| 57 | int i; |
| 58 | |
| 59 | if (!zdev) |
| 60 | return 0; |
Sebastian Ott | 80ed156 | 2015-04-10 14:34:33 +0200 | [diff] [blame] | 61 | |
| 62 | mutex_lock(&zdev->lock); |
Joe Perches | c2f0b61 | 2015-04-15 16:18:14 -0700 | [diff] [blame] | 63 | if (!zdev->fmb) { |
Sebastian Ott | 80ed156 | 2015-04-10 14:34:33 +0200 | [diff] [blame] | 64 | mutex_unlock(&zdev->lock); |
Joe Perches | c2f0b61 | 2015-04-15 16:18:14 -0700 | [diff] [blame] | 65 | seq_puts(m, "FMB statistics disabled\n"); |
| 66 | return 0; |
| 67 | } |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 68 | |
| 69 | /* header */ |
| 70 | seq_printf(m, "FMB @ %p\n", zdev->fmb); |
| 71 | seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update); |
| 72 | seq_printf(m, "Samples: %u\n", zdev->fmb->samples); |
| 73 | seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update); |
| 74 | |
| 75 | /* hardware counters */ |
| 76 | stat = (u64 *) &zdev->fmb->ld_ops; |
| 77 | for (i = 0; i < 4; i++) |
| 78 | seq_printf(m, "%26s:\t%llu\n", |
| 79 | pci_perf_names[i], *(stat + i)); |
| 80 | if (zdev->fmb->dma_valid) |
| 81 | for (i = 4; i < 6; i++) |
| 82 | seq_printf(m, "%26s:\t%llu\n", |
| 83 | pci_perf_names[i], *(stat + i)); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 84 | |
Sebastian Ott | 6001018 | 2015-04-10 14:33:08 +0200 | [diff] [blame] | 85 | pci_sw_counter_show(m); |
Sebastian Ott | 80ed156 | 2015-04-10 14:34:33 +0200 | [diff] [blame] | 86 | mutex_unlock(&zdev->lock); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf, |
| 91 | size_t count, loff_t *off) |
| 92 | { |
| 93 | struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private; |
| 94 | unsigned long val; |
| 95 | int rc; |
| 96 | |
| 97 | if (!zdev) |
| 98 | return 0; |
| 99 | |
| 100 | rc = kstrtoul_from_user(ubuf, count, 10, &val); |
| 101 | if (rc) |
| 102 | return rc; |
| 103 | |
Sebastian Ott | 80ed156 | 2015-04-10 14:34:33 +0200 | [diff] [blame] | 104 | mutex_lock(&zdev->lock); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 105 | switch (val) { |
| 106 | case 0: |
| 107 | rc = zpci_fmb_disable_device(zdev); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 108 | break; |
| 109 | case 1: |
| 110 | rc = zpci_fmb_enable_device(zdev); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 111 | break; |
| 112 | } |
Sebastian Ott | 80ed156 | 2015-04-10 14:34:33 +0200 | [diff] [blame] | 113 | mutex_unlock(&zdev->lock); |
| 114 | return rc ? rc : count; |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static int pci_perf_seq_open(struct inode *inode, struct file *filp) |
| 118 | { |
| 119 | return single_open(filp, pci_perf_show, |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 120 | file_inode(filp)->i_private); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static const struct file_operations debugfs_pci_perf_fops = { |
| 124 | .open = pci_perf_seq_open, |
| 125 | .read = seq_read, |
| 126 | .write = pci_perf_seq_write, |
| 127 | .llseek = seq_lseek, |
| 128 | .release = single_release, |
| 129 | }; |
| 130 | |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 131 | void zpci_debug_init_device(struct zpci_dev *zdev, const char *name) |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 132 | { |
Sebastian Ott | 9a99649 | 2016-01-29 15:13:30 +0100 | [diff] [blame] | 133 | zdev->debugfs_dev = debugfs_create_dir(name, debugfs_root); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 134 | if (IS_ERR(zdev->debugfs_dev)) |
| 135 | zdev->debugfs_dev = NULL; |
| 136 | |
| 137 | zdev->debugfs_perf = debugfs_create_file("statistics", |
| 138 | S_IFREG | S_IRUGO | S_IWUSR, |
| 139 | zdev->debugfs_dev, zdev, |
| 140 | &debugfs_pci_perf_fops); |
| 141 | if (IS_ERR(zdev->debugfs_perf)) |
| 142 | zdev->debugfs_perf = NULL; |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | void zpci_debug_exit_device(struct zpci_dev *zdev) |
| 146 | { |
| 147 | debugfs_remove(zdev->debugfs_perf); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 148 | debugfs_remove(zdev->debugfs_dev); |
| 149 | } |
| 150 | |
| 151 | int __init zpci_debug_init(void) |
| 152 | { |
| 153 | /* event trace buffer */ |
Sebastian Ott | f7e1e65 | 2014-02-17 11:16:10 +0100 | [diff] [blame] | 154 | pci_debug_msg_id = debug_register("pci_msg", 8, 1, 8 * sizeof(long)); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 155 | if (!pci_debug_msg_id) |
| 156 | return -EINVAL; |
| 157 | debug_register_view(pci_debug_msg_id, &debug_sprintf_view); |
| 158 | debug_set_level(pci_debug_msg_id, 3); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 159 | |
| 160 | /* error log */ |
| 161 | pci_debug_err_id = debug_register("pci_error", 2, 1, 16); |
| 162 | if (!pci_debug_err_id) |
| 163 | return -EINVAL; |
| 164 | debug_register_view(pci_debug_err_id, &debug_hex_ascii_view); |
| 165 | debug_set_level(pci_debug_err_id, 6); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 166 | |
| 167 | debugfs_root = debugfs_create_dir("pci", NULL); |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | void zpci_debug_exit(void) |
| 172 | { |
Markus Elfring | 8c080bd | 2014-11-22 15:00:55 +0100 | [diff] [blame] | 173 | debug_unregister(pci_debug_msg_id); |
| 174 | debug_unregister(pci_debug_err_id); |
Jan Glauber | d0b0885 | 2012-12-11 14:53:35 +0100 | [diff] [blame] | 175 | debugfs_remove(debugfs_root); |
| 176 | } |