^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright IBM Corp. 2020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author(s):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Pierre Morel <pmorel@linux.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define KMSG_COMPONENT "zpci"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/jump_label.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/pci_clp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/pci_dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "pci_bus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "pci_iov.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static LIST_HEAD(zbus_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static DEFINE_SPINLOCK(zbus_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int zpci_nb_devices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* zpci_bus_scan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * @zbus: the zbus holding the zdevices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @ops: the pci operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * The domain number must be set before pci_scan_root_bus is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * This function can be called once the domain is known, hence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * when the function_0 is dicovered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static int zpci_bus_scan(struct zpci_bus *zbus, int domain, struct pci_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct pci_bus *bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) rc = zpci_alloc_domain(domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) zbus->domain_nr = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) bus = pci_scan_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (!bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) zpci_free_domain(zbus->domain_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) zbus->bus = bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) pci_bus_add_devices(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static void zpci_bus_release(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct zpci_bus *zbus = container_of(kref, struct zpci_bus, kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (zbus->bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) pci_lock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) pci_stop_root_bus(zbus->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) zpci_free_domain(zbus->domain_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) pci_free_resource_list(&zbus->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) pci_remove_root_bus(zbus->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) spin_lock(&zbus_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) list_del(&zbus->bus_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) spin_unlock(&zbus_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) kfree(zbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void zpci_bus_put(struct zpci_bus *zbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) kref_put(&zbus->kref, zpci_bus_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static struct zpci_bus *zpci_bus_get(int pchid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct zpci_bus *zbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) spin_lock(&zbus_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) list_for_each_entry(zbus, &zbus_list, bus_next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (pchid == zbus->pchid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) kref_get(&zbus->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) zbus = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) spin_unlock(&zbus_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return zbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static struct zpci_bus *zpci_bus_alloc(int pchid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct zpci_bus *zbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) zbus = kzalloc(sizeof(*zbus), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (!zbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) zbus->pchid = pchid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) INIT_LIST_HEAD(&zbus->bus_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) spin_lock(&zbus_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) list_add_tail(&zbus->bus_next, &zbus_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) spin_unlock(&zbus_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) kref_init(&zbus->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) INIT_LIST_HEAD(&zbus->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) zbus->bus_resource.start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) zbus->bus_resource.end = ZPCI_BUS_NR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) zbus->bus_resource.flags = IORESOURCE_BUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) pci_add_resource(&zbus->resources, &zbus->bus_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return zbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void pcibios_bus_add_device(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct zpci_dev *zdev = to_zpci(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * With pdev->no_vf_scan the common PCI probing code does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * perform PF/VF linking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (zdev->vfn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) zpci_iov_setup_virtfn(zdev->zbus, pdev, zdev->vfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) pdev->no_command_memory = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static int zpci_bus_add_device(struct zpci_bus *zbus, struct zpci_dev *zdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct pci_bus *bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct resource_entry *window, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) bus = zbus->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) pdev = pci_get_slot(bus, zdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (pdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* Device is already known. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) pci_dev_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) rc = zpci_init_slot(zdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) zdev->has_hp_slot = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) resource_list_for_each_entry_safe(window, n, &zbus->resources) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) res = window->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) pci_bus_add_resource(bus, res, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) pdev = pci_scan_single_device(bus, zdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) pci_bus_add_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static void zpci_bus_add_devices(struct zpci_bus *zbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) for (i = 1; i < ZPCI_FUNCTIONS_PER_BUS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (zbus->function[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) zpci_bus_add_device(zbus, zbus->function[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) pci_lock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pci_bus_add_devices(zbus->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int zpci_bus_device_register(struct zpci_dev *zdev, struct pci_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct zpci_bus *zbus = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int rc = -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (zpci_nb_devices == ZPCI_NR_DEVICES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) pr_warn("Adding PCI function %08x failed because the configured limit of %d is reached\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) zdev->fid, ZPCI_NR_DEVICES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) zpci_nb_devices++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (zdev->devfn >= ZPCI_FUNCTIONS_PER_BUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (!s390_pci_no_rid && zdev->rid_available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) zbus = zpci_bus_get(zdev->pchid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (!zbus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) zbus = zpci_bus_alloc(zdev->pchid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!zbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) zdev->zbus = zbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (zbus->function[zdev->devfn]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) pr_err("devfn %04x is already assigned\n", zdev->devfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) goto error; /* rc already set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) zbus->function[zdev->devfn] = zdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) zpci_setup_bus_resources(zdev, &zbus->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (zbus->bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!zbus->multifunction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) WARN_ONCE(1, "zbus is not multifunction\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) goto error_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (!zdev->rid_available) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) WARN_ONCE(1, "rid_available not set for multifunction\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) goto error_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) rc = zpci_bus_add_device(zbus, zdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) goto error_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) } else if (zdev->devfn == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (zbus->multifunction && !zdev->rid_available) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) WARN_ONCE(1, "rid_available not set on function 0 for multifunction\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) goto error_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) rc = zpci_bus_scan(zbus, (u16)zdev->uid, ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) goto error_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) zpci_bus_add_devices(zbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) rc = zpci_init_slot(zdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) goto error_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) zdev->has_hp_slot = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) zbus->multifunction = zdev->rid_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) zbus->max_bus_speed = zdev->max_bus_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) zbus->multifunction = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) error_bus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) zpci_nb_devices--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) zbus->function[zdev->devfn] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) pr_err("Adding PCI function %08x failed\n", zdev->fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) zpci_bus_put(zbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) void zpci_bus_device_unregister(struct zpci_dev *zdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct zpci_bus *zbus = zdev->zbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) zpci_nb_devices--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) zbus->function[zdev->devfn] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) zpci_bus_put(zbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }