Commit 9b6a3df3 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6:
  PCI SR-IOV: correct broken resource alignment calculations
parents d3acd16c 6faf17f6
...@@ -597,6 +597,29 @@ int pci_iov_resource_bar(struct pci_dev *dev, int resno, ...@@ -597,6 +597,29 @@ int pci_iov_resource_bar(struct pci_dev *dev, int resno,
4 * (resno - PCI_IOV_RESOURCES); 4 * (resno - PCI_IOV_RESOURCES);
} }
/**
* pci_sriov_resource_alignment - get resource alignment for VF BAR
* @dev: the PCI device
* @resno: the resource number
*
* Returns the alignment of the VF BAR found in the SR-IOV capability.
* This is not the same as the resource size which is defined as
* the VF BAR size multiplied by the number of VFs. The alignment
* is just the VF BAR size.
*/
int pci_sriov_resource_alignment(struct pci_dev *dev, int resno)
{
struct resource tmp;
enum pci_bar_type type;
int reg = pci_iov_resource_bar(dev, resno, &type);
if (!reg)
return 0;
__pci_read_base(dev, type, &tmp, reg);
return resource_alignment(&tmp);
}
/** /**
* pci_restore_iov_state - restore the state of the IOV capability * pci_restore_iov_state - restore the state of the IOV capability
* @dev: the PCI device * @dev: the PCI device
......
...@@ -243,6 +243,7 @@ extern int pci_iov_init(struct pci_dev *dev); ...@@ -243,6 +243,7 @@ extern int pci_iov_init(struct pci_dev *dev);
extern void pci_iov_release(struct pci_dev *dev); extern void pci_iov_release(struct pci_dev *dev);
extern int pci_iov_resource_bar(struct pci_dev *dev, int resno, extern int pci_iov_resource_bar(struct pci_dev *dev, int resno,
enum pci_bar_type *type); enum pci_bar_type *type);
extern int pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
extern void pci_restore_iov_state(struct pci_dev *dev); extern void pci_restore_iov_state(struct pci_dev *dev);
extern int pci_iov_bus_range(struct pci_bus *bus); extern int pci_iov_bus_range(struct pci_bus *bus);
...@@ -298,4 +299,16 @@ static inline int pci_ats_enabled(struct pci_dev *dev) ...@@ -298,4 +299,16 @@ static inline int pci_ats_enabled(struct pci_dev *dev)
} }
#endif /* CONFIG_PCI_IOV */ #endif /* CONFIG_PCI_IOV */
static inline int pci_resource_alignment(struct pci_dev *dev,
struct resource *res)
{
#ifdef CONFIG_PCI_IOV
int resno = res - dev->resource;
if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
return pci_sriov_resource_alignment(dev, resno);
#endif
return resource_alignment(res);
}
#endif /* DRIVERS_PCI_H */ #endif /* DRIVERS_PCI_H */
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "pci.h"
static void pbus_assign_resources_sorted(const struct pci_bus *bus) static void pbus_assign_resources_sorted(const struct pci_bus *bus)
{ {
...@@ -384,7 +384,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long ...@@ -384,7 +384,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long
continue; continue;
r_size = resource_size(r); r_size = resource_size(r);
/* For bridges size != alignment */ /* For bridges size != alignment */
align = resource_alignment(r); align = pci_resource_alignment(dev, r);
order = __ffs(align) - 20; order = __ffs(align) - 20;
if (order > 11) { if (order > 11) {
dev_warn(&dev->dev, "BAR %d bad alignment %llx: " dev_warn(&dev->dev, "BAR %d bad alignment %llx: "
......
...@@ -144,7 +144,7 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev, ...@@ -144,7 +144,7 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
size = resource_size(res); size = resource_size(res);
min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM; min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
align = resource_alignment(res); align = pci_resource_alignment(dev, res);
/* First, try exact prefetching match.. */ /* First, try exact prefetching match.. */
ret = pci_bus_alloc_resource(bus, res, size, align, min, ret = pci_bus_alloc_resource(bus, res, size, align, min,
...@@ -178,7 +178,7 @@ int pci_assign_resource(struct pci_dev *dev, int resno) ...@@ -178,7 +178,7 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
struct pci_bus *bus; struct pci_bus *bus;
int ret; int ret;
align = resource_alignment(res); align = pci_resource_alignment(dev, res);
if (!align) { if (!align) {
dev_info(&dev->dev, "BAR %d: can't allocate resource (bogus " dev_info(&dev->dev, "BAR %d: can't allocate resource (bogus "
"alignment) %pR flags %#lx\n", "alignment) %pR flags %#lx\n",
...@@ -259,7 +259,7 @@ void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head) ...@@ -259,7 +259,7 @@ void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
if (!(r->flags) || r->parent) if (!(r->flags) || r->parent)
continue; continue;
r_align = resource_alignment(r); r_align = pci_resource_alignment(dev, r);
if (!r_align) { if (!r_align) {
dev_warn(&dev->dev, "BAR %d: bogus alignment " dev_warn(&dev->dev, "BAR %d: bogus alignment "
"%pR flags %#lx\n", "%pR flags %#lx\n",
...@@ -271,7 +271,7 @@ void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head) ...@@ -271,7 +271,7 @@ void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
struct resource_list *ln = list->next; struct resource_list *ln = list->next;
if (ln) if (ln)
align = resource_alignment(ln->res); align = pci_resource_alignment(ln->dev, ln->res);
if (r_align > align) { if (r_align > align) {
tmp = kmalloc(sizeof(*tmp), GFP_KERNEL); tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment