sysfs: remove DEBUG defines
[linux/fpc-iii.git] / arch / s390 / pci / pci_sysfs.c
blob430c14b006d17b71854ac24345a5e90140e8fdf1
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright IBM Corp. 2012
5 * Author(s):
6 * Jan Glauber <jang@linux.vnet.ibm.com>
7 */
9 #define KMSG_COMPONENT "zpci"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/kernel.h>
13 #include <linux/stat.h>
14 #include <linux/pci.h>
16 #include <asm/sclp.h>
18 #define zpci_attr(name, fmt, member) \
19 static ssize_t name##_show(struct device *dev, \
20 struct device_attribute *attr, char *buf) \
21 { \
22 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); \
24 return sprintf(buf, fmt, zdev->member); \
25 } \
26 static DEVICE_ATTR_RO(name)
28 zpci_attr(function_id, "0x%08x\n", fid);
29 zpci_attr(function_handle, "0x%08x\n", fh);
30 zpci_attr(pchid, "0x%04x\n", pchid);
31 zpci_attr(pfgid, "0x%02x\n", pfgid);
32 zpci_attr(vfn, "0x%04x\n", vfn);
33 zpci_attr(pft, "0x%02x\n", pft);
34 zpci_attr(uid, "0x%x\n", uid);
35 zpci_attr(segment0, "0x%02x\n", pfip[0]);
36 zpci_attr(segment1, "0x%02x\n", pfip[1]);
37 zpci_attr(segment2, "0x%02x\n", pfip[2]);
38 zpci_attr(segment3, "0x%02x\n", pfip[3]);
40 static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
41 const char *buf, size_t count)
43 struct pci_dev *pdev = to_pci_dev(dev);
44 struct zpci_dev *zdev = to_zpci(pdev);
45 int ret;
47 if (!device_remove_file_self(dev, attr))
48 return count;
50 pci_lock_rescan_remove();
51 pci_stop_and_remove_bus_device(pdev);
52 ret = zpci_disable_device(zdev);
53 if (ret)
54 goto error;
56 ret = zpci_enable_device(zdev);
57 if (ret)
58 goto error;
60 pci_rescan_bus(zdev->bus);
61 pci_unlock_rescan_remove();
63 return count;
65 error:
66 pci_unlock_rescan_remove();
67 return ret;
69 static DEVICE_ATTR_WO(recover);
71 static ssize_t util_string_read(struct file *filp, struct kobject *kobj,
72 struct bin_attribute *attr, char *buf,
73 loff_t off, size_t count)
75 struct device *dev = kobj_to_dev(kobj);
76 struct pci_dev *pdev = to_pci_dev(dev);
77 struct zpci_dev *zdev = to_zpci(pdev);
79 return memory_read_from_buffer(buf, count, &off, zdev->util_str,
80 sizeof(zdev->util_str));
82 static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN);
84 static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
85 struct bin_attribute *attr, char *buf,
86 loff_t off, size_t count)
88 struct zpci_report_error_header *report = (void *) buf;
89 struct device *dev = kobj_to_dev(kobj);
90 struct pci_dev *pdev = to_pci_dev(dev);
91 struct zpci_dev *zdev = to_zpci(pdev);
92 int ret;
94 if (off || (count < sizeof(*report)))
95 return -EINVAL;
97 ret = sclp_pci_report(report, zdev->fh, zdev->fid);
99 return ret ? ret : count;
101 static BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAGE_SIZE);
103 static struct bin_attribute *zpci_bin_attrs[] = {
104 &bin_attr_util_string,
105 &bin_attr_report_error,
106 NULL,
109 static struct attribute *zpci_dev_attrs[] = {
110 &dev_attr_function_id.attr,
111 &dev_attr_function_handle.attr,
112 &dev_attr_pchid.attr,
113 &dev_attr_pfgid.attr,
114 &dev_attr_pft.attr,
115 &dev_attr_vfn.attr,
116 &dev_attr_uid.attr,
117 &dev_attr_recover.attr,
118 NULL,
120 static struct attribute_group zpci_attr_group = {
121 .attrs = zpci_dev_attrs,
122 .bin_attrs = zpci_bin_attrs,
125 static struct attribute *pfip_attrs[] = {
126 &dev_attr_segment0.attr,
127 &dev_attr_segment1.attr,
128 &dev_attr_segment2.attr,
129 &dev_attr_segment3.attr,
130 NULL,
132 static struct attribute_group pfip_attr_group = {
133 .name = "pfip",
134 .attrs = pfip_attrs,
137 const struct attribute_group *zpci_attr_groups[] = {
138 &zpci_attr_group,
139 &pfip_attr_group,
140 NULL,