diff --git a/drivers/raw/ioat/dpdk_idxd_cfg.py b/drivers/raw/ioat/dpdk_idxd_cfg.py index ff06d9e240..ad8393a645 100755 --- a/drivers/raw/ioat/dpdk_idxd_cfg.py +++ b/drivers/raw/ioat/dpdk_idxd_cfg.py @@ -29,6 +29,26 @@ class SysfsDir: f.write(str(contents)) +def get_pci_dir(pci): + "Search for the sysfs directory of the PCI device" + base_dir = '/sys/bus/pci/devices/' + for path, dirs, files in os.walk(base_dir): + for dir in dirs: + if pci in dir: + return os.path.join(base_dir, dir) + sys.exit(f"Could not find sysfs directory for device {pci}") + + +def get_dsa_id(pci): + "Get the DSA instance ID using the PCI address of the device" + pci_dir = get_pci_dir(pci) + for path, dirs, files in os.walk(pci_dir): + for dir in dirs: + if dir.startswith('dsa') and 'wq' not in dir: + return int(dir[3:]) + sys.exit(f"Could not get device ID for device {pci}") + + def configure_dsa(dsa_id, queues, prefix): "Configure the DSA instance with appropriate number of queues" dsa_dir = SysfsDir(f"/sys/bus/dsa/devices/dsa{dsa_id}") @@ -68,14 +88,18 @@ def main(args): "Main function, does arg parsing and calls config function" arg_p = argparse.ArgumentParser( description="Configure whole DSA device instance for DPDK use") - arg_p.add_argument('dsa_id', type=int, help="DSA instance number") + arg_p.add_argument('dsa_id', + help="Specify DSA instance either via DSA instance number or PCI address") arg_p.add_argument('-q', metavar='queues', type=int, default=255, help="Number of queues to set up") arg_p.add_argument('--name-prefix', metavar='prefix', dest='prefix', default="dpdk", help="Prefix for workqueue name to mark for DPDK use [default: 'dpdk']") parsed_args = arg_p.parse_args(args[1:]) - configure_dsa(parsed_args.dsa_id, parsed_args.q, parsed_args.prefix) + + dsa_id = parsed_args.dsa_id + dsa_id = get_dsa_id(dsa_id) if ':' in dsa_id else dsa_id + configure_dsa(dsa_id, parsed_args.q, parsed_args.prefix) if __name__ == "__main__":