IB/mthca: Fix offset in query_gid method
[linux-2.6] / drivers / infiniband / hw / mthca / mthca_main.c
1 /*
2  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
3  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4  * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  * $Id: mthca_main.c 1396 2004-12-28 04:10:27Z roland $
35  */
36
37 #include <linux/config.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/errno.h>
41 #include <linux/pci.h>
42 #include <linux/interrupt.h>
43
44 #include "mthca_dev.h"
45 #include "mthca_config_reg.h"
46 #include "mthca_cmd.h"
47 #include "mthca_profile.h"
48 #include "mthca_memfree.h"
49
50 MODULE_AUTHOR("Roland Dreier");
51 MODULE_DESCRIPTION("Mellanox InfiniBand HCA low-level driver");
52 MODULE_LICENSE("Dual BSD/GPL");
53 MODULE_VERSION(DRV_VERSION);
54
55 #ifdef CONFIG_INFINIBAND_MTHCA_DEBUG
56
57 int mthca_debug_level = 0;
58 module_param_named(debug_level, mthca_debug_level, int, 0644);
59 MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
60
61 #endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */
62
63 #ifdef CONFIG_PCI_MSI
64
65 static int msi_x = 0;
66 module_param(msi_x, int, 0444);
67 MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
68
69 static int msi = 0;
70 module_param(msi, int, 0444);
71 MODULE_PARM_DESC(msi, "attempt to use MSI if nonzero");
72
73 #else /* CONFIG_PCI_MSI */
74
75 #define msi_x (0)
76 #define msi   (0)
77
78 #endif /* CONFIG_PCI_MSI */
79
80 static int tune_pci = 0;
81 module_param(tune_pci, int, 0444);
82 MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero");
83
84 static const char mthca_version[] __devinitdata =
85         DRV_NAME ": Mellanox InfiniBand HCA driver v"
86         DRV_VERSION " (" DRV_RELDATE ")\n";
87
88 static struct mthca_profile default_profile = {
89         .num_qp            = 1 << 16,
90         .rdb_per_qp        = 4,
91         .num_cq            = 1 << 16,
92         .num_mcg           = 1 << 13,
93         .num_mpt           = 1 << 17,
94         .num_mtt           = 1 << 20,
95         .num_udav          = 1 << 15,   /* Tavor only */
96         .fmr_reserved_mtts = 1 << 18,   /* Tavor only */
97         .uarc_size         = 1 << 18,   /* Arbel only */
98 };
99
100 static int __devinit mthca_tune_pci(struct mthca_dev *mdev)
101 {
102         int cap;
103         u16 val;
104
105         if (!tune_pci)
106                 return 0;
107
108         /* First try to max out Read Byte Count */
109         cap = pci_find_capability(mdev->pdev, PCI_CAP_ID_PCIX);
110         if (cap) {
111                 if (pci_read_config_word(mdev->pdev, cap + PCI_X_CMD, &val)) {
112                         mthca_err(mdev, "Couldn't read PCI-X command register, "
113                                   "aborting.\n");
114                         return -ENODEV;
115                 }
116                 val = (val & ~PCI_X_CMD_MAX_READ) | (3 << 2);
117                 if (pci_write_config_word(mdev->pdev, cap + PCI_X_CMD, val)) {
118                         mthca_err(mdev, "Couldn't write PCI-X command register, "
119                                   "aborting.\n");
120                         return -ENODEV;
121                 }
122         } else if (!(mdev->mthca_flags & MTHCA_FLAG_PCIE))
123                 mthca_info(mdev, "No PCI-X capability, not setting RBC.\n");
124
125         cap = pci_find_capability(mdev->pdev, PCI_CAP_ID_EXP);
126         if (cap) {
127                 if (pci_read_config_word(mdev->pdev, cap + PCI_EXP_DEVCTL, &val)) {
128                         mthca_err(mdev, "Couldn't read PCI Express device control "
129                                   "register, aborting.\n");
130                         return -ENODEV;
131                 }
132                 val = (val & ~PCI_EXP_DEVCTL_READRQ) | (5 << 12);
133                 if (pci_write_config_word(mdev->pdev, cap + PCI_EXP_DEVCTL, val)) {
134                         mthca_err(mdev, "Couldn't write PCI Express device control "
135                                   "register, aborting.\n");
136                         return -ENODEV;
137                 }
138         } else if (mdev->mthca_flags & MTHCA_FLAG_PCIE)
139                 mthca_info(mdev, "No PCI Express capability, "
140                            "not setting Max Read Request Size.\n");
141
142         return 0;
143 }
144
145 static int __devinit mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim *dev_lim)
146 {
147         int err;
148         u8 status;
149
150         err = mthca_QUERY_DEV_LIM(mdev, dev_lim, &status);
151         if (err) {
152                 mthca_err(mdev, "QUERY_DEV_LIM command failed, aborting.\n");
153                 return err;
154         }
155         if (status) {
156                 mthca_err(mdev, "QUERY_DEV_LIM returned status 0x%02x, "
157                           "aborting.\n", status);
158                 return -EINVAL;
159         }
160         if (dev_lim->min_page_sz > PAGE_SIZE) {
161                 mthca_err(mdev, "HCA minimum page size of %d bigger than "
162                           "kernel PAGE_SIZE of %ld, aborting.\n",
163                           dev_lim->min_page_sz, PAGE_SIZE);
164                 return -ENODEV;
165         }
166         if (dev_lim->num_ports > MTHCA_MAX_PORTS) {
167                 mthca_err(mdev, "HCA has %d ports, but we only support %d, "
168                           "aborting.\n",
169                           dev_lim->num_ports, MTHCA_MAX_PORTS);
170                 return -ENODEV;
171         }
172
173         if (dev_lim->uar_size > pci_resource_len(mdev->pdev, 2)) {
174                 mthca_err(mdev, "HCA reported UAR size of 0x%x bigger than "
175                           "PCI resource 2 size of 0x%lx, aborting.\n",
176                           dev_lim->uar_size, pci_resource_len(mdev->pdev, 2));
177                 return -ENODEV;
178         }
179
180         mdev->limits.num_ports          = dev_lim->num_ports;
181         mdev->limits.vl_cap             = dev_lim->max_vl;
182         mdev->limits.mtu_cap            = dev_lim->max_mtu;
183         mdev->limits.gid_table_len      = dev_lim->max_gids;
184         mdev->limits.pkey_table_len     = dev_lim->max_pkeys;
185         mdev->limits.local_ca_ack_delay = dev_lim->local_ca_ack_delay;
186         mdev->limits.max_sg             = dev_lim->max_sg;
187         mdev->limits.max_wqes           = dev_lim->max_qp_sz;
188         mdev->limits.max_qp_init_rdma   = dev_lim->max_requester_per_qp;
189         mdev->limits.reserved_qps       = dev_lim->reserved_qps;
190         mdev->limits.max_srq_wqes       = dev_lim->max_srq_sz;
191         mdev->limits.reserved_srqs      = dev_lim->reserved_srqs;
192         mdev->limits.reserved_eecs      = dev_lim->reserved_eecs;
193         mdev->limits.max_desc_sz        = dev_lim->max_desc_sz;
194         mdev->limits.max_srq_sge        = mthca_max_srq_sge(mdev);
195         /*
196          * Subtract 1 from the limit because we need to allocate a
197          * spare CQE so the HCA HW can tell the difference between an
198          * empty CQ and a full CQ.
199          */
200         mdev->limits.max_cqes           = dev_lim->max_cq_sz - 1;
201         mdev->limits.reserved_cqs       = dev_lim->reserved_cqs;
202         mdev->limits.reserved_eqs       = dev_lim->reserved_eqs;
203         mdev->limits.reserved_mtts      = dev_lim->reserved_mtts;
204         mdev->limits.reserved_mrws      = dev_lim->reserved_mrws;
205         mdev->limits.reserved_uars      = dev_lim->reserved_uars;
206         mdev->limits.reserved_pds       = dev_lim->reserved_pds;
207         mdev->limits.port_width_cap     = dev_lim->max_port_width;
208         mdev->limits.page_size_cap      = ~(u32) (dev_lim->min_page_sz - 1);
209         mdev->limits.flags              = dev_lim->flags;
210         /*
211          * For old FW that doesn't return static rate support, use a
212          * value of 0x3 (only static rate values of 0 or 1 are handled),
213          * except on Sinai, where even old FW can handle static rate
214          * values of 2 and 3.
215          */
216         if (dev_lim->stat_rate_support)
217                 mdev->limits.stat_rate_support = dev_lim->stat_rate_support;
218         else if (mdev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
219                 mdev->limits.stat_rate_support = 0xf;
220         else
221                 mdev->limits.stat_rate_support = 0x3;
222
223         /* IB_DEVICE_RESIZE_MAX_WR not supported by driver.
224            May be doable since hardware supports it for SRQ.
225
226            IB_DEVICE_N_NOTIFY_CQ is supported by hardware but not by driver.
227
228            IB_DEVICE_SRQ_RESIZE is supported by hardware but SRQ is not
229            supported by driver. */
230         mdev->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT |
231                 IB_DEVICE_PORT_ACTIVE_EVENT |
232                 IB_DEVICE_SYS_IMAGE_GUID |
233                 IB_DEVICE_RC_RNR_NAK_GEN;
234
235         if (dev_lim->flags & DEV_LIM_FLAG_BAD_PKEY_CNTR)
236                 mdev->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
237
238         if (dev_lim->flags & DEV_LIM_FLAG_BAD_QKEY_CNTR)
239                 mdev->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR;
240
241         if (dev_lim->flags & DEV_LIM_FLAG_RAW_MULTI)
242                 mdev->device_cap_flags |= IB_DEVICE_RAW_MULTI;
243
244         if (dev_lim->flags & DEV_LIM_FLAG_AUTO_PATH_MIG)
245                 mdev->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG;
246
247         if (dev_lim->flags & DEV_LIM_FLAG_UD_AV_PORT_ENFORCE)
248                 mdev->device_cap_flags |= IB_DEVICE_UD_AV_PORT_ENFORCE;
249
250         if (dev_lim->flags & DEV_LIM_FLAG_SRQ)
251                 mdev->mthca_flags |= MTHCA_FLAG_SRQ;
252
253         return 0;
254 }
255
256 static int __devinit mthca_init_tavor(struct mthca_dev *mdev)
257 {
258         u8 status;
259         int err;
260         struct mthca_dev_lim        dev_lim;
261         struct mthca_profile        profile;
262         struct mthca_init_hca_param init_hca;
263
264         err = mthca_SYS_EN(mdev, &status);
265         if (err) {
266                 mthca_err(mdev, "SYS_EN command failed, aborting.\n");
267                 return err;
268         }
269         if (status) {
270                 mthca_err(mdev, "SYS_EN returned status 0x%02x, "
271                           "aborting.\n", status);
272                 return -EINVAL;
273         }
274
275         err = mthca_QUERY_FW(mdev, &status);
276         if (err) {
277                 mthca_err(mdev, "QUERY_FW command failed, aborting.\n");
278                 goto err_disable;
279         }
280         if (status) {
281                 mthca_err(mdev, "QUERY_FW returned status 0x%02x, "
282                           "aborting.\n", status);
283                 err = -EINVAL;
284                 goto err_disable;
285         }
286         err = mthca_QUERY_DDR(mdev, &status);
287         if (err) {
288                 mthca_err(mdev, "QUERY_DDR command failed, aborting.\n");
289                 goto err_disable;
290         }
291         if (status) {
292                 mthca_err(mdev, "QUERY_DDR returned status 0x%02x, "
293                           "aborting.\n", status);
294                 err = -EINVAL;
295                 goto err_disable;
296         }
297
298         err = mthca_dev_lim(mdev, &dev_lim);
299         if (err) {
300                 mthca_err(mdev, "QUERY_DEV_LIM command failed, aborting.\n");
301                 goto err_disable;
302         }
303
304         profile = default_profile;
305         profile.num_uar   = dev_lim.uar_size / PAGE_SIZE;
306         profile.uarc_size = 0;
307         if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
308                 profile.num_srq = dev_lim.max_srqs;
309
310         err = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
311         if (err < 0)
312                 goto err_disable;
313
314         err = mthca_INIT_HCA(mdev, &init_hca, &status);
315         if (err) {
316                 mthca_err(mdev, "INIT_HCA command failed, aborting.\n");
317                 goto err_disable;
318         }
319         if (status) {
320                 mthca_err(mdev, "INIT_HCA returned status 0x%02x, "
321                           "aborting.\n", status);
322                 err = -EINVAL;
323                 goto err_disable;
324         }
325
326         return 0;
327
328 err_disable:
329         mthca_SYS_DIS(mdev, &status);
330
331         return err;
332 }
333
334 static int __devinit mthca_load_fw(struct mthca_dev *mdev)
335 {
336         u8 status;
337         int err;
338
339         /* FIXME: use HCA-attached memory for FW if present */
340
341         mdev->fw.arbel.fw_icm =
342                 mthca_alloc_icm(mdev, mdev->fw.arbel.fw_pages,
343                                 GFP_HIGHUSER | __GFP_NOWARN);
344         if (!mdev->fw.arbel.fw_icm) {
345                 mthca_err(mdev, "Couldn't allocate FW area, aborting.\n");
346                 return -ENOMEM;
347         }
348
349         err = mthca_MAP_FA(mdev, mdev->fw.arbel.fw_icm, &status);
350         if (err) {
351                 mthca_err(mdev, "MAP_FA command failed, aborting.\n");
352                 goto err_free;
353         }
354         if (status) {
355                 mthca_err(mdev, "MAP_FA returned status 0x%02x, aborting.\n", status);
356                 err = -EINVAL;
357                 goto err_free;
358         }
359         err = mthca_RUN_FW(mdev, &status);
360         if (err) {
361                 mthca_err(mdev, "RUN_FW command failed, aborting.\n");
362                 goto err_unmap_fa;
363         }
364         if (status) {
365                 mthca_err(mdev, "RUN_FW returned status 0x%02x, aborting.\n", status);
366                 err = -EINVAL;
367                 goto err_unmap_fa;
368         }
369
370         return 0;
371
372 err_unmap_fa:
373         mthca_UNMAP_FA(mdev, &status);
374
375 err_free:
376         mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);
377         return err;
378 }
379
380 static int __devinit mthca_init_icm(struct mthca_dev *mdev,
381                                     struct mthca_dev_lim *dev_lim,
382                                     struct mthca_init_hca_param *init_hca,
383                                     u64 icm_size)
384 {
385         u64 aux_pages;
386         u8 status;
387         int err;
388
389         err = mthca_SET_ICM_SIZE(mdev, icm_size, &aux_pages, &status);
390         if (err) {
391                 mthca_err(mdev, "SET_ICM_SIZE command failed, aborting.\n");
392                 return err;
393         }
394         if (status) {
395                 mthca_err(mdev, "SET_ICM_SIZE returned status 0x%02x, "
396                           "aborting.\n", status);
397                 return -EINVAL;
398         }
399
400         mthca_dbg(mdev, "%lld KB of HCA context requires %lld KB aux memory.\n",
401                   (unsigned long long) icm_size >> 10,
402                   (unsigned long long) aux_pages << 2);
403
404         mdev->fw.arbel.aux_icm = mthca_alloc_icm(mdev, aux_pages,
405                                                  GFP_HIGHUSER | __GFP_NOWARN);
406         if (!mdev->fw.arbel.aux_icm) {
407                 mthca_err(mdev, "Couldn't allocate aux memory, aborting.\n");
408                 return -ENOMEM;
409         }
410
411         err = mthca_MAP_ICM_AUX(mdev, mdev->fw.arbel.aux_icm, &status);
412         if (err) {
413                 mthca_err(mdev, "MAP_ICM_AUX command failed, aborting.\n");
414                 goto err_free_aux;
415         }
416         if (status) {
417                 mthca_err(mdev, "MAP_ICM_AUX returned status 0x%02x, aborting.\n", status);
418                 err = -EINVAL;
419                 goto err_free_aux;
420         }
421
422         err = mthca_map_eq_icm(mdev, init_hca->eqc_base);
423         if (err) {
424                 mthca_err(mdev, "Failed to map EQ context memory, aborting.\n");
425                 goto err_unmap_aux;
426         }
427
428         mdev->mr_table.mtt_table = mthca_alloc_icm_table(mdev, init_hca->mtt_base,
429                                                          MTHCA_MTT_SEG_SIZE,
430                                                          mdev->limits.num_mtt_segs,
431                                                          mdev->limits.reserved_mtts, 1);
432         if (!mdev->mr_table.mtt_table) {
433                 mthca_err(mdev, "Failed to map MTT context memory, aborting.\n");
434                 err = -ENOMEM;
435                 goto err_unmap_eq;
436         }
437
438         mdev->mr_table.mpt_table = mthca_alloc_icm_table(mdev, init_hca->mpt_base,
439                                                          dev_lim->mpt_entry_sz,
440                                                          mdev->limits.num_mpts,
441                                                          mdev->limits.reserved_mrws, 1);
442         if (!mdev->mr_table.mpt_table) {
443                 mthca_err(mdev, "Failed to map MPT context memory, aborting.\n");
444                 err = -ENOMEM;
445                 goto err_unmap_mtt;
446         }
447
448         mdev->qp_table.qp_table = mthca_alloc_icm_table(mdev, init_hca->qpc_base,
449                                                         dev_lim->qpc_entry_sz,
450                                                         mdev->limits.num_qps,
451                                                         mdev->limits.reserved_qps, 0);
452         if (!mdev->qp_table.qp_table) {
453                 mthca_err(mdev, "Failed to map QP context memory, aborting.\n");
454                 err = -ENOMEM;
455                 goto err_unmap_mpt;
456         }
457
458         mdev->qp_table.eqp_table = mthca_alloc_icm_table(mdev, init_hca->eqpc_base,
459                                                          dev_lim->eqpc_entry_sz,
460                                                          mdev->limits.num_qps,
461                                                          mdev->limits.reserved_qps, 0);
462         if (!mdev->qp_table.eqp_table) {
463                 mthca_err(mdev, "Failed to map EQP context memory, aborting.\n");
464                 err = -ENOMEM;
465                 goto err_unmap_qp;
466         }
467
468         mdev->qp_table.rdb_table = mthca_alloc_icm_table(mdev, init_hca->rdb_base,
469                                                          MTHCA_RDB_ENTRY_SIZE,
470                                                          mdev->limits.num_qps <<
471                                                          mdev->qp_table.rdb_shift,
472                                                          0, 0);
473         if (!mdev->qp_table.rdb_table) {
474                 mthca_err(mdev, "Failed to map RDB context memory, aborting\n");
475                 err = -ENOMEM;
476                 goto err_unmap_eqp;
477         }
478
479        mdev->cq_table.table = mthca_alloc_icm_table(mdev, init_hca->cqc_base,
480                                                     dev_lim->cqc_entry_sz,
481                                                     mdev->limits.num_cqs,
482                                                     mdev->limits.reserved_cqs, 0);
483         if (!mdev->cq_table.table) {
484                 mthca_err(mdev, "Failed to map CQ context memory, aborting.\n");
485                 err = -ENOMEM;
486                 goto err_unmap_rdb;
487         }
488
489         if (mdev->mthca_flags & MTHCA_FLAG_SRQ) {
490                 mdev->srq_table.table =
491                         mthca_alloc_icm_table(mdev, init_hca->srqc_base,
492                                               dev_lim->srq_entry_sz,
493                                               mdev->limits.num_srqs,
494                                               mdev->limits.reserved_srqs, 0);
495                 if (!mdev->srq_table.table) {
496                         mthca_err(mdev, "Failed to map SRQ context memory, "
497                                   "aborting.\n");
498                         err = -ENOMEM;
499                         goto err_unmap_cq;
500                 }
501         }
502
503         /*
504          * It's not strictly required, but for simplicity just map the
505          * whole multicast group table now.  The table isn't very big
506          * and it's a lot easier than trying to track ref counts.
507          */
508         mdev->mcg_table.table = mthca_alloc_icm_table(mdev, init_hca->mc_base,
509                                                       MTHCA_MGM_ENTRY_SIZE,
510                                                       mdev->limits.num_mgms +
511                                                       mdev->limits.num_amgms,
512                                                       mdev->limits.num_mgms +
513                                                       mdev->limits.num_amgms,
514                                                       0);
515         if (!mdev->mcg_table.table) {
516                 mthca_err(mdev, "Failed to map MCG context memory, aborting.\n");
517                 err = -ENOMEM;
518                 goto err_unmap_srq;
519         }
520
521         return 0;
522
523 err_unmap_srq:
524         if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
525                 mthca_free_icm_table(mdev, mdev->srq_table.table);
526
527 err_unmap_cq:
528         mthca_free_icm_table(mdev, mdev->cq_table.table);
529
530 err_unmap_rdb:
531         mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);
532
533 err_unmap_eqp:
534         mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);
535
536 err_unmap_qp:
537         mthca_free_icm_table(mdev, mdev->qp_table.qp_table);
538
539 err_unmap_mpt:
540         mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);
541
542 err_unmap_mtt:
543         mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);
544
545 err_unmap_eq:
546         mthca_unmap_eq_icm(mdev);
547
548 err_unmap_aux:
549         mthca_UNMAP_ICM_AUX(mdev, &status);
550
551 err_free_aux:
552         mthca_free_icm(mdev, mdev->fw.arbel.aux_icm);
553
554         return err;
555 }
556
557 static void mthca_free_icms(struct mthca_dev *mdev)
558 {
559         u8 status;
560
561         mthca_free_icm_table(mdev, mdev->mcg_table.table);
562         if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
563                 mthca_free_icm_table(mdev, mdev->srq_table.table);
564         mthca_free_icm_table(mdev, mdev->cq_table.table);
565         mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);
566         mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);
567         mthca_free_icm_table(mdev, mdev->qp_table.qp_table);
568         mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);
569         mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);
570         mthca_unmap_eq_icm(mdev);
571
572         mthca_UNMAP_ICM_AUX(mdev, &status);
573         mthca_free_icm(mdev, mdev->fw.arbel.aux_icm);
574 }
575
576 static int __devinit mthca_init_arbel(struct mthca_dev *mdev)
577 {
578         struct mthca_dev_lim        dev_lim;
579         struct mthca_profile        profile;
580         struct mthca_init_hca_param init_hca;
581         u64 icm_size;
582         u8 status;
583         int err;
584
585         err = mthca_QUERY_FW(mdev, &status);
586         if (err) {
587                 mthca_err(mdev, "QUERY_FW command failed, aborting.\n");
588                 return err;
589         }
590         if (status) {
591                 mthca_err(mdev, "QUERY_FW returned status 0x%02x, "
592                           "aborting.\n", status);
593                 return -EINVAL;
594         }
595
596         err = mthca_ENABLE_LAM(mdev, &status);
597         if (err) {
598                 mthca_err(mdev, "ENABLE_LAM command failed, aborting.\n");
599                 return err;
600         }
601         if (status == MTHCA_CMD_STAT_LAM_NOT_PRE) {
602                 mthca_dbg(mdev, "No HCA-attached memory (running in MemFree mode)\n");
603                 mdev->mthca_flags |= MTHCA_FLAG_NO_LAM;
604         } else if (status) {
605                 mthca_err(mdev, "ENABLE_LAM returned status 0x%02x, "
606                           "aborting.\n", status);
607                 return -EINVAL;
608         }
609
610         err = mthca_load_fw(mdev);
611         if (err) {
612                 mthca_err(mdev, "Failed to start FW, aborting.\n");
613                 goto err_disable;
614         }
615
616         err = mthca_dev_lim(mdev, &dev_lim);
617         if (err) {
618                 mthca_err(mdev, "QUERY_DEV_LIM command failed, aborting.\n");
619                 goto err_stop_fw;
620         }
621
622         profile = default_profile;
623         profile.num_uar  = dev_lim.uar_size / PAGE_SIZE;
624         profile.num_udav = 0;
625         if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
626                 profile.num_srq = dev_lim.max_srqs;
627
628         icm_size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);
629         if ((int) icm_size < 0) {
630                 err = icm_size;
631                 goto err_stop_fw;
632         }
633
634         err = mthca_init_icm(mdev, &dev_lim, &init_hca, icm_size);
635         if (err)
636                 goto err_stop_fw;
637
638         err = mthca_INIT_HCA(mdev, &init_hca, &status);
639         if (err) {
640                 mthca_err(mdev, "INIT_HCA command failed, aborting.\n");
641                 goto err_free_icm;
642         }
643         if (status) {
644                 mthca_err(mdev, "INIT_HCA returned status 0x%02x, "
645                           "aborting.\n", status);
646                 err = -EINVAL;
647                 goto err_free_icm;
648         }
649
650         return 0;
651
652 err_free_icm:
653         mthca_free_icms(mdev);
654
655 err_stop_fw:
656         mthca_UNMAP_FA(mdev, &status);
657         mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);
658
659 err_disable:
660         if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))
661                 mthca_DISABLE_LAM(mdev, &status);
662
663         return err;
664 }
665
666 static void mthca_close_hca(struct mthca_dev *mdev)
667 {
668         u8 status;
669
670         mthca_CLOSE_HCA(mdev, 0, &status);
671
672         if (mthca_is_memfree(mdev)) {
673                 mthca_free_icms(mdev);
674
675                 mthca_UNMAP_FA(mdev, &status);
676                 mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);
677
678                 if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))
679                         mthca_DISABLE_LAM(mdev, &status);
680         } else
681                 mthca_SYS_DIS(mdev, &status);
682 }
683
684 static int __devinit mthca_init_hca(struct mthca_dev *mdev)
685 {
686         u8 status;
687         int err;
688         struct mthca_adapter adapter;
689
690         if (mthca_is_memfree(mdev))
691                 err = mthca_init_arbel(mdev);
692         else
693                 err = mthca_init_tavor(mdev);
694
695         if (err)
696                 return err;
697
698         err = mthca_QUERY_ADAPTER(mdev, &adapter, &status);
699         if (err) {
700                 mthca_err(mdev, "QUERY_ADAPTER command failed, aborting.\n");
701                 goto err_close;
702         }
703         if (status) {
704                 mthca_err(mdev, "QUERY_ADAPTER returned status 0x%02x, "
705                           "aborting.\n", status);
706                 err = -EINVAL;
707                 goto err_close;
708         }
709
710         mdev->eq_table.inta_pin = adapter.inta_pin;
711         mdev->rev_id            = adapter.revision_id;
712         memcpy(mdev->board_id, adapter.board_id, sizeof mdev->board_id);
713
714         return 0;
715
716 err_close:
717         mthca_close_hca(mdev);
718         return err;
719 }
720
721 static int __devinit mthca_setup_hca(struct mthca_dev *dev)
722 {
723         int err;
724         u8 status;
725
726         MTHCA_INIT_DOORBELL_LOCK(&dev->doorbell_lock);
727
728         err = mthca_init_uar_table(dev);
729         if (err) {
730                 mthca_err(dev, "Failed to initialize "
731                           "user access region table, aborting.\n");
732                 return err;
733         }
734
735         err = mthca_uar_alloc(dev, &dev->driver_uar);
736         if (err) {
737                 mthca_err(dev, "Failed to allocate driver access region, "
738                           "aborting.\n");
739                 goto err_uar_table_free;
740         }
741
742         dev->kar = ioremap(dev->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
743         if (!dev->kar) {
744                 mthca_err(dev, "Couldn't map kernel access region, "
745                           "aborting.\n");
746                 err = -ENOMEM;
747                 goto err_uar_free;
748         }
749
750         err = mthca_init_pd_table(dev);
751         if (err) {
752                 mthca_err(dev, "Failed to initialize "
753                           "protection domain table, aborting.\n");
754                 goto err_kar_unmap;
755         }
756
757         err = mthca_init_mr_table(dev);
758         if (err) {
759                 mthca_err(dev, "Failed to initialize "
760                           "memory region table, aborting.\n");
761                 goto err_pd_table_free;
762         }
763
764         err = mthca_pd_alloc(dev, 1, &dev->driver_pd);
765         if (err) {
766                 mthca_err(dev, "Failed to create driver PD, "
767                           "aborting.\n");
768                 goto err_mr_table_free;
769         }
770
771         err = mthca_init_eq_table(dev);
772         if (err) {
773                 mthca_err(dev, "Failed to initialize "
774                           "event queue table, aborting.\n");
775                 goto err_pd_free;
776         }
777
778         err = mthca_cmd_use_events(dev);
779         if (err) {
780                 mthca_err(dev, "Failed to switch to event-driven "
781                           "firmware commands, aborting.\n");
782                 goto err_eq_table_free;
783         }
784
785         err = mthca_NOP(dev, &status);
786         if (err || status) {
787                 mthca_err(dev, "NOP command failed to generate interrupt (IRQ %d), aborting.\n",
788                           dev->mthca_flags & MTHCA_FLAG_MSI_X ?
789                           dev->eq_table.eq[MTHCA_EQ_CMD].msi_x_vector :
790                           dev->pdev->irq);
791                 if (dev->mthca_flags & (MTHCA_FLAG_MSI | MTHCA_FLAG_MSI_X))
792                         mthca_err(dev, "Try again with MSI/MSI-X disabled.\n");
793                 else
794                         mthca_err(dev, "BIOS or ACPI interrupt routing problem?\n");
795
796                 goto err_cmd_poll;
797         }
798
799         mthca_dbg(dev, "NOP command IRQ test passed\n");
800
801         err = mthca_init_cq_table(dev);
802         if (err) {
803                 mthca_err(dev, "Failed to initialize "
804                           "completion queue table, aborting.\n");
805                 goto err_cmd_poll;
806         }
807
808         err = mthca_init_srq_table(dev);
809         if (err) {
810                 mthca_err(dev, "Failed to initialize "
811                           "shared receive queue table, aborting.\n");
812                 goto err_cq_table_free;
813         }
814
815         err = mthca_init_qp_table(dev);
816         if (err) {
817                 mthca_err(dev, "Failed to initialize "
818                           "queue pair table, aborting.\n");
819                 goto err_srq_table_free;
820         }
821
822         err = mthca_init_av_table(dev);
823         if (err) {
824                 mthca_err(dev, "Failed to initialize "
825                           "address vector table, aborting.\n");
826                 goto err_qp_table_free;
827         }
828
829         err = mthca_init_mcg_table(dev);
830         if (err) {
831                 mthca_err(dev, "Failed to initialize "
832                           "multicast group table, aborting.\n");
833                 goto err_av_table_free;
834         }
835
836         return 0;
837
838 err_av_table_free:
839         mthca_cleanup_av_table(dev);
840
841 err_qp_table_free:
842         mthca_cleanup_qp_table(dev);
843
844 err_srq_table_free:
845         mthca_cleanup_srq_table(dev);
846
847 err_cq_table_free:
848         mthca_cleanup_cq_table(dev);
849
850 err_cmd_poll:
851         mthca_cmd_use_polling(dev);
852
853 err_eq_table_free:
854         mthca_cleanup_eq_table(dev);
855
856 err_pd_free:
857         mthca_pd_free(dev, &dev->driver_pd);
858
859 err_mr_table_free:
860         mthca_cleanup_mr_table(dev);
861
862 err_pd_table_free:
863         mthca_cleanup_pd_table(dev);
864
865 err_kar_unmap:
866         iounmap(dev->kar);
867
868 err_uar_free:
869         mthca_uar_free(dev, &dev->driver_uar);
870
871 err_uar_table_free:
872         mthca_cleanup_uar_table(dev);
873         return err;
874 }
875
876 static int __devinit mthca_request_regions(struct pci_dev *pdev,
877                                            int ddr_hidden)
878 {
879         int err;
880
881         /*
882          * We can't just use pci_request_regions() because the MSI-X
883          * table is right in the middle of the first BAR.  If we did
884          * pci_request_region and grab all of the first BAR, then
885          * setting up MSI-X would fail, since the PCI core wants to do
886          * request_mem_region on the MSI-X vector table.
887          *
888          * So just request what we need right now, and request any
889          * other regions we need when setting up EQs.
890          */
891         if (!request_mem_region(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE,
892                                 MTHCA_HCR_SIZE, DRV_NAME))
893                 return -EBUSY;
894
895         err = pci_request_region(pdev, 2, DRV_NAME);
896         if (err)
897                 goto err_bar2_failed;
898
899         if (!ddr_hidden) {
900                 err = pci_request_region(pdev, 4, DRV_NAME);
901                 if (err)
902                         goto err_bar4_failed;
903         }
904
905         return 0;
906
907 err_bar4_failed:
908         pci_release_region(pdev, 2);
909
910 err_bar2_failed:
911         release_mem_region(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE,
912                            MTHCA_HCR_SIZE);
913
914         return err;
915 }
916
917 static void mthca_release_regions(struct pci_dev *pdev,
918                                   int ddr_hidden)
919 {
920         if (!ddr_hidden)
921                 pci_release_region(pdev, 4);
922
923         pci_release_region(pdev, 2);
924
925         release_mem_region(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE,
926                            MTHCA_HCR_SIZE);
927 }
928
929 static int __devinit mthca_enable_msi_x(struct mthca_dev *mdev)
930 {
931         struct msix_entry entries[3];
932         int err;
933
934         entries[0].entry = 0;
935         entries[1].entry = 1;
936         entries[2].entry = 2;
937
938         err = pci_enable_msix(mdev->pdev, entries, ARRAY_SIZE(entries));
939         if (err) {
940                 if (err > 0)
941                         mthca_info(mdev, "Only %d MSI-X vectors available, "
942                                    "not using MSI-X\n", err);
943                 return err;
944         }
945
946         mdev->eq_table.eq[MTHCA_EQ_COMP ].msi_x_vector = entries[0].vector;
947         mdev->eq_table.eq[MTHCA_EQ_ASYNC].msi_x_vector = entries[1].vector;
948         mdev->eq_table.eq[MTHCA_EQ_CMD  ].msi_x_vector = entries[2].vector;
949
950         return 0;
951 }
952
953 /* Types of supported HCA */
954 enum {
955         TAVOR,                  /* MT23108                        */
956         ARBEL_COMPAT,           /* MT25208 in Tavor compat mode   */
957         ARBEL_NATIVE,           /* MT25208 with extended features */
958         SINAI                   /* MT25204 */
959 };
960
961 #define MTHCA_FW_VER(major, minor, subminor) \
962         (((u64) (major) << 32) | ((u64) (minor) << 16) | (u64) (subminor))
963
964 static struct {
965         u64 latest_fw;
966         u32 flags;
967 } mthca_hca_table[] = {
968         [TAVOR]        = { .latest_fw = MTHCA_FW_VER(3, 4, 0),
969                            .flags     = 0 },
970         [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 7, 400),
971                            .flags     = MTHCA_FLAG_PCIE },
972         [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 1, 0),
973                            .flags     = MTHCA_FLAG_MEMFREE |
974                                         MTHCA_FLAG_PCIE },
975         [SINAI]        = { .latest_fw = MTHCA_FW_VER(1, 0, 800),
976                            .flags     = MTHCA_FLAG_MEMFREE |
977                                         MTHCA_FLAG_PCIE    |
978                                         MTHCA_FLAG_SINAI_OPT }
979 };
980
981 static int __devinit mthca_init_one(struct pci_dev *pdev,
982                                     const struct pci_device_id *id)
983 {
984         static int mthca_version_printed = 0;
985         int ddr_hidden = 0;
986         int err;
987         struct mthca_dev *mdev;
988
989         if (!mthca_version_printed) {
990                 printk(KERN_INFO "%s", mthca_version);
991                 ++mthca_version_printed;
992         }
993
994         printk(KERN_INFO PFX "Initializing %s\n",
995                pci_name(pdev));
996
997         if (id->driver_data >= ARRAY_SIZE(mthca_hca_table)) {
998                 printk(KERN_ERR PFX "%s has invalid driver data %lx\n",
999                        pci_name(pdev), id->driver_data);
1000                 return -ENODEV;
1001         }
1002
1003         err = pci_enable_device(pdev);
1004         if (err) {
1005                 dev_err(&pdev->dev, "Cannot enable PCI device, "
1006                         "aborting.\n");
1007                 return err;
1008         }
1009
1010         /*
1011          * Check for BARs.  We expect 0: 1MB, 2: 8MB, 4: DDR (may not
1012          * be present)
1013          */
1014         if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
1015             pci_resource_len(pdev, 0) != 1 << 20) {
1016                 dev_err(&pdev->dev, "Missing DCS, aborting.\n");
1017                 err = -ENODEV;
1018                 goto err_disable_pdev;
1019         }
1020         if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
1021                 dev_err(&pdev->dev, "Missing UAR, aborting.\n");
1022                 err = -ENODEV;
1023                 goto err_disable_pdev;
1024         }
1025         if (!(pci_resource_flags(pdev, 4) & IORESOURCE_MEM))
1026                 ddr_hidden = 1;
1027
1028         err = mthca_request_regions(pdev, ddr_hidden);
1029         if (err) {
1030                 dev_err(&pdev->dev, "Cannot obtain PCI resources, "
1031                         "aborting.\n");
1032                 goto err_disable_pdev;
1033         }
1034
1035         pci_set_master(pdev);
1036
1037         err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
1038         if (err) {
1039                 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
1040                 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1041                 if (err) {
1042                         dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
1043                         goto err_free_res;
1044                 }
1045         }
1046         err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
1047         if (err) {
1048                 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
1049                          "consistent PCI DMA mask.\n");
1050                 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1051                 if (err) {
1052                         dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
1053                                 "aborting.\n");
1054                         goto err_free_res;
1055                 }
1056         }
1057
1058         mdev = (struct mthca_dev *) ib_alloc_device(sizeof *mdev);
1059         if (!mdev) {
1060                 dev_err(&pdev->dev, "Device struct alloc failed, "
1061                         "aborting.\n");
1062                 err = -ENOMEM;
1063                 goto err_free_res;
1064         }
1065
1066         mdev->pdev = pdev;
1067
1068         mdev->mthca_flags = mthca_hca_table[id->driver_data].flags;
1069         if (ddr_hidden)
1070                 mdev->mthca_flags |= MTHCA_FLAG_DDR_HIDDEN;
1071
1072         /*
1073          * Now reset the HCA before we touch the PCI capabilities or
1074          * attempt a firmware command, since a boot ROM may have left
1075          * the HCA in an undefined state.
1076          */
1077         err = mthca_reset(mdev);
1078         if (err) {
1079                 mthca_err(mdev, "Failed to reset HCA, aborting.\n");
1080                 goto err_free_dev;
1081         }
1082
1083         if (msi_x && !mthca_enable_msi_x(mdev))
1084                 mdev->mthca_flags |= MTHCA_FLAG_MSI_X;
1085         if (msi && !(mdev->mthca_flags & MTHCA_FLAG_MSI_X) &&
1086             !pci_enable_msi(pdev))
1087                 mdev->mthca_flags |= MTHCA_FLAG_MSI;
1088
1089         if (mthca_cmd_init(mdev)) {
1090                 mthca_err(mdev, "Failed to init command interface, aborting.\n");
1091                 goto err_free_dev;
1092         }
1093
1094         err = mthca_tune_pci(mdev);
1095         if (err)
1096                 goto err_cmd;
1097
1098         err = mthca_init_hca(mdev);
1099         if (err)
1100                 goto err_cmd;
1101
1102         if (mdev->fw_ver < mthca_hca_table[id->driver_data].latest_fw) {
1103                 mthca_warn(mdev, "HCA FW version %d.%d.%d is old (%d.%d.%d is current).\n",
1104                            (int) (mdev->fw_ver >> 32), (int) (mdev->fw_ver >> 16) & 0xffff,
1105                            (int) (mdev->fw_ver & 0xffff),
1106                            (int) (mthca_hca_table[id->driver_data].latest_fw >> 32),
1107                            (int) (mthca_hca_table[id->driver_data].latest_fw >> 16) & 0xffff,
1108                            (int) (mthca_hca_table[id->driver_data].latest_fw & 0xffff));
1109                 mthca_warn(mdev, "If you have problems, try updating your HCA FW.\n");
1110         }
1111
1112         err = mthca_setup_hca(mdev);
1113         if (err)
1114                 goto err_close;
1115
1116         err = mthca_register_device(mdev);
1117         if (err)
1118                 goto err_cleanup;
1119
1120         err = mthca_create_agents(mdev);
1121         if (err)
1122                 goto err_unregister;
1123
1124         pci_set_drvdata(pdev, mdev);
1125
1126         return 0;
1127
1128 err_unregister:
1129         mthca_unregister_device(mdev);
1130
1131 err_cleanup:
1132         mthca_cleanup_mcg_table(mdev);
1133         mthca_cleanup_av_table(mdev);
1134         mthca_cleanup_qp_table(mdev);
1135         mthca_cleanup_srq_table(mdev);
1136         mthca_cleanup_cq_table(mdev);
1137         mthca_cmd_use_polling(mdev);
1138         mthca_cleanup_eq_table(mdev);
1139
1140         mthca_pd_free(mdev, &mdev->driver_pd);
1141
1142         mthca_cleanup_mr_table(mdev);
1143         mthca_cleanup_pd_table(mdev);
1144         mthca_cleanup_uar_table(mdev);
1145
1146 err_close:
1147         mthca_close_hca(mdev);
1148
1149 err_cmd:
1150         mthca_cmd_cleanup(mdev);
1151
1152 err_free_dev:
1153         if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
1154                 pci_disable_msix(pdev);
1155         if (mdev->mthca_flags & MTHCA_FLAG_MSI)
1156                 pci_disable_msi(pdev);
1157
1158         ib_dealloc_device(&mdev->ib_dev);
1159
1160 err_free_res:
1161         mthca_release_regions(pdev, ddr_hidden);
1162
1163 err_disable_pdev:
1164         pci_disable_device(pdev);
1165         pci_set_drvdata(pdev, NULL);
1166         return err;
1167 }
1168
1169 static void __devexit mthca_remove_one(struct pci_dev *pdev)
1170 {
1171         struct mthca_dev *mdev = pci_get_drvdata(pdev);
1172         u8 status;
1173         int p;
1174
1175         if (mdev) {
1176                 mthca_free_agents(mdev);
1177                 mthca_unregister_device(mdev);
1178
1179                 for (p = 1; p <= mdev->limits.num_ports; ++p)
1180                         mthca_CLOSE_IB(mdev, p, &status);
1181
1182                 mthca_cleanup_mcg_table(mdev);
1183                 mthca_cleanup_av_table(mdev);
1184                 mthca_cleanup_qp_table(mdev);
1185                 mthca_cleanup_srq_table(mdev);
1186                 mthca_cleanup_cq_table(mdev);
1187                 mthca_cmd_use_polling(mdev);
1188                 mthca_cleanup_eq_table(mdev);
1189
1190                 mthca_pd_free(mdev, &mdev->driver_pd);
1191
1192                 mthca_cleanup_mr_table(mdev);
1193                 mthca_cleanup_pd_table(mdev);
1194
1195                 iounmap(mdev->kar);
1196                 mthca_uar_free(mdev, &mdev->driver_uar);
1197                 mthca_cleanup_uar_table(mdev);
1198                 mthca_close_hca(mdev);
1199                 mthca_cmd_cleanup(mdev);
1200
1201                 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
1202                         pci_disable_msix(pdev);
1203                 if (mdev->mthca_flags & MTHCA_FLAG_MSI)
1204                         pci_disable_msi(pdev);
1205
1206                 ib_dealloc_device(&mdev->ib_dev);
1207                 mthca_release_regions(pdev, mdev->mthca_flags &
1208                                       MTHCA_FLAG_DDR_HIDDEN);
1209                 pci_disable_device(pdev);
1210                 pci_set_drvdata(pdev, NULL);
1211         }
1212 }
1213
1214 static struct pci_device_id mthca_pci_table[] = {
1215         { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_TAVOR),
1216           .driver_data = TAVOR },
1217         { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_TAVOR),
1218           .driver_data = TAVOR },
1219         { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT),
1220           .driver_data = ARBEL_COMPAT },
1221         { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT),
1222           .driver_data = ARBEL_COMPAT },
1223         { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_ARBEL),
1224           .driver_data = ARBEL_NATIVE },
1225         { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_ARBEL),
1226           .driver_data = ARBEL_NATIVE },
1227         { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_SINAI),
1228           .driver_data = SINAI },
1229         { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_SINAI),
1230           .driver_data = SINAI },
1231         { PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_SINAI_OLD),
1232           .driver_data = SINAI },
1233         { PCI_DEVICE(PCI_VENDOR_ID_TOPSPIN, PCI_DEVICE_ID_MELLANOX_SINAI_OLD),
1234           .driver_data = SINAI },
1235         { 0, }
1236 };
1237
1238 MODULE_DEVICE_TABLE(pci, mthca_pci_table);
1239
1240 static struct pci_driver mthca_driver = {
1241         .name           = DRV_NAME,
1242         .id_table       = mthca_pci_table,
1243         .probe          = mthca_init_one,
1244         .remove         = __devexit_p(mthca_remove_one)
1245 };
1246
1247 static int __init mthca_init(void)
1248 {
1249         int ret;
1250
1251         ret = pci_register_driver(&mthca_driver);
1252         return ret < 0 ? ret : 0;
1253 }
1254
1255 static void __exit mthca_cleanup(void)
1256 {
1257         pci_unregister_driver(&mthca_driver);
1258 }
1259
1260 module_init(mthca_init);
1261 module_exit(mthca_cleanup);