Device Abstraction

A PCIe device wrapper for Linux PCIe devices.

class bakeneko.support.sys_dev.PCIDevice(slot: str, vendor: int | str, device: int | str)

A simple abstraction around PCI(e) devices on Linux.

Attributes:
  • slot (str) – The device slot.

  • node (Path) – The full sys path to the device node

  • vendor (int) – Device Vendor ID

  • device (int) – Device ID

Parameters:
  • slot (str) – Device Slot

  • vendor (int) – Vendor ID

  • device (int) – Device ID

static enumerate() list[PCIDevice]

Get a list of PCI(e) devices attached to the system

Returns:

All found PCI(e) devices

Return type:

list[PCIDevice]

static get(slot: str) PCIDevice | None

Get a PCIDevice from the give device/slot IDs.

Parameters:

slot (str) – The slot ID to use

Return type:

PCIDevice | None

Returns:

  • PCIDevice – The PCI(e) device, if found.

  • None – Otherwise

static from_path(path: Path) PCIDevice

Construct a PCIDevice from a device node path

Parameters:

path (Path) – The device node path in the /sys/bus/pci/devices tree.

Returns:

A new PCI(e) device wrapper

Return type:

PCIDevice

static enumerate_remote(conn: Connection) list[PCIDevice]

Get a list of PCI(e) devices attached to the remote system

Parameters:

conn (fabric.Connection) – The connection to use.

Returns:

All found PCI(e) devices

Return type:

list[PCIDevice]

static get_remote(slot: str, conn: Connection) PCIDevice | None

Get a PCIDevice from the give device/slot ID on the remote system.

Parameters:
  • slot (str) – The slot ID to get.

  • conn (fabric.Connection) – The connection to use.

Return type:

PCIDevice | None

Returns:

  • PCIDevice – The PCI(e) device, if found.

  • None – Otherwise

static from_remote_path(path: Path, conn: Connection) PCIDevice

Construct a PCIDevice from a device node path

Parameters:
  • path (Path) – The device node path in the /sys/bus/pci/devices tree.

  • conn (fabric.Connection) – The connection to use.

Returns:

A new PCI(e) device wrapper

Return type:

PCIDevice

set_speed(speed: LinkSpeed) bool

Set the device link speed.

Note

This only works on PCIe gen2 or newer devices, as the LC2 register is not specified in PCIe v1 which makes sense, as in PCIe v1 there was only one speed.

Parameters:

speed (LinkSpeed) – The target device speed

Returns:

True if speed was able to be set and get_speed reads it back, otherwise False

Return type:

bool

get_capability(cap: str, port: bool = False) str | None

Use setpci to read a PCI device register and return the value.

Parameters:
  • cap (str) – The setpci capability/register to read.

  • port (bool) – If this capability request is direct at the port, rather than the slot. (default: False) (default: False)

Return type:

str | None

Returns:

  • str – The result from the setpci -s call on success.

  • None – Otherwise None

Try to force the device to re-train the link

Return type:

bool

Get the link status

Get the link capabilities

property max_speed: LinkSpeed

Get the maximum link speed this PCIe device supports.

property max_width: LinkWidth

Get the maximum link width this PCIe device supports.

Speed of the currently active PCIe link for this device.

Width of the currently active PCIe link for this device.

recycle() bool

Remove this PCI(e) device, and then force a bus re-scan to try to bring it back.

Returns:

True if the device came back after a re-scan, otherwise False

Return type:

bool

reset() None

Soft-reset this device

Return type:

None