blob: 91b69ff4b4a20f8f2bd2f6c9405cf6ab60af7f6a [file] [log] [blame]
Roland Dreier225c7b12007-05-08 18:00:38 -07001/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
Jack Morgenstein51a379d2008-07-25 10:32:52 -07003 * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
Roland Dreier225c7b12007-05-08 18:00:38 -07004 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +000035#include <linux/etherdevice.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070036#include <linux/mlx4/cmd.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040037#include <linux/module.h>
Eli Cohenc57e20dcf2009-09-24 11:03:03 -070038#include <linux/cache.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070039
40#include "fw.h"
41#include "icm.h"
42
Roland Dreierfe409002007-06-07 23:24:36 -070043enum {
Roland Dreier5ae2a7a2007-06-18 08:15:02 -070044 MLX4_COMMAND_INTERFACE_MIN_REV = 2,
45 MLX4_COMMAND_INTERFACE_MAX_REV = 3,
46 MLX4_COMMAND_INTERFACE_NEW_PORT_CMDS = 3,
Roland Dreierfe409002007-06-07 23:24:36 -070047};
48
Roland Dreier225c7b12007-05-08 18:00:38 -070049extern void __buggy_use_of_MLX4_GET(void);
50extern void __buggy_use_of_MLX4_PUT(void);
51
Rusty Russelleb939922011-12-19 14:08:01 +000052static bool enable_qos;
Jack Morgenstein51f5f0e2008-07-22 14:19:37 -070053module_param(enable_qos, bool, 0444);
54MODULE_PARM_DESC(enable_qos, "Enable Quality of Service support in the HCA (default: off)");
55
Roland Dreier225c7b12007-05-08 18:00:38 -070056#define MLX4_GET(dest, source, offset) \
57 do { \
58 void *__p = (char *) (source) + (offset); \
59 switch (sizeof (dest)) { \
60 case 1: (dest) = *(u8 *) __p; break; \
61 case 2: (dest) = be16_to_cpup(__p); break; \
62 case 4: (dest) = be32_to_cpup(__p); break; \
63 case 8: (dest) = be64_to_cpup(__p); break; \
64 default: __buggy_use_of_MLX4_GET(); \
65 } \
66 } while (0)
67
68#define MLX4_PUT(dest, source, offset) \
69 do { \
70 void *__d = ((char *) (dest) + (offset)); \
71 switch (sizeof(source)) { \
72 case 1: *(u8 *) __d = (source); break; \
73 case 2: *(__be16 *) __d = cpu_to_be16(source); break; \
74 case 4: *(__be32 *) __d = cpu_to_be32(source); break; \
75 case 8: *(__be64 *) __d = cpu_to_be64(source); break; \
76 default: __buggy_use_of_MLX4_PUT(); \
77 } \
78 } while (0)
79
Or Gerlitz52eafc62011-06-15 14:41:42 +000080static void dump_dev_cap_flags(struct mlx4_dev *dev, u64 flags)
Roland Dreier225c7b12007-05-08 18:00:38 -070081{
82 static const char *fname[] = {
83 [ 0] = "RC transport",
84 [ 1] = "UC transport",
85 [ 2] = "UD transport",
Roland Dreierea980542007-10-09 19:59:13 -070086 [ 3] = "XRC transport",
Roland Dreier225c7b12007-05-08 18:00:38 -070087 [ 4] = "reliable multicast",
88 [ 5] = "FCoIB support",
89 [ 6] = "SRQ support",
90 [ 7] = "IPoIB checksum offload",
91 [ 8] = "P_Key violation counter",
92 [ 9] = "Q_Key violation counter",
93 [10] = "VMM",
Or Gerlitz4d531aa2013-04-07 03:44:06 +000094 [12] = "Dual Port Different Protocol (DPDP) support",
Eli Cohen417608c2009-11-12 11:19:44 -080095 [15] = "Big LSO headers",
Roland Dreier225c7b12007-05-08 18:00:38 -070096 [16] = "MW support",
97 [17] = "APM support",
98 [18] = "Atomic ops support",
99 [19] = "Raw multicast support",
100 [20] = "Address vector port checking support",
101 [21] = "UD multicast support",
102 [24] = "Demand paging support",
Eli Cohen96dfa682010-10-20 21:57:02 -0700103 [25] = "Router support",
Or Gerlitzccf86322011-07-07 19:19:29 +0000104 [30] = "IBoE support",
105 [32] = "Unicast loopback support",
Yevgeny Petrilinf3a9d1f2011-10-18 01:50:42 +0000106 [34] = "FCS header control",
Or Gerlitzccf86322011-07-07 19:19:29 +0000107 [38] = "Wake On LAN support",
108 [40] = "UDP RSS support",
109 [41] = "Unicast VEP steering support",
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +0000110 [42] = "Multicast VEP steering support",
111 [48] = "Counters support",
Or Gerlitz540b3a32013-04-07 03:44:07 +0000112 [53] = "Port ETS Scheduler support",
Or Gerlitz4d531aa2013-04-07 03:44:06 +0000113 [55] = "Port link type sensing support",
Jack Morgenstein00f5ce92012-06-19 11:21:40 +0300114 [59] = "Port management change event support",
Or Gerlitz08ff3232012-10-21 14:59:24 +0000115 [61] = "64 byte EQE support",
116 [62] = "64 byte CQE support",
Roland Dreier225c7b12007-05-08 18:00:38 -0700117 };
118 int i;
119
120 mlx4_dbg(dev, "DEV_CAP flags:\n");
Roland Dreier23c15c22007-05-19 08:51:57 -0700121 for (i = 0; i < ARRAY_SIZE(fname); ++i)
Or Gerlitz52eafc62011-06-15 14:41:42 +0000122 if (fname[i] && (flags & (1LL << i)))
Roland Dreier225c7b12007-05-08 18:00:38 -0700123 mlx4_dbg(dev, " %s\n", fname[i]);
124}
125
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300126static void dump_dev_cap_flags2(struct mlx4_dev *dev, u64 flags)
127{
128 static const char * const fname[] = {
129 [0] = "RSS support",
130 [1] = "RSS Toeplitz Hash Function support",
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000131 [2] = "RSS XOR Hash Function support",
Matan Barak955154f2013-01-30 23:07:10 +0000132 [3] = "Device manage flow steering support",
Eugenia Emantayevd9987352013-04-23 06:06:47 +0000133 [4] = "Automatic MAC reassignment support",
Or Gerlitz4e8cf5b2013-05-08 22:22:34 +0000134 [5] = "Time stamping support",
135 [6] = "VST (control vlan insertion/stripping) support",
Jack Morgensteinb01978c2013-06-27 19:05:21 +0300136 [7] = "FSM (MAC anti-spoofing) support",
Or Gerlitz7ffdf722013-12-23 16:09:43 +0200137 [8] = "Dynamic QP updates support",
138 [9] = "TCP/IP offloads/flow-steering for VXLAN support"
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300139 };
140 int i;
141
142 for (i = 0; i < ARRAY_SIZE(fname); ++i)
143 if (fname[i] && (flags & (1LL << i)))
144 mlx4_dbg(dev, " %s\n", fname[i]);
145}
146
Vladimir Sokolovsky2d928652008-07-14 23:48:53 -0700147int mlx4_MOD_STAT_CFG(struct mlx4_dev *dev, struct mlx4_mod_stat_cfg *cfg)
148{
149 struct mlx4_cmd_mailbox *mailbox;
150 u32 *inbox;
151 int err = 0;
152
153#define MOD_STAT_CFG_IN_SIZE 0x100
154
155#define MOD_STAT_CFG_PG_SZ_M_OFFSET 0x002
156#define MOD_STAT_CFG_PG_SZ_OFFSET 0x003
157
158 mailbox = mlx4_alloc_cmd_mailbox(dev);
159 if (IS_ERR(mailbox))
160 return PTR_ERR(mailbox);
161 inbox = mailbox->buf;
162
Vladimir Sokolovsky2d928652008-07-14 23:48:53 -0700163 MLX4_PUT(inbox, cfg->log_pg_sz, MOD_STAT_CFG_PG_SZ_OFFSET);
164 MLX4_PUT(inbox, cfg->log_pg_sz_m, MOD_STAT_CFG_PG_SZ_M_OFFSET);
165
166 err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_MOD_STAT_CFG,
Jack Morgensteinf9baff52011-12-13 04:10:51 +0000167 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
Vladimir Sokolovsky2d928652008-07-14 23:48:53 -0700168
169 mlx4_free_cmd_mailbox(dev, mailbox);
170 return err;
171}
172
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000173int mlx4_QUERY_FUNC_CAP_wrapper(struct mlx4_dev *dev, int slave,
174 struct mlx4_vhcr *vhcr,
175 struct mlx4_cmd_mailbox *inbox,
176 struct mlx4_cmd_mailbox *outbox,
177 struct mlx4_cmd_info *cmd)
178{
Jack Morgenstein5a0d0a62013-11-03 10:03:23 +0200179 struct mlx4_priv *priv = mlx4_priv(dev);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000180 u8 field;
181 u32 size;
182 int err = 0;
183
184#define QUERY_FUNC_CAP_FLAGS_OFFSET 0x0
185#define QUERY_FUNC_CAP_NUM_PORTS_OFFSET 0x1
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000186#define QUERY_FUNC_CAP_PF_BHVR_OFFSET 0x4
Jack Morgenstein105c3202012-06-19 11:21:43 +0300187#define QUERY_FUNC_CAP_FMR_OFFSET 0x8
Jack Morgensteineb456a62013-11-03 10:03:24 +0200188#define QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP 0x10
189#define QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP 0x14
190#define QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP 0x18
191#define QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP 0x20
192#define QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP 0x24
193#define QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP 0x28
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000194#define QUERY_FUNC_CAP_MAX_EQ_OFFSET 0x2c
Roland Dreier69612b92012-09-23 09:18:24 -0700195#define QUERY_FUNC_CAP_RESERVED_EQ_OFFSET 0x30
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000196
Jack Morgensteineb456a62013-11-03 10:03:24 +0200197#define QUERY_FUNC_CAP_QP_QUOTA_OFFSET 0x50
198#define QUERY_FUNC_CAP_CQ_QUOTA_OFFSET 0x54
199#define QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET 0x58
200#define QUERY_FUNC_CAP_MPT_QUOTA_OFFSET 0x60
201#define QUERY_FUNC_CAP_MTT_QUOTA_OFFSET 0x64
202#define QUERY_FUNC_CAP_MCG_QUOTA_OFFSET 0x68
203
Jack Morgenstein105c3202012-06-19 11:21:43 +0300204#define QUERY_FUNC_CAP_FMR_FLAG 0x80
205#define QUERY_FUNC_CAP_FLAG_RDMA 0x40
206#define QUERY_FUNC_CAP_FLAG_ETH 0x80
Jack Morgensteineb456a62013-11-03 10:03:24 +0200207#define QUERY_FUNC_CAP_FLAG_QUOTAS 0x10
Jack Morgenstein105c3202012-06-19 11:21:43 +0300208
209/* when opcode modifier = 1 */
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000210#define QUERY_FUNC_CAP_PHYS_PORT_OFFSET 0x3
Hadar Hen Zion73e74ab2013-12-19 21:20:10 +0200211#define QUERY_FUNC_CAP_FLAGS0_OFFSET 0x8
212#define QUERY_FUNC_CAP_FLAGS1_OFFSET 0xc
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000213
Jack Morgenstein47605df2012-08-03 08:40:57 +0000214#define QUERY_FUNC_CAP_QP0_TUNNEL 0x10
215#define QUERY_FUNC_CAP_QP0_PROXY 0x14
216#define QUERY_FUNC_CAP_QP1_TUNNEL 0x18
217#define QUERY_FUNC_CAP_QP1_PROXY 0x1c
Hadar Hen Zion8e1a28e2013-12-19 21:20:12 +0200218#define QUERY_FUNC_CAP_PHYS_PORT_ID 0x28
Jack Morgenstein47605df2012-08-03 08:40:57 +0000219
Hadar Hen Zion73e74ab2013-12-19 21:20:10 +0200220#define QUERY_FUNC_CAP_FLAGS1_FORCE_MAC 0x40
221#define QUERY_FUNC_CAP_FLAGS1_FORCE_VLAN 0x80
Hadar Hen Zioneb177112013-12-19 21:20:11 +0200222#define QUERY_FUNC_CAP_FLAGS1_NIC_INFO 0x10
Jack Morgenstein105c3202012-06-19 11:21:43 +0300223
Hadar Hen Zion73e74ab2013-12-19 21:20:10 +0200224#define QUERY_FUNC_CAP_FLAGS0_FORCE_PHY_WQE_GID 0x80
Jack Morgenstein105c3202012-06-19 11:21:43 +0300225
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000226 if (vhcr->op_modifier == 1) {
Hadar Hen Zioneb177112013-12-19 21:20:11 +0200227 /* Set nic_info bit to mark new fields support */
228 field = QUERY_FUNC_CAP_FLAGS1_NIC_INFO;
229 MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FLAGS1_OFFSET);
Jack Morgenstein105c3202012-06-19 11:21:43 +0300230
Jack Morgenstein47605df2012-08-03 08:40:57 +0000231 field = vhcr->in_modifier; /* phys-port = logical-port */
232 MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_PHYS_PORT_OFFSET);
233
234 /* size is now the QP number */
235 size = dev->phys_caps.base_tunnel_sqpn + 8 * slave + field - 1;
236 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP0_TUNNEL);
237
238 size += 2;
239 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP1_TUNNEL);
240
241 size = dev->phys_caps.base_proxy_sqpn + 8 * slave + field - 1;
242 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP0_PROXY);
243
244 size += 2;
245 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP1_PROXY);
246
Hadar Hen Zion8e1a28e2013-12-19 21:20:12 +0200247 MLX4_PUT(outbox->buf, dev->caps.phys_port_id[vhcr->in_modifier],
248 QUERY_FUNC_CAP_PHYS_PORT_ID);
249
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000250 } else if (vhcr->op_modifier == 0) {
Jack Morgensteineb456a62013-11-03 10:03:24 +0200251 /* enable rdma and ethernet interfaces, and new quota locations */
252 field = (QUERY_FUNC_CAP_FLAG_ETH | QUERY_FUNC_CAP_FLAG_RDMA |
253 QUERY_FUNC_CAP_FLAG_QUOTAS);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000254 MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FLAGS_OFFSET);
255
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000256 field = dev->caps.num_ports;
257 MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_NUM_PORTS_OFFSET);
258
Or Gerlitz08ff3232012-10-21 14:59:24 +0000259 size = dev->caps.function_caps; /* set PF behaviours */
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000260 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_PF_BHVR_OFFSET);
261
Jack Morgenstein105c3202012-06-19 11:21:43 +0300262 field = 0; /* protected FMR support not available as yet */
263 MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FMR_OFFSET);
264
Jack Morgenstein5a0d0a62013-11-03 10:03:23 +0200265 size = priv->mfunc.master.res_tracker.res_alloc[RES_QP].quota[slave];
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000266 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP_QUOTA_OFFSET);
Jack Morgensteineb456a62013-11-03 10:03:24 +0200267 size = dev->caps.num_qps;
268 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000269
Jack Morgenstein5a0d0a62013-11-03 10:03:23 +0200270 size = priv->mfunc.master.res_tracker.res_alloc[RES_SRQ].quota[slave];
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000271 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET);
Jack Morgensteineb456a62013-11-03 10:03:24 +0200272 size = dev->caps.num_srqs;
273 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000274
Jack Morgenstein5a0d0a62013-11-03 10:03:23 +0200275 size = priv->mfunc.master.res_tracker.res_alloc[RES_CQ].quota[slave];
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000276 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET);
Jack Morgensteineb456a62013-11-03 10:03:24 +0200277 size = dev->caps.num_cqs;
278 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000279
280 size = dev->caps.num_eqs;
281 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MAX_EQ_OFFSET);
282
283 size = dev->caps.reserved_eqs;
284 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_RESERVED_EQ_OFFSET);
285
Jack Morgenstein5a0d0a62013-11-03 10:03:23 +0200286 size = priv->mfunc.master.res_tracker.res_alloc[RES_MPT].quota[slave];
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000287 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET);
Jack Morgensteineb456a62013-11-03 10:03:24 +0200288 size = dev->caps.num_mpts;
289 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000290
Jack Morgenstein5a0d0a62013-11-03 10:03:23 +0200291 size = priv->mfunc.master.res_tracker.res_alloc[RES_MTT].quota[slave];
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000292 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET);
Jack Morgensteineb456a62013-11-03 10:03:24 +0200293 size = dev->caps.num_mtts;
294 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000295
296 size = dev->caps.num_mgms + dev->caps.num_amgms;
297 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET);
Jack Morgensteineb456a62013-11-03 10:03:24 +0200298 MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000299
300 } else
301 err = -EINVAL;
302
303 return err;
304}
305
Jack Morgenstein47605df2012-08-03 08:40:57 +0000306int mlx4_QUERY_FUNC_CAP(struct mlx4_dev *dev, u32 gen_or_port,
307 struct mlx4_func_cap *func_cap)
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000308{
309 struct mlx4_cmd_mailbox *mailbox;
310 u32 *outbox;
Jack Morgenstein47605df2012-08-03 08:40:57 +0000311 u8 field, op_modifier;
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000312 u32 size;
Jack Morgensteineb456a62013-11-03 10:03:24 +0200313 int err = 0, quotas = 0;
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000314
Jack Morgenstein47605df2012-08-03 08:40:57 +0000315 op_modifier = !!gen_or_port; /* 0 = general, 1 = logical port */
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000316
317 mailbox = mlx4_alloc_cmd_mailbox(dev);
318 if (IS_ERR(mailbox))
319 return PTR_ERR(mailbox);
320
Jack Morgenstein47605df2012-08-03 08:40:57 +0000321 err = mlx4_cmd_box(dev, 0, mailbox->dma, gen_or_port, op_modifier,
322 MLX4_CMD_QUERY_FUNC_CAP,
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000323 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
324 if (err)
325 goto out;
326
327 outbox = mailbox->buf;
328
Jack Morgenstein47605df2012-08-03 08:40:57 +0000329 if (!op_modifier) {
330 MLX4_GET(field, outbox, QUERY_FUNC_CAP_FLAGS_OFFSET);
331 if (!(field & (QUERY_FUNC_CAP_FLAG_ETH | QUERY_FUNC_CAP_FLAG_RDMA))) {
332 mlx4_err(dev, "The host supports neither eth nor rdma interfaces\n");
333 err = -EPROTONOSUPPORT;
334 goto out;
335 }
336 func_cap->flags = field;
Jack Morgensteineb456a62013-11-03 10:03:24 +0200337 quotas = !!(func_cap->flags & QUERY_FUNC_CAP_FLAG_QUOTAS);
Jack Morgenstein47605df2012-08-03 08:40:57 +0000338
339 MLX4_GET(field, outbox, QUERY_FUNC_CAP_NUM_PORTS_OFFSET);
340 func_cap->num_ports = field;
341
342 MLX4_GET(size, outbox, QUERY_FUNC_CAP_PF_BHVR_OFFSET);
343 func_cap->pf_context_behaviour = size;
344
Jack Morgensteineb456a62013-11-03 10:03:24 +0200345 if (quotas) {
346 MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP_QUOTA_OFFSET);
347 func_cap->qp_quota = size & 0xFFFFFF;
Jack Morgenstein47605df2012-08-03 08:40:57 +0000348
Jack Morgensteineb456a62013-11-03 10:03:24 +0200349 MLX4_GET(size, outbox, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET);
350 func_cap->srq_quota = size & 0xFFFFFF;
Jack Morgenstein47605df2012-08-03 08:40:57 +0000351
Jack Morgensteineb456a62013-11-03 10:03:24 +0200352 MLX4_GET(size, outbox, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET);
353 func_cap->cq_quota = size & 0xFFFFFF;
Jack Morgenstein47605df2012-08-03 08:40:57 +0000354
Jack Morgensteineb456a62013-11-03 10:03:24 +0200355 MLX4_GET(size, outbox, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET);
356 func_cap->mpt_quota = size & 0xFFFFFF;
357
358 MLX4_GET(size, outbox, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET);
359 func_cap->mtt_quota = size & 0xFFFFFF;
360
361 MLX4_GET(size, outbox, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET);
362 func_cap->mcg_quota = size & 0xFFFFFF;
363
364 } else {
365 MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP);
366 func_cap->qp_quota = size & 0xFFFFFF;
367
368 MLX4_GET(size, outbox, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP);
369 func_cap->srq_quota = size & 0xFFFFFF;
370
371 MLX4_GET(size, outbox, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP);
372 func_cap->cq_quota = size & 0xFFFFFF;
373
374 MLX4_GET(size, outbox, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP);
375 func_cap->mpt_quota = size & 0xFFFFFF;
376
377 MLX4_GET(size, outbox, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP);
378 func_cap->mtt_quota = size & 0xFFFFFF;
379
380 MLX4_GET(size, outbox, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP);
381 func_cap->mcg_quota = size & 0xFFFFFF;
382 }
Jack Morgenstein47605df2012-08-03 08:40:57 +0000383 MLX4_GET(size, outbox, QUERY_FUNC_CAP_MAX_EQ_OFFSET);
384 func_cap->max_eq = size & 0xFFFFFF;
385
386 MLX4_GET(size, outbox, QUERY_FUNC_CAP_RESERVED_EQ_OFFSET);
387 func_cap->reserved_eq = size & 0xFFFFFF;
388
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000389 goto out;
390 }
391
Jack Morgenstein47605df2012-08-03 08:40:57 +0000392 /* logical port query */
393 if (gen_or_port > dev->caps.num_ports) {
394 err = -EINVAL;
395 goto out;
396 }
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000397
Hadar Hen Zioneb177112013-12-19 21:20:11 +0200398 MLX4_GET(func_cap->flags1, outbox, QUERY_FUNC_CAP_FLAGS1_OFFSET);
Jack Morgenstein47605df2012-08-03 08:40:57 +0000399 if (dev->caps.port_type[gen_or_port] == MLX4_PORT_TYPE_ETH) {
Hadar Hen Zioneb177112013-12-19 21:20:11 +0200400 if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_OFFSET) {
Jack Morgenstein47605df2012-08-03 08:40:57 +0000401 mlx4_err(dev, "VLAN is enforced on this port\n");
402 err = -EPROTONOSUPPORT;
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000403 goto out;
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000404 }
405
Hadar Hen Zioneb177112013-12-19 21:20:11 +0200406 if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_FORCE_MAC) {
Jack Morgenstein47605df2012-08-03 08:40:57 +0000407 mlx4_err(dev, "Force mac is enabled on this port\n");
408 err = -EPROTONOSUPPORT;
409 goto out;
410 }
411 } else if (dev->caps.port_type[gen_or_port] == MLX4_PORT_TYPE_IB) {
Hadar Hen Zion73e74ab2013-12-19 21:20:10 +0200412 MLX4_GET(field, outbox, QUERY_FUNC_CAP_FLAGS0_OFFSET);
413 if (field & QUERY_FUNC_CAP_FLAGS0_FORCE_PHY_WQE_GID) {
Jack Morgenstein47605df2012-08-03 08:40:57 +0000414 mlx4_err(dev, "phy_wqe_gid is "
415 "enforced on this ib port\n");
416 err = -EPROTONOSUPPORT;
417 goto out;
418 }
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000419 }
420
Jack Morgenstein47605df2012-08-03 08:40:57 +0000421 MLX4_GET(field, outbox, QUERY_FUNC_CAP_PHYS_PORT_OFFSET);
422 func_cap->physical_port = field;
423 if (func_cap->physical_port != gen_or_port) {
424 err = -ENOSYS;
425 goto out;
426 }
427
428 MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP0_TUNNEL);
429 func_cap->qp0_tunnel_qpn = size & 0xFFFFFF;
430
431 MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP0_PROXY);
432 func_cap->qp0_proxy_qpn = size & 0xFFFFFF;
433
434 MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP1_TUNNEL);
435 func_cap->qp1_tunnel_qpn = size & 0xFFFFFF;
436
437 MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP1_PROXY);
438 func_cap->qp1_proxy_qpn = size & 0xFFFFFF;
439
Hadar Hen Zion8e1a28e2013-12-19 21:20:12 +0200440 if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_NIC_INFO)
441 MLX4_GET(func_cap->phys_port_id, outbox,
442 QUERY_FUNC_CAP_PHYS_PORT_ID);
443
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000444 /* All other resources are allocated by the master, but we still report
445 * 'num' and 'reserved' capabilities as follows:
446 * - num remains the maximum resource index
447 * - 'num - reserved' is the total available objects of a resource, but
448 * resource indices may be less than 'reserved'
449 * TODO: set per-resource quotas */
450
451out:
452 mlx4_free_cmd_mailbox(dev, mailbox);
453
454 return err;
455}
456
Roland Dreier225c7b12007-05-08 18:00:38 -0700457int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
458{
459 struct mlx4_cmd_mailbox *mailbox;
460 u32 *outbox;
461 u8 field;
Or Gerlitzccf86322011-07-07 19:19:29 +0000462 u32 field32, flags, ext_flags;
Roland Dreier225c7b12007-05-08 18:00:38 -0700463 u16 size;
464 u16 stat_rate;
465 int err;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700466 int i;
Roland Dreier225c7b12007-05-08 18:00:38 -0700467
468#define QUERY_DEV_CAP_OUT_SIZE 0x100
469#define QUERY_DEV_CAP_MAX_SRQ_SZ_OFFSET 0x10
470#define QUERY_DEV_CAP_MAX_QP_SZ_OFFSET 0x11
471#define QUERY_DEV_CAP_RSVD_QP_OFFSET 0x12
472#define QUERY_DEV_CAP_MAX_QP_OFFSET 0x13
473#define QUERY_DEV_CAP_RSVD_SRQ_OFFSET 0x14
474#define QUERY_DEV_CAP_MAX_SRQ_OFFSET 0x15
475#define QUERY_DEV_CAP_RSVD_EEC_OFFSET 0x16
476#define QUERY_DEV_CAP_MAX_EEC_OFFSET 0x17
477#define QUERY_DEV_CAP_MAX_CQ_SZ_OFFSET 0x19
478#define QUERY_DEV_CAP_RSVD_CQ_OFFSET 0x1a
479#define QUERY_DEV_CAP_MAX_CQ_OFFSET 0x1b
480#define QUERY_DEV_CAP_MAX_MPT_OFFSET 0x1d
481#define QUERY_DEV_CAP_RSVD_EQ_OFFSET 0x1e
482#define QUERY_DEV_CAP_MAX_EQ_OFFSET 0x1f
483#define QUERY_DEV_CAP_RSVD_MTT_OFFSET 0x20
484#define QUERY_DEV_CAP_MAX_MRW_SZ_OFFSET 0x21
485#define QUERY_DEV_CAP_RSVD_MRW_OFFSET 0x22
486#define QUERY_DEV_CAP_MAX_MTT_SEG_OFFSET 0x23
487#define QUERY_DEV_CAP_MAX_AV_OFFSET 0x27
488#define QUERY_DEV_CAP_MAX_REQ_QP_OFFSET 0x29
489#define QUERY_DEV_CAP_MAX_RES_QP_OFFSET 0x2b
Eli Cohenb832be12008-04-16 21:09:27 -0700490#define QUERY_DEV_CAP_MAX_GSO_OFFSET 0x2d
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300491#define QUERY_DEV_CAP_RSS_OFFSET 0x2e
Roland Dreier225c7b12007-05-08 18:00:38 -0700492#define QUERY_DEV_CAP_MAX_RDMA_OFFSET 0x2f
493#define QUERY_DEV_CAP_RSZ_SRQ_OFFSET 0x33
494#define QUERY_DEV_CAP_ACK_DELAY_OFFSET 0x35
495#define QUERY_DEV_CAP_MTU_WIDTH_OFFSET 0x36
496#define QUERY_DEV_CAP_VL_PORT_OFFSET 0x37
Dotan Barak149983af2007-06-26 15:55:28 +0300497#define QUERY_DEV_CAP_MAX_MSG_SZ_OFFSET 0x38
Roland Dreier225c7b12007-05-08 18:00:38 -0700498#define QUERY_DEV_CAP_MAX_GID_OFFSET 0x3b
499#define QUERY_DEV_CAP_RATE_SUPPORT_OFFSET 0x3c
Eugenia Emantayevd9987352013-04-23 06:06:47 +0000500#define QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET 0x3e
Roland Dreier225c7b12007-05-08 18:00:38 -0700501#define QUERY_DEV_CAP_MAX_PKEY_OFFSET 0x3f
Or Gerlitzccf86322011-07-07 19:19:29 +0000502#define QUERY_DEV_CAP_EXT_FLAGS_OFFSET 0x40
Roland Dreier225c7b12007-05-08 18:00:38 -0700503#define QUERY_DEV_CAP_FLAGS_OFFSET 0x44
504#define QUERY_DEV_CAP_RSVD_UAR_OFFSET 0x48
505#define QUERY_DEV_CAP_UAR_SZ_OFFSET 0x49
506#define QUERY_DEV_CAP_PAGE_SZ_OFFSET 0x4b
507#define QUERY_DEV_CAP_BF_OFFSET 0x4c
508#define QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET 0x4d
509#define QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET 0x4e
510#define QUERY_DEV_CAP_LOG_MAX_BF_PAGES_OFFSET 0x4f
511#define QUERY_DEV_CAP_MAX_SG_SQ_OFFSET 0x51
512#define QUERY_DEV_CAP_MAX_DESC_SZ_SQ_OFFSET 0x52
513#define QUERY_DEV_CAP_MAX_SG_RQ_OFFSET 0x55
514#define QUERY_DEV_CAP_MAX_DESC_SZ_RQ_OFFSET 0x56
515#define QUERY_DEV_CAP_MAX_QP_MCG_OFFSET 0x61
516#define QUERY_DEV_CAP_RSVD_MCG_OFFSET 0x62
517#define QUERY_DEV_CAP_MAX_MCG_OFFSET 0x63
518#define QUERY_DEV_CAP_RSVD_PD_OFFSET 0x64
519#define QUERY_DEV_CAP_MAX_PD_OFFSET 0x65
Linus Torvaldsf470f8d2011-11-01 10:51:38 -0700520#define QUERY_DEV_CAP_RSVD_XRC_OFFSET 0x66
521#define QUERY_DEV_CAP_MAX_XRC_OFFSET 0x67
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +0000522#define QUERY_DEV_CAP_MAX_COUNTERS_OFFSET 0x68
Rony Efraim3f7fb022013-04-25 05:22:28 +0000523#define QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET 0x70
Matan Barak4de65802013-11-07 15:25:14 +0200524#define QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET 0x74
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000525#define QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET 0x76
526#define QUERY_DEV_CAP_FLOW_STEERING_MAX_QP_OFFSET 0x77
Roland Dreier225c7b12007-05-08 18:00:38 -0700527#define QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET 0x80
528#define QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET 0x82
529#define QUERY_DEV_CAP_AUX_ENTRY_SZ_OFFSET 0x84
530#define QUERY_DEV_CAP_ALTC_ENTRY_SZ_OFFSET 0x86
531#define QUERY_DEV_CAP_EQC_ENTRY_SZ_OFFSET 0x88
532#define QUERY_DEV_CAP_CQC_ENTRY_SZ_OFFSET 0x8a
533#define QUERY_DEV_CAP_SRQ_ENTRY_SZ_OFFSET 0x8c
534#define QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET 0x8e
535#define QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET 0x90
536#define QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET 0x92
Roland Dreier95d04f02008-07-23 08:12:26 -0700537#define QUERY_DEV_CAP_BMME_FLAGS_OFFSET 0x94
Roland Dreier225c7b12007-05-08 18:00:38 -0700538#define QUERY_DEV_CAP_RSVD_LKEY_OFFSET 0x98
539#define QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET 0xa0
Matan Barak955154f2013-01-30 23:07:10 +0000540#define QUERY_DEV_CAP_FW_REASSIGN_MAC 0x9d
Or Gerlitz7ffdf722013-12-23 16:09:43 +0200541#define QUERY_DEV_CAP_VXLAN 0x9e
Roland Dreier225c7b12007-05-08 18:00:38 -0700542
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300543 dev_cap->flags2 = 0;
Roland Dreier225c7b12007-05-08 18:00:38 -0700544 mailbox = mlx4_alloc_cmd_mailbox(dev);
545 if (IS_ERR(mailbox))
546 return PTR_ERR(mailbox);
547 outbox = mailbox->buf;
548
549 err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP,
Jack Morgenstein401453a2012-05-30 09:14:55 +0000550 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -0700551 if (err)
552 goto out;
553
554 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_QP_OFFSET);
555 dev_cap->reserved_qps = 1 << (field & 0xf);
556 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_OFFSET);
557 dev_cap->max_qps = 1 << (field & 0x1f);
558 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_SRQ_OFFSET);
559 dev_cap->reserved_srqs = 1 << (field >> 4);
560 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SRQ_OFFSET);
561 dev_cap->max_srqs = 1 << (field & 0x1f);
562 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_CQ_SZ_OFFSET);
563 dev_cap->max_cq_sz = 1 << field;
564 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_CQ_OFFSET);
565 dev_cap->reserved_cqs = 1 << (field & 0xf);
566 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_CQ_OFFSET);
567 dev_cap->max_cqs = 1 << (field & 0x1f);
568 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MPT_OFFSET);
569 dev_cap->max_mpts = 1 << (field & 0x3f);
570 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_EQ_OFFSET);
Yevgeny Petrilinbe504b02009-11-12 15:51:16 -0800571 dev_cap->reserved_eqs = field & 0xf;
Roland Dreier225c7b12007-05-08 18:00:38 -0700572 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_EQ_OFFSET);
Jack Morgenstein59208692007-12-10 05:25:23 +0200573 dev_cap->max_eqs = 1 << (field & 0xf);
Roland Dreier225c7b12007-05-08 18:00:38 -0700574 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MTT_OFFSET);
575 dev_cap->reserved_mtts = 1 << (field >> 4);
576 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MRW_SZ_OFFSET);
577 dev_cap->max_mrw_sz = 1 << field;
578 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MRW_OFFSET);
579 dev_cap->reserved_mrws = 1 << (field & 0xf);
580 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MTT_SEG_OFFSET);
581 dev_cap->max_mtt_seg = 1 << (field & 0x3f);
582 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_REQ_QP_OFFSET);
583 dev_cap->max_requester_per_qp = 1 << (field & 0x3f);
584 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_RES_QP_OFFSET);
585 dev_cap->max_responder_per_qp = 1 << (field & 0x3f);
Eli Cohenb832be12008-04-16 21:09:27 -0700586 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_GSO_OFFSET);
587 field &= 0x1f;
588 if (!field)
589 dev_cap->max_gso_sz = 0;
590 else
591 dev_cap->max_gso_sz = 1 << field;
592
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300593 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSS_OFFSET);
594 if (field & 0x20)
595 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS_XOR;
596 if (field & 0x10)
597 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS_TOP;
598 field &= 0xf;
599 if (field) {
600 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS;
601 dev_cap->max_rss_tbl_sz = 1 << field;
602 } else
603 dev_cap->max_rss_tbl_sz = 0;
Roland Dreier225c7b12007-05-08 18:00:38 -0700604 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_RDMA_OFFSET);
605 dev_cap->max_rdma_global = 1 << (field & 0x3f);
606 MLX4_GET(field, outbox, QUERY_DEV_CAP_ACK_DELAY_OFFSET);
607 dev_cap->local_ca_ack_delay = field & 0x1f;
Roland Dreier225c7b12007-05-08 18:00:38 -0700608 MLX4_GET(field, outbox, QUERY_DEV_CAP_VL_PORT_OFFSET);
Roland Dreier225c7b12007-05-08 18:00:38 -0700609 dev_cap->num_ports = field & 0xf;
Dotan Barak149983af2007-06-26 15:55:28 +0300610 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MSG_SZ_OFFSET);
611 dev_cap->max_msg_sz = 1 << (field & 0x1f);
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000612 MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET);
613 if (field & 0x80)
614 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_FS_EN;
615 dev_cap->fs_log_max_ucast_qp_range_size = field & 0x1f;
Matan Barak4de65802013-11-07 15:25:14 +0200616 MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
617 if (field & 0x80)
618 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_DMFS_IPOIB;
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +0000619 MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_MAX_QP_OFFSET);
620 dev_cap->fs_max_num_qp_per_entry = field;
Roland Dreier225c7b12007-05-08 18:00:38 -0700621 MLX4_GET(stat_rate, outbox, QUERY_DEV_CAP_RATE_SUPPORT_OFFSET);
622 dev_cap->stat_rate_support = stat_rate;
Eugenia Emantayevd9987352013-04-23 06:06:47 +0000623 MLX4_GET(field, outbox, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
624 if (field & 0x80)
625 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_TS;
Or Gerlitzccf86322011-07-07 19:19:29 +0000626 MLX4_GET(ext_flags, outbox, QUERY_DEV_CAP_EXT_FLAGS_OFFSET);
Or Gerlitz52eafc62011-06-15 14:41:42 +0000627 MLX4_GET(flags, outbox, QUERY_DEV_CAP_FLAGS_OFFSET);
Or Gerlitzccf86322011-07-07 19:19:29 +0000628 dev_cap->flags = flags | (u64)ext_flags << 32;
Roland Dreier225c7b12007-05-08 18:00:38 -0700629 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_UAR_OFFSET);
630 dev_cap->reserved_uars = field >> 4;
631 MLX4_GET(field, outbox, QUERY_DEV_CAP_UAR_SZ_OFFSET);
632 dev_cap->uar_size = 1 << ((field & 0x3f) + 20);
633 MLX4_GET(field, outbox, QUERY_DEV_CAP_PAGE_SZ_OFFSET);
634 dev_cap->min_page_sz = 1 << field;
635
636 MLX4_GET(field, outbox, QUERY_DEV_CAP_BF_OFFSET);
637 if (field & 0x80) {
638 MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET);
639 dev_cap->bf_reg_size = 1 << (field & 0x1f);
640 MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET);
Roland Dreierf5a49532011-01-10 17:42:05 -0800641 if ((1 << (field & 0x3f)) > (PAGE_SIZE / dev_cap->bf_reg_size))
Eli Cohen58d74bb2010-11-10 12:52:37 +0000642 field = 3;
Roland Dreier225c7b12007-05-08 18:00:38 -0700643 dev_cap->bf_regs_per_page = 1 << (field & 0x3f);
644 mlx4_dbg(dev, "BlueFlame available (reg size %d, regs/page %d)\n",
645 dev_cap->bf_reg_size, dev_cap->bf_regs_per_page);
646 } else {
647 dev_cap->bf_reg_size = 0;
648 mlx4_dbg(dev, "BlueFlame not available\n");
649 }
650
651 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SG_SQ_OFFSET);
652 dev_cap->max_sq_sg = field;
653 MLX4_GET(size, outbox, QUERY_DEV_CAP_MAX_DESC_SZ_SQ_OFFSET);
654 dev_cap->max_sq_desc_sz = size;
655
656 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_MCG_OFFSET);
657 dev_cap->max_qp_per_mcg = 1 << field;
658 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MCG_OFFSET);
659 dev_cap->reserved_mgms = field & 0xf;
660 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MCG_OFFSET);
661 dev_cap->max_mcgs = 1 << field;
662 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_PD_OFFSET);
663 dev_cap->reserved_pds = field >> 4;
664 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PD_OFFSET);
665 dev_cap->max_pds = 1 << (field & 0x3f);
Linus Torvaldsf470f8d2011-11-01 10:51:38 -0700666 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_XRC_OFFSET);
667 dev_cap->reserved_xrcds = field >> 4;
Dotan Barak426dd002012-08-23 14:09:04 +0000668 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_XRC_OFFSET);
Linus Torvaldsf470f8d2011-11-01 10:51:38 -0700669 dev_cap->max_xrcds = 1 << (field & 0x1f);
Roland Dreier225c7b12007-05-08 18:00:38 -0700670
671 MLX4_GET(size, outbox, QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET);
672 dev_cap->rdmarc_entry_sz = size;
673 MLX4_GET(size, outbox, QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET);
674 dev_cap->qpc_entry_sz = size;
675 MLX4_GET(size, outbox, QUERY_DEV_CAP_AUX_ENTRY_SZ_OFFSET);
676 dev_cap->aux_entry_sz = size;
677 MLX4_GET(size, outbox, QUERY_DEV_CAP_ALTC_ENTRY_SZ_OFFSET);
678 dev_cap->altc_entry_sz = size;
679 MLX4_GET(size, outbox, QUERY_DEV_CAP_EQC_ENTRY_SZ_OFFSET);
680 dev_cap->eqc_entry_sz = size;
681 MLX4_GET(size, outbox, QUERY_DEV_CAP_CQC_ENTRY_SZ_OFFSET);
682 dev_cap->cqc_entry_sz = size;
683 MLX4_GET(size, outbox, QUERY_DEV_CAP_SRQ_ENTRY_SZ_OFFSET);
684 dev_cap->srq_entry_sz = size;
685 MLX4_GET(size, outbox, QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET);
686 dev_cap->cmpt_entry_sz = size;
687 MLX4_GET(size, outbox, QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET);
688 dev_cap->mtt_entry_sz = size;
689 MLX4_GET(size, outbox, QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET);
690 dev_cap->dmpt_entry_sz = size;
691
692 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SRQ_SZ_OFFSET);
693 dev_cap->max_srq_sz = 1 << field;
694 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_SZ_OFFSET);
695 dev_cap->max_qp_sz = 1 << field;
696 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSZ_SRQ_OFFSET);
697 dev_cap->resize_srq = field & 1;
698 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SG_RQ_OFFSET);
699 dev_cap->max_rq_sg = field;
700 MLX4_GET(size, outbox, QUERY_DEV_CAP_MAX_DESC_SZ_RQ_OFFSET);
701 dev_cap->max_rq_desc_sz = size;
702
703 MLX4_GET(dev_cap->bmme_flags, outbox,
704 QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
705 MLX4_GET(dev_cap->reserved_lkey, outbox,
706 QUERY_DEV_CAP_RSVD_LKEY_OFFSET);
Matan Barak955154f2013-01-30 23:07:10 +0000707 MLX4_GET(field, outbox, QUERY_DEV_CAP_FW_REASSIGN_MAC);
708 if (field & 1<<6)
Or Gerlitz5930e8d2013-10-15 16:55:22 +0200709 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN;
Or Gerlitz7ffdf722013-12-23 16:09:43 +0200710 MLX4_GET(field, outbox, QUERY_DEV_CAP_VXLAN);
711 if (field & 1<<3)
712 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS;
Roland Dreier225c7b12007-05-08 18:00:38 -0700713 MLX4_GET(dev_cap->max_icm_sz, outbox,
714 QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET);
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +0000715 if (dev_cap->flags & MLX4_DEV_CAP_FLAG_COUNTERS)
716 MLX4_GET(dev_cap->max_counters, outbox,
717 QUERY_DEV_CAP_MAX_COUNTERS_OFFSET);
Roland Dreier225c7b12007-05-08 18:00:38 -0700718
Rony Efraim3f7fb022013-04-25 05:22:28 +0000719 MLX4_GET(field32, outbox, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET);
Jack Morgensteinb01978c2013-06-27 19:05:21 +0300720 if (field32 & (1 << 16))
721 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_UPDATE_QP;
Rony Efraim3f7fb022013-04-25 05:22:28 +0000722 if (field32 & (1 << 26))
723 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_VLAN_CONTROL;
Rony Efraime6b6a232013-04-25 05:22:29 +0000724 if (field32 & (1 << 20))
725 dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_FSM;
Rony Efraim3f7fb022013-04-25 05:22:28 +0000726
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700727 if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
728 for (i = 1; i <= dev_cap->num_ports; ++i) {
729 MLX4_GET(field, outbox, QUERY_DEV_CAP_VL_PORT_OFFSET);
730 dev_cap->max_vl[i] = field >> 4;
731 MLX4_GET(field, outbox, QUERY_DEV_CAP_MTU_WIDTH_OFFSET);
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -0700732 dev_cap->ib_mtu[i] = field >> 4;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700733 dev_cap->max_port_width[i] = field & 0xf;
734 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_GID_OFFSET);
735 dev_cap->max_gids[i] = 1 << (field & 0xf);
736 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PKEY_OFFSET);
737 dev_cap->max_pkeys[i] = 1 << (field & 0xf);
738 }
739 } else {
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700740#define QUERY_PORT_SUPPORTED_TYPE_OFFSET 0x00
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700741#define QUERY_PORT_MTU_OFFSET 0x01
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -0700742#define QUERY_PORT_ETH_MTU_OFFSET 0x02
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700743#define QUERY_PORT_WIDTH_OFFSET 0x06
744#define QUERY_PORT_MAX_GID_PKEY_OFFSET 0x07
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700745#define QUERY_PORT_MAX_MACVLAN_OFFSET 0x0a
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700746#define QUERY_PORT_MAX_VL_OFFSET 0x0b
Yevgeny Petriline65b9592008-10-26 17:13:24 +0200747#define QUERY_PORT_MAC_OFFSET 0x10
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000748#define QUERY_PORT_TRANS_VENDOR_OFFSET 0x18
749#define QUERY_PORT_WAVELENGTH_OFFSET 0x1c
750#define QUERY_PORT_TRANS_CODE_OFFSET 0x20
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700751
752 for (i = 1; i <= dev_cap->num_ports; ++i) {
753 err = mlx4_cmd_box(dev, 0, mailbox->dma, i, 0, MLX4_CMD_QUERY_PORT,
Jack Morgenstein401453a2012-05-30 09:14:55 +0000754 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700755 if (err)
756 goto out;
757
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700758 MLX4_GET(field, outbox, QUERY_PORT_SUPPORTED_TYPE_OFFSET);
759 dev_cap->supported_port_types[i] = field & 3;
Yevgeny Petrilin8d0fc7b2011-12-19 04:00:34 +0000760 dev_cap->suggested_type[i] = (field >> 3) & 1;
761 dev_cap->default_sense[i] = (field >> 4) & 1;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700762 MLX4_GET(field, outbox, QUERY_PORT_MTU_OFFSET);
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -0700763 dev_cap->ib_mtu[i] = field & 0xf;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700764 MLX4_GET(field, outbox, QUERY_PORT_WIDTH_OFFSET);
765 dev_cap->max_port_width[i] = field & 0xf;
766 MLX4_GET(field, outbox, QUERY_PORT_MAX_GID_PKEY_OFFSET);
767 dev_cap->max_gids[i] = 1 << (field >> 4);
768 dev_cap->max_pkeys[i] = 1 << (field & 0xf);
769 MLX4_GET(field, outbox, QUERY_PORT_MAX_VL_OFFSET);
770 dev_cap->max_vl[i] = field & 0xf;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700771 MLX4_GET(field, outbox, QUERY_PORT_MAX_MACVLAN_OFFSET);
772 dev_cap->log_max_macs[i] = field & 0xf;
773 dev_cap->log_max_vlans[i] = field >> 4;
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -0700774 MLX4_GET(dev_cap->eth_mtu[i], outbox, QUERY_PORT_ETH_MTU_OFFSET);
775 MLX4_GET(dev_cap->def_mac[i], outbox, QUERY_PORT_MAC_OFFSET);
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000776 MLX4_GET(field32, outbox, QUERY_PORT_TRANS_VENDOR_OFFSET);
777 dev_cap->trans_type[i] = field32 >> 24;
778 dev_cap->vendor_oui[i] = field32 & 0xffffff;
779 MLX4_GET(dev_cap->wavelength[i], outbox, QUERY_PORT_WAVELENGTH_OFFSET);
780 MLX4_GET(dev_cap->trans_code[i], outbox, QUERY_PORT_TRANS_CODE_OFFSET);
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700781 }
782 }
783
Roland Dreier95d04f02008-07-23 08:12:26 -0700784 mlx4_dbg(dev, "Base MM extensions: flags %08x, rsvd L_Key %08x\n",
785 dev_cap->bmme_flags, dev_cap->reserved_lkey);
Roland Dreier225c7b12007-05-08 18:00:38 -0700786
787 /*
788 * Each UAR has 4 EQ doorbells; so if a UAR is reserved, then
789 * we can't use any EQs whose doorbell falls on that page,
790 * even if the EQ itself isn't reserved.
791 */
792 dev_cap->reserved_eqs = max(dev_cap->reserved_uars * 4,
793 dev_cap->reserved_eqs);
794
795 mlx4_dbg(dev, "Max ICM size %lld MB\n",
796 (unsigned long long) dev_cap->max_icm_sz >> 20);
797 mlx4_dbg(dev, "Max QPs: %d, reserved QPs: %d, entry size: %d\n",
798 dev_cap->max_qps, dev_cap->reserved_qps, dev_cap->qpc_entry_sz);
799 mlx4_dbg(dev, "Max SRQs: %d, reserved SRQs: %d, entry size: %d\n",
800 dev_cap->max_srqs, dev_cap->reserved_srqs, dev_cap->srq_entry_sz);
801 mlx4_dbg(dev, "Max CQs: %d, reserved CQs: %d, entry size: %d\n",
802 dev_cap->max_cqs, dev_cap->reserved_cqs, dev_cap->cqc_entry_sz);
803 mlx4_dbg(dev, "Max EQs: %d, reserved EQs: %d, entry size: %d\n",
804 dev_cap->max_eqs, dev_cap->reserved_eqs, dev_cap->eqc_entry_sz);
805 mlx4_dbg(dev, "reserved MPTs: %d, reserved MTTs: %d\n",
806 dev_cap->reserved_mrws, dev_cap->reserved_mtts);
807 mlx4_dbg(dev, "Max PDs: %d, reserved PDs: %d, reserved UARs: %d\n",
808 dev_cap->max_pds, dev_cap->reserved_pds, dev_cap->reserved_uars);
809 mlx4_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n",
810 dev_cap->max_pds, dev_cap->reserved_mgms);
811 mlx4_dbg(dev, "Max CQEs: %d, max WQEs: %d, max SRQ WQEs: %d\n",
812 dev_cap->max_cq_sz, dev_cap->max_qp_sz, dev_cap->max_srq_sz);
813 mlx4_dbg(dev, "Local CA ACK delay: %d, max MTU: %d, port width cap: %d\n",
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -0700814 dev_cap->local_ca_ack_delay, 128 << dev_cap->ib_mtu[1],
Roland Dreier5ae2a7a2007-06-18 08:15:02 -0700815 dev_cap->max_port_width[1]);
Roland Dreier225c7b12007-05-08 18:00:38 -0700816 mlx4_dbg(dev, "Max SQ desc size: %d, max SQ S/G: %d\n",
817 dev_cap->max_sq_desc_sz, dev_cap->max_sq_sg);
818 mlx4_dbg(dev, "Max RQ desc size: %d, max RQ S/G: %d\n",
819 dev_cap->max_rq_desc_sz, dev_cap->max_rq_sg);
Eli Cohenb832be12008-04-16 21:09:27 -0700820 mlx4_dbg(dev, "Max GSO size: %d\n", dev_cap->max_gso_sz);
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +0000821 mlx4_dbg(dev, "Max counters: %d\n", dev_cap->max_counters);
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300822 mlx4_dbg(dev, "Max RSS Table size: %d\n", dev_cap->max_rss_tbl_sz);
Roland Dreier225c7b12007-05-08 18:00:38 -0700823
824 dump_dev_cap_flags(dev, dev_cap->flags);
Shlomo Pongratzb3416f42012-04-29 17:04:25 +0300825 dump_dev_cap_flags2(dev, dev_cap->flags2);
Roland Dreier225c7b12007-05-08 18:00:38 -0700826
827out:
828 mlx4_free_cmd_mailbox(dev, mailbox);
829 return err;
830}
831
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +0000832int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
833 struct mlx4_vhcr *vhcr,
834 struct mlx4_cmd_mailbox *inbox,
835 struct mlx4_cmd_mailbox *outbox,
836 struct mlx4_cmd_info *cmd)
837{
Jack Morgenstein2a4fae12012-08-03 08:40:50 +0000838 u64 flags;
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +0000839 int err = 0;
840 u8 field;
Shani Michaelicc1ade92013-02-06 16:19:10 +0000841 u32 bmme_flags;
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +0000842
843 err = mlx4_cmd_box(dev, 0, outbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP,
844 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
845 if (err)
846 return err;
847
Shani Michaelicc1ade92013-02-06 16:19:10 +0000848 /* add port mng change event capability and disable mw type 1
849 * unconditionally to slaves
850 */
Jack Morgenstein2a4fae12012-08-03 08:40:50 +0000851 MLX4_GET(flags, outbox->buf, QUERY_DEV_CAP_EXT_FLAGS_OFFSET);
852 flags |= MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV;
Shani Michaelicc1ade92013-02-06 16:19:10 +0000853 flags &= ~MLX4_DEV_CAP_FLAG_MEM_WINDOW;
Jack Morgenstein2a4fae12012-08-03 08:40:50 +0000854 MLX4_PUT(outbox->buf, flags, QUERY_DEV_CAP_EXT_FLAGS_OFFSET);
855
Amir Vadai30b40c32013-04-25 05:22:23 +0000856 /* For guests, disable timestamp */
857 MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
858 field &= 0x7f;
859 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
860
Or Gerlitz7ffdf722013-12-23 16:09:43 +0200861 /* For guests, disable vxlan tunneling */
862 MLX4_GET(field, outbox, QUERY_DEV_CAP_VXLAN);
863 field &= 0xf7;
864 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN);
865
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +0000866 /* For guests, report Blueflame disabled */
867 MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_BF_OFFSET);
868 field &= 0x7f;
869 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET);
870
Shani Michaelicc1ade92013-02-06 16:19:10 +0000871 /* For guests, disable mw type 2 */
872 MLX4_GET(bmme_flags, outbox, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
873 bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN;
874 MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
875
Jack Morgenstein0081c8f2013-03-07 03:46:53 +0000876 /* turn off device-managed steering capability if not enabled */
877 if (dev->caps.steering_mode != MLX4_STEERING_MODE_DEVICE_MANAGED) {
878 MLX4_GET(field, outbox->buf,
879 QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET);
880 field &= 0x7f;
881 MLX4_PUT(outbox->buf, field,
882 QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET);
883 }
Matan Barak4de65802013-11-07 15:25:14 +0200884
885 /* turn off ipoib managed steering for guests */
886 MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
887 field &= ~0x80;
888 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
889
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +0000890 return 0;
891}
892
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000893int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
894 struct mlx4_vhcr *vhcr,
895 struct mlx4_cmd_mailbox *inbox,
896 struct mlx4_cmd_mailbox *outbox,
897 struct mlx4_cmd_info *cmd)
898{
Rony Efraim0eb62b92013-04-25 05:22:26 +0000899 struct mlx4_priv *priv = mlx4_priv(dev);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000900 u64 def_mac;
901 u8 port_type;
Jack Morgenstein66349612012-06-19 11:21:44 +0300902 u16 short_field;
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000903 int err;
Rony Efraim948e3062013-06-13 13:19:11 +0300904 int admin_link_state;
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000905
Jack Morgenstein105c3202012-06-19 11:21:43 +0300906#define MLX4_VF_PORT_NO_LINK_SENSE_MASK 0xE0
Rony Efraim948e3062013-06-13 13:19:11 +0300907#define MLX4_PORT_LINK_UP_MASK 0x80
Jack Morgenstein66349612012-06-19 11:21:44 +0300908#define QUERY_PORT_CUR_MAX_PKEY_OFFSET 0x0c
909#define QUERY_PORT_CUR_MAX_GID_OFFSET 0x0e
Yevgeny Petrilin95f56e72011-12-29 07:42:39 +0000910
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000911 err = mlx4_cmd_box(dev, 0, outbox->dma, vhcr->in_modifier, 0,
912 MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B,
913 MLX4_CMD_NATIVE);
914
915 if (!err && dev->caps.function != slave) {
Or Gerlitz0508ad62013-08-01 19:55:00 +0300916 def_mac = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.mac;
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000917 MLX4_PUT(outbox->buf, def_mac, QUERY_PORT_MAC_OFFSET);
918
919 /* get port type - currently only eth is enabled */
920 MLX4_GET(port_type, outbox->buf,
921 QUERY_PORT_SUPPORTED_TYPE_OFFSET);
922
Jack Morgenstein105c3202012-06-19 11:21:43 +0300923 /* No link sensing allowed */
924 port_type &= MLX4_VF_PORT_NO_LINK_SENSE_MASK;
925 /* set port type to currently operating port type */
926 port_type |= (dev->caps.port_type[vhcr->in_modifier] & 0x3);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000927
Rony Efraim948e3062013-06-13 13:19:11 +0300928 admin_link_state = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.link_state;
929 if (IFLA_VF_LINK_STATE_ENABLE == admin_link_state)
930 port_type |= MLX4_PORT_LINK_UP_MASK;
931 else if (IFLA_VF_LINK_STATE_DISABLE == admin_link_state)
932 port_type &= ~MLX4_PORT_LINK_UP_MASK;
933
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000934 MLX4_PUT(outbox->buf, port_type,
935 QUERY_PORT_SUPPORTED_TYPE_OFFSET);
Jack Morgenstein66349612012-06-19 11:21:44 +0300936
937 short_field = 1; /* slave max gids */
938 MLX4_PUT(outbox->buf, short_field,
939 QUERY_PORT_CUR_MAX_GID_OFFSET);
940
941 short_field = dev->caps.pkey_table_len[vhcr->in_modifier];
942 MLX4_PUT(outbox->buf, short_field,
943 QUERY_PORT_CUR_MAX_PKEY_OFFSET);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +0000944 }
945
946 return err;
947}
948
Jack Morgenstein66349612012-06-19 11:21:44 +0300949int mlx4_get_slave_pkey_gid_tbl_len(struct mlx4_dev *dev, u8 port,
950 int *gid_tbl_len, int *pkey_tbl_len)
951{
952 struct mlx4_cmd_mailbox *mailbox;
953 u32 *outbox;
954 u16 field;
955 int err;
956
957 mailbox = mlx4_alloc_cmd_mailbox(dev);
958 if (IS_ERR(mailbox))
959 return PTR_ERR(mailbox);
960
961 err = mlx4_cmd_box(dev, 0, mailbox->dma, port, 0,
962 MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B,
963 MLX4_CMD_WRAPPED);
964 if (err)
965 goto out;
966
967 outbox = mailbox->buf;
968
969 MLX4_GET(field, outbox, QUERY_PORT_CUR_MAX_GID_OFFSET);
970 *gid_tbl_len = field;
971
972 MLX4_GET(field, outbox, QUERY_PORT_CUR_MAX_PKEY_OFFSET);
973 *pkey_tbl_len = field;
974
975out:
976 mlx4_free_cmd_mailbox(dev, mailbox);
977 return err;
978}
979EXPORT_SYMBOL(mlx4_get_slave_pkey_gid_tbl_len);
980
Roland Dreier225c7b12007-05-08 18:00:38 -0700981int mlx4_map_cmd(struct mlx4_dev *dev, u16 op, struct mlx4_icm *icm, u64 virt)
982{
983 struct mlx4_cmd_mailbox *mailbox;
984 struct mlx4_icm_iter iter;
985 __be64 *pages;
986 int lg;
987 int nent = 0;
988 int i;
989 int err = 0;
990 int ts = 0, tc = 0;
991
992 mailbox = mlx4_alloc_cmd_mailbox(dev);
993 if (IS_ERR(mailbox))
994 return PTR_ERR(mailbox);
Roland Dreier225c7b12007-05-08 18:00:38 -0700995 pages = mailbox->buf;
996
997 for (mlx4_icm_first(icm, &iter);
998 !mlx4_icm_last(&iter);
999 mlx4_icm_next(&iter)) {
1000 /*
1001 * We have to pass pages that are aligned to their
1002 * size, so find the least significant 1 in the
1003 * address or size and use that as our log2 size.
1004 */
1005 lg = ffs(mlx4_icm_addr(&iter) | mlx4_icm_size(&iter)) - 1;
1006 if (lg < MLX4_ICM_PAGE_SHIFT) {
1007 mlx4_warn(dev, "Got FW area not aligned to %d (%llx/%lx).\n",
1008 MLX4_ICM_PAGE_SIZE,
1009 (unsigned long long) mlx4_icm_addr(&iter),
1010 mlx4_icm_size(&iter));
1011 err = -EINVAL;
1012 goto out;
1013 }
1014
1015 for (i = 0; i < mlx4_icm_size(&iter) >> lg; ++i) {
1016 if (virt != -1) {
1017 pages[nent * 2] = cpu_to_be64(virt);
1018 virt += 1 << lg;
1019 }
1020
1021 pages[nent * 2 + 1] =
1022 cpu_to_be64((mlx4_icm_addr(&iter) + (i << lg)) |
1023 (lg - MLX4_ICM_PAGE_SHIFT));
1024 ts += 1 << (lg - 10);
1025 ++tc;
1026
1027 if (++nent == MLX4_MAILBOX_SIZE / 16) {
1028 err = mlx4_cmd(dev, mailbox->dma, nent, 0, op,
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001029 MLX4_CMD_TIME_CLASS_B,
1030 MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001031 if (err)
1032 goto out;
1033 nent = 0;
1034 }
1035 }
1036 }
1037
1038 if (nent)
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001039 err = mlx4_cmd(dev, mailbox->dma, nent, 0, op,
1040 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001041 if (err)
1042 goto out;
1043
1044 switch (op) {
1045 case MLX4_CMD_MAP_FA:
1046 mlx4_dbg(dev, "Mapped %d chunks/%d KB for FW.\n", tc, ts);
1047 break;
1048 case MLX4_CMD_MAP_ICM_AUX:
1049 mlx4_dbg(dev, "Mapped %d chunks/%d KB for ICM aux.\n", tc, ts);
1050 break;
1051 case MLX4_CMD_MAP_ICM:
1052 mlx4_dbg(dev, "Mapped %d chunks/%d KB at %llx for ICM.\n",
1053 tc, ts, (unsigned long long) virt - (ts << 10));
1054 break;
1055 }
1056
1057out:
1058 mlx4_free_cmd_mailbox(dev, mailbox);
1059 return err;
1060}
1061
1062int mlx4_MAP_FA(struct mlx4_dev *dev, struct mlx4_icm *icm)
1063{
1064 return mlx4_map_cmd(dev, MLX4_CMD_MAP_FA, icm, -1);
1065}
1066
1067int mlx4_UNMAP_FA(struct mlx4_dev *dev)
1068{
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001069 return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_UNMAP_FA,
1070 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001071}
1072
1073
1074int mlx4_RUN_FW(struct mlx4_dev *dev)
1075{
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001076 return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_RUN_FW,
1077 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001078}
1079
1080int mlx4_QUERY_FW(struct mlx4_dev *dev)
1081{
1082 struct mlx4_fw *fw = &mlx4_priv(dev)->fw;
1083 struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
1084 struct mlx4_cmd_mailbox *mailbox;
1085 u32 *outbox;
1086 int err = 0;
1087 u64 fw_ver;
Roland Dreierfe409002007-06-07 23:24:36 -07001088 u16 cmd_if_rev;
Roland Dreier225c7b12007-05-08 18:00:38 -07001089 u8 lg;
1090
1091#define QUERY_FW_OUT_SIZE 0x100
1092#define QUERY_FW_VER_OFFSET 0x00
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001093#define QUERY_FW_PPF_ID 0x09
Roland Dreierfe409002007-06-07 23:24:36 -07001094#define QUERY_FW_CMD_IF_REV_OFFSET 0x0a
Roland Dreier225c7b12007-05-08 18:00:38 -07001095#define QUERY_FW_MAX_CMD_OFFSET 0x0f
1096#define QUERY_FW_ERR_START_OFFSET 0x30
1097#define QUERY_FW_ERR_SIZE_OFFSET 0x38
1098#define QUERY_FW_ERR_BAR_OFFSET 0x3c
1099
1100#define QUERY_FW_SIZE_OFFSET 0x00
1101#define QUERY_FW_CLR_INT_BASE_OFFSET 0x20
1102#define QUERY_FW_CLR_INT_BAR_OFFSET 0x28
1103
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001104#define QUERY_FW_COMM_BASE_OFFSET 0x40
1105#define QUERY_FW_COMM_BAR_OFFSET 0x48
1106
Eugenia Emantayevddd8a6c2013-04-23 06:06:48 +00001107#define QUERY_FW_CLOCK_OFFSET 0x50
1108#define QUERY_FW_CLOCK_BAR 0x58
1109
Roland Dreier225c7b12007-05-08 18:00:38 -07001110 mailbox = mlx4_alloc_cmd_mailbox(dev);
1111 if (IS_ERR(mailbox))
1112 return PTR_ERR(mailbox);
1113 outbox = mailbox->buf;
1114
1115 err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_FW,
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001116 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001117 if (err)
1118 goto out;
1119
1120 MLX4_GET(fw_ver, outbox, QUERY_FW_VER_OFFSET);
1121 /*
Roland Dreier3e1db332007-06-03 19:47:10 -07001122 * FW subminor version is at more significant bits than minor
Roland Dreier225c7b12007-05-08 18:00:38 -07001123 * version, so swap here.
1124 */
1125 dev->caps.fw_ver = (fw_ver & 0xffff00000000ull) |
1126 ((fw_ver & 0xffff0000ull) >> 16) |
1127 ((fw_ver & 0x0000ffffull) << 16);
1128
Jack Morgenstein752a50c2012-06-19 11:21:33 +03001129 MLX4_GET(lg, outbox, QUERY_FW_PPF_ID);
1130 dev->caps.function = lg;
1131
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +00001132 if (mlx4_is_slave(dev))
1133 goto out;
1134
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001135
Roland Dreierfe409002007-06-07 23:24:36 -07001136 MLX4_GET(cmd_if_rev, outbox, QUERY_FW_CMD_IF_REV_OFFSET);
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001137 if (cmd_if_rev < MLX4_COMMAND_INTERFACE_MIN_REV ||
1138 cmd_if_rev > MLX4_COMMAND_INTERFACE_MAX_REV) {
Roland Dreierfe409002007-06-07 23:24:36 -07001139 mlx4_err(dev, "Installed FW has unsupported "
1140 "command interface revision %d.\n",
1141 cmd_if_rev);
1142 mlx4_err(dev, "(Installed FW version is %d.%d.%03d)\n",
1143 (int) (dev->caps.fw_ver >> 32),
1144 (int) (dev->caps.fw_ver >> 16) & 0xffff,
1145 (int) dev->caps.fw_ver & 0xffff);
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001146 mlx4_err(dev, "This driver version supports only revisions %d to %d.\n",
1147 MLX4_COMMAND_INTERFACE_MIN_REV, MLX4_COMMAND_INTERFACE_MAX_REV);
Roland Dreierfe409002007-06-07 23:24:36 -07001148 err = -ENODEV;
1149 goto out;
1150 }
1151
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001152 if (cmd_if_rev < MLX4_COMMAND_INTERFACE_NEW_PORT_CMDS)
1153 dev->flags |= MLX4_FLAG_OLD_PORT_CMDS;
1154
Roland Dreier225c7b12007-05-08 18:00:38 -07001155 MLX4_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
1156 cmd->max_cmds = 1 << lg;
1157
Roland Dreierfe409002007-06-07 23:24:36 -07001158 mlx4_dbg(dev, "FW version %d.%d.%03d (cmd intf rev %d), max commands %d\n",
Roland Dreier225c7b12007-05-08 18:00:38 -07001159 (int) (dev->caps.fw_ver >> 32),
1160 (int) (dev->caps.fw_ver >> 16) & 0xffff,
1161 (int) dev->caps.fw_ver & 0xffff,
Roland Dreierfe409002007-06-07 23:24:36 -07001162 cmd_if_rev, cmd->max_cmds);
Roland Dreier225c7b12007-05-08 18:00:38 -07001163
1164 MLX4_GET(fw->catas_offset, outbox, QUERY_FW_ERR_START_OFFSET);
1165 MLX4_GET(fw->catas_size, outbox, QUERY_FW_ERR_SIZE_OFFSET);
1166 MLX4_GET(fw->catas_bar, outbox, QUERY_FW_ERR_BAR_OFFSET);
1167 fw->catas_bar = (fw->catas_bar >> 6) * 2;
1168
1169 mlx4_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x, BAR %d\n",
1170 (unsigned long long) fw->catas_offset, fw->catas_size, fw->catas_bar);
1171
1172 MLX4_GET(fw->fw_pages, outbox, QUERY_FW_SIZE_OFFSET);
1173 MLX4_GET(fw->clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET);
1174 MLX4_GET(fw->clr_int_bar, outbox, QUERY_FW_CLR_INT_BAR_OFFSET);
1175 fw->clr_int_bar = (fw->clr_int_bar >> 6) * 2;
1176
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001177 MLX4_GET(fw->comm_base, outbox, QUERY_FW_COMM_BASE_OFFSET);
1178 MLX4_GET(fw->comm_bar, outbox, QUERY_FW_COMM_BAR_OFFSET);
1179 fw->comm_bar = (fw->comm_bar >> 6) * 2;
1180 mlx4_dbg(dev, "Communication vector bar:%d offset:0x%llx\n",
1181 fw->comm_bar, fw->comm_base);
Roland Dreier225c7b12007-05-08 18:00:38 -07001182 mlx4_dbg(dev, "FW size %d KB\n", fw->fw_pages >> 2);
1183
Eugenia Emantayevddd8a6c2013-04-23 06:06:48 +00001184 MLX4_GET(fw->clock_offset, outbox, QUERY_FW_CLOCK_OFFSET);
1185 MLX4_GET(fw->clock_bar, outbox, QUERY_FW_CLOCK_BAR);
1186 fw->clock_bar = (fw->clock_bar >> 6) * 2;
1187 mlx4_dbg(dev, "Internal clock bar:%d offset:0x%llx\n",
1188 fw->clock_bar, fw->clock_offset);
1189
Roland Dreier225c7b12007-05-08 18:00:38 -07001190 /*
1191 * Round up number of system pages needed in case
1192 * MLX4_ICM_PAGE_SIZE < PAGE_SIZE.
1193 */
1194 fw->fw_pages =
1195 ALIGN(fw->fw_pages, PAGE_SIZE / MLX4_ICM_PAGE_SIZE) >>
1196 (PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT);
1197
1198 mlx4_dbg(dev, "Clear int @ %llx, BAR %d\n",
1199 (unsigned long long) fw->clr_int_base, fw->clr_int_bar);
1200
1201out:
1202 mlx4_free_cmd_mailbox(dev, mailbox);
1203 return err;
1204}
1205
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +00001206int mlx4_QUERY_FW_wrapper(struct mlx4_dev *dev, int slave,
1207 struct mlx4_vhcr *vhcr,
1208 struct mlx4_cmd_mailbox *inbox,
1209 struct mlx4_cmd_mailbox *outbox,
1210 struct mlx4_cmd_info *cmd)
1211{
1212 u8 *outbuf;
1213 int err;
1214
1215 outbuf = outbox->buf;
1216 err = mlx4_cmd_box(dev, 0, outbox->dma, 0, 0, MLX4_CMD_QUERY_FW,
1217 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
1218 if (err)
1219 return err;
1220
Jack Morgenstein752a50c2012-06-19 11:21:33 +03001221 /* for slaves, set pci PPF ID to invalid and zero out everything
1222 * else except FW version */
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +00001223 outbuf[0] = outbuf[1] = 0;
1224 memset(&outbuf[8], 0, QUERY_FW_OUT_SIZE - 8);
Jack Morgenstein752a50c2012-06-19 11:21:33 +03001225 outbuf[QUERY_FW_PPF_ID] = MLX4_INVALID_SLAVE_ID;
1226
Jack Morgensteinb91cb3e2012-05-30 09:14:53 +00001227 return 0;
1228}
1229
Roland Dreier225c7b12007-05-08 18:00:38 -07001230static void get_board_id(void *vsd, char *board_id)
1231{
1232 int i;
1233
1234#define VSD_OFFSET_SIG1 0x00
1235#define VSD_OFFSET_SIG2 0xde
1236#define VSD_OFFSET_MLX_BOARD_ID 0xd0
1237#define VSD_OFFSET_TS_BOARD_ID 0x20
1238
1239#define VSD_SIGNATURE_TOPSPIN 0x5ad
1240
1241 memset(board_id, 0, MLX4_BOARD_ID_LEN);
1242
1243 if (be16_to_cpup(vsd + VSD_OFFSET_SIG1) == VSD_SIGNATURE_TOPSPIN &&
1244 be16_to_cpup(vsd + VSD_OFFSET_SIG2) == VSD_SIGNATURE_TOPSPIN) {
1245 strlcpy(board_id, vsd + VSD_OFFSET_TS_BOARD_ID, MLX4_BOARD_ID_LEN);
1246 } else {
1247 /*
1248 * The board ID is a string but the firmware byte
1249 * swaps each 4-byte word before passing it back to
1250 * us. Therefore we need to swab it before printing.
1251 */
1252 for (i = 0; i < 4; ++i)
1253 ((u32 *) board_id)[i] =
1254 swab32(*(u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4));
1255 }
1256}
1257
1258int mlx4_QUERY_ADAPTER(struct mlx4_dev *dev, struct mlx4_adapter *adapter)
1259{
1260 struct mlx4_cmd_mailbox *mailbox;
1261 u32 *outbox;
1262 int err;
1263
1264#define QUERY_ADAPTER_OUT_SIZE 0x100
Roland Dreier225c7b12007-05-08 18:00:38 -07001265#define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10
1266#define QUERY_ADAPTER_VSD_OFFSET 0x20
1267
1268 mailbox = mlx4_alloc_cmd_mailbox(dev);
1269 if (IS_ERR(mailbox))
1270 return PTR_ERR(mailbox);
1271 outbox = mailbox->buf;
1272
1273 err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_ADAPTER,
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001274 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001275 if (err)
1276 goto out;
1277
Roland Dreier225c7b12007-05-08 18:00:38 -07001278 MLX4_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET);
1279
1280 get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4,
1281 adapter->board_id);
1282
1283out:
1284 mlx4_free_cmd_mailbox(dev, mailbox);
1285 return err;
1286}
1287
1288int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param)
1289{
1290 struct mlx4_cmd_mailbox *mailbox;
1291 __be32 *inbox;
1292 int err;
1293
1294#define INIT_HCA_IN_SIZE 0x200
1295#define INIT_HCA_VERSION_OFFSET 0x000
1296#define INIT_HCA_VERSION 2
Or Gerlitz7ffdf722013-12-23 16:09:43 +02001297#define INIT_HCA_VXLAN_OFFSET 0x0c
Eli Cohenc57e20dcf2009-09-24 11:03:03 -07001298#define INIT_HCA_CACHELINE_SZ_OFFSET 0x0e
Roland Dreier225c7b12007-05-08 18:00:38 -07001299#define INIT_HCA_FLAGS_OFFSET 0x014
1300#define INIT_HCA_QPC_OFFSET 0x020
1301#define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10)
1302#define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17)
1303#define INIT_HCA_SRQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x28)
1304#define INIT_HCA_LOG_SRQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x2f)
1305#define INIT_HCA_CQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x30)
1306#define INIT_HCA_LOG_CQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x37)
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001307#define INIT_HCA_EQE_CQE_OFFSETS (INIT_HCA_QPC_OFFSET + 0x38)
Roland Dreier225c7b12007-05-08 18:00:38 -07001308#define INIT_HCA_ALTC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x40)
1309#define INIT_HCA_AUXC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x50)
1310#define INIT_HCA_EQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x60)
1311#define INIT_HCA_LOG_EQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x67)
1312#define INIT_HCA_RDMARC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x70)
1313#define INIT_HCA_LOG_RD_OFFSET (INIT_HCA_QPC_OFFSET + 0x77)
1314#define INIT_HCA_MCAST_OFFSET 0x0c0
1315#define INIT_HCA_MC_BASE_OFFSET (INIT_HCA_MCAST_OFFSET + 0x00)
1316#define INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x12)
1317#define INIT_HCA_LOG_MC_HASH_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x16)
Yevgeny Petrilin16792002011-03-22 22:38:31 +00001318#define INIT_HCA_UC_STEERING_OFFSET (INIT_HCA_MCAST_OFFSET + 0x18)
Roland Dreier225c7b12007-05-08 18:00:38 -07001319#define INIT_HCA_LOG_MC_TABLE_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x1b)
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001320#define INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN 0x6
1321#define INIT_HCA_FS_PARAM_OFFSET 0x1d0
1322#define INIT_HCA_FS_BASE_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x00)
1323#define INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x12)
1324#define INIT_HCA_FS_LOG_TABLE_SZ_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x1b)
1325#define INIT_HCA_FS_ETH_BITS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x21)
1326#define INIT_HCA_FS_ETH_NUM_ADDRS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x22)
1327#define INIT_HCA_FS_IB_BITS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x25)
1328#define INIT_HCA_FS_IB_NUM_ADDRS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x26)
Roland Dreier225c7b12007-05-08 18:00:38 -07001329#define INIT_HCA_TPT_OFFSET 0x0f0
1330#define INIT_HCA_DMPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x00)
Shani Michaelie4488342013-02-06 16:19:11 +00001331#define INIT_HCA_TPT_MW_OFFSET (INIT_HCA_TPT_OFFSET + 0x08)
Roland Dreier225c7b12007-05-08 18:00:38 -07001332#define INIT_HCA_LOG_MPT_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x0b)
1333#define INIT_HCA_MTT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x10)
1334#define INIT_HCA_CMPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x18)
1335#define INIT_HCA_UAR_OFFSET 0x120
1336#define INIT_HCA_LOG_UAR_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0a)
1337#define INIT_HCA_UAR_PAGE_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0b)
1338
1339 mailbox = mlx4_alloc_cmd_mailbox(dev);
1340 if (IS_ERR(mailbox))
1341 return PTR_ERR(mailbox);
1342 inbox = mailbox->buf;
1343
Roland Dreier225c7b12007-05-08 18:00:38 -07001344 *((u8 *) mailbox->buf + INIT_HCA_VERSION_OFFSET) = INIT_HCA_VERSION;
1345
Eli Cohenc57e20dcf2009-09-24 11:03:03 -07001346 *((u8 *) mailbox->buf + INIT_HCA_CACHELINE_SZ_OFFSET) =
1347 (ilog2(cache_line_size()) - 4) << 5;
1348
Roland Dreier225c7b12007-05-08 18:00:38 -07001349#if defined(__LITTLE_ENDIAN)
1350 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) &= ~cpu_to_be32(1 << 1);
1351#elif defined(__BIG_ENDIAN)
1352 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 1);
1353#else
1354#error Host endianness not defined
1355#endif
1356 /* Check port for UD address vector: */
1357 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1);
1358
Eli Cohen8ff095e2008-04-16 21:01:10 -07001359 /* Enable IPoIB checksumming if we can: */
1360 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IPOIB_CSUM)
1361 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 3);
1362
Jack Morgenstein51f5f0e2008-07-22 14:19:37 -07001363 /* Enable QoS support if module parameter set */
1364 if (enable_qos)
1365 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 2);
1366
Or Gerlitzf2a3f6a2011-06-15 14:47:14 +00001367 /* enable counters */
1368 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)
1369 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 4);
1370
Or Gerlitz08ff3232012-10-21 14:59:24 +00001371 /* CX3 is capable of extending CQEs/EQEs from 32 to 64 bytes */
1372 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_64B_EQE) {
1373 *(inbox + INIT_HCA_EQE_CQE_OFFSETS / 4) |= cpu_to_be32(1 << 29);
1374 dev->caps.eqe_size = 64;
1375 dev->caps.eqe_factor = 1;
1376 } else {
1377 dev->caps.eqe_size = 32;
1378 dev->caps.eqe_factor = 0;
1379 }
1380
1381 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_64B_CQE) {
1382 *(inbox + INIT_HCA_EQE_CQE_OFFSETS / 4) |= cpu_to_be32(1 << 30);
1383 dev->caps.cqe_size = 64;
1384 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_64B_CQE;
1385 } else {
1386 dev->caps.cqe_size = 32;
1387 }
1388
Roland Dreier225c7b12007-05-08 18:00:38 -07001389 /* QPC/EEC/CQC/EQC/RDMARC attributes */
1390
1391 MLX4_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET);
1392 MLX4_PUT(inbox, param->log_num_qps, INIT_HCA_LOG_QP_OFFSET);
1393 MLX4_PUT(inbox, param->srqc_base, INIT_HCA_SRQC_BASE_OFFSET);
1394 MLX4_PUT(inbox, param->log_num_srqs, INIT_HCA_LOG_SRQ_OFFSET);
1395 MLX4_PUT(inbox, param->cqc_base, INIT_HCA_CQC_BASE_OFFSET);
1396 MLX4_PUT(inbox, param->log_num_cqs, INIT_HCA_LOG_CQ_OFFSET);
1397 MLX4_PUT(inbox, param->altc_base, INIT_HCA_ALTC_BASE_OFFSET);
1398 MLX4_PUT(inbox, param->auxc_base, INIT_HCA_AUXC_BASE_OFFSET);
1399 MLX4_PUT(inbox, param->eqc_base, INIT_HCA_EQC_BASE_OFFSET);
1400 MLX4_PUT(inbox, param->log_num_eqs, INIT_HCA_LOG_EQ_OFFSET);
1401 MLX4_PUT(inbox, param->rdmarc_base, INIT_HCA_RDMARC_BASE_OFFSET);
1402 MLX4_PUT(inbox, param->log_rd_per_qp, INIT_HCA_LOG_RD_OFFSET);
1403
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001404 /* steering attributes */
1405 if (dev->caps.steering_mode ==
1406 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1407 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |=
1408 cpu_to_be32(1 <<
1409 INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN);
Roland Dreier225c7b12007-05-08 18:00:38 -07001410
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001411 MLX4_PUT(inbox, param->mc_base, INIT_HCA_FS_BASE_OFFSET);
1412 MLX4_PUT(inbox, param->log_mc_entry_sz,
1413 INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET);
1414 MLX4_PUT(inbox, param->log_mc_table_sz,
1415 INIT_HCA_FS_LOG_TABLE_SZ_OFFSET);
1416 /* Enable Ethernet flow steering
1417 * with udp unicast and tcp unicast
1418 */
Hadar Hen Zion23537b72013-01-30 23:07:09 +00001419 MLX4_PUT(inbox, (u8) (MLX4_FS_UDP_UC_EN | MLX4_FS_TCP_UC_EN),
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001420 INIT_HCA_FS_ETH_BITS_OFFSET);
1421 MLX4_PUT(inbox, (u16) MLX4_FS_NUM_OF_L2_ADDR,
1422 INIT_HCA_FS_ETH_NUM_ADDRS_OFFSET);
1423 /* Enable IPoIB flow steering
1424 * with udp unicast and tcp unicast
1425 */
Hadar Hen Zion23537b72013-01-30 23:07:09 +00001426 MLX4_PUT(inbox, (u8) (MLX4_FS_UDP_UC_EN | MLX4_FS_TCP_UC_EN),
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001427 INIT_HCA_FS_IB_BITS_OFFSET);
1428 MLX4_PUT(inbox, (u16) MLX4_FS_NUM_OF_L2_ADDR,
1429 INIT_HCA_FS_IB_NUM_ADDRS_OFFSET);
1430 } else {
1431 MLX4_PUT(inbox, param->mc_base, INIT_HCA_MC_BASE_OFFSET);
1432 MLX4_PUT(inbox, param->log_mc_entry_sz,
1433 INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET);
1434 MLX4_PUT(inbox, param->log_mc_hash_sz,
1435 INIT_HCA_LOG_MC_HASH_SZ_OFFSET);
1436 MLX4_PUT(inbox, param->log_mc_table_sz,
1437 INIT_HCA_LOG_MC_TABLE_SZ_OFFSET);
1438 if (dev->caps.steering_mode == MLX4_STEERING_MODE_B0)
1439 MLX4_PUT(inbox, (u8) (1 << 3),
1440 INIT_HCA_UC_STEERING_OFFSET);
1441 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001442
1443 /* TPT attributes */
1444
1445 MLX4_PUT(inbox, param->dmpt_base, INIT_HCA_DMPT_BASE_OFFSET);
Shani Michaelie4488342013-02-06 16:19:11 +00001446 MLX4_PUT(inbox, param->mw_enabled, INIT_HCA_TPT_MW_OFFSET);
Roland Dreier225c7b12007-05-08 18:00:38 -07001447 MLX4_PUT(inbox, param->log_mpt_sz, INIT_HCA_LOG_MPT_SZ_OFFSET);
1448 MLX4_PUT(inbox, param->mtt_base, INIT_HCA_MTT_BASE_OFFSET);
1449 MLX4_PUT(inbox, param->cmpt_base, INIT_HCA_CMPT_BASE_OFFSET);
1450
1451 /* UAR attributes */
1452
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001453 MLX4_PUT(inbox, param->uar_page_sz, INIT_HCA_UAR_PAGE_SZ_OFFSET);
Roland Dreier225c7b12007-05-08 18:00:38 -07001454 MLX4_PUT(inbox, param->log_uar_sz, INIT_HCA_LOG_UAR_SZ_OFFSET);
1455
Or Gerlitz7ffdf722013-12-23 16:09:43 +02001456 /* set parser VXLAN attributes */
1457 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS) {
1458 u8 parser_params = 0;
1459 MLX4_PUT(inbox, parser_params, INIT_HCA_VXLAN_OFFSET);
1460 }
1461
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001462 err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_INIT_HCA, 10000,
1463 MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001464
1465 if (err)
1466 mlx4_err(dev, "INIT_HCA returns %d\n", err);
1467
1468 mlx4_free_cmd_mailbox(dev, mailbox);
1469 return err;
1470}
1471
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001472int mlx4_QUERY_HCA(struct mlx4_dev *dev,
1473 struct mlx4_init_hca_param *param)
1474{
1475 struct mlx4_cmd_mailbox *mailbox;
1476 __be32 *outbox;
Jack Morgenstein7b8157b2012-12-06 17:11:59 +00001477 u32 dword_field;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001478 int err;
Or Gerlitz08ff3232012-10-21 14:59:24 +00001479 u8 byte_field;
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001480
1481#define QUERY_HCA_GLOBAL_CAPS_OFFSET 0x04
Eugenia Emantayevddd8a6c2013-04-23 06:06:48 +00001482#define QUERY_HCA_CORE_CLOCK_OFFSET 0x0c
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001483
1484 mailbox = mlx4_alloc_cmd_mailbox(dev);
1485 if (IS_ERR(mailbox))
1486 return PTR_ERR(mailbox);
1487 outbox = mailbox->buf;
1488
1489 err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0,
1490 MLX4_CMD_QUERY_HCA,
1491 MLX4_CMD_TIME_CLASS_B,
1492 !mlx4_is_slave(dev));
1493 if (err)
1494 goto out;
1495
1496 MLX4_GET(param->global_caps, outbox, QUERY_HCA_GLOBAL_CAPS_OFFSET);
Eugenia Emantayevddd8a6c2013-04-23 06:06:48 +00001497 MLX4_GET(param->hca_core_clock, outbox, QUERY_HCA_CORE_CLOCK_OFFSET);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001498
1499 /* QPC/EEC/CQC/EQC/RDMARC attributes */
1500
1501 MLX4_GET(param->qpc_base, outbox, INIT_HCA_QPC_BASE_OFFSET);
1502 MLX4_GET(param->log_num_qps, outbox, INIT_HCA_LOG_QP_OFFSET);
1503 MLX4_GET(param->srqc_base, outbox, INIT_HCA_SRQC_BASE_OFFSET);
1504 MLX4_GET(param->log_num_srqs, outbox, INIT_HCA_LOG_SRQ_OFFSET);
1505 MLX4_GET(param->cqc_base, outbox, INIT_HCA_CQC_BASE_OFFSET);
1506 MLX4_GET(param->log_num_cqs, outbox, INIT_HCA_LOG_CQ_OFFSET);
1507 MLX4_GET(param->altc_base, outbox, INIT_HCA_ALTC_BASE_OFFSET);
1508 MLX4_GET(param->auxc_base, outbox, INIT_HCA_AUXC_BASE_OFFSET);
1509 MLX4_GET(param->eqc_base, outbox, INIT_HCA_EQC_BASE_OFFSET);
1510 MLX4_GET(param->log_num_eqs, outbox, INIT_HCA_LOG_EQ_OFFSET);
1511 MLX4_GET(param->rdmarc_base, outbox, INIT_HCA_RDMARC_BASE_OFFSET);
1512 MLX4_GET(param->log_rd_per_qp, outbox, INIT_HCA_LOG_RD_OFFSET);
1513
Jack Morgenstein7b8157b2012-12-06 17:11:59 +00001514 MLX4_GET(dword_field, outbox, INIT_HCA_FLAGS_OFFSET);
1515 if (dword_field & (1 << INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN)) {
1516 param->steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED;
1517 } else {
1518 MLX4_GET(byte_field, outbox, INIT_HCA_UC_STEERING_OFFSET);
1519 if (byte_field & 0x8)
1520 param->steering_mode = MLX4_STEERING_MODE_B0;
1521 else
1522 param->steering_mode = MLX4_STEERING_MODE_A0;
1523 }
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001524 /* steering attributes */
Jack Morgenstein7b8157b2012-12-06 17:11:59 +00001525 if (param->steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) {
Hadar Hen Zion0ff1fb62012-07-05 04:03:46 +00001526 MLX4_GET(param->mc_base, outbox, INIT_HCA_FS_BASE_OFFSET);
1527 MLX4_GET(param->log_mc_entry_sz, outbox,
1528 INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET);
1529 MLX4_GET(param->log_mc_table_sz, outbox,
1530 INIT_HCA_FS_LOG_TABLE_SZ_OFFSET);
1531 } else {
1532 MLX4_GET(param->mc_base, outbox, INIT_HCA_MC_BASE_OFFSET);
1533 MLX4_GET(param->log_mc_entry_sz, outbox,
1534 INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET);
1535 MLX4_GET(param->log_mc_hash_sz, outbox,
1536 INIT_HCA_LOG_MC_HASH_SZ_OFFSET);
1537 MLX4_GET(param->log_mc_table_sz, outbox,
1538 INIT_HCA_LOG_MC_TABLE_SZ_OFFSET);
1539 }
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001540
Or Gerlitz08ff3232012-10-21 14:59:24 +00001541 /* CX3 is capable of extending CQEs/EQEs from 32 to 64 bytes */
1542 MLX4_GET(byte_field, outbox, INIT_HCA_EQE_CQE_OFFSETS);
1543 if (byte_field & 0x20) /* 64-bytes eqe enabled */
1544 param->dev_cap_enabled |= MLX4_DEV_CAP_64B_EQE_ENABLED;
1545 if (byte_field & 0x40) /* 64-bytes cqe enabled */
1546 param->dev_cap_enabled |= MLX4_DEV_CAP_64B_CQE_ENABLED;
1547
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001548 /* TPT attributes */
1549
1550 MLX4_GET(param->dmpt_base, outbox, INIT_HCA_DMPT_BASE_OFFSET);
Shani Michaelie4488342013-02-06 16:19:11 +00001551 MLX4_GET(param->mw_enabled, outbox, INIT_HCA_TPT_MW_OFFSET);
Jack Morgensteinab9c17a2011-12-13 04:18:30 +00001552 MLX4_GET(param->log_mpt_sz, outbox, INIT_HCA_LOG_MPT_SZ_OFFSET);
1553 MLX4_GET(param->mtt_base, outbox, INIT_HCA_MTT_BASE_OFFSET);
1554 MLX4_GET(param->cmpt_base, outbox, INIT_HCA_CMPT_BASE_OFFSET);
1555
1556 /* UAR attributes */
1557
1558 MLX4_GET(param->uar_page_sz, outbox, INIT_HCA_UAR_PAGE_SZ_OFFSET);
1559 MLX4_GET(param->log_uar_sz, outbox, INIT_HCA_LOG_UAR_SZ_OFFSET);
1560
1561out:
1562 mlx4_free_cmd_mailbox(dev, mailbox);
1563
1564 return err;
1565}
1566
Jack Morgenstein980e9002012-08-03 08:40:53 +00001567/* for IB-type ports only in SRIOV mode. Checks that both proxy QP0
1568 * and real QP0 are active, so that the paravirtualized QP0 is ready
1569 * to operate */
1570static int check_qp0_state(struct mlx4_dev *dev, int function, int port)
1571{
1572 struct mlx4_priv *priv = mlx4_priv(dev);
1573 /* irrelevant if not infiniband */
1574 if (priv->mfunc.master.qp0_state[port].proxy_qp0_active &&
1575 priv->mfunc.master.qp0_state[port].qp0_active)
1576 return 1;
1577 return 0;
1578}
1579
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001580int mlx4_INIT_PORT_wrapper(struct mlx4_dev *dev, int slave,
1581 struct mlx4_vhcr *vhcr,
1582 struct mlx4_cmd_mailbox *inbox,
1583 struct mlx4_cmd_mailbox *outbox,
1584 struct mlx4_cmd_info *cmd)
1585{
1586 struct mlx4_priv *priv = mlx4_priv(dev);
1587 int port = vhcr->in_modifier;
1588 int err;
1589
1590 if (priv->mfunc.master.slave_state[slave].init_port_mask & (1 << port))
1591 return 0;
1592
Jack Morgenstein980e9002012-08-03 08:40:53 +00001593 if (dev->caps.port_mask[port] != MLX4_PORT_TYPE_IB) {
1594 /* Enable port only if it was previously disabled */
1595 if (!priv->mfunc.master.init_port_ref[port]) {
1596 err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
1597 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
1598 if (err)
1599 return err;
1600 }
1601 priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
1602 } else {
1603 if (slave == mlx4_master_func_num(dev)) {
1604 if (check_qp0_state(dev, slave, port) &&
1605 !priv->mfunc.master.qp0_state[port].port_active) {
1606 err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
1607 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
1608 if (err)
1609 return err;
1610 priv->mfunc.master.qp0_state[port].port_active = 1;
1611 priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
1612 }
1613 } else
1614 priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001615 }
1616 ++priv->mfunc.master.init_port_ref[port];
1617 return 0;
1618}
1619
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001620int mlx4_INIT_PORT(struct mlx4_dev *dev, int port)
Roland Dreier225c7b12007-05-08 18:00:38 -07001621{
1622 struct mlx4_cmd_mailbox *mailbox;
1623 u32 *inbox;
1624 int err;
1625 u32 flags;
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001626 u16 field;
Roland Dreier225c7b12007-05-08 18:00:38 -07001627
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001628 if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
Roland Dreier225c7b12007-05-08 18:00:38 -07001629#define INIT_PORT_IN_SIZE 256
1630#define INIT_PORT_FLAGS_OFFSET 0x00
1631#define INIT_PORT_FLAG_SIG (1 << 18)
1632#define INIT_PORT_FLAG_NG (1 << 17)
1633#define INIT_PORT_FLAG_G0 (1 << 16)
1634#define INIT_PORT_VL_SHIFT 4
1635#define INIT_PORT_PORT_WIDTH_SHIFT 8
1636#define INIT_PORT_MTU_OFFSET 0x04
1637#define INIT_PORT_MAX_GID_OFFSET 0x06
1638#define INIT_PORT_MAX_PKEY_OFFSET 0x0a
1639#define INIT_PORT_GUID0_OFFSET 0x10
1640#define INIT_PORT_NODE_GUID_OFFSET 0x18
1641#define INIT_PORT_SI_GUID_OFFSET 0x20
1642
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001643 mailbox = mlx4_alloc_cmd_mailbox(dev);
1644 if (IS_ERR(mailbox))
1645 return PTR_ERR(mailbox);
1646 inbox = mailbox->buf;
Roland Dreier225c7b12007-05-08 18:00:38 -07001647
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001648 flags = 0;
1649 flags |= (dev->caps.vl_cap[port] & 0xf) << INIT_PORT_VL_SHIFT;
1650 flags |= (dev->caps.port_width_cap[port] & 0xf) << INIT_PORT_PORT_WIDTH_SHIFT;
1651 MLX4_PUT(inbox, flags, INIT_PORT_FLAGS_OFFSET);
Roland Dreier225c7b12007-05-08 18:00:38 -07001652
Yevgeny Petrilinb79acb42008-10-22 10:56:48 -07001653 field = 128 << dev->caps.ib_mtu_cap[port];
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001654 MLX4_PUT(inbox, field, INIT_PORT_MTU_OFFSET);
1655 field = dev->caps.gid_table_len[port];
1656 MLX4_PUT(inbox, field, INIT_PORT_MAX_GID_OFFSET);
1657 field = dev->caps.pkey_table_len[port];
1658 MLX4_PUT(inbox, field, INIT_PORT_MAX_PKEY_OFFSET);
Roland Dreier225c7b12007-05-08 18:00:38 -07001659
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001660 err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_INIT_PORT,
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001661 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001662
Roland Dreier5ae2a7a2007-06-18 08:15:02 -07001663 mlx4_free_cmd_mailbox(dev, mailbox);
1664 } else
1665 err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001666 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
Roland Dreier225c7b12007-05-08 18:00:38 -07001667
1668 return err;
1669}
1670EXPORT_SYMBOL_GPL(mlx4_INIT_PORT);
1671
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001672int mlx4_CLOSE_PORT_wrapper(struct mlx4_dev *dev, int slave,
1673 struct mlx4_vhcr *vhcr,
1674 struct mlx4_cmd_mailbox *inbox,
1675 struct mlx4_cmd_mailbox *outbox,
1676 struct mlx4_cmd_info *cmd)
1677{
1678 struct mlx4_priv *priv = mlx4_priv(dev);
1679 int port = vhcr->in_modifier;
1680 int err;
1681
1682 if (!(priv->mfunc.master.slave_state[slave].init_port_mask &
1683 (1 << port)))
1684 return 0;
1685
Jack Morgenstein980e9002012-08-03 08:40:53 +00001686 if (dev->caps.port_mask[port] != MLX4_PORT_TYPE_IB) {
1687 if (priv->mfunc.master.init_port_ref[port] == 1) {
1688 err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT,
1689 1000, MLX4_CMD_NATIVE);
1690 if (err)
1691 return err;
1692 }
1693 priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
1694 } else {
1695 /* infiniband port */
1696 if (slave == mlx4_master_func_num(dev)) {
1697 if (!priv->mfunc.master.qp0_state[port].qp0_active &&
1698 priv->mfunc.master.qp0_state[port].port_active) {
1699 err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT,
1700 1000, MLX4_CMD_NATIVE);
1701 if (err)
1702 return err;
1703 priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
1704 priv->mfunc.master.qp0_state[port].port_active = 0;
1705 }
1706 } else
1707 priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001708 }
Marcel Apfelbaum5cc914f2011-12-13 04:12:40 +00001709 --priv->mfunc.master.init_port_ref[port];
1710 return 0;
1711}
1712
Roland Dreier225c7b12007-05-08 18:00:38 -07001713int mlx4_CLOSE_PORT(struct mlx4_dev *dev, int port)
1714{
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001715 return mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT, 1000,
1716 MLX4_CMD_WRAPPED);
Roland Dreier225c7b12007-05-08 18:00:38 -07001717}
1718EXPORT_SYMBOL_GPL(mlx4_CLOSE_PORT);
1719
1720int mlx4_CLOSE_HCA(struct mlx4_dev *dev, int panic)
1721{
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001722 return mlx4_cmd(dev, 0, 0, panic, MLX4_CMD_CLOSE_HCA, 1000,
1723 MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001724}
1725
1726int mlx4_SET_ICM_SIZE(struct mlx4_dev *dev, u64 icm_size, u64 *aux_pages)
1727{
1728 int ret = mlx4_cmd_imm(dev, icm_size, aux_pages, 0, 0,
1729 MLX4_CMD_SET_ICM_SIZE,
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001730 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001731 if (ret)
1732 return ret;
1733
1734 /*
1735 * Round up number of system pages needed in case
1736 * MLX4_ICM_PAGE_SIZE < PAGE_SIZE.
1737 */
1738 *aux_pages = ALIGN(*aux_pages, PAGE_SIZE / MLX4_ICM_PAGE_SIZE) >>
1739 (PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT);
1740
1741 return 0;
1742}
1743
1744int mlx4_NOP(struct mlx4_dev *dev)
1745{
1746 /* Input modifier of 0x1f means "finish as soon as possible." */
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001747 return mlx4_cmd(dev, 0, 0x1f, 0, MLX4_CMD_NOP, 100, MLX4_CMD_NATIVE);
Roland Dreier225c7b12007-05-08 18:00:38 -07001748}
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +00001749
Hadar Hen Zion8e1a28e2013-12-19 21:20:12 +02001750int mlx4_get_phys_port_id(struct mlx4_dev *dev)
1751{
1752 u8 port;
1753 u32 *outbox;
1754 struct mlx4_cmd_mailbox *mailbox;
1755 u32 in_mod;
1756 u32 guid_hi, guid_lo;
1757 int err, ret = 0;
1758#define MOD_STAT_CFG_PORT_OFFSET 8
1759#define MOD_STAT_CFG_GUID_H 0X14
1760#define MOD_STAT_CFG_GUID_L 0X1c
1761
1762 mailbox = mlx4_alloc_cmd_mailbox(dev);
1763 if (IS_ERR(mailbox))
1764 return PTR_ERR(mailbox);
1765 outbox = mailbox->buf;
1766
1767 for (port = 1; port <= dev->caps.num_ports; port++) {
1768 in_mod = port << MOD_STAT_CFG_PORT_OFFSET;
1769 err = mlx4_cmd_box(dev, 0, mailbox->dma, in_mod, 0x2,
1770 MLX4_CMD_MOD_STAT_CFG, MLX4_CMD_TIME_CLASS_A,
1771 MLX4_CMD_NATIVE);
1772 if (err) {
1773 mlx4_err(dev, "Fail to get port %d uplink guid\n",
1774 port);
1775 ret = err;
1776 } else {
1777 MLX4_GET(guid_hi, outbox, MOD_STAT_CFG_GUID_H);
1778 MLX4_GET(guid_lo, outbox, MOD_STAT_CFG_GUID_L);
1779 dev->caps.phys_port_id[port] = (u64)guid_lo |
1780 (u64)guid_hi << 32;
1781 }
1782 }
1783 mlx4_free_cmd_mailbox(dev, mailbox);
1784 return ret;
1785}
1786
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +00001787#define MLX4_WOL_SETUP_MODE (5 << 28)
1788int mlx4_wol_read(struct mlx4_dev *dev, u64 *config, int port)
1789{
1790 u32 in_mod = MLX4_WOL_SETUP_MODE | port << 8;
1791
1792 return mlx4_cmd_imm(dev, 0, config, in_mod, 0x3,
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001793 MLX4_CMD_MOD_STAT_CFG, MLX4_CMD_TIME_CLASS_A,
1794 MLX4_CMD_NATIVE);
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +00001795}
1796EXPORT_SYMBOL_GPL(mlx4_wol_read);
1797
1798int mlx4_wol_write(struct mlx4_dev *dev, u64 config, int port)
1799{
1800 u32 in_mod = MLX4_WOL_SETUP_MODE | port << 8;
1801
1802 return mlx4_cmd(dev, config, in_mod, 0x1, MLX4_CMD_MOD_STAT_CFG,
Jack Morgensteinf9baff52011-12-13 04:10:51 +00001803 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +00001804}
1805EXPORT_SYMBOL_GPL(mlx4_wol_write);
Yevgeny Petrilinfe6f7002013-07-28 18:54:21 +03001806
1807enum {
1808 ADD_TO_MCG = 0x26,
1809};
1810
1811
1812void mlx4_opreq_action(struct work_struct *work)
1813{
1814 struct mlx4_priv *priv = container_of(work, struct mlx4_priv,
1815 opreq_task);
1816 struct mlx4_dev *dev = &priv->dev;
1817 int num_tasks = atomic_read(&priv->opreq_count);
1818 struct mlx4_cmd_mailbox *mailbox;
1819 struct mlx4_mgm *mgm;
1820 u32 *outbox;
1821 u32 modifier;
1822 u16 token;
Yevgeny Petrilinfe6f7002013-07-28 18:54:21 +03001823 u16 type;
1824 int err;
1825 u32 num_qps;
1826 struct mlx4_qp qp;
1827 int i;
1828 u8 rem_mcg;
1829 u8 prot;
1830
1831#define GET_OP_REQ_MODIFIER_OFFSET 0x08
1832#define GET_OP_REQ_TOKEN_OFFSET 0x14
1833#define GET_OP_REQ_TYPE_OFFSET 0x1a
1834#define GET_OP_REQ_DATA_OFFSET 0x20
1835
1836 mailbox = mlx4_alloc_cmd_mailbox(dev);
1837 if (IS_ERR(mailbox)) {
1838 mlx4_err(dev, "Failed to allocate mailbox for GET_OP_REQ\n");
1839 return;
1840 }
1841 outbox = mailbox->buf;
1842
1843 while (num_tasks) {
1844 err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0,
1845 MLX4_CMD_GET_OP_REQ, MLX4_CMD_TIME_CLASS_A,
1846 MLX4_CMD_NATIVE);
1847 if (err) {
Masanari Iida6d3be302013-09-30 23:19:09 +09001848 mlx4_err(dev, "Failed to retrieve required operation: %d\n",
Yevgeny Petrilinfe6f7002013-07-28 18:54:21 +03001849 err);
1850 return;
1851 }
1852 MLX4_GET(modifier, outbox, GET_OP_REQ_MODIFIER_OFFSET);
1853 MLX4_GET(token, outbox, GET_OP_REQ_TOKEN_OFFSET);
1854 MLX4_GET(type, outbox, GET_OP_REQ_TYPE_OFFSET);
Yevgeny Petrilinfe6f7002013-07-28 18:54:21 +03001855 type &= 0xfff;
1856
1857 switch (type) {
1858 case ADD_TO_MCG:
1859 if (dev->caps.steering_mode ==
1860 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1861 mlx4_warn(dev, "ADD MCG operation is not supported in DEVICE_MANAGED steering mode\n");
1862 err = EPERM;
1863 break;
1864 }
1865 mgm = (struct mlx4_mgm *)((u8 *)(outbox) +
1866 GET_OP_REQ_DATA_OFFSET);
1867 num_qps = be32_to_cpu(mgm->members_count) &
1868 MGM_QPN_MASK;
1869 rem_mcg = ((u8 *)(&mgm->members_count))[0] & 1;
1870 prot = ((u8 *)(&mgm->members_count))[0] >> 6;
1871
1872 for (i = 0; i < num_qps; i++) {
1873 qp.qpn = be32_to_cpu(mgm->qp[i]);
1874 if (rem_mcg)
1875 err = mlx4_multicast_detach(dev, &qp,
1876 mgm->gid,
1877 prot, 0);
1878 else
1879 err = mlx4_multicast_attach(dev, &qp,
1880 mgm->gid,
1881 mgm->gid[5]
1882 , 0, prot,
1883 NULL);
1884 if (err)
1885 break;
1886 }
1887 break;
1888 default:
1889 mlx4_warn(dev, "Bad type for required operation\n");
1890 err = EINVAL;
1891 break;
1892 }
1893 err = mlx4_cmd(dev, 0, ((u32) err | cpu_to_be32(token) << 16),
1894 1, MLX4_CMD_GET_OP_REQ, MLX4_CMD_TIME_CLASS_A,
1895 MLX4_CMD_NATIVE);
1896 if (err) {
1897 mlx4_err(dev, "Failed to acknowledge required request: %d\n",
1898 err);
1899 goto out;
1900 }
1901 memset(outbox, 0, 0xffc);
1902 num_tasks = atomic_dec_return(&priv->opreq_count);
1903 }
1904
1905out:
1906 mlx4_free_cmd_mailbox(dev, mailbox);
1907}