forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/infiniband/hw/usnic/usnic_ib_verbs.c
....@@ -37,6 +37,7 @@
3737
3838 #include <rdma/ib_user_verbs.h>
3939 #include <rdma/ib_addr.h>
40
+#include <rdma/uverbs_ioctl.h>
4041
4142 #include "usnic_abi.h"
4243 #include "usnic_ib.h"
....@@ -159,7 +160,8 @@
159160
160161 err = ib_copy_to_udata(udata, &resp, sizeof(resp));
161162 if (err) {
162
- usnic_err("Failed to copy udata for %s", us_ibdev->ib_dev.name);
163
+ usnic_err("Failed to copy udata for %s",
164
+ dev_name(&us_ibdev->ib_dev.dev));
163165 return err;
164166 }
165167
....@@ -192,12 +194,12 @@
192194 return ERR_CAST(dev_list);
193195 for (i = 0; dev_list[i]; i++) {
194196 dev = dev_list[i];
195
- vf = pci_get_drvdata(to_pci_dev(dev));
197
+ vf = dev_get_drvdata(dev);
196198 spin_lock(&vf->lock);
197199 vnic = vf->vnic;
198200 if (!usnic_vnic_check_room(vnic, res_spec)) {
199201 usnic_dbg("Found used vnic %s from %s\n",
200
- us_ibdev->ib_dev.name,
202
+ dev_name(&us_ibdev->ib_dev.dev),
201203 pci_name(usnic_vnic_get_pdev(
202204 vnic)));
203205 qp_grp = usnic_ib_qp_grp_create(us_ibdev->ufdev,
....@@ -231,7 +233,8 @@
231233 spin_unlock(&vf->lock);
232234 }
233235
234
- usnic_info("No free qp grp found on %s\n", us_ibdev->ib_dev.name);
236
+ usnic_info("No free qp grp found on %s\n",
237
+ dev_name(&us_ibdev->ib_dev.dev));
235238 return ERR_PTR(-ENOMEM);
236239
237240 qp_grp_check:
....@@ -322,7 +325,6 @@
322325 props->max_mcast_grp = 0;
323326 props->max_mcast_qp_attach = 0;
324327 props->max_total_mcast_qp_attach = 0;
325
- props->max_map_per_fmr = 0;
326328 /* Owned by Userspace
327329 * max_qp_wr, max_sge, max_sge_rd, max_cqe */
328330 mutex_unlock(&us_ibdev->usdev_lock);
....@@ -356,18 +358,18 @@
356358
357359 if (!us_ibdev->ufdev->link_up) {
358360 props->state = IB_PORT_DOWN;
359
- props->phys_state = 3;
361
+ props->phys_state = IB_PORT_PHYS_STATE_DISABLED;
360362 } else if (!us_ibdev->ufdev->inaddr) {
361363 props->state = IB_PORT_INIT;
362
- props->phys_state = 4;
364
+ props->phys_state =
365
+ IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING;
363366 } else {
364367 props->state = IB_PORT_ACTIVE;
365
- props->phys_state = 5;
368
+ props->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
366369 }
367370
368371 props->port_cap_flags = 0;
369372 props->gid_tbl_len = 1;
370
- props->pkey_tbl_len = 1;
371373 props->bad_pkey_cntr = 0;
372374 props->qkey_viol_cntr = 0;
373375 props->max_mtu = IB_MTU_4096;
....@@ -437,56 +439,22 @@
437439 return 0;
438440 }
439441
440
-struct net_device *usnic_get_netdev(struct ib_device *device, u8 port_num)
442
+int usnic_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
441443 {
442
- struct usnic_ib_dev *us_ibdev = to_usdev(device);
443
-
444
- if (us_ibdev->netdev)
445
- dev_hold(us_ibdev->netdev);
446
-
447
- return us_ibdev->netdev;
448
-}
449
-
450
-int usnic_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
451
- u16 *pkey)
452
-{
453
- if (index > 0)
454
- return -EINVAL;
455
-
456
- *pkey = 0xffff;
457
- return 0;
458
-}
459
-
460
-struct ib_pd *usnic_ib_alloc_pd(struct ib_device *ibdev,
461
- struct ib_ucontext *context,
462
- struct ib_udata *udata)
463
-{
464
- struct usnic_ib_pd *pd;
444
+ struct usnic_ib_pd *pd = to_upd(ibpd);
465445 void *umem_pd;
466
-
467
- usnic_dbg("\n");
468
-
469
- pd = kzalloc(sizeof(*pd), GFP_KERNEL);
470
- if (!pd)
471
- return ERR_PTR(-ENOMEM);
472446
473447 umem_pd = pd->umem_pd = usnic_uiom_alloc_pd();
474448 if (IS_ERR_OR_NULL(umem_pd)) {
475
- kfree(pd);
476
- return ERR_PTR(umem_pd ? PTR_ERR(umem_pd) : -ENOMEM);
449
+ return umem_pd ? PTR_ERR(umem_pd) : -ENOMEM;
477450 }
478451
479
- usnic_info("domain 0x%p allocated for context 0x%p and device %s\n",
480
- pd, context, ibdev->name);
481
- return &pd->ibpd;
452
+ return 0;
482453 }
483454
484
-int usnic_ib_dealloc_pd(struct ib_pd *pd)
455
+int usnic_ib_dealloc_pd(struct ib_pd *pd, struct ib_udata *udata)
485456 {
486
- usnic_info("freeing domain 0x%p\n", pd);
487
-
488457 usnic_uiom_dealloc_pd((to_upd(pd))->umem_pd);
489
- kfree(pd);
490458 return 0;
491459 }
492460
....@@ -497,7 +465,8 @@
497465 int err;
498466 struct usnic_ib_dev *us_ibdev;
499467 struct usnic_ib_qp_grp *qp_grp;
500
- struct usnic_ib_ucontext *ucontext;
468
+ struct usnic_ib_ucontext *ucontext = rdma_udata_to_drv_context(
469
+ udata, struct usnic_ib_ucontext, ibucontext);
501470 int cq_cnt;
502471 struct usnic_vnic_res_spec res_spec;
503472 struct usnic_ib_create_qp_cmd cmd;
....@@ -505,7 +474,6 @@
505474
506475 usnic_dbg("\n");
507476
508
- ucontext = to_uucontext(pd->uobject->context);
509477 us_ibdev = to_usdev(pd->device);
510478
511479 if (init_attr->create_flags)
....@@ -514,21 +482,21 @@
514482 err = ib_copy_from_udata(&cmd, udata, sizeof(cmd));
515483 if (err) {
516484 usnic_err("%s: cannot copy udata for create_qp\n",
517
- us_ibdev->ib_dev.name);
485
+ dev_name(&us_ibdev->ib_dev.dev));
518486 return ERR_PTR(-EINVAL);
519487 }
520488
521489 err = create_qp_validate_user_data(cmd);
522490 if (err) {
523491 usnic_err("%s: Failed to validate user data\n",
524
- us_ibdev->ib_dev.name);
492
+ dev_name(&us_ibdev->ib_dev.dev));
525493 return ERR_PTR(-EINVAL);
526494 }
527495
528496 if (init_attr->qp_type != IB_QPT_UD) {
529497 usnic_err("%s asked to make a non-UD QP: %d\n",
530
- us_ibdev->ib_dev.name, init_attr->qp_type);
531
- return ERR_PTR(-EINVAL);
498
+ dev_name(&us_ibdev->ib_dev.dev), init_attr->qp_type);
499
+ return ERR_PTR(-EOPNOTSUPP);
532500 }
533501
534502 trans_spec = cmd.spec;
....@@ -563,7 +531,7 @@
563531 return ERR_PTR(err);
564532 }
565533
566
-int usnic_ib_destroy_qp(struct ib_qp *qp)
534
+int usnic_ib_destroy_qp(struct ib_qp *qp, struct ib_udata *udata)
567535 {
568536 struct usnic_ib_qp_grp *qp_grp;
569537 struct usnic_ib_vf *vf;
....@@ -612,28 +580,17 @@
612580 return status;
613581 }
614582
615
-struct ib_cq *usnic_ib_create_cq(struct ib_device *ibdev,
616
- const struct ib_cq_init_attr *attr,
617
- struct ib_ucontext *context,
618
- struct ib_udata *udata)
583
+int usnic_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
584
+ struct ib_udata *udata)
619585 {
620
- struct ib_cq *cq;
621
-
622
- usnic_dbg("\n");
623586 if (attr->flags)
624
- return ERR_PTR(-EINVAL);
587
+ return -EINVAL;
625588
626
- cq = kzalloc(sizeof(*cq), GFP_KERNEL);
627
- if (!cq)
628
- return ERR_PTR(-EBUSY);
629
-
630
- return cq;
589
+ return 0;
631590 }
632591
633
-int usnic_ib_destroy_cq(struct ib_cq *cq)
592
+int usnic_ib_destroy_cq(struct ib_cq *cq, struct ib_udata *udata)
634593 {
635
- usnic_dbg("\n");
636
- kfree(cq);
637594 return 0;
638595 }
639596
....@@ -666,48 +623,42 @@
666623 return ERR_PTR(err);
667624 }
668625
669
-int usnic_ib_dereg_mr(struct ib_mr *ibmr)
626
+int usnic_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
670627 {
671628 struct usnic_ib_mr *mr = to_umr(ibmr);
672629
673630 usnic_dbg("va 0x%lx length 0x%zx\n", mr->umem->va, mr->umem->length);
674631
675
- usnic_uiom_reg_release(mr->umem, ibmr->uobject->context);
632
+ usnic_uiom_reg_release(mr->umem);
676633 kfree(mr);
677634 return 0;
678635 }
679636
680
-struct ib_ucontext *usnic_ib_alloc_ucontext(struct ib_device *ibdev,
681
- struct ib_udata *udata)
637
+int usnic_ib_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata *udata)
682638 {
683
- struct usnic_ib_ucontext *context;
639
+ struct ib_device *ibdev = uctx->device;
640
+ struct usnic_ib_ucontext *context = to_ucontext(uctx);
684641 struct usnic_ib_dev *us_ibdev = to_usdev(ibdev);
685642 usnic_dbg("\n");
686
-
687
- context = kmalloc(sizeof(*context), GFP_KERNEL);
688
- if (!context)
689
- return ERR_PTR(-ENOMEM);
690643
691644 INIT_LIST_HEAD(&context->qp_grp_list);
692645 mutex_lock(&us_ibdev->usdev_lock);
693646 list_add_tail(&context->link, &us_ibdev->ctx_list);
694647 mutex_unlock(&us_ibdev->usdev_lock);
695648
696
- return &context->ibucontext;
649
+ return 0;
697650 }
698651
699
-int usnic_ib_dealloc_ucontext(struct ib_ucontext *ibcontext)
652
+void usnic_ib_dealloc_ucontext(struct ib_ucontext *ibcontext)
700653 {
701654 struct usnic_ib_ucontext *context = to_uucontext(ibcontext);
702655 struct usnic_ib_dev *us_ibdev = to_usdev(ibcontext->device);
703656 usnic_dbg("\n");
704657
705658 mutex_lock(&us_ibdev->usdev_lock);
706
- BUG_ON(!list_empty(&context->qp_grp_list));
659
+ WARN_ON_ONCE(!list_empty(&context->qp_grp_list));
707660 list_del(&context->link);
708661 mutex_unlock(&us_ibdev->usdev_lock);
709
- kfree(context);
710
- return 0;
711662 }
712663
713664 int usnic_ib_mmap(struct ib_ucontext *context,
....@@ -761,56 +712,3 @@
761712 return -EINVAL;
762713 }
763714
764
-/* In ib callbacks section - Start of stub funcs */
765
-struct ib_ah *usnic_ib_create_ah(struct ib_pd *pd,
766
- struct rdma_ah_attr *ah_attr,
767
- struct ib_udata *udata)
768
-
769
-{
770
- usnic_dbg("\n");
771
- return ERR_PTR(-EPERM);
772
-}
773
-
774
-int usnic_ib_destroy_ah(struct ib_ah *ah)
775
-{
776
- usnic_dbg("\n");
777
- return -EINVAL;
778
-}
779
-
780
-int usnic_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
781
- const struct ib_send_wr **bad_wr)
782
-{
783
- usnic_dbg("\n");
784
- return -EINVAL;
785
-}
786
-
787
-int usnic_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
788
- const struct ib_recv_wr **bad_wr)
789
-{
790
- usnic_dbg("\n");
791
- return -EINVAL;
792
-}
793
-
794
-int usnic_ib_poll_cq(struct ib_cq *ibcq, int num_entries,
795
- struct ib_wc *wc)
796
-{
797
- usnic_dbg("\n");
798
- return -EINVAL;
799
-}
800
-
801
-int usnic_ib_req_notify_cq(struct ib_cq *cq,
802
- enum ib_cq_notify_flags flags)
803
-{
804
- usnic_dbg("\n");
805
- return -EINVAL;
806
-}
807
-
808
-struct ib_mr *usnic_ib_get_dma_mr(struct ib_pd *pd, int acc)
809
-{
810
- usnic_dbg("\n");
811
- return ERR_PTR(-ENOMEM);
812
-}
813
-
814
-
815
-/* In ib callbacks section - End of stub funcs */
816
-/* End of ib callbacks section */