Commit 4ebeb1ec authored by CQ Tang's avatar CQ Tang Committed by Bjorn Helgaas

PCI: Restore PRI and PASID state after Function-Level Reset

After a Function-Level Reset, PCI states need to be restored.  Save PASID
features and PRI reqs cached.

[bhelgaas: search for capability only if PRI/PASID were enabled]
Signed-off-by: default avatarCQ Tang <cq.tang@intel.com>
Signed-off-by: default avatarAshok Raj <ashok.raj@intel.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Jean-Phillipe Brucker <jean-philippe.brucker@arm.com>
Cc: David Woodhouse <dwmw2@infradead.org>
parent a4f4fa68
...@@ -160,17 +160,16 @@ int pci_enable_pri(struct pci_dev *pdev, u32 reqs) ...@@ -160,17 +160,16 @@ int pci_enable_pri(struct pci_dev *pdev, u32 reqs)
if (!pos) if (!pos)
return -EINVAL; return -EINVAL;
pci_read_config_word(pdev, pos + PCI_PRI_CTRL, &control);
pci_read_config_word(pdev, pos + PCI_PRI_STATUS, &status); pci_read_config_word(pdev, pos + PCI_PRI_STATUS, &status);
if ((control & PCI_PRI_CTRL_ENABLE) || if (!(status & PCI_PRI_STATUS_STOPPED))
!(status & PCI_PRI_STATUS_STOPPED))
return -EBUSY; return -EBUSY;
pci_read_config_dword(pdev, pos + PCI_PRI_MAX_REQ, &max_requests); pci_read_config_dword(pdev, pos + PCI_PRI_MAX_REQ, &max_requests);
reqs = min(max_requests, reqs); reqs = min(max_requests, reqs);
pdev->pri_reqs_alloc = reqs;
pci_write_config_dword(pdev, pos + PCI_PRI_ALLOC_REQ, reqs); pci_write_config_dword(pdev, pos + PCI_PRI_ALLOC_REQ, reqs);
control |= PCI_PRI_CTRL_ENABLE; control = PCI_PRI_CTRL_ENABLE;
pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control); pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control);
pdev->pri_enabled = 1; pdev->pri_enabled = 1;
...@@ -205,6 +204,28 @@ void pci_disable_pri(struct pci_dev *pdev) ...@@ -205,6 +204,28 @@ void pci_disable_pri(struct pci_dev *pdev)
} }
EXPORT_SYMBOL_GPL(pci_disable_pri); EXPORT_SYMBOL_GPL(pci_disable_pri);
/**
* pci_restore_pri_state - Restore PRI
* @pdev: PCI device structure
*/
void pci_restore_pri_state(struct pci_dev *pdev)
{
u16 control = PCI_PRI_CTRL_ENABLE;
u32 reqs = pdev->pri_reqs_alloc;
int pos;
if (!pdev->pri_enabled)
return;
pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
if (!pos)
return;
pci_write_config_dword(pdev, pos + PCI_PRI_ALLOC_REQ, reqs);
pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control);
}
EXPORT_SYMBOL_GPL(pci_restore_pri_state);
/** /**
* pci_reset_pri - Resets device's PRI state * pci_reset_pri - Resets device's PRI state
* @pdev: PCI device structure * @pdev: PCI device structure
...@@ -224,12 +245,7 @@ int pci_reset_pri(struct pci_dev *pdev) ...@@ -224,12 +245,7 @@ int pci_reset_pri(struct pci_dev *pdev)
if (!pos) if (!pos)
return -EINVAL; return -EINVAL;
pci_read_config_word(pdev, pos + PCI_PRI_CTRL, &control); control = PCI_PRI_CTRL_RESET;
if (control & PCI_PRI_CTRL_ENABLE)
return -EBUSY;
control |= PCI_PRI_CTRL_RESET;
pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control); pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control);
return 0; return 0;
...@@ -259,12 +275,7 @@ int pci_enable_pasid(struct pci_dev *pdev, int features) ...@@ -259,12 +275,7 @@ int pci_enable_pasid(struct pci_dev *pdev, int features)
if (!pos) if (!pos)
return -EINVAL; return -EINVAL;
pci_read_config_word(pdev, pos + PCI_PASID_CTRL, &control);
pci_read_config_word(pdev, pos + PCI_PASID_CAP, &supported); pci_read_config_word(pdev, pos + PCI_PASID_CAP, &supported);
if (control & PCI_PASID_CTRL_ENABLE)
return -EINVAL;
supported &= PCI_PASID_CAP_EXEC | PCI_PASID_CAP_PRIV; supported &= PCI_PASID_CAP_EXEC | PCI_PASID_CAP_PRIV;
/* User wants to enable anything unsupported? */ /* User wants to enable anything unsupported? */
...@@ -272,6 +283,7 @@ int pci_enable_pasid(struct pci_dev *pdev, int features) ...@@ -272,6 +283,7 @@ int pci_enable_pasid(struct pci_dev *pdev, int features)
return -EINVAL; return -EINVAL;
control = PCI_PASID_CTRL_ENABLE | features; control = PCI_PASID_CTRL_ENABLE | features;
pdev->pasid_features = features;
pci_write_config_word(pdev, pos + PCI_PASID_CTRL, control); pci_write_config_word(pdev, pos + PCI_PASID_CTRL, control);
...@@ -284,7 +296,6 @@ EXPORT_SYMBOL_GPL(pci_enable_pasid); ...@@ -284,7 +296,6 @@ EXPORT_SYMBOL_GPL(pci_enable_pasid);
/** /**
* pci_disable_pasid - Disable the PASID capability * pci_disable_pasid - Disable the PASID capability
* @pdev: PCI device structure * @pdev: PCI device structure
*
*/ */
void pci_disable_pasid(struct pci_dev *pdev) void pci_disable_pasid(struct pci_dev *pdev)
{ {
...@@ -304,6 +315,27 @@ void pci_disable_pasid(struct pci_dev *pdev) ...@@ -304,6 +315,27 @@ void pci_disable_pasid(struct pci_dev *pdev)
} }
EXPORT_SYMBOL_GPL(pci_disable_pasid); EXPORT_SYMBOL_GPL(pci_disable_pasid);
/**
* pci_restore_pasid_state - Restore PASID capabilities
* @pdev: PCI device structure
*/
void pci_restore_pasid_state(struct pci_dev *pdev)
{
u16 control;
int pos;
if (!pdev->pasid_enabled)
return;
pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PASID);
if (!pos)
return;
control = PCI_PASID_CTRL_ENABLE | pdev->pasid_features;
pci_write_config_word(pdev, pos + PCI_PASID_CTRL, control);
}
EXPORT_SYMBOL_GPL(pci_restore_pasid_state);
/** /**
* pci_pasid_features - Check which PASID features are supported * pci_pasid_features - Check which PASID features are supported
* @pdev: PCI device structure * @pdev: PCI device structure
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/pci_hotplug.h> #include <linux/pci_hotplug.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/pci-ats.h>
#include <asm/setup.h> #include <asm/setup.h>
#include <asm/dma.h> #include <asm/dma.h>
#include <linux/aer.h> #include <linux/aer.h>
...@@ -1173,6 +1174,8 @@ void pci_restore_state(struct pci_dev *dev) ...@@ -1173,6 +1174,8 @@ void pci_restore_state(struct pci_dev *dev)
/* PCI Express register must be restored first */ /* PCI Express register must be restored first */
pci_restore_pcie_state(dev); pci_restore_pcie_state(dev);
pci_restore_pasid_state(dev);
pci_restore_pri_state(dev);
pci_restore_ats_state(dev); pci_restore_ats_state(dev);
pci_restore_vc_state(dev); pci_restore_vc_state(dev);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
int pci_enable_pri(struct pci_dev *pdev, u32 reqs); int pci_enable_pri(struct pci_dev *pdev, u32 reqs);
void pci_disable_pri(struct pci_dev *pdev); void pci_disable_pri(struct pci_dev *pdev);
void pci_restore_pri_state(struct pci_dev *pdev);
int pci_reset_pri(struct pci_dev *pdev); int pci_reset_pri(struct pci_dev *pdev);
#else /* CONFIG_PCI_PRI */ #else /* CONFIG_PCI_PRI */
...@@ -20,6 +21,10 @@ static inline void pci_disable_pri(struct pci_dev *pdev) ...@@ -20,6 +21,10 @@ static inline void pci_disable_pri(struct pci_dev *pdev)
{ {
} }
static inline void pci_restore_pri_state(struct pci_dev *pdev)
{
}
static inline int pci_reset_pri(struct pci_dev *pdev) static inline int pci_reset_pri(struct pci_dev *pdev)
{ {
return -ENODEV; return -ENODEV;
...@@ -31,6 +36,7 @@ static inline int pci_reset_pri(struct pci_dev *pdev) ...@@ -31,6 +36,7 @@ static inline int pci_reset_pri(struct pci_dev *pdev)
int pci_enable_pasid(struct pci_dev *pdev, int features); int pci_enable_pasid(struct pci_dev *pdev, int features);
void pci_disable_pasid(struct pci_dev *pdev); void pci_disable_pasid(struct pci_dev *pdev);
void pci_restore_pasid_state(struct pci_dev *pdev);
int pci_pasid_features(struct pci_dev *pdev); int pci_pasid_features(struct pci_dev *pdev);
int pci_max_pasids(struct pci_dev *pdev); int pci_max_pasids(struct pci_dev *pdev);
...@@ -45,6 +51,10 @@ static inline void pci_disable_pasid(struct pci_dev *pdev) ...@@ -45,6 +51,10 @@ static inline void pci_disable_pasid(struct pci_dev *pdev)
{ {
} }
static inline void pci_restore_pasid_state(struct pci_dev *pdev)
{
}
static inline int pci_pasid_features(struct pci_dev *pdev) static inline int pci_pasid_features(struct pci_dev *pdev)
{ {
return -EINVAL; return -EINVAL;
......
...@@ -400,6 +400,12 @@ struct pci_dev { ...@@ -400,6 +400,12 @@ struct pci_dev {
u16 ats_cap; /* ATS Capability offset */ u16 ats_cap; /* ATS Capability offset */
u8 ats_stu; /* ATS Smallest Translation Unit */ u8 ats_stu; /* ATS Smallest Translation Unit */
atomic_t ats_ref_cnt; /* number of VFs with ATS enabled */ atomic_t ats_ref_cnt; /* number of VFs with ATS enabled */
#endif
#ifdef CONFIG_PCI_PRI
u32 pri_reqs_alloc; /* Number of PRI requests allocated */
#endif
#ifdef CONFIG_PCI_PASID
u16 pasid_features;
#endif #endif
phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */ phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */
size_t romlen; /* Length of ROM if it's not from the BAR */ size_t romlen; /* Length of ROM if it's not from the BAR */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment