Commit 80fd8238 authored by Roland Dreier's avatar Roland Dreier Committed by Linus Torvalds

[PATCH] IB/mthca: Encapsulate command interface init

Encapsulate mthca command interface initialization/cleanup.
Signed-off-by: default avatarRoland Dreier <roland@topspin.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 761f9eb8
...@@ -431,6 +431,27 @@ static int mthca_cmd_imm(struct mthca_dev *dev, ...@@ -431,6 +431,27 @@ static int mthca_cmd_imm(struct mthca_dev *dev,
timeout, status); timeout, status);
} }
int mthca_cmd_init(struct mthca_dev *dev)
{
sema_init(&dev->cmd.hcr_sem, 1);
sema_init(&dev->cmd.poll_sem, 1);
dev->cmd.use_events = 0;
dev->hcr = ioremap(pci_resource_start(dev->pdev, 0) + MTHCA_HCR_BASE,
MTHCA_HCR_SIZE);
if (!dev->hcr) {
mthca_err(dev, "Couldn't map command register.");
return -ENOMEM;
}
return 0;
}
void mthca_cmd_cleanup(struct mthca_dev *dev)
{
iounmap(dev->hcr);
}
/* /*
* Switch to using events to issue FW commands (should be called after * Switch to using events to issue FW commands (should be called after
* event queue to command events has been initialized). * event queue to command events has been initialized).
......
...@@ -235,6 +235,8 @@ struct mthca_set_ib_param { ...@@ -235,6 +235,8 @@ struct mthca_set_ib_param {
u32 cap_mask; u32 cap_mask;
}; };
int mthca_cmd_init(struct mthca_dev *dev);
void mthca_cmd_cleanup(struct mthca_dev *dev);
int mthca_cmd_use_events(struct mthca_dev *dev); int mthca_cmd_use_events(struct mthca_dev *dev);
void mthca_cmd_use_polling(struct mthca_dev *dev); void mthca_cmd_use_polling(struct mthca_dev *dev);
void mthca_cmd_event(struct mthca_dev *dev, u16 token, void mthca_cmd_event(struct mthca_dev *dev, u16 token,
......
...@@ -1005,25 +1005,18 @@ static int __devinit mthca_init_one(struct pci_dev *pdev, ...@@ -1005,25 +1005,18 @@ static int __devinit mthca_init_one(struct pci_dev *pdev,
!pci_enable_msi(pdev)) !pci_enable_msi(pdev))
mdev->mthca_flags |= MTHCA_FLAG_MSI; mdev->mthca_flags |= MTHCA_FLAG_MSI;
sema_init(&mdev->cmd.hcr_sem, 1); if (mthca_cmd_init(mdev)) {
sema_init(&mdev->cmd.poll_sem, 1); mthca_err(mdev, "Failed to init command interface, aborting.\n");
mdev->cmd.use_events = 0;
mdev->hcr = ioremap(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE, MTHCA_HCR_SIZE);
if (!mdev->hcr) {
mthca_err(mdev, "Couldn't map command register, "
"aborting.\n");
err = -ENOMEM;
goto err_free_dev; goto err_free_dev;
} }
err = mthca_tune_pci(mdev); err = mthca_tune_pci(mdev);
if (err) if (err)
goto err_iounmap; goto err_cmd;
err = mthca_init_hca(mdev); err = mthca_init_hca(mdev);
if (err) if (err)
goto err_iounmap; goto err_cmd;
if (mdev->fw_ver < mthca_hca_table[id->driver_data].latest_fw) { if (mdev->fw_ver < mthca_hca_table[id->driver_data].latest_fw) {
mthca_warn(mdev, "HCA FW version %x.%x.%x is old (%x.%x.%x is current).\n", mthca_warn(mdev, "HCA FW version %x.%x.%x is old (%x.%x.%x is current).\n",
...@@ -1071,8 +1064,8 @@ static int __devinit mthca_init_one(struct pci_dev *pdev, ...@@ -1071,8 +1064,8 @@ static int __devinit mthca_init_one(struct pci_dev *pdev,
err_close: err_close:
mthca_close_hca(mdev); mthca_close_hca(mdev);
err_iounmap: err_cmd:
iounmap(mdev->hcr); mthca_cmd_cleanup(mdev);
err_free_dev: err_free_dev:
if (mdev->mthca_flags & MTHCA_FLAG_MSI_X) if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
...@@ -1119,10 +1112,8 @@ static void __devexit mthca_remove_one(struct pci_dev *pdev) ...@@ -1119,10 +1112,8 @@ static void __devexit mthca_remove_one(struct pci_dev *pdev)
iounmap(mdev->kar); iounmap(mdev->kar);
mthca_uar_free(mdev, &mdev->driver_uar); mthca_uar_free(mdev, &mdev->driver_uar);
mthca_cleanup_uar_table(mdev); mthca_cleanup_uar_table(mdev);
mthca_close_hca(mdev); mthca_close_hca(mdev);
mthca_cmd_cleanup(mdev);
iounmap(mdev->hcr);
if (mdev->mthca_flags & MTHCA_FLAG_MSI_X) if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
pci_disable_msix(pdev); pci_disable_msix(pdev);
......
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