Commit 05bc1be6 authored by Pierre Morel's avatar Pierre Morel Committed by Vasily Gorbik

s390/pci: create zPCI bus

The zPCI bus is in charge to handle common zPCI resources for
zPCI devices.

Creating the zPCI bus, the PCI bus, the zPCI devices and the
PCI devices and hotplug slots
done in a specific order:
- PCI hotplug slot creation needs a PCI bus
- PCI bus needs a PCI domain
  which is reported by the pci_domain_nr() when setting up the
  host bridge
- PCI domain is set from the zPCI with devfn 0
  this is necessary to have a reproducible enumeration

Therefore we can not create devices or hotplug slots for any PCI
device associated with a zPCI device before having discovered
the function zero of the bus.

The discovery and initialization of devices can be done at several
points in the code:
- On Events, serialized in a thread context
- On initialization, in the kernel init thread context
- When powering on the hotplug slot, in a user thread context

The removal of devices and their parent bus may also be done on
events or for devices when powering down the slot.

To guarantee the existence of the bus and devices until they are
no more needed we use kref in zPCI bus and introduce a reference
count in the zPCI devices.

In this patch the zPCI bus still only accept a device with
a devfn 0.
Signed-off-by: default avatarPierre Morel <pmorel@linux.ibm.com>
Reviewed-by: default avatarNiklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
parent c9a1752b
...@@ -28,6 +28,12 @@ int pci_proc_domain(struct pci_bus *); ...@@ -28,6 +28,12 @@ int pci_proc_domain(struct pci_bus *);
#define ZPCI_NR_DEVICES CONFIG_PCI_NR_FUNCTIONS #define ZPCI_NR_DEVICES CONFIG_PCI_NR_FUNCTIONS
#define ZPCI_DOMAIN_BITMAP_SIZE (1 << 16) #define ZPCI_DOMAIN_BITMAP_SIZE (1 << 16)
#ifdef PCI
#if (ZPCI_NR_DEVICES > ZPCI_DOMAIN_BITMAP_SIZE)
# error ZPCI_NR_DEVICES can not be bigger than ZPCI_DOMAIN_BITMAP_SIZE
#endif
#endif /* PCI */
/* PCI Function Controls */ /* PCI Function Controls */
#define ZPCI_FC_FN_ENABLED 0x80 #define ZPCI_FC_FN_ENABLED 0x80
#define ZPCI_FC_ERROR 0x40 #define ZPCI_FC_ERROR 0x40
...@@ -94,10 +100,23 @@ struct zpci_bar_struct { ...@@ -94,10 +100,23 @@ struct zpci_bar_struct {
struct s390_domain; struct s390_domain;
#define ZPCI_FUNCTIONS_PER_BUS 256
struct zpci_bus {
struct kref kref;
struct pci_bus *bus;
struct zpci_dev *function[ZPCI_FUNCTIONS_PER_BUS];
struct list_head resources;
struct list_head bus_next;
int pchid;
int domain_nr;
enum pci_bus_speed max_bus_speed;
};
/* Private data per function */ /* Private data per function */
struct zpci_dev { struct zpci_dev {
struct pci_bus *bus; struct zpci_bus *zbus;
struct list_head entry; /* list of all zpci_devices, needed for hotplug, etc. */ struct list_head entry; /* list of all zpci_devices, needed for hotplug, etc. */
struct kref kref;
struct hotplug_slot hotplug_slot; struct hotplug_slot hotplug_slot;
enum zpci_state state; enum zpci_state state;
...@@ -107,7 +126,6 @@ struct zpci_dev { ...@@ -107,7 +126,6 @@ struct zpci_dev {
u16 pchid; /* physical channel ID */ u16 pchid; /* physical channel ID */
u8 pfgid; /* function group ID */ u8 pfgid; /* function group ID */
u8 pft; /* pci function type */ u8 pft; /* pci function type */
u16 domain;
u8 port; u8 port;
u8 rid_available : 1; u8 rid_available : 1;
u8 reserved : 7; u8 reserved : 7;
...@@ -232,7 +250,9 @@ static inline void zpci_exit_slot(struct zpci_dev *zdev) {} ...@@ -232,7 +250,9 @@ static inline void zpci_exit_slot(struct zpci_dev *zdev) {}
/* Helpers */ /* Helpers */
static inline struct zpci_dev *to_zpci(struct pci_dev *pdev) static inline struct zpci_dev *to_zpci(struct pci_dev *pdev)
{ {
return pdev->sysdata; struct zpci_bus *zbus = pdev->sysdata;
return zbus->function[ZPCI_DEVFN];
} }
static inline struct zpci_dev *to_zpci_dev(struct device *dev) static inline struct zpci_dev *to_zpci_dev(struct device *dev)
......
...@@ -4,4 +4,5 @@ ...@@ -4,4 +4,5 @@
# #
obj-$(CONFIG_PCI) += pci.o pci_irq.o pci_dma.o pci_clp.o pci_sysfs.o \ obj-$(CONFIG_PCI) += pci.o pci_irq.o pci_dma.o pci_clp.o pci_sysfs.o \
pci_event.o pci_debug.o pci_insn.o pci_mmio.o pci_event.o pci_debug.o pci_insn.o pci_mmio.o \
pci_bus.o
...@@ -36,13 +36,14 @@ ...@@ -36,13 +36,14 @@
#include <asm/pci_clp.h> #include <asm/pci_clp.h>
#include <asm/pci_dma.h> #include <asm/pci_dma.h>
#include "pci_bus.h"
/* list of all detected zpci devices */ /* list of all detected zpci devices */
static LIST_HEAD(zpci_list); static LIST_HEAD(zpci_list);
static DEFINE_SPINLOCK(zpci_list_lock); static DEFINE_SPINLOCK(zpci_list_lock);
static DECLARE_BITMAP(zpci_domain, ZPCI_DOMAIN_BITMAP_SIZE); static DECLARE_BITMAP(zpci_domain, ZPCI_DOMAIN_BITMAP_SIZE);
static DEFINE_SPINLOCK(zpci_domain_lock); static DEFINE_SPINLOCK(zpci_domain_lock);
static unsigned int zpci_num_domains_allocated;
#define ZPCI_IOMAP_ENTRIES \ #define ZPCI_IOMAP_ENTRIES \
min(((unsigned long) ZPCI_NR_DEVICES * PCI_STD_NUM_BARS / 2), \ min(((unsigned long) ZPCI_NR_DEVICES * PCI_STD_NUM_BARS / 2), \
...@@ -90,17 +91,12 @@ void zpci_remove_reserved_devices(void) ...@@ -90,17 +91,12 @@ void zpci_remove_reserved_devices(void)
spin_unlock(&zpci_list_lock); spin_unlock(&zpci_list_lock);
list_for_each_entry_safe(zdev, tmp, &remove, entry) list_for_each_entry_safe(zdev, tmp, &remove, entry)
zpci_remove_device(zdev); zpci_zdev_put(zdev);
}
static struct zpci_dev *get_zdev_by_bus(struct pci_bus *bus)
{
return (bus && bus->sysdata) ? (struct zpci_dev *) bus->sysdata : NULL;
} }
int pci_domain_nr(struct pci_bus *bus) int pci_domain_nr(struct pci_bus *bus)
{ {
return ((struct zpci_dev *) bus->sysdata)->domain; return ((struct zpci_bus *) bus->sysdata)->domain_nr;
} }
EXPORT_SYMBOL_GPL(pci_domain_nr); EXPORT_SYMBOL_GPL(pci_domain_nr);
...@@ -508,7 +504,7 @@ static struct resource *__alloc_res(struct zpci_dev *zdev, unsigned long start, ...@@ -508,7 +504,7 @@ static struct resource *__alloc_res(struct zpci_dev *zdev, unsigned long start,
return r; return r;
} }
static int zpci_setup_bus_resources(struct zpci_dev *zdev, int zpci_setup_bus_resources(struct zpci_dev *zdev,
struct list_head *resources) struct list_head *resources)
{ {
unsigned long addr, size, flags; unsigned long addr, size, flags;
...@@ -516,7 +512,7 @@ static int zpci_setup_bus_resources(struct zpci_dev *zdev, ...@@ -516,7 +512,7 @@ static int zpci_setup_bus_resources(struct zpci_dev *zdev,
int i, entry; int i, entry;
snprintf(zdev->res_name, sizeof(zdev->res_name), snprintf(zdev->res_name, sizeof(zdev->res_name),
"PCI Bus %04x:%02x", zdev->domain, ZPCI_BUS_NR); "PCI Bus %04x:%02x", zdev->uid, ZPCI_BUS_NR);
for (i = 0; i < PCI_STD_NUM_BARS; i++) { for (i = 0; i < PCI_STD_NUM_BARS; i++) {
if (!zdev->bars[i].size) if (!zdev->bars[i].size)
...@@ -610,98 +606,53 @@ void pcibios_disable_device(struct pci_dev *pdev) ...@@ -610,98 +606,53 @@ void pcibios_disable_device(struct pci_dev *pdev)
zpci_debug_exit_device(zdev); zpci_debug_exit_device(zdev);
} }
static int zpci_alloc_domain(struct zpci_dev *zdev) static int __zpci_register_domain(int domain)
{ {
spin_lock(&zpci_domain_lock); spin_lock(&zpci_domain_lock);
if (zpci_num_domains_allocated > (ZPCI_NR_DEVICES - 1)) { if (test_bit(domain, zpci_domain)) {
spin_unlock(&zpci_domain_lock);
pr_err("Adding PCI function %08x failed because the configured limit of %d is reached\n",
zdev->fid, ZPCI_NR_DEVICES);
return -ENOSPC;
}
if (zpci_unique_uid) {
zdev->domain = (u16) zdev->uid;
if (zdev->domain == 0) {
pr_warn("UID checking is active but no UID is set for PCI function %08x, so automatic domain allocation is used instead\n",
zdev->fid);
update_uid_checking(false);
goto auto_allocate;
}
if (test_bit(zdev->domain, zpci_domain)) {
spin_unlock(&zpci_domain_lock); spin_unlock(&zpci_domain_lock);
pr_err("Adding PCI function %08x failed because domain %04x is already assigned\n", pr_err("Domain %04x is already assigned\n", domain);
zdev->fid, zdev->domain);
return -EEXIST; return -EEXIST;
} }
set_bit(zdev->domain, zpci_domain); set_bit(domain, zpci_domain);
zpci_num_domains_allocated++;
spin_unlock(&zpci_domain_lock); spin_unlock(&zpci_domain_lock);
return 0; return domain;
} }
auto_allocate:
static int __zpci_alloc_domain(void)
{
int domain;
spin_lock(&zpci_domain_lock);
/* /*
* We can always auto allocate domains below ZPCI_NR_DEVICES. * We can always auto allocate domains below ZPCI_NR_DEVICES.
* There is either a free domain or we have reached the maximum in * There is either a free domain or we have reached the maximum in
* which case we would have bailed earlier. * which case we would have bailed earlier.
*/ */
zdev->domain = find_first_zero_bit(zpci_domain, ZPCI_NR_DEVICES); domain = find_first_zero_bit(zpci_domain, ZPCI_NR_DEVICES);
set_bit(zdev->domain, zpci_domain); set_bit(domain, zpci_domain);
zpci_num_domains_allocated++;
spin_unlock(&zpci_domain_lock); spin_unlock(&zpci_domain_lock);
return 0; return domain;
} }
static void zpci_free_domain(struct zpci_dev *zdev) int zpci_alloc_domain(int domain)
{ {
spin_lock(&zpci_domain_lock); if (zpci_unique_uid) {
clear_bit(zdev->domain, zpci_domain); if (domain)
zpci_num_domains_allocated--; return __zpci_register_domain(domain);
spin_unlock(&zpci_domain_lock); pr_warn("UID checking was active but no UID is provided: switching to automatic domain allocation\n");
update_uid_checking(false);
}
return __zpci_alloc_domain();
} }
void pcibios_remove_bus(struct pci_bus *bus) void zpci_free_domain(int domain)
{ {
struct zpci_dev *zdev = get_zdev_by_bus(bus); spin_lock(&zpci_domain_lock);
clear_bit(domain, zpci_domain);
zpci_exit_slot(zdev); spin_unlock(&zpci_domain_lock);
zpci_cleanup_bus_resources(zdev);
zpci_destroy_iommu(zdev);
zpci_free_domain(zdev);
spin_lock(&zpci_list_lock);
list_del(&zdev->entry);
spin_unlock(&zpci_list_lock);
zpci_dbg(3, "rem fid:%x\n", zdev->fid);
kfree(zdev);
} }
static int zpci_scan_bus(struct zpci_dev *zdev)
{
LIST_HEAD(resources);
int ret;
ret = zpci_setup_bus_resources(zdev, &resources);
if (ret)
goto error;
zdev->bus = pci_scan_root_bus(NULL, ZPCI_BUS_NR, &pci_root_ops,
zdev, &resources);
if (!zdev->bus) {
ret = -EIO;
goto error;
}
zdev->bus->max_bus_speed = zdev->max_bus_speed;
pci_bus_add_devices(zdev->bus);
return 0;
error:
zpci_cleanup_bus_resources(zdev);
pci_free_resource_list(&resources);
return ret;
}
int zpci_enable_device(struct zpci_dev *zdev) int zpci_enable_device(struct zpci_dev *zdev)
{ {
...@@ -736,13 +687,15 @@ int zpci_create_device(struct zpci_dev *zdev) ...@@ -736,13 +687,15 @@ int zpci_create_device(struct zpci_dev *zdev)
{ {
int rc; int rc;
rc = zpci_alloc_domain(zdev); kref_init(&zdev->kref);
if (rc)
goto out; spin_lock(&zpci_list_lock);
list_add_tail(&zdev->entry, &zpci_list);
spin_unlock(&zpci_list_lock);
rc = zpci_init_iommu(zdev); rc = zpci_init_iommu(zdev);
if (rc) if (rc)
goto out_free; goto out;
mutex_init(&zdev->lock); mutex_init(&zdev->lock);
if (zdev->state == ZPCI_FN_STATE_CONFIGURED) { if (zdev->state == ZPCI_FN_STATE_CONFIGURED) {
...@@ -750,16 +703,12 @@ int zpci_create_device(struct zpci_dev *zdev) ...@@ -750,16 +703,12 @@ int zpci_create_device(struct zpci_dev *zdev)
if (rc) if (rc)
goto out_destroy_iommu; goto out_destroy_iommu;
} }
rc = zpci_scan_bus(zdev);
rc = zpci_bus_device_register(zdev, &pci_root_ops);
if (rc) if (rc)
goto out_disable; goto out_disable;
spin_lock(&zpci_list_lock);
list_add_tail(&zdev->entry, &zpci_list);
spin_unlock(&zpci_list_lock);
zpci_init_slot(zdev); zpci_init_slot(zdev);
return 0; return 0;
out_disable: out_disable:
...@@ -767,19 +716,39 @@ int zpci_create_device(struct zpci_dev *zdev) ...@@ -767,19 +716,39 @@ int zpci_create_device(struct zpci_dev *zdev)
zpci_disable_device(zdev); zpci_disable_device(zdev);
out_destroy_iommu: out_destroy_iommu:
zpci_destroy_iommu(zdev); zpci_destroy_iommu(zdev);
out_free:
zpci_free_domain(zdev);
out: out:
spin_lock(&zpci_list_lock);
list_del(&zdev->entry);
spin_unlock(&zpci_list_lock);
return rc; return rc;
} }
void zpci_remove_device(struct zpci_dev *zdev) void zpci_release_device(struct kref *kref)
{ {
if (!zdev->bus) struct zpci_dev *zdev = container_of(kref, struct zpci_dev, kref);
return;
pci_stop_root_bus(zdev->bus); switch (zdev->state) {
pci_remove_root_bus(zdev->bus); case ZPCI_FN_STATE_ONLINE:
case ZPCI_FN_STATE_CONFIGURED:
zpci_disable_device(zdev);
fallthrough;
case ZPCI_FN_STATE_STANDBY:
if (zdev->zbus) {
zpci_exit_slot(zdev);
zpci_cleanup_bus_resources(zdev);
zpci_bus_device_unregister(zdev);
zpci_destroy_iommu(zdev);
}
fallthrough;
default:
break;
}
spin_lock(&zpci_list_lock);
list_del(&zdev->entry);
spin_unlock(&zpci_list_lock);
zpci_dbg(3, "rem fid:%x\n", zdev->fid);
kfree(zdev);
} }
int zpci_report_error(struct pci_dev *pdev, int zpci_report_error(struct pci_dev *pdev,
......
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright IBM Corp. 2020
*
* Author(s):
* Pierre Morel <pmorel@linux.ibm.com>
*
*/
#define KMSG_COMPONENT "zpci"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/export.h>
#include <linux/delay.h>
#include <linux/seq_file.h>
#include <linux/jump_label.h>
#include <linux/pci.h>
#include <linux/printk.h>
#include <asm/pci_clp.h>
#include <asm/pci_dma.h>
#include "pci_bus.h"
static LIST_HEAD(zbus_list);
static DEFINE_SPINLOCK(zbus_list_lock);
static int zpci_nb_devices;
/* zpci_bus_scan
* @zbus: the zbus holding the zdevices
* @ops: the pci operations
*
* The domain number must be set before pci_scan_root_bus is called.
* This function can be called once the domain is known, hence
* when the function_0 is dicovered.
*/
static int zpci_bus_scan(struct zpci_bus *zbus, int domain, struct pci_ops *ops)
{
struct pci_bus *bus;
int rc;
rc = zpci_alloc_domain(domain);
if (rc < 0)
return rc;
zbus->domain_nr = rc;
bus = pci_scan_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources);
if (!bus) {
zpci_free_domain(zbus->domain_nr);
return -EFAULT;
}
zbus->bus = bus;
pci_bus_add_devices(bus);
return 0;
}
static void zpci_bus_release(struct kref *kref)
{
struct zpci_bus *zbus = container_of(kref, struct zpci_bus, kref);
pci_lock_rescan_remove();
pci_stop_root_bus(zbus->bus);
zpci_free_domain(zbus->domain_nr);
pci_free_resource_list(&zbus->resources);
pci_remove_root_bus(zbus->bus);
pci_unlock_rescan_remove();
spin_lock(&zbus_list_lock);
list_del(&zbus->bus_next);
spin_unlock(&zbus_list_lock);
kfree(zbus);
}
static void zpci_bus_put(struct zpci_bus *zbus)
{
kref_put(&zbus->kref, zpci_bus_release);
}
static struct zpci_bus *zpci_bus_alloc(int pchid)
{
struct zpci_bus *zbus;
zbus = kzalloc(sizeof(*zbus), GFP_KERNEL);
if (!zbus)
return NULL;
zbus->pchid = pchid;
INIT_LIST_HEAD(&zbus->bus_next);
spin_lock(&zbus_list_lock);
list_add_tail(&zbus->bus_next, &zbus_list);
spin_unlock(&zbus_list_lock);
kref_init(&zbus->kref);
INIT_LIST_HEAD(&zbus->resources);
return zbus;
}
int zpci_bus_device_register(struct zpci_dev *zdev, struct pci_ops *ops)
{
struct zpci_bus *zbus;
int rc;
if (zpci_nb_devices == ZPCI_NR_DEVICES) {
pr_warn("Adding PCI function %08x failed because the configured limit of %d is reached\n",
zdev->fid, ZPCI_NR_DEVICES);
return -ENOSPC;
}
zpci_nb_devices++;
if (zdev->devfn != ZPCI_DEVFN)
return -EINVAL;
zbus = zpci_bus_alloc(zdev->pchid);
if (!zbus)
return -ENOMEM;
zdev->zbus = zbus;
zbus->function[ZPCI_DEVFN] = zdev;
zpci_setup_bus_resources(zdev, &zbus->resources);
zbus->max_bus_speed = zdev->max_bus_speed;
rc = zpci_bus_scan(zbus, (u16)zdev->uid, ops);
if (!rc)
return 0;
pr_err("Adding PCI function %08x failed\n", zdev->fid);
zdev->zbus = NULL;
zpci_bus_put(zbus);
return rc;
}
void zpci_bus_device_unregister(struct zpci_dev *zdev)
{
struct zpci_bus *zbus = zdev->zbus;
zpci_nb_devices--;
zbus->function[ZPCI_DEVFN] = NULL;
zpci_bus_put(zbus);
}
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright IBM Corp. 2020
*
* Author(s):
* Pierre Morel <pmorel@linux.ibm.com>
*
*/
int zpci_bus_device_register(struct zpci_dev *zdev, struct pci_ops *ops);
void zpci_bus_device_unregister(struct zpci_dev *zdev);
int zpci_bus_init(void);
void zpci_release_device(struct kref *kref);
static inline void zpci_zdev_put(struct zpci_dev *zdev)
{
kref_put(&zdev->kref, zpci_release_device);
}
int zpci_alloc_domain(int domain);
void zpci_free_domain(int domain);
int zpci_setup_bus_resources(struct zpci_dev *zdev,
struct list_head *resources);
static inline struct zpci_dev *get_zdev_by_bus(struct pci_bus *bus)
{
struct zpci_bus *zbus = bus->sysdata;
return zbus->function[ZPCI_DEVFN];
}
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <asm/pci_debug.h> #include <asm/pci_debug.h>
#include <asm/sclp.h> #include <asm/sclp.h>
#include "pci_bus.h"
/* Content Code Description for PCI Function Error */ /* Content Code Description for PCI Function Error */
struct zpci_ccdf_err { struct zpci_ccdf_err {
u32 reserved1; u32 reserved1;
...@@ -53,7 +55,7 @@ static void __zpci_event_error(struct zpci_ccdf_err *ccdf) ...@@ -53,7 +55,7 @@ static void __zpci_event_error(struct zpci_ccdf_err *ccdf)
zpci_err_hex(ccdf, sizeof(*ccdf)); zpci_err_hex(ccdf, sizeof(*ccdf));
if (zdev) if (zdev)
pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN); pdev = pci_get_slot(zdev->zbus->bus, ZPCI_DEVFN);
pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n", pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid); pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
...@@ -78,11 +80,9 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf) ...@@ -78,11 +80,9 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
enum zpci_state state; enum zpci_state state;
int ret; int ret;
if (zdev) if (zdev && zdev->zbus && zdev->zbus->bus)
pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN); pdev = pci_get_slot(zdev->zbus->bus, ZPCI_DEVFN);
pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
zpci_err("avail CCDF:\n"); zpci_err("avail CCDF:\n");
zpci_err_hex(ccdf, sizeof(*ccdf)); zpci_err_hex(ccdf, sizeof(*ccdf));
...@@ -102,7 +102,7 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf) ...@@ -102,7 +102,7 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
if (ret) if (ret)
break; break;
pci_lock_rescan_remove(); pci_lock_rescan_remove();
pci_rescan_bus(zdev->bus); pci_rescan_bus(zdev->zbus->bus);
pci_unlock_rescan_remove(); pci_unlock_rescan_remove();
break; break;
case 0x0302: /* Reserved -> Standby */ case 0x0302: /* Reserved -> Standby */
...@@ -140,7 +140,7 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf) ...@@ -140,7 +140,7 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
zdev->state = ZPCI_FN_STATE_STANDBY; zdev->state = ZPCI_FN_STATE_STANDBY;
if (!clp_get_state(ccdf->fid, &state) && if (!clp_get_state(ccdf->fid, &state) &&
state == ZPCI_FN_STATE_RESERVED) { state == ZPCI_FN_STATE_RESERVED) {
zpci_remove_device(zdev); zpci_zdev_put(zdev);
} }
break; break;
case 0x0306: /* 0x308 or 0x302 for multiple devices */ case 0x0306: /* 0x308 or 0x302 for multiple devices */
...@@ -149,12 +149,11 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf) ...@@ -149,12 +149,11 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
case 0x0308: /* Standby -> Reserved */ case 0x0308: /* Standby -> Reserved */
if (!zdev) if (!zdev)
break; break;
zpci_remove_device(zdev); zpci_zdev_put(zdev);
break; break;
default: default:
break; break;
} }
pci_dev_put(pdev);
} }
void zpci_event_availability(void *data) void zpci_event_availability(void *data)
......
...@@ -89,7 +89,7 @@ static ssize_t recover_store(struct device *dev, struct device_attribute *attr, ...@@ -89,7 +89,7 @@ static ssize_t recover_store(struct device *dev, struct device_attribute *attr,
ret = zpci_enable_device(zdev); ret = zpci_enable_device(zdev);
if (ret) if (ret)
goto out; goto out;
pci_rescan_bus(zdev->bus); pci_rescan_bus(zdev->zbus->bus);
} }
out: out:
pci_unlock_rescan_remove(); pci_unlock_rescan_remove();
......
...@@ -52,6 +52,7 @@ static int enable_slot(struct hotplug_slot *hotplug_slot) ...@@ -52,6 +52,7 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
{ {
struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev, struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
hotplug_slot); hotplug_slot);
struct zpci_bus *zbus = zdev->zbus;
int rc; int rc;
if (zdev->state != ZPCI_FN_STATE_STANDBY) if (zdev->state != ZPCI_FN_STATE_STANDBY)
...@@ -65,9 +66,9 @@ static int enable_slot(struct hotplug_slot *hotplug_slot) ...@@ -65,9 +66,9 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
if (rc) if (rc)
goto out_deconfigure; goto out_deconfigure;
pci_scan_slot(zdev->bus, ZPCI_DEVFN); pci_scan_slot(zbus->bus, ZPCI_DEVFN);
pci_lock_rescan_remove(); pci_lock_rescan_remove();
pci_bus_add_devices(zdev->bus); pci_bus_add_devices(zbus->bus);
pci_unlock_rescan_remove(); pci_unlock_rescan_remove();
return rc; return rc;
...@@ -82,12 +83,13 @@ static int disable_slot(struct hotplug_slot *hotplug_slot) ...@@ -82,12 +83,13 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev, struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
hotplug_slot); hotplug_slot);
struct pci_dev *pdev; struct pci_dev *pdev;
struct zpci_bus *zbus = zdev->zbus;
int rc; int rc;
if (!zpci_fn_configured(zdev->state)) if (!zpci_fn_configured(zdev->state))
return -EIO; return -EIO;
pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN); pdev = pci_get_slot(zbus->bus, ZPCI_DEVFN);
if (pdev) { if (pdev) {
pci_stop_and_remove_bus_device_locked(pdev); pci_stop_and_remove_bus_device_locked(pdev);
pci_dev_put(pdev); pci_dev_put(pdev);
...@@ -133,11 +135,12 @@ static const struct hotplug_slot_ops s390_hotplug_slot_ops = { ...@@ -133,11 +135,12 @@ static const struct hotplug_slot_ops s390_hotplug_slot_ops = {
int zpci_init_slot(struct zpci_dev *zdev) int zpci_init_slot(struct zpci_dev *zdev)
{ {
char name[SLOT_NAME_SIZE]; char name[SLOT_NAME_SIZE];
struct zpci_bus *zbus = zdev->zbus;
zdev->hotplug_slot.ops = &s390_hotplug_slot_ops; zdev->hotplug_slot.ops = &s390_hotplug_slot_ops;
snprintf(name, SLOT_NAME_SIZE, "%08x", zdev->fid); snprintf(name, SLOT_NAME_SIZE, "%08x", zdev->fid);
return pci_hp_register(&zdev->hotplug_slot, zdev->bus, return pci_hp_register(&zdev->hotplug_slot, zbus->bus,
ZPCI_DEVFN, name); ZPCI_DEVFN, name);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment