blob: f8125a82c0cb3ff6c09aa0a1948c785b3f286120 [file] [log] [blame]
Roland Dreier225c7b12007-05-08 18:00:38 -07001/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
Jack Morgenstein51a379d2008-07-25 10:32:52 -07004 * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
Roland Dreier225c7b12007-05-08 18:00:38 -07005 * 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 Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Eli Cohenc1b43dc2011-03-22 22:38:41 +000042#include <linux/io-mapping.h>
Jack Morgensteinab9c17a2011-12-13 04:18:30 +000043#include <linux/delay.h>
Yuval Mintz90b1ebe2012-07-01 03:18:51 +000044#include <linux/netdevice.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070045
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
53MODULE_AUTHOR("Roland Dreier");
54MODULE_DESCRIPTION("Mellanox ConnectX HCA low-level driver");
55MODULE_LICENSE("Dual BSD/GPL");
56MODULE_VERSION(DRV_VERSION);
57
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -070058struct workqueue_struct *mlx4_wq;
59
Roland Dreier225c7b12007-05-08 18:00:38 -070060#ifdef CONFIG_MLX4_DEBUG
61
62int mlx4_debug_level = 0;
63module_param_named(debug_level, mlx4_debug_level, int, 0644);
64MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
65
66#endif /* CONFIG_MLX4_DEBUG */
67
68#ifdef CONFIG_PCI_MSI
69
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +030070static int msi_x = 1;
Roland Dreier225c7b12007-05-08 18:00:38 -070071module_param(msi_x, int, 0444);
72MODULE_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 Morgensteinab9c17a2011-12-13 04:18:30 +000080static int num_vfs;
81module_param(num_vfs, int, 0444);
82MODULE_PARM_DESC(num_vfs, "enable #num_vfs functions if num_vfs > 0");
83
84static int probe_vf;
85module_param(probe_vf, int, 0644);
86MODULE_PARM_DESC(probe_vf, "number of vfs to probe by pf driver (num_vfs > 0)");
87
Eugenia Emantayev0ec2c0f2011-12-13 04:16:02 +000088int mlx4_log_num_mgm_entry_size = 10;
89module_param_named(log_num_mgm_entry_size,
90 mlx4_log_num_mgm_entry_size, int, 0444);
91MODULE_PARM_DESC(log_num_mgm_entry_size, "log mgm size, that defines the num"
92 " of qp per mcg, for example:"
93 " 10 gives 248.range: 9<="
94 " log_num_mgm_entry_size <= 12");
95
Jack Morgensteinab9c17a2011-12-13 04:18:30 +000096#define MLX4_VF (1 << 0)
97
98#define HCA_GLOBAL_CAP_MASK 0
99#define PF_CONTEXT_BEHAVIOUR_MASK 0
100
Roland Dreierf33afc22008-02-04 20:20:44 -0800101static char mlx4_version[] __devinitdata =
Roland Dreier225c7b12007-05-08 18:00:38 -0700102 DRV_NAME ": Mellanox ConnectX core driver v"
103 DRV_VERSION " (" DRV_RELDATE ")\n";
104
105static struct mlx4_profile default_profile = {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000106 .num_qp = 1 << 18,
Roland Dreier225c7b12007-05-08 18:00:38 -0700107 .num_srq = 1 << 16,
Jack Morgensteinc9f2ba52007-07-17 13:11:43 +0300108 .rdmarc_per_qp = 1 << 4,
Roland Dreier225c7b12007-05-08 18:00:38 -0700109 .num_cq = 1 << 16,
110 .num_mcg = 1 << 13,
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000111 .num_mpt = 1 << 19,
Marcel Apfelbaum9fd7a1e2012-01-19 09:45:31 +0000112 .num_mtt = 1 << 20, /* It is really num mtt segements */
Roland Dreier225c7b12007-05-08 18:00:38 -0700113};
114
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000115static int log_num_mac = 7;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700116module_param_named(log_num_mac, log_num_mac, int, 0444);
117MODULE_PARM_DESC(log_num_mac, "Log2 max number of MACs per ETH port (1-7)");
118
119static int log_num_vlan;
120module_param_named(log_num_vlan, log_num_vlan, int, 0444);
121MODULE_PARM_DESC(log_num_vlan, "Log2 max number of VLANs per ETH port (0-7)");
Or Gerlitzcb296882011-10-16 10:26:21 +0200122/* Log2 max number of VLANs per ETH port (0-7) */
123#define MLX4_LOG_NUM_VLANS 7
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700124
Rusty Russelleb939922011-12-19 14:08:01 +0000125static bool use_prio;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700126module_param_named(use_prio, use_prio, bool, 0444);
127MODULE_PARM_DESC(use_prio, "Enable steering by VLAN priority on ETH ports "
128 "(0/1, default 0)");
129
Marcel Apfelbaum2b8fb282011-12-13 04:16:56 +0000130int log_mtts_per_seg = ilog2(MLX4_MTT_ENTRY_PER_SEG);
Eli Cohenab6bf422009-05-27 14:38:34 -0700131module_param_named(log_mtts_per_seg, log_mtts_per_seg, int, 0444);
Eli Cohen04986282010-09-20 08:42:38 +0200132MODULE_PARM_DESC(log_mtts_per_seg, "Log2 number of MTT entries per segment (1-7)");
Eli Cohenab6bf422009-05-27 14:38:34 -0700133
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000134static int port_type_array[2] = {MLX4_PORT_TYPE_NONE, MLX4_PORT_TYPE_NONE};
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000135static int arr_argc = 2;
136module_param_array(port_type_array, int, &arr_argc, 0444);
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000137MODULE_PARM_DESC(port_type_array, "Array of port types: HW_DEFAULT (0) is default "
138 "1 for IB, 2 for Ethernet");
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000139
140struct mlx4_port_config {
141 struct list_head list;
142 enum mlx4_port_type port_type[MLX4_MAX_PORTS + 1];
143 struct pci_dev *pdev;
144};
145
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700146int mlx4_check_port_params(struct mlx4_dev *dev,
147 enum mlx4_port_type *port_type)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700148{
149 int i;
150
151 for (i = 0; i < dev->caps.num_ports - 1; i++) {
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700152 if (port_type[i] != port_type[i + 1]) {
153 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) {
154 mlx4_err(dev, "Only same port types supported "
155 "on this HCA, aborting.\n");
156 return -EINVAL;
157 }
158 if (port_type[i] == MLX4_PORT_TYPE_ETH &&
159 port_type[i + 1] == MLX4_PORT_TYPE_IB)
160 return -EINVAL;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700161 }
162 }
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700163
164 for (i = 0; i < dev->caps.num_ports; i++) {
165 if (!(port_type[i] & dev->caps.supported_type[i+1])) {
166 mlx4_err(dev, "Requested port type for port %d is not "
167 "supported on this HCA\n", i + 1);
168 return -EINVAL;
169 }
170 }
171 return 0;
172}
173
174static void mlx4_set_port_mask(struct mlx4_dev *dev)
175{
176 int i;
177
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700178 for (i = 1; i <= dev->caps.num_ports; ++i)
Jack Morgenstein65dab252011-12-13 04:10:41 +0000179 dev->caps.port_mask[i] = dev->caps.port_type[i];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700180}
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +0000181
Roland Dreier3d73c282007-10-10 15:43:54 -0700182static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
Roland Dreier225c7b12007-05-08 18:00:38 -0700183{
184 int err;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700185 int i;
Roland Dreier225c7b12007-05-08 18:00:38 -0700186
187 err = mlx4_QUERY_DEV_CAP(dev, dev_cap);
188 if (err) {
189 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
190 return err;
191 }
192
193 if (dev_cap->min_page_sz > PAGE_SIZE) {
194 mlx4_err(dev, "HCA minimum page size of %d bigger than "
195 "kernel PAGE_SIZE of %ld, aborting.\n",
196 dev_cap->min_page_sz, PAGE_SIZE);
197 return -ENODEV;
198 }
199 if (dev_cap->num_ports > MLX4_MAX_PORTS) {
200 mlx4_err(dev, "HCA has %d ports, but we only support %d, "
201 "aborting.\n",
202 dev_cap->num_ports, MLX4_MAX_PORTS);
203 return -ENODEV;
204 }
205
206 if (dev_cap->uar_size > pci_resource_len(dev->pdev, 2)) {
207 mlx4_err(dev, "HCA reported UAR size of 0x%x bigger than "
208 "PCI resource 2 size of 0x%llx, aborting.\n",
209 dev_cap->uar_size,
210 (unsigned long long) pci_resource_len(dev->pdev, 2));
211 return -ENODEV;
212 }
213
214 dev->caps.num_ports = dev_cap->num_ports;
Marcel Apfelbaum3fc929e2012-05-30 09:14:51 +0000215 dev->phys_caps.num_phys_eqs = MLX4_MAX_EQ_NUM;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700216 for (i = 1; i <= dev->caps.num_ports; ++i) {
217 dev->caps.vl_cap[i] = dev_cap->max_vl[i];
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -0700218 dev->caps.ib_mtu_cap[i] = dev_cap->ib_mtu[i];
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700219 dev->caps.gid_table_len[i] = dev_cap->max_gids[i];
220 dev->caps.pkey_table_len[i] = dev_cap->max_pkeys[i];
221 dev->caps.port_width_cap[i] = dev_cap->max_port_width[i];
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -0700222 dev->caps.eth_mtu_cap[i] = dev_cap->eth_mtu[i];
223 dev->caps.def_mac[i] = dev_cap->def_mac[i];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700224 dev->caps.supported_type[i] = dev_cap->supported_port_types[i];
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000225 dev->caps.suggested_type[i] = dev_cap->suggested_type[i];
226 dev->caps.default_sense[i] = dev_cap->default_sense[i];
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000227 dev->caps.trans_type[i] = dev_cap->trans_type[i];
228 dev->caps.vendor_oui[i] = dev_cap->vendor_oui[i];
229 dev->caps.wavelength[i] = dev_cap->wavelength[i];
230 dev->caps.trans_code[i] = dev_cap->trans_code[i];
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700231 }
232
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000233 dev->caps.uar_page_size = PAGE_SIZE;
Roland Dreier225c7b12007-05-08 18:00:38 -0700234 dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE;
Roland Dreier225c7b12007-05-08 18:00:38 -0700235 dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay;
236 dev->caps.bf_reg_size = dev_cap->bf_reg_size;
237 dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page;
238 dev->caps.max_sq_sg = dev_cap->max_sq_sg;
239 dev->caps.max_rq_sg = dev_cap->max_rq_sg;
240 dev->caps.max_wqes = dev_cap->max_qp_sz;
241 dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp;
Roland Dreier225c7b12007-05-08 18:00:38 -0700242 dev->caps.max_srq_wqes = dev_cap->max_srq_sz;
243 dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1;
244 dev->caps.reserved_srqs = dev_cap->reserved_srqs;
245 dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz;
246 dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz;
Roland Dreier225c7b12007-05-08 18:00:38 -0700247 /*
248 * Subtract 1 from the limit because we need to allocate a
249 * spare CQE so the HCA HW can tell the difference between an
250 * empty CQ and a full CQ.
251 */
252 dev->caps.max_cqes = dev_cap->max_cq_sz - 1;
253 dev->caps.reserved_cqs = dev_cap->reserved_cqs;
254 dev->caps.reserved_eqs = dev_cap->reserved_eqs;
Marcel Apfelbaum2b8fb282011-12-13 04:16:56 +0000255 dev->caps.reserved_mtts = dev_cap->reserved_mtts;
Roland Dreier225c7b12007-05-08 18:00:38 -0700256 dev->caps.reserved_mrws = dev_cap->reserved_mrws;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000257
258 /* The first 128 UARs are used for EQ doorbells */
259 dev->caps.reserved_uars = max_t(int, 128, dev_cap->reserved_uars);
Roland Dreier225c7b12007-05-08 18:00:38 -0700260 dev->caps.reserved_pds = dev_cap->reserved_pds;
Sean Hefty012a8ff2011-06-02 09:01:33 -0700261 dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
262 dev_cap->reserved_xrcds : 0;
263 dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
264 dev_cap->max_xrcds : 0;
Marcel Apfelbaum2b8fb282011-12-13 04:16:56 +0000265 dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz;
266
Dotan Barak149983af2007-06-26 15:55:28 +0300267 dev->caps.max_msg_sz = dev_cap->max_msg_sz;
Roland Dreier225c7b12007-05-08 18:00:38 -0700268 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
269 dev->caps.flags = dev_cap->flags;
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300270 dev->caps.flags2 = dev_cap->flags2;
Roland Dreier95d04f02008-07-23 08:12:26 -0700271 dev->caps.bmme_flags = dev_cap->bmme_flags;
272 dev->caps.reserved_lkey = dev_cap->reserved_lkey;
Roland Dreier225c7b12007-05-08 18:00:38 -0700273 dev->caps.stat_rate_support = dev_cap->stat_rate_support;
Eli Cohenb832be12008-04-16 21:09:27 -0700274 dev->caps.max_gso_sz = dev_cap->max_gso_sz;
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300275 dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz;
Roland Dreier225c7b12007-05-08 18:00:38 -0700276
Hadar Hen Zionc96d97f2012-07-05 04:03:44 +0000277 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER &&
278 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) {
279 dev->caps.steering_mode = MLX4_STEERING_MODE_B0;
280 } else {
281 dev->caps.steering_mode = MLX4_STEERING_MODE_A0;
282
283 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER ||
284 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER)
285 mlx4_warn(dev, "Must have UC_STEER and MC_STEER flags "
286 "set to use B0 steering. Falling back to A0 steering mode.\n");
287 }
288 mlx4_dbg(dev, "Steering mode is: %s\n",
289 mlx4_steering_mode_str(dev->caps.steering_mode));
290 dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev);
291
Yevgeny Petrilin58a60162011-12-19 04:00:26 +0000292 /* Sense port always allowed on supported devices for ConnectX1 and 2 */
293 if (dev->pdev->device != 0x1003)
294 dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT;
295
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700296 dev->caps.log_num_macs = log_num_mac;
Or Gerlitzcb296882011-10-16 10:26:21 +0200297 dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700298 dev->caps.log_num_prios = use_prio ? 3 : 0;
299
300 for (i = 1; i <= dev->caps.num_ports; ++i) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000301 dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE;
302 if (dev->caps.supported_type[i]) {
303 /* if only ETH is supported - assign ETH */
304 if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH)
305 dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH;
306 /* if only IB is supported,
307 * assign IB only if SRIOV is off*/
308 else if (dev->caps.supported_type[i] ==
309 MLX4_PORT_TYPE_IB) {
310 if (dev->flags & MLX4_FLAG_SRIOV)
311 dev->caps.port_type[i] =
312 MLX4_PORT_TYPE_NONE;
313 else
314 dev->caps.port_type[i] =
315 MLX4_PORT_TYPE_IB;
316 /* if IB and ETH are supported,
317 * first of all check if SRIOV is on */
318 } else if (dev->flags & MLX4_FLAG_SRIOV)
319 dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000320 else {
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000321 /* In non-SRIOV mode, we set the port type
322 * according to user selection of port type,
323 * if usere selected none, take the FW hint */
324 if (port_type_array[i-1] == MLX4_PORT_TYPE_NONE)
325 dev->caps.port_type[i] = dev->caps.suggested_type[i] ?
326 MLX4_PORT_TYPE_ETH : MLX4_PORT_TYPE_IB;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000327 else
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000328 dev->caps.port_type[i] = port_type_array[i-1];
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000329 }
330 }
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000331 /*
332 * Link sensing is allowed on the port if 3 conditions are true:
333 * 1. Both protocols are supported on the port.
334 * 2. Different types are supported on the port
335 * 3. FW declared that it supports link sensing
336 */
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700337 mlx4_priv(dev)->sense.sense_allowed[i] =
Yevgeny Petrilin58a60162011-12-19 04:00:26 +0000338 ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) &&
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000339 (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
Yevgeny Petrilin58a60162011-12-19 04:00:26 +0000340 (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT));
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700341
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000342 /*
343 * If "default_sense" bit is set, we move the port to "AUTO" mode
344 * and perform sense_port FW command to try and set the correct
345 * port type from beginning
346 */
Yevgeny Petrilin46c46742011-12-29 07:42:34 +0000347 if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) {
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000348 enum mlx4_port_type sensed_port = MLX4_PORT_TYPE_NONE;
349 dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO;
350 mlx4_SENSE_PORT(dev, i, &sensed_port);
351 if (sensed_port != MLX4_PORT_TYPE_NONE)
352 dev->caps.port_type[i] = sensed_port;
353 } else {
354 dev->caps.possible_type[i] = dev->caps.port_type[i];
355 }
356
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700357 if (dev->caps.log_num_macs > dev_cap->log_max_macs[i]) {
358 dev->caps.log_num_macs = dev_cap->log_max_macs[i];
359 mlx4_warn(dev, "Requested number of MACs is too much "
360 "for port %d, reducing to %d.\n",
361 i, 1 << dev->caps.log_num_macs);
362 }
363 if (dev->caps.log_num_vlans > dev_cap->log_max_vlans[i]) {
364 dev->caps.log_num_vlans = dev_cap->log_max_vlans[i];
365 mlx4_warn(dev, "Requested number of VLANs is too much "
366 "for port %d, reducing to %d.\n",
367 i, 1 << dev->caps.log_num_vlans);
368 }
369 }
370
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +0000371 dev->caps.max_counters = 1 << ilog2(dev_cap->max_counters);
372
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700373 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps;
374 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] =
375 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] =
376 (1 << dev->caps.log_num_macs) *
377 (1 << dev->caps.log_num_vlans) *
378 (1 << dev->caps.log_num_prios) *
379 dev->caps.num_ports;
380 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH;
381
382 dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] +
383 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] +
384 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] +
385 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH];
386
Roland Dreier225c7b12007-05-08 18:00:38 -0700387 return 0;
388}
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000389/*The function checks if there are live vf, return the num of them*/
390static int mlx4_how_many_lives_vf(struct mlx4_dev *dev)
391{
392 struct mlx4_priv *priv = mlx4_priv(dev);
393 struct mlx4_slave_state *s_state;
394 int i;
395 int ret = 0;
396
397 for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) {
398 s_state = &priv->mfunc.master.slave_state[i];
399 if (s_state->active && s_state->last_cmd !=
400 MLX4_COMM_CMD_RESET) {
401 mlx4_warn(dev, "%s: slave: %d is still active\n",
402 __func__, i);
403 ret++;
404 }
405 }
406 return ret;
407}
408
Roland Dreiere10903b2012-02-26 01:48:12 -0800409int mlx4_is_slave_active(struct mlx4_dev *dev, int slave)
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000410{
411 struct mlx4_priv *priv = mlx4_priv(dev);
412 struct mlx4_slave_state *s_slave;
413
414 if (!mlx4_is_master(dev))
415 return 0;
416
417 s_slave = &priv->mfunc.master.slave_state[slave];
418 return !!s_slave->active;
419}
420EXPORT_SYMBOL(mlx4_is_slave_active);
421
422static int mlx4_slave_cap(struct mlx4_dev *dev)
423{
424 int err;
425 u32 page_size;
426 struct mlx4_dev_cap dev_cap;
427 struct mlx4_func_cap func_cap;
428 struct mlx4_init_hca_param hca_param;
429 int i;
430
431 memset(&hca_param, 0, sizeof(hca_param));
432 err = mlx4_QUERY_HCA(dev, &hca_param);
433 if (err) {
434 mlx4_err(dev, "QUERY_HCA command failed, aborting.\n");
435 return err;
436 }
437
438 /*fail if the hca has an unknown capability */
439 if ((hca_param.global_caps | HCA_GLOBAL_CAP_MASK) !=
440 HCA_GLOBAL_CAP_MASK) {
441 mlx4_err(dev, "Unknown hca global capabilities\n");
442 return -ENOSYS;
443 }
444
445 mlx4_log_num_mgm_entry_size = hca_param.log_mc_entry_sz;
446
447 memset(&dev_cap, 0, sizeof(dev_cap));
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +0000448 dev->caps.max_qp_dest_rdma = 1 << hca_param.log_rd_per_qp;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000449 err = mlx4_dev_cap(dev, &dev_cap);
450 if (err) {
451 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
452 return err;
453 }
454
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +0000455 err = mlx4_QUERY_FW(dev);
456 if (err)
457 mlx4_err(dev, "QUERY_FW command failed: could not get FW version.\n");
458
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000459 page_size = ~dev->caps.page_size_cap + 1;
460 mlx4_warn(dev, "HCA minimum page size:%d\n", page_size);
461 if (page_size > PAGE_SIZE) {
462 mlx4_err(dev, "HCA minimum page size of %d bigger than "
463 "kernel PAGE_SIZE of %ld, aborting.\n",
464 page_size, PAGE_SIZE);
465 return -ENODEV;
466 }
467
468 /* slave gets uar page size from QUERY_HCA fw command */
469 dev->caps.uar_page_size = 1 << (hca_param.uar_page_sz + 12);
470
471 /* TODO: relax this assumption */
472 if (dev->caps.uar_page_size != PAGE_SIZE) {
473 mlx4_err(dev, "UAR size:%d != kernel PAGE_SIZE of %ld\n",
474 dev->caps.uar_page_size, PAGE_SIZE);
475 return -ENODEV;
476 }
477
478 memset(&func_cap, 0, sizeof(func_cap));
479 err = mlx4_QUERY_FUNC_CAP(dev, &func_cap);
480 if (err) {
481 mlx4_err(dev, "QUERY_FUNC_CAP command failed, aborting.\n");
482 return err;
483 }
484
485 if ((func_cap.pf_context_behaviour | PF_CONTEXT_BEHAVIOUR_MASK) !=
486 PF_CONTEXT_BEHAVIOUR_MASK) {
487 mlx4_err(dev, "Unknown pf context behaviour\n");
488 return -ENOSYS;
489 }
490
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000491 dev->caps.num_ports = func_cap.num_ports;
492 dev->caps.num_qps = func_cap.qp_quota;
493 dev->caps.num_srqs = func_cap.srq_quota;
494 dev->caps.num_cqs = func_cap.cq_quota;
495 dev->caps.num_eqs = func_cap.max_eq;
496 dev->caps.reserved_eqs = func_cap.reserved_eq;
497 dev->caps.num_mpts = func_cap.mpt_quota;
498 dev->caps.num_mtts = func_cap.mtt_quota;
499 dev->caps.num_pds = MLX4_NUM_PDS;
500 dev->caps.num_mgms = 0;
501 dev->caps.num_amgms = 0;
502
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000503 if (dev->caps.num_ports > MLX4_MAX_PORTS) {
504 mlx4_err(dev, "HCA has %d ports, but we only support %d, "
505 "aborting.\n", dev->caps.num_ports, MLX4_MAX_PORTS);
506 return -ENODEV;
507 }
508
Jack Morgenstein6230bb22012-05-30 09:14:54 +0000509 for (i = 1; i <= dev->caps.num_ports; ++i)
510 dev->caps.port_mask[i] = dev->caps.port_type[i];
511
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000512 if (dev->caps.uar_page_size * (dev->caps.num_uars -
513 dev->caps.reserved_uars) >
514 pci_resource_len(dev->pdev, 2)) {
515 mlx4_err(dev, "HCA reported UAR region size of 0x%x bigger than "
516 "PCI resource 2 size of 0x%llx, aborting.\n",
517 dev->caps.uar_page_size * dev->caps.num_uars,
518 (unsigned long long) pci_resource_len(dev->pdev, 2));
519 return -ENODEV;
520 }
521
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000522 return 0;
523}
Roland Dreier225c7b12007-05-08 18:00:38 -0700524
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700525/*
526 * Change the port configuration of the device.
527 * Every user of this function must hold the port mutex.
528 */
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700529int mlx4_change_port_types(struct mlx4_dev *dev,
530 enum mlx4_port_type *port_types)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700531{
532 int err = 0;
533 int change = 0;
534 int port;
535
536 for (port = 0; port < dev->caps.num_ports; port++) {
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700537 /* Change the port type only if the new type is different
538 * from the current, and not set to Auto */
Yevgeny Petrilin3d8f9302012-02-21 03:41:07 +0000539 if (port_types[port] != dev->caps.port_type[port + 1])
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700540 change = 1;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700541 }
542 if (change) {
543 mlx4_unregister_device(dev);
544 for (port = 1; port <= dev->caps.num_ports; port++) {
545 mlx4_CLOSE_PORT(dev, port);
Yevgeny Petrilin1e0f03d2012-02-23 07:04:35 +0000546 dev->caps.port_type[port] = port_types[port - 1];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700547 err = mlx4_SET_PORT(dev, port);
548 if (err) {
549 mlx4_err(dev, "Failed to set port %d, "
550 "aborting\n", port);
551 goto out;
552 }
553 }
554 mlx4_set_port_mask(dev);
555 err = mlx4_register_device(dev);
556 }
557
558out:
559 return err;
560}
561
562static ssize_t show_port_type(struct device *dev,
563 struct device_attribute *attr,
564 char *buf)
565{
566 struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
567 port_attr);
568 struct mlx4_dev *mdev = info->dev;
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700569 char type[8];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700570
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700571 sprintf(type, "%s",
572 (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_IB) ?
573 "ib" : "eth");
574 if (mdev->caps.possible_type[info->port] == MLX4_PORT_TYPE_AUTO)
575 sprintf(buf, "auto (%s)\n", type);
576 else
577 sprintf(buf, "%s\n", type);
578
579 return strlen(buf);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700580}
581
582static ssize_t set_port_type(struct device *dev,
583 struct device_attribute *attr,
584 const char *buf, size_t count)
585{
586 struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
587 port_attr);
588 struct mlx4_dev *mdev = info->dev;
589 struct mlx4_priv *priv = mlx4_priv(mdev);
590 enum mlx4_port_type types[MLX4_MAX_PORTS];
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700591 enum mlx4_port_type new_types[MLX4_MAX_PORTS];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700592 int i;
593 int err = 0;
594
595 if (!strcmp(buf, "ib\n"))
596 info->tmp_type = MLX4_PORT_TYPE_IB;
597 else if (!strcmp(buf, "eth\n"))
598 info->tmp_type = MLX4_PORT_TYPE_ETH;
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700599 else if (!strcmp(buf, "auto\n"))
600 info->tmp_type = MLX4_PORT_TYPE_AUTO;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700601 else {
602 mlx4_err(mdev, "%s is not supported port type\n", buf);
603 return -EINVAL;
604 }
605
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700606 mlx4_stop_sense(mdev);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700607 mutex_lock(&priv->port_mutex);
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700608 /* Possible type is always the one that was delivered */
609 mdev->caps.possible_type[info->port] = info->tmp_type;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700610
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700611 for (i = 0; i < mdev->caps.num_ports; i++) {
612 types[i] = priv->port[i+1].tmp_type ? priv->port[i+1].tmp_type :
613 mdev->caps.possible_type[i+1];
614 if (types[i] == MLX4_PORT_TYPE_AUTO)
615 types[i] = mdev->caps.port_type[i+1];
616 }
617
Yevgeny Petrilin58a60162011-12-19 04:00:26 +0000618 if (!(mdev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
619 !(mdev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)) {
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700620 for (i = 1; i <= mdev->caps.num_ports; i++) {
621 if (mdev->caps.possible_type[i] == MLX4_PORT_TYPE_AUTO) {
622 mdev->caps.possible_type[i] = mdev->caps.port_type[i];
623 err = -EINVAL;
624 }
625 }
626 }
627 if (err) {
628 mlx4_err(mdev, "Auto sensing is not supported on this HCA. "
629 "Set only 'eth' or 'ib' for both ports "
630 "(should be the same)\n");
631 goto out;
632 }
633
634 mlx4_do_sense_ports(mdev, new_types, types);
635
636 err = mlx4_check_port_params(mdev, new_types);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700637 if (err)
638 goto out;
639
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700640 /* We are about to apply the changes after the configuration
641 * was verified, no need to remember the temporary types
642 * any more */
643 for (i = 0; i < mdev->caps.num_ports; i++)
644 priv->port[i + 1].tmp_type = 0;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700645
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700646 err = mlx4_change_port_types(mdev, new_types);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700647
648out:
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700649 mlx4_start_sense(mdev);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700650 mutex_unlock(&priv->port_mutex);
651 return err ? err : count;
652}
653
Or Gerlitz096335b2012-01-11 19:02:17 +0200654enum ibta_mtu {
655 IB_MTU_256 = 1,
656 IB_MTU_512 = 2,
657 IB_MTU_1024 = 3,
658 IB_MTU_2048 = 4,
659 IB_MTU_4096 = 5
660};
661
662static inline int int_to_ibta_mtu(int mtu)
663{
664 switch (mtu) {
665 case 256: return IB_MTU_256;
666 case 512: return IB_MTU_512;
667 case 1024: return IB_MTU_1024;
668 case 2048: return IB_MTU_2048;
669 case 4096: return IB_MTU_4096;
670 default: return -1;
671 }
672}
673
674static inline int ibta_mtu_to_int(enum ibta_mtu mtu)
675{
676 switch (mtu) {
677 case IB_MTU_256: return 256;
678 case IB_MTU_512: return 512;
679 case IB_MTU_1024: return 1024;
680 case IB_MTU_2048: return 2048;
681 case IB_MTU_4096: return 4096;
682 default: return -1;
683 }
684}
685
686static ssize_t show_port_ib_mtu(struct device *dev,
687 struct device_attribute *attr,
688 char *buf)
689{
690 struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
691 port_mtu_attr);
692 struct mlx4_dev *mdev = info->dev;
693
694 if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH)
695 mlx4_warn(mdev, "port level mtu is only used for IB ports\n");
696
697 sprintf(buf, "%d\n",
698 ibta_mtu_to_int(mdev->caps.port_ib_mtu[info->port]));
699 return strlen(buf);
700}
701
702static ssize_t set_port_ib_mtu(struct device *dev,
703 struct device_attribute *attr,
704 const char *buf, size_t count)
705{
706 struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
707 port_mtu_attr);
708 struct mlx4_dev *mdev = info->dev;
709 struct mlx4_priv *priv = mlx4_priv(mdev);
710 int err, port, mtu, ibta_mtu = -1;
711
712 if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH) {
713 mlx4_warn(mdev, "port level mtu is only used for IB ports\n");
714 return -EINVAL;
715 }
716
717 err = sscanf(buf, "%d", &mtu);
718 if (err > 0)
719 ibta_mtu = int_to_ibta_mtu(mtu);
720
721 if (err <= 0 || ibta_mtu < 0) {
722 mlx4_err(mdev, "%s is invalid IBTA mtu\n", buf);
723 return -EINVAL;
724 }
725
726 mdev->caps.port_ib_mtu[info->port] = ibta_mtu;
727
728 mlx4_stop_sense(mdev);
729 mutex_lock(&priv->port_mutex);
730 mlx4_unregister_device(mdev);
731 for (port = 1; port <= mdev->caps.num_ports; port++) {
732 mlx4_CLOSE_PORT(mdev, port);
733 err = mlx4_SET_PORT(mdev, port);
734 if (err) {
735 mlx4_err(mdev, "Failed to set port %d, "
736 "aborting\n", port);
737 goto err_set_port;
738 }
739 }
740 err = mlx4_register_device(mdev);
741err_set_port:
742 mutex_unlock(&priv->port_mutex);
743 mlx4_start_sense(mdev);
744 return err ? err : count;
745}
746
Roland Dreiere8f9b2e2008-02-04 20:20:41 -0800747static int mlx4_load_fw(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -0700748{
749 struct mlx4_priv *priv = mlx4_priv(dev);
750 int err;
751
752 priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300753 GFP_HIGHUSER | __GFP_NOWARN, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700754 if (!priv->fw.fw_icm) {
755 mlx4_err(dev, "Couldn't allocate FW area, aborting.\n");
756 return -ENOMEM;
757 }
758
759 err = mlx4_MAP_FA(dev, priv->fw.fw_icm);
760 if (err) {
761 mlx4_err(dev, "MAP_FA command failed, aborting.\n");
762 goto err_free;
763 }
764
765 err = mlx4_RUN_FW(dev);
766 if (err) {
767 mlx4_err(dev, "RUN_FW command failed, aborting.\n");
768 goto err_unmap_fa;
769 }
770
771 return 0;
772
773err_unmap_fa:
774 mlx4_UNMAP_FA(dev);
775
776err_free:
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300777 mlx4_free_icm(dev, priv->fw.fw_icm, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700778 return err;
779}
780
Roland Dreiere8f9b2e2008-02-04 20:20:41 -0800781static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
782 int cmpt_entry_sz)
Roland Dreier225c7b12007-05-08 18:00:38 -0700783{
784 struct mlx4_priv *priv = mlx4_priv(dev);
785 int err;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000786 int num_eqs;
Roland Dreier225c7b12007-05-08 18:00:38 -0700787
788 err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table,
789 cmpt_base +
790 ((u64) (MLX4_CMPT_TYPE_QP *
791 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
792 cmpt_entry_sz, dev->caps.num_qps,
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700793 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
794 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700795 if (err)
796 goto err;
797
798 err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table,
799 cmpt_base +
800 ((u64) (MLX4_CMPT_TYPE_SRQ *
801 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
802 cmpt_entry_sz, dev->caps.num_srqs,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300803 dev->caps.reserved_srqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700804 if (err)
805 goto err_qp;
806
807 err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table,
808 cmpt_base +
809 ((u64) (MLX4_CMPT_TYPE_CQ *
810 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
811 cmpt_entry_sz, dev->caps.num_cqs,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300812 dev->caps.reserved_cqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700813 if (err)
814 goto err_srq;
815
Marcel Apfelbaum3fc929e2012-05-30 09:14:51 +0000816 num_eqs = (mlx4_is_master(dev)) ? dev->phys_caps.num_phys_eqs :
817 dev->caps.num_eqs;
Roland Dreier225c7b12007-05-08 18:00:38 -0700818 err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table,
819 cmpt_base +
820 ((u64) (MLX4_CMPT_TYPE_EQ *
821 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000822 cmpt_entry_sz, num_eqs, num_eqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700823 if (err)
824 goto err_cq;
825
826 return 0;
827
828err_cq:
829 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
830
831err_srq:
832 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
833
834err_qp:
835 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
836
837err:
838 return err;
839}
840
Roland Dreier3d73c282007-10-10 15:43:54 -0700841static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap,
842 struct mlx4_init_hca_param *init_hca, u64 icm_size)
Roland Dreier225c7b12007-05-08 18:00:38 -0700843{
844 struct mlx4_priv *priv = mlx4_priv(dev);
845 u64 aux_pages;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000846 int num_eqs;
Roland Dreier225c7b12007-05-08 18:00:38 -0700847 int err;
848
849 err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages);
850 if (err) {
851 mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n");
852 return err;
853 }
854
855 mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n",
856 (unsigned long long) icm_size >> 10,
857 (unsigned long long) aux_pages << 2);
858
859 priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300860 GFP_HIGHUSER | __GFP_NOWARN, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700861 if (!priv->fw.aux_icm) {
862 mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n");
863 return -ENOMEM;
864 }
865
866 err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm);
867 if (err) {
868 mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n");
869 goto err_free_aux;
870 }
871
872 err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz);
873 if (err) {
874 mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n");
875 goto err_unmap_aux;
876 }
877
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000878
Marcel Apfelbaum3fc929e2012-05-30 09:14:51 +0000879 num_eqs = (mlx4_is_master(dev)) ? dev->phys_caps.num_phys_eqs :
880 dev->caps.num_eqs;
Roland Dreierfa0681d2009-09-05 20:24:49 -0700881 err = mlx4_init_icm_table(dev, &priv->eq_table.table,
882 init_hca->eqc_base, dev_cap->eqc_entry_sz,
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000883 num_eqs, num_eqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700884 if (err) {
885 mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
886 goto err_unmap_cmpt;
887 }
888
Jack Morgensteind7bb58f2007-08-01 12:28:53 +0300889 /*
890 * Reserved MTT entries must be aligned up to a cacheline
891 * boundary, since the FW will write to them, while the driver
892 * writes to all other MTT entries. (The variable
893 * dev->caps.mtt_entry_sz below is really the MTT segment
894 * size, not the raw entry size)
895 */
896 dev->caps.reserved_mtts =
897 ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz,
898 dma_get_cache_alignment()) / dev->caps.mtt_entry_sz;
899
Roland Dreier225c7b12007-05-08 18:00:38 -0700900 err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
901 init_hca->mtt_base,
902 dev->caps.mtt_entry_sz,
Marcel Apfelbaum2b8fb282011-12-13 04:16:56 +0000903 dev->caps.num_mtts,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300904 dev->caps.reserved_mtts, 1, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700905 if (err) {
906 mlx4_err(dev, "Failed to map MTT context memory, aborting.\n");
907 goto err_unmap_eq;
908 }
909
910 err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table,
911 init_hca->dmpt_base,
912 dev_cap->dmpt_entry_sz,
913 dev->caps.num_mpts,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300914 dev->caps.reserved_mrws, 1, 1);
Roland Dreier225c7b12007-05-08 18:00:38 -0700915 if (err) {
916 mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n");
917 goto err_unmap_mtt;
918 }
919
920 err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table,
921 init_hca->qpc_base,
922 dev_cap->qpc_entry_sz,
923 dev->caps.num_qps,
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700924 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
925 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700926 if (err) {
927 mlx4_err(dev, "Failed to map QP context memory, aborting.\n");
928 goto err_unmap_dmpt;
929 }
930
931 err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table,
932 init_hca->auxc_base,
933 dev_cap->aux_entry_sz,
934 dev->caps.num_qps,
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700935 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
936 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700937 if (err) {
938 mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n");
939 goto err_unmap_qp;
940 }
941
942 err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table,
943 init_hca->altc_base,
944 dev_cap->altc_entry_sz,
945 dev->caps.num_qps,
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700946 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
947 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700948 if (err) {
949 mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n");
950 goto err_unmap_auxc;
951 }
952
953 err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table,
954 init_hca->rdmarc_base,
955 dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift,
956 dev->caps.num_qps,
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700957 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
958 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700959 if (err) {
960 mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n");
961 goto err_unmap_altc;
962 }
963
964 err = mlx4_init_icm_table(dev, &priv->cq_table.table,
965 init_hca->cqc_base,
966 dev_cap->cqc_entry_sz,
967 dev->caps.num_cqs,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300968 dev->caps.reserved_cqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700969 if (err) {
970 mlx4_err(dev, "Failed to map CQ context memory, aborting.\n");
971 goto err_unmap_rdmarc;
972 }
973
974 err = mlx4_init_icm_table(dev, &priv->srq_table.table,
975 init_hca->srqc_base,
976 dev_cap->srq_entry_sz,
977 dev->caps.num_srqs,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300978 dev->caps.reserved_srqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700979 if (err) {
980 mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
981 goto err_unmap_cq;
982 }
983
984 /*
985 * It's not strictly required, but for simplicity just map the
986 * whole multicast group table now. The table isn't very big
987 * and it's a lot easier than trying to track ref counts.
988 */
989 err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
Eugenia Emantayev0ec2c0f2011-12-13 04:16:02 +0000990 init_hca->mc_base,
991 mlx4_get_mgm_entry_size(dev),
Roland Dreier225c7b12007-05-08 18:00:38 -0700992 dev->caps.num_mgms + dev->caps.num_amgms,
993 dev->caps.num_mgms + dev->caps.num_amgms,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300994 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700995 if (err) {
996 mlx4_err(dev, "Failed to map MCG context memory, aborting.\n");
997 goto err_unmap_srq;
998 }
999
1000 return 0;
1001
1002err_unmap_srq:
1003 mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
1004
1005err_unmap_cq:
1006 mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
1007
1008err_unmap_rdmarc:
1009 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
1010
1011err_unmap_altc:
1012 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
1013
1014err_unmap_auxc:
1015 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
1016
1017err_unmap_qp:
1018 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
1019
1020err_unmap_dmpt:
1021 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
1022
1023err_unmap_mtt:
1024 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
1025
1026err_unmap_eq:
Roland Dreierfa0681d2009-09-05 20:24:49 -07001027 mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
Roland Dreier225c7b12007-05-08 18:00:38 -07001028
1029err_unmap_cmpt:
1030 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
1031 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
1032 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
1033 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
1034
1035err_unmap_aux:
1036 mlx4_UNMAP_ICM_AUX(dev);
1037
1038err_free_aux:
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +03001039 mlx4_free_icm(dev, priv->fw.aux_icm, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001040
1041 return err;
1042}
1043
1044static void mlx4_free_icms(struct mlx4_dev *dev)
1045{
1046 struct mlx4_priv *priv = mlx4_priv(dev);
1047
1048 mlx4_cleanup_icm_table(dev, &priv->mcg_table.table);
1049 mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
1050 mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
1051 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
1052 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
1053 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
1054 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
1055 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
1056 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
Roland Dreierfa0681d2009-09-05 20:24:49 -07001057 mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
Roland Dreier225c7b12007-05-08 18:00:38 -07001058 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
1059 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
1060 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
1061 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
Roland Dreier225c7b12007-05-08 18:00:38 -07001062
1063 mlx4_UNMAP_ICM_AUX(dev);
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +03001064 mlx4_free_icm(dev, priv->fw.aux_icm, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001065}
1066
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001067static void mlx4_slave_exit(struct mlx4_dev *dev)
1068{
1069 struct mlx4_priv *priv = mlx4_priv(dev);
1070
1071 down(&priv->cmd.slave_sem);
1072 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_TIME))
1073 mlx4_warn(dev, "Failed to close slave function.\n");
1074 up(&priv->cmd.slave_sem);
1075}
1076
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001077static int map_bf_area(struct mlx4_dev *dev)
1078{
1079 struct mlx4_priv *priv = mlx4_priv(dev);
1080 resource_size_t bf_start;
1081 resource_size_t bf_len;
1082 int err = 0;
1083
Jack Morgenstein3d747472012-02-19 21:38:52 +00001084 if (!dev->caps.bf_reg_size)
1085 return -ENXIO;
1086
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001087 bf_start = pci_resource_start(dev->pdev, 2) +
1088 (dev->caps.num_uars << PAGE_SHIFT);
1089 bf_len = pci_resource_len(dev->pdev, 2) -
1090 (dev->caps.num_uars << PAGE_SHIFT);
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001091 priv->bf_mapping = io_mapping_create_wc(bf_start, bf_len);
1092 if (!priv->bf_mapping)
1093 err = -ENOMEM;
1094
1095 return err;
1096}
1097
1098static void unmap_bf_area(struct mlx4_dev *dev)
1099{
1100 if (mlx4_priv(dev)->bf_mapping)
1101 io_mapping_free(mlx4_priv(dev)->bf_mapping);
1102}
1103
Roland Dreier225c7b12007-05-08 18:00:38 -07001104static void mlx4_close_hca(struct mlx4_dev *dev)
1105{
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001106 unmap_bf_area(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001107 if (mlx4_is_slave(dev))
1108 mlx4_slave_exit(dev);
1109 else {
1110 mlx4_CLOSE_HCA(dev, 0);
1111 mlx4_free_icms(dev);
1112 mlx4_UNMAP_FA(dev);
1113 mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0);
1114 }
1115}
1116
1117static int mlx4_init_slave(struct mlx4_dev *dev)
1118{
1119 struct mlx4_priv *priv = mlx4_priv(dev);
1120 u64 dma = (u64) priv->mfunc.vhcr_dma;
1121 int num_of_reset_retries = NUM_OF_RESET_RETRIES;
1122 int ret_from_reset = 0;
1123 u32 slave_read;
1124 u32 cmd_channel_ver;
1125
1126 down(&priv->cmd.slave_sem);
1127 priv->cmd.max_cmds = 1;
1128 mlx4_warn(dev, "Sending reset\n");
1129 ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0,
1130 MLX4_COMM_TIME);
1131 /* if we are in the middle of flr the slave will try
1132 * NUM_OF_RESET_RETRIES times before leaving.*/
1133 if (ret_from_reset) {
1134 if (MLX4_DELAY_RESET_SLAVE == ret_from_reset) {
1135 msleep(SLEEP_TIME_IN_RESET);
1136 while (ret_from_reset && num_of_reset_retries) {
1137 mlx4_warn(dev, "slave is currently in the"
1138 "middle of FLR. retrying..."
1139 "(try num:%d)\n",
1140 (NUM_OF_RESET_RETRIES -
1141 num_of_reset_retries + 1));
1142 ret_from_reset =
1143 mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET,
1144 0, MLX4_COMM_TIME);
1145 num_of_reset_retries = num_of_reset_retries - 1;
1146 }
1147 } else
1148 goto err;
1149 }
1150
1151 /* check the driver version - the slave I/F revision
1152 * must match the master's */
1153 slave_read = swab32(readl(&priv->mfunc.comm->slave_read));
1154 cmd_channel_ver = mlx4_comm_get_version();
1155
1156 if (MLX4_COMM_GET_IF_REV(cmd_channel_ver) !=
1157 MLX4_COMM_GET_IF_REV(slave_read)) {
1158 mlx4_err(dev, "slave driver version is not supported"
1159 " by the master\n");
1160 goto err;
1161 }
1162
1163 mlx4_warn(dev, "Sending vhcr0\n");
1164 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48,
1165 MLX4_COMM_TIME))
1166 goto err;
1167 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32,
1168 MLX4_COMM_TIME))
1169 goto err;
1170 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16,
1171 MLX4_COMM_TIME))
1172 goto err;
1173 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, MLX4_COMM_TIME))
1174 goto err;
1175 up(&priv->cmd.slave_sem);
1176 return 0;
1177
1178err:
1179 mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, 0);
1180 up(&priv->cmd.slave_sem);
1181 return -EIO;
Roland Dreier225c7b12007-05-08 18:00:38 -07001182}
1183
Roland Dreier3d73c282007-10-10 15:43:54 -07001184static int mlx4_init_hca(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -07001185{
1186 struct mlx4_priv *priv = mlx4_priv(dev);
1187 struct mlx4_adapter adapter;
1188 struct mlx4_dev_cap dev_cap;
Vladimir Sokolovsky2d928652008-07-14 23:48:53 -07001189 struct mlx4_mod_stat_cfg mlx4_cfg;
Roland Dreier225c7b12007-05-08 18:00:38 -07001190 struct mlx4_profile profile;
1191 struct mlx4_init_hca_param init_hca;
1192 u64 icm_size;
1193 int err;
1194
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001195 if (!mlx4_is_slave(dev)) {
1196 err = mlx4_QUERY_FW(dev);
1197 if (err) {
1198 if (err == -EACCES)
1199 mlx4_info(dev, "non-primary physical function, skipping.\n");
1200 else
1201 mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
1202 goto unmap_bf;
1203 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001204
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001205 err = mlx4_load_fw(dev);
1206 if (err) {
1207 mlx4_err(dev, "Failed to start FW, aborting.\n");
1208 goto unmap_bf;
1209 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001210
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001211 mlx4_cfg.log_pg_sz_m = 1;
1212 mlx4_cfg.log_pg_sz = 0;
1213 err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg);
1214 if (err)
1215 mlx4_warn(dev, "Failed to override log_pg_sz parameter\n");
Vladimir Sokolovsky2d928652008-07-14 23:48:53 -07001216
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001217 err = mlx4_dev_cap(dev, &dev_cap);
1218 if (err) {
1219 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
1220 goto err_stop_fw;
1221 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001222
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001223 profile = default_profile;
Roland Dreier225c7b12007-05-08 18:00:38 -07001224
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001225 icm_size = mlx4_make_profile(dev, &profile, &dev_cap,
1226 &init_hca);
1227 if ((long long) icm_size < 0) {
1228 err = icm_size;
1229 goto err_stop_fw;
1230 }
1231
Eli Cohena5bbe892012-02-09 18:10:06 +02001232 dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1;
1233
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001234 init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
1235 init_hca.uar_page_sz = PAGE_SHIFT - 12;
1236
1237 err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
1238 if (err)
1239 goto err_stop_fw;
1240
1241 err = mlx4_INIT_HCA(dev, &init_hca);
1242 if (err) {
1243 mlx4_err(dev, "INIT_HCA command failed, aborting.\n");
1244 goto err_free_icm;
1245 }
1246 } else {
1247 err = mlx4_init_slave(dev);
1248 if (err) {
1249 mlx4_err(dev, "Failed to initialize slave\n");
1250 goto unmap_bf;
1251 }
1252
1253 err = mlx4_slave_cap(dev);
1254 if (err) {
1255 mlx4_err(dev, "Failed to obtain slave caps\n");
1256 goto err_close;
1257 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001258 }
1259
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001260 if (map_bf_area(dev))
1261 mlx4_dbg(dev, "Failed to map blue flame area\n");
1262
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001263 /*Only the master set the ports, all the rest got it from it.*/
1264 if (!mlx4_is_slave(dev))
1265 mlx4_set_port_mask(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001266
1267 err = mlx4_QUERY_ADAPTER(dev, &adapter);
1268 if (err) {
1269 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
1270 goto err_close;
1271 }
1272
1273 priv->eq_table.inta_pin = adapter.inta_pin;
Jack Morgensteincd9281d2007-09-18 09:14:18 +02001274 memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id);
Roland Dreier225c7b12007-05-08 18:00:38 -07001275
1276 return 0;
1277
1278err_close:
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001279 mlx4_close_hca(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001280
1281err_free_icm:
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001282 if (!mlx4_is_slave(dev))
1283 mlx4_free_icms(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001284
1285err_stop_fw:
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001286 if (!mlx4_is_slave(dev)) {
1287 mlx4_UNMAP_FA(dev);
1288 mlx4_free_icm(dev, priv->fw.fw_icm, 0);
1289 }
1290unmap_bf:
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001291 unmap_bf_area(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001292 return err;
1293}
1294
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001295static int mlx4_init_counters_table(struct mlx4_dev *dev)
1296{
1297 struct mlx4_priv *priv = mlx4_priv(dev);
1298 int nent;
1299
1300 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS))
1301 return -ENOENT;
1302
1303 nent = dev->caps.max_counters;
1304 return mlx4_bitmap_init(&priv->counters_bitmap, nent, nent - 1, 0, 0);
1305}
1306
1307static void mlx4_cleanup_counters_table(struct mlx4_dev *dev)
1308{
1309 mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap);
1310}
1311
Jack Morgensteinba062d52012-05-15 10:35:03 +00001312int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx)
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001313{
1314 struct mlx4_priv *priv = mlx4_priv(dev);
1315
1316 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS))
1317 return -ENOENT;
1318
1319 *idx = mlx4_bitmap_alloc(&priv->counters_bitmap);
1320 if (*idx == -1)
1321 return -ENOMEM;
1322
1323 return 0;
1324}
Jack Morgensteinba062d52012-05-15 10:35:03 +00001325
1326int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx)
1327{
1328 u64 out_param;
1329 int err;
1330
1331 if (mlx4_is_mfunc(dev)) {
1332 err = mlx4_cmd_imm(dev, 0, &out_param, RES_COUNTER,
1333 RES_OP_RESERVE, MLX4_CMD_ALLOC_RES,
1334 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
1335 if (!err)
1336 *idx = get_param_l(&out_param);
1337
1338 return err;
1339 }
1340 return __mlx4_counter_alloc(dev, idx);
1341}
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001342EXPORT_SYMBOL_GPL(mlx4_counter_alloc);
1343
Jack Morgensteinba062d52012-05-15 10:35:03 +00001344void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx)
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001345{
1346 mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx);
1347 return;
1348}
Jack Morgensteinba062d52012-05-15 10:35:03 +00001349
1350void mlx4_counter_free(struct mlx4_dev *dev, u32 idx)
1351{
1352 u64 in_param;
1353
1354 if (mlx4_is_mfunc(dev)) {
1355 set_param_l(&in_param, idx);
1356 mlx4_cmd(dev, in_param, RES_COUNTER, RES_OP_RESERVE,
1357 MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A,
1358 MLX4_CMD_WRAPPED);
1359 return;
1360 }
1361 __mlx4_counter_free(dev, idx);
1362}
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001363EXPORT_SYMBOL_GPL(mlx4_counter_free);
1364
Roland Dreier3d73c282007-10-10 15:43:54 -07001365static int mlx4_setup_hca(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -07001366{
1367 struct mlx4_priv *priv = mlx4_priv(dev);
1368 int err;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001369 int port;
Jack Morgenstein9a5aa622008-11-28 21:29:46 -08001370 __be32 ib_port_default_caps;
Roland Dreier225c7b12007-05-08 18:00:38 -07001371
Roland Dreier225c7b12007-05-08 18:00:38 -07001372 err = mlx4_init_uar_table(dev);
1373 if (err) {
1374 mlx4_err(dev, "Failed to initialize "
1375 "user access region table, aborting.\n");
1376 return err;
1377 }
1378
1379 err = mlx4_uar_alloc(dev, &priv->driver_uar);
1380 if (err) {
1381 mlx4_err(dev, "Failed to allocate driver access region, "
1382 "aborting.\n");
1383 goto err_uar_table_free;
1384 }
1385
Roland Dreier4979d182011-01-12 09:50:36 -08001386 priv->kar = ioremap((phys_addr_t) priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001387 if (!priv->kar) {
1388 mlx4_err(dev, "Couldn't map kernel access region, "
1389 "aborting.\n");
1390 err = -ENOMEM;
1391 goto err_uar_free;
1392 }
1393
1394 err = mlx4_init_pd_table(dev);
1395 if (err) {
1396 mlx4_err(dev, "Failed to initialize "
1397 "protection domain table, aborting.\n");
1398 goto err_kar_unmap;
1399 }
1400
Sean Hefty012a8ff2011-06-02 09:01:33 -07001401 err = mlx4_init_xrcd_table(dev);
1402 if (err) {
1403 mlx4_err(dev, "Failed to initialize "
1404 "reliable connection domain table, aborting.\n");
1405 goto err_pd_table_free;
1406 }
1407
Roland Dreier225c7b12007-05-08 18:00:38 -07001408 err = mlx4_init_mr_table(dev);
1409 if (err) {
1410 mlx4_err(dev, "Failed to initialize "
1411 "memory region table, aborting.\n");
Sean Hefty012a8ff2011-06-02 09:01:33 -07001412 goto err_xrcd_table_free;
Roland Dreier225c7b12007-05-08 18:00:38 -07001413 }
1414
Roland Dreier225c7b12007-05-08 18:00:38 -07001415 err = mlx4_init_eq_table(dev);
1416 if (err) {
1417 mlx4_err(dev, "Failed to initialize "
1418 "event queue table, aborting.\n");
Jack Morgensteinee49bd92007-07-12 17:50:45 +03001419 goto err_mr_table_free;
Roland Dreier225c7b12007-05-08 18:00:38 -07001420 }
1421
1422 err = mlx4_cmd_use_events(dev);
1423 if (err) {
1424 mlx4_err(dev, "Failed to switch to event-driven "
1425 "firmware commands, aborting.\n");
1426 goto err_eq_table_free;
1427 }
1428
1429 err = mlx4_NOP(dev);
1430 if (err) {
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03001431 if (dev->flags & MLX4_FLAG_MSI_X) {
1432 mlx4_warn(dev, "NOP command failed to generate MSI-X "
1433 "interrupt IRQ %d).\n",
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001434 priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03001435 mlx4_warn(dev, "Trying again without MSI-X.\n");
1436 } else {
1437 mlx4_err(dev, "NOP command failed to generate interrupt "
1438 "(IRQ %d), aborting.\n",
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001439 priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
Roland Dreier225c7b12007-05-08 18:00:38 -07001440 mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03001441 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001442
1443 goto err_cmd_poll;
1444 }
1445
1446 mlx4_dbg(dev, "NOP command IRQ test passed\n");
1447
1448 err = mlx4_init_cq_table(dev);
1449 if (err) {
1450 mlx4_err(dev, "Failed to initialize "
1451 "completion queue table, aborting.\n");
1452 goto err_cmd_poll;
1453 }
1454
1455 err = mlx4_init_srq_table(dev);
1456 if (err) {
1457 mlx4_err(dev, "Failed to initialize "
1458 "shared receive queue table, aborting.\n");
1459 goto err_cq_table_free;
1460 }
1461
1462 err = mlx4_init_qp_table(dev);
1463 if (err) {
1464 mlx4_err(dev, "Failed to initialize "
1465 "queue pair table, aborting.\n");
1466 goto err_srq_table_free;
1467 }
1468
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001469 if (!mlx4_is_slave(dev)) {
1470 err = mlx4_init_mcg_table(dev);
1471 if (err) {
1472 mlx4_err(dev, "Failed to initialize "
1473 "multicast group table, aborting.\n");
1474 goto err_qp_table_free;
1475 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001476 }
1477
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001478 err = mlx4_init_counters_table(dev);
1479 if (err && err != -ENOENT) {
1480 mlx4_err(dev, "Failed to initialize counters table, aborting.\n");
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001481 goto err_mcg_table_free;
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001482 }
1483
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001484 if (!mlx4_is_slave(dev)) {
1485 for (port = 1; port <= dev->caps.num_ports; port++) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001486 ib_port_default_caps = 0;
1487 err = mlx4_get_port_ib_caps(dev, port,
1488 &ib_port_default_caps);
1489 if (err)
1490 mlx4_warn(dev, "failed to get port %d default "
1491 "ib capabilities (%d). Continuing "
1492 "with caps = 0\n", port, err);
1493 dev->caps.ib_port_def_cap[port] = ib_port_default_caps;
Marcel Apfelbaum97285b72011-10-24 11:02:34 +02001494
Or Gerlitz096335b2012-01-11 19:02:17 +02001495 if (mlx4_is_mfunc(dev))
1496 dev->caps.port_ib_mtu[port] = IB_MTU_2048;
1497 else
1498 dev->caps.port_ib_mtu[port] = IB_MTU_4096;
Marcel Apfelbaum97285b72011-10-24 11:02:34 +02001499
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001500 err = mlx4_SET_PORT(dev, port);
1501 if (err) {
1502 mlx4_err(dev, "Failed to set port %d, aborting\n",
1503 port);
1504 goto err_counters_table_free;
1505 }
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001506 }
1507 }
1508
Roland Dreier225c7b12007-05-08 18:00:38 -07001509 return 0;
1510
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001511err_counters_table_free:
1512 mlx4_cleanup_counters_table(dev);
1513
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001514err_mcg_table_free:
1515 mlx4_cleanup_mcg_table(dev);
1516
Roland Dreier225c7b12007-05-08 18:00:38 -07001517err_qp_table_free:
1518 mlx4_cleanup_qp_table(dev);
1519
1520err_srq_table_free:
1521 mlx4_cleanup_srq_table(dev);
1522
1523err_cq_table_free:
1524 mlx4_cleanup_cq_table(dev);
1525
1526err_cmd_poll:
1527 mlx4_cmd_use_polling(dev);
1528
1529err_eq_table_free:
1530 mlx4_cleanup_eq_table(dev);
1531
Jack Morgensteinee49bd92007-07-12 17:50:45 +03001532err_mr_table_free:
Roland Dreier225c7b12007-05-08 18:00:38 -07001533 mlx4_cleanup_mr_table(dev);
1534
Sean Hefty012a8ff2011-06-02 09:01:33 -07001535err_xrcd_table_free:
1536 mlx4_cleanup_xrcd_table(dev);
1537
Roland Dreier225c7b12007-05-08 18:00:38 -07001538err_pd_table_free:
1539 mlx4_cleanup_pd_table(dev);
1540
1541err_kar_unmap:
1542 iounmap(priv->kar);
1543
1544err_uar_free:
1545 mlx4_uar_free(dev, &priv->driver_uar);
1546
1547err_uar_table_free:
1548 mlx4_cleanup_uar_table(dev);
1549 return err;
1550}
1551
Roland Dreiere8f9b2e2008-02-04 20:20:41 -08001552static void mlx4_enable_msi_x(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -07001553{
1554 struct mlx4_priv *priv = mlx4_priv(dev);
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001555 struct msix_entry *entries;
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001556 int nreq = min_t(int, dev->caps.num_ports *
Yuval Mintz90b1ebe2012-07-01 03:18:51 +00001557 min_t(int, netif_get_num_default_rss_queues() + 1,
1558 MAX_MSIX_P_PORT) + MSIX_LEGACY_SZ, MAX_MSIX);
Roland Dreier225c7b12007-05-08 18:00:38 -07001559 int err;
1560 int i;
1561
1562 if (msi_x) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001563 /* In multifunction mode each function gets 2 msi-X vectors
1564 * one for data path completions anf the other for asynch events
1565 * or command completions */
1566 if (mlx4_is_mfunc(dev)) {
1567 nreq = 2;
1568 } else {
1569 nreq = min_t(int, dev->caps.num_eqs -
1570 dev->caps.reserved_eqs, nreq);
1571 }
1572
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001573 entries = kcalloc(nreq, sizeof *entries, GFP_KERNEL);
1574 if (!entries)
1575 goto no_msi;
1576
1577 for (i = 0; i < nreq; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001578 entries[i].entry = i;
1579
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001580 retry:
1581 err = pci_enable_msix(dev->pdev, entries, nreq);
Roland Dreier225c7b12007-05-08 18:00:38 -07001582 if (err) {
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001583 /* Try again if at least 2 vectors are available */
1584 if (err > 1) {
1585 mlx4_info(dev, "Requested %d vectors, "
1586 "but only %d MSI-X vectors available, "
1587 "trying again\n", nreq, err);
1588 nreq = err;
1589 goto retry;
1590 }
Nicolas Morey-Chaisemartin5bf0da72009-04-21 10:11:06 -07001591 kfree(entries);
Roland Dreier225c7b12007-05-08 18:00:38 -07001592 goto no_msi;
1593 }
1594
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001595 if (nreq <
1596 MSIX_LEGACY_SZ + dev->caps.num_ports * MIN_MSIX_P_PORT) {
1597 /*Working in legacy mode , all EQ's shared*/
1598 dev->caps.comp_pool = 0;
1599 dev->caps.num_comp_vectors = nreq - 1;
1600 } else {
1601 dev->caps.comp_pool = nreq - MSIX_LEGACY_SZ;
1602 dev->caps.num_comp_vectors = MSIX_LEGACY_SZ - 1;
1603 }
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001604 for (i = 0; i < nreq; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001605 priv->eq_table.eq[i].irq = entries[i].vector;
1606
1607 dev->flags |= MLX4_FLAG_MSI_X;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001608
1609 kfree(entries);
Roland Dreier225c7b12007-05-08 18:00:38 -07001610 return;
1611 }
1612
1613no_msi:
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001614 dev->caps.num_comp_vectors = 1;
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001615 dev->caps.comp_pool = 0;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001616
1617 for (i = 0; i < 2; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001618 priv->eq_table.eq[i].irq = dev->pdev->irq;
1619}
1620
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001621static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07001622{
1623 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001624 int err = 0;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07001625
1626 info->dev = dev;
1627 info->port = port;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001628 if (!mlx4_is_slave(dev)) {
1629 INIT_RADIX_TREE(&info->mac_tree, GFP_KERNEL);
1630 mlx4_init_mac_table(dev, &info->mac_table);
1631 mlx4_init_vlan_table(dev, &info->vlan_table);
1632 info->base_qpn =
1633 dev->caps.reserved_qps_base[MLX4_QP_REGION_ETH_ADDR] +
Yevgeny Petrilin06fa0a82011-08-03 16:38:59 -07001634 (port - 1) * (1 << log_num_mac);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001635 }
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001636
1637 sprintf(info->dev_name, "mlx4_port%d", port);
1638 info->port_attr.attr.name = info->dev_name;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001639 if (mlx4_is_mfunc(dev))
1640 info->port_attr.attr.mode = S_IRUGO;
1641 else {
1642 info->port_attr.attr.mode = S_IRUGO | S_IWUSR;
1643 info->port_attr.store = set_port_type;
1644 }
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001645 info->port_attr.show = show_port_type;
Greg Kroah-Hartman3691c9642010-03-15 14:01:55 -07001646 sysfs_attr_init(&info->port_attr.attr);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001647
1648 err = device_create_file(&dev->pdev->dev, &info->port_attr);
1649 if (err) {
1650 mlx4_err(dev, "Failed to create file for port %d\n", port);
1651 info->port = -1;
1652 }
1653
Or Gerlitz096335b2012-01-11 19:02:17 +02001654 sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
1655 info->port_mtu_attr.attr.name = info->dev_mtu_name;
1656 if (mlx4_is_mfunc(dev))
1657 info->port_mtu_attr.attr.mode = S_IRUGO;
1658 else {
1659 info->port_mtu_attr.attr.mode = S_IRUGO | S_IWUSR;
1660 info->port_mtu_attr.store = set_port_ib_mtu;
1661 }
1662 info->port_mtu_attr.show = show_port_ib_mtu;
1663 sysfs_attr_init(&info->port_mtu_attr.attr);
1664
1665 err = device_create_file(&dev->pdev->dev, &info->port_mtu_attr);
1666 if (err) {
1667 mlx4_err(dev, "Failed to create mtu file for port %d\n", port);
1668 device_remove_file(&info->dev->pdev->dev, &info->port_attr);
1669 info->port = -1;
1670 }
1671
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001672 return err;
1673}
1674
1675static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
1676{
1677 if (info->port < 0)
1678 return;
1679
1680 device_remove_file(&info->dev->pdev->dev, &info->port_attr);
Or Gerlitz096335b2012-01-11 19:02:17 +02001681 device_remove_file(&info->dev->pdev->dev, &info->port_mtu_attr);
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07001682}
1683
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00001684static int mlx4_init_steering(struct mlx4_dev *dev)
1685{
1686 struct mlx4_priv *priv = mlx4_priv(dev);
1687 int num_entries = dev->caps.num_ports;
1688 int i, j;
1689
1690 priv->steer = kzalloc(sizeof(struct mlx4_steer) * num_entries, GFP_KERNEL);
1691 if (!priv->steer)
1692 return -ENOMEM;
1693
Eugenia Emantayev45b51362012-02-14 06:37:41 +00001694 for (i = 0; i < num_entries; i++)
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00001695 for (j = 0; j < MLX4_NUM_STEERS; j++) {
1696 INIT_LIST_HEAD(&priv->steer[i].promisc_qps[j]);
1697 INIT_LIST_HEAD(&priv->steer[i].steer_entries[j]);
1698 }
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00001699 return 0;
1700}
1701
1702static void mlx4_clear_steering(struct mlx4_dev *dev)
1703{
1704 struct mlx4_priv *priv = mlx4_priv(dev);
1705 struct mlx4_steer_index *entry, *tmp_entry;
1706 struct mlx4_promisc_qp *pqp, *tmp_pqp;
1707 int num_entries = dev->caps.num_ports;
1708 int i, j;
1709
1710 for (i = 0; i < num_entries; i++) {
1711 for (j = 0; j < MLX4_NUM_STEERS; j++) {
1712 list_for_each_entry_safe(pqp, tmp_pqp,
1713 &priv->steer[i].promisc_qps[j],
1714 list) {
1715 list_del(&pqp->list);
1716 kfree(pqp);
1717 }
1718 list_for_each_entry_safe(entry, tmp_entry,
1719 &priv->steer[i].steer_entries[j],
1720 list) {
1721 list_del(&entry->list);
1722 list_for_each_entry_safe(pqp, tmp_pqp,
1723 &entry->duplicates,
1724 list) {
1725 list_del(&pqp->list);
1726 kfree(pqp);
1727 }
1728 kfree(entry);
1729 }
1730 }
1731 }
1732 kfree(priv->steer);
1733}
1734
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001735static int extended_func_num(struct pci_dev *pdev)
1736{
1737 return PCI_SLOT(pdev->devfn) * 8 + PCI_FUNC(pdev->devfn);
1738}
1739
1740#define MLX4_OWNER_BASE 0x8069c
1741#define MLX4_OWNER_SIZE 4
1742
1743static int mlx4_get_ownership(struct mlx4_dev *dev)
1744{
1745 void __iomem *owner;
1746 u32 ret;
1747
1748 owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE,
1749 MLX4_OWNER_SIZE);
1750 if (!owner) {
1751 mlx4_err(dev, "Failed to obtain ownership bit\n");
1752 return -ENOMEM;
1753 }
1754
1755 ret = readl(owner);
1756 iounmap(owner);
1757 return (int) !!ret;
1758}
1759
1760static void mlx4_free_ownership(struct mlx4_dev *dev)
1761{
1762 void __iomem *owner;
1763
1764 owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE,
1765 MLX4_OWNER_SIZE);
1766 if (!owner) {
1767 mlx4_err(dev, "Failed to obtain ownership bit\n");
1768 return;
1769 }
1770 writel(0, owner);
1771 msleep(1000);
1772 iounmap(owner);
1773}
1774
Roland Dreier3d73c282007-10-10 15:43:54 -07001775static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
Roland Dreier225c7b12007-05-08 18:00:38 -07001776{
Roland Dreier225c7b12007-05-08 18:00:38 -07001777 struct mlx4_priv *priv;
1778 struct mlx4_dev *dev;
1779 int err;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07001780 int port;
Roland Dreier225c7b12007-05-08 18:00:38 -07001781
Joe Perches0a645e82010-07-10 07:22:46 +00001782 pr_info(DRV_NAME ": Initializing %s\n", pci_name(pdev));
Roland Dreier225c7b12007-05-08 18:00:38 -07001783
1784 err = pci_enable_device(pdev);
1785 if (err) {
1786 dev_err(&pdev->dev, "Cannot enable PCI device, "
1787 "aborting.\n");
1788 return err;
1789 }
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001790 if (num_vfs > MLX4_MAX_NUM_VF) {
1791 printk(KERN_ERR "There are more VF's (%d) than allowed(%d)\n",
1792 num_vfs, MLX4_MAX_NUM_VF);
1793 return -EINVAL;
1794 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001795 /*
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001796 * Check for BARs.
Roland Dreier225c7b12007-05-08 18:00:38 -07001797 */
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001798 if (((id == NULL) || !(id->driver_data & MLX4_VF)) &&
1799 !(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1800 dev_err(&pdev->dev, "Missing DCS, aborting."
1801 "(id == 0X%p, id->driver_data: 0x%lx,"
1802 " pci_resource_flags(pdev, 0):0x%lx)\n", id,
1803 id ? id->driver_data : 0, pci_resource_flags(pdev, 0));
Roland Dreier225c7b12007-05-08 18:00:38 -07001804 err = -ENODEV;
1805 goto err_disable_pdev;
1806 }
1807 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
1808 dev_err(&pdev->dev, "Missing UAR, aborting.\n");
1809 err = -ENODEV;
1810 goto err_disable_pdev;
1811 }
1812
Roland Dreiera01df0f2009-09-05 20:24:48 -07001813 err = pci_request_regions(pdev, DRV_NAME);
Roland Dreier225c7b12007-05-08 18:00:38 -07001814 if (err) {
Roland Dreiera01df0f2009-09-05 20:24:48 -07001815 dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n");
Roland Dreier225c7b12007-05-08 18:00:38 -07001816 goto err_disable_pdev;
1817 }
1818
Roland Dreier225c7b12007-05-08 18:00:38 -07001819 pci_set_master(pdev);
1820
Yang Hongyang6a355282009-04-06 19:01:13 -07001821 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
Roland Dreier225c7b12007-05-08 18:00:38 -07001822 if (err) {
1823 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
Yang Hongyang284901a2009-04-06 19:01:15 -07001824 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Roland Dreier225c7b12007-05-08 18:00:38 -07001825 if (err) {
1826 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
Roland Dreiera01df0f2009-09-05 20:24:48 -07001827 goto err_release_regions;
Roland Dreier225c7b12007-05-08 18:00:38 -07001828 }
1829 }
Yang Hongyang6a355282009-04-06 19:01:13 -07001830 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Roland Dreier225c7b12007-05-08 18:00:38 -07001831 if (err) {
1832 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
1833 "consistent PCI DMA mask.\n");
Yang Hongyang284901a2009-04-06 19:01:15 -07001834 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Roland Dreier225c7b12007-05-08 18:00:38 -07001835 if (err) {
1836 dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
1837 "aborting.\n");
Roland Dreiera01df0f2009-09-05 20:24:48 -07001838 goto err_release_regions;
Roland Dreier225c7b12007-05-08 18:00:38 -07001839 }
1840 }
1841
David Dillow7f9e5c482011-01-17 02:09:44 +00001842 /* Allow large DMA segments, up to the firmware limit of 1 GB */
1843 dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024);
1844
Roland Dreier225c7b12007-05-08 18:00:38 -07001845 priv = kzalloc(sizeof *priv, GFP_KERNEL);
1846 if (!priv) {
1847 dev_err(&pdev->dev, "Device struct alloc failed, "
1848 "aborting.\n");
1849 err = -ENOMEM;
Roland Dreiera01df0f2009-09-05 20:24:48 -07001850 goto err_release_regions;
Roland Dreier225c7b12007-05-08 18:00:38 -07001851 }
1852
1853 dev = &priv->dev;
1854 dev->pdev = pdev;
Roland Dreierb5814012007-06-07 11:51:58 -07001855 INIT_LIST_HEAD(&priv->ctx_list);
1856 spin_lock_init(&priv->ctx_lock);
Roland Dreier225c7b12007-05-08 18:00:38 -07001857
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001858 mutex_init(&priv->port_mutex);
1859
Yevgeny Petrilin62968832008-04-23 11:55:45 -07001860 INIT_LIST_HEAD(&priv->pgdir_list);
1861 mutex_init(&priv->pgdir_mutex);
1862
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001863 INIT_LIST_HEAD(&priv->bf_list);
1864 mutex_init(&priv->bf_mutex);
1865
Sergei Shtylyovaca7a3a2011-06-23 04:44:30 +00001866 dev->rev_id = pdev->revision;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001867 /* Detect if this device is a virtual function */
1868 if (id && id->driver_data & MLX4_VF) {
1869 /* When acting as pf, we normally skip vfs unless explicitly
1870 * requested to probe them. */
1871 if (num_vfs && extended_func_num(pdev) > probe_vf) {
1872 mlx4_warn(dev, "Skipping virtual function:%d\n",
1873 extended_func_num(pdev));
1874 err = -ENODEV;
1875 goto err_free_dev;
1876 }
1877 mlx4_warn(dev, "Detected virtual function - running in slave mode\n");
1878 dev->flags |= MLX4_FLAG_SLAVE;
1879 } else {
1880 /* We reset the device and enable SRIOV only for physical
1881 * devices. Try to claim ownership on the device;
1882 * if already taken, skip -- do not allow multiple PFs */
1883 err = mlx4_get_ownership(dev);
1884 if (err) {
1885 if (err < 0)
1886 goto err_free_dev;
1887 else {
1888 mlx4_warn(dev, "Multiple PFs not yet supported."
1889 " Skipping PF.\n");
1890 err = -EINVAL;
1891 goto err_free_dev;
1892 }
1893 }
Sergei Shtylyovaca7a3a2011-06-23 04:44:30 +00001894
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001895 if (num_vfs) {
1896 mlx4_warn(dev, "Enabling sriov with:%d vfs\n", num_vfs);
1897 err = pci_enable_sriov(pdev, num_vfs);
1898 if (err) {
1899 mlx4_err(dev, "Failed to enable sriov,"
1900 "continuing without sriov enabled"
1901 " (err = %d).\n", err);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001902 err = 0;
1903 } else {
1904 mlx4_warn(dev, "Running in master mode\n");
1905 dev->flags |= MLX4_FLAG_SRIOV |
1906 MLX4_FLAG_MASTER;
1907 dev->num_vfs = num_vfs;
1908 }
1909 }
1910
1911 /*
1912 * Now reset the HCA before we touch the PCI capabilities or
1913 * attempt a firmware command, since a boot ROM may have left
1914 * the HCA in an undefined state.
1915 */
1916 err = mlx4_reset(dev);
1917 if (err) {
1918 mlx4_err(dev, "Failed to reset HCA, aborting.\n");
1919 goto err_rel_own;
1920 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001921 }
1922
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001923slave_start:
Roland Dreier225c7b12007-05-08 18:00:38 -07001924 if (mlx4_cmd_init(dev)) {
1925 mlx4_err(dev, "Failed to init command interface, aborting.\n");
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001926 goto err_sriov;
1927 }
1928
1929 /* In slave functions, the communication channel must be initialized
1930 * before posting commands. Also, init num_slaves before calling
1931 * mlx4_init_hca */
1932 if (mlx4_is_mfunc(dev)) {
1933 if (mlx4_is_master(dev))
1934 dev->num_slaves = MLX4_MAX_NUM_SLAVES;
1935 else {
1936 dev->num_slaves = 0;
1937 if (mlx4_multi_func_init(dev)) {
1938 mlx4_err(dev, "Failed to init slave mfunc"
1939 " interface, aborting.\n");
1940 goto err_cmd;
1941 }
1942 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001943 }
1944
1945 err = mlx4_init_hca(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001946 if (err) {
1947 if (err == -EACCES) {
1948 /* Not primary Physical function
1949 * Running in slave mode */
1950 mlx4_cmd_cleanup(dev);
1951 dev->flags |= MLX4_FLAG_SLAVE;
1952 dev->flags &= ~MLX4_FLAG_MASTER;
1953 goto slave_start;
1954 } else
1955 goto err_mfunc;
1956 }
1957
1958 /* In master functions, the communication channel must be initialized
1959 * after obtaining its address from fw */
1960 if (mlx4_is_master(dev)) {
1961 if (mlx4_multi_func_init(dev)) {
1962 mlx4_err(dev, "Failed to init master mfunc"
1963 "interface, aborting.\n");
1964 goto err_close;
1965 }
1966 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001967
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001968 err = mlx4_alloc_eq_table(dev);
1969 if (err)
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001970 goto err_master_mfunc;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001971
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001972 priv->msix_ctl.pool_bm = 0;
Yevgeny Petrilin730c41d2012-02-21 03:39:32 +00001973 mutex_init(&priv->msix_ctl.pool_lock);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001974
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03001975 mlx4_enable_msi_x(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001976 if ((mlx4_is_mfunc(dev)) &&
1977 !(dev->flags & MLX4_FLAG_MSI_X)) {
1978 mlx4_err(dev, "INTx is not supported in multi-function mode."
1979 " aborting.\n");
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00001980 goto err_free_eq;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001981 }
1982
1983 if (!mlx4_is_slave(dev)) {
1984 err = mlx4_init_steering(dev);
1985 if (err)
1986 goto err_free_eq;
1987 }
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00001988
Roland Dreier225c7b12007-05-08 18:00:38 -07001989 err = mlx4_setup_hca(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001990 if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) &&
1991 !mlx4_is_mfunc(dev)) {
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03001992 dev->flags &= ~MLX4_FLAG_MSI_X;
Yevgeny Petrilin9858d2d2012-06-25 00:24:12 +00001993 dev->caps.num_comp_vectors = 1;
1994 dev->caps.comp_pool = 0;
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03001995 pci_disable_msix(pdev);
1996 err = mlx4_setup_hca(dev);
1997 }
1998
Roland Dreier225c7b12007-05-08 18:00:38 -07001999 if (err)
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00002000 goto err_steer;
Roland Dreier225c7b12007-05-08 18:00:38 -07002001
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002002 for (port = 1; port <= dev->caps.num_ports; port++) {
2003 err = mlx4_init_port_info(dev, port);
2004 if (err)
2005 goto err_port;
2006 }
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07002007
Roland Dreier225c7b12007-05-08 18:00:38 -07002008 err = mlx4_register_device(dev);
2009 if (err)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002010 goto err_port;
Roland Dreier225c7b12007-05-08 18:00:38 -07002011
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -07002012 mlx4_sense_init(dev);
2013 mlx4_start_sense(dev);
2014
Roland Dreier225c7b12007-05-08 18:00:38 -07002015 pci_set_drvdata(pdev, dev);
2016
2017 return 0;
2018
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002019err_port:
Eli Cohenb4f77262010-01-06 12:54:39 -08002020 for (--port; port >= 1; --port)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002021 mlx4_cleanup_port_info(&priv->port[port]);
2022
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00002023 mlx4_cleanup_counters_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002024 mlx4_cleanup_mcg_table(dev);
2025 mlx4_cleanup_qp_table(dev);
2026 mlx4_cleanup_srq_table(dev);
2027 mlx4_cleanup_cq_table(dev);
2028 mlx4_cmd_use_polling(dev);
2029 mlx4_cleanup_eq_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002030 mlx4_cleanup_mr_table(dev);
Sean Hefty012a8ff2011-06-02 09:01:33 -07002031 mlx4_cleanup_xrcd_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002032 mlx4_cleanup_pd_table(dev);
2033 mlx4_cleanup_uar_table(dev);
2034
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00002035err_steer:
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002036 if (!mlx4_is_slave(dev))
2037 mlx4_clear_steering(dev);
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00002038
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08002039err_free_eq:
2040 mlx4_free_eq_table(dev);
2041
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002042err_master_mfunc:
2043 if (mlx4_is_master(dev))
2044 mlx4_multi_func_cleanup(dev);
2045
Roland Dreier225c7b12007-05-08 18:00:38 -07002046err_close:
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03002047 if (dev->flags & MLX4_FLAG_MSI_X)
2048 pci_disable_msix(pdev);
2049
Roland Dreier225c7b12007-05-08 18:00:38 -07002050 mlx4_close_hca(dev);
2051
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002052err_mfunc:
2053 if (mlx4_is_slave(dev))
2054 mlx4_multi_func_cleanup(dev);
2055
Roland Dreier225c7b12007-05-08 18:00:38 -07002056err_cmd:
2057 mlx4_cmd_cleanup(dev);
2058
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002059err_sriov:
Jack Morgenstein681372a2012-05-15 10:35:01 +00002060 if (dev->flags & MLX4_FLAG_SRIOV)
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002061 pci_disable_sriov(pdev);
2062
2063err_rel_own:
2064 if (!mlx4_is_slave(dev))
2065 mlx4_free_ownership(dev);
2066
Roland Dreier225c7b12007-05-08 18:00:38 -07002067err_free_dev:
Roland Dreier225c7b12007-05-08 18:00:38 -07002068 kfree(priv);
2069
Roland Dreiera01df0f2009-09-05 20:24:48 -07002070err_release_regions:
2071 pci_release_regions(pdev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002072
2073err_disable_pdev:
2074 pci_disable_device(pdev);
2075 pci_set_drvdata(pdev, NULL);
2076 return err;
2077}
2078
Roland Dreier3d73c282007-10-10 15:43:54 -07002079static int __devinit mlx4_init_one(struct pci_dev *pdev,
2080 const struct pci_device_id *id)
2081{
Joe Perches0a645e82010-07-10 07:22:46 +00002082 printk_once(KERN_INFO "%s", mlx4_version);
Roland Dreier3d73c282007-10-10 15:43:54 -07002083
Roland Dreierb027cac2007-10-13 14:10:50 -07002084 return __mlx4_init_one(pdev, id);
Roland Dreier3d73c282007-10-10 15:43:54 -07002085}
2086
2087static void mlx4_remove_one(struct pci_dev *pdev)
Roland Dreier225c7b12007-05-08 18:00:38 -07002088{
2089 struct mlx4_dev *dev = pci_get_drvdata(pdev);
2090 struct mlx4_priv *priv = mlx4_priv(dev);
2091 int p;
2092
2093 if (dev) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002094 /* in SRIOV it is not allowed to unload the pf's
2095 * driver while there are alive vf's */
2096 if (mlx4_is_master(dev)) {
2097 if (mlx4_how_many_lives_vf(dev))
2098 printk(KERN_ERR "Removing PF when there are assigned VF's !!!\n");
2099 }
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -07002100 mlx4_stop_sense(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002101 mlx4_unregister_device(dev);
2102
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002103 for (p = 1; p <= dev->caps.num_ports; p++) {
2104 mlx4_cleanup_port_info(&priv->port[p]);
Roland Dreier225c7b12007-05-08 18:00:38 -07002105 mlx4_CLOSE_PORT(dev, p);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002106 }
Roland Dreier225c7b12007-05-08 18:00:38 -07002107
Jack Morgensteinb8924952012-05-15 10:35:02 +00002108 if (mlx4_is_master(dev))
2109 mlx4_free_resource_tracker(dev,
2110 RES_TR_FREE_SLAVES_ONLY);
2111
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00002112 mlx4_cleanup_counters_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002113 mlx4_cleanup_mcg_table(dev);
2114 mlx4_cleanup_qp_table(dev);
2115 mlx4_cleanup_srq_table(dev);
2116 mlx4_cleanup_cq_table(dev);
2117 mlx4_cmd_use_polling(dev);
2118 mlx4_cleanup_eq_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002119 mlx4_cleanup_mr_table(dev);
Sean Hefty012a8ff2011-06-02 09:01:33 -07002120 mlx4_cleanup_xrcd_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002121 mlx4_cleanup_pd_table(dev);
2122
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002123 if (mlx4_is_master(dev))
Jack Morgensteinb8924952012-05-15 10:35:02 +00002124 mlx4_free_resource_tracker(dev,
2125 RES_TR_FREE_STRUCTS_ONLY);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002126
Roland Dreier225c7b12007-05-08 18:00:38 -07002127 iounmap(priv->kar);
2128 mlx4_uar_free(dev, &priv->driver_uar);
2129 mlx4_cleanup_uar_table(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002130 if (!mlx4_is_slave(dev))
2131 mlx4_clear_steering(dev);
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08002132 mlx4_free_eq_table(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002133 if (mlx4_is_master(dev))
2134 mlx4_multi_func_cleanup(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002135 mlx4_close_hca(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002136 if (mlx4_is_slave(dev))
2137 mlx4_multi_func_cleanup(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002138 mlx4_cmd_cleanup(dev);
2139
2140 if (dev->flags & MLX4_FLAG_MSI_X)
2141 pci_disable_msix(pdev);
Jack Morgenstein681372a2012-05-15 10:35:01 +00002142 if (dev->flags & MLX4_FLAG_SRIOV) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002143 mlx4_warn(dev, "Disabling sriov\n");
2144 pci_disable_sriov(pdev);
2145 }
Roland Dreier225c7b12007-05-08 18:00:38 -07002146
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002147 if (!mlx4_is_slave(dev))
2148 mlx4_free_ownership(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002149 kfree(priv);
Roland Dreiera01df0f2009-09-05 20:24:48 -07002150 pci_release_regions(pdev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002151 pci_disable_device(pdev);
2152 pci_set_drvdata(pdev, NULL);
2153 }
2154}
2155
Jack Morgensteinee49bd92007-07-12 17:50:45 +03002156int mlx4_restart_one(struct pci_dev *pdev)
2157{
2158 mlx4_remove_one(pdev);
Roland Dreier3d73c282007-10-10 15:43:54 -07002159 return __mlx4_init_one(pdev, NULL);
Jack Morgensteinee49bd92007-07-12 17:50:45 +03002160}
2161
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00002162static DEFINE_PCI_DEVICE_TABLE(mlx4_pci_table) = {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002163 /* MT25408 "Hermon" SDR */
2164 { PCI_VDEVICE(MELLANOX, 0x6340), 0 },
2165 /* MT25408 "Hermon" DDR */
2166 { PCI_VDEVICE(MELLANOX, 0x634a), 0 },
2167 /* MT25408 "Hermon" QDR */
2168 { PCI_VDEVICE(MELLANOX, 0x6354), 0 },
2169 /* MT25408 "Hermon" DDR PCIe gen2 */
2170 { PCI_VDEVICE(MELLANOX, 0x6732), 0 },
2171 /* MT25408 "Hermon" QDR PCIe gen2 */
2172 { PCI_VDEVICE(MELLANOX, 0x673c), 0 },
2173 /* MT25408 "Hermon" EN 10GigE */
2174 { PCI_VDEVICE(MELLANOX, 0x6368), 0 },
2175 /* MT25408 "Hermon" EN 10GigE PCIe gen2 */
2176 { PCI_VDEVICE(MELLANOX, 0x6750), 0 },
2177 /* MT25458 ConnectX EN 10GBASE-T 10GigE */
2178 { PCI_VDEVICE(MELLANOX, 0x6372), 0 },
2179 /* MT25458 ConnectX EN 10GBASE-T+Gen2 10GigE */
2180 { PCI_VDEVICE(MELLANOX, 0x675a), 0 },
2181 /* MT26468 ConnectX EN 10GigE PCIe gen2*/
2182 { PCI_VDEVICE(MELLANOX, 0x6764), 0 },
2183 /* MT26438 ConnectX EN 40GigE PCIe gen2 5GT/s */
2184 { PCI_VDEVICE(MELLANOX, 0x6746), 0 },
2185 /* MT26478 ConnectX2 40GigE PCIe gen2 */
2186 { PCI_VDEVICE(MELLANOX, 0x676e), 0 },
2187 /* MT25400 Family [ConnectX-2 Virtual Function] */
2188 { PCI_VDEVICE(MELLANOX, 0x1002), MLX4_VF },
2189 /* MT27500 Family [ConnectX-3] */
2190 { PCI_VDEVICE(MELLANOX, 0x1003), 0 },
2191 /* MT27500 Family [ConnectX-3 Virtual Function] */
2192 { PCI_VDEVICE(MELLANOX, 0x1004), MLX4_VF },
2193 { PCI_VDEVICE(MELLANOX, 0x1005), 0 }, /* MT27510 Family */
2194 { PCI_VDEVICE(MELLANOX, 0x1006), 0 }, /* MT27511 Family */
2195 { PCI_VDEVICE(MELLANOX, 0x1007), 0 }, /* MT27520 Family */
2196 { PCI_VDEVICE(MELLANOX, 0x1008), 0 }, /* MT27521 Family */
2197 { PCI_VDEVICE(MELLANOX, 0x1009), 0 }, /* MT27530 Family */
2198 { PCI_VDEVICE(MELLANOX, 0x100a), 0 }, /* MT27531 Family */
2199 { PCI_VDEVICE(MELLANOX, 0x100b), 0 }, /* MT27540 Family */
2200 { PCI_VDEVICE(MELLANOX, 0x100c), 0 }, /* MT27541 Family */
2201 { PCI_VDEVICE(MELLANOX, 0x100d), 0 }, /* MT27550 Family */
2202 { PCI_VDEVICE(MELLANOX, 0x100e), 0 }, /* MT27551 Family */
2203 { PCI_VDEVICE(MELLANOX, 0x100f), 0 }, /* MT27560 Family */
2204 { PCI_VDEVICE(MELLANOX, 0x1010), 0 }, /* MT27561 Family */
Roland Dreier225c7b12007-05-08 18:00:38 -07002205 { 0, }
2206};
2207
2208MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
2209
2210static struct pci_driver mlx4_driver = {
2211 .name = DRV_NAME,
2212 .id_table = mlx4_pci_table,
2213 .probe = mlx4_init_one,
2214 .remove = __devexit_p(mlx4_remove_one)
2215};
2216
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002217static int __init mlx4_verify_params(void)
2218{
2219 if ((log_num_mac < 0) || (log_num_mac > 7)) {
Joe Perches0a645e82010-07-10 07:22:46 +00002220 pr_warning("mlx4_core: bad num_mac: %d\n", log_num_mac);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002221 return -1;
2222 }
2223
Or Gerlitzcb296882011-10-16 10:26:21 +02002224 if (log_num_vlan != 0)
2225 pr_warning("mlx4_core: log_num_vlan - obsolete module param, using %d\n",
2226 MLX4_LOG_NUM_VLANS);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002227
Eli Cohen04986282010-09-20 08:42:38 +02002228 if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 7)) {
Joe Perches0a645e82010-07-10 07:22:46 +00002229 pr_warning("mlx4_core: bad log_mtts_per_seg: %d\n", log_mtts_per_seg);
Eli Cohenab6bf422009-05-27 14:38:34 -07002230 return -1;
2231 }
2232
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002233 /* Check if module param for ports type has legal combination */
2234 if (port_type_array[0] == false && port_type_array[1] == true) {
2235 printk(KERN_WARNING "Module parameter configuration ETH/IB is not supported. Switching to default configuration IB/IB\n");
2236 port_type_array[0] = true;
2237 }
2238
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002239 return 0;
2240}
2241
Roland Dreier225c7b12007-05-08 18:00:38 -07002242static int __init mlx4_init(void)
2243{
2244 int ret;
2245
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002246 if (mlx4_verify_params())
2247 return -EINVAL;
2248
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -07002249 mlx4_catas_init();
2250
2251 mlx4_wq = create_singlethread_workqueue("mlx4");
2252 if (!mlx4_wq)
2253 return -ENOMEM;
Jack Morgensteinee49bd92007-07-12 17:50:45 +03002254
Roland Dreier225c7b12007-05-08 18:00:38 -07002255 ret = pci_register_driver(&mlx4_driver);
2256 return ret < 0 ? ret : 0;
2257}
2258
2259static void __exit mlx4_cleanup(void)
2260{
2261 pci_unregister_driver(&mlx4_driver);
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -07002262 destroy_workqueue(mlx4_wq);
Roland Dreier225c7b12007-05-08 18:00:38 -07002263}
2264
2265module_init(mlx4_init);
2266module_exit(mlx4_cleanup);