Lines Matching +full:pci +full:- +full:domain
1 // SPDX-License-Identifier: GPL-2.0
20 #include <linux/pci.h>
33 /* zpci_bus_prepare_device - Prepare a zPCI function for scanning
36 * The PCI resources for the function are set up and added to its zbus and the
38 * a PCI bus created. If an error occurs the zPCI function is not enabled.
52 if (!zdev->has_resources) { in zpci_bus_prepare_device()
55 if (zdev->bars[i].res) in zpci_bus_prepare_device()
56 pci_bus_add_resource(zdev->zbus->bus, zdev->bars[i].res); in zpci_bus_prepare_device()
63 /* zpci_bus_scan_device - Scan a single device adding it to the PCI core
66 * Scans the PCI function making it available to the common PCI code.
79 pdev = pci_scan_single_device(zdev->zbus->bus, zdev->devfn); in zpci_bus_scan_device()
81 return -ENODEV; in zpci_bus_scan_device()
90 /* zpci_bus_remove_device - Removes the given zdev from the PCI core
91 * @zdev: the zdev to be removed from the PCI core
96 * API but is removed from the common code PCI bus, making it
101 struct zpci_bus *zbus = zdev->zbus; in zpci_bus_remove_device()
104 if (!zdev->zbus->bus) in zpci_bus_remove_device()
107 pdev = pci_get_slot(zbus->bus, zdev->devfn); in zpci_bus_remove_device()
110 pdev->error_state = pci_channel_io_perm_failure; in zpci_bus_remove_device()
111 if (pdev->is_virtfn) { in zpci_bus_remove_device()
112 zpci_iov_remove_virtfn(pdev, zdev->vfn); in zpci_bus_remove_device()
123 /* zpci_bus_scan_bus - Scan all configured zPCI functions on the bus
126 * Enables and scans all PCI functions on the bus making them available to the
127 * common PCI code. If a PCI function fails to be initialized an error will be
138 zdev = zbus->function[devfn]; in zpci_bus_scan_bus()
139 if (zdev && zdev->state == ZPCI_FN_STATE_CONFIGURED) { in zpci_bus_scan_bus()
142 ret = -EIO; in zpci_bus_scan_bus()
147 pci_scan_child_bus(zbus->bus); in zpci_bus_scan_bus()
148 pci_bus_add_devices(zbus->bus); in zpci_bus_scan_bus()
154 /* zpci_bus_scan_busses - Scan all registered busses
173 return !s390_pci_no_rid && zdev->rid_available && in zpci_bus_is_multifunction_root()
174 !zdev->vfn; in zpci_bus_is_multifunction_root()
177 /* zpci_bus_create_pci_bus - Create the PCI bus associated with this zbus
179 * @fr: PCI root function that will determine the bus's domain, and bus speed
180 * @ops: the pci operations
182 * The PCI function @fr determines the domain (its UID), multifunction property
190 int domain; in zpci_bus_create_pci_bus() local
192 domain = zpci_alloc_domain((u16)fr->uid); in zpci_bus_create_pci_bus()
193 if (domain < 0) in zpci_bus_create_pci_bus()
194 return domain; in zpci_bus_create_pci_bus()
196 zbus->domain_nr = domain; in zpci_bus_create_pci_bus()
197 zbus->multifunction = zpci_bus_is_multifunction_root(fr); in zpci_bus_create_pci_bus()
198 zbus->max_bus_speed = fr->max_bus_speed; in zpci_bus_create_pci_bus()
201 * Note that the zbus->resources are taken over and zbus->resources in zpci_bus_create_pci_bus()
204 bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources); in zpci_bus_create_pci_bus()
206 zpci_free_domain(zbus->domain_nr); in zpci_bus_create_pci_bus()
207 return -EFAULT; in zpci_bus_create_pci_bus()
210 zbus->bus = bus; in zpci_bus_create_pci_bus()
219 if (zbus->bus) { in zpci_bus_release()
221 pci_stop_root_bus(zbus->bus); in zpci_bus_release()
223 zpci_free_domain(zbus->domain_nr); in zpci_bus_release()
224 pci_free_resource_list(&zbus->resources); in zpci_bus_release()
226 pci_remove_root_bus(zbus->bus); in zpci_bus_release()
231 list_del(&zbus->bus_next); in zpci_bus_release()
238 kref_put(&zbus->kref, zpci_bus_release); in zpci_bus_put()
247 if (!zbus->multifunction) in zpci_bus_get()
249 if (topo_is_tid == zbus->topo_is_tid && topo == zbus->topo) { in zpci_bus_get()
250 kref_get(&zbus->kref); in zpci_bus_get()
268 zbus->topo = topo; in zpci_bus_alloc()
269 zbus->topo_is_tid = topo_is_tid; in zpci_bus_alloc()
270 INIT_LIST_HEAD(&zbus->bus_next); in zpci_bus_alloc()
272 list_add_tail(&zbus->bus_next, &zbus_list); in zpci_bus_alloc()
275 kref_init(&zbus->kref); in zpci_bus_alloc()
276 INIT_LIST_HEAD(&zbus->resources); in zpci_bus_alloc()
278 zbus->bus_resource.start = 0; in zpci_bus_alloc()
279 zbus->bus_resource.end = ZPCI_BUS_NR; in zpci_bus_alloc()
280 zbus->bus_resource.flags = IORESOURCE_BUS; in zpci_bus_alloc()
281 pci_add_resource(&zbus->resources, &zbus->bus_resource); in zpci_bus_alloc()
291 * With pdev->no_vf_scan the common PCI probing code does not in pcibios_bus_add_device()
294 if (zdev->vfn) { in pcibios_bus_add_device()
295 zpci_iov_setup_virtfn(zdev->zbus, pdev, zdev->vfn); in pcibios_bus_add_device()
296 pdev->no_command_memory = 1; in pcibios_bus_add_device()
302 int rc = -EINVAL; in zpci_bus_add_device()
304 if (zbus->multifunction) { in zpci_bus_add_device()
305 if (!zdev->rid_available) { in zpci_bus_add_device()
309 zdev->devfn = zdev->rid & ZPCI_RID_MASK_DEVFN; in zpci_bus_add_device()
312 if (zbus->function[zdev->devfn]) { in zpci_bus_add_device()
313 pr_err("devfn %04x is already assigned\n", zdev->devfn); in zpci_bus_add_device()
316 zdev->zbus = zbus; in zpci_bus_add_device()
317 zbus->function[zdev->devfn] = zdev; in zpci_bus_add_device()
323 zdev->has_hp_slot = 1; in zpci_bus_add_device()
328 zbus->function[zdev->devfn] = NULL; in zpci_bus_add_device()
329 zdev->zbus = NULL; in zpci_bus_add_device()
330 zpci_nb_devices--; in zpci_bus_add_device()
347 bool topo_is_tid = zdev->tid_avail; in zpci_bus_device_register()
349 int topo, rc = -EBADF; in zpci_bus_device_register()
352 pr_warn("Adding PCI function %08x failed because the configured limit of %d is reached\n", in zpci_bus_device_register()
353 zdev->fid, ZPCI_NR_DEVICES); in zpci_bus_device_register()
354 return -ENOSPC; in zpci_bus_device_register()
357 topo = topo_is_tid ? zdev->tid : zdev->pchid; in zpci_bus_device_register()
360 * An isolated VF gets its own domain/bus even if there exists in zpci_bus_device_register()
361 * a matching domain/bus already in zpci_bus_device_register()
371 return -ENOMEM; in zpci_bus_device_register()
374 if (!zbus->bus) { in zpci_bus_device_register()
375 /* The UID of the first PCI function registered with a zpci_bus in zpci_bus_device_register()
376 * is used as the domain number for that bus. Currently there in zpci_bus_device_register()
377 * is exactly one zpci_bus per domain. in zpci_bus_device_register()
391 pr_err("Adding PCI function %08x failed\n", zdev->fid); in zpci_bus_device_register()
398 struct zpci_bus *zbus = zdev->zbus; in zpci_bus_device_unregister()
400 zpci_nb_devices--; in zpci_bus_device_unregister()
401 zbus->function[zdev->devfn] = NULL; in zpci_bus_device_unregister()