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 static ssize_t show_fid(struct device *dev, struct device_attribute *attr, 16 char *buf) 17 { 18 struct zpci_dev *zdev = get_zdev(container_of(dev, struct pci_dev, dev)); 19 20 sprintf(buf, "0x%08x\n", zdev->fid); 21 return strlen(buf); 22 } 23 static DEVICE_ATTR(function_id, S_IRUGO, show_fid, NULL); 24 25 static ssize_t show_fh(struct device *dev, struct device_attribute *attr, 26 char *buf) 27 { 28 struct zpci_dev *zdev = get_zdev(container_of(dev, struct pci_dev, dev)); 29 30 sprintf(buf, "0x%08x\n", zdev->fh); 31 return strlen(buf); 32 } 33 static DEVICE_ATTR(function_handle, S_IRUGO, show_fh, NULL); 34 35 static ssize_t show_pchid(struct device *dev, struct device_attribute *attr, 36 char *buf) 37 { 38 struct zpci_dev *zdev = get_zdev(container_of(dev, struct pci_dev, dev)); 39 40 sprintf(buf, "0x%04x\n", zdev->pchid); 41 return strlen(buf); 42 } 43 static DEVICE_ATTR(pchid, S_IRUGO, show_pchid, NULL); 44 45 static ssize_t show_pfgid(struct device *dev, struct device_attribute *attr, 46 char *buf) 47 { 48 struct zpci_dev *zdev = get_zdev(container_of(dev, struct pci_dev, dev)); 49 50 sprintf(buf, "0x%02x\n", zdev->pfgid); 51 return strlen(buf); 52 } 53 static DEVICE_ATTR(pfgid, S_IRUGO, show_pfgid, NULL); 54 55 static struct device_attribute *zpci_dev_attrs[] = { 56 &dev_attr_function_id, 57 &dev_attr_function_handle, 58 &dev_attr_pchid, 59 &dev_attr_pfgid, 60 NULL, 61 }; 62 63 int zpci_sysfs_add_device(struct device *dev) 64 { 65 int i, rc = 0; 66 67 for (i = 0; zpci_dev_attrs[i]; i++) { 68 rc = device_create_file(dev, zpci_dev_attrs[i]); 69 if (rc) 70 goto error; 71 } 72 return 0; 73 74 error: 75 while (--i >= 0) 76 device_remove_file(dev, zpci_dev_attrs[i]); 77 return rc; 78 } 79 80 void zpci_sysfs_remove_device(struct device *dev) 81 { 82 int i; 83 84 for (i = 0; zpci_dev_attrs[i]; i++) 85 device_remove_file(dev, zpci_dev_attrs[i]); 86 } 87