PCI device drivers can define own pci_error_handlers which are called on errors or before/after reset. The VFIO PCI driver defines one as well. This adds a vfio_pci_error_handlers struct for VFIO PCI which is a wrapper on top of vfio_err_handlers. At the moment it defines reset_done() - this hook is called right after the device reset and it can be used to do some device tweaking before the userspace gets a chance to use the device. Signed-off-by: Alexey Kardashevskiy <aik@xxxxxxxxx> --- drivers/vfio/pci/vfio_pci_private.h | 5 +++++ drivers/vfio/pci/vfio_pci.c | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index 1812cf22fc4f..aff96fa28726 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -87,8 +87,13 @@ struct vfio_pci_reflck { struct mutex lock; }; +struct vfio_pci_error_handlers { + void (*reset_done)(struct vfio_pci_device *vdev); +}; + struct vfio_pci_device { struct pci_dev *pdev; + struct vfio_pci_error_handlers *error_handlers; void __iomem *barmap[PCI_STD_RESOURCE_END + 1]; bool bar_mmap_supported[PCI_STD_RESOURCE_END + 1]; u8 *pci_config_map; diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 5bd97fa632d3..6ebc441d91c3 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -1434,8 +1434,25 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, return PCI_ERS_RESULT_CAN_RECOVER; } +static void vfio_pci_reset_done(struct pci_dev *dev) +{ + struct vfio_pci_device *vdev; + struct vfio_device *device; + + device = vfio_device_get_from_dev(&dev->dev); + if (device == NULL) + return; + + vdev = vfio_device_data(device); + if (vdev && vdev->error_handlers && vdev->error_handlers->reset_done) + vdev->error_handlers->reset_done(vdev); + + vfio_device_put(device); +} + static const struct pci_error_handlers vfio_err_handlers = { .error_detected = vfio_pci_aer_err_detected, + .reset_done = vfio_pci_reset_done, }; static struct pci_driver vfio_pci_driver = { -- 2.17.1