Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * PCI Hot Plug Controller Driver for System z
0004  *
0005  * Copyright 2012 IBM Corp.
0006  *
0007  * Author(s):
0008  *   Jan Glauber <jang@linux.vnet.ibm.com>
0009  */
0010 
0011 #define KMSG_COMPONENT "zpci"
0012 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/slab.h>
0016 #include <linux/pci.h>
0017 #include <linux/pci_hotplug.h>
0018 #include <asm/pci_debug.h>
0019 #include <asm/sclp.h>
0020 
0021 #define SLOT_NAME_SIZE  10
0022 
0023 static int enable_slot(struct hotplug_slot *hotplug_slot)
0024 {
0025     struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
0026                          hotplug_slot);
0027     int rc;
0028 
0029     if (zdev->state != ZPCI_FN_STATE_STANDBY)
0030         return -EIO;
0031 
0032     rc = sclp_pci_configure(zdev->fid);
0033     zpci_dbg(3, "conf fid:%x, rc:%d\n", zdev->fid, rc);
0034     if (rc)
0035         return rc;
0036     zdev->state = ZPCI_FN_STATE_CONFIGURED;
0037 
0038     return zpci_scan_configured_device(zdev, zdev->fh);
0039 }
0040 
0041 static int disable_slot(struct hotplug_slot *hotplug_slot)
0042 {
0043     struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
0044                          hotplug_slot);
0045     struct pci_dev *pdev;
0046 
0047     if (zdev->state != ZPCI_FN_STATE_CONFIGURED)
0048         return -EIO;
0049 
0050     pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
0051     if (pdev && pci_num_vf(pdev)) {
0052         pci_dev_put(pdev);
0053         return -EBUSY;
0054     }
0055     pci_dev_put(pdev);
0056 
0057     return zpci_deconfigure_device(zdev);
0058 }
0059 
0060 static int reset_slot(struct hotplug_slot *hotplug_slot, bool probe)
0061 {
0062     struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
0063                          hotplug_slot);
0064 
0065     if (zdev->state != ZPCI_FN_STATE_CONFIGURED)
0066         return -EIO;
0067     /*
0068      * We can't take the zdev->lock as reset_slot may be called during
0069      * probing and/or device removal which already happens under the
0070      * zdev->lock. Instead the user should use the higher level
0071      * pci_reset_function() or pci_bus_reset() which hold the PCI device
0072      * lock preventing concurrent removal. If not using these functions
0073      * holding the PCI device lock is required.
0074      */
0075 
0076     /* As long as the function is configured we can reset */
0077     if (probe)
0078         return 0;
0079 
0080     return zpci_hot_reset_device(zdev);
0081 }
0082 
0083 static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
0084 {
0085     struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
0086                          hotplug_slot);
0087 
0088     *value = zpci_is_device_configured(zdev) ? 1 : 0;
0089     return 0;
0090 }
0091 
0092 static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
0093 {
0094     /* if the slot exits it always contains a function */
0095     *value = 1;
0096     return 0;
0097 }
0098 
0099 static const struct hotplug_slot_ops s390_hotplug_slot_ops = {
0100     .enable_slot =      enable_slot,
0101     .disable_slot =     disable_slot,
0102     .reset_slot =       reset_slot,
0103     .get_power_status = get_power_status,
0104     .get_adapter_status =   get_adapter_status,
0105 };
0106 
0107 int zpci_init_slot(struct zpci_dev *zdev)
0108 {
0109     char name[SLOT_NAME_SIZE];
0110     struct zpci_bus *zbus = zdev->zbus;
0111 
0112     zdev->hotplug_slot.ops = &s390_hotplug_slot_ops;
0113 
0114     snprintf(name, SLOT_NAME_SIZE, "%08x", zdev->fid);
0115     return pci_hp_register(&zdev->hotplug_slot, zbus->bus,
0116                    zdev->devfn, name);
0117 }
0118 
0119 void zpci_exit_slot(struct zpci_dev *zdev)
0120 {
0121     pci_hp_deregister(&zdev->hotplug_slot);
0122 }