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 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/errno.h>
39 #include <linux/pci.h>
40 #include <linux/dma-mapping.h>
42 #include <linux/mlx4/device.h>
43 #include <linux/mlx4/doorbell.h>
49 MODULE_AUTHOR("Roland Dreier");
50 MODULE_DESCRIPTION("Mellanox ConnectX HCA low-level driver");
51 MODULE_LICENSE("Dual BSD/GPL");
52 MODULE_VERSION(DRV_VERSION
);
54 #ifdef CONFIG_MLX4_DEBUG
56 int mlx4_debug_level
= 0;
57 module_param_named(debug_level
, mlx4_debug_level
, int, 0644);
58 MODULE_PARM_DESC(debug_level
, "Enable debug tracing if > 0");
60 #endif /* CONFIG_MLX4_DEBUG */
65 module_param(msi_x
, int, 0444);
66 MODULE_PARM_DESC(msi_x
, "attempt to use MSI-X if nonzero");
68 #else /* CONFIG_PCI_MSI */
72 #endif /* CONFIG_PCI_MSI */
74 static const char mlx4_version
[] __devinitdata
=
75 DRV_NAME
": Mellanox ConnectX core driver v"
76 DRV_VERSION
" (" DRV_RELDATE
")\n";
78 static struct mlx4_profile default_profile
= {
88 static int __devinit
mlx4_dev_cap(struct mlx4_dev
*dev
, struct mlx4_dev_cap
*dev_cap
)
92 err
= mlx4_QUERY_DEV_CAP(dev
, dev_cap
);
94 mlx4_err(dev
, "QUERY_DEV_CAP command failed, aborting.\n");
98 if (dev_cap
->min_page_sz
> PAGE_SIZE
) {
99 mlx4_err(dev
, "HCA minimum page size of %d bigger than "
100 "kernel PAGE_SIZE of %ld, aborting.\n",
101 dev_cap
->min_page_sz
, PAGE_SIZE
);
104 if (dev_cap
->num_ports
> MLX4_MAX_PORTS
) {
105 mlx4_err(dev
, "HCA has %d ports, but we only support %d, "
107 dev_cap
->num_ports
, MLX4_MAX_PORTS
);
111 if (dev_cap
->uar_size
> pci_resource_len(dev
->pdev
, 2)) {
112 mlx4_err(dev
, "HCA reported UAR size of 0x%x bigger than "
113 "PCI resource 2 size of 0x%llx, aborting.\n",
115 (unsigned long long) pci_resource_len(dev
->pdev
, 2));
119 dev
->caps
.num_ports
= dev_cap
->num_ports
;
120 dev
->caps
.num_uars
= dev_cap
->uar_size
/ PAGE_SIZE
;
121 dev
->caps
.vl_cap
= dev_cap
->max_vl
;
122 dev
->caps
.mtu_cap
= dev_cap
->max_mtu
;
123 dev
->caps
.gid_table_len
= dev_cap
->max_gids
;
124 dev
->caps
.pkey_table_len
= dev_cap
->max_pkeys
;
125 dev
->caps
.local_ca_ack_delay
= dev_cap
->local_ca_ack_delay
;
126 dev
->caps
.bf_reg_size
= dev_cap
->bf_reg_size
;
127 dev
->caps
.bf_regs_per_page
= dev_cap
->bf_regs_per_page
;
128 dev
->caps
.max_sq_sg
= dev_cap
->max_sq_sg
;
129 dev
->caps
.max_rq_sg
= dev_cap
->max_rq_sg
;
130 dev
->caps
.max_wqes
= dev_cap
->max_qp_sz
;
131 dev
->caps
.max_qp_init_rdma
= dev_cap
->max_requester_per_qp
;
132 dev
->caps
.reserved_qps
= dev_cap
->reserved_qps
;
133 dev
->caps
.max_srq_wqes
= dev_cap
->max_srq_sz
;
134 dev
->caps
.max_srq_sge
= dev_cap
->max_rq_sg
- 1;
135 dev
->caps
.reserved_srqs
= dev_cap
->reserved_srqs
;
136 dev
->caps
.max_sq_desc_sz
= dev_cap
->max_sq_desc_sz
;
137 dev
->caps
.max_rq_desc_sz
= dev_cap
->max_rq_desc_sz
;
138 dev
->caps
.num_qp_per_mgm
= MLX4_QP_PER_MGM
;
140 * Subtract 1 from the limit because we need to allocate a
141 * spare CQE so the HCA HW can tell the difference between an
142 * empty CQ and a full CQ.
144 dev
->caps
.max_cqes
= dev_cap
->max_cq_sz
- 1;
145 dev
->caps
.reserved_cqs
= dev_cap
->reserved_cqs
;
146 dev
->caps
.reserved_eqs
= dev_cap
->reserved_eqs
;
147 dev
->caps
.reserved_mtts
= dev_cap
->reserved_mtts
;
148 dev
->caps
.reserved_mrws
= dev_cap
->reserved_mrws
;
149 dev
->caps
.reserved_uars
= dev_cap
->reserved_uars
;
150 dev
->caps
.reserved_pds
= dev_cap
->reserved_pds
;
151 dev
->caps
.port_width_cap
= dev_cap
->max_port_width
;
152 dev
->caps
.mtt_entry_sz
= MLX4_MTT_ENTRY_PER_SEG
* dev_cap
->mtt_entry_sz
;
153 dev
->caps
.page_size_cap
= ~(u32
) (dev_cap
->min_page_sz
- 1);
154 dev
->caps
.flags
= dev_cap
->flags
;
155 dev
->caps
.stat_rate_support
= dev_cap
->stat_rate_support
;
160 static int __devinit
mlx4_load_fw(struct mlx4_dev
*dev
)
162 struct mlx4_priv
*priv
= mlx4_priv(dev
);
165 priv
->fw
.fw_icm
= mlx4_alloc_icm(dev
, priv
->fw
.fw_pages
,
166 GFP_HIGHUSER
| __GFP_NOWARN
);
167 if (!priv
->fw
.fw_icm
) {
168 mlx4_err(dev
, "Couldn't allocate FW area, aborting.\n");
172 err
= mlx4_MAP_FA(dev
, priv
->fw
.fw_icm
);
174 mlx4_err(dev
, "MAP_FA command failed, aborting.\n");
178 err
= mlx4_RUN_FW(dev
);
180 mlx4_err(dev
, "RUN_FW command failed, aborting.\n");
190 mlx4_free_icm(dev
, priv
->fw
.fw_icm
);
194 static int __devinit
mlx4_init_cmpt_table(struct mlx4_dev
*dev
, u64 cmpt_base
,
197 struct mlx4_priv
*priv
= mlx4_priv(dev
);
200 err
= mlx4_init_icm_table(dev
, &priv
->qp_table
.cmpt_table
,
202 ((u64
) (MLX4_CMPT_TYPE_QP
*
203 cmpt_entry_sz
) << MLX4_CMPT_SHIFT
),
204 cmpt_entry_sz
, dev
->caps
.num_qps
,
205 dev
->caps
.reserved_qps
, 0);
209 err
= mlx4_init_icm_table(dev
, &priv
->srq_table
.cmpt_table
,
211 ((u64
) (MLX4_CMPT_TYPE_SRQ
*
212 cmpt_entry_sz
) << MLX4_CMPT_SHIFT
),
213 cmpt_entry_sz
, dev
->caps
.num_srqs
,
214 dev
->caps
.reserved_srqs
, 0);
218 err
= mlx4_init_icm_table(dev
, &priv
->cq_table
.cmpt_table
,
220 ((u64
) (MLX4_CMPT_TYPE_CQ
*
221 cmpt_entry_sz
) << MLX4_CMPT_SHIFT
),
222 cmpt_entry_sz
, dev
->caps
.num_cqs
,
223 dev
->caps
.reserved_cqs
, 0);
227 err
= mlx4_init_icm_table(dev
, &priv
->eq_table
.cmpt_table
,
229 ((u64
) (MLX4_CMPT_TYPE_EQ
*
230 cmpt_entry_sz
) << MLX4_CMPT_SHIFT
),
232 roundup_pow_of_two(MLX4_NUM_EQ
+
233 dev
->caps
.reserved_eqs
),
234 MLX4_NUM_EQ
+ dev
->caps
.reserved_eqs
, 0);
241 mlx4_cleanup_icm_table(dev
, &priv
->cq_table
.cmpt_table
);
244 mlx4_cleanup_icm_table(dev
, &priv
->srq_table
.cmpt_table
);
247 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.cmpt_table
);
253 static int __devinit
mlx4_init_icm(struct mlx4_dev
*dev
,
254 struct mlx4_dev_cap
*dev_cap
,
255 struct mlx4_init_hca_param
*init_hca
,
258 struct mlx4_priv
*priv
= mlx4_priv(dev
);
262 err
= mlx4_SET_ICM_SIZE(dev
, icm_size
, &aux_pages
);
264 mlx4_err(dev
, "SET_ICM_SIZE command failed, aborting.\n");
268 mlx4_dbg(dev
, "%lld KB of HCA context requires %lld KB aux memory.\n",
269 (unsigned long long) icm_size
>> 10,
270 (unsigned long long) aux_pages
<< 2);
272 priv
->fw
.aux_icm
= mlx4_alloc_icm(dev
, aux_pages
,
273 GFP_HIGHUSER
| __GFP_NOWARN
);
274 if (!priv
->fw
.aux_icm
) {
275 mlx4_err(dev
, "Couldn't allocate aux memory, aborting.\n");
279 err
= mlx4_MAP_ICM_AUX(dev
, priv
->fw
.aux_icm
);
281 mlx4_err(dev
, "MAP_ICM_AUX command failed, aborting.\n");
285 err
= mlx4_init_cmpt_table(dev
, init_hca
->cmpt_base
, dev_cap
->cmpt_entry_sz
);
287 mlx4_err(dev
, "Failed to map cMPT context memory, aborting.\n");
291 err
= mlx4_map_eq_icm(dev
, init_hca
->eqc_base
);
293 mlx4_err(dev
, "Failed to map EQ context memory, aborting.\n");
297 err
= mlx4_init_icm_table(dev
, &priv
->mr_table
.mtt_table
,
299 dev
->caps
.mtt_entry_sz
,
300 dev
->caps
.num_mtt_segs
,
301 dev
->caps
.reserved_mtts
, 1);
303 mlx4_err(dev
, "Failed to map MTT context memory, aborting.\n");
307 err
= mlx4_init_icm_table(dev
, &priv
->mr_table
.dmpt_table
,
309 dev_cap
->dmpt_entry_sz
,
311 dev
->caps
.reserved_mrws
, 1);
313 mlx4_err(dev
, "Failed to map dMPT context memory, aborting.\n");
317 err
= mlx4_init_icm_table(dev
, &priv
->qp_table
.qp_table
,
319 dev_cap
->qpc_entry_sz
,
321 dev
->caps
.reserved_qps
, 0);
323 mlx4_err(dev
, "Failed to map QP context memory, aborting.\n");
327 err
= mlx4_init_icm_table(dev
, &priv
->qp_table
.auxc_table
,
329 dev_cap
->aux_entry_sz
,
331 dev
->caps
.reserved_qps
, 0);
333 mlx4_err(dev
, "Failed to map AUXC context memory, aborting.\n");
337 err
= mlx4_init_icm_table(dev
, &priv
->qp_table
.altc_table
,
339 dev_cap
->altc_entry_sz
,
341 dev
->caps
.reserved_qps
, 0);
343 mlx4_err(dev
, "Failed to map ALTC context memory, aborting.\n");
347 err
= mlx4_init_icm_table(dev
, &priv
->qp_table
.rdmarc_table
,
348 init_hca
->rdmarc_base
,
349 dev_cap
->rdmarc_entry_sz
<< priv
->qp_table
.rdmarc_shift
,
351 dev
->caps
.reserved_qps
, 0);
353 mlx4_err(dev
, "Failed to map RDMARC context memory, aborting\n");
357 err
= mlx4_init_icm_table(dev
, &priv
->cq_table
.table
,
359 dev_cap
->cqc_entry_sz
,
361 dev
->caps
.reserved_cqs
, 0);
363 mlx4_err(dev
, "Failed to map CQ context memory, aborting.\n");
364 goto err_unmap_rdmarc
;
367 err
= mlx4_init_icm_table(dev
, &priv
->srq_table
.table
,
369 dev_cap
->srq_entry_sz
,
371 dev
->caps
.reserved_srqs
, 0);
373 mlx4_err(dev
, "Failed to map SRQ context memory, aborting.\n");
378 * It's not strictly required, but for simplicity just map the
379 * whole multicast group table now. The table isn't very big
380 * and it's a lot easier than trying to track ref counts.
382 err
= mlx4_init_icm_table(dev
, &priv
->mcg_table
.table
,
383 init_hca
->mc_base
, MLX4_MGM_ENTRY_SIZE
,
384 dev
->caps
.num_mgms
+ dev
->caps
.num_amgms
,
385 dev
->caps
.num_mgms
+ dev
->caps
.num_amgms
,
388 mlx4_err(dev
, "Failed to map MCG context memory, aborting.\n");
395 mlx4_cleanup_icm_table(dev
, &priv
->srq_table
.table
);
398 mlx4_cleanup_icm_table(dev
, &priv
->cq_table
.table
);
401 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.rdmarc_table
);
404 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.altc_table
);
407 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.auxc_table
);
410 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.qp_table
);
413 mlx4_cleanup_icm_table(dev
, &priv
->mr_table
.dmpt_table
);
416 mlx4_cleanup_icm_table(dev
, &priv
->mr_table
.mtt_table
);
419 mlx4_unmap_eq_icm(dev
);
422 mlx4_cleanup_icm_table(dev
, &priv
->eq_table
.cmpt_table
);
423 mlx4_cleanup_icm_table(dev
, &priv
->cq_table
.cmpt_table
);
424 mlx4_cleanup_icm_table(dev
, &priv
->srq_table
.cmpt_table
);
425 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.cmpt_table
);
428 mlx4_UNMAP_ICM_AUX(dev
);
431 mlx4_free_icm(dev
, priv
->fw
.aux_icm
);
436 static void mlx4_free_icms(struct mlx4_dev
*dev
)
438 struct mlx4_priv
*priv
= mlx4_priv(dev
);
440 mlx4_cleanup_icm_table(dev
, &priv
->mcg_table
.table
);
441 mlx4_cleanup_icm_table(dev
, &priv
->srq_table
.table
);
442 mlx4_cleanup_icm_table(dev
, &priv
->cq_table
.table
);
443 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.rdmarc_table
);
444 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.altc_table
);
445 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.auxc_table
);
446 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.qp_table
);
447 mlx4_cleanup_icm_table(dev
, &priv
->mr_table
.dmpt_table
);
448 mlx4_cleanup_icm_table(dev
, &priv
->mr_table
.mtt_table
);
449 mlx4_cleanup_icm_table(dev
, &priv
->eq_table
.cmpt_table
);
450 mlx4_cleanup_icm_table(dev
, &priv
->cq_table
.cmpt_table
);
451 mlx4_cleanup_icm_table(dev
, &priv
->srq_table
.cmpt_table
);
452 mlx4_cleanup_icm_table(dev
, &priv
->qp_table
.cmpt_table
);
453 mlx4_unmap_eq_icm(dev
);
455 mlx4_UNMAP_ICM_AUX(dev
);
456 mlx4_free_icm(dev
, priv
->fw
.aux_icm
);
459 static void mlx4_close_hca(struct mlx4_dev
*dev
)
461 mlx4_CLOSE_HCA(dev
, 0);
464 mlx4_free_icm(dev
, mlx4_priv(dev
)->fw
.fw_icm
);
467 static int __devinit
mlx4_init_hca(struct mlx4_dev
*dev
)
469 struct mlx4_priv
*priv
= mlx4_priv(dev
);
470 struct mlx4_adapter adapter
;
471 struct mlx4_dev_cap dev_cap
;
472 struct mlx4_profile profile
;
473 struct mlx4_init_hca_param init_hca
;
477 err
= mlx4_QUERY_FW(dev
);
479 mlx4_err(dev
, "QUERY_FW command failed, aborting.\n");
483 err
= mlx4_load_fw(dev
);
485 mlx4_err(dev
, "Failed to start FW, aborting.\n");
489 err
= mlx4_dev_cap(dev
, &dev_cap
);
491 mlx4_err(dev
, "QUERY_DEV_CAP command failed, aborting.\n");
495 profile
= default_profile
;
497 icm_size
= mlx4_make_profile(dev
, &profile
, &dev_cap
, &init_hca
);
498 if ((long long) icm_size
< 0) {
503 init_hca
.log_uar_sz
= ilog2(dev
->caps
.num_uars
);
505 err
= mlx4_init_icm(dev
, &dev_cap
, &init_hca
, icm_size
);
509 err
= mlx4_INIT_HCA(dev
, &init_hca
);
511 mlx4_err(dev
, "INIT_HCA command failed, aborting.\n");
515 err
= mlx4_QUERY_ADAPTER(dev
, &adapter
);
517 mlx4_err(dev
, "QUERY_ADAPTER command failed, aborting.\n");
521 priv
->eq_table
.inta_pin
= adapter
.inta_pin
;
522 priv
->rev_id
= adapter
.revision_id
;
523 memcpy(priv
->board_id
, adapter
.board_id
, sizeof priv
->board_id
);
535 mlx4_free_icm(dev
, priv
->fw
.fw_icm
);
540 static int __devinit
mlx4_setup_hca(struct mlx4_dev
*dev
)
542 struct mlx4_priv
*priv
= mlx4_priv(dev
);
545 MLX4_INIT_DOORBELL_LOCK(&priv
->doorbell_lock
);
547 err
= mlx4_init_uar_table(dev
);
549 mlx4_err(dev
, "Failed to initialize "
550 "user access region table, aborting.\n");
554 err
= mlx4_uar_alloc(dev
, &priv
->driver_uar
);
556 mlx4_err(dev
, "Failed to allocate driver access region, "
558 goto err_uar_table_free
;
561 priv
->kar
= ioremap(priv
->driver_uar
.pfn
<< PAGE_SHIFT
, PAGE_SIZE
);
563 mlx4_err(dev
, "Couldn't map kernel access region, "
569 err
= mlx4_init_pd_table(dev
);
571 mlx4_err(dev
, "Failed to initialize "
572 "protection domain table, aborting.\n");
576 err
= mlx4_init_mr_table(dev
);
578 mlx4_err(dev
, "Failed to initialize "
579 "memory region table, aborting.\n");
580 goto err_pd_table_free
;
583 mlx4_map_catas_buf(dev
);
585 err
= mlx4_init_eq_table(dev
);
587 mlx4_err(dev
, "Failed to initialize "
588 "event queue table, aborting.\n");
592 err
= mlx4_cmd_use_events(dev
);
594 mlx4_err(dev
, "Failed to switch to event-driven "
595 "firmware commands, aborting.\n");
596 goto err_eq_table_free
;
601 mlx4_err(dev
, "NOP command failed to generate interrupt "
602 "(IRQ %d), aborting.\n",
603 priv
->eq_table
.eq
[MLX4_EQ_ASYNC
].irq
);
604 if (dev
->flags
& MLX4_FLAG_MSI_X
)
605 mlx4_err(dev
, "Try again with MSI-X disabled.\n");
607 mlx4_err(dev
, "BIOS or ACPI interrupt routing problem?\n");
612 mlx4_dbg(dev
, "NOP command IRQ test passed\n");
614 err
= mlx4_init_cq_table(dev
);
616 mlx4_err(dev
, "Failed to initialize "
617 "completion queue table, aborting.\n");
621 err
= mlx4_init_srq_table(dev
);
623 mlx4_err(dev
, "Failed to initialize "
624 "shared receive queue table, aborting.\n");
625 goto err_cq_table_free
;
628 err
= mlx4_init_qp_table(dev
);
630 mlx4_err(dev
, "Failed to initialize "
631 "queue pair table, aborting.\n");
632 goto err_srq_table_free
;
635 err
= mlx4_init_mcg_table(dev
);
637 mlx4_err(dev
, "Failed to initialize "
638 "multicast group table, aborting.\n");
639 goto err_qp_table_free
;
645 mlx4_cleanup_qp_table(dev
);
648 mlx4_cleanup_srq_table(dev
);
651 mlx4_cleanup_cq_table(dev
);
654 mlx4_cmd_use_polling(dev
);
657 mlx4_cleanup_eq_table(dev
);
660 mlx4_unmap_catas_buf(dev
);
661 mlx4_cleanup_mr_table(dev
);
664 mlx4_cleanup_pd_table(dev
);
670 mlx4_uar_free(dev
, &priv
->driver_uar
);
673 mlx4_cleanup_uar_table(dev
);
677 static void __devinit
mlx4_enable_msi_x(struct mlx4_dev
*dev
)
679 struct mlx4_priv
*priv
= mlx4_priv(dev
);
680 struct msix_entry entries
[MLX4_NUM_EQ
];
685 for (i
= 0; i
< MLX4_NUM_EQ
; ++i
)
686 entries
[i
].entry
= i
;
688 err
= pci_enable_msix(dev
->pdev
, entries
, ARRAY_SIZE(entries
));
691 mlx4_info(dev
, "Only %d MSI-X vectors available, "
692 "not using MSI-X\n", err
);
696 for (i
= 0; i
< MLX4_NUM_EQ
; ++i
)
697 priv
->eq_table
.eq
[i
].irq
= entries
[i
].vector
;
699 dev
->flags
|= MLX4_FLAG_MSI_X
;
704 for (i
= 0; i
< MLX4_NUM_EQ
; ++i
)
705 priv
->eq_table
.eq
[i
].irq
= dev
->pdev
->irq
;
708 static int __devinit
mlx4_init_one(struct pci_dev
*pdev
,
709 const struct pci_device_id
*id
)
711 static int mlx4_version_printed
;
712 struct mlx4_priv
*priv
;
713 struct mlx4_dev
*dev
;
716 if (!mlx4_version_printed
) {
717 printk(KERN_INFO
"%s", mlx4_version
);
718 ++mlx4_version_printed
;
721 printk(KERN_INFO PFX
"Initializing %s\n",
724 err
= pci_enable_device(pdev
);
726 dev_err(&pdev
->dev
, "Cannot enable PCI device, "
732 * Check for BARs. We expect 0: 1MB, 2: 8MB, 4: DDR (may not
735 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
) ||
736 pci_resource_len(pdev
, 0) != 1 << 20) {
737 dev_err(&pdev
->dev
, "Missing DCS, aborting.\n");
739 goto err_disable_pdev
;
741 if (!(pci_resource_flags(pdev
, 2) & IORESOURCE_MEM
)) {
742 dev_err(&pdev
->dev
, "Missing UAR, aborting.\n");
744 goto err_disable_pdev
;
747 err
= pci_request_region(pdev
, 0, DRV_NAME
);
749 dev_err(&pdev
->dev
, "Cannot request control region, aborting.\n");
750 goto err_disable_pdev
;
753 err
= pci_request_region(pdev
, 2, DRV_NAME
);
755 dev_err(&pdev
->dev
, "Cannot request UAR region, aborting.\n");
756 goto err_release_bar0
;
759 pci_set_master(pdev
);
761 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
763 dev_warn(&pdev
->dev
, "Warning: couldn't set 64-bit PCI DMA mask.\n");
764 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
766 dev_err(&pdev
->dev
, "Can't set PCI DMA mask, aborting.\n");
767 goto err_release_bar2
;
770 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
772 dev_warn(&pdev
->dev
, "Warning: couldn't set 64-bit "
773 "consistent PCI DMA mask.\n");
774 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
776 dev_err(&pdev
->dev
, "Can't set consistent PCI DMA mask, "
778 goto err_release_bar2
;
782 priv
= kzalloc(sizeof *priv
, GFP_KERNEL
);
784 dev_err(&pdev
->dev
, "Device struct alloc failed, "
787 goto err_release_bar2
;
794 * Now reset the HCA before we touch the PCI capabilities or
795 * attempt a firmware command, since a boot ROM may have left
796 * the HCA in an undefined state.
798 err
= mlx4_reset(dev
);
800 mlx4_err(dev
, "Failed to reset HCA, aborting.\n");
804 mlx4_enable_msi_x(dev
);
806 if (mlx4_cmd_init(dev
)) {
807 mlx4_err(dev
, "Failed to init command interface, aborting.\n");
811 err
= mlx4_init_hca(dev
);
815 err
= mlx4_setup_hca(dev
);
819 err
= mlx4_register_device(dev
);
823 pci_set_drvdata(pdev
, dev
);
828 mlx4_cleanup_mcg_table(dev
);
829 mlx4_cleanup_qp_table(dev
);
830 mlx4_cleanup_srq_table(dev
);
831 mlx4_cleanup_cq_table(dev
);
832 mlx4_cmd_use_polling(dev
);
833 mlx4_cleanup_eq_table(dev
);
835 mlx4_unmap_catas_buf(dev
);
837 mlx4_cleanup_mr_table(dev
);
838 mlx4_cleanup_pd_table(dev
);
839 mlx4_cleanup_uar_table(dev
);
845 mlx4_cmd_cleanup(dev
);
848 if (dev
->flags
& MLX4_FLAG_MSI_X
)
849 pci_disable_msix(pdev
);
854 pci_release_region(pdev
, 2);
857 pci_release_region(pdev
, 0);
860 pci_disable_device(pdev
);
861 pci_set_drvdata(pdev
, NULL
);
865 static void __devexit
mlx4_remove_one(struct pci_dev
*pdev
)
867 struct mlx4_dev
*dev
= pci_get_drvdata(pdev
);
868 struct mlx4_priv
*priv
= mlx4_priv(dev
);
872 mlx4_unregister_device(dev
);
874 for (p
= 1; p
<= dev
->caps
.num_ports
; ++p
)
875 mlx4_CLOSE_PORT(dev
, p
);
877 mlx4_cleanup_mcg_table(dev
);
878 mlx4_cleanup_qp_table(dev
);
879 mlx4_cleanup_srq_table(dev
);
880 mlx4_cleanup_cq_table(dev
);
881 mlx4_cmd_use_polling(dev
);
882 mlx4_cleanup_eq_table(dev
);
884 mlx4_unmap_catas_buf(dev
);
886 mlx4_cleanup_mr_table(dev
);
887 mlx4_cleanup_pd_table(dev
);
890 mlx4_uar_free(dev
, &priv
->driver_uar
);
891 mlx4_cleanup_uar_table(dev
);
893 mlx4_cmd_cleanup(dev
);
895 if (dev
->flags
& MLX4_FLAG_MSI_X
)
896 pci_disable_msix(pdev
);
899 pci_release_region(pdev
, 2);
900 pci_release_region(pdev
, 0);
901 pci_disable_device(pdev
);
902 pci_set_drvdata(pdev
, NULL
);
906 static struct pci_device_id mlx4_pci_table
[] = {
907 { PCI_VDEVICE(MELLANOX
, 0x6340) }, /* MT25408 "Hermon" SDR */
908 { PCI_VDEVICE(MELLANOX
, 0x634a) }, /* MT25408 "Hermon" DDR */
909 { PCI_VDEVICE(MELLANOX
, 0x6354) }, /* MT25408 "Hermon" QDR */
913 MODULE_DEVICE_TABLE(pci
, mlx4_pci_table
);
915 static struct pci_driver mlx4_driver
= {
917 .id_table
= mlx4_pci_table
,
918 .probe
= mlx4_init_one
,
919 .remove
= __devexit_p(mlx4_remove_one
)
922 static int __init
mlx4_init(void)
926 ret
= pci_register_driver(&mlx4_driver
);
927 return ret
< 0 ? ret
: 0;
930 static void __exit
mlx4_cleanup(void)
932 pci_unregister_driver(&mlx4_driver
);
935 module_init(mlx4_init
);
936 module_exit(mlx4_cleanup
);