RDMA/hns: Use a separated function for setting extend sge paramters
authorLijun Ou <oulijun@huawei.com>
Mon, 8 Jul 2019 13:41:20 +0000 (21:41 +0800)
committerJason Gunthorpe <jgg@mellanox.com>
Thu, 25 Jul 2019 15:23:10 +0000 (12:23 -0300)
Moves the related lines of setting extended sge size into a separate
function as well as remove the unused variables.

Link: https://lore.kernel.org/r/1562593285-8037-5-git-send-email-oulijun@huawei.com
Signed-off-by: Lijun Ou <oulijun@huawei.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/hns/hns_roce_device.h
drivers/infiniband/hw/hns/hns_roce_qp.c

index a548b28..b39497a 100644 (file)
@@ -654,8 +654,6 @@ struct hns_roce_qp {
        u32                     doorbell_qpn;
        __le32                  sq_signal_bits;
        u32                     sq_next_wqe;
-       int                     sq_max_wqes_per_wr;
-       int                     sq_spare_wqes;
        struct hns_roce_wq      sq;
 
        struct ib_umem          *umem;
index e042402..9c272c2 100644 (file)
@@ -501,6 +501,35 @@ static int calc_wqe_bt_page_shift(struct hns_roce_dev *hr_dev,
        return bt_pg_shift - PAGE_SHIFT;
 }
 
+static int set_extend_sge_param(struct hns_roce_dev *hr_dev,
+                               struct hns_roce_qp *hr_qp)
+{
+       struct device *dev = hr_dev->dev;
+
+       if (hr_qp->sq.max_gs > 2) {
+               hr_qp->sge.sge_cnt = roundup_pow_of_two(hr_qp->sq.wqe_cnt *
+                                    (hr_qp->sq.max_gs - 2));
+               hr_qp->sge.sge_shift = 4;
+       }
+
+       /* ud sqwqe's sge use extend sge */
+       if (hr_dev->caps.max_sq_sg > 2 && hr_qp->ibqp.qp_type == IB_QPT_GSI) {
+               hr_qp->sge.sge_cnt = roundup_pow_of_two(hr_qp->sq.wqe_cnt *
+                                    hr_qp->sq.max_gs);
+               hr_qp->sge.sge_shift = 4;
+       }
+
+       if ((hr_qp->sq.max_gs > 2) && hr_dev->pci_dev->revision == 0x20) {
+               if (hr_qp->sge.sge_cnt > hr_dev->caps.max_extend_sg) {
+                       dev_err(dev, "The extended sge cnt error! sge_cnt=%d\n",
+                               hr_qp->sge.sge_cnt);
+                       return -EINVAL;
+               }
+       }
+
+       return 0;
+}
+
 static int hns_roce_set_kernel_sq_size(struct hns_roce_dev *hr_dev,
                                       struct ib_qp_cap *cap,
                                       struct hns_roce_qp *hr_qp)
@@ -509,6 +538,7 @@ static int hns_roce_set_kernel_sq_size(struct hns_roce_dev *hr_dev,
        u32 page_size;
        u32 max_cnt;
        int size;
+       int ret;
 
        if (cap->max_send_wr  > hr_dev->caps.max_wqes  ||
            cap->max_send_sge > hr_dev->caps.max_sq_sg ||
@@ -518,8 +548,6 @@ static int hns_roce_set_kernel_sq_size(struct hns_roce_dev *hr_dev,
        }
 
        hr_qp->sq.wqe_shift = ilog2(hr_dev->caps.max_sq_desc_sz);
-       hr_qp->sq_max_wqes_per_wr = 1;
-       hr_qp->sq_spare_wqes = 0;
 
        if (hr_dev->caps.min_wqes)
                max_cnt = max(cap->max_send_wr, hr_dev->caps.min_wqes);
@@ -539,25 +567,10 @@ static int hns_roce_set_kernel_sq_size(struct hns_roce_dev *hr_dev,
        else
                hr_qp->sq.max_gs = max_cnt;
 
-       if (hr_qp->sq.max_gs > 2) {
-               hr_qp->sge.sge_cnt = roundup_pow_of_two(hr_qp->sq.wqe_cnt *
-                                    (hr_qp->sq.max_gs - 2));
-               hr_qp->sge.sge_shift = 4;
-       }
-
-       /* ud sqwqe's sge use extend sge */
-       if (hr_dev->caps.max_sq_sg > 2 && hr_qp->ibqp.qp_type == IB_QPT_GSI) {
-               hr_qp->sge.sge_cnt = roundup_pow_of_two(hr_qp->sq.wqe_cnt *
-                                    hr_qp->sq.max_gs);
-               hr_qp->sge.sge_shift = 4;
-       }
-
-       if ((hr_qp->sq.max_gs > 2) && hr_dev->pci_dev->revision == 0x20) {
-               if (hr_qp->sge.sge_cnt > hr_dev->caps.max_extend_sg) {
-                       dev_err(dev, "The extended sge cnt error! sge_cnt=%d\n",
-                               hr_qp->sge.sge_cnt);
-                       return -EINVAL;
-               }
+       ret = set_extend_sge_param(hr_dev, hr_qp);
+       if (ret) {
+               dev_err(dev, "set extend sge parameters fail\n");
+               return ret;
        }
 
        /* Get buf size, SQ and RQ are aligned to PAGE_SIZE */
@@ -942,11 +955,13 @@ err_db:
                hns_roce_free_db(hr_dev, &hr_qp->rdb);
 
 err_rq_sge_list:
-       if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE)
+       if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE) &&
+            hns_roce_qp_has_rq(init_attr))
                kfree(hr_qp->rq_inl_buf.wqe_list[0].sg_list);
 
 err_wqe_list:
-       if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE)
+       if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE) &&
+            hns_roce_qp_has_rq(init_attr))
                kfree(hr_qp->rq_inl_buf.wqe_list);
 
 err_out: