1
2
3
4
5
6
7
8
9#define KMSG_COMPONENT "zpci"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
12#include <linux/kernel.h>
13#include <linux/stat.h>
14#include <linux/pci.h>
15
16#include "../../../drivers/pci/pci.h"
17
18#include <asm/sclp.h>
19
20#define zpci_attr(name, fmt, member) \
21static ssize_t name##_show(struct device *dev, \
22 struct device_attribute *attr, char *buf) \
23{ \
24 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); \
25 \
26 return sprintf(buf, fmt, zdev->member); \
27} \
28static DEVICE_ATTR_RO(name)
29
30zpci_attr(function_id, "0x%08x\n", fid);
31zpci_attr(function_handle, "0x%08x\n", fh);
32zpci_attr(pchid, "0x%04x\n", pchid);
33zpci_attr(pfgid, "0x%02x\n", pfgid);
34zpci_attr(vfn, "0x%04x\n", vfn);
35zpci_attr(pft, "0x%02x\n", pft);
36zpci_attr(port, "%d\n", port);
37zpci_attr(uid, "0x%x\n", uid);
38zpci_attr(segment0, "0x%02x\n", pfip[0]);
39zpci_attr(segment1, "0x%02x\n", pfip[1]);
40zpci_attr(segment2, "0x%02x\n", pfip[2]);
41zpci_attr(segment3, "0x%02x\n", pfip[3]);
42
43static ssize_t mio_enabled_show(struct device *dev,
44 struct device_attribute *attr, char *buf)
45{
46 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
47
48 return sprintf(buf, zpci_use_mio(zdev) ? "1\n" : "0\n");
49}
50static DEVICE_ATTR_RO(mio_enabled);
51
52static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
53 const char *buf, size_t count)
54{
55 struct kernfs_node *kn;
56 struct pci_dev *pdev = to_pci_dev(dev);
57 struct zpci_dev *zdev = to_zpci(pdev);
58 int ret = 0;
59
60
61
62
63
64
65
66
67
68
69
70 kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
71 WARN_ON_ONCE(!kn);
72
73
74
75 device_remove_file(dev, attr);
76
77
78
79
80
81
82 pci_lock_rescan_remove();
83 if (pci_dev_is_added(pdev)) {
84 pci_stop_and_remove_bus_device(pdev);
85 if (zdev->dma_table) {
86 ret = zpci_dma_exit_device(zdev);
87 if (ret)
88 goto out;
89 }
90
91 if (zdev_enabled(zdev)) {
92 ret = zpci_disable_device(zdev);
93 if (ret)
94 goto out;
95 }
96
97 ret = zpci_enable_device(zdev);
98 if (ret)
99 goto out;
100 ret = zpci_dma_init_device(zdev);
101 if (ret) {
102 zpci_disable_device(zdev);
103 goto out;
104 }
105 pci_rescan_bus(zdev->zbus->bus);
106 }
107out:
108 pci_unlock_rescan_remove();
109 if (kn)
110 sysfs_unbreak_active_protection(kn);
111 return ret ? ret : count;
112}
113static DEVICE_ATTR_WO(recover);
114
115static ssize_t util_string_read(struct file *filp, struct kobject *kobj,
116 struct bin_attribute *attr, char *buf,
117 loff_t off, size_t count)
118{
119 struct device *dev = kobj_to_dev(kobj);
120 struct pci_dev *pdev = to_pci_dev(dev);
121 struct zpci_dev *zdev = to_zpci(pdev);
122
123 return memory_read_from_buffer(buf, count, &off, zdev->util_str,
124 sizeof(zdev->util_str));
125}
126static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN);
127
128static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
129 struct bin_attribute *attr, char *buf,
130 loff_t off, size_t count)
131{
132 struct zpci_report_error_header *report = (void *) buf;
133 struct device *dev = kobj_to_dev(kobj);
134 struct pci_dev *pdev = to_pci_dev(dev);
135 struct zpci_dev *zdev = to_zpci(pdev);
136 int ret;
137
138 if (off || (count < sizeof(*report)))
139 return -EINVAL;
140
141 ret = sclp_pci_report(report, zdev->fh, zdev->fid);
142
143 return ret ? ret : count;
144}
145static BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAGE_SIZE);
146
147static ssize_t uid_is_unique_show(struct device *dev,
148 struct device_attribute *attr, char *buf)
149{
150 return sysfs_emit(buf, "%d\n", zpci_unique_uid ? 1 : 0);
151}
152static DEVICE_ATTR_RO(uid_is_unique);
153
154#ifndef CONFIG_DMI
155
156static ssize_t index_show(struct device *dev,
157 struct device_attribute *attr, char *buf)
158{
159 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
160 u32 index = ~0;
161
162 if (zpci_unique_uid)
163 index = zdev->uid;
164
165 return sysfs_emit(buf, "%u\n", index);
166}
167static DEVICE_ATTR_RO(index);
168
169static umode_t zpci_index_is_visible(struct kobject *kobj,
170 struct attribute *attr, int n)
171{
172 return zpci_unique_uid ? attr->mode : 0;
173}
174
175static struct attribute *zpci_ident_attrs[] = {
176 &dev_attr_index.attr,
177 NULL,
178};
179
180static struct attribute_group zpci_ident_attr_group = {
181 .attrs = zpci_ident_attrs,
182 .is_visible = zpci_index_is_visible,
183};
184#endif
185
186static struct bin_attribute *zpci_bin_attrs[] = {
187 &bin_attr_util_string,
188 &bin_attr_report_error,
189 NULL,
190};
191
192static struct attribute *zpci_dev_attrs[] = {
193 &dev_attr_function_id.attr,
194 &dev_attr_function_handle.attr,
195 &dev_attr_pchid.attr,
196 &dev_attr_pfgid.attr,
197 &dev_attr_pft.attr,
198 &dev_attr_port.attr,
199 &dev_attr_vfn.attr,
200 &dev_attr_uid.attr,
201 &dev_attr_recover.attr,
202 &dev_attr_mio_enabled.attr,
203 &dev_attr_uid_is_unique.attr,
204 NULL,
205};
206
207static struct attribute_group zpci_attr_group = {
208 .attrs = zpci_dev_attrs,
209 .bin_attrs = zpci_bin_attrs,
210};
211
212static struct attribute *pfip_attrs[] = {
213 &dev_attr_segment0.attr,
214 &dev_attr_segment1.attr,
215 &dev_attr_segment2.attr,
216 &dev_attr_segment3.attr,
217 NULL,
218};
219static struct attribute_group pfip_attr_group = {
220 .name = "pfip",
221 .attrs = pfip_attrs,
222};
223
224const struct attribute_group *zpci_attr_groups[] = {
225 &zpci_attr_group,
226 &pfip_attr_group,
227#ifndef CONFIG_DMI
228 &zpci_ident_attr_group,
229#endif
230 NULL,
231};
232