From 54f9e5713d5595564ac2bb1fbe6703f08a6dbb35 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 16 Apr 2023 17:26:14 +0000 Subject: [PATCH] Fix (and simplify) link speed reporting. ok jsg@ --- usr.sbin/pcidump/pcidump.c | 40 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/usr.sbin/pcidump/pcidump.c b/usr.sbin/pcidump/pcidump.c index 3148a8732ee..e5df1ef709f 100644 --- a/usr.sbin/pcidump/pcidump.c +++ b/usr.sbin/pcidump/pcidump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcidump.c,v 1.68 2021/10/25 19:54:29 kn Exp $ */ +/* $OpenBSD: pcidump.c,v 1.69 2023/04/16 17:26:14 kettenis Exp $ */ /* * Copyright (c) 2006, 2007 David Gwynne @@ -528,11 +528,17 @@ pcie_dcsr_mrrs(uint32_t dcsr) void print_pcie_ls(uint8_t speed) { - if (speed & 4) + if (speed == 6) + printf("64.0"); + else if (speed == 5) + printf("32.0"); + else if (speed == 4) + printf("16.0"); + else if (speed == 3) printf("8.0"); - else if (speed & 2) + else if (speed == 2) printf("5.0"); - else if (speed & 1) + else if (speed == 1) printf("2.5"); else printf("unknown (%d)", speed); @@ -542,7 +548,7 @@ void dump_pcie_linkspeed(int bus, int dev, int func, uint8_t ptr) { u_int32_t dcap, dcsr; - u_int32_t lcap, sreg, lcap2 = 0, xcap; + u_int32_t lcap, lcsr; u_int8_t cwidth, cspeed, swidth, sspeed; if (pci_read(bus, dev, func, ptr + PCI_PCIE_DCAP, &dcap) != 0) @@ -556,31 +562,17 @@ dump_pcie_linkspeed(int bus, int dev, int func, uint8_t ptr) printf("\t\tMax Read Request Size: %u bytes\n", pcie_dcsr_mrrs(dcsr)); - if (pci_read(bus, dev, func, ptr + PCI_PCIE_XCAP, &xcap) != 0) - return; - - if (PCI_PCIE_XCAP_VER(xcap) >= 2) { - if (pci_read(bus, dev, func, ptr + PCI_PCIE_LCAP2, &lcap2) != 0) - lcap2 = 0; - else - cspeed = (lcap2 & 0x0e) >> 1; - } - if (pci_read(bus, dev, func, ptr + PCI_PCIE_LCAP, &lcap) != 0) return; - if (lcap2 == 0) - cspeed = lcap & 0x0f; - - if (pci_read(bus, dev, func, ptr + PCI_PCIE_LCSR, &sreg) != 0) - return; - sreg = sreg >> 16; - + cspeed = lcap & 0x0f; cwidth = (lcap >> 4) & 0x3f; if (cwidth == 0) return; - swidth = (sreg >> 4) & 0x3f; - sspeed = sreg & 0x0f; + if (pci_read(bus, dev, func, ptr + PCI_PCIE_LCSR, &lcsr) != 0) + return; + sspeed = (lcsr >> 16) & 0x0f; + swidth = (lcsr >> 20) & 0x3f; printf("\t\tLink Speed: "); print_pcie_ls(sspeed); -- 2.20.1