Add a helper to query enabled TPH mode on a PCI device. This is useful for drivers like VFIO-PCI that need to validate TPH state before allowing access to steering tag tables. Signed-off-by: Chengwen Feng --- drivers/pci/tph.c | 14 ++++++++++++++ include/linux/pci-tph.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c index 11a06730e08c..95e2a95055ee 100644 --- a/drivers/pci/tph.c +++ b/drivers/pci/tph.c @@ -451,6 +451,20 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode) } EXPORT_SYMBOL(pcie_enable_tph); +/** + * pcie_tph_enabled_mode - Get current enabled TPH mode + * @pdev: PCI device + * + * Return: the enabled TPH mode (one of PCI_TPH_ST_NS_MODE, PCI_TPH_ST_IV_MODE + * or PCI_TPH_ST_DS_MODE) on success, or -EINVAL if TPH is not currently + * enabled on the device. + */ +int pcie_tph_enabled_mode(struct pci_dev *pdev) +{ + return pdev->tph_enabled ? pdev->tph_mode : -EINVAL; +} +EXPORT_SYMBOL(pcie_tph_enabled_mode); + void pci_restore_tph_state(struct pci_dev *pdev) { struct pci_cap_saved_state *save_state; diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h index 5c3997f4b51b..e8c9166e33dd 100644 --- a/include/linux/pci-tph.h +++ b/include/linux/pci-tph.h @@ -28,6 +28,7 @@ int pcie_tph_get_cpu_st(struct pci_dev *dev, unsigned int cpu, u16 *tag); void pcie_disable_tph(struct pci_dev *pdev); int pcie_enable_tph(struct pci_dev *pdev, int mode); +int pcie_tph_enabled_mode(struct pci_dev *pdev); u16 pcie_tph_get_st_table_size(struct pci_dev *pdev); u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev); u8 pcie_tph_get_st_modes(struct pci_dev *pdev); @@ -42,6 +43,8 @@ static inline int pcie_tph_get_cpu_st(struct pci_dev *dev, static inline void pcie_disable_tph(struct pci_dev *pdev) { } static inline int pcie_enable_tph(struct pci_dev *pdev, int mode) { return -EINVAL; } +static inline int pcie_tph_enabled_mode(struct pci_dev *pdev) +{ return -EINVAL; } static inline u16 pcie_tph_get_st_table_size(struct pci_dev *pdev) { return 0; } static inline u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev) -- 2.17.1