Pull ia64-clocksource into release branch
[pandora-kernel.git] / drivers / infiniband / hw / mthca / mthca_main.c
index 0491ec7..76fed75 100644 (file)
@@ -67,7 +67,7 @@ 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");
+MODULE_PARM_DESC(msi, "attempt to use MSI if nonzero (deprecated, use MSI-X instead)");
 
 #else /* CONFIG_PCI_MSI */
 
@@ -80,24 +80,61 @@ static int tune_pci = 0;
 module_param(tune_pci, int, 0444);
 MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero");
 
-struct mutex mthca_device_mutex;
+DEFINE_MUTEX(mthca_device_mutex);
+
+#define MTHCA_DEFAULT_NUM_QP            (1 << 16)
+#define MTHCA_DEFAULT_RDB_PER_QP        (1 << 2)
+#define MTHCA_DEFAULT_NUM_CQ            (1 << 16)
+#define MTHCA_DEFAULT_NUM_MCG           (1 << 13)
+#define MTHCA_DEFAULT_NUM_MPT           (1 << 17)
+#define MTHCA_DEFAULT_NUM_MTT           (1 << 20)
+#define MTHCA_DEFAULT_NUM_UDAV          (1 << 15)
+#define MTHCA_DEFAULT_NUM_RESERVED_MTTS (1 << 18)
+#define MTHCA_DEFAULT_NUM_UARC_SIZE     (1 << 18)
+
+static struct mthca_profile hca_profile = {
+       .num_qp             = MTHCA_DEFAULT_NUM_QP,
+       .rdb_per_qp         = MTHCA_DEFAULT_RDB_PER_QP,
+       .num_cq             = MTHCA_DEFAULT_NUM_CQ,
+       .num_mcg            = MTHCA_DEFAULT_NUM_MCG,
+       .num_mpt            = MTHCA_DEFAULT_NUM_MPT,
+       .num_mtt            = MTHCA_DEFAULT_NUM_MTT,
+       .num_udav           = MTHCA_DEFAULT_NUM_UDAV,          /* Tavor only */
+       .fmr_reserved_mtts  = MTHCA_DEFAULT_NUM_RESERVED_MTTS, /* Tavor only */
+       .uarc_size          = MTHCA_DEFAULT_NUM_UARC_SIZE,     /* Arbel only */
+};
+
+module_param_named(num_qp, hca_profile.num_qp, int, 0444);
+MODULE_PARM_DESC(num_qp, "maximum number of QPs per HCA");
+
+module_param_named(rdb_per_qp, hca_profile.rdb_per_qp, int, 0444);
+MODULE_PARM_DESC(rdb_per_qp, "number of RDB buffers per QP");
+
+module_param_named(num_cq, hca_profile.num_cq, int, 0444);
+MODULE_PARM_DESC(num_cq, "maximum number of CQs per HCA");
+
+module_param_named(num_mcg, hca_profile.num_mcg, int, 0444);
+MODULE_PARM_DESC(num_mcg, "maximum number of multicast groups per HCA");
+
+module_param_named(num_mpt, hca_profile.num_mpt, int, 0444);
+MODULE_PARM_DESC(num_mpt,
+               "maximum number of memory protection table entries per HCA");
+
+module_param_named(num_mtt, hca_profile.num_mtt, int, 0444);
+MODULE_PARM_DESC(num_mtt,
+                "maximum number of memory translation table segments per HCA");
+
+module_param_named(num_udav, hca_profile.num_udav, int, 0444);
+MODULE_PARM_DESC(num_udav, "maximum number of UD address vectors per HCA");
+
+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 =
        DRV_NAME ": Mellanox InfiniBand HCA driver v"
        DRV_VERSION " (" DRV_RELDATE ")\n";
 
-static struct mthca_profile default_profile = {
-       .num_qp            = 1 << 16,
-       .rdb_per_qp        = 4,
-       .num_cq            = 1 << 16,
-       .num_mcg           = 1 << 13,
-       .num_mpt           = 1 << 17,
-       .num_mtt           = 1 << 20,
-       .num_udav          = 1 << 15,   /* Tavor only */
-       .fmr_reserved_mtts = 1 << 18,   /* Tavor only */
-       .uarc_size         = 1 << 18,   /* Arbel only */
-};
-
 static int mthca_tune_pci(struct mthca_dev *mdev)
 {
        int cap;
@@ -303,7 +340,7 @@ static int mthca_init_tavor(struct mthca_dev *mdev)
                goto err_disable;
        }
 
