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