Re: [PATCH rdma-core] hns: Use verbs_set_ops instead of opencoding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



在 2018/5/18 7:16, Jason Gunthorpe 写道:
> Somehow hns got missed when I did the bulk conversion. All drivers must
> use verbs_set_ops.
> 
> Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
> ---
>  libibverbs/driver.h              |  4 ++--
>  providers/hns/hns_roce_u.c       | 37 +++++++++++++++-----------------
>  providers/hns/hns_roce_u.h       | 16 ++++----------
>  providers/hns/hns_roce_u_hw_v1.c | 16 ++++++++------
>  providers/hns/hns_roce_u_hw_v2.c | 16 ++++++++------
>  5 files changed, 41 insertions(+), 48 deletions(-)
> 
> diff --git a/libibverbs/driver.h b/libibverbs/driver.h
> index ca618272320dd8..2ba91f24abc8b0 100644
> --- a/libibverbs/driver.h
> +++ b/libibverbs/driver.h
> @@ -122,7 +122,7 @@ struct verbs_match_ent {
>  };
>  #define VERBS_PCI_MATCH(_vendor, _device, _data)                               \
>  	{                                                                      \
> -	    .driver_data = (_data),                                            \
> +	    .driver_data = (void *)(_data),				       \
>  	    .vendor = (_vendor),                                               \
>  	    .device = (_device),                                               \
>  	    .kind = VERBS_MATCH_PCI,                                           \
> @@ -130,7 +130,7 @@ struct verbs_match_ent {
>  
>  #define VERBS_MODALIAS_MATCH(_mod_str, _data)                                  \
>  	{                                                                      \
> -	    .driver_data = (_data),                                            \
> +	    .driver_data = (void *)(_data),			               \
>  	    .modalias = (_mod_str),                                            \
>  	    .kind = VERBS_MATCH_MODALIAS,                                      \
>  	}
> diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c
> index f43722caaf99f3..1ec5858ee69901 100644
> --- a/providers/hns/hns_roce_u.c
> +++ b/providers/hns/hns_roce_u.c
> @@ -61,6 +61,21 @@ static const struct verbs_match_ent hca_table[] = {
>  	{}
>  };
>  
> +static const struct verbs_context_ops hns_common_ops = {
> +	.alloc_pd = hns_roce_u_alloc_pd,
> +	.cq_event = hns_roce_u_cq_event,
> +	.create_cq = hns_roce_u_create_cq,
> +	.create_qp = hns_roce_u_create_qp,
> +	.dealloc_pd = hns_roce_u_free_pd,
> +	.dereg_mr = hns_roce_u_dereg_mr,
> +	.destroy_cq = hns_roce_u_destroy_cq,
> +	.query_device = hns_roce_u_query_device,
> +	.query_port = hns_roce_u_query_port,
> +	.query_qp = hns_roce_u_query_qp,
> +	.reg_mr = hns_roce_u_reg_mr,
> +	.rereg_mr = hns_roce_u_rereg_mr,
> +};
> +
>  static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,
>  						    int cmd_fd)
>  {
> @@ -113,26 +128,8 @@ static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,
>  
>  	pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);
>  
> -	context->ibv_ctx.context.ops.query_device  = hns_roce_u_query_device;
> -	context->ibv_ctx.context.ops.query_port    = hns_roce_u_query_port;
> -	context->ibv_ctx.context.ops.alloc_pd	   = hns_roce_u_alloc_pd;
> -	context->ibv_ctx.context.ops.dealloc_pd    = hns_roce_u_free_pd;
> -	context->ibv_ctx.context.ops.reg_mr	   = hns_roce_u_reg_mr;
> -	context->ibv_ctx.context.ops.rereg_mr	   = hns_roce_u_rereg_mr;
> -	context->ibv_ctx.context.ops.dereg_mr	   = hns_roce_u_dereg_mr;
> -
> -	context->ibv_ctx.context.ops.create_cq     = hns_roce_u_create_cq;
> -	context->ibv_ctx.context.ops.poll_cq	   = hr_dev->u_hw->poll_cq;
> -	context->ibv_ctx.context.ops.req_notify_cq = hr_dev->u_hw->arm_cq;
> -	context->ibv_ctx.context.ops.cq_event	   = hns_roce_u_cq_event;
> -	context->ibv_ctx.context.ops.destroy_cq    = hns_roce_u_destroy_cq;
> -
> -	context->ibv_ctx.context.ops.create_qp     = hns_roce_u_create_qp;
> -	context->ibv_ctx.context.ops.query_qp	   = hns_roce_u_query_qp;
> -	context->ibv_ctx.context.ops.modify_qp     = hr_dev->u_hw->modify_qp;
> -	context->ibv_ctx.context.ops.destroy_qp    = hr_dev->u_hw->destroy_qp;
> -	context->ibv_ctx.context.ops.post_send     = hr_dev->u_hw->post_send;
> -	context->ibv_ctx.context.ops.post_recv     = hr_dev->u_hw->post_recv;
> +	verbs_set_ops(&context->ibv_ctx, &hns_common_ops);
> +	verbs_set_ops(&context->ibv_ctx, &hr_dev->u_hw->hw_ops);
>  
>  	if (hns_roce_u_query_device(&context->ibv_ctx.context, &dev_attrs))
>  		goto tptr_free;
> diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h
> index 781b36b59e0f05..bd66c6e778be15 100644
> --- a/providers/hns/hns_roce_u.h
> +++ b/providers/hns/hns_roce_u.h
> @@ -85,7 +85,7 @@ enum {
>  struct hns_roce_device {
>  	struct verbs_device		ibv_dev;
>  	int				page_size;
> -	struct hns_roce_u_hw		*u_hw;
> +	const struct hns_roce_u_hw	*u_hw;
>  	int				hw_version;
>  };
>  
> @@ -221,15 +221,7 @@ struct hns_roce_qp {
>  
>  struct hns_roce_u_hw {
>  	uint32_t hw_version;
> -	int (*poll_cq)(struct ibv_cq *ibvcq, int ne, struct ibv_wc *wc);
> -	int (*arm_cq)(struct ibv_cq *ibvcq, int solicited);
> -	int (*post_send)(struct ibv_qp *ibvqp, struct ibv_send_wr *wr,
> -			 struct ibv_send_wr **bad_wr);
> -	int (*post_recv)(struct ibv_qp *ibvqp, struct ibv_recv_wr *wr,
> -			 struct ibv_recv_wr **bad_wr);
> -	int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
> -			 int attr_mask);
> -	int (*destroy_qp)(struct ibv_qp *ibqp);
> +	struct verbs_context_ops hw_ops;
>  };
>  
>  static inline unsigned long align(unsigned long val, unsigned long align)
> @@ -300,7 +292,7 @@ void hns_roce_free_buf(struct hns_roce_buf *buf);
>  
>  void hns_roce_init_qp_indices(struct hns_roce_qp *qp);
>  
> -extern struct hns_roce_u_hw hns_roce_u_hw_v1;
> -extern struct hns_roce_u_hw hns_roce_u_hw_v2;
> +extern const struct hns_roce_u_hw hns_roce_u_hw_v1;
> +extern const struct hns_roce_u_hw hns_roce_u_hw_v2;
>  
>  #endif /* _HNS_ROCE_U_H */
> diff --git a/providers/hns/hns_roce_u_hw_v1.c b/providers/hns/hns_roce_u_hw_v1.c
> index 1d256aa698d004..dbe0a185d154f0 100644
> --- a/providers/hns/hns_roce_u_hw_v1.c
> +++ b/providers/hns/hns_roce_u_hw_v1.c
> @@ -830,12 +830,14 @@ out:
>  	return ret;
>  }
>  
> -struct hns_roce_u_hw hns_roce_u_hw_v1 = {
> +const struct hns_roce_u_hw hns_roce_u_hw_v1 = {
>  	.hw_version = HNS_ROCE_HW_VER1,
> -	.poll_cq = hns_roce_u_v1_poll_cq,
> -	.arm_cq = hns_roce_u_v1_arm_cq,
> -	.post_send = hns_roce_u_v1_post_send,
> -	.post_recv = hns_roce_u_v1_post_recv,
> -	.modify_qp = hns_roce_u_v1_modify_qp,
> -	.destroy_qp = hns_roce_u_v1_destroy_qp,
> +	.hw_ops = {
> +		.poll_cq = hns_roce_u_v1_poll_cq,
> +		.req_notify_cq = hns_roce_u_v1_arm_cq,
> +		.post_send = hns_roce_u_v1_post_send,
> +		.post_recv = hns_roce_u_v1_post_recv,
> +		.modify_qp = hns_roce_u_v1_modify_qp,
> +		.destroy_qp = hns_roce_u_v1_destroy_qp,
> +	},
>  };
> diff --git a/providers/hns/hns_roce_u_hw_v2.c b/providers/hns/hns_roce_u_hw_v2.c
> index 0e75604fca2053..ca59011f955a8f 100644
> --- a/providers/hns/hns_roce_u_hw_v2.c
> +++ b/providers/hns/hns_roce_u_hw_v2.c
> @@ -1012,12 +1012,14 @@ static int hns_roce_u_v2_destroy_qp(struct ibv_qp *ibqp)
>  	return ret;
>  }
>  
> -struct hns_roce_u_hw hns_roce_u_hw_v2 = {
> +const struct hns_roce_u_hw hns_roce_u_hw_v2 = {
>  	.hw_version = HNS_ROCE_HW_VER2,
> -	.poll_cq = hns_roce_u_v2_poll_cq,
> -	.arm_cq = hns_roce_u_v2_arm_cq,
> -	.post_send = hns_roce_u_v2_post_send,
> -	.post_recv = hns_roce_u_v2_post_recv,
> -	.modify_qp = hns_roce_u_v2_modify_qp,
> -	.destroy_qp = hns_roce_u_v2_destroy_qp,
> +	.hw_ops = {
> +		.poll_cq = hns_roce_u_v2_poll_cq,
> +		.req_notify_cq = hns_roce_u_v2_arm_cq,
> +		.post_send = hns_roce_u_v2_post_send,
> +		.post_recv = hns_roce_u_v2_post_recv,
> +		.modify_qp = hns_roce_u_v2_modify_qp,
> +		.destroy_qp = hns_roce_u_v2_destroy_qp,
> +	},
>  };
> 
thanks. Review-by: Lijun Ou <oulijun@xxxxxxxxxx>

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux