Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. |
| 3 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
Jack Morgenstein | 51a379d | 2008-07-25 10:32:52 -0700 | [diff] [blame] | 4 | * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved. |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 5 | * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved. |
| 6 | * |
| 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: |
| 12 | * |
| 13 | * Redistribution and use in source and binary forms, with or |
| 14 | * without modification, are permitted provided that the following |
| 15 | * conditions are met: |
| 16 | * |
| 17 | * - Redistributions of source code must retain the above |
| 18 | * copyright notice, this list of conditions and the following |
| 19 | * disclaimer. |
| 20 | * |
| 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. |
| 25 | * |
| 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 |
| 33 | * SOFTWARE. |
| 34 | */ |
| 35 | |
| 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Eli Cohen | c1b43dc | 2011-03-22 22:38:41 +0000 | [diff] [blame] | 42 | #include <linux/io-mapping.h> |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 43 | #include <linux/delay.h> |
Yuval Mintz | 90b1ebe | 2012-07-01 03:18:51 +0000 | [diff] [blame] | 44 | #include <linux/netdevice.h> |
Eyal Perry | b046ffe | 2013-10-15 16:55:24 +0200 | [diff] [blame] | 45 | #include <linux/kmod.h> |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 46 | |
| 47 | #include <linux/mlx4/device.h> |
| 48 | #include <linux/mlx4/doorbell.h> |
| 49 | |
| 50 | #include "mlx4.h" |
| 51 | #include "fw.h" |
| 52 | #include "icm.h" |
| 53 | |
| 54 | MODULE_AUTHOR("Roland Dreier"); |
| 55 | MODULE_DESCRIPTION("Mellanox ConnectX HCA low-level driver"); |
| 56 | MODULE_LICENSE("Dual BSD/GPL"); |
| 57 | MODULE_VERSION(DRV_VERSION); |
| 58 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 59 | struct workqueue_struct *mlx4_wq; |
| 60 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 61 | #ifdef CONFIG_MLX4_DEBUG |
| 62 | |
| 63 | int mlx4_debug_level = 0; |
| 64 | module_param_named(debug_level, mlx4_debug_level, int, 0644); |
| 65 | MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0"); |
| 66 | |
| 67 | #endif /* CONFIG_MLX4_DEBUG */ |
| 68 | |
| 69 | #ifdef CONFIG_PCI_MSI |
| 70 | |
Michael S. Tsirkin | 08fb105 | 2007-08-07 16:08:28 +0300 | [diff] [blame] | 71 | static int msi_x = 1; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 72 | module_param(msi_x, int, 0444); |
| 73 | MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero"); |
| 74 | |
| 75 | #else /* CONFIG_PCI_MSI */ |
| 76 | |
| 77 | #define msi_x (0) |
| 78 | |
| 79 | #endif /* CONFIG_PCI_MSI */ |
| 80 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 81 | static int num_vfs; |
| 82 | module_param(num_vfs, int, 0444); |
| 83 | MODULE_PARM_DESC(num_vfs, "enable #num_vfs functions if num_vfs > 0"); |
| 84 | |
| 85 | static int probe_vf; |
| 86 | module_param(probe_vf, int, 0644); |
| 87 | MODULE_PARM_DESC(probe_vf, "number of vfs to probe by pf driver (num_vfs > 0)"); |
| 88 | |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 89 | int mlx4_log_num_mgm_entry_size = MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE; |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 90 | module_param_named(log_num_mgm_entry_size, |
| 91 | mlx4_log_num_mgm_entry_size, int, 0444); |
| 92 | MODULE_PARM_DESC(log_num_mgm_entry_size, "log mgm size, that defines the num" |
| 93 | " of qp per mcg, for example:" |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 94 | " 10 gives 248.range: 7 <=" |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 95 | " log_num_mgm_entry_size <= 12." |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 96 | " To activate device managed" |
| 97 | " flow steering when available, set to -1"); |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 98 | |
Eyal Perry | be902ab | 2013-12-19 21:20:15 +0200 | [diff] [blame] | 99 | static bool enable_64b_cqe_eqe = true; |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 100 | module_param(enable_64b_cqe_eqe, bool, 0444); |
| 101 | MODULE_PARM_DESC(enable_64b_cqe_eqe, |
Eyal Perry | be902ab | 2013-12-19 21:20:15 +0200 | [diff] [blame] | 102 | "Enable 64 byte CQEs/EQEs when the FW supports this (default: True)"); |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 103 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 104 | #define HCA_GLOBAL_CAP_MASK 0 |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 105 | |
| 106 | #define PF_CONTEXT_BEHAVIOUR_MASK MLX4_FUNC_CAP_64B_EQE_CQE |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 107 | |
Bill Pemberton | f57e684 | 2012-12-03 09:23:15 -0500 | [diff] [blame] | 108 | static char mlx4_version[] = |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 109 | DRV_NAME ": Mellanox ConnectX core driver v" |
| 110 | DRV_VERSION " (" DRV_RELDATE ")\n"; |
| 111 | |
| 112 | static struct mlx4_profile default_profile = { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 113 | .num_qp = 1 << 18, |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 114 | .num_srq = 1 << 16, |
Jack Morgenstein | c9f2ba5 | 2007-07-17 13:11:43 +0300 | [diff] [blame] | 115 | .rdmarc_per_qp = 1 << 4, |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 116 | .num_cq = 1 << 16, |
| 117 | .num_mcg = 1 << 13, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 118 | .num_mpt = 1 << 19, |
Marcel Apfelbaum | 9fd7a1e | 2012-01-19 09:45:31 +0000 | [diff] [blame] | 119 | .num_mtt = 1 << 20, /* It is really num mtt segements */ |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 122 | static int log_num_mac = 7; |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 123 | module_param_named(log_num_mac, log_num_mac, int, 0444); |
| 124 | MODULE_PARM_DESC(log_num_mac, "Log2 max number of MACs per ETH port (1-7)"); |
| 125 | |
| 126 | static int log_num_vlan; |
| 127 | module_param_named(log_num_vlan, log_num_vlan, int, 0444); |
| 128 | MODULE_PARM_DESC(log_num_vlan, "Log2 max number of VLANs per ETH port (0-7)"); |
Or Gerlitz | cb29688 | 2011-10-16 10:26:21 +0200 | [diff] [blame] | 129 | /* Log2 max number of VLANs per ETH port (0-7) */ |
| 130 | #define MLX4_LOG_NUM_VLANS 7 |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 131 | |
Rusty Russell | eb93992 | 2011-12-19 14:08:01 +0000 | [diff] [blame] | 132 | static bool use_prio; |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 133 | module_param_named(use_prio, use_prio, bool, 0444); |
| 134 | MODULE_PARM_DESC(use_prio, "Enable steering by VLAN priority on ETH ports " |
| 135 | "(0/1, default 0)"); |
| 136 | |
Marcel Apfelbaum | 2b8fb28 | 2011-12-13 04:16:56 +0000 | [diff] [blame] | 137 | int log_mtts_per_seg = ilog2(MLX4_MTT_ENTRY_PER_SEG); |
Eli Cohen | ab6bf42 | 2009-05-27 14:38:34 -0700 | [diff] [blame] | 138 | module_param_named(log_mtts_per_seg, log_mtts_per_seg, int, 0444); |
Eli Cohen | 0498628 | 2010-09-20 08:42:38 +0200 | [diff] [blame] | 139 | MODULE_PARM_DESC(log_mtts_per_seg, "Log2 number of MTT entries per segment (1-7)"); |
Eli Cohen | ab6bf42 | 2009-05-27 14:38:34 -0700 | [diff] [blame] | 140 | |
Yevgeny Petrilin | 8d0fc7b | 2011-12-19 04:00:34 +0000 | [diff] [blame] | 141 | static int port_type_array[2] = {MLX4_PORT_TYPE_NONE, MLX4_PORT_TYPE_NONE}; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 142 | static int arr_argc = 2; |
| 143 | module_param_array(port_type_array, int, &arr_argc, 0444); |
Yevgeny Petrilin | 8d0fc7b | 2011-12-19 04:00:34 +0000 | [diff] [blame] | 144 | MODULE_PARM_DESC(port_type_array, "Array of port types: HW_DEFAULT (0) is default " |
| 145 | "1 for IB, 2 for Ethernet"); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 146 | |
| 147 | struct mlx4_port_config { |
| 148 | struct list_head list; |
| 149 | enum mlx4_port_type port_type[MLX4_MAX_PORTS + 1]; |
| 150 | struct pci_dev *pdev; |
| 151 | }; |
| 152 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 153 | int mlx4_check_port_params(struct mlx4_dev *dev, |
| 154 | enum mlx4_port_type *port_type) |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 155 | { |
| 156 | int i; |
| 157 | |
| 158 | for (i = 0; i < dev->caps.num_ports - 1; i++) { |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 159 | if (port_type[i] != port_type[i + 1]) { |
| 160 | if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) { |
| 161 | mlx4_err(dev, "Only same port types supported " |
| 162 | "on this HCA, aborting.\n"); |
| 163 | return -EINVAL; |
| 164 | } |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 167 | |
| 168 | for (i = 0; i < dev->caps.num_ports; i++) { |
| 169 | if (!(port_type[i] & dev->caps.supported_type[i+1])) { |
| 170 | mlx4_err(dev, "Requested port type for port %d is not " |
| 171 | "supported on this HCA\n", i + 1); |
| 172 | return -EINVAL; |
| 173 | } |
| 174 | } |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static void mlx4_set_port_mask(struct mlx4_dev *dev) |
| 179 | { |
| 180 | int i; |
| 181 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 182 | for (i = 1; i <= dev->caps.num_ports; ++i) |
Jack Morgenstein | 65dab25 | 2011-12-13 04:10:41 +0000 | [diff] [blame] | 183 | dev->caps.port_mask[i] = dev->caps.port_type[i]; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 184 | } |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 185 | |
Roland Dreier | 3d73c28 | 2007-10-10 15:43:54 -0700 | [diff] [blame] | 186 | static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 187 | { |
| 188 | int err; |
Roland Dreier | 5ae2a7a | 2007-06-18 08:15:02 -0700 | [diff] [blame] | 189 | int i; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 190 | |
| 191 | err = mlx4_QUERY_DEV_CAP(dev, dev_cap); |
| 192 | if (err) { |
| 193 | mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); |
| 194 | return err; |
| 195 | } |
| 196 | |
| 197 | if (dev_cap->min_page_sz > PAGE_SIZE) { |
| 198 | mlx4_err(dev, "HCA minimum page size of %d bigger than " |
| 199 | "kernel PAGE_SIZE of %ld, aborting.\n", |
| 200 | dev_cap->min_page_sz, PAGE_SIZE); |
| 201 | return -ENODEV; |
| 202 | } |
| 203 | if (dev_cap->num_ports > MLX4_MAX_PORTS) { |
| 204 | mlx4_err(dev, "HCA has %d ports, but we only support %d, " |
| 205 | "aborting.\n", |
| 206 | dev_cap->num_ports, MLX4_MAX_PORTS); |
| 207 | return -ENODEV; |
| 208 | } |
| 209 | |
| 210 | if (dev_cap->uar_size > pci_resource_len(dev->pdev, 2)) { |
| 211 | mlx4_err(dev, "HCA reported UAR size of 0x%x bigger than " |
| 212 | "PCI resource 2 size of 0x%llx, aborting.\n", |
| 213 | dev_cap->uar_size, |
| 214 | (unsigned long long) pci_resource_len(dev->pdev, 2)); |
| 215 | return -ENODEV; |
| 216 | } |
| 217 | |
| 218 | dev->caps.num_ports = dev_cap->num_ports; |
Marcel Apfelbaum | 3fc929e | 2012-05-30 09:14:51 +0000 | [diff] [blame] | 219 | dev->phys_caps.num_phys_eqs = MLX4_MAX_EQ_NUM; |
Roland Dreier | 5ae2a7a | 2007-06-18 08:15:02 -0700 | [diff] [blame] | 220 | for (i = 1; i <= dev->caps.num_ports; ++i) { |
| 221 | dev->caps.vl_cap[i] = dev_cap->max_vl[i]; |
Yevgeny Petrilin | b79acb4 | 2008-10-22 10:56:48 -0700 | [diff] [blame] | 222 | dev->caps.ib_mtu_cap[i] = dev_cap->ib_mtu[i]; |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 223 | dev->phys_caps.gid_phys_table_len[i] = dev_cap->max_gids[i]; |
| 224 | dev->phys_caps.pkey_phys_table_len[i] = dev_cap->max_pkeys[i]; |
| 225 | /* set gid and pkey table operating lengths by default |
| 226 | * to non-sriov values */ |
Roland Dreier | 5ae2a7a | 2007-06-18 08:15:02 -0700 | [diff] [blame] | 227 | dev->caps.gid_table_len[i] = dev_cap->max_gids[i]; |
| 228 | dev->caps.pkey_table_len[i] = dev_cap->max_pkeys[i]; |
| 229 | dev->caps.port_width_cap[i] = dev_cap->max_port_width[i]; |
Yevgeny Petrilin | b79acb4 | 2008-10-22 10:56:48 -0700 | [diff] [blame] | 230 | dev->caps.eth_mtu_cap[i] = dev_cap->eth_mtu[i]; |
| 231 | dev->caps.def_mac[i] = dev_cap->def_mac[i]; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 232 | dev->caps.supported_type[i] = dev_cap->supported_port_types[i]; |
Yevgeny Petrilin | 8d0fc7b | 2011-12-19 04:00:34 +0000 | [diff] [blame] | 233 | dev->caps.suggested_type[i] = dev_cap->suggested_type[i]; |
| 234 | dev->caps.default_sense[i] = dev_cap->default_sense[i]; |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 235 | dev->caps.trans_type[i] = dev_cap->trans_type[i]; |
| 236 | dev->caps.vendor_oui[i] = dev_cap->vendor_oui[i]; |
| 237 | dev->caps.wavelength[i] = dev_cap->wavelength[i]; |
| 238 | dev->caps.trans_code[i] = dev_cap->trans_code[i]; |
Roland Dreier | 5ae2a7a | 2007-06-18 08:15:02 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 241 | dev->caps.uar_page_size = PAGE_SIZE; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 242 | dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 243 | dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay; |
| 244 | dev->caps.bf_reg_size = dev_cap->bf_reg_size; |
| 245 | dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page; |
| 246 | dev->caps.max_sq_sg = dev_cap->max_sq_sg; |
| 247 | dev->caps.max_rq_sg = dev_cap->max_rq_sg; |
| 248 | dev->caps.max_wqes = dev_cap->max_qp_sz; |
| 249 | dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 250 | dev->caps.max_srq_wqes = dev_cap->max_srq_sz; |
| 251 | dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1; |
| 252 | dev->caps.reserved_srqs = dev_cap->reserved_srqs; |
| 253 | dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz; |
| 254 | dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 255 | /* |
| 256 | * Subtract 1 from the limit because we need to allocate a |
| 257 | * spare CQE so the HCA HW can tell the difference between an |
| 258 | * empty CQ and a full CQ. |
| 259 | */ |
| 260 | dev->caps.max_cqes = dev_cap->max_cq_sz - 1; |
| 261 | dev->caps.reserved_cqs = dev_cap->reserved_cqs; |
| 262 | dev->caps.reserved_eqs = dev_cap->reserved_eqs; |
Marcel Apfelbaum | 2b8fb28 | 2011-12-13 04:16:56 +0000 | [diff] [blame] | 263 | dev->caps.reserved_mtts = dev_cap->reserved_mtts; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 264 | dev->caps.reserved_mrws = dev_cap->reserved_mrws; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 265 | |
| 266 | /* The first 128 UARs are used for EQ doorbells */ |
| 267 | dev->caps.reserved_uars = max_t(int, 128, dev_cap->reserved_uars); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 268 | dev->caps.reserved_pds = dev_cap->reserved_pds; |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 269 | dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? |
| 270 | dev_cap->reserved_xrcds : 0; |
| 271 | dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? |
| 272 | dev_cap->max_xrcds : 0; |
Marcel Apfelbaum | 2b8fb28 | 2011-12-13 04:16:56 +0000 | [diff] [blame] | 273 | dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz; |
| 274 | |
Dotan Barak | 149983af | 2007-06-26 15:55:28 +0300 | [diff] [blame] | 275 | dev->caps.max_msg_sz = dev_cap->max_msg_sz; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 276 | dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1); |
| 277 | dev->caps.flags = dev_cap->flags; |
Shlomo Pongratz | b3416f4 | 2012-04-29 17:04:25 +0300 | [diff] [blame] | 278 | dev->caps.flags2 = dev_cap->flags2; |
Roland Dreier | 95d04f0 | 2008-07-23 08:12:26 -0700 | [diff] [blame] | 279 | dev->caps.bmme_flags = dev_cap->bmme_flags; |
| 280 | dev->caps.reserved_lkey = dev_cap->reserved_lkey; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 281 | dev->caps.stat_rate_support = dev_cap->stat_rate_support; |
Eli Cohen | b832be1 | 2008-04-16 21:09:27 -0700 | [diff] [blame] | 282 | dev->caps.max_gso_sz = dev_cap->max_gso_sz; |
Shlomo Pongratz | b3416f4 | 2012-04-29 17:04:25 +0300 | [diff] [blame] | 283 | dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 284 | |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 285 | /* Sense port always allowed on supported devices for ConnectX-1 and -2 */ |
| 286 | if (mlx4_priv(dev)->pci_dev_data & MLX4_PCI_DEV_FORCE_SENSE_PORT) |
Yevgeny Petrilin | 58a6016 | 2011-12-19 04:00:26 +0000 | [diff] [blame] | 287 | dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; |
Roland Dreier | aadf4f3 | 2012-09-27 10:01:19 -0700 | [diff] [blame] | 288 | /* Don't do sense port on multifunction devices (for now at least) */ |
| 289 | if (mlx4_is_mfunc(dev)) |
| 290 | dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; |
Yevgeny Petrilin | 58a6016 | 2011-12-19 04:00:26 +0000 | [diff] [blame] | 291 | |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 292 | dev->caps.log_num_macs = log_num_mac; |
Or Gerlitz | cb29688 | 2011-10-16 10:26:21 +0200 | [diff] [blame] | 293 | dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS; |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 294 | dev->caps.log_num_prios = use_prio ? 3 : 0; |
| 295 | |
| 296 | for (i = 1; i <= dev->caps.num_ports; ++i) { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 297 | dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE; |
| 298 | if (dev->caps.supported_type[i]) { |
| 299 | /* if only ETH is supported - assign ETH */ |
| 300 | if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH) |
| 301 | dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH; |
Jack Morgenstein | 105c320 | 2012-06-19 11:21:43 +0300 | [diff] [blame] | 302 | /* if only IB is supported, assign IB */ |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 303 | else if (dev->caps.supported_type[i] == |
Jack Morgenstein | 105c320 | 2012-06-19 11:21:43 +0300 | [diff] [blame] | 304 | MLX4_PORT_TYPE_IB) |
| 305 | dev->caps.port_type[i] = MLX4_PORT_TYPE_IB; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 306 | else { |
Jack Morgenstein | 105c320 | 2012-06-19 11:21:43 +0300 | [diff] [blame] | 307 | /* if IB and ETH are supported, we set the port |
| 308 | * type according to user selection of port type; |
| 309 | * if user selected none, take the FW hint */ |
| 310 | if (port_type_array[i - 1] == MLX4_PORT_TYPE_NONE) |
Yevgeny Petrilin | 8d0fc7b | 2011-12-19 04:00:34 +0000 | [diff] [blame] | 311 | dev->caps.port_type[i] = dev->caps.suggested_type[i] ? |
| 312 | MLX4_PORT_TYPE_ETH : MLX4_PORT_TYPE_IB; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 313 | else |
Jack Morgenstein | 105c320 | 2012-06-19 11:21:43 +0300 | [diff] [blame] | 314 | dev->caps.port_type[i] = port_type_array[i - 1]; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 315 | } |
| 316 | } |
Yevgeny Petrilin | 8d0fc7b | 2011-12-19 04:00:34 +0000 | [diff] [blame] | 317 | /* |
| 318 | * Link sensing is allowed on the port if 3 conditions are true: |
| 319 | * 1. Both protocols are supported on the port. |
| 320 | * 2. Different types are supported on the port |
| 321 | * 3. FW declared that it supports link sensing |
| 322 | */ |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 323 | mlx4_priv(dev)->sense.sense_allowed[i] = |
Yevgeny Petrilin | 58a6016 | 2011-12-19 04:00:26 +0000 | [diff] [blame] | 324 | ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) && |
Yevgeny Petrilin | 8d0fc7b | 2011-12-19 04:00:34 +0000 | [diff] [blame] | 325 | (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) && |
Yevgeny Petrilin | 58a6016 | 2011-12-19 04:00:26 +0000 | [diff] [blame] | 326 | (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 327 | |
Yevgeny Petrilin | 8d0fc7b | 2011-12-19 04:00:34 +0000 | [diff] [blame] | 328 | /* |
| 329 | * If "default_sense" bit is set, we move the port to "AUTO" mode |
| 330 | * and perform sense_port FW command to try and set the correct |
| 331 | * port type from beginning |
| 332 | */ |
Yevgeny Petrilin | 46c4674 | 2011-12-29 07:42:34 +0000 | [diff] [blame] | 333 | if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) { |
Yevgeny Petrilin | 8d0fc7b | 2011-12-19 04:00:34 +0000 | [diff] [blame] | 334 | enum mlx4_port_type sensed_port = MLX4_PORT_TYPE_NONE; |
| 335 | dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO; |
| 336 | mlx4_SENSE_PORT(dev, i, &sensed_port); |
| 337 | if (sensed_port != MLX4_PORT_TYPE_NONE) |
| 338 | dev->caps.port_type[i] = sensed_port; |
| 339 | } else { |
| 340 | dev->caps.possible_type[i] = dev->caps.port_type[i]; |
| 341 | } |
| 342 | |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 343 | if (dev->caps.log_num_macs > dev_cap->log_max_macs[i]) { |
| 344 | dev->caps.log_num_macs = dev_cap->log_max_macs[i]; |
| 345 | mlx4_warn(dev, "Requested number of MACs is too much " |
| 346 | "for port %d, reducing to %d.\n", |
| 347 | i, 1 << dev->caps.log_num_macs); |
| 348 | } |
| 349 | if (dev->caps.log_num_vlans > dev_cap->log_max_vlans[i]) { |
| 350 | dev->caps.log_num_vlans = dev_cap->log_max_vlans[i]; |
| 351 | mlx4_warn(dev, "Requested number of VLANs is too much " |
| 352 | "for port %d, reducing to %d.\n", |
| 353 | i, 1 << dev->caps.log_num_vlans); |
| 354 | } |
| 355 | } |
| 356 | |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 357 | dev->caps.max_counters = 1 << ilog2(dev_cap->max_counters); |
| 358 | |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 359 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps; |
| 360 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] = |
| 361 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] = |
| 362 | (1 << dev->caps.log_num_macs) * |
| 363 | (1 << dev->caps.log_num_vlans) * |
| 364 | (1 << dev->caps.log_num_prios) * |
| 365 | dev->caps.num_ports; |
| 366 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH; |
| 367 | |
| 368 | dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] + |
| 369 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] + |
| 370 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] + |
| 371 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH]; |
| 372 | |
Jack Morgenstein | e2c7682 | 2012-08-03 08:40:41 +0000 | [diff] [blame] | 373 | dev->caps.sqp_demux = (mlx4_is_master(dev)) ? MLX4_MAX_NUM_SLAVES : 0; |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 374 | |
Jack Morgenstein | b305132 | 2013-08-01 19:55:01 +0300 | [diff] [blame] | 375 | if (!enable_64b_cqe_eqe && !mlx4_is_slave(dev)) { |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 376 | if (dev_cap->flags & |
| 377 | (MLX4_DEV_CAP_FLAG_64B_CQE | MLX4_DEV_CAP_FLAG_64B_EQE)) { |
| 378 | mlx4_warn(dev, "64B EQEs/CQEs supported by the device but not enabled\n"); |
| 379 | dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_CQE; |
| 380 | dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_EQE; |
| 381 | } |
| 382 | } |
| 383 | |
Or Gerlitz | f97b4b5 | 2013-01-10 15:18:35 +0000 | [diff] [blame] | 384 | if ((dev->caps.flags & |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 385 | (MLX4_DEV_CAP_FLAG_64B_CQE | MLX4_DEV_CAP_FLAG_64B_EQE)) && |
| 386 | mlx4_is_master(dev)) |
| 387 | dev->caps.function_caps |= MLX4_FUNC_CAP_64B_EQE_CQE; |
| 388 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 389 | return 0; |
| 390 | } |
Eyal Perry | b912b2f | 2014-01-05 17:41:08 +0200 | [diff] [blame] | 391 | |
| 392 | static int mlx4_get_pcie_dev_link_caps(struct mlx4_dev *dev, |
| 393 | enum pci_bus_speed *speed, |
| 394 | enum pcie_link_width *width) |
| 395 | { |
| 396 | u32 lnkcap1, lnkcap2; |
| 397 | int err1, err2; |
| 398 | |
| 399 | #define PCIE_MLW_CAP_SHIFT 4 /* start of MLW mask in link capabilities */ |
| 400 | |
| 401 | *speed = PCI_SPEED_UNKNOWN; |
| 402 | *width = PCIE_LNK_WIDTH_UNKNOWN; |
| 403 | |
| 404 | err1 = pcie_capability_read_dword(dev->pdev, PCI_EXP_LNKCAP, &lnkcap1); |
| 405 | err2 = pcie_capability_read_dword(dev->pdev, PCI_EXP_LNKCAP2, &lnkcap2); |
| 406 | if (!err2 && lnkcap2) { /* PCIe r3.0-compliant */ |
| 407 | if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB) |
| 408 | *speed = PCIE_SPEED_8_0GT; |
| 409 | else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB) |
| 410 | *speed = PCIE_SPEED_5_0GT; |
| 411 | else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB) |
| 412 | *speed = PCIE_SPEED_2_5GT; |
| 413 | } |
| 414 | if (!err1) { |
| 415 | *width = (lnkcap1 & PCI_EXP_LNKCAP_MLW) >> PCIE_MLW_CAP_SHIFT; |
| 416 | if (!lnkcap2) { /* pre-r3.0 */ |
| 417 | if (lnkcap1 & PCI_EXP_LNKCAP_SLS_5_0GB) |
| 418 | *speed = PCIE_SPEED_5_0GT; |
| 419 | else if (lnkcap1 & PCI_EXP_LNKCAP_SLS_2_5GB) |
| 420 | *speed = PCIE_SPEED_2_5GT; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | if (*speed == PCI_SPEED_UNKNOWN || *width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 425 | return err1 ? err1 : |
| 426 | err2 ? err2 : -EINVAL; |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static void mlx4_check_pcie_caps(struct mlx4_dev *dev) |
| 432 | { |
| 433 | enum pcie_link_width width, width_cap; |
| 434 | enum pci_bus_speed speed, speed_cap; |
| 435 | int err; |
| 436 | |
| 437 | #define PCIE_SPEED_STR(speed) \ |
| 438 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : \ |
| 439 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : \ |
| 440 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : \ |
| 441 | "Unknown") |
| 442 | |
| 443 | err = mlx4_get_pcie_dev_link_caps(dev, &speed_cap, &width_cap); |
| 444 | if (err) { |
| 445 | mlx4_warn(dev, |
| 446 | "Unable to determine PCIe device BW capabilities\n"); |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | err = pcie_get_minimum_link(dev->pdev, &speed, &width); |
| 451 | if (err || speed == PCI_SPEED_UNKNOWN || |
| 452 | width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 453 | mlx4_warn(dev, |
| 454 | "Unable to determine PCI device chain minimum BW\n"); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | if (width != width_cap || speed != speed_cap) |
| 459 | mlx4_warn(dev, |
| 460 | "PCIe BW is different than device's capability\n"); |
| 461 | |
| 462 | mlx4_info(dev, "PCIe link speed is %s, device supports %s\n", |
| 463 | PCIE_SPEED_STR(speed), PCIE_SPEED_STR(speed_cap)); |
| 464 | mlx4_info(dev, "PCIe link width is x%d, device supports x%d\n", |
| 465 | width, width_cap); |
| 466 | return; |
| 467 | } |
| 468 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 469 | /*The function checks if there are live vf, return the num of them*/ |
| 470 | static int mlx4_how_many_lives_vf(struct mlx4_dev *dev) |
| 471 | { |
| 472 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 473 | struct mlx4_slave_state *s_state; |
| 474 | int i; |
| 475 | int ret = 0; |
| 476 | |
| 477 | for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) { |
| 478 | s_state = &priv->mfunc.master.slave_state[i]; |
| 479 | if (s_state->active && s_state->last_cmd != |
| 480 | MLX4_COMM_CMD_RESET) { |
| 481 | mlx4_warn(dev, "%s: slave: %d is still active\n", |
| 482 | __func__, i); |
| 483 | ret++; |
| 484 | } |
| 485 | } |
| 486 | return ret; |
| 487 | } |
| 488 | |
Jack Morgenstein | 396f2fe | 2012-06-19 11:21:42 +0300 | [diff] [blame] | 489 | int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey) |
| 490 | { |
| 491 | u32 qk = MLX4_RESERVED_QKEY_BASE; |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 492 | |
| 493 | if (qpn >= dev->phys_caps.base_tunnel_sqpn + 8 * MLX4_MFUNC_MAX || |
| 494 | qpn < dev->phys_caps.base_proxy_sqpn) |
Jack Morgenstein | 396f2fe | 2012-06-19 11:21:42 +0300 | [diff] [blame] | 495 | return -EINVAL; |
| 496 | |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 497 | if (qpn >= dev->phys_caps.base_tunnel_sqpn) |
Jack Morgenstein | 396f2fe | 2012-06-19 11:21:42 +0300 | [diff] [blame] | 498 | /* tunnel qp */ |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 499 | qk += qpn - dev->phys_caps.base_tunnel_sqpn; |
Jack Morgenstein | 396f2fe | 2012-06-19 11:21:42 +0300 | [diff] [blame] | 500 | else |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 501 | qk += qpn - dev->phys_caps.base_proxy_sqpn; |
Jack Morgenstein | 396f2fe | 2012-06-19 11:21:42 +0300 | [diff] [blame] | 502 | *qkey = qk; |
| 503 | return 0; |
| 504 | } |
| 505 | EXPORT_SYMBOL(mlx4_get_parav_qkey); |
| 506 | |
Jack Morgenstein | 54679e1 | 2012-08-03 08:40:43 +0000 | [diff] [blame] | 507 | void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port, int i, int val) |
| 508 | { |
| 509 | struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); |
| 510 | |
| 511 | if (!mlx4_is_master(dev)) |
| 512 | return; |
| 513 | |
| 514 | priv->virt2phys_pkey[slave][port - 1][i] = val; |
| 515 | } |
| 516 | EXPORT_SYMBOL(mlx4_sync_pkey_table); |
| 517 | |
Jack Morgenstein | afa8fd1 | 2012-08-03 08:40:56 +0000 | [diff] [blame] | 518 | void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid) |
| 519 | { |
| 520 | struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); |
| 521 | |
| 522 | if (!mlx4_is_master(dev)) |
| 523 | return; |
| 524 | |
| 525 | priv->slave_node_guids[slave] = guid; |
| 526 | } |
| 527 | EXPORT_SYMBOL(mlx4_put_slave_node_guid); |
| 528 | |
| 529 | __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave) |
| 530 | { |
| 531 | struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); |
| 532 | |
| 533 | if (!mlx4_is_master(dev)) |
| 534 | return 0; |
| 535 | |
| 536 | return priv->slave_node_guids[slave]; |
| 537 | } |
| 538 | EXPORT_SYMBOL(mlx4_get_slave_node_guid); |
| 539 | |
Roland Dreier | e10903b | 2012-02-26 01:48:12 -0800 | [diff] [blame] | 540 | int mlx4_is_slave_active(struct mlx4_dev *dev, int slave) |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 541 | { |
| 542 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 543 | struct mlx4_slave_state *s_slave; |
| 544 | |
| 545 | if (!mlx4_is_master(dev)) |
| 546 | return 0; |
| 547 | |
| 548 | s_slave = &priv->mfunc.master.slave_state[slave]; |
| 549 | return !!s_slave->active; |
| 550 | } |
| 551 | EXPORT_SYMBOL(mlx4_is_slave_active); |
| 552 | |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 553 | static void slave_adjust_steering_mode(struct mlx4_dev *dev, |
| 554 | struct mlx4_dev_cap *dev_cap, |
| 555 | struct mlx4_init_hca_param *hca_param) |
| 556 | { |
| 557 | dev->caps.steering_mode = hca_param->steering_mode; |
| 558 | if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) { |
| 559 | dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; |
| 560 | dev->caps.fs_log_max_ucast_qp_range_size = |
| 561 | dev_cap->fs_log_max_ucast_qp_range_size; |
| 562 | } else |
| 563 | dev->caps.num_qp_per_mgm = |
| 564 | 4 * ((1 << hca_param->log_mc_entry_sz)/16 - 2); |
| 565 | |
| 566 | mlx4_dbg(dev, "Steering mode is: %s\n", |
| 567 | mlx4_steering_mode_str(dev->caps.steering_mode)); |
| 568 | } |
| 569 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 570 | static int mlx4_slave_cap(struct mlx4_dev *dev) |
| 571 | { |
| 572 | int err; |
| 573 | u32 page_size; |
| 574 | struct mlx4_dev_cap dev_cap; |
| 575 | struct mlx4_func_cap func_cap; |
| 576 | struct mlx4_init_hca_param hca_param; |
| 577 | int i; |
| 578 | |
| 579 | memset(&hca_param, 0, sizeof(hca_param)); |
| 580 | err = mlx4_QUERY_HCA(dev, &hca_param); |
| 581 | if (err) { |
| 582 | mlx4_err(dev, "QUERY_HCA command failed, aborting.\n"); |
| 583 | return err; |
| 584 | } |
| 585 | |
| 586 | /*fail if the hca has an unknown capability */ |
| 587 | if ((hca_param.global_caps | HCA_GLOBAL_CAP_MASK) != |
| 588 | HCA_GLOBAL_CAP_MASK) { |
| 589 | mlx4_err(dev, "Unknown hca global capabilities\n"); |
| 590 | return -ENOSYS; |
| 591 | } |
| 592 | |
| 593 | mlx4_log_num_mgm_entry_size = hca_param.log_mc_entry_sz; |
| 594 | |
Eugenia Emantayev | ddd8a6c | 2013-04-23 06:06:48 +0000 | [diff] [blame] | 595 | dev->caps.hca_core_clock = hca_param.hca_core_clock; |
| 596 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 597 | memset(&dev_cap, 0, sizeof(dev_cap)); |
Jack Morgenstein | b91cb3e | 2012-05-30 09:14:53 +0000 | [diff] [blame] | 598 | dev->caps.max_qp_dest_rdma = 1 << hca_param.log_rd_per_qp; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 599 | err = mlx4_dev_cap(dev, &dev_cap); |
| 600 | if (err) { |
| 601 | mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); |
| 602 | return err; |
| 603 | } |
| 604 | |
Jack Morgenstein | b91cb3e | 2012-05-30 09:14:53 +0000 | [diff] [blame] | 605 | err = mlx4_QUERY_FW(dev); |
| 606 | if (err) |
| 607 | mlx4_err(dev, "QUERY_FW command failed: could not get FW version.\n"); |
| 608 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 609 | page_size = ~dev->caps.page_size_cap + 1; |
| 610 | mlx4_warn(dev, "HCA minimum page size:%d\n", page_size); |
| 611 | if (page_size > PAGE_SIZE) { |
| 612 | mlx4_err(dev, "HCA minimum page size of %d bigger than " |
| 613 | "kernel PAGE_SIZE of %ld, aborting.\n", |
| 614 | page_size, PAGE_SIZE); |
| 615 | return -ENODEV; |
| 616 | } |
| 617 | |
| 618 | /* slave gets uar page size from QUERY_HCA fw command */ |
| 619 | dev->caps.uar_page_size = 1 << (hca_param.uar_page_sz + 12); |
| 620 | |
| 621 | /* TODO: relax this assumption */ |
| 622 | if (dev->caps.uar_page_size != PAGE_SIZE) { |
| 623 | mlx4_err(dev, "UAR size:%d != kernel PAGE_SIZE of %ld\n", |
| 624 | dev->caps.uar_page_size, PAGE_SIZE); |
| 625 | return -ENODEV; |
| 626 | } |
| 627 | |
| 628 | memset(&func_cap, 0, sizeof(func_cap)); |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 629 | err = mlx4_QUERY_FUNC_CAP(dev, 0, &func_cap); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 630 | if (err) { |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 631 | mlx4_err(dev, "QUERY_FUNC_CAP general command failed, aborting (%d).\n", |
| 632 | err); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 633 | return err; |
| 634 | } |
| 635 | |
| 636 | if ((func_cap.pf_context_behaviour | PF_CONTEXT_BEHAVIOUR_MASK) != |
| 637 | PF_CONTEXT_BEHAVIOUR_MASK) { |
| 638 | mlx4_err(dev, "Unknown pf context behaviour\n"); |
| 639 | return -ENOSYS; |
| 640 | } |
| 641 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 642 | dev->caps.num_ports = func_cap.num_ports; |
Jack Morgenstein | 5a0d0a6 | 2013-11-03 10:03:23 +0200 | [diff] [blame] | 643 | dev->quotas.qp = func_cap.qp_quota; |
| 644 | dev->quotas.srq = func_cap.srq_quota; |
| 645 | dev->quotas.cq = func_cap.cq_quota; |
| 646 | dev->quotas.mpt = func_cap.mpt_quota; |
| 647 | dev->quotas.mtt = func_cap.mtt_quota; |
| 648 | dev->caps.num_qps = 1 << hca_param.log_num_qps; |
| 649 | dev->caps.num_srqs = 1 << hca_param.log_num_srqs; |
| 650 | dev->caps.num_cqs = 1 << hca_param.log_num_cqs; |
| 651 | dev->caps.num_mpts = 1 << hca_param.log_mpt_sz; |
| 652 | dev->caps.num_eqs = func_cap.max_eq; |
| 653 | dev->caps.reserved_eqs = func_cap.reserved_eq; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 654 | dev->caps.num_pds = MLX4_NUM_PDS; |
| 655 | dev->caps.num_mgms = 0; |
| 656 | dev->caps.num_amgms = 0; |
| 657 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 658 | if (dev->caps.num_ports > MLX4_MAX_PORTS) { |
| 659 | mlx4_err(dev, "HCA has %d ports, but we only support %d, " |
| 660 | "aborting.\n", dev->caps.num_ports, MLX4_MAX_PORTS); |
| 661 | return -ENODEV; |
| 662 | } |
| 663 | |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 664 | dev->caps.qp0_tunnel = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); |
| 665 | dev->caps.qp0_proxy = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); |
| 666 | dev->caps.qp1_tunnel = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); |
| 667 | dev->caps.qp1_proxy = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); |
| 668 | |
| 669 | if (!dev->caps.qp0_tunnel || !dev->caps.qp0_proxy || |
| 670 | !dev->caps.qp1_tunnel || !dev->caps.qp1_proxy) { |
| 671 | err = -ENOMEM; |
| 672 | goto err_mem; |
| 673 | } |
| 674 | |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 675 | for (i = 1; i <= dev->caps.num_ports; ++i) { |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 676 | err = mlx4_QUERY_FUNC_CAP(dev, (u32) i, &func_cap); |
| 677 | if (err) { |
| 678 | mlx4_err(dev, "QUERY_FUNC_CAP port command failed for" |
| 679 | " port %d, aborting (%d).\n", i, err); |
| 680 | goto err_mem; |
| 681 | } |
| 682 | dev->caps.qp0_tunnel[i - 1] = func_cap.qp0_tunnel_qpn; |
| 683 | dev->caps.qp0_proxy[i - 1] = func_cap.qp0_proxy_qpn; |
| 684 | dev->caps.qp1_tunnel[i - 1] = func_cap.qp1_tunnel_qpn; |
| 685 | dev->caps.qp1_proxy[i - 1] = func_cap.qp1_proxy_qpn; |
Jack Morgenstein | 6230bb2 | 2012-05-30 09:14:54 +0000 | [diff] [blame] | 686 | dev->caps.port_mask[i] = dev->caps.port_type[i]; |
Hadar Hen Zion | 8e1a28e | 2013-12-19 21:20:12 +0200 | [diff] [blame] | 687 | dev->caps.phys_port_id[i] = func_cap.phys_port_id; |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 688 | if (mlx4_get_slave_pkey_gid_tbl_len(dev, i, |
| 689 | &dev->caps.gid_table_len[i], |
| 690 | &dev->caps.pkey_table_len[i])) |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 691 | goto err_mem; |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 692 | } |
Jack Morgenstein | 6230bb2 | 2012-05-30 09:14:54 +0000 | [diff] [blame] | 693 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 694 | if (dev->caps.uar_page_size * (dev->caps.num_uars - |
| 695 | dev->caps.reserved_uars) > |
| 696 | pci_resource_len(dev->pdev, 2)) { |
| 697 | mlx4_err(dev, "HCA reported UAR region size of 0x%x bigger than " |
| 698 | "PCI resource 2 size of 0x%llx, aborting.\n", |
| 699 | dev->caps.uar_page_size * dev->caps.num_uars, |
| 700 | (unsigned long long) pci_resource_len(dev->pdev, 2)); |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 701 | goto err_mem; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 704 | if (hca_param.dev_cap_enabled & MLX4_DEV_CAP_64B_EQE_ENABLED) { |
| 705 | dev->caps.eqe_size = 64; |
| 706 | dev->caps.eqe_factor = 1; |
| 707 | } else { |
| 708 | dev->caps.eqe_size = 32; |
| 709 | dev->caps.eqe_factor = 0; |
| 710 | } |
| 711 | |
| 712 | if (hca_param.dev_cap_enabled & MLX4_DEV_CAP_64B_CQE_ENABLED) { |
| 713 | dev->caps.cqe_size = 64; |
| 714 | dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_64B_CQE; |
| 715 | } else { |
| 716 | dev->caps.cqe_size = 32; |
| 717 | } |
| 718 | |
Amir Vadai | f9bd2d7 | 2013-06-20 14:58:10 +0300 | [diff] [blame] | 719 | dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; |
| 720 | mlx4_warn(dev, "Timestamping is not supported in slave mode.\n"); |
| 721 | |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 722 | slave_adjust_steering_mode(dev, &dev_cap, &hca_param); |
| 723 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 724 | return 0; |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 725 | |
| 726 | err_mem: |
| 727 | kfree(dev->caps.qp0_tunnel); |
| 728 | kfree(dev->caps.qp0_proxy); |
| 729 | kfree(dev->caps.qp1_tunnel); |
| 730 | kfree(dev->caps.qp1_proxy); |
| 731 | dev->caps.qp0_tunnel = dev->caps.qp0_proxy = |
| 732 | dev->caps.qp1_tunnel = dev->caps.qp1_proxy = NULL; |
| 733 | |
| 734 | return err; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 735 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 736 | |
Eyal Perry | b046ffe | 2013-10-15 16:55:24 +0200 | [diff] [blame] | 737 | static void mlx4_request_modules(struct mlx4_dev *dev) |
| 738 | { |
| 739 | int port; |
| 740 | int has_ib_port = false; |
| 741 | int has_eth_port = false; |
| 742 | #define EN_DRV_NAME "mlx4_en" |
| 743 | #define IB_DRV_NAME "mlx4_ib" |
| 744 | |
| 745 | for (port = 1; port <= dev->caps.num_ports; port++) { |
| 746 | if (dev->caps.port_type[port] == MLX4_PORT_TYPE_IB) |
| 747 | has_ib_port = true; |
| 748 | else if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) |
| 749 | has_eth_port = true; |
| 750 | } |
| 751 | |
| 752 | if (has_ib_port) |
| 753 | request_module_nowait(IB_DRV_NAME); |
| 754 | if (has_eth_port) |
| 755 | request_module_nowait(EN_DRV_NAME); |
| 756 | } |
| 757 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 758 | /* |
| 759 | * Change the port configuration of the device. |
| 760 | * Every user of this function must hold the port mutex. |
| 761 | */ |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 762 | int mlx4_change_port_types(struct mlx4_dev *dev, |
| 763 | enum mlx4_port_type *port_types) |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 764 | { |
| 765 | int err = 0; |
| 766 | int change = 0; |
| 767 | int port; |
| 768 | |
| 769 | for (port = 0; port < dev->caps.num_ports; port++) { |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 770 | /* Change the port type only if the new type is different |
| 771 | * from the current, and not set to Auto */ |
Yevgeny Petrilin | 3d8f930 | 2012-02-21 03:41:07 +0000 | [diff] [blame] | 772 | if (port_types[port] != dev->caps.port_type[port + 1]) |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 773 | change = 1; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 774 | } |
| 775 | if (change) { |
| 776 | mlx4_unregister_device(dev); |
| 777 | for (port = 1; port <= dev->caps.num_ports; port++) { |
| 778 | mlx4_CLOSE_PORT(dev, port); |
Yevgeny Petrilin | 1e0f03d | 2012-02-23 07:04:35 +0000 | [diff] [blame] | 779 | dev->caps.port_type[port] = port_types[port - 1]; |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 780 | err = mlx4_SET_PORT(dev, port, -1); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 781 | if (err) { |
| 782 | mlx4_err(dev, "Failed to set port %d, " |
| 783 | "aborting\n", port); |
| 784 | goto out; |
| 785 | } |
| 786 | } |
| 787 | mlx4_set_port_mask(dev); |
| 788 | err = mlx4_register_device(dev); |
Eyal Perry | b046ffe | 2013-10-15 16:55:24 +0200 | [diff] [blame] | 789 | if (err) { |
| 790 | mlx4_err(dev, "Failed to register device\n"); |
| 791 | goto out; |
| 792 | } |
| 793 | mlx4_request_modules(dev); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | out: |
| 797 | return err; |
| 798 | } |
| 799 | |
| 800 | static ssize_t show_port_type(struct device *dev, |
| 801 | struct device_attribute *attr, |
| 802 | char *buf) |
| 803 | { |
| 804 | struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info, |
| 805 | port_attr); |
| 806 | struct mlx4_dev *mdev = info->dev; |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 807 | char type[8]; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 808 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 809 | sprintf(type, "%s", |
| 810 | (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_IB) ? |
| 811 | "ib" : "eth"); |
| 812 | if (mdev->caps.possible_type[info->port] == MLX4_PORT_TYPE_AUTO) |
| 813 | sprintf(buf, "auto (%s)\n", type); |
| 814 | else |
| 815 | sprintf(buf, "%s\n", type); |
| 816 | |
| 817 | return strlen(buf); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static ssize_t set_port_type(struct device *dev, |
| 821 | struct device_attribute *attr, |
| 822 | const char *buf, size_t count) |
| 823 | { |
| 824 | struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info, |
| 825 | port_attr); |
| 826 | struct mlx4_dev *mdev = info->dev; |
| 827 | struct mlx4_priv *priv = mlx4_priv(mdev); |
| 828 | enum mlx4_port_type types[MLX4_MAX_PORTS]; |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 829 | enum mlx4_port_type new_types[MLX4_MAX_PORTS]; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 830 | int i; |
| 831 | int err = 0; |
| 832 | |
| 833 | if (!strcmp(buf, "ib\n")) |
| 834 | info->tmp_type = MLX4_PORT_TYPE_IB; |
| 835 | else if (!strcmp(buf, "eth\n")) |
| 836 | info->tmp_type = MLX4_PORT_TYPE_ETH; |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 837 | else if (!strcmp(buf, "auto\n")) |
| 838 | info->tmp_type = MLX4_PORT_TYPE_AUTO; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 839 | else { |
| 840 | mlx4_err(mdev, "%s is not supported port type\n", buf); |
| 841 | return -EINVAL; |
| 842 | } |
| 843 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 844 | mlx4_stop_sense(mdev); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 845 | mutex_lock(&priv->port_mutex); |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 846 | /* Possible type is always the one that was delivered */ |
| 847 | mdev->caps.possible_type[info->port] = info->tmp_type; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 848 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 849 | for (i = 0; i < mdev->caps.num_ports; i++) { |
| 850 | types[i] = priv->port[i+1].tmp_type ? priv->port[i+1].tmp_type : |
| 851 | mdev->caps.possible_type[i+1]; |
| 852 | if (types[i] == MLX4_PORT_TYPE_AUTO) |
| 853 | types[i] = mdev->caps.port_type[i+1]; |
| 854 | } |
| 855 | |
Yevgeny Petrilin | 58a6016 | 2011-12-19 04:00:26 +0000 | [diff] [blame] | 856 | if (!(mdev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) && |
| 857 | !(mdev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)) { |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 858 | for (i = 1; i <= mdev->caps.num_ports; i++) { |
| 859 | if (mdev->caps.possible_type[i] == MLX4_PORT_TYPE_AUTO) { |
| 860 | mdev->caps.possible_type[i] = mdev->caps.port_type[i]; |
| 861 | err = -EINVAL; |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | if (err) { |
| 866 | mlx4_err(mdev, "Auto sensing is not supported on this HCA. " |
| 867 | "Set only 'eth' or 'ib' for both ports " |
| 868 | "(should be the same)\n"); |
| 869 | goto out; |
| 870 | } |
| 871 | |
| 872 | mlx4_do_sense_ports(mdev, new_types, types); |
| 873 | |
| 874 | err = mlx4_check_port_params(mdev, new_types); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 875 | if (err) |
| 876 | goto out; |
| 877 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 878 | /* We are about to apply the changes after the configuration |
| 879 | * was verified, no need to remember the temporary types |
| 880 | * any more */ |
| 881 | for (i = 0; i < mdev->caps.num_ports; i++) |
| 882 | priv->port[i + 1].tmp_type = 0; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 883 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 884 | err = mlx4_change_port_types(mdev, new_types); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 885 | |
| 886 | out: |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 887 | mlx4_start_sense(mdev); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 888 | mutex_unlock(&priv->port_mutex); |
| 889 | return err ? err : count; |
| 890 | } |
| 891 | |
Or Gerlitz | 096335b | 2012-01-11 19:02:17 +0200 | [diff] [blame] | 892 | enum ibta_mtu { |
| 893 | IB_MTU_256 = 1, |
| 894 | IB_MTU_512 = 2, |
| 895 | IB_MTU_1024 = 3, |
| 896 | IB_MTU_2048 = 4, |
| 897 | IB_MTU_4096 = 5 |
| 898 | }; |
| 899 | |
| 900 | static inline int int_to_ibta_mtu(int mtu) |
| 901 | { |
| 902 | switch (mtu) { |
| 903 | case 256: return IB_MTU_256; |
| 904 | case 512: return IB_MTU_512; |
| 905 | case 1024: return IB_MTU_1024; |
| 906 | case 2048: return IB_MTU_2048; |
| 907 | case 4096: return IB_MTU_4096; |
| 908 | default: return -1; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | static inline int ibta_mtu_to_int(enum ibta_mtu mtu) |
| 913 | { |
| 914 | switch (mtu) { |
| 915 | case IB_MTU_256: return 256; |
| 916 | case IB_MTU_512: return 512; |
| 917 | case IB_MTU_1024: return 1024; |
| 918 | case IB_MTU_2048: return 2048; |
| 919 | case IB_MTU_4096: return 4096; |
| 920 | default: return -1; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | static ssize_t show_port_ib_mtu(struct device *dev, |
| 925 | struct device_attribute *attr, |
| 926 | char *buf) |
| 927 | { |
| 928 | struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info, |
| 929 | port_mtu_attr); |
| 930 | struct mlx4_dev *mdev = info->dev; |
| 931 | |
| 932 | if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH) |
| 933 | mlx4_warn(mdev, "port level mtu is only used for IB ports\n"); |
| 934 | |
| 935 | sprintf(buf, "%d\n", |
| 936 | ibta_mtu_to_int(mdev->caps.port_ib_mtu[info->port])); |
| 937 | return strlen(buf); |
| 938 | } |
| 939 | |
| 940 | static ssize_t set_port_ib_mtu(struct device *dev, |
| 941 | struct device_attribute *attr, |
| 942 | const char *buf, size_t count) |
| 943 | { |
| 944 | struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info, |
| 945 | port_mtu_attr); |
| 946 | struct mlx4_dev *mdev = info->dev; |
| 947 | struct mlx4_priv *priv = mlx4_priv(mdev); |
| 948 | int err, port, mtu, ibta_mtu = -1; |
| 949 | |
| 950 | if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH) { |
| 951 | mlx4_warn(mdev, "port level mtu is only used for IB ports\n"); |
| 952 | return -EINVAL; |
| 953 | } |
| 954 | |
Dotan Barak | 618fad9 | 2013-06-25 12:09:36 +0300 | [diff] [blame] | 955 | err = kstrtoint(buf, 0, &mtu); |
| 956 | if (!err) |
Or Gerlitz | 096335b | 2012-01-11 19:02:17 +0200 | [diff] [blame] | 957 | ibta_mtu = int_to_ibta_mtu(mtu); |
| 958 | |
Dotan Barak | 618fad9 | 2013-06-25 12:09:36 +0300 | [diff] [blame] | 959 | if (err || ibta_mtu < 0) { |
Or Gerlitz | 096335b | 2012-01-11 19:02:17 +0200 | [diff] [blame] | 960 | mlx4_err(mdev, "%s is invalid IBTA mtu\n", buf); |
| 961 | return -EINVAL; |
| 962 | } |
| 963 | |
| 964 | mdev->caps.port_ib_mtu[info->port] = ibta_mtu; |
| 965 | |
| 966 | mlx4_stop_sense(mdev); |
| 967 | mutex_lock(&priv->port_mutex); |
| 968 | mlx4_unregister_device(mdev); |
| 969 | for (port = 1; port <= mdev->caps.num_ports; port++) { |
| 970 | mlx4_CLOSE_PORT(mdev, port); |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 971 | err = mlx4_SET_PORT(mdev, port, -1); |
Or Gerlitz | 096335b | 2012-01-11 19:02:17 +0200 | [diff] [blame] | 972 | if (err) { |
| 973 | mlx4_err(mdev, "Failed to set port %d, " |
| 974 | "aborting\n", port); |
| 975 | goto err_set_port; |
| 976 | } |
| 977 | } |
| 978 | err = mlx4_register_device(mdev); |
| 979 | err_set_port: |
| 980 | mutex_unlock(&priv->port_mutex); |
| 981 | mlx4_start_sense(mdev); |
| 982 | return err ? err : count; |
| 983 | } |
| 984 | |
Roland Dreier | e8f9b2e | 2008-02-04 20:20:41 -0800 | [diff] [blame] | 985 | static int mlx4_load_fw(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 986 | { |
| 987 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 988 | int err; |
| 989 | |
| 990 | priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 991 | GFP_HIGHUSER | __GFP_NOWARN, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 992 | if (!priv->fw.fw_icm) { |
| 993 | mlx4_err(dev, "Couldn't allocate FW area, aborting.\n"); |
| 994 | return -ENOMEM; |
| 995 | } |
| 996 | |
| 997 | err = mlx4_MAP_FA(dev, priv->fw.fw_icm); |
| 998 | if (err) { |
| 999 | mlx4_err(dev, "MAP_FA command failed, aborting.\n"); |
| 1000 | goto err_free; |
| 1001 | } |
| 1002 | |
| 1003 | err = mlx4_RUN_FW(dev); |
| 1004 | if (err) { |
| 1005 | mlx4_err(dev, "RUN_FW command failed, aborting.\n"); |
| 1006 | goto err_unmap_fa; |
| 1007 | } |
| 1008 | |
| 1009 | return 0; |
| 1010 | |
| 1011 | err_unmap_fa: |
| 1012 | mlx4_UNMAP_FA(dev); |
| 1013 | |
| 1014 | err_free: |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1015 | mlx4_free_icm(dev, priv->fw.fw_icm, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1016 | return err; |
| 1017 | } |
| 1018 | |
Roland Dreier | e8f9b2e | 2008-02-04 20:20:41 -0800 | [diff] [blame] | 1019 | static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base, |
| 1020 | int cmpt_entry_sz) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1021 | { |
| 1022 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1023 | int err; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1024 | int num_eqs; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1025 | |
| 1026 | err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table, |
| 1027 | cmpt_base + |
| 1028 | ((u64) (MLX4_CMPT_TYPE_QP * |
| 1029 | cmpt_entry_sz) << MLX4_CMPT_SHIFT), |
| 1030 | cmpt_entry_sz, dev->caps.num_qps, |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 1031 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], |
| 1032 | 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1033 | if (err) |
| 1034 | goto err; |
| 1035 | |
| 1036 | err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table, |
| 1037 | cmpt_base + |
| 1038 | ((u64) (MLX4_CMPT_TYPE_SRQ * |
| 1039 | cmpt_entry_sz) << MLX4_CMPT_SHIFT), |
| 1040 | cmpt_entry_sz, dev->caps.num_srqs, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1041 | dev->caps.reserved_srqs, 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1042 | if (err) |
| 1043 | goto err_qp; |
| 1044 | |
| 1045 | err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table, |
| 1046 | cmpt_base + |
| 1047 | ((u64) (MLX4_CMPT_TYPE_CQ * |
| 1048 | cmpt_entry_sz) << MLX4_CMPT_SHIFT), |
| 1049 | cmpt_entry_sz, dev->caps.num_cqs, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1050 | dev->caps.reserved_cqs, 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1051 | if (err) |
| 1052 | goto err_srq; |
| 1053 | |
Marcel Apfelbaum | 3fc929e | 2012-05-30 09:14:51 +0000 | [diff] [blame] | 1054 | num_eqs = (mlx4_is_master(dev)) ? dev->phys_caps.num_phys_eqs : |
| 1055 | dev->caps.num_eqs; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1056 | err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table, |
| 1057 | cmpt_base + |
| 1058 | ((u64) (MLX4_CMPT_TYPE_EQ * |
| 1059 | cmpt_entry_sz) << MLX4_CMPT_SHIFT), |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1060 | cmpt_entry_sz, num_eqs, num_eqs, 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1061 | if (err) |
| 1062 | goto err_cq; |
| 1063 | |
| 1064 | return 0; |
| 1065 | |
| 1066 | err_cq: |
| 1067 | mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); |
| 1068 | |
| 1069 | err_srq: |
| 1070 | mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); |
| 1071 | |
| 1072 | err_qp: |
| 1073 | mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); |
| 1074 | |
| 1075 | err: |
| 1076 | return err; |
| 1077 | } |
| 1078 | |
Roland Dreier | 3d73c28 | 2007-10-10 15:43:54 -0700 | [diff] [blame] | 1079 | static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, |
| 1080 | struct mlx4_init_hca_param *init_hca, u64 icm_size) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1081 | { |
| 1082 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1083 | u64 aux_pages; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1084 | int num_eqs; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1085 | int err; |
| 1086 | |
| 1087 | err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages); |
| 1088 | if (err) { |
| 1089 | mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n"); |
| 1090 | return err; |
| 1091 | } |
| 1092 | |
| 1093 | mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n", |
| 1094 | (unsigned long long) icm_size >> 10, |
| 1095 | (unsigned long long) aux_pages << 2); |
| 1096 | |
| 1097 | priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1098 | GFP_HIGHUSER | __GFP_NOWARN, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1099 | if (!priv->fw.aux_icm) { |
| 1100 | mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n"); |
| 1101 | return -ENOMEM; |
| 1102 | } |
| 1103 | |
| 1104 | err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm); |
| 1105 | if (err) { |
| 1106 | mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n"); |
| 1107 | goto err_free_aux; |
| 1108 | } |
| 1109 | |
| 1110 | err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz); |
| 1111 | if (err) { |
| 1112 | mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n"); |
| 1113 | goto err_unmap_aux; |
| 1114 | } |
| 1115 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1116 | |
Marcel Apfelbaum | 3fc929e | 2012-05-30 09:14:51 +0000 | [diff] [blame] | 1117 | num_eqs = (mlx4_is_master(dev)) ? dev->phys_caps.num_phys_eqs : |
| 1118 | dev->caps.num_eqs; |
Roland Dreier | fa0681d | 2009-09-05 20:24:49 -0700 | [diff] [blame] | 1119 | err = mlx4_init_icm_table(dev, &priv->eq_table.table, |
| 1120 | init_hca->eqc_base, dev_cap->eqc_entry_sz, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1121 | num_eqs, num_eqs, 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1122 | if (err) { |
| 1123 | mlx4_err(dev, "Failed to map EQ context memory, aborting.\n"); |
| 1124 | goto err_unmap_cmpt; |
| 1125 | } |
| 1126 | |
Jack Morgenstein | d7bb58f | 2007-08-01 12:28:53 +0300 | [diff] [blame] | 1127 | /* |
| 1128 | * Reserved MTT entries must be aligned up to a cacheline |
| 1129 | * boundary, since the FW will write to them, while the driver |
| 1130 | * writes to all other MTT entries. (The variable |
| 1131 | * dev->caps.mtt_entry_sz below is really the MTT segment |
| 1132 | * size, not the raw entry size) |
| 1133 | */ |
| 1134 | dev->caps.reserved_mtts = |
| 1135 | ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz, |
| 1136 | dma_get_cache_alignment()) / dev->caps.mtt_entry_sz; |
| 1137 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1138 | err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table, |
| 1139 | init_hca->mtt_base, |
| 1140 | dev->caps.mtt_entry_sz, |
Marcel Apfelbaum | 2b8fb28 | 2011-12-13 04:16:56 +0000 | [diff] [blame] | 1141 | dev->caps.num_mtts, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1142 | dev->caps.reserved_mtts, 1, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1143 | if (err) { |
| 1144 | mlx4_err(dev, "Failed to map MTT context memory, aborting.\n"); |
| 1145 | goto err_unmap_eq; |
| 1146 | } |
| 1147 | |
| 1148 | err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table, |
| 1149 | init_hca->dmpt_base, |
| 1150 | dev_cap->dmpt_entry_sz, |
| 1151 | dev->caps.num_mpts, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1152 | dev->caps.reserved_mrws, 1, 1); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1153 | if (err) { |
| 1154 | mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n"); |
| 1155 | goto err_unmap_mtt; |
| 1156 | } |
| 1157 | |
| 1158 | err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table, |
| 1159 | init_hca->qpc_base, |
| 1160 | dev_cap->qpc_entry_sz, |
| 1161 | dev->caps.num_qps, |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 1162 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], |
| 1163 | 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1164 | if (err) { |
| 1165 | mlx4_err(dev, "Failed to map QP context memory, aborting.\n"); |
| 1166 | goto err_unmap_dmpt; |
| 1167 | } |
| 1168 | |
| 1169 | err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table, |
| 1170 | init_hca->auxc_base, |
| 1171 | dev_cap->aux_entry_sz, |
| 1172 | dev->caps.num_qps, |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 1173 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], |
| 1174 | 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1175 | if (err) { |
| 1176 | mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n"); |
| 1177 | goto err_unmap_qp; |
| 1178 | } |
| 1179 | |
| 1180 | err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table, |
| 1181 | init_hca->altc_base, |
| 1182 | dev_cap->altc_entry_sz, |
| 1183 | dev->caps.num_qps, |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 1184 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], |
| 1185 | 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1186 | if (err) { |
| 1187 | mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n"); |
| 1188 | goto err_unmap_auxc; |
| 1189 | } |
| 1190 | |
| 1191 | err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table, |
| 1192 | init_hca->rdmarc_base, |
| 1193 | dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift, |
| 1194 | dev->caps.num_qps, |
Yevgeny Petrilin | 93fc9e1 | 2008-10-22 10:25:29 -0700 | [diff] [blame] | 1195 | dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], |
| 1196 | 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1197 | if (err) { |
| 1198 | mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n"); |
| 1199 | goto err_unmap_altc; |
| 1200 | } |
| 1201 | |
| 1202 | err = mlx4_init_icm_table(dev, &priv->cq_table.table, |
| 1203 | init_hca->cqc_base, |
| 1204 | dev_cap->cqc_entry_sz, |
| 1205 | dev->caps.num_cqs, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1206 | dev->caps.reserved_cqs, 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1207 | if (err) { |
| 1208 | mlx4_err(dev, "Failed to map CQ context memory, aborting.\n"); |
| 1209 | goto err_unmap_rdmarc; |
| 1210 | } |
| 1211 | |
| 1212 | err = mlx4_init_icm_table(dev, &priv->srq_table.table, |
| 1213 | init_hca->srqc_base, |
| 1214 | dev_cap->srq_entry_sz, |
| 1215 | dev->caps.num_srqs, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1216 | dev->caps.reserved_srqs, 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1217 | if (err) { |
| 1218 | mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n"); |
| 1219 | goto err_unmap_cq; |
| 1220 | } |
| 1221 | |
| 1222 | /* |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1223 | * For flow steering device managed mode it is required to use |
| 1224 | * mlx4_init_icm_table. For B0 steering mode it's not strictly |
| 1225 | * required, but for simplicity just map the whole multicast |
| 1226 | * group table now. The table isn't very big and it's a lot |
| 1227 | * easier than trying to track ref counts. |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1228 | */ |
| 1229 | err = mlx4_init_icm_table(dev, &priv->mcg_table.table, |
Eugenia Emantayev | 0ec2c0f | 2011-12-13 04:16:02 +0000 | [diff] [blame] | 1230 | init_hca->mc_base, |
| 1231 | mlx4_get_mgm_entry_size(dev), |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1232 | dev->caps.num_mgms + dev->caps.num_amgms, |
| 1233 | dev->caps.num_mgms + dev->caps.num_amgms, |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1234 | 0, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1235 | if (err) { |
| 1236 | mlx4_err(dev, "Failed to map MCG context memory, aborting.\n"); |
| 1237 | goto err_unmap_srq; |
| 1238 | } |
| 1239 | |
| 1240 | return 0; |
| 1241 | |
| 1242 | err_unmap_srq: |
| 1243 | mlx4_cleanup_icm_table(dev, &priv->srq_table.table); |
| 1244 | |
| 1245 | err_unmap_cq: |
| 1246 | mlx4_cleanup_icm_table(dev, &priv->cq_table.table); |
| 1247 | |
| 1248 | err_unmap_rdmarc: |
| 1249 | mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); |
| 1250 | |
| 1251 | err_unmap_altc: |
| 1252 | mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); |
| 1253 | |
| 1254 | err_unmap_auxc: |
| 1255 | mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); |
| 1256 | |
| 1257 | err_unmap_qp: |
| 1258 | mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); |
| 1259 | |
| 1260 | err_unmap_dmpt: |
| 1261 | mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); |
| 1262 | |
| 1263 | err_unmap_mtt: |
| 1264 | mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); |
| 1265 | |
| 1266 | err_unmap_eq: |
Roland Dreier | fa0681d | 2009-09-05 20:24:49 -0700 | [diff] [blame] | 1267 | mlx4_cleanup_icm_table(dev, &priv->eq_table.table); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1268 | |
| 1269 | err_unmap_cmpt: |
| 1270 | mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); |
| 1271 | mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); |
| 1272 | mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); |
| 1273 | mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); |
| 1274 | |
| 1275 | err_unmap_aux: |
| 1276 | mlx4_UNMAP_ICM_AUX(dev); |
| 1277 | |
| 1278 | err_free_aux: |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1279 | mlx4_free_icm(dev, priv->fw.aux_icm, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1280 | |
| 1281 | return err; |
| 1282 | } |
| 1283 | |
| 1284 | static void mlx4_free_icms(struct mlx4_dev *dev) |
| 1285 | { |
| 1286 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1287 | |
| 1288 | mlx4_cleanup_icm_table(dev, &priv->mcg_table.table); |
| 1289 | mlx4_cleanup_icm_table(dev, &priv->srq_table.table); |
| 1290 | mlx4_cleanup_icm_table(dev, &priv->cq_table.table); |
| 1291 | mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); |
| 1292 | mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); |
| 1293 | mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); |
| 1294 | mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); |
| 1295 | mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); |
| 1296 | mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); |
Roland Dreier | fa0681d | 2009-09-05 20:24:49 -0700 | [diff] [blame] | 1297 | mlx4_cleanup_icm_table(dev, &priv->eq_table.table); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1298 | mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); |
| 1299 | mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); |
| 1300 | mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); |
| 1301 | mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1302 | |
| 1303 | mlx4_UNMAP_ICM_AUX(dev); |
Jack Morgenstein | 5b0bf5e | 2007-08-01 12:28:20 +0300 | [diff] [blame] | 1304 | mlx4_free_icm(dev, priv->fw.aux_icm, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1307 | static void mlx4_slave_exit(struct mlx4_dev *dev) |
| 1308 | { |
| 1309 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1310 | |
Roland Dreier | f3d4c89 | 2012-09-25 21:24:07 -0700 | [diff] [blame] | 1311 | mutex_lock(&priv->cmd.slave_cmd_mutex); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1312 | if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_TIME)) |
| 1313 | mlx4_warn(dev, "Failed to close slave function.\n"); |
Roland Dreier | f3d4c89 | 2012-09-25 21:24:07 -0700 | [diff] [blame] | 1314 | mutex_unlock(&priv->cmd.slave_cmd_mutex); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Eli Cohen | c1b43dc | 2011-03-22 22:38:41 +0000 | [diff] [blame] | 1317 | static int map_bf_area(struct mlx4_dev *dev) |
| 1318 | { |
| 1319 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1320 | resource_size_t bf_start; |
| 1321 | resource_size_t bf_len; |
| 1322 | int err = 0; |
| 1323 | |
Jack Morgenstein | 3d74747 | 2012-02-19 21:38:52 +0000 | [diff] [blame] | 1324 | if (!dev->caps.bf_reg_size) |
| 1325 | return -ENXIO; |
| 1326 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1327 | bf_start = pci_resource_start(dev->pdev, 2) + |
| 1328 | (dev->caps.num_uars << PAGE_SHIFT); |
| 1329 | bf_len = pci_resource_len(dev->pdev, 2) - |
| 1330 | (dev->caps.num_uars << PAGE_SHIFT); |
Eli Cohen | c1b43dc | 2011-03-22 22:38:41 +0000 | [diff] [blame] | 1331 | priv->bf_mapping = io_mapping_create_wc(bf_start, bf_len); |
| 1332 | if (!priv->bf_mapping) |
| 1333 | err = -ENOMEM; |
| 1334 | |
| 1335 | return err; |
| 1336 | } |
| 1337 | |
| 1338 | static void unmap_bf_area(struct mlx4_dev *dev) |
| 1339 | { |
| 1340 | if (mlx4_priv(dev)->bf_mapping) |
| 1341 | io_mapping_free(mlx4_priv(dev)->bf_mapping); |
| 1342 | } |
| 1343 | |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 1344 | cycle_t mlx4_read_clock(struct mlx4_dev *dev) |
| 1345 | { |
| 1346 | u32 clockhi, clocklo, clockhi1; |
| 1347 | cycle_t cycles; |
| 1348 | int i; |
| 1349 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1350 | |
| 1351 | for (i = 0; i < 10; i++) { |
| 1352 | clockhi = swab32(readl(priv->clock_mapping)); |
| 1353 | clocklo = swab32(readl(priv->clock_mapping + 4)); |
| 1354 | clockhi1 = swab32(readl(priv->clock_mapping)); |
| 1355 | if (clockhi == clockhi1) |
| 1356 | break; |
| 1357 | } |
| 1358 | |
| 1359 | cycles = (u64) clockhi << 32 | (u64) clocklo; |
| 1360 | |
| 1361 | return cycles; |
| 1362 | } |
| 1363 | EXPORT_SYMBOL_GPL(mlx4_read_clock); |
| 1364 | |
| 1365 | |
Eugenia Emantayev | ddd8a6c | 2013-04-23 06:06:48 +0000 | [diff] [blame] | 1366 | static int map_internal_clock(struct mlx4_dev *dev) |
| 1367 | { |
| 1368 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1369 | |
| 1370 | priv->clock_mapping = |
| 1371 | ioremap(pci_resource_start(dev->pdev, priv->fw.clock_bar) + |
| 1372 | priv->fw.clock_offset, MLX4_CLOCK_SIZE); |
| 1373 | |
| 1374 | if (!priv->clock_mapping) |
| 1375 | return -ENOMEM; |
| 1376 | |
| 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | static void unmap_internal_clock(struct mlx4_dev *dev) |
| 1381 | { |
| 1382 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1383 | |
| 1384 | if (priv->clock_mapping) |
| 1385 | iounmap(priv->clock_mapping); |
| 1386 | } |
| 1387 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1388 | static void mlx4_close_hca(struct mlx4_dev *dev) |
| 1389 | { |
Eugenia Emantayev | ddd8a6c | 2013-04-23 06:06:48 +0000 | [diff] [blame] | 1390 | unmap_internal_clock(dev); |
Eli Cohen | c1b43dc | 2011-03-22 22:38:41 +0000 | [diff] [blame] | 1391 | unmap_bf_area(dev); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1392 | if (mlx4_is_slave(dev)) |
| 1393 | mlx4_slave_exit(dev); |
| 1394 | else { |
| 1395 | mlx4_CLOSE_HCA(dev, 0); |
| 1396 | mlx4_free_icms(dev); |
| 1397 | mlx4_UNMAP_FA(dev); |
| 1398 | mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0); |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | static int mlx4_init_slave(struct mlx4_dev *dev) |
| 1403 | { |
| 1404 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1405 | u64 dma = (u64) priv->mfunc.vhcr_dma; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1406 | int ret_from_reset = 0; |
| 1407 | u32 slave_read; |
| 1408 | u32 cmd_channel_ver; |
| 1409 | |
Roland Dreier | f3d4c89 | 2012-09-25 21:24:07 -0700 | [diff] [blame] | 1410 | mutex_lock(&priv->cmd.slave_cmd_mutex); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1411 | priv->cmd.max_cmds = 1; |
| 1412 | mlx4_warn(dev, "Sending reset\n"); |
| 1413 | ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, |
| 1414 | MLX4_COMM_TIME); |
| 1415 | /* if we are in the middle of flr the slave will try |
| 1416 | * NUM_OF_RESET_RETRIES times before leaving.*/ |
| 1417 | if (ret_from_reset) { |
| 1418 | if (MLX4_DELAY_RESET_SLAVE == ret_from_reset) { |
Jack Morgenstein | 5efe535 | 2013-06-04 05:13:27 +0000 | [diff] [blame] | 1419 | mlx4_warn(dev, "slave is currently in the " |
| 1420 | "middle of FLR. Deferring probe.\n"); |
| 1421 | mutex_unlock(&priv->cmd.slave_cmd_mutex); |
| 1422 | return -EPROBE_DEFER; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1423 | } else |
| 1424 | goto err; |
| 1425 | } |
| 1426 | |
| 1427 | /* check the driver version - the slave I/F revision |
| 1428 | * must match the master's */ |
| 1429 | slave_read = swab32(readl(&priv->mfunc.comm->slave_read)); |
| 1430 | cmd_channel_ver = mlx4_comm_get_version(); |
| 1431 | |
| 1432 | if (MLX4_COMM_GET_IF_REV(cmd_channel_ver) != |
| 1433 | MLX4_COMM_GET_IF_REV(slave_read)) { |
| 1434 | mlx4_err(dev, "slave driver version is not supported" |
| 1435 | " by the master\n"); |
| 1436 | goto err; |
| 1437 | } |
| 1438 | |
| 1439 | mlx4_warn(dev, "Sending vhcr0\n"); |
| 1440 | if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48, |
| 1441 | MLX4_COMM_TIME)) |
| 1442 | goto err; |
| 1443 | if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32, |
| 1444 | MLX4_COMM_TIME)) |
| 1445 | goto err; |
| 1446 | if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16, |
| 1447 | MLX4_COMM_TIME)) |
| 1448 | goto err; |
| 1449 | if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, MLX4_COMM_TIME)) |
| 1450 | goto err; |
Roland Dreier | f3d4c89 | 2012-09-25 21:24:07 -0700 | [diff] [blame] | 1451 | |
| 1452 | mutex_unlock(&priv->cmd.slave_cmd_mutex); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1453 | return 0; |
| 1454 | |
| 1455 | err: |
| 1456 | mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, 0); |
Roland Dreier | f3d4c89 | 2012-09-25 21:24:07 -0700 | [diff] [blame] | 1457 | mutex_unlock(&priv->cmd.slave_cmd_mutex); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1458 | return -EIO; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 1461 | static void mlx4_parav_master_pf_caps(struct mlx4_dev *dev) |
| 1462 | { |
| 1463 | int i; |
| 1464 | |
| 1465 | for (i = 1; i <= dev->caps.num_ports; i++) { |
| 1466 | dev->caps.gid_table_len[i] = 1; |
| 1467 | dev->caps.pkey_table_len[i] = |
| 1468 | dev->phys_caps.pkey_phys_table_len[i] - 1; |
| 1469 | } |
| 1470 | } |
| 1471 | |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 1472 | static int choose_log_fs_mgm_entry_size(int qp_per_entry) |
| 1473 | { |
| 1474 | int i = MLX4_MIN_MGM_LOG_ENTRY_SIZE; |
| 1475 | |
| 1476 | for (i = MLX4_MIN_MGM_LOG_ENTRY_SIZE; i <= MLX4_MAX_MGM_LOG_ENTRY_SIZE; |
| 1477 | i++) { |
| 1478 | if (qp_per_entry <= 4 * ((1 << i) / 16 - 2)) |
| 1479 | break; |
| 1480 | } |
| 1481 | |
| 1482 | return (i <= MLX4_MAX_MGM_LOG_ENTRY_SIZE) ? i : -1; |
| 1483 | } |
| 1484 | |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 1485 | static void choose_steering_mode(struct mlx4_dev *dev, |
| 1486 | struct mlx4_dev_cap *dev_cap) |
| 1487 | { |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 1488 | if (mlx4_log_num_mgm_entry_size == -1 && |
| 1489 | dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_FS_EN && |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 1490 | (!mlx4_is_mfunc(dev) || |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 1491 | (dev_cap->fs_max_num_qp_per_entry >= (num_vfs + 1))) && |
| 1492 | choose_log_fs_mgm_entry_size(dev_cap->fs_max_num_qp_per_entry) >= |
| 1493 | MLX4_MIN_MGM_LOG_ENTRY_SIZE) { |
| 1494 | dev->oper_log_mgm_entry_size = |
| 1495 | choose_log_fs_mgm_entry_size(dev_cap->fs_max_num_qp_per_entry); |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 1496 | dev->caps.steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED; |
| 1497 | dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; |
| 1498 | dev->caps.fs_log_max_ucast_qp_range_size = |
| 1499 | dev_cap->fs_log_max_ucast_qp_range_size; |
| 1500 | } else { |
| 1501 | if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER && |
| 1502 | dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) |
| 1503 | dev->caps.steering_mode = MLX4_STEERING_MODE_B0; |
| 1504 | else { |
| 1505 | dev->caps.steering_mode = MLX4_STEERING_MODE_A0; |
| 1506 | |
| 1507 | if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER || |
| 1508 | dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) |
| 1509 | mlx4_warn(dev, "Must have both UC_STEER and MC_STEER flags " |
| 1510 | "set to use B0 steering. Falling back to A0 steering mode.\n"); |
| 1511 | } |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 1512 | dev->oper_log_mgm_entry_size = |
| 1513 | mlx4_log_num_mgm_entry_size > 0 ? |
| 1514 | mlx4_log_num_mgm_entry_size : |
| 1515 | MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE; |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 1516 | dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev); |
| 1517 | } |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 1518 | mlx4_dbg(dev, "Steering mode is: %s, oper_log_mgm_entry_size = %d, " |
| 1519 | "modparam log_num_mgm_entry_size = %d\n", |
| 1520 | mlx4_steering_mode_str(dev->caps.steering_mode), |
| 1521 | dev->oper_log_mgm_entry_size, |
| 1522 | mlx4_log_num_mgm_entry_size); |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Or Gerlitz | 7ffdf72 | 2013-12-23 16:09:43 +0200 | [diff] [blame] | 1525 | static void choose_tunnel_offload_mode(struct mlx4_dev *dev, |
| 1526 | struct mlx4_dev_cap *dev_cap) |
| 1527 | { |
| 1528 | if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED && |
| 1529 | dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS) |
| 1530 | dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_VXLAN; |
| 1531 | else |
| 1532 | dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_NONE; |
| 1533 | |
| 1534 | mlx4_dbg(dev, "Tunneling offload mode is: %s\n", (dev->caps.tunnel_offload_mode |
| 1535 | == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) ? "vxlan" : "none"); |
| 1536 | } |
| 1537 | |
Roland Dreier | 3d73c28 | 2007-10-10 15:43:54 -0700 | [diff] [blame] | 1538 | static int mlx4_init_hca(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1539 | { |
| 1540 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1541 | struct mlx4_adapter adapter; |
| 1542 | struct mlx4_dev_cap dev_cap; |
Vladimir Sokolovsky | 2d92865 | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1543 | struct mlx4_mod_stat_cfg mlx4_cfg; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1544 | struct mlx4_profile profile; |
| 1545 | struct mlx4_init_hca_param init_hca; |
| 1546 | u64 icm_size; |
| 1547 | int err; |
| 1548 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1549 | if (!mlx4_is_slave(dev)) { |
| 1550 | err = mlx4_QUERY_FW(dev); |
| 1551 | if (err) { |
| 1552 | if (err == -EACCES) |
| 1553 | mlx4_info(dev, "non-primary physical function, skipping.\n"); |
| 1554 | else |
| 1555 | mlx4_err(dev, "QUERY_FW command failed, aborting.\n"); |
Aviad Yehezkel | bef772e | 2012-09-05 22:50:51 +0000 | [diff] [blame] | 1556 | return err; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1557 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1558 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1559 | err = mlx4_load_fw(dev); |
| 1560 | if (err) { |
| 1561 | mlx4_err(dev, "Failed to start FW, aborting.\n"); |
Aviad Yehezkel | bef772e | 2012-09-05 22:50:51 +0000 | [diff] [blame] | 1562 | return err; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1563 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1564 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1565 | mlx4_cfg.log_pg_sz_m = 1; |
| 1566 | mlx4_cfg.log_pg_sz = 0; |
| 1567 | err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg); |
| 1568 | if (err) |
| 1569 | mlx4_warn(dev, "Failed to override log_pg_sz parameter\n"); |
Vladimir Sokolovsky | 2d92865 | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1570 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1571 | err = mlx4_dev_cap(dev, &dev_cap); |
| 1572 | if (err) { |
| 1573 | mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); |
| 1574 | goto err_stop_fw; |
| 1575 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1576 | |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 1577 | choose_steering_mode(dev, &dev_cap); |
Or Gerlitz | 7ffdf72 | 2013-12-23 16:09:43 +0200 | [diff] [blame] | 1578 | choose_tunnel_offload_mode(dev, &dev_cap); |
Jack Morgenstein | 7b8157b | 2012-12-06 17:11:59 +0000 | [diff] [blame] | 1579 | |
Hadar Hen Zion | 8e1a28e | 2013-12-19 21:20:12 +0200 | [diff] [blame] | 1580 | err = mlx4_get_phys_port_id(dev); |
| 1581 | if (err) |
| 1582 | mlx4_err(dev, "Fail to get physical port id\n"); |
| 1583 | |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 1584 | if (mlx4_is_master(dev)) |
| 1585 | mlx4_parav_master_pf_caps(dev); |
| 1586 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1587 | profile = default_profile; |
Hadar Hen Zion | 0ff1fb6 | 2012-07-05 04:03:46 +0000 | [diff] [blame] | 1588 | if (dev->caps.steering_mode == |
| 1589 | MLX4_STEERING_MODE_DEVICE_MANAGED) |
| 1590 | profile.num_mcg = MLX4_FS_NUM_MCG; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1591 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1592 | icm_size = mlx4_make_profile(dev, &profile, &dev_cap, |
| 1593 | &init_hca); |
| 1594 | if ((long long) icm_size < 0) { |
| 1595 | err = icm_size; |
| 1596 | goto err_stop_fw; |
| 1597 | } |
| 1598 | |
Eli Cohen | a5bbe89 | 2012-02-09 18:10:06 +0200 | [diff] [blame] | 1599 | dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1; |
| 1600 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1601 | init_hca.log_uar_sz = ilog2(dev->caps.num_uars); |
| 1602 | init_hca.uar_page_sz = PAGE_SHIFT - 12; |
Shani Michaeli | e448834 | 2013-02-06 16:19:11 +0000 | [diff] [blame] | 1603 | init_hca.mw_enabled = 0; |
| 1604 | if (dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW || |
| 1605 | dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN) |
| 1606 | init_hca.mw_enabled = INIT_HCA_TPT_MW_ENABLE; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1607 | |
| 1608 | err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size); |
| 1609 | if (err) |
| 1610 | goto err_stop_fw; |
| 1611 | |
| 1612 | err = mlx4_INIT_HCA(dev, &init_hca); |
| 1613 | if (err) { |
| 1614 | mlx4_err(dev, "INIT_HCA command failed, aborting.\n"); |
| 1615 | goto err_free_icm; |
| 1616 | } |
Eugenia Emantayev | ddd8a6c | 2013-04-23 06:06:48 +0000 | [diff] [blame] | 1617 | /* |
| 1618 | * If TS is supported by FW |
| 1619 | * read HCA frequency by QUERY_HCA command |
| 1620 | */ |
| 1621 | if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) { |
| 1622 | memset(&init_hca, 0, sizeof(init_hca)); |
| 1623 | err = mlx4_QUERY_HCA(dev, &init_hca); |
| 1624 | if (err) { |
| 1625 | mlx4_err(dev, "QUERY_HCA command failed, disable timestamp.\n"); |
| 1626 | dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; |
| 1627 | } else { |
| 1628 | dev->caps.hca_core_clock = |
| 1629 | init_hca.hca_core_clock; |
| 1630 | } |
| 1631 | |
| 1632 | /* In case we got HCA frequency 0 - disable timestamping |
| 1633 | * to avoid dividing by zero |
| 1634 | */ |
| 1635 | if (!dev->caps.hca_core_clock) { |
| 1636 | dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; |
| 1637 | mlx4_err(dev, |
| 1638 | "HCA frequency is 0. Timestamping is not supported."); |
| 1639 | } else if (map_internal_clock(dev)) { |
| 1640 | /* |
| 1641 | * Map internal clock, |
| 1642 | * in case of failure disable timestamping |
| 1643 | */ |
| 1644 | dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; |
| 1645 | mlx4_err(dev, "Failed to map internal clock. Timestamping is not supported.\n"); |
| 1646 | } |
| 1647 | } |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1648 | } else { |
| 1649 | err = mlx4_init_slave(dev); |
| 1650 | if (err) { |
Jack Morgenstein | 5efe535 | 2013-06-04 05:13:27 +0000 | [diff] [blame] | 1651 | if (err != -EPROBE_DEFER) |
| 1652 | mlx4_err(dev, "Failed to initialize slave\n"); |
Aviad Yehezkel | bef772e | 2012-09-05 22:50:51 +0000 | [diff] [blame] | 1653 | return err; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | err = mlx4_slave_cap(dev); |
| 1657 | if (err) { |
| 1658 | mlx4_err(dev, "Failed to obtain slave caps\n"); |
| 1659 | goto err_close; |
| 1660 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
Eli Cohen | c1b43dc | 2011-03-22 22:38:41 +0000 | [diff] [blame] | 1663 | if (map_bf_area(dev)) |
| 1664 | mlx4_dbg(dev, "Failed to map blue flame area\n"); |
| 1665 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1666 | /*Only the master set the ports, all the rest got it from it.*/ |
| 1667 | if (!mlx4_is_slave(dev)) |
| 1668 | mlx4_set_port_mask(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1669 | |
| 1670 | err = mlx4_QUERY_ADAPTER(dev, &adapter); |
| 1671 | if (err) { |
| 1672 | mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n"); |
Aviad Yehezkel | bef772e | 2012-09-05 22:50:51 +0000 | [diff] [blame] | 1673 | goto unmap_bf; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | priv->eq_table.inta_pin = adapter.inta_pin; |
Jack Morgenstein | cd9281d | 2007-09-18 09:14:18 +0200 | [diff] [blame] | 1677 | memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1678 | |
| 1679 | return 0; |
| 1680 | |
Aviad Yehezkel | bef772e | 2012-09-05 22:50:51 +0000 | [diff] [blame] | 1681 | unmap_bf: |
Eugenia Emantayev | ddd8a6c | 2013-04-23 06:06:48 +0000 | [diff] [blame] | 1682 | unmap_internal_clock(dev); |
Aviad Yehezkel | bef772e | 2012-09-05 22:50:51 +0000 | [diff] [blame] | 1683 | unmap_bf_area(dev); |
| 1684 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1685 | err_close: |
Dotan Barak | 41929ed | 2012-10-21 14:59:23 +0000 | [diff] [blame] | 1686 | if (mlx4_is_slave(dev)) |
| 1687 | mlx4_slave_exit(dev); |
| 1688 | else |
| 1689 | mlx4_CLOSE_HCA(dev, 0); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1690 | |
| 1691 | err_free_icm: |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1692 | if (!mlx4_is_slave(dev)) |
| 1693 | mlx4_free_icms(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1694 | |
| 1695 | err_stop_fw: |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1696 | if (!mlx4_is_slave(dev)) { |
| 1697 | mlx4_UNMAP_FA(dev); |
| 1698 | mlx4_free_icm(dev, priv->fw.fw_icm, 0); |
| 1699 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1700 | return err; |
| 1701 | } |
| 1702 | |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1703 | static int mlx4_init_counters_table(struct mlx4_dev *dev) |
| 1704 | { |
| 1705 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1706 | int nent; |
| 1707 | |
| 1708 | if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) |
| 1709 | return -ENOENT; |
| 1710 | |
| 1711 | nent = dev->caps.max_counters; |
| 1712 | return mlx4_bitmap_init(&priv->counters_bitmap, nent, nent - 1, 0, 0); |
| 1713 | } |
| 1714 | |
| 1715 | static void mlx4_cleanup_counters_table(struct mlx4_dev *dev) |
| 1716 | { |
| 1717 | mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap); |
| 1718 | } |
| 1719 | |
Jack Morgenstein | ba062d5 | 2012-05-15 10:35:03 +0000 | [diff] [blame] | 1720 | int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx) |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1721 | { |
| 1722 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1723 | |
| 1724 | if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) |
| 1725 | return -ENOENT; |
| 1726 | |
| 1727 | *idx = mlx4_bitmap_alloc(&priv->counters_bitmap); |
| 1728 | if (*idx == -1) |
| 1729 | return -ENOMEM; |
| 1730 | |
| 1731 | return 0; |
| 1732 | } |
Jack Morgenstein | ba062d5 | 2012-05-15 10:35:03 +0000 | [diff] [blame] | 1733 | |
| 1734 | int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx) |
| 1735 | { |
| 1736 | u64 out_param; |
| 1737 | int err; |
| 1738 | |
| 1739 | if (mlx4_is_mfunc(dev)) { |
| 1740 | err = mlx4_cmd_imm(dev, 0, &out_param, RES_COUNTER, |
| 1741 | RES_OP_RESERVE, MLX4_CMD_ALLOC_RES, |
| 1742 | MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED); |
| 1743 | if (!err) |
| 1744 | *idx = get_param_l(&out_param); |
| 1745 | |
| 1746 | return err; |
| 1747 | } |
| 1748 | return __mlx4_counter_alloc(dev, idx); |
| 1749 | } |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1750 | EXPORT_SYMBOL_GPL(mlx4_counter_alloc); |
| 1751 | |
Jack Morgenstein | ba062d5 | 2012-05-15 10:35:03 +0000 | [diff] [blame] | 1752 | void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx) |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1753 | { |
Jack Morgenstein | 7c6d74d | 2013-12-08 16:50:17 +0200 | [diff] [blame] | 1754 | mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx, MLX4_USE_RR); |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1755 | return; |
| 1756 | } |
Jack Morgenstein | ba062d5 | 2012-05-15 10:35:03 +0000 | [diff] [blame] | 1757 | |
| 1758 | void mlx4_counter_free(struct mlx4_dev *dev, u32 idx) |
| 1759 | { |
Jack Morgenstein | e7dbeba | 2013-03-07 03:46:54 +0000 | [diff] [blame] | 1760 | u64 in_param = 0; |
Jack Morgenstein | ba062d5 | 2012-05-15 10:35:03 +0000 | [diff] [blame] | 1761 | |
| 1762 | if (mlx4_is_mfunc(dev)) { |
| 1763 | set_param_l(&in_param, idx); |
| 1764 | mlx4_cmd(dev, in_param, RES_COUNTER, RES_OP_RESERVE, |
| 1765 | MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A, |
| 1766 | MLX4_CMD_WRAPPED); |
| 1767 | return; |
| 1768 | } |
| 1769 | __mlx4_counter_free(dev, idx); |
| 1770 | } |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1771 | EXPORT_SYMBOL_GPL(mlx4_counter_free); |
| 1772 | |
Roland Dreier | 3d73c28 | 2007-10-10 15:43:54 -0700 | [diff] [blame] | 1773 | static int mlx4_setup_hca(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1774 | { |
| 1775 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 1776 | int err; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 1777 | int port; |
Jack Morgenstein | 9a5aa62 | 2008-11-28 21:29:46 -0800 | [diff] [blame] | 1778 | __be32 ib_port_default_caps; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1779 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1780 | err = mlx4_init_uar_table(dev); |
| 1781 | if (err) { |
| 1782 | mlx4_err(dev, "Failed to initialize " |
| 1783 | "user access region table, aborting.\n"); |
| 1784 | return err; |
| 1785 | } |
| 1786 | |
| 1787 | err = mlx4_uar_alloc(dev, &priv->driver_uar); |
| 1788 | if (err) { |
| 1789 | mlx4_err(dev, "Failed to allocate driver access region, " |
| 1790 | "aborting.\n"); |
| 1791 | goto err_uar_table_free; |
| 1792 | } |
| 1793 | |
Roland Dreier | 4979d18 | 2011-01-12 09:50:36 -0800 | [diff] [blame] | 1794 | priv->kar = ioremap((phys_addr_t) priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1795 | if (!priv->kar) { |
| 1796 | mlx4_err(dev, "Couldn't map kernel access region, " |
| 1797 | "aborting.\n"); |
| 1798 | err = -ENOMEM; |
| 1799 | goto err_uar_free; |
| 1800 | } |
| 1801 | |
| 1802 | err = mlx4_init_pd_table(dev); |
| 1803 | if (err) { |
| 1804 | mlx4_err(dev, "Failed to initialize " |
| 1805 | "protection domain table, aborting.\n"); |
| 1806 | goto err_kar_unmap; |
| 1807 | } |
| 1808 | |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 1809 | err = mlx4_init_xrcd_table(dev); |
| 1810 | if (err) { |
| 1811 | mlx4_err(dev, "Failed to initialize " |
| 1812 | "reliable connection domain table, aborting.\n"); |
| 1813 | goto err_pd_table_free; |
| 1814 | } |
| 1815 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1816 | err = mlx4_init_mr_table(dev); |
| 1817 | if (err) { |
| 1818 | mlx4_err(dev, "Failed to initialize " |
| 1819 | "memory region table, aborting.\n"); |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 1820 | goto err_xrcd_table_free; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Yevgeny Petrilin | fe6f700 | 2013-07-28 18:54:21 +0300 | [diff] [blame] | 1823 | if (!mlx4_is_slave(dev)) { |
| 1824 | err = mlx4_init_mcg_table(dev); |
| 1825 | if (err) { |
| 1826 | mlx4_err(dev, "Failed to initialize multicast group table, aborting.\n"); |
| 1827 | goto err_mr_table_free; |
| 1828 | } |
| 1829 | } |
| 1830 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1831 | err = mlx4_init_eq_table(dev); |
| 1832 | if (err) { |
| 1833 | mlx4_err(dev, "Failed to initialize " |
| 1834 | "event queue table, aborting.\n"); |
Yevgeny Petrilin | fe6f700 | 2013-07-28 18:54:21 +0300 | [diff] [blame] | 1835 | goto err_mcg_table_free; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | err = mlx4_cmd_use_events(dev); |
| 1839 | if (err) { |
| 1840 | mlx4_err(dev, "Failed to switch to event-driven " |
| 1841 | "firmware commands, aborting.\n"); |
| 1842 | goto err_eq_table_free; |
| 1843 | } |
| 1844 | |
| 1845 | err = mlx4_NOP(dev); |
| 1846 | if (err) { |
Michael S. Tsirkin | 08fb105 | 2007-08-07 16:08:28 +0300 | [diff] [blame] | 1847 | if (dev->flags & MLX4_FLAG_MSI_X) { |
| 1848 | mlx4_warn(dev, "NOP command failed to generate MSI-X " |
| 1849 | "interrupt IRQ %d).\n", |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 1850 | priv->eq_table.eq[dev->caps.num_comp_vectors].irq); |
Michael S. Tsirkin | 08fb105 | 2007-08-07 16:08:28 +0300 | [diff] [blame] | 1851 | mlx4_warn(dev, "Trying again without MSI-X.\n"); |
| 1852 | } else { |
| 1853 | mlx4_err(dev, "NOP command failed to generate interrupt " |
| 1854 | "(IRQ %d), aborting.\n", |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 1855 | priv->eq_table.eq[dev->caps.num_comp_vectors].irq); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1856 | mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n"); |
Michael S. Tsirkin | 08fb105 | 2007-08-07 16:08:28 +0300 | [diff] [blame] | 1857 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1858 | |
| 1859 | goto err_cmd_poll; |
| 1860 | } |
| 1861 | |
| 1862 | mlx4_dbg(dev, "NOP command IRQ test passed\n"); |
| 1863 | |
| 1864 | err = mlx4_init_cq_table(dev); |
| 1865 | if (err) { |
| 1866 | mlx4_err(dev, "Failed to initialize " |
| 1867 | "completion queue table, aborting.\n"); |
| 1868 | goto err_cmd_poll; |
| 1869 | } |
| 1870 | |
| 1871 | err = mlx4_init_srq_table(dev); |
| 1872 | if (err) { |
| 1873 | mlx4_err(dev, "Failed to initialize " |
| 1874 | "shared receive queue table, aborting.\n"); |
| 1875 | goto err_cq_table_free; |
| 1876 | } |
| 1877 | |
| 1878 | err = mlx4_init_qp_table(dev); |
| 1879 | if (err) { |
| 1880 | mlx4_err(dev, "Failed to initialize " |
| 1881 | "queue pair table, aborting.\n"); |
| 1882 | goto err_srq_table_free; |
| 1883 | } |
| 1884 | |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1885 | err = mlx4_init_counters_table(dev); |
| 1886 | if (err && err != -ENOENT) { |
| 1887 | mlx4_err(dev, "Failed to initialize counters table, aborting.\n"); |
Yevgeny Petrilin | fe6f700 | 2013-07-28 18:54:21 +0300 | [diff] [blame] | 1888 | goto err_qp_table_free; |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1891 | if (!mlx4_is_slave(dev)) { |
| 1892 | for (port = 1; port <= dev->caps.num_ports; port++) { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1893 | ib_port_default_caps = 0; |
| 1894 | err = mlx4_get_port_ib_caps(dev, port, |
| 1895 | &ib_port_default_caps); |
| 1896 | if (err) |
| 1897 | mlx4_warn(dev, "failed to get port %d default " |
| 1898 | "ib capabilities (%d). Continuing " |
| 1899 | "with caps = 0\n", port, err); |
| 1900 | dev->caps.ib_port_def_cap[port] = ib_port_default_caps; |
Marcel Apfelbaum | 97285b7 | 2011-10-24 11:02:34 +0200 | [diff] [blame] | 1901 | |
Jack Morgenstein | 2aca117 | 2012-06-19 11:21:41 +0300 | [diff] [blame] | 1902 | /* initialize per-slave default ib port capabilities */ |
| 1903 | if (mlx4_is_master(dev)) { |
| 1904 | int i; |
| 1905 | for (i = 0; i < dev->num_slaves; i++) { |
| 1906 | if (i == mlx4_master_func_num(dev)) |
| 1907 | continue; |
| 1908 | priv->mfunc.master.slave_state[i].ib_cap_mask[port] = |
| 1909 | ib_port_default_caps; |
| 1910 | } |
| 1911 | } |
| 1912 | |
Or Gerlitz | 096335b | 2012-01-11 19:02:17 +0200 | [diff] [blame] | 1913 | if (mlx4_is_mfunc(dev)) |
| 1914 | dev->caps.port_ib_mtu[port] = IB_MTU_2048; |
| 1915 | else |
| 1916 | dev->caps.port_ib_mtu[port] = IB_MTU_4096; |
Marcel Apfelbaum | 97285b7 | 2011-10-24 11:02:34 +0200 | [diff] [blame] | 1917 | |
Jack Morgenstein | 6634961 | 2012-06-19 11:21:44 +0300 | [diff] [blame] | 1918 | err = mlx4_SET_PORT(dev, port, mlx4_is_master(dev) ? |
| 1919 | dev->caps.pkey_table_len[port] : -1); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1920 | if (err) { |
| 1921 | mlx4_err(dev, "Failed to set port %d, aborting\n", |
| 1922 | port); |
| 1923 | goto err_counters_table_free; |
| 1924 | } |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1928 | return 0; |
| 1929 | |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 1930 | err_counters_table_free: |
| 1931 | mlx4_cleanup_counters_table(dev); |
| 1932 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1933 | err_qp_table_free: |
| 1934 | mlx4_cleanup_qp_table(dev); |
| 1935 | |
| 1936 | err_srq_table_free: |
| 1937 | mlx4_cleanup_srq_table(dev); |
| 1938 | |
| 1939 | err_cq_table_free: |
| 1940 | mlx4_cleanup_cq_table(dev); |
| 1941 | |
| 1942 | err_cmd_poll: |
| 1943 | mlx4_cmd_use_polling(dev); |
| 1944 | |
| 1945 | err_eq_table_free: |
| 1946 | mlx4_cleanup_eq_table(dev); |
| 1947 | |
Yevgeny Petrilin | fe6f700 | 2013-07-28 18:54:21 +0300 | [diff] [blame] | 1948 | err_mcg_table_free: |
| 1949 | if (!mlx4_is_slave(dev)) |
| 1950 | mlx4_cleanup_mcg_table(dev); |
| 1951 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 1952 | err_mr_table_free: |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1953 | mlx4_cleanup_mr_table(dev); |
| 1954 | |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 1955 | err_xrcd_table_free: |
| 1956 | mlx4_cleanup_xrcd_table(dev); |
| 1957 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1958 | err_pd_table_free: |
| 1959 | mlx4_cleanup_pd_table(dev); |
| 1960 | |
| 1961 | err_kar_unmap: |
| 1962 | iounmap(priv->kar); |
| 1963 | |
| 1964 | err_uar_free: |
| 1965 | mlx4_uar_free(dev, &priv->driver_uar); |
| 1966 | |
| 1967 | err_uar_table_free: |
| 1968 | mlx4_cleanup_uar_table(dev); |
| 1969 | return err; |
| 1970 | } |
| 1971 | |
Roland Dreier | e8f9b2e | 2008-02-04 20:20:41 -0800 | [diff] [blame] | 1972 | static void mlx4_enable_msi_x(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1973 | { |
| 1974 | struct mlx4_priv *priv = mlx4_priv(dev); |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 1975 | struct msix_entry *entries; |
Yevgeny Petrilin | 0b7ca5a | 2011-03-22 22:37:47 +0000 | [diff] [blame] | 1976 | int nreq = min_t(int, dev->caps.num_ports * |
Yuval Mintz | 90b1ebe | 2012-07-01 03:18:51 +0000 | [diff] [blame] | 1977 | min_t(int, netif_get_num_default_rss_queues() + 1, |
| 1978 | MAX_MSIX_P_PORT) + MSIX_LEGACY_SZ, MAX_MSIX); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1979 | int err; |
| 1980 | int i; |
| 1981 | |
| 1982 | if (msi_x) { |
Or Gerlitz | ca4c7b3 | 2013-01-17 05:30:43 +0000 | [diff] [blame] | 1983 | nreq = min_t(int, dev->caps.num_eqs - dev->caps.reserved_eqs, |
| 1984 | nreq); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 1985 | |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 1986 | entries = kcalloc(nreq, sizeof *entries, GFP_KERNEL); |
| 1987 | if (!entries) |
| 1988 | goto no_msi; |
| 1989 | |
| 1990 | for (i = 0; i < nreq; ++i) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1991 | entries[i].entry = i; |
| 1992 | |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 1993 | retry: |
| 1994 | err = pci_enable_msix(dev->pdev, entries, nreq); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1995 | if (err) { |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 1996 | /* Try again if at least 2 vectors are available */ |
| 1997 | if (err > 1) { |
| 1998 | mlx4_info(dev, "Requested %d vectors, " |
| 1999 | "but only %d MSI-X vectors available, " |
| 2000 | "trying again\n", nreq, err); |
| 2001 | nreq = err; |
| 2002 | goto retry; |
| 2003 | } |
Nicolas Morey-Chaisemartin | 5bf0da7 | 2009-04-21 10:11:06 -0700 | [diff] [blame] | 2004 | kfree(entries); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2005 | goto no_msi; |
| 2006 | } |
| 2007 | |
Yevgeny Petrilin | 0b7ca5a | 2011-03-22 22:37:47 +0000 | [diff] [blame] | 2008 | if (nreq < |
| 2009 | MSIX_LEGACY_SZ + dev->caps.num_ports * MIN_MSIX_P_PORT) { |
| 2010 | /*Working in legacy mode , all EQ's shared*/ |
| 2011 | dev->caps.comp_pool = 0; |
| 2012 | dev->caps.num_comp_vectors = nreq - 1; |
| 2013 | } else { |
| 2014 | dev->caps.comp_pool = nreq - MSIX_LEGACY_SZ; |
| 2015 | dev->caps.num_comp_vectors = MSIX_LEGACY_SZ - 1; |
| 2016 | } |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2017 | for (i = 0; i < nreq; ++i) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2018 | priv->eq_table.eq[i].irq = entries[i].vector; |
| 2019 | |
| 2020 | dev->flags |= MLX4_FLAG_MSI_X; |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2021 | |
| 2022 | kfree(entries); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2023 | return; |
| 2024 | } |
| 2025 | |
| 2026 | no_msi: |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2027 | dev->caps.num_comp_vectors = 1; |
Yevgeny Petrilin | 0b7ca5a | 2011-03-22 22:37:47 +0000 | [diff] [blame] | 2028 | dev->caps.comp_pool = 0; |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2029 | |
| 2030 | for (i = 0; i < 2; ++i) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2031 | priv->eq_table.eq[i].irq = dev->pdev->irq; |
| 2032 | } |
| 2033 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2034 | static int mlx4_init_port_info(struct mlx4_dev *dev, int port) |
Yevgeny Petrilin | 2a2336f | 2008-10-22 11:44:46 -0700 | [diff] [blame] | 2035 | { |
| 2036 | struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2037 | int err = 0; |
Yevgeny Petrilin | 2a2336f | 2008-10-22 11:44:46 -0700 | [diff] [blame] | 2038 | |
| 2039 | info->dev = dev; |
| 2040 | info->port = port; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2041 | if (!mlx4_is_slave(dev)) { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2042 | mlx4_init_mac_table(dev, &info->mac_table); |
| 2043 | mlx4_init_vlan_table(dev, &info->vlan_table); |
Yan Burman | 16a10ff | 2013-02-07 02:25:22 +0000 | [diff] [blame] | 2044 | info->base_qpn = mlx4_get_base_qpn(dev, port); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2045 | } |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2046 | |
| 2047 | sprintf(info->dev_name, "mlx4_port%d", port); |
| 2048 | info->port_attr.attr.name = info->dev_name; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2049 | if (mlx4_is_mfunc(dev)) |
| 2050 | info->port_attr.attr.mode = S_IRUGO; |
| 2051 | else { |
| 2052 | info->port_attr.attr.mode = S_IRUGO | S_IWUSR; |
| 2053 | info->port_attr.store = set_port_type; |
| 2054 | } |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2055 | info->port_attr.show = show_port_type; |
Greg Kroah-Hartman | 3691c96 | 2010-03-15 14:01:55 -0700 | [diff] [blame] | 2056 | sysfs_attr_init(&info->port_attr.attr); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2057 | |
| 2058 | err = device_create_file(&dev->pdev->dev, &info->port_attr); |
| 2059 | if (err) { |
| 2060 | mlx4_err(dev, "Failed to create file for port %d\n", port); |
| 2061 | info->port = -1; |
| 2062 | } |
| 2063 | |
Or Gerlitz | 096335b | 2012-01-11 19:02:17 +0200 | [diff] [blame] | 2064 | sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port); |
| 2065 | info->port_mtu_attr.attr.name = info->dev_mtu_name; |
| 2066 | if (mlx4_is_mfunc(dev)) |
| 2067 | info->port_mtu_attr.attr.mode = S_IRUGO; |
| 2068 | else { |
| 2069 | info->port_mtu_attr.attr.mode = S_IRUGO | S_IWUSR; |
| 2070 | info->port_mtu_attr.store = set_port_ib_mtu; |
| 2071 | } |
| 2072 | info->port_mtu_attr.show = show_port_ib_mtu; |
| 2073 | sysfs_attr_init(&info->port_mtu_attr.attr); |
| 2074 | |
| 2075 | err = device_create_file(&dev->pdev->dev, &info->port_mtu_attr); |
| 2076 | if (err) { |
| 2077 | mlx4_err(dev, "Failed to create mtu file for port %d\n", port); |
| 2078 | device_remove_file(&info->dev->pdev->dev, &info->port_attr); |
| 2079 | info->port = -1; |
| 2080 | } |
| 2081 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2082 | return err; |
| 2083 | } |
| 2084 | |
| 2085 | static void mlx4_cleanup_port_info(struct mlx4_port_info *info) |
| 2086 | { |
| 2087 | if (info->port < 0) |
| 2088 | return; |
| 2089 | |
| 2090 | device_remove_file(&info->dev->pdev->dev, &info->port_attr); |
Or Gerlitz | 096335b | 2012-01-11 19:02:17 +0200 | [diff] [blame] | 2091 | device_remove_file(&info->dev->pdev->dev, &info->port_mtu_attr); |
Yevgeny Petrilin | 2a2336f | 2008-10-22 11:44:46 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 2094 | static int mlx4_init_steering(struct mlx4_dev *dev) |
| 2095 | { |
| 2096 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 2097 | int num_entries = dev->caps.num_ports; |
| 2098 | int i, j; |
| 2099 | |
| 2100 | priv->steer = kzalloc(sizeof(struct mlx4_steer) * num_entries, GFP_KERNEL); |
| 2101 | if (!priv->steer) |
| 2102 | return -ENOMEM; |
| 2103 | |
Eugenia Emantayev | 45b5136 | 2012-02-14 06:37:41 +0000 | [diff] [blame] | 2104 | for (i = 0; i < num_entries; i++) |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 2105 | for (j = 0; j < MLX4_NUM_STEERS; j++) { |
| 2106 | INIT_LIST_HEAD(&priv->steer[i].promisc_qps[j]); |
| 2107 | INIT_LIST_HEAD(&priv->steer[i].steer_entries[j]); |
| 2108 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 2109 | return 0; |
| 2110 | } |
| 2111 | |
| 2112 | static void mlx4_clear_steering(struct mlx4_dev *dev) |
| 2113 | { |
| 2114 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 2115 | struct mlx4_steer_index *entry, *tmp_entry; |
| 2116 | struct mlx4_promisc_qp *pqp, *tmp_pqp; |
| 2117 | int num_entries = dev->caps.num_ports; |
| 2118 | int i, j; |
| 2119 | |
| 2120 | for (i = 0; i < num_entries; i++) { |
| 2121 | for (j = 0; j < MLX4_NUM_STEERS; j++) { |
| 2122 | list_for_each_entry_safe(pqp, tmp_pqp, |
| 2123 | &priv->steer[i].promisc_qps[j], |
| 2124 | list) { |
| 2125 | list_del(&pqp->list); |
| 2126 | kfree(pqp); |
| 2127 | } |
| 2128 | list_for_each_entry_safe(entry, tmp_entry, |
| 2129 | &priv->steer[i].steer_entries[j], |
| 2130 | list) { |
| 2131 | list_del(&entry->list); |
| 2132 | list_for_each_entry_safe(pqp, tmp_pqp, |
| 2133 | &entry->duplicates, |
| 2134 | list) { |
| 2135 | list_del(&pqp->list); |
| 2136 | kfree(pqp); |
| 2137 | } |
| 2138 | kfree(entry); |
| 2139 | } |
| 2140 | } |
| 2141 | } |
| 2142 | kfree(priv->steer); |
| 2143 | } |
| 2144 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2145 | static int extended_func_num(struct pci_dev *pdev) |
| 2146 | { |
| 2147 | return PCI_SLOT(pdev->devfn) * 8 + PCI_FUNC(pdev->devfn); |
| 2148 | } |
| 2149 | |
| 2150 | #define MLX4_OWNER_BASE 0x8069c |
| 2151 | #define MLX4_OWNER_SIZE 4 |
| 2152 | |
| 2153 | static int mlx4_get_ownership(struct mlx4_dev *dev) |
| 2154 | { |
| 2155 | void __iomem *owner; |
| 2156 | u32 ret; |
| 2157 | |
Kleber Sacilotto de Souza | 57dbf29 | 2012-07-20 09:55:43 +0000 | [diff] [blame] | 2158 | if (pci_channel_offline(dev->pdev)) |
| 2159 | return -EIO; |
| 2160 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2161 | owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE, |
| 2162 | MLX4_OWNER_SIZE); |
| 2163 | if (!owner) { |
| 2164 | mlx4_err(dev, "Failed to obtain ownership bit\n"); |
| 2165 | return -ENOMEM; |
| 2166 | } |
| 2167 | |
| 2168 | ret = readl(owner); |
| 2169 | iounmap(owner); |
| 2170 | return (int) !!ret; |
| 2171 | } |
| 2172 | |
| 2173 | static void mlx4_free_ownership(struct mlx4_dev *dev) |
| 2174 | { |
| 2175 | void __iomem *owner; |
| 2176 | |
Kleber Sacilotto de Souza | 57dbf29 | 2012-07-20 09:55:43 +0000 | [diff] [blame] | 2177 | if (pci_channel_offline(dev->pdev)) |
| 2178 | return; |
| 2179 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2180 | owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE, |
| 2181 | MLX4_OWNER_SIZE); |
| 2182 | if (!owner) { |
| 2183 | mlx4_err(dev, "Failed to obtain ownership bit\n"); |
| 2184 | return; |
| 2185 | } |
| 2186 | writel(0, owner); |
| 2187 | msleep(1000); |
| 2188 | iounmap(owner); |
| 2189 | } |
| 2190 | |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2191 | static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2192 | { |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2193 | struct mlx4_priv *priv; |
| 2194 | struct mlx4_dev *dev; |
| 2195 | int err; |
Yevgeny Petrilin | 2a2336f | 2008-10-22 11:44:46 -0700 | [diff] [blame] | 2196 | int port; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2197 | |
Joe Perches | 0a645e8 | 2010-07-10 07:22:46 +0000 | [diff] [blame] | 2198 | pr_info(DRV_NAME ": Initializing %s\n", pci_name(pdev)); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2199 | |
| 2200 | err = pci_enable_device(pdev); |
| 2201 | if (err) { |
| 2202 | dev_err(&pdev->dev, "Cannot enable PCI device, " |
| 2203 | "aborting.\n"); |
| 2204 | return err; |
| 2205 | } |
Jack Morgenstein | 5a0d0a6 | 2013-11-03 10:03:23 +0200 | [diff] [blame] | 2206 | |
| 2207 | /* Due to requirement that all VFs and the PF are *guaranteed* 2 MACS |
| 2208 | * per port, we must limit the number of VFs to 63 (since their are |
| 2209 | * 128 MACs) |
| 2210 | */ |
| 2211 | if (num_vfs >= MLX4_MAX_NUM_VF) { |
| 2212 | dev_err(&pdev->dev, |
| 2213 | "Requested more VF's (%d) than allowed (%d)\n", |
| 2214 | num_vfs, MLX4_MAX_NUM_VF - 1); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2215 | return -EINVAL; |
| 2216 | } |
Jack Morgenstein | 30e514a | 2013-06-25 12:09:38 +0300 | [diff] [blame] | 2217 | |
| 2218 | if (num_vfs < 0) { |
| 2219 | pr_err("num_vfs module parameter cannot be negative\n"); |
| 2220 | return -EINVAL; |
| 2221 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2222 | /* |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2223 | * Check for BARs. |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2224 | */ |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2225 | if (!(pci_dev_data & MLX4_PCI_DEV_IS_VF) && |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2226 | !(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 2227 | dev_err(&pdev->dev, "Missing DCS, aborting." |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2228 | "(driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\n", |
| 2229 | pci_dev_data, pci_resource_flags(pdev, 0)); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2230 | err = -ENODEV; |
| 2231 | goto err_disable_pdev; |
| 2232 | } |
| 2233 | if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
| 2234 | dev_err(&pdev->dev, "Missing UAR, aborting.\n"); |
| 2235 | err = -ENODEV; |
| 2236 | goto err_disable_pdev; |
| 2237 | } |
| 2238 | |
Roland Dreier | a01df0f | 2009-09-05 20:24:48 -0700 | [diff] [blame] | 2239 | err = pci_request_regions(pdev, DRV_NAME); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2240 | if (err) { |
Roland Dreier | a01df0f | 2009-09-05 20:24:48 -0700 | [diff] [blame] | 2241 | dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n"); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2242 | goto err_disable_pdev; |
| 2243 | } |
| 2244 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2245 | pci_set_master(pdev); |
| 2246 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 2247 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2248 | if (err) { |
| 2249 | dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n"); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2250 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2251 | if (err) { |
| 2252 | dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n"); |
Roland Dreier | a01df0f | 2009-09-05 20:24:48 -0700 | [diff] [blame] | 2253 | goto err_release_regions; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2254 | } |
| 2255 | } |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 2256 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2257 | if (err) { |
| 2258 | dev_warn(&pdev->dev, "Warning: couldn't set 64-bit " |
| 2259 | "consistent PCI DMA mask.\n"); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2260 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2261 | if (err) { |
| 2262 | dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, " |
| 2263 | "aborting.\n"); |
Roland Dreier | a01df0f | 2009-09-05 20:24:48 -0700 | [diff] [blame] | 2264 | goto err_release_regions; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
David Dillow | 7f9e5c48 | 2011-01-17 02:09:44 +0000 | [diff] [blame] | 2268 | /* Allow large DMA segments, up to the firmware limit of 1 GB */ |
| 2269 | dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024); |
| 2270 | |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 2271 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2272 | if (!priv) { |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2273 | err = -ENOMEM; |
Roland Dreier | a01df0f | 2009-09-05 20:24:48 -0700 | [diff] [blame] | 2274 | goto err_release_regions; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | dev = &priv->dev; |
| 2278 | dev->pdev = pdev; |
Roland Dreier | b581401 | 2007-06-07 11:51:58 -0700 | [diff] [blame] | 2279 | INIT_LIST_HEAD(&priv->ctx_list); |
| 2280 | spin_lock_init(&priv->ctx_lock); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2281 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2282 | mutex_init(&priv->port_mutex); |
| 2283 | |
Yevgeny Petrilin | 6296883 | 2008-04-23 11:55:45 -0700 | [diff] [blame] | 2284 | INIT_LIST_HEAD(&priv->pgdir_list); |
| 2285 | mutex_init(&priv->pgdir_mutex); |
| 2286 | |
Eli Cohen | c1b43dc | 2011-03-22 22:38:41 +0000 | [diff] [blame] | 2287 | INIT_LIST_HEAD(&priv->bf_list); |
| 2288 | mutex_init(&priv->bf_mutex); |
| 2289 | |
Sergei Shtylyov | aca7a3a | 2011-06-23 04:44:30 +0000 | [diff] [blame] | 2290 | dev->rev_id = pdev->revision; |
Eugenia Emantayev | 6e7136e | 2013-11-07 12:19:53 +0200 | [diff] [blame] | 2291 | dev->numa_node = dev_to_node(&pdev->dev); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2292 | /* Detect if this device is a virtual function */ |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2293 | if (pci_dev_data & MLX4_PCI_DEV_IS_VF) { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2294 | /* When acting as pf, we normally skip vfs unless explicitly |
| 2295 | * requested to probe them. */ |
| 2296 | if (num_vfs && extended_func_num(pdev) > probe_vf) { |
| 2297 | mlx4_warn(dev, "Skipping virtual function:%d\n", |
| 2298 | extended_func_num(pdev)); |
| 2299 | err = -ENODEV; |
| 2300 | goto err_free_dev; |
| 2301 | } |
| 2302 | mlx4_warn(dev, "Detected virtual function - running in slave mode\n"); |
| 2303 | dev->flags |= MLX4_FLAG_SLAVE; |
| 2304 | } else { |
| 2305 | /* We reset the device and enable SRIOV only for physical |
| 2306 | * devices. Try to claim ownership on the device; |
| 2307 | * if already taken, skip -- do not allow multiple PFs */ |
| 2308 | err = mlx4_get_ownership(dev); |
| 2309 | if (err) { |
| 2310 | if (err < 0) |
| 2311 | goto err_free_dev; |
| 2312 | else { |
| 2313 | mlx4_warn(dev, "Multiple PFs not yet supported." |
| 2314 | " Skipping PF.\n"); |
| 2315 | err = -EINVAL; |
| 2316 | goto err_free_dev; |
| 2317 | } |
| 2318 | } |
Sergei Shtylyov | aca7a3a | 2011-06-23 04:44:30 +0000 | [diff] [blame] | 2319 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2320 | if (num_vfs) { |
Roland Dreier | 84b1f15 | 2012-09-25 17:09:42 -0700 | [diff] [blame] | 2321 | mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2322 | err = pci_enable_sriov(pdev, num_vfs); |
| 2323 | if (err) { |
Roland Dreier | 84b1f15 | 2012-09-25 17:09:42 -0700 | [diff] [blame] | 2324 | mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n", |
| 2325 | err); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2326 | err = 0; |
| 2327 | } else { |
| 2328 | mlx4_warn(dev, "Running in master mode\n"); |
| 2329 | dev->flags |= MLX4_FLAG_SRIOV | |
| 2330 | MLX4_FLAG_MASTER; |
| 2331 | dev->num_vfs = num_vfs; |
| 2332 | } |
| 2333 | } |
| 2334 | |
Yevgeny Petrilin | fe6f700 | 2013-07-28 18:54:21 +0300 | [diff] [blame] | 2335 | atomic_set(&priv->opreq_count, 0); |
| 2336 | INIT_WORK(&priv->opreq_task, mlx4_opreq_action); |
| 2337 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2338 | /* |
| 2339 | * Now reset the HCA before we touch the PCI capabilities or |
| 2340 | * attempt a firmware command, since a boot ROM may have left |
| 2341 | * the HCA in an undefined state. |
| 2342 | */ |
| 2343 | err = mlx4_reset(dev); |
| 2344 | if (err) { |
| 2345 | mlx4_err(dev, "Failed to reset HCA, aborting.\n"); |
| 2346 | goto err_rel_own; |
| 2347 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2350 | slave_start: |
Eugenia Emantayev | 521130d | 2012-09-05 22:50:52 +0000 | [diff] [blame] | 2351 | err = mlx4_cmd_init(dev); |
| 2352 | if (err) { |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2353 | mlx4_err(dev, "Failed to init command interface, aborting.\n"); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2354 | goto err_sriov; |
| 2355 | } |
| 2356 | |
| 2357 | /* In slave functions, the communication channel must be initialized |
| 2358 | * before posting commands. Also, init num_slaves before calling |
| 2359 | * mlx4_init_hca */ |
| 2360 | if (mlx4_is_mfunc(dev)) { |
| 2361 | if (mlx4_is_master(dev)) |
| 2362 | dev->num_slaves = MLX4_MAX_NUM_SLAVES; |
| 2363 | else { |
| 2364 | dev->num_slaves = 0; |
Jack Morgenstein | f356fcbe | 2013-01-24 01:54:17 +0000 | [diff] [blame] | 2365 | err = mlx4_multi_func_init(dev); |
| 2366 | if (err) { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2367 | mlx4_err(dev, "Failed to init slave mfunc" |
| 2368 | " interface, aborting.\n"); |
| 2369 | goto err_cmd; |
| 2370 | } |
| 2371 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | err = mlx4_init_hca(dev); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2375 | if (err) { |
| 2376 | if (err == -EACCES) { |
| 2377 | /* Not primary Physical function |
| 2378 | * Running in slave mode */ |
| 2379 | mlx4_cmd_cleanup(dev); |
| 2380 | dev->flags |= MLX4_FLAG_SLAVE; |
| 2381 | dev->flags &= ~MLX4_FLAG_MASTER; |
| 2382 | goto slave_start; |
| 2383 | } else |
| 2384 | goto err_mfunc; |
| 2385 | } |
| 2386 | |
Eyal Perry | b912b2f | 2014-01-05 17:41:08 +0200 | [diff] [blame] | 2387 | /* check if the device is functioning at its maximum possible speed. |
| 2388 | * No return code for this call, just warn the user in case of PCI |
| 2389 | * express device capabilities are under-satisfied by the bus. |
| 2390 | */ |
| 2391 | mlx4_check_pcie_caps(dev); |
| 2392 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2393 | /* In master functions, the communication channel must be initialized |
| 2394 | * after obtaining its address from fw */ |
| 2395 | if (mlx4_is_master(dev)) { |
Jack Morgenstein | f356fcbe | 2013-01-24 01:54:17 +0000 | [diff] [blame] | 2396 | err = mlx4_multi_func_init(dev); |
| 2397 | if (err) { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2398 | mlx4_err(dev, "Failed to init master mfunc" |
| 2399 | "interface, aborting.\n"); |
| 2400 | goto err_close; |
| 2401 | } |
| 2402 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2403 | |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2404 | err = mlx4_alloc_eq_table(dev); |
| 2405 | if (err) |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2406 | goto err_master_mfunc; |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2407 | |
Yevgeny Petrilin | 0b7ca5a | 2011-03-22 22:37:47 +0000 | [diff] [blame] | 2408 | priv->msix_ctl.pool_bm = 0; |
Yevgeny Petrilin | 730c41d | 2012-02-21 03:39:32 +0000 | [diff] [blame] | 2409 | mutex_init(&priv->msix_ctl.pool_lock); |
Yevgeny Petrilin | 0b7ca5a | 2011-03-22 22:37:47 +0000 | [diff] [blame] | 2410 | |
Michael S. Tsirkin | 08fb105 | 2007-08-07 16:08:28 +0300 | [diff] [blame] | 2411 | mlx4_enable_msi_x(dev); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2412 | if ((mlx4_is_mfunc(dev)) && |
| 2413 | !(dev->flags & MLX4_FLAG_MSI_X)) { |
Jack Morgenstein | f356fcbe | 2013-01-24 01:54:17 +0000 | [diff] [blame] | 2414 | err = -ENOSYS; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2415 | mlx4_err(dev, "INTx is not supported in multi-function mode." |
| 2416 | " aborting.\n"); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 2417 | goto err_free_eq; |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | if (!mlx4_is_slave(dev)) { |
| 2421 | err = mlx4_init_steering(dev); |
| 2422 | if (err) |
| 2423 | goto err_free_eq; |
| 2424 | } |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 2425 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2426 | err = mlx4_setup_hca(dev); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2427 | if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) && |
| 2428 | !mlx4_is_mfunc(dev)) { |
Michael S. Tsirkin | 08fb105 | 2007-08-07 16:08:28 +0300 | [diff] [blame] | 2429 | dev->flags &= ~MLX4_FLAG_MSI_X; |
Yevgeny Petrilin | 9858d2d | 2012-06-25 00:24:12 +0000 | [diff] [blame] | 2430 | dev->caps.num_comp_vectors = 1; |
| 2431 | dev->caps.comp_pool = 0; |
Michael S. Tsirkin | 08fb105 | 2007-08-07 16:08:28 +0300 | [diff] [blame] | 2432 | pci_disable_msix(pdev); |
| 2433 | err = mlx4_setup_hca(dev); |
| 2434 | } |
| 2435 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2436 | if (err) |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 2437 | goto err_steer; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2438 | |
Jack Morgenstein | 5a0d0a6 | 2013-11-03 10:03:23 +0200 | [diff] [blame] | 2439 | mlx4_init_quotas(dev); |
| 2440 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2441 | for (port = 1; port <= dev->caps.num_ports; port++) { |
| 2442 | err = mlx4_init_port_info(dev, port); |
| 2443 | if (err) |
| 2444 | goto err_port; |
| 2445 | } |
Yevgeny Petrilin | 2a2336f | 2008-10-22 11:44:46 -0700 | [diff] [blame] | 2446 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2447 | err = mlx4_register_device(dev); |
| 2448 | if (err) |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2449 | goto err_port; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2450 | |
Eyal Perry | b046ffe | 2013-10-15 16:55:24 +0200 | [diff] [blame] | 2451 | mlx4_request_modules(dev); |
| 2452 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 2453 | mlx4_sense_init(dev); |
| 2454 | mlx4_start_sense(dev); |
| 2455 | |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2456 | priv->pci_dev_data = pci_dev_data; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2457 | pci_set_drvdata(pdev, dev); |
| 2458 | |
| 2459 | return 0; |
| 2460 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2461 | err_port: |
Eli Cohen | b4f7726 | 2010-01-06 12:54:39 -0800 | [diff] [blame] | 2462 | for (--port; port >= 1; --port) |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2463 | mlx4_cleanup_port_info(&priv->port[port]); |
| 2464 | |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 2465 | mlx4_cleanup_counters_table(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2466 | mlx4_cleanup_qp_table(dev); |
| 2467 | mlx4_cleanup_srq_table(dev); |
| 2468 | mlx4_cleanup_cq_table(dev); |
| 2469 | mlx4_cmd_use_polling(dev); |
| 2470 | mlx4_cleanup_eq_table(dev); |
Yevgeny Petrilin | fe6f700 | 2013-07-28 18:54:21 +0300 | [diff] [blame] | 2471 | mlx4_cleanup_mcg_table(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2472 | mlx4_cleanup_mr_table(dev); |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 2473 | mlx4_cleanup_xrcd_table(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2474 | mlx4_cleanup_pd_table(dev); |
| 2475 | mlx4_cleanup_uar_table(dev); |
| 2476 | |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 2477 | err_steer: |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2478 | if (!mlx4_is_slave(dev)) |
| 2479 | mlx4_clear_steering(dev); |
Yevgeny Petrilin | b12d93d | 2011-03-22 22:38:24 +0000 | [diff] [blame] | 2480 | |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2481 | err_free_eq: |
| 2482 | mlx4_free_eq_table(dev); |
| 2483 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2484 | err_master_mfunc: |
| 2485 | if (mlx4_is_master(dev)) |
| 2486 | mlx4_multi_func_cleanup(dev); |
| 2487 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2488 | err_close: |
Michael S. Tsirkin | 08fb105 | 2007-08-07 16:08:28 +0300 | [diff] [blame] | 2489 | if (dev->flags & MLX4_FLAG_MSI_X) |
| 2490 | pci_disable_msix(pdev); |
| 2491 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2492 | mlx4_close_hca(dev); |
| 2493 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2494 | err_mfunc: |
| 2495 | if (mlx4_is_slave(dev)) |
| 2496 | mlx4_multi_func_cleanup(dev); |
| 2497 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2498 | err_cmd: |
| 2499 | mlx4_cmd_cleanup(dev); |
| 2500 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2501 | err_sriov: |
Jack Morgenstein | 681372a | 2012-05-15 10:35:01 +0000 | [diff] [blame] | 2502 | if (dev->flags & MLX4_FLAG_SRIOV) |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2503 | pci_disable_sriov(pdev); |
| 2504 | |
| 2505 | err_rel_own: |
| 2506 | if (!mlx4_is_slave(dev)) |
| 2507 | mlx4_free_ownership(dev); |
| 2508 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2509 | err_free_dev: |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2510 | kfree(priv); |
| 2511 | |
Roland Dreier | a01df0f | 2009-09-05 20:24:48 -0700 | [diff] [blame] | 2512 | err_release_regions: |
| 2513 | pci_release_regions(pdev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2514 | |
| 2515 | err_disable_pdev: |
| 2516 | pci_disable_device(pdev); |
| 2517 | pci_set_drvdata(pdev, NULL); |
| 2518 | return err; |
| 2519 | } |
| 2520 | |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 2521 | static int mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id) |
Roland Dreier | 3d73c28 | 2007-10-10 15:43:54 -0700 | [diff] [blame] | 2522 | { |
Joe Perches | 0a645e8 | 2010-07-10 07:22:46 +0000 | [diff] [blame] | 2523 | printk_once(KERN_INFO "%s", mlx4_version); |
Roland Dreier | 3d73c28 | 2007-10-10 15:43:54 -0700 | [diff] [blame] | 2524 | |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2525 | return __mlx4_init_one(pdev, id->driver_data); |
Roland Dreier | 3d73c28 | 2007-10-10 15:43:54 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | static void mlx4_remove_one(struct pci_dev *pdev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2529 | { |
| 2530 | struct mlx4_dev *dev = pci_get_drvdata(pdev); |
| 2531 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 2532 | int p; |
| 2533 | |
| 2534 | if (dev) { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2535 | /* in SRIOV it is not allowed to unload the pf's |
| 2536 | * driver while there are alive vf's */ |
| 2537 | if (mlx4_is_master(dev)) { |
| 2538 | if (mlx4_how_many_lives_vf(dev)) |
| 2539 | printk(KERN_ERR "Removing PF when there are assigned VF's !!!\n"); |
| 2540 | } |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 2541 | mlx4_stop_sense(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2542 | mlx4_unregister_device(dev); |
| 2543 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2544 | for (p = 1; p <= dev->caps.num_ports; p++) { |
| 2545 | mlx4_cleanup_port_info(&priv->port[p]); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2546 | mlx4_CLOSE_PORT(dev, p); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2547 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2548 | |
Jack Morgenstein | b892495 | 2012-05-15 10:35:02 +0000 | [diff] [blame] | 2549 | if (mlx4_is_master(dev)) |
| 2550 | mlx4_free_resource_tracker(dev, |
| 2551 | RES_TR_FREE_SLAVES_ONLY); |
| 2552 | |
Or Gerlitz | f2a3f6a | 2011-06-15 14:47:14 +0000 | [diff] [blame] | 2553 | mlx4_cleanup_counters_table(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2554 | mlx4_cleanup_qp_table(dev); |
| 2555 | mlx4_cleanup_srq_table(dev); |
| 2556 | mlx4_cleanup_cq_table(dev); |
| 2557 | mlx4_cmd_use_polling(dev); |
| 2558 | mlx4_cleanup_eq_table(dev); |
Yevgeny Petrilin | fe6f700 | 2013-07-28 18:54:21 +0300 | [diff] [blame] | 2559 | mlx4_cleanup_mcg_table(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2560 | mlx4_cleanup_mr_table(dev); |
Sean Hefty | 012a8ff | 2011-06-02 09:01:33 -0700 | [diff] [blame] | 2561 | mlx4_cleanup_xrcd_table(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2562 | mlx4_cleanup_pd_table(dev); |
| 2563 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2564 | if (mlx4_is_master(dev)) |
Jack Morgenstein | b892495 | 2012-05-15 10:35:02 +0000 | [diff] [blame] | 2565 | mlx4_free_resource_tracker(dev, |
| 2566 | RES_TR_FREE_STRUCTS_ONLY); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2567 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2568 | iounmap(priv->kar); |
| 2569 | mlx4_uar_free(dev, &priv->driver_uar); |
| 2570 | mlx4_cleanup_uar_table(dev); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2571 | if (!mlx4_is_slave(dev)) |
| 2572 | mlx4_clear_steering(dev); |
Yevgeny Petrilin | b8dd786 | 2008-12-22 07:15:03 -0800 | [diff] [blame] | 2573 | mlx4_free_eq_table(dev); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2574 | if (mlx4_is_master(dev)) |
| 2575 | mlx4_multi_func_cleanup(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2576 | mlx4_close_hca(dev); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2577 | if (mlx4_is_slave(dev)) |
| 2578 | mlx4_multi_func_cleanup(dev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2579 | mlx4_cmd_cleanup(dev); |
| 2580 | |
| 2581 | if (dev->flags & MLX4_FLAG_MSI_X) |
| 2582 | pci_disable_msix(pdev); |
Jack Morgenstein | 681372a | 2012-05-15 10:35:01 +0000 | [diff] [blame] | 2583 | if (dev->flags & MLX4_FLAG_SRIOV) { |
Roland Dreier | 84b1f15 | 2012-09-25 17:09:42 -0700 | [diff] [blame] | 2584 | mlx4_warn(dev, "Disabling SR-IOV\n"); |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2585 | pci_disable_sriov(pdev); |
| 2586 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2587 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2588 | if (!mlx4_is_slave(dev)) |
| 2589 | mlx4_free_ownership(dev); |
Jack Morgenstein | 47605df | 2012-08-03 08:40:57 +0000 | [diff] [blame] | 2590 | |
| 2591 | kfree(dev->caps.qp0_tunnel); |
| 2592 | kfree(dev->caps.qp0_proxy); |
| 2593 | kfree(dev->caps.qp1_tunnel); |
| 2594 | kfree(dev->caps.qp1_proxy); |
| 2595 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2596 | kfree(priv); |
Roland Dreier | a01df0f | 2009-09-05 20:24:48 -0700 | [diff] [blame] | 2597 | pci_release_regions(pdev); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2598 | pci_disable_device(pdev); |
| 2599 | pci_set_drvdata(pdev, NULL); |
| 2600 | } |
| 2601 | } |
| 2602 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 2603 | int mlx4_restart_one(struct pci_dev *pdev) |
| 2604 | { |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2605 | struct mlx4_dev *dev = pci_get_drvdata(pdev); |
| 2606 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 2607 | int pci_dev_data; |
| 2608 | |
| 2609 | pci_dev_data = priv->pci_dev_data; |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 2610 | mlx4_remove_one(pdev); |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2611 | return __mlx4_init_one(pdev, pci_dev_data); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 2612 | } |
| 2613 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 2614 | static DEFINE_PCI_DEVICE_TABLE(mlx4_pci_table) = { |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2615 | /* MT25408 "Hermon" SDR */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2616 | { PCI_VDEVICE(MELLANOX, 0x6340), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2617 | /* MT25408 "Hermon" DDR */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2618 | { PCI_VDEVICE(MELLANOX, 0x634a), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2619 | /* MT25408 "Hermon" QDR */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2620 | { PCI_VDEVICE(MELLANOX, 0x6354), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2621 | /* MT25408 "Hermon" DDR PCIe gen2 */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2622 | { PCI_VDEVICE(MELLANOX, 0x6732), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2623 | /* MT25408 "Hermon" QDR PCIe gen2 */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2624 | { PCI_VDEVICE(MELLANOX, 0x673c), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2625 | /* MT25408 "Hermon" EN 10GigE */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2626 | { PCI_VDEVICE(MELLANOX, 0x6368), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2627 | /* MT25408 "Hermon" EN 10GigE PCIe gen2 */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2628 | { PCI_VDEVICE(MELLANOX, 0x6750), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2629 | /* MT25458 ConnectX EN 10GBASE-T 10GigE */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2630 | { PCI_VDEVICE(MELLANOX, 0x6372), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2631 | /* MT25458 ConnectX EN 10GBASE-T+Gen2 10GigE */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2632 | { PCI_VDEVICE(MELLANOX, 0x675a), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2633 | /* MT26468 ConnectX EN 10GigE PCIe gen2*/ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2634 | { PCI_VDEVICE(MELLANOX, 0x6764), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2635 | /* MT26438 ConnectX EN 40GigE PCIe gen2 5GT/s */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2636 | { PCI_VDEVICE(MELLANOX, 0x6746), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2637 | /* MT26478 ConnectX2 40GigE PCIe gen2 */ |
Roland Dreier | ca3e57a | 2012-09-27 09:53:05 -0700 | [diff] [blame] | 2638 | { PCI_VDEVICE(MELLANOX, 0x676e), MLX4_PCI_DEV_FORCE_SENSE_PORT }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2639 | /* MT25400 Family [ConnectX-2 Virtual Function] */ |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2640 | { PCI_VDEVICE(MELLANOX, 0x1002), MLX4_PCI_DEV_IS_VF }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2641 | /* MT27500 Family [ConnectX-3] */ |
| 2642 | { PCI_VDEVICE(MELLANOX, 0x1003), 0 }, |
| 2643 | /* MT27500 Family [ConnectX-3 Virtual Function] */ |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2644 | { PCI_VDEVICE(MELLANOX, 0x1004), MLX4_PCI_DEV_IS_VF }, |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2645 | { PCI_VDEVICE(MELLANOX, 0x1005), 0 }, /* MT27510 Family */ |
| 2646 | { PCI_VDEVICE(MELLANOX, 0x1006), 0 }, /* MT27511 Family */ |
| 2647 | { PCI_VDEVICE(MELLANOX, 0x1007), 0 }, /* MT27520 Family */ |
| 2648 | { PCI_VDEVICE(MELLANOX, 0x1008), 0 }, /* MT27521 Family */ |
| 2649 | { PCI_VDEVICE(MELLANOX, 0x1009), 0 }, /* MT27530 Family */ |
| 2650 | { PCI_VDEVICE(MELLANOX, 0x100a), 0 }, /* MT27531 Family */ |
| 2651 | { PCI_VDEVICE(MELLANOX, 0x100b), 0 }, /* MT27540 Family */ |
| 2652 | { PCI_VDEVICE(MELLANOX, 0x100c), 0 }, /* MT27541 Family */ |
| 2653 | { PCI_VDEVICE(MELLANOX, 0x100d), 0 }, /* MT27550 Family */ |
| 2654 | { PCI_VDEVICE(MELLANOX, 0x100e), 0 }, /* MT27551 Family */ |
| 2655 | { PCI_VDEVICE(MELLANOX, 0x100f), 0 }, /* MT27560 Family */ |
| 2656 | { PCI_VDEVICE(MELLANOX, 0x1010), 0 }, /* MT27561 Family */ |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2657 | { 0, } |
| 2658 | }; |
| 2659 | |
| 2660 | MODULE_DEVICE_TABLE(pci, mlx4_pci_table); |
| 2661 | |
Kleber Sacilotto de Souza | 57dbf29 | 2012-07-20 09:55:43 +0000 | [diff] [blame] | 2662 | static pci_ers_result_t mlx4_pci_err_detected(struct pci_dev *pdev, |
| 2663 | pci_channel_state_t state) |
| 2664 | { |
| 2665 | mlx4_remove_one(pdev); |
| 2666 | |
| 2667 | return state == pci_channel_io_perm_failure ? |
| 2668 | PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET; |
| 2669 | } |
| 2670 | |
| 2671 | static pci_ers_result_t mlx4_pci_slot_reset(struct pci_dev *pdev) |
| 2672 | { |
Roland Dreier | 839f124 | 2012-09-27 09:23:41 -0700 | [diff] [blame] | 2673 | int ret = __mlx4_init_one(pdev, 0); |
Kleber Sacilotto de Souza | 57dbf29 | 2012-07-20 09:55:43 +0000 | [diff] [blame] | 2674 | |
| 2675 | return ret ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED; |
| 2676 | } |
| 2677 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 2678 | static const struct pci_error_handlers mlx4_err_handler = { |
Kleber Sacilotto de Souza | 57dbf29 | 2012-07-20 09:55:43 +0000 | [diff] [blame] | 2679 | .error_detected = mlx4_pci_err_detected, |
| 2680 | .slot_reset = mlx4_pci_slot_reset, |
| 2681 | }; |
| 2682 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2683 | static struct pci_driver mlx4_driver = { |
| 2684 | .name = DRV_NAME, |
| 2685 | .id_table = mlx4_pci_table, |
| 2686 | .probe = mlx4_init_one, |
Gavin Shan | 367d56f | 2014-03-04 15:35:20 +0800 | [diff] [blame] | 2687 | .shutdown = mlx4_remove_one, |
Bill Pemberton | f57e684 | 2012-12-03 09:23:15 -0500 | [diff] [blame] | 2688 | .remove = mlx4_remove_one, |
Kleber Sacilotto de Souza | 57dbf29 | 2012-07-20 09:55:43 +0000 | [diff] [blame] | 2689 | .err_handler = &mlx4_err_handler, |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2690 | }; |
| 2691 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2692 | static int __init mlx4_verify_params(void) |
| 2693 | { |
| 2694 | if ((log_num_mac < 0) || (log_num_mac > 7)) { |
Joe Perches | 0a645e8 | 2010-07-10 07:22:46 +0000 | [diff] [blame] | 2695 | pr_warning("mlx4_core: bad num_mac: %d\n", log_num_mac); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2696 | return -1; |
| 2697 | } |
| 2698 | |
Or Gerlitz | cb29688 | 2011-10-16 10:26:21 +0200 | [diff] [blame] | 2699 | if (log_num_vlan != 0) |
| 2700 | pr_warning("mlx4_core: log_num_vlan - obsolete module param, using %d\n", |
| 2701 | MLX4_LOG_NUM_VLANS); |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2702 | |
Eli Cohen | 0498628 | 2010-09-20 08:42:38 +0200 | [diff] [blame] | 2703 | if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 7)) { |
Joe Perches | 0a645e8 | 2010-07-10 07:22:46 +0000 | [diff] [blame] | 2704 | pr_warning("mlx4_core: bad log_mtts_per_seg: %d\n", log_mtts_per_seg); |
Eli Cohen | ab6bf42 | 2009-05-27 14:38:34 -0700 | [diff] [blame] | 2705 | return -1; |
| 2706 | } |
| 2707 | |
Jack Morgenstein | ab9c17a | 2011-12-13 04:18:30 +0000 | [diff] [blame] | 2708 | /* Check if module param for ports type has legal combination */ |
| 2709 | if (port_type_array[0] == false && port_type_array[1] == true) { |
| 2710 | printk(KERN_WARNING "Module parameter configuration ETH/IB is not supported. Switching to default configuration IB/IB\n"); |
| 2711 | port_type_array[0] = true; |
| 2712 | } |
| 2713 | |
Jack Morgenstein | 3c439b5 | 2012-12-06 17:12:00 +0000 | [diff] [blame] | 2714 | if (mlx4_log_num_mgm_entry_size != -1 && |
| 2715 | (mlx4_log_num_mgm_entry_size < MLX4_MIN_MGM_LOG_ENTRY_SIZE || |
| 2716 | mlx4_log_num_mgm_entry_size > MLX4_MAX_MGM_LOG_ENTRY_SIZE)) { |
| 2717 | pr_warning("mlx4_core: mlx4_log_num_mgm_entry_size (%d) not " |
| 2718 | "in legal range (-1 or %d..%d)\n", |
| 2719 | mlx4_log_num_mgm_entry_size, |
| 2720 | MLX4_MIN_MGM_LOG_ENTRY_SIZE, |
| 2721 | MLX4_MAX_MGM_LOG_ENTRY_SIZE); |
| 2722 | return -1; |
| 2723 | } |
| 2724 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2725 | return 0; |
| 2726 | } |
| 2727 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2728 | static int __init mlx4_init(void) |
| 2729 | { |
| 2730 | int ret; |
| 2731 | |
Yevgeny Petrilin | 7ff93f8 | 2008-10-22 15:38:42 -0700 | [diff] [blame] | 2732 | if (mlx4_verify_params()) |
| 2733 | return -EINVAL; |
| 2734 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 2735 | mlx4_catas_init(); |
| 2736 | |
| 2737 | mlx4_wq = create_singlethread_workqueue("mlx4"); |
| 2738 | if (!mlx4_wq) |
| 2739 | return -ENOMEM; |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 2740 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2741 | ret = pci_register_driver(&mlx4_driver); |
Wei Yang | 1b85ee0 | 2013-12-03 10:04:10 +0800 | [diff] [blame] | 2742 | if (ret < 0) |
| 2743 | destroy_workqueue(mlx4_wq); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2744 | return ret < 0 ? ret : 0; |
| 2745 | } |
| 2746 | |
| 2747 | static void __exit mlx4_cleanup(void) |
| 2748 | { |
| 2749 | pci_unregister_driver(&mlx4_driver); |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 2750 | destroy_workqueue(mlx4_wq); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | module_init(mlx4_init); |
| 2754 | module_exit(mlx4_cleanup); |