PCIe TPH and cache direct injection support
Subsystems (5)
v4 cover PCIe TPH and cache direct injection support
Hi All,
TPH (TLP Processing Hints) is a PCIe feature that allows endpoint devices to provide optimization hints for requests that target memory space. These hints, in a format called steering tag (ST), are provided in the requester's TLP headers and allow the system hardware, including the Root Complex, to optimize the utilization of platform resources for the requests.
Upcoming AMD hardware implement a new Cache Injection feature that leverages TPH. Cache Injection allows PCIe endpoints to inject I/O Coherent DMA writes directly into an L2 within the CCX (core complex) closest to the CPU core that will consume it. This technology is aimed at applications requiring high performance and low latency, such as networking and storage applications.
This series introduces generic TPH support in Linux, allowing STs to be retrieved and used by PCIe endpoint drivers as needed. As a demonstration, it includes an example usage in the Broadcom BNXT driver. When running on Broadcom NICs with the appropriate firmware, it shows substantial memory bandwidth savings and better network bandwidth using real-world benchmarks. This solution is vendor-neutral and implemented based on industry standards (PCIe Spec and PCI FW Spec).
V3->V4:
* Rebase on top of the latest pci/next tree (tag: 6.11-rc1)
* Add new API functioins to query/enable/disable TPH support
* Make pcie_tph_set_st() completely independent from pcie_tph_get_cpu_st()
* Rewrite bnxt.c based on new APIs
* Remove documentation for now due to constantly changing API
* Remove pci=notph, but keep pci=nostmode with better flow (Bjorn)
* Lots of code rewrite in tph.c & pci-tph.h with cleaner interface (Bjorn)
* Add TPH save/restore support (Paul Luse and Lukas Wunner)
V2->V3:
* Rebase on top of pci/next tree (tag: pci-v6.11-changes)
* Redefine PCI TPH registers (pci_regs.h) without breaking uapi
* Fix commit subjects/messages for kernel options (Jonathan and Bjorn)
* Break API functions into three individual patches for easy review
* Rewrite lots of code in tph.c/tph.h based (Jonathan and Bjorn)
V1->V2:
* Rebase on top of pci.git/for-linus (6.10-rc1)
* Address mismatched data types reported by Sparse (Sparse check passed)
* Add pcie_tph_intr_vec_supported() for checking IRQ mode support
* Skip bnxt affinity notifier registration if pcie_tph_intr_vec_supported()=false
* Minor fixes in bnxt driver (i.e. warning messages)
Manoj Panicker (1):
bnxt_en: Add TPH support in BNXT driver
Michael Chan (1):
bnxt_en: Pass NQ ID to the FW when allocating RX/RX AGG rings
Paul Luse (1):
PCI/TPH: Add save/restore support for TPH
Wei Huang (9):
PCI: Introduce PCIe TPH support framework
PCI: Add TPH related register definition PCI/TPH: Add pcie_tph_modes() to query TPH modes PCI/TPH: Add pcie_enable_tph() to enable TPH PCI/TPH: Add pcie_disable_tph() to disable TPH PCI/TPH: Add pcie_tph_enabled() to check TPH state PCI/TPH: Add pcie_tph_set_st_entry() to set ST tag PCI/TPH: Add pcie_tph_get_cpu_st() to get ST tag PCI/TPH: Add pci=nostmode to force TPH No ST Mode
.../admin-guide/kernel-parameters.txt | 3 + drivers/net/ethernet/broadcom/bnxt/bnxt.c | 86 ++- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 4 + drivers/pci/pci.c | 4 + drivers/pci/pci.h | 12 + drivers/pci/pcie/Kconfig | 11 + drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/tph.c | 563 ++++++++++++++++++ drivers/pci/probe.c | 1 + include/linux/pci-tph.h | 48 ++ include/linux/pci.h | 7 + include/uapi/linux/pci_regs.h | 38 +- 12 files changed, 768 insertions(+), 10 deletions(-) create mode 100644 drivers/pci/pcie/tph.c create mode 100644 include/linux/pci-tph.h
Signature · 1 line
2.45.1
PATCH v4 1/12 PCI: Introduce PCIe TPH support framework
Implement the framework for PCIe TPH support by introducing tph.c source file, along with CONFIG_PCIE_TPH, to Linux PCIe subsystem. Add tph_cap in pci_dev to cache TPH capability offset.
--- drivers/pci/pci.h | 6 ++++++ drivers/pci/pcie/Kconfig | 11 +++++++++++ drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/tph.c | 15 +++++++++++++++ drivers/pci/probe.c | 1 + include/linux/pci.h | 4 ++++ 6 files changed, 38 insertions(+) create mode 100644 drivers/pci/pcie/tph.c
drivers/pci/pci.h +6 -0
@@ -571,6 +571,12 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)#endif /* CONFIG_PCI_IOV */ +#ifdef CONFIG_PCIE_TPH +void pci_tph_init (struct pci_dev *dev); +#else +static inline void pci_tph_init (struct pci_dev *dev) { } +#endif +#ifdef CONFIG_PCIE_PTM void pci_ptm_init (struct pci_dev *dev);void pci_save_ptm_state (struct pci_dev *dev);
drivers/pci/pcie/Kconfig +11 -0
@@ -155,3 +155,14 @@ config PCIE_EDR the PCI Firmware Specification r3.2. Enable this if you want to support hybrid DPC model which uses both firmware and OS to implement DPC. + +config PCIE_TPH + bool "TLP Processing Hints" + depends on ACPI + default n + help + This option adds support for PCIe TLP Processing Hints (TPH). + TPH allows endpoint devices to provide optimization hints, such as + desired caching behavior, for requests that target memory space. + These hints, called Steering Tags, can empower the system hardware + to optimize the utilization of platform resources.
drivers/pci/pcie/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_PCIE_PME) += pme.o obj-$(CONFIG_PCIE_DPC) += dpc.o obj-$(CONFIG_PCIE_PTM) += ptm.o obj-$(CONFIG_PCIE_EDR) += edr.o +obj-$(CONFIG_PCIE_TPH) += tph.o
drivers/pci/pcie/tph.c new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* TPH (TLP Processing Hints) support +* +* Copyright (C) 2024 Advanced Micro Devices, Inc. +* Eric Van Tassell <[email protected]> +* Wei Huang <[email protected]> +*/ + +#include "../pci.h" + +void pci_tph_init (struct pci_dev *pdev) +{ + pdev->tph_cap =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_TPH ); +}
drivers/pci/probe.c +1 -0
@@ -2498,6 +2498,7 @@ static void pci_init_capabilities(struct pci_dev *dev)pci_dpc_init (dev);/* Downstream Port Containment */ pci_rcec_init (dev);/* Root Complex Event Collector */ pci_doe_init (dev);/* Data Object Exchange */ +pci_tph_init (dev);/* TLP Processing Hints */ pcie_report_downtraining (dev);pci_init_reset_methods (dev);
include/linux/pci.h +4 -0
@@ -530,6 +530,10 @@ struct pci_dev {/* These methods index pci_reset_fn_methods[] */ u8 reset_methods[PCI_NUM_RESET_METHODS ];/* In priority order */ + +#ifdef CONFIG_PCIE_TPH +u16 tph_cap;/* TPH capability offset */ +#endif };static inline struct pci_dev *pci_physfn (struct pci_dev *dev)
Signature · 1 line
2.45.1
PATCH v4 2/12 PCI: Add TPH related register definition
In reply to Wei HuangLinux has some basic, but incomplete, definition for the TPH Requester capability registers. Also the definitions of TPH Requester control register and TPH Completer capability, as well as the ST fields of MSI-X entry, are missing. Add all required definitions to support TPH without changing the existing Linux UAPI.
--- include/uapi/linux/pci_regs.h | 38 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
include/uapi/linux/pci_regs.h +30 -8
@@ -340,7 +340,9 @@#define PCI_MSIX_ENTRY_UPPER_ADDR 0x4/* Message Upper Address */ #define PCI_MSIX_ENTRY_DATA 0x8/* Message Data */ #define PCI_MSIX_ENTRY_VECTOR_CTRL 0xc/* Vector Control */ -#define PCI_MSIX_ENTRY_CTRL_MASKBIT 0x00000001 +#define PCI_MSIX_ENTRY_CTRL_MASKBIT 0x00000001/* Mask Bit */ +#define PCI_MSIX_ENTRY_CTRL_ST_LOWER 0x00ff0000/* ST Lower */ +#define PCI_MSIX_ENTRY_CTRL_ST_UPPER 0xff000000/* ST Upper */ /* CompactPCI Hotswap Register */
@@ -657,6 +659,7 @@#define PCI_EXP_DEVCAP2_ATOMIC_COMP64 0x00000100/* 64b AtomicOp completion */ #define PCI_EXP_DEVCAP2_ATOMIC_COMP128 0x00000200/* 128b AtomicOp completion */ #define PCI_EXP_DEVCAP2_LTR 0x00000800/* Latency tolerance reporting */ +#define PCI_EXP_DEVCAP2_TPH_COMP_MASK 0x00003000/* TPH completer support */ #define PCI_EXP_DEVCAP2_OBFF_MASK 0x000c0000/* OBFF support mechanism */ #define PCI_EXP_DEVCAP2_OBFF_MSG 0x00040000/* New message signaling */ #define PCI_EXP_DEVCAP2_OBFF_WAKE 0x00080000/* Re-use WAKE# for OBFF */
@@ -1020,15 +1023,34 @@#define PCI_DPA_CAP_SUBSTATE_MASK 0x1F/* # substates - 1 */ #define PCI_DPA_BASE_SIZEOF 16/* size with 0 substates */ +/* TPH Completer Support */ +#define PCI_EXP_DEVCAP2_TPH_COMP_NONE 0x0/* None */ +#define PCI_EXP_DEVCAP2_TPH_COMP_TPH_ONLY 0x1/* TPH only */ +#define PCI_EXP_DEVCAP2_TPH_COMP_TPH_AND_EXT 0x3/* TPH and Extended TPH */ +/* TPH Requester */ #define PCI_TPH_CAP 4/* capability register */ -#define PCI_TPH_CAP_LOC_MASK 0x600/* location mask */ -#define PCI_TPH_LOC_NONE 0x000/* no location */ -#define PCI_TPH_LOC_CAP 0x200/* in capability */ -#define PCI_TPH_LOC_MSIX 0x400/* in MSI-X */ -#define PCI_TPH_CAP_ST_MASK 0x07FF0000/* ST table mask */ -#define PCI_TPH_CAP_ST_SHIFT 16/* ST table shift */ -#define PCI_TPH_BASE_SIZEOF 0xc/* size with no ST table */ +#define PCI_TPH_CAP_NO_ST 0x00000001/* No ST Mode Supported */ +#define PCI_TPH_CAP_INT_VEC 0x00000002/* Interrupt Vector Mode Supported */ +#define PCI_TPH_CAP_DEV_SPEC 0x00000004/* Device Specific Mode Supported */ +#define PCI_TPH_CAP_EXT_TPH 0x00000100/* Ext TPH Requester Supported */ +#define PCI_TPH_CAP_LOC_MASK 0x00000600/* ST Table Location */ +#define PCI_TPH_LOC_NONE 0x00000000/* Not present */ +#define PCI_TPH_LOC_CAP 0x00000200/* In capability */ +#define PCI_TPH_LOC_MSIX 0x00000400/* In MSI-X */ +#define PCI_TPH_CAP_ST_MASK 0x07FF0000/* ST Table Size */ +#define PCI_TPH_CAP_ST_SHIFT 16/* ST Table Size shift */ +#define PCI_TPH_BASE_SIZEOF 0xc/* Size with no ST table */ + +#define PCI_TPH_CTRL 8/* control register */ +#define PCI_TPH_CTRL_MODE_SEL_MASK 0x00000007/* ST Mode Select */ +#define PCI_TPH_NO_ST_MODE 0x0/* No ST Mode */ +#define PCI_TPH_INT_VEC_MODE 0x1/* Interrupt Vector Mode */ +#define PCI_TPH_DEV_SPEC_MODE 0x2/* Device Specific Mode */ +#define PCI_TPH_CTRL_REQ_EN_MASK 0x00000300/* TPH Requester Enable */ +#define PCI_TPH_REQ_DISABLE 0x0/* No TPH requests allowed */ +#define PCI_TPH_REQ_TPH_ONLY 0x1/* TPH only requests allowed */ +#define PCI_TPH_REQ_EXT_TPH 0x3/* Extended TPH requests allowed */ /* Downstream Port Containment */ #define PCI_EXP_DPC_CAP 0x04/* DPC Capability */
Signature · 1 line
2.45.1
Re: [PATCH V4 02/12] PCI: Add TPH related register definition
Quoted 8 lines · Wei Huang
Linux has some basic, but incomplete, definition for the TPH Requester capability registers. Also the definitions of TPH Requester control register and TPH Completer capability, as well as the ST fields of MSI-X entry, are missing. Add all required definitions to support TPH without changing the existing Linux UAPI.
/* TPH Requester */
#definePCI_TPH_CAP4 /* capability register */
include/uapi/linux/pci_regs.h line 1035
Quoted 10 lines
include/uapi/linux/pci_regs.h +3
-7-#define PCI_TPH_CAP_LOC_MASK 0x600/* location mask */ -#define PCI_TPH_LOC_NONE 0x000/* no location */ -#define PCI_TPH_LOC_CAP 0x200/* in capability */ -#define PCI_TPH_LOC_MSIX 0x400/* in MSI-X */ -#define PCI_TPH_CAP_ST_MASK 0x07FF0000/* ST table mask */ -#define PCI_TPH_CAP_ST_SHIFT 16/* ST table shift */ -#define PCI_TPH_BASE_SIZEOF 0xc/* size with no ST table */ +#define PCI_TPH_CAP_NO_ST 0x00000001/* No ST Mode Supported */ +#define PCI_TPH_CAP_INT_VEC 0x00000002/* Interrupt Vector Mode Supported */ +#define PCI_TPH_CAP_DEV_SPEC 0x00000004/* Device Specific Mode Supported */
I think these modes should all include "ST" to clearly delineate Steering Tags from the Processing Hints. E.g.,
PCI_TPH_CAP_ST_NO_ST or maybe PCI_TPH_CAP_ST_NONE
PCI_TPH_CAP_ST_INT_VEC
PCI_TPH_CAP_ST_DEV_SPEC
include/uapi/linux/pci_regs.h line 1040
Quoted 5 lines
include/uapi/linux/pci_regs.h +5
-0+#define PCI_TPH_CAP_EXT_TPH 0x00000100/* Ext TPH Requester Supported */ +#define PCI_TPH_CAP_LOC_MASK 0x00000600/* ST Table Location */ +#define PCI_TPH_LOC_NONE 0x00000000/* Not present */ +#define PCI_TPH_LOC_CAP 0x00000200/* In capability */ +#define PCI_TPH_LOC_MSIX 0x00000400/* In MSI-X */
These are existing symbols just being tidied, so can't really add "ST" here unless we just add aliases. Since they're just used internally, not by drivers, I think they're fine as-is.
include/uapi/linux/pci_regs.h line 1049
Quoted 9 lines
include/uapi/linux/pci_regs.h +9
-0+#define PCI_TPH_CAP_ST_MASK 0x07FF0000/* ST Table Size */ +#define PCI_TPH_CAP_ST_SHIFT 16/* ST Table Size shift */ +#define PCI_TPH_BASE_SIZEOF 0xc/* Size with no ST table */ + +#define PCI_TPH_CTRL 8/* control register */ +#define PCI_TPH_CTRL_MODE_SEL_MASK 0x00000007/* ST Mode Select */ +#define PCI_TPH_NO_ST_MODE 0x0/* No ST Mode */ +#define PCI_TPH_INT_VEC_MODE 0x1/* Interrupt Vector Mode */ +#define PCI_TPH_DEV_SPEC_MODE 0x2/* Device Specific Mode */
These are also internal, but they're new and I think they should also include "ST" to match the CAP #defines.
Even better, maybe we only add these and use them for both CAP and CTRL since they're defined with identical values.
Re: [PATCH V4 02/12] PCI: Add TPH related register definition
Quoted 11 lines · Bjorn Helgaas
include/uapi/linux/pci_regs.h line 1035
Quoted 6 lines
include/uapi/linux/pci_regs.h +3
-3-#define PCI_TPH_CAP_ST_MASK 0x07FF0000/* ST table mask */ -#define PCI_TPH_CAP_ST_SHIFT 16/* ST table shift */ -#define PCI_TPH_BASE_SIZEOF 0xc/* size with no ST table */ +#define PCI_TPH_CAP_NO_ST 0x00000001/* No ST Mode Supported */ +#define PCI_TPH_CAP_INT_VEC 0x00000002/* Interrupt Vector Mode Supported */ +#define PCI_TPH_CAP_DEV_SPEC 0x00000004/* Device Specific Mode Supported */ I think these modes should all include "ST" to clearly delineate Steering Tags from the Processing Hints. E.g.,
PCI_TPH_CAP_ST_NO_STor maybePCI_TPH_CAP_ST_NONE
Can I keep "NO_ST" instead of switching over to "ST_NONE"? First, it matches with PCIe spec. Secondly, IMO "ST_NONE" implies no ST support at all.
Quoted 2 lines
PCI_TPH_CAP_ST_INT_VEC
PCI_TPH_CAP_ST_DEV_SPEC
Will change
Quoted 11 lines
include/uapi/linux/pci_regs.h line 1040
Quoted 6 lines
include/uapi/linux/pci_regs.h +5
-0+#define PCI_TPH_CAP_EXT_TPH 0x00000100/* Ext TPH Requester Supported */ +#define PCI_TPH_CAP_LOC_MASK 0x00000600/* ST Table Location */ +#define PCI_TPH_LOC_NONE 0x00000000/* Not present */ +#define PCI_TPH_LOC_CAP 0x00000200/* In capability */ +#define PCI_TPH_LOC_MSIX 0x00000400/* In MSI-X */ These are existing symbols just being tidied, so can't really add "ST" here unless we just add aliases. Since they're just used internally, not by drivers, I think they're fine as-is.
Yes. In V1 review, Alex Williamson and Jonathan Cameron asked not to change these definitions as they might be used by existing software.
Quoted 13 lines
include/uapi/linux/pci_regs.h line 1049
Quoted 9 lines
include/uapi/linux/pci_regs.h +9
-0+#define PCI_TPH_CAP_ST_MASK 0x07FF0000/* ST Table Size */ +#define PCI_TPH_CAP_ST_SHIFT 16/* ST Table Size shift */ +#define PCI_TPH_BASE_SIZEOF 0xc/* Size with no ST table */ + +#define PCI_TPH_CTRL 8/* control register */ +#define PCI_TPH_CTRL_MODE_SEL_MASK 0x00000007/* ST Mode Select */ +#define PCI_TPH_NO_ST_MODE 0x0/* No ST Mode */ +#define PCI_TPH_INT_VEC_MODE 0x1/* Interrupt Vector Mode */ +#define PCI_TPH_DEV_SPEC_MODE 0x2/* Device Specific Mode */ These are also internal, but they're new and I think they should also include "ST" to match the CAP #defines.
Quoted 2 lines
Even better, maybe we only add these and use them for both CAP and CTRL since they're defined with identical values.
Can you elaborate here? In CTRL register, "ST Mode Select" is defined as a 2-bit field. The possible values are 0, 1, 2. But in CAP register, the modes are individual bit masked. So I cannot use CTRL definitions in CAP register directly unless I do shifting.
Re: [PATCH V4 02/12] PCI: Add TPH related register definition
Quoted 11 lines · Wei Huang
Quoted 10 lines · Bjorn Helgaas
include/uapi/linux/pci_regs.h line 1035
Quoted 6 lines
include/uapi/linux/pci_regs.h +3
-3-#define PCI_TPH_CAP_ST_MASK 0x07FF0000/* ST table mask */ -#define PCI_TPH_CAP_ST_SHIFT 16/* ST table shift */ -#define PCI_TPH_BASE_SIZEOF 0xc/* size with no ST table */ +#define PCI_TPH_CAP_NO_ST 0x00000001/* No ST Mode Supported */ +#define PCI_TPH_CAP_INT_VEC 0x00000002/* Interrupt Vector Mode Supported */ +#define PCI_TPH_CAP_DEV_SPEC 0x00000004/* Device Specific Mode Supported */ I think these modes should all include "ST" to clearly delineate Steering Tags from the Processing Hints. E.g.,
Quoted 5 lines
Quoted 1 line
PCI_TPH_CAP_ST_NO_STor maybePCI_TPH_CAP_ST_NONECan I keep "
NO_ST" instead of switching over to "ST_NONE"? First, it matches with PCIe spec. Secondly, IMO "ST_NONE" implies no ST support at all.
Sure. Does PCI_TPH_CAP_ST_NO_ST work for you? That follows the same PCI_TPH_CAP_ST_* pattern as below.
Quoted 18 lines
Quoted 2 lines
PCI_TPH_CAP_ST_INT_VEC
PCI_TPH_CAP_ST_DEV_SPECWill change
Quoted 13 lines
include/uapi/linux/pci_regs.h line 1049
Quoted 9 lines
include/uapi/linux/pci_regs.h +9
-0+#define PCI_TPH_CAP_ST_MASK 0x07FF0000/* ST Table Size */ +#define PCI_TPH_CAP_ST_SHIFT 16/* ST Table Size shift */ +#define PCI_TPH_BASE_SIZEOF 0xc/* Size with no ST table */ + +#define PCI_TPH_CTRL 8/* control register */ +#define PCI_TPH_CTRL_MODE_SEL_MASK 0x00000007/* ST Mode Select */ +#define PCI_TPH_NO_ST_MODE 0x0/* No ST Mode */ +#define PCI_TPH_INT_VEC_MODE 0x1/* Interrupt Vector Mode */ +#define PCI_TPH_DEV_SPEC_MODE 0x2/* Device Specific Mode */ These are also internal, but they're new and I think they should also include "ST" to match the CAP #defines.
Quoted 7 lines
Quoted 2 lines
Even better, maybe we only add these and use them for both CAP and CTRL since they're defined with identical values.
Can you elaborate here? In CTRL register, "ST Mode Select" is defined as a 2-bit field. The possible values are 0, 1, 2. But in CAP register, the modes are individual bit masked. So I cannot use CTRL definitions in CAP register directly unless I do shifting.
Oops, sorry, I thought they were the same values, but they're not, so ignore this comment.
Re: [PATCH V4 02/12] PCI: Add TPH related register definition
Quoted 5 lines · Bjorn Helgaas
Quoted 4 lines · Wei Huang
Quoted 3 lines · Bjorn Helgaas
I think these modes should all include "ST" to clearly delineate Steering Tags from the Processing Hints. E.g.,
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
PCI_TPH_CAP_ST_NO_STor maybePCI_TPH_CAP_ST_NONECan I keep "
NO_ST" instead of switching over to "ST_NONE"? First, it matches with PCIe spec. Secondly, IMO "ST_NONE" implies no ST support at all.Sure. Does
PCI_TPH_CAP_ST_NO_STwork for you? That follows the same PCI_TPH_CAP_ST_* pattern as below.
So I tweaked a bit in V5 to make them look cleaner: instead of ST_NO_ST, V5 has ST_NS. Similar pattern applies to other modes:
PCI_TPH_CAP_NO_ST => PCI_TPH_CAP_ST_NSPCI_TPH_CAP_INT_VEC => PCI_TPH_CAP_ST_IVPCI_TPH_CAP_DEV_SPEC => PCI_TPH_CAP_ST_DS
Ctrl register has similar changes.
PATCH v4 3/12 PCI/TPH: Add pcie_tph_modes() to query TPH modes
In reply to Wei HuangAdd pcie_tph_modes() to allow drivers to query the TPH modes supported by an endpoint device, as reported in the TPH Requester Capability register. The modes are reported as a bitmask and current supported modes include:
- PCI_TPH_CAP_NO_ST: NO ST Mode Supported
- PCI_TPH_CAP_INT_VEC: Interrupt Vector Mode Supported
- PCI_TPH_CAP_DEV_SPEC: Device Specific Mode Supported
--- drivers/pci/pcie/tph.c | 33 +++++++++++++++++++++++++++++++++ include/linux/pci-tph.h | 18 ++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 include/linux/pci-tph.h
drivers/pci/pcie/tph.c +33 -0
@@ -6,9 +6,42 @@* Eric Van Tassell <[email protected]> * Wei Huang <[email protected]> */ +#include <linux/pci.h> +#include <linux/pci-tph.h> #include "../pci.h" +static u8 get_st_modes (struct pci_dev *pdev) +{ +u32 reg; + +pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CAP , ®); + reg &=PCI_TPH_CAP_NO_ST |PCI_TPH_CAP_INT_VEC |PCI_TPH_CAP_DEV_SPEC ; + +return reg; +} + +/** +* pcie_tph_modes - Get the ST modes supported by device +* @pdev: PCI device +* +* Returns a bitmask with all TPH modes supported by a device as shown in the +* TPH capability register. Current supported modes include: +* PCI_TPH_CAP_NO_ST - NO ST Mode Supported +* PCI_TPH_CAP_INT_VEC - Interrupt Vector Mode Supported +* PCI_TPH_CAP_DEV_SPEC - Device Specific Mode Supported +* +* Return: 0 when TPH is not supported, otherwise bitmask of supported modes +*/ +int pcie_tph_modes (struct pci_dev *pdev) +{ +if (!pdev->tph_cap) +return 0 ; + +return get_st_modes (pdev); +} +EXPORT_SYMBOL (pcie_tph_modes); +void pci_tph_init (struct pci_dev *pdev) { pdev->tph_cap =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_TPH );
include/linux/pci-tph.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* TPH (TLP Processing Hints) +* +* Copyright (C) 2024 Advanced Micro Devices, Inc. +* Eric Van Tassell <[email protected]> +* Wei Huang <[email protected]> +*/ +#ifndef LINUX_PCI_TPH_H +#define LINUX_PCI_TPH_H + +#ifdef CONFIG_PCIE_TPH +int pcie_tph_modes (struct pci_dev *pdev); +#else +static inline int pcie_tph_modes (struct pci_dev *pdev) {return 0 ; } +#endif + +#endif /* LINUX_PCI_TPH_H */
Signature · 1 line
2.45.1
Re: [PATCH V4 03/12] PCI/TPH: Add pcie_tph_modes() to query TPH modes
Quoted 20 lines · Wei Huang
Add
pcie_tph_modes()to allow drivers to query the TPH modes supported by an endpoint device, as reported in the TPH Requester Capability register. The modes are reported as a bitmask and current supported modes include:-
PCI_TPH_CAP_NO_ST: NO ST Mode Supported
-PCI_TPH_CAP_INT_VEC: Interrupt Vector Mode Supported
-PCI_TPH_CAP_DEV_SPEC: Device Specific Mode Supported+ *
pcie_tph_modes- Get the ST modes supported by device
+ * @pdev: PCI device
+ *
+ * Returns a bitmask with all TPH modes supported by a device as shown in the
+ * TPH capability register. Current supported modes include:+ * PCI_TPH_CAP_NO_ST - NO ST Mode Supported + * PCI_TPH_CAP_INT_VEC - Interrupt Vector Mode Supported + * PCI_TPH_CAP_DEV_SPEC - Device Specific Mode Supported+ *
+ * Return: 0 when TPH is not supported, otherwise bitmask of supported modes
+ */
drivers/pci/pcie/tph.c line 43
Quoted 8 lines
drivers/pci/pcie/tph.c +8
-0+int pcie_tph_modes (struct pci_dev *pdev) +{ +if (!pdev->tph_cap) +return 0 ; + +return get_st_modes (pdev); +} +EXPORT_SYMBOL (pcie_tph_modes);
I'm not sure I see the need for pcie_tph_modes(). The new bnxt code looks like this:
bnxt_request_irq
if (pcie_tph_modes(bp->pdev) & PCI_TPH_CAP_INT_VEC)
rc = pcie_enable_tph(bp->pdev, PCI_TPH_CAP_INT_VEC);What is the advantage of this over just this?
bnxt_request_irq
rc = pcie_enable_tph(bp->pdev, PCI_TPH_CAP_INT_VEC);It seems like drivers could just ask for what they want since pcie_enable_tph() has to verify support for it anyway. If that fails, the driver can fall back to another mode.
Returning a bitmask of supported modes might be useful if the driver could combine them, but IIUC the modes are all mutually exclusive, so the driver can't request a combination of them.
Bjorn
Re: [PATCH V4 03/12] PCI/TPH: Add pcie_tph_modes() to query TPH modes
Quoted 37 lines · Bjorn Helgaas
Quoted 20 lines · Wei Huang
Add
pcie_tph_modes()to allow drivers to query the TPH modes supported by an endpoint device, as reported in the TPH Requester Capability register. The modes are reported as a bitmask and current supported modes include:-
PCI_TPH_CAP_NO_ST: NO ST Mode Supported
-PCI_TPH_CAP_INT_VEC: Interrupt Vector Mode Supported
-PCI_TPH_CAP_DEV_SPEC: Device Specific Mode Supported+ *
pcie_tph_modes- Get the ST modes supported by device
+ * @pdev: PCI device
+ *
+ * Returns a bitmask with all TPH modes supported by a device as shown in the
+ * TPH capability register. Current supported modes include:+ * PCI_TPH_CAP_NO_ST - NO ST Mode Supported + * PCI_TPH_CAP_INT_VEC - Interrupt Vector Mode Supported + * PCI_TPH_CAP_DEV_SPEC - Device Specific Mode Supported+ *
+ * Return: 0 when TPH is not supported, otherwise bitmask of supported modes
+ */drivers/pci/pcie/tph.c line 43
Quoted 8 lines
drivers/pci/pcie/tph.c +8
-0+int pcie_tph_modes (struct pci_dev *pdev) +{ +if (!pdev->tph_cap) +return 0 ; + +return get_st_modes (pdev); +} +EXPORT_SYMBOL (pcie_tph_modes);I'm not sure I see the need for
pcie_tph_modes(). The new bnxt code looks like this:bnxt_request_irq if (pcie_tph_modes(bp->pdev) & PCI_TPH_CAP_INT_VEC) rc = pcie_enable_tph(bp->pdev, PCI_TPH_CAP_INT_VEC);
Quoted 8 lines
What is the advantage of this over just this?
bnxt_request_irq rc = pcie_enable_tph(bp->pdev, PCI_TPH_CAP_INT_VEC);It seems like drivers could just ask for what they want since
pcie_enable_tph()has to verify support for it anyway. If that fails, the driver can fall back to another mode.
I can get rid of pcie_tph_modes() if unnecessary.
The design logic was that a driver can be used on various devices from the same company. Some of these devices might not be TPH capable. So instead of using trial-and-error (i.e. try INT_VEC ==> DEV_SPEC ==> give up), we provide a way for the driver to query the device TPH capabilities and pick a mode explicitly. IMO the code will be a bit cleaner.
Quoted 4 lines
Returning a bitmask of supported modes might be useful if the driver could combine them, but IIUC the modes are all mutually exclusive, so the driver can't request a combination of them.
In the real world cases I saw, this is true. In the spec I didn't find that these bits are mutually exclusive though.
Quoted 2 lines
Bjorn
Re: [PATCH V4 03/12] PCI/TPH: Add pcie_tph_modes() to query TPH modes
Quoted 55 lines · Wei Huang
Quoted 37 lines · Bjorn Helgaas
Quoted 20 lines · Wei Huang
Add
pcie_tph_modes()to allow drivers to query the TPH modes supported by an endpoint device, as reported in the TPH Requester Capability register. The modes are reported as a bitmask and current supported modes include:-
PCI_TPH_CAP_NO_ST: NO ST Mode Supported
-PCI_TPH_CAP_INT_VEC: Interrupt Vector Mode Supported
-PCI_TPH_CAP_DEV_SPEC: Device Specific Mode Supported+ *
pcie_tph_modes- Get the ST modes supported by device
+ * @pdev: PCI device
+ *
+ * Returns a bitmask with all TPH modes supported by a device as shown in the
+ * TPH capability register. Current supported modes include:+ * PCI_TPH_CAP_NO_ST - NO ST Mode Supported + * PCI_TPH_CAP_INT_VEC - Interrupt Vector Mode Supported + * PCI_TPH_CAP_DEV_SPEC - Device Specific Mode Supported+ *
+ * Return: 0 when TPH is not supported, otherwise bitmask of supported modes
+ */drivers/pci/pcie/tph.c line 43
Quoted 8 lines
drivers/pci/pcie/tph.c +8
-0+int pcie_tph_modes (struct pci_dev *pdev) +{ +if (!pdev->tph_cap) +return 0 ; + +return get_st_modes (pdev); +} +EXPORT_SYMBOL (pcie_tph_modes);I'm not sure I see the need for
pcie_tph_modes(). The new bnxt code looks like this:bnxt_request_irq if (pcie_tph_modes(bp->pdev) & PCI_TPH_CAP_INT_VEC) rc = pcie_enable_tph(bp->pdev, PCI_TPH_CAP_INT_VEC);Quoted 8 lines
What is the advantage of this over just this?
bnxt_request_irq rc = pcie_enable_tph(bp->pdev, PCI_TPH_CAP_INT_VEC);It seems like drivers could just ask for what they want since
pcie_enable_tph()has to verify support for it anyway. If that fails, the driver can fall back to another mode.I can get rid of
pcie_tph_modes()if unnecessary.The design logic was that a driver can be used on various devices from the same company. Some of these devices might not be TPH capable. So instead of using trial-and-error (i.e. try
INT_VEC==>DEV_SPEC==> give up), we provide a way for the driver to query the device TPH capabilities and pick a mode explicitly. IMO the code will be a bit cleaner.
Quoted 6 lines
Quoted 3 lines
Returning a bitmask of supported modes might be useful if the driver could combine them, but IIUC the modes are all mutually exclusive, so the driver can't request a combination of them.
In the real world cases I saw, this is true. In the spec I didn't find that these bits are mutually exclusive though.
A device may advertise *support* for multiple modes in TPH Requester Capability, of course.
What I meant by "driver can't request a combination" is that we can only *select* one of them via the ST Mode select in TPH Requester Control.
PATCH v4 4/12 PCI/TPH: Add pcie_enable_tph() to enable TPH
In reply to Wei HuangAllow drivers to enable TPH support using a specific ST mode. It checks whether the mode is actually supported by the device before enabling. Additionally determines what types of requests, TPH (8-bit) or Extended TPH (16-bit), can be issued by the device based on the device's TPH Requester capability and its Root Port's Completer capability.
--- drivers/pci/pcie/tph.c | 92 +++++++++++++++++++++++++++++++++++++++++ include/linux/pci-tph.h | 3 ++ include/linux/pci.h | 3 ++ 3 files changed, 98 insertions(+)
drivers/pci/pcie/tph.c +92 -0
@@ -7,6 +7,7 @@* Wei Huang <[email protected]> */ #include <linux/pci.h> +#include <linux/bitfield.h> #include <linux/pci-tph.h> #include "../pci.h"
@@ -21,6 +22,97 @@ static u8 get_st_modes(struct pci_dev *pdev)return reg; } +/* Return device's Root Port completer capability */ +static u8 get_rp_completer_type (struct pci_dev *pdev) +{ +struct pci_dev *rp; +u32 reg; +int ret; + + rp =pcie_find_root_port (pdev); +if (!rp) +return 0 ; + + ret =pcie_capability_read_dword (rp,PCI_EXP_DEVCAP2 , ®); +if (ret) +return 0 ; + +return FIELD_GET (PCI_EXP_DEVCAP2_TPH_COMP_MASK , reg); +} + +/** +* pcie_enable_tph - Enable TPH support for device using a specific ST mode +* @pdev: PCI device +* @mode: ST mode to enable, as returned by pcie_tph_modes() +* +* Checks whether the mode is actually supported by the device before enabling +* and returns an error if not. Additionally determines what types of requests, +* TPH or extended TPH, can be issued by the device based on its TPH requester +* capability and the Root Port's completer capability. +* +* Return: 0 on success, otherwise negative value (-errno) +*/ +int pcie_enable_tph (struct pci_dev *pdev,int mode) +{ +u32 reg; +u8 dev_modes; +u8 rp_req_type; + +if (!pdev->tph_cap) +return -EINVAL ; + +if (pdev->tph_enabled) +return -EBUSY ; + +/* Check ST mode comptability */ + dev_modes =get_st_modes (pdev); +if (!(mode & dev_modes)) +return -EINVAL ; + +/* Select a supported mode */ +switch (mode) { +case PCI_TPH_CAP_INT_VEC : + pdev->tph_mode =PCI_TPH_INT_VEC_MODE ; +break ; +case PCI_TPH_CAP_DEV_SPEC : + pdev->tph_mode =PCI_TPH_DEV_SPEC_MODE ; +break ; +case PCI_TPH_CAP_NO_ST : + pdev->tph_mode =PCI_TPH_NO_ST_MODE ; +break ; +default : +return -EINVAL ; + } + +/* Get req_type supported by device and its Root Port */ + reg =pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CAP , ®); +if (FIELD_GET (PCI_TPH_CAP_EXT_TPH , reg)) + pdev->tph_req_type =PCI_TPH_REQ_EXT_TPH ; +else + pdev->tph_req_type =PCI_TPH_REQ_TPH_ONLY ; + + rp_req_type =get_rp_completer_type (pdev); + +/* Final req_type is the smallest value of two */ + pdev->tph_req_type =min (pdev->tph_req_type, rp_req_type); + +/* Write them into TPH control register */ +pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL , ®); + + reg &= ~PCI_TPH_CTRL_MODE_SEL_MASK ; + reg |=FIELD_PREP (PCI_TPH_CTRL_MODE_SEL_MASK , pdev->tph_mode); + + reg &= ~PCI_TPH_CTRL_REQ_EN_MASK ; + reg |=FIELD_PREP (PCI_TPH_CTRL_REQ_EN_MASK , pdev->tph_req_type); + +pci_write_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL , reg); + + pdev->tph_enabled =1 ; + +return 0 ; +} +EXPORT_SYMBOL (pcie_enable_tph); +/** * pcie_tph_modes - Get the ST modes supported by device * @pdev: PCI device
include/linux/pci-tph.h +3 -0
@@ -10,8 +10,11 @@#define LINUX_PCI_TPH_H #ifdef CONFIG_PCIE_TPH +int pcie_enable_tph (struct pci_dev *pdev,int mode);int pcie_tph_modes (struct pci_dev *pdev);#else +static inline int pcie_enable_tph (struct pci_dev *pdev,int mode) +{return -EINVAL ; }static inline int pcie_tph_modes (struct pci_dev *pdev) {return 0 ; }#endif
include/linux/pci.h +3 -0
@@ -433,6 +433,7 @@ struct pci_dev { unsigned int ats_enabled:1; /* Address Translation Svc */ unsigned int pasid_enabled:1; /* Process Address Space ID */ unsigned int pri_enabled:1; /* Page Request Interface */ + unsigned int tph_enabled:1; /* TLP Processing Hints */ unsigned int is_managed:1; /* Managed via devres */ unsigned int is_msi_managed:1; /* MSI release via devres installed */ unsigned int needs_freset:1; /* Requires fundamental reset */
@@ -533,6 +534,8 @@ struct pci_dev {#ifdef CONFIG_PCIE_TPH u16 tph_cap;/* TPH capability offset */ +u8 tph_mode;/* TPH mode */ +u8 tph_req_type;/* TPH requester type */ #endif };
Signature · 1 line
2.45.1
Re: [PATCH V4 04/12] PCI/TPH: Add pcie_enable_tph() to enable TPH
Quoted 100 lines · Wei Huang
Allow drivers to enable TPH support using a specific ST mode. It checks whether the mode is actually supported by the device before enabling. Additionally determines what types of requests, TPH (8-bit) or Extended TPH (16-bit), can be issued by the device based on the device's TPH Requester capability and its Root Port's Completer capability.
Co-developed-by Eric Van Tassell <[email protected]>Signed-off-by Eric Van Tassell <[email protected]>Signed-off-by Wei Huang <[email protected]>Reviewed-by Ajit Khaparde <[email protected]>Reviewed-by Somnath Kotur <[email protected]>Reviewed-by Andy Gospodarek <[email protected]>--- drivers/pci/pcie/tph.c | 92 +++++++++++++++++++++++++++++++++++++++++ include/linux/pci-tph.h | 3 ++ include/linux/pci.h | 3 ++ 3 files changed, 98 insertions(+)drivers/pci/pcie/tph.c +67
-0@@ -7,6 +7,7 @@* Wei Huang <[email protected]> */ #include <linux/pci.h> +#include <linux/bitfield.h> #include <linux/pci-tph.h> #include "../pci.h" @@ -21,6 +22,97 @@ static u8 get_st_modes(struct pci_dev *pdev)return reg; } +/* Return device's Root Port completer capability */ +static u8 get_rp_completer_type (struct pci_dev *pdev) +{ +struct pci_dev *rp; +u32 reg; +int ret; + + rp =pcie_find_root_port (pdev); +if (!rp) +return 0 ; + + ret =pcie_capability_read_dword (rp,PCI_EXP_DEVCAP2 , ®); +if (ret) +return 0 ; + +return FIELD_GET (PCI_EXP_DEVCAP2_TPH_COMP_MASK , reg); +} + +/** +* pcie_enable_tph - Enable TPH support for device using a specific ST mode +* @pdev: PCI device +* @mode: ST mode to enable, as returned by pcie_tph_modes() +* +* Checks whether the mode is actually supported by the device before enabling +* and returns an error if not. Additionally determines what types of requests, +* TPH or extended TPH, can be issued by the device based on its TPH requester +* capability and the Root Port's completer capability. +* +* Return: 0 on success, otherwise negative value (-errno) +*/ +int pcie_enable_tph (struct pci_dev *pdev,int mode) +{ +u32 reg; +u8 dev_modes; +u8 rp_req_type; + +if (!pdev->tph_cap) +return -EINVAL ; + +if (pdev->tph_enabled) +return -EBUSY ; + +/* Check ST mode comptability */ + dev_modes =get_st_modes (pdev); +if (!(mode & dev_modes)) +return -EINVAL ; + +/* Select a supported mode */ +switch (mode) { +case PCI_TPH_CAP_INT_VEC : + pdev->tph_mode =PCI_TPH_INT_VEC_MODE ; +break ; +case PCI_TPH_CAP_DEV_SPEC : + pdev->tph_mode =PCI_TPH_DEV_SPEC_MODE ; +break ; +case PCI_TPH_CAP_NO_ST : + pdev->tph_mode =PCI_TPH_NO_ST_MODE ; +break ; +default : +return -EINVAL ; + } + +/* Get req_type supported by device and its Root Port */ + reg =pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CAP , ®); +if (FIELD_GET (PCI_TPH_CAP_EXT_TPH , reg)) + pdev->tph_req_type =PCI_TPH_REQ_EXT_TPH ;
drivers/pci/pcie/tph.c static u8 get_st_modes(struct pci_dev *pdev) · line 100
Quoted 10 lines
drivers/pci/pcie/tph.c +10
-0+else + pdev->tph_req_type =PCI_TPH_REQ_TPH_ONLY ; + + rp_req_type =get_rp_completer_type (pdev); + +/* Final req_type is the smallest value of two */ + pdev->tph_req_type =min (pdev->tph_req_type, rp_req_type); + +/* Write them into TPH control register */ +pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL , ®);
No error checked. Same with below pci_write_config_dword.
Quoted 55 lines
drivers/pci/pcie/tph.c +15
-0+ + reg &= ~PCI_TPH_CTRL_MODE_SEL_MASK ; + reg |=FIELD_PREP (PCI_TPH_CTRL_MODE_SEL_MASK , pdev->tph_mode); + + reg &= ~PCI_TPH_CTRL_REQ_EN_MASK ; + reg |=FIELD_PREP (PCI_TPH_CTRL_REQ_EN_MASK , pdev->tph_req_type); + +pci_write_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL , reg); + + pdev->tph_enabled =1 ; + +return 0 ; +} +EXPORT_SYMBOL (pcie_enable_tph); +/** * pcie_tph_modes - Get the ST modes supported by device * @pdev: PCI device include/linux/pci-tph.h +3
-0@@ -10,8 +10,11 @@#define LINUX_PCI_TPH_H #ifdef CONFIG_PCIE_TPH +int pcie_enable_tph (struct pci_dev *pdev,int mode);int pcie_tph_modes (struct pci_dev *pdev);#else +static inline int pcie_enable_tph (struct pci_dev *pdev,int mode) +{return -EINVAL ; }static inline int pcie_tph_modes (struct pci_dev *pdev) {return 0 ; }#endif include/linux/pci.h +3
-0@@ -433,6 +433,7 @@ struct pci_dev { unsigned int ats_enabled:1; /* Address Translation Svc */ unsigned int pasid_enabled:1; /* Process Address Space ID */ unsigned int pri_enabled:1; /* Page Request Interface */ + unsigned int tph_enabled:1; /* TLP Processing Hints */ unsigned int is_managed:1; /* Managed via devres */ unsigned int is_msi_managed:1; /* MSI release via devres installed */ unsigned int needs_freset:1; /* Requires fundamental reset */@@ -533,6 +534,8 @@ struct pci_dev {#ifdef CONFIG_PCIE_TPH u16 tph_cap;/* TPH capability offset */ +u8 tph_mode;/* TPH mode */ +u8 tph_req_type;/* TPH requester type */ #endif };
PATCH v4 5/12 PCI/TPH: Add pcie_disable_tph() to disable TPH
In reply to Wei HuangTurn off TPH support for a device and clean all related states.
--- drivers/pci/pcie/tph.c | 22 ++++++++++++++++++++++ include/linux/pci-tph.h | 2 ++ 2 files changed, 24 insertions(+)
drivers/pci/pcie/tph.c +22 -0
@@ -40,6 +40,28 @@ static u8 get_rp_completer_type(struct pci_dev *pdev)return FIELD_GET (PCI_EXP_DEVCAP2_TPH_COMP_MASK , reg); } +/** +* pcie_disable_tph - Turn off TPH support for device +* @pdev: PCI device +* +* Return: none +*/ +void pcie_disable_tph (struct pci_dev *pdev) +{ +if (!pdev->tph_cap) +return ; + +if (!pdev->tph_enabled) +return ; + +pci_write_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL ,0 ); + + pdev->tph_mode =0 ; + pdev->tph_req_type =0 ; + pdev->tph_enabled =0 ; +} +EXPORT_SYMBOL (pcie_disable_tph); +/** * pcie_enable_tph - Enable TPH support for device using a specific ST mode * @pdev: PCI device
include/linux/pci-tph.h +2 -0
@@ -10,9 +10,11 @@#define LINUX_PCI_TPH_H #ifdef CONFIG_PCIE_TPH +void pcie_disable_tph (struct pci_dev *pdev);int pcie_enable_tph (struct pci_dev *pdev,int mode);int pcie_tph_modes (struct pci_dev *pdev);#else +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_modes (struct pci_dev *pdev) {return 0 ; }
Signature · 1 line
2.45.1
PATCH v4 6/12 PCI/TPH: Add pcie_tph_enabled() to check TPH state
In reply to Wei HuangCheck if TPH has been enabled on a device.
--- drivers/pci/pcie/tph.c | 12 ++++++++++++ include/linux/pci-tph.h | 2 ++ 2 files changed, 14 insertions(+)
drivers/pci/pcie/tph.c +12 -0
@@ -40,6 +40,18 @@ static u8 get_rp_completer_type(struct pci_dev *pdev)return FIELD_GET (PCI_EXP_DEVCAP2_TPH_COMP_MASK , reg); } +/** +* pcie_tph_enabled - Check whether TPH is enabled in device +* @pdev: PCI device +* +* Return: true if TPH is enabled, otherwise false +*/ +bool pcie_tph_enabled (struct pci_dev *pdev) +{ +return pdev->tph_enabled; +} +EXPORT_SYMBOL (pcie_tph_enabled); +/** * pcie_disable_tph - Turn off TPH support for device * @pdev: PCI device
include/linux/pci-tph.h +2 -0
@@ -10,10 +10,12 @@#define LINUX_PCI_TPH_H #ifdef CONFIG_PCIE_TPH +bool pcie_tph_enabled (struct pci_dev *pdev);void pcie_disable_tph (struct pci_dev *pdev);int pcie_enable_tph (struct pci_dev *pdev,int mode);int pcie_tph_modes (struct pci_dev *pdev);#else +static inline bool pcie_tph_enabled (struct pci_dev *pdev) {return false; }static inline void pcie_disable_tph (struct pci_dev *pdev) { }static inline int pcie_enable_tph (struct pci_dev *pdev,int mode) {return -EINVAL ; }
Signature · 1 line
2.45.1
PATCH v4 7/12 PCI/TPH: Add pcie_tph_set_st_entry() to set ST tag
In reply to Wei HuangAdd a function to update the device's steering tags. Depending on the ST table location, the tags will be automatically written into the device's MSI-X table or into the ST table located in the TPH Extended Capability space.
--- drivers/pci/pcie/tph.c | 161 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-tph.h | 5 ++ 2 files changed, 166 insertions(+)
drivers/pci/pcie/tph.c +161 -0
@@ -8,10 +8,24 @@*/ #include <linux/pci.h> #include <linux/bitfield.h> +#include <linux/msi.h> #include <linux/pci-tph.h> #include "../pci.h" +/* Update the TPH Requester Enable field of TPH Control Register */ +static void set_ctrl_reg_req_en (struct pci_dev *pdev,u8 req_type) +{ +u32 reg; + +pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL , ®); + + reg &= ~PCI_TPH_CTRL_REQ_EN_MASK ; + reg |=FIELD_PREP (PCI_TPH_CTRL_REQ_EN_MASK , req_type); + +pci_write_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL , reg); +} +static u8 get_st_modes (struct pci_dev *pdev) {u32 reg;
@@ -22,6 +36,37 @@ static u8 get_st_modes(struct pci_dev *pdev)return reg; } +static u32 get_st_table_loc (struct pci_dev *pdev) +{ +u32 reg; + +pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CAP , ®); + +return FIELD_GET (PCI_TPH_CAP_LOC_MASK , reg); +} + +/* +* Return the size of ST table. If ST table is not in TPH Requester Extended +* Capability space, return 0. Otherwise return the ST Table Size + 1. +*/ +static u16 get_st_table_size (struct pci_dev *pdev) +{ +u32 reg; +u32 loc; + +/* Check ST table location first */ + loc =get_st_table_loc (pdev); + +/* Convert loc to match with PCI_TPH_LOC_* defined in pci_regs.h */ + loc =FIELD_PREP (PCI_TPH_CAP_LOC_MASK , loc); +if (loc !=PCI_TPH_LOC_CAP ) +return 0 ; + +pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CAP , ®); + +return FIELD_GET (PCI_TPH_CAP_ST_MASK , reg) +1 ; +} +/* Return device's Root Port completer capability */ static u8 get_rp_completer_type (struct pci_dev *pdev) {
@@ -40,6 +85,122 @@ static u8 get_rp_completer_type(struct pci_dev *pdev)return FIELD_GET (PCI_EXP_DEVCAP2_TPH_COMP_MASK , reg); } +/* Write ST to MSI-X vector control reg - Return 0 if OK, otherwise -errno */ +static int write_tag_to_msix (struct pci_dev *pdev,int msix_idx,u16 tag) +{ +struct msi_desc *msi_desc =NULL ; +void __iomem *vec_ctrl; +u32 val, mask; +int err =0 ; + +msi_lock_descs (&pdev->dev); + +/* Find the msi_desc entry with matching msix_idx */ +msi_for_each_desc (msi_desc, &pdev->dev,MSI_DESC_ASSOCIATED ) { +if (msi_desc->msi_index == msix_idx) +break ; + } + +if (!msi_desc) { + err = -ENXIO ; + goto err_out; + } + +/* Get the vector control register (offset 0xc) pointed by msix_idx */ + vec_ctrl = pdev->msix_base + msix_idx *PCI_MSIX_ENTRY_SIZE ; + vec_ctrl +=PCI_MSIX_ENTRY_VECTOR_CTRL ; + + val =readl (vec_ctrl); + mask =PCI_MSIX_ENTRY_CTRL_ST_LOWER |PCI_MSIX_ENTRY_CTRL_ST_UPPER ; + val &= ~mask; + val |=FIELD_PREP (mask, tag); +writel (val, vec_ctrl); + +/* Read back to flush the update */ + val =readl (vec_ctrl); + +err_out: +msi_unlock_descs (&pdev->dev); +return err; +} + +/* 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) +{ +int st_table_size; +int offset; + +/* Check if index is out of bound */ + st_table_size =get_st_table_size (pdev); +if (index >= st_table_size) +return -ENXIO ; + + offset = pdev->tph_cap +PCI_TPH_BASE_SIZEOF + index *sizeof (u16); + +return pci_write_config_word (pdev, offset, tag); +} + +/** +* pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry +* @pdev: PCI device +* @index: ST table entry index +* @tag: Steering Tag to be written +* +* This function will figure out the proper location of ST table, either in +* the MSI-X table or in the TPH Extended Capability space, and write the +* Steering Tag into the ST entry pointed by index. +* +* Returns: 0 if success, otherwise negative value (-errno) +*/ +int pcie_tph_set_st_entry (struct pci_dev *pdev,unsigned int index,u16 tag) +{ +u32 loc; +int err =0 ; + +if (!pdev->tph_cap) +return -EINVAL ; + +if (!pdev->tph_enabled) +return -EINVAL ; + +/* No need to write tag if device is in "No ST Mode" */ +if (pdev->tph_mode ==PCI_TPH_NO_ST_MODE ) +return 0 ; + +/* Disable TPH before updating ST to avoid potential instability as +* cautioned in PCIe r6.2, sec 6.17.3, "ST Modes of Operation" +*/ +set_ctrl_reg_req_en (pdev,PCI_TPH_REQ_DISABLE ); + + loc =get_st_table_loc (pdev); +/* Convert loc to match with PCI_TPH_LOC_* defined in pci_regs.h */ + loc =FIELD_PREP (PCI_TPH_CAP_LOC_MASK , loc); + +switch (loc) { +case PCI_TPH_LOC_MSIX : + err =write_tag_to_msix (pdev, index, tag); +break ; +case PCI_TPH_LOC_CAP : + err =write_tag_to_st_table (pdev, index, tag); +break ; +default : + err = -EINVAL ; + } + +if (err) { +pcie_disable_tph (pdev); +return err; + } + +set_ctrl_reg_req_en (pdev, pdev->tph_mode); + +pci_dbg (pdev,"set steering tag: %s table, index=%d, tag=%#04x\n" , + (loc ==PCI_TPH_LOC_MSIX ) ?"MSI-X" :"ST" , index, tag); + +return 0 ; +} +EXPORT_SYMBOL (pcie_tph_set_st_entry); +/** * pcie_tph_enabled - Check whether TPH is enabled in device * @pdev: PCI device
include/linux/pci-tph.h +5 -0
@@ -10,11 +10,16 @@#define LINUX_PCI_TPH_H #ifdef CONFIG_PCIE_TPH +int pcie_tph_set_st_entry (struct pci_dev *pdev, +unsigned int index,u16 tag);bool pcie_tph_enabled (struct pci_dev *pdev);void pcie_disable_tph (struct pci_dev *pdev);int pcie_enable_tph (struct pci_dev *pdev,int mode);int pcie_tph_modes (struct pci_dev *pdev);#else +static inline int pcie_tph_set_st_entry (struct pci_dev *pdev, +unsigned int index,u16 tag) +{return -EINVAL ; }static inline bool pcie_tph_enabled (struct pci_dev *pdev) {return false; }static inline void pcie_disable_tph (struct pci_dev *pdev) { }static inline int pcie_enable_tph (struct pci_dev *pdev,int mode)
Signature · 1 line
2.45.1
kernel test robot
build botRe: [PATCH V4 07/12] PCI/TPH: Add pcie_tph_set_st_entry() to set ST tag
kernel test robot noticed the following build warnings:
Hi Wei,
kernel test robot noticed the following build warnings:
[auto build test WARNING on pci/next]
[also build test WARNING on pci/for-linus linus/master v6.11-rc5 next-20240826] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Wei-Huang/PCI-Introduce-PCIe-TPH-support-framework/20240826-121149 base: https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next patch link: https://lore.kernel.org/r/20240822204120.3634-8-wei.huang2%40amd.com patch subject: [PATCH V4 07/12] PCI/TPH: Add pcie_tph_set_st_entry() to set ST tag config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20240826/[email protected]/config) compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240826/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/pci/pcie/tph.c:116:9: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (mask)))' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
116 | val |= FIELD_PREP(mask, tag);
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:115:3: note: expanded from macro 'FIELD_PREP'
115 | __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:53: note: expanded from macro '__BF_FIELD_CHECK'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
73 | __bf_cast_unsigned(_reg, ~0ull), \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 | _pfx "type of reg too small for mask"); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:58: note: expanded from macro 'BUILD_BUG_ON_MSG'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
include/linux/compiler_types.h:510:22: note: expanded from macro 'compiletime_assert'
510 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:498:23: note: expanded from macro '_compiletime_assert'
498 | __compiletime_assert(condition, msg, prefix, suffix)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:490:9: note: expanded from macro '__compiletime_assert'
490 | if (!(condition)) \
| ^~~~~~~~~1 warning generated.
vim +116 drivers/pci/pcie/tph.c
87
88 /* Write ST to MSI-X vector control reg - Return 0 if OK, otherwise -errno */
89 static int write_tag_to_msix(struct pci_dev *pdev, int msix_idx, u16 tag)
90 {
91 struct msi_desc *msi_desc = NULL;
92 void __iomem *vec_ctrl;
93 u32 val, mask;
94 int err = 0;
95
96 msi_lock_descs(&pdev->dev);
97
98 /* Find the msi_desc entry with matching msix_idx */
99 msi_for_each_desc(msi_desc, &pdev->dev, MSI_DESC_ASSOCIATED) {
100 if (msi_desc->msi_index == msix_idx)
101 break;
102 }
103
104 if (!msi_desc) {
105 err = -ENXIO;
106 goto err_out;
107 }
108
109 /* Get the vector control register (offset 0xc) pointed by msix_idx */
110 vec_ctrl = pdev->msix_base + msix_idx * PCI_MSIX_ENTRY_SIZE;
111 vec_ctrl += PCI_MSIX_ENTRY_VECTOR_CTRL;
112
113 val = readl(vec_ctrl);
114 mask = PCI_MSIX_ENTRY_CTRL_ST_LOWER | PCI_MSIX_ENTRY_CTRL_ST_UPPER;
115 val &= ~mask;
> 116 val |= FIELD_PREP(mask, tag); 117 writel(val, vec_ctrl);
118
119 /* Read back to flush the update */
120 val = readl(vec_ctrl);
121
122 err_out:
123 msi_unlock_descs(&pdev->dev);
124 return err;
125 }
126
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v4 8/12 PCI/TPH: Add pcie_tph_get_cpu_st() to get ST tag
In reply to Wei HuangAllow a caller to retrieve Steering Tags for a target memory that is associated with a specific CPU. The caller must provided two parameters, memory type and CPU UID, when calling this function. The tag is retrieved by invoking ACPI _DSM of the device's Root Port device.
--- drivers/pci/pcie/tph.c | 154 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-tph.h | 18 +++++ 2 files changed, 172 insertions(+)
drivers/pci/pcie/tph.c +154 -0
@@ -7,12 +7,125 @@* Wei Huang <[email protected]> */ #include <linux/pci.h> +#include <linux/pci-acpi.h> #include <linux/bitfield.h> #include <linux/msi.h> #include <linux/pci-tph.h> #include "../pci.h" +/* +* The st_info struct defines the Steering Tag (ST) info returned by the +* firmware _DSM method defined in the approved ECN for PCI Firmware Spec, +* available at https://members.pcisig.com/wg/PCI-SIG/document/15470. +* +* @vm_st_valid: 8-bit ST for volatile memory is valid +* @vm_xst_valid: 16-bit extended ST for volatile memory is valid +* @vm_ph_ignore: 1 => PH was and will be ignored, 0 => PH should be supplied +* @vm_st: 8-bit ST for volatile mem +* @vm_xst: 16-bit extended ST for volatile mem +* @pm_st_valid: 8-bit ST for persistent memory is valid +* @pm_xst_valid: 16-bit extended ST for persistent memory is valid +* @pm_ph_ignore: 1 => PH was and will be ignored, 0 => PH should be supplied +* @pm_st: 8-bit ST for persistent mem +* @pm_xst: 16-bit extended ST for persistent mem +*/ +union st_info { +struct { +u64 vm_st_valid :1 ; +u64 vm_xst_valid :1 ; +u64 vm_ph_ignore :1 ; +u64 rsvd1 :5 ; +u64 vm_st :8 ; +u64 vm_xst :16 ; +u64 pm_st_valid :1 ; +u64 pm_xst_valid :1 ; +u64 pm_ph_ignore :1 ; +u64 rsvd2 :5 ; +u64 pm_st :8 ; +u64 pm_xst :16 ; + }; +u64 value; +}; + +static u16 tph_extract_tag (enum tph_mem_type mem_type,u8 req_type, +union st_info *info) +{ +switch (req_type) { +case PCI_TPH_REQ_TPH_ONLY :/* 8-bit tag */ +switch (mem_type) { +case TPH_MEM_TYPE_VM : +if (info->vm_st_valid) +return info->vm_st; +break ; +case TPH_MEM_TYPE_PM : +if (info->pm_st_valid) +return info->pm_st; +break ; + } +break ; +case PCI_TPH_REQ_EXT_TPH :/* 16-bit tag */ +switch (mem_type) { +case TPH_MEM_TYPE_VM : +if (info->vm_xst_valid) +return info->vm_xst; +break ; +case TPH_MEM_TYPE_PM : +if (info->pm_xst_valid) +return info->pm_xst; +break ; + } +break ; +default : +return 0 ; + } + +return 0 ; +} + +#define TPH_ST_DSM_FUNC_INDEX 0xF +static acpi_status tph_invoke_dsm (acpi_handle handle,u32 cpu_uid, +union st_info *st_out) +{ +union acpi_object arg3[3 ], in_obj, *out_obj; + +if (!acpi_check_dsm (handle, &pci_acpi_dsm_guid,7 , +BIT (TPH_ST_DSM_FUNC_INDEX ))) +return AE_ERROR ; + +/* DWORD: feature ID (0 for processor cache ST query) */ + arg3[0 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[0 ].integer.value =0 ; + +/* DWORD: target UID */ + arg3[1 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[1 ].integer.value = cpu_uid; + +/* QWORD: properties, all 0's */ + arg3[2 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[2 ].integer.value =0 ; + + in_obj.type =ACPI_TYPE_PACKAGE ; + in_obj.package.count =ARRAY_SIZE (arg3); + in_obj.package.elements = arg3; + + out_obj =acpi_evaluate_dsm (handle, &pci_acpi_dsm_guid,7 , +TPH_ST_DSM_FUNC_INDEX , &in_obj); +if (!out_obj) +return AE_ERROR ; + +if (out_obj->type !=ACPI_TYPE_BUFFER ) { +ACPI_FREE (out_obj); +return AE_ERROR ; + } + + st_out->value = *((u64 *)(out_obj->buffer.pointer)); + +ACPI_FREE (out_obj); + +return AE_OK ; +} +/* Update the TPH Requester Enable field of TPH Control Register */ static void set_ctrl_reg_req_en (struct pci_dev *pdev,u8 req_type) {
@@ -140,6 +253,47 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)return pci_write_config_word (pdev, offset, tag); } +/** +* pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated +* with a specific CPU +* @pdev: PCI device +* @mem_type: target memory type (volatile or persistent RAM) +* @cpu_uid: associated CPU id +* @tag: Steering Tag to be returned +* +* This function returns the Steering Tag for a target memory that is +* associated with a specific CPU as indicated by cpu_uid. +* +* Returns 0 if success, otherwise negative value (-errno) +*/ +int pcie_tph_get_cpu_st (struct pci_dev *pdev,enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag) +{ +struct pci_dev *rp; +acpi_handle rp_acpi_handle; +union st_info info; + + rp =pcie_find_root_port (pdev); +if (!rp || !rp->bus || !rp->bus->bridge) +return -ENODEV ; + + rp_acpi_handle =ACPI_HANDLE (rp->bus->bridge); + +if (tph_invoke_dsm (rp_acpi_handle, cpu_uid, &info) !=AE_OK ) { + *tag =0 ; +return -EINVAL ; + } + + *tag =tph_extract_tag (mem_type, pdev->tph_req_type, &info); + +pci_dbg (pdev,"get steering tag: mem_type=%s, cpu_uid=%d, tag=%#04x\n" , + (mem_type ==TPH_MEM_TYPE_VM ) ?"volatile" :"persistent" , + cpu_uid, *tag); + +return 0 ; +} +EXPORT_SYMBOL (pcie_tph_get_cpu_st); +/** * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry * @pdev: PCI device
include/linux/pci-tph.h +18 -0
@@ -9,9 +9,23 @@#ifndef LINUX_PCI_TPH_H #define LINUX_PCI_TPH_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 +* caller query about a target's Steering Tag, it must provide the target's +* tph_mem_type. ECN link: https://members.pcisig.com/wg/PCI-SIG/document/15470. +*/ +enum tph_mem_type { +TPH_MEM_TYPE_VM ,/* volatile memory */ +TPH_MEM_TYPE_PM /* persistent memory */ +}; +#ifdef CONFIG_PCIE_TPH int pcie_tph_set_st_entry (struct pci_dev *pdev,unsigned int index,u16 tag); +int pcie_tph_get_cpu_st (struct pci_dev *dev, +enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag);bool pcie_tph_enabled (struct pci_dev *pdev);void pcie_disable_tph (struct pci_dev *pdev);int pcie_enable_tph (struct pci_dev *pdev,int mode);
@@ -20,6 +34,10 @@ int pcie_tph_modes(struct pci_dev *pdev);static inline int pcie_tph_set_st_entry (struct pci_dev *pdev,unsigned int index,u16 tag) {return -EINVAL ; } +static inline int pcie_tph_get_cpu_st (struct pci_dev *dev, +enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag) +{return -EINVAL ; }static inline bool pcie_tph_enabled (struct pci_dev *pdev) {return false; }static inline void pcie_disable_tph (struct pci_dev *pdev) { }static inline int pcie_enable_tph (struct pci_dev *pdev,int mode)
Signature · 1 line
2.45.1
Re: [PATCH V4 08/12] PCI/TPH: Add pcie_tph_get_cpu_st() to get ST tag
Quoted 91 lines · Wei Huang
Allow a caller to retrieve Steering Tags for a target memory that is associated with a specific CPU. The caller must provided two parameters, memory type and CPU UID, when calling this function. The tag is retrieved by invoking ACPI
_DSMof the device's Root Port device.Co-developed-by Eric Van Tassell <[email protected]>Signed-off-by Eric Van Tassell <[email protected]>Signed-off-by Wei Huang <[email protected]>Reviewed-by Ajit Khaparde <[email protected]>Reviewed-by Somnath Kotur <[email protected]>Reviewed-by Andy Gospodarek <[email protected]>--- drivers/pci/pcie/tph.c | 154 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-tph.h | 18 +++++ 2 files changed, 172 insertions(+)drivers/pci/pcie/tph.c +61
-0@@ -7,12 +7,125 @@* Wei Huang <[email protected]> */ #include <linux/pci.h> +#include <linux/pci-acpi.h> #include <linux/bitfield.h> #include <linux/msi.h> #include <linux/pci-tph.h> #include "../pci.h" +/* +* The st_info struct defines the Steering Tag (ST) info returned by the +* firmware _DSM method defined in the approved ECN for PCI Firmware Spec, +* available at https://members.pcisig.com/wg/PCI-SIG/document/15470. +* +* @vm_st_valid: 8-bit ST for volatile memory is valid +* @vm_xst_valid: 16-bit extended ST for volatile memory is valid +* @vm_ph_ignore: 1 => PH was and will be ignored, 0 => PH should be supplied +* @vm_st: 8-bit ST for volatile mem +* @vm_xst: 16-bit extended ST for volatile mem +* @pm_st_valid: 8-bit ST for persistent memory is valid +* @pm_xst_valid: 16-bit extended ST for persistent memory is valid +* @pm_ph_ignore: 1 => PH was and will be ignored, 0 => PH should be supplied +* @pm_st: 8-bit ST for persistent mem +* @pm_xst: 16-bit extended ST for persistent mem +*/ +union st_info { +struct { +u64 vm_st_valid :1 ; +u64 vm_xst_valid :1 ; +u64 vm_ph_ignore :1 ; +u64 rsvd1 :5 ; +u64 vm_st :8 ; +u64 vm_xst :16 ; +u64 pm_st_valid :1 ; +u64 pm_xst_valid :1 ; +u64 pm_ph_ignore :1 ; +u64 rsvd2 :5 ; +u64 pm_st :8 ; +u64 pm_xst :16 ; + }; +u64 value; +}; + +static u16 tph_extract_tag (enum tph_mem_type mem_type,u8 req_type, +union st_info *info) +{ +switch (req_type) { +case PCI_TPH_REQ_TPH_ONLY :/* 8-bit tag */ +switch (mem_type) { +case TPH_MEM_TYPE_VM : +if (info->vm_st_valid) +return info->vm_st; +break ; +case TPH_MEM_TYPE_PM : +if (info->pm_st_valid) +return info->pm_st; +break ; + } +break ; +case PCI_TPH_REQ_EXT_TPH :/* 16-bit tag */ +switch (mem_type) { +case TPH_MEM_TYPE_VM : +if (info->vm_xst_valid) +return info->vm_xst; +break ; +case TPH_MEM_TYPE_PM : +if (info->pm_xst_valid) +return info->pm_xst; +break ;
drivers/pci/pcie/tph.c line 86
Quoted 10 lines
drivers/pci/pcie/tph.c +10
-0+ } +break ; +default : +return 0 ; + } + +return 0 ; +} + +#define TPH_ST_DSM_FUNC_INDEX 0xF
Where is this coming from? Any spec to refer to?
drivers/pci/pcie/tph.c line 92
Quoted 6 lines
drivers/pci/pcie/tph.c +6
-0+static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid, + union st_info *st_out) +{ + union acpi_object arg3[3], in_obj, *out_obj; + + if (!acpi_check_dsm(handle, &pci_acpi_dsm_guid, 7,
Again, what is this revision 7 based on? Specs?
I'm trying to use this patchset and this call fails. I've tried to use lower revision numbers with no success.
FWIW, I got no DSM function at all. This could be a problem with my BIOS or system, but in any case, this should be clearer specified in the code.
Quoted 126 lines
drivers/pci/pcie/tph.c +77
-0+ BIT(TPH_ST_DSM_FUNC_INDEX))) +return AE_ERROR ; + +/* DWORD: feature ID (0 for processor cache ST query) */ + arg3[0 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[0 ].integer.value =0 ; + +/* DWORD: target UID */ + arg3[1 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[1 ].integer.value = cpu_uid; + +/* QWORD: properties, all 0's */ + arg3[2 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[2 ].integer.value =0 ; + + in_obj.type =ACPI_TYPE_PACKAGE ; + in_obj.package.count =ARRAY_SIZE (arg3); + in_obj.package.elements = arg3; + + out_obj =acpi_evaluate_dsm (handle, &pci_acpi_dsm_guid,7 , +TPH_ST_DSM_FUNC_INDEX , &in_obj); +if (!out_obj) +return AE_ERROR ; + +if (out_obj->type !=ACPI_TYPE_BUFFER ) { +ACPI_FREE (out_obj); +return AE_ERROR ; + } + + st_out->value = *((u64 *)(out_obj->buffer.pointer)); + +ACPI_FREE (out_obj); + +return AE_OK ; +} +/* Update the TPH Requester Enable field of TPH Control Register */ static void set_ctrl_reg_req_en (struct pci_dev *pdev,u8 req_type) {@@ -140,6 +253,47 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)return pci_write_config_word (pdev, offset, tag); } +/** +* pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated +* with a specific CPU +* @pdev: PCI device +* @mem_type: target memory type (volatile or persistent RAM) +* @cpu_uid: associated CPU id +* @tag: Steering Tag to be returned +* +* This function returns the Steering Tag for a target memory that is +* associated with a specific CPU as indicated by cpu_uid. +* +* Returns 0 if success, otherwise negative value (-errno) +*/ +int pcie_tph_get_cpu_st (struct pci_dev *pdev,enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag) +{ +struct pci_dev *rp; +acpi_handle rp_acpi_handle; +union st_info info; + + rp =pcie_find_root_port (pdev); +if (!rp || !rp->bus || !rp->bus->bridge) +return -ENODEV ; + + rp_acpi_handle =ACPI_HANDLE (rp->bus->bridge); + +if (tph_invoke_dsm (rp_acpi_handle, cpu_uid, &info) !=AE_OK ) { + *tag =0 ; +return -EINVAL ; + } + + *tag =tph_extract_tag (mem_type, pdev->tph_req_type, &info); + +pci_dbg (pdev,"get steering tag: mem_type=%s, cpu_uid=%d, tag=%#04x\n" , + (mem_type ==TPH_MEM_TYPE_VM ) ?"volatile" :"persistent" , + cpu_uid, *tag); + +return 0 ; +} +EXPORT_SYMBOL (pcie_tph_get_cpu_st); +/** * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry * @pdev: PCI device include/linux/pci-tph.h +18
-0@@ -9,9 +9,23 @@#ifndef LINUX_PCI_TPH_H #define LINUX_PCI_TPH_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 +* caller query about a target's Steering Tag, it must provide the target's +* tph_mem_type. ECN link: https://members.pcisig.com/wg/PCI-SIG/document/15470. +*/ +enum tph_mem_type { +TPH_MEM_TYPE_VM ,/* volatile memory */ +TPH_MEM_TYPE_PM /* persistent memory */ +}; +#ifdef CONFIG_PCIE_TPH int pcie_tph_set_st_entry (struct pci_dev *pdev,unsigned int index,u16 tag); +int pcie_tph_get_cpu_st (struct pci_dev *dev, +enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag);bool pcie_tph_enabled (struct pci_dev *pdev);void pcie_disable_tph (struct pci_dev *pdev);int pcie_enable_tph (struct pci_dev *pdev,int mode);@@ -20,6 +34,10 @@ int pcie_tph_modes(struct pci_dev *pdev);static inline int pcie_tph_set_st_entry (struct pci_dev *pdev,unsigned int index,u16 tag) {return -EINVAL ; } +static inline int pcie_tph_get_cpu_st (struct pci_dev *dev, +enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag) +{return -EINVAL ; }static inline bool pcie_tph_enabled (struct pci_dev *pdev) {return false; }static inline void pcie_disable_tph (struct pci_dev *pdev) { }static inline int pcie_enable_tph (struct pci_dev *pdev,int mode)
Re: [PATCH V4 08/12] PCI/TPH: Add pcie_tph_get_cpu_st() to get ST tag
Quoted 98 lines · Alejandro Lucero Palau
Quoted 96 lines · Wei Huang
Allow a caller to retrieve Steering Tags for a target memory that is associated with a specific CPU. The caller must provided two parameters, memory type and CPU UID, when calling this function. The tag is retrieved by invoking ACPI
_DSMof the device's Root Port device.Co-developed-by Eric Van Tassell <[email protected]>Signed-off-by Eric Van Tassell <[email protected]>Signed-off-by Wei Huang <[email protected]>Reviewed-by Ajit Khaparde <[email protected]>Reviewed-by Somnath Kotur <[email protected]>Reviewed-by Andy Gospodarek <[email protected]>--- drivers/pci/pcie/tph.c | 154 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-tph.h | 18 +++++ 2 files changed, 172 insertions(+)drivers/pci/pcie/tph.c +66
-0@@ -7,12 +7,125 @@* Wei Huang <[email protected]> */ #include <linux/pci.h> +#include <linux/pci-acpi.h> #include <linux/bitfield.h> #include <linux/msi.h> #include <linux/pci-tph.h> #include "../pci.h" +/* +* The st_info struct defines the Steering Tag (ST) info returned by the +* firmware _DSM method defined in the approved ECN for PCI Firmware Spec, +* available at https://members.pcisig.com/wg/PCI-SIG/document/15470. +* +* @vm_st_valid: 8-bit ST for volatile memory is valid +* @vm_xst_valid: 16-bit extended ST for volatile memory is valid +* @vm_ph_ignore: 1 => PH was and will be ignored, 0 => PH should be supplied +* @vm_st: 8-bit ST for volatile mem +* @vm_xst: 16-bit extended ST for volatile mem +* @pm_st_valid: 8-bit ST for persistent memory is valid +* @pm_xst_valid: 16-bit extended ST for persistent memory is valid +* @pm_ph_ignore: 1 => PH was and will be ignored, 0 => PH should be supplied +* @pm_st: 8-bit ST for persistent mem +* @pm_xst: 16-bit extended ST for persistent mem +*/ +union st_info { +struct { +u64 vm_st_valid :1 ; +u64 vm_xst_valid :1 ; +u64 vm_ph_ignore :1 ; +u64 rsvd1 :5 ; +u64 vm_st :8 ; +u64 vm_xst :16 ; +u64 pm_st_valid :1 ; +u64 pm_xst_valid :1 ; +u64 pm_ph_ignore :1 ; +u64 rsvd2 :5 ; +u64 pm_st :8 ; +u64 pm_xst :16 ; + }; +u64 value; +}; + +static u16 tph_extract_tag (enum tph_mem_type mem_type,u8 req_type, +union st_info *info) +{ +switch (req_type) { +case PCI_TPH_REQ_TPH_ONLY :/* 8-bit tag */ +switch (mem_type) { +case TPH_MEM_TYPE_VM : +if (info->vm_st_valid) +return info->vm_st; +break ; +case TPH_MEM_TYPE_PM : +if (info->pm_st_valid) +return info->pm_st; +break ; + } +break ; +case PCI_TPH_REQ_EXT_TPH :/* 16-bit tag */ +switch (mem_type) { +case TPH_MEM_TYPE_VM : +if (info->vm_xst_valid) +return info->vm_xst; +break ; +case TPH_MEM_TYPE_PM : +if (info->pm_xst_valid) +return info->pm_xst; +break ; + } +break ; +default : +return 0 ; + }
Quoted 8 lines
drivers/pci/pcie/tph.c line 86
Quoted 5 lines
drivers/pci/pcie/tph.c +5
-0+ +return 0 ; +} + +#define TPH_ST_DSM_FUNC_INDEX 0xFWhere is this coming from? Any spec to refer to?
See comment above: https://members.pcisig.com/wg/PCI-SIG/document/15470
Quoted 11 lines
drivers/pci/pcie/tph.c line 92
Quoted 8 lines
drivers/pci/pcie/tph.c +6
-0+static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid, + union st_info *st_out) +{ + union acpi_object arg3[3], in_obj, *out_obj; + + if (!acpi_check_dsm(handle, &pci_acpi_dsm_guid, 7,Again, what is this revision 7 based on? Specs?
https://members.pcisig.com/wg/PCI-SIG/document/15470
Quoted 6 lines
I'm trying to use this patchset and this call fails. I've tried to use lower revision numbers with no success.
FWIW, I got no DSM function at all. This could be a problem with my BIOS or system, but in any case, this should be clearer specified in the code.
Please make sure both BIOS is the latest version and BIOS option is turned on. You should be able to find the GUID defined in PCIe ECN after dumping ACPI table.
Quoted 128 lines
Quoted 128 lines
drivers/pci/pcie/tph.c +77
-0+ BIT(TPH_ST_DSM_FUNC_INDEX))) +return AE_ERROR ; + +/* DWORD: feature ID (0 for processor cache ST query) */ + arg3[0 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[0 ].integer.value =0 ; + +/* DWORD: target UID */ + arg3[1 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[1 ].integer.value = cpu_uid; + +/* QWORD: properties, all 0's */ + arg3[2 ].integer.type =ACPI_TYPE_INTEGER ; + arg3[2 ].integer.value =0 ; + + in_obj.type =ACPI_TYPE_PACKAGE ; + in_obj.package.count =ARRAY_SIZE (arg3); + in_obj.package.elements = arg3; + + out_obj =acpi_evaluate_dsm (handle, &pci_acpi_dsm_guid,7 , +TPH_ST_DSM_FUNC_INDEX , &in_obj); +if (!out_obj) +return AE_ERROR ; + +if (out_obj->type !=ACPI_TYPE_BUFFER ) { +ACPI_FREE (out_obj); +return AE_ERROR ; + } + + st_out->value = *((u64 *)(out_obj->buffer.pointer)); + +ACPI_FREE (out_obj); + +return AE_OK ; +} +/* Update the TPH Requester Enable field of TPH Control Register */ static void set_ctrl_reg_req_en (struct pci_dev *pdev,u8 req_type) {@@ -140,6 +253,47 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)return pci_write_config_word (pdev, offset, tag); } +/** +* pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated +* with a specific CPU +* @pdev: PCI device +* @mem_type: target memory type (volatile or persistent RAM) +* @cpu_uid: associated CPU id +* @tag: Steering Tag to be returned +* +* This function returns the Steering Tag for a target memory that is +* associated with a specific CPU as indicated by cpu_uid. +* +* Returns 0 if success, otherwise negative value (-errno) +*/ +int pcie_tph_get_cpu_st (struct pci_dev *pdev,enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag) +{ +struct pci_dev *rp; +acpi_handle rp_acpi_handle; +union st_info info; + + rp =pcie_find_root_port (pdev); +if (!rp || !rp->bus || !rp->bus->bridge) +return -ENODEV ; + + rp_acpi_handle =ACPI_HANDLE (rp->bus->bridge); + +if (tph_invoke_dsm (rp_acpi_handle, cpu_uid, &info) !=AE_OK ) { + *tag =0 ; +return -EINVAL ; + } + + *tag =tph_extract_tag (mem_type, pdev->tph_req_type, &info); + +pci_dbg (pdev,"get steering tag: mem_type=%s, cpu_uid=%d, tag=%#04x\n" , + (mem_type ==TPH_MEM_TYPE_VM ) ?"volatile" :"persistent" , + cpu_uid, *tag); + +return 0 ; +} +EXPORT_SYMBOL (pcie_tph_get_cpu_st); +/** * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry * @pdev: PCI device include/linux/pci-tph.h +18
-0@@ -9,9 +9,23 @@#ifndef LINUX_PCI_TPH_H #define LINUX_PCI_TPH_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 +* caller query about a target's Steering Tag, it must provide the target's +* tph_mem_type. ECN link: https://members.pcisig.com/wg/PCI-SIG/document/15470. +*/ +enum tph_mem_type { +TPH_MEM_TYPE_VM ,/* volatile memory */ +TPH_MEM_TYPE_PM /* persistent memory */ +}; +#ifdef CONFIG_PCIE_TPH int pcie_tph_set_st_entry (struct pci_dev *pdev,unsigned int index,u16 tag); +int pcie_tph_get_cpu_st (struct pci_dev *dev, +enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag);bool pcie_tph_enabled (struct pci_dev *pdev);void pcie_disable_tph (struct pci_dev *pdev);int pcie_enable_tph (struct pci_dev *pdev,int mode);@@ -20,6 +34,10 @@ int pcie_tph_modes(struct pci_dev *pdev);static inline int pcie_tph_set_st_entry (struct pci_dev *pdev,unsigned int index,u16 tag) {return -EINVAL ; } +static inline int pcie_tph_get_cpu_st (struct pci_dev *dev, +enum tph_mem_type mem_type, +unsigned int cpu_uid,u16 *tag) +{return -EINVAL ; }static inline bool pcie_tph_enabled (struct pci_dev *pdev) {return false; }static inline void pcie_disable_tph (struct pci_dev *pdev) { }static inline int pcie_enable_tph (struct pci_dev *pdev,int mode)
PATCH v4 9/12 PCI/TPH: Add save/restore support for TPH
In reply to Wei HuangFrom: Paul Luse <[email protected]>
Save and restore the configuration space for TPH capability to preserve the settings during PCI reset. The settings include the TPH control register and the ST table if present.
--- drivers/pci/pci.c | 2 ++ drivers/pci/pci.h | 4 +++ drivers/pci/pcie/tph.c | 62 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+)
drivers/pci/pci.c +2 -0
@@ -1813,6 +1813,7 @@ int pci_save_state(struct pci_dev *dev)pci_save_dpc_state (dev);pci_save_aer_state (dev);pci_save_ptm_state (dev); +pci_save_tph_state (dev);return pci_save_vc_state (dev); }EXPORT_SYMBOL (pci_save_state);
@@ -1917,6 +1918,7 @@ void pci_restore_state(struct pci_dev *dev)pci_restore_vc_state (dev);pci_restore_rebar_state (dev);pci_restore_dpc_state (dev); +pci_restore_tph_state (dev);pci_restore_ptm_state (dev);pci_aer_clear_status (dev);
drivers/pci/pci.h +4 -0
@@ -572,8 +572,12 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)#endif /* CONFIG_PCI_IOV */ #ifdef CONFIG_PCIE_TPH +void pci_restore_tph_state (struct pci_dev *dev); +void pci_save_tph_state (struct pci_dev *dev);void pci_tph_init (struct pci_dev *dev);#else +static inline void pci_restore_tph_state (struct pci_dev *dev) { } +static inline void pci_save_tph_state (struct pci_dev *dev) { }static inline void pci_tph_init (struct pci_dev *dev) { }#endif
drivers/pci/pcie/tph.c +62 -0
68 lines not on this page · raw message
Signature · 1 line
2.45.1
Re: [PATCH V4 09/12] PCI/TPH: Add save/restore support for TPH
Quoted 42 lines · Wei Huang
From: Paul Luse <[email protected]>
Save and restore the configuration space for TPH capability to preserve the settings during PCI reset. The settings include the TPH control register and the ST table if present.
drivers/pci/pcie/tph.c +36
-0+void pci_restore_tph_state (struct pci_dev *pdev) +{ +struct pci_cap_saved_state *save_state; +int num_entries, i, offset; +u16 *st_entry; +u32 *cap; + +if (!pdev->tph_cap) +return ; + +if (!pdev->tph_enabled) +return ; + + save_state =pci_find_saved_ext_cap (pdev,PCI_EXT_CAP_ID_TPH ); +if (!save_state) +return ; + +/* Restore control register and all ST entries */ + cap = &save_state->cap.data[0 ]; +pci_write_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL , *cap++); + st_entry = (u16 *)cap; + offset =PCI_TPH_BASE_SIZEOF ; + num_entries =get_st_table_size (pdev); +for (i =0 ; i < num_entries; i++) { +pci_write_config_word (pdev, pdev->tph_cap + offset, + *st_entry++); + offset +=sizeof (u16); + } +} + +void pci_save_tph_state (struct pci_dev *pdev) +{ +struct pci_cap_saved_state *save_state; +int num_entries, i, offset; +u16 *st_entry; +u32 *cap;
drivers/pci/pcie/tph.c int pcie_tph_modes(struct pci_dev *pdev) · line 531
Quoted 10 lines
drivers/pci/pcie/tph.c +10
-0+ +if (!pdev->tph_cap) +return ; + +if (!pdev->tph_enabled) +return ; + + save_state =pci_find_saved_ext_cap (pdev,PCI_EXT_CAP_ID_TPH ); +if (!save_state) +return ;
Don't we need a pci_add_ext_cap_save_buffer() somewhere for this? E.g., in pci_tph_init()?
Quoted 21 lines
drivers/pci/pcie/tph.c +15
-0+/* Save control register */ + cap = &save_state->cap.data[0 ]; +pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CTRL , cap++); + +/* Save all ST entries in extended capability structure */ + st_entry = (u16 *)cap; + offset =PCI_TPH_BASE_SIZEOF ; + num_entries =get_st_table_size (pdev); +for (i =0 ; i < num_entries; i++) { +pci_read_config_word (pdev, pdev->tph_cap + offset, + st_entry++); + offset +=sizeof (u16); + } +} +void pci_tph_init (struct pci_dev *pdev) { pdev->tph_cap =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_TPH );Signature · 1 line
2.45.1
PATCH v4 10/12 PCI/TPH: Add pci=nostmode to force TPH No ST Mode
In reply to Wei HuangWhen "No ST mode" is enabled, endpoint devices can generate TPH headers but with all steering tags treated as zero. A steering tag of zero is interpreted as "using the default policy" by the root complex. This is essential to quantify the benefit of Steering Tags for some given workloads.
--- Documentation/admin-guide/kernel-parameters.txt | 3 +++ drivers/pci/pci.c | 2 ++ drivers/pci/pci.h | 2 ++ drivers/pci/pcie/tph.c | 12 ++++++++++++ 4 files changed, 19 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +3 -0
@@ -4617,6 +4617,9 @@ nomio [S390] Do not use MIO instructions. norid [S390] ignore the RID field and force use of one PCI domain per PCI function + nostmode [PCIE] If PCIe TPH Processing Hints (TPH) is + enabled, this kernel option forces all Steering + Tags to be treated as zero (aka "No ST Mode"). pcie_aspm= [PCIE] Forcibly enable or ignore PCIe Active State Power Management.
drivers/pci/pci.c +2 -0
@@ -6870,6 +6870,8 @@ static int __init pci_setup(char *str)pci_no_domains (); }else if (!strncmp (str,"noari" ,5 )) { pcie_ari_disabled = true; + }else if (!strncmp (str,"nostmode" ,8 )) { +pci_tph_set_nostmode (); }else if (!strncmp (str,"cbiosize=" ,9 )) { pci_cardbus_io_size =memparse (str +9 , &str); }else if (!strncmp (str,"cbmemsize=" ,10 )) {
drivers/pci/pci.h +2 -0
@@ -574,10 +574,12 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)#ifdef CONFIG_PCIE_TPH void pci_restore_tph_state (struct pci_dev *dev);void pci_save_tph_state (struct pci_dev *dev); +void pci_tph_set_nostmode (void );void pci_tph_init (struct pci_dev *dev);#else static inline void pci_restore_tph_state (struct pci_dev *dev) { }static inline void pci_save_tph_state (struct pci_dev *dev) { } +static inline void pci_tph_set_nostmode (void ) { }static inline void pci_tph_init (struct pci_dev *dev) { }#endif
drivers/pci/pcie/tph.c +12 -0
@@ -48,6 +48,8 @@ union st_info {u64 value; }; +static bool pci_tph_nostmode; +static u16 tph_extract_tag (enum tph_mem_type mem_type,u8 req_type,union st_info *info) {
@@ -433,6 +435,10 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)return -EINVAL ; } +/* Honor "nostmode" kernel parameter */ +if (pci_tph_nostmode) + pdev->tph_mode =PCI_TPH_NO_ST_MODE ; +/* Get req_type supported by device and its Root Port */ reg =pci_read_config_dword (pdev, pdev->tph_cap +PCI_TPH_CAP , ®);if (FIELD_GET (PCI_TPH_CAP_EXT_TPH , reg))
@@ -545,6 +551,12 @@ void pci_save_tph_state(struct pci_dev *pdev) } } +void pci_tph_set_nostmode (void ) +{ + pci_tph_nostmode = true; +pr_info ("PCIe TPH No ST Mode is enabled\n" ); +} +void pci_tph_init (struct pci_dev *pdev) { pdev->tph_cap =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_TPH );
Signature · 1 line
2.45.1
PATCH v4 11/12 bnxt_en: Add TPH support in BNXT driver
In reply to Wei HuangFrom: Manoj Panicker <[email protected]>
Implement TPH support in Broadcom BNXT device driver. The driver uses TPH functions to retrieve and configure the device's Steering Tags when its interrupt affinity is being changed.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 78 +++++++++++++++++++++++ drivers/net/ethernet/broadcom/bnxt/bnxt.h | 4 ++ 2 files changed, 82 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +78 -0
@@ -55,6 +55,7 @@#include <net/page_pool/helpers.h> #include <linux/align.h> #include <net/netdev_queues.h> +#include <linux/pci-tph.h> #include "bnxt_hsi.h" #include "bnxt.h"
@@ -10821,6 +10822,58 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)return 0 ; } +static void __bnxt_irq_affinity_notify (struct irq_affinity_notify *notify, +const cpumask_t *mask) +{ +struct bnxt_irq *irq; +u16 tag; + + irq = container_of(notify, struct bnxt_irq, affinity_notify); +cpumask_copy (irq->cpu_mask, mask); + +if (pcie_tph_get_cpu_st (irq->bp->pdev,TPH_MEM_TYPE_VM , +cpumask_first (irq->cpu_mask), &tag)) +return ; + +if (pcie_tph_set_st_entry (irq->bp->pdev, irq->msix_nr, tag)) +return ; + +if (netif_running (irq->bp->dev)) { +rtnl_lock (); +bnxt_close_nic (irq->bp, false, false); +bnxt_open_nic (irq->bp, false, false); +rtnl_unlock (); + } +} + +static void __bnxt_irq_affinity_release (struct kref __always_unused *ref) +{ +} + +static void bnxt_release_irq_notifier (struct bnxt_irq *irq) +{ +irq_set_affinity_notifier (irq->vector,NULL ); +} + +static void bnxt_register_irq_notifier (struct bnxt *bp,struct bnxt_irq *irq) +{ +struct irq_affinity_notify *notify; + +/* Nothing to do if TPH is not enabled */ +if (!pcie_tph_enabled (bp->pdev)) +return ; + + irq->bp = bp; + +/* Register IRQ affinility notifier */ + notify = &irq->affinity_notify; + notify->irq = irq->vector; + notify->notify = __bnxt_irq_affinity_notify; + notify->release = __bnxt_irq_affinity_release; + +irq_set_affinity_notifier (irq->vector, notify); +} +static void bnxt_free_irq (struct bnxt *bp) {struct bnxt_irq *irq;
@@ -10843,11 +10896,17 @@ static void bnxt_free_irq(struct bnxt *bp)free_cpumask_var (irq->cpu_mask); irq->have_cpumask =0 ; } + +bnxt_release_irq_notifier (irq); +free_irq (irq->vector, bp->bnapi[i]); } irq->requested =0 ; } + +/* Disable TPH support */ +pcie_disable_tph (bp->pdev); }static int bnxt_request_irq (struct bnxt *bp)
@@ -10870,6 +10929,13 @@ static int bnxt_request_irq(struct bnxt *bp)if (!(bp->flags &BNXT_FLAG_USING_MSIX )) flags =IRQF_SHARED ; +/* Enable TPH support as part of IRQ request */ +if (pcie_tph_modes (bp->pdev) &PCI_TPH_CAP_INT_VEC ) { + rc =pcie_enable_tph (bp->pdev,PCI_TPH_CAP_INT_VEC ); +if (rc) +netdev_warn (bp->dev,"failed enabling TPH support\n" ); + } +for (i =0 , j =0 ; i < bp->cp_nr_rings; i++) {int map_idx =bnxt_cp_num_to_irq_num (bp, i);struct bnxt_irq *irq = &bp->irq_tbl[map_idx];
@@ -10893,8 +10959,10 @@ static int bnxt_request_irq(struct bnxt *bp)if (zalloc_cpumask_var (&irq->cpu_mask,GFP_KERNEL )) {int numa_node =dev_to_node (&bp->pdev->dev); +u16 tag; irq->have_cpumask =1 ; + irq->msix_nr = map_idx;cpumask_set_cpu (cpumask_local_spread (i, numa_node), irq->cpu_mask); rc =irq_set_affinity_hint (irq->vector, irq->cpu_mask);
@@ -10904,6 +10972,16 @@ static int bnxt_request_irq(struct bnxt *bp) irq->vector);break ; } + +bnxt_register_irq_notifier (bp, irq); + +/* Init ST table entry */ +if (pcie_tph_get_cpu_st (irq->bp->pdev,TPH_MEM_TYPE_VM , +cpumask_first (irq->cpu_mask), + &tag)) +break ; + +pcie_tph_set_st_entry (irq->bp->pdev, irq->msix_nr, tag); } }return rc;
drivers/net/ethernet/broadcom/bnxt/bnxt.h +4 -0
@@ -1224,6 +1224,10 @@ struct bnxt_irq { u8 have_cpumask:1;char name[IFNAMSIZ +2 ];cpumask_var_t cpu_mask; + +struct bnxt *bp; +int msix_nr; +struct irq_affinity_notify affinity_notify; };#define HWRM_RING_ALLOC_TX 0x1
Signature · 1 line
2.45.1
Jakub Kicinski
maintainerRe: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 10845
Quoted 4 lines · On Thu, 22 Aug 2024 15:41:19 -0500 Wei Huang wrote:
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4
-0+rtnl_lock (); +bnxt_close_nic (irq->bp, false, false); +bnxt_open_nic (irq->bp, false, false); +rtnl_unlock ();
This code means that under memory pressure changing CPU affinity can take the machine offline. The entire machine, even if container orchestration is trying to just move a few IRQs in place for a new container.
We can't let you do this, it will set a bad precedent. I can't think of any modern driver with reconfiguration safety as bad as bnxt. Technical debt coming due.
Re: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
Quoted 11 lines · Jakub Kicinski
drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 10845
Quoted 4 lines · On Thu, 22 Aug 2024 15:41:19 -0500 Wei Huang wrote:
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4
-0+rtnl_lock (); +bnxt_close_nic (irq->bp, false, false); +bnxt_open_nic (irq->bp, false, false); +rtnl_unlock ();This code means that under memory pressure changing CPU affinity can take the machine offline. The entire machine, even if container orchestration is trying to just move a few IRQs in place for a new container.
Quoted 3 lines
We can't let you do this, it will set a bad precedent. I can't think of any modern driver with reconfiguration safety as bad as bnxt. Technical debt coming due.
Jakub,
We have not said this on the list, but we agree. We plan to replace these calls with calls to stop and start only that ring via netdev_rx_queue_restart as soon as these calls all land in the same tree. Since this set is [presumably] coming through linux-pci we didn't think we could do that yet.
Thoughts?
-andy
Jakub Kicinski
maintainerRe: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
Quoted 6 lines · On Mon, 26 Aug 2024 16:56:36 -0400 Andy Gospodarek wrote:
We plan to replace these calls with calls to stop and start only that ring via
netdev_rx_queue_restartas soon as these calls all land in the same tree. Since this set is [presumably] coming through linux-pci we didn't think we could do that yet.Thoughts?
The merge window is in 3 weeks or so, so this can wait. I'm worried we'll find out later that the current queue reset implementation in bnxt turns out to be insufficient. And we'll be stuck with yet another close/open in this driver.
While we talk about affinity settings in bnxt -- it'd be great if it maintained the mapping and XPS settings across reconfiguration (like queue count changes or attaching XDP).
Re: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
Quoted 9 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 26 Aug 2024 16:56:36 -0400 Andy Gospodarek wrote:
We plan to replace these calls with calls to stop and start only that ring via
netdev_rx_queue_restartas soon as these calls all land in the same tree. Since this set is [presumably] coming through linux-pci we didn't think we could do that yet.Thoughts?
The merge window is in 3 weeks or so, so this can wait.
Are you asking for the patch for this feature to include the queue stop/start instead of this? I just checked linux-pci and it does have bnxt_queue_stop/bnxt_queue_start.
Quoted 3 lines
I'm worried we'll find out later that the current queue reset implementation in bnxt turns out to be insufficient. And we'll be stuck with yet another close/open in this driver.
The queue reset _has_ to work. We will ensure that it does and fix any problems found. Note that these have been under test already internally and fixes are/will be posted to the list as they are made. Holding this patch because an API that it uses might not work seems odd.
Jakub Kicinski
maintainerRe: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
Quoted 4 lines · On Tue, 27 Aug 2024 10:50:51 -0400 Andy Gospodarek wrote:
Quoted 1 line
The merge window is in 3 weeks or so, so this can wait.
Are you asking for the patch for this feature to include the queue stop/start instead of this?
Yes, indeed.
Quoted 10 lines
I just checked linux-pci and it does have bnxt_queue_stop/bnxt_queue_start.
Quoted 3 lines
I'm worried we'll find out later that the current queue reset implementation in bnxt turns out to be insufficient. And we'll be stuck with yet another close/open in this driver.
The queue reset _has_ to work. We will ensure that it does and fix any problems found. Note that these have been under test already internally and fixes are/will be posted to the list as they are made. Holding this patch because an API that it uses might not work seems odd.
Not holding because API may not work, holding because (I thought) API isn't in place at all. If bnxt_queue_stop/bnxt_queue_start are in linux-pci please rewrite the patch to use those and then all clear from my PoV.
Michael Chan
maintainerRe: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
Quoted 4 lines · Jakub Kicinski
Not holding because API may not work, holding because (I thought) API isn't in place at all. If bnxt_queue_stop/bnxt_queue_start are in linux-pci please rewrite the patch to use those and then all clear from my PoV.
To be clear, the API is available in the linux-pci tree but the recent patch from David to check for proper FW support is only in net-next:
97cbf3d0accc ("bnxt_en: only set dev->queue_mgmt_ops if supported by FW")
So we'll need to add this check for TPH also once the 2 trees are merged.
Re: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
In reply to Wei Huangdrivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 10868
Quoted 7 lines · Wei Huang
From: Manoj Panicker <[email protected]>
Implement TPH support in Broadcom BNXT device driver. The driver uses TPH functions to retrieve and configure the device's Steering Tags when its interrupt affinity is being changed.
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1
-0+/* Register IRQ affinility notifier */
s/affinility/affinity/
Re: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
In reply to Wei HuangQuoted 34 lines · Wei Huang
From: Manoj Panicker <[email protected]>
Implement TPH support in Broadcom BNXT device driver. The driver uses TPH functions to retrieve and configure the device's Steering Tags when its interrupt affinity is being changed.
Co-developed-by Wei Huang <[email protected]>Signed-off-by Wei Huang <[email protected]>Signed-off-by Manoj Panicker <[email protected]>Reviewed-by Ajit Khaparde <[email protected]>Reviewed-by Somnath Kotur <[email protected]>Reviewed-by Andy Gospodarek <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 78 +++++++++++++++++++++++ drivers/net/ethernet/broadcom/bnxt/bnxt.h | 4 ++ 2 files changed, 82 insertions(+)drivers/net/ethernet/broadcom/bnxt/bnxt.c +2
-0@@ -55,6 +55,7 @@#include <net/page_pool/helpers.h> #include <linux/align.h> #include <net/netdev_queues.h> +#include <linux/pci-tph.h> #include "bnxt_hsi.h" #include "bnxt.h" @@ -10821,6 +10822,58 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)return 0 ; } +static void __bnxt_irq_affinity_notify(struct irq_affinity_notify *notify,
drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 10835
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10
-0+ const cpumask_t *mask) +{ +struct bnxt_irq *irq; +u16 tag; + + irq = container_of(notify, struct bnxt_irq, affinity_notify); +cpumask_copy (irq->cpu_mask, mask); + +if (pcie_tph_get_cpu_st (irq->bp->pdev,TPH_MEM_TYPE_VM , +cpumask_first (irq->cpu_mask), &tag))
I understand just one cpu from the mask has to be used, but I wonder if some check should be done for ensuring the mask is not mad.
This is control path and the related queue is going to be restarted, so maybe a sanity check for ensuring all the cpus in the mask are from the same CCX complex?
That would be an iteration checking the tag is the same one for all of them. If not, at least a warning stating the tag/CCX/cpu used.
Quoted 119 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +66
-0+return ; + +if (pcie_tph_set_st_entry (irq->bp->pdev, irq->msix_nr, tag)) +return ; + +if (netif_running (irq->bp->dev)) { +rtnl_lock (); +bnxt_close_nic (irq->bp, false, false); +bnxt_open_nic (irq->bp, false, false); +rtnl_unlock (); + } +} + +static void __bnxt_irq_affinity_release (struct kref __always_unused *ref) +{ +} + +static void bnxt_release_irq_notifier (struct bnxt_irq *irq) +{ +irq_set_affinity_notifier (irq->vector,NULL ); +} + +static void bnxt_register_irq_notifier (struct bnxt *bp,struct bnxt_irq *irq) +{ +struct irq_affinity_notify *notify; + +/* Nothing to do if TPH is not enabled */ +if (!pcie_tph_enabled (bp->pdev)) +return ; + + irq->bp = bp; + +/* Register IRQ affinility notifier */ + notify = &irq->affinity_notify; + notify->irq = irq->vector; + notify->notify = __bnxt_irq_affinity_notify; + notify->release = __bnxt_irq_affinity_release; + +irq_set_affinity_notifier (irq->vector, notify); +} +static void bnxt_free_irq (struct bnxt *bp) {struct bnxt_irq *irq;@@ -10843,11 +10896,17 @@ static void bnxt_free_irq(struct bnxt *bp)free_cpumask_var (irq->cpu_mask); irq->have_cpumask =0 ; } + +bnxt_release_irq_notifier (irq); +free_irq (irq->vector, bp->bnapi[i]); } irq->requested =0 ; } + +/* Disable TPH support */ +pcie_disable_tph (bp->pdev); }static int bnxt_request_irq (struct bnxt *bp)@@ -10870,6 +10929,13 @@ static int bnxt_request_irq(struct bnxt *bp)if (!(bp->flags &BNXT_FLAG_USING_MSIX )) flags =IRQF_SHARED ; +/* Enable TPH support as part of IRQ request */ +if (pcie_tph_modes (bp->pdev) &PCI_TPH_CAP_INT_VEC ) { + rc =pcie_enable_tph (bp->pdev,PCI_TPH_CAP_INT_VEC ); +if (rc) +netdev_warn (bp->dev,"failed enabling TPH support\n" ); + } +for (i =0 , j =0 ; i < bp->cp_nr_rings; i++) {int map_idx =bnxt_cp_num_to_irq_num (bp, i);struct bnxt_irq *irq = &bp->irq_tbl[map_idx];@@ -10893,8 +10959,10 @@ static int bnxt_request_irq(struct bnxt *bp)if (zalloc_cpumask_var (&irq->cpu_mask,GFP_KERNEL )) {int numa_node =dev_to_node (&bp->pdev->dev); +u16 tag; irq->have_cpumask =1 ; + irq->msix_nr = map_idx;cpumask_set_cpu (cpumask_local_spread (i, numa_node), irq->cpu_mask); rc =irq_set_affinity_hint (irq->vector, irq->cpu_mask);@@ -10904,6 +10972,16 @@ static int bnxt_request_irq(struct bnxt *bp) irq->vector);break ; } + +bnxt_register_irq_notifier (bp, irq); + +/* Init ST table entry */ +if (pcie_tph_get_cpu_st (irq->bp->pdev,TPH_MEM_TYPE_VM , +cpumask_first (irq->cpu_mask), + &tag)) +break ; + +pcie_tph_set_st_entry (irq->bp->pdev, irq->msix_nr, tag); } }return rc;drivers/net/ethernet/broadcom/bnxt/bnxt.h +4
-0@@ -1224,6 +1224,10 @@ struct bnxt_irq { u8 have_cpumask:1;char name[IFNAMSIZ +2 ];cpumask_var_t cpu_mask; + +struct bnxt *bp; +int msix_nr; +struct irq_affinity_notify affinity_notify; };#define HWRM_RING_ALLOC_TX 0x1
Re: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
Quoted 51 lines · Alejandro Lucero Palau
Quoted 34 lines · Wei Huang
From: Manoj Panicker <[email protected]>
Implement TPH support in Broadcom BNXT device driver. The driver uses TPH functions to retrieve and configure the device's Steering Tags when its interrupt affinity is being changed.
Co-developed-by Wei Huang <[email protected]>Signed-off-by Wei Huang <[email protected]>Signed-off-by Manoj Panicker <[email protected]>Reviewed-by Ajit Khaparde <[email protected]>Reviewed-by Somnath Kotur <[email protected]>Reviewed-by Andy Gospodarek <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 78 +++++++++++++++++++++++ drivers/net/ethernet/broadcom/bnxt/bnxt.h | 4 ++ 2 files changed, 82 insertions(+)drivers/net/ethernet/broadcom/bnxt/bnxt.c +2
-0@@ -55,6 +55,7 @@#include <net/page_pool/helpers.h> #include <linux/align.h> #include <net/netdev_queues.h> +#include <linux/pci-tph.h> #include "bnxt_hsi.h" #include "bnxt.h" @@ -10821,6 +10822,58 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)return 0 ; } +static void __bnxt_irq_affinity_notify(struct irq_affinity_notify *notify,drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) · line 10835
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10
-0+ const cpumask_t *mask) +{ +struct bnxt_irq *irq; +u16 tag; + + irq = container_of(notify, struct bnxt_irq, affinity_notify); +cpumask_copy (irq->cpu_mask, mask); + +if (pcie_tph_get_cpu_st (irq->bp->pdev,TPH_MEM_TYPE_VM , +cpumask_first (irq->cpu_mask), &tag))I understand just one cpu from the mask has to be used, but I wonder if some check should be done for ensuring the mask is not mad.
Quoted 3 lines
This is control path and the related queue is going to be restarted, so maybe a sanity check for ensuring all the cpus in the mask are from the same CCX complex?
I don't think this is always true and we shouldn't warn when this happens. There is only one ST can be supported, so the driver need to make a good judgement on which ST to be used. But no matter what, ST is just a hint - it shouldn't cause any correctness issues in HW, even when it is not the optimal target CPU. So warning is unnecessary.
Quoted 124 lines
That would be an iteration checking the tag is the same one for all of them. If not, at least a warning stating the tag/CCX/cpu used.
Quoted 119 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +66
-0+return ; + +if (pcie_tph_set_st_entry (irq->bp->pdev, irq->msix_nr, tag)) +return ; + +if (netif_running (irq->bp->dev)) { +rtnl_lock (); +bnxt_close_nic (irq->bp, false, false); +bnxt_open_nic (irq->bp, false, false); +rtnl_unlock (); + } +} + +static void __bnxt_irq_affinity_release (struct kref __always_unused *ref) +{ +} + +static void bnxt_release_irq_notifier (struct bnxt_irq *irq) +{ +irq_set_affinity_notifier (irq->vector,NULL ); +} + +static void bnxt_register_irq_notifier (struct bnxt *bp,struct bnxt_irq *irq) +{ +struct irq_affinity_notify *notify; + +/* Nothing to do if TPH is not enabled */ +if (!pcie_tph_enabled (bp->pdev)) +return ; + + irq->bp = bp; + +/* Register IRQ affinility notifier */ + notify = &irq->affinity_notify; + notify->irq = irq->vector; + notify->notify = __bnxt_irq_affinity_notify; + notify->release = __bnxt_irq_affinity_release; + +irq_set_affinity_notifier (irq->vector, notify); +} +static void bnxt_free_irq (struct bnxt *bp) {struct bnxt_irq *irq;@@ -10843,11 +10896,17 @@ static void bnxt_free_irq(struct bnxt *bp)free_cpumask_var (irq->cpu_mask); irq->have_cpumask =0 ; } + +bnxt_release_irq_notifier (irq); +free_irq (irq->vector, bp->bnapi[i]); } irq->requested =0 ; } + +/* Disable TPH support */ +pcie_disable_tph (bp->pdev); }static int bnxt_request_irq (struct bnxt *bp)@@ -10870,6 +10929,13 @@ static int bnxt_request_irq(struct bnxt *bp)if (!(bp->flags &BNXT_FLAG_USING_MSIX )) flags =IRQF_SHARED ; +/* Enable TPH support as part of IRQ request */ +if (pcie_tph_modes (bp->pdev) &PCI_TPH_CAP_INT_VEC ) { + rc =pcie_enable_tph (bp->pdev,PCI_TPH_CAP_INT_VEC ); +if (rc) +netdev_warn (bp->dev,"failed enabling TPH support\n" ); + } +for (i =0 , j =0 ; i < bp->cp_nr_rings; i++) {int map_idx =bnxt_cp_num_to_irq_num (bp, i);struct bnxt_irq *irq = &bp->irq_tbl[map_idx];@@ -10893,8 +10959,10 @@ static int bnxt_request_irq(struct bnxt *bp)if (zalloc_cpumask_var (&irq->cpu_mask,GFP_KERNEL )) {int numa_node =dev_to_node (&bp->pdev->dev); +u16 tag; irq->have_cpumask =1 ; + irq->msix_nr = map_idx;cpumask_set_cpu (cpumask_local_spread (i, numa_node), irq->cpu_mask); rc =irq_set_affinity_hint (irq->vector, irq->cpu_mask);@@ -10904,6 +10972,16 @@ static int bnxt_request_irq(struct bnxt *bp) irq->vector);break ; } + +bnxt_register_irq_notifier (bp, irq); + +/* Init ST table entry */ +if (pcie_tph_get_cpu_st (irq->bp->pdev,TPH_MEM_TYPE_VM , +cpumask_first (irq->cpu_mask), + &tag)) +break ; + +pcie_tph_set_st_entry (irq->bp->pdev, irq->msix_nr, tag); } }return rc;drivers/net/ethernet/broadcom/bnxt/bnxt.h +4
-0@@ -1224,6 +1224,10 @@ struct bnxt_irq { u8 have_cpumask:1;char name[IFNAMSIZ +2 ];cpumask_var_t cpu_mask; + +struct bnxt *bp; +int msix_nr; +struct irq_affinity_notify affinity_notify; };#define HWRM_RING_ALLOC_TX 0x1
Re: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
Quoted 54 lines · Wei Huang
Quoted 51 lines · Alejandro Lucero Palau
Quoted 34 lines · Wei Huang
From: Manoj Panicker <[email protected]>
Implement TPH support in Broadcom BNXT device driver. The driver uses TPH functions to retrieve and configure the device's Steering Tags when its interrupt affinity is being changed.
Co-developed-by Wei Huang <[email protected]>Signed-off-by Wei Huang <[email protected]>Signed-off-by Manoj Panicker <[email protected]>Reviewed-by Ajit Khaparde <[email protected]>Reviewed-by Somnath Kotur <[email protected]>Reviewed-by Andy Gospodarek <[email protected]>---
drivers/net/ethernet/broadcom/bnxt/bnxt.c| 78
+++++++++++++++++++++++
drivers/net/ethernet/broadcom/bnxt/bnxt.h| 4 ++2 files changed, 82 insertions(+)drivers/net/ethernet/broadcom/bnxt/bnxt.c +1
-0@@ -55,6 +55,7 @@ #include <net/page_pool/helpers.h> #include <linux/align.h> #include <net/netdev_queues.h> +#include <linux/pci-tph.h> #include "bnxt_hsi.h" #include "bnxt.h"@@ -10821,6 +10822,58 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init) return 0; } +static void __bnxt_irq_affinity_notify(struct irq_affinity_notify *notify,drivers/net/ethernet/broadcom/bnxt/bnxt.c int bnxt_reserve_rings(struct bnxt *bp, · line 10835
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10
-0+ const cpumask_t *mask) +{ + struct bnxt_irq *irq; + u16 tag; + + irq = container_of(notify, struct bnxt_irq, affinity_notify); + cpumask_copy(irq->cpu_mask, mask); + + if (pcie_tph_get_cpu_st(irq->bp->pdev, TPH_MEM_TYPE_VM, + cpumask_first(irq->cpu_mask), &tag))I understand just one cpu from the mask has to be used, but I wonder if some check should be done for ensuring the mask is not mad.
Quoted 6 lines
Quoted 3 lines
This is control path and the related queue is going to be restarted, so maybe a sanity check for ensuring all the cpus in the mask are from the same CCX complex?
I don't think this is always true and we shouldn't warn when this happens. There is only one ST can be supported, so the driver need to make a good judgement on which ST to be used. But no matter what, ST is just a hint - it shouldn't cause any correctness issues in HW, even when it is not the optimal target CPU. So warning is unnecessary.
1) You can use a "mad" mask for avoiding a specific interrupt to disturb a specific execution is those cores not part of the mask. But I argue the ST hint should not be set then.
2) Someone, maybe an automatic script, could try to get the best performance possible, and a "mad" mask could preclude such outcome inadvertently.
I agree a warning could not be a good idea because 1, but I would say adding some way of traceability here could be interesting. A tracepoint or a new ST field for last hint set for that interrupt/queue.
Quoted 120 lines
Quoted 120 lines
That would be an iteration checking the tag is the same one for all of them. If not, at least a warning stating the tag/CCX/cpu used.
Quoted 115 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +41
-0+ return; + + if (pcie_tph_set_st_entry(irq->bp->pdev, irq->msix_nr, tag)) + return; + + if (netif_running(irq->bp->dev)) { + rtnl_lock(); + bnxt_close_nic(irq->bp, false, false); + bnxt_open_nic(irq->bp, false, false); + rtnl_unlock(); + } +} + +static void __bnxt_irq_affinity_release (struct kref __always_unused *ref) +{ +} + +static void bnxt_release_irq_notifier (struct bnxt_irq *irq) +{ + irq_set_affinity_notifier(irq->vector, NULL); +} + +static void bnxt_register_irq_notifier (struct bnxt *bp,struct bnxt_irq *irq) +{ + struct irq_affinity_notify *notify; + + /* Nothing to do if TPH is not enabled */ + if (!pcie_tph_enabled(bp->pdev)) + return; + + irq->bp = bp; + + /* Register IRQ affinility notifier */ + notify = &irq->affinity_notify; + notify->irq = irq->vector; + notify->notify = __bnxt_irq_affinity_notify; + notify->release = __bnxt_irq_affinity_release; + + irq_set_affinity_notifier(irq->vector, notify); +} +static void
bnxt_free_irq(struct bnxt *bp)
{
structbnxt_irq*irq;drivers/net/ethernet/broadcom/bnxt/bnxt.c +6
-0@@ -10843,11 +10896,17 @@ static void bnxt_free_irq(struct bnxt *bp) free_cpumask_var(irq->cpu_mask); irq->have_cpumask = 0; } + + bnxt_release_irq_notifier(irq); + free_irq(irq->vector, bp->bnapi[i]); } irq->requested = 0; } + + /* Disable TPH support */ + pcie_disable_tph(bp->pdev); } static int bnxt_request_irq(struct bnxt *bp)@@ -10870,6 +10929,13 @@ static int bnxt_request_irq(struct bnxt *bp) if (!(bp->flags & BNXT_FLAG_USING_MSIX)) flags = IRQF_SHARED;+ /* Enable TPH support as part of IRQ request */ + if (
pcie_tph_modes(bp->pdev)&PCI_TPH_CAP_INT_VEC) { + rc =pcie_enable_tph(bp->pdev, PCI_TPH_CAP_INT_VEC); + if (rc)
+netdev_warn(bp->dev, "failed enabling TPH support\n"); + }
+
for (i = 0, j = 0; i <bp->cp_nr_rings; i++) { intmap_idx=bnxt_cp_num_to_irq_num(bp, i); structbnxt_irq*irq = &bp->irq_tbl[map_idx];drivers/net/ethernet/broadcom/bnxt/bnxt.c +12
-0@@ -10893,8 +10959,10 @@ static int bnxt_request_irq(struct bnxt *bp) if (zalloc_cpumask_var(&irq->cpu_mask, GFP_KERNEL)) { int numa_node = dev_to_node(&bp->pdev->dev); + u16 tag; irq->have_cpumask = 1; + irq->msix_nr = map_idx; cpumask_set_cpu(cpumask_local_spread(i, numa_node), irq->cpu_mask); rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask);@@ -10904,6 +10972,16 @@ static int bnxt_request_irq(struct bnxt *bp) irq->vector); break; } + + bnxt_register_irq_notifier(bp, irq); + + /* Init ST table entry */ + if (pcie_tph_get_cpu_st(irq->bp->pdev, TPH_MEM_TYPE_VM, + cpumask_first(irq->cpu_mask), + &tag)) + break; + + pcie_tph_set_st_entry(irq->bp->pdev, irq->msix_nr, tag); } } return rc;drivers/net/ethernet/broadcom/bnxt/bnxt.h +4
-0@@ -1224,6 +1224,10 @@ struct bnxt_irq { u8 have_cpumask:1; char name[IFNAMSIZ + 2]; cpumask_var_t cpu_mask; + + struct bnxt *bp; + int msix_nr; + struct irq_affinity_notify affinity_notify; }; #define HWRM_RING_ALLOC_TX 0x1
Re: [PATCH V4 11/12] bnxt_en: Add TPH support in BNXT driver
Quoted 6 lines · Alejandro Lucero Palau
Quoted 4 lines · Wei Huang
Quoted 1 line · Alejandro Lucero Palau
...
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
I understand just one cpu from the mask has to be used, but I wonder if some check should be done for ensuring the mask is not mad.
This is control path and the related queue is going to be restarted, so maybe a sanity check for ensuring all the cpus in the mask are from the same CCX complex?
Quoted 6 lines
I don't think this is always true and we shouldn't warn when this happens. There is only one ST can be supported, so the driver need to make a good judgement on which ST to be used. But no matter what, ST is just a hint - it shouldn't cause any correctness issues in HW, even when it is not the optimal target CPU. So warning is unnecessary.
Quoted 9 lines
1) You can use a "mad" mask for avoiding a specific interrupt to disturb a specific execution is those cores not part of the mask. But I argue the ST hint should not be set then.
2) Someone, maybe an automatic script, could try to get the best performance possible, and a "mad" mask could preclude such outcome inadvertently.
For this case, you can use the following command:
echo cpu_id > /proc/irq/nnn/smp_affinity_list
where nnn is the MSI IRQ number associated witht the device. This forces IRQ to be associated with only one specific CPU.
Quoted 4 lines
I agree a warning could not be a good idea because 1, but I would say adding some way of traceability here could be interesting. A tracepoint or a new ST field for last hint set for that interrupt/queue.
We do have two pci_dbg() in tph.c. You can see the logs with proper kernel print level. The logs show GET/SET ST values in what PCIe device, which ST table, and at which index.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
That would be an iteration checking the tag is the same one for all of them. If not, at least a warning stating the tag/CCX/cpu used.
PATCH v4 12/12 bnxt_en: Pass NQ ID to the FW when allocating RX/RX AGG rings
In reply to Wei HuangFrom: Michael Chan <[email protected]>
Newer firmware can use the NQ ring ID associated with each RX/RX AGG ring to enable PCIe steering tag. Older firmware will just ignore the information.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -2
@@ -6838,10 +6838,12 @@ static int hwrm_ring_alloc_send_msg(struct bnxt *bp,/* Association of rx ring with stats context */ grp_info = &bp->grp_info[ring->grp_idx]; + req->nq_ring_id =cpu_to_le16 (grp_info->cp_fw_ring_id); req->rx_buf_size =cpu_to_le16 (bp->rx_buf_use_size); req->stat_ctx_id =cpu_to_le32 (grp_info->fw_stats_ctx); req->enables |=cpu_to_le32 ( -RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID ); +RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID | +RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID );if (NET_IP_ALIGN ==2 ) flags =RING_ALLOC_REQ_FLAGS_RX_SOP_PAD ; req->flags =cpu_to_le16 (flags);
@@ -6853,11 +6855,13 @@ static int hwrm_ring_alloc_send_msg(struct bnxt *bp,/* Association of agg ring with rx ring */ grp_info = &bp->grp_info[ring->grp_idx]; req->rx_ring_id =cpu_to_le16 (grp_info->rx_fw_ring_id); + req->nq_ring_id =cpu_to_le16 (grp_info->cp_fw_ring_id); req->rx_buf_size =cpu_to_le16 (BNXT_RX_PAGE_SIZE ); req->stat_ctx_id =cpu_to_le32 (grp_info->fw_stats_ctx); req->enables |=cpu_to_le32 (RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID | -RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID ); +RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID | +RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID ); }else { req->ring_type =RING_ALLOC_REQ_RING_TYPE_RX ; }
Signature · 1 line
2.45.1
Hi Bjorn,
I have incorporated Jakub's feedback on patch 11 (i.e. bnxt.c) in my new revision. Do you have additional comments or suggestions on V4 to include in the next spin?
Thanks,
-Wei
Quoted 85 lines · Wei Huang
Hi All,
TPH (TLP Processing Hints) is a PCIe feature that allows endpoint devices to provide optimization hints for requests that target memory space. These hints, in a format called steering tag (ST), are provided in the requester's TLP headers and allow the system hardware, including the Root Complex, to optimize the utilization of platform resources for the requests.
Upcoming AMD hardware implement a new Cache Injection feature that leverages TPH. Cache Injection allows PCIe endpoints to inject I/O Coherent DMA writes directly into an L2 within the CCX (core complex) closest to the CPU core that will consume it. This technology is aimed at applications requiring high performance and low latency, such as networking and storage applications.
This series introduces generic TPH support in Linux, allowing STs to be retrieved and used by PCIe endpoint drivers as needed. As a demonstration, it includes an example usage in the Broadcom BNXT driver. When running on Broadcom NICs with the appropriate firmware, it shows substantial memory bandwidth savings and better network bandwidth using real-world benchmarks. This solution is vendor-neutral and implemented based on industry standards (PCIe Spec and PCI FW Spec).
V3->V4:
* Rebase on top of the latest pci/next tree (tag: 6.11-rc1)
* Add new API functioins to query/enable/disable TPH support
* Makepcie_tph_set_st()completely independent frompcie_tph_get_cpu_st()
* Rewritebnxt.cbased on new APIs
* Remove documentation for now due to constantly changing API
* Remove pci=notph, but keep pci=nostmode with better flow (Bjorn)
* Lots of code rewrite intph.c&pci-tph.hwith cleaner interface (Bjorn)
* Add TPH save/restore support (Paul Luse and Lukas Wunner)
V2->V3:
* Rebase on top of pci/next tree (tag: pci-v6.11-changes)
* Redefine PCI TPH registers (pci_regs.h) without breaking uapi
* Fix commit subjects/messages for kernel options (Jonathan and Bjorn)
* Break API functions into three individual patches for easy review
* Rewrite lots of code intph.c/tph.hbased (Jonathan and Bjorn)
V1->V2:
* Rebase on top of pci.git/for-linus (6.10-rc1)
* Address mismatched data types reported by Sparse (Sparse check passed)
* Addpcie_tph_intr_vec_supported()for checking IRQ mode support
* Skip bnxt affinity notifier registration if pcie_tph_intr_vec_supported()=false
* Minor fixes in bnxt driver (i.e. warning messages)Manoj Panicker (1):
bnxt_en: Add TPH support in BNXT driverMichael Chan (1):
bnxt_en: Pass NQ ID to the FW when allocating RX/RX AGG ringsPaul Luse (1):
PCI/TPH: Add save/restore support for TPHWei Huang (9):
PCI: Introduce PCIe TPH support framework
PCI: Add TPH related register definition PCI/TPH: Addpcie_tph_modes()to query TPH modes PCI/TPH: Addpcie_enable_tph()to enable TPH PCI/TPH: Addpcie_disable_tph()to disable TPH PCI/TPH: Addpcie_tph_enabled()to check TPH state PCI/TPH: Addpcie_tph_set_st_entry()to set ST tag PCI/TPH: Addpcie_tph_get_cpu_st()to get ST tag PCI/TPH: Add pci=nostmode to force TPH No ST Mode.../admin-guide/kernel-parameters.txt | 3 + drivers/net/ethernet/broadcom/bnxt/bnxt.c | 86 ++- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 4 + drivers/pci/pci.c | 4 + drivers/pci/pci.h | 12 + drivers/pci/pcie/Kconfig | 11 + drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/tph.c | 563 ++++++++++++++++++ drivers/pci/probe.c | 1 + include/linux/pci-tph.h | 48 ++ include/linux/pci.h | 7 + include/uapi/linux/pci_regs.h | 38 +- 12 files changed, 768 insertions(+), 10 deletions(-)create mode 100644
drivers/pci/pcie/tph.c
create mode 100644include/linux/pci-tph.h
Quoted 9 lines · Wei Huang
Hi All,
TPH (TLP Processing Hints) is a PCIe feature that allows endpoint devices to provide optimization hints for requests that target memory space. These hints, in a format called steering tag (ST), are provided in the requester's TLP headers and allow the system hardware, including the Root Complex, to optimize the utilization of platform resources for the requests.
Quoted 6 lines
Upcoming AMD hardware implement a new Cache Injection feature that leverages TPH. Cache Injection allows PCIe endpoints to inject I/O Coherent DMA writes directly into an L2 within the CCX (core complex) closest to the CPU core that will consume it. This technology is aimed at applications requiring high performance and low latency, such as networking and storage applications.
Thanks for this example, it's a great intro. Suggest adding something similar to a patch commit log, since the cover letter is harder to find after this appears in git.
Quoted 10 lines
This series introduces generic TPH support in Linux, allowing STs to be retrieved and used by PCIe endpoint drivers as needed. As a demonstration, it includes an example usage in the Broadcom BNXT driver. When running on Broadcom NICs with the appropriate firmware, it shows substantial memory bandwidth savings and better network bandwidth using real-world benchmarks. This solution is vendor-neutral and implemented based on industry standards (PCIe Spec and PCI FW Spec).
V3->V4:
* Rebase on top of the latest pci/next tree (tag: 6.11-rc1)
No need to rebase to pci/next; pci/main is where it will be applied. But it currently applies cleanly to either, so no problem.
Quoted 4 lines
* Add new API functioins to query/enable/disable TPH support
* Makepcie_tph_set_st()completely independent frompcie_tph_get_cpu_st()
* Rewritebnxt.cbased on new APIs
* Remove documentation for now due to constantly changing API
I'd like to see this documentation included. And updated if the API changes, of course.
Quoted 1 line
* Remove pci=notph, but keep pci=nostmode with better flow (Bjorn)
This seems backward to me. I think "pci=notph" makes sense as a way to completely disable the TPH feature in case a user trips over a hardware or driver defect.
But "pci=nostmode" is advertised as a way to quantify the benefit of Steering Tags, and that seems like it's of interest to developers but not users.
So my advice would be to keep "pci=notph" and drop "pci=nostmode".
Bjorn
Quoted 17 lines · Bjorn Helgaas
Quoted 9 lines · Wei Huang
Hi All,
TPH (TLP Processing Hints) is a PCIe feature that allows endpoint devices to provide optimization hints for requests that target memory space. These hints, in a format called steering tag (ST), are provided in the requester's TLP headers and allow the system hardware, including the Root Complex, to optimize the utilization of platform resources for the requests.
Quoted 6 lines
Upcoming AMD hardware implement a new Cache Injection feature that leverages TPH. Cache Injection allows PCIe endpoints to inject I/O Coherent DMA writes directly into an L2 within the CCX (core complex) closest to the CPU core that will consume it. This technology is aimed at applications requiring high performance and low latency, such as networking and storage applications.
Quoted 3 lines
Thanks for this example, it's a great intro. Suggest adding something similar to a patch commit log, since the cover letter is harder to find after this appears in git.
I'll incorporate some of these descriptions into the TPH patches where relevant. Additionally, I'll enhance the commit log for bnxt.c (patch
11) with examples of the benefits.
Quoted 9 lines
Quoted 9 lines
This series introduces generic TPH support in Linux, allowing STs to be retrieved and used by PCIe endpoint drivers as needed. As a demonstration, it includes an example usage in the Broadcom BNXT driver. When running on Broadcom NICs with the appropriate firmware, it shows substantial memory bandwidth savings and better network bandwidth using real-world benchmarks. This solution is vendor-neutral and implemented based on industry standards (PCIe Spec and PCI FW Spec).
Quoted 5 lines
Quoted 2 lines
V3->V4:
* Rebase on top of the latest pci/next tree (tag: 6.11-rc1)No need to rebase to pci/next; pci/main is where it will be applied. But it currently applies cleanly to either, so no problem.
Got it, will rebase to pci/main in next spin anyway.
Quoted 8 lines
Quoted 5 lines
* Add new API functioins to query/enable/disable TPH support
* Makepcie_tph_set_st()completely independent frompcie_tph_get_cpu_st()
* Rewritebnxt.cbased on new APIs
* Remove documentation for now due to constantly changing APII'd like to see this documentation included. And updated if the API changes, of course.
Will do.
Quoted 7 lines
Quoted 2 lines
* Remove pci=notph, but keep pci=nostmode with better flow (Bjorn)
This seems backward to me. I think "pci=notph" makes sense as a way to completely disable the TPH feature in case a user trips over a hardware or driver defect.
Quoted 5 lines
But "pci=nostmode" is advertised as a way to quantify the benefit of Steering Tags, and that seems like it's of interest to developers but not users.
So my advice would be to keep "pci=notph" and drop "pci=nostmode".
OK, I will replace the "nostmode" patch with "notph" in V5.
Quoted 2 lines
Bjorn
Quoted 18 lines · Wei Huang
Quoted 17 lines · Bjorn Helgaas
Quoted 15 lines · Wei Huang
Hi All,
TPH (TLP Processing Hints) is a PCIe feature that allows endpoint devices to provide optimization hints for requests that target memory space. These hints, in a format called steering tag (ST), are provided in the requester's TLP headers and allow the system hardware, including the Root Complex, to optimize the utilization of platform resources for the requests.
Upcoming AMD hardware implement a new Cache Injection feature that leverages TPH. Cache Injection allows PCIe endpoints to inject I/O Coherent DMA writes directly into an L2 within the CCX (core complex) closest to the CPU core that will consume it. This technology is aimed at applications requiring high performance and low latency, such as networking and storage applications.
Quoted 7 lines
Quoted 3 lines
Thanks for this example, it's a great intro. Suggest adding something similar to a patch commit log, since the cover letter is harder to find after this appears in git.
I'll incorporate some of these descriptions into the TPH patches where relevant. Additionally, I'll enhance the commit log for
bnxt.c(patch
11) with examples of the benefits.
Sounds good.
Another confusing point that would be helpful to mention is that TPH includes two pieces: Processing Hints and Steering Tags.
As far as I can see, the only architected control of Processing Hints (bi-directional, requester, target, target w/ priority) is to enable/disable TPH or Extended TPH.
But we *do* have significant software control over the Steering Tags.
Quoted 12 lines · Wei Huang
Hi All,
TPH (TLP Processing Hints) is a PCIe feature that allows endpoint devices to provide optimization hints for requests that target memory space. These hints, in a format called steering tag (ST), are provided in the requester's TLP headers and allow the system hardware, including the Root Complex, to optimize the utilization of platform resources for the requests.
Paul Luse (1):
PCI/TPH: Add save/restore support for TPH
Quoted 10 lines
Wei Huang (9):
PCI: Introduce PCIe TPH support framework
PCI: Add TPH related register definition PCI/TPH: Addpcie_tph_modes()to query TPH modes PCI/TPH: Addpcie_enable_tph()to enable TPH PCI/TPH: Addpcie_disable_tph()to disable TPH PCI/TPH: Addpcie_tph_enabled()to check TPH state PCI/TPH: Addpcie_tph_set_st_entry()to set ST tag PCI/TPH: Addpcie_tph_get_cpu_st()to get ST tag PCI/TPH: Add pci=nostmode to force TPH No ST Mode
To me, this series would make more sense if we squashed these together:
PCI: Introduce PCIe TPH support framework
PCI: Add TPH related register definition
PCI/TPH: Add pcie_enable_tph() to enable TPH
PCI/TPH: Add pcie_disable_tph() to disable TPH
PCI/TPH: Add save/restore support for TPH
These would add the "minimum viable functionality", e.g., enable TPH just for Processing Hints, with no Steering Tag support at all. Would also include "pci=notph".
PCI/TPH: Add pcie_tph_set_st_entry() to set ST tag PCI/TPH: Add pcie_tph_get_cpu_st() to get ST tag
And squash these also to add Steering Tag support in a single commit, including enhancing the save/restore.
PCI/TPH: Add pcie_tph_modes() to query TPH modes PCI/TPH: Add pcie_tph_enabled() to check TPH state
And maybe we can get away without these altogether. I mentioned pcie_tph_modes() elsewhere; seems possibly unnecessary since drivers can just request the mode they want and we'll fail if it's not supported.
Drivers should also be able to remember whether they enabled TPH successfully without us having to remind them.
Quoted 9 lines · Bjorn Helgaas
To me, this series would make more sense if we squashed these together:
PCI: Introduce PCIe TPH support framework
PCI: Add TPH related register definition
PCI/TPH: Addpcie_enable_tph()to enable TPH
PCI/TPH: Addpcie_disable_tph()to disable TPH
PCI/TPH: Add save/restore support for TPH
Quoted 3 lines
These would add the "minimum viable functionality", e.g., enable TPH just for Processing Hints, with no Steering Tag support at all. Would also include "pci=notph".
Will do
Quoted 6 lines
PCI/TPH: Add
pcie_tph_set_st_entry()to set ST tag PCI/TPH: Addpcie_tph_get_cpu_st()to get ST tagAnd squash these also to add Steering Tag support in a single commit, including enhancing the save/restore.
Can you elaborate on save/restore enhancement? Assuming that the first combined patch will have save/restore support as suggested. Are you talking about the ST entries save/restore as the enhancements (see below), because the second combined patch deals with ST?
st_entry = (u16 *)cap;
offset = PCI_TPH_BASE_SIZEOF;
num_entries = get_st_table_size(pdev);
for (i = 0; i < num_entries; i++) {
pci_write_config_word(pdev, pdev->tph_cap + offset,
*st_entry++);
offset += sizeof(u16);
}Quoted 11 lines
PCI/TPH: Add
pcie_tph_modes()to query TPH modes PCI/TPH: Addpcie_tph_enabled()to check TPH stateAnd maybe we can get away without these altogether. I mentioned
pcie_tph_modes()elsewhere; seems possibly unnecessary since drivers can just request the mode they want and we'll fail if it's not supported.Drivers should also be able to remember whether they enabled TPH successfully without us having to remind them.
Quoted 25 lines · Wei Huang
Quoted 13 lines · Bjorn Helgaas
To me, this series would make more sense if we squashed these together:
PCI: Introduce PCIe TPH support framework
PCI: Add TPH related register definition
PCI/TPH: Addpcie_enable_tph()to enable TPH
PCI/TPH: Addpcie_disable_tph()to disable TPH
PCI/TPH: Add save/restore support for TPHThese would add the "minimum viable functionality", e.g., enable TPH just for Processing Hints, with no Steering Tag support at all. Would also include "pci=notph".
Quoted 5 lines
PCI/TPH: Add
pcie_tph_set_st_entry()to set ST tag PCI/TPH: Addpcie_tph_get_cpu_st()to get ST tagAnd squash these also to add Steering Tag support in a single commit, including enhancing the save/restore.
Can you elaborate on save/restore enhancement? Assuming that the first combined patch will have save/restore support as suggested. Are you talking about the ST entries save/restore as the enhancements (see below), because the second combined patch deals with ST?
Quoted 8 lines
st_entry = (u16 *)cap;
offset = PCI_TPH_BASE_SIZEOF;
num_entries = get_st_table_size(pdev);
for (i = 0; i < num_entries; i++) {
pci_write_config_word(pdev, pdev->tph_cap + offset,
*st_entry++);
offset += sizeof(u16);
}I meant that since the first patch knows nothing about ST, it would save/restore TPH control but not the ST entries.
The second patch would add ST support and also add save/restore of the ST entries.