From: Bjorn Helgaas <helgaas@kernel.org>
To: Zhiping Zhang <zhipingz@meta.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
Michael Guralnik <michaelgur@nvidia.com>,
Sumit Semwal <sumit.semwal@linaro.org>,
Christian Konig <christian.koenig@amd.com>,
Alex Williamson <alex@shazbot.org>,
Bjorn Helgaas <bhelgaas@google.com>,
kvm@vger.kernel.org, linux-rdma@vger.kernel.org,
linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v13 2/5] PCI/TPH: Add requester/completer type helpers
Date: Tue, 15 Sep 2026 17:23:03 -0500 [thread overview]
Message-ID: <20260915222303.GA877199@bhelgaas> (raw)
In-Reply-To: <20260731211601.3033906-3-zhipingz@meta.com>
On Fri, Jul 31, 2026 at 02:15:49PM -0700, Zhiping Zhang wrote:
> Add pcie_tph_enabled_req_type() so drivers can query the enabled TPH
> requester mode without reaching into pci_dev internals.
>
> Add pcie_tph_completer_type() so drivers that publish TPH metadata for a
> device acting as a completer can gate on the "TPH Completer Supported"
> field of Device Capabilities 2 (bits 13:12, PCI_EXP_DEVCAP2_TPH_COMP_MASK)
> rather than reusing requester-side state. It applies the same reserved-
> encoding fold as get_rp_completer_type(), inlined, so the reserved 0b10
> value never reaches callers.
>
> This keeps pci_dev::tph_req_type and the completer-capability decode
> inside the PCI/TPH code and provides !CONFIG_PCIE_TPH stubs for callers.
>
> Signed-off-by: Zhiping Zhang <zhipingz@meta.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
> ---
> drivers/pci/tph.c | 44 +++++++++++++++++++++++++++++++++++++++++
> include/linux/pci-tph.h | 8 ++++++++
> 2 files changed, 52 insertions(+)
>
> diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
> index 5cbb381e2a02..d0202ff7a1b2 100644
> --- a/drivers/pci/tph.c
> +++ b/drivers/pci/tph.c
> @@ -223,6 +223,50 @@ static u8 get_rp_completer_type(struct pci_dev *pdev)
> return PCI_EXP_DEVCAP2_TPH_COMP_NONE;
> }
>
> +/**
> + * pcie_tph_enabled_req_type - Return the device's enabled TPH requester type
> + * @pdev: PCI device to query
> + *
> + * Return: PCI_TPH_REQ_DISABLE, PCI_TPH_REQ_TPH_ONLY or PCI_TPH_REQ_EXT_TPH.
> + */
> +u8 pcie_tph_enabled_req_type(struct pci_dev *pdev)
> +{
> + return pdev->tph_req_type;
> +}
> +EXPORT_SYMBOL(pcie_tph_enabled_req_type);
> +
> +/**
> + * pcie_tph_completer_type - Return the device's TPH Completer support
> + * @pdev: PCI device to query
> + *
> + * Reads the "TPH Completer Supported" field (bits 13:12) of Device
s/Reads/Read/ to match other doc ("Return ... type" above, "Write tag" below)
> + * Capabilities 2. The reserved 0b10 encoding is folded into
> + * "not supported" so callers only need to compare against the three
> + * defined values.
s/The reserved 0b10 encoding is folded/Fold reserved 0b10 encoding/
> + *
> + * Return: one of %PCI_EXP_DEVCAP2_TPH_COMP_NONE,
> + * %PCI_EXP_DEVCAP2_TPH_COMP_TPH_ONLY or
> + * %PCI_EXP_DEVCAP2_TPH_COMP_EXT_TPH.
> + */
> +u8 pcie_tph_completer_type(struct pci_dev *pdev)
> +{
> + u8 tph_comp;
> + u32 reg;
> +
> + if (pcie_capability_read_dword(pdev, PCI_EXP_DEVCAP2, ®))
> + return PCI_EXP_DEVCAP2_TPH_COMP_NONE;
> + if (PCI_POSSIBLE_ERROR(reg))
> + return PCI_EXP_DEVCAP2_TPH_COMP_NONE;
> +
> + /* 0b10 is reserved; fold it into "not supported" (see above). */
> + tph_comp = FIELD_GET(PCI_EXP_DEVCAP2_TPH_COMP_MASK, reg);
> + if (tph_comp == PCI_EXP_DEVCAP2_TPH_COMP_TPH_ONLY ||
> + tph_comp == PCI_EXP_DEVCAP2_TPH_COMP_EXT_TPH)
> + return tph_comp;
> + return PCI_EXP_DEVCAP2_TPH_COMP_NONE;
> +}
> +EXPORT_SYMBOL(pcie_tph_completer_type);
> +
> /* Write tag to ST table - Return 0 if OK, otherwise -errno */
> static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)
> {
> diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h
> index be68cd17f2f8..7743af6fe432 100644
> --- a/include/linux/pci-tph.h
> +++ b/include/linux/pci-tph.h
> @@ -9,6 +9,8 @@
> #ifndef LINUX_PCI_TPH_H
> #define LINUX_PCI_TPH_H
>
> +#include <linux/pci_regs.h>
> +
> /*
> * According to the ECN for PCI Firmware Spec, Steering Tag can be different
> * depending on the memory type: Volatile Memory or Persistent Memory. When a
> @@ -30,6 +32,8 @@ void pcie_disable_tph(struct pci_dev *pdev);
> int pcie_enable_tph(struct pci_dev *pdev, int mode);
> 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_enabled_req_type(struct pci_dev *pdev);
> +u8 pcie_tph_completer_type(struct pci_dev *pdev);
> #else
> static inline int pcie_tph_set_st_entry(struct pci_dev *pdev,
> unsigned int index, u16 tag)
> @@ -41,6 +45,10 @@ 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 u8 pcie_tph_enabled_req_type(struct pci_dev *pdev)
> +{ return PCI_TPH_REQ_DISABLE; }
> +static inline u8 pcie_tph_completer_type(struct pci_dev *pdev)
> +{ return PCI_EXP_DEVCAP2_TPH_COMP_NONE; }
> #endif
>
> #endif /* LINUX_PCI_TPH_H */
> --
> 2.53.0-Meta
>
next prev parent reply other threads:[~2026-09-15 22:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 21:15 [PATCH v13 0/5] vfio/dma-buf: add TPH support for peer-to-peer access Zhiping Zhang
2026-07-31 21:15 ` [PATCH v13 1/5] PCI/TPH: treat reserved 0b10 completer encoding as unsupported Zhiping Zhang
2026-07-31 21:38 ` sashiko-bot
2026-09-15 22:19 ` Bjorn Helgaas
2026-09-15 23:14 ` Zhiping Zhang
2026-07-31 21:15 ` [PATCH v13 2/5] PCI/TPH: Add requester/completer type helpers Zhiping Zhang
2026-07-31 21:40 ` sashiko-bot
2026-08-03 1:21 ` fengchengwen
2026-09-15 22:23 ` Bjorn Helgaas [this message]
2026-09-15 23:27 ` Zhiping Zhang
2026-07-31 21:15 ` [PATCH v13 3/5] dma-buf: add optional get_pci_tph() callback Zhiping Zhang
2026-07-31 21:37 ` sashiko-bot
2026-07-31 21:15 ` [PATCH v13 4/5] vfio/pci: implement get_pci_tph and DMA_BUF_TPH feature Zhiping Zhang
2026-07-31 21:38 ` sashiko-bot
2026-07-31 21:15 ` [PATCH v13 5/5] RDMA/mlx5: get tph for p2p access when registering dma-buf mr Zhiping Zhang
2026-07-31 21:48 ` sashiko-bot
2026-07-31 22:59 ` Zhiping Zhang
2026-09-23 19:11 ` Zhiping Zhang
2026-09-24 1:13 ` fengchengwen
2026-09-24 6:24 ` Zhiping Zhang
2026-09-24 23:30 ` Jason Gunthorpe
2026-09-25 6:17 ` Zhiping Zhang
2026-09-28 17:29 ` Jason Gunthorpe
2026-09-28 21:47 ` Zhiping Zhang
2026-09-30 12:13 ` Leon Romanovsky
2026-10-05 21:33 ` Zhiping Zhang
2026-08-14 18:08 ` [PATCH v13 0/5] vfio/dma-buf: add TPH support for peer-to-peer access Zhiping Zhang
2026-09-02 20:53 ` Zhiping Zhang
2026-09-10 21:46 ` [PATCH v13 0/5] vfio/dma-buf: add TPH support for peer-to-peer access - ping Zhiping Zhang
2026-09-11 7:58 ` Christian König
2026-09-14 16:44 ` Zhiping Zhang
2026-09-15 20:49 ` Alex Williamson
2026-09-16 0:17 ` Zhiping Zhang
2026-09-15 11:37 ` Leon Romanovsky
2026-09-15 12:59 ` Christian König
2026-09-15 13:37 ` Leon Romanovsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260915222303.GA877199@bhelgaas \
--to=helgaas@kernel.org \
--cc=alex@shazbot.org \
--cc=bhelgaas@google.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jgg@ziepe.ca \
--cc=kvm@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=michaelgur@nvidia.com \
--cc=sumit.semwal@linaro.org \
--cc=zhipingz@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox