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 static ssize_t show_fid(struct device *dev, struct device_attribute *attr,
18 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
20 return sprintf(buf, "0x%08x\n", zdev->fid);
22 static DEVICE_ATTR(function_id, S_IRUGO, show_fid, NULL);
24 static ssize_t show_fh(struct device *dev, struct device_attribute *attr,
27 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
29 return sprintf(buf, "0x%08x\n", zdev->fh);
31 static DEVICE_ATTR(function_handle, S_IRUGO, show_fh, NULL);
33 static ssize_t show_pchid(struct device *dev, struct device_attribute *attr,
36 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
38 return sprintf(buf, "0x%04x\n", zdev->pchid);
40 static DEVICE_ATTR(pchid, S_IRUGO, show_pchid, NULL);
42 static ssize_t show_pfgid(struct device *dev, struct device_attribute *attr,
45 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
47 return sprintf(buf, "0x%02x\n", zdev->pfgid);
49 static DEVICE_ATTR(pfgid, S_IRUGO, show_pfgid, NULL);
51 static void recover_callback(struct device *dev)
53 struct pci_dev *pdev = to_pci_dev(dev);
54 struct zpci_dev *zdev = get_zdev(pdev);
57 pci_stop_and_remove_bus_device(pdev);
58 ret = zpci_disable_device(zdev);
62 ret = zpci_enable_device(zdev);
66 pci_rescan_bus(zdev->bus);
69 static ssize_t store_recover(struct device *dev, struct device_attribute *attr,
70 const char *buf, size_t count)
72 int rc = device_schedule_callback(dev, recover_callback);
73 return rc ? rc : count;
75 static DEVICE_ATTR(recover, S_IWUSR, NULL, store_recover);
77 static struct device_attribute *zpci_dev_attrs[] = {
78 &dev_attr_function_id,
79 &dev_attr_function_handle,
86 int zpci_sysfs_add_device(struct device *dev)
90 for (i = 0; zpci_dev_attrs[i]; i++) {
91 rc = device_create_file(dev, zpci_dev_attrs[i]);
99 device_remove_file(dev, zpci_dev_attrs[i]);
103 void zpci_sysfs_remove_device(struct device *dev)
107 for (i = 0; zpci_dev_attrs[i]; i++)
108 device_remove_file(dev, zpci_dev_attrs[i]);