This source file includes following definitions.
- rvt_init
- rvt_cleanup
- rvt_alloc_device
- rvt_dealloc_device
- rvt_query_device
- rvt_modify_device
- rvt_query_port
- rvt_modify_port
- rvt_query_pkey
- rvt_query_gid
- to_iucontext
- rvt_alloc_ucontext
- rvt_dealloc_ucontext
- rvt_get_port_immutable
- check_support
- rvt_register_device
- rvt_unregister_device
- rvt_init_port
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 #include <linux/module.h>
49 #include <linux/kernel.h>
50 #include <linux/dma-mapping.h>
51 #include "vt.h"
52 #include "cq.h"
53 #include "trace.h"
54
55 #define RVT_UVERBS_ABI_VERSION 2
56
57 MODULE_LICENSE("Dual BSD/GPL");
58 MODULE_DESCRIPTION("RDMA Verbs Transport Library");
59
60 static int rvt_init(void)
61 {
62 int ret = rvt_driver_cq_init();
63
64 if (ret)
65 pr_err("Error in driver CQ init.\n");
66
67 return ret;
68 }
69 module_init(rvt_init);
70
71 static void rvt_cleanup(void)
72 {
73 rvt_cq_exit();
74 }
75 module_exit(rvt_cleanup);
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
91 {
92 struct rvt_dev_info *rdi;
93
94 rdi = container_of(_ib_alloc_device(size), struct rvt_dev_info, ibdev);
95 if (!rdi)
96 return rdi;
97
98 rdi->ports = kcalloc(nports,
99 sizeof(struct rvt_ibport **),
100 GFP_KERNEL);
101 if (!rdi->ports)
102 ib_dealloc_device(&rdi->ibdev);
103
104 return rdi;
105 }
106 EXPORT_SYMBOL(rvt_alloc_device);
107
108
109
110
111
112
113
114 void rvt_dealloc_device(struct rvt_dev_info *rdi)
115 {
116 kfree(rdi->ports);
117 ib_dealloc_device(&rdi->ibdev);
118 }
119 EXPORT_SYMBOL(rvt_dealloc_device);
120
121 static int rvt_query_device(struct ib_device *ibdev,
122 struct ib_device_attr *props,
123 struct ib_udata *uhw)
124 {
125 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
126
127 if (uhw->inlen || uhw->outlen)
128 return -EINVAL;
129
130
131
132 *props = rdi->dparms.props;
133 return 0;
134 }
135
136 static int rvt_modify_device(struct ib_device *device,
137 int device_modify_mask,
138 struct ib_device_modify *device_modify)
139 {
140
141
142
143
144
145 return -EOPNOTSUPP;
146 }
147
148
149
150
151
152
153
154
155
156 static int rvt_query_port(struct ib_device *ibdev, u8 port_num,
157 struct ib_port_attr *props)
158 {
159 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
160 struct rvt_ibport *rvp;
161 int port_index = ibport_num_to_idx(ibdev, port_num);
162
163 if (port_index < 0)
164 return -EINVAL;
165
166 rvp = rdi->ports[port_index];
167
168 props->sm_lid = rvp->sm_lid;
169 props->sm_sl = rvp->sm_sl;
170 props->port_cap_flags = rvp->port_cap_flags;
171 props->max_msg_sz = 0x80000000;
172 props->pkey_tbl_len = rvt_get_npkeys(rdi);
173 props->bad_pkey_cntr = rvp->pkey_violations;
174 props->qkey_viol_cntr = rvp->qkey_violations;
175 props->subnet_timeout = rvp->subnet_timeout;
176 props->init_type_reply = 0;
177
178
179 return rdi->driver_f.query_port_state(rdi, port_num, props);
180 }
181
182
183
184
185
186
187
188
189
190
191 static int rvt_modify_port(struct ib_device *ibdev, u8 port_num,
192 int port_modify_mask, struct ib_port_modify *props)
193 {
194 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
195 struct rvt_ibport *rvp;
196 int ret = 0;
197 int port_index = ibport_num_to_idx(ibdev, port_num);
198
199 if (port_index < 0)
200 return -EINVAL;
201
202 rvp = rdi->ports[port_index];
203 if (port_modify_mask & IB_PORT_OPA_MASK_CHG) {
204 rvp->port_cap3_flags |= props->set_port_cap_mask;
205 rvp->port_cap3_flags &= ~props->clr_port_cap_mask;
206 } else {
207 rvp->port_cap_flags |= props->set_port_cap_mask;
208 rvp->port_cap_flags &= ~props->clr_port_cap_mask;
209 }
210
211 if (props->set_port_cap_mask || props->clr_port_cap_mask)
212 rdi->driver_f.cap_mask_chg(rdi, port_num);
213 if (port_modify_mask & IB_PORT_SHUTDOWN)
214 ret = rdi->driver_f.shut_down_port(rdi, port_num);
215 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
216 rvp->qkey_violations = 0;
217
218 return ret;
219 }
220
221
222
223
224
225
226
227
228
229
230 static int rvt_query_pkey(struct ib_device *ibdev, u8 port_num, u16 index,
231 u16 *pkey)
232 {
233
234
235
236
237
238
239 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
240 int port_index;
241
242 port_index = ibport_num_to_idx(ibdev, port_num);
243 if (port_index < 0)
244 return -EINVAL;
245
246 if (index >= rvt_get_npkeys(rdi))
247 return -EINVAL;
248
249 *pkey = rvt_get_pkey(rdi, port_index, index);
250 return 0;
251 }
252
253
254
255
256
257
258
259
260
261
262 static int rvt_query_gid(struct ib_device *ibdev, u8 port_num,
263 int guid_index, union ib_gid *gid)
264 {
265 struct rvt_dev_info *rdi;
266 struct rvt_ibport *rvp;
267 int port_index;
268
269
270
271
272
273
274 port_index = ibport_num_to_idx(ibdev, port_num);
275 if (port_index < 0)
276 return -EINVAL;
277
278 rdi = ib_to_rvt(ibdev);
279 rvp = rdi->ports[port_index];
280
281 gid->global.subnet_prefix = rvp->gid_prefix;
282
283 return rdi->driver_f.get_guid_be(rdi, rvp, guid_index,
284 &gid->global.interface_id);
285 }
286
287 static inline struct rvt_ucontext *to_iucontext(struct ib_ucontext
288 *ibucontext)
289 {
290 return container_of(ibucontext, struct rvt_ucontext, ibucontext);
291 }
292
293
294
295
296
297
298 static int rvt_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata)
299 {
300 return 0;
301 }
302
303
304
305
306
307 static void rvt_dealloc_ucontext(struct ib_ucontext *context)
308 {
309 return;
310 }
311
312 static int rvt_get_port_immutable(struct ib_device *ibdev, u8 port_num,
313 struct ib_port_immutable *immutable)
314 {
315 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
316 struct ib_port_attr attr;
317 int err, port_index;
318
319 port_index = ibport_num_to_idx(ibdev, port_num);
320 if (port_index < 0)
321 return -EINVAL;
322
323 immutable->core_cap_flags = rdi->dparms.core_cap_flags;
324
325 err = ib_query_port(ibdev, port_num, &attr);
326 if (err)
327 return err;
328
329 immutable->pkey_tbl_len = attr.pkey_tbl_len;
330 immutable->gid_tbl_len = attr.gid_tbl_len;
331 immutable->max_mad_size = rdi->dparms.max_mad_size;
332
333 return 0;
334 }
335
336 enum {
337 MISC,
338 QUERY_DEVICE,
339 MODIFY_DEVICE,
340 QUERY_PORT,
341 MODIFY_PORT,
342 QUERY_PKEY,
343 QUERY_GID,
344 ALLOC_UCONTEXT,
345 DEALLOC_UCONTEXT,
346 GET_PORT_IMMUTABLE,
347 CREATE_QP,
348 MODIFY_QP,
349 DESTROY_QP,
350 QUERY_QP,
351 POST_SEND,
352 POST_RECV,
353 POST_SRQ_RECV,
354 CREATE_AH,
355 DESTROY_AH,
356 MODIFY_AH,
357 QUERY_AH,
358 CREATE_SRQ,
359 MODIFY_SRQ,
360 DESTROY_SRQ,
361 QUERY_SRQ,
362 ATTACH_MCAST,
363 DETACH_MCAST,
364 GET_DMA_MR,
365 REG_USER_MR,
366 DEREG_MR,
367 ALLOC_MR,
368 MAP_MR_SG,
369 ALLOC_FMR,
370 MAP_PHYS_FMR,
371 UNMAP_FMR,
372 DEALLOC_FMR,
373 MMAP,
374 CREATE_CQ,
375 DESTROY_CQ,
376 POLL_CQ,
377 REQ_NOTFIY_CQ,
378 RESIZE_CQ,
379 ALLOC_PD,
380 DEALLOC_PD,
381 _VERB_IDX_MAX
382 };
383
384 static const struct ib_device_ops rvt_dev_ops = {
385 .uverbs_abi_ver = RVT_UVERBS_ABI_VERSION,
386
387 .alloc_fmr = rvt_alloc_fmr,
388 .alloc_mr = rvt_alloc_mr,
389 .alloc_pd = rvt_alloc_pd,
390 .alloc_ucontext = rvt_alloc_ucontext,
391 .attach_mcast = rvt_attach_mcast,
392 .create_ah = rvt_create_ah,
393 .create_cq = rvt_create_cq,
394 .create_qp = rvt_create_qp,
395 .create_srq = rvt_create_srq,
396 .dealloc_fmr = rvt_dealloc_fmr,
397 .dealloc_pd = rvt_dealloc_pd,
398 .dealloc_ucontext = rvt_dealloc_ucontext,
399 .dereg_mr = rvt_dereg_mr,
400 .destroy_ah = rvt_destroy_ah,
401 .destroy_cq = rvt_destroy_cq,
402 .destroy_qp = rvt_destroy_qp,
403 .destroy_srq = rvt_destroy_srq,
404 .detach_mcast = rvt_detach_mcast,
405 .get_dma_mr = rvt_get_dma_mr,
406 .get_port_immutable = rvt_get_port_immutable,
407 .map_mr_sg = rvt_map_mr_sg,
408 .map_phys_fmr = rvt_map_phys_fmr,
409 .mmap = rvt_mmap,
410 .modify_ah = rvt_modify_ah,
411 .modify_device = rvt_modify_device,
412 .modify_port = rvt_modify_port,
413 .modify_qp = rvt_modify_qp,
414 .modify_srq = rvt_modify_srq,
415 .poll_cq = rvt_poll_cq,
416 .post_recv = rvt_post_recv,
417 .post_send = rvt_post_send,
418 .post_srq_recv = rvt_post_srq_recv,
419 .query_ah = rvt_query_ah,
420 .query_device = rvt_query_device,
421 .query_gid = rvt_query_gid,
422 .query_pkey = rvt_query_pkey,
423 .query_port = rvt_query_port,
424 .query_qp = rvt_query_qp,
425 .query_srq = rvt_query_srq,
426 .reg_user_mr = rvt_reg_user_mr,
427 .req_notify_cq = rvt_req_notify_cq,
428 .resize_cq = rvt_resize_cq,
429 .unmap_fmr = rvt_unmap_fmr,
430
431 INIT_RDMA_OBJ_SIZE(ib_ah, rvt_ah, ibah),
432 INIT_RDMA_OBJ_SIZE(ib_cq, rvt_cq, ibcq),
433 INIT_RDMA_OBJ_SIZE(ib_pd, rvt_pd, ibpd),
434 INIT_RDMA_OBJ_SIZE(ib_srq, rvt_srq, ibsrq),
435 INIT_RDMA_OBJ_SIZE(ib_ucontext, rvt_ucontext, ibucontext),
436 };
437
438 static noinline int check_support(struct rvt_dev_info *rdi, int verb)
439 {
440 switch (verb) {
441 case MISC:
442
443
444
445
446 if ((!rdi->ibdev.ops.init_port) ||
447 (!rdi->driver_f.get_pci_dev))
448 return -EINVAL;
449 break;
450
451 case MODIFY_DEVICE:
452
453
454
455
456 if (!rdi->ibdev.ops.modify_device)
457 return -EOPNOTSUPP;
458 break;
459
460 case QUERY_PORT:
461 if (!rdi->ibdev.ops.query_port)
462 if (!rdi->driver_f.query_port_state)
463 return -EINVAL;
464 break;
465
466 case MODIFY_PORT:
467 if (!rdi->ibdev.ops.modify_port)
468 if (!rdi->driver_f.cap_mask_chg ||
469 !rdi->driver_f.shut_down_port)
470 return -EINVAL;
471 break;
472
473 case QUERY_GID:
474 if (!rdi->ibdev.ops.query_gid)
475 if (!rdi->driver_f.get_guid_be)
476 return -EINVAL;
477 break;
478
479 case CREATE_QP:
480 if (!rdi->ibdev.ops.create_qp)
481 if (!rdi->driver_f.qp_priv_alloc ||
482 !rdi->driver_f.qp_priv_free ||
483 !rdi->driver_f.notify_qp_reset ||
484 !rdi->driver_f.flush_qp_waiters ||
485 !rdi->driver_f.stop_send_queue ||
486 !rdi->driver_f.quiesce_qp)
487 return -EINVAL;
488 break;
489
490 case MODIFY_QP:
491 if (!rdi->ibdev.ops.modify_qp)
492 if (!rdi->driver_f.notify_qp_reset ||
493 !rdi->driver_f.schedule_send ||
494 !rdi->driver_f.get_pmtu_from_attr ||
495 !rdi->driver_f.flush_qp_waiters ||
496 !rdi->driver_f.stop_send_queue ||
497 !rdi->driver_f.quiesce_qp ||
498 !rdi->driver_f.notify_error_qp ||
499 !rdi->driver_f.mtu_from_qp ||
500 !rdi->driver_f.mtu_to_path_mtu)
501 return -EINVAL;
502 break;
503
504 case DESTROY_QP:
505 if (!rdi->ibdev.ops.destroy_qp)
506 if (!rdi->driver_f.qp_priv_free ||
507 !rdi->driver_f.notify_qp_reset ||
508 !rdi->driver_f.flush_qp_waiters ||
509 !rdi->driver_f.stop_send_queue ||
510 !rdi->driver_f.quiesce_qp)
511 return -EINVAL;
512 break;
513
514 case POST_SEND:
515 if (!rdi->ibdev.ops.post_send)
516 if (!rdi->driver_f.schedule_send ||
517 !rdi->driver_f.do_send ||
518 !rdi->post_parms)
519 return -EINVAL;
520 break;
521
522 }
523
524 return 0;
525 }
526
527
528
529
530
531
532
533
534
535
536 int rvt_register_device(struct rvt_dev_info *rdi)
537 {
538 int ret = 0, i;
539
540 if (!rdi)
541 return -EINVAL;
542
543
544
545
546
547 for (i = 0; i < _VERB_IDX_MAX; i++)
548 if (check_support(rdi, i)) {
549 pr_err("Driver support req not met at %d\n", i);
550 return -EINVAL;
551 }
552
553 ib_set_device_ops(&rdi->ibdev, &rvt_dev_ops);
554
555
556 trace_rvt_dbg(rdi, "Driver attempting registration");
557 rvt_mmap_init(rdi);
558
559
560 ret = rvt_driver_qp_init(rdi);
561 if (ret) {
562 pr_err("Error in driver QP init.\n");
563 return -EINVAL;
564 }
565
566
567 spin_lock_init(&rdi->n_ahs_lock);
568 rdi->n_ahs_allocated = 0;
569
570
571 rvt_driver_srq_init(rdi);
572
573
574 rvt_driver_mcast_init(rdi);
575
576
577 ret = rvt_driver_mr_init(rdi);
578 if (ret) {
579 pr_err("Error in driver MR init.\n");
580 goto bail_no_mr;
581 }
582
583
584 ret = rvt_wss_init(rdi);
585 if (ret) {
586 rvt_pr_err(rdi, "Error in WSS init.\n");
587 goto bail_mr;
588 }
589
590
591 spin_lock_init(&rdi->n_cqs_lock);
592
593
594 rdi->ibdev.dev.dma_ops = rdi->ibdev.dev.dma_ops ? : &dma_virt_ops;
595
596
597 spin_lock_init(&rdi->n_pds_lock);
598 rdi->n_pds_allocated = 0;
599
600
601
602
603
604
605
606 rdi->ibdev.uverbs_cmd_mask =
607 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
608 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
609 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
610 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
611 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
612 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
613 (1ull << IB_USER_VERBS_CMD_MODIFY_AH) |
614 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
615 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
616 (1ull << IB_USER_VERBS_CMD_REG_MR) |
617 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
618 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
619 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
620 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
621 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
622 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
623 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
624 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
625 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
626 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
627 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
628 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
629 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
630 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
631 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
632 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
633 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
634 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
635 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
636 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
637 rdi->ibdev.node_type = RDMA_NODE_IB_CA;
638 if (!rdi->ibdev.num_comp_vectors)
639 rdi->ibdev.num_comp_vectors = 1;
640
641
642 ret = ib_register_device(&rdi->ibdev, dev_name(&rdi->ibdev.dev));
643 if (ret) {
644 rvt_pr_err(rdi, "Failed to register driver with ib core.\n");
645 goto bail_wss;
646 }
647
648 rvt_create_mad_agents(rdi);
649
650 rvt_pr_info(rdi, "Registration with rdmavt done.\n");
651 return ret;
652
653 bail_wss:
654 rvt_wss_exit(rdi);
655 bail_mr:
656 rvt_mr_exit(rdi);
657
658 bail_no_mr:
659 rvt_qp_exit(rdi);
660
661 return ret;
662 }
663 EXPORT_SYMBOL(rvt_register_device);
664
665
666
667
668
669 void rvt_unregister_device(struct rvt_dev_info *rdi)
670 {
671 trace_rvt_dbg(rdi, "Driver is unregistering.");
672 if (!rdi)
673 return;
674
675 rvt_free_mad_agents(rdi);
676
677 ib_unregister_device(&rdi->ibdev);
678 rvt_wss_exit(rdi);
679 rvt_mr_exit(rdi);
680 rvt_qp_exit(rdi);
681 }
682 EXPORT_SYMBOL(rvt_unregister_device);
683
684
685
686
687
688
689
690
691
692
693
694
695 int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
696 int port_index, u16 *pkey_table)
697 {
698
699 rdi->ports[port_index] = port;
700 rdi->ports[port_index]->pkey_table = pkey_table;
701
702 return 0;
703 }
704 EXPORT_SYMBOL(rvt_init_port);