]> git.ipfire.org Git - thirdparty/pciutils.git/commitdiff
lspci: Report if the PCIe link speed/width is full or downgraded
authorMartin Mares <mj@ucw.cz>
Fri, 16 Mar 2018 16:53:42 +0000 (17:53 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 16 Mar 2018 16:53:42 +0000 (17:53 +0100)
Based on an idea by Dmitry Monakhov.

ls-caps.c

index 158ac38f864291723c02366e0d01f473dde98c6f..e74d13a8bac20b5d846076e7d7bf73ce6b1aee72 100644 (file)
--- a/ls-caps.c
+++ b/ls-caps.c
@@ -1,7 +1,7 @@
 /*
  *     The PCI Utilities -- Show Capabilities
  *
- *     Copyright (c) 1997--2010 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 1997--2018 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -733,6 +733,15 @@ static char *link_speed(int speed)
     }
 }
 
+static char *link_compare(int sta, int cap)
+{
+  if (sta < cap)
+    return "downgraded";
+  if (sta > cap)
+    return "strange";
+  return "ok";
+}
+
 static char *aspm_support(int code)
 {
   switch (code)
@@ -758,14 +767,16 @@ static const char *aspm_enabled(int code)
 
 static void cap_express_link(struct device *d, int where, int type)
 {
-  u32 t, aspm;
+  u32 t, aspm, cap_speed, cap_width, sta_speed, sta_width;
   u16 w;
 
   t = get_conf_long(d, where + PCI_EXP_LNKCAP);
   aspm = (t & PCI_EXP_LNKCAP_ASPM) >> 10;
+  cap_speed = t & PCI_EXP_LNKCAP_SPEED;
+  cap_width = (t & PCI_EXP_LNKCAP_WIDTH) >> 4;
   printf("\t\tLnkCap:\tPort #%d, Speed %s, Width x%d, ASPM %s",
        t >> 24,
-       link_speed(t & PCI_EXP_LNKCAP_SPEED), (t & PCI_EXP_LNKCAP_WIDTH) >> 4,
+       link_speed(cap_speed), cap_width,
        aspm_support(aspm));
   if (aspm)
     {
@@ -799,9 +810,14 @@ static void cap_express_link(struct device *d, int where, int type)
        FLAG(w, PCI_EXP_LNKCTL_AUTBWIE));
 
   w = get_conf_word(d, where + PCI_EXP_LNKSTA);
-  printf("\t\tLnkSta:\tSpeed %s, Width x%d, TrErr%c Train%c SlotClk%c DLActive%c BWMgmt%c ABWMgmt%c\n",
-       link_speed(w & PCI_EXP_LNKSTA_SPEED),
-       (w & PCI_EXP_LNKSTA_WIDTH) >> 4,
+  sta_speed = w & PCI_EXP_LNKSTA_SPEED;
+  sta_width = (w & PCI_EXP_LNKSTA_WIDTH) >> 4;
+  printf("\t\tLnkSta:\tSpeed %s (%s), Width x%d (%s)\n",
+       link_speed(sta_speed),
+       link_compare(sta_speed, cap_speed),
+       sta_width,
+       link_compare(sta_width, cap_width));
+  printf("\t\t\tTrErr%c Train%c SlotClk%c DLActive%c BWMgmt%c ABWMgmt%c\n",
        FLAG(w, PCI_EXP_LNKSTA_TR_ERR),
        FLAG(w, PCI_EXP_LNKSTA_TRAIN),
        FLAG(w, PCI_EXP_LNKSTA_SL_CLK),