From patchwork Thu Oct 10 10:32:01 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: 13829906 X-Patchwork-Delegate: bhelgaas@google.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (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 81DC31C2DBF; Thu, 10 Oct 2024 10:32:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.16 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728556348; cv=fail; b=qGDsYZxEZpzsTrRZ5ZlQAmj2DYwnYkyiA5LB57jlIVRfxnoT+s9umwvbQmDYIi8isuwF9YK6Q/EJH4xRJPo9Zm805jMcFJtl1gPwibA+ocg+r302MsQNVp7fzwYHXXwL+gJwILQgjj8SBQO/Pb/Efmlg9QMTOW/3wMuoDrlDPyE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728556348; c=relaxed/simple; bh=ybaOv2ojJW7CwOeUTI7puwXRWFM1V1+uIvZzDLzNOR0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=oTmWcnU0/ZNjUCoXEAwC2MRr2RlvssbaRcTNa9m94C0Dozs/XnJjeKc9Fvj108AsUScF3rQmC9x4clNL73LLmqFncjSvAm+NX8bCe1EfM3OX/bv0yVO1GPPamn321cffM571jgudGv48mfUBnU/2FbxNCNPl29MkWHFk5KulL8o= 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=Jrd1pDWM; arc=fail smtp.client-ip=192.198.163.16 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="Jrd1pDWM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728556346; x=1760092346; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=ybaOv2ojJW7CwOeUTI7puwXRWFM1V1+uIvZzDLzNOR0=; b=Jrd1pDWMTwHTg+Ftf7dEcnZYoAHKJKusrsb9+hRd6m5WyF6MQq+SZmc5 VuzFCaQEcPSSqEEgxxi9AHTuKelOywJhCKUCMbLJQjjUUF5Vx8v1Vl4qf UmP/OqLjyEjcDJp5EuW+ZGRC2Wb3pNlTDbKX0CL7f5A9qG737yvDZ7f04 ueLIIfyQpiLwvo3je1SM3q3Zs79JGbRrOExxYuIwfBR9H684GpsTi2gXr LvRFFO3m7L6+UWeUteltmyZLlbyS0KJOm+mjaB+DfSzYXoMc0bZXIeAZ/ BeIid9c6DKT6nzZg8I8yjf8C8t34KVraqVTU62PdRUYlGo5rg4isJKlHq Q==; X-CSE-ConnectionGUID: Sa20o+bdQJ2LTkpN2f2cUg== X-CSE-MsgGUID: UyJ7aSeiT52Wo/GYZgTxsg== X-IronPort-AV: E=McAfee;i="6700,10204,11220"; a="15528446" X-IronPort-AV: E=Sophos;i="6.11,192,1725346800"; d="scan'208";a="15528446" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2024 03:32:26 -0700 X-CSE-ConnectionGUID: VeisuotSSoqWCy3d81VI8g== X-CSE-MsgGUID: qiOs39orTq2A4jEt31w1Fw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,192,1725346800"; d="scan'208";a="76751659" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orviesa006.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 10 Oct 2024 03:32:25 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) 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; Thu, 10 Oct 2024 03:32:25 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Thu, 10 Oct 2024 03:32:25 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.45) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 10 Oct 2024 03:32:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FBzyVQkaH46NE0mUJ0zRMwbHAktKDr4xo4NmrHgA7Op97Sy4+zq2RnDm7iiUrcdVfJa7dPrhzuXGzaZKxQTgzG7FF6NBMhhxspEUm5dwQsNwFBKzVEWHi3t51dCnSZoQ1hffeQo5QdRZyLNqHn9HerF/Ce97qY7h5TYcNfrwnh/nrtb+RipOWro3ClysWJcQUWkUdigTMYTtJsAoebbI0oD+wrhK60d9x+TrsjIheV8TJlvSXPGAiKNshX/XHVy1Tt3uuLOpjxy4nryimhBM7ABAKUs3/teB+ztzuebtzQF6vCh3uO70ywRBgRJStWE3AQKMPND6jEr0LV16p/9r9w== 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=G8RdkHf2rYc9zV3jfSuykZ0/1sP4SE+Beit5J1B6fNE=; b=xrqEW7gfqrxP3LsNip7QudfHVB8erwkhLG5RHnlyrEx8UiTSBmtH4Pz3VOagrDJSiutzGCz4+AquDSoakikgW35o1FTLHLzeHPnr+vBnCwvbHEh7zmEDhtFoSixrCvXqfjI7nM+NRZ+OhVBeP6w3w8mECVRaCuzrGOFQuF/pxue81R7eslcqPcEW/rRxi4Po5TphwP7wnGK5UdLQFBtzGrpUvwtEokpgKKsiraQwhhR+tFlUNdZdKn0L6JneSCSyi7sOaev/wATbxix5mdG4ciJu84tI4/Rr+67yTkql7sDhTlhkVKWITZu+6uGqqCXH2wwMhYmuVPcD4xEOpbe2tw== 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 MN6PR11MB8103.namprd11.prod.outlook.com (2603:10b6:208:473::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.22; Thu, 10 Oct 2024 10:32:23 +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.8048.013; Thu, 10 Oct 2024 10:32:22 +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 v3 3/5] PCI: Allow IOV resources to be resized in pci_resize_resource Date: Thu, 10 Oct 2024 12:32:01 +0200 Message-ID: <20241010103203.382898-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241010103203.382898-1-michal.winiarski@intel.com> References: <20241010103203.382898-1-michal.winiarski@intel.com> X-ClientProxiedBy: MI1P293CA0024.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:3::6) 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_|MN6PR11MB8103:EE_ X-MS-Office365-Filtering-Correlation-Id: 97c693b3-3926-4deb-1322-08dce916d38c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?zmhztpgNoW8mpe/VzwN13aYm1PI1lBB?= =?utf-8?q?jxiqQ8ek0FJGM9FqHbX0FLWgyDV4P9XeLMo9bTKIkdKd3EgjzSQd+NyKEJPv0JLWB?= =?utf-8?q?rBtIRUX7crOl2bAmUsrGlF0v90SSLjMAf7sqFrvpm8KTZmMditX8PjZluDgHft3Ua?= =?utf-8?q?KRR1U8LK/+S2dGRuV0gepSgXM/dsRS2cNx9sakNWXpavEV3b52ANUN1c+wlfcKKDv?= =?utf-8?q?fHnlDj7sCWrtuU9mBxE/90k/atwfUrOi0y61Q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HtsAidAe/iQMHkFSv9oTt7C?= =?utf-8?q?bbpyuI+iKx4QrBnP3Ge34wqfBHCORkgKDYmCiy+X/GGrqMCjVOesmGKZteTJb4OcW?= =?utf-8?q?eX7GnENnxOpH4Bjanm+aM+1rkZSqQm4cznIg=3D=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)(366016)(7416014)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?yccBlx4OZQfgVWlsRGBvsCVgA1oU?= =?utf-8?q?GPHluyC7wu4DRRpWhyI/P1nll4wKr8wGC2HB2Cq25bTRRw7+Fu85tHHUZ9gGgtWSm?= =?utf-8?q?RIFwRd/zlmOUiHMTqZGwZAyznMwewyLfXJVgo3/dPOrT/kmnsYBVqHSkrEzG9e6TN?= =?utf-8?q?vLLf0uElxB9YHdaYyAEVsyRVWOolZLkoMidSGmnxm0Sra78UsNoheQjUkOygaYxB5?= =?utf-8?q?NTKJNwzJVjNBG0BS56jNecN0xkRPx1PiwJf8RlHwe3gYjN5IRhgBr0xpBM5IJo+Th?= =?utf-8?q?nZ9j0iGP0trSNEAj9G2qHgZv73Dbzc+Msc3O4u9DX7OIIVlgxCQU+wqp2D0riWGY8?= =?utf-8?q?qHsYA5H5hE2XFNw6SRPa5/No1McEpk2hJdNSJwCKDddxS+5mdF1AiKYNU3WbtSJ0C?= =?utf-8?q?Mb06ImMSm12W/+2fs8Ch3pGE7JDtNAOPZtV5vUObFBYDN1Gho1BFz9VSqoI5PByle?= =?utf-8?q?5/O9jHcpvLv1Fov7AlH1RWaKKZyYhna9yTO+6ZOF7bvl+eIueo8tJb10ur8WotcF1?= =?utf-8?q?vH7aGUQiDwtTQohAzjo1Z2EmNXYB1H4DymGl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c/otvc6vO5HFUd1a126?= =?utf-8?q?BAneBgL145EptEwBAy0v35J74X4MnyBN4BnnqPN1fDqaScVAKIXzAt+STjHS+jRLx?= =?utf-8?q?sRYk3oiMvnESr/eMjtEx/lFXCurdby3Z0A=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 97c693b3-3926-4deb-1322-08dce916d38c X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 10:32:22.8536 (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: GQs655IqyfDqnVW72EGhn4fmOrcNfCLbm30t4ztwsyYSaH/Nd0LybMLiymkAjp4EgG991N+D9mapJjleq56bH5HZfAwg7mBK3s9S/3J1ioQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR11MB8103 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. See PCIe r4.0, sec 9.3.7.4. Signed-off-by: MichaƂ Winiarski --- drivers/pci/iov.c | 20 ++++++++++++++++++++ drivers/pci/pci.c | 9 ++++++++- drivers/pci/pci.h | 8 ++++++++ drivers/pci/setup-res.c | 33 ++++++++++++++++++++++++++++----- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index fd5c059b29c13..591a3eae1618a 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -154,6 +154,26 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) return dev->sriov->barsz[resno - PCI_IOV_RESOURCES]; } +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[resno - PCI_IOV_RESOURCES] = 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..788ae61731213 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3718,10 +3718,17 @@ void pci_acs_init(struct pci_dev *dev) */ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar) { + int cap = PCI_EXT_CAP_ID_REBAR; unsigned int pos, nbars, i; u32 ctrl; - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR); +#ifdef CONFIG_PCI_IOV + if (pci_resource_is_iov(bar)) { + cap = PCI_EXT_CAP_ID_VF_REBAR; + bar -= PCI_IOV_RESOURCES; + } +#endif + pos = pci_find_ext_capability(pdev, cap); if (!pos) return -ENOTSUPP; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index c55f2d7a4f37e..e15fd8fe0f81f 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -584,6 +584,8 @@ static inline bool pci_resource_is_iov(int resno) { return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END; } +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); extern const struct attribute_group sriov_pf_dev_attr_group; extern const struct attribute_group sriov_vf_dev_attr_group; #else @@ -607,6 +609,12 @@ static inline bool pci_resource_is_iov(int resno) { return false; } +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; +} #endif /* CONFIG_PCI_IOV */ #ifdef CONFIG_PCIE_PTM diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index e2cf79253ebda..95a13a5fa379c 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -425,13 +425,37 @@ 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 +466,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 +484,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 +496,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);