Skip to content

Commit e5321ae

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Store number of supported End-End TLP Prefixes
eetlp_prefix_path in the struct pci_dev tells if End-End TLP Prefixes are supported by the path or not, and the value is only calculated if CONFIG_PCI_PASID is set. The Max End-End TLP Prefixes field in the Device Capabilities Register 2 also tells how many (1-4) End-End TLP Prefixes are supported (PCIe r6.2 sec 7.5.3.15). The number of supported End-End Prefixes is useful for reading correct number of DWORDs from TLP Prefix Log register in AER capability (PCIe r6.2 sec 7.8.4.12). Replace eetlp_prefix_path with eetlp_prefix_max and determine the number of supported End-End Prefixes regardless of CONFIG_PCI_PASID so that an upcoming commit generalizing TLP Prefix Log register reading does not have to read extra DWORDs for End-End Prefixes that never will be there. The value stored into eetlp_prefix_max is directly derived from device's Max End-End TLP Prefixes and does not consider limitations imposed by bridges or the Root Port beyond supported/not supported flags. This is intentional for two reasons: 1) PCIe r6.2 spec sections 2.2.10.4 & 6.2.4.4 indicate that a TLP is malformed only if the number of prefixes exceed the number of Max End-End TLP Prefixes, which seems to be the case even if the device could never receive that many prefixes due to smaller maximum imposed by a bridge or the Root Port. If TLP parsing is later added, this distinction is significant in interpreting what is logged by the TLP Prefix Log registers and the value matching to the Malformed TLP threshold is going to be more useful. 2) TLP Prefix handling happens autonomously on a low layer and the value in eetlp_prefix_max is not programmed anywhere by the kernel (i.e., there is no limiter OS can control to prevent sending more than N TLP Prefixes). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Yazen Ghannam <[email protected]>
1 parent 27d4181 commit e5321ae

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

drivers/pci/ats.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ int pci_enable_pasid(struct pci_dev *pdev, int features)
410410
if (WARN_ON(pdev->pasid_enabled))
411411
return -EBUSY;
412412

413-
if (!pdev->eetlp_prefix_path && !pdev->pasid_no_tlp)
413+
if (!pdev->eetlp_prefix_max && !pdev->pasid_no_tlp)
414414
return -EINVAL;
415415

416416
if (!pasid)

drivers/pci/probe.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,8 +2251,8 @@ static void pci_configure_relaxed_ordering(struct pci_dev *dev)
22512251

22522252
static void pci_configure_eetlp_prefix(struct pci_dev *dev)
22532253
{
2254-
#ifdef CONFIG_PCI_PASID
22552254
struct pci_dev *bridge;
2255+
unsigned int eetlp_max;
22562256
int pcie_type;
22572257
u32 cap;
22582258

@@ -2264,15 +2264,19 @@ static void pci_configure_eetlp_prefix(struct pci_dev *dev)
22642264
return;
22652265

22662266
pcie_type = pci_pcie_type(dev);
2267+
2268+
eetlp_max = FIELD_GET(PCI_EXP_DEVCAP2_EE_PREFIX_MAX, cap);
2269+
/* 00b means 4 */
2270+
eetlp_max = eetlp_max ?: 4;
2271+
22672272
if (pcie_type == PCI_EXP_TYPE_ROOT_PORT ||
22682273
pcie_type == PCI_EXP_TYPE_RC_END)
2269-
dev->eetlp_prefix_path = 1;
2274+
dev->eetlp_prefix_max = eetlp_max;
22702275
else {
22712276
bridge = pci_upstream_bridge(dev);
2272-
if (bridge && bridge->eetlp_prefix_path)
2273-
dev->eetlp_prefix_path = 1;
2277+
if (bridge && bridge->eetlp_prefix_max)
2278+
dev->eetlp_prefix_max = eetlp_max;
22742279
}
2275-
#endif
22762280
}
22772281

22782282
static void pci_configure_serr(struct pci_dev *dev)

include/linux/pci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ struct pci_dev {
407407
supported from root to here */
408408
#endif
409409
unsigned int pasid_no_tlp:1; /* PASID works without TLP Prefix */
410-
unsigned int eetlp_prefix_path:1; /* End-to-End TLP Prefix */
410+
unsigned int eetlp_prefix_max:3; /* Max # of End-End TLP Prefixes, 0=not supported */
411411

412412
pci_channel_state_t error_state; /* Current connectivity state */
413413
struct device dev; /* Generic device interface */

include/uapi/linux/pci_regs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@
665665
#define PCI_EXP_DEVCAP2_OBFF_MSG 0x00040000 /* New message signaling */
666666
#define PCI_EXP_DEVCAP2_OBFF_WAKE 0x00080000 /* Re-use WAKE# for OBFF */
667667
#define PCI_EXP_DEVCAP2_EE_PREFIX 0x00200000 /* End-End TLP Prefix */
668+
#define PCI_EXP_DEVCAP2_EE_PREFIX_MAX 0x00c00000 /* Max End-End TLP Prefixes */
668669
#define PCI_EXP_DEVCTL2 0x28 /* Device Control 2 */
669670
#define PCI_EXP_DEVCTL2_COMP_TIMEOUT 0x000f /* Completion Timeout Value */
670671
#define PCI_EXP_DEVCTL2_COMP_TMOUT_DIS 0x0010 /* Completion Timeout Disable */

0 commit comments

Comments
 (0)