From patchwork Fri Nov 11 07:22:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ling, WeiX" X-Patchwork-Id: 119771 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 54BB3A0542; Fri, 11 Nov 2022 08:30:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4E91C40141; Fri, 11 Nov 2022 08:30:01 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id D6DE5400EF for ; Fri, 11 Nov 2022 08:29:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668151800; x=1699687800; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Awb26a/pdbvq0iYZfj3OmHgxJnosgkFR1NX0mOb01lg=; b=Lams1ThJghmwg5QKCI0WTfCFKF56SochZ6xtjNJiVJXJa7Ile7NuxLWy wyWVBQBWuUcjwOwPdA6EkBU3ZxFKYZLGp+DFYrJx+eoJ03vG8Qer4bnfE QwouYO0PIoqcZDOxLGU6s17uR240vGt6cHcJG8rns+PSmT7bD6k1R3u94 2q0ctwCZNU3bkFFnTqmNKL1sx1qekcU+6aRvQGVMxn26vabyUeVUH56cC pqSiPsMK65QvhkQYHlq+AwvNe+FFnvGrCKNhMn7unKVGh3tuEsvu3sTi/ 2GJppbJVeEuzYrwgElnlC8EVeYthS25XMAKdRDWgQxqanz0vYxjtd1XJf w==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="375806982" X-IronPort-AV: E=Sophos;i="5.96,156,1665471600"; d="scan'208";a="375806982" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 23:29:46 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="882676934" X-IronPort-AV: E=Sophos;i="5.96,156,1665471600"; d="scan'208";a="882676934" Received: from unknown (HELO localhost.localdomain) ([10.239.252.222]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 23:29:21 -0800 From: Wei Ling To: dts@dpdk.org Cc: Wei Ling Subject: [dts][PATCH V1] tests/dsadev_common: add DSA device common API module Date: Fri, 11 Nov 2022 15:22:41 +0800 Message-Id: <20221111072241.2424148-1-weix.ling@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Add DSA device common API module to provide some DSA related function. Signed-off-by: Wei Ling --- 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@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 + )