From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93FEAD6B6CE for ; Wed, 30 Oct 2024 19:36:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4B61110E7F7; Wed, 30 Oct 2024 19:36:46 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="h4TX26fe"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id AF78E10E7F7 for ; Wed, 30 Oct 2024 19:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730317005; x=1761853005; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UIvaiT7A3kmMOoYI36yl6zKncc8ZhV8DvRKO9Erjg6U=; b=h4TX26feZCeGc6QHqsq3z2cuxOwgAtYMGIDepvxsx78qssvU52xWZCIl BeRz2TdLLme8gW7hdMT+cRhYnLg/E2Z6kHYQa2kfnQj4e5Ii2gOreeIcc wwAjyNGUtHxqE2yei3GOlnpMolktsuWi5VbMvxPgJl4lA8Ncq7ZF2h/3V a23aNCDOhqT2z1mvWMRQZOETwX9bHMnqDdqYHq1AG/8cS5hPsloSUQUKk PO0SsQZRdKSVnZsL1HrwRoW8yiXsgZJ5iHtUyLG6QuZCJ4Y1XpGBkjjaC iBZID7bJxBGDDz1ODxUXSP2JLWfHXSHOEsdVZxCqFTE0Lq3w6+m20Tu46 g==; X-CSE-ConnectionGUID: Im7FNjgaTHq2JPxYBFCSsA== X-CSE-MsgGUID: GekT3FybTcWWS5cuGQ4yfA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47499956" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47499956" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2024 12:36:45 -0700 X-CSE-ConnectionGUID: JpzqxSPSS3GYfoQArRWuBw== X-CSE-MsgGUID: 6oXWXvBDRWyoUs72iy1ugg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,245,1725346800"; d="scan'208";a="82578430" Received: from mbernato-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.84.149]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2024 12:36:42 -0700 From: Marcin Bernatowicz To: igt-dev@lists.freedesktop.org Cc: adam.miszczak@linux.intel.com, jakub1.kolakowski@intel.com, lukasz.laguna@intel.com, michal.wajdeczko@intel.com, michal.winiarski@intel.com, narasimha.c.v@intel.com, piotr.piorkowski@intel.com, satyanarayana.k.v.p@intel.com, tomasz.lis@intel.com, Marcin Bernatowicz Subject: [PATCH i-g-t 1/5] lib/xe_sriov_debugfs: add helper for opening attributes Date: Wed, 30 Oct 2024 20:36:25 +0100 Message-Id: <20241030193629.1238637-2-marcin.bernatowicz@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20241030193629.1238637-1-marcin.bernatowicz@linux.intel.com> References: <20241030193629.1238637-1-marcin.bernatowicz@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" From: Lukasz Laguna Helper allows to open SR-IOV debugfs attributes corresponding to specified PF device, VF number and GT number. Signed-off-by: Lukasz Laguna Signed-off-by: Marcin Bernatowicz Cc: Adam Miszczak Cc: Jakub Kolakowski Cc: Michał Wajdeczko Cc: Michał Winiarski Cc: Narasimha C V Cc: Piotr Piórkowski Cc: Satyanarayana K V P Cc: Tomasz Lis --- lib/meson.build | 1 + lib/xe/xe_sriov_debugfs.c | 69 +++++++++++++++++++++++++++++++++++++++ lib/xe/xe_sriov_debugfs.h | 14 ++++++++ 3 files changed, 84 insertions(+) create mode 100644 lib/xe/xe_sriov_debugfs.c create mode 100644 lib/xe/xe_sriov_debugfs.h diff --git a/lib/meson.build b/lib/meson.build index c3556a921..3d5d68b75 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -116,6 +116,7 @@ lib_sources = [ 'xe/xe_mmio.c', 'xe/xe_query.c', 'xe/xe_spin.c', + 'xe/xe_sriov_debugfs.c', 'xe/xe_util.c', ] diff --git a/lib/xe/xe_sriov_debugfs.c b/lib/xe/xe_sriov_debugfs.c new file mode 100644 index 000000000..dc6ef9da3 --- /dev/null +++ b/lib/xe/xe_sriov_debugfs.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright(c) 2024 Intel Corporation. All rights reserved. + */ + +#include +#include + +#include "drmtest.h" +#include "igt_debugfs.h" +#include "igt_sriov_device.h" +#include "xe/xe_sriov_debugfs.h" +#include "xe/xe_query.h" + +#define SRIOV_DEBUGFS_PATH_MAX 96 + +static char *xe_sriov_pf_debugfs_path(int pf, unsigned int vf_num, unsigned int gt_num, char *path, + int pathlen) +{ + char sriov_path[SRIOV_DEBUGFS_PATH_MAX]; + + if (!igt_debugfs_path(pf, path, pathlen)) + return NULL; + + if (vf_num) + snprintf(sriov_path, SRIOV_DEBUGFS_PATH_MAX, "/gt%u/vf%u/", gt_num, vf_num); + else + snprintf(sriov_path, SRIOV_DEBUGFS_PATH_MAX, "/gt%u/pf/", gt_num); + + strncat(path, sriov_path, pathlen - strlen(path)); + + if (access(path, F_OK)) + return NULL; + + return path; +} + +/** + * xe_sriov_pf_debugfs_attr_open: + * @pf: PF device file descriptor + * @vf_num: VF number (1-based) or 0 for PF + * @gt_num: GT number + * @attr: debugfs attribute name + * @mode: mode bits as used by open() + * + * Opens SR-IOV debugfs attribute @attr for given PF device @pf, VF number @vf_num on GT @gt_num. + * + * Returns: + * File descriptor or -1 on failure. + */ +int xe_sriov_pf_debugfs_attr_open(int pf, unsigned int vf_num, unsigned int gt_num, + const char *attr, int mode) +{ + char path[PATH_MAX]; + int debugfs; + + igt_assert(igt_sriov_is_pf(pf) && is_xe_device(pf)); + igt_assert(gt_num < xe_number_gt(pf)); + + if (!xe_sriov_pf_debugfs_path(pf, vf_num, gt_num, path, sizeof(path))) + return -1; + + strncat(path, attr, sizeof(path) - strlen(path)); + + debugfs = open(path, mode); + igt_debug_on(debugfs < 0); + + return debugfs; +} diff --git a/lib/xe/xe_sriov_debugfs.h b/lib/xe/xe_sriov_debugfs.h new file mode 100644 index 000000000..e859ff5b2 --- /dev/null +++ b/lib/xe/xe_sriov_debugfs.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright(c) 2024 Intel Corporation. All rights reserved. + */ + +#ifndef __XE_SRIOV_DEBUGFS_H__ +#define __XE_SRIOV_DEBUGFS_H__ + +#include + +int xe_sriov_pf_debugfs_attr_open(int pf, unsigned int vf_num, unsigned int gt_num, + const char *attr, int mode); + +#endif /* __XE_SRIOV_DEBUGFS_H__ */ -- 2.31.1