xref: /linux/drivers/infiniband/hw/mthca/mthca_main.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
3cd4e8fb4STom Duffy  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
42a1d9b7fSRoland Dreier  * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * This software is available to you under a choice of one of two
71da177e4SLinus Torvalds  * licenses.  You may choose to be licensed under the terms of the GNU
81da177e4SLinus Torvalds  * General Public License (GPL) Version 2, available from the file
91da177e4SLinus Torvalds  * COPYING in the main directory of this source tree, or the
101da177e4SLinus Torvalds  * OpenIB.org BSD license below:
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *     Redistribution and use in source and binary forms, with or
131da177e4SLinus Torvalds  *     without modification, are permitted provided that the following
141da177e4SLinus Torvalds  *     conditions are met:
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  *      - Redistributions of source code must retain the above
171da177e4SLinus Torvalds  *        copyright notice, this list of conditions and the following
181da177e4SLinus Torvalds  *        disclaimer.
191da177e4SLinus Torvalds  *
201da177e4SLinus Torvalds  *      - Redistributions in binary form must reproduce the above
211da177e4SLinus Torvalds  *        copyright notice, this list of conditions and the following
221da177e4SLinus Torvalds  *        disclaimer in the documentation and/or other materials
231da177e4SLinus Torvalds  *        provided with the distribution.
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
261da177e4SLinus Torvalds  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
271da177e4SLinus Torvalds  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
281da177e4SLinus Torvalds  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
291da177e4SLinus Torvalds  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
301da177e4SLinus Torvalds  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
311da177e4SLinus Torvalds  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
321da177e4SLinus Torvalds  * SOFTWARE.
331da177e4SLinus Torvalds  */
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds #include <linux/module.h>
361da177e4SLinus Torvalds #include <linux/init.h>
371da177e4SLinus Torvalds #include <linux/errno.h>
381da177e4SLinus Torvalds #include <linux/pci.h>
391da177e4SLinus Torvalds #include <linux/interrupt.h>
405a0e3ad6STejun Heo #include <linux/gfp.h>
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds #include "mthca_dev.h"
431da177e4SLinus Torvalds #include "mthca_config_reg.h"
441da177e4SLinus Torvalds #include "mthca_cmd.h"
451da177e4SLinus Torvalds #include "mthca_profile.h"
461da177e4SLinus Torvalds #include "mthca_memfree.h"
4712103dcaSRoland Dreier #include "mthca_wqe.h"
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds MODULE_AUTHOR("Roland Dreier");
501da177e4SLinus Torvalds MODULE_DESCRIPTION("Mellanox InfiniBand HCA low-level driver");
511da177e4SLinus Torvalds MODULE_LICENSE("Dual BSD/GPL");
521da177e4SLinus Torvalds 
53227c939bSRoland Dreier #ifdef CONFIG_INFINIBAND_MTHCA_DEBUG
54227c939bSRoland Dreier 
55227c939bSRoland Dreier int mthca_debug_level = 0;
56227c939bSRoland Dreier module_param_named(debug_level, mthca_debug_level, int, 0644);
57227c939bSRoland Dreier MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
58227c939bSRoland Dreier 
59227c939bSRoland Dreier #endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */
60227c939bSRoland Dreier 
611da177e4SLinus Torvalds #ifdef CONFIG_PCI_MSI
621da177e4SLinus Torvalds 
63017aadc4SMichael S. Tsirkin static int msi_x = 1;
641da177e4SLinus Torvalds module_param(msi_x, int, 0444);
651da177e4SLinus Torvalds MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds #else /* CONFIG_PCI_MSI */
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds #define msi_x (0)
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds #endif /* CONFIG_PCI_MSI */
721da177e4SLinus Torvalds 
73abf45dbbSMichael S. Tsirkin static int tune_pci = 0;
74abf45dbbSMichael S. Tsirkin module_param(tune_pci, int, 0444);
75abf45dbbSMichael S. Tsirkin MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero");
76abf45dbbSMichael S. Tsirkin 
770b0df6f2SRoland Dreier DEFINE_MUTEX(mthca_device_mutex);
78b3b30f5eSJack Morgenstein 
7982da703eSLeonid Arsh #define MTHCA_DEFAULT_NUM_QP            (1 << 16)
8082da703eSLeonid Arsh #define MTHCA_DEFAULT_RDB_PER_QP        (1 << 2)
8182da703eSLeonid Arsh #define MTHCA_DEFAULT_NUM_CQ            (1 << 16)
8282da703eSLeonid Arsh #define MTHCA_DEFAULT_NUM_MCG           (1 << 13)
8382da703eSLeonid Arsh #define MTHCA_DEFAULT_NUM_MPT           (1 << 17)
8482da703eSLeonid Arsh #define MTHCA_DEFAULT_NUM_MTT           (1 << 20)
8582da703eSLeonid Arsh #define MTHCA_DEFAULT_NUM_UDAV          (1 << 15)
8682da703eSLeonid Arsh #define MTHCA_DEFAULT_NUM_RESERVED_MTTS (1 << 18)
8782da703eSLeonid Arsh #define MTHCA_DEFAULT_NUM_UARC_SIZE     (1 << 18)
8882da703eSLeonid Arsh 
8982da703eSLeonid Arsh static struct mthca_profile hca_profile = {
9082da703eSLeonid Arsh 	.num_qp             = MTHCA_DEFAULT_NUM_QP,
9182da703eSLeonid Arsh 	.rdb_per_qp         = MTHCA_DEFAULT_RDB_PER_QP,
9282da703eSLeonid Arsh 	.num_cq             = MTHCA_DEFAULT_NUM_CQ,
9382da703eSLeonid Arsh 	.num_mcg            = MTHCA_DEFAULT_NUM_MCG,
9482da703eSLeonid Arsh 	.num_mpt            = MTHCA_DEFAULT_NUM_MPT,
9582da703eSLeonid Arsh 	.num_mtt            = MTHCA_DEFAULT_NUM_MTT,
9682da703eSLeonid Arsh 	.num_udav           = MTHCA_DEFAULT_NUM_UDAV,          /* Tavor only */
9782da703eSLeonid Arsh 	.fmr_reserved_mtts  = MTHCA_DEFAULT_NUM_RESERVED_MTTS, /* Tavor only */
9882da703eSLeonid Arsh 	.uarc_size          = MTHCA_DEFAULT_NUM_UARC_SIZE,     /* Arbel only */
9982da703eSLeonid Arsh };
10082da703eSLeonid Arsh 
10182da703eSLeonid Arsh module_param_named(num_qp, hca_profile.num_qp, int, 0444);
10282da703eSLeonid Arsh MODULE_PARM_DESC(num_qp, "maximum number of QPs per HCA");
10382da703eSLeonid Arsh 
10482da703eSLeonid Arsh module_param_named(rdb_per_qp, hca_profile.rdb_per_qp, int, 0444);
10582da703eSLeonid Arsh MODULE_PARM_DESC(rdb_per_qp, "number of RDB buffers per QP");
10682da703eSLeonid Arsh 
10782da703eSLeonid Arsh module_param_named(num_cq, hca_profile.num_cq, int, 0444);
10882da703eSLeonid Arsh MODULE_PARM_DESC(num_cq, "maximum number of CQs per HCA");
10982da703eSLeonid Arsh 
11082da703eSLeonid Arsh module_param_named(num_mcg, hca_profile.num_mcg, int, 0444);
11182da703eSLeonid Arsh MODULE_PARM_DESC(num_mcg, "maximum number of multicast groups per HCA");
11282da703eSLeonid Arsh 
11382da703eSLeonid Arsh module_param_named(num_mpt, hca_profile.num_mpt, int, 0444);
11482da703eSLeonid Arsh MODULE_PARM_DESC(num_mpt,
11582da703eSLeonid Arsh 		"maximum number of memory protection table entries per HCA");
11682da703eSLeonid Arsh 
11782da703eSLeonid Arsh module_param_named(num_mtt, hca_profile.num_mtt, int, 0444);
11882da703eSLeonid Arsh MODULE_PARM_DESC(num_mtt,
11982da703eSLeonid Arsh 		 "maximum number of memory translation table segments per HCA");
12082da703eSLeonid Arsh 
12182da703eSLeonid Arsh module_param_named(num_udav, hca_profile.num_udav, int, 0444);
12282da703eSLeonid Arsh MODULE_PARM_DESC(num_udav, "maximum number of UD address vectors per HCA");
12382da703eSLeonid Arsh 
12482da703eSLeonid Arsh module_param_named(fmr_reserved_mtts, hca_profile.fmr_reserved_mtts, int, 0444);
12582da703eSLeonid Arsh MODULE_PARM_DESC(fmr_reserved_mtts,
12682da703eSLeonid Arsh 		 "number of memory translation table segments reserved for FMR");
12782da703eSLeonid Arsh 
128c1f67a88SEli Cohen static int log_mtts_per_seg = ilog2(MTHCA_MTT_SEG_SIZE / 8);
129c1f67a88SEli Cohen module_param_named(log_mtts_per_seg, log_mtts_per_seg, int, 0444);
130c1f67a88SEli Cohen MODULE_PARM_DESC(log_mtts_per_seg, "Log2 number of MTT entries per segment (1-5)");
131c1f67a88SEli Cohen 
1321e6d9abeSGreg Kroah-Hartman static char mthca_version[] =
133177214afSBernhard Fischer 	DRV_NAME ": Mellanox InfiniBand HCA driver v"
1341da177e4SLinus Torvalds 	DRV_VERSION " (" DRV_RELDATE ")\n";
1351da177e4SLinus Torvalds 
mthca_tune_pci(struct mthca_dev * mdev)136f4f3d0f0SRoland Dreier static int mthca_tune_pci(struct mthca_dev *mdev)
1371da177e4SLinus Torvalds {
138abf45dbbSMichael S. Tsirkin 	if (!tune_pci)
139abf45dbbSMichael S. Tsirkin 		return 0;
140abf45dbbSMichael S. Tsirkin 
1411da177e4SLinus Torvalds 	/* First try to max out Read Byte Count */
142a855b1a7SPeter Oruba 	if (pci_find_capability(mdev->pdev, PCI_CAP_ID_PCIX)) {
143a855b1a7SPeter Oruba 		if (pcix_set_mmrbc(mdev->pdev, pcix_get_max_mmrbc(mdev->pdev))) {
144a855b1a7SPeter Oruba 			mthca_err(mdev, "Couldn't set PCI-X max read count, "
1451da177e4SLinus Torvalds 				"aborting.\n");
1461da177e4SLinus Torvalds 			return -ENODEV;
1471da177e4SLinus Torvalds 		}
14868a3c212SRoland Dreier 	} else if (!(mdev->mthca_flags & MTHCA_FLAG_PCIE))
1491da177e4SLinus Torvalds 		mthca_info(mdev, "No PCI-X capability, not setting RBC.\n");
1501da177e4SLinus Torvalds 
1519b89925cSJon Mason 	if (pci_is_pcie(mdev->pdev)) {
152a855b1a7SPeter Oruba 		if (pcie_set_readrq(mdev->pdev, 4096)) {
153a855b1a7SPeter Oruba 			mthca_err(mdev, "Couldn't write PCI Express read request, "
154a855b1a7SPeter Oruba 				"aborting.\n");
1551da177e4SLinus Torvalds 			return -ENODEV;
1561da177e4SLinus Torvalds 		}
15768a3c212SRoland Dreier 	} else if (mdev->mthca_flags & MTHCA_FLAG_PCIE)
1581da177e4SLinus Torvalds 		mthca_info(mdev, "No PCI Express capability, "
1591da177e4SLinus Torvalds 			   "not setting Max Read Request Size.\n");
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds 	return 0;
1621da177e4SLinus Torvalds }
1631da177e4SLinus Torvalds 
mthca_dev_lim(struct mthca_dev * mdev,struct mthca_dev_lim * dev_lim)164f4f3d0f0SRoland Dreier static int mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim *dev_lim)
1651da177e4SLinus Torvalds {
1661da177e4SLinus Torvalds 	int err;
1671da177e4SLinus Torvalds 
168c1f67a88SEli Cohen 	mdev->limits.mtt_seg_size = (1 << log_mtts_per_seg) * 8;
169cdb73db0SGoldwyn Rodrigues 	err = mthca_QUERY_DEV_LIM(mdev, dev_lim);
1701da177e4SLinus Torvalds 	if (err) {
171cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "QUERY_DEV_LIM command returned %d"
172cdb73db0SGoldwyn Rodrigues 				", aborting.\n", err);
1731da177e4SLinus Torvalds 		return err;
1741da177e4SLinus Torvalds 	}
1751da177e4SLinus Torvalds 	if (dev_lim->min_page_sz > PAGE_SIZE) {
1761da177e4SLinus Torvalds 		mthca_err(mdev, "HCA minimum page size of %d bigger than "
1771da177e4SLinus Torvalds 			  "kernel PAGE_SIZE of %ld, aborting.\n",
1781da177e4SLinus Torvalds 			  dev_lim->min_page_sz, PAGE_SIZE);
1791da177e4SLinus Torvalds 		return -ENODEV;
1801da177e4SLinus Torvalds 	}
1811da177e4SLinus Torvalds 	if (dev_lim->num_ports > MTHCA_MAX_PORTS) {
1821da177e4SLinus Torvalds 		mthca_err(mdev, "HCA has %d ports, but we only support %d, "
1831da177e4SLinus Torvalds 			  "aborting.\n",
1841da177e4SLinus Torvalds 			  dev_lim->num_ports, MTHCA_MAX_PORTS);
1851da177e4SLinus Torvalds 		return -ENODEV;
1861da177e4SLinus Torvalds 	}
1871da177e4SLinus Torvalds 
188cbd2981aSMichael S. Tsirkin 	if (dev_lim->uar_size > pci_resource_len(mdev->pdev, 2)) {
189cbd2981aSMichael S. Tsirkin 		mthca_err(mdev, "HCA reported UAR size of 0x%x bigger than "
190e29419ffSGreg Kroah-Hartman 			  "PCI resource 2 size of 0x%llx, aborting.\n",
191e29419ffSGreg Kroah-Hartman 			  dev_lim->uar_size,
192e29419ffSGreg Kroah-Hartman 			  (unsigned long long)pci_resource_len(mdev->pdev, 2));
193cbd2981aSMichael S. Tsirkin 		return -ENODEV;
194cbd2981aSMichael S. Tsirkin 	}
195cbd2981aSMichael S. Tsirkin 
1961da177e4SLinus Torvalds 	mdev->limits.num_ports      	= dev_lim->num_ports;
1971da177e4SLinus Torvalds 	mdev->limits.vl_cap             = dev_lim->max_vl;
1981da177e4SLinus Torvalds 	mdev->limits.mtu_cap            = dev_lim->max_mtu;
1991da177e4SLinus Torvalds 	mdev->limits.gid_table_len  	= dev_lim->max_gids;
2001da177e4SLinus Torvalds 	mdev->limits.pkey_table_len 	= dev_lim->max_pkeys;
2011da177e4SLinus Torvalds 	mdev->limits.local_ca_ack_delay = dev_lim->local_ca_ack_delay;
20212103dcaSRoland Dreier 	/*
20312103dcaSRoland Dreier 	 * Need to allow for worst case send WQE overhead and check
20412103dcaSRoland Dreier 	 * whether max_desc_sz imposes a lower limit than max_sg; UD
20512103dcaSRoland Dreier 	 * send has the biggest overhead.
20612103dcaSRoland Dreier 	 */
20712103dcaSRoland Dreier 	mdev->limits.max_sg		= min_t(int, dev_lim->max_sg,
20812103dcaSRoland Dreier 					      (dev_lim->max_desc_sz -
20912103dcaSRoland Dreier 					       sizeof (struct mthca_next_seg) -
21012103dcaSRoland Dreier 					       (mthca_is_memfree(mdev) ?
21112103dcaSRoland Dreier 						sizeof (struct mthca_arbel_ud_seg) :
21212103dcaSRoland Dreier 						sizeof (struct mthca_tavor_ud_seg))) /
21312103dcaSRoland Dreier 						sizeof (struct mthca_data_seg));
214efaae8f7SJack Morgenstein 	mdev->limits.max_wqes           = dev_lim->max_qp_sz;
215efaae8f7SJack Morgenstein 	mdev->limits.max_qp_init_rdma   = dev_lim->max_requester_per_qp;
2161da177e4SLinus Torvalds 	mdev->limits.reserved_qps       = dev_lim->reserved_qps;
217efaae8f7SJack Morgenstein 	mdev->limits.max_srq_wqes       = dev_lim->max_srq_sz;
2181da177e4SLinus Torvalds 	mdev->limits.reserved_srqs      = dev_lim->reserved_srqs;
2191da177e4SLinus Torvalds 	mdev->limits.reserved_eecs      = dev_lim->reserved_eecs;
22077369ed3SJack Morgenstein 	mdev->limits.max_desc_sz        = dev_lim->max_desc_sz;
22159fef3b1SJack Morgenstein 	mdev->limits.max_srq_sge	= mthca_max_srq_sge(mdev);
222efaae8f7SJack Morgenstein 	/*
223efaae8f7SJack Morgenstein 	 * Subtract 1 from the limit because we need to allocate a
224efaae8f7SJack Morgenstein 	 * spare CQE so the HCA HW can tell the difference between an
225efaae8f7SJack Morgenstein 	 * empty CQ and a full CQ.
226efaae8f7SJack Morgenstein 	 */
227efaae8f7SJack Morgenstein 	mdev->limits.max_cqes           = dev_lim->max_cq_sz - 1;
2281da177e4SLinus Torvalds 	mdev->limits.reserved_cqs       = dev_lim->reserved_cqs;
2291da177e4SLinus Torvalds 	mdev->limits.reserved_eqs       = dev_lim->reserved_eqs;
2301da177e4SLinus Torvalds 	mdev->limits.reserved_mtts      = dev_lim->reserved_mtts;
2311da177e4SLinus Torvalds 	mdev->limits.reserved_mrws      = dev_lim->reserved_mrws;
2321da177e4SLinus Torvalds 	mdev->limits.reserved_uars      = dev_lim->reserved_uars;
2331da177e4SLinus Torvalds 	mdev->limits.reserved_pds       = dev_lim->reserved_pds;
234da6561c2SRoland Dreier 	mdev->limits.port_width_cap     = dev_lim->max_port_width;
2350f69ce1eSJack Morgenstein 	mdev->limits.page_size_cap      = ~(u32) (dev_lim->min_page_sz - 1);
23633033b79SJack Morgenstein 	mdev->limits.flags              = dev_lim->flags;
237bf6a9e31SJack Morgenstein 	/*
238bf6a9e31SJack Morgenstein 	 * For old FW that doesn't return static rate support, use a
239bf6a9e31SJack Morgenstein 	 * value of 0x3 (only static rate values of 0 or 1 are handled),
240bf6a9e31SJack Morgenstein 	 * except on Sinai, where even old FW can handle static rate
241bf6a9e31SJack Morgenstein 	 * values of 2 and 3.
242bf6a9e31SJack Morgenstein 	 */
243bf6a9e31SJack Morgenstein 	if (dev_lim->stat_rate_support)
244bf6a9e31SJack Morgenstein 		mdev->limits.stat_rate_support = dev_lim->stat_rate_support;
245bf6a9e31SJack Morgenstein 	else if (mdev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
246bf6a9e31SJack Morgenstein 		mdev->limits.stat_rate_support = 0xf;
247bf6a9e31SJack Morgenstein 	else
248bf6a9e31SJack Morgenstein 		mdev->limits.stat_rate_support = 0x3;
2491da177e4SLinus Torvalds 
2501da177e4SLinus Torvalds 	/* IB_DEVICE_RESIZE_MAX_WR not supported by driver.
2511da177e4SLinus Torvalds 	   May be doable since hardware supports it for SRQ.
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds 	   IB_DEVICE_N_NOTIFY_CQ is supported by hardware but not by driver.
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds 	   IB_DEVICE_SRQ_RESIZE is supported by hardware but SRQ is not
2561da177e4SLinus Torvalds 	   supported by driver. */
2571da177e4SLinus Torvalds 	mdev->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT |
2581da177e4SLinus Torvalds 		IB_DEVICE_PORT_ACTIVE_EVENT |
2591da177e4SLinus Torvalds 		IB_DEVICE_SYS_IMAGE_GUID |
2601da177e4SLinus Torvalds 		IB_DEVICE_RC_RNR_NAK_GEN;
2611da177e4SLinus Torvalds 
2621da177e4SLinus Torvalds 	if (dev_lim->flags & DEV_LIM_FLAG_BAD_PKEY_CNTR)
2631da177e4SLinus Torvalds 		mdev->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds 	if (dev_lim->flags & DEV_LIM_FLAG_BAD_QKEY_CNTR)
2661da177e4SLinus Torvalds 		mdev->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR;
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds 	if (dev_lim->flags & DEV_LIM_FLAG_RAW_MULTI)
2691da177e4SLinus Torvalds 		mdev->device_cap_flags |= IB_DEVICE_RAW_MULTI;
2701da177e4SLinus Torvalds 
2711da177e4SLinus Torvalds 	if (dev_lim->flags & DEV_LIM_FLAG_AUTO_PATH_MIG)
2721da177e4SLinus Torvalds 		mdev->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG;
2731da177e4SLinus Torvalds 
2741da177e4SLinus Torvalds 	if (dev_lim->flags & DEV_LIM_FLAG_UD_AV_PORT_ENFORCE)
2751da177e4SLinus Torvalds 		mdev->device_cap_flags |= IB_DEVICE_UD_AV_PORT_ENFORCE;
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds 	if (dev_lim->flags & DEV_LIM_FLAG_SRQ)
2781da177e4SLinus Torvalds 		mdev->mthca_flags |= MTHCA_FLAG_SRQ;
2791da177e4SLinus Torvalds 
280680b575fSEli Cohen 	if (mthca_is_memfree(mdev))
281680b575fSEli Cohen 		if (dev_lim->flags & DEV_LIM_FLAG_IPOIB_CSUM)
282680b575fSEli Cohen 			mdev->device_cap_flags |= IB_DEVICE_UD_IP_CSUM;
283680b575fSEli Cohen 
2841da177e4SLinus Torvalds 	return 0;
2851da177e4SLinus Torvalds }
2861da177e4SLinus Torvalds 
mthca_init_tavor(struct mthca_dev * mdev)287f4f3d0f0SRoland Dreier static int mthca_init_tavor(struct mthca_dev *mdev)
2881da177e4SLinus Torvalds {
28919773539SRoland Dreier 	s64 size;
2901da177e4SLinus Torvalds 	int err;
2911da177e4SLinus Torvalds 	struct mthca_dev_lim        dev_lim;
2921da177e4SLinus Torvalds 	struct mthca_profile        profile;
2931da177e4SLinus Torvalds 	struct mthca_init_hca_param init_hca;
2941da177e4SLinus Torvalds 
295cdb73db0SGoldwyn Rodrigues 	err = mthca_SYS_EN(mdev);
2961da177e4SLinus Torvalds 	if (err) {
297cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "SYS_EN command returned %d, aborting.\n", err);
2981da177e4SLinus Torvalds 		return err;
2991da177e4SLinus Torvalds 	}
3001da177e4SLinus Torvalds 
301cdb73db0SGoldwyn Rodrigues 	err = mthca_QUERY_FW(mdev);
3021da177e4SLinus Torvalds 	if (err) {
303cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "QUERY_FW command returned %d,"
304cdb73db0SGoldwyn Rodrigues 				" aborting.\n", err);
3051da177e4SLinus Torvalds 		goto err_disable;
3061da177e4SLinus Torvalds 	}
307cdb73db0SGoldwyn Rodrigues 	err = mthca_QUERY_DDR(mdev);
3081da177e4SLinus Torvalds 	if (err) {
309cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "QUERY_DDR command returned %d, aborting.\n", err);
3101da177e4SLinus Torvalds 		goto err_disable;
3111da177e4SLinus Torvalds 	}
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds 	err = mthca_dev_lim(mdev, &dev_lim);
314aa2f9367SJack Morgenstein 	if (err) {
315cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "QUERY_DEV_LIM command returned %d, aborting.\n", err);
316aa2f9367SJack Morgenstein 		goto err_disable;
317aa2f9367SJack Morgenstein 	}
3181da177e4SLinus Torvalds 
31982da703eSLeonid Arsh 	profile = hca_profile;
3201da177e4SLinus Torvalds 	profile.num_uar   = dev_lim.uar_size / PAGE_SIZE;
3211da177e4SLinus Torvalds 	profile.uarc_size = 0;
322ec34a922SRoland Dreier 	if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
323ec34a922SRoland Dreier 		profile.num_srq = dev_lim.max_srqs;
3241da177e4SLinus Torvalds 
32519773539SRoland Dreier 	size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
32619773539SRoland Dreier 	if (size < 0) {
32719773539SRoland Dreier 		err = size;
3281da177e4SLinus Torvalds 		goto err_disable;
32919773539SRoland Dreier 	}
3301da177e4SLinus Torvalds 
331cdb73db0SGoldwyn Rodrigues 	err = mthca_INIT_HCA(mdev, &init_hca);
3321da177e4SLinus Torvalds 	if (err) {
333cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "INIT_HCA command returned %d, aborting.\n", err);
3341da177e4SLinus Torvalds 		goto err_disable;
3351da177e4SLinus Torvalds 	}
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds 	return 0;
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds err_disable:
340cdb73db0SGoldwyn Rodrigues 	mthca_SYS_DIS(mdev);
3411da177e4SLinus Torvalds 
3421da177e4SLinus Torvalds 	return err;
3431da177e4SLinus Torvalds }
3441da177e4SLinus Torvalds 
mthca_load_fw(struct mthca_dev * mdev)345f4f3d0f0SRoland Dreier static int mthca_load_fw(struct mthca_dev *mdev)
3461da177e4SLinus Torvalds {
3471da177e4SLinus Torvalds 	int err;
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds 	/* FIXME: use HCA-attached memory for FW if present */
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds 	mdev->fw.arbel.fw_icm =
3521da177e4SLinus Torvalds 		mthca_alloc_icm(mdev, mdev->fw.arbel.fw_pages,
353391e4deaSMichael S. Tsirkin 				GFP_HIGHUSER | __GFP_NOWARN, 0);
3541da177e4SLinus Torvalds 	if (!mdev->fw.arbel.fw_icm) {
3551da177e4SLinus Torvalds 		mthca_err(mdev, "Couldn't allocate FW area, aborting.\n");
3561da177e4SLinus Torvalds 		return -ENOMEM;
3571da177e4SLinus Torvalds 	}
3581da177e4SLinus Torvalds 
359cdb73db0SGoldwyn Rodrigues 	err = mthca_MAP_FA(mdev, mdev->fw.arbel.fw_icm);
3601da177e4SLinus Torvalds 	if (err) {
361cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "MAP_FA command returned %d, aborting.\n", err);
3621da177e4SLinus Torvalds 		goto err_free;
3631da177e4SLinus Torvalds 	}
364cdb73db0SGoldwyn Rodrigues 	err = mthca_RUN_FW(mdev);
3651da177e4SLinus Torvalds 	if (err) {
366cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "RUN_FW command returned %d, aborting.\n", err);
3671da177e4SLinus Torvalds 		goto err_unmap_fa;
3681da177e4SLinus Torvalds 	}
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds 	return 0;
3711da177e4SLinus Torvalds 
3721da177e4SLinus Torvalds err_unmap_fa:
373cdb73db0SGoldwyn Rodrigues 	mthca_UNMAP_FA(mdev);
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds err_free:
376391e4deaSMichael S. Tsirkin 	mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
3771da177e4SLinus Torvalds 	return err;
3781da177e4SLinus Torvalds }
3791da177e4SLinus Torvalds 
mthca_init_icm(struct mthca_dev * mdev,struct mthca_dev_lim * dev_lim,struct mthca_init_hca_param * init_hca,u64 icm_size)380f4f3d0f0SRoland Dreier static int mthca_init_icm(struct mthca_dev *mdev,
3811da177e4SLinus Torvalds 			  struct mthca_dev_lim *dev_lim,
3821da177e4SLinus Torvalds 			  struct mthca_init_hca_param *init_hca,
3831da177e4SLinus Torvalds 			  u64 icm_size)
3841da177e4SLinus Torvalds {
385*b9a85e5eSLeon Romanovsky 	u64 aux_pages = 0;
3861da177e4SLinus Torvalds 	int err;
3871da177e4SLinus Torvalds 
388cdb73db0SGoldwyn Rodrigues 	err = mthca_SET_ICM_SIZE(mdev, icm_size, &aux_pages);
3891da177e4SLinus Torvalds 	if (err) {
390cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "SET_ICM_SIZE command returned %d, aborting.\n", err);
3911da177e4SLinus Torvalds 		return err;
3921da177e4SLinus Torvalds 	}
3931da177e4SLinus Torvalds 
3941da177e4SLinus Torvalds 	mthca_dbg(mdev, "%lld KB of HCA context requires %lld KB aux memory.\n",
3951da177e4SLinus Torvalds 		  (unsigned long long) icm_size >> 10,
3961da177e4SLinus Torvalds 		  (unsigned long long) aux_pages << 2);
3971da177e4SLinus Torvalds 
3981da177e4SLinus Torvalds 	mdev->fw.arbel.aux_icm = mthca_alloc_icm(mdev, aux_pages,
399391e4deaSMichael S. Tsirkin 						 GFP_HIGHUSER | __GFP_NOWARN, 0);
4001da177e4SLinus Torvalds 	if (!mdev->fw.arbel.aux_icm) {
4011da177e4SLinus Torvalds 		mthca_err(mdev, "Couldn't allocate aux memory, aborting.\n");
4021da177e4SLinus Torvalds 		return -ENOMEM;
4031da177e4SLinus Torvalds 	}
4041da177e4SLinus Torvalds 
405cdb73db0SGoldwyn Rodrigues 	err = mthca_MAP_ICM_AUX(mdev, mdev->fw.arbel.aux_icm);
4061da177e4SLinus Torvalds 	if (err) {
407cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "MAP_ICM_AUX returned %d, aborting.\n", err);
4081da177e4SLinus Torvalds 		goto err_free_aux;
4091da177e4SLinus Torvalds 	}
4101da177e4SLinus Torvalds 
4111da177e4SLinus Torvalds 	err = mthca_map_eq_icm(mdev, init_hca->eqc_base);
4121da177e4SLinus Torvalds 	if (err) {
4131da177e4SLinus Torvalds 		mthca_err(mdev, "Failed to map EQ context memory, aborting.\n");
4141da177e4SLinus Torvalds 		goto err_unmap_aux;
4151da177e4SLinus Torvalds 	}
4161da177e4SLinus Torvalds 
4171d1f19cfSMichael S. Tsirkin 	/* CPU writes to non-reserved MTTs, while HCA might DMA to reserved mtts */
418c1f67a88SEli Cohen 	mdev->limits.reserved_mtts = ALIGN(mdev->limits.reserved_mtts * mdev->limits.mtt_seg_size,
419c1f67a88SEli Cohen 					   dma_get_cache_alignment()) / mdev->limits.mtt_seg_size;
4201d1f19cfSMichael S. Tsirkin 
4211da177e4SLinus Torvalds 	mdev->mr_table.mtt_table = mthca_alloc_icm_table(mdev, init_hca->mtt_base,
422c1f67a88SEli Cohen 							 mdev->limits.mtt_seg_size,
4231da177e4SLinus Torvalds 							 mdev->limits.num_mtt_segs,
424391e4deaSMichael S. Tsirkin 							 mdev->limits.reserved_mtts,
425391e4deaSMichael S. Tsirkin 							 1, 0);
4261da177e4SLinus Torvalds 	if (!mdev->mr_table.mtt_table) {
4271da177e4SLinus Torvalds 		mthca_err(mdev, "Failed to map MTT context memory, aborting.\n");
4281da177e4SLinus Torvalds 		err = -ENOMEM;
4291da177e4SLinus Torvalds 		goto err_unmap_eq;
4301da177e4SLinus Torvalds 	}
4311da177e4SLinus Torvalds 
4321da177e4SLinus Torvalds 	mdev->mr_table.mpt_table = mthca_alloc_icm_table(mdev, init_hca->mpt_base,
4331da177e4SLinus Torvalds 							 dev_lim->mpt_entry_sz,
4341da177e4SLinus Torvalds 							 mdev->limits.num_mpts,
435391e4deaSMichael S. Tsirkin 							 mdev->limits.reserved_mrws,
436391e4deaSMichael S. Tsirkin 							 1, 1);
4371da177e4SLinus Torvalds 	if (!mdev->mr_table.mpt_table) {
4381da177e4SLinus Torvalds 		mthca_err(mdev, "Failed to map MPT context memory, aborting.\n");
4391da177e4SLinus Torvalds 		err = -ENOMEM;
4401da177e4SLinus Torvalds 		goto err_unmap_mtt;
4411da177e4SLinus Torvalds 	}
4421da177e4SLinus Torvalds 
4431da177e4SLinus Torvalds 	mdev->qp_table.qp_table = mthca_alloc_icm_table(mdev, init_hca->qpc_base,
4441da177e4SLinus Torvalds 							dev_lim->qpc_entry_sz,
4451da177e4SLinus Torvalds 							mdev->limits.num_qps,
446391e4deaSMichael S. Tsirkin 							mdev->limits.reserved_qps,
447391e4deaSMichael S. Tsirkin 							0, 0);
4481da177e4SLinus Torvalds 	if (!mdev->qp_table.qp_table) {
4491da177e4SLinus Torvalds 		mthca_err(mdev, "Failed to map QP context memory, aborting.\n");
4501da177e4SLinus Torvalds 		err = -ENOMEM;
4511da177e4SLinus Torvalds 		goto err_unmap_mpt;
4521da177e4SLinus Torvalds 	}
4531da177e4SLinus Torvalds 
4541da177e4SLinus Torvalds 	mdev->qp_table.eqp_table = mthca_alloc_icm_table(mdev, init_hca->eqpc_base,
4551da177e4SLinus Torvalds 							 dev_lim->eqpc_entry_sz,
4561da177e4SLinus Torvalds 							 mdev->limits.num_qps,
457391e4deaSMichael S. Tsirkin 							 mdev->limits.reserved_qps,
458391e4deaSMichael S. Tsirkin 							 0, 0);
4591da177e4SLinus Torvalds 	if (!mdev->qp_table.eqp_table) {
4601da177e4SLinus Torvalds 		mthca_err(mdev, "Failed to map EQP context memory, aborting.\n");
4611da177e4SLinus Torvalds 		err = -ENOMEM;
4621da177e4SLinus Torvalds 		goto err_unmap_qp;
4631da177e4SLinus Torvalds 	}
4641da177e4SLinus Torvalds 
46508aeb14eSRoland Dreier 	mdev->qp_table.rdb_table = mthca_alloc_icm_table(mdev, init_hca->rdb_base,
46608aeb14eSRoland Dreier 							 MTHCA_RDB_ENTRY_SIZE,
46708aeb14eSRoland Dreier 							 mdev->limits.num_qps <<
468391e4deaSMichael S. Tsirkin 							 mdev->qp_table.rdb_shift, 0,
46908aeb14eSRoland Dreier 							 0, 0);
47008aeb14eSRoland Dreier 	if (!mdev->qp_table.rdb_table) {
47108aeb14eSRoland Dreier 		mthca_err(mdev, "Failed to map RDB context memory, aborting\n");
47208aeb14eSRoland Dreier 		err = -ENOMEM;
47319272d43SRoland Dreier 		goto err_unmap_eqp;
47408aeb14eSRoland Dreier 	}
47508aeb14eSRoland Dreier 
4761da177e4SLinus Torvalds 	mdev->cq_table.table = mthca_alloc_icm_table(mdev, init_hca->cqc_base,
4771da177e4SLinus Torvalds 						     dev_lim->cqc_entry_sz,
4781da177e4SLinus Torvalds 						     mdev->limits.num_cqs,
479391e4deaSMichael S. Tsirkin 						     mdev->limits.reserved_cqs,
480391e4deaSMichael S. Tsirkin 						     0, 0);
4811da177e4SLinus Torvalds 	if (!mdev->cq_table.table) {
4821da177e4SLinus Torvalds 		mthca_err(mdev, "Failed to map CQ context memory, aborting.\n");
4831da177e4SLinus Torvalds 		err = -ENOMEM;
48408aeb14eSRoland Dreier 		goto err_unmap_rdb;
4851da177e4SLinus Torvalds 	}
4861da177e4SLinus Torvalds 
487ec34a922SRoland Dreier 	if (mdev->mthca_flags & MTHCA_FLAG_SRQ) {
488ec34a922SRoland Dreier 		mdev->srq_table.table =
489ec34a922SRoland Dreier 			mthca_alloc_icm_table(mdev, init_hca->srqc_base,
490ec34a922SRoland Dreier 					      dev_lim->srq_entry_sz,
491ec34a922SRoland Dreier 					      mdev->limits.num_srqs,
492391e4deaSMichael S. Tsirkin 					      mdev->limits.reserved_srqs,
493391e4deaSMichael S. Tsirkin 					      0, 0);
494ec34a922SRoland Dreier 		if (!mdev->srq_table.table) {
495ec34a922SRoland Dreier 			mthca_err(mdev, "Failed to map SRQ context memory, "
496ec34a922SRoland Dreier 				  "aborting.\n");
497ec34a922SRoland Dreier 			err = -ENOMEM;
498ec34a922SRoland Dreier 			goto err_unmap_cq;
499ec34a922SRoland Dreier 		}
500ec34a922SRoland Dreier 	}
501ec34a922SRoland Dreier 
5021da177e4SLinus Torvalds 	/*
5031da177e4SLinus Torvalds 	 * It's not strictly required, but for simplicity just map the
5041da177e4SLinus Torvalds 	 * whole multicast group table now.  The table isn't very big
5051da177e4SLinus Torvalds 	 * and it's a lot easier than trying to track ref counts.
5061da177e4SLinus Torvalds 	 */
5071da177e4SLinus Torvalds 	mdev->mcg_table.table = mthca_alloc_icm_table(mdev, init_hca->mc_base,
5081da177e4SLinus Torvalds 						      MTHCA_MGM_ENTRY_SIZE,
5091da177e4SLinus Torvalds 						      mdev->limits.num_mgms +
5101da177e4SLinus Torvalds 						      mdev->limits.num_amgms,
5111da177e4SLinus Torvalds 						      mdev->limits.num_mgms +
5121da177e4SLinus Torvalds 						      mdev->limits.num_amgms,
513391e4deaSMichael S. Tsirkin 						      0, 0);
5141da177e4SLinus Torvalds 	if (!mdev->mcg_table.table) {
5151da177e4SLinus Torvalds 		mthca_err(mdev, "Failed to map MCG context memory, aborting.\n");
5161da177e4SLinus Torvalds 		err = -ENOMEM;
517ec34a922SRoland Dreier 		goto err_unmap_srq;
5181da177e4SLinus Torvalds 	}
5191da177e4SLinus Torvalds 
5201da177e4SLinus Torvalds 	return 0;
5211da177e4SLinus Torvalds 
522ec34a922SRoland Dreier err_unmap_srq:
523ec34a922SRoland Dreier 	if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
524ec34a922SRoland Dreier 		mthca_free_icm_table(mdev, mdev->srq_table.table);
525ec34a922SRoland Dreier 
5261da177e4SLinus Torvalds err_unmap_cq:
5271da177e4SLinus Torvalds 	mthca_free_icm_table(mdev, mdev->cq_table.table);
5281da177e4SLinus Torvalds 
52908aeb14eSRoland Dreier err_unmap_rdb:
53008aeb14eSRoland Dreier 	mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);
53108aeb14eSRoland Dreier 
5321da177e4SLinus Torvalds err_unmap_eqp:
5331da177e4SLinus Torvalds 	mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);
5341da177e4SLinus Torvalds 
5351da177e4SLinus Torvalds err_unmap_qp:
5361da177e4SLinus Torvalds 	mthca_free_icm_table(mdev, mdev->qp_table.qp_table);
5371da177e4SLinus Torvalds 
5381da177e4SLinus Torvalds err_unmap_mpt:
5391da177e4SLinus Torvalds 	mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds err_unmap_mtt:
5421da177e4SLinus Torvalds 	mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);
5431da177e4SLinus Torvalds 
5441da177e4SLinus Torvalds err_unmap_eq:
5451da177e4SLinus Torvalds 	mthca_unmap_eq_icm(mdev);
5461da177e4SLinus Torvalds 
5471da177e4SLinus Torvalds err_unmap_aux:
548cdb73db0SGoldwyn Rodrigues 	mthca_UNMAP_ICM_AUX(mdev);
5491da177e4SLinus Torvalds 
5501da177e4SLinus Torvalds err_free_aux:
551391e4deaSMichael S. Tsirkin 	mthca_free_icm(mdev, mdev->fw.arbel.aux_icm, 0);
5521da177e4SLinus Torvalds 
5531da177e4SLinus Torvalds 	return err;
5541da177e4SLinus Torvalds }
5551da177e4SLinus Torvalds 
mthca_free_icms(struct mthca_dev * mdev)556aba7a22fSMichael S. Tsirkin static void mthca_free_icms(struct mthca_dev *mdev)
557aba7a22fSMichael S. Tsirkin {
558aba7a22fSMichael S. Tsirkin 
559aba7a22fSMichael S. Tsirkin 	mthca_free_icm_table(mdev, mdev->mcg_table.table);
560aba7a22fSMichael S. Tsirkin 	if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
561aba7a22fSMichael S. Tsirkin 		mthca_free_icm_table(mdev, mdev->srq_table.table);
562aba7a22fSMichael S. Tsirkin 	mthca_free_icm_table(mdev, mdev->cq_table.table);
563aba7a22fSMichael S. Tsirkin 	mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);
564aba7a22fSMichael S. Tsirkin 	mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);
565aba7a22fSMichael S. Tsirkin 	mthca_free_icm_table(mdev, mdev->qp_table.qp_table);
566aba7a22fSMichael S. Tsirkin 	mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);
567aba7a22fSMichael S. Tsirkin 	mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);
568aba7a22fSMichael S. Tsirkin 	mthca_unmap_eq_icm(mdev);
569aba7a22fSMichael S. Tsirkin 
570cdb73db0SGoldwyn Rodrigues 	mthca_UNMAP_ICM_AUX(mdev);
571391e4deaSMichael S. Tsirkin 	mthca_free_icm(mdev, mdev->fw.arbel.aux_icm, 0);
572aba7a22fSMichael S. Tsirkin }
573aba7a22fSMichael S. Tsirkin 
mthca_init_arbel(struct mthca_dev * mdev)574f4f3d0f0SRoland Dreier static int mthca_init_arbel(struct mthca_dev *mdev)
5751da177e4SLinus Torvalds {
5761da177e4SLinus Torvalds 	struct mthca_dev_lim        dev_lim;
5771da177e4SLinus Torvalds 	struct mthca_profile        profile;
5781da177e4SLinus Torvalds 	struct mthca_init_hca_param init_hca;
57919773539SRoland Dreier 	s64 icm_size;
5801da177e4SLinus Torvalds 	int err;
5811da177e4SLinus Torvalds 
582cdb73db0SGoldwyn Rodrigues 	err = mthca_QUERY_FW(mdev);
5831da177e4SLinus Torvalds 	if (err) {
584cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "QUERY_FW command failed %d, aborting.\n", err);
5851da177e4SLinus Torvalds 		return err;
5861da177e4SLinus Torvalds 	}
5871da177e4SLinus Torvalds 
588cdb73db0SGoldwyn Rodrigues 	err = mthca_ENABLE_LAM(mdev);
589cdb73db0SGoldwyn Rodrigues 	if (err == -EAGAIN) {
5901da177e4SLinus Torvalds 		mthca_dbg(mdev, "No HCA-attached memory (running in MemFree mode)\n");
5911da177e4SLinus Torvalds 		mdev->mthca_flags |= MTHCA_FLAG_NO_LAM;
592cdb73db0SGoldwyn Rodrigues 	} else if (err) {
593cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "ENABLE_LAM returned %d, aborting.\n", err);
594cdb73db0SGoldwyn Rodrigues 		return err;
5951da177e4SLinus Torvalds 	}
5961da177e4SLinus Torvalds 
5971da177e4SLinus Torvalds 	err = mthca_load_fw(mdev);
5981da177e4SLinus Torvalds 	if (err) {
599cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "Loading FW returned %d, aborting.\n", err);
6001da177e4SLinus Torvalds 		goto err_disable;
6011da177e4SLinus Torvalds 	}
6021da177e4SLinus Torvalds 
6031da177e4SLinus Torvalds 	err = mthca_dev_lim(mdev, &dev_lim);
6041da177e4SLinus Torvalds 	if (err) {
605cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "QUERY_DEV_LIM returned %d, aborting.\n", err);
6061da177e4SLinus Torvalds 		goto err_stop_fw;
6071da177e4SLinus Torvalds 	}
6081da177e4SLinus Torvalds 
60982da703eSLeonid Arsh 	profile = hca_profile;
6101da177e4SLinus Torvalds 	profile.num_uar  = dev_lim.uar_size / PAGE_SIZE;
6111da177e4SLinus Torvalds 	profile.num_udav = 0;
612ec34a922SRoland Dreier 	if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
613ec34a922SRoland Dreier 		profile.num_srq = dev_lim.max_srqs;
6141da177e4SLinus Torvalds 
6151da177e4SLinus Torvalds 	icm_size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
61619773539SRoland Dreier 	if (icm_size < 0) {
6171da177e4SLinus Torvalds 		err = icm_size;
6181da177e4SLinus Torvalds 		goto err_stop_fw;
6191da177e4SLinus Torvalds 	}
6201da177e4SLinus Torvalds 
6211da177e4SLinus Torvalds 	err = mthca_init_icm(mdev, &dev_lim, &init_hca, icm_size);
6221da177e4SLinus Torvalds 	if (err)
6231da177e4SLinus Torvalds 		goto err_stop_fw;
6241da177e4SLinus Torvalds 
625cdb73db0SGoldwyn Rodrigues 	err = mthca_INIT_HCA(mdev, &init_hca);
6261da177e4SLinus Torvalds 	if (err) {
627cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "INIT_HCA command returned %d, aborting.\n", err);
6281da177e4SLinus Torvalds 		goto err_free_icm;
6291da177e4SLinus Torvalds 	}
6301da177e4SLinus Torvalds 
6311da177e4SLinus Torvalds 	return 0;
6321da177e4SLinus Torvalds 
6331da177e4SLinus Torvalds err_free_icm:
634aba7a22fSMichael S. Tsirkin 	mthca_free_icms(mdev);
6351da177e4SLinus Torvalds 
6361da177e4SLinus Torvalds err_stop_fw:
637cdb73db0SGoldwyn Rodrigues 	mthca_UNMAP_FA(mdev);
638391e4deaSMichael S. Tsirkin 	mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
6391da177e4SLinus Torvalds 
6401da177e4SLinus Torvalds err_disable:
6411da177e4SLinus Torvalds 	if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))
642cdb73db0SGoldwyn Rodrigues 		mthca_DISABLE_LAM(mdev);
6431da177e4SLinus Torvalds 
6441da177e4SLinus Torvalds 	return err;
6451da177e4SLinus Torvalds }
6461da177e4SLinus Torvalds 
mthca_close_hca(struct mthca_dev * mdev)6472e8b981cSMichael S. Tsirkin static void mthca_close_hca(struct mthca_dev *mdev)
6482e8b981cSMichael S. Tsirkin {
649cdb73db0SGoldwyn Rodrigues 	mthca_CLOSE_HCA(mdev, 0);
6502e8b981cSMichael S. Tsirkin 
6512e8b981cSMichael S. Tsirkin 	if (mthca_is_memfree(mdev)) {
652aba7a22fSMichael S. Tsirkin 		mthca_free_icms(mdev);
6532e8b981cSMichael S. Tsirkin 
654cdb73db0SGoldwyn Rodrigues 		mthca_UNMAP_FA(mdev);
655391e4deaSMichael S. Tsirkin 		mthca_free_icm(mdev, mdev->fw.arbel.fw_icm, 0);
6562e8b981cSMichael S. Tsirkin 
6572e8b981cSMichael S. Tsirkin 		if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))
658cdb73db0SGoldwyn Rodrigues 			mthca_DISABLE_LAM(mdev);
6592e8b981cSMichael S. Tsirkin 	} else
660cdb73db0SGoldwyn Rodrigues 		mthca_SYS_DIS(mdev);
6612e8b981cSMichael S. Tsirkin }
6622e8b981cSMichael S. Tsirkin 
mthca_init_hca(struct mthca_dev * mdev)663f4f3d0f0SRoland Dreier static int mthca_init_hca(struct mthca_dev *mdev)
6641da177e4SLinus Torvalds {
6652e8b981cSMichael S. Tsirkin 	int err;
6662e8b981cSMichael S. Tsirkin 	struct mthca_adapter adapter;
6672e8b981cSMichael S. Tsirkin 
668d10ddbf6SRoland Dreier 	if (mthca_is_memfree(mdev))
6692e8b981cSMichael S. Tsirkin 		err = mthca_init_arbel(mdev);
6701da177e4SLinus Torvalds 	else
6712e8b981cSMichael S. Tsirkin 		err = mthca_init_tavor(mdev);
6722e8b981cSMichael S. Tsirkin 
6732e8b981cSMichael S. Tsirkin 	if (err)
6742e8b981cSMichael S. Tsirkin 		return err;
6752e8b981cSMichael S. Tsirkin 
676cdb73db0SGoldwyn Rodrigues 	err = mthca_QUERY_ADAPTER(mdev, &adapter);
6772e8b981cSMichael S. Tsirkin 	if (err) {
678cdb73db0SGoldwyn Rodrigues 		mthca_err(mdev, "QUERY_ADAPTER command returned %d, aborting.\n", err);
6792e8b981cSMichael S. Tsirkin 		goto err_close;
6802e8b981cSMichael S. Tsirkin 	}
6812e8b981cSMichael S. Tsirkin 
6822e8b981cSMichael S. Tsirkin 	mdev->eq_table.inta_pin = adapter.inta_pin;
6836ccef1deSJack Morgenstein 	if (!mthca_is_memfree(mdev))
6842e8b981cSMichael S. Tsirkin 		mdev->rev_id = adapter.revision_id;
6852e8b981cSMichael S. Tsirkin 	memcpy(mdev->board_id, adapter.board_id, sizeof mdev->board_id);
6862e8b981cSMichael S. Tsirkin 
6872e8b981cSMichael S. Tsirkin 	return 0;
6882e8b981cSMichael S. Tsirkin 
6892e8b981cSMichael S. Tsirkin err_close:
6902e8b981cSMichael S. Tsirkin 	mthca_close_hca(mdev);
6912e8b981cSMichael S. Tsirkin 	return err;
6921da177e4SLinus Torvalds }
6931da177e4SLinus Torvalds 
mthca_setup_hca(struct mthca_dev * dev)694f4f3d0f0SRoland Dreier static int mthca_setup_hca(struct mthca_dev *dev)
6951da177e4SLinus Torvalds {
6961da177e4SLinus Torvalds 	int err;
6971da177e4SLinus Torvalds 
6981da177e4SLinus Torvalds 	MTHCA_INIT_DOORBELL_LOCK(&dev->doorbell_lock);
6991da177e4SLinus Torvalds 
7001da177e4SLinus Torvalds 	err = mthca_init_uar_table(dev);
7011da177e4SLinus Torvalds 	if (err) {
7021da177e4SLinus Torvalds 		mthca_err(dev, "Failed to initialize "
7031da177e4SLinus Torvalds 			  "user access region table, aborting.\n");
7041da177e4SLinus Torvalds 		return err;
7051da177e4SLinus Torvalds 	}
7061da177e4SLinus Torvalds 
7071da177e4SLinus Torvalds 	err = mthca_uar_alloc(dev, &dev->driver_uar);
7081da177e4SLinus Torvalds 	if (err) {
7091da177e4SLinus Torvalds 		mthca_err(dev, "Failed to allocate driver access region, "
7101da177e4SLinus Torvalds 			  "aborting.\n");
7111da177e4SLinus Torvalds 		goto err_uar_table_free;
7121da177e4SLinus Torvalds 	}
7131da177e4SLinus Torvalds 
714eb4a7cbfSJohn L. Burr 	dev->kar = ioremap((phys_addr_t) dev->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
7151da177e4SLinus Torvalds 	if (!dev->kar) {
7161da177e4SLinus Torvalds 		mthca_err(dev, "Couldn't map kernel access region, "
7171da177e4SLinus Torvalds 			  "aborting.\n");
7181da177e4SLinus Torvalds 		err = -ENOMEM;
7191da177e4SLinus Torvalds 		goto err_uar_free;
7201da177e4SLinus Torvalds 	}
7211da177e4SLinus Torvalds 
7221da177e4SLinus Torvalds 	err = mthca_init_pd_table(dev);
7231da177e4SLinus Torvalds 	if (err) {
7241da177e4SLinus Torvalds 		mthca_err(dev, "Failed to initialize "
7251da177e4SLinus Torvalds 			  "protection domain table, aborting.\n");
7261da177e4SLinus Torvalds 		goto err_kar_unmap;
7271da177e4SLinus Torvalds 	}
7281da177e4SLinus Torvalds 
7291da177e4SLinus Torvalds 	err = mthca_init_mr_table(dev);
7301da177e4SLinus Torvalds 	if (err) {
7311da177e4SLinus Torvalds 		mthca_err(dev, "Failed to initialize "
7321da177e4SLinus Torvalds 			  "memory region table, aborting.\n");
7331da177e4SLinus Torvalds 		goto err_pd_table_free;
7341da177e4SLinus Torvalds 	}
7351da177e4SLinus Torvalds 
73699264c1eSRoland Dreier 	err = mthca_pd_alloc(dev, 1, &dev->driver_pd);
7371da177e4SLinus Torvalds 	if (err) {
7381da177e4SLinus Torvalds 		mthca_err(dev, "Failed to create driver PD, "
7391da177e4SLinus Torvalds 			  "aborting.\n");
7401da177e4SLinus Torvalds 		goto err_mr_table_free;
7411da177e4SLinus Torvalds 	}
7421da177e4SLinus Torvalds 
7431da177e4SLinus Torvalds 	err = mthca_init_eq_table(dev);
7441da177e4SLinus Torvalds 	if (err) {
7451da177e4SLinus Torvalds 		mthca_err(dev, "Failed to initialize "
7461da177e4SLinus Torvalds 			  "event queue table, aborting.\n");
7471da177e4SLinus Torvalds 		goto err_pd_free;
7481da177e4SLinus Torvalds 	}
7491da177e4SLinus Torvalds 
7501da177e4SLinus Torvalds 	err = mthca_cmd_use_events(dev);
7511da177e4SLinus Torvalds 	if (err) {
7521da177e4SLinus Torvalds 		mthca_err(dev, "Failed to switch to event-driven "
7531da177e4SLinus Torvalds 			  "firmware commands, aborting.\n");
7541da177e4SLinus Torvalds 		goto err_eq_table_free;
7551da177e4SLinus Torvalds 	}
7561da177e4SLinus Torvalds 
757cdb73db0SGoldwyn Rodrigues 	err = mthca_NOP(dev);
758cdb73db0SGoldwyn Rodrigues 	if (err) {
759e57895d3SAdrian Bunk 		if (dev->mthca_flags & MTHCA_FLAG_MSI_X) {
760017aadc4SMichael S. Tsirkin 			mthca_warn(dev, "NOP command failed to generate interrupt "
761017aadc4SMichael S. Tsirkin 				   "(IRQ %d).\n",
762e57895d3SAdrian Bunk 				   dev->eq_table.eq[MTHCA_EQ_CMD].msi_x_vector);
763e57895d3SAdrian Bunk 			mthca_warn(dev, "Trying again with MSI-X disabled.\n");
764017aadc4SMichael S. Tsirkin 		} else {
765017aadc4SMichael S. Tsirkin 			mthca_err(dev, "NOP command failed to generate interrupt "
766017aadc4SMichael S. Tsirkin 				  "(IRQ %d), aborting.\n",
767017aadc4SMichael S. Tsirkin 				  dev->pdev->irq);
7681da177e4SLinus Torvalds 			mthca_err(dev, "BIOS or ACPI interrupt routing problem?\n");
769017aadc4SMichael S. Tsirkin 		}
7701da177e4SLinus Torvalds 
7711da177e4SLinus Torvalds 		goto err_cmd_poll;
7721da177e4SLinus Torvalds 	}
7731da177e4SLinus Torvalds 
7741da177e4SLinus Torvalds 	mthca_dbg(dev, "NOP command IRQ test passed\n");
7751da177e4SLinus Torvalds 
7761da177e4SLinus Torvalds 	err = mthca_init_cq_table(dev);
7771da177e4SLinus Torvalds 	if (err) {
7781da177e4SLinus Torvalds 		mthca_err(dev, "Failed to initialize "
7791da177e4SLinus Torvalds 			  "completion queue table, aborting.\n");
7801da177e4SLinus Torvalds 		goto err_cmd_poll;
7811da177e4SLinus Torvalds 	}
7821da177e4SLinus Torvalds 
783ec34a922SRoland Dreier 	err = mthca_init_srq_table(dev);
784ec34a922SRoland Dreier 	if (err) {
785ec34a922SRoland Dreier 		mthca_err(dev, "Failed to initialize "
786ec34a922SRoland Dreier 			  "shared receive queue table, aborting.\n");
787ec34a922SRoland Dreier 		goto err_cq_table_free;
788ec34a922SRoland Dreier 	}
789ec34a922SRoland Dreier 
7901da177e4SLinus Torvalds 	err = mthca_init_qp_table(dev);
7911da177e4SLinus Torvalds 	if (err) {
7921da177e4SLinus Torvalds 		mthca_err(dev, "Failed to initialize "
7931da177e4SLinus Torvalds 			  "queue pair table, aborting.\n");
794ec34a922SRoland Dreier 		goto err_srq_table_free;
7951da177e4SLinus Torvalds 	}
7961da177e4SLinus Torvalds 
7971da177e4SLinus Torvalds 	err = mthca_init_av_table(dev);
7981da177e4SLinus Torvalds 	if (err) {
7991da177e4SLinus Torvalds 		mthca_err(dev, "Failed to initialize "
8001da177e4SLinus Torvalds 			  "address vector table, aborting.\n");
8011da177e4SLinus Torvalds 		goto err_qp_table_free;
8021da177e4SLinus Torvalds 	}
8031da177e4SLinus Torvalds 
8041da177e4SLinus Torvalds 	err = mthca_init_mcg_table(dev);
8051da177e4SLinus Torvalds 	if (err) {
8061da177e4SLinus Torvalds 		mthca_err(dev, "Failed to initialize "
8071da177e4SLinus Torvalds 			  "multicast group table, aborting.\n");
8081da177e4SLinus Torvalds 		goto err_av_table_free;
8091da177e4SLinus Torvalds 	}
8101da177e4SLinus Torvalds 
8111da177e4SLinus Torvalds 	return 0;
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds err_av_table_free:
8141da177e4SLinus Torvalds 	mthca_cleanup_av_table(dev);
8151da177e4SLinus Torvalds 
8161da177e4SLinus Torvalds err_qp_table_free:
8171da177e4SLinus Torvalds 	mthca_cleanup_qp_table(dev);
8181da177e4SLinus Torvalds 
819ec34a922SRoland Dreier err_srq_table_free:
820ec34a922SRoland Dreier 	mthca_cleanup_srq_table(dev);
821ec34a922SRoland Dreier 
8221da177e4SLinus Torvalds err_cq_table_free:
8231da177e4SLinus Torvalds 	mthca_cleanup_cq_table(dev);
8241da177e4SLinus Torvalds 
8251da177e4SLinus Torvalds err_cmd_poll:
8261da177e4SLinus Torvalds 	mthca_cmd_use_polling(dev);
8271da177e4SLinus Torvalds 
8281da177e4SLinus Torvalds err_eq_table_free:
8291da177e4SLinus Torvalds 	mthca_cleanup_eq_table(dev);
8301da177e4SLinus Torvalds 
8311da177e4SLinus Torvalds err_pd_free:
8321da177e4SLinus Torvalds 	mthca_pd_free(dev, &dev->driver_pd);
8331da177e4SLinus Torvalds 
8341da177e4SLinus Torvalds err_mr_table_free:
8351da177e4SLinus Torvalds 	mthca_cleanup_mr_table(dev);
8361da177e4SLinus Torvalds 
8371da177e4SLinus Torvalds err_pd_table_free:
8381da177e4SLinus Torvalds 	mthca_cleanup_pd_table(dev);
8391da177e4SLinus Torvalds 
8401da177e4SLinus Torvalds err_kar_unmap:
8411da177e4SLinus Torvalds 	iounmap(dev->kar);
8421da177e4SLinus Torvalds 
8431da177e4SLinus Torvalds err_uar_free:
8441da177e4SLinus Torvalds 	mthca_uar_free(dev, &dev->driver_uar);
8451da177e4SLinus Torvalds 
8461da177e4SLinus Torvalds err_uar_table_free:
8471da177e4SLinus Torvalds 	mthca_cleanup_uar_table(dev);
8481da177e4SLinus Torvalds 	return err;
8491da177e4SLinus Torvalds }
8501da177e4SLinus Torvalds 
mthca_enable_msi_x(struct mthca_dev * mdev)851f4f3d0f0SRoland Dreier static int mthca_enable_msi_x(struct mthca_dev *mdev)
8521da177e4SLinus Torvalds {
8531da177e4SLinus Torvalds 	int err;
8541da177e4SLinus Torvalds 
855f50cccddSChristoph Hellwig 	err = pci_alloc_irq_vectors(mdev->pdev, 3, 3, PCI_IRQ_MSIX);
856f50cccddSChristoph Hellwig 	if (err < 0)
8571da177e4SLinus Torvalds 		return err;
8581da177e4SLinus Torvalds 
859f50cccddSChristoph Hellwig 	mdev->eq_table.eq[MTHCA_EQ_COMP ].msi_x_vector =
860f50cccddSChristoph Hellwig 			pci_irq_vector(mdev->pdev, 0);
861f50cccddSChristoph Hellwig 	mdev->eq_table.eq[MTHCA_EQ_ASYNC].msi_x_vector =
862f50cccddSChristoph Hellwig 			pci_irq_vector(mdev->pdev, 1);
863f50cccddSChristoph Hellwig 	mdev->eq_table.eq[MTHCA_EQ_CMD  ].msi_x_vector =
864f50cccddSChristoph Hellwig 			pci_irq_vector(mdev->pdev, 2);
8651da177e4SLinus Torvalds 
8661da177e4SLinus Torvalds 	return 0;
8671da177e4SLinus Torvalds }
8681da177e4SLinus Torvalds 
86968a3c212SRoland Dreier /* Types of supported HCA */
87068a3c212SRoland Dreier enum {
87168a3c212SRoland Dreier 	TAVOR,			/* MT23108                        */
87268a3c212SRoland Dreier 	ARBEL_COMPAT,		/* MT25208 in Tavor compat mode   */
87368a3c212SRoland Dreier 	ARBEL_NATIVE,		/* MT25208 with extended features */
87468a3c212SRoland Dreier 	SINAI			/* MT25204 */
87568a3c212SRoland Dreier };
87668a3c212SRoland Dreier 
87768a3c212SRoland Dreier #define MTHCA_FW_VER(major, minor, subminor) \
87868a3c212SRoland Dreier 	(((u64) (major) << 32) | ((u64) (minor) << 16) | (u64) (subminor))
87968a3c212SRoland Dreier 
88068a3c212SRoland Dreier static struct {
88168a3c212SRoland Dreier 	u64 latest_fw;
882651eaac9SEli Cohen 	u32 flags;
88368a3c212SRoland Dreier } mthca_hca_table[] = {
8843f114853SRoland Dreier 	[TAVOR]        = { .latest_fw = MTHCA_FW_VER(3, 5, 0),
885651eaac9SEli Cohen 			   .flags     = 0 },
8863f114853SRoland Dreier 	[ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 8, 200),
887651eaac9SEli Cohen 			   .flags     = MTHCA_FLAG_PCIE },
888950529e5SRoland Dreier 	[ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 3, 0),
889651eaac9SEli Cohen 			   .flags     = MTHCA_FLAG_MEMFREE |
890651eaac9SEli Cohen 					MTHCA_FLAG_PCIE },
8913f114853SRoland Dreier 	[SINAI]        = { .latest_fw = MTHCA_FW_VER(1, 2, 0),
892651eaac9SEli Cohen 			   .flags     = MTHCA_FLAG_MEMFREE |
893651eaac9SEli Cohen 					MTHCA_FLAG_PCIE    |
894651eaac9SEli Cohen 					MTHCA_FLAG_SINAI_OPT }
89568a3c212SRoland Dreier };
89668a3c212SRoland Dreier 
__mthca_init_one(struct pci_dev * pdev,int hca_type)897b3b30f5eSJack Morgenstein static int __mthca_init_one(struct pci_dev *pdev, int hca_type)
8981da177e4SLinus Torvalds {
8991da177e4SLinus Torvalds 	int ddr_hidden = 0;
9001da177e4SLinus Torvalds 	int err;
9011da177e4SLinus Torvalds 	struct mthca_dev *mdev;
9021da177e4SLinus Torvalds 
903982245f0SAdrian Bunk 	printk(KERN_INFO PFX "Initializing %s\n",
904982245f0SAdrian Bunk 	       pci_name(pdev));
9051da177e4SLinus Torvalds 
9061da177e4SLinus Torvalds 	err = pci_enable_device(pdev);
9071da177e4SLinus Torvalds 	if (err) {
9081da177e4SLinus Torvalds 		dev_err(&pdev->dev, "Cannot enable PCI device, "
9091da177e4SLinus Torvalds 			"aborting.\n");
9101da177e4SLinus Torvalds 		return err;
9111da177e4SLinus Torvalds 	}
9121da177e4SLinus Torvalds 
9131da177e4SLinus Torvalds 	/*
9141da177e4SLinus Torvalds 	 * Check for BARs.  We expect 0: 1MB, 2: 8MB, 4: DDR (may not
9151da177e4SLinus Torvalds 	 * be present)
9161da177e4SLinus Torvalds 	 */
9171da177e4SLinus Torvalds 	if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
9181da177e4SLinus Torvalds 	    pci_resource_len(pdev, 0) != 1 << 20) {
919177214afSBernhard Fischer 		dev_err(&pdev->dev, "Missing DCS, aborting.\n");
9201da177e4SLinus Torvalds 		err = -ENODEV;
9211da177e4SLinus Torvalds 		goto err_disable_pdev;
9221da177e4SLinus Torvalds 	}
923cbd2981aSMichael S. Tsirkin 	if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
924177214afSBernhard Fischer 		dev_err(&pdev->dev, "Missing UAR, aborting.\n");
9251da177e4SLinus Torvalds 		err = -ENODEV;
9261da177e4SLinus Torvalds 		goto err_disable_pdev;
9271da177e4SLinus Torvalds 	}
9281da177e4SLinus Torvalds 	if (!(pci_resource_flags(pdev, 4) & IORESOURCE_MEM))
9291da177e4SLinus Torvalds 		ddr_hidden = 1;
9301da177e4SLinus Torvalds 
931208dde28SRoland Dreier 	err = pci_request_regions(pdev, DRV_NAME);
9321da177e4SLinus Torvalds 	if (err) {
9331da177e4SLinus Torvalds 		dev_err(&pdev->dev, "Cannot obtain PCI resources, "
9341da177e4SLinus Torvalds 			"aborting.\n");
9351da177e4SLinus Torvalds 		goto err_disable_pdev;
9361da177e4SLinus Torvalds 	}
9371da177e4SLinus Torvalds 
9381da177e4SLinus Torvalds 	pci_set_master(pdev);
9391da177e4SLinus Torvalds 
9403f69f4e0SChristophe JAILLET 	err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9411da177e4SLinus Torvalds 	if (err) {
9421da177e4SLinus Torvalds 		dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
9431da177e4SLinus Torvalds 		goto err_free_res;
9441da177e4SLinus Torvalds 	}
9451da177e4SLinus Torvalds 
9467f9e5c48SDavid Dillow 	/* We can handle large RDMA requests, so allow larger segments. */
9477f9e5c48SDavid Dillow 	dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024);
9487f9e5c48SDavid Dillow 
949459cc69fSLeon Romanovsky 	mdev = ib_alloc_device(mthca_dev, ib_dev);
9501da177e4SLinus Torvalds 	if (!mdev) {
9511da177e4SLinus Torvalds 		dev_err(&pdev->dev, "Device struct alloc failed, "
9521da177e4SLinus Torvalds 			"aborting.\n");
9531da177e4SLinus Torvalds 		err = -ENOMEM;
9541da177e4SLinus Torvalds 		goto err_free_res;
9551da177e4SLinus Torvalds 	}
9561da177e4SLinus Torvalds 
9571da177e4SLinus Torvalds 	mdev->pdev = pdev;
9581da177e4SLinus Torvalds 
959b3b30f5eSJack Morgenstein 	mdev->mthca_flags = mthca_hca_table[hca_type].flags;
9601da177e4SLinus Torvalds 	if (ddr_hidden)
9611da177e4SLinus Torvalds 		mdev->mthca_flags |= MTHCA_FLAG_DDR_HIDDEN;
9621da177e4SLinus Torvalds 
9631da177e4SLinus Torvalds 	/*
9641da177e4SLinus Torvalds 	 * Now reset the HCA before we touch the PCI capabilities or
9651da177e4SLinus Torvalds 	 * attempt a firmware command, since a boot ROM may have left
9661da177e4SLinus Torvalds 	 * the HCA in an undefined state.
9671da177e4SLinus Torvalds 	 */
9681da177e4SLinus Torvalds 	err = mthca_reset(mdev);
9691da177e4SLinus Torvalds 	if (err) {
9701da177e4SLinus Torvalds 		mthca_err(mdev, "Failed to reset HCA, aborting.\n");
9711da177e4SLinus Torvalds 		goto err_free_dev;
9721da177e4SLinus Torvalds 	}
9731da177e4SLinus Torvalds 
97439f24956SWei Yongjun 	err = mthca_cmd_init(mdev);
97539f24956SWei Yongjun 	if (err) {
97680fd8238SRoland Dreier 		mthca_err(mdev, "Failed to init command interface, aborting.\n");
9771da177e4SLinus Torvalds 		goto err_free_dev;
9781da177e4SLinus Torvalds 	}
9791da177e4SLinus Torvalds 
9801da177e4SLinus Torvalds 	err = mthca_tune_pci(mdev);
9811da177e4SLinus Torvalds 	if (err)
98280fd8238SRoland Dreier 		goto err_cmd;
9831da177e4SLinus Torvalds 
9841da177e4SLinus Torvalds 	err = mthca_init_hca(mdev);
9851da177e4SLinus Torvalds 	if (err)
98680fd8238SRoland Dreier 		goto err_cmd;
9871da177e4SLinus Torvalds 
988b3b30f5eSJack Morgenstein 	if (mdev->fw_ver < mthca_hca_table[hca_type].latest_fw) {
989e4daf738SRoland Dreier 		mthca_warn(mdev, "HCA FW version %d.%d.%03d is old (%d.%d.%03d is current).\n",
99068a3c212SRoland Dreier 			   (int) (mdev->fw_ver >> 32), (int) (mdev->fw_ver >> 16) & 0xffff,
99168a3c212SRoland Dreier 			   (int) (mdev->fw_ver & 0xffff),
992b3b30f5eSJack Morgenstein 			   (int) (mthca_hca_table[hca_type].latest_fw >> 32),
993b3b30f5eSJack Morgenstein 			   (int) (mthca_hca_table[hca_type].latest_fw >> 16) & 0xffff,
994b3b30f5eSJack Morgenstein 			   (int) (mthca_hca_table[hca_type].latest_fw & 0xffff));
99568a3c212SRoland Dreier 		mthca_warn(mdev, "If you have problems, try updating your HCA FW.\n");
99668a3c212SRoland Dreier 	}
99768a3c212SRoland Dreier 
998017aadc4SMichael S. Tsirkin 	if (msi_x && !mthca_enable_msi_x(mdev))
999017aadc4SMichael S. Tsirkin 		mdev->mthca_flags |= MTHCA_FLAG_MSI_X;
1000017aadc4SMichael S. Tsirkin 
10011da177e4SLinus Torvalds 	err = mthca_setup_hca(mdev);
1002e57895d3SAdrian Bunk 	if (err == -EBUSY && (mdev->mthca_flags & MTHCA_FLAG_MSI_X)) {
1003f50cccddSChristoph Hellwig 		pci_free_irq_vectors(pdev);
1004e57895d3SAdrian Bunk 		mdev->mthca_flags &= ~MTHCA_FLAG_MSI_X;
1005017aadc4SMichael S. Tsirkin 
1006017aadc4SMichael S. Tsirkin 		err = mthca_setup_hca(mdev);
1007017aadc4SMichael S. Tsirkin 	}
1008017aadc4SMichael S. Tsirkin 
10091da177e4SLinus Torvalds 	if (err)
10101da177e4SLinus Torvalds 		goto err_close;
10111da177e4SLinus Torvalds 
10121da177e4SLinus Torvalds 	err = mthca_register_device(mdev);
10131da177e4SLinus Torvalds 	if (err)
10141da177e4SLinus Torvalds 		goto err_cleanup;
10151da177e4SLinus Torvalds 
10161da177e4SLinus Torvalds 	err = mthca_create_agents(mdev);
10171da177e4SLinus Torvalds 	if (err)
10181da177e4SLinus Torvalds 		goto err_unregister;
10191da177e4SLinus Torvalds 
10201da177e4SLinus Torvalds 	pci_set_drvdata(pdev, mdev);
1021b3b30f5eSJack Morgenstein 	mdev->hca_type = hca_type;
10221da177e4SLinus Torvalds 
1023d8410647SJack Morgenstein 	mdev->active = true;
1024d8410647SJack Morgenstein 
10251da177e4SLinus Torvalds 	return 0;
10261da177e4SLinus Torvalds 
10271da177e4SLinus Torvalds err_unregister:
10281da177e4SLinus Torvalds 	mthca_unregister_device(mdev);
10291da177e4SLinus Torvalds 
10301da177e4SLinus Torvalds err_cleanup:
10311da177e4SLinus Torvalds 	mthca_cleanup_mcg_table(mdev);
10321da177e4SLinus Torvalds 	mthca_cleanup_av_table(mdev);
10331da177e4SLinus Torvalds 	mthca_cleanup_qp_table(mdev);
1034ec34a922SRoland Dreier 	mthca_cleanup_srq_table(mdev);
10351da177e4SLinus Torvalds 	mthca_cleanup_cq_table(mdev);
10361da177e4SLinus Torvalds 	mthca_cmd_use_polling(mdev);
10371da177e4SLinus Torvalds 	mthca_cleanup_eq_table(mdev);
10381da177e4SLinus Torvalds 
10391da177e4SLinus Torvalds 	mthca_pd_free(mdev, &mdev->driver_pd);
10401da177e4SLinus Torvalds 
10411da177e4SLinus Torvalds 	mthca_cleanup_mr_table(mdev);
10421da177e4SLinus Torvalds 	mthca_cleanup_pd_table(mdev);
10431da177e4SLinus Torvalds 	mthca_cleanup_uar_table(mdev);
10441da177e4SLinus Torvalds 
10451da177e4SLinus Torvalds err_close:
1046017aadc4SMichael S. Tsirkin 	if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
1047f50cccddSChristoph Hellwig 		pci_free_irq_vectors(pdev);
1048017aadc4SMichael S. Tsirkin 
10491da177e4SLinus Torvalds 	mthca_close_hca(mdev);
10501da177e4SLinus Torvalds 
105180fd8238SRoland Dreier err_cmd:
105280fd8238SRoland Dreier 	mthca_cmd_cleanup(mdev);
10531da177e4SLinus Torvalds 
10541da177e4SLinus Torvalds err_free_dev:
10551da177e4SLinus Torvalds 	ib_dealloc_device(&mdev->ib_dev);
10561da177e4SLinus Torvalds 
10571da177e4SLinus Torvalds err_free_res:
1058208dde28SRoland Dreier 	pci_release_regions(pdev);
10591da177e4SLinus Torvalds 
10601da177e4SLinus Torvalds err_disable_pdev:
10611da177e4SLinus Torvalds 	pci_disable_device(pdev);
10621da177e4SLinus Torvalds 	pci_set_drvdata(pdev, NULL);
10631da177e4SLinus Torvalds 	return err;
10641da177e4SLinus Torvalds }
10651da177e4SLinus Torvalds 
__mthca_remove_one(struct pci_dev * pdev)1066b3b30f5eSJack Morgenstein static void __mthca_remove_one(struct pci_dev *pdev)
10671da177e4SLinus Torvalds {
10681da177e4SLinus Torvalds 	struct mthca_dev *mdev = pci_get_drvdata(pdev);
10691da177e4SLinus Torvalds 	int p;
10701da177e4SLinus Torvalds 
10711da177e4SLinus Torvalds 	if (mdev) {
10721da177e4SLinus Torvalds 		mthca_free_agents(mdev);
10731da177e4SLinus Torvalds 		mthca_unregister_device(mdev);
10741da177e4SLinus Torvalds 
10751da177e4SLinus Torvalds 		for (p = 1; p <= mdev->limits.num_ports; ++p)
1076cdb73db0SGoldwyn Rodrigues 			mthca_CLOSE_IB(mdev, p);
10771da177e4SLinus Torvalds 
10781da177e4SLinus Torvalds 		mthca_cleanup_mcg_table(mdev);
10791da177e4SLinus Torvalds 		mthca_cleanup_av_table(mdev);
10801da177e4SLinus Torvalds 		mthca_cleanup_qp_table(mdev);
1081ec34a922SRoland Dreier 		mthca_cleanup_srq_table(mdev);
10821da177e4SLinus Torvalds 		mthca_cleanup_cq_table(mdev);
10831da177e4SLinus Torvalds 		mthca_cmd_use_polling(mdev);
10841da177e4SLinus Torvalds 		mthca_cleanup_eq_table(mdev);
10851da177e4SLinus Torvalds 
10861da177e4SLinus Torvalds 		mthca_pd_free(mdev, &mdev->driver_pd);
10871da177e4SLinus Torvalds 
10881da177e4SLinus Torvalds 		mthca_cleanup_mr_table(mdev);
10891da177e4SLinus Torvalds 		mthca_cleanup_pd_table(mdev);
10901da177e4SLinus Torvalds 
10911da177e4SLinus Torvalds 		iounmap(mdev->kar);
10921da177e4SLinus Torvalds 		mthca_uar_free(mdev, &mdev->driver_uar);
10931da177e4SLinus Torvalds 		mthca_cleanup_uar_table(mdev);
10941da177e4SLinus Torvalds 		mthca_close_hca(mdev);
109580fd8238SRoland Dreier 		mthca_cmd_cleanup(mdev);
10961da177e4SLinus Torvalds 
10971da177e4SLinus Torvalds 		if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
1098f50cccddSChristoph Hellwig 			pci_free_irq_vectors(pdev);
10991da177e4SLinus Torvalds 
11001da177e4SLinus Torvalds 		ib_dealloc_device(&mdev->ib_dev);
1101208dde28SRoland Dreier 		pci_release_regions(pdev);
11021da177e4SLinus Torvalds 		pci_disable_device(pdev);
11031da177e4SLinus Torvalds 		pci_set_drvdata(pdev, NULL);
11041da177e4SLinus Torvalds 	}
11051da177e4SLinus Torvalds }
11061da177e4SLinus Torvalds 
__mthca_restart_one(struct pci_dev * pdev)1107b3b30f5eSJack Morgenstein int __mthca_restart_one(struct pci_dev *pdev)
1108b3b30f5eSJack Morgenstein {
1109b3b30f5eSJack Morgenstein 	struct mthca_dev *mdev;
1110de57c9f1SAli Ayoub 	int hca_type;
1111b3b30f5eSJack Morgenstein 
1112b3b30f5eSJack Morgenstein 	mdev = pci_get_drvdata(pdev);
1113b3b30f5eSJack Morgenstein 	if (!mdev)
1114b3b30f5eSJack Morgenstein 		return -ENODEV;
1115de57c9f1SAli Ayoub 	hca_type = mdev->hca_type;
1116b3b30f5eSJack Morgenstein 	__mthca_remove_one(pdev);
1117de57c9f1SAli Ayoub 	return __mthca_init_one(pdev, hca_type);
1118b3b30f5eSJack Morgenstein }
1119b3b30f5eSJack Morgenstein 
mthca_init_one(struct pci_dev * pdev,const struct pci_device_id * id)11201e6d9abeSGreg Kroah-Hartman static int mthca_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
1121b3b30f5eSJack Morgenstein {
1122b3b30f5eSJack Morgenstein 	int ret;
1123b3b30f5eSJack Morgenstein 
1124b3b30f5eSJack Morgenstein 	mutex_lock(&mthca_device_mutex);
1125b3b30f5eSJack Morgenstein 
1126f1aa78b2SMarcin Slusarz 	printk_once(KERN_INFO "%s", mthca_version);
1127b3b30f5eSJack Morgenstein 
1128b3b30f5eSJack Morgenstein 	if (id->driver_data >= ARRAY_SIZE(mthca_hca_table)) {
1129b3b30f5eSJack Morgenstein 		printk(KERN_ERR PFX "%s has invalid driver data %lx\n",
1130b3b30f5eSJack Morgenstein 		       pci_name(pdev), id->driver_data);
1131b3b30f5eSJack Morgenstein 		mutex_unlock(&mthca_device_mutex);
1132b3b30f5eSJack Morgenstein 		return -ENODEV;
1133b3b30f5eSJack Morgenstein 	}
1134b3b30f5eSJack Morgenstein 
1135b3b30f5eSJack Morgenstein 	ret = __mthca_init_one(pdev, id->driver_data);
1136b3b30f5eSJack Morgenstein 
1137b3b30f5eSJack Morgenstein 	mutex_unlock(&mthca_device_mutex);
1138b3b30f5eSJack Morgenstein 
1139b3b30f5eSJack Morgenstein 	return ret;
1140b3b30f5eSJack Morgenstein }
1141b3b30f5eSJack Morgenstein 
mthca_remove_one(struct pci_dev * pdev)11421e6d9abeSGreg Kroah-Hartman static void mthca_remove_one(struct pci_dev *pdev)
1143b3b30f5eSJack Morgenstein {
1144b3b30f5eSJack Morgenstein 	mutex_lock(&mthca_device_mutex);
1145b3b30f5eSJack Morgenstein 	__mthca_remove_one(pdev);
1146b3b30f5eSJack Morgenstein 	mutex_unlock(&mthca_device_mutex);
1147b3b30f5eSJack Morgenstein }
1148b3b30f5eSJack Morgenstein 
1149e0604df1SArvind Yadav static const struct pci_device_id mthca_pci_table[] = {
11501da177e4SLinus Torvalds 	{ PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_TAVOR),
11511da177e4SLinus Torvalds 	  .driver_data = TAVOR },
11521da177e4SLinus Torvalds 	{ PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_TAVOR),
11531da177e4SLinus Torvalds 	  .driver_data = TAVOR },
11541da177e4SLinus Torvalds 	{ PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT),
11551da177e4SLinus Torvalds 	  .driver_data = ARBEL_COMPAT },
11561da177e4SLinus Torvalds 	{ PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT),
11571da177e4SLinus Torvalds 	  .driver_data = ARBEL_COMPAT },
11581da177e4SLinus Torvalds 	{ PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_ARBEL),
11591da177e4SLinus Torvalds 	  .driver_data = ARBEL_NATIVE },
11601da177e4SLinus Torvalds 	{ PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_ARBEL),
11611da177e4SLinus Torvalds 	  .driver_data = ARBEL_NATIVE },
116268a3c212SRoland Dreier 	{ PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_SINAI),
116368a3c212SRoland Dreier 	  .driver_data = SINAI },
116468a3c212SRoland Dreier 	{ PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_SINAI),
116568a3c212SRoland Dreier 	  .driver_data = SINAI },
116668a3c212SRoland Dreier 	{ PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_SINAI_OLD),
116768a3c212SRoland Dreier 	  .driver_data = SINAI },
116868a3c212SRoland Dreier 	{ PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_SINAI_OLD),
116968a3c212SRoland Dreier 	  .driver_data = SINAI },
11701da177e4SLinus Torvalds 	{ 0, }
11711da177e4SLinus Torvalds };
11721da177e4SLinus Torvalds 
11731da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, mthca_pci_table);
11741da177e4SLinus Torvalds 
11751da177e4SLinus Torvalds static struct pci_driver mthca_driver = {
1176177214afSBernhard Fischer 	.name		= DRV_NAME,
11771da177e4SLinus Torvalds 	.id_table	= mthca_pci_table,
11781da177e4SLinus Torvalds 	.probe		= mthca_init_one,
11791e6d9abeSGreg Kroah-Hartman 	.remove		= mthca_remove_one,
11801da177e4SLinus Torvalds };
11811da177e4SLinus Torvalds 
__mthca_check_profile_val(const char * name,int * pval,int pval_default)118282da703eSLeonid Arsh static void __init __mthca_check_profile_val(const char *name, int *pval,
118382da703eSLeonid Arsh 					     int pval_default)
118482da703eSLeonid Arsh {
118582da703eSLeonid Arsh 	/* value must be positive and power of 2 */
118682da703eSLeonid Arsh 	int old_pval = *pval;
118782da703eSLeonid Arsh 
118882da703eSLeonid Arsh 	if (old_pval <= 0)
118982da703eSLeonid Arsh 		*pval = pval_default;
119082da703eSLeonid Arsh 	else
119182da703eSLeonid Arsh 		*pval = roundup_pow_of_two(old_pval);
119282da703eSLeonid Arsh 
119382da703eSLeonid Arsh 	if (old_pval != *pval) {
119482da703eSLeonid Arsh 		printk(KERN_WARNING PFX "Invalid value %d for %s in module parameter.\n",
119582da703eSLeonid Arsh 		       old_pval, name);
119682da703eSLeonid Arsh 		printk(KERN_WARNING PFX "Corrected %s to %d.\n", name, *pval);
119782da703eSLeonid Arsh 	}
119882da703eSLeonid Arsh }
119982da703eSLeonid Arsh 
120082da703eSLeonid Arsh #define mthca_check_profile_val(name, default)				\
120182da703eSLeonid Arsh 	__mthca_check_profile_val(#name, &hca_profile.name, default)
120282da703eSLeonid Arsh 
mthca_validate_profile(void)120382da703eSLeonid Arsh static void __init mthca_validate_profile(void)
120482da703eSLeonid Arsh {
120582da703eSLeonid Arsh 	mthca_check_profile_val(num_qp,            MTHCA_DEFAULT_NUM_QP);
120682da703eSLeonid Arsh 	mthca_check_profile_val(rdb_per_qp,        MTHCA_DEFAULT_RDB_PER_QP);
120782da703eSLeonid Arsh 	mthca_check_profile_val(num_cq,            MTHCA_DEFAULT_NUM_CQ);
120882da703eSLeonid Arsh 	mthca_check_profile_val(num_mcg, 	   MTHCA_DEFAULT_NUM_MCG);
120982da703eSLeonid Arsh 	mthca_check_profile_val(num_mpt, 	   MTHCA_DEFAULT_NUM_MPT);
121082da703eSLeonid Arsh 	mthca_check_profile_val(num_mtt, 	   MTHCA_DEFAULT_NUM_MTT);
121182da703eSLeonid Arsh 	mthca_check_profile_val(num_udav,          MTHCA_DEFAULT_NUM_UDAV);
121282da703eSLeonid Arsh 	mthca_check_profile_val(fmr_reserved_mtts, MTHCA_DEFAULT_NUM_RESERVED_MTTS);
121382da703eSLeonid Arsh 
121482da703eSLeonid Arsh 	if (hca_profile.fmr_reserved_mtts >= hca_profile.num_mtt) {
121582da703eSLeonid Arsh 		printk(KERN_WARNING PFX "Invalid fmr_reserved_mtts module parameter %d.\n",
121682da703eSLeonid Arsh 		       hca_profile.fmr_reserved_mtts);
121782da703eSLeonid Arsh 		printk(KERN_WARNING PFX "(Must be smaller than num_mtt %d)\n",
121882da703eSLeonid Arsh 		       hca_profile.num_mtt);
121982da703eSLeonid Arsh 		hca_profile.fmr_reserved_mtts = hca_profile.num_mtt / 2;
122082da703eSLeonid Arsh 		printk(KERN_WARNING PFX "Corrected fmr_reserved_mtts to %d.\n",
122182da703eSLeonid Arsh 		       hca_profile.fmr_reserved_mtts);
122282da703eSLeonid Arsh 	}
1223c1f67a88SEli Cohen 
1224c1f67a88SEli Cohen 	if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 5)) {
1225c1f67a88SEli Cohen 		printk(KERN_WARNING PFX "bad log_mtts_per_seg (%d). Using default - %d\n",
1226c1f67a88SEli Cohen 		       log_mtts_per_seg, ilog2(MTHCA_MTT_SEG_SIZE / 8));
1227c1f67a88SEli Cohen 		log_mtts_per_seg = ilog2(MTHCA_MTT_SEG_SIZE / 8);
1228c1f67a88SEli Cohen 	}
122982da703eSLeonid Arsh }
123082da703eSLeonid Arsh 
mthca_init(void)12311da177e4SLinus Torvalds static int __init mthca_init(void)
12321da177e4SLinus Torvalds {
12331da177e4SLinus Torvalds 	int ret;
12341da177e4SLinus Torvalds 
123582da703eSLeonid Arsh 	mthca_validate_profile();
123682da703eSLeonid Arsh 
1237b3b30f5eSJack Morgenstein 	ret = mthca_catas_init();
1238b3b30f5eSJack Morgenstein 	if (ret)
1239b3b30f5eSJack Morgenstein 		return ret;
1240b3b30f5eSJack Morgenstein 
12411da177e4SLinus Torvalds 	ret = pci_register_driver(&mthca_driver);
1242b3b30f5eSJack Morgenstein 	if (ret < 0) {
1243b3b30f5eSJack Morgenstein 		mthca_catas_cleanup();
1244b3b30f5eSJack Morgenstein 		return ret;
1245b3b30f5eSJack Morgenstein 	}
1246b3b30f5eSJack Morgenstein 
1247b3b30f5eSJack Morgenstein 	return 0;
12481da177e4SLinus Torvalds }
12491da177e4SLinus Torvalds 
mthca_cleanup(void)12501da177e4SLinus Torvalds static void __exit mthca_cleanup(void)
12511da177e4SLinus Torvalds {
12521da177e4SLinus Torvalds 	pci_unregister_driver(&mthca_driver);
1253b3b30f5eSJack Morgenstein 	mthca_catas_cleanup();
12541da177e4SLinus Torvalds }
12551da177e4SLinus Torvalds 
12561da177e4SLinus Torvalds module_init(mthca_init);
12571da177e4SLinus Torvalds module_exit(mthca_cleanup);
1258