powerpc/powernv: Reserve additional space for IOV BAR, with m64_per_iov supported
authorWei Yang <weiyang@linux.vnet.ibm.com>
Wed, 25 Mar 2015 08:23:58 +0000 (16:23 +0800)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Tue, 31 Mar 2015 02:02:38 +0000 (13:02 +1100)
M64 aperture size is limited on PHB3.  When the IOV BAR is too big, this
will exceed the limitation and failed to be assigned.

Introduce a different mechanism based on the IOV BAR size:

  - if IOV BAR size is smaller than 64MB, expand to total_pe
  - if IOV BAR size is bigger than 64MB, roundup power2

[bhelgaas: make dev_printk() output more consistent, use PCI_SRIOV_NUM_BARS]
Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/include/asm/pci-bridge.h
arch/powerpc/platforms/powernv/pci-ioda.c

index 8716db48e9461a8bdd5924cf3e12aa11d243f3af..415df8509f5207b7463ec06877c867f0b7d218de 100644 (file)
@@ -182,6 +182,8 @@ struct pci_dn {
        u16     vfs_expanded;           /* number of VFs IOV BAR expanded */
        u16     num_vfs;                /* number of VFs enabled*/
        int     offset;                 /* PE# for the first VF PE */
+#define M64_PER_IOV 4
+       int     m64_per_iov;
 #define IODA_INVALID_M64        (-1)
        int     m64_wins[PCI_SRIOV_NUM_BARS];
 #endif /* CONFIG_PCI_IOV */
index 5187d164cfe1331d46101154bedfce215ebe8a07..b63925f483fc36d19c6ed7c0af5eb4281c6424e7 100644 (file)
@@ -2250,6 +2250,7 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)
        int i;
        resource_size_t size;
        struct pci_dn *pdn;
+       int mul, total_vfs;
 
        if (!pdev->is_physfn || pdev->is_added)
                return;
@@ -2260,6 +2261,32 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)
        pdn = pci_get_pdn(pdev);
        pdn->vfs_expanded = 0;
 
+       total_vfs = pci_sriov_get_totalvfs(pdev);
+       pdn->m64_per_iov = 1;
+       mul = phb->ioda.total_pe;
+
+       for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
+               res = &pdev->resource[i + PCI_IOV_RESOURCES];
+               if (!res->flags || res->parent)
+                       continue;
+               if (!pnv_pci_is_mem_pref_64(res->flags)) {
+                       dev_warn(&pdev->dev, " non M64 VF BAR%d: %pR\n",
+                                i, res);
+                       continue;
+               }
+
+               size = pci_iov_resource_size(pdev, i + PCI_IOV_RESOURCES);
+
+               /* bigger than 64M */
+               if (size > (1 << 26)) {
+                       dev_info(&pdev->dev, "PowerNV: VF BAR%d: %pR IOV size is bigger than 64M, roundup power2\n",
+                                i, res);
+                       pdn->m64_per_iov = M64_PER_IOV;
+                       mul = roundup_pow_of_two(total_vfs);
+                       break;
+               }
+       }
+
        for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
                res = &pdev->resource[i + PCI_IOV_RESOURCES];
                if (!res->flags || res->parent)
@@ -2272,12 +2299,12 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)
 
                dev_dbg(&pdev->dev, " Fixing VF BAR%d: %pR to\n", i, res);
                size = pci_iov_resource_size(pdev, i + PCI_IOV_RESOURCES);
-               res->end = res->start + size * phb->ioda.total_pe - 1;
+               res->end = res->start + size * mul - 1;
                dev_dbg(&pdev->dev, "                       %pR\n", res);
                dev_info(&pdev->dev, "VF BAR%d: %pR (expanded to %d VFs for PE alignment)",
-                               i, res, phb->ioda.total_pe);
+                        i, res, mul);
        }
-       pdn->vfs_expanded = phb->ioda.total_pe;
+       pdn->vfs_expanded = mul;
 }
 #endif /* CONFIG_PCI_IOV */