On 6/8/26 20:56, Zhiping Zhang wrote:
> Add an optional dma-buf get_tph callback so an exporter can return TPH
> (TLP Processing Hints) metadata to an importer.
> 
> 8-bit ST and 16-bit Extended ST are distinct namespaces in the PCIe TPH
> ST table and may both be present with different values. The importer
> passes its supported steering-tag width and the exporter returns the
> matching value, or -EOPNOTSUPP if no metadata is available for that
> width.
> 
> The callback is intentionally exporter-owned and optional. The exporter
> owns the completing address space for the dma-buf, so only it can decide
> whether it has meaningful TPH metadata for that completer. The dma-buf
> core keeps the returned ST/PH tuple opaque and simply provides a
> discoverable negotiation point between exporter and importer; exporters
> that cannot derive a useful tuple just return -EOPNOTSUPP.
> 
> That keeps the kernel API generic rather than VFIO-specific. The first
> user is VFIO_DEVICE_FEATURE_DMA_BUF_TPH in vfio-pci, with the mlx5 RDMA
> driver as the first importer, but any future exporter that can derive a
> TPH tuple for its completing address space can reuse the same callback.
> 
> Signed-off-by: Zhiping Zhang <[email protected]>
> ---
>  include/linux/dma-buf.h | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
> index d1203da56fc5..8437dbe4a83e 100644
> --- a/include/linux/dma-buf.h
> +++ b/include/linux/dma-buf.h
> @@ -113,6 +113,37 @@ struct dma_buf_ops {
>        */
>       void (*unpin)(struct dma_buf_attachment *attach);
>  
> +     /**
> +      * @get_tph:
> +      * @dmabuf: DMA buffer for which to retrieve TPH metadata
> +      * @extended: false to request the 8-bit ST namespace, true to request
> +      *            the 16-bit Extended ST namespace
> +      * @steering_tag: Returns the raw TPH steering tag for the requested
> +      *                namespace
> +      * @ph: Returns the TPH processing hint (2-bit value)
> +      *
> +      * Return the TPH (TLP Processing Hints) metadata associated with this
> +      * DMA buffer for the requested steering-tag namespace. 8-bit ST and
> +      * 16-bit Extended ST are distinct namespaces in the PCIe TPH ST table
> +      * and may both be present with different values, so the exporter must
> +      * select the value that matches @extended and must not substitute one
> +      * for the other.
> +      *
> +      * The exporter owns the completing address space for @dmabuf and
> +      * therefore decides whether it can derive meaningful TPH metadata for
> +      * that completer. The dma-buf core treats the returned ST/PH tuple as
> +      * opaque transport metadata; importers that support TPH place it on
> +      * outbound TLPs, while exporters that cannot derive a useful tuple
> +      * simply return -EOPNOTSUPP.
> +      *
> +      * Return 0 on success, or -EOPNOTSUPP if no metadata is available for
> +      * the requested namespace.
> +      *
> +      * This callback is optional.
> +      */
> +     int (*get_tph)(struct dma_buf *dmabuf, bool extended,
> +                    u16 *steering_tag, u8 *ph);
> +

That needs a wrapper for importers to call which also handles if the callback 
isn't present.

Regards,
Christian.

>       /**
>        * @map_dma_buf:
>        *

Reply via email to