[dts][PATCH V1] tests/dsadev_common: add DSA device common API module
Wei Ling
weix.ling at intel.com
Fri Nov 11 08:22:41 CET 2022
Add DSA device common API module to provide some DSA related function.
Signed-off-by: Wei Ling <weix.ling at intel.com>
---
tests/dsadev_common.py | 133 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 133 insertions(+)
create mode 100644 tests/dsadev_common.py
diff --git a/tests/dsadev_common.py b/tests/dsadev_common.py
new file mode 100644
index 00000000..9e657d0b
--- /dev/null
+++ b/tests/dsadev_common.py
@@ -0,0 +1,133 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2022 Intel Corporation
+#
+
+import os
+import re
+
+
+class DsaDev_common(object):
+ def __init__(self, test_case):
+ self.test_case = test_case
+
+ def get_all_work_queue_index(self):
+ """
+ Get all DSA device work queue index.
+ Example: `wq0.0 wq0.1 wq1.0 wq1.1`, return [0, 1]
+ """
+ dsa_index_list = []
+ if os.path.exists("/dev/dsa"):
+ out = self.test_case.dut.send_expect("ls /dev/dsa", "# ")
+ info = out.split()
+ for item in info:
+ index = int(re.search("(\d+)", item).group(0))
+ dsa_index_list.append(index)
+ return list(set(dsa_index_list))
+
+ def reset_all_work_queue(self):
+ """
+ Reset all DSA device work queue which have created work queue.
+ After reset all DSA device work queues, the `/dev/dsa/` path will not exist.
+ """
+ dsa_index_list = self.get_all_work_queue_index()
+ if len(dsa_index_list) > 0:
+ for dsa_index in dsa_index_list:
+ self.test_case.dut.send_expect(
+ "./drivers/dma/idxd/dpdk_idxd_cfg.py --reset %s" % dsa_index, "# "
+ )
+
+ def check_dsa_has_work_queue(self, dsa_index):
+ """
+ Check DSA device has work queue or not, if has work queue, return True, or return False
+ """
+ if dsa_index in self.get_all_work_queue_index():
+ return True
+ else:
+ return False
+
+ def create_work_queue(self, work_queue_number, dsa_index):
+ """
+ Create work queue by work_queue_number and dsa_index.
+ :param work_queue_number: number of work queue to be create.
+ :param dsa_index: index of DSA device which to create work queue.
+ Example: work_queue_number=4, dsa_index=0, will create 4 work queue under this first DSA device
+ root at dpdk:~# ls /dev/dsa/
+ wq0.0 wq0.1 wq0.2 wq0.3
+ """
+ if self.check_dsa_has_work_queue(dsa_index=dsa_index):
+ self.test_case.dut.send_expect(
+ "./drivers/dma/idxd/dpdk_idxd_cfg.py --reset %s" % dsa_index, "# "
+ )
+ self.test_case.dut.send_expect(
+ "./drivers/dma/idxd/dpdk_idxd_cfg.py -q %d %d"
+ % (work_queue_number, dsa_index),
+ "# ",
+ )
+
+ def get_all_dsa_pci(self):
+ """
+ Get all the DSA device PCI of DUT.
+ :return: [0000:6a:01.0, 0000:6f:01.0, 0000:74:01.0, 0000:79:01.0, 0000:e7:01.0, 0000:ec:01.0, 0000:f1:01.0, 0000:f6:01.0]
+ """
+ dsa_pci = []
+ out = self.test_case.dut.send_expect(
+ "./usertools/dpdk-devbind.py --status-dev dma", "#"
+ )
+ info = out.split("\n")
+ for item in info:
+ pci = re.search("\s*(0000:\S*:\d*.\d*)", item)
+ if pci is not None:
+ dsa_pci.append(pci.group(1))
+ return dsa_pci
+
+ def bind_dsa_to_dpdk(self, dsa_number, driver_name, dsa_index_list="all"):
+ """
+ Bind DAS device to driver
+ :param dsa_number: number of DSA device to be bind.
+ :param driver_name: driver name, like `vfio-pci`.
+ :param dsa_index_list: the index list of DSA device, like [2,3]
+ :return: bind_dsa_list, like [0000:6a:01.0, 0000:6f:01.0]
+ """
+ if dsa_index_list == "all":
+ dsa_pci = self.get_all_dsa_pci()
+ else:
+ dsa_pci = []
+ all_dsa_pci = self.get_all_dsa_pci()
+ if len(all_dsa_pci) >= len(dsa_index_list):
+ for index in dsa_index_list:
+ dsa_pci.append(all_dsa_pci[index])
+ bind_dsa_list = dsa_pci[0:dsa_number]
+ bind_dsa_string = " ".join(bind_dsa_list)
+ self.test_case.dut.send_expect(
+ "./usertools/dpdk-devbind.py --force --bind=%s %s"
+ % (driver_name, bind_dsa_string),
+ "# ",
+ 60,
+ )
+ return bind_dsa_list
+
+ def bind_all_dsa_to_kernel(self):
+ """
+ Check the DSA device is bind to kernel driver or not, if not bind to kernel driver, then bind to kernel driver.
+ """
+ dsa_pci = self.get_all_dsa_pci()
+ for pci in dsa_pci:
+ addr_array = pci.split(":")
+ domain_id, bus_id, devfun_id = addr_array[0], addr_array[1], addr_array[2]
+ out = self.test_case.dut.send_expect(
+ "cat /sys/bus/pci/devices/%s\:%s\:%s/uevent"
+ % (domain_id, bus_id, devfun_id),
+ "# ",
+ alt_session=True,
+ )
+ rexp = r"DRIVER=(.+?)\r"
+ pattern = re.compile(rexp)
+ match = pattern.search(out)
+ if not match:
+ driver = None
+ else:
+ driver = match.group(1)
+ if driver != "idxd":
+ self.test_case.dut.send_expect(
+ "./usertools/dpdk-devbind.py --force --bind=idxd %s" % pci, "# ", 60
+ )
--
2.25.1
More information about the dts
mailing list