forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
....@@ -69,16 +69,16 @@
6969 struct hns_roce_wqe_data_seg *dseg = NULL;
7070 struct hns_roce_qp *qp = to_hr_qp(ibqp);
7171 struct device *dev = &hr_dev->pdev->dev;
72
- struct hns_roce_sq_db sq_db;
73
- int ps_opcode = 0, i = 0;
72
+ struct hns_roce_sq_db sq_db = {};
73
+ int ps_opcode, i;
7474 unsigned long flags = 0;
7575 void *wqe = NULL;
76
- u32 doorbell[2];
77
- int nreq = 0;
78
- u32 ind = 0;
76
+ __le32 doorbell[2];
7977 int ret = 0;
80
- u8 *smac;
8178 int loopback;
79
+ u32 wqe_idx;
80
+ int nreq;
81
+ u8 *smac;
8282
8383 if (unlikely(ibqp->qp_type != IB_QPT_GSI &&
8484 ibqp->qp_type != IB_QPT_RC)) {
....@@ -88,13 +88,15 @@
8888 }
8989
9090 spin_lock_irqsave(&qp->sq.lock, flags);
91
- ind = qp->sq_next_wqe;
91
+
9292 for (nreq = 0; wr; ++nreq, wr = wr->next) {
9393 if (hns_roce_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq)) {
9494 ret = -ENOMEM;
9595 *bad_wr = wr;
9696 goto out;
9797 }
98
+
99
+ wqe_idx = (qp->sq.head + nreq) & (qp->sq.wqe_cnt - 1);
98100
99101 if (unlikely(wr->num_sge > qp->sq.max_gs)) {
100102 dev_err(dev, "num_sge=%d > qp->sq.max_gs=%d\n",
....@@ -104,9 +106,8 @@
104106 goto out;
105107 }
106108
107
- wqe = get_send_wqe(qp, ind & (qp->sq.wqe_cnt - 1));
108
- qp->sq.wrid[(qp->sq.head + nreq) & (qp->sq.wqe_cnt - 1)] =
109
- wr->wr_id;
109
+ wqe = hns_roce_get_send_wqe(qp, wqe_idx);
110
+ qp->sq.wrid[wqe_idx] = wr->wr_id;
110111
111112 /* Corresponding to the RC and RD type wqe process separately */
112113 if (ibqp->qp_type == IB_QPT_GSI) {
....@@ -175,13 +176,11 @@
175176 roce_set_field(ud_sq_wqe->u32_36,
176177 UD_SEND_WQE_U32_36_FLOW_LABEL_M,
177178 UD_SEND_WQE_U32_36_FLOW_LABEL_S,
178
- ah->av.sl_tclass_flowlabel &
179
- HNS_ROCE_FLOW_LABEL_MASK);
179
+ ah->av.flowlabel);
180180 roce_set_field(ud_sq_wqe->u32_36,
181181 UD_SEND_WQE_U32_36_PRIORITY_M,
182182 UD_SEND_WQE_U32_36_PRIORITY_S,
183
- le32_to_cpu(ah->av.sl_tclass_flowlabel) >>
184
- HNS_ROCE_SL_SHIFT);
183
+ ah->av.sl);
185184 roce_set_field(ud_sq_wqe->u32_36,
186185 UD_SEND_WQE_U32_36_SGID_INDEX_M,
187186 UD_SEND_WQE_U32_36_SGID_INDEX_S,
....@@ -195,8 +194,7 @@
195194 roce_set_field(ud_sq_wqe->u32_40,
196195 UD_SEND_WQE_U32_40_TRAFFIC_CLASS_M,
197196 UD_SEND_WQE_U32_40_TRAFFIC_CLASS_S,
198
- ah->av.sl_tclass_flowlabel >>
199
- HNS_ROCE_TCLASS_SHIFT);
197
+ ah->av.tclass);
200198
201199 memcpy(&ud_sq_wqe->dgid[0], &ah->av.dgid[0], GID_LEN);
202200
....@@ -213,7 +211,6 @@
213211 cpu_to_le32((wr->sg_list[1].addr) >> 32);
214212 ud_sq_wqe->l_key1 =
215213 cpu_to_le32(wr->sg_list[1].lkey);
216
- ind++;
217214 } else if (ibqp->qp_type == IB_QPT_RC) {
218215 u32 tmp_len = 0;
219216
....@@ -310,7 +307,6 @@
310307 ctrl->flag |= cpu_to_le32(wr->num_sge <<
311308 HNS_ROCE_WQE_SGE_NUM_BIT);
312309 }
313
- ind++;
314310 }
315311 }
316312
....@@ -321,8 +317,6 @@
321317 /* Memory barrier */
322318 wmb();
323319
324
- sq_db.u32_4 = 0;
325
- sq_db.u32_8 = 0;
326320 roce_set_field(sq_db.u32_4, SQ_DOORBELL_U32_4_SQ_HEAD_M,
327321 SQ_DOORBELL_U32_4_SQ_HEAD_S,
328322 (qp->sq.head & ((qp->sq.wqe_cnt << 1) - 1)));
....@@ -334,11 +328,10 @@
334328 SQ_DOORBELL_U32_8_QPN_S, qp->doorbell_qpn);
335329 roce_set_bit(sq_db.u32_8, SQ_DOORBELL_HW_SYNC_S, 1);
336330
337
- doorbell[0] = le32_to_cpu(sq_db.u32_4);
338
- doorbell[1] = le32_to_cpu(sq_db.u32_8);
331
+ doorbell[0] = sq_db.u32_4;
332
+ doorbell[1] = sq_db.u32_8;
339333
340
- hns_roce_write64_k((__le32 *)doorbell, qp->sq.db_reg_l);
341
- qp->sq_next_wqe = ind;
334
+ hns_roce_write64_k(doorbell, qp->sq.db_reg_l);
342335 }
343336
344337 spin_unlock_irqrestore(&qp->sq.lock, flags);
....@@ -350,22 +343,21 @@
350343 const struct ib_recv_wr *wr,
351344 const struct ib_recv_wr **bad_wr)
352345 {
353
- int ret = 0;
354
- int nreq = 0;
355
- int ind = 0;
356
- int i = 0;
357
- u32 reg_val;
358
- unsigned long flags = 0;
359346 struct hns_roce_rq_wqe_ctrl *ctrl = NULL;
360347 struct hns_roce_wqe_data_seg *scat = NULL;
361348 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
362349 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
363350 struct device *dev = &hr_dev->pdev->dev;
364
- struct hns_roce_rq_db rq_db;
365
- uint32_t doorbell[2] = {0};
351
+ struct hns_roce_rq_db rq_db = {};
352
+ __le32 doorbell[2] = {0};
353
+ unsigned long flags = 0;
354
+ unsigned int wqe_idx;
355
+ int ret = 0;
356
+ int nreq = 0;
357
+ int i = 0;
358
+ u32 reg_val;
366359
367360 spin_lock_irqsave(&hr_qp->rq.lock, flags);
368
- ind = hr_qp->rq.head & (hr_qp->rq.wqe_cnt - 1);
369361
370362 for (nreq = 0; wr; ++nreq, wr = wr->next) {
371363 if (hns_roce_wq_overflow(&hr_qp->rq, nreq,
....@@ -375,6 +367,8 @@
375367 goto out;
376368 }
377369
370
+ wqe_idx = (hr_qp->rq.head + nreq) & (hr_qp->rq.wqe_cnt - 1);
371
+
378372 if (unlikely(wr->num_sge > hr_qp->rq.max_gs)) {
379373 dev_err(dev, "rq:num_sge=%d > qp->sq.max_gs=%d\n",
380374 wr->num_sge, hr_qp->rq.max_gs);
....@@ -383,7 +377,7 @@
383377 goto out;
384378 }
385379
386
- ctrl = get_recv_wqe(hr_qp, ind);
380
+ ctrl = hns_roce_get_recv_wqe(hr_qp, wqe_idx);
387381
388382 roce_set_field(ctrl->rwqe_byte_12,
389383 RQ_WQE_CTRL_RWQE_BYTE_12_RWQE_SGE_NUM_M,
....@@ -395,9 +389,7 @@
395389 for (i = 0; i < wr->num_sge; i++)
396390 set_data_seg(scat + i, wr->sg_list + i);
397391
398
- hr_qp->rq.wrid[ind] = wr->wr_id;
399
-
400
- ind = (ind + 1) & (hr_qp->rq.wqe_cnt - 1);
392
+ hr_qp->rq.wrid[wqe_idx] = wr->wr_id;
401393 }
402394
403395 out:
....@@ -423,9 +415,6 @@
423415 ROCEE_QP1C_CFG3_0_REG +
424416 QP1C_CFGN_OFFSET * hr_qp->phy_port, reg_val);
425417 } else {
426
- rq_db.u32_4 = 0;
427
- rq_db.u32_8 = 0;
428
-
429418 roce_set_field(rq_db.u32_4, RQ_DOORBELL_U32_4_RQ_HEAD_M,
430419 RQ_DOORBELL_U32_4_RQ_HEAD_S,
431420 hr_qp->rq.head);
....@@ -436,11 +425,10 @@
436425 roce_set_bit(rq_db.u32_8, RQ_DOORBELL_U32_8_HW_SYNC_S,
437426 1);
438427
439
- doorbell[0] = le32_to_cpu(rq_db.u32_4);
440
- doorbell[1] = le32_to_cpu(rq_db.u32_8);
428
+ doorbell[0] = rq_db.u32_4;
429
+ doorbell[1] = rq_db.u32_8;
441430
442
- hns_roce_write64_k((__le32 *)doorbell,
443
- hr_qp->rq.db_reg_l);
431
+ hns_roce_write64_k(doorbell, hr_qp->rq.db_reg_l);
444432 }
445433 }
446434 spin_unlock_irqrestore(&hr_qp->rq.lock, flags);
....@@ -514,15 +502,12 @@
514502 static void hns_roce_set_sdb_ext(struct hns_roce_dev *hr_dev, u32 ext_sdb_alept,
515503 u32 ext_sdb_alful)
516504 {
505
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
506
+ struct hns_roce_db_table *db = &priv->db_table;
517507 struct device *dev = &hr_dev->pdev->dev;
518
- struct hns_roce_v1_priv *priv;
519
- struct hns_roce_db_table *db;
520508 dma_addr_t sdb_dma_addr;
521509 __le32 tmp;
522510 u32 val;
523
-
524
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
525
- db = &priv->db_table;
526511
527512 /* Configure extend SDB threshold */
528513 roce_write(hr_dev, ROCEE_EXT_DB_SQ_WL_EMPTY_REG, ext_sdb_alept);
....@@ -549,22 +534,19 @@
549534 roce_write(hr_dev, ROCEE_EXT_DB_SQ_H_REG, val);
550535
551536 dev_dbg(dev, "ext SDB depth: 0x%x\n", db->ext_db->esdb_dep);
552
- dev_dbg(dev, "ext SDB threshold: epmty: 0x%x, ful: 0x%x\n",
537
+ dev_dbg(dev, "ext SDB threshold: empty: 0x%x, ful: 0x%x\n",
553538 ext_sdb_alept, ext_sdb_alful);
554539 }
555540
556541 static void hns_roce_set_odb_ext(struct hns_roce_dev *hr_dev, u32 ext_odb_alept,
557542 u32 ext_odb_alful)
558543 {
544
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
545
+ struct hns_roce_db_table *db = &priv->db_table;
559546 struct device *dev = &hr_dev->pdev->dev;
560
- struct hns_roce_v1_priv *priv;
561
- struct hns_roce_db_table *db;
562547 dma_addr_t odb_dma_addr;
563548 __le32 tmp;
564549 u32 val;
565
-
566
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
567
- db = &priv->db_table;
568550
569551 /* Configure extend ODB threshold */
570552 roce_write(hr_dev, ROCEE_EXT_DB_OTHERS_WL_EMPTY_REG, ext_odb_alept);
....@@ -594,15 +576,12 @@
594576 static int hns_roce_db_ext_init(struct hns_roce_dev *hr_dev, u32 sdb_ext_mod,
595577 u32 odb_ext_mod)
596578 {
579
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
580
+ struct hns_roce_db_table *db = &priv->db_table;
597581 struct device *dev = &hr_dev->pdev->dev;
598
- struct hns_roce_v1_priv *priv;
599
- struct hns_roce_db_table *db;
600582 dma_addr_t sdb_dma_addr;
601583 dma_addr_t odb_dma_addr;
602584 int ret = 0;
603
-
604
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
605
- db = &priv->db_table;
606585
607586 db->ext_db = kmalloc(sizeof(*db->ext_db), GFP_KERNEL);
608587 if (!db->ext_db)
....@@ -703,35 +682,38 @@
703682
704683 static int hns_roce_v1_rsv_lp_qp(struct hns_roce_dev *hr_dev)
705684 {
685
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
686
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
706687 struct hns_roce_caps *caps = &hr_dev->caps;
688
+ struct ib_device *ibdev = &hr_dev->ib_dev;
707689 struct device *dev = &hr_dev->pdev->dev;
708690 struct ib_cq_init_attr cq_init_attr;
709
- struct hns_roce_free_mr *free_mr;
710691 struct ib_qp_attr attr = { 0 };
711
- struct hns_roce_v1_priv *priv;
712692 struct hns_roce_qp *hr_qp;
713693 struct ib_cq *cq;
714694 struct ib_pd *pd;
715695 union ib_gid dgid;
716
- u64 subnet_prefix;
696
+ __be64 subnet_prefix;
717697 int attr_mask = 0;
718
- int i, j;
719698 int ret;
699
+ int i, j;
720700 u8 queue_en[HNS_ROCE_V1_RESV_QP] = { 0 };
721701 u8 phy_port;
722702 u8 port = 0;
723703 u8 sl;
724704
725
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
726
- free_mr = &priv->free_mr;
727
-
728705 /* Reserved cq for loop qp */
729706 cq_init_attr.cqe = HNS_ROCE_MIN_WQE_NUM * 2;
730707 cq_init_attr.comp_vector = 0;
731
- cq = hns_roce_ib_create_cq(&hr_dev->ib_dev, &cq_init_attr, NULL, NULL);
732
- if (IS_ERR(cq)) {
733
- dev_err(dev, "Create cq for reseved loop qp failed!");
708
+
709
+ cq = rdma_zalloc_drv_obj(ibdev, ib_cq);
710
+ if (!cq)
734711 return -ENOMEM;
712
+
713
+ ret = hns_roce_create_cq(cq, &cq_init_attr, NULL);
714
+ if (ret) {
715
+ dev_err(dev, "Create cq for reserved loop qp failed!");
716
+ goto alloc_cq_failed;
735717 }
736718 free_mr->mr_free_cq = to_hr_cq(cq);
737719 free_mr->mr_free_cq->ib_cq.device = &hr_dev->ib_dev;
....@@ -741,12 +723,17 @@
741723 free_mr->mr_free_cq->ib_cq.cq_context = NULL;
742724 atomic_set(&free_mr->mr_free_cq->ib_cq.usecnt, 0);
743725
744
- pd = hns_roce_alloc_pd(&hr_dev->ib_dev, NULL, NULL);
745
- if (IS_ERR(pd)) {
746
- dev_err(dev, "Create pd for reseved loop qp failed!");
726
+ pd = rdma_zalloc_drv_obj(ibdev, ib_pd);
727
+ if (!pd) {
747728 ret = -ENOMEM;
748
- goto alloc_pd_failed;
729
+ goto alloc_mem_failed;
749730 }
731
+
732
+ pd->device = ibdev;
733
+ ret = hns_roce_alloc_pd(pd, NULL);
734
+ if (ret)
735
+ goto alloc_pd_failed;
736
+
750737 free_mr->mr_free_pd = to_hr_pd(pd);
751738 free_mr->mr_free_pd->ibpd.device = &hr_dev->ib_dev;
752739 free_mr->mr_free_pd->ibpd.uobject = NULL;
....@@ -812,7 +799,7 @@
812799 attr.dest_qp_num = hr_qp->qpn;
813800 memcpy(rdma_ah_retrieve_dmac(&attr.ah_attr),
814801 hr_dev->dev_addr[port],
815
- MAC_ADDR_OCTET_NUM);
802
+ ETH_ALEN);
816803
817804 memcpy(&dgid.raw, &subnet_prefix, sizeof(u64));
818805 memcpy(&dgid.raw[8], hr_dev->dev_addr[port], 3);
....@@ -849,65 +836,58 @@
849836 create_lp_qp_failed:
850837 for (i -= 1; i >= 0; i--) {
851838 hr_qp = free_mr->mr_free_qp[i];
852
- if (hns_roce_v1_destroy_qp(&hr_qp->ibqp))
839
+ if (hns_roce_v1_destroy_qp(&hr_qp->ibqp, NULL))
853840 dev_err(dev, "Destroy qp %d for mr free failed!\n", i);
854841 }
855842
856
- if (hns_roce_dealloc_pd(pd))
857
- dev_err(dev, "Destroy pd for create_lp_qp failed!\n");
843
+ hns_roce_dealloc_pd(pd, NULL);
858844
859845 alloc_pd_failed:
860
- if (hns_roce_ib_destroy_cq(cq))
861
- dev_err(dev, "Destroy cq for create_lp_qp failed!\n");
846
+ kfree(pd);
862847
848
+alloc_mem_failed:
849
+ hns_roce_destroy_cq(cq, NULL);
850
+alloc_cq_failed:
851
+ kfree(cq);
863852 return ret;
864853 }
865854
866855 static void hns_roce_v1_release_lp_qp(struct hns_roce_dev *hr_dev)
867856 {
857
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
858
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
868859 struct device *dev = &hr_dev->pdev->dev;
869
- struct hns_roce_free_mr *free_mr;
870
- struct hns_roce_v1_priv *priv;
871860 struct hns_roce_qp *hr_qp;
872861 int ret;
873862 int i;
874
-
875
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
876
- free_mr = &priv->free_mr;
877863
878864 for (i = 0; i < HNS_ROCE_V1_RESV_QP; i++) {
879865 hr_qp = free_mr->mr_free_qp[i];
880866 if (!hr_qp)
881867 continue;
882868
883
- ret = hns_roce_v1_destroy_qp(&hr_qp->ibqp);
869
+ ret = hns_roce_v1_destroy_qp(&hr_qp->ibqp, NULL);
884870 if (ret)
885871 dev_err(dev, "Destroy qp %d for mr free failed(%d)!\n",
886872 i, ret);
887873 }
888874
889
- ret = hns_roce_ib_destroy_cq(&free_mr->mr_free_cq->ib_cq);
890
- if (ret)
891
- dev_err(dev, "Destroy cq for mr_free failed(%d)!\n", ret);
892
-
893
- ret = hns_roce_dealloc_pd(&free_mr->mr_free_pd->ibpd);
894
- if (ret)
895
- dev_err(dev, "Destroy pd for mr_free failed(%d)!\n", ret);
875
+ hns_roce_destroy_cq(&free_mr->mr_free_cq->ib_cq, NULL);
876
+ kfree(&free_mr->mr_free_cq->ib_cq);
877
+ hns_roce_dealloc_pd(&free_mr->mr_free_pd->ibpd, NULL);
878
+ kfree(&free_mr->mr_free_pd->ibpd);
896879 }
897880
898881 static int hns_roce_db_init(struct hns_roce_dev *hr_dev)
899882 {
883
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
884
+ struct hns_roce_db_table *db = &priv->db_table;
900885 struct device *dev = &hr_dev->pdev->dev;
901
- struct hns_roce_v1_priv *priv;
902
- struct hns_roce_db_table *db;
903886 u32 sdb_ext_mod;
904887 u32 odb_ext_mod;
905888 u32 sdb_evt_mod;
906889 u32 odb_evt_mod;
907
- int ret = 0;
908
-
909
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
910
- db = &priv->db_table;
890
+ int ret;
911891
912892 memset(db, 0, sizeof(*db));
913893
....@@ -954,16 +934,12 @@
954934
955935 static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
956936 {
957
- struct device *dev = &hr_dev->pdev->dev;
937
+ long end = HNS_ROCE_V1_RECREATE_LP_QP_TIMEOUT_MSECS;
938
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
939
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
958940 struct hns_roce_recreate_lp_qp_work *lp_qp_work;
959
- struct hns_roce_free_mr *free_mr;
960
- struct hns_roce_v1_priv *priv;
941
+ struct device *dev = &hr_dev->pdev->dev;
961942 struct completion comp;
962
- unsigned long end =
963
- msecs_to_jiffies(HNS_ROCE_V1_RECREATE_LP_QP_TIMEOUT_MSECS) + jiffies;
964
-
965
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
966
- free_mr = &priv->free_mr;
967943
968944 lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
969945 GFP_KERNEL);
....@@ -980,10 +956,11 @@
980956
981957 queue_work(free_mr->free_mr_wq, &(lp_qp_work->work));
982958
983
- while (time_before_eq(jiffies, end)) {
959
+ while (end > 0) {
984960 if (try_wait_for_completion(&comp))
985961 return 0;
986962 msleep(HNS_ROCE_V1_RECREATE_LP_QP_WAIT_VALUE);
963
+ end -= HNS_ROCE_V1_RECREATE_LP_QP_WAIT_VALUE;
987964 }
988965
989966 lp_qp_work->comp_flag = 0;
....@@ -1021,29 +998,21 @@
1021998
1022999 static void hns_roce_v1_mr_free_work_fn(struct work_struct *work)
10231000 {
1024
- struct hns_roce_mr_free_work *mr_work;
1025
- struct ib_wc wc[HNS_ROCE_V1_RESV_QP];
1026
- struct hns_roce_free_mr *free_mr;
1027
- struct hns_roce_cq *mr_free_cq;
1028
- struct hns_roce_v1_priv *priv;
1029
- struct hns_roce_dev *hr_dev;
1030
- struct hns_roce_mr *hr_mr;
1031
- struct hns_roce_qp *hr_qp;
1032
- struct device *dev;
10331001 unsigned long end =
10341002 msecs_to_jiffies(HNS_ROCE_V1_FREE_MR_TIMEOUT_MSECS) + jiffies;
1035
- int i;
1036
- int ret;
1003
+ struct hns_roce_mr_free_work *mr_work =
1004
+ container_of(work, struct hns_roce_mr_free_work, work);
1005
+ struct hns_roce_dev *hr_dev = to_hr_dev(mr_work->ib_dev);
1006
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1007
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
1008
+ struct hns_roce_cq *mr_free_cq = free_mr->mr_free_cq;
1009
+ struct hns_roce_mr *hr_mr = mr_work->mr;
1010
+ struct device *dev = &hr_dev->pdev->dev;
1011
+ struct ib_wc wc[HNS_ROCE_V1_RESV_QP];
1012
+ struct hns_roce_qp *hr_qp;
10371013 int ne = 0;
1038
-
1039
- mr_work = container_of(work, struct hns_roce_mr_free_work, work);
1040
- hr_mr = (struct hns_roce_mr *)mr_work->mr;
1041
- hr_dev = to_hr_dev(mr_work->ib_dev);
1042
- dev = &hr_dev->pdev->dev;
1043
-
1044
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1045
- free_mr = &priv->free_mr;
1046
- mr_free_cq = free_mr->mr_free_cq;
1014
+ int ret;
1015
+ int i;
10471016
10481017 for (i = 0; i < HNS_ROCE_V1_RESV_QP; i++) {
10491018 hr_qp = free_mr->mr_free_qp[i];
....@@ -1090,26 +1059,22 @@
10901059 }
10911060
10921061 static int hns_roce_v1_dereg_mr(struct hns_roce_dev *hr_dev,
1093
- struct hns_roce_mr *mr)
1062
+ struct hns_roce_mr *mr, struct ib_udata *udata)
10941063 {
1064
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1065
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
1066
+ long end = HNS_ROCE_V1_FREE_MR_TIMEOUT_MSECS;
10951067 struct device *dev = &hr_dev->pdev->dev;
10961068 struct hns_roce_mr_free_work *mr_work;
1097
- struct hns_roce_free_mr *free_mr;
1098
- struct hns_roce_v1_priv *priv;
1099
- struct completion comp;
1100
- unsigned long end =
1101
- msecs_to_jiffies(HNS_ROCE_V1_FREE_MR_TIMEOUT_MSECS) + jiffies;
11021069 unsigned long start = jiffies;
1103
- int npages;
1070
+ struct completion comp;
11041071 int ret = 0;
11051072
1106
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1107
- free_mr = &priv->free_mr;
1108
-
11091073 if (mr->enabled) {
1110
- if (hns_roce_hw2sw_mpt(hr_dev, NULL, key_to_hw_index(mr->key)
1111
- & (hr_dev->caps.num_mtpts - 1)))
1112
- dev_warn(dev, "HW2SW_MPT failed!\n");
1074
+ if (hns_roce_hw_destroy_mpt(hr_dev, NULL,
1075
+ key_to_hw_index(mr->key) &
1076
+ (hr_dev->caps.num_mtpts - 1)))
1077
+ dev_warn(dev, "DESTROY_MPT failed!\n");
11131078 }
11141079
11151080 mr_work = kzalloc(sizeof(*mr_work), GFP_KERNEL);
....@@ -1128,10 +1093,11 @@
11281093
11291094 queue_work(free_mr->free_mr_wq, &(mr_work->work));
11301095
1131
- while (time_before_eq(jiffies, end)) {
1096
+ while (end > 0) {
11321097 if (try_wait_for_completion(&comp))
11331098 goto free_mr;
11341099 msleep(HNS_ROCE_V1_FREE_MR_WAIT_VALUE);
1100
+ end -= HNS_ROCE_V1_FREE_MR_WAIT_VALUE;
11351101 }
11361102
11371103 mr_work->comp_flag = 0;
....@@ -1145,18 +1111,9 @@
11451111 dev_dbg(dev, "Free mr 0x%x use 0x%x us.\n",
11461112 mr->key, jiffies_to_usecs(jiffies) - jiffies_to_usecs(start));
11471113
1148
- if (mr->size != ~0ULL) {
1149
- npages = ib_umem_page_count(mr->umem);
1150
- dma_free_coherent(dev, npages * 8, mr->pbl_buf,
1151
- mr->pbl_dma_addr);
1152
- }
1153
-
11541114 hns_roce_bitmap_free(&hr_dev->mr_table.mtpt_bitmap,
11551115 key_to_hw_index(mr->key), 0);
1156
-
1157
- if (mr->umem)
1158
- ib_umem_release(mr->umem);
1159
-
1116
+ hns_roce_mtr_destroy(hr_dev, &mr->pbl_mtr);
11601117 kfree(mr);
11611118
11621119 return ret;
....@@ -1164,12 +1121,9 @@
11641121
11651122 static void hns_roce_db_free(struct hns_roce_dev *hr_dev)
11661123 {
1124
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1125
+ struct hns_roce_db_table *db = &priv->db_table;
11671126 struct device *dev = &hr_dev->pdev->dev;
1168
- struct hns_roce_v1_priv *priv;
1169
- struct hns_roce_db_table *db;
1170
-
1171
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1172
- db = &priv->db_table;
11731127
11741128 if (db->sdb_ext_mod) {
11751129 dma_free_coherent(dev, HNS_ROCE_V1_EXT_SDB_SIZE,
....@@ -1190,17 +1144,14 @@
11901144
11911145 static int hns_roce_raq_init(struct hns_roce_dev *hr_dev)
11921146 {
1193
- int ret;
1194
- u32 val;
1195
- __le32 tmp;
1196
- int raq_shift = 0;
1197
- dma_addr_t addr;
1198
- struct hns_roce_v1_priv *priv;
1199
- struct hns_roce_raq_table *raq;
1147
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1148
+ struct hns_roce_raq_table *raq = &priv->raq_table;
12001149 struct device *dev = &hr_dev->pdev->dev;
1201
-
1202
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1203
- raq = &priv->raq_table;
1150
+ dma_addr_t addr;
1151
+ int raq_shift;
1152
+ __le32 tmp;
1153
+ u32 val;
1154
+ int ret;
12041155
12051156 raq->e_raq_buf = kzalloc(sizeof(*(raq->e_raq_buf)), GFP_KERNEL);
12061157 if (!raq->e_raq_buf)
....@@ -1280,12 +1231,9 @@
12801231
12811232 static void hns_roce_raq_free(struct hns_roce_dev *hr_dev)
12821233 {
1234
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1235
+ struct hns_roce_raq_table *raq = &priv->raq_table;
12831236 struct device *dev = &hr_dev->pdev->dev;
1284
- struct hns_roce_v1_priv *priv;
1285
- struct hns_roce_raq_table *raq;
1286
-
1287
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1288
- raq = &priv->raq_table;
12891237
12901238 dma_free_coherent(dev, HNS_ROCE_V1_RAQ_SIZE, raq->e_raq_buf->buf,
12911239 raq->e_raq_buf->map);
....@@ -1319,11 +1267,9 @@
13191267
13201268 static int hns_roce_bt_init(struct hns_roce_dev *hr_dev)
13211269 {
1270
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
13221271 struct device *dev = &hr_dev->pdev->dev;
1323
- struct hns_roce_v1_priv *priv;
13241272 int ret;
1325
-
1326
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
13271273
13281274 priv->bt_table.qpc_buf.buf = dma_alloc_coherent(dev,
13291275 HNS_ROCE_BT_RSV_BUF_SIZE, &priv->bt_table.qpc_buf.map,
....@@ -1362,10 +1308,8 @@
13621308
13631309 static void hns_roce_bt_free(struct hns_roce_dev *hr_dev)
13641310 {
1311
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
13651312 struct device *dev = &hr_dev->pdev->dev;
1366
- struct hns_roce_v1_priv *priv;
1367
-
1368
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
13691313
13701314 dma_free_coherent(dev, HNS_ROCE_BT_RSV_BUF_SIZE,
13711315 priv->bt_table.cqc_buf.buf, priv->bt_table.cqc_buf.map);
....@@ -1379,12 +1323,9 @@
13791323
13801324 static int hns_roce_tptr_init(struct hns_roce_dev *hr_dev)
13811325 {
1326
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1327
+ struct hns_roce_buf_list *tptr_buf = &priv->tptr_table.tptr_buf;
13821328 struct device *dev = &hr_dev->pdev->dev;
1383
- struct hns_roce_buf_list *tptr_buf;
1384
- struct hns_roce_v1_priv *priv;
1385
-
1386
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1387
- tptr_buf = &priv->tptr_table.tptr_buf;
13881329
13891330 /*
13901331 * This buffer will be used for CQ's tptr(tail pointer), also
....@@ -1405,12 +1346,9 @@
14051346
14061347 static void hns_roce_tptr_free(struct hns_roce_dev *hr_dev)
14071348 {
1349
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1350
+ struct hns_roce_buf_list *tptr_buf = &priv->tptr_table.tptr_buf;
14081351 struct device *dev = &hr_dev->pdev->dev;
1409
- struct hns_roce_buf_list *tptr_buf;
1410
- struct hns_roce_v1_priv *priv;
1411
-
1412
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1413
- tptr_buf = &priv->tptr_table.tptr_buf;
14141352
14151353 dma_free_coherent(dev, HNS_ROCE_V1_TPTR_BUF_SIZE,
14161354 tptr_buf->buf, tptr_buf->map);
....@@ -1418,13 +1356,10 @@
14181356
14191357 static int hns_roce_free_mr_init(struct hns_roce_dev *hr_dev)
14201358 {
1359
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1360
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
14211361 struct device *dev = &hr_dev->pdev->dev;
1422
- struct hns_roce_free_mr *free_mr;
1423
- struct hns_roce_v1_priv *priv;
1424
- int ret = 0;
1425
-
1426
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1427
- free_mr = &priv->free_mr;
1362
+ int ret;
14281363
14291364 free_mr->free_mr_wq = create_singlethread_workqueue("hns_roce_free_mr");
14301365 if (!free_mr->free_mr_wq) {
....@@ -1444,11 +1379,8 @@
14441379
14451380 static void hns_roce_free_mr_free(struct hns_roce_dev *hr_dev)
14461381 {
1447
- struct hns_roce_free_mr *free_mr;
1448
- struct hns_roce_v1_priv *priv;
1449
-
1450
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1451
- free_mr = &priv->free_mr;
1382
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1383
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
14521384
14531385 flush_workqueue(free_mr->free_mr_wq);
14541386 destroy_workqueue(free_mr->free_mr_wq);
....@@ -1505,42 +1437,10 @@
15051437 return ret;
15061438 }
15071439
1508
-static int hns_roce_des_qp_init(struct hns_roce_dev *hr_dev)
1509
-{
1510
- struct device *dev = &hr_dev->pdev->dev;
1511
- struct hns_roce_v1_priv *priv;
1512
- struct hns_roce_des_qp *des_qp;
1513
-
1514
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1515
- des_qp = &priv->des_qp;
1516
-
1517
- des_qp->requeue_flag = 1;
1518
- des_qp->qp_wq = create_singlethread_workqueue("hns_roce_destroy_qp");
1519
- if (!des_qp->qp_wq) {
1520
- dev_err(dev, "Create destroy qp workqueue failed!\n");
1521
- return -ENOMEM;
1522
- }
1523
-
1524
- return 0;
1525
-}
1526
-
1527
-static void hns_roce_des_qp_free(struct hns_roce_dev *hr_dev)
1528
-{
1529
- struct hns_roce_v1_priv *priv;
1530
- struct hns_roce_des_qp *des_qp;
1531
-
1532
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1533
- des_qp = &priv->des_qp;
1534
-
1535
- des_qp->requeue_flag = 0;
1536
- flush_workqueue(des_qp->qp_wq);
1537
- destroy_workqueue(des_qp->qp_wq);
1538
-}
1539
-
15401440 static int hns_roce_v1_profile(struct hns_roce_dev *hr_dev)
15411441 {
1542
- int i = 0;
15431442 struct hns_roce_caps *caps = &hr_dev->caps;
1443
+ int i;
15441444
15451445 hr_dev->vendor_id = roce_read(hr_dev, ROCEE_VENDOR_ID_REG);
15461446 hr_dev->vendor_part_id = roce_read(hr_dev, ROCEE_VENDOR_PART_ID_REG);
....@@ -1570,18 +1470,19 @@
15701470 caps->max_qp_dest_rdma = HNS_ROCE_V1_MAX_QP_DEST_RDMA;
15711471 caps->max_sq_desc_sz = HNS_ROCE_V1_MAX_SQ_DESC_SZ;
15721472 caps->max_rq_desc_sz = HNS_ROCE_V1_MAX_RQ_DESC_SZ;
1573
- caps->qpc_entry_sz = HNS_ROCE_V1_QPC_ENTRY_SIZE;
1473
+ caps->qpc_sz = HNS_ROCE_V1_QPC_SIZE;
15741474 caps->irrl_entry_sz = HNS_ROCE_V1_IRRL_ENTRY_SIZE;
15751475 caps->cqc_entry_sz = HNS_ROCE_V1_CQC_ENTRY_SIZE;
15761476 caps->mtpt_entry_sz = HNS_ROCE_V1_MTPT_ENTRY_SIZE;
15771477 caps->mtt_entry_sz = HNS_ROCE_V1_MTT_ENTRY_SIZE;
1578
- caps->cq_entry_sz = HNS_ROCE_V1_CQE_ENTRY_SIZE;
1478
+ caps->cqe_sz = HNS_ROCE_V1_CQE_SIZE;
15791479 caps->page_size_cap = HNS_ROCE_V1_PAGE_SIZE_SUPPORT;
15801480 caps->reserved_lkey = 0;
15811481 caps->reserved_pds = 0;
15821482 caps->reserved_mrws = 1;
15831483 caps->reserved_uars = 0;
15841484 caps->reserved_cqs = 0;
1485
+ caps->reserved_qps = 12; /* 2 SQP per port, six ports total 12 */
15851486 caps->chunk_sz = HNS_ROCE_V1_TABLE_CHUNK_SIZE;
15861487
15871488 for (i = 0; i < caps->num_ports; i++)
....@@ -1655,12 +1556,6 @@
16551556 goto error_failed_tptr_init;
16561557 }
16571558
1658
- ret = hns_roce_des_qp_init(hr_dev);
1659
- if (ret) {
1660
- dev_err(dev, "des qp init failed!\n");
1661
- goto error_failed_des_qp_init;
1662
- }
1663
-
16641559 ret = hns_roce_free_mr_init(hr_dev);
16651560 if (ret) {
16661561 dev_err(dev, "free mr init failed!\n");
....@@ -1672,9 +1567,6 @@
16721567 return 0;
16731568
16741569 error_failed_free_mr_init:
1675
- hns_roce_des_qp_free(hr_dev);
1676
-
1677
-error_failed_des_qp_init:
16781570 hns_roce_tptr_free(hr_dev);
16791571
16801572 error_failed_tptr_init:
....@@ -1692,7 +1584,6 @@
16921584 {
16931585 hns_roce_port_enable(hr_dev, HNS_ROCE_PORT_DOWN);
16941586 hns_roce_free_mr_free(hr_dev);
1695
- hns_roce_des_qp_free(hr_dev);
16961587 hns_roce_tptr_free(hr_dev);
16971588 hns_roce_bt_free(hr_dev);
16981589 hns_roce_raq_free(hr_dev);
....@@ -1744,8 +1635,6 @@
17441635
17451636 writel(val, hcr + 5);
17461637
1747
- mmiowb();
1748
-
17491638 return 0;
17501639 }
17511640
....@@ -1753,7 +1642,7 @@
17531642 unsigned long timeout)
17541643 {
17551644 u8 __iomem *hcr = hr_dev->reg_base + ROCEE_MB1_REG;
1756
- unsigned long end = 0;
1645
+ unsigned long end;
17571646 u32 status = 0;
17581647
17591648 end = msecs_to_jiffies(timeout) + jiffies;
....@@ -1779,10 +1668,13 @@
17791668 int gid_index, const union ib_gid *gid,
17801669 const struct ib_gid_attr *attr)
17811670 {
1671
+ unsigned long flags;
17821672 u32 *p = NULL;
1783
- u8 gid_idx = 0;
1673
+ u8 gid_idx;
17841674
17851675 gid_idx = hns_get_gid_index(hr_dev, port, gid_index);
1676
+
1677
+ spin_lock_irqsave(&hr_dev->iboe.lock, flags);
17861678
17871679 p = (u32 *)&gid->raw[0];
17881680 roce_raw_write(*p, hr_dev->reg_base + ROCEE_PORT_GID_L_0_REG +
....@@ -1799,6 +1691,8 @@
17991691 p = (u32 *)&gid->raw[0xc];
18001692 roce_raw_write(*p, hr_dev->reg_base + ROCEE_PORT_GID_H_0_REG +
18011693 (HNS_ROCE_V1_GID_NUM * gid_idx));
1694
+
1695
+ spin_unlock_irqrestore(&hr_dev->iboe.lock, flags);
18021696
18031697 return 0;
18041698 }
....@@ -1861,13 +1755,15 @@
18611755 val);
18621756 }
18631757
1864
-static int hns_roce_v1_write_mtpt(void *mb_buf, struct hns_roce_mr *mr,
1758
+static int hns_roce_v1_write_mtpt(struct hns_roce_dev *hr_dev, void *mb_buf,
1759
+ struct hns_roce_mr *mr,
18651760 unsigned long mtpt_idx)
18661761 {
1762
+ u64 pages[HNS_ROCE_MAX_INNER_MTPT_NUM] = { 0 };
1763
+ struct ib_device *ibdev = &hr_dev->ib_dev;
18671764 struct hns_roce_v1_mpt_entry *mpt_entry;
1868
- struct scatterlist *sg;
1869
- u64 *pages;
1870
- int entry;
1765
+ dma_addr_t pbl_ba;
1766
+ int count;
18711767 int i;
18721768
18731769 /* MPT filled into mailbox buf */
....@@ -1917,22 +1813,15 @@
19171813 if (mr->type == MR_TYPE_DMA)
19181814 return 0;
19191815
1920
- pages = (u64 *) __get_free_page(GFP_KERNEL);
1921
- if (!pages)
1922
- return -ENOMEM;
1923
-
1924
- i = 0;
1925
- for_each_sg(mr->umem->sg_head.sgl, sg, mr->umem->nmap, entry) {
1926
- pages[i] = ((u64)sg_dma_address(sg)) >> 12;
1927
-
1928
- /* Directly record to MTPT table firstly 7 entry */
1929
- if (i >= HNS_ROCE_MAX_INNER_MTPT_NUM)
1930
- break;
1931
- i++;
1816
+ count = hns_roce_mtr_find(hr_dev, &mr->pbl_mtr, 0, pages,
1817
+ ARRAY_SIZE(pages), &pbl_ba);
1818
+ if (count < 1) {
1819
+ ibdev_err(ibdev, "failed to find PBL mtr, count = %d.", count);
1820
+ return -ENOBUFS;
19321821 }
19331822
19341823 /* Register user mr */
1935
- for (i = 0; i < HNS_ROCE_MAX_INNER_MTPT_NUM; i++) {
1824
+ for (i = 0; i < count; i++) {
19361825 switch (i) {
19371826 case 0:
19381827 mpt_entry->pa0_l = cpu_to_le32((u32)(pages[i]));
....@@ -1998,21 +1887,16 @@
19981887 }
19991888 }
20001889
2001
- free_page((unsigned long) pages);
2002
-
2003
- mpt_entry->pbl_addr_l = cpu_to_le32((u32)(mr->pbl_dma_addr));
2004
-
1890
+ mpt_entry->pbl_addr_l = cpu_to_le32(pbl_ba);
20051891 roce_set_field(mpt_entry->mpt_byte_12, MPT_BYTE_12_PBL_ADDR_H_M,
2006
- MPT_BYTE_12_PBL_ADDR_H_S,
2007
- ((u32)(mr->pbl_dma_addr >> 32)));
1892
+ MPT_BYTE_12_PBL_ADDR_H_S, upper_32_bits(pbl_ba));
20081893
20091894 return 0;
20101895 }
20111896
20121897 static void *get_cqe(struct hns_roce_cq *hr_cq, int n)
20131898 {
2014
- return hns_roce_buf_offset(&hr_cq->hr_buf.hr_buf,
2015
- n * HNS_ROCE_V1_CQE_ENTRY_SIZE);
1899
+ return hns_roce_buf_offset(hr_cq->mtr.kmem, n * HNS_ROCE_V1_CQE_SIZE);
20161900 }
20171901
20181902 static void *get_sw_cqe(struct hns_roce_cq *hr_cq, int n)
....@@ -2021,7 +1905,7 @@
20211905
20221906 /* Get cqe when Owner bit is Conversely with the MSB of cons_idx */
20231907 return (roce_get_bit(hr_cqe->cqe_byte_4, CQE_BYTE_4_OWNER_S) ^
2024
- !!(n & (hr_cq->ib_cq.cqe + 1))) ? hr_cqe : NULL;
1908
+ !!(n & hr_cq->cq_depth)) ? hr_cqe : NULL;
20251909 }
20261910
20271911 static struct hns_roce_cqe *next_cqe_sw(struct hns_roce_cq *hr_cq)
....@@ -2104,19 +1988,14 @@
21041988
21051989 static void hns_roce_v1_write_cqc(struct hns_roce_dev *hr_dev,
21061990 struct hns_roce_cq *hr_cq, void *mb_buf,
2107
- u64 *mtts, dma_addr_t dma_handle, int nent,
2108
- u32 vector)
1991
+ u64 *mtts, dma_addr_t dma_handle)
21091992 {
2110
- struct hns_roce_cq_context *cq_context = NULL;
2111
- struct hns_roce_buf_list *tptr_buf;
2112
- struct hns_roce_v1_priv *priv;
1993
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1994
+ struct hns_roce_buf_list *tptr_buf = &priv->tptr_table.tptr_buf;
1995
+ struct hns_roce_cq_context *cq_context = mb_buf;
21131996 dma_addr_t tptr_dma_addr;
21141997 int offset;
21151998
2116
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
2117
- tptr_buf = &priv->tptr_table.tptr_buf;
2118
-
2119
- cq_context = mb_buf;
21201999 memset(cq_context, 0, sizeof(*cq_context));
21212000
21222001 /* Get the tptr for this CQ. */
....@@ -2140,9 +2019,9 @@
21402019 roce_set_field(cq_context->cqc_byte_12,
21412020 CQ_CONTEXT_CQC_BYTE_12_CQ_CQE_SHIFT_M,
21422021 CQ_CONTEXT_CQC_BYTE_12_CQ_CQE_SHIFT_S,
2143
- ilog2((unsigned int)nent));
2022
+ ilog2(hr_cq->cq_depth));
21442023 roce_set_field(cq_context->cqc_byte_12, CQ_CONTEXT_CQC_BYTE_12_CEQN_M,
2145
- CQ_CONTEXT_CQC_BYTE_12_CEQN_S, vector);
2024
+ CQ_CONTEXT_CQC_BYTE_12_CEQN_S, hr_cq->vector);
21462025
21472026 cq_context->cur_cqe_ba0_l = cpu_to_le32((u32)(mtts[0]));
21482027
....@@ -2193,7 +2072,7 @@
21932072 {
21942073 struct hns_roce_cq *hr_cq = to_hr_cq(ibcq);
21952074 u32 notification_flag;
2196
- __le32 doorbell[2];
2075
+ __le32 doorbell[2] = {};
21972076
21982077 notification_flag = (flags & IB_CQ_SOLICITED_MASK) ==
21992078 IB_CQ_SOLICITED ? CQ_DB_REQ_NOT : CQ_DB_REQ_NOT_SOL;
....@@ -2325,9 +2204,10 @@
23252204
23262205 if (is_send) {
23272206 /* SQ conrespond to CQE */
2328
- sq_wqe = get_send_wqe(*cur_qp, roce_get_field(cqe->cqe_byte_4,
2207
+ sq_wqe = hns_roce_get_send_wqe(*cur_qp,
2208
+ roce_get_field(cqe->cqe_byte_4,
23292209 CQE_BYTE_4_WQE_INDEX_M,
2330
- CQE_BYTE_4_WQE_INDEX_S)&
2210
+ CQE_BYTE_4_WQE_INDEX_S) &
23312211 ((*cur_qp)->sq.wqe_cnt-1));
23322212 switch (le32_to_cpu(sq_wqe->flag) & HNS_ROCE_WQE_OPCODE_MASK) {
23332213 case HNS_ROCE_WQE_OPCODE_SEND:
....@@ -2456,29 +2336,22 @@
24562336 struct hns_roce_hem_table *table, int obj,
24572337 int step_idx)
24582338 {
2339
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
24592340 struct device *dev = &hr_dev->pdev->dev;
2460
- struct hns_roce_v1_priv *priv;
2461
- unsigned long end = 0, flags = 0;
2341
+ long end = HW_SYNC_TIMEOUT_MSECS;
24622342 __le32 bt_cmd_val[2] = {0};
2343
+ unsigned long flags = 0;
24632344 void __iomem *bt_cmd;
24642345 u64 bt_ba = 0;
24652346
2466
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
2467
-
24682347 switch (table->type) {
24692348 case HEM_TYPE_QPC:
2470
- roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M,
2471
- ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, HEM_TYPE_QPC);
24722349 bt_ba = priv->bt_table.qpc_buf.map >> 12;
24732350 break;
24742351 case HEM_TYPE_MTPT:
2475
- roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M,
2476
- ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, HEM_TYPE_MTPT);
24772352 bt_ba = priv->bt_table.mtpt_buf.map >> 12;
24782353 break;
24792354 case HEM_TYPE_CQC:
2480
- roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M,
2481
- ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, HEM_TYPE_CQC);
24822355 bt_ba = priv->bt_table.cqc_buf.map >> 12;
24832356 break;
24842357 case HEM_TYPE_SRQC:
....@@ -2487,6 +2360,8 @@
24872360 default:
24882361 return 0;
24892362 }
2363
+ roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M,
2364
+ ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, table->type);
24902365 roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_M,
24912366 ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_S, obj);
24922367 roce_set_bit(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_S, 0);
....@@ -2496,10 +2371,9 @@
24962371
24972372 bt_cmd = hr_dev->reg_base + ROCEE_BT_CMD_H_REG;
24982373
2499
- end = msecs_to_jiffies(HW_SYNC_TIMEOUT_MSECS) + jiffies;
25002374 while (1) {
25012375 if (readl(bt_cmd) >> BT_CMD_SYNC_SHIFT) {
2502
- if (!(time_before(jiffies, end))) {
2376
+ if (!end) {
25032377 dev_err(dev, "Write bt_cmd err,hw_sync is not zero.\n");
25042378 spin_unlock_irqrestore(&hr_dev->bt_cmd_lock,
25052379 flags);
....@@ -2508,10 +2382,11 @@
25082382 } else {
25092383 break;
25102384 }
2511
- msleep(HW_SYNC_SLEEP_TIME_INTERVAL);
2385
+ mdelay(HW_SYNC_SLEEP_TIME_INTERVAL);
2386
+ end -= HW_SYNC_SLEEP_TIME_INTERVAL;
25122387 }
25132388
2514
- bt_cmd_val[0] = (__le32)bt_ba;
2389
+ bt_cmd_val[0] = cpu_to_le32(bt_ba);
25152390 roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_M,
25162391 ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_S, bt_ba >> 32);
25172392 hns_roce_write64_k(bt_cmd_val, hr_dev->reg_base + ROCEE_BT_CMD_L_REG);
....@@ -2522,7 +2397,6 @@
25222397 }
25232398
25242399 static int hns_roce_v1_qp_modify(struct hns_roce_dev *hr_dev,
2525
- struct hns_roce_mtt *mtt,
25262400 enum hns_roce_qp_state cur_state,
25272401 enum hns_roce_qp_state new_state,
25282402 struct hns_roce_qp_context *context,
....@@ -2569,7 +2443,7 @@
25692443
25702444 struct hns_roce_cmd_mailbox *mailbox;
25712445 struct device *dev = &hr_dev->pdev->dev;
2572
- int ret = 0;
2446
+ int ret;
25732447
25742448 if (cur_state >= HNS_ROCE_QP_NUM_STATE ||
25752449 new_state >= HNS_ROCE_QP_NUM_STATE ||
....@@ -2603,6 +2477,28 @@
26032477 return ret;
26042478 }
26052479
2480
+static int find_wqe_mtt(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
2481
+ u64 *sq_ba, u64 *rq_ba, dma_addr_t *bt_ba)
2482
+{
2483
+ struct ib_device *ibdev = &hr_dev->ib_dev;
2484
+ int count;
2485
+
2486
+ count = hns_roce_mtr_find(hr_dev, &hr_qp->mtr, 0, sq_ba, 1, bt_ba);
2487
+ if (count < 1) {
2488
+ ibdev_err(ibdev, "Failed to find SQ ba\n");
2489
+ return -ENOBUFS;
2490
+ }
2491
+
2492
+ count = hns_roce_mtr_find(hr_dev, &hr_qp->mtr, hr_qp->rq.offset, rq_ba,
2493
+ 1, NULL);
2494
+ if (!count) {
2495
+ ibdev_err(ibdev, "Failed to find RQ ba\n");
2496
+ return -ENOBUFS;
2497
+ }
2498
+
2499
+ return 0;
2500
+}
2501
+
26062502 static int hns_roce_v1_m_sqp(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
26072503 int attr_mask, enum ib_qp_state cur_state,
26082504 enum ib_qp_state new_state)
....@@ -2610,25 +2506,20 @@
26102506 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
26112507 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
26122508 struct hns_roce_sqp_context *context;
2613
- struct device *dev = &hr_dev->pdev->dev;
26142509 dma_addr_t dma_handle = 0;
26152510 u32 __iomem *addr;
2616
- int rq_pa_start;
2511
+ u64 sq_ba = 0;
2512
+ u64 rq_ba = 0;
26172513 __le32 tmp;
26182514 u32 reg_val;
2619
- u64 *mtts;
26202515
26212516 context = kzalloc(sizeof(*context), GFP_KERNEL);
26222517 if (!context)
26232518 return -ENOMEM;
26242519
26252520 /* Search QP buf's MTTs */
2626
- mtts = hns_roce_table_find(hr_dev, &hr_dev->mr_table.mtt_table,
2627
- hr_qp->mtt.first_seg, &dma_handle);
2628
- if (!mtts) {
2629
- dev_err(dev, "qp buf pa find failed\n");
2521
+ if (find_wqe_mtt(hr_dev, hr_qp, &sq_ba, &rq_ba, &dma_handle))
26302522 goto out;
2631
- }
26322523
26332524 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) {
26342525 roce_set_field(context->qp1c_bytes_4,
....@@ -2642,11 +2533,11 @@
26422533 roce_set_field(context->qp1c_bytes_4, QP1C_BYTES_4_PD_M,
26432534 QP1C_BYTES_4_PD_S, to_hr_pd(ibqp->pd)->pdn);
26442535
2645
- context->sq_rq_bt_l = cpu_to_le32((u32)(dma_handle));
2536
+ context->sq_rq_bt_l = cpu_to_le32(dma_handle);
26462537 roce_set_field(context->qp1c_bytes_12,
26472538 QP1C_BYTES_12_SQ_RQ_BT_H_M,
26482539 QP1C_BYTES_12_SQ_RQ_BT_H_S,
2649
- ((u32)(dma_handle >> 32)));
2540
+ upper_32_bits(dma_handle));
26502541
26512542 roce_set_field(context->qp1c_bytes_16, QP1C_BYTES_16_RQ_HEAD_M,
26522543 QP1C_BYTES_16_RQ_HEAD_S, hr_qp->rq.head);
....@@ -2654,7 +2545,7 @@
26542545 QP1C_BYTES_16_PORT_NUM_S, hr_qp->phy_port);
26552546 roce_set_bit(context->qp1c_bytes_16,
26562547 QP1C_BYTES_16_SIGNALING_TYPE_S,
2657
- le32_to_cpu(hr_qp->sq_signal_bits));
2548
+ hr_qp->sq_signal_bits);
26582549 roce_set_bit(context->qp1c_bytes_16, QP1C_BYTES_16_RQ_BA_FLG_S,
26592550 1);
26602551 roce_set_bit(context->qp1c_bytes_16, QP1C_BYTES_16_SQ_BA_FLG_S,
....@@ -2667,14 +2558,12 @@
26672558 roce_set_field(context->qp1c_bytes_20, QP1C_BYTES_20_PKEY_IDX_M,
26682559 QP1C_BYTES_20_PKEY_IDX_S, attr->pkey_index);
26692560
2670
- rq_pa_start = (u32)hr_qp->rq.offset / PAGE_SIZE;
2671
- context->cur_rq_wqe_ba_l =
2672
- cpu_to_le32((u32)(mtts[rq_pa_start]));
2561
+ context->cur_rq_wqe_ba_l = cpu_to_le32(rq_ba);
26732562
26742563 roce_set_field(context->qp1c_bytes_28,
26752564 QP1C_BYTES_28_CUR_RQ_WQE_BA_H_M,
26762565 QP1C_BYTES_28_CUR_RQ_WQE_BA_H_S,
2677
- (mtts[rq_pa_start]) >> 32);
2566
+ upper_32_bits(rq_ba));
26782567 roce_set_field(context->qp1c_bytes_28,
26792568 QP1C_BYTES_28_RQ_CUR_IDX_M,
26802569 QP1C_BYTES_28_RQ_CUR_IDX_S, 0);
....@@ -2688,12 +2577,12 @@
26882577 QP1C_BYTES_32_TX_CQ_NUM_S,
26892578 to_hr_cq(ibqp->send_cq)->cqn);
26902579
2691
- context->cur_sq_wqe_ba_l = cpu_to_le32((u32)mtts[0]);
2580
+ context->cur_sq_wqe_ba_l = cpu_to_le32(sq_ba);
26922581
26932582 roce_set_field(context->qp1c_bytes_40,
26942583 QP1C_BYTES_40_CUR_SQ_WQE_BA_H_M,
26952584 QP1C_BYTES_40_CUR_SQ_WQE_BA_H_S,
2696
- (mtts[0]) >> 32);
2585
+ upper_32_bits(sq_ba));
26972586 roce_set_field(context->qp1c_bytes_40,
26982587 QP1C_BYTES_40_SQ_CUR_IDX_M,
26992588 QP1C_BYTES_40_SQ_CUR_IDX_S, 0);
....@@ -2737,7 +2626,6 @@
27372626 hr_qp->rq.tail = 0;
27382627 hr_qp->sq.head = 0;
27392628 hr_qp->sq.tail = 0;
2740
- hr_qp->sq_next_wqe = 0;
27412629 }
27422630
27432631 kfree(context);
....@@ -2746,6 +2634,28 @@
27462634 out:
27472635 kfree(context);
27482636 return -EINVAL;
2637
+}
2638
+
2639
+static bool check_qp_state(enum ib_qp_state cur_state,
2640
+ enum ib_qp_state new_state)
2641
+{
2642
+ static const bool sm[][IB_QPS_ERR + 1] = {
2643
+ [IB_QPS_RESET] = { [IB_QPS_RESET] = true,
2644
+ [IB_QPS_INIT] = true },
2645
+ [IB_QPS_INIT] = { [IB_QPS_RESET] = true,
2646
+ [IB_QPS_INIT] = true,
2647
+ [IB_QPS_RTR] = true,
2648
+ [IB_QPS_ERR] = true },
2649
+ [IB_QPS_RTR] = { [IB_QPS_RESET] = true,
2650
+ [IB_QPS_RTS] = true,
2651
+ [IB_QPS_ERR] = true },
2652
+ [IB_QPS_RTS] = { [IB_QPS_RESET] = true, [IB_QPS_ERR] = true },
2653
+ [IB_QPS_SQD] = {},
2654
+ [IB_QPS_SQE] = {},
2655
+ [IB_QPS_ERR] = { [IB_QPS_RESET] = true, [IB_QPS_ERR] = true }
2656
+ };
2657
+
2658
+ return sm[cur_state][new_state];
27492659 }
27502660
27512661 static int hns_roce_v1_m_qp(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
....@@ -2760,26 +2670,29 @@
27602670 dma_addr_t dma_handle_2 = 0;
27612671 dma_addr_t dma_handle = 0;
27622672 __le32 doorbell[2] = {0};
2763
- int rq_pa_start = 0;
27642673 u64 *mtts_2 = NULL;
27652674 int ret = -EINVAL;
2766
- u64 *mtts = NULL;
2675
+ u64 sq_ba = 0;
2676
+ u64 rq_ba = 0;
27672677 int port;
27682678 u8 port_num;
27692679 u8 *dmac;
27702680 u8 *smac;
2681
+
2682
+ if (!check_qp_state(cur_state, new_state)) {
2683
+ ibdev_err(ibqp->device,
2684
+ "not support QP(%u) status from %d to %d\n",
2685
+ ibqp->qp_num, cur_state, new_state);
2686
+ return -EINVAL;
2687
+ }
27712688
27722689 context = kzalloc(sizeof(*context), GFP_KERNEL);
27732690 if (!context)
27742691 return -ENOMEM;
27752692
27762693 /* Search qp buf's mtts */
2777
- mtts = hns_roce_table_find(hr_dev, &hr_dev->mr_table.mtt_table,
2778
- hr_qp->mtt.first_seg, &dma_handle);
2779
- if (mtts == NULL) {
2780
- dev_err(dev, "qp buf pa find failed\n");
2694
+ if (find_wqe_mtt(hr_dev, hr_qp, &sq_ba, &rq_ba, &dma_handle))
27812695 goto out;
2782
- }
27832696
27842697 /* Search IRRL's mtts */
27852698 mtts_2 = hns_roce_table_find(hr_dev, &hr_dev->qp_table.irrl_table,
....@@ -2934,11 +2847,11 @@
29342847
29352848 dmac = (u8 *)attr->ah_attr.roce.dmac;
29362849
2937
- context->sq_rq_bt_l = cpu_to_le32((u32)(dma_handle));
2850
+ context->sq_rq_bt_l = cpu_to_le32(dma_handle);
29382851 roce_set_field(context->qpc_bytes_24,
29392852 QP_CONTEXT_QPC_BYTES_24_SQ_RQ_BT_H_M,
29402853 QP_CONTEXT_QPC_BYTES_24_SQ_RQ_BT_H_S,
2941
- ((u32)(dma_handle >> 32)));
2854
+ upper_32_bits(dma_handle));
29422855 roce_set_bit(context->qpc_bytes_24,
29432856 QP_CONTEXT_QPC_BYTE_24_REMOTE_ENABLE_E2E_CREDITS_S,
29442857 1);
....@@ -2960,7 +2873,7 @@
29602873 1);
29612874 roce_set_bit(context->qpc_bytes_32,
29622875 QP_CONTEXT_QPC_BYTE_32_SIGNALING_TYPE_S,
2963
- le32_to_cpu(hr_qp->sq_signal_bits));
2876
+ hr_qp->sq_signal_bits);
29642877
29652878 port = (attr_mask & IB_QP_PORT) ? (attr->port_num - 1) :
29662879 hr_qp->port;
....@@ -3037,14 +2950,12 @@
30372950 QP_CONTEXT_QPC_BYTES_68_RQ_CUR_INDEX_M,
30382951 QP_CONTEXT_QPC_BYTES_68_RQ_CUR_INDEX_S, 0);
30392952
3040
- rq_pa_start = (u32)hr_qp->rq.offset / PAGE_SIZE;
3041
- context->cur_rq_wqe_ba_l =
3042
- cpu_to_le32((u32)(mtts[rq_pa_start]));
2953
+ context->cur_rq_wqe_ba_l = cpu_to_le32(rq_ba);
30432954
30442955 roce_set_field(context->qpc_bytes_76,
30452956 QP_CONTEXT_QPC_BYTES_76_CUR_RQ_WQE_BA_H_M,
30462957 QP_CONTEXT_QPC_BYTES_76_CUR_RQ_WQE_BA_H_S,
3047
- mtts[rq_pa_start] >> 32);
2958
+ upper_32_bits(rq_ba));
30482959 roce_set_field(context->qpc_bytes_76,
30492960 QP_CONTEXT_QPC_BYTES_76_RX_REQ_MSN_M,
30502961 QP_CONTEXT_QPC_BYTES_76_RX_REQ_MSN_S, 0);
....@@ -3106,8 +3017,7 @@
31063017 QP_CONTEXT_QPC_BYTES_156_SL_S,
31073018 rdma_ah_get_sl(&attr->ah_attr));
31083019 hr_qp->sl = rdma_ah_get_sl(&attr->ah_attr);
3109
- } else if (cur_state == IB_QPS_RTR &&
3110
- new_state == IB_QPS_RTS) {
3020
+ } else if (cur_state == IB_QPS_RTR && new_state == IB_QPS_RTS) {
31113021 /* If exist optional param, return error */
31123022 if ((attr_mask & IB_QP_ALT_PATH) ||
31133023 (attr_mask & IB_QP_ACCESS_FLAGS) ||
....@@ -3119,12 +3029,12 @@
31193029 goto out;
31203030 }
31213031
3122
- context->rx_cur_sq_wqe_ba_l = cpu_to_le32((u32)(mtts[0]));
3032
+ context->rx_cur_sq_wqe_ba_l = cpu_to_le32(sq_ba);
31233033
31243034 roce_set_field(context->qpc_bytes_120,
31253035 QP_CONTEXT_QPC_BYTES_120_RX_CUR_SQ_WQE_BA_H_M,
31263036 QP_CONTEXT_QPC_BYTES_120_RX_CUR_SQ_WQE_BA_H_S,
3127
- (mtts[0]) >> 32);
3037
+ upper_32_bits(sq_ba));
31283038
31293039 roce_set_field(context->qpc_bytes_124,
31303040 QP_CONTEXT_QPC_BYTES_124_RX_ACK_MSN_M,
....@@ -3267,28 +3177,18 @@
32673177 QP_CONTEXT_QPC_BYTES_180_SQ_HEAD_M,
32683178 QP_CONTEXT_QPC_BYTES_180_SQ_HEAD_S, 0);
32693179
3270
- context->tx_cur_sq_wqe_ba_l = cpu_to_le32((u32)(mtts[0]));
3180
+ context->tx_cur_sq_wqe_ba_l = cpu_to_le32(sq_ba);
32713181
32723182 roce_set_field(context->qpc_bytes_188,
32733183 QP_CONTEXT_QPC_BYTES_188_TX_CUR_SQ_WQE_BA_H_M,
32743184 QP_CONTEXT_QPC_BYTES_188_TX_CUR_SQ_WQE_BA_H_S,
3275
- (mtts[0]) >> 32);
3185
+ upper_32_bits(sq_ba));
32763186 roce_set_bit(context->qpc_bytes_188,
32773187 QP_CONTEXT_QPC_BYTES_188_PKT_RETRY_FLG_S, 0);
32783188 roce_set_field(context->qpc_bytes_188,
32793189 QP_CONTEXT_QPC_BYTES_188_TX_RETRY_CUR_INDEX_M,
32803190 QP_CONTEXT_QPC_BYTES_188_TX_RETRY_CUR_INDEX_S,
32813191 0);
3282
- } else if (!((cur_state == IB_QPS_INIT && new_state == IB_QPS_RESET) ||
3283
- (cur_state == IB_QPS_INIT && new_state == IB_QPS_ERR) ||
3284
- (cur_state == IB_QPS_RTR && new_state == IB_QPS_RESET) ||
3285
- (cur_state == IB_QPS_RTR && new_state == IB_QPS_ERR) ||
3286
- (cur_state == IB_QPS_RTS && new_state == IB_QPS_RESET) ||
3287
- (cur_state == IB_QPS_RTS && new_state == IB_QPS_ERR) ||
3288
- (cur_state == IB_QPS_ERR && new_state == IB_QPS_RESET) ||
3289
- (cur_state == IB_QPS_ERR && new_state == IB_QPS_ERR))) {
3290
- dev_err(dev, "not support this status migration\n");
3291
- goto out;
32923192 }
32933193
32943194 /* Every status migrate must change state */
....@@ -3297,8 +3197,7 @@
32973197 QP_CONTEXT_QPC_BYTES_144_QP_STATE_S, new_state);
32983198
32993199 /* SW pass context to HW */
3300
- ret = hns_roce_v1_qp_modify(hr_dev, &hr_qp->mtt,
3301
- to_hns_roce_state(cur_state),
3200
+ ret = hns_roce_v1_qp_modify(hr_dev, to_hns_roce_state(cur_state),
33023201 to_hns_roce_state(new_state), context,
33033202 hr_qp);
33043203 if (ret) {
....@@ -3351,7 +3250,6 @@
33513250 hr_qp->rq.tail = 0;
33523251 hr_qp->sq.head = 0;
33533252 hr_qp->sq.tail = 0;
3354
- hr_qp->sq_next_wqe = 0;
33553253 }
33563254 out:
33573255 kfree(context);
....@@ -3494,7 +3392,7 @@
34943392 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
34953393 struct device *dev = &hr_dev->pdev->dev;
34963394 struct hns_roce_qp_context *context;
3497
- int tmp_qp_state = 0;
3395
+ int tmp_qp_state;
34983396 int ret = 0;
34993397 int state;
35003398
....@@ -3605,7 +3503,7 @@
36053503 qp_attr->retry_cnt = roce_get_field(context->qpc_bytes_148,
36063504 QP_CONTEXT_QPC_BYTES_148_RETRY_COUNT_M,
36073505 QP_CONTEXT_QPC_BYTES_148_RETRY_COUNT_S);
3608
- qp_attr->rnr_retry = (u8)context->rnr_retry;
3506
+ qp_attr->rnr_retry = (u8)le32_to_cpu(context->rnr_retry);
36093507
36103508 done:
36113509 qp_attr->cur_qp_state = qp_attr->qp_state;
....@@ -3639,372 +3537,47 @@
36393537 hns_roce_v1_q_qp(ibqp, qp_attr, qp_attr_mask, qp_init_attr);
36403538 }
36413539
3642
-static void hns_roce_check_sdb_status(struct hns_roce_dev *hr_dev,
3643
- u32 *old_send, u32 *old_retry,
3644
- u32 *tsp_st, u32 *success_flags)
3645
-{
3646
- __le32 *old_send_tmp, *old_retry_tmp;
3647
- u32 sdb_retry_cnt;
3648
- u32 sdb_send_ptr;
3649
- u32 cur_cnt, old_cnt;
3650
- __le32 tmp, tmp1;
3651
- u32 send_ptr;
3652
-
3653
- sdb_send_ptr = roce_read(hr_dev, ROCEE_SDB_SEND_PTR_REG);
3654
- sdb_retry_cnt = roce_read(hr_dev, ROCEE_SDB_RETRY_CNT_REG);
3655
- tmp = cpu_to_le32(sdb_send_ptr);
3656
- tmp1 = cpu_to_le32(sdb_retry_cnt);
3657
- cur_cnt = roce_get_field(tmp, ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_M,
3658
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_S) +
3659
- roce_get_field(tmp1, ROCEE_SDB_RETRY_CNT_SDB_RETRY_CT_M,
3660
- ROCEE_SDB_RETRY_CNT_SDB_RETRY_CT_S);
3661
-
3662
- old_send_tmp = (__le32 *)old_send;
3663
- old_retry_tmp = (__le32 *)old_retry;
3664
- if (!roce_get_bit(*tsp_st, ROCEE_CNT_CLR_CE_CNT_CLR_CE_S)) {
3665
- old_cnt = roce_get_field(*old_send_tmp,
3666
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_M,
3667
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_S) +
3668
- roce_get_field(*old_retry_tmp,
3669
- ROCEE_SDB_RETRY_CNT_SDB_RETRY_CT_M,
3670
- ROCEE_SDB_RETRY_CNT_SDB_RETRY_CT_S);
3671
- if (cur_cnt - old_cnt > SDB_ST_CMP_VAL)
3672
- *success_flags = 1;
3673
- } else {
3674
- old_cnt = roce_get_field(*old_send_tmp,
3675
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_M,
3676
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_S);
3677
- if (cur_cnt - old_cnt > SDB_ST_CMP_VAL) {
3678
- *success_flags = 1;
3679
- } else {
3680
- send_ptr = roce_get_field(*old_send_tmp,
3681
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_M,
3682
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_S) +
3683
- roce_get_field(tmp1,
3684
- ROCEE_SDB_RETRY_CNT_SDB_RETRY_CT_M,
3685
- ROCEE_SDB_RETRY_CNT_SDB_RETRY_CT_S);
3686
- roce_set_field(*old_send_tmp,
3687
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_M,
3688
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_S,
3689
- send_ptr);
3690
- }
3691
- }
3692
-}
3693
-
3694
-static int check_qp_db_process_status(struct hns_roce_dev *hr_dev,
3695
- struct hns_roce_qp *hr_qp,
3696
- u32 sdb_issue_ptr,
3697
- u32 *sdb_inv_cnt,
3698
- u32 *wait_stage)
3699
-{
3700
- struct device *dev = &hr_dev->pdev->dev;
3701
- u32 sdb_send_ptr, old_send;
3702
- __le32 sdb_issue_ptr_tmp;
3703
- __le32 sdb_send_ptr_tmp;
3704
- u32 success_flags = 0;
3705
- unsigned long end;
3706
- u32 old_retry;
3707
- u32 inv_cnt;
3708
- u32 tsp_st;
3709
- __le32 tmp;
3710
-
3711
- if (*wait_stage > HNS_ROCE_V1_DB_STAGE2 ||
3712
- *wait_stage < HNS_ROCE_V1_DB_STAGE1) {
3713
- dev_err(dev, "QP(0x%lx) db status wait stage(%d) error!\n",
3714
- hr_qp->qpn, *wait_stage);
3715
- return -EINVAL;
3716
- }
3717
-
3718
- /* Calculate the total timeout for the entire verification process */
3719
- end = msecs_to_jiffies(HNS_ROCE_V1_CHECK_DB_TIMEOUT_MSECS) + jiffies;
3720
-
3721
- if (*wait_stage == HNS_ROCE_V1_DB_STAGE1) {
3722
- /* Query db process status, until hw process completely */
3723
- sdb_send_ptr = roce_read(hr_dev, ROCEE_SDB_SEND_PTR_REG);
3724
- while (roce_hw_index_cmp_lt(sdb_send_ptr, sdb_issue_ptr,
3725
- ROCEE_SDB_PTR_CMP_BITS)) {
3726
- if (!time_before(jiffies, end)) {
3727
- dev_dbg(dev, "QP(0x%lx) db process stage1 timeout. issue 0x%x send 0x%x.\n",
3728
- hr_qp->qpn, sdb_issue_ptr,
3729
- sdb_send_ptr);
3730
- return 0;
3731
- }
3732
-
3733
- msleep(HNS_ROCE_V1_CHECK_DB_SLEEP_MSECS);
3734
- sdb_send_ptr = roce_read(hr_dev,
3735
- ROCEE_SDB_SEND_PTR_REG);
3736
- }
3737
-
3738
- sdb_send_ptr_tmp = cpu_to_le32(sdb_send_ptr);
3739
- sdb_issue_ptr_tmp = cpu_to_le32(sdb_issue_ptr);
3740
- if (roce_get_field(sdb_issue_ptr_tmp,
3741
- ROCEE_SDB_ISSUE_PTR_SDB_ISSUE_PTR_M,
3742
- ROCEE_SDB_ISSUE_PTR_SDB_ISSUE_PTR_S) ==
3743
- roce_get_field(sdb_send_ptr_tmp,
3744
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_M,
3745
- ROCEE_SDB_SEND_PTR_SDB_SEND_PTR_S)) {
3746
- old_send = roce_read(hr_dev, ROCEE_SDB_SEND_PTR_REG);
3747
- old_retry = roce_read(hr_dev, ROCEE_SDB_RETRY_CNT_REG);
3748
-
3749
- do {
3750
- tsp_st = roce_read(hr_dev, ROCEE_TSP_BP_ST_REG);
3751
- tmp = cpu_to_le32(tsp_st);
3752
- if (roce_get_bit(tmp,
3753
- ROCEE_TSP_BP_ST_QH_FIFO_ENTRY_S) == 1) {
3754
- *wait_stage = HNS_ROCE_V1_DB_WAIT_OK;
3755
- return 0;
3756
- }
3757
-
3758
- if (!time_before(jiffies, end)) {
3759
- dev_dbg(dev, "QP(0x%lx) db process stage1 timeout when send ptr equals issue ptr.\n"
3760
- "issue 0x%x send 0x%x.\n",
3761
- hr_qp->qpn,
3762
- le32_to_cpu(sdb_issue_ptr_tmp),
3763
- le32_to_cpu(sdb_send_ptr_tmp));
3764
- return 0;
3765
- }
3766
-
3767
- msleep(HNS_ROCE_V1_CHECK_DB_SLEEP_MSECS);
3768
-
3769
- hns_roce_check_sdb_status(hr_dev, &old_send,
3770
- &old_retry, &tsp_st,
3771
- &success_flags);
3772
- } while (!success_flags);
3773
- }
3774
-
3775
- *wait_stage = HNS_ROCE_V1_DB_STAGE2;
3776
-
3777
- /* Get list pointer */
3778
- *sdb_inv_cnt = roce_read(hr_dev, ROCEE_SDB_INV_CNT_REG);
3779
- dev_dbg(dev, "QP(0x%lx) db process stage2. inv cnt = 0x%x.\n",
3780
- hr_qp->qpn, *sdb_inv_cnt);
3781
- }
3782
-
3783
- if (*wait_stage == HNS_ROCE_V1_DB_STAGE2) {
3784
- /* Query db's list status, until hw reversal */
3785
- inv_cnt = roce_read(hr_dev, ROCEE_SDB_INV_CNT_REG);
3786
- while (roce_hw_index_cmp_lt(inv_cnt,
3787
- *sdb_inv_cnt + SDB_INV_CNT_OFFSET,
3788
- ROCEE_SDB_CNT_CMP_BITS)) {
3789
- if (!time_before(jiffies, end)) {
3790
- dev_dbg(dev, "QP(0x%lx) db process stage2 timeout. inv cnt 0x%x.\n",
3791
- hr_qp->qpn, inv_cnt);
3792
- return 0;
3793
- }
3794
-
3795
- msleep(HNS_ROCE_V1_CHECK_DB_SLEEP_MSECS);
3796
- inv_cnt = roce_read(hr_dev, ROCEE_SDB_INV_CNT_REG);
3797
- }
3798
-
3799
- *wait_stage = HNS_ROCE_V1_DB_WAIT_OK;
3800
- }
3801
-
3802
- return 0;
3803
-}
3804
-
3805
-static int check_qp_reset_state(struct hns_roce_dev *hr_dev,
3806
- struct hns_roce_qp *hr_qp,
3807
- struct hns_roce_qp_work *qp_work_entry,
3808
- int *is_timeout)
3809
-{
3810
- struct device *dev = &hr_dev->pdev->dev;
3811
- u32 sdb_issue_ptr;
3812
- int ret;
3813
-
3814
- if (hr_qp->state != IB_QPS_RESET) {
3815
- /* Set qp to ERR, waiting for hw complete processing all dbs */
3816
- ret = hns_roce_v1_modify_qp(&hr_qp->ibqp, NULL, 0, hr_qp->state,
3817
- IB_QPS_ERR);
3818
- if (ret) {
3819
- dev_err(dev, "Modify QP(0x%lx) to ERR failed!\n",
3820
- hr_qp->qpn);
3821
- return ret;
3822
- }
3823
-
3824
- /* Record issued doorbell */
3825
- sdb_issue_ptr = roce_read(hr_dev, ROCEE_SDB_ISSUE_PTR_REG);
3826
- qp_work_entry->sdb_issue_ptr = sdb_issue_ptr;
3827
- qp_work_entry->db_wait_stage = HNS_ROCE_V1_DB_STAGE1;
3828
-
3829
- /* Query db process status, until hw process completely */
3830
- ret = check_qp_db_process_status(hr_dev, hr_qp, sdb_issue_ptr,
3831
- &qp_work_entry->sdb_inv_cnt,
3832
- &qp_work_entry->db_wait_stage);
3833
- if (ret) {
3834
- dev_err(dev, "Check QP(0x%lx) db process status failed!\n",
3835
- hr_qp->qpn);
3836
- return ret;
3837
- }
3838
-
3839
- if (qp_work_entry->db_wait_stage != HNS_ROCE_V1_DB_WAIT_OK) {
3840
- qp_work_entry->sche_cnt = 0;
3841
- *is_timeout = 1;
3842
- return 0;
3843
- }
3844
-
3845
- /* Modify qp to reset before destroying qp */
3846
- ret = hns_roce_v1_modify_qp(&hr_qp->ibqp, NULL, 0, hr_qp->state,
3847
- IB_QPS_RESET);
3848
- if (ret) {
3849
- dev_err(dev, "Modify QP(0x%lx) to RST failed!\n",
3850
- hr_qp->qpn);
3851
- return ret;
3852
- }
3853
- }
3854
-
3855
- return 0;
3856
-}
3857
-
3858
-static void hns_roce_v1_destroy_qp_work_fn(struct work_struct *work)
3859
-{
3860
- struct hns_roce_qp_work *qp_work_entry;
3861
- struct hns_roce_v1_priv *priv;
3862
- struct hns_roce_dev *hr_dev;
3863
- struct hns_roce_qp *hr_qp;
3864
- struct device *dev;
3865
- unsigned long qpn;
3866
- int ret;
3867
-
3868
- qp_work_entry = container_of(work, struct hns_roce_qp_work, work);
3869
- hr_dev = to_hr_dev(qp_work_entry->ib_dev);
3870
- dev = &hr_dev->pdev->dev;
3871
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
3872
- hr_qp = qp_work_entry->qp;
3873
- qpn = hr_qp->qpn;
3874
-
3875
- dev_dbg(dev, "Schedule destroy QP(0x%lx) work.\n", qpn);
3876
-
3877
- qp_work_entry->sche_cnt++;
3878
-
3879
- /* Query db process status, until hw process completely */
3880
- ret = check_qp_db_process_status(hr_dev, hr_qp,
3881
- qp_work_entry->sdb_issue_ptr,
3882
- &qp_work_entry->sdb_inv_cnt,
3883
- &qp_work_entry->db_wait_stage);
3884
- if (ret) {
3885
- dev_err(dev, "Check QP(0x%lx) db process status failed!\n",
3886
- qpn);
3887
- return;
3888
- }
3889
-
3890
- if (qp_work_entry->db_wait_stage != HNS_ROCE_V1_DB_WAIT_OK &&
3891
- priv->des_qp.requeue_flag) {
3892
- queue_work(priv->des_qp.qp_wq, work);
3893
- return;
3894
- }
3895
-
3896
- /* Modify qp to reset before destroying qp */
3897
- ret = hns_roce_v1_modify_qp(&hr_qp->ibqp, NULL, 0, hr_qp->state,
3898
- IB_QPS_RESET);
3899
- if (ret) {
3900
- dev_err(dev, "Modify QP(0x%lx) to RST failed!\n", qpn);
3901
- return;
3902
- }
3903
-
3904
- hns_roce_qp_remove(hr_dev, hr_qp);
3905
- hns_roce_qp_free(hr_dev, hr_qp);
3906
-
3907
- if (hr_qp->ibqp.qp_type == IB_QPT_RC) {
3908
- /* RC QP, release QPN */
3909
- hns_roce_release_range_qp(hr_dev, qpn, 1);
3910
- kfree(hr_qp);
3911
- } else
3912
- kfree(hr_to_hr_sqp(hr_qp));
3913
-
3914
- kfree(qp_work_entry);
3915
-
3916
- dev_dbg(dev, "Accomplished destroy QP(0x%lx) work.\n", qpn);
3917
-}
3918
-
3919
-int hns_roce_v1_destroy_qp(struct ib_qp *ibqp)
3540
+int hns_roce_v1_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
39203541 {
39213542 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
39223543 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
3923
- struct device *dev = &hr_dev->pdev->dev;
3924
- struct hns_roce_qp_work qp_work_entry;
3925
- struct hns_roce_qp_work *qp_work;
3926
- struct hns_roce_v1_priv *priv;
39273544 struct hns_roce_cq *send_cq, *recv_cq;
3928
- int is_user = !!ibqp->pd->uobject;
3929
- int is_timeout = 0;
39303545 int ret;
39313546
3932
- ret = check_qp_reset_state(hr_dev, hr_qp, &qp_work_entry, &is_timeout);
3933
- if (ret) {
3934
- dev_err(dev, "QP reset state check failed(%d)!\n", ret);
3547
+ ret = hns_roce_v1_modify_qp(ibqp, NULL, 0, hr_qp->state, IB_QPS_RESET);
3548
+ if (ret)
39353549 return ret;
3936
- }
39373550
3938
- send_cq = to_hr_cq(hr_qp->ibqp.send_cq);
3939
- recv_cq = to_hr_cq(hr_qp->ibqp.recv_cq);
3551
+ send_cq = hr_qp->ibqp.send_cq ? to_hr_cq(hr_qp->ibqp.send_cq) : NULL;
3552
+ recv_cq = hr_qp->ibqp.recv_cq ? to_hr_cq(hr_qp->ibqp.recv_cq) : NULL;
39403553
39413554 hns_roce_lock_cqs(send_cq, recv_cq);
3942
- if (!is_user) {
3943
- __hns_roce_v1_cq_clean(recv_cq, hr_qp->qpn, hr_qp->ibqp.srq ?
3944
- to_hr_srq(hr_qp->ibqp.srq) : NULL);
3945
- if (send_cq != recv_cq)
3555
+ if (!udata) {
3556
+ if (recv_cq)
3557
+ __hns_roce_v1_cq_clean(recv_cq, hr_qp->qpn,
3558
+ (hr_qp->ibqp.srq ?
3559
+ to_hr_srq(hr_qp->ibqp.srq) :
3560
+ NULL));
3561
+
3562
+ if (send_cq && send_cq != recv_cq)
39463563 __hns_roce_v1_cq_clean(send_cq, hr_qp->qpn, NULL);
39473564 }
3565
+ hns_roce_qp_remove(hr_dev, hr_qp);
39483566 hns_roce_unlock_cqs(send_cq, recv_cq);
39493567
3950
- if (!is_timeout) {
3951
- hns_roce_qp_remove(hr_dev, hr_qp);
3952
- hns_roce_qp_free(hr_dev, hr_qp);
3953
-
3954
- /* RC QP, release QPN */
3955
- if (hr_qp->ibqp.qp_type == IB_QPT_RC)
3956
- hns_roce_release_range_qp(hr_dev, hr_qp->qpn, 1);
3957
- }
3958
-
3959
- hns_roce_mtt_cleanup(hr_dev, &hr_qp->mtt);
3960
-
3961
- if (is_user)
3962
- ib_umem_release(hr_qp->umem);
3963
- else {
3964
- kfree(hr_qp->sq.wrid);
3965
- kfree(hr_qp->rq.wrid);
3966
-
3967
- hns_roce_buf_free(hr_dev, hr_qp->buff_size, &hr_qp->hr_buf);
3968
- }
3969
-
3970
- if (!is_timeout) {
3971
- if (hr_qp->ibqp.qp_type == IB_QPT_RC)
3972
- kfree(hr_qp);
3973
- else
3974
- kfree(hr_to_hr_sqp(hr_qp));
3975
- } else {
3976
- qp_work = kzalloc(sizeof(*qp_work), GFP_KERNEL);
3977
- if (!qp_work)
3978
- return -ENOMEM;
3979
-
3980
- INIT_WORK(&qp_work->work, hns_roce_v1_destroy_qp_work_fn);
3981
- qp_work->ib_dev = &hr_dev->ib_dev;
3982
- qp_work->qp = hr_qp;
3983
- qp_work->db_wait_stage = qp_work_entry.db_wait_stage;
3984
- qp_work->sdb_issue_ptr = qp_work_entry.sdb_issue_ptr;
3985
- qp_work->sdb_inv_cnt = qp_work_entry.sdb_inv_cnt;
3986
- qp_work->sche_cnt = qp_work_entry.sche_cnt;
3987
-
3988
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
3989
- queue_work(priv->des_qp.qp_wq, &qp_work->work);
3990
- dev_dbg(dev, "Begin destroy QP(0x%lx) work.\n", hr_qp->qpn);
3991
- }
3568
+ hns_roce_qp_destroy(hr_dev, hr_qp, udata);
39923569
39933570 return 0;
39943571 }
39953572
3996
-static int hns_roce_v1_destroy_cq(struct ib_cq *ibcq)
3573
+static int hns_roce_v1_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
39973574 {
39983575 struct hns_roce_dev *hr_dev = to_hr_dev(ibcq->device);
39993576 struct hns_roce_cq *hr_cq = to_hr_cq(ibcq);
40003577 struct device *dev = &hr_dev->pdev->dev;
40013578 u32 cqe_cnt_ori;
40023579 u32 cqe_cnt_cur;
4003
- u32 cq_buf_size;
40043580 int wait_time = 0;
4005
- int ret = 0;
4006
-
4007
- hns_roce_free_cq(hr_dev, hr_cq);
40083581
40093582 /*
40103583 * Before freeing cq buffer, we need to ensure that the outstanding CQE
....@@ -4024,25 +3597,11 @@
40243597 if (wait_time > HNS_ROCE_MAX_FREE_CQ_WAIT_CNT) {
40253598 dev_warn(dev, "Destroy cq 0x%lx timeout!\n",
40263599 hr_cq->cqn);
4027
- ret = -ETIMEDOUT;
40283600 break;
40293601 }
40303602 wait_time++;
40313603 }
4032
-
4033
- hns_roce_mtt_cleanup(hr_dev, &hr_cq->hr_buf.hr_mtt);
4034
-
4035
- if (ibcq->uobject)
4036
- ib_umem_release(hr_cq->umem);
4037
- else {
4038
- /* Free the buff of stored cq */
4039
- cq_buf_size = (ibcq->cqe + 1) * hr_dev->caps.cq_entry_sz;
4040
- hns_roce_buf_free(hr_dev, cq_buf_size, &hr_cq->hr_buf.hr_buf);
4041
- }
4042
-
4043
- kfree(hr_cq);
4044
-
4045
- return ret;
3604
+ return 0;
40463605 }
40473606
40483607 static void set_eq_cons_index_v1(struct hns_roce_eq *eq, int req_not)
....@@ -4215,8 +3774,7 @@
42153774
42163775 static struct hns_roce_aeqe *get_aeqe_v1(struct hns_roce_eq *eq, u32 entry)
42173776 {
4218
- unsigned long off = (entry & (eq->entries - 1)) *
4219
- HNS_ROCE_AEQ_ENTRY_SIZE;
3777
+ unsigned long off = (entry & (eq->entries - 1)) * HNS_ROCE_AEQE_SIZE;
42203778
42213779 return (struct hns_roce_aeqe *)((u8 *)
42223780 (eq->buf_list[off / HNS_ROCE_BA_SIZE].buf) +
....@@ -4246,7 +3804,8 @@
42463804 */
42473805 dma_rmb();
42483806
4249
- dev_dbg(dev, "aeqe = %p, aeqe->asyn.event_type = 0x%lx\n", aeqe,
3807
+ dev_dbg(dev, "aeqe = %pK, aeqe->asyn.event_type = 0x%lx\n",
3808
+ aeqe,
42503809 roce_get_field(aeqe->asyn,
42513810 HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M,
42523811 HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S));
....@@ -4309,10 +3868,8 @@
43093868 eq->cons_index++;
43103869 aeqes_found = 1;
43113870
4312
- if (eq->cons_index > 2 * hr_dev->caps.aeqe_depth - 1) {
4313
- dev_warn(dev, "cons_index overflow, set back to 0.\n");
3871
+ if (eq->cons_index > 2 * hr_dev->caps.aeqe_depth - 1)
43143872 eq->cons_index = 0;
4315
- }
43163873 }
43173874
43183875 set_eq_cons_index_v1(eq, 0);
....@@ -4322,8 +3879,7 @@
43223879
43233880 static struct hns_roce_ceqe *get_ceqe_v1(struct hns_roce_eq *eq, u32 entry)
43243881 {
4325
- unsigned long off = (entry & (eq->entries - 1)) *
4326
- HNS_ROCE_CEQ_ENTRY_SIZE;
3882
+ unsigned long off = (entry & (eq->entries - 1)) * HNS_ROCE_CEQE_SIZE;
43273883
43283884 return (struct hns_roce_ceqe *)((u8 *)
43293885 (eq->buf_list[off / HNS_ROCE_BA_SIZE].buf) +
....@@ -4361,11 +3917,9 @@
43613917 ++eq->cons_index;
43623918 ceqes_found = 1;
43633919
4364
- if (eq->cons_index > 2 * hr_dev->caps.ceqe_depth - 1) {
4365
- dev_warn(&eq->hr_dev->pdev->dev,
4366
- "cons_index overflow, set back to 0.\n");
3920
+ if (eq->cons_index >
3921
+ EQ_DEPTH_COEFF * hr_dev->caps.ceqe_depth - 1)
43673922 eq->cons_index = 0;
4368
- }
43693923 }
43703924
43713925 set_eq_cons_index_v1(eq, 0);
....@@ -4377,7 +3931,7 @@
43773931 {
43783932 struct hns_roce_eq *eq = eq_ptr;
43793933 struct hns_roce_dev *hr_dev = eq->hr_dev;
4380
- int int_work = 0;
3934
+ int int_work;
43813935
43823936 if (eq->type_flag == HNS_ROCE_CEQ)
43833937 /* CEQ irq routine, CEQ is pulse irq, not clear */
....@@ -4575,9 +4129,9 @@
45754129 void __iomem *eqc = hr_dev->eq_table.eqc_base[eq->eqn];
45764130 struct device *dev = &hr_dev->pdev->dev;
45774131 dma_addr_t tmp_dma_addr;
4578
- u32 eqconsindx_val = 0;
45794132 u32 eqcuridx_val = 0;
4580
- u32 eqshift_val = 0;
4133
+ u32 eqconsindx_val;
4134
+ u32 eqshift_val;
45814135 __le32 tmp2 = 0;
45824136 __le32 tmp1 = 0;
45834137 __le32 tmp = 0;
....@@ -4609,7 +4163,6 @@
46094163 }
46104164
46114165 eq->buf_list[i].map = tmp_dma_addr;
4612
- memset(eq->buf_list[i].buf, 0, HNS_ROCE_BA_SIZE);
46134166 }
46144167 eq->cons_index = 0;
46154168 roce_set_field(tmp, ROCEE_CAEP_AEQC_AEQE_SHIFT_CAEP_AEQC_STATE_M,
....@@ -4697,7 +4250,7 @@
46974250 CEQ_REG_OFFSET * i;
46984251 eq->entries = hr_dev->caps.ceqe_depth;
46994252 eq->log_entries = ilog2(eq->entries);
4700
- eq->eqe_size = HNS_ROCE_CEQ_ENTRY_SIZE;
4253
+ eq->eqe_size = HNS_ROCE_CEQE_SIZE;
47014254 } else {
47024255 /* AEQ */
47034256 eq_table->eqc_base[i] = hr_dev->reg_base +
....@@ -4707,7 +4260,7 @@
47074260 ROCEE_CAEP_AEQE_CONS_IDX_REG;
47084261 eq->entries = hr_dev->caps.aeqe_depth;
47094262 eq->log_entries = ilog2(eq->entries);
4710
- eq->eqe_size = HNS_ROCE_AEQ_ENTRY_SIZE;
4263
+ eq->eqe_size = HNS_ROCE_AEQE_SIZE;
47114264 }
47124265 }
47134266
....@@ -4792,6 +4345,16 @@
47924345 kfree(eq_table->eq);
47934346 }
47944347
4348
+static const struct ib_device_ops hns_roce_v1_dev_ops = {
4349
+ .destroy_qp = hns_roce_v1_destroy_qp,
4350
+ .modify_cq = hns_roce_v1_modify_cq,
4351
+ .poll_cq = hns_roce_v1_poll_cq,
4352
+ .post_recv = hns_roce_v1_post_recv,
4353
+ .post_send = hns_roce_v1_post_send,
4354
+ .query_qp = hns_roce_v1_query_qp,
4355
+ .req_notify_cq = hns_roce_v1_req_notify_cq,
4356
+};
4357
+
47954358 static const struct hns_roce_hw hns_roce_hw_v1 = {
47964359 .reset = hns_roce_v1_reset,
47974360 .hw_profile = hns_roce_v1_profile,
....@@ -4817,6 +4380,7 @@
48174380 .destroy_cq = hns_roce_v1_destroy_cq,
48184381 .init_eq = hns_roce_v1_init_eq_table,
48194382 .cleanup_eq = hns_roce_v1_cleanup_eq_table,
4383
+ .hns_roce_dev_ops = &hns_roce_v1_dev_ops,
48204384 };
48214385
48224386 static const struct of_device_id hns_roce_of_match[] = {
....@@ -4831,19 +4395,13 @@
48314395 };
48324396 MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
48334397
4834
-static int hns_roce_node_match(struct device *dev, void *fwnode)
4835
-{
4836
- return dev->fwnode == fwnode;
4837
-}
4838
-
48394398 static struct
48404399 platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
48414400 {
48424401 struct device *dev;
48434402
48444403 /* get the 'device' corresponding to the matching 'fwnode' */
4845
- dev = bus_find_device(&platform_bus_type, NULL,
4846
- fwnode, hns_roce_node_match);
4404
+ dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
48474405 /* get the platform device */
48484406 return dev ? to_platform_device(dev) : NULL;
48494407 }
....@@ -4854,7 +4412,6 @@
48544412 struct platform_device *pdev = NULL;
48554413 struct net_device *netdev = NULL;
48564414 struct device_node *net_node;
4857
- struct resource *res;
48584415 int port_cnt = 0;
48594416 u8 phy_port;
48604417 int ret;
....@@ -4893,8 +4450,7 @@
48934450 }
48944451
48954452 /* get the mapped register base address */
4896
- res = platform_get_resource(hr_dev->pdev, IORESOURCE_MEM, 0);
4897
- hr_dev->reg_base = devm_ioremap_resource(dev, res);
4453
+ hr_dev->reg_base = devm_platform_ioremap_resource(hr_dev->pdev, 0);
48984454 if (IS_ERR(hr_dev->reg_base))
48994455 return PTR_ERR(hr_dev->reg_base);
49004456
....@@ -4969,10 +4525,8 @@
49694525 /* fetch the interrupt numbers */
49704526 for (i = 0; i < HNS_ROCE_V1_MAX_IRQ_NUM; i++) {
49714527 hr_dev->irq[i] = platform_get_irq(hr_dev->pdev, i);
4972
- if (hr_dev->irq[i] <= 0) {
4973
- dev_err(dev, "platform get of irq[=%d] failed!\n", i);
4528
+ if (hr_dev->irq[i] <= 0)
49744529 return -EINVAL;
4975
- }
49764530 }
49774531
49784532 return 0;
....@@ -4990,7 +4544,7 @@
49904544 struct hns_roce_dev *hr_dev;
49914545 struct device *dev = &pdev->dev;
49924546
4993
- hr_dev = (struct hns_roce_dev *)ib_alloc_device(sizeof(*hr_dev));
4547
+ hr_dev = ib_alloc_device(hns_roce_dev, ib_dev);
49944548 if (!hr_dev)
49954549 return -ENOMEM;
49964550