-       profile = default_profile;
+       profile = hca_profile;
        profile.num_uar   = dev_lim.uar_size / PAGE_SIZE;
        profile.uarc_size = 0;
        if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
@@ -342,7 +379,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;
@@ -375,7 +412,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;
 }
 
@@ -404,7 +441,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;
@@ -427,10 +464,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;
@@ -440,7 +482,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;
@@ -450,7 +493,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;
@@ -460,7 +504,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;
@@ -470,7 +515,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");
@@ -481,7 +526,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;
@@ -493,7 +539,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");
@@ -513,7 +560,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;
@@ -551,7 +598,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;
 }
@@ -572,7 +619,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)
@@ -621,7 +668,7 @@ static int mthca_init_arbel(struct mthca_dev *mdev)
                goto err_stop_fw;
        }
 
-       profile = default_profile;
+       profile = hca_profile;
        profile.num_uar  = dev_lim.uar_size / PAGE_SIZE;
        profile.num_udav = 0;
        if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
@@ -656,7 +703,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))
@@ -675,7 +722,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);
@@ -966,14 +1013,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, 2, 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 }
@@ -1070,9 +1117,21 @@ static int __mthca_init_one(struct pci_dev *pdev, int hca_type)
 
        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;
+       else if (msi) {
+               static int warned;
+
+               if (!warned) {
+                       printk(KERN_WARNING PFX "WARNING: MSI support will be "
+                              "removed from the ib_mthca driver in January 2008.\n");
+                       printk(KERN_WARNING "    If you are using MSI and cannot "
+                              "switch to MSI-X, please tell "
+                              "<general@lists.openfabrics.org>.\n");
+                       ++warned;
+               }
+
+               if (!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");
@@ -1088,7 +1147,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),
@@ -1203,12 +1262,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,
@@ -1278,11 +1339,55 @@ static struct pci_driver mthca_driver = {
        .remove         = __devexit_p(mthca_remove_one)
 };
 
+static void __init __mthca_check_profile_val(const char *name, int *pval,
+                                            int pval_default)
+{
+       /* value must be positive and power of 2 */
+       int old_pval = *pval;
+
+       if (old_pval <= 0)
+               *pval = pval_default;
+       else
+               *pval = roundup_pow_of_two(old_pval);
+
+       if (old_pval != *pval) {
+               printk(KERN_WARNING PFX "Invalid value %d for %s in module parameter.\n",
+                      old_pval, name);
+               printk(KERN_WARNING PFX "Corrected %s to %d.\n", name, *pval);
+       }
+}
+
+#define mthca_check_profile_val(name, default)                         \
+       __mthca_check_profile_val(#name, &hca_profile.name, default)
+
+static void __init mthca_validate_profile(void)
+{
+       mthca_check_profile_val(num_qp,            MTHCA_DEFAULT_NUM_QP);
+       mthca_check_profile_val(rdb_per_qp,        MTHCA_DEFAULT_RDB_PER_QP);
+       mthca_check_profile_val(num_cq,            MTHCA_DEFAULT_NUM_CQ);
+       mthca_check_profile_val(num_mcg,           MTHCA_DEFAULT_NUM_MCG);
+       mthca_check_profile_val(num_mpt,           MTHCA_DEFAULT_NUM_MPT);
+       mthca_check_profile_val(num_mtt,           MTHCA_DEFAULT_NUM_MTT);
+       mthca_check_profile_val(num_udav,          MTHCA_DEFAULT_NUM_UDAV);
+       mthca_check_profile_val(fmr_reserved_mtts, MTHCA_DEFAULT_NUM_RESERVED_MTTS);
+
+       if (hca_profile.fmr_reserved_mtts >= hca_profile.num_mtt) {
+               printk(KERN_WARNING PFX "Invalid fmr_reserved_mtts module parameter %d.\n",
+                      hca_profile.fmr_reserved_mtts);
+               printk(KERN_WARNING PFX "(Must be smaller than num_mtt %d)\n",
+                      hca_profile.num_mtt);
+               hca_profile.fmr_reserved_mtts = hca_profile.num_mtt / 2;
+               printk(KERN_WARNING PFX "Corrected fmr_reserved_mtts to %d.\n",
+                      hca_profile.fmr_reserved_mtts);
+       }
+}
+
 static int __init mthca_init(void)
 {
        int ret;
 
-       mutex_init(&mthca_device_mutex);
+       mthca_validate_profile();
+
        ret = mthca_catas_init();
        if (ret)
                return ret;