blob: e99a2557f1865f5c50e246b1e52b08227d2f83f5 [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
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
15static ssize_t show_fid(struct device *dev, struct device_attribute *attr,
16 char *buf)
17{
Sebastian Ott92948962013-05-17 16:33:40 +020018 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
Jan Glauber1e8da952012-11-29 14:36:55 +010019
Sebastian Ott80b054b2013-06-05 16:08:07 +020020 return sprintf(buf, "0x%08x\n", zdev->fid);
Jan Glauber1e8da952012-11-29 14:36:55 +010021}
22static DEVICE_ATTR(function_id, S_IRUGO, show_fid, NULL);
23
24static ssize_t show_fh(struct device *dev, struct device_attribute *attr,
25 char *buf)
26{
Sebastian Ott92948962013-05-17 16:33:40 +020027 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
Jan Glauber1e8da952012-11-29 14:36:55 +010028
Sebastian Ott80b054b2013-06-05 16:08:07 +020029 return sprintf(buf, "0x%08x\n", zdev->fh);
Jan Glauber1e8da952012-11-29 14:36:55 +010030}
31static DEVICE_ATTR(function_handle, S_IRUGO, show_fh, NULL);
32
33static ssize_t show_pchid(struct device *dev, struct device_attribute *attr,
34 char *buf)
35{
Sebastian Ott92948962013-05-17 16:33:40 +020036 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
Jan Glauber1e8da952012-11-29 14:36:55 +010037
Sebastian Ott80b054b2013-06-05 16:08:07 +020038 return sprintf(buf, "0x%04x\n", zdev->pchid);
Jan Glauber1e8da952012-11-29 14:36:55 +010039}
40static DEVICE_ATTR(pchid, S_IRUGO, show_pchid, NULL);
41
42static ssize_t show_pfgid(struct device *dev, struct device_attribute *attr,
43 char *buf)
44{
Sebastian Ott92948962013-05-17 16:33:40 +020045 struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
Jan Glauber1e8da952012-11-29 14:36:55 +010046
Sebastian Ott80b054b2013-06-05 16:08:07 +020047 return sprintf(buf, "0x%02x\n", zdev->pfgid);
Jan Glauber1e8da952012-11-29 14:36:55 +010048}
49static DEVICE_ATTR(pfgid, S_IRUGO, show_pfgid, NULL);
50
51static struct device_attribute *zpci_dev_attrs[] = {
52 &dev_attr_function_id,
53 &dev_attr_function_handle,
54 &dev_attr_pchid,
55 &dev_attr_pfgid,
56 NULL,
57};
58
59int zpci_sysfs_add_device(struct device *dev)
60{
61 int i, rc = 0;
62
63 for (i = 0; zpci_dev_attrs[i]; i++) {
64 rc = device_create_file(dev, zpci_dev_attrs[i]);
65 if (rc)
66 goto error;
67 }
68 return 0;
69
70error:
71 while (--i >= 0)
72 device_remove_file(dev, zpci_dev_attrs[i]);
73 return rc;
74}
75
76void zpci_sysfs_remove_device(struct device *dev)
77{
78 int i;
79
80 for (i = 0; zpci_dev_attrs[i]; i++)
81 device_remove_file(dev, zpci_dev_attrs[i]);
82}