Jan Glauber | 1e8da95 | 2012-11-29 14:36:55 +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 | 1e8da95 | 2012-11-29 14:36:55 +0100 | [diff] [blame] | 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/stat.h> |
| 13 | #include <linux/pci.h> |
| 14 | |
Sebastian Ott | 368704a | 2015-11-27 11:22:57 +0100 | [diff] [blame] | 15 | #include <asm/sclp.h> |
| 16 | |
Sebastian Ott | b346953 | 2014-04-16 16:10:18 +0200 | [diff] [blame] | 17 | #define zpci_attr(name, fmt, member) \ |
| 18 | static ssize_t name##_show(struct device *dev, \ |
| 19 | struct device_attribute *attr, char *buf) \ |
| 20 | { \ |
Sebastian Ott | 198a527 | 2015-06-23 14:06:35 +0200 | [diff] [blame] | 21 | struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); \ |
Sebastian Ott | b346953 | 2014-04-16 16:10:18 +0200 | [diff] [blame] | 22 | \ |
| 23 | return sprintf(buf, fmt, zdev->member); \ |
| 24 | } \ |
| 25 | static DEVICE_ATTR_RO(name) |
Jan Glauber | 1e8da95 | 2012-11-29 14:36:55 +0100 | [diff] [blame] | 26 | |
Sebastian Ott | b346953 | 2014-04-16 16:10:18 +0200 | [diff] [blame] | 27 | zpci_attr(function_id, "0x%08x\n", fid); |
| 28 | zpci_attr(function_handle, "0x%08x\n", fh); |
| 29 | zpci_attr(pchid, "0x%04x\n", pchid); |
| 30 | zpci_attr(pfgid, "0x%02x\n", pfgid); |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 31 | zpci_attr(vfn, "0x%04x\n", vfn); |
| 32 | zpci_attr(pft, "0x%02x\n", pft); |
| 33 | zpci_attr(uid, "0x%x\n", uid); |
| 34 | zpci_attr(segment0, "0x%02x\n", pfip[0]); |
| 35 | zpci_attr(segment1, "0x%02x\n", pfip[1]); |
| 36 | zpci_attr(segment2, "0x%02x\n", pfip[2]); |
| 37 | zpci_attr(segment3, "0x%02x\n", pfip[3]); |
Jan Glauber | 1e8da95 | 2012-11-29 14:36:55 +0100 | [diff] [blame] | 38 | |
Sebastian Ott | b346953 | 2014-04-16 16:10:18 +0200 | [diff] [blame] | 39 | static ssize_t recover_store(struct device *dev, struct device_attribute *attr, |
Tejun Heo | 0b60f9e | 2014-02-03 14:03:04 -0500 | [diff] [blame] | 40 | const char *buf, size_t count) |
Sebastian Ott | 0ff70ec | 2013-08-29 19:35:19 +0200 | [diff] [blame] | 41 | { |
| 42 | struct pci_dev *pdev = to_pci_dev(dev); |
Sebastian Ott | 198a527 | 2015-06-23 14:06:35 +0200 | [diff] [blame] | 43 | struct zpci_dev *zdev = to_zpci(pdev); |
Sebastian Ott | 0ff70ec | 2013-08-29 19:35:19 +0200 | [diff] [blame] | 44 | int ret; |
| 45 | |
Tejun Heo | 0b60f9e | 2014-02-03 14:03:04 -0500 | [diff] [blame] | 46 | if (!device_remove_file_self(dev, attr)) |
| 47 | return count; |
| 48 | |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 49 | pci_lock_rescan_remove(); |
Sebastian Ott | 0ff70ec | 2013-08-29 19:35:19 +0200 | [diff] [blame] | 50 | pci_stop_and_remove_bus_device(pdev); |
| 51 | ret = zpci_disable_device(zdev); |
| 52 | if (ret) |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 53 | goto error; |
Sebastian Ott | 0ff70ec | 2013-08-29 19:35:19 +0200 | [diff] [blame] | 54 | |
| 55 | ret = zpci_enable_device(zdev); |
| 56 | if (ret) |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 57 | goto error; |
Sebastian Ott | 0ff70ec | 2013-08-29 19:35:19 +0200 | [diff] [blame] | 58 | |
| 59 | pci_rescan_bus(zdev->bus); |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 60 | pci_unlock_rescan_remove(); |
| 61 | |
Tejun Heo | 0b60f9e | 2014-02-03 14:03:04 -0500 | [diff] [blame] | 62 | return count; |
Sebastian Ott | 2a01bd1 | 2015-07-28 19:14:51 +0200 | [diff] [blame] | 63 | |
| 64 | error: |
| 65 | pci_unlock_rescan_remove(); |
| 66 | return ret; |
Sebastian Ott | 0ff70ec | 2013-08-29 19:35:19 +0200 | [diff] [blame] | 67 | } |
Sebastian Ott | b346953 | 2014-04-16 16:10:18 +0200 | [diff] [blame] | 68 | static DEVICE_ATTR_WO(recover); |
Sebastian Ott | 0ff70ec | 2013-08-29 19:35:19 +0200 | [diff] [blame] | 69 | |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 70 | static ssize_t util_string_read(struct file *filp, struct kobject *kobj, |
| 71 | struct bin_attribute *attr, char *buf, |
| 72 | loff_t off, size_t count) |
| 73 | { |
| 74 | struct device *dev = kobj_to_dev(kobj); |
| 75 | struct pci_dev *pdev = to_pci_dev(dev); |
Sebastian Ott | 198a527 | 2015-06-23 14:06:35 +0200 | [diff] [blame] | 76 | struct zpci_dev *zdev = to_zpci(pdev); |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 77 | |
| 78 | return memory_read_from_buffer(buf, count, &off, zdev->util_str, |
| 79 | sizeof(zdev->util_str)); |
| 80 | } |
| 81 | static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN); |
Sebastian Ott | 368704a | 2015-11-27 11:22:57 +0100 | [diff] [blame] | 82 | |
| 83 | static ssize_t report_error_write(struct file *filp, struct kobject *kobj, |
| 84 | struct bin_attribute *attr, char *buf, |
| 85 | loff_t off, size_t count) |
| 86 | { |
| 87 | struct zpci_report_error_header *report = (void *) buf; |
| 88 | struct device *dev = kobj_to_dev(kobj); |
| 89 | struct pci_dev *pdev = to_pci_dev(dev); |
| 90 | struct zpci_dev *zdev = to_zpci(pdev); |
| 91 | int ret; |
| 92 | |
| 93 | if (off || (count < sizeof(*report))) |
| 94 | return -EINVAL; |
| 95 | |
| 96 | ret = sclp_pci_report(report, zdev->fh, zdev->fid); |
| 97 | |
| 98 | return ret ? ret : count; |
| 99 | } |
| 100 | static BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAGE_SIZE); |
| 101 | |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 102 | static struct bin_attribute *zpci_bin_attrs[] = { |
| 103 | &bin_attr_util_string, |
Sebastian Ott | 368704a | 2015-11-27 11:22:57 +0100 | [diff] [blame] | 104 | &bin_attr_report_error, |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 105 | NULL, |
| 106 | }; |
| 107 | |
Sebastian Ott | 93065d0 | 2014-04-16 16:11:00 +0200 | [diff] [blame] | 108 | static struct attribute *zpci_dev_attrs[] = { |
| 109 | &dev_attr_function_id.attr, |
| 110 | &dev_attr_function_handle.attr, |
| 111 | &dev_attr_pchid.attr, |
| 112 | &dev_attr_pfgid.attr, |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 113 | &dev_attr_pft.attr, |
| 114 | &dev_attr_vfn.attr, |
| 115 | &dev_attr_uid.attr, |
Sebastian Ott | 93065d0 | 2014-04-16 16:11:00 +0200 | [diff] [blame] | 116 | &dev_attr_recover.attr, |
Jan Glauber | 1e8da95 | 2012-11-29 14:36:55 +0100 | [diff] [blame] | 117 | NULL, |
| 118 | }; |
Sebastian Ott | 93065d0 | 2014-04-16 16:11:00 +0200 | [diff] [blame] | 119 | static struct attribute_group zpci_attr_group = { |
| 120 | .attrs = zpci_dev_attrs, |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 121 | .bin_attrs = zpci_bin_attrs, |
Sebastian Ott | 93065d0 | 2014-04-16 16:11:00 +0200 | [diff] [blame] | 122 | }; |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 123 | |
| 124 | static struct attribute *pfip_attrs[] = { |
| 125 | &dev_attr_segment0.attr, |
| 126 | &dev_attr_segment1.attr, |
| 127 | &dev_attr_segment2.attr, |
| 128 | &dev_attr_segment3.attr, |
| 129 | NULL, |
| 130 | }; |
| 131 | static struct attribute_group pfip_attr_group = { |
| 132 | .name = "pfip", |
| 133 | .attrs = pfip_attrs, |
| 134 | }; |
| 135 | |
Sebastian Ott | 93065d0 | 2014-04-16 16:11:00 +0200 | [diff] [blame] | 136 | const struct attribute_group *zpci_attr_groups[] = { |
| 137 | &zpci_attr_group, |
Sebastian Ott | ac4995b | 2014-04-16 16:12:05 +0200 | [diff] [blame] | 138 | &pfip_attr_group, |
Sebastian Ott | 93065d0 | 2014-04-16 16:11:00 +0200 | [diff] [blame] | 139 | NULL, |
| 140 | }; |