From: Yu Zhao Subject: Xen SR-IOV support initiation Date: Fri, 13 Mar 2009 11:29:15 +0800 Message-ID: <20090313032915.GA19927@yzhao-otc.sh.intel.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="9jxsPFA5p3P2qPhR" Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: keir.fraser@eu.citrix.com List-Id: xen-devel@lists.xenproject.org --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Greetings, Following commits from the upstream kernel are backported to the Domain0 kernel as the first step of enabling Xen SR-IOV. Hopefully the SR-IOV core patches for the upstream kernel would be applied on the PCI subsystem tree in the next several days. Will backport them immediately they are in-tree so Xen 3.4 release could have the SR-IOV support. PCI: define PCI resource names in an 'enum' PCI: remove unnecessary condition check in pci_restore_bars() PCI: add a new function to map BAR offsets PCI: rewrite PCI BAR reading code PCI: handle 64-bit resources better on 32-bit machines PCI: fix 64-vbit prefetchable memory resource BARs PCI: export __pci_read_base() PCI: support PCIe ARI capability PCI: fix ARI code to be compatible with mixed ARI/non-ARI systems PCI: enhance pci_ari_enabled() PCI: allow pci_alloc_child_bus() to handle a NULL bridge PCI: remove unnecessary arg of pci_update_resource() drivers/pci/pci-sysfs.c | 4 drivers/pci/pci.c | 104 +++++++++++++------ drivers/pci/pci.h | 29 ++++- drivers/pci/probe.c | 252 ++++++++++++++++++++++++++++------------------- drivers/pci/proc.c | 7 - drivers/pci/quirks.c | 2 drivers/pci/setup-res.c | 20 +-- include/linux/pci.h | 40 ++++--- include/linux/pci_regs.h | 15 ++ 9 files changed, 310 insertions(+), 163 deletions(-) --- The SR-IOV specification (requires membership) can be found at: * http://www.pcisig.com/members/downloads/specifications/iov/sr-iov1.0_11Sep07.pdf The latest SR-IOV core patches for the upstream kernel are: PCI: initialize and release SR-IOV capability * http://patchwork.kernel.org/patch/11062/ PCI: restore saved SR-IOV state * http://patchwork.kernel.org/patch/11063/ PCI: reserve bus range for SR-IOV device * http://patchwork.kernel.org/patch/11064/ PCI: centralize device setup code * http://patchwork.kernel.org/patch/11065/ PCI: add SR-IOV API for Physical Function driver * http://patchwork.kernel.org/patch/11070/ PCI: handle SR-IOV Virtual Function Migration * http://patchwork.kernel.org/patch/11066/ PCI: document SR-IOV sysfs entries * http://patchwork.kernel.org/patch/11068/ PCI: manual for SR-IOV user and driver developer * http://patchwork.kernel.org/patch/11069/ Intel 82576 Gigabit Ethernet Controller datasheet is available at: * http://download.intel.com/design/network/datashts/82576_Datasheet.pdf The patches to enable the SR-IOV capability of Intel 82576 NIC are available at (a.k.a Physical Function driver): * http://patchwork.kernel.org/patch/8063/ * http://patchwork.kernel.org/patch/8064/ * http://patchwork.kernel.org/patch/8065/ * http://patchwork.kernel.org/patch/8066/ And the driver for Intel 82576 Virtual Function is available at: * http://patchwork.kernel.org/patch/11029/ * http://patchwork.kernel.org/patch/11028/ --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="1.patch" # HG changeset patch # User Yu Zhao # Date 1236909107 14400 # Node ID 7f81d57622ccb390212d1c76308664115ae3a955 # Parent 0430b1dbfb3af5f374921b903c96b9b3234cd77c Backport: PCI: rewrite PCI BAR reading code commit 6ac665c63dcac8fcec534a1d224ecbb8b867ad59 Author: Matthew Wilcox Date: Mon Jul 28 13:38:59 2008 -0400 PCI: rewrite PCI BAR reading code Factor out the code to read one BAR from the loop in pci_read_bases into a new function, __pci_read_base. The new code is slightly more readable, better commented and removes the ifdef. Signed-off-by: Matthew Wilcox Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r 0430b1dbfb3a -r 7f81d57622cc drivers/pci/probe.c --- a/drivers/pci/probe.c Fri Mar 06 12:51:33 2009 +0000 +++ b/drivers/pci/probe.c Thu Mar 12 21:51:47 2009 -0400 @@ -123,12 +123,9 @@ return IORESOURCE_MEM; } -/* - * Find the extent of a PCI decode.. - */ -static u32 pci_size(u32 base, u32 maxbase, u32 mask) +static u64 pci_size(u64 base, u64 maxbase, u64 mask) { - u32 size = mask & maxbase; /* Find the significant bits */ + u64 size = mask & maxbase; /* Find the significant bits */ if (!size) return 0; @@ -144,91 +141,141 @@ return size; } +enum pci_bar_type { + pci_bar_unknown, /* Standard PCI BAR probe */ + pci_bar_io, /* An io port BAR */ + pci_bar_mem32, /* A 32-bit memory BAR */ + pci_bar_mem64, /* A 64-bit memory BAR */ +}; + +static inline enum pci_bar_type decode_bar(struct resource *res, u32 bar) +{ + if ((bar & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) { + res->flags = bar & ~PCI_BASE_ADDRESS_IO_MASK; + return pci_bar_io; + } + + res->flags = bar & ~PCI_BASE_ADDRESS_MEM_MASK; + + if (res->flags == PCI_BASE_ADDRESS_MEM_TYPE_64) + return pci_bar_mem64; + return pci_bar_mem32; +} + +/* + * If the type is not unknown, we assume that the lowest bit is 'enable'. + * Returns 1 if the BAR was 64-bit and 0 if it was 32-bit. + */ +static int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, + struct resource *res, unsigned int pos) +{ + u32 l, sz, mask; + + mask = type ? ~PCI_ROM_ADDRESS_ENABLE : ~0; + + res->name = pci_name(dev); + + pci_read_config_dword(dev, pos, &l); + pci_write_config_dword(dev, pos, mask); + pci_read_config_dword(dev, pos, &sz); + pci_write_config_dword(dev, pos, l); + + /* + * All bits set in sz means the device isn't working properly. + * If the BAR isn't implemented, all bits must be 0. If it's a + * memory BAR or a ROM, bit 0 must be clear; if it's an io BAR, bit + * 1 must be clear. + */ + if (!sz || sz == 0xffffffff) + goto fail; + + /* + * I don't know how l can have all bits set. Copied from old code. + * Maybe it fixes a bug on some ancient platform. + */ + if (l == 0xffffffff) + l = 0; + + if (type == pci_bar_unknown) { + type = decode_bar(res, l); + res->flags |= pci_calc_resource_flags(l); + if (type == pci_bar_io) { + l &= PCI_BASE_ADDRESS_IO_MASK; + mask = PCI_BASE_ADDRESS_IO_MASK & 0xffff; + } else { + l &= PCI_BASE_ADDRESS_MEM_MASK; + mask = (u32)PCI_BASE_ADDRESS_MEM_MASK; + } + } else { + res->flags |= (l & IORESOURCE_ROM_ENABLE); + l &= PCI_ROM_ADDRESS_MASK; + mask = (u32)PCI_ROM_ADDRESS_MASK; + } + + if (type == pci_bar_mem64) { + u64 l64 = l; + u64 sz64 = sz; + u64 mask64 = mask | (u64)~0 << 32; + + pci_read_config_dword(dev, pos + 4, &l); + pci_write_config_dword(dev, pos + 4, ~0); + pci_read_config_dword(dev, pos + 4, &sz); + pci_write_config_dword(dev, pos + 4, l); + + l64 |= ((u64)l << 32); + sz64 |= ((u64)sz << 32); + + sz64 = pci_size(l64, sz64, mask64); + + if (!sz64) + goto fail; + + if ((BITS_PER_LONG < 64) && (sz64 > 0x100000000ULL)) { + dev_err(&dev->dev, "can't handle 64-bit BAR\n"); + goto fail; + } else if ((BITS_PER_LONG < 64) && l) { + /* Address above 32-bit boundary; disable the BAR */ + pci_write_config_dword(dev, pos, 0); + pci_write_config_dword(dev, pos + 4, 0); + res->start = 0; + res->end = sz64; + } else { + res->start = l64; + res->end = l64 + sz64; + } + } else { + sz = pci_size(l, sz, mask); + + if (!sz) + goto fail; + + res->start = l; + res->end = l + sz; + } + + out: + return (type == pci_bar_mem64) ? 1 : 0; + fail: + res->flags = 0; + goto out; +} + static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) { - unsigned int pos, reg, next; - u32 l, sz; - struct resource *res; + unsigned int pos, reg; - for(pos=0; posresource[pos]; - res->name = pci_name(dev); + for (pos = 0; pos < howmany; pos++) { + struct resource *res = &dev->resource[pos]; reg = PCI_BASE_ADDRESS_0 + (pos << 2); - pci_read_config_dword(dev, reg, &l); - pci_write_config_dword(dev, reg, ~0); - pci_read_config_dword(dev, reg, &sz); - pci_write_config_dword(dev, reg, l); - if (!sz || sz == 0xffffffff) - continue; - if (l == 0xffffffff) - l = 0; - if ((l & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY) { - sz = pci_size(l, sz, (u32)PCI_BASE_ADDRESS_MEM_MASK); - if (!sz) - continue; - res->start = l & PCI_BASE_ADDRESS_MEM_MASK; - res->flags |= l & ~PCI_BASE_ADDRESS_MEM_MASK; - } else { - sz = pci_size(l, sz, PCI_BASE_ADDRESS_IO_MASK & 0xffff); - if (!sz) - continue; - res->start = l & PCI_BASE_ADDRESS_IO_MASK; - res->flags |= l & ~PCI_BASE_ADDRESS_IO_MASK; - } - res->end = res->start + (unsigned long) sz; - res->flags |= pci_calc_resource_flags(l); - if ((l & (PCI_BASE_ADDRESS_SPACE | PCI_BASE_ADDRESS_MEM_TYPE_MASK)) - == (PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64)) { - u32 szhi, lhi; - pci_read_config_dword(dev, reg+4, &lhi); - pci_write_config_dword(dev, reg+4, ~0); - pci_read_config_dword(dev, reg+4, &szhi); - pci_write_config_dword(dev, reg+4, lhi); - szhi = pci_size(lhi, szhi, 0xffffffff); - next++; -#if BITS_PER_LONG == 64 - res->start |= ((unsigned long) lhi) << 32; - res->end = res->start + sz; - if (szhi) { - /* This BAR needs > 4GB? Wow. */ - res->end |= (unsigned long)szhi<<32; - } -#else - if (szhi) { - printk(KERN_ERR "PCI: Unable to handle 64-bit BAR for device %s\n", pci_name(dev)); - res->start = 0; - res->flags = 0; - } else if (lhi) { - /* 64-bit wide address, treat as disabled */ - pci_write_config_dword(dev, reg, l & ~(u32)PCI_BASE_ADDRESS_MEM_MASK); - pci_write_config_dword(dev, reg+4, 0); - res->start = 0; - res->end = sz; - } -#endif - } + pos += __pci_read_base(dev, pci_bar_unknown, res, reg); } + if (rom) { + struct resource *res = &dev->resource[PCI_ROM_RESOURCE]; dev->rom_base_reg = rom; - res = &dev->resource[PCI_ROM_RESOURCE]; - res->name = pci_name(dev); - pci_read_config_dword(dev, rom, &l); - pci_write_config_dword(dev, rom, ~PCI_ROM_ADDRESS_ENABLE); - pci_read_config_dword(dev, rom, &sz); - pci_write_config_dword(dev, rom, l); - if (l == 0xffffffff) - l = 0; - if (sz && sz != 0xffffffff) { - sz = pci_size(l, sz, (u32)PCI_ROM_ADDRESS_MASK); - if (sz) { - res->flags = (l & IORESOURCE_ROM_ENABLE) | - IORESOURCE_MEM | IORESOURCE_PREFETCH | - IORESOURCE_READONLY | IORESOURCE_CACHEABLE; - res->start = l & PCI_ROM_ADDRESS_MASK; - res->end = res->start + (unsigned long) sz; - } - } + res->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH | + IORESOURCE_READONLY | IORESOURCE_CACHEABLE; + __pci_read_base(dev, pci_bar_mem32, res, rom); } } --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="2.patch" # HG changeset patch # User Yu Zhao # Date 1236909173 14400 # Node ID 8bac898877bc9fb52befd566bbb8f04c190006f4 # Parent 7f81d57622ccb390212d1c76308664115ae3a955 Backport: PCI: handle 64-bit resources better on 32-bit machines commit cc5499c3a607a392e8a7adb934aaf14b2c6a3519 Author: Matthew Wilcox Date: Mon Jul 28 13:39:00 2008 -0400 PCI: handle 64-bit resources better on 32-bit machines If the kernel is configured to support 64-bit resources on a 32-bit machine, we can support 64-bit BARs properly. Just change the condition to check sizeof(resource_size_t) instead of BITS_PER_LONG. Signed-off-by: Matthew Wilcox Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r 7f81d57622cc -r 8bac898877bc drivers/pci/probe.c --- a/drivers/pci/probe.c Thu Mar 12 21:51:47 2009 -0400 +++ b/drivers/pci/probe.c Thu Mar 12 21:52:53 2009 -0400 @@ -230,10 +230,10 @@ if (!sz64) goto fail; - if ((BITS_PER_LONG < 64) && (sz64 > 0x100000000ULL)) { + if ((sizeof(resource_size_t) < 8) && (sz64 > 0x100000000ULL)) { dev_err(&dev->dev, "can't handle 64-bit BAR\n"); goto fail; - } else if ((BITS_PER_LONG < 64) && l) { + } else if ((sizeof(resource_size_t) < 8) && l) { /* Address above 32-bit boundary; disable the BAR */ pci_write_config_dword(dev, pos, 0); pci_write_config_dword(dev, pos + 4, 0); --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="3.patch" # HG changeset patch # User Yu Zhao # Date 1236909216 14400 # Node ID 8de852cacf43ac03f7f4819589bc22f62a8d1b3c # Parent 8bac898877bc9fb52befd566bbb8f04c190006f4 Backport: PCI: fix 64-vbit prefetchable memory resource BARs commit e354597cce8d219d135d65e585dc4f30323486b9 Author: Peter Chubb Date: Mon Oct 13 11:49:04 2008 +1100 PCI: fix 64-vbit prefetchable memory resource BARs Since patch 6ac665c63dcac8fcec534a1d224ecbb8b867ad59 my infiniband controller hasn't worked. This is because it has 64-bit prefetchable memory, which was mistakenly being taken to be 32-bit memory. The resource flags in this case are PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH. This patch checks only for the PCI_BASE_ADDRESS_MEM_TYPE_64 bit; thus whether the region is prefetchable or not is ignored. This fixes my Infiniband. Reviewed-by: Matthew Wilcox Signed-off-by: Peter Chubb Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r 8bac898877bc -r 8de852cacf43 drivers/pci/probe.c --- a/drivers/pci/probe.c Thu Mar 12 21:52:53 2009 -0400 +++ b/drivers/pci/probe.c Thu Mar 12 21:53:36 2009 -0400 @@ -157,7 +157,7 @@ res->flags = bar & ~PCI_BASE_ADDRESS_MEM_MASK; - if (res->flags == PCI_BASE_ADDRESS_MEM_TYPE_64) + if (res->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) return pci_bar_mem64; return pci_bar_mem32; } --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="4.patch" # HG changeset patch # User Yu Zhao # Date 1236909313 14400 # Node ID 66f3de153185eddae2d118d088ecfc17e96bf706 # Parent 8de852cacf43ac03f7f4819589bc22f62a8d1b3c Backport: PCI: export __pci_read_base() commit 0b400c7ed4d027e02f6231afa39852a2d48e6f25 Author: Yu Zhao Date: Sat Nov 22 02:40:40 2008 +0800 PCI: export __pci_read_base() Export __pci_read_base() so it can be used by whole PCI subsystem. Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r 8de852cacf43 -r 66f3de153185 drivers/pci/pci.h --- a/drivers/pci/pci.h Thu Mar 12 21:53:36 2009 -0400 +++ b/drivers/pci/pci.h Thu Mar 12 21:55:13 2009 -0400 @@ -109,3 +109,13 @@ #ifdef CONFIG_PCI_GUESTDEV int pci_is_guestdev_to_reassign(struct pci_dev *dev); #endif /* CONFIG_PCI_GUESTDEV */ + +enum pci_bar_type { + pci_bar_unknown, /* Standard PCI BAR probe */ + pci_bar_io, /* An io port BAR */ + pci_bar_mem32, /* A 32-bit memory BAR */ + pci_bar_mem64, /* A 64-bit memory BAR */ +}; + +extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, + struct resource *res, unsigned int reg); diff -r 8de852cacf43 -r 66f3de153185 drivers/pci/probe.c --- a/drivers/pci/probe.c Thu Mar 12 21:53:36 2009 -0400 +++ b/drivers/pci/probe.c Thu Mar 12 21:55:13 2009 -0400 @@ -141,13 +141,6 @@ return size; } -enum pci_bar_type { - pci_bar_unknown, /* Standard PCI BAR probe */ - pci_bar_io, /* An io port BAR */ - pci_bar_mem32, /* A 32-bit memory BAR */ - pci_bar_mem64, /* A 64-bit memory BAR */ -}; - static inline enum pci_bar_type decode_bar(struct resource *res, u32 bar) { if ((bar & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) { @@ -162,11 +155,16 @@ return pci_bar_mem32; } -/* - * If the type is not unknown, we assume that the lowest bit is 'enable'. - * Returns 1 if the BAR was 64-bit and 0 if it was 32-bit. +/** + * pci_read_base - read a PCI BAR + * @dev: the PCI device + * @type: type of the BAR + * @res: resource buffer to be filled in + * @pos: BAR position in the config space + * + * Returns 1 if the BAR is 64-bit, or 0 if 32-bit. */ -static int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, +int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, struct resource *res, unsigned int pos) { u32 l, sz, mask; --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="5.patch" # HG changeset patch # User Yu Zhao # Date 1236909443 14400 # Node ID 313310b824c81e803a698ee3a1a8a94075096060 # Parent 66f3de153185eddae2d118d088ecfc17e96bf706 Backport: PCI: support PCIe ARI capability commit 58c3a727cb73b75a9104d295f096cca12959a5a5 Author: Yu Zhao Date: Tue Oct 14 14:02:53 2008 +0800 PCI: support PCIe ARI capability This patch adds support for PCI Express Alternative Routing-ID Interpretation (ARI) capability. The ARI capability extends the Function Number field of the PCI Express Endpoint by reusing the Device Number which is otherwise hardwired to 0. With ARI, an Endpoint can have up to 256 functions. Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r 66f3de153185 -r 313310b824c8 drivers/pci/pci.c --- a/drivers/pci/pci.c Thu Mar 12 21:55:13 2009 -0400 +++ b/drivers/pci/pci.c Thu Mar 12 21:57:23 2009 -0400 @@ -629,6 +629,38 @@ return 0; } +/** + * pci_enable_ari - enable ARI forwarding if hardware support it + * @dev: the PCI device + */ +void pci_enable_ari(struct pci_dev *dev) +{ + int pos; + u32 cap; + u16 ctrl; + + if (!dev->is_pcie) + return; + + if (dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && + dev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) + return; + + pos = pci_find_capability(dev, PCI_CAP_ID_EXP); + if (!pos) + return; + + pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap); + if (!(cap & PCI_EXP_DEVCAP2_ARI)) + return; + + pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); + ctrl |= PCI_EXP_DEVCTL2_ARI; + pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); + + dev->ari_enabled = 1; +} + int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge) { diff -r 66f3de153185 -r 313310b824c8 drivers/pci/pci.h --- a/drivers/pci/pci.h Thu Mar 12 21:55:13 2009 -0400 +++ b/drivers/pci/pci.h Thu Mar 12 21:57:23 2009 -0400 @@ -119,3 +119,14 @@ extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, struct resource *res, unsigned int reg); +extern void pci_enable_ari(struct pci_dev *dev); +/** + * pci_ari_enabled - query ARI forwarding status + * @dev: the PCI device + * + * Returns 1 if ARI forwarding is enabled, or 0 if not enabled; + */ +static inline int pci_ari_enabled(struct pci_dev *dev) +{ + return dev->ari_enabled; +} diff -r 66f3de153185 -r 313310b824c8 drivers/pci/probe.c --- a/drivers/pci/probe.c Thu Mar 12 21:55:13 2009 -0400 +++ b/drivers/pci/probe.c Thu Mar 12 21:57:23 2009 -0400 @@ -885,6 +885,9 @@ /* Fix up broken headers */ pci_fixup_device(pci_fixup_header, dev); + /* Alternative Routing-ID Forwarding */ + pci_enable_ari(dev); + /* * Add the device to our list of discovered devices * and the bus list for fixup functions, etc. diff -r 66f3de153185 -r 313310b824c8 include/linux/pci.h --- a/include/linux/pci.h Thu Mar 12 21:55:13 2009 -0400 +++ b/include/linux/pci.h Thu Mar 12 21:57:23 2009 -0400 @@ -172,6 +172,7 @@ struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */ int rom_attr_enabled; /* has display of the rom attribute been enabled? */ struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */ + unsigned int ari_enabled:1; /* ARI forwarding */ }; #define pci_dev_g(n) list_entry(n, struct pci_dev, global_list) diff -r 66f3de153185 -r 313310b824c8 include/linux/pci_regs.h --- a/include/linux/pci_regs.h Thu Mar 12 21:55:13 2009 -0400 +++ b/include/linux/pci_regs.h Thu Mar 12 21:57:23 2009 -0400 @@ -378,6 +378,10 @@ #define PCI_EXP_RTCTL_CRSSVE 0x10 /* CRS Software Visibility Enable */ #define PCI_EXP_RTCAP 30 /* Root Capabilities */ #define PCI_EXP_RTSTA 32 /* Root Status */ +#define PCI_EXP_DEVCAP2 36 /* Device Capabilities 2 */ +#define PCI_EXP_DEVCAP2_ARI 0x20 /* Alternative Routing-ID */ +#define PCI_EXP_DEVCTL2 40 /* Device Control 2 */ +#define PCI_EXP_DEVCTL2_ARI 0x20 /* Alternative Routing-ID */ /* Extended Capabilities (PCI-X 2.0 and Express) */ #define PCI_EXT_CAP_ID(header) (header & 0x0000ffff) @@ -388,6 +392,7 @@ #define PCI_EXT_CAP_ID_VC 2 #define PCI_EXT_CAP_ID_DSN 3 #define PCI_EXT_CAP_ID_PWR 4 +#define PCI_EXT_CAP_ID_ARI 14 /* Advanced Error Reporting */ #define PCI_ERR_UNCOR_STATUS 4 /* Uncorrectable Error Status */ @@ -463,4 +468,14 @@ #define PCI_PWR_CAP 12 /* Capability */ #define PCI_PWR_CAP_BUDGET(x) ((x) & 1) /* Included in system budget */ +/* Alternative Routing-ID Interpretation */ +#define PCI_ARI_CAP 0x04 /* ARI Capability Register */ +#define PCI_ARI_CAP_MFVC 0x0001 /* MFVC Function Groups Capability */ +#define PCI_ARI_CAP_ACS 0x0002 /* ACS Function Groups Capability */ +#define PCI_ARI_CAP_NFN(x) (((x) >> 8) & 0xff) /* Next Function Number */ +#define PCI_ARI_CTRL 0x06 /* ARI Control Register */ +#define PCI_ARI_CTRL_MFVC 0x0001 /* MFVC Function Groups Enable */ +#define PCI_ARI_CTRL_ACS 0x0002 /* ACS Function Groups Enable */ +#define PCI_ARI_CTRL_FG(x) (((x) >> 4) & 7) /* Function Group */ + #endif /* LINUX_PCI_REGS_H */ --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="6.patch" # HG changeset patch # User Yu Zhao # Date 1236909504 14400 # Node ID 16659f5d8bb0d9d4b47cdb4a8c086c89deba793d # Parent 313310b824c81e803a698ee3a1a8a94075096060 Backport: PCI: fix ARI code to be compatible with mixed ARI/non-ARI systems commit 8113587c2d14d3be2414190845b2e2617c0aa33b Author: Zhao, Yu Date: Thu Oct 23 13:15:39 2008 +0800 PCI: fix ARI code to be compatible with mixed ARI/non-ARI systems The original ARI support code has a compatibility problem with non-ARI devices. If a device doesn't support ARI, turning on ARI forwarding on its upper level bridge will cause undefined behavior. This fix turns on ARI forwarding only when the subordinate devices support it. Tested-by: Suresh Siddha Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r 313310b824c8 -r 16659f5d8bb0 drivers/pci/pci.c --- a/drivers/pci/pci.c Thu Mar 12 21:57:23 2009 -0400 +++ b/drivers/pci/pci.c Thu Mar 12 21:58:24 2009 -0400 @@ -638,27 +638,32 @@ int pos; u32 cap; u16 ctrl; + struct pci_dev *bridge; - if (!dev->is_pcie) + if (dev->devfn) return; - if (dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && - dev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) - return; - - pos = pci_find_capability(dev, PCI_CAP_ID_EXP); + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); if (!pos) return; - pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap); + bridge = dev->bus->self; + if (!bridge) + return; + + pos = pci_find_capability(bridge, PCI_CAP_ID_EXP); + if (!pos) + return; + + pci_read_config_dword(bridge, pos + PCI_EXP_DEVCAP2, &cap); if (!(cap & PCI_EXP_DEVCAP2_ARI)) return; - pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); + pci_read_config_word(bridge, pos + PCI_EXP_DEVCTL2, &ctrl); ctrl |= PCI_EXP_DEVCTL2_ARI; - pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); + pci_write_config_word(bridge, pos + PCI_EXP_DEVCTL2, ctrl); - dev->ari_enabled = 1; + bridge->ari_enabled = 1; } int --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="7.patch" # HG changeset patch # User Yu Zhao # Date 1236909555 14400 # Node ID fe864af8b34bb03cdfe51dae05e2e3bcce2c5d69 # Parent 16659f5d8bb0d9d4b47cdb4a8c086c89deba793d Backport: PCI: enhance pci_ari_enabled() commit 6a49d8120021897e139641062236215aac5d220e Author: Yu Zhao Date: Sat Nov 22 02:38:21 2008 +0800 PCI: enhance pci_ari_enabled() Change parameter of pci_ari_enabled() from 'pci_dev' to 'pci_bus'. ARI forwarding on the bridge mostly concerns the subordinate devices rather than the bridge itself. So this change will make the function easier to use. Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r 16659f5d8bb0 -r fe864af8b34b drivers/pci/pci.h --- a/drivers/pci/pci.h Thu Mar 12 21:58:24 2009 -0400 +++ b/drivers/pci/pci.h Thu Mar 12 21:59:15 2009 -0400 @@ -122,11 +122,11 @@ extern void pci_enable_ari(struct pci_dev *dev); /** * pci_ari_enabled - query ARI forwarding status - * @dev: the PCI device + * @bus: the PCI bus * * Returns 1 if ARI forwarding is enabled, or 0 if not enabled; */ -static inline int pci_ari_enabled(struct pci_dev *dev) +static inline int pci_ari_enabled(struct pci_bus *bus) { - return dev->ari_enabled; + return bus->self && bus->self->ari_enabled; } --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="8.patch" # HG changeset patch # User Yu Zhao # Date 1236909605 14400 # Node ID b9b4e811af229682d7c6a70aabffd5ade5876c91 # Parent fe864af8b34bb03cdfe51dae05e2e3bcce2c5d69 Backport: PCI: allow pci_alloc_child_bus() to handle a NULL bridge commit 3789fa8a2e534523c896a32a9f27f78d52ad7d82 Author: Yu Zhao Date: Sat Nov 22 02:41:07 2008 +0800 PCI: allow pci_alloc_child_bus() to handle a NULL bridge Allow pci_alloc_child_bus() to allocate buses without bridge devices. Some SR-IOV devices can occupy more than one bus number, but there is no explicit bridges because that have internal routing mechanism. Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r fe864af8b34b -r b9b4e811af22 drivers/pci/probe.c --- a/drivers/pci/probe.c Thu Mar 12 21:59:15 2009 -0400 +++ b/drivers/pci/probe.c Thu Mar 12 22:00:05 2009 -0400 @@ -392,12 +392,10 @@ if (!child) return NULL; - child->self = bridge; child->parent = parent; child->ops = parent->ops; child->sysdata = parent->sysdata; child->bus_flags = parent->bus_flags; - child->bridge = get_device(&bridge->dev); child->class_dev.class = &pcibus_class; sprintf(child->class_dev.class_id, "%04x:%02x", pci_domain_nr(child), busnr); @@ -411,6 +409,12 @@ child->number = child->secondary = busnr; child->primary = parent->secondary; child->subordinate = 0xff; + + if (!bridge) + return child; + + child->self = bridge; + child->bridge = get_device(&bridge->dev); /* Set up default resource pointers and names.. */ for (i = 0; i < 4; i++) { --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="9.patch" # HG changeset patch # User Yu Zhao # Date 1236909787 14400 # Node ID c0e566166776cb7e096ee182bde557554fa4167e # Parent b9b4e811af229682d7c6a70aabffd5ade5876c91 Backport: PCI: remove unnecessary arg of pci_update_resource() commit 14add80b5120966fe0659d61815b9e9b4b68fdc5 Author: Yu Zhao Date: Sat Nov 22 02:38:52 2008 +0800 PCI: remove unnecessary arg of pci_update_resource() This cleanup removes unnecessary argument 'struct resource *res' in pci_update_resource(), so it takes same arguments as other companion functions (pci_assign_resource(), etc.). Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r b9b4e811af22 -r c0e566166776 drivers/pci/pci.c --- a/drivers/pci/pci.c Thu Mar 12 22:00:05 2009 -0400 +++ b/drivers/pci/pci.c Thu Mar 12 22:03:07 2009 -0400 @@ -273,8 +273,8 @@ return; } - for (i = 0; i < numres; i ++) - pci_update_resource(dev, &dev->resource[i], i); + for (i = 0; i < numres; i++) + pci_update_resource(dev, &dev->resource[i]); } int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t); diff -r b9b4e811af22 -r c0e566166776 drivers/pci/quirks.c --- a/drivers/pci/quirks.c Thu Mar 12 22:00:05 2009 -0400 +++ b/drivers/pci/quirks.c Thu Mar 12 22:03:07 2009 -0400 @@ -56,7 +56,7 @@ r->start = 0; if (i < PCI_BRIDGE_RESOURCES) { - pci_update_resource(dev, r, i); + pci_update_resource(dev, i); } } /* need to disable bridge's resource window, diff -r b9b4e811af22 -r c0e566166776 drivers/pci/setup-res.c --- a/drivers/pci/setup-res.c Thu Mar 12 22:00:05 2009 -0400 +++ b/drivers/pci/setup-res.c Thu Mar 12 22:03:07 2009 -0400 @@ -27,11 +27,12 @@ void -pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) +pci_update_resource(struct pci_dev *dev, int resno) { struct pci_bus_region region; u32 new, check, mask; int reg; + struct resource *res = dev->resource + resno; /* Ignore resources for unimplemented BARs and unused resource slots for 64 bit BARs. */ @@ -183,7 +184,7 @@ "%016llx - %016llx\n", resno, pci_name(dev), (unsigned long long)res->start, (unsigned long long)res->end); - pci_update_resource(dev, res, resno); + pci_update_resource(dev, resno); } return ret; @@ -221,7 +222,7 @@ resno, (unsigned long long)(res->end - res->start + 1), (unsigned long long)res->start, pci_name(dev)); } else if (resno < PCI_BRIDGE_RESOURCES) { - pci_update_resource(dev, res, resno); + pci_update_resource(dev, resno); } return ret; diff -r b9b4e811af22 -r c0e566166776 include/linux/pci.h --- a/include/linux/pci.h Thu Mar 12 22:00:05 2009 -0400 +++ b/include/linux/pci.h Thu Mar 12 22:03:07 2009 -0400 @@ -500,7 +500,7 @@ void pci_intx(struct pci_dev *dev, int enable); int pci_set_dma_mask(struct pci_dev *dev, u64 mask); int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask); -void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno); +void pci_update_resource(struct pci_dev *dev, int resno); int pci_assign_resource(struct pci_dev *dev, int i); int pci_assign_resource_fixed(struct pci_dev *dev, int i); void pci_restore_bars(struct pci_dev *dev); --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="10.patch" # HG changeset patch # User Yu Zhao # Date 1236910004 14400 # Node ID ee3f8ec76f20de0e818621c8f86122427532bc3d # Parent c0e566166776cb7e096ee182bde557554fa4167e Backport: PCI: define PCI resource names in an 'enum' commit fde09c6d8f92de0c9f75698a75f0989f2234c517 Author: Yu Zhao Date: Sat Nov 22 02:39:32 2008 +0800 PCI: define PCI resource names in an 'enum' This patch moves all definitions of the PCI resource names to an 'enum', and also replaces some hard-coded resource variables with symbol names. This change eases introduction of device specific resources. Reviewed-by: Bjorn Helgaas Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r c0e566166776 -r ee3f8ec76f20 drivers/pci/pci-sysfs.c --- a/drivers/pci/pci-sysfs.c Thu Mar 12 22:03:07 2009 -0400 +++ b/drivers/pci/pci-sysfs.c Thu Mar 12 22:06:44 2009 -0400 @@ -85,11 +85,13 @@ struct pci_dev * pci_dev = to_pci_dev(dev); char * str = buf; int i; - int max = 7; + int max; resource_size_t start, end; if (pci_dev->subordinate) max = DEVICE_COUNT_RESOURCE; + else + max = PCI_BRIDGE_RESOURCES; for (i = 0; i < max; i++) { struct resource *res = &pci_dev->resource[i]; diff -r c0e566166776 -r ee3f8ec76f20 drivers/pci/probe.c --- a/drivers/pci/probe.c Thu Mar 12 22:03:07 2009 -0400 +++ b/drivers/pci/probe.c Thu Mar 12 22:06:44 2009 -0400 @@ -417,7 +417,7 @@ child->bridge = get_device(&bridge->dev); /* Set up default resource pointers and names.. */ - for (i = 0; i < 4; i++) { + for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES+i]; child->resource[i]->name = child->name; } diff -r c0e566166776 -r ee3f8ec76f20 drivers/pci/proc.c --- a/drivers/pci/proc.c Thu Mar 12 22:03:07 2009 -0400 +++ b/drivers/pci/proc.c Thu Mar 12 22:06:44 2009 -0400 @@ -348,15 +348,16 @@ dev->vendor, dev->device, dev->irq); - /* Here should be 7 and not PCI_NUM_RESOURCES as we need to preserve compatibility */ - for (i=0; i<7; i++) { + + /* only print standard and ROM resources to preserve compatibility */ + for (i = 0; i <= PCI_ROM_RESOURCE; i++) { resource_size_t start, end; pci_resource_to_user(dev, i, &dev->resource[i], &start, &end); seq_printf(m, "\t%16llx", (unsigned long long)(start | (dev->resource[i].flags & PCI_REGION_FLAG_MASK))); } - for (i=0; i<7; i++) { + for (i = 0; i <= PCI_ROM_RESOURCE; i++) { resource_size_t start, end; pci_resource_to_user(dev, i, &dev->resource[i], &start, &end); seq_printf(m, "\t%16llx", diff -r c0e566166776 -r ee3f8ec76f20 include/linux/pci.h --- a/include/linux/pci.h Thu Mar 12 22:03:07 2009 -0400 +++ b/include/linux/pci.h Thu Mar 12 22:06:44 2009 -0400 @@ -65,8 +65,31 @@ #define PCI_DMA_NONE 3 #define DEVICE_COUNT_COMPATIBLE 4 -#define DEVICE_COUNT_RESOURCE 12 +/* + * For PCI devices, the region numbers are assigned this way: + */ +enum { + /* #0-5: standard PCI resources */ + PCI_STD_RESOURCES, + PCI_STD_RESOURCE_END = 5, + + /* #6: expansion ROM resource */ + PCI_ROM_RESOURCE, + + /* resources assigned to buses behind the bridge */ +#define PCI_BRIDGE_RESOURCE_NUM 4 + + PCI_BRIDGE_RESOURCES, + PCI_BRIDGE_RESOURCE_END = PCI_BRIDGE_RESOURCES + + PCI_BRIDGE_RESOURCE_NUM - 1, + + /* total resources associated with a PCI device */ + PCI_NUM_RESOURCES, + + /* preserve this for compatibility */ + DEVICE_COUNT_RESOURCE +}; typedef int __bitwise pci_power_t; #define PCI_D0 ((pci_power_t __force) 0) @@ -203,18 +226,6 @@ { hlist_del(&cap->next); } - -/* - * For PCI devices, the region numbers are assigned this way: - * - * 0-5 standard PCI regions - * 6 expansion ROM - * 7-10 bridges: address space assigned to buses behind the bridge - */ - -#define PCI_ROM_RESOURCE 6 -#define PCI_BRIDGE_RESOURCES 7 -#define PCI_NUM_RESOURCES 11 #ifndef PCI_BUS_NUM_RESOURCES #define PCI_BUS_NUM_RESOURCES 8 --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="11.patch" # HG changeset patch # User Yu Zhao # Date 1236910104 14400 # Node ID 4bc56b3855d6449abcf402f3be106102ecd667de # Parent ee3f8ec76f20de0e818621c8f86122427532bc3d Backport: PCI: remove unnecessary condition check in pci_restore_bars() commit bc5f5a8277cb353161454b6704b3186ebcf3a2a3 Author: Yu Zhao Date: Sat Nov 22 02:40:00 2008 +0800 PCI: remove unnecessary condition check in pci_restore_bars() Remove the unnecessary number of resources condition checks because the pci_update_resource() will check availability of the resources. Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r ee3f8ec76f20 -r 4bc56b3855d6 drivers/pci/pci.c --- a/drivers/pci/pci.c Thu Mar 12 22:06:44 2009 -0400 +++ b/drivers/pci/pci.c Thu Mar 12 22:08:24 2009 -0400 @@ -256,25 +256,10 @@ void pci_restore_bars(struct pci_dev *dev) { - int i, numres; + int i; - switch (dev->hdr_type) { - case PCI_HEADER_TYPE_NORMAL: - numres = 6; - break; - case PCI_HEADER_TYPE_BRIDGE: - numres = 2; - break; - case PCI_HEADER_TYPE_CARDBUS: - numres = 1; - break; - default: - /* Should never get here, but just in case... */ - return; - } - - for (i = 0; i < numres; i++) - pci_update_resource(dev, &dev->resource[i]); + for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) + pci_update_resource(dev, i); } int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t); --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="12.patch" # HG changeset patch # User Yu Zhao # Date 1236910170 14400 # Node ID ebec1feb35c3a3efe319853a31acee72924453f3 # Parent 4bc56b3855d6449abcf402f3be106102ecd667de Backport: PCI: add a new function to map BAR offsets commit 613e7ed6f72b1a115f7ece8ce1b66cf095de1348 Author: Yu Zhao Date: Sat Nov 22 02:41:27 2008 +0800 PCI: add a new function to map BAR offsets Add a function to map a given resource number to a corresponding register so drivers can get the offset and type of device specific BARs. Signed-off-by: Yu Zhao Signed-off-by: Jesse Barnes Signed-off-by: Yu Zhao diff -r 4bc56b3855d6 -r ebec1feb35c3 drivers/pci/pci.c --- a/drivers/pci/pci.c Thu Mar 12 22:08:24 2009 -0400 +++ b/drivers/pci/pci.c Thu Mar 12 22:09:30 2009 -0400 @@ -949,6 +949,28 @@ } #endif +/** + * pci_resource_bar - get position of the BAR associated with a resource + * @dev: the PCI device + * @resno: the resource number + * @type: the BAR type to be filled in + * + * Returns BAR position in config space, or 0 if the BAR is invalid. + */ +int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type) +{ + if (resno < PCI_ROM_RESOURCE) { + *type = pci_bar_unknown; + return PCI_BASE_ADDRESS_0 + 4 * resno; + } else if (resno == PCI_ROM_RESOURCE) { + *type = pci_bar_mem32; + return dev->rom_base_reg; + } + + dev_err(&dev->dev, "BAR: invalid resource #%d\n", resno); + return 0; +} + static int __devinit pci_init(void) { struct pci_dev *dev = NULL; diff -r 4bc56b3855d6 -r ebec1feb35c3 drivers/pci/pci.h --- a/drivers/pci/pci.h Thu Mar 12 22:08:24 2009 -0400 +++ b/drivers/pci/pci.h Thu Mar 12 22:09:30 2009 -0400 @@ -119,6 +119,8 @@ extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, struct resource *res, unsigned int reg); +extern int pci_resource_bar(struct pci_dev *dev, int resno, + enum pci_bar_type *type); extern void pci_enable_ari(struct pci_dev *dev); /** * pci_ari_enabled - query ARI forwarding status diff -r 4bc56b3855d6 -r ebec1feb35c3 drivers/pci/setup-res.c --- a/drivers/pci/setup-res.c Thu Mar 12 22:08:24 2009 -0400 +++ b/drivers/pci/setup-res.c Thu Mar 12 22:09:30 2009 -0400 @@ -32,6 +32,7 @@ struct pci_bus_region region; u32 new, check, mask; int reg; + enum pci_bar_type type; struct resource *res = dev->resource + resno; /* Ignore resources for unimplemented BARs and unused resource slots @@ -52,17 +53,13 @@ else mask = (u32)PCI_BASE_ADDRESS_MEM_MASK; - if (resno < 6) { - reg = PCI_BASE_ADDRESS_0 + 4 * resno; - } else if (resno == PCI_ROM_RESOURCE) { + reg = pci_resource_bar(dev, resno, &type); + if (!reg) + return; + if (type != pci_bar_unknown) { if (!(res->flags & IORESOURCE_ROM_ENABLE)) return; new |= PCI_ROM_ADDRESS_ENABLE; - reg = dev->rom_base_reg; - } else { - /* Hmm, non-standard resource. */ - - return; /* kill uninitialised var warning */ } pci_write_config_dword(dev, reg, new); --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --9jxsPFA5p3P2qPhR--