This enables GEN4 link speed (16GT/s) property to be fetched properly and thus
allows the detach/reattach/dumpxml to work.

Signed-off-by: Shivaprasad G Bhat <[email protected]>
---
Verified on Mellanox MT27800 Family ConnectX-5 IB card.
# lspci -kvvvs 0001:01:00.4
0001:01:00.4 Infiniband controller: Mellanox Technologies MT27800 Family 
[ConnectX-5 Virtual Function]
        Subsystem: IBM MT28800 Family [ConnectX-5 Virtual Function]
        Control: I/O- Mem- BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- 
Stepping- SERR- FastB2B- DisINTx-
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- 
<MAbort- >SERR- <PERR- INTx-
        Latency: 0
        Region 0: [virtual] Memory at 21000e000000 (64-bit, prefetchable) 
[size=32M]
        Capabilities: [60] Express (v2) Endpoint, MSI 00
                DevCap: MaxPayload 512 bytes, PhantFunc 0, Latency L0s 
unlimited, L1 unlimited
                        ExtTag+ AttnBtn- AttnInd- PwrInd- RBE+ FLReset+
                DevCtl: Report errors: Correctable- Non-Fatal- Fatal- 
Unsupported-
                        RlxdOrd- ExtTag- PhantFunc- AuxPwr- NoSnoop- FLReset-
                        MaxPayload 128 bytes, MaxReadReq 128 bytes
                DevSta: CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr- 
TransPend-
                LnkCap: Port #0, Speed 16GT/s, Width x16, ASPM not supported, 
Exit Latency L0s unlimited, L1 unlimited
                        ClockPM- Surprise- LLActRep- BwNot- ASPMOptComp+
                LnkCtl: ASPM Disabled; RCB 64 bytes Disabled- CommClk-
                        ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
                LnkSta: Speed unknown, Width x0, TrErr- Train- SlotClk- 
DLActive- BWMgmt- ABWMgmt-
                DevCap2: Completion Timeout: Range ABCD, TimeoutDis+, LTR-, 
OBFF Not Supported
                DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR-, 
OBFF Disabled
                LnkSta2: Current De-emphasis Level: -6dB, 
EqualizationComplete-, EqualizationPhase1-
                         EqualizationPhase2-, EqualizationPhase3-, 
LinkEqualizationRequest-
        Capabilities: [48] Vital Product Data
                Product Name: PCIe4 2-port 100Gb EDR Adapter x16
                Read-only fields:
                        [PN] Part number: 00WT174
                        [EC] Engineering changes: P40094
                        [VF] Vendor specific: 00WT176
                        [SN] Serial number: YA50YF6AL00B
                        [Z0] Unknown: 49 42 4d 30 30 30 30 30 30 30 30 30 32
                        [VC] Vendor specific: EC64
                        [MN] Manufacture ID: 36 34 31 58 34 38 31 31 37 34 30 
30 33 34 20
                        [VH] Vendor specific: 2CF2
                        [VK] Vendor specific: ipzSeries
                        [RV] Reserved: checksum good, 0 byte(s) reserved
                End
        Capabilities: [9c] MSI-X: Enable+ Count=12 Masked-
                Vector table: BAR=0 offset=00002000
                PBA: BAR=0 offset=00003000
        Kernel driver in use: mlx5_core
        Kernel modules: mlx5_core

Before fix :
# virsh  nodedev-dumpxml  pci_0001_01_00_4
<device>
  <name>pci_0001_01_00_4</name>
  <path>/sys/devices/pci0001:00/0001:00:00.0/0001:01:00.4</path>
  <parent>pci_0001_00_00_0</parent>
  <driver>
    <name>vfio-pci</name>
  </driver>
  <capability type='pci'>
    <domain>1</domain>
    <bus>1</bus>
    <slot>0</slot>
    <function>4</function>
    <product id='0x1018'>MT27800 Family [ConnectX-5 Virtual Function]</product>
    <vendor id='0x15b3'>Mellanox Technologies</vendor>
    <capability type='phys_function'>
      <address domain='0x0001' bus='0x01' slot='0x00' function='0x0'/>
    </capability>
    <iommuGroup number='10'>
      <address domain='0x0001' bus='0x01' slot='0x00' function='0x4'/>
    </iommuGroup>
    <numa node='0'/>
    <pci-express>
      <link validity='cap' port='0' speed='(null)' width='16'/>
      <link validity='sta' width='0'/>
    </pci-express>
  </capability>
