forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/drivers/infiniband/hw/bnxt_re/ib_verbs.c
....@@ -48,6 +48,7 @@
4848 #include <rdma/ib_addr.h>
4949 #include <rdma/ib_mad.h>
5050 #include <rdma/ib_cache.h>
51
+#include <rdma/uverbs_ioctl.h>
5152
5253 #include "bnxt_ulp.h"
5354
....@@ -118,21 +119,6 @@
118119 }
119120
120121 /* Device */
121
-struct net_device *bnxt_re_get_netdev(struct ib_device *ibdev, u8 port_num)
122
-{
123
- struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
124
- struct net_device *netdev = NULL;
125
-
126
- rcu_read_lock();
127
- if (rdev)
128
- netdev = rdev->netdev;
129
- if (netdev)
130
- dev_hold(netdev);
131
-
132
- rcu_read_unlock();
133
- return netdev;
134
-}
135
-
136122 int bnxt_re_query_device(struct ib_device *ibdev,
137123 struct ib_device_attr *ib_attr,
138124 struct ib_udata *udata)
....@@ -191,9 +177,6 @@
191177 ib_attr->max_total_mcast_qp_attach = 0;
192178 ib_attr->max_ah = dev_attr->max_ah;
193179
194
- ib_attr->max_fmr = 0;
195
- ib_attr->max_map_per_fmr = 0;
196
-
197180 ib_attr->max_srq = dev_attr->max_srq;
198181 ib_attr->max_srq_wr = dev_attr->max_srq_wqes;
199182 ib_attr->max_srq_sge = dev_attr->max_srq_sges;
....@@ -202,24 +185,6 @@
202185
203186 ib_attr->max_pkeys = 1;
204187 ib_attr->local_ca_ack_delay = BNXT_RE_DEFAULT_ACK_DELAY;
205
- return 0;
206
-}
207
-
208
-int bnxt_re_modify_device(struct ib_device *ibdev,
209
- int device_modify_mask,
210
- struct ib_device_modify *device_modify)
211
-{
212
- switch (device_modify_mask) {
213
- case IB_DEVICE_MODIFY_SYS_IMAGE_GUID:
214
- /* Modify the GUID requires the modification of the GID table */
215
- /* GUID should be made as READ-ONLY */
216
- break;
217
- case IB_DEVICE_MODIFY_NODE_DESC:
218
- /* Node Desc should be made as READ-ONLY */
219
- break;
220
- default:
221
- break;
222
- }
223188 return 0;
224189 }
225190
....@@ -234,10 +199,10 @@
234199
235200 if (netif_running(rdev->netdev) && netif_carrier_ok(rdev->netdev)) {
236201 port_attr->state = IB_PORT_ACTIVE;
237
- port_attr->phys_state = 5;
202
+ port_attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
238203 } else {
239204 port_attr->state = IB_PORT_DOWN;
240
- port_attr->phys_state = 3;
205
+ port_attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
241206 }
242207 port_attr->max_mtu = IB_MTU_4096;
243208 port_attr->active_mtu = iboe_get_mtu(rdev->netdev->mtu);
....@@ -322,6 +287,7 @@
322287 struct bnxt_re_dev *rdev = to_bnxt_re_dev(attr->device, ibdev);
323288 struct bnxt_qplib_sgid_tbl *sgid_tbl = &rdev->qplib_res.sgid_tbl;
324289 struct bnxt_qplib_gid *gid_to_del;
290
+ u16 vlan_id = 0xFFFF;
325291
326292 /* Delete the entry from the hardware */
327293 ctx = *context;
....@@ -331,7 +297,8 @@
331297 if (sgid_tbl && sgid_tbl->active) {
332298 if (ctx->idx >= sgid_tbl->max)
333299 return -EINVAL;
334
- gid_to_del = &sgid_tbl->tbl[ctx->idx];
300
+ gid_to_del = &sgid_tbl->tbl[ctx->idx].gid;
301
+ vlan_id = sgid_tbl->tbl[ctx->idx].vlan_id;
335302 /* DEL_GID is called in WQ context(netdevice_event_work_handler)
336303 * or via the ib_unregister_device path. In the former case QP1
337304 * may not be destroyed yet, in which case just return as FW
....@@ -342,17 +309,18 @@
342309 */
343310 if (ctx->idx == 0 &&
344311 rdma_link_local_addr((struct in6_addr *)gid_to_del) &&
345
- ctx->refcnt == 1 && rdev->qp1_sqp) {
346
- dev_dbg(rdev_to_dev(rdev),
347
- "Trying to delete GID0 while QP1 is alive\n");
312
+ ctx->refcnt == 1 && rdev->gsi_ctx.gsi_sqp) {
313
+ ibdev_dbg(&rdev->ibdev,
314
+ "Trying to delete GID0 while QP1 is alive\n");
348315 return -EFAULT;
349316 }
350317 ctx->refcnt--;
351318 if (!ctx->refcnt) {
352
- rc = bnxt_qplib_del_sgid(sgid_tbl, gid_to_del, true);
319
+ rc = bnxt_qplib_del_sgid(sgid_tbl, gid_to_del,
320
+ vlan_id, true);
353321 if (rc) {
354
- dev_err(rdev_to_dev(rdev),
355
- "Failed to remove GID: %#x", rc);
322
+ ibdev_err(&rdev->ibdev,
323
+ "Failed to remove GID: %#x", rc);
356324 } else {
357325 ctx_tbl = sgid_tbl->ctx;
358326 ctx_tbl[ctx->idx] = NULL;
....@@ -374,8 +342,9 @@
374342 struct bnxt_re_dev *rdev = to_bnxt_re_dev(attr->device, ibdev);
375343 struct bnxt_qplib_sgid_tbl *sgid_tbl = &rdev->qplib_res.sgid_tbl;
376344
377
- if ((attr->ndev) && is_vlan_dev(attr->ndev))
378
- vlan_id = vlan_dev_vlan_id(attr->ndev);
345
+ rc = rdma_read_gid_l2_fields(attr, &vlan_id, NULL);
346
+ if (rc)
347
+ return rc;
379348
380349 rc = bnxt_qplib_add_sgid(sgid_tbl, (struct bnxt_qplib_gid *)&attr->gid,
381350 rdev->qplib_res.netdev->dev_addr,
....@@ -388,7 +357,7 @@
388357 }
389358
390359 if (rc < 0) {
391
- dev_err(rdev_to_dev(rdev), "Failed to add GID: %#x", rc);
360
+ ibdev_err(&rdev->ibdev, "Failed to add GID: %#x", rc);
392361 return rc;
393362 }
394363
....@@ -451,12 +420,12 @@
451420 wqe.bind.r_key = fence->bind_rkey;
452421 fence->bind_rkey = ib_inc_rkey(fence->bind_rkey);
453422
454
- dev_dbg(rdev_to_dev(qp->rdev),
455
- "Posting bind fence-WQE: rkey: %#x QP: %d PD: %p\n",
423
+ ibdev_dbg(&qp->rdev->ibdev,
424
+ "Posting bind fence-WQE: rkey: %#x QP: %d PD: %p\n",
456425 wqe.bind.r_key, qp->qplib_qp.id, pd);
457426 rc = bnxt_qplib_post_send(&qp->qplib_qp, &wqe);
458427 if (rc) {
459
- dev_err(rdev_to_dev(qp->rdev), "Failed to bind fence-WQE\n");
428
+ ibdev_err(&qp->rdev->ibdev, "Failed to bind fence-WQE\n");
460429 return rc;
461430 }
462431 bnxt_qplib_post_send_db(&qp->qplib_qp);
....@@ -507,7 +476,7 @@
507476 DMA_BIDIRECTIONAL);
508477 rc = dma_mapping_error(dev, dma_addr);
509478 if (rc) {
510
- dev_err(rdev_to_dev(rdev), "Failed to dma-map fence-MR-mem\n");
479
+ ibdev_err(&rdev->ibdev, "Failed to dma-map fence-MR-mem\n");
511480 rc = -EIO;
512481 fence->dma_addr = 0;
513482 goto fail;
....@@ -527,7 +496,7 @@
527496 mr->qplib_mr.flags = __from_ib_access_flags(mr_access_flags);
528497 rc = bnxt_qplib_alloc_mrw(&rdev->qplib_res, &mr->qplib_mr);
529498 if (rc) {
530
- dev_err(rdev_to_dev(rdev), "Failed to alloc fence-HW-MR\n");
499
+ ibdev_err(&rdev->ibdev, "Failed to alloc fence-HW-MR\n");
531500 goto fail;
532501 }
533502
....@@ -539,7 +508,7 @@
539508 rc = bnxt_qplib_reg_mr(&rdev->qplib_res, &mr->qplib_mr, &pbl_tbl,
540509 BNXT_RE_FENCE_PBL_SIZE, false, PAGE_SIZE);
541510 if (rc) {
542
- dev_err(rdev_to_dev(rdev), "Failed to register fence-MR\n");
511
+ ibdev_err(&rdev->ibdev, "Failed to register fence-MR\n");
543512 goto fail;
544513 }
545514 mr->ib_mr.rkey = mr->qplib_mr.rkey;
....@@ -547,8 +516,8 @@
547516 /* Create a fence MW only for kernel consumers */
548517 mw = bnxt_re_alloc_mw(&pd->ib_pd, IB_MW_TYPE_1, NULL);
549518 if (IS_ERR(mw)) {
550
- dev_err(rdev_to_dev(rdev),
551
- "Failed to create fence-MW for PD: %p\n", pd);
519
+ ibdev_err(&rdev->ibdev,
520
+ "Failed to create fence-MW for PD: %p\n", pd);
552521 rc = PTR_ERR(mw);
553522 goto fail;
554523 }
....@@ -563,44 +532,31 @@
563532 }
564533
565534 /* Protection Domains */
566
-int bnxt_re_dealloc_pd(struct ib_pd *ib_pd)
535
+int bnxt_re_dealloc_pd(struct ib_pd *ib_pd, struct ib_udata *udata)
567536 {
568537 struct bnxt_re_pd *pd = container_of(ib_pd, struct bnxt_re_pd, ib_pd);
569538 struct bnxt_re_dev *rdev = pd->rdev;
570
- int rc;
571539
572540 bnxt_re_destroy_fence_mr(pd);
573541
574
- if (pd->qplib_pd.id) {
575
- rc = bnxt_qplib_dealloc_pd(&rdev->qplib_res,
576
- &rdev->qplib_res.pd_tbl,
577
- &pd->qplib_pd);
578
- if (rc)
579
- dev_err(rdev_to_dev(rdev), "Failed to deallocate HW PD");
580
- }
581
-
582
- kfree(pd);
542
+ if (pd->qplib_pd.id)
543
+ bnxt_qplib_dealloc_pd(&rdev->qplib_res, &rdev->qplib_res.pd_tbl,
544
+ &pd->qplib_pd);
583545 return 0;
584546 }
585547
586
-struct ib_pd *bnxt_re_alloc_pd(struct ib_device *ibdev,
587
- struct ib_ucontext *ucontext,
588
- struct ib_udata *udata)
548
+int bnxt_re_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
589549 {
550
+ struct ib_device *ibdev = ibpd->device;
590551 struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
591
- struct bnxt_re_ucontext *ucntx = container_of(ucontext,
592
- struct bnxt_re_ucontext,
593
- ib_uctx);
594
- struct bnxt_re_pd *pd;
552
+ struct bnxt_re_ucontext *ucntx = rdma_udata_to_drv_context(
553
+ udata, struct bnxt_re_ucontext, ib_uctx);
554
+ struct bnxt_re_pd *pd = container_of(ibpd, struct bnxt_re_pd, ib_pd);
595555 int rc;
596
-
597
- pd = kzalloc(sizeof(*pd), GFP_KERNEL);
598
- if (!pd)
599
- return ERR_PTR(-ENOMEM);
600556
601557 pd->rdev = rdev;
602558 if (bnxt_qplib_alloc_pd(&rdev->qplib_res.pd_tbl, &pd->qplib_pd)) {
603
- dev_err(rdev_to_dev(rdev), "Failed to allocate HW PD");
559
+ ibdev_err(&rdev->ibdev, "Failed to allocate HW PD");
604560 rc = -ENOMEM;
605561 goto fail;
606562 }
....@@ -627,59 +583,71 @@
627583
628584 rc = ib_copy_to_udata(udata, &resp, sizeof(resp));
629585 if (rc) {
630
- dev_err(rdev_to_dev(rdev),
631
- "Failed to copy user response\n");
586
+ ibdev_err(&rdev->ibdev,
587
+ "Failed to copy user response\n");
632588 goto dbfail;
633589 }
634590 }
635591
636592 if (!udata)
637593 if (bnxt_re_create_fence_mr(pd))
638
- dev_warn(rdev_to_dev(rdev),
639
- "Failed to create Fence-MR\n");
640
- return &pd->ib_pd;
594
+ ibdev_warn(&rdev->ibdev,
595
+ "Failed to create Fence-MR\n");
596
+ return 0;
641597 dbfail:
642
- (void)bnxt_qplib_dealloc_pd(&rdev->qplib_res, &rdev->qplib_res.pd_tbl,
643
- &pd->qplib_pd);
598
+ bnxt_qplib_dealloc_pd(&rdev->qplib_res, &rdev->qplib_res.pd_tbl,
599
+ &pd->qplib_pd);
644600 fail:
645
- kfree(pd);
646
- return ERR_PTR(rc);
601
+ return rc;
647602 }
648603
649604 /* Address Handles */
650
-int bnxt_re_destroy_ah(struct ib_ah *ib_ah)
605
+int bnxt_re_destroy_ah(struct ib_ah *ib_ah, u32 flags)
651606 {
652607 struct bnxt_re_ah *ah = container_of(ib_ah, struct bnxt_re_ah, ib_ah);
653608 struct bnxt_re_dev *rdev = ah->rdev;
654
- int rc;
655609
656
- rc = bnxt_qplib_destroy_ah(&rdev->qplib_res, &ah->qplib_ah);
657
- if (rc) {
658
- dev_err(rdev_to_dev(rdev), "Failed to destroy HW AH");
659
- return rc;
660
- }
661
- kfree(ah);
610
+ bnxt_qplib_destroy_ah(&rdev->qplib_res, &ah->qplib_ah,
611
+ !(flags & RDMA_DESTROY_AH_SLEEPABLE));
662612 return 0;
663613 }
664614
665
-struct ib_ah *bnxt_re_create_ah(struct ib_pd *ib_pd,
666
- struct rdma_ah_attr *ah_attr,
667
- struct ib_udata *udata)
615
+static u8 bnxt_re_stack_to_dev_nw_type(enum rdma_network_type ntype)
668616 {
669
- struct bnxt_re_pd *pd = container_of(ib_pd, struct bnxt_re_pd, ib_pd);
670
- struct bnxt_re_dev *rdev = pd->rdev;
671
- struct bnxt_re_ah *ah;
672
- const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
673
- int rc;
674617 u8 nw_type;
675618
676
- if (!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) {
677
- dev_err(rdev_to_dev(rdev), "Failed to alloc AH: GRH not set");
678
- return ERR_PTR(-EINVAL);
619
+ switch (ntype) {
620
+ case RDMA_NETWORK_IPV4:
621
+ nw_type = CMDQ_CREATE_AH_TYPE_V2IPV4;
622
+ break;
623
+ case RDMA_NETWORK_IPV6:
624
+ nw_type = CMDQ_CREATE_AH_TYPE_V2IPV6;
625
+ break;
626
+ default:
627
+ nw_type = CMDQ_CREATE_AH_TYPE_V1;
628
+ break;
679629 }
680
- ah = kzalloc(sizeof(*ah), GFP_ATOMIC);
681
- if (!ah)
682
- return ERR_PTR(-ENOMEM);
630
+ return nw_type;
631
+}
632
+
633
+int bnxt_re_create_ah(struct ib_ah *ib_ah, struct rdma_ah_init_attr *init_attr,
634
+ struct ib_udata *udata)
635
+{
636
+ struct ib_pd *ib_pd = ib_ah->pd;
637
+ struct bnxt_re_pd *pd = container_of(ib_pd, struct bnxt_re_pd, ib_pd);
638
+ struct rdma_ah_attr *ah_attr = init_attr->ah_attr;
639
+ const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
640
+ struct bnxt_re_dev *rdev = pd->rdev;
641
+ const struct ib_gid_attr *sgid_attr;
642
+ struct bnxt_re_gid_ctx *ctx;
643
+ struct bnxt_re_ah *ah = container_of(ib_ah, struct bnxt_re_ah, ib_ah);
644
+ u8 nw_type;
645
+ int rc;
646
+
647
+ if (!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) {
648
+ ibdev_err(&rdev->ibdev, "Failed to alloc AH: GRH not set");
649
+ return -EINVAL;
650
+ }
683651
684652 ah->rdev = rdev;
685653 ah->qplib_ah.pd = &pd->qplib_pd;
....@@ -687,55 +655,38 @@
687655 /* Supply the configuration for the HW */
688656 memcpy(ah->qplib_ah.dgid.data, grh->dgid.raw,
689657 sizeof(union ib_gid));
690
- /*
691
- * If RoCE V2 is enabled, stack will have two entries for
692
- * each GID entry. Avoiding this duplicte entry in HW. Dividing
693
- * the GID index by 2 for RoCE V2
658
+ sgid_attr = grh->sgid_attr;
659
+ /* Get the HW context of the GID. The reference
660
+ * of GID table entry is already taken by the caller.
694661 */
695
- ah->qplib_ah.sgid_index = grh->sgid_index / 2;
662
+ ctx = rdma_read_gid_hw_context(sgid_attr);
663
+ ah->qplib_ah.sgid_index = ctx->idx;
696664 ah->qplib_ah.host_sgid_index = grh->sgid_index;
697665 ah->qplib_ah.traffic_class = grh->traffic_class;
698666 ah->qplib_ah.flow_label = grh->flow_label;
699667 ah->qplib_ah.hop_limit = grh->hop_limit;
700668 ah->qplib_ah.sl = rdma_ah_get_sl(ah_attr);
701
- if (ib_pd->uobject &&
702
- !rdma_is_multicast_addr((struct in6_addr *)
703
- grh->dgid.raw) &&
704
- !rdma_link_local_addr((struct in6_addr *)
705
- grh->dgid.raw)) {
706
- const struct ib_gid_attr *sgid_attr;
707669
708
- sgid_attr = grh->sgid_attr;
709
- /* Get network header type for this GID */
710
- nw_type = rdma_gid_attr_network_type(sgid_attr);
711
- switch (nw_type) {
712
- case RDMA_NETWORK_IPV4:
713
- ah->qplib_ah.nw_type = CMDQ_CREATE_AH_TYPE_V2IPV4;
714
- break;
715
- case RDMA_NETWORK_IPV6:
716
- ah->qplib_ah.nw_type = CMDQ_CREATE_AH_TYPE_V2IPV6;
717
- break;
718
- default:
719
- ah->qplib_ah.nw_type = CMDQ_CREATE_AH_TYPE_V1;
720
- break;
721
- }
722
- }
670
+ /* Get network header type for this GID */
671
+ nw_type = rdma_gid_attr_network_type(sgid_attr);
672
+ ah->qplib_ah.nw_type = bnxt_re_stack_to_dev_nw_type(nw_type);
723673
724674 memcpy(ah->qplib_ah.dmac, ah_attr->roce.dmac, ETH_ALEN);
725
- rc = bnxt_qplib_create_ah(&rdev->qplib_res, &ah->qplib_ah);
675
+ rc = bnxt_qplib_create_ah(&rdev->qplib_res, &ah->qplib_ah,
676
+ !(init_attr->flags &
677
+ RDMA_CREATE_AH_SLEEPABLE));
726678 if (rc) {
727
- dev_err(rdev_to_dev(rdev), "Failed to allocate HW AH");
728
- goto fail;
679
+ ibdev_err(&rdev->ibdev, "Failed to allocate HW AH");
680
+ return rc;
729681 }
730682
731683 /* Write AVID to shared page. */
732
- if (ib_pd->uobject) {
733
- struct ib_ucontext *ib_uctx = ib_pd->uobject->context;
734
- struct bnxt_re_ucontext *uctx;
684
+ if (udata) {
685
+ struct bnxt_re_ucontext *uctx = rdma_udata_to_drv_context(
686
+ udata, struct bnxt_re_ucontext, ib_uctx);
735687 unsigned long flag;
736688 u32 *wrptr;
737689
738
- uctx = container_of(ib_uctx, struct bnxt_re_ucontext, ib_uctx);
739690 spin_lock_irqsave(&uctx->sh_lock, flag);
740691 wrptr = (u32 *)(uctx->shpg + BNXT_RE_AVID_OFFT);
741692 *wrptr = ah->qplib_ah.id;
....@@ -743,11 +694,7 @@
743694 spin_unlock_irqrestore(&uctx->sh_lock, flag);
744695 }
745696
746
- return &ah->ib_ah;
747
-
748
-fail:
749
- kfree(ah);
750
- return ERR_PTR(rc);
697
+ return 0;
751698 }
752699
753700 int bnxt_re_modify_ah(struct ib_ah *ib_ah, struct rdma_ah_attr *ah_attr)
....@@ -796,67 +743,91 @@
796743 spin_unlock_irqrestore(&qp->scq->cq_lock, flags);
797744 }
798745
746
+static int bnxt_re_destroy_gsi_sqp(struct bnxt_re_qp *qp)
747
+{
748
+ struct bnxt_re_qp *gsi_sqp;
749
+ struct bnxt_re_ah *gsi_sah;
750
+ struct bnxt_re_dev *rdev;
751
+ int rc = 0;
752
+
753
+ rdev = qp->rdev;
754
+ gsi_sqp = rdev->gsi_ctx.gsi_sqp;
755
+ gsi_sah = rdev->gsi_ctx.gsi_sah;
756
+
757
+ ibdev_dbg(&rdev->ibdev, "Destroy the shadow AH\n");
758
+ bnxt_qplib_destroy_ah(&rdev->qplib_res,
759
+ &gsi_sah->qplib_ah,
760
+ true);
761
+ bnxt_qplib_clean_qp(&qp->qplib_qp);
762
+
763
+ ibdev_dbg(&rdev->ibdev, "Destroy the shadow QP\n");
764
+ rc = bnxt_qplib_destroy_qp(&rdev->qplib_res, &gsi_sqp->qplib_qp);
765
+ if (rc) {
766
+ ibdev_err(&rdev->ibdev, "Destroy Shadow QP failed");
767
+ goto fail;
768
+ }
769
+ bnxt_qplib_free_qp_res(&rdev->qplib_res, &gsi_sqp->qplib_qp);
770
+
771
+ /* remove from active qp list */
772
+ mutex_lock(&rdev->qp_lock);
773
+ list_del(&gsi_sqp->list);
774
+ mutex_unlock(&rdev->qp_lock);
775
+ atomic_dec(&rdev->qp_count);
776
+
777
+ kfree(rdev->gsi_ctx.sqp_tbl);
778
+ kfree(gsi_sah);
779
+ kfree(gsi_sqp);
780
+ rdev->gsi_ctx.gsi_sqp = NULL;
781
+ rdev->gsi_ctx.gsi_sah = NULL;
782
+ rdev->gsi_ctx.sqp_tbl = NULL;
783
+
784
+ return 0;
785
+fail:
786
+ return rc;
787
+}
788
+
799789 /* Queue Pairs */
800
-int bnxt_re_destroy_qp(struct ib_qp *ib_qp)
790
+int bnxt_re_destroy_qp(struct ib_qp *ib_qp, struct ib_udata *udata)
801791 {
802792 struct bnxt_re_qp *qp = container_of(ib_qp, struct bnxt_re_qp, ib_qp);
803793 struct bnxt_re_dev *rdev = qp->rdev;
804
- int rc;
805794 unsigned int flags;
795
+ int rc;
806796
807797 bnxt_qplib_flush_cqn_wq(&qp->qplib_qp);
798
+
808799 rc = bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp);
809800 if (rc) {
810
- dev_err(rdev_to_dev(rdev), "Failed to destroy HW QP");
801
+ ibdev_err(&rdev->ibdev, "Failed to destroy HW QP");
811802 return rc;
812803 }
813804
814
- flags = bnxt_re_lock_cqs(qp);
815
- bnxt_qplib_clean_qp(&qp->qplib_qp);
816
- bnxt_re_unlock_cqs(qp, flags);
817
- bnxt_qplib_free_qp_res(&rdev->qplib_res, &qp->qplib_qp);
818
-
819
- if (ib_qp->qp_type == IB_QPT_GSI && rdev->qp1_sqp) {
820
- rc = bnxt_qplib_destroy_ah(&rdev->qplib_res,
821
- &rdev->sqp_ah->qplib_ah);
822
- if (rc) {
823
- dev_err(rdev_to_dev(rdev),
824
- "Failed to destroy HW AH for shadow QP");
825
- return rc;
826
- }
827
-
805
+ if (rdma_is_kernel_res(&qp->ib_qp.res)) {
806
+ flags = bnxt_re_lock_cqs(qp);
828807 bnxt_qplib_clean_qp(&qp->qplib_qp);
829
- rc = bnxt_qplib_destroy_qp(&rdev->qplib_res,
830
- &rdev->qp1_sqp->qplib_qp);
831
- if (rc) {
832
- dev_err(rdev_to_dev(rdev),
833
- "Failed to destroy Shadow QP");
834
- return rc;
835
- }
836
- bnxt_qplib_free_qp_res(&rdev->qplib_res,
837
- &rdev->qp1_sqp->qplib_qp);
838
- mutex_lock(&rdev->qp_lock);
839
- list_del(&rdev->qp1_sqp->list);
840
- atomic_dec(&rdev->qp_count);
841
- mutex_unlock(&rdev->qp_lock);
842
-
843
- kfree(rdev->sqp_ah);
844
- kfree(rdev->qp1_sqp);
845
- rdev->qp1_sqp = NULL;
846
- rdev->sqp_ah = NULL;
808
+ bnxt_re_unlock_cqs(qp, flags);
847809 }
848810
849
- if (!IS_ERR_OR_NULL(qp->rumem))
850
- ib_umem_release(qp->rumem);
851
- if (!IS_ERR_OR_NULL(qp->sumem))
852
- ib_umem_release(qp->sumem);
811
+ bnxt_qplib_free_qp_res(&rdev->qplib_res, &qp->qplib_qp);
812
+
813
+ if (ib_qp->qp_type == IB_QPT_GSI && rdev->gsi_ctx.gsi_sqp) {
814
+ rc = bnxt_re_destroy_gsi_sqp(qp);
815
+ if (rc)
816
+ goto sh_fail;
817
+ }
853818
854819 mutex_lock(&rdev->qp_lock);
855820 list_del(&qp->list);
856
- atomic_dec(&rdev->qp_count);
857821 mutex_unlock(&rdev->qp_lock);
822
+ atomic_dec(&rdev->qp_count);
823
+
824
+ ib_umem_release(qp->rumem);
825
+ ib_umem_release(qp->sumem);
826
+
858827 kfree(qp);
859828 return 0;
829
+sh_fail:
830
+ return rc;
860831 }
861832
862833 static u8 __from_ib_qp_type(enum ib_qp_type type)
....@@ -873,45 +844,118 @@
873844 }
874845 }
875846
847
+static u16 bnxt_re_setup_rwqe_size(struct bnxt_qplib_qp *qplqp,
848
+ int rsge, int max)
849
+{
850
+ if (qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC)
851
+ rsge = max;
852
+ return bnxt_re_get_rwqe_size(rsge);
853
+}
854
+
855
+static u16 bnxt_re_get_wqe_size(int ilsize, int nsge)
856
+{
857
+ u16 wqe_size, calc_ils;
858
+
859
+ wqe_size = bnxt_re_get_swqe_size(nsge);
860
+ if (ilsize) {
861
+ calc_ils = sizeof(struct sq_send_hdr) + ilsize;
862
+ wqe_size = max_t(u16, calc_ils, wqe_size);
863
+ wqe_size = ALIGN(wqe_size, sizeof(struct sq_send_hdr));
864
+ }
865
+ return wqe_size;
866
+}
867
+
868
+static int bnxt_re_setup_swqe_size(struct bnxt_re_qp *qp,
869
+ struct ib_qp_init_attr *init_attr)
870
+{
871
+ struct bnxt_qplib_dev_attr *dev_attr;
872
+ struct bnxt_qplib_qp *qplqp;
873
+ struct bnxt_re_dev *rdev;
874
+ struct bnxt_qplib_q *sq;
875
+ int align, ilsize;
876
+
877
+ rdev = qp->rdev;
878
+ qplqp = &qp->qplib_qp;
879
+ sq = &qplqp->sq;
880
+ dev_attr = &rdev->dev_attr;
881
+
882
+ align = sizeof(struct sq_send_hdr);
883
+ ilsize = ALIGN(init_attr->cap.max_inline_data, align);
884
+
885
+ sq->wqe_size = bnxt_re_get_wqe_size(ilsize, sq->max_sge);
886
+ if (sq->wqe_size > bnxt_re_get_swqe_size(dev_attr->max_qp_sges))
887
+ return -EINVAL;
888
+ /* For gen p4 and gen p5 backward compatibility mode
889
+ * wqe size is fixed to 128 bytes
890
+ */
891
+ if (sq->wqe_size < bnxt_re_get_swqe_size(dev_attr->max_qp_sges) &&
892
+ qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC)
893
+ sq->wqe_size = bnxt_re_get_swqe_size(dev_attr->max_qp_sges);
894
+
895
+ if (init_attr->cap.max_inline_data) {
896
+ qplqp->max_inline_data = sq->wqe_size -
897
+ sizeof(struct sq_send_hdr);
898
+ init_attr->cap.max_inline_data = qplqp->max_inline_data;
899
+ if (qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC)
900
+ sq->max_sge = qplqp->max_inline_data /
901
+ sizeof(struct sq_sge);
902
+ }
903
+
904
+ return 0;
905
+}
906
+
876907 static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd,
877908 struct bnxt_re_qp *qp, struct ib_udata *udata)
878909 {
910
+ struct bnxt_qplib_qp *qplib_qp;
911
+ struct bnxt_re_ucontext *cntx;
879912 struct bnxt_re_qp_req ureq;
880
- struct bnxt_qplib_qp *qplib_qp = &qp->qplib_qp;
913
+ int bytes = 0, psn_sz;
881914 struct ib_umem *umem;
882
- int bytes = 0;
883
- struct ib_ucontext *context = pd->ib_pd.uobject->context;
884
- struct bnxt_re_ucontext *cntx = container_of(context,
885
- struct bnxt_re_ucontext,
886
- ib_uctx);
915
+ int psn_nume;
916
+
917
+ qplib_qp = &qp->qplib_qp;
918
+ cntx = rdma_udata_to_drv_context(udata, struct bnxt_re_ucontext,
919
+ ib_uctx);
887920 if (ib_copy_from_udata(&ureq, udata, sizeof(ureq)))
888921 return -EFAULT;
889922
890
- bytes = (qplib_qp->sq.max_wqe * BNXT_QPLIB_MAX_SQE_ENTRY_SIZE);
923
+ bytes = (qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size);
891924 /* Consider mapping PSN search memory only for RC QPs. */
892
- if (qplib_qp->type == CMDQ_CREATE_QP_TYPE_RC)
893
- bytes += (qplib_qp->sq.max_wqe * sizeof(struct sq_psn_search));
925
+ if (qplib_qp->type == CMDQ_CREATE_QP_TYPE_RC) {
926
+ psn_sz = bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx) ?
927
+ sizeof(struct sq_psn_search_ext) :
928
+ sizeof(struct sq_psn_search);
929
+ psn_nume = (qplib_qp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC) ?
930
+ qplib_qp->sq.max_wqe :
931
+ ((qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) /
932
+ sizeof(struct bnxt_qplib_sge));
933
+ bytes += (psn_nume * psn_sz);
934
+ }
935
+
894936 bytes = PAGE_ALIGN(bytes);
895
- umem = ib_umem_get(context, ureq.qpsva, bytes,
896
- IB_ACCESS_LOCAL_WRITE, 1);
937
+ umem = ib_umem_get(&rdev->ibdev, ureq.qpsva, bytes,
938
+ IB_ACCESS_LOCAL_WRITE);
897939 if (IS_ERR(umem))
898940 return PTR_ERR(umem);
899941
900942 qp->sumem = umem;
901
- qplib_qp->sq.sglist = umem->sg_head.sgl;
902
- qplib_qp->sq.nmap = umem->nmap;
943
+ qplib_qp->sq.sg_info.umem = umem;
944
+ qplib_qp->sq.sg_info.pgsize = PAGE_SIZE;
945
+ qplib_qp->sq.sg_info.pgshft = PAGE_SHIFT;
903946 qplib_qp->qp_handle = ureq.qp_handle;
904947
905948 if (!qp->qplib_qp.srq) {
906
- bytes = (qplib_qp->rq.max_wqe * BNXT_QPLIB_MAX_RQE_ENTRY_SIZE);
949
+ bytes = (qplib_qp->rq.max_wqe * qplib_qp->rq.wqe_size);
907950 bytes = PAGE_ALIGN(bytes);
908
- umem = ib_umem_get(context, ureq.qprva, bytes,
909
- IB_ACCESS_LOCAL_WRITE, 1);
951
+ umem = ib_umem_get(&rdev->ibdev, ureq.qprva, bytes,
952
+ IB_ACCESS_LOCAL_WRITE);
910953 if (IS_ERR(umem))
911954 goto rqfail;
912955 qp->rumem = umem;
913
- qplib_qp->rq.sglist = umem->sg_head.sgl;
914
- qplib_qp->rq.nmap = umem->nmap;
956
+ qplib_qp->rq.sg_info.umem = umem;
957
+ qplib_qp->rq.sg_info.pgsize = PAGE_SIZE;
958
+ qplib_qp->rq.sg_info.pgshft = PAGE_SHIFT;
915959 }
916960
917961 qplib_qp->dpi = &cntx->dpi;
....@@ -919,8 +963,7 @@
919963 rqfail:
920964 ib_umem_release(qp->sumem);
921965 qp->sumem = NULL;
922
- qplib_qp->sq.sglist = NULL;
923
- qplib_qp->sq.nmap = 0;
966
+ memset(&qplib_qp->sq.sg_info, 0, sizeof(qplib_qp->sq.sg_info));
924967
925968 return PTR_ERR(umem);
926969 }
....@@ -958,10 +1001,10 @@
9581001 /* Have DMAC same as SMAC */
9591002 ether_addr_copy(ah->qplib_ah.dmac, rdev->netdev->dev_addr);
9601003
961
- rc = bnxt_qplib_create_ah(&rdev->qplib_res, &ah->qplib_ah);
1004
+ rc = bnxt_qplib_create_ah(&rdev->qplib_res, &ah->qplib_ah, false);
9621005 if (rc) {
963
- dev_err(rdev_to_dev(rdev),
964
- "Failed to allocate HW AH for Shadow QP");
1006
+ ibdev_err(&rdev->ibdev,
1007
+ "Failed to allocate HW AH for Shadow QP");
9651008 goto fail;
9661009 }
9671010
....@@ -998,18 +1041,24 @@
9981041 qp->qplib_qp.sig_type = true;
9991042
10001043 /* Shadow QP SQ depth should be same as QP1 RQ depth */
1044
+ qp->qplib_qp.sq.wqe_size = bnxt_re_get_wqe_size(0, 6);
10011045 qp->qplib_qp.sq.max_wqe = qp1_qp->rq.max_wqe;
10021046 qp->qplib_qp.sq.max_sge = 2;
10031047 /* Q full delta can be 1 since it is internal QP */
10041048 qp->qplib_qp.sq.q_full_delta = 1;
1049
+ qp->qplib_qp.sq.sg_info.pgsize = PAGE_SIZE;
1050
+ qp->qplib_qp.sq.sg_info.pgshft = PAGE_SHIFT;
10051051
10061052 qp->qplib_qp.scq = qp1_qp->scq;
10071053 qp->qplib_qp.rcq = qp1_qp->rcq;
10081054
1055
+ qp->qplib_qp.rq.wqe_size = bnxt_re_get_rwqe_size(6);
10091056 qp->qplib_qp.rq.max_wqe = qp1_qp->rq.max_wqe;
10101057 qp->qplib_qp.rq.max_sge = qp1_qp->rq.max_sge;
10111058 /* Q full delta can be 1 since it is internal QP */
10121059 qp->qplib_qp.rq.q_full_delta = 1;
1060
+ qp->qplib_qp.rq.sg_info.pgsize = PAGE_SIZE;
1061
+ qp->qplib_qp.rq.sg_info.pgshft = PAGE_SHIFT;
10131062
10141063 qp->qplib_qp.mtu = qp1_qp->mtu;
10151064
....@@ -1020,8 +1069,6 @@
10201069 rc = bnxt_qplib_create_qp(qp1_res, &qp->qplib_qp);
10211070 if (rc)
10221071 goto fail;
1023
-
1024
- rdev->sqp_id = qp->qplib_qp.id;
10251072
10261073 spin_lock_init(&qp->sq_lock);
10271074 INIT_LIST_HEAD(&qp->list);
....@@ -1035,6 +1082,336 @@
10351082 return NULL;
10361083 }
10371084
1085
+static int bnxt_re_init_rq_attr(struct bnxt_re_qp *qp,
1086
+ struct ib_qp_init_attr *init_attr)
1087
+{
1088
+ struct bnxt_qplib_dev_attr *dev_attr;
1089
+ struct bnxt_qplib_qp *qplqp;
1090
+ struct bnxt_re_dev *rdev;
1091
+ struct bnxt_qplib_q *rq;
1092
+ int entries;
1093
+
1094
+ rdev = qp->rdev;
1095
+ qplqp = &qp->qplib_qp;
1096
+ rq = &qplqp->rq;
1097
+ dev_attr = &rdev->dev_attr;
1098
+
1099
+ if (init_attr->srq) {
1100
+ struct bnxt_re_srq *srq;
1101
+
1102
+ srq = container_of(init_attr->srq, struct bnxt_re_srq, ib_srq);
1103
+ if (!srq) {
1104
+ ibdev_err(&rdev->ibdev, "SRQ not found");
1105
+ return -EINVAL;
1106
+ }
1107
+ qplqp->srq = &srq->qplib_srq;
1108
+ rq->max_wqe = 0;
1109
+ } else {
1110
+ rq->max_sge = init_attr->cap.max_recv_sge;
1111
+ if (rq->max_sge > dev_attr->max_qp_sges)
1112
+ rq->max_sge = dev_attr->max_qp_sges;
1113
+ init_attr->cap.max_recv_sge = rq->max_sge;
1114
+ rq->wqe_size = bnxt_re_setup_rwqe_size(qplqp, rq->max_sge,
1115
+ dev_attr->max_qp_sges);
1116
+ /* Allocate 1 more than what's provided so posting max doesn't
1117
+ * mean empty.
1118
+ */
1119
+ entries = roundup_pow_of_two(init_attr->cap.max_recv_wr + 1);
1120
+ rq->max_wqe = min_t(u32, entries, dev_attr->max_qp_wqes + 1);
1121
+ rq->q_full_delta = 0;
1122
+ rq->sg_info.pgsize = PAGE_SIZE;
1123
+ rq->sg_info.pgshft = PAGE_SHIFT;
1124
+ }
1125
+
1126
+ return 0;
1127
+}
1128
+
1129
+static void bnxt_re_adjust_gsi_rq_attr(struct bnxt_re_qp *qp)
1130
+{
1131
+ struct bnxt_qplib_dev_attr *dev_attr;
1132
+ struct bnxt_qplib_qp *qplqp;
1133
+ struct bnxt_re_dev *rdev;
1134
+
1135
+ rdev = qp->rdev;
1136
+ qplqp = &qp->qplib_qp;
1137
+ dev_attr = &rdev->dev_attr;
1138
+
1139
+ if (!bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx)) {
1140
+ qplqp->rq.max_sge = dev_attr->max_qp_sges;
1141
+ if (qplqp->rq.max_sge > dev_attr->max_qp_sges)
1142
+ qplqp->rq.max_sge = dev_attr->max_qp_sges;
1143
+ qplqp->rq.max_sge = 6;
1144
+ }
1145
+}
1146
+
1147
+static int bnxt_re_init_sq_attr(struct bnxt_re_qp *qp,
1148
+ struct ib_qp_init_attr *init_attr,
1149
+ struct ib_udata *udata)
1150
+{
1151
+ struct bnxt_qplib_dev_attr *dev_attr;
1152
+ struct bnxt_qplib_qp *qplqp;
1153
+ struct bnxt_re_dev *rdev;
1154
+ struct bnxt_qplib_q *sq;
1155
+ int entries;
1156
+ int diff;
1157
+ int rc;
1158
+
1159
+ rdev = qp->rdev;
1160
+ qplqp = &qp->qplib_qp;
1161
+ sq = &qplqp->sq;
1162
+ dev_attr = &rdev->dev_attr;
1163
+
1164
+ sq->max_sge = init_attr->cap.max_send_sge;
1165
+ if (sq->max_sge > dev_attr->max_qp_sges) {
1166
+ sq->max_sge = dev_attr->max_qp_sges;
1167
+ init_attr->cap.max_send_sge = sq->max_sge;
1168
+ }
1169
+
1170
+ rc = bnxt_re_setup_swqe_size(qp, init_attr);
1171
+ if (rc)
1172
+ return rc;
1173
+
1174
+ entries = init_attr->cap.max_send_wr;
1175
+ /* Allocate 128 + 1 more than what's provided */
1176
+ diff = (qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_VARIABLE) ?
1177
+ 0 : BNXT_QPLIB_RESERVED_QP_WRS;
1178
+ entries = roundup_pow_of_two(entries + diff + 1);
1179
+ sq->max_wqe = min_t(u32, entries, dev_attr->max_qp_wqes + diff + 1);
1180
+ sq->q_full_delta = diff + 1;
1181
+ /*
1182
+ * Reserving one slot for Phantom WQE. Application can
1183
+ * post one extra entry in this case. But allowing this to avoid
1184
+ * unexpected Queue full condition
1185
+ */
1186
+ qplqp->sq.q_full_delta -= 1;
1187
+ qplqp->sq.sg_info.pgsize = PAGE_SIZE;
1188
+ qplqp->sq.sg_info.pgshft = PAGE_SHIFT;
1189
+
1190
+ return 0;
1191
+}
1192
+
1193
+static void bnxt_re_adjust_gsi_sq_attr(struct bnxt_re_qp *qp,
1194
+ struct ib_qp_init_attr *init_attr)
1195
+{
1196
+ struct bnxt_qplib_dev_attr *dev_attr;
1197
+ struct bnxt_qplib_qp *qplqp;
1198
+ struct bnxt_re_dev *rdev;
1199
+ int entries;
1200
+
1201
+ rdev = qp->rdev;
1202
+ qplqp = &qp->qplib_qp;
1203
+ dev_attr = &rdev->dev_attr;
1204
+
1205
+ if (!bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx)) {
1206
+ entries = roundup_pow_of_two(init_attr->cap.max_send_wr + 1);
1207
+ qplqp->sq.max_wqe = min_t(u32, entries,
1208
+ dev_attr->max_qp_wqes + 1);
1209
+ qplqp->sq.q_full_delta = qplqp->sq.max_wqe -
1210
+ init_attr->cap.max_send_wr;
1211
+ qplqp->sq.max_sge++; /* Need one extra sge to put UD header */
1212
+ if (qplqp->sq.max_sge > dev_attr->max_qp_sges)
1213
+ qplqp->sq.max_sge = dev_attr->max_qp_sges;
1214
+ }
1215
+}
1216
+
1217
+static int bnxt_re_init_qp_type(struct bnxt_re_dev *rdev,
1218
+ struct ib_qp_init_attr *init_attr)
1219
+{
1220
+ struct bnxt_qplib_chip_ctx *chip_ctx;
1221
+ int qptype;
1222
+
1223
+ chip_ctx = rdev->chip_ctx;
1224
+
1225
+ qptype = __from_ib_qp_type(init_attr->qp_type);
1226
+ if (qptype == IB_QPT_MAX) {
1227
+ ibdev_err(&rdev->ibdev, "QP type 0x%x not supported", qptype);
1228
+ qptype = -EOPNOTSUPP;
1229
+ goto out;
1230
+ }
1231
+
1232
+ if (bnxt_qplib_is_chip_gen_p5(chip_ctx) &&
1233
+ init_attr->qp_type == IB_QPT_GSI)
1234
+ qptype = CMDQ_CREATE_QP_TYPE_GSI;
1235
+out:
1236
+ return qptype;
1237
+}
1238
+
1239
+static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,
1240
+ struct ib_qp_init_attr *init_attr,
1241
+ struct ib_udata *udata)
1242
+{
1243
+ struct bnxt_qplib_dev_attr *dev_attr;
1244
+ struct bnxt_qplib_qp *qplqp;
1245
+ struct bnxt_re_dev *rdev;
1246
+ struct bnxt_re_cq *cq;
1247
+ int rc = 0, qptype;
1248
+
1249
+ rdev = qp->rdev;
1250
+ qplqp = &qp->qplib_qp;
1251
+ dev_attr = &rdev->dev_attr;
1252
+
1253
+ /* Setup misc params */
1254
+ ether_addr_copy(qplqp->smac, rdev->netdev->dev_addr);
1255
+ qplqp->pd = &pd->qplib_pd;
1256
+ qplqp->qp_handle = (u64)qplqp;
1257
+ qplqp->max_inline_data = init_attr->cap.max_inline_data;
1258
+ qplqp->sig_type = ((init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) ?
1259
+ true : false);
1260
+ qptype = bnxt_re_init_qp_type(rdev, init_attr);
1261
+ if (qptype < 0) {
1262
+ rc = qptype;
1263
+ goto out;
1264
+ }
1265
+ qplqp->type = (u8)qptype;
1266
+ qplqp->wqe_mode = rdev->chip_ctx->modes.wqe_mode;
1267
+
1268
+ if (init_attr->qp_type == IB_QPT_RC) {
1269
+ qplqp->max_rd_atomic = dev_attr->max_qp_rd_atom;
1270
+ qplqp->max_dest_rd_atomic = dev_attr->max_qp_init_rd_atom;
1271
+ }
1272
+ qplqp->mtu = ib_mtu_enum_to_int(iboe_get_mtu(rdev->netdev->mtu));
1273
+ qplqp->dpi = &rdev->dpi_privileged; /* Doorbell page */
1274
+ if (init_attr->create_flags)
1275
+ ibdev_dbg(&rdev->ibdev,
1276
+ "QP create flags 0x%x not supported",
1277
+ init_attr->create_flags);
1278
+
1279
+ /* Setup CQs */
1280
+ if (init_attr->send_cq) {
1281
+ cq = container_of(init_attr->send_cq, struct bnxt_re_cq, ib_cq);
1282
+ if (!cq) {
1283
+ ibdev_err(&rdev->ibdev, "Send CQ not found");
1284
+ rc = -EINVAL;
1285
+ goto out;
1286
+ }
1287
+ qplqp->scq = &cq->qplib_cq;
1288
+ qp->scq = cq;
1289
+ }
1290
+
1291
+ if (init_attr->recv_cq) {
1292
+ cq = container_of(init_attr->recv_cq, struct bnxt_re_cq, ib_cq);
1293
+ if (!cq) {
1294
+ ibdev_err(&rdev->ibdev, "Receive CQ not found");
1295
+ rc = -EINVAL;
1296
+ goto out;
1297
+ }
1298
+ qplqp->rcq = &cq->qplib_cq;
1299
+ qp->rcq = cq;
1300
+ }
1301
+
1302
+ /* Setup RQ/SRQ */
1303
+ rc = bnxt_re_init_rq_attr(qp, init_attr);
1304
+ if (rc)
1305
+ goto out;
1306
+ if (init_attr->qp_type == IB_QPT_GSI)
1307
+ bnxt_re_adjust_gsi_rq_attr(qp);
1308
+
1309
+ /* Setup SQ */
1310
+ rc = bnxt_re_init_sq_attr(qp, init_attr, udata);
1311
+ if (rc)
1312
+ goto out;
1313
+ if (init_attr->qp_type == IB_QPT_GSI)
1314
+ bnxt_re_adjust_gsi_sq_attr(qp, init_attr);
1315
+
1316
+ if (udata) /* This will update DPI and qp_handle */
1317
+ rc = bnxt_re_init_user_qp(rdev, pd, qp, udata);
1318
+out:
1319
+ return rc;
1320
+}
1321
+
1322
+static int bnxt_re_create_shadow_gsi(struct bnxt_re_qp *qp,
1323
+ struct bnxt_re_pd *pd)
1324
+{
1325
+ struct bnxt_re_sqp_entries *sqp_tbl = NULL;
1326
+ struct bnxt_re_dev *rdev;
1327
+ struct bnxt_re_qp *sqp;
1328
+ struct bnxt_re_ah *sah;
1329
+ int rc = 0;
1330
+
1331
+ rdev = qp->rdev;
1332
+ /* Create a shadow QP to handle the QP1 traffic */
1333
+ sqp_tbl = kzalloc(sizeof(*sqp_tbl) * BNXT_RE_MAX_GSI_SQP_ENTRIES,
1334
+ GFP_KERNEL);
1335
+ if (!sqp_tbl)
1336
+ return -ENOMEM;
1337
+ rdev->gsi_ctx.sqp_tbl = sqp_tbl;
1338
+
1339
+ sqp = bnxt_re_create_shadow_qp(pd, &rdev->qplib_res, &qp->qplib_qp);
1340
+ if (!sqp) {
1341
+ rc = -ENODEV;
1342
+ ibdev_err(&rdev->ibdev, "Failed to create Shadow QP for QP1");
1343
+ goto out;
1344
+ }
1345
+ rdev->gsi_ctx.gsi_sqp = sqp;
1346
+
1347
+ sqp->rcq = qp->rcq;
1348
+ sqp->scq = qp->scq;
1349
+ sah = bnxt_re_create_shadow_qp_ah(pd, &rdev->qplib_res,
1350
+ &qp->qplib_qp);
1351
+ if (!sah) {
1352
+ bnxt_qplib_destroy_qp(&rdev->qplib_res,
1353
+ &sqp->qplib_qp);
1354
+ rc = -ENODEV;
1355
+ ibdev_err(&rdev->ibdev,
1356
+ "Failed to create AH entry for ShadowQP");
1357
+ goto out;
1358
+ }
1359
+ rdev->gsi_ctx.gsi_sah = sah;
1360
+
1361
+ return 0;
1362
+out:
1363
+ kfree(sqp_tbl);
1364
+ return rc;
1365
+}
1366
+
1367
+static int bnxt_re_create_gsi_qp(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,
1368
+ struct ib_qp_init_attr *init_attr)
1369
+{
1370
+ struct bnxt_re_dev *rdev;
1371
+ struct bnxt_qplib_qp *qplqp;
1372
+ int rc = 0;
1373
+
1374
+ rdev = qp->rdev;
1375
+ qplqp = &qp->qplib_qp;
1376
+
1377
+ qplqp->rq_hdr_buf_size = BNXT_QPLIB_MAX_QP1_RQ_HDR_SIZE_V2;
1378
+ qplqp->sq_hdr_buf_size = BNXT_QPLIB_MAX_QP1_SQ_HDR_SIZE_V2;
1379
+
1380
+ rc = bnxt_qplib_create_qp1(&rdev->qplib_res, qplqp);
1381
+ if (rc) {
1382
+ ibdev_err(&rdev->ibdev, "create HW QP1 failed!");
1383
+ goto out;
1384
+ }
1385
+
1386
+ rc = bnxt_re_create_shadow_gsi(qp, pd);
1387
+out:
1388
+ return rc;
1389
+}
1390
+
1391
+static bool bnxt_re_test_qp_limits(struct bnxt_re_dev *rdev,
1392
+ struct ib_qp_init_attr *init_attr,
1393
+ struct bnxt_qplib_dev_attr *dev_attr)
1394
+{
1395
+ bool rc = true;
1396
+
1397
+ if (init_attr->cap.max_send_wr > dev_attr->max_qp_wqes ||
1398
+ init_attr->cap.max_recv_wr > dev_attr->max_qp_wqes ||
1399
+ init_attr->cap.max_send_sge > dev_attr->max_qp_sges ||
1400
+ init_attr->cap.max_recv_sge > dev_attr->max_qp_sges ||
1401
+ init_attr->cap.max_inline_data > dev_attr->max_inline_data) {
1402
+ ibdev_err(&rdev->ibdev,
1403
+ "Create QP failed - max exceeded! 0x%x/0x%x 0x%x/0x%x 0x%x/0x%x 0x%x/0x%x 0x%x/0x%x",
1404
+ init_attr->cap.max_send_wr, dev_attr->max_qp_wqes,
1405
+ init_attr->cap.max_recv_wr, dev_attr->max_qp_wqes,
1406
+ init_attr->cap.max_send_sge, dev_attr->max_qp_sges,
1407
+ init_attr->cap.max_recv_sge, dev_attr->max_qp_sges,
1408
+ init_attr->cap.max_inline_data,
1409
+ dev_attr->max_inline_data);
1410
+ rc = false;
1411
+ }
1412
+ return rc;
1413
+}
1414
+
10381415 struct ib_qp *bnxt_re_create_qp(struct ib_pd *ib_pd,
10391416 struct ib_qp_init_attr *qp_init_attr,
10401417 struct ib_udata *udata)
....@@ -1043,204 +1420,70 @@
10431420 struct bnxt_re_dev *rdev = pd->rdev;
10441421 struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
10451422 struct bnxt_re_qp *qp;
1046
- struct bnxt_re_cq *cq;
1047
- struct bnxt_re_srq *srq;
1048
- int rc, entries;
1423
+ int rc;
10491424
1050
- if ((qp_init_attr->cap.max_send_wr > dev_attr->max_qp_wqes) ||
1051
- (qp_init_attr->cap.max_recv_wr > dev_attr->max_qp_wqes) ||
1052
- (qp_init_attr->cap.max_send_sge > dev_attr->max_qp_sges) ||
1053
- (qp_init_attr->cap.max_recv_sge > dev_attr->max_qp_sges) ||
1054
- (qp_init_attr->cap.max_inline_data > dev_attr->max_inline_data))
1055
- return ERR_PTR(-EINVAL);
1425
+ rc = bnxt_re_test_qp_limits(rdev, qp_init_attr, dev_attr);
1426
+ if (!rc) {
1427
+ rc = -EINVAL;
1428
+ goto exit;
1429
+ }
10561430
10571431 qp = kzalloc(sizeof(*qp), GFP_KERNEL);
1058
- if (!qp)
1059
- return ERR_PTR(-ENOMEM);
1060
-
1432
+ if (!qp) {
1433
+ rc = -ENOMEM;
1434
+ goto exit;
1435
+ }
10611436 qp->rdev = rdev;
1062
- ether_addr_copy(qp->qplib_qp.smac, rdev->netdev->dev_addr);
1063
- qp->qplib_qp.pd = &pd->qplib_pd;
1064
- qp->qplib_qp.qp_handle = (u64)(unsigned long)(&qp->qplib_qp);
1065
- qp->qplib_qp.type = __from_ib_qp_type(qp_init_attr->qp_type);
1066
- if (qp->qplib_qp.type == IB_QPT_MAX) {
1067
- dev_err(rdev_to_dev(rdev), "QP type 0x%x not supported",
1068
- qp->qplib_qp.type);
1069
- rc = -EINVAL;
1437
+ rc = bnxt_re_init_qp_attr(qp, pd, qp_init_attr, udata);
1438
+ if (rc)
10701439 goto fail;
1071
- }
1072
- qp->qplib_qp.max_inline_data = qp_init_attr->cap.max_inline_data;
1073
- qp->qplib_qp.sig_type = ((qp_init_attr->sq_sig_type ==
1074
- IB_SIGNAL_ALL_WR) ? true : false);
10751440
1076
- qp->qplib_qp.sq.max_sge = qp_init_attr->cap.max_send_sge;
1077
- if (qp->qplib_qp.sq.max_sge > dev_attr->max_qp_sges)
1078
- qp->qplib_qp.sq.max_sge = dev_attr->max_qp_sges;
1079
-
1080
- if (qp_init_attr->send_cq) {
1081
- cq = container_of(qp_init_attr->send_cq, struct bnxt_re_cq,
1082
- ib_cq);
1083
- if (!cq) {
1084
- dev_err(rdev_to_dev(rdev), "Send CQ not found");
1085
- rc = -EINVAL;
1086
- goto fail;
1087
- }
1088
- qp->qplib_qp.scq = &cq->qplib_cq;
1089
- qp->scq = cq;
1090
- }
1091
-
1092
- if (qp_init_attr->recv_cq) {
1093
- cq = container_of(qp_init_attr->recv_cq, struct bnxt_re_cq,
1094
- ib_cq);
1095
- if (!cq) {
1096
- dev_err(rdev_to_dev(rdev), "Receive CQ not found");
1097
- rc = -EINVAL;
1098
- goto fail;
1099
- }
1100
- qp->qplib_qp.rcq = &cq->qplib_cq;
1101
- qp->rcq = cq;
1102
- }
1103
-
1104
- if (qp_init_attr->srq) {
1105
- srq = container_of(qp_init_attr->srq, struct bnxt_re_srq,
1106
- ib_srq);
1107
- if (!srq) {
1108
- dev_err(rdev_to_dev(rdev), "SRQ not found");
1109
- rc = -EINVAL;
1110
- goto fail;
1111
- }
1112
- qp->qplib_qp.srq = &srq->qplib_srq;
1113
- qp->qplib_qp.rq.max_wqe = 0;
1114
- } else {
1115
- /* Allocate 1 more than what's provided so posting max doesn't
1116
- * mean empty
1117
- */
1118
- entries = roundup_pow_of_two(qp_init_attr->cap.max_recv_wr + 1);
1119
- qp->qplib_qp.rq.max_wqe = min_t(u32, entries,
1120
- dev_attr->max_qp_wqes + 1);
1121
-
1122
- qp->qplib_qp.rq.q_full_delta = qp->qplib_qp.rq.max_wqe -
1123
- qp_init_attr->cap.max_recv_wr;
1124
-
1125
- qp->qplib_qp.rq.max_sge = qp_init_attr->cap.max_recv_sge;
1126
- if (qp->qplib_qp.rq.max_sge > dev_attr->max_qp_sges)
1127
- qp->qplib_qp.rq.max_sge = dev_attr->max_qp_sges;
1128
- }
1129
-
1130
- qp->qplib_qp.mtu = ib_mtu_enum_to_int(iboe_get_mtu(rdev->netdev->mtu));
1131
-
1132
- if (qp_init_attr->qp_type == IB_QPT_GSI) {
1133
- /* Allocate 1 more than what's provided */
1134
- entries = roundup_pow_of_two(qp_init_attr->cap.max_send_wr + 1);
1135
- qp->qplib_qp.sq.max_wqe = min_t(u32, entries,
1136
- dev_attr->max_qp_wqes + 1);
1137
- qp->qplib_qp.sq.q_full_delta = qp->qplib_qp.sq.max_wqe -
1138
- qp_init_attr->cap.max_send_wr;
1139
- qp->qplib_qp.rq.max_sge = dev_attr->max_qp_sges;
1140
- if (qp->qplib_qp.rq.max_sge > dev_attr->max_qp_sges)
1141
- qp->qplib_qp.rq.max_sge = dev_attr->max_qp_sges;
1142
- qp->qplib_qp.sq.max_sge++;
1143
- if (qp->qplib_qp.sq.max_sge > dev_attr->max_qp_sges)
1144
- qp->qplib_qp.sq.max_sge = dev_attr->max_qp_sges;
1145
-
1146
- qp->qplib_qp.rq_hdr_buf_size =
1147
- BNXT_QPLIB_MAX_QP1_RQ_HDR_SIZE_V2;
1148
-
1149
- qp->qplib_qp.sq_hdr_buf_size =
1150
- BNXT_QPLIB_MAX_QP1_SQ_HDR_SIZE_V2;
1151
- qp->qplib_qp.dpi = &rdev->dpi_privileged;
1152
- rc = bnxt_qplib_create_qp1(&rdev->qplib_res, &qp->qplib_qp);
1153
- if (rc) {
1154
- dev_err(rdev_to_dev(rdev), "Failed to create HW QP1");
1155
- goto fail;
1156
- }
1157
- /* Create a shadow QP to handle the QP1 traffic */
1158
- rdev->qp1_sqp = bnxt_re_create_shadow_qp(pd, &rdev->qplib_res,
1159
- &qp->qplib_qp);
1160
- if (!rdev->qp1_sqp) {
1161
- rc = -EINVAL;
1162
- dev_err(rdev_to_dev(rdev),
1163
- "Failed to create Shadow QP for QP1");
1441
+ if (qp_init_attr->qp_type == IB_QPT_GSI &&
1442
+ !(bnxt_qplib_is_chip_gen_p5(rdev->chip_ctx))) {
1443
+ rc = bnxt_re_create_gsi_qp(qp, pd, qp_init_attr);
1444
+ if (rc == -ENODEV)
11641445 goto qp_destroy;
1165
- }
1166
- rdev->sqp_ah = bnxt_re_create_shadow_qp_ah(pd, &rdev->qplib_res,
1167
- &qp->qplib_qp);
1168
- if (!rdev->sqp_ah) {
1169
- bnxt_qplib_destroy_qp(&rdev->qplib_res,
1170
- &rdev->qp1_sqp->qplib_qp);
1171
- rc = -EINVAL;
1172
- dev_err(rdev_to_dev(rdev),
1173
- "Failed to create AH entry for ShadowQP");
1174
- goto qp_destroy;
1175
- }
1176
-
1446
+ if (rc)
1447
+ goto fail;
11771448 } else {
1178
- /* Allocate 128 + 1 more than what's provided */
1179
- entries = roundup_pow_of_two(qp_init_attr->cap.max_send_wr +
1180
- BNXT_QPLIB_RESERVED_QP_WRS + 1);
1181
- qp->qplib_qp.sq.max_wqe = min_t(u32, entries,
1182
- dev_attr->max_qp_wqes +
1183
- BNXT_QPLIB_RESERVED_QP_WRS + 1);
1184
- qp->qplib_qp.sq.q_full_delta = BNXT_QPLIB_RESERVED_QP_WRS + 1;
1185
-
1186
- /*
1187
- * Reserving one slot for Phantom WQE. Application can
1188
- * post one extra entry in this case. But allowing this to avoid
1189
- * unexpected Queue full condition
1190
- */
1191
-
1192
- qp->qplib_qp.sq.q_full_delta -= 1;
1193
-
1194
- qp->qplib_qp.max_rd_atomic = dev_attr->max_qp_rd_atom;
1195
- qp->qplib_qp.max_dest_rd_atomic = dev_attr->max_qp_init_rd_atom;
1196
- if (udata) {
1197
- rc = bnxt_re_init_user_qp(rdev, pd, qp, udata);
1198
- if (rc)
1199
- goto fail;
1200
- } else {
1201
- qp->qplib_qp.dpi = &rdev->dpi_privileged;
1202
- }
1203
-
12041449 rc = bnxt_qplib_create_qp(&rdev->qplib_res, &qp->qplib_qp);
12051450 if (rc) {
1206
- dev_err(rdev_to_dev(rdev), "Failed to create HW QP");
1451
+ ibdev_err(&rdev->ibdev, "Failed to create HW QP");
12071452 goto free_umem;
1453
+ }
1454
+ if (udata) {
1455
+ struct bnxt_re_qp_resp resp;
1456
+
1457
+ resp.qpid = qp->qplib_qp.id;
1458
+ resp.rsvd = 0;
1459
+ rc = ib_copy_to_udata(udata, &resp, sizeof(resp));
1460
+ if (rc) {
1461
+ ibdev_err(&rdev->ibdev, "Failed to copy QP udata");
1462
+ goto qp_destroy;
1463
+ }
12081464 }
12091465 }
12101466
12111467 qp->ib_qp.qp_num = qp->qplib_qp.id;
1468
+ if (qp_init_attr->qp_type == IB_QPT_GSI)
1469
+ rdev->gsi_ctx.gsi_qp = qp;
12121470 spin_lock_init(&qp->sq_lock);
12131471 spin_lock_init(&qp->rq_lock);
1214
-
1215
- if (udata) {
1216
- struct bnxt_re_qp_resp resp;
1217
-
1218
- resp.qpid = qp->ib_qp.qp_num;
1219
- resp.rsvd = 0;
1220
- rc = ib_copy_to_udata(udata, &resp, sizeof(resp));
1221
- if (rc) {
1222
- dev_err(rdev_to_dev(rdev), "Failed to copy QP udata");
1223
- goto qp_destroy;
1224
- }
1225
- }
12261472 INIT_LIST_HEAD(&qp->list);
12271473 mutex_lock(&rdev->qp_lock);
12281474 list_add_tail(&qp->list, &rdev->qp_list);
1229
- atomic_inc(&rdev->qp_count);
12301475 mutex_unlock(&rdev->qp_lock);
1476
+ atomic_inc(&rdev->qp_count);
12311477
12321478 return &qp->ib_qp;
12331479 qp_destroy:
12341480 bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp);
12351481 free_umem:
1236
- if (udata) {
1237
- if (qp->rumem)
1238
- ib_umem_release(qp->rumem);
1239
- if (qp->sumem)
1240
- ib_umem_release(qp->sumem);
1241
- }
1482
+ ib_umem_release(qp->rumem);
1483
+ ib_umem_release(qp->sumem);
12421484 fail:
12431485 kfree(qp);
1486
+exit:
12441487 return ERR_PTR(rc);
12451488 }
12461489
....@@ -1323,26 +1566,18 @@
13231566 }
13241567
13251568 /* Shared Receive Queues */
1326
-int bnxt_re_destroy_srq(struct ib_srq *ib_srq)
1569
+int bnxt_re_destroy_srq(struct ib_srq *ib_srq, struct ib_udata *udata)
13271570 {
13281571 struct bnxt_re_srq *srq = container_of(ib_srq, struct bnxt_re_srq,
13291572 ib_srq);
13301573 struct bnxt_re_dev *rdev = srq->rdev;
13311574 struct bnxt_qplib_srq *qplib_srq = &srq->qplib_srq;
13321575 struct bnxt_qplib_nq *nq = NULL;
1333
- int rc;
13341576
13351577 if (qplib_srq->cq)
13361578 nq = qplib_srq->cq->nq;
1337
- rc = bnxt_qplib_destroy_srq(&rdev->qplib_res, qplib_srq);
1338
- if (rc) {
1339
- dev_err(rdev_to_dev(rdev), "Destroy HW SRQ failed!");
1340
- return rc;
1341
- }
1342
-
1343
- if (srq->umem)
1344
- ib_umem_release(srq->umem);
1345
- kfree(srq);
1579
+ bnxt_qplib_destroy_srq(&rdev->qplib_res, qplib_srq);
1580
+ ib_umem_release(srq->umem);
13461581 atomic_dec(&rdev->srq_count);
13471582 if (nq)
13481583 nq->budget--;
....@@ -1358,42 +1593,49 @@
13581593 struct bnxt_qplib_srq *qplib_srq = &srq->qplib_srq;
13591594 struct ib_umem *umem;
13601595 int bytes = 0;
1361
- struct ib_ucontext *context = pd->ib_pd.uobject->context;
1362
- struct bnxt_re_ucontext *cntx = container_of(context,
1363
- struct bnxt_re_ucontext,
1364
- ib_uctx);
1596
+ struct bnxt_re_ucontext *cntx = rdma_udata_to_drv_context(
1597
+ udata, struct bnxt_re_ucontext, ib_uctx);
1598
+
13651599 if (ib_copy_from_udata(&ureq, udata, sizeof(ureq)))
13661600 return -EFAULT;
13671601
1368
- bytes = (qplib_srq->max_wqe * BNXT_QPLIB_MAX_RQE_ENTRY_SIZE);
1602
+ bytes = (qplib_srq->max_wqe * qplib_srq->wqe_size);
13691603 bytes = PAGE_ALIGN(bytes);
1370
- umem = ib_umem_get(context, ureq.srqva, bytes,
1371
- IB_ACCESS_LOCAL_WRITE, 1);
1604
+ umem = ib_umem_get(&rdev->ibdev, ureq.srqva, bytes,
1605
+ IB_ACCESS_LOCAL_WRITE);
13721606 if (IS_ERR(umem))
13731607 return PTR_ERR(umem);
13741608
13751609 srq->umem = umem;
1376
- qplib_srq->nmap = umem->nmap;
1377
- qplib_srq->sglist = umem->sg_head.sgl;
1610
+ qplib_srq->sg_info.umem = umem;
1611
+ qplib_srq->sg_info.pgsize = PAGE_SIZE;
1612
+ qplib_srq->sg_info.pgshft = PAGE_SHIFT;
13781613 qplib_srq->srq_handle = ureq.srq_handle;
13791614 qplib_srq->dpi = &cntx->dpi;
13801615
13811616 return 0;
13821617 }
13831618
1384
-struct ib_srq *bnxt_re_create_srq(struct ib_pd *ib_pd,
1385
- struct ib_srq_init_attr *srq_init_attr,
1386
- struct ib_udata *udata)
1619
+int bnxt_re_create_srq(struct ib_srq *ib_srq,
1620
+ struct ib_srq_init_attr *srq_init_attr,
1621
+ struct ib_udata *udata)
13871622 {
1388
- struct bnxt_re_pd *pd = container_of(ib_pd, struct bnxt_re_pd, ib_pd);
1389
- struct bnxt_re_dev *rdev = pd->rdev;
1390
- struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
1391
- struct bnxt_re_srq *srq;
1623
+ struct bnxt_qplib_dev_attr *dev_attr;
13921624 struct bnxt_qplib_nq *nq = NULL;
1625
+ struct bnxt_re_dev *rdev;
1626
+ struct bnxt_re_srq *srq;
1627
+ struct bnxt_re_pd *pd;
1628
+ struct ib_pd *ib_pd;
13931629 int rc, entries;
13941630
1631
+ ib_pd = ib_srq->pd;
1632
+ pd = container_of(ib_pd, struct bnxt_re_pd, ib_pd);
1633
+ rdev = pd->rdev;
1634
+ dev_attr = &rdev->dev_attr;
1635
+ srq = container_of(ib_srq, struct bnxt_re_srq, ib_srq);
1636
+
13951637 if (srq_init_attr->attr.max_wr >= dev_attr->max_srq_wqes) {
1396
- dev_err(rdev_to_dev(rdev), "Create CQ failed - max exceeded");
1638
+ ibdev_err(&rdev->ibdev, "Create CQ failed - max exceeded");
13971639 rc = -EINVAL;
13981640 goto exit;
13991641 }
....@@ -1403,11 +1645,6 @@
14031645 goto exit;
14041646 }
14051647
1406
- srq = kzalloc(sizeof(*srq), GFP_KERNEL);
1407
- if (!srq) {
1408
- rc = -ENOMEM;
1409
- goto exit;
1410
- }
14111648 srq->rdev = rdev;
14121649 srq->qplib_srq.pd = &pd->qplib_pd;
14131650 srq->qplib_srq.dpi = &rdev->dpi_privileged;
....@@ -1417,9 +1654,11 @@
14171654 entries = roundup_pow_of_two(srq_init_attr->attr.max_wr + 1);
14181655 if (entries > dev_attr->max_srq_wqes + 1)
14191656 entries = dev_attr->max_srq_wqes + 1;
1420
-
14211657 srq->qplib_srq.max_wqe = entries;
1658
+
14221659 srq->qplib_srq.max_sge = srq_init_attr->attr.max_sge;
1660
+ /* 128 byte wqe size for SRQ . So use max sges */
1661
+ srq->qplib_srq.wqe_size = bnxt_re_get_rwqe_size(dev_attr->max_srq_sges);
14231662 srq->qplib_srq.threshold = srq_init_attr->attr.srq_limit;
14241663 srq->srq_limit = srq_init_attr->attr.srq_limit;
14251664 srq->qplib_srq.eventq_hw_ring_id = rdev->nq[0].ring_id;
....@@ -1433,7 +1672,7 @@
14331672
14341673 rc = bnxt_qplib_create_srq(&rdev->qplib_res, &srq->qplib_srq);
14351674 if (rc) {
1436
- dev_err(rdev_to_dev(rdev), "Create HW SRQ failed!");
1675
+ ibdev_err(&rdev->ibdev, "Create HW SRQ failed!");
14371676 goto fail;
14381677 }
14391678
....@@ -1443,7 +1682,7 @@
14431682 resp.srqid = srq->qplib_srq.id;
14441683 rc = ib_copy_to_udata(udata, &resp, sizeof(resp));
14451684 if (rc) {
1446
- dev_err(rdev_to_dev(rdev), "SRQ copy to udata failed!");
1685
+ ibdev_err(&rdev->ibdev, "SRQ copy to udata failed!");
14471686 bnxt_qplib_destroy_srq(&rdev->qplib_res,
14481687 &srq->qplib_srq);
14491688 goto fail;
....@@ -1452,15 +1691,14 @@
14521691 if (nq)
14531692 nq->budget++;
14541693 atomic_inc(&rdev->srq_count);
1694
+ spin_lock_init(&srq->lock);
14551695
1456
- return &srq->ib_srq;
1696
+ return 0;
14571697
14581698 fail:
1459
- if (srq->umem)
1460
- ib_umem_release(srq->umem);
1461
- kfree(srq);
1699
+ ib_umem_release(srq->umem);
14621700 exit:
1463
- return ERR_PTR(rc);
1701
+ return rc;
14641702 }
14651703
14661704 int bnxt_re_modify_srq(struct ib_srq *ib_srq, struct ib_srq_attr *srq_attr,
....@@ -1484,7 +1722,7 @@
14841722 srq->qplib_srq.threshold = srq_attr->srq_limit;
14851723 rc = bnxt_qplib_modify_srq(&rdev->qplib_res, &srq->qplib_srq);
14861724 if (rc) {
1487
- dev_err(rdev_to_dev(rdev), "Modify HW SRQ failed!");
1725
+ ibdev_err(&rdev->ibdev, "Modify HW SRQ failed!");
14881726 return rc;
14891727 }
14901728 /* On success, update the shadow */
....@@ -1492,8 +1730,8 @@
14921730 /* No need to Build and send response back to udata */
14931731 break;
14941732 default:
1495
- dev_err(rdev_to_dev(rdev),
1496
- "Unsupported srq_attr_mask 0x%x", srq_attr_mask);
1733
+ ibdev_err(&rdev->ibdev,
1734
+ "Unsupported srq_attr_mask 0x%x", srq_attr_mask);
14971735 return -EINVAL;
14981736 }
14991737 return 0;
....@@ -1511,7 +1749,7 @@
15111749 tsrq.qplib_srq.id = srq->qplib_srq.id;
15121750 rc = bnxt_qplib_query_srq(&rdev->qplib_res, &tsrq.qplib_srq);
15131751 if (rc) {
1514
- dev_err(rdev_to_dev(rdev), "Query HW SRQ failed!");
1752
+ ibdev_err(&rdev->ibdev, "Query HW SRQ failed!");
15151753 return rc;
15161754 }
15171755 srq_attr->max_wr = srq->qplib_srq.max_wqe;
....@@ -1553,7 +1791,7 @@
15531791 struct bnxt_re_qp *qp1_qp,
15541792 int qp_attr_mask)
15551793 {
1556
- struct bnxt_re_qp *qp = rdev->qp1_sqp;
1794
+ struct bnxt_re_qp *qp = rdev->gsi_ctx.gsi_sqp;
15571795 int rc = 0;
15581796
15591797 if (qp_attr_mask & IB_QP_STATE) {
....@@ -1577,8 +1815,7 @@
15771815
15781816 rc = bnxt_qplib_modify_qp(&rdev->qplib_res, &qp->qplib_qp);
15791817 if (rc)
1580
- dev_err(rdev_to_dev(rdev),
1581
- "Failed to modify Shadow QP for QP1");
1818
+ ibdev_err(&rdev->ibdev, "Failed to modify Shadow QP for QP1");
15821819 return rc;
15831820 }
15841821
....@@ -1598,17 +1835,16 @@
15981835 curr_qp_state = __to_ib_qp_state(qp->qplib_qp.cur_qp_state);
15991836 new_qp_state = qp_attr->qp_state;
16001837 if (!ib_modify_qp_is_ok(curr_qp_state, new_qp_state,
1601
- ib_qp->qp_type, qp_attr_mask,
1602
- IB_LINK_LAYER_ETHERNET)) {
1603
- dev_err(rdev_to_dev(rdev),
1604
- "Invalid attribute mask: %#x specified ",
1605
- qp_attr_mask);
1606
- dev_err(rdev_to_dev(rdev),
1607
- "for qpn: %#x type: %#x",
1608
- ib_qp->qp_num, ib_qp->qp_type);
1609
- dev_err(rdev_to_dev(rdev),
1610
- "curr_qp_state=0x%x, new_qp_state=0x%x\n",
1611
- curr_qp_state, new_qp_state);
1838
+ ib_qp->qp_type, qp_attr_mask)) {
1839
+ ibdev_err(&rdev->ibdev,
1840
+ "Invalid attribute mask: %#x specified ",
1841
+ qp_attr_mask);
1842
+ ibdev_err(&rdev->ibdev,
1843
+ "for qpn: %#x type: %#x",
1844
+ ib_qp->qp_num, ib_qp->qp_type);
1845
+ ibdev_err(&rdev->ibdev,
1846
+ "curr_qp_state=0x%x, new_qp_state=0x%x\n",
1847
+ curr_qp_state, new_qp_state);
16121848 return -EINVAL;
16131849 }
16141850 qp->qplib_qp.modify_flags |= CMDQ_MODIFY_QP_MODIFY_MASK_STATE;
....@@ -1616,18 +1852,16 @@
16161852
16171853 if (!qp->sumem &&
16181854 qp->qplib_qp.state == CMDQ_MODIFY_QP_NEW_STATE_ERR) {
1619
- dev_dbg(rdev_to_dev(rdev),
1620
- "Move QP = %p to flush list\n",
1621
- qp);
1855
+ ibdev_dbg(&rdev->ibdev,
1856
+ "Move QP = %p to flush list\n", qp);
16221857 flags = bnxt_re_lock_cqs(qp);
16231858 bnxt_qplib_add_flush_qp(&qp->qplib_qp);
16241859 bnxt_re_unlock_cqs(qp, flags);
16251860 }
16261861 if (!qp->sumem &&
16271862 qp->qplib_qp.state == CMDQ_MODIFY_QP_NEW_STATE_RESET) {
1628
- dev_dbg(rdev_to_dev(rdev),
1629
- "Move QP = %p out of flush list\n",
1630
- qp);
1863
+ ibdev_dbg(&rdev->ibdev,
1864
+ "Move QP = %p out of flush list\n", qp);
16311865 flags = bnxt_re_lock_cqs(qp);
16321866 bnxt_qplib_clean_qp(&qp->qplib_qp);
16331867 bnxt_re_unlock_cqs(qp, flags);
....@@ -1644,6 +1878,9 @@
16441878 __from_ib_access_flags(qp_attr->qp_access_flags);
16451879 /* LOCAL_WRITE access must be set to allow RC receive */
16461880 qp->qplib_qp.access |= BNXT_QPLIB_ACCESS_LOCAL_WRITE;
1881
+ /* Temp: Set all params on QP as of now */
1882
+ qp->qplib_qp.access |= CMDQ_MODIFY_QP_ACCESS_REMOTE_WRITE;
1883
+ qp->qplib_qp.access |= CMDQ_MODIFY_QP_ACCESS_REMOTE_READ;
16471884 }
16481885 if (qp_attr_mask & IB_QP_PKEY_INDEX) {
16491886 qp->qplib_qp.modify_flags |= CMDQ_MODIFY_QP_MODIFY_MASK_PKEY;
....@@ -1657,6 +1894,7 @@
16571894 const struct ib_global_route *grh =
16581895 rdma_ah_read_grh(&qp_attr->ah_attr);
16591896 const struct ib_gid_attr *sgid_attr;
1897
+ struct bnxt_re_gid_ctx *ctx;
16601898
16611899 qp->qplib_qp.modify_flags |= CMDQ_MODIFY_QP_MODIFY_MASK_DGID |
16621900 CMDQ_MODIFY_QP_MODIFY_MASK_FLOW_LABEL |
....@@ -1668,11 +1906,12 @@
16681906 memcpy(qp->qplib_qp.ah.dgid.data, grh->dgid.raw,
16691907 sizeof(qp->qplib_qp.ah.dgid.data));
16701908 qp->qplib_qp.ah.flow_label = grh->flow_label;
1671
- /* If RoCE V2 is enabled, stack will have two entries for
1672
- * each GID entry. Avoiding this duplicte entry in HW. Dividing
1673
- * the GID index by 2 for RoCE V2
1909
+ sgid_attr = grh->sgid_attr;
1910
+ /* Get the HW context of the GID. The reference
1911
+ * of GID table entry is already taken by the caller.
16741912 */
1675
- qp->qplib_qp.ah.sgid_index = grh->sgid_index / 2;
1913
+ ctx = rdma_read_gid_hw_context(sgid_attr);
1914
+ qp->qplib_qp.ah.sgid_index = ctx->idx;
16761915 qp->qplib_qp.ah.host_sgid_index = grh->sgid_index;
16771916 qp->qplib_qp.ah.hop_limit = grh->hop_limit;
16781917 qp->qplib_qp.ah.traffic_class = grh->traffic_class;
....@@ -1680,9 +1919,11 @@
16801919 ether_addr_copy(qp->qplib_qp.ah.dmac,
16811920 qp_attr->ah_attr.roce.dmac);
16821921
1683
- sgid_attr = qp_attr->ah_attr.grh.sgid_attr;
1684
- memcpy(qp->qplib_qp.smac, sgid_attr->ndev->dev_addr,
1685
- ETH_ALEN);
1922
+ rc = rdma_read_gid_l2_fields(sgid_attr, NULL,
1923
+ &qp->qplib_qp.smac[0]);
1924
+ if (rc)
1925
+ return rc;
1926
+
16861927 nw_type = rdma_gid_attr_network_type(sgid_attr);
16871928 switch (nw_type) {
16881929 case RDMA_NETWORK_IPV4:
....@@ -1751,10 +1992,10 @@
17511992 if (qp_attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
17521993 if (qp_attr->max_dest_rd_atomic >
17531994 dev_attr->max_qp_init_rd_atom) {
1754
- dev_err(rdev_to_dev(rdev),
1755
- "max_dest_rd_atomic requested%d is > dev_max%d",
1756
- qp_attr->max_dest_rd_atomic,
1757
- dev_attr->max_qp_init_rd_atom);
1995
+ ibdev_err(&rdev->ibdev,
1996
+ "max_dest_rd_atomic requested%d is > dev_max%d",
1997
+ qp_attr->max_dest_rd_atomic,
1998
+ dev_attr->max_qp_init_rd_atom);
17581999 return -EINVAL;
17592000 }
17602001
....@@ -1775,8 +2016,8 @@
17752016 (qp_attr->cap.max_recv_sge >= dev_attr->max_qp_sges) ||
17762017 (qp_attr->cap.max_inline_data >=
17772018 dev_attr->max_inline_data)) {
1778
- dev_err(rdev_to_dev(rdev),
1779
- "Create QP failed - max exceeded");
2019
+ ibdev_err(&rdev->ibdev,
2020
+ "Create QP failed - max exceeded");
17802021 return -EINVAL;
17812022 }
17822023 entries = roundup_pow_of_two(qp_attr->cap.max_send_wr);
....@@ -1809,10 +2050,10 @@
18092050 }
18102051 rc = bnxt_qplib_modify_qp(&rdev->qplib_res, &qp->qplib_qp);
18112052 if (rc) {
1812
- dev_err(rdev_to_dev(rdev), "Failed to modify HW QP");
2053
+ ibdev_err(&rdev->ibdev, "Failed to modify HW QP");
18132054 return rc;
18142055 }
1815
- if (ib_qp->qp_type == IB_QPT_GSI && rdev->qp1_sqp)
2056
+ if (ib_qp->qp_type == IB_QPT_GSI && rdev->gsi_ctx.gsi_sqp)
18162057 rc = bnxt_re_modify_shadow_qp(rdev, qp, qp_attr_mask);
18172058 return rc;
18182059 }
....@@ -1834,7 +2075,7 @@
18342075
18352076 rc = bnxt_qplib_query_qp(&rdev->qplib_res, qplib_qp);
18362077 if (rc) {
1837
- dev_err(rdev_to_dev(rdev), "Failed to query HW QP");
2078
+ ibdev_err(&rdev->ibdev, "Failed to query HW QP");
18382079 goto out;
18392080 }
18402081 qp_attr->qp_state = __to_ib_qp_state(qplib_qp->state);
....@@ -1902,8 +2143,10 @@
19022143
19032144 memset(&qp->qp1_hdr, 0, sizeof(qp->qp1_hdr));
19042145
1905
- if (is_vlan_dev(sgid_attr->ndev))
1906
- vlan_id = vlan_dev_vlan_id(sgid_attr->ndev);
2146
+ rc = rdma_read_gid_l2_fields(sgid_attr, &vlan_id, NULL);
2147
+ if (rc)
2148
+ return rc;
2149
+
19072150 /* Get network header type for this GID */
19082151 nw_type = rdma_gid_attr_network_type(sgid_attr);
19092152 switch (nw_type) {
....@@ -2038,7 +2281,7 @@
20382281 wqe->num_sge++;
20392282
20402283 } else {
2041
- dev_err(rdev_to_dev(qp->rdev), "QP1 buffer is empty!");
2284
+ ibdev_err(&qp->rdev->ibdev, "QP1 buffer is empty!");
20422285 rc = -ENOMEM;
20432286 }
20442287 return rc;
....@@ -2055,9 +2298,12 @@
20552298 struct bnxt_qplib_swqe *wqe,
20562299 int payload_size)
20572300 {
2058
- struct bnxt_qplib_sge ref, sge;
2059
- u32 rq_prod_index;
20602301 struct bnxt_re_sqp_entries *sqp_entry;
2302
+ struct bnxt_qplib_sge ref, sge;
2303
+ struct bnxt_re_dev *rdev;
2304
+ u32 rq_prod_index;
2305
+
2306
+ rdev = qp->rdev;
20612307
20622308 rq_prod_index = bnxt_qplib_get_rq_prod_index(&qp->qplib_qp);
20632309
....@@ -2072,7 +2318,7 @@
20722318 ref.lkey = wqe->sg_list[0].lkey;
20732319 ref.size = wqe->sg_list[0].size;
20742320
2075
- sqp_entry = &qp->rdev->sqp_tbl[rq_prod_index];
2321
+ sqp_entry = &rdev->gsi_ctx.sqp_tbl[rq_prod_index];
20762322
20772323 /* SGE 1 */
20782324 wqe->sg_list[0].addr = sge.addr;
....@@ -2092,7 +2338,8 @@
20922338
20932339 static int is_ud_qp(struct bnxt_re_qp *qp)
20942340 {
2095
- return qp->qplib_qp.type == CMDQ_CREATE_QP_TYPE_UD;
2341
+ return (qp->qplib_qp.type == CMDQ_CREATE_QP_TYPE_UD ||
2342
+ qp->qplib_qp.type == CMDQ_CREATE_QP_TYPE_GSI);
20962343 }
20972344
20982345 static int bnxt_re_build_send_wqe(struct bnxt_re_qp *qp,
....@@ -2223,7 +2470,7 @@
22232470 wqe->frmr.pbl_dma_ptr = qplib_frpl->hwq.pbl_dma_ptr[0];
22242471 wqe->frmr.page_list = mr->pages;
22252472 wqe->frmr.page_list_len = mr->npages;
2226
- wqe->frmr.levels = qplib_frpl->hwq.level + 1;
2473
+ wqe->frmr.levels = qplib_frpl->hwq.level;
22272474 wqe->type = BNXT_QPLIB_SWQE_TYPE_REG_MR;
22282475
22292476 /* Need unconditional fence for reg_mr
....@@ -2270,8 +2517,8 @@
22702517
22712518 if ((sge_len + wqe->inline_len) >
22722519 BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH) {
2273
- dev_err(rdev_to_dev(rdev),
2274
- "Inline data size requested > supported value");
2520
+ ibdev_err(&rdev->ibdev,
2521
+ "Inline data size requested > supported value");
22752522 return -EINVAL;
22762523 }
22772524 sge_len = wr->sg_list[i].length;
....@@ -2318,21 +2565,18 @@
23182565 struct bnxt_re_qp *qp,
23192566 const struct ib_send_wr *wr)
23202567 {
2321
- struct bnxt_qplib_swqe wqe;
23222568 int rc = 0, payload_sz = 0;
23232569 unsigned long flags;
23242570
23252571 spin_lock_irqsave(&qp->sq_lock, flags);
2326
- memset(&wqe, 0, sizeof(wqe));
23272572 while (wr) {
2328
- /* House keeping */
2329
- memset(&wqe, 0, sizeof(wqe));
2573
+ struct bnxt_qplib_swqe wqe = {};
23302574
23312575 /* Common */
23322576 wqe.num_sge = wr->num_sge;
23332577 if (wr->num_sge > qp->qplib_qp.sq.max_sge) {
2334
- dev_err(rdev_to_dev(rdev),
2335
- "Limit exceeded for Send SGEs");
2578
+ ibdev_err(&rdev->ibdev,
2579
+ "Limit exceeded for Send SGEs");
23362580 rc = -EINVAL;
23372581 goto bad;
23382582 }
....@@ -2351,9 +2595,9 @@
23512595 rc = bnxt_qplib_post_send(&qp->qplib_qp, &wqe);
23522596 bad:
23532597 if (rc) {
2354
- dev_err(rdev_to_dev(rdev),
2355
- "Post send failed opcode = %#x rc = %d",
2356
- wr->opcode, rc);
2598
+ ibdev_err(&rdev->ibdev,
2599
+ "Post send failed opcode = %#x rc = %d",
2600
+ wr->opcode, rc);
23572601 break;
23582602 }
23592603 wr = wr->next;
....@@ -2380,8 +2624,8 @@
23802624 /* Common */
23812625 wqe.num_sge = wr->num_sge;
23822626 if (wr->num_sge > qp->qplib_qp.sq.max_sge) {
2383
- dev_err(rdev_to_dev(qp->rdev),
2384
- "Limit exceeded for Send SGEs");
2627
+ ibdev_err(&qp->rdev->ibdev,
2628
+ "Limit exceeded for Send SGEs");
23852629 rc = -EINVAL;
23862630 goto bad;
23872631 }
....@@ -2396,7 +2640,7 @@
23962640 switch (wr->opcode) {
23972641 case IB_WR_SEND:
23982642 case IB_WR_SEND_WITH_IMM:
2399
- if (ib_qp->qp_type == IB_QPT_GSI) {
2643
+ if (qp->qplib_qp.type == CMDQ_CREATE_QP1_TYPE_GSI) {
24002644 rc = bnxt_re_build_qp1_send_v2(qp, wr, &wqe,
24012645 payload_sz);
24022646 if (rc)
....@@ -2412,7 +2656,7 @@
24122656 default:
24132657 break;
24142658 }
2415
- /* fall through */
2659
+ fallthrough;
24162660 case IB_WR_SEND_WITH_INV:
24172661 rc = bnxt_re_build_send_wqe(qp, wr, &wqe);
24182662 break;
....@@ -2426,8 +2670,8 @@
24262670 rc = bnxt_re_build_atomic_wqe(wr, &wqe);
24272671 break;
24282672 case IB_WR_RDMA_READ_WITH_INV:
2429
- dev_err(rdev_to_dev(qp->rdev),
2430
- "RDMA Read with Invalidate is not supported");
2673
+ ibdev_err(&qp->rdev->ibdev,
2674
+ "RDMA Read with Invalidate is not supported");
24312675 rc = -EINVAL;
24322676 goto bad;
24332677 case IB_WR_LOCAL_INV:
....@@ -2438,8 +2682,8 @@
24382682 break;
24392683 default:
24402684 /* Unsupported WRs */
2441
- dev_err(rdev_to_dev(qp->rdev),
2442
- "WR (%#x) is not supported", wr->opcode);
2685
+ ibdev_err(&qp->rdev->ibdev,
2686
+ "WR (%#x) is not supported", wr->opcode);
24432687 rc = -EINVAL;
24442688 goto bad;
24452689 }
....@@ -2447,9 +2691,9 @@
24472691 rc = bnxt_qplib_post_send(&qp->qplib_qp, &wqe);
24482692 bad:
24492693 if (rc) {
2450
- dev_err(rdev_to_dev(qp->rdev),
2451
- "post_send failed op:%#x qps = %#x rc = %d\n",
2452
- wr->opcode, qp->qplib_qp.state, rc);
2694
+ ibdev_err(&qp->rdev->ibdev,
2695
+ "post_send failed op:%#x qps = %#x rc = %d\n",
2696
+ wr->opcode, qp->qplib_qp.state, rc);
24532697 *bad_wr = wr;
24542698 break;
24552699 }
....@@ -2477,8 +2721,8 @@
24772721 /* Common */
24782722 wqe.num_sge = wr->num_sge;
24792723 if (wr->num_sge > qp->qplib_qp.rq.max_sge) {
2480
- dev_err(rdev_to_dev(rdev),
2481
- "Limit exceeded for Receive SGEs");
2724
+ ibdev_err(&rdev->ibdev,
2725
+ "Limit exceeded for Receive SGEs");
24822726 rc = -EINVAL;
24832727 break;
24842728 }
....@@ -2514,8 +2758,8 @@
25142758 /* Common */
25152759 wqe.num_sge = wr->num_sge;
25162760 if (wr->num_sge > qp->qplib_qp.rq.max_sge) {
2517
- dev_err(rdev_to_dev(qp->rdev),
2518
- "Limit exceeded for Receive SGEs");
2761
+ ibdev_err(&qp->rdev->ibdev,
2762
+ "Limit exceeded for Receive SGEs");
25192763 rc = -EINVAL;
25202764 *bad_wr = wr;
25212765 break;
....@@ -2526,7 +2770,8 @@
25262770 wqe.wr_id = wr->wr_id;
25272771 wqe.type = BNXT_QPLIB_SWQE_TYPE_RECV;
25282772
2529
- if (ib_qp->qp_type == IB_QPT_GSI)
2773
+ if (ib_qp->qp_type == IB_QPT_GSI &&
2774
+ qp->qplib_qp.type != CMDQ_CREATE_QP_TYPE_GSI)
25302775 rc = bnxt_re_build_qp1_shadow_qp_recv(qp, wr, &wqe,
25312776 payload_sz);
25322777 if (!rc)
....@@ -2554,9 +2799,8 @@
25542799 }
25552800
25562801 /* Completion Queues */
2557
-int bnxt_re_destroy_cq(struct ib_cq *ib_cq)
2802
+int bnxt_re_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata)
25582803 {
2559
- int rc;
25602804 struct bnxt_re_cq *cq;
25612805 struct bnxt_qplib_nq *nq;
25622806 struct bnxt_re_dev *rdev;
....@@ -2565,30 +2809,21 @@
25652809 rdev = cq->rdev;
25662810 nq = cq->qplib_cq.nq;
25672811
2568
- rc = bnxt_qplib_destroy_cq(&rdev->qplib_res, &cq->qplib_cq);
2569
- if (rc) {
2570
- dev_err(rdev_to_dev(rdev), "Failed to destroy HW CQ");
2571
- return rc;
2572
- }
2573
- if (!IS_ERR_OR_NULL(cq->umem))
2574
- ib_umem_release(cq->umem);
2812
+ bnxt_qplib_destroy_cq(&rdev->qplib_res, &cq->qplib_cq);
2813
+ ib_umem_release(cq->umem);
25752814
25762815 atomic_dec(&rdev->cq_count);
25772816 nq->budget--;
25782817 kfree(cq->cql);
2579
- kfree(cq);
2580
-
25812818 return 0;
25822819 }
25832820
2584
-struct ib_cq *bnxt_re_create_cq(struct ib_device *ibdev,
2585
- const struct ib_cq_init_attr *attr,
2586
- struct ib_ucontext *context,
2587
- struct ib_udata *udata)
2821
+int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
2822
+ struct ib_udata *udata)
25882823 {
2589
- struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
2824
+ struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibcq->device, ibdev);
25902825 struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
2591
- struct bnxt_re_cq *cq = NULL;
2826
+ struct bnxt_re_cq *cq = container_of(ibcq, struct bnxt_re_cq, ib_cq);
25922827 int rc, entries;
25932828 int cqe = attr->cqe;
25942829 struct bnxt_qplib_nq *nq = NULL;
....@@ -2596,12 +2831,9 @@
25962831
25972832 /* Validate CQ fields */
25982833 if (cqe < 1 || cqe > dev_attr->max_cq_wqes) {
2599
- dev_err(rdev_to_dev(rdev), "Failed to create CQ -max exceeded");
2600
- return ERR_PTR(-EINVAL);
2834
+ ibdev_err(&rdev->ibdev, "Failed to create CQ -max exceeded");
2835
+ return -EINVAL;
26012836 }
2602
- cq = kzalloc(sizeof(*cq), GFP_KERNEL);
2603
- if (!cq)
2604
- return ERR_PTR(-ENOMEM);
26052837
26062838 cq->rdev = rdev;
26072839 cq->qplib_cq.cq_handle = (u64)(unsigned long)(&cq->qplib_cq);
....@@ -2610,26 +2842,25 @@
26102842 if (entries > dev_attr->max_cq_wqes + 1)
26112843 entries = dev_attr->max_cq_wqes + 1;
26122844
2613
- if (context) {
2845
+ cq->qplib_cq.sg_info.pgsize = PAGE_SIZE;
2846
+ cq->qplib_cq.sg_info.pgshft = PAGE_SHIFT;
2847
+ if (udata) {
26142848 struct bnxt_re_cq_req req;
2615
- struct bnxt_re_ucontext *uctx = container_of
2616
- (context,
2617
- struct bnxt_re_ucontext,
2618
- ib_uctx);
2849
+ struct bnxt_re_ucontext *uctx = rdma_udata_to_drv_context(
2850
+ udata, struct bnxt_re_ucontext, ib_uctx);
26192851 if (ib_copy_from_udata(&req, udata, sizeof(req))) {
26202852 rc = -EFAULT;
26212853 goto fail;
26222854 }
26232855
2624
- cq->umem = ib_umem_get(context, req.cq_va,
2856
+ cq->umem = ib_umem_get(&rdev->ibdev, req.cq_va,
26252857 entries * sizeof(struct cq_base),
2626
- IB_ACCESS_LOCAL_WRITE, 1);
2858
+ IB_ACCESS_LOCAL_WRITE);
26272859 if (IS_ERR(cq->umem)) {
26282860 rc = PTR_ERR(cq->umem);
26292861 goto fail;
26302862 }
2631
- cq->qplib_cq.sghead = cq->umem->sg_head.sgl;
2632
- cq->qplib_cq.nmap = cq->umem->nmap;
2863
+ cq->qplib_cq.sg_info.umem = cq->umem;
26332864 cq->qplib_cq.dpi = &uctx->dpi;
26342865 } else {
26352866 cq->max_cql = min_t(u32, entries, MAX_CQL_PER_POLL);
....@@ -2641,8 +2872,6 @@
26412872 }
26422873
26432874 cq->qplib_cq.dpi = &rdev->dpi_privileged;
2644
- cq->qplib_cq.sghead = NULL;
2645
- cq->qplib_cq.nmap = 0;
26462875 }
26472876 /*
26482877 * Allocating the NQ in a round robin fashion. nq_alloc_cnt is a
....@@ -2656,7 +2885,7 @@
26562885
26572886 rc = bnxt_qplib_create_cq(&rdev->qplib_res, &cq->qplib_cq);
26582887 if (rc) {
2659
- dev_err(rdev_to_dev(rdev), "Failed to create HW CQ");
2888
+ ibdev_err(&rdev->ibdev, "Failed to create HW CQ");
26602889 goto fail;
26612890 }
26622891
....@@ -2667,7 +2896,7 @@
26672896 atomic_inc(&rdev->cq_count);
26682897 spin_lock_init(&cq->cq_lock);
26692898
2670
- if (context) {
2899
+ if (udata) {
26712900 struct bnxt_re_cq_resp resp;
26722901
26732902 resp.cqid = cq->qplib_cq.id;
....@@ -2676,21 +2905,19 @@
26762905 resp.rsvd = 0;
26772906 rc = ib_copy_to_udata(udata, &resp, sizeof(resp));
26782907 if (rc) {
2679
- dev_err(rdev_to_dev(rdev), "Failed to copy CQ udata");
2908
+ ibdev_err(&rdev->ibdev, "Failed to copy CQ udata");
26802909 bnxt_qplib_destroy_cq(&rdev->qplib_res, &cq->qplib_cq);
26812910 goto c2fail;
26822911 }
26832912 }
26842913
2685
- return &cq->ib_cq;
2914
+ return 0;
26862915
26872916 c2fail:
2688
- if (context)
2689
- ib_umem_release(cq->umem);
2917
+ ib_umem_release(cq->umem);
26902918 fail:
26912919 kfree(cq->cql);
2692
- kfree(cq);
2693
- return ERR_PTR(rc);
2920
+ return rc;
26942921 }
26952922
26962923 static u8 __req_to_ib_wc_status(u8 qstatus)
....@@ -2909,12 +3136,13 @@
29093136 return rc;
29103137 }
29113138
2912
-static int bnxt_re_process_raw_qp_pkt_rx(struct bnxt_re_qp *qp1_qp,
3139
+static int bnxt_re_process_raw_qp_pkt_rx(struct bnxt_re_qp *gsi_qp,
29133140 struct bnxt_qplib_cqe *cqe)
29143141 {
2915
- struct bnxt_re_dev *rdev = qp1_qp->rdev;
3142
+ struct bnxt_re_dev *rdev = gsi_qp->rdev;
29163143 struct bnxt_re_sqp_entries *sqp_entry = NULL;
2917
- struct bnxt_re_qp *qp = rdev->qp1_sqp;
3144
+ struct bnxt_re_qp *gsi_sqp = rdev->gsi_ctx.gsi_sqp;
3145
+ struct bnxt_re_ah *gsi_sah;
29183146 struct ib_send_wr *swr;
29193147 struct ib_ud_wr udwr;
29203148 struct ib_recv_wr rwr;
....@@ -2937,26 +3165,26 @@
29373165 swr = &udwr.wr;
29383166 tbl_idx = cqe->wr_id;
29393167
2940
- rq_hdr_buf = qp1_qp->qplib_qp.rq_hdr_buf +
2941
- (tbl_idx * qp1_qp->qplib_qp.rq_hdr_buf_size);
2942
- rq_hdr_buf_map = bnxt_qplib_get_qp_buf_from_index(&qp1_qp->qplib_qp,
3168
+ rq_hdr_buf = gsi_qp->qplib_qp.rq_hdr_buf +
3169
+ (tbl_idx * gsi_qp->qplib_qp.rq_hdr_buf_size);
3170
+ rq_hdr_buf_map = bnxt_qplib_get_qp_buf_from_index(&gsi_qp->qplib_qp,
29433171 tbl_idx);
29443172
29453173 /* Shadow QP header buffer */
2946
- shrq_hdr_buf_map = bnxt_qplib_get_qp_buf_from_index(&qp->qplib_qp,
3174
+ shrq_hdr_buf_map = bnxt_qplib_get_qp_buf_from_index(&gsi_qp->qplib_qp,
29473175 tbl_idx);
2948
- sqp_entry = &rdev->sqp_tbl[tbl_idx];
3176
+ sqp_entry = &rdev->gsi_ctx.sqp_tbl[tbl_idx];
29493177
29503178 /* Store this cqe */
29513179 memcpy(&sqp_entry->cqe, cqe, sizeof(struct bnxt_qplib_cqe));
2952
- sqp_entry->qp1_qp = qp1_qp;
3180
+ sqp_entry->qp1_qp = gsi_qp;
29533181
29543182 /* Find packet type from the cqe */
29553183
29563184 pkt_type = bnxt_re_check_packet_type(cqe->raweth_qp1_flags,
29573185 cqe->raweth_qp1_flags2);
29583186 if (pkt_type < 0) {
2959
- dev_err(rdev_to_dev(rdev), "Invalid packet\n");
3187
+ ibdev_err(&rdev->ibdev, "Invalid packet\n");
29603188 return -EINVAL;
29613189 }
29623190
....@@ -3003,10 +3231,10 @@
30033231 rwr.wr_id = tbl_idx;
30043232 rwr.next = NULL;
30053233
3006
- rc = bnxt_re_post_recv_shadow_qp(rdev, qp, &rwr);
3234
+ rc = bnxt_re_post_recv_shadow_qp(rdev, gsi_sqp, &rwr);
30073235 if (rc) {
3008
- dev_err(rdev_to_dev(rdev),
3009
- "Failed to post Rx buffers to shadow QP");
3236
+ ibdev_err(&rdev->ibdev,
3237
+ "Failed to post Rx buffers to shadow QP");
30103238 return -ENOMEM;
30113239 }
30123240
....@@ -3015,13 +3243,13 @@
30153243 swr->wr_id = tbl_idx;
30163244 swr->opcode = IB_WR_SEND;
30173245 swr->next = NULL;
3018
-
3019
- udwr.ah = &rdev->sqp_ah->ib_ah;
3020
- udwr.remote_qpn = rdev->qp1_sqp->qplib_qp.id;
3021
- udwr.remote_qkey = rdev->qp1_sqp->qplib_qp.qkey;
3246
+ gsi_sah = rdev->gsi_ctx.gsi_sah;
3247
+ udwr.ah = &gsi_sah->ib_ah;
3248
+ udwr.remote_qpn = gsi_sqp->qplib_qp.id;
3249
+ udwr.remote_qkey = gsi_sqp->qplib_qp.qkey;
30223250
30233251 /* post data received in the send queue */
3024
- rc = bnxt_re_post_send_shadow_qp(rdev, qp, swr);
3252
+ rc = bnxt_re_post_send_shadow_qp(rdev, gsi_sqp, swr);
30253253
30263254 return 0;
30273255 }
....@@ -3088,12 +3316,12 @@
30883316 wc->opcode = IB_WC_RECV_RDMA_WITH_IMM;
30893317 }
30903318
3091
-static void bnxt_re_process_res_shadow_qp_wc(struct bnxt_re_qp *qp,
3319
+static void bnxt_re_process_res_shadow_qp_wc(struct bnxt_re_qp *gsi_sqp,
30923320 struct ib_wc *wc,
30933321 struct bnxt_qplib_cqe *cqe)
30943322 {
3095
- struct bnxt_re_dev *rdev = qp->rdev;
3096
- struct bnxt_re_qp *qp1_qp = NULL;
3323
+ struct bnxt_re_dev *rdev = gsi_sqp->rdev;
3324
+ struct bnxt_re_qp *gsi_qp = NULL;
30973325 struct bnxt_qplib_cqe *orig_cqe = NULL;
30983326 struct bnxt_re_sqp_entries *sqp_entry = NULL;
30993327 int nw_type;
....@@ -3103,13 +3331,13 @@
31033331
31043332 tbl_idx = cqe->wr_id;
31053333
3106
- sqp_entry = &rdev->sqp_tbl[tbl_idx];
3107
- qp1_qp = sqp_entry->qp1_qp;
3334
+ sqp_entry = &rdev->gsi_ctx.sqp_tbl[tbl_idx];
3335
+ gsi_qp = sqp_entry->qp1_qp;
31083336 orig_cqe = &sqp_entry->cqe;
31093337
31103338 wc->wr_id = sqp_entry->wrid;
31113339 wc->byte_len = orig_cqe->length;
3112
- wc->qp = &qp1_qp->ib_qp;
3340
+ wc->qp = &gsi_qp->ib_qp;
31133341
31143342 wc->ex.imm_data = orig_cqe->immdata;
31153343 wc->src_qp = orig_cqe->src_qp;
....@@ -3136,19 +3364,39 @@
31363364 }
31373365 }
31383366
3139
-static void bnxt_re_process_res_ud_wc(struct ib_wc *wc,
3367
+static void bnxt_re_process_res_ud_wc(struct bnxt_re_qp *qp,
3368
+ struct ib_wc *wc,
31403369 struct bnxt_qplib_cqe *cqe)
31413370 {
3371
+ struct bnxt_re_dev *rdev;
3372
+ u16 vlan_id = 0;
3373
+ u8 nw_type;
3374
+
3375
+ rdev = qp->rdev;
31423376 wc->opcode = IB_WC_RECV;
31433377 wc->status = __rc_to_ib_wc_status(cqe->status);
31443378
3145
- if (cqe->flags & CQ_RES_RC_FLAGS_IMM)
3379
+ if (cqe->flags & CQ_RES_UD_FLAGS_IMM)
31463380 wc->wc_flags |= IB_WC_WITH_IMM;
3147
- if (cqe->flags & CQ_RES_RC_FLAGS_INV)
3148
- wc->wc_flags |= IB_WC_WITH_INVALIDATE;
3149
- if ((cqe->flags & (CQ_RES_RC_FLAGS_RDMA | CQ_RES_RC_FLAGS_IMM)) ==
3150
- (CQ_RES_RC_FLAGS_RDMA | CQ_RES_RC_FLAGS_IMM))
3151
- wc->opcode = IB_WC_RECV_RDMA_WITH_IMM;
3381
+ /* report only on GSI QP for Thor */
3382
+ if (qp->qplib_qp.type == CMDQ_CREATE_QP_TYPE_GSI) {
3383
+ wc->wc_flags |= IB_WC_GRH;
3384
+ memcpy(wc->smac, cqe->smac, ETH_ALEN);
3385
+ wc->wc_flags |= IB_WC_WITH_SMAC;
3386
+ if (cqe->flags & CQ_RES_UD_FLAGS_META_FORMAT_VLAN) {
3387
+ vlan_id = (cqe->cfa_meta & 0xFFF);
3388
+ }
3389
+ /* Mark only if vlan_id is non zero */
3390
+ if (vlan_id && bnxt_re_check_if_vlan_valid(rdev, vlan_id)) {
3391
+ wc->vlan_id = vlan_id;
3392
+ wc->wc_flags |= IB_WC_WITH_VLAN;
3393
+ }
3394
+ nw_type = (cqe->flags & CQ_RES_UD_FLAGS_ROCE_IP_VER_MASK) >>
3395
+ CQ_RES_UD_FLAGS_ROCE_IP_VER_SFT;
3396
+ wc->network_hdr_type = bnxt_re_to_ib_nw_type(nw_type);
3397
+ wc->wc_flags |= IB_WC_WITH_NETWORK_HDR_TYPE;
3398
+ }
3399
+
31523400 }
31533401
31543402 static int send_phantom_wqe(struct bnxt_re_qp *qp)
....@@ -3162,11 +3410,11 @@
31623410 rc = bnxt_re_bind_fence_mw(lib_qp);
31633411 if (!rc) {
31643412 lib_qp->sq.phantom_wqe_cnt++;
3165
- dev_dbg(&lib_qp->sq.hwq.pdev->dev,
3166
- "qp %#x sq->prod %#x sw_prod %#x phantom_wqe_cnt %d\n",
3167
- lib_qp->id, lib_qp->sq.hwq.prod,
3168
- HWQ_CMP(lib_qp->sq.hwq.prod, &lib_qp->sq.hwq),
3169
- lib_qp->sq.phantom_wqe_cnt);
3413
+ ibdev_dbg(&qp->rdev->ibdev,
3414
+ "qp %#x sq->prod %#x sw_prod %#x phantom_wqe_cnt %d\n",
3415
+ lib_qp->id, lib_qp->sq.hwq.prod,
3416
+ HWQ_CMP(lib_qp->sq.hwq.prod, &lib_qp->sq.hwq),
3417
+ lib_qp->sq.phantom_wqe_cnt);
31703418 }
31713419
31723420 spin_unlock_irqrestore(&qp->sq_lock, flags);
....@@ -3176,7 +3424,7 @@
31763424 int bnxt_re_poll_cq(struct ib_cq *ib_cq, int num_entries, struct ib_wc *wc)
31773425 {
31783426 struct bnxt_re_cq *cq = container_of(ib_cq, struct bnxt_re_cq, ib_cq);
3179
- struct bnxt_re_qp *qp;
3427
+ struct bnxt_re_qp *qp, *sh_qp;
31803428 struct bnxt_qplib_cqe *cqe;
31813429 int i, ncqe, budget;
31823430 struct bnxt_qplib_q *sq;
....@@ -3189,7 +3437,7 @@
31893437 budget = min_t(u32, num_entries, cq->max_cql);
31903438 num_entries = budget;
31913439 if (!cq->cql) {
3192
- dev_err(rdev_to_dev(cq->rdev), "POLL CQ : no CQL to use");
3440
+ ibdev_err(&cq->rdev->ibdev, "POLL CQ : no CQL to use");
31933441 goto exit;
31943442 }
31953443 cqe = &cq->cql[0];
....@@ -3202,8 +3450,8 @@
32023450 qp = container_of(lib_qp,
32033451 struct bnxt_re_qp, qplib_qp);
32043452 if (send_phantom_wqe(qp) == -ENOMEM)
3205
- dev_err(rdev_to_dev(cq->rdev),
3206
- "Phantom failed! Scheduled to send again\n");
3453
+ ibdev_err(&cq->rdev->ibdev,
3454
+ "Phantom failed! Scheduled to send again\n");
32073455 else
32083456 sq->send_phantom = false;
32093457 }
....@@ -3227,8 +3475,7 @@
32273475 (unsigned long)(cqe->qp_handle),
32283476 struct bnxt_re_qp, qplib_qp);
32293477 if (!qp) {
3230
- dev_err(rdev_to_dev(cq->rdev),
3231
- "POLL CQ : bad QP handle");
3478
+ ibdev_err(&cq->rdev->ibdev, "POLL CQ : bad QP handle");
32323479 continue;
32333480 }
32343481 wc->qp = &qp->ib_qp;
....@@ -3240,8 +3487,9 @@
32403487
32413488 switch (cqe->opcode) {
32423489 case CQ_BASE_CQE_TYPE_REQ:
3243
- if (qp->qplib_qp.id ==
3244
- qp->rdev->qp1_sqp->qplib_qp.id) {
3490
+ sh_qp = qp->rdev->gsi_ctx.gsi_sqp;
3491
+ if (sh_qp &&
3492
+ qp->qplib_qp.id == sh_qp->qplib_qp.id) {
32453493 /* Handle this completion with
32463494 * the stored completion
32473495 */
....@@ -3267,7 +3515,7 @@
32673515 * stored in the table
32683516 */
32693517 tbl_idx = cqe->wr_id;
3270
- sqp_entry = &cq->rdev->sqp_tbl[tbl_idx];
3518
+ sqp_entry = &cq->rdev->gsi_ctx.sqp_tbl[tbl_idx];
32713519 wc->wr_id = sqp_entry->wrid;
32723520 bnxt_re_process_res_rawqp1_wc(wc, cqe);
32733521 break;
....@@ -3275,8 +3523,9 @@
32753523 bnxt_re_process_res_rc_wc(wc, cqe);
32763524 break;
32773525 case CQ_BASE_CQE_TYPE_RES_UD:
3278
- if (qp->qplib_qp.id ==
3279
- qp->rdev->qp1_sqp->qplib_qp.id) {
3526
+ sh_qp = qp->rdev->gsi_ctx.gsi_sqp;
3527
+ if (sh_qp &&
3528
+ qp->qplib_qp.id == sh_qp->qplib_qp.id) {
32803529 /* Handle this completion with
32813530 * the stored completion
32823531 */
....@@ -3288,12 +3537,12 @@
32883537 break;
32893538 }
32903539 }
3291
- bnxt_re_process_res_ud_wc(wc, cqe);
3540
+ bnxt_re_process_res_ud_wc(qp, wc, cqe);
32923541 break;
32933542 default:
3294
- dev_err(rdev_to_dev(cq->rdev),
3295
- "POLL CQ : type 0x%x not handled",
3296
- cqe->opcode);
3543
+ ibdev_err(&cq->rdev->ibdev,
3544
+ "POLL CQ : type 0x%x not handled",
3545
+ cqe->opcode);
32973546 continue;
32983547 }
32993548 wc++;
....@@ -3315,10 +3564,10 @@
33153564 spin_lock_irqsave(&cq->cq_lock, flags);
33163565 /* Trigger on the very next completion */
33173566 if (ib_cqn_flags & IB_CQ_NEXT_COMP)
3318
- type = DBR_DBR_TYPE_CQ_ARMALL;
3567
+ type = DBC_DBC_TYPE_CQ_ARMALL;
33193568 /* Trigger on the next solicited completion */
33203569 else if (ib_cqn_flags & IB_CQ_SOLICITED)
3321
- type = DBR_DBR_TYPE_CQ_ARMSE;
3570
+ type = DBC_DBC_TYPE_CQ_ARMSE;
33223571
33233572 /* Poll to see if there are missed events */
33243573 if ((ib_cqn_flags & IB_CQ_REPORT_MISSED_EVENTS) &&
....@@ -3378,7 +3627,7 @@
33783627 return ERR_PTR(rc);
33793628 }
33803629
3381
-int bnxt_re_dereg_mr(struct ib_mr *ib_mr)
3630
+int bnxt_re_dereg_mr(struct ib_mr *ib_mr, struct ib_udata *udata)
33823631 {
33833632 struct bnxt_re_mr *mr = container_of(ib_mr, struct bnxt_re_mr, ib_mr);
33843633 struct bnxt_re_dev *rdev = mr->rdev;
....@@ -3386,7 +3635,7 @@
33863635
33873636 rc = bnxt_qplib_free_mrw(&rdev->qplib_res, &mr->qplib_mr);
33883637 if (rc) {
3389
- dev_err(rdev_to_dev(rdev), "Dereg MR failed: %#x\n", rc);
3638
+ ibdev_err(&rdev->ibdev, "Dereg MR failed: %#x\n", rc);
33903639 return rc;
33913640 }
33923641
....@@ -3397,8 +3646,7 @@
33973646 mr->npages = 0;
33983647 mr->pages = NULL;
33993648 }
3400
- if (!IS_ERR_OR_NULL(mr->ib_umem))
3401
- ib_umem_release(mr->ib_umem);
3649
+ ib_umem_release(mr->ib_umem);
34023650
34033651 kfree(mr);
34043652 atomic_dec(&rdev->mr_count);
....@@ -3434,7 +3682,7 @@
34343682 int rc;
34353683
34363684 if (type != IB_MR_TYPE_MEM_REG) {
3437
- dev_dbg(rdev_to_dev(rdev), "MR type 0x%x not supported", type);
3685
+ ibdev_dbg(&rdev->ibdev, "MR type 0x%x not supported", type);
34383686 return ERR_PTR(-EINVAL);
34393687 }
34403688 if (max_num_sg > MAX_PBL_LVL_1_PGS)
....@@ -3464,8 +3712,8 @@
34643712 rc = bnxt_qplib_alloc_fast_reg_page_list(&rdev->qplib_res,
34653713 &mr->qplib_frpl, max_num_sg);
34663714 if (rc) {
3467
- dev_err(rdev_to_dev(rdev),
3468
- "Failed to allocate HW FR page list");
3715
+ ibdev_err(&rdev->ibdev,
3716
+ "Failed to allocate HW FR page list");
34693717 goto fail_mr;
34703718 }
34713719
....@@ -3500,7 +3748,7 @@
35003748 CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE2B);
35013749 rc = bnxt_qplib_alloc_mrw(&rdev->qplib_res, &mw->qplib_mw);
35023750 if (rc) {
3503
- dev_err(rdev_to_dev(rdev), "Allocate MW failed!");
3751
+ ibdev_err(&rdev->ibdev, "Allocate MW failed!");
35043752 goto fail;
35053753 }
35063754 mw->ib_mw.rkey = mw->qplib_mw.rkey;
....@@ -3521,7 +3769,7 @@
35213769
35223770 rc = bnxt_qplib_free_mrw(&rdev->qplib_res, &mw->qplib_mw);
35233771 if (rc) {
3524
- dev_err(rdev_to_dev(rdev), "Free MW failed: %#x\n", rc);
3772
+ ibdev_err(&rdev->ibdev, "Free MW failed: %#x\n", rc);
35253773 return rc;
35263774 }
35273775
....@@ -3530,43 +3778,16 @@
35303778 return rc;
35313779 }
35323780
3533
-static int bnxt_re_page_size_ok(int page_shift)
3534
-{
3535
- switch (page_shift) {
3536
- case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_4K:
3537
- case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_8K:
3538
- case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_64K:
3539
- case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_2M:
3540
- case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_256K:
3541
- case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_1M:
3542
- case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_4M:
3543
- case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_1G:
3544
- return 1;
3545
- default:
3546
- return 0;
3547
- }
3548
-}
3549
-
35503781 static int fill_umem_pbl_tbl(struct ib_umem *umem, u64 *pbl_tbl_orig,
35513782 int page_shift)
35523783 {
35533784 u64 *pbl_tbl = pbl_tbl_orig;
3554
- u64 paddr;
3555
- u64 page_mask = (1ULL << page_shift) - 1;
3556
- int i, pages;
3557
- struct scatterlist *sg;
3558
- int entry;
3785
+ u64 page_size = BIT_ULL(page_shift);
3786
+ struct ib_block_iter biter;
35593787
3560
- for_each_sg(umem->sg_head.sgl, sg, umem->nmap, entry) {
3561
- pages = sg_dma_len(sg) >> PAGE_SHIFT;
3562
- for (i = 0; i < pages; i++) {
3563
- paddr = sg_dma_address(sg) + (i << PAGE_SHIFT);
3564
- if (pbl_tbl == pbl_tbl_orig)
3565
- *pbl_tbl++ = paddr & ~page_mask;
3566
- else if ((paddr & page_mask) == 0)
3567
- *pbl_tbl++ = paddr;
3568
- }
3569
- }
3788
+ rdma_umem_for_each_dma_block(umem, &biter, page_size)
3789
+ *pbl_tbl++ = rdma_block_iter_dma_address(&biter);
3790
+
35703791 return pbl_tbl - pbl_tbl_orig;
35713792 }
35723793
....@@ -3580,11 +3801,12 @@
35803801 struct bnxt_re_mr *mr;
35813802 struct ib_umem *umem;
35823803 u64 *pbl_tbl = NULL;
3583
- int umem_pgs, page_shift, rc;
3804
+ unsigned long page_size;
3805
+ int umem_pgs, rc;
35843806
35853807 if (length > BNXT_RE_MAX_MR_SIZE) {
3586
- dev_err(rdev_to_dev(rdev), "MR Size: %lld > Max supported:%lld\n",
3587
- length, BNXT_RE_MAX_MR_SIZE);
3808
+ ibdev_err(&rdev->ibdev, "MR Size: %lld > Max supported:%lld\n",
3809
+ length, BNXT_RE_MAX_MR_SIZE);
35883810 return ERR_PTR(-ENOMEM);
35893811 }
35903812
....@@ -3599,62 +3821,51 @@
35993821
36003822 rc = bnxt_qplib_alloc_mrw(&rdev->qplib_res, &mr->qplib_mr);
36013823 if (rc) {
3602
- dev_err(rdev_to_dev(rdev), "Failed to allocate MR");
3824
+ ibdev_err(&rdev->ibdev, "Failed to allocate MR");
36033825 goto free_mr;
36043826 }
36053827 /* The fixed portion of the rkey is the same as the lkey */
36063828 mr->ib_mr.rkey = mr->qplib_mr.rkey;
36073829
3608
- umem = ib_umem_get(ib_pd->uobject->context, start, length,
3609
- mr_access_flags, 0);
3830
+ umem = ib_umem_get(&rdev->ibdev, start, length, mr_access_flags);
36103831 if (IS_ERR(umem)) {
3611
- dev_err(rdev_to_dev(rdev), "Failed to get umem");
3832
+ ibdev_err(&rdev->ibdev, "Failed to get umem");
36123833 rc = -EFAULT;
36133834 goto free_mrw;
36143835 }
36153836 mr->ib_umem = umem;
36163837
36173838 mr->qplib_mr.va = virt_addr;
3618
- umem_pgs = ib_umem_page_count(umem);
3619
- if (!umem_pgs) {
3620
- dev_err(rdev_to_dev(rdev), "umem is invalid!");
3621
- rc = -EINVAL;
3839
+ page_size = ib_umem_find_best_pgsz(
3840
+ umem, BNXT_RE_PAGE_SIZE_4K | BNXT_RE_PAGE_SIZE_2M, virt_addr);
3841
+ if (!page_size) {
3842
+ ibdev_err(&rdev->ibdev, "umem page size unsupported!");
3843
+ rc = -EFAULT;
36223844 goto free_umem;
36233845 }
36243846 mr->qplib_mr.total_size = length;
36253847
3626
- pbl_tbl = kcalloc(umem_pgs, sizeof(u64 *), GFP_KERNEL);
3848
+ if (page_size == BNXT_RE_PAGE_SIZE_4K &&
3849
+ length > BNXT_RE_MAX_MR_SIZE_LOW) {
3850
+ ibdev_err(&rdev->ibdev, "Requested MR Sz:%llu Max sup:%llu",
3851
+ length, (u64)BNXT_RE_MAX_MR_SIZE_LOW);
3852
+ rc = -EINVAL;
3853
+ goto free_umem;
3854
+ }
3855
+
3856
+ umem_pgs = ib_umem_num_dma_blocks(umem, page_size);
3857
+ pbl_tbl = kcalloc(umem_pgs, sizeof(*pbl_tbl), GFP_KERNEL);
36273858 if (!pbl_tbl) {
36283859 rc = -ENOMEM;
36293860 goto free_umem;
36303861 }
36313862
3632
- page_shift = umem->page_shift;
3633
-
3634
- if (!bnxt_re_page_size_ok(page_shift)) {
3635
- dev_err(rdev_to_dev(rdev), "umem page size unsupported!");
3636
- rc = -EFAULT;
3637
- goto fail;
3638
- }
3639
-
3640
- if (!umem->hugetlb && length > BNXT_RE_MAX_MR_SIZE_LOW) {
3641
- dev_err(rdev_to_dev(rdev), "Requested MR Sz:%llu Max sup:%llu",
3642
- length, (u64)BNXT_RE_MAX_MR_SIZE_LOW);
3643
- rc = -EINVAL;
3644
- goto fail;
3645
- }
3646
- if (umem->hugetlb && length > BNXT_RE_PAGE_SIZE_2M) {
3647
- page_shift = BNXT_RE_PAGE_SHIFT_2M;
3648
- dev_warn(rdev_to_dev(rdev), "umem hugetlb set page_size %x",
3649
- 1 << page_shift);
3650
- }
3651
-
36523863 /* Map umem buf ptrs to the PBL */
3653
- umem_pgs = fill_umem_pbl_tbl(umem, pbl_tbl, page_shift);
3864
+ umem_pgs = fill_umem_pbl_tbl(umem, pbl_tbl, order_base_2(page_size));
36543865 rc = bnxt_qplib_reg_mr(&rdev->qplib_res, &mr->qplib_mr, pbl_tbl,
3655
- umem_pgs, false, 1 << page_shift);
3866
+ umem_pgs, false, page_size);
36563867 if (rc) {
3657
- dev_err(rdev_to_dev(rdev), "Failed to register user MR");
3868
+ ibdev_err(&rdev->ibdev, "Failed to register user MR");
36583869 goto fail;
36593870 }
36603871
....@@ -3676,27 +3887,24 @@
36763887 return ERR_PTR(rc);
36773888 }
36783889
3679
-struct ib_ucontext *bnxt_re_alloc_ucontext(struct ib_device *ibdev,
3680
- struct ib_udata *udata)
3890
+int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
36813891 {
3892
+ struct ib_device *ibdev = ctx->device;
3893
+ struct bnxt_re_ucontext *uctx =
3894
+ container_of(ctx, struct bnxt_re_ucontext, ib_uctx);
36823895 struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
3683
- struct bnxt_re_uctx_resp resp;
3684
- struct bnxt_re_ucontext *uctx;
36853896 struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
3897
+ struct bnxt_re_uctx_resp resp;
3898
+ u32 chip_met_rev_num = 0;
36863899 int rc;
36873900
3688
- dev_dbg(rdev_to_dev(rdev), "ABI version requested %d",
3689
- ibdev->uverbs_abi_ver);
3901
+ ibdev_dbg(ibdev, "ABI version requested %u", ibdev->ops.uverbs_abi_ver);
36903902
3691
- if (ibdev->uverbs_abi_ver != BNXT_RE_ABI_VERSION) {
3692
- dev_dbg(rdev_to_dev(rdev), " is different from the device %d ",
3693
- BNXT_RE_ABI_VERSION);
3694
- return ERR_PTR(-EPERM);
3903
+ if (ibdev->ops.uverbs_abi_ver != BNXT_RE_ABI_VERSION) {
3904
+ ibdev_dbg(ibdev, " is different from the device %d ",
3905
+ BNXT_RE_ABI_VERSION);
3906
+ return -EPERM;
36953907 }
3696
-
3697
- uctx = kzalloc(sizeof(*uctx), GFP_KERNEL);
3698
- if (!uctx)
3699
- return ERR_PTR(-ENOMEM);
37003908
37013909 uctx->rdev = rdev;
37023910
....@@ -3707,37 +3915,45 @@
37073915 }
37083916 spin_lock_init(&uctx->sh_lock);
37093917
3710
- resp.dev_id = rdev->en_dev->pdev->devfn; /*Temp, Use idr_alloc instead*/
3918
+ resp.comp_mask = BNXT_RE_UCNTX_CMASK_HAVE_CCTX;
3919
+ chip_met_rev_num = rdev->chip_ctx->chip_num;
3920
+ chip_met_rev_num |= ((u32)rdev->chip_ctx->chip_rev & 0xFF) <<
3921
+ BNXT_RE_CHIP_ID0_CHIP_REV_SFT;
3922
+ chip_met_rev_num |= ((u32)rdev->chip_ctx->chip_metal & 0xFF) <<
3923
+ BNXT_RE_CHIP_ID0_CHIP_MET_SFT;
3924
+ resp.chip_id0 = chip_met_rev_num;
3925
+ /* Future extension of chip info */
3926
+ resp.chip_id1 = 0;
3927
+ /*Temp, Use xa_alloc instead */
3928
+ resp.dev_id = rdev->en_dev->pdev->devfn;
37113929 resp.max_qp = rdev->qplib_ctx.qpc_count;
37123930 resp.pg_size = PAGE_SIZE;
37133931 resp.cqe_sz = sizeof(struct cq_base);
37143932 resp.max_cqd = dev_attr->max_cq_wqes;
37153933 resp.rsvd = 0;
37163934
3717
- rc = ib_copy_to_udata(udata, &resp, sizeof(resp));
3935
+ rc = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp)));
37183936 if (rc) {
3719
- dev_err(rdev_to_dev(rdev), "Failed to copy user context");
3937
+ ibdev_err(ibdev, "Failed to copy user context");
37203938 rc = -EFAULT;
37213939 goto cfail;
37223940 }
37233941
3724
- return &uctx->ib_uctx;
3942
+ return 0;
37253943 cfail:
37263944 free_page((unsigned long)uctx->shpg);
37273945 uctx->shpg = NULL;
37283946 fail:
3729
- kfree(uctx);
3730
- return ERR_PTR(rc);
3947
+ return rc;
37313948 }
37323949
3733
-int bnxt_re_dealloc_ucontext(struct ib_ucontext *ib_uctx)
3950
+void bnxt_re_dealloc_ucontext(struct ib_ucontext *ib_uctx)
37343951 {
37353952 struct bnxt_re_ucontext *uctx = container_of(ib_uctx,
37363953 struct bnxt_re_ucontext,
37373954 ib_uctx);
37383955
37393956 struct bnxt_re_dev *rdev = uctx->rdev;
3740
- int rc = 0;
37413957
37423958 if (uctx->shpg)
37433959 free_page((unsigned long)uctx->shpg);
....@@ -3746,17 +3962,10 @@
37463962 /* Free DPI only if this is the first PD allocated by the
37473963 * application and mark the context dpi as NULL
37483964 */
3749
- rc = bnxt_qplib_dealloc_dpi(&rdev->qplib_res,
3750
- &rdev->qplib_res.dpi_tbl,
3751
- &uctx->dpi);
3752
- if (rc)
3753
- dev_err(rdev_to_dev(rdev), "Deallocate HW DPI failed!");
3754
- /* Don't fail, continue*/
3965
+ bnxt_qplib_dealloc_dpi(&rdev->qplib_res,
3966
+ &rdev->qplib_res.dpi_tbl, &uctx->dpi);
37553967 uctx->dpi.dbr = NULL;
37563968 }
3757
-
3758
- kfree(uctx);
3759
- return 0;
37603969 }
37613970
37623971 /* Helper function to mmap the virtual memory from user app */
....@@ -3775,15 +3984,14 @@
37753984 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
37763985 if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
37773986 PAGE_SIZE, vma->vm_page_prot)) {
3778
- dev_err(rdev_to_dev(rdev), "Failed to map DPI");
3987
+ ibdev_err(&rdev->ibdev, "Failed to map DPI");
37793988 return -EAGAIN;
37803989 }
37813990 } else {
37823991 pfn = virt_to_phys(uctx->shpg) >> PAGE_SHIFT;
37833992 if (remap_pfn_range(vma, vma->vm_start,
37843993 pfn, PAGE_SIZE, vma->vm_page_prot)) {
3785
- dev_err(rdev_to_dev(rdev),
3786
- "Failed to map shared page");
3994
+ ibdev_err(&rdev->ibdev, "Failed to map shared page");
37873995 return -EAGAIN;
37883996 }
37893997 }