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 | 12 ++++++++++++ include/linux/pci-tph.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c index ba31b010f67a..91c1e83410a3 100644 --- a/drivers/pci/tph.c +++ b/drivers/pci/tph.c @@ -451,6 +451,18 @@ 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 (IV/DS) or 0 if disabled. + */ +int pcie_tph_enabled_mode(struct pci_dev *pdev) +{ + return pdev->tph_enabled ? pdev->tph_mode : 0; +} +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 5772d48ea444..28d0fa762146 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 0; } 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