</device>
# virsh  nodedev-detach  pci_0001_01_00_4
error: Failed to detach device pci_0001_01_00_4
error: malformed 'speed' attribute: (null)

After Fix:
# ./run tools/virsh  nodedev-dumpxml  pci_0001_01_00_4
<device>
  <name>pci_0001_01_00_4</name>
  <path>/sys/devices/pci0001:00/0001:00:00.0/0001:01:00.4</path>
  <parent>pci_0001_00_00_0</parent>
  <driver>
    <name>mlx5_core</name>
  </driver>
  <capability type='pci'>
    <domain>1</domain>
    <bus>1</bus>
    <slot>0</slot>
    <function>4</function>
    <product id='0x1018'>MT27800 Family [ConnectX-5 Virtual Function]</product>
    <vendor id='0x15b3'>Mellanox Technologies</vendor>
    <capability type='phys_function'>
      <address domain='0x0001' bus='0x01' slot='0x00' function='0x0'/>
    </capability>
    <iommuGroup number='10'>
      <address domain='0x0001' bus='0x01' slot='0x00' function='0x4'/>
    </iommuGroup>
    <numa node='0'/>
    <pci-express>
      <link validity='cap' port='0' speed='16' width='16'/>
      <link validity='sta' width='0'/>
    </pci-express>
  </capability>
</device>

# ./run tools/virsh  nodedev-detach  pci_0001_01_00_4
Device pci_0001_01_00_4 detached
---
 src/util/virpci.c |    4 ++--
 src/util/virpci.h |    1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index 3c1e13b..1e0d903 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -53,7 +53,7 @@ VIR_LOG_INIT("util.pci");
 #define PCI_ADDR_LEN 13 /* "XXXX:XX:XX.X" */
 
 VIR_ENUM_IMPL(virPCIELinkSpeed, VIR_PCIE_LINK_SPEED_LAST,
-              "", "2.5", "5", "8")
+              "", "2.5", "5", "8", "16")
 
 VIR_ENUM_IMPL(virPCIStubDriver, VIR_PCI_STUB_DRIVER_LAST,
               "none",
@@ -147,7 +147,7 @@ struct _virPCIDeviceList {
 #define PCI_EXP_DEVCAP          0x4     /* Device capabilities */
 #define PCI_EXP_DEVCAP_FLR     (1<<28)  /* Function Level Reset */
 #define PCI_EXP_LNKCAP          0xc     /* Link Capabilities */
-#define PCI_EXP_LNKCAP_SPEED    0x0000f /* Maximum Link Speed */
+#define PCI_EXP_LNKCAP_SPEED    0x0001f /* Maximum Link Speed */
 #define PCI_EXP_LNKCAP_WIDTH    0x003f0 /* Maximum Link Width */
 #define PCI_EXP_LNKSTA          0x12    /* Link Status */
 #define PCI_EXP_LNKSTA_SPEED    0x000f  /* Negotiated Link Speed */
diff --git a/src/util/virpci.h b/src/util/virpci.h
index a5e8d00..50e8b3c 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -58,6 +58,7 @@ typedef enum {
     VIR_PCIE_LINK_SPEED_25,
     VIR_PCIE_LINK_SPEED_5,
     VIR_PCIE_LINK_SPEED_8,
+    VIR_PCIE_LINK_SPEED_16,
     VIR_PCIE_LINK_SPEED_LAST
 } virPCIELinkSpeed;
 

--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to