From: Jason Gunthorpe <jgg@xxxxxxxxxxxx> Replace the entire IBV_INIT_CMD_RESP(); write(); return errno; Sequence with a single function call. This signature has enough information for the execute call to compute the location of all 5 components of a write command. This requires adding a the _v3 version of modify_srq to the command macros. This can be done without a lot of complexity by using core_payload instead of the struct member aliases. Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx> --- libibverbs/cmd.c | 36 ++++++++++++------------------------ libibverbs/cmd_write.h | 11 +++++++++++ libibverbs/ibverbs.h | 7 ------- libibverbs/kern-abi.h | 6 ++++-- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index 8123aae1ad89b8..d759ec89c843cc 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -719,19 +719,15 @@ static int ibv_cmd_modify_srq_v3(struct ibv_srq *srq, cmd = alloca(cmd_size); memcpy(cmd + 1, new_cmd + 1, new_cmd_size - sizeof *new_cmd); - IBV_INIT_CMD(cmd, cmd_size, MODIFY_SRQ); - - cmd->srq_handle = srq->handle; - cmd->attr_mask = srq_attr_mask; - cmd->max_wr = srq_attr->max_wr; - cmd->srq_limit = srq_attr->srq_limit; - cmd->max_sge = 0; - cmd->reserved = 0; - - if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; + cmd->core_payload = (struct ib_uverbs_modify_srq_v3){ + .srq_handle = srq->handle, + .attr_mask = srq_attr_mask, + .max_wr = srq_attr->max_wr, + .srq_limit = srq_attr->srq_limit, + }; - return 0; + return execute_cmd_write_req( + srq->context, IB_USER_VERBS_CMD_MODIFY_SRQ_V3, cmd, cmd_size); } int ibv_cmd_modify_srq(struct ibv_srq *srq, @@ -743,17 +739,13 @@ int ibv_cmd_modify_srq(struct ibv_srq *srq, return ibv_cmd_modify_srq_v3(srq, srq_attr, srq_attr_mask, cmd, cmd_size); - IBV_INIT_CMD(cmd, cmd_size, MODIFY_SRQ); - cmd->srq_handle = srq->handle; cmd->attr_mask = srq_attr_mask; cmd->max_wr = srq_attr->max_wr; cmd->srq_limit = srq_attr->srq_limit; - if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - return 0; + return execute_cmd_write_req(srq->context, IB_USER_VERBS_CMD_MODIFY_SRQ, + cmd, cmd_size); } int ibv_cmd_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, @@ -1288,14 +1280,10 @@ int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, if (attr_mask & ~(IBV_QP_RATE_LIMIT - 1)) return EOPNOTSUPP; - IBV_INIT_CMD(cmd, cmd_size, MODIFY_QP); - copy_modify_qp_fields(qp, attr, attr_mask, &cmd->core_payload); - if (write(qp->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - return 0; + return execute_cmd_write_req(qp->context, IB_USER_VERBS_CMD_MODIFY_QP, + cmd, cmd_size); } int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr, diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index c7a7ef0b50a22b..7ae26359b25f29 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -228,6 +228,17 @@ int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, sizeof(*(resp)), resp_size); \ }) +/* For write() commands that have no respone */ +#define execute_cmd_write_req(ctx, enum, cmd, cmd_size) \ + ({ \ + static_assert(sizeof(IBV_KABI_RESP(enum)) == 0, \ + "Method has a response!"); \ + _execute_cmd_write( \ + ctx, enum, \ + &(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *), \ + sizeof(*(cmd)), cmd_size, NULL, 0, 0); \ + }) + /* * Execute a write command that does not have a uhw component. THe cmd_size * and resp_size are the lengths of the core structure. This version is only diff --git a/libibverbs/ibverbs.h b/libibverbs/ibverbs.h index c99d617eace611..c70114f11e9bad 100644 --- a/libibverbs/ibverbs.h +++ b/libibverbs/ibverbs.h @@ -86,13 +86,6 @@ static inline const struct verbs_context_ops *get_ops(struct ibv_context *ctx) return &get_priv(ctx)->ops; } -#define IBV_INIT_CMD(cmd, size, opcode) \ - do { \ - (cmd)->hdr.command = IB_USER_VERBS_CMD_##opcode; \ - (cmd)->hdr.in_words = (size) / 4; \ - (cmd)->hdr.out_words = 0; \ - } while (0) - static inline uint32_t _cmd_ex(uint32_t cmd) { return IB_USER_VERBS_CMD_FLAG_EXTENDED | cmd; diff --git a/libibverbs/kern-abi.h b/libibverbs/kern-abi.h index 8c07b8d2731adb..dc2f33d3f78e45 100644 --- a/libibverbs/kern-abi.h +++ b/libibverbs/kern-abi.h @@ -277,8 +277,7 @@ struct ibv_kern_spec { }; }; -struct ibv_modify_srq_v3 { - struct ib_uverbs_cmd_hdr hdr; +struct ib_uverbs_modify_srq_v3 { __u32 srq_handle; __u32 attr_mask; __u32 max_wr; @@ -286,6 +285,9 @@ struct ibv_modify_srq_v3 { __u32 srq_limit; __u32 reserved; }; +#define _STRUCT_ib_uverbs_modify_srq_v3 +enum { IB_USER_VERBS_CMD_MODIFY_SRQ_V3 = IB_USER_VERBS_CMD_MODIFY_SRQ }; +DECLARE_CMDX(IB_USER_VERBS_CMD_MODIFY_SRQ_V3, ibv_modify_srq_v3, ib_uverbs_modify_srq_v3, empty); struct ibv_create_qp_resp_v3 { __u32 qp_handle; -- 2.19.1