blob: 2f4a26039e801270b5d634abe43bc6de5ab3309f [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
Jack Morgenstein3c439b52012-12-06 17:12:00 +000088int mlx4_log_num_mgm_entry_size = MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE;
Eugenia Emantayev0ec2c0f2011-12-13 04:16:02 +000089module_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:"
Jack Morgenstein3c439b52012-12-06 17:12:00 +000093 " 10 gives 248.range: 7 <="
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +000094 " log_num_mgm_entry_size <= 12."
Jack Morgenstein3c439b52012-12-06 17:12:00 +000095 " To activate device managed"
96 " flow steering when available, set to -1");
Eugenia Emantayev0ec2c0f2011-12-13 04:16:02 +000097
Or Gerlitz08ff3232012-10-21 14:59:24 +000098static bool enable_64b_cqe_eqe;
99module_param(enable_64b_cqe_eqe, bool, 0444);
100MODULE_PARM_DESC(enable_64b_cqe_eqe,
101 "Enable 64 byte CQEs/EQEs when the the FW supports this");
102
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000103#define HCA_GLOBAL_CAP_MASK 0
Or Gerlitz08ff3232012-10-21 14:59:24 +0000104
105#define PF_CONTEXT_BEHAVIOUR_MASK MLX4_FUNC_CAP_64B_EQE_CQE
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000106
Bill Pembertonf57e6842012-12-03 09:23:15 -0500107static char mlx4_version[] =
Roland Dreier225c7b12007-05-08 18:00:38 -0700108 DRV_NAME ": Mellanox ConnectX core driver v"
109 DRV_VERSION " (" DRV_RELDATE ")\n";
110
111static struct mlx4_profile default_profile = {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000112 .num_qp = 1 << 18,
Roland Dreier225c7b12007-05-08 18:00:38 -0700113 .num_srq = 1 << 16,
Jack Morgensteinc9f2ba52007-07-17 13:11:43 +0300114 .rdmarc_per_qp = 1 << 4,
Roland Dreier225c7b12007-05-08 18:00:38 -0700115 .num_cq = 1 << 16,
116 .num_mcg = 1 << 13,
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000117 .num_mpt = 1 << 19,
Marcel Apfelbaum9fd7a1e2012-01-19 09:45:31 +0000118 .num_mtt = 1 << 20, /* It is really num mtt segements */
Roland Dreier225c7b12007-05-08 18:00:38 -0700119};
120
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000121static int log_num_mac = 7;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700122module_param_named(log_num_mac, log_num_mac, int, 0444);
123MODULE_PARM_DESC(log_num_mac, "Log2 max number of MACs per ETH port (1-7)");
124
125static int log_num_vlan;
126module_param_named(log_num_vlan, log_num_vlan, int, 0444);
127MODULE_PARM_DESC(log_num_vlan, "Log2 max number of VLANs per ETH port (0-7)");
Or Gerlitzcb296882011-10-16 10:26:21 +0200128/* Log2 max number of VLANs per ETH port (0-7) */
129#define MLX4_LOG_NUM_VLANS 7
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700130
Rusty Russelleb939922011-12-19 14:08:01 +0000131static bool use_prio;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700132module_param_named(use_prio, use_prio, bool, 0444);
133MODULE_PARM_DESC(use_prio, "Enable steering by VLAN priority on ETH ports "
134 "(0/1, default 0)");
135
Marcel Apfelbaum2b8fb282011-12-13 04:16:56 +0000136int log_mtts_per_seg = ilog2(MLX4_MTT_ENTRY_PER_SEG);
Eli Cohenab6bf422009-05-27 14:38:34 -0700137module_param_named(log_mtts_per_seg, log_mtts_per_seg, int, 0444);
Eli Cohen04986282010-09-20 08:42:38 +0200138MODULE_PARM_DESC(log_mtts_per_seg, "Log2 number of MTT entries per segment (1-7)");
Eli Cohenab6bf422009-05-27 14:38:34 -0700139
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000140static int port_type_array[2] = {MLX4_PORT_TYPE_NONE, MLX4_PORT_TYPE_NONE};
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000141static int arr_argc = 2;
142module_param_array(port_type_array, int, &arr_argc, 0444);
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000143MODULE_PARM_DESC(port_type_array, "Array of port types: HW_DEFAULT (0) is default "
144 "1 for IB, 2 for Ethernet");
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000145
146struct 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 Petrilin27bf91d2009-03-18 19:45:11 -0700152int mlx4_check_port_params(struct mlx4_dev *dev,
153 enum mlx4_port_type *port_type)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700154{
155 int i;
156
157 for (i = 0; i < dev->caps.num_ports - 1; i++) {
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700158 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 Petrilin7ff93f82008-10-22 15:38:42 -0700164 }
165 }
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700166
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
177static void mlx4_set_port_mask(struct mlx4_dev *dev)
178{
179 int i;
180
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700181 for (i = 1; i <= dev->caps.num_ports; ++i)
Jack Morgenstein65dab252011-12-13 04:10:41 +0000182 dev->caps.port_mask[i] = dev->caps.port_type[i];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700183}
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +0000184
Roland Dreier3d73c282007-10-10 15:43:54 -0700185static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
Roland Dreier225c7b12007-05-08 18:00:38 -0700186{
187 int err;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700188 int i;
Roland Dreier225c7b12007-05-08 18:00:38 -0700189
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 Apfelbaum3fc929e2012-05-30 09:14:51 +0000218 dev->phys_caps.num_phys_eqs = MLX4_MAX_EQ_NUM;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700219 for (i = 1; i <= dev->caps.num_ports; ++i) {
220 dev->caps.vl_cap[i] = dev_cap->max_vl[i];
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -0700221 dev->caps.ib_mtu_cap[i] = dev_cap->ib_mtu[i];
Jack Morgenstein66349612012-06-19 11:21:44 +0300222 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 Dreier5ae2a7a2007-06-18 08:15:02 -0700226 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 Petrilinb79acb42008-10-22 10:56:48 -0700229 dev->caps.eth_mtu_cap[i] = dev_cap->eth_mtu[i];
230 dev->caps.def_mac[i] = dev_cap->def_mac[i];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700231 dev->caps.supported_type[i] = dev_cap->supported_port_types[i];
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000232 dev->caps.suggested_type[i] = dev_cap->suggested_type[i];
233 dev->caps.default_sense[i] = dev_cap->default_sense[i];
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000234 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 Dreier5ae2a7a2007-06-18 08:15:02 -0700238 }
239
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000240 dev->caps.uar_page_size = PAGE_SIZE;
Roland Dreier225c7b12007-05-08 18:00:38 -0700241 dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE;
Roland Dreier225c7b12007-05-08 18:00:38 -0700242 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 Dreier225c7b12007-05-08 18:00:38 -0700249 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 Dreier225c7b12007-05-08 18:00:38 -0700254 /*
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 Apfelbaum2b8fb282011-12-13 04:16:56 +0000262 dev->caps.reserved_mtts = dev_cap->reserved_mtts;
Roland Dreier225c7b12007-05-08 18:00:38 -0700263 dev->caps.reserved_mrws = dev_cap->reserved_mrws;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000264
265 /* The first 128 UARs are used for EQ doorbells */
266 dev->caps.reserved_uars = max_t(int, 128, dev_cap->reserved_uars);
Roland Dreier225c7b12007-05-08 18:00:38 -0700267 dev->caps.reserved_pds = dev_cap->reserved_pds;
Sean Hefty012a8ff2011-06-02 09:01:33 -0700268 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 Apfelbaum2b8fb282011-12-13 04:16:56 +0000272 dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz;
273
Dotan Barak149983af2007-06-26 15:55:28 +0300274 dev->caps.max_msg_sz = dev_cap->max_msg_sz;
Roland Dreier225c7b12007-05-08 18:00:38 -0700275 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
276 dev->caps.flags = dev_cap->flags;
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300277 dev->caps.flags2 = dev_cap->flags2;
Roland Dreier95d04f02008-07-23 08:12:26 -0700278 dev->caps.bmme_flags = dev_cap->bmme_flags;
279 dev->caps.reserved_lkey = dev_cap->reserved_lkey;
Roland Dreier225c7b12007-05-08 18:00:38 -0700280 dev->caps.stat_rate_support = dev_cap->stat_rate_support;
Eli Cohenb832be12008-04-16 21:09:27 -0700281 dev->caps.max_gso_sz = dev_cap->max_gso_sz;
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300282 dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz;
Roland Dreier225c7b12007-05-08 18:00:38 -0700283
Roland Dreierca3e57a2012-09-27 09:53:05 -0700284 /* 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 Petrilin58a60162011-12-19 04:00:26 +0000286 dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT;
Roland Dreieraadf4f32012-09-27 10:01:19 -0700287 /* 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 Petrilin58a60162011-12-19 04:00:26 +0000290
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700291 dev->caps.log_num_macs = log_num_mac;
Or Gerlitzcb296882011-10-16 10:26:21 +0200292 dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700293 dev->caps.log_num_prios = use_prio ? 3 : 0;
294
295 for (i = 1; i <= dev->caps.num_ports; ++i) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000296 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 Morgenstein105c3202012-06-19 11:21:43 +0300301 /* if only IB is supported, assign IB */
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000302 else if (dev->caps.supported_type[i] ==
Jack Morgenstein105c3202012-06-19 11:21:43 +0300303 MLX4_PORT_TYPE_IB)
304 dev->caps.port_type[i] = MLX4_PORT_TYPE_IB;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000305 else {
Jack Morgenstein105c3202012-06-19 11:21:43 +0300306 /* 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 Petrilin8d0fc7b2011-12-19 04:00:34 +0000310 dev->caps.port_type[i] = dev->caps.suggested_type[i] ?
311 MLX4_PORT_TYPE_ETH : MLX4_PORT_TYPE_IB;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000312 else
Jack Morgenstein105c3202012-06-19 11:21:43 +0300313 dev->caps.port_type[i] = port_type_array[i - 1];
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000314 }
315 }
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000316 /*
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 Petrilin27bf91d2009-03-18 19:45:11 -0700322 mlx4_priv(dev)->sense.sense_allowed[i] =
Yevgeny Petrilin58a60162011-12-19 04:00:26 +0000323 ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) &&
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000324 (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
Yevgeny Petrilin58a60162011-12-19 04:00:26 +0000325 (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT));
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700326
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000327 /*
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 Petrilin46c46742011-12-29 07:42:34 +0000332 if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) {
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000333 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 Petrilin93fc9e12008-10-22 10:25:29 -0700342 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 Gerlitzf2a3f6a2011-06-15 14:47:14 +0000356 dev->caps.max_counters = 1 << ilog2(dev_cap->max_counters);
357
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700358 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 Morgensteine2c76822012-08-03 08:40:41 +0000372 dev->caps.sqp_demux = (mlx4_is_master(dev)) ? MLX4_MAX_NUM_SLAVES : 0;
Or Gerlitz08ff3232012-10-21 14:59:24 +0000373
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 Gerlitzf97b4b52013-01-10 15:18:35 +0000383 if ((dev->caps.flags &
Or Gerlitz08ff3232012-10-21 14:59:24 +0000384 (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 Dreier225c7b12007-05-08 18:00:38 -0700388 return 0;
389}
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000390/*The function checks if there are live vf, return the num of them*/
391static 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 Morgenstein396f2fe2012-06-19 11:21:42 +0300410int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey)
411{
412 u32 qk = MLX4_RESERVED_QKEY_BASE;
Jack Morgenstein47605df2012-08-03 08:40:57 +0000413
414 if (qpn >= dev->phys_caps.base_tunnel_sqpn + 8 * MLX4_MFUNC_MAX ||
415 qpn < dev->phys_caps.base_proxy_sqpn)
Jack Morgenstein396f2fe2012-06-19 11:21:42 +0300416 return -EINVAL;
417
Jack Morgenstein47605df2012-08-03 08:40:57 +0000418 if (qpn >= dev->phys_caps.base_tunnel_sqpn)
Jack Morgenstein396f2fe2012-06-19 11:21:42 +0300419 /* tunnel qp */
Jack Morgenstein47605df2012-08-03 08:40:57 +0000420 qk += qpn - dev->phys_caps.base_tunnel_sqpn;
Jack Morgenstein396f2fe2012-06-19 11:21:42 +0300421 else
Jack Morgenstein47605df2012-08-03 08:40:57 +0000422 qk += qpn - dev->phys_caps.base_proxy_sqpn;
Jack Morgenstein396f2fe2012-06-19 11:21:42 +0300423 *qkey = qk;
424 return 0;
425}
426EXPORT_SYMBOL(mlx4_get_parav_qkey);
427
Jack Morgenstein54679e12012-08-03 08:40:43 +0000428void 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}
437EXPORT_SYMBOL(mlx4_sync_pkey_table);
438
Jack Morgensteinafa8fd12012-08-03 08:40:56 +0000439void 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}
448EXPORT_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}
459EXPORT_SYMBOL(mlx4_get_slave_node_guid);
460
Roland Dreiere10903b2012-02-26 01:48:12 -0800461int mlx4_is_slave_active(struct mlx4_dev *dev, int slave)
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000462{
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}
472EXPORT_SYMBOL(mlx4_is_slave_active);
473
Jack Morgenstein7b8157b2012-12-06 17:11:59 +0000474static 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 Morgensteinab9c17a2011-12-13 04:18:30 +0000491static 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 Emantayevddd8a6c2013-04-23 06:06:48 +0000516 dev->caps.hca_core_clock = hca_param.hca_core_clock;
517
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000518 memset(&dev_cap, 0, sizeof(dev_cap));
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +0000519 dev->caps.max_qp_dest_rdma = 1 << hca_param.log_rd_per_qp;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000520 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 Morgensteinb91cb3e2012-05-30 09:14:53 +0000526 err = mlx4_QUERY_FW(dev);
527 if (err)
528 mlx4_err(dev, "QUERY_FW command failed: could not get FW version.\n");
529
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000530 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 Morgenstein47605df2012-08-03 08:40:57 +0000550 err = mlx4_QUERY_FUNC_CAP(dev, 0, &func_cap);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000551 if (err) {
Jack Morgenstein47605df2012-08-03 08:40:57 +0000552 mlx4_err(dev, "QUERY_FUNC_CAP general command failed, aborting (%d).\n",
553 err);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000554 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 Morgensteinab9c17a2011-12-13 04:18:30 +0000563 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 Morgensteinab9c17a2011-12-13 04:18:30 +0000575 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 Morgenstein47605df2012-08-03 08:40:57 +0000581 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 Morgenstein66349612012-06-19 11:21:44 +0300592 for (i = 1; i <= dev->caps.num_ports; ++i) {
Jack Morgenstein47605df2012-08-03 08:40:57 +0000593 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 Morgenstein6230bb22012-05-30 09:14:54 +0000603 dev->caps.port_mask[i] = dev->caps.port_type[i];
Jack Morgenstein66349612012-06-19 11:21:44 +0300604 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 Morgenstein47605df2012-08-03 08:40:57 +0000607 goto err_mem;
Jack Morgenstein66349612012-06-19 11:21:44 +0300608 }
Jack Morgenstein6230bb22012-05-30 09:14:54 +0000609
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000610 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 Morgenstein47605df2012-08-03 08:40:57 +0000617 goto err_mem;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000618 }
619
Or Gerlitz08ff3232012-10-21 14:59:24 +0000620 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 Morgenstein7b8157b2012-12-06 17:11:59 +0000635 slave_adjust_steering_mode(dev, &dev_cap, &hca_param);
636
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000637 return 0;
Jack Morgenstein47605df2012-08-03 08:40:57 +0000638
639err_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 Morgensteinab9c17a2011-12-13 04:18:30 +0000648}
Roland Dreier225c7b12007-05-08 18:00:38 -0700649
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700650/*
651 * Change the port configuration of the device.
652 * Every user of this function must hold the port mutex.
653 */
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700654int mlx4_change_port_types(struct mlx4_dev *dev,
655 enum mlx4_port_type *port_types)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700656{
657 int err = 0;
658 int change = 0;
659 int port;
660
661 for (port = 0; port < dev->caps.num_ports; port++) {
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700662 /* Change the port type only if the new type is different
663 * from the current, and not set to Auto */
Yevgeny Petrilin3d8f9302012-02-21 03:41:07 +0000664 if (port_types[port] != dev->caps.port_type[port + 1])
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700665 change = 1;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700666 }
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 Petrilin1e0f03d2012-02-23 07:04:35 +0000671 dev->caps.port_type[port] = port_types[port - 1];
Jack Morgenstein66349612012-06-19 11:21:44 +0300672 err = mlx4_SET_PORT(dev, port, -1);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700673 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
683out:
684 return err;
685}
686
687static 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 Petrilin27bf91d2009-03-18 19:45:11 -0700694 char type[8];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700695
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700696 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 Petrilin7ff93f82008-10-22 15:38:42 -0700705}
706
707static 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 Petrilin27bf91d2009-03-18 19:45:11 -0700716 enum mlx4_port_type new_types[MLX4_MAX_PORTS];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700717 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 Petrilin27bf91d2009-03-18 19:45:11 -0700724 else if (!strcmp(buf, "auto\n"))
725 info->tmp_type = MLX4_PORT_TYPE_AUTO;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700726 else {
727 mlx4_err(mdev, "%s is not supported port type\n", buf);
728 return -EINVAL;
729 }
730
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700731 mlx4_stop_sense(mdev);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700732 mutex_lock(&priv->port_mutex);
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700733 /* Possible type is always the one that was delivered */
734 mdev->caps.possible_type[info->port] = info->tmp_type;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700735
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700736 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 Petrilin58a60162011-12-19 04:00:26 +0000743 if (!(mdev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
744 !(mdev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)) {
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700745 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 Petrilin7ff93f82008-10-22 15:38:42 -0700762 if (err)
763 goto out;
764
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700765 /* 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 Petrilin7ff93f82008-10-22 15:38:42 -0700770
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700771 err = mlx4_change_port_types(mdev, new_types);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700772
773out:
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700774 mlx4_start_sense(mdev);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700775 mutex_unlock(&priv->port_mutex);
776 return err ? err : count;
777}
778
Or Gerlitz096335b2012-01-11 19:02:17 +0200779enum 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
787static 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
799static 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
811static 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
827static 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 Morgenstein66349612012-06-19 11:21:44 +0300858 err = mlx4_SET_PORT(mdev, port, -1);
Or Gerlitz096335b2012-01-11 19:02:17 +0200859 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);
866err_set_port:
867 mutex_unlock(&priv->port_mutex);
868 mlx4_start_sense(mdev);
869 return err ? err : count;
870}
871
Roland Dreiere8f9b2e2008-02-04 20:20:41 -0800872static int mlx4_load_fw(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -0700873{
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 Morgenstein5b0bf5e2007-08-01 12:28:20 +0300878 GFP_HIGHUSER | __GFP_NOWARN, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700879 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
898err_unmap_fa:
899 mlx4_UNMAP_FA(dev);
900
901err_free:
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300902 mlx4_free_icm(dev, priv->fw.fw_icm, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700903 return err;
904}
905
Roland Dreiere8f9b2e2008-02-04 20:20:41 -0800906static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
907 int cmpt_entry_sz)
Roland Dreier225c7b12007-05-08 18:00:38 -0700908{
909 struct mlx4_priv *priv = mlx4_priv(dev);
910 int err;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000911 int num_eqs;
Roland Dreier225c7b12007-05-08 18:00:38 -0700912
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 Petrilin93fc9e12008-10-22 10:25:29 -0700918 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
919 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700920 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 Morgenstein5b0bf5e2007-08-01 12:28:20 +0300928 dev->caps.reserved_srqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700929 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 Morgenstein5b0bf5e2007-08-01 12:28:20 +0300937 dev->caps.reserved_cqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700938 if (err)
939 goto err_srq;
940
Marcel Apfelbaum3fc929e2012-05-30 09:14:51 +0000941 num_eqs = (mlx4_is_master(dev)) ? dev->phys_caps.num_phys_eqs :
942 dev->caps.num_eqs;
Roland Dreier225c7b12007-05-08 18:00:38 -0700943 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 Morgensteinab9c17a2011-12-13 04:18:30 +0000947 cmpt_entry_sz, num_eqs, num_eqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700948 if (err)
949 goto err_cq;
950
951 return 0;
952
953err_cq:
954 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
955
956err_srq:
957 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
958
959err_qp:
960 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
961
962err:
963 return err;
964}
965
Roland Dreier3d73c282007-10-10 15:43:54 -0700966static 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 Dreier225c7b12007-05-08 18:00:38 -0700968{
969 struct mlx4_priv *priv = mlx4_priv(dev);
970 u64 aux_pages;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +0000971 int num_eqs;
Roland Dreier225c7b12007-05-08 18:00:38 -0700972 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 Morgenstein5b0bf5e2007-08-01 12:28:20 +0300985 GFP_HIGHUSER | __GFP_NOWARN, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -0700986 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 Morgensteinab9c17a2011-12-13 04:18:30 +00001003
Marcel Apfelbaum3fc929e2012-05-30 09:14:51 +00001004 num_eqs = (mlx4_is_master(dev)) ? dev->phys_caps.num_phys_eqs :
1005 dev->caps.num_eqs;
Roland Dreierfa0681d2009-09-05 20:24:49 -07001006 err = mlx4_init_icm_table(dev, &priv->eq_table.table,
1007 init_hca->eqc_base, dev_cap->eqc_entry_sz,
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001008 num_eqs, num_eqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001009 if (err) {
1010 mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
1011 goto err_unmap_cmpt;
1012 }
1013
Jack Morgensteind7bb58f2007-08-01 12:28:53 +03001014 /*
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 Dreier225c7b12007-05-08 18:00:38 -07001025 err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
1026 init_hca->mtt_base,
1027 dev->caps.mtt_entry_sz,
Marcel Apfelbaum2b8fb282011-12-13 04:16:56 +00001028 dev->caps.num_mtts,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +03001029 dev->caps.reserved_mtts, 1, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001030 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 Morgenstein5b0bf5e2007-08-01 12:28:20 +03001039 dev->caps.reserved_mrws, 1, 1);
Roland Dreier225c7b12007-05-08 18:00:38 -07001040 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 Petrilin93fc9e12008-10-22 10:25:29 -07001049 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
1050 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001051 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 Petrilin93fc9e12008-10-22 10:25:29 -07001060 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
1061 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001062 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 Petrilin93fc9e12008-10-22 10:25:29 -07001071 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
1072 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001073 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 Petrilin93fc9e12008-10-22 10:25:29 -07001082 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
1083 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001084 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 Morgenstein5b0bf5e2007-08-01 12:28:20 +03001093 dev->caps.reserved_cqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001094 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 Morgenstein5b0bf5e2007-08-01 12:28:20 +03001103 dev->caps.reserved_srqs, 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001104 if (err) {
1105 mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
1106 goto err_unmap_cq;
1107 }
1108
1109 /*
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001110 * 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 Dreier225c7b12007-05-08 18:00:38 -07001115 */
1116 err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
Eugenia Emantayev0ec2c0f2011-12-13 04:16:02 +00001117 init_hca->mc_base,
1118 mlx4_get_mgm_entry_size(dev),
Roland Dreier225c7b12007-05-08 18:00:38 -07001119 dev->caps.num_mgms + dev->caps.num_amgms,
1120 dev->caps.num_mgms + dev->caps.num_amgms,
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +03001121 0, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001122 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
1129err_unmap_srq:
1130 mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
1131
1132err_unmap_cq:
1133 mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
1134
1135err_unmap_rdmarc:
1136 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
1137
1138err_unmap_altc:
1139 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
1140
1141err_unmap_auxc:
1142 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
1143
1144err_unmap_qp:
1145 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
1146
1147err_unmap_dmpt:
1148 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
1149
1150err_unmap_mtt:
1151 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
1152
1153err_unmap_eq:
Roland Dreierfa0681d2009-09-05 20:24:49 -07001154 mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
Roland Dreier225c7b12007-05-08 18:00:38 -07001155
1156err_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
1162err_unmap_aux:
1163 mlx4_UNMAP_ICM_AUX(dev);
1164
1165err_free_aux:
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +03001166 mlx4_free_icm(dev, priv->fw.aux_icm, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001167
1168 return err;
1169}
1170
1171static 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 Dreierfa0681d2009-09-05 20:24:49 -07001184 mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
Roland Dreier225c7b12007-05-08 18:00:38 -07001185 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 Dreier225c7b12007-05-08 18:00:38 -07001189
1190 mlx4_UNMAP_ICM_AUX(dev);
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +03001191 mlx4_free_icm(dev, priv->fw.aux_icm, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001192}
1193
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001194static void mlx4_slave_exit(struct mlx4_dev *dev)
1195{
1196 struct mlx4_priv *priv = mlx4_priv(dev);
1197
Roland Dreierf3d4c892012-09-25 21:24:07 -07001198 mutex_lock(&priv->cmd.slave_cmd_mutex);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001199 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_TIME))
1200 mlx4_warn(dev, "Failed to close slave function.\n");
Roland Dreierf3d4c892012-09-25 21:24:07 -07001201 mutex_unlock(&priv->cmd.slave_cmd_mutex);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001202}
1203
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001204static 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 Morgenstein3d747472012-02-19 21:38:52 +00001211 if (!dev->caps.bf_reg_size)
1212 return -ENXIO;
1213
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001214 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 Cohenc1b43dc2011-03-22 22:38:41 +00001218 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
1225static 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 Vadaiec693d42013-04-23 06:06:49 +00001231cycle_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}
1250EXPORT_SYMBOL_GPL(mlx4_read_clock);
1251
1252
Eugenia Emantayevddd8a6c2013-04-23 06:06:48 +00001253static 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
1267static 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 Dreier225c7b12007-05-08 18:00:38 -07001275static void mlx4_close_hca(struct mlx4_dev *dev)
1276{
Eugenia Emantayevddd8a6c2013-04-23 06:06:48 +00001277 unmap_internal_clock(dev);
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001278 unmap_bf_area(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001279 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
1289static 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 Morgensteinab9c17a2011-12-13 04:18:30 +00001293 int ret_from_reset = 0;
1294 u32 slave_read;
1295 u32 cmd_channel_ver;
1296
Roland Dreierf3d4c892012-09-25 21:24:07 -07001297 mutex_lock(&priv->cmd.slave_cmd_mutex);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001298 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 Morgenstein5efe5352013-06-04 05:13:27 +00001306 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 Morgensteinab9c17a2011-12-13 04:18:30 +00001310 } 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 Dreierf3d4c892012-09-25 21:24:07 -07001338
1339 mutex_unlock(&priv->cmd.slave_cmd_mutex);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001340 return 0;
1341
1342err:
1343 mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, 0);
Roland Dreierf3d4c892012-09-25 21:24:07 -07001344 mutex_unlock(&priv->cmd.slave_cmd_mutex);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001345 return -EIO;
Roland Dreier225c7b12007-05-08 18:00:38 -07001346}
1347
Jack Morgenstein66349612012-06-19 11:21:44 +03001348static 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 Morgenstein3c439b52012-12-06 17:12:00 +00001359static 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 Morgenstein7b8157b2012-12-06 17:11:59 +00001372static void choose_steering_mode(struct mlx4_dev *dev,
1373 struct mlx4_dev_cap *dev_cap)
1374{
Jack Morgenstein3c439b52012-12-06 17:12:00 +00001375 if (mlx4_log_num_mgm_entry_size == -1 &&
1376 dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_FS_EN &&
Jack Morgenstein7b8157b2012-12-06 17:11:59 +00001377 (!mlx4_is_mfunc(dev) ||
Jack Morgenstein3c439b52012-12-06 17:12:00 +00001378 (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 Morgenstein7b8157b2012-12-06 17:11:59 +00001383 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 Morgenstein3c439b52012-12-06 17:12:00 +00001399 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 Morgenstein7b8157b2012-12-06 17:11:59 +00001403 dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev);
1404 }
Jack Morgenstein3c439b52012-12-06 17:12:00 +00001405 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 Morgenstein7b8157b2012-12-06 17:11:59 +00001410}
1411
Roland Dreier3d73c282007-10-10 15:43:54 -07001412static int mlx4_init_hca(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -07001413{
1414 struct mlx4_priv *priv = mlx4_priv(dev);
1415 struct mlx4_adapter adapter;
1416 struct mlx4_dev_cap dev_cap;
Vladimir Sokolovsky2d928652008-07-14 23:48:53 -07001417 struct mlx4_mod_stat_cfg mlx4_cfg;
Roland Dreier225c7b12007-05-08 18:00:38 -07001418 struct mlx4_profile profile;
1419 struct mlx4_init_hca_param init_hca;
1420 u64 icm_size;
1421 int err;
1422
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001423 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 Yehezkelbef772e2012-09-05 22:50:51 +00001430 return err;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001431 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001432
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001433 err = mlx4_load_fw(dev);
1434 if (err) {
1435 mlx4_err(dev, "Failed to start FW, aborting.\n");
Aviad Yehezkelbef772e2012-09-05 22:50:51 +00001436 return err;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001437 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001438
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001439 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 Sokolovsky2d928652008-07-14 23:48:53 -07001444
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001445 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 Dreier225c7b12007-05-08 18:00:38 -07001450
Jack Morgenstein7b8157b2012-12-06 17:11:59 +00001451 choose_steering_mode(dev, &dev_cap);
1452
Jack Morgenstein66349612012-06-19 11:21:44 +03001453 if (mlx4_is_master(dev))
1454 mlx4_parav_master_pf_caps(dev);
1455
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001456 profile = default_profile;
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001457 if (dev->caps.steering_mode ==
1458 MLX4_STEERING_MODE_DEVICE_MANAGED)
1459 profile.num_mcg = MLX4_FS_NUM_MCG;
Roland Dreier225c7b12007-05-08 18:00:38 -07001460
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001461 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 Cohena5bbe892012-02-09 18:10:06 +02001468 dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1;
1469
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001470 init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
1471 init_hca.uar_page_sz = PAGE_SHIFT - 12;
Shani Michaelie4488342013-02-06 16:19:11 +00001472 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 Morgensteinab9c17a2011-12-13 04:18:30 +00001476
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 Emantayevddd8a6c2013-04-23 06:06:48 +00001486 /*
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 Morgensteinab9c17a2011-12-13 04:18:30 +00001517 } else {
1518 err = mlx4_init_slave(dev);
1519 if (err) {
Jack Morgenstein5efe5352013-06-04 05:13:27 +00001520 if (err != -EPROBE_DEFER)
1521 mlx4_err(dev, "Failed to initialize slave\n");
Aviad Yehezkelbef772e2012-09-05 22:50:51 +00001522 return err;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001523 }
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 Dreier225c7b12007-05-08 18:00:38 -07001530 }
1531
Eli Cohenc1b43dc2011-03-22 22:38:41 +00001532 if (map_bf_area(dev))
1533 mlx4_dbg(dev, "Failed to map blue flame area\n");
1534
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001535 /*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 Dreier225c7b12007-05-08 18:00:38 -07001538
1539 err = mlx4_QUERY_ADAPTER(dev, &adapter);
1540 if (err) {
1541 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
Aviad Yehezkelbef772e2012-09-05 22:50:51 +00001542 goto unmap_bf;
Roland Dreier225c7b12007-05-08 18:00:38 -07001543 }
1544
1545 priv->eq_table.inta_pin = adapter.inta_pin;
Jack Morgensteincd9281d2007-09-18 09:14:18 +02001546 memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id);
Roland Dreier225c7b12007-05-08 18:00:38 -07001547
1548 return 0;
1549
Aviad Yehezkelbef772e2012-09-05 22:50:51 +00001550unmap_bf:
Eugenia Emantayevddd8a6c2013-04-23 06:06:48 +00001551 unmap_internal_clock(dev);
Aviad Yehezkelbef772e2012-09-05 22:50:51 +00001552 unmap_bf_area(dev);
1553
Roland Dreier225c7b12007-05-08 18:00:38 -07001554err_close:
Dotan Barak41929ed2012-10-21 14:59:23 +00001555 if (mlx4_is_slave(dev))
1556 mlx4_slave_exit(dev);
1557 else
1558 mlx4_CLOSE_HCA(dev, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001559
1560err_free_icm:
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001561 if (!mlx4_is_slave(dev))
1562 mlx4_free_icms(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001563
1564err_stop_fw:
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001565 if (!mlx4_is_slave(dev)) {
1566 mlx4_UNMAP_FA(dev);
1567 mlx4_free_icm(dev, priv->fw.fw_icm, 0);
1568 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001569 return err;
1570}
1571
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001572static 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
1584static void mlx4_cleanup_counters_table(struct mlx4_dev *dev)
1585{
1586 mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap);
1587}
1588
Jack Morgensteinba062d52012-05-15 10:35:03 +00001589int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx)
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001590{
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 Morgensteinba062d52012-05-15 10:35:03 +00001602
1603int 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 Gerlitzf2a3f6a2011-06-15 14:47:14 +00001619EXPORT_SYMBOL_GPL(mlx4_counter_alloc);
1620
Jack Morgensteinba062d52012-05-15 10:35:03 +00001621void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx)
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001622{
1623 mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx);
1624 return;
1625}
Jack Morgensteinba062d52012-05-15 10:35:03 +00001626
1627void mlx4_counter_free(struct mlx4_dev *dev, u32 idx)
1628{
Jack Morgensteine7dbeba2013-03-07 03:46:54 +00001629 u64 in_param = 0;
Jack Morgensteinba062d52012-05-15 10:35:03 +00001630
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 Gerlitzf2a3f6a2011-06-15 14:47:14 +00001640EXPORT_SYMBOL_GPL(mlx4_counter_free);
1641
Roland Dreier3d73c282007-10-10 15:43:54 -07001642static int mlx4_setup_hca(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -07001643{
1644 struct mlx4_priv *priv = mlx4_priv(dev);
1645 int err;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001646 int port;
Jack Morgenstein9a5aa622008-11-28 21:29:46 -08001647 __be32 ib_port_default_caps;
Roland Dreier225c7b12007-05-08 18:00:38 -07001648
Roland Dreier225c7b12007-05-08 18:00:38 -07001649 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 Dreier4979d182011-01-12 09:50:36 -08001663 priv->kar = ioremap((phys_addr_t) priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001664 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 Hefty012a8ff2011-06-02 09:01:33 -07001678 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 Dreier225c7b12007-05-08 18:00:38 -07001685 err = mlx4_init_mr_table(dev);
1686 if (err) {
1687 mlx4_err(dev, "Failed to initialize "
1688 "memory region table, aborting.\n");
Sean Hefty012a8ff2011-06-02 09:01:33 -07001689 goto err_xrcd_table_free;
Roland Dreier225c7b12007-05-08 18:00:38 -07001690 }
1691
Roland Dreier225c7b12007-05-08 18:00:38 -07001692 err = mlx4_init_eq_table(dev);
1693 if (err) {
1694 mlx4_err(dev, "Failed to initialize "
1695 "event queue table, aborting.\n");
Jack Morgensteinee49bd92007-07-12 17:50:45 +03001696 goto err_mr_table_free;
Roland Dreier225c7b12007-05-08 18:00:38 -07001697 }
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. Tsirkin08fb1052007-08-07 16:08:28 +03001708 if (dev->flags & MLX4_FLAG_MSI_X) {
1709 mlx4_warn(dev, "NOP command failed to generate MSI-X "
1710 "interrupt IRQ %d).\n",
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001711 priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03001712 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 Petrilinb8dd7862008-12-22 07:15:03 -08001716 priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
Roland Dreier225c7b12007-05-08 18:00:38 -07001717 mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03001718 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001719
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 Morgensteinab9c17a2011-12-13 04:18:30 +00001746 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 Dreier225c7b12007-05-08 18:00:38 -07001753 }
1754
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001755 err = mlx4_init_counters_table(dev);
1756 if (err && err != -ENOENT) {
1757 mlx4_err(dev, "Failed to initialize counters table, aborting.\n");
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001758 goto err_mcg_table_free;
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001759 }
1760
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001761 if (!mlx4_is_slave(dev)) {
1762 for (port = 1; port <= dev->caps.num_ports; port++) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001763 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 Apfelbaum97285b72011-10-24 11:02:34 +02001771
Jack Morgenstein2aca1172012-06-19 11:21:41 +03001772 /* 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 Gerlitz096335b2012-01-11 19:02:17 +02001783 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 Apfelbaum97285b72011-10-24 11:02:34 +02001787
Jack Morgenstein66349612012-06-19 11:21:44 +03001788 err = mlx4_SET_PORT(dev, port, mlx4_is_master(dev) ?
1789 dev->caps.pkey_table_len[port] : -1);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001790 if (err) {
1791 mlx4_err(dev, "Failed to set port %d, aborting\n",
1792 port);
1793 goto err_counters_table_free;
1794 }
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001795 }
1796 }
1797
Roland Dreier225c7b12007-05-08 18:00:38 -07001798 return 0;
1799
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001800err_counters_table_free:
1801 mlx4_cleanup_counters_table(dev);
1802
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001803err_mcg_table_free:
1804 mlx4_cleanup_mcg_table(dev);
1805
Roland Dreier225c7b12007-05-08 18:00:38 -07001806err_qp_table_free:
1807 mlx4_cleanup_qp_table(dev);
1808
1809err_srq_table_free:
1810 mlx4_cleanup_srq_table(dev);
1811
1812err_cq_table_free:
1813 mlx4_cleanup_cq_table(dev);
1814
1815err_cmd_poll:
1816 mlx4_cmd_use_polling(dev);
1817
1818err_eq_table_free:
1819 mlx4_cleanup_eq_table(dev);
1820
Jack Morgensteinee49bd92007-07-12 17:50:45 +03001821err_mr_table_free:
Roland Dreier225c7b12007-05-08 18:00:38 -07001822 mlx4_cleanup_mr_table(dev);
1823
Sean Hefty012a8ff2011-06-02 09:01:33 -07001824err_xrcd_table_free:
1825 mlx4_cleanup_xrcd_table(dev);
1826
Roland Dreier225c7b12007-05-08 18:00:38 -07001827err_pd_table_free:
1828 mlx4_cleanup_pd_table(dev);
1829
1830err_kar_unmap:
1831 iounmap(priv->kar);
1832
1833err_uar_free:
1834 mlx4_uar_free(dev, &priv->driver_uar);
1835
1836err_uar_table_free:
1837 mlx4_cleanup_uar_table(dev);
1838 return err;
1839}
1840
Roland Dreiere8f9b2e2008-02-04 20:20:41 -08001841static void mlx4_enable_msi_x(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -07001842{
1843 struct mlx4_priv *priv = mlx4_priv(dev);
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001844 struct msix_entry *entries;
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001845 int nreq = min_t(int, dev->caps.num_ports *
Yuval Mintz90b1ebe2012-07-01 03:18:51 +00001846 min_t(int, netif_get_num_default_rss_queues() + 1,
1847 MAX_MSIX_P_PORT) + MSIX_LEGACY_SZ, MAX_MSIX);
Roland Dreier225c7b12007-05-08 18:00:38 -07001848 int err;
1849 int i;
1850
1851 if (msi_x) {
Or Gerlitzca4c7b32013-01-17 05:30:43 +00001852 nreq = min_t(int, dev->caps.num_eqs - dev->caps.reserved_eqs,
1853 nreq);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001854
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001855 entries = kcalloc(nreq, sizeof *entries, GFP_KERNEL);
1856 if (!entries)
1857 goto no_msi;
1858
1859 for (i = 0; i < nreq; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001860 entries[i].entry = i;
1861
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001862 retry:
1863 err = pci_enable_msix(dev->pdev, entries, nreq);
Roland Dreier225c7b12007-05-08 18:00:38 -07001864 if (err) {
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001865 /* 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-Chaisemartin5bf0da72009-04-21 10:11:06 -07001873 kfree(entries);
Roland Dreier225c7b12007-05-08 18:00:38 -07001874 goto no_msi;
1875 }
1876
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001877 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 Petrilinb8dd7862008-12-22 07:15:03 -08001886 for (i = 0; i < nreq; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001887 priv->eq_table.eq[i].irq = entries[i].vector;
1888
1889 dev->flags |= MLX4_FLAG_MSI_X;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001890
1891 kfree(entries);
Roland Dreier225c7b12007-05-08 18:00:38 -07001892 return;
1893 }
1894
1895no_msi:
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001896 dev->caps.num_comp_vectors = 1;
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001897 dev->caps.comp_pool = 0;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001898
1899 for (i = 0; i < 2; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001900 priv->eq_table.eq[i].irq = dev->pdev->irq;
1901}
1902
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001903static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07001904{
1905 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001906 int err = 0;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07001907
1908 info->dev = dev;
1909 info->port = port;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001910 if (!mlx4_is_slave(dev)) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001911 mlx4_init_mac_table(dev, &info->mac_table);
1912 mlx4_init_vlan_table(dev, &info->vlan_table);
Yan Burman16a10ff2013-02-07 02:25:22 +00001913 info->base_qpn = mlx4_get_base_qpn(dev, port);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001914 }
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001915
1916 sprintf(info->dev_name, "mlx4_port%d", port);
1917 info->port_attr.attr.name = info->dev_name;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001918 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 Petrilin7ff93f82008-10-22 15:38:42 -07001924 info->port_attr.show = show_port_type;
Greg Kroah-Hartman3691c9642010-03-15 14:01:55 -07001925 sysfs_attr_init(&info->port_attr.attr);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07001926
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 Gerlitz096335b2012-01-11 19:02:17 +02001933 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 Petrilin7ff93f82008-10-22 15:38:42 -07001951 return err;
1952}
1953
1954static 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 Gerlitz096335b2012-01-11 19:02:17 +02001960 device_remove_file(&info->dev->pdev->dev, &info->port_mtu_attr);
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07001961}
1962
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00001963static 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 Emantayev45b51362012-02-14 06:37:41 +00001973 for (i = 0; i < num_entries; i++)
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00001974 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 Petrilinb12d93d2011-03-22 22:38:24 +00001978 return 0;
1979}
1980
1981static 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 Morgensteinab9c17a2011-12-13 04:18:30 +00002014static 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
2022static int mlx4_get_ownership(struct mlx4_dev *dev)
2023{
2024 void __iomem *owner;
2025 u32 ret;
2026
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +00002027 if (pci_channel_offline(dev->pdev))
2028 return -EIO;
2029
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002030 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
2042static void mlx4_free_ownership(struct mlx4_dev *dev)
2043{
2044 void __iomem *owner;
2045
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +00002046 if (pci_channel_offline(dev->pdev))
2047 return;
2048
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002049 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 Dreier839f1242012-09-27 09:23:41 -07002060static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data)
Roland Dreier225c7b12007-05-08 18:00:38 -07002061{
Roland Dreier225c7b12007-05-08 18:00:38 -07002062 struct mlx4_priv *priv;
2063 struct mlx4_dev *dev;
2064 int err;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -07002065 int port;
Roland Dreier225c7b12007-05-08 18:00:38 -07002066
Joe Perches0a645e82010-07-10 07:22:46 +00002067 pr_info(DRV_NAME ": Initializing %s\n", pci_name(pdev));
Roland Dreier225c7b12007-05-08 18:00:38 -07002068
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 Morgensteinab9c17a2011-12-13 04:18:30 +00002075 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 Dreier225c7b12007-05-08 18:00:38 -07002080 /*
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002081 * Check for BARs.
Roland Dreier225c7b12007-05-08 18:00:38 -07002082 */
Roland Dreier839f1242012-09-27 09:23:41 -07002083 if (!(pci_dev_data & MLX4_PCI_DEV_IS_VF) &&
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002084 !(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2085 dev_err(&pdev->dev, "Missing DCS, aborting."
Roland Dreier839f1242012-09-27 09:23:41 -07002086 "(driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\n",
2087 pci_dev_data, pci_resource_flags(pdev, 0));
Roland Dreier225c7b12007-05-08 18:00:38 -07002088 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 Dreiera01df0f2009-09-05 20:24:48 -07002097 err = pci_request_regions(pdev, DRV_NAME);
Roland Dreier225c7b12007-05-08 18:00:38 -07002098 if (err) {
Roland Dreiera01df0f2009-09-05 20:24:48 -07002099 dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n");
Roland Dreier225c7b12007-05-08 18:00:38 -07002100 goto err_disable_pdev;
2101 }
2102
Roland Dreier225c7b12007-05-08 18:00:38 -07002103 pci_set_master(pdev);
2104
Yang Hongyang6a355282009-04-06 19:01:13 -07002105 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
Roland Dreier225c7b12007-05-08 18:00:38 -07002106 if (err) {
2107 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
Yang Hongyang284901a2009-04-06 19:01:15 -07002108 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Roland Dreier225c7b12007-05-08 18:00:38 -07002109 if (err) {
2110 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
Roland Dreiera01df0f2009-09-05 20:24:48 -07002111 goto err_release_regions;
Roland Dreier225c7b12007-05-08 18:00:38 -07002112 }
2113 }
Yang Hongyang6a355282009-04-06 19:01:13 -07002114 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
Roland Dreier225c7b12007-05-08 18:00:38 -07002115 if (err) {
2116 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
2117 "consistent PCI DMA mask.\n");
Yang Hongyang284901a2009-04-06 19:01:15 -07002118 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Roland Dreier225c7b12007-05-08 18:00:38 -07002119 if (err) {
2120 dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
2121 "aborting.\n");
Roland Dreiera01df0f2009-09-05 20:24:48 -07002122 goto err_release_regions;
Roland Dreier225c7b12007-05-08 18:00:38 -07002123 }
2124 }
2125
David Dillow7f9e5c482011-01-17 02:09:44 +00002126 /* 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 Perchesb2adaca2013-02-03 17:43:58 +00002129 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
Roland Dreier225c7b12007-05-08 18:00:38 -07002130 if (!priv) {
Roland Dreier225c7b12007-05-08 18:00:38 -07002131 err = -ENOMEM;
Roland Dreiera01df0f2009-09-05 20:24:48 -07002132 goto err_release_regions;
Roland Dreier225c7b12007-05-08 18:00:38 -07002133 }
2134
2135 dev = &priv->dev;
2136 dev->pdev = pdev;
Roland Dreierb5814012007-06-07 11:51:58 -07002137 INIT_LIST_HEAD(&priv->ctx_list);
2138 spin_lock_init(&priv->ctx_lock);
Roland Dreier225c7b12007-05-08 18:00:38 -07002139
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002140 mutex_init(&priv->port_mutex);
2141
Yevgeny Petrilin62968832008-04-23 11:55:45 -07002142 INIT_LIST_HEAD(&priv->pgdir_list);
2143 mutex_init(&priv->pgdir_mutex);
2144
Eli Cohenc1b43dc2011-03-22 22:38:41 +00002145 INIT_LIST_HEAD(&priv->bf_list);
2146 mutex_init(&priv->bf_mutex);
2147
Sergei Shtylyovaca7a3a2011-06-23 04:44:30 +00002148 dev->rev_id = pdev->revision;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002149 /* Detect if this device is a virtual function */
Roland Dreier839f1242012-09-27 09:23:41 -07002150 if (pci_dev_data & MLX4_PCI_DEV_IS_VF) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002151 /* 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 Shtylyovaca7a3a2011-06-23 04:44:30 +00002176
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002177 if (num_vfs) {
Roland Dreier84b1f152012-09-25 17:09:42 -07002178 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002179 err = pci_enable_sriov(pdev, num_vfs);
2180 if (err) {
Roland Dreier84b1f152012-09-25 17:09:42 -07002181 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n",
2182 err);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002183 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 Dreier225c7b12007-05-08 18:00:38 -07002202 }
2203
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002204slave_start:
Eugenia Emantayev521130d2012-09-05 22:50:52 +00002205 err = mlx4_cmd_init(dev);
2206 if (err) {
Roland Dreier225c7b12007-05-08 18:00:38 -07002207 mlx4_err(dev, "Failed to init command interface, aborting.\n");
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002208 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 Morgensteinf356fcbe2013-01-24 01:54:17 +00002219 err = mlx4_multi_func_init(dev);
2220 if (err) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002221 mlx4_err(dev, "Failed to init slave mfunc"
2222 " interface, aborting.\n");
2223 goto err_cmd;
2224 }
2225 }
Roland Dreier225c7b12007-05-08 18:00:38 -07002226 }
2227
2228 err = mlx4_init_hca(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002229 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 Morgensteinf356fcbe2013-01-24 01:54:17 +00002244 err = mlx4_multi_func_init(dev);
2245 if (err) {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002246 mlx4_err(dev, "Failed to init master mfunc"
2247 "interface, aborting.\n");
2248 goto err_close;
2249 }
2250 }
Roland Dreier225c7b12007-05-08 18:00:38 -07002251
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08002252 err = mlx4_alloc_eq_table(dev);
2253 if (err)
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002254 goto err_master_mfunc;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08002255
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00002256 priv->msix_ctl.pool_bm = 0;
Yevgeny Petrilin730c41d2012-02-21 03:39:32 +00002257 mutex_init(&priv->msix_ctl.pool_lock);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00002258
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03002259 mlx4_enable_msi_x(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002260 if ((mlx4_is_mfunc(dev)) &&
2261 !(dev->flags & MLX4_FLAG_MSI_X)) {
Jack Morgensteinf356fcbe2013-01-24 01:54:17 +00002262 err = -ENOSYS;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002263 mlx4_err(dev, "INTx is not supported in multi-function mode."
2264 " aborting.\n");
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00002265 goto err_free_eq;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002266 }
2267
2268 if (!mlx4_is_slave(dev)) {
2269 err = mlx4_init_steering(dev);
2270 if (err)
2271 goto err_free_eq;
2272 }
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00002273
Roland Dreier225c7b12007-05-08 18:00:38 -07002274 err = mlx4_setup_hca(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002275 if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) &&
2276 !mlx4_is_mfunc(dev)) {
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03002277 dev->flags &= ~MLX4_FLAG_MSI_X;
Yevgeny Petrilin9858d2d2012-06-25 00:24:12 +00002278 dev->caps.num_comp_vectors = 1;
2279 dev->caps.comp_pool = 0;
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03002280 pci_disable_msix(pdev);
2281 err = mlx4_setup_hca(dev);
2282 }
2283
Roland Dreier225c7b12007-05-08 18:00:38 -07002284 if (err)
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00002285 goto err_steer;
Roland Dreier225c7b12007-05-08 18:00:38 -07002286
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002287 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 Petrilin2a2336f2008-10-22 11:44:46 -07002292
Roland Dreier225c7b12007-05-08 18:00:38 -07002293 err = mlx4_register_device(dev);
2294 if (err)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002295 goto err_port;
Roland Dreier225c7b12007-05-08 18:00:38 -07002296
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -07002297 mlx4_sense_init(dev);
2298 mlx4_start_sense(dev);
2299
Roland Dreier839f1242012-09-27 09:23:41 -07002300 priv->pci_dev_data = pci_dev_data;
Roland Dreier225c7b12007-05-08 18:00:38 -07002301 pci_set_drvdata(pdev, dev);
2302
2303 return 0;
2304
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002305err_port:
Eli Cohenb4f77262010-01-06 12:54:39 -08002306 for (--port; port >= 1; --port)
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002307 mlx4_cleanup_port_info(&priv->port[port]);
2308
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00002309 mlx4_cleanup_counters_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002310 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 Dreier225c7b12007-05-08 18:00:38 -07002316 mlx4_cleanup_mr_table(dev);
Sean Hefty012a8ff2011-06-02 09:01:33 -07002317 mlx4_cleanup_xrcd_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002318 mlx4_cleanup_pd_table(dev);
2319 mlx4_cleanup_uar_table(dev);
2320
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00002321err_steer:
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002322 if (!mlx4_is_slave(dev))
2323 mlx4_clear_steering(dev);
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +00002324
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08002325err_free_eq:
2326 mlx4_free_eq_table(dev);
2327
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002328err_master_mfunc:
2329 if (mlx4_is_master(dev))
2330 mlx4_multi_func_cleanup(dev);
2331
Roland Dreier225c7b12007-05-08 18:00:38 -07002332err_close:
Michael S. Tsirkin08fb1052007-08-07 16:08:28 +03002333 if (dev->flags & MLX4_FLAG_MSI_X)
2334 pci_disable_msix(pdev);
2335
Roland Dreier225c7b12007-05-08 18:00:38 -07002336 mlx4_close_hca(dev);
2337
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002338err_mfunc:
2339 if (mlx4_is_slave(dev))
2340 mlx4_multi_func_cleanup(dev);
2341
Roland Dreier225c7b12007-05-08 18:00:38 -07002342err_cmd:
2343 mlx4_cmd_cleanup(dev);
2344
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002345err_sriov:
Jack Morgenstein681372a2012-05-15 10:35:01 +00002346 if (dev->flags & MLX4_FLAG_SRIOV)
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002347 pci_disable_sriov(pdev);
2348
2349err_rel_own:
2350 if (!mlx4_is_slave(dev))
2351 mlx4_free_ownership(dev);
2352
Roland Dreier225c7b12007-05-08 18:00:38 -07002353err_free_dev:
Roland Dreier225c7b12007-05-08 18:00:38 -07002354 kfree(priv);
2355
Roland Dreiera01df0f2009-09-05 20:24:48 -07002356err_release_regions:
2357 pci_release_regions(pdev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002358
2359err_disable_pdev:
2360 pci_disable_device(pdev);
2361 pci_set_drvdata(pdev, NULL);
2362 return err;
2363}
2364
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00002365static int mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
Roland Dreier3d73c282007-10-10 15:43:54 -07002366{
Joe Perches0a645e82010-07-10 07:22:46 +00002367 printk_once(KERN_INFO "%s", mlx4_version);
Roland Dreier3d73c282007-10-10 15:43:54 -07002368
Roland Dreier839f1242012-09-27 09:23:41 -07002369 return __mlx4_init_one(pdev, id->driver_data);
Roland Dreier3d73c282007-10-10 15:43:54 -07002370}
2371
2372static void mlx4_remove_one(struct pci_dev *pdev)
Roland Dreier225c7b12007-05-08 18:00:38 -07002373{
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 Morgensteinab9c17a2011-12-13 04:18:30 +00002379 /* 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 Petrilin27bf91d2009-03-18 19:45:11 -07002385 mlx4_stop_sense(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002386 mlx4_unregister_device(dev);
2387
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002388 for (p = 1; p <= dev->caps.num_ports; p++) {
2389 mlx4_cleanup_port_info(&priv->port[p]);
Roland Dreier225c7b12007-05-08 18:00:38 -07002390 mlx4_CLOSE_PORT(dev, p);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002391 }
Roland Dreier225c7b12007-05-08 18:00:38 -07002392
Jack Morgensteinb8924952012-05-15 10:35:02 +00002393 if (mlx4_is_master(dev))
2394 mlx4_free_resource_tracker(dev,
2395 RES_TR_FREE_SLAVES_ONLY);
2396
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00002397 mlx4_cleanup_counters_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002398 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 Dreier225c7b12007-05-08 18:00:38 -07002404 mlx4_cleanup_mr_table(dev);
Sean Hefty012a8ff2011-06-02 09:01:33 -07002405 mlx4_cleanup_xrcd_table(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002406 mlx4_cleanup_pd_table(dev);
2407
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002408 if (mlx4_is_master(dev))
Jack Morgensteinb8924952012-05-15 10:35:02 +00002409 mlx4_free_resource_tracker(dev,
2410 RES_TR_FREE_STRUCTS_ONLY);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002411
Roland Dreier225c7b12007-05-08 18:00:38 -07002412 iounmap(priv->kar);
2413 mlx4_uar_free(dev, &priv->driver_uar);
2414 mlx4_cleanup_uar_table(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002415 if (!mlx4_is_slave(dev))
2416 mlx4_clear_steering(dev);
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08002417 mlx4_free_eq_table(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002418 if (mlx4_is_master(dev))
2419 mlx4_multi_func_cleanup(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002420 mlx4_close_hca(dev);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002421 if (mlx4_is_slave(dev))
2422 mlx4_multi_func_cleanup(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002423 mlx4_cmd_cleanup(dev);
2424
2425 if (dev->flags & MLX4_FLAG_MSI_X)
2426 pci_disable_msix(pdev);
Jack Morgenstein681372a2012-05-15 10:35:01 +00002427 if (dev->flags & MLX4_FLAG_SRIOV) {
Roland Dreier84b1f152012-09-25 17:09:42 -07002428 mlx4_warn(dev, "Disabling SR-IOV\n");
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002429 pci_disable_sriov(pdev);
2430 }
Roland Dreier225c7b12007-05-08 18:00:38 -07002431
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002432 if (!mlx4_is_slave(dev))
2433 mlx4_free_ownership(dev);
Jack Morgenstein47605df2012-08-03 08:40:57 +00002434
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 Dreier225c7b12007-05-08 18:00:38 -07002440 kfree(priv);
Roland Dreiera01df0f2009-09-05 20:24:48 -07002441 pci_release_regions(pdev);
Roland Dreier225c7b12007-05-08 18:00:38 -07002442 pci_disable_device(pdev);
2443 pci_set_drvdata(pdev, NULL);
2444 }
2445}
2446
Jack Morgensteinee49bd92007-07-12 17:50:45 +03002447int mlx4_restart_one(struct pci_dev *pdev)
2448{
Roland Dreier839f1242012-09-27 09:23:41 -07002449 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 Morgensteinee49bd92007-07-12 17:50:45 +03002454 mlx4_remove_one(pdev);
Roland Dreier839f1242012-09-27 09:23:41 -07002455 return __mlx4_init_one(pdev, pci_dev_data);
Jack Morgensteinee49bd92007-07-12 17:50:45 +03002456}
2457
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00002458static DEFINE_PCI_DEVICE_TABLE(mlx4_pci_table) = {
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002459 /* MT25408 "Hermon" SDR */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002460 { PCI_VDEVICE(MELLANOX, 0x6340), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002461 /* MT25408 "Hermon" DDR */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002462 { PCI_VDEVICE(MELLANOX, 0x634a), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002463 /* MT25408 "Hermon" QDR */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002464 { PCI_VDEVICE(MELLANOX, 0x6354), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002465 /* MT25408 "Hermon" DDR PCIe gen2 */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002466 { PCI_VDEVICE(MELLANOX, 0x6732), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002467 /* MT25408 "Hermon" QDR PCIe gen2 */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002468 { PCI_VDEVICE(MELLANOX, 0x673c), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002469 /* MT25408 "Hermon" EN 10GigE */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002470 { PCI_VDEVICE(MELLANOX, 0x6368), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002471 /* MT25408 "Hermon" EN 10GigE PCIe gen2 */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002472 { PCI_VDEVICE(MELLANOX, 0x6750), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002473 /* MT25458 ConnectX EN 10GBASE-T 10GigE */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002474 { PCI_VDEVICE(MELLANOX, 0x6372), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002475 /* MT25458 ConnectX EN 10GBASE-T+Gen2 10GigE */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002476 { PCI_VDEVICE(MELLANOX, 0x675a), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002477 /* MT26468 ConnectX EN 10GigE PCIe gen2*/
Roland Dreierca3e57a2012-09-27 09:53:05 -07002478 { PCI_VDEVICE(MELLANOX, 0x6764), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002479 /* MT26438 ConnectX EN 40GigE PCIe gen2 5GT/s */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002480 { PCI_VDEVICE(MELLANOX, 0x6746), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002481 /* MT26478 ConnectX2 40GigE PCIe gen2 */
Roland Dreierca3e57a2012-09-27 09:53:05 -07002482 { PCI_VDEVICE(MELLANOX, 0x676e), MLX4_PCI_DEV_FORCE_SENSE_PORT },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002483 /* MT25400 Family [ConnectX-2 Virtual Function] */
Roland Dreier839f1242012-09-27 09:23:41 -07002484 { PCI_VDEVICE(MELLANOX, 0x1002), MLX4_PCI_DEV_IS_VF },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002485 /* MT27500 Family [ConnectX-3] */
2486 { PCI_VDEVICE(MELLANOX, 0x1003), 0 },
2487 /* MT27500 Family [ConnectX-3 Virtual Function] */
Roland Dreier839f1242012-09-27 09:23:41 -07002488 { PCI_VDEVICE(MELLANOX, 0x1004), MLX4_PCI_DEV_IS_VF },
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002489 { 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 Dreier225c7b12007-05-08 18:00:38 -07002501 { 0, }
2502};
2503
2504MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
2505
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +00002506static 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
2515static pci_ers_result_t mlx4_pci_slot_reset(struct pci_dev *pdev)
2516{
Roland Dreier839f1242012-09-27 09:23:41 -07002517 int ret = __mlx4_init_one(pdev, 0);
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +00002518
2519 return ret ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
2520}
2521
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07002522static const struct pci_error_handlers mlx4_err_handler = {
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +00002523 .error_detected = mlx4_pci_err_detected,
2524 .slot_reset = mlx4_pci_slot_reset,
2525};
2526
Roland Dreier225c7b12007-05-08 18:00:38 -07002527static struct pci_driver mlx4_driver = {
2528 .name = DRV_NAME,
2529 .id_table = mlx4_pci_table,
2530 .probe = mlx4_init_one,
Bill Pembertonf57e6842012-12-03 09:23:15 -05002531 .remove = mlx4_remove_one,
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +00002532 .err_handler = &mlx4_err_handler,
Roland Dreier225c7b12007-05-08 18:00:38 -07002533};
2534
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002535static int __init mlx4_verify_params(void)
2536{
2537 if ((log_num_mac < 0) || (log_num_mac > 7)) {
Joe Perches0a645e82010-07-10 07:22:46 +00002538 pr_warning("mlx4_core: bad num_mac: %d\n", log_num_mac);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002539 return -1;
2540 }
2541
Or Gerlitzcb296882011-10-16 10:26:21 +02002542 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 Petrilin7ff93f82008-10-22 15:38:42 -07002545
Eli Cohen04986282010-09-20 08:42:38 +02002546 if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 7)) {
Joe Perches0a645e82010-07-10 07:22:46 +00002547 pr_warning("mlx4_core: bad log_mtts_per_seg: %d\n", log_mtts_per_seg);
Eli Cohenab6bf422009-05-27 14:38:34 -07002548 return -1;
2549 }
2550
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00002551 /* 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 Morgenstein3c439b52012-12-06 17:12:00 +00002557 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 Petrilin7ff93f82008-10-22 15:38:42 -07002568 return 0;
2569}
2570
Roland Dreier225c7b12007-05-08 18:00:38 -07002571static int __init mlx4_init(void)
2572{
2573 int ret;
2574
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -07002575 if (mlx4_verify_params())
2576 return -EINVAL;
2577
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -07002578 mlx4_catas_init();
2579
2580 mlx4_wq = create_singlethread_workqueue("mlx4");
2581 if (!mlx4_wq)
2582 return -ENOMEM;
Jack Morgensteinee49bd92007-07-12 17:50:45 +03002583
Roland Dreier225c7b12007-05-08 18:00:38 -07002584 ret = pci_register_driver(&mlx4_driver);
2585 return ret < 0 ? ret : 0;
2586}
2587
2588static void __exit mlx4_cleanup(void)
2589{
2590 pci_unregister_driver(&mlx4_driver);
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -07002591 destroy_workqueue(mlx4_wq);
Roland Dreier225c7b12007-05-08 18:00:38 -07002592}
2593
2594module_init(mlx4_init);
2595module_exit(mlx4_cleanup);