vlib: add format pci link port

Added a function to nicely format pci link ports. Similar to the existing
link_speed etc format functions.

Type: improvement

Signed-off-by: Ray Kinsella <mdr@ashroe.eu>
Change-Id: Ic1f104e0cb34dad274f6c959e776a32c0bab697d
diff --git a/src/vlib/pci/pci.c b/src/vlib/pci/pci.c
index 1c1f4b6..18d93ac 100644
--- a/src/vlib/pci/pci.c
+++ b/src/vlib/pci/pci.c
@@ -143,6 +143,19 @@
 }
 
 u8 *
+format_vlib_pci_link_port (u8 *s, va_list *va)
+{
+  vlib_pci_device_info_t *d = va_arg (*va, vlib_pci_device_info_t *);
+  pcie_config_regs_t *r =
+    pci_config_find_capability (&d->config0, PCI_CAP_ID_PCIE);
+
+  if (!r)
+    return format (s, "unknown");
+
+  return format (s, "P%d", r->link_status >> 24);
+}
+
+u8 *
 format_vlib_pci_link_speed (u8 * s, va_list * va)
 {
   vlib_pci_device_info_t *d = va_arg (*va, vlib_pci_device_info_t *);