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)
93 err = mlx4_QUERY_DEV_CAP(dev, dev_cap);
95 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
99 if (dev_cap->min_page_sz > PAGE_SIZE) {
100 mlx4_err(dev, "HCA minimum page size of %d bigger than "
101 "kernel PAGE_SIZE of %ld, aborting.\n",
102 dev_cap->min_page_sz, PAGE_SIZE);
105 if (dev_cap->num_ports > MLX4_MAX_PORTS) {
106 mlx4_err(dev, "HCA has %d ports, but we only support %d, "
108 dev_cap->num_ports, MLX4_MAX_PORTS);
112 if (dev_cap->uar_size > pci_resource_len(dev->pdev, 2)) {
113 mlx4_err(dev, "HCA reported UAR size of 0x%x bigger than "
114 "PCI resource 2 size of 0x%llx, aborting.\n",
116 (unsigned long long) pci_resource_len(dev->pdev, 2));
120 dev->caps.num_ports = dev_cap->num_ports;
121 for (i = 1; i <= dev->caps.num_ports; ++i) {
122 dev->caps.vl_cap[i] = dev_cap->max_vl[i];
123 dev->caps.mtu_cap[i] = dev_cap->max_mtu[i];
124 dev->caps.gid_table_len[i] = dev_cap->max_gids[i];
125 dev->caps.pkey_table_len[i] = dev_cap->max_pkeys[i];
126 dev->caps.port_width_cap[i] = dev_cap->max_port_width[i];
129 dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE;
130 dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay;
131 dev->caps.bf_reg_size = dev_cap->bf_reg_size;
132 dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page;
133 dev->caps.max_sq_sg = dev_cap->max_sq_sg;
134 dev->caps.max_rq_sg = dev_cap->max_rq_sg;
135 dev->caps.max_wqes = dev_cap->max_qp_sz;
136 dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp;
137 dev->caps.reserved_qps = dev_cap->reserved_qps;
138 dev->caps.max_srq_wqes = dev_cap->max_srq_sz;
139 dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1;
140 dev->caps.reserved_srqs = dev_cap->reserved_srqs;
141 dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz;
142 dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz;
143 dev->caps.num_qp_per_mgm = MLX4_QP_PER_MGM;
145 * Subtract 1 from the limit because we need to allocate a
146 * spare CQE so the HCA HW can tell the difference between an
147 * empty CQ and a full CQ.
149 dev->caps.max_cqes = dev_cap->max_cq_sz - 1;
150 dev->caps.reserved_cqs = dev_cap->reserved_cqs;
151 dev->caps.reserved_eqs = dev_cap->reserved_eqs;
152 dev->caps.reserved_mtts = dev_cap->reserved_mtts;
153 dev->caps.reserved_mrws = dev_cap->reserved_mrws;
154 dev->caps.reserved_uars = dev_cap->reserved_uars;
155 dev->caps.reserved_pds = dev_cap->reserved_pds;
156 dev->caps.mtt_entry_sz = MLX4_MTT_ENTRY_PER_SEG * dev_cap->mtt_entry_sz;
157 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
158 dev->caps.flags = dev_cap->flags;
159 dev->caps.stat_rate_support = dev_cap->stat_rate_support;
164 static int __devinit mlx4_load_fw(struct mlx4_dev *dev)
166 struct mlx4_priv *priv = mlx4_priv(dev);
169 priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages,
170 GFP_HIGHUSER | __GFP_NOWARN);
171 if (!priv->fw.fw_icm) {
172 mlx4_err(dev, "Couldn't allocate FW area, aborting.\n");
176 err = mlx4_MAP_FA(dev, priv->fw.fw_icm);
178 mlx4_err(dev, "MAP_FA command failed, aborting.\n");
182 err = mlx4_RUN_FW(dev);
184 mlx4_err(dev, "RUN_FW command failed, aborting.\n");
194 mlx4_free_icm(dev, priv->fw.fw_icm);
198 static int __devinit mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
201 struct mlx4_priv *priv = mlx4_priv(dev);
204 err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table,
206 ((u64) (MLX4_CMPT_TYPE_QP *
207 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
208 cmpt_entry_sz, dev->caps.num_qps,
209 dev->caps.reserved_qps, 0);
213 err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table,
215 ((u64) (MLX4_CMPT_TYPE_SRQ *
216 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
217 cmpt_entry_sz, dev->caps.num_srqs,
218 dev->caps.reserved_srqs, 0);
222 err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table,
224 ((u64) (MLX4_CMPT_TYPE_CQ *
225 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
226 cmpt_entry_sz, dev->caps.num_cqs,
227 dev->caps.reserved_cqs, 0);
231 err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table,
233 ((u64) (MLX4_CMPT_TYPE_EQ *
234 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
236 roundup_pow_of_two(MLX4_NUM_EQ +
237 dev->caps.reserved_eqs),
238 MLX4_NUM_EQ + dev->caps.reserved_eqs, 0);
245 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
248 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
251 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
257 static int __devinit mlx4_init_icm(struct mlx4_dev *dev,
258 struct mlx4_dev_cap *dev_cap,
259 struct mlx4_init_hca_param *init_hca,
262 struct mlx4_priv *priv = mlx4_priv(dev);
266 err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages);
268 mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n");
272 mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n",
273 (unsigned long long) icm_size >> 10,
274 (unsigned long long) aux_pages << 2);
276 priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages,
277 GFP_HIGHUSER | __GFP_NOWARN);
278 if (!priv->fw.aux_icm) {
279 mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n");
283 err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm);
285 mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n");
289 err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz);
291 mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n");
295 err = mlx4_map_eq_icm(dev, init_hca->eqc_base);
297 mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
301 err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
303 dev->caps.mtt_entry_sz,
304 dev->caps.num_mtt_segs,
305 dev->caps.reserved_mtts, 1);
307 mlx4_err(dev, "Failed to map MTT context memory, aborting.\n");
311 err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table,
313 dev_cap->dmpt_entry_sz,
315 dev->caps.reserved_mrws, 1);
317 mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n");
321 err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table,
323 dev_cap->qpc_entry_sz,
325 dev->caps.reserved_qps, 0);
327 mlx4_err(dev, "Failed to map QP context memory, aborting.\n");
331 err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table,
333 dev_cap->aux_entry_sz,
335 dev->caps.reserved_qps, 0);
337 mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n");
341 err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table,
343 dev_cap->altc_entry_sz,
345 dev->caps.reserved_qps, 0);
347 mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n");
351 err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table,
352 init_hca->rdmarc_base,
353 dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift,
355 dev->caps.reserved_qps, 0);
357 mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n");
361 err = mlx4_init_icm_table(dev, &priv->cq_table.table,
363 dev_cap->cqc_entry_sz,
365 dev->caps.reserved_cqs, 0);
367 mlx4_err(dev, "Failed to map CQ context memory, aborting.\n");
368 goto err_unmap_rdmarc;
371 err = mlx4_init_icm_table(dev, &priv->srq_table.table,
373 dev_cap->srq_entry_sz,
375 dev->caps.reserved_srqs, 0);
377 mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
382 * It's not strictly required, but for simplicity just map the
383 * whole multicast group table now. The table isn't very big
384 * and it's a lot easier than trying to track ref counts.
386 err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
387 init_hca->mc_base, MLX4_MGM_ENTRY_SIZE,
388 dev->caps.num_mgms + dev->caps.num_amgms,
389 dev->caps.num_mgms + dev->caps.num_amgms,
392 mlx4_err(dev, "Failed to map MCG context memory, aborting.\n");
399 mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
402 mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
405 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
408 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
411 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
414 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
417 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
420 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
423 mlx4_unmap_eq_icm(dev);
426 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
427 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
428 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
429 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
432 mlx4_UNMAP_ICM_AUX(dev);
435 mlx4_free_icm(dev, priv->fw.aux_icm);
440 static void mlx4_free_icms(struct mlx4_dev *dev)
442 struct mlx4_priv *priv = mlx4_priv(dev);
444 mlx4_cleanup_icm_table(dev, &priv->mcg_table.table);
445 mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
446 mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
447 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
448 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
449 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
450 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
451 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
452 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
453 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
454 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
455 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
456 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
457 mlx4_unmap_eq_icm(dev);
459 mlx4_UNMAP_ICM_AUX(dev);
460 mlx4_free_icm(dev, priv->fw.aux_icm);
463 static void mlx4_close_hca(struct mlx4_dev *dev)
465 mlx4_CLOSE_HCA(dev, 0);
468 mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm);
471 static int __devinit mlx4_init_hca(struct mlx4_dev *dev)
473 struct mlx4_priv *priv = mlx4_priv(dev);
474 struct mlx4_adapter adapter;
475 struct mlx4_dev_cap dev_cap;
476 struct mlx4_profile profile;
477 struct mlx4_init_hca_param init_hca;
481 err = mlx4_QUERY_FW(dev);
483 mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
487 err = mlx4_load_fw(dev);
489 mlx4_err(dev, "Failed to start FW, aborting.\n");
493 err = mlx4_dev_cap(dev, &dev_cap);
495 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
499 profile = default_profile;
501 icm_size = mlx4_make_profile(dev, &profile, &dev_cap, &init_hca);
502 if ((long long) icm_size < 0) {
507 init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
509 err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
513 err = mlx4_INIT_HCA(dev, &init_hca);
515 mlx4_err(dev, "INIT_HCA command failed, aborting.\n");
519 err = mlx4_QUERY_ADAPTER(dev, &adapter);
521 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
525 priv->eq_table.inta_pin = adapter.inta_pin;
526 priv->rev_id = adapter.revision_id;
527 memcpy(priv->board_id, adapter.board_id, sizeof priv->board_id);
539 mlx4_free_icm(dev, priv->fw.fw_icm);
544 static int __devinit mlx4_setup_hca(struct mlx4_dev *dev)
546 struct mlx4_priv *priv = mlx4_priv(dev);
549 err = mlx4_init_uar_table(dev);
551 mlx4_err(dev, "Failed to initialize "
552 "user access region table, aborting.\n");
556 err = mlx4_uar_alloc(dev, &priv->driver_uar);
558 mlx4_err(dev, "Failed to allocate driver access region, "
560 goto err_uar_table_free;
563 priv->kar = ioremap(priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
565 mlx4_err(dev, "Couldn't map kernel access region, "
571 err = mlx4_init_pd_table(dev);
573 mlx4_err(dev, "Failed to initialize "
574 "protection domain table, aborting.\n");
578 err = mlx4_init_mr_table(dev);
580 mlx4_err(dev, "Failed to initialize "
581 "memory region table, aborting.\n");
582 goto err_pd_table_free;
585 mlx4_map_catas_buf(dev);
587 err = mlx4_init_eq_table(dev);
589 mlx4_err(dev, "Failed to initialize "
590 "event queue table, aborting.\n");
594 err = mlx4_cmd_use_events(dev);
596 mlx4_err(dev, "Failed to switch to event-driven "
597 "firmware commands, aborting.\n");
598 goto err_eq_table_free;
603 mlx4_err(dev, "NOP command failed to generate interrupt "
604 "(IRQ %d), aborting.\n",
605 priv->eq_table.eq[MLX4_EQ_ASYNC].irq);
606 if (dev->flags & MLX4_FLAG_MSI_X)
607 mlx4_err(dev, "Try again with MSI-X disabled.\n");
609 mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
614 mlx4_dbg(dev, "NOP command IRQ test passed\n");
616 err = mlx4_init_cq_table(dev);
618 mlx4_err(dev, "Failed to initialize "
619 "completion queue table, aborting.\n");
623 err = mlx4_init_srq_table(dev);
625 mlx4_err(dev, "Failed to initialize "
626 "shared receive queue table, aborting.\n");
627 goto err_cq_table_free;
630 err = mlx4_init_qp_table(dev);
632 mlx4_err(dev, "Failed to initialize "
633 "queue pair table, aborting.\n");
634 goto err_srq_table_free;
637 err = mlx4_init_mcg_table(dev);
639 mlx4_err(dev, "Failed to initialize "
640 "multicast group table, aborting.\n");
641 goto err_qp_table_free;
647 mlx4_cleanup_qp_table(dev);
650 mlx4_cleanup_srq_table(dev);
653 mlx4_cleanup_cq_table(dev);
656 mlx4_cmd_use_polling(dev);
659 mlx4_cleanup_eq_table(dev);
662 mlx4_unmap_catas_buf(dev);
663 mlx4_cleanup_mr_table(dev);
666 mlx4_cleanup_pd_table(dev);
672 mlx4_uar_free(dev, &priv->driver_uar);
675 mlx4_cleanup_uar_table(dev);
679 static void __devinit mlx4_enable_msi_x(struct mlx4_dev *dev)
681 struct mlx4_priv *priv = mlx4_priv(dev);
682 struct msix_entry entries[MLX4_NUM_EQ];
687 for (i = 0; i < MLX4_NUM_EQ; ++i)
688 entries[i].entry = i;
690 err = pci_enable_msix(dev->pdev, entries, ARRAY_SIZE(entries));
693 mlx4_info(dev, "Only %d MSI-X vectors available, "
694 "not using MSI-X\n", err);
698 for (i = 0; i < MLX4_NUM_EQ; ++i)
699 priv->eq_table.eq[i].irq = entries[i].vector;
701 dev->flags |= MLX4_FLAG_MSI_X;
706 for (i = 0; i < MLX4_NUM_EQ; ++i)
707 priv->eq_table.eq[i].irq = dev->pdev->irq;
710 static int __devinit mlx4_init_one(struct pci_dev *pdev,
711 const struct pci_device_id *id)
713 static int mlx4_version_printed;
714 struct mlx4_priv *priv;
715 struct mlx4_dev *dev;
718 if (!mlx4_version_printed) {
719 printk(KERN_INFO "%s", mlx4_version);
720 ++mlx4_version_printed;
723 printk(KERN_INFO PFX "Initializing %s\n",
726 err = pci_enable_device(pdev);
728 dev_err(&pdev->dev, "Cannot enable PCI device, "
734 * Check for BARs. We expect 0: 1MB, 2: 8MB, 4: DDR (may not
737 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
738 pci_resource_len(pdev, 0) != 1 << 20) {
739 dev_err(&pdev->dev, "Missing DCS, aborting.\n");
741 goto err_disable_pdev;
743 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
744 dev_err(&pdev->dev, "Missing UAR, aborting.\n");
746 goto err_disable_pdev;
749 err = pci_request_region(pdev, 0, DRV_NAME);
751 dev_err(&pdev->dev, "Cannot request control region, aborting.\n");
752 goto err_disable_pdev;
755 err = pci_request_region(pdev, 2, DRV_NAME);
757 dev_err(&pdev->dev, "Cannot request UAR region, aborting.\n");
758 goto err_release_bar0;
761 pci_set_master(pdev);
763 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
765 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
766 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
768 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
769 goto err_release_bar2;
772 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
774 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
775 "consistent PCI DMA mask.\n");
776 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
778 dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
780 goto err_release_bar2;
784 priv = kzalloc(sizeof *priv, GFP_KERNEL);
786 dev_err(&pdev->dev, "Device struct alloc failed, "
789 goto err_release_bar2;
794 INIT_LIST_HEAD(&priv->ctx_list);
795 spin_lock_init(&priv->ctx_lock);
798 * Now reset the HCA before we touch the PCI capabilities or
799 * attempt a firmware command, since a boot ROM may have left
800 * the HCA in an undefined state.
802 err = mlx4_reset(dev);
804 mlx4_err(dev, "Failed to reset HCA, aborting.\n");
808 mlx4_enable_msi_x(dev);
810 if (mlx4_cmd_init(dev)) {
811 mlx4_err(dev, "Failed to init command interface, aborting.\n");
815 err = mlx4_init_hca(dev);
819 err = mlx4_setup_hca(dev);
823 err = mlx4_register_device(dev);
827 pci_set_drvdata(pdev, dev);
832 mlx4_cleanup_mcg_table(dev);
833 mlx4_cleanup_qp_table(dev);
834 mlx4_cleanup_srq_table(dev);
835 mlx4_cleanup_cq_table(dev);
836 mlx4_cmd_use_polling(dev);
837 mlx4_cleanup_eq_table(dev);
839 mlx4_unmap_catas_buf(dev);
841 mlx4_cleanup_mr_table(dev);
842 mlx4_cleanup_pd_table(dev);
843 mlx4_cleanup_uar_table(dev);
849 mlx4_cmd_cleanup(dev);
852 if (dev->flags & MLX4_FLAG_MSI_X)
853 pci_disable_msix(pdev);
858 pci_release_region(pdev, 2);
861 pci_release_region(pdev, 0);
864 pci_disable_device(pdev);
865 pci_set_drvdata(pdev, NULL);
869 static void __devexit mlx4_remove_one(struct pci_dev *pdev)
871 struct mlx4_dev *dev = pci_get_drvdata(pdev);
872 struct mlx4_priv *priv = mlx4_priv(dev);
876 mlx4_unregister_device(dev);
878 for (p = 1; p <= dev->caps.num_ports; ++p)
879 mlx4_CLOSE_PORT(dev, p);
881 mlx4_cleanup_mcg_table(dev);
882 mlx4_cleanup_qp_table(dev);
883 mlx4_cleanup_srq_table(dev);
884 mlx4_cleanup_cq_table(dev);
885 mlx4_cmd_use_polling(dev);
886 mlx4_cleanup_eq_table(dev);
888 mlx4_unmap_catas_buf(dev);
890 mlx4_cleanup_mr_table(dev);
891 mlx4_cleanup_pd_table(dev);
894 mlx4_uar_free(dev, &priv->driver_uar);
895 mlx4_cleanup_uar_table(dev);
897 mlx4_cmd_cleanup(dev);
899 if (dev->flags & MLX4_FLAG_MSI_X)
900 pci_disable_msix(pdev);
903 pci_release_region(pdev, 2);
904 pci_release_region(pdev, 0);
905 pci_disable_device(pdev);
906 pci_set_drvdata(pdev, NULL);
910 static struct pci_device_id mlx4_pci_table[] = {
911 { PCI_VDEVICE(MELLANOX, 0x6340) }, /* MT25408 "Hermon" SDR */
912 { PCI_VDEVICE(MELLANOX, 0x634a) }, /* MT25408 "Hermon" DDR */
913 { PCI_VDEVICE(MELLANOX, 0x6354) }, /* MT25408 "Hermon" QDR */
917 MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
919 static struct pci_driver mlx4_driver = {
921 .id_table = mlx4_pci_table,
922 .probe = mlx4_init_one,
923 .remove = __devexit_p(mlx4_remove_one)
926 static int __init mlx4_init(void)
930 ret = pci_register_driver(&mlx4_driver);
931 return ret < 0 ? ret : 0;
934 static void __exit mlx4_cleanup(void)
936 pci_unregister_driver(&mlx4_driver);
939 module_init(mlx4_init);
940 module_exit(mlx4_cleanup);