Skip to content

Commit da995d5

Browse files
niklas88Vasily Gorbik
authored andcommitted
s390/pci: implement reset_slot for hotplug slot
This is done by adding a zpci_hot_reset_device() call which does a low level reset of the PCI function without changing its higher level function state. This way it can be used while the zPCI function is bound to a driver and with DMA tables being controlled either through the IOMMU or DMA APIs which is prohibited when using zpci_disable_device() as that drop existing DMA translations. As this reset, unlike a normal FLR, also calls zpci_clear_irq() we need to implement arch_restore_msi_irqs() and make sure we re-enable IRQs for the PCI function if they were previously disabled. Reviewed-by: Pierre Morel <[email protected]> Reviewed-by: Matthew Rosato <[email protected]> Signed-off-by: Niklas Schnelle <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent 4fe2049 commit da995d5

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

arch/s390/include/asm/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int zpci_deconfigure_device(struct zpci_dev *zdev);
210210
void zpci_device_reserved(struct zpci_dev *zdev);
211211
bool zpci_is_device_configured(struct zpci_dev *zdev);
212212

213+
int zpci_hot_reset_device(struct zpci_dev *zdev);
213214
int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64);
214215
int zpci_unregister_ioat(struct zpci_dev *, u8);
215216
void zpci_remove_reserved_devices(void);

arch/s390/pci/pci.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,65 @@ int zpci_disable_device(struct zpci_dev *zdev)
723723
return rc;
724724
}
725725

726+
/**
727+
* zpci_hot_reset_device - perform a reset of the given zPCI function
728+
* @zdev: the slot which should be reset
729+
*
730+
* Performs a low level reset of the zPCI function. The reset is low level in
731+
* the sense that the zPCI function can be reset without detaching it from the
732+
* common PCI subsystem. The reset may be performed while under control of
733+
* either DMA or IOMMU APIs in which case the existing DMA/IOMMU translation
734+
* table is reinstated at the end of the reset.
735+
*
736+
* After the reset the functions internal state is reset to an initial state
737+
* equivalent to its state during boot when first probing a driver.
738+
* Consequently after reset the PCI function requires re-initialization via the
739+
* common PCI code including re-enabling IRQs via pci_alloc_irq_vectors()
740+
* and enabling the function via e.g.pci_enablde_device_flags().The caller
741+
* must guard against concurrent reset attempts.
742+
*
743+
* In most cases this function should not be called directly but through
744+
* pci_reset_function() or pci_reset_bus() which handle the save/restore and
745+
* locking.
746+
*
747+
* Return: 0 on success and an error value otherwise
748+
*/
749+
int zpci_hot_reset_device(struct zpci_dev *zdev)
750+
{
751+
int rc;
752+
753+
zpci_dbg(3, "rst fid:%x, fh:%x\n", zdev->fid, zdev->fh);
754+
if (zdev_enabled(zdev)) {
755+
/* Disables device access, DMAs and IRQs (reset state) */
756+
rc = zpci_disable_device(zdev);
757+
/*
758+
* Due to a z/VM vs LPAR inconsistency in the error state the
759+
* FH may indicate an enabled device but disable says the
760+
* device is already disabled don't treat it as an error here.
761+
*/
762+
if (rc == -EINVAL)
763+
rc = 0;
764+
if (rc)
765+
return rc;
766+
}
767+
768+
rc = zpci_enable_device(zdev);
769+
if (rc)
770+
return rc;
771+
772+
if (zdev->dma_table)
773+
rc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
774+
(u64)zdev->dma_table);
775+
else
776+
rc = zpci_dma_init_device(zdev);
777+
if (rc) {
778+
zpci_disable_device(zdev);
779+
return rc;
780+
}
781+
782+
return 0;
783+
}
784+
726785
/**
727786
* zpci_create_device() - Create a new zpci_dev and add it to the zbus
728787
* @fid: Function ID of the device to be created

arch/s390/pci/pci_irq.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ void arch_teardown_msi_irqs(struct pci_dev *pdev)
387387
airq_iv_free(zpci_ibv[0], zdev->msi_first_bit, zdev->msi_nr_irqs);
388388
}
389389

390+
void arch_restore_msi_irqs(struct pci_dev *pdev)
391+
{
392+
struct zpci_dev *zdev = to_zpci(pdev);
393+
394+
if (!zdev->irqs_registered)
395+
zpci_set_irq(zdev);
396+
default_restore_msi_irqs(pdev);
397+
}
398+
390399
static struct airq_struct zpci_airq = {
391400
.handler = zpci_floating_irq_handler,
392401
.isc = PCI_ISC,

drivers/pci/hotplug/s390_pci_hpc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
5757
return zpci_deconfigure_device(zdev);
5858
}
5959

60+
static int reset_slot(struct hotplug_slot *hotplug_slot, bool probe)
61+
{
62+
struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
63+
hotplug_slot);
64+
65+
if (zdev->state != ZPCI_FN_STATE_CONFIGURED)
66+
return -EIO;
67+
/*
68+
* We can't take the zdev->lock as reset_slot may be called during
69+
* probing and/or device removal which already happens under the
70+
* zdev->lock. Instead the user should use the higher level
71+
* pci_reset_function() or pci_bus_reset() which hold the PCI device
72+
* lock preventing concurrent removal. If not using these functions
73+
* holding the PCI device lock is required.
74+
*/
75+
76+
/* As long as the function is configured we can reset */
77+
if (probe)
78+
return 0;
79+
80+
return zpci_hot_reset_device(zdev);
81+
}
82+
6083
static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
6184
{
6285
struct zpci_dev *zdev = container_of(hotplug_slot, struct zpci_dev,
@@ -76,6 +99,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
7699
static const struct hotplug_slot_ops s390_hotplug_slot_ops = {
77100
.enable_slot = enable_slot,
78101
.disable_slot = disable_slot,
102+
.reset_slot = reset_slot,
79103
.get_power_status = get_power_status,
80104
.get_adapter_status = get_adapter_status,
81105
};

0 commit comments

Comments
 (0)