linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Gavin Shan <gwshan@linux.vnet.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: benh@kernel.crashing.org, paulus@samba.org, aik@ozlabs.ru,
	Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: [PATCH 1/2] powerpc/powernv: Fix alignment for IOV BAR
Date: Fri, 17 Jul 2015 10:14:42 +1000	[thread overview]
Message-ID: <1437092083-20672-2-git-send-email-gwshan@linux.vnet.ibm.com> (raw)
In-Reply-To: <1437092083-20672-1-git-send-email-gwshan@linux.vnet.ibm.com>

IOV BAR is extended to cover 256 VFs or number of supported VFs,
the alignment is the IOV BAR size, which is usually huge and bigger
than M64 segment size (256MB). That means the IOV BAR is expected
to be assigned to the beginning of PHB's M64 window prior to other
M64 BARs in PCI devices that are hooked to the PCI bus behind root
port. Other M64 BARs actually need M64 segment size other than the
huge IOV BAR size as the required alignment.

The patch returns M64 segment size if IOV BAR size is bigger than
it when the PF seats behind root port. Otherwise, the IOV BAR size
is returned as before. It will save lots of consumed M64 space,
which would be 16GB in some cases as I observed.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 35 +++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index fdafbac..6ec62b9 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -2961,16 +2961,39 @@ static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,
 static resource_size_t pnv_pci_iov_resource_alignment(struct pci_dev *pdev,
 						      int resno)
 {
+	struct pci_controller *hose = pci_bus_to_host(pdev->bus);
+	struct pnv_phb *phb = hose->private_data;
 	struct pci_dn *pdn = pci_get_pdn(pdev);
-	resource_size_t align, iov_align;
+	resource_size_t align;
+	resource_size_t m64_segsz = phb->ioda.m64_segsize;
 
-	iov_align = resource_size(&pdev->resource[resno]);
-	if (iov_align)
-		return iov_align;
+	/*
+	 * When PF is the only one adapter under the PHB, the IOV BAR
+	 * is expected to be assigned prior to any other M64 BARs. To
+	 * have M64 segment size, which is usually smaller than IOV
+	 * BAR size, as the alignment to avoid wasting M64 space to
+	 * satisfy the alignment required by other M64 BARs.
+	 */
+	align = resource_size(&pdev->resource[resno]);
+	if (align) {
+		if (!pci_bus_is_root(pdev->bus) &&
+		    pci_bus_is_root(pdev->bus->self->bus))
+			align = min(align, m64_segsz);
+		else
+			align = max(align, m64_segsz);
+
+		return align;
+	}
 
 	align = pci_iov_resource_size(pdev, resno);
-	if (pdn->vfs_expanded)
-		return pdn->vfs_expanded * align;
+	if (pdn->vfs_expanded) {
+		align = pdn->vfs_expanded * align;
+		if (!pci_bus_is_root(pdev->bus) &&
+		    pci_bus_is_root(pdev->bus->self->bus))
+			align = min(align, m64_segsz);
+		else
+			align = max(align, m64_segsz);
+	}
 
 	return align;
 }
-- 
2.1.0

  reply	other threads:[~2015-07-17  0:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-17  0:14 [PATCH 0/2] powerpc/powernv: Avoid compound PE for VF Gavin Shan
2015-07-17  0:14 ` Gavin Shan [this message]
2015-07-17  0:14 ` [PATCH 2/2] powerpc/powernv: Double VF BAR size for compound PE Gavin Shan
2015-07-17  0:28   ` Gavin Shan
2015-07-29 23:06 ` [PATCH 0/2] powerpc/powernv: Avoid compound PE for VF Gavin Shan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1437092083-20672-2-git-send-email-gwshan@linux.vnet.ibm.com \
    --to=gwshan@linux.vnet.ibm.com \
    --cc=aik@ozlabs.ru \
    --cc=benh@kernel.crashing.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).