forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/infiniband/sw/rdmavt/vt.c
....@@ -91,7 +91,7 @@
9191 {
9292 struct rvt_dev_info *rdi;
9393
94
- rdi = (struct rvt_dev_info *)ib_alloc_device(size);
94
+ rdi = container_of(_ib_alloc_device(size), struct rvt_dev_info, ibdev);
9595 if (!rdi)
9696 return rdi;
9797
....@@ -282,40 +282,23 @@
282282 &gid->global.interface_id);
283283 }
284284
285
-struct rvt_ucontext {
286
- struct ib_ucontext ibucontext;
287
-};
288
-
289
-static inline struct rvt_ucontext *to_iucontext(struct ib_ucontext
290
- *ibucontext)
291
-{
292
- return container_of(ibucontext, struct rvt_ucontext, ibucontext);
293
-}
294
-
295285 /**
296286 * rvt_alloc_ucontext - Allocate a user context
297
- * @ibdev: Verbs IB dev
287
+ * @uctx: Verbs context
298288 * @udata: User data allocated
299289 */
300
-static struct ib_ucontext *rvt_alloc_ucontext(struct ib_device *ibdev,
301
- struct ib_udata *udata)
290
+static int rvt_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata)
302291 {
303
- struct rvt_ucontext *context;
304
-
305
- context = kmalloc(sizeof(*context), GFP_KERNEL);
306
- if (!context)
307
- return ERR_PTR(-ENOMEM);
308
- return &context->ibucontext;
292
+ return 0;
309293 }
310294
311295 /**
312
- *rvt_dealloc_ucontext - Free a user context
313
- *@context - Free this
296
+ * rvt_dealloc_ucontext - Free a user context
297
+ * @context - Free this
314298 */
315
-static int rvt_dealloc_ucontext(struct ib_ucontext *context)
299
+static void rvt_dealloc_ucontext(struct ib_ucontext *context)
316300 {
317
- kfree(to_iucontext(context));
318
- return 0;
301
+ return;
319302 }
320303
321304 static int rvt_get_port_immutable(struct ib_device *ibdev, u8 port_num,
....@@ -390,16 +373,55 @@
390373 _VERB_IDX_MAX /* Must always be last! */
391374 };
392375
393
-static inline int check_driver_override(struct rvt_dev_info *rdi,
394
- size_t offset, void *func)
395
-{
396
- if (!*(void **)((void *)&rdi->ibdev + offset)) {
397
- *(void **)((void *)&rdi->ibdev + offset) = func;
398
- return 0;
399
- }
376
+static const struct ib_device_ops rvt_dev_ops = {
377
+ .uverbs_abi_ver = RVT_UVERBS_ABI_VERSION,
400378
401
- return 1;
402
-}
379
+ .alloc_mr = rvt_alloc_mr,
380
+ .alloc_pd = rvt_alloc_pd,
381
+ .alloc_ucontext = rvt_alloc_ucontext,
382
+ .attach_mcast = rvt_attach_mcast,
383
+ .create_ah = rvt_create_ah,
384
+ .create_cq = rvt_create_cq,
385
+ .create_qp = rvt_create_qp,
386
+ .create_srq = rvt_create_srq,
387
+ .dealloc_pd = rvt_dealloc_pd,
388
+ .dealloc_ucontext = rvt_dealloc_ucontext,
389
+ .dereg_mr = rvt_dereg_mr,
390
+ .destroy_ah = rvt_destroy_ah,
391
+ .destroy_cq = rvt_destroy_cq,
392
+ .destroy_qp = rvt_destroy_qp,
393
+ .destroy_srq = rvt_destroy_srq,
394
+ .detach_mcast = rvt_detach_mcast,
395
+ .get_dma_mr = rvt_get_dma_mr,
396
+ .get_port_immutable = rvt_get_port_immutable,
397
+ .map_mr_sg = rvt_map_mr_sg,
398
+ .mmap = rvt_mmap,
399
+ .modify_ah = rvt_modify_ah,
400
+ .modify_device = rvt_modify_device,
401
+ .modify_port = rvt_modify_port,
402
+ .modify_qp = rvt_modify_qp,
403
+ .modify_srq = rvt_modify_srq,
404
+ .poll_cq = rvt_poll_cq,
405
+ .post_recv = rvt_post_recv,
406
+ .post_send = rvt_post_send,
407
+ .post_srq_recv = rvt_post_srq_recv,
408
+ .query_ah = rvt_query_ah,
409
+ .query_device = rvt_query_device,
410
+ .query_gid = rvt_query_gid,
411
+ .query_pkey = rvt_query_pkey,
412
+ .query_port = rvt_query_port,
413
+ .query_qp = rvt_query_qp,
414
+ .query_srq = rvt_query_srq,
415
+ .reg_user_mr = rvt_reg_user_mr,
416
+ .req_notify_cq = rvt_req_notify_cq,
417
+ .resize_cq = rvt_resize_cq,
418
+
419
+ INIT_RDMA_OBJ_SIZE(ib_ah, rvt_ah, ibah),
420
+ INIT_RDMA_OBJ_SIZE(ib_cq, rvt_cq, ibcq),
421
+ INIT_RDMA_OBJ_SIZE(ib_pd, rvt_pd, ibpd),
422
+ INIT_RDMA_OBJ_SIZE(ib_srq, rvt_srq, ibsrq),
423
+ INIT_RDMA_OBJ_SIZE(ib_ucontext, rvt_ucontext, ibucontext),
424
+};
403425
404426 static noinline int check_support(struct rvt_dev_info *rdi, int verb)
405427 {
....@@ -409,15 +431,9 @@
409431 * These functions are not part of verbs specifically but are
410432 * required for rdmavt to function.
411433 */
412
- if ((!rdi->driver_f.port_callback) ||
434
+ if ((!rdi->ibdev.ops.init_port) ||
413435 (!rdi->driver_f.get_pci_dev))
414436 return -EINVAL;
415
- break;
416
-
417
- case QUERY_DEVICE:
418
- check_driver_override(rdi, offsetof(struct ib_device,
419
- query_device),
420
- rvt_query_device);
421437 break;
422438
423439 case MODIFY_DEVICE:
....@@ -425,65 +441,31 @@
425441 * rdmavt does not support modify device currently drivers must
426442 * provide.
427443 */
428
- if (!check_driver_override(rdi, offsetof(struct ib_device,
429
- modify_device),
430
- rvt_modify_device))
444
+ if (!rdi->ibdev.ops.modify_device)
431445 return -EOPNOTSUPP;
432446 break;
433447
434448 case QUERY_PORT:
435
- if (!check_driver_override(rdi, offsetof(struct ib_device,
436
- query_port),
437
- rvt_query_port))
449
+ if (!rdi->ibdev.ops.query_port)
438450 if (!rdi->driver_f.query_port_state)
439451 return -EINVAL;
440452 break;
441453
442454 case MODIFY_PORT:
443
- if (!check_driver_override(rdi, offsetof(struct ib_device,
444
- modify_port),
445
- rvt_modify_port))
455
+ if (!rdi->ibdev.ops.modify_port)
446456 if (!rdi->driver_f.cap_mask_chg ||
447457 !rdi->driver_f.shut_down_port)
448458 return -EINVAL;
449459 break;
450460
451
- case QUERY_PKEY:
452
- check_driver_override(rdi, offsetof(struct ib_device,
453
- query_pkey),
454
- rvt_query_pkey);
455
- break;
456
-
457461 case QUERY_GID:
458
- if (!check_driver_override(rdi, offsetof(struct ib_device,
459
- query_gid),
460
- rvt_query_gid))
462
+ if (!rdi->ibdev.ops.query_gid)
461463 if (!rdi->driver_f.get_guid_be)
462464 return -EINVAL;
463465 break;
464466
465
- case ALLOC_UCONTEXT:
466
- check_driver_override(rdi, offsetof(struct ib_device,
467
- alloc_ucontext),
468
- rvt_alloc_ucontext);
469
- break;
470
-
471
- case DEALLOC_UCONTEXT:
472
- check_driver_override(rdi, offsetof(struct ib_device,
473
- dealloc_ucontext),
474
- rvt_dealloc_ucontext);
475
- break;
476
-
477
- case GET_PORT_IMMUTABLE:
478
- check_driver_override(rdi, offsetof(struct ib_device,
479
- get_port_immutable),
480
- rvt_get_port_immutable);
481
- break;
482
-
483467 case CREATE_QP:
484
- if (!check_driver_override(rdi, offsetof(struct ib_device,
485
- create_qp),
486
- rvt_create_qp))
468
+ if (!rdi->ibdev.ops.create_qp)
487469 if (!rdi->driver_f.qp_priv_alloc ||
488470 !rdi->driver_f.qp_priv_free ||
489471 !rdi->driver_f.notify_qp_reset ||
....@@ -494,9 +476,7 @@
494476 break;
495477
496478 case MODIFY_QP:
497
- if (!check_driver_override(rdi, offsetof(struct ib_device,
498
- modify_qp),
499
- rvt_modify_qp))
479
+ if (!rdi->ibdev.ops.modify_qp)
500480 if (!rdi->driver_f.notify_qp_reset ||
501481 !rdi->driver_f.schedule_send ||
502482 !rdi->driver_f.get_pmtu_from_attr ||
....@@ -510,9 +490,7 @@
510490 break;
511491
512492 case DESTROY_QP:
513
- if (!check_driver_override(rdi, offsetof(struct ib_device,
514
- destroy_qp),
515
- rvt_destroy_qp))
493
+ if (!rdi->ibdev.ops.destroy_qp)
516494 if (!rdi->driver_f.qp_priv_free ||
517495 !rdi->driver_f.notify_qp_reset ||
518496 !rdi->driver_f.flush_qp_waiters ||
....@@ -521,197 +499,14 @@
521499 return -EINVAL;
522500 break;
523501
524
- case QUERY_QP:
525
- check_driver_override(rdi, offsetof(struct ib_device,
526
- query_qp),
527
- rvt_query_qp);
528
- break;
529
-
530502 case POST_SEND:
531
- if (!check_driver_override(rdi, offsetof(struct ib_device,
532
- post_send),
533
- rvt_post_send))
503
+ if (!rdi->ibdev.ops.post_send)
534504 if (!rdi->driver_f.schedule_send ||
535505 !rdi->driver_f.do_send ||
536506 !rdi->post_parms)
537507 return -EINVAL;
538508 break;
539509
540
- case POST_RECV:
541
- check_driver_override(rdi, offsetof(struct ib_device,
542
- post_recv),
543
- rvt_post_recv);
544
- break;
545
- case POST_SRQ_RECV:
546
- check_driver_override(rdi, offsetof(struct ib_device,
547
- post_srq_recv),
548
- rvt_post_srq_recv);
549
- break;
550
-
551
- case CREATE_AH:
552
- check_driver_override(rdi, offsetof(struct ib_device,
553
- create_ah),
554
- rvt_create_ah);
555
- break;
556
-
557
- case DESTROY_AH:
558
- check_driver_override(rdi, offsetof(struct ib_device,
559
- destroy_ah),
560
- rvt_destroy_ah);
561
- break;
562
-
563
- case MODIFY_AH:
564
- check_driver_override(rdi, offsetof(struct ib_device,
565
- modify_ah),
566
- rvt_modify_ah);
567
- break;
568
-
569
- case QUERY_AH:
570
- check_driver_override(rdi, offsetof(struct ib_device,
571
- query_ah),
572
- rvt_query_ah);
573
- break;
574
-
575
- case CREATE_SRQ:
576
- check_driver_override(rdi, offsetof(struct ib_device,
577
- create_srq),
578
- rvt_create_srq);
579
- break;
580
-
581
- case MODIFY_SRQ:
582
- check_driver_override(rdi, offsetof(struct ib_device,
583
- modify_srq),
584
- rvt_modify_srq);
585
- break;
586
-
587
- case DESTROY_SRQ:
588
- check_driver_override(rdi, offsetof(struct ib_device,
589
- destroy_srq),
590
- rvt_destroy_srq);
591
- break;
592
-
593
- case QUERY_SRQ:
594
- check_driver_override(rdi, offsetof(struct ib_device,
595
- query_srq),
596
- rvt_query_srq);
597
- break;
598
-
599
- case ATTACH_MCAST:
600
- check_driver_override(rdi, offsetof(struct ib_device,
601
- attach_mcast),
602
- rvt_attach_mcast);
603
- break;
604
-
605
- case DETACH_MCAST:
606
- check_driver_override(rdi, offsetof(struct ib_device,
607
- detach_mcast),
608
- rvt_detach_mcast);
609
- break;
610
-
611
- case GET_DMA_MR:
612
- check_driver_override(rdi, offsetof(struct ib_device,
613
- get_dma_mr),
614
- rvt_get_dma_mr);
615
- break;
616
-
617
- case REG_USER_MR:
618
- check_driver_override(rdi, offsetof(struct ib_device,
619
- reg_user_mr),
620
- rvt_reg_user_mr);
621
- break;
622
-
623
- case DEREG_MR:
624
- check_driver_override(rdi, offsetof(struct ib_device,
625
- dereg_mr),
626
- rvt_dereg_mr);
627
- break;
628
-
629
- case ALLOC_FMR:
630
- check_driver_override(rdi, offsetof(struct ib_device,
631
- alloc_fmr),
632
- rvt_alloc_fmr);
633
- break;
634
-
635
- case ALLOC_MR:
636
- check_driver_override(rdi, offsetof(struct ib_device,
637
- alloc_mr),
638
- rvt_alloc_mr);
639
- break;
640
-
641
- case MAP_MR_SG:
642
- check_driver_override(rdi, offsetof(struct ib_device,
643
- map_mr_sg),
644
- rvt_map_mr_sg);
645
- break;
646
-
647
- case MAP_PHYS_FMR:
648
- check_driver_override(rdi, offsetof(struct ib_device,
649
- map_phys_fmr),
650
- rvt_map_phys_fmr);
651
- break;
652
-
653
- case UNMAP_FMR:
654
- check_driver_override(rdi, offsetof(struct ib_device,
655
- unmap_fmr),
656
- rvt_unmap_fmr);
657
- break;
658
-
659
- case DEALLOC_FMR:
660
- check_driver_override(rdi, offsetof(struct ib_device,
661
- dealloc_fmr),
662
- rvt_dealloc_fmr);
663
- break;
664
-
665
- case MMAP:
666
- check_driver_override(rdi, offsetof(struct ib_device,
667
- mmap),
668
- rvt_mmap);
669
- break;
670
-
671
- case CREATE_CQ:
672
- check_driver_override(rdi, offsetof(struct ib_device,
673
- create_cq),
674
- rvt_create_cq);
675
- break;
676
-
677
- case DESTROY_CQ:
678
- check_driver_override(rdi, offsetof(struct ib_device,
679
- destroy_cq),
680
- rvt_destroy_cq);
681
- break;
682
-
683
- case POLL_CQ:
684
- check_driver_override(rdi, offsetof(struct ib_device,
685
- poll_cq),
686
- rvt_poll_cq);
687
- break;
688
-
689
- case REQ_NOTFIY_CQ:
690
- check_driver_override(rdi, offsetof(struct ib_device,
691
- req_notify_cq),
692
- rvt_req_notify_cq);
693
- break;
694
-
695
- case RESIZE_CQ:
696
- check_driver_override(rdi, offsetof(struct ib_device,
697
- resize_cq),
698
- rvt_resize_cq);
699
- break;
700
-
701
- case ALLOC_PD:
702
- check_driver_override(rdi, offsetof(struct ib_device,
703
- alloc_pd),
704
- rvt_alloc_pd);
705
- break;
706
-
707
- case DEALLOC_PD:
708
- check_driver_override(rdi, offsetof(struct ib_device,
709
- dealloc_pd),
710
- rvt_dealloc_pd);
711
- break;
712
-
713
- default:
714
- return -EINVAL;
715510 }
716511
717512 return 0;
....@@ -726,7 +521,7 @@
726521 *
727522 * Return: 0 on success otherwise an errno.
728523 */
729
-int rvt_register_device(struct rvt_dev_info *rdi, u32 driver_id)
524
+int rvt_register_device(struct rvt_dev_info *rdi)
730525 {
731526 int ret = 0, i;
732527
....@@ -743,6 +538,7 @@
743538 return -EINVAL;
744539 }
745540
541
+ ib_set_device_ops(&rdi->ibdev, &rvt_dev_ops);
746542
747543 /* Once we get past here we can use rvt_pr macros and tracepoints */
748544 trace_rvt_dbg(rdi, "Driver attempting registration");
....@@ -772,11 +568,15 @@
772568 goto bail_no_mr;
773569 }
774570
571
+ /* Memory Working Set Size */
572
+ ret = rvt_wss_init(rdi);
573
+ if (ret) {
574
+ rvt_pr_err(rdi, "Error in WSS init.\n");
575
+ goto bail_mr;
576
+ }
577
+
775578 /* Completion queues */
776579 spin_lock_init(&rdi->n_cqs_lock);
777
-
778
- /* DMA Operations */
779
- rdi->ibdev.dev.dma_ops = rdi->ibdev.dev.dma_ops ? : &dma_virt_ops;
780580
781581 /* Protection Domain */
782582 spin_lock_init(&rdi->n_pds_lock);
....@@ -788,7 +588,6 @@
788588 * exactly which functions rdmavt supports, nor do they know the ABI
789589 * version, so we do all of this sort of stuff here.
790590 */
791
- rdi->ibdev.uverbs_abi_ver = RVT_UVERBS_ABI_VERSION;
792591 rdi->ibdev.uverbs_cmd_mask =
793592 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
794593 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
....@@ -824,12 +623,11 @@
824623 if (!rdi->ibdev.num_comp_vectors)
825624 rdi->ibdev.num_comp_vectors = 1;
826625
827
- rdi->ibdev.driver_id = driver_id;
828626 /* We are now good to announce we exist */
829
- ret = ib_register_device(&rdi->ibdev, rdi->driver_f.port_callback);
627
+ ret = ib_register_device(&rdi->ibdev, dev_name(&rdi->ibdev.dev), NULL);
830628 if (ret) {
831629 rvt_pr_err(rdi, "Failed to register driver with ib core.\n");
832
- goto bail_mr;
630
+ goto bail_wss;
833631 }
834632
835633 rvt_create_mad_agents(rdi);
....@@ -837,6 +635,8 @@
837635 rvt_pr_info(rdi, "Registration with rdmavt done.\n");
838636 return ret;
839637
638
+bail_wss:
639
+ rvt_wss_exit(rdi);
840640 bail_mr:
841641 rvt_mr_exit(rdi);
842642
....@@ -860,6 +660,7 @@
860660 rvt_free_mad_agents(rdi);
861661
862662 ib_unregister_device(&rdi->ibdev);
663
+ rvt_wss_exit(rdi);
863664 rvt_mr_exit(rdi);
864665 rvt_qp_exit(rdi);
865666 }
....@@ -867,9 +668,10 @@
867668
868669 /**
869670 * rvt_init_port - init internal data for driver port
870
- * @rdi: rvt dev strut
671
+ * @rdi: rvt_dev_info struct
871672 * @port: rvt port
872673 * @port_index: 0 based index of ports, different from IB core port num
674
+ * @pkey_table: pkey_table for @port
873675 *
874676 * Keep track of a list of ports. No need to have a detach port.
875677 * They persist until the driver goes away.