IB: convert struct class_device to struct device
[safe/jmp/linux-2.6] / drivers / infiniband / hw / mthca / mthca_main.c
index 44bc6cc..9ebadd6 100644 (file)
@@ -61,18 +61,13 @@ MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
 
 #ifdef CONFIG_PCI_MSI
 
-static int msi_x = 0;
+static int msi_x = 1;
 module_param(msi_x, int, 0444);
 MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
 
-static int msi = 0;
-module_param(msi, int, 0444);
-MODULE_PARM_DESC(msi, "attempt to use MSI if nonzero");
-
 #else /* CONFIG_PCI_MSI */
 
 #define msi_x (0)
-#define msi   (0)
 
 #endif /* CONFIG_PCI_MSI */
 
@@ -131,46 +126,29 @@ module_param_named(fmr_reserved_mtts, hca_profile.fmr_reserved_mtts, int, 0444);
 MODULE_PARM_DESC(fmr_reserved_mtts,
                 "number of memory translation table segments reserved for FMR");
 
-static const char mthca_version[] __devinitdata =
+static char mthca_version[] __devinitdata =
        DRV_NAME ": Mellanox InfiniBand HCA driver v"
        DRV_VERSION " (" DRV_RELDATE ")\n";
 
 static int mthca_tune_pci(struct mthca_dev *mdev)
 {
-       int cap;
-       u16 val;
-
        if (!tune_pci)
                return 0;
 
        /* First try to max out Read Byte Count */
-       cap = pci_find_capability(mdev->pdev, PCI_CAP_ID_PCIX);
-       if (cap) {
-               if (pci_read_config_word(mdev->pdev, cap + PCI_X_CMD, &val)) {
-                       mthca_err(mdev, "Couldn't read PCI-X command register, "
-                                 "aborting.\n");
-                       return -ENODEV;
-               }
-               val = (val & ~PCI_X_CMD_MAX_READ) | (3 << 2);
-               if (pci_write_config_word(mdev->pdev, cap + PCI_X_CMD, val)) {
-                       mthca_err(mdev, "Couldn't write PCI-X command register, "
-                                 "aborting.\n");
+       if (pci_find_capability(mdev->pdev, PCI_CAP_ID_PCIX)) {
+               if (pcix_set_mmrbc(mdev->pdev, pcix_get_max_mmrbc(mdev->pdev))) {
+                       mthca_err(mdev, "Couldn't set PCI-X max read count, "
+                               "aborting.\n");
                        return -ENODEV;
                }
        } else if (!(mdev->mthca_flags & MTHCA_FLAG_PCIE))
                mthca_info(mdev, "No PCI-X capability, not setting RBC.\n");
 
-       cap = pci_find_capability(mdev->pdev, PCI_CAP_ID_EXP);
-       if (cap) {
-               if (pci_read_config_word(mdev->pdev, cap + PCI_EXP_DEVCTL, &val)) {
-                       mthca_err(mdev, "Couldn't read PCI Express device control "
-                                 "register, aborting.\n");
-                       return -ENODEV;
-               }
-               val = (val & ~PCI_EXP_DEVCTL_READRQ) | (5 << 12);
-               if (pci_write_config_word(mdev->pdev, cap + PCI_EXP_DEVCTL, val)) {
-                       mthca_err(mdev, "Couldn't write PCI Express device control "
-                                 "register, aborting.\n");
+       if (pci_find_capability(mdev->pdev, PCI_CAP_ID_EXP)) {
+               if (pcie_set_readrq(mdev->pdev, 4096)) {
+                       mthca_err(mdev, "Couldn't write PCI Express read request, "
+                               "aborting.\n");
                        return -ENODEV;
                }
        } else if (mdev->mthca_flags & MTHCA_FLAG_PCIE)
@@ -289,11 +267,16 @@ static int mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim *dev_lim)
        if (dev_lim->flags & DEV_LIM_FLAG_SRQ)
                mdev->mthca_flags |= MTHCA_FLAG_SRQ;
 
+       if (mthca_is_memfree(mdev))
+               if (dev_lim->flags & DEV_LIM_FLAG_IPOIB_CSUM)
+                       mdev->device_cap_flags |= IB_DEVICE_UD_IP_CSUM;
+
        return 0;
 }
 
 static int mthca_init_tavor(struct mthca_dev *mdev)
 {
+       s64 size;
        u8 status;
        int err;
        struct mthca_dev_lim        dev_lim;
@@ -346,9 +329,11 @@ static int mthca_init_tavor(struct mthca_dev *mdev)
        if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
                profile.num_srq = dev_lim.max_srqs;
 
-       err = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
-       if (err < 0)
+       size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
+       if (size < 0) {
+               err = size;
                goto err_disable;
+       }
 
        err = mthca_INIT_HCA(mdev, &init_hca, &status);
        if (err) {
@@ -379,7 +364,7 @@ static int mthca_load_fw(struct mthca_dev *mdev)
 
        mdev->fw.arbel.fw_icm =
                mthca_alloc_icm(mdev, mdev->fw.arbel.fw_pages,
-                               GFP_HIGHUSER | __GFP_NOWARN);
+                               GFP_HIGHUSER | __GFP_NOWARN, 0);
        if (!mdev->fw.arbel.fw_icm) {
                mthca_err(mdev, "Couldn't allocate FW area, aborting.\n");
                return -ENOMEM;
@@ -412,7 +397,7 @@ err_unmap_fa:
        mthca_UNMAP_FA(mdev, &status);
 
 err_free:
-       mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);
+       mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
        return err;
 }
 
@@ -441,7 +426,7 @@ static int mthca_init_icm(struct mthca_dev *mdev,
                  (unsigned long long) aux_pages << 2);
 
        mdev->fw.arbel.aux_icm = mthca_alloc_icm(mdev, aux_pages,
-                                                GFP_HIGHUSER | __GFP_NOWARN);
+                                                GFP_HIGHUSER | __GFP_NOWARN, 0);
        if (!mdev->fw.arbel.aux_icm) {
                mthca_err(mdev, "Couldn't allocate aux memory, aborting.\n");
                return -ENOMEM;
@@ -464,10 +449,15 @@ static int mthca_init_icm(struct mthca_dev *mdev,
                goto err_unmap_aux;
        }
 
+       /* CPU writes to non-reserved MTTs, while HCA might DMA to reserved mtts */
+       mdev->limits.reserved_mtts = ALIGN(mdev->limits.reserved_mtts * MTHCA_MTT_SEG_SIZE,
+                                          dma_get_cache_alignment()) / MTHCA_MTT_SEG_SIZE;
+
        mdev->mr_table.mtt_table = mthca_alloc_icm_table(mdev, init_hca->mtt_base,
                                                         MTHCA_MTT_SEG_SIZE,
                                                         mdev->limits.num_mtt_segs,
-                                                        mdev->limits.reserved_mtts, 1);
+                                                        mdev->limits.reserved_mtts,
+                                                        1, 0);
        if (!mdev->mr_table.mtt_table) {
                mthca_err(mdev, "Failed to map MTT context memory, aborting.\n");
                err = -ENOMEM;
@@ -477,7 +467,8 @@ static int mthca_init_icm(struct mthca_dev *mdev,
        mdev->mr_table.mpt_table = mthca_alloc_icm_table(mdev, init_hca->mpt_base,
                                                         dev_lim->mpt_entry_sz,
                                                         mdev->limits.num_mpts,
-                                                        mdev->limits.reserved_mrws, 1);
+                                                        mdev->limits.reserved_mrws,
+                                                        1, 1);
        if (!mdev->mr_table.mpt_table) {
                mthca_err(mdev, "Failed to map MPT context memory, aborting.\n");
                err = -ENOMEM;
@@ -487,7 +478,8 @@ static int mthca_init_icm(struct mthca_dev *mdev,
        mdev->qp_table.qp_table = mthca_alloc_icm_table(mdev, init_hca->qpc_base,
                                                        dev_lim->qpc_entry_sz,
                                                        mdev->limits.num_qps,
-                                                       mdev->limits.reserved_qps, 0);
+                                                       mdev->limits.reserved_qps,
+                                                       0, 0);
        if (!mdev->qp_table.qp_table) {
                mthca_err(mdev, "Failed to map QP context memory, aborting.\n");
                err = -ENOMEM;
@@ -497,7 +489,8 @@ static int mthca_init_icm(struct mthca_dev *mdev,
        mdev->qp_table.eqp_table = mthca_alloc_icm_table(mdev, init_hca->eqpc_base,
                                                         dev_lim->eqpc_entry_sz,
                                                         mdev->limits.num_qps,
-                                                        mdev->limits.reserved_qps, 0);
+                                                        mdev->limits.reserved_qps,
+                                                        0, 0);
        if (!mdev->qp_table.eqp_table) {
                mthca_err(mdev, "Failed to map EQP context memory, aborting.\n");
                err = -ENOMEM;
@@ -507,7 +500,7 @@ static int mthca_init_icm(struct mthca_dev *mdev,
        mdev->qp_table.rdb_table = mthca_alloc_icm_table(mdev, init_hca->rdb_base,
                                                         MTHCA_RDB_ENTRY_SIZE,
                                                         mdev->limits.num_qps <<
-                                                        mdev->qp_table.rdb_shift,
+                                                        mdev->qp_table.rdb_shift, 0,
                                                         0, 0);
        if (!mdev->qp_table.rdb_table) {
                mthca_err(mdev, "Failed to map RDB context memory, aborting\n");
@@ -518,7 +511,8 @@ static int mthca_init_icm(struct mthca_dev *mdev,
        mdev->cq_table.table = mthca_alloc_icm_table(mdev, init_hca->cqc_base,
                                                    dev_lim->cqc_entry_sz,
                                                    mdev->limits.num_cqs,
-                                                   mdev->limits.reserved_cqs, 0);
+                                                   mdev->limits.reserved_cqs,
+                                                   0, 0);
        if (!mdev->cq_table.table) {
                mthca_err(mdev, "Failed to map CQ context memory, aborting.\n");
                err = -ENOMEM;
@@ -530,7 +524,8 @@ static int mthca_init_icm(struct mthca_dev *mdev,
                        mthca_alloc_icm_table(mdev, init_hca->srqc_base,
                                              dev_lim->srq_entry_sz,
                                              mdev->limits.num_srqs,
-                                             mdev->limits.reserved_srqs, 0);
+                                             mdev->limits.reserved_srqs,
+                                             0, 0);
                if (!mdev->srq_table.table) {
                        mthca_err(mdev, "Failed to map SRQ context memory, "
                                  "aborting.\n");
@@ -550,7 +545,7 @@ static int mthca_init_icm(struct mthca_dev *mdev,
                                                      mdev->limits.num_amgms,
                                                      mdev->limits.num_mgms +
                                                      mdev->limits.num_amgms,
-                                                     0);
+                                                     0, 0);
        if (!mdev->mcg_table.table) {
                mthca_err(mdev, "Failed to map MCG context memory, aborting.\n");
                err = -ENOMEM;
@@ -588,7 +583,7 @@ err_unmap_aux:
        mthca_UNMAP_ICM_AUX(mdev, &status);
 
 err_free_aux:
-       mthca_free_icm(mdev, mdev->fw.arbel.aux_icm);
+       mthca_free_icm(mdev, mdev->fw.arbel.aux_icm, 0);
 
        return err;
 }
@@ -609,7 +604,7 @@ static void mthca_free_icms(struct mthca_dev *mdev)
        mthca_unmap_eq_icm(mdev);
 
        mthca_UNMAP_ICM_AUX(mdev, &status);
-       mthca_free_icm(mdev, mdev->fw.arbel.aux_icm);
+       mthca_free_icm(mdev, mdev->fw.arbel.aux_icm, 0);
 }
 
 static int mthca_init_arbel(struct mthca_dev *mdev)
@@ -617,7 +612,7 @@ static int mthca_init_arbel(struct mthca_dev *mdev)
        struct mthca_dev_lim        dev_lim;
        struct mthca_profile        profile;
        struct mthca_init_hca_param init_hca;
-       u64 icm_size;
+       s64 icm_size;
        u8 status;
        int err;
 
@@ -665,7 +660,7 @@ static int mthca_init_arbel(struct mthca_dev *mdev)
                profile.num_srq = dev_lim.max_srqs;
 
        icm_size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
-       if ((int) icm_size < 0) {
+       if (icm_size < 0) {
                err = icm_size;
                goto err_stop_fw;
        }
@@ -693,7 +688,7 @@ err_free_icm:
 
 err_stop_fw:
        mthca_UNMAP_FA(mdev, &status);
-       mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);
+       mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
 
 err_disable:
        if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))
@@ -712,7 +707,7 @@ static void mthca_close_hca(struct mthca_dev *mdev)
                mthca_free_icms(mdev);
 
                mthca_UNMAP_FA(mdev, &status);
-               mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);
+               mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
 
                if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))
                        mthca_DISABLE_LAM(mdev, &status);
@@ -747,7 +742,8 @@ static int mthca_init_hca(struct mthca_dev *mdev)
        }
 
        mdev->eq_table.inta_pin = adapter.inta_pin;
-       mdev->rev_id            = adapter.revision_id;
+       if (!mthca_is_memfree(mdev))
+               mdev->rev_id = adapter.revision_id;
        memcpy(mdev->board_id, adapter.board_id, sizeof mdev->board_id);
 
        return 0;
@@ -823,14 +819,17 @@ static int mthca_setup_hca(struct mthca_dev *dev)
 
        err = mthca_NOP(dev, &status);
        if (err || status) {
-               mthca_err(dev, "NOP command failed to generate interrupt (IRQ %d), aborting.\n",
-                         dev->mthca_flags & MTHCA_FLAG_MSI_X ?
-                         dev->eq_table.eq[MTHCA_EQ_CMD].msi_x_vector :
-                         dev->pdev->irq);
-               if (dev->mthca_flags & (MTHCA_FLAG_MSI | MTHCA_FLAG_MSI_X))
-                       mthca_err(dev, "Try again with MSI/MSI-X disabled.\n");
-               else
+               if (dev->mthca_flags & MTHCA_FLAG_MSI_X) {
+                       mthca_warn(dev, "NOP command failed to generate interrupt "
+                                  "(IRQ %d).\n",
+                                  dev->eq_table.eq[MTHCA_EQ_CMD].msi_x_vector);
+                       mthca_warn(dev, "Trying again with MSI-X disabled.\n");
+               } else {
+                       mthca_err(dev, "NOP command failed to generate interrupt "
+                                 "(IRQ %d), aborting.\n",
+                                 dev->pdev->irq);
                        mthca_err(dev, "BIOS or ACPI interrupt routing problem?\n");
+               }
 
                goto err_cmd_poll;
        }
@@ -1003,14 +1002,14 @@ static struct {
        u64 latest_fw;
        u32 flags;
 } mthca_hca_table[] = {
-       [TAVOR]        = { .latest_fw = MTHCA_FW_VER(3, 4, 0),
+       [TAVOR]        = { .latest_fw = MTHCA_FW_VER(3, 5, 0),
                           .flags     = 0 },
-       [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 7, 600),
+       [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 8, 200),
                           .flags     = MTHCA_FLAG_PCIE },
-       [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 1, 400),
+       [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 3, 0),
                           .flags     = MTHCA_FLAG_MEMFREE |
                                        MTHCA_FLAG_PCIE },
-       [SINAI]        = { .latest_fw = MTHCA_FW_VER(1, 1, 0),
+       [SINAI]        = { .latest_fw = MTHCA_FW_VER(1, 2, 0),
                           .flags     = MTHCA_FLAG_MEMFREE |
                                        MTHCA_FLAG_PCIE    |
                                        MTHCA_FLAG_SINAI_OPT }
@@ -1105,12 +1104,6 @@ static int __mthca_init_one(struct pci_dev *pdev, int hca_type)
                goto err_free_dev;
        }
 
-       if (msi_x && !mthca_enable_msi_x(mdev))
-               mdev->mthca_flags |= MTHCA_FLAG_MSI_X;
-       if (msi && !(mdev->mthca_flags & MTHCA_FLAG_MSI_X) &&
-           !pci_enable_msi(pdev))
-               mdev->mthca_flags |= MTHCA_FLAG_MSI;
-
        if (mthca_cmd_init(mdev)) {
                mthca_err(mdev, "Failed to init command interface, aborting.\n");
                goto err_free_dev;
@@ -1125,7 +1118,7 @@ static int __mthca_init_one(struct pci_dev *pdev, int hca_type)
                goto err_cmd;
 
        if (mdev->fw_ver < mthca_hca_table[hca_type].latest_fw) {
-               mthca_warn(mdev, "HCA FW version %d.%d.%d is old (%d.%d.%d is current).\n",
+               mthca_warn(mdev, "HCA FW version %d.%d.%03d is old (%d.%d.%03d is current).\n",
                           (int) (mdev->fw_ver >> 32), (int) (mdev->fw_ver >> 16) & 0xffff,
                           (int) (mdev->fw_ver & 0xffff),
                           (int) (mthca_hca_table[hca_type].latest_fw >> 32),
@@ -1134,7 +1127,18 @@ static int __mthca_init_one(struct pci_dev *pdev, int hca_type)
                mthca_warn(mdev, "If you have problems, try updating your HCA FW.\n");
        }
 
+       if (msi_x && !mthca_enable_msi_x(mdev))
+               mdev->mthca_flags |= MTHCA_FLAG_MSI_X;
+
        err = mthca_setup_hca(mdev);
+       if (err == -EBUSY && (mdev->mthca_flags & MTHCA_FLAG_MSI_X)) {
+               if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
+                       pci_disable_msix(pdev);
+               mdev->mthca_flags &= ~MTHCA_FLAG_MSI_X;
+
+               err = mthca_setup_hca(mdev);
+       }
+
        if (err)
                goto err_close;
 
@@ -1170,17 +1174,15 @@ err_cleanup:
        mthca_cleanup_uar_table(mdev);
 
 err_close:
+       if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
+               pci_disable_msix(pdev);
+
        mthca_close_hca(mdev);
 
 err_cmd:
        mthca_cmd_cleanup(mdev);
 
 err_free_dev:
-       if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
-               pci_disable_msix(pdev);
-       if (mdev->mthca_flags & MTHCA_FLAG_MSI)
-               pci_disable_msi(pdev);
-
        ib_dealloc_device(&mdev->ib_dev);
 
 err_free_res:
@@ -1226,8 +1228,6 @@ static void __mthca_remove_one(struct pci_dev *pdev)
 
                if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
                        pci_disable_msix(pdev);
-               if (mdev->mthca_flags & MTHCA_FLAG_MSI)
-                       pci_disable_msi(pdev);
 
                ib_dealloc_device(&mdev->ib_dev);
                mthca_release_regions(pdev, mdev->mthca_flags &
@@ -1240,12 +1240,14 @@ static void __mthca_remove_one(struct pci_dev *pdev)
 int __mthca_restart_one(struct pci_dev *pdev)
 {
        struct mthca_dev *mdev;
+       int hca_type;
 
        mdev = pci_get_drvdata(pdev);
        if (!mdev)
                return -ENODEV;
+       hca_type = mdev->hca_type;
        __mthca_remove_one(pdev);
-       return __mthca_init_one(pdev, mdev->hca_type);
+       return __mthca_init_one(pdev, hca_type);
 }
 
 static int __devinit mthca_init_one(struct pci_dev *pdev,