0001
0002
0003
0004
0005
0006
0007
0008
0009 #define KMSG_COMPONENT "zpci"
0010 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
0011
0012 #include <linux/kernel.h>
0013 #include <linux/stat.h>
0014 #include <linux/pci.h>
0015
0016 #include "../../../drivers/pci/pci.h"
0017
0018 #include <asm/sclp.h>
0019
0020 #define zpci_attr(name, fmt, member) \
0021 static ssize_t name##_show(struct device *dev, \
0022 struct device_attribute *attr, char *buf) \
0023 { \
0024 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); \
0025 \
0026 return sprintf(buf, fmt, zdev->member); \
0027 } \
0028 static DEVICE_ATTR_RO(name)
0029
0030 zpci_attr(function_id, "0x%08x\n", fid);
0031 zpci_attr(function_handle, "0x%08x\n", fh);
0032 zpci_attr(pchid, "0x%04x\n", pchid);
0033 zpci_attr(pfgid, "0x%02x\n", pfgid);
0034 zpci_attr(vfn, "0x%04x\n", vfn);
0035 zpci_attr(pft, "0x%02x\n", pft);
0036 zpci_attr(port, "%d\n", port);
0037 zpci_attr(uid, "0x%x\n", uid);
0038 zpci_attr(segment0, "0x%02x\n", pfip[0]);
0039 zpci_attr(segment1, "0x%02x\n", pfip[1]);
0040 zpci_attr(segment2, "0x%02x\n", pfip[2]);
0041 zpci_attr(segment3, "0x%02x\n", pfip[3]);
0042
0043 static ssize_t mio_enabled_show(struct device *dev,
0044 struct device_attribute *attr, char *buf)
0045 {
0046 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
0047
0048 return sprintf(buf, zpci_use_mio(zdev) ? "1\n" : "0\n");
0049 }
0050 static DEVICE_ATTR_RO(mio_enabled);
0051
0052 static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
0053 const char *buf, size_t count)
0054 {
0055 struct kernfs_node *kn;
0056 struct pci_dev *pdev = to_pci_dev(dev);
0057 struct zpci_dev *zdev = to_zpci(pdev);
0058 int ret = 0;
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
0071 WARN_ON_ONCE(!kn);
0072
0073
0074
0075 device_remove_file(dev, attr);
0076
0077
0078
0079
0080
0081
0082 pci_lock_rescan_remove();
0083 if (pci_dev_is_added(pdev)) {
0084 pci_stop_and_remove_bus_device(pdev);
0085 if (zdev->dma_table) {
0086 ret = zpci_dma_exit_device(zdev);
0087 if (ret)
0088 goto out;
0089 }
0090
0091 if (zdev_enabled(zdev)) {
0092 ret = zpci_disable_device(zdev);
0093
0094
0095
0096
0097
0098
0099 if (ret == -EINVAL)
0100 ret = 0;
0101 if (ret)
0102 goto out;
0103 }
0104
0105 ret = zpci_enable_device(zdev);
0106 if (ret)
0107 goto out;
0108 ret = zpci_dma_init_device(zdev);
0109 if (ret) {
0110 zpci_disable_device(zdev);
0111 goto out;
0112 }
0113 pci_rescan_bus(zdev->zbus->bus);
0114 }
0115 out:
0116 pci_unlock_rescan_remove();
0117 if (kn)
0118 sysfs_unbreak_active_protection(kn);
0119 return ret ? ret : count;
0120 }
0121 static DEVICE_ATTR_WO(recover);
0122
0123 static ssize_t util_string_read(struct file *filp, struct kobject *kobj,
0124 struct bin_attribute *attr, char *buf,
0125 loff_t off, size_t count)
0126 {
0127 struct device *dev = kobj_to_dev(kobj);
0128 struct pci_dev *pdev = to_pci_dev(dev);
0129 struct zpci_dev *zdev = to_zpci(pdev);
0130
0131 return memory_read_from_buffer(buf, count, &off, zdev->util_str,
0132 sizeof(zdev->util_str));
0133 }
0134 static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN);
0135
0136 static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
0137 struct bin_attribute *attr, char *buf,
0138 loff_t off, size_t count)
0139 {
0140 struct zpci_report_error_header *report = (void *) buf;
0141 struct device *dev = kobj_to_dev(kobj);
0142 struct pci_dev *pdev = to_pci_dev(dev);
0143 struct zpci_dev *zdev = to_zpci(pdev);
0144 int ret;
0145
0146 if (off || (count < sizeof(*report)))
0147 return -EINVAL;
0148
0149 ret = sclp_pci_report(report, zdev->fh, zdev->fid);
0150
0151 return ret ? ret : count;
0152 }
0153 static BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAGE_SIZE);
0154
0155 static ssize_t uid_is_unique_show(struct device *dev,
0156 struct device_attribute *attr, char *buf)
0157 {
0158 return sysfs_emit(buf, "%d\n", zpci_unique_uid ? 1 : 0);
0159 }
0160 static DEVICE_ATTR_RO(uid_is_unique);
0161
0162 #ifndef CONFIG_DMI
0163
0164 static ssize_t index_show(struct device *dev,
0165 struct device_attribute *attr, char *buf)
0166 {
0167 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
0168 u32 index = ~0;
0169
0170 if (zpci_unique_uid)
0171 index = zdev->uid;
0172
0173 return sysfs_emit(buf, "%u\n", index);
0174 }
0175 static DEVICE_ATTR_RO(index);
0176
0177 static umode_t zpci_index_is_visible(struct kobject *kobj,
0178 struct attribute *attr, int n)
0179 {
0180 return zpci_unique_uid ? attr->mode : 0;
0181 }
0182
0183 static struct attribute *zpci_ident_attrs[] = {
0184 &dev_attr_index.attr,
0185 NULL,
0186 };
0187
0188 static struct attribute_group zpci_ident_attr_group = {
0189 .attrs = zpci_ident_attrs,
0190 .is_visible = zpci_index_is_visible,
0191 };
0192 #endif
0193
0194 static struct bin_attribute *zpci_bin_attrs[] = {
0195 &bin_attr_util_string,
0196 &bin_attr_report_error,
0197 NULL,
0198 };
0199
0200 static struct attribute *zpci_dev_attrs[] = {
0201 &dev_attr_function_id.attr,
0202 &dev_attr_function_handle.attr,
0203 &dev_attr_pchid.attr,
0204 &dev_attr_pfgid.attr,
0205 &dev_attr_pft.attr,
0206 &dev_attr_port.attr,
0207 &dev_attr_vfn.attr,
0208 &dev_attr_uid.attr,
0209 &dev_attr_recover.attr,
0210 &dev_attr_mio_enabled.attr,
0211 &dev_attr_uid_is_unique.attr,
0212 NULL,
0213 };
0214
0215 static struct attribute_group zpci_attr_group = {
0216 .attrs = zpci_dev_attrs,
0217 .bin_attrs = zpci_bin_attrs,
0218 };
0219
0220 static struct attribute *pfip_attrs[] = {
0221 &dev_attr_segment0.attr,
0222 &dev_attr_segment1.attr,
0223 &dev_attr_segment2.attr,
0224 &dev_attr_segment3.attr,
0225 NULL,
0226 };
0227 static struct attribute_group pfip_attr_group = {
0228 .name = "pfip",
0229 .attrs = pfip_attrs,
0230 };
0231
0232 const struct attribute_group *zpci_attr_groups[] = {
0233 &zpci_attr_group,
0234 &pfip_attr_group,
0235 #ifndef CONFIG_DMI
0236 &zpci_ident_attr_group,
0237 #endif
0238 NULL,
0239 };