blob: 2ccf6103e5faaceedff1a7119038dc44d88721d0 [file] [log] [blame]
Dennis Dalessandro01946212016-01-06 09:50:24 -08001/*
Dennis Dalessandrofe314192016-01-22 13:04:58 -08002 * Copyright(c) 2016 Intel Corporation.
Dennis Dalessandro01946212016-01-06 09:50:24 -08003 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include <linux/module.h>
49#include <linux/kernel.h>
50#include "vt.h"
Dennis Dalessandro81ba39a2016-01-22 13:00:28 -080051#include "trace.h"
Dennis Dalessandro01946212016-01-06 09:50:24 -080052
Dennis Dalessandro182285d2016-01-22 13:01:01 -080053#define RVT_UVERBS_ABI_VERSION 2
54
Dennis Dalessandro01946212016-01-06 09:50:24 -080055MODULE_LICENSE("Dual BSD/GPL");
56MODULE_DESCRIPTION("RDMA Verbs Transport Library");
57
58static int rvt_init(void)
59{
60 /* Do any work needed prior to drivers calling for registration*/
61 return 0;
62}
63module_init(rvt_init);
64
65static void rvt_cleanup(void)
66{
67}
68module_exit(rvt_cleanup);
69
Dennis Dalessandroff6acd62016-01-22 13:04:45 -080070struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
71{
72 struct rvt_dev_info *rdi = ERR_PTR(-ENOMEM);
73
74 rdi = (struct rvt_dev_info *)ib_alloc_device(size);
75 if (!rdi)
76 return rdi;
77
78 rdi->ports = kcalloc(nports,
79 sizeof(struct rvt_ibport **),
80 GFP_KERNEL);
81 if (!rdi->ports)
82 ib_dealloc_device(&rdi->ibdev);
83
84 return rdi;
85}
86EXPORT_SYMBOL(rvt_alloc_device);
87
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -080088static int rvt_query_device(struct ib_device *ibdev,
89 struct ib_device_attr *props,
90 struct ib_udata *uhw)
91{
Harish Chegondifeaeb6e2016-01-22 12:50:36 -080092 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
93
94 if (uhw->inlen || uhw->outlen)
95 return -EINVAL;
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -080096 /*
Harish Chegondifeaeb6e2016-01-22 12:50:36 -080097 * Return rvt_dev_info.dparms.props contents
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -080098 */
Harish Chegondifeaeb6e2016-01-22 12:50:36 -080099 *props = rdi->dparms.props;
100 return 0;
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800101}
102
103static int rvt_modify_device(struct ib_device *device,
104 int device_modify_mask,
105 struct ib_device_modify *device_modify)
106{
107 /*
108 * Change dev props. Planned support is for node desc change and sys
109 * guid change only. This matches hfi1 and qib behavior. Other drivers
110 * that support existing modifications will need to add their support.
111 */
112
113 /*
114 * VT-DRIVER-API: node_desc_change()
115 * VT-DRIVER-API: sys_guid_change()
116 */
117 return -EOPNOTSUPP;
118}
119
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800120/**
121 * rvt_query_port: Passes the query port call to the driver
122 * @ibdev: Verbs IB dev
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800123 * @port_num: port number, 1 based from ib core
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800124 * @props: structure to hold returned properties
125 *
126 * Returns 0 on success
127 */
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800128static int rvt_query_port(struct ib_device *ibdev, u8 port_num,
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800129 struct ib_port_attr *props)
130{
Harish Chegondi61a650c2016-02-03 14:15:20 -0800131 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
132 struct rvt_ibport *rvp;
133 int port_index = ibport_num_to_idx(ibdev, port_num);
134
135 if (port_index < 0)
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800136 return -EINVAL;
137
Harish Chegondi61a650c2016-02-03 14:15:20 -0800138 rvp = rdi->ports[port_index];
139 memset(props, 0, sizeof(*props));
140 props->sm_lid = rvp->sm_lid;
141 props->sm_sl = rvp->sm_sl;
142 props->port_cap_flags = rvp->port_cap_flags;
143 props->max_msg_sz = 0x80000000;
144 props->pkey_tbl_len = rvt_get_npkeys(rdi);
145 props->bad_pkey_cntr = rvp->pkey_violations;
146 props->qkey_viol_cntr = rvp->qkey_violations;
147 props->subnet_timeout = rvp->subnet_timeout;
148 props->init_type_reply = 0;
149
150 /* Populate the remaining ib_port_attr elements */
151 return rdi->driver_f.query_port_state(rdi, port_num, props);
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800152}
153
154/**
155 * rvt_modify_port
156 * @ibdev: Verbs IB dev
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800157 * @port_num: Port number, 1 based from ib core
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800158 * @port_modify_mask: How to change the port
159 * @props: Structure to fill in
160 *
161 * Returns 0 on success
162 */
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800163static int rvt_modify_port(struct ib_device *ibdev, u8 port_num,
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800164 int port_modify_mask, struct ib_port_modify *props)
165{
Harish Chegondi61a650c2016-02-03 14:15:20 -0800166 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
167 struct rvt_ibport *rvp;
168 int ret = 0;
169 int port_index = ibport_num_to_idx(ibdev, port_num);
170
171 if (port_index < 0)
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800172 return -EINVAL;
173
Harish Chegondi61a650c2016-02-03 14:15:20 -0800174 rvp = rdi->ports[port_index];
175 rvp->port_cap_flags |= props->set_port_cap_mask;
176 rvp->port_cap_flags &= ~props->clr_port_cap_mask;
177
178 if (props->set_port_cap_mask || props->clr_port_cap_mask)
179 rdi->driver_f.cap_mask_chg(rdi, port_num);
180 if (port_modify_mask & IB_PORT_SHUTDOWN)
181 ret = rdi->driver_f.shut_down_port(rdi, port_num);
182 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
183 rvp->qkey_violations = 0;
184
185 return ret;
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800186}
187
Dennis Dalessandro30588642016-01-06 09:54:16 -0800188/**
189 * rvt_query_pkey - Return a pkey from the table at a given index
190 * @ibdev: Verbs IB dev
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800191 * @port_num: Port number, 1 based from ib core
Dennis Dalessandro30588642016-01-06 09:54:16 -0800192 * @intex: Index into pkey table
193 *
194 * Returns 0 on failure pkey otherwise
195 */
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800196static int rvt_query_pkey(struct ib_device *ibdev, u8 port_num, u16 index,
Dennis Dalessandro30588642016-01-06 09:54:16 -0800197 u16 *pkey)
198{
199 /*
200 * Driver will be responsible for keeping rvt_dev_info.pkey_table up to
201 * date. This function will just return that value. There is no need to
202 * lock, if a stale value is read and sent to the user so be it there is
203 * no way to protect against that anyway.
204 */
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800205 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
206 int port_index;
207
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800208 port_index = ibport_num_to_idx(ibdev, port_num);
209 if (port_index < 0)
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800210 return -EINVAL;
211
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800212 if (index >= rvt_get_npkeys(rdi))
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800213 return -EINVAL;
214
215 *pkey = rvt_get_pkey(rdi, port_index, index);
Dennis Dalessandro30588642016-01-06 09:54:16 -0800216 return 0;
217}
218
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800219/**
220 * rvt_query_gid - Return a gid from the table
221 * @ibdev: Verbs IB dev
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800222 * @port_num: Port number, 1 based from ib core
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800223 * @index: = Index in table
224 * @gid: Gid to return
225 *
226 * Returns 0 on success
227 */
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800228static int rvt_query_gid(struct ib_device *ibdev, u8 port_num,
Dennis Dalessandro1f024992016-02-03 14:15:11 -0800229 int guid_index, union ib_gid *gid)
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800230{
Dennis Dalessandro1f024992016-02-03 14:15:11 -0800231 struct rvt_dev_info *rdi;
232 struct rvt_ibport *rvp;
233 int port_index;
234
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800235 /*
236 * Driver is responsible for updating the guid table. Which will be used
237 * to craft the return value. This will work similar to how query_pkey()
238 * is being done.
239 */
Dennis Dalessandro1f024992016-02-03 14:15:11 -0800240 port_index = ibport_num_to_idx(ibdev, port_num);
241 if (port_index < 0)
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800242 return -EINVAL;
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800243
Dennis Dalessandro1f024992016-02-03 14:15:11 -0800244 rdi = ib_to_rvt(ibdev);
245 rvp = rdi->ports[port_index];
246
247 gid->global.subnet_prefix = rvp->gid_prefix;
248
249 return rdi->driver_f.get_guid_be(rdi, rvp, guid_index,
250 &gid->global.interface_id);
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800251}
252
Harish Chegondi6c43cf42016-01-22 12:50:05 -0800253struct rvt_ucontext {
254 struct ib_ucontext ibucontext;
255};
256
257static inline struct rvt_ucontext *to_iucontext(struct ib_ucontext
258 *ibucontext)
259{
260 return container_of(ibucontext, struct rvt_ucontext, ibucontext);
261}
262
Dennis Dalessandroc4ed7d82016-01-06 09:55:39 -0800263/**
264 * rvt_alloc_ucontext - Allocate a user context
265 * @ibdev: Vers IB dev
266 * @data: User data allocated
267 */
268static struct ib_ucontext *rvt_alloc_ucontext(struct ib_device *ibdev,
269 struct ib_udata *udata)
270{
Harish Chegondi6c43cf42016-01-22 12:50:05 -0800271 struct rvt_ucontext *context;
272
273 context = kmalloc(sizeof(*context), GFP_KERNEL);
274 if (!context)
275 return ERR_PTR(-ENOMEM);
276 return &context->ibucontext;
Dennis Dalessandroc4ed7d82016-01-06 09:55:39 -0800277}
278
279/**
280 *rvt_dealloc_ucontext - Free a user context
281 *@context - Free this
282 */
283static int rvt_dealloc_ucontext(struct ib_ucontext *context)
284{
Harish Chegondi6c43cf42016-01-22 12:50:05 -0800285 kfree(to_iucontext(context));
286 return 0;
Dennis Dalessandroc4ed7d82016-01-06 09:55:39 -0800287}
288
Dennis Dalessandroe6a88182016-01-06 09:59:38 -0800289static int rvt_get_port_immutable(struct ib_device *ibdev, u8 port_num,
290 struct ib_port_immutable *immutable)
291{
Harish Chegondi61a650c2016-02-03 14:15:20 -0800292 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
293 struct ib_port_attr attr;
294 int err, port_index;
295
296 port_index = ibport_num_to_idx(ibdev, port_num);
297 if (port_index < 0)
298 return -EINVAL;
299
300 err = rvt_query_port(ibdev, port_num, &attr);
301 if (err)
302 return err;
303
304 immutable->pkey_tbl_len = attr.pkey_tbl_len;
305 immutable->gid_tbl_len = attr.gid_tbl_len;
306 immutable->core_cap_flags = rdi->dparms.core_cap_flags;
307 immutable->max_mad_size = rdi->dparms.max_mad_size;
308
309 return 0;
Dennis Dalessandroe6a88182016-01-06 09:59:38 -0800310}
311
Dennis Dalessandro49978702016-01-06 09:52:40 -0800312/*
313 * Check driver override. If driver passes a value use it, otherwise we use our
314 * own value.
315 */
316#define CHECK_DRIVER_OVERRIDE(rdi, x) \
317 rdi->ibdev.x = rdi->ibdev.x ? : rvt_ ##x
318
Dennis Dalessandro01946212016-01-06 09:50:24 -0800319int rvt_register_device(struct rvt_dev_info *rdi)
320{
Dennis Dalessandrob5348752016-01-06 10:02:59 -0800321 /* Validate that drivers have provided the right information */
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800322 int ret = 0;
323
Dennis Dalessandro01946212016-01-06 09:50:24 -0800324 if (!rdi)
325 return -EINVAL;
326
Dennis Dalessandrob5348752016-01-06 10:02:59 -0800327 if ((!rdi->driver_f.port_callback) ||
328 (!rdi->driver_f.get_card_name) ||
Kamal Heib119a8e72016-01-06 10:03:59 -0800329 (!rdi->driver_f.get_pci_dev) ||
330 (!rdi->driver_f.check_ah)) {
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800331 pr_err("Driver not supporting req func\n");
Dennis Dalessandrob5348752016-01-06 10:02:59 -0800332 return -EINVAL;
333 }
334
Dennis Dalessandro81ba39a2016-01-22 13:00:28 -0800335 /* Once we get past here we can use rvt_pr macros and tracepoints */
336 trace_rvt_dbg(rdi, "Driver attempting registration");
Dennis Dalessandro822514d2016-01-06 10:04:57 -0800337 rvt_mmap_init(rdi);
Dennis Dalessandrob5348752016-01-06 10:02:59 -0800338
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800339 /* Dev Ops */
340 CHECK_DRIVER_OVERRIDE(rdi, query_device);
341 CHECK_DRIVER_OVERRIDE(rdi, modify_device);
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800342 CHECK_DRIVER_OVERRIDE(rdi, query_port);
343 CHECK_DRIVER_OVERRIDE(rdi, modify_port);
Dennis Dalessandro30588642016-01-06 09:54:16 -0800344 CHECK_DRIVER_OVERRIDE(rdi, query_pkey);
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800345 CHECK_DRIVER_OVERRIDE(rdi, query_gid);
Dennis Dalessandroc4ed7d82016-01-06 09:55:39 -0800346 CHECK_DRIVER_OVERRIDE(rdi, alloc_ucontext);
347 CHECK_DRIVER_OVERRIDE(rdi, dealloc_ucontext);
Dennis Dalessandroe6a88182016-01-06 09:59:38 -0800348 CHECK_DRIVER_OVERRIDE(rdi, get_port_immutable);
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800349
Dennis Dalessandrob518d3e2016-01-06 09:56:15 -0800350 /* Queue Pairs */
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800351 ret = rvt_driver_qp_init(rdi);
352 if (ret) {
353 pr_err("Error in driver QP init.\n");
354 return -EINVAL;
355 }
356
Dennis Dalessandrob518d3e2016-01-06 09:56:15 -0800357 CHECK_DRIVER_OVERRIDE(rdi, create_qp);
358 CHECK_DRIVER_OVERRIDE(rdi, modify_qp);
359 CHECK_DRIVER_OVERRIDE(rdi, destroy_qp);
360 CHECK_DRIVER_OVERRIDE(rdi, query_qp);
Dennis Dalessandro8cf40202016-01-06 10:01:17 -0800361 CHECK_DRIVER_OVERRIDE(rdi, post_send);
362 CHECK_DRIVER_OVERRIDE(rdi, post_recv);
363 CHECK_DRIVER_OVERRIDE(rdi, post_srq_recv);
Dennis Dalessandrob518d3e2016-01-06 09:56:15 -0800364
Dennis Dalessandro4c1e4972016-01-06 09:56:41 -0800365 /* Address Handle */
366 CHECK_DRIVER_OVERRIDE(rdi, create_ah);
367 CHECK_DRIVER_OVERRIDE(rdi, destroy_ah);
368 CHECK_DRIVER_OVERRIDE(rdi, modify_ah);
369 CHECK_DRIVER_OVERRIDE(rdi, query_ah);
Kamal Heib119a8e72016-01-06 10:03:59 -0800370 spin_lock_init(&rdi->n_ahs_lock);
371 rdi->n_ahs_allocated = 0;
Dennis Dalessandro4c1e4972016-01-06 09:56:41 -0800372
Dennis Dalessandroaad91582016-01-06 09:57:58 -0800373 /* Shared Receive Queue */
374 CHECK_DRIVER_OVERRIDE(rdi, create_srq);
375 CHECK_DRIVER_OVERRIDE(rdi, modify_srq);
376 CHECK_DRIVER_OVERRIDE(rdi, destroy_srq);
377 CHECK_DRIVER_OVERRIDE(rdi, query_srq);
Jubin Johnb8f881b2016-02-03 14:14:36 -0800378 rvt_driver_srq_init(rdi);
Dennis Dalessandroaad91582016-01-06 09:57:58 -0800379
Dennis Dalessandro9fa25172016-01-06 09:58:23 -0800380 /* Multicast */
Dennis Dalessandro4e740802016-01-22 13:00:55 -0800381 rvt_driver_mcast_init(rdi);
Dennis Dalessandro9fa25172016-01-06 09:58:23 -0800382 CHECK_DRIVER_OVERRIDE(rdi, attach_mcast);
383 CHECK_DRIVER_OVERRIDE(rdi, detach_mcast);
384
Dennis Dalessandro2a055eb2016-01-06 09:57:21 -0800385 /* Mem Region */
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800386 ret = rvt_driver_mr_init(rdi);
387 if (ret) {
Dennis Dalessandro36055a02016-01-06 10:03:39 -0800388 pr_err("Error in driver MR init.\n");
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800389 goto bail_no_mr;
390 }
391
Dennis Dalessandro2a055eb2016-01-06 09:57:21 -0800392 CHECK_DRIVER_OVERRIDE(rdi, get_dma_mr);
393 CHECK_DRIVER_OVERRIDE(rdi, reg_user_mr);
394 CHECK_DRIVER_OVERRIDE(rdi, dereg_mr);
395 CHECK_DRIVER_OVERRIDE(rdi, alloc_mr);
396 CHECK_DRIVER_OVERRIDE(rdi, alloc_fmr);
397 CHECK_DRIVER_OVERRIDE(rdi, map_phys_fmr);
398 CHECK_DRIVER_OVERRIDE(rdi, unmap_fmr);
399 CHECK_DRIVER_OVERRIDE(rdi, dealloc_fmr);
Dennis Dalessandrodc217522016-01-06 09:59:04 -0800400 CHECK_DRIVER_OVERRIDE(rdi, mmap);
Dennis Dalessandro2a055eb2016-01-06 09:57:21 -0800401
Dennis Dalessandrocf163352016-01-06 10:00:42 -0800402 /* Completion queues */
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800403 ret = rvt_driver_cq_init(rdi);
404 if (ret) {
405 pr_err("Error in driver CQ init.\n");
406 goto bail_mr;
407 }
Dennis Dalessandrocf163352016-01-06 10:00:42 -0800408 CHECK_DRIVER_OVERRIDE(rdi, create_cq);
409 CHECK_DRIVER_OVERRIDE(rdi, destroy_cq);
410 CHECK_DRIVER_OVERRIDE(rdi, poll_cq);
411 CHECK_DRIVER_OVERRIDE(rdi, req_notify_cq);
412 CHECK_DRIVER_OVERRIDE(rdi, resize_cq);
413
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800414 /* DMA Operations */
Dennis Dalessandroc1b332b2016-01-06 09:51:18 -0800415 rdi->ibdev.dma_ops =
416 rdi->ibdev.dma_ops ? : &rvt_default_dma_mapping_ops;
417
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800418 /* Protection Domain */
Dennis Dalessandro49978702016-01-06 09:52:40 -0800419 CHECK_DRIVER_OVERRIDE(rdi, alloc_pd);
420 CHECK_DRIVER_OVERRIDE(rdi, dealloc_pd);
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800421 spin_lock_init(&rdi->n_pds_lock);
422 rdi->n_pds_allocated = 0;
423
Dennis Dalessandro182285d2016-01-22 13:01:01 -0800424 /*
425 * There are some things which could be set by underlying drivers but
426 * really should be up to rdmavt to set. For instance drivers can't know
427 * exactly which functions rdmavt supports, nor do they know the ABI
428 * version, so we do all of this sort of stuff here.
429 */
430 rdi->ibdev.uverbs_abi_ver = RVT_UVERBS_ABI_VERSION;
431 rdi->ibdev.uverbs_cmd_mask =
432 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
433 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
434 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
435 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
436 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
437 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
438 (1ull << IB_USER_VERBS_CMD_MODIFY_AH) |
439 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
440 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
441 (1ull << IB_USER_VERBS_CMD_REG_MR) |
442 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
443 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
444 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
445 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
446 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
447 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
448 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
449 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
450 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
451 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
452 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
453 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
454 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
455 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
456 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
457 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
458 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
459 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
460 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
461 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
462 rdi->ibdev.node_type = RDMA_NODE_IB_CA;
463 rdi->ibdev.num_comp_vectors = 1;
464
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800465 /* We are now good to announce we exist */
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800466 ret = ib_register_device(&rdi->ibdev, rdi->driver_f.port_callback);
467 if (ret) {
468 rvt_pr_err(rdi, "Failed to register driver with ib core.\n");
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800469 goto bail_cq;
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800470 }
471
Dennis Dalessandro3711baf2016-01-22 13:04:51 -0800472 rvt_create_mad_agents(rdi);
473
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800474 rvt_pr_info(rdi, "Registration with rdmavt done.\n");
475 return ret;
476
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800477bail_cq:
478 rvt_cq_exit(rdi);
479
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800480bail_mr:
481 rvt_mr_exit(rdi);
482
483bail_no_mr:
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800484 rvt_qp_exit(rdi);
485
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800486 return ret;
Dennis Dalessandro01946212016-01-06 09:50:24 -0800487}
488EXPORT_SYMBOL(rvt_register_device);
489
490void rvt_unregister_device(struct rvt_dev_info *rdi)
491{
Dennis Dalessandro81ba39a2016-01-22 13:00:28 -0800492 trace_rvt_dbg(rdi, "Driver is unregistering.");
Dennis Dalessandro01946212016-01-06 09:50:24 -0800493 if (!rdi)
494 return;
495
Dennis Dalessandro3711baf2016-01-22 13:04:51 -0800496 rvt_free_mad_agents(rdi);
497
Dennis Dalessandro01946212016-01-06 09:50:24 -0800498 ib_unregister_device(&rdi->ibdev);
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800499 rvt_cq_exit(rdi);
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800500 rvt_mr_exit(rdi);
Dennis Dalessandro515667f2016-01-22 12:50:17 -0800501 rvt_qp_exit(rdi);
Dennis Dalessandro01946212016-01-06 09:50:24 -0800502}
503EXPORT_SYMBOL(rvt_unregister_device);
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800504
505/*
506 * Keep track of a list of ports. No need to have a detach port.
507 * They persist until the driver goes away.
508 */
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800509int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800510 int port_index, u16 *pkey_table)
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800511{
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800512
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800513 rdi->ports[port_index] = port;
514 rdi->ports[port_index]->pkey_table = pkey_table;
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800515
516 return 0;
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800517}
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800518EXPORT_SYMBOL(rvt_init_port);