From nobody Mon Nov 25 16:28:28 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 9BA7E213127; Fri, 25 Oct 2024 21:51:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.17 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729893078; cv=fail; b=oQ1aPAS1J1Nv1b67/imcFrQsXqs0GphGMQiNt90FbNCud+HgqyVD2H736gm4ge8pIqVE1YiOcODWWDH8kg3b5v9zLmNyy3wfHX8kyrquGSch2FKbXkXrEelRxR28AddcbbajjnLPW4Nw3YLZ4+6GxaVJ1iJY0oL7N8pdkuHlYds= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729893078; c=relaxed/simple; bh=qJltdOa9zzHaE43rZDoTUvvQPNmAf3k66aRnLSDP5W8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=kx6BkrdgnR8+4XEOf3+DsuuPXNLljKsF8OqDC0S5yPEpR2eFvA551akqVKxQgj5Hirylw1ep9N9TrVApCEr2lPIYYd36C9MxtHmyqrkrGRat1Eg46fVW3HZrdLcrumaYIhEFc6DS7KCarG6cXrv7eMSaLHy6oR+MyMRvs4hHoSk= 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=AFs4lS4t; arc=fail smtp.client-ip=198.175.65.17 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="AFs4lS4t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893077; x=1761429077; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=qJltdOa9zzHaE43rZDoTUvvQPNmAf3k66aRnLSDP5W8=; b=AFs4lS4tLl6VpuQwFI+cFbDLNt6snfaRtaGUVFQ3dLqJ4SeAf29v4mV2 NyzLBtGsoRJSuQUpgAKvtXiTLI1Ie+5DXg++iqDw/uX/VmTf/tzU9r50o b1n0mDH/he/PzjSyMM4n0ueEY6K4/ENy1FCXFuohCl+UIrOGEwEjhJxXa O29c51i4akni1ZVlBD6sbVq+s9vK/ckU8FbFv8GmrdiuacQLX5+uZ0jZP JZi85YbcpzLT53qHi2gdqLpa6KfBK6FYy/55evpRAHu3FVouL6+Yocalb UCYAt6K/sIz9JQ6Gf18DHozfq/knWPAqeEQVJLHDsi1u2aUN5gbqXIgcv g==; X-CSE-ConnectionGUID: iJzbmk20RhmnYIWk3jdP0Q== X-CSE-MsgGUID: v6/8L8c4Q/+HhFX1JYy0Sg== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="29683420" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="29683420" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 14:51:17 -0700 X-CSE-ConnectionGUID: oDl29PNyT9SimuKdfx/5Yg== X-CSE-MsgGUID: XY2ml2VoTZySHarOGi7chg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="81492900" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orviesa007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 25 Oct 2024 14:51:16 -0700 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 25 Oct 2024 14:51:15 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Fri, 25 Oct 2024 14:51:15 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.176) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 25 Oct 2024 14:51:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nXa+T0crMxRVfD+POB1wX1tzkQVUFVzJoXQw/mrbwMSeIpIkXf2eNr2tumtqAYenTglHXtn/r2zuA2IH72XkFVCzOPEMV0OeQbHsU2piyl8Y92hWHWpuB/wDYb22xQHXXZpd1Z3XbAappPSSlrFTbOjjJNIWsztQRhOLQ/DrqCxtxgsYXI9XWb28HCHR64jzOgP6UmPJTWll1pYsV/zwAXkhNH52kmfsDBDu76z+XMz9qhIiJw3cXJEnsdAhQCNsMaWkbVRNQaSq9ehqXGfQAFYkxdRWsxmpFPbnrKpYsd2iYyGMg1hThXJ/kw+LivLS7B80k/ghzZnNwEQU4SDRgA== 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=ROterculxntEPzXGkt8YiHRCMcU9C2S0nxZB0C13n5I=; b=lDLPKTqIaVtmFV0E8YaN6mw0ibn6OJWSwz//DvnmZ8u8SlKbF887Qx6YGey24QdHpmxRnQaRogV9pK2CBUS1+UDsszYPbZs0nky9T2R2tphJMYst+hxSTuh3Ds0GkT5FZaNCbkijQGh46byVx8+txBRI5fxxGtuMnKNbg5qcIcfBqKrS6OYj+heYIc7OX4Idpy0AywdkWTVxO0MUP4G5ZKwIIwWiKF/h8BG+QPDU8UoYBJwx5aUk0wlAjgfz6N624Ns9dNwl3b/Z8uFBLuCsfITWkbgCarRTWnRZc+YA2F4/JYplCVeuZwTfZC+Ekcnrr34nXukcY6lVTjnIcleBOA== 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 CY8PR11MB7745.namprd11.prod.outlook.com (2603:10b6:930:90::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Fri, 25 Oct 2024 21:51:13 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39%5]) with mapi id 15.20.8093.018; Fri, 25 Oct 2024 21:51:13 +0000 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: , , , , "Bjorn Helgaas" , =?UTF-8?q?Christian=20K=C3=B6nig?= , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= CC: Rodrigo Vivi , Michal Wajdeczko , Lucas De Marchi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Matt Roper , =?UTF-8?q?Micha=C5=82=20Winiarski?= Subject: [PATCH v4 3/7] PCI: Add a helper to convert between standard and IOV resources Date: Fri, 25 Oct 2024 23:50:34 +0200 Message-ID: <20241025215038.3125626-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241025215038.3125626-1-michal.winiarski@intel.com> References: <20241025215038.3125626-1-michal.winiarski@intel.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA2P291CA0035.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1f::11) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CY8PR11MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: 51f4a631-28cf-4329-26c2-08dcf53f2538 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?N0hWSGxBVHdJb2ZmamtOc3licFI4OEMyU0RmNkFLYlBGSzl0VUdTU1VtVDlH?= =?utf-8?B?WDFHMHFlVjY1dDlLUVNITjhCYSthTzY5ekxZRlZINFhUUmpTWHpqK21Lbldx?= =?utf-8?B?Vmd1b0NsMjZBU3k5ZXlHWjhyM0F1S3BkK3ZKMWpleDdqUjh5OEJwdTlRTjlR?= =?utf-8?B?VFJQb1FQNlVBWXRneEpJNUJZZHNPQ3A5MWY5L0Z4MC93bFlKOVd2d2loS1Yv?= =?utf-8?B?U0VMR0U2UEtSYW5BTDJUZzZLdmdPRkxmMGxrdStDN0k5YzUrVlpicnRDTGFI?= =?utf-8?B?cnk2VXBTT2RLeC9CZWY0cWloa3Z3ZDQ1RkJud3p2TE5DcFBmLzNUVG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SUZvcVBER3lGVTBPVkYw?= =?utf-8?B?Q0NiOGUvTy9mMUtCUk55emJTQlJvWHBwUTJDWmhMamVUQkUwRmE4ZTJaOHFC?= =?utf-8?B?TWo5U3haY2VGWGZCVmF6a2MxZ3pmUXNsaXFoUGdMRWVLNHVERGJ6cDR6SFlR?= =?utf-8?B?L0NBcG5DMmxVcExqRkhXR0RWSHpLTmg0ZzR2VmkrREhpMERrV2pGVDhQTUd4?= =?utf-8?B?VTNSd2pVWVBCTkZqSjdXQnQrMTFVMUZQL0lhYmVsQ1dCMndxWlRHQ2dXaVZn?= =?utf-8?B?ZE9tZld6cTJsVzdhdGI3REIzV2tDUGpOMDR6RUJHeFRiRHoyb3cwUUYxNlhO?= =?utf-8?B?Nkd0MHpiWWNIeFV4N3JBV0NvNzhWRTlkOEJkNVFmd3c1SUQ2ako2NXJlVzF0?= =?utf-8?B?S1dFY09YRjVjSCtreHNMTk1JYnFxcXBlQ2p5UXZWVTFQZnJnbHVYSFdvRkVF?= =?utf-8?B?cStETHBhWWpEYVo5TExGTVVzeUhUeVhyRXZSZktCZDVQSVFaTmJ6WVFNVWxs?= =?utf-8?Q?K42aBJIZKSmB1OM6H49CiHg0BGzjf8QSB67Wm1F?= 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)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eGtlSmZjUkU0dGZlMnplOXBFM01sK0JBYUp1TTlZUFdvUnR6NUora2RUTi9r?= =?utf-8?B?RHZHcS9aaElCT3c2eHlvYmVicXRhYWFRNFZBaTJvSGExVURuK09mZVhrM1Rm?= =?utf-8?B?aEVPdkZqMlozYmFrUFNySEdoUk1XTW1WV2xFOHk2ZHJh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TEU1L1NUNnpiY21ySXlsR2xJY1JzYUFScjNE?= =?utf-8?B?d1AzbXVnR0I4T0VGWXlXTHNTVk1iUVFxak1UaFM1ckI3M0s5Y3ZZMTVkMmxw?= =?utf-8?B?S3h0R05sTTBuWHk5M3FqR2xNN0NqMzVwdWNLVHhXdEp4VFVxZjJTTngvMEZ6?= =?utf-8?B?SVlLZDh3dkN1M2hYblNnVDZMNDh6ckF4S1VqTVhoNjRJMVRML3NOdkRCUnho?= =?utf-8?B?enc9PQ==?= X-MS-Exchange-CrossTenant-Network-Message-Id: 51f4a631-28cf-4329-26c2-08dcf53f2538 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 21:51:13.7509 (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: pIvcSHyDkYMQq+stL701h7HPja+aXIvpo4ZnY9Yz3FbS/dPMhxx5mPo4lOvtbcEpLcYIBfOrewX26zSZfGHW6haPEIKg19tKSwrO0Rgu/GQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7745 X-OriginatorOrg: intel.com There are multiple places where conversions between IOV resources and standard resources are done. Extract the logic to pci_resource_to_iov() and pci_resource_from_iov() helpers. Suggested-by: Ilpo J=C3=A4rvinen Signed-off-by: Micha=C5=82 Winiarski --- drivers/pci/iov.c | 20 ++++++++++---------- drivers/pci/pci.h | 18 ++++++++++++++++++ drivers/pci/setup-bus.c | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 6bdc9950b9787..eedc1df56c49e 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 *d= ev, int resno) if (!dev->is_physfn) return 0; =20 - return dev->sriov->barsz[resno - PCI_IOV_RESOURCES]; + return dev->sriov->barsz[pci_resource_from_iov(resno)]; } =20 static void pci_read_vf_config_common(struct pci_dev *virtfn) @@ -322,12 +322,12 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) virtfn->multifunction =3D 0; =20 for (i =3D 0; i < PCI_SRIOV_NUM_BARS; i++) { - res =3D &dev->resource[i + PCI_IOV_RESOURCES]; + res =3D &dev->resource[pci_resource_to_iov(i)]; if (!res->parent) continue; virtfn->resource[i].name =3D pci_name(virtfn); virtfn->resource[i].flags =3D res->flags; - size =3D pci_iov_resource_size(dev, i + PCI_IOV_RESOURCES); + size =3D pci_iov_resource_size(dev, pci_resource_to_iov(i)); virtfn->resource[i].start =3D res->start + size * id; virtfn->resource[i].end =3D virtfn->resource[i].start + size - 1; rc =3D request_resource(res, &virtfn->resource[i]); @@ -624,8 +624,8 @@ static int sriov_enable(struct pci_dev *dev, int nr_vir= tfn) =20 nres =3D 0; for (i =3D 0; i < PCI_SRIOV_NUM_BARS; i++) { - bars |=3D (1 << (i + PCI_IOV_RESOURCES)); - res =3D &dev->resource[i + PCI_IOV_RESOURCES]; + bars |=3D (1 << pci_resource_to_iov(i)); + res =3D &dev->resource[pci_resource_to_iov(i)]; if (res->parent) nres++; } @@ -786,8 +786,8 @@ static int sriov_init(struct pci_dev *dev, int pos) =20 nres =3D 0; for (i =3D 0; i < PCI_SRIOV_NUM_BARS; i++) { - res =3D &dev->resource[i + PCI_IOV_RESOURCES]; - res_name =3D pci_resource_name(dev, i + PCI_IOV_RESOURCES); + res =3D &dev->resource[pci_resource_to_iov(i)]; + res_name =3D pci_resource_name(dev, pci_resource_to_iov(i)); =20 /* * If it is already FIXED, don't change it, something @@ -844,7 +844,7 @@ static int sriov_init(struct pci_dev *dev, int pos) dev->is_physfn =3D 0; failed: for (i =3D 0; i < PCI_SRIOV_NUM_BARS; i++) { - res =3D &dev->resource[i + PCI_IOV_RESOURCES]; + res =3D &dev->resource[pci_resource_to_iov(i)]; res->flags =3D 0; } =20 @@ -906,7 +906,7 @@ static void sriov_restore_state(struct pci_dev *dev) pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, ctrl); =20 for (i =3D 0; i < PCI_SRIOV_NUM_BARS; i++) - pci_update_resource(dev, i + PCI_IOV_RESOURCES); + pci_update_resource(dev, pci_resource_to_iov(i)); =20 pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz); pci_iov_set_numvfs(dev, iov->num_VFs); @@ -972,7 +972,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int r= esno) { struct pci_sriov *iov =3D dev->is_physfn ? dev->sriov : NULL; struct resource *res =3D dev->resource + resno; - int vf_bar =3D resno - PCI_IOV_RESOURCES; + int vf_bar =3D pci_resource_from_iov(resno); struct pci_bus_region region; u16 cmd; u32 new; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 48d345607e57e..1f8d88f0243b7 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -584,6 +584,15 @@ static inline bool pci_resource_is_iov(int resno) { return resno >=3D PCI_IOV_RESOURCES && resno <=3D PCI_IOV_RESOURCE_END; } +static inline int pci_resource_to_iov(int resno) +{ + return resno + PCI_IOV_RESOURCES; +} + +static inline int pci_resource_from_iov(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 @@ -608,6 +617,15 @@ static inline bool pci_resource_is_iov(int resno) { return false; } +static inline int pci_resource_to_iov(int resno) +{ + return -ENODEV; +} + +static inline int pci_resource_from_iov(int resno) +{ + return -ENODEV; +} #endif /* CONFIG_PCI_IOV */ =20 #ifdef CONFIG_PCIE_PTM diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index ba293df10c050..c5ad7c4ad6eb1 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1778,7 +1778,7 @@ static int iov_resources_unassigned(struct pci_dev *d= ev, void *data) bool *unassigned =3D data; =20 for (i =3D 0; i < PCI_SRIOV_NUM_BARS; i++) { - struct resource *r =3D &dev->resource[i + PCI_IOV_RESOURCES]; + struct resource *r =3D &dev->resource[pci_resource_to_iov(i)]; struct pci_bus_region region; =20 /* Not assigned or rejected by kernel? */ --=20 2.47.0