2018-01-30 08:23:07 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-11-29 21:35:47 +08:00
|
|
|
/*
|
|
|
|
* PCI Hot Plug Controller Driver for System z
|
|
|
|
*
|
|
|
|
* Copyright 2012 IBM Corp.
|
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Jan Glauber <jang@linux.vnet.ibm.com>
|
|
|
|
*/
|
|
|
|
|
2014-07-16 23:21:01 +08:00
|
|
|
#define KMSG_COMPONENT "zpci"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
2012-11-29 21:35:47 +08:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/pci_hotplug.h>
|
2013-04-16 20:11:14 +08:00
|
|
|
#include <asm/pci_debug.h>
|
2012-11-29 21:35:47 +08:00
|
|
|
#include <asm/sclp.h>
|
|
|
|
|
|
|
|
#define SLOT_NAME_SIZE 10
|
|
|
|
|
|
|
|
static int zpci_fn_configured(enum zpci_state state)
|
|
|
|
{
|
|
|
|
return state == ZPCI_FN_STATE_CONFIGURED ||
|
|
|
|
state == ZPCI_FN_STATE_ONLINE;
|
|
|
|
}
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
static inline int zdev_configure(struct zpci_dev *zdev)
|
2018-09-08 15:59:01 +08:00
|
|
|
{
|
2020-02-11 00:53:25 +08:00
|
|
|
int ret = sclp_pci_configure(zdev->fid);
|
2013-06-05 22:06:42 +08:00
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
zpci_dbg(3, "conf fid:%x, rc:%d\n", zdev->fid, ret);
|
2013-06-05 22:06:42 +08:00
|
|
|
if (!ret)
|
2020-02-11 00:53:25 +08:00
|
|
|
zdev->state = ZPCI_FN_STATE_CONFIGURED;
|
2013-06-05 22:06:42 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
static inline int zdev_deconfigure(struct zpci_dev *zdev)
|
2013-06-05 22:06:42 +08:00
|
|
|
{
|
2020-02-11 00:53:25 +08:00
|
|
|
int ret = sclp_pci_deconfigure(zdev->fid);
|
2013-06-05 22:06:42 +08:00
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
|
2013-06-05 22:06:42 +08:00
|
|
|
if (!ret)
|
2020-02-11 00:53:25 +08:00
|
|
|
zdev->state = ZPCI_FN_STATE_STANDBY;
|
2013-06-05 22:06:42 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-29 21:35:47 +08:00
|
|
|
static int enable_slot(struct hotplug_slot *hotplug_slot)
|
|
|
|
{
|
2020-02-11 00:53:25 +08:00
|
|
|
struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
|
|
|
|
hotplug_slot);
|
2012-11-29 21:35:47 +08:00
|
|
|
int rc;
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
if (zdev->state != ZPCI_FN_STATE_STANDBY)
|
2012-11-29 21:35:47 +08:00
|
|
|
return -EIO;
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
rc = zdev_configure(zdev);
|
2013-06-05 22:06:42 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
rc = zpci_enable_device(zdev);
|
2013-06-05 22:06:42 +08:00
|
|
|
if (rc)
|
|
|
|
goto out_deconfigure;
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
pci_scan_slot(zdev->bus, ZPCI_DEVFN);
|
2014-01-15 03:03:14 +08:00
|
|
|
pci_lock_rescan_remove();
|
2020-02-11 00:53:25 +08:00
|
|
|
pci_bus_add_devices(zdev->bus);
|
2014-01-15 03:03:14 +08:00
|
|
|
pci_unlock_rescan_remove();
|
2013-06-05 22:06:42 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
out_deconfigure:
|
2020-02-11 00:53:25 +08:00
|
|
|
zdev_deconfigure(zdev);
|
2012-11-29 21:35:47 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int disable_slot(struct hotplug_slot *hotplug_slot)
|
|
|
|
{
|
2020-02-11 00:53:25 +08:00
|
|
|
struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
|
|
|
|
hotplug_slot);
|
2016-01-29 22:13:30 +08:00
|
|
|
struct pci_dev *pdev;
|
2012-11-29 21:35:47 +08:00
|
|
|
int rc;
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
if (!zpci_fn_configured(zdev->state))
|
2012-11-29 21:35:47 +08:00
|
|
|
return -EIO;
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
pdev = pci_get_slot(zdev->bus, ZPCI_DEVFN);
|
2016-01-29 22:13:30 +08:00
|
|
|
if (pdev) {
|
|
|
|
pci_stop_and_remove_bus_device_locked(pdev);
|
|
|
|
pci_dev_put(pdev);
|
|
|
|
}
|
2013-06-05 22:07:28 +08:00
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
rc = zpci_disable_device(zdev);
|
2013-04-16 20:12:17 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2013-06-05 22:07:28 +08:00
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
return zdev_deconfigure(zdev);
|
2012-11-29 21:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
|
|
|
{
|
2020-02-11 00:53:25 +08:00
|
|
|
struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
|
|
|
|
hotplug_slot);
|
2012-11-29 21:35:47 +08:00
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
switch (zdev->state) {
|
2012-11-29 21:35:47 +08:00
|
|
|
case ZPCI_FN_STATE_STANDBY:
|
|
|
|
*value = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*value = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
|
|
|
{
|
|
|
|
/* if the slot exits it always contains a function */
|
|
|
|
*value = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-08 15:59:01 +08:00
|
|
|
static const struct hotplug_slot_ops s390_hotplug_slot_ops = {
|
2012-11-29 21:35:47 +08:00
|
|
|
.enable_slot = enable_slot,
|
|
|
|
.disable_slot = disable_slot,
|
|
|
|
.get_power_status = get_power_status,
|
|
|
|
.get_adapter_status = get_adapter_status,
|
|
|
|
};
|
|
|
|
|
2013-08-30 01:33:16 +08:00
|
|
|
int zpci_init_slot(struct zpci_dev *zdev)
|
2012-11-29 21:35:47 +08:00
|
|
|
{
|
|
|
|
char name[SLOT_NAME_SIZE];
|
|
|
|
|
2020-02-11 00:53:25 +08:00
|
|
|
zdev->hotplug_slot.ops = &s390_hotplug_slot_ops;
|
2012-11-29 21:35:47 +08:00
|
|
|
|
|
|
|
snprintf(name, SLOT_NAME_SIZE, "%08x", zdev->fid);
|
2020-02-11 00:53:25 +08:00
|
|
|
return pci_hp_register(&zdev->hotplug_slot, zdev->bus,
|
|
|
|
ZPCI_DEVFN, name);
|
2012-11-29 21:35:47 +08:00
|
|
|
}
|
|
|
|
|
2013-08-30 01:33:16 +08:00
|
|
|
void zpci_exit_slot(struct zpci_dev *zdev)
|
2012-11-29 21:35:47 +08:00
|
|
|
{
|
2020-02-11 00:53:25 +08:00
|
|
|
pci_hp_deregister(&zdev->hotplug_slot);
|
2012-11-29 21:35:47 +08:00
|
|
|
}
|