tph.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===========
  3. TPH Support
  4. ===========
  5. :Copyright: 2024 Advanced Micro Devices, Inc.
  6. :Authors: - Eric van Tassell <eric.vantassell@amd.com>
  7. - Wei Huang <wei.huang2@amd.com>
  8. Overview
  9. ========
  10. TPH (TLP Processing Hints) is a PCIe feature that allows endpoint devices
  11. to provide optimization hints for requests that target memory space.
  12. These hints, in a format called Steering Tags (STs), are embedded in the
  13. requester's TLP headers, enabling the system hardware, such as the Root
  14. Complex, to better manage platform resources for these requests.
  15. For example, on platforms with TPH-based direct data cache injection
  16. support, an endpoint device can include appropriate STs in its DMA
  17. traffic to specify which cache the data should be written to. This allows
  18. the CPU core to have a higher probability of getting data from cache,
  19. potentially improving performance and reducing latency in data
  20. processing.
  21. How to Use TPH
  22. ==============
  23. TPH is presented as an optional extended capability in PCIe. The Linux
  24. kernel handles TPH discovery during boot, but it is up to the device
  25. driver to request TPH enablement if it is to be utilized. Once enabled,
  26. the driver uses the provided API to obtain the Steering Tag for the
  27. target memory and to program the ST into the device's ST table.
  28. Enable TPH support in Linux
  29. ---------------------------
  30. To support TPH, the kernel must be built with the CONFIG_PCIE_TPH option
  31. enabled.
  32. Manage TPH
  33. ----------
  34. To enable TPH for a device, use the following function::
  35. int pcie_enable_tph(struct pci_dev *pdev, int mode);
  36. This function enables TPH support for device with a specific ST mode.
  37. Current supported modes include:
  38. * PCI_TPH_ST_NS_MODE - NO ST Mode
  39. * PCI_TPH_ST_IV_MODE - Interrupt Vector Mode
  40. * PCI_TPH_ST_DS_MODE - Device Specific Mode
  41. `pcie_enable_tph()` checks whether the requested mode is actually
  42. supported by the device before enabling. The device driver can figure out
  43. which TPH mode is supported and can be properly enabled based on the
  44. return value of `pcie_enable_tph()`.
  45. To disable TPH, use the following function::
  46. void pcie_disable_tph(struct pci_dev *pdev);
  47. Manage ST
  48. ---------
  49. Steering Tags are platform specific. PCIe spec does not specify where STs
  50. are from. Instead PCI Firmware Specification defines an ACPI _DSM method
  51. (see the `Revised _DSM for Cache Locality TPH Features ECN
  52. <https://members.pcisig.com/wg/PCI-SIG/document/15470>`_) for retrieving
  53. STs for a target memory of various properties. This method is what is
  54. supported in this implementation.
  55. To retrieve a Steering Tag for a target memory associated with a specific
  56. CPU, use the following function::
  57. int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type type,
  58. unsigned int cpu_uid, u16 *tag);
  59. The `type` argument is used to specify the memory type, either volatile
  60. or persistent, of the target memory. The `cpu_uid` argument specifies the
  61. CPU where the memory is associated to.
  62. After the ST value is retrieved, the device driver can use the following
  63. function to write the ST into the device::
  64. int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index,
  65. u16 tag);
  66. The `index` argument is the ST table entry index the ST tag will be
  67. written into. `pcie_tph_set_st_entry()` will figure out the proper
  68. location of ST table, either in the MSI-X table or in the TPH Extended
  69. Capability space, and write the Steering Tag into the ST entry pointed by
  70. the `index` argument.
  71. It is completely up to the driver to decide how to use these TPH
  72. functions. For example a network device driver can use the TPH APIs above
  73. to update the Steering Tag when interrupt affinity of a RX/TX queue has
  74. been changed. Here is a sample code for IRQ affinity notifier:
  75. .. code-block:: c
  76. static void irq_affinity_notified(struct irq_affinity_notify *notify,
  77. const cpumask_t *mask)
  78. {
  79. struct drv_irq *irq;
  80. unsigned int cpu_id;
  81. u16 tag;
  82. irq = container_of(notify, struct drv_irq, affinity_notify);
  83. cpumask_copy(irq->cpu_mask, mask);
  84. /* Pick a right CPU as the target - here is just an example */
  85. cpu_id = cpumask_first(irq->cpu_mask);
  86. if (pcie_tph_get_cpu_st(irq->pdev, TPH_MEM_TYPE_VM, cpu_id,
  87. &tag))
  88. return;
  89. if (pcie_tph_set_st_entry(irq->pdev, irq->msix_nr, tag))
  90. return;
  91. }
  92. Disable TPH system-wide
  93. -----------------------
  94. There is a kernel command line option available to control TPH feature:
  95. * "notph": TPH will be disabled for all endpoint devices.