2 * Copyright IBM Corp. 2012
5 * Jan Glauber <jang@linux.vnet.ibm.com>
8 #define KMSG_COMPONENT "zpci"
9 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 #include <linux/kernel.h>
12 #include <linux/stat.h>
13 #include <linux/pci.h>
17 #define zpci_attr(name, fmt, member) \
18 static ssize_t name##_show(struct device *dev, \
19 struct device_attribute *attr, char *buf) \
21 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); \
23 return sprintf(buf, fmt, zdev->member); \
25 static DEVICE_ATTR_RO(name)
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
);
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]);
39 static ssize_t
recover_store(struct device
*dev
, struct device_attribute
*attr
,
40 const char *buf
, size_t count
)
42 struct pci_dev
*pdev
= to_pci_dev(dev
);
43 struct zpci_dev
*zdev
= to_zpci(pdev
);
46 if (!device_remove_file_self(dev
, attr
))
49 pci_lock_rescan_remove();
50 pci_stop_and_remove_bus_device(pdev
);
51 ret
= zpci_disable_device(zdev
);
55 ret
= zpci_enable_device(zdev
);
59 pci_rescan_bus(zdev
->bus
);
60 pci_unlock_rescan_remove();
65 pci_unlock_rescan_remove();
68 static DEVICE_ATTR_WO(recover
);
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
)
74 struct device
*dev
= kobj_to_dev(kobj
);
75 struct pci_dev
*pdev
= to_pci_dev(dev
);
76 struct zpci_dev
*zdev
= to_zpci(pdev
);
78 return memory_read_from_buffer(buf
, count
, &off
, zdev
->util_str
,
79 sizeof(zdev
->util_str
));
81 static BIN_ATTR_RO(util_string
, CLP_UTIL_STR_LEN
);
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
)
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
);
93 if (off
|| (count
< sizeof(*report
)))
96 ret
= sclp_pci_report(report
, zdev
->fh
, zdev
->fid
);
98 return ret
? ret
: count
;
100 static BIN_ATTR(report_error
, S_IWUSR
, NULL
, report_error_write
, PAGE_SIZE
);
102 static struct bin_attribute
*zpci_bin_attrs
[] = {
103 &bin_attr_util_string
,
104 &bin_attr_report_error
,
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
,
116 &dev_attr_recover
.attr
,
119 static struct attribute_group zpci_attr_group
= {
120 .attrs
= zpci_dev_attrs
,
121 .bin_attrs
= zpci_bin_attrs
,
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
,
131 static struct attribute_group pfip_attr_group
= {
136 const struct attribute_group
*zpci_attr_groups
[] = {