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: 13851867 X-Patchwork-Delegate: bhelgaas@google.com 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 DFEAA213154; Fri, 25 Oct 2024 21:51:21 +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=1729893084; cv=fail; b=obPPlS3gQTyHdKPXQpkaPDWKcL6Gk4bHe1IMQwhBTOgbY3qDPyutxBzzkHzMktM3VTSiTT+tgYLhAZ2VOf5F7Rpl6ZQhOxc/9vskkNjIwnm1d/83MTqVpT7vNNWgqdgF0ixT4rVuYdvmCRBwyvMgkuUR0Z8tuztA1fA1CNPWmvY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729893084; c=relaxed/simple; bh=S3MtAJFYYvsilqByJKro/df74qguvca7gbT6ls0V49w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=iEvc/Rhjde8RwyuakDprA3v976I9Hx/3UMnm0EWvGuNqAXBOQvoBfAG+qp8dk3UFpUcWepOZ9otzzIWvrqq5c3o468kEXD1uv3vHFUtYc+LFeotka/VUT6dpu9JnjhpJkhy5UpsY1LQQP2gKgLvCbeWw3gkTK9jwm9jLWYIOdHQ= 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=E7P5NFae; 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="E7P5NFae" 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: HQ+AT2wcQm+0zvUmZLNzIg== X-CSE-MsgGUID: Y+GcGc1TRUiOQbQtyvZ2IQ== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="29683445" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="29683445" 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) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|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?bawbSWbkGqoeIaakxWA2S7FBpt9mkbQp8f3R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ltQxkE2NbXxb8YQJ3voqOeLhsR3eL5O/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?+5nUYXpHurd5AeW4WhxHmsN7Hsv28K4TWWdFbdpjOrSXBj1CxguegBgdLYd4Wu5Lz?= =?utf-8?q?liMTRQaSidtx4BKNAJiFNojbJhH75spt1B7S9u6hVtYWN1RxEBdXiN9YEoOA8csD4?= =?utf-8?q?qklvR9DFbB3buXlzTXnDyh5IMtCdRO32QLers5MJyI0NLWJPhKEjgJy8aqCULRBBd?= =?utf-8?q?yG8seyxY3l29xBRe08p/au4oE9pnpcgsj0Z6SolgBPw5PSDMi+A/3vjRyicaocwoG?= =?utf-8?q?8aSxGutlYitokQU3G61EbD5AZJzvz3qy7+Tme9TSs5PBIVZolO4DWU1m8XPw3JIUb?= =?utf-8?q?HOsCjJbzEFKNr00VNboOdd/NBeSgLGbXZfbyJRueBkw2SUmss7jmQ8jedC1XM1HR8?= =?utf-8?q?R2chhKlC4P8m9SfaasqmBJB6oDTPu2qvxdPuUJqpYmlMzpEa6Gsa6ecgbM82jCOii?= =?utf-8?q?3PaWAvj2DDjcQ+JO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nC3gMAAzUqO3Oqe3O3vU30tHEGsJdgw40suf2KwmV?= =?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 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);