hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
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
....@@ -242,7 +239,7 @@
242239 break;
243240 }
244241
245
- /*Ctrl field, ctrl set type: sig, solic, imm, fence */
242
+ /* Ctrl field, ctrl set type: sig, solic, imm, fence */
246243 /* SO wait for conforming application scenarios */
247244 ctrl->flag |= (wr->send_flags & IB_SEND_SIGNALED ?
248245 cpu_to_le32(HNS_ROCE_WQE_CQ_NOTIFY) : 0) |
....@@ -303,14 +300,13 @@
303300 }
304301 ctrl->flag |= cpu_to_le32(HNS_ROCE_WQE_INLINE);
305302 } else {
306
- /*sqe num is two */
303
+ /* sqe num is two */
307304 for (i = 0; i < wr->num_sge; i++)
308305 set_data_seg(dseg + i, wr->sg_list + i);
309306
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);
....@@ -460,6 +448,82 @@
460448 roce_set_bit(tmp, ROCEE_GLB_CFG_ROCEE_DB_OTH_MODE_S, odb_mode);
461449 val = le32_to_cpu(tmp);
462450 roce_write(hr_dev, ROCEE_GLB_CFG_REG, val);
451
+}
452
+
453
+static int hns_roce_v1_set_hem(struct hns_roce_dev *hr_dev,
454
+ struct hns_roce_hem_table *table, int obj,
455
+ int step_idx)
456
+{
457
+ spinlock_t *lock = &hr_dev->bt_cmd_lock;
458
+ struct device *dev = hr_dev->dev;
459
+ struct hns_roce_hem_iter iter;
460
+ void __iomem *bt_cmd;
461
+ __le32 bt_cmd_val[2];
462
+ __le32 bt_cmd_h = 0;
463
+ unsigned long flags;
464
+ __le32 bt_cmd_l;
465
+ int ret = 0;
466
+ u64 bt_ba;
467
+ long end;
468
+
469
+ /* Find the HEM(Hardware Entry Memory) entry */
470
+ unsigned long i = (obj & (table->num_obj - 1)) /
471
+ (table->table_chunk_size / table->obj_size);
472
+
473
+ switch (table->type) {
474
+ case HEM_TYPE_QPC:
475
+ case HEM_TYPE_MTPT:
476
+ case HEM_TYPE_CQC:
477
+ case HEM_TYPE_SRQC:
478
+ roce_set_field(bt_cmd_h, ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M,
479
+ ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, table->type);
480
+ break;
481
+ default:
482
+ return ret;
483
+ }
484
+
485
+ roce_set_field(bt_cmd_h, ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_M,
486
+ ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_S, obj);
487
+ roce_set_bit(bt_cmd_h, ROCEE_BT_CMD_H_ROCEE_BT_CMD_S, 0);
488
+ roce_set_bit(bt_cmd_h, ROCEE_BT_CMD_H_ROCEE_BT_CMD_HW_SYNS_S, 1);
489
+
490
+ /* Currently iter only a chunk */
491
+ for (hns_roce_hem_first(table->hem[i], &iter);
492
+ !hns_roce_hem_last(&iter); hns_roce_hem_next(&iter)) {
493
+ bt_ba = hns_roce_hem_addr(&iter) >> HNS_HW_PAGE_SHIFT;
494
+
495
+ spin_lock_irqsave(lock, flags);
496
+
497
+ bt_cmd = hr_dev->reg_base + ROCEE_BT_CMD_H_REG;
498
+
499
+ end = HW_SYNC_TIMEOUT_MSECS;
500
+ while (end > 0) {
501
+ if (!(readl(bt_cmd) >> BT_CMD_SYNC_SHIFT))
502
+ break;
503
+
504
+ mdelay(HW_SYNC_SLEEP_TIME_INTERVAL);
505
+ end -= HW_SYNC_SLEEP_TIME_INTERVAL;
506
+ }
507
+
508
+ if (end <= 0) {
509
+ dev_err(dev, "Write bt_cmd err,hw_sync is not zero.\n");
510
+ spin_unlock_irqrestore(lock, flags);
511
+ return -EBUSY;
512
+ }
513
+
514
+ bt_cmd_l = cpu_to_le32(bt_ba);
515
+ roce_set_field(bt_cmd_h, ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_M,
516
+ ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_S,
517
+ upper_32_bits(bt_ba));
518
+
519
+ bt_cmd_val[0] = bt_cmd_l;
520
+ bt_cmd_val[1] = bt_cmd_h;
521
+ hns_roce_write64_k(bt_cmd_val,
522
+ hr_dev->reg_base + ROCEE_BT_CMD_L_REG);
523
+ spin_unlock_irqrestore(lock, flags);
524
+ }
525
+
526
+ return ret;
463527 }
464528
465529 static void hns_roce_set_db_ext_mode(struct hns_roce_dev *hr_dev, u32 sdb_mode,
....@@ -514,15 +578,12 @@
514578 static void hns_roce_set_sdb_ext(struct hns_roce_dev *hr_dev, u32 ext_sdb_alept,
515579 u32 ext_sdb_alful)
516580 {
581
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
582
+ struct hns_roce_db_table *db = &priv->db_table;
517583 struct device *dev = &hr_dev->pdev->dev;
518
- struct hns_roce_v1_priv *priv;
519
- struct hns_roce_db_table *db;
520584 dma_addr_t sdb_dma_addr;
521585 __le32 tmp;
522586 u32 val;
523
-
524
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
525
- db = &priv->db_table;
526587
527588 /* Configure extend SDB threshold */
528589 roce_write(hr_dev, ROCEE_EXT_DB_SQ_WL_EMPTY_REG, ext_sdb_alept);
....@@ -549,22 +610,19 @@
549610 roce_write(hr_dev, ROCEE_EXT_DB_SQ_H_REG, val);
550611
551612 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",
613
+ dev_dbg(dev, "ext SDB threshold: empty: 0x%x, ful: 0x%x\n",
553614 ext_sdb_alept, ext_sdb_alful);
554615 }
555616
556617 static void hns_roce_set_odb_ext(struct hns_roce_dev *hr_dev, u32 ext_odb_alept,
557618 u32 ext_odb_alful)
558619 {
620
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
621
+ struct hns_roce_db_table *db = &priv->db_table;
559622 struct device *dev = &hr_dev->pdev->dev;
560
- struct hns_roce_v1_priv *priv;
561
- struct hns_roce_db_table *db;
562623 dma_addr_t odb_dma_addr;
563624 __le32 tmp;
564625 u32 val;
565
-
566
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
567
- db = &priv->db_table;
568626
569627 /* Configure extend ODB threshold */
570628 roce_write(hr_dev, ROCEE_EXT_DB_OTHERS_WL_EMPTY_REG, ext_odb_alept);
....@@ -594,15 +652,12 @@
594652 static int hns_roce_db_ext_init(struct hns_roce_dev *hr_dev, u32 sdb_ext_mod,
595653 u32 odb_ext_mod)
596654 {
655
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
656
+ struct hns_roce_db_table *db = &priv->db_table;
597657 struct device *dev = &hr_dev->pdev->dev;
598
- struct hns_roce_v1_priv *priv;
599
- struct hns_roce_db_table *db;
600658 dma_addr_t sdb_dma_addr;
601659 dma_addr_t odb_dma_addr;
602660 int ret = 0;
603
-
604
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
605
- db = &priv->db_table;
606661
607662 db->ext_db = kmalloc(sizeof(*db->ext_db), GFP_KERNEL);
608663 if (!db->ext_db)
....@@ -703,35 +758,38 @@
703758
704759 static int hns_roce_v1_rsv_lp_qp(struct hns_roce_dev *hr_dev)
705760 {
761
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
762
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
706763 struct hns_roce_caps *caps = &hr_dev->caps;
764
+ struct ib_device *ibdev = &hr_dev->ib_dev;
707765 struct device *dev = &hr_dev->pdev->dev;
708766 struct ib_cq_init_attr cq_init_attr;
709
- struct hns_roce_free_mr *free_mr;
710767 struct ib_qp_attr attr = { 0 };
711
- struct hns_roce_v1_priv *priv;
712768 struct hns_roce_qp *hr_qp;
713769 struct ib_cq *cq;
714770 struct ib_pd *pd;
715771 union ib_gid dgid;
716
- u64 subnet_prefix;
772
+ __be64 subnet_prefix;
717773 int attr_mask = 0;
718
- int i, j;
719774 int ret;
775
+ int i, j;
720776 u8 queue_en[HNS_ROCE_V1_RESV_QP] = { 0 };
721777 u8 phy_port;
722778 u8 port = 0;
723779 u8 sl;
724780
725
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
726
- free_mr = &priv->free_mr;
727
-
728781 /* Reserved cq for loop qp */
729782 cq_init_attr.cqe = HNS_ROCE_MIN_WQE_NUM * 2;
730783 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!");
784
+
785
+ cq = rdma_zalloc_drv_obj(ibdev, ib_cq);
786
+ if (!cq)
734787 return -ENOMEM;
788
+
789
+ ret = hns_roce_create_cq(cq, &cq_init_attr, NULL);
790
+ if (ret) {
791
+ dev_err(dev, "Create cq for reserved loop qp failed!");
792
+ goto alloc_cq_failed;
735793 }
736794 free_mr->mr_free_cq = to_hr_cq(cq);
737795 free_mr->mr_free_cq->ib_cq.device = &hr_dev->ib_dev;
....@@ -741,12 +799,17 @@
741799 free_mr->mr_free_cq->ib_cq.cq_context = NULL;
742800 atomic_set(&free_mr->mr_free_cq->ib_cq.usecnt, 0);
743801
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!");
802
+ pd = rdma_zalloc_drv_obj(ibdev, ib_pd);
803
+ if (!pd) {
747804 ret = -ENOMEM;
748
- goto alloc_pd_failed;
805
+ goto alloc_mem_failed;
749806 }
807
+
808
+ pd->device = ibdev;
809
+ ret = hns_roce_alloc_pd(pd, NULL);
810
+ if (ret)
811
+ goto alloc_pd_failed;
812
+
750813 free_mr->mr_free_pd = to_hr_pd(pd);
751814 free_mr->mr_free_pd->ibpd.device = &hr_dev->ib_dev;
752815 free_mr->mr_free_pd->ibpd.uobject = NULL;
....@@ -812,7 +875,7 @@
812875 attr.dest_qp_num = hr_qp->qpn;
813876 memcpy(rdma_ah_retrieve_dmac(&attr.ah_attr),
814877 hr_dev->dev_addr[port],
815
- MAC_ADDR_OCTET_NUM);
878
+ ETH_ALEN);
816879
817880 memcpy(&dgid.raw, &subnet_prefix, sizeof(u64));
818881 memcpy(&dgid.raw[8], hr_dev->dev_addr[port], 3);
....@@ -849,65 +912,58 @@
849912 create_lp_qp_failed:
850913 for (i -= 1; i >= 0; i--) {
851914 hr_qp = free_mr->mr_free_qp[i];
852
- if (hns_roce_v1_destroy_qp(&hr_qp->ibqp))
915
+ if (hns_roce_v1_destroy_qp(&hr_qp->ibqp, NULL))
853916 dev_err(dev, "Destroy qp %d for mr free failed!\n", i);
854917 }
855918
856
- if (hns_roce_dealloc_pd(pd))
857
- dev_err(dev, "Destroy pd for create_lp_qp failed!\n");
919
+ hns_roce_dealloc_pd(pd, NULL);
858920
859921 alloc_pd_failed:
860
- if (hns_roce_ib_destroy_cq(cq))
861
- dev_err(dev, "Destroy cq for create_lp_qp failed!\n");
922
+ kfree(pd);
862923
924
+alloc_mem_failed:
925
+ hns_roce_destroy_cq(cq, NULL);
926
+alloc_cq_failed:
927
+ kfree(cq);
863928 return ret;
864929 }
865930
866931 static void hns_roce_v1_release_lp_qp(struct hns_roce_dev *hr_dev)
867932 {
933
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
934
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
868935 struct device *dev = &hr_dev->pdev->dev;
869
- struct hns_roce_free_mr *free_mr;
870
- struct hns_roce_v1_priv *priv;
871936 struct hns_roce_qp *hr_qp;
872937 int ret;
873938 int i;
874
-
875
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
876
- free_mr = &priv->free_mr;
877939
878940 for (i = 0; i < HNS_ROCE_V1_RESV_QP; i++) {
879941 hr_qp = free_mr->mr_free_qp[i];
880942 if (!hr_qp)
881943 continue;
882944
883
- ret = hns_roce_v1_destroy_qp(&hr_qp->ibqp);
945
+ ret = hns_roce_v1_destroy_qp(&hr_qp->ibqp, NULL);
884946 if (ret)
885947 dev_err(dev, "Destroy qp %d for mr free failed(%d)!\n",
886948 i, ret);
887949 }
888950
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);
951
+ hns_roce_destroy_cq(&free_mr->mr_free_cq->ib_cq, NULL);
952
+ kfree(&free_mr->mr_free_cq->ib_cq);
953
+ hns_roce_dealloc_pd(&free_mr->mr_free_pd->ibpd, NULL);
954
+ kfree(&free_mr->mr_free_pd->ibpd);
896955 }
897956
898957 static int hns_roce_db_init(struct hns_roce_dev *hr_dev)
899958 {
959
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
960
+ struct hns_roce_db_table *db = &priv->db_table;
900961 struct device *dev = &hr_dev->pdev->dev;
901
- struct hns_roce_v1_priv *priv;
902
- struct hns_roce_db_table *db;
903962 u32 sdb_ext_mod;
904963 u32 odb_ext_mod;
905964 u32 sdb_evt_mod;
906965 u32 odb_evt_mod;
907
- int ret = 0;
908
-
909
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
910
- db = &priv->db_table;
966
+ int ret;
911967
912968 memset(db, 0, sizeof(*db));
913969
....@@ -954,16 +1010,12 @@
9541010
9551011 static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
9561012 {
957
- struct device *dev = &hr_dev->pdev->dev;
1013
+ long end = HNS_ROCE_V1_RECREATE_LP_QP_TIMEOUT_MSECS;
1014
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1015
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
9581016 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;
1017
+ struct device *dev = &hr_dev->pdev->dev;
9611018 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;
9671019
9681020 lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
9691021 GFP_KERNEL);
....@@ -980,10 +1032,11 @@
9801032
9811033 queue_work(free_mr->free_mr_wq, &(lp_qp_work->work));
9821034
983
- while (time_before_eq(jiffies, end)) {
1035
+ while (end > 0) {
9841036 if (try_wait_for_completion(&comp))
9851037 return 0;
9861038 msleep(HNS_ROCE_V1_RECREATE_LP_QP_WAIT_VALUE);
1039
+ end -= HNS_ROCE_V1_RECREATE_LP_QP_WAIT_VALUE;
9871040 }
9881041
9891042 lp_qp_work->comp_flag = 0;
....@@ -1021,29 +1074,21 @@
10211074
10221075 static void hns_roce_v1_mr_free_work_fn(struct work_struct *work)
10231076 {
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;
10331077 unsigned long end =
10341078 msecs_to_jiffies(HNS_ROCE_V1_FREE_MR_TIMEOUT_MSECS) + jiffies;
1035
- int i;
1036
- int ret;
1079
+ struct hns_roce_mr_free_work *mr_work =
1080
+ container_of(work, struct hns_roce_mr_free_work, work);
1081
+ struct hns_roce_dev *hr_dev = to_hr_dev(mr_work->ib_dev);
1082
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1083
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
1084
+ struct hns_roce_cq *mr_free_cq = free_mr->mr_free_cq;
1085
+ struct hns_roce_mr *hr_mr = mr_work->mr;
1086
+ struct device *dev = &hr_dev->pdev->dev;
1087
+ struct ib_wc wc[HNS_ROCE_V1_RESV_QP];
1088
+ struct hns_roce_qp *hr_qp;
10371089 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;
1090
+ int ret;
1091
+ int i;
10471092
10481093 for (i = 0; i < HNS_ROCE_V1_RESV_QP; i++) {
10491094 hr_qp = free_mr->mr_free_qp[i];
....@@ -1090,26 +1135,22 @@
10901135 }
10911136
10921137 static int hns_roce_v1_dereg_mr(struct hns_roce_dev *hr_dev,
1093
- struct hns_roce_mr *mr)
1138
+ struct hns_roce_mr *mr, struct ib_udata *udata)
10941139 {
1140
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1141
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
1142
+ long end = HNS_ROCE_V1_FREE_MR_TIMEOUT_MSECS;
10951143 struct device *dev = &hr_dev->pdev->dev;
10961144 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;
11021145 unsigned long start = jiffies;
1103
- int npages;
1146
+ struct completion comp;
11041147 int ret = 0;
11051148
1106
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1107
- free_mr = &priv->free_mr;
1108
-
11091149 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");
1150
+ if (hns_roce_hw_destroy_mpt(hr_dev, NULL,
1151
+ key_to_hw_index(mr->key) &
1152
+ (hr_dev->caps.num_mtpts - 1)))
1153
+ dev_warn(dev, "DESTROY_MPT failed!\n");
11131154 }
11141155
11151156 mr_work = kzalloc(sizeof(*mr_work), GFP_KERNEL);
....@@ -1128,10 +1169,11 @@
11281169
11291170 queue_work(free_mr->free_mr_wq, &(mr_work->work));
11301171
1131
- while (time_before_eq(jiffies, end)) {
1172
+ while (end > 0) {
11321173 if (try_wait_for_completion(&comp))
11331174 goto free_mr;
11341175 msleep(HNS_ROCE_V1_FREE_MR_WAIT_VALUE);
1176
+ end -= HNS_ROCE_V1_FREE_MR_WAIT_VALUE;
11351177 }
11361178
11371179 mr_work->comp_flag = 0;
....@@ -1145,18 +1187,9 @@
11451187 dev_dbg(dev, "Free mr 0x%x use 0x%x us.\n",
11461188 mr->key, jiffies_to_usecs(jiffies) - jiffies_to_usecs(start));
11471189
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
-
11541190 hns_roce_bitmap_free(&hr_dev->mr_table.mtpt_bitmap,
11551191 key_to_hw_index(mr->key), 0);
1156
-
1157
- if (mr->umem)
1158
- ib_umem_release(mr->umem);
1159
-
1192
+ hns_roce_mtr_destroy(hr_dev, &mr->pbl_mtr);
11601193 kfree(mr);
11611194
11621195 return ret;
....@@ -1164,12 +1197,9 @@
11641197
11651198 static void hns_roce_db_free(struct hns_roce_dev *hr_dev)
11661199 {
1200
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1201
+ struct hns_roce_db_table *db = &priv->db_table;
11671202 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;
11731203
11741204 if (db->sdb_ext_mod) {
11751205 dma_free_coherent(dev, HNS_ROCE_V1_EXT_SDB_SIZE,
....@@ -1190,17 +1220,14 @@
11901220
11911221 static int hns_roce_raq_init(struct hns_roce_dev *hr_dev)
11921222 {
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;
1223
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1224
+ struct hns_roce_raq_table *raq = &priv->raq_table;
12001225 struct device *dev = &hr_dev->pdev->dev;
1201
-
1202
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
1203
- raq = &priv->raq_table;
1226
+ dma_addr_t addr;
1227
+ int raq_shift;
1228
+ __le32 tmp;
1229
+ u32 val;
1230
+ int ret;
12041231
12051232 raq->e_raq_buf = kzalloc(sizeof(*(raq->e_raq_buf)), GFP_KERNEL);
12061233 if (!raq->e_raq_buf)
....@@ -1214,7 +1241,7 @@
12141241 }
12151242 raq->e_raq_buf->map = addr;
12161243
1217
- /* Configure raq extended address. 48bit 4K align*/
1244
+ /* Configure raq extended address. 48bit 4K align */
12181245 roce_write(hr_dev, ROCEE_EXT_RAQ_REG, raq->e_raq_buf->map >> 12);
12191246
12201247 /* Configure raq_shift */
....@@ -1280,12 +1307,9 @@
12801307
12811308 static void hns_roce_raq_free(struct hns_roce_dev *hr_dev)
12821309 {
1310
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1311
+ struct hns_roce_raq_table *raq = &priv->raq_table;
12831312 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;
12891313
12901314 dma_free_coherent(dev, HNS_ROCE_V1_RAQ_SIZE, raq->e_raq_buf->buf,
12911315 raq->e_raq_buf->map);
....@@ -1319,11 +1343,9 @@
13191343
13201344 static int hns_roce_bt_init(struct hns_roce_dev *hr_dev)
13211345 {
1346
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
13221347 struct device *dev = &hr_dev->pdev->dev;
1323
- struct hns_roce_v1_priv *priv;
13241348 int ret;
1325
-
1326
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
13271349
13281350 priv->bt_table.qpc_buf.buf = dma_alloc_coherent(dev,
13291351 HNS_ROCE_BT_RSV_BUF_SIZE, &priv->bt_table.qpc_buf.map,
....@@ -1362,10 +1384,8 @@
13621384
13631385 static void hns_roce_bt_free(struct hns_roce_dev *hr_dev)
13641386 {
1387
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
13651388 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;
13691389
13701390 dma_free_coherent(dev, HNS_ROCE_BT_RSV_BUF_SIZE,
13711391 priv->bt_table.cqc_buf.buf, priv->bt_table.cqc_buf.map);
....@@ -1379,12 +1399,9 @@
13791399
13801400 static int hns_roce_tptr_init(struct hns_roce_dev *hr_dev)
13811401 {
1402
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1403
+ struct hns_roce_buf_list *tptr_buf = &priv->tptr_table.tptr_buf;
13821404 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;
13881405
13891406 /*
13901407 * This buffer will be used for CQ's tptr(tail pointer), also
....@@ -1405,12 +1422,9 @@
14051422
14061423 static void hns_roce_tptr_free(struct hns_roce_dev *hr_dev)
14071424 {
1425
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1426
+ struct hns_roce_buf_list *tptr_buf = &priv->tptr_table.tptr_buf;
14081427 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;
14141428
14151429 dma_free_coherent(dev, HNS_ROCE_V1_TPTR_BUF_SIZE,
14161430 tptr_buf->buf, tptr_buf->map);
....@@ -1418,13 +1432,10 @@
14181432
14191433 static int hns_roce_free_mr_init(struct hns_roce_dev *hr_dev)
14201434 {
1435
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1436
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
14211437 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;
1438
+ int ret;
14281439
14291440 free_mr->free_mr_wq = create_singlethread_workqueue("hns_roce_free_mr");
14301441 if (!free_mr->free_mr_wq) {
....@@ -1444,11 +1455,8 @@
14441455
14451456 static void hns_roce_free_mr_free(struct hns_roce_dev *hr_dev)
14461457 {
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;
1458
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
1459
+ struct hns_roce_free_mr *free_mr = &priv->free_mr;
14521460
14531461 flush_workqueue(free_mr->free_mr_wq);
14541462 destroy_workqueue(free_mr->free_mr_wq);
....@@ -1505,42 +1513,10 @@
15051513 return ret;
15061514 }
15071515
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
-
15401516 static int hns_roce_v1_profile(struct hns_roce_dev *hr_dev)
15411517 {
1542
- int i = 0;
15431518 struct hns_roce_caps *caps = &hr_dev->caps;
1519
+ int i;
15441520
15451521 hr_dev->vendor_id = roce_read(hr_dev, ROCEE_VENDOR_ID_REG);
15461522 hr_dev->vendor_part_id = roce_read(hr_dev, ROCEE_VENDOR_PART_ID_REG);
....@@ -1570,18 +1546,19 @@
15701546 caps->max_qp_dest_rdma = HNS_ROCE_V1_MAX_QP_DEST_RDMA;
15711547 caps->max_sq_desc_sz = HNS_ROCE_V1_MAX_SQ_DESC_SZ;
15721548 caps->max_rq_desc_sz = HNS_ROCE_V1_MAX_RQ_DESC_SZ;
1573
- caps->qpc_entry_sz = HNS_ROCE_V1_QPC_ENTRY_SIZE;
1549
+ caps->qpc_sz = HNS_ROCE_V1_QPC_SIZE;
15741550 caps->irrl_entry_sz = HNS_ROCE_V1_IRRL_ENTRY_SIZE;
15751551 caps->cqc_entry_sz = HNS_ROCE_V1_CQC_ENTRY_SIZE;
15761552 caps->mtpt_entry_sz = HNS_ROCE_V1_MTPT_ENTRY_SIZE;
15771553 caps->mtt_entry_sz = HNS_ROCE_V1_MTT_ENTRY_SIZE;
1578
- caps->cq_entry_sz = HNS_ROCE_V1_CQE_ENTRY_SIZE;
1554
+ caps->cqe_sz = HNS_ROCE_V1_CQE_SIZE;
15791555 caps->page_size_cap = HNS_ROCE_V1_PAGE_SIZE_SUPPORT;
15801556 caps->reserved_lkey = 0;
15811557 caps->reserved_pds = 0;
15821558 caps->reserved_mrws = 1;
15831559 caps->reserved_uars = 0;
15841560 caps->reserved_cqs = 0;
1561
+ caps->reserved_qps = 12; /* 2 SQP per port, six ports total 12 */
15851562 caps->chunk_sz = HNS_ROCE_V1_TABLE_CHUNK_SIZE;
15861563
15871564 for (i = 0; i < caps->num_ports; i++)
....@@ -1655,12 +1632,6 @@
16551632 goto error_failed_tptr_init;
16561633 }
16571634
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
-
16641635 ret = hns_roce_free_mr_init(hr_dev);
16651636 if (ret) {
16661637 dev_err(dev, "free mr init failed!\n");
....@@ -1672,9 +1643,6 @@
16721643 return 0;
16731644
16741645 error_failed_free_mr_init:
1675
- hns_roce_des_qp_free(hr_dev);
1676
-
1677
-error_failed_des_qp_init:
16781646 hns_roce_tptr_free(hr_dev);
16791647
16801648 error_failed_tptr_init:
....@@ -1692,7 +1660,6 @@
16921660 {
16931661 hns_roce_port_enable(hr_dev, HNS_ROCE_PORT_DOWN);
16941662 hns_roce_free_mr_free(hr_dev);
1695
- hns_roce_des_qp_free(hr_dev);
16961663 hns_roce_tptr_free(hr_dev);
16971664 hns_roce_bt_free(hr_dev);
16981665 hns_roce_raq_free(hr_dev);
....@@ -1744,8 +1711,6 @@
17441711
17451712 writel(val, hcr + 5);
17461713
1747
- mmiowb();
1748
-
17491714 return 0;
17501715 }
17511716
....@@ -1753,7 +1718,7 @@
17531718 unsigned long timeout)
17541719 {
17551720 u8 __iomem *hcr = hr_dev->reg_base + ROCEE_MB1_REG;
1756
- unsigned long end = 0;
1721
+ unsigned long end;
17571722 u32 status = 0;
17581723
17591724 end = msecs_to_jiffies(timeout) + jiffies;
....@@ -1779,10 +1744,13 @@
17791744 int gid_index, const union ib_gid *gid,
17801745 const struct ib_gid_attr *attr)
17811746 {
1747
+ unsigned long flags;
17821748 u32 *p = NULL;
1783
- u8 gid_idx = 0;
1749
+ u8 gid_idx;
17841750
17851751 gid_idx = hns_get_gid_index(hr_dev, port, gid_index);
1752
+
1753
+ spin_lock_irqsave(&hr_dev->iboe.lock, flags);
17861754
17871755 p = (u32 *)&gid->raw[0];
17881756 roce_raw_write(*p, hr_dev->reg_base + ROCEE_PORT_GID_L_0_REG +
....@@ -1799,6 +1767,8 @@
17991767 p = (u32 *)&gid->raw[0xc];
18001768 roce_raw_write(*p, hr_dev->reg_base + ROCEE_PORT_GID_H_0_REG +
18011769 (HNS_ROCE_V1_GID_NUM * gid_idx));
1770
+
1771
+ spin_unlock_irqrestore(&hr_dev->iboe.lock, flags);
18021772
18031773 return 0;
18041774 }
....@@ -1861,13 +1831,15 @@
18611831 val);
18621832 }
18631833
1864
-static int hns_roce_v1_write_mtpt(void *mb_buf, struct hns_roce_mr *mr,
1834
+static int hns_roce_v1_write_mtpt(struct hns_roce_dev *hr_dev, void *mb_buf,
1835
+ struct hns_roce_mr *mr,
18651836 unsigned long mtpt_idx)
18661837 {
1838
+ u64 pages[HNS_ROCE_MAX_INNER_MTPT_NUM] = { 0 };
1839
+ struct ib_device *ibdev = &hr_dev->ib_dev;
18671840 struct hns_roce_v1_mpt_entry *mpt_entry;
1868
- struct scatterlist *sg;
1869
- u64 *pages;
1870
- int entry;
1841
+ dma_addr_t pbl_ba;
1842
+ int count;
18711843 int i;
18721844
18731845 /* MPT filled into mailbox buf */
....@@ -1917,22 +1889,15 @@
19171889 if (mr->type == MR_TYPE_DMA)
19181890 return 0;
19191891
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++;
1892
+ count = hns_roce_mtr_find(hr_dev, &mr->pbl_mtr, 0, pages,
1893
+ ARRAY_SIZE(pages), &pbl_ba);
1894
+ if (count < 1) {
1895
+ ibdev_err(ibdev, "failed to find PBL mtr, count = %d.", count);
1896
+ return -ENOBUFS;
19321897 }
19331898
19341899 /* Register user mr */
1935
- for (i = 0; i < HNS_ROCE_MAX_INNER_MTPT_NUM; i++) {
1900
+ for (i = 0; i < count; i++) {
19361901 switch (i) {
19371902 case 0:
19381903 mpt_entry->pa0_l = cpu_to_le32((u32)(pages[i]));
....@@ -1998,21 +1963,16 @@
19981963 }
19991964 }
20001965
2001
- free_page((unsigned long) pages);
2002
-
2003
- mpt_entry->pbl_addr_l = cpu_to_le32((u32)(mr->pbl_dma_addr));
2004
-
1966
+ mpt_entry->pbl_addr_l = cpu_to_le32(pbl_ba);
20051967 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)));
1968
+ MPT_BYTE_12_PBL_ADDR_H_S, upper_32_bits(pbl_ba));
20081969
20091970 return 0;
20101971 }
20111972
20121973 static void *get_cqe(struct hns_roce_cq *hr_cq, int n)
20131974 {
2014
- return hns_roce_buf_offset(&hr_cq->hr_buf.hr_buf,
2015
- n * HNS_ROCE_V1_CQE_ENTRY_SIZE);
1975
+ return hns_roce_buf_offset(hr_cq->mtr.kmem, n * HNS_ROCE_V1_CQE_SIZE);
20161976 }
20171977
20181978 static void *get_sw_cqe(struct hns_roce_cq *hr_cq, int n)
....@@ -2021,7 +1981,7 @@
20211981
20221982 /* Get cqe when Owner bit is Conversely with the MSB of cons_idx */
20231983 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;
1984
+ !!(n & hr_cq->cq_depth)) ? hr_cqe : NULL;
20251985 }
20261986
20271987 static struct hns_roce_cqe *next_cqe_sw(struct hns_roce_cq *hr_cq)
....@@ -2104,19 +2064,14 @@
21042064
21052065 static void hns_roce_v1_write_cqc(struct hns_roce_dev *hr_dev,
21062066 struct hns_roce_cq *hr_cq, void *mb_buf,
2107
- u64 *mtts, dma_addr_t dma_handle, int nent,
2108
- u32 vector)
2067
+ u64 *mtts, dma_addr_t dma_handle)
21092068 {
2110
- struct hns_roce_cq_context *cq_context = NULL;
2111
- struct hns_roce_buf_list *tptr_buf;
2112
- struct hns_roce_v1_priv *priv;
2069
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
2070
+ struct hns_roce_buf_list *tptr_buf = &priv->tptr_table.tptr_buf;
2071
+ struct hns_roce_cq_context *cq_context = mb_buf;
21132072 dma_addr_t tptr_dma_addr;
21142073 int offset;
21152074
2116
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
2117
- tptr_buf = &priv->tptr_table.tptr_buf;
2118
-
2119
- cq_context = mb_buf;
21202075 memset(cq_context, 0, sizeof(*cq_context));
21212076
21222077 /* Get the tptr for this CQ. */
....@@ -2140,9 +2095,9 @@
21402095 roce_set_field(cq_context->cqc_byte_12,
21412096 CQ_CONTEXT_CQC_BYTE_12_CQ_CQE_SHIFT_M,
21422097 CQ_CONTEXT_CQC_BYTE_12_CQ_CQE_SHIFT_S,
2143
- ilog2((unsigned int)nent));
2098
+ ilog2(hr_cq->cq_depth));
21442099 roce_set_field(cq_context->cqc_byte_12, CQ_CONTEXT_CQC_BYTE_12_CEQN_M,
2145
- CQ_CONTEXT_CQC_BYTE_12_CEQN_S, vector);
2100
+ CQ_CONTEXT_CQC_BYTE_12_CEQN_S, hr_cq->vector);
21462101
21472102 cq_context->cur_cqe_ba0_l = cpu_to_le32((u32)(mtts[0]));
21482103
....@@ -2183,17 +2138,12 @@
21832138 CQ_CONTEXT_CQC_BYTE_32_CQ_CONS_IDX_S, 0);
21842139 }
21852140
2186
-static int hns_roce_v1_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period)
2187
-{
2188
- return -EOPNOTSUPP;
2189
-}
2190
-
21912141 static int hns_roce_v1_req_notify_cq(struct ib_cq *ibcq,
21922142 enum ib_cq_notify_flags flags)
21932143 {
21942144 struct hns_roce_cq *hr_cq = to_hr_cq(ibcq);
21952145 u32 notification_flag;
2196
- __le32 doorbell[2];
2146
+ __le32 doorbell[2] = {};
21972147
21982148 notification_flag = (flags & IB_CQ_SOLICITED_MASK) ==
21992149 IB_CQ_SOLICITED ? CQ_DB_REQ_NOT : CQ_DB_REQ_NOT_SOL;
....@@ -2325,9 +2275,10 @@
23252275
23262276 if (is_send) {
23272277 /* SQ conrespond to CQE */
2328
- sq_wqe = get_send_wqe(*cur_qp, roce_get_field(cqe->cqe_byte_4,
2278
+ sq_wqe = hns_roce_get_send_wqe(*cur_qp,
2279
+ roce_get_field(cqe->cqe_byte_4,
23292280 CQE_BYTE_4_WQE_INDEX_M,
2330
- CQE_BYTE_4_WQE_INDEX_S)&
2281
+ CQE_BYTE_4_WQE_INDEX_S) &
23312282 ((*cur_qp)->sq.wqe_cnt-1));
23322283 switch (le32_to_cpu(sq_wqe->flag) & HNS_ROCE_WQE_OPCODE_MASK) {
23332284 case HNS_ROCE_WQE_OPCODE_SEND:
....@@ -2456,29 +2407,22 @@
24562407 struct hns_roce_hem_table *table, int obj,
24572408 int step_idx)
24582409 {
2410
+ struct hns_roce_v1_priv *priv = hr_dev->priv;
24592411 struct device *dev = &hr_dev->pdev->dev;
2460
- struct hns_roce_v1_priv *priv;
2461
- unsigned long end = 0, flags = 0;
2412
+ long end = HW_SYNC_TIMEOUT_MSECS;
24622413 __le32 bt_cmd_val[2] = {0};
2414
+ unsigned long flags = 0;
24632415 void __iomem *bt_cmd;
24642416 u64 bt_ba = 0;
24652417
2466
- priv = (struct hns_roce_v1_priv *)hr_dev->priv;
2467
-
24682418 switch (table->type) {
24692419 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);
24722420 bt_ba = priv->bt_table.qpc_buf.map >> 12;
24732421 break;
24742422 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);
24772423 bt_ba = priv->bt_table.mtpt_buf.map >> 12;
24782424 break;
24792425 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);
24822426 bt_ba = priv->bt_table.cqc_buf.map >> 12;
24832427 break;
24842428 case HEM_TYPE_SRQC:
....@@ -2487,6 +2431,8 @@
24872431 default:
24882432 return 0;
24892433 }
2434
+ roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M,
2435
+ ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, table->type);
24902436 roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_M,
24912437 ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_S, obj);
24922438 roce_set_bit(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_S, 0);
....@@ -2496,10 +2442,9 @@
24962442
24972443 bt_cmd = hr_dev->reg_base + ROCEE_BT_CMD_H_REG;
24982444
2499
- end = msecs_to_jiffies(HW_SYNC_TIMEOUT_MSECS) + jiffies;
25002445 while (1) {
25012446 if (readl(bt_cmd) >> BT_CMD_SYNC_SHIFT) {
2502
- if (!(time_before(jiffies, end))) {
2447
+ if (!end) {
25032448 dev_err(dev, "Write bt_cmd err,hw_sync is not zero.\n");
25042449 spin_unlock_irqrestore(&hr_dev->bt_cmd_lock,
25052450 flags);
....@@ -2508,10 +2453,11 @@
25082453 } else {
25092454 break;
25102455 }
2511
- msleep(HW_SYNC_SLEEP_TIME_INTERVAL);
2456
+ mdelay(HW_SYNC_SLEEP_TIME_INTERVAL);
2457
+ end -= HW_SYNC_SLEEP_TIME_INTERVAL;
25122458 }
25132459
2514
- bt_cmd_val[0] = (__le32)bt_ba;
2460
+ bt_cmd_val[0] = cpu_to_le32(bt_ba);
25152461 roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_M,
25162462 ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_S, bt_ba >> 32);
25172463 hns_roce_write64_k(bt_cmd_val, hr_dev->reg_base + ROCEE_BT_CMD_L_REG);
....@@ -2522,7 +2468,6 @@
25222468 }
25232469
25242470 static int hns_roce_v1_qp_modify(struct hns_roce_dev *hr_dev,
2525
- struct hns_roce_mtt *mtt,
25262471 enum hns_roce_qp_state cur_state,
25272472 enum hns_roce_qp_state new_state,
25282473 struct hns_roce_qp_context *context,
....@@ -2569,7 +2514,7 @@
25692514
25702515 struct hns_roce_cmd_mailbox *mailbox;
25712516 struct device *dev = &hr_dev->pdev->dev;
2572
- int ret = 0;
2517
+ int ret;
25732518
25742519 if (cur_state >= HNS_ROCE_QP_NUM_STATE ||
25752520 new_state >= HNS_ROCE_QP_NUM_STATE ||
....@@ -2603,6 +2548,28 @@
26032548 return ret;
26042549 }
26052550
2551
+static int find_wqe_mtt(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
2552
+ u64 *sq_ba, u64 *rq_ba, dma_addr_t *bt_ba)
2553
+{
2554
+ struct ib_device *ibdev = &hr_dev->ib_dev;
2555
+ int count;
2556
+
2557
+ count = hns_roce_mtr_find(hr_dev, &hr_qp->mtr, 0, sq_ba, 1, bt_ba);
2558
+ if (count < 1) {
2559
+ ibdev_err(ibdev, "Failed to find SQ ba\n");
2560
+ return -ENOBUFS;
2561
+ }
2562
+
2563
+ count = hns_roce_mtr_find(hr_dev, &hr_qp->mtr, hr_qp->rq.offset, rq_ba,
2564
+ 1, NULL);
2565
+ if (!count) {
2566
+ ibdev_err(ibdev, "Failed to find RQ ba\n");
2567
+ return -ENOBUFS;
2568
+ }
2569
+
2570
+ return 0;
2571
+}
2572
+
26062573 static int hns_roce_v1_m_sqp(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
26072574 int attr_mask, enum ib_qp_state cur_state,
26082575 enum ib_qp_state new_state)
....@@ -2610,25 +2577,20 @@
26102577 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
26112578 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
26122579 struct hns_roce_sqp_context *context;
2613
- struct device *dev = &hr_dev->pdev->dev;
26142580 dma_addr_t dma_handle = 0;
26152581 u32 __iomem *addr;
2616
- int rq_pa_start;
2582
+ u64 sq_ba = 0;
2583
+ u64 rq_ba = 0;
26172584 __le32 tmp;
26182585 u32 reg_val;
2619
- u64 *mtts;
26202586
26212587 context = kzalloc(sizeof(*context), GFP_KERNEL);
26222588 if (!context)
26232589 return -ENOMEM;
26242590
26252591 /* 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");
2592
+ if (find_wqe_mtt(hr_dev, hr_qp, &sq_ba, &rq_ba, &dma_handle))
26302593 goto out;
2631
- }
26322594
26332595 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) {
26342596 roce_set_field(context->qp1c_bytes_4,
....@@ -2642,11 +2604,11 @@
26422604 roce_set_field(context->qp1c_bytes_4, QP1C_BYTES_4_PD_M,
26432605 QP1C_BYTES_4_PD_S, to_hr_pd(ibqp->pd)->pdn);
26442606
2645
- context->sq_rq_bt_l = cpu_to_le32((u32)(dma_handle));
2607
+ context->sq_rq_bt_l = cpu_to_le32(dma_handle);
26462608 roce_set_field(context->qp1c_bytes_12,
26472609 QP1C_BYTES_12_SQ_RQ_BT_H_M,
26482610 QP1C_BYTES_12_SQ_RQ_BT_H_S,
2649
- ((u32)(dma_handle >> 32)));
2611
+ upper_32_bits(dma_handle));
26502612
26512613 roce_set_field(context->qp1c_bytes_16, QP1C_BYTES_16_RQ_HEAD_M,
26522614 QP1C_BYTES_16_RQ_HEAD_S, hr_qp->rq.head);
....@@ -2654,7 +2616,7 @@
26542616 QP1C_BYTES_16_PORT_NUM_S, hr_qp->phy_port);
26552617 roce_set_bit(context->qp1c_bytes_16,
26562618 QP1C_BYTES_16_SIGNALING_TYPE_S,
2657
- le32_to_cpu(hr_qp->sq_signal_bits));
2619
+ hr_qp->sq_signal_bits);
26582620 roce_set_bit(context->qp1c_bytes_16, QP1C_BYTES_16_RQ_BA_FLG_S,
26592621 1);
26602622 roce_set_bit(context->qp1c_bytes_16, QP1C_BYTES_16_SQ_BA_FLG_S,
....@@ -2667,14 +2629,12 @@
26672629 roce_set_field(context->qp1c_bytes_20, QP1C_BYTES_20_PKEY_IDX_M,
26682630 QP1C_BYTES_20_PKEY_IDX_S, attr->pkey_index);
26692631
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]));
2632
+ context->cur_rq_wqe_ba_l = cpu_to_le32(rq_ba);
26732633
26742634 roce_set_field(context->qp1c_bytes_28,
26752635 QP1C_BYTES_28_CUR_RQ_WQE_BA_H_M,
26762636 QP1C_BYTES_28_CUR_RQ_WQE_BA_H_S,
2677
- (mtts[rq_pa_start]) >> 32);
2637
+ upper_32_bits(rq_ba));
26782638 roce_set_field(context->qp1c_bytes_28,
26792639 QP1C_BYTES_28_RQ_CUR_IDX_M,
26802640 QP1C_BYTES_28_RQ_CUR_IDX_S, 0);
....@@ -2688,12 +2648,12 @@
26882648 QP1C_BYTES_32_TX_CQ_NUM_S,
26892649 to_hr_cq(ibqp->send_cq)->cqn);
26902650
2691
- context->cur_sq_wqe_ba_l = cpu_to_le32((u32)mtts[0]);
2651
+ context->cur_sq_wqe_ba_l = cpu_to_le32(sq_ba);
26922652
26932653 roce_set_field(context->qp1c_bytes_40,
26942654 QP1C_BYTES_40_CUR_SQ_WQE_BA_H_M,
26952655 QP1C_BYTES_40_CUR_SQ_WQE_BA_H_S,
2696
- (mtts[0]) >> 32);
2656
+ upper_32_bits(sq_ba));
26972657 roce_set_field(context->qp1c_bytes_40,
26982658 QP1C_BYTES_40_SQ_CUR_IDX_M,
26992659 QP1C_BYTES_40_SQ_CUR_IDX_S, 0);
....@@ -2737,7 +2697,6 @@
27372697 hr_qp->rq.tail = 0;
27382698 hr_qp->sq.head = 0;
27392699 hr_qp->sq.tail = 0;
2740
- hr_qp->sq_next_wqe = 0;
27412700 }
27422701
27432702 kfree(context);
....@@ -2746,6 +2705,28 @@
27462705 out:
27472706 kfree(context);
27482707 return -EINVAL;
2708
+}
2709
+
2710
+static bool check_qp_state(enum ib_qp_state cur_state,
2711
+ enum ib_qp_state new_state)
2712
+{
2713
+ static const bool sm[][IB_QPS_ERR + 1] = {
2714
+ [IB_QPS_RESET] = { [IB_QPS_RESET] = true,
2715
+ [IB_QPS_INIT] = true },
2716
+ [IB_QPS_INIT] = { [IB_QPS_RESET] = true,
2717
+ [IB_QPS_INIT] = true,
2718
+ [IB_QPS_RTR] = true,
2719
+ [IB_QPS_ERR] = true },
2720
+ [IB_QPS_RTR] = { [IB_QPS_RESET] = true,
2721
+ [IB_QPS_RTS] = true,
2722
+ [IB_QPS_ERR] = true },
2723
+ [IB_QPS_RTS] = { [IB_QPS_RESET] = true, [IB_QPS_ERR] = true },
2724
+ [IB_QPS_SQD] = {},
2725
+ [IB_QPS_SQE] = {},
2726
+ [IB_QPS_ERR] = { [IB_QPS_RESET] = true, [IB_QPS_ERR] = true }
2727
+ };
2728
+
2729
+ return sm[cur_state][new_state];
27492730 }
27502731
27512732 static int hns_roce_v1_m_qp(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
....@@ -2760,26 +2741,29 @@
27602741 dma_addr_t dma_handle_2 = 0;
27612742 dma_addr_t dma_handle = 0;
27622743 __le32 doorbell[2] = {0};
2763
- int rq_pa_start = 0;
27642744 u64 *mtts_2 = NULL;
27652745 int ret = -EINVAL;
2766
- u64 *mtts = NULL;
2746
+ u64 sq_ba = 0;
2747
+ u64 rq_ba = 0;
27672748 int port;
27682749 u8 port_num;
27692750 u8 *dmac;
27702751 u8 *smac;
2752
+
2753
+ if (!check_qp_state(cur_state, new_state)) {
2754
+ ibdev_err(ibqp->device,
2755
+ "not support QP(%u) status from %d to %d\n",
2756
+ ibqp->qp_num, cur_state, new_state);
2757
+ return -EINVAL;
2758
+ }
27712759
27722760 context = kzalloc(sizeof(*context), GFP_KERNEL);
27732761 if (!context)
27742762 return -ENOMEM;
27752763
27762764 /* 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");
2765
+ if (find_wqe_mtt(hr_dev, hr_qp, &sq_ba, &rq_ba, &dma_handle))
27812766 goto out;
2782
- }
27832767
27842768 /* Search IRRL's mtts */
27852769 mtts_2 = hns_roce_table_find(hr_dev, &hr_dev->qp_table.irrl_table,
....@@ -2852,7 +2836,6 @@
28522836 roce_set_field(context->qpc_bytes_16,
28532837 QP_CONTEXT_QPC_BYTES_16_QP_NUM_M,
28542838 QP_CONTEXT_QPC_BYTES_16_QP_NUM_S, hr_qp->qpn);
2855
-
28562839 } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_INIT) {
28572840 roce_set_field(context->qpc_bytes_4,
28582841 QP_CONTEXT_QPC_BYTES_4_TRANSPORT_SERVICE_TYPE_M,
....@@ -2934,11 +2917,11 @@
29342917
29352918 dmac = (u8 *)attr->ah_attr.roce.dmac;
29362919
2937
- context->sq_rq_bt_l = cpu_to_le32((u32)(dma_handle));
2920
+ context->sq_rq_bt_l = cpu_to_le32(dma_handle);
29382921 roce_set_field(context->qpc_bytes_24,
29392922 QP_CONTEXT_QPC_BYTES_24_SQ_RQ_BT_H_M,
29402923 QP_CONTEXT_QPC_BYTES_24_SQ_RQ_BT_H_S,
2941
- ((u32)(dma_handle >> 32)));
2924
+ upper_32_bits(dma_handle));
29422925 roce_set_bit(context->qpc_bytes_24,
29432926 QP_CONTEXT_QPC_BYTE_24_REMOTE_ENABLE_E2E_CREDITS_S,
29442927 1);
....@@ -2960,7 +2943,7 @@
29602943 1);
29612944 roce_set_bit(context->qpc_bytes_32,
29622945 QP_CONTEXT_QPC_BYTE_32_SIGNALING_TYPE_S,
2963
- le32_to_cpu(hr_qp->sq_signal_bits));
2946
+ hr_qp->sq_signal_bits);
29642947
29652948 port = (attr_mask & IB_QP_PORT) ? (attr->port_num - 1) :
29662949 hr_qp->port;
....@@ -3037,14 +3020,12 @@
30373020 QP_CONTEXT_QPC_BYTES_68_RQ_CUR_INDEX_M,
30383021 QP_CONTEXT_QPC_BYTES_68_RQ_CUR_INDEX_S, 0);
30393022
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]));
3023
+ context->cur_rq_wqe_ba_l = cpu_to_le32(rq_ba);
30433024
30443025 roce_set_field(context->qpc_bytes_76,
30453026 QP_CONTEXT_QPC_BYTES_76_CUR_RQ_WQE_BA_H_M,
30463027 QP_CONTEXT_QPC_BYTES_76_CUR_RQ_WQE_BA_H_S,
3047
- mtts[rq_pa_start] >> 32);
3028
+ upper_32_bits(rq_ba));
30483029 roce_set_field(context->qpc_bytes_76,
30493030 QP_CONTEXT_QPC_BYTES_76_RX_REQ_MSN_M,
30503031 QP_CONTEXT_QPC_BYTES_76_RX_REQ_MSN_S, 0);
....@@ -3106,8 +3087,7 @@
31063087 QP_CONTEXT_QPC_BYTES_156_SL_S,
31073088 rdma_ah_get_sl(&attr->ah_attr));
31083089 hr_qp->sl = rdma_ah_get_sl(&attr->ah_attr);
3109
- } else if (cur_state == IB_QPS_RTR &&
3110
- new_state == IB_QPS_RTS) {
3090
+ } else if (cur_state == IB_QPS_RTR && new_state == IB_QPS_RTS) {
31113091 /* If exist optional param, return error */
31123092 if ((attr_mask & IB_QP_ALT_PATH) ||
31133093 (attr_mask & IB_QP_ACCESS_FLAGS) ||
....@@ -3119,12 +3099,12 @@
31193099 goto out;
31203100 }
31213101
3122
- context->rx_cur_sq_wqe_ba_l = cpu_to_le32((u32)(mtts[0]));
3102
+ context->rx_cur_sq_wqe_ba_l = cpu_to_le32(sq_ba);
31233103
31243104 roce_set_field(context->qpc_bytes_120,
31253105 QP_CONTEXT_QPC_BYTES_120_RX_CUR_SQ_WQE_BA_H_M,
31263106 QP_CONTEXT_QPC_BYTES_120_RX_CUR_SQ_WQE_BA_H_S,
3127
- (mtts[0]) >> 32);
3107
+ upper_32_bits(sq_ba));
31283108
31293109 roce_set_field(context->qpc_bytes_124,
31303110 QP_CONTEXT_QPC_BYTES_124_RX_ACK_MSN_M,
....@@ -3267,28 +3247,18 @@
32673247 QP_CONTEXT_QPC_BYTES_180_SQ_HEAD_M,
32683248 QP_CONTEXT_QPC_BYTES_180_SQ_HEAD_S, 0);
32693249
3270
- context->tx_cur_sq_wqe_ba_l = cpu_to_le32((u32)(mtts[0]));
3250
+ context->tx_cur_sq_wqe_ba_l = cpu_to_le32(sq_ba);
32713251
32723252 roce_set_field(context->qpc_bytes_188,
32733253 QP_CONTEXT_QPC_BYTES_188_TX_CUR_SQ_WQE_BA_H_M,
32743254 QP_CONTEXT_QPC_BYTES_188_TX_CUR_SQ_WQE_BA_H_S,
3275
- (mtts[0]) >> 32);
3255
+ upper_32_bits(sq_ba));
32763256 roce_set_bit(context->qpc_bytes_188,
32773257 QP_CONTEXT_QPC_BYTES_188_PKT_RETRY_FLG_S, 0);
32783258 roce_set_field(context->qpc_bytes_188,
32793259 QP_CONTEXT_QPC_BYTES_188_TX_RETRY_CUR_INDEX_M,
32803260 QP_CONTEXT_QPC_BYTES_188_TX_RETRY_CUR_INDEX_S,
32813261 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;
32923262 }
32933263
32943264 /* Every status migrate must change state */
....@@ -3297,8 +3267,7 @@
32973267 QP_CONTEXT_QPC_BYTES_144_QP_STATE_S, new_state);
32983268
32993269 /* SW pass context to HW */
3300
- ret = hns_roce_v1_qp_modify(hr_dev, &hr_qp->mtt,
3301
- to_hns_roce_state(cur_state),
3270
+ ret = hns_roce_v1_qp_modify(hr_dev, to_hns_roce_state(cur_state),
33023271 to_hns_roce_state(new_state), context,
33033272 hr_qp);
33043273 if (ret) {
....@@ -3351,7 +3320,6 @@
33513320 hr_qp->rq.tail = 0;
33523321 hr_qp->sq.head = 0;
33533322 hr_qp->sq.tail = 0;
3354
- hr_qp->sq_next_wqe = 0;
33553323 }
33563324 out:
33573325 kfree(context);
....@@ -3494,7 +3462,7 @@
34943462 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
34953463 struct device *dev = &hr_dev->pdev->dev;
34963464 struct hns_roce_qp_context *context;
3497
- int tmp_qp_state = 0;
3465
+ int tmp_qp_state;
34983466 int ret = 0;
34993467 int state;
35003468
....@@ -3605,7 +3573,7 @@
36053573 qp_attr->retry_cnt = roce_get_field(context->qpc_bytes_148,
36063574 QP_CONTEXT_QPC_BYTES_148_RETRY_COUNT_M,
36073575 QP_CONTEXT_QPC_BYTES_148_RETRY_COUNT_S);
3608
- qp_attr->rnr_retry = (u8)context->rnr_retry;
3576
+ qp_attr->rnr_retry = (u8)le32_to_cpu(context->rnr_retry);
36093577
36103578 done:
36113579 qp_attr->cur_qp_state = qp_attr->qp_state;
....@@ -3639,372 +3607,47 @@
36393607 hns_roce_v1_q_qp(ibqp, qp_attr, qp_attr_mask, qp_init_attr);
36403608 }
36413609
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)
3610
+int hns_roce_v1_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
39203611 {
39213612 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
39223613 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;
39273614 struct hns_roce_cq *send_cq, *recv_cq;
3928
- int is_user = !!ibqp->pd->uobject;
3929
- int is_timeout = 0;
39303615 int ret;
39313616
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);
3617
+ ret = hns_roce_v1_modify_qp(ibqp, NULL, 0, hr_qp->state, IB_QPS_RESET);
3618
+ if (ret)
39353619 return ret;
3936
- }
39373620
3938
- send_cq = to_hr_cq(hr_qp->ibqp.send_cq);
3939
- recv_cq = to_hr_cq(hr_qp->ibqp.recv_cq);
3621
+ send_cq = hr_qp->ibqp.send_cq ? to_hr_cq(hr_qp->ibqp.send_cq) : NULL;
3622
+ recv_cq = hr_qp->ibqp.recv_cq ? to_hr_cq(hr_qp->ibqp.recv_cq) : NULL;
39403623
39413624 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)
3625
+ if (!udata) {
3626
+ if (recv_cq)
3627
+ __hns_roce_v1_cq_clean(recv_cq, hr_qp->qpn,
3628
+ (hr_qp->ibqp.srq ?
3629
+ to_hr_srq(hr_qp->ibqp.srq) :
3630
+ NULL));
3631
+
3632
+ if (send_cq && send_cq != recv_cq)
39463633 __hns_roce_v1_cq_clean(send_cq, hr_qp->qpn, NULL);
39473634 }
3635
+ hns_roce_qp_remove(hr_dev, hr_qp);
39483636 hns_roce_unlock_cqs(send_cq, recv_cq);
39493637
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
- }
3638
+ hns_roce_qp_destroy(hr_dev, hr_qp, udata);
39923639
39933640 return 0;
39943641 }
39953642
3996
-static int hns_roce_v1_destroy_cq(struct ib_cq *ibcq)
3643
+static int hns_roce_v1_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
39973644 {
39983645 struct hns_roce_dev *hr_dev = to_hr_dev(ibcq->device);
39993646 struct hns_roce_cq *hr_cq = to_hr_cq(ibcq);
40003647 struct device *dev = &hr_dev->pdev->dev;
40013648 u32 cqe_cnt_ori;
40023649 u32 cqe_cnt_cur;
4003
- u32 cq_buf_size;
40043650 int wait_time = 0;
4005
- int ret = 0;
4006
-
4007
- hns_roce_free_cq(hr_dev, hr_cq);
40083651
40093652 /*
40103653 * Before freeing cq buffer, we need to ensure that the outstanding CQE
....@@ -4024,25 +3667,11 @@
40243667 if (wait_time > HNS_ROCE_MAX_FREE_CQ_WAIT_CNT) {
40253668 dev_warn(dev, "Destroy cq 0x%lx timeout!\n",
40263669 hr_cq->cqn);
4027
- ret = -ETIMEDOUT;
40283670 break;
40293671 }
40303672 wait_time++;
40313673 }
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;
3674
+ return 0;
40463675 }
40473676
40483677 static void set_eq_cons_index_v1(struct hns_roce_eq *eq, int req_not)
....@@ -4215,8 +3844,7 @@
42153844
42163845 static struct hns_roce_aeqe *get_aeqe_v1(struct hns_roce_eq *eq, u32 entry)
42173846 {
4218
- unsigned long off = (entry & (eq->entries - 1)) *
4219
- HNS_ROCE_AEQ_ENTRY_SIZE;
3847
+ unsigned long off = (entry & (eq->entries - 1)) * HNS_ROCE_AEQE_SIZE;
42203848
42213849 return (struct hns_roce_aeqe *)((u8 *)
42223850 (eq->buf_list[off / HNS_ROCE_BA_SIZE].buf) +
....@@ -4240,13 +3868,13 @@
42403868 int event_type;
42413869
42423870 while ((aeqe = next_aeqe_sw_v1(eq))) {
4243
-
42443871 /* Make sure we read the AEQ entry after we have checked the
42453872 * ownership bit
42463873 */
42473874 dma_rmb();
42483875
4249
- dev_dbg(dev, "aeqe = %p, aeqe->asyn.event_type = 0x%lx\n", aeqe,
3876
+ dev_dbg(dev, "aeqe = %pK, aeqe->asyn.event_type = 0x%lx\n",
3877
+ aeqe,
42503878 roce_get_field(aeqe->asyn,
42513879 HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M,
42523880 HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S));
....@@ -4309,10 +3937,8 @@
43093937 eq->cons_index++;
43103938 aeqes_found = 1;
43113939
4312
- if (eq->cons_index > 2 * hr_dev->caps.aeqe_depth - 1) {
4313
- dev_warn(dev, "cons_index overflow, set back to 0.\n");
3940
+ if (eq->cons_index > 2 * hr_dev->caps.aeqe_depth - 1)
43143941 eq->cons_index = 0;
4315
- }
43163942 }
43173943
43183944 set_eq_cons_index_v1(eq, 0);
....@@ -4322,8 +3948,7 @@
43223948
43233949 static struct hns_roce_ceqe *get_ceqe_v1(struct hns_roce_eq *eq, u32 entry)
43243950 {
4325
- unsigned long off = (entry & (eq->entries - 1)) *
4326
- HNS_ROCE_CEQ_ENTRY_SIZE;
3951
+ unsigned long off = (entry & (eq->entries - 1)) * HNS_ROCE_CEQE_SIZE;
43273952
43283953 return (struct hns_roce_ceqe *)((u8 *)
43293954 (eq->buf_list[off / HNS_ROCE_BA_SIZE].buf) +
....@@ -4347,7 +3972,6 @@
43473972 u32 cqn;
43483973
43493974 while ((ceqe = next_ceqe_sw_v1(eq))) {
4350
-
43513975 /* Make sure we read CEQ entry after we have checked the
43523976 * ownership bit
43533977 */
....@@ -4361,11 +3985,9 @@
43613985 ++eq->cons_index;
43623986 ceqes_found = 1;
43633987
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");
3988
+ if (eq->cons_index >
3989
+ EQ_DEPTH_COEFF * hr_dev->caps.ceqe_depth - 1)
43673990 eq->cons_index = 0;
4368
- }
43693991 }
43703992
43713993 set_eq_cons_index_v1(eq, 0);
....@@ -4377,7 +3999,7 @@
43773999 {
43784000 struct hns_roce_eq *eq = eq_ptr;
43794001 struct hns_roce_dev *hr_dev = eq->hr_dev;
4380
- int int_work = 0;
4002
+ int int_work;
43814003
43824004 if (eq->type_flag == HNS_ROCE_CEQ)
43834005 /* CEQ irq routine, CEQ is pulse irq, not clear */
....@@ -4575,9 +4197,9 @@
45754197 void __iomem *eqc = hr_dev->eq_table.eqc_base[eq->eqn];
45764198 struct device *dev = &hr_dev->pdev->dev;
45774199 dma_addr_t tmp_dma_addr;
4578
- u32 eqconsindx_val = 0;
45794200 u32 eqcuridx_val = 0;
4580
- u32 eqshift_val = 0;
4201
+ u32 eqconsindx_val;
4202
+ u32 eqshift_val;
45814203 __le32 tmp2 = 0;
45824204 __le32 tmp1 = 0;
45834205 __le32 tmp = 0;
....@@ -4609,7 +4231,6 @@
46094231 }
46104232
46114233 eq->buf_list[i].map = tmp_dma_addr;
4612
- memset(eq->buf_list[i].buf, 0, HNS_ROCE_BA_SIZE);
46134234 }
46144235 eq->cons_index = 0;
46154236 roce_set_field(tmp, ROCEE_CAEP_AEQC_AEQE_SHIFT_CAEP_AEQC_STATE_M,
....@@ -4697,7 +4318,7 @@
46974318 CEQ_REG_OFFSET * i;
46984319 eq->entries = hr_dev->caps.ceqe_depth;
46994320 eq->log_entries = ilog2(eq->entries);
4700
- eq->eqe_size = HNS_ROCE_CEQ_ENTRY_SIZE;
4321
+ eq->eqe_size = HNS_ROCE_CEQE_SIZE;
47014322 } else {
47024323 /* AEQ */
47034324 eq_table->eqc_base[i] = hr_dev->reg_base +
....@@ -4707,7 +4328,7 @@
47074328 ROCEE_CAEP_AEQE_CONS_IDX_REG;
47084329 eq->entries = hr_dev->caps.aeqe_depth;
47094330 eq->log_entries = ilog2(eq->entries);
4710
- eq->eqe_size = HNS_ROCE_AEQ_ENTRY_SIZE;
4331
+ eq->eqe_size = HNS_ROCE_AEQE_SIZE;
47114332 }
47124333 }
47134334
....@@ -4792,6 +4413,15 @@
47924413 kfree(eq_table->eq);
47934414 }
47944415
4416
+static const struct ib_device_ops hns_roce_v1_dev_ops = {
4417
+ .destroy_qp = hns_roce_v1_destroy_qp,
4418
+ .poll_cq = hns_roce_v1_poll_cq,
4419
+ .post_recv = hns_roce_v1_post_recv,
4420
+ .post_send = hns_roce_v1_post_send,
4421
+ .query_qp = hns_roce_v1_query_qp,
4422
+ .req_notify_cq = hns_roce_v1_req_notify_cq,
4423
+};
4424
+
47954425 static const struct hns_roce_hw hns_roce_hw_v1 = {
47964426 .reset = hns_roce_v1_reset,
47974427 .hw_profile = hns_roce_v1_profile,
....@@ -4804,7 +4434,7 @@
48044434 .set_mtu = hns_roce_v1_set_mtu,
48054435 .write_mtpt = hns_roce_v1_write_mtpt,
48064436 .write_cqc = hns_roce_v1_write_cqc,
4807
- .modify_cq = hns_roce_v1_modify_cq,
4437
+ .set_hem = hns_roce_v1_set_hem,
48084438 .clear_hem = hns_roce_v1_clear_hem,
48094439 .modify_qp = hns_roce_v1_modify_qp,
48104440 .query_qp = hns_roce_v1_query_qp,
....@@ -4817,6 +4447,7 @@
48174447 .destroy_cq = hns_roce_v1_destroy_cq,
48184448 .init_eq = hns_roce_v1_init_eq_table,
48194449 .cleanup_eq = hns_roce_v1_cleanup_eq_table,
4450
+ .hns_roce_dev_ops = &hns_roce_v1_dev_ops,
48204451 };
48214452
48224453 static const struct of_device_id hns_roce_of_match[] = {
....@@ -4831,19 +4462,13 @@
48314462 };
48324463 MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
48334464
4834
-static int hns_roce_node_match(struct device *dev, void *fwnode)
4835
-{
4836
- return dev->fwnode == fwnode;
4837
-}
4838
-
48394465 static struct
48404466 platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
48414467 {
48424468 struct device *dev;
48434469
48444470 /* get the 'device' corresponding to the matching 'fwnode' */
4845
- dev = bus_find_device(&platform_bus_type, NULL,
4846
- fwnode, hns_roce_node_match);
4471
+ dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
48474472 /* get the platform device */
48484473 return dev ? to_platform_device(dev) : NULL;
48494474 }
....@@ -4854,7 +4479,6 @@
48544479 struct platform_device *pdev = NULL;
48554480 struct net_device *netdev = NULL;
48564481 struct device_node *net_node;
4857
- struct resource *res;
48584482 int port_cnt = 0;
48594483 u8 phy_port;
48604484 int ret;
....@@ -4893,8 +4517,7 @@
48934517 }
48944518
48954519 /* 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);
4520
+ hr_dev->reg_base = devm_platform_ioremap_resource(hr_dev->pdev, 0);
48984521 if (IS_ERR(hr_dev->reg_base))
48994522 return PTR_ERR(hr_dev->reg_base);
49004523
....@@ -4969,10 +4592,8 @@
49694592 /* fetch the interrupt numbers */
49704593 for (i = 0; i < HNS_ROCE_V1_MAX_IRQ_NUM; i++) {
49714594 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);
4595
+ if (hr_dev->irq[i] <= 0)
49744596 return -EINVAL;
4975
- }
49764597 }
49774598
49784599 return 0;
....@@ -4990,7 +4611,7 @@
49904611 struct hns_roce_dev *hr_dev;
49914612 struct device *dev = &pdev->dev;
49924613
4993
- hr_dev = (struct hns_roce_dev *)ib_alloc_device(sizeof(*hr_dev));
4614
+ hr_dev = ib_alloc_device(hns_roce_dev, ib_dev);
49944615 if (!hr_dev)
49954616 return -ENOMEM;
49964617