Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[safe/jmp/linux-2.6] / drivers / infiniband / hw / mthca / mthca_main.c
index aa563e6..200cf13 100644 (file)
@@ -45,6 +45,7 @@
 #include "mthca_cmd.h"
 #include "mthca_profile.h"
 #include "mthca_memfree.h"
+#include "mthca_wqe.h"
 
 MODULE_AUTHOR("Roland Dreier");
 MODULE_DESCRIPTION("Mellanox InfiniBand HCA low-level driver");
@@ -61,18 +62,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 +127,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)
@@ -222,7 +201,18 @@ static int mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim *dev_lim)
        mdev->limits.gid_table_len      = dev_lim->max_gids;
        mdev->limits.pkey_table_len     = dev_lim->max_pkeys;
        mdev->limits.local_ca_ack_delay = dev_lim->local_ca_ack_delay;
-       mdev->limits.max_sg             = dev_lim->max_sg;
+       /*
+        * Need to allow for worst case send WQE overhead and check
+        * whether max_desc_sz imposes a lower limit than max_sg; UD
+        * send has the biggest overhead.
+        */
+       mdev->limits.max_sg             = min_t(int, dev_lim->max_sg,
+                                             (dev_lim->max_desc_sz -
+                                              sizeof (struct mthca_next_seg) -
+                                              (mthca_is_memfree(mdev) ?
+                                               sizeof (struct mthca_arbel_ud_seg) :
+                                               sizeof (struct mthca_tavor_ud_seg))) /
+                                               sizeof (struct mthca_data_seg));
        mdev->limits.max_wqes           = dev_lim->max_qp_sz;
        mdev->limits.max_qp_init_rdma   = dev_lim->max_requester_per_qp;
        mdev->limits.reserved_qps       = dev_lim->reserved_qps;
@@ -289,11 +279,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 +341,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) {
@@ -627,7 +624,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;
 
@@ -675,7 +672,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;
        }
@@ -757,7 +754,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;
@@ -833,14 +831,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;
        }
@@ -1017,7 +1018,7 @@ static struct {
                           .flags     = 0 },
        [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 8, 200),
                           .flags     = MTHCA_FLAG_PCIE },
-       [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 2, 0),
+       [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 3, 0),
                           .flags     = MTHCA_FLAG_MEMFREE |
                                        MTHCA_FLAG_PCIE },
        [SINAI]        = { .latest_fw = MTHCA_FW_VER(1, 2, 0),
@@ -1115,12 +1116,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;
@@ -1135,7 +1130,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.%3d is old (%d.%d.%3d 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),
@@ -1144,7 +1139,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;
 
@@ -1180,17 +1186,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:
@@ -1236,8 +1240,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 &