~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/s390/pci/pci_sysfs.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Copyright IBM Corp. 2012
  4  *
  5  * Author(s):
  6  *   Jan Glauber <jang@linux.vnet.ibm.com>
  7  */
  8 
  9 #define KMSG_COMPONENT "zpci"
 10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 11 
 12 #include <linux/kernel.h>
 13 #include <linux/stat.h>
 14 #include <linux/pci.h>
 15 
 16 #include "../../../drivers/pci/pci.h"
 17 
 18 #include <asm/sclp.h>
 19 
 20 #define zpci_attr(name, fmt, member)                                    \
 21 static ssize_t name##_show(struct device *dev,                          \
 22                            struct device_attribute *attr, char *buf)    \
 23 {                                                                       \
 24         struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));               \
 25                                                                         \
 26         return sprintf(buf, fmt, zdev->member);                         \
 27 }                                                                       \
 28 static DEVICE_ATTR_RO(name)
 29 
 30 zpci_attr(function_id, "0x%08x\n", fid);
 31 zpci_attr(function_handle, "0x%08x\n", fh);
 32 zpci_attr(pchid, "0x%04x\n", pchid);
 33 zpci_attr(pfgid, "0x%02x\n", pfgid);
 34 zpci_attr(vfn, "0x%04x\n", vfn);
 35 zpci_attr(pft, "0x%02x\n", pft);
 36 zpci_attr(port, "%d\n", port);
 37 zpci_attr(uid, "0x%x\n", uid);
 38 zpci_attr(segment0, "0x%02x\n", pfip[0]);
 39 zpci_attr(segment1, "0x%02x\n", pfip[1]);
 40 zpci_attr(segment2, "0x%02x\n", pfip[2]);
 41 zpci_attr(segment3, "0x%02x\n", pfip[3]);
 42 
 43 static ssize_t mio_enabled_show(struct device *dev,
 44                                 struct device_attribute *attr, char *buf)
 45 {
 46         struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
 47 
 48         return sprintf(buf, zpci_use_mio(zdev) ? "1\n" : "\n");
 49 }
 50 static DEVICE_ATTR_RO(mio_enabled);
 51 
 52 static int _do_recover(struct pci_dev *pdev, struct zpci_dev *zdev)
 53 {
 54         u8 status;
 55         int ret;
 56 
 57         pci_stop_and_remove_bus_device(pdev);
 58         if (zdev_enabled(zdev)) {
 59                 ret = zpci_disable_device(zdev);
 60                 /*
 61                  * Due to a z/VM vs LPAR inconsistency in the error
 62                  * state the FH may indicate an enabled device but
 63                  * disable says the device is already disabled don't
 64                  * treat it as an error here.
 65                  */
 66                 if (ret == -EINVAL)
 67                         ret = 0;
 68                 if (ret)
 69                         return ret;
 70         }
 71 
 72         ret = zpci_enable_device(zdev);
 73         if (ret)
 74                 return ret;
 75 
 76         if (zdev->dma_table) {
 77                 ret = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
 78                                          virt_to_phys(zdev->dma_table), &status);
 79                 if (ret)
 80                         zpci_disable_device(zdev);
 81         }
 82         return ret;
 83 }
 84 
 85 static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
 86                              const char *buf, size_t count)
 87 {
 88         struct kernfs_node *kn;
 89         struct pci_dev *pdev = to_pci_dev(dev);
 90         struct zpci_dev *zdev = to_zpci(pdev);
 91         int ret = 0;
 92 
 93         /* Can't use device_remove_self() here as that would lead us to lock
 94          * the pci_rescan_remove_lock while holding the device' kernfs lock.
 95          * This would create a possible deadlock with disable_slot() which is
 96          * not directly protected by the device' kernfs lock but takes it
 97          * during the device removal which happens under
 98          * pci_rescan_remove_lock.
 99          *
100          * This is analogous to sdev_store_delete() in
101          * drivers/scsi/scsi_sysfs.c
102          */
103         kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
104         WARN_ON_ONCE(!kn);
105 
106         /* Device needs to be configured and state must not change */
107         mutex_lock(&zdev->state_lock);
108         if (zdev->state != ZPCI_FN_STATE_CONFIGURED)
109                 goto out;
110 
111         /* device_remove_file() serializes concurrent calls ignoring all but
112          * the first
113          */
114         device_remove_file(dev, attr);
115 
116         /* A concurrent call to recover_store() may slip between
117          * sysfs_break_active_protection() and the sysfs file removal.
118          * Once it unblocks from pci_lock_rescan_remove() the original pdev
119          * will already be removed.
120          */
121         pci_lock_rescan_remove();
122         if (pci_dev_is_added(pdev)) {
123                 ret = _do_recover(pdev, zdev);
124         }
125         pci_rescan_bus(zdev->zbus->bus);
126         pci_unlock_rescan_remove();
127 
128 out:
129         mutex_unlock(&zdev->state_lock);
130         if (kn)
131                 sysfs_unbreak_active_protection(kn);
132         return ret ? ret : count;
133 }
134 static DEVICE_ATTR_WO(recover);
135 
136 static ssize_t util_string_read(struct file *filp, struct kobject *kobj,
137                                 struct bin_attribute *attr, char *buf,
138                                 loff_t off, size_t count)
139 {
140         struct device *dev = kobj_to_dev(kobj);
141         struct pci_dev *pdev = to_pci_dev(dev);
142         struct zpci_dev *zdev = to_zpci(pdev);
143 
144         return memory_read_from_buffer(buf, count, &off, zdev->util_str,
145                                        sizeof(zdev->util_str));
146 }
147 static BIN_ATTR_RO(util_string, CLP_UTIL_STR_LEN);
148 
149 static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
150                                   struct bin_attribute *attr, char *buf,
151                                   loff_t off, size_t count)
152 {
153         struct zpci_report_error_header *report = (void *) buf;
154         struct device *dev = kobj_to_dev(kobj);
155         struct pci_dev *pdev = to_pci_dev(dev);
156         struct zpci_dev *zdev = to_zpci(pdev);
157         int ret;
158 
159         if (off || (count < sizeof(*report)))
160                 return -EINVAL;
161 
162         ret = sclp_pci_report(report, zdev->fh, zdev->fid);
163 
164         return ret ? ret : count;
165 }
166 static BIN_ATTR(report_error, S_IWUSR, NULL, report_error_write, PAGE_SIZE);
167 
168 static ssize_t uid_is_unique_show(struct device *dev,
169                                   struct device_attribute *attr, char *buf)
170 {
171         return sysfs_emit(buf, "%d\n", zpci_unique_uid ? 1 : 0);
172 }
173 static DEVICE_ATTR_RO(uid_is_unique);
174 
175 /* analogous to smbios index */
176 static ssize_t index_show(struct device *dev,
177                           struct device_attribute *attr, char *buf)
178 {
179         struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
180         u32 index = ~0;
181 
182         if (zpci_unique_uid)
183                 index = zdev->uid;
184 
185         return sysfs_emit(buf, "%u\n", index);
186 }
187 static DEVICE_ATTR_RO(index);
188 
189 static umode_t zpci_index_is_visible(struct kobject *kobj,
190                                      struct attribute *attr, int n)
191 {
192         return zpci_unique_uid ? attr->mode : 0;
193 }
194 
195 static struct attribute *zpci_ident_attrs[] = {
196         &dev_attr_index.attr,
197         NULL,
198 };
199 
200 static struct attribute_group zpci_ident_attr_group = {
201         .attrs = zpci_ident_attrs,
202         .is_visible = zpci_index_is_visible,
203 };
204 
205 static struct bin_attribute *zpci_bin_attrs[] = {
206         &bin_attr_util_string,
207         &bin_attr_report_error,
208         NULL,
209 };
210 
211 static struct attribute *zpci_dev_attrs[] = {
212         &dev_attr_function_id.attr,
213         &dev_attr_function_handle.attr,
214         &dev_attr_pchid.attr,
215         &dev_attr_pfgid.attr,
216         &dev_attr_pft.attr,
217         &dev_attr_port.attr,
218         &dev_attr_vfn.attr,
219         &dev_attr_uid.attr,
220         &dev_attr_recover.attr,
221         &dev_attr_mio_enabled.attr,
222         &dev_attr_uid_is_unique.attr,
223         NULL,
224 };
225 
226 static struct attribute_group zpci_attr_group = {
227         .attrs = zpci_dev_attrs,
228         .bin_attrs = zpci_bin_attrs,
229 };
230 
231 static struct attribute *pfip_attrs[] = {
232         &dev_attr_segment0.attr,
233         &dev_attr_segment1.attr,
234         &dev_attr_segment2.attr,
235         &dev_attr_segment3.attr,
236         NULL,
237 };
238 static struct attribute_group pfip_attr_group = {
239         .name = "pfip",
240         .attrs = pfip_attrs,
241 };
242 
243 const struct attribute_group *zpci_attr_groups[] = {
244         &zpci_attr_group,
245         &pfip_attr_group,
246         &zpci_ident_attr_group,
247         NULL,
248 };
249 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php