diff mbox

[v2] PCI: don't UNSET valid resources when reassign fails

Message ID 1403179096-12113-1-git-send-email-yan@linux.vnet.ibm.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Guo Chao June 19, 2014, 11:58 a.m. UTC
Commit bd064f0a sets IORESOURCE_UNSET flag if resources can not be
assgined. Part of these changes breaks resource assignment.

If resource is too big, PCI core assgins basic part first and
extends (reassigns) it to include optional part (notably SR-IOV resources).
In this case, IORESOURCE_UNSET should not be set if resource is properly
assigned before reassigning. Otherwise, these resources are never updated
to hardware and we will see errors like this:

	pci 0003:00:00.0: can't enable device: BAR 15 [mem size 0x0c000000 64bit pref] not assigned
	pci 0003:00:00.0: Error enabling bridge (-22), continuing

Signed-off-by: Guo Chao <yan@linux.vnet.ibm.com>
---
Changed from v1: don't clear IORESOURCE_UNSET unconditionally
---
 drivers/pci/setup-res.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index caed1ce..2022f49 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -321,9 +321,14 @@  int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsiz
 {
 	struct resource *res = dev->resource + resno;
 	resource_size_t new_size;
-	int ret;
+	int ret, valid;
+
+	if (!(res->flags & IORESOURCE_UNSET)) {
+		valid = 1;
+		res->flags |= IORESOURCE_UNSET;
+	} else
+		valid = 0;
 
-	res->flags |= IORESOURCE_UNSET;
 	if (!res->parent) {
 		dev_info(&dev->dev, "BAR %d: can't reassign an unassigned resource %pR\n",
 			 resno, res);
@@ -339,7 +344,9 @@  int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsiz
 		dev_info(&dev->dev, "BAR %d: reassigned %pR\n", resno, res);
 		if (resno < PCI_BRIDGE_RESOURCES)
 			pci_update_resource(dev, resno);
-	}
+	} else if (valid)
+		res->flags &= ~IORESOURCE_UNSET;
+
 	return ret;
 }