s390_pci_hpc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * PCI Hot Plug Controller Driver for System z
  4. *
  5. * Copyright 2012 IBM Corp.
  6. *
  7. * Author(s):
  8. * Jan Glauber <[email protected]>
  9. */
  10. #define KMSG_COMPONENT "zpci"
  11. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/pci.h>
  15. #include <linux/pci_hotplug.h>
  16. #include <asm/pci_debug.h>
  17. #include <asm/sclp.h>
  18. #define SLOT_NAME_SIZE 10
  19. static int enable_slot(struct hotplug_slot *hotplug_slot)
  20. {
  21. struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
  22. hotplug_slot);
  23. int rc;
  24. if (zdev->state != ZPCI_FN_STATE_STANDBY)
  25. return -EIO;
  26. rc = sclp_pci_configure(zdev->fid);
  27. zpci_dbg(3, "conf fid:%x, rc:%d\n", zdev->fid, rc);
  28. if (rc)
  29. return rc;
  30. zdev->state = ZPCI_FN_STATE_CONFIGURED;
  31. return zpci_scan_configured_device(zdev, zdev->fh);
  32. }
  33. static int disable_slot(struct hotplug_slot *hotplug_slot)
  34. {
  35. struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
  36. hotplug_slot);
  37. struct pci_dev *pdev;
  38. if (zdev->state != ZPCI_FN_STATE_CONFIGURED)
  39. return -EIO;
  40. pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
  41. if (pdev && pci_num_vf(pdev)) {
  42. pci_dev_put(pdev);
  43. return -EBUSY;
  44. }
  45. pci_dev_put(pdev);
  46. return zpci_deconfigure_device(zdev);
  47. }
  48. static int reset_slot(struct hotplug_slot *hotplug_slot, bool probe)
  49. {
  50. struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
  51. hotplug_slot);
  52. if (zdev->state != ZPCI_FN_STATE_CONFIGURED)
  53. return -EIO;
  54. /*
  55. * We can't take the zdev->lock as reset_slot may be called during
  56. * probing and/or device removal which already happens under the
  57. * zdev->lock. Instead the user should use the higher level
  58. * pci_reset_function() or pci_bus_reset() which hold the PCI device
  59. * lock preventing concurrent removal. If not using these functions
  60. * holding the PCI device lock is required.
  61. */
  62. /* As long as the function is configured we can reset */
  63. if (probe)
  64. return 0;
  65. return zpci_hot_reset_device(zdev);
  66. }
  67. static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
  68. {
  69. struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
  70. hotplug_slot);
  71. *value = zpci_is_device_configured(zdev) ? 1 : 0;
  72. return 0;
  73. }
  74. static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
  75. {
  76. /* if the slot exits it always contains a function */
  77. *value = 1;
  78. return 0;
  79. }
  80. static const struct hotplug_slot_ops s390_hotplug_slot_ops = {
  81. .enable_slot = enable_slot,
  82. .disable_slot = disable_slot,
  83. .reset_slot = reset_slot,
  84. .get_power_status = get_power_status,
  85. .get_adapter_status = get_adapter_status,
  86. };
  87. int zpci_init_slot(struct zpci_dev *zdev)
  88. {
  89. char name[SLOT_NAME_SIZE];
  90. struct zpci_bus *zbus = zdev->zbus;
  91. zdev->hotplug_slot.ops = &s390_hotplug_slot_ops;
  92. snprintf(name, SLOT_NAME_SIZE, "%08x", zdev->fid);
  93. return pci_hp_register(&zdev->hotplug_slot, zbus->bus,
  94. zdev->devfn, name);
  95. }
  96. void zpci_exit_slot(struct zpci_dev *zdev)
  97. {
  98. pci_hp_deregister(&zdev->hotplug_slot);
  99. }