Lines Matching +full:pci +full:- +full:domain

1 // SPDX-License-Identifier: GPL-2.0
20 #include <linux/pci.h>
22 #include <linux/dma-direct.h>
34 /* zpci_bus_prepare_device - Prepare a zPCI function for scanning
37 * The PCI resources for the function are set up and added to its zbus and the
39 * a PCI bus created. If an error occurs the zPCI function is not enabled.
53 if (!zdev->has_resources) { in zpci_bus_prepare_device()
56 if (zdev->bars[i].res) in zpci_bus_prepare_device()
57 pci_bus_add_resource(zdev->zbus->bus, zdev->bars[i].res); in zpci_bus_prepare_device()
64 /* zpci_bus_scan_device - Scan a single device adding it to the PCI core
67 * Scans the PCI function making it available to the common PCI code.
80 pdev = pci_scan_single_device(zdev->zbus->bus, zdev->devfn); in zpci_bus_scan_device()
82 return -ENODEV; in zpci_bus_scan_device()
91 /* zpci_bus_remove_device - Removes the given zdev from the PCI core
92 * @zdev: the zdev to be removed from the PCI core
97 * API but is removed from the common code PCI bus, making it
102 struct zpci_bus *zbus = zdev->zbus; in zpci_bus_remove_device()
105 if (!zdev->zbus->bus) in zpci_bus_remove_device()
108 pdev = pci_get_slot(zbus->bus, zdev->devfn); in zpci_bus_remove_device()
111 pdev->error_state = pci_channel_io_perm_failure; in zpci_bus_remove_device()
112 if (pdev->is_virtfn) { in zpci_bus_remove_device()
113 zpci_iov_remove_virtfn(pdev, zdev->vfn); in zpci_bus_remove_device()
124 /* zpci_bus_scan_bus - Scan all configured zPCI functions on the bus
127 * Enables and scans all PCI functions on the bus making them available to the
128 * common PCI code. If a PCI function fails to be initialized an error will be
139 zdev = zbus->function[devfn]; in zpci_bus_scan_bus()
140 if (zdev && zdev->state == ZPCI_FN_STATE_CONFIGURED) { in zpci_bus_scan_bus()
143 ret = -EIO; in zpci_bus_scan_bus()
148 pci_scan_child_bus(zbus->bus); in zpci_bus_scan_bus()
149 pci_bus_add_devices(zbus->bus); in zpci_bus_scan_bus()
155 /* zpci_bus_scan_busses - Scan all registered busses
174 return !s390_pci_no_rid && zdev->rid_available && in zpci_bus_is_multifunction_root()
175 !zdev->vfn; in zpci_bus_is_multifunction_root()
178 /* zpci_bus_create_pci_bus - Create the PCI bus associated with this zbus
180 * @fr: PCI root function that will determine the bus's domain, and bus speed
181 * @ops: the pci operations
183 * The PCI function @fr determines the domain (its UID), multifunction property
191 int domain; in zpci_bus_create_pci_bus() local
193 domain = zpci_alloc_domain((u16)fr->uid); in zpci_bus_create_pci_bus()
194 if (domain < 0) in zpci_bus_create_pci_bus()
195 return domain; in zpci_bus_create_pci_bus()
197 zbus->domain_nr = domain; in zpci_bus_create_pci_bus()
198 zbus->multifunction = zpci_bus_is_multifunction_root(fr); in zpci_bus_create_pci_bus()
199 zbus->max_bus_speed = fr->max_bus_speed; in zpci_bus_create_pci_bus()
202 * Note that the zbus->resources are taken over and zbus->resources in zpci_bus_create_pci_bus()
205 bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources); in zpci_bus_create_pci_bus()
207 zpci_free_domain(zbus->domain_nr); in zpci_bus_create_pci_bus()
208 return -EFAULT; in zpci_bus_create_pci_bus()
211 zbus->bus = bus; in zpci_bus_create_pci_bus()
220 if (zbus->bus) { in zpci_bus_release()
222 pci_stop_root_bus(zbus->bus); in zpci_bus_release()
224 zpci_free_domain(zbus->domain_nr); in zpci_bus_release()
225 pci_free_resource_list(&zbus->resources); in zpci_bus_release()
227 pci_remove_root_bus(zbus->bus); in zpci_bus_release()
232 list_del(&zbus->bus_next); in zpci_bus_release()
239 kref_put(&zbus->kref, zpci_bus_release); in zpci_bus_put()
248 if (!zbus->multifunction) in zpci_bus_get()
250 if (topo_is_tid == zbus->topo_is_tid && topo == zbus->topo) { in zpci_bus_get()
251 kref_get(&zbus->kref); in zpci_bus_get()
269 zbus->topo = topo; in zpci_bus_alloc()
270 zbus->topo_is_tid = topo_is_tid; in zpci_bus_alloc()
271 INIT_LIST_HEAD(&zbus->bus_next); in zpci_bus_alloc()
273 list_add_tail(&zbus->bus_next, &zbus_list); in zpci_bus_alloc()
276 kref_init(&zbus->kref); in zpci_bus_alloc()
277 INIT_LIST_HEAD(&zbus->resources); in zpci_bus_alloc()
279 zbus->bus_resource.start = 0; in zpci_bus_alloc()
280 zbus->bus_resource.end = ZPCI_BUS_NR; in zpci_bus_alloc()
281 zbus->bus_resource.flags = IORESOURCE_BUS; in zpci_bus_alloc()
282 pci_add_resource(&zbus->resources, &zbus->bus_resource); in zpci_bus_alloc()
294 dma_start = PAGE_ALIGN(zdev->start_dma); in pci_dma_range_setup()
295 aligned_end = PAGE_ALIGN_DOWN(zdev->end_dma + 1); in pci_dma_range_setup()
297 size = aligned_end - dma_start; in pci_dma_range_setup()
302 ret = dma_direct_set_offset(&pdev->dev, 0, dma_start, size); in pci_dma_range_setup()
314 * With pdev->no_vf_scan the common PCI probing code does not in pcibios_bus_add_device()
317 if (zdev->vfn) { in pcibios_bus_add_device()
318 zpci_iov_setup_virtfn(zdev->zbus, pdev, zdev->vfn); in pcibios_bus_add_device()
319 pdev->no_command_memory = 1; in pcibios_bus_add_device()
325 int rc = -EINVAL; in zpci_bus_add_device()
327 if (zbus->multifunction) { in zpci_bus_add_device()
328 if (!zdev->rid_available) { in zpci_bus_add_device()
332 zdev->devfn = zdev->rid & ZPCI_RID_MASK_DEVFN; in zpci_bus_add_device()
335 if (zbus->function[zdev->devfn]) { in zpci_bus_add_device()
336 pr_err("devfn %04x is already assigned\n", zdev->devfn); in zpci_bus_add_device()
339 zdev->zbus = zbus; in zpci_bus_add_device()
340 zbus->function[zdev->devfn] = zdev; in zpci_bus_add_device()
346 zdev->has_hp_slot = 1; in zpci_bus_add_device()
351 zbus->function[zdev->devfn] = NULL; in zpci_bus_add_device()
352 zdev->zbus = NULL; in zpci_bus_add_device()
353 zpci_nb_devices--; in zpci_bus_add_device()
361 if (!zdev->vfn) in zpci_bus_is_isolated_vf()
373 bool topo_is_tid = zdev->tid_avail; in zpci_bus_device_register()
375 int topo, rc = -EBADF; in zpci_bus_device_register()
378 pr_warn("Adding PCI function %08x failed because the configured limit of %d is reached\n", in zpci_bus_device_register()
379 zdev->fid, ZPCI_NR_DEVICES); in zpci_bus_device_register()
380 return -ENOSPC; in zpci_bus_device_register()
383 topo = topo_is_tid ? zdev->tid : zdev->pchid; in zpci_bus_device_register()
386 * An isolated VF gets its own domain/bus even if there exists in zpci_bus_device_register()
387 * a matching domain/bus already in zpci_bus_device_register()
397 return -ENOMEM; in zpci_bus_device_register()
400 if (!zbus->bus) { in zpci_bus_device_register()
401 /* The UID of the first PCI function registered with a zpci_bus in zpci_bus_device_register()
402 * is used as the domain number for that bus. Currently there in zpci_bus_device_register()
403 * is exactly one zpci_bus per domain. in zpci_bus_device_register()
417 pr_err("Adding PCI function %08x failed\n", zdev->fid); in zpci_bus_device_register()
424 struct zpci_bus *zbus = zdev->zbus; in zpci_bus_device_unregister()
426 zpci_nb_devices--; in zpci_bus_device_unregister()
427 zbus->function[zdev->devfn] = NULL; in zpci_bus_device_unregister()