From patchwork Wed Mar 20 11:31:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13597795 X-Patchwork-Delegate: kw@linux.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 708593D566 for ; Wed, 20 Mar 2024 11:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934335; cv=none; b=pO788GSy6Xo0FZblzJaLI9tJWQlSmUxj3wdlaJjzxuCKHu8V69Je7gt7MCqf9JHWlBudrgYWQnlenDKnY1oJ6Rue/ADIbhr0mExaCZDjbW+duA1Qf8XlGqGnsfHzrFRrbhDt/v45VNhgbuJYlbyvQpSIoHQ0z7i5+UmRDObMUi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934335; c=relaxed/simple; bh=xucd+rDP+hLOY+Yk3qc1JEjN9Y3Q1WAwyxHnk72d2pE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NO3WayTlXz0q89RrPi6az4bN6ITrAHZEgdytwNKer9jql/0wcC9loXVaeKM8el+xxmLO+v62tOHBg8k22iD8xacqZNXuoCk6YMPyohNJ6S2leYEs2fDhMr4MBYBnzB64j5fLxgVVinq/TktghcYDAKLRhkv40Cv3S+Ux6aCHHLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S89AANju; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S89AANju" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA371C433C7; Wed, 20 Mar 2024 11:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710934334; bh=xucd+rDP+hLOY+Yk3qc1JEjN9Y3Q1WAwyxHnk72d2pE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S89AANjuMTQ9UJoxRMgeiRFpZvu2nbGulkDF/tkoxIS/WyovVkXD/drsXDbIZYGQh wvw5tNe2E9yWdYtWhb5MlATVVegL7kkCVdPThe4mqCG5Sgo/Q+JCL1eRhHNtNR3u7G EKWwhai/aboy/MI6MEWGmT4fM4z9l6bY6nskgh44aGWrxIivcS2W0SlbqzEH6v3x3X ts63/n//sLM1XK/sIJzS1w8reYJ/TsGCuYR83EhxWD9PMp5P+njqKDP2e9nLsm6e+M VgWYUo3ID7SI26TOYxlcw5AkBGLgFwzpiujlpkuIFGrnfZIna9+5uejulWceJVBJgH OM1/4n1n+GL3A== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v4 1/7] PCI: endpoint: pci-epf-test: Simplify pci_epf_test_alloc_space() loop Date: Wed, 20 Mar 2024 12:31:48 +0100 Message-ID: <20240320113157.322695-2-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320113157.322695-1-cassel@kernel.org> References: <20240320113157.322695-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make pci-epf-test use pci_epc_get_next_free_bar() just like pci-epf-ntb.c and pci-epf-vntb.c. Using pci_epc_get_next_free_bar() also makes it more obvious that pci-epf-test does no special configuration at all. (The only configuration pci-epf-test does is setting PCI_BASE_ADDRESS_MEM_TYPE_64 if epc_features has marked the specific BAR as only_64bit. pci_epc_get_next_free_bar() already takes only_64bit into account when looping.) This way, the code is more consistent between EPF drivers, and pci-epf-test does not need to explicitly check if the BAR is reserved, or if the index belongs to a BAR succeeding a 64-bit only BAR. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index cd4ffb39dcdc..16dfd61cd9fb 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -817,14 +817,13 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); struct device *dev = &epf->dev; - struct pci_epf_bar *epf_bar; size_t msix_table_size = 0; size_t test_reg_bar_size; size_t pba_size = 0; bool msix_capable; void *base; - int bar, add; enum pci_barno test_reg_bar = epf_test->test_reg_bar; + enum pci_barno bar; const struct pci_epc_features *epc_features; size_t test_reg_size; @@ -849,16 +848,14 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) } epf_test->reg[test_reg_bar] = base; - for (bar = 0; bar < PCI_STD_NUM_BARS; bar += add) { - epf_bar = &epf->bar[bar]; - add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; + for (bar = BAR_0; bar < PCI_STD_NUM_BARS; bar++) { + bar = pci_epc_get_next_free_bar(epc_features, bar); + if (bar == NO_BAR) + break; if (bar == test_reg_bar) continue; - if (epc_features->bar[bar].type == BAR_RESERVED) - continue; - base = pci_epf_alloc_space(epf, bar_size[bar], bar, epc_features, PRIMARY_INTERFACE); if (!base) From patchwork Wed Mar 20 11:31:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13597796 X-Patchwork-Delegate: kw@linux.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 135303D566 for ; Wed, 20 Mar 2024 11:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934338; cv=none; b=BYDKNic7vZ0NjMkPz0KYES2cskMT9UaD0jcPECWXgDCS6vJjEayPSN/aklU7m5SLIuM/oVr2dHAg0oD0C2R9i0CLKx82TzdJIrPQgd5nfo6cvyee3xaDcZuSbEV+LBMOWWshJE8nkK4SHTjsKVJHZIit/wVckvvSdRKBGQgDTNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934338; c=relaxed/simple; bh=X8GTmTOMsGGtNaPPdmCyGMfJX9TsguvdNZ5uoAo8URU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z/YlJvd33gDCMIuSOjKWcK/xjVKzefsUYEVql4bch5w+wlbvDL/Ed1gwjj36o9tyeTv3rz+ZAKQk6M1aiCdeJDc66u3RFEDlpUebpXaD67osLIhsyTRfk3XCjCd92KXUFEamssOtWVM1E90mwWBmlUDN/LByvmSO6w3CBo9UOJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cicb0NJw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cicb0NJw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98702C433B1; Wed, 20 Mar 2024 11:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710934337; bh=X8GTmTOMsGGtNaPPdmCyGMfJX9TsguvdNZ5uoAo8URU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cicb0NJwc15vbAu46x+unI6Qbshkd0oKe6E39mbJbiI1FIAZvh+f3VfougjSUOvRK fgRJI/QRnKu60fUVM4HY6fPEANj5KZ1TQHhBOlkfh+0chc9VJtVjzHXJzLpkQ/Ttok VmCCxWEHVnmO9lDM9WvQ3tZXm1v2dABfFm6Jc3IM7M/JAoVl4pYD/b2cM1d9R02SmR YVyyxJ7xuu0J1wLeVgI9zH4NWm/AQLWtp53hgLkkjQgvOyYCkKKwug/m6JhlMS2ep9 VRhz0CPruG+1dTJIn0kFZDEVgzSnXZLcuivUSfMk7zQlv2JLpdWKJSfJPHLEAxun+w /VS3b2L7Ck55Q== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v4 2/7] PCI: endpoint: Allocate a 64-bit BAR if that is the only option Date: Wed, 20 Mar 2024 12:31:49 +0100 Message-ID: <20240320113157.322695-3-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320113157.322695-1-cassel@kernel.org> References: <20240320113157.322695-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 pci_epf_alloc_space() already sets the 64-bit flag if the BAR size is larger than 2GB, even if the caller did not explicitly request a 64-bit BAR. Thus, let pci_epf_alloc_space() also set the 64-bit flag if the hardware description says that the specific BAR can only be 64-bit. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/pci-epf-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 0a28a0b0911b..323f2a60ab16 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -255,6 +255,8 @@ EXPORT_SYMBOL_GPL(pci_epf_free_space); * @type: Identifies if the allocation is for primary EPC or secondary EPC * * Invoke to allocate memory for the PCI EPF register space. + * Flag PCI_BASE_ADDRESS_MEM_TYPE_64 will automatically get set if the BAR + * can only be a 64-bit BAR, or if the requested size is larger than 2 GB. */ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, const struct pci_epc_features *epc_features, @@ -304,9 +306,10 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, epf_bar[bar].addr = space; epf_bar[bar].size = size; epf_bar[bar].barno = bar; - epf_bar[bar].flags |= upper_32_bits(size) ? - PCI_BASE_ADDRESS_MEM_TYPE_64 : - PCI_BASE_ADDRESS_MEM_TYPE_32; + if (upper_32_bits(size) || epc_features->bar[bar].only_64bit) + epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_TYPE_64; + else + epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_TYPE_32; return space; } From patchwork Wed Mar 20 11:31:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13597797 X-Patchwork-Delegate: kw@linux.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C28B13D566 for ; Wed, 20 Mar 2024 11:32:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934340; cv=none; b=EToFengQfHWdI5BpFPF/BcRe8PP9cDrQ6ZoH7m6vYdsR02bsMJTdOdh7TfbZ9X/0JiJ9r95+7yYMD7QJmTAwmjU+mSSOswK46p/kkNfWkgaEndQnXtLa2nC61vSQBjl9YfDpskNxnceqNr8UaGxaolY7M19B4L8dsexncSSxSyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934340; c=relaxed/simple; bh=DcG2wqFhyHctYhrJ0dTWozI4m+2msmP4B5/Lk5nblKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SswUYteLIu8xPAXLNUEW2BQdlSgzdi1FFIC7z5kTW6YpkQg5x9NkxonUEGNzV/CrO9iPS2cExiHvwMUMHzXBFLBSy3C0PzxL3qoOk5HJm/80Y/zxouwBWKrd1mA2/Z98S10z5Tr+wqmfsu0UvdIeFYnFmKTMNNXIUlBzs9E8YFk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S7Rx+bfD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S7Rx+bfD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 560DAC43394; Wed, 20 Mar 2024 11:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710934340; bh=DcG2wqFhyHctYhrJ0dTWozI4m+2msmP4B5/Lk5nblKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S7Rx+bfDZxyapbxwHzeW/i187E4eNMQSoCWyMmLlkkdGMvtfeRb12ur9MMCIEg4XS 3h0TmK9B3RQZkIo3b2nHumhuoFwr8XgdPS3XMemp5jjlFa6iKHQI6Yp6JW8daq2jgc DZTAINcTXXFhHBDnkvmOxDjvkA8v8fvM78eYfKa0zGmrorXInuZFxdgcoAHEtLjLsP NSjUGlXlCe/Sr4p/nT6ChsH85UTZ1FrpdVUyRa+9EH5pcG4TUNhhgeUoPG0FMRvaOk Omoq5CX7h7xNtjofnEakjwAO59iGwT6LJw9a1zX43A/rvP9yNhJVX0aK/1gxEZb1Rg ZiYE241SV5mMA== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v4 3/7] PCI: endpoint: pci-epf-test: Remove superfluous code Date: Wed, 20 Mar 2024 12:31:50 +0100 Message-ID: <20240320113157.322695-4-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320113157.322695-1-cassel@kernel.org> References: <20240320113157.322695-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The only reason why we call pci_epf_configure_bar() is to set PCI_BASE_ADDRESS_MEM_TYPE_64 in case the hardware requires it. However, this flag is now automatically set when allocating a BAR that can only be a 64-bit BAR, so we can drop pci_epf_configure_bar() completely. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 16dfd61cd9fb..0a83a1901bb7 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -867,19 +867,6 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) return 0; } -static void pci_epf_configure_bar(struct pci_epf *epf, - const struct pci_epc_features *epc_features) -{ - struct pci_epf_bar *epf_bar; - int i; - - for (i = 0; i < PCI_STD_NUM_BARS; i++) { - epf_bar = &epf->bar[i]; - if (epc_features->bar[i].only_64bit) - epf_bar->flags |= PCI_BASE_ADDRESS_MEM_TYPE_64; - } -} - static int pci_epf_test_bind(struct pci_epf *epf) { int ret; @@ -904,7 +891,6 @@ static int pci_epf_test_bind(struct pci_epf *epf) test_reg_bar = pci_epc_get_first_free_bar(epc_features); if (test_reg_bar < 0) return -EINVAL; - pci_epf_configure_bar(epf, epc_features); epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features; From patchwork Wed Mar 20 11:31:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13597798 X-Patchwork-Delegate: kw@linux.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4AD833D566 for ; Wed, 20 Mar 2024 11:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934343; cv=none; b=YdiaxrACD3HQoTBfSnyQDiO+1sqWBRCEJroZPSYEKDK1EsWJpGeSCSIoeOKn2J47SSWj3pvN2Lo0WmL9WO5t7mfwon0j6sg3myK2UuA++yOevWudKf28CtrtnO3fgtiDhzalqNYA2j2tyGb/P5TjLNX2U8yGVcNT1SyEwDSdqhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934343; c=relaxed/simple; bh=qlo8LE8aYFDw5YRRHFlCNqf9qXT2c3WiS0hz4pZjpUQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PvtkyLby/eRPD+AEc61FlDPXBNtzV/0S9mLErY4NkTDVbnRZYk6VtPHeLnXAA3ps3ISlfbpe4/K6l2QY0Qx3p/jYoFi1plCA+hoM5lckcLjOxdO0QvCnSwlIiGNU6B4MhkyTptObHAOxWF8y9e2kjubjOSOMfuGhcyGCVxYzDVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=reTeiKrb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="reTeiKrb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19080C433B1; Wed, 20 Mar 2024 11:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710934343; bh=qlo8LE8aYFDw5YRRHFlCNqf9qXT2c3WiS0hz4pZjpUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=reTeiKrboGTvlQY8Y1Wi3KZfzRh2S7Sqj/G+3Ybxl7cfxar8tV+B60t4248sYWPWD wy6uKv6I0srIqengbB6SDLMXMxgBzSUOkOqSW5FLOX/Ejl/AwtMqH4TbGhcRc+LQ1E PWoA0JGk0CO6IQ5Tb+y//j07cf+mUcnofds74yO1/Wyn4q7qUeuEQYyYRTXEIqzqRx xDmQKazQon4t0zmgf3v9gMp0FMinPUStepmGg4akkbeME7cYtsyLnJZLS2KVvys6aY XRCppTBfqxBgXWY8yHatTYsDzgs3OmPccMLizfXOhz4VriVpMxwhnTvzzkLQPMhJ8A 7Etq+zUe6Wpbw== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v4 4/7] PCI: endpoint: pci-epf-test: Simplify pci_epf_test_set_bar() loop Date: Wed, 20 Mar 2024 12:31:51 +0100 Message-ID: <20240320113157.322695-5-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320113157.322695-1-cassel@kernel.org> References: <20240320113157.322695-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Simplify the loop in pci_epf_test_set_bar(). If we allocated memory for the BAR, we need to call set_bar() for that BAR, if we did not allocated memory for that BAR, we need to skip. It is as simple as that. This also matches the logic in pci_epf_test_unbind(). A 64-bit BAR will still only be one allocation, with the BAR succeeding the 64-bit BAR being null. While at it, remove the misleading comment. A EPC .set_bar() callback should never change the epf_bar->flags. (E.g. to set a 64-bit BAR if we requested a 32-bit BAR.) A .set_bar() callback should do what we request it to do. If it can't satisfy the request, it should return an error. If platform has a specific requirement, e.g. that a certain BAR has to be a 64-bit BAR, then it should specify that by setting the .only_64bit flag for that specific BAR in epc_features->bar[], such that pci_epf_alloc_space() will return a epf_bar with the 64-bit flag set. (Such that .set_bar() will receive a request to set a 64-bit BAR.) Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 0a83a1901bb7..faf347216b6b 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -709,31 +709,18 @@ static void pci_epf_test_unbind(struct pci_epf *epf) static int pci_epf_test_set_bar(struct pci_epf *epf) { - int bar, add; - int ret; - struct pci_epf_bar *epf_bar; + int bar, ret; struct pci_epc *epc = epf->epc; struct device *dev = &epf->dev; struct pci_epf_test *epf_test = epf_get_drvdata(epf); enum pci_barno test_reg_bar = epf_test->test_reg_bar; - const struct pci_epc_features *epc_features; - epc_features = epf_test->epc_features; - - for (bar = 0; bar < PCI_STD_NUM_BARS; bar += add) { - epf_bar = &epf->bar[bar]; - /* - * pci_epc_set_bar() sets PCI_BASE_ADDRESS_MEM_TYPE_64 - * if the specific implementation required a 64-bit BAR, - * even if we only requested a 32-bit BAR. - */ - add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; - - if (epc_features->bar[bar].type == BAR_RESERVED) + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + if (!epf_test->reg[bar]) continue; ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, - epf_bar); + &epf->bar[bar]); if (ret) { pci_epf_free_space(epf, epf_test->reg[bar], bar, PRIMARY_INTERFACE); From patchwork Wed Mar 20 11:31:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13597799 X-Patchwork-Delegate: kw@linux.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 630A73D566 for ; Wed, 20 Mar 2024 11:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934346; cv=none; b=qAktlsIO21XQUckqxfudjjUNYsYQEyodUotm2fRx0pS4JQW2UX2r85oeC7SgY6+rxD15Oxfh7okri1Epy818N4kxmvD8KQH/7bnY+6wXYINBDqAHQA8CQi/v+4UtP/tPfkLzHpKtoazIwRod6DlkziQWMisCoDRiawscVdls9r4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934346; c=relaxed/simple; bh=tVAqwOdolhcvEOaLQbkQAkdXLif+OLVmPn3t1h9ZWBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g5LJxjd9BqWxnnaEQo05dr3yPNVc8ZeyuGvzBX6pNFbHkWqEPPPbZXMvpCFLKhbbQu7VDdMy52q2ny551g51xFfsd0DYfbY/GagOdZaDY137SIxGDQEXVM//5wIi9ZVbO5bICve6f5u7kGJnzWe35YouWUarFBRPVF6Deydr8zc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q8rLxR+J; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q8rLxR+J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE2D9C433F1; Wed, 20 Mar 2024 11:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710934345; bh=tVAqwOdolhcvEOaLQbkQAkdXLif+OLVmPn3t1h9ZWBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q8rLxR+JG1VBO/fmY46p/WNwWSwLzcCJzyQyR6ybrxFzm6JgmWN13VN2vOuXS5bAI IHmXHOL+w8KKZq+cgwbk/TJbSNCKjGy2Carz4RPk2WWze2SQuzL7gsWIbCebmRNFnq JFaQCfDm7+Nsas6Dm5ISUW9sWQ5+7U925e6qrITImxU/G2dBaA1f/AkUqabxu3vJqG g+OMW3amlyiP1Efrz/0EsxJ/lgS/UoQSZfgKRNOhQc+MEiSczwJf8WL/88heSXagKr M2PndR+xO0knzE2ezl94H6ABKkYcR/176baS+0C3CEqMFtShiMNNarj4Ii2YkLPZ2N 1IhQK8D2BmItg== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v4 5/7] PCI: endpoint: pci-epf-test: Clean up pci_epf_test_unbind() Date: Wed, 20 Mar 2024 12:31:52 +0100 Message-ID: <20240320113157.322695-6-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320113157.322695-1-cassel@kernel.org> References: <20240320113157.322695-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Clean up pci_epf_test_unbind() by using a continue if we did not allocate memory for the BAR index. This reduces the indentation level by one. This makes pci_epf_test_unbind() more similar to pci_epf_test_set_bar(). Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index faf347216b6b..d244a5083d04 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -690,20 +690,18 @@ static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); struct pci_epc *epc = epf->epc; - struct pci_epf_bar *epf_bar; int bar; cancel_delayed_work(&epf_test->cmd_handler); pci_epf_test_clean_dma_chan(epf_test); for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { - epf_bar = &epf->bar[bar]; + if (!epf_test->reg[bar]) + continue; - if (epf_test->reg[bar]) { - pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, - epf_bar); - pci_epf_free_space(epf, epf_test->reg[bar], bar, - PRIMARY_INTERFACE); - } + pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, + &epf->bar[bar]); + pci_epf_free_space(epf, epf_test->reg[bar], bar, + PRIMARY_INTERFACE); } } From patchwork Wed Mar 20 11:31:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13597800 X-Patchwork-Delegate: kw@linux.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B3F063D961 for ; Wed, 20 Mar 2024 11:32:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934348; cv=none; b=gUPBhzc4VbLslDIvEVpqslCLVO/0/JYwU7Q4Q67WQ3sBd+gSRxcTqwIsFY4gaUFk4yK5Ds9BoI7/s52lTm0aRpvLdLAIrVqeWL4AQ6KOemHQeIHocSNMG37ak8kBFophPbQ166IRehbJUfIXPGmEX58UvNihsw1MzcsFhIslK94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934348; c=relaxed/simple; bh=ZMXXAd43rYk7lswNbM6lIgq88PzjCi6FS81oQyedQPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qXc6Fxz8nDUA7fJXEVAcfFo7ssgicc+seDDd7P8LLjHV5sjnRcU1Lf2Yj1C8PvTzFr8VDiBAlARhyb+mAtTCabmNcojII2WE/fx2M7ZBeX4PVJ18K7KY51F2P24egMneR/2qfylAmG6EQZTei0Ilhn0DtcYWbSV7X0DsaEo83qU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VEcpMUl9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VEcpMUl9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8ABEDC433F1; Wed, 20 Mar 2024 11:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710934348; bh=ZMXXAd43rYk7lswNbM6lIgq88PzjCi6FS81oQyedQPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VEcpMUl9n9MeIv6rL8etLPAh/SloUKza+EalKpNtB1/UAIhaPTNVEPQF3djJEvfZP 2v0RpTV2RblinD0tpJGQZMMvlDc9vCjy/TOsAkz+eRLlgKslFO6pwui96BnLIah6K2 /YpRB+I53nDK6jfsOEBkL2vyc4ytlwFctP7yMoMKPFZFlhiGSBDGViYfgGrMq1+Pnw 4EZu/YOc7fRU2gmABSkSo64VO04d8ewzVLTCGdm3Wr3n/GdQucMNJsJ3lu0wvbBDOA T4XD7PvNcv5T76wCToshQ/mUNbeR+kRvKJpyz45NiRD8D2y/Oe8/GsnfFK9rI4r7D3 FAp2k3EsEsHrA== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v4 6/7] PCI: cadence: Set a 64-bit BAR if requested Date: Wed, 20 Mar 2024 12:31:53 +0100 Message-ID: <20240320113157.322695-7-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320113157.322695-1-cassel@kernel.org> References: <20240320113157.322695-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Ever since commit f25b5fae29d4 ("PCI: endpoint: Setting a BAR size > 4 GB is invalid if 64-bit flag is not set") it has been impossible to get the .set_bar() callback with a BAR size > 2 GB (yes, 2GB!), if the BAR was also not requested to be configured as a 64-bit BAR. Thus, forcing setting the 64-bit flag for BARs larger than 2 GB in the lower level driver is dead code and can be removed. It is however possible that an EPF driver configures a BAR as 64-bit, even if the requested size is < 4 GB. Respect the requested BAR configuration, just like how it is already repected with regards to the prefetchable bit. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/cadence/pcie-cadence-ep.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/pci/controller/cadence/pcie-cadence-ep.c b/drivers/pci/controller/cadence/pcie-cadence-ep.c index 2d0a8d78bffb..de10e5edd1b0 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-ep.c +++ b/drivers/pci/controller/cadence/pcie-cadence-ep.c @@ -99,14 +99,11 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, u8 vfn, ctrl = CDNS_PCIE_LM_BAR_CFG_CTRL_IO_32BITS; } else { bool is_prefetch = !!(flags & PCI_BASE_ADDRESS_MEM_PREFETCH); - bool is_64bits = sz > SZ_2G; + bool is_64bits = !!(flags & PCI_BASE_ADDRESS_MEM_TYPE_64); if (is_64bits && (bar & 1)) return -EINVAL; - if (is_64bits && !(flags & PCI_BASE_ADDRESS_MEM_TYPE_64)) - epf_bar->flags |= PCI_BASE_ADDRESS_MEM_TYPE_64; - if (is_64bits && is_prefetch) ctrl = CDNS_PCIE_LM_BAR_CFG_CTRL_PREFETCH_MEM_64BITS; else if (is_prefetch) From patchwork Wed Mar 20 11:31:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13597801 X-Patchwork-Delegate: kw@linux.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A080B3D961 for ; Wed, 20 Mar 2024 11:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934352; cv=none; b=apHe5e4nKpGCkRaV+RbwuHO7vzW9Qg7AuYFL0IXr6PKLF3sD3OCYPED88Ln4Wc1i/BARm7sx4vzVgEt653pdbqJEIK5PqYKB2CyA2sguvseQp4xfaKIItJJNGL/hXfHTxDquJtSKdBpc0QpeJQxTszJHA5d7j7HO33dcYpMtiJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934352; c=relaxed/simple; bh=q66K0XDfqa4FH1mzvBlDGOW/HIb2nk503TpvzVrO3uw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ETO6m/APr4BkxBRcGQR8ZNTv23c30J894oUREqRfQuSColonZP1B119Qy+gnQ6Q1cWBS9YRfsDMyjL52buZaHvDCKwkCzRIpPjetr+/RIKaBBdC1MlFjtJd2qOwU3TQZVYVHvtE54uufKxncbBOJL+HLIv/fiuaFVmqYmXLIXbM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b0z853G/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b0z853G/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A65BC433B1; Wed, 20 Mar 2024 11:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710934352; bh=q66K0XDfqa4FH1mzvBlDGOW/HIb2nk503TpvzVrO3uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b0z853G/KCqIKbAzHMyET5yPiC7NK9lhx6S1JnpJ9Bn8BYyNrNZtk2RWP/rw2QKGZ 4/wlPBkWWEsHZ7UVFUbIYaOCWcJHakfF12kS1JMAMdzAHEXAguURm59a7Rkt5DHvzj SbkbieyE2zIIXHVDLLvQR0uSCJ1ybo2901O1svpFTIiq6Wm2IMfzPEVdUq3F3dm6Ae x8dYsbKKphtdT8cCnOb2jF0NRVezO5BlHl5zviXSG+n2hVOvQlwMorxgPxE8B1U9e1 B5lyaIClz7Ot/n1M1vf8TOY0IXZRtApjsRYNtfkAeMBkcRXts0NNLIbPUCQPTQsj7W h0mQZgU+k+SxA== From: Niklas Cassel To: Manivannan Sadhasivam , Shawn Lin , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Bjorn Helgaas , Heiko Stuebner Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 7/7] PCI: rockchip-ep: Set a 64-bit BAR if requested Date: Wed, 20 Mar 2024 12:31:54 +0100 Message-ID: <20240320113157.322695-8-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320113157.322695-1-cassel@kernel.org> References: <20240320113157.322695-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Ever since commit f25b5fae29d4 ("PCI: endpoint: Setting a BAR size > 4 GB is invalid if 64-bit flag is not set") it has been impossible to get the .set_bar() callback with a BAR size > 2 GB (yes, 2GB!), if the BAR was also not requested to be configured as a 64-bit BAR. It is however possible that an EPF driver configures a BAR as 64-bit, even if the requested size is < 4 GB. Respect the requested BAR configuration, just like how it is already repected with regards to the prefetchable bit. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/pcie-rockchip-ep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/controller/pcie-rockchip-ep.c b/drivers/pci/controller/pcie-rockchip-ep.c index c9046e97a1d2..57472cf48997 100644 --- a/drivers/pci/controller/pcie-rockchip-ep.c +++ b/drivers/pci/controller/pcie-rockchip-ep.c @@ -153,7 +153,7 @@ static int rockchip_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, u8 vfn, ctrl = ROCKCHIP_PCIE_CORE_BAR_CFG_CTRL_IO_32BITS; } else { bool is_prefetch = !!(flags & PCI_BASE_ADDRESS_MEM_PREFETCH); - bool is_64bits = sz > SZ_2G; + bool is_64bits = !!(flags & PCI_BASE_ADDRESS_MEM_TYPE_64); if (is_64bits && (bar & 1)) return -EINVAL;