|
@@ -54,24 +54,29 @@ static inline void pci_iov_set_numvfs(struct pci_dev *dev, int nr_virtfn)
|
|
* The PF consumes one bus number. NumVFs, First VF Offset, and VF Stride
|
|
* The PF consumes one bus number. NumVFs, First VF Offset, and VF Stride
|
|
* determine how many additional bus numbers will be consumed by VFs.
|
|
* determine how many additional bus numbers will be consumed by VFs.
|
|
*
|
|
*
|
|
- * Iterate over all valid NumVFs and calculate the maximum number of bus
|
|
|
|
- * numbers that could ever be required.
|
|
|
|
|
|
+ * Iterate over all valid NumVFs, validate offset and stride, and calculate
|
|
|
|
+ * the maximum number of bus numbers that could ever be required.
|
|
*/
|
|
*/
|
|
-static inline u8 virtfn_max_buses(struct pci_dev *dev)
|
|
|
|
|
|
+static int compute_max_vf_buses(struct pci_dev *dev)
|
|
{
|
|
{
|
|
struct pci_sriov *iov = dev->sriov;
|
|
struct pci_sriov *iov = dev->sriov;
|
|
- int nr_virtfn;
|
|
|
|
- u8 max = 0;
|
|
|
|
- int busnr;
|
|
|
|
|
|
+ int nr_virtfn, busnr, rc = 0;
|
|
|
|
|
|
- for (nr_virtfn = 1; nr_virtfn <= iov->total_VFs; nr_virtfn++) {
|
|
|
|
|
|
+ for (nr_virtfn = iov->total_VFs; nr_virtfn; nr_virtfn--) {
|
|
pci_iov_set_numvfs(dev, nr_virtfn);
|
|
pci_iov_set_numvfs(dev, nr_virtfn);
|
|
|
|
+ if (!iov->offset || (nr_virtfn > 1 && !iov->stride)) {
|
|
|
|
+ rc = -EIO;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
busnr = pci_iov_virtfn_bus(dev, nr_virtfn - 1);
|
|
busnr = pci_iov_virtfn_bus(dev, nr_virtfn - 1);
|
|
- if (busnr > max)
|
|
|
|
- max = busnr;
|
|
|
|
|
|
+ if (busnr > iov->max_VF_buses)
|
|
|
|
+ iov->max_VF_buses = busnr;
|
|
}
|
|
}
|
|
|
|
|
|
- return max;
|
|
|
|
|
|
+out:
|
|
|
|
+ pci_iov_set_numvfs(dev, 0);
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
static struct pci_bus *virtfn_add_bus(struct pci_bus *bus, int busnr)
|
|
static struct pci_bus *virtfn_add_bus(struct pci_bus *bus, int busnr)
|
|
@@ -222,21 +227,25 @@ static void virtfn_remove(struct pci_dev *dev, int id, int reset)
|
|
|
|
|
|
int __weak pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
|
|
int __weak pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
|
|
{
|
|
{
|
|
- return 0;
|
|
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int __weak pcibios_sriov_disable(struct pci_dev *pdev)
|
|
|
|
+{
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
|
|
static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
|
|
{
|
|
{
|
|
int rc;
|
|
int rc;
|
|
- int i, j;
|
|
|
|
|
|
+ int i;
|
|
int nres;
|
|
int nres;
|
|
- u16 offset, stride, initial;
|
|
|
|
|
|
+ u16 initial;
|
|
struct resource *res;
|
|
struct resource *res;
|
|
struct pci_dev *pdev;
|
|
struct pci_dev *pdev;
|
|
struct pci_sriov *iov = dev->sriov;
|
|
struct pci_sriov *iov = dev->sriov;
|
|
int bars = 0;
|
|
int bars = 0;
|
|
int bus;
|
|
int bus;
|
|
- int retval;
|
|
|
|
|
|
|
|
if (!nr_virtfn)
|
|
if (!nr_virtfn)
|
|
return 0;
|
|
return 0;
|
|
@@ -253,11 +262,6 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
|
|
(!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial)))
|
|
(!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial)))
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_OFFSET, &offset);
|
|
|
|
- pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_STRIDE, &stride);
|
|
|
|
- if (!offset || (nr_virtfn > 1 && !stride))
|
|
|
|
- return -EIO;
|
|
|
|
-
|
|
|
|
nres = 0;
|
|
nres = 0;
|
|
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
|
|
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
|
|
bars |= (1 << (i + PCI_IOV_RESOURCES));
|
|
bars |= (1 << (i + PCI_IOV_RESOURCES));
|
|
@@ -270,9 +274,6 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
|
|
- iov->offset = offset;
|
|
|
|
- iov->stride = stride;
|
|
|
|
-
|
|
|
|
bus = pci_iov_virtfn_bus(dev, nr_virtfn - 1);
|
|
bus = pci_iov_virtfn_bus(dev, nr_virtfn - 1);
|
|
if (bus > dev->bus->busn_res.end) {
|
|
if (bus > dev->bus->busn_res.end) {
|
|
dev_err(&dev->dev, "can't enable %d VFs (bus %02x out of range of %pR)\n",
|
|
dev_err(&dev->dev, "can't enable %d VFs (bus %02x out of range of %pR)\n",
|
|
@@ -313,10 +314,10 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
|
|
if (nr_virtfn < initial)
|
|
if (nr_virtfn < initial)
|
|
initial = nr_virtfn;
|
|
initial = nr_virtfn;
|
|
|
|
|
|
- if ((retval = pcibios_sriov_enable(dev, initial))) {
|
|
|
|
- dev_err(&dev->dev, "failure %d from pcibios_sriov_enable()\n",
|
|
|
|
- retval);
|
|
|
|
- return retval;
|
|
|
|
|
|
+ rc = pcibios_sriov_enable(dev, initial);
|
|
|
|
+ if (rc) {
|
|
|
|
+ dev_err(&dev->dev, "failure %d from pcibios_sriov_enable()\n", rc);
|
|
|
|
+ goto err_pcibios;
|
|
}
|
|
}
|
|
|
|
|
|
for (i = 0; i < initial; i++) {
|
|
for (i = 0; i < initial; i++) {
|
|
@@ -331,27 +332,24 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
failed:
|
|
failed:
|
|
- for (j = 0; j < i; j++)
|
|
|
|
- virtfn_remove(dev, j, 0);
|
|
|
|
|
|
+ while (i--)
|
|
|
|
+ virtfn_remove(dev, i, 0);
|
|
|
|
|
|
|
|
+ pcibios_sriov_disable(dev);
|
|
|
|
+err_pcibios:
|
|
iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
|
|
iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
|
|
pci_cfg_access_lock(dev);
|
|
pci_cfg_access_lock(dev);
|
|
pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
|
|
pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
|
|
- pci_iov_set_numvfs(dev, 0);
|
|
|
|
ssleep(1);
|
|
ssleep(1);
|
|
pci_cfg_access_unlock(dev);
|
|
pci_cfg_access_unlock(dev);
|
|
|
|
|
|
if (iov->link != dev->devfn)
|
|
if (iov->link != dev->devfn)
|
|
sysfs_remove_link(&dev->dev.kobj, "dep_link");
|
|
sysfs_remove_link(&dev->dev.kobj, "dep_link");
|
|
|
|
|
|
|
|
+ pci_iov_set_numvfs(dev, 0);
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
|
|
-int __weak pcibios_sriov_disable(struct pci_dev *pdev)
|
|
|
|
-{
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static void sriov_disable(struct pci_dev *dev)
|
|
static void sriov_disable(struct pci_dev *dev)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
@@ -384,7 +382,7 @@ static int sriov_init(struct pci_dev *dev, int pos)
|
|
int rc;
|
|
int rc;
|
|
int nres;
|
|
int nres;
|
|
u32 pgsz;
|
|
u32 pgsz;
|
|
- u16 ctrl, total, offset, stride;
|
|
|
|
|
|
+ u16 ctrl, total;
|
|
struct pci_sriov *iov;
|
|
struct pci_sriov *iov;
|
|
struct resource *res;
|
|
struct resource *res;
|
|
struct pci_dev *pdev;
|
|
struct pci_dev *pdev;
|
|
@@ -399,10 +397,6 @@ static int sriov_init(struct pci_dev *dev, int pos)
|
|
ssleep(1);
|
|
ssleep(1);
|
|
}
|
|
}
|
|
|
|
|
|
- pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &total);
|
|
|
|
- if (!total)
|
|
|
|
- return 0;
|
|
|
|
-
|
|
|
|
ctrl = 0;
|
|
ctrl = 0;
|
|
list_for_each_entry(pdev, &dev->bus->devices, bus_list)
|
|
list_for_each_entry(pdev, &dev->bus->devices, bus_list)
|
|
if (pdev->is_physfn)
|
|
if (pdev->is_physfn)
|
|
@@ -414,11 +408,10 @@ static int sriov_init(struct pci_dev *dev, int pos)
|
|
|
|
|
|
found:
|
|
found:
|
|
pci_write_config_word(dev, pos + PCI_SRIOV_CTRL, ctrl);
|
|
pci_write_config_word(dev, pos + PCI_SRIOV_CTRL, ctrl);
|
|
- pci_write_config_word(dev, pos + PCI_SRIOV_NUM_VF, 0);
|
|
|
|
- pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &offset);
|
|
|
|
- pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &stride);
|
|
|
|
- if (!offset || (total > 1 && !stride))
|
|
|
|
- return -EIO;
|
|
|
|
|
|
+
|
|
|
|
+ pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &total);
|
|
|
|
+ if (!total)
|
|
|
|
+ return 0;
|
|
|
|
|
|
pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &pgsz);
|
|
pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &pgsz);
|
|
i = PAGE_SHIFT > 12 ? PAGE_SHIFT - 12 : 0;
|
|
i = PAGE_SHIFT > 12 ? PAGE_SHIFT - 12 : 0;
|
|
@@ -436,8 +429,15 @@ found:
|
|
nres = 0;
|
|
nres = 0;
|
|
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
|
|
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
|
|
res = &dev->resource[i + PCI_IOV_RESOURCES];
|
|
res = &dev->resource[i + PCI_IOV_RESOURCES];
|
|
- bar64 = __pci_read_base(dev, pci_bar_unknown, res,
|
|
|
|
- pos + PCI_SRIOV_BAR + i * 4);
|
|
|
|
|
|
+ /*
|
|
|
|
+ * If it is already FIXED, don't change it, something
|
|
|
|
+ * (perhaps EA or header fixups) wants it this way.
|
|
|
|
+ */
|
|
|
|
+ if (res->flags & IORESOURCE_PCI_FIXED)
|
|
|
|
+ bar64 = (res->flags & IORESOURCE_MEM_64) ? 1 : 0;
|
|
|
|
+ else
|
|
|
|
+ bar64 = __pci_read_base(dev, pci_bar_unknown, res,
|
|
|
|
+ pos + PCI_SRIOV_BAR + i * 4);
|
|
if (!res->flags)
|
|
if (!res->flags)
|
|
continue;
|
|
continue;
|
|
if (resource_size(res) & (PAGE_SIZE - 1)) {
|
|
if (resource_size(res) & (PAGE_SIZE - 1)) {
|
|
@@ -456,8 +456,6 @@ found:
|
|
iov->nres = nres;
|
|
iov->nres = nres;
|
|
iov->ctrl = ctrl;
|
|
iov->ctrl = ctrl;
|
|
iov->total_VFs = total;
|
|
iov->total_VFs = total;
|
|
- iov->offset = offset;
|
|
|
|
- iov->stride = stride;
|
|
|
|
iov->pgsz = pgsz;
|
|
iov->pgsz = pgsz;
|
|
iov->self = dev;
|
|
iov->self = dev;
|
|
pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
|
|
pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
|
|
@@ -474,10 +472,15 @@ found:
|
|
|
|
|
|
dev->sriov = iov;
|
|
dev->sriov = iov;
|
|
dev->is_physfn = 1;
|
|
dev->is_physfn = 1;
|
|
- iov->max_VF_buses = virtfn_max_buses(dev);
|
|
|
|
|
|
+ rc = compute_max_vf_buses(dev);
|
|
|
|
+ if (rc)
|
|
|
|
+ goto fail_max_buses;
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
+fail_max_buses:
|
|
|
|
+ dev->sriov = NULL;
|
|
|
|
+ dev->is_physfn = 0;
|
|
failed:
|
|
failed:
|
|
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
|
|
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
|
|
res = &dev->resource[i + PCI_IOV_RESOURCES];
|
|
res = &dev->resource[i + PCI_IOV_RESOURCES];
|