133ec1ccbSHans Petter Selasky /*
233ec1ccbSHans Petter Selasky * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
333ec1ccbSHans Petter Selasky * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
433ec1ccbSHans Petter Selasky * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
533ec1ccbSHans Petter Selasky *
633ec1ccbSHans Petter Selasky * This software is available to you under a choice of one of two
733ec1ccbSHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU
833ec1ccbSHans Petter Selasky * General Public License (GPL) Version 2, available from the file
933ec1ccbSHans Petter Selasky * COPYING in the main directory of this source tree, or the
1033ec1ccbSHans Petter Selasky * OpenIB.org BSD license below:
1133ec1ccbSHans Petter Selasky *
1233ec1ccbSHans Petter Selasky * Redistribution and use in source and binary forms, with or
1333ec1ccbSHans Petter Selasky * without modification, are permitted provided that the following
1433ec1ccbSHans Petter Selasky * conditions are met:
1533ec1ccbSHans Petter Selasky *
1633ec1ccbSHans Petter Selasky * - Redistributions of source code must retain the above
1733ec1ccbSHans Petter Selasky * copyright notice, this list of conditions and the following
1833ec1ccbSHans Petter Selasky * disclaimer.
1933ec1ccbSHans Petter Selasky *
2033ec1ccbSHans Petter Selasky * - Redistributions in binary form must reproduce the above
2133ec1ccbSHans Petter Selasky * copyright notice, this list of conditions and the following
2233ec1ccbSHans Petter Selasky * disclaimer in the documentation and/or other materials
2333ec1ccbSHans Petter Selasky * provided with the distribution.
2433ec1ccbSHans Petter Selasky *
2533ec1ccbSHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2633ec1ccbSHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2733ec1ccbSHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2833ec1ccbSHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2933ec1ccbSHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3033ec1ccbSHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3133ec1ccbSHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3233ec1ccbSHans Petter Selasky * SOFTWARE.
3333ec1ccbSHans Petter Selasky */
3433ec1ccbSHans Petter Selasky
3533ec1ccbSHans Petter Selasky #define LINUXKPI_PARAM_PREFIX mthca_
3633ec1ccbSHans Petter Selasky
3733ec1ccbSHans Petter Selasky #include <linux/module.h>
3833ec1ccbSHans Petter Selasky #include <linux/errno.h>
3933ec1ccbSHans Petter Selasky #include <linux/pci.h>
4033ec1ccbSHans Petter Selasky #include <linux/interrupt.h>
4133ec1ccbSHans Petter Selasky #include <linux/gfp.h>
4233ec1ccbSHans Petter Selasky
4333ec1ccbSHans Petter Selasky #include "mthca_dev.h"
4433ec1ccbSHans Petter Selasky #include "mthca_config_reg.h"
4533ec1ccbSHans Petter Selasky #include "mthca_cmd.h"
4633ec1ccbSHans Petter Selasky #include "mthca_profile.h"
4733ec1ccbSHans Petter Selasky #include "mthca_memfree.h"
4833ec1ccbSHans Petter Selasky #include "mthca_wqe.h"
4933ec1ccbSHans Petter Selasky
5033ec1ccbSHans Petter Selasky MODULE_AUTHOR("Roland Dreier");
5133ec1ccbSHans Petter Selasky MODULE_DESCRIPTION("Mellanox InfiniBand HCA low-level driver");
5233ec1ccbSHans Petter Selasky MODULE_LICENSE("Dual BSD/GPL");
5333ec1ccbSHans Petter Selasky
5433ec1ccbSHans Petter Selasky #ifdef CONFIG_INFINIBAND_MTHCA_DEBUG
5533ec1ccbSHans Petter Selasky
5633ec1ccbSHans Petter Selasky int mthca_debug_level = 0;
5733ec1ccbSHans Petter Selasky module_param_named(debug_level, mthca_debug_level, int, 0644);
5833ec1ccbSHans Petter Selasky MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
5933ec1ccbSHans Petter Selasky
6033ec1ccbSHans Petter Selasky #endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */
6133ec1ccbSHans Petter Selasky
6233ec1ccbSHans Petter Selasky #ifdef CONFIG_PCI_MSI
6333ec1ccbSHans Petter Selasky
6433ec1ccbSHans Petter Selasky static int msi_x = 1;
6533ec1ccbSHans Petter Selasky module_param(msi_x, int, 0444);
6633ec1ccbSHans Petter Selasky MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
6733ec1ccbSHans Petter Selasky
6833ec1ccbSHans Petter Selasky #else /* CONFIG_PCI_MSI */
6933ec1ccbSHans Petter Selasky
7033ec1ccbSHans Petter Selasky #define msi_x (0)
7133ec1ccbSHans Petter Selasky
7233ec1ccbSHans Petter Selasky #endif /* CONFIG_PCI_MSI */
7333ec1ccbSHans Petter Selasky
7433ec1ccbSHans Petter Selasky static int tune_pci = 0;
7533ec1ccbSHans Petter Selasky module_param(tune_pci, int, 0444);
7633ec1ccbSHans Petter Selasky MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero");
7733ec1ccbSHans Petter Selasky
7833ec1ccbSHans Petter Selasky DEFINE_MUTEX(mthca_device_mutex);
7933ec1ccbSHans Petter Selasky
8033ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_NUM_QP (1 << 16)
8133ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_RDB_PER_QP (1 << 2)
8233ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_NUM_CQ (1 << 16)
8333ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_NUM_MCG (1 << 13)
8433ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_NUM_MPT (1 << 17)
8533ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_NUM_MTT (1 << 20)
8633ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_NUM_UDAV (1 << 15)
8733ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_NUM_RESERVED_MTTS (1 << 18)
8833ec1ccbSHans Petter Selasky #define MTHCA_DEFAULT_NUM_UARC_SIZE (1 << 18)
8933ec1ccbSHans Petter Selasky
9033ec1ccbSHans Petter Selasky static struct mthca_profile hca_profile = {
9133ec1ccbSHans Petter Selasky .num_qp = MTHCA_DEFAULT_NUM_QP,
9233ec1ccbSHans Petter Selasky .rdb_per_qp = MTHCA_DEFAULT_RDB_PER_QP,
9333ec1ccbSHans Petter Selasky .num_cq = MTHCA_DEFAULT_NUM_CQ,
9433ec1ccbSHans Petter Selasky .num_mcg = MTHCA_DEFAULT_NUM_MCG,
9533ec1ccbSHans Petter Selasky .num_mpt = MTHCA_DEFAULT_NUM_MPT,
9633ec1ccbSHans Petter Selasky .num_mtt = MTHCA_DEFAULT_NUM_MTT,
9733ec1ccbSHans Petter Selasky .num_udav = MTHCA_DEFAULT_NUM_UDAV, /* Tavor only */
9833ec1ccbSHans Petter Selasky .fmr_reserved_mtts = MTHCA_DEFAULT_NUM_RESERVED_MTTS, /* Tavor only */
9933ec1ccbSHans Petter Selasky .uarc_size = MTHCA_DEFAULT_NUM_UARC_SIZE, /* Arbel only */
10033ec1ccbSHans Petter Selasky };
10133ec1ccbSHans Petter Selasky
10233ec1ccbSHans Petter Selasky module_param_named(num_qp, hca_profile.num_qp, int, 0444);
10333ec1ccbSHans Petter Selasky MODULE_PARM_DESC(num_qp, "maximum number of QPs per HCA");
10433ec1ccbSHans Petter Selasky
10533ec1ccbSHans Petter Selasky module_param_named(rdb_per_qp, hca_profile.rdb_per_qp, int, 0444);
10633ec1ccbSHans Petter Selasky MODULE_PARM_DESC(rdb_per_qp, "number of RDB buffers per QP");
10733ec1ccbSHans Petter Selasky
10833ec1ccbSHans Petter Selasky module_param_named(num_cq, hca_profile.num_cq, int, 0444);
10933ec1ccbSHans Petter Selasky MODULE_PARM_DESC(num_cq, "maximum number of CQs per HCA");
11033ec1ccbSHans Petter Selasky
11133ec1ccbSHans Petter Selasky module_param_named(num_mcg, hca_profile.num_mcg, int, 0444);
11233ec1ccbSHans Petter Selasky MODULE_PARM_DESC(num_mcg, "maximum number of multicast groups per HCA");
11333ec1ccbSHans Petter Selasky
11433ec1ccbSHans Petter Selasky module_param_named(num_mpt, hca_profile.num_mpt, int, 0444);
11533ec1ccbSHans Petter Selasky MODULE_PARM_DESC(num_mpt,
11633ec1ccbSHans Petter Selasky "maximum number of memory protection table entries per HCA");
11733ec1ccbSHans Petter Selasky
11833ec1ccbSHans Petter Selasky module_param_named(num_mtt, hca_profile.num_mtt, int, 0444);
11933ec1ccbSHans Petter Selasky MODULE_PARM_DESC(num_mtt,
12033ec1ccbSHans Petter Selasky "maximum number of memory translation table segments per HCA");
12133ec1ccbSHans Petter Selasky
12233ec1ccbSHans Petter Selasky module_param_named(num_udav, hca_profile.num_udav, int, 0444);
12333ec1ccbSHans Petter Selasky MODULE_PARM_DESC(num_udav, "maximum number of UD address vectors per HCA");
12433ec1ccbSHans Petter Selasky
12533ec1ccbSHans Petter Selasky module_param_named(fmr_reserved_mtts, hca_profile.fmr_reserved_mtts, int, 0444);
12633ec1ccbSHans Petter Selasky MODULE_PARM_DESC(fmr_reserved_mtts,
12733ec1ccbSHans Petter Selasky "number of memory translation table segments reserved for FMR");
12833ec1ccbSHans Petter Selasky
12933ec1ccbSHans Petter Selasky static int log_mtts_per_seg = ilog2(MTHCA_MTT_SEG_SIZE / 8);
13033ec1ccbSHans Petter Selasky module_param_named(log_mtts_per_seg, log_mtts_per_seg, int, 0444);
13133ec1ccbSHans Petter Selasky MODULE_PARM_DESC(log_mtts_per_seg, "Log2 number of MTT entries per segment (1-5)");
13233ec1ccbSHans Petter Selasky
13333ec1ccbSHans Petter Selasky static char mthca_version[] =
13433ec1ccbSHans Petter Selasky DRV_NAME ": Mellanox InfiniBand HCA driver v"
13533ec1ccbSHans Petter Selasky DRV_VERSION " (" DRV_RELDATE ")\n";
13633ec1ccbSHans Petter Selasky
mthca_tune_pci(struct mthca_dev * mdev)13733ec1ccbSHans Petter Selasky static int mthca_tune_pci(struct mthca_dev *mdev)
13833ec1ccbSHans Petter Selasky {
13933ec1ccbSHans Petter Selasky if (!tune_pci)
14033ec1ccbSHans Petter Selasky return 0;
14133ec1ccbSHans Petter Selasky
14233ec1ccbSHans Petter Selasky /* First try to max out Read Byte Count */
14333ec1ccbSHans Petter Selasky if (pci_find_capability(mdev->pdev, PCI_CAP_ID_PCIX)) {
14433ec1ccbSHans Petter Selasky if (pcix_set_mmrbc(mdev->pdev, pcix_get_max_mmrbc(mdev->pdev))) {
14533ec1ccbSHans Petter Selasky mthca_err(mdev, "Couldn't set PCI-X max read count, "
14633ec1ccbSHans Petter Selasky "aborting.\n");
14733ec1ccbSHans Petter Selasky return -ENODEV;
14833ec1ccbSHans Petter Selasky }
14933ec1ccbSHans Petter Selasky } else if (!(mdev->mthca_flags & MTHCA_FLAG_PCIE))
15033ec1ccbSHans Petter Selasky mthca_info(mdev, "No PCI-X capability, not setting RBC.\n");
15133ec1ccbSHans Petter Selasky
15233ec1ccbSHans Petter Selasky if (pci_is_pcie(mdev->pdev)) {
15333ec1ccbSHans Petter Selasky if (pcie_set_readrq(mdev->pdev, 4096)) {
15433ec1ccbSHans Petter Selasky mthca_err(mdev, "Couldn't write PCI Express read request, "
15533ec1ccbSHans Petter Selasky "aborting.\n");
15633ec1ccbSHans Petter Selasky return -ENODEV;
15733ec1ccbSHans Petter Selasky }
15833ec1ccbSHans Petter Selasky } else if (mdev->mthca_flags & MTHCA_FLAG_PCIE)
15933ec1ccbSHans Petter Selasky mthca_info(mdev, "No PCI Express capability, "
16033ec1ccbSHans Petter Selasky "not setting Max Read Request Size.\n");
16133ec1ccbSHans Petter Selasky
16233ec1ccbSHans Petter Selasky return 0;
16333ec1ccbSHans Petter Selasky }
16433ec1ccbSHans Petter Selasky
mthca_dev_lim(struct mthca_dev * mdev,struct mthca_dev_lim * dev_lim)16533ec1ccbSHans Petter Selasky static int mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim *dev_lim)
16633ec1ccbSHans Petter Selasky {
16733ec1ccbSHans Petter Selasky int err;
16833ec1ccbSHans Petter Selasky
16933ec1ccbSHans Petter Selasky mdev->limits.mtt_seg_size = (1 << log_mtts_per_seg) * 8;
17033ec1ccbSHans Petter Selasky err = mthca_QUERY_DEV_LIM(mdev, dev_lim);
17133ec1ccbSHans Petter Selasky if (err) {
17233ec1ccbSHans Petter Selasky mthca_err(mdev, "QUERY_DEV_LIM command returned %d"
17333ec1ccbSHans Petter Selasky ", aborting.\n", err);
17433ec1ccbSHans Petter Selasky return err;
17533ec1ccbSHans Petter Selasky }
17633ec1ccbSHans Petter Selasky if (dev_lim->min_page_sz > PAGE_SIZE) {
17733ec1ccbSHans Petter Selasky mthca_err(mdev, "HCA minimum page size of %d bigger than "
17833ec1ccbSHans Petter Selasky "kernel PAGE_SIZE of %ld, aborting.\n",
17933ec1ccbSHans Petter Selasky dev_lim->min_page_sz, (long)PAGE_SIZE);
18033ec1ccbSHans Petter Selasky return -ENODEV;
18133ec1ccbSHans Petter Selasky }
18233ec1ccbSHans Petter Selasky if (dev_lim->num_ports > MTHCA_MAX_PORTS) {
18333ec1ccbSHans Petter Selasky mthca_err(mdev, "HCA has %d ports, but we only support %d, "
18433ec1ccbSHans Petter Selasky "aborting.\n",
18533ec1ccbSHans Petter Selasky dev_lim->num_ports, MTHCA_MAX_PORTS);
18633ec1ccbSHans Petter Selasky return -ENODEV;
18733ec1ccbSHans Petter Selasky }
18833ec1ccbSHans Petter Selasky
18933ec1ccbSHans Petter Selasky if (dev_lim->uar_size > pci_resource_len(mdev->pdev, 2)) {
19033ec1ccbSHans Petter Selasky mthca_err(mdev, "HCA reported UAR size of 0x%x bigger than "
19133ec1ccbSHans Petter Selasky "PCI resource 2 size of 0x%llx, aborting.\n",
19233ec1ccbSHans Petter Selasky dev_lim->uar_size,
19333ec1ccbSHans Petter Selasky (unsigned long long)pci_resource_len(mdev->pdev, 2));
19433ec1ccbSHans Petter Selasky return -ENODEV;
19533ec1ccbSHans Petter Selasky }
19633ec1ccbSHans Petter Selasky
19733ec1ccbSHans Petter Selasky mdev->limits.num_ports = dev_lim->num_ports;
19833ec1ccbSHans Petter Selasky mdev->limits.vl_cap = dev_lim->max_vl;
19933ec1ccbSHans Petter Selasky mdev->limits.mtu_cap = dev_lim->max_mtu;
20033ec1ccbSHans Petter Selasky mdev->limits.gid_table_len = dev_lim->max_gids;
20133ec1ccbSHans Petter Selasky mdev->limits.pkey_table_len = dev_lim->max_pkeys;
20233ec1ccbSHans Petter Selasky mdev->limits.local_ca_ack_delay = dev_lim->local_ca_ack_delay;
20333ec1ccbSHans Petter Selasky /*
20433ec1ccbSHans Petter Selasky * Need to allow for worst case send WQE overhead and check
20533ec1ccbSHans Petter Selasky * whether max_desc_sz imposes a lower limit than max_sg; UD
20633ec1ccbSHans Petter Selasky * send has the biggest overhead.
20733ec1ccbSHans Petter Selasky */
20833ec1ccbSHans Petter Selasky mdev->limits.max_sg = min_t(int, dev_lim->max_sg,
20933ec1ccbSHans Petter Selasky (dev_lim->max_desc_sz -
21033ec1ccbSHans Petter Selasky sizeof (struct mthca_next_seg) -
21133ec1ccbSHans Petter Selasky (mthca_is_memfree(mdev) ?
21233ec1ccbSHans Petter Selasky sizeof (struct mthca_arbel_ud_seg) :
21333ec1ccbSHans Petter Selasky sizeof (struct mthca_tavor_ud_seg))) /
21433ec1ccbSHans Petter Selasky sizeof (struct mthca_data_seg));
21533ec1ccbSHans Petter Selasky mdev->limits.max_wqes = dev_lim->max_qp_sz;
21633ec1ccbSHans Petter Selasky mdev->limits.max_qp_init_rdma = dev_lim->max_requester_per_qp;
21733ec1ccbSHans Petter Selasky mdev->limits.reserved_qps = dev_lim->reserved_qps;
21833ec1ccbSHans Petter Selasky mdev->limits.max_srq_wqes = dev_lim->max_srq_sz;
21933ec1ccbSHans Petter Selasky mdev->limits.reserved_srqs = dev_lim->reserved_srqs;
22033ec1ccbSHans Petter Selasky mdev->limits.reserved_eecs = dev_lim->reserved_eecs;
22133ec1ccbSHans Petter Selasky mdev->limits.max_desc_sz = dev_lim->max_desc_sz;
22233ec1ccbSHans Petter Selasky mdev->limits.max_srq_sge = mthca_max_srq_sge(mdev);
22333ec1ccbSHans Petter Selasky /*
22433ec1ccbSHans Petter Selasky * Subtract 1 from the limit because we need to allocate a
22533ec1ccbSHans Petter Selasky * spare CQE so the HCA HW can tell the difference between an
22633ec1ccbSHans Petter Selasky * empty CQ and a full CQ.
22733ec1ccbSHans Petter Selasky */
22833ec1ccbSHans Petter Selasky mdev->limits.max_cqes = dev_lim->max_cq_sz - 1;
22933ec1ccbSHans Petter Selasky mdev->limits.reserved_cqs = dev_lim->reserved_cqs;
23033ec1ccbSHans Petter Selasky mdev->limits.reserved_eqs = dev_lim->reserved_eqs;
23133ec1ccbSHans Petter Selasky mdev->limits.reserved_mtts = dev_lim->reserved_mtts;
23233ec1ccbSHans Petter Selasky mdev->limits.reserved_mrws = dev_lim->reserved_mrws;
23333ec1ccbSHans Petter Selasky mdev->limits.reserved_uars = dev_lim->reserved_uars;
23433ec1ccbSHans Petter Selasky mdev->limits.reserved_pds = dev_lim->reserved_pds;
23533ec1ccbSHans Petter Selasky mdev->limits.port_width_cap = dev_lim->max_port_width;
23633ec1ccbSHans Petter Selasky mdev->limits.page_size_cap = ~(u32) (dev_lim->min_page_sz - 1);
23733ec1ccbSHans Petter Selasky mdev->limits.flags = dev_lim->flags;
23833ec1ccbSHans Petter Selasky /*
23933ec1ccbSHans Petter Selasky * For old FW that doesn't return static rate support, use a
24033ec1ccbSHans Petter Selasky * value of 0x3 (only static rate values of 0 or 1 are handled),
24133ec1ccbSHans Petter Selasky * except on Sinai, where even old FW can handle static rate
24233ec1ccbSHans Petter Selasky * values of 2 and 3.
24333ec1ccbSHans Petter Selasky */
24433ec1ccbSHans Petter Selasky if (dev_lim->stat_rate_support)
24533ec1ccbSHans Petter Selasky mdev->limits.stat_rate_support = dev_lim->stat_rate_support;
24633ec1ccbSHans Petter Selasky else if (mdev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
24733ec1ccbSHans Petter Selasky mdev->limits.stat_rate_support = 0xf;
24833ec1ccbSHans Petter Selasky else
24933ec1ccbSHans Petter Selasky mdev->limits.stat_rate_support = 0x3;
25033ec1ccbSHans Petter Selasky
25133ec1ccbSHans Petter Selasky /* IB_DEVICE_RESIZE_MAX_WR not supported by driver.
25233ec1ccbSHans Petter Selasky May be doable since hardware supports it for SRQ.
25333ec1ccbSHans Petter Selasky
25433ec1ccbSHans Petter Selasky IB_DEVICE_N_NOTIFY_CQ is supported by hardware but not by driver.
25533ec1ccbSHans Petter Selasky
25633ec1ccbSHans Petter Selasky IB_DEVICE_SRQ_RESIZE is supported by hardware but SRQ is not
25733ec1ccbSHans Petter Selasky supported by driver. */
25833ec1ccbSHans Petter Selasky mdev->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT |
25933ec1ccbSHans Petter Selasky IB_DEVICE_PORT_ACTIVE_EVENT |
26033ec1ccbSHans Petter Selasky IB_DEVICE_SYS_IMAGE_GUID |
26133ec1ccbSHans Petter Selasky IB_DEVICE_RC_RNR_NAK_GEN;
26233ec1ccbSHans Petter Selasky
26333ec1ccbSHans Petter Selasky if (dev_lim->flags & DEV_LIM_FLAG_BAD_PKEY_CNTR)
26433ec1ccbSHans Petter Selasky mdev->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
26533ec1ccbSHans Petter Selasky
26633ec1ccbSHans Petter Selasky if (dev_lim->flags & DEV_LIM_FLAG_BAD_QKEY_CNTR)
26733ec1ccbSHans Petter Selasky mdev->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR;
26833ec1ccbSHans Petter Selasky
26933ec1ccbSHans Petter Selasky if (dev_lim->flags & DEV_LIM_FLAG_RAW_MULTI)
27033ec1ccbSHans Petter Selasky mdev->device_cap_flags |= IB_DEVICE_RAW_MULTI;
27133ec1ccbSHans Petter Selasky
27233ec1ccbSHans Petter Selasky if (dev_lim->flags & DEV_LIM_FLAG_AUTO_PATH_MIG)
27333ec1ccbSHans Petter Selasky mdev->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG;
27433ec1ccbSHans Petter Selasky
27533ec1ccbSHans Petter Selasky if (dev_lim->flags & DEV_LIM_FLAG_UD_AV_PORT_ENFORCE)
27633ec1ccbSHans Petter Selasky mdev->device_cap_flags |= IB_DEVICE_UD_AV_PORT_ENFORCE;
27733ec1ccbSHans Petter Selasky
27833ec1ccbSHans Petter Selasky if (dev_lim->flags & DEV_LIM_FLAG_SRQ)
27933ec1ccbSHans Petter Selasky mdev->mthca_flags |= MTHCA_FLAG_SRQ;
28033ec1ccbSHans Petter Selasky
28133ec1ccbSHans Petter Selasky if (mthca_is_memfree(mdev))
28233ec1ccbSHans Petter Selasky if (dev_lim->flags & DEV_LIM_FLAG_IPOIB_CSUM)
28333ec1ccbSHans Petter Selasky mdev->device_cap_flags |= IB_DEVICE_UD_IP_CSUM;
28433ec1ccbSHans Petter Selasky
28533ec1ccbSHans Petter Selasky return 0;
28633ec1ccbSHans Petter Selasky }
28733ec1ccbSHans Petter Selasky
mthca_init_tavor(struct mthca_dev * mdev)28833ec1ccbSHans Petter Selasky static int mthca_init_tavor(struct mthca_dev *mdev)
28933ec1ccbSHans Petter Selasky {
29033ec1ccbSHans Petter Selasky s64 size;
29133ec1ccbSHans Petter Selasky int err;
29233ec1ccbSHans Petter Selasky struct mthca_dev_lim dev_lim;
29333ec1ccbSHans Petter Selasky struct mthca_profile profile;
29433ec1ccbSHans Petter Selasky struct mthca_init_hca_param init_hca;
29533ec1ccbSHans Petter Selasky
29633ec1ccbSHans Petter Selasky err = mthca_SYS_EN(mdev);
29733ec1ccbSHans Petter Selasky if (err) {
29833ec1ccbSHans Petter Selasky mthca_err(mdev, "SYS_EN command returned %d, aborting.\n", err);
29933ec1ccbSHans Petter Selasky return err;
30033ec1ccbSHans Petter Selasky }
30133ec1ccbSHans Petter Selasky
30233ec1ccbSHans Petter Selasky err = mthca_QUERY_FW(mdev);
30333ec1ccbSHans Petter Selasky if (err) {
30433ec1ccbSHans Petter Selasky mthca_err(mdev, "QUERY_FW command returned %d,"
30533ec1ccbSHans Petter Selasky " aborting.\n", err);
30633ec1ccbSHans Petter Selasky goto err_disable;
30733ec1ccbSHans Petter Selasky }
30833ec1ccbSHans Petter Selasky err = mthca_QUERY_DDR(mdev);
30933ec1ccbSHans Petter Selasky if (err) {
31033ec1ccbSHans Petter Selasky mthca_err(mdev, "QUERY_DDR command returned %d, aborting.\n", err);
31133ec1ccbSHans Petter Selasky goto err_disable;
31233ec1ccbSHans Petter Selasky }
31333ec1ccbSHans Petter Selasky
31433ec1ccbSHans Petter Selasky err = mthca_dev_lim(mdev, &dev_lim);
31533ec1ccbSHans Petter Selasky if (err) {
31633ec1ccbSHans Petter Selasky mthca_err(mdev, "QUERY_DEV_LIM command returned %d, aborting.\n", err);
31733ec1ccbSHans Petter Selasky goto err_disable;
31833ec1ccbSHans Petter Selasky }
31933ec1ccbSHans Petter Selasky
32033ec1ccbSHans Petter Selasky profile = hca_profile;
32133ec1ccbSHans Petter Selasky profile.num_uar = dev_lim.uar_size / PAGE_SIZE;
32233ec1ccbSHans Petter Selasky profile.uarc_size = 0;
32333ec1ccbSHans Petter Selasky if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
32433ec1ccbSHans Petter Selasky profile.num_srq = dev_lim.max_srqs;
32533ec1ccbSHans Petter Selasky
32633ec1ccbSHans Petter Selasky size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
32733ec1ccbSHans Petter Selasky if (size < 0) {
32833ec1ccbSHans Petter Selasky err = size;
32933ec1ccbSHans Petter Selasky goto err_disable;
33033ec1ccbSHans Petter Selasky }
33133ec1ccbSHans Petter Selasky
33233ec1ccbSHans Petter Selasky err = mthca_INIT_HCA(mdev, &init_hca);
33333ec1ccbSHans Petter Selasky if (err) {
33433ec1ccbSHans Petter Selasky mthca_err(mdev, "INIT_HCA command returned %d, aborting.\n", err);
33533ec1ccbSHans Petter Selasky goto err_disable;
33633ec1ccbSHans Petter Selasky }
33733ec1ccbSHans Petter Selasky
33833ec1ccbSHans Petter Selasky return 0;
33933ec1ccbSHans Petter Selasky
34033ec1ccbSHans Petter Selasky err_disable:
34133ec1ccbSHans Petter Selasky mthca_SYS_DIS(mdev);
34233ec1ccbSHans Petter Selasky
34333ec1ccbSHans Petter Selasky return err;
34433ec1ccbSHans Petter Selasky }
34533ec1ccbSHans Petter Selasky
mthca_load_fw(struct mthca_dev * mdev)34633ec1ccbSHans Petter Selasky static int mthca_load_fw(struct mthca_dev *mdev)
34733ec1ccbSHans Petter Selasky {
34833ec1ccbSHans Petter Selasky int err;
34933ec1ccbSHans Petter Selasky
35033ec1ccbSHans Petter Selasky /* FIXME: use HCA-attached memory for FW if present */
35133ec1ccbSHans Petter Selasky
35233ec1ccbSHans Petter Selasky mdev->fw.arbel.fw_icm =
35333ec1ccbSHans Petter Selasky mthca_alloc_icm(mdev, mdev->fw.arbel.fw_pages,
35433ec1ccbSHans Petter Selasky GFP_HIGHUSER | __GFP_NOWARN, 0);
35533ec1ccbSHans Petter Selasky if (!mdev->fw.arbel.fw_icm) {
35633ec1ccbSHans Petter Selasky mthca_err(mdev, "Couldn't allocate FW area, aborting.\n");
35733ec1ccbSHans Petter Selasky return -ENOMEM;
35833ec1ccbSHans Petter Selasky }
35933ec1ccbSHans Petter Selasky
36033ec1ccbSHans Petter Selasky err = mthca_MAP_FA(mdev, mdev->fw.arbel.fw_icm);
36133ec1ccbSHans Petter Selasky if (err) {
36233ec1ccbSHans Petter Selasky mthca_err(mdev, "MAP_FA command returned %d, aborting.\n", err);
36333ec1ccbSHans Petter Selasky goto err_free;
36433ec1ccbSHans Petter Selasky }
36533ec1ccbSHans Petter Selasky err = mthca_RUN_FW(mdev);
36633ec1ccbSHans Petter Selasky if (err) {
36733ec1ccbSHans Petter Selasky mthca_err(mdev, "RUN_FW command returned %d, aborting.\n", err);
36833ec1ccbSHans Petter Selasky goto err_unmap_fa;
36933ec1ccbSHans Petter Selasky }
37033ec1ccbSHans Petter Selasky
37133ec1ccbSHans Petter Selasky return 0;
37233ec1ccbSHans Petter Selasky
37333ec1ccbSHans Petter Selasky err_unmap_fa:
37433ec1ccbSHans Petter Selasky mthca_UNMAP_FA(mdev);
37533ec1ccbSHans Petter Selasky
37633ec1ccbSHans Petter Selasky err_free:
37733ec1ccbSHans Petter Selasky mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
37833ec1ccbSHans Petter Selasky return err;
37933ec1ccbSHans Petter Selasky }
38033ec1ccbSHans Petter Selasky
mthca_init_icm(struct mthca_dev * mdev,struct mthca_dev_lim * dev_lim,struct mthca_init_hca_param * init_hca,u64 icm_size)38133ec1ccbSHans Petter Selasky static int mthca_init_icm(struct mthca_dev *mdev,
38233ec1ccbSHans Petter Selasky struct mthca_dev_lim *dev_lim,
38333ec1ccbSHans Petter Selasky struct mthca_init_hca_param *init_hca,
38433ec1ccbSHans Petter Selasky u64 icm_size)
38533ec1ccbSHans Petter Selasky {
38633ec1ccbSHans Petter Selasky u64 aux_pages;
38733ec1ccbSHans Petter Selasky int err;
38833ec1ccbSHans Petter Selasky
38933ec1ccbSHans Petter Selasky err = mthca_SET_ICM_SIZE(mdev, icm_size, &aux_pages);
39033ec1ccbSHans Petter Selasky if (err) {
39133ec1ccbSHans Petter Selasky mthca_err(mdev, "SET_ICM_SIZE command returned %d, aborting.\n", err);
39233ec1ccbSHans Petter Selasky return err;
39333ec1ccbSHans Petter Selasky }
39433ec1ccbSHans Petter Selasky
39533ec1ccbSHans Petter Selasky mthca_dbg(mdev, "%lld KB of HCA context requires %lld KB aux memory.\n",
39633ec1ccbSHans Petter Selasky (unsigned long long) icm_size >> 10,
39733ec1ccbSHans Petter Selasky (unsigned long long) aux_pages << 2);
39833ec1ccbSHans Petter Selasky
39933ec1ccbSHans Petter Selasky mdev->fw.arbel.aux_icm = mthca_alloc_icm(mdev, aux_pages,
40033ec1ccbSHans Petter Selasky GFP_HIGHUSER | __GFP_NOWARN, 0);
40133ec1ccbSHans Petter Selasky if (!mdev->fw.arbel.aux_icm) {
40233ec1ccbSHans Petter Selasky mthca_err(mdev, "Couldn't allocate aux memory, aborting.\n");
40333ec1ccbSHans Petter Selasky return -ENOMEM;
40433ec1ccbSHans Petter Selasky }
40533ec1ccbSHans Petter Selasky
40633ec1ccbSHans Petter Selasky err = mthca_MAP_ICM_AUX(mdev, mdev->fw.arbel.aux_icm);
40733ec1ccbSHans Petter Selasky if (err) {
40833ec1ccbSHans Petter Selasky mthca_err(mdev, "MAP_ICM_AUX returned %d, aborting.\n", err);
40933ec1ccbSHans Petter Selasky goto err_free_aux;
41033ec1ccbSHans Petter Selasky }
41133ec1ccbSHans Petter Selasky
41233ec1ccbSHans Petter Selasky err = mthca_map_eq_icm(mdev, init_hca->eqc_base);
41333ec1ccbSHans Petter Selasky if (err) {
41433ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map EQ context memory, aborting.\n");
41533ec1ccbSHans Petter Selasky goto err_unmap_aux;
41633ec1ccbSHans Petter Selasky }
41733ec1ccbSHans Petter Selasky
41833ec1ccbSHans Petter Selasky /* CPU writes to non-reserved MTTs, while HCA might DMA to reserved mtts */
41933ec1ccbSHans Petter Selasky mdev->limits.reserved_mtts = ALIGN(mdev->limits.reserved_mtts * mdev->limits.mtt_seg_size,
42033ec1ccbSHans Petter Selasky dma_get_cache_alignment()) / mdev->limits.mtt_seg_size;
42133ec1ccbSHans Petter Selasky
42233ec1ccbSHans Petter Selasky mdev->mr_table.mtt_table = mthca_alloc_icm_table(mdev, init_hca->mtt_base,
42333ec1ccbSHans Petter Selasky mdev->limits.mtt_seg_size,
42433ec1ccbSHans Petter Selasky mdev->limits.num_mtt_segs,
42533ec1ccbSHans Petter Selasky mdev->limits.reserved_mtts,
42633ec1ccbSHans Petter Selasky 1, 0);
42733ec1ccbSHans Petter Selasky if (!mdev->mr_table.mtt_table) {
42833ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map MTT context memory, aborting.\n");
42933ec1ccbSHans Petter Selasky err = -ENOMEM;
43033ec1ccbSHans Petter Selasky goto err_unmap_eq;
43133ec1ccbSHans Petter Selasky }
43233ec1ccbSHans Petter Selasky
43333ec1ccbSHans Petter Selasky mdev->mr_table.mpt_table = mthca_alloc_icm_table(mdev, init_hca->mpt_base,
43433ec1ccbSHans Petter Selasky dev_lim->mpt_entry_sz,
43533ec1ccbSHans Petter Selasky mdev->limits.num_mpts,
43633ec1ccbSHans Petter Selasky mdev->limits.reserved_mrws,
43733ec1ccbSHans Petter Selasky 1, 1);
43833ec1ccbSHans Petter Selasky if (!mdev->mr_table.mpt_table) {
43933ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map MPT context memory, aborting.\n");
44033ec1ccbSHans Petter Selasky err = -ENOMEM;
44133ec1ccbSHans Petter Selasky goto err_unmap_mtt;
44233ec1ccbSHans Petter Selasky }
44333ec1ccbSHans Petter Selasky
44433ec1ccbSHans Petter Selasky mdev->qp_table.qp_table = mthca_alloc_icm_table(mdev, init_hca->qpc_base,
44533ec1ccbSHans Petter Selasky dev_lim->qpc_entry_sz,
44633ec1ccbSHans Petter Selasky mdev->limits.num_qps,
44733ec1ccbSHans Petter Selasky mdev->limits.reserved_qps,
44833ec1ccbSHans Petter Selasky 0, 0);
44933ec1ccbSHans Petter Selasky if (!mdev->qp_table.qp_table) {
45033ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map QP context memory, aborting.\n");
45133ec1ccbSHans Petter Selasky err = -ENOMEM;
45233ec1ccbSHans Petter Selasky goto err_unmap_mpt;
45333ec1ccbSHans Petter Selasky }
45433ec1ccbSHans Petter Selasky
45533ec1ccbSHans Petter Selasky mdev->qp_table.eqp_table = mthca_alloc_icm_table(mdev, init_hca->eqpc_base,
45633ec1ccbSHans Petter Selasky dev_lim->eqpc_entry_sz,
45733ec1ccbSHans Petter Selasky mdev->limits.num_qps,
45833ec1ccbSHans Petter Selasky mdev->limits.reserved_qps,
45933ec1ccbSHans Petter Selasky 0, 0);
46033ec1ccbSHans Petter Selasky if (!mdev->qp_table.eqp_table) {
46133ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map EQP context memory, aborting.\n");
46233ec1ccbSHans Petter Selasky err = -ENOMEM;
46333ec1ccbSHans Petter Selasky goto err_unmap_qp;
46433ec1ccbSHans Petter Selasky }
46533ec1ccbSHans Petter Selasky
46633ec1ccbSHans Petter Selasky mdev->qp_table.rdb_table = mthca_alloc_icm_table(mdev, init_hca->rdb_base,
46733ec1ccbSHans Petter Selasky MTHCA_RDB_ENTRY_SIZE,
46833ec1ccbSHans Petter Selasky mdev->limits.num_qps <<
46933ec1ccbSHans Petter Selasky mdev->qp_table.rdb_shift, 0,
47033ec1ccbSHans Petter Selasky 0, 0);
47133ec1ccbSHans Petter Selasky if (!mdev->qp_table.rdb_table) {
47233ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map RDB context memory, aborting\n");
47333ec1ccbSHans Petter Selasky err = -ENOMEM;
47433ec1ccbSHans Petter Selasky goto err_unmap_eqp;
47533ec1ccbSHans Petter Selasky }
47633ec1ccbSHans Petter Selasky
47733ec1ccbSHans Petter Selasky mdev->cq_table.table = mthca_alloc_icm_table(mdev, init_hca->cqc_base,
47833ec1ccbSHans Petter Selasky dev_lim->cqc_entry_sz,
47933ec1ccbSHans Petter Selasky mdev->limits.num_cqs,
48033ec1ccbSHans Petter Selasky mdev->limits.reserved_cqs,
48133ec1ccbSHans Petter Selasky 0, 0);
48233ec1ccbSHans Petter Selasky if (!mdev->cq_table.table) {
48333ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map CQ context memory, aborting.\n");
48433ec1ccbSHans Petter Selasky err = -ENOMEM;
48533ec1ccbSHans Petter Selasky goto err_unmap_rdb;
48633ec1ccbSHans Petter Selasky }
48733ec1ccbSHans Petter Selasky
48833ec1ccbSHans Petter Selasky if (mdev->mthca_flags & MTHCA_FLAG_SRQ) {
48933ec1ccbSHans Petter Selasky mdev->srq_table.table =
49033ec1ccbSHans Petter Selasky mthca_alloc_icm_table(mdev, init_hca->srqc_base,
49133ec1ccbSHans Petter Selasky dev_lim->srq_entry_sz,
49233ec1ccbSHans Petter Selasky mdev->limits.num_srqs,
49333ec1ccbSHans Petter Selasky mdev->limits.reserved_srqs,
49433ec1ccbSHans Petter Selasky 0, 0);
49533ec1ccbSHans Petter Selasky if (!mdev->srq_table.table) {
49633ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map SRQ context memory, "
49733ec1ccbSHans Petter Selasky "aborting.\n");
49833ec1ccbSHans Petter Selasky err = -ENOMEM;
49933ec1ccbSHans Petter Selasky goto err_unmap_cq;
50033ec1ccbSHans Petter Selasky }
50133ec1ccbSHans Petter Selasky }
50233ec1ccbSHans Petter Selasky
50333ec1ccbSHans Petter Selasky /*
50433ec1ccbSHans Petter Selasky * It's not strictly required, but for simplicity just map the
50533ec1ccbSHans Petter Selasky * whole multicast group table now. The table isn't very big
50633ec1ccbSHans Petter Selasky * and it's a lot easier than trying to track ref counts.
50733ec1ccbSHans Petter Selasky */
50833ec1ccbSHans Petter Selasky mdev->mcg_table.table = mthca_alloc_icm_table(mdev, init_hca->mc_base,
50933ec1ccbSHans Petter Selasky MTHCA_MGM_ENTRY_SIZE,
51033ec1ccbSHans Petter Selasky mdev->limits.num_mgms +
51133ec1ccbSHans Petter Selasky mdev->limits.num_amgms,
51233ec1ccbSHans Petter Selasky mdev->limits.num_mgms +
51333ec1ccbSHans Petter Selasky mdev->limits.num_amgms,
51433ec1ccbSHans Petter Selasky 0, 0);
51533ec1ccbSHans Petter Selasky if (!mdev->mcg_table.table) {
51633ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to map MCG context memory, aborting.\n");
51733ec1ccbSHans Petter Selasky err = -ENOMEM;
51833ec1ccbSHans Petter Selasky goto err_unmap_srq;
51933ec1ccbSHans Petter Selasky }
52033ec1ccbSHans Petter Selasky
52133ec1ccbSHans Petter Selasky return 0;
52233ec1ccbSHans Petter Selasky
52333ec1ccbSHans Petter Selasky err_unmap_srq:
52433ec1ccbSHans Petter Selasky if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
52533ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->srq_table.table);
52633ec1ccbSHans Petter Selasky
52733ec1ccbSHans Petter Selasky err_unmap_cq:
52833ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->cq_table.table);
52933ec1ccbSHans Petter Selasky
53033ec1ccbSHans Petter Selasky err_unmap_rdb:
53133ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);
53233ec1ccbSHans Petter Selasky
53333ec1ccbSHans Petter Selasky err_unmap_eqp:
53433ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);
53533ec1ccbSHans Petter Selasky
53633ec1ccbSHans Petter Selasky err_unmap_qp:
53733ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->qp_table.qp_table);
53833ec1ccbSHans Petter Selasky
53933ec1ccbSHans Petter Selasky err_unmap_mpt:
54033ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);
54133ec1ccbSHans Petter Selasky
54233ec1ccbSHans Petter Selasky err_unmap_mtt:
54333ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);
54433ec1ccbSHans Petter Selasky
54533ec1ccbSHans Petter Selasky err_unmap_eq:
54633ec1ccbSHans Petter Selasky mthca_unmap_eq_icm(mdev);
54733ec1ccbSHans Petter Selasky
54833ec1ccbSHans Petter Selasky err_unmap_aux:
54933ec1ccbSHans Petter Selasky mthca_UNMAP_ICM_AUX(mdev);
55033ec1ccbSHans Petter Selasky
55133ec1ccbSHans Petter Selasky err_free_aux:
55233ec1ccbSHans Petter Selasky mthca_free_icm(mdev, mdev->fw.arbel.aux_icm, 0);
55333ec1ccbSHans Petter Selasky
55433ec1ccbSHans Petter Selasky return err;
55533ec1ccbSHans Petter Selasky }
55633ec1ccbSHans Petter Selasky
mthca_free_icms(struct mthca_dev * mdev)55733ec1ccbSHans Petter Selasky static void mthca_free_icms(struct mthca_dev *mdev)
55833ec1ccbSHans Petter Selasky {
55933ec1ccbSHans Petter Selasky
56033ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->mcg_table.table);
56133ec1ccbSHans Petter Selasky if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
56233ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->srq_table.table);
56333ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->cq_table.table);
56433ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);
56533ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);
56633ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->qp_table.qp_table);
56733ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);
56833ec1ccbSHans Petter Selasky mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);
56933ec1ccbSHans Petter Selasky mthca_unmap_eq_icm(mdev);
57033ec1ccbSHans Petter Selasky
57133ec1ccbSHans Petter Selasky mthca_UNMAP_ICM_AUX(mdev);
57233ec1ccbSHans Petter Selasky mthca_free_icm(mdev, mdev->fw.arbel.aux_icm, 0);
57333ec1ccbSHans Petter Selasky }
57433ec1ccbSHans Petter Selasky
mthca_init_arbel(struct mthca_dev * mdev)57533ec1ccbSHans Petter Selasky static int mthca_init_arbel(struct mthca_dev *mdev)
57633ec1ccbSHans Petter Selasky {
57733ec1ccbSHans Petter Selasky struct mthca_dev_lim dev_lim;
57833ec1ccbSHans Petter Selasky struct mthca_profile profile;
57933ec1ccbSHans Petter Selasky struct mthca_init_hca_param init_hca;
58033ec1ccbSHans Petter Selasky s64 icm_size;
58133ec1ccbSHans Petter Selasky int err;
58233ec1ccbSHans Petter Selasky
58333ec1ccbSHans Petter Selasky err = mthca_QUERY_FW(mdev);
58433ec1ccbSHans Petter Selasky if (err) {
58533ec1ccbSHans Petter Selasky mthca_err(mdev, "QUERY_FW command failed %d, aborting.\n", err);
58633ec1ccbSHans Petter Selasky return err;
58733ec1ccbSHans Petter Selasky }
58833ec1ccbSHans Petter Selasky
58933ec1ccbSHans Petter Selasky err = mthca_ENABLE_LAM(mdev);
59033ec1ccbSHans Petter Selasky if (err == -EAGAIN) {
59133ec1ccbSHans Petter Selasky mthca_dbg(mdev, "No HCA-attached memory (running in MemFree mode)\n");
59233ec1ccbSHans Petter Selasky mdev->mthca_flags |= MTHCA_FLAG_NO_LAM;
59333ec1ccbSHans Petter Selasky } else if (err) {
59433ec1ccbSHans Petter Selasky mthca_err(mdev, "ENABLE_LAM returned %d, aborting.\n", err);
59533ec1ccbSHans Petter Selasky return err;
59633ec1ccbSHans Petter Selasky }
59733ec1ccbSHans Petter Selasky
59833ec1ccbSHans Petter Selasky err = mthca_load_fw(mdev);
59933ec1ccbSHans Petter Selasky if (err) {
60033ec1ccbSHans Petter Selasky mthca_err(mdev, "Loading FW returned %d, aborting.\n", err);
60133ec1ccbSHans Petter Selasky goto err_disable;
60233ec1ccbSHans Petter Selasky }
60333ec1ccbSHans Petter Selasky
60433ec1ccbSHans Petter Selasky err = mthca_dev_lim(mdev, &dev_lim);
60533ec1ccbSHans Petter Selasky if (err) {
60633ec1ccbSHans Petter Selasky mthca_err(mdev, "QUERY_DEV_LIM returned %d, aborting.\n", err);
60733ec1ccbSHans Petter Selasky goto err_stop_fw;
60833ec1ccbSHans Petter Selasky }
60933ec1ccbSHans Petter Selasky
61033ec1ccbSHans Petter Selasky profile = hca_profile;
61133ec1ccbSHans Petter Selasky profile.num_uar = dev_lim.uar_size / PAGE_SIZE;
61233ec1ccbSHans Petter Selasky profile.num_udav = 0;
61333ec1ccbSHans Petter Selasky if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
61433ec1ccbSHans Petter Selasky profile.num_srq = dev_lim.max_srqs;
61533ec1ccbSHans Petter Selasky
61633ec1ccbSHans Petter Selasky icm_size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
61733ec1ccbSHans Petter Selasky if (icm_size < 0) {
61833ec1ccbSHans Petter Selasky err = icm_size;
61933ec1ccbSHans Petter Selasky goto err_stop_fw;
62033ec1ccbSHans Petter Selasky }
62133ec1ccbSHans Petter Selasky
62233ec1ccbSHans Petter Selasky err = mthca_init_icm(mdev, &dev_lim, &init_hca, icm_size);
62333ec1ccbSHans Petter Selasky if (err)
62433ec1ccbSHans Petter Selasky goto err_stop_fw;
62533ec1ccbSHans Petter Selasky
62633ec1ccbSHans Petter Selasky err = mthca_INIT_HCA(mdev, &init_hca);
62733ec1ccbSHans Petter Selasky if (err) {
62833ec1ccbSHans Petter Selasky mthca_err(mdev, "INIT_HCA command returned %d, aborting.\n", err);
62933ec1ccbSHans Petter Selasky goto err_free_icm;
63033ec1ccbSHans Petter Selasky }
63133ec1ccbSHans Petter Selasky
63233ec1ccbSHans Petter Selasky return 0;
63333ec1ccbSHans Petter Selasky
63433ec1ccbSHans Petter Selasky err_free_icm:
63533ec1ccbSHans Petter Selasky mthca_free_icms(mdev);
63633ec1ccbSHans Petter Selasky
63733ec1ccbSHans Petter Selasky err_stop_fw:
63833ec1ccbSHans Petter Selasky mthca_UNMAP_FA(mdev);
63933ec1ccbSHans Petter Selasky mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
64033ec1ccbSHans Petter Selasky
64133ec1ccbSHans Petter Selasky err_disable:
64233ec1ccbSHans Petter Selasky if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))
64333ec1ccbSHans Petter Selasky mthca_DISABLE_LAM(mdev);
64433ec1ccbSHans Petter Selasky
64533ec1ccbSHans Petter Selasky return err;
64633ec1ccbSHans Petter Selasky }
64733ec1ccbSHans Petter Selasky
mthca_close_hca(struct mthca_dev * mdev)64833ec1ccbSHans Petter Selasky static void mthca_close_hca(struct mthca_dev *mdev)
64933ec1ccbSHans Petter Selasky {
65033ec1ccbSHans Petter Selasky mthca_CLOSE_HCA(mdev, 0);
65133ec1ccbSHans Petter Selasky
65233ec1ccbSHans Petter Selasky if (mthca_is_memfree(mdev)) {
65333ec1ccbSHans Petter Selasky mthca_free_icms(mdev);
65433ec1ccbSHans Petter Selasky
65533ec1ccbSHans Petter Selasky mthca_UNMAP_FA(mdev);
65633ec1ccbSHans Petter Selasky mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
65733ec1ccbSHans Petter Selasky
65833ec1ccbSHans Petter Selasky if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))
65933ec1ccbSHans Petter Selasky mthca_DISABLE_LAM(mdev);
66033ec1ccbSHans Petter Selasky } else
66133ec1ccbSHans Petter Selasky mthca_SYS_DIS(mdev);
66233ec1ccbSHans Petter Selasky }
66333ec1ccbSHans Petter Selasky
mthca_init_hca(struct mthca_dev * mdev)66433ec1ccbSHans Petter Selasky static int mthca_init_hca(struct mthca_dev *mdev)
66533ec1ccbSHans Petter Selasky {
66633ec1ccbSHans Petter Selasky int err;
66733ec1ccbSHans Petter Selasky struct mthca_adapter adapter;
66833ec1ccbSHans Petter Selasky
66933ec1ccbSHans Petter Selasky if (mthca_is_memfree(mdev))
67033ec1ccbSHans Petter Selasky err = mthca_init_arbel(mdev);
67133ec1ccbSHans Petter Selasky else
67233ec1ccbSHans Petter Selasky err = mthca_init_tavor(mdev);
67333ec1ccbSHans Petter Selasky
67433ec1ccbSHans Petter Selasky if (err)
67533ec1ccbSHans Petter Selasky return err;
67633ec1ccbSHans Petter Selasky
67733ec1ccbSHans Petter Selasky err = mthca_QUERY_ADAPTER(mdev, &adapter);
67833ec1ccbSHans Petter Selasky if (err) {
67933ec1ccbSHans Petter Selasky mthca_err(mdev, "QUERY_ADAPTER command returned %d, aborting.\n", err);
68033ec1ccbSHans Petter Selasky goto err_close;
68133ec1ccbSHans Petter Selasky }
68233ec1ccbSHans Petter Selasky
68333ec1ccbSHans Petter Selasky mdev->eq_table.inta_pin = adapter.inta_pin;
68433ec1ccbSHans Petter Selasky if (!mthca_is_memfree(mdev))
68533ec1ccbSHans Petter Selasky mdev->rev_id = adapter.revision_id;
68633ec1ccbSHans Petter Selasky memcpy(mdev->board_id, adapter.board_id, sizeof mdev->board_id);
68733ec1ccbSHans Petter Selasky
68833ec1ccbSHans Petter Selasky return 0;
68933ec1ccbSHans Petter Selasky
69033ec1ccbSHans Petter Selasky err_close:
69133ec1ccbSHans Petter Selasky mthca_close_hca(mdev);
69233ec1ccbSHans Petter Selasky return err;
69333ec1ccbSHans Petter Selasky }
69433ec1ccbSHans Petter Selasky
mthca_setup_hca(struct mthca_dev * dev)69533ec1ccbSHans Petter Selasky static int mthca_setup_hca(struct mthca_dev *dev)
69633ec1ccbSHans Petter Selasky {
69733ec1ccbSHans Petter Selasky int err;
69833ec1ccbSHans Petter Selasky
69933ec1ccbSHans Petter Selasky MTHCA_INIT_DOORBELL_LOCK(&dev->doorbell_lock);
70033ec1ccbSHans Petter Selasky
70133ec1ccbSHans Petter Selasky err = mthca_init_uar_table(dev);
70233ec1ccbSHans Petter Selasky if (err) {
70333ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
70433ec1ccbSHans Petter Selasky "user access region table, aborting.\n");
70533ec1ccbSHans Petter Selasky return err;
70633ec1ccbSHans Petter Selasky }
70733ec1ccbSHans Petter Selasky
70833ec1ccbSHans Petter Selasky err = mthca_uar_alloc(dev, &dev->driver_uar);
70933ec1ccbSHans Petter Selasky if (err) {
71033ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to allocate driver access region, "
71133ec1ccbSHans Petter Selasky "aborting.\n");
71233ec1ccbSHans Petter Selasky goto err_uar_table_free;
71333ec1ccbSHans Petter Selasky }
71433ec1ccbSHans Petter Selasky
71533ec1ccbSHans Petter Selasky dev->kar = ioremap((phys_addr_t) dev->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
71633ec1ccbSHans Petter Selasky if (!dev->kar) {
71733ec1ccbSHans Petter Selasky mthca_err(dev, "Couldn't map kernel access region, "
71833ec1ccbSHans Petter Selasky "aborting.\n");
71933ec1ccbSHans Petter Selasky err = -ENOMEM;
72033ec1ccbSHans Petter Selasky goto err_uar_free;
72133ec1ccbSHans Petter Selasky }
72233ec1ccbSHans Petter Selasky
72333ec1ccbSHans Petter Selasky err = mthca_init_pd_table(dev);
72433ec1ccbSHans Petter Selasky if (err) {
72533ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
72633ec1ccbSHans Petter Selasky "protection domain table, aborting.\n");
72733ec1ccbSHans Petter Selasky goto err_kar_unmap;
72833ec1ccbSHans Petter Selasky }
72933ec1ccbSHans Petter Selasky
73033ec1ccbSHans Petter Selasky err = mthca_init_mr_table(dev);
73133ec1ccbSHans Petter Selasky if (err) {
73233ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
73333ec1ccbSHans Petter Selasky "memory region table, aborting.\n");
73433ec1ccbSHans Petter Selasky goto err_pd_table_free;
73533ec1ccbSHans Petter Selasky }
73633ec1ccbSHans Petter Selasky
73733ec1ccbSHans Petter Selasky err = mthca_pd_alloc(dev, 1, &dev->driver_pd);
73833ec1ccbSHans Petter Selasky if (err) {
73933ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to create driver PD, "
74033ec1ccbSHans Petter Selasky "aborting.\n");
74133ec1ccbSHans Petter Selasky goto err_mr_table_free;
74233ec1ccbSHans Petter Selasky }
74333ec1ccbSHans Petter Selasky
74433ec1ccbSHans Petter Selasky err = mthca_init_eq_table(dev);
74533ec1ccbSHans Petter Selasky if (err) {
74633ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
74733ec1ccbSHans Petter Selasky "event queue table, aborting.\n");
74833ec1ccbSHans Petter Selasky goto err_pd_free;
74933ec1ccbSHans Petter Selasky }
75033ec1ccbSHans Petter Selasky
75133ec1ccbSHans Petter Selasky err = mthca_cmd_use_events(dev);
75233ec1ccbSHans Petter Selasky if (err) {
75333ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to switch to event-driven "
75433ec1ccbSHans Petter Selasky "firmware commands, aborting.\n");
75533ec1ccbSHans Petter Selasky goto err_eq_table_free;
75633ec1ccbSHans Petter Selasky }
75733ec1ccbSHans Petter Selasky
75833ec1ccbSHans Petter Selasky err = mthca_NOP(dev);
75933ec1ccbSHans Petter Selasky if (err) {
76033ec1ccbSHans Petter Selasky if (dev->mthca_flags & MTHCA_FLAG_MSI_X) {
76133ec1ccbSHans Petter Selasky mthca_warn(dev, "NOP command failed to generate interrupt "
76233ec1ccbSHans Petter Selasky "(IRQ %d).\n",
76333ec1ccbSHans Petter Selasky dev->eq_table.eq[MTHCA_EQ_CMD].msi_x_vector);
76433ec1ccbSHans Petter Selasky mthca_warn(dev, "Trying again with MSI-X disabled.\n");
76533ec1ccbSHans Petter Selasky } else {
76633ec1ccbSHans Petter Selasky mthca_err(dev, "NOP command failed to generate interrupt "
76733ec1ccbSHans Petter Selasky "(IRQ %d), aborting.\n",
76833ec1ccbSHans Petter Selasky dev->pdev->irq);
76933ec1ccbSHans Petter Selasky mthca_err(dev, "BIOS or ACPI interrupt routing problem?\n");
77033ec1ccbSHans Petter Selasky }
77133ec1ccbSHans Petter Selasky
77233ec1ccbSHans Petter Selasky goto err_cmd_poll;
77333ec1ccbSHans Petter Selasky }
77433ec1ccbSHans Petter Selasky
77533ec1ccbSHans Petter Selasky mthca_dbg(dev, "NOP command IRQ test passed\n");
77633ec1ccbSHans Petter Selasky
77733ec1ccbSHans Petter Selasky err = mthca_init_cq_table(dev);
77833ec1ccbSHans Petter Selasky if (err) {
77933ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
78033ec1ccbSHans Petter Selasky "completion queue table, aborting.\n");
78133ec1ccbSHans Petter Selasky goto err_cmd_poll;
78233ec1ccbSHans Petter Selasky }
78333ec1ccbSHans Petter Selasky
78433ec1ccbSHans Petter Selasky err = mthca_init_srq_table(dev);
78533ec1ccbSHans Petter Selasky if (err) {
78633ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
78733ec1ccbSHans Petter Selasky "shared receive queue table, aborting.\n");
78833ec1ccbSHans Petter Selasky goto err_cq_table_free;
78933ec1ccbSHans Petter Selasky }
79033ec1ccbSHans Petter Selasky
79133ec1ccbSHans Petter Selasky err = mthca_init_qp_table(dev);
79233ec1ccbSHans Petter Selasky if (err) {
79333ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
79433ec1ccbSHans Petter Selasky "queue pair table, aborting.\n");
79533ec1ccbSHans Petter Selasky goto err_srq_table_free;
79633ec1ccbSHans Petter Selasky }
79733ec1ccbSHans Petter Selasky
79833ec1ccbSHans Petter Selasky err = mthca_init_av_table(dev);
79933ec1ccbSHans Petter Selasky if (err) {
80033ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
80133ec1ccbSHans Petter Selasky "address vector table, aborting.\n");
80233ec1ccbSHans Petter Selasky goto err_qp_table_free;
80333ec1ccbSHans Petter Selasky }
80433ec1ccbSHans Petter Selasky
80533ec1ccbSHans Petter Selasky err = mthca_init_mcg_table(dev);
80633ec1ccbSHans Petter Selasky if (err) {
80733ec1ccbSHans Petter Selasky mthca_err(dev, "Failed to initialize "
80833ec1ccbSHans Petter Selasky "multicast group table, aborting.\n");
80933ec1ccbSHans Petter Selasky goto err_av_table_free;
81033ec1ccbSHans Petter Selasky }
81133ec1ccbSHans Petter Selasky
81233ec1ccbSHans Petter Selasky return 0;
81333ec1ccbSHans Petter Selasky
81433ec1ccbSHans Petter Selasky err_av_table_free:
81533ec1ccbSHans Petter Selasky mthca_cleanup_av_table(dev);
81633ec1ccbSHans Petter Selasky
81733ec1ccbSHans Petter Selasky err_qp_table_free:
81833ec1ccbSHans Petter Selasky mthca_cleanup_qp_table(dev);
81933ec1ccbSHans Petter Selasky
82033ec1ccbSHans Petter Selasky err_srq_table_free:
82133ec1ccbSHans Petter Selasky mthca_cleanup_srq_table(dev);
82233ec1ccbSHans Petter Selasky
82333ec1ccbSHans Petter Selasky err_cq_table_free:
82433ec1ccbSHans Petter Selasky mthca_cleanup_cq_table(dev);
82533ec1ccbSHans Petter Selasky
82633ec1ccbSHans Petter Selasky err_cmd_poll:
82733ec1ccbSHans Petter Selasky mthca_cmd_use_polling(dev);
82833ec1ccbSHans Petter Selasky
82933ec1ccbSHans Petter Selasky err_eq_table_free:
83033ec1ccbSHans Petter Selasky mthca_cleanup_eq_table(dev);
83133ec1ccbSHans Petter Selasky
83233ec1ccbSHans Petter Selasky err_pd_free:
83333ec1ccbSHans Petter Selasky mthca_pd_free(dev, &dev->driver_pd);
83433ec1ccbSHans Petter Selasky
83533ec1ccbSHans Petter Selasky err_mr_table_free:
83633ec1ccbSHans Petter Selasky mthca_cleanup_mr_table(dev);
83733ec1ccbSHans Petter Selasky
83833ec1ccbSHans Petter Selasky err_pd_table_free:
83933ec1ccbSHans Petter Selasky mthca_cleanup_pd_table(dev);
84033ec1ccbSHans Petter Selasky
84133ec1ccbSHans Petter Selasky err_kar_unmap:
84233ec1ccbSHans Petter Selasky iounmap(dev->kar);
84333ec1ccbSHans Petter Selasky
84433ec1ccbSHans Petter Selasky err_uar_free:
84533ec1ccbSHans Petter Selasky mthca_uar_free(dev, &dev->driver_uar);
84633ec1ccbSHans Petter Selasky
84733ec1ccbSHans Petter Selasky err_uar_table_free:
84833ec1ccbSHans Petter Selasky mthca_cleanup_uar_table(dev);
84933ec1ccbSHans Petter Selasky return err;
85033ec1ccbSHans Petter Selasky }
85133ec1ccbSHans Petter Selasky
mthca_enable_msi_x(struct mthca_dev * mdev)85233ec1ccbSHans Petter Selasky static int mthca_enable_msi_x(struct mthca_dev *mdev)
85333ec1ccbSHans Petter Selasky {
85433ec1ccbSHans Petter Selasky struct msix_entry entries[3];
85533ec1ccbSHans Petter Selasky int err;
85633ec1ccbSHans Petter Selasky
85733ec1ccbSHans Petter Selasky entries[0].entry = 0;
85833ec1ccbSHans Petter Selasky entries[1].entry = 1;
85933ec1ccbSHans Petter Selasky entries[2].entry = 2;
86033ec1ccbSHans Petter Selasky
86133ec1ccbSHans Petter Selasky err = pci_enable_msix_range(mdev->pdev, entries, ARRAY_SIZE(entries), ARRAY_SIZE(entries));
86233ec1ccbSHans Petter Selasky if (err < 0)
86333ec1ccbSHans Petter Selasky return err;
86433ec1ccbSHans Petter Selasky
86533ec1ccbSHans Petter Selasky mdev->eq_table.eq[MTHCA_EQ_COMP ].msi_x_vector = entries[0].vector;
86633ec1ccbSHans Petter Selasky mdev->eq_table.eq[MTHCA_EQ_ASYNC].msi_x_vector = entries[1].vector;
86733ec1ccbSHans Petter Selasky mdev->eq_table.eq[MTHCA_EQ_CMD ].msi_x_vector = entries[2].vector;
86833ec1ccbSHans Petter Selasky
86933ec1ccbSHans Petter Selasky return 0;
87033ec1ccbSHans Petter Selasky }
87133ec1ccbSHans Petter Selasky
87233ec1ccbSHans Petter Selasky /* Types of supported HCA */
87333ec1ccbSHans Petter Selasky enum {
87433ec1ccbSHans Petter Selasky TAVOR, /* MT23108 */
87533ec1ccbSHans Petter Selasky ARBEL_COMPAT, /* MT25208 in Tavor compat mode */
87633ec1ccbSHans Petter Selasky ARBEL_NATIVE, /* MT25208 with extended features */
87733ec1ccbSHans Petter Selasky SINAI /* MT25204 */
87833ec1ccbSHans Petter Selasky };
87933ec1ccbSHans Petter Selasky
88033ec1ccbSHans Petter Selasky #define MTHCA_FW_VER(major, minor, subminor) \
88133ec1ccbSHans Petter Selasky (((u64) (major) << 32) | ((u64) (minor) << 16) | (u64) (subminor))
88233ec1ccbSHans Petter Selasky
88333ec1ccbSHans Petter Selasky static struct {
88433ec1ccbSHans Petter Selasky u64 latest_fw;
88533ec1ccbSHans Petter Selasky u32 flags;
88633ec1ccbSHans Petter Selasky } mthca_hca_table[] = {
88733ec1ccbSHans Petter Selasky [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 5, 0),
88833ec1ccbSHans Petter Selasky .flags = 0 },
88933ec1ccbSHans Petter Selasky [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 8, 200),
89033ec1ccbSHans Petter Selasky .flags = MTHCA_FLAG_PCIE },
89133ec1ccbSHans Petter Selasky [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 3, 0),
89233ec1ccbSHans Petter Selasky .flags = MTHCA_FLAG_MEMFREE |
89333ec1ccbSHans Petter Selasky MTHCA_FLAG_PCIE },
89433ec1ccbSHans Petter Selasky [SINAI] = { .latest_fw = MTHCA_FW_VER(1, 2, 0),
89533ec1ccbSHans Petter Selasky .flags = MTHCA_FLAG_MEMFREE |
89633ec1ccbSHans Petter Selasky MTHCA_FLAG_PCIE |
89733ec1ccbSHans Petter Selasky MTHCA_FLAG_SINAI_OPT }
89833ec1ccbSHans Petter Selasky };
89933ec1ccbSHans Petter Selasky
__mthca_init_one(struct pci_dev * pdev,int hca_type)90033ec1ccbSHans Petter Selasky static int __mthca_init_one(struct pci_dev *pdev, int hca_type)
90133ec1ccbSHans Petter Selasky {
90233ec1ccbSHans Petter Selasky int ddr_hidden = 0;
90333ec1ccbSHans Petter Selasky int err;
90433ec1ccbSHans Petter Selasky struct mthca_dev *mdev;
90533ec1ccbSHans Petter Selasky
90633ec1ccbSHans Petter Selasky printk(KERN_INFO PFX "Initializing %s\n",
90733ec1ccbSHans Petter Selasky pci_name(pdev));
90833ec1ccbSHans Petter Selasky
90933ec1ccbSHans Petter Selasky err = pci_enable_device(pdev);
91033ec1ccbSHans Petter Selasky if (err) {
91133ec1ccbSHans Petter Selasky dev_err(&pdev->dev, "Cannot enable PCI device, "
91233ec1ccbSHans Petter Selasky "aborting.\n");
91333ec1ccbSHans Petter Selasky return err;
91433ec1ccbSHans Petter Selasky }
91533ec1ccbSHans Petter Selasky
91633ec1ccbSHans Petter Selasky /*
91733ec1ccbSHans Petter Selasky * Check for BARs. We expect 0: 1MB, 2: 8MB, 4: DDR (may not
91833ec1ccbSHans Petter Selasky * be present)
91933ec1ccbSHans Petter Selasky */
92033ec1ccbSHans Petter Selasky if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
92133ec1ccbSHans Petter Selasky pci_resource_len(pdev, 0) != 1 << 20) {
92233ec1ccbSHans Petter Selasky dev_err(&pdev->dev, "Missing DCS, aborting.\n");
92333ec1ccbSHans Petter Selasky err = -ENODEV;
92433ec1ccbSHans Petter Selasky goto err_disable_pdev;
92533ec1ccbSHans Petter Selasky }
92633ec1ccbSHans Petter Selasky if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
92733ec1ccbSHans Petter Selasky dev_err(&pdev->dev, "Missing UAR, aborting.\n");
92833ec1ccbSHans Petter Selasky err = -ENODEV;
92933ec1ccbSHans Petter Selasky goto err_disable_pdev;
93033ec1ccbSHans Petter Selasky }
93133ec1ccbSHans Petter Selasky if (!(pci_resource_flags(pdev, 4) & IORESOURCE_MEM))
93233ec1ccbSHans Petter Selasky ddr_hidden = 1;
93333ec1ccbSHans Petter Selasky
93433ec1ccbSHans Petter Selasky err = pci_request_regions(pdev, DRV_NAME);
93533ec1ccbSHans Petter Selasky if (err) {
93633ec1ccbSHans Petter Selasky dev_err(&pdev->dev, "Cannot obtain PCI resources, "
93733ec1ccbSHans Petter Selasky "aborting.\n");
93833ec1ccbSHans Petter Selasky goto err_disable_pdev;
93933ec1ccbSHans Petter Selasky }
94033ec1ccbSHans Petter Selasky
94133ec1ccbSHans Petter Selasky pci_set_master(pdev);
94233ec1ccbSHans Petter Selasky
94333ec1ccbSHans Petter Selasky err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
94433ec1ccbSHans Petter Selasky if (err) {
94533ec1ccbSHans Petter Selasky dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
94633ec1ccbSHans Petter Selasky err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
94733ec1ccbSHans Petter Selasky if (err) {
94833ec1ccbSHans Petter Selasky dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
94933ec1ccbSHans Petter Selasky goto err_free_res;
95033ec1ccbSHans Petter Selasky }
95133ec1ccbSHans Petter Selasky }
95233ec1ccbSHans Petter Selasky err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
95333ec1ccbSHans Petter Selasky if (err) {
95433ec1ccbSHans Petter Selasky dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
95533ec1ccbSHans Petter Selasky "consistent PCI DMA mask.\n");
95633ec1ccbSHans Petter Selasky err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
95733ec1ccbSHans Petter Selasky if (err) {
95833ec1ccbSHans Petter Selasky dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
95933ec1ccbSHans Petter Selasky "aborting.\n");
96033ec1ccbSHans Petter Selasky goto err_free_res;
96133ec1ccbSHans Petter Selasky }
96233ec1ccbSHans Petter Selasky }
96333ec1ccbSHans Petter Selasky
96433ec1ccbSHans Petter Selasky /* We can handle large RDMA requests, so allow larger segments. */
96533ec1ccbSHans Petter Selasky dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024);
96633ec1ccbSHans Petter Selasky
96733ec1ccbSHans Petter Selasky mdev = (struct mthca_dev *) ib_alloc_device(sizeof *mdev);
96833ec1ccbSHans Petter Selasky if (!mdev) {
96933ec1ccbSHans Petter Selasky dev_err(&pdev->dev, "Device struct alloc failed, "
97033ec1ccbSHans Petter Selasky "aborting.\n");
97133ec1ccbSHans Petter Selasky err = -ENOMEM;
97233ec1ccbSHans Petter Selasky goto err_free_res;
97333ec1ccbSHans Petter Selasky }
97433ec1ccbSHans Petter Selasky
97533ec1ccbSHans Petter Selasky mdev->pdev = pdev;
97633ec1ccbSHans Petter Selasky
97733ec1ccbSHans Petter Selasky mdev->mthca_flags = mthca_hca_table[hca_type].flags;
97833ec1ccbSHans Petter Selasky if (ddr_hidden)
97933ec1ccbSHans Petter Selasky mdev->mthca_flags |= MTHCA_FLAG_DDR_HIDDEN;
98033ec1ccbSHans Petter Selasky
98133ec1ccbSHans Petter Selasky /*
98233ec1ccbSHans Petter Selasky * Now reset the HCA before we touch the PCI capabilities or
98333ec1ccbSHans Petter Selasky * attempt a firmware command, since a boot ROM may have left
98433ec1ccbSHans Petter Selasky * the HCA in an undefined state.
98533ec1ccbSHans Petter Selasky */
98633ec1ccbSHans Petter Selasky err = mthca_reset(mdev);
98733ec1ccbSHans Petter Selasky if (err) {
98833ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to reset HCA, aborting.\n");
98933ec1ccbSHans Petter Selasky goto err_free_dev;
99033ec1ccbSHans Petter Selasky }
99133ec1ccbSHans Petter Selasky
99233ec1ccbSHans Petter Selasky if (mthca_cmd_init(mdev)) {
99333ec1ccbSHans Petter Selasky mthca_err(mdev, "Failed to init command interface, aborting.\n");
99433ec1ccbSHans Petter Selasky goto err_free_dev;
99533ec1ccbSHans Petter Selasky }
99633ec1ccbSHans Petter Selasky
99733ec1ccbSHans Petter Selasky err = mthca_tune_pci(mdev);
99833ec1ccbSHans Petter Selasky if (err)
99933ec1ccbSHans Petter Selasky goto err_cmd;
100033ec1ccbSHans Petter Selasky
100133ec1ccbSHans Petter Selasky err = mthca_init_hca(mdev);
100233ec1ccbSHans Petter Selasky if (err)
100333ec1ccbSHans Petter Selasky goto err_cmd;
100433ec1ccbSHans Petter Selasky
100533ec1ccbSHans Petter Selasky if (mdev->fw_ver < mthca_hca_table[hca_type].latest_fw) {
100633ec1ccbSHans Petter Selasky mthca_warn(mdev, "HCA FW version %d.%d.%03d is old (%d.%d.%03d is current).\n",
100733ec1ccbSHans Petter Selasky (int) (mdev->fw_ver >> 32), (int) (mdev->fw_ver >> 16) & 0xffff,
100833ec1ccbSHans Petter Selasky (int) (mdev->fw_ver & 0xffff),
100933ec1ccbSHans Petter Selasky (int) (mthca_hca_table[hca_type].latest_fw >> 32),
101033ec1ccbSHans Petter Selasky (int) (mthca_hca_table[hca_type].latest_fw >> 16) & 0xffff,
101133ec1ccbSHans Petter Selasky (int) (mthca_hca_table[hca_type].latest_fw & 0xffff));
101233ec1ccbSHans Petter Selasky mthca_warn(mdev, "If you have problems, try updating your HCA FW.\n");
101333ec1ccbSHans Petter Selasky }
101433ec1ccbSHans Petter Selasky
101533ec1ccbSHans Petter Selasky if (msi_x && !mthca_enable_msi_x(mdev))
101633ec1ccbSHans Petter Selasky mdev->mthca_flags |= MTHCA_FLAG_MSI_X;
101733ec1ccbSHans Petter Selasky
101833ec1ccbSHans Petter Selasky err = mthca_setup_hca(mdev);
101933ec1ccbSHans Petter Selasky if (err == -EBUSY && (mdev->mthca_flags & MTHCA_FLAG_MSI_X)) {
102033ec1ccbSHans Petter Selasky if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
102133ec1ccbSHans Petter Selasky pci_disable_msix(pdev);
102233ec1ccbSHans Petter Selasky mdev->mthca_flags &= ~MTHCA_FLAG_MSI_X;
102333ec1ccbSHans Petter Selasky
102433ec1ccbSHans Petter Selasky err = mthca_setup_hca(mdev);
102533ec1ccbSHans Petter Selasky }
102633ec1ccbSHans Petter Selasky
102733ec1ccbSHans Petter Selasky if (err)
102833ec1ccbSHans Petter Selasky goto err_close;
102933ec1ccbSHans Petter Selasky
103033ec1ccbSHans Petter Selasky err = mthca_register_device(mdev);
103133ec1ccbSHans Petter Selasky if (err)
103233ec1ccbSHans Petter Selasky goto err_cleanup;
103333ec1ccbSHans Petter Selasky
103433ec1ccbSHans Petter Selasky err = mthca_create_agents(mdev);
103533ec1ccbSHans Petter Selasky if (err)
103633ec1ccbSHans Petter Selasky goto err_unregister;
103733ec1ccbSHans Petter Selasky
103833ec1ccbSHans Petter Selasky pci_set_drvdata(pdev, mdev);
103933ec1ccbSHans Petter Selasky mdev->hca_type = hca_type;
104033ec1ccbSHans Petter Selasky
104133ec1ccbSHans Petter Selasky mdev->active = true;
104233ec1ccbSHans Petter Selasky
104333ec1ccbSHans Petter Selasky return 0;
104433ec1ccbSHans Petter Selasky
104533ec1ccbSHans Petter Selasky err_unregister:
104633ec1ccbSHans Petter Selasky mthca_unregister_device(mdev);
104733ec1ccbSHans Petter Selasky
104833ec1ccbSHans Petter Selasky err_cleanup:
104933ec1ccbSHans Petter Selasky mthca_cleanup_mcg_table(mdev);
105033ec1ccbSHans Petter Selasky mthca_cleanup_av_table(mdev);
105133ec1ccbSHans Petter Selasky mthca_cleanup_qp_table(mdev);
105233ec1ccbSHans Petter Selasky mthca_cleanup_srq_table(mdev);
105333ec1ccbSHans Petter Selasky mthca_cleanup_cq_table(mdev);
105433ec1ccbSHans Petter Selasky mthca_cmd_use_polling(mdev);
105533ec1ccbSHans Petter Selasky mthca_cleanup_eq_table(mdev);
105633ec1ccbSHans Petter Selasky
105733ec1ccbSHans Petter Selasky mthca_pd_free(mdev, &mdev->driver_pd);
105833ec1ccbSHans Petter Selasky
105933ec1ccbSHans Petter Selasky mthca_cleanup_mr_table(mdev);
106033ec1ccbSHans Petter Selasky mthca_cleanup_pd_table(mdev);
106133ec1ccbSHans Petter Selasky mthca_cleanup_uar_table(mdev);
106233ec1ccbSHans Petter Selasky
106333ec1ccbSHans Petter Selasky err_close:
106433ec1ccbSHans Petter Selasky if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
106533ec1ccbSHans Petter Selasky pci_disable_msix(pdev);
106633ec1ccbSHans Petter Selasky
106733ec1ccbSHans Petter Selasky mthca_close_hca(mdev);
106833ec1ccbSHans Petter Selasky
106933ec1ccbSHans Petter Selasky err_cmd:
107033ec1ccbSHans Petter Selasky mthca_cmd_cleanup(mdev);
107133ec1ccbSHans Petter Selasky
107233ec1ccbSHans Petter Selasky err_free_dev:
107333ec1ccbSHans Petter Selasky ib_dealloc_device(&mdev->ib_dev);
107433ec1ccbSHans Petter Selasky
107533ec1ccbSHans Petter Selasky err_free_res:
107633ec1ccbSHans Petter Selasky pci_release_regions(pdev);
107733ec1ccbSHans Petter Selasky
107833ec1ccbSHans Petter Selasky err_disable_pdev:
107933ec1ccbSHans Petter Selasky pci_disable_device(pdev);
108033ec1ccbSHans Petter Selasky pci_set_drvdata(pdev, NULL);
108133ec1ccbSHans Petter Selasky return err;
108233ec1ccbSHans Petter Selasky }
108333ec1ccbSHans Petter Selasky
__mthca_remove_one(struct pci_dev * pdev)108433ec1ccbSHans Petter Selasky static void __mthca_remove_one(struct pci_dev *pdev)
108533ec1ccbSHans Petter Selasky {
108633ec1ccbSHans Petter Selasky struct mthca_dev *mdev = pci_get_drvdata(pdev);
108733ec1ccbSHans Petter Selasky int p;
108833ec1ccbSHans Petter Selasky
108933ec1ccbSHans Petter Selasky if (mdev) {
109033ec1ccbSHans Petter Selasky mthca_free_agents(mdev);
109133ec1ccbSHans Petter Selasky mthca_unregister_device(mdev);
109233ec1ccbSHans Petter Selasky
109333ec1ccbSHans Petter Selasky for (p = 1; p <= mdev->limits.num_ports; ++p)
109433ec1ccbSHans Petter Selasky mthca_CLOSE_IB(mdev, p);
109533ec1ccbSHans Petter Selasky
109633ec1ccbSHans Petter Selasky mthca_cleanup_mcg_table(mdev);
109733ec1ccbSHans Petter Selasky mthca_cleanup_av_table(mdev);
109833ec1ccbSHans Petter Selasky mthca_cleanup_qp_table(mdev);
109933ec1ccbSHans Petter Selasky mthca_cleanup_srq_table(mdev);
110033ec1ccbSHans Petter Selasky mthca_cleanup_cq_table(mdev);
110133ec1ccbSHans Petter Selasky mthca_cmd_use_polling(mdev);
110233ec1ccbSHans Petter Selasky mthca_cleanup_eq_table(mdev);
110333ec1ccbSHans Petter Selasky
110433ec1ccbSHans Petter Selasky mthca_pd_free(mdev, &mdev->driver_pd);
110533ec1ccbSHans Petter Selasky
110633ec1ccbSHans Petter Selasky mthca_cleanup_mr_table(mdev);
110733ec1ccbSHans Petter Selasky mthca_cleanup_pd_table(mdev);
110833ec1ccbSHans Petter Selasky
110933ec1ccbSHans Petter Selasky iounmap(mdev->kar);
111033ec1ccbSHans Petter Selasky mthca_uar_free(mdev, &mdev->driver_uar);
111133ec1ccbSHans Petter Selasky mthca_cleanup_uar_table(mdev);
111233ec1ccbSHans Petter Selasky mthca_close_hca(mdev);
111333ec1ccbSHans Petter Selasky mthca_cmd_cleanup(mdev);
111433ec1ccbSHans Petter Selasky
111533ec1ccbSHans Petter Selasky if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
111633ec1ccbSHans Petter Selasky pci_disable_msix(pdev);
111733ec1ccbSHans Petter Selasky
111833ec1ccbSHans Petter Selasky ib_dealloc_device(&mdev->ib_dev);
111933ec1ccbSHans Petter Selasky pci_release_regions(pdev);
112033ec1ccbSHans Petter Selasky pci_disable_device(pdev);
112133ec1ccbSHans Petter Selasky pci_set_drvdata(pdev, NULL);
112233ec1ccbSHans Petter Selasky }
112333ec1ccbSHans Petter Selasky }
112433ec1ccbSHans Petter Selasky
__mthca_restart_one(struct pci_dev * pdev)112533ec1ccbSHans Petter Selasky int __mthca_restart_one(struct pci_dev *pdev)
112633ec1ccbSHans Petter Selasky {
112733ec1ccbSHans Petter Selasky struct mthca_dev *mdev;
112833ec1ccbSHans Petter Selasky int hca_type;
112933ec1ccbSHans Petter Selasky
113033ec1ccbSHans Petter Selasky mdev = pci_get_drvdata(pdev);
113133ec1ccbSHans Petter Selasky if (!mdev)
113233ec1ccbSHans Petter Selasky return -ENODEV;
113333ec1ccbSHans Petter Selasky hca_type = mdev->hca_type;
113433ec1ccbSHans Petter Selasky __mthca_remove_one(pdev);
113533ec1ccbSHans Petter Selasky return __mthca_init_one(pdev, hca_type);
113633ec1ccbSHans Petter Selasky }
113733ec1ccbSHans Petter Selasky
mthca_init_one(struct pci_dev * pdev,const struct pci_device_id * id)113833ec1ccbSHans Petter Selasky static int mthca_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
113933ec1ccbSHans Petter Selasky {
114033ec1ccbSHans Petter Selasky int ret;
114133ec1ccbSHans Petter Selasky
114233ec1ccbSHans Petter Selasky mutex_lock(&mthca_device_mutex);
114333ec1ccbSHans Petter Selasky
114433ec1ccbSHans Petter Selasky printk_once(KERN_INFO "%s", mthca_version);
114533ec1ccbSHans Petter Selasky
114633ec1ccbSHans Petter Selasky if (id->driver_data >= ARRAY_SIZE(mthca_hca_table)) {
114733ec1ccbSHans Petter Selasky printk(KERN_ERR PFX "%s has invalid driver data %lx\n",
114833ec1ccbSHans Petter Selasky pci_name(pdev), (long)id->driver_data);
114933ec1ccbSHans Petter Selasky mutex_unlock(&mthca_device_mutex);
115033ec1ccbSHans Petter Selasky return -ENODEV;
115133ec1ccbSHans Petter Selasky }
115233ec1ccbSHans Petter Selasky
115333ec1ccbSHans Petter Selasky ret = __mthca_init_one(pdev, id->driver_data);
115433ec1ccbSHans Petter Selasky
115533ec1ccbSHans Petter Selasky mutex_unlock(&mthca_device_mutex);
115633ec1ccbSHans Petter Selasky
115733ec1ccbSHans Petter Selasky return ret;
115833ec1ccbSHans Petter Selasky }
115933ec1ccbSHans Petter Selasky
mthca_remove_one(struct pci_dev * pdev)116033ec1ccbSHans Petter Selasky static void mthca_remove_one(struct pci_dev *pdev)
116133ec1ccbSHans Petter Selasky {
116233ec1ccbSHans Petter Selasky mutex_lock(&mthca_device_mutex);
116333ec1ccbSHans Petter Selasky __mthca_remove_one(pdev);
116433ec1ccbSHans Petter Selasky mutex_unlock(&mthca_device_mutex);
116533ec1ccbSHans Petter Selasky }
116633ec1ccbSHans Petter Selasky
116733ec1ccbSHans Petter Selasky static struct pci_device_id mthca_pci_table[] = {
116833ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_TAVOR),
116933ec1ccbSHans Petter Selasky .driver_data = TAVOR },
117033ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_TAVOR),
117133ec1ccbSHans Petter Selasky .driver_data = TAVOR },
117233ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT),
117333ec1ccbSHans Petter Selasky .driver_data = ARBEL_COMPAT },
117433ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT),
117533ec1ccbSHans Petter Selasky .driver_data = ARBEL_COMPAT },
117633ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_ARBEL),
117733ec1ccbSHans Petter Selasky .driver_data = ARBEL_NATIVE },
117833ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_ARBEL),
117933ec1ccbSHans Petter Selasky .driver_data = ARBEL_NATIVE },
118033ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_SINAI),
118133ec1ccbSHans Petter Selasky .driver_data = SINAI },
118233ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_SINAI),
118333ec1ccbSHans Petter Selasky .driver_data = SINAI },
118433ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_SINAI_OLD),
118533ec1ccbSHans Petter Selasky .driver_data = SINAI },
118633ec1ccbSHans Petter Selasky { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_SINAI_OLD),
118733ec1ccbSHans Petter Selasky .driver_data = SINAI },
118833ec1ccbSHans Petter Selasky { 0, }
118933ec1ccbSHans Petter Selasky };
119033ec1ccbSHans Petter Selasky
119133ec1ccbSHans Petter Selasky MODULE_DEVICE_TABLE(pci, mthca_pci_table);
119233ec1ccbSHans Petter Selasky
119333ec1ccbSHans Petter Selasky static struct pci_driver mthca_driver = {
119433ec1ccbSHans Petter Selasky .name = DRV_NAME,
119533ec1ccbSHans Petter Selasky .id_table = mthca_pci_table,
119633ec1ccbSHans Petter Selasky .probe = mthca_init_one,
119733ec1ccbSHans Petter Selasky .remove = mthca_remove_one,
119833ec1ccbSHans Petter Selasky };
119933ec1ccbSHans Petter Selasky
__mthca_check_profile_val(const char * name,int * pval,int pval_default)120033ec1ccbSHans Petter Selasky static void __init __mthca_check_profile_val(const char *name, int *pval,
120133ec1ccbSHans Petter Selasky int pval_default)
120233ec1ccbSHans Petter Selasky {
120333ec1ccbSHans Petter Selasky /* value must be positive and power of 2 */
120433ec1ccbSHans Petter Selasky int old_pval = *pval;
120533ec1ccbSHans Petter Selasky
120633ec1ccbSHans Petter Selasky if (old_pval <= 0)
120733ec1ccbSHans Petter Selasky *pval = pval_default;
120833ec1ccbSHans Petter Selasky else
120933ec1ccbSHans Petter Selasky *pval = roundup_pow_of_two(old_pval);
121033ec1ccbSHans Petter Selasky
121133ec1ccbSHans Petter Selasky if (old_pval != *pval) {
121233ec1ccbSHans Petter Selasky printk(KERN_WARNING PFX "Invalid value %d for %s in module parameter.\n",
121333ec1ccbSHans Petter Selasky old_pval, name);
121433ec1ccbSHans Petter Selasky printk(KERN_WARNING PFX "Corrected %s to %d.\n", name, *pval);
121533ec1ccbSHans Petter Selasky }
121633ec1ccbSHans Petter Selasky }
121733ec1ccbSHans Petter Selasky
121833ec1ccbSHans Petter Selasky #define mthca_check_profile_val(name, default) \
121933ec1ccbSHans Petter Selasky __mthca_check_profile_val(#name, &hca_profile.name, default)
122033ec1ccbSHans Petter Selasky
mthca_validate_profile(void)122133ec1ccbSHans Petter Selasky static void __init mthca_validate_profile(void)
122233ec1ccbSHans Petter Selasky {
122333ec1ccbSHans Petter Selasky mthca_check_profile_val(num_qp, MTHCA_DEFAULT_NUM_QP);
122433ec1ccbSHans Petter Selasky mthca_check_profile_val(rdb_per_qp, MTHCA_DEFAULT_RDB_PER_QP);
122533ec1ccbSHans Petter Selasky mthca_check_profile_val(num_cq, MTHCA_DEFAULT_NUM_CQ);
122633ec1ccbSHans Petter Selasky mthca_check_profile_val(num_mcg, MTHCA_DEFAULT_NUM_MCG);
122733ec1ccbSHans Petter Selasky mthca_check_profile_val(num_mpt, MTHCA_DEFAULT_NUM_MPT);
122833ec1ccbSHans Petter Selasky mthca_check_profile_val(num_mtt, MTHCA_DEFAULT_NUM_MTT);
122933ec1ccbSHans Petter Selasky mthca_check_profile_val(num_udav, MTHCA_DEFAULT_NUM_UDAV);
123033ec1ccbSHans Petter Selasky mthca_check_profile_val(fmr_reserved_mtts, MTHCA_DEFAULT_NUM_RESERVED_MTTS);
123133ec1ccbSHans Petter Selasky
123233ec1ccbSHans Petter Selasky if (hca_profile.fmr_reserved_mtts >= hca_profile.num_mtt) {
123333ec1ccbSHans Petter Selasky printk(KERN_WARNING PFX "Invalid fmr_reserved_mtts module parameter %d.\n",
123433ec1ccbSHans Petter Selasky hca_profile.fmr_reserved_mtts);
123533ec1ccbSHans Petter Selasky printk(KERN_WARNING PFX "(Must be smaller than num_mtt %d)\n",
123633ec1ccbSHans Petter Selasky hca_profile.num_mtt);
123733ec1ccbSHans Petter Selasky hca_profile.fmr_reserved_mtts = hca_profile.num_mtt / 2;
123833ec1ccbSHans Petter Selasky printk(KERN_WARNING PFX "Corrected fmr_reserved_mtts to %d.\n",
123933ec1ccbSHans Petter Selasky hca_profile.fmr_reserved_mtts);
124033ec1ccbSHans Petter Selasky }
124133ec1ccbSHans Petter Selasky
124233ec1ccbSHans Petter Selasky if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 5)) {
124333ec1ccbSHans Petter Selasky printk(KERN_WARNING PFX "bad log_mtts_per_seg (%d). Using default - %d\n",
124433ec1ccbSHans Petter Selasky log_mtts_per_seg, ilog2(MTHCA_MTT_SEG_SIZE / 8));
124533ec1ccbSHans Petter Selasky log_mtts_per_seg = ilog2(MTHCA_MTT_SEG_SIZE / 8);
124633ec1ccbSHans Petter Selasky }
124733ec1ccbSHans Petter Selasky }
124833ec1ccbSHans Petter Selasky
mthca_init(void)124933ec1ccbSHans Petter Selasky static int __init mthca_init(void)
125033ec1ccbSHans Petter Selasky {
125133ec1ccbSHans Petter Selasky int ret;
125233ec1ccbSHans Petter Selasky
125333ec1ccbSHans Petter Selasky mthca_validate_profile();
125433ec1ccbSHans Petter Selasky
125533ec1ccbSHans Petter Selasky ret = mthca_catas_init();
125633ec1ccbSHans Petter Selasky if (ret)
125733ec1ccbSHans Petter Selasky return ret;
125833ec1ccbSHans Petter Selasky
125933ec1ccbSHans Petter Selasky ret = pci_register_driver(&mthca_driver);
126033ec1ccbSHans Petter Selasky if (ret < 0) {
126133ec1ccbSHans Petter Selasky mthca_catas_cleanup();
126233ec1ccbSHans Petter Selasky return ret;
126333ec1ccbSHans Petter Selasky }
126433ec1ccbSHans Petter Selasky
126533ec1ccbSHans Petter Selasky return 0;
126633ec1ccbSHans Petter Selasky }
126733ec1ccbSHans Petter Selasky
mthca_cleanup(void)126833ec1ccbSHans Petter Selasky static void __exit mthca_cleanup(void)
126933ec1ccbSHans Petter Selasky {
127033ec1ccbSHans Petter Selasky pci_unregister_driver(&mthca_driver);
127133ec1ccbSHans Petter Selasky mthca_catas_cleanup();
127233ec1ccbSHans Petter Selasky }
127333ec1ccbSHans Petter Selasky
1274*1866c98eSHans Petter Selasky module_init_order(mthca_init, SI_ORDER_SEVENTH);
1275*1866c98eSHans Petter Selasky module_exit_order(mthca_cleanup, SI_ORDER_SEVENTH);
127633ec1ccbSHans Petter Selasky
127733ec1ccbSHans Petter Selasky MODULE_VERSION(mthca, 1);
127833ec1ccbSHans Petter Selasky MODULE_DEPEND(mthca, ibcore, 1, 1, 1);
127933ec1ccbSHans Petter Selasky MODULE_DEPEND(mthca, linuxkpi, 1, 1, 1);
1280