From: Ram Pai <linuxram@us.ibm.com>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Ram Pai <linuxram@us.ibm.com>, Yinghai Lu <yinghai@kernel.org>,
Don Dutile <ddutile@redhat.com>,
linux-pci@vger.kernel.org,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Nishanth Aravamudan <nacc@us.ibm.com>,
prarit@redhat.com, brking@linux.vnet.ibm.com
Subject: [PATCH 1/1 v2]PCI: defer enablement of SRIOV BARS
Date: Fri, 9 Dec 2011 18:04:28 +0800 [thread overview]
Message-ID: <20111209100428.GB3763@ram-ThinkPad-T61> (raw)
In-Reply-To: <20111208055355.19c346a8@jbarnes-desktop>
PCI: defer enablement of SRIOV BARS
All the PCI BARs of a device are enabled when the device is enabled using
pci_enable_device(). This unnecessarily enables SRIOV BARs of the device.
On some platforms, which do not support SRIOV; as yet, the pci_enable_device()
fails to enable the device if its SRIOV BARs are not allocated resources
correctly.
The following patch fixes the above problem. The SRIOV BARs are now enabled
when IOV capability of the device is enabled in sriov_enable().
NOTE: Note, there is subtle change in the pci_enable_device() API. Any driver
that depends on SRIOV BARS to be enabled in pci_enable_device() can fail.
Changelog v2: Fixed a bug reported by Yinghai.The bug lead to ROM and
BRIDGE BARs getting disabled. Thanks for code snippets from Yinghai
and Don Dutile.
Signed-off-by: Ram Pai <linuxram@us.ibm.com
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 9b4e88c..b0446dd 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -282,6 +282,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
struct resource *res;
struct pci_dev *pdev;
struct pci_sriov *iov = dev->sriov;
+ int bars = 0;
if (!nr_virtfn)
return 0;
@@ -306,6 +307,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
nres = 0;
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
+ bars |= (1 << (i + PCI_IOV_RESOURCES));
res = dev->resource + PCI_IOV_RESOURCES + i;
if (res->parent)
nres++;
@@ -323,6 +325,11 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
return -ENOMEM;
}
+ if (pci_enable_resources(dev, bars)) {
+ dev_err(&dev->dev, "SR-IOV: IOV BARS not allocated\n");
+ return -ENOMEM;
+ }
+
if (iov->link != dev->devfn) {
pdev = pci_get_slot(dev->bus, iov->link);
if (!pdev)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 6f45a73..b548bec 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1126,9 +1126,14 @@ static int __pci_enable_device_flags(struct pci_dev *dev,
if (atomic_add_return(1, &dev->enable_cnt) > 1)
return 0; /* already enabled */
- for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
+ for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
+#ifdef CONFIG_PCI_IOV
+ if ((i >= PCI_IOV_RESOURCES) && (i <= PCI_IOV_RESOURCE_END))
+ continue; /* skip sriov related resources */
+#endif
if (dev->resource[i].flags & flags)
bars |= (1 << i);
+ }
err = do_pci_enable_device(dev, bars);
if (err < 0)
next prev parent reply other threads:[~2011-12-09 10:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20111006210320.GA14959@us.ibm.com>
[not found] ` <CAErSpo7b_6_AaZXW9XBx5p3-0PZJk-1jeCork__KePdzCS89OA@mail.gmail.com>
[not found] ` <1317970100.29415.305.camel@pasglop>
[not found] ` <CAErSpo58okGsDW4dOK4i0g_RUejkuQa=iw2uQ5HAJJZCwFtsbw@mail.gmail.com>
[not found] ` <20111007232516.GF2980@ram-ThinkPad-T61>
[not found] ` <1318057168.29415.333.camel@pasglop>
[not found] ` <20111008075353.GK2980@ram-ThinkPad-T61>
[not found] ` <1318060793.29415.347.camel@pasglop>
[not found] ` <20111102140325.004b9dad@jbarnes-desktop>
[not found] ` <20111103013014.GB393@ram-ThinkPad-T61>
[not found] ` <20111106023310.GA2383@ram-ThinkPad-T61>
2011-11-11 18:01 ` [RFC PATCH 1/1]PCI: defer enablement of SRIOV BARS Jesse Barnes
2011-11-14 4:33 ` Ram Pai
2011-11-14 4:56 ` Michael Wang
2011-12-05 18:32 ` Jesse Barnes
2011-12-07 8:22 ` Yinghai Lu
2011-12-07 9:25 ` Ram Pai
2011-12-07 19:33 ` Yinghai Lu
2011-12-07 20:23 ` Don Dutile
2011-12-07 20:35 ` Nishanth Aravamudan
2011-12-07 22:34 ` Don Dutile
2011-12-07 23:11 ` Yinghai Lu
2011-12-08 2:50 ` Ram Pai
2011-12-08 13:53 ` Jesse Barnes
2011-12-08 16:59 ` Yinghai Lu
2011-12-09 10:04 ` Ram Pai [this message]
2011-12-08 16:22 ` Don Dutile
[not found] ` <20111106023357.GB2383@ram-ThinkPad-T61>
2011-12-05 18:17 ` [RFC PATCH 1/1] PCI:delay configuration of SRIOV capability Jesse Barnes
2011-12-05 21:25 ` Don Dutile
2011-12-06 7:51 ` Ram Pai
2011-12-06 9:14 ` Don Dutile
2011-12-05 21:37 ` Jesse Barnes
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=20111209100428.GB3763@ram-ThinkPad-T61 \
--to=linuxram@us.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=bhelgaas@google.com \
--cc=brking@linux.vnet.ibm.com \
--cc=ddutile@redhat.com \
--cc=jbarnes@virtuousgeek.org \
--cc=linux-pci@vger.kernel.org \
--cc=nacc@us.ibm.com \
--cc=prarit@redhat.com \
--cc=yinghai@kernel.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