2 * Copyright IBM Corp. 2012
5 * Jan Glauber <jang@linux.vnet.ibm.com>
8 #define COMPONENT "zPCI"
9 #define pr_fmt(fmt) 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);
30 static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
31 const char *buf, size_t count)
33 struct pci_dev *pdev = to_pci_dev(dev);
34 struct zpci_dev *zdev = get_zdev(pdev);
37 if (!device_remove_file_self(dev, attr))
40 pci_stop_and_remove_bus_device(pdev);
41 ret = zpci_disable_device(zdev);
45 ret = zpci_enable_device(zdev);
49 pci_rescan_bus(zdev->bus);
52 static DEVICE_ATTR_WO(recover);
54 static struct attribute *zpci_dev_attrs[] = {
55 &dev_attr_function_id.attr,
56 &dev_attr_function_handle.attr,
59 &dev_attr_recover.attr,
62 static struct attribute_group zpci_attr_group = {
63 .attrs = zpci_dev_attrs,
65 const struct attribute_group *zpci_attr_groups[] = {