Skip to content

Commit f68ea77

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Add pcie_print_tlp_log() to print TLP Header and Prefix Log
Add pcie_print_tlp_log() to print TLP Header and Prefix Log. Print End-End Prefixes only if they are non-zero. Consolidate the few places which currently print TLP using custom formatting. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> [bhelgaas: commit log] Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]>
1 parent ad41dde commit f68ea77

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

drivers/pci/pci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
553553
int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2,
554554
unsigned int tlp_len, struct pcie_tlp_log *log);
555555
unsigned int aer_tlp_log_len(struct pci_dev *dev, u32 aercc);
556+
void pcie_print_tlp_log(const struct pci_dev *dev,
557+
const struct pcie_tlp_log *log, const char *pfx);
556558
#endif /* CONFIG_PCIEAER */
557559

558560
#ifdef CONFIG_PCIEPORTBUS

drivers/pci/pcie/aer.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,6 @@ static void pci_rootport_aer_stats_incr(struct pci_dev *pdev,
665665
}
666666
}
667667

668-
static void __print_tlp_header(struct pci_dev *dev, struct pcie_tlp_log *t)
669-
{
670-
pci_err(dev, " TLP Header: %08x %08x %08x %08x\n",
671-
t->dw[0], t->dw[1], t->dw[2], t->dw[3]);
672-
}
673-
674668
static void __aer_print_error(struct pci_dev *dev,
675669
struct aer_err_info *info)
676670
{
@@ -725,7 +719,7 @@ void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
725719
__aer_print_error(dev, info);
726720

727721
if (info->tlp_header_valid)
728-
__print_tlp_header(dev, &info->tlp);
722+
pcie_print_tlp_log(dev, &info->tlp, dev_fmt(" "));
729723

730724
out:
731725
if (info->id && info->error_dev_num > 1 && info->id == id)
@@ -797,7 +791,7 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity,
797791
aer->uncor_severity);
798792

799793
if (tlp_header_valid)
800-
__print_tlp_header(dev, &aer->header_log);
794+
pcie_print_tlp_log(dev, &aer->header_log, dev_fmt(" "));
801795

802796
trace_aer_event(dev_name(&dev->dev), (status & ~mask),
803797
aer_severity, tlp_header_valid, &aer->header_log);

drivers/pci/pcie/dpc.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ static void dpc_process_rp_pio_error(struct pci_dev *pdev)
220220
pcie_read_tlp_log(pdev, cap + PCI_EXP_DPC_RP_PIO_HEADER_LOG,
221221
cap + PCI_EXP_DPC_RP_PIO_TLPPREFIX_LOG,
222222
dpc_tlp_log_len(pdev), &tlp_log);
223-
pci_err(pdev, "TLP Header: %#010x %#010x %#010x %#010x\n",
224-
tlp_log.dw[0], tlp_log.dw[1], tlp_log.dw[2], tlp_log.dw[3]);
225-
for (i = 0; i < pdev->dpc_rp_log_size - PCIE_STD_NUM_TLP_HEADERLOG - 1; i++)
226-
pci_err(pdev, "TLP Prefix Header: dw%d, %#010x\n", i, tlp_log.prefix[i]);
223+
pcie_print_tlp_log(pdev, &tlp_log, dev_fmt(""));
227224

228225
if (pdev->dpc_rp_log_size < PCIE_STD_NUM_TLP_HEADERLOG + 1)
229226
goto clear_status;

drivers/pci/pcie/tlp.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <linux/aer.h>
9+
#include <linux/array_size.h>
910
#include <linux/pci.h>
1011
#include <linux/string.h>
1112

@@ -79,3 +80,36 @@ int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2,
7980

8081
return 0;
8182
}
83+
84+
#define EE_PREFIX_STR " E-E Prefixes:"
85+
86+
/**
87+
* pcie_print_tlp_log - Print TLP Header / Prefix Log contents
88+
* @dev: PCIe device
89+
* @log: TLP Log structure
90+
* @pfx: String prefix
91+
*
92+
* Prints TLP Header and Prefix Log information held by @log.
93+
*/
94+
void pcie_print_tlp_log(const struct pci_dev *dev,
95+
const struct pcie_tlp_log *log, const char *pfx)
96+
{
97+
char buf[11 * (PCIE_STD_NUM_TLP_HEADERLOG + ARRAY_SIZE(log->prefix)) +
98+
sizeof(EE_PREFIX_STR)];
99+
unsigned int i;
100+
int len;
101+
102+
len = scnprintf(buf, sizeof(buf), "%#010x %#010x %#010x %#010x",
103+
log->dw[0], log->dw[1], log->dw[2], log->dw[3]);
104+
105+
if (log->prefix[0])
106+
len += scnprintf(buf + len, sizeof(buf) - len, EE_PREFIX_STR);
107+
for (i = 0; i < ARRAY_SIZE(log->prefix); i++) {
108+
if (!log->prefix[i])
109+
break;
110+
len += scnprintf(buf + len, sizeof(buf) - len,
111+
" %#010x", log->prefix[i]);
112+
}
113+
114+
pci_err(dev, "%sTLP Header: %s\n", pfx, buf);
115+
}

0 commit comments

Comments
 (0)