blob: fa3ce891e5976196d1d4225fbf286226509266e1 [file] [log] [blame]
Jan Glauber1e8da952012-11-29 14:36:55 +01001/*
2 * Copyright IBM Corp. 2012
3 *
4 * Author(s):
5 * Jan Glauber <jang@linux.vnet.ibm.com>
6 */
7
Gerald Schaefer896cb7e2014-07-16 17:21:01 +02008#define KMSG_COMPONENT "zpci"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
Jan Glauber1e8da952012-11-29 14:36:55 +010010
11#include <linux/kernel.h>
12#include <linux/stat.h>
13#include <linux/pci.h>
14
Sebastian Ottb3469532014-04-16 16:10:18 +020015#define zpci_attr(name, fmt, member) \
16static 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} \
23static DEVICE_ATTR_RO(name)
Jan Glauber1e8da952012-11-29 14:36:55 +010024
Sebastian Ottb3469532014-04-16 16:10:18 +020025zpci_attr(function_id, "0x%08x\n", fid);
26zpci_attr(function_handle, "0x%08x\n", fh);
27zpci_attr(pchid, "0x%04x\n", pchid);
28zpci_attr(pfgid, "0x%02x\n", pfgid);
Sebastian Ottac4995b2014-04-16 16:12:05 +020029zpci_attr(vfn, "0x%04x\n", vfn);
30zpci_attr(pft, "0x%02x\n", pft);
31zpci_attr(uid, "0x%x\n", uid);
32zpci_attr(segment0, "0x%02x\n", pfip[0]);
33zpci_attr(segment1, "0x%02x\n", pfip[1]);
34zpci_attr(segment2, "0x%02x\n", pfip[2]);
35zpci_attr(segment3, "0x%02x\n", pfip[3]);
Jan Glauber1e8da952012-11-29 14:36:55 +010036
Sebastian Ottb3469532014-04-16 16:10:18 +020037static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
Tejun Heo0b60f9e2014-02-03 14:03:04 -050038 const char *buf, size_t count)
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020039{
40 struct pci_dev *pdev = to_pci_dev(dev);
41 struct zpci_dev *zdev = get_zdev(pdev);
42 int ret;
43
Tejun Heo0b60f9e2014-02-03 14:03:04 -050044 if (!device_remove_file_self(dev, attr))
45 return count;
46
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020047 pci_stop_and_remove_bus_device(pdev);
48 ret = zpci_disable_device(zdev);
49 if (ret)
Tejun Heo0b60f9e2014-02-03 14:03:04 -050050 return ret;
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020051
52 ret = zpci_enable_device(zdev);
53 if (ret)
Tejun Heo0b60f9e2014-02-03 14:03:04 -050054 return ret;
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020055
56 pci_rescan_bus(zdev->bus);
Tejun Heo0b60f9e2014-02-03 14:03:04 -050057 return count;
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020058}
Sebastian Ottb3469532014-04-16 16:10:18 +020059static DEVICE_ATTR_WO(recover);
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020060
Sebastian Ottac4995b2014-04-16 16:12:05 +020061static 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)
64{
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);
68
69 return memory_read_from_buffer(buf, count, &off, zdev->util_str,
70 sizeof(zdev->util_str));
71}
72static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN);
73static struct bin_attribute *zpci_bin_attrs[] = {
74 &bin_attr_util_string,
75 NULL,
76};
77
Sebastian Ott93065d02014-04-16 16:11:00 +020078static struct attribute *zpci_dev_attrs[] = {
79 &dev_attr_function_id.attr,
80 &dev_attr_function_handle.attr,
81 &dev_attr_pchid.attr,
82 &dev_attr_pfgid.attr,
Sebastian Ottac4995b2014-04-16 16:12:05 +020083 &dev_attr_pft.attr,
84 &dev_attr_vfn.attr,
85 &dev_attr_uid.attr,
Sebastian Ott93065d02014-04-16 16:11:00 +020086 &dev_attr_recover.attr,
Jan Glauber1e8da952012-11-29 14:36:55 +010087 NULL,
88};
Sebastian Ott93065d02014-04-16 16:11:00 +020089static struct attribute_group zpci_attr_group = {
90 .attrs = zpci_dev_attrs,
Sebastian Ottac4995b2014-04-16 16:12:05 +020091 .bin_attrs = zpci_bin_attrs,
Sebastian Ott93065d02014-04-16 16:11:00 +020092};
Sebastian Ottac4995b2014-04-16 16:12:05 +020093
94static struct attribute *pfip_attrs[] = {
95 &dev_attr_segment0.attr,
96 &dev_attr_segment1.attr,
97 &dev_attr_segment2.attr,
98 &dev_attr_segment3.attr,
99 NULL,
100};
101static struct attribute_group pfip_attr_group = {
102 .name = "pfip",
103 .attrs = pfip_attrs,
104};
105
Sebastian Ott93065d02014-04-16 16:11:00 +0200106const struct attribute_group *zpci_attr_groups[] = {
107 &zpci_attr_group,
Sebastian Ottac4995b2014-04-16 16:12:05 +0200108 &pfip_attr_group,
Sebastian Ott93065d02014-04-16 16:11:00 +0200109 NULL,
110};