1 /* Code to dump registers for NetXtreme-E/NetXtreme-C Broadcom devices.
2 *
3 * Copyright (c) 2020 Broadcom Inc.
4 */
5 #include <stdio.h>
6 #include "internal.h"
7
8 #define BNXT_PXP_REG_LEN 0x3110
9 #define BNXT_PCIE_STATS_LEN (12 * sizeof(u64))
10
11 struct bnxt_pcie_stat {
12 const char *name;
13 u16 offset;
14 u8 size;
15 const char *format;
16 };
17
18 static const struct bnxt_pcie_stat bnxt_pcie_stats[] = {
19 { .name = "PL Signal integrity errors", .offset = 0, .size = 4, .format = "%llu" },
20 { .name = "DL Signal integrity errors", .offset = 4, .size = 4, .format = "%llu" },
21 { .name = "TLP Signal integrity errors", .offset = 8, .size = 4, .format = "%llu" },
22 { .name = "Link integrity", .offset = 12, .size = 4, .format = "%llu" },
23 { .name = "TX TLP traffic rate", .offset = 16, .size = 4, .format = "%llu" },
24 { .name = "RX TLP traffic rate", .offset = 20, .size = 4, .format = "%llu" },
25 { .name = "TX DLLP traffic rate", .offset = 24, .size = 4, .format = "%llu" },
26 { .name = "RX DLLP traffic rate", .offset = 28, .size = 4, .format = "%llu" },
27 { .name = "Equalization Phase 0 time(ms)", .offset = 33, .size = 1, .format = "0x%x" },
28 { .name = "Equalization Phase 1 time(ms)", .offset = 32, .size = 1, .format = "0x%x" },
29 { .name = "Equalization Phase 2 time(ms)", .offset = 35, .size = 1, .format = "0x%x" },
30 { .name = "Equalization Phase 3 time(ms)", .offset = 34, .size = 1, .format = "0x%x" },
31 { .name = "PHY LTSSM Histogram 0", .offset = 36, .size = 2, .format = "0x%x"},
32 { .name = "PHY LTSSM Histogram 1", .offset = 38, .size = 2, .format = "0x%x"},
33 { .name = "PHY LTSSM Histogram 2", .offset = 40, .size = 2, .format = "0x%x"},
34 { .name = "PHY LTSSM Histogram 3", .offset = 42, .size = 2, .format = "0x%x"},
35 { .name = "Recovery Histogram 0", .offset = 44, .size = 2, .format = "0x%x"},
36 { .name = "Recovery Histogram 1", .offset = 46, .size = 2, .format = "0x%x"},
37 };
38
bnxt_dump_regs(struct ethtool_drvinfo * info __maybe_unused,struct ethtool_regs * regs)39 int bnxt_dump_regs(struct ethtool_drvinfo *info __maybe_unused, struct ethtool_regs *regs)
40 {
41 const struct bnxt_pcie_stat *stats = bnxt_pcie_stats;
42 u16 *pcie_stats, pcie_stat16;
43 u32 reg, i, pcie_stat32;
44 u64 pcie_stat64;
45
46 if (regs->len < BNXT_PXP_REG_LEN) {
47 fprintf(stdout, "Length too short, expected at least 0x%x\n",
48 BNXT_PXP_REG_LEN);
49 return -1;
50 }
51
52 fprintf(stdout, "PXP Registers\n");
53 fprintf(stdout, "Offset\tValue\n");
54 fprintf(stdout, "------\t-------\n");
55 for (i = 0; i < BNXT_PXP_REG_LEN; i += sizeof(reg)) {
56 memcpy(®, ®s->data[i], sizeof(reg));
57 if (reg)
58 fprintf(stdout, "0x%04x\t0x%08x\n", i, reg);
59 }
60 fprintf(stdout, "\n");
61
62 if (!regs->version)
63 return 0;
64
65 if (regs->len < (BNXT_PXP_REG_LEN + BNXT_PCIE_STATS_LEN)) {
66 fprintf(stdout, "Length is too short, expected 0x%zx\n",
67 BNXT_PXP_REG_LEN + BNXT_PCIE_STATS_LEN);
68 return -1;
69 }
70
71 pcie_stats = (u16 *)(regs->data + BNXT_PXP_REG_LEN);
72 fprintf(stdout, "PCIe statistics:\n");
73 fprintf(stdout, "----------------\n");
74 for (i = 0; i < ARRAY_SIZE(bnxt_pcie_stats); i++) {
75 fprintf(stdout, "%-30s : ", stats[i].name);
76 switch (stats[i].size) {
77 case 1:
78 pcie_stat16 = 0;
79 memcpy(&pcie_stat16, &pcie_stats[stats[i].offset], sizeof(u16));
80 fprintf(stdout, stats[i].format, pcie_stat16);
81 break;
82 case 2:
83 pcie_stat32 = 0;
84 memcpy(&pcie_stat32, &pcie_stats[stats[i].offset], sizeof(u32));
85 fprintf(stdout, stats[i].format, pcie_stat32);
86 break;
87 case 4:
88 pcie_stat64 = 0;
89 memcpy(&pcie_stat64, &pcie_stats[stats[i].offset], sizeof(u64));
90 fprintf(stdout, stats[i].format, pcie_stat64);
91 break;
92 }
93 fprintf(stdout, "\n");
94 }
95
96 return 0;
97 }
98