blob: 602f067c14cc129f609e64a9e6c0cf9d426fd8ac [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>
Achiad Shochat3f89a642015-12-23 18:47:21 +020043#include <rdma/ib_addr.h>
Achiad Shochat2811ba52015-12-23 18:47:24 +020044#include <rdma/ib_cache.h>
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030045#include <linux/mlx5/vport.h>
Eli Cohene126ba92013-07-07 17:25:49 +030046#include <rdma/ib_smi.h>
47#include <rdma/ib_umem.h>
48#include "user.h"
49#include "mlx5_ib.h"
50
51#define DRIVER_NAME "mlx5_ib"
Amir Vadai169a1d82014-02-19 17:47:31 +020052#define DRIVER_VERSION "2.2-1"
53#define DRIVER_RELDATE "Feb 2014"
Eli Cohene126ba92013-07-07 17:25:49 +030054
55MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
56MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver");
57MODULE_LICENSE("Dual BSD/GPL");
58MODULE_VERSION(DRIVER_VERSION);
59
Jack Morgenstein9603b612014-07-28 23:30:22 +030060static int deprecated_prof_sel = 2;
61module_param_named(prof_sel, deprecated_prof_sel, int, 0444);
62MODULE_PARM_DESC(prof_sel, "profile selector. Deprecated here. Moved to module mlx5_core");
Eli Cohene126ba92013-07-07 17:25:49 +030063
64static char mlx5_version[] =
65 DRIVER_NAME ": Mellanox Connect-IB Infiniband driver v"
66 DRIVER_VERSION " (" DRIVER_RELDATE ")\n";
67
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030068static enum rdma_link_layer
Achiad Shochatebd61f62015-12-23 18:47:16 +020069mlx5_port_type_cap_to_rdma_ll(int port_type_cap)
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030070{
Achiad Shochatebd61f62015-12-23 18:47:16 +020071 switch (port_type_cap) {
Majd Dibbiny1b5daf12015-06-04 19:30:46 +030072 case MLX5_CAP_PORT_TYPE_IB:
73 return IB_LINK_LAYER_INFINIBAND;
74 case MLX5_CAP_PORT_TYPE_ETH:
75 return IB_LINK_LAYER_ETHERNET;
76 default:
77 return IB_LINK_LAYER_UNSPECIFIED;
78 }
79}
80
Achiad Shochatebd61f62015-12-23 18:47:16 +020081static enum rdma_link_layer
82mlx5_ib_port_link_layer(struct ib_device *device, u8 port_num)
83{
84 struct mlx5_ib_dev *dev = to_mdev(device);
85 int port_type_cap = MLX5_CAP_GEN(dev->mdev, port_type);
86
87 return mlx5_port_type_cap_to_rdma_ll(port_type_cap);
88}
89
Achiad Shochatfc24fc52015-12-23 18:47:17 +020090static int mlx5_netdev_event(struct notifier_block *this,
91 unsigned long event, void *ptr)
92{
93 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
94 struct mlx5_ib_dev *ibdev = container_of(this, struct mlx5_ib_dev,
95 roce.nb);
96
97 if ((event != NETDEV_UNREGISTER) && (event != NETDEV_REGISTER))
98 return NOTIFY_DONE;
99
100 write_lock(&ibdev->roce.netdev_lock);
101 if (ndev->dev.parent == &ibdev->mdev->pdev->dev)
102 ibdev->roce.netdev = (event == NETDEV_UNREGISTER) ? NULL : ndev;
103 write_unlock(&ibdev->roce.netdev_lock);
104
105 return NOTIFY_DONE;
106}
107
108static struct net_device *mlx5_ib_get_netdev(struct ib_device *device,
109 u8 port_num)
110{
111 struct mlx5_ib_dev *ibdev = to_mdev(device);
112 struct net_device *ndev;
113
114 /* Ensure ndev does not disappear before we invoke dev_hold()
115 */
116 read_lock(&ibdev->roce.netdev_lock);
117 ndev = ibdev->roce.netdev;
118 if (ndev)
119 dev_hold(ndev);
120 read_unlock(&ibdev->roce.netdev_lock);
121
122 return ndev;
123}
124
Achiad Shochat3f89a642015-12-23 18:47:21 +0200125static int mlx5_query_port_roce(struct ib_device *device, u8 port_num,
126 struct ib_port_attr *props)
127{
128 struct mlx5_ib_dev *dev = to_mdev(device);
129 struct net_device *ndev;
130 enum ib_mtu ndev_ib_mtu;
131
132 memset(props, 0, sizeof(*props));
133
134 props->port_cap_flags |= IB_PORT_CM_SUP;
135 props->port_cap_flags |= IB_PORT_IP_BASED_GIDS;
136
137 props->gid_tbl_len = MLX5_CAP_ROCE(dev->mdev,
138 roce_address_table_size);
139 props->max_mtu = IB_MTU_4096;
140 props->max_msg_sz = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg);
141 props->pkey_tbl_len = 1;
142 props->state = IB_PORT_DOWN;
143 props->phys_state = 3;
144
145 mlx5_query_nic_vport_qkey_viol_cntr(dev->mdev,
146 (u16 *)&props->qkey_viol_cntr);
147
148 ndev = mlx5_ib_get_netdev(device, port_num);
149 if (!ndev)
150 return 0;
151
152 if (netif_running(ndev) && netif_carrier_ok(ndev)) {
153 props->state = IB_PORT_ACTIVE;
154 props->phys_state = 5;
155 }
156
157 ndev_ib_mtu = iboe_get_mtu(ndev->mtu);
158
159 dev_put(ndev);
160
161 props->active_mtu = min(props->max_mtu, ndev_ib_mtu);
162
163 props->active_width = IB_WIDTH_4X; /* TODO */
164 props->active_speed = IB_SPEED_QDR; /* TODO */
165
166 return 0;
167}
168
Achiad Shochat3cca2602015-12-23 18:47:23 +0200169static void ib_gid_to_mlx5_roce_addr(const union ib_gid *gid,
170 const struct ib_gid_attr *attr,
171 void *mlx5_addr)
172{
173#define MLX5_SET_RA(p, f, v) MLX5_SET(roce_addr_layout, p, f, v)
174 char *mlx5_addr_l3_addr = MLX5_ADDR_OF(roce_addr_layout, mlx5_addr,
175 source_l3_address);
176 void *mlx5_addr_mac = MLX5_ADDR_OF(roce_addr_layout, mlx5_addr,
177 source_mac_47_32);
178
179 if (!gid)
180 return;
181
182 ether_addr_copy(mlx5_addr_mac, attr->ndev->dev_addr);
183
184 if (is_vlan_dev(attr->ndev)) {
185 MLX5_SET_RA(mlx5_addr, vlan_valid, 1);
186 MLX5_SET_RA(mlx5_addr, vlan_id, vlan_dev_vlan_id(attr->ndev));
187 }
188
189 switch (attr->gid_type) {
190 case IB_GID_TYPE_IB:
191 MLX5_SET_RA(mlx5_addr, roce_version, MLX5_ROCE_VERSION_1);
192 break;
193 case IB_GID_TYPE_ROCE_UDP_ENCAP:
194 MLX5_SET_RA(mlx5_addr, roce_version, MLX5_ROCE_VERSION_2);
195 break;
196
197 default:
198 WARN_ON(true);
199 }
200
201 if (attr->gid_type != IB_GID_TYPE_IB) {
202 if (ipv6_addr_v4mapped((void *)gid))
203 MLX5_SET_RA(mlx5_addr, roce_l3_type,
204 MLX5_ROCE_L3_TYPE_IPV4);
205 else
206 MLX5_SET_RA(mlx5_addr, roce_l3_type,
207 MLX5_ROCE_L3_TYPE_IPV6);
208 }
209
210 if ((attr->gid_type == IB_GID_TYPE_IB) ||
211 !ipv6_addr_v4mapped((void *)gid))
212 memcpy(mlx5_addr_l3_addr, gid, sizeof(*gid));
213 else
214 memcpy(&mlx5_addr_l3_addr[12], &gid->raw[12], 4);
215}
216
217static int set_roce_addr(struct ib_device *device, u8 port_num,
218 unsigned int index,
219 const union ib_gid *gid,
220 const struct ib_gid_attr *attr)
221{
222 struct mlx5_ib_dev *dev = to_mdev(device);
223 u32 in[MLX5_ST_SZ_DW(set_roce_address_in)];
224 u32 out[MLX5_ST_SZ_DW(set_roce_address_out)];
225 void *in_addr = MLX5_ADDR_OF(set_roce_address_in, in, roce_address);
226 enum rdma_link_layer ll = mlx5_ib_port_link_layer(device, port_num);
227
228 if (ll != IB_LINK_LAYER_ETHERNET)
229 return -EINVAL;
230
231 memset(in, 0, sizeof(in));
232
233 ib_gid_to_mlx5_roce_addr(gid, attr, in_addr);
234
235 MLX5_SET(set_roce_address_in, in, roce_address_index, index);
236 MLX5_SET(set_roce_address_in, in, opcode, MLX5_CMD_OP_SET_ROCE_ADDRESS);
237
238 memset(out, 0, sizeof(out));
239 return mlx5_cmd_exec(dev->mdev, in, sizeof(in), out, sizeof(out));
240}
241
242static int mlx5_ib_add_gid(struct ib_device *device, u8 port_num,
243 unsigned int index, const union ib_gid *gid,
244 const struct ib_gid_attr *attr,
245 __always_unused void **context)
246{
247 return set_roce_addr(device, port_num, index, gid, attr);
248}
249
250static int mlx5_ib_del_gid(struct ib_device *device, u8 port_num,
251 unsigned int index, __always_unused void **context)
252{
253 return set_roce_addr(device, port_num, index, NULL, NULL);
254}
255
Achiad Shochat2811ba52015-12-23 18:47:24 +0200256__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
257 int index)
258{
259 struct ib_gid_attr attr;
260 union ib_gid gid;
261
262 if (ib_get_cached_gid(&dev->ib_dev, port_num, index, &gid, &attr))
263 return 0;
264
265 if (!attr.ndev)
266 return 0;
267
268 dev_put(attr.ndev);
269
270 if (attr.gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP)
271 return 0;
272
273 return cpu_to_be16(MLX5_CAP_ROCE(dev->mdev, r_roce_min_src_udp_port));
274}
275
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300276static int mlx5_use_mad_ifc(struct mlx5_ib_dev *dev)
277{
278 return !dev->mdev->issi;
279}
280
281enum {
282 MLX5_VPORT_ACCESS_METHOD_MAD,
283 MLX5_VPORT_ACCESS_METHOD_HCA,
284 MLX5_VPORT_ACCESS_METHOD_NIC,
285};
286
287static int mlx5_get_vport_access_method(struct ib_device *ibdev)
288{
289 if (mlx5_use_mad_ifc(to_mdev(ibdev)))
290 return MLX5_VPORT_ACCESS_METHOD_MAD;
291
Achiad Shochatebd61f62015-12-23 18:47:16 +0200292 if (mlx5_ib_port_link_layer(ibdev, 1) ==
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300293 IB_LINK_LAYER_ETHERNET)
294 return MLX5_VPORT_ACCESS_METHOD_NIC;
295
296 return MLX5_VPORT_ACCESS_METHOD_HCA;
297}
298
299static int mlx5_query_system_image_guid(struct ib_device *ibdev,
300 __be64 *sys_image_guid)
301{
302 struct mlx5_ib_dev *dev = to_mdev(ibdev);
303 struct mlx5_core_dev *mdev = dev->mdev;
304 u64 tmp;
305 int err;
306
307 switch (mlx5_get_vport_access_method(ibdev)) {
308 case MLX5_VPORT_ACCESS_METHOD_MAD:
309 return mlx5_query_mad_ifc_system_image_guid(ibdev,
310 sys_image_guid);
311
312 case MLX5_VPORT_ACCESS_METHOD_HCA:
313 err = mlx5_query_hca_vport_system_image_guid(mdev, &tmp);
Achiad Shochat3f89a642015-12-23 18:47:21 +0200314 break;
315
316 case MLX5_VPORT_ACCESS_METHOD_NIC:
317 err = mlx5_query_nic_vport_system_image_guid(mdev, &tmp);
318 break;
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300319
320 default:
321 return -EINVAL;
322 }
Achiad Shochat3f89a642015-12-23 18:47:21 +0200323
324 if (!err)
325 *sys_image_guid = cpu_to_be64(tmp);
326
327 return err;
328
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300329}
330
331static int mlx5_query_max_pkeys(struct ib_device *ibdev,
332 u16 *max_pkeys)
333{
334 struct mlx5_ib_dev *dev = to_mdev(ibdev);
335 struct mlx5_core_dev *mdev = dev->mdev;
336
337 switch (mlx5_get_vport_access_method(ibdev)) {
338 case MLX5_VPORT_ACCESS_METHOD_MAD:
339 return mlx5_query_mad_ifc_max_pkeys(ibdev, max_pkeys);
340
341 case MLX5_VPORT_ACCESS_METHOD_HCA:
342 case MLX5_VPORT_ACCESS_METHOD_NIC:
343 *max_pkeys = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev,
344 pkey_table_size));
345 return 0;
346
347 default:
348 return -EINVAL;
349 }
350}
351
352static int mlx5_query_vendor_id(struct ib_device *ibdev,
353 u32 *vendor_id)
354{
355 struct mlx5_ib_dev *dev = to_mdev(ibdev);
356
357 switch (mlx5_get_vport_access_method(ibdev)) {
358 case MLX5_VPORT_ACCESS_METHOD_MAD:
359 return mlx5_query_mad_ifc_vendor_id(ibdev, vendor_id);
360
361 case MLX5_VPORT_ACCESS_METHOD_HCA:
362 case MLX5_VPORT_ACCESS_METHOD_NIC:
363 return mlx5_core_query_vendor_id(dev->mdev, vendor_id);
364
365 default:
366 return -EINVAL;
367 }
368}
369
370static int mlx5_query_node_guid(struct mlx5_ib_dev *dev,
371 __be64 *node_guid)
372{
373 u64 tmp;
374 int err;
375
376 switch (mlx5_get_vport_access_method(&dev->ib_dev)) {
377 case MLX5_VPORT_ACCESS_METHOD_MAD:
378 return mlx5_query_mad_ifc_node_guid(dev, node_guid);
379
380 case MLX5_VPORT_ACCESS_METHOD_HCA:
381 err = mlx5_query_hca_vport_node_guid(dev->mdev, &tmp);
Achiad Shochat3f89a642015-12-23 18:47:21 +0200382 break;
383
384 case MLX5_VPORT_ACCESS_METHOD_NIC:
385 err = mlx5_query_nic_vport_node_guid(dev->mdev, &tmp);
386 break;
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300387
388 default:
389 return -EINVAL;
390 }
Achiad Shochat3f89a642015-12-23 18:47:21 +0200391
392 if (!err)
393 *node_guid = cpu_to_be64(tmp);
394
395 return err;
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300396}
397
398struct mlx5_reg_node_desc {
399 u8 desc[64];
400};
401
402static int mlx5_query_node_desc(struct mlx5_ib_dev *dev, char *node_desc)
403{
404 struct mlx5_reg_node_desc in;
405
406 if (mlx5_use_mad_ifc(dev))
407 return mlx5_query_mad_ifc_node_desc(dev, node_desc);
408
409 memset(&in, 0, sizeof(in));
410
411 return mlx5_core_access_reg(dev->mdev, &in, sizeof(in), node_desc,
412 sizeof(struct mlx5_reg_node_desc),
413 MLX5_REG_NODE_DESC, 0, 0);
414}
415
Eli Cohene126ba92013-07-07 17:25:49 +0300416static int mlx5_ib_query_device(struct ib_device *ibdev,
Matan Barak2528e332015-06-11 16:35:25 +0300417 struct ib_device_attr *props,
418 struct ib_udata *uhw)
Eli Cohene126ba92013-07-07 17:25:49 +0300419{
420 struct mlx5_ib_dev *dev = to_mdev(ibdev);
Saeed Mahameed938fe832015-05-28 22:28:41 +0300421 struct mlx5_core_dev *mdev = dev->mdev;
Eli Cohene126ba92013-07-07 17:25:49 +0300422 int err = -ENOMEM;
423 int max_rq_sg;
424 int max_sq_sg;
Sagi Grimberge0238a62015-07-21 14:40:12 +0300425 u64 min_page_size = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz);
Eli Cohene126ba92013-07-07 17:25:49 +0300426
Matan Barak2528e332015-06-11 16:35:25 +0300427 if (uhw->inlen || uhw->outlen)
428 return -EINVAL;
429
Eli Cohene126ba92013-07-07 17:25:49 +0300430 memset(props, 0, sizeof(*props));
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300431 err = mlx5_query_system_image_guid(ibdev,
432 &props->sys_image_guid);
433 if (err)
434 return err;
435
436 err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys);
437 if (err)
438 return err;
439
440 err = mlx5_query_vendor_id(ibdev, &props->vendor_id);
441 if (err)
442 return err;
Eli Cohene126ba92013-07-07 17:25:49 +0300443
Jack Morgenstein9603b612014-07-28 23:30:22 +0300444 props->fw_ver = ((u64)fw_rev_maj(dev->mdev) << 32) |
445 (fw_rev_min(dev->mdev) << 16) |
446 fw_rev_sub(dev->mdev);
Eli Cohene126ba92013-07-07 17:25:49 +0300447 props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT |
448 IB_DEVICE_PORT_ACTIVE_EVENT |
449 IB_DEVICE_SYS_IMAGE_GUID |
Eli Cohen1a4c3a32014-02-06 17:41:25 +0200450 IB_DEVICE_RC_RNR_NAK_GEN;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300451
452 if (MLX5_CAP_GEN(mdev, pkv))
Eli Cohene126ba92013-07-07 17:25:49 +0300453 props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300454 if (MLX5_CAP_GEN(mdev, qkv))
Eli Cohene126ba92013-07-07 17:25:49 +0300455 props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300456 if (MLX5_CAP_GEN(mdev, apm))
Eli Cohene126ba92013-07-07 17:25:49 +0300457 props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300458 if (MLX5_CAP_GEN(mdev, xrc))
Eli Cohene126ba92013-07-07 17:25:49 +0300459 props->device_cap_flags |= IB_DEVICE_XRC;
460 props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300461 if (MLX5_CAP_GEN(mdev, sho)) {
Sagi Grimberg2dea9092014-02-23 14:19:13 +0200462 props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER;
463 /* At this stage no support for signature handover */
464 props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 |
465 IB_PROT_T10DIF_TYPE_2 |
466 IB_PROT_T10DIF_TYPE_3;
467 props->sig_guard_cap = IB_GUARD_T10DIF_CRC |
468 IB_GUARD_T10DIF_CSUM;
469 }
Saeed Mahameed938fe832015-05-28 22:28:41 +0300470 if (MLX5_CAP_GEN(mdev, block_lb_mc))
Eli Cohenf360d882014-04-02 00:10:16 +0300471 props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK;
Eli Cohene126ba92013-07-07 17:25:49 +0300472
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300473 props->vendor_part_id = mdev->pdev->device;
474 props->hw_ver = mdev->pdev->revision;
Eli Cohene126ba92013-07-07 17:25:49 +0300475
476 props->max_mr_size = ~0ull;
Sagi Grimberge0238a62015-07-21 14:40:12 +0300477 props->page_size_cap = ~(min_page_size - 1);
Saeed Mahameed938fe832015-05-28 22:28:41 +0300478 props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp);
479 props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz);
480 max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) /
481 sizeof(struct mlx5_wqe_data_seg);
482 max_sq_sg = (MLX5_CAP_GEN(mdev, max_wqe_sz_sq) -
483 sizeof(struct mlx5_wqe_ctrl_seg)) /
484 sizeof(struct mlx5_wqe_data_seg);
Eli Cohene126ba92013-07-07 17:25:49 +0300485 props->max_sge = min(max_rq_sg, max_sq_sg);
Sagi Grimberg18ebd402015-07-27 18:10:01 -0500486 props->max_sge_rd = props->max_sge;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300487 props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq);
488 props->max_cqe = (1 << MLX5_CAP_GEN(mdev, log_max_eq_sz)) - 1;
489 props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey);
490 props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd);
491 props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp);
492 props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp);
493 props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq);
494 props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1;
495 props->local_ca_ack_delay = MLX5_CAP_GEN(mdev, local_ca_ack_delay);
Eli Cohene126ba92013-07-07 17:25:49 +0300496 props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
Eli Cohene126ba92013-07-07 17:25:49 +0300497 props->max_srq_sge = max_rq_sg - 1;
498 props->max_fast_reg_page_list_len = (unsigned int)-1;
Eli Cohen81bea282013-09-11 16:35:30 +0300499 props->atomic_cap = IB_ATOMIC_NONE;
500 props->masked_atomic_cap = IB_ATOMIC_NONE;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300501 props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg);
502 props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg);
Eli Cohene126ba92013-07-07 17:25:49 +0300503 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
504 props->max_mcast_grp;
505 props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */
Matan Barak7c60bcb2015-12-15 20:30:11 +0200506 props->hca_core_clock = MLX5_CAP_GEN(mdev, device_frequency_khz);
507 props->timestamp_mask = 0x7FFFFFFFFFFFFFFFULL;
Eli Cohene126ba92013-07-07 17:25:49 +0300508
Haggai Eran8cdd3122014-12-11 17:04:20 +0200509#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
Saeed Mahameed938fe832015-05-28 22:28:41 +0300510 if (MLX5_CAP_GEN(mdev, pg))
Haggai Eran8cdd3122014-12-11 17:04:20 +0200511 props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING;
512 props->odp_caps = dev->odp_caps;
513#endif
514
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300515 return 0;
516}
Eli Cohene126ba92013-07-07 17:25:49 +0300517
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300518enum mlx5_ib_width {
519 MLX5_IB_WIDTH_1X = 1 << 0,
520 MLX5_IB_WIDTH_2X = 1 << 1,
521 MLX5_IB_WIDTH_4X = 1 << 2,
522 MLX5_IB_WIDTH_8X = 1 << 3,
523 MLX5_IB_WIDTH_12X = 1 << 4
524};
525
526static int translate_active_width(struct ib_device *ibdev, u8 active_width,
527 u8 *ib_width)
528{
529 struct mlx5_ib_dev *dev = to_mdev(ibdev);
530 int err = 0;
531
532 if (active_width & MLX5_IB_WIDTH_1X) {
533 *ib_width = IB_WIDTH_1X;
534 } else if (active_width & MLX5_IB_WIDTH_2X) {
535 mlx5_ib_dbg(dev, "active_width %d is not supported by IB spec\n",
536 (int)active_width);
537 err = -EINVAL;
538 } else if (active_width & MLX5_IB_WIDTH_4X) {
539 *ib_width = IB_WIDTH_4X;
540 } else if (active_width & MLX5_IB_WIDTH_8X) {
541 *ib_width = IB_WIDTH_8X;
542 } else if (active_width & MLX5_IB_WIDTH_12X) {
543 *ib_width = IB_WIDTH_12X;
544 } else {
545 mlx5_ib_dbg(dev, "Invalid active_width %d\n",
546 (int)active_width);
547 err = -EINVAL;
548 }
549
550 return err;
551}
552
553static int mlx5_mtu_to_ib_mtu(int mtu)
554{
555 switch (mtu) {
556 case 256: return 1;
557 case 512: return 2;
558 case 1024: return 3;
559 case 2048: return 4;
560 case 4096: return 5;
561 default:
562 pr_warn("invalid mtu\n");
563 return -1;
564 }
565}
566
567enum ib_max_vl_num {
568 __IB_MAX_VL_0 = 1,
569 __IB_MAX_VL_0_1 = 2,
570 __IB_MAX_VL_0_3 = 3,
571 __IB_MAX_VL_0_7 = 4,
572 __IB_MAX_VL_0_14 = 5,
573};
574
575enum mlx5_vl_hw_cap {
576 MLX5_VL_HW_0 = 1,
577 MLX5_VL_HW_0_1 = 2,
578 MLX5_VL_HW_0_2 = 3,
579 MLX5_VL_HW_0_3 = 4,
580 MLX5_VL_HW_0_4 = 5,
581 MLX5_VL_HW_0_5 = 6,
582 MLX5_VL_HW_0_6 = 7,
583 MLX5_VL_HW_0_7 = 8,
584 MLX5_VL_HW_0_14 = 15
585};
586
587static int translate_max_vl_num(struct ib_device *ibdev, u8 vl_hw_cap,
588 u8 *max_vl_num)
589{
590 switch (vl_hw_cap) {
591 case MLX5_VL_HW_0:
592 *max_vl_num = __IB_MAX_VL_0;
593 break;
594 case MLX5_VL_HW_0_1:
595 *max_vl_num = __IB_MAX_VL_0_1;
596 break;
597 case MLX5_VL_HW_0_3:
598 *max_vl_num = __IB_MAX_VL_0_3;
599 break;
600 case MLX5_VL_HW_0_7:
601 *max_vl_num = __IB_MAX_VL_0_7;
602 break;
603 case MLX5_VL_HW_0_14:
604 *max_vl_num = __IB_MAX_VL_0_14;
605 break;
606
607 default:
608 return -EINVAL;
609 }
610
611 return 0;
612}
613
614static int mlx5_query_hca_port(struct ib_device *ibdev, u8 port,
615 struct ib_port_attr *props)
616{
617 struct mlx5_ib_dev *dev = to_mdev(ibdev);
618 struct mlx5_core_dev *mdev = dev->mdev;
619 struct mlx5_hca_vport_context *rep;
620 int max_mtu;
621 int oper_mtu;
622 int err;
623 u8 ib_link_width_oper;
624 u8 vl_hw_cap;
625
626 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
627 if (!rep) {
628 err = -ENOMEM;
629 goto out;
630 }
631
632 memset(props, 0, sizeof(*props));
633
634 err = mlx5_query_hca_vport_context(mdev, 0, port, 0, rep);
635 if (err)
636 goto out;
637
638 props->lid = rep->lid;
639 props->lmc = rep->lmc;
640 props->sm_lid = rep->sm_lid;
641 props->sm_sl = rep->sm_sl;
642 props->state = rep->vport_state;
643 props->phys_state = rep->port_physical_state;
644 props->port_cap_flags = rep->cap_mask1;
645 props->gid_tbl_len = mlx5_get_gid_table_len(MLX5_CAP_GEN(mdev, gid_table_size));
646 props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg);
647 props->pkey_tbl_len = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(mdev, pkey_table_size));
648 props->bad_pkey_cntr = rep->pkey_violation_counter;
649 props->qkey_viol_cntr = rep->qkey_violation_counter;
650 props->subnet_timeout = rep->subnet_timeout;
651 props->init_type_reply = rep->init_type_reply;
652
653 err = mlx5_query_port_link_width_oper(mdev, &ib_link_width_oper, port);
654 if (err)
655 goto out;
656
657 err = translate_active_width(ibdev, ib_link_width_oper,
658 &props->active_width);
659 if (err)
660 goto out;
661 err = mlx5_query_port_proto_oper(mdev, &props->active_speed, MLX5_PTYS_IB,
662 port);
663 if (err)
664 goto out;
665
Saeed Mahameedfacc9692015-06-11 14:47:27 +0300666 mlx5_query_port_max_mtu(mdev, &max_mtu, port);
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300667
668 props->max_mtu = mlx5_mtu_to_ib_mtu(max_mtu);
669
Saeed Mahameedfacc9692015-06-11 14:47:27 +0300670 mlx5_query_port_oper_mtu(mdev, &oper_mtu, port);
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300671
672 props->active_mtu = mlx5_mtu_to_ib_mtu(oper_mtu);
673
674 err = mlx5_query_port_vl_hw_cap(mdev, &vl_hw_cap, port);
675 if (err)
676 goto out;
677
678 err = translate_max_vl_num(ibdev, vl_hw_cap,
679 &props->max_vl_num);
680out:
681 kfree(rep);
Eli Cohene126ba92013-07-07 17:25:49 +0300682 return err;
683}
684
685int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
686 struct ib_port_attr *props)
687{
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300688 switch (mlx5_get_vport_access_method(ibdev)) {
689 case MLX5_VPORT_ACCESS_METHOD_MAD:
690 return mlx5_query_mad_ifc_port(ibdev, port, props);
Eli Cohene126ba92013-07-07 17:25:49 +0300691
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300692 case MLX5_VPORT_ACCESS_METHOD_HCA:
693 return mlx5_query_hca_port(ibdev, port, props);
694
Achiad Shochat3f89a642015-12-23 18:47:21 +0200695 case MLX5_VPORT_ACCESS_METHOD_NIC:
696 return mlx5_query_port_roce(ibdev, port, props);
697
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300698 default:
Eli Cohene126ba92013-07-07 17:25:49 +0300699 return -EINVAL;
700 }
Eli Cohene126ba92013-07-07 17:25:49 +0300701}
702
703static int mlx5_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
704 union ib_gid *gid)
705{
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300706 struct mlx5_ib_dev *dev = to_mdev(ibdev);
707 struct mlx5_core_dev *mdev = dev->mdev;
Eli Cohene126ba92013-07-07 17:25:49 +0300708
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300709 switch (mlx5_get_vport_access_method(ibdev)) {
710 case MLX5_VPORT_ACCESS_METHOD_MAD:
711 return mlx5_query_mad_ifc_gids(ibdev, port, index, gid);
Eli Cohene126ba92013-07-07 17:25:49 +0300712
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300713 case MLX5_VPORT_ACCESS_METHOD_HCA:
714 return mlx5_query_hca_vport_gid(mdev, 0, port, 0, index, gid);
Eli Cohene126ba92013-07-07 17:25:49 +0300715
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300716 default:
717 return -EINVAL;
718 }
Eli Cohene126ba92013-07-07 17:25:49 +0300719
Eli Cohene126ba92013-07-07 17:25:49 +0300720}
721
722static int mlx5_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
723 u16 *pkey)
724{
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300725 struct mlx5_ib_dev *dev = to_mdev(ibdev);
726 struct mlx5_core_dev *mdev = dev->mdev;
Eli Cohene126ba92013-07-07 17:25:49 +0300727
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300728 switch (mlx5_get_vport_access_method(ibdev)) {
729 case MLX5_VPORT_ACCESS_METHOD_MAD:
730 return mlx5_query_mad_ifc_pkey(ibdev, port, index, pkey);
Eli Cohene126ba92013-07-07 17:25:49 +0300731
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300732 case MLX5_VPORT_ACCESS_METHOD_HCA:
733 case MLX5_VPORT_ACCESS_METHOD_NIC:
734 return mlx5_query_hca_vport_pkey(mdev, 0, port, 0, index,
735 pkey);
736 default:
737 return -EINVAL;
738 }
Eli Cohene126ba92013-07-07 17:25:49 +0300739}
740
Eli Cohene126ba92013-07-07 17:25:49 +0300741static int mlx5_ib_modify_device(struct ib_device *ibdev, int mask,
742 struct ib_device_modify *props)
743{
744 struct mlx5_ib_dev *dev = to_mdev(ibdev);
745 struct mlx5_reg_node_desc in;
746 struct mlx5_reg_node_desc out;
747 int err;
748
749 if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
750 return -EOPNOTSUPP;
751
752 if (!(mask & IB_DEVICE_MODIFY_NODE_DESC))
753 return 0;
754
755 /*
756 * If possible, pass node desc to FW, so it can generate
757 * a 144 trap. If cmd fails, just ignore.
758 */
759 memcpy(&in, props->node_desc, 64);
Jack Morgenstein9603b612014-07-28 23:30:22 +0300760 err = mlx5_core_access_reg(dev->mdev, &in, sizeof(in), &out,
Eli Cohene126ba92013-07-07 17:25:49 +0300761 sizeof(out), MLX5_REG_NODE_DESC, 0, 1);
762 if (err)
763 return err;
764
765 memcpy(ibdev->node_desc, props->node_desc, 64);
766
767 return err;
768}
769
770static int mlx5_ib_modify_port(struct ib_device *ibdev, u8 port, int mask,
771 struct ib_port_modify *props)
772{
773 struct mlx5_ib_dev *dev = to_mdev(ibdev);
774 struct ib_port_attr attr;
775 u32 tmp;
776 int err;
777
778 mutex_lock(&dev->cap_mask_mutex);
779
780 err = mlx5_ib_query_port(ibdev, port, &attr);
781 if (err)
782 goto out;
783
784 tmp = (attr.port_cap_flags | props->set_port_cap_mask) &
785 ~props->clr_port_cap_mask;
786
Jack Morgenstein9603b612014-07-28 23:30:22 +0300787 err = mlx5_set_port_caps(dev->mdev, port, tmp);
Eli Cohene126ba92013-07-07 17:25:49 +0300788
789out:
790 mutex_unlock(&dev->cap_mask_mutex);
791 return err;
792}
793
794static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
795 struct ib_udata *udata)
796{
797 struct mlx5_ib_dev *dev = to_mdev(ibdev);
Matan Barakb368d7c2015-12-15 20:30:12 +0200798 struct mlx5_ib_alloc_ucontext_req_v2 req = {};
799 struct mlx5_ib_alloc_ucontext_resp resp = {};
Eli Cohene126ba92013-07-07 17:25:49 +0300800 struct mlx5_ib_ucontext *context;
801 struct mlx5_uuar_info *uuari;
802 struct mlx5_uar *uars;
Eli Cohenc1be5232014-01-14 17:45:12 +0200803 int gross_uuars;
Eli Cohene126ba92013-07-07 17:25:49 +0300804 int num_uars;
Eli Cohen78c0f982014-01-30 13:49:48 +0200805 int ver;
Eli Cohene126ba92013-07-07 17:25:49 +0300806 int uuarn;
807 int err;
808 int i;
Jack Morgensteinf241e742014-07-28 23:30:23 +0300809 size_t reqlen;
Eli Cohene126ba92013-07-07 17:25:49 +0300810
811 if (!dev->ib_active)
812 return ERR_PTR(-EAGAIN);
813
Eli Cohen78c0f982014-01-30 13:49:48 +0200814 reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr);
815 if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req))
816 ver = 0;
Matan Barakb368d7c2015-12-15 20:30:12 +0200817 else if (reqlen >= sizeof(struct mlx5_ib_alloc_ucontext_req_v2))
Eli Cohen78c0f982014-01-30 13:49:48 +0200818 ver = 2;
819 else
820 return ERR_PTR(-EINVAL);
821
Matan Barakb368d7c2015-12-15 20:30:12 +0200822 err = ib_copy_from_udata(&req, udata, min(reqlen, sizeof(req)));
Eli Cohene126ba92013-07-07 17:25:49 +0300823 if (err)
824 return ERR_PTR(err);
825
Matan Barakb368d7c2015-12-15 20:30:12 +0200826 if (req.flags)
Eli Cohen78c0f982014-01-30 13:49:48 +0200827 return ERR_PTR(-EINVAL);
828
Eli Cohene126ba92013-07-07 17:25:49 +0300829 if (req.total_num_uuars > MLX5_MAX_UUARS)
830 return ERR_PTR(-ENOMEM);
831
832 if (req.total_num_uuars == 0)
833 return ERR_PTR(-EINVAL);
834
Matan Barakb368d7c2015-12-15 20:30:12 +0200835 if (req.comp_mask)
836 return ERR_PTR(-EOPNOTSUPP);
837
838 if (reqlen > sizeof(req) &&
839 !ib_is_udata_cleared(udata, sizeof(req),
840 udata->inlen - sizeof(req)))
841 return ERR_PTR(-EOPNOTSUPP);
842
Eli Cohenc1be5232014-01-14 17:45:12 +0200843 req.total_num_uuars = ALIGN(req.total_num_uuars,
844 MLX5_NON_FP_BF_REGS_PER_PAGE);
Eli Cohene126ba92013-07-07 17:25:49 +0300845 if (req.num_low_latency_uuars > req.total_num_uuars - 1)
846 return ERR_PTR(-EINVAL);
847
Eli Cohenc1be5232014-01-14 17:45:12 +0200848 num_uars = req.total_num_uuars / MLX5_NON_FP_BF_REGS_PER_PAGE;
849 gross_uuars = num_uars * MLX5_BF_REGS_PER_PAGE;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300850 resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp);
851 resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size);
852 resp.cache_line_size = L1_CACHE_BYTES;
853 resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq);
854 resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq);
855 resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz);
856 resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz);
857 resp.max_srq_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz);
Matan Barakb368d7c2015-12-15 20:30:12 +0200858 resp.response_length = min(offsetof(typeof(resp), response_length) +
859 sizeof(resp.response_length), udata->outlen);
Eli Cohene126ba92013-07-07 17:25:49 +0300860
861 context = kzalloc(sizeof(*context), GFP_KERNEL);
862 if (!context)
863 return ERR_PTR(-ENOMEM);
864
865 uuari = &context->uuari;
866 mutex_init(&uuari->lock);
867 uars = kcalloc(num_uars, sizeof(*uars), GFP_KERNEL);
868 if (!uars) {
869 err = -ENOMEM;
870 goto out_ctx;
871 }
872
Eli Cohenc1be5232014-01-14 17:45:12 +0200873 uuari->bitmap = kcalloc(BITS_TO_LONGS(gross_uuars),
Eli Cohene126ba92013-07-07 17:25:49 +0300874 sizeof(*uuari->bitmap),
875 GFP_KERNEL);
876 if (!uuari->bitmap) {
877 err = -ENOMEM;
878 goto out_uar_ctx;
879 }
880 /*
881 * clear all fast path uuars
882 */
Eli Cohenc1be5232014-01-14 17:45:12 +0200883 for (i = 0; i < gross_uuars; i++) {
Eli Cohene126ba92013-07-07 17:25:49 +0300884 uuarn = i & 3;
885 if (uuarn == 2 || uuarn == 3)
886 set_bit(i, uuari->bitmap);
887 }
888
Eli Cohenc1be5232014-01-14 17:45:12 +0200889 uuari->count = kcalloc(gross_uuars, sizeof(*uuari->count), GFP_KERNEL);
Eli Cohene126ba92013-07-07 17:25:49 +0300890 if (!uuari->count) {
891 err = -ENOMEM;
892 goto out_bitmap;
893 }
894
895 for (i = 0; i < num_uars; i++) {
Jack Morgenstein9603b612014-07-28 23:30:22 +0300896 err = mlx5_cmd_alloc_uar(dev->mdev, &uars[i].index);
Eli Cohene126ba92013-07-07 17:25:49 +0300897 if (err)
898 goto out_count;
899 }
900
Haggai Eranb4cfe442014-12-11 17:04:26 +0200901#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
902 context->ibucontext.invalidate_range = &mlx5_ib_invalidate_range;
903#endif
904
Eli Cohene126ba92013-07-07 17:25:49 +0300905 INIT_LIST_HEAD(&context->db_page_list);
906 mutex_init(&context->db_page_mutex);
907
908 resp.tot_uuars = req.total_num_uuars;
Saeed Mahameed938fe832015-05-28 22:28:41 +0300909 resp.num_ports = MLX5_CAP_GEN(dev->mdev, num_ports);
Matan Barakb368d7c2015-12-15 20:30:12 +0200910
911 if (field_avail(typeof(resp), reserved2, udata->outlen))
912 resp.response_length += sizeof(resp.reserved2);
913
914 if (field_avail(typeof(resp), hca_core_clock_offset, udata->outlen)) {
915 resp.comp_mask |=
916 MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET;
917 resp.hca_core_clock_offset =
918 offsetof(struct mlx5_init_seg, internal_timer_h) %
919 PAGE_SIZE;
920 resp.response_length += sizeof(resp.hca_core_clock_offset);
921 }
922
923 err = ib_copy_to_udata(udata, &resp, resp.response_length);
Eli Cohene126ba92013-07-07 17:25:49 +0300924 if (err)
925 goto out_uars;
926
Eli Cohen78c0f982014-01-30 13:49:48 +0200927 uuari->ver = ver;
Eli Cohene126ba92013-07-07 17:25:49 +0300928 uuari->num_low_latency_uuars = req.num_low_latency_uuars;
929 uuari->uars = uars;
930 uuari->num_uars = num_uars;
931 return &context->ibucontext;
932
933out_uars:
934 for (i--; i >= 0; i--)
Jack Morgenstein9603b612014-07-28 23:30:22 +0300935 mlx5_cmd_free_uar(dev->mdev, uars[i].index);
Eli Cohene126ba92013-07-07 17:25:49 +0300936out_count:
937 kfree(uuari->count);
938
939out_bitmap:
940 kfree(uuari->bitmap);
941
942out_uar_ctx:
943 kfree(uars);
944
945out_ctx:
946 kfree(context);
947 return ERR_PTR(err);
948}
949
950static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext)
951{
952 struct mlx5_ib_ucontext *context = to_mucontext(ibcontext);
953 struct mlx5_ib_dev *dev = to_mdev(ibcontext->device);
954 struct mlx5_uuar_info *uuari = &context->uuari;
955 int i;
956
957 for (i = 0; i < uuari->num_uars; i++) {
Jack Morgenstein9603b612014-07-28 23:30:22 +0300958 if (mlx5_cmd_free_uar(dev->mdev, uuari->uars[i].index))
Eli Cohene126ba92013-07-07 17:25:49 +0300959 mlx5_ib_warn(dev, "failed to free UAR 0x%x\n", uuari->uars[i].index);
960 }
961
962 kfree(uuari->count);
963 kfree(uuari->bitmap);
964 kfree(uuari->uars);
965 kfree(context);
966
967 return 0;
968}
969
970static phys_addr_t uar_index2pfn(struct mlx5_ib_dev *dev, int index)
971{
Jack Morgenstein9603b612014-07-28 23:30:22 +0300972 return (pci_resource_start(dev->mdev->pdev, 0) >> PAGE_SHIFT) + index;
Eli Cohene126ba92013-07-07 17:25:49 +0300973}
974
975static int get_command(unsigned long offset)
976{
977 return (offset >> MLX5_IB_MMAP_CMD_SHIFT) & MLX5_IB_MMAP_CMD_MASK;
978}
979
980static int get_arg(unsigned long offset)
981{
982 return offset & ((1 << MLX5_IB_MMAP_CMD_SHIFT) - 1);
983}
984
985static int get_index(unsigned long offset)
986{
987 return get_arg(offset);
988}
989
990static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma)
991{
992 struct mlx5_ib_ucontext *context = to_mucontext(ibcontext);
993 struct mlx5_ib_dev *dev = to_mdev(ibcontext->device);
994 struct mlx5_uuar_info *uuari = &context->uuari;
995 unsigned long command;
996 unsigned long idx;
997 phys_addr_t pfn;
998
999 command = get_command(vma->vm_pgoff);
1000 switch (command) {
1001 case MLX5_IB_MMAP_REGULAR_PAGE:
1002 if (vma->vm_end - vma->vm_start != PAGE_SIZE)
1003 return -EINVAL;
1004
1005 idx = get_index(vma->vm_pgoff);
Eli Cohen1c3ce902014-09-14 16:47:53 +03001006 if (idx >= uuari->num_uars)
1007 return -EINVAL;
1008
Eli Cohene126ba92013-07-07 17:25:49 +03001009 pfn = uar_index2pfn(dev, uuari->uars[idx].index);
1010 mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn 0x%llx\n", idx,
1011 (unsigned long long)pfn);
1012
Eli Cohene126ba92013-07-07 17:25:49 +03001013 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1014 if (io_remap_pfn_range(vma, vma->vm_start, pfn,
1015 PAGE_SIZE, vma->vm_page_prot))
1016 return -EAGAIN;
1017
1018 mlx5_ib_dbg(dev, "mapped WC at 0x%lx, PA 0x%llx\n",
1019 vma->vm_start,
1020 (unsigned long long)pfn << PAGE_SHIFT);
1021 break;
1022
1023 case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES:
1024 return -ENOSYS;
1025
Matan Barakd69e3bc2015-12-15 20:30:13 +02001026 case MLX5_IB_MMAP_CORE_CLOCK:
1027 {
1028 phys_addr_t pfn;
1029
1030 if (vma->vm_end - vma->vm_start != PAGE_SIZE)
1031 return -EINVAL;
1032
1033 if (vma->vm_flags & (VM_WRITE | VM_EXEC))
1034 return -EPERM;
1035
1036 /* Don't expose to user-space information it shouldn't have */
1037 if (PAGE_SIZE > 4096)
1038 return -EOPNOTSUPP;
1039
1040 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1041 pfn = (dev->mdev->iseg_base +
1042 offsetof(struct mlx5_init_seg, internal_timer_h)) >>
1043 PAGE_SHIFT;
1044 if (io_remap_pfn_range(vma, vma->vm_start, pfn,
1045 PAGE_SIZE, vma->vm_page_prot))
1046 return -EAGAIN;
1047
1048 mlx5_ib_dbg(dev, "mapped internal timer at 0x%lx, PA 0x%llx\n",
1049 vma->vm_start,
1050 (unsigned long long)pfn << PAGE_SHIFT);
1051 break;
1052 }
1053
Eli Cohene126ba92013-07-07 17:25:49 +03001054 default:
1055 return -EINVAL;
1056 }
1057
1058 return 0;
1059}
1060
Eli Cohene126ba92013-07-07 17:25:49 +03001061static struct ib_pd *mlx5_ib_alloc_pd(struct ib_device *ibdev,
1062 struct ib_ucontext *context,
1063 struct ib_udata *udata)
1064{
1065 struct mlx5_ib_alloc_pd_resp resp;
1066 struct mlx5_ib_pd *pd;
1067 int err;
1068
1069 pd = kmalloc(sizeof(*pd), GFP_KERNEL);
1070 if (!pd)
1071 return ERR_PTR(-ENOMEM);
1072
Jack Morgenstein9603b612014-07-28 23:30:22 +03001073 err = mlx5_core_alloc_pd(to_mdev(ibdev)->mdev, &pd->pdn);
Eli Cohene126ba92013-07-07 17:25:49 +03001074 if (err) {
1075 kfree(pd);
1076 return ERR_PTR(err);
1077 }
1078
1079 if (context) {
1080 resp.pdn = pd->pdn;
1081 if (ib_copy_to_udata(udata, &resp, sizeof(resp))) {
Jack Morgenstein9603b612014-07-28 23:30:22 +03001082 mlx5_core_dealloc_pd(to_mdev(ibdev)->mdev, pd->pdn);
Eli Cohene126ba92013-07-07 17:25:49 +03001083 kfree(pd);
1084 return ERR_PTR(-EFAULT);
1085 }
Eli Cohene126ba92013-07-07 17:25:49 +03001086 }
1087
1088 return &pd->ibpd;
1089}
1090
1091static int mlx5_ib_dealloc_pd(struct ib_pd *pd)
1092{
1093 struct mlx5_ib_dev *mdev = to_mdev(pd->device);
1094 struct mlx5_ib_pd *mpd = to_mpd(pd);
1095
Jack Morgenstein9603b612014-07-28 23:30:22 +03001096 mlx5_core_dealloc_pd(mdev->mdev, mpd->pdn);
Eli Cohene126ba92013-07-07 17:25:49 +03001097 kfree(mpd);
1098
1099 return 0;
1100}
1101
1102static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
1103{
1104 struct mlx5_ib_dev *dev = to_mdev(ibqp->device);
1105 int err;
1106
Jack Morgenstein9603b612014-07-28 23:30:22 +03001107 err = mlx5_core_attach_mcg(dev->mdev, gid, ibqp->qp_num);
Eli Cohene126ba92013-07-07 17:25:49 +03001108 if (err)
1109 mlx5_ib_warn(dev, "failed attaching QPN 0x%x, MGID %pI6\n",
1110 ibqp->qp_num, gid->raw);
1111
1112 return err;
1113}
1114
1115static int mlx5_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
1116{
1117 struct mlx5_ib_dev *dev = to_mdev(ibqp->device);
1118 int err;
1119
Jack Morgenstein9603b612014-07-28 23:30:22 +03001120 err = mlx5_core_detach_mcg(dev->mdev, gid, ibqp->qp_num);
Eli Cohene126ba92013-07-07 17:25:49 +03001121 if (err)
1122 mlx5_ib_warn(dev, "failed detaching QPN 0x%x, MGID %pI6\n",
1123 ibqp->qp_num, gid->raw);
1124
1125 return err;
1126}
1127
1128static int init_node_data(struct mlx5_ib_dev *dev)
1129{
Majd Dibbiny1b5daf12015-06-04 19:30:46 +03001130 int err;
Eli Cohene126ba92013-07-07 17:25:49 +03001131
Majd Dibbiny1b5daf12015-06-04 19:30:46 +03001132 err = mlx5_query_node_desc(dev, dev->ib_dev.node_desc);
Eli Cohene126ba92013-07-07 17:25:49 +03001133 if (err)
Majd Dibbiny1b5daf12015-06-04 19:30:46 +03001134 return err;
Eli Cohene126ba92013-07-07 17:25:49 +03001135
Majd Dibbiny1b5daf12015-06-04 19:30:46 +03001136 dev->mdev->rev_id = dev->mdev->pdev->revision;
Eli Cohene126ba92013-07-07 17:25:49 +03001137
Majd Dibbiny1b5daf12015-06-04 19:30:46 +03001138 return mlx5_query_node_guid(dev, &dev->ib_dev.node_guid);
Eli Cohene126ba92013-07-07 17:25:49 +03001139}
1140
1141static ssize_t show_fw_pages(struct device *device, struct device_attribute *attr,
1142 char *buf)
1143{
1144 struct mlx5_ib_dev *dev =
1145 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
1146
Jack Morgenstein9603b612014-07-28 23:30:22 +03001147 return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages);
Eli Cohene126ba92013-07-07 17:25:49 +03001148}
1149
1150static ssize_t show_reg_pages(struct device *device,
1151 struct device_attribute *attr, char *buf)
1152{
1153 struct mlx5_ib_dev *dev =
1154 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
1155
Haggai Eran6aec21f2014-12-11 17:04:23 +02001156 return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages));
Eli Cohene126ba92013-07-07 17:25:49 +03001157}
1158
1159static ssize_t show_hca(struct device *device, struct device_attribute *attr,
1160 char *buf)
1161{
1162 struct mlx5_ib_dev *dev =
1163 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
Jack Morgenstein9603b612014-07-28 23:30:22 +03001164 return sprintf(buf, "MT%d\n", dev->mdev->pdev->device);
Eli Cohene126ba92013-07-07 17:25:49 +03001165}
1166
1167static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr,
1168 char *buf)
1169{
1170 struct mlx5_ib_dev *dev =
1171 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
Jack Morgenstein9603b612014-07-28 23:30:22 +03001172 return sprintf(buf, "%d.%d.%d\n", fw_rev_maj(dev->mdev),
1173 fw_rev_min(dev->mdev), fw_rev_sub(dev->mdev));
Eli Cohene126ba92013-07-07 17:25:49 +03001174}
1175
1176static ssize_t show_rev(struct device *device, struct device_attribute *attr,
1177 char *buf)
1178{
1179 struct mlx5_ib_dev *dev =
1180 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
Jack Morgenstein9603b612014-07-28 23:30:22 +03001181 return sprintf(buf, "%x\n", dev->mdev->rev_id);
Eli Cohene126ba92013-07-07 17:25:49 +03001182}
1183
1184static ssize_t show_board(struct device *device, struct device_attribute *attr,
1185 char *buf)
1186{
1187 struct mlx5_ib_dev *dev =
1188 container_of(device, struct mlx5_ib_dev, ib_dev.dev);
1189 return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN,
Jack Morgenstein9603b612014-07-28 23:30:22 +03001190 dev->mdev->board_id);
Eli Cohene126ba92013-07-07 17:25:49 +03001191}
1192
1193static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
1194static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
1195static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
1196static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
1197static DEVICE_ATTR(fw_pages, S_IRUGO, show_fw_pages, NULL);
1198static DEVICE_ATTR(reg_pages, S_IRUGO, show_reg_pages, NULL);
1199
1200static struct device_attribute *mlx5_class_attributes[] = {
1201 &dev_attr_hw_rev,
1202 &dev_attr_fw_ver,
1203 &dev_attr_hca_type,
1204 &dev_attr_board_id,
1205 &dev_attr_fw_pages,
1206 &dev_attr_reg_pages,
1207};
1208
Jack Morgenstein9603b612014-07-28 23:30:22 +03001209static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context,
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +03001210 enum mlx5_dev_event event, unsigned long param)
Eli Cohene126ba92013-07-07 17:25:49 +03001211{
Jack Morgenstein9603b612014-07-28 23:30:22 +03001212 struct mlx5_ib_dev *ibdev = (struct mlx5_ib_dev *)context;
Eli Cohene126ba92013-07-07 17:25:49 +03001213 struct ib_event ibev;
Jack Morgenstein9603b612014-07-28 23:30:22 +03001214
Eli Cohene126ba92013-07-07 17:25:49 +03001215 u8 port = 0;
1216
1217 switch (event) {
1218 case MLX5_DEV_EVENT_SYS_ERROR:
1219 ibdev->ib_active = false;
1220 ibev.event = IB_EVENT_DEVICE_FATAL;
1221 break;
1222
1223 case MLX5_DEV_EVENT_PORT_UP:
1224 ibev.event = IB_EVENT_PORT_ACTIVE;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +03001225 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +03001226 break;
1227
1228 case MLX5_DEV_EVENT_PORT_DOWN:
1229 ibev.event = IB_EVENT_PORT_ERR;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +03001230 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +03001231 break;
1232
1233 case MLX5_DEV_EVENT_PORT_INITIALIZED:
1234 /* not used by ULPs */
1235 return;
1236
1237 case MLX5_DEV_EVENT_LID_CHANGE:
1238 ibev.event = IB_EVENT_LID_CHANGE;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +03001239 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +03001240 break;
1241
1242 case MLX5_DEV_EVENT_PKEY_CHANGE:
1243 ibev.event = IB_EVENT_PKEY_CHANGE;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +03001244 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +03001245 break;
1246
1247 case MLX5_DEV_EVENT_GUID_CHANGE:
1248 ibev.event = IB_EVENT_GID_CHANGE;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +03001249 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +03001250 break;
1251
1252 case MLX5_DEV_EVENT_CLIENT_REREG:
1253 ibev.event = IB_EVENT_CLIENT_REREGISTER;
Jack Morgenstein4d2f9bb2014-07-28 23:30:24 +03001254 port = (u8)param;
Eli Cohene126ba92013-07-07 17:25:49 +03001255 break;
1256 }
1257
1258 ibev.device = &ibdev->ib_dev;
1259 ibev.element.port_num = port;
1260
Eli Cohena0c84c32013-09-11 16:35:27 +03001261 if (port < 1 || port > ibdev->num_ports) {
1262 mlx5_ib_warn(ibdev, "warning: event on port %d\n", port);
1263 return;
1264 }
1265
Eli Cohene126ba92013-07-07 17:25:49 +03001266 if (ibdev->ib_active)
1267 ib_dispatch_event(&ibev);
1268}
1269
1270static void get_ext_port_caps(struct mlx5_ib_dev *dev)
1271{
1272 int port;
1273
Saeed Mahameed938fe832015-05-28 22:28:41 +03001274 for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++)
Eli Cohene126ba92013-07-07 17:25:49 +03001275 mlx5_query_ext_port_caps(dev, port);
1276}
1277
1278static int get_port_caps(struct mlx5_ib_dev *dev)
1279{
1280 struct ib_device_attr *dprops = NULL;
1281 struct ib_port_attr *pprops = NULL;
Dan Carpenterf614fc12015-01-12 11:56:58 +03001282 int err = -ENOMEM;
Eli Cohene126ba92013-07-07 17:25:49 +03001283 int port;
Matan Barak2528e332015-06-11 16:35:25 +03001284 struct ib_udata uhw = {.inlen = 0, .outlen = 0};
Eli Cohene126ba92013-07-07 17:25:49 +03001285
1286 pprops = kmalloc(sizeof(*pprops), GFP_KERNEL);
1287 if (!pprops)
1288 goto out;
1289
1290 dprops = kmalloc(sizeof(*dprops), GFP_KERNEL);
1291 if (!dprops)
1292 goto out;
1293
Matan Barak2528e332015-06-11 16:35:25 +03001294 err = mlx5_ib_query_device(&dev->ib_dev, dprops, &uhw);
Eli Cohene126ba92013-07-07 17:25:49 +03001295 if (err) {
1296 mlx5_ib_warn(dev, "query_device failed %d\n", err);
1297 goto out;
1298 }
1299
Saeed Mahameed938fe832015-05-28 22:28:41 +03001300 for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++) {
Eli Cohene126ba92013-07-07 17:25:49 +03001301 err = mlx5_ib_query_port(&dev->ib_dev, port, pprops);
1302 if (err) {
Saeed Mahameed938fe832015-05-28 22:28:41 +03001303 mlx5_ib_warn(dev, "query_port %d failed %d\n",
1304 port, err);
Eli Cohene126ba92013-07-07 17:25:49 +03001305 break;
1306 }
Saeed Mahameed938fe832015-05-28 22:28:41 +03001307 dev->mdev->port_caps[port - 1].pkey_table_len =
1308 dprops->max_pkeys;
1309 dev->mdev->port_caps[port - 1].gid_table_len =
1310 pprops->gid_tbl_len;
Eli Cohene126ba92013-07-07 17:25:49 +03001311 mlx5_ib_dbg(dev, "pkey_table_len %d, gid_table_len %d\n",
1312 dprops->max_pkeys, pprops->gid_tbl_len);
1313 }
1314
1315out:
1316 kfree(pprops);
1317 kfree(dprops);
1318
1319 return err;
1320}
1321
1322static void destroy_umrc_res(struct mlx5_ib_dev *dev)
1323{
1324 int err;
1325
1326 err = mlx5_mr_cache_cleanup(dev);
1327 if (err)
1328 mlx5_ib_warn(dev, "mr cache cleanup failed\n");
1329
1330 mlx5_ib_destroy_qp(dev->umrc.qp);
1331 ib_destroy_cq(dev->umrc.cq);
Eli Cohene126ba92013-07-07 17:25:49 +03001332 ib_dealloc_pd(dev->umrc.pd);
1333}
1334
1335enum {
1336 MAX_UMR_WR = 128,
1337};
1338
1339static int create_umr_res(struct mlx5_ib_dev *dev)
1340{
1341 struct ib_qp_init_attr *init_attr = NULL;
1342 struct ib_qp_attr *attr = NULL;
1343 struct ib_pd *pd;
1344 struct ib_cq *cq;
1345 struct ib_qp *qp;
Matan Barak8e372102015-06-11 16:35:21 +03001346 struct ib_cq_init_attr cq_attr = {};
Eli Cohene126ba92013-07-07 17:25:49 +03001347 int ret;
1348
1349 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
1350 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1351 if (!attr || !init_attr) {
1352 ret = -ENOMEM;
1353 goto error_0;
1354 }
1355
1356 pd = ib_alloc_pd(&dev->ib_dev);
1357 if (IS_ERR(pd)) {
1358 mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n");
1359 ret = PTR_ERR(pd);
1360 goto error_0;
1361 }
1362
Matan Barak8e372102015-06-11 16:35:21 +03001363 cq_attr.cqe = 128;
1364 cq = ib_create_cq(&dev->ib_dev, mlx5_umr_cq_handler, NULL, NULL,
1365 &cq_attr);
Eli Cohene126ba92013-07-07 17:25:49 +03001366 if (IS_ERR(cq)) {
1367 mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n");
1368 ret = PTR_ERR(cq);
1369 goto error_2;
1370 }
1371 ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
1372
1373 init_attr->send_cq = cq;
1374 init_attr->recv_cq = cq;
1375 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR;
1376 init_attr->cap.max_send_wr = MAX_UMR_WR;
1377 init_attr->cap.max_send_sge = 1;
1378 init_attr->qp_type = MLX5_IB_QPT_REG_UMR;
1379 init_attr->port_num = 1;
1380 qp = mlx5_ib_create_qp(pd, init_attr, NULL);
1381 if (IS_ERR(qp)) {
1382 mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n");
1383 ret = PTR_ERR(qp);
1384 goto error_3;
1385 }
1386 qp->device = &dev->ib_dev;
1387 qp->real_qp = qp;
1388 qp->uobject = NULL;
1389 qp->qp_type = MLX5_IB_QPT_REG_UMR;
1390
1391 attr->qp_state = IB_QPS_INIT;
1392 attr->port_num = 1;
1393 ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE | IB_QP_PKEY_INDEX |
1394 IB_QP_PORT, NULL);
1395 if (ret) {
1396 mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n");
1397 goto error_4;
1398 }
1399
1400 memset(attr, 0, sizeof(*attr));
1401 attr->qp_state = IB_QPS_RTR;
1402 attr->path_mtu = IB_MTU_256;
1403
1404 ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL);
1405 if (ret) {
1406 mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n");
1407 goto error_4;
1408 }
1409
1410 memset(attr, 0, sizeof(*attr));
1411 attr->qp_state = IB_QPS_RTS;
1412 ret = mlx5_ib_modify_qp(qp, attr, IB_QP_STATE, NULL);
1413 if (ret) {
1414 mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n");
1415 goto error_4;
1416 }
1417
1418 dev->umrc.qp = qp;
1419 dev->umrc.cq = cq;
Eli Cohene126ba92013-07-07 17:25:49 +03001420 dev->umrc.pd = pd;
1421
1422 sema_init(&dev->umrc.sem, MAX_UMR_WR);
1423 ret = mlx5_mr_cache_init(dev);
1424 if (ret) {
1425 mlx5_ib_warn(dev, "mr cache init failed %d\n", ret);
1426 goto error_4;
1427 }
1428
1429 kfree(attr);
1430 kfree(init_attr);
1431
1432 return 0;
1433
1434error_4:
1435 mlx5_ib_destroy_qp(qp);
1436
1437error_3:
1438 ib_destroy_cq(cq);
1439
1440error_2:
Eli Cohene126ba92013-07-07 17:25:49 +03001441 ib_dealloc_pd(pd);
1442
1443error_0:
1444 kfree(attr);
1445 kfree(init_attr);
1446 return ret;
1447}
1448
1449static int create_dev_resources(struct mlx5_ib_resources *devr)
1450{
1451 struct ib_srq_init_attr attr;
1452 struct mlx5_ib_dev *dev;
Matan Barakbcf4c1e2015-06-11 16:35:20 +03001453 struct ib_cq_init_attr cq_attr = {.cqe = 1};
Eli Cohene126ba92013-07-07 17:25:49 +03001454 int ret = 0;
1455
1456 dev = container_of(devr, struct mlx5_ib_dev, devr);
1457
1458 devr->p0 = mlx5_ib_alloc_pd(&dev->ib_dev, NULL, NULL);
1459 if (IS_ERR(devr->p0)) {
1460 ret = PTR_ERR(devr->p0);
1461 goto error0;
1462 }
1463 devr->p0->device = &dev->ib_dev;
1464 devr->p0->uobject = NULL;
1465 atomic_set(&devr->p0->usecnt, 0);
1466
Matan Barakbcf4c1e2015-06-11 16:35:20 +03001467 devr->c0 = mlx5_ib_create_cq(&dev->ib_dev, &cq_attr, NULL, NULL);
Eli Cohene126ba92013-07-07 17:25:49 +03001468 if (IS_ERR(devr->c0)) {
1469 ret = PTR_ERR(devr->c0);
1470 goto error1;
1471 }
1472 devr->c0->device = &dev->ib_dev;
1473 devr->c0->uobject = NULL;
1474 devr->c0->comp_handler = NULL;
1475 devr->c0->event_handler = NULL;
1476 devr->c0->cq_context = NULL;
1477 atomic_set(&devr->c0->usecnt, 0);
1478
1479 devr->x0 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL);
1480 if (IS_ERR(devr->x0)) {
1481 ret = PTR_ERR(devr->x0);
1482 goto error2;
1483 }
1484 devr->x0->device = &dev->ib_dev;
1485 devr->x0->inode = NULL;
1486 atomic_set(&devr->x0->usecnt, 0);
1487 mutex_init(&devr->x0->tgt_qp_mutex);
1488 INIT_LIST_HEAD(&devr->x0->tgt_qp_list);
1489
1490 devr->x1 = mlx5_ib_alloc_xrcd(&dev->ib_dev, NULL, NULL);
1491 if (IS_ERR(devr->x1)) {
1492 ret = PTR_ERR(devr->x1);
1493 goto error3;
1494 }
1495 devr->x1->device = &dev->ib_dev;
1496 devr->x1->inode = NULL;
1497 atomic_set(&devr->x1->usecnt, 0);
1498 mutex_init(&devr->x1->tgt_qp_mutex);
1499 INIT_LIST_HEAD(&devr->x1->tgt_qp_list);
1500
1501 memset(&attr, 0, sizeof(attr));
1502 attr.attr.max_sge = 1;
1503 attr.attr.max_wr = 1;
1504 attr.srq_type = IB_SRQT_XRC;
1505 attr.ext.xrc.cq = devr->c0;
1506 attr.ext.xrc.xrcd = devr->x0;
1507
1508 devr->s0 = mlx5_ib_create_srq(devr->p0, &attr, NULL);
1509 if (IS_ERR(devr->s0)) {
1510 ret = PTR_ERR(devr->s0);
1511 goto error4;
1512 }
1513 devr->s0->device = &dev->ib_dev;
1514 devr->s0->pd = devr->p0;
1515 devr->s0->uobject = NULL;
1516 devr->s0->event_handler = NULL;
1517 devr->s0->srq_context = NULL;
1518 devr->s0->srq_type = IB_SRQT_XRC;
1519 devr->s0->ext.xrc.xrcd = devr->x0;
1520 devr->s0->ext.xrc.cq = devr->c0;
1521 atomic_inc(&devr->s0->ext.xrc.xrcd->usecnt);
1522 atomic_inc(&devr->s0->ext.xrc.cq->usecnt);
1523 atomic_inc(&devr->p0->usecnt);
1524 atomic_set(&devr->s0->usecnt, 0);
1525
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +03001526 memset(&attr, 0, sizeof(attr));
1527 attr.attr.max_sge = 1;
1528 attr.attr.max_wr = 1;
1529 attr.srq_type = IB_SRQT_BASIC;
1530 devr->s1 = mlx5_ib_create_srq(devr->p0, &attr, NULL);
1531 if (IS_ERR(devr->s1)) {
1532 ret = PTR_ERR(devr->s1);
1533 goto error5;
1534 }
1535 devr->s1->device = &dev->ib_dev;
1536 devr->s1->pd = devr->p0;
1537 devr->s1->uobject = NULL;
1538 devr->s1->event_handler = NULL;
1539 devr->s1->srq_context = NULL;
1540 devr->s1->srq_type = IB_SRQT_BASIC;
1541 devr->s1->ext.xrc.cq = devr->c0;
1542 atomic_inc(&devr->p0->usecnt);
1543 atomic_set(&devr->s0->usecnt, 0);
1544
Eli Cohene126ba92013-07-07 17:25:49 +03001545 return 0;
1546
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +03001547error5:
1548 mlx5_ib_destroy_srq(devr->s0);
Eli Cohene126ba92013-07-07 17:25:49 +03001549error4:
1550 mlx5_ib_dealloc_xrcd(devr->x1);
1551error3:
1552 mlx5_ib_dealloc_xrcd(devr->x0);
1553error2:
1554 mlx5_ib_destroy_cq(devr->c0);
1555error1:
1556 mlx5_ib_dealloc_pd(devr->p0);
1557error0:
1558 return ret;
1559}
1560
1561static void destroy_dev_resources(struct mlx5_ib_resources *devr)
1562{
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +03001563 mlx5_ib_destroy_srq(devr->s1);
Eli Cohene126ba92013-07-07 17:25:49 +03001564 mlx5_ib_destroy_srq(devr->s0);
1565 mlx5_ib_dealloc_xrcd(devr->x0);
1566 mlx5_ib_dealloc_xrcd(devr->x1);
1567 mlx5_ib_destroy_cq(devr->c0);
1568 mlx5_ib_dealloc_pd(devr->p0);
1569}
1570
Achiad Shochate53505a2015-12-23 18:47:25 +02001571static u32 get_core_cap_flags(struct ib_device *ibdev)
1572{
1573 struct mlx5_ib_dev *dev = to_mdev(ibdev);
1574 enum rdma_link_layer ll = mlx5_ib_port_link_layer(ibdev, 1);
1575 u8 l3_type_cap = MLX5_CAP_ROCE(dev->mdev, l3_type);
1576 u8 roce_version_cap = MLX5_CAP_ROCE(dev->mdev, roce_version);
1577 u32 ret = 0;
1578
1579 if (ll == IB_LINK_LAYER_INFINIBAND)
1580 return RDMA_CORE_PORT_IBA_IB;
1581
1582 if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV4_CAP))
1583 return 0;
1584
1585 if (!(l3_type_cap & MLX5_ROCE_L3_TYPE_IPV6_CAP))
1586 return 0;
1587
1588 if (roce_version_cap & MLX5_ROCE_VERSION_1_CAP)
1589 ret |= RDMA_CORE_PORT_IBA_ROCE;
1590
1591 if (roce_version_cap & MLX5_ROCE_VERSION_2_CAP)
1592 ret |= RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
1593
1594 return ret;
1595}
1596
Ira Weiny77386132015-05-13 20:02:58 -04001597static int mlx5_port_immutable(struct ib_device *ibdev, u8 port_num,
1598 struct ib_port_immutable *immutable)
1599{
1600 struct ib_port_attr attr;
1601 int err;
1602
1603 err = mlx5_ib_query_port(ibdev, port_num, &attr);
1604 if (err)
1605 return err;
1606
1607 immutable->pkey_tbl_len = attr.pkey_tbl_len;
1608 immutable->gid_tbl_len = attr.gid_tbl_len;
Achiad Shochate53505a2015-12-23 18:47:25 +02001609 immutable->core_cap_flags = get_core_cap_flags(ibdev);
Ira Weiny337877a2015-06-06 14:38:29 -04001610 immutable->max_mad_size = IB_MGMT_MAD_SIZE;
Ira Weiny77386132015-05-13 20:02:58 -04001611
1612 return 0;
1613}
1614
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001615static int mlx5_enable_roce(struct mlx5_ib_dev *dev)
1616{
Achiad Shochate53505a2015-12-23 18:47:25 +02001617 int err;
1618
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001619 dev->roce.nb.notifier_call = mlx5_netdev_event;
Achiad Shochate53505a2015-12-23 18:47:25 +02001620 err = register_netdevice_notifier(&dev->roce.nb);
1621 if (err)
1622 return err;
1623
1624 err = mlx5_nic_vport_enable_roce(dev->mdev);
1625 if (err)
1626 goto err_unregister_netdevice_notifier;
1627
1628 return 0;
1629
1630err_unregister_netdevice_notifier:
1631 unregister_netdevice_notifier(&dev->roce.nb);
1632 return err;
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001633}
1634
1635static void mlx5_disable_roce(struct mlx5_ib_dev *dev)
1636{
Achiad Shochate53505a2015-12-23 18:47:25 +02001637 mlx5_nic_vport_disable_roce(dev->mdev);
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001638 unregister_netdevice_notifier(&dev->roce.nb);
1639}
1640
Jack Morgenstein9603b612014-07-28 23:30:22 +03001641static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
Eli Cohene126ba92013-07-07 17:25:49 +03001642{
Eli Cohene126ba92013-07-07 17:25:49 +03001643 struct mlx5_ib_dev *dev;
Achiad Shochatebd61f62015-12-23 18:47:16 +02001644 enum rdma_link_layer ll;
1645 int port_type_cap;
Eli Cohene126ba92013-07-07 17:25:49 +03001646 int err;
1647 int i;
1648
Achiad Shochatebd61f62015-12-23 18:47:16 +02001649 port_type_cap = MLX5_CAP_GEN(mdev, port_type);
1650 ll = mlx5_port_type_cap_to_rdma_ll(port_type_cap);
1651
Achiad Shochate53505a2015-12-23 18:47:25 +02001652 if ((ll == IB_LINK_LAYER_ETHERNET) && !MLX5_CAP_GEN(mdev, roce))
Majd Dibbiny647241e2015-06-04 19:30:47 +03001653 return NULL;
1654
Eli Cohene126ba92013-07-07 17:25:49 +03001655 printk_once(KERN_INFO "%s", mlx5_version);
1656
1657 dev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*dev));
1658 if (!dev)
Jack Morgenstein9603b612014-07-28 23:30:22 +03001659 return NULL;
Eli Cohene126ba92013-07-07 17:25:49 +03001660
Jack Morgenstein9603b612014-07-28 23:30:22 +03001661 dev->mdev = mdev;
Eli Cohene126ba92013-07-07 17:25:49 +03001662
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001663 rwlock_init(&dev->roce.netdev_lock);
Eli Cohene126ba92013-07-07 17:25:49 +03001664 err = get_port_caps(dev);
1665 if (err)
Jack Morgenstein9603b612014-07-28 23:30:22 +03001666 goto err_dealloc;
Eli Cohene126ba92013-07-07 17:25:49 +03001667
Majd Dibbiny1b5daf12015-06-04 19:30:46 +03001668 if (mlx5_use_mad_ifc(dev))
1669 get_ext_port_caps(dev);
Eli Cohene126ba92013-07-07 17:25:49 +03001670
Eli Cohene126ba92013-07-07 17:25:49 +03001671 MLX5_INIT_DOORBELL_LOCK(&dev->uar_lock);
1672
1673 strlcpy(dev->ib_dev.name, "mlx5_%d", IB_DEVICE_NAME_MAX);
1674 dev->ib_dev.owner = THIS_MODULE;
1675 dev->ib_dev.node_type = RDMA_NODE_IB_CA;
Sagi Grimbergc6790aa2015-09-24 10:34:23 +03001676 dev->ib_dev.local_dma_lkey = 0 /* not supported for now */;
Saeed Mahameed938fe832015-05-28 22:28:41 +03001677 dev->num_ports = MLX5_CAP_GEN(mdev, num_ports);
Eli Cohene126ba92013-07-07 17:25:49 +03001678 dev->ib_dev.phys_port_cnt = dev->num_ports;
Saeed Mahameed233d05d2015-04-02 17:07:32 +03001679 dev->ib_dev.num_comp_vectors =
1680 dev->mdev->priv.eq_table.num_comp_vectors;
Eli Cohene126ba92013-07-07 17:25:49 +03001681 dev->ib_dev.dma_device = &mdev->pdev->dev;
1682
1683 dev->ib_dev.uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION;
1684 dev->ib_dev.uverbs_cmd_mask =
1685 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
1686 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
1687 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
1688 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
1689 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
1690 (1ull << IB_USER_VERBS_CMD_REG_MR) |
1691 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
1692 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
1693 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
1694 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
1695 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
1696 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
1697 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
1698 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
1699 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
1700 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
1701 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
1702 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
1703 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
1704 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
1705 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
1706 (1ull << IB_USER_VERBS_CMD_CREATE_XSRQ) |
1707 (1ull << IB_USER_VERBS_CMD_OPEN_QP);
Haggai Eran1707cb42015-02-08 13:28:52 +02001708 dev->ib_dev.uverbs_ex_cmd_mask =
1709 (1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE);
Eli Cohene126ba92013-07-07 17:25:49 +03001710
1711 dev->ib_dev.query_device = mlx5_ib_query_device;
1712 dev->ib_dev.query_port = mlx5_ib_query_port;
Achiad Shochatebd61f62015-12-23 18:47:16 +02001713 dev->ib_dev.get_link_layer = mlx5_ib_port_link_layer;
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001714 if (ll == IB_LINK_LAYER_ETHERNET)
1715 dev->ib_dev.get_netdev = mlx5_ib_get_netdev;
Eli Cohene126ba92013-07-07 17:25:49 +03001716 dev->ib_dev.query_gid = mlx5_ib_query_gid;
Achiad Shochat3cca2602015-12-23 18:47:23 +02001717 dev->ib_dev.add_gid = mlx5_ib_add_gid;
1718 dev->ib_dev.del_gid = mlx5_ib_del_gid;
Eli Cohene126ba92013-07-07 17:25:49 +03001719 dev->ib_dev.query_pkey = mlx5_ib_query_pkey;
1720 dev->ib_dev.modify_device = mlx5_ib_modify_device;
1721 dev->ib_dev.modify_port = mlx5_ib_modify_port;
1722 dev->ib_dev.alloc_ucontext = mlx5_ib_alloc_ucontext;
1723 dev->ib_dev.dealloc_ucontext = mlx5_ib_dealloc_ucontext;
1724 dev->ib_dev.mmap = mlx5_ib_mmap;
1725 dev->ib_dev.alloc_pd = mlx5_ib_alloc_pd;
1726 dev->ib_dev.dealloc_pd = mlx5_ib_dealloc_pd;
1727 dev->ib_dev.create_ah = mlx5_ib_create_ah;
1728 dev->ib_dev.query_ah = mlx5_ib_query_ah;
1729 dev->ib_dev.destroy_ah = mlx5_ib_destroy_ah;
1730 dev->ib_dev.create_srq = mlx5_ib_create_srq;
1731 dev->ib_dev.modify_srq = mlx5_ib_modify_srq;
1732 dev->ib_dev.query_srq = mlx5_ib_query_srq;
1733 dev->ib_dev.destroy_srq = mlx5_ib_destroy_srq;
1734 dev->ib_dev.post_srq_recv = mlx5_ib_post_srq_recv;
1735 dev->ib_dev.create_qp = mlx5_ib_create_qp;
1736 dev->ib_dev.modify_qp = mlx5_ib_modify_qp;
1737 dev->ib_dev.query_qp = mlx5_ib_query_qp;
1738 dev->ib_dev.destroy_qp = mlx5_ib_destroy_qp;
1739 dev->ib_dev.post_send = mlx5_ib_post_send;
1740 dev->ib_dev.post_recv = mlx5_ib_post_recv;
1741 dev->ib_dev.create_cq = mlx5_ib_create_cq;
1742 dev->ib_dev.modify_cq = mlx5_ib_modify_cq;
1743 dev->ib_dev.resize_cq = mlx5_ib_resize_cq;
1744 dev->ib_dev.destroy_cq = mlx5_ib_destroy_cq;
1745 dev->ib_dev.poll_cq = mlx5_ib_poll_cq;
1746 dev->ib_dev.req_notify_cq = mlx5_ib_arm_cq;
1747 dev->ib_dev.get_dma_mr = mlx5_ib_get_dma_mr;
1748 dev->ib_dev.reg_user_mr = mlx5_ib_reg_user_mr;
1749 dev->ib_dev.dereg_mr = mlx5_ib_dereg_mr;
1750 dev->ib_dev.attach_mcast = mlx5_ib_mcg_attach;
1751 dev->ib_dev.detach_mcast = mlx5_ib_mcg_detach;
1752 dev->ib_dev.process_mad = mlx5_ib_process_mad;
Sagi Grimberg9bee1782015-07-30 10:32:35 +03001753 dev->ib_dev.alloc_mr = mlx5_ib_alloc_mr;
Sagi Grimberg8a187ee2015-10-13 19:11:26 +03001754 dev->ib_dev.map_mr_sg = mlx5_ib_map_mr_sg;
Sagi Grimbergd5436ba2014-02-23 14:19:12 +02001755 dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status;
Ira Weiny77386132015-05-13 20:02:58 -04001756 dev->ib_dev.get_port_immutable = mlx5_port_immutable;
Eli Cohene126ba92013-07-07 17:25:49 +03001757
Saeed Mahameed938fe832015-05-28 22:28:41 +03001758 mlx5_ib_internal_fill_odp_caps(dev);
Haggai Eran8cdd3122014-12-11 17:04:20 +02001759
Saeed Mahameed938fe832015-05-28 22:28:41 +03001760 if (MLX5_CAP_GEN(mdev, xrc)) {
Eli Cohene126ba92013-07-07 17:25:49 +03001761 dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd;
1762 dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd;
1763 dev->ib_dev.uverbs_cmd_mask |=
1764 (1ull << IB_USER_VERBS_CMD_OPEN_XRCD) |
1765 (1ull << IB_USER_VERBS_CMD_CLOSE_XRCD);
1766 }
1767
1768 err = init_node_data(dev);
1769 if (err)
Saeed Mahameed233d05d2015-04-02 17:07:32 +03001770 goto err_dealloc;
Eli Cohene126ba92013-07-07 17:25:49 +03001771
1772 mutex_init(&dev->cap_mask_mutex);
Eli Cohene126ba92013-07-07 17:25:49 +03001773
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001774 if (ll == IB_LINK_LAYER_ETHERNET) {
1775 err = mlx5_enable_roce(dev);
1776 if (err)
1777 goto err_dealloc;
1778 }
1779
Eli Cohene126ba92013-07-07 17:25:49 +03001780 err = create_dev_resources(&dev->devr);
1781 if (err)
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001782 goto err_disable_roce;
Eli Cohene126ba92013-07-07 17:25:49 +03001783
Haggai Eran6aec21f2014-12-11 17:04:23 +02001784 err = mlx5_ib_odp_init_one(dev);
Wei Yongjun281d1a92013-07-30 07:54:26 +08001785 if (err)
Eli Cohene126ba92013-07-07 17:25:49 +03001786 goto err_rsrc;
1787
Haggai Eran6aec21f2014-12-11 17:04:23 +02001788 err = ib_register_device(&dev->ib_dev, NULL);
1789 if (err)
1790 goto err_odp;
1791
Eli Cohene126ba92013-07-07 17:25:49 +03001792 err = create_umr_res(dev);
1793 if (err)
1794 goto err_dev;
1795
1796 for (i = 0; i < ARRAY_SIZE(mlx5_class_attributes); i++) {
Wei Yongjun281d1a92013-07-30 07:54:26 +08001797 err = device_create_file(&dev->ib_dev.dev,
1798 mlx5_class_attributes[i]);
1799 if (err)
Eli Cohene126ba92013-07-07 17:25:49 +03001800 goto err_umrc;
1801 }
1802
1803 dev->ib_active = true;
1804
Jack Morgenstein9603b612014-07-28 23:30:22 +03001805 return dev;
Eli Cohene126ba92013-07-07 17:25:49 +03001806
1807err_umrc:
1808 destroy_umrc_res(dev);
1809
1810err_dev:
1811 ib_unregister_device(&dev->ib_dev);
1812
Haggai Eran6aec21f2014-12-11 17:04:23 +02001813err_odp:
1814 mlx5_ib_odp_remove_one(dev);
1815
Eli Cohene126ba92013-07-07 17:25:49 +03001816err_rsrc:
1817 destroy_dev_resources(&dev->devr);
1818
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001819err_disable_roce:
1820 if (ll == IB_LINK_LAYER_ETHERNET)
1821 mlx5_disable_roce(dev);
1822
Jack Morgenstein9603b612014-07-28 23:30:22 +03001823err_dealloc:
Eli Cohene126ba92013-07-07 17:25:49 +03001824 ib_dealloc_device((struct ib_device *)dev);
1825
Jack Morgenstein9603b612014-07-28 23:30:22 +03001826 return NULL;
Eli Cohene126ba92013-07-07 17:25:49 +03001827}
1828
Jack Morgenstein9603b612014-07-28 23:30:22 +03001829static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context)
Eli Cohene126ba92013-07-07 17:25:49 +03001830{
Jack Morgenstein9603b612014-07-28 23:30:22 +03001831 struct mlx5_ib_dev *dev = context;
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001832 enum rdma_link_layer ll = mlx5_ib_port_link_layer(&dev->ib_dev, 1);
Haggai Eran6aec21f2014-12-11 17:04:23 +02001833
Eli Cohene126ba92013-07-07 17:25:49 +03001834 ib_unregister_device(&dev->ib_dev);
Eli Coheneefd56e2014-09-14 16:47:50 +03001835 destroy_umrc_res(dev);
Haggai Eran6aec21f2014-12-11 17:04:23 +02001836 mlx5_ib_odp_remove_one(dev);
Eli Cohene126ba92013-07-07 17:25:49 +03001837 destroy_dev_resources(&dev->devr);
Achiad Shochatfc24fc52015-12-23 18:47:17 +02001838 if (ll == IB_LINK_LAYER_ETHERNET)
1839 mlx5_disable_roce(dev);
Eli Cohene126ba92013-07-07 17:25:49 +03001840 ib_dealloc_device(&dev->ib_dev);
1841}
1842
Jack Morgenstein9603b612014-07-28 23:30:22 +03001843static struct mlx5_interface mlx5_ib_interface = {
1844 .add = mlx5_ib_add,
1845 .remove = mlx5_ib_remove,
1846 .event = mlx5_ib_event,
Saeed Mahameed64613d942015-04-02 17:07:34 +03001847 .protocol = MLX5_INTERFACE_PROTOCOL_IB,
Eli Cohene126ba92013-07-07 17:25:49 +03001848};
1849
1850static int __init mlx5_ib_init(void)
1851{
Haggai Eran6aec21f2014-12-11 17:04:23 +02001852 int err;
1853
Jack Morgenstein9603b612014-07-28 23:30:22 +03001854 if (deprecated_prof_sel != 2)
1855 pr_warn("prof_sel is deprecated for mlx5_ib, set it for mlx5_core\n");
1856
Haggai Eran6aec21f2014-12-11 17:04:23 +02001857 err = mlx5_ib_odp_init();
1858 if (err)
1859 return err;
1860
1861 err = mlx5_register_interface(&mlx5_ib_interface);
1862 if (err)
1863 goto clean_odp;
1864
1865 return err;
1866
1867clean_odp:
1868 mlx5_ib_odp_cleanup();
1869 return err;
Eli Cohene126ba92013-07-07 17:25:49 +03001870}
1871
1872static void __exit mlx5_ib_cleanup(void)
1873{
Jack Morgenstein9603b612014-07-28 23:30:22 +03001874 mlx5_unregister_interface(&mlx5_ib_interface);
Haggai Eran6aec21f2014-12-11 17:04:23 +02001875 mlx5_ib_odp_cleanup();
Eli Cohene126ba92013-07-07 17:25:49 +03001876}
1877
1878module_init(mlx5_ib_init);
1879module_exit(mlx5_ib_cleanup);