def express_link()

in pci_lib/pci_lib.py [0:0]


    def express_link(self):
        """
        Retrieve the PCI-Express link status.

        Returns None if this is not a PCIe device, otherwise returns a
        PCIExpressLink
        """

        with closing(PCIConfigSpace.get(self.device_name)) as config:
            express = find_capability(config, PCI_CAP_EXPRESS)
            if express is None:
                return None
            flags = read_u16(config, express + PCI_CAP_FLAGS)
            exptype = EXPRESS_TYPES.get((flags & 0xf0) >> 4)
            if exptype is None:
                return None
            if exptype not in ['root_complex_endpoint',
                               'root_complex_event_collector']:
                lnksta = read_u16(config, express + PCI_EXP_LNKSTA)
                lnkcap = read_u16(config, express + PCI_EXP_LNKCAP)
                lnkctl2 = None
                if self.express_cap_version >= 2:
                    lnkctl2 = read_u16(config, express + PCI_EXP_LNKCTL2)

                cur_speed = EXPRESS_SPEED.get(lnksta & 0xf, 'unknown')
                cur_width = ((lnksta & 0x3f0) >> 4)
                capable_speed = EXPRESS_SPEED.get(lnkcap & 0xf, 'unknown')
                capable_width = ((lnkcap & 0x3f0) >> 4)
                target_speed = None
                if lnkctl2 is not None:
                    target_speed = EXPRESS_SPEED.get(lnkctl2 & 0xf, None)

                return PCIExpressLink(cur_speed, cur_width,
                                      capable_speed, capable_width, target_speed)