From patchwork Fri Oct 25 21:50:32 2024 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: 13851873 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 7CF0DD149F4 for ; Fri, 25 Oct 2024 21:51:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0B5A210EB89; Fri, 25 Oct 2024 21:51:09 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="E2jEkX1v"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8B75810EB89; Fri, 25 Oct 2024 21:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893069; x=1761429069; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=gO0LvjUua6S62XJgIlioVb9aEnjmlOSXeHNkenlw+X8=; b=E2jEkX1vXd8Vl1Ci/Wwp397I5nKHQjKc5SMEqm4Np7jF9Cc4qvL/JDfK 8WAb6GCxYYSRQw5TD8yLFfdsGcans3bu9rdPHy3S2tXRtXAJNeWGfvh6V tNXfkaLM7Sjw35dW5+pMhEn7tjzhev2GjKdG9xXeDDNPkzDpaQWbKIl0f 4qdG7zqHpOUd4L7ybWDkMwu19MvbPmeQ9VT7wM98jrssnuTwpFzJG6pBv 1Okz+an63oDuHxnfpMYRoMNVjWNZITBCoVtCwGbIRfOReOprzrcHgNrnE vFWE8z4csq10w/Jpou+meqsb7FYfpKgqSZkcn9g1yQFqGJFanNT/wkVPJ A==; X-CSE-ConnectionGUID: jIqBgrHSTNuiAh3BeXnWYg== X-CSE-MsgGUID: p6t3wLWRS9+8K/Iifc+B4g== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="29683392" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="29683392" 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:08 -0700 X-CSE-ConnectionGUID: JpRVv2PYT1SEzJq6WMWfeA== X-CSE-MsgGUID: zyPzq2r1T2eatpfsZu6EJw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="81492860" 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:08 -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:07 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) 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:07 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.171) 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.39; Fri, 25 Oct 2024 14:51:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zIaPtggEJsoOgF2fCXpaop6HmO0aC4yCtSEsPyaCADCGQVfGfJ1FcUtoMSF3dEEYa+y4UJFIjeS8/fuolZpRZlJk9WN8sVdV9XDzknbpBWZjAsPBF2PcVv0i7qB0+j4aTX8pHMt7lR6T7VLCYLWDfSFCT7EsgmppEEkk3Lzcp7S/wF95jh/d3XdYQOFxdPY3AnOb2zHljyoxRybUkpC7hFVAZw9RPftGD6XYV4xZZBxC4pP7Mq4lVOyT0KoKcB8bvP2KiRYOV6T/bLZcLEpM1/2OR5geeF1XdJPguf7dymekEXjqNgNe3sD7AtyIpMufFHCiCvQsmZTBhF2+dKi6pQ== 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=rxHJttmjn7E6Myjzq3+TueUpYOqq6Ozmnw7CozqMA8Y=; b=upF1qqP2QW4dlSl0MyLIZGFNUQLwox1xvht6bLuyvOPSKFmW1FFaOmBJlY/LJn9L/L1B1/4Uq9ZMtQJCwdeQe9OJEaPuV6kZkYxNNpVf+SSZKFCXK1NN8zkI4s7V0oLI48nPJzQacngydX9FeBwa31xYWgsQSI77VtcJrH6V6OY+wydon9hfKfbc2Tt6jOVPPiQ4AQ33EroJCS9XY7zAeixfygPBQyoNxZXrm/SgsfiFuAy2f3nkvHMjuUp9kpbL2sRElG5Y+YWyC3boWIjhTWElYK77o2AtUwTTngHpKmBNCXhfVB5x7x62DHE1W8HwYJ3KMeUlJFQGarTgek3OFQ== 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 DS0PR11MB7682.namprd11.prod.outlook.com (2603:10b6:8:dc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21; Fri, 25 Oct 2024 21:51:05 +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:05 +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 v4 1/7] PCI/IOV: Restore VF resizable BAR state after reset Date: Fri, 25 Oct 2024 23:50:32 +0200 Message-ID: <20241025215038.3125626-2-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> X-ClientProxiedBy: WA0P291CA0012.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1::7) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|DS0PR11MB7682:EE_ X-MS-Office365-Filtering-Correlation-Id: 87a0a3e0-998c-449f-8c04-08dcf53f200c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: =?utf-8?q?c+fMr9zjjw99pVnJm6ht46KaXAhSOEA?= =?utf-8?q?si5FbyplM1l4mBp5DipaO/DQgXpzPW07UAQZr56yH9Se3IVxOKBG9MR4yEdOv4kIF?= =?utf-8?q?vyLYaGtNhg7JpChAr1UqJOQDItP4zdgAnsP8truOygZsj0xTnIYMQiREj2lcmct8u?= =?utf-8?q?wsQqGsMmh2y5eKwTP2DcMdKMM0gXinGRWXqxisAheuzi/HoMaWgf78nJb7kz6gueu?= =?utf-8?q?tGybz+u/PnOXY3icDuWVy+ghP34eXpmM2DW5S69/aep5LYUMLGkqzcZlQt/sOQXtd?= =?utf-8?q?ZAH51bqJ+17fiCqJvHUBNeME13Y9cdjBhR/ksz+GY7vXDACxI48Qi6k/0KeRwvDiC?= =?utf-8?q?CDxaCOaF7t6dHtR72i5T7ZpElNMCEjF8KsUKJhPraxo9gwK9rTIO4cW4YLt+u0R+I?= =?utf-8?q?wMa2fPwKlHAoJZCm/pOMoxfPdYII8+zxJmJMdF6JpDzui76rMRFZZcCQjA2xj4Seo?= =?utf-8?q?eiXg6mtHs0n9LWmPkP2mt/+ydmb/pA6mKD3iM9M5515AC5HFyb2ihDk+0+oYR9gyZ?= =?utf-8?q?aTSUxQUyfQtho2L2KoVG8kHgdiQIiu0k+TzMHE/QQ/z/ukJcF2awFGVAg33JlkQx1?= =?utf-8?q?2um4Zb3bWLoNDoZ5zhTzeQq6Bd/im+eaDjFdANeX+VX25CZCyrhfFvi2bpe1S+Uqy?= =?utf-8?q?0aTOEaFGvoL3Y/lkOGqlWU24FG9FeYxlGwlpurlzfsIASyXxAiTftQIyFtkAUSabW?= =?utf-8?q?u+MB8EexFdcjpWC2U4rfoOT4Ec8NMhz4uT4SX3YBjBEzTjYN34JPbxnee6bldDxRp?= =?utf-8?q?0yRBbCnZCZXJTpSKmkFWRcX+Qf9D+1pbO/nIF0qbuAlZUHpAZudg4PXE3a4WdAscy?= =?utf-8?q?CZmLCOPC5X2IrKFG6f89ShBdzrw48frL+9Uf4Sfy8HWBNDS06oPJWub70BTTgFU+a?= =?utf-8?q?9ycNs0e2gs5seo0kTG14ZIJ47eLotqpGz2zEczCppbx949NmGwiaoc3jDmtIBJvFz?= =?utf-8?q?sAdnMw0v/nuK7SwuxvFF4UUNU94izg6OdgoxXMWl4LDbtgQLfDLRGn/Lwt1NvfF9F?= =?utf-8?q?YTc+RGAVJqYaGmZkTcjNdCmmpLbxYE8bATgsTv1RGNC5XyiYp4FInfcXPOSqdOET9?= =?utf-8?q?203ts5Z9MIwjxagZYWBgu6kRzApBh+OaEFVdQ+FxE0YiTKLov60b00y2nGRa/2OWd?= =?utf-8?q?ZFoOcNDYWkMJiyeks4Fh3EMe0g7uJC4Y9kz5wttCjSIph/OS2dKlWVRD/MvQl8ps3?= =?utf-8?q?S3BCEgoISB7j5FaQPdBCmtfQnce1tRRksnODUyMBHJ5SxpCVmaPUJ6XpnL0cbADhT?= =?utf-8?q?pXa7YdEZdcbO2?= 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)(1800799024)(376014)(7416014)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?MKv5hRyjm8HwdFCcrJyfBmaX5OaZ?= =?utf-8?q?qYAarzlrnypjEb9A/mc6ArEm8kCPtBle2sOxeMF3wdXjTZ1QMxUawXKVEpQway/3/?= =?utf-8?q?TuNAYAS3HiwT9dS4c6T++8uO7I4U9YKnUFgEhr84uHAhnc70ufWEsm4tcQWr5rX6y?= =?utf-8?q?P6HPTf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J3URbrLRaNOPUMN2665bjFaS+7Epo1uukaznu4zQ09On8BwPu0gxb?= =?utf-8?q?NiQDBgYIIe1OUkY7+aiE1jcox0GT/94MbKfpXTmlhcgtuDx2rviHX/8lt4kZduRjK?= =?utf-8?q?qdsN90r7dCNIIAAUg07d4Kjdg9tflFL2P88VTDP2nf/bMcr49lXVcc6Jdoqh54+j6?= =?utf-8?q?GOgGlkObBPiZD9P58vJx3FlXxZiVkHJdmLPbXfCckgie9c93AKU0JdIB2BGmVDYcW?= =?utf-8?q?eAxg+71uPENDe5d8/iTDphPn8aYlUY/L1iQbTwt/T1MiukKv0PrUNwQdrFNnO6xu7?= =?utf-8?q?z9zWQ9GCYM9VjT92EK8xSwxgFjIxRxNaeyOBrFEHO36dch7OTZb0uwsr2ontcByJp?= =?utf-8?q?nLO1Oxe9TE4XYAh6QZ3HfEoevQS7PERhOIbdNvbV4zxQS/d05YiGTVP/SA5cOd1BY?= =?utf-8?q?JNSV6zlqgSsMCWxpTxeckVzOloJBu7BbEN9rireSJfsK+AClQF70S+aanz6fpJ1eT?= =?utf-8?q?FOuAkiV4sdfqLjMsR5sJY6cn9i79hfQyfw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 87a0a3e0-998c-449f-8c04-08dcf53f200c 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:05.0689 (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: Rlqrkr1UVhT8C748GdR5513UtX2aRGNX5daPLMK8YKgmVEBksqwH9pBHIAw4eBYXKy8SNHEwyOMHf0NeHjS3m61tJUJPdp7jZl7/Sc7EbE0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB7682 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Similar to regular resizable BAR, VF BAR can also be resized, e.g. by the system firmware or the PCI subsystem itself. Add the capability ID and restore it as a part of IOV state. See PCIe r4.0, sec 9.3.7.4. Signed-off-by: Michał Winiarski Reviewed-by: Ilpo Järvinen Reviewed-by: Christian König --- drivers/pci/iov.c | 29 ++++++++++++++++++++++++++++- include/uapi/linux/pci_regs.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index aaa33e8dc4c97..6bdc9950b9787 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -7,6 +7,7 @@ * Copyright (C) 2009 Intel Corporation, Yu Zhao */ +#include #include #include #include @@ -862,6 +863,30 @@ static void sriov_release(struct pci_dev *dev) dev->sriov = NULL; } +static void sriov_restore_vf_rebar_state(struct pci_dev *dev) +{ + unsigned int pos, nbars, i; + u32 ctrl; + + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_VF_REBAR); + if (!pos) + return; + + pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl); + nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl); + + for (i = 0; i < nbars; i++, pos += 8) { + int bar_idx, size; + + pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl); + bar_idx = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, ctrl); + size = pci_rebar_bytes_to_size(dev->sriov->barsz[bar_idx]); + ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE; + ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size); + pci_write_config_dword(dev, pos + PCI_REBAR_CTRL, ctrl); + } +} + static void sriov_restore_state(struct pci_dev *dev) { int i; @@ -1021,8 +1046,10 @@ resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno) */ void pci_restore_iov_state(struct pci_dev *dev) { - if (dev->is_physfn) + if (dev->is_physfn) { + sriov_restore_vf_rebar_state(dev); sriov_restore_state(dev); + } } /** diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h index 12323b3334a9c..a0cf701c4c3af 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h @@ -740,6 +740,7 @@ #define PCI_EXT_CAP_ID_L1SS 0x1E /* L1 PM Substates */ #define PCI_EXT_CAP_ID_PTM 0x1F /* Precision Time Measurement */ #define PCI_EXT_CAP_ID_DVSEC 0x23 /* Designated Vendor-Specific */ +#define PCI_EXT_CAP_ID_VF_REBAR 0x24 /* VF Resizable BAR */ #define PCI_EXT_CAP_ID_DLF 0x25 /* Data Link Feature */ #define PCI_EXT_CAP_ID_PL_16GT 0x26 /* Physical Layer 16.0 GT/s */ #define PCI_EXT_CAP_ID_NPEM 0x29 /* Native PCIe Enclosure Management */ From patchwork Fri Oct 25 21:50:33 2024 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: 13851874 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 00E04D149F3 for ; Fri, 25 Oct 2024 21:51:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D3A410EB8F; Fri, 25 Oct 2024 21:51:14 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="BHGaNp9q"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2E80510EB8F; Fri, 25 Oct 2024 21:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893073; x=1761429073; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=b+AcW5z+LhuxH8S4a6rgeC+p3lNIPIrjSHwqh1CNDKg=; b=BHGaNp9qqdquQObATcqdnWzmLwZ8smUgdlDB7FJsOssS2dDkAQpG/KPG TAGJA43oYxmiOt56UTlX6V/Sq47kKPZ0uYH685f7OrTF8UjwHl9dtoWI2 in4tKgXPDa2pEJ3cOd+X9GrifDRDqnLy5G8PgBf+FQtsUCqbOM93ffEa4 3EHYET+cX5MHfvLRkU4I4O6DAKSoY002paYEcJcB3fABU+/viC+dmC1kt LrTDx75wKHDHzczBzKajqZaeyJOrZJc9Bkx4xjepie8rWE4jBgJ8pemDn f41JKkhKDkohHwPEx3urHSmWJJnvv4bVZ21BjBZtyDiYQ0fwBAAE36iyY Q==; X-CSE-ConnectionGUID: osKvl+eXR3eM6/Blh5xjaw== X-CSE-MsgGUID: Knfmof7rTcarcSPxUiIxAQ== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="29683411" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="29683411" 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:13 -0700 X-CSE-ConnectionGUID: xOA1yq0DSQuWWn7xj0d1og== X-CSE-MsgGUID: XlM93+VVRRGLe77MUcIwiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="81492888" 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:13 -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:12 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) 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:12 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.168) 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.39; Fri, 25 Oct 2024 14:51:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l1hSppBsaAQsTI8Ht+jNgyTfLeZIlgY5anTt19GT9VJ3Fw1+ZTIZ5d8ZqC0nUUjgM58Un7ywqy0fE5JWwJGooqTQXUARw4n+lagwux27sRw/4PaPkHprlTAIPdcEw8t24c0Y4AtRmfSWt3vK/QZO+QFOlYaG5rLfzm+QSevP6+hPsDQszfTep/jC8BmvRyJ6ukZhOg3yDAl8teZDXdQakbbdC4P8mvouUhp7zn9kHxvr/rx9SqE7zHqEmF211+1EzZIZ+Z8jJ5ebm1IGan5vFKGl6RG6URUmRPwZJnotT2CX4JJHmSA97sXxGnnugNdkltQW8sUodlqA2Ip2CYPlIg== 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=w0eyaZpCfnN0MwjPBmAOWVxef3FSGSOq9l1UFOMvkO4=; b=arirohtlEk6yOaCxEvqUEb5nCLZImSi/PsXsi25ijEyHwifjJUhoBEExZ6EYBlZrx7JwnCia/tE6OI7NjfUbYLVOkR0FIfMpPrfWnHdbyu8viZ6Zpx4hwbRFCLoty3B4+r7rqpG5gZ5nbkOBZMtkLgq8Xpn/CzTObSYsqT4q2SqXqcukWKSeBayBc4cI8sR57bQn22LxaejsJQgIwTqdVg0qFfTfKI5k5Nt/T7dPDBi6wSzrGu4DJGBApHGWQkKsdkv46dMERYn3uEFl/yX41cswKFwz001KhQpKXJemsV/hbOGkKk1Csh2WpbBVmwbqnYvw9E3cS1hEMnOiP2LwBw== 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 DS0PR11MB7682.namprd11.prod.outlook.com (2603:10b6:8:dc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21; Fri, 25 Oct 2024 21:51:09 +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:09 +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 v4 2/7] PCI: Add a helper to identify IOV resources Date: Fri, 25 Oct 2024 23:50:33 +0200 Message-ID: <20241025215038.3125626-3-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> X-ClientProxiedBy: MI1P293CA0017.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:3::13) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|DS0PR11MB7682:EE_ X-MS-Office365-Filtering-Correlation-Id: 78d1cde8-6918-44f5-4c6f-08dcf53f2279 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: =?utf-8?q?zgQ8KvapuBqXQ/5X7UWVIPS1XSYpZR7?= =?utf-8?q?Zbe1QGNSJRkMgXYMtCb42yuRKZ1wkR6OGGij/6fg9kMZEcdKeOsJax4lEBw9EQIUf?= =?utf-8?q?3SxU7bWZOUs4UU7hmY5HNxM0F64bxQwcfxsUEva3bZP6849r0sq2BhgUtCHjRdU8f?= =?utf-8?q?1PaKlm9m5hhEyEvgaib2TMKkJrUlC/oIfMz1KNzi0mLhhTIAaqa4TfqYS5xPV12FU?= =?utf-8?q?fv/laHDYAf+F5LtHos1yXweAW1ND0VrZGN0tpVPRyyIrKOgCTIzN7jq7YaPTk/N8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q?sNEEgKVOfQXIHQWLjF6zqQ4eX4M8EXgc2rqhL/IaKPYdCjqjweARGeFtO1zGTJP//?= =?utf-8?q?TFIypQ4ptn6+tc0gwi1xrAoHoL1AmB9UZrZiy0eyomBOsHKE903d4anfxDqXCnI8Q?= =?utf-8?q?qGDaTfFYsVFlr?= 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)(1800799024)(376014)(7416014)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?mDggQFZWAS9TBfWe71YVj8LDMNoy?= =?utf-8?q?IDzQo9jT7Vg0x9sqtnZ4eUNRJW94mtLY0bOF/aLO+DNIXKo/SfQQtd12LR86Hb5u4?= =?utf-8?q?7vsyCbM2czw4GfIw55NQ+N+Jv9ltTxDUkNdXX4vTZNxc2IiPyAh6heV0xEhKyfCgi?= =?utf-8?q?4sWGOqa+FMqhMKXyQ9TTpxOlLC/RzTkUwEPJ64o8I3qQGX3phB2kRNIwxLWuLD1Hx?= =?utf-8?q?q8nUV2cThz3Cksi+r8DpjPSe5bEOhHfdwqIWcjAMIxUUbV3hMSOXMOCqTlRrK8daO?= =?utf-8?q?ESD9jQnxCAvqhMO9BfAtyRR4bpfvHjrm5TzLljXhCLGQHynYooyBqAje8GXAXZ0jB?= =?utf-8?q?nU48qwljTQTQn0aHia+eQrZPMkpnzcVVplxDHkMaRg8ZcWu+pzKIS4ilIvtdWU5Y7?= =?utf-8?q?vkqRP602roxLhmpOUdwF7joC58sFBkPnBpV+VS/ZqJr56LsFkeRrPXeNaQWmc0g2s?= =?utf-8?q?BQxB9j7W2/AfihN9IgfIfJQqu1MJFLJRFK+5xQZnT1pKeVbLu+QuGNLDsI0KOJYgu?= =?utf-8?q?xgNuVSyERBP5G9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4A9jhLZ0W8sjPSILJ8jZx5XY0EeG+bxBWCw?= =?utf-8?q?NxG4CPDyrofnqKsDg4yBSNmOYrEVihbpiCMV4hTRhYOvuSFJWT9DkOEydKTWg/tJ6?= =?utf-8?q?HlOmBE9GW2xi0YfLkyJ0L//u6wnei3GjCA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 78d1cde8-6918-44f5-4c6f-08dcf53f2279 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:09.1120 (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: fBvm5R8mZf0qTqPDAYKDqz4HtL1XLnNlVt/HkO//D1iTsggTKnsm2nXhMLy5lS9QxQj0jXW5clHg3rcF+5SzUlP/Bd9fJN9OkKYRc97MMnI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB7682 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There are multiple places where special handling is required for IOV resources. Extract it to pci_resource_is_iov() helper and drop a few ifdefs. Signed-off-by: Michał Winiarski Reviewed-by: Ilpo Järvinen Reviewed-by: Christian König --- drivers/pci/pci.h | 19 +++++++++++++++---- drivers/pci/setup-bus.c | 7 +++---- drivers/pci/setup-res.c | 4 +--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 14d00ce45bfa9..48d345607e57e 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -580,6 +580,10 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno); resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); void pci_restore_iov_state(struct pci_dev *dev); int pci_iov_bus_range(struct pci_bus *bus); +static inline bool pci_resource_is_iov(int resno) +{ + return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END; +} extern const struct attribute_group sriov_pf_dev_attr_group; extern const struct attribute_group sriov_vf_dev_attr_group; #else @@ -589,12 +593,21 @@ static inline int pci_iov_init(struct pci_dev *dev) } static inline void pci_iov_release(struct pci_dev *dev) { } static inline void pci_iov_remove(struct pci_dev *dev) { } +static inline void pci_iov_update_resource(struct pci_dev *dev, int resno) { } +static inline resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, + int resno) +{ + return 0; +} static inline void pci_restore_iov_state(struct pci_dev *dev) { } static inline int pci_iov_bus_range(struct pci_bus *bus) { return 0; } - +static inline bool pci_resource_is_iov(int resno) +{ + return false; +} #endif /* CONFIG_PCI_IOV */ #ifdef CONFIG_PCIE_PTM @@ -616,12 +629,10 @@ unsigned long pci_cardbus_resource_alignment(struct resource *); static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, struct resource *res) { -#ifdef CONFIG_PCI_IOV int resno = res - dev->resource; - if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) + if (pci_resource_is_iov(resno)) return pci_sriov_resource_alignment(dev, resno); -#endif if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS) return pci_cardbus_resource_alignment(res); return resource_alignment(res); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 23082bc0ca37a..ba293df10c050 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1093,17 +1093,16 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, (r->flags & mask) != type3)) continue; r_size = resource_size(r); -#ifdef CONFIG_PCI_IOV + /* Put SRIOV requested res to the optional list */ - if (realloc_head && i >= PCI_IOV_RESOURCES && - i <= PCI_IOV_RESOURCE_END) { + if (realloc_head && pci_resource_is_iov(i)) { add_align = max(pci_resource_alignment(dev, r), add_align); r->end = r->start - 1; add_to_list(realloc_head, dev, r, r_size, 0 /* Don't care */); children_add_size += r_size; continue; } -#endif + /* * aligns[0] is for 1MB (since bridge memory * windows are always at least 1MB aligned), so diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index c6d933ddfd464..e2cf79253ebda 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -127,10 +127,8 @@ void pci_update_resource(struct pci_dev *dev, int resno) { if (resno <= PCI_ROM_RESOURCE) pci_std_update_resource(dev, resno); -#ifdef CONFIG_PCI_IOV - else if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) + else if (pci_resource_is_iov(resno)) pci_iov_update_resource(dev, resno); -#endif } int pci_claim_resource(struct pci_dev *dev, int resource) From patchwork Fri Oct 25 21:50:34 2024 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: 13851875 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 E6DD9D149F4 for ; Fri, 25 Oct 2024 21:51:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7246D10E121; Fri, 25 Oct 2024 21:51:18 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="AFs4lS4t"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 838B410EB8E; Fri, 25 Oct 2024 21:51:16 +0000 (UTC) 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: UtVfjJd6TLm5Joy0pmXy0w== X-CSE-MsgGUID: /LKRNZEbRTunsc5t15TioQ== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="29683426" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="29683426" 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_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 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> X-ClientProxiedBy: WA2P291CA0035.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1f::11) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) 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?q?7HVHlATwIoffjkNsybpR88C2SDf6AKb?= =?utf-8?q?PFK9tUGSSUmT9GX1G0qeV65t9KQSHN8Ba+aO69zLYFVH4XTRjSXzj+mKnWqVguoCl?= =?utf-8?q?26ASy9eyGZ8r3AuKpd+vJ1jex7jR8y8Bpu9QN9QTRPoQP6UAYtgxJI5BYdsOCp91f?= =?utf-8?q?9/Fx0/wlYJ9WvwihKV/SELGE6PKRanAL2Tg6KvgOFLf0lku+C7I9c5+VZbrtCLaHr?= =?utf-8?q?y6UpSOdKx/Bef4qihkvwd45FBnwzvLNCpPf/3TTfsFMwA3cKcrDQp9Ht6D8pu9UoT?= =?utf-8?q?U6OnYkYloIgOtvSv5ldDcWaG+97QzSLqKcJSfnEeDUuFo8dms8Da7rJd9MWhwSJhU?= =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Lpa?= =?utf-8?q?YjDaZ9LLFMUsyHTyXrEvRfKBd5PIQZNbzYQMUllK42aBJIZKSmB1OM6H49CiHg0BG?= =?utf-8?q?zjf8QSB67Wm1F?= 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?q?xkeJfcRE4tfe2ze9pE3Ml+BAaJuM?= =?utf-8?q?9YPWoRtz5J+kdTN/kDvGq/ZhIBOw6xyobebqtaaaQ4VAi2oHa1UDn+OfeXk3TfhEO?= =?utf-8?q?vFj2Z3bakPSrHGhRMWMmVWlE8y6dra+F8xuHxMRDh4wVnPIOEIuuhsdPHrVExxdaB?= =?utf-8?q?Pc/t+YK68XUNc+ZWq2xDQdHZ07Fs7LGLK0k55YwgJUhqUYAQmS3YHp0fa7mODTAuD?= =?utf-8?q?kKz4N8LdrcpIwmxhF/2/SOn8DvIhundeA2bLEN3wN56U97+iHQ1qnNqZuWTBRjJaQ?= =?utf-8?q?eWkeSscdwsqndt+Ov7n9USVOG+yW2cEvvPMenSE7vMvXe7YUo3ESkSrVh3dIbolbY?= =?utf-8?q?dXJ9IoCpQH8tZOZjgtw+dEcTyXxjbholkeTazE5UcZ1XkEc5h3lzfVJYoZPKqiov1?= =?utf-8?q?7u2+MUf6z1pxJ9plzaBao8h1B9ZRxu4CbqNaJnqWw6bTbvLc0NMnTZ9+Zkf3BzOPG?= =?utf-8?q?Ftq5d3b24kaY9K6FzoSwiCd5i8/bvBKOzWJ+NSEUvjztBkxDjMNbGljC85Z82GlM8?= =?utf-8?q?M0bwDV6mP1ij3K6/PR+q1p1618kkeFV6U0v0Oj7aeaulwi2vs9/M+YPJG403XbAaT?= =?utf-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lpKxtGNlM0nXy93qjGlM7Cj35pucKTxWtJxTUqf2SNx/0FzIYKd8wvCu3hXn?= =?utf-8?q?SgT6L48zrAxKUjMXh64I1TL/sNvDBRxhzw=3D=3D?= 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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ärvinen Signed-off-by: Michał 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 *dev, int resno) if (!dev->is_physfn) return 0; - return dev->sriov->barsz[resno - PCI_IOV_RESOURCES]; + return dev->sriov->barsz[pci_resource_from_iov(resno)]; } 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 = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = &dev->resource[i + PCI_IOV_RESOURCES]; + res = &dev->resource[pci_resource_to_iov(i)]; 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, pci_resource_to_iov(i)); virtfn->resource[i].start = res->start + size * id; virtfn->resource[i].end = virtfn->resource[i].start + size - 1; rc = request_resource(res, &virtfn->resource[i]); @@ -624,8 +624,8 @@ 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]; + bars |= (1 << pci_resource_to_iov(i)); + res = &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) 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); + res = &dev->resource[pci_resource_to_iov(i)]; + res_name = pci_resource_name(dev, pci_resource_to_iov(i)); /* * 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 = 0; failed: for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = &dev->resource[i + PCI_IOV_RESOURCES]; + res = &dev->resource[pci_resource_to_iov(i)]; res->flags = 0; } @@ -906,7 +906,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_to_iov(i)); 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 resno) { struct pci_sriov *iov = dev->is_physfn ? dev->sriov : NULL; struct resource *res = dev->resource + resno; - int vf_bar = resno - PCI_IOV_RESOURCES; + int vf_bar = 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 >= PCI_IOV_RESOURCES && resno <= 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 */ #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 *dev, void *data) bool *unassigned = data; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - struct resource *r = &dev->resource[i + PCI_IOV_RESOURCES]; + struct resource *r = &dev->resource[pci_resource_to_iov(i)]; struct pci_bus_region region; /* Not assigned or rejected by kernel? */ From patchwork Fri Oct 25 21:50:35 2024 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: 13851876 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 ECE7DD149F3 for ; Fri, 25 Oct 2024 21:51:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6F5B210EB80; Fri, 25 Oct 2024 21:51:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="E7P5NFae"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id F24E510EB94; Fri, 25 Oct 2024 21:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893082; x=1761429082; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=S3MtAJFYYvsilqByJKro/df74qguvca7gbT6ls0V49w=; b=E7P5NFaeja/ITBfXK0JGRDmaaD5fR6Vu4/X6SXX89totZFCQRGoXu6bx LleWiItsAX7MpytBnrUfQFvNerGGrBvPo2xM8vCVajvmyRjslSHJaloZe XUeXblXINEhDGi2k/OAHjYR3zDk23m1JXfUh3MPw/yiWTm1yS0mFC05Vy Dz5O7TD0df5iMIdf0Bsu709U8cwCZZcxn+TvVpAWZFxxt6EOkTH111kk+ QYDVJO4Kvx/NTOtQvwsDqX1U+obbve1qeWkZOScfTSfKAh7gkGhH007+1 XEm70byGsJFfHiy0tgKvMtjDojWViex8NlXrhsCPCq64HjEipCqdexdZW w==; X-CSE-ConnectionGUID: AymSF77mQ++TWo1yyKcm+g== X-CSE-MsgGUID: ZanY33JfQ0qPGKbSuQBWlw== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="29683450" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="29683450" 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:22 -0700 X-CSE-ConnectionGUID: oeCL1L6rRQarrTCs/L0zWw== X-CSE-MsgGUID: L2Ewi+7+Qvyl0kZXkA4b5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="81492907" 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:20 -0700 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) 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:19 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx602.amr.corp.intel.com (10.22.229.15) 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:19 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.175) 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:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uKbCVaaOFtXjgQR3cKd1JaQzfH44fse3ps3Ppw6Kh+XSTvic/RqzF6ePpl7ZLSOlMJ5Hcqo72wzwlxwSI7n1winl8jQaBdBk59zIRcBXuFDNazUrbvJf80CKRgAeibHxWtG+Om7xq5+oAKBWGR8xrWzy7iGhT3FWkhyeUx0y2efTccc3KGHfqhFAX8n3Z54BDUyz91xQQ2U91BdQSNQDjXitMEKCYda7kgldyKcNuLN9VgXUnNr0AdYXtzSNBHGZqBt5roIInCBTiXRt4Y80kB18sSF2Ih1OiDqxc1h3xVNsds1c0xi8nM0Ciasir2jPsBvJPvvD0DZy5FB/fv3M/Q== 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=Sh9KtT2pJ4ZvygJzlA3ulaFMLixbb90nBzVxCGkLSpY=; b=ImTebWVEZNNpAWWnqgFanrqdG9iDf4iHs8Viy5MEe/TB8pyTyGl7Nvskuhk+bR3qxXxjUFlcyvi4QJBiq7jJ9Bt2oiMJWah1X3bwQyFMILx5HdfhL21EEtn1gLV1qX5Z1a08VT+Pipbz3zvGRdbdCfsEFzR4DkS+kkenPxeMVDk3b8+JWvvwvbOxJcpdTrOZPtR/LbHh+ZPrk7WKVvNxsbqji0JwiEafOrUorHQUIEAEwT4z+TQ85eYGH8zsb8XL+fKPzKLnmqa+akKiQrUp5kDomy7iMPSCSsnKeTIVa1+1xwduI3FaNIB/ClhKvnZ++N7WQ9lmRiXF6jLgnewFcg== 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:17 +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:17 +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 v4 4/7] PCI: Allow IOV resources to be resized in pci_resize_resource() Date: Fri, 25 Oct 2024 23:50:35 +0200 Message-ID: <20241025215038.3125626-5-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> X-ClientProxiedBy: WA2P291CA0037.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1f::17) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CY8PR11MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: c697f026-fc7d-4f0d-31f9-08dcf53f27ae 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?q?BGmK15Ln8/WLEmc6wAjdf7leUCTLjsI?= =?utf-8?q?1/dLT3QiQ59jCnz0ReZsp0MCdBdsQIJjh9K/AbZDkL7hgXwIUHQPPsxF06lPPdG7H?= =?utf-8?q?217Ks5O6Zdup+vBR1O1kaumyRubSp938zdR+MMer+oC2GDHzonQSpthEjOdzgAWsR?= =?utf-8?q?AAfBN2KxovDaEMSzAvqGXsKO8tHg1DySGwiJAAQlIm56FP3RE64TxoCLLXYhnEZ/4?= =?utf-8?q?bawbSWbkGqoeIaakxWA2S7FBpt9mkbQp8f3RGYu0TJyT5tUCmuc07+ZSNmPuknS8m?= =?utf-8?q?UjUaYIt0SDAr5FpRUw8oNzf/Zl3AgPIgcpRj/EaNv33JzmQY+tJNYY9J/ZriC1QQt?= =?utf-8?q?O3e2j7NtCIIp4gubJTNhKuAg5TYSqIZ3v/NqsUxS+9lD60XFkO7CmYF4Uw8LyPN+0?= =?utf-8?q?C8EYG3jq7nGxEr0IK1X6Q9XrALL+XqUhTwPIjgnKzSs7cZYBSfakuMKwVuybFbLq4?= =?utf-8?q?NsDQ33HjV/JErS6itpZ886FWiUaKqmI1FTtwgAB9K7eNi3fkfcxH8J8MuFnuMmDza?= =?utf-8?q?POdazMObX+dncPz/7/fd85dtDRfbDEuojH4y7OfGIgGKnq6QEvu5fjEXjr6vIf3ro?= =?utf-8?q?AEzELZ6buHXiYnWiejENacxNDEbtW09KoqbQdn7Uk3g/8qlSXvIQ2zRMOzd+ilgpb?= =?utf-8?q?P+ZWIYzNIzT0W66xzqfVNt6UqRl/4o3zqqj+EUNdZmT7kr2xymfcgeMreunExFZ+e?= =?utf-8?q?gsmOLlSMXuGfU39oA8w63yKnKMw70vVKh0hWOFGdC1dITTKiwYTu1Eed9DasYSUcu?= =?utf-8?q?58Nyiv5B1UKil+Fd0XiKrSsNNlbbqZPqr3D7LONQFYjdmNsbnwgXzuw9wXuO7I0DP?= =?utf-8?q?n6rQ/NrXZdQ/mFU3As/JvoQVZv8FVsfx4a10sFGmPDmcxWVeLSmYDoAF4qJLr4KR7?= =?utf-8?q?UWsTk8QMwNm0m8DdaVnLWyVGuoivvHwjVm8dDltOOgLk8Dd3uIcBXT6MeoyNB8vu2?= =?utf-8?q?SZz/RX6jyYtePSFfG1Zo4dC7Kdmn9g3zsiSaUzOHE0+8otbXf1/jrdszlFwU2EWqd?= =?utf-8?q?jZAMHDA7z2aY7+4x2m8c5IWYrdtydVst8oM9SIAmEKl66d5VlC36CQkUV9URRNWPP?= =?utf-8?q?QKkJ7hseqQnA7Y6eYbdg2OpaDWpltQxkE2NbXxb8YQJ3voqOeLhsR3eL5O/edBCxD?= =?utf-8?q?65JPWwyDq1jWYdPxMrpEO+iOa6AFhNRmCGrpwC0jj5TKSTM09KBqDF4l6Tvkc41fP?= =?utf-8?q?y2jD68nVvrMF24VV7gPKUweMtGIWW2zmejKCkbF6Xojk4oQBnNWBdZh8o=3D?= 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?q?0Ia/2ORYVVuep4l7Jsz8sI7PZ0CN?= =?utf-8?q?8BBz0NcizY39zSmokeuXJb83OHRW9Zx++87CtIKhJnZWoJ/rBqgPCySlCmTFYiS+u?= =?utf-8?q?+5nUYXpHurd5AeW4WhxHmsN7Hs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K9ELevRCbYRvl9wyGag?= =?utf-8?q?10kKiGN/tZj+IBo50tmBMS+KpU+kwXSO/7oz3t/sP8MINvXghFPbFY3zKvrujBusM?= =?utf-8?q?YYFGK6h5bhlWLJo4ZwCs5BA7NG5k3g/TguMlpt55/Xl8yc50V7qcJdTh3JKxY7vXh?= =?utf-8?q?TBFJfD2sVUiTpm0IaXAJZ+HDCQlM1zZp+MITmk/fMLYm3RL6fJVLvsF3KV2cxr4gl?= =?utf-8?q?azBILlrmezUxAayon+3KqpXKzBtz+S8IdNTC7Sb6OL5TkJPbhoNJ/CLBRYdMsHT7U?= =?utf-8?q?rkuhIBmwNwxN/Bmq+TPXqv1uQN65k6vzMZuUJFrxWhFHRRZBHlvRmI1Fg7qKVQpES?= =?utf-8?q?838KriYrR/YtWYT+UoVbVhM2/sOSb3uG1JXobN3tj3ieg3AIwlfkOfYYlDXUfpjY2?= =?utf-8?q?rL9l0KTJx/LOsrLK48snLgzhnC3gMAAzUqO3Oqe3O3vU30tHEGsJdgw40suf2KwmV?= =?utf-8?q?vcuD4qVcGx3gQw9em2h5A3a4oU2lgdXMJGKmcusX59zwlkuNFkAWhcNXp4So88oY5?= =?utf-8?q?/8O3aARkP7PWg7ZXSVvg6hJ6MQROEQSm2Q=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: c697f026-fc7d-4f0d-31f9-08dcf53f27ae 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:17.8524 (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: ZRcEBI2gJ0QJeOH2lroBrnXszOR13W8lchFKxupVDPJHT8gEtwpJz7h6L5AWt803t48sw4ui5JmXtxWVh876GUAHqUiRpxGqYWbz436kFTU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7745 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Similar to regular resizable BAR, VF BAR can also be resized. The structures are very similar, which means we can reuse most of the implementation. Extend the pci_resize_resource() function to accept IOV resources. See PCIe r4.0, sec 9.3.7.4. Signed-off-by: Michał Winiarski --- drivers/pci/iov.c | 21 +++++++++++++++++++++ drivers/pci/pci.c | 10 +++++++++- drivers/pci/pci.h | 10 +++++++++- drivers/pci/setup-res.c | 36 +++++++++++++++++++++++++++++++----- 4 files changed, 70 insertions(+), 7 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index eedc1df56c49e..79143c1bc7bb4 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -154,6 +154,27 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) return dev->sriov->barsz[pci_resource_from_iov(resno)]; } +void pci_iov_resource_set_size(struct pci_dev *dev, int resno, + resource_size_t size) +{ + if (!pci_resource_is_iov(resno)) { + pci_warn(dev, "%s is not an IOV resource\n", + pci_resource_name(dev, resno)); + return; + } + + dev->sriov->barsz[pci_resource_from_iov(resno)] = size; +} + +bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev) +{ + u16 cmd; + + pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_CTRL, &cmd); + + return cmd & PCI_SRIOV_CTRL_MSE; +} + static void pci_read_vf_config_common(struct pci_dev *virtfn) { struct pci_dev *physfn = virtfn->physfn; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7d85c04fbba2a..905a533807b32 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3720,8 +3720,16 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar) { unsigned int pos, nbars, i; u32 ctrl; + int cap; - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR); + if (pci_resource_is_iov(bar)) { + cap = PCI_EXT_CAP_ID_VF_REBAR; + bar = pci_resource_from_iov(bar); + } else { + cap = PCI_EXT_CAP_ID_REBAR; + } + + pos = pci_find_ext_capability(pdev, cap); if (!pos) return -ENOTSUPP; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 1f8d88f0243b7..4347858007145 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -580,6 +580,9 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno); resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); void pci_restore_iov_state(struct pci_dev *dev); int pci_iov_bus_range(struct pci_bus *bus); +void pci_iov_resource_set_size(struct pci_dev *dev, int resno, + resource_size_t size); +bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev); static inline bool pci_resource_is_iov(int resno) { return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END; @@ -613,6 +616,12 @@ static inline int pci_iov_bus_range(struct pci_bus *bus) { return 0; } +static inline void pci_iov_resource_set_size(struct pci_dev *dev, int resno, + resource_size_t size) { } +static inline bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev) +{ + return false; +} static inline bool pci_resource_is_iov(int resno) { return false; @@ -621,7 +630,6 @@ static inline int pci_resource_to_iov(int resno) { return -ENODEV; } - static inline int pci_resource_from_iov(int resno) { return -ENODEV; diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index e2cf79253ebda..cec8f684b7c70 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -425,13 +425,40 @@ void pci_release_resource(struct pci_dev *dev, int resno) } EXPORT_SYMBOL(pci_release_resource); +static bool pci_resize_is_memory_decoding_enabled(struct pci_dev *dev, + int resno) +{ + u16 cmd; + + if (pci_resource_is_iov(resno)) + return pci_iov_is_memory_decoding_enabled(dev); + + pci_read_config_word(dev, PCI_COMMAND, &cmd); + + return cmd & PCI_COMMAND_MEMORY; +} + +static void pci_resize_resource_set_size(struct pci_dev *dev, int resno, + int size) +{ + resource_size_t res_size = pci_rebar_size_to_bytes(size); + struct resource *res = dev->resource + resno; + + if (!pci_resource_is_iov(resno)) { + res->end = res->start + res_size - 1; + } else { + res->end = res->start + + res_size * pci_sriov_get_totalvfs(dev) - 1; + pci_iov_resource_set_size(dev, resno, res_size); + } +} + int pci_resize_resource(struct pci_dev *dev, int resno, int size) { struct resource *res = dev->resource + resno; struct pci_host_bridge *host; int old, ret; u32 sizes; - u16 cmd; /* Check if we must preserve the firmware's resource assignment */ host = pci_find_host_bridge(dev->bus); @@ -442,8 +469,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) if (!(res->flags & IORESOURCE_UNSET)) return -EBUSY; - pci_read_config_word(dev, PCI_COMMAND, &cmd); - if (cmd & PCI_COMMAND_MEMORY) + if (pci_resize_is_memory_decoding_enabled(dev, resno)) return -EBUSY; sizes = pci_rebar_get_possible_sizes(dev, resno); @@ -461,7 +487,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) if (ret) return ret; - res->end = res->start + pci_rebar_size_to_bytes(size) - 1; + pci_resize_resource_set_size(dev, resno, size); /* Check if the new config works by trying to assign everything. */ if (dev->bus->self) { @@ -473,7 +499,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) error_resize: pci_rebar_set_size(dev, resno, old); - res->end = res->start + pci_rebar_size_to_bytes(old) - 1; + pci_resize_resource_set_size(dev, resno, old); return ret; } EXPORT_SYMBOL(pci_resize_resource); From patchwork Fri Oct 25 21:50:36 2024 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: 13851877 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 1AB47D149F3 for ; Fri, 25 Oct 2024 21:51:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8859E10EB93; Fri, 25 Oct 2024 21:51:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Kh7GiJBt"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8044110EB94; Fri, 25 Oct 2024 21:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893085; x=1761429085; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=+6kX+PN8G7ONn69IurZXEHL7OKrxjzVRleyDPT0EP3I=; b=Kh7GiJBtgsuD9yFaaWJDUF67Wfw5pLut5WyAYuUl6hse8OP7hh15J98i xF336LPCLv3jxK8oaPtqbzQQmvE29Ic5LBNOk4538atBLEgNVydHjIXG+ Omxiz+QarHeocDdYWmh10BhVr8gpTcBllNWo6BbFe6bNXyMyDutAS5ELI MXyZipkKJmr8iiNdOir/m8oAzR2x3hpkv4D27Ci/IFgdPKWIoAWFPEb2m 4TW1bcuaoq6Tbe82YYti3Jq3rgyMhzjE2suL1bK07oiY2XWBzcsqEgHuS 8Tfb8OGFTKv9V7e/mTfn0syTp04thsCUTnRawmAlg7PjdHgrEMonmePJg Q==; X-CSE-ConnectionGUID: yS/M8t+ZTyu3ploeeH8I9g== X-CSE-MsgGUID: fOW8yV4/SD+SHIOBvtgsHw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="29704511" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="29704511" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 14:51:24 -0700 X-CSE-ConnectionGUID: fVOU1lOORGShgQld12K5tw== X-CSE-MsgGUID: KjNzKySLTx+EEDqUT3X9cg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="111854145" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmviesa001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 25 Oct 2024 14:51:23 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX602.amr.corp.intel.com (10.22.229.15) 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:23 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx603.amr.corp.intel.com (10.22.229.16) 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:23 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.177) 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:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t61H16/QvbYc7XiVxmQ2qeypXB3lixCgRenTVrw5kMtrQNfIhfVToy7lY+e8oT4QsUskzTRWPUeZBhqPCUuS1frnTBez33SXPWC2sRABs3/8z0HAB4VlQ4U2hl0Ys+mcjvDR6LlpOICtNx4D4KLroeyhT3tKoMRCE+3NcEnWMykgBCQ3YSR26EviT8gQi0zxHJWUArKdNZKFU4KMkKTmMEK6GZbKMSFr9Y7cFdWFiD2JXsPcb+GsUWuHRK8i1iKjhfej7XIJE9y8nsCTN1/PKfV3TQz9kuptYvz9BVIzYlX/EgCUnrD8cVAo8CQ+4Qtfqvd91XR/gxdFkbv3rGcg3g== 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=+QmHvi2kGNZ/R3MXys/d+yl7CPR0MJOK4uWFtGOMqxM=; b=c9D9WMMnAdSSbZivka/R6iIInAF2+Xlujo9d9xolefwgiCTjM5nfIushDoInXn+oNUIF3qgiplIWWlh9IwJqnOVCwGrJNmxJ66DHdgwhqVPm7QFTCM6EDoCIDho/DScN4sgrCOoodu0soDq1E7UmJlw9k375jd5uSsVTn2/Bkpvv1kGhQI4RF8aOQQVGZT764q4K7rtTQx28cAAZsu/lAetexg4fUDl6amNrUA8YzEAiG4Aa5tYysDFPPenmTuHDCMVY8lZFYEAxVsKAstLeSDuC4IDH3+7WKoxJ/jS+W+UJcm+FuJeif6GGTch2LX5+C7uhJ76H4Zqy3lGNF8kVVw== 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:21 +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:21 +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 v4 5/7] PCI/IOV: Check that VF BAR fits within the reservation Date: Fri, 25 Oct 2024 23:50:36 +0200 Message-ID: <20241025215038.3125626-6-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> X-ClientProxiedBy: WA2P291CA0018.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1e::13) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CY8PR11MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: ca155235-7f3f-41fa-1ddb-08dcf53f29c4 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?q?WFD5tRRa95ebfw9CzLQ4ZdCWs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c66IIhUdM0I2Tn+?= =?utf-8?q?z6+F7U02yb4i/ayS4C3hsI2QAPJT4BhvjoOUF0bCR0hAjGSYy1Mq5DuNakiEv/bFH?= =?utf-8?q?CX1LiFJRfC1RrCpUULViyzrduKBg7BW1fJ500ifsPpcmF81mQWw7GNogJMdSDVxx0?= =?utf-8?q?MirBPtS7PwdCaagXHDWfrVsTK7rpX4ivx2Hy3smsg7lTFvoMwmOVhNhN4P4XvAHZB?= =?utf-8?q?nD+xXH2kGokbo9ZQauDKtKCOlWpMRRM3GZEPEHT5Ui1tUshp1PHKFxmiEq+jfvSr5?= =?utf-8?q?EzNrTCnVJkk66ut6/PGEtpsy8N1u4on7v9HisR+6IcIApOe1P55suQmOaSPxIXTg3?= =?utf-8?q?aiijWwkZi5ovlmn3Vkqet0dVDItU2oV8b6dmq1eioaVvkMZrV9D78LVbnLmIXcEUa?= =?utf-8?q?W8MCTX7epDxLx?= 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?q?xddZdIRgFEJsh2mb0k2jl6hzV2zK?= =?utf-8?q?gbkEhZAdw9nCe2zZK29LtiGKNoD4haJF+kbi4LelDx7ldQUWiI2dUXooku0a+C1ZX?= =?utf-8?q?/wvtr3xgbtRhpSihDmPEEWn9xEuprFFsy+wPQF+brRkc9lKqtHm6uE0M5T0BKXI3h?= =?utf-8?q?OjpbVvWxZCZgYjs0zZhFF6+f8WGfxRmvyopmfjFZWigeRoAbngqdF5A7rHhjC83Oz?= =?utf-8?q?BfIPF5MoPTKrSLZgrG39jtpGRpVujMZYiF0EqdoHanghBfWOycQv5Wk/7IjWZOKlj?= =?utf-8?q?KBGIP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q?OCD3hLEI7ZmXNgK7vBCT0nE94wJCkUeLNCFmiJdqsXVNVvtkfPlH/UR69GjzXg64n?= =?utf-8?q?+khLrTqVOr4orFGm4qFRmhcWiK5LfNQ/HeRX8umSlfHPb/HMrH1JC8eGpHZ192gDQ?= =?utf-8?q?Z1OmVSRA53sCmXRIcHVWddqKELG8OzVDrr7Z9OfJLTv2cPldKkGhUTS70jdSlDIZQ?= =?utf-8?q?PuurzklZQib2kq6PVBL2MmTk0WhIhoZvyDnGMODQCt602XkSPhoZlCvryq5juAIkU?= =?utf-8?q?Krh9oFBfFi27kvkb3f6SUWFojryP5He8wa43GUWSAIwPqJrlirmf43GTy+VZS8sNx?= =?utf-8?q?btaIyMt6bCmVzAlMVsfHHBJnKqd6lbto8RAtk43On/qGBwnV8+csGQp4K2DrcyGOv?= =?utf-8?q?9XAlMNldl19UTttyPPfLMpCjYWs2PRoLsw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: ca155235-7f3f-41fa-1ddb-08dcf53f29c4 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:21.3542 (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: 9XgPgUJNOFCIDFEH3Fo/lHsn9Q+NGbgHujLlu+gf3xOdD2MhI4McvcoU5hX4vsWGTbRdzrXCeAW1E9ev9JtOfaRta/VOjhB4TWROpvXHyr4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7745 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" VF MMIO resource reservation, either created by system firmware and inherited by Linux PCI subsystem or created by the subsystem itself, should contain enough space to fit the BAR of all SR-IOV Virtual Functions that can potentially be created (total VFs supported by the device). However, that assumption only holds in an environment where VF BAR size can't be modified. Add an additional check that verifies that VF BAR for all enabled VFs fits within the underlying reservation resource. Signed-off-by: Michał Winiarski --- drivers/pci/iov.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 79143c1bc7bb4..5de828e5a26ea 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -645,10 +645,14 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) nres = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { + int vf_bar_sz = pci_iov_resource_size(dev, + pci_resource_to_iov(i)); bars |= (1 << pci_resource_to_iov(i)); res = &dev->resource[pci_resource_to_iov(i)]; - if (res->parent) - nres++; + if (!res->parent || vf_bar_sz * nr_virtfn > resource_size(res)) + continue; + + nres++; } if (nres != iov->nres) { pci_err(dev, "not enough MMIO resources for SR-IOV\n"); From patchwork Fri Oct 25 21:50:37 2024 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: 13851878 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 9DD6BD149F4 for ; Fri, 25 Oct 2024 21:51:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E4BC410EB92; Fri, 25 Oct 2024 21:51:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="jWkNmDOv"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 83EAA10EB8E; Fri, 25 Oct 2024 21:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893093; x=1761429093; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Cb21LiisF8elRGSHW71OF80D2cdzyNx82WHuMbx7zMQ=; b=jWkNmDOvk/4mkferVg+jO7GS/V2jy9ba041FRta3mPQPJdqTBnkAuktS BgGLZJsApdWhop3256ofTSjaGu0Odj+TlZQPEqtwVrFhAXTlbcXI/MFnS n+czBlUIo1/nUHsQVXM338yFGPTJEy58qFSzVi4VTLsUh4Hpta1uN8AMr MMiwaJ17q80AX2hTFTrPNoAkUn/oAuAjURtQ8nFSlb7z61rMGdCUXcjI1 VVnAuxUdMOUYKlUKgWlp8xy/VoAmDgRUzPDYiDH0a1sGgZ34zR8/8HVPk TdXIeDPF81tFttPLlb0ZgykRY9AGTSrPJJmyZIupt3XlWBxH+zvK/vHjd g==; X-CSE-ConnectionGUID: Mz9BaDIgTcWPLntqwMlghQ== X-CSE-MsgGUID: 5uaYoh2YSfaF+YUVBA73fQ== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="40192815" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="40192815" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 14:51:33 -0700 X-CSE-ConnectionGUID: 0tKz9vp2T/6CtIaXQkIZeQ== X-CSE-MsgGUID: SRzMFBBBT+OWfwNpzaBQKA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="104358193" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmviesa002.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 25 Oct 2024 14:51:33 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx602.amr.corp.intel.com (10.18.126.82) 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:32 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) 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:32 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.170) by edgegateway.intel.com (192.55.55.70) 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:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Tysue0GKSs8qWZ2J2pWbeGohRU3gzhCmexqocbxjhj/osK6VdZh104lLBnLiny1ITmXry7e0ij1GOOC9m2asb5ZOx+VLN5PyGvNePHA2/E5Dot86OroRQSFwUwwR8yFuxKtVSbKMzAqbhApDh2Si9Bi6ktoXmA44gyqkF1f+EJdERmccFJ0rOxLg7r7blG82Z8cenbGWDl+lRYSozTC14LSw2uH+2YMeG+OvuR6I9VgOHSW2iqnN7QI1XIOUIsxp60IlODyAalxr/mcUmKr4nWVPSw3VyJxe/3pV1t4ftml6WD6f1HNGRojs/d1UMs9ecrV1LXNFZKHjLbeFBSDfhw== 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=prUTcacmshz3WO2AIjl4k3nUwsfAHpTcDq5xf2IXaoM=; b=oSoSEWKNhJU6L9JExtrcc3IWMYKw8x4w3JVdNAvxOU9t0BkDp9LYrxqfA9L4cnF/3nhnXZxJnOu95hSrrssrK4jePZHhdyKQdcXCdQrbf6gAFjmKsrfodHIZ5pKnuFNUBFZLyT2NCfRnN2Uj1V4hAhRljYUkQjEkL+oTcyVydEC8paaiDXZL9icWetl9NYBUIsqOfS1hus/p6a894IGCgGigGQspO5QIvQUJxtwraQLQof/OLz290EQReBCiPnWuQ367Z558wt9oIvjgK1LNtyLRthuGr10tGNoIDx+IIiJTEZDT1hLfraqU1auPb9fYk+/QGeyvoGSCBGPgiNrzSw== 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:25 +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:25 +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 v4 6/7] PCI: Allow drivers to control VF BAR size Date: Fri, 25 Oct 2024 23:50:37 +0200 Message-ID: <20241025215038.3125626-7-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> X-ClientProxiedBy: WA1P291CA0007.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::11) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CY8PR11MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: f46ff9bf-6247-4a52-050f-08dcf53f2c21 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?q?lsv79m2DZ3B69/WlJAtGseiesROQsMq?= =?utf-8?q?giqm1ao2dYx5b0jaWjQ0axHUbJ0smXS1bRZPG1Ao47MsBgNw43p/h0IdNDUFBmwM3?= =?utf-8?q?YN5h2BxjsF6nee/IjdparoOMPOCJwdQ4dLQja+6hiJGnuUstEz/aoykdLq5vrG6b3?= =?utf-8?q?K5Fzo9LK5b/rrGQIYORKuUI7h7VhuQoNzzFjz5SfEg3pFtNZWTaidVUi4LMTKVEJa?= =?utf-8?q?YIkv8gT14h1ME0rF2XarAYZ3l8RDchECES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yZ+DKyecb6fMRcMmYi8fTYZA9RS/0K?= =?utf-8?q?fGR6PFh7N44H/VtgZwrIC5vXq9lZ8mPup/T7mz5fPAzKVz7UVRBYAaGNZ5aJFJaQH?= =?utf-8?q?H1Q4pYsoJ+8IUloe8bZEmKbGET89giW1GuTlMJNkmWdH0dGYMvg2hMAEHPXDPx9U+?= =?utf-8?q?fX9xHtmyZ7lr3?= 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?q?+UvLrwKUsQ+ltBLKefJZrGmnd7pq?= =?utf-8?q?s+ur43kvM9npmtOEYdJHxPhzEYSiQS4Emsq7O7DINOmGKTtBTxNvXGYQJtqT8PMle?= =?utf-8?q?xtnNbdcOMwU5m4gheO+zK1nvXaMmbF8/i+IPxBg/gL8i63hWrEr639+6M+It4uCzT?= =?utf-8?q?mF1CumcfZm76hlmPNTKaNhx1nJFZpeMgvpuzCXkXMIOIV5E8QETQLVl3iG2c4WuUp?= =?utf-8?q?z0glKXXq4Epu+mbm7GPp/Oe5lD8+rbTQ37kTBjQ5mIg38hvotJ//ZpghN4Rej1DGI?= =?utf-8?q?A0kFpmSTfeoqUE26l3d7xwJKE5SFiNQAd14WEE8JtPHYryP6UedjoF28zeDhZfRLN?= =?utf-8?q?HWHymrHRNcHBSpTlrVL+k7Us4zTKzBfF3SwkZACwBIC7wuwB+nJqSwyiHLnTr0raw?= =?utf-8?q?de4Y1t6acr185+ciORHLW+AJOLi99NIz3Gt9rB6qOelF7FNwdF+sQ6UPN1d9tbctS?= =?utf-8?q?/5AGPuHr84QBdhbvEdxeu96RqXQPga68mIiAJ8ReBGsHpqtIPuQmpN1+lZtQ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8jHd6cNh69m?= =?utf-8?q?Erw41mOKlVF4JqEA5zDSB3vS6MwIGkktsF7w+DlrpTc5ErAINhYSLP10+qgzry7hR?= =?utf-8?q?HA+6iNyH66sIpNDb11pazhmloB4ioWlbVqXirbJnWyszUqvpM0o0RYlEOIrjTNKyM?= =?utf-8?q?Wi3hVCa2Q3ezah4MRBMIxnXRFsMygnzfYA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: f46ff9bf-6247-4a52-050f-08dcf53f2c21 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:25.4462 (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: 4lpjpm+PrdnrSLgXcW4jGDb0w+DsQi3EgAsRb5u1vRJuEndwQGxDvdcDYaVjWSkRjNvPcctCIxHPjzPBcklHxE8iTTcqRY2+O9FG4uubvCg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7745 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Drivers could leverage the fact that the VF BAR MMIO reservation is created for total number of VFs supported by the device by resizing the BAR to larger size when smaller number of VFs is enabled. Add a pci_iov_vf_bar_set_size() function to control the size and a pci_iov_vf_bar_get_sizes() helper to get the VF BAR sizes that will allow up to num_vfs to be successfully enabled with the current underlying reservation size. Signed-off-by: Michał Winiarski --- drivers/pci/iov.c | 80 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 6 ++++ 2 files changed, 86 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 5de828e5a26ea..de8d473459440 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -1281,3 +1281,83 @@ int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn) return nr_virtfn; } EXPORT_SYMBOL_GPL(pci_sriov_configure_simple); + +/** + * pci_iov_vf_bar_set_size - set a new size for a VF BAR + * @dev: the PCI device + * @resno: the resource number + * @size: new size as defined in the spec (0=1MB, 19=512GB) + * + * Set the new size of a VF BAR that supports VF resizable BAR capability. + * Unlike pci_resize_resource(), this does not cause the resource that + * reserves the MMIO space (originally up to total_VFs) to be resized, which + * means that following calls to pci_enable_sriov() can fail if the resources + * no longer fit. + * + * Returns 0 on success, or negative on failure. + * + */ +int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size) +{ + int ret; + u32 sizes; + + if (!pci_resource_is_iov(resno)) + return -EINVAL; + + if (pci_iov_is_memory_decoding_enabled(dev)) + return -EBUSY; + + sizes = pci_rebar_get_possible_sizes(dev, resno); + if (!sizes) + return -ENOTSUPP; + + if (!(sizes & BIT(size))) + return -EINVAL; + + ret = pci_rebar_set_size(dev, resno, size); + if (ret) + return ret; + + pci_iov_resource_set_size(dev, resno, pci_rebar_size_to_bytes(size)); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_iov_vf_bar_set_size); + +/** + * pci_iov_vf_bar_get_sizes - get VF BAR sizes that allow to create up to num_vfs + * @dev: the PCI device + * @resno: the resource number + * @num_vfs: number of VFs + * + * Get the sizes of a VF resizable BAR that can fit up to num_vfs within the + * resource that reserves the MMIO space (originally up to total_VFs) the as + * bitmask defined in the spec (bit 0=1MB, bit 19=512GB). + * + * Returns 0 if BAR isn't resizable. + * + */ +u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs) +{ + resource_size_t size; + u32 sizes; + int i; + + sizes = pci_rebar_get_possible_sizes(dev, resno); + if (!sizes) + return 0; + + while (sizes > 0) { + i = __fls(sizes); + size = pci_rebar_size_to_bytes(i); + + if (size * num_vfs <= pci_resource_len(dev, resno)) + break; + + sizes &= ~BIT(i); + } + + return sizes; +} +EXPORT_SYMBOL_GPL(pci_iov_vf_bar_get_sizes); diff --git a/include/linux/pci.h b/include/linux/pci.h index 573b4c4c2be61..1b9e7e3cab0ce 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2371,6 +2371,8 @@ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs); int pci_sriov_get_totalvfs(struct pci_dev *dev); int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn); resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno); +int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size); +u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs); void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe); /* Arch may override these (weak) */ @@ -2423,6 +2425,10 @@ static inline int pci_sriov_get_totalvfs(struct pci_dev *dev) #define pci_sriov_configure_simple NULL static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) { return 0; } +static inline int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size) +{ return -ENODEV; } +static inline u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs) +{ return 0; } static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe) { } #endif From patchwork Fri Oct 25 21:50:38 2024 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: 13851879 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 D4D88D149F5 for ; Fri, 25 Oct 2024 21:51:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 07E8410EB97; Fri, 25 Oct 2024 21:51:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="mtN/C0u8"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8EE6010EB8E; Fri, 25 Oct 2024 21:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893095; x=1761429095; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=wV/lB3RvOsZOu3vDULszMLNgmlK9960n/gBi+PSlrKE=; b=mtN/C0u88n7fls8sZl14u8mQePWdFNs48HeRWSDYEFFgzmXujo7NVuNR h8MHzjgZLhg/lJiuC6URkWIKnJk0ZwFENqBmQBTGScoCz9NMAixccjwXf FTF2Z0dO7nFRU9H5+jHNXANScLS4/Tmxz/P5EwM47xgwy7Kgx0Nuw5X4A OgnahhLyFxZLqQEwi44UX+SyF2wDGhMmaX/kn+zR4VVz+QxzsLuBjNXiI OLGVAD3aetN2eGyzF0xGQZzkzFzESVHRIoQ5iXW7LhShvefvhqu4780mU IvW/bnk0Qcy4R9y/tkC8/sKbrIqVM4Rbkaq6Pwr/1tVUIXx+AloeadT5/ Q==; X-CSE-ConnectionGUID: U/sNaBQPSzeWGC4cHnCL+A== X-CSE-MsgGUID: yWztMW3cRWOkg6GsCHQGTA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="29750671" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="29750671" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 14:51:34 -0700 X-CSE-ConnectionGUID: bF8FtKR1SYa0C23rCnraUQ== X-CSE-MsgGUID: iRTtAwq/SseoUQScyMBfGw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="85816278" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orviesa005.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 25 Oct 2024 14:51:34 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx603.amr.corp.intel.com (10.18.126.83) 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:33 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) 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:33 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.170) by edgegateway.intel.com (192.55.55.70) 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:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BVfGQhUM0duLzY9RXbPECPTozg0n02qOx/cjvozrLi7yaItfV6cx8BM2azZ/QDpdGDrRXeMrGyGT+K/PNRP/XzPWRpHwMexq/OPp6NACdarhWV9tE1dtBHLdjMWi7+igVNIi58U3hm+Q3NN6PbrQfGDFAG8sDJWYjwnaNBjiOAZ1reQsmvB2H5bXdNyVbLqkViKv4Zc/5/cHQM9iabL0eV4cqOlE9Dpq3KNdxFmn9wwJ0cTwk8J7KSWJqAIHZ1nhvmjNrgSCDWFtdtX7NUxPOFeNZgpktnfrPv3e4OP6YnAq0FIT8m30JdyXRs12yLBEoU8lGX1aSeB1t8VR9ecICw== 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=UwNmh+itC+Ul8yFEj6hh3gv/yry98BeOohAwro8BFBU=; b=eaSMxNx8RYOFBSApdcTCuN7gjk8b+VYmva8IEdrceCUO0ATisa4gtL4Av/dpyUDv00P6xir9xG7in072pX1PFly83B4hWUkZkOP8Ye2osu+yfnLNLwsaSQAHdm8H7l4gWtIrMJh2PBKsdBuidtc3hg2YzIoTqdQaCBciTEPleMEHo3LYLnakMGH0Owy5dYVYdOzHVyt3fbslepYieGH3f/LaQPoXMPhJjHHZXZlksx8sdDs22XVvvgYFCIQk1ZnbEgFcXvxWeawXnng6u2ZcQK3VOEou/rk3Df2P3k5z1/vX/bSWQfZhg9L6jnnA8fy5H0D5vfGQki5evL05a4TW0A== 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:29 +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:29 +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 v4 7/7] drm/xe/pf: Set VF LMEM BAR size Date: Fri, 25 Oct 2024 23:50:38 +0200 Message-ID: <20241025215038.3125626-8-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> X-ClientProxiedBy: WA0P291CA0011.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1::23) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CY8PR11MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: 3bd2660d-564f-476c-8417-08dcf53f2e97 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?q?6Ym0H42Hlol2TypwMBgma97Pp4Z03TP?= =?utf-8?q?P4ERbnm91ZvC6pu1mlh++q2EfZ2o1Rw1GPmkPf4/VYUJ3j2dpAxIj44m3x40KxSQr?= =?utf-8?q?JLmi21CVvtUVD47C+YIS+rG93uCY8zYHDsMCOBc7d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v/mEkIvu8UYUcLp3cNtkdB?= =?utf-8?q?aUjcPoKwg+CPeQaohac3khgwfTXIm7QtkBForVcfPHYmB6/+T2t7vysKV2KLz6er5?= =?utf-8?q?Mz2vt7TuTrj+IpGD3KCdUYwEqzQEbAm3dfvDCi7C2vCfycgqSbsGLkiqZ/W8L57BU?= =?utf-8?q?SnQBxhkwxzyLp1Wj4qKKWJ+s2VE/ltuiFNy6MXPAdWecPd8702rwl0/LlUqg3SwX9?= =?utf-8?q?h3UidCUffkeyQeqiCFMon7djWBCHoB+iuR3Q0vgXuTaPaueb7lu1/hQE6+ezIGmcJ?= =?utf-8?q?RVdBPoYj4lgH7?= 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?q?D1dkYCIbeccu5HXWtMcWP+cGE1NV?= =?utf-8?q?Q+F1zAl7secnEvAiXcFtai/02akti2Nj3AuaAg7YauXuo4DYhK9KtuX9KJqYY+7sV?= =?utf-8?q?1N0tvQrY+Uxzb1fL/ZOwmES0EO1xQzMlURM23Tu8p01vGL8QudSoRn57U3etFHH0p?= =?utf-8?q?/3mJAA+sPi0iKozb46RZQ/IV3ry+dr7SWjBHmhUEe+gBbS8C9W3COkCzm4Sb+houH?= =?utf-8?q?dzNvm2sdR2zl/HmoIxTvsMEMjsAkEJXImpZmbQDRiS/Sd7PpmHNUI4heweErO1Nxp?= =?utf-8?q?qcQBNbA9UUNqTRwI2hvbbXEC4e6pSgtS8CKTGIyC/ct2T45wGYUgbgvDKdtScKcWH?= =?utf-8?q?rJa5L5uKaKqlCnkoS8gaXC4+gnyU2wEqGtqSs8iO1aneyf2/kN//BotbsHaHq/CKf?= =?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YFTlI693MtYcavup8I4mZXXXE8fr0dnF1dl+lUEI0hnHOXixm0UMqhii?= =?utf-8?q?McYAl7Nd/UityLaK5A8MOE3XTfwKEz9tT3lDHd6/K/8Gb37xRJyPJ9zXPpILDCaXx?= =?utf-8?q?gDirttUz7SCsONV3S5qo7GD80PdxnjdqidmC3mxTTxkoWGQV5w4HURQyleSUciTvZ?= =?utf-8?q?0fyxKQ2BDJw7pB7HEdDuXVyH5u+GlLBCFTBEm8fysFvLHnuWkCLT0juHggRYnVHsk?= =?utf-8?q?9rq77YpPwxLSh+C9AOMsQaoq6igOCZG6gA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 3bd2660d-564f-476c-8417-08dcf53f2e97 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:29.4417 (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: 3w3Doj34VXuKQocdxUmMW4BEd9xbChY6yNytKjsKl0K+tLWVS1zE6MTurV47t9JQC7OsuKQ5GcORp6oTvw/lT29EpUVWWuMiRnl8jKsFifY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7745 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" LMEM is partitioned between multiple VFs and we expect that the more VFs we have, the less LMEM is assigned to each VF. This means that we can achieve full LMEM BAR access without the need to attempt full VF LMEM BAR resize via pci_resize_resource(). Always set the largest possible BAR size that allows to fit the number of enabled VFs. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/xe/regs/xe_bars.h | 1 + drivers/gpu/drm/xe/xe_pci_sriov.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/gpu/drm/xe/regs/xe_bars.h b/drivers/gpu/drm/xe/regs/xe_bars.h index ce05b6ae832f1..880140d6ccdca 100644 --- a/drivers/gpu/drm/xe/regs/xe_bars.h +++ b/drivers/gpu/drm/xe/regs/xe_bars.h @@ -7,5 +7,6 @@ #define GTTMMADR_BAR 0 /* MMIO + GTT */ #define LMEM_BAR 2 /* VRAM */ +#define VF_LMEM_BAR 9 /* VF VRAM */ #endif diff --git a/drivers/gpu/drm/xe/xe_pci_sriov.c b/drivers/gpu/drm/xe/xe_pci_sriov.c index aaceee748287e..57cdeb41ef1d9 100644 --- a/drivers/gpu/drm/xe/xe_pci_sriov.c +++ b/drivers/gpu/drm/xe/xe_pci_sriov.c @@ -3,6 +3,10 @@ * Copyright © 2023-2024 Intel Corporation */ +#include +#include + +#include "regs/xe_bars.h" #include "xe_assert.h" #include "xe_device.h" #include "xe_gt_sriov_pf_config.h" @@ -62,6 +66,18 @@ static void pf_reset_vfs(struct xe_device *xe, unsigned int num_vfs) xe_gt_sriov_pf_control_trigger_flr(gt, n); } +static int resize_vf_vram_bar(struct xe_device *xe, int num_vfs) +{ + struct pci_dev *pdev = to_pci_dev(xe->drm.dev); + u32 sizes; + + sizes = pci_iov_vf_bar_get_sizes(pdev, VF_LMEM_BAR, num_vfs); + if (!sizes) + return 0; + + return pci_iov_vf_bar_set_size(pdev, VF_LMEM_BAR, __fls(sizes)); +} + static int pf_enable_vfs(struct xe_device *xe, int num_vfs) { struct pci_dev *pdev = to_pci_dev(xe->drm.dev); @@ -88,6 +104,12 @@ static int pf_enable_vfs(struct xe_device *xe, int num_vfs) if (err < 0) goto failed; + if (IS_DGFX(xe)) { + err = resize_vf_vram_bar(xe, num_vfs); + if (err) + xe_sriov_info(xe, "Failed to set VF LMEM BAR size: %d\n", err); + } + err = pci_enable_sriov(pdev, num_vfs); if (err < 0) goto failed;