@@ -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,
@@ -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
@@ -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;
@@ -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;