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>
15 #define zpci_attr(name, fmt, member) \
16 static ssize_t name##_show(struct device *dev, \
17 struct device_attribute *attr, char *buf) \
19 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev)); \
21 return sprintf(buf, fmt, zdev->member); \
23 static DEVICE_ATTR_RO(name)
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
);
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]);
37 static ssize_t
recover_store(struct device
*dev
, struct device_attribute
*attr
,
38 const char *buf
, size_t count
)
40 struct pci_dev
*pdev
= to_pci_dev(dev
);
41 struct zpci_dev
*zdev
= get_zdev(pdev
);
44 if (!device_remove_file_self(dev
, attr
))
47 pci_stop_and_remove_bus_device(pdev
);
48 ret
= zpci_disable_device(zdev
);
52 ret
= zpci_enable_device(zdev
);
56 pci_rescan_bus(zdev
->bus
);
59 static DEVICE_ATTR_WO(recover
);
61 static ssize_t
util_string_read(struct file
*filp
, struct kobject
*kobj
,
62 struct bin_attribute
*attr
, char *buf
,
63 loff_t off
, size_t count
)
65 struct device
*dev
= kobj_to_dev(kobj
);
66 struct pci_dev
*pdev
= to_pci_dev(dev
);
67 struct zpci_dev
*zdev
= get_zdev(pdev
);
69 return memory_read_from_buffer(buf
, count
, &off
, zdev
->util_str
,
70 sizeof(zdev
->util_str
));
72 static BIN_ATTR_RO(util_string
, CLP_UTIL_STR_LEN
);
73 static struct bin_attribute
*zpci_bin_attrs
[] = {
74 &bin_attr_util_string
,
78 static struct attribute
*zpci_dev_attrs
[] = {
79 &dev_attr_function_id
.attr
,
80 &dev_attr_function_handle
.attr
,
86 &dev_attr_recover
.attr
,
89 static struct attribute_group zpci_attr_group
= {
90 .attrs
= zpci_dev_attrs
,
91 .bin_attrs
= zpci_bin_attrs
,
94 static struct attribute
*pfip_attrs
[] = {
95 &dev_attr_segment0
.attr
,
96 &dev_attr_segment1
.attr
,
97 &dev_attr_segment2
.attr
,
98 &dev_attr_segment3
.attr
,
101 static struct attribute_group pfip_attr_group
= {
106 const struct attribute_group
*zpci_attr_groups
[] = {