Commit 208dde28 authored by Roland Dreier's avatar Roland Dreier

IB/mthca: Use pci_request_regions()

Back in prehistoric (pre-git!) days, the kernel's MSI-X support did
request_mem_region() on a device's MSI-X tables, which meant that a
driver that enabled MSI-X couldn't use pci_request_regions() (since
that would clash with the PCI layer's MSI-X request).

However, that was removed (by me!) years ago, so mthca can just use
pci_request_regions() and pci_release_regions() instead of its own
much more complicated code that avoids requesting the MSI-X tables.
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent 9824b8f1
...@@ -149,18 +149,10 @@ void mthca_start_catas_poll(struct mthca_dev *dev) ...@@ -149,18 +149,10 @@ void mthca_start_catas_poll(struct mthca_dev *dev)
((pci_resource_len(dev->pdev, 0) - 1) & ((pci_resource_len(dev->pdev, 0) - 1) &
dev->catas_err.addr); dev->catas_err.addr);
if (!request_mem_region(addr, dev->catas_err.size * 4,
DRV_NAME)) {
mthca_warn(dev, "couldn't request catastrophic error region "
"at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4);
return;
}
dev->catas_err.map = ioremap(addr, dev->catas_err.size * 4); dev->catas_err.map = ioremap(addr, dev->catas_err.size * 4);
if (!dev->catas_err.map) { if (!dev->catas_err.map) {
mthca_warn(dev, "couldn't map catastrophic error region " mthca_warn(dev, "couldn't map catastrophic error region "
"at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4); "at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4);
release_mem_region(addr, dev->catas_err.size * 4);
return; return;
} }
...@@ -175,13 +167,8 @@ void mthca_stop_catas_poll(struct mthca_dev *dev) ...@@ -175,13 +167,8 @@ void mthca_stop_catas_poll(struct mthca_dev *dev)
{ {
del_timer_sync(&dev->catas_err.timer); del_timer_sync(&dev->catas_err.timer);
if (dev->catas_err.map) { if (dev->catas_err.map)
iounmap(dev->catas_err.map); iounmap(dev->catas_err.map);
release_mem_region(pci_resource_start(dev->pdev, 0) +
((pci_resource_len(dev->pdev, 0) - 1) &
dev->catas_err.addr),
dev->catas_err.size * 4);
}
spin_lock_irq(&catas_lock); spin_lock_irq(&catas_lock);
list_del(&dev->catas_err.list); list_del(&dev->catas_err.list);
......
...@@ -652,27 +652,13 @@ static int mthca_map_reg(struct mthca_dev *dev, ...@@ -652,27 +652,13 @@ static int mthca_map_reg(struct mthca_dev *dev,
{ {
unsigned long base = pci_resource_start(dev->pdev, 0); unsigned long base = pci_resource_start(dev->pdev, 0);
if (!request_mem_region(base + offset, size, DRV_NAME))
return -EBUSY;
*map = ioremap(base + offset, size); *map = ioremap(base + offset, size);
if (!*map) { if (!*map)
release_mem_region(base + offset, size);
return -ENOMEM; return -ENOMEM;
}
return 0; return 0;
} }
static void mthca_unmap_reg(struct mthca_dev *dev, unsigned long offset,
unsigned long size, void __iomem *map)
{
unsigned long base = pci_resource_start(dev->pdev, 0);
release_mem_region(base + offset, size);
iounmap(map);
}
static int mthca_map_eq_regs(struct mthca_dev *dev) static int mthca_map_eq_regs(struct mthca_dev *dev)
{ {
if (mthca_is_memfree(dev)) { if (mthca_is_memfree(dev)) {
...@@ -699,9 +685,7 @@ static int mthca_map_eq_regs(struct mthca_dev *dev) ...@@ -699,9 +685,7 @@ static int mthca_map_eq_regs(struct mthca_dev *dev)
dev->fw.arbel.eq_arm_base) + 4, 4, dev->fw.arbel.eq_arm_base) + 4, 4,
&dev->eq_regs.arbel.eq_arm)) { &dev->eq_regs.arbel.eq_arm)) {
mthca_err(dev, "Couldn't map EQ arm register, aborting.\n"); mthca_err(dev, "Couldn't map EQ arm register, aborting.\n");
mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) & iounmap(dev->clr_base);
dev->fw.arbel.clr_int_base, MTHCA_CLR_INT_SIZE,
dev->clr_base);
return -ENOMEM; return -ENOMEM;
} }
...@@ -710,12 +694,8 @@ static int mthca_map_eq_regs(struct mthca_dev *dev) ...@@ -710,12 +694,8 @@ static int mthca_map_eq_regs(struct mthca_dev *dev)
MTHCA_EQ_SET_CI_SIZE, MTHCA_EQ_SET_CI_SIZE,
&dev->eq_regs.arbel.eq_set_ci_base)) { &dev->eq_regs.arbel.eq_set_ci_base)) {
mthca_err(dev, "Couldn't map EQ CI register, aborting.\n"); mthca_err(dev, "Couldn't map EQ CI register, aborting.\n");
mthca_unmap_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) & iounmap(dev->eq_regs.arbel.eq_arm);
dev->fw.arbel.eq_arm_base) + 4, 4, iounmap(dev->clr_base);
dev->eq_regs.arbel.eq_arm);
mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) &
dev->fw.arbel.clr_int_base, MTHCA_CLR_INT_SIZE,
dev->clr_base);
return -ENOMEM; return -ENOMEM;
} }
} else { } else {
...@@ -731,8 +711,7 @@ static int mthca_map_eq_regs(struct mthca_dev *dev) ...@@ -731,8 +711,7 @@ static int mthca_map_eq_regs(struct mthca_dev *dev)
&dev->eq_regs.tavor.ecr_base)) { &dev->eq_regs.tavor.ecr_base)) {
mthca_err(dev, "Couldn't map ecr register, " mthca_err(dev, "Couldn't map ecr register, "
"aborting.\n"); "aborting.\n");
mthca_unmap_reg(dev, MTHCA_CLR_INT_BASE, MTHCA_CLR_INT_SIZE, iounmap(dev->clr_base);
dev->clr_base);
return -ENOMEM; return -ENOMEM;
} }
} }
...@@ -744,22 +723,12 @@ static int mthca_map_eq_regs(struct mthca_dev *dev) ...@@ -744,22 +723,12 @@ static int mthca_map_eq_regs(struct mthca_dev *dev)
static void mthca_unmap_eq_regs(struct mthca_dev *dev) static void mthca_unmap_eq_regs(struct mthca_dev *dev)
{ {
if (mthca_is_memfree(dev)) { if (mthca_is_memfree(dev)) {
mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) & iounmap(dev->eq_regs.arbel.eq_set_ci_base);
dev->fw.arbel.eq_set_ci_base, iounmap(dev->eq_regs.arbel.eq_arm);
MTHCA_EQ_SET_CI_SIZE, iounmap(dev->clr_base);
dev->eq_regs.arbel.eq_set_ci_base);
mthca_unmap_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) &
dev->fw.arbel.eq_arm_base) + 4, 4,
dev->eq_regs.arbel.eq_arm);
mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) &
dev->fw.arbel.clr_int_base, MTHCA_CLR_INT_SIZE,
dev->clr_base);
} else { } else {
mthca_unmap_reg(dev, MTHCA_ECR_BASE, iounmap(dev->eq_regs.tavor.ecr_base);
MTHCA_ECR_SIZE + MTHCA_ECR_CLR_SIZE, iounmap(dev->clr_base);
dev->eq_regs.tavor.ecr_base);
mthca_unmap_reg(dev, MTHCA_CLR_INT_BASE, MTHCA_CLR_INT_SIZE,
dev->clr_base);
} }
} }
......
...@@ -921,58 +921,6 @@ static int mthca_setup_hca(struct mthca_dev *dev) ...@@ -921,58 +921,6 @@ static int mthca_setup_hca(struct mthca_dev *dev)
return err; return err;
} }
static int mthca_request_regions(struct pci_dev *pdev, int ddr_hidden)
{
int err;
/*
* We can't just use pci_request_regions() because the MSI-X
* table is right in the middle of the first BAR. If we did
* pci_request_region and grab all of the first BAR, then
* setting up MSI-X would fail, since the PCI core wants to do
* request_mem_region on the MSI-X vector table.
*
* So just request what we need right now, and request any
* other regions we need when setting up EQs.
*/
if (!request_mem_region(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE,
MTHCA_HCR_SIZE, DRV_NAME))
return -EBUSY;
err = pci_request_region(pdev, 2, DRV_NAME);
if (err)
goto err_bar2_failed;
if (!ddr_hidden) {
err = pci_request_region(pdev, 4, DRV_NAME);
if (err)
goto err_bar4_failed;
}
return 0;
err_bar4_failed:
pci_release_region(pdev, 2);
err_bar2_failed:
release_mem_region(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE,
MTHCA_HCR_SIZE);
return err;
}
static void mthca_release_regions(struct pci_dev *pdev,
int ddr_hidden)
{
if (!ddr_hidden)
pci_release_region(pdev, 4);
pci_release_region(pdev, 2);
release_mem_region(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE,
MTHCA_HCR_SIZE);
}
static int mthca_enable_msi_x(struct mthca_dev *mdev) static int mthca_enable_msi_x(struct mthca_dev *mdev)
{ {
struct msix_entry entries[3]; struct msix_entry entries[3];
...@@ -1059,7 +1007,7 @@ static int __mthca_init_one(struct pci_dev *pdev, int hca_type) ...@@ -1059,7 +1007,7 @@ static int __mthca_init_one(struct pci_dev *pdev, int hca_type)
if (!(pci_resource_flags(pdev, 4) & IORESOURCE_MEM)) if (!(pci_resource_flags(pdev, 4) & IORESOURCE_MEM))
ddr_hidden = 1; ddr_hidden = 1;
err = mthca_request_regions(pdev, ddr_hidden); err = pci_request_regions(pdev, DRV_NAME);
if (err) { if (err) {
dev_err(&pdev->dev, "Cannot obtain PCI resources, " dev_err(&pdev->dev, "Cannot obtain PCI resources, "
"aborting.\n"); "aborting.\n");
...@@ -1196,7 +1144,7 @@ static int __mthca_init_one(struct pci_dev *pdev, int hca_type) ...@@ -1196,7 +1144,7 @@ static int __mthca_init_one(struct pci_dev *pdev, int hca_type)
ib_dealloc_device(&mdev->ib_dev); ib_dealloc_device(&mdev->ib_dev);
err_free_res: err_free_res:
mthca_release_regions(pdev, ddr_hidden); pci_release_regions(pdev);
err_disable_pdev: err_disable_pdev:
pci_disable_device(pdev); pci_disable_device(pdev);
...@@ -1240,8 +1188,7 @@ static void __mthca_remove_one(struct pci_dev *pdev) ...@@ -1240,8 +1188,7 @@ static void __mthca_remove_one(struct pci_dev *pdev)
pci_disable_msix(pdev); pci_disable_msix(pdev);
ib_dealloc_device(&mdev->ib_dev); ib_dealloc_device(&mdev->ib_dev);
mthca_release_regions(pdev, mdev->mthca_flags & pci_release_regions(pdev);
MTHCA_FLAG_DDR_HIDDEN);
pci_disable_device(pdev); pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
} }
......
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