f23da1c0a489be80d07b29a1741e4ccab1569e96
[deliverable/linux.git] / arch / s390 / pci / pci_sysfs.c
1 /*
2 * Copyright IBM Corp. 2012
3 *
4 * Author(s):
5 * Jan Glauber <jang@linux.vnet.ibm.com>
6 */
7
8 #define COMPONENT "zPCI"
9 #define pr_fmt(fmt) COMPONENT ": " fmt
10
11 #include <linux/kernel.h>
12 #include <linux/stat.h>
13 #include <linux/pci.h>
14
15 #define zpci_attr(name, fmt, member) \
16 static ssize_t name##_show(struct device *dev, \
17 struct device_attribute *attr, char *buf) \
18 { \
19 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev)); \
20 \
21 return sprintf(buf, fmt, zdev->member); \
22 } \
23 static DEVICE_ATTR_RO(name)
24
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
30 static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
31 const char *buf, size_t count)
32 {
33 struct pci_dev *pdev = to_pci_dev(dev);
34 struct zpci_dev *zdev = get_zdev(pdev);
35 int ret;
36
37 if (!device_remove_file_self(dev, attr))
38 return count;
39
40 pci_stop_and_remove_bus_device(pdev);
41 ret = zpci_disable_device(zdev);
42 if (ret)
43 return ret;
44
45 ret = zpci_enable_device(zdev);
46 if (ret)
47 return ret;
48
49 pci_rescan_bus(zdev->bus);
50 return count;
51 }
52 static DEVICE_ATTR_WO(recover);
53
54 static struct attribute *zpci_dev_attrs[] = {
55 &dev_attr_function_id.attr,
56 &dev_attr_function_handle.attr,
57 &dev_attr_pchid.attr,
58 &dev_attr_pfgid.attr,
59 &dev_attr_recover.attr,
60 NULL,
61 };
62 static struct attribute_group zpci_attr_group = {
63 .attrs = zpci_dev_attrs,
64 };
65 const struct attribute_group *zpci_attr_groups[] = {
66 &zpci_attr_group,
67 NULL,
68 };
This page took 0.031479 seconds and 5 git commands to generate.