RDMA/hns: Refactor qp related code
Subsystems (2)
v2 cover RDMA/hns: Refactor qp related code
This series refactor qp related code, including creating, destroying qp and so on to make the processs easier to understand and maintain.
Previous disscussion can be found at:
https://patchwork.kernel.org/cover/11341265/
Changes since v1:
- Reduce the number of prints as Leon suggested.
- Fix a wrong function name in description of patch 4/7.
Xi Wang (7):
RDMA/hns: Optimize qp destroy flow
RDMA/hns: Optimize qp context create and destroy flow RDMA/hns: Optimize qp number assign flow RDMA/hns: Optimize qp buffer allocation flow RDMA/hns: Optimize qp param setup flow RDMA/hns: Optimize kernel qp wrid allocation flow RDMA/hns: Optimize qp doorbell allocation flow
drivers/infiniband/hw/hns/hns_roce_device.h | 6 +- drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 19 +- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 43 +- drivers/infiniband/hw/hns/hns_roce_qp.c | 788 ++++++++++++++++------------ 4 files changed, 446 insertions(+), 410 deletions(-)
Signature · 1 line
2.8.1
PATCH v2 1/7 RDMA/hns: Optimize qp destroy flow
From: Xi Wang <[email protected]>
Wrap the duplicate code in hip08 and hip06 qp destruction process as hns_roce_qp_destroy() to simply the qp destroy flow.
--- drivers/infiniband/hw/hns/hns_roce_device.h | 5 ++-- drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 19 ++----------- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 39 +-------------------------- drivers/infiniband/hw/hns/hns_roce_qp.c | 41 +++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 58 deletions(-)
drivers/infiniband/hw/hns/hns_roce_device.h +2 -3
@@ -1248,9 +1248,8 @@ void hns_roce_lock_cqs(struct hns_roce_cq *send_cq,void hns_roce_unlock_cqs (struct hns_roce_cq *send_cq,struct hns_roce_cq *recv_cq);void hns_roce_qp_remove (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp); -void hns_roce_qp_free (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp); -void hns_roce_release_range_qp (struct hns_roce_dev *hr_dev,int base_qpn, -int cnt); +void hns_roce_qp_destroy (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp, +struct ib_udata *udata);__be32 send_ieth (const struct ib_send_wr *wr);int to_hr_qp_type (int qp_type);
drivers/infiniband/hw/hns/hns_roce_hw_v1.c +2 -17
@@ -3623,26 +3623,11 @@ int hns_roce_v1_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)if (send_cq && send_cq != recv_cq)__hns_roce_v1_cq_clean (send_cq, hr_qp->qpn,NULL ); } -hns_roce_unlock_cqs (send_cq, recv_cq); -hns_roce_qp_remove (hr_dev, hr_qp); -hns_roce_qp_free (hr_dev, hr_qp); - -/* RC QP, release QPN */ -if (hr_qp->ibqp.qp_type ==IB_QPT_RC ) -hns_roce_release_range_qp (hr_dev, hr_qp->qpn,1 ); - -hns_roce_mtt_cleanup (hr_dev, &hr_qp->mtt); - -ib_umem_release (hr_qp->umem); -if (!udata) { -kfree (hr_qp->sq.wrid); -kfree (hr_qp->rq.wrid); +hns_roce_unlock_cqs (send_cq, recv_cq); -hns_roce_buf_free (hr_dev, hr_qp->buff_size, &hr_qp->hr_buf); - } +hns_roce_qp_destroy (hr_dev, hr_qp, udata); -kfree (hr_qp);return 0 ; }
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +1 -38
@@ -5032,43 +5032,6 @@ static int hns_roce_v2_destroy_qp_common(struct hns_roce_dev *hr_dev,hns_roce_unlock_cqs (send_cq, recv_cq);spin_unlock_irqrestore (&hr_dev->qp_list_lock, flags); -hns_roce_qp_free (hr_dev, hr_qp); - -/* Not special_QP, free their QPN */ -if ((hr_qp->ibqp.qp_type ==IB_QPT_RC ) || - (hr_qp->ibqp.qp_type ==IB_QPT_UC ) || - (hr_qp->ibqp.qp_type ==IB_QPT_UD )) -hns_roce_release_range_qp (hr_dev, hr_qp->qpn,1 ); - -hns_roce_mtr_cleanup (hr_dev, &hr_qp->mtr); - -if (udata) { -struct hns_roce_ucontext *context = -rdma_udata_to_drv_context ( - udata, - struct hns_roce_ucontext, - ibucontext); - -if (hr_qp->sq.wqe_cnt && (hr_qp->sdb_en ==1 )) -hns_roce_db_unmap_user (context, &hr_qp->sdb); - -if (hr_qp->rq.wqe_cnt && (hr_qp->rdb_en ==1 )) -hns_roce_db_unmap_user (context, &hr_qp->rdb); - }else { -kfree (hr_qp->sq.wrid); -kfree (hr_qp->rq.wrid); -hns_roce_buf_free (hr_dev, hr_qp->buff_size, &hr_qp->hr_buf); -if (hr_qp->rq.wqe_cnt) -hns_roce_free_db (hr_dev, &hr_qp->rdb); - } -ib_umem_release (hr_qp->umem); - -if ((hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_RQ_INLINE ) && - hr_qp->rq.wqe_cnt) { -kfree (hr_qp->rq_inl_buf.wqe_list[0 ].sg_list); -kfree (hr_qp->rq_inl_buf.wqe_list); - } -return ret; }
@@ -5083,7 +5046,7 @@ static int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)ibdev_err (&hr_dev->ib_dev,"Destroy qp 0x%06lx failed(%d)\n" , hr_qp->qpn, ret); -kfree (hr_qp); +hns_roce_qp_destroy (hr_dev, hr_qp, udata);return 0 ; }
drivers/infiniband/hw/hns/hns_roce_qp.c +41 -0
47 lines not on this page · raw message
Signature · 1 line
2.8.1
PATCH v2 2/7 RDMA/hns: Optimize qp context create and destroy flow
In reply to Weihang LiFrom: Xi Wang <[email protected]>
Rename the qp context related functions and adjusts the code location to distinguish between the qp context and the entire qp.
--- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 4 - drivers/infiniband/hw/hns/hns_roce_qp.c | 166 ++++++++++++++--------------- 2 files changed, 81 insertions(+), 89 deletions(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +0 -4
@@ -5011,10 +5011,6 @@ static int hns_roce_v2_destroy_qp_common(struct hns_roce_dev *hr_dev,spin_lock_irqsave (&hr_dev->qp_list_lock, flags);hns_roce_lock_cqs (send_cq, recv_cq); -list_del (&hr_qp->node); -list_del (&hr_qp->sq_node); -list_del (&hr_qp->rq_node); -if (!udata) {if (recv_cq) __hns_roce_v2_cq_clean(recv_cq, hr_qp->qpn,
drivers/infiniband/hw/hns/hns_roce_qp.c +81 -85
276 lines not on this page · raw message
Signature · 1 line
2.8.1
PATCH v2 3/7 RDMA/hns: Optimize qp number assign flow
In reply to Weihang LiFrom: Xi Wang <[email protected]>
Encapsulate the code associated with the qp number assignment into alloc_qpn() and free_qpn().
--- drivers/infiniband/hw/hns/hns_roce_qp.c | 91 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 47 deletions(-)
drivers/infiniband/hw/hns/hns_roce_qp.c +44 -47
@@ -108,15 +108,34 @@ static void hns_roce_ib_qp_event(struct hns_roce_qp *hr_qp, } } -static int hns_roce_reserve_range_qp (struct hns_roce_dev *hr_dev,int cnt, -int align,unsigned long *base) +static int alloc_qpn (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp) { -struct hns_roce_qp_table *qp_table = &hr_dev->qp_table; +unsigned long num =0 ; +int ret; + +if (hr_qp->ibqp.qp_type ==IB_QPT_GSI ) { +/* when hw version is v1, the sqpn is allocated */ +if (hr_dev->caps.max_sq_sg <=HNS_ROCE_MAX_SGE_NUM ) + num =HNS_ROCE_MAX_PORTS + + hr_dev->iboe.phy_port[hr_qp->port]; +else + num =1 ; -return hns_roce_bitmap_alloc_range (&qp_table->bitmap, cnt, align, - base) ? - -ENOMEM : -0 ; + hr_qp->doorbell_qpn =1 ; + }else { + ret =hns_roce_bitmap_alloc_range (&hr_dev->qp_table.bitmap, +1 ,1 , &num); +if (ret) { +ibdev_err (&hr_dev->ib_dev,"Failed to alloc bitmap\n" ); +return -ENOMEM ; + } + + hr_qp->doorbell_qpn = (u32 )num; + } + + hr_qp->qpn = num; + +return 0 ; }enum hns_roce_qp_state to_hns_roce_state (enum ib_qp_state state)
@@ -275,15 +294,17 @@ static void free_qpc(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)hns_roce_table_put (hr_dev, &qp_table->irrl_table, hr_qp->qpn); } -void hns_roce_release_range_qp (struct hns_roce_dev *hr_dev,int base_qpn, -int cnt) +static void free_qpn (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp) {struct hns_roce_qp_table *qp_table = &hr_dev->qp_table; -if (base_qpn < hr_dev->caps.reserved_qps) +if (hr_qp->ibqp.qp_type ==IB_QPT_GSI ) +return ; + +if (hr_qp->qpn < hr_dev->caps.reserved_qps)return ; -hns_roce_bitmap_free_range (&qp_table->bitmap, base_qpn, cnt,BITMAP_RR ); +hns_roce_bitmap_free_range (&qp_table->bitmap, hr_qp->qpn,1 ,BITMAP_RR ); } static int hns_roce_set_rq_size(struct hns_roce_dev *hr_dev,
@@ -698,7 +719,7 @@ static void free_rq_inline_buf(struct hns_roce_qp *hr_qp)static int hns_roce_create_qp_common (struct hns_roce_dev *hr_dev,struct ib_pd *ib_pd,struct ib_qp_init_attr *init_attr, -struct ib_udata *udata,unsigned long sqpn, +struct ib_udata *udata,struct hns_roce_qp *hr_qp) {dma_addr_t *buf_list[ARRAY_SIZE (hr_qp->regions)] = {NULL };
@@ -708,7 +729,6 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,struct hns_roce_ucontext *uctx =rdma_udata_to_drv_context ( udata, struct hns_roce_ucontext, ibucontext);struct hns_roce_buf_region *r; -unsigned long qpn =0 ;u32 page_shift;int buf_count;int ret;
@@ -907,19 +927,6 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, } } -if (sqpn) { - qpn = sqpn; - }else { -/* Get QPN */ - ret =hns_roce_reserve_range_qp (hr_dev,1 ,1 , &qpn); -if (ret) { -dev_err (dev,"hns_roce_reserve_range_qp alloc qpn error\n" ); - goto err_wrid; - } - } - - hr_qp->qpn = qpn; - hr_qp->wqe_bt_pg_shift =calc_wqe_bt_page_shift (hr_dev, hr_qp->regions, hr_qp->region_cnt); hns_roce_mtr_init(&hr_qp->mtr, PAGE_SHIFT + hr_qp->wqe_bt_pg_shift,
@@ -928,6 +935,12 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, hr_qp->regions, hr_qp->region_cnt);if (ret) {dev_err (dev,"mtr attach error for create qp\n" ); + goto err_wrid; + } + + ret =alloc_qpn (hr_dev, hr_qp); +if (ret) { +ibdev_err (&hr_dev->ib_dev,"Failed to alloc QPN\n" ); goto err_mtr; }
@@ -943,11 +956,6 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, goto err_qpc; } -if (sqpn) - hr_qp->doorbell_qpn =1 ; -else - hr_qp->doorbell_qpn = (u32 )hr_qp->qpn; -if (udata) { ret =ib_copy_to_udata (udata, &resp,min (udata->outlen,sizeof (resp)));
@@ -961,6 +969,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, goto err_store; } + hr_qp->ibqp.qp_num = hr_qp->qpn; hr_qp->event = hns_roce_ib_qp_event;atomic_set (&hr_qp->refcount,1 );init_completion (&hr_qp->free);
@@ -976,8 +985,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,free_qpc (hr_dev, hr_qp); err_qpn: -if (!sqpn) -hns_roce_release_range_qp (hr_dev, qpn,1 ); +free_qpn (hr_dev, hr_qp); err_mtr:hns_roce_mtr_cleanup (hr_dev, &hr_qp->mtr);
@@ -1036,9 +1044,7 @@ void hns_roce_qp_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,free_qpc (hr_dev, hr_qp); -/* Not special_QP, free their QPN */ -if (hr_qp->ibqp.qp_type !=IB_QPT_GSI ) -hns_roce_release_range_qp (hr_dev, hr_qp->qpn,1 ); +free_qpn (hr_dev, hr_qp);hns_roce_mtr_cleanup (hr_dev, &hr_qp->mtr);
@@ -1087,7 +1093,7 @@ struct ib_qp *hns_roce_create_qp(struct ib_pd *pd,if (!hr_qp)return ERR_PTR (-ENOMEM ); - ret =hns_roce_create_qp_common (hr_dev, pd, init_attr, udata,0 , + ret =hns_roce_create_qp_common (hr_dev, pd, init_attr, udata, hr_qp);if (ret) { ibdev_err(ibdev, "Create QP 0x%06lx failed(%d)\n",
@@ -1096,8 +1102,6 @@ struct ib_qp *hns_roce_create_qp(struct ib_pd *pd,return ERR_PTR (ret); } - hr_qp->ibqp.qp_num = hr_qp->qpn; -break ; }case IB_QPT_GSI : {
@@ -1114,15 +1118,8 @@ struct ib_qp *hns_roce_create_qp(struct ib_pd *pd, hr_qp->port = init_attr->port_num -1 ; hr_qp->phy_port = hr_dev->iboe.phy_port[hr_qp->port]; -/* when hw version is v1, the sqpn is allocated */ -if (hr_dev->caps.max_sq_sg <=2 ) - hr_qp->ibqp.qp_num =HNS_ROCE_MAX_PORTS + - hr_dev->iboe.phy_port[hr_qp->port]; -else - hr_qp->ibqp.qp_num =1 ; - ret =hns_roce_create_qp_common (hr_dev, pd, init_attr, udata, - hr_qp->ibqp.qp_num, hr_qp); + hr_qp);if (ret) {ibdev_err (ibdev,"Create GSI QP failed!\n" );kfree (hr_qp);
Signature · 1 line
2.8.1
PATCH v2 4/7 RDMA/hns: Optimize qp buffer allocation flow
In reply to Weihang LiFrom: Xi Wang <[email protected]>
Encapsulate qp buffer allocation related code into 3 functions:alloc_qp_buf(), map_wqe_buf() and free_qp_buf().
--- drivers/infiniband/hw/hns/hns_roce_device.h | 1 - drivers/infiniband/hw/hns/hns_roce_qp.c | 266 +++++++++++++++------------- 2 files changed, 144 insertions(+), 123 deletions(-)
drivers/infiniband/hw/hns/hns_roce_device.h +0 -1
@@ -660,7 +660,6 @@ struct hns_roce_qp {/* this define must less than HNS_ROCE_MAX_BT_REGION */ #define HNS_ROCE_WQE_REGION_MAX 3struct hns_roce_buf_region regions[HNS_ROCE_WQE_REGION_MAX ]; -int region_cnt;int wqe_bt_pg_shift;u32 buff_size;
drivers/infiniband/hw/hns/hns_roce_qp.c +144 -122
389 lines not on this page · raw message
Signature · 1 line
2.8.1
PATCH v2 5/7 RDMA/hns: Optimize qp param setup flow
In reply to Weihang LiFrom: Xi Wang <[email protected]>
Encapsulate the qp param setup related code into set_qp_param().
--- drivers/infiniband/hw/hns/hns_roce_qp.c | 136 +++++++++++++++++--------------- 1 file changed, 72 insertions(+), 64 deletions(-)
drivers/infiniband/hw/hns/hns_roce_qp.c +72 -64
@@ -307,18 +307,18 @@ static void free_qpn(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)hns_roce_bitmap_free_range (&qp_table->bitmap, hr_qp->qpn,1 ,BITMAP_RR ); } -static int hns_roce_set_rq_size (struct hns_roce_dev *hr_dev, +static int set_rq_size (struct hns_roce_dev *hr_dev,struct ib_qp_cap *cap,bool is_user,int has_rq,struct hns_roce_qp *hr_qp) { -struct device *dev = hr_dev->dev; +struct ib_device *ibdev = &hr_dev->ib_dev;u32 max_cnt;/* Check the validity of QP support capacity */ if (cap->max_recv_wr > hr_dev->caps.max_wqes || cap->max_recv_sge > hr_dev->caps.max_rq_sg) { -dev_err (dev,"RQ WR or sge error!max_recv_wr=%d max_recv_sge=%d\n" , - cap->max_recv_wr, cap->max_recv_sge); +ibdev_err (ibdev,"Failed to check max recv WR %d and SGE %d\n" , + cap->max_recv_wr, cap->max_recv_sge);return -EINVAL ; }
@@ -330,7 +330,7 @@ static int hns_roce_set_rq_size(struct hns_roce_dev *hr_dev, cap->max_recv_sge =0 ; }else {if (is_user && (!cap->max_recv_wr || !cap->max_recv_sge)) { -dev_err (dev,"user space no need config max_recv_wr max_recv_sge\n" ); +ibdev_err (ibdev,"Failed to check user max recv WR and SGE\n" );return -EINVAL ; }
@@ -342,7 +342,7 @@ static int hns_roce_set_rq_size(struct hns_roce_dev *hr_dev, hr_qp->rq.wqe_cnt =roundup_pow_of_two (max_cnt);if ((u32 )hr_qp->rq.wqe_cnt > hr_dev->caps.max_wqes) { -dev_err (dev,"while setting rq size, rq.wqe_cnt too large\n" ); +ibdev_err (ibdev,"Failed to check RQ WQE count limit\n" );return -EINVAL ; }
@@ -373,12 +373,12 @@ static int check_sq_size_with_integrity(struct hns_roce_dev *hr_dev,/* Sanity check SQ size before proceeding */ if (ucmd->log_sq_stride > max_sq_stride || ucmd->log_sq_stride <HNS_ROCE_IB_MIN_SQ_STRIDE ) { -ibdev_err (&hr_dev->ib_dev,"check SQ size error!\n" ); +ibdev_err (&hr_dev->ib_dev,"Failed to check SQ stride size\n" );return -EINVAL ; }if (cap->max_send_sge > hr_dev->caps.max_sq_sg) { -ibdev_err (&hr_dev->ib_dev,"SQ sge error! max_send_sge=%d\n" , +ibdev_err (&hr_dev->ib_dev,"Failed to check SQ SGE size %d\n" , cap->max_send_sge);return -EINVAL ; }
@@ -386,10 +386,9 @@ static int check_sq_size_with_integrity(struct hns_roce_dev *hr_dev,return 0 ; } -static int hns_roce_set_user_sq_size (struct hns_roce_dev *hr_dev, -struct ib_qp_cap *cap, -struct hns_roce_qp *hr_qp, -struct hns_roce_ib_create_qp *ucmd) +static int set_user_sq_size (struct hns_roce_dev *hr_dev, +struct ib_qp_cap *cap,struct hns_roce_qp *hr_qp, +struct hns_roce_ib_create_qp *ucmd) {u32 ex_sge_num;u32 page_size;
@@ -402,7 +401,7 @@ static int hns_roce_set_user_sq_size(struct hns_roce_dev *hr_dev, ret =check_sq_size_with_integrity (hr_dev, cap, ucmd);if (ret) { -ibdev_err (&hr_dev->ib_dev,"Sanity check sq size failed\n" ); +ibdev_err (&hr_dev->ib_dev,"Failed to check user SQ size limit\n" );return ret; }
@@ -420,9 +419,9 @@ static int hns_roce_set_user_sq_size(struct hns_roce_dev *hr_dev,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 (hr_dev->dev, -"The extended sge cnt error! sge_cnt=%d\n" , - hr_qp->sge.sge_cnt); +ibdev_err (&hr_dev->ib_dev, +"Failed to check extended SGE size limit %d\n" , + hr_qp->sge.sge_cnt);return -EINVAL ; } }
@@ -584,9 +583,8 @@ static int set_extend_sge_param(struct hns_roce_dev *hr_dev,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) +static int set_kernel_sq_size (struct hns_roce_dev *hr_dev, +struct ib_qp_cap *cap,struct hns_roce_qp *hr_qp) {struct device *dev = hr_dev->dev;u32 page_size;
@@ -845,6 +843,58 @@ static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp) hr_qp->rq.wqe_cnt)free_rq_inline_buf (hr_qp); } + +static int set_qp_param (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp, +struct ib_qp_init_attr *init_attr, +struct ib_udata *udata, +struct hns_roce_ib_create_qp *ucmd) +{ +struct ib_device *ibdev = &hr_dev->ib_dev; +int ret; + + hr_qp->ibqp.qp_type = init_attr->qp_type; + +if (init_attr->sq_sig_type ==IB_SIGNAL_ALL_WR ) + hr_qp->sq_signal_bits =IB_SIGNAL_ALL_WR ; +else + hr_qp->sq_signal_bits =IB_SIGNAL_REQ_WR ; + + ret =set_rq_size (hr_dev, &init_attr->cap, udata, +hns_roce_qp_has_rq (init_attr), hr_qp); +if (ret) { +ibdev_err (ibdev,"Failed to set user RQ size\n" ); +return ret; + } + +if (udata) { +if (ib_copy_from_udata (ucmd, udata,sizeof (*ucmd))) { +ibdev_err (ibdev,"Failed to copy QP ucmd\n" ); +return -EFAULT ; + } + + ret =set_user_sq_size (hr_dev, &init_attr->cap, hr_qp, ucmd); +if (ret) +ibdev_err (ibdev,"Failed to set user SQ size\n" ); + }else { +if (init_attr->create_flags & +IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK ) { +ibdev_err (ibdev,"Failed to check multicast loopback\n" ); +return -EINVAL ; + } + +if (init_attr->create_flags &IB_QP_CREATE_IPOIB_UD_LSO ) { +ibdev_err (ibdev,"Failed to check ipoib ud lso\n" ); +return -EINVAL ; + } + + ret =set_kernel_sq_size (hr_dev, &init_attr->cap, hr_qp); +if (ret) +ibdev_err (ibdev,"Failed to set kernel SQ size\n" ); + } + +return ret; +} + static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, struct ib_pd *ib_pd, struct ib_qp_init_attr *init_attr,
@@ -864,34 +914,13 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, hr_qp->state =IB_QPS_RESET ; - hr_qp->ibqp.qp_type = init_attr->qp_type; - -if (init_attr->sq_sig_type ==IB_SIGNAL_ALL_WR ) - hr_qp->sq_signal_bits =IB_SIGNAL_ALL_WR ; -else - hr_qp->sq_signal_bits =IB_SIGNAL_REQ_WR ; - - ret =hns_roce_set_rq_size (hr_dev, &init_attr->cap, udata, -hns_roce_qp_has_rq (init_attr), hr_qp); + ret =set_qp_param (hr_dev, hr_qp, init_attr, udata, &ucmd);if (ret) { -dev_err (dev,"hns_roce_set_rq_size failed\n" ); - goto err_out; +ibdev_err (&hr_dev->ib_dev,"Failed to set QP param\n" ); +return ret; }if (udata) { -if (ib_copy_from_udata (&ucmd, udata,sizeof (ucmd))) { -dev_err (dev,"ib_copy_from_udata error for create qp\n" ); - ret = -EFAULT ; - goto err_out; - } - - ret =hns_roce_set_user_sq_size (hr_dev, &init_attr->cap, hr_qp, - &ucmd); -if (ret) { -dev_err (dev,"hns_roce_set_user_sq_size error for create qp\n" ); - goto err_out; - } - if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SQ_RECORD_DB) && (udata->inlen >= sizeof(ucmd)) && (udata->outlen >= sizeof(resp)) &&
@@ -923,27 +952,6 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, hr_qp->rdb_en =1 ; } }else { -if (init_attr->create_flags & -IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK ) { -dev_err (dev,"init_attr->create_flags error!\n" ); - ret = -EINVAL ; - goto err_out; - } - -if (init_attr->create_flags &IB_QP_CREATE_IPOIB_UD_LSO ) { -dev_err (dev,"init_attr->create_flags error!\n" ); - ret = -EINVAL ; - goto err_out; - } - -/* Set SQ size */ - ret =hns_roce_set_kernel_sq_size (hr_dev, &init_attr->cap, - hr_qp); -if (ret) { -dev_err (dev,"hns_roce_set_kernel_sq_size error!\n" ); - goto err_out; - } -/* QP doorbell register address */ hr_qp->sq.db_reg_l = hr_dev->reg_base + hr_dev->sdb_offset +DB_REG_OFFSET * hr_dev->priv_uar.index;
Signature · 1 line
2.8.1
PATCH v2 6/7 RDMA/hns: Optimize kernel qp wrid allocation flow
In reply to Weihang LiFrom: Xi Wang <[email protected]>
Encapsulate the kernel qp wrid allocation related code into 2 functions:alloc_kernel_wrid() and free_kernel_wrid().
--- drivers/infiniband/hw/hns/hns_roce_qp.c | 72 ++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 27 deletions(-)
drivers/infiniband/hw/hns/hns_roce_qp.c +45 -27
@@ -844,6 +844,45 @@ static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)free_rq_inline_buf (hr_qp); } +static int alloc_kernel_wrid (struct hns_roce_dev *hr_dev, +struct hns_roce_qp *hr_qp) +{ +struct ib_device *ibdev = &hr_dev->ib_dev; +u64 *sq_wrid =NULL ; +u64 *rq_wrid =NULL ; +int ret; + + sq_wrid =kcalloc (hr_qp->sq.wqe_cnt,sizeof (u64),GFP_KERNEL ); +if (ZERO_OR_NULL_PTR (sq_wrid)) { +ibdev_err (ibdev,"Failed to alloc SQ wrid\n" ); +return -ENOMEM ; + } + +if (hr_qp->rq.wqe_cnt) { + rq_wrid =kcalloc (hr_qp->rq.wqe_cnt,sizeof (u64),GFP_KERNEL ); +if (ZERO_OR_NULL_PTR (rq_wrid)) { +ibdev_err (ibdev,"Failed to alloc RQ wrid\n" ); + ret = -ENOMEM ; + goto err_sq; + } + } + + hr_qp->sq.wrid = sq_wrid; + hr_qp->rq.wrid = rq_wrid; +return 0 ; +err_sq: +kfree (sq_wrid); + +return ret; +} + +static void free_kernel_wrid (struct hns_roce_dev *hr_dev, +struct hns_roce_qp *hr_qp) +{ +kfree (hr_qp->rq.wrid); +kfree (hr_qp->sq.wrid); +} + static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp, struct ib_qp_init_attr *init_attr, struct ib_udata *udata,
@@ -969,21 +1008,11 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, hr_qp->rdb_en =1 ; } - hr_qp->sq.wrid =kcalloc (hr_qp->sq.wqe_cnt,sizeof (u64), -GFP_KERNEL ); -if (ZERO_OR_NULL_PTR (hr_qp->sq.wrid)) { - ret = -ENOMEM ; + ret =alloc_kernel_wrid (hr_dev, hr_qp); +if (ret) { +ibdev_err (&hr_dev->ib_dev,"Failed to alloc wrid\n" ); goto err_db; } - -if (hr_qp->rq.wqe_cnt) { - hr_qp->rq.wrid =kcalloc (hr_qp->rq.wqe_cnt,sizeof (u64), -GFP_KERNEL ); -if (ZERO_OR_NULL_PTR (hr_qp->rq.wrid)) { - ret = -ENOMEM ; - goto err_sq_wrid; - } - } } ret =alloc_qp_buf (hr_dev, hr_qp, init_attr, udata, ucmd.buf_addr);
@@ -1032,24 +1061,20 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, err_store:hns_roce_qp_remove (hr_dev, hr_qp); - err_qpc:free_qpc (hr_dev, hr_qp); - err_qpn:free_qpn (hr_dev, hr_qp); - err_buf:free_qp_buf (hr_dev, hr_qp); +free_kernel_wrid (hr_dev, hr_qp); +if (udata) {if ((hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_RECORD_DB ) && (udata->outlen >=sizeof (resp)) &&hns_roce_qp_has_rq (init_attr))hns_roce_db_unmap_user (uctx, &hr_qp->rdb); - }else { -if (hr_qp->rq.wqe_cnt) -kfree (hr_qp->rq.wrid); } err_sq_dbmap:
@@ -1060,10 +1085,6 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, hns_roce_qp_has_sq(init_attr))hns_roce_db_unmap_user (uctx, &hr_qp->sdb); -err_sq_wrid: -if (!udata) -kfree (hr_qp->sq.wrid); - err_db:if (!udata &&hns_roce_qp_has_rq (init_attr) && (hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_RECORD_DB ))
@@ -1081,10 +1102,9 @@ void hns_roce_qp_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,wait_for_completion (&hr_qp->free);free_qpc (hr_dev, hr_qp); -free_qpn (hr_dev, hr_qp); -free_qp_buf (hr_dev, hr_qp); +free_kernel_wrid (hr_dev, hr_qp);if (udata) { struct hns_roce_ucontext *context =
@@ -1099,8 +1119,6 @@ void hns_roce_qp_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,if (hr_qp->rq.wqe_cnt && (hr_qp->rdb_en ==1 ))hns_roce_db_unmap_user (context, &hr_qp->rdb); }else { -kfree (hr_qp->sq.wrid); -kfree (hr_qp->rq.wrid);if (hr_qp->rq.wqe_cnt)hns_roce_free_db (hr_dev, &hr_qp->rdb); }
Signature · 1 line
2.8.1
PATCH v2 7/7 RDMA/hns: Optimize qp doorbell allocation flow
In reply to Weihang LiFrom: Xi Wang <[email protected]>
Encapsulate the kernel qp doorbell allocation related code into 2
functions: alloc_qp_db() and free_qp_db().
--- drivers/infiniband/hw/hns/hns_roce_qp.c | 214 +++++++++++++++++--------------- 1 file changed, 113 insertions(+), 101 deletions(-)
drivers/infiniband/hw/hns/hns_roce_qp.c +113 -101
@@ -844,6 +844,96 @@ static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)free_rq_inline_buf (hr_qp); } +#define user_qp_has_sdb (hr_dev, init_attr, udata, resp, ucmd) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SQ_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_sq(init_attr) && udata->inlen >= sizeof(*ucmd)) + +#define user_qp_has_rdb (hr_dev, init_attr, udata, resp) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_rq(init_attr)) + +#define kernel_qp_has_rdb (hr_dev, init_attr) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + hns_roce_qp_has_rq(init_attr)) + +static int alloc_qp_db (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp, +struct ib_qp_init_attr *init_attr, +struct ib_udata *udata, +struct hns_roce_ib_create_qp *ucmd, +struct hns_roce_ib_create_qp_resp *resp) +{ +struct hns_roce_ucontext *uctx =rdma_udata_to_drv_context ( + udata, struct hns_roce_ucontext, ibucontext); +struct ib_device *ibdev = &hr_dev->ib_dev; +int ret; + +if (udata) { +if (user_qp_has_sdb (hr_dev, init_attr, udata, resp, ucmd)) { + ret =hns_roce_db_map_user (uctx, udata, ucmd->sdb_addr, + &hr_qp->sdb); +if (ret) { +ibdev_err (ibdev,"Failed to map user SQ doorbell\n" ); + goto err_out; + } + hr_qp->sdb_en =1 ; + resp->cap_flags |=HNS_ROCE_SUPPORT_SQ_RECORD_DB ; + } + +if (user_qp_has_rdb (hr_dev, init_attr, udata, resp)) { + ret =hns_roce_db_map_user (uctx, udata, ucmd->db_addr, + &hr_qp->rdb); +if (ret) { +ibdev_err (ibdev,"Failed to map user RQ doorbell\n" ); + goto err_sdb; + } + hr_qp->rdb_en =1 ; + resp->cap_flags |=HNS_ROCE_SUPPORT_RQ_RECORD_DB ; + } + }else { +/* QP doorbell register address */ + hr_qp->sq.db_reg_l = hr_dev->reg_base + hr_dev->sdb_offset + +DB_REG_OFFSET * hr_dev->priv_uar.index; + hr_qp->rq.db_reg_l = hr_dev->reg_base + hr_dev->odb_offset + +DB_REG_OFFSET * hr_dev->priv_uar.index; + +if (kernel_qp_has_rdb (hr_dev, init_attr)) { + ret =hns_roce_alloc_db (hr_dev, &hr_qp->rdb,0 ); +if (ret) { +ibdev_err (ibdev,"Failed to alloc kernel RQ doorbell\n" ); + goto err_out; + } + *hr_qp->rdb.db_record =0 ; + hr_qp->rdb_en =1 ; + } + } + +return 0 ; +err_sdb: +if (udata && hr_qp->sdb_en) +hns_roce_db_unmap_user (uctx, &hr_qp->sdb); +err_out: +return ret; +} + +static void free_qp_db (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp, +struct ib_udata *udata) +{ +struct hns_roce_ucontext *uctx =rdma_udata_to_drv_context ( + udata, struct hns_roce_ucontext, ibucontext); + +if (udata) { +if (hr_qp->rdb_en) +hns_roce_db_unmap_user (uctx, &hr_qp->rdb); +if (hr_qp->sdb_en) +hns_roce_db_unmap_user (uctx, &hr_qp->sdb); + }else { +if (hr_qp->rdb_en) +hns_roce_free_db (hr_dev, &hr_qp->rdb); + } +} +static int alloc_kernel_wrid (struct hns_roce_dev *hr_dev,struct hns_roce_qp *hr_qp) {
@@ -940,11 +1030,9 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,struct ib_udata *udata, struct hns_roce_qp *hr_qp) { - struct device *dev = hr_dev->dev; -struct hns_roce_ib_create_qp ucmd; struct hns_roce_ib_create_qp_resp resp = {}; -struct hns_roce_ucontext *uctx =rdma_udata_to_drv_context ( - udata, struct hns_roce_ucontext, ibucontext); +struct ib_device *ibdev = &hr_dev->ib_dev; +struct hns_roce_ib_create_qp ucmd;int ret;mutex_init (&hr_qp->mutex);
@@ -955,95 +1043,55 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, ret =set_qp_param (hr_dev, hr_qp, init_attr, udata, &ucmd);if (ret) { -ibdev_err (&hr_dev->ib_dev,"Failed to set QP param\n" ); +ibdev_err (ibdev,"Failed to set QP param\n" );return ret; } -if (udata) { -if ((hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_SQ_RECORD_DB ) && - (udata->inlen >=sizeof (ucmd)) && - (udata->outlen >=sizeof (resp)) && -hns_roce_qp_has_sq (init_attr)) { - ret =hns_roce_db_map_user (uctx, udata, ucmd.sdb_addr, - &hr_qp->sdb); -if (ret) { -dev_err (dev,"sq record doorbell map failed!\n" ); - goto err_out; - } - -/* indicate kernel supports sq record db */ - resp.cap_flags |=HNS_ROCE_SUPPORT_SQ_RECORD_DB ; - hr_qp->sdb_en =1 ; - } - -if ((hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_RECORD_DB ) && - (udata->outlen >=sizeof (resp)) && -hns_roce_qp_has_rq (init_attr)) { - ret =hns_roce_db_map_user (uctx, udata, ucmd.db_addr, - &hr_qp->rdb); -if (ret) { -dev_err (dev,"rq record doorbell map failed!\n" ); - goto err_sq_dbmap; - } - -/* indicate kernel supports rq record db */ - resp.cap_flags |=HNS_ROCE_SUPPORT_RQ_RECORD_DB ; - hr_qp->rdb_en =1 ; - } - }else { -/* QP doorbell register address */ - hr_qp->sq.db_reg_l = hr_dev->reg_base + hr_dev->sdb_offset + -DB_REG_OFFSET * hr_dev->priv_uar.index; - hr_qp->rq.db_reg_l = hr_dev->reg_base + hr_dev->odb_offset + -DB_REG_OFFSET * hr_dev->priv_uar.index; - -if ((hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_RECORD_DB ) && -hns_roce_qp_has_rq (init_attr)) { - ret =hns_roce_alloc_db (hr_dev, &hr_qp->rdb,0 ); -if (ret) { -dev_err (dev,"rq record doorbell alloc failed!\n" ); - goto err_out; - } - *hr_qp->rdb.db_record =0 ; - hr_qp->rdb_en =1 ; - } - +if (!udata) { ret =alloc_kernel_wrid (hr_dev, hr_qp);if (ret) { -ibdev_err (&hr_dev->ib_dev,"Failed to alloc wrid\n" ); - goto err_db; +ibdev_err (ibdev,"Failed to alloc wrid\n" ); +return ret; } } + ret =alloc_qp_db (hr_dev, hr_qp, init_attr, udata, &ucmd, &resp); +if (ret) { +ibdev_err (ibdev,"Failed to alloc QP doorbell\n" ); + goto err_wrid; + } + ret =alloc_qp_buf (hr_dev, hr_qp, init_attr, udata, ucmd.buf_addr);if (ret) { -ibdev_err (&hr_dev->ib_dev,"Failed to alloc QP buffer\n" ); +ibdev_err (ibdev,"Failed to alloc QP buffer\n" ); goto err_db; } ret =alloc_qpn (hr_dev, hr_qp);if (ret) { -ibdev_err (&hr_dev->ib_dev,"Failed to alloc QPN\n" ); +ibdev_err (ibdev,"Failed to alloc QPN\n" ); goto err_buf; } ret =alloc_qpc (hr_dev, hr_qp);if (ret) { -ibdev_err (&hr_dev->ib_dev,"Failed to alloc QP context\n" ); +ibdev_err (ibdev,"Failed to alloc QP context\n" ); goto err_qpn; } ret =hns_roce_qp_store (hr_dev, hr_qp, init_attr);if (ret) { -ibdev_err (&hr_dev->ib_dev,"Failed to store QP\n" ); +ibdev_err (ibdev,"Failed to store QP\n" ); goto err_qpc; }if (udata) { ret =ib_copy_to_udata (udata, &resp,min (udata->outlen,sizeof (resp))); -if (ret) +if (ret) { +ibdev_err (ibdev,"copy qp resp failed!\n" ); goto err_store; + } }if (hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL ) {
@@ -1067,30 +1115,10 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,free_qpn (hr_dev, hr_qp); err_buf:free_qp_buf (hr_dev, hr_qp); - -free_kernel_wrid (hr_dev, hr_qp); - -if (udata) { -if ((hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_RECORD_DB ) && - (udata->outlen >=sizeof (resp)) && -hns_roce_qp_has_rq (init_attr)) -hns_roce_db_unmap_user (uctx, &hr_qp->rdb); - } - -err_sq_dbmap: -if (udata) -if ((hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_SQ_RECORD_DB ) && - (udata->inlen >=sizeof (ucmd)) && - (udata->outlen >=sizeof (resp)) && -hns_roce_qp_has_sq (init_attr)) -hns_roce_db_unmap_user (uctx, &hr_qp->sdb); - err_db: -if (!udata &&hns_roce_qp_has_rq (init_attr) && - (hr_dev->caps.flags &HNS_ROCE_CAP_FLAG_RECORD_DB )) -hns_roce_free_db (hr_dev, &hr_qp->rdb); - -err_out: +free_qp_db (hr_dev, hr_qp, udata); +err_wrid: +free_kernel_wrid (hr_dev, hr_qp);return ret; }
@@ -1105,23 +1133,7 @@ void hns_roce_qp_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,free_qpn (hr_dev, hr_qp);free_qp_buf (hr_dev, hr_qp);free_kernel_wrid (hr_dev, hr_qp); - -if (udata) { -struct hns_roce_ucontext *context = -rdma_udata_to_drv_context ( - udata, - struct hns_roce_ucontext, - ibucontext); - -if (hr_qp->sq.wqe_cnt && (hr_qp->sdb_en ==1 )) -hns_roce_db_unmap_user (context, &hr_qp->sdb); - -if (hr_qp->rq.wqe_cnt && (hr_qp->rdb_en ==1 )) -hns_roce_db_unmap_user (context, &hr_qp->rdb); - }else { -if (hr_qp->rq.wqe_cnt) -hns_roce_free_db (hr_dev, &hr_qp->rdb); - } +free_qp_db (hr_dev, hr_qp, udata);kfree (hr_qp); }
Signature · 1 line
2.8.1
Re: [PATCH v2 for-next 7/7] RDMA/hns: Optimize qp doorbell allocation flow
Quoted 20 lines · Weihang Li
From: Xi Wang <[email protected]>
Encapsulate the kernel qp doorbell allocation related code into 2
functions:alloc_qp_db()andfree_qp_db().Signed-off-by Xi Wang <[email protected]>Signed-off-by Weihang Li <[email protected]>drivers/infiniband/hw/hns/hns_roce_qp.c | 214 +++++++++++++++++--------------- 1 file changed, 113 insertions(+), 101 deletions(-)drivers/infiniband/hw/hns/hns_roce_qp.c +4
-0+++ b/drivers/infiniband/hw/hns/hns_roce_qp.c@@ -844,6 +844,96 @@ static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)free_rq_inline_buf (hr_qp); } +#define user_qp_has_sdb (hr_dev, init_attr, udata, resp, ucmd) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SQ_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \
drivers/infiniband/hw/hns/hns_roce_qp.c static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp) · line 859
Quoted 10 lines
drivers/infiniband/hw/hns/hns_roce_qp.c +10
-0+ hns_roce_qp_has_sq(init_attr) && udata->inlen >= sizeof(*ucmd)) + +#define user_qp_has_rdb (hr_dev, init_attr, udata, resp) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_rq(init_attr)) + +#define kernel_qp_has_rdb (hr_dev, init_attr) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + hns_roce_qp_has_rq(init_attr))
static inline functions not defines please
Also, these tests against inline and outlen look very strange. What are they doing?
Jason
Re: [PATCH v2 for-next 7/7] RDMA/hns: Optimize qp doorbell allocation flow
Quoted 18 lines · Jason Gunthorpe
Quoted 17 lines · Weihang Li
From: Xi Wang <[email protected]>
Encapsulate the kernel qp doorbell allocation related code into 2
functions:alloc_qp_db()andfree_qp_db().Signed-off-by Xi Wang <[email protected]>Signed-off-by Weihang Li <[email protected]>drivers/infiniband/hw/hns/hns_roce_qp.c | 214 +++++++++++++++++--------------- 1 file changed, 113 insertions(+), 101 deletions(-)drivers/infiniband/hw/hns/hns_roce_qp.c +1
-0+++ b/drivers/infiniband/hw/hns/hns_roce_qp.c@@ -844,6 +844,96 @@ static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)free_rq_inline_buf (hr_qp); }
Quoted 16 lines
drivers/infiniband/hw/hns/hns_roce_qp.c static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp) · line 859
Quoted 13 lines
drivers/infiniband/hw/hns/hns_roce_qp.c +13
-0+#define user_qp_has_sdb (hr_dev, init_attr, udata, resp, ucmd) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SQ_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_sq(init_attr) && udata->inlen >= sizeof(*ucmd)) + +#define user_qp_has_rdb (hr_dev, init_attr, udata, resp) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_rq(init_attr)) + +#define kernel_qp_has_rdb (hr_dev, init_attr) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + hns_roce_qp_has_rq(init_attr))static inline functions not defines please
OK, I will change them into inline functions.
Quoted 5 lines
Also, these tests against inline and outlen look very strange. What are they doing?
Jason
These judgement about inlen and outlen is for compatibility reasons, previous discussions can be found at:
https://patchwork.kernel.org/patch/10172233/
Thanks,
Weihang
Quoted 1 line
Re: [PATCH v2 for-next 7/7] RDMA/hns: Optimize qp doorbell allocation flow
Quoted 43 lines · Weihang Li
Quoted 18 lines · Jason Gunthorpe
Quoted 17 lines · Weihang Li
From: Xi Wang <[email protected]>
Encapsulate the kernel qp doorbell allocation related code into 2
functions:alloc_qp_db()andfree_qp_db().Signed-off-by Xi Wang <[email protected]>Signed-off-by Weihang Li <[email protected]>drivers/infiniband/hw/hns/hns_roce_qp.c | 214 +++++++++++++++++--------------- 1 file changed, 113 insertions(+), 101 deletions(-)drivers/infiniband/hw/hns/hns_roce_qp.c +1
-0+++ b/drivers/infiniband/hw/hns/hns_roce_qp.c@@ -844,6 +844,96 @@ static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)free_rq_inline_buf (hr_qp); }Quoted 16 lines
drivers/infiniband/hw/hns/hns_roce_qp.c static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp) · line 859
Quoted 13 lines
drivers/infiniband/hw/hns/hns_roce_qp.c +13
-0+#define user_qp_has_sdb (hr_dev, init_attr, udata, resp, ucmd) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SQ_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_sq(init_attr) && udata->inlen >= sizeof(*ucmd)) + +#define user_qp_has_rdb (hr_dev, init_attr, udata, resp) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_rq(init_attr)) + +#define kernel_qp_has_rdb (hr_dev, init_attr) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + hns_roce_qp_has_rq(init_attr))static inline functions not defines please
OK, I will change them into inline functions.
Quoted 3 lines
Also, these tests against inline and outlen look very strange. What are they doing?
Quoted 7 lines
Quoted 2 lines
Jason
These judgement about inlen and outlen is for compatibility reasons, previous discussions can be found at:
Something is wrong, it should be testing the legnth using a field_offset_off kind of scheme, not sizeof(*resp)
Jason
Re: [PATCH v2 for-next 7/7] RDMA/hns: Optimize qp doorbell allocation flow
Quoted 50 lines · Jason Gunthorpe
Quoted 49 lines · Weihang Li
Quoted 18 lines · Jason Gunthorpe
Quoted 17 lines · Weihang Li
From: Xi Wang <[email protected]>
Encapsulate the kernel qp doorbell allocation related code into 2
functions:alloc_qp_db()andfree_qp_db().Signed-off-by Xi Wang <[email protected]>Signed-off-by Weihang Li <[email protected]>drivers/infiniband/hw/hns/hns_roce_qp.c | 214 +++++++++++++++++--------------- 1 file changed, 113 insertions(+), 101 deletions(-)drivers/infiniband/hw/hns/hns_roce_qp.c +1
-0+++ b/drivers/infiniband/hw/hns/hns_roce_qp.c@@ -844,6 +844,96 @@ static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)free_rq_inline_buf (hr_qp); }Quoted 16 lines
drivers/infiniband/hw/hns/hns_roce_qp.c static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp) · line 859
Quoted 13 lines
drivers/infiniband/hw/hns/hns_roce_qp.c +13
-0+#define user_qp_has_sdb (hr_dev, init_attr, udata, resp, ucmd) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SQ_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_sq(init_attr) && udata->inlen >= sizeof(*ucmd)) + +#define user_qp_has_rdb (hr_dev, init_attr, udata, resp) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_rq(init_attr)) + +#define kernel_qp_has_rdb (hr_dev, init_attr) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + hns_roce_qp_has_rq(init_attr))static inline functions not defines please
OK, I will change them into inline functions.
Quoted 5 lines
Also, these tests against inline and outlen look very strange. What are they doing?
Jason
These judgement about inlen and outlen is for compatibility reasons, previous discussions can be found at:
Quoted 7 lines
Quoted 1 line
Something is wrong, it should be testing the legnth using a
field_offset_offkind of scheme, notsizeof(*resp)Jason
Hi Jason,
Do you means
udata->outlen >= sizeof(*resp)
should be changed into:
udata->out_len >= offsetof(typeof(*resp), cap_flags)
If yes, I will fix other similar codes with this issue in hns drivers.
Thanks
Weihang
Re: [PATCH v2 for-next 7/7] RDMA/hns: Optimize qp doorbell allocation flow
Quoted 64 lines · Weihang Li
Quoted 50 lines · Jason Gunthorpe
Quoted 49 lines · Weihang Li
Quoted 18 lines · Jason Gunthorpe
Quoted 17 lines · Weihang Li
From: Xi Wang <[email protected]>
Encapsulate the kernel qp doorbell allocation related code into 2
functions:alloc_qp_db()andfree_qp_db().Signed-off-by Xi Wang <[email protected]>Signed-off-by Weihang Li <[email protected]>drivers/infiniband/hw/hns/hns_roce_qp.c | 214 +++++++++++++++++--------------- 1 file changed, 113 insertions(+), 101 deletions(-)drivers/infiniband/hw/hns/hns_roce_qp.c +1
-0+++ b/drivers/infiniband/hw/hns/hns_roce_qp.c@@ -844,6 +844,96 @@ static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)free_rq_inline_buf (hr_qp); }Quoted 16 lines
drivers/infiniband/hw/hns/hns_roce_qp.c static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp) · line 859
Quoted 13 lines
drivers/infiniband/hw/hns/hns_roce_qp.c +13
-0+#define user_qp_has_sdb (hr_dev, init_attr, udata, resp, ucmd) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SQ_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_sq(init_attr) && udata->inlen >= sizeof(*ucmd)) + +#define user_qp_has_rdb (hr_dev, init_attr, udata, resp) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + udata->outlen >= sizeof(*resp) && \ + hns_roce_qp_has_rq(init_attr)) + +#define kernel_qp_has_rdb (hr_dev, init_attr) \ + ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && \ + hns_roce_qp_has_rq(init_attr))static inline functions not defines please
OK, I will change them into inline functions.
Quoted 5 lines
Also, these tests against inline and outlen look very strange. What are they doing?
Jason
These judgement about inlen and outlen is for compatibility reasons, previous discussions can be found at:
Quoted 7 lines
Quoted 1 line
Something is wrong, it should be testing the legnth using a
field_offset_offkind of scheme, notsizeof(*resp)Jason
Hi Jason,
Do you means
Quoted 7 lines
udata->outlen >= sizeof(*resp)should be changed into:
udata->out_len >= offsetof(typeof(*resp), cap_flags)If yes, I will fix other similar codes with this issue in hns drivers.
Probably offsetofend though, right?
But yes, that is how the general 'feature test for old userspace with old kernel ABI' should look
Jason
Re: [PATCH v2 for-next 7/7] RDMA/hns: Optimize qp doorbell allocation flow
Quoted 10 lines · Jason Gunthorpe
Quoted 10 lines
Hi Jason,
Do you means
udata->outlen >= sizeof(*resp)should be changed into:
udata->out_len >= offsetof(typeof(*resp), cap_flags)
Quoted 8 lines
Quoted 1 line
If yes, I will fix other similar codes with this issue in hns drivers.
Probably offsetofend though, right?
But yes, that is how the general 'feature test for old userspace with old kernel ABI' should look
Jason
Yes, you are right, I made a mistake :)
Thanks for your comments.
Weihang
Quoted 10 lines · Weihang Li
This series refactor qp related code, including creating, destroying qp and so on to make the processs easier to understand and maintain.
Previous disscussion can be found at:
https://patchwork.kernel.org/cover/11341265/Changes since v1:
- Reduce the number of prints as Leon suggested.
- Fix a wrong function name in description of patch 4/7.
Quoted 8 lines
Xi Wang (7):
RDMA/hns: Optimize qp destroy flow
RDMA/hns: Optimize qp context create and destroy flow RDMA/hns: Optimize qp number assign flow RDMA/hns: Optimize qp buffer allocation flow RDMA/hns: Optimize qp param setup flow RDMA/hns: Optimize kernel qp wrid allocation flow RDMA/hns: Optimize qp doorbell allocation flow
These don't apply, please resend.
Jason
Quoted 20 lines · Jason Gunthorpe
Quoted 10 lines · Weihang Li
This series refactor qp related code, including creating, destroying qp and so on to make the processs easier to understand and maintain.
Previous disscussion can be found at:
https://patchwork.kernel.org/cover/11341265/Changes since v1:
- Reduce the number of prints as Leon suggested.
- Fix a wrong function name in description of patch 4/7.Quoted 8 lines
Xi Wang (7):
RDMA/hns: Optimize qp destroy flow
RDMA/hns: Optimize qp context create and destroy flow RDMA/hns: Optimize qp number assign flow RDMA/hns: Optimize qp buffer allocation flow RDMA/hns: Optimize qp param setup flow RDMA/hns: Optimize kernel qp wrid allocation flow RDMA/hns: Optimize qp doorbell allocation flow
Quoted 4 lines
These don't apply, please resend.
Jason
OK, will resend a new version. Thank you.
Weihang