Skip to content

Commit

Permalink
PCI: Notify driver before and after device reset
Browse files Browse the repository at this point in the history
Notify a PCI device driver when its device's access is about to be disabled
for an impending reset attempt, then after the attempt completes and device
access is restored.  The notification is via the pci_error_handlers
interface.

Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
  • Loading branch information
Keith Busch authored and Bjorn Helgaas committed May 27, 2014
1 parent 761ce53 commit 3ebe7f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions drivers/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -3305,8 +3305,27 @@ static void pci_dev_unlock(struct pci_dev *dev)
pci_cfg_access_unlock(dev);
}

/**
* pci_reset_notify - notify device driver of reset
* @dev: device to be notified of reset
* @prepare: 'true' if device is about to be reset; 'false' if reset attempt
* completed
*
* Must be called prior to device access being disabled and after device
* access is restored.
*/
static void pci_reset_notify(struct pci_dev *dev, bool prepare)
{
const struct pci_error_handlers *err_handler =
dev->driver ? dev->driver->err_handler : NULL;
if (err_handler && err_handler->reset_notify)
err_handler->reset_notify(dev, prepare);
}

static void pci_dev_save_and_disable(struct pci_dev *dev)
{
pci_reset_notify(dev, true);

/*
* Wake-up device prior to save. PM registers default to D0 after
* reset and a simple register restore doesn't reliably return
Expand All @@ -3328,6 +3347,7 @@ static void pci_dev_save_and_disable(struct pci_dev *dev)
static void pci_dev_restore(struct pci_dev *dev)
{
pci_restore_state(dev);
pci_reset_notify(dev, false);
}

static int pci_dev_reset(struct pci_dev *dev, int probe)
Expand All @@ -3344,6 +3364,7 @@ static int pci_dev_reset(struct pci_dev *dev, int probe)

return rc;
}

/**
* __pci_reset_function - reset a PCI device function
* @dev: PCI device to reset
Expand Down
3 changes: 3 additions & 0 deletions include/linux/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ struct pci_error_handlers {
/* PCI slot has been reset */
pci_ers_result_t (*slot_reset)(struct pci_dev *dev);

/* PCI function reset prepare or completed */
void (*reset_notify)(struct pci_dev *dev, bool prepare);

/* Device driver may resume normal operations */
void (*resume)(struct pci_dev *dev);
};
Expand Down

0 comments on commit 3ebe7f9

Please sign in to comment.