blob: f5cb09b718bef38192083666602b4f42d37d4c88 [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{
Dennis Dalessandro90793f72016-02-14 12:10:29 -080060 /*
61 * rdmavt does not need to do anything special when it starts up. All it
62 * needs to do is sit and wait until a driver attempts registration.
63 */
Dennis Dalessandro01946212016-01-06 09:50:24 -080064 return 0;
65}
66module_init(rvt_init);
67
68static void rvt_cleanup(void)
69{
Dennis Dalessandro90793f72016-02-14 12:10:29 -080070 /*
71 * Nothing to do at exit time either. The module won't be able to be
72 * removed until all drivers are gone which means all the dev structs
73 * are gone so there is really nothing to do.
74 */
Dennis Dalessandro01946212016-01-06 09:50:24 -080075}
76module_exit(rvt_cleanup);
77
Dennis Dalessandro90793f72016-02-14 12:10:29 -080078/**
79 * rvt_alloc_device - allocate rdi
80 * @size: how big of a structure to allocate
81 * @nports: number of ports to allocate array slots for
82 *
83 * Use IB core device alloc to allocate space for the rdi which is assumed to be
84 * inside of the ib_device. Any extra space that drivers require should be
85 * included in size.
86 *
87 * We also allocate a port array based on the number of ports.
88 *
89 * Return: pointer to allocated rdi
90 */
Dennis Dalessandroff6acd62016-01-22 13:04:45 -080091struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
92{
93 struct rvt_dev_info *rdi = ERR_PTR(-ENOMEM);
94
95 rdi = (struct rvt_dev_info *)ib_alloc_device(size);
96 if (!rdi)
97 return rdi;
98
99 rdi->ports = kcalloc(nports,
100 sizeof(struct rvt_ibport **),
101 GFP_KERNEL);
102 if (!rdi->ports)
103 ib_dealloc_device(&rdi->ibdev);
104
105 return rdi;
106}
107EXPORT_SYMBOL(rvt_alloc_device);
108
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800109static int rvt_query_device(struct ib_device *ibdev,
110 struct ib_device_attr *props,
111 struct ib_udata *uhw)
112{
Harish Chegondifeaeb6e2016-01-22 12:50:36 -0800113 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
114
115 if (uhw->inlen || uhw->outlen)
116 return -EINVAL;
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800117 /*
Harish Chegondifeaeb6e2016-01-22 12:50:36 -0800118 * Return rvt_dev_info.dparms.props contents
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800119 */
Harish Chegondifeaeb6e2016-01-22 12:50:36 -0800120 *props = rdi->dparms.props;
121 return 0;
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800122}
123
124static int rvt_modify_device(struct ib_device *device,
125 int device_modify_mask,
126 struct ib_device_modify *device_modify)
127{
128 /*
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800129 * There is currently no need to supply this based on qib and hfi1.
130 * Future drivers may need to implement this though.
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800131 */
132
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800133 return -EOPNOTSUPP;
134}
135
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800136/**
137 * rvt_query_port: Passes the query port call to the driver
138 * @ibdev: Verbs IB dev
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800139 * @port_num: port number, 1 based from ib core
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800140 * @props: structure to hold returned properties
141 *
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800142 * Return: 0 on success
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800143 */
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800144static int rvt_query_port(struct ib_device *ibdev, u8 port_num,
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800145 struct ib_port_attr *props)
146{
Harish Chegondi61a650c2016-02-03 14:15:20 -0800147 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
148 struct rvt_ibport *rvp;
149 int port_index = ibport_num_to_idx(ibdev, port_num);
150
151 if (port_index < 0)
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800152 return -EINVAL;
153
Harish Chegondi61a650c2016-02-03 14:15:20 -0800154 rvp = rdi->ports[port_index];
155 memset(props, 0, sizeof(*props));
156 props->sm_lid = rvp->sm_lid;
157 props->sm_sl = rvp->sm_sl;
158 props->port_cap_flags = rvp->port_cap_flags;
159 props->max_msg_sz = 0x80000000;
160 props->pkey_tbl_len = rvt_get_npkeys(rdi);
161 props->bad_pkey_cntr = rvp->pkey_violations;
162 props->qkey_viol_cntr = rvp->qkey_violations;
163 props->subnet_timeout = rvp->subnet_timeout;
164 props->init_type_reply = 0;
165
166 /* Populate the remaining ib_port_attr elements */
167 return rdi->driver_f.query_port_state(rdi, port_num, props);
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800168}
169
170/**
171 * rvt_modify_port
172 * @ibdev: Verbs IB dev
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800173 * @port_num: Port number, 1 based from ib core
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800174 * @port_modify_mask: How to change the port
175 * @props: Structure to fill in
176 *
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800177 * Return: 0 on success
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800178 */
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800179static int rvt_modify_port(struct ib_device *ibdev, u8 port_num,
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800180 int port_modify_mask, struct ib_port_modify *props)
181{
Harish Chegondi61a650c2016-02-03 14:15:20 -0800182 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
183 struct rvt_ibport *rvp;
184 int ret = 0;
185 int port_index = ibport_num_to_idx(ibdev, port_num);
186
187 if (port_index < 0)
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800188 return -EINVAL;
189
Harish Chegondi61a650c2016-02-03 14:15:20 -0800190 rvp = rdi->ports[port_index];
191 rvp->port_cap_flags |= props->set_port_cap_mask;
192 rvp->port_cap_flags &= ~props->clr_port_cap_mask;
193
194 if (props->set_port_cap_mask || props->clr_port_cap_mask)
195 rdi->driver_f.cap_mask_chg(rdi, port_num);
196 if (port_modify_mask & IB_PORT_SHUTDOWN)
197 ret = rdi->driver_f.shut_down_port(rdi, port_num);
198 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
199 rvp->qkey_violations = 0;
200
201 return ret;
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800202}
203
Dennis Dalessandro30588642016-01-06 09:54:16 -0800204/**
205 * rvt_query_pkey - Return a pkey from the table at a given index
206 * @ibdev: Verbs IB dev
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800207 * @port_num: Port number, 1 based from ib core
Dennis Dalessandro30588642016-01-06 09:54:16 -0800208 * @intex: Index into pkey table
209 *
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800210 * Return: 0 on failure pkey otherwise
Dennis Dalessandro30588642016-01-06 09:54:16 -0800211 */
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800212static int rvt_query_pkey(struct ib_device *ibdev, u8 port_num, u16 index,
Dennis Dalessandro30588642016-01-06 09:54:16 -0800213 u16 *pkey)
214{
215 /*
216 * Driver will be responsible for keeping rvt_dev_info.pkey_table up to
217 * date. This function will just return that value. There is no need to
218 * lock, if a stale value is read and sent to the user so be it there is
219 * no way to protect against that anyway.
220 */
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800221 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
222 int port_index;
223
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800224 port_index = ibport_num_to_idx(ibdev, port_num);
225 if (port_index < 0)
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800226 return -EINVAL;
227
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800228 if (index >= rvt_get_npkeys(rdi))
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800229 return -EINVAL;
230
231 *pkey = rvt_get_pkey(rdi, port_index, index);
Dennis Dalessandro30588642016-01-06 09:54:16 -0800232 return 0;
233}
234
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800235/**
236 * rvt_query_gid - Return a gid from the table
237 * @ibdev: Verbs IB dev
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800238 * @port_num: Port number, 1 based from ib core
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800239 * @index: = Index in table
240 * @gid: Gid to return
241 *
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800242 * Return: 0 on success
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800243 */
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800244static int rvt_query_gid(struct ib_device *ibdev, u8 port_num,
Dennis Dalessandro1f024992016-02-03 14:15:11 -0800245 int guid_index, union ib_gid *gid)
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800246{
Dennis Dalessandro1f024992016-02-03 14:15:11 -0800247 struct rvt_dev_info *rdi;
248 struct rvt_ibport *rvp;
249 int port_index;
250
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800251 /*
252 * Driver is responsible for updating the guid table. Which will be used
253 * to craft the return value. This will work similar to how query_pkey()
254 * is being done.
255 */
Dennis Dalessandro1f024992016-02-03 14:15:11 -0800256 port_index = ibport_num_to_idx(ibdev, port_num);
257 if (port_index < 0)
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800258 return -EINVAL;
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800259
Dennis Dalessandro1f024992016-02-03 14:15:11 -0800260 rdi = ib_to_rvt(ibdev);
261 rvp = rdi->ports[port_index];
262
263 gid->global.subnet_prefix = rvp->gid_prefix;
264
265 return rdi->driver_f.get_guid_be(rdi, rvp, guid_index,
266 &gid->global.interface_id);
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800267}
268
Harish Chegondi6c43cf42016-01-22 12:50:05 -0800269struct rvt_ucontext {
270 struct ib_ucontext ibucontext;
271};
272
273static inline struct rvt_ucontext *to_iucontext(struct ib_ucontext
274 *ibucontext)
275{
276 return container_of(ibucontext, struct rvt_ucontext, ibucontext);
277}
278
Dennis Dalessandroc4ed7d82016-01-06 09:55:39 -0800279/**
280 * rvt_alloc_ucontext - Allocate a user context
281 * @ibdev: Vers IB dev
282 * @data: User data allocated
283 */
284static struct ib_ucontext *rvt_alloc_ucontext(struct ib_device *ibdev,
285 struct ib_udata *udata)
286{
Harish Chegondi6c43cf42016-01-22 12:50:05 -0800287 struct rvt_ucontext *context;
288
289 context = kmalloc(sizeof(*context), GFP_KERNEL);
290 if (!context)
291 return ERR_PTR(-ENOMEM);
292 return &context->ibucontext;
Dennis Dalessandroc4ed7d82016-01-06 09:55:39 -0800293}
294
295/**
296 *rvt_dealloc_ucontext - Free a user context
297 *@context - Free this
298 */
299static int rvt_dealloc_ucontext(struct ib_ucontext *context)
300{
Harish Chegondi6c43cf42016-01-22 12:50:05 -0800301 kfree(to_iucontext(context));
302 return 0;
Dennis Dalessandroc4ed7d82016-01-06 09:55:39 -0800303}
304
Dennis Dalessandroe6a88182016-01-06 09:59:38 -0800305static int rvt_get_port_immutable(struct ib_device *ibdev, u8 port_num,
306 struct ib_port_immutable *immutable)
307{
Harish Chegondi61a650c2016-02-03 14:15:20 -0800308 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
309 struct ib_port_attr attr;
310 int err, port_index;
311
312 port_index = ibport_num_to_idx(ibdev, port_num);
313 if (port_index < 0)
314 return -EINVAL;
315
316 err = rvt_query_port(ibdev, port_num, &attr);
317 if (err)
318 return err;
319
320 immutable->pkey_tbl_len = attr.pkey_tbl_len;
321 immutable->gid_tbl_len = attr.gid_tbl_len;
322 immutable->core_cap_flags = rdi->dparms.core_cap_flags;
323 immutable->max_mad_size = rdi->dparms.max_mad_size;
324
325 return 0;
Dennis Dalessandroe6a88182016-01-06 09:59:38 -0800326}
327
Dennis Dalessandro49978702016-01-06 09:52:40 -0800328/*
329 * Check driver override. If driver passes a value use it, otherwise we use our
330 * own value.
331 */
332#define CHECK_DRIVER_OVERRIDE(rdi, x) \
333 rdi->ibdev.x = rdi->ibdev.x ? : rvt_ ##x
334
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800335/**
336 * rvt_register_device - register a driver
337 * @rdi: main dev structure for all of rdmavt operations
338 *
339 * It is up to drivers to allocate the rdi and fill in the appropriate
340 * information.
341 *
342 * Return: 0 on success otherwise an errno.
343 */
Dennis Dalessandro01946212016-01-06 09:50:24 -0800344int rvt_register_device(struct rvt_dev_info *rdi)
345{
Dennis Dalessandrob5348752016-01-06 10:02:59 -0800346 /* Validate that drivers have provided the right information */
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800347 int ret = 0;
348
Dennis Dalessandro01946212016-01-06 09:50:24 -0800349 if (!rdi)
350 return -EINVAL;
351
Dennis Dalessandrob5348752016-01-06 10:02:59 -0800352 if ((!rdi->driver_f.port_callback) ||
353 (!rdi->driver_f.get_card_name) ||
Kamal Heib119a8e72016-01-06 10:03:59 -0800354 (!rdi->driver_f.get_pci_dev) ||
355 (!rdi->driver_f.check_ah)) {
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800356 pr_err("Driver not supporting req func\n");
Dennis Dalessandrob5348752016-01-06 10:02:59 -0800357 return -EINVAL;
358 }
359
Dennis Dalessandro81ba39a2016-01-22 13:00:28 -0800360 /* Once we get past here we can use rvt_pr macros and tracepoints */
361 trace_rvt_dbg(rdi, "Driver attempting registration");
Dennis Dalessandro822514d2016-01-06 10:04:57 -0800362 rvt_mmap_init(rdi);
Dennis Dalessandrob5348752016-01-06 10:02:59 -0800363
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800364 /* Dev Ops */
365 CHECK_DRIVER_OVERRIDE(rdi, query_device);
366 CHECK_DRIVER_OVERRIDE(rdi, modify_device);
Dennis Dalessandro765525c2016-01-06 09:54:07 -0800367 CHECK_DRIVER_OVERRIDE(rdi, query_port);
368 CHECK_DRIVER_OVERRIDE(rdi, modify_port);
Dennis Dalessandro30588642016-01-06 09:54:16 -0800369 CHECK_DRIVER_OVERRIDE(rdi, query_pkey);
Dennis Dalessandro2d092e12016-01-06 09:54:50 -0800370 CHECK_DRIVER_OVERRIDE(rdi, query_gid);
Dennis Dalessandroc4ed7d82016-01-06 09:55:39 -0800371 CHECK_DRIVER_OVERRIDE(rdi, alloc_ucontext);
372 CHECK_DRIVER_OVERRIDE(rdi, dealloc_ucontext);
Dennis Dalessandroe6a88182016-01-06 09:59:38 -0800373 CHECK_DRIVER_OVERRIDE(rdi, get_port_immutable);
Dennis Dalessandro19ef1ed2016-01-06 09:53:05 -0800374
Dennis Dalessandrob518d3e2016-01-06 09:56:15 -0800375 /* Queue Pairs */
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800376 ret = rvt_driver_qp_init(rdi);
377 if (ret) {
378 pr_err("Error in driver QP init.\n");
379 return -EINVAL;
380 }
381
Dennis Dalessandrob518d3e2016-01-06 09:56:15 -0800382 CHECK_DRIVER_OVERRIDE(rdi, create_qp);
383 CHECK_DRIVER_OVERRIDE(rdi, modify_qp);
384 CHECK_DRIVER_OVERRIDE(rdi, destroy_qp);
385 CHECK_DRIVER_OVERRIDE(rdi, query_qp);
Dennis Dalessandro8cf40202016-01-06 10:01:17 -0800386 CHECK_DRIVER_OVERRIDE(rdi, post_send);
387 CHECK_DRIVER_OVERRIDE(rdi, post_recv);
388 CHECK_DRIVER_OVERRIDE(rdi, post_srq_recv);
Dennis Dalessandrob518d3e2016-01-06 09:56:15 -0800389
Dennis Dalessandro4c1e4972016-01-06 09:56:41 -0800390 /* Address Handle */
391 CHECK_DRIVER_OVERRIDE(rdi, create_ah);
392 CHECK_DRIVER_OVERRIDE(rdi, destroy_ah);
393 CHECK_DRIVER_OVERRIDE(rdi, modify_ah);
394 CHECK_DRIVER_OVERRIDE(rdi, query_ah);
Kamal Heib119a8e72016-01-06 10:03:59 -0800395 spin_lock_init(&rdi->n_ahs_lock);
396 rdi->n_ahs_allocated = 0;
Dennis Dalessandro4c1e4972016-01-06 09:56:41 -0800397
Dennis Dalessandroaad91582016-01-06 09:57:58 -0800398 /* Shared Receive Queue */
399 CHECK_DRIVER_OVERRIDE(rdi, create_srq);
400 CHECK_DRIVER_OVERRIDE(rdi, modify_srq);
401 CHECK_DRIVER_OVERRIDE(rdi, destroy_srq);
402 CHECK_DRIVER_OVERRIDE(rdi, query_srq);
Jubin Johnb8f881b2016-02-03 14:14:36 -0800403 rvt_driver_srq_init(rdi);
Dennis Dalessandroaad91582016-01-06 09:57:58 -0800404
Dennis Dalessandro9fa25172016-01-06 09:58:23 -0800405 /* Multicast */
Dennis Dalessandro4e740802016-01-22 13:00:55 -0800406 rvt_driver_mcast_init(rdi);
Dennis Dalessandro9fa25172016-01-06 09:58:23 -0800407 CHECK_DRIVER_OVERRIDE(rdi, attach_mcast);
408 CHECK_DRIVER_OVERRIDE(rdi, detach_mcast);
409
Dennis Dalessandro2a055eb2016-01-06 09:57:21 -0800410 /* Mem Region */
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800411 ret = rvt_driver_mr_init(rdi);
412 if (ret) {
Dennis Dalessandro36055a02016-01-06 10:03:39 -0800413 pr_err("Error in driver MR init.\n");
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800414 goto bail_no_mr;
415 }
416
Dennis Dalessandro2a055eb2016-01-06 09:57:21 -0800417 CHECK_DRIVER_OVERRIDE(rdi, get_dma_mr);
418 CHECK_DRIVER_OVERRIDE(rdi, reg_user_mr);
419 CHECK_DRIVER_OVERRIDE(rdi, dereg_mr);
420 CHECK_DRIVER_OVERRIDE(rdi, alloc_mr);
421 CHECK_DRIVER_OVERRIDE(rdi, alloc_fmr);
422 CHECK_DRIVER_OVERRIDE(rdi, map_phys_fmr);
423 CHECK_DRIVER_OVERRIDE(rdi, unmap_fmr);
424 CHECK_DRIVER_OVERRIDE(rdi, dealloc_fmr);
Dennis Dalessandrodc217522016-01-06 09:59:04 -0800425 CHECK_DRIVER_OVERRIDE(rdi, mmap);
Dennis Dalessandro2a055eb2016-01-06 09:57:21 -0800426
Dennis Dalessandrocf163352016-01-06 10:00:42 -0800427 /* Completion queues */
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800428 ret = rvt_driver_cq_init(rdi);
429 if (ret) {
430 pr_err("Error in driver CQ init.\n");
431 goto bail_mr;
432 }
Dennis Dalessandrocf163352016-01-06 10:00:42 -0800433 CHECK_DRIVER_OVERRIDE(rdi, create_cq);
434 CHECK_DRIVER_OVERRIDE(rdi, destroy_cq);
435 CHECK_DRIVER_OVERRIDE(rdi, poll_cq);
436 CHECK_DRIVER_OVERRIDE(rdi, req_notify_cq);
437 CHECK_DRIVER_OVERRIDE(rdi, resize_cq);
438
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800439 /* DMA Operations */
Dennis Dalessandroc1b332b2016-01-06 09:51:18 -0800440 rdi->ibdev.dma_ops =
441 rdi->ibdev.dma_ops ? : &rvt_default_dma_mapping_ops;
442
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800443 /* Protection Domain */
Dennis Dalessandro49978702016-01-06 09:52:40 -0800444 CHECK_DRIVER_OVERRIDE(rdi, alloc_pd);
445 CHECK_DRIVER_OVERRIDE(rdi, dealloc_pd);
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800446 spin_lock_init(&rdi->n_pds_lock);
447 rdi->n_pds_allocated = 0;
448
Dennis Dalessandro182285d2016-01-22 13:01:01 -0800449 /*
450 * There are some things which could be set by underlying drivers but
451 * really should be up to rdmavt to set. For instance drivers can't know
452 * exactly which functions rdmavt supports, nor do they know the ABI
453 * version, so we do all of this sort of stuff here.
454 */
455 rdi->ibdev.uverbs_abi_ver = RVT_UVERBS_ABI_VERSION;
456 rdi->ibdev.uverbs_cmd_mask =
457 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
458 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
459 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
460 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
461 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
462 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
463 (1ull << IB_USER_VERBS_CMD_MODIFY_AH) |
464 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
465 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
466 (1ull << IB_USER_VERBS_CMD_REG_MR) |
467 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
468 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
469 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
470 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
471 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
472 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
473 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
474 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
475 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
476 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
477 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
478 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
479 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
480 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
481 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
482 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
483 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
484 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
485 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
486 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
487 rdi->ibdev.node_type = RDMA_NODE_IB_CA;
488 rdi->ibdev.num_comp_vectors = 1;
489
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800490 /* We are now good to announce we exist */
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800491 ret = ib_register_device(&rdi->ibdev, rdi->driver_f.port_callback);
492 if (ret) {
493 rvt_pr_err(rdi, "Failed to register driver with ib core.\n");
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800494 goto bail_cq;
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800495 }
496
Dennis Dalessandro3711baf2016-01-22 13:04:51 -0800497 rvt_create_mad_agents(rdi);
498
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800499 rvt_pr_info(rdi, "Registration with rdmavt done.\n");
500 return ret;
501
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800502bail_cq:
503 rvt_cq_exit(rdi);
504
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800505bail_mr:
506 rvt_mr_exit(rdi);
507
508bail_no_mr:
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800509 rvt_qp_exit(rdi);
510
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800511 return ret;
Dennis Dalessandro01946212016-01-06 09:50:24 -0800512}
513EXPORT_SYMBOL(rvt_register_device);
514
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800515/**
516 * rvt_unregister_device - remove a driver
517 * @rdi: rvt dev struct
518 */
Dennis Dalessandro01946212016-01-06 09:50:24 -0800519void rvt_unregister_device(struct rvt_dev_info *rdi)
520{
Dennis Dalessandro81ba39a2016-01-22 13:00:28 -0800521 trace_rvt_dbg(rdi, "Driver is unregistering.");
Dennis Dalessandro01946212016-01-06 09:50:24 -0800522 if (!rdi)
523 return;
524
Dennis Dalessandro3711baf2016-01-22 13:04:51 -0800525 rvt_free_mad_agents(rdi);
526
Dennis Dalessandro01946212016-01-06 09:50:24 -0800527 ib_unregister_device(&rdi->ibdev);
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800528 rvt_cq_exit(rdi);
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800529 rvt_mr_exit(rdi);
Dennis Dalessandro515667f2016-01-22 12:50:17 -0800530 rvt_qp_exit(rdi);
Dennis Dalessandro01946212016-01-06 09:50:24 -0800531}
532EXPORT_SYMBOL(rvt_unregister_device);
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800533
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800534/**
535 * rvt_init_port - init internal data for driver port
536 * @rdi: rvt dev strut
537 * @port: rvt port
538 * @port_index: 0 based index of ports, different from IB core port num
539 *
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800540 * Keep track of a list of ports. No need to have a detach port.
541 * They persist until the driver goes away.
Dennis Dalessandro90793f72016-02-14 12:10:29 -0800542 *
543 * Return: always 0
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800544 */
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800545int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800546 int port_index, u16 *pkey_table)
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800547{
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800548
Dennis Dalessandrof1badc72016-02-03 14:15:02 -0800549 rdi->ports[port_index] = port;
550 rdi->ports[port_index]->pkey_table = pkey_table;
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800551
552 return 0;
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800553}
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800554EXPORT_SYMBOL(rvt_init_port);