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