Merge branch 'pci/virtualization'
- Fix memory leak in pci_iov_add_virtfn() (Navid Emamdoost) - Extend pci_add_dma_alias() so it can add a range of aliases (James Sewart) - Add DMA aliases for PLX PEX NTB (James Sewart) * pci/virtualization: PCI: Add DMA alias quirk for PLX PEX NTB PCI: Add nr_devfns parameter to pci_add_dma_alias() PCI: Fix pci_add_dma_alias() bitmask size PCI/IOV: Fix memory leak in pci_iov_add_virtfn()
This commit is contained in:
commit
c7417cf36a
@ -230,11 +230,8 @@ static struct pci_dev *setup_aliases(struct device *dev)
|
||||
*/
|
||||
ivrs_alias = amd_iommu_alias_table[pci_dev_id(pdev)];
|
||||
if (ivrs_alias != pci_dev_id(pdev) &&
|
||||
PCI_BUS_NUM(ivrs_alias) == pdev->bus->number) {
|
||||
pci_add_dma_alias(pdev, ivrs_alias & 0xff);
|
||||
pci_info(pdev, "Added PCI DMA alias %02x.%d\n",
|
||||
PCI_SLOT(ivrs_alias), PCI_FUNC(ivrs_alias));
|
||||
}
|
||||
PCI_BUS_NUM(ivrs_alias) == pdev->bus->number)
|
||||
pci_add_dma_alias(pdev, ivrs_alias & 0xff, 1);
|
||||
|
||||
clone_aliases(pdev);
|
||||
|
||||
|
@ -186,10 +186,10 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id)
|
||||
sprintf(buf, "virtfn%u", id);
|
||||
rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
|
||||
if (rc)
|
||||
goto failed2;
|
||||
goto failed1;
|
||||
rc = sysfs_create_link(&virtfn->dev.kobj, &dev->dev.kobj, "physfn");
|
||||
if (rc)
|
||||
goto failed3;
|
||||
goto failed2;
|
||||
|
||||
kobject_uevent(&virtfn->dev.kobj, KOBJ_CHANGE);
|
||||
|
||||
@ -197,11 +197,10 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id)
|
||||
|
||||
return 0;
|
||||
|
||||
failed3:
|
||||
sysfs_remove_link(&dev->dev.kobj, buf);
|
||||
failed2:
|
||||
pci_stop_and_remove_bus_device(virtfn);
|
||||
sysfs_remove_link(&dev->dev.kobj, buf);
|
||||
failed1:
|
||||
pci_stop_and_remove_bus_device(virtfn);
|
||||
pci_dev_put(dev);
|
||||
failed0:
|
||||
virtfn_remove_bus(dev->bus, bus);
|
||||
|
@ -6001,7 +6001,8 @@ EXPORT_SYMBOL_GPL(pci_pr3_present);
|
||||
/**
|
||||
* pci_add_dma_alias - Add a DMA devfn alias for a device
|
||||
* @dev: the PCI device for which alias is added
|
||||
* @devfn: alias slot and function
|
||||
* @devfn_from: alias slot and function
|
||||
* @nr_devfns: number of subsequent devfns to alias
|
||||
*
|
||||
* This helper encodes an 8-bit devfn as a bit number in dma_alias_mask
|
||||
* which is used to program permissible bus-devfn source addresses for DMA
|
||||
@ -6017,18 +6018,29 @@ EXPORT_SYMBOL_GPL(pci_pr3_present);
|
||||
* cannot be left as a userspace activity). DMA aliases should therefore
|
||||
* be configured via quirks, such as the PCI fixup header quirk.
|
||||
*/
|
||||
void pci_add_dma_alias(struct pci_dev *dev, u8 devfn)
|
||||
void pci_add_dma_alias(struct pci_dev *dev, u8 devfn_from, unsigned nr_devfns)
|
||||
{
|
||||
int devfn_to;
|
||||
|
||||
nr_devfns = min(nr_devfns, (unsigned) MAX_NR_DEVFNS - devfn_from);
|
||||
devfn_to = devfn_from + nr_devfns - 1;
|
||||
|
||||
if (!dev->dma_alias_mask)
|
||||
dev->dma_alias_mask = bitmap_zalloc(U8_MAX, GFP_KERNEL);
|
||||
dev->dma_alias_mask = bitmap_zalloc(MAX_NR_DEVFNS, GFP_KERNEL);
|
||||
if (!dev->dma_alias_mask) {
|
||||
pci_warn(dev, "Unable to allocate DMA alias mask\n");
|
||||
return;
|
||||
}
|
||||
|
||||
set_bit(devfn, dev->dma_alias_mask);
|
||||
pci_info(dev, "Enabling fixed DMA alias to %02x.%d\n",
|
||||
PCI_SLOT(devfn), PCI_FUNC(devfn));
|
||||
bitmap_set(dev->dma_alias_mask, devfn_from, nr_devfns);
|
||||
|
||||
if (nr_devfns == 1)
|
||||
pci_info(dev, "Enabling fixed DMA alias to %02x.%d\n",
|
||||
PCI_SLOT(devfn_from), PCI_FUNC(devfn_from));
|
||||
else if (nr_devfns > 1)
|
||||
pci_info(dev, "Enabling fixed DMA alias for devfn range from %02x.%d to %02x.%d\n",
|
||||
PCI_SLOT(devfn_from), PCI_FUNC(devfn_from),
|
||||
PCI_SLOT(devfn_to), PCI_FUNC(devfn_to));
|
||||
}
|
||||
|
||||
bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2)
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
#include <linux/pci.h>
|
||||
|
||||
/* Number of possible devfns: 0.0 to 1f.7 inclusive */
|
||||
#define MAX_NR_DEVFNS 256
|
||||
|
||||
#define PCI_FIND_CAP_TTL 48
|
||||
|
||||
#define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */
|
||||
|
@ -3927,7 +3927,7 @@ int pci_dev_specific_reset(struct pci_dev *dev, int probe)
|
||||
static void quirk_dma_func0_alias(struct pci_dev *dev)
|
||||
{
|
||||
if (PCI_FUNC(dev->devfn) != 0)
|
||||
pci_add_dma_alias(dev, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
|
||||
pci_add_dma_alias(dev, PCI_DEVFN(PCI_SLOT(dev->devfn), 0), 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3941,7 +3941,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RICOH, 0xe476, quirk_dma_func0_alias);
|
||||
static void quirk_dma_func1_alias(struct pci_dev *dev)
|
||||
{
|
||||
if (PCI_FUNC(dev->devfn) != 1)
|
||||
pci_add_dma_alias(dev, PCI_DEVFN(PCI_SLOT(dev->devfn), 1));
|
||||
pci_add_dma_alias(dev, PCI_DEVFN(PCI_SLOT(dev->devfn), 1), 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -4026,7 +4026,7 @@ static void quirk_fixed_dma_alias(struct pci_dev *dev)
|
||||
|
||||
id = pci_match_id(fixed_dma_alias_tbl, dev);
|
||||
if (id)
|
||||
pci_add_dma_alias(dev, id->driver_data);
|
||||
pci_add_dma_alias(dev, id->driver_data, 1);
|
||||
}
|
||||
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ADAPTEC2, 0x0285, quirk_fixed_dma_alias);
|
||||
|
||||
@ -4067,9 +4067,9 @@ DECLARE_PCI_FIXUP_HEADER(0x8086, 0x244e, quirk_use_pcie_bridge_dma_alias);
|
||||
*/
|
||||
static void quirk_mic_x200_dma_alias(struct pci_dev *pdev)
|
||||
{
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(0x10, 0x0));
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(0x11, 0x0));
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(0x12, 0x3));
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(0x10, 0x0), 1);
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(0x11, 0x0), 1);
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(0x12, 0x3), 1);
|
||||
}
|
||||
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2260, quirk_mic_x200_dma_alias);
|
||||
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2264, quirk_mic_x200_dma_alias);
|
||||
@ -4093,13 +4093,8 @@ static void quirk_pex_vca_alias(struct pci_dev *pdev)
|
||||
const unsigned int num_pci_slots = 0x20;
|
||||
unsigned int slot;
|
||||
|
||||
for (slot = 0; slot < num_pci_slots; slot++) {
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(slot, 0x0));
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(slot, 0x1));
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(slot, 0x2));
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(slot, 0x3));
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(slot, 0x4));
|
||||
}
|
||||
for (slot = 0; slot < num_pci_slots; slot++)
|
||||
pci_add_dma_alias(pdev, PCI_DEVFN(slot, 0x0), 5);
|
||||
}
|
||||
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2954, quirk_pex_vca_alias);
|
||||
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2955, quirk_pex_vca_alias);
|
||||
@ -5327,7 +5322,7 @@ static void quirk_switchtec_ntb_dma_alias(struct pci_dev *pdev)
|
||||
pci_dbg(pdev,
|
||||
"Aliasing Partition %d Proxy ID %02x.%d\n",
|
||||
pp, PCI_SLOT(devfn), PCI_FUNC(devfn));
|
||||
pci_add_dma_alias(pdev, devfn);
|
||||
pci_add_dma_alias(pdev, devfn, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5387,6 +5382,21 @@ SWITCHTEC_QUIRK(0x4252); /* PAX 52XG4 */
|
||||
SWITCHTEC_QUIRK(0x4236); /* PAX 36XG4 */
|
||||
SWITCHTEC_QUIRK(0x4228); /* PAX 28XG4 */
|
||||
|
||||
/*
|
||||
* The PLX NTB uses devfn proxy IDs to move TLPs between NT endpoints.
|
||||
* These IDs are used to forward responses to the originator on the other
|
||||
* side of the NTB. Alias all possible IDs to the NTB to permit access when
|
||||
* the IOMMU is turned on.
|
||||
*/
|
||||
static void quirk_plx_ntb_dma_alias(struct pci_dev *pdev)
|
||||
{
|
||||
pci_info(pdev, "Setting PLX NTB proxy ID aliases\n");
|
||||
/* PLX NTB may use all 256 devfns */
|
||||
pci_add_dma_alias(pdev, 0, 256);
|
||||
}
|
||||
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_PLX, 0x87b0, quirk_plx_ntb_dma_alias);
|
||||
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_PLX, 0x87b1, quirk_plx_ntb_dma_alias);
|
||||
|
||||
/*
|
||||
* On Lenovo Thinkpad P50 SKUs with a Nvidia Quadro M1000M, the BIOS does
|
||||
* not always reset the secondary Nvidia GPU between reboots if the system
|
||||
|
@ -41,9 +41,9 @@ int pci_for_each_dma_alias(struct pci_dev *pdev,
|
||||
* DMA, iterate over that too.
|
||||
*/
|
||||
if (unlikely(pdev->dma_alias_mask)) {
|
||||
u8 devfn;
|
||||
unsigned int devfn;
|
||||
|
||||
for_each_set_bit(devfn, pdev->dma_alias_mask, U8_MAX) {
|
||||
for_each_set_bit(devfn, pdev->dma_alias_mask, MAX_NR_DEVFNS) {
|
||||
ret = fn(pdev, PCI_DEVID(pdev->bus->number, devfn),
|
||||
data);
|
||||
if (ret)
|
||||
|
@ -2310,7 +2310,7 @@ static inline struct eeh_dev *pci_dev_to_eeh_dev(struct pci_dev *pdev)
|
||||
}
|
||||
#endif
|
||||
|
||||
void pci_add_dma_alias(struct pci_dev *dev, u8 devfn);
|
||||
void pci_add_dma_alias(struct pci_dev *dev, u8 devfn_from, unsigned nr_devfns);
|
||||
bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2);
|
||||
int pci_for_each_dma_alias(struct pci_dev *pdev,
|
||||
int (*fn)(struct pci_dev *pdev,
|
||||
|
Loading…
Reference in New Issue
Block a user