blob: a3295bb158912fd8e8548c51a4151c9f8a43d4e1 [file] [log] [blame]
Eli Cohene126ba92013-07-07 17:25:49 +03001/*
Saeed Mahameed6cf0a152015-04-02 17:07:30 +03002 * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
Eli Cohene126ba92013-07-07 17:25:49 +03003 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
Christoph Hellwigadec6402015-08-28 09:27:19 +020033#include <linux/highmem.h>
Eli Cohene126ba92013-07-07 17:25:49 +030034#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/errno.h>
37#include <linux/pci.h>
38#include <linux/dma-mapping.h>
39#include <linux/slab.h>
40#include <linux/io-mapping.h>
41#include <linux/sched.h>
42#include <rdma/ib_user_verbs.h>
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030043#include <linux/mlx5/vport.h>
Eli Cohene126ba92013-07-07 17:25:49 +030044#include <rdma/ib_smi.h>
45#include <rdma/ib_umem.h>
46#include "user.h"
47#include "mlx5_ib.h"
48
49#define DRIVER_NAME "mlx5_ib"
Amir Vadai169a1d82014-02-19 17:47:31 +020050#define DRIVER_VERSION "2.2-1"
51#define DRIVER_RELDATE "Feb 2014"
Eli Cohene126ba92013-07-07 17:25:49 +030052
53MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
54MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver");
55MODULE_LICENSE("Dual BSD/GPL");
56MODULE_VERSION(DRIVER_VERSION);
57
Jack Morgenstein9603b612014-07-28 23:30:22 +030058static int deprecated_prof_sel = 2;
59module_param_named(prof_sel, deprecated_prof_sel, int, 0444);
60MODULE_PARM_DESC(prof_sel, "profile selector. Deprecated here. Moved to module mlx5_core");
Eli Cohene126ba92013-07-07 17:25:49 +030061
62static char mlx5_version[] =
63 DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v"
64 DRIVER_VERSION " (" DRIVER_RELDATE ")\n";
65
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030066static enum rdma_link_layer
Achiad Shochatebd61f62015-12-23 18:47:16 +020067mlx5_port_type_cap_to_rdma_ll(int port_type_cap)
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030068{
Achiad Shochatebd61f62015-12-23 18:47:16 +020069 switch (port_type_cap) {
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030070 case MLX5_CAP_PORT_TYPE_IB:
71 return IB_LINK_LAYER_INFINIBAND;
72 case MLX5_CAP_PORT_TYPE_ETH:
73 return IB_LINK_LAYER_ETHERNET;
74 default:
75 return IB_LINK_LAYER_UNSPECIFIED;
76 }
77}
78
Achiad Shochatebd61f62015-12-23 18:47:16 +020079static enum rdma_link_layer
80mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num)
81{
82 struct mlx5_ib_dev *dev = to_mdev(device);
83 int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type);
84
85 return mlx5_port_type_cap_to_rdma_ll(port_type_cap);
86}
87
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030088static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev)
89{
90 return !dev->mdev->issi;
91}
92
93enum {
94 MLX5_VPORT_ACCESS_METHOD_MAD,
95 MLX5_VPORT_ACCESS_METHOD_HCA,
96 MLX5_VPORT_ACCESS_METHOD_NIC,
97};
98
99static int mlx5_get_vport_access_method(struct ib_device *ibdev)
100{
101 if (mlx5_use_mad_ifc(to_mdev(ibdev)))
102 return MLX5_VPORT_ACCESS_METHOD_MAD;
103
Achiad Shochatebd61f62015-12-23 18:47:16 +0200104 if (mlx5_ib_port_link_layer(ibdev, 1) ==
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300105 IB_LINK_LAYER_ETHERNET)
106 return MLX5_VPORT_ACCESS_METHOD_NIC;
107
108 return MLX5_VPORT_ACCESS_METHOD_HCA;
109}
110
111static int mlx5_query_system_image_guid(struct ib_device *ibdev,
112 __be64 *sys_image_guid)
113{
114 struct mlx5_ib_dev *dev = to_mdev(ibdev);
115 struct mlx5_core_dev *mdev = dev->mdev;
116 u64 tmp;
117 int err;
118
119 switch (mlx5_get_vport_access_method(ibdev)) {
120 case MLX5_VPORT_ACCESS_METHOD_MAD:
121 return mlx5_query_mad_ifc_system_image_guid(ibdev,
122 sys_image_guid);
123
124 case MLX5_VPORT_ACCESS_METHOD_HCA:
125 err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp);
126 if (!err)
127 *sys_image_guid = cpu_to_be64(tmp);
128 return err;
129
130 default:
131 return -EINVAL;
132 }
133}
134
135static int mlx5_query_max_pkeys(struct ib_device *ibdev,
136 u16 *max_pkeys)
137{
138 struct mlx5_ib_dev *dev = to_mdev(ibdev);
139 struct mlx5_core_dev *mdev = dev->mdev;
140
141 switch (mlx5_get_vport_access_method(ibdev)) {
142 case MLX5_VPORT_ACCESS_METHOD_MAD:
143 return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys);
144
145 case MLX5_VPORT_ACCESS_METHOD_HCA:
146 case MLX5_VPORT_ACCESS_METHOD_NIC:
147 *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev,
148 pkey_table_size));
149 return 0;
150
151 default:
152 return -EINVAL;
153 }
154}
155
156static int mlx5_query_vendor_id(struct ib_device *ibdev,
157 u32 *vendor_id)
158{
159 struct mlx5_ib_dev *dev = to_mdev(ibdev);
160
161 switch (mlx5_get_vport_access_method(ibdev)) {
162 case MLX5_VPORT_ACCESS_METHOD_MAD:
163 return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id);
164
165 case MLX5_VPORT_ACCESS_METHOD_HCA:
166 case MLX5_VPORT_ACCESS_METHOD_NIC:
167 return mlx5_core_query_vendor_id(dev->mdev, vendor_id);
168
169 default:
170 return -EINVAL;
171 }
172}
173
174static int mlx5_query_node_guid(struct mlx5_ib_dev *dev,
175 __be64 *node_guid)
176{
177 u64 tmp;
178 int err;
179
180 switch (mlx5_get_vport_access_method(&dev->ib_dev)) {
181 case MLX5_VPORT_ACCESS_METHOD_MAD:
182 return mlx5_query_mad_ifc_node_guid(dev, node_guid);
183
184 case MLX5_VPORT_ACCESS_METHOD_HCA:
185 err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp);
186 if (!err)
187 *node_guid = cpu_to_be64(tmp);
188 return err;
189
190 default:
191 return -EINVAL;
192 }
193}
194
195struct mlx5_reg_node_desc {
196 u8 desc[64];
197};
198
199static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc)
200{
201 struct mlx5_reg_node_desc in;
202
203 if (mlx5_use_mad_ifc(dev))
204 return mlx5_query_mad_ifc_node_desc(dev, node_desc);
205
206 memset(&in, 0, sizeof(in));
207
208 return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc,
209 sizeof(struct mlx5_reg_node_desc),
210 MLX5_REG_NODE_DESC, 0, 0);
211}
212
Eli Cohene126ba92013-07-07 17:25:49 +0300213static int mlx5_ib_query_device(struct ib_device *ibdev,
Matan Barak2528e332015-06-11 16:35:25 +0300214 struct ib_device_attr *props,
215 struct ib_udata *uhw)
Eli Cohene126ba92013-07-07 17:25:49 +0300216{
217 struct mlx5_ib_dev *dev = to_mdev(ibdev);
Saeed Mahameed938fe832015-05-28 22:28:41 +0300218 struct mlx5_core_dev *mdev = dev->mdev;
Eli Cohene126ba92013-07-07 17:25:49 +0300219 int err = -ENOMEM;
220 int max_rq_sg;
221 int max_sq_sg;
Sagi Grimberge0238a62015-07-21 14:40:12 +0300222 u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz);
Eli Cohene126ba92013-07-07 17:25:49 +0300223
Matan Barak2528e332015-06-11 16:35:25 +0300224 if (uhw->inlen || uhw->outlen)
225 return -EINVAL;
226
Eli Cohene126ba92013-07-07 17:25:49 +0300227 memset(props, 0, sizeof(*props));
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300228 err = mlx5_query_system_image_guid(ibdev,
229 &props->sys_image_guid);
230 if (err)
231 return err;
232
233 err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys);
234 if (err)
235 return err;
236
237 err = mlx5_query_vendor_id(ibdev, &props->vendor_id);
238 if (err)
239 return err;
Eli Cohene126ba92013-07-07 17:25:49 +0300240
Jack Morgenstein9603b612014-07-28 23:30:22 +0300241 props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) |
242 (fw_rev_min(dev->mdev) << 16) |
243 fw_rev_sub(dev->mdev);
Eli Cohene126ba92013-07-07 17:25:49 +0300244 props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT |
245 IB_DEVICE_PORT_ACTIVE_EVENT |
246 IB_DEVICE_SYS_IMAGE_GUID |
Eli Cohen1a4c3a32014-02-06 17:41:25 +0200247 IB_DEVICE_RC_RNR_NAK_GEN;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300248
249 if (MLX5_CAP_GEN(mdev, pkv))
Eli Cohene126ba92013-07-07 17:25:49 +0300250 props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300251 if (MLX5_CAP_GEN(mdev, qkv))
Eli Cohene126ba92013-07-07 17:25:49 +0300252 props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300253 if (MLX5_CAP_GEN(mdev, apm))
Eli Cohene126ba92013-07-07 17:25:49 +0300254 props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300255 if (MLX5_CAP_GEN(mdev, xrc))
Eli Cohene126ba92013-07-07 17:25:49 +0300256 props->device_cap_flags |= IB_DEVICE_XRC;
257 props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300258 if (MLX5_CAP_GEN(mdev, sho)) {
Sagi Grimberg2dea9092014-02-23 14:19:13 +0200259 props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER;
260 /* At this stage no support for signature handover */
261 props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 |
262 IB_PROT_T10DIF_TYPE_2 |
263 IB_PROT_T10DIF_TYPE_3;
264 props->sig_guard_cap = IB_GUARD_T10DIF_CRC |
265 IB_GUARD_T10DIF_CSUM;
266 }
Saeed Mahameed938fe832015-05-28 22:28:41 +0300267 if (MLX5_CAP_GEN(mdev, block_lb_mc))
Eli Cohenf360d882014-04-02 00:10:16 +0300268 props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK;
Eli Cohene126ba92013-07-07 17:25:49 +0300269
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300270 props->vendor_part_id = mdev->pdev->device;
271 props->hw_ver = mdev->pdev->revision;
Eli Cohene126ba92013-07-07 17:25:49 +0300272
273 props->max_mr_size = ~0ull;
Sagi Grimberge0238a62015-07-21 14:40:12 +0300274 props->page_size_cap = ~(min_page_size - 1);
Saeed Mahameed938fe832015-05-28 22:28:41 +0300275 props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp);
276 props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz);
277 max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) /
278 sizeof(struct mlx5_wqe_data_seg);
279 max_sq_sg = (MLX5_CAP_GEN(mdev, max_wqe_sz_sq) -
280 sizeof(struct mlx5_wqe_ctrl_seg)) /
281 sizeof(struct mlx5_wqe_data_seg);
Eli Cohene126ba92013-07-07 17:25:49 +0300282 props->max_sge = min(max_rq_sg, max_sq_sg);
Sagi Grimberg18ebd402015-07-27 18:10:01 -0500283 props->max_sge_rd = props->max_sge;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300284 props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq);
285 props->max_cqe = (1 << MLX5_CAP_GEN(mdev, log_max_eq_sz)) - 1;
286 props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey);
287 props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd);
288 props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp);
289 props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp);
290 props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq);
291 props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1;
292 props->local_ca_ack_delay = MLX5_CAP_GEN(mdev, local_ca_ack_delay);
Eli Cohene126ba92013-07-07 17:25:49 +0300293 props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
Eli Cohene126ba92013-07-07 17:25:49 +0300294 props->max_srq_sge = max_rq_sg - 1;
295 props->max_fast_reg_page_list_len = (unsigned int)-1;
Eli Cohen81bea282013-09-11 16:35:30 +0300296 props->atomic_cap = IB_ATOMIC_NONE;
297 props->masked_atomic_cap = IB_ATOMIC_NONE;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300298 props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg);
299 props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg);
Eli Cohene126ba92013-07-07 17:25:49 +0300300 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
301 props->max_mcast_grp;
302 props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */
303
Haggai Eran8cdd3122014-12-11 17:04:20 +0200304#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
Saeed Mahameed938fe832015-05-28 22:28:41 +0300305 if (MLX5_CAP_GEN(mdev, pg))
Haggai Eran8cdd3122014-12-11 17:04:20 +0200306 props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING;
307 props->odp_caps = dev->odp_caps;
308#endif
309
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300310 return 0;
311}
Eli Cohene126ba92013-07-07 17:25:49 +0300312
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300313enum mlx5_ib_width {
314 MLX5_IB_WIDTH_1X = 1 << 0,
315 MLX5_IB_WIDTH_2X = 1 << 1,
316 MLX5_IB_WIDTH_4X = 1 << 2,
317 MLX5_IB_WIDTH_8X = 1 << 3,
318 MLX5_IB_WIDTH_12X = 1 << 4
319};
320
321static int translate_active_width(struct ib_device *ibdev, u8 active_width,
322 u8 *ib_width)
323{
324 struct mlx5_ib_dev *dev = to_mdev(ibdev);
325 int err = 0;
326
327 if (active_width & MLX5_IB_WIDTH_1X) {
328 *ib_width = IB_WIDTH_1X;
329 } else if (active_width & MLX5_IB_WIDTH_2X) {
330 mlx5_ib_dbg(dev, "active_width %d is not supported by IB spec\n",
331 (int)active_width);
332 err = -EINVAL;
333 } else if (active_width & MLX5_IB_WIDTH_4X) {
334 *ib_width = IB_WIDTH_4X;
335 } else if (active_width & MLX5_IB_WIDTH_8X) {
336 *ib_width = IB_WIDTH_8X;
337 } else if (active_width & MLX5_IB_WIDTH_12X) {
338 *ib_width = IB_WIDTH_12X;
339 } else {
340 mlx5_ib_dbg(dev, "Invalid active_width %d\n",
341 (int)active_width);
342 err = -EINVAL;
343 }
344
345 return err;
346}
347
348static int mlx5_mtu_to_ib_mtu(int mtu)
349{
350 switch (mtu) {
351 case 256: return 1;
352 case 512: return 2;
353 case 1024: return 3;
354 case 2048: return 4;
355 case 4096: return 5;
356 default:
357 pr_warn("invalid mtu\n");
358 return -1;
359 }
360}
361
362enum ib_max_vl_num {
363 __IB_MAX_VL_0 = 1,
364 __IB_MAX_VL_0_1 = 2,
365 __IB_MAX_VL_0_3 = 3,
366 __IB_MAX_VL_0_7 = 4,
367 __IB_MAX_VL_0_14 = 5,
368};
369
370enum mlx5_vl_hw_cap {
371 MLX5_VL_HW_0 = 1,
372 MLX5_VL_HW_0_1 = 2,
373 MLX5_VL_HW_0_2 = 3,
374 MLX5_VL_HW_0_3 = 4,
375 MLX5_VL_HW_0_4 = 5,
376 MLX5_VL_HW_0_5 = 6,
377 MLX5_VL_HW_0_6 = 7,
378 MLX5_VL_HW_0_7 = 8,
379 MLX5_VL_HW_0_14 = 15
380};
381
382static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap,
383 u8 *max_vl_num)
384{
385 switch (vl_hw_cap) {
386 case MLX5_VL_HW_0:
387 *max_vl_num = __IB_MAX_VL_0;
388 break;
389 case MLX5_VL_HW_0_1:
390 *max_vl_num = __IB_MAX_VL_0_1;
391 break;
392 case MLX5_VL_HW_0_3:
393 *max_vl_num = __IB_MAX_VL_0_3;
394 break;
395 case MLX5_VL_HW_0_7:
396 *max_vl_num = __IB_MAX_VL_0_7;
397 break;
398 case MLX5_VL_HW_0_14:
399 *max_vl_num = __IB_MAX_VL_0_14;
400 break;
401
402 default:
403 return -EINVAL;
404 }
405
406 return 0;
407}
408
409static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port,
410 struct ib_port_attr *props)
411{
412 struct mlx5_ib_dev *dev = to_mdev(ibdev);
413 struct mlx5_core_dev *mdev = dev->mdev;
414 struct mlx5_hca_vport_context *rep;
415 int max_mtu;
416 int oper_mtu;
417 int err;
418 u8 ib_link_width_oper;
419 u8 vl_hw_cap;
420
421 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
422 if (!rep) {
423 err = -ENOMEM;
424 goto out;
425 }
426
427 memset(props, 0, sizeof(*props));
428
429 err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep);
430 if (err)
431 goto out;
432
433 props->lid = rep->lid;
434 props->lmc = rep->lmc;
435 props->sm_lid = rep->sm_lid;
436 props->sm_sl = rep->sm_sl;
437 props->state = rep->vport_state;
438 props->phys_state = rep->port_physical_state;
439 props->port_cap_flags = rep->cap_mask1;
440 props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size));
441 props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg);
442 props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size));
443 props->bad_pkey_cntr = rep->pkey_violation_counter;
444 props->qkey_viol_cntr = rep->qkey_violation_counter;
445 props->subnet_timeout = rep->subnet_timeout;
446 props->init_type_reply = rep->init_type_reply;
447
448 err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port);
449 if (err)
450 goto out;
451
452 err = translate_active_width(ibdev, ib_link_width_oper,
453 &props->active_width);
454 if (err)
455 goto out;
456 err = mlx5_query_port_proto_oper(mdev, &props->active_speed, MLX5_PTYS_IB,
457 port);
458 if (err)
459 goto out;
460
Saeed Mahameedfacc9692015-06-11 14:47:27 +0300461 mlx5_query_port_max_mtu(mdev, &max_mtu, port);
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300462
463 props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu);
464
Saeed Mahameedfacc9692015-06-11 14:47:27 +0300465 mlx5_query_port_oper_mtu(mdev, &oper_mtu, port);
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300466
467 props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu);
468
469 err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port);
470 if (err)
471 goto out;
472
473 err = translate_max_vl_num(ibdev, vl_hw_cap,
474 &props->max_vl_num);
475out:
476 kfree(rep);
Eli Cohene126ba92013-07-07 17:25:49 +0300477 return err;
478}
479
480int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
481 struct ib_port_attr *props)
482{
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300483 switch (mlx5_get_vport_access_method(ibdev)) {
484 case MLX5_VPORT_ACCESS_METHOD_MAD:
485 return mlx5_query_mad_ifc_port(ibdev, port, props);
Eli Cohene126ba92013-07-07 17:25:49 +0300486
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300487 case MLX5_VPORT_ACCESS_METHOD_HCA:
488 return mlx5_query_hca_port(ibdev, port, props);
489
490 default:
Eli Cohene126ba92013-07-07 17:25:49 +0300491 return -EINVAL;
492 }
Eli Cohene126ba92013-07-07 17:25:49 +0300493}
494
495static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
496 union ib_gid *gid)
497{
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300498 struct mlx5_ib_dev *dev = to_mdev(ibdev);
499 struct mlx5_core_dev *mdev = dev->mdev;
Eli Cohene126ba92013-07-07 17:25:49 +0300500
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300501 switch (mlx5_get_vport_access_method(ibdev)) {
502 case MLX5_VPORT_ACCESS_METHOD_MAD:
503 return mlx5_query_mad_ifc_gids(ibdev, port, index, gid);
Eli Cohene126ba92013-07-07 17:25:49 +0300504
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300505 case MLX5_VPORT_ACCESS_METHOD_HCA:
506 return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid);
Eli Cohene126ba92013-07-07 17:25:49 +0300507
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300508 default:
509 return -EINVAL;
510 }
Eli Cohene126ba92013-07-07 17:25:49 +0300511
Eli Cohene126ba92013-07-07 17:25:49 +0300512}
513
514static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
515 u16 *pkey)
516{
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300517 struct mlx5_ib_dev *dev = to_mdev(ibdev);
518 struct mlx5_core_dev *mdev = dev->mdev;
Eli Cohene126ba92013-07-07 17:25:49 +0300519
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300520 switch (mlx5_get_vport_access_method(ibdev)) {
521 case MLX5_VPORT_ACCESS_METHOD_MAD:
522 return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey);
Eli Cohene126ba92013-07-07 17:25:49 +0300523
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300524 case MLX5_VPORT_ACCESS_METHOD_HCA:
525 case MLX5_VPORT_ACCESS_METHOD_NIC:
526 return mlx5_query_hca_vport_pkey(mdev, 0, port, 0, index,
527 pkey);
528 default:
529 return -EINVAL;
530 }
Eli Cohene126ba92013-07-07 17:25:49 +0300531}
532
Eli Cohene126ba92013-07-07 17:25:49 +0300533static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask,
534 struct ib_device_modify *props)
535{
536 struct mlx5_ib_dev *dev = to_mdev(ibdev);
537 struct mlx5_reg_node_desc in;
538 struct mlx5_reg_node_desc out;
539 int err;
540
541 if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
542 return -EOPNOTSUPP;
543
544 if (!(mask & IB_DEVICE_MODIFY_NODE_DESC))
545 return 0;
546
547 /*
548 * If possible, pass node desc to FW, so it can generate
549 * a 144 trap. If cmd fails, just ignore.
550 */
551 memcpy(&in, props->node_desc, 64);
Jack Morgenstein9603b612014-07-28 23:30:22 +0300552 err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out,
Eli Cohene126ba92013-07-07 17:25:49 +0300553 sizeof(out), MLX5_REG_NODE_DESC, 0, 1);
554 if (err)
555 return err;
556
557 memcpy(ibdev->node_desc, props->node_desc, 64);
558
559 return err;
560}
561
562static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask,
563 struct ib_port_modify *props)
564{
565 struct mlx5_ib_dev *dev = to_mdev(ibdev);
566 struct ib_port_attr attr;
567 u32 tmp;
568 int err;
569
570 mutex_lock(&dev->cap_mask_mutex);
571
572 err = mlx5_ib_query_port(ibdev, port, &attr);
573 if (err)
574 goto out;
575
576 tmp = (attr.port_cap_flags | props->set_port_cap_mask) &
577 ~props->clr_port_cap_mask;
578
Jack Morgenstein9603b612014-07-28 23:30:22 +0300579 err = mlx5_set_port_caps(dev->mdev, port, tmp);
Eli Cohene126ba92013-07-07 17:25:49 +0300580
581out:
582 mutex_unlock(&dev->cap_mask_mutex);
583 return err;
584}
585
586static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
587 struct ib_udata *udata)
588{
589 struct mlx5_ib_dev *dev = to_mdev(ibdev);
Eli Cohen78c0f982014-01-30 13:49:48 +0200590 struct mlx5_ib_alloc_ucontext_req_v2 req;
Eli Cohene126ba92013-07-07 17:25:49 +0300591 struct mlx5_ib_alloc_ucontext_resp resp;
592 struct mlx5_ib_ucontext *context;
593 struct mlx5_uuar_info *uuari;
594 struct mlx5_uar *uars;
Eli Cohenc1be5232014-01-14 17:45:12 +0200595 int gross_uuars;
Eli Cohene126ba92013-07-07 17:25:49 +0300596 int num_uars;
Eli Cohen78c0f982014-01-30 13:49:48 +0200597 int ver;
Eli Cohene126ba92013-07-07 17:25:49 +0300598 int uuarn;
599 int err;
600 int i;
Jack Morgensteinf241e742014-07-28 23:30:23 +0300601 size_t reqlen;
Eli Cohene126ba92013-07-07 17:25:49 +0300602
603 if (!dev->ib_active)
604 return ERR_PTR(-EAGAIN);
605
Eli Cohen78c0f982014-01-30 13:49:48 +0200606 memset(&req, 0, sizeof(req));
607 reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr);
608 if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req))
609 ver = 0;
610 else if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req_v2))
611 ver = 2;
612 else
613 return ERR_PTR(-EINVAL);
614
615 err = ib_copy_from_udata(&req, udata, reqlen);
Eli Cohene126ba92013-07-07 17:25:49 +0300616 if (err)
617 return ERR_PTR(err);
618
Eli Cohen78c0f982014-01-30 13:49:48 +0200619 if (req.flags || req.reserved)
620 return ERR_PTR(-EINVAL);
621
Eli Cohene126ba92013-07-07 17:25:49 +0300622 if (req.total_num_uuars > MLX5_MAX_UUARS)
623 return ERR_PTR(-ENOMEM);
624
625 if (req.total_num_uuars == 0)
626 return ERR_PTR(-EINVAL);
627
Eli Cohenc1be5232014-01-14 17:45:12 +0200628 req.total_num_uuars = ALIGN(req.total_num_uuars,
629 MLX5_NON_FP_BF_REGS_PER_PAGE);
Eli Cohene126ba92013-07-07 17:25:49 +0300630 if (req.num_low_latency_uuars > req.total_num_uuars - 1)
631 return ERR_PTR(-EINVAL);
632
Eli Cohenc1be5232014-01-14 17:45:12 +0200633 num_uars = req.total_num_uuars / MLX5_NON_FP_BF_REGS_PER_PAGE;
634 gross_uuars = num_uars * MLX5_BF_REGS_PER_PAGE;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300635 resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp);
636 resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size);
637 resp.cache_line_size = L1_CACHE_BYTES;
638 resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq);
639 resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq);
640 resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz);
641 resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz);
642 resp.max_srq_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz);
Eli Cohene126ba92013-07-07 17:25:49 +0300643
644 context = kzalloc(sizeof(*context), GFP_KERNEL);
645 if (!context)
646 return ERR_PTR(-ENOMEM);
647
648 uuari = &context->uuari;
649 mutex_init(&uuari->lock);
650 uars = kcalloc(num_uars, sizeof(*uars), GFP_KERNEL);
651 if (!uars) {
652 err = -ENOMEM;
653 goto out_ctx;
654 }
655
Eli Cohenc1be5232014-01-14 17:45:12 +0200656 uuari->bitmap = kcalloc(BITS_TO_LONGS(gross_uuars),
Eli Cohene126ba92013-07-07 17:25:49 +0300657 sizeof(*uuari->bitmap),
658 GFP_KERNEL);
659 if (!uuari->bitmap) {
660 err = -ENOMEM;
661 goto out_uar_ctx;
662 }
663 /*
664 * clear all fast path uuars
665 */
Eli Cohenc1be5232014-01-14 17:45:12 +0200666 for (i = 0; i < gross_uuars; i++) {
Eli Cohene126ba92013-07-07 17:25:49 +0300667 uuarn = i & 3;
668 if (uuarn == 2 || uuarn == 3)
669 set_bit(i, uuari->bitmap);
670 }
671
Eli Cohenc1be5232014-01-14 17:45:12 +0200672 uuari->count = kcalloc(gross_uuars, sizeof(*uuari->count), GFP_KERNEL);
Eli Cohene126ba92013-07-07 17:25:49 +0300673 if (!uuari->count) {
674 err = -ENOMEM;
675 goto out_bitmap;
676 }
677
678 for (i = 0; i < num_uars; i++) {
Jack Morgenstein9603b612014-07-28 23:30:22 +0300679 err = mlx5_cmd_alloc_uar(dev->mdev, &uars[i].index);
Eli Cohene126ba92013-07-07 17:25:49 +0300680 if (err)
681 goto out_count;
682 }
683
Haggai Eranb4cfe442014-12-11 17:04:26 +0200684#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
685 context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range;
686#endif
687
Eli Cohene126ba92013-07-07 17:25:49 +0300688 INIT_LIST_HEAD(&context->db_page_list);
689 mutex_init(&context->db_page_mutex);
690
691 resp.tot_uuars = req.total_num_uuars;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300692 resp.num_ports = MLX5_CAP_GEN(dev->mdev, num_ports);
Dan Carpenter92b0ca72013-07-25 20:04:36 +0300693 err = ib_copy_to_udata(udata, &resp,
694 sizeof(resp) - sizeof(resp.reserved));
Eli Cohene126ba92013-07-07 17:25:49 +0300695 if (err)
696 goto out_uars;
697
Eli Cohen78c0f982014-01-30 13:49:48 +0200698 uuari->ver = ver;
Eli Cohene126ba92013-07-07 17:25:49 +0300699 uuari->num_low_latency_uuars = req.num_low_latency_uuars;
700 uuari->uars = uars;
701 uuari->num_uars = num_uars;
702 return &context->ibucontext;
703
704out_uars:
705 for (i--; i >= 0; i--)
Jack Morgenstein9603b612014-07-28 23:30:22 +0300706 mlx5_cmd_free_uar(dev->mdev, uars[i].index);
Eli Cohene126ba92013-07-07 17:25:49 +0300707out_count:
708 kfree(uuari->count);
709
710out_bitmap:
711 kfree(uuari->bitmap);
712
713out_uar_ctx:
714 kfree(uars);
715
716out_ctx:
717 kfree(context);
718 return ERR_PTR(err);
719}
720
721static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext)
722{
723 struct mlx5_ib_ucontext *context = to_mucontext(ibcontext);
724 struct mlx5_ib_dev *dev = to_mdev(ibcontext->device);
725 struct mlx5_uuar_info *uuari = &context->uuari;
726 int i;
727
728 for (i = 0; i < uuari->num_uars; i++) {
Jack Morgenstein9603b612014-07-28 23:30:22 +0300729 if (mlx5_cmd_free_uar(dev->mdev, uuari->uars[i].index))
Eli Cohene126ba92013-07-07 17:25:49 +0300730 mlx5_ib_warn(dev, "failed to free UAR 0x%x\n", uuari->uars[i].index);
731 }
732
733 kfree(uuari->count);
734 kfree(uuari->bitmap);
735 kfree(uuari->uars);
736 kfree(context);
737
738 return 0;
739}
740
741static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, int index)
742{
Jack Morgenstein9603b612014-07-28 23:30:22 +0300743 return (pci_resource_start(dev->mdev->pdev, 0) >> PAGE_SHIFT) + index;
Eli Cohene126ba92013-07-07 17:25:49 +0300744}
745
746static int get_command(unsigned long offset)
747{
748 return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK;
749}
750
751static int get_arg(unsigned long offset)
752{
753 return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1);
754}
755
756static int get_index(unsigned long offset)
757{
758 return get_arg(offset);
759}
760
761static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma)
762{
763 struct mlx5_ib_ucontext *context = to_mucontext(ibcontext);
764 struct mlx5_ib_dev *dev = to_mdev(ibcontext->device);
765 struct mlx5_uuar_info *uuari = &context->uuari;
766 unsigned long command;
767 unsigned long idx;
768 phys_addr_t pfn;
769
770 command = get_command(vma->vm_pgoff);
771 switch (command) {
772 case MLX5_IB_MMAP_REGULAR_PAGE:
773 if (vma->vm_end - vma->vm_start != PAGE_SIZE)
774 return -EINVAL;
775
776 idx = get_index(vma->vm_pgoff);
Eli Cohen1c3ce902014-09-14 16:47:53 +0300777 if (idx >= uuari->num_uars)
778 return -EINVAL;
779
Eli Cohene126ba92013-07-07 17:25:49 +0300780 pfn = uar_index2pfn(dev, uuari->uars[idx].index);
781 mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn 0x%llx\n", idx,
782 (unsigned long long)pfn);
783
Eli Cohene126ba92013-07-07 17:25:49 +0300784 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
785 if (io_remap_pfn_range(vma, vma->vm_start, pfn,
786 PAGE_SIZE, vma->vm_page_prot))
787 return -EAGAIN;
788
789 mlx5_ib_dbg(dev, "mapped WC at 0x%lx, PA 0x%llx\n",
790 vma->vm_start,
791 (unsigned long long)pfn << PAGE_SHIFT);
792 break;
793
794 case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES:
795 return -ENOSYS;
796
797 default:
798 return -EINVAL;
799 }
800
801 return 0;
802}
803
Eli Cohene126ba92013-07-07 17:25:49 +0300804static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev,
805 struct ib_ucontext *context,
806 struct ib_udata *udata)
807{
808 struct mlx5_ib_alloc_pd_resp resp;
809 struct mlx5_ib_pd *pd;
810 int err;
811
812 pd = kmalloc(sizeof(*pd), GFP_KERNEL);
813 if (!pd)
814 return ERR_PTR(-ENOMEM);
815
Jack Morgenstein9603b612014-07-28 23:30:22 +0300816 err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn);
Eli Cohene126ba92013-07-07 17:25:49 +0300817 if (err) {
818 kfree(pd);
819 return ERR_PTR(err);
820 }
821
822 if (context) {
823 resp.pdn = pd->pdn;
824 if (ib_copy_to_udata(udata, &resp, sizeof(resp))) {
Jack Morgenstein9603b612014-07-28 23:30:22 +0300825 mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn);
Eli Cohene126ba92013-07-07 17:25:49 +0300826 kfree(pd);
827 return ERR_PTR(-EFAULT);
828 }
Eli Cohene126ba92013-07-07 17:25:49 +0300829 }
830
831 return &pd->ibpd;
832}
833
834static int mlx5_ib_dealloc_pd(struct ib_pd *pd)
835{
836 struct mlx5_ib_dev *mdev = to_mdev(pd->device);
837 struct mlx5_ib_pd *mpd = to_mpd(pd);
838
Jack Morgenstein9603b612014-07-28 23:30:22 +0300839 mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn);
Eli Cohene126ba92013-07-07 17:25:49 +0300840 kfree(mpd);
841
842 return 0;
843}
844
845static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
846{
847 struct mlx5_ib_dev *dev = to_mdev(ibqp->device);
848 int err;
849
Jack Morgenstein9603b612014-07-28 23:30:22 +0300850 err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num);
Eli Cohene126ba92013-07-07 17:25:49 +0300851 if (err)
852 mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n",
853 ibqp->qp_num, gid->raw);
854
855 return err;
856}
857
858static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
859{
860 struct mlx5_ib_dev *dev = to_mdev(ibqp->device);
861 int err;
862
Jack Morgenstein9603b612014-07-28 23:30:22 +0300863 err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num);
Eli Cohene126ba92013-07-07 17:25:49 +0300864 if (err)
865 mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n",
866 ibqp->qp_num, gid->raw);
867
868 return err;
869}
870
871static int init_node_data(struct mlx5_ib_dev *dev)
872{
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300873 int err;
Eli Cohene126ba92013-07-07 17:25:49 +0300874
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300875 err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc);
Eli Cohene126ba92013-07-07 17:25:49 +0300876 if (err)
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300877 return err;
Eli Cohene126ba92013-07-07 17:25:49 +0300878
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300879 dev->mdev->rev_id = dev->mdev->pdev->revision;
Eli Cohene126ba92013-07-07 17:25:49 +0300880
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300881 return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid);
Eli Cohene126ba92013-07-07 17:25:49 +0300882}
883
884static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr,
885 char *buf)
886{
887 struct mlx5_ib_dev *dev =
888 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
889
Jack Morgenstein9603b612014-07-28 23:30:22 +0300890 return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages);
Eli Cohene126ba92013-07-07 17:25:49 +0300891}
892
893static ssize_t show_reg_pages(struct device *device,
894 struct device_attribute *attr, char *buf)
895{
896 struct mlx5_ib_dev *dev =
897 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
898
Haggai Eran6aec21f2014-12-11 17:04:23 +0200899 return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages));
Eli Cohene126ba92013-07-07 17:25:49 +0300900}
901
902static ssize_t show_hca(struct device *device, struct device_attribute *attr,
903 char *buf)
904{
905 struct mlx5_ib_dev *dev =
906 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
Jack Morgenstein9603b612014-07-28 23:30:22 +0300907 return sprintf(buf, "MT%d\n", dev->mdev->pdev->device);
Eli Cohene126ba92013-07-07 17:25:49 +0300908}
909
910static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr,
911 char *buf)
912{
913 struct mlx5_ib_dev *dev =
914 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
Jack Morgenstein9603b612014-07-28 23:30:22 +0300915 return sprintf(buf, "%d.%d.%d\n", fw_rev_maj(dev->mdev),
916 fw_rev_min(dev->mdev), fw_rev_sub(dev->mdev));
Eli Cohene126ba92013-07-07 17:25:49 +0300917}
918
919static ssize_t show_rev(struct device *device, struct device_attribute *attr,
920 char *buf)
921{
922 struct mlx5_ib_dev *dev =
923 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
Jack Morgenstein9603b612014-07-28 23:30:22 +0300924 return sprintf(buf, "%x\n", dev->mdev->rev_id);
Eli Cohene126ba92013-07-07 17:25:49 +0300925}
926
927static ssize_t show_board(struct device *device, struct device_attribute *attr,
928 char *buf)
929{
930 struct mlx5_ib_dev *dev =
931 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
932 return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN,
Jack Morgenstein9603b612014-07-28 23:30:22 +0300933 dev->mdev->board_id);
Eli Cohene126ba92013-07-07 17:25:49 +0300934}
935
936static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
937static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
938static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
939static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
940static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL);
941static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL);
942
943static struct device_attribute *mlx5_class_attributes[] = {
944 &dev_attr_hw_rev,
945 &dev_attr_fw_ver,
946 &dev_attr_hca_type,
947 &dev_attr_board_id,
948 &dev_attr_fw_pages,
949 &dev_attr_reg_pages,
950};
951
Jack Morgenstein9603b612014-07-28 23:30:22 +0300952static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context,
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +0300953 enum mlx5_dev_event event, unsigned long param)
Eli Cohene126ba92013-07-07 17:25:49 +0300954{
Jack Morgenstein9603b612014-07-28 23:30:22 +0300955 struct mlx5_ib_dev *ibdev = (struct mlx5_ib_dev *)context;
Eli Cohene126ba92013-07-07 17:25:49 +0300956 struct ib_event ibev;
Jack Morgenstein9603b612014-07-28 23:30:22 +0300957
Eli Cohene126ba92013-07-07 17:25:49 +0300958 u8 port = 0;
959
960 switch (event) {
961 case MLX5_DEV_EVENT_SYS_ERROR:
962 ibdev->ib_active = false;
963 ibev.event = IB_EVENT_DEVICE_FATAL;
964 break;
965
966 case MLX5_DEV_EVENT_PORT_UP:
967 ibev.event = IB_EVENT_PORT_ACTIVE;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +0300968 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +0300969 break;
970
971 case MLX5_DEV_EVENT_PORT_DOWN:
972 ibev.event = IB_EVENT_PORT_ERR;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +0300973 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +0300974 break;
975
976 case MLX5_DEV_EVENT_PORT_INITIALIZED:
977 /* not used by ULPs */
978 return;
979
980 case MLX5_DEV_EVENT_LID_CHANGE:
981 ibev.event = IB_EVENT_LID_CHANGE;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +0300982 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +0300983 break;
984
985 case MLX5_DEV_EVENT_PKEY_CHANGE:
986 ibev.event = IB_EVENT_PKEY_CHANGE;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +0300987 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +0300988 break;
989
990 case MLX5_DEV_EVENT_GUID_CHANGE:
991 ibev.event = IB_EVENT_GID_CHANGE;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +0300992 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +0300993 break;
994
995 case MLX5_DEV_EVENT_CLIENT_REREG:
996 ibev.event = IB_EVENT_CLIENT_REREGISTER;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +0300997 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +0300998 break;
999 }
1000
1001 ibev.device = &ibdev->ib_dev;
1002 ibev.element.port_num = port;
1003
Eli Cohena0c84c32013-09-11 16:35:27 +03001004 if (port < 1 || port > ibdev->num_ports) {
1005 mlx5_ib_warn(ibdev, "warning: event on port %d\n", port);
1006 return;
1007 }
1008
Eli Cohene126ba92013-07-07 17:25:49 +03001009 if (ibdev->ib_active)
1010 ib_dispatch_event(&ibev);
1011}
1012
1013static void get_ext_port_caps(struct mlx5_ib_dev *dev)
1014{
1015 int port;
1016
Saeed Mahameed938fe832015-05-28 22:28:41 +03001017 for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++)
Eli Cohene126ba92013-07-07 17:25:49 +03001018 mlx5_query_ext_port_caps(dev, port);
1019}
1020
1021static int get_port_caps(struct mlx5_ib_dev *dev)
1022{
1023 struct ib_device_attr *dprops = NULL;
1024 struct ib_port_attr *pprops = NULL;
Dan Carpenterf614fc12015-01-12 11:56:58 +03001025 int err = -ENOMEM;
Eli Cohene126ba92013-07-07 17:25:49 +03001026 int port;
Matan Barak2528e332015-06-11 16:35:25 +03001027 struct ib_udata uhw = {.inlen = 0, .outlen = 0};
Eli Cohene126ba92013-07-07 17:25:49 +03001028
1029 pprops = kmalloc(sizeof(*pprops), GFP_KERNEL);
1030 if (!pprops)
1031 goto out;
1032
1033 dprops = kmalloc(sizeof(*dprops), GFP_KERNEL);
1034 if (!dprops)
1035 goto out;
1036
Matan Barak2528e332015-06-11 16:35:25 +03001037 err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw);
Eli Cohene126ba92013-07-07 17:25:49 +03001038 if (err) {
1039 mlx5_ib_warn(dev, "query_device failed %d\n", err);
1040 goto out;
1041 }
1042
Saeed Mahameed938fe832015-05-28 22:28:41 +03001043 for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++) {
Eli Cohene126ba92013-07-07 17:25:49 +03001044 err = mlx5_ib_query_port(&dev->ib_dev, port, pprops);
1045 if (err) {
Saeed Mahameed938fe832015-05-28 22:28:41 +03001046 mlx5_ib_warn(dev, "query_port %d failed %d\n",
1047 port, err);
Eli Cohene126ba92013-07-07 17:25:49 +03001048 break;
1049 }
Saeed Mahameed938fe832015-05-28 22:28:41 +03001050 dev->mdev->port_caps[port - 1].pkey_table_len =
1051 dprops->max_pkeys;
1052 dev->mdev->port_caps[port - 1].gid_table_len =
1053 pprops->gid_tbl_len;
Eli Cohene126ba92013-07-07 17:25:49 +03001054 mlx5_ib_dbg(dev, "pkey_table_len %d, gid_table_len %d\n",
1055 dprops->max_pkeys, pprops->gid_tbl_len);
1056 }
1057
1058out:
1059 kfree(pprops);
1060 kfree(dprops);
1061
1062 return err;
1063}
1064
1065static void destroy_umrc_res(struct mlx5_ib_dev *dev)
1066{
1067 int err;
1068
1069 err = mlx5_mr_cache_cleanup(dev);
1070 if (err)
1071 mlx5_ib_warn(dev, "mr cache cleanup failed\n");
1072
1073 mlx5_ib_destroy_qp(dev->umrc.qp);
1074 ib_destroy_cq(dev->umrc.cq);
Eli Cohene126ba92013-07-07 17:25:49 +03001075 ib_dealloc_pd(dev->umrc.pd);
1076}
1077
1078enum {
1079 MAX_UMR_WR = 128,
1080};
1081
1082static int create_umr_res(struct mlx5_ib_dev *dev)
1083{
1084 struct ib_qp_init_attr *init_attr = NULL;
1085 struct ib_qp_attr *attr = NULL;
1086 struct ib_pd *pd;
1087 struct ib_cq *cq;
1088 struct ib_qp *qp;
Matan Barak8e372102015-06-11 16:35:21 +03001089 struct ib_cq_init_attr cq_attr = {};
Eli Cohene126ba92013-07-07 17:25:49 +03001090 int ret;
1091
1092 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
1093 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1094 if (!attr || !init_attr) {
1095 ret = -ENOMEM;
1096 goto error_0;
1097 }
1098
1099 pd = ib_alloc_pd(&dev->ib_dev);
1100 if (IS_ERR(pd)) {
1101 mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n");
1102 ret = PTR_ERR(pd);
1103 goto error_0;
1104 }
1105
Matan Barak8e372102015-06-11 16:35:21 +03001106 cq_attr.cqe = 128;
1107 cq = ib_create_cq(&dev->ib_dev, mlx5_umr_cq_handler, NULL, NULL,
1108 &cq_attr);
Eli Cohene126ba92013-07-07 17:25:49 +03001109 if (IS_ERR(cq)) {
1110 mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n");
1111 ret = PTR_ERR(cq);
1112 goto error_2;
1113 }
1114 ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
1115
1116 init_attr->send_cq = cq;
1117 init_attr->recv_cq = cq;
1118 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR;
1119 init_attr->cap.max_send_wr = MAX_UMR_WR;
1120 init_attr->cap.max_send_sge = 1;
1121 init_attr->qp_type = MLX5_IB_QPT_REG_UMR;
1122 init_attr->port_num = 1;
1123 qp = mlx5_ib_create_qp(pd, init_attr, NULL);
1124 if (IS_ERR(qp)) {
1125 mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n");
1126 ret = PTR_ERR(qp);
1127 goto error_3;
1128 }
1129 qp->device = &dev->ib_dev;
1130 qp->real_qp = qp;
1131 qp->uobject = NULL;
1132 qp->qp_type = MLX5_IB_QPT_REG_UMR;
1133
1134 attr->qp_state = IB_QPS_INIT;
1135 attr->port_num = 1;
1136 ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX |
1137 IB_QP_PORT, NULL);
1138 if (ret) {
1139 mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n");
1140 goto error_4;
1141 }
1142
1143 memset(attr, 0, sizeof(*attr));
1144 attr->qp_state = IB_QPS_RTR;
1145 attr->path_mtu = IB_MTU_256;
1146
1147 ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL);
1148 if (ret) {
1149 mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n");
1150 goto error_4;
1151 }
1152
1153 memset(attr, 0, sizeof(*attr));
1154 attr->qp_state = IB_QPS_RTS;
1155 ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL);
1156 if (ret) {
1157 mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n");
1158 goto error_4;
1159 }
1160
1161 dev->umrc.qp = qp;
1162 dev->umrc.cq = cq;
Eli Cohene126ba92013-07-07 17:25:49 +03001163 dev->umrc.pd = pd;
1164
1165 sema_init(&dev->umrc.sem, MAX_UMR_WR);
1166 ret = mlx5_mr_cache_init(dev);
1167 if (ret) {
1168 mlx5_ib_warn(dev, "mr cache init failed %d\n", ret);
1169 goto error_4;
1170 }
1171
1172 kfree(attr);
1173 kfree(init_attr);
1174
1175 return 0;
1176
1177error_4:
1178 mlx5_ib_destroy_qp(qp);
1179
1180error_3:
1181 ib_destroy_cq(cq);
1182
1183error_2:
Eli Cohene126ba92013-07-07 17:25:49 +03001184 ib_dealloc_pd(pd);
1185
1186error_0:
1187 kfree(attr);
1188 kfree(init_attr);
1189 return ret;
1190}
1191
1192static int create_dev_resources(struct mlx5_ib_resources *devr)
1193{
1194 struct ib_srq_init_attr attr;
1195 struct mlx5_ib_dev *dev;
Matan Barakbcf4c1e2015-06-11 16:35:20 +03001196 struct ib_cq_init_attr cq_attr = {.cqe = 1};
Eli Cohene126ba92013-07-07 17:25:49 +03001197 int ret = 0;
1198
1199 dev = container_of(devr, struct mlx5_ib_dev, devr);
1200
1201 devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL);
1202 if (IS_ERR(devr->p0)) {
1203 ret = PTR_ERR(devr->p0);
1204 goto error0;
1205 }
1206 devr->p0->device = &dev->ib_dev;
1207 devr->p0->uobject = NULL;
1208 atomic_set(&devr->p0->usecnt, 0);
1209
Matan Barakbcf4c1e2015-06-11 16:35:20 +03001210 devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, &cq_attr, NULL, NULL);
Eli Cohene126ba92013-07-07 17:25:49 +03001211 if (IS_ERR(devr->c0)) {
1212 ret = PTR_ERR(devr->c0);
1213 goto error1;
1214 }
1215 devr->c0->device = &dev->ib_dev;
1216 devr->c0->uobject = NULL;
1217 devr->c0->comp_handler = NULL;
1218 devr->c0->event_handler = NULL;
1219 devr->c0->cq_context = NULL;
1220 atomic_set(&devr->c0->usecnt, 0);
1221
1222 devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL);
1223 if (IS_ERR(devr->x0)) {
1224 ret = PTR_ERR(devr->x0);
1225 goto error2;
1226 }
1227 devr->x0->device = &dev->ib_dev;
1228 devr->x0->inode = NULL;
1229 atomic_set(&devr->x0->usecnt, 0);
1230 mutex_init(&devr->x0->tgt_qp_mutex);
1231 INIT_LIST_HEAD(&devr->x0->tgt_qp_list);
1232
1233 devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL);
1234 if (IS_ERR(devr->x1)) {
1235 ret = PTR_ERR(devr->x1);
1236 goto error3;
1237 }
1238 devr->x1->device = &dev->ib_dev;
1239 devr->x1->inode = NULL;
1240 atomic_set(&devr->x1->usecnt, 0);
1241 mutex_init(&devr->x1->tgt_qp_mutex);
1242 INIT_LIST_HEAD(&devr->x1->tgt_qp_list);
1243
1244 memset(&attr, 0, sizeof(attr));
1245 attr.attr.max_sge = 1;
1246 attr.attr.max_wr = 1;
1247 attr.srq_type = IB_SRQT_XRC;
1248 attr.ext.xrc.cq = devr->c0;
1249 attr.ext.xrc.xrcd = devr->x0;
1250
1251 devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL);
1252 if (IS_ERR(devr->s0)) {
1253 ret = PTR_ERR(devr->s0);
1254 goto error4;
1255 }
1256 devr->s0->device = &dev->ib_dev;
1257 devr->s0->pd = devr->p0;
1258 devr->s0->uobject = NULL;
1259 devr->s0->event_handler = NULL;
1260 devr->s0->srq_context = NULL;
1261 devr->s0->srq_type = IB_SRQT_XRC;
1262 devr->s0->ext.xrc.xrcd = devr->x0;
1263 devr->s0->ext.xrc.cq = devr->c0;
1264 atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt);
1265 atomic_inc(&devr->s0->ext.xrc.cq->usecnt);
1266 atomic_inc(&devr->p0->usecnt);
1267 atomic_set(&devr->s0->usecnt, 0);
1268
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +03001269 memset(&attr, 0, sizeof(attr));
1270 attr.attr.max_sge = 1;
1271 attr.attr.max_wr = 1;
1272 attr.srq_type = IB_SRQT_BASIC;
1273 devr->s1 = mlx5_ib_create_srq(devr->p0, &attr, NULL);
1274 if (IS_ERR(devr->s1)) {
1275 ret = PTR_ERR(devr->s1);
1276 goto error5;
1277 }
1278 devr->s1->device = &dev->ib_dev;
1279 devr->s1->pd = devr->p0;
1280 devr->s1->uobject = NULL;
1281 devr->s1->event_handler = NULL;
1282 devr->s1->srq_context = NULL;
1283 devr->s1->srq_type = IB_SRQT_BASIC;
1284 devr->s1->ext.xrc.cq = devr->c0;
1285 atomic_inc(&devr->p0->usecnt);
1286 atomic_set(&devr->s0->usecnt, 0);
1287
Eli Cohene126ba92013-07-07 17:25:49 +03001288 return 0;
1289
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +03001290error5:
1291 mlx5_ib_destroy_srq(devr->s0);
Eli Cohene126ba92013-07-07 17:25:49 +03001292error4:
1293 mlx5_ib_dealloc_xrcd(devr->x1);
1294error3:
1295 mlx5_ib_dealloc_xrcd(devr->x0);
1296error2:
1297 mlx5_ib_destroy_cq(devr->c0);
1298error1:
1299 mlx5_ib_dealloc_pd(devr->p0);
1300error0:
1301 return ret;
1302}
1303
1304static void destroy_dev_resources(struct mlx5_ib_resources *devr)
1305{
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +03001306 mlx5_ib_destroy_srq(devr->s1);
Eli Cohene126ba92013-07-07 17:25:49 +03001307 mlx5_ib_destroy_srq(devr->s0);
1308 mlx5_ib_dealloc_xrcd(devr->x0);
1309 mlx5_ib_dealloc_xrcd(devr->x1);
1310 mlx5_ib_destroy_cq(devr->c0);
1311 mlx5_ib_dealloc_pd(devr->p0);
1312}
1313
Ira Weiny77386132015-05-13 20:02:58 -04001314static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num,
1315 struct ib_port_immutable *immutable)
1316{
1317 struct ib_port_attr attr;
1318 int err;
1319
1320 err = mlx5_ib_query_port(ibdev, port_num, &attr);
1321 if (err)
1322 return err;
1323
1324 immutable->pkey_tbl_len = attr.pkey_tbl_len;
1325 immutable->gid_tbl_len = attr.gid_tbl_len;
Ira Weinyf9b22e32015-05-13 20:02:59 -04001326 immutable->core_cap_flags = RDMA_CORE_PORT_IBA_IB;
Ira Weiny337877a2015-06-06 14:38:29 -04001327 immutable->max_mad_size = IB_MGMT_MAD_SIZE;
Ira Weiny77386132015-05-13 20:02:58 -04001328
1329 return 0;
1330}
1331
Jack Morgenstein9603b612014-07-28 23:30:22 +03001332static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
Eli Cohene126ba92013-07-07 17:25:49 +03001333{
Eli Cohene126ba92013-07-07 17:25:49 +03001334 struct mlx5_ib_dev *dev;
Achiad Shochatebd61f62015-12-23 18:47:16 +02001335 enum rdma_link_layer ll;
1336 int port_type_cap;
Eli Cohene126ba92013-07-07 17:25:49 +03001337 int err;
1338 int i;
1339
Achiad Shochatebd61f62015-12-23 18:47:16 +02001340 port_type_cap = MLX5_CAP_GEN(mdev, port_type);
1341 ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap);
1342
Majd Dibbiny647241e2015-06-04 19:30:47 +03001343 /* don't create IB instance over Eth ports, no RoCE yet! */
Achiad Shochatebd61f62015-12-23 18:47:16 +02001344 if (ll == IB_LINK_LAYER_ETHERNET)
Majd Dibbiny647241e2015-06-04 19:30:47 +03001345 return NULL;
1346
Eli Cohene126ba92013-07-07 17:25:49 +03001347 printk_once(KERN_INFO "%s", mlx5_version);
1348
1349 dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev));
1350 if (!dev)
Jack Morgenstein9603b612014-07-28 23:30:22 +03001351 return NULL;
Eli Cohene126ba92013-07-07 17:25:49 +03001352
Jack Morgenstein9603b612014-07-28 23:30:22 +03001353 dev->mdev = mdev;
Eli Cohene126ba92013-07-07 17:25:49 +03001354
1355 err = get_port_caps(dev);
1356 if (err)
Jack Morgenstein9603b612014-07-28 23:30:22 +03001357 goto err_dealloc;
Eli Cohene126ba92013-07-07 17:25:49 +03001358
Majd Dibbiny1b5daf12015-06-04 19:30:46 +03001359 if (mlx5_use_mad_ifc(dev))
1360 get_ext_port_caps(dev);
Eli Cohene126ba92013-07-07 17:25:49 +03001361
Eli Cohene126ba92013-07-07 17:25:49 +03001362 MLX5_INIT_DOORBELL_LOCK(&dev->uar_lock);
1363
1364 strlcpy(dev->ib_dev.name, "mlx5_%d", IB_DEVICE_NAME_MAX);
1365 dev->ib_dev.owner = THIS_MODULE;
1366 dev->ib_dev.node_type = RDMA_NODE_IB_CA;
Sagi Grimbergc6790aa2015-09-24 10:34:23 +03001367 dev->ib_dev.local_dma_lkey = 0 /* not supported for now */;
Saeed Mahameed938fe832015-05-28 22:28:41 +03001368 dev->num_ports = MLX5_CAP_GEN(mdev, num_ports);
Eli Cohene126ba92013-07-07 17:25:49 +03001369 dev->ib_dev.phys_port_cnt = dev->num_ports;
Saeed Mahameed233d05d2015-04-02 17:07:32 +03001370 dev->ib_dev.num_comp_vectors =
1371 dev->mdev->priv.eq_table.num_comp_vectors;
Eli Cohene126ba92013-07-07 17:25:49 +03001372 dev->ib_dev.dma_device = &mdev->pdev->dev;
1373
1374 dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION;
1375 dev->ib_dev.uverbs_cmd_mask =
1376 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
1377 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
1378 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
1379 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
1380 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
1381 (1ull << IB_USER_VERBS_CMD_REG_MR) |
1382 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
1383 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
1384 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
1385 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
1386 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
1387 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
1388 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
1389 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
1390 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
1391 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
1392 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
1393 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
1394 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
1395 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
1396 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
1397 (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) |
1398 (1ull << IB_USER_VERBS_CMD_OPEN_QP);
Haggai Eran1707cb42015-02-08 13:28:52 +02001399 dev->ib_dev.uverbs_ex_cmd_mask =
1400 (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE);
Eli Cohene126ba92013-07-07 17:25:49 +03001401
1402 dev->ib_dev.query_device = mlx5_ib_query_device;
1403 dev->ib_dev.query_port = mlx5_ib_query_port;
Achiad Shochatebd61f62015-12-23 18:47:16 +02001404 dev->ib_dev.get_link_layer = mlx5_ib_port_link_layer;
Eli Cohene126ba92013-07-07 17:25:49 +03001405 dev->ib_dev.query_gid = mlx5_ib_query_gid;
1406 dev->ib_dev.query_pkey = mlx5_ib_query_pkey;
1407 dev->ib_dev.modify_device = mlx5_ib_modify_device;
1408 dev->ib_dev.modify_port = mlx5_ib_modify_port;
1409 dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext;
1410 dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext;
1411 dev->ib_dev.mmap = mlx5_ib_mmap;
1412 dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd;
1413 dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd;
1414 dev->ib_dev.create_ah = mlx5_ib_create_ah;
1415 dev->ib_dev.query_ah = mlx5_ib_query_ah;
1416 dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah;
1417 dev->ib_dev.create_srq = mlx5_ib_create_srq;
1418 dev->ib_dev.modify_srq = mlx5_ib_modify_srq;
1419 dev->ib_dev.query_srq = mlx5_ib_query_srq;
1420 dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq;
1421 dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv;
1422 dev->ib_dev.create_qp = mlx5_ib_create_qp;
1423 dev->ib_dev.modify_qp = mlx5_ib_modify_qp;
1424 dev->ib_dev.query_qp = mlx5_ib_query_qp;
1425 dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp;
1426 dev->ib_dev.post_send = mlx5_ib_post_send;
1427 dev->ib_dev.post_recv = mlx5_ib_post_recv;
1428 dev->ib_dev.create_cq = mlx5_ib_create_cq;
1429 dev->ib_dev.modify_cq = mlx5_ib_modify_cq;
1430 dev->ib_dev.resize_cq = mlx5_ib_resize_cq;
1431 dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq;
1432 dev->ib_dev.poll_cq = mlx5_ib_poll_cq;
1433 dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq;
1434 dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr;
1435 dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr;
1436 dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr;
1437 dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach;
1438 dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach;
1439 dev->ib_dev.process_mad = mlx5_ib_process_mad;
Sagi Grimberg9bee1782015-07-30 10:32:35 +03001440 dev->ib_dev.alloc_mr = mlx5_ib_alloc_mr;
Sagi Grimberg8a187ee2015-10-13 19:11:26 +03001441 dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg;
Sagi Grimbergd5436ba2014-02-23 14:19:12 +02001442 dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status;
Ira Weiny77386132015-05-13 20:02:58 -04001443 dev->ib_dev.get_port_immutable = mlx5_port_immutable;
Eli Cohene126ba92013-07-07 17:25:49 +03001444
Saeed Mahameed938fe832015-05-28 22:28:41 +03001445 mlx5_ib_internal_fill_odp_caps(dev);
Haggai Eran8cdd3122014-12-11 17:04:20 +02001446
Saeed Mahameed938fe832015-05-28 22:28:41 +03001447 if (MLX5_CAP_GEN(mdev, xrc)) {
Eli Cohene126ba92013-07-07 17:25:49 +03001448 dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd;
1449 dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd;
1450 dev->ib_dev.uverbs_cmd_mask |=
1451 (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) |
1452 (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD);
1453 }
1454
1455 err = init_node_data(dev);
1456 if (err)
Saeed Mahameed233d05d2015-04-02 17:07:32 +03001457 goto err_dealloc;
Eli Cohene126ba92013-07-07 17:25:49 +03001458
1459 mutex_init(&dev->cap_mask_mutex);
Eli Cohene126ba92013-07-07 17:25:49 +03001460
1461 err = create_dev_resources(&dev->devr);
1462 if (err)
Saeed Mahameed233d05d2015-04-02 17:07:32 +03001463 goto err_dealloc;
Eli Cohene126ba92013-07-07 17:25:49 +03001464
Haggai Eran6aec21f2014-12-11 17:04:23 +02001465 err = mlx5_ib_odp_init_one(dev);
Wei Yongjun281d1a92013-07-30 07:54:26 +08001466 if (err)
Eli Cohene126ba92013-07-07 17:25:49 +03001467 goto err_rsrc;
1468
Haggai Eran6aec21f2014-12-11 17:04:23 +02001469 err = ib_register_device(&dev->ib_dev, NULL);
1470 if (err)
1471 goto err_odp;
1472
Eli Cohene126ba92013-07-07 17:25:49 +03001473 err = create_umr_res(dev);
1474 if (err)
1475 goto err_dev;
1476
1477 for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) {
Wei Yongjun281d1a92013-07-30 07:54:26 +08001478 err = device_create_file(&dev->ib_dev.dev,
1479 mlx5_class_attributes[i]);
1480 if (err)
Eli Cohene126ba92013-07-07 17:25:49 +03001481 goto err_umrc;
1482 }
1483
1484 dev->ib_active = true;
1485
Jack Morgenstein9603b612014-07-28 23:30:22 +03001486 return dev;
Eli Cohene126ba92013-07-07 17:25:49 +03001487
1488err_umrc:
1489 destroy_umrc_res(dev);
1490
1491err_dev:
1492 ib_unregister_device(&dev->ib_dev);
1493
Haggai Eran6aec21f2014-12-11 17:04:23 +02001494err_odp:
1495 mlx5_ib_odp_remove_one(dev);
1496
Eli Cohene126ba92013-07-07 17:25:49 +03001497err_rsrc:
1498 destroy_dev_resources(&dev->devr);
1499
Jack Morgenstein9603b612014-07-28 23:30:22 +03001500err_dealloc:
Eli Cohene126ba92013-07-07 17:25:49 +03001501 ib_dealloc_device((struct ib_device *)dev);
1502
Jack Morgenstein9603b612014-07-28 23:30:22 +03001503 return NULL;
Eli Cohene126ba92013-07-07 17:25:49 +03001504}
1505
Jack Morgenstein9603b612014-07-28 23:30:22 +03001506static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context)
Eli Cohene126ba92013-07-07 17:25:49 +03001507{
Jack Morgenstein9603b612014-07-28 23:30:22 +03001508 struct mlx5_ib_dev *dev = context;
Haggai Eran6aec21f2014-12-11 17:04:23 +02001509
Eli Cohene126ba92013-07-07 17:25:49 +03001510 ib_unregister_device(&dev->ib_dev);
Eli Coheneefd56e2014-09-14 16:47:50 +03001511 destroy_umrc_res(dev);
Haggai Eran6aec21f2014-12-11 17:04:23 +02001512 mlx5_ib_odp_remove_one(dev);
Eli Cohene126ba92013-07-07 17:25:49 +03001513 destroy_dev_resources(&dev->devr);
Eli Cohene126ba92013-07-07 17:25:49 +03001514 ib_dealloc_device(&dev->ib_dev);
1515}
1516
Jack Morgenstein9603b612014-07-28 23:30:22 +03001517static struct mlx5_interface mlx5_ib_interface = {
1518 .add = mlx5_ib_add,
1519 .remove = mlx5_ib_remove,
1520 .event = mlx5_ib_event,
Saeed Mahameed64613d942015-04-02 17:07:34 +03001521 .protocol = MLX5_INTERFACE_PROTOCOL_IB,
Eli Cohene126ba92013-07-07 17:25:49 +03001522};
1523
1524static int __init mlx5_ib_init(void)
1525{
Haggai Eran6aec21f2014-12-11 17:04:23 +02001526 int err;
1527
Jack Morgenstein9603b612014-07-28 23:30:22 +03001528 if (deprecated_prof_sel != 2)
1529 pr_warn("prof_sel is deprecated for mlx5_ib, set it for mlx5_core\n");
1530
Haggai Eran6aec21f2014-12-11 17:04:23 +02001531 err = mlx5_ib_odp_init();
1532 if (err)
1533 return err;
1534
1535 err = mlx5_register_interface(&mlx5_ib_interface);
1536 if (err)
1537 goto clean_odp;
1538
1539 return err;
1540
1541clean_odp:
1542 mlx5_ib_odp_cleanup();
1543 return err;
Eli Cohene126ba92013-07-07 17:25:49 +03001544}
1545
1546static void __exit mlx5_ib_cleanup(void)
1547{
Jack Morgenstein9603b612014-07-28 23:30:22 +03001548 mlx5_unregister_interface(&mlx5_ib_interface);
Haggai Eran6aec21f2014-12-11 17:04:23 +02001549 mlx5_ib_odp_cleanup();
Eli Cohene126ba92013-07-07 17:25:49 +03001550}
1551
1552module_init(mlx5_ib_init);
1553module_exit(mlx5_ib_cleanup);