From patchwork Wed Apr 2 14:11:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 14036083 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3F4F23A99C; Wed, 2 Apr 2025 14:12:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743603129; cv=fail; b=AvJRdyWkBegDV1MELjkVmkBzHuOyOsUu0QGqafMlPgCEks8LilE69PCULmK2p++CInEDckuUT9zo+XbdBPfEWB77yZspgqtIvzv2rvymDXWI5JhtxllXog8kRz6GOG9W1B0b8n+d5KJuacSUOYW9qlehdD7oMUc9V4JcSE0Vsyk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743603129; c=relaxed/simple; bh=Nv+UfiYi334Vj2bEklwc7omGZtO8waKDPtZmnD/hEhw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Fd90uVMLupx2nkQHW+nwOTqMAH8G/bbEVOoqgLiVjv7c7lncx1G/DY6zsd9JBC1/mVAaKuqjtQ7y9/CJEyS1pI8xqXiS9YlvhMoPiSaYEp15VcSQR7Sl07RR3oq7rbsfLp8Y+dWjiKDnyIS+ZvR6NEXBRR9wX9sSJx0N1PE5b5M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bjAGd8yl; arc=fail smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bjAGd8yl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743603128; x=1775139128; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Nv+UfiYi334Vj2bEklwc7omGZtO8waKDPtZmnD/hEhw=; b=bjAGd8ylWyUjTyDVELfhyPieBkTI1NzqMj7+b1JDJDXRPJXqL4mtnXHM VpRJBoNGdce1d8SmvDlSW23YQpzmOU+A9RGYJfywrU5bi6BCRrydME4CC cuSGFyiVq0GbUJOi43p5OiQo/6GDxhXjSuhqCjBTFrHyFPl3Vn7HM1C/G F2Jhr39aqcagULKwQrJfLZMeF+qKPKnlNBSIB2JKMDsH6x0uemJ57Vh8X NW2c1ND/JrKTDqPRuYbPFCd2igpkegbjq24bq7rPrwjrSi1pI2vwX9c4i VhaId/TEkM4sBCT0XGBV925EZG5SSkd3xQAMtLencRTYNUWeXl6WDt2JU g==; X-CSE-ConnectionGUID: iS3AYbwkR5uZjjLWhGhLTg== X-CSE-MsgGUID: 20hBMShASHyO5rEued+PpA== X-IronPort-AV: E=McAfee;i="6700,10204,11392"; a="44677138" X-IronPort-AV: E=Sophos;i="6.15,182,1739865600"; d="scan'208";a="44677138" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 07:12:04 -0700 X-CSE-ConnectionGUID: O86ujsA0SFiARd9S4Ltt1g== X-CSE-MsgGUID: dzmy1acqSq2IXw8IUVwb8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,182,1739865600"; d="scan'208";a="127620415" Received: from orsmsx903.amr.corp.intel.com ([10.22.229.25]) by orviesa008.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 07:12:04 -0700 Received: from ORSMSX901.amr.corp.intel.com (10.22.229.23) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Wed, 2 Apr 2025 07:12:03 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14 via Frontend Transport; Wed, 2 Apr 2025 07:12:03 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.169) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.44; Wed, 2 Apr 2025 07:12:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HMZMj2zneIZoT+t4ZDXQj7HXhkgCG/dTWl1e1O6ZEKDXI5H3HqeHmzc6tb0sqrOL4UAlHBbq+G+XKAIHaPMCD7SMD8IhmitfgbDQe96KJGyIpJvs6NUy2Atzuc9/1kVwDR5yts7i82VCUhe5HhiqraqriXC2XOoXu0ipqjQZ7FTvninzf5jRrgZMjI5VfXm1ZY0DVyNp9FA1MLrjx4YzIFV23bKdAFnPhdaNOxwhElrao7SkJy8uxQvWj35138A6B5ZTSE2X3BZx4slbQWErpD+ITqfSUEof3zitJYgqnSkfM2B0JGwJ3TXqQ6WzruK3sijO9T7YDcGG+D7/HqRjjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dfGxvsJ/e+JrR6SZ0zItm7bxN5WZZg32/gGWH4KsMAQ=; b=B1WM+pQglIB+jmE1VrACL7tW2i+fwcL+P8xElwUUejLz67xP7cfQKZDu2DpWXO6mzdxlB5T/Ms656BKzlc778U1au30gVf5qICsX2Stu5QaFXgk8YS+5gAZGfOob5NpORlA1fHg0JfdF/43PYZsSPtstTMt6jPECy17Ys6HaAzwklfXuxLwQYtKJ9/lzc8S6KxEI8PQz+w4DVxF1g1vs6MPslAvnOC5nE3/IEiVLe4YXs/eYruzYJCevM1nff+Lcm/wlOAEVHkEQwkNZ0uJ3PcLnD8RPj8G1vIvoxn9xqmOTjIViNqd+EqX5r2/YbfogoGhV1W4PkVxdYW3w1vV/3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by SJ0PR11MB5213.namprd11.prod.outlook.com (2603:10b6:a03:2da::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.48; Wed, 2 Apr 2025 14:11:43 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39%4]) with mapi id 15.20.8583.041; Wed, 2 Apr 2025 14:11:43 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , , , "Bjorn Helgaas" , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= CC: Rodrigo Vivi , Michal Wajdeczko , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Matt Roper , =?utf-8?q?Micha=C5=82_Winiarski?= Subject: [PATCH v7 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Date: Wed, 2 Apr 2025 16:11:18 +0200 Message-ID: <20250402141122.2818478-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402141122.2818478-1-michal.winiarski@intel.com> References: <20250402141122.2818478-1-michal.winiarski@intel.com> X-ClientProxiedBy: VI1PR09CA0135.eurprd09.prod.outlook.com (2603:10a6:803:12c::19) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|SJ0PR11MB5213:EE_ X-MS-Office365-Filtering-Correlation-Id: 53c8a69d-f97d-4f38-820e-08dd71f04bac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?UqrUtlcWbU7HppZZOOLmp1DyYD4fa35?= =?utf-8?q?d6PI+dkSc60SYv+C7Pa5xfa95iIAlCcXUGFZDvID2pZcys6Ovo6gjEXlajDUFPQ7H?= =?utf-8?q?9l5FwQbXEiSyapnYcptaiBqpzoXAT7A/leMP39rsPukX8IDfdPh76UNb+Luk7Ygn+?= =?utf-8?q?LHCK/DxnjIRttARmQQRD2f3ZE+9+S10rZuO3hhAAL+WZ+GfFsVTFRwT5Xxpt5E5s0?= =?utf-8?q?Hp4cBKVR7N7lOaaP7fftc3HQK8NvxhYGmeB8RqoDWEaC4GcTSnF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IM9ceVoX6DZ88goQYz?= =?utf-8?q?QApr0BmaaBD4m09bHF/PLIikkSKjaokbn206WvIIYxtIkPPqv8iLs/OGT0Y8wX18L?= =?utf-8?q?FzaSm7sZkH4zpOY9SULiwl/yxP0IvRgMkecS7H6gwoGSLPO9v8U23Q2AHRC6MLJZp?= =?utf-8?q?T3e5UpbXNOEhGAtQ2es8dyssF/RKO23w1IHGghBMoO9zQsusc7lVtX29jcyooxs7t?= =?utf-8?q?L49RiGcOI6lY?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR11MB5373.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ElzcDt2ryLc2xPkCvrwGFKQDInkV?= =?utf-8?q?7DKd/fGLTDWsLRCHOZJaRtgObAbWQUVyloOhqpNPINdh+TSa6mJ3DpU3nbvljVoKf?= =?utf-8?q?H0uVL+wDfsFexObjErKCl9JTpeKySHMgAToLkgAaLwxqIr/HKa8x6XW6/PjHQ9eW5?= =?utf-8?q?Fn9vCFVXoR6NEqTZV+BM+w9L8nZ8lZfAVjNM28xUINvadNZIfxDYj/fNpdYFtWR2O?= =?utf-8?q?igPrTEYI63c0rRmOuFNH+d66PBI/fA2pYegqnQLtUPL+S4VQS0sIyjsq4JuiqMTpn?= =?utf-8?q?GCxs+8kcdBP5+sOrgjsbyeF12B4w9Rn7v59w092xgYVhl1NaRSdirL3elZPpIeyH8?= =?utf-8?q?Hz+STEUZSWhG7ynzebYTYXs6/iPh/iR8hLlPLMu/iKN3SJtamtFAUDpbT+DY5jmuu?= =?utf-8?q?sTmA9LzReJYHVe5koLCCukgWdAqzLt6MN6XS7u6ynaBo00YIuR3VRSCG3m1JXBmx8?= =?utf-8?q?4WVzuS5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Z9v82Nj4YpYoigY0aCRj+co9brNbV09x1uuq55x8xlA0k+O4?= =?utf-8?q?PQm5IUsfwpTPc5dq8Og52iaygwE+mbs/JT3uQE7C7fKaYgXhi2x8czzqgJSuWfWyc?= =?utf-8?q?L2484pLzutlybnSpSNh65x5BpJRGKuUBPChTJiuvkr63v4cT5/B2K56kJnFXFgnfL?= =?utf-8?q?AFmgKuygwksnd/5mT7B2n7UFsq5PAwD5UA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 53c8a69d-f97d-4f38-820e-08dd71f04bac X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2025 14:11:43.4179 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lS6gXxDbDo3onBE/Pbb/HeFbJUjgcyrRI8D4sO8rtNJEaEiXQqmHPyL+yWvLaILiLQ3YCh7jOqTpjoDi0v5iaYMsg3NSvRoCPy2rmoK7JFI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5213 X-OriginatorOrg: intel.com There are multiple places where conversions between IOV resources and corresponding VF BAR numbers are done. Extract the logic to pci_resource_num_from_vf_bar() and pci_resource_num_to_vf_bar() helpers. Suggested-by: Ilpo Järvinen Signed-off-by: Michał Winiarski Acked-by: Christian König Reviewed-by: Ilpo Järvinen --- drivers/pci/iov.c | 26 ++++++++++++++++---------- drivers/pci/pci.h | 19 +++++++++++++++++++ drivers/pci/setup-bus.c | 3 ++- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 8bdc0829f847b..3d5da055c3dc1 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -151,7 +151,7 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) if (!dev->is_physfn) return 0; - return dev->sriov->barsz[resno - PCI_IOV_RESOURCES]; + return dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)]; } static void pci_read_vf_config_common(struct pci_dev *virtfn) @@ -342,12 +342,14 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) virtfn->multifunction = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = &dev->resource[i + PCI_IOV_RESOURCES]; + int idx = pci_resource_num_from_vf_bar(i); + + res = &dev->resource[idx]; if (!res->parent) continue; virtfn->resource[i].name = pci_name(virtfn); virtfn->resource[i].flags = res->flags; - size = pci_iov_resource_size(dev, i + PCI_IOV_RESOURCES); + size = pci_iov_resource_size(dev, idx); resource_set_range(&virtfn->resource[i], res->start + size * id, size); rc = request_resource(res, &virtfn->resource[i]); @@ -644,8 +646,10 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) nres = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - bars |= (1 << (i + PCI_IOV_RESOURCES)); - res = &dev->resource[i + PCI_IOV_RESOURCES]; + int idx = pci_resource_num_from_vf_bar(i); + + bars |= (1 << idx); + res = &dev->resource[idx]; if (res->parent) nres++; } @@ -811,8 +815,10 @@ static int sriov_init(struct pci_dev *dev, int pos) nres = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = &dev->resource[i + PCI_IOV_RESOURCES]; - res_name = pci_resource_name(dev, i + PCI_IOV_RESOURCES); + int idx = pci_resource_num_from_vf_bar(i); + + res = &dev->resource[idx]; + res_name = pci_resource_name(dev, idx); /* * If it is already FIXED, don't change it, something @@ -871,7 +877,7 @@ static int sriov_init(struct pci_dev *dev, int pos) dev->is_physfn = 0; failed: for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = &dev->resource[i + PCI_IOV_RESOURCES]; + res = &dev->resource[pci_resource_num_from_vf_bar(i)]; res->flags = 0; } @@ -933,7 +939,7 @@ static void sriov_restore_state(struct pci_dev *dev) pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, ctrl); for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) - pci_update_resource(dev, i + PCI_IOV_RESOURCES); + pci_update_resource(dev, pci_resource_num_from_vf_bar(i)); pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz); pci_iov_set_numvfs(dev, iov->num_VFs); @@ -999,7 +1005,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno) { struct pci_sriov *iov = dev->is_physfn ? dev->sriov : NULL; struct resource *res = pci_resource_n(dev, resno); - int vf_bar = resno - PCI_IOV_RESOURCES; + int vf_bar = pci_resource_num_to_vf_bar(resno); struct pci_bus_region region; u16 cmd; u32 new; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index adc54bb2c8b34..f44840ee3c327 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -693,6 +693,15 @@ static inline bool pci_resource_is_iov(int resno) { return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END; } +static inline int pci_resource_num_from_vf_bar(int resno) +{ + return resno + PCI_IOV_RESOURCES; +} + +static inline int pci_resource_num_to_vf_bar(int resno) +{ + return resno - PCI_IOV_RESOURCES; +} extern const struct attribute_group sriov_pf_dev_attr_group; extern const struct attribute_group sriov_vf_dev_attr_group; #else @@ -717,6 +726,16 @@ static inline bool pci_resource_is_iov(int resno) { return false; } +static inline int pci_resource_num_from_vf_bar(int resno) +{ + WARN_ON_ONCE(1); + return -ENODEV; +} +static inline int pci_resource_num_to_vf_bar(int resno) +{ + WARN_ON_ONCE(1); + return -ENODEV; +} #endif /* CONFIG_PCI_IOV */ #ifdef CONFIG_PCIE_TPH diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 54d6f4fa3ce16..281121449fc0b 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1885,7 +1885,8 @@ static int iov_resources_unassigned(struct pci_dev *dev, void *data) bool *unassigned = data; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - struct resource *r = &dev->resource[i + PCI_IOV_RESOURCES]; + int idx = pci_resource_num_from_vf_bar(i); + struct resource *r = &dev->resource[idx]; struct pci_bus_region region; /* Not assigned or rejected by kernel? */