blob: 430c14b006d17b71854ac24345a5e90140e8fdf1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jan Glauber1e8da952012-11-29 14:36:55 +01002/*
3 * Copyright IBM Corp. 2012
4 *
5 * Author(s):
6 * Jan Glauber <jang@linux.vnet.ibm.com>
7 */
8
Gerald Schaefer896cb7e2014-07-16 17:21:01 +02009#define KMSG_COMPONENT "zpci"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
Jan Glauber1e8da952012-11-29 14:36:55 +010011
12#include <linux/kernel.h>
13#include <linux/stat.h>
14#include <linux/pci.h>
15
Sebastian Ott368704a2015-11-27 11:22:57 +010016#include <asm/sclp.h>
17
Sebastian Ottb3469532014-04-16 16:10:18 +020018#define zpci_attr(name, fmt, member) \
19static ssize_t name##_show(struct device *dev, \
20 struct device_attribute *attr, char *buf) \
21{ \
Sebastian Ott198a5272015-06-23 14:06:35 +020022 struct zpci_dev *zdev = to_zpci(to_pci_dev(dev)); \
Sebastian Ottb3469532014-04-16 16:10:18 +020023 \
24 return sprintf(buf, fmt, zdev->member); \
25} \
26static DEVICE_ATTR_RO(name)
Jan Glauber1e8da952012-11-29 14:36:55 +010027
Sebastian Ottb3469532014-04-16 16:10:18 +020028zpci_attr(function_id, "0x%08x\n", fid);
29zpci_attr(function_handle, "0x%08x\n", fh);
30zpci_attr(pchid, "0x%04x\n", pchid);
31zpci_attr(pfgid, "0x%02x\n", pfgid);
Sebastian Ottac4995b2014-04-16 16:12:05 +020032zpci_attr(vfn, "0x%04x\n", vfn);
33zpci_attr(pft, "0x%02x\n", pft);
34zpci_attr(uid, "0x%x\n", uid);
35zpci_attr(segment0, "0x%02x\n", pfip[0]);
36zpci_attr(segment1, "0x%02x\n", pfip[1]);
37zpci_attr(segment2, "0x%02x\n", pfip[2]);
38zpci_attr(segment3, "0x%02x\n", pfip[3]);
Jan Glauber1e8da952012-11-29 14:36:55 +010039
Sebastian Ottb3469532014-04-16 16:10:18 +020040static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
Tejun Heo0b60f9e2014-02-03 14:03:04 -050041 const char *buf, size_t count)
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020042{
43 struct pci_dev *pdev = to_pci_dev(dev);
Sebastian Ott198a5272015-06-23 14:06:35 +020044 struct zpci_dev *zdev = to_zpci(pdev);
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020045 int ret;
46
Tejun Heo0b60f9e2014-02-03 14:03:04 -050047 if (!device_remove_file_self(dev, attr))
48 return count;
49
Sebastian Ott2a01bd12015-07-28 19:14:51 +020050 pci_lock_rescan_remove();
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020051 pci_stop_and_remove_bus_device(pdev);
52 ret = zpci_disable_device(zdev);
53 if (ret)
Sebastian Ott2a01bd12015-07-28 19:14:51 +020054 goto error;
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020055
56 ret = zpci_enable_device(zdev);
57 if (ret)
Sebastian Ott2a01bd12015-07-28 19:14:51 +020058 goto error;
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020059
60 pci_rescan_bus(zdev->bus);
Sebastian Ott2a01bd12015-07-28 19:14:51 +020061 pci_unlock_rescan_remove();
62
Tejun Heo0b60f9e2014-02-03 14:03:04 -050063 return count;
Sebastian Ott2a01bd12015-07-28 19:14:51 +020064
65error:
66 pci_unlock_rescan_remove();
67 return ret;
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020068}
Sebastian Ottb3469532014-04-16 16:10:18 +020069static DEVICE_ATTR_WO(recover);
Sebastian Ott0ff70ec2013-08-29 19:35:19 +020070
Sebastian Ottac4995b2014-04-16 16:12:05 +020071static ssize_t util_string_read(struct file *filp, struct kobject *kobj,
72 struct bin_attribute *attr, char *buf,
73 loff_t off, size_t count)
74{
75 struct device *dev = kobj_to_dev(kobj);
76 struct pci_dev *pdev = to_pci_dev(dev);
Sebastian Ott198a5272015-06-23 14:06:35 +020077 struct zpci_dev *zdev = to_zpci(pdev);
Sebastian Ottac4995b2014-04-16 16:12:05 +020078
79 return memory_read_from_buffer(buf, count, &off, zdev->util_str,
80 sizeof(zdev->util_str));
81}
82static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN);
Sebastian Ott368704a2015-11-27 11:22:57 +010083
84static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
85 struct bin_attribute *attr, char *buf,
86 loff_t off, size_t count)
87{
88 struct zpci_report_error_header *report = (void *) buf;
89 struct device *dev = kobj_to_dev(kobj);
90 struct pci_dev *pdev = to_pci_dev(dev);
91 struct zpci_dev *zdev = to_zpci(pdev);
92 int ret;
93
94 if (off || (count < sizeof(*report)))
95 return -EINVAL;
96
97 ret = sclp_pci_report(report, zdev->fh, zdev->fid);
98
99 return ret ? ret : count;
100}
101static BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAGE_SIZE);
102
Sebastian Ottac4995b2014-04-16 16:12:05 +0200103static struct bin_attribute *zpci_bin_attrs[] = {
104 &bin_attr_util_string,
Sebastian Ott368704a2015-11-27 11:22:57 +0100105 &bin_attr_report_error,
Sebastian Ottac4995b2014-04-16 16:12:05 +0200106 NULL,
107};
108
Sebastian Ott93065d02014-04-16 16:11:00 +0200109static struct attribute *zpci_dev_attrs[] = {
110 &dev_attr_function_id.attr,
111 &dev_attr_function_handle.attr,
112 &dev_attr_pchid.attr,
113 &dev_attr_pfgid.attr,
Sebastian Ottac4995b2014-04-16 16:12:05 +0200114 &dev_attr_pft.attr,
115 &dev_attr_vfn.attr,
116 &dev_attr_uid.attr,
Sebastian Ott93065d02014-04-16 16:11:00 +0200117 &dev_attr_recover.attr,
Jan Glauber1e8da952012-11-29 14:36:55 +0100118 NULL,
119};
Sebastian Ott93065d02014-04-16 16:11:00 +0200120static struct attribute_group zpci_attr_group = {
121 .attrs = zpci_dev_attrs,
Sebastian Ottac4995b2014-04-16 16:12:05 +0200122 .bin_attrs = zpci_bin_attrs,
Sebastian Ott93065d02014-04-16 16:11:00 +0200123};
Sebastian Ottac4995b2014-04-16 16:12:05 +0200124
125static struct attribute *pfip_attrs[] = {
126 &dev_attr_segment0.attr,
127 &dev_attr_segment1.attr,
128 &dev_attr_segment2.attr,
129 &dev_attr_segment3.attr,
130 NULL,
131};
132static struct attribute_group pfip_attr_group = {
133 .name = "pfip",
134 .attrs = pfip_attrs,
135};
136
Sebastian Ott93065d02014-04-16 16:11:00 +0200137const struct attribute_group *zpci_attr_groups[] = {
138 &zpci_attr_group,
Sebastian Ottac4995b2014-04-16 16:12:05 +0200139 &pfip_attr_group,
Sebastian Ott93065d02014-04-16 16:11:00 +0200140 NULL,
141};